@dxos/echo 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878

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 (602) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +9 -9
  3. package/dist/lib/neutral/Annotation.mjs +7 -3
  4. package/dist/lib/neutral/Database.mjs +8 -4
  5. package/dist/lib/neutral/Entity.mjs +35 -18
  6. package/dist/lib/neutral/Err.mjs +3 -1
  7. package/dist/lib/neutral/Extension.mjs +18 -0
  8. package/dist/lib/neutral/Extension.mjs.map +7 -0
  9. package/dist/lib/neutral/Feed.mjs +54 -0
  10. package/dist/lib/neutral/Feed.mjs.map +7 -0
  11. package/dist/lib/neutral/Filter.mjs +25 -12
  12. package/dist/lib/neutral/Format.mjs +23 -3
  13. package/dist/lib/neutral/JsonSchema.mjs +9 -9
  14. package/dist/lib/neutral/Key.mjs +7 -3
  15. package/dist/lib/neutral/Migration.mjs +18 -0
  16. package/dist/lib/neutral/Migration.mjs.map +7 -0
  17. package/dist/lib/neutral/Obj.mjs +41 -23
  18. package/dist/lib/neutral/Order.mjs +1 -1
  19. package/dist/lib/neutral/Query.mjs +21 -9
  20. package/dist/lib/neutral/QueryResult.mjs +1 -1
  21. package/dist/lib/neutral/Ref.mjs +13 -9
  22. package/dist/lib/neutral/Relation.mjs +34 -23
  23. package/dist/lib/neutral/SchemaRegistry.mjs +1 -1
  24. package/dist/lib/neutral/Tag.mjs +14 -10
  25. package/dist/lib/neutral/Type.mjs +52 -36
  26. package/dist/lib/neutral/{chunk-K5K3Z62A.mjs → chunk-4SYHDOQA.mjs} +14 -6
  27. package/dist/lib/neutral/chunk-4SYHDOQA.mjs.map +7 -0
  28. package/dist/lib/neutral/{chunk-XAJMXQ4H.mjs → chunk-4U7OD55H.mjs} +6 -2
  29. package/dist/lib/neutral/chunk-4U7OD55H.mjs.map +7 -0
  30. package/dist/lib/neutral/chunk-52NG2XEE.mjs +34 -0
  31. package/dist/lib/neutral/chunk-52NG2XEE.mjs.map +7 -0
  32. package/dist/lib/neutral/{chunk-KB7RIVLK.mjs → chunk-A5HDDVKS.mjs} +33 -6
  33. package/dist/lib/neutral/chunk-A5HDDVKS.mjs.map +7 -0
  34. package/dist/lib/neutral/{chunk-DLPC7DHQ.mjs → chunk-EZ4XJFHJ.mjs} +9 -11
  35. package/dist/lib/neutral/chunk-EZ4XJFHJ.mjs.map +7 -0
  36. package/dist/lib/neutral/{chunk-ZAHWXGK4.mjs → chunk-F625JEZB.mjs} +97 -19
  37. package/dist/lib/neutral/chunk-F625JEZB.mjs.map +7 -0
  38. package/dist/lib/neutral/chunk-FFCN66OF.mjs +420 -0
  39. package/dist/lib/neutral/chunk-FFCN66OF.mjs.map +7 -0
  40. package/dist/lib/neutral/{chunk-RPB6V4BE.mjs → chunk-GOHDOJE3.mjs} +16 -3
  41. package/dist/lib/neutral/chunk-GOHDOJE3.mjs.map +7 -0
  42. package/dist/lib/neutral/chunk-GWFFC34K.mjs +50 -0
  43. package/dist/lib/neutral/chunk-GWFFC34K.mjs.map +7 -0
  44. package/dist/lib/neutral/chunk-J7QWJQQV.mjs +318 -0
  45. package/dist/lib/neutral/chunk-J7QWJQQV.mjs.map +7 -0
  46. package/dist/lib/neutral/{chunk-QARLJVDB.mjs → chunk-JTHNDGAR.mjs} +8 -4
  47. package/dist/lib/neutral/chunk-JTHNDGAR.mjs.map +7 -0
  48. package/dist/lib/neutral/chunk-K5RH2PBH.mjs +361 -0
  49. package/dist/lib/neutral/chunk-K5RH2PBH.mjs.map +7 -0
  50. package/dist/lib/neutral/{chunk-RIMHNJ3E.mjs → chunk-KHRAQDYX.mjs} +138 -91
  51. package/dist/lib/neutral/chunk-KHRAQDYX.mjs.map +7 -0
  52. package/dist/lib/neutral/chunk-L65CW5EI.mjs +156 -0
  53. package/dist/lib/neutral/chunk-L65CW5EI.mjs.map +7 -0
  54. package/dist/lib/neutral/chunk-LNZIPZX6.mjs +2186 -0
  55. package/dist/lib/neutral/chunk-LNZIPZX6.mjs.map +7 -0
  56. package/dist/lib/neutral/chunk-MPXUNTME.mjs +41 -0
  57. package/dist/lib/neutral/chunk-MPXUNTME.mjs.map +7 -0
  58. package/dist/lib/neutral/{chunk-7WE7SBA2.mjs → chunk-O2EOH7XQ.mjs} +152 -134
  59. package/dist/lib/neutral/chunk-O2EOH7XQ.mjs.map +7 -0
  60. package/dist/lib/neutral/{chunk-MTEHHY62.mjs → chunk-Q7ID37KF.mjs} +121 -94
  61. package/dist/lib/neutral/chunk-Q7ID37KF.mjs.map +7 -0
  62. package/dist/lib/neutral/chunk-QLYEQ5VA.mjs +205 -0
  63. package/dist/lib/neutral/chunk-QLYEQ5VA.mjs.map +7 -0
  64. package/dist/lib/neutral/chunk-SSDGRJ3A.mjs +747 -0
  65. package/dist/lib/neutral/chunk-SSDGRJ3A.mjs.map +7 -0
  66. package/dist/lib/neutral/{chunk-ROKO4RKJ.mjs → chunk-TTCSATUD.mjs} +2 -2
  67. package/dist/lib/neutral/chunk-TTCSATUD.mjs.map +7 -0
  68. package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-UEFRFUYC.mjs} +8 -4
  69. package/dist/lib/neutral/chunk-UEFRFUYC.mjs.map +7 -0
  70. package/dist/lib/neutral/chunk-UN7K472Q.mjs +132 -0
  71. package/dist/lib/neutral/chunk-UN7K472Q.mjs.map +7 -0
  72. package/dist/lib/neutral/chunk-UQAMAXDU.mjs +243 -0
  73. package/dist/lib/neutral/chunk-UQAMAXDU.mjs.map +7 -0
  74. package/dist/lib/neutral/{chunk-4L6DOFXP.mjs → chunk-V5NE2X7Y.mjs} +1 -1
  75. package/dist/lib/neutral/chunk-V5NE2X7Y.mjs.map +7 -0
  76. package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-V72DY6LU.mjs} +1 -1
  77. package/dist/lib/neutral/chunk-ZII2BGPM.mjs +269 -0
  78. package/dist/lib/neutral/chunk-ZII2BGPM.mjs.map +7 -0
  79. package/dist/lib/neutral/{chunk-N2QNHMT5.mjs → chunk-ZM7VFIS2.mjs} +22 -2
  80. package/dist/lib/neutral/chunk-ZM7VFIS2.mjs.map +7 -0
  81. package/dist/lib/neutral/index.mjs +56 -29
  82. package/dist/lib/neutral/internal/index.mjs +128 -77
  83. package/dist/lib/neutral/meta.json +1 -1
  84. package/dist/lib/neutral/testing/index.mjs +226 -174
  85. package/dist/lib/neutral/testing/index.mjs.map +3 -3
  86. package/dist/types/src/Annotation.d.ts +3 -3
  87. package/dist/types/src/Annotation.d.ts.map +1 -1
  88. package/dist/types/src/Collection.d.ts +15 -0
  89. package/dist/types/src/Collection.d.ts.map +1 -0
  90. package/dist/types/src/Database.d.ts +27 -42
  91. package/dist/types/src/Database.d.ts.map +1 -1
  92. package/dist/types/src/Dataset.d.ts +29 -0
  93. package/dist/types/src/Dataset.d.ts.map +1 -0
  94. package/dist/types/src/Entity.d.ts +123 -29
  95. package/dist/types/src/Entity.d.ts.map +1 -1
  96. package/dist/types/src/Err.d.ts +56 -13
  97. package/dist/types/src/Err.d.ts.map +1 -1
  98. package/dist/types/src/Extension.d.ts +80 -0
  99. package/dist/types/src/Extension.d.ts.map +1 -0
  100. package/dist/types/src/Extension.test.d.ts +2 -0
  101. package/dist/types/src/Extension.test.d.ts.map +1 -0
  102. package/dist/types/src/Feed.d.ts +229 -0
  103. package/dist/types/src/Feed.d.ts.map +1 -0
  104. package/dist/types/src/Filter.d.ts +74 -11
  105. package/dist/types/src/Filter.d.ts.map +1 -1
  106. package/dist/types/src/Filter.test.d.ts +2 -0
  107. package/dist/types/src/Filter.test.d.ts.map +1 -0
  108. package/dist/types/src/Format.d.ts +3 -3
  109. package/dist/types/src/Format.d.ts.map +1 -1
  110. package/dist/types/src/Hypergraph.d.ts +15 -10
  111. package/dist/types/src/Hypergraph.d.ts.map +1 -1
  112. package/dist/types/src/Json.d.ts +33 -0
  113. package/dist/types/src/Json.d.ts.map +1 -0
  114. package/dist/types/src/Json.test.d.ts +2 -0
  115. package/dist/types/src/Json.test.d.ts.map +1 -0
  116. package/dist/types/src/JsonSchema.d.ts +11 -4
  117. package/dist/types/src/JsonSchema.d.ts.map +1 -1
  118. package/dist/types/src/Key.d.ts +1 -1
  119. package/dist/types/src/Key.d.ts.map +1 -1
  120. package/dist/types/src/Migration.d.ts +72 -0
  121. package/dist/types/src/Migration.d.ts.map +1 -0
  122. package/dist/types/src/Obj.d.ts +201 -77
  123. package/dist/types/src/Obj.d.ts.map +1 -1
  124. package/dist/types/src/Order.d.ts.map +1 -1
  125. package/dist/types/src/Query.d.ts +117 -17
  126. package/dist/types/src/Query.d.ts.map +1 -1
  127. package/dist/types/src/Ref.d.ts +66 -10
  128. package/dist/types/src/Ref.d.ts.map +1 -1
  129. package/dist/types/src/Relation.d.ts +127 -54
  130. package/dist/types/src/Relation.d.ts.map +1 -1
  131. package/dist/types/src/SchemaRegistry.d.ts +12 -13
  132. package/dist/types/src/SchemaRegistry.d.ts.map +1 -1
  133. package/dist/types/src/Tag.d.ts +4 -3
  134. package/dist/types/src/Tag.d.ts.map +1 -1
  135. package/dist/types/src/Type.d.ts +337 -218
  136. package/dist/types/src/Type.d.ts.map +1 -1
  137. package/dist/types/src/View.d.ts +65 -0
  138. package/dist/types/src/View.d.ts.map +1 -0
  139. package/dist/types/src/exemplars.test.d.ts +2 -0
  140. package/dist/types/src/exemplars.test.d.ts.map +1 -0
  141. package/dist/types/src/index.d.ts +8 -1
  142. package/dist/types/src/index.d.ts.map +1 -1
  143. package/dist/types/src/internal/{annotations → Annotation}/annotations.d.ts +98 -24
  144. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
  145. package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
  146. package/dist/types/src/internal/Annotation/index.d.ts +4 -0
  147. package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
  148. package/dist/types/src/internal/{api → Annotation}/sorting.d.ts +1 -1
  149. package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
  150. package/dist/types/src/internal/{annotations → Annotation}/util.d.ts +15 -6
  151. package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
  152. package/dist/types/src/internal/Entity/api.d.ts +13 -0
  153. package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
  154. package/dist/types/src/internal/Entity/entity.d.ts +67 -0
  155. package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
  156. package/dist/types/src/internal/Entity/index.d.ts +10 -0
  157. package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
  158. package/dist/types/src/internal/Entity/model.d.ts +57 -0
  159. package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
  160. package/dist/types/src/internal/{entities → Entity}/object.d.ts +3 -3
  161. package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
  162. package/dist/types/src/internal/Entity/relation.d.ts +51 -0
  163. package/dist/types/src/internal/Entity/relation.d.ts.map +1 -0
  164. package/dist/types/src/internal/Entity/type-kind.d.ts +24 -0
  165. package/dist/types/src/internal/Entity/type-kind.d.ts.map +1 -0
  166. package/dist/types/src/internal/Entity/type-uri.d.ts +25 -0
  167. package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -0
  168. package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
  169. package/dist/types/src/internal/{api → Entity}/version.d.ts +1 -1
  170. package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
  171. package/dist/types/src/internal/Format/date.d.ts.map +1 -0
  172. package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
  173. package/dist/types/src/internal/{formats → Format}/format.d.ts +2 -1
  174. package/dist/types/src/internal/Format/format.d.ts.map +1 -0
  175. package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
  176. package/dist/types/src/internal/{formats → Format}/index.d.ts +2 -2
  177. package/dist/types/src/internal/Format/index.d.ts.map +1 -0
  178. package/dist/types/src/internal/Format/number.d.ts.map +1 -0
  179. package/dist/types/src/internal/Format/object.d.ts.map +1 -0
  180. package/dist/types/src/internal/Format/select.d.ts.map +1 -0
  181. package/dist/types/src/internal/Format/string.d.ts.map +1 -0
  182. package/dist/types/src/internal/{formats → Format}/types.d.ts +1 -1
  183. package/dist/types/src/internal/Format/types.d.ts.map +1 -0
  184. package/dist/types/src/internal/{json-schema → JsonSchema}/annotations.d.ts +1 -1
  185. package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
  186. package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
  187. package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
  188. package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
  189. package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-type.d.ts +37 -37
  190. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
  191. package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.d.ts +3 -2
  192. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
  193. package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
  194. package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
  195. package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
  196. package/dist/types/src/internal/{object → Obj}/create-object.d.ts +10 -12
  197. package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
  198. package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
  199. package/dist/types/src/internal/{object → Obj}/deleted.d.ts +1 -1
  200. package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
  201. package/dist/types/src/internal/{object → Obj}/index.d.ts +0 -1
  202. package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
  203. package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
  204. package/dist/types/src/internal/{object → Obj}/json-serializer.d.ts +16 -8
  205. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -0
  206. package/dist/types/src/internal/Obj/json-serializer.test.d.ts.map +1 -0
  207. package/dist/types/src/internal/Obj/schema-validator.d.ts +2 -0
  208. package/dist/types/src/internal/Obj/schema-validator.d.ts.map +1 -0
  209. package/dist/types/src/internal/Obj/schema-validator.test.d.ts.map +1 -0
  210. package/dist/types/src/internal/{object → Obj}/set-value.d.ts +2 -2
  211. package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
  212. package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
  213. package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
  214. package/dist/types/src/internal/{object → Obj}/typed-object.d.ts +5 -5
  215. package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
  216. package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
  217. package/dist/types/src/internal/Query.d.ts +10 -0
  218. package/dist/types/src/internal/Query.d.ts.map +1 -0
  219. package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
  220. package/dist/types/src/internal/{ref → Ref}/ref-array.d.ts +1 -1
  221. package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
  222. package/dist/types/src/internal/{ref → Ref}/ref.d.ts +42 -19
  223. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
  224. package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
  225. package/dist/types/src/internal/{schema → Type}/compose.d.ts +1 -1
  226. package/dist/types/src/internal/Type/compose.d.ts.map +1 -0
  227. package/dist/types/src/internal/Type/compose.test.d.ts.map +1 -0
  228. package/dist/types/src/internal/Type/index.d.ts +3 -0
  229. package/dist/types/src/internal/Type/index.d.ts.map +1 -0
  230. package/dist/types/src/internal/{schema → Type}/manipulation.d.ts +0 -1
  231. package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
  232. package/dist/types/src/internal/Type/type-schema.d.ts +52 -0
  233. package/dist/types/src/internal/Type/type-schema.d.ts.map +1 -0
  234. package/dist/types/src/internal/{api → common/api}/index.d.ts +0 -4
  235. package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
  236. package/dist/types/src/internal/{api → common/api}/meta.d.ts +3 -3
  237. package/dist/types/src/internal/common/api/meta.d.ts.map +1 -0
  238. package/dist/types/src/internal/common/index.d.ts +4 -0
  239. package/dist/types/src/internal/common/index.d.ts.map +1 -0
  240. package/dist/types/src/internal/{proxy → common/proxy}/change-context.d.ts +1 -1
  241. package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -0
  242. package/dist/types/src/internal/common/proxy/change.test.d.ts.map +1 -0
  243. package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
  244. package/dist/types/src/internal/{proxy → common/proxy}/errors.d.ts +1 -1
  245. package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -0
  246. package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -0
  247. package/dist/types/src/internal/common/proxy/handler.test.d.ts.map +1 -0
  248. package/dist/types/src/internal/common/proxy/index.d.ts.map +1 -0
  249. package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -0
  250. package/dist/types/src/internal/common/proxy/make-object.d.ts +19 -0
  251. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -0
  252. package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -0
  253. package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -0
  254. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -0
  255. package/dist/types/src/internal/{proxy → common/proxy}/reactive-array.d.ts +1 -1
  256. package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
  257. package/dist/types/src/internal/{proxy → common/proxy}/reactive.d.ts +2 -2
  258. package/dist/types/src/internal/{proxy → common/proxy}/reactive.d.ts.map +1 -1
  259. package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
  260. package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -0
  261. package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -0
  262. package/dist/types/src/internal/common/proxy/schema.test.d.ts.map +1 -0
  263. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -0
  264. package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.d.ts +18 -2
  265. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -0
  266. package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts.map +1 -0
  267. package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
  268. package/dist/types/src/internal/{types → common/types}/base.d.ts +1 -0
  269. package/dist/types/src/internal/common/types/base.d.ts.map +1 -0
  270. package/dist/types/src/internal/common/types/entity.d.ts +94 -0
  271. package/dist/types/src/internal/common/types/entity.d.ts.map +1 -0
  272. package/dist/types/src/internal/{types → common/types}/index.d.ts +1 -0
  273. package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
  274. package/dist/types/src/internal/{types → common/types}/meta.d.ts +12 -1
  275. package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
  276. package/dist/types/src/internal/common/types/model-symbols.d.ts +58 -0
  277. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
  278. package/dist/types/src/internal/{types → common/types}/typename.d.ts +7 -0
  279. package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
  280. package/dist/types/src/internal/{types → common/types}/version.d.ts +2 -2
  281. package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
  282. package/dist/types/src/internal/index.d.ts +9 -10
  283. package/dist/types/src/internal/index.d.ts.map +1 -1
  284. package/dist/types/src/testing/test-data.d.ts +8 -8
  285. package/dist/types/src/testing/test-data.d.ts.map +1 -1
  286. package/dist/types/src/testing/test-schema.d.ts +77 -82
  287. package/dist/types/src/testing/test-schema.d.ts.map +1 -1
  288. package/dist/types/src/testing/util.d.ts +5 -3
  289. package/dist/types/src/testing/util.d.ts.map +1 -1
  290. package/dist/types/tsconfig.tsbuildinfo +1 -1
  291. package/package.json +30 -15
  292. package/src/Annotation.ts +7 -3
  293. package/src/Collection.ts +36 -0
  294. package/src/Database.ts +80 -77
  295. package/src/Dataset.ts +34 -0
  296. package/src/Entity.test.ts +116 -6
  297. package/src/Entity.ts +181 -66
  298. package/src/Err.ts +25 -3
  299. package/src/Extension.test.ts +235 -0
  300. package/src/Extension.ts +122 -0
  301. package/src/Feed.ts +356 -0
  302. package/src/Filter.test.ts +90 -0
  303. package/src/Filter.ts +152 -21
  304. package/src/Format.ts +3 -3
  305. package/src/Hypergraph.ts +16 -11
  306. package/src/Json.test.ts +175 -0
  307. package/src/Json.ts +103 -0
  308. package/src/JsonSchema.ts +14 -4
  309. package/src/Key.ts +1 -1
  310. package/src/Migration.ts +114 -0
  311. package/src/Obj.test.ts +158 -20
  312. package/src/Obj.ts +451 -183
  313. package/src/Order.ts +3 -1
  314. package/src/Query.test.ts +446 -89
  315. package/src/Query.ts +300 -35
  316. package/src/Ref.ts +83 -12
  317. package/src/Relation.test.ts +16 -10
  318. package/src/Relation.ts +236 -165
  319. package/src/SchemaRegistry.ts +13 -17
  320. package/src/Tag.ts +9 -9
  321. package/src/Type.test.ts +169 -24
  322. package/src/Type.ts +561 -354
  323. package/src/View.ts +101 -0
  324. package/src/exemplars.test.ts +21 -0
  325. package/src/index.ts +9 -2
  326. package/src/internal/Annotation/annotations.test.ts +165 -0
  327. package/src/internal/{annotations → Annotation}/annotations.ts +181 -101
  328. package/src/internal/{annotations → Annotation}/index.ts +1 -0
  329. package/src/internal/{api → Annotation}/sorting.ts +2 -4
  330. package/src/internal/{annotations → Annotation}/util.ts +17 -9
  331. package/src/internal/{api/entity.ts → Entity/api.ts} +9 -8
  332. package/src/internal/Entity/entity.ts +246 -0
  333. package/src/internal/{entities → Entity}/index.ts +4 -0
  334. package/src/internal/{entities → Entity}/model.ts +42 -60
  335. package/src/internal/{entities → Entity}/object.ts +13 -6
  336. package/src/internal/Entity/relation.ts +179 -0
  337. package/src/internal/Entity/type-kind.ts +67 -0
  338. package/src/internal/Entity/type-uri.ts +87 -0
  339. package/src/internal/Entity/util.ts +34 -0
  340. package/src/internal/{api → Entity}/version.ts +2 -2
  341. package/src/internal/{formats → Format}/date.test.ts +1 -2
  342. package/src/internal/{formats → Format}/date.ts +0 -4
  343. package/src/internal/{formats → Format}/format.test.ts +1 -2
  344. package/src/internal/{formats → Format}/index.ts +2 -3
  345. package/src/internal/{formats → Format}/types.ts +2 -2
  346. package/src/internal/{json-schema → JsonSchema}/annotations.ts +3 -3
  347. package/src/internal/{json-schema → JsonSchema}/json-schema-type.ts +4 -4
  348. package/src/internal/{json-schema → JsonSchema}/json-schema.test.ts +64 -151
  349. package/src/internal/{json-schema → JsonSchema}/json-schema.ts +47 -28
  350. package/src/internal/{object → Obj}/clone.ts +10 -6
  351. package/src/internal/{object → Obj}/common.ts +2 -2
  352. package/src/internal/{object → Obj}/create-object.test.ts +13 -14
  353. package/src/internal/Obj/create-object.ts +135 -0
  354. package/src/internal/{object → Obj}/deleted.ts +2 -2
  355. package/src/internal/{object → Obj}/index.ts +0 -1
  356. package/src/internal/{object → Obj}/inspect.ts +3 -3
  357. package/src/internal/Obj/json-serializer.test.ts +185 -0
  358. package/src/internal/{object → Obj}/json-serializer.ts +108 -45
  359. package/src/internal/{object → Obj}/schema-validator.ts +1 -1
  360. package/src/internal/{object → Obj}/set-value.test.ts +31 -54
  361. package/src/internal/{object → Obj}/set-value.ts +3 -3
  362. package/src/internal/{object → Obj}/snapshot.ts +41 -23
  363. package/src/internal/Obj/typed-object.test.ts +32 -0
  364. package/src/internal/{object → Obj}/typed-object.ts +5 -5
  365. package/src/internal/Query.ts +156 -0
  366. package/src/internal/{ref → Ref}/ref-array.ts +1 -2
  367. package/src/internal/{ref → Ref}/ref.test.ts +16 -26
  368. package/src/internal/{ref → Ref}/ref.ts +117 -57
  369. package/src/internal/{schema → Type}/compose.test.ts +6 -5
  370. package/src/internal/{schema → Type}/compose.ts +1 -1
  371. package/src/internal/Type/index.ts +6 -0
  372. package/src/internal/{schema → Type}/manipulation.ts +0 -25
  373. package/src/internal/Type/type-schema.ts +60 -0
  374. package/src/internal/{README.md → common/README.md} +2 -2
  375. package/src/internal/{api → common/api}/index.ts +0 -4
  376. package/src/internal/{api → common/api}/meta.ts +3 -3
  377. package/src/internal/common/index.ts +7 -0
  378. package/src/internal/{proxy → common/proxy}/change-context.ts +1 -1
  379. package/src/internal/{proxy → common/proxy}/change.test.ts +97 -97
  380. package/src/internal/{proxy → common/proxy}/errors.ts +2 -2
  381. package/src/internal/{proxy → common/proxy}/handler.test.ts +2 -4
  382. package/src/internal/{proxy → common/proxy}/json-serializer.ts +20 -14
  383. package/src/internal/{proxy → common/proxy}/make-object.ts +37 -15
  384. package/src/internal/{proxy → common/proxy}/ownership.ts +0 -1
  385. package/src/internal/{proxy → common/proxy}/reactive-array.ts +1 -1
  386. package/src/internal/common/proxy/reactive.test.ts +54 -0
  387. package/src/internal/{proxy → common/proxy}/reactive.ts +12 -4
  388. package/src/internal/common/proxy/schema.test.ts +107 -0
  389. package/src/internal/{proxy → common/proxy}/typed-handler.test.ts +15 -15
  390. package/src/internal/{proxy → common/proxy}/typed-handler.ts +75 -18
  391. package/src/internal/{proxy → common/proxy}/typed-object.test.ts +17 -30
  392. package/src/internal/{types → common/types}/base.ts +1 -1
  393. package/src/internal/common/types/entity.ts +133 -0
  394. package/src/internal/{types → common/types}/index.ts +1 -0
  395. package/src/internal/{types → common/types}/meta.ts +15 -1
  396. package/src/internal/common/types/model-symbols.ts +74 -0
  397. package/src/internal/common/types/typename.ts +91 -0
  398. package/src/internal/{types → common/types}/version.ts +2 -3
  399. package/src/internal/index.ts +9 -31
  400. package/src/testing/api.test.ts +15 -12
  401. package/src/testing/test-data.ts +158 -99
  402. package/src/testing/test-schema.ts +33 -67
  403. package/src/testing/util.ts +14 -11
  404. package/dist/lib/neutral/chunk-2AF5GMG6.mjs +0 -171
  405. package/dist/lib/neutral/chunk-2AF5GMG6.mjs.map +0 -7
  406. package/dist/lib/neutral/chunk-4L6DOFXP.mjs.map +0 -7
  407. package/dist/lib/neutral/chunk-7WE7SBA2.mjs.map +0 -7
  408. package/dist/lib/neutral/chunk-ANHVGJI4.mjs.map +0 -7
  409. package/dist/lib/neutral/chunk-DLPC7DHQ.mjs.map +0 -7
  410. package/dist/lib/neutral/chunk-EBUAT5ID.mjs +0 -229
  411. package/dist/lib/neutral/chunk-EBUAT5ID.mjs.map +0 -7
  412. package/dist/lib/neutral/chunk-K5K3Z62A.mjs.map +0 -7
  413. package/dist/lib/neutral/chunk-KB7RIVLK.mjs.map +0 -7
  414. package/dist/lib/neutral/chunk-LKFNEFHF.mjs +0 -130
  415. package/dist/lib/neutral/chunk-LKFNEFHF.mjs.map +0 -7
  416. package/dist/lib/neutral/chunk-MTEHHY62.mjs.map +0 -7
  417. package/dist/lib/neutral/chunk-N2QNHMT5.mjs.map +0 -7
  418. package/dist/lib/neutral/chunk-QARLJVDB.mjs.map +0 -7
  419. package/dist/lib/neutral/chunk-RIMHNJ3E.mjs.map +0 -7
  420. package/dist/lib/neutral/chunk-ROKO4RKJ.mjs.map +0 -7
  421. package/dist/lib/neutral/chunk-RPB6V4BE.mjs.map +0 -7
  422. package/dist/lib/neutral/chunk-TLGNKUUG.mjs +0 -3905
  423. package/dist/lib/neutral/chunk-TLGNKUUG.mjs.map +0 -7
  424. package/dist/lib/neutral/chunk-TQT6WTIJ.mjs +0 -142
  425. package/dist/lib/neutral/chunk-TQT6WTIJ.mjs.map +0 -7
  426. package/dist/lib/neutral/chunk-VUQGRDRI.mjs +0 -97
  427. package/dist/lib/neutral/chunk-VUQGRDRI.mjs.map +0 -7
  428. package/dist/lib/neutral/chunk-X2MPMYYN.mjs +0 -13
  429. package/dist/lib/neutral/chunk-X2MPMYYN.mjs.map +0 -7
  430. package/dist/lib/neutral/chunk-XAJMXQ4H.mjs.map +0 -7
  431. package/dist/lib/neutral/chunk-ZAHWXGK4.mjs.map +0 -7
  432. package/dist/types/src/internal/annotations/annotations.d.ts.map +0 -1
  433. package/dist/types/src/internal/annotations/annotations.test.d.ts.map +0 -1
  434. package/dist/types/src/internal/annotations/index.d.ts +0 -3
  435. package/dist/types/src/internal/annotations/index.d.ts.map +0 -1
  436. package/dist/types/src/internal/annotations/util.d.ts.map +0 -1
  437. package/dist/types/src/internal/api/annotations.d.ts +0 -23
  438. package/dist/types/src/internal/api/annotations.d.ts.map +0 -1
  439. package/dist/types/src/internal/api/entity.d.ts +0 -13
  440. package/dist/types/src/internal/api/entity.d.ts.map +0 -1
  441. package/dist/types/src/internal/api/index.d.ts.map +0 -1
  442. package/dist/types/src/internal/api/meta.d.ts.map +0 -1
  443. package/dist/types/src/internal/api/sorting.d.ts.map +0 -1
  444. package/dist/types/src/internal/api/version.d.ts.map +0 -1
  445. package/dist/types/src/internal/entities/entity.d.ts +0 -20
  446. package/dist/types/src/internal/entities/entity.d.ts.map +0 -1
  447. package/dist/types/src/internal/entities/index.d.ts +0 -6
  448. package/dist/types/src/internal/entities/index.d.ts.map +0 -1
  449. package/dist/types/src/internal/entities/model.d.ts +0 -79
  450. package/dist/types/src/internal/entities/model.d.ts.map +0 -1
  451. package/dist/types/src/internal/entities/object.d.ts.map +0 -1
  452. package/dist/types/src/internal/entities/relation.d.ts +0 -62
  453. package/dist/types/src/internal/entities/relation.d.ts.map +0 -1
  454. package/dist/types/src/internal/entities/util.d.ts.map +0 -1
  455. package/dist/types/src/internal/formats/date.d.ts.map +0 -1
  456. package/dist/types/src/internal/formats/date.test.d.ts.map +0 -1
  457. package/dist/types/src/internal/formats/format.d.ts.map +0 -1
  458. package/dist/types/src/internal/formats/format.test.d.ts.map +0 -1
  459. package/dist/types/src/internal/formats/index.d.ts.map +0 -1
  460. package/dist/types/src/internal/formats/number.d.ts.map +0 -1
  461. package/dist/types/src/internal/formats/object.d.ts.map +0 -1
  462. package/dist/types/src/internal/formats/select.d.ts.map +0 -1
  463. package/dist/types/src/internal/formats/string.d.ts.map +0 -1
  464. package/dist/types/src/internal/formats/types.d.ts.map +0 -1
  465. package/dist/types/src/internal/json-schema/annotations.d.ts.map +0 -1
  466. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +0 -1
  467. package/dist/types/src/internal/json-schema/index.d.ts.map +0 -1
  468. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +0 -1
  469. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +0 -1
  470. package/dist/types/src/internal/json-schema/json-schema.d.ts.map +0 -1
  471. package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +0 -1
  472. package/dist/types/src/internal/object/clone.d.ts.map +0 -1
  473. package/dist/types/src/internal/object/common.d.ts.map +0 -1
  474. package/dist/types/src/internal/object/create-object.d.ts.map +0 -1
  475. package/dist/types/src/internal/object/create-object.test.d.ts.map +0 -1
  476. package/dist/types/src/internal/object/deleted.d.ts.map +0 -1
  477. package/dist/types/src/internal/object/ids.d.ts +0 -6
  478. package/dist/types/src/internal/object/ids.d.ts.map +0 -1
  479. package/dist/types/src/internal/object/index.d.ts.map +0 -1
  480. package/dist/types/src/internal/object/inspect.d.ts.map +0 -1
  481. package/dist/types/src/internal/object/json-serializer.d.ts.map +0 -1
  482. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +0 -1
  483. package/dist/types/src/internal/object/schema-validator.d.ts +0 -2
  484. package/dist/types/src/internal/object/schema-validator.d.ts.map +0 -1
  485. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +0 -1
  486. package/dist/types/src/internal/object/set-value.d.ts.map +0 -1
  487. package/dist/types/src/internal/object/set-value.test.d.ts.map +0 -1
  488. package/dist/types/src/internal/object/snapshot.d.ts.map +0 -1
  489. package/dist/types/src/internal/object/typed-object.d.ts.map +0 -1
  490. package/dist/types/src/internal/object/typed-object.test.d.ts.map +0 -1
  491. package/dist/types/src/internal/proxy/change-context.d.ts.map +0 -1
  492. package/dist/types/src/internal/proxy/change.test.d.ts.map +0 -1
  493. package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +0 -1
  494. package/dist/types/src/internal/proxy/errors.d.ts.map +0 -1
  495. package/dist/types/src/internal/proxy/event-batch.d.ts.map +0 -1
  496. package/dist/types/src/internal/proxy/handler.test.d.ts.map +0 -1
  497. package/dist/types/src/internal/proxy/index.d.ts.map +0 -1
  498. package/dist/types/src/internal/proxy/json-serializer.d.ts.map +0 -1
  499. package/dist/types/src/internal/proxy/make-object.d.ts +0 -14
  500. package/dist/types/src/internal/proxy/make-object.d.ts.map +0 -1
  501. package/dist/types/src/internal/proxy/ownership.d.ts.map +0 -1
  502. package/dist/types/src/internal/proxy/proxy-types.d.ts.map +0 -1
  503. package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +0 -1
  504. package/dist/types/src/internal/proxy/reactive-array.d.ts.map +0 -1
  505. package/dist/types/src/internal/proxy/schema-validator.d.ts.map +0 -1
  506. package/dist/types/src/internal/proxy/schema.test.d.ts.map +0 -1
  507. package/dist/types/src/internal/proxy/symbols.d.ts.map +0 -1
  508. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +0 -1
  509. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +0 -1
  510. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +0 -1
  511. package/dist/types/src/internal/ref/index.d.ts.map +0 -1
  512. package/dist/types/src/internal/ref/ref-array.d.ts.map +0 -1
  513. package/dist/types/src/internal/ref/ref.d.ts.map +0 -1
  514. package/dist/types/src/internal/ref/ref.test.d.ts.map +0 -1
  515. package/dist/types/src/internal/schema/compose.d.ts.map +0 -1
  516. package/dist/types/src/internal/schema/compose.test.d.ts.map +0 -1
  517. package/dist/types/src/internal/schema/echo-schema.d.ts +0 -181
  518. package/dist/types/src/internal/schema/echo-schema.d.ts.map +0 -1
  519. package/dist/types/src/internal/schema/index.d.ts +0 -4
  520. package/dist/types/src/internal/schema/index.d.ts.map +0 -1
  521. package/dist/types/src/internal/schema/manipulation.d.ts.map +0 -1
  522. package/dist/types/src/internal/schema/persistent-schema.d.ts +0 -20
  523. package/dist/types/src/internal/schema/persistent-schema.d.ts.map +0 -1
  524. package/dist/types/src/internal/types/base.d.ts.map +0 -1
  525. package/dist/types/src/internal/types/entity.d.ts +0 -37
  526. package/dist/types/src/internal/types/entity.d.ts.map +0 -1
  527. package/dist/types/src/internal/types/index.d.ts.map +0 -1
  528. package/dist/types/src/internal/types/meta.d.ts.map +0 -1
  529. package/dist/types/src/internal/types/typename.d.ts.map +0 -1
  530. package/dist/types/src/internal/types/version.d.ts.map +0 -1
  531. package/src/internal/annotations/annotations.test.ts +0 -96
  532. package/src/internal/api/annotations.ts +0 -60
  533. package/src/internal/entities/entity.ts +0 -126
  534. package/src/internal/entities/relation.ts +0 -171
  535. package/src/internal/entities/util.ts +0 -33
  536. package/src/internal/object/create-object.ts +0 -95
  537. package/src/internal/object/ids.ts +0 -12
  538. package/src/internal/object/json-serializer.test.ts +0 -98
  539. package/src/internal/object/typed-object.test.ts +0 -34
  540. package/src/internal/proxy/schema.test.ts +0 -145
  541. package/src/internal/schema/echo-schema.ts +0 -424
  542. package/src/internal/schema/index.ts +0 -7
  543. package/src/internal/schema/persistent-schema.ts +0 -28
  544. package/src/internal/types/entity.ts +0 -54
  545. package/src/internal/types/typename.ts +0 -55
  546. /package/dist/lib/neutral/{chunk-OMUPQMLR.mjs.map → chunk-V72DY6LU.mjs.map} +0 -0
  547. /package/dist/types/src/internal/{annotations → Annotation}/annotations.test.d.ts +0 -0
  548. /package/dist/types/src/internal/{entities → Entity}/util.d.ts +0 -0
  549. /package/dist/types/src/internal/{formats → Format}/date.d.ts +0 -0
  550. /package/dist/types/src/internal/{formats → Format}/date.test.d.ts +0 -0
  551. /package/dist/types/src/internal/{formats → Format}/format.test.d.ts +0 -0
  552. /package/dist/types/src/internal/{formats → Format}/number.d.ts +0 -0
  553. /package/dist/types/src/internal/{formats → Format}/object.d.ts +0 -0
  554. /package/dist/types/src/internal/{formats → Format}/select.d.ts +0 -0
  555. /package/dist/types/src/internal/{formats → Format}/string.d.ts +0 -0
  556. /package/dist/types/src/internal/{json-schema → JsonSchema}/effect-schema.test.d.ts +0 -0
  557. /package/dist/types/src/internal/{json-schema → JsonSchema}/index.d.ts +0 -0
  558. /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-normalize.d.ts +0 -0
  559. /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.test.d.ts +0 -0
  560. /package/dist/types/src/internal/{object → Obj}/clone.d.ts +0 -0
  561. /package/dist/types/src/internal/{object → Obj}/common.d.ts +0 -0
  562. /package/dist/types/src/internal/{object → Obj}/create-object.test.d.ts +0 -0
  563. /package/dist/types/src/internal/{object → Obj}/inspect.d.ts +0 -0
  564. /package/dist/types/src/internal/{object → Obj}/json-serializer.test.d.ts +0 -0
  565. /package/dist/types/src/internal/{object → Obj}/schema-validator.test.d.ts +0 -0
  566. /package/dist/types/src/internal/{object → Obj}/set-value.test.d.ts +0 -0
  567. /package/dist/types/src/internal/{object → Obj}/snapshot.d.ts +0 -0
  568. /package/dist/types/src/internal/{object → Obj}/typed-object.test.d.ts +0 -0
  569. /package/dist/types/src/internal/{ref → Ref}/index.d.ts +0 -0
  570. /package/dist/types/src/internal/{ref → Ref}/ref.test.d.ts +0 -0
  571. /package/dist/types/src/internal/{schema → Type}/compose.test.d.ts +0 -0
  572. /package/dist/types/src/internal/{proxy → common/proxy}/change.test.d.ts +0 -0
  573. /package/dist/types/src/internal/{proxy → common/proxy}/define-hidden-property.d.ts +0 -0
  574. /package/dist/types/src/internal/{proxy → common/proxy}/event-batch.d.ts +0 -0
  575. /package/dist/types/src/internal/{proxy → common/proxy}/handler.test.d.ts +0 -0
  576. /package/dist/types/src/internal/{proxy → common/proxy}/index.d.ts +0 -0
  577. /package/dist/types/src/internal/{proxy → common/proxy}/json-serializer.d.ts +0 -0
  578. /package/dist/types/src/internal/{proxy → common/proxy}/ownership.d.ts +0 -0
  579. /package/dist/types/src/internal/{proxy → common/proxy}/proxy-types.d.ts +0 -0
  580. /package/dist/types/src/internal/{proxy → common/proxy}/proxy-utils.d.ts +0 -0
  581. /package/dist/types/src/internal/{proxy → common/proxy}/schema-validator.d.ts +0 -0
  582. /package/dist/types/src/internal/{proxy → common/proxy}/schema.test.d.ts +0 -0
  583. /package/dist/types/src/internal/{proxy → common/proxy}/symbols.d.ts +0 -0
  584. /package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.test.d.ts +0 -0
  585. /package/dist/types/src/internal/{proxy → common/proxy}/typed-object.test.d.ts +0 -0
  586. /package/src/internal/{formats → Format}/format.ts +0 -0
  587. /package/src/internal/{formats → Format}/number.ts +0 -0
  588. /package/src/internal/{formats → Format}/object.ts +0 -0
  589. /package/src/internal/{formats → Format}/select.ts +0 -0
  590. /package/src/internal/{formats → Format}/string.ts +0 -0
  591. /package/src/internal/{json-schema → JsonSchema}/effect-schema.test.ts +0 -0
  592. /package/src/internal/{json-schema → JsonSchema}/index.ts +0 -0
  593. /package/src/internal/{json-schema → JsonSchema}/json-schema-normalize.ts +0 -0
  594. /package/src/internal/{object → Obj}/schema-validator.test.ts +0 -0
  595. /package/src/internal/{ref → Ref}/index.ts +0 -0
  596. /package/src/internal/{proxy → common/proxy}/define-hidden-property.ts +0 -0
  597. /package/src/internal/{proxy → common/proxy}/event-batch.ts +0 -0
  598. /package/src/internal/{proxy → common/proxy}/index.ts +0 -0
  599. /package/src/internal/{proxy → common/proxy}/proxy-types.ts +0 -0
  600. /package/src/internal/{proxy → common/proxy}/proxy-utils.ts +0 -0
  601. /package/src/internal/{proxy → common/proxy}/schema-validator.ts +0 -0
  602. /package/src/internal/{proxy → common/proxy}/symbols.ts +0 -0
package/src/Type.ts CHANGED
@@ -2,160 +2,93 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
5
7
  import * as Schema from 'effect/Schema';
8
+ import type * as Types from 'effect/Types';
6
9
 
10
+ import { raise } from '@dxos/debug';
7
11
  import { type EncodedReference } from '@dxos/echo-protocol';
8
12
  import { invariant } from '@dxos/invariant';
9
- import { type DXN, type ObjectId } from '@dxos/keys';
10
- import { type ToMutable } from '@dxos/util';
11
-
12
- import type * as Entity$ from './Entity';
13
- import {
14
- ANY_OBJECT_TYPENAME,
15
- ANY_OBJECT_VERSION,
16
- type ATTR_RELATION_SOURCE,
17
- type ATTR_RELATION_TARGET,
18
- type AnyEntity,
19
- type AnyProperties,
20
- EchoObjectSchema,
21
- EchoRelationSchema,
22
- type EchoRelationSchemaOptions,
23
- EchoSchema,
24
- EntityKind,
25
- PersistentSchema,
26
- Ref as Ref$,
27
- type RefFn,
28
- type RefSchema,
29
- SchemaKindId,
30
- type TypeAnnotation,
31
- type TypeMeta,
32
- getSchemaDXN,
33
- getSchemaTypename,
34
- getSchemaVersion,
35
- getTypeAnnotation,
36
- isMutable as isMutable$,
37
- toEffectSchema,
38
- toJsonSchema,
39
- } from './internal';
40
- import type * as Relation$ from './Relation';
41
-
42
- // TODO(burdon): Remove toEffectSchema, toJsonSchema (moved to JsonSchema export).
43
- export { toEffectSchema, toJsonSchema };
44
-
45
- /**
46
- * Returns all properties of an object or relation except for the id and kind.
47
- */
48
- export type Properties<T = any> = Omit<T, 'id' | Entity$.KindId | Relation$.Source | Relation$.Target>;
13
+ import { DXN, EchoURI, type ObjectId, type URI } from '@dxos/keys';
14
+
15
+ import type * as Database from './Database';
16
+ import type * as EntityModule from './Entity';
17
+ import * as internal from './internal';
18
+ import * as typeInternal from './internal/Type';
19
+ import type * as RelationModule from './Relation';
49
20
 
50
21
  //
51
22
  // Internal types (not exported)
52
23
  //
53
24
 
54
25
  /**
55
- * Type that marks a schema as an ECHO schema.
56
- * The value indicates the entity kind (Object or Relation).
57
- */
58
- type EchoSchemaKind<K extends EntityKind = EntityKind> = {
59
- readonly [SchemaKindId]: K;
60
- };
61
-
62
- /**
63
- * JSON-encoded properties for objects.
26
+ * Structural base shared by the three sibling type-entity interfaces
27
+ * ({@link Obj}, {@link Relation}, {@link Type}). NOT exported — callers
28
+ * should constrain on {@link AnyEntity} when they want "any of the three"
29
+ * and on the specific kind interface otherwise.
64
30
  */
65
- interface ObjJsonProps {
66
- id: string;
67
- }
31
+ interface BaseTypeEntity<A> {
32
+ /**
33
+ * Entity-kind brand of the type-entity value itself — always `EntityKind.Type`.
34
+ * The kind of instance the type *describes* lives on `[SchemaKindId]`
35
+ * (Object / Relation / Type). Lets `Obj.isObject` / `Relation.isRelation`
36
+ * reject type entities by a single `[KindId]` check.
37
+ */
38
+ readonly [internal.KindId]: internal.EntityKind.Type;
68
39
 
69
- /**
70
- * JSON-encoded properties for relations.
71
- */
72
- interface RelationJsonProps {
73
- id: string;
74
- [ATTR_RELATION_SOURCE]: string;
75
- [ATTR_RELATION_TARGET]: string;
40
+ /**
41
+ * Object id. Like all ECHO entities, type entities always carry an id —
42
+ * stamped at construction for in-memory (static) declarations and assigned by
43
+ * the database once persisted. The id does NOT determine the entity's URI:
44
+ * static types resolve to their typename DXN, persisted types to `echo:/<id>`
45
+ * (see `getTypeURIFromSpecifier`).
46
+ */
47
+ readonly id: ObjectId;
48
+
49
+ readonly name?: string;
50
+ // NOTE: `typename` / `version` are intentionally NOT fields on any type-entity
51
+ // interface. Both static and persisted entities carry them in `ObjectMeta`
52
+ // (`key` / `version`); read them via `Type.getTypename(self)` /
53
+ // `Type.getVersion(self)` — never as a direct property.
54
+ readonly jsonSchema: internal.JsonSchemaType;
55
+ readonly [InstancePhantomId]?: A;
76
56
  }
77
57
 
78
58
  //
79
- // Obj - Runtime schema for any ECHO object
59
+ // Obj `Type.Type` value for an ECHO object schema.
80
60
  //
81
61
 
82
- // Internal type for the Obj schema constant.
83
- // NOTE: The `any` in the type intersection is intentional - it makes this type bidirectionally
84
- // assignable with specific object types (e.g., Type.Obj can be assigned to/from Meeting.Meeting).
85
- // This is needed because operation schemas erase type information.
86
- // TODO(wittjosiah): Consider alternatives to the `any` intersection hack:
87
- // - Generic operation schemas that preserve input type in output
88
- // - Branded types that specific schemas also carry
89
- // - Accept the limitation and require explicit type narrowing at call sites
90
- type ObjSchemaType = Schema.Schema<
91
- any & AnyEntity & Entity$.OfKind<typeof Entity$.Kind.Object> & AnyProperties,
92
- { id: string } & AnyProperties
93
- > &
94
- EchoSchemaKind<EntityKind.Object> &
95
- TypeMeta;
96
-
97
- // Internal schema definition.
98
- // NOTE: The EchoObjectSchema annotation is required for Type.Ref(Type.Obj) to work.
99
- // The typename/version only satisfy ECHO schema machinery for reference targets.
100
- const ObjSchema = Schema.Struct({
101
- id: Schema.String,
102
- }).pipe(
103
- Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
104
- EchoObjectSchema({ typename: ANY_OBJECT_TYPENAME, version: ANY_OBJECT_VERSION }),
105
- );
106
-
107
- /**
108
- * Runtime Effect schema for any ECHO object.
109
- * Use for validation, parsing, or as a reference target for collections.
110
- *
111
- * NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).
112
- * Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.
113
- *
114
- * @example
115
- * ```ts
116
- * // Structural type guard (accepts any object with id field)
117
- * if (Schema.is(Type.Obj)(unknownValue)) { ... }
62
+ /**
63
+ * TypeScript type for an ECHO object type a `Type.Type<A>` entity.
118
64
  *
119
- * // ECHO instance type guard (checks KindId brand)
120
- * if (Obj.isObject(unknownValue)) { ... }
65
+ * `T` is the instance type produced by `Obj.make(Foo, props)`. `Fields` is
66
+ * retained as a structural hint (the runtime value still carries `.fields`),
67
+ * but consumers should derive instance/encoded types via `Type.InstanceType`.
121
68
  *
122
- * // Reference to any object type
123
- * const Collection = Schema.Struct({
124
- * objects: Schema.Array(Type.Ref(Type.Obj)),
125
- * }).pipe(Type.object({ typename: 'Collection', version: '0.1.0' }));
126
- * ```
127
- */
128
- // TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.
129
- // Effect Schema normalizes proxy objects to plain objects before calling filter predicates.
130
- // Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.
131
- export const Obj: ObjSchemaType = Object.assign(ObjSchema, {
132
- [SchemaKindId]: (ObjSchema as any)[SchemaKindId],
133
- }) as unknown as ObjSchemaType;
134
-
135
- /**
136
- * TypeScript type for an ECHO object schema.
137
- * `T` is the instance type produced by the schema.
138
- * `Fields` is the optional struct fields type for introspection.
69
+ * **Not a `Schema.Schema`.** `Foo.ast` / `Schema.Schema.Type<typeof Foo>` /
70
+ * `Schema.extend(Foo)` no longer typecheck — extract the Effect Schema via
71
+ * `Type.getSchema(Foo)` first, or derive instance types via
72
+ * `Type.InstanceType<typeof Foo>`.
139
73
  *
140
74
  * @example
141
75
  * ```ts
142
- * const PersonSchema: Type.Obj<Person> = Schema.Struct({
76
+ * const Person = Schema.Struct({
143
77
  * name: Schema.String,
144
- * }).pipe(Type.object({ typename: 'Person', version: '0.1.0' }));
78
+ * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));
145
79
  *
146
- * // Access fields for introspection:
147
- * Object.keys(PersonSchema.fields); // ['name']
80
+ * type Person = Type.InstanceType<typeof Person>;
148
81
  * ```
149
82
  */
150
- export interface Obj<T = any, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>
151
- extends TypeMeta,
152
- EchoSchemaKind<EntityKind.Object>,
153
- Schema.AnnotableClass<
154
- Obj<T, Fields>,
155
- Entity$.OfKind<typeof Entity$.Kind.Object> & T,
156
- Schema.Simplify<ObjJsonProps & ToMutable<T>>,
157
- never
158
- > {
83
+ export interface Obj<T, Fields extends Schema.Struct.Fields = Schema.Struct.Fields> extends BaseTypeEntity<
84
+ T & EntityModule.OfKind<typeof EntityModule.Kind.Object>
85
+ > {
86
+ /** Schema-kind brand (object). */
87
+ readonly [internal.SchemaKindId]: internal.EntityKind.Object;
88
+
89
+ /** Source Effect Schema — used internally by `Type.getSchema(self)`. */
90
+ readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;
91
+
159
92
  /**
160
93
  * The fields defined in the original struct schema.
161
94
  * Allows accessing field definitions for introspection.
@@ -164,116 +97,148 @@ export interface Obj<T = any, Fields extends Schema.Struct.Fields = Schema.Struc
164
97
  }
165
98
 
166
99
  /**
167
- * Structural base type for any ECHO object schema.
168
- * Accepts both static schemas (created with Type.object()) and EchoSchema.
169
- * NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.
170
- * Use Type.isObjectSchema() for runtime type guards.
100
+ * Type that represents any ECHO object type — a `Type.Type` entity branded
101
+ * with the object entity kind, i.e. what `Type.makeObject(dxn)` produces.
171
102
  */
172
- type ObjectSchemaBase = Schema.Schema.AnyNoContext & {
173
- readonly typename: string;
174
- readonly version: string;
175
- };
176
-
177
- export namespace Obj {
178
- /**
179
- * Type that represents any ECHO object schema.
180
- * Accepts both static schemas (Type.object()) and mutable schemas (EchoSchema).
181
- */
182
- export type Any = ObjectSchemaBase;
183
- }
103
+ export type AnyObj = Obj<unknown>;
184
104
 
185
105
  /**
186
- * Factory function to create an ECHO object schema.
187
- * Adds object metadata annotations to an Effect schema.
106
+ * Factory function to create an ECHO object type.
107
+ *
108
+ * Returns a `Type.Type` entity — a live, in-memory `TypeSchema` instance,
109
+ * NOT a `Schema.Schema`. Use `Type.InstanceType<typeof Foo>` for the instance
110
+ * type and `Type.getSchema(Foo)` to obtain the underlying Effect Schema.
188
111
  *
189
112
  * @example
190
113
  * ```ts
191
114
  * const Person = Schema.Struct({
192
115
  * name: Schema.String,
193
- * }).pipe(Type.object({ typename: 'example.com/type/Person', version: '0.1.0' }));
116
+ * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));
194
117
  * ```
195
118
  */
196
- export const object: {
197
- (opts: TypeMeta): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;
198
- } = EchoObjectSchema as any;
119
+ export const makeObject: {
120
+ (dxn: DXN.DXN): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;
121
+ } = internal.EchoObjectSchema as any;
199
122
 
200
123
  //
201
- // PersistentType (Schema stored in database)
124
+ // Type the ECHO entity that holds a schema and metadata.
125
+ // Persisted via `db.add()`; subscribed to via `Filter.type(Type.Type)`.
202
126
  //
203
127
 
204
- export const PersistentType: Obj<PersistentSchema> = PersistentSchema as any;
205
-
206
- export interface PersistentType extends Schema.Schema.Type<typeof PersistentType> {}
128
+ /**
129
+ * ECHO meta-schema entity — stores `{ name?, typename, version, jsonSchema }`.
130
+ * Type-kind sibling of `Type.makeObject(...)` / `Type.makeRelation(...)` outputs.
131
+ * Stored types live under this entity; filter via `Filter.type(Type.Type)`.
132
+ */
133
+ export const Type: Type<typeInternal.TypeSchema> = typeInternal.TypeSchema as any;
207
134
 
208
- export { EchoSchema as RuntimeType };
135
+ /**
136
+ * Default version stamped on draft (unnamed) types created via
137
+ * {@link makeObjectFromJsonSchema} / {@link makeRelationFromJsonSchema} when
138
+ * the caller does not supply one. Pure dynamic drafts surface as `'0.0.0'`
139
+ * until they are persisted, at which point automerge-heads suffix the version.
140
+ */
141
+ const DRAFT_VERSION = '0.0.0';
209
142
 
210
- //
211
- // Relation - Runtime schema for any ECHO relation
212
- //
143
+ /**
144
+ * Common props shared by the type-kind factories. Typename and version are
145
+ * optional — drafts omit typename and default version to {@link DRAFT_VERSION}.
146
+ */
147
+ type MakeTypeProps = {
148
+ jsonSchema: internal.JsonSchemaType;
149
+ typename?: string;
150
+ version?: string;
151
+ name?: string;
152
+ id?: ObjectId;
153
+ };
213
154
 
214
- // Internal type for the Relation schema constant.
215
- type RelationSchemaType = Schema.Schema<
216
- { id: ObjectId } & Record<string, unknown>,
217
- { id: string } & Record<string, unknown>
218
- > &
219
- EchoSchemaKind<EntityKind.Relation> &
220
- TypeMeta;
221
-
222
- // Internal schema definition.
223
- // NOTE: The EchoRelationSchema annotation is required for Type.Ref(Type.Relation) to work.
224
- // The typename/version/source/target only satisfy ECHO schema machinery for reference targets.
225
- const RelationSchema = Schema.Struct({
226
- id: Schema.String,
227
- }).pipe(
228
- Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
229
- EchoRelationSchema({
230
- typename: 'dxos.org/schema/AnyRelation',
231
- version: '0.0.0',
232
- source: ObjSchema,
233
- target: ObjSchema,
234
- }),
235
- );
236
-
237
- /**
238
- * Runtime Effect schema for any ECHO relation.
239
- * Use for validation, parsing, or as a reference target for collections.
240
- * A relation has `id`, source, and target fields plus any additional properties.
241
- *
242
- * NOTE: `Schema.is(Type.Relation)` does STRUCTURAL validation only (checks for `id` field).
243
- * Use `Relation.isRelation()` for proper ECHO instance type guards that check the KindId brand.
155
+ /**
156
+ * Construct a new object-kind type entity from raw metadata — for cases where
157
+ * an Effect Schema isn't available (e.g. JSON-Schema arriving over the network
158
+ * or from a UI editor). Parallel to {@link makeObject} but takes pre-built
159
+ * `jsonSchema` instead of piping through an Effect schema.
244
160
  *
245
- * @example
246
- * ```ts
247
- * // Structural type guard (accepts any object with id field)
248
- * if (Schema.is(Type.Relation)(unknownValue)) { ... }
161
+ * The returned entity is in-memory; persist it with `db.add(entity)`.
162
+ */
163
+ export const makeObjectFromJsonSchema = (props: MakeTypeProps): Type<typeInternal.TypeSchema> => {
164
+ const { typename, version, ...data } = props;
165
+ // `typename` / `version` are routed through `ObjectMeta` (`key` / `version`)
166
+ // — the canonical registry-provenance pair — not data fields. Drafts default
167
+ // to `'0.0.0'`; the version is omitted from meta entirely when the caller
168
+ // doesn't supply one so the proxy projection can apply its own default.
169
+ return internal.makeObject(
170
+ internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,
171
+ data as any,
172
+ {
173
+ keys: [],
174
+ key: typename,
175
+ version: version ?? DRAFT_VERSION,
176
+ },
177
+ typeInternal.TypeSchema,
178
+ ) as unknown as Type<typeInternal.TypeSchema>;
179
+ };
180
+
181
+ /**
182
+ * Construct a new relation-kind type entity from raw metadata. Parallel to
183
+ * {@link makeRelation} but takes pre-built `jsonSchema` instead of piping
184
+ * through an Effect schema. `source` / `target` accept either a static
185
+ * `Type.Obj` entity or the well-known `Obj.Unknown` schema.
249
186
  *
250
- * // ECHO instance type guard (checks KindId brand)
251
- * if (Relation.isRelation(unknownValue)) { ... }
252
- * ```
187
+ * The returned entity is in-memory; persist it with `db.add(entity)`.
253
188
  */
254
- export const Relation: RelationSchemaType = Object.assign(RelationSchema, {
255
- [SchemaKindId]: (RelationSchema as any)[SchemaKindId],
256
- }) as unknown as RelationSchemaType;
189
+ export const makeRelationFromJsonSchema = (
190
+ props: MakeTypeProps & {
191
+ source: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;
192
+ target: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;
193
+ },
194
+ ): Type<typeInternal.TypeSchema> => {
195
+ const { source, target, jsonSchema, typename, version, ...rest } = props;
196
+ // Embed source/target DXNs + relation entity-kind into the jsonSchema so the
197
+ // entity round-trips correctly through `toEffectSchema` / queries / refs.
198
+ const sourceURI = internal.getTypeURIFromSpecifier(source);
199
+ const targetURI = internal.getTypeURIFromSpecifier(target);
200
+ const enrichedJsonSchema: internal.JsonSchemaType = {
201
+ ...jsonSchema,
202
+ entityKind: internal.EntityKind.Relation,
203
+ relationSource: { $ref: sourceURI },
204
+ relationTarget: { $ref: targetURI },
205
+ };
206
+ // `typename` / `version` route through `ObjectMeta` (see
207
+ // {@link makeObjectFromJsonSchema}); drafts default version to `'0.0.0'`.
208
+ return internal.makeObject(
209
+ internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,
210
+ { ...rest, jsonSchema: enrichedJsonSchema } as any,
211
+ {
212
+ keys: [],
213
+ key: typename,
214
+ version: version ?? DRAFT_VERSION,
215
+ },
216
+ typeInternal.TypeSchema,
217
+ ) as unknown as Type<typeInternal.TypeSchema>;
218
+ };
257
219
 
258
220
  /**
259
- * TypeScript type for an ECHO relation schema.
260
- * `T` is the instance type produced by the schema (excluding source/target).
261
- * `Source` and `Target` are the endpoint types.
262
- * `Fields` is the optional struct fields type for introspection.
221
+ * TypeScript type for an ECHO relation type — a `Type.Type<A>` entity.
222
+ *
223
+ * `T` is the instance-property type produced by `Relation.make(...)` (excluding
224
+ * source/target endpoints). `Source` and `Target` are the endpoint types.
225
+ *
226
+ * **Not a `Schema.Schema`.** See {@link Obj}'s note.
263
227
  */
264
228
  export interface Relation<
265
- T = any,
266
- Source = any,
267
- Target = any,
229
+ T,
230
+ Source,
231
+ Target,
268
232
  Fields extends Schema.Struct.Fields = Schema.Struct.Fields,
269
- > extends TypeMeta,
270
- EchoSchemaKind<EntityKind.Relation>,
271
- Schema.AnnotableClass<
272
- Relation<T, Source, Target, Fields>,
273
- Entity$.OfKind<typeof Entity$.Kind.Relation> & Relation.Endpoints<Source, Target> & T,
274
- Schema.Simplify<RelationJsonProps & ToMutable<T>>,
275
- never
276
- > {
233
+ > extends BaseTypeEntity<
234
+ RelationModule.Endpoints<Source, Target> & T & EntityModule.OfKind<typeof EntityModule.Kind.Relation>
235
+ > {
236
+ /** Schema-kind brand (relation). */
237
+ readonly [internal.SchemaKindId]: internal.EntityKind.Relation;
238
+
239
+ /** Source Effect Schema — used internally by `Type.getSchema(self)`. */
240
+ readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;
241
+
277
242
  /**
278
243
  * The fields defined in the original struct schema.
279
244
  * Allows accessing field definitions for introspection.
@@ -282,38 +247,10 @@ export interface Relation<
282
247
  }
283
248
 
284
249
  /**
285
- * Structural base type for any ECHO relation schema.
286
- * Accepts static schemas (created with Type.relation()).
287
- * NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.
288
- * Use Type.isRelationSchema() for runtime type guards.
250
+ * Type that represents any ECHO relation type — a `Type.Type` entity branded
251
+ * with the relation entity kind, i.e. what `Type.makeRelation(...)` produces.
289
252
  */
290
- type RelationSchemaBase = Schema.Schema.AnyNoContext & {
291
- readonly typename: string;
292
- readonly version: string;
293
- };
294
-
295
- export namespace Relation {
296
- /**
297
- * Type that represents any ECHO relation schema.
298
- * Accepts static schemas (Type.relation()).
299
- */
300
- export type Any = RelationSchemaBase;
301
-
302
- /**
303
- * Get relation source type.
304
- */
305
- export type Source<A> = A extends Relation.Endpoints<infer S, infer _T> ? S : never;
306
-
307
- /**
308
- * Get relation target type.
309
- */
310
- export type Target<A> = A extends Relation.Endpoints<infer _S, infer T> ? T : never;
311
-
312
- export type Endpoints<Source, Target> = {
313
- [Relation$.Source]: Source;
314
- [Relation$.Target]: Target;
315
- };
316
- }
253
+ export type AnyRelation = Relation<unknown, unknown, unknown>;
317
254
 
318
255
  /**
319
256
  * Factory function to create an ECHO relation schema.
@@ -323,170 +260,440 @@ export namespace Relation {
323
260
  * ```ts
324
261
  * const WorksFor = Schema.Struct({
325
262
  * role: Schema.String,
326
- * }).pipe(Type.relation({
327
- * typename: 'example.com/type/WorksFor',
328
- * version: '0.1.0',
263
+ * }).pipe(Type.makeRelation({
264
+ * dxn: DXN.make('com.example.type.worksFor', '0.1.0'),
329
265
  * source: Person,
330
266
  * target: Company,
331
267
  * }));
332
268
  * ```
333
269
  */
334
- export const relation: {
335
- <SourceSchema extends Schema.Schema.AnyNoContext, TargetSchema extends Schema.Schema.AnyNoContext>(
336
- opts: EchoRelationSchemaOptions<SourceSchema, TargetSchema>,
337
- ): <Self extends Schema.Schema.Any>(
270
+ export const makeRelation: {
271
+ <SourceInstance, TargetInstance>(opts: {
272
+ dxn: DXN.DXN;
273
+ source: Obj<SourceInstance, any> | internal.UnknownTypeSchema<SourceInstance, typeof EntityModule.Kind.Object>;
274
+ target: Obj<TargetInstance, any> | internal.UnknownTypeSchema<TargetInstance, typeof EntityModule.Kind.Object>;
275
+ }): <Self extends Schema.Schema.Any>(
338
276
  self: Self,
339
- ) => Relation<Schema.Schema.Type<Self>, Schema.Schema.Type<SourceSchema>, Schema.Schema.Type<TargetSchema>>;
340
- } = EchoRelationSchema as any;
277
+ ) => Relation<
278
+ Schema.Schema.Type<Self>,
279
+ SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,
280
+ TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>
281
+ >;
282
+ } = internal.EchoRelationSchema as any;
341
283
 
342
- //
343
- // Entity - Entity schema types (union of Object | Relation)
344
- //
284
+ /**
285
+ * Type that represents any ECHO type-kind entity a `Type.Type` meta-schema
286
+ * value (static `Type.Type` or a persisted draft from `db.add(...)`).
287
+ * Mirrors {@link AnyObj} / {@link AnyRelation} for the third sibling kind.
288
+ */
289
+ export type AnyType = Type<unknown>;
345
290
 
346
- export namespace Entity {
347
- /**
348
- * Runtime Effect schema for any ECHO entity (object or relation).
349
- * Use for validation, parsing, or type guards on unknown values.
350
- *
351
- * @example
352
- * ```ts
353
- * if (Schema.is(Type.Entity.Any)(unknownValue)) {
354
- * // unknownValue is an ECHO entity
355
- * }
356
- * ```
357
- */
358
- export const Any: Schema.Schema<
359
- { id: ObjectId } & Record<string, unknown>,
360
- { id: string } & Record<string, unknown>
361
- > = Schema.Union(Obj, Relation);
291
+ /**
292
+ * Any ECHO type-entity — one of the three sibling kinds: object-kind, relation-kind,
293
+ * or type-kind (the meta-schema). APIs that want "any ECHO type" use this union;
294
+ * the underlying Effect Schema is retrieved via `Type.getSchema`.
295
+ */
296
+ export type AnyEntity = AnyObj | AnyRelation | AnyType;
362
297
 
363
- /**
364
- * Type alias for any ECHO entity schema (object or relation).
365
- * Use this in type annotations for schema parameters.
366
- */
367
- export type Any = Obj.Any | Relation.Any;
368
- }
298
+ /**
299
+ * Type guard: narrows a `Type.AnyEntity` to an object-kind entity. Checks
300
+ * ENTITIES, not instances use `Obj.isObject` for instances. Raw
301
+ * `Schema.Schema` values (including the branded `Obj.Unknown` companion)
302
+ * are intentionally not accepted; inspect their `TypeAnnotation` directly.
303
+ */
304
+ export const isObject = (entity: AnyEntity): entity is AnyObj => {
305
+ return internal.getSchemaKind(entity) === internal.EntityKind.Object;
306
+ };
369
307
 
370
308
  /**
371
- * Type guard to check if a schema is an object schema.
372
- * NOTE: This checks SCHEMAS, not instances. Use Obj.isObject for instances.
309
+ * Type guard: narrows a `Type.AnyEntity` to a relation-kind entity. Checks
310
+ * ENTITIES, not instances use `Relation.isRelation` for instances.
373
311
  */
374
- export const isObjectSchema = (schema: Entity.Any): schema is Obj.Any => {
375
- return (schema as any)[SchemaKindId] === EntityKind.Object;
312
+ export const isRelation = (entity: AnyEntity): entity is AnyRelation => {
313
+ return internal.getSchemaKind(entity) === internal.EntityKind.Relation;
376
314
  };
377
315
 
378
316
  /**
379
- * Type guard to check if a schema is a relation schema.
380
- * NOTE: This checks SCHEMAS, not instances. Use Relation.isRelation for instances.
317
+ * Type guard: narrows a `Type.AnyEntity` to the type-kind meta-schema
318
+ * (e.g. `Type.Type`). Mirrors {@link isObject} / {@link isRelation}.
381
319
  */
382
- export const isRelationSchema = (schema: Entity.Any): schema is Relation.Any => {
383
- return (schema as any)[SchemaKindId] === EntityKind.Relation;
320
+ export const isTypeKindSchema = (entity: AnyEntity): entity is Type => {
321
+ return internal.getSchemaKind(entity) === internal.EntityKind.Type;
384
322
  };
385
323
 
324
+ /**
325
+ * Narrow a `Type.AnyEntity` (e.g. one returned from `schemaRegistry.query(...)`)
326
+ * to `AnyObj`, throwing if it describes a relation or the type-kind
327
+ * meta-schema. Use at call sites that need to pass the value to `Obj.make`,
328
+ * `Filter.type`, or other object-only APIs.
329
+ */
330
+ export const assertObject = (entity: AnyEntity): AnyObj => {
331
+ invariant(isObject(entity), 'Expected an object-kind Type entity.');
332
+ return entity;
333
+ };
334
+
335
+ /** Narrow a `Type.AnyEntity` to `AnyRelation`, throwing otherwise. */
336
+ export const expectRelation = (entity: AnyEntity): AnyRelation => {
337
+ invariant(isRelation(entity), 'Expected a relation-kind Type entity.');
338
+ return entity;
339
+ };
340
+
341
+ /** Narrow a `Type.AnyEntity` to the `Type.Type` meta-schema, throwing otherwise. */
342
+ export const expectTypeKind = (entity: AnyEntity): Type => {
343
+ invariant(isTypeKindSchema(entity), 'Expected a type-kind Type entity.');
344
+ return entity;
345
+ };
346
+
347
+ /**
348
+ * Type that represents any Ref schema (with unknown target type).
349
+ * This is a schema type, not an instance type.
350
+ */
351
+ export type AnyRef = Schema.Schema<internal.Ref<any>, EncodedReference>;
352
+
386
353
  //
387
- // Ref
388
- //
389
- // NOTE: `Type.Ref` vs `Ref.Ref`:
390
- // - `Type.Ref<T>` is the SCHEMA type - a schema that produces `Ref.Ref<T>` instances.
391
- // - `Ref.Ref<T>` is the INSTANCE type - the actual runtime ref object.
392
- //
393
- // Example:
394
- // const taskRef: Ref.Ref<Task> = Ref.make(task); // Instance
395
- // const schema: Type.Ref<Task> = Type.Ref(Task); // Schema
354
+ // Schema utility functions
396
355
  //
397
356
 
398
357
  /**
399
- * Return type of the `Ref` schema constructor.
358
+ * Returns the URI identifying a type entity. Always defined.
359
+ *
360
+ * - Static `Type.Obj` / `Type.Relation` → typename DXN (e.g. `dxn:com.example.type.person:0.1.0`).
361
+ * - Persisted `Type.Type` instance (has `id`) → local `EchoURI` (`echo:/<objectId>`).
362
+ * - In-memory `Type.Type` draft (has `id`, no typename) → local `EchoURI`.
400
363
  *
401
- * This typedef avoids `TS4023` error (name from external module cannot be used named).
402
- * See Effect's note on interface types.
364
+ * Only accepts `Type.AnyEntity` entities. Raw `Schema.Schema` values and the
365
+ * branded `Obj.Unknown` / `Relation.Unknown` schemas are intentionally not
366
+ * supported — use `internal.getSchemaURI` or the schema's typename annotation
367
+ * directly when working at the schema level.
403
368
  */
404
- export interface ref<TargetSchema extends Schema.Schema.Any> extends RefSchema<Schema.Schema.Type<TargetSchema>> {}
369
+ export const getURI = (input: AnyEntity): URI.URI => {
370
+ // For Type entities, route through `getTypeURIFromSpecifier` (id → EchoURI,
371
+ // typename/version → DXN). For Obj/Relation entities, unwrap to the source
372
+ // Effect Schema first and read its annotations.
373
+ if (isType(input)) {
374
+ return internal.getTypeURIFromSpecifier(input);
375
+ }
376
+ return internal.getSchemaURI(getSchema(input)) ?? raise(new TypeError('Type entity has no URI'));
377
+ };
405
378
 
406
379
  /**
407
- * Factory function to create a Ref schema for the given target schema.
408
- * Use this in schema definitions to declare reference fields.
380
+ * @returns The typename. Example: `com.example.type.person`.
409
381
  *
410
- * @example
411
- * ```ts
412
- * const Task = Schema.Struct({
413
- * assignee: Type.Ref(Person), // Creates a Ref schema
414
- * }).pipe(Type.object({ typename: 'Task', version: '0.1.0' }));
415
- * ```
382
+ * Persisted `Type.Type` entities carry typename in `ObjectMeta.key` (the
383
+ * canonical registry-provenance field); unnamed drafts fall back to the
384
+ * entity's object id so the helper always returns a string. Any `dxn:` or
385
+ * `echo:/` prefix is stripped — typename is a bare identifier, not a URI.
416
386
  */
417
- export const Ref: RefFn = Ref$;
387
+ // TODO(wittjosiah): For in-database types this should return the object id once the registry
388
+ // has more robust options for shadowing types (so callers can disambiguate db-stored copies).
389
+ export const getTypename = (input: AnyEntity): string => {
390
+ // Both in-memory and in-database entities carry typename in `ObjectMeta.key`
391
+ // — the canonical registry-provenance field. In-memory entities attach meta
392
+ // eagerly (see `makeEchoTypeSchema`), so a single meta-backed read covers
393
+ // both forms. Unnamed drafts fall back to the entity id.
394
+ const meta = internal.getMetaChecked(input);
395
+ let typename: string = (meta.key as string | undefined) ?? (input.id as string);
396
+ // Typename is a bare identifier — strip URI prefixes if a caller seeded
397
+ // meta.key with one accidentally (or if a static entity carries a DXN-
398
+ // style typename).
399
+ typename = stripTypenamePrefix(typename);
400
+ invariant(typeof typename === 'string' && typename.length > 0, 'Invalid typename');
401
+ return typename;
402
+ };
418
403
 
419
404
  /**
420
- * TypeScript type for a Ref schema.
421
- * This is the type of the SCHEMA itself, not the runtime ref instance.
422
- * For the instance type, use `Ref.Ref<T>` from the Ref module.
405
+ * Gets the version.
406
+ * @example 0.1.0
407
+ * @example 0.1.0-<heads> (in-database, versioned by automerge heads)
423
408
  *
424
- * @example
425
- * ```ts
426
- * // Schema type annotation (rarely needed, usually inferred):
427
- * const refSchema: Type.Ref<Task> = Type.Ref(Task);
409
+ * The registry-provenance semver lives in `ObjectMeta.version`; unversioned
410
+ * drafts default to {@link DRAFT_VERSION} (`'0.0.0'`). In-database entities are
411
+ * additionally versioned by their automerge heads, which are exposed as the
412
+ * semver pre-release tag (`<semver>-<heads>`). In-memory declarations have no
413
+ * heads and surface the bare semver. Read the registry semver alone via
414
+ * `Type.getMeta(input).version`.
415
+ */
416
+ export const getVersion = (input: AnyEntity): string => {
417
+ const meta = internal.getMetaChecked(input);
418
+ const semver = (meta.version as string | undefined) ?? DRAFT_VERSION;
419
+ invariant(typeof semver === 'string' && semver.match(/^\d+\.\d+\.\d+$/), 'Invalid version');
420
+ // In-database entities are versioned by their automerge heads; expose them as
421
+ // the semver pre-release tag. In-memory drafts carry no heads → bare semver.
422
+ const heads = internal.version(input).automergeHeads;
423
+ if (heads != null && heads.length > 0) {
424
+ return `${semver}-${[...heads].sort().join('.')}`;
425
+ }
426
+ return semver;
427
+ };
428
+
429
+ /**
430
+ * Strip URI prefixes (`dxn:`, `echo:/`, `echo://`) from a typename string.
431
+ * Typename is a bare identifier — callers reading from meta or from a
432
+ * caller-supplied seed value shouldn't propagate URI prefixes downstream.
433
+ */
434
+ const stripTypenamePrefix = (value: string): string => {
435
+ if (value.startsWith('dxn:')) {
436
+ return value.slice('dxn:'.length);
437
+ }
438
+ if (value.startsWith('echo://')) {
439
+ return value.slice('echo://'.length);
440
+ }
441
+ if (value.startsWith('echo:/')) {
442
+ return value.slice('echo:/'.length);
443
+ }
444
+ return value;
445
+ };
446
+
447
+ /**
448
+ * Type predicate: true iff the value is any type-kind ECHO entity — a static
449
+ * `Type.Obj` / `Type.Relation` produced by `Type.makeObject` / `Type.makeRelation`, a
450
+ * static meta `Type.Type`, or a persisted `Type.Type` returned by the database.
428
451
  *
429
- * // Instance type annotation (use Ref.Ref instead):
430
- * const refInstance: Ref.Ref<Task> = Ref.make(task);
431
- * ```
452
+ * All three branches stamp `[KindId] = Type`, so this is a single brand check.
453
+ * Use {@link isObject} / {@link isRelation} / {@link isTypeKindSchema}
454
+ * when you need to discriminate further; use {@link getDatabase} when you mean
455
+ * "is this a db-attached type" (vs. an in-memory declaration).
432
456
  */
433
- export interface Ref<T> extends Schema.SchemaClass<Ref$<T>, EncodedReference> {}
457
+ export const isType = (value: unknown): value is AnyEntity =>
458
+ internal.getEntityKindBrand(value) === internal.EntityKind.Type;
434
459
 
435
- export namespace Ref {
436
- /**
437
- * Type that represents any Ref schema (with unknown target type).
438
- * This is a schema type, not an instance type.
439
- */
440
- export type Any = Schema.Schema<Ref$<any>, EncodedReference>;
460
+ /**
461
+ * Get the database the type entity belongs to, or `undefined` if it is an
462
+ * in-memory declaration (`Type.makeObject` / `Type.makeRelation` result) not
463
+ * yet attached to a database. Mirrors `Obj.getDatabase` / `Relation.getDatabase`.
464
+ *
465
+ * Database attachment is the canonical discriminator between in-memory and
466
+ * in-database type entities — both are live reactive `TypeSchema` instances and
467
+ * are otherwise indistinguishable.
468
+ */
469
+ export const getDatabase = (input: AnyEntity): Database.Database | undefined => internal.getDatabase(input);
470
+
471
+ /**
472
+ * Mutable meta type returned by `Type.getMeta` inside a `Type.update` callback.
473
+ * Mirrors `Obj.Meta` / `Relation.Meta` — `Type.Type` is an Entity like its
474
+ * siblings, so its meta is the same `ObjectMeta` record:
475
+ * `{ keys, tags?, key?, version? }`.
476
+ *
477
+ * `key` / `version` here are the canonical registry-provenance pair
478
+ * (typename + semver) on persisted Type.Type entities; they are absent on
479
+ * unnamed drafts. Use {@link getTypename} / {@link getVersion} when you want
480
+ * a non-`undefined` value with id / {@link DRAFT_VERSION} fallbacks.
481
+ */
482
+ export type Meta = internal.Meta;
483
+
484
+ /**
485
+ * Deeply read-only version of {@link Meta}.
486
+ * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TS error).
487
+ */
488
+ export type ReadonlyMeta = internal.ReadonlyMeta;
489
+
490
+ /**
491
+ * Returns the entity's `ObjectMeta`. Same semantics as `Obj.getMeta` /
492
+ * `Relation.getMeta` — `Type.Type` is an Entity and carries the canonical
493
+ * `ObjectMeta` directly. Returns mutable meta when passed a mutable type
494
+ * (inside a `Type.update` callback), read-only meta otherwise.
495
+ *
496
+ * For persisted Type entities, `meta.key` holds the typename and
497
+ * `meta.version` holds the semver. Use {@link getTypename} / {@link getVersion}
498
+ * if you want the helpers' id / {@link DRAFT_VERSION} fallbacks for drafts.
499
+ *
500
+ * Both persisted and in-memory type entities (`Type.makeObject` /
501
+ * `Type.makeRelation` results) carry their `ObjectMeta` via `[MetaId]`, so the
502
+ * lookup is uniform.
503
+ */
504
+ export function getMeta(entity: internal.Mutable<AnyEntity>): Meta;
505
+ export function getMeta(entity: Mutable): Meta;
506
+ export function getMeta(entity: AnyEntity): ReadonlyMeta;
507
+ export function getMeta(entity: AnyEntity | internal.Mutable<AnyEntity> | Mutable): ReadonlyMeta | Meta {
508
+ // The `Mutable` overload accepts the narrowed view passed to `Type.update`
509
+ // callbacks; at runtime that draft IS the underlying persisted Type entity,
510
+ // so the same `MetaId` lookup works.
511
+ invariant(isType(entity), 'Expected a Type entity.');
512
+ // Both persisted and in-memory type entities carry runtime `ObjectMeta` via
513
+ // `[MetaId]`, so the lookup is uniform.
514
+ return internal.getMetaChecked(entity);
441
515
  }
442
516
 
443
- //
444
- // Schema utility functions
445
- //
517
+ /**
518
+ * String key used to phantom-carry the instance type produced by a `Type.Type`.
519
+ * Used by `Type.InstanceType<typeof Foo>` to recover the schema instance type
520
+ * since `Type.makeObject(dxn)` does not return a `Schema.Schema`.
521
+ *
522
+ * Re-exported from the internal types layer so both `Type.ts` and internal
523
+ * helpers (`makeObject`, `createObject`) reference the same phantom key.
524
+ */
525
+ export const InstancePhantomId = internal.InstancePhantomId;
526
+ export type InstancePhantomId = internal.InstancePhantomId;
446
527
 
447
528
  /**
448
- * Gets the full DXN of the schema.
449
- * Will include the version if it's a `type` DXN.
450
- * @example "dxn:example.com/type/Person:0.1.0"
451
- * @example "dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX"
529
+ * Sibling of {@link Obj} / {@link Relation} for the third ECHO entity kind:
530
+ * **type-kind** entities (meta-schemas). The singleton {@link Type} const is
531
+ * the canonical example — it describes stored type definitions themselves.
532
+ *
533
+ * Not a `Schema.Schema`. Use `Type.getSchema(value)` to obtain the underlying
534
+ * Effect Schema and `Type.update(value, draft => ...)` to mutate.
535
+ *
536
+ * `A` is the instance-type phantom — what `Obj.make(value, ...)` would produce.
537
+ * Merged with the `Type` const value via TypeScript declaration merging.
452
538
  */
453
- export const getDXN = (schema: Entity.Any): DXN | undefined => {
454
- return getSchemaDXN(schema);
455
- };
539
+ export interface Type<A = unknown> extends BaseTypeEntity<A & EntityModule.OfKind<typeof EntityModule.Kind.Type>> {
540
+ /** Schema-kind brand (type — the meta-schema kind). */
541
+ readonly [internal.SchemaKindId]: internal.EntityKind.Type;
542
+
543
+ /** Source Effect Schema — used internally by `Type.getSchema(self)`. */
544
+ readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;
545
+ }
456
546
 
457
547
  /**
458
- * @param schema - Schema to get the typename from.
459
- * @returns The typename of the schema. Example: `example.com/type/Person`.
548
+ * Instance type produced by a Type entity.
549
+ *
550
+ * Accepts ONLY {@link AnyEntity} inputs — `Type.Obj`, `Type.Relation`, or
551
+ * `Type.Type`. Raw Effect `Schema.Schema` values are rejected: for those, use
552
+ * `Schema.Schema.Type<typeof Foo>` directly. This separation keeps the type
553
+ * system honest about which values represent ECHO entities versus plain
554
+ * Effect schemas.
555
+ *
556
+ * Dispatches on the entity kind:
557
+ * - `Relation<Props, S, T>` → `Endpoints<S,T> & Props & OfKind<Relation>`
558
+ * - `Obj<A>` → `A & OfKind<Object>`
559
+ * - `Type<A>` → `A & OfKind<Type>`
460
560
  */
461
- export const getTypename = (schema: Entity.Any): string => {
462
- const typename = getSchemaTypename(schema);
463
- invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');
464
- return typename;
561
+ export type InstanceType<T extends AnyEntity> =
562
+ T extends Relation<infer Props, infer Source, infer Target, any>
563
+ ? RelationModule.Endpoints<Source, Target> & Props & EntityModule.OfKind<typeof EntityModule.Kind.Relation>
564
+ : T extends Obj<infer A, any>
565
+ ? A & EntityModule.OfKind<typeof EntityModule.Kind.Object>
566
+ : T extends Type<infer A>
567
+ ? A & EntityModule.OfKind<typeof EntityModule.Kind.Type>
568
+ : never;
569
+
570
+ /**
571
+ * Returns the Effect Schema for a type entity.
572
+ *
573
+ * - For static `Type.Obj` / `Type.Relation` entities the source Effect Schema is
574
+ * read from a hidden slot — these overloads preserve the instance type.
575
+ * - For `Type.Type` entities (the meta-schema kind) the schema is rebuilt from
576
+ * `type.jsonSchema`; the instance type isn't statically knowable so the wide
577
+ * `AnyEntity` overload widens to `Schema.Schema.AnyNoContext`.
578
+ *
579
+ * Always call this when you need to interact with the Effect Schema API
580
+ * (e.g. before passing to Effect.Schema functions). For ECHO-side APIs
581
+ * (`Obj.make`, `Filter.type`, `Ref`) pass the type entity directly.
582
+ *
583
+ * Only accepts `Type.AnyEntity` — raw `Schema.Schema` values can be used
584
+ * directly without unwrapping.
585
+ */
586
+ export function getSchema<T extends AnyObj>(type: T): Schema.Schema<InstanceType<T>>;
587
+ export function getSchema<T extends AnyRelation>(type: T): Schema.Schema<InstanceType<T>>;
588
+ export function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext;
589
+ export function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext {
590
+ // Static `Type.Type` entities carry the source Effect Schema on a hidden
591
+ // slot so we can return it without round-tripping through JsonSchema.
592
+ const staticSchema = internal.getStaticTypeSchema(type);
593
+ if (staticSchema != null) {
594
+ return staticSchema;
595
+ }
596
+ invariant(isType(type), 'Expected a Type entity.');
597
+ // Persisted `Type.Type` entity — build the Effect Schema from its stored
598
+ // jsonSchema and re-attach the TypeIdentifierAnnotation so the rebuilt
599
+ // schema's URI (via getSchemaURI) matches the entity's local EchoURI.
600
+ const rebuilt = internal.toEffectSchema(type.jsonSchema);
601
+ if (typeof type.id === 'string') {
602
+ return rebuilt.annotations({
603
+ [internal.TypeIdentifierAnnotationId]: EchoURI.make({ objectId: type.id }),
604
+ });
605
+ }
606
+ return rebuilt;
607
+ }
608
+
609
+ /**
610
+ * Mutable view of a `Type.Type` — the shape passed to the `Type.update` callback.
611
+ * Outside `Type.update`, `Type.Type` fields are read-only (both at the type level
612
+ * and at runtime — direct assignment throws). Use this to constrain mutation to
613
+ * the change context, analogous to `Obj.update(obj, (draft) => ...)`.
614
+ *
615
+ * NOTE: `typename` and `version` are intentionally absent — they live in
616
+ * `ObjectMeta` (`key` / `version` — the canonical registry-provenance pair).
617
+ * Read them via {@link getTypename} / {@link getVersion} / {@link getMeta};
618
+ * `typename` is treated as immutable on persisted entities.
619
+ *
620
+ * Unlike `Obj.update` — whose mutable view is inferred as `Mutable<A>` over the
621
+ * whole instance type because every data field is editable — a `Type.Type`
622
+ * exposes only `name` and `jsonSchema` for mutation. The rest of its shape
623
+ * (`id`, the `[KindId]` / `[SchemaKindId]` brands, and `typename` / `version`
624
+ * in meta) is immutable, so this view is declared explicitly rather than
625
+ * derived from `InstanceType<Type.Type>`.
626
+ */
627
+ export interface Mutable {
628
+ name?: string;
629
+ // Deep-mutable within the change context — `Type.update`'s purpose is to allow
630
+ // mutation, so the draft exposes `jsonSchema` as writable (the readonly
631
+ // `JsonSchemaType` would force callers to cast).
632
+ jsonSchema: Types.DeepMutable<internal.JsonSchemaType>;
633
+ }
634
+
635
+ /**
636
+ * Perform mutations on a `Type.Type` within a change context.
637
+ *
638
+ * The callback receives a {@link Mutable} view of the type — direct mutation of
639
+ * a `Type.Type` outside `Type.update` throws at runtime, mirroring `Obj.update`.
640
+ * Delegates to the same automerge-transaction primitive `Obj.update(obj, cb)` uses.
641
+ */
642
+ export const update = (type: AnyEntity, callback: (mutable: Mutable) => void): void => {
643
+ // `Type.Type` is an ECHO object; the change machinery is the same as `Obj.update`.
644
+ internal.change(type, callback as internal.ChangeCallback<AnyEntity>);
465
645
  };
466
646
 
647
+ //
648
+ // Field-level helpers for mutating persisted types.
649
+ // These are thin wrappers over `Type.update` plus the JsonSchema manipulation
650
+ // utilities. Callers pass a persisted `Type.Type` (e.g. one returned by
651
+ // `DatabaseSchemaRegistry.register`) and the helper drives the change context.
652
+ //
653
+
467
654
  /**
468
- * Gets the version of the schema.
469
- * @example 0.1.0
655
+ * Add fields to a persisted type's schema.
656
+ * @throws if the type is not persisted.
470
657
  */
471
- export const getVersion = (schema: Entity.Any): string => {
472
- const version = getSchemaVersion(schema);
473
- invariant(typeof version === 'string' && version.match(/^\d+\.\d+\.\d+$/), 'Invalid version');
474
- return version;
658
+ export const addFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {
659
+ const extended = typeInternal.addFieldsToSchema(getSchema(type), fields);
660
+ update(type, (draft) => {
661
+ draft.jsonSchema = internal.toJsonSchema(extended);
662
+ });
475
663
  };
476
664
 
477
665
  /**
478
- * @returns True if the schema is mutable.
666
+ * Replace existing fields on a persisted type's schema.
667
+ * @throws if the type is not persisted.
479
668
  */
480
- export const isMutable = isMutable$;
669
+ export const updateFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {
670
+ const updated = typeInternal.updateFieldsInSchema(getSchema(type), fields);
671
+ update(type, (draft) => {
672
+ draft.jsonSchema = internal.toJsonSchema(updated);
673
+ });
674
+ };
481
675
 
482
676
  /**
483
- * ECHO type metadata.
677
+ * Rename a field on a persisted type's schema.
678
+ * @throws if the type is not persisted.
484
679
  */
485
- export type Meta = TypeAnnotation;
680
+ export const updateFieldPropertyName = (
681
+ type: Type,
682
+ { before, after }: { before: PropertyKey; after: PropertyKey },
683
+ ): void => {
684
+ const renamed = typeInternal.updateFieldNameInSchema(getSchema(type), { before, after });
685
+ update(type, (draft) => {
686
+ draft.jsonSchema = internal.toJsonSchema(renamed);
687
+ });
688
+ };
486
689
 
487
690
  /**
488
- * Gets the meta data of the schema.
691
+ * Remove fields from a persisted type's schema.
692
+ * @throws if the type is not persisted.
489
693
  */
490
- export const getMeta = (schema: Entity.Any): Meta | undefined => {
491
- return getTypeAnnotation(schema);
694
+ export const removeFields = (type: AnyEntity, fieldNames: string[]): void => {
695
+ const removed = typeInternal.removeFieldsFromSchema(getSchema(type), fieldNames);
696
+ update(type, (draft) => {
697
+ draft.jsonSchema = internal.toJsonSchema(removed);
698
+ });
492
699
  };