@verdant-web/common 1.15.2 → 1.15.3-next.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 (163) 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 +42 -42
  6. package/dist/cjs/batching.js +91 -91
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/files.test.d.ts +1 -0
  10. package/dist/cjs/files.test.js +81 -0
  11. package/dist/cjs/files.test.js.map +1 -0
  12. package/dist/cjs/index.d.ts +19 -18
  13. package/dist/cjs/index.js +41 -36
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/indexes.d.ts +17 -17
  16. package/dist/cjs/indexes.js +142 -142
  17. package/dist/cjs/indexes.test.d.ts +1 -1
  18. package/dist/cjs/indexes.test.js +127 -127
  19. package/dist/cjs/migration.d.ts +172 -172
  20. package/dist/cjs/migration.js +301 -301
  21. package/dist/cjs/oids.d.ts +100 -96
  22. package/dist/cjs/oids.js +457 -439
  23. package/dist/cjs/oids.js.map +1 -1
  24. package/dist/cjs/oids.test.d.ts +1 -1
  25. package/dist/cjs/oids.test.js +348 -272
  26. package/dist/cjs/oids.test.js.map +1 -1
  27. package/dist/cjs/operation.d.ts +139 -139
  28. package/dist/cjs/operation.js +545 -545
  29. package/dist/cjs/operation.test.d.ts +1 -1
  30. package/dist/cjs/operation.test.js +529 -529
  31. package/dist/cjs/patch.d.ts +26 -26
  32. package/dist/cjs/patch.js +226 -226
  33. package/dist/cjs/presence.d.ts +27 -27
  34. package/dist/cjs/presence.js +2 -2
  35. package/dist/cjs/protocol.d.ts +145 -145
  36. package/dist/cjs/protocol.js +3 -3
  37. package/dist/cjs/refs.d.ts +7 -5
  38. package/dist/cjs/refs.js +29 -21
  39. package/dist/cjs/refs.js.map +1 -1
  40. package/dist/cjs/replica.d.ts +28 -28
  41. package/dist/cjs/replica.js +28 -28
  42. package/dist/cjs/schema/defaults.d.ts +4 -0
  43. package/dist/cjs/schema/defaults.js +72 -0
  44. package/dist/cjs/schema/defaults.js.map +1 -0
  45. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  46. package/dist/cjs/schema/defaults.test.js +20 -20
  47. package/dist/cjs/schema/fields.d.ts +9 -9
  48. package/dist/cjs/schema/fields.js +144 -144
  49. package/dist/cjs/schema/index.d.ts +8 -8
  50. package/dist/cjs/schema/index.js +51 -51
  51. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  52. package/dist/cjs/schema/indexFilters.js +30 -30
  53. package/dist/cjs/schema/types/collection.d.ts +23 -23
  54. package/dist/cjs/schema/types/collection.js +2 -2
  55. package/dist/cjs/schema/types/compounds.d.ts +11 -11
  56. package/dist/cjs/schema/types/compounds.js +2 -2
  57. package/dist/cjs/schema/types/fields.d.ts +75 -75
  58. package/dist/cjs/schema/types/fields.js +2 -2
  59. package/dist/cjs/schema/types/filters.d.ts +29 -29
  60. package/dist/cjs/schema/types/filters.js +2 -2
  61. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  62. package/dist/cjs/schema/types/shapes.js +2 -2
  63. package/dist/cjs/schema/types/synthetics.d.ts +37 -37
  64. package/dist/cjs/schema/types/synthetics.js +2 -2
  65. package/dist/cjs/schema/types.d.ts +18 -18
  66. package/dist/cjs/schema/types.js +22 -22
  67. package/dist/cjs/schema/validation.d.ts +3 -3
  68. package/dist/cjs/schema/validation.js +86 -86
  69. package/dist/cjs/timestamp.d.ts +50 -50
  70. package/dist/cjs/timestamp.js +251 -251
  71. package/dist/cjs/timestamp.test.d.ts +1 -1
  72. package/dist/cjs/timestamp.test.js +104 -104
  73. package/dist/cjs/undo.d.ts +3 -3
  74. package/dist/cjs/undo.js +198 -198
  75. package/dist/cjs/utils.d.ts +20 -20
  76. package/dist/cjs/utils.js +145 -145
  77. package/dist/cjs/utils.test.d.ts +1 -1
  78. package/dist/cjs/utils.test.js +36 -36
  79. package/dist/esm/EventSubscriber.d.ts +17 -17
  80. package/dist/esm/EventSubscriber.js +62 -62
  81. package/dist/esm/baseline.d.ts +5 -5
  82. package/dist/esm/baseline.js +1 -1
  83. package/dist/esm/batching.d.ts +42 -42
  84. package/dist/esm/batching.js +86 -86
  85. package/dist/esm/files.d.ts +19 -19
  86. package/dist/esm/files.js +12 -12
  87. package/dist/esm/files.test.d.ts +1 -0
  88. package/dist/esm/files.test.js +79 -0
  89. package/dist/esm/files.test.js.map +1 -0
  90. package/dist/esm/index.d.ts +19 -18
  91. package/dist/esm/index.js +16 -15
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/indexes.d.ts +17 -17
  94. package/dist/esm/indexes.js +130 -130
  95. package/dist/esm/indexes.test.d.ts +1 -1
  96. package/dist/esm/indexes.test.js +125 -125
  97. package/dist/esm/migration.d.ts +172 -172
  98. package/dist/esm/migration.js +294 -294
  99. package/dist/esm/oids.d.ts +100 -96
  100. package/dist/esm/oids.js +422 -407
  101. package/dist/esm/oids.js.map +1 -1
  102. package/dist/esm/oids.test.d.ts +1 -1
  103. package/dist/esm/oids.test.js +346 -270
  104. package/dist/esm/oids.test.js.map +1 -1
  105. package/dist/esm/operation.d.ts +139 -139
  106. package/dist/esm/operation.js +530 -530
  107. package/dist/esm/operation.test.d.ts +1 -1
  108. package/dist/esm/operation.test.js +527 -527
  109. package/dist/esm/patch.d.ts +26 -26
  110. package/dist/esm/patch.js +222 -222
  111. package/dist/esm/presence.d.ts +27 -27
  112. package/dist/esm/presence.js +1 -1
  113. package/dist/esm/protocol.d.ts +145 -145
  114. package/dist/esm/protocol.js +2 -2
  115. package/dist/esm/refs.d.ts +7 -5
  116. package/dist/esm/refs.js +22 -16
  117. package/dist/esm/refs.js.map +1 -1
  118. package/dist/esm/replica.d.ts +28 -28
  119. package/dist/esm/replica.js +25 -25
  120. package/dist/esm/schema/defaults.d.ts +4 -0
  121. package/dist/esm/schema/defaults.js +66 -0
  122. package/dist/esm/schema/defaults.js.map +1 -0
  123. package/dist/esm/schema/defaults.test.d.ts +1 -1
  124. package/dist/esm/schema/defaults.test.js +18 -18
  125. package/dist/esm/schema/fields.d.ts +9 -9
  126. package/dist/esm/schema/fields.js +133 -133
  127. package/dist/esm/schema/index.d.ts +8 -8
  128. package/dist/esm/schema/index.js +32 -32
  129. package/dist/esm/schema/indexFilters.d.ts +6 -6
  130. package/dist/esm/schema/indexFilters.js +22 -22
  131. package/dist/esm/schema/types/collection.d.ts +23 -23
  132. package/dist/esm/schema/types/collection.js +1 -1
  133. package/dist/esm/schema/types/compounds.d.ts +11 -11
  134. package/dist/esm/schema/types/compounds.js +1 -1
  135. package/dist/esm/schema/types/fields.d.ts +75 -75
  136. package/dist/esm/schema/types/fields.js +1 -1
  137. package/dist/esm/schema/types/filters.d.ts +29 -29
  138. package/dist/esm/schema/types/filters.js +1 -1
  139. package/dist/esm/schema/types/shapes.d.ts +21 -21
  140. package/dist/esm/schema/types/shapes.js +1 -1
  141. package/dist/esm/schema/types/synthetics.d.ts +37 -37
  142. package/dist/esm/schema/types/synthetics.js +1 -1
  143. package/dist/esm/schema/types.d.ts +18 -18
  144. package/dist/esm/schema/types.js +6 -6
  145. package/dist/esm/schema/validation.d.ts +3 -3
  146. package/dist/esm/schema/validation.js +81 -81
  147. package/dist/esm/timestamp.d.ts +50 -50
  148. package/dist/esm/timestamp.js +234 -234
  149. package/dist/esm/timestamp.test.d.ts +1 -1
  150. package/dist/esm/timestamp.test.js +102 -102
  151. package/dist/esm/undo.d.ts +3 -3
  152. package/dist/esm/undo.js +194 -194
  153. package/dist/esm/utils.d.ts +20 -20
  154. package/dist/esm/utils.js +127 -127
  155. package/dist/esm/utils.test.d.ts +1 -1
  156. package/dist/esm/utils.test.js +34 -34
  157. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +1 -1
  160. package/src/index.ts +1 -0
  161. package/src/oids.test.ts +82 -0
  162. package/src/oids.ts +17 -0
  163. package/src/refs.ts +8 -0
@@ -1,27 +1,27 @@
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
- const clock = () => (i++).toString();
10
- Object.defineProperty(clock, 'current', {
11
- get() {
12
- return i;
13
- },
14
- });
15
- return clock;
16
- }
17
- (0, vitest_1.describe)('creating diff patch operations', () => {
18
- (0, vitest_1.describe)('on flat objects', () => {
19
- (0, vitest_1.it)('generates and applies set and remove operations', () => {
20
- const from = { foo: 'bar', baz: 'qux', zing: 1 };
21
- (0, oids_js_1.assignOid)(from, 'test/a');
22
- const to = { foo: 'bar', baz: 'pop' };
23
- (0, oids_js_1.assignOid)(to, 'test/a');
24
- 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
+ const clock = () => (i++).toString();
10
+ Object.defineProperty(clock, 'current', {
11
+ get() {
12
+ return i;
13
+ },
14
+ });
15
+ return clock;
16
+ }
17
+ (0, vitest_1.describe)('creating diff patch operations', () => {
18
+ (0, vitest_1.describe)('on flat objects', () => {
19
+ (0, vitest_1.it)('generates and applies set and remove operations', () => {
20
+ const from = { foo: 'bar', baz: 'qux', zing: 1 };
21
+ (0, oids_js_1.assignOid)(from, 'test/a');
22
+ const to = { foo: 'bar', baz: 'pop' };
23
+ (0, oids_js_1.assignOid)(to, 'test/a');
24
+ const ops = (0, operation_js_1.diffToPatches)(from, to, createClock());
25
25
  (0, vitest_1.expect)(ops).toMatchInlineSnapshot(`
26
26
  [
27
27
  {
@@ -42,22 +42,22 @@ function createClock(init = 0) {
42
42
  "timestamp": "1",
43
43
  },
44
44
  ]
45
- `);
46
- const result = (0, operation_js_1.applyOperations)(from, ops);
47
- (0, vitest_1.expect)(result).toEqual(to);
48
- });
49
- });
50
- (0, vitest_1.describe)('on nested objects', () => {
51
- (0, vitest_1.it)('replaces whole nested objects', () => {
52
- const from = (0, oids_js_1.assignOid)({
53
- foo: 'bar',
54
- baz: (0, oids_js_1.assignOid)({ qux: 'corge' }, 'test/a:0'),
55
- }, 'test/a');
56
- const to = (0, oids_js_1.assignOid)({
57
- foo: 'bar',
58
- baz: (0, oids_js_1.assignOid)({ qux: 'grault' }, 'test/a:1'),
59
- }, 'test/a');
60
- const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
45
+ `);
46
+ const result = (0, operation_js_1.applyOperations)(from, ops);
47
+ (0, vitest_1.expect)(result).toEqual(to);
48
+ });
49
+ });
50
+ (0, vitest_1.describe)('on nested objects', () => {
51
+ (0, vitest_1.it)('replaces whole nested objects', () => {
52
+ const from = (0, oids_js_1.assignOid)({
53
+ foo: 'bar',
54
+ baz: (0, oids_js_1.assignOid)({ qux: 'corge' }, 'test/a:0'),
55
+ }, 'test/a');
56
+ const to = (0, oids_js_1.assignOid)({
57
+ foo: 'bar',
58
+ baz: (0, oids_js_1.assignOid)({ qux: 'grault' }, 'test/a:1'),
59
+ }, 'test/a');
60
+ const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
61
61
  (0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
62
62
  [
63
63
  {
@@ -90,22 +90,22 @@ function createClock(init = 0) {
90
90
  "timestamp": "2",
91
91
  },
92
92
  ]
93
- `);
94
- });
95
- (0, vitest_1.it)('replaces whole nested objects with different ids even if fields are the same', () => {
96
- const from = {
97
- foo: 'bar',
98
- baz: { qux: 'corge' },
99
- };
100
- (0, oids_js_1.assignOid)(from, 'test/a');
101
- (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
102
- const to = {
103
- foo: 'bar',
104
- baz: { qux: 'corge' },
105
- };
106
- (0, oids_js_1.assignOid)(to, 'test/a');
107
- (0, oids_js_1.assignOid)(to.baz, 'test/a:1');
108
- const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
93
+ `);
94
+ });
95
+ (0, vitest_1.it)('replaces whole nested objects with different ids even if fields are the same', () => {
96
+ const from = {
97
+ foo: 'bar',
98
+ baz: { qux: 'corge' },
99
+ };
100
+ (0, oids_js_1.assignOid)(from, 'test/a');
101
+ (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
102
+ const to = {
103
+ foo: 'bar',
104
+ baz: { qux: 'corge' },
105
+ };
106
+ (0, oids_js_1.assignOid)(to, 'test/a');
107
+ (0, oids_js_1.assignOid)(to.baz, 'test/a:1');
108
+ const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
109
109
  (0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
110
110
  [
111
111
  {
@@ -138,38 +138,38 @@ function createClock(init = 0) {
138
138
  "timestamp": "2",
139
139
  },
140
140
  ]
141
- `);
142
- });
143
- (0, vitest_1.it)('does not replace objects with the same identity and same fields', () => {
144
- const from = {
145
- foo: 'bar',
146
- baz: { qux: 'corge' },
147
- };
148
- (0, oids_js_1.assignOid)(from, 'test/a');
149
- (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
150
- const to = {
151
- foo: 'bar',
152
- baz: { qux: 'corge' },
153
- };
154
- (0, oids_js_1.assignOid)(to, 'test/a');
155
- (0, oids_js_1.assignOid)(to.baz, 'test/a:0');
156
- const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
157
- (0, vitest_1.expect)(patches).toEqual([]);
158
- });
159
- (0, vitest_1.it)('patches sub-objects with same identity', () => {
160
- const from = {
161
- foo: 'bar',
162
- baz: { qux: 'corge' },
163
- };
164
- (0, oids_js_1.assignOid)(from, 'test/a');
165
- (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
166
- const to = {
167
- foo: 'bar',
168
- baz: { qux: 'fig' },
169
- };
170
- (0, oids_js_1.assignOid)(to, 'test/a');
171
- (0, oids_js_1.assignOid)(to.baz, 'test/a:0');
172
- const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
141
+ `);
142
+ });
143
+ (0, vitest_1.it)('does not replace objects with the same identity and same fields', () => {
144
+ const from = {
145
+ foo: 'bar',
146
+ baz: { qux: 'corge' },
147
+ };
148
+ (0, oids_js_1.assignOid)(from, 'test/a');
149
+ (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
150
+ const to = {
151
+ foo: 'bar',
152
+ baz: { qux: 'corge' },
153
+ };
154
+ (0, oids_js_1.assignOid)(to, 'test/a');
155
+ (0, oids_js_1.assignOid)(to.baz, 'test/a:0');
156
+ const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
157
+ (0, vitest_1.expect)(patches).toEqual([]);
158
+ });
159
+ (0, vitest_1.it)('patches sub-objects with same identity', () => {
160
+ const from = {
161
+ foo: 'bar',
162
+ baz: { qux: 'corge' },
163
+ };
164
+ (0, oids_js_1.assignOid)(from, 'test/a');
165
+ (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
166
+ const to = {
167
+ foo: 'bar',
168
+ baz: { qux: 'fig' },
169
+ };
170
+ (0, oids_js_1.assignOid)(to, 'test/a');
171
+ (0, oids_js_1.assignOid)(to.baz, 'test/a:0');
172
+ const patches = (0, operation_js_1.diffToPatches)(from, to, createClock());
173
173
  (0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
174
174
  [
175
175
  {
@@ -182,23 +182,23 @@ function createClock(init = 0) {
182
182
  "timestamp": "0",
183
183
  },
184
184
  ]
185
- `);
186
- });
187
- (0, vitest_1.it)('retains keys which are undefined in new object if defaultUndefined is set', () => {
188
- const from = {
189
- foo: 'bar',
190
- baz: { qux: 'corge' },
191
- };
192
- (0, oids_js_1.assignOid)(from, 'test/a');
193
- (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
194
- const to = {
195
- foo: 'bip',
196
- };
197
- (0, oids_js_1.assignOid)(to, 'test/a');
198
- const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), undefined, [], {
199
- defaultUndefined: true,
200
- mergeUnknownObjects: true,
201
- });
185
+ `);
186
+ });
187
+ (0, vitest_1.it)('retains keys which are undefined in new object if defaultUndefined is set', () => {
188
+ const from = {
189
+ foo: 'bar',
190
+ baz: { qux: 'corge' },
191
+ };
192
+ (0, oids_js_1.assignOid)(from, 'test/a');
193
+ (0, oids_js_1.assignOid)(from.baz, 'test/a:0');
194
+ const to = {
195
+ foo: 'bip',
196
+ };
197
+ (0, oids_js_1.assignOid)(to, 'test/a');
198
+ const patches = (0, operation_js_1.diffToPatches)(from, to, createClock(), undefined, [], {
199
+ defaultUndefined: true,
200
+ mergeUnknownObjects: true,
201
+ });
202
202
  (0, vitest_1.expect)(patches).toMatchInlineSnapshot(`
203
203
  [
204
204
  {
@@ -211,74 +211,74 @@ function createClock(init = 0) {
211
211
  "timestamp": "0",
212
212
  },
213
213
  ]
214
- `);
215
- });
216
- });
217
- (0, vitest_1.describe)('on lists of primitives', () => {
218
- (0, vitest_1.it)('pushes items', async () => {
219
- (0, vitest_1.expect)((0, operation_js_1.applyOperations)((0, oids_js_1.assignOid)(['foo', 'bar'], 'test/a'), [
220
- {
221
- oid: 'test/a',
222
- timestamp: 'meh',
223
- data: {
224
- op: 'list-push',
225
- value: 'baz',
226
- },
227
- },
228
- ])).toEqual((0, oids_js_1.assignOid)(['foo', 'bar', 'baz'], 'test/a'));
229
- });
230
- vitest_1.it.todo('sets items');
231
- vitest_1.it.todo('inserts items');
232
- vitest_1.it.todo('removes items by index');
233
- vitest_1.it.todo('removes items by value');
234
- vitest_1.it.todo('moves items by index');
235
- vitest_1.it.todo('moves items by value');
236
- });
237
- vitest_1.describe.todo('on lists of objects', () => {
238
- vitest_1.it.todo('pushes items');
239
- vitest_1.it.todo('moves objects by identity');
240
- vitest_1.it.todo('removes objects by identity');
241
- });
242
- vitest_1.describe.todo('on lists of lists', () => {
243
- vitest_1.it.todo('rejects operations by value or identity');
244
- });
245
- (0, vitest_1.it)('should work for complex nested arrays and objects', () => {
246
- const from = {
247
- foo: {
248
- bar: [1, 2, 3],
249
- },
250
- baz: [
251
- {
252
- corge: true,
253
- },
254
- ],
255
- };
256
- (0, oids_js_1.assignOid)(from, 'test/a');
257
- (0, oids_js_1.assignOid)(from.foo, 'test/a:1');
258
- (0, oids_js_1.assignOid)(from.foo.bar, 'test/a:2');
259
- (0, oids_js_1.assignOid)(from.baz, 'test/a:3');
260
- (0, oids_js_1.assignOid)(from.baz[0], 'test/a:4');
261
- const to = {
262
- foo: {
263
- bar: [1, 2],
264
- bop: [0],
265
- },
266
- baz: [
267
- {
268
- corge: false,
269
- },
270
- {
271
- corge: false,
272
- },
273
- ],
274
- };
275
- (0, oids_js_1.assignOid)(to, 'test/a');
276
- (0, oids_js_1.assignOid)(to.foo, 'test/a:1');
277
- (0, oids_js_1.assignOid)(to.foo.bar, 'test/a:2');
278
- (0, oids_js_1.assignOid)(to.foo.bop, 'test/a:6');
279
- (0, oids_js_1.assignOid)(to.baz, 'test/a:3');
280
- (0, oids_js_1.assignOid)(to.baz[0], 'test/a:4');
281
- (0, oids_js_1.assignOid)(to.baz[1], 'test/a:5');
214
+ `);
215
+ });
216
+ });
217
+ (0, vitest_1.describe)('on lists of primitives', () => {
218
+ (0, vitest_1.it)('pushes items', async () => {
219
+ (0, vitest_1.expect)((0, operation_js_1.applyOperations)((0, oids_js_1.assignOid)(['foo', 'bar'], 'test/a'), [
220
+ {
221
+ oid: 'test/a',
222
+ timestamp: 'meh',
223
+ data: {
224
+ op: 'list-push',
225
+ value: 'baz',
226
+ },
227
+ },
228
+ ])).toEqual((0, oids_js_1.assignOid)(['foo', 'bar', 'baz'], 'test/a'));
229
+ });
230
+ vitest_1.it.todo('sets items');
231
+ vitest_1.it.todo('inserts items');
232
+ vitest_1.it.todo('removes items by index');
233
+ vitest_1.it.todo('removes items by value');
234
+ vitest_1.it.todo('moves items by index');
235
+ vitest_1.it.todo('moves items by value');
236
+ });
237
+ vitest_1.describe.todo('on lists of objects', () => {
238
+ vitest_1.it.todo('pushes items');
239
+ vitest_1.it.todo('moves objects by identity');
240
+ vitest_1.it.todo('removes objects by identity');
241
+ });
242
+ vitest_1.describe.todo('on lists of lists', () => {
243
+ vitest_1.it.todo('rejects operations by value or identity');
244
+ });
245
+ (0, vitest_1.it)('should work for complex nested arrays and objects', () => {
246
+ const from = {
247
+ foo: {
248
+ bar: [1, 2, 3],
249
+ },
250
+ baz: [
251
+ {
252
+ corge: true,
253
+ },
254
+ ],
255
+ };
256
+ (0, oids_js_1.assignOid)(from, 'test/a');
257
+ (0, oids_js_1.assignOid)(from.foo, 'test/a:1');
258
+ (0, oids_js_1.assignOid)(from.foo.bar, 'test/a:2');
259
+ (0, oids_js_1.assignOid)(from.baz, 'test/a:3');
260
+ (0, oids_js_1.assignOid)(from.baz[0], 'test/a:4');
261
+ const to = {
262
+ foo: {
263
+ bar: [1, 2],
264
+ bop: [0],
265
+ },
266
+ baz: [
267
+ {
268
+ corge: false,
269
+ },
270
+ {
271
+ corge: false,
272
+ },
273
+ ],
274
+ };
275
+ (0, oids_js_1.assignOid)(to, 'test/a');
276
+ (0, oids_js_1.assignOid)(to.foo, 'test/a:1');
277
+ (0, oids_js_1.assignOid)(to.foo.bar, 'test/a:2');
278
+ (0, oids_js_1.assignOid)(to.foo.bop, 'test/a:6');
279
+ (0, oids_js_1.assignOid)(to.baz, 'test/a:3');
280
+ (0, oids_js_1.assignOid)(to.baz[0], 'test/a:4');
281
+ (0, oids_js_1.assignOid)(to.baz[1], 'test/a:5');
282
282
  (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock())).toMatchInlineSnapshot(`
283
283
  [
284
284
  {
@@ -344,37 +344,37 @@ function createClock(init = 0) {
344
344
  "timestamp": "5",
345
345
  },
346
346
  ]
347
- `);
348
- });
349
- (0, vitest_1.it)('should try to merge unknown objects if specified to do so', () => {
350
- const from = {
351
- foo: {
352
- bar: [1, 2, 3],
353
- },
354
- baz: [
355
- {
356
- corge: true,
357
- },
358
- ],
359
- };
360
- (0, oids_js_1.assignOid)(from, 'test/a');
361
- (0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
362
- const to = {
363
- foo: {
364
- bar: [1, 2],
365
- bop: [0],
366
- },
367
- baz: [
368
- {
369
- corge: false,
370
- },
371
- {
372
- corge: false,
373
- },
374
- ],
375
- };
376
- (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
377
- mergeUnknownObjects: true,
347
+ `);
348
+ });
349
+ (0, vitest_1.it)('should try to merge unknown objects if specified to do so', () => {
350
+ const from = {
351
+ foo: {
352
+ bar: [1, 2, 3],
353
+ },
354
+ baz: [
355
+ {
356
+ corge: true,
357
+ },
358
+ ],
359
+ };
360
+ (0, oids_js_1.assignOid)(from, 'test/a');
361
+ (0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
362
+ const to = {
363
+ foo: {
364
+ bar: [1, 2],
365
+ bop: [0],
366
+ },
367
+ baz: [
368
+ {
369
+ corge: false,
370
+ },
371
+ {
372
+ corge: false,
373
+ },
374
+ ],
375
+ };
376
+ (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
377
+ mergeUnknownObjects: true,
378
378
  })).toMatchInlineSnapshot(`
379
379
  [
380
380
  {
@@ -440,25 +440,25 @@ function createClock(init = 0) {
440
440
  "timestamp": "5",
441
441
  },
442
442
  ]
443
- `);
444
- });
445
- (0, vitest_1.it)('should not diff file refs', () => {
446
- const from = {
447
- foo: {
448
- file: (0, files_js_1.createFileRef)('abc123'),
449
- },
450
- bar: [(0, files_js_1.createFileRef)('def456'), (0, files_js_1.createFileRef)('ghi789')],
451
- };
452
- (0, oids_js_1.assignOid)(from, 'test/a');
453
- (0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
454
- const to = {
455
- foo: {
456
- file: (0, files_js_1.createFileRef)('abc456'),
457
- },
458
- bar: [(0, files_js_1.createFileRef)('def456')],
459
- };
460
- (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
461
- mergeUnknownObjects: true,
443
+ `);
444
+ });
445
+ (0, vitest_1.it)('should not diff file refs', () => {
446
+ const from = {
447
+ foo: {
448
+ file: (0, files_js_1.createFileRef)('abc123'),
449
+ },
450
+ bar: [(0, files_js_1.createFileRef)('def456'), (0, files_js_1.createFileRef)('ghi789')],
451
+ };
452
+ (0, oids_js_1.assignOid)(from, 'test/a');
453
+ (0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
454
+ const to = {
455
+ foo: {
456
+ file: (0, files_js_1.createFileRef)('abc456'),
457
+ },
458
+ bar: [(0, files_js_1.createFileRef)('def456')],
459
+ };
460
+ (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
461
+ mergeUnknownObjects: true,
462
462
  })).toMatchInlineSnapshot(`
463
463
  [
464
464
  {
@@ -483,26 +483,26 @@ function createClock(init = 0) {
483
483
  "timestamp": "1",
484
484
  },
485
485
  ]
486
- `);
487
- });
488
- (0, vitest_1.it)('should assign a new OID to objects which had an incompatible existing OID', () => {
489
- const from = {
490
- foo: {
491
- bar: [1, 2, 3],
492
- },
493
- };
494
- (0, oids_js_1.assignOid)(from, 'test/a');
495
- (0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
496
- const to = {
497
- foo: {
498
- bar: [1, 2],
499
- },
500
- };
501
- (0, oids_js_1.assignOid)(to, 'test/a');
502
- (0, oids_js_1.assignOid)(to.foo, 'uff/b');
503
- (0, oids_js_1.assignOidsToAllSubObjects)(to.foo, createClock());
504
- (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
505
- mergeUnknownObjects: true,
486
+ `);
487
+ });
488
+ (0, vitest_1.it)('should assign a new OID to objects which had an incompatible existing OID', () => {
489
+ const from = {
490
+ foo: {
491
+ bar: [1, 2, 3],
492
+ },
493
+ };
494
+ (0, oids_js_1.assignOid)(from, 'test/a');
495
+ (0, oids_js_1.assignOidsToAllSubObjects)(from, createClock());
496
+ const to = {
497
+ foo: {
498
+ bar: [1, 2],
499
+ },
500
+ };
501
+ (0, oids_js_1.assignOid)(to, 'test/a');
502
+ (0, oids_js_1.assignOid)(to.foo, 'uff/b');
503
+ (0, oids_js_1.assignOidsToAllSubObjects)(to.foo, createClock());
504
+ (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
505
+ mergeUnknownObjects: true,
506
506
  })).toMatchInlineSnapshot(`
507
507
  [
508
508
  {
@@ -549,25 +549,25 @@ function createClock(init = 0) {
549
549
  "timestamp": "3",
550
550
  },
551
551
  ]
552
- `);
553
- });
554
- // an edge case - if a subobject which contains nested objects changes identity,
555
- // this gets written as a new init patch tree - we want to ensure all init subobjects
556
- // in that tree have compatible OIDs.
557
- (0, vitest_1.it)('should assign a new OID to objects which have an incompatible OID when parent identity changes', () => {
558
- const from = {
559
- bar: [],
560
- };
561
- (0, oids_js_1.assignOid)(from, 'test/a');
562
- (0, oids_js_1.assignOid)(from.bar, 'test/random');
563
- const to = {
564
- bar: [{ baz: 1 }, { baz: 2 }],
565
- };
566
- (0, oids_js_1.assignOid)(to, 'test/a');
567
- (0, oids_js_1.assignOidsToAllSubObjects)(to, createClock());
568
- (0, oids_js_1.assignOid)(to.bar[0], 'uff/b');
569
- (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
570
- mergeUnknownObjects: true,
552
+ `);
553
+ });
554
+ // an edge case - if a subobject which contains nested objects changes identity,
555
+ // this gets written as a new init patch tree - we want to ensure all init subobjects
556
+ // in that tree have compatible OIDs.
557
+ (0, vitest_1.it)('should assign a new OID to objects which have an incompatible OID when parent identity changes', () => {
558
+ const from = {
559
+ bar: [],
560
+ };
561
+ (0, oids_js_1.assignOid)(from, 'test/a');
562
+ (0, oids_js_1.assignOid)(from.bar, 'test/random');
563
+ const to = {
564
+ bar: [{ baz: 1 }, { baz: 2 }],
565
+ };
566
+ (0, oids_js_1.assignOid)(to, 'test/a');
567
+ (0, oids_js_1.assignOidsToAllSubObjects)(to, createClock());
568
+ (0, oids_js_1.assignOid)(to.bar[0], 'uff/b');
569
+ (0, vitest_1.expect)((0, operation_js_1.diffToPatches)(from, to, createClock(), createClock(5), [], {
570
+ mergeUnknownObjects: true,
571
571
  })).toMatchInlineSnapshot(`
572
572
  [
573
573
  {
@@ -627,157 +627,157 @@ function createClock(init = 0) {
627
627
  "timestamp": "4",
628
628
  },
629
629
  ]
630
- `);
631
- });
632
- });
633
- (0, vitest_1.describe)('substituting refs with objects', () => {
634
- (0, vitest_1.it)('does nothing when no refs exist', () => {
635
- const root = {
636
- foo: 'bar',
637
- };
638
- (0, oids_js_1.assignOid)(root, 'test/a');
639
- const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map());
640
- (0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
641
- foo: 'bar',
642
- }, 'test/a'));
643
- (0, vitest_1.expect)(substituted).toEqual([]);
644
- });
645
- (0, vitest_1.it)('inserts top level objects with oids', () => {
646
- const root = {
647
- foo: {
648
- '@@type': 'ref',
649
- id: 'test/1:a',
650
- },
651
- qux: 1,
652
- };
653
- (0, oids_js_1.assignOid)(root, 'test/1');
654
- const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([['test/1:a', { foo: 'bar' }]]));
655
- (0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
656
- foo: (0, oids_js_1.assignOid)({
657
- foo: 'bar',
658
- }, 'test/1:a'),
659
- qux: 1,
660
- }, 'test/1'));
661
- (0, vitest_1.expect)(substituted).toEqual(['test/1:a']);
662
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
663
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
664
- });
665
- (0, vitest_1.it)('inserts nested objects with oids', () => {
666
- const root = {
667
- foo: {
668
- '@@type': 'ref',
669
- id: 'test/1:a',
670
- },
671
- };
672
- (0, oids_js_1.assignOid)(root, 'test/1');
673
- const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
674
- [
675
- 'test/1:a',
676
- {
677
- foo: 'bar',
678
- baz: {
679
- '@@type': 'ref',
680
- id: 'test/1:b',
681
- },
682
- },
683
- ],
684
- [
685
- 'test/1:b',
686
- {
687
- qux: 'corge',
688
- },
689
- ],
690
- ]));
691
- (0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
692
- foo: (0, oids_js_1.assignOid)({
693
- foo: 'bar',
694
- baz: (0, oids_js_1.assignOid)({
695
- qux: 'corge',
696
- }, 'test/1:b'),
697
- }, 'test/1:a'),
698
- }, 'test/1'));
699
- (0, vitest_1.expect)(substituted).toEqual(['test/1:a', 'test/1:b']);
700
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
701
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
702
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo.baz)).toEqual('test/1:b');
703
- });
704
- (0, vitest_1.it)('substitutes arrays of objects', () => {
705
- const root = {
706
- foo: {
707
- '@@type': 'ref',
708
- id: 'test/1:c',
709
- },
710
- };
711
- (0, oids_js_1.assignOid)(root, 'test/1');
712
- const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
713
- [
714
- 'test/1:c',
715
- [
716
- {
717
- '@@type': 'ref',
718
- id: 'test/1:a',
719
- },
720
- {
721
- '@@type': 'ref',
722
- id: 'test/1:b',
723
- },
724
- ],
725
- ],
726
- [
727
- 'test/1:a',
728
- {
729
- foo: 'bar',
730
- },
731
- ],
732
- [
733
- 'test/1:b',
734
- {
735
- qux: 'corge',
736
- },
737
- ],
738
- ]));
739
- (0, vitest_1.expect)(root).toEqual({
740
- foo: (0, oids_js_1.assignOid)([
741
- (0, oids_js_1.assignOid)({
742
- foo: 'bar',
743
- }, 'test/1:a'),
744
- (0, oids_js_1.assignOid)({
745
- qux: 'corge',
746
- }, 'test/1:b'),
747
- ], 'test/1:c'),
748
- });
749
- (0, vitest_1.expect)(substituted).toEqual(['test/1:c', 'test/1:a', 'test/1:b']);
750
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
751
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:c');
752
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[0])).toEqual('test/1:a');
753
- (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[1])).toEqual('test/1:b');
754
- });
755
- vitest_1.it.todo('substitutes arrays of arrays of objects');
756
- });
757
- (0, vitest_1.describe)('creating patches from initial state', () => {
758
- (0, vitest_1.it)('adds oids to all sub-objects', async () => {
759
- let i = 0;
760
- function createSubId() {
761
- return (i++).toString();
762
- }
763
- const result = (0, operation_js_1.initialToPatches)({
764
- foo: {
765
- bar: 'baz',
766
- },
767
- qux: [
768
- {
769
- corge: 'grault',
770
- },
771
- {
772
- bin: {
773
- oof: 1,
774
- },
775
- },
776
- ],
777
- }, 'test/a', createClock(), createSubId);
778
- /**
779
- * Patches should not include assigned OID property
780
- */
630
+ `);
631
+ });
632
+ });
633
+ (0, vitest_1.describe)('substituting refs with objects', () => {
634
+ (0, vitest_1.it)('does nothing when no refs exist', () => {
635
+ const root = {
636
+ foo: 'bar',
637
+ };
638
+ (0, oids_js_1.assignOid)(root, 'test/a');
639
+ const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map());
640
+ (0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
641
+ foo: 'bar',
642
+ }, 'test/a'));
643
+ (0, vitest_1.expect)(substituted).toEqual([]);
644
+ });
645
+ (0, vitest_1.it)('inserts top level objects with oids', () => {
646
+ const root = {
647
+ foo: {
648
+ '@@type': 'ref',
649
+ id: 'test/1:a',
650
+ },
651
+ qux: 1,
652
+ };
653
+ (0, oids_js_1.assignOid)(root, 'test/1');
654
+ const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([['test/1:a', { foo: 'bar' }]]));
655
+ (0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
656
+ foo: (0, oids_js_1.assignOid)({
657
+ foo: 'bar',
658
+ }, 'test/1:a'),
659
+ qux: 1,
660
+ }, 'test/1'));
661
+ (0, vitest_1.expect)(substituted).toEqual(['test/1:a']);
662
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
663
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
664
+ });
665
+ (0, vitest_1.it)('inserts nested objects with oids', () => {
666
+ const root = {
667
+ foo: {
668
+ '@@type': 'ref',
669
+ id: 'test/1:a',
670
+ },
671
+ };
672
+ (0, oids_js_1.assignOid)(root, 'test/1');
673
+ const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
674
+ [
675
+ 'test/1:a',
676
+ {
677
+ foo: 'bar',
678
+ baz: {
679
+ '@@type': 'ref',
680
+ id: 'test/1:b',
681
+ },
682
+ },
683
+ ],
684
+ [
685
+ 'test/1:b',
686
+ {
687
+ qux: 'corge',
688
+ },
689
+ ],
690
+ ]));
691
+ (0, vitest_1.expect)(root).toEqual((0, oids_js_1.assignOid)({
692
+ foo: (0, oids_js_1.assignOid)({
693
+ foo: 'bar',
694
+ baz: (0, oids_js_1.assignOid)({
695
+ qux: 'corge',
696
+ }, 'test/1:b'),
697
+ }, 'test/1:a'),
698
+ }, 'test/1'));
699
+ (0, vitest_1.expect)(substituted).toEqual(['test/1:a', 'test/1:b']);
700
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
701
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:a');
702
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo.baz)).toEqual('test/1:b');
703
+ });
704
+ (0, vitest_1.it)('substitutes arrays of objects', () => {
705
+ const root = {
706
+ foo: {
707
+ '@@type': 'ref',
708
+ id: 'test/1:c',
709
+ },
710
+ };
711
+ (0, oids_js_1.assignOid)(root, 'test/1');
712
+ const substituted = (0, operation_js_1.substituteRefsWithObjects)(root, new Map([
713
+ [
714
+ 'test/1:c',
715
+ [
716
+ {
717
+ '@@type': 'ref',
718
+ id: 'test/1:a',
719
+ },
720
+ {
721
+ '@@type': 'ref',
722
+ id: 'test/1:b',
723
+ },
724
+ ],
725
+ ],
726
+ [
727
+ 'test/1:a',
728
+ {
729
+ foo: 'bar',
730
+ },
731
+ ],
732
+ [
733
+ 'test/1:b',
734
+ {
735
+ qux: 'corge',
736
+ },
737
+ ],
738
+ ]));
739
+ (0, vitest_1.expect)(root).toEqual({
740
+ foo: (0, oids_js_1.assignOid)([
741
+ (0, oids_js_1.assignOid)({
742
+ foo: 'bar',
743
+ }, 'test/1:a'),
744
+ (0, oids_js_1.assignOid)({
745
+ qux: 'corge',
746
+ }, 'test/1:b'),
747
+ ], 'test/1:c'),
748
+ });
749
+ (0, vitest_1.expect)(substituted).toEqual(['test/1:c', 'test/1:a', 'test/1:b']);
750
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root)).toEqual('test/1');
751
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo)).toEqual('test/1:c');
752
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[0])).toEqual('test/1:a');
753
+ (0, vitest_1.expect)((0, oids_js_1.getOid)(root.foo[1])).toEqual('test/1:b');
754
+ });
755
+ vitest_1.it.todo('substitutes arrays of arrays of objects');
756
+ });
757
+ (0, vitest_1.describe)('creating patches from initial state', () => {
758
+ (0, vitest_1.it)('adds oids to all sub-objects', async () => {
759
+ let i = 0;
760
+ function createSubId() {
761
+ return (i++).toString();
762
+ }
763
+ const result = (0, operation_js_1.initialToPatches)({
764
+ foo: {
765
+ bar: 'baz',
766
+ },
767
+ qux: [
768
+ {
769
+ corge: 'grault',
770
+ },
771
+ {
772
+ bin: {
773
+ oof: 1,
774
+ },
775
+ },
776
+ ],
777
+ }, 'test/a', createClock(), createSubId);
778
+ /**
779
+ * Patches should not include assigned OID property
780
+ */
781
781
  (0, vitest_1.expect)(result).toMatchInlineSnapshot(`
782
782
  [
783
783
  {
@@ -858,120 +858,120 @@ function createClock(init = 0) {
858
858
  "timestamp": "5",
859
859
  },
860
860
  ]
861
- `);
862
- });
863
- });
864
- (0, vitest_1.describe)('applying individual operations', () => {
865
- (0, vitest_1.it)('applies a list-remove of only the last instance', () => {
866
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
867
- op: 'list-remove',
868
- value: 'a',
869
- only: 'last',
870
- })).toEqual(['a', 'b', 'c', 'b']);
871
- });
872
- (0, vitest_1.it)('applies a list-remove of only the first instance', () => {
873
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
874
- op: 'list-remove',
875
- value: 'a',
876
- only: 'first',
877
- })).toEqual(['b', 'c', 'a', 'b']);
878
- });
879
- (0, vitest_1.it)('applies a list-remove of all instances', () => {
880
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
881
- op: 'list-remove',
882
- value: 'a',
883
- })).toEqual(['b', 'c', 'b']);
884
- });
885
- (0, vitest_1.it)('applies a list-remove of an object ref', () => {
886
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)([
887
- (0, oids_js_1.createRef)('a'),
888
- (0, oids_js_1.createRef)('b'),
889
- (0, oids_js_1.createRef)('c'),
890
- (0, oids_js_1.createRef)('a'),
891
- (0, oids_js_1.createRef)('b'),
892
- ], {
893
- op: 'list-remove',
894
- value: (0, oids_js_1.createRef)('a'),
895
- only: 'last',
896
- })).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')]);
897
- });
898
- (0, vitest_1.it)('applies a list-add of a nonexistent item', () => {
899
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
900
- op: 'list-add',
901
- value: 'd',
902
- })).toEqual(['a', 'b', 'c', 'd']);
903
- });
904
- (0, vitest_1.it)('does not apply a list-add if the item is already present', () => {
905
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
906
- op: 'list-add',
907
- value: 'b',
908
- })).toEqual(['a', 'b', 'c']);
909
- });
910
- });
911
- (0, vitest_1.describe)('collecting deleted refs during patch application', () => {
912
- (0, vitest_1.it)('collects refs that are removed from a list', () => {
913
- const refs = [];
914
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)([
915
- (0, oids_js_1.createRef)('a'),
916
- (0, oids_js_1.createRef)('b'),
917
- (0, oids_js_1.createRef)('c'),
918
- (0, oids_js_1.createRef)('d'),
919
- (0, oids_js_1.createRef)('e'),
920
- ], {
921
- op: 'list-remove',
922
- value: (0, oids_js_1.createRef)('c'),
923
- }, 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')]);
924
- (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('c')]);
925
- });
926
- (0, vitest_1.it)('collects a deleted ref field from an object', () => {
927
- const refs = [];
928
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)({
929
- a: (0, oids_js_1.createRef)('a'),
930
- b: (0, oids_js_1.createRef)('b'),
931
- c: (0, oids_js_1.createRef)('c'),
932
- }, {
933
- op: 'remove',
934
- name: 'b',
935
- }, refs)).toEqual({
936
- a: (0, oids_js_1.createRef)('a'),
937
- c: (0, oids_js_1.createRef)('c'),
938
- });
939
- (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
940
- });
941
- (0, vitest_1.it)('collects all refs in a deleted object', () => {
942
- const refs = [];
943
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)({
944
- a: (0, oids_js_1.createRef)('a'),
945
- b: (0, oids_js_1.createRef)('b'),
946
- c: (0, oids_js_1.createRef)('c'),
947
- }, {
948
- op: 'delete',
949
- }, refs)).toEqual(undefined);
950
- (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
951
- });
952
- (0, vitest_1.it)('collects all refs in a deleted list', () => {
953
- const refs = [];
954
- (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')], {
955
- op: 'delete',
956
- }, refs)).toEqual(undefined);
957
- (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
958
- });
959
- (0, vitest_1.it)('collects a ref in a replaced field', () => {
960
- const refs = [];
961
- (0, vitest_1.expect)((0, operation_js_1.applyPatch)({
962
- a: (0, oids_js_1.createRef)('a'),
963
- b: (0, oids_js_1.createRef)('b'),
964
- c: (0, oids_js_1.createRef)('c'),
965
- }, {
966
- op: 'set',
967
- name: 'b',
968
- value: (0, oids_js_1.createRef)('d'),
969
- }, refs)).toEqual({
970
- a: (0, oids_js_1.createRef)('a'),
971
- b: (0, oids_js_1.createRef)('d'),
972
- c: (0, oids_js_1.createRef)('c'),
973
- });
974
- (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
975
- });
976
- });
861
+ `);
862
+ });
863
+ });
864
+ (0, vitest_1.describe)('applying individual operations', () => {
865
+ (0, vitest_1.it)('applies a list-remove of only the last instance', () => {
866
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
867
+ op: 'list-remove',
868
+ value: 'a',
869
+ only: 'last',
870
+ })).toEqual(['a', 'b', 'c', 'b']);
871
+ });
872
+ (0, vitest_1.it)('applies a list-remove of only the first instance', () => {
873
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
874
+ op: 'list-remove',
875
+ value: 'a',
876
+ only: 'first',
877
+ })).toEqual(['b', 'c', 'a', 'b']);
878
+ });
879
+ (0, vitest_1.it)('applies a list-remove of all instances', () => {
880
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c', 'a', 'b'], {
881
+ op: 'list-remove',
882
+ value: 'a',
883
+ })).toEqual(['b', 'c', 'b']);
884
+ });
885
+ (0, vitest_1.it)('applies a list-remove of an object ref', () => {
886
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)([
887
+ (0, oids_js_1.createRef)('a'),
888
+ (0, oids_js_1.createRef)('b'),
889
+ (0, oids_js_1.createRef)('c'),
890
+ (0, oids_js_1.createRef)('a'),
891
+ (0, oids_js_1.createRef)('b'),
892
+ ], {
893
+ op: 'list-remove',
894
+ value: (0, oids_js_1.createRef)('a'),
895
+ only: 'last',
896
+ })).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')]);
897
+ });
898
+ (0, vitest_1.it)('applies a list-add of a nonexistent item', () => {
899
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
900
+ op: 'list-add',
901
+ value: 'd',
902
+ })).toEqual(['a', 'b', 'c', 'd']);
903
+ });
904
+ (0, vitest_1.it)('does not apply a list-add if the item is already present', () => {
905
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)(['a', 'b', 'c'], {
906
+ op: 'list-add',
907
+ value: 'b',
908
+ })).toEqual(['a', 'b', 'c']);
909
+ });
910
+ });
911
+ (0, vitest_1.describe)('collecting deleted refs during patch application', () => {
912
+ (0, vitest_1.it)('collects refs that are removed from a list', () => {
913
+ const refs = [];
914
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)([
915
+ (0, oids_js_1.createRef)('a'),
916
+ (0, oids_js_1.createRef)('b'),
917
+ (0, oids_js_1.createRef)('c'),
918
+ (0, oids_js_1.createRef)('d'),
919
+ (0, oids_js_1.createRef)('e'),
920
+ ], {
921
+ op: 'list-remove',
922
+ value: (0, oids_js_1.createRef)('c'),
923
+ }, 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')]);
924
+ (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('c')]);
925
+ });
926
+ (0, vitest_1.it)('collects a deleted ref field from an object', () => {
927
+ const refs = [];
928
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)({
929
+ a: (0, oids_js_1.createRef)('a'),
930
+ b: (0, oids_js_1.createRef)('b'),
931
+ c: (0, oids_js_1.createRef)('c'),
932
+ }, {
933
+ op: 'remove',
934
+ name: 'b',
935
+ }, refs)).toEqual({
936
+ a: (0, oids_js_1.createRef)('a'),
937
+ c: (0, oids_js_1.createRef)('c'),
938
+ });
939
+ (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
940
+ });
941
+ (0, vitest_1.it)('collects all refs in a deleted object', () => {
942
+ const refs = [];
943
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)({
944
+ a: (0, oids_js_1.createRef)('a'),
945
+ b: (0, oids_js_1.createRef)('b'),
946
+ c: (0, oids_js_1.createRef)('c'),
947
+ }, {
948
+ op: 'delete',
949
+ }, refs)).toEqual(undefined);
950
+ (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
951
+ });
952
+ (0, vitest_1.it)('collects all refs in a deleted list', () => {
953
+ const refs = [];
954
+ (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')], {
955
+ op: 'delete',
956
+ }, refs)).toEqual(undefined);
957
+ (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('a'), (0, oids_js_1.createRef)('b'), (0, oids_js_1.createRef)('c')]);
958
+ });
959
+ (0, vitest_1.it)('collects a ref in a replaced field', () => {
960
+ const refs = [];
961
+ (0, vitest_1.expect)((0, operation_js_1.applyPatch)({
962
+ a: (0, oids_js_1.createRef)('a'),
963
+ b: (0, oids_js_1.createRef)('b'),
964
+ c: (0, oids_js_1.createRef)('c'),
965
+ }, {
966
+ op: 'set',
967
+ name: 'b',
968
+ value: (0, oids_js_1.createRef)('d'),
969
+ }, refs)).toEqual({
970
+ a: (0, oids_js_1.createRef)('a'),
971
+ b: (0, oids_js_1.createRef)('d'),
972
+ c: (0, oids_js_1.createRef)('c'),
973
+ });
974
+ (0, vitest_1.expect)(refs).toEqual([(0, oids_js_1.createRef)('b')]);
975
+ });
976
+ });
977
977
  //# sourceMappingURL=operation.test.js.map