@dxos/echo 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/dist/lib/Annotation.mjs +3 -0
  2. package/dist/lib/Blob.mjs +160 -0
  3. package/dist/lib/Blob.mjs.map +1 -0
  4. package/dist/lib/Database.mjs +2 -0
  5. package/dist/lib/Entity.mjs +231 -0
  6. package/dist/lib/Entity.mjs.map +1 -0
  7. package/dist/lib/Err.mjs +105 -0
  8. package/dist/lib/Err.mjs.map +1 -0
  9. package/dist/lib/Feed.mjs +338 -0
  10. package/dist/lib/Feed.mjs.map +1 -0
  11. package/dist/lib/Filter.mjs +380 -0
  12. package/dist/lib/Filter.mjs.map +1 -0
  13. package/dist/lib/Format.mjs +47 -0
  14. package/dist/lib/Format.mjs.map +1 -0
  15. package/dist/lib/JsonSchema.mjs +21 -0
  16. package/dist/lib/JsonSchema.mjs.map +1 -0
  17. package/dist/lib/Key.mjs +15 -0
  18. package/dist/lib/Key.mjs.map +1 -0
  19. package/dist/lib/Migration.mjs +38 -0
  20. package/dist/lib/Migration.mjs.map +1 -0
  21. package/dist/lib/Obj.mjs +660 -0
  22. package/dist/lib/Obj.mjs.map +1 -0
  23. package/dist/lib/Order.mjs +65 -0
  24. package/dist/lib/Order.mjs.map +1 -0
  25. package/dist/lib/Query.mjs +336 -0
  26. package/dist/lib/Query.mjs.map +1 -0
  27. package/dist/lib/QueryResult.mjs +7 -0
  28. package/dist/lib/QueryResult.mjs.map +1 -0
  29. package/dist/lib/Ref.mjs +44 -0
  30. package/dist/lib/Ref.mjs.map +1 -0
  31. package/dist/lib/Registry.mjs +35 -0
  32. package/dist/lib/Registry.mjs.map +1 -0
  33. package/dist/lib/Relation.mjs +397 -0
  34. package/dist/lib/Relation.mjs.map +1 -0
  35. package/dist/lib/Scope.mjs +51 -0
  36. package/dist/lib/Scope.mjs.map +1 -0
  37. package/dist/lib/Tag.mjs +70 -0
  38. package/dist/lib/Tag.mjs.map +1 -0
  39. package/dist/lib/Text.mjs +82 -0
  40. package/dist/lib/Text.mjs.map +1 -0
  41. package/dist/lib/Type.mjs +371 -0
  42. package/dist/lib/Type.mjs.map +1 -0
  43. package/dist/lib/chunk-Annotation.mjs +221 -0
  44. package/dist/lib/chunk-Annotation.mjs.map +1 -0
  45. package/dist/lib/chunk-Database.mjs +918 -0
  46. package/dist/lib/chunk-Database.mjs.map +1 -0
  47. package/dist/lib/chunk-atom-snapshot.mjs +249 -0
  48. package/dist/lib/chunk-atom-snapshot.mjs.map +1 -0
  49. package/dist/lib/chunk-internal.mjs +2775 -0
  50. package/dist/lib/chunk-internal.mjs.map +1 -0
  51. package/dist/lib/chunk-json-schema.mjs +660 -0
  52. package/dist/lib/chunk-json-schema.mjs.map +1 -0
  53. package/dist/lib/chunk-number.mjs +164 -0
  54. package/dist/lib/chunk-number.mjs.map +1 -0
  55. package/dist/lib/chunk-ref-array.mjs +31 -0
  56. package/dist/lib/chunk-ref-array.mjs.map +1 -0
  57. package/dist/lib/chunk-ref.mjs +590 -0
  58. package/dist/lib/chunk-ref.mjs.map +1 -0
  59. package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
  60. package/dist/lib/chunk-select.mjs +186 -0
  61. package/dist/lib/chunk-select.mjs.map +1 -0
  62. package/dist/lib/chunk-src.mjs +234 -0
  63. package/dist/lib/chunk-src.mjs.map +1 -0
  64. package/dist/lib/chunk-util.mjs +140 -0
  65. package/dist/lib/chunk-util.mjs.map +1 -0
  66. package/dist/lib/index.mjs +24 -0
  67. package/dist/lib/internal.mjs +10 -0
  68. package/dist/lib/testing.mjs +346 -0
  69. package/dist/lib/testing.mjs.map +1 -0
  70. package/dist/types/src/Aggregate.d.ts +86 -0
  71. package/dist/types/src/Aggregate.d.ts.map +1 -0
  72. package/dist/types/src/Blob.d.ts +153 -0
  73. package/dist/types/src/Blob.d.ts.map +1 -0
  74. package/dist/types/src/Blob.test.d.ts +2 -0
  75. package/dist/types/src/Blob.test.d.ts.map +1 -0
  76. package/dist/types/src/Database.d.ts +153 -4
  77. package/dist/types/src/Database.d.ts.map +1 -1
  78. package/dist/types/src/Err.d.ts +116 -0
  79. package/dist/types/src/Err.d.ts.map +1 -1
  80. package/dist/types/src/Feed.d.ts +116 -28
  81. package/dist/types/src/Feed.d.ts.map +1 -1
  82. package/dist/types/src/Feed.test.d.ts +2 -0
  83. package/dist/types/src/Feed.test.d.ts.map +1 -0
  84. package/dist/types/src/Filter.d.ts +14 -6
  85. package/dist/types/src/Filter.d.ts.map +1 -1
  86. package/dist/types/src/Hypergraph.d.ts +18 -0
  87. package/dist/types/src/Hypergraph.d.ts.map +1 -1
  88. package/dist/types/src/Json.d.ts.map +1 -1
  89. package/dist/types/src/Obj.d.ts +14 -1
  90. package/dist/types/src/Obj.d.ts.map +1 -1
  91. package/dist/types/src/Order.d.ts +9 -3
  92. package/dist/types/src/Order.d.ts.map +1 -1
  93. package/dist/types/src/Query.d.ts +107 -26
  94. package/dist/types/src/Query.d.ts.map +1 -1
  95. package/dist/types/src/Relation.d.ts +6 -0
  96. package/dist/types/src/Relation.d.ts.map +1 -1
  97. package/dist/types/src/Type.d.ts.map +1 -1
  98. package/dist/types/src/View.d.ts +1 -1
  99. package/dist/types/src/index.d.ts +2 -0
  100. package/dist/types/src/index.d.ts.map +1 -1
  101. package/dist/types/src/internal/Entity/api.d.ts +6 -0
  102. package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
  103. package/dist/types/src/internal/Entity/model.d.ts +3 -2
  104. package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
  105. package/dist/types/src/internal/Filter/match.d.ts.map +1 -1
  106. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +34 -8
  107. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -1
  108. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
  109. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
  110. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
  111. package/dist/types/src/internal/Query/pretty.d.ts.map +1 -1
  112. package/dist/types/src/internal/Query/query-result-effect.d.ts.map +1 -1
  113. package/dist/types/src/internal/common/proxy/make-object.d.ts +13 -0
  114. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
  115. package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -1
  116. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -1
  117. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +12 -0
  118. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
  119. package/dist/types/src/internal/common/types/index.d.ts +1 -0
  120. package/dist/types/src/internal/common/types/index.d.ts.map +1 -1
  121. package/dist/types/src/internal/common/types/model-symbols.d.ts +5 -0
  122. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
  123. package/dist/types/src/internal/common/types/projection.d.ts +32 -0
  124. package/dist/types/src/internal/common/types/projection.d.ts.map +1 -0
  125. package/dist/types/tsconfig.tsbuildinfo +1 -1
  126. package/package.json +40 -35
  127. package/src/Aggregate.ts +105 -0
  128. package/src/Blob.test.ts +45 -0
  129. package/src/Blob.ts +205 -0
  130. package/src/Database.ts +207 -17
  131. package/src/Err.ts +36 -0
  132. package/src/Feed.test.ts +188 -0
  133. package/src/Feed.ts +238 -62
  134. package/src/Filter.ts +28 -10
  135. package/src/Hypergraph.ts +18 -0
  136. package/src/Json.ts +1 -0
  137. package/src/Obj.test.ts +2 -2
  138. package/src/Obj.ts +21 -1
  139. package/src/Order.ts +16 -9
  140. package/src/Query.test.ts +319 -2
  141. package/src/Query.ts +165 -51
  142. package/src/Relation.ts +14 -0
  143. package/src/Type.ts +5 -6
  144. package/src/index.ts +2 -0
  145. package/src/internal/Entity/api.ts +11 -1
  146. package/src/internal/Entity/model.ts +3 -0
  147. package/src/internal/Filter/match.ts +30 -1
  148. package/src/internal/JsonSchema/json-schema-type.ts +14 -2
  149. package/src/internal/JsonSchema/json-schema.test.ts +28 -1
  150. package/src/internal/JsonSchema/json-schema.ts +33 -6
  151. package/src/internal/Obj/atoms.ts +4 -2
  152. package/src/internal/Obj/json-serializer.test.ts +162 -2
  153. package/src/internal/Obj/json-serializer.ts +6 -0
  154. package/src/internal/Query/pretty.ts +19 -1
  155. package/src/internal/Query/query-result-effect.ts +2 -4
  156. package/src/internal/Ref/atoms.ts +1 -1
  157. package/src/internal/common/proxy/change-context.ts +1 -1
  158. package/src/internal/common/proxy/make-object.ts +42 -3
  159. package/src/internal/common/proxy/reactive.ts +5 -0
  160. package/src/internal/common/proxy/symbols.ts +1 -0
  161. package/src/internal/common/proxy/typed-handler.ts +71 -29
  162. package/src/internal/common/types/index.ts +1 -0
  163. package/src/internal/common/types/model-symbols.ts +6 -0
  164. package/src/internal/common/types/projection.ts +45 -0
  165. package/src/testing/test-data.ts +14 -14
  166. package/dist/lib/neutral/Annotation.mjs +0 -90
  167. package/dist/lib/neutral/Annotation.mjs.map +0 -7
  168. package/dist/lib/neutral/Database.mjs +0 -42
  169. package/dist/lib/neutral/Database.mjs.map +0 -7
  170. package/dist/lib/neutral/Entity.mjs +0 -76
  171. package/dist/lib/neutral/Entity.mjs.map +0 -7
  172. package/dist/lib/neutral/Err.mjs +0 -16
  173. package/dist/lib/neutral/Err.mjs.map +0 -7
  174. package/dist/lib/neutral/Feed.mjs +0 -50
  175. package/dist/lib/neutral/Feed.mjs.map +0 -7
  176. package/dist/lib/neutral/Filter.mjs +0 -72
  177. package/dist/lib/neutral/Filter.mjs.map +0 -7
  178. package/dist/lib/neutral/Format.mjs +0 -82
  179. package/dist/lib/neutral/Format.mjs.map +0 -7
  180. package/dist/lib/neutral/JsonSchema.mjs +0 -18
  181. package/dist/lib/neutral/JsonSchema.mjs.map +0 -7
  182. package/dist/lib/neutral/Key.mjs +0 -16
  183. package/dist/lib/neutral/Key.mjs.map +0 -7
  184. package/dist/lib/neutral/Migration.mjs +0 -18
  185. package/dist/lib/neutral/Migration.mjs.map +0 -7
  186. package/dist/lib/neutral/Obj.mjs +0 -128
  187. package/dist/lib/neutral/Obj.mjs.map +0 -7
  188. package/dist/lib/neutral/Order.mjs +0 -16
  189. package/dist/lib/neutral/Order.mjs.map +0 -7
  190. package/dist/lib/neutral/Query.mjs +0 -38
  191. package/dist/lib/neutral/Query.mjs.map +0 -7
  192. package/dist/lib/neutral/QueryResult.mjs +0 -2
  193. package/dist/lib/neutral/QueryResult.mjs.map +0 -7
  194. package/dist/lib/neutral/Ref.mjs +0 -25
  195. package/dist/lib/neutral/Ref.mjs.map +0 -7
  196. package/dist/lib/neutral/Registry.mjs +0 -14
  197. package/dist/lib/neutral/Registry.mjs.map +0 -7
  198. package/dist/lib/neutral/Relation.mjs +0 -97
  199. package/dist/lib/neutral/Relation.mjs.map +0 -7
  200. package/dist/lib/neutral/Scope.mjs +0 -12
  201. package/dist/lib/neutral/Scope.mjs.map +0 -7
  202. package/dist/lib/neutral/Tag.mjs +0 -32
  203. package/dist/lib/neutral/Tag.mjs.map +0 -7
  204. package/dist/lib/neutral/Text.mjs +0 -25
  205. package/dist/lib/neutral/Text.mjs.map +0 -7
  206. package/dist/lib/neutral/Type.mjs +0 -65
  207. package/dist/lib/neutral/Type.mjs.map +0 -7
  208. package/dist/lib/neutral/chunk-2HKGAQM4.mjs +0 -1394
  209. package/dist/lib/neutral/chunk-2HKGAQM4.mjs.map +0 -7
  210. package/dist/lib/neutral/chunk-2ZHECXUR.mjs +0 -95
  211. package/dist/lib/neutral/chunk-2ZHECXUR.mjs.map +0 -7
  212. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs +0 -336
  213. package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs.map +0 -7
  214. package/dist/lib/neutral/chunk-3TN2VMI4.mjs +0 -714
  215. package/dist/lib/neutral/chunk-3TN2VMI4.mjs.map +0 -7
  216. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs +0 -104
  217. package/dist/lib/neutral/chunk-42L4HJ3Z.mjs.map +0 -7
  218. package/dist/lib/neutral/chunk-4A2NWKRJ.mjs +0 -747
  219. package/dist/lib/neutral/chunk-4A2NWKRJ.mjs.map +0 -7
  220. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs +0 -25
  221. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +0 -7
  222. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs +0 -1531
  223. package/dist/lib/neutral/chunk-ACFAOTKJ.mjs.map +0 -7
  224. package/dist/lib/neutral/chunk-BEFR7LEA.mjs +0 -170
  225. package/dist/lib/neutral/chunk-BEFR7LEA.mjs.map +0 -7
  226. package/dist/lib/neutral/chunk-BXIKXT7Q.mjs +0 -89
  227. package/dist/lib/neutral/chunk-BXIKXT7Q.mjs.map +0 -7
  228. package/dist/lib/neutral/chunk-C57XMMBY.mjs +0 -206
  229. package/dist/lib/neutral/chunk-C57XMMBY.mjs.map +0 -7
  230. package/dist/lib/neutral/chunk-C62JYFAD.mjs +0 -183
  231. package/dist/lib/neutral/chunk-C62JYFAD.mjs.map +0 -7
  232. package/dist/lib/neutral/chunk-FSGX2R62.mjs +0 -48
  233. package/dist/lib/neutral/chunk-FSGX2R62.mjs.map +0 -7
  234. package/dist/lib/neutral/chunk-HBXT3GSB.mjs +0 -459
  235. package/dist/lib/neutral/chunk-HBXT3GSB.mjs.map +0 -7
  236. package/dist/lib/neutral/chunk-IQR45HAD.mjs +0 -31
  237. package/dist/lib/neutral/chunk-IQR45HAD.mjs.map +0 -7
  238. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  239. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  240. package/dist/lib/neutral/chunk-KCBW4BR6.mjs +0 -424
  241. package/dist/lib/neutral/chunk-KCBW4BR6.mjs.map +0 -7
  242. package/dist/lib/neutral/chunk-L3E5IXAE.mjs +0 -575
  243. package/dist/lib/neutral/chunk-L3E5IXAE.mjs.map +0 -7
  244. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs +0 -56
  245. package/dist/lib/neutral/chunk-PRC4FEKJ.mjs.map +0 -7
  246. package/dist/lib/neutral/chunk-SCT6FFCR.mjs +0 -351
  247. package/dist/lib/neutral/chunk-SCT6FFCR.mjs.map +0 -7
  248. package/dist/lib/neutral/chunk-TOCVVFK2.mjs +0 -75
  249. package/dist/lib/neutral/chunk-TOCVVFK2.mjs.map +0 -7
  250. package/dist/lib/neutral/chunk-U53LSQQA.mjs +0 -41
  251. package/dist/lib/neutral/chunk-U53LSQQA.mjs.map +0 -7
  252. package/dist/lib/neutral/chunk-UGFFV2FR.mjs +0 -27
  253. package/dist/lib/neutral/chunk-UGFFV2FR.mjs.map +0 -7
  254. package/dist/lib/neutral/chunk-UWLP4RFM.mjs +0 -7
  255. package/dist/lib/neutral/chunk-UWLP4RFM.mjs.map +0 -7
  256. package/dist/lib/neutral/chunk-UZHCQ6NI.mjs +0 -283
  257. package/dist/lib/neutral/chunk-UZHCQ6NI.mjs.map +0 -7
  258. package/dist/lib/neutral/chunk-WISOH2XH.mjs +0 -36
  259. package/dist/lib/neutral/chunk-WISOH2XH.mjs.map +0 -7
  260. package/dist/lib/neutral/chunk-WKIT2YY5.mjs +0 -34
  261. package/dist/lib/neutral/chunk-WKIT2YY5.mjs.map +0 -7
  262. package/dist/lib/neutral/chunk-XB6ISRAO.mjs +0 -271
  263. package/dist/lib/neutral/chunk-XB6ISRAO.mjs.map +0 -7
  264. package/dist/lib/neutral/chunk-XXL42WCB.mjs +0 -84
  265. package/dist/lib/neutral/chunk-XXL42WCB.mjs.map +0 -7
  266. package/dist/lib/neutral/chunk-XXWK4J53.mjs +0 -117
  267. package/dist/lib/neutral/chunk-XXWK4J53.mjs.map +0 -7
  268. package/dist/lib/neutral/index.mjs +0 -115
  269. package/dist/lib/neutral/index.mjs.map +0 -7
  270. package/dist/lib/neutral/internal/index.mjs +0 -581
  271. package/dist/lib/neutral/internal/index.mjs.map +0 -7
  272. package/dist/lib/neutral/meta.json +0 -1
  273. package/dist/lib/neutral/testing/index.mjs +0 -477
  274. package/dist/lib/neutral/testing/index.mjs.map +0 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-json-schema.mjs","names":[],"sources":["../../src/internal/JsonSchema/annotations.ts","../../src/internal/JsonSchema/json-schema-type.ts","../../src/internal/JsonSchema/json-schema.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { GeneratorAnnotationId, LabelAnnotationId, PropertyMetaAnnotationId } from '../Annotation/annotations';\nimport { CurrencyAnnotationId, FormatAnnotationId } from '../Format';\nimport { type JsonSchemaEchoAnnotations, type JsonSchemaType } from '../JsonSchema';\n\n//\n// This file configures annotations for JSON encoding/decoding.\n//\n\n// Go on the root level.\ntype RootJsonSchemaProperty = keyof JsonSchemaType;\n\n// Go on the namespaced `annotations` property.\ntype NamespacedJsonSchemaProperty = keyof JsonSchemaEchoAnnotations;\n\n/**\n * List of annotations for JSON encoding/decoding.\n * Omits default effect-schema annotations since they are encoded with default serializer.\n */\n// TODO(burdon): Reconcile with `EchoAnnotations`.\nexport const CustomAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {\n format: FormatAnnotationId,\n currency: CurrencyAnnotationId,\n};\n\n/**\n * List of annotations for JSON decoding only.\n * Includes default effect annotations.\n */\nexport const DecodedAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {\n title: SchemaAST.TitleAnnotationId,\n description: SchemaAST.DescriptionAnnotationId,\n};\n\n/**\n * Annotations that go into ECHO namespace in json-schema.\n */\n// TODO(dmaretskyi): Consider removing ECHO namespace and putting them at the top level.\n// TODO(dmaretskyi): Move to format.ts when circular imports are solved\nexport const EchoAnnotations: Partial<Record<NamespacedJsonSchemaProperty, symbol>> = {\n // TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.\n meta: PropertyMetaAnnotationId,\n generator: GeneratorAnnotationId,\n labelProp: LabelAnnotationId,\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { SchemaEx } from '@dxos/effect';\n\nimport { type Mutable } from '../common/proxy';\nimport { EntityKindSchema } from '../common/types';\nimport { FormatAnnotation, TypeFormat } from '../Format';\n\n//\n// JSON Schema\n//\n\n// TODO(burdon): Reuse/reconcile with ScalarTypeEnum (handle arrays).\nconst SimpleTypes = Schema.Literal('array', 'boolean', 'integer', 'null', 'number', 'object', 'string');\n\nconst NonNegativeInteger = Schema.Number.pipe(Schema.greaterThanOrEqualTo(0));\n\nconst StringArray = Schema.Array(Schema.String);\n\nconst JsonSchemaOrBoolean = Schema.Union(\n Schema.suspend(() => JsonSchemaType),\n Schema.Boolean,\n);\n\n/**\n * Go under the `annotations` property.\n */\nexport const JsonSchemaEchoAnnotations = Schema.Struct({\n /**\n * Label for this schema.\n * Mapped from {@link LabelAnnotationId}.\n */\n labelProp: Schema.optional(Schema.Union(SchemaEx.JsonPath, Schema.Array(SchemaEx.JsonPath))),\n\n /**\n * Generator function for this schema.\n * Mapped from {@link GeneratorAnnotationId}; mirrors `GeneratorAnnotationValue`, whose object\n * form (`{ generator, args }`) is used by schemas like `Task` — a narrower contract here makes\n * those schemas unserializable (`Operation.serialize` fails on any operation referencing them).\n */\n generator: Schema.optional(\n Schema.Union(\n Schema.String,\n Schema.Tuple(Schema.String, Schema.Number),\n Schema.Struct({\n generator: Schema.String,\n args: Schema.optional(Schema.Array(Schema.Any)),\n probability: Schema.optional(Schema.Number),\n }),\n ),\n ),\n\n /**\n * {@link PropertyMeta} annotations get serialized here.\n */\n meta: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.Any,\n }),\n ),\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): We risk old schema not passing validation due to the extra fields. Remove when we are sure this is safe.\n type: Schema.optional(\n Schema.Struct({\n typename: Schema.String,\n version: Schema.String,\n\n // Not used.\n schemaId: Schema.optional(Schema.String),\n }),\n ),\n\n /**\n * @deprecated Superseded by `meta`.\n */\n annotations: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.Any,\n }),\n ),\n});\nexport type JsonSchemaEchoAnnotations = Schema.Schema.Type<typeof JsonSchemaEchoAnnotations>;\n\n/**\n * Describes a schema for the JSON-schema objects stored in ECHO.\n * Contains extensions for ECHO (e.g., references).\n * Ref: https://json-schema.org/draft-07/schema\n */\n// TODO(burdon): Integrate with Effect Serializable?\n// TODO(dmaretskyi): Update to latest draft: https://json-schema.org/draft/2020-12\nconst _JsonSchemaType = Schema.Struct({\n /**\n * Identifier for this schema.\n * This schema might be referenced by $ref clause in other schemas.\n */\n // TODO(dmaretskyi): Specify how the ids are generated.\n // TODO(dmaretskyi): For type dxns, should this include the version?\n $id: Schema.optional(Schema.String),\n\n /**\n * Schema of this schema.\n * Set to \"https://json-schema.org/draft-07/schema\".\n */\n $schema: Schema.optional(Schema.String),\n\n /**\n * Reference to another schema.\n */\n $ref: Schema.optional(Schema.String),\n\n /**\n * Comments are ignored when interpreting the schema.\n */\n $comment: Schema.optional(Schema.String),\n\n /**\n * Defines whether this schema is an object schema or a relation schema.\n */\n entityKind: Schema.optional(EntityKindSchema),\n\n /**\n * Typename of this schema.\n * Only on schema representing an ECHO object.\n *\n * @example 'com.example.type.my-type'\n */\n typename: Schema.optional(Schema.String),\n\n /**\n * Version of this schema.\n * Custom dialect for ECHO.\n */\n version: Schema.optional(Schema.String),\n\n /**\n * Target of this relation.\n * Only for relation schemas.\n * The referenced schema must be an object schema.\n */\n relationTarget: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n /**\n * Source of this relation.\n * Only for relation schemas.\n * The referenced schema must be an object schema.\n */\n relationSource: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n /**\n * Title of this schema.\n */\n title: Schema.optional(Schema.String),\n\n /**\n * Description of this schema.\n */\n description: Schema.optional(Schema.String),\n\n /**\n * Whether this schema is read-only.\n */\n readOnly: Schema.optional(Schema.Boolean),\n\n /**\n * Whether this schema is write-only.\n */\n writeOnly: Schema.optional(Schema.Boolean),\n\n /**\n * Examples of instances of this schema.\n */\n examples: Schema.optional(Schema.Array(Schema.Any)),\n\n /**\n * Default value for this schema.\n */\n default: Schema.optional(Schema.Any),\n\n /**\n * This schema only matches values that are equal to this value.\n */\n const: Schema.optional(Schema.Any),\n\n /**\n * This schema only matches one of the values in this array.\n */\n enum: Schema.optional(Schema.Array(Schema.Any)),\n\n /**\n * Base type of the schema.\n */\n type: Schema.optional(Schema.Union(SimpleTypes, Schema.Array(SimpleTypes))),\n\n //\n // Numbers.\n //\n\n multipleOf: Schema.optional(Schema.Number.pipe(Schema.greaterThan(0))),\n maximum: Schema.optional(Schema.Number),\n exclusiveMaximum: Schema.optional(Schema.Number),\n minimum: Schema.optional(Schema.Number),\n exclusiveMinimum: Schema.optional(Schema.Number),\n\n //\n // Strings.\n //\n\n maxLength: Schema.optional(NonNegativeInteger),\n\n /**\n * Regex pattern for strings.\n */\n pattern: Schema.optional(Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex))),\n\n /**\n * Serialized from {@link FormatAnnotationId}.\n */\n format: Schema.optional(Schema.String),\n\n //\n // Arrays\n //\n\n minLength: Schema.optional(NonNegativeInteger),\n items: Schema.optional(\n Schema.Union(\n Schema.suspend(() => JsonSchemaType),\n Schema.Array(Schema.suspend(() => JsonSchemaType)),\n ),\n ),\n additionalItems: Schema.optional(\n Schema.Union(\n Schema.suspend(() => JsonSchemaType),\n Schema.Boolean,\n ),\n ),\n maxItems: Schema.optional(NonNegativeInteger),\n minItems: Schema.optional(NonNegativeInteger),\n uniqueItems: Schema.optional(Schema.Boolean),\n contains: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n //\n // Objects\n //\n\n maxProperties: Schema.optional(NonNegativeInteger),\n minProperties: Schema.optional(NonNegativeInteger),\n required: Schema.optional(StringArray),\n\n /**\n * Non-standard JSON Schema extension.\n * Defines the order of properties in the object.\n * The unmentioned properties are placed at the end.\n *\n * Related: https://github.com/json-schema/json-schema/issues/119\n */\n propertyOrder: Schema.optional(StringArray),\n\n additionalProperties: Schema.optional(JsonSchemaOrBoolean),\n properties: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n patternProperties: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n propertyNames: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n definitions: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n dependencies: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => Schema.Union(Schema.String, StringArray, JsonSchemaType)).annotations({\n identifier: 'dependency',\n description: 'Dependency',\n }),\n }),\n ),\n\n contentMediaType: Schema.optional(Schema.String),\n contentEncoding: Schema.optional(Schema.String),\n\n if: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n then: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n else: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n allOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n anyOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n oneOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n not: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n $defs: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n\n //\n // ECHO extensions.\n //\n\n currency: Schema.optional(Schema.String),\n\n reference: Schema.optional(\n Schema.Struct({\n schema: Schema.suspend(() => JsonSchemaType),\n schemaVersion: Schema.optional(Schema.String),\n schemaObject: Schema.optional(Schema.String),\n }),\n ),\n\n /**\n * ECHO-specific annotations.\n */\n // TODO(dmaretskyi): Since we are adding a lot of new extensions to the JSON Schema, it is safer to namespace them here.\n annotations: Schema.optional(JsonSchemaEchoAnnotations),\n\n /**\n * @deprecated Use `annotations` instead.\n */\n echo: Schema.optional(JsonSchemaEchoAnnotations),\n}).annotations({ identifier: 'jsonSchema', description: 'JSON Schema' });\n\nexport const JsonSchemaFields = Object.keys(_JsonSchemaType.fields);\n\n/**\n * https://json-schema.org/draft-07/schema\n */\n// TODO(burdon): Reconcile with @effect/Schema/JSONSchema\nexport interface JsonSchemaType extends Schema.Schema.Type<typeof _JsonSchemaType> {}\n\nexport const JsonSchemaType: Schema.Schema<JsonSchemaType> = _JsonSchemaType;\n\n// TODO(burdon): Factor out JSON schema utils.\n\nexport const getSchemaProperty = (schema: JsonSchemaType, property: SchemaEx.JsonProp): JsonSchemaType | undefined => {\n return schema.properties?.[property];\n};\n\n// TODO(burdon): Properties should be ordered.\nexport const setSchemaProperty = (\n schema: Mutable<JsonSchemaType>,\n property: SchemaEx.JsonProp,\n value: Mutable<JsonSchemaType>,\n) => {\n schema.properties ??= {};\n schema.properties[property] = value;\n return schema;\n};\n\n/**\n * @internal\n */\nexport const ECHO_ANNOTATIONS_NS_DEPRECATED_KEY: keyof JsonSchemaType = 'echo';\n\n/**\n * @internal\n */\nexport const ECHO_ANNOTATIONS_NS_KEY = 'annotations';\n\n/**\n * @internal\n * @returns ECHO annotations namespace object in its normalized form.\n *\n * `meta` holds PropertyMeta annotations.\n * `annotations` holds other annotations.\n */\nexport const getNormalizedEchoAnnotations = (obj: JsonSchemaType): JsonSchemaEchoAnnotations | undefined => {\n if (obj[ECHO_ANNOTATIONS_NS_KEY] != null && obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {\n return normalizeEchoAnnotations({\n ...obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY],\n ...obj[ECHO_ANNOTATIONS_NS_KEY],\n });\n } else if (obj[ECHO_ANNOTATIONS_NS_KEY] != null) {\n return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_KEY]!);\n } else if (obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {\n return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY]!);\n } else {\n return undefined;\n }\n};\n\nconst normalizeEchoAnnotations = (obj: JsonSchemaEchoAnnotations): JsonSchemaEchoAnnotations => {\n if (!obj.annotations) {\n return obj;\n } else {\n const res = {\n ...obj,\n meta: {\n ...obj.annotations,\n ...(obj.meta ?? {}),\n },\n };\n delete res.annotations;\n return res;\n }\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Array from 'effect/Array';\nimport * as Function from 'effect/Function';\nimport * as JSONSchema from 'effect/JSONSchema';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport type * as Types from 'effect/Types';\n\nimport { raise } from '@dxos/debug';\nimport { SchemaEx } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, EntityId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { clearUndefined, orderKeys, removeProperties } from '@dxos/util';\n\nimport type * as Type from '../../Type';\nimport { type TypeAnnotation, TypeAnnotationId, TypeIdentifierAnnotationId } from '../Annotation/annotations';\nimport { makeTypeJsonSchemaAnnotation } from '../Annotation/util';\nimport {\n ANY_OBJECT_TYPENAME,\n ANY_OBJECT_VERSION,\n EntityKind,\n EntityKindSchema,\n getStaticTypeSchema,\n} from '../common/types';\nimport { type JsonSchemaReferenceInfo, createEchoReferenceSchema } from '../Ref';\nimport { CustomAnnotations, DecodedAnnotations, EchoAnnotations } from './annotations';\nimport {\n ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,\n ECHO_ANNOTATIONS_NS_KEY,\n type JsonSchemaEchoAnnotations,\n type JsonSchemaType,\n getNormalizedEchoAnnotations,\n} from './json-schema-type';\n\n// TODO(burdon): Are these values stored (can they be changed?)\nexport enum PropType {\n NONE = 0,\n STRING = 1, // TODO(burdon): vs TEXT?\n NUMBER = 2,\n BOOLEAN = 3,\n DATE = 4,\n REF = 5,\n RECORD = 6,\n ENUM = 7,\n}\n\n// TODO(burdon): Reconcile with @dxos/schema.\nexport const toPropType = (type?: PropType): string => {\n switch (type) {\n case PropType.STRING:\n return 'string';\n case PropType.NUMBER:\n return 'number';\n case PropType.BOOLEAN:\n return 'boolean';\n case PropType.DATE:\n return 'date';\n case PropType.REF:\n return 'ref';\n case PropType.RECORD:\n return 'object';\n default:\n throw new Error(`Invalid type: ${type}`);\n }\n};\n\nconst JSON_SCHEMA_URL = 'http://json-schema.org/draft-07/schema#';\n\nexport type JsonSchemaOptions = {\n strict?: boolean;\n};\n\n/**\n * Convert effect schema to JSON Schema.\n * NOTE: This handles custom annotations.\n * @param schema\n */\n// TODO(burdon): Reconcile with possibly extending @effect/Schema/JSONSchema\n// We add additional propertyOrder (but the object properties ARE ordered); and type \"string\" for literals.\n// TODO(wittjosiah): This is mutable because its a pojo, perhaps should be left as readonly at type level though?\nexport const toJsonSchema = (\n schema: Schema.Schema.All | Type.AnyEntity,\n options: JsonSchemaOptions = {},\n): Types.DeepMutable<JsonSchemaType> => {\n // Allow passing a `Type.Type` entity — use its hidden source schema (or its\n // already-built jsonSchema as a fallback).\n const slot = getStaticTypeSchema(schema);\n if (slot != null) {\n schema = slot;\n } else if (!Schema.isSchema(schema)) {\n const entityJsonSchema = (schema as { jsonSchema?: JsonSchemaType }).jsonSchema;\n if (entityJsonSchema != null) {\n return entityJsonSchema as Types.DeepMutable<JsonSchemaType>;\n }\n }\n assertArgument(Schema.isSchema(schema), 'schema');\n let jsonSchema = _toJsonSchemaAST((schema as Schema.Schema.All).ast);\n if (options.strict) {\n // TOOD(burdon): Workaround to ensure JSON schema is valid (for agv parsing).\n jsonSchema = removeProperties(jsonSchema, (key, value) => {\n if (key === '$id' && value === '/schemas/any') {\n return true;\n }\n if (key === '$ref' && value === '#/$defs/dependency') {\n return true;\n }\n if (key === '$ref' && value === '#/$defs/jsonSchema') {\n return true;\n }\n\n return false;\n });\n }\n\n return jsonSchema;\n};\n\nconst _toJsonSchemaAST = (\n ast: SchemaAST.AST,\n inProgress: Set<SchemaAST.AST> = new Set(),\n): Types.DeepMutable<JsonSchemaType> => {\n const withRefinements = withEchoRefinements(ast, '#', new Map(), inProgress);\n const jsonSchema = JSONSchema.fromAST(withRefinements, {\n definitions: {},\n }) as Types.DeepMutable<JsonSchemaType>;\n\n return normalizeJsonSchema(jsonSchema);\n};\n\nconst withEchoRefinements = (\n ast: SchemaAST.AST,\n path: string | undefined,\n suspendCache = new Map<SchemaAST.AST, string>(),\n // Suspended ASTs whose expansion is currently in flight — unlike `suspendCache`, this is shared\n // across the fresh caches each new expansion starts with, so it also catches mutual cycles.\n inProgress: Set<SchemaAST.AST> = new Set(),\n): SchemaAST.AST => {\n if (path) {\n suspendCache.set(ast, path);\n }\n\n let recursiveResult: SchemaAST.AST;\n if (SchemaAST.isSuspend(ast)) {\n // Precompute JSON schema for suspended AST since effect serializer does not support it.\n const suspendedAst = ast.f();\n const cachedPath = suspendCache.get(suspendedAst);\n if (cachedPath) {\n recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache, inProgress), {\n [SchemaAST.JSONSchemaAnnotationId]: {\n $ref: cachedPath,\n },\n });\n } else if (inProgress.has(suspendedAst)) {\n // Reached via a *different* suspended type already being expanded (e.g. two mutually-recursive\n // schemas, A embedding B and B embedding A) — `suspendCache` alone won't catch this, since each\n // fresh expansion below starts from an empty one. Stop with a permissive \"any\" placeholder\n // instead of expanding again. The `type` key is required: effect's JSONSchema.fromAST only\n // treats this annotation as a full override (vs. merging it onto a recomputed, and for a bare\n // Suspend unsupported, structural schema) when it sees type/oneOf/anyOf/$ref.\n recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache, inProgress), {\n [SchemaAST.JSONSchemaAnnotationId]: {\n $id: '/schemas/any',\n type: ['string', 'number', 'boolean', 'object', 'array', 'null'],\n },\n });\n } else {\n inProgress.add(suspendedAst);\n const jsonSchema = _toJsonSchemaAST(suspendedAst, inProgress);\n inProgress.delete(suspendedAst);\n recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache, inProgress), {\n [SchemaAST.JSONSchemaAnnotationId]: jsonSchema,\n });\n }\n } else if (SchemaAST.isTypeLiteral(ast)) {\n // Add property order annotations\n recursiveResult = SchemaEx.mapAst(ast, (ast, key) =>\n withEchoRefinements(\n ast,\n path && typeof key === 'string' ? `${path}/${key}` : undefined,\n suspendCache,\n inProgress,\n ),\n );\n recursiveResult = addJsonSchemaFields(recursiveResult, {\n propertyOrder: [...ast.propertySignatures.map((p) => p.name)] as string[],\n });\n } else if (SchemaAST.isUndefinedKeyword(ast)) {\n // Ignore undefined keyword that appears in the optional fields.\n return ast;\n } else {\n recursiveResult = SchemaEx.mapAst(ast, (ast, key) =>\n withEchoRefinements(\n ast,\n path && (typeof key === 'string' || typeof key === 'number') ? `${path}/${key}` : undefined,\n suspendCache,\n inProgress,\n ),\n );\n }\n\n const annotationFields = annotations_toJsonSchemaFields(ast.annotations);\n if (Object.keys(annotationFields).length === 0) {\n return recursiveResult;\n } else {\n return addJsonSchemaFields(recursiveResult, annotationFields);\n }\n};\n\n/**\n * Convert JSON schema to effect schema.\n * @param root\n * @param definitions\n */\nexport const toEffectSchema = (root: JsonSchemaType, _defs?: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {\n const defs = root.$defs ? { ..._defs, ...root.$defs } : (_defs ?? {});\n if ('type' in root && root.type === 'object') {\n return objectToEffectSchema(root, defs);\n }\n\n let result: Schema.Schema.AnyNoContext = Schema.Unknown;\n if ('$ref' in root) {\n switch (root.$ref) {\n case '/schemas/echo/ref': {\n result = refToEffectSchema(root);\n break;\n }\n }\n } else if ('$id' in root) {\n switch (decodeURIComponent(root.$id as string)) {\n case '/schemas/any': {\n result = anyToEffectSchema(root as JSONSchema.JsonSchema7Any);\n break;\n }\n case '/schemas/unknown': {\n result = Schema.Unknown;\n break;\n }\n case '/schemas/{}':\n case '/schemas/object': {\n result = Schema.Struct({});\n break;\n }\n // Custom ECHO object reference.\n case '/schemas/echo/ref': {\n result = refToEffectSchema(root);\n break;\n }\n }\n } else if ('enum' in root) {\n result = Schema.Union(...root.enum!.map((e) => Schema.Literal(e)));\n } else if ('oneOf' in root) {\n result = Schema.Union(...root.oneOf!.map((v) => toEffectSchema(v, defs)));\n } else if ('anyOf' in root) {\n result = Schema.Union(...root.anyOf!.map((v) => toEffectSchema(v, defs)));\n } else if ('allOf' in root) {\n if (root.allOf!.length === 1) {\n result = toEffectSchema(root.allOf![0], defs);\n } else {\n log.warn('allOf with multiple schemas is not supported');\n result = Schema.Unknown;\n }\n } else if ('type' in root) {\n switch (root.type) {\n case 'string': {\n result = Schema.String;\n if (root.pattern) {\n result = result.pipe(Schema.pattern(new RegExp(root.pattern)));\n }\n break;\n }\n case 'number': {\n result = Schema.Number;\n break;\n }\n case 'integer': {\n result = Schema.Number.pipe(Schema.int());\n break;\n }\n case 'boolean': {\n result = Schema.Boolean;\n break;\n }\n case 'array': {\n if (Array.isArray(root.items)) {\n const [required, optional] = Function.pipe(\n root.items,\n Array.map((v) => toEffectSchema(v as JsonSchemaType, defs)),\n Array.splitAt(root.minItems ?? root.items.length),\n );\n result = Schema.Tuple(...required, ...optional.map(Schema.optionalElement));\n } else {\n invariant(root.items);\n const items = root.items;\n result = Array.isArray(items)\n ? Schema.Tuple(...items.map((v) => toEffectSchema(v as JsonSchemaType, defs)))\n : Schema.Array(toEffectSchema(items as JsonSchemaType, defs));\n }\n break;\n }\n case 'null': {\n result = Schema.Null;\n break;\n }\n }\n } else if ('$ref' in root) {\n const refSegments = root.$ref!.split('/');\n const jsonSchema = defs[refSegments[refSegments.length - 1]];\n invariant(jsonSchema, `missing definition for ${root.$ref}`);\n result = toEffectSchema(jsonSchema, defs).pipe(\n Schema.annotations({ identifier: refSegments[refSegments.length - 1] }),\n );\n }\n\n const annotations = jsonSchemaFieldsToAnnotations(root);\n\n // log.info('toEffectSchema', { root, annotations });\n result = result.annotations(annotations);\n\n return result;\n};\n\nconst objectToEffectSchema = (root: JsonSchemaType, defs: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {\n invariant('type' in root && root.type === 'object', `not an object: ${root}`);\n\n const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];\n const isEchoObject =\n echoRefinement != null || ('$id' in root && typeof root.$id === 'string' && root.$id.startsWith('dxn:'));\n\n let fields: Schema.Struct.Fields = {};\n const propertyList = Object.entries(root.properties ?? {});\n let immutableIdField: Schema.Schema.AnyNoContext | undefined;\n for (const [key, value] of propertyList) {\n if (isEchoObject && key === 'id') {\n immutableIdField = toEffectSchema(value, defs);\n } else {\n // TODO(burdon): Mutable cast.\n (fields as any)[key] = root.required?.includes(key)\n ? toEffectSchema(value, defs)\n : Schema.optional(toEffectSchema(value, defs));\n }\n }\n\n if (root.propertyOrder) {\n fields = orderKeys(fields, root.propertyOrder as any);\n }\n\n let schema: Schema.Schema<any, any, unknown>;\n if (root.patternProperties) {\n invariant(propertyList.length === 0, 'pattern properties mixed with regular properties are not supported');\n invariant(\n Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === '',\n 'only one pattern property is supported',\n );\n\n schema = Schema.Record({ key: Schema.String, value: toEffectSchema(root.patternProperties[''], defs) });\n } else if (typeof root.additionalProperties !== 'object') {\n schema = Schema.Struct(fields);\n } else {\n const indexValue = toEffectSchema(root.additionalProperties, defs);\n if (propertyList.length > 0) {\n schema = Schema.Struct(fields, { key: Schema.String, value: indexValue });\n } else {\n schema = Schema.Record({ key: Schema.String, value: indexValue });\n }\n }\n\n if (immutableIdField) {\n schema = Schema.extend(schema, Schema.Struct({ id: immutableIdField }));\n }\n\n const annotations = jsonSchemaFieldsToAnnotations(root);\n return schema.annotations(annotations) as any;\n};\n\nconst anyToEffectSchema = (root: JSONSchema.JsonSchema7Any): Schema.Schema.AnyNoContext => {\n const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];\n // TODO(dmaretskyi): Is this branch still taken?\n if ((echoRefinement as any)?.reference != null) {\n const echoUri = root.$id.startsWith('echo:') ? root.$id : undefined;\n return createEchoReferenceSchema(\n echoUri,\n (echoRefinement as any).reference.typename,\n (echoRefinement as any).reference.version,\n );\n }\n\n return Schema.Any;\n};\n\n// TODO(dmaretskyi): Types.\nconst refToEffectSchema = (root: any): Schema.Schema.AnyNoContext => {\n if (!('reference' in root)) {\n // Fallback to generic object ref when no reference info is provided.\n return createEchoReferenceSchema(undefined, ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION);\n }\n\n const reference: JsonSchemaReferenceInfo = root.reference;\n if (typeof reference !== 'object') {\n throw new Error('Invalid reference field in ref schema');\n }\n\n const ref = reference.schema.$ref;\n const targetSchemaDXN = DXN.tryMake(ref);\n invariant(targetSchemaDXN, `Expected a type DXN, got: ${ref}`);\n\n return createEchoReferenceSchema(ref, DXN.getName(targetSchemaDXN), reference.schemaVersion);\n};\n\n//\n// Annotations\n//\n\nconst annotations_toJsonSchemaFields = (annotations: SchemaAST.Annotations): Record<symbol, any> => {\n const schemaFields: Record<string, any> = {};\n\n const echoAnnotations: Types.Mutable<JsonSchemaEchoAnnotations> = {};\n for (const [key, annotationId] of Object.entries(EchoAnnotations)) {\n if (annotations[annotationId] != null) {\n echoAnnotations[key as keyof JsonSchemaEchoAnnotations] = annotations[annotationId] as any;\n }\n }\n if (Object.keys(echoAnnotations).length > 0) {\n // TODO(dmaretskyi): use new namespace.\n schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;\n }\n\n // For stored schemas the storage URI is the definitive identifier — it overrides\n // the typename `$id` written above.\n const echoIdentifier = annotations[TypeIdentifierAnnotationId];\n if (echoIdentifier) {\n schemaFields.$id = echoIdentifier;\n }\n\n // Custom (at end).\n for (const [key, annotationId] of Object.entries(CustomAnnotations)) {\n const value = annotations[annotationId];\n if (value != null) {\n schemaFields[key] = value;\n }\n }\n\n return schemaFields;\n};\n\nconst decodeTypeIdentifierAnnotation = (schema: JsonSchemaType): string | undefined => {\n // For stored schemas `$id` IS the storage URI (echo:/<id>).\n if (schema.$id && schema.$id.startsWith('echo:')) {\n return schema.$id;\n }\n // Older serializations stored the EID on echo.type.schemaId.\n const legacySchemaId = schema.echo?.type?.schemaId;\n if (legacySchemaId) {\n return EntityId.isValid(legacySchemaId) ? EID.make({ entityId: legacySchemaId }) : legacySchemaId;\n }\n return undefined;\n};\n\nconst decodeTypeAnnotation = (schema: JsonSchemaType): TypeAnnotation | undefined => {\n if (schema.typename) {\n const annotation: Types.Mutable<TypeAnnotation> = {\n // TODO(dmaretskyi): Decoding default.\n kind: schema.entityKind ? Schema.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,\n typename: schema.typename,\n version: schema.version ?? '0.1.0',\n };\n\n if (annotation.kind === EntityKind.Relation) {\n const source = schema.relationSource?.$ref ?? raise(new Error('Relation source not set'));\n const target = schema.relationTarget?.$ref ?? raise(new Error('Relation target not set'));\n annotation.sourceSchema = DXN.tryMake(source) ?? raise(new Error(`Invalid relation source: ${source}`));\n annotation.targetSchema = DXN.tryMake(target) ?? raise(new Error(`Invalid relation target: ${target}`));\n }\n\n return annotation;\n }\n\n // Decode legacy schema.\n if (!schema.typename && schema?.echo?.type) {\n return {\n kind: EntityKind.Object,\n typename: schema.echo.type.typename,\n version: schema.echo.type.version,\n };\n }\n\n return undefined;\n};\n\nconst jsonSchemaFieldsToAnnotations = (schema: JsonSchemaType): SchemaAST.Annotations => {\n const annotations: Types.Mutable<Schema.Annotations.Schema<any>> = {};\n\n const echoAnnotations: JsonSchemaEchoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};\n if (echoAnnotations) {\n for (const [key, annotationId] of Object.entries(EchoAnnotations)) {\n if (echoAnnotations[key as keyof JsonSchemaEchoAnnotations]) {\n annotations[annotationId] = echoAnnotations[key as keyof JsonSchemaEchoAnnotations];\n }\n }\n }\n\n const typeIdentifier = decodeTypeIdentifierAnnotation(schema);\n annotations[TypeIdentifierAnnotationId] = typeIdentifier;\n const typeAnnotation = decodeTypeAnnotation(schema);\n if (typeAnnotation) {\n annotations[TypeAnnotationId] = typeAnnotation;\n annotations[SchemaAST.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({\n // $id is the typename DXN — the schema's type identity. The storage EID (if any)\n // is preserved separately on TypeIdentifierAnnotation / echo.schemaId.\n identifier: DXN.make(typeAnnotation.typename, typeAnnotation.version),\n kind: typeAnnotation.kind,\n typename: typeAnnotation.typename,\n version: typeAnnotation.version,\n relationSource: typeAnnotation.sourceSchema,\n relationTarget: typeAnnotation.targetSchema,\n });\n }\n\n // Custom (at end).\n for (const [key, annotationId] of Object.entries({ ...CustomAnnotations, ...DecodedAnnotations })) {\n if (key in schema) {\n annotations[annotationId] = (schema as any)[key];\n }\n }\n\n return clearUndefined(annotations);\n};\n\nconst makeAnnotatedRefinement = (ast: SchemaAST.AST, annotations: SchemaAST.Annotations): SchemaAST.Refinement => {\n return new SchemaAST.Refinement(ast, () => Option.none(), annotations);\n};\n\nconst addJsonSchemaFields = (ast: SchemaAST.AST, schema: JsonSchemaType): SchemaAST.AST =>\n makeAnnotatedRefinement(ast, { [SchemaAST.JSONSchemaAnnotationId]: schema });\n\n/**\n * Fixes field order.\n * Sets `$schema` prop.\n */\nconst normalizeJsonSchema = (jsonSchema: Types.DeepMutable<JsonSchemaType>): Types.DeepMutable<JsonSchemaType> => {\n if (jsonSchema.properties && 'id' in jsonSchema.properties) {\n jsonSchema.properties = orderKeys(jsonSchema.properties, ['id']); // Put id first.\n }\n\n // TODO(dmaretskyi): Makes sure undefined is not left on optional fields for the resulting object.\n jsonSchema.$schema = JSON_SCHEMA_URL;\n jsonSchema = orderKeys(jsonSchema, [\n '$schema',\n '$id',\n\n 'entityKind',\n 'typename',\n 'version',\n 'relationTarget',\n 'relationSource',\n\n 'type',\n 'enum',\n\n 'properties',\n 'required',\n 'propertyOrder',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mB,GAAG;CAAmB,CAAC,GAC9F,IAAI,OAAO,QACT,YAAY,gBAAiB,OAAe;CAIhD,OAAO,eAAe,WAAW;AACnC;AAEA,IAAM,2BAA2B,KAAoB,gBAA6D;CAChH,OAAO,IAAI,UAAU,WAAW,WAAW,OAAO,KAAK,GAAG,WAAW;AACvE;AAEA,IAAM,uBAAuB,KAAoB,WAC/C,wBAAwB,KAAK,GAAG,UAAU,yBAAyB,OAAO,CAAC;;;;;AAM7E,IAAM,uBAAuB,eAAqF;CAChH,IAAI,WAAW,cAAc,QAAQ,WAAW,YAC9C,WAAW,aAAa,UAAU,WAAW,YAAY,CAAC,IAAI,CAAC;CAIjE,WAAW,UAAU;CACrB,aAAa,UAAU,YAAY;EACjC;EACA;EAEA;EACA;EACA;EACA;EACA;EAEA;EACA;EAEA;EACA;EACA;EACA;EACA;EAEA;EACA;CACF,CAAC;CACD,OAAO;AACT"}
@@ -0,0 +1,164 @@
1
+ import { t as createAnnotationHelper } from "./chunk-util.mjs";
2
+ import * as Function from "effect/Function";
3
+ import * as Option from "effect/Option";
4
+ import * as Schema from "effect/Schema";
5
+ import * as SchemaAST from "effect/SchemaAST";
6
+ //#region src/internal/Format/types.ts
7
+ var TypeEnum = /* @__PURE__ */ function(TypeEnum) {
8
+ TypeEnum["Array"] = "array";
9
+ TypeEnum["Object"] = "object";
10
+ TypeEnum["String"] = "string";
11
+ TypeEnum["Number"] = "number";
12
+ TypeEnum["Boolean"] = "boolean";
13
+ TypeEnum["Ref"] = "ref";
14
+ return TypeEnum;
15
+ }({});
16
+ var getTypeEnum = (property) => {
17
+ switch (property.type) {
18
+ case "array": return "array";
19
+ case "object": return "object";
20
+ case "string": return "string";
21
+ case "number": return "number";
22
+ case "boolean": return "boolean";
23
+ default: return;
24
+ }
25
+ };
26
+ /**
27
+ * https://json-schema.org/understanding-json-schema/reference/schema
28
+ * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats
29
+ */
30
+ var FormatAnnotationId = Symbol.for("@dxos/schema/annotation/Format");
31
+ var FormatAnnotation = createAnnotationHelper(FormatAnnotationId);
32
+ /** @deprecated */
33
+ var getFormatAnnotation = (node) => Function.pipe(SchemaAST.getAnnotation(FormatAnnotationId)(node), Option.getOrUndefined);
34
+ var TypeFormat = /* @__PURE__ */ function(TypeFormat) {
35
+ TypeFormat["None"] = "none";
36
+ TypeFormat["String"] = "string";
37
+ TypeFormat["Number"] = "number";
38
+ TypeFormat["Boolean"] = "boolean";
39
+ TypeFormat["Ref"] = "ref";
40
+ TypeFormat["DID"] = "did";
41
+ TypeFormat["DXN"] = "dxn";
42
+ TypeFormat["Email"] = "email";
43
+ TypeFormat["Formula"] = "formula";
44
+ TypeFormat["Hostname"] = "hostname";
45
+ TypeFormat["JSON"] = "json";
46
+ TypeFormat["Markdown"] = "markdown";
47
+ TypeFormat["Password"] = "password";
48
+ TypeFormat["Regex"] = "regex";
49
+ TypeFormat["SingleSelect"] = "single-select";
50
+ TypeFormat["Text"] = "text";
51
+ TypeFormat["MultiSelect"] = "multi-select";
52
+ TypeFormat["URL"] = "url";
53
+ TypeFormat["UUID"] = "uuid";
54
+ TypeFormat["Currency"] = "currency";
55
+ TypeFormat["Integer"] = "integer";
56
+ TypeFormat["Percent"] = "percent";
57
+ TypeFormat["Timestamp"] = "timestamp";
58
+ TypeFormat["DateTime"] = "date-time";
59
+ TypeFormat["Date"] = "date";
60
+ TypeFormat["Time"] = "time";
61
+ TypeFormat["Duration"] = "duration";
62
+ TypeFormat["GeoPoint"] = "lnglat";
63
+ return TypeFormat;
64
+ }({});
65
+ var FormatEnums = Object.values(TypeFormat).sort();
66
+ var PropertyKind = {
67
+ type: TypeEnum,
68
+ format: TypeFormat
69
+ };
70
+ /**
71
+ * Default formats
72
+ */
73
+ var typeToFormat = {
74
+ ["string"]: "string",
75
+ ["number"]: "number",
76
+ ["boolean"]: "boolean"
77
+ };
78
+ /**
79
+ * Map of format to type.
80
+ */
81
+ var formatToType = {
82
+ ["none"]: "string",
83
+ ["string"]: "string",
84
+ ["number"]: "number",
85
+ ["boolean"]: "boolean",
86
+ ["ref"]: "ref",
87
+ ["did"]: "string",
88
+ ["dxn"]: "string",
89
+ ["email"]: "string",
90
+ ["formula"]: "string",
91
+ ["hostname"]: "string",
92
+ ["json"]: "string",
93
+ ["markdown"]: "string",
94
+ ["password"]: "string",
95
+ ["regex"]: "string",
96
+ ["url"]: "string",
97
+ ["uuid"]: "string",
98
+ ["single-select"]: "string",
99
+ ["text"]: "string",
100
+ ["multi-select"]: "object",
101
+ ["date"]: "string",
102
+ ["date-time"]: "string",
103
+ ["duration"]: "string",
104
+ ["time"]: "string",
105
+ ["currency"]: "number",
106
+ ["integer"]: "number",
107
+ ["percent"]: "number",
108
+ ["timestamp"]: "number",
109
+ ["lnglat"]: "array"
110
+ };
111
+ /**
112
+ * Allowed value options for select.
113
+ */
114
+ var OptionsAnnotationId = Symbol.for("@dxos/schema/annotation/Options");
115
+ var OptionsAnnotation = createAnnotationHelper(OptionsAnnotationId);
116
+ /** @deprecated */
117
+ var getOptionsAnnotation = (node) => Function.pipe(SchemaAST.getAnnotation(OptionsAnnotationId)(node), Option.getOrUndefined);
118
+ //#endregion
119
+ //#region src/internal/Format/number.ts
120
+ var encodeMultipleOf = (divisor) => 1 / Math.pow(10, divisor);
121
+ var encodeMultiple = (divisor) => (self) => divisor === void 0 || divisor === 0 ? self : self.pipe(Schema.multipleOf(encodeMultipleOf(divisor)));
122
+ /**
123
+ * Convert number of digits to multipleOf annotation.
124
+ */
125
+ var DecimalPrecision = Schema.transform(Schema.Number, Schema.Number, {
126
+ strict: true,
127
+ encode: (value) => encodeMultipleOf(value),
128
+ decode: (value) => Math.log10(1 / value)
129
+ }).annotations({ title: "Number of digits" });
130
+ var CurrencyAnnotationId = Symbol.for("@dxos/schema/annotation/Currency");
131
+ /**
132
+ * ISO 4217 currency code.
133
+ */
134
+ var Currency = ({ decimals, code } = { decimals: 2 }) => Schema.Number.pipe(encodeMultiple(decimals), FormatAnnotation.set(TypeFormat.Currency), Schema.annotations({
135
+ title: "Currency",
136
+ description: "Currency value",
137
+ ...code ? { [CurrencyAnnotationId]: code.toUpperCase() } : {}
138
+ }));
139
+ /**
140
+ * Integer.
141
+ */
142
+ var Integer = () => Schema.Number.pipe(Schema.int(), FormatAnnotation.set(TypeFormat.Integer), Schema.annotations({
143
+ title: "Integer",
144
+ description: "Integer value"
145
+ }));
146
+ /**
147
+ * Percent.
148
+ */
149
+ var Percent = ({ decimals } = { decimals: 2 }) => Schema.Number.pipe(encodeMultiple(decimals), FormatAnnotation.set(TypeFormat.Percent), Schema.annotations({
150
+ title: "Percent",
151
+ description: "Percentage value"
152
+ }));
153
+ /**
154
+ * Unix timestamp.
155
+ * https://en.wikipedia.org/wiki/Unix_time
156
+ */
157
+ var Timestamp = Schema.Number.pipe(FormatAnnotation.set(TypeFormat.Timestamp), Schema.annotations({
158
+ title: "Timestamp",
159
+ description: "Unix timestamp"
160
+ }));
161
+ //#endregion
162
+ export { getOptionsAnnotation as _, Percent as a, FormatAnnotationId as c, OptionsAnnotationId as d, PropertyKind as f, getFormatAnnotation as g, formatToType as h, Integer as i, FormatEnums as l, TypeFormat as m, CurrencyAnnotationId as n, Timestamp as o, TypeEnum as p, DecimalPrecision as r, FormatAnnotation as s, Currency as t, OptionsAnnotation as u, getTypeEnum as v, typeToFormat as y };
163
+
164
+ //# sourceMappingURL=chunk-number.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-number.mjs","names":[],"sources":["../../src/internal/Format/types.ts","../../src/internal/Format/number.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport type * as JSONSchema from 'effect/JSONSchema';\nimport * as Option from 'effect/Option';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { createAnnotationHelper } from '../Annotation';\nimport { type JsonSchemaType } from '../JsonSchema';\n\n// TODO(burdon): Rename PropertyType.\nexport type ScalarType =\n | JSONSchema.JsonSchema7Object\n | JSONSchema.JsonSchema7String\n | JSONSchema.JsonSchema7Number\n | JSONSchema.JsonSchema7Boolean\n | JSONSchema.JsonSchema7Ref;\n\n// TODO(burdon): Rename ValueType and change to disciminated union.\n// export type ValueType = 'array' | 'object' | 'string' | 'number' | 'boolean' | 'ref';\nexport enum TypeEnum {\n Array = 'array', // TODO(burdon): Remove?\n Object = 'object',\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Ref = 'ref',\n}\n\n// TODO(burdon): Ref?\nexport const getTypeEnum = (property: JsonSchemaType): TypeEnum | undefined => {\n switch (property.type) {\n case 'array':\n return TypeEnum.Array;\n case 'object':\n return TypeEnum.Object;\n case 'string':\n return TypeEnum.String;\n case 'number':\n return TypeEnum.Number;\n case 'boolean':\n return TypeEnum.Boolean;\n default:\n return undefined;\n }\n};\n\n/**\n * https://json-schema.org/understanding-json-schema/reference/schema\n * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats\n */\nexport const FormatAnnotationId = Symbol.for('@dxos/schema/annotation/Format');\n\nexport const FormatAnnotation = createAnnotationHelper<TypeFormat>(FormatAnnotationId);\n\n/** @deprecated */\nexport const getFormatAnnotation = (node: SchemaAST.AST): TypeFormat | undefined =>\n Function.pipe(SchemaAST.getAnnotation<TypeFormat>(FormatAnnotationId)(node), Option.getOrUndefined);\n\n// TODO(burdon): Rename Format; Change to discriminated union?\nexport enum TypeFormat {\n None = 'none',\n\n //\n // Scalar\n //\n\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Ref = 'ref',\n\n //\n // { type: 'string' }\n //\n\n DID = 'did', // Users, etc.\n DXN = 'dxn',\n Email = 'email',\n Formula = 'formula', // Spreadsheet (Excel, Google Sheets, etc.) formula.\n Hostname = 'hostname',\n JSON = 'json',\n Markdown = 'markdown',\n Password = 'password',\n Regex = 'regex',\n SingleSelect = 'single-select',\n Text = 'text',\n MultiSelect = 'multi-select',\n URL = 'url',\n UUID = 'uuid',\n\n //\n // { type: 'number' }\n //\n\n Currency = 'currency',\n Integer = 'integer',\n Percent = 'percent',\n Timestamp = 'timestamp',\n\n //\n // { type: 'date' }\n //\n\n DateTime = 'date-time',\n Date = 'date',\n Time = 'time',\n Duration = 'duration',\n\n //\n // { type: 'object' }\n //\n\n GeoPoint = 'lnglat',\n}\n\nexport const FormatEnums = Object.values(TypeFormat).sort();\n\nexport const PropertyKind = {\n type: TypeEnum,\n format: TypeFormat,\n};\n\n/**\n * Default formats\n */\nexport const typeToFormat: Partial<Record<TypeEnum, TypeFormat>> = {\n [TypeEnum.String]: TypeFormat.String,\n [TypeEnum.Number]: TypeFormat.Number,\n [TypeEnum.Boolean]: TypeFormat.Boolean,\n};\n\n/**\n * Map of format to type.\n */\nexport const formatToType: Record<TypeFormat, TypeEnum> = {\n [TypeFormat.None]: TypeEnum.String,\n [TypeFormat.String]: TypeEnum.String,\n [TypeFormat.Number]: TypeEnum.Number,\n [TypeFormat.Boolean]: TypeEnum.Boolean,\n [TypeFormat.Ref]: TypeEnum.Ref,\n\n // Strings\n [TypeFormat.DID]: TypeEnum.String,\n [TypeFormat.DXN]: TypeEnum.String,\n [TypeFormat.Email]: TypeEnum.String,\n [TypeFormat.Formula]: TypeEnum.String,\n [TypeFormat.Hostname]: TypeEnum.String,\n [TypeFormat.JSON]: TypeEnum.String,\n [TypeFormat.Markdown]: TypeEnum.String,\n [TypeFormat.Password]: TypeEnum.String,\n [TypeFormat.Regex]: TypeEnum.String,\n [TypeFormat.URL]: TypeEnum.String,\n [TypeFormat.UUID]: TypeEnum.String,\n [TypeFormat.SingleSelect]: TypeEnum.String,\n [TypeFormat.Text]: TypeEnum.String,\n [TypeFormat.MultiSelect]: TypeEnum.Object,\n\n // Dates\n [TypeFormat.Date]: TypeEnum.String,\n [TypeFormat.DateTime]: TypeEnum.String,\n [TypeFormat.Duration]: TypeEnum.String,\n [TypeFormat.Time]: TypeEnum.String,\n\n // Numbers\n [TypeFormat.Currency]: TypeEnum.Number,\n [TypeFormat.Integer]: TypeEnum.Number,\n [TypeFormat.Percent]: TypeEnum.Number,\n [TypeFormat.Timestamp]: TypeEnum.Number,\n\n // Objects\n [TypeFormat.GeoPoint]: TypeEnum.Array,\n};\n\n/**\n * Allowed value options for select.\n */\nexport const OptionsAnnotationId = Symbol.for('@dxos/schema/annotation/Options');\n\n// TODO(wittjosiah): Reconcile with `SelectOption`.\nexport type Options = string | number;\nexport const OptionsAnnotation = createAnnotationHelper<Options[]>(OptionsAnnotationId);\n\n/** @deprecated */\nexport const getOptionsAnnotation = (node: SchemaAST.AST): Options[] | undefined =>\n Function.pipe(SchemaAST.getAnnotation<Options[]>(OptionsAnnotationId)(node), Option.getOrUndefined);\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\nconst encodeMultipleOf = (divisor: number) => 1 / Math.pow(10, divisor);\n\nconst encodeMultiple =\n <A extends number>(divisor?: number) =>\n <I, R>(self: Schema.Schema<A, I, R>) =>\n divisor === undefined || divisor === 0 ? self : self.pipe(Schema.multipleOf(encodeMultipleOf(divisor)));\n\n/**\n * Convert number of digits to multipleOf annotation.\n */\nexport const DecimalPrecision = Schema.transform(Schema.Number, Schema.Number, {\n strict: true,\n encode: (value) => encodeMultipleOf(value),\n decode: (value) => Math.log10(1 / value),\n}).annotations({\n title: 'Number of digits',\n});\n\nexport const CurrencyAnnotationId = Symbol.for('@dxos/schema/annotation/Currency');\n\nexport type CurrencyAnnotation = {\n decimals?: number;\n code?: string;\n};\n\n/**\n * ISO 4217 currency code.\n */\nexport const Currency = ({ decimals, code }: CurrencyAnnotation = { decimals: 2 }) =>\n Schema.Number.pipe(\n encodeMultiple(decimals),\n FormatAnnotation.set(TypeFormat.Currency),\n Schema.annotations({\n title: 'Currency',\n description: 'Currency value',\n ...(code ? { [CurrencyAnnotationId]: code.toUpperCase() } : {}),\n }),\n );\n\nexport type PercentAnnotation = {\n decimals?: number;\n};\n\n/**\n * Integer.\n */\nexport const Integer = () =>\n Schema.Number.pipe(\n Schema.int(),\n FormatAnnotation.set(TypeFormat.Integer),\n Schema.annotations({\n title: 'Integer',\n description: 'Integer value',\n }),\n );\n\n/**\n * Percent.\n */\n// TODO(burdon): Define min/max (e.g., 0, 1).\nexport const Percent = ({ decimals }: PercentAnnotation = { decimals: 2 }) =>\n Schema.Number.pipe(\n encodeMultiple(decimals),\n FormatAnnotation.set(TypeFormat.Percent),\n Schema.annotations({\n title: 'Percent',\n description: 'Percentage value',\n }),\n );\n\n/**\n * Unix timestamp.\n * https://en.wikipedia.org/wiki/Unix_time\n */\nexport const Timestamp = Schema.Number.pipe(\n FormatAnnotation.set(TypeFormat.Timestamp),\n Schema.annotations({\n title: 'Timestamp',\n description: 'Unix timestamp',\n }),\n);\n"],"mappings":";;;;;;AAsBA,IAAY,WAAL,yBAAA,UAAA;CACL,SAAA,WAAA;CACA,SAAA,YAAA;CACA,SAAA,YAAA;CACA,SAAA,YAAA;CACA,SAAA,aAAA;CACA,SAAA,SAAA;;AACF,EAAA,CAAA,CAAA;AAGA,IAAa,eAAe,aAAmD;CAC7E,QAAQ,SAAS,MAAjB;EACE,KAAK,SACH,OAAA;EACF,KAAK,UACH,OAAA;EACF,KAAK,UACH,OAAA;EACF,KAAK,UACH,OAAA;EACF,KAAK,WACH,OAAA;EACF,SACE;CACJ;AACF;;;;;AAMA,IAAa,qBAAqB,OAAO,IAAI,gCAAgC;AAE7E,IAAa,mBAAmB,uBAAmC,kBAAkB;;AAGrF,IAAa,uBAAuB,SAClC,SAAS,KAAK,UAAU,cAA0B,kBAAkB,CAAC,CAAC,IAAI,GAAG,OAAO,cAAc;AAGpG,IAAY,aAAL,yBAAA,YAAA;CACL,WAAA,UAAA;CAMA,WAAA,YAAA;CACA,WAAA,YAAA;CACA,WAAA,aAAA;CACA,WAAA,SAAA;CAMA,WAAA,SAAA;CACA,WAAA,SAAA;CACA,WAAA,WAAA;CACA,WAAA,aAAA;CACA,WAAA,cAAA;CACA,WAAA,UAAA;CACA,W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AI,WAAW,QAAQ,GACxC,OAAO,YAAY;CACjB,OAAO;CACP,aAAa;CACb,GAAI,OAAO,GAAG,uBAAuB,KAAK,YAAY,EAAE,IAAI,CAAC;AAC/D,CAAC,CACH;;;;AASF,IAAa,gBACX,OAAO,OAAO,KACZ,OAAO,IAAI,GACX,iBAAiB,IAAI,WAAW,OAAO,GACvC,OAAO,YAAY;CACjB,OAAO;CACP,aAAa;AACf,CAAC,CACH;;;;AAMF,IAAa,WAAW,EAAE,aAAgC,EAAE,UAAU,EAAE,MACtE,OAAO,OAAO,KACZ,eAAe,QAAQ,GACvB,iBAAiB,IAAI,WAAW,OAAO,GACvC,OAAO,YAAY;CACjB,OAAO;CACP,aAAa;AACf,CAAC,CACH;;;;;AAMF,IAAa,YAAY,OAAO,OAAO,KACrC,iBAAiB,IAAI,WAAW,SAAS,GACzC,OAAO,YAAY;CACjB,OAAO;CACP,aAAa;AACf,CAAC,CACH"}
@@ -0,0 +1,31 @@
1
+ import { n as Ref } from "./chunk-ref.mjs";
2
+ import { isNonNullable } from "@dxos/util";
3
+ //#region src/internal/Ref/ref-array.ts
4
+ /**
5
+ * Helper functions for working with arrays of refs.
6
+ */
7
+ var RefArray = Object.freeze({
8
+ /**
9
+ * @returns all resolved targets.
10
+ */
11
+ targets: (refs) => {
12
+ return refs.map((ref) => ref.target).filter(isNonNullable);
13
+ },
14
+ /**
15
+ * Load all referenced objects.
16
+ */
17
+ loadAll: (refs) => {
18
+ return Promise.all(refs.map((ref) => ref.load()));
19
+ },
20
+ /**
21
+ * Removes the ref with the given id.
22
+ */
23
+ removeById: (refs, id) => {
24
+ const index = refs.findIndex(Ref.hasEntityId(id));
25
+ if (index >= 0) refs.splice(index, 1);
26
+ }
27
+ });
28
+ //#endregion
29
+ export { RefArray as t };
30
+
31
+ //# sourceMappingURL=chunk-ref-array.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-ref-array.mjs","names":[],"sources":["../../src/internal/Ref/ref-array.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type EntityId } from '@dxos/keys';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type AnyEntity } from '../common/types';\nimport { Ref } from './ref';\n\n/**\n * Helper functions for working with arrays of refs.\n */\nexport const RefArray = Object.freeze({\n /**\n * @returns all resolved targets.\n */\n targets: <T extends AnyEntity>(refs: readonly Ref<T>[]): T[] => {\n return refs.map((ref) => ref.target).filter(isNonNullable);\n },\n\n /**\n * Load all referenced objects.\n */\n loadAll: <T extends AnyEntity>(refs: readonly Ref<T>[]): Promise<T[]> => {\n return Promise.all(refs.map((ref) => ref.load()));\n },\n\n /**\n * Removes the ref with the given id.\n */\n removeById: (refs: Ref<AnyEntity>[], id: EntityId) => {\n const index = refs.findIndex(Ref.hasEntityId(id));\n if (index >= 0) {\n refs.splice(index, 1);\n }\n },\n});\n"],"mappings":";;;;;;AAaA,IAAa,WAAW,OAAO,OAAO;;;;CAIpC,UAA+B,SAAiC;EAC9D,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,CAAC,OAAO,aAAa;CAC3D;;;;CAKA,UAA+B,SAA0C;EACvE,OAAO,QAAQ,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,CAAC;CAClD;;;;CAKA,aAAa,MAAwB,OAAiB;EACpD,MAAM,QAAQ,KAAK,UAAU,IAAI,YAAY,EAAE,CAAC;EAChD,IAAI,SAAS,GACX,KAAK,OAAO,OAAO,CAAC;CAExB;AACF,CAAC"}