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