@dxos/echo 0.16.0 → 0.17.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 (176) hide show
  1. package/dist/lib/Annotation.mjs +2 -2
  2. package/dist/lib/Database.mjs +1 -1
  3. package/dist/lib/Error.mjs +1 -1
  4. package/dist/lib/Feed.mjs +1 -1
  5. package/dist/lib/Format.mjs +2 -2
  6. package/dist/lib/Migration.mjs +1 -1
  7. package/dist/lib/chunk-Annotation.mjs +14 -11
  8. package/dist/lib/chunk-Annotation.mjs.map +1 -1
  9. package/dist/lib/chunk-Blob.mjs +1 -1
  10. package/dist/lib/chunk-Collection.mjs +1 -1
  11. package/dist/lib/chunk-Database.mjs +93 -7
  12. package/dist/lib/chunk-Database.mjs.map +1 -1
  13. package/dist/lib/chunk-Dataset.mjs +1 -1
  14. package/dist/lib/chunk-Entity.mjs +2 -2
  15. package/dist/lib/chunk-Entity.mjs.map +1 -1
  16. package/dist/lib/chunk-Error.mjs +13 -1
  17. package/dist/lib/chunk-Error.mjs.map +1 -1
  18. package/dist/lib/chunk-Feed.mjs +311 -17
  19. package/dist/lib/chunk-Feed.mjs.map +1 -1
  20. package/dist/lib/chunk-Filter.mjs +4 -3
  21. package/dist/lib/chunk-Filter.mjs.map +1 -1
  22. package/dist/lib/chunk-Format.mjs +2 -1
  23. package/dist/lib/chunk-Hypergraph.mjs +1 -1
  24. package/dist/lib/chunk-Hypergraph.mjs.map +1 -1
  25. package/dist/lib/chunk-Migration.mjs +155 -5
  26. package/dist/lib/chunk-Migration.mjs.map +1 -1
  27. package/dist/lib/chunk-Obj.mjs +12 -5
  28. package/dist/lib/chunk-Obj.mjs.map +1 -1
  29. package/dist/lib/chunk-Query.mjs +2 -2
  30. package/dist/lib/chunk-QueryResult.mjs.map +1 -1
  31. package/dist/lib/chunk-Ref2.mjs +2 -2
  32. package/dist/lib/chunk-Registry.mjs +1 -1
  33. package/dist/lib/chunk-Registry.mjs.map +1 -1
  34. package/dist/lib/chunk-Relation.mjs +5 -5
  35. package/dist/lib/chunk-Relation.mjs.map +1 -1
  36. package/dist/lib/chunk-Scope.mjs +16 -2
  37. package/dist/lib/chunk-Scope.mjs.map +1 -1
  38. package/dist/lib/chunk-Tag.mjs +4 -4
  39. package/dist/lib/chunk-Tag.mjs.map +1 -1
  40. package/dist/lib/chunk-Text.mjs +2 -2
  41. package/dist/lib/chunk-Type.mjs +26 -7
  42. package/dist/lib/chunk-Type.mjs.map +1 -1
  43. package/dist/lib/chunk-View.mjs +1 -1
  44. package/dist/lib/chunk-atom-snapshot.mjs +29 -1
  45. package/dist/lib/chunk-atom-snapshot.mjs.map +1 -1
  46. package/dist/lib/chunk-entity-dictionary.mjs +28 -19
  47. package/dist/lib/chunk-entity-dictionary.mjs.map +1 -1
  48. package/dist/lib/chunk-internal.mjs +231 -79
  49. package/dist/lib/chunk-internal.mjs.map +1 -1
  50. package/dist/lib/chunk-json-schema.mjs +1 -1
  51. package/dist/lib/chunk-ref.mjs +38 -34
  52. package/dist/lib/chunk-ref.mjs.map +1 -1
  53. package/dist/lib/chunk-select.mjs +7 -3
  54. package/dist/lib/chunk-select.mjs.map +1 -1
  55. package/dist/lib/index.mjs +2 -2
  56. package/dist/lib/internal.mjs +6 -6
  57. package/dist/lib/testing.mjs +2 -2
  58. package/dist/lib/testing.mjs.map +1 -1
  59. package/dist/types/src/Annotation.d.ts +1 -1
  60. package/dist/types/src/Annotation.d.ts.map +1 -1
  61. package/dist/types/src/Database.d.ts +30 -13
  62. package/dist/types/src/Database.d.ts.map +1 -1
  63. package/dist/types/src/Entity.d.ts +3 -4
  64. package/dist/types/src/Entity.d.ts.map +1 -1
  65. package/dist/types/src/Error.d.ts +36 -0
  66. package/dist/types/src/Error.d.ts.map +1 -1
  67. package/dist/types/src/Feed.d.ts +261 -18
  68. package/dist/types/src/Feed.d.ts.map +1 -1
  69. package/dist/types/src/Filter.d.ts +7 -1
  70. package/dist/types/src/Filter.d.ts.map +1 -1
  71. package/dist/types/src/Hypergraph.d.ts +1 -1
  72. package/dist/types/src/Migration.d.ts +213 -2
  73. package/dist/types/src/Migration.d.ts.map +1 -1
  74. package/dist/types/src/Migration.test.d.ts +2 -0
  75. package/dist/types/src/Migration.test.d.ts.map +1 -0
  76. package/dist/types/src/Obj.d.ts +4 -4
  77. package/dist/types/src/Obj.d.ts.map +1 -1
  78. package/dist/types/src/QueryResult.d.ts +16 -0
  79. package/dist/types/src/QueryResult.d.ts.map +1 -1
  80. package/dist/types/src/Relation.d.ts +3 -4
  81. package/dist/types/src/Relation.d.ts.map +1 -1
  82. package/dist/types/src/Scope.d.ts +32 -1
  83. package/dist/types/src/Scope.d.ts.map +1 -1
  84. package/dist/types/src/Tag.d.ts.map +1 -1
  85. package/dist/types/src/Type.d.ts +27 -2
  86. package/dist/types/src/Type.d.ts.map +1 -1
  87. package/dist/types/src/internal/Annotation/annotations.d.ts +35 -1
  88. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
  89. package/dist/types/src/internal/Annotation/atoms.d.ts +2 -2
  90. package/dist/types/src/internal/Annotation/atoms.d.ts.map +1 -1
  91. package/dist/types/src/internal/Entity/api.d.ts +11 -0
  92. package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
  93. package/dist/types/src/internal/Entity/model.d.ts +3 -2
  94. package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
  95. package/dist/types/src/internal/Format/string.d.ts +5 -1
  96. package/dist/types/src/internal/Format/string.d.ts.map +1 -1
  97. package/dist/types/src/internal/Obj/atoms.d.ts +1 -1
  98. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
  99. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
  100. package/dist/types/src/internal/Query/pretty.d.ts.map +1 -1
  101. package/dist/types/src/internal/Ref/ref.d.ts +5 -1
  102. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
  103. package/dist/types/src/internal/Ref/strong-deps.d.ts +3 -1
  104. package/dist/types/src/internal/Ref/strong-deps.d.ts.map +1 -1
  105. package/dist/types/src/internal/common/api/meta.d.ts +4 -5
  106. package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
  107. package/dist/types/src/internal/common/atom-snapshot.d.ts +10 -0
  108. package/dist/types/src/internal/common/atom-snapshot.d.ts.map +1 -1
  109. package/dist/types/src/internal/common/proxy/change-context.d.ts +4 -0
  110. package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -1
  111. package/dist/types/src/internal/common/proxy/ownership.d.ts +5 -0
  112. package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -1
  113. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
  114. package/dist/types/src/internal/common/proxy/schema-validator.d.ts +17 -2
  115. package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -1
  116. package/dist/types/src/internal/common/proxy/symbols.d.ts +10 -0
  117. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -1
  118. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +0 -1
  119. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
  120. package/dist/types/src/internal/common/types/meta.d.ts +8 -4
  121. package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
  122. package/dist/types/src/internal/common/types/model-symbols.d.ts +6 -0
  123. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
  124. package/dist/types/src/internal/index.d.ts.map +1 -1
  125. package/dist/types/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +19 -15
  127. package/src/Annotation.test.ts +34 -0
  128. package/src/Annotation.ts +3 -0
  129. package/src/Database.ts +46 -15
  130. package/src/Entity.ts +3 -4
  131. package/src/Error.ts +9 -0
  132. package/src/Feed.test.ts +160 -0
  133. package/src/Feed.ts +412 -29
  134. package/src/Filter.ts +8 -1
  135. package/src/Hypergraph.ts +1 -1
  136. package/src/Migration.test.ts +137 -0
  137. package/src/Migration.ts +376 -4
  138. package/src/Obj.test.ts +44 -4
  139. package/src/Obj.ts +19 -5
  140. package/src/QueryResult.ts +14 -0
  141. package/src/Relation.ts +3 -4
  142. package/src/Scope.ts +43 -1
  143. package/src/Tag.md +5 -6
  144. package/src/Tag.ts +3 -2
  145. package/src/Type.test.ts +52 -0
  146. package/src/Type.ts +75 -22
  147. package/src/Type.tst.ts +155 -0
  148. package/src/internal/Annotation/annotations.test.ts +19 -0
  149. package/src/internal/Annotation/annotations.ts +67 -1
  150. package/src/internal/Annotation/atoms.ts +10 -9
  151. package/src/internal/Entity/api.ts +20 -1
  152. package/src/internal/Entity/model.ts +3 -0
  153. package/src/internal/Filter/match.ts +2 -2
  154. package/src/internal/Format/string.ts +7 -2
  155. package/src/internal/JsonSchema/json-schema.test.ts +2 -2
  156. package/src/internal/Obj/atoms.ts +9 -5
  157. package/src/internal/Obj/json-serializer.test.ts +34 -7
  158. package/src/internal/Obj/json-serializer.ts +18 -3
  159. package/src/internal/Query/pretty.ts +3 -2
  160. package/src/internal/Ref/ref.test.ts +27 -2
  161. package/src/internal/Ref/ref.ts +18 -2
  162. package/src/internal/Ref/strong-deps.ts +21 -2
  163. package/src/internal/common/api/meta.ts +7 -8
  164. package/src/internal/common/atom-snapshot.ts +61 -0
  165. package/src/internal/common/proxy/change-context.ts +5 -0
  166. package/src/internal/common/proxy/change.test.ts +62 -31
  167. package/src/internal/common/proxy/json-serializer.ts +3 -2
  168. package/src/internal/common/proxy/ownership.ts +14 -1
  169. package/src/internal/common/proxy/proxy-utils.ts +7 -1
  170. package/src/internal/common/proxy/schema-validator.ts +116 -27
  171. package/src/internal/common/proxy/symbols.ts +12 -0
  172. package/src/internal/common/proxy/typed-handler.test.ts +43 -0
  173. package/src/internal/common/proxy/typed-handler.ts +105 -33
  174. package/src/internal/common/types/meta.ts +25 -20
  175. package/src/internal/common/types/model-symbols.ts +7 -0
  176. package/src/internal/index.ts +1 -2
@@ -15,12 +15,40 @@ var snapshotForComparison = (value) => {
15
15
  if (value !== null && typeof value === "object") return { ...value };
16
16
  return value;
17
17
  };
18
+ /**
19
+ * {@link snapshotForComparison} at every depth, for a value whose readers hold on to its nested records and arrays: a
20
+ * shallow copy would hand them the same nested reference after an in-place change below the top level.
21
+ */
22
+ var snapshotDeep = (value) => {
23
+ if (Array.isArray(value)) return value.map(snapshotDeep);
24
+ if (isRefLike(value)) return value;
25
+ if (value instanceof Uint8Array) return new Uint8Array(value);
26
+ if (value instanceof Date) return new Date(value.getTime());
27
+ if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, snapshotDeep(entry)]));
28
+ return value;
29
+ };
18
30
  var valueEquals = (a, b) => {
19
31
  if (isRefLike(a) || isRefLike(b)) return isRefLike(a) && isRefLike(b) && a.uri.toString() === b.uri.toString() && a._getSavedTarget?.() === b._getSavedTarget?.();
20
32
  if (isRecord(a) || isRecord(b)) return false;
21
33
  return Object.is(a, b);
22
34
  };
23
35
  /**
36
+ * Structural equality between two {@link snapshotDeep} results, which share no references below the top level, so
37
+ * records and arrays compare by content at every depth. Refs compare as in {@link snapshotEquals}.
38
+ */
39
+ var snapshotDeepEquals = (a, b) => {
40
+ if (isRefLike(a) || isRefLike(b)) return valueEquals(a, b);
41
+ if (a instanceof Date || b instanceof Date) return a instanceof Date && b instanceof Date && Object.is(a.getTime(), b.getTime());
42
+ if (a instanceof Uint8Array || b instanceof Uint8Array) return a instanceof Uint8Array && b instanceof Uint8Array && a.length === b.length && a.every((byte, i) => byte === b[i]);
43
+ if (Array.isArray(a) || Array.isArray(b)) return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => snapshotDeepEquals(item, b[index]));
44
+ if (isRecord(a) || isRecord(b)) {
45
+ if (!isRecord(a) || !isRecord(b)) return false;
46
+ const keys = Object.keys(a);
47
+ return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && snapshotDeepEquals(a[key], b[key]));
48
+ }
49
+ return Object.is(a, b);
50
+ };
51
+ /**
24
52
  * Change-detection equality between a live value and a previously emitted snapshot. Identity cannot
25
53
  * serve, because `snapshotForComparison` mints a fresh reference on every read, so unchanged content
26
54
  * still fails `===` and the atom re-fires on every mutation of the owning object.
@@ -33,6 +61,6 @@ var snapshotEquals = (value, snapshot) => {
33
61
  return valueEquals(value, snapshot);
34
62
  };
35
63
  //#endregion
36
- export { snapshotForComparison as n, snapshotEquals as t };
64
+ export { snapshotForComparison as i, snapshotDeepEquals as n, snapshotEquals as r, snapshotDeep as t };
37
65
 
38
66
  //# sourceMappingURL=chunk-atom-snapshot.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-atom-snapshot.mjs","names":[],"sources":["../../src/internal/common/atom-snapshot.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { RefTypeId } from '../Ref/ref.ts';\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === 'object' && !Array.isArray(value);\n\ntype RefLike = {\n uri: { toString(): string };\n /** {@link RefImpl._getSavedTarget}; absent on a ref-like that is not a `RefImpl`. */\n _getSavedTarget?: () => unknown;\n};\n\nconst isRefLike = (value: unknown): value is RefLike =>\n value !== null && typeof value === 'object' && RefTypeId in value;\n\n/**\n * Snapshot a value to create a new reference for atom change-detection and React dependency tracking.\n * Objects and arrays are shallow-copied (a fresh reference each read, so an in-place mutation is\n * observed); primitives are returned as-is (so they dedupe via `!==`) and refs are too, since they\n * dedupe by URI and inlined target in {@link snapshotEquals}. Shared by the object-property and\n * annotation atom families.\n */\nexport const snapshotForComparison = <V>(value: V): V => {\n if (Array.isArray(value)) {\n return [...value] as V;\n }\n // Refs are immutable handles whose `uri`/`target` are prototype getters over private fields, so a\n // spread would hand the consumer an empty object — `useObject(obj, refField).uri` read `undefined`.\n if (isRefLike(value)) {\n return value;\n }\n if (value !== null && typeof value === 'object') {\n return { ...value } as V;\n }\n return value;\n};\n\n// Refs compare by URI: `RefImpl` mints a fresh wrapper on every property read, so `Object.is` never\n// matches two reads of the same ref. The inlined target is part of the ref's encoded value\n// (`{'/': uri, target}` for an object not yet in the database), so `Ref.make(target)` and a\n// `noInline()` of it share a URI without being the same value — comparing the URI alone would\n// swallow that update. The saved target is identity-stable across reads, so it needs no deeper\n// comparison.\nconst valueEquals = (a: unknown, b: unknown): boolean => {\n if (isRefLike(a) || isRefLike(b)) {\n return (\n isRefLike(a) &&\n isRefLike(b) &&\n a.uri.toString() === b.uri.toString() &&\n a._getSavedTarget?.() === b._getSavedTarget?.()\n );\n }\n // Records before `Object.is`: the snapshot shallow-copies the array, so a record element mutated in\n // place is the same reference on both sides and would otherwise read as unchanged.\n if (isRecord(a) || isRecord(b)) {\n return false;\n }\n return Object.is(a, b);\n};\n\n/**\n * Change-detection equality between a live value and a previously emitted snapshot. Identity cannot\n * serve, because `snapshotForComparison` mints a fresh reference on every read, so unchanged content\n * still fails `===` and the atom re-fires on every mutation of the owning object.\n *\n * Records always compare unequal: consumers mutate nested fields in place (e.g. kanban's\n * `arrangement.columns[x].ids`), which a shallow top-level comparison cannot see.\n */\nexport const snapshotEquals = (value: unknown, snapshot: unknown): boolean => {\n if (Array.isArray(value) && Array.isArray(snapshot)) {\n return value.length === snapshot.length && value.every((item, index) => valueEquals(item, snapshot[index]));\n }\n // A ref held directly compares exactly as one inside an array does, so both go through `valueEquals`\n // — two ladders would drift and reintroduce the asymmetry that left a ref field always unequal.\n return valueEquals(value, snapshot);\n};\n"],"mappings":";;AAMA,IAAM,YAAY,UAChB,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAQrE,IAAM,aAAa,UACjB,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa;;;;;;;;AAS9D,IAAa,yBAA4B,UAAgB;CACvD,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,CAAC,GAAG,KAAK;CAIlB,IAAI,UAAU,KAAK,GACjB,OAAO;CAET,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO,EAAE,GAAG,MAAM;CAEpB,OAAO;AACT;AAQA,IAAM,eAAe,GAAY,MAAwB;CACvD,IAAI,UAAU,CAAC,KAAK,UAAU,CAAC,GAC7B,OACE,UAAU,CAAC,KACX,UAAU,CAAC,KACX,EAAE,IAAI,SAAS,MAAM,EAAE,IAAI,SAAS,KACpC,EAAE,kBAAkB,MAAM,EAAE,kBAAkB;CAKlD,IAAI,SAAS,CAAC,KAAK,SAAS,CAAC,GAC3B,OAAO;CAET,OAAO,OAAO,GAAG,GAAG,CAAC;AACvB;;;;;;;;;AAUA,IAAa,kBAAkB,OAAgB,aAA+B;CAC5E,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,QAAQ,GAChD,OAAO,MAAM,WAAW,SAAS,UAAU,MAAM,OAAO,MAAM,UAAU,YAAY,MAAM,SAAS,MAAM,CAAC;CAI5G,OAAO,YAAY,OAAO,QAAQ;AACpC"}
1
+ {"version":3,"file":"chunk-atom-snapshot.mjs","names":[],"sources":["../../src/internal/common/atom-snapshot.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { RefTypeId } from '../Ref/ref.ts';\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === 'object' && !Array.isArray(value);\n\ntype RefLike = {\n uri: { toString(): string };\n /** {@link RefImpl._getSavedTarget}; absent on a ref-like that is not a `RefImpl`. */\n _getSavedTarget?: () => unknown;\n};\n\nconst isRefLike = (value: unknown): value is RefLike =>\n value !== null && typeof value === 'object' && RefTypeId in value;\n\n/**\n * Snapshot a value to create a new reference for atom change-detection and React dependency tracking.\n * Objects and arrays are shallow-copied (a fresh reference each read, so an in-place mutation is\n * observed); primitives are returned as-is (so they dedupe via `!==`) and refs are too, since they\n * dedupe by URI and inlined target in {@link snapshotEquals}. Shared by the object-property and\n * annotation atom families.\n */\nexport const snapshotForComparison = <V>(value: V): V => {\n if (Array.isArray(value)) {\n return [...value] as V;\n }\n // Refs are immutable handles whose `uri`/`target` are prototype getters over private fields, so a\n // spread would hand the consumer an empty object — `useObject(obj, refField).uri` read `undefined`.\n if (isRefLike(value)) {\n return value;\n }\n if (value !== null && typeof value === 'object') {\n return { ...value } as V;\n }\n return value;\n};\n\n/**\n * {@link snapshotForComparison} at every depth, for a value whose readers hold on to its nested records and arrays: a\n * shallow copy would hand them the same nested reference after an in-place change below the top level.\n */\nexport const snapshotDeep = <V>(value: V): V => {\n if (Array.isArray(value)) {\n return value.map(snapshotDeep) as V;\n }\n if (isRefLike(value)) {\n return value;\n }\n // Bytes and dates keep their class: the record branch below would turn them into plain objects.\n if (value instanceof Uint8Array) {\n return new Uint8Array(value) as V;\n }\n if (value instanceof Date) {\n return new Date(value.getTime()) as V;\n }\n if (value !== null && typeof value === 'object') {\n return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, snapshotDeep(entry)])) as V;\n }\n return value;\n};\n\n// Refs compare by URI: `RefImpl` mints a fresh wrapper on every property read, so `Object.is` never\n// matches two reads of the same ref. The inlined target is part of the ref's encoded value\n// (`{'/': uri, target}` for an object not yet in the database), so `Ref.make(target)` and a\n// `noInline()` of it share a URI without being the same value — comparing the URI alone would\n// swallow that update. The saved target is identity-stable across reads, so it needs no deeper\n// comparison.\nconst valueEquals = (a: unknown, b: unknown): boolean => {\n if (isRefLike(a) || isRefLike(b)) {\n return (\n isRefLike(a) &&\n isRefLike(b) &&\n a.uri.toString() === b.uri.toString() &&\n a._getSavedTarget?.() === b._getSavedTarget?.()\n );\n }\n // Records before `Object.is`: the snapshot shallow-copies the array, so a record element mutated in\n // place is the same reference on both sides and would otherwise read as unchanged.\n if (isRecord(a) || isRecord(b)) {\n return false;\n }\n return Object.is(a, b);\n};\n\n/**\n * Structural equality between two {@link snapshotDeep} results, which share no references below the top level, so\n * records and arrays compare by content at every depth. Refs compare as in {@link snapshotEquals}.\n */\nexport const snapshotDeepEquals = (a: unknown, b: unknown): boolean => {\n if (isRefLike(a) || isRefLike(b)) {\n return valueEquals(a, b);\n }\n if (a instanceof Date || b instanceof Date) {\n return a instanceof Date && b instanceof Date && Object.is(a.getTime(), b.getTime());\n }\n if (a instanceof Uint8Array || b instanceof Uint8Array) {\n return (\n a instanceof Uint8Array && b instanceof Uint8Array && a.length === b.length && a.every((byte, i) => byte === b[i])\n );\n }\n if (Array.isArray(a) || Array.isArray(b)) {\n return (\n Array.isArray(a) &&\n Array.isArray(b) &&\n a.length === b.length &&\n a.every((item, index) => snapshotDeepEquals(item, b[index]))\n );\n }\n if (isRecord(a) || isRecord(b)) {\n if (!isRecord(a) || !isRecord(b)) {\n return false;\n }\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => Object.hasOwn(b, key) && snapshotDeepEquals(a[key], b[key]))\n );\n }\n return Object.is(a, b);\n};\n\n/**\n * Change-detection equality between a live value and a previously emitted snapshot. Identity cannot\n * serve, because `snapshotForComparison` mints a fresh reference on every read, so unchanged content\n * still fails `===` and the atom re-fires on every mutation of the owning object.\n *\n * Records always compare unequal: consumers mutate nested fields in place (e.g. kanban's\n * `arrangement.columns[x].ids`), which a shallow top-level comparison cannot see.\n */\nexport const snapshotEquals = (value: unknown, snapshot: unknown): boolean => {\n if (Array.isArray(value) && Array.isArray(snapshot)) {\n return value.length === snapshot.length && value.every((item, index) => valueEquals(item, snapshot[index]));\n }\n // A ref held directly compares exactly as one inside an array does, so both go through `valueEquals`\n // — two ladders would drift and reintroduce the asymmetry that left a ref field always unequal.\n return valueEquals(value, snapshot);\n};\n"],"mappings":";;AAMA,IAAM,YAAY,UAChB,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAQrE,IAAM,aAAa,UACjB,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa;;;;;;;;AAS9D,IAAa,yBAA4B,UAAgB;CACvD,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,CAAC,GAAG,KAAK;CAIlB,IAAI,UAAU,KAAK,GACjB,OAAO;CAET,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO,EA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AAC,KACf,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,MAAM,UAAU,mBAAmB,MAAM,EAAE,MAAM,CAAC;CAG/D,IAAI,SAAS,CAAC,KAAK,SAAS,CAAC,GAAG;EAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,GAC7B,OAAO;EAET,MAAM,OAAO,OAAO,KAAK,CAAC;EAC1B,OACE,KAAK,WAAW,OAAO,KAAK,CAAC,CAAC,CAAC,UAC/B,KAAK,OAAO,QAAQ,OAAO,OAAO,GAAG,GAAG,KAAK,mBAAmB,EAAE,MAAM,EAAE,IAAI,CAAC;CAEnF;CACA,OAAO,OAAO,GAAG,GAAG,CAAC;AACvB;;;;;;;;;AAUA,IAAa,kBAAkB,OAAgB,aAA+B;CAC5E,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,QAAQ,GAChD,OAAO,MAAM,WAAW,SAAS,UAAU,MAAM,OAAO,MAAM,UAAU,YAAY,MAAM,SAAS,MAAM,CAAC;CAI5G,OAAO,YAAY,OAAO,QAAQ;AACpC"}
@@ -1,6 +1,6 @@
1
1
  import { d as SnapshotKindId, l as KindId } from "./chunk-util.mjs";
2
- import { nn as MetaId } from "./chunk-Database.mjs";
3
- import { o as createEchoReferenceSchema, v as change } from "./chunk-ref.mjs";
2
+ import { fn as MetaId, tn as TypeId } from "./chunk-Database.mjs";
3
+ import { v as change, z as EntityValueAnnotationId } from "./chunk-ref.mjs";
4
4
  import { ForeignKey } from "@dxos/echo-protocol";
5
5
  import { DXN } from "@dxos/keys";
6
6
  import * as Function from "effect/Function";
@@ -49,20 +49,29 @@ var __dxlog_file$1 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common
49
49
  */
50
50
  var ATTR_META = "@meta";
51
51
  /**
52
- * Schema for references to {@link Tag} objects stored in {@link EntityMetaSchema.tags}.
53
- *
54
- * Built from the shared {@link createEchoReferenceSchema} (the same builder `Ref.Ref` uses) via
55
- * `Schema.suspend`, so it reuses the canonical ref codec rather than duplicating it. The Tag type
56
- * identity comes from the shared {@link TagTypeDXN} constant; `suspend` defers construction until
57
- * first use, and `Tag` is referenced type-only, so no `Tag` value import is needed.
52
+ * Whether the value is a {@link Tag} entity. Read off the entity's own kind and type stamps, so
53
+ * neither `Tag` nor the annotation helpers are imported here (both would form an eval-order cycle).
58
54
  */
59
- var TagRefSchema = Schema.suspend(() => createEchoReferenceSchema(void 0, DXN.getName(TagTypeDXN), DXN.getVersion(TagTypeDXN)));
55
+ var isTagEntity = (value) => {
56
+ if (value == null || typeof value !== "object" || Reflect.get(value, "~@dxos/echo/Kind") === void 0) return false;
57
+ const type = Reflect.get(value, TypeId);
58
+ const dxn = DXN.isDXN(type) ? DXN.tryMake(type) : void 0;
59
+ return dxn != null && DXN.getName(dxn) === DXN.getName(TagTypeDXN);
60
+ };
61
+ /**
62
+ * Schema for the {@link Tag} entities in {@link EntityMetaSchema.tags}: a strong dependency, held by
63
+ * identity like a relation endpoint, and persisted as a reference.
64
+ */
65
+ var TagEntitySchema = Schema.declare(isTagEntity, {
66
+ identifier: "Tag",
67
+ [EntityValueAnnotationId]: true
68
+ });
60
69
  var EntityMetaSchema = Schema.Struct({
61
70
  keys: Schema.Array(ForeignKey),
62
71
  /**
63
- * Tags applied to this entity, as references to {@link Tag} objects.
72
+ * Tags applied to this entity: {@link Tag} objects, loaded with the entity as strong dependencies.
64
73
  */
65
- tags: Schema.Array(TagRefSchema),
74
+ tags: Schema.Array(TagEntitySchema),
66
75
  /**
67
76
  * Fully-qualified registry key for the object (FQN format, e.g. `com.example.type.foo`).
68
77
  * Identifies the canonical registry entry the object instance was created from.
@@ -127,7 +136,7 @@ var getMeta = (obj) => {
127
136
  invariant(metadata, "EntityMeta not found.", {
128
137
  "~LogMeta": "~LogMeta",
129
138
  F: __dxlog_file$1,
130
- L: 132,
139
+ L: 137,
131
140
  S: void 0,
132
141
  A: ["metadata", "'EntityMeta not found.'"]
133
142
  });
@@ -148,7 +157,7 @@ function getMetaChecked(entity) {
148
157
  invariant(meta != null, "Invalid entity.", {
149
158
  "~LogMeta": "~LogMeta",
150
159
  F: __dxlog_file,
151
- L: 37,
160
+ L: 36,
152
161
  S: this,
153
162
  A: ["meta != null", "'Invalid entity.'"]
154
163
  });
@@ -164,7 +173,7 @@ var getKeys = (entity, source) => {
164
173
  invariant(meta != null, "Invalid entity.", {
165
174
  "~LogMeta": "~LogMeta",
166
175
  F: __dxlog_file,
167
- L: 48,
176
+ L: 47,
168
177
  S: void 0,
169
178
  A: ["meta != null", "'Invalid entity.'"]
170
179
  });
@@ -182,20 +191,20 @@ var deleteKeys = (entity, source) => {
182
191
  }
183
192
  };
184
193
  /**
185
- * Add a tag (a reference to a {@link Tag} object) to the entity. Idempotent.
194
+ * Add a {@link Tag} to the entity. Idempotent.
186
195
  * Must be called within an Obj.update or Relation.update callback.
187
196
  */
188
197
  var addTag = (entity, tag) => {
189
198
  const meta = getMetaChecked(entity);
190
- if (!meta.tags.some((existing) => existing.uri === tag.uri)) meta.tags.push(tag);
199
+ if (!meta.tags.some((existing) => existing.id === tag.id)) meta.tags.push(tag);
191
200
  };
192
201
  /**
193
- * Remove a tag (a reference to a {@link Tag} object) from the entity. No-op when not present.
202
+ * Remove a {@link Tag} from the entity. No-op when not present.
194
203
  * Must be called within an Obj.update or Relation.update callback.
195
204
  */
196
205
  var removeTag = (entity, tag) => {
197
206
  const meta = getMetaChecked(entity);
198
- for (let i = 0; i < meta.tags.length; i++) if (meta.tags[i].uri === tag.uri) {
207
+ for (let i = 0; i < meta.tags.length; i++) if (meta.tags[i].id === tag.id) {
199
208
  meta.tags.splice(i, 1);
200
209
  i--;
201
210
  }
@@ -259,6 +268,6 @@ var update = (target, annotation, mutator) => {
259
268
  });
260
269
  };
261
270
  //#endregion
262
- export { TagTypeDXN as _, addTag as a, getDictionary as b, getMetaChecked as c, EntityMetaSchema as d, SCALAR_META_FIELDS as f, getMeta as g, foreignKeyEquals as h, isEntity as i, removeTag as l, foreignKey as m, set as n, deleteKeys as o, compareForeignKeys as p, update as r, getKeys as s, get as t, ATTR_META as u, Dictionary as v, setDictionary as x, Key as y };
271
+ export { setDictionary as S, isTagEntity as _, addTag as a, Key as b, getMetaChecked as c, EntityMetaSchema as d, SCALAR_META_FIELDS as f, getMeta as g, foreignKeyEquals as h, isEntity as i, removeTag as l, foreignKey as m, set as n, deleteKeys as o, compareForeignKeys as p, update as r, getKeys as s, get as t, ATTR_META as u, TagTypeDXN as v, getDictionary as x, Dictionary as y };
263
272
 
264
273
  //# sourceMappingURL=chunk-entity-dictionary.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-entity-dictionary.mjs","names":["__dxlog_file","getMeta$"],"sources":["../../src/internal/Annotation/dictionary.ts","../../src/internal/common/types/well-known-types.ts","../../src/internal/common/types/meta.ts","../../src/internal/common/api/meta.ts","../../src/internal/Entity/guard.ts","../../src/internal/Annotation/entity-dictionary.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as Types from 'effect/Types';\n\nimport type * as Annotation from '../../Annotation.ts';\n\n/**\n * Unique identifier for an annotation.\n */\nexport const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/AnnotationKey'));\nexport type Key = Schema.Schema.Type<typeof Key>;\n\n/**\n * Set of annotation values stored on entity meta or nested in schemas.\n */\nexport const Dictionary = Schema.Record(Key, Schema.Unknown);\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a dictionary.\n */\nexport const getDictionary = <T>(\n values: Annotation.Dictionary,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (!(annotation.key in values)) {\n return Option.none();\n }\n\n return Function.pipe(values[annotation.key], Schema.decodeUnknownSync(annotation.schema), Option.some);\n};\n\n/**\n * Set the value of an annotation in a dictionary.\n */\nexport const setDictionary = <T>(\n values: Types.Mutable<Annotation.Dictionary>,\n annotation: Annotation.Annotation<T>,\n value: T,\n): void => {\n values[annotation.key] = Schema.encodeSync(annotation.schema)(value);\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { DXN } from '@dxos/keys';\n\n/**\n * DXN identity of the system {@link Tag} type.\n *\n * Defined in this low-level leaf so it can be shared by the public `Tag` type (which brands the\n * schema with this DXN) and by `EntityMetaSchema.tags` (which builds a `Ref<Tag>` schema from it)\n * without either importing the other — `Tag` is top-level and `meta` is deep-internal, so a direct\n * dependency between them would form an eval-order cycle.\n */\nexport const TagTypeDXN = DXN.make('org.dxos.type.tag', '0.1.0');\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type EncodedReference, ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport { type Comparator, intersection } from '@dxos/util';\n\nimport type * as Tag from '../../../Tag.ts';\nimport { Dictionary } from '../../Annotation/dictionary.ts';\n// `meta` is no longer re-exported from the `common/types` barrel (see ./index.ts), so importing the\n// Ref schema builder here no longer forms an eval-order cycle with `Annotation`/`Database`.\nimport { type Ref, createEchoReferenceSchema } from '../../Ref/ref.ts';\nimport { type AnyProperties } from './base.ts';\nimport { MetaId } from './model-symbols.ts';\nimport { TagTypeDXN } from './well-known-types.ts';\n\n/**\n * Property name for meta when object is serialized to JSON.\n */\nexport const ATTR_META = '@meta';\n\n//\n// EntityMeta\n//\n\n/**\n * Schema for references to {@link Tag} objects stored in {@link EntityMetaSchema.tags}.\n *\n * Built from the shared {@link createEchoReferenceSchema} (the same builder `Ref.Ref` uses) via\n * `Schema.suspend`, so it reuses the canonical ref codec rather than duplicating it. The Tag type\n * identity comes from the shared {@link TagTypeDXN} constant; `suspend` defers construction until\n * first use, and `Tag` is referenced type-only, so no `Tag` value import is needed.\n */\nconst TagRefSchema = Schema.suspend(\n (): Schema.Codec<Ref<Tag.Tag>, EncodedReference> =>\n // The factory yields a loosely-typed `Ref<any>` schema; narrow it to the Tag-typed ref.\n createEchoReferenceSchema(undefined, DXN.getName(TagTypeDXN), DXN.getVersion(TagTypeDXN)) as Schema.Codec<\n Ref<Tag.Tag>,\n EncodedReference\n >,\n);\n\nexport const EntityMetaSchema = Schema.Struct({\n keys: Schema.Array(ForeignKey),\n\n /**\n * Tags applied to this entity, as references to {@link Tag} objects.\n */\n tags: Schema.Array(TagRefSchema),\n\n /**\n * Fully-qualified registry key for the object (FQN format, e.g. `com.example.type.foo`).\n * Identifies the canonical registry entry the object instance was created from.\n */\n key: Schema.optional(Schema.String),\n\n /**\n * Semantic version of the registry entry the object was created from.\n * Must be a valid semver string (e.g. `1.2.3`).\n */\n version: Schema.optional(Schema.String),\n\n /**\n * Caller-supplied domain identity, unique within a space: two entities carrying the same\n * convergence key are the same entity and are merged into one. Declared by assigning this\n * field inside an update callback — `Entity.update(x, (x) => { Entity.getMeta(x).convergenceKey = '…' })`\n * — so it batches with the caller's other writes; there is deliberately no dedicated setter.\n *\n * Objects only: the merge engine ignores the field on relations and types (not merge subjects\n * yet), and treats the empty string as no key — both are verified at detection, in the worker,\n * and in the client executor rather than at write time, since the field replicates from peers\n * that cannot be trusted to have validated it.\n *\n * Opaque to the storage engine — callers that need generations encode them in the string\n * (e.g. `com.example.seed@2`), which yields distinct entities because the strings differ.\n * Distinct from `key`/`version` above, which record the registry entry an instance was\n * created from (provenance, not identity).\n */\n convergenceKey: Schema.optional(Schema.String),\n\n /**\n * Dictionary of annotations to this entity.\n */\n annotations: Dictionary,\n\n /**\n * Unix ms timestamp when this entity was created.\n * Read-only; sourced from the system section of the automerge document — not stored in meta.\n */\n createdAt: Schema.optional(Schema.Number),\n\n /**\n * Unix ms timestamp of the last automerge change on this entity's document.\n * Read-only; derived from the automerge change graph — not stored in meta.\n */\n updatedAt: Schema.optional(Schema.Number),\n});\n\nexport type EntityMeta = Schema.Schema.Type<typeof EntityMetaSchema>;\n\n/** Copied element-wise rather than by value, so that a snapshot is not aliased to the live meta. */\nconst CONTAINER_META_FIELDS: readonly string[] = ['keys', 'tags', 'annotations'];\n\n/** Derived at read time from the system section and the change graph; never stored in meta. */\nconst VIRTUAL_META_FIELDS: readonly string[] = ['createdAt', 'updatedAt'];\n\n/**\n * Stored meta fields holding a single scalar value.\n *\n * Derived from the schema rather than listed by hand: several places enumerate meta fields —\n * snapshotting copies them, and persistence decides from them whether the meta section is worth\n * writing at all — and a hand-maintained list silently drops any field added later, so the field\n * appears to work until it crosses one of those boundaries.\n */\nexport const SCALAR_META_FIELDS: readonly string[] = Object.keys(EntityMetaSchema.fields).filter(\n (field) => !CONTAINER_META_FIELDS.includes(field) && !VIRTUAL_META_FIELDS.includes(field),\n);\n\n/*\n * Get metadata from object.\n * Only callable on the object root.\n *\n * @internal (use Obj.getMeta or Relation.getMeta)\n */\n// TODO(burdon): Refine type to BaseObj.\nexport const getMeta = (obj: AnyProperties): EntityMeta => {\n const metadata = (obj as any)[MetaId];\n invariant(metadata, 'EntityMeta not found.');\n return metadata;\n};\n\n//\n// Foreign keys\n//\n\nexport const foreignKey = (source: string, id: string): ForeignKey => ({ source, id });\nexport const foreignKeyEquals = (a: ForeignKey, b: ForeignKey) => a.source === b.source && a.id === b.id;\n\n// TODO(dmaretskyi): Move to echo-schema.\nexport const compareForeignKeys: Comparator<AnyProperties> = (a: AnyProperties, b: AnyProperties) =>\n intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DeepReadonly } from '@dxos/util';\n\nimport type * as Tag from '../../../Tag.ts';\nimport type { Ref } from '../../Ref/ref.ts';\nimport { type Mutable } from '../proxy/index.ts';\nimport { type AnyProperties } from '../types/index.ts';\nimport { type EntityMeta, getMeta as getMeta$ } from '../types/meta.ts';\n\n/**\n * Deeply read-only version of EntityMeta.\n */\nexport type ReadonlyMeta = DeepReadonly<EntityMeta>;\n\n/**\n * Mutable meta type received in meta mutation callbacks.\n */\nexport type Meta = Mutable<EntityMeta>;\n\n/**\n * Get the metadata for an entity with validation.\n * Returns mutable meta when passed a mutable entity (inside change callback).\n * Returns read-only meta when passed a regular entity or snapshot.\n *\n * TODO(burdon): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\n */\nexport function getMetaChecked(entity: Mutable<AnyProperties>): Meta;\nexport function getMetaChecked(entity: AnyProperties): ReadonlyMeta;\nexport function getMetaChecked(entity: AnyProperties): Meta | ReadonlyMeta {\n assertArgument(entity, 'entity', 'Should be an entity.');\n const meta = getMeta$(entity);\n invariant(meta != null, 'Invalid entity.');\n return meta;\n}\n\n/**\n * @returns Foreign keys for the entity from the specified source.\n * Accepts both reactive entities and snapshots.\n */\nexport const getKeys = (entity: AnyProperties, source: string): ForeignKey[] => {\n assertArgument(entity, 'entity', 'Should be an entity.');\n const meta = getMetaChecked(entity);\n invariant(meta != null, 'Invalid entity.');\n return meta.keys.filter((key) => key.source === source);\n};\n\n/**\n * Delete all keys from the entity for the specified source.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const deleteKeys = (entity: Mutable<AnyProperties>, source: string) => {\n const meta = getMetaChecked(entity);\n for (let i = 0; i < meta.keys.length; i++) {\n if (meta.keys[i].source === source) {\n meta.keys.splice(i, 1);\n i--;\n }\n }\n};\n\n/**\n * Add a tag (a reference to a {@link Tag} object) to the entity. Idempotent.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const addTag = (entity: Mutable<AnyProperties>, tag: Ref<Tag.Tag>) => {\n const meta = getMetaChecked(entity);\n // Two refs to the same target are not `===`; dedupe by URI.\n if (!meta.tags.some((existing) => existing.uri === tag.uri)) {\n meta.tags.push(tag);\n }\n};\n\n/**\n * Remove a tag (a reference to a {@link Tag} object) from the entity. No-op when not present.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const removeTag = (entity: Mutable<AnyProperties>, tag: Ref<Tag.Tag>) => {\n const meta = getMetaChecked(entity);\n for (let i = 0; i < meta.tags.length; i++) {\n if (meta.tags[i].uri === tag.uri) {\n meta.tags.splice(i, 1);\n i--;\n }\n }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as Entity from '../../Entity.ts';\nimport { KindId, SnapshotKindId } from '../common/types/index.ts';\n\n/**\n * Returns true if the value is an ECHO entity instance (object or relation).\n */\nexport const isEntity = (value: unknown): value is Entity.Unknown => {\n // (some) type entities are functions since they are class declarations.\n if (value == null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n return (value as any)[KindId] !== undefined;\n};\n\n/**\n * Returns true if the value is an ECHO entity snapshot.\n */\nexport const isSnapshot = (value: unknown): value is Entity.Snapshot => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[SnapshotKindId] !== undefined;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport type * as Annotation from '../../Annotation.ts';\nimport type * as Entity from '../../Entity.ts';\nimport { getMetaChecked } from '../common/api/meta.ts';\nimport { type Mutable, change } from '../common/proxy/reactive.ts';\nimport { isEntity, isSnapshot } from '../Entity/guard.ts';\n\n/**\n * Get the value of an annotation from an entity instance or snapshot.\n *\n * The value is read-only (schema types are readonly by default). To mutate it, use {@link update}\n * (which reads it as mutable inside a change transaction); the reactive proxy rejects mutation of the\n * live value outside an `Obj.update`. Snapshots return a detached copy.\n */\nexport const get = <T>(\n target: Entity.Unknown | Entity.Snapshot,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (!isEntity(target) && !isSnapshot(target)) {\n throw new TypeError('Target is not an annotation target.');\n }\n\n // The dictionary slot is typed `unknown`; at runtime it holds the annotation's decoded value (the\n // proxy codecs nested refs in both directions, and a snapshot deep-copies what the proxy yields),\n // so the read coerces to the declared type rather than decoding a second time.\n const annotations = getMetaChecked(target).annotations;\n return annotation.key in annotations ? Option.some(annotations[annotation.key] as T) : Option.none();\n};\n\n/**\n * Set the value of an annotation on an entity instance.\n * Must be called with a mutable entity — i.e. inside an `Obj.update` callback.\n *\n * The value is assigned directly to the reactive meta dictionary; the proxy encodes nested Refs and\n * links their unsaved targets on write (matching ordinary property assignment), so no manual\n * encode/persist step is needed.\n */\nexport const set = <T>(target: Mutable<Entity.Unknown>, annotation: Annotation.Annotation<T>, value: T): void => {\n if (isEntity(target)) {\n // The dictionary slot is untyped, so the proxy can't validate against the annotation schema;\n // validate here (without encoding — the proxy encodes nested refs and links targets on assignment).\n Schema.decodeSync(Schema.toType(annotation.schema))(value);\n getMetaChecked(target).annotations[annotation.key] = value;\n } else {\n throw new TypeError('Target is not an annotation target.');\n }\n};\n\n/**\n * Mutate an existing annotation value in place via a callback, wrapping the mutation in a change\n * transaction (like `Obj.update`). Use when only an annotation needs to change. No-op when absent.\n */\nexport const update = <T>(\n target: Entity.Unknown,\n annotation: Annotation.Annotation<T>,\n mutator: (value: Mutable<T>) => void,\n): void => {\n change(target, (mutable) => {\n const current = get(mutable, annotation);\n if (Option.isSome(current)) {\n // `get` returns the value read-only; inside this change transaction the live value is mutable.\n const value = current.value as Mutable<T>;\n mutator(value);\n // Validate against the annotation's own schema — the dictionary slot is untyped, so the proxy\n // can't. Schema validation checks ref structure only (not targets), so it is cycle-safe.\n Schema.decodeUnknownSync(Schema.toType(annotation.schema))(value);\n }\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,MAAM,OAAO,OAAO,KAAK,OAAO,MAAM,2BAA2B,CAAC;;;;AAM/E,IAAa,aAAa,OAAO,OAAO,KAAK,OAAO,OAAO;;;;AAM3D,IAAa,iBACX,QACA,eACqB;CACrB,IAAI,EAAE,WAAW,OAAO,SACtB,OAAO,OAAO,KAAK;CAGrB,OAAO,SAAS,KAAK,OAAO,WAAW,MAAM,OAAO,kBAAkB,WAAW,MAAM,GAAG,OAAO,IAAI;AACvG;;;;AAKA,IAAa,iBACX,QACA,YACA,UACS;CACT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AC;EACrB;CACF;AAEJ;;;;;;AC/EA,IAAa,YAAY,UAA4C;CAEnE,IAAI,SAAS,QAAS,OAAO,UAAU,YAAY,OAAO,UAAU,YAClE,OAAO;CAET,OAAQ,MAAc,YAAY,KAAA;AACpC;;;;AAKA,IAAa,cAAc,UAA6C;CACtE,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;CAET,OAAQ,MAAc,oBAAoB,KAAA;AAC5C;;;;;;;;;;ACNA,IAAa,OACX,QACA,eACqB;CACrB,IAAI,CAAC,SAAS,MAAM,KAAK,CAAC,WAAW,MAAM,GACzC,MAAM,IAAI,UAAU,qCAAqC;CAM3D,MAAM,cAAc,eAAe,MAAM,CAAC,CAAC;CAC3C,OAAO,WAAW,OAAO,cAAc,OAAO,KAAK,YAAY,WAAW,IAAS,IAAI,OAAO,KAAK;AACrG;;;;;;;;;AAUA,IAAa,OAAU,QAAiC,YAAsC,UAAmB;CAC/G,IAAI,SAAS,MAAM,GAAG;EAGpB,OAAO,WAAW,OAAO,OAAO,WAAW,MAAM,CAAC,CAAC,CAAC,KAAK;EACzD,eAAe,MAAM,CAAC,CAAC,YAAY,WAAW,OAAO;CACvD,OACE,MAAM,IAAI,UAAU,qCAAqC;AAE7D;;;;;AAMA,IAAa,UACX,QACA,YACA,YACS;CACT,OAAO,SAAS,YAAY;EAC1B,MAAM,UAAU,IAAI,SAAS,UAAU;EACvC,IAAI,OAAO,OAAO,OAAO,GAAG;GAE1B,MAAM,QAAQ,QAAQ;GACtB,QAAQ,KAAK;GAGb,OAAO,kBAAkB,OAAO,OAAO,WAAW,MAAM,CAAC,CAAC,CAAC,KAAK;EAClE;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"chunk-entity-dictionary.mjs","names":["__dxlog_file","getMeta$"],"sources":["../../src/internal/Annotation/dictionary.ts","../../src/internal/common/types/well-known-types.ts","../../src/internal/common/types/meta.ts","../../src/internal/common/api/meta.ts","../../src/internal/Entity/guard.ts","../../src/internal/Annotation/entity-dictionary.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as Types from 'effect/Types';\n\nimport type * as Annotation from '../../Annotation.ts';\n\n/**\n * Unique identifier for an annotation.\n */\nexport const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/AnnotationKey'));\nexport type Key = Schema.Schema.Type<typeof Key>;\n\n/**\n * Set of annotation values stored on entity meta or nested in schemas.\n */\nexport const Dictionary = Schema.Record(Key, Schema.Unknown);\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a dictionary.\n */\nexport const getDictionary = <T>(\n values: Annotation.Dictionary,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (!(annotation.key in values)) {\n return Option.none();\n }\n\n return Function.pipe(values[annotation.key], Schema.decodeUnknownSync(annotation.schema), Option.some);\n};\n\n/**\n * Set the value of an annotation in a dictionary.\n */\nexport const setDictionary = <T>(\n values: Types.Mutable<Annotation.Dictionary>,\n annotation: Annotation.Annotation<T>,\n value: T,\n): void => {\n values[annotation.key] = Schema.encodeSync(annotation.schema)(value);\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { DXN } from '@dxos/keys';\n\n/**\n * DXN identity of the system {@link Tag} type.\n *\n * Defined in this low-level leaf so it can be shared by the public `Tag` type (which brands the\n * schema with this DXN) and by `EntityMetaSchema.tags` (which builds a `Ref<Tag>` schema from it)\n * without either importing the other — `Tag` is top-level and `meta` is deep-internal, so a direct\n * dependency between them would form an eval-order cycle.\n */\nexport const TagTypeDXN = DXN.make('org.dxos.type.tag', '0.1.0');\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport { type Comparator, intersection } from '@dxos/util';\n\nimport type * as Tag from '../../../Tag.ts';\nimport { Dictionary } from '../../Annotation/dictionary.ts';\nimport { EntityValueAnnotationId } from '../proxy/symbols.ts';\nimport { type AnyProperties } from './base.ts';\nimport { KindId } from './entity.ts';\nimport { MetaId } from './model-symbols.ts';\nimport { TypeId } from './typename.ts';\nimport { TagTypeDXN } from './well-known-types.ts';\n\n/**\n * Property name for meta when object is serialized to JSON.\n */\nexport const ATTR_META = '@meta';\n\n//\n// EntityMeta\n//\n\n/**\n * Whether the value is a {@link Tag} entity. Read off the entity's own kind and type stamps, so\n * neither `Tag` nor the annotation helpers are imported here (both would form an eval-order cycle).\n */\nexport const isTagEntity = (value: unknown): value is Tag.Tag => {\n if (value == null || typeof value !== 'object' || Reflect.get(value, KindId) === undefined) {\n return false;\n }\n const type = Reflect.get(value, TypeId);\n const dxn = DXN.isDXN(type) ? DXN.tryMake(type) : undefined;\n return dxn != null && DXN.getName(dxn) === DXN.getName(TagTypeDXN);\n};\n\n/**\n * Schema for the {@link Tag} entities in {@link EntityMetaSchema.tags}: a strong dependency, held by\n * identity like a relation endpoint, and persisted as a reference.\n */\nconst TagEntitySchema = Schema.declare(isTagEntity, {\n identifier: 'Tag',\n [EntityValueAnnotationId]: true,\n});\n\nexport const EntityMetaSchema = Schema.Struct({\n keys: Schema.Array(ForeignKey),\n\n /**\n * Tags applied to this entity: {@link Tag} objects, loaded with the entity as strong dependencies.\n */\n tags: Schema.Array(TagEntitySchema),\n\n /**\n * Fully-qualified registry key for the object (FQN format, e.g. `com.example.type.foo`).\n * Identifies the canonical registry entry the object instance was created from.\n */\n key: Schema.optional(Schema.String),\n\n /**\n * Semantic version of the registry entry the object was created from.\n * Must be a valid semver string (e.g. `1.2.3`).\n */\n version: Schema.optional(Schema.String),\n\n /**\n * Caller-supplied domain identity, unique within a space: two entities carrying the same\n * convergence key are the same entity and are merged into one. Declared by assigning this\n * field inside an update callback — `Entity.update(x, (x) => { Entity.getMeta(x).convergenceKey = '…' })`\n * — so it batches with the caller's other writes; there is deliberately no dedicated setter.\n *\n * Objects only: the merge engine ignores the field on relations and types (not merge subjects\n * yet), and treats the empty string as no key — both are verified at detection, in the worker,\n * and in the client executor rather than at write time, since the field replicates from peers\n * that cannot be trusted to have validated it.\n *\n * Opaque to the storage engine — callers that need generations encode them in the string\n * (e.g. `com.example.seed@2`), which yields distinct entities because the strings differ.\n * Distinct from `key`/`version` above, which record the registry entry an instance was\n * created from (provenance, not identity).\n */\n convergenceKey: Schema.optional(Schema.String),\n\n /**\n * Dictionary of annotations to this entity.\n */\n annotations: Dictionary,\n\n /**\n * Unix ms timestamp when this entity was created.\n * Read-only; sourced from the system section of the automerge document — not stored in meta.\n */\n createdAt: Schema.optional(Schema.Number),\n\n /**\n * Unix ms timestamp of the last automerge change on this entity's document.\n * Read-only; derived from the automerge change graph — not stored in meta.\n */\n updatedAt: Schema.optional(Schema.Number),\n});\n\nexport type EntityMeta = Schema.Schema.Type<typeof EntityMetaSchema>;\n\n/** Copied element-wise rather than by value, so that a snapshot is not aliased to the live meta. */\nconst CONTAINER_META_FIELDS: readonly string[] = ['keys', 'tags', 'annotations'];\n\n/** Derived at read time from the system section and the change graph; never stored in meta. */\nconst VIRTUAL_META_FIELDS: readonly string[] = ['createdAt', 'updatedAt'];\n\n/**\n * Stored meta fields holding a single scalar value.\n *\n * Derived from the schema rather than listed by hand: several places enumerate meta fields —\n * snapshotting copies them, and persistence decides from them whether the meta section is worth\n * writing at all — and a hand-maintained list silently drops any field added later, so the field\n * appears to work until it crosses one of those boundaries.\n */\nexport const SCALAR_META_FIELDS: readonly string[] = Object.keys(EntityMetaSchema.fields).filter(\n (field) => !CONTAINER_META_FIELDS.includes(field) && !VIRTUAL_META_FIELDS.includes(field),\n);\n\n/*\n * Get metadata from object.\n * Only callable on the object root.\n *\n * @internal (use Obj.getMeta or Relation.getMeta)\n */\n// TODO(burdon): Refine type to BaseObj.\nexport const getMeta = (obj: AnyProperties): EntityMeta => {\n const metadata = (obj as any)[MetaId];\n invariant(metadata, 'EntityMeta not found.');\n return metadata;\n};\n\n//\n// Foreign keys\n//\n\nexport const foreignKey = (source: string, id: string): ForeignKey => ({ source, id });\nexport const foreignKeyEquals = (a: ForeignKey, b: ForeignKey) => a.source === b.source && a.id === b.id;\n\n// TODO(dmaretskyi): Move to echo-schema.\nexport const compareForeignKeys: Comparator<AnyProperties> = (a: AnyProperties, b: AnyProperties) =>\n intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DeepReadonly } from '@dxos/util';\n\nimport type * as Tag from '../../../Tag.ts';\nimport { type Mutable } from '../proxy/index.ts';\nimport { type AnyProperties } from '../types/index.ts';\nimport { type EntityMeta, getMeta as getMeta$ } from '../types/meta.ts';\n\n/**\n * Deeply read-only version of EntityMeta.\n */\nexport type ReadonlyMeta = DeepReadonly<EntityMeta>;\n\n/**\n * Mutable meta type received in meta mutation callbacks.\n */\nexport type Meta = Mutable<EntityMeta>;\n\n/**\n * Get the metadata for an entity with validation.\n * Returns mutable meta when passed a mutable entity (inside change callback).\n * Returns read-only meta when passed a regular entity or snapshot.\n *\n * TODO(burdon): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\n */\nexport function getMetaChecked(entity: Mutable<AnyProperties>): Meta;\nexport function getMetaChecked(entity: AnyProperties): ReadonlyMeta;\nexport function getMetaChecked(entity: AnyProperties): Meta | ReadonlyMeta {\n assertArgument(entity, 'entity', 'Should be an entity.');\n const meta = getMeta$(entity);\n invariant(meta != null, 'Invalid entity.');\n return meta;\n}\n\n/**\n * @returns Foreign keys for the entity from the specified source.\n * Accepts both reactive entities and snapshots.\n */\nexport const getKeys = (entity: AnyProperties, source: string): ForeignKey[] => {\n assertArgument(entity, 'entity', 'Should be an entity.');\n const meta = getMetaChecked(entity);\n invariant(meta != null, 'Invalid entity.');\n return meta.keys.filter((key) => key.source === source);\n};\n\n/**\n * Delete all keys from the entity for the specified source.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const deleteKeys = (entity: Mutable<AnyProperties>, source: string) => {\n const meta = getMetaChecked(entity);\n for (let i = 0; i < meta.keys.length; i++) {\n if (meta.keys[i].source === source) {\n meta.keys.splice(i, 1);\n i--;\n }\n }\n};\n\n/**\n * Add a {@link Tag} to the entity. Idempotent.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const addTag = (entity: Mutable<AnyProperties>, tag: Tag.Tag) => {\n const meta = getMetaChecked(entity);\n // Deduped by id: a snapshot or a mutable view of the same tag is not `===` to the live entity.\n if (!meta.tags.some((existing) => existing.id === tag.id)) {\n meta.tags.push(tag);\n }\n};\n\n/**\n * Remove a {@link Tag} from the entity. No-op when not present.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const removeTag = (entity: Mutable<AnyProperties>, tag: Tag.Tag) => {\n const meta = getMetaChecked(entity);\n for (let i = 0; i < meta.tags.length; i++) {\n if (meta.tags[i].id === tag.id) {\n meta.tags.splice(i, 1);\n i--;\n }\n }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as Entity from '../../Entity.ts';\nimport { KindId, SnapshotKindId } from '../common/types/index.ts';\n\n/**\n * Returns true if the value is an ECHO entity instance (object or relation).\n */\nexport const isEntity = (value: unknown): value is Entity.Unknown => {\n // (some) type entities are functions since they are class declarations.\n if (value == null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n return (value as any)[KindId] !== undefined;\n};\n\n/**\n * Returns true if the value is an ECHO entity snapshot.\n */\nexport const isSnapshot = (value: unknown): value is Entity.Snapshot => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[SnapshotKindId] !== undefined;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport type * as Annotation from '../../Annotation.ts';\nimport type * as Entity from '../../Entity.ts';\nimport { getMetaChecked } from '../common/api/meta.ts';\nimport { type Mutable, change } from '../common/proxy/reactive.ts';\nimport { isEntity, isSnapshot } from '../Entity/guard.ts';\n\n/**\n * Get the value of an annotation from an entity instance or snapshot.\n *\n * The value is read-only (schema types are readonly by default). To mutate it, use {@link update}\n * (which reads it as mutable inside a change transaction); the reactive proxy rejects mutation of the\n * live value outside an `Obj.update`. Snapshots return a detached copy.\n */\nexport const get = <T>(\n target: Entity.Unknown | Entity.Snapshot,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (!isEntity(target) && !isSnapshot(target)) {\n throw new TypeError('Target is not an annotation target.');\n }\n\n // The dictionary slot is typed `unknown`; at runtime it holds the annotation's decoded value (the\n // proxy codecs nested refs in both directions, and a snapshot deep-copies what the proxy yields),\n // so the read coerces to the declared type rather than decoding a second time.\n const annotations = getMetaChecked(target).annotations;\n return annotation.key in annotations ? Option.some(annotations[annotation.key] as T) : Option.none();\n};\n\n/**\n * Set the value of an annotation on an entity instance.\n * Must be called with a mutable entity — i.e. inside an `Obj.update` callback.\n *\n * The value is assigned directly to the reactive meta dictionary; the proxy encodes nested Refs and\n * links their unsaved targets on write (matching ordinary property assignment), so no manual\n * encode/persist step is needed.\n */\nexport const set = <T>(target: Mutable<Entity.Unknown>, annotation: Annotation.Annotation<T>, value: T): void => {\n if (isEntity(target)) {\n // The dictionary slot is untyped, so the proxy can't validate against the annotation schema;\n // validate here (without encoding — the proxy encodes nested refs and links targets on assignment).\n Schema.decodeSync(Schema.toType(annotation.schema))(value);\n getMetaChecked(target).annotations[annotation.key] = value;\n } else {\n throw new TypeError('Target is not an annotation target.');\n }\n};\n\n/**\n * Mutate an existing annotation value in place via a callback, wrapping the mutation in a change\n * transaction (like `Obj.update`). Use when only an annotation needs to change. No-op when absent.\n */\nexport const update = <T>(\n target: Entity.Unknown,\n annotation: Annotation.Annotation<T>,\n mutator: (value: Mutable<T>) => void,\n): void => {\n change(target, (mutable) => {\n const current = get(mutable, annotation);\n if (Option.isSome(current)) {\n // `get` returns the value read-only; inside this change transaction the live value is mutable.\n const value = current.value as Mutable<T>;\n mutator(value);\n // Validate against the annotation's own schema — the dictionary slot is untyped, so the proxy\n // can't. Schema validation checks ref structure only (not targets), so it is cycle-safe.\n Schema.decodeUnknownSync(Schema.toType(annotation.schema))(value);\n }\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,MAAM,OAAO,OAAO,KAAK,OAAO,MAAM,2BAA2B,CAAC;;;;AAM/E,IAAa,aAAa,OAAO,OAAO,KAAK,OAAO,OAAO;;;;AAM3D,IAAa,iBACX,QACA,eACqB;CACrB,IAAI,EAAE,WAAW,OAAO,SACtB,OAAO,OAAO,KAAK;CAGrB,OAAO,SAAS,KAAK,OAAO,WAAW,MAAM,OAAO,kBAAkB,WAAW,MAAM,GAAG,OAAO,IAAI;AACvG;;;;AAKA,IAAa,iBACX,QACA,YACA,UACS;CACT,OAAO,WAAW,OAAO,OAAO,WAAW,WAAW,MAAM,CAAC,CAAC,KAAK;AACrE;;;;;;;;;;;AChCA,IAAa,aAAa,IAAI,KAAK,qBAAqB,OAAO;;;;;;;ACS/D,IAAa,YAAY;;;;;AAUzB,IAAa,eAAe,UAAqC;CAC/D,IAAI,SAAS,QAAQ,OAAO,UAAU,YAAY,QAAQ,IAAI,OAAA,kBAAa,MAAM,KAAA,GAC/E,OAAO;CAET,MAAM,OAAO,QAAQ,IAAI,OAAO,MAAM;CACtC,MAAM,MAAM,IAAI,MAAM,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAA;CAClD,OAAO,OAAO,QAAQ,IAAI,QAAQ,GAAG,MAAM,IAAI,QAAQ,UAAU;AACnE;;;;;AAMA,IAAM,kBAAkB,OAAO,QAAQ,aAAa;CAClD,YAAY;EACX,0BAA0B;AAC7B,CAAC;AAED,IAAa,mBAAmB,OAAO,OAAO;CAC5C,MAAM,OAAO,MAAM,UAAU;;;;CAK7B,MAAM,OAAO,MAAM,eAAe;;;;;CAMlC,KAAK,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