@byearlybird/starling 0.2.1 → 0.2.2
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/dist/index.d.ts +1 -3
- package/dist/index.js +8 -39
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -63,10 +63,8 @@ declare const create$1: (iterable?: Iterable<readonly [string, EncodedDocument]>
|
|
|
63
63
|
values(): MapIterator<EncodedDocument>;
|
|
64
64
|
entries(): MapIterator<[string, EncodedDocument]>;
|
|
65
65
|
readonly size: number;
|
|
66
|
-
put(key: string, value: EncodedDocument): void;
|
|
67
|
-
patch(key: string, value: EncodedDocument): void;
|
|
68
|
-
del(key: string, eventstamp: string): void;
|
|
69
66
|
begin(): {
|
|
67
|
+
get(key: string): EncodedDocument | null;
|
|
70
68
|
put(key: string, value: EncodedDocument): void;
|
|
71
69
|
patch(key: string, value: EncodedDocument): void;
|
|
72
70
|
del(key: string, eventstamp: string): void;
|
package/dist/index.js
CHANGED
|
@@ -181,27 +181,13 @@ const create$2 = (iterable) => {
|
|
|
181
181
|
get size() {
|
|
182
182
|
return readMap.size;
|
|
183
183
|
},
|
|
184
|
-
put(key, value) {
|
|
185
|
-
const next = cloneMap(readMap);
|
|
186
|
-
next.set(key, value);
|
|
187
|
-
readMap = next;
|
|
188
|
-
},
|
|
189
|
-
patch(key, value) {
|
|
190
|
-
const next = cloneMap(readMap);
|
|
191
|
-
const prev = next.get(key);
|
|
192
|
-
next.set(key, prev ? merge(prev, value) : value);
|
|
193
|
-
readMap = next;
|
|
194
|
-
},
|
|
195
|
-
del(key, eventstamp) {
|
|
196
|
-
const next = cloneMap(readMap);
|
|
197
|
-
const prev = next.get(key);
|
|
198
|
-
if (prev) next.set(key, del(prev, eventstamp));
|
|
199
|
-
readMap = next;
|
|
200
|
-
},
|
|
201
184
|
begin() {
|
|
202
185
|
const staging = cloneMap(readMap);
|
|
203
186
|
let committed = false;
|
|
204
187
|
return {
|
|
188
|
+
get(key) {
|
|
189
|
+
return staging.get(key) ?? null;
|
|
190
|
+
},
|
|
205
191
|
put(key, value) {
|
|
206
192
|
staging.set(key, value);
|
|
207
193
|
},
|
|
@@ -214,8 +200,7 @@ const create$2 = (iterable) => {
|
|
|
214
200
|
if (prev) staging.set(key, del(prev, eventstamp));
|
|
215
201
|
},
|
|
216
202
|
has(key) {
|
|
217
|
-
|
|
218
|
-
return doc !== void 0 && !doc["~deletedAt"];
|
|
203
|
+
return staging.get(key) !== void 0;
|
|
219
204
|
},
|
|
220
205
|
commit() {
|
|
221
206
|
if (committed) return;
|
|
@@ -304,46 +289,30 @@ const create$1 = () => {
|
|
|
304
289
|
const putKeyValues = [];
|
|
305
290
|
const patchKeyValues = [];
|
|
306
291
|
const deleteKeys = [];
|
|
307
|
-
const txState = /* @__PURE__ */ new Map();
|
|
308
292
|
return {
|
|
309
293
|
put(key, value) {
|
|
310
294
|
for (const fn of listeners.beforePut) fn(key, value);
|
|
311
295
|
tx.put(key, encodeValue(key, value));
|
|
312
|
-
txState.set(key, value);
|
|
313
296
|
putKeyValues.push([key, value]);
|
|
314
297
|
},
|
|
315
298
|
patch(key, value) {
|
|
316
299
|
for (const fn of listeners.beforePatch) fn(key, value);
|
|
317
300
|
tx.patch(key, encode(key, value, clock.now()));
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
else baseValue = decodeActive(kv.get(key));
|
|
321
|
-
if (baseValue) {
|
|
322
|
-
const merged = {
|
|
323
|
-
...baseValue,
|
|
324
|
-
...value
|
|
325
|
-
};
|
|
326
|
-
txState.set(key, merged);
|
|
327
|
-
patchKeyValues.push([key, merged]);
|
|
328
|
-
}
|
|
301
|
+
const merged = decodeActive(tx.get(key));
|
|
302
|
+
if (merged) patchKeyValues.push([key, merged]);
|
|
329
303
|
},
|
|
330
304
|
merge(doc) {
|
|
331
|
-
if (doc["~deletedAt"]) {
|
|
332
|
-
this.del(doc["~id"]);
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
305
|
if (tx.has(doc["~id"])) tx.patch(doc["~id"], doc);
|
|
336
306
|
else tx.put(doc["~id"], doc);
|
|
337
|
-
const currentDoc =
|
|
307
|
+
const currentDoc = tx.get(doc["~id"]);
|
|
338
308
|
if (currentDoc && !currentDoc["~deletedAt"]) {
|
|
339
309
|
const merged = decode(currentDoc)["~data"];
|
|
340
|
-
txState.set(doc["~id"], merged);
|
|
341
310
|
patchKeyValues.push([doc["~id"], merged]);
|
|
342
311
|
}
|
|
343
312
|
},
|
|
344
313
|
del(key) {
|
|
345
314
|
for (const fn of listeners.beforeDel) fn(key);
|
|
346
|
-
if (!
|
|
315
|
+
if (!tx.get(key)) return;
|
|
347
316
|
tx.del(key, clock.now());
|
|
348
317
|
deleteKeys.push(key);
|
|
349
318
|
},
|