@procedures/collections 0.60.1 → 0.61.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 +17 -0
- package/dist/undo/undo-log.d.ts +4 -1
- package/dist/undo/undo-log.d.ts.map +1 -1
- package/dist/undo/undo-log.js +6 -35
- package/dist/undo/undo-log.js.map +1 -1
- package/package.json +3 -2
- package/src/undo/undo-log.ts +6 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @procedures/collections
|
|
2
2
|
|
|
3
|
+
## 0.61.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8506442: `fingerprintOf` of the undo log uses `canonicalJson` of `@mark1russell7/rigor-generators` (CLI-128). The local copy of the canonical text is removed.
|
|
8
|
+
|
|
9
|
+
- A JSON value, a `Date`, a `RegExp`, a `Map` and a `Set` keep their fingerprint. A test pins these fingerprints.
|
|
10
|
+
- A `bigint` gets a tag with its value. Before, it caused a `TypeError`.
|
|
11
|
+
- An object with a `toJSON` method gets the fingerprint of the result of that method. Before, the fingerprint read the own keys of the object.
|
|
12
|
+
- A function, a symbol and a cycle cause a `TypeError`. Before, a function and a symbol had the fingerprint of `null`, and a cycle overflowed the stack.
|
|
13
|
+
|
|
14
|
+
Migration: an entry that an older version recorded for an item with a `toJSON` object (not a `Date`) keeps its old fingerprint. Its undo refuses with `UndoConflictError`, as after a change by another writer. The other entries do not change.
|
|
15
|
+
- Updated dependencies [8506442]
|
|
16
|
+
- Updated dependencies [f9a78f9]
|
|
17
|
+
- Updated dependencies [3eb4b59]
|
|
18
|
+
- @procedures/client@0.61.0
|
|
19
|
+
|
|
3
20
|
## 0.60.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/undo/undo-log.d.ts
CHANGED
|
@@ -70,7 +70,10 @@ export declare class UndoConflictError extends Error {
|
|
|
70
70
|
/**
|
|
71
71
|
* The fingerprint of an item: a 64-bit hash of its canonical JSON text, in hexadecimal. A missing
|
|
72
72
|
* item and `null` have the same fingerprint. Two items with the same fields in another order have
|
|
73
|
-
* the same fingerprint.
|
|
73
|
+
* the same fingerprint. A Date, a RegExp, a Map, a Set and a bigint get a tag with their value
|
|
74
|
+
* (`canonicalJson` of `@mark1russell7/rigor-generators`, CLI-128).
|
|
75
|
+
*
|
|
76
|
+
* @throws TypeError when the item holds a function, a symbol or a cycle
|
|
74
77
|
*/
|
|
75
78
|
export declare function fingerprintOf(item: unknown): string;
|
|
76
79
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo-log.d.ts","sourceRoot":"","sources":["../../src/undo/undo-log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"undo-log.d.ts","sourceRoot":"","sources":["../../src/undo/undo-log.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACtG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,+FAA+F;IAC/F,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,gCAAgC;AAChC,MAAM,WAAW,SAAS;IACxB,qDAAqD;IACrD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,QAAQ,CAAC,UAA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EAO7B;IAED;;;;;;OAMG;IACG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBnD;IAED,uDAAuD;IACjD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAEpC;IAED;;;;;;;;;;;;OAYG;IACG,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAyBjC;CACF"}
|
package/dist/undo/undo-log.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canonicalJson } from "@mark1russell7/rigor-generators";
|
|
1
2
|
import { applyPatch } from "@procedures/client/query";
|
|
2
3
|
import { inversePatch, touchedValues } from "./inverse.js";
|
|
3
4
|
/**
|
|
@@ -17,46 +18,16 @@ export class UndoConflictError extends Error {
|
|
|
17
18
|
function isObject(value) {
|
|
18
19
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
20
|
}
|
|
20
|
-
/**
|
|
21
|
-
* The tagged text of a value that has no own keys, or `undefined` for each other value (CLI-127). The
|
|
22
|
-
* items of a Map or a Set are in the order of their text. A tag is not JSON, so it is not the text of an object.
|
|
23
|
-
*/
|
|
24
|
-
function taggedText(value) {
|
|
25
|
-
if (value instanceof Date)
|
|
26
|
-
return `Date(${value.getTime()})`;
|
|
27
|
-
if (value instanceof RegExp)
|
|
28
|
-
return `RegExp(${JSON.stringify(String(value))})`;
|
|
29
|
-
if (value instanceof Map)
|
|
30
|
-
return `Map(${[...value].map(([key, item]) => `[${canonical(key)},${canonical(item)}]`).sort().join(",")})`;
|
|
31
|
-
if (value instanceof Set)
|
|
32
|
-
return `Set(${[...value].map(canonical).sort().join(",")})`;
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The JSON text of a value with the keys of each object in order. A missing item is `undefined`. A
|
|
37
|
-
* Date, a RegExp, a Map and a Set get a tag with their value. Before CLI-127, the text of each one was `{}`.
|
|
38
|
-
*/
|
|
39
|
-
function canonical(value) {
|
|
40
|
-
if (value === undefined || value === null)
|
|
41
|
-
return "null";
|
|
42
|
-
if (Array.isArray(value))
|
|
43
|
-
return `[${value.map((item) => (item === undefined ? "null" : canonical(item))).join(",")}]`;
|
|
44
|
-
const tag = typeof value === "object" ? taggedText(value) : undefined;
|
|
45
|
-
if (tag !== undefined)
|
|
46
|
-
return tag;
|
|
47
|
-
if (isObject(value)) {
|
|
48
|
-
const keys = Object.keys(value).filter((key) => value[key] !== undefined).sort();
|
|
49
|
-
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
50
|
-
}
|
|
51
|
-
return JSON.stringify(value) ?? "null";
|
|
52
|
-
}
|
|
53
21
|
/**
|
|
54
22
|
* The fingerprint of an item: a 64-bit hash of its canonical JSON text, in hexadecimal. A missing
|
|
55
23
|
* item and `null` have the same fingerprint. Two items with the same fields in another order have
|
|
56
|
-
* the same fingerprint.
|
|
24
|
+
* the same fingerprint. A Date, a RegExp, a Map, a Set and a bigint get a tag with their value
|
|
25
|
+
* (`canonicalJson` of `@mark1russell7/rigor-generators`, CLI-128).
|
|
26
|
+
*
|
|
27
|
+
* @throws TypeError when the item holds a function, a symbol or a cycle
|
|
57
28
|
*/
|
|
58
29
|
export function fingerprintOf(item) {
|
|
59
|
-
const text =
|
|
30
|
+
const text = canonicalJson(item, { form: "json", tags: "typed" });
|
|
60
31
|
// Two 32-bit FNV-1a hashes with different offsets: no dependency, and the same in each runtime
|
|
61
32
|
let a = 0x811c9dc5;
|
|
62
33
|
let b = 0x01000193 ^ 0x5bd1e995;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo-log.js","sourceRoot":"","sources":["../../src/undo/undo-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkD,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA+D3D;;;GAGG;AACH,MAAM,OAAO,iBAAkB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AAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7G,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3B,CAAC;QAED,0BAA0B;QAC1B,KAAK,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACpD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;gBAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;;gBAC/D,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC;QACD,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3D,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/collections",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "Collections for TypeScript: ArrayList, LinkedList, ArrayDeque, HashMap, LinkedHashMap, TreeMap (red-black), PriorityQueue, LRU and TTL maps, async queues, channels and collectors, tested with fast-check.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"collections",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@mark1russell7/collections": "^0.10.0",
|
|
71
|
-
"@
|
|
71
|
+
"@mark1russell7/rigor-generators": "^0.2.0",
|
|
72
|
+
"@procedures/client": "0.61.0"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
75
|
"@mark1russell7/rigor-testkit": "^0.1.4"
|
package/src/undo/undo-log.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canonicalJson } from "@mark1russell7/rigor-generators";
|
|
1
2
|
import { applyPatch, type StoragePatch, type StoragePatchOperations } from "@procedures/client/query";
|
|
2
3
|
import type { CollectionStorage } from "../storage/interface.js";
|
|
3
4
|
import { inversePatch, touchedValues } from "./inverse.js";
|
|
@@ -83,41 +84,16 @@ function isObject(value: unknown): value is Record<string, unknown> {
|
|
|
83
84
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
/**
|
|
87
|
-
* The tagged text of a value that has no own keys, or `undefined` for each other value (CLI-127). The
|
|
88
|
-
* items of a Map or a Set are in the order of their text. A tag is not JSON, so it is not the text of an object.
|
|
89
|
-
*/
|
|
90
|
-
function taggedText(value: object): string | undefined {
|
|
91
|
-
if (value instanceof Date) return `Date(${value.getTime()})`;
|
|
92
|
-
if (value instanceof RegExp) return `RegExp(${JSON.stringify(String(value))})`;
|
|
93
|
-
if (value instanceof Map) return `Map(${[...value].map(([key, item]) => `[${canonical(key)},${canonical(item)}]`).sort().join(",")})`;
|
|
94
|
-
if (value instanceof Set) return `Set(${[...value].map(canonical).sort().join(",")})`;
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* The JSON text of a value with the keys of each object in order. A missing item is `undefined`. A
|
|
100
|
-
* Date, a RegExp, a Map and a Set get a tag with their value. Before CLI-127, the text of each one was `{}`.
|
|
101
|
-
*/
|
|
102
|
-
function canonical(value: unknown): string {
|
|
103
|
-
if (value === undefined || value === null) return "null";
|
|
104
|
-
if (Array.isArray(value)) return `[${value.map((item) => (item === undefined ? "null" : canonical(item))).join(",")}]`;
|
|
105
|
-
const tag = typeof value === "object" ? taggedText(value) : undefined;
|
|
106
|
-
if (tag !== undefined) return tag;
|
|
107
|
-
if (isObject(value)) {
|
|
108
|
-
const keys = Object.keys(value).filter((key) => value[key] !== undefined).sort();
|
|
109
|
-
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
110
|
-
}
|
|
111
|
-
return JSON.stringify(value) ?? "null";
|
|
112
|
-
}
|
|
113
|
-
|
|
114
87
|
/**
|
|
115
88
|
* The fingerprint of an item: a 64-bit hash of its canonical JSON text, in hexadecimal. A missing
|
|
116
89
|
* item and `null` have the same fingerprint. Two items with the same fields in another order have
|
|
117
|
-
* the same fingerprint.
|
|
90
|
+
* the same fingerprint. A Date, a RegExp, a Map, a Set and a bigint get a tag with their value
|
|
91
|
+
* (`canonicalJson` of `@mark1russell7/rigor-generators`, CLI-128).
|
|
92
|
+
*
|
|
93
|
+
* @throws TypeError when the item holds a function, a symbol or a cycle
|
|
118
94
|
*/
|
|
119
95
|
export function fingerprintOf(item: unknown): string {
|
|
120
|
-
const text =
|
|
96
|
+
const text = canonicalJson(item, { form: "json", tags: "typed" });
|
|
121
97
|
// Two 32-bit FNV-1a hashes with different offsets: no dependency, and the same in each runtime
|
|
122
98
|
let a = 0x811c9dc5;
|
|
123
99
|
let b = 0x01000193 ^ 0x5bd1e995;
|