Skip to content

Commit b9e4406

Browse files
1 parent b1d42b9 commit b9e4406

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+531
-666
lines changed

packages/database/exp/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from '../src/exp/Database';
2727

2828
export {
29+
FirebaseDatabase,
2930
enableLogging,
3031
getDatabase,
3132
goOffline,
@@ -41,9 +42,10 @@ export {
4142
} from '../src/exp/Reference';
4243
export { OnDisconnect } from '../src/exp/OnDisconnect';
4344
export {
44-
QueryConstraint,
4545
DataSnapshot,
4646
EventType,
47+
QueryConstraint,
48+
QueryConstraintType,
4749
endAt,
4850
endBefore,
4951
equalTo,
@@ -55,16 +57,23 @@ export {
5557
onChildChanged,
5658
onChildMoved,
5759
onChildRemoved,
60+
onDisconnect,
5861
onValue,
5962
orderByChild,
6063
orderByKey,
6164
orderByPriority,
6265
orderByValue,
66+
push,
6367
query,
68+
ref,
69+
refFromURL,
70+
remove,
71+
set,
72+
setPriority,
73+
setWithPriority,
6474
startAfter,
6575
startAt,
66-
ref,
67-
refFromURL
76+
update
6877
} from '../src/exp/Reference_impl';
6978
export { increment, serverTimestamp } from '../src/exp/ServerValue';
7079
export {

packages/database/exp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"browser": "../dist/exp/index.esm.js",
66
"module": "../dist/exp/index.esm.js",
77
"esm2017": "../dist/exp/index.esm2017.js",
8-
"typings": "../exp-types/index.d.ts"
8+
"typings": "../dist/exp/index.d.ts"
99
}

packages/database/index.node.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ const ServerValue = Database.ServerValue;
4040
* A one off register function which returns a database based on the app and
4141
* passed database URL. (Used by the Admin SDK)
4242
*
43-
* @param app A valid FirebaseApp-like object
44-
* @param url A valid Firebase databaseURL
45-
* @param version custom version e.g. firebase-admin version
46-
* @param nodeAdmin true if the SDK is being initialized from Firebase Admin.
43+
* @param app - A valid FirebaseApp-like object
44+
* @param url - A valid Firebase databaseURL
45+
* @param version - custom version e.g. firebase-admin version
46+
* @param nodeAdmin - true if the SDK is being initialized from Firebase Admin.
4747
*/
4848
export function initStandalone(
4949
app: FirebaseApp,

packages/database/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1515
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1616
"prettier": "prettier --write '*.js' '*.ts' '@(exp|src|test)/**/*.ts'",
17-
"build": "run-p build:classic build:exp && yarn api-report",
17+
"build": "run-p build:classic build:exp",
1818
"build:classic": "rollup -c rollup.config.js",
1919
"build:exp": "rollup -c rollup.config.exp.js && yarn api-report",
2020
"build:deps": "lerna run --scope @firebase/'{app,database}' --include-dependencies build",
@@ -25,7 +25,8 @@
2525
"test:browser": "karma start --single-run",
2626
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --config ../../config/mocharc.node.js",
2727
"test:emulator": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/database-test-runner.ts",
28-
"api-report": "api-extractor run --local --verbose",
28+
"api-report": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ts-node ./scripts/api-report.ts && yarn api-report:api-json",
29+
"api-report:api-json": "rm -rf temp && api-extractor run --local --verbose",
2930
"predoc": "node ../../scripts/exp/remove-exp.js temp",
3031
"doc": "api-documenter markdown --input temp --output docs"
3132
},
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as fs from 'fs';
19+
import * as path from 'path';
20+
21+
import { Extractor, ExtractorConfig } from 'api-extractor-me';
22+
import * as tmp from 'tmp';
23+
24+
import {
25+
pruneDts,
26+
removeUnusedImports
27+
} from '../../../repo-scripts/prune-dts/prune-dts';
28+
29+
/* eslint-disable no-console */
30+
31+
// This script takes the output of the API Extractor, post-processes it using
32+
// the pruned-dts script and then invokes API report to generate a report
33+
// that only includes exported symbols. This is all done in temporary folders,
34+
// all configuration is auto-generated for each run.
35+
36+
const baseApiExtractorConfigFile: string = path.resolve(
37+
__dirname,
38+
'../../../config/api-extractor.json'
39+
);
40+
const reportFolder = path.resolve(__dirname, '../../../common/api-review');
41+
const tmpDir = tmp.dirSync().name;
42+
43+
function writeTypescriptConfig(): void {
44+
const tsConfigJson = {
45+
extends: path.resolve(__dirname, '../tsconfig.json'),
46+
include: [path.resolve(__dirname, '../src')],
47+
compilerOptions: {
48+
downlevelIteration: true // Needed for FirebaseApp
49+
}
50+
};
51+
fs.writeFileSync(
52+
path.resolve(tmpDir, 'tsconfig.json'),
53+
JSON.stringify(tsConfigJson),
54+
{ encoding: 'utf-8' }
55+
);
56+
}
57+
58+
function writePackageJson(): void {
59+
const packageJson = {
60+
'name': `@firebase/database-exp`
61+
};
62+
const packageJsonPath = path.resolve(tmpDir, 'package.json');
63+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson), {
64+
encoding: 'utf-8'
65+
});
66+
}
67+
68+
function loadApiExtractorConfig(
69+
typescriptDtsPath: string,
70+
rollupDtsPath: string,
71+
untrimmedRollupDtsPath: string,
72+
dtsRollupEnabled: boolean,
73+
apiReportEnabled: boolean
74+
): ExtractorConfig {
75+
const apiExtractorJsonPath = path.resolve(tmpDir, 'api-extractor.json');
76+
const apiExtractorJson = {
77+
extends: baseApiExtractorConfigFile,
78+
mainEntryPointFilePath: typescriptDtsPath,
79+
'dtsRollup': {
80+
'enabled': dtsRollupEnabled,
81+
publicTrimmedFilePath: rollupDtsPath,
82+
untrimmedFilePath: untrimmedRollupDtsPath
83+
},
84+
'tsdocMetadata': {
85+
'enabled': false
86+
},
87+
'apiReport': {
88+
'enabled': apiReportEnabled,
89+
reportFolder
90+
},
91+
'messages': {
92+
'extractorMessageReporting': {
93+
'ae-missing-release-tag': {
94+
'logLevel': 'none'
95+
},
96+
'ae-unresolved-link': {
97+
'logLevel': 'none'
98+
},
99+
'ae-forgotten-export': {
100+
'logLevel': apiReportEnabled ? 'error' : 'none'
101+
}
102+
},
103+
'tsdocMessageReporting': {
104+
'tsdoc-undefined-tag': {
105+
'logLevel': 'none'
106+
}
107+
}
108+
}
109+
};
110+
fs.writeFileSync(apiExtractorJsonPath, JSON.stringify(apiExtractorJson), {
111+
encoding: 'utf-8'
112+
});
113+
return ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath);
114+
}
115+
116+
export async function generateApi(): Promise<void> {
117+
// The .d.ts file generated by the Typescript compiler as we transpile our
118+
// sources
119+
const typescriptDtsPath: string = path.resolve(
120+
__dirname,
121+
`../dist/exp/packages/database/exp/index.d.ts`
122+
);
123+
// A "bundled" version of our d.ts files that includes all public and private
124+
// types
125+
const rollupDtsPath: string = path.resolve(
126+
__dirname,
127+
`../dist/exp/private.d.ts`
128+
);
129+
130+
// A "bundled" version of our d.ts files that includes all public and private
131+
// types, but also include exports marked as @internal
132+
// This file is used by @firebase/database-compat to use internal exports
133+
const untrimmedRollupDtsPath: string = path.resolve(
134+
__dirname,
135+
`../dist/exp/internal.d.ts`
136+
);
137+
138+
// A customer-facing d.ts file that only include the public APIs
139+
const publicDtsPath: string = path.resolve(
140+
__dirname,
141+
`../dist/exp/index.d.ts`
142+
);
143+
144+
console.log(`Running API Extractor configuration for RTDB...`);
145+
writeTypescriptConfig();
146+
writePackageJson();
147+
148+
let extractorConfig = loadApiExtractorConfig(
149+
typescriptDtsPath,
150+
rollupDtsPath,
151+
untrimmedRollupDtsPath,
152+
/* dtsRollupEnabled= */ true,
153+
/* apiReportEnabled= */ false
154+
);
155+
Extractor.invoke(extractorConfig, {
156+
localBuild: true
157+
});
158+
159+
console.log('Generated rollup DTS');
160+
pruneDts(rollupDtsPath, publicDtsPath);
161+
console.log('Pruned DTS file');
162+
await removeUnusedImports(publicDtsPath);
163+
console.log('Removed unused imports');
164+
165+
extractorConfig = loadApiExtractorConfig(
166+
publicDtsPath,
167+
rollupDtsPath,
168+
untrimmedRollupDtsPath,
169+
/* dtsRollupEnabled= */ false,
170+
/* apiReportEnabled= */ true
171+
);
172+
Extractor.invoke(extractorConfig, { localBuild: true });
173+
console.log(`API report for RTDB written to ${reportFolder}`);
174+
}
175+
176+
void generateApi();

packages/database/src/api/Database.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class Database implements FirebaseService, Compat<ExpDatabase> {
5454
*
5555
* <p>Note: This method must be called before performing any other operation.
5656
*
57-
* @param host the emulator host (ex: localhost)
58-
* @param port the emulator port (ex: 8080)
57+
* @param host - the emulator host (ex: localhost)
58+
* @param port - the emulator port (ex: 8080)
5959
*/
6060
useEmulator(host: string, port: number): void {
6161
useDatabaseEmulator(this._delegate, host, port);
@@ -65,7 +65,7 @@ export class Database implements FirebaseService, Compat<ExpDatabase> {
6565
* Returns a reference to the root or to the path specified in the provided
6666
* argument.
6767
*
68-
* @param path The relative string path or an existing Reference to a database
68+
* @param path - The relative string path or an existing Reference to a database
6969
* location.
7070
* @throws If a Reference is provided, throws if it does not belong to the
7171
* same project.

packages/database/src/api/Reference.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ import {
6464
setWithPriority,
6565
remove,
6666
setPriority,
67-
push
67+
push,
68+
ThenableReferenceImpl
6869
} from '../exp/Reference_impl';
6970
import { runTransaction } from '../exp/Transaction';
7071

@@ -123,7 +124,7 @@ export class DataSnapshot implements Compat<ExpDataSnapshot> {
123124
/**
124125
* Returns a DataSnapshot of the specified child node's contents.
125126
*
126-
* @param path Path to a child.
127+
* @param path - Path to a child.
127128
* @returns DataSnapshot for child node.
128129
*/
129130
child(path: string): DataSnapshot {
@@ -137,7 +138,7 @@ export class DataSnapshot implements Compat<ExpDataSnapshot> {
137138
/**
138139
* Returns whether the snapshot contains a child at the specified path.
139140
*
140-
* @param path Path to a child.
141+
* @param path - Path to a child.
141142
* @returns Whether the child exists.
142143
*/
143144
hasChild(path: string): boolean {
@@ -159,7 +160,7 @@ export class DataSnapshot implements Compat<ExpDataSnapshot> {
159160
/**
160161
* Iterates through child nodes and calls the specified action for each one.
161162
*
162-
* @param action Callback function to be called
163+
* @param action - Callback function to be called
163164
* for each child.
164165
* @returns True if forEach was canceled by action returning true for
165166
* one of the child nodes.
@@ -502,7 +503,7 @@ export class Query implements Compat<QueryImpl> {
502503

503504
/**
504505
* Helper used by .on and .once to extract the context and or cancel arguments.
505-
* @param fnName The function name (on or once)
506+
* @param fnName - The function name (on or once)
506507
*
507508
*/
508509
private static getCancelAndContextArgs_(
@@ -743,7 +744,7 @@ export class Reference extends Query implements Compat<ReferenceImpl> {
743744
validateArgCount('Reference.push', 0, 2, arguments.length);
744745
validateCallback('Reference.push', 'onComplete', onComplete, true);
745746

746-
const expPromise = push(this._delegate, value);
747+
const expPromise = push(this._delegate, value) as ThenableReferenceImpl;
747748
const promise = expPromise.then(
748749
expRef => new Reference(this.database, expRef)
749750
);

packages/database/src/api/internal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export const interceptServerData = function (
9393
* Used by console to create a database based on the app,
9494
* passed database URL and a custom auth implementation.
9595
*
96-
* @param app A valid FirebaseApp-like object
97-
* @param url A valid Firebase databaseURL
98-
* @param version custom version e.g. firebase-admin version
99-
* @param customAuthImpl custom auth implementation
96+
* @param app - A valid FirebaseApp-like object
97+
* @param url - A valid Firebase databaseURL
98+
* @param version - custom version e.g. firebase-admin version
99+
* @param customAuthImpl - custom auth implementation
100100
*/
101101
export function initStandalone<T>({
102102
app,

0 commit comments

Comments
 (0)