@dxos/echo-protocol 0.8.3 → 0.8.4-main.05e74ebcff

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 (36) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/neutral/index.mjs +825 -0
  4. package/dist/lib/neutral/index.mjs.map +7 -0
  5. package/dist/lib/neutral/meta.json +1 -0
  6. package/dist/types/src/document-structure.d.ts +26 -2
  7. package/dist/types/src/document-structure.d.ts.map +1 -1
  8. package/dist/types/src/echo-feed-codec.d.ts +17 -0
  9. package/dist/types/src/echo-feed-codec.d.ts.map +1 -0
  10. package/dist/types/src/foreign-key.d.ts +1 -1
  11. package/dist/types/src/foreign-key.d.ts.map +1 -1
  12. package/dist/types/src/index.d.ts +4 -3
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/query/ast.d.ts +238 -25
  15. package/dist/types/src/query/ast.d.ts.map +1 -1
  16. package/dist/types/src/reference.d.ts +17 -0
  17. package/dist/types/src/reference.d.ts.map +1 -1
  18. package/dist/types/src/space-id.d.ts.map +1 -1
  19. package/dist/types/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +15 -15
  21. package/src/document-structure.ts +36 -2
  22. package/src/echo-feed-codec.ts +67 -0
  23. package/src/foreign-key.ts +4 -3
  24. package/src/index.ts +4 -3
  25. package/src/query/ast.ts +326 -34
  26. package/src/reference.ts +29 -0
  27. package/src/space-id.ts +1 -1
  28. package/dist/lib/browser/index.mjs +0 -509
  29. package/dist/lib/browser/index.mjs.map +0 -7
  30. package/dist/lib/browser/meta.json +0 -1
  31. package/dist/lib/node/index.cjs +0 -527
  32. package/dist/lib/node/index.cjs.map +0 -7
  33. package/dist/lib/node/meta.json +0 -1
  34. package/dist/lib/node-esm/index.mjs +0 -510
  35. package/dist/lib/node-esm/index.mjs.map +0 -7
  36. package/dist/lib/node-esm/meta.json +0 -1
@@ -8,7 +8,7 @@ import { visitValues } from '@dxos/util';
8
8
 
9
9
  import { type RawString } from './automerge';
10
10
  import type { ForeignKey } from './foreign-key';
11
- import { isEncodedReference, type EncodedReference } from './reference';
11
+ import { type EncodedReference, isEncodedReference } from './reference';
12
12
  import { type SpaceDocVersion } from './space-doc-version';
13
13
 
14
14
  export type SpaceState = {
@@ -137,6 +137,10 @@ export const ObjectStructure = Object.freeze({
137
137
  return object.system?.target;
138
138
  },
139
139
 
140
+ getParent: (object: ObjectStructure): EncodedReference | undefined => {
141
+ return object.system?.parent;
142
+ },
143
+
140
144
  /**
141
145
  * @returns All references in the data section of the object.
142
146
  */
@@ -153,6 +157,10 @@ export const ObjectStructure = Object.freeze({
153
157
  return references;
154
158
  },
155
159
 
160
+ getTags: (object: ObjectStructure): string[] => {
161
+ return object.meta.tags ?? [];
162
+ },
163
+
156
164
  makeObject: ({
157
165
  type,
158
166
  data,
@@ -214,6 +222,26 @@ export type ObjectMeta = {
214
222
  * Foreign keys.
215
223
  */
216
224
  keys: ForeignKey[];
225
+
226
+ /**
227
+ * Tags.
228
+ * An array of DXNs of Tag objects within the space.
229
+ *
230
+ * NOTE: Optional for backwards compatibilty.
231
+ */
232
+ tags?: string[];
233
+
234
+ /**
235
+ * Fully-qualified registry key for the object (FQN format, e.g. `org.example.type.foo`).
236
+ * Identifies the canonical registry entry the object instance was created from.
237
+ */
238
+ key?: string;
239
+
240
+ /**
241
+ * Semantic version of the registry entry the object was created from.
242
+ * Must be a valid semver string (e.g. `1.2.3`).
243
+ */
244
+ version?: string;
217
245
  };
218
246
 
219
247
  /**
@@ -236,13 +264,19 @@ export type ObjectSystem = {
236
264
  */
237
265
  deleted?: boolean;
238
266
 
267
+ /**
268
+ * Object parent.
269
+ * Objects with no parent are at the top level of the object hierarchy in the space.
270
+ */
271
+ parent?: EncodedReference;
272
+
239
273
  /**
240
274
  * Only for relations.
241
275
  */
242
276
  source?: EncodedReference;
243
277
 
244
278
  /**
245
- * Only for relations.w
279
+ * Only for relations.
246
280
  */
247
281
  target?: EncodedReference;
248
282
  };
@@ -0,0 +1,67 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { FeedProtocol } from '@dxos/protocols';
6
+
7
+ import type { ForeignKey } from './foreign-key';
8
+
9
+ /** Property name for meta when object is serialized to JSON. Matches @dxos/echo/internal ATTR_META. */
10
+ const ATTR_META = '@meta';
11
+
12
+ /**
13
+ * Codec for ECHO objects in feed block payload: JSON object ↔ UTF-8 bytes.
14
+ * Encodes with queue position stripped; decodes with optional position injection.
15
+ */
16
+ export class EchoFeedCodec {
17
+ static readonly #encoder = new TextEncoder();
18
+ static readonly #decoder = new TextDecoder();
19
+
20
+ /**
21
+ * Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
22
+ */
23
+ static encode(value: Record<string, unknown>): Uint8Array {
24
+ const prepared = EchoFeedCodec.#stripQueuePosition(value);
25
+ return EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
26
+ }
27
+
28
+ /**
29
+ * Decodes feed block bytes to a JSON value.
30
+ * If position is provided, injects queue position into the decoded object's metadata.
31
+ */
32
+ static decode(data: Uint8Array, position?: number): Record<string, unknown> {
33
+ const decoded = JSON.parse(EchoFeedCodec.#decoder.decode(data));
34
+ if (position !== undefined && typeof decoded === 'object' && decoded !== null) {
35
+ EchoFeedCodec.#setQueuePosition(decoded, position);
36
+ }
37
+ return decoded;
38
+ }
39
+
40
+ static #stripQueuePosition(value: Record<string, unknown>): Record<string, unknown> {
41
+ if (typeof value !== 'object' || value === null) {
42
+ return value;
43
+ }
44
+ const obj = structuredClone(value);
45
+ const meta = obj[ATTR_META] as { keys?: ForeignKey[] } | undefined;
46
+ if (meta?.keys?.some((key: ForeignKey) => key.source === FeedProtocol.KEY_QUEUE_POSITION)) {
47
+ meta.keys = meta.keys.filter((key: ForeignKey) => key.source !== FeedProtocol.KEY_QUEUE_POSITION);
48
+ }
49
+ return obj;
50
+ }
51
+
52
+ static #setQueuePosition(obj: Record<string, any>, position: number): void {
53
+ obj[ATTR_META] ??= { keys: [] };
54
+ obj[ATTR_META]!.keys ??= [];
55
+ const keys = obj[ATTR_META]!.keys!;
56
+ for (let i = 0; i < keys.length; i++) {
57
+ if (keys[i].source === FeedProtocol.KEY_QUEUE_POSITION) {
58
+ keys.splice(i, 1);
59
+ i--;
60
+ }
61
+ }
62
+ keys.push({
63
+ source: FeedProtocol.KEY_QUEUE_POSITION,
64
+ id: position.toString(),
65
+ });
66
+ }
67
+ }
@@ -2,7 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema, SchemaAST } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
6
7
 
7
8
  const ForeignKey_ = Schema.Struct({
8
9
  /**
@@ -15,8 +16,8 @@ const ForeignKey_ = Schema.Struct({
15
16
  * Id within the foreign database.
16
17
  */
17
18
  // TODO(wittjosiah): This annotation is currently used to ensure id field shows up in forms.
18
- // TODO(dmaretskyi): `false` is not a valid value for the annotation.
19
- id: Schema.String.annotations({ [SchemaAST.IdentifierAnnotationId]: false }),
19
+ // TODO(dmaretskyi): `false` is not a valid value for the annotation. Use a different annotation.
20
+ id: Schema.String.annotations({ [SchemaAST.IdentifierAnnotationId]: 'false' }),
20
21
  });
21
22
 
22
23
  export type ForeignKey = Schema.Schema.Type<typeof ForeignKey_>;
package/src/index.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export type * from './collection-sync';
5
6
  export * from './document-structure';
7
+ export * from './echo-feed-codec';
8
+ export * from './foreign-key';
9
+ export * from './query';
6
10
  export * from './reference';
7
11
  export * from './space-doc-version';
8
- export * from './collection-sync';
9
12
  export * from './space-id';
10
- export * from './foreign-key';
11
- export * from './query';