@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,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
- });
@@ -1,306 +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 firebase from '@firebase/app-compat';
19
- import { expect } from 'chai';
20
-
21
- import { DATABASE_ADDRESS, createTestApp } from './helpers/util';
22
- import '../src/index';
23
-
24
- describe('Database Tests', () => {
25
- let defaultApp;
26
-
27
- beforeEach(() => {
28
- defaultApp = createTestApp();
29
- });
30
-
31
- afterEach(() => {
32
- return defaultApp.delete();
33
- });
34
-
35
- it('Can get database.', () => {
36
- const db = (firebase as any).database();
37
- expect(db).to.not.be.undefined;
38
- expect(db).not.to.be.null;
39
- });
40
-
41
- it('Can get database with custom URL', () => {
42
- const db = defaultApp.database('http://foo.bar.com');
43
- expect(db).to.be.ok;
44
- // The URL is assumed to be secure if no port is specified.
45
- expect(db.ref().toString()).to.equal('https://foo.bar.com/');
46
- });
47
-
48
- it('Can get database with custom URL and port', () => {
49
- const db = defaultApp.database('http://foo.bar.com:80');
50
- expect(db).to.be.ok;
51
- expect(db.ref().toString()).to.equal('http://foo.bar.com:80/');
52
- });
53
-
54
- it('Can get database with https URL', () => {
55
- const db = defaultApp.database('https://foo.bar.com');
56
- expect(db).to.be.ok;
57
- expect(db.ref().toString()).to.equal('https://foo.bar.com/');
58
- });
59
-
60
- it('Can get database with multi-region URL', () => {
61
- const db = defaultApp.database('http://foo.euw1.firebasedatabase.app');
62
- expect(db).to.be.ok;
63
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
64
- expect(db.ref().toString()).to.equal(
65
- 'https://foo.euw1.firebasedatabase.app/'
66
- );
67
- });
68
-
69
- it('Can get database with upper case URL', () => {
70
- const db = defaultApp.database('http://fOO.EUW1.firebaseDATABASE.app');
71
- expect(db).to.be.ok;
72
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
73
- expect(db.ref().toString()).to.equal(
74
- 'https://foo.euw1.firebasedatabase.app/'
75
- );
76
- });
77
-
78
- it('Can get database with localhost URL', () => {
79
- const db = defaultApp.database('http://localhost');
80
- expect(db).to.be.ok;
81
- expect(db.ref().toString()).to.equal('https://localhost/');
82
- });
83
-
84
- it('Can get database with localhost URL and port', () => {
85
- const db = defaultApp.database('http://localhost:80');
86
- expect(db).to.be.ok;
87
- expect(db.ref().toString()).to.equal('http://localhost:80/');
88
- });
89
-
90
- it('Can get database with a upper case localhost URL', () => {
91
- const db = defaultApp.database('http://LOCALHOST');
92
- expect(db).to.be.ok;
93
- expect(db.ref().toString()).to.equal('https://localhost/');
94
- });
95
-
96
- it('Can get database with a upper case localhost URL and ns', () => {
97
- const db = defaultApp.database('http://LOCALHOST?ns=foo');
98
- expect(db).to.be.ok;
99
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
100
- expect(db.ref().toString()).to.equal('https://localhost/');
101
- });
102
-
103
- it('Can infer database URL from project Id', async () => {
104
- const app = firebase.initializeApp(
105
- { projectId: 'abc123' },
106
- 'project-id-app'
107
- );
108
- const db = app.database();
109
- expect(db).to.be.ok;
110
- // The URL is assumed to be secure if no port is specified.
111
- expect(db.ref().toString()).to.equal(
112
- 'https://abc123-default-rtdb.firebaseio.com/'
113
- );
114
- await app.delete();
115
- });
116
-
117
- it('Can read ns query param', () => {
118
- const db = defaultApp.database('http://localhost:80/?ns=foo&unused=true');
119
- expect(db).to.be.ok;
120
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
121
- expect(db.ref().toString()).to.equal('http://localhost:80/');
122
- });
123
-
124
- it('Reads ns query param even when subdomain is set', () => {
125
- const db = defaultApp.database('http://bar.firebaseio.com?ns=foo');
126
- expect(db).to.be.ok;
127
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('foo');
128
- expect(db.ref().toString()).to.equal('https://bar.firebaseio.com/');
129
- });
130
-
131
- it('Interprets FIREBASE_DATABASE_EMULATOR_HOST var correctly', () => {
132
- process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
133
- const db = defaultApp.database('https://bar.firebaseio.com');
134
- expect(db).to.be.ok;
135
- expect(db._delegate._repo.repoInfo_.namespace).to.equal('bar');
136
- expect(db._delegate._repo.repoInfo_.host).to.equal('localhost:9000');
137
- delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
138
- });
139
-
140
- it('Different instances for different URLs', () => {
141
- const db1 = defaultApp.database('http://foo1.bar.com');
142
- const db2 = defaultApp.database('http://foo2.bar.com');
143
- expect(db1.ref().toString()).to.equal('https://foo1.bar.com/');
144
- expect(db2.ref().toString()).to.equal('https://foo2.bar.com/');
145
- });
146
-
147
- it('Different instances for different URLs (with FIREBASE_DATABASE_EMULATOR_HOST)', () => {
148
- process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
149
- const db1 = defaultApp.database('http://foo1.bar.com');
150
- const db2 = defaultApp.database('http://foo2.bar.com');
151
- expect(db1._delegate._repo.repoInfo_.toURLString()).to.equal(
152
- 'http://localhost:9000/?ns=foo1'
153
- );
154
- expect(db2._delegate._repo.repoInfo_.toURLString()).to.equal(
155
- 'http://localhost:9000/?ns=foo2'
156
- );
157
- delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
158
- });
159
-
160
- it('Cannot use same URL twice', () => {
161
- defaultApp.database('http://foo.bar.com');
162
- expect(() => {
163
- defaultApp.database('http://foo.bar.com/');
164
- }).to.throw(/Database initialized multiple times/i);
165
- });
166
-
167
- it('Cannot use same URL twice (with FIREBASE_DATABASE_EMULATOR_HOST)', () => {
168
- process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
169
- defaultApp.database('http://foo.bar.com');
170
- expect(() => {
171
- defaultApp.database('http://foo.bar.com/');
172
- }).to.throw(/Database initialized multiple times/i);
173
- delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
174
- });
175
-
176
- it('Databases with legacy domain', () => {
177
- expect(() => {
178
- defaultApp.database('http://foo.firebase.com/');
179
- }).to.throw(/is no longer supported/i);
180
- });
181
-
182
- it('Databases with invalid custom URLs', () => {
183
- expect(() => {
184
- defaultApp.database('not-a-url');
185
- }).to.throw(/Cannot parse Firebase url/i);
186
- expect(() => {
187
- defaultApp.database('http://foo.com');
188
- }).to.throw(/Cannot parse Firebase url/i);
189
- expect(() => {
190
- defaultApp.database('http://fblocal.com');
191
- }).to.throw(/Cannot parse Firebase url/i);
192
- expect(() => {
193
- defaultApp.database('http://x.fblocal.com:9000/paths/are/bad');
194
- }).to.throw(/Database URL must point to the root of a Firebase Database/i);
195
- });
196
-
197
- it('Can get app', () => {
198
- const db = (firebase as any).database();
199
- expect(db.app).to.not.be.undefined;
200
- expect((db.app as any) instanceof firebase.app.App);
201
- });
202
-
203
- it('Can get root ref', () => {
204
- const db = (firebase as any).database();
205
-
206
- const ref = db.ref();
207
-
208
- expect(ref instanceof (firebase as any).database.Reference).to.be.true;
209
- expect(ref.key).to.be.null;
210
- });
211
-
212
- it('Can get child ref', () => {
213
- const db = (firebase as any).database();
214
-
215
- const ref = db.ref('child');
216
-
217
- expect(ref instanceof (firebase as any).database.Reference).to.be.true;
218
- expect(ref.key).to.equal('child');
219
- });
220
-
221
- it('Can get deep child ref', () => {
222
- const db = (firebase as any).database();
223
-
224
- const ref = db.ref('child/grand-child');
225
-
226
- expect(ref instanceof (firebase as any).database.Reference).to.be.true;
227
- expect(ref.key).to.equal('grand-child');
228
- });
229
-
230
- it('Can get ref from ref', () => {
231
- const db1 = (firebase as any).database();
232
- const db2 = (firebase as any).database();
233
-
234
- const ref1 = db1.ref('child');
235
- const ref2 = db2.ref(ref1);
236
-
237
- expect(ref1.key).to.equal('child');
238
- expect(ref2.key).to.equal('child');
239
- });
240
-
241
- it('ref() validates arguments', () => {
242
- const db = (firebase as any).database();
243
- expect(() => {
244
- const ref = (db as any).ref('path', 'extra');
245
- }).to.throw(/Expects no more than 1/);
246
- });
247
-
248
- it('ref() validates project', () => {
249
- const db1 = defaultApp.database('http://bar.firebaseio.com');
250
- const db2 = defaultApp.database('http://foo.firebaseio.com');
251
-
252
- const ref1 = db1.ref('child');
253
-
254
- expect(() => {
255
- db2.ref(ref1);
256
- }).to.throw(/does not match.*database/i);
257
- });
258
-
259
- it('Can get refFromURL()', () => {
260
- const db = (firebase as any).database();
261
- const ref = db.refFromURL(DATABASE_ADDRESS + '/path/to/data');
262
- expect(ref.key).to.equal('data');
263
- });
264
-
265
- it('refFromURL() validates domain', () => {
266
- const db = (firebase as any)
267
- .app()
268
- .database('https://thisisreal.firebaseio.com');
269
- expect(() =>
270
- db.refFromURL('https://thisisnotreal.firebaseio.com/path/to/data')
271
- ).to.throw(/does not match.*database/i);
272
- });
273
-
274
- it('refFromURL() validates argument', () => {
275
- const db = (firebase as any).database();
276
- expect(() => {
277
- const ref = (db as any).refFromURL();
278
- }).to.throw(/Expects at least 1/);
279
- });
280
-
281
- it('can call useEmulator before use', () => {
282
- const db = (firebase as any).database();
283
- db.useEmulator('localhost', 1234);
284
- expect(db.ref().toString()).to.equal('http://localhost:1234/');
285
- });
286
-
287
- it('cannot call useEmulator after use', () => {
288
- const db = (firebase as any).database();
289
-
290
- db.ref().set({
291
- hello: 'world'
292
- });
293
-
294
- expect(() => {
295
- db.useEmulator('localhost', 1234);
296
- }).to.throw(/Cannot call useEmulator/);
297
- });
298
-
299
- it('refFromURL returns an emulated ref with useEmulator', () => {
300
- const db = (firebase as any).database();
301
- db.useEmulator('localhost', 1234);
302
-
303
- const ref = db.refFromURL(DATABASE_ADDRESS + '/path/to/data');
304
- expect(ref.toString()).to.equal(`http://localhost:1234/path/to/data`);
305
- });
306
- });