@verdant-web/common 1.11.0 → 1.11.1
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/cjs/EventSubscriber.d.ts +17 -17
- package/dist/cjs/EventSubscriber.js +66 -66
- package/dist/cjs/baseline.d.ts +5 -5
- package/dist/cjs/baseline.js +2 -2
- package/dist/cjs/batching.d.ts +41 -41
- package/dist/cjs/batching.js +88 -88
- package/dist/cjs/files.d.ts +19 -19
- package/dist/cjs/files.js +18 -18
- package/dist/cjs/index.d.ts +18 -18
- package/dist/cjs/index.js +35 -35
- package/dist/cjs/indexes.d.ts +14 -14
- package/dist/cjs/indexes.js +115 -115
- package/dist/cjs/indexes.test.d.ts +1 -1
- package/dist/cjs/indexes.test.js +127 -127
- package/dist/cjs/migration.d.ts +98 -98
- package/dist/cjs/migration.js +127 -127
- package/dist/cjs/oids.d.ts +87 -87
- package/dist/cjs/oids.js +374 -374
- package/dist/cjs/oids.test.d.ts +1 -1
- package/dist/cjs/oids.test.js +245 -245
- package/dist/cjs/operation.d.ts +139 -139
- package/dist/cjs/operation.js +532 -532
- package/dist/cjs/operation.test.d.ts +1 -1
- package/dist/cjs/operation.test.js +484 -484
- package/dist/cjs/patch.d.ts +26 -26
- package/dist/cjs/patch.js +226 -226
- package/dist/cjs/presence.d.ts +27 -27
- package/dist/cjs/presence.js +2 -2
- package/dist/cjs/protocol.d.ts +145 -145
- package/dist/cjs/protocol.js +3 -3
- package/dist/cjs/refs.d.ts +5 -5
- package/dist/cjs/refs.js +21 -21
- package/dist/cjs/replica.d.ts +28 -28
- package/dist/cjs/replica.js +28 -28
- package/dist/cjs/schema/defaults.d.ts +4 -4
- package/dist/cjs/schema/defaults.js +71 -71
- package/dist/cjs/schema/defaults.test.d.ts +1 -1
- package/dist/cjs/schema/defaults.test.js +20 -20
- package/dist/cjs/schema/index.d.ts +8 -8
- package/dist/cjs/schema/index.js +28 -28
- package/dist/cjs/schema/indexFilters.d.ts +6 -6
- package/dist/cjs/schema/indexFilters.js +30 -30
- package/dist/cjs/schema/types/collection.d.ts +51 -51
- package/dist/cjs/schema/types/collection.js +2 -2
- package/dist/cjs/schema/types/compounds.d.ts +12 -12
- package/dist/cjs/schema/types/compounds.js +2 -2
- package/dist/cjs/schema/types/fields.d.ts +59 -59
- package/dist/cjs/schema/types/fields.js +2 -2
- package/dist/cjs/schema/types/filters.d.ts +29 -29
- package/dist/cjs/schema/types/filters.js +2 -2
- package/dist/cjs/schema/types/shapes.d.ts +21 -21
- package/dist/cjs/schema/types/shapes.js +2 -2
- package/dist/cjs/schema/types/synthetics.d.ts +28 -28
- package/dist/cjs/schema/types/synthetics.js +2 -2
- package/dist/cjs/schema/types.d.ts +18 -18
- package/dist/cjs/schema/types.js +22 -22
- package/dist/cjs/timestamp.d.ts +48 -48
- package/dist/cjs/timestamp.js +243 -243
- package/dist/cjs/timestamp.test.d.ts +1 -1
- package/dist/cjs/timestamp.test.js +93 -93
- package/dist/cjs/undo.d.ts +3 -3
- package/dist/cjs/undo.js +198 -198
- package/dist/cjs/utils.d.ts +15 -15
- package/dist/cjs/utils.js +127 -127
- package/dist/cjs/utils.test.d.ts +1 -1
- package/dist/cjs/utils.test.js +36 -36
- package/dist/esm/EventSubscriber.d.ts +17 -17
- package/dist/esm/EventSubscriber.js +62 -62
- package/dist/esm/baseline.d.ts +5 -5
- package/dist/esm/baseline.js +1 -1
- package/dist/esm/batching.d.ts +41 -41
- package/dist/esm/batching.js +83 -83
- package/dist/esm/files.d.ts +19 -19
- package/dist/esm/files.js +12 -12
- package/dist/esm/index.d.ts +18 -18
- package/dist/esm/index.js +15 -15
- package/dist/esm/indexes.d.ts +14 -14
- package/dist/esm/indexes.js +105 -105
- package/dist/esm/indexes.test.d.ts +1 -1
- package/dist/esm/indexes.test.js +125 -125
- package/dist/esm/migration.d.ts +98 -98
- package/dist/esm/migration.js +121 -121
- package/dist/esm/oids.d.ts +87 -87
- package/dist/esm/oids.js +347 -347
- package/dist/esm/oids.test.d.ts +1 -1
- package/dist/esm/oids.test.js +243 -243
- package/dist/esm/operation.d.ts +139 -139
- package/dist/esm/operation.js +517 -517
- package/dist/esm/operation.test.d.ts +1 -1
- package/dist/esm/operation.test.js +482 -482
- package/dist/esm/patch.d.ts +26 -26
- package/dist/esm/patch.js +222 -222
- package/dist/esm/presence.d.ts +27 -27
- package/dist/esm/presence.js +1 -1
- package/dist/esm/protocol.d.ts +145 -145
- package/dist/esm/protocol.js +2 -2
- package/dist/esm/refs.d.ts +5 -5
- package/dist/esm/refs.js +16 -16
- package/dist/esm/replica.d.ts +28 -28
- package/dist/esm/replica.js +25 -25
- package/dist/esm/schema/defaults.d.ts +4 -4
- package/dist/esm/schema/defaults.js +65 -65
- package/dist/esm/schema/defaults.test.d.ts +1 -1
- package/dist/esm/schema/defaults.test.js +18 -18
- package/dist/esm/schema/index.d.ts +8 -8
- package/dist/esm/schema/index.js +9 -9
- package/dist/esm/schema/indexFilters.d.ts +6 -6
- package/dist/esm/schema/indexFilters.js +22 -22
- package/dist/esm/schema/types/collection.d.ts +51 -51
- package/dist/esm/schema/types/collection.js +1 -1
- package/dist/esm/schema/types/compounds.d.ts +12 -12
- package/dist/esm/schema/types/compounds.js +1 -1
- package/dist/esm/schema/types/fields.d.ts +59 -59
- package/dist/esm/schema/types/fields.js +1 -1
- package/dist/esm/schema/types/filters.d.ts +29 -29
- package/dist/esm/schema/types/filters.js +1 -1
- package/dist/esm/schema/types/shapes.d.ts +21 -21
- package/dist/esm/schema/types/shapes.js +1 -1
- package/dist/esm/schema/types/synthetics.d.ts +28 -28
- package/dist/esm/schema/types/synthetics.js +1 -1
- package/dist/esm/schema/types.d.ts +18 -18
- package/dist/esm/schema/types.js +6 -6
- package/dist/esm/timestamp.d.ts +48 -48
- package/dist/esm/timestamp.js +228 -228
- package/dist/esm/timestamp.test.d.ts +1 -1
- package/dist/esm/timestamp.test.js +91 -91
- package/dist/esm/undo.d.ts +3 -3
- package/dist/esm/undo.js +194 -194
- package/dist/esm/utils.d.ts +15 -15
- package/dist/esm/utils.js +113 -113
- package/dist/esm/utils.test.d.ts +1 -1
- package/dist/esm/utils.test.js +34 -34
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/files.test.d.ts +0 -1
- package/dist/cjs/files.test.js +0 -81
- package/dist/cjs/files.test.js.map +0 -1
- package/dist/esm/files.test.d.ts +0 -1
- package/dist/esm/files.test.js +0 -79
- package/dist/esm/files.test.js.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const files_js_1 = require("./files.js");
|
|
5
|
-
const oids_js_1 = require("./oids.js");
|
|
6
|
-
const operation_js_1 = require("./operation.js");
|
|
7
|
-
function createClock(init = 0) {
|
|
8
|
-
let i = init;
|
|
9
|
-
return () => (i++).toString();
|
|
10
|
-
}
|
|
11
|
-
(0, vitest_1.describe)('creating diff patch operations', () => {
|
|
12
|
-
(0, vitest_1.describe)('on flat objects', () => {
|
|
13
|
-
(0, vitest_1.it)('generates and applies set and remove operations', () => {
|
|
14
|
-
const from = { foo: 'bar', baz: 'qux', zing: 1 };
|
|
15
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
16
|
-
const to = { foo: 'bar', baz: 'pop' };
|
|
17
|
-
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
18
|
-
const ops = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const files_js_1 = require("./files.js");
|
|
5
|
+
const oids_js_1 = require("./oids.js");
|
|
6
|
+
const operation_js_1 = require("./operation.js");
|
|
7
|
+
function createClock(init = 0) {
|
|
8
|
+
let i = init;
|
|
9
|
+
return () => (i++).toString();
|
|
10
|
+
}
|
|
11
|
+
(0, vitest_1.describe)('creating diff patch operations', () => {
|
|
12
|
+
(0, vitest_1.describe)('on flat objects', () => {
|
|
13
|
+
(0, vitest_1.it)('generates and applies set and remove operations', () => {
|
|
14
|
+
const from = { foo: 'bar', baz: 'qux', zing: 1 };
|
|
15
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
16
|
+
const to = { foo: 'bar', baz: 'pop' };
|
|
17
|
+
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
18
|
+
const ops = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
19
19
|
(0, vitest_1.expect)(ops).toMatchInlineSnapshot(`
|
|
20
20
|
[
|
|
21
21
|
{
|
|
@@ -36,22 +36,22 @@ function createClock(init = 0) {
|
|
|
36
36
|
"timestamp": "1",
|
|
37
37
|
},
|
|
38
38
|
]
|
|
39
|
-
`);
|
|
40
|
-
const result = (0, operation_js_1.applyOperations)(from, ops);
|
|
41
|
-
(0, vitest_1.expect)(result).toEqual(to);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
(0, vitest_1.describe)('on nested objects', () => {
|
|
45
|
-
(0, vitest_1.it)('replaces whole nested objects', () => {
|
|
46
|
-
const from = (0, oids_js_1.assignOid)({
|
|
47
|
-
foo: 'bar',
|
|
48
|
-
baz: (0, oids_js_1.assignOid)({ qux: 'corge' }, 'test/a:0'),
|
|
49
|
-
}, 'test/a');
|
|
50
|
-
const to = (0, oids_js_1.assignOid)({
|
|
51
|
-
foo: 'bar',
|
|
52
|
-
baz: (0, oids_js_1.assignOid)({ qux: 'grault' }, 'test/a:1'),
|
|
53
|
-
}, 'test/a');
|
|
54
|
-
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
39
|
+
`);
|
|
40
|
+
const result = (0, operation_js_1.applyOperations)(from, ops);
|
|
41
|
+
(0, vitest_1.expect)(result).toEqual(to);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.describe)('on nested objects', () => {
|
|
45
|
+
(0, vitest_1.it)('replaces whole nested objects', () => {
|
|
46
|
+
const from = (0, oids_js_1.assignOid)({
|
|
47
|
+
foo: 'bar',
|
|
48
|
+
baz: (0, oids_js_1.assignOid)({ qux: 'corge' }, 'test/a:0'),
|
|
49
|
+
}, 'test/a');
|
|
50
|
+
const to = (0, oids_js_1.assignOid)({
|
|
51
|
+
foo: 'bar',
|
|
52
|
+
baz: (0, oids_js_1.assignOid)({ qux: 'grault' }, 'test/a:1'),
|
|
53
|
+
}, 'test/a');
|
|
54
|
+
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
55
55
|
(0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
|
|
56
56
|
[
|
|
57
57
|
{
|
|
@@ -84,22 +84,22 @@ function createClock(init = 0) {
|
|
|
84
84
|
"timestamp": "2",
|
|
85
85
|
},
|
|
86
86
|
]
|
|
87
|
-
`);
|
|
88
|
-
});
|
|
89
|
-
(0, vitest_1.it)('replaces whole nested objects with different ids even if fields are the same', () => {
|
|
90
|
-
const from = {
|
|
91
|
-
foo: 'bar',
|
|
92
|
-
baz: { qux: 'corge' },
|
|
93
|
-
};
|
|
94
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
95
|
-
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
96
|
-
const to = {
|
|
97
|
-
foo: 'bar',
|
|
98
|
-
baz: { qux: 'corge' },
|
|
99
|
-
};
|
|
100
|
-
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
101
|
-
(0, oids_js_1.assignOid)(to.baz, 'test/a:1');
|
|
102
|
-
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
87
|
+
`);
|
|
88
|
+
});
|
|
89
|
+
(0, vitest_1.it)('replaces whole nested objects with different ids even if fields are the same', () => {
|
|
90
|
+
const from = {
|
|
91
|
+
foo: 'bar',
|
|
92
|
+
baz: { qux: 'corge' },
|
|
93
|
+
};
|
|
94
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
95
|
+
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
96
|
+
const to = {
|
|
97
|
+
foo: 'bar',
|
|
98
|
+
baz: { qux: 'corge' },
|
|
99
|
+
};
|
|
100
|
+
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
101
|
+
(0, oids_js_1.assignOid)(to.baz, 'test/a:1');
|
|
102
|
+
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
103
103
|
(0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
|
|
104
104
|
[
|
|
105
105
|
{
|
|
@@ -132,38 +132,38 @@ function createClock(init = 0) {
|
|
|
132
132
|
"timestamp": "2",
|
|
133
133
|
},
|
|
134
134
|
]
|
|
135
|
-
`);
|
|
136
|
-
});
|
|
137
|
-
(0, vitest_1.it)('does not replace objects with the same identity and same fields', () => {
|
|
138
|
-
const from = {
|
|
139
|
-
foo: 'bar',
|
|
140
|
-
baz: { qux: 'corge' },
|
|
141
|
-
};
|
|
142
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
143
|
-
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
144
|
-
const to = {
|
|
145
|
-
foo: 'bar',
|
|
146
|
-
baz: { qux: 'corge' },
|
|
147
|
-
};
|
|
148
|
-
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
149
|
-
(0, oids_js_1.assignOid)(to.baz, 'test/a:0');
|
|
150
|
-
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
151
|
-
(0, vitest_1.expect)(patches).toEqual([]);
|
|
152
|
-
});
|
|
153
|
-
(0, vitest_1.it)('patches sub-objects with same identity', () => {
|
|
154
|
-
const from = {
|
|
155
|
-
foo: 'bar',
|
|
156
|
-
baz: { qux: 'corge' },
|
|
157
|
-
};
|
|
158
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
159
|
-
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
160
|
-
const to = {
|
|
161
|
-
foo: 'bar',
|
|
162
|
-
baz: { qux: 'fig' },
|
|
163
|
-
};
|
|
164
|
-
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
165
|
-
(0, oids_js_1.assignOid)(to.baz, 'test/a:0');
|
|
166
|
-
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
135
|
+
`);
|
|
136
|
+
});
|
|
137
|
+
(0, vitest_1.it)('does not replace objects with the same identity and same fields', () => {
|
|
138
|
+
const from = {
|
|
139
|
+
foo: 'bar',
|
|
140
|
+
baz: { qux: 'corge' },
|
|
141
|
+
};
|
|
142
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
143
|
+
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
144
|
+
const to = {
|
|
145
|
+
foo: 'bar',
|
|
146
|
+
baz: { qux: 'corge' },
|
|
147
|
+
};
|
|
148
|
+
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
149
|
+
(0, oids_js_1.assignOid)(to.baz, 'test/a:0');
|
|
150
|
+
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
151
|
+
(0, vitest_1.expect)(patches).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
(0, vitest_1.it)('patches sub-objects with same identity', () => {
|
|
154
|
+
const from = {
|
|
155
|
+
foo: 'bar',
|
|
156
|
+
baz: { qux: 'corge' },
|
|
157
|
+
};
|
|
158
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
159
|
+
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
160
|
+
const to = {
|
|
161
|
+
foo: 'bar',
|
|
162
|
+
baz: { qux: 'fig' },
|
|
163
|
+
};
|
|
164
|
+
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
165
|
+
(0, oids_js_1.assignOid)(to.baz, 'test/a:0');
|
|
166
|
+
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), []);
|
|
167
167
|
(0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
|
|
168
168
|
[
|
|
169
169
|
{
|
|
@@ -176,23 +176,23 @@ function createClock(init = 0) {
|
|
|
176
176
|
"timestamp": "0",
|
|
177
177
|
},
|
|
178
178
|
]
|
|
179
|
-
`);
|
|
180
|
-
});
|
|
181
|
-
(0, vitest_1.it)('retains keys which are undefined in new object if defaultUndefined is set', () => {
|
|
182
|
-
const from = {
|
|
183
|
-
foo: 'bar',
|
|
184
|
-
baz: { qux: 'corge' },
|
|
185
|
-
};
|
|
186
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
187
|
-
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
188
|
-
const to = {
|
|
189
|
-
foo: 'bip',
|
|
190
|
-
};
|
|
191
|
-
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
192
|
-
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), [], undefined, [], {
|
|
193
|
-
defaultUndefined: true,
|
|
194
|
-
mergeUnknownObjects: true,
|
|
195
|
-
});
|
|
179
|
+
`);
|
|
180
|
+
});
|
|
181
|
+
(0, vitest_1.it)('retains keys which are undefined in new object if defaultUndefined is set', () => {
|
|
182
|
+
const from = {
|
|
183
|
+
foo: 'bar',
|
|
184
|
+
baz: { qux: 'corge' },
|
|
185
|
+
};
|
|
186
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
187
|
+
(0, oids_js_1.assignOid)(from.baz, 'test/a:0');
|
|
188
|
+
const to = {
|
|
189
|
+
foo: 'bip',
|
|
190
|
+
};
|
|
191
|
+
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
192
|
+
const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), [], undefined, [], {
|
|
193
|
+
defaultUndefined: true,
|
|
194
|
+
mergeUnknownObjects: true,
|
|
195
|
+
});
|
|
196
196
|
(0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
|
|
197
197
|
[
|
|
198
198
|
{
|
|
@@ -205,74 +205,74 @@ function createClock(init = 0) {
|
|
|
205
205
|
"timestamp": "0",
|
|
206
206
|
},
|
|
207
207
|
]
|
|
208
|
-
`);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
(0, vitest_1.describe)('on lists of primitives', () => {
|
|
212
|
-
(0, vitest_1.it)('pushes items', async () => {
|
|
213
|
-
(0, vitest_1.expect)((0, operation_js_1.applyOperations)((0, oids_js_1.assignOid)(['foo', 'bar'], 'test/a'), [
|
|
214
|
-
{
|
|
215
|
-
oid: 'test/a',
|
|
216
|
-
timestamp: 'meh',
|
|
217
|
-
data: {
|
|
218
|
-
op: 'list-push',
|
|
219
|
-
value: 'baz',
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
])).toEqual((0, oids_js_1.assignOid)(['foo', 'bar', 'baz'], 'test/a'));
|
|
223
|
-
});
|
|
224
|
-
vitest_1.it.todo('sets items');
|
|
225
|
-
vitest_1.it.todo('inserts items');
|
|
226
|
-
vitest_1.it.todo('removes items by index');
|
|
227
|
-
vitest_1.it.todo('removes items by value');
|
|
228
|
-
vitest_1.it.todo('moves items by index');
|
|
229
|
-
vitest_1.it.todo('moves items by value');
|
|
230
|
-
});
|
|
231
|
-
vitest_1.describe.todo('on lists of objects', () => {
|
|
232
|
-
vitest_1.it.todo('pushes items');
|
|
233
|
-
vitest_1.it.todo('moves objects by identity');
|
|
234
|
-
vitest_1.it.todo('removes objects by identity');
|
|
235
|
-
});
|
|
236
|
-
vitest_1.describe.todo('on lists of lists', () => {
|
|
237
|
-
vitest_1.it.todo('rejects operations by value or identity');
|
|
238
|
-
});
|
|
239
|
-
(0, vitest_1.it)('should work for complex nested arrays and objects', () => {
|
|
240
|
-
const from = {
|
|
241
|
-
foo: {
|
|
242
|
-
bar: [1, 2, 3],
|
|
243
|
-
},
|
|
244
|
-
baz: [
|
|
245
|
-
{
|
|
246
|
-
corge: true,
|
|
247
|
-
},
|
|
248
|
-
],
|
|
249
|
-
};
|
|
250
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
251
|
-
(0, oids_js_1.assignOid)(from.foo, 'test/a:1');
|
|
252
|
-
(0, oids_js_1.assignOid)(from.foo.bar, 'test/a:2');
|
|
253
|
-
(0, oids_js_1.assignOid)(from.baz, 'test/a:3');
|
|
254
|
-
(0, oids_js_1.assignOid)(from.baz[0], 'test/a:4');
|
|
255
|
-
const to = {
|
|
256
|
-
foo: {
|
|
257
|
-
bar: [1, 2],
|
|
258
|
-
bop: [0],
|
|
259
|
-
},
|
|
260
|
-
baz: [
|
|
261
|
-
{
|
|
262
|
-
corge: false,
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
corge: false,
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
};
|
|
269
|
-
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
270
|
-
(0, oids_js_1.assignOid)(to.foo, 'test/a:1');
|
|
271
|
-
(0, oids_js_1.assignOid)(to.foo.bar, 'test/a:2');
|
|
272
|
-
(0, oids_js_1.assignOid)(to.foo.bop, 'test/a:6');
|
|
273
|
-
(0, oids_js_1.assignOid)(to.baz, 'test/a:3');
|
|
274
|
-
(0, oids_js_1.assignOid)(to.baz[0], 'test/a:4');
|
|
275
|
-
(0, oids_js_1.assignOid)(to.baz[1], 'test/a:5');
|
|
208
|
+
`);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
(0, vitest_1.describe)('on lists of primitives', () => {
|
|
212
|
+
(0, vitest_1.it)('pushes items', async () => {
|
|
213
|
+
(0, vitest_1.expect)((0, operation_js_1.applyOperations)((0, oids_js_1.assignOid)(['foo', 'bar'], 'test/a'), [
|
|
214
|
+
{
|
|
215
|
+
oid: 'test/a',
|
|
216
|
+
timestamp: 'meh',
|
|
217
|
+
data: {
|
|
218
|
+
op: 'list-push',
|
|
219
|
+
value: 'baz',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
])).toEqual((0, oids_js_1.assignOid)(['foo', 'bar', 'baz'], 'test/a'));
|
|
223
|
+
});
|
|
224
|
+
vitest_1.it.todo('sets items');
|
|
225
|
+
vitest_1.it.todo('inserts items');
|
|
226
|
+
vitest_1.it.todo('removes items by index');
|
|
227
|
+
vitest_1.it.todo('removes items by value');
|
|
228
|
+
vitest_1.it.todo('moves items by index');
|
|
229
|
+
vitest_1.it.todo('moves items by value');
|
|
230
|
+
});
|
|
231
|
+
vitest_1.describe.todo('on lists of objects', () => {
|
|
232
|
+
vitest_1.it.todo('pushes items');
|
|
233
|
+
vitest_1.it.todo('moves objects by identity');
|
|
234
|
+
vitest_1.it.todo('removes objects by identity');
|
|
235
|
+
});
|
|
236
|
+
vitest_1.describe.todo('on lists of lists', () => {
|
|
237
|
+
vitest_1.it.todo('rejects operations by value or identity');
|
|
238
|
+
});
|
|
239
|
+
(0, vitest_1.it)('should work for complex nested arrays and objects', () => {
|
|
240
|
+
const from = {
|
|
241
|
+
foo: {
|
|
242
|
+
bar: [1, 2, 3],
|
|
243
|
+
},
|
|
244
|
+
baz: [
|
|
245
|
+
{
|
|
246
|
+
corge: true,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
};
|
|
250
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
251
|
+
(0, oids_js_1.assignOid)(from.foo, 'test/a:1');
|
|
252
|
+
(0, oids_js_1.assignOid)(from.foo.bar, 'test/a:2');
|
|
253
|
+
(0, oids_js_1.assignOid)(from.baz, 'test/a:3');
|
|
254
|
+
(0, oids_js_1.assignOid)(from.baz[0], 'test/a:4');
|
|
255
|
+
const to = {
|
|
256
|
+
foo: {
|
|
257
|
+
bar: [1, 2],
|
|
258
|
+
bop: [0],
|
|
259
|
+
},
|
|
260
|
+
baz: [
|
|
261
|
+
{
|
|
262
|
+
corge: false,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
corge: false,
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
};
|
|
269
|
+
(0, oids_js_1.assignOid)(to, 'test/a');
|
|
270
|
+
(0, oids_js_1.assignOid)(to.foo, 'test/a:1');
|
|
271
|
+
(0, oids_js_1.assignOid)(to.foo.bar, 'test/a:2');
|
|
272
|
+
(0, oids_js_1.assignOid)(to.foo.bop, 'test/a:6');
|
|
273
|
+
(0, oids_js_1.assignOid)(to.baz, 'test/a:3');
|
|
274
|
+
(0, oids_js_1.assignOid)(to.baz[0], 'test/a:4');
|
|
275
|
+
(0, oids_js_1.assignOid)(to.baz[1], 'test/a:5');
|
|
276
276
|
(0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), [])).toMatchInlineSnapshot(`
|
|
277
277
|
[
|
|
278
278
|
{
|
|
@@ -338,37 +338,37 @@ function createClock(init = 0) {
|
|
|
338
338
|
"timestamp": "5",
|
|
339
339
|
},
|
|
340
340
|
]
|
|
341
|
-
`);
|
|
342
|
-
});
|
|
343
|
-
(0, vitest_1.it)('should try to merge unknown objects if specified to do so', () => {
|
|
344
|
-
const from = {
|
|
345
|
-
foo: {
|
|
346
|
-
bar: [1, 2, 3],
|
|
347
|
-
},
|
|
348
|
-
baz: [
|
|
349
|
-
{
|
|
350
|
-
corge: true,
|
|
351
|
-
},
|
|
352
|
-
],
|
|
353
|
-
};
|
|
354
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
355
|
-
(0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
|
|
356
|
-
const to = {
|
|
357
|
-
foo: {
|
|
358
|
-
bar: [1, 2],
|
|
359
|
-
bop: [0],
|
|
360
|
-
},
|
|
361
|
-
baz: [
|
|
362
|
-
{
|
|
363
|
-
corge: false,
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
corge: false,
|
|
367
|
-
},
|
|
368
|
-
],
|
|
369
|
-
};
|
|
370
|
-
(0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), [], createClock(5), [], {
|
|
371
|
-
mergeUnknownObjects: true,
|
|
341
|
+
`);
|
|
342
|
+
});
|
|
343
|
+
(0, vitest_1.it)('should try to merge unknown objects if specified to do so', () => {
|
|
344
|
+
const from = {
|
|
345
|
+
foo: {
|
|
346
|
+
bar: [1, 2, 3],
|
|
347
|
+
},
|
|
348
|
+
baz: [
|
|
349
|
+
{
|
|
350
|
+
corge: true,
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
};
|
|
354
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
355
|
+
(0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
|
|
356
|
+
const to = {
|
|
357
|
+
foo: {
|
|
358
|
+
bar: [1, 2],
|
|
359
|
+
bop: [0],
|
|
360
|
+
},
|
|
361
|
+
baz: [
|
|
362
|
+
{
|
|
363
|
+
corge: false,
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
corge: false,
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
};
|
|
370
|
+
(0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), [], createClock(5), [], {
|
|
371
|
+
mergeUnknownObjects: true,
|
|
372
372
|
})).toMatchInlineSnapshot(`
|
|
373
373
|
[
|
|
374
374
|
{
|
|
@@ -434,25 +434,25 @@ function createClock(init = 0) {
|
|
|
434
434
|
"timestamp": "5",
|
|
435
435
|
},
|
|
436
436
|
]
|
|
437
|
-
`);
|
|
438
|
-
});
|
|
439
|
-
(0, vitest_1.it)('should not diff file refs', () => {
|
|
440
|
-
const from = {
|
|
441
|
-
foo: {
|
|
442
|
-
file: (0, files_js_1.createFileRef)('abc123'),
|
|
443
|
-
},
|
|
444
|
-
bar: [(0, files_js_1.createFileRef)('def456'), (0, files_js_1.createFileRef)('ghi789')],
|
|
445
|
-
};
|
|
446
|
-
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
447
|
-
(0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
|
|
448
|
-
const to = {
|
|
449
|
-
foo: {
|
|
450
|
-
file: (0, files_js_1.createFileRef)('abc456'),
|
|
451
|
-
},
|
|
452
|
-
bar: [(0, files_js_1.createFileRef)('def456')],
|
|
453
|
-
};
|
|
454
|
-
(0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), [], createClock(5), [], {
|
|
455
|
-
mergeUnknownObjects: true,
|
|
437
|
+
`);
|
|
438
|
+
});
|
|
439
|
+
(0, vitest_1.it)('should not diff file refs', () => {
|
|
440
|
+
const from = {
|
|
441
|
+
foo: {
|
|
442
|
+
file: (0, files_js_1.createFileRef)('abc123'),
|
|
443
|
+
},
|
|
444
|
+
bar: [(0, files_js_1.createFileRef)('def456'), (0, files_js_1.createFileRef)('ghi789')],
|
|
445
|
+
};
|
|
446
|
+
(0, oids_js_1.assignOid)(from, 'test/a');
|
|
447
|
+
(0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
|
|
448
|
+
const to = {
|
|
449
|
+
foo: {
|
|
450
|
+
file: (0, files_js_1.createFileRef)('abc456'),
|
|
451
|
+
},
|
|
452
|
+
bar: [(0, files_js_1.createFileRef)('def456')],
|
|
453
|
+
};
|
|
454
|
+
(0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), [], createClock(5), [], {
|
|
455
|
+
mergeUnknownObjects: true,
|
|
456
456
|
})).toMatchInlineSnapshot(`
|
|
457
457
|
[
|
|
458
458
|
{
|
|
@@ -477,157 +477,157 @@ function createClock(init = 0) {
|
|
|
477
477
|
"timestamp": "1",
|
|
478
478
|
},
|
|
479
479
|
]
|
|
480
|
-
`);
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
(0, vitest_1.describe)('substituting refs with objects', () => {
|
|
484
|
-
(0, vitest_1.it)('does nothing when no refs exist', () => {
|
|
485
|
-
const root = {
|
|
486
|
-
foo: 'bar',
|
|
487
|
-
};
|
|
488
|
-
(0, oids_js_1.assignOid)(root, 'test/a');
|
|
489
|
-
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map());
|
|
490
|
-
(0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
|
|
491
|
-
foo: 'bar',
|
|
492
|
-
}, 'test/a'));
|
|
493
|
-
(0, vitest_1.expect)(substituted).toEqual([]);
|
|
494
|
-
});
|
|
495
|
-
(0, vitest_1.it)('inserts top level objects with oids', () => {
|
|
496
|
-
const root = {
|
|
497
|
-
foo: {
|
|
498
|
-
'@@type': 'ref',
|
|
499
|
-
id: 'test/1:a',
|
|
500
|
-
},
|
|
501
|
-
qux: 1,
|
|
502
|
-
};
|
|
503
|
-
(0, oids_js_1.assignOid)(root, 'test/1');
|
|
504
|
-
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([['test/1:a', { foo: 'bar' }]]));
|
|
505
|
-
(0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
|
|
506
|
-
foo: (0, oids_js_1.assignOid)({
|
|
507
|
-
foo: 'bar',
|
|
508
|
-
}, 'test/1:a'),
|
|
509
|
-
qux: 1,
|
|
510
|
-
}, 'test/1'));
|
|
511
|
-
(0, vitest_1.expect)(substituted).toEqual(['test/1:a']);
|
|
512
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
|
|
513
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
|
|
514
|
-
});
|
|
515
|
-
(0, vitest_1.it)('inserts nested objects with oids', () => {
|
|
516
|
-
const root = {
|
|
517
|
-
foo: {
|
|
518
|
-
'@@type': 'ref',
|
|
519
|
-
id: 'test/1:a',
|
|
520
|
-
},
|
|
521
|
-
};
|
|
522
|
-
(0, oids_js_1.assignOid)(root, 'test/1');
|
|
523
|
-
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
|
|
524
|
-
[
|
|
525
|
-
'test/1:a',
|
|
526
|
-
{
|
|
527
|
-
foo: 'bar',
|
|
528
|
-
baz: {
|
|
529
|
-
'@@type': 'ref',
|
|
530
|
-
id: 'test/1:b',
|
|
531
|
-
},
|
|
532
|
-
},
|
|
533
|
-
],
|
|
534
|
-
[
|
|
535
|
-
'test/1:b',
|
|
536
|
-
{
|
|
537
|
-
qux: 'corge',
|
|
538
|
-
},
|
|
539
|
-
],
|
|
540
|
-
]));
|
|
541
|
-
(0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
|
|
542
|
-
foo: (0, oids_js_1.assignOid)({
|
|
543
|
-
foo: 'bar',
|
|
544
|
-
baz: (0, oids_js_1.assignOid)({
|
|
545
|
-
qux: 'corge',
|
|
546
|
-
}, 'test/1:b'),
|
|
547
|
-
}, 'test/1:a'),
|
|
548
|
-
}, 'test/1'));
|
|
549
|
-
(0, vitest_1.expect)(substituted).toEqual(['test/1:a', 'test/1:b']);
|
|
550
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
|
|
551
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
|
|
552
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo.baz)).toEqual('test/1:b');
|
|
553
|
-
});
|
|
554
|
-
(0, vitest_1.it)('substitutes arrays of objects', () => {
|
|
555
|
-
const root = {
|
|
556
|
-
foo: {
|
|
557
|
-
'@@type': 'ref',
|
|
558
|
-
id: 'test/1:c',
|
|
559
|
-
},
|
|
560
|
-
};
|
|
561
|
-
(0, oids_js_1.assignOid)(root, 'test/1');
|
|
562
|
-
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
|
|
563
|
-
[
|
|
564
|
-
'test/1:c',
|
|
565
|
-
[
|
|
566
|
-
{
|
|
567
|
-
'@@type': 'ref',
|
|
568
|
-
id: 'test/1:a',
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
'@@type': 'ref',
|
|
572
|
-
id: 'test/1:b',
|
|
573
|
-
},
|
|
574
|
-
],
|
|
575
|
-
],
|
|
576
|
-
[
|
|
577
|
-
'test/1:a',
|
|
578
|
-
{
|
|
579
|
-
foo: 'bar',
|
|
580
|
-
},
|
|
581
|
-
],
|
|
582
|
-
[
|
|
583
|
-
'test/1:b',
|
|
584
|
-
{
|
|
585
|
-
qux: 'corge',
|
|
586
|
-
},
|
|
587
|
-
],
|
|
588
|
-
]));
|
|
589
|
-
(0, vitest_1.expect)(root).toEqual({
|
|
590
|
-
foo: (0, oids_js_1.assignOid)([
|
|
591
|
-
(0, oids_js_1.assignOid)({
|
|
592
|
-
foo: 'bar',
|
|
593
|
-
}, 'test/1:a'),
|
|
594
|
-
(0, oids_js_1.assignOid)({
|
|
595
|
-
qux: 'corge',
|
|
596
|
-
}, 'test/1:b'),
|
|
597
|
-
], 'test/1:c'),
|
|
598
|
-
});
|
|
599
|
-
(0, vitest_1.expect)(substituted).toEqual(['test/1:c', 'test/1:a', 'test/1:b']);
|
|
600
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
|
|
601
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:c');
|
|
602
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[0])).toEqual('test/1:a');
|
|
603
|
-
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[1])).toEqual('test/1:b');
|
|
604
|
-
});
|
|
605
|
-
vitest_1.it.todo('substitutes arrays of arrays of objects');
|
|
606
|
-
});
|
|
607
|
-
(0, vitest_1.describe)('creating patches from initial state', () => {
|
|
608
|
-
(0, vitest_1.it)('adds oids to all sub-objects', async () => {
|
|
609
|
-
let i = 0;
|
|
610
|
-
function createSubId() {
|
|
611
|
-
return (i++).toString();
|
|
612
|
-
}
|
|
613
|
-
const result = (0, operation_js_1.initialToPatches)({
|
|
614
|
-
foo: {
|
|
615
|
-
bar: 'baz',
|
|
616
|
-
},
|
|
617
|
-
qux: [
|
|
618
|
-
{
|
|
619
|
-
corge: 'grault',
|
|
620
|
-
},
|
|
621
|
-
{
|
|
622
|
-
bin: {
|
|
623
|
-
oof: 1,
|
|
624
|
-
},
|
|
625
|
-
},
|
|
626
|
-
],
|
|
627
|
-
}, 'test/a', createClock(), createSubId);
|
|
628
|
-
/**
|
|
629
|
-
* Patches should not include assigned OID property
|
|
630
|
-
*/
|
|
480
|
+
`);
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
(0, vitest_1.describe)('substituting refs with objects', () => {
|
|
484
|
+
(0, vitest_1.it)('does nothing when no refs exist', () => {
|
|
485
|
+
const root = {
|
|
486
|
+
foo: 'bar',
|
|
487
|
+
};
|
|
488
|
+
(0, oids_js_1.assignOid)(root, 'test/a');
|
|
489
|
+
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map());
|
|
490
|
+
(0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
|
|
491
|
+
foo: 'bar',
|
|
492
|
+
}, 'test/a'));
|
|
493
|
+
(0, vitest_1.expect)(substituted).toEqual([]);
|
|
494
|
+
});
|
|
495
|
+
(0, vitest_1.it)('inserts top level objects with oids', () => {
|
|
496
|
+
const root = {
|
|
497
|
+
foo: {
|
|
498
|
+
'@@type': 'ref',
|
|
499
|
+
id: 'test/1:a',
|
|
500
|
+
},
|
|
501
|
+
qux: 1,
|
|
502
|
+
};
|
|
503
|
+
(0, oids_js_1.assignOid)(root, 'test/1');
|
|
504
|
+
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([['test/1:a', { foo: 'bar' }]]));
|
|
505
|
+
(0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
|
|
506
|
+
foo: (0, oids_js_1.assignOid)({
|
|
507
|
+
foo: 'bar',
|
|
508
|
+
}, 'test/1:a'),
|
|
509
|
+
qux: 1,
|
|
510
|
+
}, 'test/1'));
|
|
511
|
+
(0, vitest_1.expect)(substituted).toEqual(['test/1:a']);
|
|
512
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
|
|
513
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
|
|
514
|
+
});
|
|
515
|
+
(0, vitest_1.it)('inserts nested objects with oids', () => {
|
|
516
|
+
const root = {
|
|
517
|
+
foo: {
|
|
518
|
+
'@@type': 'ref',
|
|
519
|
+
id: 'test/1:a',
|
|
520
|
+
},
|
|
521
|
+
};
|
|
522
|
+
(0, oids_js_1.assignOid)(root, 'test/1');
|
|
523
|
+
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
|
|
524
|
+
[
|
|
525
|
+
'test/1:a',
|
|
526
|
+
{
|
|
527
|
+
foo: 'bar',
|
|
528
|
+
baz: {
|
|
529
|
+
'@@type': 'ref',
|
|
530
|
+
id: 'test/1:b',
|
|
531
|
+
},
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
[
|
|
535
|
+
'test/1:b',
|
|
536
|
+
{
|
|
537
|
+
qux: 'corge',
|
|
538
|
+
},
|
|
539
|
+
],
|
|
540
|
+
]));
|
|
541
|
+
(0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
|
|
542
|
+
foo: (0, oids_js_1.assignOid)({
|
|
543
|
+
foo: 'bar',
|
|
544
|
+
baz: (0, oids_js_1.assignOid)({
|
|
545
|
+
qux: 'corge',
|
|
546
|
+
}, 'test/1:b'),
|
|
547
|
+
}, 'test/1:a'),
|
|
548
|
+
}, 'test/1'));
|
|
549
|
+
(0, vitest_1.expect)(substituted).toEqual(['test/1:a', 'test/1:b']);
|
|
550
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
|
|
551
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
|
|
552
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo.baz)).toEqual('test/1:b');
|
|
553
|
+
});
|
|
554
|
+
(0, vitest_1.it)('substitutes arrays of objects', () => {
|
|
555
|
+
const root = {
|
|
556
|
+
foo: {
|
|
557
|
+
'@@type': 'ref',
|
|
558
|
+
id: 'test/1:c',
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
(0, oids_js_1.assignOid)(root, 'test/1');
|
|
562
|
+
const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
|
|
563
|
+
[
|
|
564
|
+
'test/1:c',
|
|
565
|
+
[
|
|
566
|
+
{
|
|
567
|
+
'@@type': 'ref',
|
|
568
|
+
id: 'test/1:a',
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
'@@type': 'ref',
|
|
572
|
+
id: 'test/1:b',
|
|
573
|
+
},
|
|
574
|
+
],
|
|
575
|
+
],
|
|
576
|
+
[
|
|
577
|
+
'test/1:a',
|
|
578
|
+
{
|
|
579
|
+
foo: 'bar',
|
|
580
|
+
},
|
|
581
|
+
],
|
|
582
|
+
[
|
|
583
|
+
'test/1:b',
|
|
584
|
+
{
|
|
585
|
+
qux: 'corge',
|
|
586
|
+
},
|
|
587
|
+
],
|
|
588
|
+
]));
|
|
589
|
+
(0, vitest_1.expect)(root).toEqual({
|
|
590
|
+
foo: (0, oids_js_1.assignOid)([
|
|
591
|
+
(0, oids_js_1.assignOid)({
|
|
592
|
+
foo: 'bar',
|
|
593
|
+
}, 'test/1:a'),
|
|
594
|
+
(0, oids_js_1.assignOid)({
|
|
595
|
+
qux: 'corge',
|
|
596
|
+
}, 'test/1:b'),
|
|
597
|
+
], 'test/1:c'),
|
|
598
|
+
});
|
|
599
|
+
(0, vitest_1.expect)(substituted).toEqual(['test/1:c', 'test/1:a', 'test/1:b']);
|
|
600
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
|
|
601
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:c');
|
|
602
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[0])).toEqual('test/1:a');
|
|
603
|
+
(0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[1])).toEqual('test/1:b');
|
|
604
|
+
});
|
|
605
|
+
vitest_1.it.todo('substitutes arrays of arrays of objects');
|
|
606
|
+
});
|
|
607
|
+
(0, vitest_1.describe)('creating patches from initial state', () => {
|
|
608
|
+
(0, vitest_1.it)('adds oids to all sub-objects', async () => {
|
|
609
|
+
let i = 0;
|
|
610
|
+
function createSubId() {
|
|
611
|
+
return (i++).toString();
|
|
612
|
+
}
|
|
613
|
+
const result = (0, operation_js_1.initialToPatches)({
|
|
614
|
+
foo: {
|
|
615
|
+
bar: 'baz',
|
|
616
|
+
},
|
|
617
|
+
qux: [
|
|
618
|
+
{
|
|
619
|
+
corge: 'grault',
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
bin: {
|
|
623
|
+
oof: 1,
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
],
|
|
627
|
+
}, 'test/a', createClock(), createSubId);
|
|
628
|
+
/**
|
|
629
|
+
* Patches should not include assigned OID property
|
|
630
|
+
*/
|
|
631
631
|
(0, vitest_1.expect)(result).toMatchInlineSnapshot(`
|
|
632
632
|
[
|
|
633
633
|
{
|
|
@@ -708,120 +708,120 @@ function createClock(init = 0) {
|
|
|
708
708
|
"timestamp": "5",
|
|
709
709
|
},
|
|
710
710
|
]
|
|
711
|
-
`);
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
(0, vitest_1.describe)('applying individual operations', () => {
|
|
715
|
-
(0, vitest_1.it)('applies a list-remove of only the last instance', () => {
|
|
716
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
|
|
717
|
-
op: 'list-remove',
|
|
718
|
-
value: 'a',
|
|
719
|
-
only: 'last',
|
|
720
|
-
})).toEqual(['a', 'b', 'c', 'b']);
|
|
721
|
-
});
|
|
722
|
-
(0, vitest_1.it)('applies a list-remove of only the first instance', () => {
|
|
723
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
|
|
724
|
-
op: 'list-remove',
|
|
725
|
-
value: 'a',
|
|
726
|
-
only: 'first',
|
|
727
|
-
})).toEqual(['b', 'c', 'a', 'b']);
|
|
728
|
-
});
|
|
729
|
-
(0, vitest_1.it)('applies a list-remove of all instances', () => {
|
|
730
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
|
|
731
|
-
op: 'list-remove',
|
|
732
|
-
value: 'a',
|
|
733
|
-
})).toEqual(['b', 'c', 'b']);
|
|
734
|
-
});
|
|
735
|
-
(0, vitest_1.it)('applies a list-remove of an object ref', () => {
|
|
736
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)([
|
|
737
|
-
(0, oids_js_1.createRef)('a'),
|
|
738
|
-
(0, oids_js_1.createRef)('b'),
|
|
739
|
-
(0, oids_js_1.createRef)('c'),
|
|
740
|
-
(0, oids_js_1.createRef)('a'),
|
|
741
|
-
(0, oids_js_1.createRef)('b'),
|
|
742
|
-
], {
|
|
743
|
-
op: 'list-remove',
|
|
744
|
-
value: (0, oids_js_1.createRef)('a'),
|
|
745
|
-
only: 'last',
|
|
746
|
-
})).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c'), (0, oids_js_1.createRef)('b')]);
|
|
747
|
-
});
|
|
748
|
-
(0, vitest_1.it)('applies a list-add of a nonexistent item', () => {
|
|
749
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
|
|
750
|
-
op: 'list-add',
|
|
751
|
-
value: 'd',
|
|
752
|
-
})).toEqual(['a', 'b', 'c', 'd']);
|
|
753
|
-
});
|
|
754
|
-
(0, vitest_1.it)('does not apply a list-add if the item is already present', () => {
|
|
755
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
|
|
756
|
-
op: 'list-add',
|
|
757
|
-
value: 'b',
|
|
758
|
-
})).toEqual(['a', 'b', 'c']);
|
|
759
|
-
});
|
|
760
|
-
});
|
|
761
|
-
(0, vitest_1.describe)('collecting deleted refs during patch application', () => {
|
|
762
|
-
(0, vitest_1.it)('collects refs that are removed from a list', () => {
|
|
763
|
-
const refs = [];
|
|
764
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)([
|
|
765
|
-
(0, oids_js_1.createRef)('a'),
|
|
766
|
-
(0, oids_js_1.createRef)('b'),
|
|
767
|
-
(0, oids_js_1.createRef)('c'),
|
|
768
|
-
(0, oids_js_1.createRef)('d'),
|
|
769
|
-
(0, oids_js_1.createRef)('e'),
|
|
770
|
-
], {
|
|
771
|
-
op: 'list-remove',
|
|
772
|
-
value: (0, oids_js_1.createRef)('c'),
|
|
773
|
-
}, refs)).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('d'), (0, oids_js_1.createRef)('e')]);
|
|
774
|
-
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('c')]);
|
|
775
|
-
});
|
|
776
|
-
(0, vitest_1.it)('collects a deleted ref field from an object', () => {
|
|
777
|
-
const refs = [];
|
|
778
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)({
|
|
779
|
-
a: (0, oids_js_1.createRef)('a'),
|
|
780
|
-
b: (0, oids_js_1.createRef)('b'),
|
|
781
|
-
c: (0, oids_js_1.createRef)('c'),
|
|
782
|
-
}, {
|
|
783
|
-
op: 'remove',
|
|
784
|
-
name: 'b',
|
|
785
|
-
}, refs)).toEqual({
|
|
786
|
-
a: (0, oids_js_1.createRef)('a'),
|
|
787
|
-
c: (0, oids_js_1.createRef)('c'),
|
|
788
|
-
});
|
|
789
|
-
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
|
|
790
|
-
});
|
|
791
|
-
(0, vitest_1.it)('collects all refs in a deleted object', () => {
|
|
792
|
-
const refs = [];
|
|
793
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)({
|
|
794
|
-
a: (0, oids_js_1.createRef)('a'),
|
|
795
|
-
b: (0, oids_js_1.createRef)('b'),
|
|
796
|
-
c: (0, oids_js_1.createRef)('c'),
|
|
797
|
-
}, {
|
|
798
|
-
op: 'delete',
|
|
799
|
-
}, refs)).toEqual(undefined);
|
|
800
|
-
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
|
|
801
|
-
});
|
|
802
|
-
(0, vitest_1.it)('collects all refs in a deleted list', () => {
|
|
803
|
-
const refs = [];
|
|
804
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')], {
|
|
805
|
-
op: 'delete',
|
|
806
|
-
}, refs)).toEqual(undefined);
|
|
807
|
-
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
|
|
808
|
-
});
|
|
809
|
-
(0, vitest_1.it)('collects a ref in a replaced field', () => {
|
|
810
|
-
const refs = [];
|
|
811
|
-
(0, vitest_1.expect)((0, operation_js_1.applyPatch)({
|
|
812
|
-
a: (0, oids_js_1.createRef)('a'),
|
|
813
|
-
b: (0, oids_js_1.createRef)('b'),
|
|
814
|
-
c: (0, oids_js_1.createRef)('c'),
|
|
815
|
-
}, {
|
|
816
|
-
op: 'set',
|
|
817
|
-
name: 'b',
|
|
818
|
-
value: (0, oids_js_1.createRef)('d'),
|
|
819
|
-
}, refs)).toEqual({
|
|
820
|
-
a: (0, oids_js_1.createRef)('a'),
|
|
821
|
-
b: (0, oids_js_1.createRef)('d'),
|
|
822
|
-
c: (0, oids_js_1.createRef)('c'),
|
|
823
|
-
});
|
|
824
|
-
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
|
|
825
|
-
});
|
|
826
|
-
});
|
|
711
|
+
`);
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
(0, vitest_1.describe)('applying individual operations', () => {
|
|
715
|
+
(0, vitest_1.it)('applies a list-remove of only the last instance', () => {
|
|
716
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
|
|
717
|
+
op: 'list-remove',
|
|
718
|
+
value: 'a',
|
|
719
|
+
only: 'last',
|
|
720
|
+
})).toEqual(['a', 'b', 'c', 'b']);
|
|
721
|
+
});
|
|
722
|
+
(0, vitest_1.it)('applies a list-remove of only the first instance', () => {
|
|
723
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
|
|
724
|
+
op: 'list-remove',
|
|
725
|
+
value: 'a',
|
|
726
|
+
only: 'first',
|
|
727
|
+
})).toEqual(['b', 'c', 'a', 'b']);
|
|
728
|
+
});
|
|
729
|
+
(0, vitest_1.it)('applies a list-remove of all instances', () => {
|
|
730
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
|
|
731
|
+
op: 'list-remove',
|
|
732
|
+
value: 'a',
|
|
733
|
+
})).toEqual(['b', 'c', 'b']);
|
|
734
|
+
});
|
|
735
|
+
(0, vitest_1.it)('applies a list-remove of an object ref', () => {
|
|
736
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)([
|
|
737
|
+
(0, oids_js_1.createRef)('a'),
|
|
738
|
+
(0, oids_js_1.createRef)('b'),
|
|
739
|
+
(0, oids_js_1.createRef)('c'),
|
|
740
|
+
(0, oids_js_1.createRef)('a'),
|
|
741
|
+
(0, oids_js_1.createRef)('b'),
|
|
742
|
+
], {
|
|
743
|
+
op: 'list-remove',
|
|
744
|
+
value: (0, oids_js_1.createRef)('a'),
|
|
745
|
+
only: 'last',
|
|
746
|
+
})).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c'), (0, oids_js_1.createRef)('b')]);
|
|
747
|
+
});
|
|
748
|
+
(0, vitest_1.it)('applies a list-add of a nonexistent item', () => {
|
|
749
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
|
|
750
|
+
op: 'list-add',
|
|
751
|
+
value: 'd',
|
|
752
|
+
})).toEqual(['a', 'b', 'c', 'd']);
|
|
753
|
+
});
|
|
754
|
+
(0, vitest_1.it)('does not apply a list-add if the item is already present', () => {
|
|
755
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
|
|
756
|
+
op: 'list-add',
|
|
757
|
+
value: 'b',
|
|
758
|
+
})).toEqual(['a', 'b', 'c']);
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
(0, vitest_1.describe)('collecting deleted refs during patch application', () => {
|
|
762
|
+
(0, vitest_1.it)('collects refs that are removed from a list', () => {
|
|
763
|
+
const refs = [];
|
|
764
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)([
|
|
765
|
+
(0, oids_js_1.createRef)('a'),
|
|
766
|
+
(0, oids_js_1.createRef)('b'),
|
|
767
|
+
(0, oids_js_1.createRef)('c'),
|
|
768
|
+
(0, oids_js_1.createRef)('d'),
|
|
769
|
+
(0, oids_js_1.createRef)('e'),
|
|
770
|
+
], {
|
|
771
|
+
op: 'list-remove',
|
|
772
|
+
value: (0, oids_js_1.createRef)('c'),
|
|
773
|
+
}, refs)).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('d'), (0, oids_js_1.createRef)('e')]);
|
|
774
|
+
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('c')]);
|
|
775
|
+
});
|
|
776
|
+
(0, vitest_1.it)('collects a deleted ref field from an object', () => {
|
|
777
|
+
const refs = [];
|
|
778
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)({
|
|
779
|
+
a: (0, oids_js_1.createRef)('a'),
|
|
780
|
+
b: (0, oids_js_1.createRef)('b'),
|
|
781
|
+
c: (0, oids_js_1.createRef)('c'),
|
|
782
|
+
}, {
|
|
783
|
+
op: 'remove',
|
|
784
|
+
name: 'b',
|
|
785
|
+
}, refs)).toEqual({
|
|
786
|
+
a: (0, oids_js_1.createRef)('a'),
|
|
787
|
+
c: (0, oids_js_1.createRef)('c'),
|
|
788
|
+
});
|
|
789
|
+
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
|
|
790
|
+
});
|
|
791
|
+
(0, vitest_1.it)('collects all refs in a deleted object', () => {
|
|
792
|
+
const refs = [];
|
|
793
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)({
|
|
794
|
+
a: (0, oids_js_1.createRef)('a'),
|
|
795
|
+
b: (0, oids_js_1.createRef)('b'),
|
|
796
|
+
c: (0, oids_js_1.createRef)('c'),
|
|
797
|
+
}, {
|
|
798
|
+
op: 'delete',
|
|
799
|
+
}, refs)).toEqual(undefined);
|
|
800
|
+
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
|
|
801
|
+
});
|
|
802
|
+
(0, vitest_1.it)('collects all refs in a deleted list', () => {
|
|
803
|
+
const refs = [];
|
|
804
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')], {
|
|
805
|
+
op: 'delete',
|
|
806
|
+
}, refs)).toEqual(undefined);
|
|
807
|
+
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
|
|
808
|
+
});
|
|
809
|
+
(0, vitest_1.it)('collects a ref in a replaced field', () => {
|
|
810
|
+
const refs = [];
|
|
811
|
+
(0, vitest_1.expect)((0, operation_js_1.applyPatch)({
|
|
812
|
+
a: (0, oids_js_1.createRef)('a'),
|
|
813
|
+
b: (0, oids_js_1.createRef)('b'),
|
|
814
|
+
c: (0, oids_js_1.createRef)('c'),
|
|
815
|
+
}, {
|
|
816
|
+
op: 'set',
|
|
817
|
+
name: 'b',
|
|
818
|
+
value: (0, oids_js_1.createRef)('d'),
|
|
819
|
+
}, refs)).toEqual({
|
|
820
|
+
a: (0, oids_js_1.createRef)('a'),
|
|
821
|
+
b: (0, oids_js_1.createRef)('d'),
|
|
822
|
+
c: (0, oids_js_1.createRef)('c'),
|
|
823
|
+
});
|
|
824
|
+
(0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
827
|
//# sourceMappingURL=operation.test.js.map
|