@verdant-web/common 1.15.3-next.0 → 1.15.4

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 (154) 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/index.d.ts +19 -19
  10. package/dist/cjs/index.js +41 -41
  11. package/dist/cjs/indexes.d.ts +17 -17
  12. package/dist/cjs/indexes.js +142 -142
  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 +172 -172
  16. package/dist/cjs/migration.js +301 -301
  17. package/dist/cjs/oids.d.ts +100 -100
  18. package/dist/cjs/oids.js +461 -457
  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 +348 -348
  22. package/dist/cjs/operation.d.ts +139 -139
  23. package/dist/cjs/operation.js +545 -545
  24. package/dist/cjs/operation.test.d.ts +1 -1
  25. package/dist/cjs/operation.test.js +529 -529
  26. package/dist/cjs/patch.d.ts +26 -26
  27. package/dist/cjs/patch.js +226 -226
  28. package/dist/cjs/presence.d.ts +27 -27
  29. package/dist/cjs/presence.js +2 -2
  30. package/dist/cjs/protocol.d.ts +145 -145
  31. package/dist/cjs/protocol.js +3 -3
  32. package/dist/cjs/refs.d.ts +7 -7
  33. package/dist/cjs/refs.js +29 -29
  34. package/dist/cjs/replica.d.ts +28 -28
  35. package/dist/cjs/replica.js +28 -28
  36. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  37. package/dist/cjs/schema/defaults.test.js +20 -20
  38. package/dist/cjs/schema/fields.d.ts +9 -9
  39. package/dist/cjs/schema/fields.js +144 -144
  40. package/dist/cjs/schema/index.d.ts +8 -8
  41. package/dist/cjs/schema/index.js +51 -51
  42. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  43. package/dist/cjs/schema/indexFilters.js +30 -30
  44. package/dist/cjs/schema/types/collection.d.ts +23 -23
  45. package/dist/cjs/schema/types/collection.js +2 -2
  46. package/dist/cjs/schema/types/compounds.d.ts +11 -11
  47. package/dist/cjs/schema/types/compounds.js +2 -2
  48. package/dist/cjs/schema/types/fields.d.ts +75 -75
  49. package/dist/cjs/schema/types/fields.js +2 -2
  50. package/dist/cjs/schema/types/filters.d.ts +29 -29
  51. package/dist/cjs/schema/types/filters.js +2 -2
  52. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  53. package/dist/cjs/schema/types/shapes.js +2 -2
  54. package/dist/cjs/schema/types/synthetics.d.ts +37 -37
  55. package/dist/cjs/schema/types/synthetics.js +2 -2
  56. package/dist/cjs/schema/types.d.ts +18 -18
  57. package/dist/cjs/schema/types.js +22 -22
  58. package/dist/cjs/schema/validation.d.ts +3 -3
  59. package/dist/cjs/schema/validation.js +86 -86
  60. package/dist/cjs/timestamp.d.ts +50 -50
  61. package/dist/cjs/timestamp.js +251 -251
  62. package/dist/cjs/timestamp.test.d.ts +1 -1
  63. package/dist/cjs/timestamp.test.js +104 -104
  64. package/dist/cjs/undo.d.ts +3 -3
  65. package/dist/cjs/undo.js +198 -198
  66. package/dist/cjs/utils.d.ts +20 -20
  67. package/dist/cjs/utils.js +145 -145
  68. package/dist/cjs/utils.test.d.ts +1 -1
  69. package/dist/cjs/utils.test.js +36 -36
  70. package/dist/esm/EventSubscriber.d.ts +17 -17
  71. package/dist/esm/EventSubscriber.js +62 -62
  72. package/dist/esm/baseline.d.ts +5 -5
  73. package/dist/esm/baseline.js +1 -1
  74. package/dist/esm/batching.d.ts +42 -42
  75. package/dist/esm/batching.js +86 -86
  76. package/dist/esm/files.d.ts +19 -19
  77. package/dist/esm/files.js +12 -12
  78. package/dist/esm/index.d.ts +19 -19
  79. package/dist/esm/index.js +16 -16
  80. package/dist/esm/indexes.d.ts +17 -17
  81. package/dist/esm/indexes.js +130 -130
  82. package/dist/esm/indexes.test.d.ts +1 -1
  83. package/dist/esm/indexes.test.js +125 -125
  84. package/dist/esm/migration.d.ts +172 -172
  85. package/dist/esm/migration.js +294 -294
  86. package/dist/esm/oids.d.ts +100 -100
  87. package/dist/esm/oids.js +426 -422
  88. package/dist/esm/oids.js.map +1 -1
  89. package/dist/esm/oids.test.d.ts +1 -1
  90. package/dist/esm/oids.test.js +346 -346
  91. package/dist/esm/operation.d.ts +139 -139
  92. package/dist/esm/operation.js +530 -530
  93. package/dist/esm/operation.test.d.ts +1 -1
  94. package/dist/esm/operation.test.js +527 -527
  95. package/dist/esm/patch.d.ts +26 -26
  96. package/dist/esm/patch.js +222 -222
  97. package/dist/esm/presence.d.ts +27 -27
  98. package/dist/esm/presence.js +1 -1
  99. package/dist/esm/protocol.d.ts +145 -145
  100. package/dist/esm/protocol.js +2 -2
  101. package/dist/esm/refs.d.ts +7 -7
  102. package/dist/esm/refs.js +22 -22
  103. package/dist/esm/replica.d.ts +28 -28
  104. package/dist/esm/replica.js +25 -25
  105. package/dist/esm/schema/defaults.test.d.ts +1 -1
  106. package/dist/esm/schema/defaults.test.js +18 -18
  107. package/dist/esm/schema/fields.d.ts +9 -9
  108. package/dist/esm/schema/fields.js +133 -133
  109. package/dist/esm/schema/index.d.ts +8 -8
  110. package/dist/esm/schema/index.js +32 -32
  111. package/dist/esm/schema/indexFilters.d.ts +6 -6
  112. package/dist/esm/schema/indexFilters.js +22 -22
  113. package/dist/esm/schema/types/collection.d.ts +23 -23
  114. package/dist/esm/schema/types/collection.js +1 -1
  115. package/dist/esm/schema/types/compounds.d.ts +11 -11
  116. package/dist/esm/schema/types/compounds.js +1 -1
  117. package/dist/esm/schema/types/fields.d.ts +75 -75
  118. package/dist/esm/schema/types/fields.js +1 -1
  119. package/dist/esm/schema/types/filters.d.ts +29 -29
  120. package/dist/esm/schema/types/filters.js +1 -1
  121. package/dist/esm/schema/types/shapes.d.ts +21 -21
  122. package/dist/esm/schema/types/shapes.js +1 -1
  123. package/dist/esm/schema/types/synthetics.d.ts +37 -37
  124. package/dist/esm/schema/types/synthetics.js +1 -1
  125. package/dist/esm/schema/types.d.ts +18 -18
  126. package/dist/esm/schema/types.js +6 -6
  127. package/dist/esm/schema/validation.d.ts +3 -3
  128. package/dist/esm/schema/validation.js +81 -81
  129. package/dist/esm/timestamp.d.ts +50 -50
  130. package/dist/esm/timestamp.js +234 -234
  131. package/dist/esm/timestamp.test.d.ts +1 -1
  132. package/dist/esm/timestamp.test.js +102 -102
  133. package/dist/esm/undo.d.ts +3 -3
  134. package/dist/esm/undo.js +194 -194
  135. package/dist/esm/utils.d.ts +20 -20
  136. package/dist/esm/utils.js +127 -127
  137. package/dist/esm/utils.test.d.ts +1 -1
  138. package/dist/esm/utils.test.js +34 -34
  139. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  140. package/dist/tsconfig.tsbuildinfo +1 -1
  141. package/package.json +1 -1
  142. package/src/oids.ts +5 -1
  143. package/dist/cjs/files.test.d.ts +0 -1
  144. package/dist/cjs/files.test.js +0 -81
  145. package/dist/cjs/files.test.js.map +0 -1
  146. package/dist/cjs/schema/defaults.d.ts +0 -4
  147. package/dist/cjs/schema/defaults.js +0 -72
  148. package/dist/cjs/schema/defaults.js.map +0 -1
  149. package/dist/esm/files.test.d.ts +0 -1
  150. package/dist/esm/files.test.js +0 -79
  151. package/dist/esm/files.test.js.map +0 -1
  152. package/dist/esm/schema/defaults.d.ts +0 -4
  153. package/dist/esm/schema/defaults.js +0 -66
  154. package/dist/esm/schema/defaults.js.map +0 -1
@@ -1,142 +1,142 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { createFileRef } from './files.js';
3
- import { areOidsRelated, assignOid, assignOidPropertiesToAllSubObjects, assignOidProperty, assignOidsToAllSubObjects, createOid, createSubOid, decomposeOid, getOid, getOidSubIdRange, getOidRoot, hasOid, maybeGetOidProperty, normalize, normalizeFirstLevel, removeOidPropertiesFromAllSubObjects, getLegacyDotOidSubIdRange, MATCH_LEGACY_OID_JSON_STRING, replaceLegacyOidsInObject, } from './oids.js';
4
- describe('normalizing an object', () => {
5
- it('should return a map of sub-objects with relationships replaced by refs', () => {
6
- let i = 0;
7
- function createSubId() {
8
- return (i++).toString();
9
- }
10
- const initial = {
11
- foo: {
12
- bar: 1,
13
- baz: [2, 3],
14
- },
15
- qux: [
16
- {
17
- corge: true,
18
- },
19
- {
20
- grault: {
21
- garply: 4,
22
- },
23
- },
24
- ],
25
- };
26
- assignOid(initial, 'test/a');
27
- assignOidsToAllSubObjects(initial, createSubId);
28
- const result = normalize(initial);
29
- expect(result.get('test/a')).toEqual(assignOid({
30
- foo: {
31
- '@@type': 'ref',
32
- id: 'test/a:0',
33
- },
34
- qux: {
35
- '@@type': 'ref',
36
- id: 'test/a:2',
37
- },
38
- }, 'test/a'));
39
- expect(result.get('test/a:0')).toEqual(assignOid({
40
- bar: 1,
41
- baz: {
42
- '@@type': 'ref',
43
- id: 'test/a:1',
44
- },
45
- }, 'test/a:0'));
46
- expect(result.get('test/a:1')).toEqual(assignOid([2, 3], 'test/a:1'));
47
- expect(result.get('test/a:2')).toEqual(assignOid([
48
- {
49
- '@@type': 'ref',
50
- id: 'test/a:3',
51
- },
52
- {
53
- '@@type': 'ref',
54
- id: 'test/a:4',
55
- },
56
- ], 'test/a:2'));
57
- expect(result.get('test/a:3')).toEqual(assignOid({
58
- corge: true,
59
- }, 'test/a:3'));
60
- expect(result.get('test/a:4')).toEqual(assignOid({
61
- grault: {
62
- '@@type': 'ref',
63
- id: 'test/a:5',
64
- },
65
- }, 'test/a:4'));
66
- expect(result.get('test/a:5')).toEqual(assignOid({
67
- garply: 4,
68
- }, 'test/a:5'));
69
- });
70
- it('should handle file references and not replace them with refs or attempt to normalize them', () => {
71
- let i = 0;
72
- function createSubId() {
73
- return (i++).toString();
74
- }
75
- const initial = {
76
- foo: {
77
- bar: 1,
78
- file: createFileRef('abcd123'),
79
- },
80
- qux: [createFileRef('efgh456'), createFileRef('ijkl789')],
81
- };
82
- assignOid(initial, 'test/a');
83
- assignOidsToAllSubObjects(initial, createSubId);
84
- const result = normalize(initial);
85
- expect(result.size).toBe(3);
86
- expect(result.get('test/a')).toEqual(assignOid({
87
- foo: {
88
- '@@type': 'ref',
89
- id: 'test/a:0',
90
- },
91
- qux: {
92
- '@@type': 'ref',
93
- id: 'test/a:1',
94
- },
95
- }, 'test/a'));
96
- expect(result.get('test/a:0')).toEqual(assignOid({
97
- bar: 1,
98
- file: {
99
- '@@type': 'file',
100
- id: 'abcd123',
101
- },
102
- }, 'test/a:0'));
103
- expect(result.get('test/a:1')).toEqual(assignOid([
104
- {
105
- '@@type': 'file',
106
- id: 'efgh456',
107
- },
108
- {
109
- '@@type': 'file',
110
- id: 'ijkl789',
111
- },
112
- ], 'test/a:2'));
113
- });
114
- });
115
- describe('normalizing the first level of an object', () => {
116
- it('collects all top-level sub-objects', () => {
117
- let i = 0;
118
- function createSubId() {
119
- return (i++).toString();
120
- }
121
- const initial = {
122
- foo: {
123
- bar: 1,
124
- baz: [2, 3],
125
- },
126
- qux: [
127
- {
128
- corge: true,
129
- },
130
- {
131
- grault: {
132
- garply: 4,
133
- },
134
- },
135
- ],
136
- };
137
- assignOid(initial, 'test/a');
138
- assignOidsToAllSubObjects(initial, createSubId);
139
- const { refs: result } = normalizeFirstLevel(initial);
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createFileRef } from './files.js';
3
+ import { areOidsRelated, assignOid, assignOidPropertiesToAllSubObjects, assignOidProperty, assignOidsToAllSubObjects, createOid, createSubOid, decomposeOid, getOid, getOidSubIdRange, getOidRoot, hasOid, maybeGetOidProperty, normalize, normalizeFirstLevel, removeOidPropertiesFromAllSubObjects, getLegacyDotOidSubIdRange, MATCH_LEGACY_OID_JSON_STRING, replaceLegacyOidsInObject, } from './oids.js';
4
+ describe('normalizing an object', () => {
5
+ it('should return a map of sub-objects with relationships replaced by refs', () => {
6
+ let i = 0;
7
+ function createSubId() {
8
+ return (i++).toString();
9
+ }
10
+ const initial = {
11
+ foo: {
12
+ bar: 1,
13
+ baz: [2, 3],
14
+ },
15
+ qux: [
16
+ {
17
+ corge: true,
18
+ },
19
+ {
20
+ grault: {
21
+ garply: 4,
22
+ },
23
+ },
24
+ ],
25
+ };
26
+ assignOid(initial, 'test/a');
27
+ assignOidsToAllSubObjects(initial, createSubId);
28
+ const result = normalize(initial);
29
+ expect(result.get('test/a')).toEqual(assignOid({
30
+ foo: {
31
+ '@@type': 'ref',
32
+ id: 'test/a:0',
33
+ },
34
+ qux: {
35
+ '@@type': 'ref',
36
+ id: 'test/a:2',
37
+ },
38
+ }, 'test/a'));
39
+ expect(result.get('test/a:0')).toEqual(assignOid({
40
+ bar: 1,
41
+ baz: {
42
+ '@@type': 'ref',
43
+ id: 'test/a:1',
44
+ },
45
+ }, 'test/a:0'));
46
+ expect(result.get('test/a:1')).toEqual(assignOid([2, 3], 'test/a:1'));
47
+ expect(result.get('test/a:2')).toEqual(assignOid([
48
+ {
49
+ '@@type': 'ref',
50
+ id: 'test/a:3',
51
+ },
52
+ {
53
+ '@@type': 'ref',
54
+ id: 'test/a:4',
55
+ },
56
+ ], 'test/a:2'));
57
+ expect(result.get('test/a:3')).toEqual(assignOid({
58
+ corge: true,
59
+ }, 'test/a:3'));
60
+ expect(result.get('test/a:4')).toEqual(assignOid({
61
+ grault: {
62
+ '@@type': 'ref',
63
+ id: 'test/a:5',
64
+ },
65
+ }, 'test/a:4'));
66
+ expect(result.get('test/a:5')).toEqual(assignOid({
67
+ garply: 4,
68
+ }, 'test/a:5'));
69
+ });
70
+ it('should handle file references and not replace them with refs or attempt to normalize them', () => {
71
+ let i = 0;
72
+ function createSubId() {
73
+ return (i++).toString();
74
+ }
75
+ const initial = {
76
+ foo: {
77
+ bar: 1,
78
+ file: createFileRef('abcd123'),
79
+ },
80
+ qux: [createFileRef('efgh456'), createFileRef('ijkl789')],
81
+ };
82
+ assignOid(initial, 'test/a');
83
+ assignOidsToAllSubObjects(initial, createSubId);
84
+ const result = normalize(initial);
85
+ expect(result.size).toBe(3);
86
+ expect(result.get('test/a')).toEqual(assignOid({
87
+ foo: {
88
+ '@@type': 'ref',
89
+ id: 'test/a:0',
90
+ },
91
+ qux: {
92
+ '@@type': 'ref',
93
+ id: 'test/a:1',
94
+ },
95
+ }, 'test/a'));
96
+ expect(result.get('test/a:0')).toEqual(assignOid({
97
+ bar: 1,
98
+ file: {
99
+ '@@type': 'file',
100
+ id: 'abcd123',
101
+ },
102
+ }, 'test/a:0'));
103
+ expect(result.get('test/a:1')).toEqual(assignOid([
104
+ {
105
+ '@@type': 'file',
106
+ id: 'efgh456',
107
+ },
108
+ {
109
+ '@@type': 'file',
110
+ id: 'ijkl789',
111
+ },
112
+ ], 'test/a:2'));
113
+ });
114
+ });
115
+ describe('normalizing the first level of an object', () => {
116
+ it('collects all top-level sub-objects', () => {
117
+ let i = 0;
118
+ function createSubId() {
119
+ return (i++).toString();
120
+ }
121
+ const initial = {
122
+ foo: {
123
+ bar: 1,
124
+ baz: [2, 3],
125
+ },
126
+ qux: [
127
+ {
128
+ corge: true,
129
+ },
130
+ {
131
+ grault: {
132
+ garply: 4,
133
+ },
134
+ },
135
+ ],
136
+ };
137
+ assignOid(initial, 'test/a');
138
+ assignOidsToAllSubObjects(initial, createSubId);
139
+ const { refs: result } = normalizeFirstLevel(initial);
140
140
  expect(result.get('test/a')).toMatchInlineSnapshot(`
141
141
  {
142
142
  "foo": {
@@ -148,7 +148,7 @@ describe('normalizing the first level of an object', () => {
148
148
  "id": "test/a:2",
149
149
  },
150
150
  }
151
- `);
151
+ `);
152
152
  expect(result.get('test/a:0')).toMatchInlineSnapshot(`
153
153
  {
154
154
  "bar": 1,
@@ -157,8 +157,8 @@ describe('normalizing the first level of an object', () => {
157
157
  3,
158
158
  ],
159
159
  }
160
- `);
161
- expect(result.get('test/a:1')).toBeUndefined();
160
+ `);
161
+ expect(result.get('test/a:1')).toBeUndefined();
162
162
  expect(result.get('test/a:2')).toMatchInlineSnapshot(`
163
163
  [
164
164
  {
@@ -170,73 +170,73 @@ describe('normalizing the first level of an object', () => {
170
170
  },
171
171
  },
172
172
  ]
173
- `);
174
- expect(result.get('test/a:3')).toBeUndefined();
175
- expect(result.get('test/a:4')).toBeUndefined();
176
- expect(result.get('test/a:5')).toBeUndefined();
177
- });
178
- });
179
- describe('computing a range of oids for a whole object set', () => {
180
- function isWithin(oid, start, end) {
181
- return oid >= start && oid <= end;
182
- }
183
- it('should include the root object and any possible sub object oid', () => {
184
- const [start, end] = getOidSubIdRange('test/a');
185
- expect(start).toEqual('test/a:');
186
- expect(end).toEqual('test/a:\uffff');
187
- expect(start < end).toBe(true);
188
- expect(isWithin('test/a:0', start, end)).toBe(true);
189
- expect(isWithin('test/a:1', start, end)).toBe(true);
190
- expect(isWithin('test/a:zzzzzzzzzzzzzzzzzzzzzzz', start, end)).toBe(true);
191
- expect(isWithin('test/a:\uffff', start, end)).toBe(true);
192
- expect(isWithin('test1/a', start, end)).toBe(false);
193
- expect(isWithin('test/b', start, end)).toBe(false);
194
- expect(isWithin('test/ ', start, end)).toBe(false);
195
- expect(isWithin('test/a1', start, end)).toBe(false);
196
- expect(isWithin('test/a1:3', start, end)).toBe(false);
197
- });
198
- it('should accommodate legacy dot style oids', () => {
199
- const [start, end] = getLegacyDotOidSubIdRange('test/a.foo:barrrr');
200
- expect(start).toEqual('test/a.');
201
- expect(end).toEqual('test/a.\uffff');
202
- expect(start < end).toBe(true);
203
- expect(isWithin('test/a.foo:0', start, end)).toBe(true);
204
- expect(isWithin('test/a.foo:1', start, end)).toBe(true);
205
- expect(isWithin('test/a.bar:zzzzzzzzzzzzzzzzzzzzzzz', start, end)).toBe(true);
206
- expect(isWithin('test/a.aff:\uffff', start, end)).toBe(true);
207
- expect(isWithin('test1/a', start, end)).toBe(false);
208
- expect(isWithin('test/b', start, end)).toBe(false);
209
- expect(isWithin('test/ ', start, end)).toBe(false);
210
- expect(isWithin('test/a1', start, end)).toBe(false);
211
- expect(isWithin('test/a1:3', start, end)).toBe(false);
212
- expect(isWithin('test/a.foo:barrrr', start, end)).toBe(true);
213
- });
214
- });
215
- describe('assigning OIDs as properties', () => {
216
- it('should assign to all sub-objects', () => {
217
- let i = 0;
218
- function createSubId() {
219
- return (i++).toString();
220
- }
221
- const initial = {
222
- foo: {
223
- bar: 1,
224
- baz: [2, 3],
225
- },
226
- qux: [
227
- {
228
- corge: true,
229
- },
230
- {
231
- grault: {
232
- garply: 4,
233
- },
234
- },
235
- ],
236
- };
237
- assignOid(initial, 'test/a');
238
- assignOidsToAllSubObjects(initial, createSubId);
239
- assignOidPropertiesToAllSubObjects(initial);
173
+ `);
174
+ expect(result.get('test/a:3')).toBeUndefined();
175
+ expect(result.get('test/a:4')).toBeUndefined();
176
+ expect(result.get('test/a:5')).toBeUndefined();
177
+ });
178
+ });
179
+ describe('computing a range of oids for a whole object set', () => {
180
+ function isWithin(oid, start, end) {
181
+ return oid >= start && oid <= end;
182
+ }
183
+ it('should include the root object and any possible sub object oid', () => {
184
+ const [start, end] = getOidSubIdRange('test/a');
185
+ expect(start).toEqual('test/a:');
186
+ expect(end).toEqual('test/a:\uffff');
187
+ expect(start < end).toBe(true);
188
+ expect(isWithin('test/a:0', start, end)).toBe(true);
189
+ expect(isWithin('test/a:1', start, end)).toBe(true);
190
+ expect(isWithin('test/a:zzzzzzzzzzzzzzzzzzzzzzz', start, end)).toBe(true);
191
+ expect(isWithin('test/a:\uffff', start, end)).toBe(true);
192
+ expect(isWithin('test1/a', start, end)).toBe(false);
193
+ expect(isWithin('test/b', start, end)).toBe(false);
194
+ expect(isWithin('test/ ', start, end)).toBe(false);
195
+ expect(isWithin('test/a1', start, end)).toBe(false);
196
+ expect(isWithin('test/a1:3', start, end)).toBe(false);
197
+ });
198
+ it('should accommodate legacy dot style oids', () => {
199
+ const [start, end] = getLegacyDotOidSubIdRange('test/a.foo:barrrr');
200
+ expect(start).toEqual('test/a.');
201
+ expect(end).toEqual('test/a.\uffff');
202
+ expect(start < end).toBe(true);
203
+ expect(isWithin('test/a.foo:0', start, end)).toBe(true);
204
+ expect(isWithin('test/a.foo:1', start, end)).toBe(true);
205
+ expect(isWithin('test/a.bar:zzzzzzzzzzzzzzzzzzzzzzz', start, end)).toBe(true);
206
+ expect(isWithin('test/a.aff:\uffff', start, end)).toBe(true);
207
+ expect(isWithin('test1/a', start, end)).toBe(false);
208
+ expect(isWithin('test/b', start, end)).toBe(false);
209
+ expect(isWithin('test/ ', start, end)).toBe(false);
210
+ expect(isWithin('test/a1', start, end)).toBe(false);
211
+ expect(isWithin('test/a1:3', start, end)).toBe(false);
212
+ expect(isWithin('test/a.foo:barrrr', start, end)).toBe(true);
213
+ });
214
+ });
215
+ describe('assigning OIDs as properties', () => {
216
+ it('should assign to all sub-objects', () => {
217
+ let i = 0;
218
+ function createSubId() {
219
+ return (i++).toString();
220
+ }
221
+ const initial = {
222
+ foo: {
223
+ bar: 1,
224
+ baz: [2, 3],
225
+ },
226
+ qux: [
227
+ {
228
+ corge: true,
229
+ },
230
+ {
231
+ grault: {
232
+ garply: 4,
233
+ },
234
+ },
235
+ ],
236
+ };
237
+ assignOid(initial, 'test/a');
238
+ assignOidsToAllSubObjects(initial, createSubId);
239
+ assignOidPropertiesToAllSubObjects(initial);
240
240
  expect(initial).toMatchInlineSnapshot(`
241
241
  {
242
242
  "@@id": "test/a",
@@ -262,141 +262,141 @@ describe('assigning OIDs as properties', () => {
262
262
  },
263
263
  ],
264
264
  }
265
- `);
266
- // extra check needed for array since it doesn't serialize in the snapshot
267
- expect(maybeGetOidProperty(initial.qux)).toBe('test/a:2');
268
- });
269
- it('should transfer assigned OID properties to the memory system', () => {
270
- const initial = assignOidProperty({
271
- foo: assignOidProperty({
272
- bar: 1,
273
- }, 'test/a:1'),
274
- qux: assignOidProperty([
275
- assignOidProperty({
276
- corge: true,
277
- }, 'test/a:2'),
278
- assignOidProperty({
279
- grault: assignOidProperty({
280
- garply: 4,
281
- }, 'test/a:3'),
282
- }, 'test/a:4'),
283
- ], 'test/a:2'),
284
- }, 'test/a');
285
- removeOidPropertiesFromAllSubObjects(initial);
286
- expect(getOid(initial)).toEqual('test/a');
287
- expect(getOid(initial.foo)).toEqual('test/a:1');
288
- expect(getOid(initial.qux)).toEqual('test/a:2');
289
- expect(getOid(initial.qux[0])).toEqual('test/a:2');
290
- expect(getOid(initial.qux[1])).toEqual('test/a:4');
291
- expect(getOid(initial.qux[1].grault)).toEqual('test/a:3');
292
- });
293
- });
294
- it('should handle special characters in document id or collection', () => {
295
- expect(decomposeOid(createOid('test.teesssst/asdf::', 'foo/bar (.) : huh:', 'corge'))).toEqual({
296
- collection: 'test.teesssst/asdf::',
297
- id: 'foo/bar (.) : huh:',
298
- subId: 'corge',
299
- });
300
- });
301
- describe('assigning OIDs to sub-objects', () => {
302
- it('should not assign oids to refs', () => {
303
- const obj = {
304
- foo: {
305
- file: createFileRef('1a'),
306
- },
307
- bar: [createFileRef('2a')],
308
- };
309
- assignOid(obj, 'test/a');
310
- assignOidsToAllSubObjects(obj);
311
- expect(hasOid(obj.foo.file)).toBe(false);
312
- expect(hasOid(obj.bar[0])).toBe(false);
313
- });
314
- });
315
- describe('handling legacy OIDs', () => {
316
- it('should get the root OID for a legacy OID', () => {
317
- expect(getOidRoot('items/clabgyjfh00003968qycsq3ld.inputs.#')).toEqual('items/clabgyjfh00003968qycsq3ld');
318
- });
319
- it('should create sub-ids for legacy OIDs in new format', () => {
320
- expect(createSubOid('items/clabgyjfh00003968qycsq3ld.inputs.#', () => 'pseudorandom')).toEqual('items/clabgyjfh00003968qycsq3ld:pseudorandom');
321
- });
322
- it('should identify new sub-OIDs as related to the legacy root OID', () => {
323
- expect(areOidsRelated('items/clabgyjfh00003968qycsq3ld.inputs.#', 'items/clabgyjfh00003968qycsq3ld:pseudorandom')).toBe(true);
324
- });
325
- it.each([
326
- ['items/clabgyjfh00003968qycsq3ld.inputs.#:baz', true],
327
- // include more unicode chars
328
- ['items/clabgyjfh00003968qycsq3ld\ufea3.inputs\u39fc.#:baz!!!', true],
329
- // not matching new oids
330
- ['items/clabgyjfh00003968qycsq3ld', false],
331
- ['items/clabgyjfh00003968qycsq3ld:baz', false],
332
- ['items/clabgyjfh00003968qycsq3ld:baz1111', false],
333
- ])('matches legacy oids', (oid, match) => {
334
- expect(MATCH_LEGACY_OID_JSON_STRING.test('"' + oid + '"'), oid).toBe(match);
335
- // regex are stateful 🙄
336
- MATCH_LEGACY_OID_JSON_STRING.lastIndex = 0;
337
- });
338
- it.each([
339
- [
340
- { op: 'delete', oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz' },
341
- { op: 'delete', oid: 'items/clabgyjfh00003968qycsq3ld:baz' },
342
- ],
343
- [
344
- {
345
- op: 'list-push',
346
- oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
347
- value: {
348
- '@@type': 'ref',
349
- id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
350
- },
351
- },
352
- {
353
- op: 'list-push',
354
- oid: 'items/clabgyjfh00003968qycsq3ld:baz',
355
- value: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
356
- },
357
- ],
358
- [
359
- {
360
- op: 'list-remove',
361
- oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
362
- value: {
363
- '@@type': 'ref',
364
- id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
365
- },
366
- },
367
- {
368
- op: 'list-remove',
369
- oid: 'items/clabgyjfh00003968qycsq3ld:baz',
370
- value: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
371
- },
372
- ],
373
- [
374
- {
375
- oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
376
- timestamp: '2021-03-04T21:00:00.000Z',
377
- snapshot: {
378
- foo: 1,
379
- bar: {
380
- '@@type': 'ref',
381
- id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
382
- },
383
- },
384
- },
385
- {
386
- oid: 'items/clabgyjfh00003968qycsq3ld:baz',
387
- timestamp: '2021-03-04T21:00:00.000Z',
388
- snapshot: {
389
- foo: 1,
390
- bar: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
391
- },
392
- },
393
- ],
394
- [
395
- { oid: 'test thing/what if.boo.blah so what:fajsdfj' },
396
- { oid: 'test thing/what if:fajsdfj' },
397
- ],
398
- ])('should replace legacy OIDs in a JSON string with new OIDs', (from, to) => {
399
- expect(replaceLegacyOidsInObject(from), JSON.stringify(from)).toEqual(to);
400
- });
401
- });
265
+ `);
266
+ // extra check needed for array since it doesn't serialize in the snapshot
267
+ expect(maybeGetOidProperty(initial.qux)).toBe('test/a:2');
268
+ });
269
+ it('should transfer assigned OID properties to the memory system', () => {
270
+ const initial = assignOidProperty({
271
+ foo: assignOidProperty({
272
+ bar: 1,
273
+ }, 'test/a:1'),
274
+ qux: assignOidProperty([
275
+ assignOidProperty({
276
+ corge: true,
277
+ }, 'test/a:2'),
278
+ assignOidProperty({
279
+ grault: assignOidProperty({
280
+ garply: 4,
281
+ }, 'test/a:3'),
282
+ }, 'test/a:4'),
283
+ ], 'test/a:2'),
284
+ }, 'test/a');
285
+ removeOidPropertiesFromAllSubObjects(initial);
286
+ expect(getOid(initial)).toEqual('test/a');
287
+ expect(getOid(initial.foo)).toEqual('test/a:1');
288
+ expect(getOid(initial.qux)).toEqual('test/a:2');
289
+ expect(getOid(initial.qux[0])).toEqual('test/a:2');
290
+ expect(getOid(initial.qux[1])).toEqual('test/a:4');
291
+ expect(getOid(initial.qux[1].grault)).toEqual('test/a:3');
292
+ });
293
+ });
294
+ it('should handle special characters in document id or collection', () => {
295
+ expect(decomposeOid(createOid('test.teesssst/asdf::', 'foo/bar (.) : huh:', 'corge'))).toEqual({
296
+ collection: 'test.teesssst/asdf::',
297
+ id: 'foo/bar (.) : huh:',
298
+ subId: 'corge',
299
+ });
300
+ });
301
+ describe('assigning OIDs to sub-objects', () => {
302
+ it('should not assign oids to refs', () => {
303
+ const obj = {
304
+ foo: {
305
+ file: createFileRef('1a'),
306
+ },
307
+ bar: [createFileRef('2a')],
308
+ };
309
+ assignOid(obj, 'test/a');
310
+ assignOidsToAllSubObjects(obj);
311
+ expect(hasOid(obj.foo.file)).toBe(false);
312
+ expect(hasOid(obj.bar[0])).toBe(false);
313
+ });
314
+ });
315
+ describe('handling legacy OIDs', () => {
316
+ it('should get the root OID for a legacy OID', () => {
317
+ expect(getOidRoot('items/clabgyjfh00003968qycsq3ld.inputs.#')).toEqual('items/clabgyjfh00003968qycsq3ld');
318
+ });
319
+ it('should create sub-ids for legacy OIDs in new format', () => {
320
+ expect(createSubOid('items/clabgyjfh00003968qycsq3ld.inputs.#', () => 'pseudorandom')).toEqual('items/clabgyjfh00003968qycsq3ld:pseudorandom');
321
+ });
322
+ it('should identify new sub-OIDs as related to the legacy root OID', () => {
323
+ expect(areOidsRelated('items/clabgyjfh00003968qycsq3ld.inputs.#', 'items/clabgyjfh00003968qycsq3ld:pseudorandom')).toBe(true);
324
+ });
325
+ it.each([
326
+ ['items/clabgyjfh00003968qycsq3ld.inputs.#:baz', true],
327
+ // include more unicode chars
328
+ ['items/clabgyjfh00003968qycsq3ld\ufea3.inputs\u39fc.#:baz!!!', true],
329
+ // not matching new oids
330
+ ['items/clabgyjfh00003968qycsq3ld', false],
331
+ ['items/clabgyjfh00003968qycsq3ld:baz', false],
332
+ ['items/clabgyjfh00003968qycsq3ld:baz1111', false],
333
+ ])('matches legacy oids', (oid, match) => {
334
+ expect(MATCH_LEGACY_OID_JSON_STRING.test('"' + oid + '"'), oid).toBe(match);
335
+ // regex are stateful 🙄
336
+ MATCH_LEGACY_OID_JSON_STRING.lastIndex = 0;
337
+ });
338
+ it.each([
339
+ [
340
+ { op: 'delete', oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz' },
341
+ { op: 'delete', oid: 'items/clabgyjfh00003968qycsq3ld:baz' },
342
+ ],
343
+ [
344
+ {
345
+ op: 'list-push',
346
+ oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
347
+ value: {
348
+ '@@type': 'ref',
349
+ id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
350
+ },
351
+ },
352
+ {
353
+ op: 'list-push',
354
+ oid: 'items/clabgyjfh00003968qycsq3ld:baz',
355
+ value: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
356
+ },
357
+ ],
358
+ [
359
+ {
360
+ op: 'list-remove',
361
+ oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
362
+ value: {
363
+ '@@type': 'ref',
364
+ id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
365
+ },
366
+ },
367
+ {
368
+ op: 'list-remove',
369
+ oid: 'items/clabgyjfh00003968qycsq3ld:baz',
370
+ value: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
371
+ },
372
+ ],
373
+ [
374
+ {
375
+ oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
376
+ timestamp: '2021-03-04T21:00:00.000Z',
377
+ snapshot: {
378
+ foo: 1,
379
+ bar: {
380
+ '@@type': 'ref',
381
+ id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
382
+ },
383
+ },
384
+ },
385
+ {
386
+ oid: 'items/clabgyjfh00003968qycsq3ld:baz',
387
+ timestamp: '2021-03-04T21:00:00.000Z',
388
+ snapshot: {
389
+ foo: 1,
390
+ bar: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
391
+ },
392
+ },
393
+ ],
394
+ [
395
+ { oid: 'test thing/what if.boo.blah so what:fajsdfj' },
396
+ { oid: 'test thing/what if:fajsdfj' },
397
+ ],
398
+ ])('should replace legacy OIDs in a JSON string with new OIDs', (from, to) => {
399
+ expect(replaceLegacyOidsInObject(from), JSON.stringify(from)).toEqual(to);
400
+ });
401
+ });
402
402
  //# sourceMappingURL=oids.test.js.map