fake-indexeddb 4.0.2 → 5.0.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/README.md +0 -6
- package/build/cjs/FDBCursor.js +39 -159
- package/build/cjs/FDBCursorWithValue.js +1 -9
- package/build/cjs/FDBDatabase.js +9 -72
- package/build/cjs/FDBFactory.js +23 -66
- package/build/cjs/FDBIndex.js +17 -73
- package/build/cjs/FDBKeyRange.js +3 -28
- package/build/cjs/FDBObjectStore.js +25 -145
- package/build/cjs/FDBOpenDBRequest.js +1 -8
- package/build/cjs/FDBRequest.js +1 -15
- package/build/cjs/FDBTransaction.js +26 -64
- package/build/cjs/FDBVersionChangeEvent.js +1 -8
- package/build/cjs/fakeIndexedDB.js +1 -5
- package/build/cjs/index.js +1 -16
- package/build/cjs/lib/Database.js +1 -11
- package/build/cjs/lib/FakeDOMStringList.js +5 -13
- package/build/cjs/lib/FakeEvent.js +3 -10
- package/build/cjs/lib/FakeEventTarget.js +15 -32
- package/build/cjs/lib/Index.js +14 -46
- package/build/cjs/lib/KeyGenerator.js +3 -12
- package/build/cjs/lib/ObjectStore.js +24 -63
- package/build/cjs/lib/RecordStore.js +4 -42
- package/build/cjs/lib/binarySearch.js +5 -24
- package/build/cjs/lib/canInjectKey.js +2 -14
- package/build/cjs/lib/cmp.js +3 -29
- package/build/cjs/lib/enforceRange.js +2 -6
- package/build/cjs/lib/errors.js +0 -32
- package/build/cjs/lib/extractKey.js +2 -17
- package/build/cjs/lib/scheduling.js +4 -7
- package/build/cjs/lib/validateKeyPath.js +4 -16
- package/build/cjs/lib/valueToKey.js +2 -15
- package/build/cjs/lib/valueToKeyRange.js +1 -11
- package/build/esm/FDBCursor.js +33 -144
- package/build/esm/FDBCursorWithValue.js +0 -5
- package/build/esm/FDBDatabase.js +8 -62
- package/build/esm/FDBFactory.js +22 -54
- package/build/esm/FDBIndex.js +16 -61
- package/build/esm/FDBKeyRange.js +4 -22
- package/build/esm/FDBObjectStore.js +23 -126
- package/build/esm/FDBOpenDBRequest.js +0 -4
- package/build/esm/FDBRequest.js +0 -10
- package/build/esm/FDBTransaction.js +25 -54
- package/build/esm/FDBVersionChangeEvent.js +0 -4
- package/build/esm/lib/Database.js +2 -8
- package/build/esm/lib/FakeDOMStringList.js +4 -9
- package/build/esm/lib/FakeEvent.js +2 -7
- package/build/esm/lib/FakeEventTarget.js +14 -29
- package/build/esm/lib/Index.js +14 -37
- package/build/esm/lib/KeyGenerator.js +2 -8
- package/build/esm/lib/ObjectStore.js +19 -51
- package/build/esm/lib/RecordStore.js +3 -36
- package/build/esm/lib/binarySearch.js +5 -18
- package/build/esm/lib/canInjectKey.js +1 -11
- package/build/esm/lib/cmp.js +2 -24
- package/build/esm/lib/enforceRange.js +1 -3
- package/build/esm/lib/errors.js +0 -11
- package/build/esm/lib/extractKey.js +3 -13
- package/build/esm/lib/scheduling.js +3 -3
- package/build/esm/lib/validateKeyPath.js +3 -13
- package/build/esm/lib/valueToKey.js +1 -12
- package/build/esm/lib/valueToKeyRange.js +2 -5
- package/package.json +30 -28
- package/build/cjs/lib/structuredClone.js +0 -30
- package/build/esm/lib/structuredClone.js +0 -18
package/build/cjs/lib/Index.js
CHANGED
|
@@ -4,89 +4,71 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _errors = require("./errors.js");
|
|
9
|
-
|
|
10
8
|
var _extractKey = _interopRequireDefault(require("./extractKey.js"));
|
|
11
|
-
|
|
12
9
|
var _RecordStore = _interopRequireDefault(require("./RecordStore.js"));
|
|
13
|
-
|
|
14
|
-
var _structuredClone = _interopRequireDefault(require("./structuredClone.js"));
|
|
15
|
-
|
|
16
10
|
var _valueToKey = _interopRequireDefault(require("./valueToKey.js"));
|
|
17
|
-
|
|
18
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
12
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-index
|
|
21
13
|
class Index {
|
|
22
|
-
deleted = false;
|
|
14
|
+
deleted = false;
|
|
15
|
+
// Initialized should be used to decide whether to throw an error or abort the versionchange transaction when there is a
|
|
23
16
|
// constraint
|
|
24
|
-
|
|
25
17
|
initialized = false;
|
|
26
18
|
records = new _RecordStore.default();
|
|
27
|
-
|
|
28
19
|
constructor(rawObjectStore, name, keyPath, multiEntry, unique) {
|
|
29
20
|
this.rawObjectStore = rawObjectStore;
|
|
30
21
|
this.name = name;
|
|
31
22
|
this.keyPath = keyPath;
|
|
32
23
|
this.multiEntry = multiEntry;
|
|
33
24
|
this.unique = unique;
|
|
34
|
-
}
|
|
35
|
-
|
|
25
|
+
}
|
|
36
26
|
|
|
27
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-retrieving-a-value-from-an-index
|
|
37
28
|
getKey(key) {
|
|
38
29
|
const record = this.records.get(key);
|
|
39
30
|
return record !== undefined ? record.value : undefined;
|
|
40
|
-
}
|
|
41
|
-
|
|
31
|
+
}
|
|
42
32
|
|
|
33
|
+
// http://w3c.github.io/IndexedDB/#retrieve-multiple-referenced-values-from-an-index
|
|
43
34
|
getAllKeys(range, count) {
|
|
44
35
|
if (count === undefined || count === 0) {
|
|
45
36
|
count = Infinity;
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
const records = [];
|
|
49
|
-
|
|
50
39
|
for (const record of this.records.values(range)) {
|
|
51
|
-
records.push((
|
|
52
|
-
|
|
40
|
+
records.push(structuredClone(record.value));
|
|
53
41
|
if (records.length >= count) {
|
|
54
42
|
break;
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
|
-
|
|
58
45
|
return records;
|
|
59
|
-
}
|
|
60
|
-
|
|
46
|
+
}
|
|
61
47
|
|
|
48
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#index-referenced-value-retrieval-operation
|
|
62
49
|
getValue(key) {
|
|
63
50
|
const record = this.records.get(key);
|
|
64
51
|
return record !== undefined ? this.rawObjectStore.getValue(record.value) : undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
52
|
+
}
|
|
67
53
|
|
|
54
|
+
// http://w3c.github.io/IndexedDB/#retrieve-multiple-referenced-values-from-an-index
|
|
68
55
|
getAllValues(range, count) {
|
|
69
56
|
if (count === undefined || count === 0) {
|
|
70
57
|
count = Infinity;
|
|
71
58
|
}
|
|
72
|
-
|
|
73
59
|
const records = [];
|
|
74
|
-
|
|
75
60
|
for (const record of this.records.values(range)) {
|
|
76
61
|
records.push(this.rawObjectStore.getValue(record.value));
|
|
77
|
-
|
|
78
62
|
if (records.length >= count) {
|
|
79
63
|
break;
|
|
80
64
|
}
|
|
81
65
|
}
|
|
82
|
-
|
|
83
66
|
return records;
|
|
84
|
-
}
|
|
85
|
-
|
|
67
|
+
}
|
|
86
68
|
|
|
69
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store (step 7)
|
|
87
70
|
storeRecord(newRecord) {
|
|
88
71
|
let indexKey;
|
|
89
|
-
|
|
90
72
|
try {
|
|
91
73
|
indexKey = (0, _extractKey.default)(this.keyPath, newRecord.value);
|
|
92
74
|
} catch (err) {
|
|
@@ -94,10 +76,8 @@ class Index {
|
|
|
94
76
|
// Invalid key is not an actual error, just means we do not store an entry in this index
|
|
95
77
|
return;
|
|
96
78
|
}
|
|
97
|
-
|
|
98
79
|
throw err;
|
|
99
80
|
}
|
|
100
|
-
|
|
101
81
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
102
82
|
try {
|
|
103
83
|
(0, _valueToKey.default)(indexKey);
|
|
@@ -108,7 +88,6 @@ class Index {
|
|
|
108
88
|
// remove any elements from index key that are not valid keys and remove any duplicate elements from index
|
|
109
89
|
// key such that only one instance of the duplicate value remains.
|
|
110
90
|
const keep = [];
|
|
111
|
-
|
|
112
91
|
for (const part of indexKey) {
|
|
113
92
|
if (keep.indexOf(part) < 0) {
|
|
114
93
|
try {
|
|
@@ -118,14 +97,11 @@ class Index {
|
|
|
118
97
|
}
|
|
119
98
|
}
|
|
120
99
|
}
|
|
121
|
-
|
|
122
100
|
indexKey = keep;
|
|
123
101
|
}
|
|
124
|
-
|
|
125
102
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
126
103
|
if (this.unique) {
|
|
127
104
|
const existingRecord = this.records.get(indexKey);
|
|
128
|
-
|
|
129
105
|
if (existingRecord) {
|
|
130
106
|
throw new _errors.ConstraintError();
|
|
131
107
|
}
|
|
@@ -134,14 +110,12 @@ class Index {
|
|
|
134
110
|
if (this.unique) {
|
|
135
111
|
for (const individualIndexKey of indexKey) {
|
|
136
112
|
const existingRecord = this.records.get(individualIndexKey);
|
|
137
|
-
|
|
138
113
|
if (existingRecord) {
|
|
139
114
|
throw new _errors.ConstraintError();
|
|
140
115
|
}
|
|
141
116
|
}
|
|
142
117
|
}
|
|
143
118
|
}
|
|
144
|
-
|
|
145
119
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
146
120
|
this.records.add({
|
|
147
121
|
key: indexKey,
|
|
@@ -156,12 +130,10 @@ class Index {
|
|
|
156
130
|
}
|
|
157
131
|
}
|
|
158
132
|
}
|
|
159
|
-
|
|
160
133
|
initialize(transaction) {
|
|
161
134
|
if (this.initialized) {
|
|
162
135
|
throw new Error("Index already initialized");
|
|
163
136
|
}
|
|
164
|
-
|
|
165
137
|
transaction._execRequestAsync({
|
|
166
138
|
operation: () => {
|
|
167
139
|
try {
|
|
@@ -169,7 +141,6 @@ class Index {
|
|
|
169
141
|
for (const record of this.rawObjectStore.records.values()) {
|
|
170
142
|
this.storeRecord(record);
|
|
171
143
|
}
|
|
172
|
-
|
|
173
144
|
this.initialized = true;
|
|
174
145
|
} catch (err) {
|
|
175
146
|
// console.error(err);
|
|
@@ -179,9 +150,6 @@ class Index {
|
|
|
179
150
|
source: null
|
|
180
151
|
});
|
|
181
152
|
}
|
|
182
|
-
|
|
183
153
|
}
|
|
184
|
-
|
|
185
|
-
var _default = Index;
|
|
186
|
-
exports.default = _default;
|
|
154
|
+
var _default = exports.default = Index;
|
|
187
155
|
module.exports = exports.default;
|
|
@@ -4,35 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _errors = require("./errors.js");
|
|
9
|
-
|
|
10
8
|
const MAX_KEY = 9007199254740992;
|
|
11
|
-
|
|
12
9
|
class KeyGenerator {
|
|
13
10
|
// This is kind of wrong. Should start at 1 and increment only after record is saved
|
|
14
11
|
num = 0;
|
|
15
|
-
|
|
16
12
|
next() {
|
|
17
13
|
if (this.num >= MAX_KEY) {
|
|
18
14
|
throw new _errors.ConstraintError();
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
this.num += 1;
|
|
22
17
|
return this.num;
|
|
23
|
-
}
|
|
24
|
-
|
|
18
|
+
}
|
|
25
19
|
|
|
20
|
+
// https://w3c.github.io/IndexedDB/#possibly-update-the-key-generator
|
|
26
21
|
setIfLarger(num) {
|
|
27
22
|
const value = Math.floor(Math.min(num, MAX_KEY)) - 1;
|
|
28
|
-
|
|
29
23
|
if (value >= this.num) {
|
|
30
24
|
this.num = value + 1;
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
var _default = KeyGenerator;
|
|
37
|
-
exports.default = _default;
|
|
28
|
+
var _default = exports.default = KeyGenerator;
|
|
38
29
|
module.exports = exports.default;
|
|
@@ -4,25 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _errors = require("./errors.js");
|
|
9
|
-
|
|
10
8
|
var _extractKey = _interopRequireDefault(require("./extractKey.js"));
|
|
11
|
-
|
|
12
9
|
var _KeyGenerator = _interopRequireDefault(require("./KeyGenerator.js"));
|
|
13
|
-
|
|
14
10
|
var _RecordStore = _interopRequireDefault(require("./RecordStore.js"));
|
|
15
|
-
|
|
16
|
-
var _structuredClone = _interopRequireDefault(require("./structuredClone.js"));
|
|
17
|
-
|
|
18
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
12
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-object-store
|
|
21
13
|
class ObjectStore {
|
|
22
14
|
deleted = false;
|
|
23
15
|
records = new _RecordStore.default();
|
|
24
16
|
rawIndexes = new Map();
|
|
25
|
-
|
|
26
17
|
constructor(rawDatabase, name, keyPath, autoIncrement) {
|
|
27
18
|
this.rawDatabase = rawDatabase;
|
|
28
19
|
this.keyGenerator = autoIncrement === true ? new _KeyGenerator.default() : null;
|
|
@@ -30,68 +21,58 @@ class ObjectStore {
|
|
|
30
21
|
this.name = name;
|
|
31
22
|
this.keyPath = keyPath;
|
|
32
23
|
this.autoIncrement = autoIncrement;
|
|
33
|
-
}
|
|
34
|
-
|
|
24
|
+
}
|
|
35
25
|
|
|
26
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-retrieving-a-value-from-an-object-store
|
|
36
27
|
getKey(key) {
|
|
37
28
|
const record = this.records.get(key);
|
|
38
|
-
return record !== undefined ? (
|
|
39
|
-
}
|
|
40
|
-
|
|
29
|
+
return record !== undefined ? structuredClone(record.key) : undefined;
|
|
30
|
+
}
|
|
41
31
|
|
|
32
|
+
// http://w3c.github.io/IndexedDB/#retrieve-multiple-keys-from-an-object-store
|
|
42
33
|
getAllKeys(range, count) {
|
|
43
34
|
if (count === undefined || count === 0) {
|
|
44
35
|
count = Infinity;
|
|
45
36
|
}
|
|
46
|
-
|
|
47
37
|
const records = [];
|
|
48
|
-
|
|
49
38
|
for (const record of this.records.values(range)) {
|
|
50
|
-
records.push((
|
|
51
|
-
|
|
39
|
+
records.push(structuredClone(record.key));
|
|
52
40
|
if (records.length >= count) {
|
|
53
41
|
break;
|
|
54
42
|
}
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
return records;
|
|
58
|
-
}
|
|
59
|
-
|
|
45
|
+
}
|
|
60
46
|
|
|
47
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-retrieving-a-value-from-an-object-store
|
|
61
48
|
getValue(key) {
|
|
62
49
|
const record = this.records.get(key);
|
|
63
|
-
return record !== undefined ? (
|
|
64
|
-
}
|
|
65
|
-
|
|
50
|
+
return record !== undefined ? structuredClone(record.value) : undefined;
|
|
51
|
+
}
|
|
66
52
|
|
|
53
|
+
// http://w3c.github.io/IndexedDB/#retrieve-multiple-values-from-an-object-store
|
|
67
54
|
getAllValues(range, count) {
|
|
68
55
|
if (count === undefined || count === 0) {
|
|
69
56
|
count = Infinity;
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
const records = [];
|
|
73
|
-
|
|
74
59
|
for (const record of this.records.values(range)) {
|
|
75
|
-
records.push((
|
|
76
|
-
|
|
60
|
+
records.push(structuredClone(record.value));
|
|
77
61
|
if (records.length >= count) {
|
|
78
62
|
break;
|
|
79
63
|
}
|
|
80
64
|
}
|
|
81
|
-
|
|
82
65
|
return records;
|
|
83
|
-
}
|
|
84
|
-
|
|
66
|
+
}
|
|
85
67
|
|
|
68
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store
|
|
86
69
|
storeRecord(newRecord, noOverwrite, rollbackLog) {
|
|
87
70
|
if (this.keyPath !== null) {
|
|
88
71
|
const key = (0, _extractKey.default)(this.keyPath, newRecord.value);
|
|
89
|
-
|
|
90
72
|
if (key !== undefined) {
|
|
91
73
|
newRecord.key = key;
|
|
92
74
|
}
|
|
93
75
|
}
|
|
94
|
-
|
|
95
76
|
if (this.keyGenerator !== null && newRecord.key === undefined) {
|
|
96
77
|
if (rollbackLog) {
|
|
97
78
|
const keyGeneratorBefore = this.keyGenerator.num;
|
|
@@ -101,78 +82,64 @@ class ObjectStore {
|
|
|
101
82
|
}
|
|
102
83
|
});
|
|
103
84
|
}
|
|
85
|
+
newRecord.key = this.keyGenerator.next();
|
|
104
86
|
|
|
105
|
-
|
|
87
|
+
// Set in value if keyPath defiend but led to no key
|
|
106
88
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-to-assign-a-key-to-a-value-using-a-key-path
|
|
107
|
-
|
|
108
89
|
if (this.keyPath !== null) {
|
|
109
90
|
if (Array.isArray(this.keyPath)) {
|
|
110
91
|
throw new Error("Cannot have an array key path in an object store with a key generator");
|
|
111
92
|
}
|
|
112
|
-
|
|
113
93
|
let remainingKeyPath = this.keyPath;
|
|
114
94
|
let object = newRecord.value;
|
|
115
95
|
let identifier;
|
|
116
96
|
let i = 0; // Just to run the loop at least once
|
|
117
|
-
|
|
118
97
|
while (i >= 0) {
|
|
119
98
|
if (typeof object !== "object") {
|
|
120
99
|
throw new _errors.DataError();
|
|
121
100
|
}
|
|
122
|
-
|
|
123
101
|
i = remainingKeyPath.indexOf(".");
|
|
124
|
-
|
|
125
102
|
if (i >= 0) {
|
|
126
103
|
identifier = remainingKeyPath.slice(0, i);
|
|
127
104
|
remainingKeyPath = remainingKeyPath.slice(i + 1);
|
|
128
|
-
|
|
129
|
-
if (!object.hasOwnProperty(identifier)) {
|
|
105
|
+
if (!Object.hasOwn(object, identifier)) {
|
|
130
106
|
object[identifier] = {};
|
|
131
107
|
}
|
|
132
|
-
|
|
133
108
|
object = object[identifier];
|
|
134
109
|
}
|
|
135
110
|
}
|
|
136
|
-
|
|
137
111
|
identifier = remainingKeyPath;
|
|
138
112
|
object[identifier] = newRecord.key;
|
|
139
113
|
}
|
|
140
114
|
} else if (this.keyGenerator !== null && typeof newRecord.key === "number") {
|
|
141
115
|
this.keyGenerator.setIfLarger(newRecord.key);
|
|
142
116
|
}
|
|
143
|
-
|
|
144
117
|
const existingRecord = this.records.get(newRecord.key);
|
|
145
|
-
|
|
146
118
|
if (existingRecord) {
|
|
147
119
|
if (noOverwrite) {
|
|
148
120
|
throw new _errors.ConstraintError();
|
|
149
121
|
}
|
|
150
|
-
|
|
151
122
|
this.deleteRecord(newRecord.key, rollbackLog);
|
|
152
123
|
}
|
|
153
|
-
|
|
154
124
|
this.records.add(newRecord);
|
|
155
|
-
|
|
156
125
|
if (rollbackLog) {
|
|
157
126
|
rollbackLog.push(() => {
|
|
158
127
|
this.deleteRecord(newRecord.key);
|
|
159
128
|
});
|
|
160
|
-
}
|
|
161
|
-
|
|
129
|
+
}
|
|
162
130
|
|
|
131
|
+
// Update indexes
|
|
163
132
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
164
133
|
if (rawIndex.initialized) {
|
|
165
134
|
rawIndex.storeRecord(newRecord);
|
|
166
135
|
}
|
|
167
136
|
}
|
|
168
|
-
|
|
169
137
|
return newRecord.key;
|
|
170
|
-
}
|
|
171
|
-
|
|
138
|
+
}
|
|
172
139
|
|
|
140
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-deleting-records-from-an-object-store
|
|
173
141
|
deleteRecord(key, rollbackLog) {
|
|
174
142
|
const deletedRecords = this.records.delete(key);
|
|
175
|
-
|
|
176
143
|
if (rollbackLog) {
|
|
177
144
|
for (const record of deletedRecords) {
|
|
178
145
|
rollbackLog.push(() => {
|
|
@@ -180,16 +147,14 @@ class ObjectStore {
|
|
|
180
147
|
});
|
|
181
148
|
}
|
|
182
149
|
}
|
|
183
|
-
|
|
184
150
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
185
151
|
rawIndex.records.deleteByValue(key);
|
|
186
152
|
}
|
|
187
|
-
}
|
|
188
|
-
|
|
153
|
+
}
|
|
189
154
|
|
|
155
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-clearing-an-object-store
|
|
190
156
|
clear(rollbackLog) {
|
|
191
157
|
const deletedRecords = this.records.clear();
|
|
192
|
-
|
|
193
158
|
if (rollbackLog) {
|
|
194
159
|
for (const record of deletedRecords) {
|
|
195
160
|
rollbackLog.push(() => {
|
|
@@ -197,14 +162,10 @@ class ObjectStore {
|
|
|
197
162
|
});
|
|
198
163
|
}
|
|
199
164
|
}
|
|
200
|
-
|
|
201
165
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
202
166
|
rawIndex.records.clear();
|
|
203
167
|
}
|
|
204
168
|
}
|
|
205
|
-
|
|
206
169
|
}
|
|
207
|
-
|
|
208
|
-
var _default = ObjectStore;
|
|
209
|
-
exports.default = _default;
|
|
170
|
+
var _default = exports.default = ObjectStore;
|
|
210
171
|
module.exports = exports.default;
|
|
@@ -4,35 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _FDBKeyRange = _interopRequireDefault(require("../FDBKeyRange.js"));
|
|
9
|
-
|
|
10
8
|
var _binarySearch = require("./binarySearch.js");
|
|
11
|
-
|
|
12
9
|
var _cmp = _interopRequireDefault(require("./cmp.js"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
class RecordStore {
|
|
17
12
|
records = [];
|
|
18
|
-
|
|
19
13
|
get(key) {
|
|
20
14
|
if (key instanceof _FDBKeyRange.default) {
|
|
21
15
|
return (0, _binarySearch.getByKeyRange)(this.records, key);
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
return (0, _binarySearch.getByKey)(this.records, key);
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
add(newRecord) {
|
|
28
20
|
// Find where to put it so it's sorted by key
|
|
29
21
|
let i;
|
|
30
|
-
|
|
31
22
|
if (this.records.length === 0) {
|
|
32
23
|
i = 0;
|
|
33
24
|
} else {
|
|
34
25
|
i = (0, _binarySearch.getIndexByKeyGTE)(this.records, newRecord.key);
|
|
35
|
-
|
|
36
26
|
if (i === -1) {
|
|
37
27
|
// If no matching key, add to end
|
|
38
28
|
i = this.records.length;
|
|
@@ -43,7 +33,6 @@ class RecordStore {
|
|
|
43
33
|
// Record value >= newRecord value, so insert here
|
|
44
34
|
break;
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
i += 1; // Look at next record
|
|
48
37
|
}
|
|
49
38
|
}
|
|
@@ -51,95 +40,74 @@ class RecordStore {
|
|
|
51
40
|
|
|
52
41
|
this.records.splice(i, 0, newRecord);
|
|
53
42
|
}
|
|
54
|
-
|
|
55
43
|
delete(key) {
|
|
56
44
|
const deletedRecords = [];
|
|
57
45
|
const isRange = key instanceof _FDBKeyRange.default;
|
|
58
|
-
|
|
59
46
|
while (true) {
|
|
60
47
|
const idx = isRange ? (0, _binarySearch.getIndexByKeyRange)(this.records, key) : (0, _binarySearch.getIndexByKey)(this.records, key);
|
|
61
|
-
|
|
62
48
|
if (idx === -1) {
|
|
63
49
|
break;
|
|
64
50
|
}
|
|
65
|
-
|
|
66
51
|
deletedRecords.push(this.records[idx]);
|
|
67
52
|
this.records.splice(idx, 1);
|
|
68
53
|
}
|
|
69
|
-
|
|
70
54
|
return deletedRecords;
|
|
71
55
|
}
|
|
72
|
-
|
|
73
56
|
deleteByValue(key) {
|
|
74
57
|
const range = key instanceof _FDBKeyRange.default ? key : _FDBKeyRange.default.only(key);
|
|
75
58
|
const deletedRecords = [];
|
|
76
59
|
this.records = this.records.filter(record => {
|
|
77
60
|
const shouldDelete = range.includes(record.value);
|
|
78
|
-
|
|
79
61
|
if (shouldDelete) {
|
|
80
62
|
deletedRecords.push(record);
|
|
81
63
|
}
|
|
82
|
-
|
|
83
64
|
return !shouldDelete;
|
|
84
65
|
});
|
|
85
66
|
return deletedRecords;
|
|
86
67
|
}
|
|
87
|
-
|
|
88
68
|
clear() {
|
|
89
69
|
const deletedRecords = this.records.slice();
|
|
90
70
|
this.records = [];
|
|
91
71
|
return deletedRecords;
|
|
92
72
|
}
|
|
93
|
-
|
|
94
73
|
values(range, direction = "next") {
|
|
95
74
|
return {
|
|
96
75
|
[Symbol.iterator]: () => {
|
|
97
76
|
let i;
|
|
98
|
-
|
|
99
77
|
if (direction === "next") {
|
|
100
78
|
i = 0;
|
|
101
|
-
|
|
102
79
|
if (range !== undefined && range.lower !== undefined) {
|
|
103
80
|
while (this.records[i] !== undefined) {
|
|
104
81
|
const cmpResult = (0, _cmp.default)(this.records[i].key, range.lower);
|
|
105
|
-
|
|
106
82
|
if (cmpResult === 1 || cmpResult === 0 && !range.lowerOpen) {
|
|
107
83
|
break;
|
|
108
84
|
}
|
|
109
|
-
|
|
110
85
|
i += 1;
|
|
111
86
|
}
|
|
112
87
|
}
|
|
113
88
|
} else {
|
|
114
89
|
i = this.records.length - 1;
|
|
115
|
-
|
|
116
90
|
if (range !== undefined && range.upper !== undefined) {
|
|
117
91
|
while (this.records[i] !== undefined) {
|
|
118
92
|
const cmpResult = (0, _cmp.default)(this.records[i].key, range.upper);
|
|
119
|
-
|
|
120
93
|
if (cmpResult === -1 || cmpResult === 0 && !range.upperOpen) {
|
|
121
94
|
break;
|
|
122
95
|
}
|
|
123
|
-
|
|
124
96
|
i -= 1;
|
|
125
97
|
}
|
|
126
98
|
}
|
|
127
99
|
}
|
|
128
|
-
|
|
129
100
|
return {
|
|
130
101
|
next: () => {
|
|
131
102
|
let done;
|
|
132
103
|
let value;
|
|
133
|
-
|
|
134
104
|
if (direction === "next") {
|
|
135
105
|
value = this.records[i];
|
|
136
106
|
done = i >= this.records.length;
|
|
137
107
|
i += 1;
|
|
138
|
-
|
|
139
108
|
if (!done && range !== undefined && range.upper !== undefined) {
|
|
140
109
|
const cmpResult = (0, _cmp.default)(value.key, range.upper);
|
|
141
110
|
done = cmpResult === 1 || cmpResult === 0 && range.upperOpen;
|
|
142
|
-
|
|
143
111
|
if (done) {
|
|
144
112
|
value = undefined;
|
|
145
113
|
}
|
|
@@ -148,21 +116,18 @@ class RecordStore {
|
|
|
148
116
|
value = this.records[i];
|
|
149
117
|
done = i < 0;
|
|
150
118
|
i -= 1;
|
|
151
|
-
|
|
152
119
|
if (!done && range !== undefined && range.lower !== undefined) {
|
|
153
120
|
const cmpResult = (0, _cmp.default)(value.key, range.lower);
|
|
154
121
|
done = cmpResult === -1 || cmpResult === 0 && range.lowerOpen;
|
|
155
|
-
|
|
156
122
|
if (done) {
|
|
157
123
|
value = undefined;
|
|
158
124
|
}
|
|
159
125
|
}
|
|
160
|
-
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// The weird "as IteratorResult<Record>" is needed because of
|
|
161
129
|
// https://github.com/Microsoft/TypeScript/issues/11375 and
|
|
162
130
|
// https://github.com/Microsoft/TypeScript/issues/2983
|
|
163
|
-
// tslint:disable-next-line no-object-literal-type-assertion
|
|
164
|
-
|
|
165
|
-
|
|
166
131
|
return {
|
|
167
132
|
done,
|
|
168
133
|
value
|
|
@@ -172,9 +137,6 @@ class RecordStore {
|
|
|
172
137
|
}
|
|
173
138
|
};
|
|
174
139
|
}
|
|
175
|
-
|
|
176
140
|
}
|
|
177
|
-
|
|
178
|
-
var _default = RecordStore;
|
|
179
|
-
exports.default = _default;
|
|
141
|
+
var _default = exports.default = RecordStore;
|
|
180
142
|
module.exports = exports.default;
|