@dxos/echo 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/dist/lib/Annotation.mjs +3 -0
  2. package/dist/lib/Blob.mjs +160 -0
  3. package/dist/lib/Blob.mjs.map +1 -0
  4. package/dist/lib/Database.mjs +2 -0
  5. package/dist/lib/Entity.mjs +231 -0
  6. package/dist/lib/Entity.mjs.map +1 -0
  7. package/dist/lib/Err.mjs +105 -0
  8. package/dist/lib/Err.mjs.map +1 -0
  9. package/dist/lib/Feed.mjs +338 -0
  10. package/dist/lib/Feed.mjs.map +1 -0
  11. package/dist/lib/Filter.mjs +380 -0
  12. package/dist/lib/Filter.mjs.map +1 -0
  13. package/dist/lib/Format.mjs +47 -0
  14. package/dist/lib/Format.mjs.map +1 -0
  15. package/dist/lib/JsonSchema.mjs +21 -0
  16. package/dist/lib/JsonSchema.mjs.map +1 -0
  17. package/dist/lib/Key.mjs +15 -0
  18. package/dist/lib/Key.mjs.map +1 -0
  19. package/dist/lib/Migration.mjs +38 -0
  20. package/dist/lib/Migration.mjs.map +1 -0
  21. package/dist/lib/Obj.mjs +660 -0
  22. package/dist/lib/Obj.mjs.map +1 -0
  23. package/dist/lib/Order.mjs +65 -0
  24. package/dist/lib/Order.mjs.map +1 -0
  25. package/dist/lib/Query.mjs +336 -0
  26. package/dist/lib/Query.mjs.map +1 -0
  27. package/dist/lib/QueryResult.mjs +7 -0
  28. package/dist/lib/QueryResult.mjs.map +1 -0
  29. package/dist/lib/Ref.mjs +44 -0
  30. package/dist/lib/Ref.mjs.map +1 -0
  31. package/dist/lib/Registry.mjs +35 -0
  32. package/dist/lib/Registry.mjs.map +1 -0
  33. package/dist/lib/Relation.mjs +397 -0
  34. package/dist/lib/Relation.mjs.map +1 -0
  35. package/dist/lib/Scope.mjs +51 -0
  36. package/dist/lib/Scope.mjs.map +1 -0
  37. package/dist/lib/Tag.mjs +70 -0
  38. package/dist/lib/Tag.mjs.map +1 -0
  39. package/dist/lib/Text.mjs +82 -0
  40. package/dist/lib/Text.mjs.map +1 -0
  41. package/dist/lib/Type.mjs +371 -0
  42. package/dist/lib/Type.mjs.map +1 -0
  43. package/dist/lib/chunk-Annotation.mjs +221 -0
  44. package/dist/lib/chunk-Annotation.mjs.map +1 -0
  45. package/dist/lib/chunk-Database.mjs +918 -0
  46. package/dist/lib/chunk-Database.mjs.map +1 -0
  47. package/dist/lib/chunk-atom-snapshot.mjs +249 -0
  48. package/dist/lib/chunk-atom-snapshot.mjs.map +1 -0
  49. package/dist/lib/chunk-internal.mjs +2775 -0
  50. package/dist/lib/chunk-internal.mjs.map +1 -0
  51. package/dist/lib/chunk-json-schema.mjs +660 -0
  52. package/dist/lib/chunk-json-schema.mjs.map +1 -0
  53. package/dist/lib/chunk-number.mjs +164 -0
  54. package/dist/lib/chunk-number.mjs.map +1 -0
  55. package/dist/lib/chunk-ref-array.mjs +31 -0
  56. package/dist/lib/chunk-ref-array.mjs.map +1 -0
  57. package/dist/lib/chunk-ref.mjs +590 -0
  58. package/dist/lib/chunk-ref.mjs.map +1 -0
  59. package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
  60. package/dist/lib/chunk-select.mjs +186 -0
  61. package/dist/lib/chunk-select.mjs.map +1 -0
  62. package/dist/lib/chunk-src.mjs +234 -0
  63. package/dist/lib/chunk-src.mjs.map +1 -0
  64. package/dist/lib/chunk-util.mjs +140 -0
  65. package/dist/lib/chunk-util.mjs.map +1 -0
  66. package/dist/lib/index.mjs +24 -0
  67. package/dist/lib/internal.mjs +10 -0
  68. package/dist/lib/testing.mjs +346 -0
  69. package/dist/lib/testing.mjs.map +1 -0
  70. package/dist/types/src/Aggregate.d.ts +86 -0
  71. package/dist/types/src/Aggregate.d.ts.map +1 -0
  72. package/dist/types/src/Blob.d.ts +153 -0
  73. package/dist/types/src/Blob.d.ts.map +1 -0
  74. package/dist/types/src/Blob.test.d.ts +2 -0
  75. package/dist/types/src/Blob.test.d.ts.map +1 -0
  76. package/dist/types/src/Database.d.ts +153 -4
  77. package/dist/types/src/Database.d.ts.map +1 -1
  78. package/dist/types/src/Err.d.ts +116 -0
  79. package/dist/types/src/Err.d.ts.map +1 -1
  80. package/dist/types/src/Feed.d.ts +116 -28
  81. package/dist/types/src/Feed.d.ts.map +1 -1
  82. package/dist/types/src/Feed.test.d.ts +2 -0
  83. package/dist/types/src/Feed.test.d.ts.map +1 -0
  84. package/dist/types/src/Filter.d.ts +14 -6
  85. package/dist/types/src/Filter.d.ts.map +1 -1
  86. package/dist/types/src/Hypergraph.d.ts +18 -0
  87. package/dist/types/src/Hypergraph.d.ts.map +1 -1
  88. package/dist/types/src/Json.d.ts.map +1 -1
  89. package/dist/types/src/Obj.d.ts +14 -1
  90. package/dist/types/src/Obj.d.ts.map +1 -1
  91. package/dist/types/src/Order.d.ts +9 -3
  92. package/dist/types/src/Order.d.ts.map +1 -1
  93. package/dist/types/src/Query.d.ts +107 -26
  94. package/dist/types/src/Query.d.ts.map +1 -1
  95. package/dist/types/src/Relation.d.ts +6 -0
  96. package/dist/types/src/Relation.d.ts.map +1 -1
  97. package/dist/types/src/Type.d.ts.map +1 -1
  98. package/dist/types/src/View.d.ts +1 -1
  99. package/dist/types/src/index.d.ts +2 -0
  100. package/dist/types/src/index.d.ts.map +1 -1
  101. package/dist/types/src/internal/Entity/api.d.ts +6 -0
  102. package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
  103. package/dist/types/src/internal/Entity/model.d.ts +3 -2
  104. package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
  105. package/dist/types/src/internal/Filter/match.d.ts.map +1 -1
  106. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +34 -8
  107. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -1
  108. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
  109. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
  110. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
  111. package/dist/types/src/internal/Query/pretty.d.ts.map +1 -1
  112. package/dist/types/src/internal/Query/query-result-effect.d.ts.map +1 -1
  113. package/dist/types/src/internal/common/proxy/make-object.d.ts +13 -0
  114. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
  115. package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -1
  116. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -1
  117. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +12 -0
  118. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
  119. package/dist/types/src/internal/common/types/index.d.ts +1 -0
  120. package/dist/types/src/internal/common/types/index.d.ts.map +1 -1
  121. package/dist/types/src/internal/common/types/model-symbols.d.ts +5 -0
  122. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
  123. package/dist/types/src/internal/common/types/projection.d.ts +32 -0
  124. package/dist/types/src/internal/common/types/projection.d.ts.map +1 -0
  125. package/dist/types/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +40 -35
  127. package/src/Aggregate.ts +105 -0
  128. package/src/Blob.test.ts +45 -0
  129. package/src/Blob.ts +205 -0
  130. package/src/Database.ts +207 -17
  131. package/src/Err.ts +36 -0
  132. package/src/Feed.test.ts +188 -0
  133. package/src/Feed.ts +238 -62
  134. package/src/Filter.ts +28 -10
  135. package/src/Hypergraph.ts +18 -0
  136. package/src/Json.ts +1 -0
  137. package/src/Obj.test.ts +2 -2
  138. package/src/Obj.ts +21 -1
  139. package/src/Order.ts +16 -9
  140. package/src/Query.test.ts +319 -2
  141. package/src/Query.ts +165 -51
  142. package/src/Relation.ts +14 -0
  143. package/src/Type.ts +5 -6
  144. package/src/index.ts +2 -0
  145. package/src/internal/Entity/api.ts +11 -1
  146. package/src/internal/Entity/model.ts +3 -0
  147. package/src/internal/Filter/match.ts +30 -1
  148. package/src/internal/JsonSchema/json-schema-type.ts +14 -2
  149. package/src/internal/JsonSchema/json-schema.test.ts +28 -1
  150. package/src/internal/JsonSchema/json-schema.ts +33 -6
  151. package/src/internal/Obj/atoms.ts +4 -2
  152. package/src/internal/Obj/json-serializer.test.ts +162 -2
  153. package/src/internal/Obj/json-serializer.ts +6 -0
  154. package/src/internal/Query/pretty.ts +19 -1
  155. package/src/internal/Query/query-result-effect.ts +2 -4
  156. package/src/internal/Ref/atoms.ts +1 -1
  157. package/src/internal/common/proxy/change-context.ts +1 -1
  158. package/src/internal/common/proxy/make-object.ts +42 -3
  159. package/src/internal/common/proxy/reactive.ts +5 -0
  160. package/src/internal/common/proxy/symbols.ts +1 -0
  161. package/src/internal/common/proxy/typed-handler.ts +71 -29
  162. package/src/internal/common/types/index.ts +1 -0
  163. package/src/internal/common/types/model-symbols.ts +6 -0
  164. package/src/internal/common/types/projection.ts +45 -0
  165. package/src/testing/test-data.ts +14 -14
  166. package/dist/lib/neutral/Annotation.mjs +0 -90
  167. package/dist/lib/neutral/Annotation.mjs.map +0 -7
  168. package/dist/lib/neutral/Database.mjs +0 -42
  169. package/dist/lib/neutral/Database.mjs.map +0 -7
  170. package/dist/lib/neutral/Entity.mjs +0 -76
  171. package/dist/lib/neutral/Entity.mjs.map +0 -7
  172. package/dist/lib/neutral/Err.mjs +0 -16
  173. package/dist/lib/neutral/Err.mjs.map +0 -7
  174. package/dist/lib/neutral/Feed.mjs +0 -50
  175. package/dist/lib/neutral/Feed.mjs.map +0 -7
  176. package/dist/lib/neutral/Filter.mjs +0 -72
  177. package/dist/lib/neutral/Filter.mjs.map +0 -7
  178. package/dist/lib/neutral/Format.mjs +0 -82
  179. package/dist/lib/neutral/Format.mjs.map +0 -7
  180. package/dist/lib/neutral/JsonSchema.mjs +0 -18
  181. package/dist/lib/neutral/JsonSchema.mjs.map +0 -7
  182. package/dist/lib/neutral/Key.mjs +0 -16
  183. package/dist/lib/neutral/Key.mjs.map +0 -7
  184. package/dist/lib/neutral/Migration.mjs +0 -18
  185. package/dist/lib/neutral/Migration.mjs.map +0 -7
  186. package/dist/lib/neutral/Obj.mjs +0 -128
  187. package/dist/lib/neutral/Obj.mjs.map +0 -7
  188. package/dist/lib/neutral/Order.mjs +0 -16
  189. package/dist/lib/neutral/Order.mjs.map +0 -7
  190. package/dist/lib/neutral/Query.mjs +0 -38
  191. package/dist/lib/neutral/Query.mjs.map +0 -7
  192. package/dist/lib/neutral/QueryResult.mjs +0 -2
  193. package/dist/lib/neutral/QueryResult.mjs.map +0 -7
  194. package/dist/lib/neutral/Ref.mjs +0 -25
  195. package/dist/lib/neutral/Ref.mjs.map +0 -7
  196. package/dist/lib/neutral/Registry.mjs +0 -14
  197. package/dist/lib/neutral/Registry.mjs.map +0 -7
  198. package/dist/lib/neutral/Relation.mjs +0 -97
  199. package/dist/lib/neutral/Relation.mjs.map +0 -7
  200. package/dist/lib/neutral/Scope.mjs +0 -12
  201. package/dist/lib/neutral/Scope.mjs.map +0 -7
  202. package/dist/lib/neutral/Tag.mjs +0 -32
  203. package/dist/lib/neutral/Tag.mjs.map +0 -7
  204. package/dist/lib/neutral/Text.mjs +0 -25
  205. package/dist/lib/neutral/Text.mjs.map +0 -7
  206. package/dist/lib/neutral/Type.mjs +0 -65
  207. package/dist/lib/neutral/Type.mjs.map +0 -7
  208. package/dist/lib/neutral/chunk-2HKGAQM4.mjs +0 -1394
  209. package/dist/lib/neutral/chunk-2HKGAQM4.mjs.map +0 -7
  210. package/dist/lib/neutral/chunk-2ZHECXUR.mjs +0 -95
  211. package/dist/lib/neutral/chunk-2ZHECXUR.mjs.map +0 -7
  212. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs +0 -336
  213. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs.map +0 -7
  214. package/dist/lib/neutral/chunk-3TN2VMI4.mjs +0 -714
  215. package/dist/lib/neutral/chunk-3TN2VMI4.mjs.map +0 -7
  216. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs +0 -104
  217. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs.map +0 -7
  218. package/dist/lib/neutral/chunk-4A2NWKRJ.mjs +0 -747
  219. package/dist/lib/neutral/chunk-4A2NWKRJ.mjs.map +0 -7
  220. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs +0 -25
  221. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +0 -7
  222. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs +0 -1531
  223. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs.map +0 -7
  224. package/dist/lib/neutral/chunk-BEFR7LEA.mjs +0 -170
  225. package/dist/lib/neutral/chunk-BEFR7LEA.mjs.map +0 -7
  226. package/dist/lib/neutral/chunk-BXIKXT7Q.mjs +0 -89
  227. package/dist/lib/neutral/chunk-BXIKXT7Q.mjs.map +0 -7
  228. package/dist/lib/neutral/chunk-C57XMMBY.mjs +0 -206
  229. package/dist/lib/neutral/chunk-C57XMMBY.mjs.map +0 -7
  230. package/dist/lib/neutral/chunk-C62JYFAD.mjs +0 -183
  231. package/dist/lib/neutral/chunk-C62JYFAD.mjs.map +0 -7
  232. package/dist/lib/neutral/chunk-FSGX2R62.mjs +0 -48
  233. package/dist/lib/neutral/chunk-FSGX2R62.mjs.map +0 -7
  234. package/dist/lib/neutral/chunk-HBXT3GSB.mjs +0 -459
  235. package/dist/lib/neutral/chunk-HBXT3GSB.mjs.map +0 -7
  236. package/dist/lib/neutral/chunk-IQR45HAD.mjs +0 -31
  237. package/dist/lib/neutral/chunk-IQR45HAD.mjs.map +0 -7
  238. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  239. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  240. package/dist/lib/neutral/chunk-KCBW4BR6.mjs +0 -424
  241. package/dist/lib/neutral/chunk-KCBW4BR6.mjs.map +0 -7
  242. package/dist/lib/neutral/chunk-L3E5IXAE.mjs +0 -575
  243. package/dist/lib/neutral/chunk-L3E5IXAE.mjs.map +0 -7
  244. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs +0 -56
  245. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs.map +0 -7
  246. package/dist/lib/neutral/chunk-SCT6FFCR.mjs +0 -351
  247. package/dist/lib/neutral/chunk-SCT6FFCR.mjs.map +0 -7
  248. package/dist/lib/neutral/chunk-TOCVVFK2.mjs +0 -75
  249. package/dist/lib/neutral/chunk-TOCVVFK2.mjs.map +0 -7
  250. package/dist/lib/neutral/chunk-U53LSQQA.mjs +0 -41
  251. package/dist/lib/neutral/chunk-U53LSQQA.mjs.map +0 -7
  252. package/dist/lib/neutral/chunk-UGFFV2FR.mjs +0 -27
  253. package/dist/lib/neutral/chunk-UGFFV2FR.mjs.map +0 -7
  254. package/dist/lib/neutral/chunk-UWLP4RFM.mjs +0 -7
  255. package/dist/lib/neutral/chunk-UWLP4RFM.mjs.map +0 -7
  256. package/dist/lib/neutral/chunk-UZHCQ6NI.mjs +0 -283
  257. package/dist/lib/neutral/chunk-UZHCQ6NI.mjs.map +0 -7
  258. package/dist/lib/neutral/chunk-WISOH2XH.mjs +0 -36
  259. package/dist/lib/neutral/chunk-WISOH2XH.mjs.map +0 -7
  260. package/dist/lib/neutral/chunk-WKIT2YY5.mjs +0 -34
  261. package/dist/lib/neutral/chunk-WKIT2YY5.mjs.map +0 -7
  262. package/dist/lib/neutral/chunk-XB6ISRAO.mjs +0 -271
  263. package/dist/lib/neutral/chunk-XB6ISRAO.mjs.map +0 -7
  264. package/dist/lib/neutral/chunk-XXL42WCB.mjs +0 -84
  265. package/dist/lib/neutral/chunk-XXL42WCB.mjs.map +0 -7
  266. package/dist/lib/neutral/chunk-XXWK4J53.mjs +0 -117
  267. package/dist/lib/neutral/chunk-XXWK4J53.mjs.map +0 -7
  268. package/dist/lib/neutral/index.mjs +0 -115
  269. package/dist/lib/neutral/index.mjs.map +0 -7
  270. package/dist/lib/neutral/internal/index.mjs +0 -581
  271. package/dist/lib/neutral/internal/index.mjs.map +0 -7
  272. package/dist/lib/neutral/meta.json +0 -1
  273. package/dist/lib/neutral/testing/index.mjs +0 -477
  274. package/dist/lib/neutral/testing/index.mjs.map +0 -7
@@ -0,0 +1,918 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { g as getStaticTypeSchema, o as EntityKind, t as createAnnotationHelper } from "./chunk-util.mjs";
3
+ import { EntityNotFoundError } from "./Err.mjs";
4
+ import { DXN, EID, EntityId, URI } from "@dxos/keys";
5
+ import * as Function from "effect/Function";
6
+ import * as Option from "effect/Option";
7
+ import * as Schema from "effect/Schema";
8
+ import * as SchemaAST from "effect/SchemaAST";
9
+ import { assertArgument, invariant } from "@dxos/invariant";
10
+ import { SchemaEx } from "@dxos/effect";
11
+ import { assumeType } from "@dxos/util";
12
+ import * as Effect from "effect/Effect";
13
+ import { raise } from "@dxos/debug";
14
+ import * as Context from "effect/Context";
15
+ import * as Layer from "effect/Layer";
16
+ import * as Stream from "effect/Stream";
17
+ import * as Effectable from "effect/Effectable";
18
+ //#region src/internal/common/types/model-symbols.ts
19
+ /**
20
+ * Internal symbol/string constants for the echo object model.
21
+ * Defined in common/ so proxy/ can use them without importing from Entity/.
22
+ * Entity/ re-exports these for external consumers.
23
+ */
24
+ /**
25
+ * Property name for the object's own URI when serialized to JSON.
26
+ */
27
+ var ATTR_SELF_URI = "@uri";
28
+ /**
29
+ * @deprecated Legacy JSON property name accepted on read for backward compat.
30
+ */
31
+ var ATTR_SELF_URI_LEGACY = "@dxn";
32
+ /**
33
+ * Symbol carrying the object's own URI on live entities.
34
+ */
35
+ var SelfURIId = Symbol.for("@dxos/echo/URI");
36
+ /**
37
+ * Property name for deleted when object is serialized to JSON.
38
+ */
39
+ var ATTR_DELETED = "@deleted";
40
+ /**
41
+ * Deletion marker.
42
+ */
43
+ var ObjectDeletedId = Symbol.for("@dxos/echo/Deleted");
44
+ /**
45
+ * Object version accessor symbol.
46
+ */
47
+ var ObjectVersionId = Symbol.for("@dxos/echo/Version");
48
+ /**
49
+ * Object database accessor symbol.
50
+ */
51
+ var ObjectDatabaseId = Symbol.for("@dxos/echo/Database");
52
+ /**
53
+ * Branch accessor symbol. Resolves to the branch name this object instance is bound to (`'main'` for
54
+ * the canonical object, or the branch of a `db.branch()` independent instance). Read via `Obj.getBranch`.
55
+ */
56
+ var ObjectBranchId = Symbol.for("@dxos/echo/Branch");
57
+ /**
58
+ * Property name for relation source when object is serialized to JSON.
59
+ */
60
+ var ATTR_RELATION_SOURCE = "@relationSource";
61
+ /**
62
+ * Used to access relation source ref on live ECHO objects.
63
+ */
64
+ var RelationSourceId = Symbol.for("@dxos/echo/RelationSource");
65
+ /**
66
+ * Used to access relation source DXN on live ECHO objects.
67
+ */
68
+ var RelationSourceDXNId = Symbol.for("@dxos/echo/RelationSourceDXN");
69
+ /**
70
+ * Property name for relation target when object is serialized to JSON.
71
+ */
72
+ var ATTR_RELATION_TARGET = "@relationTarget";
73
+ /**
74
+ * Used to access relation target ref on live ECHO objects.
75
+ */
76
+ var RelationTargetId = Symbol.for("@dxos/echo/RelationTarget");
77
+ /**
78
+ * Used to access relation target DXN on live ECHO objects.
79
+ */
80
+ var RelationTargetDXNId = Symbol.for("@dxos/echo/RelationTargetDXN");
81
+ /**
82
+ * Symbol carrying the entity metadata (EntityMeta) on live ECHO entities.
83
+ * Must be importable by both meta.ts (which depends on the Ref schema) and
84
+ * Entity/api.ts (which is transitively imported by the Ref schema), so it
85
+ * cannot live in either of those files without creating an import cycle.
86
+ */
87
+ var MetaId = Symbol.for("@dxos/echo/Meta");
88
+ //#endregion
89
+ //#region src/internal/common/types/typename.ts
90
+ /**
91
+ * Property name for typename when object is serialized to JSON.
92
+ */
93
+ var ATTR_TYPE = "@type";
94
+ /**
95
+ * DXN to the object type.
96
+ */
97
+ var TypeId$1 = Symbol.for("@dxos/echo/Type");
98
+ /**
99
+ * Reference to the object schema.
100
+ */
101
+ var SchemaId = Symbol.for("@dxos/echo/Schema");
102
+ /**
103
+ * Property name for parent when object is serialized to JSON.
104
+ */
105
+ var ATTR_PARENT = "@parent";
106
+ /**
107
+ * Reference to the object parent.
108
+ */
109
+ var ParentId = Symbol.for("@dxos/echo/Parent");
110
+ /**
111
+ * Reference to the object's type entity (`Type.Obj`, `Type.Relation`, or
112
+ * `Type.Type`). Set at instance creation by `createObject` / `makeObject`
113
+ * when the entity is known. Public read-back via `Obj.getType` / `Relation.getType`
114
+ * / `Entity.getType`.
115
+ */
116
+ var TypeEntityId = Symbol.for("@dxos/echo/TypeEntity");
117
+ /**
118
+ * Returns the Effect Schema for the given object if one is defined.
119
+ *
120
+ * @internal
121
+ * Internal callers needing schema-side validation read from `SchemaId`.
122
+ * Public callers should use `Type.getSchema(Obj.getType(obj))` instead.
123
+ */
124
+ var getSchema = (obj) => {
125
+ if (obj) return obj[SchemaId];
126
+ };
127
+ /**
128
+ * @internal
129
+ */
130
+ var setSchema = (obj, schema) => {
131
+ Object.defineProperty(obj, SchemaId, {
132
+ value: schema,
133
+ writable: false,
134
+ enumerable: false,
135
+ configurable: false
136
+ });
137
+ };
138
+ /**
139
+ * Returns the type entity (`Type.AnyEntity`) for the given instance.
140
+ * Set at instance creation; every entity has a type. Defensive: returns
141
+ * undefined for null/undefined input so callers can safely probe arbitrary
142
+ * values via this helper.
143
+ *
144
+ * @internal Re-exported via `Obj.getType` / `Relation.getType` / `Entity.getType`.
145
+ */
146
+ var getType = (obj) => {
147
+ if (obj == null) return;
148
+ return obj[TypeEntityId];
149
+ };
150
+ /**
151
+ * @internal
152
+ */
153
+ var setType = (obj, type) => {
154
+ Object.defineProperty(obj, TypeEntityId, {
155
+ value: type,
156
+ writable: false,
157
+ enumerable: false,
158
+ configurable: true
159
+ });
160
+ };
161
+ //#endregion
162
+ //#region src/internal/Annotation/annotations.ts
163
+ var __dxlog_file$3 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Annotation/annotations.ts";
164
+ var ANNOTATION_TYPE_ID = "~@dxos/echo/Annotation";
165
+ /**
166
+ * @internal
167
+ */
168
+ var FIELD_PATH_ANNOTATION = "path";
169
+ /**
170
+ * Sets the path for the field.
171
+ * @param path Data source path in the json path format. This is the field path in the source object.
172
+ */
173
+ var FieldPath = (path) => PropertyMeta(FIELD_PATH_ANNOTATION, path);
174
+ /**
175
+ * ECHO identifier (for a stored schema).
176
+ * Must be an `echo:` URI.
177
+ */
178
+ var TypeIdentifierAnnotationId = Symbol.for("@dxos/schema/annotation/TypeIdentifier");
179
+ var getTypeIdentifierAnnotation = (schema) => Function.flow(SchemaAST.getAnnotation(TypeIdentifierAnnotationId), Option.getOrElse(() => void 0))(schema.ast);
180
+ /**
181
+ * @returns The schema's type identifier URI — whichever URI fits.
182
+ *
183
+ * - Stored (dynamic) schemas: the schema-as-object's EID, so loaded objects ride
184
+ * along with their schema as a strong dependency.
185
+ * - Non-stored (static) schemas: the typename DXN built from `TypeAnnotation`.
186
+ *
187
+ * This URI is what gets written to an object's `system.type`; queries that filter by
188
+ * type also use it (see `Filter.type` / `getTypeURIFromSpecifier`), so both sides
189
+ * stay symmetric without per-schema branching.
190
+ */
191
+ var getSchemaURI = (schema) => {
192
+ assertArgument(Schema.isSchema(schema), "schema", "invalid schema");
193
+ const id = getTypeIdentifierAnnotation(schema);
194
+ if (id) return URI.make(id);
195
+ const objectAnnotation = getTypeAnnotation(schema);
196
+ if (objectAnnotation) return DXN.make(objectAnnotation.typename, objectAnnotation.version);
197
+ };
198
+ /**
199
+ * Fully qualified globally unique typename.
200
+ * Example: `org.dxos.type.message`
201
+ */
202
+ var TypenameSchema = Schema.String.pipe(Schema.pattern(/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/)).annotations({
203
+ description: "Fully qualified globally unique typename in reverse-DNS form.",
204
+ example: "org.dxos.type.message"
205
+ });
206
+ /**
207
+ * Semantic version format: `major.minor.patch`
208
+ * Example: `1.0.0`
209
+ */
210
+ var VersionSchema = Schema.String.pipe(Schema.pattern(/^\d+.\d+.\d+$/)).annotations({
211
+ description: "Semantic version format: `major.minor.patch`",
212
+ example: "1.0.0"
213
+ });
214
+ var TypeMeta = Schema.Struct({
215
+ typename: TypenameSchema,
216
+ version: VersionSchema
217
+ });
218
+ /**
219
+ * Entity type.
220
+ */
221
+ var TypeAnnotationId = Symbol.for("@dxos/schema/annotation/Type");
222
+ /**
223
+ * Payload stored under {@link TypeAnnotationId}.
224
+ */
225
+ var TypeAnnotation = Schema.extend(TypeMeta, Schema.Struct({
226
+ kind: Schema.Enums(EntityKind),
227
+ /**
228
+ * If this is a relation, the schema of the source object.
229
+ * Must be present if entity kind is {@link EntityKind.Relation}.
230
+ */
231
+ sourceSchema: Schema.optional(DXN.Schema),
232
+ /**
233
+ * If this is a relation, the schema of the target object.
234
+ * Must be present if entity kind is {@link EntityKind.Relation}.
235
+ */
236
+ targetSchema: Schema.optional(DXN.Schema)
237
+ }));
238
+ /**
239
+ * @returns {@link TypeAnnotation} from a schema.
240
+ * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.
241
+ */
242
+ var getTypeAnnotation = (schema) => {
243
+ assertArgument(schema != null && schema.ast != null, "schema", "invalid schema");
244
+ return Function.flow(SchemaAST.getAnnotation(TypeAnnotationId), Option.getOrElse(() => void 0))(schema.ast);
245
+ };
246
+ /**
247
+ * @returns {@link EntityKind} from a schema.
248
+ */
249
+ var getEntityKind = (schema) => getTypeAnnotation(schema)?.kind;
250
+ /**
251
+ * @internal
252
+ * @returns Schema typename (without dxn: prefix or version number).
253
+ */
254
+ var getSchemaTypename = (schema) => getTypeAnnotation(schema)?.typename;
255
+ /**
256
+ * @internal
257
+ * @returns Schema version in semver format.
258
+ */
259
+ var getSchemaVersion = (schema) => getTypeAnnotation(schema)?.version;
260
+ /**
261
+ * Gets the typename of the object without the version.
262
+ * Returns only the name portion, not the DXN.
263
+ * @example "org.example.type.contact"
264
+ *
265
+ * @internal (use Obj.getTypename)
266
+ */
267
+ var getTypename = (obj) => {
268
+ const schema = getSchema(obj);
269
+ if (schema != null) return getSchemaTypename(schema);
270
+ else {
271
+ const type = obj?.[TypeId$1];
272
+ if (DXN.isDXN(type)) {
273
+ const parsed = DXN.tryMake(type);
274
+ return parsed && DXN.getName(parsed);
275
+ }
276
+ return;
277
+ }
278
+ };
279
+ /**
280
+ * @internal (use Type.setTypename)
281
+ */
282
+ var setTypename = (obj, typename) => {
283
+ assertArgument(typeof typename === "string", "typename", "Invalid type.");
284
+ Object.defineProperty(obj, TypeId$1, {
285
+ value: typename,
286
+ writable: false,
287
+ enumerable: false,
288
+ configurable: false
289
+ });
290
+ };
291
+ /**
292
+ * @returns Object type URI — either a typename {@link DXN} or an `echo:` reference to a stored Schema object.
293
+ * @returns undefined if the object has no registered type URI (e.g. unresolved query result).
294
+ * @example `dxn:com.example.type.person:1.0.0`
295
+ * @example `echo:/01KKKG2FHWCMTR0BY00GJSVT1X` (stored schema)
296
+ *
297
+ * @internal (use Obj.getTypeURI)
298
+ */
299
+ var getTypeURI = (obj) => {
300
+ if (obj == null) return;
301
+ const type = obj[TypeId$1];
302
+ if (type == null) return;
303
+ invariant(URI.isURI(type), "Invalid object.", {
304
+ "~LogMeta": "~LogMeta",
305
+ F: __dxlog_file$3,
306
+ L: 221,
307
+ S: void 0,
308
+ A: ["URI.isURI(type)", "'Invalid object.'"]
309
+ });
310
+ return type;
311
+ };
312
+ /**
313
+ * PropertyMeta (metadata for dynamic schema properties).
314
+ * For user-defined annotations.
315
+ */
316
+ var PropertyMetaAnnotationId = Symbol.for("@dxos/schema/annotation/PropertyMeta");
317
+ /**
318
+ * Apply property-level metadata to an Effect schema. Only accepts
319
+ * `Schema.Schema.Any` — apply BEFORE wrapping the schema with
320
+ * `Type.makeObject` / `Type.makeRelation`. To read property meta off a
321
+ * `Type.Type` entity, unwrap it first with `Type.getSchema(entity)`.
322
+ */
323
+ var PropertyMeta = (name, value) => {
324
+ return (self) => {
325
+ const existingMeta = self.ast.annotations[PropertyMetaAnnotationId];
326
+ return self.annotations({ [PropertyMetaAnnotationId]: {
327
+ ...existingMeta,
328
+ [name]: value
329
+ } });
330
+ };
331
+ };
332
+ var getPropertyMetaAnnotation = (prop, name) => Function.pipe(SchemaAST.getAnnotation(PropertyMetaAnnotationId)(prop.type), Option.map((meta) => meta[name]), Option.getOrElse(() => void 0));
333
+ /**
334
+ * Schema reference.
335
+ */
336
+ var ReferenceAnnotationId = Symbol.for("@dxos/schema/annotation/Reference");
337
+ var ReferenceAnnotation = createAnnotationHelper(ReferenceAnnotationId);
338
+ /**
339
+ * SchemaMeta.
340
+ */
341
+ var SchemaMetaSymbol = Symbol.for("@dxos/schema/SchemaMeta");
342
+ /**
343
+ * Identifies a schema as hidden from user-facing surfaces (like dotfiles — visible only via an advanced setting).
344
+ */
345
+ var HiddenAnnotationId = Symbol.for("@dxos/schema/annotation/Hidden");
346
+ var HiddenAnnotation = createAnnotationHelper(HiddenAnnotationId);
347
+ /**
348
+ * Identifies label property or JSON path expression.
349
+ * Either a string or an array of strings representing field accessors each matched in priority order.
350
+ */
351
+ var LabelAnnotationId = Symbol.for("@dxos/schema/annotation/Label");
352
+ var LabelAnnotation = createAnnotationHelper(LabelAnnotationId);
353
+ /**
354
+ * Returns the label for a given object based on {@link LabelAnnotationId}.
355
+ * Lower-level version that requires explicit schema parameter.
356
+ * Skips empty strings and whitespace-only strings, continuing to the next field.
357
+ */
358
+ var getLabelWithSchema = (schema, object) => {
359
+ const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ["name"]));
360
+ for (const accessor of annotation) {
361
+ assertArgument(typeof accessor === "string", "accessor", "Label annotation must be a string or an array of strings");
362
+ const value = SchemaEx.getField(object, accessor);
363
+ switch (typeof value) {
364
+ case "string":
365
+ if (value.trim().length > 0) return value;
366
+ continue;
367
+ case "number":
368
+ case "boolean":
369
+ case "bigint":
370
+ case "symbol": return value.toString();
371
+ case "undefined":
372
+ case "object":
373
+ case "function": continue;
374
+ }
375
+ }
376
+ };
377
+ /**
378
+ * Sets the label for a given object based on {@link LabelAnnotationId}.
379
+ * Lower-level version that requires explicit schema parameter.
380
+ */
381
+ var setLabelWithSchema = (schema, object, label) => {
382
+ const annotation = LabelAnnotation.get(schema).pipe(Option.map((field) => field[0]), Option.getOrElse(() => "name"));
383
+ object[annotation] = label;
384
+ };
385
+ /**
386
+ * Identifies description property or JSON path expression.
387
+ * A string representing field accessor.
388
+ */
389
+ var DescriptionAnnotationId = Symbol.for("@dxos/schema/annotation/Description");
390
+ var DescriptionAnnotation = createAnnotationHelper(DescriptionAnnotationId);
391
+ /**
392
+ * Returns the description for a given object based on {@link DescriptionAnnotationId}.
393
+ * Lower-level version that requires explicit schema parameter.
394
+ */
395
+ var getDescriptionWithSchema = (schema, object) => {
396
+ const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => "description"));
397
+ assertArgument(typeof accessor === "string", "accessor", "Description annotation must be a string");
398
+ const value = SchemaEx.getField(object, accessor);
399
+ switch (typeof value) {
400
+ case "string":
401
+ case "number":
402
+ case "boolean":
403
+ case "bigint":
404
+ case "symbol": return value.toString();
405
+ default: return;
406
+ }
407
+ };
408
+ /**
409
+ * Sets the description for a given object based on {@link DescriptionAnnotationId}.
410
+ * Lower-level version that requires explicit schema parameter.
411
+ */
412
+ var setDescriptionWithSchema = (schema, object, description) => {
413
+ const accessorOpt = DescriptionAnnotation.get(schema);
414
+ if (Option.isNone(accessorOpt)) return;
415
+ object[accessorOpt.value] = description;
416
+ };
417
+ /**
418
+ * Identifies if a property should be included in a form or not.
419
+ * By default, all properties are included in forms, so this is opt-out.
420
+ */
421
+ var FormInputAnnotationId = Symbol.for("@dxos/schema/annotation/FormInput");
422
+ var FormInputAnnotation = createAnnotationHelper(FormInputAnnotationId);
423
+ /**
424
+ * When set on a `Ref` property, the form renders the referenced object's own
425
+ * fields inline (a nested form bound to the target) instead of a picker.
426
+ */
427
+ var FormInlineAnnotationId = Symbol.for("@dxos/schema/annotation/FormInline");
428
+ var FormInlineAnnotation = createAnnotationHelper(FormInlineAnnotationId);
429
+ /**
430
+ * When set on a `Ref` (or array-of-`Ref`) property, the form OWNS the referenced target(s): "add" creates a
431
+ * new object of the annotation's typename (instead of opening the existing-object picker) and each target is
432
+ * rendered inline — its own fields — like {@link FormInlineAnnotation}. The target typename is carried here
433
+ * (rather than inferred from the element type) so the field can stay `Ref.Ref(Obj.Unknown)` and avoid pulling
434
+ * the target's type (e.g. query-AST-laden `Trigger`) into the schema's emitted declaration.
435
+ */
436
+ var FormCreateAnnotationId = Symbol.for("@dxos/schema/annotation/FormCreate");
437
+ var FormCreateAnnotation = createAnnotationHelper(FormCreateAnnotationId);
438
+ /**
439
+ * When set on an array property, the form renders it as an ordered,
440
+ * drag-to-reorder list (drag handles per row). Element order is meaningful and
441
+ * user-controllable; reordering rewrites the array.
442
+ */
443
+ var FormOrderedAnnotationId = Symbol.for("@dxos/schema/annotation/FormOrdered");
444
+ var FormOrderedAnnotation = createAnnotationHelper(FormOrderedAnnotationId);
445
+ /**
446
+ * Annotation carrying one or more named layout DSL templates that control how a
447
+ * form arranges a schema's fields (consumed by `@dxos/react-ui-form`'s
448
+ * `Form.Layout` / `Form.FieldSet`). Callers select a variant by name; the
449
+ * implicit name is `DEFAULT_LAYOUT_NAME` (`'default'`).
450
+ *
451
+ * Templates use a minimal XML grammar. Example:
452
+ *
453
+ * FormLayoutAnnotation.set({
454
+ * default: `
455
+ * <grid cols="2">
456
+ * <field name="origin"/>
457
+ * <field name="destination"/>
458
+ * <field name="provider" span="2"/>
459
+ * </grid>
460
+ * `,
461
+ * card: `
462
+ * <grid cols="1">
463
+ * <field name="provider"/>
464
+ * <field name="number"/>
465
+ * </grid>
466
+ * `,
467
+ * })
468
+ */
469
+ var FormLayoutAnnotationId = Symbol.for("@dxos/react-ui-form/annotation/Layout");
470
+ var FormLayoutAnnotation = createAnnotationHelper(FormLayoutAnnotationId);
471
+ /** Name used when no explicit form-layout variant is requested. */
472
+ var DEFAULT_LAYOUT_NAME = "default";
473
+ /**
474
+ * Default field to be used on referenced schema to lookup the value.
475
+ */
476
+ var FieldLookupAnnotationId = Symbol.for("@dxos/schema/annotation/FieldLookup");
477
+ /**
478
+ * Generate test data.
479
+ */
480
+ var GeneratorAnnotationId = Symbol.for("@dxos/schema/annotation/Generator");
481
+ var GeneratorAnnotation = createAnnotationHelper(GeneratorAnnotationId);
482
+ var makeUserAnnotation = (props) => {
483
+ assertArgument(/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){2,}(\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)?$/.test(props.id), "id", "Annotation id must be in the FQN format (org.dxos.annotation.example or org.dxos.space.rootCollection).");
484
+ const annotation = {
485
+ [ANNOTATION_TYPE_ID]: { _Type: {} },
486
+ key: props.id,
487
+ schema: props.schema,
488
+ get: (schema) => getFromAst(schema.ast, annotation),
489
+ getFromAst: (ast) => getFromAst(ast, annotation),
490
+ set: (value) => PropertyMeta(props.id, Schema.encodeSync(props.schema)(value))
491
+ };
492
+ return annotation;
493
+ };
494
+ /**
495
+ * Icon to render in the UI.
496
+ */
497
+ var IconAnnotation = makeUserAnnotation({
498
+ id: "org.dxos.annotation.icon",
499
+ schema: Schema.Struct({
500
+ /**
501
+ * Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)
502
+ */
503
+ icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),
504
+ /**
505
+ * Color name.
506
+ *
507
+ * List of colors:
508
+ * - 'red'
509
+ * - 'orange'
510
+ * - 'amber'
511
+ * - 'yellow'
512
+ * - 'lime'
513
+ * - 'green'
514
+ * - 'emerald'
515
+ * - 'teal'
516
+ * - 'cyan'
517
+ * - 'violet'
518
+ * - 'purple'
519
+ * - 'fuchsia'
520
+ * - 'pink'
521
+ * - 'rose'
522
+ */
523
+ hue: Schema.optional(Schema.String)
524
+ })
525
+ });
526
+ /**
527
+ * Indicates that this entity's icon should be resolved from a property whose value is a `Ref`
528
+ * to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that
529
+ * target's schema `IconAnnotation` in place of the static one declared on this schema.
530
+ *
531
+ * Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity
532
+ * (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).
533
+ */
534
+ var IconFromRefAnnotation = makeUserAnnotation({
535
+ id: "org.dxos.annotation.icon.from-ref",
536
+ schema: Schema.String
537
+ });
538
+ /**
539
+ * Get the label of an entity.
540
+ * Accepts both reactive entities and snapshots.
541
+ *
542
+ * If `options.fallback === 'typename'` and no label is set, returns the
543
+ * entity's typename instead.
544
+ */
545
+ var getLabel = (entity, options) => {
546
+ const schema = getSchema(entity);
547
+ const label = schema != null ? getLabelWithSchema(schema, entity) : void 0;
548
+ if (label != null) return label;
549
+ if (options?.fallback === "typename") return getTypename(entity);
550
+ };
551
+ /**
552
+ * Set the label of an entity.
553
+ * Must be called within an Obj.update or Relation.update callback.
554
+ */
555
+ var setLabel = (entity, label) => {
556
+ const schema = getSchema(entity);
557
+ if (schema != null) setLabelWithSchema(schema, entity, label);
558
+ };
559
+ /**
560
+ * Returns the primary label property key for an entity.
561
+ * Reads the first accessor from {@link LabelAnnotation}, defaulting to 'name'.
562
+ */
563
+ var getLabelProperty = (entity) => {
564
+ const schema = getSchema(entity);
565
+ if (schema == null) return "name";
566
+ return LabelAnnotation.get(schema).pipe(Option.flatMap((fields) => Option.fromNullable(fields[0])), Option.getOrElse(() => "name"));
567
+ };
568
+ /**
569
+ * Get the description of an entity.
570
+ * Accepts both reactive entities and snapshots.
571
+ */
572
+ var getDescription = (entity) => {
573
+ const schema = getSchema(entity);
574
+ if (schema != null) return getDescriptionWithSchema(schema, entity);
575
+ };
576
+ /**
577
+ * Get the icon annotation for an entity, resolved via its type-level `IconAnnotation`.
578
+ * Accepts both reactive entities and snapshots.
579
+ *
580
+ * Returns the full `{ icon, hue }` annotation so callers can use both the phosphor icon
581
+ * name and the suggested colour. Callers wanting just the icon name typically write
582
+ * `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.
583
+ *
584
+ * Note: this is the "static" icon from the object's own schema. It does not follow
585
+ * `IconFromRefAnnotation` delegation — call sites needing that (e.g. app-graph node
586
+ * builders) should resolve the ref themselves.
587
+ */
588
+ var getIcon = (entity) => {
589
+ const schema = getSchema(entity);
590
+ if (schema == null) return;
591
+ return Option.getOrUndefined(IconAnnotation.get(schema));
592
+ };
593
+ /**
594
+ * Set the description of an entity.
595
+ * Must be called within an Obj.update or Relation.update callback.
596
+ */
597
+ var setDescription = (entity, description) => {
598
+ const schema = getSchema(entity);
599
+ if (schema != null) setDescriptionWithSchema(schema, entity, description);
600
+ };
601
+ var getFromAst = (ast, annotation) => {
602
+ return SchemaAST.getAnnotation(PropertyMetaAnnotationId)(ast).pipe(Option.flatMap((meta) => Option.fromNullable(meta[annotation.key])), Option.map(Schema.decodeUnknownSync(annotation.schema)));
603
+ };
604
+ //#endregion
605
+ //#region src/internal/Entity/util.ts
606
+ var __dxlog_file$2 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/util.ts";
607
+ /**
608
+ * Returns the EID of an object.
609
+ *
610
+ * @internal
611
+ */
612
+ var getObjectEchoUri = (object) => {
613
+ invariant(!Schema.isSchema(object), "schema not allowed in this function", {
614
+ "~LogMeta": "~LogMeta",
615
+ F: __dxlog_file$2,
616
+ L: 19,
617
+ S: void 0,
618
+ A: ["!Schema.isSchema(object)", "'schema not allowed in this function'"]
619
+ });
620
+ assertArgument(typeof object === "object" && object != null, "object", "expected object");
621
+ assumeType(object);
622
+ if (object[SelfURIId]) {
623
+ invariant(EID.isEID(object[SelfURIId]), "Invalid object model: invalid self dxn", {
624
+ "~LogMeta": "~LogMeta",
625
+ F: __dxlog_file$2,
626
+ L: 24,
627
+ S: void 0,
628
+ A: ["EID.isEID(object[SelfURIId])", "'Invalid object model: invalid self dxn'"]
629
+ });
630
+ return EID.parse(object[SelfURIId]);
631
+ }
632
+ if (!EntityId.isValid(object.id)) throw new TypeError("Object id is not valid.");
633
+ return EID.make({ entityId: object.id });
634
+ };
635
+ //#endregion
636
+ //#region src/internal/Entity/api.ts
637
+ var __dxlog_file$1 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/api.ts";
638
+ /**
639
+ * Get the URI of an entity.
640
+ * Accepts both reactive entities and snapshots.
641
+ */
642
+ var getUri = (entity, options) => {
643
+ const prefer = options?.prefer;
644
+ if (prefer === "named") {
645
+ const key = entity[MetaId]?.key;
646
+ if (key) return DXN.tryMake(`dxn:${key}`) ?? URI.make(key);
647
+ const uri = getObjectEchoUri(entity);
648
+ invariant(uri != null, "Invalid entity.", {
649
+ "~LogMeta": "~LogMeta",
650
+ F: __dxlog_file$1,
651
+ L: 42,
652
+ S: void 0,
653
+ A: ["uri != null", "'Invalid entity.'"]
654
+ });
655
+ return uri;
656
+ }
657
+ if (prefer === "relative") {
658
+ const eid = getObjectEchoUri(entity);
659
+ invariant(eid != null, "Invalid entity.", {
660
+ "~LogMeta": "~LogMeta",
661
+ F: __dxlog_file$1,
662
+ L: 48,
663
+ S: void 0,
664
+ A: ["eid != null", "'Invalid entity.'"]
665
+ });
666
+ const entityId = EID.getEntityId(eid);
667
+ return entityId ? EID.make({ entityId }) : eid;
668
+ }
669
+ if (prefer === "absolute") {
670
+ const eid = getObjectEchoUri(entity);
671
+ invariant(eid != null, "Invalid entity.", {
672
+ "~LogMeta": "~LogMeta",
673
+ F: __dxlog_file$1,
674
+ L: 55,
675
+ S: void 0,
676
+ A: ["eid != null", "'Invalid entity.'"]
677
+ });
678
+ const entityId = EID.getEntityId(eid);
679
+ if (!entityId) return eid;
680
+ assumeType(entity);
681
+ const spaceId = entity[ObjectDatabaseId]?.spaceId ?? EID.getSpaceId(eid);
682
+ return spaceId ? EID.make({
683
+ spaceId,
684
+ entityId
685
+ }) : eid;
686
+ }
687
+ const uri = getObjectEchoUri(entity);
688
+ invariant(uri != null, "Invalid entity.", {
689
+ "~LogMeta": "~LogMeta",
690
+ F: __dxlog_file$1,
691
+ L: 66,
692
+ S: void 0,
693
+ A: ["uri != null", "'Invalid entity.'"]
694
+ });
695
+ return uri;
696
+ };
697
+ /**
698
+ * Get the database the entity belongs to.
699
+ * Accepts both reactive entities and snapshots.
700
+ */
701
+ var getDatabase = (entity) => {
702
+ assumeType(entity);
703
+ return entity[ObjectDatabaseId];
704
+ };
705
+ /**
706
+ * Get the branch this entity instance is bound to (`'main'` for the canonical object, or the branch
707
+ * of a `db.branch()` independent instance). Reads the branch off the instance, so two instances of the
708
+ * same object id on different branches report their own branch.
709
+ */
710
+ var getBranch = (entity) => {
711
+ assumeType(entity);
712
+ return entity[ObjectBranchId] ?? "main";
713
+ };
714
+ //#endregion
715
+ //#region src/internal/Entity/type-uri.ts
716
+ /**
717
+ * @param input schema, `Type.Type` entity, or a type URI (an `echo:` EID or a `dxn:` DXN).
718
+ * @return type identifier URI — see {@link getSchemaURI}. A URI is returned verbatim. For a
719
+ * `Type.Type` entity, the URI of the schema it declares, symmetric with what
720
+ * `Obj.make(typeEntity, ...)` stamps on `system.type`: a static declaration resolves to its
721
+ * typename DXN, a persisted entity to its local `echo:/<objectId>`.
722
+ */
723
+ var getTypeURIFromSpecifier = (input) => {
724
+ if (Schema.isSchema(input)) return getSchemaURI(input) ?? raise(/* @__PURE__ */ new TypeError("Schema has no URI"));
725
+ if (input !== null && (typeof input === "object" || typeof input === "function") && "~@dxos/echo/Kind" in input) {
726
+ const schema = getStaticTypeSchema(input);
727
+ if (schema != null) {
728
+ const uri = getSchemaURI(schema);
729
+ if (uri != null) return uri;
730
+ }
731
+ return getUri(input);
732
+ }
733
+ assertArgument(EID.isEID(input) || DXN.isDXN(input), "input", "expected a type URI (EID or DXN)");
734
+ return input;
735
+ };
736
+ /**
737
+ * Checks if the object is an instance of the schema.
738
+ * Only typename is compared, the schema version is ignored.
739
+ *
740
+ * The following cases are considered to mean that the object is an instance of the schema:
741
+ * - Object was created with this exact schema.
742
+ * - Object was created with a different version of this schema.
743
+ * - Object was created with a different schema (maybe dynamic) that has the same typename.
744
+ */
745
+ var isInstanceOf = (schemaOrType, object) => {
746
+ if (object == null) return false;
747
+ const schemaURI = getTypeURIFromSpecifier(schemaOrType);
748
+ const type = object[TypeId$1];
749
+ if (URI.isURI(type) && type === schemaURI) return true;
750
+ const typename = getTypename(object);
751
+ if (!typename) return false;
752
+ if (!DXN.isDXN(schemaURI)) return false;
753
+ const parsed = DXN.tryMake(schemaURI);
754
+ return parsed != null && DXN.getName(parsed) === typename;
755
+ };
756
+ //#endregion
757
+ //#region src/internal/Query/query-result-effect.ts
758
+ /**
759
+ * Wraps an effect that produces a {@link QueryResult.QueryResult} into a
760
+ * {@link QueryResult.QueryResultEffect}, exposing `.run` and `.first` shorthands that execute the
761
+ * query once. Shared by `Database.query` and `Feed.query` so both surfaces chain identically.
762
+ */
763
+ var makeQueryResultEffect = (eff) => {
764
+ return {
765
+ run: Effect.flatMap(eff, (result) => Effect.promise(() => result.run())),
766
+ first: Effect.flatMap(eff, (result) => Effect.promise(async () => Option.fromNullable(await result.firstOrUndefined()))),
767
+ ...Effectable.CommitPrototype,
768
+ commit() {
769
+ return eff;
770
+ }
771
+ };
772
+ };
773
+ //#endregion
774
+ //#region src/Database.ts
775
+ var Database_exports = /* @__PURE__ */ __exportAll({
776
+ Database: () => Database,
777
+ Service: () => Service,
778
+ TypeId: () => TypeId,
779
+ add: () => add,
780
+ addType: () => addType,
781
+ appendToFeed: () => appendToFeed,
782
+ deleteFromFeed: () => deleteFromFeed,
783
+ flush: () => flush,
784
+ getSyncState: () => getSyncState,
785
+ isDatabase: () => isDatabase,
786
+ layer: () => layer,
787
+ load: () => load,
788
+ makeService: () => makeService,
789
+ notAvailable: () => notAvailable,
790
+ query: () => query,
791
+ remove: () => remove,
792
+ resolve: () => resolve,
793
+ spaceId: () => spaceId,
794
+ subscribeToSyncState: () => subscribeToSyncState
795
+ });
796
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Database.ts";
797
+ /**
798
+ * Identifier denoting an ECHO Database.
799
+ */
800
+ var TypeId = Symbol.for("@dxos/echo/Database");
801
+ var isDatabase = (obj) => {
802
+ return obj ? typeof obj === "object" && TypeId in obj && obj[TypeId] === TypeId : false;
803
+ };
804
+ var Database = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));
805
+ /**
806
+ * Effect service tag for Database dependency injection.
807
+ */
808
+ var Service = class extends Context.Tag("@dxos/echo/Database/Service")() {};
809
+ /**
810
+ * Layer that provides a Database service that throws when accessed.
811
+ * Useful as a default layer when no database is available.
812
+ */
813
+ var notAvailable = Layer.succeed(Service, { get db() {
814
+ throw new Error("Database not available");
815
+ } });
816
+ /**
817
+ * Creates a Database service instance from a Database.
818
+ */
819
+ var makeService = (db) => {
820
+ return { get db() {
821
+ return db;
822
+ } };
823
+ };
824
+ /**
825
+ * Creates a Layer that provides the Database service.
826
+ */
827
+ var layer = (db) => {
828
+ return Layer.succeed(Service, makeService(db));
829
+ };
830
+ /**
831
+ * Returns the space ID of the database.
832
+ */
833
+ var spaceId = Effect.gen(function* () {
834
+ const { db } = yield* Service;
835
+ return db.spaceId;
836
+ });
837
+ /**
838
+ * Resolves an object by its DXN.
839
+ */
840
+ var resolve = ((ref, schema) => Effect.gen(function* () {
841
+ const { db } = yield* Service;
842
+ const dxn = typeof ref === "string" ? ref : ref.uri;
843
+ const object = yield* Effect.promise(() => db.graph.createRefResolver({ context: { space: db.spaceId } }).resolveLegacy(dxn));
844
+ if (!object) return yield* Effect.fail(new EntityNotFoundError(dxn));
845
+ invariant(!schema || isInstanceOf(schema, object), "Object type mismatch.", {
846
+ "~LogMeta": "~LogMeta",
847
+ F: __dxlog_file,
848
+ L: 408,
849
+ S: this,
850
+ A: ["!schema || isInstanceOf(schema as any, object)", "'Object type mismatch.'"]
851
+ });
852
+ return object;
853
+ }).pipe(Effect.withSpan("Database.resolve")));
854
+ /**
855
+ * Loads an object reference.
856
+ *
857
+ * Catching not found error:
858
+ *
859
+ * ```ts
860
+ * yield* load(ref).pipe(Effect.catchTag('EntityNotFoundError', () => Effect.succeed(undefined)));
861
+ * ```
862
+ *
863
+ */
864
+ var load = Effect.fn("Database.load")(function* (ref) {
865
+ const object = yield* Effect.promise(() => ref.tryLoad());
866
+ if (!object) return yield* Effect.fail(new EntityNotFoundError(ref.uri));
867
+ return object;
868
+ });
869
+ /**
870
+ * Adds an object or relation to the database.
871
+ * @see {@link Database.add}
872
+ */
873
+ var add = (obj) => Service.pipe(Effect.map(({ db }) => db.add(obj))).pipe(Effect.withSpan("Database.add"));
874
+ /**
875
+ * Persists a Type definition to the database.
876
+ * @see {@link Database.addType}
877
+ */
878
+ var addType = (type) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.addType(type)))).pipe(Effect.withSpan("Database.addType"));
879
+ /**
880
+ * Removes an object from the database.
881
+ * @see {@link Database.remove}
882
+ */
883
+ var remove = (obj) => Service.pipe(Effect.map(({ db }) => db.remove(obj))).pipe(Effect.withSpan("Database.remove"));
884
+ /**
885
+ * Appends entities to a feed.
886
+ * @see {@link Database.appendToFeed}
887
+ */
888
+ var appendToFeed = (feed, entities) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.appendToFeed(feed, entities)))).pipe(Effect.withSpan("Database.appendToFeed"));
889
+ /**
890
+ * Removes entities from a feed.
891
+ * @see {@link Database.deleteFromFeed}
892
+ */
893
+ var deleteFromFeed = (feed, entities) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.deleteFromFeed(feed, entities)))).pipe(Effect.withSpan("Database.deleteFromFeed"));
894
+ /**
895
+ * Flushes pending changes to disk.
896
+ * @see {@link Database.flush}
897
+ */
898
+ var flush = (opts) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.flush(opts)))).pipe(Effect.withSpan("Database.flush"));
899
+ /**
900
+ * Creates a `QueryResult` object that can be subscribed to.
901
+ */
902
+ var query = (queryOrFilter) => Service.pipe(Effect.map(({ db }) => db.query(queryOrFilter)), Effect.withSpan("Database.query"), makeQueryResultEffect);
903
+ /**
904
+ * Get the current sync state.
905
+ */
906
+ var getSyncState = (options) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.getSyncState(options))));
907
+ /**
908
+ * Subscribe to sync state changes.
909
+ */
910
+ var subscribeToSyncState = (options) => Stream.asyncScoped((emit) => Effect.gen(function* () {
911
+ const { db } = yield* Service;
912
+ const cleanup = db.subscribeToSyncState((state) => emit.single(state), options);
913
+ yield* Effect.addFinalizer(() => Effect.sync(cleanup));
914
+ }));
915
+ //#endregion
916
+ export { ReferenceAnnotation as $, RelationTargetId as $t, FIELD_PATH_ANNOTATION as A, ATTR_PARENT as At, FormLayoutAnnotationId as B, ATTR_DELETED as Bt, getBranch as C, getTypename as Ct, DEFAULT_LAYOUT_NAME as D, setLabel as Dt, getObjectEchoUri as E, setDescriptionWithSchema as Et, FormInlineAnnotation as F, TypeId$1 as Ft, HiddenAnnotation as G, MetaId as Gt, FormOrderedAnnotationId as H, ATTR_RELATION_TARGET as Ht, FormInlineAnnotationId as I, getSchema as It, IconFromRefAnnotation as J, ObjectDeletedId as Jt, HiddenAnnotationId as K, ObjectBranchId as Kt, FormInputAnnotation as L, getType as Lt, FieldPath as M, ParentId as Mt, FormCreateAnnotation as N, SchemaId as Nt, DescriptionAnnotation as O, setLabelWithSchema as Ot, FormCreateAnnotationId as P, TypeEntityId as Pt, PropertyMetaAnnotationId as Q, RelationTargetDXNId as Qt, FormInputAnnotationId as R, setSchema as Rt, isInstanceOf as S, getTypeURI as St, getUri as T, setDescription as Tt, GeneratorAnnotation as U, ATTR_SELF_URI as Ut, FormOrderedAnnotation as V, ATTR_RELATION_SOURCE as Vt, GeneratorAnnotationId as W, ATTR_SELF_URI_LEGACY as Wt, LabelAnnotationId as X, RelationSourceDXNId as Xt, LabelAnnotation as Y, ObjectVersionId as Yt, PropertyMeta as Z, RelationSourceId as Zt, remove as _, getSchemaTypename as _t, add as a, TypeMeta as at, subscribeToSyncState as b, getTypeAnnotation as bt, deleteFromFeed as c, getDescription as ct, isDatabase as d, getFromAst as dt, SelfURIId as en, ReferenceAnnotationId as et, layer as f, getIcon as ft, query as g, getPropertyMetaAnnotation as gt, notAvailable as h, getLabelWithSchema as ht, TypeId as i, TypeIdentifierAnnotationId as it, FieldLookupAnnotationId as j, ATTR_TYPE as jt, DescriptionAnnotationId as k, setTypename as kt, flush as l, getDescriptionWithSchema as lt, makeService as m, getLabelProperty as mt, Database_exports as n, TypeAnnotation as nt, addType as o, TypenameSchema as ot, load as p, getLabel as pt, IconAnnotation as q, ObjectDatabaseId as qt, Service as r, TypeAnnotationId as rt, appendToFeed as s, VersionSchema as st, Database as t, SchemaMetaSymbol as tt, getSyncState as u, getEntityKind as ut, resolve as v, getSchemaURI as vt, getDatabase as w, makeUserAnnotation as wt, getTypeURIFromSpecifier as x, getTypeIdentifierAnnotation as xt, spaceId as y, getSchemaVersion as yt, FormLayoutAnnotation as z, setType as zt };
917
+
918
+ //# sourceMappingURL=chunk-Database.mjs.map