@firebase/database-compat 0.1.1-2021823172527 → 0.1.2-canary.0b3ca78eb

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 (61) 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 +15150 -0
  12. package/dist/index.standalone.js.map +1 -0
  13. package/dist/node-esm/database-compat/src/api/Database.d.ts +72 -0
  14. package/dist/node-esm/database-compat/src/api/Reference.d.ts +201 -0
  15. package/{karma.conf.js → dist/node-esm/database-compat/src/api/TransactionResult.d.ts} +26 -34
  16. package/dist/node-esm/database-compat/src/api/internal.d.ts +39 -0
  17. package/dist/node-esm/database-compat/src/api/onDisconnect.d.ts +27 -0
  18. package/dist/node-esm/database-compat/src/index.d.ts +32 -0
  19. package/dist/node-esm/database-compat/src/index.node.d.ts +14 -0
  20. package/dist/node-esm/database-compat/src/index.standalone.d.ts +52 -0
  21. package/{src/util/util.ts → dist/node-esm/database-compat/src/util/util.d.ts} +17 -25
  22. package/dist/node-esm/database-compat/src/util/validation.d.ts +18 -0
  23. package/{src/api/TransactionResult.ts → dist/node-esm/database-compat/test/browser/crawler_support.test.d.ts} +17 -34
  24. package/dist/node-esm/database-compat/test/database.test.d.ts +17 -0
  25. package/dist/node-esm/database-compat/test/datasnapshot.test.d.ts +17 -0
  26. package/dist/node-esm/database-compat/test/helpers/events.d.ts +34 -0
  27. package/dist/node-esm/database-compat/test/helpers/util.d.ts +42 -0
  28. package/dist/node-esm/database-compat/test/info.test.d.ts +17 -0
  29. package/dist/node-esm/database-compat/test/order.test.d.ts +17 -0
  30. package/dist/node-esm/database-compat/test/order_by.test.d.ts +17 -0
  31. package/dist/node-esm/database-compat/test/promise.test.d.ts +17 -0
  32. package/dist/node-esm/database-compat/test/query.test.d.ts +17 -0
  33. package/dist/node-esm/database-compat/test/servervalues.test.d.ts +17 -0
  34. package/dist/node-esm/database-compat/test/transaction.test.d.ts +17 -0
  35. package/dist/node-esm/index.js +868 -0
  36. package/dist/node-esm/index.js.map +1 -0
  37. package/dist/node-esm/package.json +1 -0
  38. package/package.json +34 -9
  39. package/standalone/package.json +7 -0
  40. package/.eslintrc.js +0 -64
  41. package/rollup.config.js +0 -125
  42. package/src/api/Database.ts +0 -123
  43. package/src/api/Reference.ts +0 -790
  44. package/src/api/internal.ts +0 -91
  45. package/src/api/onDisconnect.ts +0 -112
  46. package/src/index.node.ts +0 -142
  47. package/src/index.ts +0 -88
  48. package/src/util/validation.ts +0 -59
  49. package/test/browser/crawler_support.test.ts +0 -206
  50. package/test/database.test.ts +0 -306
  51. package/test/datasnapshot.test.ts +0 -249
  52. package/test/helpers/events.ts +0 -258
  53. package/test/helpers/util.ts +0 -177
  54. package/test/info.test.ts +0 -222
  55. package/test/order.test.ts +0 -592
  56. package/test/order_by.test.ts +0 -530
  57. package/test/promise.test.ts +0 -261
  58. package/test/query.test.ts +0 -4670
  59. package/test/servervalues.test.ts +0 -152
  60. package/test/transaction.test.ts +0 -1534
  61. package/tsconfig.json +0 -11
@@ -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
- }
@@ -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
- };
@@ -1,206 +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 { _TEST_ACCESS_forceRestClient as forceRestClient } from '@firebase/database';
19
- import { expect } from 'chai';
20
-
21
- import { getRandomNode, getFreshRepoFromReference } from '../helpers/util';
22
-
23
- // Some sanity checks for the ReadonlyRestClient crawler support.
24
- describe('Crawler Support', () => {
25
- let initialData;
26
- let normalRef;
27
- let restRef;
28
-
29
- beforeEach(done => {
30
- normalRef = getRandomNode();
31
-
32
- forceRestClient(true);
33
- restRef = getFreshRepoFromReference(normalRef);
34
- forceRestClient(false);
35
-
36
- setInitialData(done);
37
- });
38
-
39
- function setInitialData(done) {
40
- // Set some initial data.
41
- initialData = {
42
- leaf: 42,
43
- securedLeaf: 'secret',
44
- leafWithPriority: { '.value': 42, '.priority': 'pri' },
45
- obj: { a: 1, b: 2 },
46
- list: {
47
- 10: { name: 'amy', age: 75, '.priority': 22 },
48
- 20: { name: 'becky', age: 42, '.priority': 52 },
49
- 30: { name: 'fred', age: 35, '.priority': 23 },
50
- 40: { name: 'fred', age: 29, '.priority': 26 },
51
- 50: { name: 'sally', age: 21, '.priority': 96 },
52
- 60: { name: 'tom', age: 16, '.priority': 15 },
53
- 70: { name: 'victor', age: 4, '.priority': 47 }
54
- },
55
- valueList: {
56
- 10: 'c',
57
- 20: 'b',
58
- 30: 'e',
59
- 40: 'f',
60
- 50: 'a',
61
- 60: 'd',
62
- 70: 'e'
63
- }
64
- };
65
-
66
- return normalRef.set(initialData, error => {
67
- expect(error).to.not.be.ok;
68
- done();
69
- });
70
- }
71
-
72
- it('set() is a no-op', done => {
73
- normalRef.child('leaf').on('value', s => {
74
- expect(s.val()).to.equal(42);
75
- });
76
-
77
- restRef.child('leaf').set('hello');
78
-
79
- // We need to wait long enough to be sure that our 'hello' didn't actually get set, but there's
80
- // no good way to do that. So we just do a couple round-trips via the REST client and assume
81
- // that's good enough.
82
- restRef.child('obj').once('value', s => {
83
- expect(s.val()).to.deep.equal(initialData.obj);
84
-
85
- restRef.child('obj').once('value', s => {
86
- expect(s.val()).to.deep.equal(initialData.obj);
87
-
88
- normalRef.child('leaf').off();
89
- done();
90
- });
91
- });
92
- });
93
-
94
- it('set() is a no-op (Promise)', () => {
95
- // This test mostly exists to make sure restRef really is using ReadonlyRestClient
96
- // and we're not accidentally testing a normal Firebase connection.
97
-
98
- normalRef.child('leaf').on('value', s => {
99
- expect(s.val()).to.equal(42);
100
- });
101
-
102
- restRef.child('leaf').set('hello');
103
-
104
- // We need to wait long enough to be sure that our 'hello' didn't actually get set, but there's
105
- // no good way to do that. So we just do a couple round-trips via the REST client and assume
106
- // that's good enough.
107
- return restRef
108
- .child('obj')
109
- .once('value')
110
- .then(s => {
111
- expect(s.val()).to.deep.equal(initialData.obj);
112
-
113
- return restRef.child('obj').once('value');
114
- })
115
- .then(
116
- s => {
117
- expect(s.val()).to.deep.equal(initialData.obj);
118
- normalRef.child('leaf').off();
119
- },
120
- reason => {
121
- normalRef.child('leaf').off();
122
- return Promise.reject(reason);
123
- }
124
- );
125
- });
126
-
127
- it('.info/connected fires with true', done => {
128
- restRef.root.child('.info/connected').on('value', s => {
129
- if (s.val() === true) {
130
- done();
131
- }
132
- });
133
- });
134
-
135
- it('Leaf read works.', done => {
136
- restRef.child('leaf').once('value', s => {
137
- expect(s.val()).to.equal(initialData.leaf);
138
- done();
139
- });
140
- });
141
-
142
- it('Leaf read works. (Promise)', () => {
143
- return restRef
144
- .child('leaf')
145
- .once('value')
146
- .then(s => {
147
- expect(s.val()).to.equal(initialData.leaf);
148
- });
149
- });
150
-
151
- it('Object read works.', done => {
152
- restRef.child('obj').once('value', s => {
153
- expect(s.val()).to.deep.equal(initialData.obj);
154
- done();
155
- });
156
- });
157
-
158
- it('Object read works. (Promise)', () => {
159
- return restRef
160
- .child('obj')
161
- .once('value')
162
- .then(s => {
163
- expect(s.val()).to.deep.equal(initialData.obj);
164
- });
165
- });
166
-
167
- it('Leaf with priority read works.', done => {
168
- restRef.child('leafWithPriority').once('value', s => {
169
- expect(s.exportVal()).to.deep.equal(initialData.leafWithPriority);
170
- done();
171
- });
172
- });
173
-
174
- it('Leaf with priority read works. (Promise)', () => {
175
- return restRef
176
- .child('leafWithPriority')
177
- .once('value')
178
- .then(s => {
179
- expect(s.exportVal()).to.deep.equal(initialData.leafWithPriority);
180
- });
181
- });
182
-
183
- it('Null read works.', done => {
184
- restRef.child('nonexistent').once('value', s => {
185
- expect(s.val()).to.equal(null);
186
- done();
187
- });
188
- });
189
-
190
- it('Null read works. (Promise)', () => {
191
- return restRef
192
- .child('nonexistent')
193
- .once('value')
194
- .then(s => {
195
- expect(s.val()).to.equal(null);
196
- });
197
- });
198
-
199
- it('on works.', done => {
200
- restRef.child('leaf').on('value', s => {
201
- expect(s.val()).to.equal(initialData.leaf);
202
- restRef.child('leaf').off();
203
- done();
204
- });
205
- });
206
- });