@dxos/echo 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/dist/lib/Annotation.mjs +3 -0
  2. package/dist/lib/Blob.mjs +160 -0
  3. package/dist/lib/Blob.mjs.map +1 -0
  4. package/dist/lib/Database.mjs +2 -0
  5. package/dist/lib/Entity.mjs +231 -0
  6. package/dist/lib/Entity.mjs.map +1 -0
  7. package/dist/lib/Err.mjs +105 -0
  8. package/dist/lib/Err.mjs.map +1 -0
  9. package/dist/lib/Feed.mjs +338 -0
  10. package/dist/lib/Feed.mjs.map +1 -0
  11. package/dist/lib/Filter.mjs +380 -0
  12. package/dist/lib/Filter.mjs.map +1 -0
  13. package/dist/lib/Format.mjs +47 -0
  14. package/dist/lib/Format.mjs.map +1 -0
  15. package/dist/lib/JsonSchema.mjs +21 -0
  16. package/dist/lib/JsonSchema.mjs.map +1 -0
  17. package/dist/lib/Key.mjs +15 -0
  18. package/dist/lib/Key.mjs.map +1 -0
  19. package/dist/lib/Migration.mjs +38 -0
  20. package/dist/lib/Migration.mjs.map +1 -0
  21. package/dist/lib/Obj.mjs +660 -0
  22. package/dist/lib/Obj.mjs.map +1 -0
  23. package/dist/lib/Order.mjs +65 -0
  24. package/dist/lib/Order.mjs.map +1 -0
  25. package/dist/lib/Query.mjs +336 -0
  26. package/dist/lib/Query.mjs.map +1 -0
  27. package/dist/lib/QueryResult.mjs +7 -0
  28. package/dist/lib/QueryResult.mjs.map +1 -0
  29. package/dist/lib/Ref.mjs +44 -0
  30. package/dist/lib/Ref.mjs.map +1 -0
  31. package/dist/lib/Registry.mjs +35 -0
  32. package/dist/lib/Registry.mjs.map +1 -0
  33. package/dist/lib/Relation.mjs +397 -0
  34. package/dist/lib/Relation.mjs.map +1 -0
  35. package/dist/lib/Scope.mjs +51 -0
  36. package/dist/lib/Scope.mjs.map +1 -0
  37. package/dist/lib/Tag.mjs +70 -0
  38. package/dist/lib/Tag.mjs.map +1 -0
  39. package/dist/lib/Text.mjs +82 -0
  40. package/dist/lib/Text.mjs.map +1 -0
  41. package/dist/lib/Type.mjs +371 -0
  42. package/dist/lib/Type.mjs.map +1 -0
  43. package/dist/lib/chunk-Annotation.mjs +221 -0
  44. package/dist/lib/chunk-Annotation.mjs.map +1 -0
  45. package/dist/lib/chunk-Database.mjs +918 -0
  46. package/dist/lib/chunk-Database.mjs.map +1 -0
  47. package/dist/lib/chunk-atom-snapshot.mjs +249 -0
  48. package/dist/lib/chunk-atom-snapshot.mjs.map +1 -0
  49. package/dist/lib/chunk-internal.mjs +2775 -0
  50. package/dist/lib/chunk-internal.mjs.map +1 -0
  51. package/dist/lib/chunk-json-schema.mjs +660 -0
  52. package/dist/lib/chunk-json-schema.mjs.map +1 -0
  53. package/dist/lib/chunk-number.mjs +164 -0
  54. package/dist/lib/chunk-number.mjs.map +1 -0
  55. package/dist/lib/chunk-ref-array.mjs +31 -0
  56. package/dist/lib/chunk-ref-array.mjs.map +1 -0
  57. package/dist/lib/chunk-ref.mjs +590 -0
  58. package/dist/lib/chunk-ref.mjs.map +1 -0
  59. package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
  60. package/dist/lib/chunk-select.mjs +186 -0
  61. package/dist/lib/chunk-select.mjs.map +1 -0
  62. package/dist/lib/chunk-src.mjs +234 -0
  63. package/dist/lib/chunk-src.mjs.map +1 -0
  64. package/dist/lib/chunk-util.mjs +140 -0
  65. package/dist/lib/chunk-util.mjs.map +1 -0
  66. package/dist/lib/index.mjs +24 -0
  67. package/dist/lib/internal.mjs +10 -0
  68. package/dist/lib/testing.mjs +346 -0
  69. package/dist/lib/testing.mjs.map +1 -0
  70. package/dist/types/src/Aggregate.d.ts +86 -0
  71. package/dist/types/src/Aggregate.d.ts.map +1 -0
  72. package/dist/types/src/Blob.d.ts +153 -0
  73. package/dist/types/src/Blob.d.ts.map +1 -0
  74. package/dist/types/src/Blob.test.d.ts +2 -0
  75. package/dist/types/src/Blob.test.d.ts.map +1 -0
  76. package/dist/types/src/Database.d.ts +153 -4
  77. package/dist/types/src/Database.d.ts.map +1 -1
  78. package/dist/types/src/Err.d.ts +116 -0
  79. package/dist/types/src/Err.d.ts.map +1 -1
  80. package/dist/types/src/Feed.d.ts +116 -28
  81. package/dist/types/src/Feed.d.ts.map +1 -1
  82. package/dist/types/src/Feed.test.d.ts +2 -0
  83. package/dist/types/src/Feed.test.d.ts.map +1 -0
  84. package/dist/types/src/Filter.d.ts +14 -6
  85. package/dist/types/src/Filter.d.ts.map +1 -1
  86. package/dist/types/src/Hypergraph.d.ts +18 -0
  87. package/dist/types/src/Hypergraph.d.ts.map +1 -1
  88. package/dist/types/src/Json.d.ts.map +1 -1
  89. package/dist/types/src/Obj.d.ts +14 -1
  90. package/dist/types/src/Obj.d.ts.map +1 -1
  91. package/dist/types/src/Order.d.ts +9 -3
  92. package/dist/types/src/Order.d.ts.map +1 -1
  93. package/dist/types/src/Query.d.ts +107 -26
  94. package/dist/types/src/Query.d.ts.map +1 -1
  95. package/dist/types/src/Relation.d.ts +6 -0
  96. package/dist/types/src/Relation.d.ts.map +1 -1
  97. package/dist/types/src/Type.d.ts.map +1 -1
  98. package/dist/types/src/View.d.ts +1 -1
  99. package/dist/types/src/index.d.ts +2 -0
  100. package/dist/types/src/index.d.ts.map +1 -1
  101. package/dist/types/src/internal/Entity/api.d.ts +6 -0
  102. package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
  103. package/dist/types/src/internal/Entity/model.d.ts +3 -2
  104. package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
  105. package/dist/types/src/internal/Filter/match.d.ts.map +1 -1
  106. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +34 -8
  107. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -1
  108. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
  109. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
  110. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
  111. package/dist/types/src/internal/Query/pretty.d.ts.map +1 -1
  112. package/dist/types/src/internal/Query/query-result-effect.d.ts.map +1 -1
  113. package/dist/types/src/internal/common/proxy/make-object.d.ts +13 -0
  114. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
  115. package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -1
  116. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -1
  117. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +12 -0
  118. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
  119. package/dist/types/src/internal/common/types/index.d.ts +1 -0
  120. package/dist/types/src/internal/common/types/index.d.ts.map +1 -1
  121. package/dist/types/src/internal/common/types/model-symbols.d.ts +5 -0
  122. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
  123. package/dist/types/src/internal/common/types/projection.d.ts +32 -0
  124. package/dist/types/src/internal/common/types/projection.d.ts.map +1 -0
  125. package/dist/types/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +40 -35
  127. package/src/Aggregate.ts +105 -0
  128. package/src/Blob.test.ts +45 -0
  129. package/src/Blob.ts +205 -0
  130. package/src/Database.ts +207 -17
  131. package/src/Err.ts +36 -0
  132. package/src/Feed.test.ts +188 -0
  133. package/src/Feed.ts +238 -62
  134. package/src/Filter.ts +28 -10
  135. package/src/Hypergraph.ts +18 -0
  136. package/src/Json.ts +1 -0
  137. package/src/Obj.test.ts +2 -2
  138. package/src/Obj.ts +21 -1
  139. package/src/Order.ts +16 -9
  140. package/src/Query.test.ts +319 -2
  141. package/src/Query.ts +165 -51
  142. package/src/Relation.ts +14 -0
  143. package/src/Type.ts +5 -6
  144. package/src/index.ts +2 -0
  145. package/src/internal/Entity/api.ts +11 -1
  146. package/src/internal/Entity/model.ts +3 -0
  147. package/src/internal/Filter/match.ts +30 -1
  148. package/src/internal/JsonSchema/json-schema-type.ts +14 -2
  149. package/src/internal/JsonSchema/json-schema.test.ts +28 -1
  150. package/src/internal/JsonSchema/json-schema.ts +33 -6
  151. package/src/internal/Obj/atoms.ts +4 -2
  152. package/src/internal/Obj/json-serializer.test.ts +162 -2
  153. package/src/internal/Obj/json-serializer.ts +6 -0
  154. package/src/internal/Query/pretty.ts +19 -1
  155. package/src/internal/Query/query-result-effect.ts +2 -4
  156. package/src/internal/Ref/atoms.ts +1 -1
  157. package/src/internal/common/proxy/change-context.ts +1 -1
  158. package/src/internal/common/proxy/make-object.ts +42 -3
  159. package/src/internal/common/proxy/reactive.ts +5 -0
  160. package/src/internal/common/proxy/symbols.ts +1 -0
  161. package/src/internal/common/proxy/typed-handler.ts +71 -29
  162. package/src/internal/common/types/index.ts +1 -0
  163. package/src/internal/common/types/model-symbols.ts +6 -0
  164. package/src/internal/common/types/projection.ts +45 -0
  165. package/src/testing/test-data.ts +14 -14
  166. package/dist/lib/neutral/Annotation.mjs +0 -90
  167. package/dist/lib/neutral/Annotation.mjs.map +0 -7
  168. package/dist/lib/neutral/Database.mjs +0 -42
  169. package/dist/lib/neutral/Database.mjs.map +0 -7
  170. package/dist/lib/neutral/Entity.mjs +0 -76
  171. package/dist/lib/neutral/Entity.mjs.map +0 -7
  172. package/dist/lib/neutral/Err.mjs +0 -16
  173. package/dist/lib/neutral/Err.mjs.map +0 -7
  174. package/dist/lib/neutral/Feed.mjs +0 -50
  175. package/dist/lib/neutral/Feed.mjs.map +0 -7
  176. package/dist/lib/neutral/Filter.mjs +0 -72
  177. package/dist/lib/neutral/Filter.mjs.map +0 -7
  178. package/dist/lib/neutral/Format.mjs +0 -82
  179. package/dist/lib/neutral/Format.mjs.map +0 -7
  180. package/dist/lib/neutral/JsonSchema.mjs +0 -18
  181. package/dist/lib/neutral/JsonSchema.mjs.map +0 -7
  182. package/dist/lib/neutral/Key.mjs +0 -16
  183. package/dist/lib/neutral/Key.mjs.map +0 -7
  184. package/dist/lib/neutral/Migration.mjs +0 -18
  185. package/dist/lib/neutral/Migration.mjs.map +0 -7
  186. package/dist/lib/neutral/Obj.mjs +0 -128
  187. package/dist/lib/neutral/Obj.mjs.map +0 -7
  188. package/dist/lib/neutral/Order.mjs +0 -16
  189. package/dist/lib/neutral/Order.mjs.map +0 -7
  190. package/dist/lib/neutral/Query.mjs +0 -38
  191. package/dist/lib/neutral/Query.mjs.map +0 -7
  192. package/dist/lib/neutral/QueryResult.mjs +0 -2
  193. package/dist/lib/neutral/QueryResult.mjs.map +0 -7
  194. package/dist/lib/neutral/Ref.mjs +0 -25
  195. package/dist/lib/neutral/Ref.mjs.map +0 -7
  196. package/dist/lib/neutral/Registry.mjs +0 -14
  197. package/dist/lib/neutral/Registry.mjs.map +0 -7
  198. package/dist/lib/neutral/Relation.mjs +0 -97
  199. package/dist/lib/neutral/Relation.mjs.map +0 -7
  200. package/dist/lib/neutral/Scope.mjs +0 -12
  201. package/dist/lib/neutral/Scope.mjs.map +0 -7
  202. package/dist/lib/neutral/Tag.mjs +0 -32
  203. package/dist/lib/neutral/Tag.mjs.map +0 -7
  204. package/dist/lib/neutral/Text.mjs +0 -25
  205. package/dist/lib/neutral/Text.mjs.map +0 -7
  206. package/dist/lib/neutral/Type.mjs +0 -65
  207. package/dist/lib/neutral/Type.mjs.map +0 -7
  208. package/dist/lib/neutral/chunk-2HKGAQM4.mjs +0 -1394
  209. package/dist/lib/neutral/chunk-2HKGAQM4.mjs.map +0 -7
  210. package/dist/lib/neutral/chunk-2ZHECXUR.mjs +0 -95
  211. package/dist/lib/neutral/chunk-2ZHECXUR.mjs.map +0 -7
  212. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs +0 -336
  213. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs.map +0 -7
  214. package/dist/lib/neutral/chunk-3TN2VMI4.mjs +0 -714
  215. package/dist/lib/neutral/chunk-3TN2VMI4.mjs.map +0 -7
  216. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs +0 -104
  217. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs.map +0 -7
  218. package/dist/lib/neutral/chunk-4A2NWKRJ.mjs +0 -747
  219. package/dist/lib/neutral/chunk-4A2NWKRJ.mjs.map +0 -7
  220. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs +0 -25
  221. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +0 -7
  222. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs +0 -1531
  223. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs.map +0 -7
  224. package/dist/lib/neutral/chunk-BEFR7LEA.mjs +0 -170
  225. package/dist/lib/neutral/chunk-BEFR7LEA.mjs.map +0 -7
  226. package/dist/lib/neutral/chunk-BXIKXT7Q.mjs +0 -89
  227. package/dist/lib/neutral/chunk-BXIKXT7Q.mjs.map +0 -7
  228. package/dist/lib/neutral/chunk-C57XMMBY.mjs +0 -206
  229. package/dist/lib/neutral/chunk-C57XMMBY.mjs.map +0 -7
  230. package/dist/lib/neutral/chunk-C62JYFAD.mjs +0 -183
  231. package/dist/lib/neutral/chunk-C62JYFAD.mjs.map +0 -7
  232. package/dist/lib/neutral/chunk-FSGX2R62.mjs +0 -48
  233. package/dist/lib/neutral/chunk-FSGX2R62.mjs.map +0 -7
  234. package/dist/lib/neutral/chunk-HBXT3GSB.mjs +0 -459
  235. package/dist/lib/neutral/chunk-HBXT3GSB.mjs.map +0 -7
  236. package/dist/lib/neutral/chunk-IQR45HAD.mjs +0 -31
  237. package/dist/lib/neutral/chunk-IQR45HAD.mjs.map +0 -7
  238. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  239. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  240. package/dist/lib/neutral/chunk-KCBW4BR6.mjs +0 -424
  241. package/dist/lib/neutral/chunk-KCBW4BR6.mjs.map +0 -7
  242. package/dist/lib/neutral/chunk-L3E5IXAE.mjs +0 -575
  243. package/dist/lib/neutral/chunk-L3E5IXAE.mjs.map +0 -7
  244. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs +0 -56
  245. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs.map +0 -7
  246. package/dist/lib/neutral/chunk-SCT6FFCR.mjs +0 -351
  247. package/dist/lib/neutral/chunk-SCT6FFCR.mjs.map +0 -7
  248. package/dist/lib/neutral/chunk-TOCVVFK2.mjs +0 -75
  249. package/dist/lib/neutral/chunk-TOCVVFK2.mjs.map +0 -7
  250. package/dist/lib/neutral/chunk-U53LSQQA.mjs +0 -41
  251. package/dist/lib/neutral/chunk-U53LSQQA.mjs.map +0 -7
  252. package/dist/lib/neutral/chunk-UGFFV2FR.mjs +0 -27
  253. package/dist/lib/neutral/chunk-UGFFV2FR.mjs.map +0 -7
  254. package/dist/lib/neutral/chunk-UWLP4RFM.mjs +0 -7
  255. package/dist/lib/neutral/chunk-UWLP4RFM.mjs.map +0 -7
  256. package/dist/lib/neutral/chunk-UZHCQ6NI.mjs +0 -283
  257. package/dist/lib/neutral/chunk-UZHCQ6NI.mjs.map +0 -7
  258. package/dist/lib/neutral/chunk-WISOH2XH.mjs +0 -36
  259. package/dist/lib/neutral/chunk-WISOH2XH.mjs.map +0 -7
  260. package/dist/lib/neutral/chunk-WKIT2YY5.mjs +0 -34
  261. package/dist/lib/neutral/chunk-WKIT2YY5.mjs.map +0 -7
  262. package/dist/lib/neutral/chunk-XB6ISRAO.mjs +0 -271
  263. package/dist/lib/neutral/chunk-XB6ISRAO.mjs.map +0 -7
  264. package/dist/lib/neutral/chunk-XXL42WCB.mjs +0 -84
  265. package/dist/lib/neutral/chunk-XXL42WCB.mjs.map +0 -7
  266. package/dist/lib/neutral/chunk-XXWK4J53.mjs +0 -117
  267. package/dist/lib/neutral/chunk-XXWK4J53.mjs.map +0 -7
  268. package/dist/lib/neutral/index.mjs +0 -115
  269. package/dist/lib/neutral/index.mjs.map +0 -7
  270. package/dist/lib/neutral/internal/index.mjs +0 -581
  271. package/dist/lib/neutral/internal/index.mjs.map +0 -7
  272. package/dist/lib/neutral/meta.json +0 -1
  273. package/dist/lib/neutral/testing/index.mjs +0 -477
  274. package/dist/lib/neutral/testing/index.mjs.map +0 -7
@@ -0,0 +1,3 @@
1
+ import { $ as ReferenceAnnotation, B as FormLayoutAnnotationId, D as DEFAULT_LAYOUT_NAME, Et as setDescriptionWithSchema, F as FormInlineAnnotation, G as HiddenAnnotation, J as IconFromRefAnnotation, L as FormInputAnnotation, N as FormCreateAnnotation, O as DescriptionAnnotation, Ot as setLabelWithSchema, P as FormCreateAnnotationId, U as GeneratorAnnotation, V as FormOrderedAnnotation, W as GeneratorAnnotationId, Y as LabelAnnotation, bt as getTypeAnnotation, et as ReferenceAnnotationId, ht as getLabelWithSchema, j as FieldLookupAnnotationId, lt as getDescriptionWithSchema, nt as TypeAnnotation, q as IconAnnotation, xt as getTypeIdentifierAnnotation, z as FormLayoutAnnotation } from "./chunk-Database.mjs";
2
+ import { a as atom, c as get, d as make, f as set, i as TypeId, l as getDictionary, m as update, n as Dictionary, o as atomProperty, p as setDictionary, r as Key, s as buildDictionary, u as getFromAst } from "./chunk-Annotation.mjs";
3
+ export { DEFAULT_LAYOUT_NAME, DescriptionAnnotation, Dictionary, FieldLookupAnnotationId, FormCreateAnnotation, FormCreateAnnotationId, FormInlineAnnotation, FormInputAnnotation, FormLayoutAnnotation, FormLayoutAnnotationId, FormOrderedAnnotation, GeneratorAnnotation, GeneratorAnnotationId, HiddenAnnotation, IconAnnotation, IconFromRefAnnotation, Key, LabelAnnotation, ReferenceAnnotation, ReferenceAnnotationId, TypeAnnotation, TypeId, atom, atomProperty, buildDictionary, get, getDescriptionWithSchema, getDictionary, getFromAst, getLabelWithSchema, getTypeAnnotation, getTypeIdentifierAnnotation, make, set, setDescriptionWithSchema, setDictionary, setLabelWithSchema, update };
@@ -0,0 +1,160 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { G as HiddenAnnotation, q as IconAnnotation, r as Service } from "./chunk-Database.mjs";
3
+ import { BlobNotAvailableError, BlobTooLargeError, BlobWriteError } from "./Err.mjs";
4
+ import { makeObject } from "./Type.mjs";
5
+ import { make as make$1 } from "./Obj.mjs";
6
+ import { DXN } from "@dxos/keys";
7
+ import * as Option from "effect/Option";
8
+ import * as Schema from "effect/Schema";
9
+ import * as Effect from "effect/Effect";
10
+ //#region src/Blob.ts
11
+ var Blob_exports = /* @__PURE__ */ __exportAll({
12
+ Blob: () => Blob,
13
+ BlobData: () => BlobData,
14
+ ExternalData: () => ExternalData,
15
+ InlineData: () => InlineData,
16
+ MAX_INLINE_SIZE: () => MAX_INLINE_SIZE,
17
+ Scheme: () => Scheme,
18
+ Storage: () => Storage,
19
+ exists: () => exists,
20
+ externalData: () => externalData,
21
+ fromBytes: () => fromBytes,
22
+ inlineData: () => inlineData,
23
+ make: () => make,
24
+ read: () => read,
25
+ url: () => url
26
+ });
27
+ /**
28
+ * Inline blob data: bytes stored directly on the ECHO object.
29
+ */
30
+ var InlineData = Schema.TaggedStruct("inline", { bytes: Schema.Uint8ArrayFromSelf.annotations({ jsonSchema: {
31
+ type: "string",
32
+ contentEncoding: "base64"
33
+ } }) });
34
+ /**
35
+ * External blob data: bytes stored by a registered blob backend, addressed by `uri`.
36
+ */
37
+ var ExternalData = Schema.TaggedStruct("external", {
38
+ /**
39
+ * URI locating the bytes. The scheme selects the backend at read time (e.g. `ni:///sha-256;…` for
40
+ * the edge backend — an RFC 6920 content digest, not a backend name — or `wnfs://…` for the
41
+ * plugin-wnfs extension), resolved via the scheme→backend map built from `registerBlobBackend`
42
+ * calls. Core code never parses or constructs backend-specific URIs beyond reading the scheme.
43
+ *
44
+ * @see {@link https://www.rfc-editor.org/rfc/rfc6920 RFC 6920} for the `ni:` URI format.
45
+ */
46
+ uri: Schema.String });
47
+ var BlobData = Schema.Union(InlineData, ExternalData);
48
+ /**
49
+ * Runtime schema for a Blob object.
50
+ *
51
+ * NOTE: This export shadows the DOM `Blob` global within modules that import it as a namespace.
52
+ * Code that needs the DOM class should use `globalThis.Blob` explicitly.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const blob = yield* Blob.fromBytes(bytes, { type: 'image/png' });
57
+ * ```
58
+ */
59
+ var Blob = class extends makeObject(DXN.make("org.dxos.type.blob", "0.1.0"))(Schema.Struct({
60
+ /** MIME type. */
61
+ type: Schema.optional(Schema.String),
62
+ size: Schema.Number,
63
+ data: BlobData
64
+ }).pipe(HiddenAnnotation.set(true), IconAnnotation.set({
65
+ icon: "ph--file--regular",
66
+ hue: "teal"
67
+ }))) {};
68
+ /**
69
+ * Storage backend names, selected at write time via {@link FromBytesOptions.storage}. Call sites
70
+ * always use these constants, never raw string literals. Extensions (e.g. plugin-wnfs) define
71
+ * their own storage names in their own package — core code knows nothing of them.
72
+ *
73
+ * Distinct from {@link Scheme}: a storage name picks *where* to write, a URI scheme describes
74
+ * *what the identifier is* at read time. They coincide for backends with no content-addressing
75
+ * (e.g. wnfs uses `'wnfs'` for both), but the edge backend's storage name (`'edge'`) differs from
76
+ * its URI scheme (`Scheme.ni`) because the identifier it produces is a content hash, not an
77
+ * edge-specific address.
78
+ */
79
+ var Storage = {
80
+ inline: "inline",
81
+ edge: "edge"
82
+ };
83
+ /**
84
+ * URI schemes claimed by core backends (see `BlobBackend.schemes` in `@dxos/echo-protocol`).
85
+ *
86
+ * `ni` marks an {@link https://www.rfc-editor.org/rfc/rfc6920 RFC 6920} Named Information URI whose
87
+ * authority is empty and whose path carries a registered hash-algorithm name plus a base64url-encoded
88
+ * digest (e.g. `ni:///sha-256;UyaQNQIUxQKgg1jVMKMbg1Yr8Rrb2Y3RaOx2N0mVJhc`, produced by the edge
89
+ * backend). The scheme names *what the identifier is* — a content digest over the complete blob —
90
+ * not which backend wrote it, so any backend or cache that can resolve that digest may claim it.
91
+ * The URI is an identity claim, not a retrievability promise; transport is selected by the registered
92
+ * backend at read time.
93
+ *
94
+ * Extensions (e.g. plugin-wnfs) define their own schemes in their own package.
95
+ */
96
+ var Scheme = { ni: "ni" };
97
+ var MAX_INLINE_SIZE = 4 * 1024 * 1024;
98
+ /**
99
+ * Creates a new blob object. Does not add it to the database — see {@link fromBytes}.
100
+ */
101
+ var make = (props) => make$1(Blob, props);
102
+ /**
103
+ * Creates an inline {@link BlobData} variant that embeds raw bytes on the ECHO object.
104
+ */
105
+ var inlineData = (bytes) => ({
106
+ _tag: "inline",
107
+ bytes
108
+ });
109
+ /**
110
+ * Creates an external {@link BlobData} variant that references bytes held by a registered backend.
111
+ * @param uri - Backend-scoped URI, e.g. as returned by a `BlobBackend.put` call.
112
+ */
113
+ var externalData = (uri) => ({
114
+ _tag: "external",
115
+ uri
116
+ });
117
+ /**
118
+ * Hashes and uploads `bytes` via the chosen storage backend (a no-op for `inline`), returning an
119
+ * un-added Blob object. The caller is responsible for adding it to the database.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * const blob = yield* Blob.fromBytes(bytes, { type: 'image/png' });
124
+ * yield* Database.add(blob);
125
+ * ```
126
+ */
127
+ var fromBytes = (bytes, options) => Service.pipe(Effect.flatMap(({ db }) => Effect.tryPromise({
128
+ try: () => db.createBlob(bytes, options),
129
+ catch: (error) => error instanceof BlobTooLargeError || error instanceof BlobWriteError ? error : new BlobWriteError({ backend: options?.storage ?? "unknown" }, { cause: error })
130
+ }))).pipe(Effect.withSpan("Blob.fromBytes"));
131
+ /**
132
+ * Loads a blob's bytes. Inline: read directly off the object. External: dispatched to the
133
+ * registered backend for the URI's scheme.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const bytes = yield* Blob.read(blob);
138
+ * ```
139
+ */
140
+ var read = (blob) => Service.pipe(Effect.flatMap(({ db }) => Effect.tryPromise({
141
+ try: () => db.readBlob(blob),
142
+ catch: (error) => error instanceof BlobNotAvailableError ? error : new BlobNotAvailableError({
143
+ backend: "unknown",
144
+ key: blob.id,
145
+ reason: "not-found"
146
+ }, { cause: error })
147
+ }))).pipe(Effect.withSpan("Blob.read"));
148
+ /**
149
+ * Checks whether a blob's bytes are currently available.
150
+ */
151
+ var exists = (blob) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.blobExists(blob)))).pipe(Effect.withSpan("Blob.exists"));
152
+ /**
153
+ * Returns a renderable URL for the blob: inline blobs resolve to a `data:` URL; external blobs
154
+ * are resolved by the registered backend's `getUrl`, if it implements one.
155
+ */
156
+ var url = (blob) => Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.getBlobUrl(blob))), Effect.map(Option.fromNullable)).pipe(Effect.withSpan("Blob.url"));
157
+ //#endregion
158
+ export { Blob, BlobData, ExternalData, InlineData, MAX_INLINE_SIZE, Scheme, Storage, exists, externalData, fromBytes, inlineData, make, read, Blob_exports as t, url };
159
+
160
+ //# sourceMappingURL=Blob.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blob.mjs","names":[],"sources":["../../src/Blob.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { DXN } from '@dxos/keys';\n\nimport * as Annotation from './Annotation';\nimport * as Database from './Database';\nimport * as Err from './Err';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\n\n/**\n * Inline blob data: bytes stored directly on the ECHO object.\n */\nexport const InlineData = Schema.TaggedStruct('inline', {\n bytes: Schema.Uint8ArrayFromSelf.annotations({ jsonSchema: { type: 'string', contentEncoding: 'base64' } }),\n});\n\n/**\n * External blob data: bytes stored by a registered blob backend, addressed by `uri`.\n */\nexport const ExternalData = Schema.TaggedStruct('external', {\n /**\n * URI locating the bytes. The scheme selects the backend at read time (e.g. `ni:///sha-256;…` for\n * the edge backend — an RFC 6920 content digest, not a backend name — or `wnfs://…` for the\n * plugin-wnfs extension), resolved via the scheme→backend map built from `registerBlobBackend`\n * calls. Core code never parses or constructs backend-specific URIs beyond reading the scheme.\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc6920 RFC 6920} for the `ni:` URI format.\n */\n uri: Schema.String,\n});\n\nexport const BlobData = Schema.Union(InlineData, ExternalData);\nexport type BlobData = Schema.Schema.Type<typeof BlobData>;\n\n/**\n * Runtime schema for a Blob object.\n *\n * NOTE: This export shadows the DOM `Blob` global within modules that import it as a namespace.\n * Code that needs the DOM class should use `globalThis.Blob` explicitly.\n *\n * @example\n * ```ts\n * const blob = yield* Blob.fromBytes(bytes, { type: 'image/png' });\n * ```\n */\nexport class Blob extends Type.makeObject<Blob>(DXN.make('org.dxos.type.blob', '0.1.0'))(\n Schema.Struct({\n /** MIME type. */\n type: Schema.optional(Schema.String),\n size: Schema.Number,\n data: BlobData,\n }).pipe(\n internal.HiddenAnnotation.set(true),\n Annotation.IconAnnotation.set({ icon: 'ph--file--regular', hue: 'teal' }),\n ),\n) {}\n\n//\n// Storage constants\n//\n\n/**\n * Storage backend names, selected at write time via {@link FromBytesOptions.storage}. Call sites\n * always use these constants, never raw string literals. Extensions (e.g. plugin-wnfs) define\n * their own storage names in their own package — core code knows nothing of them.\n *\n * Distinct from {@link Scheme}: a storage name picks *where* to write, a URI scheme describes\n * *what the identifier is* at read time. They coincide for backends with no content-addressing\n * (e.g. wnfs uses `'wnfs'` for both), but the edge backend's storage name (`'edge'`) differs from\n * its URI scheme (`Scheme.ni`) because the identifier it produces is a content hash, not an\n * edge-specific address.\n */\nexport const Storage = { inline: 'inline', edge: 'edge' } as const;\nexport type Storage = (typeof Storage)[keyof typeof Storage];\n\n/**\n * URI schemes claimed by core backends (see `BlobBackend.schemes` in `@dxos/echo-protocol`).\n *\n * `ni` marks an {@link https://www.rfc-editor.org/rfc/rfc6920 RFC 6920} Named Information URI whose\n * authority is empty and whose path carries a registered hash-algorithm name plus a base64url-encoded\n * digest (e.g. `ni:///sha-256;UyaQNQIUxQKgg1jVMKMbg1Yr8Rrb2Y3RaOx2N0mVJhc`, produced by the edge\n * backend). The scheme names *what the identifier is* — a content digest over the complete blob —\n * not which backend wrote it, so any backend or cache that can resolve that digest may claim it.\n * The URI is an identity claim, not a retrievability promise; transport is selected by the registered\n * backend at read time.\n *\n * Extensions (e.g. plugin-wnfs) define their own schemes in their own package.\n */\nexport const Scheme = { ni: 'ni' } as const;\nexport type Scheme = (typeof Scheme)[keyof typeof Scheme];\n\n//\n// Factory\n//\n\nexport const MAX_INLINE_SIZE = 4 * 1024 * 1024;\n\n/**\n * Creates a new blob object. Does not add it to the database — see {@link fromBytes}.\n */\nexport const make = (props: Obj.MakeProps<typeof Blob>): Blob => Obj.make(Blob, props);\n\n/**\n * Creates an inline {@link BlobData} variant that embeds raw bytes on the ECHO object.\n */\nexport const inlineData = (bytes: Uint8Array): BlobData => ({ _tag: 'inline', bytes });\n\n/**\n * Creates an external {@link BlobData} variant that references bytes held by a registered backend.\n * @param uri - Backend-scoped URI, e.g. as returned by a `BlobBackend.put` call.\n */\nexport const externalData = (uri: string): BlobData => ({ _tag: 'external', uri });\n\nexport interface FromBytesOptions {\n /** MIME type. */\n type?: string;\n /**\n * Storage backend name. Defaults to the registry's configured default (initially `'inline'`;\n * `@dxos/client` marks `'edge'` as the default when configured).\n */\n storage?: Storage | (string & {});\n}\n\n//\n// Operations\n//\n\n/**\n * Hashes and uploads `bytes` via the chosen storage backend (a no-op for `inline`), returning an\n * un-added Blob object. The caller is responsible for adding it to the database.\n *\n * @example\n * ```ts\n * const blob = yield* Blob.fromBytes(bytes, { type: 'image/png' });\n * yield* Database.add(blob);\n * ```\n */\nexport const fromBytes = (\n bytes: Uint8Array,\n options?: FromBytesOptions,\n): Effect.Effect<Blob, Err.BlobTooLargeError | Err.BlobWriteError, Database.Service> =>\n Database.Service.pipe(\n Effect.flatMap(({ db }) =>\n Effect.tryPromise({\n try: () => db.createBlob(bytes, options),\n catch: (error) =>\n error instanceof Err.BlobTooLargeError || error instanceof Err.BlobWriteError\n ? error\n : new Err.BlobWriteError({ backend: options?.storage ?? 'unknown' }, { cause: error }),\n }),\n ),\n ).pipe(Effect.withSpan('Blob.fromBytes'));\n\n/**\n * Loads a blob's bytes. Inline: read directly off the object. External: dispatched to the\n * registered backend for the URI's scheme.\n *\n * @example\n * ```ts\n * const bytes = yield* Blob.read(blob);\n * ```\n */\nexport const read = (blob: Blob): Effect.Effect<Uint8Array, Err.BlobNotAvailableError, Database.Service> =>\n Database.Service.pipe(\n Effect.flatMap(({ db }) =>\n Effect.tryPromise({\n try: () => db.readBlob(blob),\n catch: (error) =>\n error instanceof Err.BlobNotAvailableError\n ? error\n : new Err.BlobNotAvailableError(\n { backend: 'unknown', key: blob.id, reason: 'not-found' },\n { cause: error },\n ),\n }),\n ),\n ).pipe(Effect.withSpan('Blob.read'));\n\n/**\n * Checks whether a blob's bytes are currently available.\n */\nexport const exists = (blob: Blob): Effect.Effect<boolean, never, Database.Service> =>\n Database.Service.pipe(Effect.flatMap(({ db }) => Effect.promise(() => db.blobExists(blob)))).pipe(\n Effect.withSpan('Blob.exists'),\n );\n\n/**\n * Returns a renderable URL for the blob: inline blobs resolve to a `data:` URL; external blobs\n * are resolved by the registered backend's `getUrl`, if it implements one.\n */\nexport const url = (blob: Blob): Effect.Effect<Option.Option<string>, never, Database.Service> =>\n Database.Service.pipe(\n Effect.flatMap(({ db }) => Effect.promise(() => db.getBlobUrl(blob))),\n Effect.map(Option.fromNullable),\n ).pipe(Effect.withSpan('Blob.url'));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,aAAa,OAAO,aAAa,UAAU,EACtD,OAAO,OAAO,mBAAmB,YAAY,EAAE,YAAY;CAAE,MAAM;CAAU,iBAAiB;AAAS,EAAE,CAAC,EAC5G,CAAC;;;;AAKD,IAAa,eAAe,OAAO,aAAa,YAAY;;;;;;;;;AAS1D,KAAK,OAAO,OACd,CAAC;AAED,IAAa,WAAW,OAAO,MAAM,YAAY,YAAY;;;;;;;;;;;;AAc7D,IAAa,OAAb,cAA0B,WAAsB,IAAI,KAAK,sBAAsB,OAAO,CAAC,CAAC,CACtF,OAAO,OAAO;;CAEZ,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,MAAM,OAAO;CACb,MAAM;AACR,CAAC,CAAC,CAAC,KAAA,iBACyB,IAAI,IAAI,GAAA,eACR,IAAI;CAAE,MAAM;CAAqB,KAAK;AAAO,CAAC,CAC1E,CACF,CAAC,CAAC,CAAC;;;;;;;;;;;;AAiBH,IAAa,UAAU;CAAE,QAAQ;CAAU,MAAM;AAAO;;;;;;;;;;;;;;AAgBxD,IAAa,SAAS,EAAE,IAAI,KAAK;AAOjC,IAAa,kBAAkB,IAAI,OAAO;;;;AAK1C,IAAa,QAAQ,UAA4C,OAAS,MAAM,KAAK;;;;AAKrF,IAAa,cAAc,WAAiC;CAAE,MAAM;CAAU;AAAM;;;;;AAMpF,IAAa,gBAAgB,SAA2B;CAAE,MAAM;CAAY;AAAI;;;;;;;;;;;AA0BhF,IAAa,aACX,OACA,YAAA,QAEiB,KACf,OAAO,SAAS,EAAE,SAChB,OAAO,WAAW;CAChB,WAAW,GAAG,WAAW,OAAO,OAAO;CACvC,QAAQ,UACN,iBAAiB,qBAAyB,iBAAiB,iBACvD,QACA,IAAI,eAAmB,EAAE,SAAS,SAAS,WAAW,UAAU,GAAG,EAAE,OAAO,MAAM,CAAC;AAC3F,CAAC,CACH,CACF,CAAC,CAAC,KAAK,OAAO,SAAS,gBAAgB,CAAC;;;;;;;;;;AAW1C,IAAa,QAAQ,SAAA,QACF,KACf,OAAO,SAAS,EAAE,SAChB,OAAO,WAAW;CAChB,WAAW,GAAG,SAAS,IAAI;CAC3B,QAAQ,UACN,iBAAiB,wBACb,QACA,IAAI,sBACF;EAAE,SAAS;EAAW,KAAK,KAAK;EAAI,QAAQ;CAAY,GACxD,EAAE,OAAO,MAAM,CACjB;AACR,CAAC,CACH,CACF,CAAC,CAAC,KAAK,OAAO,SAAS,WAAW,CAAC;;;;AAKrC,IAAa,UAAU,SAAA,QACJ,KAAK,OAAO,SAAS,EAAE,SAAS,OAAO,cAAc,GAAG,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAC3F,OAAO,SAAS,aAAa,CAC/B;;;;;AAMF,IAAa,OAAO,SAAA,QACD,KACf,OAAO,SAAS,EAAE,SAAS,OAAO,cAAc,GAAG,WAAW,IAAI,CAAC,CAAC,GACpE,OAAO,IAAI,OAAO,YAAY,CAChC,CAAC,CAAC,KAAK,OAAO,SAAS,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { _ as remove, a as add, b as subscribeToSyncState, c as deleteFromFeed, d as isDatabase, f as layer, g as query, h as notAvailable, i as TypeId, l as flush, m as makeService, o as addType, p as load, r as Service, s as appendToFeed, t as Database, u as getSyncState, v as resolve, y as spaceId } from "./chunk-Database.mjs";
2
+ export { Database, Service, TypeId, add, addType, appendToFeed, deleteFromFeed, flush, getSyncState, isDatabase, layer, load, makeService, notAvailable, query, remove, resolve, spaceId, subscribeToSyncState };
@@ -0,0 +1,231 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { a as isEntity$1, c as getKeys$1, l as getMetaChecked, o as addTag$1, u as removeTag$1 } from "./chunk-atom-snapshot.mjs";
3
+ import { T as objectToJSON, c as makeEntity, h as isDeleted$1, l as makeLabelAtom } from "./chunk-internal.mjs";
4
+ import { d as SnapshotKindId$1, l as KindId$1, m as getEntityKindBrand, o as EntityKind, s as EntityKindSchema } from "./chunk-util.mjs";
5
+ import { Ct as getTypename$1, Dt as setLabel$1, Gt as MetaId, Lt as getType$1, S as isInstanceOf, St as getTypeURI$1, T as getUri, ct as getDescription$1, ft as getIcon$1, mt as getLabelProperty, pt as getLabel$1, ut as getEntityKind, w as getDatabase$1 } from "./chunk-Database.mjs";
6
+ import { g as subscribe$1, h as change } from "./chunk-ref.mjs";
7
+ import { Type, getTypename as getTypename$2, getURI as getURI$1 } from "./Type.mjs";
8
+ import * as Schema from "effect/Schema";
9
+ //#region src/Entity.ts
10
+ var Entity_exports = /* @__PURE__ */ __exportAll({
11
+ Kind: () => Kind,
12
+ KindId: () => KindId,
13
+ KindSchema: () => KindSchema,
14
+ Meta: () => Meta,
15
+ SnapshotKindId: () => SnapshotKindId,
16
+ Unknown: () => Unknown,
17
+ addTag: () => addTag,
18
+ atom: () => atom,
19
+ getDatabase: () => getDatabase,
20
+ getDescription: () => getDescription,
21
+ getIcon: () => getIcon,
22
+ getKeys: () => getKeys,
23
+ getKind: () => getKind,
24
+ getLabel: () => getLabel,
25
+ getMeta: () => getMeta,
26
+ getType: () => getType,
27
+ getTypeURI: () => getTypeURI,
28
+ getTypename: () => getTypename,
29
+ getURI: () => getURI,
30
+ instanceOf: () => instanceOf,
31
+ isDeleted: () => isDeleted,
32
+ isEntity: () => isEntity,
33
+ isSnapshot: () => isSnapshot,
34
+ labelAtom: () => labelAtom,
35
+ labelProperty: () => labelProperty,
36
+ removeTag: () => removeTag,
37
+ setLabel: () => setLabel,
38
+ subscribe: () => subscribe,
39
+ toJSON: () => toJSON,
40
+ update: () => update
41
+ });
42
+ var KindId = KindId$1;
43
+ var SnapshotKindId = SnapshotKindId$1;
44
+ var Kind = EntityKind;
45
+ var KindSchema = EntityKindSchema;
46
+ /**
47
+ * Effect Schema for any ECHO entity (object or relation).
48
+ *
49
+ * Kind-agnostic counterpart to `Obj.Unknown` / `Relation.Unknown` — validates
50
+ * the structural shape (id + properties) without constraining `[KindId]`. Used
51
+ * in operation input schemas that accept any entity flavour (e.g.
52
+ * `Schema.Array(Entity.Unknown)`).
53
+ *
54
+ * The cast bridges the runtime structural schema to the branded `Unknown` type:
55
+ * `[KindId]` is a symbol brand that can't be expressed in a runtime `Struct`,
56
+ * so the entity guarantee is carried at the type level only (same approach as
57
+ * `Obj.Unknown` / `Relation.Unknown`). Unlike those, this is kind-agnostic so it
58
+ * isn't an `UnknownTypeSchema<_, K>` (there's no single `K`) and carries no
59
+ * `TypeAnnotation`.
60
+ */
61
+ var Unknown = Schema.Struct({ id: Schema.String }).pipe(Schema.extend(Schema.Record({
62
+ key: Schema.String,
63
+ value: Schema.Unknown
64
+ })));
65
+ /**
66
+ * Check if a value is an ECHO entity (object or relation).
67
+ * Returns `false` for snapshots.
68
+ */
69
+ var isEntity = isEntity$1;
70
+ /**
71
+ * Test if a value is an instance of a given object or relation type.
72
+ *
73
+ * Kind-agnostic counterpart to `Obj.instanceOf` / `Relation.instanceOf` —
74
+ * use this when the caller's input type is `Type.AnyObj | Type.AnyRelation`.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * // Caller doesn't know whether `type` is object- or relation-kind.
79
+ * const matches = <T extends Type.AnyObj | Type.AnyRelation>(type: T, value: unknown) =>
80
+ * Entity.instanceOf(type, value);
81
+ * ```
82
+ */
83
+ var instanceOf = ((...args) => {
84
+ if (args.length === 1) return (entity) => isInstanceOf(args[0], entity);
85
+ return isInstanceOf(args[0], args[1]);
86
+ });
87
+ /**
88
+ * Check if a value is an ECHO entity snapshot.
89
+ * Returns `false` for entities.
90
+ */
91
+ var isSnapshot = (value) => {
92
+ if (typeof value !== "object" || value === null) return false;
93
+ return value[SnapshotKindId] !== void 0;
94
+ };
95
+ var getKind = getEntityKind;
96
+ /**
97
+ * Property that accesses metadata for an entity.
98
+ */
99
+ var Meta = MetaId;
100
+ /**
101
+ * Whether the entity is a type-kind entity (a `Type.Type` produced by
102
+ * `Type.makeObject` / `Type.makeRelation`, or a persisted schema). Type entities
103
+ * carry their identity (typename/version) on themselves rather than referencing a
104
+ * separate type, so the accessors below route them through the `Type.*` module.
105
+ */
106
+ var isTypeEntity = (entity) => getEntityKindBrand(entity) === EntityKind.Type;
107
+ /**
108
+ * Get the canonical URI of an entity (object, relation, or type). Returns `URI.URI` —
109
+ * an `EID` for object/relation instances and persisted types, or a typename
110
+ * `DXN` for static type entities; narrow with `EID.parse(uri)` or
111
+ * `DXN.tryMake(uri)` at the point of use.
112
+ *
113
+ * @param options.prefer - Controls the URI form (see {@link internal.GetURIOptions}).
114
+ */
115
+ var getURI = (entity, options) => isTypeEntity(entity) ? getURI$1(entity, options) : getUri(entity, options);
116
+ /**
117
+ * Get the DXN of an entity's type. For object/relation instances this is the URI
118
+ * of the type they were created from; for a type entity it is the URI of the
119
+ * meta-type ({@link Type.Type}, `dxn:org.dxos.type.schema:0.1.0`).
120
+ */
121
+ var getTypeURI = (entity) => isTypeEntity(entity) ? getURI$1(Type) : getTypeURI$1(entity);
122
+ /**
123
+ * Get the type entity (`Type.AnyEntity`) the instance was created from.
124
+ *
125
+ * Returns `undefined` when the entity's type isn't registered in this runtime
126
+ * (e.g. a freshly deserialized snapshot whose type entity hasn't been wired
127
+ * up yet, or an entity loaded from storage before its schema is known). To
128
+ * get the Effect Schema from the returned entity, use `Type.getSchema(...)`.
129
+ *
130
+ * For a type entity, returns the meta-type {@link Type.Type} (a type entity's
131
+ * type is "Type").
132
+ */
133
+ var getType = (entity) => isTypeEntity(entity) ? Type : getType$1(entity);
134
+ /**
135
+ * Get the typename of an entity's type. For object/relation instances this is the
136
+ * typename of the type they were created from; for a type entity it is the type's
137
+ * own typename (e.g. `com.example.type.person`).
138
+ */
139
+ var getTypename = (entity) => isTypeEntity(entity) ? getTypename$2(entity) : getTypename$1(entity);
140
+ /**
141
+ * Get the database an entity belongs to.
142
+ */
143
+ var getDatabase = (entity) => getDatabase$1(entity);
144
+ function getMeta(entity) {
145
+ return getMetaChecked(entity);
146
+ }
147
+ /**
148
+ * Get foreign keys for an entity from the specified source.
149
+ */
150
+ var getKeys = (entity, source) => getKeys$1(entity, source);
151
+ /**
152
+ * Check if an entity is deleted.
153
+ */
154
+ var isDeleted = (entity) => isDeleted$1(entity);
155
+ /**
156
+ * Get the label of an entity.
157
+ *
158
+ * @param options.fallback `'typename'` returns the entity's typename when no
159
+ * label is set (e.g. `org.dxos.type.table`).
160
+ */
161
+ var getLabel = (entity, options) => getLabel$1(entity, options);
162
+ /**
163
+ * Set the label of an entity.
164
+ * Must be called within an `Entity.update` / `Obj.update` / `Relation.update` callback.
165
+ */
166
+ var setLabel = (entity, label) => setLabel$1(entity, label);
167
+ /**
168
+ * Get the description of an entity.
169
+ */
170
+ var getDescription = (entity) => getDescription$1(entity);
171
+ /**
172
+ * Get the icon annotation for an entity (object or relation), resolved via its type-level
173
+ * `IconAnnotation`. Returns the full `{ icon, hue }` annotation so callers can use both
174
+ * the phosphor icon name and the suggested colour.
175
+ */
176
+ var getIcon = (entity) => getIcon$1(entity);
177
+ /**
178
+ * Convert an entity to its JSON representation.
179
+ */
180
+ var toJSON = (entity) => objectToJSON(entity);
181
+ /**
182
+ * Subscribe to changes on an entity (object or relation).
183
+ * @returns Unsubscribe function.
184
+ */
185
+ var subscribe = (entity, callback) => {
186
+ return subscribe$1(entity, callback);
187
+ };
188
+ /**
189
+ * Perform mutations on an entity (object or relation) within a change context.
190
+ *
191
+ * Entities are read-only by default. Mutations are batched and notifications fire
192
+ * when the callback completes. Direct mutations outside of `Entity.update` will throw
193
+ * at runtime.
194
+ *
195
+ * @param entity - The echo entity (object or relation) to mutate.
196
+ * @param callback - Receives a mutable view of the entity. All mutations must occur here.
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * // Mutate within Entity.update
201
+ * Entity.update(entity, (obj) => {
202
+ * obj.name = 'Updated';
203
+ * obj.count = 42;
204
+ * });
205
+ *
206
+ * // Direct mutation throws
207
+ * entity.name = 'Bob'; // Error: Cannot modify outside Entity.update()
208
+ * ```
209
+ *
210
+ * Note: For type-specific operations, prefer `Obj.update` or `Relation.update`.
211
+ */
212
+ var update = (entity, callback) => {
213
+ change(entity, callback);
214
+ };
215
+ /**
216
+ * Add a tag to an entity.
217
+ * Must be called within an `Entity.update`, `Obj.update`, or `Relation.update` callback.
218
+ */
219
+ var addTag = (entity, tag) => addTag$1(entity, tag);
220
+ /**
221
+ * Remove a tag from an entity.
222
+ * Must be called within an `Entity.update`, `Obj.update`, or `Relation.update` callback.
223
+ */
224
+ var removeTag = (entity, tag) => removeTag$1(entity, tag);
225
+ var atom = makeEntity;
226
+ var labelAtom = makeLabelAtom;
227
+ var labelProperty = getLabelProperty;
228
+ //#endregion
229
+ export { Kind, KindId, KindSchema, Meta, SnapshotKindId, Unknown, addTag, atom, getDatabase, getDescription, getIcon, getKeys, getKind, getLabel, getMeta, getType, getTypeURI, getTypename, getURI, instanceOf, isDeleted, isEntity, isSnapshot, labelAtom, labelProperty, removeTag, setLabel, subscribe, Entity_exports as t, toJSON, update };
230
+
231
+ //# sourceMappingURL=Entity.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.mjs","names":[],"sources":["../../src/Entity.ts"],"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, options) : 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;\nexport const labelAtom = objInternal.makeLabelAtom;\nexport const labelProperty = internal.getLabelProperty;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,SAAS;AAEtB,IAAa,iBAAiB;AAO9B,IAAa,OAAO;AAEpB,IAAa,aAAa;;;;;;;;;;;;;;;;AA4C1B,IAAa,UAAkC,OAAO,OAAO,EAC3D,IAAI,OAAO,OACb,CAAC,CAAC,CAAC,KACD,OAAO,OAAO,OAAO,OAAO;CAAE,KAAK,OAAO;CAAQ,OAAO,OAAO;AAAQ,CAAC,CAAC,CAC5E;;;;;AA8BA,IAAa,WAAiD;;;;;;;;;;;;;;AAe9D,IAAa,eAGP,GAAG,SAAoD;CAC3D,IAAI,KAAK,WAAW,GAClB,QAAQ,WAAoB,aAAsB,KAAK,IAAI,MAAM;CAEnE,OAAO,aAAsB,KAAK,IAAI,KAAK,EAAE;AAC/C;;;;;AAMA,IAAa,cAAc,UAAsC;CAC/D,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;CAET,OAAQ,MAAc,oBAAoB,KAAA;AAC5C;AAGA,IAAa,UAAU;;;;AAKvB,IAAa,OAAsB;;;;;;;AAwBnC,IAAM,gBAAgB,WAA6B,mBAA4B,MAAM,MAAA,WAA0B;;;;;;;;;AAiB/G,IAAa,UAAU,QAAkB,YACvC,aAAa,MAAM,IAAI,SAAY,QAA0B,OAAO,IAAI,OAAgB,QAAmB,OAAO;;;;;;AAOpH,IAAa,cAAc,WACzB,aAAa,MAAM,IAAI,SAAY,IAAS,IAAI,aAAoB,MAAiB;;;;;;;;;;;;AAavF,IAAa,WAAW,WACtB,aAAa,MAAM,IAAI,OAAa,UAAiB,MAAM;;;;;;AAO7D,IAAa,eAAe,WAC1B,aAAa,MAAM,IAAI,cAAiB,MAAwB,IAAI,cAAqB,MAAiB;;;;AAK5G,IAAa,eAAe,WAAgD,cAAqB,MAAM;AAUvG,SAAgB,QAAQ,QAA4F;CAClH,OAAO,eAAwB,MAAM;AACvC;;;;AAKA,IAAa,WAAW,QAA4B,WAAiC,UAAiB,QAAQ,MAAM;;;;AAKpH,IAAa,aAAa,WAAwC,YAAmB,MAAM;;;;;;;AAQ3F,IAAa,YAAY,QAA4B,YACnD,WAAkB,QAAQ,OAAO;;;;;AAMnC,IAAa,YAAY,QAA0B,UAAwB,WAAkB,QAAQ,KAAK;;;;AAK1G,IAAa,kBAAkB,WAAmD,iBAAwB,MAAM;;;;;;AAOhH,IAAa,WAAW,WAAoE,UAAiB,MAAM;;;;AAKnH,IAAa,UAAU,WAAqC,aAAsB,MAAM;;;;;AAMxF,IAAa,aAAa,QAAiB,aAAuC;CAChF,OAAO,YAAmB,QAAQ,QAAQ;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,UAA6B,QAAW,aAA+C;CAClG,OAAgB,QAAQ,QAAQ;AAClC;;;;;AAMA,IAAa,UAAU,QAA0B,QAAgC,SAAgB,QAAQ,GAAG;;;;;AAM5G,IAAa,aAAa,QAA0B,QAAgC,YAAmB,QAAQ,GAAG;AAMlH,IAAa,OAAO;AACpB,IAAa,YAAY;AACzB,IAAa,gBAAgB"}
@@ -0,0 +1,105 @@
1
+ import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
2
+ import { BaseError } from "@dxos/errors";
3
+ //#region src/Err.ts
4
+ var Err_exports = /* @__PURE__ */ __exportAll({
5
+ BlobNotAvailableError: () => BlobNotAvailableError,
6
+ BlobTooLargeError: () => BlobTooLargeError,
7
+ BlobWriteError: () => BlobWriteError,
8
+ EntityNotFoundError: () => EntityNotFoundError,
9
+ GetReactiveError: () => GetReactiveError,
10
+ SchemaNotFoundError: () => SchemaNotFoundError,
11
+ TextEditNotFoundError: () => TextEditNotFoundError,
12
+ TextNotSupportedError: () => TextNotSupportedError
13
+ });
14
+ var SchemaNotFoundError = class extends BaseError.extend("SchemaNotFoundError", "Schema not found") {
15
+ constructor(schema, options) {
16
+ super({
17
+ context: { schema },
18
+ ...options
19
+ });
20
+ }
21
+ };
22
+ var EntityNotFoundError = class extends BaseError.extend("EntityNotFoundError", "Entity not found") {
23
+ constructor(uri, options) {
24
+ super({
25
+ context: { uri },
26
+ ...options
27
+ });
28
+ }
29
+ };
30
+ /**
31
+ * Thrown when a `Text` mutation is attempted on an object whose reactive handler does not implement
32
+ * string CRDT editing (e.g. a snapshot or a non-reactive value).
33
+ */
34
+ var TextNotSupportedError = class extends BaseError.extend("TextNotSupportedError", "Text operation is not supported for this object") {
35
+ constructor(operation, options) {
36
+ super({
37
+ context: { operation },
38
+ ...options
39
+ });
40
+ }
41
+ };
42
+ /**
43
+ * Thrown by `Text.apply` when a non-`replaceAll` edit's `oldString` is not found in the text.
44
+ */
45
+ var TextEditNotFoundError = class extends BaseError.extend("TextEditNotFoundError", "Edit text not found") {
46
+ constructor(oldString, options) {
47
+ super({
48
+ context: { oldString },
49
+ ...options
50
+ });
51
+ }
52
+ };
53
+ /**
54
+ * Thrown when a blob's bytes exceed the size limit of the storage backend writing them (inline
55
+ * storage's fixed cap, or a registered backend's own `maxSize`).
56
+ */
57
+ var BlobTooLargeError = class extends BaseError.extend("BlobTooLargeError", "Blob is too large for its backend") {
58
+ constructor(context, options) {
59
+ super({
60
+ context,
61
+ ...options
62
+ });
63
+ }
64
+ };
65
+ /**
66
+ * Thrown when a blob's bytes cannot be read from its backend.
67
+ */
68
+ var BlobNotAvailableError = class extends BaseError.extend("BlobNotAvailableError", "Blob is not available") {
69
+ constructor(context, options) {
70
+ super({
71
+ context,
72
+ ...options
73
+ });
74
+ }
75
+ };
76
+ /**
77
+ * Thrown when a blob's bytes fail to upload to its backend.
78
+ */
79
+ var BlobWriteError = class extends BaseError.extend("BlobWriteError", "Failed to write blob") {
80
+ constructor(context, options) {
81
+ super({
82
+ context,
83
+ ...options
84
+ });
85
+ }
86
+ };
87
+ /**
88
+ * Error thrown when a reactive object cannot be resolved from a snapshot.
89
+ * Extends `BaseError` with a `reason` and optional `snapshotId` in its context.
90
+ */
91
+ var GetReactiveError = class extends BaseError.extend("GetReactiveError", "Failed to get reactive object from snapshot") {
92
+ constructor(options) {
93
+ super({
94
+ context: {
95
+ reason: options.reason,
96
+ snapshotId: options.snapshotId
97
+ },
98
+ ...options
99
+ });
100
+ }
101
+ };
102
+ //#endregion
103
+ export { BlobNotAvailableError, BlobTooLargeError, BlobWriteError, EntityNotFoundError, GetReactiveError, SchemaNotFoundError, TextEditNotFoundError, TextNotSupportedError, Err_exports as t };
104
+
105
+ //# sourceMappingURL=Err.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Err.mjs","names":[],"sources":["../../src/Err.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { BaseError, type BaseErrorOptions } from '@dxos/errors';\nimport { type URI } from '@dxos/keys';\n\nexport class SchemaNotFoundError extends BaseError.extend('SchemaNotFoundError', 'Schema not found') {\n constructor(schema: string, options?: BaseErrorOptions) {\n super({ context: { schema }, ...options });\n }\n}\n\nexport class EntityNotFoundError extends BaseError.extend('EntityNotFoundError', 'Entity not found') {\n constructor(uri: URI.URI, options?: BaseErrorOptions) {\n super({ context: { uri }, ...options });\n }\n}\n\n/**\n * Thrown when a `Text` mutation is attempted on an object whose reactive handler does not implement\n * string CRDT editing (e.g. a snapshot or a non-reactive value).\n */\nexport class TextNotSupportedError extends BaseError.extend(\n 'TextNotSupportedError',\n 'Text operation is not supported for this object',\n) {\n constructor(operation: string, options?: BaseErrorOptions) {\n super({ context: { operation }, ...options });\n }\n}\n\n/**\n * Thrown by `Text.apply` when a non-`replaceAll` edit's `oldString` is not found in the text.\n */\nexport class TextEditNotFoundError extends BaseError.extend('TextEditNotFoundError', 'Edit text not found') {\n constructor(oldString: string, options?: BaseErrorOptions) {\n super({ context: { oldString }, ...options });\n }\n}\n\n/**\n * Thrown when a blob's bytes exceed the size limit of the storage backend writing them (inline\n * storage's fixed cap, or a registered backend's own `maxSize`).\n */\nexport class BlobTooLargeError extends BaseError.extend('BlobTooLargeError', 'Blob is too large for its backend') {\n constructor(context: { size: number; limit: number }, options?: BaseErrorOptions) {\n super({ context, ...options });\n }\n}\n\n/**\n * Reason why a blob's bytes could not be read.\n * - `offline`: The backend's transport failed (e.g. network unavailable).\n * - `not-found`: The backend could not locate the bytes for the given URI.\n * - `backend-not-registered`: No backend is registered for the URI's scheme.\n */\nexport type BlobNotAvailableReason = 'offline' | 'not-found' | 'backend-not-registered';\n\n/**\n * Thrown when a blob's bytes cannot be read from its backend.\n */\nexport class BlobNotAvailableError extends BaseError.extend('BlobNotAvailableError', 'Blob is not available') {\n constructor(context: { backend: string; key: string; reason: BlobNotAvailableReason }, options?: BaseErrorOptions) {\n super({ context, ...options });\n }\n}\n\n/**\n * Thrown when a blob's bytes fail to upload to its backend.\n */\nexport class BlobWriteError extends BaseError.extend('BlobWriteError', 'Failed to write blob') {\n constructor(context: { backend: string }, options?: BaseErrorOptions) {\n super({ context, ...options });\n }\n}\n\n/**\n * Reason why getting a reactive object from a snapshot failed.\n * - `no-database`: The snapshot is not associated with a database.\n * - `object-not-found`: The object was removed or does not exist in the database.\n */\nexport type GetReactiveErrorReason = 'no-database' | 'object-not-found';\n\n/**\n * Error thrown when a reactive object cannot be resolved from a snapshot.\n * Extends `BaseError` with a `reason` and optional `snapshotId` in its context.\n */\nexport class GetReactiveError extends BaseError.extend(\n 'GetReactiveError',\n 'Failed to get reactive object from snapshot',\n) {\n constructor(options: { reason: GetReactiveErrorReason; snapshotId?: string } & BaseErrorOptions) {\n super({ context: { reason: options.reason, snapshotId: options.snapshotId }, ...options });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AASA,IAAa,sBAAb,cAAyC,UAAU,OAAO,uBAAuB,kBAAkB,CAAC,CAAC;CACnG,YAAY,QAAgB,SAA4B;EACtD,MAAM;GAAE,SAAS,EAAE,OAAO;GAAG,GAAG;EAAQ,CAAC;CAC3C;AACF;AAEA,IAAa,sBAAb,cAAyC,UAAU,OAAO,uBAAuB,kBAAkB,CAAC,CAAC;CACnG,YAAY,KAAc,SAA4B;EACpD,MAAM;GAAE,SAAS,EAAE,IAAI;GAAG,GAAG;EAAQ,CAAC;CACxC;AACF;;;;;AAMA,IAAa,wBAAb,cAA2C,UAAU,OACnD,yBACA,iDACF,CAAC,CAAC;CACA,YAAY,WAAmB,SAA4B;EACzD,MAAM;GAAE,SAAS,EAAE,UAAU;GAAG,GAAG;EAAQ,CAAC;CAC9C;AACF;;;;AAKA,IAAa,wBAAb,cAA2C,UAAU,OAAO,yBAAyB,qBAAqB,CAAC,CAAC;CAC1G,YAAY,WAAmB,SAA4B;EACzD,MAAM;GAAE,SAAS,EAAE,UAAU;GAAG,GAAG;EAAQ,CAAC;CAC9C;AACF;;;;;AAMA,IAAa,oBAAb,cAAuC,UAAU,OAAO,qBAAqB,mCAAmC,CAAC,CAAC;CAChH,YAAY,SAA0C,SAA4B;EAChF,MAAM;GAAE;GAAS,GAAG;EAAQ,CAAC;CAC/B;AACF;;;;AAaA,IAAa,wBAAb,cAA2C,UAAU,OAAO,yBAAyB,uBAAuB,CAAC,CAAC;CAC5G,YAAY,SAA2E,SAA4B;EACjH,MAAM;GAAE;GAAS,GAAG;EAAQ,CAAC;CAC/B;AACF;;;;AAKA,IAAa,iBAAb,cAAoC,UAAU,OAAO,kBAAkB,sBAAsB,CAAC,CAAC;CAC7F,YAAY,SAA8B,SAA4B;EACpE,MAAM;GAAE;GAAS,GAAG;EAAQ,CAAC;CAC/B;AACF;;;;;AAaA,IAAa,mBAAb,cAAsC,UAAU,OAC9C,oBACA,6CACF,CAAC,CAAC;CACA,YAAY,SAAqF;EAC/F,MAAM;GAAE,SAAS;IAAE,QAAQ,QAAQ;IAAQ,YAAY,QAAQ;GAAW;GAAG,GAAG;EAAQ,CAAC;CAC3F;AACF"}