@react-native-firebase/app 20.0.0 → 20.2.0
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.
- package/CHANGELOG.md +26 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +1 -1
- package/ios/RNFBApp/RNFBVersion.m +1 -1
- package/lib/common/index.js +2 -0
- package/lib/index.d.ts +1 -0
- package/lib/internal/RNFBNativeEventEmitter.js +31 -6
- package/lib/internal/nativeModule.android.js +2 -0
- package/lib/internal/nativeModule.ios.js +2 -0
- package/lib/internal/nativeModule.js +4 -0
- package/lib/internal/nativeModuleAndroidIos.js +45 -0
- package/lib/internal/nativeModuleWeb.js +48 -0
- package/lib/internal/registry/app.js +2 -1
- package/lib/internal/registry/nativeModule.js +11 -15
- package/lib/internal/web/RNFBAppModule.js +266 -0
- package/lib/internal/web/firebaseApp.js +3 -0
- package/lib/internal/web/firebaseAppCheck.js +6 -0
- package/lib/internal/web/firebaseAuth.js +4 -0
- package/lib/internal/web/firebaseDatabase.js +4 -0
- package/lib/internal/web/firebaseFirestore.js +4 -0
- package/lib/internal/web/firebaseFunctions.js +4 -0
- package/lib/internal/web/firebaseInstallations.js +6 -0
- package/lib/internal/web/firebaseRemoteConfig.js +6 -0
- package/lib/internal/web/firebaseStorage.js +4 -0
- package/lib/internal/web/memidb/FDBCursor.js +503 -0
- package/lib/internal/web/memidb/FDBCursorWithValue.js +11 -0
- package/lib/internal/web/memidb/FDBDatabase.js +172 -0
- package/lib/internal/web/memidb/FDBFactory.js +256 -0
- package/lib/internal/web/memidb/FDBIndex.js +187 -0
- package/lib/internal/web/memidb/FDBKeyRange.js +71 -0
- package/lib/internal/web/memidb/FDBObjectStore.js +411 -0
- package/lib/internal/web/memidb/FDBOpenDBRequest.js +9 -0
- package/lib/internal/web/memidb/FDBRequest.js +33 -0
- package/lib/internal/web/memidb/FDBTransaction.js +216 -0
- package/lib/internal/web/memidb/FDBVersionChangeEvent.js +12 -0
- package/lib/internal/web/memidb/LICENSE +208 -0
- package/lib/internal/web/memidb/index.js +39 -0
- package/lib/internal/web/memidb/lib/Database.js +32 -0
- package/lib/internal/web/memidb/lib/FakeDOMStringList.js +72 -0
- package/lib/internal/web/memidb/lib/FakeEvent.js +38 -0
- package/lib/internal/web/memidb/lib/FakeEventTarget.js +110 -0
- package/lib/internal/web/memidb/lib/Index.js +157 -0
- package/lib/internal/web/memidb/lib/KeyGenerator.js +22 -0
- package/lib/internal/web/memidb/lib/ObjectStore.js +172 -0
- package/lib/internal/web/memidb/lib/RecordStore.js +141 -0
- package/lib/internal/web/memidb/lib/binarySearch.js +78 -0
- package/lib/internal/web/memidb/lib/canInjectKey.js +25 -0
- package/lib/internal/web/memidb/lib/cmp.js +77 -0
- package/lib/internal/web/memidb/lib/enforceRange.js +13 -0
- package/lib/internal/web/memidb/lib/errors.js +69 -0
- package/lib/internal/web/memidb/lib/extractKey.js +39 -0
- package/lib/internal/web/memidb/lib/scheduling.js +30 -0
- package/lib/internal/web/memidb/lib/types.js +1 -0
- package/lib/internal/web/memidb/lib/validateKeyPath.js +54 -0
- package/lib/internal/web/memidb/lib/valueToKey.js +62 -0
- package/lib/internal/web/memidb/lib/valueToKeyRange.js +19 -0
- package/lib/internal/web/structuredClone/index.js +222 -0
- package/lib/internal/web/utils.js +35 -0
- package/lib/utils/UtilsStatics.js +3 -2
- package/lib/version.js +1 -1
- package/package.json +9 -8
@@ -0,0 +1,208 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
13
|
+
copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
16
|
+
entities that control, are controlled by, or are under common control with
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of
|
20
|
+
fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
|
21
|
+
ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
24
|
+
permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation source,
|
28
|
+
and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
31
|
+
or translation of a Source form, including but not limited to compiled
|
32
|
+
object code, generated documentation, and conversions to
|
33
|
+
other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or Object
|
36
|
+
form, made available under the License, as indicated by a copyright notice
|
37
|
+
that is included in or attached to the work (an example is provided in the
|
38
|
+
Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
41
|
+
that is based on (or derived from) the Work and for which the editorial
|
42
|
+
revisions, annotations, elaborations, or other modifications represent,
|
43
|
+
as a whole, an original work of authorship. For the purposes of this
|
44
|
+
License, Derivative Works shall not include works that remain separable
|
45
|
+
from, or merely link (or bind by name) to the interfaces of, the Work and
|
46
|
+
Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including the original
|
49
|
+
version of the Work and any modifications or additions to that Work or
|
50
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
51
|
+
inclusion in the Work by the copyright owner or by an individual or
|
52
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
53
|
+
For the purposes of this definition, "submitted" means any form of
|
54
|
+
electronic, verbal, or written communication sent to the Licensor or its
|
55
|
+
representatives, including but not limited to communication on electronic
|
56
|
+
mailing lists, source code control systems, and issue tracking systems
|
57
|
+
that are managed by, or on behalf of, the Licensor for the purpose of
|
58
|
+
discussing and improving the Work, but excluding communication that is
|
59
|
+
conspicuously marked or otherwise designated in writing by the copyright
|
60
|
+
owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
63
|
+
behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License.
|
67
|
+
|
68
|
+
Subject to the terms and conditions of this License, each Contributor
|
69
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
70
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
71
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
72
|
+
and distribute the Work and such Derivative Works in
|
73
|
+
Source or Object form.
|
74
|
+
|
75
|
+
3. Grant of Patent License.
|
76
|
+
|
77
|
+
Subject to the terms and conditions of this License, each Contributor
|
78
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
79
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
80
|
+
license to make, have made, use, offer to sell, sell, import, and
|
81
|
+
otherwise transfer the Work, where such license applies only to those
|
82
|
+
patent claims licensable by such Contributor that are necessarily
|
83
|
+
infringed by their Contribution(s) alone or by combination of their
|
84
|
+
Contribution(s) with the Work to which such Contribution(s) was submitted.
|
85
|
+
If You institute patent litigation against any entity (including a
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
87
|
+
Contribution incorporated within the Work constitutes direct or
|
88
|
+
contributory patent infringement, then any patent licenses granted to
|
89
|
+
You under this License for that Work shall terminate as of the date such
|
90
|
+
litigation is filed.
|
91
|
+
|
92
|
+
4. Redistribution.
|
93
|
+
|
94
|
+
You may reproduce and distribute copies of the Work or Derivative Works
|
95
|
+
thereof in any medium, with or without modifications, and in Source or
|
96
|
+
Object form, provided that You meet the following conditions:
|
97
|
+
|
98
|
+
1. You must give any other recipients of the Work or Derivative Works a
|
99
|
+
copy of this License; and
|
100
|
+
|
101
|
+
2. You must cause any modified files to carry prominent notices stating
|
102
|
+
that You changed the files; and
|
103
|
+
|
104
|
+
3. You must retain, in the Source form of any Derivative Works that You
|
105
|
+
distribute, all copyright, patent, trademark, and attribution notices from
|
106
|
+
the Source form of the Work, excluding those notices that do not pertain
|
107
|
+
to any part of the Derivative Works; and
|
108
|
+
|
109
|
+
4. If the Work includes a "NOTICE" text file as part of its distribution,
|
110
|
+
then any Derivative Works that You distribute must include a readable copy
|
111
|
+
of the attribution notices contained within such NOTICE file, excluding
|
112
|
+
those notices that do not pertain to any part of the Derivative Works,
|
113
|
+
in at least one of the following places: within a NOTICE text file
|
114
|
+
distributed as part of the Derivative Works; within the Source form or
|
115
|
+
documentation, if provided along with the Derivative Works; or, within a
|
116
|
+
display generated by the Derivative Works, if and wherever such
|
117
|
+
third-party notices normally appear. The contents of the NOTICE file are
|
118
|
+
for informational purposes only and do not modify the License.
|
119
|
+
You may add Your own attribution notices within Derivative Works that You
|
120
|
+
distribute, alongside or as an addendum to the NOTICE text from the Work,
|
121
|
+
provided that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and may
|
125
|
+
provide additional or different license terms and conditions for use,
|
126
|
+
reproduction, or distribution of Your modifications, or for any such
|
127
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
128
|
+
distribution of the Work otherwise complies with the conditions
|
129
|
+
stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions.
|
132
|
+
|
133
|
+
Unless You explicitly state otherwise, any Contribution intentionally
|
134
|
+
submitted for inclusion in the Work by You to the Licensor shall be under
|
135
|
+
the terms and conditions of this License, without any additional
|
136
|
+
terms or conditions. Notwithstanding the above, nothing herein shall
|
137
|
+
supersede or modify the terms of any separate license agreement you may
|
138
|
+
have executed with Licensor regarding such Contributions.
|
139
|
+
|
140
|
+
6. Trademarks.
|
141
|
+
|
142
|
+
This License does not grant permission to use the trade names, trademarks,
|
143
|
+
service marks, or product names of the Licensor, except as required for
|
144
|
+
reasonable and customary use in describing the origin of the Work and
|
145
|
+
reproducing the content of the NOTICE file.
|
146
|
+
|
147
|
+
7. Disclaimer of Warranty.
|
148
|
+
|
149
|
+
Unless required by applicable law or agreed to in writing, Licensor
|
150
|
+
provides the Work (and each Contributor provides its Contributions)
|
151
|
+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
152
|
+
either express or implied, including, without limitation, any warranties
|
153
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
|
154
|
+
FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
|
155
|
+
appropriateness of using or redistributing the Work and assume any risks
|
156
|
+
associated with Your exercise of permissions under this License.
|
157
|
+
|
158
|
+
8. Limitation of Liability.
|
159
|
+
|
160
|
+
In no event and under no legal theory, whether in tort
|
161
|
+
(including negligence), contract, or otherwise, unless required by
|
162
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed
|
163
|
+
to in writing, shall any Contributor be liable to You for damages,
|
164
|
+
including any direct, indirect, special, incidental, or consequential
|
165
|
+
damages of any character arising as a result of this License or out of
|
166
|
+
the use or inability to use the Work (including but not limited to damages
|
167
|
+
for loss of goodwill, work stoppage, computer failure or malfunction,
|
168
|
+
or any and all other commercial damages or losses), even if such
|
169
|
+
Contributor has been advised of the possibility of such damages.
|
170
|
+
|
171
|
+
9. Accepting Warranty or Additional Liability.
|
172
|
+
|
173
|
+
While redistributing the Work or Derivative Works thereof, You may choose
|
174
|
+
to offer, and charge a fee for, acceptance of support, warranty,
|
175
|
+
indemnity, or other liability obligations and/or rights consistent with
|
176
|
+
this License. However, in accepting such obligations, You may act only
|
177
|
+
on Your own behalf and on Your sole responsibility, not on behalf of any
|
178
|
+
other Contributor, and only if You agree to indemnify, defend, and hold
|
179
|
+
each Contributor harmless for any liability incurred by, or claims
|
180
|
+
asserted against, such Contributor by reason of your accepting any such
|
181
|
+
warranty or additional liability.
|
182
|
+
|
183
|
+
END OF TERMS AND CONDITIONS
|
184
|
+
|
185
|
+
APPENDIX: How to apply the Apache License to your work
|
186
|
+
|
187
|
+
To apply the Apache License to your work, attach the following boilerplate
|
188
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
189
|
+
identifying information. (Don't include the brackets!) The text should be
|
190
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
191
|
+
recommend that a file or class name and description of purpose be included
|
192
|
+
on the same "printed page" as the copyright notice for easier
|
193
|
+
identification within third-party archives.
|
194
|
+
|
195
|
+
Copyright 2017 Jeremy Scheff
|
196
|
+
|
197
|
+
|
198
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
199
|
+
you may not use this file except in compliance with the License.
|
200
|
+
You may obtain a copy of the License at
|
201
|
+
|
202
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
203
|
+
|
204
|
+
Unless required by applicable law or agreed to in writing, software
|
205
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
206
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
207
|
+
or implied. See the License for the specific language governing
|
208
|
+
permissions and limitations under the License.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import FDBFactory from './FDBFactory.js';
|
2
|
+
import IDBCursor from './FDBCursor.js';
|
3
|
+
import IDBCursorWithValue from './FDBCursorWithValue.js';
|
4
|
+
import IDBDatabase from './FDBDatabase.js';
|
5
|
+
import IDBFactory from './FDBFactory.js';
|
6
|
+
import IDBIndex from './FDBIndex.js';
|
7
|
+
import IDBKeyRange from './FDBKeyRange.js';
|
8
|
+
import IDBObjectStore from './FDBObjectStore.js';
|
9
|
+
import IDBOpenDBRequest from './FDBOpenDBRequest.js';
|
10
|
+
import IDBRequest from './FDBRequest.js';
|
11
|
+
import IDBTransaction from './FDBTransaction.js';
|
12
|
+
import IDBVersionChangeEvent from './FDBVersionChangeEvent.js';
|
13
|
+
import { makeStructuredCloneAvailable } from '../structuredClone';
|
14
|
+
|
15
|
+
let idbAvailable = false;
|
16
|
+
export function makeIDBAvailable() {
|
17
|
+
if (idbAvailable) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
if (!global.window) {
|
21
|
+
global.window = {};
|
22
|
+
}
|
23
|
+
if (!window.indexedDB) {
|
24
|
+
makeStructuredCloneAvailable();
|
25
|
+
window.indexedDB = new FDBFactory();
|
26
|
+
window.IDBCursor = IDBCursor;
|
27
|
+
window.IDBCursorWithValue = IDBCursorWithValue;
|
28
|
+
window.IDBDatabase = IDBDatabase;
|
29
|
+
window.IDBFactory = IDBFactory;
|
30
|
+
window.IDBIndex = IDBIndex;
|
31
|
+
window.IDBKeyRange = IDBKeyRange;
|
32
|
+
window.IDBObjectStore = IDBObjectStore;
|
33
|
+
window.IDBOpenDBRequest = IDBOpenDBRequest;
|
34
|
+
window.IDBRequest = IDBRequest;
|
35
|
+
window.IDBTransaction = IDBTransaction;
|
36
|
+
window.IDBVersionChangeEvent = IDBVersionChangeEvent;
|
37
|
+
}
|
38
|
+
idbAvailable = true;
|
39
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { queueTask } from './scheduling.js';
|
2
|
+
|
3
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-database
|
4
|
+
class Database {
|
5
|
+
deletePending = false;
|
6
|
+
transactions = [];
|
7
|
+
rawObjectStores = new Map();
|
8
|
+
connections = [];
|
9
|
+
constructor(name, version) {
|
10
|
+
this.name = name;
|
11
|
+
this.version = version;
|
12
|
+
this.processTransactions = this.processTransactions.bind(this);
|
13
|
+
}
|
14
|
+
processTransactions() {
|
15
|
+
queueTask(() => {
|
16
|
+
const anyRunning = this.transactions.some(transaction => {
|
17
|
+
return transaction._started && transaction._state !== 'finished';
|
18
|
+
});
|
19
|
+
if (!anyRunning) {
|
20
|
+
const next = this.transactions.find(transaction => {
|
21
|
+
return !transaction._started && transaction._state !== 'finished';
|
22
|
+
});
|
23
|
+
if (next) {
|
24
|
+
next.addEventListener('complete', this.processTransactions);
|
25
|
+
next.addEventListener('abort', this.processTransactions);
|
26
|
+
next._start();
|
27
|
+
}
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
}
|
32
|
+
export default Database;
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class FakeDOMStringList extends Array {
|
2
|
+
contains(value) {
|
3
|
+
for (const value2 of this) {
|
4
|
+
if (value === value2) {
|
5
|
+
return true;
|
6
|
+
}
|
7
|
+
}
|
8
|
+
return false;
|
9
|
+
}
|
10
|
+
item(i) {
|
11
|
+
if (i < 0 || i >= this.length) {
|
12
|
+
return null;
|
13
|
+
}
|
14
|
+
return this[i];
|
15
|
+
}
|
16
|
+
|
17
|
+
// Used internally, should not be used by others. I could maybe get rid of these and replace rather than mutate, but too lazy to check the spec.
|
18
|
+
_push(...values) {
|
19
|
+
return Array.prototype.push.call(this, ...values);
|
20
|
+
}
|
21
|
+
_sort(...values) {
|
22
|
+
return Array.prototype.sort.call(this, ...values);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
// Would be nice to remove these properties to fix https://github.com/dumbmatter/fakeIndexedDB/issues/66 but for some reason it breaks Dexie - see test/dexie.js and FakeDOMStringList tests
|
27
|
+
/*
|
28
|
+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
29
|
+
const arrayPropertiesToDelete = ["from", "isArray", "of"];
|
30
|
+
const arrayMethodsToDelete = [
|
31
|
+
"at",
|
32
|
+
"concat",
|
33
|
+
"copyWithin",
|
34
|
+
"entries",
|
35
|
+
"every",
|
36
|
+
"fill",
|
37
|
+
"filter",
|
38
|
+
"find",
|
39
|
+
"findIndex",
|
40
|
+
"flat",
|
41
|
+
"flatMap",
|
42
|
+
"forEach",
|
43
|
+
"includes",
|
44
|
+
"indexOf",
|
45
|
+
"join",
|
46
|
+
"keys",
|
47
|
+
"lastIndexOf",
|
48
|
+
"map",
|
49
|
+
"pop",
|
50
|
+
"push",
|
51
|
+
"reduce",
|
52
|
+
"reduceRight",
|
53
|
+
"reverse",
|
54
|
+
"shift",
|
55
|
+
"slice",
|
56
|
+
"some",
|
57
|
+
"sort",
|
58
|
+
"splice",
|
59
|
+
"unshift",
|
60
|
+
"values",
|
61
|
+
];
|
62
|
+
|
63
|
+
// Set to undefined rather than delete, so it doesn't go up the chain to Array. Not perfect, but good enough?
|
64
|
+
for (const property of arrayPropertiesToDelete) {
|
65
|
+
(FakeDOMStringList as any)[property] = undefined;
|
66
|
+
}
|
67
|
+
for (const property of arrayMethodsToDelete) {
|
68
|
+
(FakeDOMStringList as any).prototype[property] = undefined;
|
69
|
+
}
|
70
|
+
*/
|
71
|
+
|
72
|
+
export default FakeDOMStringList;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Event {
|
2
|
+
eventPath = [];
|
3
|
+
NONE = 0;
|
4
|
+
CAPTURING_PHASE = 1;
|
5
|
+
AT_TARGET = 2;
|
6
|
+
BUBBLING_PHASE = 3;
|
7
|
+
|
8
|
+
// Flags
|
9
|
+
propagationStopped = false;
|
10
|
+
immediatePropagationStopped = false;
|
11
|
+
canceled = false;
|
12
|
+
initialized = true;
|
13
|
+
dispatched = false;
|
14
|
+
target = null;
|
15
|
+
currentTarget = null;
|
16
|
+
eventPhase = 0;
|
17
|
+
defaultPrevented = false;
|
18
|
+
isTrusted = false;
|
19
|
+
timeStamp = Date.now();
|
20
|
+
constructor(type, eventInitDict = {}) {
|
21
|
+
this.type = type;
|
22
|
+
this.bubbles = eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
|
23
|
+
this.cancelable = eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
|
24
|
+
}
|
25
|
+
preventDefault() {
|
26
|
+
if (this.cancelable) {
|
27
|
+
this.canceled = true;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
stopPropagation() {
|
31
|
+
this.propagationStopped = true;
|
32
|
+
}
|
33
|
+
stopImmediatePropagation() {
|
34
|
+
this.propagationStopped = true;
|
35
|
+
this.immediatePropagationStopped = true;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
export default Event;
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import { InvalidStateError } from './errors.js';
|
2
|
+
const stopped = (event, listener) => {
|
3
|
+
return (
|
4
|
+
event.immediatePropagationStopped ||
|
5
|
+
(event.eventPhase === event.CAPTURING_PHASE && listener.capture === false) ||
|
6
|
+
(event.eventPhase === event.BUBBLING_PHASE && listener.capture === true)
|
7
|
+
);
|
8
|
+
};
|
9
|
+
|
10
|
+
// http://www.w3.org/TR/dom/#concept-event-listener-invoke
|
11
|
+
const invokeEventListeners = (event, obj) => {
|
12
|
+
event.currentTarget = obj;
|
13
|
+
|
14
|
+
// The callback might cause obj.listeners to mutate as we traverse it.
|
15
|
+
// Take a copy of the array so that nothing sneaks in and we don't lose
|
16
|
+
// our place.
|
17
|
+
for (const listener of obj.listeners.slice()) {
|
18
|
+
if (event.type !== listener.type || stopped(event, listener)) {
|
19
|
+
continue;
|
20
|
+
}
|
21
|
+
|
22
|
+
// @ts-ignore
|
23
|
+
listener.callback.call(event.currentTarget, event);
|
24
|
+
}
|
25
|
+
const typeToProp = {
|
26
|
+
abort: 'onabort',
|
27
|
+
blocked: 'onblocked',
|
28
|
+
complete: 'oncomplete',
|
29
|
+
error: 'onerror',
|
30
|
+
success: 'onsuccess',
|
31
|
+
upgradeneeded: 'onupgradeneeded',
|
32
|
+
versionchange: 'onversionchange',
|
33
|
+
};
|
34
|
+
const prop = typeToProp[event.type];
|
35
|
+
if (prop === undefined) {
|
36
|
+
throw new Error(`Unknown event type: "${event.type}"`);
|
37
|
+
}
|
38
|
+
const callback = event.currentTarget[prop];
|
39
|
+
if (callback) {
|
40
|
+
const listener = {
|
41
|
+
callback,
|
42
|
+
capture: false,
|
43
|
+
type: event.type,
|
44
|
+
};
|
45
|
+
if (!stopped(event, listener)) {
|
46
|
+
// @ts-ignore
|
47
|
+
listener.callback.call(event.currentTarget, event);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
};
|
51
|
+
class FakeEventTarget {
|
52
|
+
listeners = [];
|
53
|
+
|
54
|
+
// These will be overridden in individual subclasses and made not readonly
|
55
|
+
|
56
|
+
addEventListener(type, callback, capture = false) {
|
57
|
+
this.listeners.push({
|
58
|
+
callback,
|
59
|
+
capture,
|
60
|
+
type,
|
61
|
+
});
|
62
|
+
}
|
63
|
+
removeEventListener(type, callback, capture = false) {
|
64
|
+
const i = this.listeners.findIndex(listener => {
|
65
|
+
return (
|
66
|
+
listener.type === type && listener.callback === callback && listener.capture === capture
|
67
|
+
);
|
68
|
+
});
|
69
|
+
this.listeners.splice(i, 1);
|
70
|
+
}
|
71
|
+
|
72
|
+
// http://www.w3.org/TR/dom/#dispatching-events
|
73
|
+
dispatchEvent(event) {
|
74
|
+
if (event.dispatched || !event.initialized) {
|
75
|
+
throw new InvalidStateError('The object is in an invalid state.');
|
76
|
+
}
|
77
|
+
event.isTrusted = false;
|
78
|
+
event.dispatched = true;
|
79
|
+
event.target = this;
|
80
|
+
// NOT SURE WHEN THIS SHOULD BE SET event.eventPath = [];
|
81
|
+
|
82
|
+
event.eventPhase = event.CAPTURING_PHASE;
|
83
|
+
for (const obj of event.eventPath) {
|
84
|
+
if (!event.propagationStopped) {
|
85
|
+
invokeEventListeners(event, obj);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
event.eventPhase = event.AT_TARGET;
|
89
|
+
if (!event.propagationStopped) {
|
90
|
+
invokeEventListeners(event, event.target);
|
91
|
+
}
|
92
|
+
if (event.bubbles) {
|
93
|
+
event.eventPath.reverse();
|
94
|
+
event.eventPhase = event.BUBBLING_PHASE;
|
95
|
+
for (const obj of event.eventPath) {
|
96
|
+
if (!event.propagationStopped) {
|
97
|
+
invokeEventListeners(event, obj);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
event.dispatched = false;
|
102
|
+
event.eventPhase = event.NONE;
|
103
|
+
event.currentTarget = null;
|
104
|
+
if (event.canceled) {
|
105
|
+
return false;
|
106
|
+
}
|
107
|
+
return true;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
export default FakeEventTarget;
|
@@ -0,0 +1,157 @@
|
|
1
|
+
import { ConstraintError } from './errors.js';
|
2
|
+
import extractKey from './extractKey.js';
|
3
|
+
import RecordStore from './RecordStore.js';
|
4
|
+
import valueToKey from './valueToKey.js';
|
5
|
+
|
6
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-index
|
7
|
+
class Index {
|
8
|
+
deleted = false;
|
9
|
+
// Initialized should be used to decide whether to throw an error or abort the versionchange transaction when there is a
|
10
|
+
// constraint
|
11
|
+
initialized = false;
|
12
|
+
records = new RecordStore();
|
13
|
+
constructor(rawObjectStore, name, keyPath, multiEntry, unique) {
|
14
|
+
this.rawObjectStore = rawObjectStore;
|
15
|
+
this.name = name;
|
16
|
+
this.keyPath = keyPath;
|
17
|
+
this.multiEntry = multiEntry;
|
18
|
+
this.unique = unique;
|
19
|
+
}
|
20
|
+
|
21
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-retrieving-a-value-from-an-index
|
22
|
+
getKey(key) {
|
23
|
+
const record = this.records.get(key);
|
24
|
+
return record !== undefined ? record.value : undefined;
|
25
|
+
}
|
26
|
+
|
27
|
+
// http://w3c.github.io/IndexedDB/#retrieve-multiple-referenced-values-from-an-index
|
28
|
+
getAllKeys(range, count) {
|
29
|
+
if (count === undefined || count === 0) {
|
30
|
+
count = Infinity;
|
31
|
+
}
|
32
|
+
const records = [];
|
33
|
+
for (const record of this.records.values(range)) {
|
34
|
+
records.push(structuredClone(record.value));
|
35
|
+
if (records.length >= count) {
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
return records;
|
40
|
+
}
|
41
|
+
|
42
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#index-referenced-value-retrieval-operation
|
43
|
+
getValue(key) {
|
44
|
+
const record = this.records.get(key);
|
45
|
+
return record !== undefined ? this.rawObjectStore.getValue(record.value) : undefined;
|
46
|
+
}
|
47
|
+
|
48
|
+
// http://w3c.github.io/IndexedDB/#retrieve-multiple-referenced-values-from-an-index
|
49
|
+
getAllValues(range, count) {
|
50
|
+
if (count === undefined || count === 0) {
|
51
|
+
count = Infinity;
|
52
|
+
}
|
53
|
+
const records = [];
|
54
|
+
for (const record of this.records.values(range)) {
|
55
|
+
records.push(this.rawObjectStore.getValue(record.value));
|
56
|
+
if (records.length >= count) {
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
return records;
|
61
|
+
}
|
62
|
+
|
63
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store (step 7)
|
64
|
+
storeRecord(newRecord) {
|
65
|
+
let indexKey;
|
66
|
+
try {
|
67
|
+
indexKey = extractKey(this.keyPath, newRecord.value);
|
68
|
+
} catch (err) {
|
69
|
+
if (err.name === 'DataError') {
|
70
|
+
// Invalid key is not an actual error, just means we do not store an entry in this index
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
throw err;
|
74
|
+
}
|
75
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
76
|
+
try {
|
77
|
+
valueToKey(indexKey);
|
78
|
+
} catch (e) {
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
} else {
|
82
|
+
// remove any elements from index key that are not valid keys and remove any duplicate elements from index
|
83
|
+
// key such that only one instance of the duplicate value remains.
|
84
|
+
const keep = [];
|
85
|
+
for (const part of indexKey) {
|
86
|
+
if (keep.indexOf(part) < 0) {
|
87
|
+
try {
|
88
|
+
keep.push(valueToKey(part));
|
89
|
+
} catch (err) {
|
90
|
+
/* Do nothing */
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
indexKey = keep;
|
95
|
+
}
|
96
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
97
|
+
if (this.unique) {
|
98
|
+
const existingRecord = this.records.get(indexKey);
|
99
|
+
if (existingRecord) {
|
100
|
+
throw new ConstraintError();
|
101
|
+
}
|
102
|
+
}
|
103
|
+
} else {
|
104
|
+
if (this.unique) {
|
105
|
+
for (const individualIndexKey of indexKey) {
|
106
|
+
const existingRecord = this.records.get(individualIndexKey);
|
107
|
+
if (existingRecord) {
|
108
|
+
throw new ConstraintError();
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
114
|
+
this.records.add({
|
115
|
+
key: indexKey,
|
116
|
+
value: newRecord.key,
|
117
|
+
});
|
118
|
+
} else {
|
119
|
+
for (const individualIndexKey of indexKey) {
|
120
|
+
this.records.add({
|
121
|
+
key: individualIndexKey,
|
122
|
+
value: newRecord.key,
|
123
|
+
});
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
initialize(transaction) {
|
128
|
+
if (this.initialized) {
|
129
|
+
throw new Error('Index already initialized');
|
130
|
+
}
|
131
|
+
transaction._execRequestAsync({
|
132
|
+
operation: () => {
|
133
|
+
try {
|
134
|
+
// Create index based on current value of objectstore
|
135
|
+
for (const record of this.rawObjectStore.records.values()) {
|
136
|
+
this.storeRecord(record);
|
137
|
+
}
|
138
|
+
this.initialized = true;
|
139
|
+
} catch (err) {
|
140
|
+
// console.error(err);
|
141
|
+
transaction._abort(err.name);
|
142
|
+
}
|
143
|
+
},
|
144
|
+
source: null,
|
145
|
+
});
|
146
|
+
}
|
147
|
+
count(range) {
|
148
|
+
let count = 0;
|
149
|
+
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
151
|
+
for (const record of this.records.values(range)) {
|
152
|
+
count += 1;
|
153
|
+
}
|
154
|
+
return count;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
export default Index;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { ConstraintError } from './errors.js';
|
2
|
+
const MAX_KEY = 9007199254740992;
|
3
|
+
class KeyGenerator {
|
4
|
+
// This is kind of wrong. Should start at 1 and increment only after record is saved
|
5
|
+
num = 0;
|
6
|
+
next() {
|
7
|
+
if (this.num >= MAX_KEY) {
|
8
|
+
throw new ConstraintError();
|
9
|
+
}
|
10
|
+
this.num += 1;
|
11
|
+
return this.num;
|
12
|
+
}
|
13
|
+
|
14
|
+
// https://w3c.github.io/IndexedDB/#possibly-update-the-key-generator
|
15
|
+
setIfLarger(num) {
|
16
|
+
const value = Math.floor(Math.min(num, MAX_KEY)) - 1;
|
17
|
+
if (value >= this.num) {
|
18
|
+
this.num = value + 1;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
export default KeyGenerator;
|