@enbox/dwn-sdk-js 0.3.8 → 0.4.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 (79) hide show
  1. package/dist/browser.mjs +11 -11
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +175 -512
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/dwn-error.js +1 -3
  6. package/dist/esm/src/core/dwn-error.js.map +1 -1
  7. package/dist/esm/src/core/messages-grant-authorization.js +1 -17
  8. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  9. package/dist/esm/src/core/protocol-authorization-validation.js +1 -1
  10. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
  11. package/dist/esm/src/core/replication-apply.js +200 -0
  12. package/dist/esm/src/core/replication-apply.js.map +1 -0
  13. package/dist/esm/src/dwn.js +212 -0
  14. package/dist/esm/src/dwn.js.map +1 -1
  15. package/dist/esm/src/handlers/messages-sync.js +66 -369
  16. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  17. package/dist/esm/src/handlers/records-write.js +18 -12
  18. package/dist/esm/src/handlers/records-write.js.map +1 -1
  19. package/dist/esm/src/index.js +1 -1
  20. package/dist/esm/src/index.js.map +1 -1
  21. package/dist/esm/src/interfaces/messages-sync.js +0 -11
  22. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  23. package/dist/esm/tests/core/replication-apply.spec.js +220 -0
  24. package/dist/esm/tests/core/replication-apply.spec.js.map +1 -0
  25. package/dist/esm/tests/dwn.spec.js +139 -2
  26. package/dist/esm/tests/dwn.spec.js.map +1 -1
  27. package/dist/esm/tests/features/records-record-limit.spec.js +14 -0
  28. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
  29. package/dist/esm/tests/handlers/messages-sync.spec.js +1 -684
  30. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  31. package/dist/esm/tests/handlers/records-write.spec.js +43 -2
  32. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  33. package/dist/esm/tests/test-suite.js +0 -2
  34. package/dist/esm/tests/test-suite.js.map +1 -1
  35. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  36. package/dist/types/src/core/dwn-error.d.ts +1 -3
  37. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  38. package/dist/types/src/core/messages-grant-authorization.d.ts +0 -1
  39. package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
  40. package/dist/types/src/core/replication-apply.d.ts +93 -0
  41. package/dist/types/src/core/replication-apply.d.ts.map +1 -0
  42. package/dist/types/src/dwn.d.ts +22 -1
  43. package/dist/types/src/dwn.d.ts.map +1 -1
  44. package/dist/types/src/handlers/messages-sync.d.ts +10 -54
  45. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  46. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  47. package/dist/types/src/index.d.ts +3 -3
  48. package/dist/types/src/index.d.ts.map +1 -1
  49. package/dist/types/src/interfaces/messages-sync.d.ts +0 -3
  50. package/dist/types/src/interfaces/messages-sync.d.ts.map +1 -1
  51. package/dist/types/src/types/messages-types.d.ts +0 -18
  52. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  53. package/dist/types/tests/core/replication-apply.spec.d.ts +2 -0
  54. package/dist/types/tests/core/replication-apply.spec.d.ts.map +1 -0
  55. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  56. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -1
  57. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  58. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  59. package/dist/types/tests/test-suite.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/core/dwn-error.ts +1 -3
  62. package/src/core/messages-grant-authorization.ts +1 -31
  63. package/src/core/protocol-authorization-validation.ts +2 -2
  64. package/src/core/replication-apply.ts +272 -0
  65. package/src/dwn.ts +296 -2
  66. package/src/handlers/messages-sync.ts +92 -585
  67. package/src/handlers/records-write.ts +18 -13
  68. package/src/index.ts +3 -4
  69. package/src/interfaces/messages-sync.ts +8 -25
  70. package/src/types/messages-types.ts +0 -20
  71. package/dist/esm/src/sync/records-projection.js +0 -228
  72. package/dist/esm/src/sync/records-projection.js.map +0 -1
  73. package/dist/esm/tests/sync/records-projection.spec.js +0 -245
  74. package/dist/esm/tests/sync/records-projection.spec.js.map +0 -1
  75. package/dist/types/src/sync/records-projection.d.ts +0 -98
  76. package/dist/types/src/sync/records-projection.d.ts.map +0 -1
  77. package/dist/types/tests/sync/records-projection.spec.d.ts +0 -2
  78. package/dist/types/tests/sync/records-projection.spec.d.ts.map +0 -1
  79. package/src/sync/records-projection.ts +0 -328
@@ -1,245 +0,0 @@
1
- import { afterAll, beforeAll, beforeEach, describe, expect, it, spyOn } from 'bun:test';
2
- import { lexicographicalCompare } from '../../src/utils/string.js';
3
- import { TestDataGenerator } from '../utils/test-data-generator.js';
4
- import { TestStores } from '../test-stores.js';
5
- import { getBit, hashKey, hashToHex, Jws, Message, RecordsDelete, RecordsProjection, SMTStoreMemory, SparseMerkleTree } from '../../src/index.js';
6
- export function testRecordsProjection() {
7
- describe('RecordsProjection', () => {
8
- let messageStore;
9
- let alice;
10
- const tenant = () => alice.did;
11
- beforeAll(async () => {
12
- messageStore = TestStores.get().messageStore;
13
- await messageStore.open();
14
- });
15
- beforeEach(async () => {
16
- alice = await TestDataGenerator.generatePersona();
17
- await messageStore.clear();
18
- });
19
- afterAll(async () => {
20
- await messageStore.close();
21
- });
22
- it('normalizes duplicate and covered scopes deterministically', () => {
23
- const scopes = RecordsProjection.normalizeScopes([
24
- { protocol: 'https://example.com/b', protocolPath: 'note' },
25
- { protocol: 'https://example.com/a', contextId: 'root' },
26
- { protocol: 'https://example.com/b' },
27
- { protocol: 'https://example.com/b', protocolPath: 'note' },
28
- ]);
29
- expect(scopes).toEqual([
30
- { protocol: 'https://example.com/a', contextId: 'root' },
31
- { protocol: 'https://example.com/b' },
32
- ]);
33
- });
34
- it('normalizes covered context subtree scopes to the broader context', () => {
35
- const scopes = RecordsProjection.normalizeScopes([
36
- { protocol: 'https://example.com/a', contextId: 'root/child' },
37
- { protocol: 'https://example.com/a', contextId: 'root/child/grandchild' },
38
- { protocol: 'https://example.com/a', contextId: 'root' },
39
- { protocol: 'https://example.com/a', contextId: 'rootEVIL' },
40
- { protocol: 'https://example.com/b', contextId: 'root/child' },
41
- { protocol: 'https://example.com/b', contextId: 'root' },
42
- ]);
43
- expect(scopes).toEqual([
44
- { protocol: 'https://example.com/a', contextId: 'root' },
45
- { protocol: 'https://example.com/a', contextId: 'rootEVIL' },
46
- { protocol: 'https://example.com/b', contextId: 'root' },
47
- ]);
48
- });
49
- it('rejects scopes that specify both protocolPath and contextId', () => {
50
- expect(() => RecordsProjection.normalizeScopes([
51
- { protocol: 'https://example.com/a', protocolPath: 'note', contextId: 'root' },
52
- ])).toThrow('protocolPath and contextId scopes are mutually exclusive');
53
- });
54
- it('returns primary message CIDs in bytewise order', async () => {
55
- const messages = [
56
- createGenericMessage('2026-06-05T00:00:00.000000Z'),
57
- createGenericMessage('2026-06-05T00:00:01.000000Z'),
58
- createGenericMessage('2026-06-05T00:00:02.000000Z'),
59
- ];
60
- const cidByMessage = new Map([
61
- [messages[0], 'bafyZ'],
62
- [messages[1], 'bafya'],
63
- [messages[2], 'bafyB'],
64
- ]);
65
- const getCidSpy = spyOn(Message, 'getCid').mockImplementation(async (message) => cidByMessage.get(message));
66
- try {
67
- const projectedCids = await RecordsProjection.getPrimaryMessageCids({
68
- tenant: tenant(),
69
- messageStore: createQueryOnlyMessageStore(messages),
70
- scopes: [{ protocol: 'https://example.com/chat' }],
71
- });
72
- expect(projectedCids).toEqual([...cidByMessage.values()].sort(lexicographicalCompare));
73
- }
74
- finally {
75
- getCidSpy.mockRestore();
76
- }
77
- });
78
- it('projects protocolPath scopes by exact path, not prefix', async () => {
79
- const protocol = 'https://example.com/chat';
80
- const root = await createWrite({ protocol, protocolPath: 'thread' });
81
- const child = await createWrite({
82
- protocol,
83
- protocolPath: 'thread/message',
84
- parentContextId: root.message.contextId,
85
- });
86
- const siblingType = await createWrite({
87
- protocol,
88
- protocolPath: 'thread/messageAttachment',
89
- parentContextId: root.message.contextId,
90
- });
91
- const rootCid = await putWrite(root);
92
- const childCid = await putWrite(child);
93
- await putWrite(siblingType);
94
- const rootPathCids = await RecordsProjection.getPrimaryMessageCids({
95
- tenant: tenant(),
96
- messageStore,
97
- scopes: [{ protocol, protocolPath: 'thread' }],
98
- });
99
- expect(rootPathCids).toEqual([rootCid]);
100
- const childPathCids = await RecordsProjection.getPrimaryMessageCids({
101
- tenant: tenant(),
102
- messageStore,
103
- scopes: [{ protocol, protocolPath: 'thread/message' }],
104
- });
105
- expect(childPathCids).toEqual([childCid]);
106
- });
107
- it('projects contextId scopes by context subtree boundary', async () => {
108
- const protocol = 'https://example.com/chat';
109
- const root = await createWrite({ protocol, protocolPath: 'thread' });
110
- const child = await createWrite({
111
- protocol,
112
- protocolPath: 'thread/message',
113
- parentContextId: root.message.contextId,
114
- });
115
- const falsePrefix = await createWrite({ protocol, protocolPath: 'thread' });
116
- const rootCid = await putWrite(root);
117
- const childCid = await putWrite(child);
118
- await putWrite(falsePrefix, true, { contextId: `${root.message.contextId}EVIL` });
119
- const projectedCids = await RecordsProjection.getPrimaryMessageCids({
120
- tenant: tenant(),
121
- messageStore,
122
- scopes: [{ protocol, contextId: root.message.contextId }],
123
- });
124
- expect(projectedCids).toEqual([childCid, rootCid].sort(lexicographicalCompare));
125
- });
126
- it('includes RecordsDelete tombstones by indexed initial-write projection metadata', async () => {
127
- const protocol = 'https://example.com/chat';
128
- const write = await createWrite({ protocol, protocolPath: 'thread/message' });
129
- const deleteRecord = await RecordsDelete.create({
130
- recordId: write.message.recordId,
131
- signer: Jws.createSigner(alice),
132
- });
133
- await putWrite(write, false);
134
- const deleteCid = await putDelete(deleteRecord, write.message);
135
- const projectedCids = await RecordsProjection.getPrimaryMessageCids({
136
- tenant: tenant(),
137
- messageStore,
138
- scopes: [{ protocol, protocolPath: 'thread/message' }],
139
- });
140
- expect(projectedCids).toEqual([deleteCid]);
141
- });
142
- it('computes the same SMT root, subtree hash, and leaves as the projected CID set', async () => {
143
- const protocol = 'https://example.com/chat';
144
- const root = await createWrite({ protocol, protocolPath: 'thread' });
145
- const child = await createWrite({
146
- protocol,
147
- protocolPath: 'thread/message',
148
- parentContextId: root.message.contextId,
149
- });
150
- const otherProtocol = await createWrite({
151
- protocol: 'https://example.com/notes',
152
- protocolPath: 'note',
153
- });
154
- const rootCid = await putWrite(root);
155
- const childCid = await putWrite(child);
156
- await putWrite(otherProtocol);
157
- const scopes = [{ protocol }];
158
- const expectedCids = [childCid, rootCid].sort(lexicographicalCompare);
159
- const prefix = await firstBitPrefix(rootCid);
160
- const expectedTree = await treeValuesFromCids(expectedCids, prefix);
161
- const rootHex = await RecordsProjection.getRootHex({
162
- tenant: tenant(),
163
- messageStore,
164
- scopes,
165
- });
166
- const subtreeHash = await RecordsProjection.getSubtreeHash({
167
- tenant: tenant(),
168
- messageStore,
169
- scopes,
170
- prefix,
171
- });
172
- const leaves = await RecordsProjection.getLeaves({
173
- tenant: tenant(),
174
- messageStore,
175
- scopes,
176
- prefix,
177
- });
178
- expect(rootHex).toBe(expectedTree.rootHex);
179
- expect(hashToHex(subtreeHash)).toBe(expectedTree.subtreeHex);
180
- expect(leaves.sort(lexicographicalCompare)).toEqual(expectedTree.leaves);
181
- });
182
- async function createWrite(input) {
183
- return TestDataGenerator.generateRecordsWrite({
184
- author: alice,
185
- ...input,
186
- });
187
- }
188
- async function putWrite(write, isLatestBaseState = true, indexOverrides = {}) {
189
- const indexes = {
190
- ...await write.recordsWrite.constructIndexes(isLatestBaseState),
191
- ...indexOverrides,
192
- };
193
- await messageStore.put(tenant(), write.message, indexes);
194
- return Message.getCid(write.message);
195
- }
196
- async function putDelete(recordsDelete, initialWrite) {
197
- await messageStore.put(tenant(), recordsDelete.message, recordsDelete.constructIndexes(initialWrite));
198
- return Message.getCid(recordsDelete.message);
199
- }
200
- });
201
- }
202
- function createGenericMessage(messageTimestamp) {
203
- return {
204
- descriptor: {
205
- interface: 'Records',
206
- method: 'Write',
207
- messageTimestamp,
208
- },
209
- };
210
- }
211
- function createQueryOnlyMessageStore(messages) {
212
- return {
213
- clear: async () => { },
214
- close: async () => { },
215
- count: async () => messages.length,
216
- delete: async () => { },
217
- get: async () => undefined,
218
- open: async () => { },
219
- put: async () => { },
220
- query: async () => ({ messages }),
221
- };
222
- }
223
- async function firstBitPrefix(messageCid) {
224
- const keyHash = await hashKey(messageCid);
225
- return [getBit(keyHash, 0)];
226
- }
227
- async function treeValuesFromCids(messageCids, prefix) {
228
- const tree = new SparseMerkleTree(new SMTStoreMemory());
229
- await tree.initialize();
230
- try {
231
- for (const messageCid of messageCids) {
232
- await tree.insert(messageCid);
233
- }
234
- const leaves = await tree.getLeaves(prefix);
235
- return {
236
- rootHex: hashToHex(await tree.getRoot()),
237
- subtreeHex: hashToHex(await tree.getSubtreeHash(prefix)),
238
- leaves: leaves.sort(lexicographicalCompare),
239
- };
240
- }
241
- finally {
242
- await tree.close();
243
- }
244
- }
245
- //# sourceMappingURL=records-projection.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"records-projection.spec.js","sourceRoot":"","sources":["../../../../tests/sync/records-projection.spec.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAExF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,G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AkB,CAC/B,WAAqB,EACrB,MAAiB;IAEjB,MAAM,IAAI,GAAG,IAAI,gBAAgB,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC;IACxD,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IAExB,IAAI,CAAC;QACH,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO;YACL,OAAO,EAAM,SAAS,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5C,UAAU,EAAG,SAAS,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACzD,MAAM,EAAO,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC;SACjD,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -1,98 +0,0 @@
1
- import type { Hash } from '../types/smt-types.js';
2
- import type { MessageStore, MessageStoreOptions } from '../types/message-store.js';
3
- /**
4
- * Projection-root algorithm for record-primary scoped subsets.
5
- *
6
- * This version builds an on-demand SMT over latest Records primary message CIDs
7
- * selected by protocol plus optional exact protocolPath or context subtree.
8
- * Dependency records, protocol configs, and record data payloads are not part
9
- * of this root.
10
- */
11
- export declare const RECORDS_PROJECTION_ROOT_VERSION = "records-primary-scope-root-v1";
12
- /**
13
- * A Records primary projection scope.
14
- *
15
- * `protocolPath` is an exact type-path match. `contextId` is a boundary-aware
16
- * subtree match: the candidate context must equal the scoped context or start
17
- * with `${contextId}/`. `protocolPath` and `contextId` are mutually exclusive.
18
- */
19
- export type RecordsProjectionScope = {
20
- protocol: string;
21
- protocolPath?: string;
22
- contextId?: string;
23
- };
24
- export type RecordsProjectionInput = {
25
- tenant: string;
26
- messageStore: MessageStore;
27
- scopes: readonly [RecordsProjectionScope, ...RecordsProjectionScope[]];
28
- options?: MessageStoreOptions;
29
- };
30
- export type RecordsProjectionTreeInput = RecordsProjectionInput & {
31
- prefix: boolean[];
32
- };
33
- export type RecordsProjectionSnapshot = {
34
- getRoot(): Promise<Hash>;
35
- getRootHex(): Promise<string>;
36
- getSubtreeHash(prefix: boolean[]): Promise<Hash>;
37
- getLeaves(prefix: boolean[]): Promise<string[]>;
38
- close(): Promise<void>;
39
- };
40
- export type NormalizedRecordsProjectionScope = {
41
- protocol: string;
42
- } | {
43
- protocol: string;
44
- protocolPath: string;
45
- } | {
46
- protocol: string;
47
- contextId: string;
48
- };
49
- /**
50
- * Computes deterministic on-demand roots for Records projections.
51
- *
52
- * The snapshot API performs one store enumeration and serves tree operations
53
- * from that in-memory view. A future store-level snapshot/high-watermark can be
54
- * threaded through the `options` input without changing the projection shape.
55
- */
56
- export declare class RecordsProjection {
57
- /**
58
- * Returns the sorted latest Records primary message CIDs covered by a scope union.
59
- */
60
- static getPrimaryMessageCids({ tenant, messageStore, scopes, options, }: RecordsProjectionInput): Promise<string[]>;
61
- /**
62
- * Returns the projection root hash.
63
- */
64
- static getRoot(input: RecordsProjectionInput): Promise<Hash>;
65
- /**
66
- * Returns the projection root hash encoded as lowercase hex.
67
- */
68
- static getRootHex(input: RecordsProjectionInput): Promise<string>;
69
- /**
70
- * Returns the subtree hash for a bit prefix within this projection.
71
- */
72
- static getSubtreeHash(input: RecordsProjectionTreeInput): Promise<Hash>;
73
- /**
74
- * Returns the message CIDs under a bit prefix within this projection.
75
- */
76
- static getLeaves(input: RecordsProjectionTreeInput): Promise<string[]>;
77
- /**
78
- * Builds an in-memory projection tree from one primary-CID enumeration.
79
- */
80
- static createSnapshot(input: RecordsProjectionInput): Promise<RecordsProjectionSnapshot>;
81
- /**
82
- * Normalizes a scope union into sorted, duplicate-free, subsumption-reduced entries.
83
- */
84
- static normalizeScopes(scopes: readonly [RecordsProjectionScope, ...RecordsProjectionScope[]]): [NormalizedRecordsProjectionScope, ...NormalizedRecordsProjectionScope[]];
85
- private static withTree;
86
- private static createTree;
87
- private static normalizeScope;
88
- private static constructFilters;
89
- private static requireNonEmptyString;
90
- private static scopeKey;
91
- private static isProtocolWideScope;
92
- private static isContextScope;
93
- private static contextIdSubsumes;
94
- private static compareScopes;
95
- private static scopeRank;
96
- private static scopeValue;
97
- }
98
- //# sourceMappingURL=records-projection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"records-projection.d.ts","sourceRoot":"","sources":["../../../../src/sync/records-projection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAWnF;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,kCAAkC,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,SAAS,CAAC,sBAAsB,EAAE,GAAG,sBAAsB,EAAE,CAAC,CAAC;IACvE,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,sBAAsB,GAAG;IAChE,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,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CAAC,gBAAgB;IAyB/B,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAQpC,OAAO,CAAC,MAAM,CAAC,QAAQ;IAYvB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAMlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAM7B,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAKhC,OAAO,CAAC,MAAM,CAAC,aAAa;IAkB5B,OAAO,CAAC,MAAM,CAAC,SAAS;IAMxB,OAAO,CAAC,MAAM,CAAC,UAAU;CAK1B"}
@@ -1,2 +0,0 @@
1
- export declare function testRecordsProjection(): void;
2
- //# sourceMappingURL=records-projection.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"records-projection.spec.d.ts","sourceRoot":"","sources":["../../../../tests/sync/records-projection.spec.ts"],"names":[],"mappings":"AAUA,wBAAgB,qBAAqB,IAAI,IAAI,CAgP5C"}