@verdant-web/common 1.11.0 → 1.12.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.
Files changed (159) hide show
  1. package/dist/cjs/EventSubscriber.d.ts +17 -17
  2. package/dist/cjs/EventSubscriber.js +66 -66
  3. package/dist/cjs/baseline.d.ts +5 -5
  4. package/dist/cjs/baseline.js +2 -2
  5. package/dist/cjs/batching.d.ts +41 -41
  6. package/dist/cjs/batching.js +88 -88
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/index.d.ts +18 -18
  10. package/dist/cjs/index.js +35 -35
  11. package/dist/cjs/indexes.d.ts +14 -14
  12. package/dist/cjs/indexes.js +115 -115
  13. package/dist/cjs/indexes.test.d.ts +1 -1
  14. package/dist/cjs/indexes.test.js +127 -127
  15. package/dist/cjs/migration.d.ts +98 -98
  16. package/dist/cjs/migration.js +127 -127
  17. package/dist/cjs/oids.d.ts +85 -87
  18. package/dist/cjs/oids.js +363 -374
  19. package/dist/cjs/oids.js.map +1 -1
  20. package/dist/cjs/oids.test.d.ts +1 -1
  21. package/dist/cjs/oids.test.js +269 -251
  22. package/dist/cjs/oids.test.js.map +1 -1
  23. package/dist/cjs/operation.d.ts +139 -139
  24. package/dist/cjs/operation.js +532 -532
  25. package/dist/cjs/operation.js.map +1 -1
  26. package/dist/cjs/operation.test.d.ts +1 -1
  27. package/dist/cjs/operation.test.js +505 -505
  28. package/dist/cjs/operation.test.js.map +1 -1
  29. package/dist/cjs/patch.d.ts +26 -26
  30. package/dist/cjs/patch.js +226 -226
  31. package/dist/cjs/patch.js.map +1 -1
  32. package/dist/cjs/presence.d.ts +27 -27
  33. package/dist/cjs/presence.js +2 -2
  34. package/dist/cjs/protocol.d.ts +145 -145
  35. package/dist/cjs/protocol.js +3 -3
  36. package/dist/cjs/refs.d.ts +5 -5
  37. package/dist/cjs/refs.js +21 -21
  38. package/dist/cjs/replica.d.ts +28 -28
  39. package/dist/cjs/replica.js +28 -28
  40. package/dist/cjs/schema/defaults.d.ts +4 -4
  41. package/dist/cjs/schema/defaults.js +71 -71
  42. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  43. package/dist/cjs/schema/defaults.test.js +20 -20
  44. package/dist/cjs/schema/defaults.test.js.map +1 -1
  45. package/dist/cjs/schema/index.d.ts +8 -8
  46. package/dist/cjs/schema/index.js +28 -28
  47. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  48. package/dist/cjs/schema/indexFilters.js +30 -30
  49. package/dist/cjs/schema/types/collection.d.ts +51 -51
  50. package/dist/cjs/schema/types/collection.js +2 -2
  51. package/dist/cjs/schema/types/compounds.d.ts +12 -12
  52. package/dist/cjs/schema/types/compounds.js +2 -2
  53. package/dist/cjs/schema/types/fields.d.ts +59 -59
  54. package/dist/cjs/schema/types/fields.js +2 -2
  55. package/dist/cjs/schema/types/filters.d.ts +29 -29
  56. package/dist/cjs/schema/types/filters.js +2 -2
  57. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  58. package/dist/cjs/schema/types/shapes.js +2 -2
  59. package/dist/cjs/schema/types/synthetics.d.ts +28 -28
  60. package/dist/cjs/schema/types/synthetics.js +2 -2
  61. package/dist/cjs/schema/types.d.ts +18 -18
  62. package/dist/cjs/schema/types.js +22 -22
  63. package/dist/cjs/timestamp.d.ts +48 -48
  64. package/dist/cjs/timestamp.js +243 -243
  65. package/dist/cjs/timestamp.test.d.ts +1 -1
  66. package/dist/cjs/timestamp.test.js +93 -93
  67. package/dist/cjs/undo.d.ts +3 -3
  68. package/dist/cjs/undo.js +198 -198
  69. package/dist/cjs/utils.d.ts +15 -15
  70. package/dist/cjs/utils.js +127 -127
  71. package/dist/cjs/utils.test.d.ts +1 -1
  72. package/dist/cjs/utils.test.js +36 -36
  73. package/dist/esm/EventSubscriber.d.ts +17 -17
  74. package/dist/esm/EventSubscriber.js +62 -62
  75. package/dist/esm/baseline.d.ts +5 -5
  76. package/dist/esm/baseline.js +1 -1
  77. package/dist/esm/batching.d.ts +41 -41
  78. package/dist/esm/batching.js +83 -83
  79. package/dist/esm/files.d.ts +19 -19
  80. package/dist/esm/files.js +12 -12
  81. package/dist/esm/index.d.ts +18 -18
  82. package/dist/esm/index.js +15 -15
  83. package/dist/esm/indexes.d.ts +14 -14
  84. package/dist/esm/indexes.js +105 -105
  85. package/dist/esm/indexes.test.d.ts +1 -1
  86. package/dist/esm/indexes.test.js +125 -125
  87. package/dist/esm/migration.d.ts +98 -98
  88. package/dist/esm/migration.js +121 -121
  89. package/dist/esm/oids.d.ts +85 -87
  90. package/dist/esm/oids.js +336 -347
  91. package/dist/esm/oids.js.map +1 -1
  92. package/dist/esm/oids.test.d.ts +1 -1
  93. package/dist/esm/oids.test.js +267 -249
  94. package/dist/esm/oids.test.js.map +1 -1
  95. package/dist/esm/operation.d.ts +139 -139
  96. package/dist/esm/operation.js +517 -517
  97. package/dist/esm/operation.js.map +1 -1
  98. package/dist/esm/operation.test.d.ts +1 -1
  99. package/dist/esm/operation.test.js +503 -503
  100. package/dist/esm/operation.test.js.map +1 -1
  101. package/dist/esm/patch.d.ts +26 -26
  102. package/dist/esm/patch.js +222 -222
  103. package/dist/esm/patch.js.map +1 -1
  104. package/dist/esm/presence.d.ts +27 -27
  105. package/dist/esm/presence.js +1 -1
  106. package/dist/esm/protocol.d.ts +145 -145
  107. package/dist/esm/protocol.js +2 -2
  108. package/dist/esm/refs.d.ts +5 -5
  109. package/dist/esm/refs.js +16 -16
  110. package/dist/esm/replica.d.ts +28 -28
  111. package/dist/esm/replica.js +25 -25
  112. package/dist/esm/schema/defaults.d.ts +4 -4
  113. package/dist/esm/schema/defaults.js +65 -65
  114. package/dist/esm/schema/defaults.test.d.ts +1 -1
  115. package/dist/esm/schema/defaults.test.js +18 -18
  116. package/dist/esm/schema/defaults.test.js.map +1 -1
  117. package/dist/esm/schema/index.d.ts +8 -8
  118. package/dist/esm/schema/index.js +9 -9
  119. package/dist/esm/schema/indexFilters.d.ts +6 -6
  120. package/dist/esm/schema/indexFilters.js +22 -22
  121. package/dist/esm/schema/types/collection.d.ts +51 -51
  122. package/dist/esm/schema/types/collection.js +1 -1
  123. package/dist/esm/schema/types/compounds.d.ts +12 -12
  124. package/dist/esm/schema/types/compounds.js +1 -1
  125. package/dist/esm/schema/types/fields.d.ts +59 -59
  126. package/dist/esm/schema/types/fields.js +1 -1
  127. package/dist/esm/schema/types/filters.d.ts +29 -29
  128. package/dist/esm/schema/types/filters.js +1 -1
  129. package/dist/esm/schema/types/shapes.d.ts +21 -21
  130. package/dist/esm/schema/types/shapes.js +1 -1
  131. package/dist/esm/schema/types/synthetics.d.ts +28 -28
  132. package/dist/esm/schema/types/synthetics.js +1 -1
  133. package/dist/esm/schema/types.d.ts +18 -18
  134. package/dist/esm/schema/types.js +6 -6
  135. package/dist/esm/timestamp.d.ts +48 -48
  136. package/dist/esm/timestamp.js +228 -228
  137. package/dist/esm/timestamp.test.d.ts +1 -1
  138. package/dist/esm/timestamp.test.js +91 -91
  139. package/dist/esm/undo.d.ts +3 -3
  140. package/dist/esm/undo.js +194 -194
  141. package/dist/esm/utils.d.ts +15 -15
  142. package/dist/esm/utils.js +113 -113
  143. package/dist/esm/utils.test.d.ts +1 -1
  144. package/dist/esm/utils.test.js +34 -34
  145. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  146. package/dist/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +1 -1
  148. package/src/oids.test.ts +62 -51
  149. package/src/oids.ts +7 -26
  150. package/src/operation.test.ts +32 -40
  151. package/src/operation.ts +4 -16
  152. package/src/patch.ts +5 -15
  153. package/src/schema/defaults.test.ts +1 -1
  154. package/dist/cjs/files.test.d.ts +0 -1
  155. package/dist/cjs/files.test.js +0 -81
  156. package/dist/cjs/files.test.js.map +0 -1
  157. package/dist/esm/files.test.d.ts +0 -1
  158. package/dist/esm/files.test.js +0 -79
  159. 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,75 +205,75 @@ 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');
276
- (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), [])).toMatchInlineSnapshot(`
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
+ (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock())).toMatchInlineSnapshot(`
277
277
  [
278
278
  {
279
279
  "data": {
@@ -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
  {
@@ -377,7 +377,7 @@ function createClock(init = 0) {
377
377
  "index": 2,
378
378
  "op": "list-delete",
379
379
  },
380
- "oid": "test/a.foo.bar:1",
380
+ "oid": "test/a:1",
381
381
  "timestamp": "0",
382
382
  },
383
383
  {
@@ -387,7 +387,7 @@ function createClock(init = 0) {
387
387
  0,
388
388
  ],
389
389
  },
390
- "oid": "test/a.foo.bop:5",
390
+ "oid": "test/a:5",
391
391
  "timestamp": "1",
392
392
  },
393
393
  {
@@ -396,10 +396,10 @@ function createClock(init = 0) {
396
396
  "op": "set",
397
397
  "value": {
398
398
  "@@type": "ref",
399
- "id": "test/a.foo.bop:5",
399
+ "id": "test/a:5",
400
400
  },
401
401
  },
402
- "oid": "test/a.foo:0",
402
+ "oid": "test/a:0",
403
403
  "timestamp": "2",
404
404
  },
405
405
  {
@@ -408,7 +408,7 @@ function createClock(init = 0) {
408
408
  "op": "set",
409
409
  "value": false,
410
410
  },
411
- "oid": "test/a.baz.#:3",
411
+ "oid": "test/a:3",
412
412
  "timestamp": "3",
413
413
  },
414
414
  {
@@ -418,7 +418,7 @@ function createClock(init = 0) {
418
418
  "corge": false,
419
419
  },
420
420
  },
421
- "oid": "test/a.baz.#:6",
421
+ "oid": "test/a:6",
422
422
  "timestamp": "4",
423
423
  },
424
424
  {
@@ -427,32 +427,32 @@ function createClock(init = 0) {
427
427
  "op": "set",
428
428
  "value": {
429
429
  "@@type": "ref",
430
- "id": "test/a.baz.#:6",
430
+ "id": "test/a:6",
431
431
  },
432
432
  },
433
- "oid": "test/a.baz:2",
433
+ "oid": "test/a:2",
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
  {
@@ -464,7 +464,7 @@ function createClock(init = 0) {
464
464
  "id": "abc456",
465
465
  },
466
466
  },
467
- "oid": "test/a.foo:0",
467
+ "oid": "test/a:0",
468
468
  "timestamp": "0",
469
469
  },
470
470
  {
@@ -473,161 +473,161 @@ function createClock(init = 0) {
473
473
  "index": 1,
474
474
  "op": "list-delete",
475
475
  },
476
- "oid": "test/a.bar:1",
476
+ "oid": "test/a:1",
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
  {
@@ -637,7 +637,7 @@ function createClock(init = 0) {
637
637
  "bar": "baz",
638
638
  },
639
639
  },
640
- "oid": "test/a.foo:0",
640
+ "oid": "test/a:0",
641
641
  "timestamp": "0",
642
642
  },
643
643
  {
@@ -647,7 +647,7 @@ function createClock(init = 0) {
647
647
  "corge": "grault",
648
648
  },
649
649
  },
650
- "oid": "test/a.qux.#:2",
650
+ "oid": "test/a:2",
651
651
  "timestamp": "1",
652
652
  },
653
653
  {
@@ -657,7 +657,7 @@ function createClock(init = 0) {
657
657
  "oof": 1,
658
658
  },
659
659
  },
660
- "oid": "test/a.qux.#.bin:4",
660
+ "oid": "test/a:4",
661
661
  "timestamp": "2",
662
662
  },
663
663
  {
@@ -666,11 +666,11 @@ function createClock(init = 0) {
666
666
  "value": {
667
667
  "bin": {
668
668
  "@@type": "ref",
669
- "id": "test/a.qux.#.bin:4",
669
+ "id": "test/a:4",
670
670
  },
671
671
  },
672
672
  },
673
- "oid": "test/a.qux.#:3",
673
+ "oid": "test/a:3",
674
674
  "timestamp": "3",
675
675
  },
676
676
  {
@@ -679,15 +679,15 @@ function createClock(init = 0) {
679
679
  "value": [
680
680
  {
681
681
  "@@type": "ref",
682
- "id": "test/a.qux.#:2",
682
+ "id": "test/a:2",
683
683
  },
684
684
  {
685
685
  "@@type": "ref",
686
- "id": "test/a.qux.#:3",
686
+ "id": "test/a:3",
687
687
  },
688
688
  ],
689
689
  },
690
- "oid": "test/a.qux:1",
690
+ "oid": "test/a:1",
691
691
  "timestamp": "4",
692
692
  },
693
693
  {
@@ -696,11 +696,11 @@ function createClock(init = 0) {
696
696
  "value": {
697
697
  "foo": {
698
698
  "@@type": "ref",
699
- "id": "test/a.foo:0",
699
+ "id": "test/a:0",
700
700
  },
701
701
  "qux": {
702
702
  "@@type": "ref",
703
- "id": "test/a.qux:1",
703
+ "id": "test/a:1",
704
704
  },
705
705
  },
706
706
  },
@@ -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