@verdant-web/common 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/EventSubscriber.d.ts +17 -17
- package/dist/cjs/EventSubscriber.js +66 -66
- package/dist/cjs/baseline.d.ts +5 -5
- package/dist/cjs/baseline.js +2 -2
- package/dist/cjs/batching.d.ts +41 -41
- package/dist/cjs/batching.js +88 -88
- package/dist/cjs/files.d.ts +19 -19
- package/dist/cjs/files.js +18 -18
- package/dist/cjs/index.d.ts +18 -18
- package/dist/cjs/index.js +35 -35
- package/dist/cjs/indexes.d.ts +14 -14
- package/dist/cjs/indexes.js +115 -115
- package/dist/cjs/indexes.test.d.ts +1 -1
- package/dist/cjs/indexes.test.js +127 -127
- package/dist/cjs/migration.d.ts +98 -98
- package/dist/cjs/migration.js +127 -127
- package/dist/cjs/oids.d.ts +87 -87
- package/dist/cjs/oids.js +374 -374
- package/dist/cjs/oids.test.d.ts +1 -1
- package/dist/cjs/oids.test.js +245 -245
- package/dist/cjs/operation.d.ts +139 -139
- package/dist/cjs/operation.js +532 -532
- package/dist/cjs/operation.test.d.ts +1 -1
- package/dist/cjs/operation.test.js +484 -484
- package/dist/cjs/patch.d.ts +26 -26
- package/dist/cjs/patch.js +226 -226
- package/dist/cjs/presence.d.ts +27 -27
- package/dist/cjs/presence.js +2 -2
- package/dist/cjs/protocol.d.ts +145 -145
- package/dist/cjs/protocol.js +3 -3
- package/dist/cjs/refs.d.ts +5 -5
- package/dist/cjs/refs.js +21 -21
- package/dist/cjs/replica.d.ts +28 -28
- package/dist/cjs/replica.js +28 -28
- package/dist/cjs/schema/defaults.d.ts +4 -4
- package/dist/cjs/schema/defaults.js +71 -71
- package/dist/cjs/schema/defaults.test.d.ts +1 -1
- package/dist/cjs/schema/defaults.test.js +20 -20
- package/dist/cjs/schema/index.d.ts +8 -8
- package/dist/cjs/schema/index.js +28 -28
- package/dist/cjs/schema/indexFilters.d.ts +6 -6
- package/dist/cjs/schema/indexFilters.js +30 -30
- package/dist/cjs/schema/types/collection.d.ts +51 -51
- package/dist/cjs/schema/types/collection.js +2 -2
- package/dist/cjs/schema/types/compounds.d.ts +12 -12
- package/dist/cjs/schema/types/compounds.js +2 -2
- package/dist/cjs/schema/types/fields.d.ts +59 -59
- package/dist/cjs/schema/types/fields.js +2 -2
- package/dist/cjs/schema/types/filters.d.ts +29 -29
- package/dist/cjs/schema/types/filters.js +2 -2
- package/dist/cjs/schema/types/shapes.d.ts +21 -21
- package/dist/cjs/schema/types/shapes.js +2 -2
- package/dist/cjs/schema/types/synthetics.d.ts +28 -28
- package/dist/cjs/schema/types/synthetics.js +2 -2
- package/dist/cjs/schema/types.d.ts +18 -18
- package/dist/cjs/schema/types.js +22 -22
- package/dist/cjs/timestamp.d.ts +48 -48
- package/dist/cjs/timestamp.js +243 -243
- package/dist/cjs/timestamp.test.d.ts +1 -1
- package/dist/cjs/timestamp.test.js +93 -93
- package/dist/cjs/undo.d.ts +3 -3
- package/dist/cjs/undo.js +198 -198
- package/dist/cjs/utils.d.ts +15 -15
- package/dist/cjs/utils.js +127 -127
- package/dist/cjs/utils.test.d.ts +1 -1
- package/dist/cjs/utils.test.js +36 -36
- package/dist/esm/EventSubscriber.d.ts +17 -17
- package/dist/esm/EventSubscriber.js +62 -62
- package/dist/esm/baseline.d.ts +5 -5
- package/dist/esm/baseline.js +1 -1
- package/dist/esm/batching.d.ts +41 -41
- package/dist/esm/batching.js +83 -83
- package/dist/esm/files.d.ts +19 -19
- package/dist/esm/files.js +12 -12
- package/dist/esm/index.d.ts +18 -18
- package/dist/esm/index.js +15 -15
- package/dist/esm/indexes.d.ts +14 -14
- package/dist/esm/indexes.js +105 -105
- package/dist/esm/indexes.test.d.ts +1 -1
- package/dist/esm/indexes.test.js +125 -125
- package/dist/esm/migration.d.ts +98 -98
- package/dist/esm/migration.js +121 -121
- package/dist/esm/oids.d.ts +87 -87
- package/dist/esm/oids.js +347 -347
- package/dist/esm/oids.test.d.ts +1 -1
- package/dist/esm/oids.test.js +243 -243
- package/dist/esm/operation.d.ts +139 -139
- package/dist/esm/operation.js +517 -517
- package/dist/esm/operation.test.d.ts +1 -1
- package/dist/esm/operation.test.js +482 -482
- package/dist/esm/patch.d.ts +26 -26
- package/dist/esm/patch.js +222 -222
- package/dist/esm/presence.d.ts +27 -27
- package/dist/esm/presence.js +1 -1
- package/dist/esm/protocol.d.ts +145 -145
- package/dist/esm/protocol.js +2 -2
- package/dist/esm/refs.d.ts +5 -5
- package/dist/esm/refs.js +16 -16
- package/dist/esm/replica.d.ts +28 -28
- package/dist/esm/replica.js +25 -25
- package/dist/esm/schema/defaults.d.ts +4 -4
- package/dist/esm/schema/defaults.js +65 -65
- package/dist/esm/schema/defaults.test.d.ts +1 -1
- package/dist/esm/schema/defaults.test.js +18 -18
- package/dist/esm/schema/index.d.ts +8 -8
- package/dist/esm/schema/index.js +9 -9
- package/dist/esm/schema/indexFilters.d.ts +6 -6
- package/dist/esm/schema/indexFilters.js +22 -22
- package/dist/esm/schema/types/collection.d.ts +51 -51
- package/dist/esm/schema/types/collection.js +1 -1
- package/dist/esm/schema/types/compounds.d.ts +12 -12
- package/dist/esm/schema/types/compounds.js +1 -1
- package/dist/esm/schema/types/fields.d.ts +59 -59
- package/dist/esm/schema/types/fields.js +1 -1
- package/dist/esm/schema/types/filters.d.ts +29 -29
- package/dist/esm/schema/types/filters.js +1 -1
- package/dist/esm/schema/types/shapes.d.ts +21 -21
- package/dist/esm/schema/types/shapes.js +1 -1
- package/dist/esm/schema/types/synthetics.d.ts +28 -28
- package/dist/esm/schema/types/synthetics.js +1 -1
- package/dist/esm/schema/types.d.ts +18 -18
- package/dist/esm/schema/types.js +6 -6
- package/dist/esm/timestamp.d.ts +48 -48
- package/dist/esm/timestamp.js +228 -228
- package/dist/esm/timestamp.test.d.ts +1 -1
- package/dist/esm/timestamp.test.js +91 -91
- package/dist/esm/undo.d.ts +3 -3
- package/dist/esm/undo.js +194 -194
- package/dist/esm/utils.d.ts +15 -15
- package/dist/esm/utils.js +113 -113
- package/dist/esm/utils.test.d.ts +1 -1
- package/dist/esm/utils.test.js +34 -34
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/files.test.d.ts +0 -1
- package/dist/cjs/files.test.js +0 -81
- package/dist/cjs/files.test.js.map +0 -1
- package/dist/esm/files.test.d.ts +0 -1
- package/dist/esm/files.test.js +0 -79
- package/dist/esm/files.test.js.map +0 -1
package/dist/esm/oids.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/esm/oids.test.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createFileRef } from './files.js';
|
|
3
|
-
import { assignOid, assignOidPropertiesToAllSubObjects, assignOidProperty, assignOidsToAllSubObjects, createOid, decomposeOid, getOid, getOidRange, hasOid, maybeGetOidProperty, normalize, normalizeFirstLevel, removeOidPropertiesFromAllSubObjects, } 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.foo:0',
|
|
33
|
-
},
|
|
34
|
-
qux: {
|
|
35
|
-
'@@type': 'ref',
|
|
36
|
-
id: 'test/a.qux:2',
|
|
37
|
-
},
|
|
38
|
-
}, 'test/a'));
|
|
39
|
-
expect(result.get('test/a.foo:0')).toEqual(assignOid({
|
|
40
|
-
bar: 1,
|
|
41
|
-
baz: {
|
|
42
|
-
'@@type': 'ref',
|
|
43
|
-
id: 'test/a.foo.baz:1',
|
|
44
|
-
},
|
|
45
|
-
}, 'test/a.foo:0'));
|
|
46
|
-
expect(result.get('test/a.foo.baz:1')).toEqual(assignOid([2, 3], 'test/a.foo.baz:1'));
|
|
47
|
-
expect(result.get('test/a.qux:2')).toEqual(assignOid([
|
|
48
|
-
{
|
|
49
|
-
'@@type': 'ref',
|
|
50
|
-
id: 'test/a.qux.#:3',
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
'@@type': 'ref',
|
|
54
|
-
id: 'test/a.qux.#:4',
|
|
55
|
-
},
|
|
56
|
-
], 'test/a.qux:2'));
|
|
57
|
-
expect(result.get('test/a.qux.#:3')).toEqual(assignOid({
|
|
58
|
-
corge: true,
|
|
59
|
-
}, 'test/a.qux.#:3'));
|
|
60
|
-
expect(result.get('test/a.qux.#:4')).toEqual(assignOid({
|
|
61
|
-
grault: {
|
|
62
|
-
'@@type': 'ref',
|
|
63
|
-
id: 'test/a.qux.#.grault:5',
|
|
64
|
-
},
|
|
65
|
-
}, 'test/a.qux.#:4'));
|
|
66
|
-
expect(result.get('test/a.qux.#.grault:5')).toEqual(assignOid({
|
|
67
|
-
garply: 4,
|
|
68
|
-
}, 'test/a.qux.#.grault: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.foo:0',
|
|
90
|
-
},
|
|
91
|
-
qux: {
|
|
92
|
-
'@@type': 'ref',
|
|
93
|
-
id: 'test/a.qux:1',
|
|
94
|
-
},
|
|
95
|
-
}, 'test/a'));
|
|
96
|
-
expect(result.get('test/a.foo:0')).toEqual(assignOid({
|
|
97
|
-
bar: 1,
|
|
98
|
-
file: {
|
|
99
|
-
'@@type': 'file',
|
|
100
|
-
id: 'abcd123',
|
|
101
|
-
},
|
|
102
|
-
}, 'test/a.foo:0'));
|
|
103
|
-
expect(result.get('test/a.qux:1')).toEqual(assignOid([
|
|
104
|
-
{
|
|
105
|
-
'@@type': 'file',
|
|
106
|
-
id: 'efgh456',
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
'@@type': 'file',
|
|
110
|
-
id: 'ijkl789',
|
|
111
|
-
},
|
|
112
|
-
], 'test/a.qux: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 { assignOid, assignOidPropertiesToAllSubObjects, assignOidProperty, assignOidsToAllSubObjects, createOid, decomposeOid, getOid, getOidRange, hasOid, maybeGetOidProperty, normalize, normalizeFirstLevel, removeOidPropertiesFromAllSubObjects, } 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.foo:0',
|
|
33
|
+
},
|
|
34
|
+
qux: {
|
|
35
|
+
'@@type': 'ref',
|
|
36
|
+
id: 'test/a.qux:2',
|
|
37
|
+
},
|
|
38
|
+
}, 'test/a'));
|
|
39
|
+
expect(result.get('test/a.foo:0')).toEqual(assignOid({
|
|
40
|
+
bar: 1,
|
|
41
|
+
baz: {
|
|
42
|
+
'@@type': 'ref',
|
|
43
|
+
id: 'test/a.foo.baz:1',
|
|
44
|
+
},
|
|
45
|
+
}, 'test/a.foo:0'));
|
|
46
|
+
expect(result.get('test/a.foo.baz:1')).toEqual(assignOid([2, 3], 'test/a.foo.baz:1'));
|
|
47
|
+
expect(result.get('test/a.qux:2')).toEqual(assignOid([
|
|
48
|
+
{
|
|
49
|
+
'@@type': 'ref',
|
|
50
|
+
id: 'test/a.qux.#:3',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
'@@type': 'ref',
|
|
54
|
+
id: 'test/a.qux.#:4',
|
|
55
|
+
},
|
|
56
|
+
], 'test/a.qux:2'));
|
|
57
|
+
expect(result.get('test/a.qux.#:3')).toEqual(assignOid({
|
|
58
|
+
corge: true,
|
|
59
|
+
}, 'test/a.qux.#:3'));
|
|
60
|
+
expect(result.get('test/a.qux.#:4')).toEqual(assignOid({
|
|
61
|
+
grault: {
|
|
62
|
+
'@@type': 'ref',
|
|
63
|
+
id: 'test/a.qux.#.grault:5',
|
|
64
|
+
},
|
|
65
|
+
}, 'test/a.qux.#:4'));
|
|
66
|
+
expect(result.get('test/a.qux.#.grault:5')).toEqual(assignOid({
|
|
67
|
+
garply: 4,
|
|
68
|
+
}, 'test/a.qux.#.grault: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.foo:0',
|
|
90
|
+
},
|
|
91
|
+
qux: {
|
|
92
|
+
'@@type': 'ref',
|
|
93
|
+
id: 'test/a.qux:1',
|
|
94
|
+
},
|
|
95
|
+
}, 'test/a'));
|
|
96
|
+
expect(result.get('test/a.foo:0')).toEqual(assignOid({
|
|
97
|
+
bar: 1,
|
|
98
|
+
file: {
|
|
99
|
+
'@@type': 'file',
|
|
100
|
+
id: 'abcd123',
|
|
101
|
+
},
|
|
102
|
+
}, 'test/a.foo:0'));
|
|
103
|
+
expect(result.get('test/a.qux:1')).toEqual(assignOid([
|
|
104
|
+
{
|
|
105
|
+
'@@type': 'file',
|
|
106
|
+
id: 'efgh456',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
'@@type': 'file',
|
|
110
|
+
id: 'ijkl789',
|
|
111
|
+
},
|
|
112
|
+
], 'test/a.qux: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,59 +148,59 @@ describe('normalizing the first level of an object', () => {
|
|
|
148
148
|
"id": "test/a.qux:2",
|
|
149
149
|
},
|
|
150
150
|
}
|
|
151
|
-
`);
|
|
152
|
-
expect(result.get('test/a:0')).toMatchInlineSnapshot('undefined');
|
|
153
|
-
expect(result.get('test/a:1')).toBeUndefined();
|
|
154
|
-
expect(result.get('test/a:2')).toMatchInlineSnapshot('undefined');
|
|
155
|
-
expect(result.get('test/a:3')).toBeUndefined();
|
|
156
|
-
expect(result.get('test/a:4')).toBeUndefined();
|
|
157
|
-
expect(result.get('test/a:5')).toBeUndefined();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe('computing a range of oids for a whole object set', () => {
|
|
161
|
-
function isWithin(oid, start, end) {
|
|
162
|
-
return oid >= start && oid <= end;
|
|
163
|
-
}
|
|
164
|
-
it('should include the root object and any possible sub object oid', () => {
|
|
165
|
-
const [start, end] = getOidRange('test/a');
|
|
166
|
-
expect(start).toEqual('test/a');
|
|
167
|
-
expect(end).toEqual('test/a:\uffff');
|
|
168
|
-
expect(start < end).toBe(true);
|
|
169
|
-
expect(isWithin('test/a', start, end)).toBe(true);
|
|
170
|
-
expect(isWithin('test/a:0', start, end)).toBe(true);
|
|
171
|
-
expect(isWithin('test/a:1', start, end)).toBe(true);
|
|
172
|
-
expect(isWithin('test/a:zzzzzzzzzzzzzzzzzzzzzzz', start, end)).toBe(true);
|
|
173
|
-
expect(isWithin('test/a:\uffff', start, end)).toBe(true);
|
|
174
|
-
expect(isWithin('test1/a', start, end)).toBe(false);
|
|
175
|
-
expect(isWithin('test/b', start, end)).toBe(false);
|
|
176
|
-
expect(isWithin('test/ ', start, end)).toBe(false);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
describe('assigning OIDs as properties', () => {
|
|
180
|
-
it('should assign to all sub-objects', () => {
|
|
181
|
-
let i = 0;
|
|
182
|
-
function createSubId() {
|
|
183
|
-
return (i++).toString();
|
|
184
|
-
}
|
|
185
|
-
const initial = {
|
|
186
|
-
foo: {
|
|
187
|
-
bar: 1,
|
|
188
|
-
baz: [2, 3],
|
|
189
|
-
},
|
|
190
|
-
qux: [
|
|
191
|
-
{
|
|
192
|
-
corge: true,
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
grault: {
|
|
196
|
-
garply: 4,
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
};
|
|
201
|
-
assignOid(initial, 'test/a');
|
|
202
|
-
assignOidsToAllSubObjects(initial, createSubId);
|
|
203
|
-
assignOidPropertiesToAllSubObjects(initial);
|
|
151
|
+
`);
|
|
152
|
+
expect(result.get('test/a:0')).toMatchInlineSnapshot('undefined');
|
|
153
|
+
expect(result.get('test/a:1')).toBeUndefined();
|
|
154
|
+
expect(result.get('test/a:2')).toMatchInlineSnapshot('undefined');
|
|
155
|
+
expect(result.get('test/a:3')).toBeUndefined();
|
|
156
|
+
expect(result.get('test/a:4')).toBeUndefined();
|
|
157
|
+
expect(result.get('test/a:5')).toBeUndefined();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
describe('computing a range of oids for a whole object set', () => {
|
|
161
|
+
function isWithin(oid, start, end) {
|
|
162
|
+
return oid >= start && oid <= end;
|
|
163
|
+
}
|
|
164
|
+
it('should include the root object and any possible sub object oid', () => {
|
|
165
|
+
const [start, end] = getOidRange('test/a');
|
|
166
|
+
expect(start).toEqual('test/a');
|
|
167
|
+
expect(end).toEqual('test/a:\uffff');
|
|
168
|
+
expect(start < end).toBe(true);
|
|
169
|
+
expect(isWithin('test/a', start, end)).toBe(true);
|
|
170
|
+
expect(isWithin('test/a:0', start, end)).toBe(true);
|
|
171
|
+
expect(isWithin('test/a:1', start, end)).toBe(true);
|
|
172
|
+
expect(isWithin('test/a:zzzzzzzzzzzzzzzzzzzzzzz', start, end)).toBe(true);
|
|
173
|
+
expect(isWithin('test/a:\uffff', start, end)).toBe(true);
|
|
174
|
+
expect(isWithin('test1/a', start, end)).toBe(false);
|
|
175
|
+
expect(isWithin('test/b', start, end)).toBe(false);
|
|
176
|
+
expect(isWithin('test/ ', start, end)).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
describe('assigning OIDs as properties', () => {
|
|
180
|
+
it('should assign to all sub-objects', () => {
|
|
181
|
+
let i = 0;
|
|
182
|
+
function createSubId() {
|
|
183
|
+
return (i++).toString();
|
|
184
|
+
}
|
|
185
|
+
const initial = {
|
|
186
|
+
foo: {
|
|
187
|
+
bar: 1,
|
|
188
|
+
baz: [2, 3],
|
|
189
|
+
},
|
|
190
|
+
qux: [
|
|
191
|
+
{
|
|
192
|
+
corge: true,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
grault: {
|
|
196
|
+
garply: 4,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
assignOid(initial, 'test/a');
|
|
202
|
+
assignOidsToAllSubObjects(initial, createSubId);
|
|
203
|
+
assignOidPropertiesToAllSubObjects(initial);
|
|
204
204
|
expect(initial).toMatchInlineSnapshot(`
|
|
205
205
|
{
|
|
206
206
|
"@@id": "test/a",
|
|
@@ -226,55 +226,55 @@ describe('assigning OIDs as properties', () => {
|
|
|
226
226
|
},
|
|
227
227
|
],
|
|
228
228
|
}
|
|
229
|
-
`);
|
|
230
|
-
// extra check needed for array since it doesn't serialize in the snapshot
|
|
231
|
-
expect(maybeGetOidProperty(initial.qux)).toBe('test/a.qux:2');
|
|
232
|
-
});
|
|
233
|
-
it('should transfer assigned OID properties to the memory system', () => {
|
|
234
|
-
const initial = assignOidProperty({
|
|
235
|
-
foo: assignOidProperty({
|
|
236
|
-
bar: 1,
|
|
237
|
-
}, 'test/a.foo:1'),
|
|
238
|
-
qux: assignOidProperty([
|
|
239
|
-
assignOidProperty({
|
|
240
|
-
corge: true,
|
|
241
|
-
}, 'test/a.qux.#:2'),
|
|
242
|
-
assignOidProperty({
|
|
243
|
-
grault: assignOidProperty({
|
|
244
|
-
garply: 4,
|
|
245
|
-
}, 'test/a.qux.#.grault:3'),
|
|
246
|
-
}, 'test/a.qux.#:4'),
|
|
247
|
-
], 'test/a.qux:2'),
|
|
248
|
-
}, 'test/a');
|
|
249
|
-
removeOidPropertiesFromAllSubObjects(initial);
|
|
250
|
-
expect(getOid(initial)).toEqual('test/a');
|
|
251
|
-
expect(getOid(initial.foo)).toEqual('test/a.foo:1');
|
|
252
|
-
expect(getOid(initial.qux)).toEqual('test/a.qux:2');
|
|
253
|
-
expect(getOid(initial.qux[0])).toEqual('test/a.qux.#:2');
|
|
254
|
-
expect(getOid(initial.qux[1])).toEqual('test/a.qux.#:4');
|
|
255
|
-
expect(getOid(initial.qux[1].grault)).toEqual('test/a.qux.#.grault:3');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
it('should handle special characters in document id or collection', () => {
|
|
259
|
-
expect(decomposeOid(createOid('test.teesssst/asdf::', 'foo/bar (.) : huh:', ['baz?.quoo:/', 'qux'], 'corge'))).toEqual({
|
|
260
|
-
collection: 'test.teesssst/asdf::',
|
|
261
|
-
id: 'foo/bar (.) : huh:',
|
|
262
|
-
keyPath: ['baz?.quoo:/', 'qux'],
|
|
263
|
-
subId: 'corge',
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
describe('assigning OIDs to sub-objects', () => {
|
|
267
|
-
it('should not assign oids to refs', () => {
|
|
268
|
-
const obj = {
|
|
269
|
-
foo: {
|
|
270
|
-
file: createFileRef('1a'),
|
|
271
|
-
},
|
|
272
|
-
bar: [createFileRef('2a')],
|
|
273
|
-
};
|
|
274
|
-
assignOid(obj, 'test/a');
|
|
275
|
-
assignOidsToAllSubObjects(obj);
|
|
276
|
-
expect(hasOid(obj.foo.file)).toBe(false);
|
|
277
|
-
expect(hasOid(obj.bar[0])).toBe(false);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
229
|
+
`);
|
|
230
|
+
// extra check needed for array since it doesn't serialize in the snapshot
|
|
231
|
+
expect(maybeGetOidProperty(initial.qux)).toBe('test/a.qux:2');
|
|
232
|
+
});
|
|
233
|
+
it('should transfer assigned OID properties to the memory system', () => {
|
|
234
|
+
const initial = assignOidProperty({
|
|
235
|
+
foo: assignOidProperty({
|
|
236
|
+
bar: 1,
|
|
237
|
+
}, 'test/a.foo:1'),
|
|
238
|
+
qux: assignOidProperty([
|
|
239
|
+
assignOidProperty({
|
|
240
|
+
corge: true,
|
|
241
|
+
}, 'test/a.qux.#:2'),
|
|
242
|
+
assignOidProperty({
|
|
243
|
+
grault: assignOidProperty({
|
|
244
|
+
garply: 4,
|
|
245
|
+
}, 'test/a.qux.#.grault:3'),
|
|
246
|
+
}, 'test/a.qux.#:4'),
|
|
247
|
+
], 'test/a.qux:2'),
|
|
248
|
+
}, 'test/a');
|
|
249
|
+
removeOidPropertiesFromAllSubObjects(initial);
|
|
250
|
+
expect(getOid(initial)).toEqual('test/a');
|
|
251
|
+
expect(getOid(initial.foo)).toEqual('test/a.foo:1');
|
|
252
|
+
expect(getOid(initial.qux)).toEqual('test/a.qux:2');
|
|
253
|
+
expect(getOid(initial.qux[0])).toEqual('test/a.qux.#:2');
|
|
254
|
+
expect(getOid(initial.qux[1])).toEqual('test/a.qux.#:4');
|
|
255
|
+
expect(getOid(initial.qux[1].grault)).toEqual('test/a.qux.#.grault:3');
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
it('should handle special characters in document id or collection', () => {
|
|
259
|
+
expect(decomposeOid(createOid('test.teesssst/asdf::', 'foo/bar (.) : huh:', ['baz?.quoo:/', 'qux'], 'corge'))).toEqual({
|
|
260
|
+
collection: 'test.teesssst/asdf::',
|
|
261
|
+
id: 'foo/bar (.) : huh:',
|
|
262
|
+
keyPath: ['baz?.quoo:/', 'qux'],
|
|
263
|
+
subId: 'corge',
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
describe('assigning OIDs to sub-objects', () => {
|
|
267
|
+
it('should not assign oids to refs', () => {
|
|
268
|
+
const obj = {
|
|
269
|
+
foo: {
|
|
270
|
+
file: createFileRef('1a'),
|
|
271
|
+
},
|
|
272
|
+
bar: [createFileRef('2a')],
|
|
273
|
+
};
|
|
274
|
+
assignOid(obj, 'test/a');
|
|
275
|
+
assignOidsToAllSubObjects(obj);
|
|
276
|
+
expect(hasOid(obj.foo.file)).toBe(false);
|
|
277
|
+
expect(hasOid(obj.bar[0])).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
280
|
//# sourceMappingURL=oids.test.js.map
|