@livestore/common 0.0.58-dev.1 → 0.0.58-dev.10
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/.tsbuildinfo +1 -1
- package/dist/adapter-types.d.ts +48 -6
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +16 -1
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.js.map +1 -1
- package/dist/derived-mutations.d.ts +5 -5
- package/dist/derived-mutations.d.ts.map +1 -1
- package/dist/derived-mutations.js +4 -2
- package/dist/derived-mutations.js.map +1 -1
- package/dist/derived-mutations.test.js +1 -0
- package/dist/derived-mutations.test.js.map +1 -1
- package/dist/devtools/devtools-bridge.d.ts +1 -1
- package/dist/devtools/devtools-bridge.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.d.ts +91 -13
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +13 -4
- package/dist/devtools/devtools-messages.js.map +1 -1
- package/dist/devtools/index.d.ts +1 -0
- package/dist/devtools/index.d.ts.map +1 -1
- package/dist/devtools/index.js +2 -0
- package/dist/devtools/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/rehydrate-from-mutationlog.d.ts.map +1 -1
- package/dist/rehydrate-from-mutationlog.js +11 -5
- package/dist/rehydrate-from-mutationlog.js.map +1 -1
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/mutations.d.ts +137 -17
- package/dist/schema/mutations.d.ts.map +1 -1
- package/dist/schema/mutations.js +42 -16
- package/dist/schema/mutations.js.map +1 -1
- package/dist/schema/schema-helpers.js +1 -1
- package/dist/schema/schema-helpers.js.map +1 -1
- package/dist/schema/system-tables.d.ts +119 -6
- package/dist/schema/system-tables.d.ts.map +1 -1
- package/dist/schema/system-tables.js +22 -9
- package/dist/schema/system-tables.js.map +1 -1
- package/dist/schema/table-def.d.ts +3 -3
- package/dist/schema/table-def.d.ts.map +1 -1
- package/dist/schema/table-def.js +1 -1
- package/dist/schema/table-def.js.map +1 -1
- package/dist/schema-management/migrations.d.ts +1 -1
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +2 -2
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/sql-queries/sql-queries.d.ts +10 -3
- package/dist/sql-queries/sql-queries.d.ts.map +1 -1
- package/dist/sql-queries/sql-queries.js +8 -7
- package/dist/sql-queries/sql-queries.js.map +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
- package/dist/sql-queries/types.d.ts +2 -2
- package/dist/sql-queries/types.d.ts.map +1 -1
- package/dist/sync/next/compact-events.d.ts +15 -0
- package/dist/sync/next/compact-events.d.ts.map +1 -0
- package/dist/sync/next/compact-events.js +176 -0
- package/dist/sync/next/compact-events.js.map +1 -0
- package/dist/sync/next/facts.d.ts +37 -0
- package/dist/sync/next/facts.d.ts.map +1 -0
- package/dist/sync/next/facts.js +156 -0
- package/dist/sync/next/facts.js.map +1 -0
- package/dist/sync/next/graphology.d.ts +8 -0
- package/dist/sync/next/graphology.d.ts.map +1 -0
- package/dist/sync/next/graphology.js +36 -0
- package/dist/sync/next/graphology.js.map +1 -0
- package/dist/sync/next/graphology_.d.ts +3 -0
- package/dist/sync/next/graphology_.d.ts.map +1 -0
- package/dist/sync/next/graphology_.js +3 -0
- package/dist/sync/next/graphology_.js.map +1 -0
- package/dist/sync/next/history-dag.d.ts +30 -0
- package/dist/sync/next/history-dag.d.ts.map +1 -0
- package/dist/sync/next/history-dag.js +69 -0
- package/dist/sync/next/history-dag.js.map +1 -0
- package/dist/sync/next/mod.d.ts +5 -0
- package/dist/sync/next/mod.d.ts.map +1 -0
- package/dist/sync/next/mod.js +5 -0
- package/dist/sync/next/mod.js.map +1 -0
- package/dist/sync/next/rebase-events.d.ts +27 -0
- package/dist/sync/next/rebase-events.d.ts.map +1 -0
- package/dist/sync/next/rebase-events.js +41 -0
- package/dist/sync/next/rebase-events.js.map +1 -0
- package/dist/sync/next/test/compact-events.calculator.test.d.ts +2 -0
- package/dist/sync/next/test/compact-events.calculator.test.d.ts.map +1 -0
- package/dist/sync/next/test/compact-events.calculator.test.js +101 -0
- package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -0
- package/dist/sync/next/test/compact-events.test.d.ts +2 -0
- package/dist/sync/next/test/compact-events.test.d.ts.map +1 -0
- package/dist/sync/next/test/compact-events.test.js +201 -0
- package/dist/sync/next/test/compact-events.test.js.map +1 -0
- package/dist/sync/next/test/mod.d.ts +2 -0
- package/dist/sync/next/test/mod.d.ts.map +1 -0
- package/dist/sync/next/test/mod.js +2 -0
- package/dist/sync/next/test/mod.js.map +1 -0
- package/dist/sync/next/test/mutation-fixtures.d.ts +73 -0
- package/dist/sync/next/test/mutation-fixtures.d.ts.map +1 -0
- package/dist/sync/next/test/mutation-fixtures.js +161 -0
- package/dist/sync/next/test/mutation-fixtures.js.map +1 -0
- package/dist/sync/sync.d.ts +19 -6
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js.map +1 -1
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -0
- package/dist/version.js.map +1 -1
- package/package.json +21 -4
- package/src/adapter-types.ts +46 -7
- package/src/bounded-collections.ts +1 -1
- package/src/derived-mutations.test.ts +2 -1
- package/src/derived-mutations.ts +10 -10
- package/src/devtools/devtools-bridge.ts +1 -1
- package/src/devtools/devtools-messages.ts +12 -2
- package/src/devtools/index.ts +2 -0
- package/src/index.ts +6 -0
- package/src/rehydrate-from-mutationlog.ts +16 -7
- package/src/schema/index.ts +4 -3
- package/src/schema/mutations.ts +175 -30
- package/src/schema/schema-helpers.ts +1 -1
- package/src/schema/system-tables.ts +30 -9
- package/src/schema/table-def.ts +3 -3
- package/src/schema-management/migrations.ts +2 -2
- package/src/sql-queries/sql-queries.ts +21 -10
- package/src/sql-queries/sql-query-builder.ts +1 -1
- package/src/sql-queries/types.ts +2 -2
- package/src/sync/next/ambient.d.ts +3 -0
- package/src/sync/next/compact-events.ts +218 -0
- package/src/sync/next/facts.ts +229 -0
- package/src/sync/next/graphology.ts +49 -0
- package/src/sync/next/graphology_.ts +2 -0
- package/src/sync/next/history-dag.ts +109 -0
- package/src/sync/next/mod.ts +4 -0
- package/src/sync/next/rebase-events.ts +97 -0
- package/src/sync/next/test/compact-events.calculator.test.ts +121 -0
- package/src/sync/next/test/compact-events.test.ts +232 -0
- package/src/sync/next/test/mod.ts +1 -0
- package/src/sync/next/test/mutation-fixtures.ts +230 -0
- package/src/sync/sync.ts +30 -6
- package/src/version.ts +10 -0
- package/tsconfig.json +1 -1
@@ -0,0 +1,41 @@
|
|
1
|
+
import { applyFactGroups, factsIntersect, getFactsGroupForMutationArgs, validateFacts, } from './facts.js';
|
2
|
+
export const defaultRebaseFn = ({ pendingLocalEvents }) => {
|
3
|
+
if (pendingLocalEvents.some((_) => _.conflictType === 'missing-requirement')) {
|
4
|
+
throw new Error('missing-requirement conflicts must be resolved before rebasing');
|
5
|
+
}
|
6
|
+
return { rebasedLocalEvents: pendingLocalEvents };
|
7
|
+
};
|
8
|
+
export const rebaseEvents = ({ rebaseFn, pendingLocalEvents, newRemoteEvents, currentFactsSnapshot, }) => {
|
9
|
+
const initialSnapshot = new Map(currentFactsSnapshot);
|
10
|
+
applyFactGroups(newRemoteEvents.map((event) => event.factsGroup), initialSnapshot);
|
11
|
+
// TODO detect and set actual conflict type (overlap or missing-requirement)
|
12
|
+
// TODO bring back validateFacts
|
13
|
+
const { rebasedLocalEvents } = rebaseFn({
|
14
|
+
pendingLocalEvents: pendingLocalEvents.map((pending) => ({
|
15
|
+
...pending,
|
16
|
+
conflictType: 'overlap',
|
17
|
+
conflictingEvents: newRemoteEvents.filter((remote) => factsIntersect(remote.factsGroup.modifySet, pending.factsGroup.modifySet)),
|
18
|
+
})),
|
19
|
+
newRemoteEvents: newRemoteEvents.map((remote) => ({
|
20
|
+
...remote,
|
21
|
+
conflictType: 'overlap',
|
22
|
+
conflictingEvents: pendingLocalEvents.filter((pending) => factsIntersect(pending.factsGroup.modifySet, remote.factsGroup.modifySet)),
|
23
|
+
})),
|
24
|
+
validate: ({ rebasedLocalEvents, mutationDefs }) => validateFacts({
|
25
|
+
factGroups: rebasedLocalEvents.map((event) => getFactsGroupForMutationArgs({
|
26
|
+
factsCallback: mutationDefs[event.mutation].options.facts,
|
27
|
+
args: event.args,
|
28
|
+
currentFacts: new Map(),
|
29
|
+
})),
|
30
|
+
initialSnapshot,
|
31
|
+
}),
|
32
|
+
});
|
33
|
+
const headGlobalId = newRemoteEvents.at(-1).id.global;
|
34
|
+
return rebasedLocalEvents.map((event, index) => ({
|
35
|
+
id: { global: headGlobalId + index + 1, local: 0 },
|
36
|
+
parentId: { global: headGlobalId + index, local: 0 },
|
37
|
+
mutation: event.mutation,
|
38
|
+
args: event.args,
|
39
|
+
}));
|
40
|
+
};
|
41
|
+
//# sourceMappingURL=rebase-events.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rebase-events.js","sourceRoot":"","sources":["../../../src/sync/next/rebase-events.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,cAAc,EAEd,4BAA4B,EAC5B,aAAa,GACd,MAAM,YAAY,CAAA;AAuBnB,MAAM,CAAC,MAAM,eAAe,GAAa,CAAC,EAAE,kBAAkB,EAAE,EAAE,EAAE;IAClE,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,qBAAqB,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAA;IACnF,CAAC;IAED,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,CA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AQ,CAAE,CAAC,OAAO,CAAC,KAAK;gBAC1D,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,YAAY,EAAE,IAAI,GAAG,EAAE;aACxB,CAAC,CACH;YACD,eAAe;SAChB,CAAC;KACL,CAAC,CAAA;IACF,MAAM,YAAY,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,MAAM,CAAA;IAEtD,OAAO,kBAAkB,CAAC,GAAG,CAC3B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CACf,CAAC;QACC,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAoB;QACpE,QAAQ,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,EAAoB;QACtE,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAA6B,CACjC,CAAA;AACH,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"compact-events.calculator.test.d.ts","sourceRoot":"","sources":["../../../../src/sync/next/test/compact-events.calculator.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import { defineMutation } from '@livestore/common/schema';
|
2
|
+
import { Schema } from '@livestore/utils/effect';
|
3
|
+
import { describe, expect, it } from 'vitest';
|
4
|
+
import { compactEvents } from '../compact-events.js';
|
5
|
+
import { historyDagFromNodes } from '../history-dag.js';
|
6
|
+
import { customSerializer } from './compact-events.test.js';
|
7
|
+
import { toEventNodes } from './mutation-fixtures.js';
|
8
|
+
expect.addSnapshotSerializer(customSerializer);
|
9
|
+
const compact = (events) => {
|
10
|
+
const dag = historyDagFromNodes(toEventNodes(events, mutations));
|
11
|
+
const compacted = compactEvents(dag);
|
12
|
+
return Array.from(compacted.dag.nodeEntries())
|
13
|
+
.map((_) => _.attributes)
|
14
|
+
.map(({ factsGroup, ...rest }) => ({ ...rest, facts: factsGroup }))
|
15
|
+
.slice(1);
|
16
|
+
};
|
17
|
+
const facts = {
|
18
|
+
multiplyByZero: `multiplyByZero`,
|
19
|
+
};
|
20
|
+
const mutations = {
|
21
|
+
add: defineMutation('add', Schema.Struct({ value: Schema.Number }), 'UPDATE values SET value = value + $value', {}),
|
22
|
+
multiply: defineMutation('multiply', Schema.Struct({ value: Schema.Number }), 'UPDATE values SET value = value * $value', {
|
23
|
+
facts: ({ value }, currentFacts) => ({
|
24
|
+
modify: {
|
25
|
+
set: value === 0 || currentFacts.has(facts.multiplyByZero) ? [facts.multiplyByZero] : [],
|
26
|
+
unset: value === 0 ? [] : [facts.multiplyByZero],
|
27
|
+
},
|
28
|
+
}),
|
29
|
+
}),
|
30
|
+
// TODO divide by zero
|
31
|
+
};
|
32
|
+
describe('compactEvents calculator', () => {
|
33
|
+
it('1 + 1', () => {
|
34
|
+
const expected = compact([
|
35
|
+
mutations.add({ value: 1 }), // 0
|
36
|
+
mutations.add({ value: 1 }), // 1
|
37
|
+
]);
|
38
|
+
expect(expected).toMatchInlineSnapshot(`
|
39
|
+
[
|
40
|
+
{ id: 0, parentId: -1, mutation: "add", args: { value: 1 }, facts: "" }
|
41
|
+
{ id: 1, parentId: 0, mutation: "add", args: { value: 1 }, facts: "" }
|
42
|
+
]
|
43
|
+
`);
|
44
|
+
});
|
45
|
+
it('2 * 2', () => {
|
46
|
+
const expected = compact([
|
47
|
+
mutations.multiply({ value: 2 }), // 0
|
48
|
+
mutations.multiply({ value: 2 }), // 1
|
49
|
+
]);
|
50
|
+
expect(expected).toMatchInlineSnapshot(`
|
51
|
+
[
|
52
|
+
{ id: 0, parentId: -1, mutation: "multiply", args: { value: 2 }, facts: "?multiplyByZero -multiplyByZero" }
|
53
|
+
{ id: 1, parentId: 0, mutation: "multiply", args: { value: 2 }, facts: "?multiplyByZero -multiplyByZero" }
|
54
|
+
]
|
55
|
+
`);
|
56
|
+
});
|
57
|
+
it('2 * 2 * 0', () => {
|
58
|
+
const expected = compact([
|
59
|
+
mutations.multiply({ value: 2 }), // 0
|
60
|
+
mutations.multiply({ value: 2 }), // 1
|
61
|
+
mutations.multiply({ value: 0 }), // 2
|
62
|
+
]);
|
63
|
+
expect(expected).toMatchInlineSnapshot(`
|
64
|
+
[
|
65
|
+
{ id: 2, parentId: -1, mutation: "multiply", args: { value: 0 }, facts: "+multiplyByZero" }
|
66
|
+
]
|
67
|
+
`);
|
68
|
+
});
|
69
|
+
it('2 * 2 * 0 + 1', () => {
|
70
|
+
const expected = compact([
|
71
|
+
mutations.multiply({ value: 2 }), // 0
|
72
|
+
mutations.multiply({ value: 2 }), // 1
|
73
|
+
mutations.multiply({ value: 0 }), // 2
|
74
|
+
mutations.add({ value: 1 }), // 3
|
75
|
+
]);
|
76
|
+
expect(expected).toMatchInlineSnapshot(`
|
77
|
+
[
|
78
|
+
{ id: 2, parentId: -1, mutation: "multiply", args: { value: 0 }, facts: "+multiplyByZero" }
|
79
|
+
{ id: 3, parentId: 2, mutation: "add", args: { value: 1 }, facts: "" }
|
80
|
+
]
|
81
|
+
`);
|
82
|
+
});
|
83
|
+
it('1 + 2 * 0 * 2 + 1', () => {
|
84
|
+
const expected = compact([
|
85
|
+
mutations.add({ value: 1 }), // 0
|
86
|
+
mutations.multiply({ value: 2 }), // 1
|
87
|
+
mutations.multiply({ value: 0 }), // 2
|
88
|
+
mutations.multiply({ value: 2 }), // 3
|
89
|
+
mutations.add({ value: 1 }), // 4
|
90
|
+
]);
|
91
|
+
expect(expected).toMatchInlineSnapshot(`
|
92
|
+
[
|
93
|
+
{ id: 0, parentId: -1, mutation: "add", args: { value: 1 }, facts: "" }
|
94
|
+
{ id: 2, parentId: 0, mutation: "multiply", args: { value: 0 }, facts: "+multiplyByZero" }
|
95
|
+
{ id: 3, parentId: 2, mutation: "multiply", args: { value: 2 }, facts: "?multiplyByZero +multiplyByZero -multiplyByZero" }
|
96
|
+
{ id: 4, parentId: 3, mutation: "add", args: { value: 1 }, facts: "" }
|
97
|
+
]
|
98
|
+
`);
|
99
|
+
});
|
100
|
+
});
|
101
|
+
//# sourceMappingURL=compact-events.calculator.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"compact-events.calculator.test.js","sourceRoot":"","sources":["../../../../src/sync/next/test/compact-events.calculator.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,MAAM,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAA;AAE9C,MAAM,OAAO,GAAG,CAAC,MAAa,EAAE,EAAE;IAChC,MAAM,GAAG,GAAG,mBAAmB,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;IAChE,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;IAEpC,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;SACxB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;SAClE,KAAK,CAAC,CAAC,CAAC,CAAA;AACb,CAAC,CAAA;AAED,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AC,CAAC,CAAA;IAEF,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC3B,MAAM,QAAQ,GAAG,OAAO,CAAC;YACvB,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI;YACjC,SAAS,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI;YACtC,SAAS,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI;YACtC,SAAS,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI;YACtC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI;SAClC,CAAC,CAAA;QAEF,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;KAOtC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"compact-events.test.d.ts","sourceRoot":"","sources":["../../../../src/sync/next/test/compact-events.test.ts"],"names":[],"mappings":"AA8DA,eAAO,MAAM,gBAAgB,EAKxB,GAAG,CAAA"}
|
@@ -0,0 +1,201 @@
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
2
|
+
import { compactEvents } from '../compact-events.js';
|
3
|
+
import { EMPTY_FACT_VALUE, historyDagFromNodes } from '../history-dag.js';
|
4
|
+
import { mutations, toEventNodes } from './mutation-fixtures.js';
|
5
|
+
const customStringify = (value) => {
|
6
|
+
if (value === null) {
|
7
|
+
return 'null';
|
8
|
+
}
|
9
|
+
const type = typeof value;
|
10
|
+
if (type === 'string') {
|
11
|
+
return JSON.stringify(value);
|
12
|
+
}
|
13
|
+
if (type === 'number' || type === 'boolean') {
|
14
|
+
return String(value);
|
15
|
+
}
|
16
|
+
if (Array.isArray(value)) {
|
17
|
+
const elements = value.map((el) => customStringify(el));
|
18
|
+
return `[${elements.join(', ')}]`;
|
19
|
+
}
|
20
|
+
if (value instanceof Set) {
|
21
|
+
const elements = Array.from(value).map((el) => customStringify(el));
|
22
|
+
return `[${elements.join(', ')}]`;
|
23
|
+
}
|
24
|
+
if (value instanceof Map) {
|
25
|
+
const keys = Array.from(value.keys()).map(customStringify).join(', ');
|
26
|
+
return `[${keys}]`;
|
27
|
+
}
|
28
|
+
if (type === 'object') {
|
29
|
+
const entries = Object.keys(value).map((key) => {
|
30
|
+
const val = value[key];
|
31
|
+
const valStr = key === 'facts'
|
32
|
+
? `"${factsToString(val)}"`
|
33
|
+
: (key === 'id' || key === 'parentId') && Object.keys(val).length === 2 && val.local === 0
|
34
|
+
? val.global
|
35
|
+
: customStringify(val);
|
36
|
+
return `${key}: ${valStr}`;
|
37
|
+
});
|
38
|
+
return `{ ${entries.join(', ')} }`;
|
39
|
+
}
|
40
|
+
return String(value);
|
41
|
+
};
|
42
|
+
const factsToString = (facts) => [
|
43
|
+
factsSetToString(facts.depRequire, '↖'),
|
44
|
+
factsSetToString(facts.depRead, '?'),
|
45
|
+
factsSetToString(facts.modifySet, '+'),
|
46
|
+
factsSetToString(facts.modifyUnset, '-'),
|
47
|
+
]
|
48
|
+
.flat()
|
49
|
+
.join(' ');
|
50
|
+
const factsSetToString = (facts, prefix) => Array.from(facts.entries()).map(([key, value]) => prefix + key + (value === EMPTY_FACT_VALUE ? '' : `=${value}`));
|
51
|
+
export const customSerializer = {
|
52
|
+
test: (val) => Array.isArray(val),
|
53
|
+
print: (val, _serialize) => {
|
54
|
+
return '[\n' + val.map((item) => ' ' + customStringify(item)).join('\n') + '\n]';
|
55
|
+
},
|
56
|
+
};
|
57
|
+
expect.addSnapshotSerializer(customSerializer);
|
58
|
+
const compact = (events) => {
|
59
|
+
const dag = historyDagFromNodes(toEventNodes(events, mutations));
|
60
|
+
const compacted = compactEvents(dag);
|
61
|
+
return Array.from(compacted.dag.nodeEntries())
|
62
|
+
.map((_) => _.attributes)
|
63
|
+
.map(({ factsGroup, ...rest }) => ({ ...rest, facts: factsGroup }))
|
64
|
+
.slice(1);
|
65
|
+
};
|
66
|
+
describe('compactEvents todo app', () => {
|
67
|
+
it('completeTodo', () => {
|
68
|
+
const expected = compact([
|
69
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
70
|
+
mutations.completeTodo({ id: 'A' }), // 1
|
71
|
+
mutations.completeTodo({ id: 'A' }), // 2
|
72
|
+
]);
|
73
|
+
expect(expected).toMatchInlineSnapshot(`
|
74
|
+
[
|
75
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
76
|
+
{ id: 2, parentId: 0, mutation: "completeTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
|
77
|
+
]
|
78
|
+
`);
|
79
|
+
});
|
80
|
+
it('toggleTodo', () => {
|
81
|
+
const expected = compact([
|
82
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
83
|
+
mutations.toggleTodo({ id: 'A' }), // 1
|
84
|
+
mutations.toggleTodo({ id: 'A' }), // 2
|
85
|
+
mutations.toggleTodo({ id: 'A' }), // 3
|
86
|
+
]);
|
87
|
+
expect(expected).toMatchInlineSnapshot(`
|
88
|
+
[
|
89
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
90
|
+
{ id: 1, parentId: 0, mutation: "toggleTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=true" }
|
91
|
+
{ id: 2, parentId: 1, mutation: "toggleTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=false" }
|
92
|
+
{ id: 3, parentId: 2, mutation: "toggleTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=true" }
|
93
|
+
]
|
94
|
+
`);
|
95
|
+
});
|
96
|
+
it('completeTodo / toggleTodo', () => {
|
97
|
+
const expected = compact([
|
98
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
99
|
+
mutations.toggleTodo({ id: 'A' }), // 1
|
100
|
+
mutations.toggleTodo({ id: 'A' }), // 2
|
101
|
+
mutations.completeTodo({ id: 'A' }), // 3
|
102
|
+
mutations.completeTodo({ id: 'A' }), // 4
|
103
|
+
mutations.toggleTodo({ id: 'A' }), // 5
|
104
|
+
]);
|
105
|
+
expect(expected).toMatchInlineSnapshot(`
|
106
|
+
[
|
107
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
108
|
+
{ id: 4, parentId: 0, mutation: "completeTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
|
109
|
+
{ id: 5, parentId: 4, mutation: "toggleTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true ?todo-completed-A +todo-completed-A=false" }
|
110
|
+
]
|
111
|
+
`);
|
112
|
+
});
|
113
|
+
it('readonly setTextTodo', () => {
|
114
|
+
const expected = compact([
|
115
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
116
|
+
mutations.setReadonlyTodo({ id: 'A', readonly: false }), // 1
|
117
|
+
mutations.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 2
|
118
|
+
mutations.setReadonlyTodo({ id: 'A', readonly: true }), // 3
|
119
|
+
]);
|
120
|
+
expect(expected).toMatchInlineSnapshot(`
|
121
|
+
[
|
122
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
123
|
+
{ id: 1, parentId: 0, mutation: "setReadonlyTodo", args: { id: "A", readonly: false }, facts: "↖todo-exists-A +todo-is-writeable-A=true" }
|
124
|
+
{ id: 2, parentId: 1, mutation: "setTextTodo", args: { id: "A", text: "buy soy milk" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-text-updated-A" }
|
125
|
+
{ id: 3, parentId: 2, mutation: "setReadonlyTodo", args: { id: "A", readonly: true }, facts: "↖todo-exists-A +todo-is-writeable-A=false" }
|
126
|
+
]
|
127
|
+
`);
|
128
|
+
});
|
129
|
+
it('readonly setTextTodo 2', () => {
|
130
|
+
const expected = compact([
|
131
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
132
|
+
mutations.setReadonlyTodo({ id: 'A', readonly: false }), // 1
|
133
|
+
mutations.completeTodo({ id: 'A' }), // 2
|
134
|
+
mutations.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 3
|
135
|
+
mutations.setReadonlyTodo({ id: 'A', readonly: true }), // 4
|
136
|
+
]);
|
137
|
+
expect(expected).toMatchInlineSnapshot(`
|
138
|
+
[
|
139
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
140
|
+
{ id: 1, parentId: 0, mutation: "setReadonlyTodo", args: { id: "A", readonly: false }, facts: "↖todo-exists-A +todo-is-writeable-A=true" }
|
141
|
+
{ id: 2, parentId: 1, mutation: "completeTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
|
142
|
+
{ id: 3, parentId: 2, mutation: "setTextTodo", args: { id: "A", text: "buy soy milk" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-text-updated-A" }
|
143
|
+
{ id: 4, parentId: 3, mutation: "setReadonlyTodo", args: { id: "A", readonly: true }, facts: "↖todo-exists-A +todo-is-writeable-A=false" }
|
144
|
+
]
|
145
|
+
`);
|
146
|
+
});
|
147
|
+
it('readonly setTextTodo - should fail', () => {
|
148
|
+
const expected = () => compact([
|
149
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
150
|
+
mutations.setReadonlyTodo({ id: 'A', readonly: false }), // 1
|
151
|
+
mutations.setTextTodo({ id: 'A', text: 'buy soy milk' }), // 2
|
152
|
+
mutations.setReadonlyTodo({ id: 'A', readonly: true }), // 3
|
153
|
+
mutations.setTextTodo({ id: 'A', text: 'buy oat milk' }), // 4
|
154
|
+
]);
|
155
|
+
expect(expected).toThrowErrorMatchingInlineSnapshot(`
|
156
|
+
[Error: Mutation setTextTodo requires facts that have not been set yet.
|
157
|
+
Requires: todo-exists-A, todo-is-writeable-A=true
|
158
|
+
Facts Snapshot: todo-exists-A, todo-is-writeable-A=false, todo-completed-A=false, todo-text-updated-A]
|
159
|
+
`);
|
160
|
+
});
|
161
|
+
it('completeTodos', () => {
|
162
|
+
const expected = compact([
|
163
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
164
|
+
mutations.createTodo({ id: 'B', text: 'buy bread' }), // 1
|
165
|
+
mutations.createTodo({ id: 'C', text: 'buy cheese' }), // 2
|
166
|
+
mutations.completeTodos({ ids: ['A', 'B', 'C'] }), // 3
|
167
|
+
mutations.toggleTodo({ id: 'A' }), // 4
|
168
|
+
mutations.completeTodo({ id: 'A' }), // 5
|
169
|
+
]);
|
170
|
+
expect(expected).toMatchInlineSnapshot(`
|
171
|
+
[
|
172
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
173
|
+
{ id: 1, parentId: 0, mutation: "createTodo", args: { id: "B", text: "buy bread" }, facts: "+todo-exists-B +todo-is-writeable-B=true +todo-completed-B=false" }
|
174
|
+
{ id: 2, parentId: 1, mutation: "createTodo", args: { id: "C", text: "buy cheese" }, facts: "+todo-exists-C +todo-is-writeable-C=true +todo-completed-C=false" }
|
175
|
+
{ id: 3, parentId: 2, mutation: "completeTodos", args: { ids: ["A", "B", "C"] }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true ↖todo-exists-B ↖todo-is-writeable-B=true ↖todo-exists-C ↖todo-is-writeable-C=true +todo-completed-A=true +todo-completed-B=true +todo-completed-C=true" }
|
176
|
+
{ id: 5, parentId: 3, mutation: "completeTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
|
177
|
+
]
|
178
|
+
`);
|
179
|
+
});
|
180
|
+
it('completeTodos 2', () => {
|
181
|
+
const expected = compact([
|
182
|
+
mutations.createTodo({ id: 'A', text: 'buy milk' }), // 0
|
183
|
+
mutations.createTodo({ id: 'B', text: 'buy bread' }), // 1
|
184
|
+
mutations.createTodo({ id: 'C', text: 'buy cheese' }), // 2
|
185
|
+
mutations.toggleTodo({ id: 'A' }), // 3
|
186
|
+
mutations.completeTodos({ ids: ['A', 'B', 'C'] }), // 4
|
187
|
+
mutations.toggleTodo({ id: 'A' }), // 5
|
188
|
+
mutations.completeTodo({ id: 'A' }), // 6
|
189
|
+
]);
|
190
|
+
expect(expected).toMatchInlineSnapshot(`
|
191
|
+
[
|
192
|
+
{ id: 0, parentId: -1, mutation: "createTodo", args: { id: "A", text: "buy milk" }, facts: "+todo-exists-A +todo-is-writeable-A=true +todo-completed-A=false" }
|
193
|
+
{ id: 1, parentId: 0, mutation: "createTodo", args: { id: "B", text: "buy bread" }, facts: "+todo-exists-B +todo-is-writeable-B=true +todo-completed-B=false" }
|
194
|
+
{ id: 2, parentId: 1, mutation: "createTodo", args: { id: "C", text: "buy cheese" }, facts: "+todo-exists-C +todo-is-writeable-C=true +todo-completed-C=false" }
|
195
|
+
{ id: 4, parentId: 2, mutation: "completeTodos", args: { ids: ["A", "B", "C"] }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true ↖todo-exists-B ↖todo-is-writeable-B=true ↖todo-exists-C ↖todo-is-writeable-C=true +todo-completed-A=true +todo-completed-B=true +todo-completed-C=true" }
|
196
|
+
{ id: 6, parentId: 4, mutation: "completeTodo", args: { id: "A" }, facts: "↖todo-exists-A ↖todo-is-writeable-A=true +todo-completed-A=true" }
|
197
|
+
]
|
198
|
+
`);
|
199
|
+
});
|
200
|
+
});
|
201
|
+
//# sourceMappingURL=compact-events.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"compact-events.test.js","sourceRoot":"","sources":["../../../../src/sync/next/test/compact-events.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAEhE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAU,EAAE;IAC7C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAA;IACf,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,KAAK,CAAA;IAEzB,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAA;QACvD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,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AM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;KAQtC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE;QACzB,MAAM,QAAQ,GAAG,OAAO,CAAC;YACvB,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI;YACzD,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,IAAI;YAC1D,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,IAAI;YAC3D,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI;YACvC,SAAS,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI;YACvD,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI;YACvC,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI;SAC1C,CAAC,CAAA;QAEF,MAAM,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;KAQtC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/sync/next/test/mod.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../../src/sync/next/test/mod.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import type { MutationDef } from '../../../schema/mutations.js';
|
2
|
+
import type { HistoryDagNode } from '../history-dag.js';
|
3
|
+
/** Used for conflict detection and event history compaction */
|
4
|
+
export declare const facts: {
|
5
|
+
todoExists: (id: string) => string;
|
6
|
+
todoIsWriteable: (id: string, writeable: boolean) => [string, boolean];
|
7
|
+
todoCompleted: (id: string, completed: boolean) => [string, boolean];
|
8
|
+
todoTextUpdated: (id: string) => string;
|
9
|
+
inputValue: (id: string) => string;
|
10
|
+
};
|
11
|
+
export declare const mutations: {
|
12
|
+
createTodo: MutationDef<"createTodo", {
|
13
|
+
readonly text: string;
|
14
|
+
readonly id: string;
|
15
|
+
}, {
|
16
|
+
readonly text: string;
|
17
|
+
readonly id: string;
|
18
|
+
}>;
|
19
|
+
upsertTodo: MutationDef<"upsertTodo", {
|
20
|
+
readonly id: string;
|
21
|
+
readonly text?: string | undefined;
|
22
|
+
}, {
|
23
|
+
readonly text?: string | undefined;
|
24
|
+
readonly id: string;
|
25
|
+
}>;
|
26
|
+
completeTodo: MutationDef<"completeTodo", {
|
27
|
+
readonly id: string;
|
28
|
+
}, {
|
29
|
+
readonly id: string;
|
30
|
+
}>;
|
31
|
+
uncompleteTodo: MutationDef<"uncompleteTodo", {
|
32
|
+
readonly id: string;
|
33
|
+
}, {
|
34
|
+
readonly id: string;
|
35
|
+
}>;
|
36
|
+
completeTodos: MutationDef<"completeTodos", {
|
37
|
+
readonly ids: readonly string[];
|
38
|
+
}, {
|
39
|
+
readonly ids: readonly string[];
|
40
|
+
}>;
|
41
|
+
toggleTodo: MutationDef<"toggleTodo", {
|
42
|
+
readonly id: string;
|
43
|
+
}, {
|
44
|
+
readonly id: string;
|
45
|
+
}>;
|
46
|
+
setReadonlyTodo: MutationDef<"setReadonlyTodo", {
|
47
|
+
readonly id: string;
|
48
|
+
readonly readonly: boolean;
|
49
|
+
}, {
|
50
|
+
readonly id: string;
|
51
|
+
readonly readonly: boolean;
|
52
|
+
}>;
|
53
|
+
setTextTodo: MutationDef<"setTextTodo", {
|
54
|
+
readonly text: string;
|
55
|
+
readonly id: string;
|
56
|
+
}, {
|
57
|
+
readonly text: string;
|
58
|
+
readonly id: string;
|
59
|
+
}>;
|
60
|
+
setInputValue: MutationDef<"setInputValue", {
|
61
|
+
readonly text: string;
|
62
|
+
readonly id: string;
|
63
|
+
}, {
|
64
|
+
readonly text: string;
|
65
|
+
readonly id: string;
|
66
|
+
}>;
|
67
|
+
};
|
68
|
+
export type PartialEvent = {
|
69
|
+
mutation: string;
|
70
|
+
args: any;
|
71
|
+
};
|
72
|
+
export declare const toEventNodes: (partialEvents: PartialEvent[], mutationDefs: Record<string, MutationDef.Any>) => HistoryDagNode[];
|
73
|
+
//# sourceMappingURL=mutation-fixtures.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mutation-fixtures.d.ts","sourceRoot":"","sources":["../../../../src/sync/next/test/mutation-fixtures.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAG/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGvD,+DAA+D;AAC/D,eAAO,MAAM,KAAK;qBACC,MAAM;0BACD,MAAM,aAAa,OAAO;wBAC5B,MAAM,aAAa,OAAO;0BACxB,MAAM;qBACX,MAAM;CACvB,CAAA;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+GrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAAA;AAE1D,eAAO,MAAM,YAAY,kBACR,YAAY,EAAE,gBACf,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAC5C,cAAc,EAkFhB,CAAA"}
|