@firebase/database-compat 0.1.1-2021823172527 → 0.1.2-canary.1048c4f2d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +19 -8
  2. package/dist/database-compat/src/index.d.ts +0 -9
  3. package/dist/database-compat/src/index.node.d.ts +0 -53
  4. package/dist/database-compat/src/index.standalone.d.ts +52 -0
  5. package/dist/index.esm2017.js +5 -6
  6. package/dist/index.esm2017.js.map +1 -1
  7. package/dist/index.esm5.js +2 -3
  8. package/dist/index.esm5.js.map +1 -1
  9. package/dist/index.js +10 -77
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.standalone.js +18731 -0
  12. package/dist/index.standalone.js.map +1 -0
  13. package/package.json +30 -9
  14. package/standalone/package.json +7 -0
  15. package/.eslintrc.js +0 -64
  16. package/karma.conf.js +0 -34
  17. package/rollup.config.js +0 -125
  18. package/src/api/Database.ts +0 -123
  19. package/src/api/Reference.ts +0 -790
  20. package/src/api/TransactionResult.ts +0 -34
  21. package/src/api/internal.ts +0 -91
  22. package/src/api/onDisconnect.ts +0 -112
  23. package/src/index.node.ts +0 -142
  24. package/src/index.ts +0 -88
  25. package/src/util/util.ts +0 -25
  26. package/src/util/validation.ts +0 -59
  27. package/test/browser/crawler_support.test.ts +0 -206
  28. package/test/database.test.ts +0 -306
  29. package/test/datasnapshot.test.ts +0 -249
  30. package/test/helpers/events.ts +0 -258
  31. package/test/helpers/util.ts +0 -177
  32. package/test/info.test.ts +0 -222
  33. package/test/order.test.ts +0 -592
  34. package/test/order_by.test.ts +0 -530
  35. package/test/promise.test.ts +0 -261
  36. package/test/query.test.ts +0 -4670
  37. package/test/servervalues.test.ts +0 -152
  38. package/test/transaction.test.ts +0 -1534
  39. package/tsconfig.json +0 -11
@@ -1,34 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 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 { validateArgCount } from '@firebase/util';
19
-
20
- import { DataSnapshot } from './Reference';
21
-
22
- export class TransactionResult {
23
- /**
24
- * A type for the resolve value of Firebase.transaction.
25
- */
26
- constructor(public committed: boolean, public snapshot: DataSnapshot) {}
27
-
28
- // Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
29
- // for end-users
30
- toJSON(): object {
31
- validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
32
- return { committed: this.committed, snapshot: this.snapshot.toJSON() };
33
- }
34
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 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 { FirebaseApp } from '@firebase/app-types';
19
- import {
20
- FirebaseAuthInternal,
21
- FirebaseAuthInternalName
22
- } from '@firebase/auth-interop-types';
23
- import {
24
- Component,
25
- ComponentContainer,
26
- ComponentType,
27
- Provider
28
- } from '@firebase/component';
29
- import {
30
- _repoManagerDatabaseFromApp,
31
- _setSDKVersion
32
- } from '@firebase/database';
33
- import * as types from '@firebase/database-types';
34
-
35
- import { Database } from './Database';
36
-
37
- /**
38
- * Used by console to create a database based on the app,
39
- * passed database URL and a custom auth implementation.
40
- *
41
- * @param app - A valid FirebaseApp-like object
42
- * @param url - A valid Firebase databaseURL
43
- * @param version - custom version e.g. firebase-admin version
44
- * @param customAuthImpl - custom auth implementation
45
- */
46
- export function initStandalone<T>({
47
- app,
48
- url,
49
- version,
50
- customAuthImpl,
51
- namespace,
52
- nodeAdmin = false
53
- }: {
54
- app: FirebaseApp;
55
- url: string;
56
- version: string;
57
- customAuthImpl: FirebaseAuthInternal;
58
- namespace: T;
59
- nodeAdmin?: boolean;
60
- }): {
61
- instance: types.Database;
62
- namespace: T;
63
- } {
64
- _setSDKVersion(version);
65
-
66
- /**
67
- * ComponentContainer('database-standalone') is just a placeholder that doesn't perform
68
- * any actual function.
69
- */
70
- const authProvider = new Provider<FirebaseAuthInternalName>(
71
- 'auth-internal',
72
- new ComponentContainer('database-standalone')
73
- );
74
- authProvider.setComponent(
75
- new Component('auth-internal', () => customAuthImpl, ComponentType.PRIVATE)
76
- );
77
-
78
- return {
79
- instance: new Database(
80
- _repoManagerDatabaseFromApp(
81
- app,
82
- authProvider,
83
- /* appCheckProvider= */ undefined,
84
- url,
85
- nodeAdmin
86
- ),
87
- app
88
- ) as types.Database,
89
- namespace
90
- };
91
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 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 { OnDisconnect as ModularOnDisconnect } from '@firebase/database';
19
- import { validateArgCount, validateCallback, Compat } from '@firebase/util';
20
-
21
- import { warn } from '../util/util';
22
- export class OnDisconnect implements Compat<ModularOnDisconnect> {
23
- constructor(readonly _delegate: ModularOnDisconnect) {}
24
-
25
- cancel(onComplete?: (a: Error | null) => void): Promise<void> {
26
- validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
27
- validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
28
- const result = this._delegate.cancel();
29
- if (onComplete) {
30
- result.then(
31
- () => onComplete(null),
32
- error => onComplete(error)
33
- );
34
- }
35
- return result;
36
- }
37
-
38
- remove(onComplete?: (a: Error | null) => void): Promise<void> {
39
- validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
40
- validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
41
- const result = this._delegate.remove();
42
- if (onComplete) {
43
- result.then(
44
- () => onComplete(null),
45
- error => onComplete(error)
46
- );
47
- }
48
- return result;
49
- }
50
-
51
- set(value: unknown, onComplete?: (a: Error | null) => void): Promise<void> {
52
- validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
53
- validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
54
- const result = this._delegate.set(value);
55
- if (onComplete) {
56
- result.then(
57
- () => onComplete(null),
58
- error => onComplete(error)
59
- );
60
- }
61
- return result;
62
- }
63
-
64
- setWithPriority(
65
- value: unknown,
66
- priority: number | string | null,
67
- onComplete?: (a: Error | null) => void
68
- ): Promise<void> {
69
- validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
70
- validateCallback(
71
- 'OnDisconnect.setWithPriority',
72
- 'onComplete',
73
- onComplete,
74
- true
75
- );
76
- const result = this._delegate.setWithPriority(value, priority);
77
- if (onComplete) {
78
- result.then(
79
- () => onComplete(null),
80
- error => onComplete(error)
81
- );
82
- }
83
- return result;
84
- }
85
-
86
- update(
87
- objectToMerge: Record<string, unknown>,
88
- onComplete?: (a: Error | null) => void
89
- ): Promise<void> {
90
- validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
91
- if (Array.isArray(objectToMerge)) {
92
- const newObjectToMerge: { [k: string]: unknown } = {};
93
- for (let i = 0; i < objectToMerge.length; ++i) {
94
- newObjectToMerge['' + i] = objectToMerge[i];
95
- }
96
- objectToMerge = newObjectToMerge;
97
- warn(
98
- 'Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the ' +
99
- 'existing data, or an Object with integer keys if you really do want to only update some of the children.'
100
- );
101
- }
102
- validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
103
- const result = this._delegate.update(objectToMerge);
104
- if (onComplete) {
105
- result.then(
106
- () => onComplete(null),
107
- error => onComplete(error)
108
- );
109
- }
110
- return result;
111
- }
112
- }
package/src/index.node.ts DELETED
@@ -1,142 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2021 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 { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
19
- import { _FirebaseNamespace } from '@firebase/app-types/private';
20
- import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
21
- import { Component, ComponentType } from '@firebase/component';
22
- import { enableLogging } from '@firebase/database';
23
- import * as types from '@firebase/database-types';
24
- import { CONSTANTS, isNodeSdk } from '@firebase/util';
25
-
26
- import { name, version } from '../package.json';
27
- import { Database } from '../src/api/Database';
28
- import * as INTERNAL from '../src/api/internal';
29
- import { DataSnapshot, Query, Reference } from '../src/api/Reference';
30
-
31
- const ServerValue = Database.ServerValue;
32
-
33
- /**
34
- * A one off register function which returns a database based on the app and
35
- * passed database URL. (Used by the Admin SDK)
36
- *
37
- * @param app - A valid FirebaseApp-like object
38
- * @param url - A valid Firebase databaseURL
39
- * @param version - custom version e.g. firebase-admin version
40
- * @param nodeAdmin - true if the SDK is being initialized from Firebase Admin.
41
- */
42
- export function initStandalone(
43
- app: FirebaseApp,
44
- url: string,
45
- version: string,
46
- nodeAdmin = true
47
- ) {
48
- CONSTANTS.NODE_ADMIN = nodeAdmin;
49
- return INTERNAL.initStandalone({
50
- app,
51
- url,
52
- version,
53
- // firebase-admin-node's app.INTERNAL implements FirebaseAuthInternal interface
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- customAuthImpl: (app as any).INTERNAL as FirebaseAuthInternal,
56
- namespace: {
57
- Reference,
58
- Query,
59
- Database,
60
- DataSnapshot,
61
- enableLogging,
62
- INTERNAL,
63
- ServerValue
64
- },
65
- nodeAdmin
66
- });
67
- }
68
-
69
- export function registerDatabase(instance: FirebaseNamespace) {
70
- // Register the Database Service with the 'firebase' namespace.
71
- const namespace = (instance as _FirebaseNamespace).INTERNAL.registerComponent(
72
- new Component(
73
- 'database-compat',
74
- (container, { instanceIdentifier: url }) => {
75
- /* Dependencies */
76
- // getImmediate for FirebaseApp will always succeed
77
- const app = container.getProvider('app-compat').getImmediate();
78
- const databaseExp = container
79
- .getProvider('database')
80
- .getImmediate({ identifier: url });
81
- return new Database(databaseExp, app);
82
- },
83
- ComponentType.PUBLIC
84
- )
85
- .setServiceProps(
86
- // firebase.database namespace properties
87
- {
88
- Reference,
89
- Query,
90
- Database,
91
- DataSnapshot,
92
- enableLogging,
93
- INTERNAL,
94
- ServerValue
95
- }
96
- )
97
- .setMultipleInstances(true)
98
- );
99
-
100
- instance.registerVersion(name, version, 'node');
101
-
102
- if (isNodeSdk()) {
103
- module.exports = Object.assign({}, namespace, { initStandalone });
104
- }
105
- }
106
-
107
- try {
108
- // If @firebase/app is not present, skip registering database.
109
- // It could happen when this package is used in firebase-admin which doesn't depend on @firebase/app.
110
- // Previously firebase-admin depends on @firebase/app, which causes version conflict on
111
- // @firebase/app when used together with the js sdk. More detail:
112
- // https://github.com/firebase/firebase-js-sdk/issues/1696#issuecomment-501546596
113
- // eslint-disable-next-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports
114
- const firebase = require('@firebase/app-compat').default;
115
- registerDatabase(firebase);
116
- } catch (err) {
117
- // catch and ignore 'MODULE_NOT_FOUND' error in firebase-admin context
118
- // we can safely ignore this error because RTDB in firebase-admin works without @firebase/app
119
- if (err.code !== 'MODULE_NOT_FOUND') {
120
- throw err;
121
- }
122
- }
123
-
124
- // Types to export for the admin SDK
125
- export { Database, Query, Reference, enableLogging, ServerValue };
126
-
127
- export { OnDisconnect } from '@firebase/database';
128
-
129
- declare module '@firebase/app-compat' {
130
- interface FirebaseNamespace {
131
- database?: {
132
- (app?: FirebaseApp): types.FirebaseDatabase;
133
- enableLogging: typeof types.enableLogging;
134
- ServerValue: types.ServerValue;
135
- Database: typeof types.FirebaseDatabase;
136
- };
137
- }
138
- interface FirebaseApp {
139
- database?(): types.FirebaseDatabase;
140
- }
141
- }
142
- export { DataSnapshot } from '../src/api/Reference';
package/src/index.ts DELETED
@@ -1,88 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2021 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
- // eslint-disable-next-line import/no-extraneous-dependencies
19
- import firebase, { FirebaseNamespace } from '@firebase/app-compat';
20
- import { _FirebaseNamespace } from '@firebase/app-types/private';
21
- import { Component, ComponentType } from '@firebase/component';
22
- import { enableLogging } from '@firebase/database';
23
- import * as types from '@firebase/database-types';
24
-
25
- import { name, version } from '../package.json';
26
- import { Database as DatabaseCompat } from '../src/api/Database';
27
- import * as INTERNAL from '../src/api/internal';
28
- // rename the imports to avoid conflicts with imports that will be added by "yarn add-compat-overloads" during a release build
29
- import { DataSnapshot as DataSnapshotCompat, Query as QueryCompat, Reference } from '../src/api/Reference';
30
-
31
- const ServerValue = DatabaseCompat.ServerValue;
32
-
33
- export function registerDatabase(instance: FirebaseNamespace) {
34
- // Register the Database Service with the 'firebase' namespace.
35
- const namespace = (
36
- instance as unknown as _FirebaseNamespace
37
- ).INTERNAL.registerComponent(
38
- new Component(
39
- 'database-compat',
40
- (container, { instanceIdentifier: url }) => {
41
- /* Dependencies */
42
- // getImmediate for FirebaseApp will always succeed
43
- const app = container.getProvider('app-compat').getImmediate();
44
- const databaseExp = container
45
- .getProvider('database')
46
- .getImmediate({ identifier: url });
47
- return new DatabaseCompat(databaseExp, app);
48
- },
49
- ComponentType.PUBLIC
50
- )
51
- .setServiceProps(
52
- // firebase.database namespace properties
53
- {
54
- Reference,
55
- Query: QueryCompat,
56
- Database: DatabaseCompat,
57
- DataSnapshot: DataSnapshotCompat,
58
- enableLogging,
59
- INTERNAL,
60
- ServerValue
61
- }
62
- )
63
- .setMultipleInstances(true)
64
- );
65
-
66
- instance.registerVersion(name, version);
67
- }
68
-
69
- registerDatabase(firebase);
70
-
71
- // Types to export for the admin SDK. They are exported here in the browser entry point only for types
72
- // The same symbol should be exported from the node entry point so their values can be accessed at runtime by admin SDK
73
- export { DatabaseCompat as Database, QueryCompat as Query, Reference, enableLogging, ServerValue, DataSnapshotCompat as DataSnapshot };
74
- export { OnDisconnect } from '@firebase/database';
75
-
76
- declare module '@firebase/app-compat' {
77
- interface FirebaseNamespace {
78
- database?: {
79
- (app?: FirebaseApp): types.FirebaseDatabase;
80
- enableLogging: typeof types.enableLogging;
81
- ServerValue: types.ServerValue;
82
- Database: typeof types.FirebaseDatabase;
83
- };
84
- }
85
- interface FirebaseApp {
86
- database?(databaseURL?: string): types.FirebaseDatabase;
87
- }
88
- }
package/src/util/util.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2021 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 { Logger } from '@firebase/logger';
19
-
20
- const logClient = new Logger('@firebase/database-compat');
21
-
22
- export const warn = function (msg: string) {
23
- const message = 'FIREBASE WARNING: ' + msg;
24
- logClient.warn(message);
25
- };
@@ -1,59 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2021 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 { errorPrefix as errorPrefixFxn } from '@firebase/util';
19
-
20
- export const validateBoolean = function (
21
- fnName: string,
22
- argumentName: string,
23
- bool: unknown,
24
- optional: boolean
25
- ) {
26
- if (optional && bool === undefined) {
27
- return;
28
- }
29
- if (typeof bool !== 'boolean') {
30
- throw new Error(
31
- errorPrefixFxn(fnName, argumentName) + 'must be a boolean.'
32
- );
33
- }
34
- };
35
-
36
- export const validateEventType = function (
37
- fnName: string,
38
- eventType: string,
39
- optional: boolean
40
- ) {
41
- if (optional && eventType === undefined) {
42
- return;
43
- }
44
-
45
- switch (eventType) {
46
- case 'value':
47
- case 'child_added':
48
- case 'child_removed':
49
- case 'child_changed':
50
- case 'child_moved':
51
- break;
52
- default:
53
- throw new Error(
54
- errorPrefixFxn(fnName, 'eventType') +
55
- 'must be a valid event type = "value", "child_added", "child_removed", ' +
56
- '"child_changed", or "child_moved".'
57
- );
58
- }
59
- };