@dxos/echo 0.9.0 → 0.9.1-staging.ee54ba693a

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 (289) hide show
  1. package/dist/lib/neutral/Annotation.mjs +30 -8
  2. package/dist/lib/neutral/Database.mjs +7 -3
  3. package/dist/lib/neutral/Entity.mjs +15 -11
  4. package/dist/lib/neutral/Err.mjs +7 -3
  5. package/dist/lib/neutral/Feed.mjs +15 -19
  6. package/dist/lib/neutral/Filter.mjs +13 -11
  7. package/dist/lib/neutral/Format.mjs +3 -7
  8. package/dist/lib/neutral/JsonSchema.mjs +7 -7
  9. package/dist/lib/neutral/Migration.mjs +11 -11
  10. package/dist/lib/neutral/Obj.mjs +19 -13
  11. package/dist/lib/neutral/Order.mjs +1 -1
  12. package/dist/lib/neutral/Query.mjs +17 -17
  13. package/dist/lib/neutral/QueryResult.mjs +1 -1
  14. package/dist/lib/neutral/Ref.mjs +6 -6
  15. package/dist/lib/neutral/Registry.mjs +1 -1
  16. package/dist/lib/neutral/Relation.mjs +12 -12
  17. package/dist/lib/neutral/Tag.mjs +15 -15
  18. package/dist/lib/neutral/Text.mjs +25 -0
  19. package/dist/lib/neutral/Text.mjs.map +7 -0
  20. package/dist/lib/neutral/Type.mjs +10 -10
  21. package/dist/lib/neutral/chunk-2HKGAQM4.mjs +1394 -0
  22. package/dist/lib/neutral/chunk-2HKGAQM4.mjs.map +7 -0
  23. package/dist/lib/neutral/{chunk-O6BH7EPN.mjs → chunk-2ZHECXUR.mjs} +5 -4
  24. package/dist/lib/neutral/chunk-2ZHECXUR.mjs.map +7 -0
  25. package/dist/lib/neutral/{chunk-QQIYS74I.mjs → chunk-3KTE2Y7Q.mjs} +20 -20
  26. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs.map +7 -0
  27. package/dist/lib/neutral/{chunk-R5W6DXR4.mjs → chunk-3TN2VMI4.mjs} +72 -36
  28. package/dist/lib/neutral/chunk-3TN2VMI4.mjs.map +7 -0
  29. package/dist/lib/neutral/{chunk-5SMDBFVB.mjs → chunk-42L4HJ3Z.mjs} +11 -15
  30. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs.map +7 -0
  31. package/dist/lib/neutral/{chunk-7PI7C4EF.mjs → chunk-4A2NWKRJ.mjs} +5 -5
  32. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs +1531 -0
  33. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs.map +7 -0
  34. package/dist/lib/neutral/{chunk-SBVFRTST.mjs → chunk-BEFR7LEA.mjs} +20 -10
  35. package/dist/lib/neutral/chunk-BEFR7LEA.mjs.map +7 -0
  36. package/dist/lib/neutral/{chunk-6M2Z6WBH.mjs → chunk-BXIKXT7Q.mjs} +2 -6
  37. package/dist/lib/neutral/{chunk-6M2Z6WBH.mjs.map → chunk-BXIKXT7Q.mjs.map} +1 -1
  38. package/dist/lib/neutral/{chunk-UUP46KUQ.mjs → chunk-C57XMMBY.mjs} +21 -20
  39. package/dist/lib/neutral/chunk-C57XMMBY.mjs.map +7 -0
  40. package/dist/lib/neutral/chunk-C62JYFAD.mjs +183 -0
  41. package/dist/lib/neutral/chunk-C62JYFAD.mjs.map +7 -0
  42. package/dist/lib/neutral/{chunk-MZ7K3MLL.mjs → chunk-FSGX2R62.mjs} +3 -3
  43. package/dist/lib/neutral/chunk-FSGX2R62.mjs.map +7 -0
  44. package/dist/lib/neutral/{chunk-TYGKCRMK.mjs → chunk-HBXT3GSB.mjs} +37 -15
  45. package/dist/lib/neutral/chunk-HBXT3GSB.mjs.map +7 -0
  46. package/dist/lib/neutral/{chunk-WU3GIANS.mjs → chunk-IQR45HAD.mjs} +1 -1
  47. package/dist/lib/neutral/chunk-IQR45HAD.mjs.map +7 -0
  48. package/dist/lib/neutral/{chunk-TFEWTY5A.mjs → chunk-KCBW4BR6.mjs} +4 -8
  49. package/dist/lib/neutral/chunk-KCBW4BR6.mjs.map +7 -0
  50. package/dist/lib/neutral/{chunk-WTQJHC75.mjs → chunk-L3E5IXAE.mjs} +225 -45
  51. package/dist/lib/neutral/chunk-L3E5IXAE.mjs.map +7 -0
  52. package/dist/lib/neutral/{chunk-EVK6XBXO.mjs → chunk-PRC4FEKJ.mjs} +2 -2
  53. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs.map +7 -0
  54. package/dist/lib/neutral/{chunk-6YDI3J37.mjs → chunk-SCT6FFCR.mjs} +9 -4
  55. package/dist/lib/neutral/chunk-SCT6FFCR.mjs.map +7 -0
  56. package/dist/lib/neutral/{chunk-BBFJWWAV.mjs → chunk-TOCVVFK2.mjs} +26 -2
  57. package/dist/lib/neutral/chunk-TOCVVFK2.mjs.map +7 -0
  58. package/dist/lib/neutral/{chunk-RIVWNMSF.mjs → chunk-U53LSQQA.mjs} +3 -3
  59. package/dist/lib/neutral/{chunk-RIVWNMSF.mjs.map → chunk-U53LSQQA.mjs.map} +1 -1
  60. package/dist/lib/neutral/{chunk-IGK6FN65.mjs → chunk-UGFFV2FR.mjs} +2 -2
  61. package/dist/lib/neutral/{chunk-35INCYOE.mjs → chunk-UWLP4RFM.mjs} +1 -1
  62. package/dist/lib/neutral/chunk-UWLP4RFM.mjs.map +7 -0
  63. package/dist/lib/neutral/{chunk-LWXVKPPW.mjs → chunk-UZHCQ6NI.mjs} +13 -11
  64. package/dist/lib/neutral/{chunk-LWXVKPPW.mjs.map → chunk-UZHCQ6NI.mjs.map} +3 -3
  65. package/dist/lib/neutral/{chunk-5SUJPHAE.mjs → chunk-WKIT2YY5.mjs} +2 -2
  66. package/dist/lib/neutral/{chunk-T6E37YIP.mjs → chunk-XB6ISRAO.mjs} +38 -18
  67. package/dist/lib/neutral/chunk-XB6ISRAO.mjs.map +7 -0
  68. package/dist/lib/neutral/chunk-XXL42WCB.mjs +84 -0
  69. package/dist/lib/neutral/chunk-XXL42WCB.mjs.map +7 -0
  70. package/dist/lib/neutral/{chunk-ZGNNFYHS.mjs → chunk-XXWK4J53.mjs} +27 -42
  71. package/dist/lib/neutral/chunk-XXWK4J53.mjs.map +7 -0
  72. package/dist/lib/neutral/index.mjs +30 -26
  73. package/dist/lib/neutral/internal/index.mjs +111 -69
  74. package/dist/lib/neutral/meta.json +1 -1
  75. package/dist/lib/neutral/testing/index.mjs +79 -60
  76. package/dist/lib/neutral/testing/index.mjs.map +3 -3
  77. package/dist/types/src/Annotation.d.ts +35 -1
  78. package/dist/types/src/Annotation.d.ts.map +1 -1
  79. package/dist/types/src/Collection.d.ts +9 -8
  80. package/dist/types/src/Collection.d.ts.map +1 -1
  81. package/dist/types/src/Database.d.ts +38 -0
  82. package/dist/types/src/Database.d.ts.map +1 -1
  83. package/dist/types/src/Dataset.d.ts +1 -16
  84. package/dist/types/src/Dataset.d.ts.map +1 -1
  85. package/dist/types/src/Entity.d.ts +2 -0
  86. package/dist/types/src/Entity.d.ts.map +1 -1
  87. package/dist/types/src/Err.d.ts +67 -0
  88. package/dist/types/src/Err.d.ts.map +1 -1
  89. package/dist/types/src/Feed.d.ts +59 -80
  90. package/dist/types/src/Feed.d.ts.map +1 -1
  91. package/dist/types/src/Filter.d.ts +9 -1
  92. package/dist/types/src/Filter.d.ts.map +1 -1
  93. package/dist/types/src/Hypergraph.d.ts +2 -9
  94. package/dist/types/src/Hypergraph.d.ts.map +1 -1
  95. package/dist/types/src/Migration.d.ts +1 -1
  96. package/dist/types/src/Migration.d.ts.map +1 -1
  97. package/dist/types/src/Obj.d.ts +33 -6
  98. package/dist/types/src/Obj.d.ts.map +1 -1
  99. package/dist/types/src/Order.d.ts +1 -1
  100. package/dist/types/src/Order.d.ts.map +1 -1
  101. package/dist/types/src/Query.d.ts +1 -1
  102. package/dist/types/src/Query.d.ts.map +1 -1
  103. package/dist/types/src/QueryResult.d.ts +2 -2
  104. package/dist/types/src/QueryResult.d.ts.map +1 -1
  105. package/dist/types/src/Ref.d.ts +10 -6
  106. package/dist/types/src/Ref.d.ts.map +1 -1
  107. package/dist/types/src/Registry.d.ts +1 -1
  108. package/dist/types/src/Relation.d.ts.map +1 -1
  109. package/dist/types/src/Tag.d.ts +11 -13
  110. package/dist/types/src/Tag.d.ts.map +1 -1
  111. package/dist/types/src/Text.d.ts +41 -0
  112. package/dist/types/src/Text.d.ts.map +1 -0
  113. package/dist/types/src/Text.test.d.ts +2 -0
  114. package/dist/types/src/Text.test.d.ts.map +1 -0
  115. package/dist/types/src/Type.d.ts +38 -21
  116. package/dist/types/src/Type.d.ts.map +1 -1
  117. package/dist/types/src/View.d.ts +8 -9
  118. package/dist/types/src/View.d.ts.map +1 -1
  119. package/dist/types/src/index.d.ts +1 -0
  120. package/dist/types/src/index.d.ts.map +1 -1
  121. package/dist/types/src/internal/Annotation/annotations.d.ts +50 -0
  122. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
  123. package/dist/types/src/internal/Annotation/atoms.d.ts +14 -0
  124. package/dist/types/src/internal/Annotation/atoms.d.ts.map +1 -0
  125. package/dist/types/src/internal/Annotation/entity-dictionary.d.ts +13 -0
  126. package/dist/types/src/internal/Annotation/entity-dictionary.d.ts.map +1 -1
  127. package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
  128. package/dist/types/src/internal/Entity/guard.d.ts.map +1 -1
  129. package/dist/types/src/internal/Entity/model.d.ts +1 -1
  130. package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
  131. package/dist/types/src/internal/Entity/object.d.ts +5 -1
  132. package/dist/types/src/internal/Entity/object.d.ts.map +1 -1
  133. package/dist/types/src/internal/Entity/relation.d.ts +7 -0
  134. package/dist/types/src/internal/Entity/relation.d.ts.map +1 -1
  135. package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -1
  136. package/dist/types/src/internal/Filter/index.d.ts +2 -0
  137. package/dist/types/src/internal/Filter/index.d.ts.map +1 -0
  138. package/dist/types/src/internal/Filter/match.d.ts +22 -0
  139. package/dist/types/src/internal/Filter/match.d.ts.map +1 -0
  140. package/dist/types/src/internal/Format/format.d.ts +0 -2
  141. package/dist/types/src/internal/Format/format.d.ts.map +1 -1
  142. package/dist/types/src/internal/Format/index.d.ts +2 -2
  143. package/dist/types/src/internal/Format/index.d.ts.map +1 -1
  144. package/dist/types/src/internal/Format/string.d.ts +0 -8
  145. package/dist/types/src/internal/Format/string.d.ts.map +1 -1
  146. package/dist/types/src/internal/Format/types.d.ts +2 -1
  147. package/dist/types/src/internal/Format/types.d.ts.map +1 -1
  148. package/dist/types/src/internal/Obj/atoms.d.ts +12 -3
  149. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
  150. package/dist/types/src/internal/Obj/clone.d.ts +2 -1
  151. package/dist/types/src/internal/Obj/clone.d.ts.map +1 -1
  152. package/dist/types/src/internal/Obj/create-object.d.ts +3 -4
  153. package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -1
  154. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
  155. package/dist/types/src/internal/Query/index.d.ts +1 -0
  156. package/dist/types/src/internal/Query/index.d.ts.map +1 -1
  157. package/dist/types/src/internal/Query/query-result-effect.d.ts +9 -0
  158. package/dist/types/src/internal/Query/query-result-effect.d.ts.map +1 -0
  159. package/dist/types/src/internal/Ref/atoms.d.ts +1 -2
  160. package/dist/types/src/internal/Ref/atoms.d.ts.map +1 -1
  161. package/dist/types/src/internal/Ref/index.d.ts +1 -0
  162. package/dist/types/src/internal/Ref/index.d.ts.map +1 -1
  163. package/dist/types/src/internal/Ref/ref.d.ts +79 -8
  164. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
  165. package/dist/types/src/internal/Ref/strong-deps.d.ts +35 -0
  166. package/dist/types/src/internal/Ref/strong-deps.d.ts.map +1 -0
  167. package/dist/types/src/internal/common/atom-snapshot.d.ts +8 -0
  168. package/dist/types/src/internal/common/atom-snapshot.d.ts.map +1 -0
  169. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
  170. package/dist/types/src/internal/common/proxy/proxy-types.d.ts +12 -0
  171. package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -1
  172. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts +25 -0
  173. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
  174. package/dist/types/src/internal/common/proxy/schema-validator.d.ts +5 -0
  175. package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -1
  176. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +17 -0
  177. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
  178. package/dist/types/src/internal/common/types/entity.d.ts +4 -4
  179. package/dist/types/src/internal/common/types/entity.d.ts.map +1 -1
  180. package/dist/types/src/internal/common/types/meta.d.ts +2 -4
  181. package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
  182. package/dist/types/src/internal/index.d.ts +1 -0
  183. package/dist/types/src/internal/index.d.ts.map +1 -1
  184. package/dist/types/src/testing/test-schema.d.ts +42 -171
  185. package/dist/types/src/testing/test-schema.d.ts.map +1 -1
  186. package/dist/types/tsconfig.tsbuildinfo +1 -1
  187. package/package.json +20 -13
  188. package/src/Annotation.test.ts +257 -10
  189. package/src/Annotation.ts +58 -4
  190. package/src/Collection.ts +10 -12
  191. package/src/Database.ts +55 -21
  192. package/src/Entity.ts +3 -1
  193. package/src/Err.ts +22 -0
  194. package/src/Feed.ts +117 -141
  195. package/src/Filter.test.ts +38 -0
  196. package/src/Filter.ts +17 -3
  197. package/src/Hypergraph.ts +2 -11
  198. package/src/Migration.ts +1 -1
  199. package/src/Obj.test.ts +92 -12
  200. package/src/Obj.ts +38 -5
  201. package/src/Order.ts +3 -3
  202. package/src/Query.test.ts +2 -2
  203. package/src/Query.ts +16 -16
  204. package/src/QueryResult.ts +2 -2
  205. package/src/Ref.ts +14 -6
  206. package/src/Registry.ts +1 -1
  207. package/src/Relation.ts +1 -1
  208. package/src/Tag.ts +13 -16
  209. package/src/Text.test.ts +186 -0
  210. package/src/Text.ts +116 -0
  211. package/src/Type.test.ts +52 -24
  212. package/src/Type.ts +85 -33
  213. package/src/View.ts +22 -30
  214. package/src/index.ts +1 -1
  215. package/src/internal/Annotation/annotations.ts +71 -2
  216. package/src/internal/Annotation/atoms.ts +107 -0
  217. package/src/internal/Annotation/entity-dictionary.ts +40 -37
  218. package/src/internal/Entity/api.ts +1 -1
  219. package/src/internal/Entity/guard.ts +2 -1
  220. package/src/internal/Entity/model.ts +2 -2
  221. package/src/internal/Entity/object.ts +14 -1
  222. package/src/internal/Entity/relation.ts +19 -0
  223. package/src/internal/Entity/type-uri.ts +3 -1
  224. package/src/internal/Filter/index.ts +5 -0
  225. package/src/internal/Filter/match.ts +284 -0
  226. package/src/internal/Format/format.ts +0 -2
  227. package/src/internal/Format/index.ts +2 -2
  228. package/src/internal/Format/string.ts +0 -12
  229. package/src/internal/Format/types.ts +4 -2
  230. package/src/internal/JsonSchema/json-schema.test.ts +82 -54
  231. package/src/internal/Obj/atoms.ts +62 -18
  232. package/src/internal/Obj/clone.ts +61 -20
  233. package/src/internal/Obj/create-object.test.ts +3 -3
  234. package/src/internal/Obj/create-object.ts +3 -4
  235. package/src/internal/Obj/inspect.ts +1 -1
  236. package/src/internal/Obj/json-serializer.test.ts +7 -5
  237. package/src/internal/Obj/json-serializer.ts +4 -4
  238. package/src/internal/Obj/schema-validator.test.ts +53 -0
  239. package/src/internal/Obj/set-value.test.ts +29 -19
  240. package/src/internal/Query/index.ts +1 -0
  241. package/src/internal/Query/query-result-effect.ts +35 -0
  242. package/src/internal/Ref/atoms.ts +23 -3
  243. package/src/internal/Ref/index.ts +1 -0
  244. package/src/internal/Ref/ref.test.ts +8 -8
  245. package/src/internal/Ref/ref.ts +122 -39
  246. package/src/internal/Ref/strong-deps.ts +107 -0
  247. package/src/internal/common/atom-snapshot.ts +19 -0
  248. package/src/internal/common/proxy/make-object.ts +1 -1
  249. package/src/internal/common/proxy/proxy-types.ts +20 -0
  250. package/src/internal/common/proxy/proxy-utils.ts +37 -1
  251. package/src/internal/common/proxy/reactive-array.ts +3 -3
  252. package/src/internal/common/proxy/reactive.test.ts +1 -1
  253. package/src/internal/common/proxy/schema-validator.ts +181 -8
  254. package/src/internal/common/proxy/typed-handler.ts +254 -76
  255. package/src/internal/common/types/entity.ts +15 -7
  256. package/src/internal/index.ts +1 -0
  257. package/src/testing/test-schema.ts +75 -90
  258. package/dist/lib/neutral/chunk-35INCYOE.mjs.map +0 -7
  259. package/dist/lib/neutral/chunk-3PBP4V4O.mjs +0 -101
  260. package/dist/lib/neutral/chunk-3PBP4V4O.mjs.map +0 -7
  261. package/dist/lib/neutral/chunk-4ZUHOTCG.mjs +0 -184
  262. package/dist/lib/neutral/chunk-4ZUHOTCG.mjs.map +0 -7
  263. package/dist/lib/neutral/chunk-5SMDBFVB.mjs.map +0 -7
  264. package/dist/lib/neutral/chunk-6YDI3J37.mjs.map +0 -7
  265. package/dist/lib/neutral/chunk-7FPIAJIV.mjs +0 -2279
  266. package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +0 -7
  267. package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +0 -7
  268. package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +0 -7
  269. package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +0 -7
  270. package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +0 -7
  271. package/dist/lib/neutral/chunk-QQIYS74I.mjs.map +0 -7
  272. package/dist/lib/neutral/chunk-R5W6DXR4.mjs.map +0 -7
  273. package/dist/lib/neutral/chunk-SBVFRTST.mjs.map +0 -7
  274. package/dist/lib/neutral/chunk-T6E37YIP.mjs.map +0 -7
  275. package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +0 -7
  276. package/dist/lib/neutral/chunk-TYGKCRMK.mjs.map +0 -7
  277. package/dist/lib/neutral/chunk-UUP46KUQ.mjs.map +0 -7
  278. package/dist/lib/neutral/chunk-WTQJHC75.mjs.map +0 -7
  279. package/dist/lib/neutral/chunk-WU3GIANS.mjs.map +0 -7
  280. package/dist/lib/neutral/chunk-ZGNNFYHS.mjs.map +0 -7
  281. package/dist/types/src/exemplars.test.d.ts +0 -2
  282. package/dist/types/src/exemplars.test.d.ts.map +0 -1
  283. package/dist/types/src/hierarchy.test.d.ts +0 -2
  284. package/dist/types/src/hierarchy.test.d.ts.map +0 -1
  285. package/src/exemplars.test.ts +0 -21
  286. package/src/hierarchy.test.ts +0 -33
  287. /package/dist/lib/neutral/{chunk-7PI7C4EF.mjs.map → chunk-4A2NWKRJ.mjs.map} +0 -0
  288. /package/dist/lib/neutral/{chunk-IGK6FN65.mjs.map → chunk-UGFFV2FR.mjs.map} +0 -0
  289. /package/dist/lib/neutral/{chunk-5SUJPHAE.mjs.map → chunk-WKIT2YY5.mjs.map} +0 -0
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/Ref.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport type * as internal from './internal';\nimport * as refInternal from './internal/Ref';\nimport type * as JsonSchema from './JsonSchema';\nimport type * as Obj from './Obj';\n// eslint-disable-next-line @dxos/rules/import-as-namespace\nimport type * as TypeNs from './Type';\n\n/**\n * Instance type for a reference.\n *\n * Reference can point to any object or relation.\n * References are lazy loaded.\n *\n * `ref.dxn` is the DXN of the referenced object.\n *\n * @example\n * ```ts\n * const taskRef: Ref<Task> = Ref.make(task);\n *\n * await taskRef.load(); // Returns Promise<Task>\n * yield* Database.load(taskRef); // Effectful version.\n *\n * database.makeRef(dxn); // Create a ref from a DXN.\n * ```\n */\nexport type Ref<T> = refInternal.Ref<T>;\nexport type Unknown = refInternal.Ref<Obj.Unknown>;\n\n/**\n * Factory function to create a Ref schema for the given target schema.\n * Use this in schema definitions to declare reference fields.\n *\n * @example\n * ```ts\n * const Task = Schema.Struct({\n * assignee: Ref.Ref(Person), // Creates a Ref schema\n * }).pipe(Type.makeObject(DXN.make('com.example.type.task', '0.1.0')));\n * ```\n */\nexport const Ref: {\n <S extends TypeNs.AnyObj | TypeNs.AnyRelation>(type: S): RefSchema<TypeNs.InstanceType<S> & Obj.Unknown>;\n\n // `Type.Type` entities (the meta-schema kind) can be referenced too — e.g. a\n // trigger that points to a stored function/workflow definition.\n <T extends TypeNs.Type<any>>(type: T): RefSchema<TypeNs.InstanceType<T>>;\n\n // Schema-side overload for the well-known \"any object\" / \"any relation\" schemas.\n // Other raw `Schema.Schema` values are intentionally rejected — callers should\n // pass a `Type.Type` entity instead.\n <S extends internal.UnknownTypeSchema<any, any>>(schema: S): RefSchema<Schema.Schema.Type<S> & Obj.Unknown>;\n} = refInternal.Ref as any;\n\nexport const Array = refInternal.RefArray;\n\n/**\n * TypeScript type for a Ref schema.\n * This is the type of the SCHEMA itself, not the runtime ref instance.\n * For the instance type, use `Ref.Ref<T>` from the Ref module.\n *\n * @example\n * ```ts\n * // Schema type annotation (rarely needed, usually inferred):\n * const refSchema: Ref.RefSchema<typeof Task> = Ref.Ref(Task);\n *\n * // Instance type annotation (use Ref.Ref instead):\n * const refInstance: Ref.Ref<Task> = Ref.make(task);\n * ```\n */\n// TODO(dmaretskyi): Investigate if we can remove this type.\n// Post DX-836 it will become just `Schema.Schema<Ref.Ref<T>>`.\n// NOTE: This could be Type.Ref<T> instead, but since it going to be removed, it's better to keep it here, self-contained.\nexport interface RefSchema<T extends Entity.Unknown> extends refInternal.RefSchema<T> {}\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Unknown> = R extends refInternal.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = refInternal.RefResolver;\n\nexport const isRef: (value: unknown) => value is Unknown = refInternal.Ref.isRef;\n\nexport const make = refInternal.Ref.make;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept URI.\nexport const fromURI = (uri: URI.URI): refInternal.Ref<any> => refInternal.Ref.fromURI(uri);\n\nexport const hasEntityId = refInternal.Ref.hasEntityId;\n\n// TODO(wittjosiah): Factor out?\nexport const isRefType = (ast: SchemaAST.AST): boolean => {\n return SchemaAST.getAnnotation<JsonSchema.JsonSchema>(ast, SchemaAST.JSONSchemaAnnotationId).pipe(\n Option.flatMap((jsonSchema) => ('$id' in jsonSchema ? Option.some(jsonSchema) : Option.none())),\n Option.flatMap((jsonSchema) => {\n const { typename } = refInternal.getSchemaReference(jsonSchema) ?? {};\n return typename ? Option.some(true) : Option.some(false);\n }),\n Option.getOrElse(() => false),\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;;AAAA;;;aAAAA;EAAA;;;;;;AAMA,YAAYC,YAAY;AAExB,YAAYC,eAAe;AA4CpB,IAAMC,OAWGA;AAET,IAAMC,QAAoBC;AA+B1B,IAAMC,QAA0DH,IAAIG;AAEpE,IAAMC,OAAmBJ,IAAII;AAG7B,IAAMC,UAAU,CAACC,QAAmDN,IAAIK,QAAQC,GAAAA;AAEhF,IAAMC,cAA0BP,IAAIO;AAGpC,IAAMC,YAAY,CAACC,QAAAA;AACxB,SAAiBC,wBAAqCD,KAAeE,gCAAsB,EAAEC,KACpFC,eAAQ,CAACC,eAAgB,SAASA,aAAoBC,YAAKD,UAAAA,IAAqBE,YAAI,CAAA,GACpFH,eAAQ,CAACC,eAAAA;AACd,UAAM,EAAEG,SAAQ,IAAiBC,mBAAmBJ,UAAAA,KAAe,CAAC;AACpE,WAAOG,WAAkBF,YAAK,IAAA,IAAeA,YAAK,KAAA;EACpD,CAAA,GACOI,iBAAU,MAAM,KAAA,CAAA;AAE3B;",
6
- "names": ["Ref", "Option", "SchemaAST", "Ref", "Array", "RefArray", "isRef", "make", "fromURI", "uri", "hasEntityId", "isRefType", "ast", "getAnnotation", "JSONSchemaAnnotationId", "pipe", "flatMap", "jsonSchema", "some", "none", "typename", "getSchemaReference", "getOrElse"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/internal/common/types/entity.ts", "../../../src/internal/Annotation/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.\n// Unique symbols cause TS4023 \"cannot be named\" errors when external packages\n// try to export types that reference this key (e.g., `export const Graph = ...`).\n// TypeScript cannot emit declaration files that reference unique symbols from\n// external modules. Using a string literal allows the type to be inlined in\n// declaration files, making the API portable across package boundaries.\n\n/**\n * String key used to identify the kind of an entity instance (object or relation).\n */\nexport const KindId = '~@dxos/echo/Kind' as const;\nexport type KindId = typeof KindId;\n\n/**\n * String key used to identify the kind of a schema (object schema or relation schema).\n * Parallels KindId which identifies instance kinds.\n */\nexport const SchemaKindId = '~@dxos/echo/SchemaKind' as const;\nexport type SchemaKindId = typeof SchemaKindId;\n\n/**\n * String key used to brand snapshot types.\n * Snapshots have SnapshotKindId instead of KindId, making them\n * distinguishable from reactive objects at the type level.\n */\nexport const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;\nexport type SnapshotKindId = typeof SnapshotKindId;\n\n/**\n * Hidden slot on a static `Type.Type` entity that holds the source Effect\n * Schema. `Type.getSchema(...)` reads this for static types; persisted types\n * rebuild from `jsonSchema` instead. Stored as a string key for declaration\n * portability (see KindId comment above).\n */\nexport const StaticTypeSchemaSlot = '~@dxos/echo/Type.StaticSchema' as const;\nexport type StaticTypeSchemaSlot = typeof StaticTypeSchemaSlot;\n\n/**\n * Read the hidden `StaticTypeSchemaSlot` off any value that may carry one.\n * Returns `undefined` for raw schemas (no slot) and non-object inputs.\n * Single point-of-cast for the slot lookup.\n */\nexport const getStaticTypeSchema = (value: unknown): Schema.Schema.AnyNoContext | undefined => {\n if (value == null || typeof value !== 'object') {\n return undefined;\n }\n return (value as { [StaticTypeSchemaSlot]?: Schema.Schema.AnyNoContext })[StaticTypeSchemaSlot];\n};\n\n/**\n * Read the `[SchemaKindId]` brand off a value. Returns `undefined` for raw\n * schemas (which don't carry the brand on their static type) and non-object\n * inputs. Single point-of-cast for the brand lookup.\n */\nexport const getSchemaKind = (value: unknown): EntityKind | undefined => {\n if (value == null || typeof value !== 'object') {\n return undefined;\n }\n return (value as { [SchemaKindId]?: EntityKind })[SchemaKindId];\n};\n\n/**\n * Read the `[KindId]` brand off a value. Returns `undefined` for raw schemas\n * and non-object inputs. Companion to {@link getSchemaKind}.\n */\nexport const getEntityKindBrand = (value: unknown): EntityKind | undefined => {\n if (value == null || typeof value !== 'object') {\n return undefined;\n }\n return (value as { [KindId]?: EntityKind })[KindId];\n};\n\n/**\n * Phantom string key on `Type<A>` entities that carries the instance type `A`.\n * Lets internal helpers (`makeObject`, `createObject`, etc.) pattern-match the\n * instance type from an entity input without importing from the top-level\n * `Type` module. Mirrors `Type.InstancePhantomId` (declared in `Type.ts`).\n *\n * Stored as a string key so declarations remain portable across packages\n * (see KindId comment above).\n */\nexport const InstancePhantomId = '~@dxos/echo/Type.Instance' as const;\nexport type InstancePhantomId = typeof InstancePhantomId;\n\n/**\n * Nominal brand carried by the well-known \"any object\" / \"any relation\"\n * schemas (`Obj.Unknown`, `Relation.Unknown`). The brand lets `Ref.Ref`,\n * `Filter.type`, and `Query.type` accept these schemas in addition to\n * `Type.Type` entities, without opening the door to arbitrary raw schemas.\n *\n * Stored as a string key so declarations remain portable across packages\n * (see KindId comment above).\n */\nexport const UnknownTypeSchemaBrandId = '~@dxos/echo/UnknownTypeSchemaBrand' as const;\nexport type UnknownTypeSchemaBrandId = typeof UnknownTypeSchemaBrandId;\n\n/**\n * Schema-side companion to `Type.Type` entities for the \"any object\" /\n * \"any relation\" cases. Branded so `Ref.Ref` / `Filter.type` / `Query.type`\n * can pattern-match on it; arbitrary `Schema.Schema` values do not satisfy\n * this shape.\n */\nexport interface UnknownTypeSchema<A, K extends EntityKind> extends Schema.Schema<A, any, never> {\n readonly [UnknownTypeSchemaBrandId]: K;\n}\n\n/**\n * Kinds of entities stored in ECHO: objects, relations, and types.\n */\nexport enum EntityKind {\n Object = 'object',\n Relation = 'relation',\n Type = 'type',\n}\n\nexport const EntityKindSchema = Schema.Enums(EntityKind);\n\n/**\n * Typename for generic object references (Type.Obj / Ref.Ref(Obj.Unknown)).\n * Used when referencing any object without a specific schema.\n */\nexport const ANY_OBJECT_TYPENAME = 'org.dxos.schema.anyObject';\n\n/**\n * Version for generic object references.\n */\nexport const ANY_OBJECT_VERSION = '0.0.0';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\n\nimport { EntityKind } from '../common/types';\n\nexport interface AnnotationHelper<T> {\n /**\n * Get the annotation value from an Effect schema.\n *\n * Only accepts `Schema.Schema.Any` — to read an annotation off a `Type.Type`\n * entity, unwrap it first with `Type.getSchema(entity)`. This keeps the\n * annotation pipeline single-shaped and forces annotations to live on the\n * source schema, not on the post-construction Type entity.\n */\n get: (schema: Schema.Schema.Any) => Option.Option<T>;\n /**\n * Get the annotation value from the AST.\n */\n getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;\n /**\n * Set the annotation on an Effect schema.\n *\n * Only accepts `Schema.Schema.Any` — annotations must be applied to the\n * source schema BEFORE wrapping it with `Type.makeObject` / `Type.makeRelation`.\n * In a pipe, place every `Annotation.X.set(...)` before the `Type.make...` step.\n */\n set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;\n}\n\n/**\n * Note: only for system annotations.\n */\n// TODO(dmaretskyi): Rename to createSystemAnnotationHelper.\n// TODO(dmaretskyi): REconcile with Annotation.make.\nexport const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {\n return {\n get: (schema) => SchemaAST.getAnnotation(schema.ast, id),\n getFromAst: (ast) => SchemaAST.getAnnotation(ast, id),\n set:\n (value) =>\n <S extends Schema.Schema.Any>(schema: S): S =>\n schema.annotations({ [id]: value }) as S,\n };\n};\n\n/**\n * If property is optional returns the nested property, otherwise returns the property.\n */\n// TODO(wittjosiah): Is there a way to do this as a generic?\nexport const unwrapOptional = (property: SchemaAST.PropertySignature) => {\n if (!property.isOptional || !SchemaAST.isUnion(property.type)) {\n return property;\n }\n\n return property.type.types[0];\n};\n\n/**\n * @see JSONSchemaAnnotationId\n * @returns JSON-schema annotation so that the schema can be serialized with correct parameters.\n */\n// TODO(burdon): Required type.\nexport const makeTypeJsonSchemaAnnotation = (options: {\n identifier?: string;\n kind: EntityKind;\n typename: string;\n version: string;\n relationSource?: string;\n relationTarget?: string;\n}) => {\n assertArgument(!!options.relationSource === (options.kind === EntityKind.Relation), 'relationSource');\n assertArgument(!!options.relationTarget === (options.kind === EntityKind.Relation), 'relationTarget');\n\n const obj: Record<string, unknown> = {\n $id: options.identifier ?? DXN.make(options.typename, options.version),\n entityKind: options.kind,\n version: options.version,\n typename: options.typename,\n };\n if (options.kind === EntityKind.Relation) {\n obj.relationSource = { $ref: options.relationSource };\n obj.relationTarget = { $ref: options.relationTarget };\n }\n\n return obj;\n};\n"],
5
- "mappings": ";AAIA,YAAYA,YAAY;AAYjB,IAAMC,SAAS;AAOf,IAAMC,eAAe;AAQrB,IAAMC,iBAAiB;AASvB,IAAMC,uBAAuB;AAQ7B,IAAMC,sBAAsB,CAACC,UAAAA;AAClC,MAAIA,SAAS,QAAQ,OAAOA,UAAU,UAAU;AAC9C,WAAOC;EACT;AACA,SAAQD,MAAkEF,oBAAAA;AAC5E;AAOO,IAAMI,gBAAgB,CAACF,UAAAA;AAC5B,MAAIA,SAAS,QAAQ,OAAOA,UAAU,UAAU;AAC9C,WAAOC;EACT;AACA,SAAQD,MAA0CJ,YAAAA;AACpD;AAMO,IAAMO,qBAAqB,CAACH,UAAAA;AACjC,MAAIA,SAAS,QAAQ,OAAOA,UAAU,UAAU;AAC9C,WAAOC;EACT;AACA,SAAQD,MAAoCL,MAAAA;AAC9C;AAWO,IAAMS,oBAAoB;AAY1B,IAAMC,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undefined", "getSchemaKind", "getEntityKindBrand", "InstancePhantomId", "UnknownTypeSchemaBrandId", "EntityKind", "EntityKindSchema", "Enums", "ANY_OBJECT_TYPENAME", "ANY_OBJECT_VERSION", "SchemaAST", "assertArgument", "DXN", "createAnnotationHelper", "id", "get", "schema", "getAnnotation", "ast", "getFromAst", "set", "value", "annotations", "unwrapOptional", "property", "isOptional", "isUnion", "type", "types", "makeTypeJsonSchemaAnnotation", "options", "assertArgument", "relationSource", "kind", "EntityKind", "Relation", "relationTarget", "obj", "$id", "identifier", "DXN", "make", "typename", "version", "entityKind", "$ref"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/Query.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport type * as EffectArray from 'effect/Array';\nimport type * as Schema from 'effect/Schema';\n\nimport { type QueryAST } from '@dxos/echo-protocol';\nimport { type URI } from '@dxos/keys';\n\nimport type * as Collection from './Collection';\nimport * as Database from './Database';\nimport type * as Dataset from './Dataset';\nimport * as Feed from './Feed';\nimport * as Filter from './Filter';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport type * as Order from './Order';\nimport type * as Ref from './Ref';\nimport type * as Relation from './Relation';\n// eslint-disable-next-line @dxos/rules/import-as-namespace\nimport type * as Type$ from './Type';\nimport type * as View from './View';\n\n// TODO(dmaretskyi): Split up into interfaces for objects and relations so they can have separate verbs.\n// TODO(dmaretskyi): Undirected relation traversals.\n// TODO(wittjosiah): Make Filter & Query pipeable.\n\n/**\n * All property paths inside T that are references.\n */\n// TODO(dmaretskyi): Filter only properties that are references (or optional references, or unions that include references).\ntype RefPropKey<T> = keyof T & string;\n\ntype RefArrayElement<A> = A extends readonly (infer E)[] ? E : A extends (infer E)[] ? E : never;\n\n/** Target entity when traversing an outgoing ref or array-of-refs property. */\ntype ReferenceTraversalTarget<P> = P extends Ref.Unknown\n ? Ref.Target<P>\n : P extends Ref.Unknown | undefined\n ? Ref.Target<Exclude<P, undefined>>\n : RefArrayElement<P> extends Ref.Unknown\n ? Ref.Target<RefArrayElement<P>>\n : never;\n\n// TODO(burdon): Narrow T to Entity.Unknown?\nexport interface Query<T> {\n // TODO(dmaretskyi): See new effect-schema approach to variance.\n '~Query': { value: T };\n\n ast: QueryAST.Query;\n\n /**\n * Filter the current selection based on a filter.\n * @param filter - Filter to select the objects.\n * @returns Query for the selected objects.\n */\n 'select'(filter: Filter.Filter<T>): Query<T>;\n 'select'(props: Filter.Props<T>): Query<T>;\n\n /**\n * Traverse an outgoing reference.\n * @param key - Property path inside T that is a reference or optional reference.\n * @returns Query for the target of the reference.\n */\n 'reference'<K extends RefPropKey<T>>(key: K): Query<ReferenceTraversalTarget<T[K]>>;\n\n /**\n * Find objects referencing this object.\n * @param target - Schema of the referencing object. If not provided, matches any type.\n * @param key - Property path inside the referencing object that is a reference. If not provided, matches any property.\n * @returns Query for the referencing objects.\n */\n // TODO(dmaretskyi): any way to enforce `Ref.Target<Schema.Schema.Type<S>[key]> == T`?\n // TODO(dmaretskyi): Ability to go through arrays of references.\n 'referencedBy'<S extends Type$.AnyEntity>(\n target: S | URI.URI,\n key: RefPropKey<Type$.InstanceType<S>>,\n ): Query<Type$.InstanceType<S>>;\n 'referencedBy'<S extends Type$.AnyEntity>(target: S | URI.URI): Query<Type$.InstanceType<S>>;\n 'referencedBy'(): Query<any>;\n\n /**\n * Find relations where this object is the source.\n * @returns Query for the relation objects.\n * @param relation - Schema of the relation.\n * @param predicates - Predicates to filter the relation objects.\n */\n 'sourceOf'<R extends Type$.AnyRelation>(\n relation?: R | URI.URI,\n predicates?: Filter.Props<Type$.InstanceType<R>>,\n ): Query<Type$.InstanceType<R>>;\n\n /**\n * Find relations where this object is the target.\n * @returns Query for the relation objects.\n * @param relation - Type entity of the relation.\n * @param predicates - Predicates to filter the relation objects.\n */\n 'targetOf'<R extends Type$.AnyRelation>(\n relation?: R | URI.URI,\n predicates?: Filter.Props<Type$.InstanceType<R>>,\n ): Query<Type$.InstanceType<R>>;\n\n /**\n * For a query for relations, get the source objects.\n * @returns Query for the source objects.\n */\n 'source'(): Query<Relation.SourceOf<T>>;\n\n /**\n * For a query for relations, get the target objects.\n * @returns Query for the target objects.\n */\n 'target'(): Query<Relation.TargetOf<T>>;\n\n /**\n * Get the parent object of the current selection.\n * @returns Query for the parent objects.\n */\n 'parent'(): Query<any>;\n\n /**\n * Get all child objects of the current selection.\n * @returns Query for the child objects.\n */\n 'children'(): Query<any>;\n\n /**\n * Order the query results.\n * Orders are specified in priority order. The first order will be applied first, etc.\n * @param order - Order to sort the results.\n * @returns Query for the ordered results.\n */\n 'orderBy'(...order: EffectArray.NonEmptyArray<Order.Order<T>>): Query<T>;\n\n /**\n * Limit the number of results.\n * @param limit - Maximum number of results to return.\n * @returns Query for the limited results.\n */\n 'limit'(limit: number): Query<T>;\n\n /**\n * Query from selected databases only.\n *\n * Example:\n *\n * ```ts\n * Query.select(Filter.type(Person)).from(db);\n * ```\n *\n * @param options.includeFeeds [false] - Whether to include feeds in the query. Default is to query from automerge documents only.\n */\n 'from'(database: Database.Database | Database.Database[], options?: { includeFeeds?: boolean }): Query<T>;\n\n /**\n * Query from selected feeds only.\n *\n * Example:\n *\n * ```ts\n * Query.select(Filter.type(Person)).from(feed);\n * ```\n *\n */\n 'from'(feeds: Feed.Feed | Feed.Feed[]): Query<T>;\n\n /**\n * Query from all accessible spaces.\n *\n * Example:\n *\n * ```ts\n * Query.select(Filter.type(Person)).from('all-accessible-spaces');\n * ```\n *\n * @param options.includeFeeds [false] - Whether to include feeds in the query. Default is to query from automerge documents only.\n */\n 'from'(allSpaces: 'all-accessible-spaces', options?: { includeFeeds?: boolean }): Query<T>;\n\n /**\n * Query from a dataset.\n * Currently only feeds are supported.\n *\n * Example:\n *\n * ```ts\n * Query.type(Person).from(feed);\n * ```\n */\n 'from'(dataset: Dataset.Dataset): Query<T>;\n\n /**\n * Query from the results of another query.\n *\n * Example:\n *\n * ```ts\n * Query.select(Filter.props({ foo: 'foo' })).from(Query.select(Filter.type(Contact)).reference('org'));\n * ```\n */\n 'from'(query: Any): Query<T>;\n\n /**\n * Query from one or more raw scopes.\n *\n * Use the {@link Scope} constructors rather than raw tagged objects:\n *\n * ```ts\n * Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry());\n * ```\n */\n 'from'(...scopes: QueryAST.Scope[]): Query<T>;\n\n /**\n * Query from a raw scope or array of scopes.\n */\n 'from'(scope: QueryAST.Scope | QueryAST.Scope[]): Query<T>;\n\n /**\n * Add options to a query.\n */\n 'options'(options: QueryAST.QueryOptions): Query<T>;\n\n /**\n * Attach a diagnostic label for logs and tooling (execution semantics unchanged).\n */\n 'debugLabel'(label: string): Query<T>;\n}\n\nexport type Any = Query<any>;\n\nexport type Type<Q extends Any> = Q extends Query<infer T> ? T : never;\n\nclass QueryClass implements Any {\n private static 'variance': Any['~Query'] = {} as Any['~Query'];\n\n constructor(public readonly ast: QueryAST.Query) {}\n\n '~Query' = QueryClass.variance;\n\n select(filter: Filter.Any | Filter.Props<any>): Any {\n if (Filter.is(filter)) {\n return new QueryClass({\n type: 'filter',\n selection: this.ast,\n filter: filter.ast,\n });\n } else {\n return new QueryClass({\n type: 'filter',\n selection: this.ast,\n filter: Filter.props(filter).ast,\n });\n }\n }\n\n reference(key: string): Any {\n return new QueryClass({\n type: 'reference-traversal',\n anchor: this.ast,\n property: key,\n });\n }\n\n referencedBy(target?: Type$.AnyEntity | URI.URI, key?: string): Any {\n const uri = target !== undefined ? internal.getTypeURIFromSpecifier(target) : null;\n return new QueryClass({\n type: 'incoming-references',\n anchor: this.ast,\n property: key ?? null,\n typename: uri ?? null,\n });\n }\n\n sourceOf(relation?: Type$.AnyRelation | URI.URI, predicates?: Filter.Props<unknown> | undefined): Any {\n return new QueryClass({\n type: 'relation',\n anchor: this.ast,\n direction: 'outgoing',\n filter: relation !== undefined ? Filter.type(relation, predicates).ast : undefined,\n });\n }\n\n targetOf(relation?: Type$.AnyRelation | URI.URI, predicates?: Filter.Props<unknown> | undefined): Any {\n return new QueryClass({\n type: 'relation',\n anchor: this.ast,\n direction: 'incoming',\n filter: relation !== undefined ? Filter.type(relation, predicates).ast : undefined,\n });\n }\n\n source(): Any {\n return new QueryClass({\n type: 'relation-traversal',\n anchor: this.ast,\n direction: 'source',\n });\n }\n\n target(): Any {\n return new QueryClass({\n type: 'relation-traversal',\n anchor: this.ast,\n direction: 'target',\n });\n }\n\n parent(): Any {\n return new QueryClass({\n type: 'hierarchy-traversal',\n anchor: this.ast,\n direction: 'to-parent',\n });\n }\n\n children(): Any {\n return new QueryClass({\n type: 'hierarchy-traversal',\n anchor: this.ast,\n direction: 'to-children',\n });\n }\n\n orderBy(...order: Order.Order<any>[]): Any {\n return new QueryClass({\n type: 'order',\n query: this.ast,\n order: order.map((o) => o.ast),\n });\n }\n\n limit(limit: number): Any {\n return new QueryClass({\n type: 'limit',\n query: this.ast,\n limit,\n });\n }\n\n from(\n ...args:\n | [\n (\n | Database.Database\n | Database.Database[]\n | Feed.Feed\n | Feed.Feed[]\n | Collection.Collection\n | View.View\n | Any\n | QueryAST.Scope\n | QueryAST.Scope[]\n | 'all-accessible-spaces'\n ),\n { includeFeeds?: boolean }?,\n ]\n | QueryAST.Scope[]\n ): Any {\n // Variadic raw scopes: `.from(Scope.space(), Scope.registry())`.\n if (args.length > 1 && args.every(_isRawScope)) {\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: { _tag: 'scope', scopes: args as QueryAST.Scope[] },\n });\n }\n\n const [arg, options] = args as [\n (\n | Database.Database\n | Database.Database[]\n | Feed.Feed\n | Feed.Feed[]\n | Collection.Collection\n | View.View\n | Any\n | QueryAST.Scope\n | QueryAST.Scope[]\n | 'all-accessible-spaces'\n ),\n { includeFeeds?: boolean }?,\n ];\n if (arg == null) {\n throw new TypeError(\n 'Query.from() requires a valid data source argument (database, feed, query, scope, or \"all-accessible-spaces\").',\n );\n }\n\n if (is(arg)) {\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: { _tag: 'query', query: arg.ast },\n });\n }\n\n if (arg === 'all-accessible-spaces') {\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: { _tag: 'scope', scopes: [] },\n });\n }\n\n // Raw scope(s): tagged union objects with _tag 'space' | 'feed' | 'registry'.\n if (Array.isArray(arg) && arg.every(_isRawScope)) {\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: { _tag: 'scope', scopes: arg as QueryAST.Scope[] },\n });\n }\n if (_isRawScope(arg)) {\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: { _tag: 'scope', scopes: [arg] },\n });\n }\n\n const items = Array.isArray(arg) ? arg : [arg];\n\n if (items.length > 0 && Database.isDatabase(items[0])) {\n const databases = items as Database.Database[];\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: {\n _tag: 'scope',\n scopes: databases.map((db) => ({\n _tag: 'space' as const,\n spaceId: db.spaceId,\n ...(options?.includeFeeds ? { includeAllFeeds: true } : {}),\n })),\n },\n });\n }\n\n if (items.length > 0) {\n const typename = Obj.getTypename(items[0] as Obj.Unknown);\n // TODO(dmaretskyi): Support querying from views.\n if (typename === 'org.dxos.type.view') {\n throw new Error('Query.from(view) is not yet supported.');\n }\n // TODO(dmaretskyi): Support querying from collections.\n if (typename === 'org.dxos.type.collection') {\n throw new Error('Query.from(collection) is not yet supported.');\n }\n // Validate that the items are Feed.Feed instances.\n for (const item of items) {\n if (!Obj.instanceOf(Feed.Feed, item)) {\n throw new TypeError(\n `Query.from() expects Feed objects (org.dxos.type.feed), but received an object with typename '${typename ?? 'unknown'}'.`,\n );\n }\n }\n }\n\n const feedItems = items as Feed.Feed[];\n const feedScopes = feedItems.map((feed) => {\n const uri = Feed.getQueueUri(feed);\n if (!uri) {\n throw new TypeError(\n `Query.from() expects persisted Feed objects with a queue URI; got feed without a space (id=${Obj.getURI(feed)}).`,\n );\n }\n return { _tag: 'feed' as const, feedUri: String(uri) };\n });\n return new QueryClass({\n type: 'from',\n query: this.ast,\n from: { _tag: 'scope', scopes: feedScopes },\n });\n }\n\n options(options: QueryAST.QueryOptions): Any {\n return new QueryClass({\n type: 'options',\n query: this.ast,\n options,\n });\n }\n\n debugLabel(label: string): Any {\n if (this.ast.type === 'options') {\n return new QueryClass({\n type: 'options',\n query: this.ast.query,\n options: { ...this.ast.options, debugLabel: label },\n });\n }\n return new QueryClass({\n type: 'options',\n query: this.ast,\n options: { debugLabel: label },\n });\n }\n}\n\nexport const is = (value: unknown): value is Any => {\n return typeof value === 'object' && value !== null && '~Query' in value;\n};\n\n/** Construct a query from an ast. */\nexport const fromAst = (ast: QueryAST.Query): Any => {\n return new QueryClass(ast);\n};\n\n/**\n * Select objects based on a filter.\n * @param filter - Filter to select the objects.\n * @returns Query for the selected objects.\n */\nexport const select = <F extends Filter.Any>(filter: F): Query<Filter.Type<F>> => {\n return new QueryClass({\n type: 'select',\n filter: filter.ast,\n });\n};\n\n/**\n * Query for objects of a given schema.\n * @param schema - Schema of the objects.\n * @param predicates - Predicates to filter the objects.\n * @returns Query for the objects.\n *\n * Shorthand for: `Query.select(Filter.type(schema, predicates))`.\n */\nexport const type: {\n <T extends Type$.AnyEntity>(type: T, predicates?: Filter.Props<Type$.InstanceType<T>>): Query<Type$.InstanceType<T>>;\n // Brand-narrowed schema overload — only well-known unknown schemas pass.\n <S extends internal.UnknownTypeSchema<any, any>>(\n schema: S,\n predicates?: Filter.Props<Schema.Schema.Type<S>>,\n ): Query<Schema.Schema.Type<S>>;\n <S extends Schema.Union<readonly Schema.Schema.AnyNoContext[]>>(\n union: S,\n predicates?: Filter.Props<Schema.Schema.Type<S>>,\n ): Query<Schema.Schema.Type<S>>;\n (uri: URI.URI, predicates?: Filter.Props<unknown>): Query<any>;\n} = (type: Type$.AnyEntity | URI.URI, predicates?: Filter.Props<unknown>): Any => {\n return new QueryClass({\n type: 'select',\n filter: Filter.type(type, predicates).ast,\n });\n};\n\n/**\n * Combine results of multiple queries.\n * @param queries - Queries to combine.\n * @returns Query for the combined results.\n */\n// TODO(dmaretskyi): Rename to `combine` or `union`.\nexport const all = (...queries: Any[]): Any => {\n if (queries.length === 0) {\n throw new TypeError(\n 'Query.all combines results of multiple queries, to query all objects use Query.select(Filter.everything())',\n );\n }\n return new QueryClass({\n type: 'union',\n queries: queries.map((q) => q.ast),\n });\n};\n\n/**\n * Subtract one query from another.\n * @param source - Query to subtract from.\n * @param exclude - Query to subtract.\n * @returns Query for the results of the source query minus the results of the exclude query.\n */\nexport const without = <T>(source: Query<T>, exclude: Query<T>): Query<T> => {\n return new QueryClass({\n type: 'set-difference',\n source: source.ast,\n exclude: exclude.ast,\n });\n};\n\n/**\n * Create a query scoped to a data source.\n * The returned query selects everything from the source; chain `.select()` to narrow results.\n *\n * @param source - Data source: database, feed, 'all-accessible-spaces', or another query.\n * @returns Query scoped to the given source.\n */\nexport const from = (\n ...args:\n | [\n (\n | Database.Database\n | Database.Database[]\n | Feed.Feed\n | Feed.Feed[]\n | Any\n | QueryAST.Scope\n | QueryAST.Scope[]\n | 'all-accessible-spaces'\n ),\n { includeFeeds?: boolean }?,\n ]\n | QueryAST.Scope[]\n): Any => {\n const baseQuery: QueryAST.Query = {\n type: 'select',\n filter: Filter.everything().ast,\n };\n const wrapper = new QueryClass(baseQuery);\n return (wrapper.from as (...args: unknown[]) => Any)(...args);\n};\n\nconst SCOPE_TAGS = new Set<string>(['space', 'feed', 'registry']);\n\n/** Detect a raw Scope tagged-union object. */\nconst _isRawScope = (value: unknown): value is QueryAST.Scope => {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n '_tag' in value &&\n typeof value._tag === 'string' &&\n SCOPE_TAGS.has(value._tag)\n );\n};\n\n/**\n * Returns a human-readable string representation of a Query AST.\n */\nexport const pretty = (query: Any): string => internal.prettyQuery(query.ast);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;YAAAA;EAAA;;cAAAC;EAAA;;AA6OA,IAAMC,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BM,MAAM;IACN+D,SAASA,QAAQvC,IAAI,CAACwC,MAAMA,EAAErE,GAAG;EACnC,CAAA;AACF;AAQO,IAAMsE,UAAU,CAAI/C,QAAkBgD,YAAAA;AAC3C,SAAO,IAAIxE,WAAW;IACpBM,MAAM;IACNkB,QAAQA,OAAOvB;IACfuE,SAASA,QAAQvE;EACnB,CAAA;AACF;AASO,IAAMgC,OAAO,IACfC,SAAAA;AAgBH,QAAMuC,YAA4B;IAChCnE,MAAM;IACNF,QAAesE,WAAU,EAAGzE;EAC9B;AACA,QAAM0E,UAAU,IAAI3E,WAAWyE,SAAAA;AAC/B,SAAQE,QAAQ1C,KAAI,GAAoCC,IAAAA;AAC1D;AAEA,IAAM0C,aAAa,oBAAIC,IAAY;EAAC;EAAS;EAAQ;CAAW;AAGhE,IAAMxC,cAAc,CAAC6B,UAAAA;AACnB,SACE,OAAOA,UAAU,YACjBA,UAAU,QACV,CAACvB,MAAMC,QAAQsB,KAAAA,KACf,UAAUA,SACV,OAAOA,MAAM5B,SAAS,YACtBsC,WAAWE,IAAIZ,MAAM5B,IAAI;AAE7B;AAKO,IAAMyC,SAAS,CAAClD,UAAgCmD,YAAYnD,MAAM5B,GAAG;",
6
- "names": ["is", "type", "QueryClass", "ast", "variance", "select", "filter", "is", "type", "selection", "props", "reference", "key", "anchor", "property", "referencedBy", "target", "uri", "undefined", "getTypeURIFromSpecifier", "typename", "sourceOf", "relation", "predicates", "direction", "targetOf", "source", "parent", "children", "orderBy", "order", "query", "map", "o", "limit", "from", "args", "length", "every", "_isRawScope", "_tag", "scopes", "arg", "options", "TypeError", "Array", "isArray", "items", "isDatabase", "databases", "db", "spaceId", "includeFeeds", "includeAllFeeds", "getTypename", "Error", "item", "instanceOf", "Feed", "feedItems", "feedScopes", "feed", "getQueueUri", "getURI", "feedUri", "String", "debugLabel", "label", "value", "fromAst", "all", "queries", "q", "without", "exclude", "baseQuery", "everything", "wrapper", "SCOPE_TAGS", "Set", "has", "pretty", "prettyQuery"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/Database.ts", "../../../src/internal/Entity/type-uri.ts", "../../../src/internal/Annotation/annotations.ts", "../../../src/internal/common/types/model-symbols.ts", "../../../src/internal/common/types/typename.ts", "../../../src/internal/Annotation/dictionary.ts", "../../../src/internal/Entity/api.ts", "../../../src/internal/Entity/model.ts", "../../../src/internal/Entity/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Effectable from 'effect/Effectable';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { EffectEx } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId, type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport * as Err from './Err';\nimport type * as Filter from './Filter';\nimport type * as Hypergraph from './Hypergraph';\nimport { type AnyProperties, EntityKind, KindId } from './internal/common/types';\n// Deep import (not the `./internal/Entity` barrel) to avoid a cycle:\n// Database → internal/Entity → entity → JsonSchema → Ref → Database.\nimport { isInstanceOf } from './internal/Entity/type-uri';\nimport type { Ref } from './internal/Ref/ref';\nimport type * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport type * as Registry from './Registry';\nimport type * as Type from './Type';\n\n/**\n * `query` API function declaration.\n */\n// TODO(burdon): Reconcile Query and Filter (should only have one root type).\nexport interface QueryFn {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResult<Query.Type<Q>>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResult<Filter.Type<F>>;\n}\n\n/**\n * Common interface for Database, Feed, and Hypergraph.\n */\nexport interface Queryable {\n query: QueryFn;\n}\n\nexport type GetObjectByIdOptions = {\n deleted?: boolean;\n};\n\nexport type ObjectPlacement = 'root-doc' | 'linked-doc';\n\nexport type AddOptions = {\n /**\n * Where to place the object in the Automerge document tree.\n * Root document is always loaded with the space.\n * Linked documents are loaded lazily.\n * Placing large number of objects in the root document may slow down the initial load.\n *\n * @default 'linked-doc'\n */\n placeIn?: ObjectPlacement;\n};\n\n/**\n * Rejects Type entities from {@link Database.add} at compile time via their `[KindId]` brand. Used\n * as `T & RejectTypeEntity<T>` to preserve inference of `T`. Bounding `add` on\n * `Obj.Unknown | Relation.Unknown` instead would reject broadly-typed instance adds (e.g.\n * `Entity.Any`, `Obj.OfShape<T>`), forcing casts repo-wide.\n */\nexport type RejectTypeEntity<T> = T extends { readonly [KindId]: EntityKind.Type }\n ? { __error: 'Type entities must be persisted via db.addType(), not db.add().' }\n : T;\n\nexport type FlushOptions = {\n /**\n * Write any pending changes to disk.\n * @default true\n */\n disk?: boolean;\n\n /**\n * Wait for pending index updates.\n * @default true\n */\n indexes?: boolean;\n\n /**\n * Flush pending updates to objects and queries.\n * @default false\n */\n updates?: boolean;\n};\n\n/**\n * Identifier denoting an ECHO Database.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Database');\nexport type TypeId = typeof TypeId;\n\n/**\n * ECHO Database interface.\n */\nexport interface Database extends Queryable {\n readonly [TypeId]: TypeId;\n\n get spaceId(): SpaceId;\n\n get graph(): Hypergraph.Hypergraph;\n\n /**\n * Registry for this database. Delegates type lookups to the shared hypergraph registry.\n * To persist a schema so it replicates to other clients, add the type entity with\n * {@link addType} (e.g. `await db.addType(Type.makeObjectFromJsonSchema(...))`).\n */\n readonly registry: Registry.Registry;\n\n toJSON(): object;\n\n /**\n * Return object by local ID.\n * @deprecated Use `db.query(Filter.id(id)).runSync()[0]` for a working-set lookup, or resolve via a {@link Ref}.\n */\n getObjectById<T extends Obj.Unknown = Obj.OfShape<AnyProperties>>(\n id: string,\n opts?: GetObjectByIdOptions,\n ): T | undefined;\n\n /**\n * Query objects.\n */\n query: QueryFn;\n\n /**\n * Creates a reference to an existing object in the database.\n *\n * NOTE: The reference may be dangling if the object is not present in the database.\n * NOTE: Difference from `Ref.fromURI`\n * `Ref.fromURI(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n * `db.makeRef(dxn)` is preferable in cases with access to the database.\n */\n makeRef<T extends Entity.Unknown = Entity.Unknown>(uri: URI.URI): Ref<T>;\n\n /**\n * Adds an object or relation to the database.\n *\n * Only Object and Relation entities are accepted. To persist a Type definition use\n * {@link addType} — passing a Type entity is rejected at compile time (and at runtime).\n */\n add<T extends Entity.Unknown = Entity.Unknown>(obj: T & RejectTypeEntity<T>, opts?: AddOptions): T;\n\n /**\n * Persists a Type definition (clones/forks the entity) so it replicates to other peers.\n *\n * Runs a conflict query first: if a type with the same typename + version already exists in\n * this space, the existing persisted entity is returned and no duplicate is created. This is\n * the only supported way to add Type entities — {@link add} rejects them.\n */\n addType<T extends Type.AnyEntity>(type: T): Promise<T>;\n\n /**\n * Removes object from the database.\n */\n // TODO(burdon): Return true if removed (currently throws if not present).\n remove(obj: Entity.Unknown): void;\n\n /**\n * Wait for all pending changes to be saved to disk.\n * Optionaly waits for changes to be propagated to indexes and event handlers.\n */\n flush(opts?: FlushOptions): Promise<void>;\n}\n\nexport const isDatabase = (obj: unknown): obj is Database => {\n return obj ? typeof obj === 'object' && TypeId in obj && obj[TypeId] === TypeId : false;\n};\n\nexport const Database: Schema.Schema<Database> = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));\n\n/**\n * Effect service tag for Database dependency injection.\n */\nexport class Service extends Context.Tag('@dxos/echo/Database/Service')<\n Service,\n {\n readonly db: Database;\n }\n>() {}\n\n/**\n * Layer that provides a Database service that throws when accessed.\n * Useful as a default layer when no database is available.\n */\nexport const notAvailable = Layer.succeed(Service, {\n get db(): Database {\n throw new Error('Database not available');\n },\n});\n\n/**\n * Creates a Database service instance from a Database.\n */\nexport const makeService = (db: Database): Context.Tag.Service<Service> => {\n return {\n get db() {\n return db;\n },\n };\n};\n\n/**\n * Creates a Layer that provides the Database service.\n */\nexport const layer = (db: Database): Layer.Layer<Service> => {\n return Layer.succeed(Service, makeService(db));\n};\n\n/**\n * Returns the space ID of the database.\n */\nexport const spaceId = Effect.gen(function* () {\n const { db } = yield* Service;\n return db.spaceId;\n});\n\n/**\n * Resolves an object by its DXN.\n */\nexport const resolve: {\n // No type check.\n (ref: URI.URI | Ref<any>): Effect.Effect<Entity.Unknown, never, Service>;\n // Check matches schema.\n <S extends Type.AnyEntity>(\n ref: URI.URI | Ref<any>,\n schema: S,\n ): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service>;\n} = (<S extends Type.AnyEntity>(\n ref: URI.URI | Ref<any>,\n schema?: S,\n): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service> =>\n Effect.gen(function* () {\n const { db } = yield* Service;\n const dxn = typeof ref === 'string' ? ref : ref.uri;\n const object = yield* EffectEx.promiseWithCauseCapture(() =>\n db.graph\n .createRefResolver({\n context: {\n space: db.spaceId,\n },\n })\n .resolve(dxn),\n );\n\n if (!object) {\n return yield* Effect.fail(new Err.EntityNotFoundError(dxn));\n }\n // `isInstanceOf` uses a conditional generic that TS can't resolve through\n // the local `S extends Type.AnyEntity` parameter — runtime accepts it fine.\n invariant(!schema || isInstanceOf(schema as any, object), 'Object type mismatch.');\n return object as any;\n }).pipe(Effect.withSpan('Database.resolve'))) as any;\n\n/**\n * Loads an object reference.\n *\n * Catching not found error:\n *\n * ```ts\n * yield* load(ref).pipe(Effect.catchTag('EntityNotFoundError', () => Effect.succeed(undefined)));\n * ```\n *\n */\nexport const load: <T>(ref: Ref<T>) => Effect.Effect<T, Err.EntityNotFoundError, never> = Effect.fn('Database.load')(\n function* (ref) {\n const object = yield* EffectEx.promiseWithCauseCapture(() => ref.tryLoad());\n if (!object) {\n return yield* Effect.fail(new Err.EntityNotFoundError(ref.uri));\n }\n return object;\n },\n);\n\n/**\n * Adds an object or relation to the database.\n * @see {@link Database.add}\n */\nexport const add = <T extends Entity.Unknown>(obj: T & RejectTypeEntity<T>): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.add<T>(obj))).pipe(Effect.withSpan('Database.add'));\n\n/**\n * Persists a Type definition to the database.\n * @see {@link Database.addType}\n */\nexport const addType = <T extends Type.AnyEntity>(type: T): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.addType(type)))).pipe(\n Effect.withSpan('Database.addType'),\n );\n\n/**\n * Removes an object from the database.\n * @see {@link Database.remove}\n */\nexport const remove = <T extends Entity.Unknown>(obj: T): Effect.Effect<void, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.remove(obj))).pipe(Effect.withSpan('Database.remove'));\n\n/**\n * Flushes pending changes to disk.\n * @see {@link Database.flush}\n */\nexport const flush = (opts?: FlushOptions) =>\n Service.pipe(Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.flush(opts)))).pipe(\n Effect.withSpan('Database.flush'),\n );\n\n/**\n * Creates a `QueryResult` object that can be subscribed to.\n */\nexport const query: {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResultEffect<Query.Type<Q>, never, Service>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResultEffect<Filter.Type<F>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n Service.pipe(\n Effect.map(({ db }) => db.query(queryOrFilter as any) as QueryResult.QueryResult<any>),\n Effect.withSpan('Database.query'),\n makeQueryResultEffect,\n );\n\nconst makeQueryResultEffect = <T>(\n eff: Effect.Effect<QueryResult.QueryResult<T>, never, Service>,\n): QueryResult.QueryResultEffect<T, never, Service> => {\n return {\n run: Effect.flatMap(eff, (result) => EffectEx.promiseWithCauseCapture(() => result.run())),\n first: Effect.flatMap(eff, (result) =>\n EffectEx.promiseWithCauseCapture(async () => Option.fromNullable(await result.firstOrUndefined())),\n ),\n\n // Effect internals\n ...Effectable.CommitPrototype,\n commit() {\n return eff;\n },\n } as any;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN, EID, URI } from '@dxos/keys';\n\nimport { getSchemaURI, getTypename } from '../Annotation/annotations';\nimport { type AnyEntity, InstancePhantomId, KindId, TypeId, getStaticTypeSchema } from '../common/types';\nimport { getUri as getUriFromEntity } from './api';\n\n/**\n * @param input schema, `Type.Type` entity, or a type URI (an `echo:` EID or a `dxn:` DXN).\n * @return type identifier URI — see {@link getSchemaURI}. A URI is returned verbatim. For a\n * `Type.Type` entity, the URI of the schema it declares, symmetric with what\n * `Obj.make(typeEntity, ...)` stamps on `system.type`: a static declaration resolves to its\n * typename DXN, a persisted entity to its local `echo:/<objectId>`.\n */\nexport const getTypeURIFromSpecifier = (input: Schema.Schema.All | AnyEntity | URI.URI): URI.URI => {\n if (Schema.isSchema(input)) {\n return getSchemaURI(input) ?? raise(new TypeError('Schema has no URI'));\n }\n if (typeof input === 'object' && input !== null && KindId in input) {\n // `Type.Type` entity. Both in-memory and persisted forms expose the schema\n // they declare via `StaticTypeSchemaSlot`, whose URI is exactly what\n // `Obj.make` stamps on `system.type` — a static declaration carries\n // `TypeAnnotation` (→ typename DXN), a persisted entity's rebuilt schema\n // carries `TypeIdentifierAnnotation` (→ local `echo:/<objectId>`).\n const schema = getStaticTypeSchema(input);\n if (schema != null) {\n // Static types carry TypeAnnotation → DXN; persisted db types carry\n // TypeIdentifierAnnotation → echo EID. In-memory makeObjectFromJsonSchema\n // entities have neither (plain JSON Schema), so fall through to the EID path.\n const uri = getSchemaURI(schema);\n if (uri != null) {\n return uri;\n }\n }\n return getUriFromEntity(input as AnyEntity);\n }\n // A string specifier is already a branded URI — an `echo:` EID or a `dxn:` DXN.\n assertArgument(EID.isEID(input) || DXN.isDXN(input), 'input', 'expected a type URI (EID or DXN)');\n return input;\n};\n\n/**\n * Checks if the object is an instance of the schema.\n * Only typename is compared, the schema version is ignored.\n *\n * The following cases are considered to mean that the object is an instance of the schema:\n * - Object was created with this exact schema.\n * - Object was created with a different version of this schema.\n * - Object was created with a different schema (maybe dynamic) that has the same typename.\n */\n// TODO(burdon): Can we use `Schema.is`?\nexport const isInstanceOf = <S>(\n schemaOrType: S extends Schema.Schema.AnyNoContext ? S : Schema.Schema.AnyNoContext | AnyEntity,\n object: any,\n): object is S extends Schema.Schema.AnyNoContext\n ? Schema.Schema.Type<S>\n : S extends { readonly [InstancePhantomId]?: infer A }\n ? A\n : unknown => {\n if (object == null) {\n return false;\n }\n\n const schemaURI = getTypeURIFromSpecifier(schemaOrType);\n\n // `object` is arbitrary input — read TypeId directly (it may be missing on\n // non-entities) rather than via `getTypeURI` which asserts the URI is set.\n const type = (object as any)[TypeId];\n if (URI.isURI(type) && type === schemaURI) {\n return true;\n }\n\n const typename = getTypename(object);\n if (!typename) {\n return false;\n }\n\n if (!DXN.isDXN(schemaURI)) {\n // EID-based schema URI — no typename match possible.\n return false;\n }\n\n const parsed = DXN.tryMake(schemaURI);\n return parsed != null && DXN.getName(parsed) === typename;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { SchemaEx } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, URI } from '@dxos/keys';\nimport { type Primitive } from '@dxos/util';\n\nimport type * as Annotation from '../../Annotation';\nimport { type Mutable } from '../common/proxy';\nimport { type AnyProperties, EntityKind, TypeId, getSchema } from '../common/types';\nimport { createAnnotationHelper } from './util';\n\nconst ANNOTATION_TYPE_ID: Annotation.TypeId = '~@dxos/echo/Annotation' as const;\n\n/**\n * @internal\n */\nexport const FIELD_PATH_ANNOTATION = 'path';\n\n/**\n * Sets the path for the field.\n * @param path Data source path in the json path format. This is the field path in the source object.\n */\n// TODO(burdon): Field, vs. path vs. property.\nexport const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);\n\n//\n// Type\n//\n\n/**\n * ECHO identifier (for a stored schema).\n * Must be an `echo:` URI.\n */\nexport const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');\n\nexport const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>\n Function.flow(\n SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n\n/**\n * @returns The schema's type identifier URI — whichever URI fits.\n *\n * - Stored (dynamic) schemas: the schema-as-object's EID, so loaded objects ride\n * along with their schema as a strong dependency.\n * - Non-stored (static) schemas: the typename DXN built from `TypeAnnotation`.\n *\n * This URI is what gets written to an object's `system.type`; queries that filter by\n * type also use it (see `Filter.type` / `getTypeURIFromSpecifier`), so both sides\n * stay symmetric without per-schema branching.\n */\nexport const getSchemaURI = (schema: Schema.Schema.All): URI.URI | undefined => {\n assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');\n const id = getTypeIdentifierAnnotation(schema);\n if (id) {\n return URI.make(id);\n }\n const objectAnnotation = getTypeAnnotation(schema);\n if (objectAnnotation) {\n return DXN.make(objectAnnotation.typename, objectAnnotation.version);\n }\n return undefined;\n};\n\n//\n// TypeAnnotation\n//\n\n/**\n * Fully qualified globally unique typename.\n * Example: `org.dxos.type.message`\n */\n// TODO(wittjosiah): Factor out to DXN spec.\nexport const TypenameSchema = Schema.String.pipe(\n Schema.pattern(\n /^[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})?)$/,\n ),\n).annotations({\n description: 'Fully qualified globally unique typename in reverse-DNS form.',\n example: 'org.dxos.type.message',\n});\n\n/**\n * Semantic version format: `major.minor.patch`\n * Example: `1.0.0`\n */\nexport const VersionSchema = Schema.String.pipe(Schema.pattern(/^\\d+.\\d+.\\d+$/)).annotations({\n description: 'Semantic version format: `major.minor.patch`',\n example: '1.0.0',\n});\n\nexport const TypeMeta = Schema.Struct({\n typename: TypenameSchema,\n version: VersionSchema,\n});\n\nexport interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}\n\n/**\n * Entity type.\n */\nexport const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');\n\n/**\n * Payload stored under {@link TypeAnnotationId}.\n */\nexport const TypeAnnotation = Schema.extend(\n TypeMeta,\n Schema.Struct({\n kind: Schema.Enums(EntityKind),\n\n /**\n * If this is a relation, the schema of the source object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n sourceSchema: Schema.optional(DXN.Schema),\n\n /**\n * If this is a relation, the schema of the target object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n targetSchema: Schema.optional(DXN.Schema),\n }),\n);\n\nexport interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}\n\n/**\n * @returns {@link TypeAnnotation} from a schema.\n * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.\n */\nexport const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {\n assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');\n return Function.flow(\n SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n};\n\n/**\n * @returns {@link EntityKind} from a schema.\n */\nexport const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;\n\n/**\n * @internal\n * @returns Schema typename (without dxn: prefix or version number).\n */\nexport const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;\n\n/**\n * @internal\n * @returns Schema version in semver format.\n */\nexport const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;\n\n/**\n * Gets the typename of the object without the version.\n * Returns only the name portion, not the DXN.\n * @example \"org.example.type.contact\"\n *\n * @internal (use Obj.getTypename)\n */\nexport const getTypename = (obj: AnyProperties): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n // Try to extract typename from DXN.\n return getSchemaTypename(schema);\n } else {\n // `obj` may be an arbitrary value (e.g. from `isInstanceOf`); read TypeId\n // directly so we return undefined for non-entities instead of throwing.\n const type = (obj as any)?.[TypeId];\n // Parse the URI string to extract typename.\n if (DXN.isDXN(type)) {\n const parsed = DXN.tryMake(type);\n return parsed && DXN.getName(parsed);\n }\n return undefined;\n }\n};\n\n/**\n * @internal (use Type.setTypename)\n */\n// TODO(dmaretskyi): Rename setTypeDXN.\nexport const setTypename = (obj: any, typename: URI.URI): void => {\n assertArgument(typeof typename === 'string', 'typename', 'Invalid type.');\n Object.defineProperty(obj, TypeId, {\n value: typename,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * @returns Object type URI — either a typename {@link DXN} or an `echo:` reference to a stored Schema object.\n * @returns undefined if the object has no registered type URI (e.g. unresolved query result).\n * @example `dxn:com.example.type.person:1.0.0`\n * @example `echo:/01KKKG2FHWCMTR0BY00GJSVT1X` (stored schema)\n *\n * @internal (use Obj.getTypeURI)\n */\nexport const getTypeURI = (obj: AnyProperties): URI.URI | undefined => {\n if (obj == null) {\n return undefined;\n }\n const type = (obj as any)[TypeId];\n if (type == null) {\n return undefined;\n }\n invariant(URI.isURI(type), 'Invalid object.');\n return type;\n};\n\n//\n// PropertyMeta\n//\n\n/**\n * PropertyMeta (metadata for dynamic schema properties).\n * For user-defined annotations.\n */\nexport const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');\n\nexport type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];\n\nexport type PropertyMetaAnnotation = {\n [name: string]: PropertyMetaValue;\n};\n\n// TODO(wittjosiah): Align with other annotations.\n// TODO(wittjosiah): Why is this separate from FormatAnnotation?\n/**\n * Apply property-level metadata to an Effect schema. Only accepts\n * `Schema.Schema.Any` — apply BEFORE wrapping the schema with\n * `Type.makeObject` / `Type.makeRelation`. To read property meta off a\n * `Type.Type` entity, unwrap it first with `Type.getSchema(entity)`.\n */\nexport const PropertyMeta = (name: string, value: PropertyMetaValue) => {\n return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {\n const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;\n return self.annotations({\n [PropertyMetaAnnotationId]: {\n ...existingMeta,\n [name]: value,\n },\n });\n };\n};\n\nexport const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>\n Function.pipe(\n SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),\n Option.map((meta) => meta[name] as T),\n Option.getOrElse(() => undefined),\n );\n\n//\n// Reference\n//\n\n/**\n * Schema reference.\n */\nexport const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');\nexport type ReferenceAnnotationValue = TypeAnnotation;\nexport const ReferenceAnnotation = createAnnotationHelper<ReferenceAnnotationValue>(ReferenceAnnotationId);\n\n/**\n * SchemaMeta.\n */\nexport const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');\nexport type SchemaMeta = TypeMeta & { id: string };\n\n/**\n * Identifies a schema as hidden from user-facing surfaces (like dotfiles — visible only via an advanced setting).\n */\nexport const HiddenAnnotationId = Symbol.for('@dxos/schema/annotation/Hidden');\nexport const HiddenAnnotation = createAnnotationHelper<boolean>(HiddenAnnotationId);\n\n/**\n * Identifies label property or JSON path expression.\n * Either a string or an array of strings representing field accessors each matched in priority order.\n */\nexport const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');\nexport const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);\n\n/**\n * Returns the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n * Skips empty strings and whitespace-only strings, continuing to the next field.\n */\n// TODO(burdon): Convert to SchemaEx.JsonPath?\nexport const getLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));\n for (const accessor of annotation) {\n assertArgument(\n typeof accessor === 'string',\n 'accessor',\n 'Label annotation must be a string or an array of strings',\n );\n const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);\n switch (typeof value) {\n case 'string': {\n const trimmed = value.trim();\n if (trimmed.length > 0) {\n return value;\n }\n continue;\n }\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n continue;\n }\n }\n\n return undefined;\n};\n\n/**\n * Sets the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n label: string,\n) => {\n const annotation = LabelAnnotation.get(schema).pipe(\n Option.map((field) => field[0]),\n Option.getOrElse(() => 'name'),\n );\n object[annotation] = label;\n};\n\n/**\n * Identifies description property or JSON path expression.\n * A string representing field accessor.\n */\nexport const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');\nexport const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);\n\n/**\n * Returns the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\n// TODO(burdon): Convert to SchemaEx.JsonPath?\nexport const getDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');\n const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n default:\n return undefined;\n }\n};\n\n/**\n * Sets the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n description: string,\n) => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n object[accessor] = description;\n};\n\n/**\n * Identifies if a property should be included in a form or not.\n * By default, all properties are included in forms, so this is opt-out.\n */\nexport const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');\nexport const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);\n\n/**\n * When set on a `Ref` property, the form renders the referenced object's own\n * fields inline (a nested form bound to the target) instead of a picker.\n */\nexport const FormInlineAnnotationId = Symbol.for('@dxos/schema/annotation/FormInline');\nexport const FormInlineAnnotation = createAnnotationHelper<boolean>(FormInlineAnnotationId);\n\n/**\n * Default field to be used on referenced schema to lookup the value.\n */\nexport const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');\n\n/**\n * Generate test data.\n */\nexport const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');\n\nexport type GeneratorAnnotationValue =\n | string\n | {\n generator: string;\n args?: any[];\n probability?: number;\n };\n\nexport const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);\n\ninterface MakeAnnoationsProps<T> {\n id: string;\n schema: Schema.Schema<T, any, never>;\n}\n\n// Annotation ids use the same NSID / reverse-DNS format as TypenameSchema —\n// dot-separated segments, middle segments may be hyphenated, final segment may be camelCase.\n// At least 3 segments are required (e.g. org.dxos.annotation.example).\nexport const makeUserAnnotation = <T>(props: MakeAnnoationsProps<T>): Annotation.Annotation<T> => {\n assertArgument(\n /^[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(\n props.id,\n ),\n 'id',\n 'Annotation id must be in the FQN format (org.dxos.annotation.example or org.dxos.space.rootCollection).',\n );\n\n const annotation: Annotation.Annotation<T> = {\n [ANNOTATION_TYPE_ID]: { _Type: {} as T },\n key: props.id as Annotation.Key,\n schema: props.schema,\n get: (schema) => getFromAst(schema.ast, annotation),\n getFromAst: (ast) => getFromAst(ast, annotation),\n set: (value) =>\n PropertyMeta(props.id, Schema.encodeSync(props.schema)(value)) as <S extends Schema.Schema.Any>(schema: S) => S,\n };\n\n return annotation;\n};\n\nconst IconAnnotationSchema = Schema.Struct({\n /**\n * Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)\n */\n icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),\n\n /**\n * Color name.\n *\n * List of colors:\n * - 'red'\n * - 'orange'\n * - 'amber'\n * - 'yellow'\n * - 'lime'\n * - 'green'\n * - 'emerald'\n * - 'teal'\n * - 'cyan'\n * - 'violet'\n * - 'purple'\n * - 'fuchsia'\n * - 'pink'\n * - 'rose'\n */\n hue: Schema.optional(Schema.String),\n});\n\nexport interface IconAnnotation extends Schema.Schema.Type<typeof IconAnnotationSchema> {}\n\n/**\n * Icon to render in the UI.\n */\nexport const IconAnnotation = makeUserAnnotation<IconAnnotation>({\n id: 'org.dxos.annotation.icon',\n schema: IconAnnotationSchema,\n});\n\n/**\n * Indicates that this entity's icon should be resolved from a property whose value is a `Ref`\n * to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that\n * target's schema `IconAnnotation` in place of the static one declared on this schema.\n *\n * Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity\n * (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).\n */\nexport const IconFromRefAnnotation = makeUserAnnotation<string>({\n id: 'org.dxos.annotation.icon.from-ref',\n schema: Schema.String,\n});\n\n/**\n * Options for {@link getLabel}.\n */\nexport type GetLabelOptions = {\n /**\n * Strategy for deriving a label when the entity has no `LabelAnnotation` value.\n * - `'typename'`: use the entity's typename (e.g. `org.dxos.type.table`).\n * Useful for Card.Title chrome that must always display something, even\n * for unlabeled objects.\n */\n fallback?: 'typename';\n};\n\n/**\n * Get the label of an entity.\n * Accepts both reactive entities and snapshots.\n *\n * If `options.fallback === 'typename'` and no label is set, returns the\n * entity's typename instead.\n */\nexport const getLabel = (entity: AnyProperties, options?: GetLabelOptions): string | undefined => {\n const schema = getSchema(entity);\n const label = schema != null ? getLabelWithSchema(schema, entity) : undefined;\n if (label != null) {\n return label;\n }\n if (options?.fallback === 'typename') {\n return getTypename(entity);\n }\n return undefined;\n};\n\n/**\n * Set the label of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setLabel = (entity: Mutable<AnyProperties>, label: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setLabelWithSchema(schema, entity, label);\n }\n};\n\n/**\n * Get the description of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDescription = (entity: AnyProperties): string | undefined => {\n const schema = getSchema(entity);\n if (schema != null) {\n return getDescriptionWithSchema(schema, entity);\n }\n};\n\n/**\n * Get the icon annotation for an entity, resolved via its type-level `IconAnnotation`.\n * Accepts both reactive entities and snapshots.\n *\n * Returns the full `{ icon, hue }` annotation so callers can use both the phosphor icon\n * name and the suggested colour. Callers wanting just the icon name typically write\n * `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.\n *\n * Note: this is the \"static\" icon from the object's own schema. It does not follow\n * `IconFromRefAnnotation` delegation — call sites needing that (e.g. app-graph node\n * builders) should resolve the ref themselves.\n */\nexport const getIcon = (entity: AnyProperties): IconAnnotation | undefined => {\n const schema = getSchema(entity);\n if (schema == null) {\n return undefined;\n }\n return Option.getOrUndefined(IconAnnotation.get(schema));\n};\n\n/**\n * Set the description of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setDescription = (entity: Mutable<AnyProperties>, description: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setDescriptionWithSchema(schema, entity, description);\n }\n};\n\nexport { Dictionary, Key, getDictionary, setDictionary } from './dictionary';\n\nexport const getFromAst = <T>(ast: SchemaAST.AST, annotation: Annotation.Annotation<T>): Option.Option<T> => {\n return SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(\n Option.flatMap((meta) => Option.fromNullable(meta[annotation.key])),\n Option.map(Schema.decodeUnknownSync(annotation.schema)),\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(rename): These internal entity-wide symbols/types still use the `Object*` prefix but apply\n// to all entities (objects AND relations). Rename to `Entity*` in a follow-up pass (deferred from the\n// EchoURI→EID / ObjectId→EntityId / ObjectMeta→EntityMeta rename, which covered only public SDK API):\n// ObjectCore, ObjectInternals, ObjectVersion, ObjectVersionId, ObjectDeletedId, ObjectDatabaseId,\n// ObjectLoader, ObjectDocumentLoaded, ObjectUnavailable.\n// (ObjectMigration / ObjectMigrationContext intentionally excluded — object-only, not entity-wide.)\n\n/**\n * Internal symbol/string constants for the echo object model.\n * Defined in common/ so proxy/ can use them without importing from Entity/.\n * Entity/ re-exports these for external consumers.\n */\n\n/**\n * Property name for the object's own URI when serialized to JSON.\n */\nexport const ATTR_SELF_URI = '@uri';\n\n/**\n * @deprecated Legacy JSON property name accepted on read for backward compat.\n */\nexport const ATTR_SELF_URI_LEGACY = '@dxn';\n\n/**\n * Symbol carrying the object's own URI on live entities.\n */\nexport const SelfURIId = Symbol.for('@dxos/echo/URI');\n\n/**\n * Property name for deleted when object is serialized to JSON.\n */\nexport const ATTR_DELETED = '@deleted';\n\n/**\n * Deletion marker.\n */\nexport const ObjectDeletedId = Symbol.for('@dxos/echo/Deleted');\n\n/**\n * Object version accessor symbol.\n */\nexport const ObjectVersionId: unique symbol = Symbol.for('@dxos/echo/Version');\n\n/**\n * Object database accessor symbol.\n */\nexport const ObjectDatabaseId = Symbol.for('@dxos/echo/Database');\n\n/**\n * Property name for relation source when object is serialized to JSON.\n */\nexport const ATTR_RELATION_SOURCE = '@relationSource';\n\n/**\n * Used to access relation source ref on live ECHO objects.\n */\nexport const RelationSourceId: unique symbol = Symbol.for('@dxos/echo/RelationSource');\n\n/**\n * Used to access relation source DXN on live ECHO objects.\n */\nexport const RelationSourceDXNId: unique symbol = Symbol.for('@dxos/echo/RelationSourceDXN');\n\n/**\n * Property name for relation target when object is serialized to JSON.\n */\nexport const ATTR_RELATION_TARGET = '@relationTarget';\n\n/**\n * Used to access relation target ref on live ECHO objects.\n */\nexport const RelationTargetId: unique symbol = Symbol.for('@dxos/echo/RelationTarget');\n\n/**\n * Used to access relation target DXN on live ECHO objects.\n */\nexport const RelationTargetDXNId: unique symbol = Symbol.for('@dxos/echo/RelationTargetDXN');\n\n/**\n * Symbol carrying the entity metadata (EntityMeta) on live ECHO entities.\n * Must be importable by both meta.ts (which depends on the Ref schema) and\n * Entity/api.ts (which is transitively imported by the Ref schema), so it\n * cannot live in either of those files without creating an import cycle.\n */\nexport const MetaId = Symbol.for('@dxos/echo/Meta');\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\n/**\n * Property name for typename when object is serialized to JSON.\n */\nexport const ATTR_TYPE = '@type';\n\n/**\n * DXN to the object type.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Type');\n\n/**\n * Reference to the object schema.\n */\nexport const SchemaId = Symbol.for('@dxos/echo/Schema');\n\n/**\n * Property name for parent when object is serialized to JSON.\n */\nexport const ATTR_PARENT = '@parent';\n\n/**\n * Reference to the object parent.\n */\nexport const ParentId = Symbol.for('@dxos/echo/Parent');\n\n/**\n * Reference to the object's type entity (`Type.Obj`, `Type.Relation`, or\n * `Type.Type`). Set at instance creation by `createObject` / `makeObject`\n * when the entity is known. Public read-back via `Obj.getType` / `Relation.getType`\n * / `Entity.getType`.\n */\nexport const TypeEntityId = Symbol.for('@dxos/echo/TypeEntity');\n\n/**\n * Returns the Effect Schema for the given object if one is defined.\n *\n * @internal\n * Internal callers needing schema-side validation read from `SchemaId`.\n * Public callers should use `Type.getSchema(Obj.getType(obj))` instead.\n */\n// TODO(dmaretskyi): For echo objects, this always returns the root schema.\nexport const getSchema = (obj: unknown | undefined): Schema.Schema.AnyNoContext | undefined => {\n if (obj) {\n return (obj as any)[SchemaId];\n }\n};\n\n/**\n * @internal\n */\nexport const setSchema = (obj: any, schema: Schema.Schema.AnyNoContext): void => {\n Object.defineProperty(obj, SchemaId, {\n value: schema,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * Returns the type entity (`Type.AnyEntity`) for the given instance.\n * Set at instance creation; every entity has a type. Defensive: returns\n * undefined for null/undefined input so callers can safely probe arbitrary\n * values via this helper.\n *\n * @internal Re-exported via `Obj.getType` / `Relation.getType` / `Entity.getType`.\n */\nexport const getType = (obj: unknown): unknown => {\n if (obj == null) {\n return undefined;\n }\n return (obj as any)[TypeEntityId];\n};\n\n/**\n * @internal\n */\nexport const setType = (obj: any, type: unknown): void => {\n Object.defineProperty(obj, TypeEntityId, {\n value: type,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n};\n", "//\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';\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: Key, value: 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 2025 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { DXN, EID, URI, type SpaceId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type { AnyEntity } from '../common/types';\nimport { MetaId } from '../common/types/model-symbols';\nimport { type InternalObjectProps, ObjectDatabaseId } from './model';\nimport { getObjectEchoUri } from './util';\n\n/**\n * Controls the URI form returned by `getUri` and the public `*.getURI` helpers.\n *\n * - `'named'` — Registry key URI (`dxn:<meta.key>`) when the entity has a key in its meta;\n * falls back to the default EID.\n * - `'absolute'` — Fully-qualified EID with space id (`echo://<spaceId>/<entityId>`);\n * falls back when no space is available.\n * - `'relative'` — Local EID without space id (`echo:/<entityId>`).\n *\n * Omitting `prefer` preserves the existing behaviour.\n */\nexport type GetURIOptions = {\n prefer?: 'named' | 'absolute' | 'relative';\n};\n\n/**\n * Get the URI of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getUri = (entity: AnyEntity, options?: GetURIOptions): URI.URI => {\n const prefer = options?.prefer;\n\n if (prefer === 'named') {\n const key = (entity as any)[MetaId]?.key;\n if (key) {\n return (DXN.tryMake(`dxn:${key}`) ?? URI.make(key)) as URI.URI;\n }\n const uri = getObjectEchoUri(entity);\n invariant(uri != null, 'Invalid entity.');\n return uri;\n }\n\n if (prefer === 'relative') {\n const eid = getObjectEchoUri(entity);\n invariant(eid != null, 'Invalid entity.');\n const entityId = EID.getEntityId(eid);\n return entityId ? EID.make({ entityId }) : eid;\n }\n\n if (prefer === 'absolute') {\n const eid = getObjectEchoUri(entity);\n invariant(eid != null, 'Invalid entity.');\n const entityId = EID.getEntityId(eid);\n if (!entityId) {\n return eid;\n }\n assumeType<InternalObjectProps>(entity);\n const spaceId: SpaceId | undefined = entity[ObjectDatabaseId]?.spaceId ?? EID.getSpaceId(eid);\n return spaceId ? EID.make({ spaceId, entityId }) : eid;\n }\n\n const uri = getObjectEchoUri(entity);\n invariant(uri != null, 'Invalid entity.');\n return uri;\n};\n\n/**\n * Get the database the entity belongs to.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDatabase = (entity: AnyEntity): any | undefined => {\n assumeType<InternalObjectProps>(entity);\n return entity[ObjectDatabaseId];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\nimport { type ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { EID, EntityId, type URI } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from '../../Database';\nimport {\n type ATTR_PARENT,\n type ATTR_TYPE,\n ATTR_DELETED,\n ATTR_RELATION_SOURCE,\n ATTR_RELATION_TARGET,\n ATTR_SELF_URI,\n ATTR_SELF_URI_LEGACY,\n EntityKind,\n KindId,\n ObjectDatabaseId,\n ObjectDeletedId,\n ObjectVersionId,\n type ParentId,\n RelationSourceDXNId,\n RelationSourceId,\n RelationTargetDXNId,\n RelationTargetId,\n type SchemaId,\n SelfURIId,\n TypeId,\n type Version,\n} from '../common/types';\nimport { type ATTR_META, type EntityMeta } from '../common/types/meta';\nimport { type MetaId } from '../common/types/model-symbols';\n\nexport {\n ATTR_DELETED,\n ATTR_SELF_URI,\n ATTR_SELF_URI_LEGACY,\n ObjectDatabaseId,\n ObjectDeletedId,\n ObjectVersionId,\n SelfURIId,\n};\n\n/**\n * Internal runtime representation of an object.\n * The fields are accessed through getter functions.\n */\n// NOTE: Each symbol has a jsdoc describing its purpose.\nexport interface InternalObjectProps {\n readonly id: EntityId;\n readonly [SelfURIId]: EID.EID;\n readonly [KindId]: EntityKind;\n readonly [SchemaId]: Schema.Schema.AnyNoContext;\n readonly [TypeId]: URI.URI;\n readonly [MetaId]?: EntityMeta;\n [ParentId]?: InternalObjectProps;\n readonly [ObjectDatabaseId]?: Database.Database;\n readonly [ObjectDeletedId]?: boolean;\n readonly [ObjectVersionId]?: Version;\n readonly [RelationSourceDXNId]?: EID.EID;\n readonly [RelationTargetDXNId]?: EID.EID;\n readonly [RelationSourceId]?: InternalObjectProps;\n readonly [RelationTargetId]?: InternalObjectProps;\n}\n\n/**\n * Entity metadata.\n */\nexport interface EntityMetaJSON {\n keys: ForeignKey[];\n tags?: string[];\n key?: string;\n version?: string;\n}\n\n/**\n * JSON representation of an object or relation metadata.\n */\nexport interface ObjectJSON {\n id: EntityId;\n [ATTR_TYPE]?: URI.URI;\n [ATTR_SELF_URI]?: EID.EID;\n [ATTR_PARENT]?: EID.EID; // Encoded reference\n [ATTR_DELETED]?: boolean;\n [ATTR_META]?: EntityMetaJSON;\n [ATTR_RELATION_SOURCE]?: EID.EID;\n [ATTR_RELATION_TARGET]?: EID.EID;\n\n /**\n * Application-specific properties.\n */\n [key: string]: unknown;\n}\n\n/**\n * NOTE: Keep as `function` to avoid type inference issues.\n */\nexport function assertObjectModel(obj: unknown): asserts obj is InternalObjectProps {\n invariant(typeof obj === 'object' && obj !== null, 'Invalid object model: not an object');\n assumeType<InternalObjectProps>(obj);\n invariant(EntityId.isValid(obj.id), 'Invalid object model: invalid id');\n invariant(obj[TypeId] === undefined || typeof obj[TypeId] === 'string', 'Invalid object model: invalid type');\n invariant(\n obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation || obj[KindId] === EntityKind.Type,\n 'Invalid object model: invalid entity kind',\n );\n\n if (obj[KindId] === EntityKind.Relation) {\n invariant(EID.isEID(obj[RelationSourceDXNId]), 'Invalid object model: invalid relation source');\n invariant(EID.isEID(obj[RelationTargetDXNId]), 'Invalid object model: invalid relation target');\n invariant(!EID.isEID(obj[RelationSourceId]), 'Invalid object model: source pointer is a DXN');\n invariant(!EID.isEID(obj[RelationTargetId]), 'Invalid object model: target pointer is a DXN');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { EID, EntityId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport { type InternalObjectProps, SelfURIId } from './model';\n\n/**\n * Returns the EID of an object.\n *\n * @internal\n */\nexport const getObjectEchoUri = (object: any): EID.EID | undefined => {\n invariant(!Schema.isSchema(object), 'schema not allowed in this function');\n assertArgument(typeof object === 'object' && object != null, 'object', 'expected object');\n assumeType<InternalObjectProps>(object);\n\n if (object[SelfURIId]) {\n invariant(EID.isEID(object[SelfURIId]), 'Invalid object model: invalid self dxn');\n return EID.parse(object[SelfURIId]);\n }\n\n if (!EntityId.isValid(object.id)) {\n throw new TypeError('Object id is not valid.');\n }\n\n return EID.make({ entityId: object.id });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;;;;gBAAAA;EAAA;;;;;;;;;;;;;AAMA,YAAYC,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,gBAAgB;AAC5B,YAAYC,WAAW;AACvB,YAAYC,aAAY;AACxB,YAAYC,aAAY;AAExB,SAASC,gBAAgB;AACzB,SAASC,aAAAA,kBAAiB;;;ACV1B,YAAYC,aAAY;AAExB,SAASC,aAAa;AACtB,SAASC,kBAAAA,uBAAsB;AAC/B,SAASC,OAAAA,MAAKC,OAAAA,MAAKC,OAAAA,YAAW;;;ACJ9B,YAAYC,eAAc;AAC1B,YAAYC,aAAY;AACxB,YAAYC,aAAY;AACxB,YAAYC,eAAe;AAE3B,SAASC,gBAAgB;AACzB,SAASC,gBAAgBC,iBAAiB;AAC1C,SAASC,KAAKC,WAAW;;;ACSlB,IAAMC,gBAAgB;AAKtB,IAAMC,uBAAuB;AAK7B,IAAMC,YAAYC,uBAAOC,IAAI,gBAAA;AAK7B,IAAMC,eAAe;AAKrB,IAAMC,kBAAkBH,uBAAOC,IAAI,oBAAA;A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A,GAAA,yBAAA,EAAA,YAAA,YAAA,GAAAlB,eAAA,GAAA,IAAA,GAAA,MAAA,GAAA,CAAA,2CAAA,yBAAA,EAAA,CAAA;AAEvD,SAAA;;AAaSY,IAAQ,OAAA,UAAA,eAAA,EAAA,WAAA,KAAA;QACX,SAAO,OAAOI,SAAY,wBAAQG,MAAoBR,IAAIS,QAAG,CAAA;AAC/D,MAAA,CAAA,QAAA;AACA,WAAOR,OAAAA,YAAAA,IAAAA,oBAAAA,IAAAA,GAAAA,CAAAA;EAET;AAEF,SAAA;;;;;;AAgDS,IAAA,QAAA,CAAA,kBAAA,QAAA,KAAA,WAAA,CAAA,EAAA,GAAA,MAAA,GAAA,MAAA,aAAA,CAAA,GAAA,gBAAA,gBAAA,GAAA,qBAAA;4BACeS,CAAAA,QAAMC;SAC1BC;IAIA,KAAA,eAAmB,KAAA,CAAA,WAAA,SAAA,wBAAA,MAAA,OAAA,IAAA,CAAA,CAAA;IACnB,OAAcC,eAAAA,KAAAA,CAAAA,WAAe,SAAA,wBAAA,YAAA,qBAAA,MAAA,OAAA,iBAAA,CAAA,CAAA,CAAA;;OAEpBH;IACT,SAAA;AACF,aAAA;IACF;;;",
6
- "names": ["TypeId", "Context", "Effect", "Effectable", "Layer", "Option", "Schema", "EffectEx", "invariant", "Schema", "raise", "assertArgument", "DXN", "EID", "URI", "Function", "Option", "Schema", "SchemaAST", "SchemaEx", "assertArgument", "invariant", "DXN", "URI", "ATTR_SELF_URI", "ATTR_SELF_URI_LEGACY", "SelfURIId", "Symbol", "for", "ATTR_DELETED", "ObjectDeletedId", "ObjectVersionId", "ObjectDatabaseId", "ATTR_RELATION_SOURCE", "RelationSourceId", "RelationSourceDXNId", "ATTR_RELATION_TARGET", "RelationTargetId", "RelationTargetDXNId", "MetaId", "ATTR_TYPE", "TypeId", "Symbol", "for", "SchemaId", "ATTR_PARENT", "ParentId", "TypeEntityId", "getSchema", "obj", "setSchema", "schema", "Object", "defineProperty", "value", "writable", "enumerable", "configurable", "getType", "undefined", "setType", "type", "Function", "Option", "Schema", "Key", "String", "pipe", "brand", "Dictionary", "Record", "key", "value", "Unknown", "getDictionary", "values", "annotation", "none", "decodeUnknownSync", "schema", "some", "setDictionary", "encodeSync", "ANNOTATION_TYPE_ID", "id", "getTypeIdentifierAnnotation", "URI", "objectAnnotation", "typename", "undefined", "example", "TypeMeta", "version", "VersionSchema", "Function", "getAnnotation", "schema", "getSchemaTypename", "DXN", "type", "parsed", "Object", "defineProperty", "obj", "TypeId", "writable", "enumerable", "configurable", "invariant", "existingMeta", "self", "annotations", "PropertyMetaAnnotationId", "value", "assertArgument", "SchemaEx", "getField", "annotation", "label", "object", "accessor", "description", "key", "get", "getFromAst", "ast", "set", "PropertyMeta", "Schema", "encodeSync", "IconAnnotationSchema", "getLabelWithSchema", "options", "setLabelWithSchema", "entity", "getDescriptionWithSchema", "Option", "setDescriptionWithSchema", "invariant", "DXN", "EID", "URI", "assumeType", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "ATTR_DELETED", "assumeType", "obj", "invariant", "EntityId", "isValid", "__dxlog_file", "TypeId", "KindId", "EntityKind", "Type", "EID", "isEID", "RelationSourceDXNId", "RelationTargetDXNId", "Schema", "assertArgument", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "assertArgument", "object", "assumeType", "SelfURIId", "invariant", "EID", "EntityId", "isValid", "make", "__dxlog_file", "prefer", "key", "MetaId", "DXN", "tryMake", "uri", "getObjectEchoUri", "entity", "invariant", "eid", "entityId", "getEntityId", "make", "assumeType", "spaceId", "EID", "ObjectDatabaseId", "getTypeURIFromSpecifier", "input", "isSchema", "getSchemaURI", "raise", "TypeError", "KindId", "schema", "getStaticTypeSchema", "uri", "getUriFromEntity", "assertArgument", "EID", "isEID", "DXN", "isDXN", "isInstanceOf", "schemaOrType", "object", "schemaURI", "type", "TypeId", "URI", "isURI", "typename", "getTypename", "parsed", "tryMake", "getName", "__dxlog_file", "obj", "TypeId", "Database", "Schema", "Any", "space", "isDatabase", "db", "spaceId", "dxn", "ref", "object", "EffectEx", "context", "resolve", "Effect", "pipe", "withSpan", "EntityNotFoundError", "uri", "eff", "result", "first", "CommitPrototype"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/Entity.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport type { EntityId, URI } from '@dxos/keys';\n\nimport * as internal from './internal';\nimport * as objInternal from './internal/Obj';\nimport type * as Ref from './Ref';\nimport type * as Relation from './Relation';\nimport type * as Tag from './Tag';\nimport * as Type from './Type';\n\n// Re-export KindId and SnapshotKindId from internal.\nexport const KindId = internal.KindId;\nexport type KindId = typeof internal.KindId;\nexport const SnapshotKindId = internal.SnapshotKindId;\nexport type SnapshotKindId = typeof internal.SnapshotKindId;\n\n// NOTE: Relation does not extend Obj so that, for example, we can prevent Relations from being used as source and target objects.\n// However, we generally refer to Obj and Relation instances as \"objects\",\n// and many API methods accept both Obj.Unknown and Relation.Unknown (i.e., Entity.Unknown) instances.\n\nexport const Kind = internal.EntityKind;\nexport type Kind = internal.EntityKind;\nexport const KindSchema = internal.EntityKindSchema;\n\n/**\n * Assigns a kind to an Object or Relation instance.\n * NOTE: Needed to make `isRelation` and `isObject` checks work.\n */\nexport interface OfKind<K extends Kind> {\n readonly [KindId]: K;\n readonly id: EntityId;\n}\n\n/**\n * Assigns a snapshot kind to an Object or Relation snapshot.\n */\nexport interface SnapshotOfKind<K extends Kind> {\n readonly [SnapshotKindId]: K;\n readonly id: EntityId;\n}\n\n/**\n * Obj or Relation with a specific set of properties.\n */\nexport type Entity<Props> = OfKind<Kind> & Props;\n\n/**\n * Unknown Obj or Relation (reactive).\n */\nexport interface Unknown extends OfKind<Kind> {}\n\n/**\n * Effect Schema for any ECHO entity (object or relation).\n *\n * Kind-agnostic counterpart to `Obj.Unknown` / `Relation.Unknown` — validates\n * the structural shape (id + properties) without constraining `[KindId]`. Used\n * in operation input schemas that accept any entity flavour (e.g.\n * `Schema.Array(Entity.Unknown)`).\n *\n * The cast bridges the runtime structural schema to the branded `Unknown` type:\n * `[KindId]` is a symbol brand that can't be expressed in a runtime `Struct`,\n * so the entity guarantee is carried at the type level only (same approach as\n * `Obj.Unknown` / `Relation.Unknown`). Unlike those, this is kind-agnostic so it\n * isn't an `UnknownTypeSchema<_, K>` (there's no single `K`) and carries no\n * `TypeAnnotation`.\n */\nexport const Unknown: Schema.Schema<Unknown> = Schema.Struct({\n id: Schema.String,\n}).pipe(\n Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n) as unknown as Schema.Schema<Unknown>;\n\n/**\n * Snapshot of an Obj or Relation.\n * Branded with SnapshotKindId instead of KindId.\n */\nexport interface Snapshot extends SnapshotOfKind<Kind> {}\n\n/**\n * Object with arbitrary properties.\n *\n * NOTE: Due to how typescript works, this type is not assignable to a specific schema type.\n * In that case, use `Obj.instanceOf` to check if an object is of a specific type.\n *\n * This type is very permissive and allows accessing any property on the object.\n * We should move to Obj.Unknown that is not permissive and requires explicit instanceof checks..\n */\nexport interface Any extends OfKind<Kind> {\n [key: string]: unknown;\n}\n\n/**\n * Returns all properties of an object or relation except for the id and kind.\n */\nexport type Properties<T> = Omit<T, 'id' | KindId | Relation.Source | Relation.Target>;\n\n/**\n * Check if a value is an ECHO entity (object or relation).\n * Returns `false` for snapshots.\n */\nexport const isEntity: (value: unknown) => value is Unknown = internal.isEntity;\n\n/**\n * Test if a value is an instance of a given object or relation type.\n *\n * Kind-agnostic counterpart to `Obj.instanceOf` / `Relation.instanceOf` —\n * use this when the caller's input type is `Type.AnyObj | Type.AnyRelation`.\n *\n * @example\n * ```ts\n * // Caller doesn't know whether `type` is object- or relation-kind.\n * const matches = <T extends Type.AnyObj | Type.AnyRelation>(type: T, value: unknown) =>\n * Entity.instanceOf(type, value);\n * ```\n */\nexport const instanceOf: {\n <S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Type.InstanceType<S>;\n <S extends Type.AnyEntity>(schema: S, value: unknown): value is Type.InstanceType<S>;\n} = ((...args: [schema: Type.AnyEntity, value?: unknown]) => {\n if (args.length === 1) {\n return (entity: unknown) => internal.isInstanceOf(args[0], entity);\n }\n return internal.isInstanceOf(args[0], args[1]);\n}) as any;\n\n/**\n * Check if a value is an ECHO entity snapshot.\n * Returns `false` for entities.\n */\nexport const isSnapshot = (value: unknown): value is Snapshot => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[SnapshotKindId] !== undefined;\n};\n\n// TODO(dmaretskyi): Type introspection -- move to kind.\nexport const getKind = internal.getEntityKind;\n\n/**\n * Property that accesses metadata for an entity.\n */\nexport const Meta: unique symbol = internal.MetaId as any;\n\n/**\n * Property that accesses metadata for an entity.\n */\nexport type Meta = typeof Meta;\n\n//\n// Entity-level functions that work on any entity (object or relation).\n// Use these when you don't know or care about the specific entity kind.\n// For kind-specific functions, use Obj.* or Relation.*.\n//\n\n/**\n * JSON representation of an entity.\n */\nexport type JSON = internal.ObjectJSON;\n\n/**\n * Whether the entity is a type-kind entity (a `Type.Type` produced by\n * `Type.makeObject` / `Type.makeRelation`, or a persisted schema). Type entities\n * carry their identity (typename/version) on themselves rather than referencing a\n * separate type, so the accessors below route them through the `Type.*` module.\n */\nconst isTypeEntity = (entity: unknown): boolean => internal.getEntityKindBrand(entity) === internal.EntityKind.Type;\n\n/**\n * Any value the read accessors operate on: a reactive entity or a snapshot.\n * Type entities (`Type.AnyEntity`) are also accepted — they're first-class\n * entities, and `Unknown`'s kind-agnostic brand already subsumes them.\n */\nexport type AnyInput = Unknown | Snapshot;\n\n/**\n * Get the canonical URI of an entity (object, relation, or type). Returns `URI.URI` —\n * an `EID` for object/relation instances and persisted types, or a typename\n * `DXN` for static type entities; narrow with `EID.parse(uri)` or\n * `DXN.tryMake(uri)` at the point of use.\n *\n * @param options.prefer - Controls the URI form (see {@link internal.GetURIOptions}).\n */\nexport const getURI = (entity: AnyInput, options?: internal.GetURIOptions): URI.URI =>\n isTypeEntity(entity) ? Type.getURI(entity as Type.AnyEntity) : internal.getUri(entity as Unknown, options);\n\n/**\n * Get the DXN of an entity's type. For object/relation instances this is the URI\n * of the type they were created from; for a type entity it is the URI of the\n * meta-type ({@link Type.Type}, `dxn:org.dxos.type.schema:0.1.0`).\n */\nexport const getTypeURI = (entity: AnyInput): URI.URI | undefined =>\n isTypeEntity(entity) ? Type.getURI(Type.Type) : internal.getTypeURI(entity as Unknown);\n\n/**\n * Get the type entity (`Type.AnyEntity`) the instance was created from.\n *\n * Returns `undefined` when the entity's type isn't registered in this runtime\n * (e.g. a freshly deserialized snapshot whose type entity hasn't been wired\n * up yet, or an entity loaded from storage before its schema is known). To\n * get the Effect Schema from the returned entity, use `Type.getSchema(...)`.\n *\n * For a type entity, returns the meta-type {@link Type.Type} (a type entity's\n * type is \"Type\").\n */\nexport const getType = (entity: AnyInput): Type.AnyEntity | undefined =>\n isTypeEntity(entity) ? Type.Type : (internal.getType(entity) as Type.AnyEntity | undefined);\n\n/**\n * Get the typename of an entity's type. For object/relation instances this is the\n * typename of the type they were created from; for a type entity it is the type's\n * own typename (e.g. `com.example.type.person`).\n */\nexport const getTypename = (entity: AnyInput): string | undefined =>\n isTypeEntity(entity) ? Type.getTypename(entity as Type.AnyEntity) : internal.getTypename(entity as Unknown);\n\n/**\n * Get the database an entity belongs to.\n */\nexport const getDatabase = (entity: Unknown | Snapshot): any | undefined => internal.getDatabase(entity);\n\n/**\n * Get the metadata for an entity.\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(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\nexport function getMeta(entity: Mutable<Unknown>): internal.EntityMeta;\nexport function getMeta(entity: Unknown | Snapshot): internal.ReadonlyMeta;\nexport function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): internal.EntityMeta | internal.ReadonlyMeta {\n return internal.getMetaChecked(entity);\n}\n\n/**\n * Get foreign keys for an entity from the specified source.\n */\nexport const getKeys = (entity: Unknown | Snapshot, source: string): ForeignKey[] => internal.getKeys(entity, source);\n\n/**\n * Check if an entity is deleted.\n */\nexport const isDeleted = (entity: Unknown | Snapshot): boolean => internal.isDeleted(entity);\n\n/**\n * Get the label of an entity.\n *\n * @param options.fallback `'typename'` returns the entity's typename when no\n * label is set (e.g. `org.dxos.type.table`).\n */\nexport const getLabel = (entity: Unknown | Snapshot, options?: internal.GetLabelOptions): string | undefined =>\n internal.getLabel(entity, options);\n\n/**\n * Set the label of an entity.\n * Must be called within an `Entity.update` / `Obj.update` / `Relation.update` callback.\n */\nexport const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);\n\n/**\n * Get the description of an entity.\n */\nexport const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);\n\n/**\n * Get the icon annotation for an entity (object or relation), resolved via its type-level\n * `IconAnnotation`. Returns the full `{ icon, hue }` annotation so callers can use both\n * the phosphor icon name and the suggested colour.\n */\nexport const getIcon = (entity: Unknown | Snapshot): internal.IconAnnotation | undefined => internal.getIcon(entity);\n\n/**\n * Convert an entity to its JSON representation.\n */\nexport const toJSON = (entity: Unknown | Snapshot): JSON => internal.objectToJSON(entity);\n\n/**\n * Subscribe to changes on an entity (object or relation).\n * @returns Unsubscribe function.\n */\nexport const subscribe = (entity: Unknown, callback: () => void): (() => void) => {\n return internal.subscribe(entity, callback);\n};\n\n//\n// Change\n//\n\n/**\n * Used to provide a mutable view of an entity within `Entity.update`.\n */\nexport type Mutable<T> = internal.Mutable<T>;\n\n/**\n * Perform mutations on an entity (object or relation) within a change context.\n *\n * Entities are read-only by default. Mutations are batched and notifications fire\n * when the callback completes. Direct mutations outside of `Entity.update` will throw\n * at runtime.\n *\n * @param entity - The echo entity (object or relation) to mutate.\n * @param callback - Receives a mutable view of the entity. All mutations must occur here.\n *\n * @example\n * ```typescript\n * // Mutate within Entity.update\n * Entity.update(entity, (obj) => {\n * obj.name = 'Updated';\n * obj.count = 42;\n * });\n *\n * // Direct mutation throws\n * entity.name = 'Bob'; // Error: Cannot modify outside Entity.update()\n * ```\n *\n * Note: For type-specific operations, prefer `Obj.update` or `Relation.update`.\n */\nexport const update = <T extends Unknown>(entity: T, callback: internal.ChangeCallback<T>): void => {\n internal.change(entity, callback);\n};\n\n/**\n * Add a tag to an entity.\n * Must be called within an `Entity.update`, `Obj.update`, or `Relation.update` callback.\n */\nexport const addTag = (entity: Mutable<Unknown>, tag: Ref.Ref<Tag.Tag>): void => internal.addTag(entity, tag);\n\n/**\n * Remove a tag from an entity.\n * Must be called within an `Entity.update`, `Obj.update`, or `Relation.update` callback.\n */\nexport const removeTag = (entity: Mutable<Unknown>, tag: Ref.Ref<Tag.Tag>): void => internal.removeTag(entity, tag);\n\n//\n// Atoms\n//\n\nexport const atom = objInternal.makeEntity;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gBAAAA;EAAA;;wBAAAC;EAAA,eAAAC;EAAA,cAAAC;EAAA;qBAAAC;EAAA,sBAAAC;EAAA,eAAAC;EAAA,eAAAC;EAAA;kBAAAC;EAAA;iBAAAC;EAAA,kBAAAC;EAAA,mBAAAC;EAAA,cAAAC;EAAA;mBAAAC;EAAA,gBAAAC;EAAA;mBAAAC;EAAA,gBAAAC;EAAA,iBAAAC;EAAA;;;AAMA,YAAYC,YAAY;AAajB,IAAMC,UAAkBA;AAExB,IAAMC,kBAA0BA;AAOhC,IAAMC,OAAgBC;AAEtB,IAAMC,aAAsBC;AA4C5B,IAAMC,WAAyCC,cAAO;EAC3DC,IAAWC;AACb,CAAA,EAAGC,KACMC,cAAcC,cAAO;EAAEC,KAAYJ;EAAQK,OAAcR;AAAQ,CAAA,CAAA,CAAA;AA+BnE,IAAMS,YAA0DA;AAehE,IAAMC,aAGR,IAAIC,SAA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,MAAAA;AAOnG,IAAM2B,WAAU,CAAC3B,WAA6E2B,QAAQ3B,MAAAA;AAKtG,IAAM4B,SAAS,CAAC5B,WAA8C6B,aAAa7B,MAAAA;AAM3E,IAAM8B,aAAY,CAAC9B,QAAiB+B,aAAAA;AACzC,SAAgBD,UAAU9B,QAAQ+B,QAAAA;AACpC;AAmCO,IAAMC,SAAS,CAAoBhC,QAAW+B,aAAAA;AACnDE,EAASC,OAAOlC,QAAQ+B,QAAAA;AAC1B;AAMO,IAAMI,UAAS,CAACnC,QAA0BoC,QAAyCD,OAAOnC,QAAQoC,GAAAA;AAMlG,IAAMC,aAAY,CAACrC,QAA0BoC,QAAyCC,UAAUrC,QAAQoC,GAAAA;AAMxG,IAAME,OAAmBC;",
6
- "names": ["KindId", "SnapshotKindId", "Unknown", "addTag", "getDatabase", "getDescription", "getIcon", "getKeys", "getLabel", "getType", "getTypeURI", "getTypename", "getURI", "isDeleted", "isEntity", "removeTag", "setLabel", "subscribe", "Schema", "KindId", "SnapshotKindId", "Kind", "EntityKind", "KindSchema", "EntityKindSchema", "Unknown", "Struct", "id", "String", "pipe", "extend", "Record", "key", "value", "isEntity", "instanceOf", "args", "length", "entity", "isInstanceOf", "isSnapshot", "undefined", "getKind", "getEntityKind", "Meta", "MetaId", "isTypeEntity", "getEntityKindBrand", "Type", "getURI", "options", "getUri", "getTypeURI", "getType", "getTypename", "getDatabase", "getMeta", "getMetaChecked", "getKeys", "source", "isDeleted", "getLabel", "setLabel", "label", "getDescription", "getIcon", "toJSON", "objectToJSON", "subscribe", "callback", "update", "internal", "change", "addTag", "tag", "removeTag", "atom", "makeEntity"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/Type.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { raise } from '@dxos/debug';\nimport { type EncodedReference } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, type EntityId, type URI } from '@dxos/keys';\n\nimport type * as Database from './Database';\nimport type * as EntityModule from './Entity';\nimport * as internal from './internal';\nimport * as typeInternal from './internal/Type';\nimport type * as RelationModule from './Relation';\n\n//\n// Internal types (not exported)\n//\n\n/**\n * Structural base shared by the three sibling type-entity interfaces\n * ({@link Obj}, {@link Relation}, {@link Type}). NOT exported — callers\n * should constrain on {@link AnyEntity} when they want \"any of the three\"\n * and on the specific kind interface otherwise.\n */\ninterface BaseTypeEntity<A> {\n /**\n * Entity-kind brand of the type-entity value itself — always `EntityKind.Type`.\n * The kind of instance the type *describes* lives on `[SchemaKindId]`\n * (Object / Relation / Type). Lets `Obj.isObject` / `Relation.isRelation`\n * reject type entities by a single `[KindId]` check.\n */\n readonly [internal.KindId]: internal.EntityKind.Type;\n\n /**\n * Object id. Like all ECHO entities, type entities always carry an id —\n * stamped at construction for in-memory (static) declarations and assigned by\n * the database once persisted. The id does NOT determine the entity's URI:\n * static types resolve to their typename DXN, persisted types to `echo:/<id>`\n * (see `getTypeURIFromSpecifier`).\n */\n readonly id: EntityId;\n\n readonly name?: string;\n // NOTE: `typename` / `version` are intentionally NOT fields on any type-entity\n // interface. Both static and persisted entities carry them in `EntityMeta`\n // (`key` / `version`); read them via `Type.getTypename(self)` /\n // `Type.getVersion(self)` — never as a direct property.\n readonly jsonSchema: internal.JsonSchemaType;\n readonly [InstancePhantomId]?: A;\n}\n\n//\n// Obj — `Type.Type` value for an ECHO object schema.\n//\n\n/**\n * TypeScript type for an ECHO object type — a `Type.Type<A>` entity.\n *\n * `T` is the instance type produced by `Obj.make(Foo, props)`. `Fields` is\n * retained as a structural hint (the runtime value still carries `.fields`),\n * but consumers should derive instance/encoded types via `Type.InstanceType`.\n *\n * **Not a `Schema.Schema`.** `Foo.ast` / `Schema.Schema.Type<typeof Foo>` /\n * `Schema.extend(Foo)` no longer typecheck — extract the Effect Schema via\n * `Type.getSchema(Foo)` first, or derive instance types via\n * `Type.InstanceType<typeof Foo>`.\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));\n *\n * type Person = Type.InstanceType<typeof Person>;\n * ```\n */\nexport interface Obj<T, Fields extends Schema.Struct.Fields = Schema.Struct.Fields> extends BaseTypeEntity<\n T & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n> {\n /** Schema-kind brand (object). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Object;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Type that represents any ECHO object type — a `Type.Type` entity branded\n * with the object entity kind, i.e. what `Type.makeObject(dxn)` produces.\n */\nexport type AnyObj = Obj<unknown>;\n\n/**\n * Factory function to create an ECHO object type.\n *\n * Returns a `Type.Type` entity — a live, in-memory `TypeSchema` instance,\n * NOT a `Schema.Schema`. Use `Type.InstanceType<typeof Foo>` for the instance\n * type and `Type.getSchema(Foo)` to obtain the underlying Effect Schema.\n *\n * The entity's id defaults to `EntityId.deterministic(typename, version)` so\n * constructing a type never reaches `crypto.getRandomValues()` — required for\n * Cloudflare workerd, which forbids RNG calls in global (module-evaluation)\n * scope. Pass `{ id }` to override (e.g. with `EntityId.random()` from a\n * request handler).\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));\n * ```\n */\nexport const makeObject: {\n (\n dxn: DXN.DXN,\n options?: { id?: EntityId },\n ): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;\n} = internal.EchoObjectSchema as any;\n\n//\n// Type — the ECHO entity that holds a schema and metadata.\n// Persisted via `db.addType()`; subscribed to via `Filter.type(Type.Type)`.\n//\n\n/**\n * ECHO meta-schema entity — stores `{ name?, typename, version, jsonSchema }`.\n * Type-kind sibling of `Type.makeObject(...)` / `Type.makeRelation(...)` outputs.\n * Stored types live under this entity; filter via `Filter.type(Type.Type)`.\n */\nexport const Type: Type<typeInternal.TypeSchema> = typeInternal.TypeSchema as any;\n\n/**\n * Default version stamped on draft (unnamed) types created via\n * {@link makeObjectFromJsonSchema} / {@link makeRelationFromJsonSchema} when\n * the caller does not supply one. Pure dynamic drafts surface as `'0.0.0'`\n * until they are persisted, at which point automerge-heads suffix the version.\n */\nconst DRAFT_VERSION = '0.0.0';\n\n/**\n * Common props shared by the type-kind factories. Typename and version are\n * optional — drafts omit typename and default version to {@link DRAFT_VERSION}.\n */\ntype MakeTypeProps = {\n jsonSchema: internal.JsonSchemaType;\n typename?: string;\n version?: string;\n name?: string;\n id?: EntityId;\n};\n\n/**\n * Construct a new object-kind type entity from raw metadata — for cases where\n * an Effect Schema isn't available (e.g. JSON-Schema arriving over the network\n * or from a UI editor). Parallel to {@link makeObject} but takes pre-built\n * `jsonSchema` instead of piping through an Effect schema.\n *\n * The returned entity is in-memory; persist it with `db.addType(entity)`.\n */\nexport const makeObjectFromJsonSchema = (props: MakeTypeProps): Type<typeInternal.TypeSchema> => {\n const { typename, version, ...data } = props;\n // `typename` / `version` are routed through `EntityMeta` (`key` / `version`)\n // — the canonical registry-provenance pair — not data fields. Drafts default\n // to `'0.0.0'`; the version is omitted from meta entirely when the caller\n // doesn't supply one so the proxy projection can apply its own default.\n return internal.makeObject(\n internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,\n data as any,\n {\n keys: [],\n key: typename,\n version: version ?? DRAFT_VERSION,\n },\n typeInternal.TypeSchema,\n ) as unknown as Type<typeInternal.TypeSchema>;\n};\n\n/**\n * Construct a new relation-kind type entity from raw metadata. Parallel to\n * {@link makeRelation} but takes pre-built `jsonSchema` instead of piping\n * through an Effect schema. `source` / `target` accept either a static\n * `Type.Obj` entity or the well-known `Obj.Unknown` schema.\n *\n * The returned entity is in-memory; persist it with `db.addType(entity)`.\n */\nexport const makeRelationFromJsonSchema = (\n props: MakeTypeProps & {\n source: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;\n target: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;\n },\n): Type<typeInternal.TypeSchema> => {\n const { source, target, jsonSchema, typename, version, ...rest } = props;\n // Embed source/target DXNs + relation entity-kind into the jsonSchema so the\n // entity round-trips correctly through `toEffectSchema` / queries / refs.\n const sourceURI = internal.getTypeURIFromSpecifier(source);\n const targetURI = internal.getTypeURIFromSpecifier(target);\n const enrichedJsonSchema: internal.JsonSchemaType = {\n ...jsonSchema,\n entityKind: internal.EntityKind.Relation,\n relationSource: { $ref: sourceURI },\n relationTarget: { $ref: targetURI },\n };\n // `typename` / `version` route through `EntityMeta` (see\n // {@link makeObjectFromJsonSchema}); drafts default version to `'0.0.0'`.\n return internal.makeObject(\n internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,\n { ...rest, jsonSchema: enrichedJsonSchema } as any,\n {\n keys: [],\n key: typename,\n version: version ?? DRAFT_VERSION,\n },\n typeInternal.TypeSchema,\n ) as unknown as Type<typeInternal.TypeSchema>;\n};\n\n/**\n * TypeScript type for an ECHO relation type — a `Type.Type<A>` entity.\n *\n * `T` is the instance-property type produced by `Relation.make(...)` (excluding\n * source/target endpoints). `Source` and `Target` are the endpoint types.\n *\n * **Not a `Schema.Schema`.** See {@link Obj}'s note.\n */\nexport interface Relation<\n T,\n Source,\n Target,\n Fields extends Schema.Struct.Fields = Schema.Struct.Fields,\n> extends BaseTypeEntity<\n RelationModule.Endpoints<Source, Target> & T & EntityModule.OfKind<typeof EntityModule.Kind.Relation>\n> {\n /** Schema-kind brand (relation). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Relation;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Type that represents any ECHO relation type — a `Type.Type` entity branded\n * with the relation entity kind, i.e. what `Type.makeRelation(...)` produces.\n */\nexport type AnyRelation = Relation<unknown, unknown, unknown>;\n\n/**\n * Factory function to create an ECHO relation schema.\n * Adds relation metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const WorksFor = Schema.Struct({\n * role: Schema.String,\n * }).pipe(Type.makeRelation({\n * dxn: DXN.make('com.example.type.worksFor', '0.1.0'),\n * source: Person,\n * target: Company,\n * }));\n * ```\n */\nexport const makeRelation: {\n <SourceInstance, TargetInstance>(opts: {\n dxn: DXN.DXN;\n source: Obj<SourceInstance, any> | internal.UnknownTypeSchema<SourceInstance, typeof EntityModule.Kind.Object>;\n target: Obj<TargetInstance, any> | internal.UnknownTypeSchema<TargetInstance, typeof EntityModule.Kind.Object>;\n /**\n * Override the entity id. Defaults to `EntityId.deterministic(typename, version)`;\n * see `Type.makeObject` for the workerd motivation.\n */\n id?: EntityId;\n }): <Self extends Schema.Schema.Any>(\n self: Self,\n ) => Relation<\n Schema.Schema.Type<Self>,\n SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,\n TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n >;\n} = internal.EchoRelationSchema as any;\n\n/**\n * Type that represents any ECHO type-kind entity — a `Type.Type` meta-schema\n * value (static `Type.Type` or a persisted draft from `db.addType(...)`).\n * Mirrors {@link AnyObj} / {@link AnyRelation} for the third sibling kind.\n */\nexport type AnyType = Type<unknown>;\n\n/**\n * Any ECHO type-entity — one of the three sibling kinds: object-kind, relation-kind,\n * or type-kind (the meta-schema). APIs that want \"any ECHO type\" use this union;\n * the underlying Effect Schema is retrieved via `Type.getSchema`.\n */\nexport type AnyEntity = AnyObj | AnyRelation | AnyType;\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to an object-kind entity. Checks\n * ENTITIES, not instances — use `Obj.isObject` for instances. Raw\n * `Schema.Schema` values (including the branded `Obj.Unknown` companion)\n * are intentionally not accepted; inspect their `TypeAnnotation` directly.\n */\nexport const isObject = (entity: AnyEntity): entity is AnyObj => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Object;\n};\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to a relation-kind entity. Checks\n * ENTITIES, not instances — use `Relation.isRelation` for instances.\n */\nexport const isRelation = (entity: AnyEntity): entity is AnyRelation => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Relation;\n};\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to the type-kind meta-schema\n * (e.g. `Type.Type`). Mirrors {@link isObject} / {@link isRelation}.\n */\nexport const isTypeKind = (entity: AnyEntity): entity is Type => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Type;\n};\n\n/**\n * Narrow a `Type.AnyEntity` (e.g. one returned from `schemaRegistry.query(...)`)\n * to `AnyObj`, throwing if it describes a relation or the type-kind\n * meta-schema. Use at call sites that need to pass the value to `Obj.make`,\n * `Filter.type`, or other object-only APIs.\n */\nexport const assertObject = (entity: AnyEntity): AnyObj => {\n assertArgument(isObject(entity), 'entity', 'Expected an object-kind Type entity.');\n return entity;\n};\n\n/** Narrow a `Type.AnyEntity` to `AnyRelation`, throwing otherwise. */\nexport const expectRelation = (entity: AnyEntity): AnyRelation => {\n assertArgument(isRelation(entity), 'entity', 'Expected a relation-kind Type entity.');\n return entity;\n};\n\n/** Narrow a `Type.AnyEntity` to the `Type.Type` meta-schema, throwing otherwise. */\nexport const expectTypeKind = (entity: AnyEntity): Type => {\n assertArgument(isTypeKind(entity), 'entity', 'Expected a type-kind Type entity.');\n return entity;\n};\n\n/**\n * Type that represents any Ref schema (with unknown target type).\n * This is a schema type, not an instance type.\n */\nexport type AnyRef = Schema.Schema<internal.Ref<any>, EncodedReference>;\n\n//\n// Schema utility functions\n//\n\n/**\n * Returns the URI identifying a type entity. Always defined.\n *\n * - Static `Type.Obj` / `Type.Relation` → typename DXN (e.g. `dxn:com.example.type.person:0.1.0`).\n * - Persisted `Type.Type` instance (has `id`) → local `EID` (`echo:/<objectId>`).\n * - In-memory `Type.Type` draft (has `id`, no typename) → local `EID`.\n *\n * Only accepts `Type.AnyEntity` entities. Raw `Schema.Schema` values and the\n * branded `Obj.Unknown` / `Relation.Unknown` schemas are intentionally not\n * supported — use `internal.getSchemaURI` or the schema's typename annotation\n * directly when working at the schema level.\n */\nexport const getURI = (input: AnyEntity): URI.URI => {\n // For Type entities, route through `getTypeURIFromSpecifier` (id → EID,\n // typename/version → DXN). For Obj/Relation entities, unwrap to the source\n // Effect Schema first and read its annotations.\n if (isType(input)) {\n return internal.getTypeURIFromSpecifier(input);\n }\n return internal.getSchemaURI(getSchema(input)) ?? raise(new TypeError('Type entity has no URI'));\n};\n\n/**\n * @returns The typename. Example: `com.example.type.person`.\n *\n * Persisted `Type.Type` entities carry typename in `EntityMeta.key` (the\n * canonical registry-provenance field); unnamed drafts fall back to the\n * entity's object id so the helper always returns a string. Any `dxn:` or\n * `echo:/` prefix is stripped — typename is a bare identifier, not a URI.\n */\n// TODO(wittjosiah): For in-database types this should return the object id once the registry\n// has more robust options for shadowing types (so callers can disambiguate db-stored copies).\nexport const getTypename = (input: AnyEntity): string => {\n // Both in-memory and in-database entities carry typename in `EntityMeta.key`\n // — the canonical registry-provenance field. In-memory entities attach meta\n // eagerly (see `makeEchoTypeSchema`), so a single meta-backed read covers\n // both forms.\n const meta = internal.getMetaChecked(input);\n let typename: string | undefined = meta.key as string | undefined;\n // `meta.key` is a denormalized copy of the typename. The authoritative source\n // for a type entity is its `jsonSchema.typename` (`getSchema` rebuilds the\n // Effect Schema from `jsonSchema`). A type loaded from a snapshot can arrive\n // with `meta.key` absent (the meta round-trip dropped the denormalized copy)\n // while `jsonSchema.typename` is always present — consult it before the\n // last-resort id fallback so callers never receive a bare object id where a\n // typename is expected (e.g. `Filter.typename`, which rejects non-typenames).\n if (typename == null) {\n typename = input.jsonSchema?.typename;\n }\n // Unnamed drafts (no meta.key, no jsonSchema typename) fall back to the id.\n typename ??= input.id as string;\n // Typename is a bare identifier — strip URI prefixes if a caller seeded\n // meta.key with one accidentally (or if a static entity carries a DXN-\n // style typename).\n typename = stripTypenamePrefix(typename);\n invariant(typeof typename === 'string' && typename.length > 0, 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version.\n * @example 0.1.0\n * @example 0.1.0-<heads> (in-database, versioned by automerge heads)\n *\n * The registry-provenance semver lives in `EntityMeta.version`; unversioned\n * drafts default to {@link DRAFT_VERSION} (`'0.0.0'`). In-database entities are\n * additionally versioned by their automerge heads, which are exposed as the\n * semver pre-release tag (`<semver>-<heads>`). In-memory declarations have no\n * heads and surface the bare semver. Read the registry semver alone via\n * `Type.getMeta(input).version`.\n */\nexport const getVersion = (input: AnyEntity): string => {\n const meta = internal.getMetaChecked(input);\n // As with `getTypename`: `meta.version` is a denormalized copy; the\n // authoritative semver lives in `jsonSchema.version`. Prefer meta, fall back\n // to jsonSchema (always present on persisted types, survives serialization),\n // then to `DRAFT_VERSION` for unversioned drafts.\n const semver = (meta.version as string | undefined) ?? input.jsonSchema?.version ?? DRAFT_VERSION;\n invariant(typeof semver === 'string' && semver.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n // In-database entities are versioned by their automerge heads; expose them as\n // the semver pre-release tag. In-memory drafts carry no heads → bare semver.\n const heads = internal.version(input).automergeHeads;\n if (heads != null && heads.length > 0) {\n return `${semver}-${[...heads].sort().join('.')}`;\n }\n return semver;\n};\n\n/**\n * Strip URI prefixes (`dxn:`, `echo:/`, `echo://`) from a typename string.\n * Typename is a bare identifier — callers reading from meta or from a\n * caller-supplied seed value shouldn't propagate URI prefixes downstream.\n */\nconst stripTypenamePrefix = (value: string): string => {\n if (value.startsWith('dxn:')) {\n return value.slice('dxn:'.length);\n }\n if (value.startsWith('echo://')) {\n return value.slice('echo://'.length);\n }\n if (value.startsWith('echo:/')) {\n return value.slice('echo:/'.length);\n }\n return value;\n};\n\n/**\n * Type predicate: true iff the value is any type-kind ECHO entity — a static\n * `Type.Obj` / `Type.Relation` produced by `Type.makeObject` / `Type.makeRelation`, a\n * static meta `Type.Type`, or a persisted `Type.Type` returned by the database.\n *\n * All three branches stamp `[KindId] = Type`, so this is a single brand check.\n * Use {@link isObject} / {@link isRelation} / {@link isTypeKind}\n * when you need to discriminate further; use {@link getDatabase} when you mean\n * \"is this a db-attached type\" (vs. an in-memory declaration).\n */\nexport const isType = (value: unknown): value is AnyEntity =>\n internal.getEntityKindBrand(value) === internal.EntityKind.Type;\n\n/**\n * Get the database the type entity belongs to, or `undefined` if it is an\n * in-memory declaration (`Type.makeObject` / `Type.makeRelation` result) not\n * yet attached to a database. Mirrors `Obj.getDatabase` / `Relation.getDatabase`.\n *\n * Database attachment is the canonical discriminator between in-memory and\n * in-database type entities — both are live reactive `TypeSchema` instances and\n * are otherwise indistinguishable.\n */\nexport const getDatabase = (input: AnyEntity): Database.Database | undefined => internal.getDatabase(input);\n\n/**\n * Mutable meta type returned by `Type.getMeta` inside a `Type.update` callback.\n * Mirrors `Obj.Meta` / `Relation.Meta` — `Type.Type` is an Entity like its\n * siblings, so its meta is the same `EntityMeta` record:\n * `{ keys, tags?, key?, version? }`.\n *\n * `key` / `version` here are the canonical registry-provenance pair\n * (typename + semver) on persisted Type.Type entities; they are absent on\n * unnamed drafts. Use {@link getTypename} / {@link getVersion} when you want\n * a non-`undefined` value with id / {@link DRAFT_VERSION} fallbacks.\n */\nexport type Meta = internal.Meta;\n\n/**\n * Deeply read-only version of {@link Meta}.\n * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TS error).\n */\nexport type ReadonlyMeta = internal.ReadonlyMeta;\n\n/**\n * Returns the entity's `EntityMeta`. Same semantics as `Obj.getMeta` /\n * `Relation.getMeta` — `Type.Type` is an Entity and carries the canonical\n * `EntityMeta` directly. Returns mutable meta when passed a mutable type\n * (inside a `Type.update` callback), read-only meta otherwise.\n *\n * For persisted Type entities, `meta.key` holds the typename and\n * `meta.version` holds the semver. Use {@link getTypename} / {@link getVersion}\n * if you want the helpers' id / {@link DRAFT_VERSION} fallbacks for drafts.\n *\n * Both persisted and in-memory type entities (`Type.makeObject` /\n * `Type.makeRelation` results) carry their `EntityMeta` via `[MetaId]`, so the\n * lookup is uniform.\n */\nexport function getMeta(entity: internal.Mutable<AnyEntity>): Meta;\nexport function getMeta(entity: Mutable): Meta;\nexport function getMeta(entity: AnyEntity): ReadonlyMeta;\nexport function getMeta(entity: AnyEntity | internal.Mutable<AnyEntity> | Mutable): ReadonlyMeta | Meta {\n // The `Mutable` overload accepts the narrowed view passed to `Type.update`\n // callbacks; at runtime that draft IS the underlying persisted Type entity,\n // so the same `MetaId` lookup works.\n assertArgument(isType(entity), 'entity', 'Expected a Type entity.');\n // Both persisted and in-memory type entities carry runtime `EntityMeta` via\n // `[MetaId]`, so the lookup is uniform.\n return internal.getMetaChecked(entity);\n}\n\n/**\n * Get the display label of a type entity.\n * Reads the field(s) nominated by the type's {@link LabelAnnotation} (e.g. `name` on persisted schemas).\n * Returns `undefined` if no label field is populated.\n */\nexport const getLabel = (entity: AnyEntity, options?: internal.GetLabelOptions): string | undefined =>\n internal.getLabel(entity, options);\n\n/**\n * String key used to phantom-carry the instance type produced by a `Type.Type`.\n * Used by `Type.InstanceType<typeof Foo>` to recover the schema instance type\n * since `Type.makeObject(dxn)` does not return a `Schema.Schema`.\n *\n * Re-exported from the internal types layer so both `Type.ts` and internal\n * helpers (`makeObject`, `createObject`) reference the same phantom key.\n */\nexport const InstancePhantomId = internal.InstancePhantomId;\nexport type InstancePhantomId = internal.InstancePhantomId;\n\n/**\n * Sibling of {@link Obj} / {@link Relation} for the third ECHO entity kind:\n * **type-kind** entities (meta-schemas). The singleton {@link Type} const is\n * the canonical example — it describes stored type definitions themselves.\n *\n * Not a `Schema.Schema`. Use `Type.getSchema(value)` to obtain the underlying\n * Effect Schema and `Type.update(value, draft => ...)` to mutate.\n *\n * `A` is the instance-type phantom — what `Obj.make(value, ...)` would produce.\n * Merged with the `Type` const value via TypeScript declaration merging.\n */\nexport interface Type<A = unknown> extends BaseTypeEntity<A & EntityModule.OfKind<typeof EntityModule.Kind.Type>> {\n /** Schema-kind brand (type — the meta-schema kind). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Type;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n}\n\n/**\n * Instance type produced by a Type entity.\n *\n * Accepts ONLY {@link AnyEntity} inputs — `Type.Obj`, `Type.Relation`, or\n * `Type.Type`. Raw Effect `Schema.Schema` values are rejected: for those, use\n * `Schema.Schema.Type<typeof Foo>` directly. This separation keeps the type\n * system honest about which values represent ECHO entities versus plain\n * Effect schemas.\n *\n * Dispatches on the entity kind:\n * - `Relation<Props, S, T>` → `Endpoints<S,T> & Props & OfKind<Relation>`\n * - `Obj<A>` → `A & OfKind<Object>`\n * - `Type<A>` → `A & OfKind<Type>`\n */\nexport type InstanceType<T extends AnyEntity> =\n T extends Relation<infer Props, infer Source, infer Target, any>\n ? RelationModule.Endpoints<Source, Target> & Props & EntityModule.OfKind<typeof EntityModule.Kind.Relation>\n : T extends Obj<infer A, any>\n ? A & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n : T extends Type<infer A>\n ? A & EntityModule.OfKind<typeof EntityModule.Kind.Type>\n : never;\n\n/**\n * Returns the Effect Schema for a type entity.\n *\n * - For static `Type.Obj` / `Type.Relation` entities the source Effect Schema is\n * read from a hidden slot — these overloads preserve the instance type.\n * - For `Type.Type` entities (the meta-schema kind) the schema is rebuilt from\n * `type.jsonSchema`; the instance type isn't statically knowable so the wide\n * `AnyEntity` overload widens to `Schema.Schema.AnyNoContext`.\n *\n * Always call this when you need to interact with the Effect Schema API\n * (e.g. before passing to Effect.Schema functions). For ECHO-side APIs\n * (`Obj.make`, `Filter.type`, `Ref`) pass the type entity directly.\n *\n * Only accepts `Type.AnyEntity` — raw `Schema.Schema` values can be used\n * directly without unwrapping.\n */\nexport function getSchema<T extends AnyObj>(type: T): Schema.Schema<InstanceType<T>>;\nexport function getSchema<T extends AnyRelation>(type: T): Schema.Schema<InstanceType<T>>;\nexport function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext;\nexport function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext {\n // Static `Type.Type` entities carry the source Effect Schema on a hidden\n // slot so we can return it without round-tripping through JsonSchema.\n const staticSchema = internal.getStaticTypeSchema(type);\n if (staticSchema != null) {\n return staticSchema;\n }\n assertArgument(isType(type), 'type', 'Expected a Type entity.');\n // Persisted `Type.Type` entity — build the Effect Schema from its stored\n // jsonSchema and re-attach the TypeIdentifierAnnotation so the rebuilt\n // schema's URI (via getSchemaURI) matches the entity's local EID.\n const rebuilt = internal.toEffectSchema(type.jsonSchema);\n if (typeof type.id === 'string') {\n return rebuilt.annotations({\n [internal.TypeIdentifierAnnotationId]: EID.make({ entityId: type.id }),\n });\n }\n return rebuilt;\n}\n\n/**\n * Mutable view of a `Type.Type` — the shape passed to the `Type.update` callback.\n * Outside `Type.update`, `Type.Type` fields are read-only (both at the type level\n * and at runtime — direct assignment throws). Use this to constrain mutation to\n * the change context, analogous to `Obj.update(obj, (draft) => ...)`.\n *\n * NOTE: `typename` and `version` are intentionally absent — they live in\n * `EntityMeta` (`key` / `version` — the canonical registry-provenance pair).\n * Read them via {@link getTypename} / {@link getVersion} / {@link getMeta};\n * `typename` is treated as immutable on persisted entities.\n *\n * Unlike `Obj.update` — whose mutable view is inferred as `Mutable<A>` over the\n * whole instance type because every data field is editable — a `Type.Type`\n * exposes only `name` and `jsonSchema` for mutation. The rest of its shape\n * (`id`, the `[KindId]` / `[SchemaKindId]` brands, and `typename` / `version`\n * in meta) is immutable, so this view is declared explicitly rather than\n * derived from `InstanceType<Type.Type>`.\n */\nexport interface Mutable {\n name?: string;\n // Deep-mutable within the change context — `Type.update`'s purpose is to allow\n // mutation, so the draft exposes `jsonSchema` as writable (the readonly\n // `JsonSchemaType` would force callers to cast).\n jsonSchema: Types.DeepMutable<internal.JsonSchemaType>;\n}\n\n/**\n * Perform mutations on a `Type.Type` within a change context.\n *\n * The callback receives a {@link Mutable} view of the type — direct mutation of\n * a `Type.Type` outside `Type.update` throws at runtime, mirroring `Obj.update`.\n * Delegates to the same automerge-transaction primitive `Obj.update(obj, cb)` uses.\n */\nexport const update = (type: AnyEntity, callback: (mutable: Mutable) => void): void => {\n // `Type.Type` is an ECHO object; the change machinery is the same as `Obj.update`.\n internal.change(type, callback as internal.ChangeCallback<AnyEntity>);\n};\n\n//\n// Field-level helpers for mutating persisted types.\n// These are thin wrappers over `Type.update` plus the JsonSchema manipulation\n// utilities. Callers pass a persisted `Type.Type` (e.g. one returned by\n// `db.addType(schemaEntity)`) and the helper drives the change context.\n//\n\n/**\n * Add fields to a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const addFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {\n const extended = typeInternal.addFieldsToSchema(getSchema(type), fields);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(extended);\n });\n};\n\n/**\n * Replace existing fields on a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const updateFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {\n const updated = typeInternal.updateFieldsInSchema(getSchema(type), fields);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(updated);\n });\n};\n\n/**\n * Rename a field on a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const updateFieldPropertyName = (\n type: Type,\n { before, after }: { before: PropertyKey; after: PropertyKey },\n): void => {\n const renamed = typeInternal.updateFieldNameInSchema(getSchema(type), { before, after });\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(renamed);\n });\n};\n\n/**\n * Remove fields from a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const removeFields = (type: AnyEntity, fieldNames: string[]): void => {\n const removed = typeInternal.removeFieldsFromSchema(getSchema(type), fieldNames);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(removed);\n });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;2BAAAA;EAAA;;;;;qBAAAC;EAAA,gBAAAC;EAAA;;;;;;;;;oBAAAC;EAAA;;;;;;;;AASA,SAASC,aAAa;AAEtB,SAASC,gBAAgBC,iBAAiB;AAC1C,SAAcC,WAAoC;AA4FlD,IAAA,eAAA;AA4BA,IAAAC,cAAA;;;AAyCE,IAAA,2BAAA,CAAA,UAAA;AACA,QAAA,EAAA,UAAA,SAAAC,UAAA,GAAA,KAAA,IAAA;SAQSC,WAAAA,oBAAAA,UAAAA,GAAAA,MAAAA;IACLD,MAAAA,CAAAA;IAEFE,KAAAA;IAEF,SAAAF,YAAA;EAEF,GAAA,UAAA;;AAeE,IAAA,6BAAA,CAAA,UAAA;AACA,QAAA,EAAA,QAAA,QAAA,YAAA,UAAA,SAAAA,UAAA,GAAA,KAAA,IAAA;AAGA,QAAMG,YAA8C,wBAAA,MAAA;QAClD,YAAa,wBAAA,MAAA;QACbC,qBAAqBC;IACrBC,GAAAA;gBAAwBC,WAAAA;IAAU,gBAAA;MAClCC,MAAAA;;IAAkC,gBAAA;MACpC,MAAA;IACA;EACA;SAGyBL,WAAAA,oBAAAA,UAAAA,GAAAA;IACvB,GAAA;IACEM,YAAQ;;IAERT,MAAAA,CAAAA;IAEFE,KAAAA;IAEF,SAAAF,YAAA;EAqCF,GAAA,UAAA;;;AAwDE,IAAA,WAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAME,IAAA,aAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAME,IAAA,aAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAQSU,IAAAA,eAAAA,CAAAA,WAAAA;AACP,iBAAA,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ACtFC;;AAEA,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;EAEF,CAAA;;AAMSN,IAAM,eAACC,CAAAA,MAAAA,eAAAA;QACZA,UAAmBN,uBAAsBY,UAAAA,IAAAA,GAAAA,UAAAA;AAC3C,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;;;",
6
- "names": ["InstancePhantomId", "getDatabase", "getLabel", "makeObject", "raise", "assertArgument", "invariant", "EID", "makeObject", "version", "typename", "typeInternal", "enrichedJsonSchema", "entityKind", "EntityKind", "relationSource", "sourceURI", "relationTarget", "keys", "entity", "getSchemaURI", "input", "heads", "join", "semver", "value", "startsWith", "getDatabase", "InstancePhantomId", "staticSchema", "assertArgument", "annotations", "internal", "TypeIdentifierAnnotationId", "entityId", "change", "callback", "type", "draft", "extended", "updated", "before", "after", "update", "removed"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/internal/Format/types.ts", "../../../src/internal/Format/date.ts", "../../../src/internal/Format/number.ts", "../../../src/internal/Format/object.ts", "../../../src/internal/Format/string.ts", "../../../src/internal/Format/format.ts", "../../../src/internal/Format/select.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport type * as JSONSchema from 'effect/JSONSchema';\nimport * as Option from 'effect/Option';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { createAnnotationHelper } from '../Annotation/util';\nimport { type JsonSchemaType } from '../JsonSchema';\n\n// TODO(burdon): Rename PropertyType.\nexport type ScalarType =\n | JSONSchema.JsonSchema7Object\n | JSONSchema.JsonSchema7String\n | JSONSchema.JsonSchema7Number\n | JSONSchema.JsonSchema7Boolean\n | JSONSchema.JsonSchema7Ref;\n\n// TODO(burdon): Rename ValueType and change to disciminated union.\n// export type ValueType = 'array' | 'object' | 'string' | 'number' | 'boolean' | 'ref';\nexport enum TypeEnum {\n Array = 'array', // TODO(burdon): Remove?\n Object = 'object',\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Ref = 'ref',\n}\n\n// TODO(burdon): Ref?\nexport const getTypeEnum = (property: JsonSchemaType): TypeEnum | undefined => {\n switch (property.type) {\n case 'array':\n return TypeEnum.Array;\n case 'object':\n return TypeEnum.Object;\n case 'string':\n return TypeEnum.String;\n case 'number':\n return TypeEnum.Number;\n case 'boolean':\n return TypeEnum.Boolean;\n default:\n return undefined;\n }\n};\n\n/**\n * https://json-schema.org/understanding-json-schema/reference/schema\n * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats\n */\nexport const FormatAnnotationId = Symbol.for('@dxos/schema/annotation/Format');\n\nexport const FormatAnnotation = createAnnotationHelper<TypeFormat>(FormatAnnotationId);\n\n/** @deprecated */\nexport const getFormatAnnotation = (node: SchemaAST.AST): TypeFormat | undefined =>\n Function.pipe(SchemaAST.getAnnotation<TypeFormat>(FormatAnnotationId)(node), Option.getOrUndefined);\n\n// TODO(burdon): Rename Format; Change to discriminated union?\nexport enum TypeFormat {\n None = 'none',\n\n //\n // Scalar\n //\n\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Ref = 'ref',\n\n //\n // { type: 'string' }\n //\n\n DID = 'did', // Users, etc.\n DXN = 'dxn',\n Email = 'email',\n Formula = 'formula', // Spreadsheet formula.\n Hostname = 'hostname',\n JSON = 'json',\n Markdown = 'markdown',\n Regex = 'regex',\n SingleSelect = 'single-select',\n Text = 'text',\n MultiSelect = 'multi-select',\n URL = 'url',\n UUID = 'uuid',\n\n //\n // { type: 'number' }\n //\n\n Currency = 'currency',\n Integer = 'integer',\n Percent = 'percent',\n Timestamp = 'timestamp',\n\n //\n // { type: 'date' }\n //\n\n DateTime = 'date-time',\n Date = 'date',\n Time = 'time',\n Duration = 'duration',\n\n //\n // { type: 'object' }\n //\n\n GeoPoint = 'lnglat',\n}\n\nexport const FormatEnums = Object.values(TypeFormat).sort();\n\nexport const PropertyKind = {\n type: TypeEnum,\n format: TypeFormat,\n};\n\n/**\n * Default formats\n */\nexport const typeToFormat: Partial<Record<TypeEnum, TypeFormat>> = {\n [TypeEnum.String]: TypeFormat.String,\n [TypeEnum.Number]: TypeFormat.Number,\n [TypeEnum.Boolean]: TypeFormat.Boolean,\n};\n\n/**\n * Map of format to type.\n */\nexport const formatToType: Record<TypeFormat, TypeEnum> = {\n [TypeFormat.None]: TypeEnum.String,\n [TypeFormat.String]: TypeEnum.String,\n [TypeFormat.Number]: TypeEnum.Number,\n [TypeFormat.Boolean]: TypeEnum.Boolean,\n [TypeFormat.Ref]: TypeEnum.Ref,\n\n // Strings\n [TypeFormat.DID]: TypeEnum.String,\n [TypeFormat.DXN]: TypeEnum.String,\n [TypeFormat.Email]: TypeEnum.String,\n [TypeFormat.Formula]: TypeEnum.String,\n [TypeFormat.Hostname]: TypeEnum.String,\n [TypeFormat.JSON]: TypeEnum.String,\n [TypeFormat.Markdown]: TypeEnum.String,\n [TypeFormat.Regex]: TypeEnum.String,\n [TypeFormat.URL]: TypeEnum.String,\n [TypeFormat.UUID]: TypeEnum.String,\n [TypeFormat.SingleSelect]: TypeEnum.String,\n [TypeFormat.Text]: TypeEnum.String,\n [TypeFormat.MultiSelect]: TypeEnum.Object,\n\n // Dates\n [TypeFormat.Date]: TypeEnum.String,\n [TypeFormat.DateTime]: TypeEnum.String,\n [TypeFormat.Duration]: TypeEnum.String,\n [TypeFormat.Time]: TypeEnum.String,\n\n // Numbers\n [TypeFormat.Currency]: TypeEnum.Number,\n [TypeFormat.Integer]: TypeEnum.Number,\n [TypeFormat.Percent]: TypeEnum.Number,\n [TypeFormat.Timestamp]: TypeEnum.Number,\n\n // Objects\n [TypeFormat.GeoPoint]: TypeEnum.Array,\n};\n\n/**\n * Allowed value options for select.\n */\nexport const OptionsAnnotationId = Symbol.for('@dxos/schema/annotation/Options');\n\n// TODO(wittjosiah): Reconcile with `SelectOption`.\nexport type Options = string | number;\nexport const OptionsAnnotation = createAnnotationHelper<Options[]>(OptionsAnnotationId);\n\n/** @deprecated */\nexport const getOptionsAnnotation = (node: SchemaAST.AST): Options[] | undefined =>\n Function.pipe(SchemaAST.getAnnotation<Options[]>(OptionsAnnotationId)(node), Option.getOrUndefined);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\n/**\n * Datetime values should be stored as ISO strings or unix numbers (ms) in UTC.\n *\n * NOTE: HyperFormula uses Excel's time format (null date 1900/01/01)\n * It can be configured to use a different parser via `parseDateTime`.\n * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#date-and-time-handling\n * https://github.com/handsontable/hyperformula/blob/master/src/DateTimeHelper.ts\n */\n\n// TODO(burdon): Annotations not present in JSON.\n// TODO(burdon): Timezone.\n// TODO(burdon): Format for timestamp (Unix UTC or ISO 8601)?\n// TODO(burdon): Refs\n// - https://www.npmjs.com/package/numfmt\n// - https://date-fns.org/docs/Getting-Started\n// - https://github.com/date-fns/tz\n\n/**\n * Simple date compatible with HF.\n */\nexport const SimpleDate = Schema.Struct({\n year: Schema.Number.pipe(Schema.between(1900, 9999)),\n month: Schema.Number.pipe(Schema.between(1, 12)),\n day: Schema.Number.pipe(Schema.between(1, 31)),\n});\n\nexport type SimpleDate = Schema.Schema.Type<typeof SimpleDate>;\n\nexport const toSimpleDate = (date: Date): SimpleDate => ({\n year: date.getUTCFullYear(),\n month: date.getUTCMonth() + 1,\n day: date.getUTCDate(),\n});\n\n/**\n * Simple time compatible with HF.\n */\nexport const SimpleTime = Schema.Struct({\n hours: Schema.Number.pipe(Schema.between(0, 23)),\n minutes: Schema.Number.pipe(Schema.between(0, 59)),\n seconds: Schema.Number.pipe(Schema.between(0, 59)),\n});\n\nexport type SimpleTime = Schema.Schema.Type<typeof SimpleTime>;\n\nexport const toSimpleTime = (date: Date): SimpleTime => ({\n hours: date.getUTCHours(),\n minutes: date.getUTCSeconds(),\n seconds: date.getUTCSeconds(),\n});\n\n/**\n * Simple date-time compatible with HF.\n */\nexport const SimpleDateTime = Schema.extend(SimpleDate, SimpleTime);\n\nexport type SimpleDateTime = Schema.Schema.Type<typeof SimpleDateTime>;\n\nexport const toSimpleDateTime = (date: Date): SimpleDateTime => ({\n ...toSimpleDate(date),\n ...toSimpleTime(date),\n});\n\n/**\n * https://effect.website/docs/guides/schema/transformations#date-transformations\n */\n\n// TODO(burdon): Consider if transformations should be supported with Automerge.\n\n/**\n * Format: 2018-11-13\n */\nexport const DateOnly = /* Schema.transformOrFail(Schema.String, SimpleDate, {\n strict: true,\n decode: (str, _, ast) => {\n if (!isValidDateFormat(str)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected YYYY-MM-DD format'));\n }\n if (!isValidDate(str)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Invalid date'));\n }\n\n const [year, month, day] = str.split('-').map(Number);\n return ParseResult.succeed({ year, month, day });\n },\n encode: (date) => {\n return ParseResult.succeed(\n [\n date.year.toString().padStart(4, '0'),\n date.month.toString().padStart(2, '0'),\n date.day.toString().padStart(2, '0'),\n ].join('-'),\n );\n },\n}) */ Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.Date),\n Schema.annotations({\n description: 'Valid date in ISO format',\n }),\n);\n\n/**\n * Format: 20:20:39+00:00\n */\nexport const TimeOnly = /* Schema.transformOrFail(Schema.String, SimpleTime, {\n strict: true,\n decode: (str, _, ast) => {\n if (!isValidTimeFormat(str)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));\n }\n\n const [hours, minutes, seconds] = str.split(':').map(Number);\n return ParseResult.succeed({ hours, minutes, seconds });\n },\n encode: (time) => {\n return ParseResult.succeed(\n [\n time.hours.toString().padStart(2, '0'),\n time.minutes.toString().padStart(2, '0'),\n time.seconds.toString().padStart(2, '0'),\n ].join(':'),\n );\n },\n}) */ Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.Time),\n Schema.annotations({\n description: 'Valid time in ISO format',\n }),\n);\n\n/**\n * Format: 2018-11-13T20:20:39+00:00\n */\nexport const DateTime = /* Schema.transformOrFail(Schema.String, SimpleDateTime, {\n strict: false,\n decode: (str, _, ast) => {\n const [date, time] = str.split('T');\n if (!isValidDateFormat(date)) {\n return ParseResult.fail(new ParseResult.Type(ast, date, 'Expected YYYY-MM-DD format'));\n }\n if (!isValidDate(date)) {\n return ParseResult.fail(new ParseResult.Type(ast, date, 'Invalid date'));\n }\n if (!isValidTimeFormat(time)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));\n }\n\n const [year, month, day] = date.split('-').map(Number);\n const [hours, minutes, seconds] = time.split(':').map(Number);\n return ParseResult.succeed({ year, month, day, hours, minutes, seconds });\n },\n encode: (datetime) => {\n return ParseResult.succeed(\n [\n [\n datetime.year.toString().padStart(4, '0'),\n datetime.month.toString().padStart(2, '0'),\n datetime.day.toString().padStart(2, '0'),\n ].join('-'),\n [\n datetime.hours.toString().padStart(2, '0'),\n datetime.minutes.toString().padStart(2, '0'),\n datetime.seconds.toString().padStart(2, '0'),\n ].join(':'),\n ].join('T'),\n );\n },\n}) */ Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.DateTime),\n Schema.annotations({\n description: 'Valid date and time in ISO format',\n }),\n);\n\n/**\n * https://datatracker.ietf.org/doc/html/rfc3339#appendix-A\n */\n// TODO(burdon): Define duration type.\nexport const Duration = Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.Duration),\n Schema.annotations({\n description: 'Duration in ISO 8601 format',\n [SchemaAST.ExamplesAnnotationId]: ['1h', '3D'],\n }),\n);\n\n//\n// Utils\n//\n\n// YYYY-MM-DD\nconst DATE_REGEX = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nconst _isValidDateFormat = (str: string) => DATE_REGEX.test(str);\n\nconst _isValidDate = (str: string) => {\n const date = new Date(str);\n return !isNaN(date.getTime()) && date.toISOString().startsWith(str);\n};\n\n// HH:mm:ss\nconst TIME_REGEX = /^([01]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)$/;\n\nconst _isValidTimeFormat = (str: string) => TIME_REGEX.test(str);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\nconst encodeMultipleOf = (divisor: number) => 1 / Math.pow(10, divisor);\n\nconst encodeMultiple =\n <A extends number>(divisor?: number) =>\n <I, R>(self: Schema.Schema<A, I, R>) =>\n divisor === undefined || divisor === 0 ? self : self.pipe(Schema.multipleOf(encodeMultipleOf(divisor)));\n\n/**\n * Convert number of digits to multipleOf annotation.\n */\nexport const DecimalPrecision = Schema.transform(Schema.Number, Schema.Number, {\n strict: true,\n encode: (value) => encodeMultipleOf(value),\n decode: (value) => Math.log10(1 / value),\n}).annotations({\n title: 'Number of digits',\n});\n\nexport const CurrencyAnnotationId = Symbol.for('@dxos/schema/annotation/Currency');\n\nexport type CurrencyAnnotation = {\n decimals?: number;\n code?: string;\n};\n\n/**\n * ISO 4217 currency code.\n */\nexport const Currency = ({ decimals, code }: CurrencyAnnotation = { decimals: 2 }) =>\n Schema.Number.pipe(\n encodeMultiple(decimals),\n FormatAnnotation.set(TypeFormat.Currency),\n Schema.annotations({\n title: 'Currency',\n description: 'Currency value',\n ...(code ? { [CurrencyAnnotationId]: code.toUpperCase() } : {}),\n }),\n );\n\nexport type PercentAnnotation = {\n decimals?: number;\n};\n\n/**\n * Integer.\n */\nexport const Integer = () =>\n Schema.Number.pipe(\n Schema.int(),\n FormatAnnotation.set(TypeFormat.Integer),\n Schema.annotations({\n title: 'Integer',\n description: 'Integer value',\n }),\n );\n\n/**\n * Percent.\n */\n// TODO(burdon): Define min/max (e.g., 0, 1).\nexport const Percent = ({ decimals }: PercentAnnotation = { decimals: 2 }) =>\n Schema.Number.pipe(\n encodeMultiple(decimals),\n FormatAnnotation.set(TypeFormat.Percent),\n Schema.annotations({\n title: 'Percent',\n description: 'Percentage value',\n }),\n );\n\n/**\n * Unix timestamp.\n * https://en.wikipedia.org/wiki/Unix_time\n */\nexport const Timestamp = Schema.Number.pipe(\n FormatAnnotation.set(TypeFormat.Timestamp),\n Schema.annotations({\n title: 'Timestamp',\n description: 'Unix timestamp',\n }),\n);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { clamp } from '@dxos/util';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\n/**\n * GeoJSON Format\n * https://datatracker.ietf.org/doc/html/rfc7946\n * https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1\n * https://en.wikipedia.org/wiki/Geographic_coordinate_system\n * https://geojson.org\n * {\n * \"type\": \"Point\",\n * \"coordinates\": [0, 51.47] // [longitude, latitude]\n * }\n * Note: optional third element for altitude.\n */\n/** Decimal places retained for stored coordinates (~1.1cm at the equator). */\nexport const GEO_PRECISION = 7;\n\nconst roundCoordinate = (value: number): number => {\n const factor = 10 ** GEO_PRECISION;\n return Math.round(value * factor) / factor;\n};\n\n/** Longitude/latitude clamped to range and rounded to {@link GEO_PRECISION} decimal places. */\nconst Coordinate = (min: number, max: number, title: string) =>\n Schema.transform(Schema.Number.pipe(Schema.clamp(min, max)), Schema.Number, {\n strict: true,\n decode: roundCoordinate,\n encode: roundCoordinate,\n }).annotations({ title });\n\nexport const GeoPoint = Schema.Tuple(\n Coordinate(-180, 180, 'Longitude'),\n Coordinate(-90, 90, 'Latitude'),\n Schema.optionalElement(Schema.Number).annotations({\n title: 'Height ASL (m)',\n }),\n).pipe(\n FormatAnnotation.set(TypeFormat.GeoPoint),\n Schema.annotations({\n title: 'GeoPoint',\n description: 'GeoJSON Position',\n }),\n);\n\nexport type GeoPoint = Schema.Schema.Type<typeof GeoPoint>;\n\nexport type GeoLocation = {\n longitude: number;\n latitude: number;\n height?: number;\n};\n\n/**\n * Geolocation utilities for working with GeoPoint format.\n */\nexport namespace GeoLocation {\n /**\n * Convert latitude and longitude to GeoPoint (GeoJSON format [longitude, latitude, height?]).\n * Clamps values to valid ranges: latitude [-90, 90], longitude [-180, 180].\n */\n export const toGeoPoint = ({ longitude, latitude, height }: GeoLocation): GeoPoint => {\n // TODO(ZaymonFC): Use schema validation instead of doing this manually.\n // Clamp + round to match the `Format.GeoPoint` decode/encode path so both produce identical tuples.\n const clampedLongitude = roundCoordinate(clamp(longitude, -180, 180));\n const clampedLatitude = roundCoordinate(clamp(latitude, -90, 90));\n return height !== undefined ? [clampedLongitude, clampedLatitude, height] : [clampedLongitude, clampedLatitude];\n };\n\n /**\n * Extract latitude and longitude from GeoPoint (GeoJSON format [longitude, latitude, height?]).\n */\n export const fromGeoPoint = (geoPoint: GeoPoint | undefined): GeoLocation => {\n if (!geoPoint) {\n return { longitude: 0, latitude: 0 };\n }\n\n const result: GeoLocation = {\n longitude: geoPoint[0],\n latitude: geoPoint[1],\n };\n\n // Add height if defined.\n if (geoPoint[2] !== undefined) {\n result.height = geoPoint[2];\n }\n\n return result;\n };\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\n/**\n * Email address (RFC 5321)\n * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2\n */\nexport const Email = Schema.String.pipe(\n Schema.pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/),\n FormatAnnotation.set(TypeFormat.Email),\n Schema.annotations({\n title: 'Email',\n description: 'Email address',\n }),\n);\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const Formula = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Formula));\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const Hostname = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Hostname));\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const JSON = Schema.String.pipe(FormatAnnotation.set(TypeFormat.JSON));\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const Markdown = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Markdown));\n\n/**\n * Regex\n * https://json-schema.org/understanding-json-schema/reference/regular_expressions\n * https://ecma-international.org/publications-and-standards/standards/ecma-262\n */\n// TODO(burdon): Implement.\nexport const Regex = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex));\n\n/**\n * Multi-line text.\n */\nexport const Text = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Text));\n\n/**\n * https://datatracker.ietf.org/doc/html/rfc3986#section-1.1.3\n */\nexport const URL = Schema.String.pipe(\n Schema.pattern(/^(\\w+?:\\/\\/)?([\\da-z.-]+)\\.([a-z.]{2,6})([/\\w .-]*)*\\/?$/i),\n FormatAnnotation.set(TypeFormat.URL),\n Schema.annotations({\n title: 'URL',\n description: 'URL',\n }),\n);\n\n/**\n * UUID (RFC 4122)\n * https://datatracker.ietf.org/doc/html/rfc4122\n */\nexport const UUID = Schema.UUID.pipe(\n FormatAnnotation.set(TypeFormat.UUID),\n Schema.annotations({\n [SchemaAST.ExamplesAnnotationId]: ['3e4666bf-d5e5-4aa7-b8ce-cefe41c7568a'],\n }),\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport * as Keys from '@dxos/keys';\n\nimport * as DateUtil from './date';\nimport * as NumberUtil from './number';\nimport * as ObjectUtil from './object';\nimport * as StringUtil from './string';\nimport { TypeFormat as TypeFormat$ } from './types';\n\n// TODO(burdon): Media encoding.\n// - https://json-schema.org/understanding-json-schema/reference/non_json_data\n\n/**\n * Formats.\n * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats\n * NOTE: A JSON Schema validator will ignore any format type that it does not understand.\n */\n// TODO(burdon): Add fields for `examples`, `message`, etc.\nexport namespace Format {\n export import TypeFormat = TypeFormat$;\n\n // String\n export const DXN = Keys.DXN.Schema;\n export const Email = StringUtil.Email;\n export const Formula = StringUtil.Formula;\n export const Hostname = StringUtil.Hostname;\n export const JSON = StringUtil.JSON;\n export const Markdown = StringUtil.Markdown;\n export const Regex = StringUtil.Regex;\n export const URL = StringUtil.URL;\n export const UUID = Schema.UUID;\n\n // Numbers\n // TODO(burdon): BigInt.\n export const Currency = NumberUtil.Currency;\n export const Integer = NumberUtil.Integer;\n export const Percent = NumberUtil.Percent;\n export const Timestamp = NumberUtil.Timestamp;\n\n // Dates and times\n export const Date = DateUtil.DateOnly;\n export const DateTime = DateUtil.DateTime;\n export const Duration = DateUtil.Duration;\n export const Time = DateUtil.TimeOnly;\n\n // Objects\n export const GeoPoint = ObjectUtil.GeoPoint;\n export type GeoPoint = ObjectUtil.GeoPoint; // TODO(burdon): Export types.\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n/**\n * Schema for a single select option. Used to define choices in a {single|multi}-select field.\n */\nexport const SelectOption = Schema.Struct({\n /** Stable identifier for the option. */\n id: Schema.NonEmptyString,\n title: Schema.String,\n /** Color palette used for visual styling. */\n color: Schema.String,\n});\n\nexport type SelectOption = Schema.Schema.Type<typeof SelectOption>;\n"],
5
- "mappings": ";;;;;AAIA,YAAYA,cAAc;AAE1B,YAAYC,YAAY;AACxB,YAAYC,eAAe;AAepB,IAAKC,WAAAA,0BAAAA,WAAAA;;;;;;;SAAAA;;AAUL,IAAMC,cAAc,CAACC,aAAAA;AAC1B,UAAQA,SAASC,MAAI;IACnB,KAAK;AACH,aAAA;IACF,KAAK;AACH,aAAA;IACF,KAAK;AACH,aAAA;IACF,KAAK;AACH,aAAA;IACF,KAAK;AACH,aAAA;IACF;AACE,aAAOC;EACX;AACF;AAMO,IAAMC,qBAAqBC,uBAAOC,IAAI,gCAAA;AAEtC,IAAMC,mBAAmBC,uBAAmCJ,kBAAAA;AAG5D,IAAMK,sBAAsB,CAACC,SACzBC,cAAeC,wBAA0BR,kBAAAA,EAAoBM,IAAAA,GAAcG,qBAAc;AAG7F,IAAKC,aAAAA,0BAAAA,aAAAA;;;;;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WAAsBA;UACtBC,QAAmBA;UACnBC,MAAiBA;UACjBC,OAAcA;UAIdC,WAAsBA;UACtBC,UAAqBA;UACrBC,UAAqBA;UACrBC,YAAuBA;UAGvBC,OAAgBC;UAChBC,WAAoBA;UACpBC,WAAoBA;UACpBC,OAAgBC;UAGhBC,WAAsBA;AAErC,GA9BiBtB,WAAAA,SAAAA,CAAAA,EAAAA;;;;ACnBjB,YAAYuB,aAAY;AAKjB,IAAMC,eAAsBC,eAAO;;EAExCC,IAAWC;EACXC,OAAcC;;EAEdC,OAAcD;AAChB,CAAA;",
6
- "names": ["Function", "Option", "SchemaAST", "TypeEnum", "getTypeEnum", "property", "type", "undefined", "FormatAnnotationId", "Symbol", "for", "FormatAnnotation", "createAnnotationHelper", "getFormatAnnotation", "node", "pipe", "getAnnotation", "getOrUndefined", "TypeFormat", "FormatEnums", "Object", "values", "sort", "PropertyKind", "format", "typeToFormat", "formatToType", "OptionsAnnotationId", "OptionsAnnotation", "getOptionsAnnotation", "Schema", "SchemaAST", "SimpleDate", "Struct", "year", "Number", "pipe", "between", "month", "day", "toSimpleDate", "date", "getUTCFullYear", "getUTCMonth", "getUTCDate", "SimpleTime", "hours", "minutes", "seconds", "toSimpleTime", "getUTCHours", "getUTCSeconds", "SimpleDateTime", "extend", "toSimpleDateTime", "DateOnly", "String", "FormatAnnotation", "set", "TypeFormat", "Date", "annotations", "description", "TimeOnly", "Time", "DateTime", "Duration", "ExamplesAnnotationId", "Schema", "encodeMultipleOf", "divisor", "Math", "pow", "encodeMultiple", "self", "undefined", "pipe", "multipleOf", "DecimalPrecision", "transform", "Number", "strict", "encode", "value", "decode", "log10", "annotations", "title", "CurrencyAnnotationId", "Symbol", "for", "Currency", "decimals", "code", "FormatAnnotation", "set", "TypeFormat", "description", "toUpperCase", "Integer", "int", "Percent", "Timestamp", "Schema", "clamp", "GEO_PRECISION", "roundCoordinate", "value", "factor", "Math", "round", "Coordinate", "min", "max", "title", "transform", "Number", "pipe", "clamp", "strict", "decode", "encode", "annotations", "GeoPoint", "Tuple", "optionalElement", "FormatAnnotation", "set", "TypeFormat", "description", "GeoLocation", "toGeoPoint", "longitude", "latitude", "height", "clampedLongitude", "clampedLatitude", "undefined", "fromGeoPoint", "geoPoint", "result", "Schema", "SchemaAST", "Email", "String", "pipe", "pattern", "FormatAnnotation", "set", "TypeFormat", "annotations", "title", "description", "Formula", "Hostname", "JSON", "Markdown", "Regex", "Text", "URL", "UUID", "ExamplesAnnotationId", "Schema", "Keys", "Format", "TypeFormat", "DXN", "Schema", "Email", "Formula", "Hostname", "JSON", "Markdown", "Regex", "URL", "UUID", "Currency", "Integer", "Percent", "Timestamp", "Date", "DateOnly", "DateTime", "Duration", "Time", "TimeOnly", "GeoPoint", "Schema", "SelectOption", "Struct", "id", "NonEmptyString", "title", "String", "color"]
7
- }