@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
@@ -1,747 +0,0 @@
1
- import {
2
- CurrencyAnnotationId,
3
- FormatAnnotation,
4
- FormatAnnotationId,
5
- TypeFormat
6
- } from "./chunk-KCBW4BR6.mjs";
7
- import {
8
- createEchoReferenceSchema
9
- } from "./chunk-L3E5IXAE.mjs";
10
- import {
11
- GeneratorAnnotationId,
12
- LabelAnnotationId,
13
- PropertyMetaAnnotationId,
14
- TypeAnnotationId,
15
- TypeIdentifierAnnotationId
16
- } from "./chunk-3TN2VMI4.mjs";
17
- import {
18
- ANY_OBJECT_TYPENAME,
19
- ANY_OBJECT_VERSION,
20
- EntityKind,
21
- EntityKindSchema,
22
- getStaticTypeSchema,
23
- makeTypeJsonSchemaAnnotation
24
- } from "./chunk-2ZHECXUR.mjs";
25
-
26
- // src/internal/JsonSchema/annotations.ts
27
- import * as SchemaAST from "effect/SchemaAST";
28
- var CustomAnnotations = {
29
- format: FormatAnnotationId,
30
- currency: CurrencyAnnotationId
31
- };
32
- var DecodedAnnotations = {
33
- title: SchemaAST.TitleAnnotationId,
34
- description: SchemaAST.DescriptionAnnotationId
35
- };
36
- var EchoAnnotations = {
37
- // TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.
38
- meta: PropertyMetaAnnotationId,
39
- generator: GeneratorAnnotationId,
40
- labelProp: LabelAnnotationId
41
- };
42
-
43
- // src/internal/JsonSchema/json-schema-type.ts
44
- import * as Schema from "effect/Schema";
45
- import { SchemaEx } from "@dxos/effect";
46
- var SimpleTypes = Schema.Literal("array", "boolean", "integer", "null", "number", "object", "string");
47
- var NonNegativeInteger = Schema.Number.pipe(Schema.greaterThanOrEqualTo(0));
48
- var StringArray = Schema.Array(Schema.String);
49
- var JsonSchemaOrBoolean = Schema.Union(Schema.suspend(() => JsonSchemaType), Schema.Boolean);
50
- var JsonSchemaEchoAnnotations = Schema.Struct({
51
- /**
52
- * Label for this schema.
53
- * Mapped from {@link LabelAnnotationId}.
54
- */
55
- labelProp: Schema.optional(Schema.Union(SchemaEx.JsonPath, Schema.Array(SchemaEx.JsonPath))),
56
- /**
57
- * Generator function for this schema.
58
- * Mapped from {@link GeneratorAnnotationId}.
59
- */
60
- generator: Schema.optional(Schema.Union(Schema.String, Schema.Tuple(Schema.String, Schema.Number))),
61
- /**
62
- * {@link PropertyMeta} annotations get serialized here.
63
- */
64
- meta: Schema.optional(Schema.Record({
65
- key: Schema.String,
66
- value: Schema.Any
67
- })),
68
- /**
69
- * @deprecated
70
- */
71
- // TODO(dmaretskyi): We risk old schema not passing validation due to the extra fields. Remove when we are sure this is safe.
72
- type: Schema.optional(Schema.Struct({
73
- typename: Schema.String,
74
- version: Schema.String,
75
- // Not used.
76
- schemaId: Schema.optional(Schema.String)
77
- })),
78
- /**
79
- * @deprecated Superseded by `meta`.
80
- */
81
- annotations: Schema.optional(Schema.Record({
82
- key: Schema.String,
83
- value: Schema.Any
84
- }))
85
- });
86
- var _JsonSchemaType = Schema.Struct({
87
- /**
88
- * Identifier for this schema.
89
- * This schema might be referenced by $ref clause in other schemas.
90
- */
91
- // TODO(dmaretskyi): Specify how the ids are generated.
92
- // TODO(dmaretskyi): For type dxns, should this include the version?
93
- $id: Schema.optional(Schema.String),
94
- /**
95
- * Schema of this schema.
96
- * Set to "https://json-schema.org/draft-07/schema".
97
- */
98
- $schema: Schema.optional(Schema.String),
99
- /**
100
- * Reference to another schema.
101
- */
102
- $ref: Schema.optional(Schema.String),
103
- /**
104
- * Comments are ignored when interpreting the schema.
105
- */
106
- $comment: Schema.optional(Schema.String),
107
- /**
108
- * Defines whether this schema is an object schema or a relation schema.
109
- */
110
- entityKind: Schema.optional(EntityKindSchema),
111
- /**
112
- * Typename of this schema.
113
- * Only on schema representing an ECHO object.
114
- *
115
- * @example 'com.example.type.my-type'
116
- */
117
- typename: Schema.optional(Schema.String),
118
- /**
119
- * Version of this schema.
120
- * Custom dialect for ECHO.
121
- */
122
- version: Schema.optional(Schema.String),
123
- /**
124
- * Target of this relation.
125
- * Only for relation schemas.
126
- * The referenced schema must be an object schema.
127
- */
128
- relationTarget: Schema.optional(Schema.suspend(() => JsonSchemaType)),
129
- /**
130
- * Source of this relation.
131
- * Only for relation schemas.
132
- * The referenced schema must be an object schema.
133
- */
134
- relationSource: Schema.optional(Schema.suspend(() => JsonSchemaType)),
135
- /**
136
- * Title of this schema.
137
- */
138
- title: Schema.optional(Schema.String),
139
- /**
140
- * Description of this schema.
141
- */
142
- description: Schema.optional(Schema.String),
143
- /**
144
- * Whether this schema is read-only.
145
- */
146
- readOnly: Schema.optional(Schema.Boolean),
147
- /**
148
- * Whether this schema is write-only.
149
- */
150
- writeOnly: Schema.optional(Schema.Boolean),
151
- /**
152
- * Examples of instances of this schema.
153
- */
154
- examples: Schema.optional(Schema.Array(Schema.Any)),
155
- /**
156
- * Default value for this schema.
157
- */
158
- default: Schema.optional(Schema.Any),
159
- /**
160
- * This schema only matches values that are equal to this value.
161
- */
162
- const: Schema.optional(Schema.Any),
163
- /**
164
- * This schema only matches one of the values in this array.
165
- */
166
- enum: Schema.optional(Schema.Array(Schema.Any)),
167
- /**
168
- * Base type of the schema.
169
- */
170
- type: Schema.optional(Schema.Union(SimpleTypes, Schema.Array(SimpleTypes))),
171
- //
172
- // Numbers.
173
- //
174
- multipleOf: Schema.optional(Schema.Number.pipe(Schema.greaterThan(0))),
175
- maximum: Schema.optional(Schema.Number),
176
- exclusiveMaximum: Schema.optional(Schema.Number),
177
- minimum: Schema.optional(Schema.Number),
178
- exclusiveMinimum: Schema.optional(Schema.Number),
179
- //
180
- // Strings.
181
- //
182
- maxLength: Schema.optional(NonNegativeInteger),
183
- /**
184
- * Regex pattern for strings.
185
- */
186
- pattern: Schema.optional(Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex))),
187
- /**
188
- * Serialized from {@link FormatAnnotationId}.
189
- */
190
- format: Schema.optional(Schema.String),
191
- //
192
- // Arrays
193
- //
194
- minLength: Schema.optional(NonNegativeInteger),
195
- items: Schema.optional(Schema.Union(Schema.suspend(() => JsonSchemaType), Schema.Array(Schema.suspend(() => JsonSchemaType)))),
196
- additionalItems: Schema.optional(Schema.Union(Schema.suspend(() => JsonSchemaType), Schema.Boolean)),
197
- maxItems: Schema.optional(NonNegativeInteger),
198
- minItems: Schema.optional(NonNegativeInteger),
199
- uniqueItems: Schema.optional(Schema.Boolean),
200
- contains: Schema.optional(Schema.suspend(() => JsonSchemaType)),
201
- //
202
- // Objects
203
- //
204
- maxProperties: Schema.optional(NonNegativeInteger),
205
- minProperties: Schema.optional(NonNegativeInteger),
206
- required: Schema.optional(StringArray),
207
- /**
208
- * Non-standard JSON Schema extension.
209
- * Defines the order of properties in the object.
210
- * The unmentioned properties are placed at the end.
211
- *
212
- * Related: https://github.com/json-schema/json-schema/issues/119
213
- */
214
- propertyOrder: Schema.optional(StringArray),
215
- additionalProperties: Schema.optional(JsonSchemaOrBoolean),
216
- properties: Schema.optional(Schema.Record({
217
- key: Schema.String,
218
- value: Schema.suspend(() => JsonSchemaType)
219
- })),
220
- patternProperties: Schema.optional(Schema.Record({
221
- key: Schema.String,
222
- value: Schema.suspend(() => JsonSchemaType)
223
- })),
224
- propertyNames: Schema.optional(Schema.suspend(() => JsonSchemaType)),
225
- definitions: Schema.optional(Schema.Record({
226
- key: Schema.String,
227
- value: Schema.suspend(() => JsonSchemaType)
228
- })),
229
- dependencies: Schema.optional(Schema.Record({
230
- key: Schema.String,
231
- value: Schema.suspend(() => Schema.Union(Schema.String, StringArray, JsonSchemaType)).annotations({
232
- identifier: "dependency",
233
- description: "Dependency"
234
- })
235
- })),
236
- contentMediaType: Schema.optional(Schema.String),
237
- contentEncoding: Schema.optional(Schema.String),
238
- if: Schema.optional(Schema.suspend(() => JsonSchemaType)),
239
- then: Schema.optional(Schema.suspend(() => JsonSchemaType)),
240
- else: Schema.optional(Schema.suspend(() => JsonSchemaType)),
241
- allOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),
242
- anyOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),
243
- oneOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),
244
- not: Schema.optional(Schema.suspend(() => JsonSchemaType)),
245
- $defs: Schema.optional(Schema.Record({
246
- key: Schema.String,
247
- value: Schema.suspend(() => JsonSchemaType)
248
- })),
249
- //
250
- // ECHO extensions.
251
- //
252
- currency: Schema.optional(Schema.String),
253
- reference: Schema.optional(Schema.Struct({
254
- schema: Schema.suspend(() => JsonSchemaType),
255
- schemaVersion: Schema.optional(Schema.String),
256
- schemaObject: Schema.optional(Schema.String)
257
- })),
258
- /**
259
- * ECHO-specific annotations.
260
- */
261
- // TODO(dmaretskyi): Since we are adding a lot of new extensions to the JSON Schema, it is safer to namespace them here.
262
- annotations: Schema.optional(JsonSchemaEchoAnnotations),
263
- /**
264
- * @deprecated Use `annotations` instead.
265
- */
266
- echo: Schema.optional(JsonSchemaEchoAnnotations)
267
- }).annotations({
268
- identifier: "jsonSchema",
269
- description: "JSON Schema"
270
- });
271
- var JsonSchemaFields = Object.keys(_JsonSchemaType.fields);
272
- var JsonSchemaType = _JsonSchemaType;
273
- var getSchemaProperty = (schema, property) => {
274
- return schema.properties?.[property];
275
- };
276
- var setSchemaProperty = (schema, property, value) => {
277
- schema.properties ??= {};
278
- schema.properties[property] = value;
279
- return schema;
280
- };
281
- var ECHO_ANNOTATIONS_NS_DEPRECATED_KEY = "echo";
282
- var ECHO_ANNOTATIONS_NS_KEY = "annotations";
283
- var getNormalizedEchoAnnotations = (obj) => {
284
- if (obj[ECHO_ANNOTATIONS_NS_KEY] != null && obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {
285
- return normalizeEchoAnnotations({
286
- ...obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY],
287
- ...obj[ECHO_ANNOTATIONS_NS_KEY]
288
- });
289
- } else if (obj[ECHO_ANNOTATIONS_NS_KEY] != null) {
290
- return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_KEY]);
291
- } else if (obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {
292
- return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY]);
293
- } else {
294
- return void 0;
295
- }
296
- };
297
- var normalizeEchoAnnotations = (obj) => {
298
- if (!obj.annotations) {
299
- return obj;
300
- } else {
301
- const res = {
302
- ...obj,
303
- meta: {
304
- ...obj.annotations,
305
- ...obj.meta ?? {}
306
- }
307
- };
308
- delete res.annotations;
309
- return res;
310
- }
311
- };
312
-
313
- // src/internal/JsonSchema/json-schema.ts
314
- import * as Array2 from "effect/Array";
315
- import * as Function from "effect/Function";
316
- import * as JSONSchema from "effect/JSONSchema";
317
- import * as Option from "effect/Option";
318
- import * as Schema2 from "effect/Schema";
319
- import * as SchemaAST2 from "effect/SchemaAST";
320
- import { raise } from "@dxos/debug";
321
- import { SchemaEx as SchemaEx2 } from "@dxos/effect";
322
- import { assertArgument, invariant } from "@dxos/invariant";
323
- import { DXN, EID, EntityId } from "@dxos/keys";
324
- import { log } from "@dxos/log";
325
- import { clearUndefined, orderKeys, removeProperties } from "@dxos/util";
326
- var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/JsonSchema/json-schema.ts";
327
- var PropType = /* @__PURE__ */ (function(PropType2) {
328
- PropType2[PropType2["NONE"] = 0] = "NONE";
329
- PropType2[PropType2["STRING"] = 1] = "STRING";
330
- PropType2[PropType2["NUMBER"] = 2] = "NUMBER";
331
- PropType2[PropType2["BOOLEAN"] = 3] = "BOOLEAN";
332
- PropType2[PropType2["DATE"] = 4] = "DATE";
333
- PropType2[PropType2["REF"] = 5] = "REF";
334
- PropType2[PropType2["RECORD"] = 6] = "RECORD";
335
- PropType2[PropType2["ENUM"] = 7] = "ENUM";
336
- return PropType2;
337
- })({});
338
- var toPropType = (type) => {
339
- switch (type) {
340
- case 1:
341
- return "string";
342
- case 2:
343
- return "number";
344
- case 3:
345
- return "boolean";
346
- case 4:
347
- return "date";
348
- case 5:
349
- return "ref";
350
- case 6:
351
- return "object";
352
- default:
353
- throw new Error(`Invalid type: ${type}`);
354
- }
355
- };
356
- var JSON_SCHEMA_URL = "http://json-schema.org/draft-07/schema#";
357
- var toJsonSchema = (schema, options = {}) => {
358
- const slot = getStaticTypeSchema(schema);
359
- if (slot != null) {
360
- schema = slot;
361
- } else if (!Schema2.isSchema(schema)) {
362
- const entityJsonSchema = schema.jsonSchema;
363
- if (entityJsonSchema != null) {
364
- return entityJsonSchema;
365
- }
366
- }
367
- assertArgument(Schema2.isSchema(schema), "schema");
368
- let jsonSchema = _toJsonSchemaAST(schema.ast);
369
- if (options.strict) {
370
- jsonSchema = removeProperties(jsonSchema, (key, value) => {
371
- if (key === "$id" && value === "/schemas/any") {
372
- return true;
373
- }
374
- if (key === "$ref" && value === "#/$defs/dependency") {
375
- return true;
376
- }
377
- if (key === "$ref" && value === "#/$defs/jsonSchema") {
378
- return true;
379
- }
380
- return false;
381
- });
382
- }
383
- return jsonSchema;
384
- };
385
- var _toJsonSchemaAST = (ast) => {
386
- const withRefinements = withEchoRefinements(ast, "#");
387
- const jsonSchema = JSONSchema.fromAST(withRefinements, {
388
- definitions: {}
389
- });
390
- return normalizeJsonSchema(jsonSchema);
391
- };
392
- var withEchoRefinements = (ast, path, suspendCache = /* @__PURE__ */ new Map()) => {
393
- if (path) {
394
- suspendCache.set(ast, path);
395
- }
396
- let recursiveResult;
397
- if (SchemaAST2.isSuspend(ast)) {
398
- const suspendedAst = ast.f();
399
- const cachedPath = suspendCache.get(suspendedAst);
400
- if (cachedPath) {
401
- recursiveResult = new SchemaAST2.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
402
- [SchemaAST2.JSONSchemaAnnotationId]: {
403
- $ref: cachedPath
404
- }
405
- });
406
- } else {
407
- const jsonSchema = _toJsonSchemaAST(suspendedAst);
408
- recursiveResult = new SchemaAST2.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
409
- [SchemaAST2.JSONSchemaAnnotationId]: jsonSchema
410
- });
411
- }
412
- } else if (SchemaAST2.isTypeLiteral(ast)) {
413
- recursiveResult = SchemaEx2.mapAst(ast, (ast2, key) => withEchoRefinements(ast2, path && typeof key === "string" ? `${path}/${key}` : void 0, suspendCache));
414
- recursiveResult = addJsonSchemaFields(recursiveResult, {
415
- propertyOrder: [
416
- ...ast.propertySignatures.map((p) => p.name)
417
- ]
418
- });
419
- } else if (SchemaAST2.isUndefinedKeyword(ast)) {
420
- return ast;
421
- } else {
422
- recursiveResult = SchemaEx2.mapAst(ast, (ast2, key) => withEchoRefinements(ast2, path && (typeof key === "string" || typeof key === "number") ? `${path}/${key}` : void 0, suspendCache));
423
- }
424
- const annotationFields = annotations_toJsonSchemaFields(ast.annotations);
425
- if (Object.keys(annotationFields).length === 0) {
426
- return recursiveResult;
427
- } else {
428
- return addJsonSchemaFields(recursiveResult, annotationFields);
429
- }
430
- };
431
- var toEffectSchema = (root, _defs) => {
432
- const defs = root.$defs ? {
433
- ..._defs,
434
- ...root.$defs
435
- } : _defs ?? {};
436
- if ("type" in root && root.type === "object") {
437
- return objectToEffectSchema(root, defs);
438
- }
439
- let result = Schema2.Unknown;
440
- if ("$ref" in root) {
441
- switch (root.$ref) {
442
- case "/schemas/echo/ref": {
443
- result = refToEffectSchema(root);
444
- break;
445
- }
446
- }
447
- } else if ("$id" in root) {
448
- switch (decodeURIComponent(root.$id)) {
449
- case "/schemas/any": {
450
- result = anyToEffectSchema(root);
451
- break;
452
- }
453
- case "/schemas/unknown": {
454
- result = Schema2.Unknown;
455
- break;
456
- }
457
- case "/schemas/{}":
458
- case "/schemas/object": {
459
- result = Schema2.Struct({});
460
- break;
461
- }
462
- // Custom ECHO object reference.
463
- case "/schemas/echo/ref": {
464
- result = refToEffectSchema(root);
465
- break;
466
- }
467
- }
468
- } else if ("enum" in root) {
469
- result = Schema2.Union(...root.enum.map((e) => Schema2.Literal(e)));
470
- } else if ("oneOf" in root) {
471
- result = Schema2.Union(...root.oneOf.map((v) => toEffectSchema(v, defs)));
472
- } else if ("anyOf" in root) {
473
- result = Schema2.Union(...root.anyOf.map((v) => toEffectSchema(v, defs)));
474
- } else if ("allOf" in root) {
475
- if (root.allOf.length === 1) {
476
- result = toEffectSchema(root.allOf[0], defs);
477
- } else {
478
- log.warn("allOf with multiple schemas is not supported", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 197, S: void 0 });
479
- result = Schema2.Unknown;
480
- }
481
- } else if ("type" in root) {
482
- switch (root.type) {
483
- case "string": {
484
- result = Schema2.String;
485
- if (root.pattern) {
486
- result = result.pipe(Schema2.pattern(new RegExp(root.pattern)));
487
- }
488
- break;
489
- }
490
- case "number": {
491
- result = Schema2.Number;
492
- break;
493
- }
494
- case "integer": {
495
- result = Schema2.Number.pipe(Schema2.int());
496
- break;
497
- }
498
- case "boolean": {
499
- result = Schema2.Boolean;
500
- break;
501
- }
502
- case "array": {
503
- if (Array2.isArray(root.items)) {
504
- const [required, optional3] = Function.pipe(root.items, Array2.map((v) => toEffectSchema(v, defs)), Array2.splitAt(root.minItems ?? root.items.length));
505
- result = Schema2.Tuple(...required, ...optional3.map(Schema2.optionalElement));
506
- } else {
507
- invariant(root.items, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 231, S: void 0, A: ["root.items", ""] });
508
- const items = root.items;
509
- result = Array2.isArray(items) ? Schema2.Tuple(...items.map((v) => toEffectSchema(v, defs))) : Schema2.Array(toEffectSchema(items, defs));
510
- }
511
- break;
512
- }
513
- case "null": {
514
- result = Schema2.Null;
515
- break;
516
- }
517
- }
518
- } else if ("$ref" in root) {
519
- const refSegments = root.$ref.split("/");
520
- const jsonSchema = defs[refSegments[refSegments.length - 1]];
521
- invariant(jsonSchema, `missing definition for ${root.$ref}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 246, S: void 0, A: ["jsonSchema", "`missing definition for ${root.$ref}`"] });
522
- result = toEffectSchema(jsonSchema, defs).pipe(Schema2.annotations({
523
- identifier: refSegments[refSegments.length - 1]
524
- }));
525
- }
526
- const annotations2 = jsonSchemaFieldsToAnnotations(root);
527
- result = result.annotations(annotations2);
528
- return result;
529
- };
530
- var objectToEffectSchema = (root, defs) => {
531
- invariant("type" in root && root.type === "object", `not an object: ${root}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 257, S: void 0, A: ["'type' in root && root.type === 'object'", "`not an object: ${root}`"] });
532
- const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
533
- const isEchoObject = echoRefinement != null || "$id" in root && typeof root.$id === "string" && root.$id.startsWith("dxn:");
534
- let fields = {};
535
- const propertyList = Object.entries(root.properties ?? {});
536
- let immutableIdField;
537
- for (const [key, value] of propertyList) {
538
- if (isEchoObject && key === "id") {
539
- immutableIdField = toEffectSchema(value, defs);
540
- } else {
541
- fields[key] = root.required?.includes(key) ? toEffectSchema(value, defs) : Schema2.optional(toEffectSchema(value, defs));
542
- }
543
- }
544
- if (root.propertyOrder) {
545
- fields = orderKeys(fields, root.propertyOrder);
546
- }
547
- let schema;
548
- if (root.patternProperties) {
549
- invariant(propertyList.length === 0, "pattern properties mixed with regular properties are not supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 276, S: void 0, A: ["propertyList.length === 0", "'pattern properties mixed with regular properties are not supported'"] });
550
- invariant(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 277, S: void 0, A: ["Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === ''", "'only one pattern property is supported'"] });
551
- schema = Schema2.Record({
552
- key: Schema2.String,
553
- value: toEffectSchema(root.patternProperties[""], defs)
554
- });
555
- } else if (typeof root.additionalProperties !== "object") {
556
- schema = Schema2.Struct(fields);
557
- } else {
558
- const indexValue = toEffectSchema(root.additionalProperties, defs);
559
- if (propertyList.length > 0) {
560
- schema = Schema2.Struct(fields, {
561
- key: Schema2.String,
562
- value: indexValue
563
- });
564
- } else {
565
- schema = Schema2.Record({
566
- key: Schema2.String,
567
- value: indexValue
568
- });
569
- }
570
- }
571
- if (immutableIdField) {
572
- schema = Schema2.extend(schema, Schema2.Struct({
573
- id: immutableIdField
574
- }));
575
- }
576
- const annotations2 = jsonSchemaFieldsToAnnotations(root);
577
- return schema.annotations(annotations2);
578
- };
579
- var anyToEffectSchema = (root) => {
580
- const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
581
- if (echoRefinement?.reference != null) {
582
- const echoUri = root.$id.startsWith("echo:") ? root.$id : void 0;
583
- return createEchoReferenceSchema(echoUri, echoRefinement.reference.typename, echoRefinement.reference.version);
584
- }
585
- return Schema2.Any;
586
- };
587
- var refToEffectSchema = (root) => {
588
- if (!("reference" in root)) {
589
- return createEchoReferenceSchema(void 0, ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION);
590
- }
591
- const reference = root.reference;
592
- if (typeof reference !== "object") {
593
- throw new Error("Invalid reference field in ref schema");
594
- }
595
- const ref = reference.schema.$ref;
596
- const targetSchemaDXN = DXN.tryMake(ref);
597
- invariant(targetSchemaDXN, `Expected a type DXN, got: ${ref}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 327, S: void 0, A: ["targetSchemaDXN", "`Expected a type DXN, got: ${ref}`"] });
598
- return createEchoReferenceSchema(ref, DXN.getName(targetSchemaDXN), reference.schemaVersion);
599
- };
600
- var annotations_toJsonSchemaFields = (annotations2) => {
601
- const schemaFields = {};
602
- const echoAnnotations = {};
603
- for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
604
- if (annotations2[annotationId] != null) {
605
- echoAnnotations[key] = annotations2[annotationId];
606
- }
607
- }
608
- if (Object.keys(echoAnnotations).length > 0) {
609
- schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;
610
- }
611
- const echoIdentifier = annotations2[TypeIdentifierAnnotationId];
612
- if (echoIdentifier) {
613
- schemaFields.$id = echoIdentifier;
614
- }
615
- for (const [key, annotationId] of Object.entries(CustomAnnotations)) {
616
- const value = annotations2[annotationId];
617
- if (value != null) {
618
- schemaFields[key] = value;
619
- }
620
- }
621
- return schemaFields;
622
- };
623
- var decodeTypeIdentifierAnnotation = (schema) => {
624
- if (schema.$id && schema.$id.startsWith("echo:")) {
625
- return schema.$id;
626
- }
627
- const legacySchemaId = schema.echo?.type?.schemaId;
628
- if (legacySchemaId) {
629
- return EntityId.isValid(legacySchemaId) ? EID.make({
630
- entityId: legacySchemaId
631
- }) : legacySchemaId;
632
- }
633
- return void 0;
634
- };
635
- var decodeTypeAnnotation = (schema) => {
636
- if (schema.typename) {
637
- const annotation = {
638
- // TODO(dmaretskyi): Decoding default.
639
- kind: schema.entityKind ? Schema2.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,
640
- typename: schema.typename,
641
- version: schema.version ?? "0.1.0"
642
- };
643
- if (annotation.kind === EntityKind.Relation) {
644
- const source = schema.relationSource?.$ref ?? raise(new Error("Relation source not set"));
645
- const target = schema.relationTarget?.$ref ?? raise(new Error("Relation target not set"));
646
- annotation.sourceSchema = DXN.tryMake(source) ?? raise(new Error(`Invalid relation source: ${source}`));
647
- annotation.targetSchema = DXN.tryMake(target) ?? raise(new Error(`Invalid relation target: ${target}`));
648
- }
649
- return annotation;
650
- }
651
- if (!schema.typename && schema?.echo?.type) {
652
- return {
653
- kind: EntityKind.Object,
654
- typename: schema.echo.type.typename,
655
- version: schema.echo.type.version
656
- };
657
- }
658
- return void 0;
659
- };
660
- var jsonSchemaFieldsToAnnotations = (schema) => {
661
- const annotations2 = {};
662
- const echoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};
663
- if (echoAnnotations) {
664
- for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
665
- if (echoAnnotations[key]) {
666
- annotations2[annotationId] = echoAnnotations[key];
667
- }
668
- }
669
- }
670
- const typeIdentifier = decodeTypeIdentifierAnnotation(schema);
671
- annotations2[TypeIdentifierAnnotationId] = typeIdentifier;
672
- const typeAnnotation = decodeTypeAnnotation(schema);
673
- if (typeAnnotation) {
674
- annotations2[TypeAnnotationId] = typeAnnotation;
675
- annotations2[SchemaAST2.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({
676
- // $id is the typename DXN — the schema's type identity. The storage EID (if any)
677
- // is preserved separately on TypeIdentifierAnnotation / echo.schemaId.
678
- identifier: DXN.make(typeAnnotation.typename, typeAnnotation.version),
679
- kind: typeAnnotation.kind,
680
- typename: typeAnnotation.typename,
681
- version: typeAnnotation.version,
682
- relationSource: typeAnnotation.sourceSchema,
683
- relationTarget: typeAnnotation.targetSchema
684
- });
685
- }
686
- for (const [key, annotationId] of Object.entries({
687
- ...CustomAnnotations,
688
- ...DecodedAnnotations
689
- })) {
690
- if (key in schema) {
691
- annotations2[annotationId] = schema[key];
692
- }
693
- }
694
- return clearUndefined(annotations2);
695
- };
696
- var makeAnnotatedRefinement = (ast, annotations2) => {
697
- return new SchemaAST2.Refinement(ast, () => Option.none(), annotations2);
698
- };
699
- var addJsonSchemaFields = (ast, schema) => makeAnnotatedRefinement(ast, {
700
- [SchemaAST2.JSONSchemaAnnotationId]: schema
701
- });
702
- var normalizeJsonSchema = (jsonSchema) => {
703
- if (jsonSchema.properties && "id" in jsonSchema.properties) {
704
- jsonSchema.properties = orderKeys(jsonSchema.properties, [
705
- "id"
706
- ]);
707
- }
708
- jsonSchema.$schema = JSON_SCHEMA_URL;
709
- jsonSchema = orderKeys(jsonSchema, [
710
- "$schema",
711
- "$id",
712
- "entityKind",
713
- "typename",
714
- "version",
715
- "relationTarget",
716
- "relationSource",
717
- "type",
718
- "enum",
719
- "properties",
720
- "required",
721
- "propertyOrder",
722
- "items",
723
- "additionalProperties",
724
- "anyOf",
725
- "oneOf"
726
- ]);
727
- return jsonSchema;
728
- };
729
-
730
- export {
731
- CustomAnnotations,
732
- DecodedAnnotations,
733
- EchoAnnotations,
734
- JsonSchemaEchoAnnotations,
735
- JsonSchemaFields,
736
- JsonSchemaType,
737
- getSchemaProperty,
738
- setSchemaProperty,
739
- ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,
740
- ECHO_ANNOTATIONS_NS_KEY,
741
- getNormalizedEchoAnnotations,
742
- PropType,
743
- toPropType,
744
- toJsonSchema,
745
- toEffectSchema
746
- };
747
- //# sourceMappingURL=chunk-4A2NWKRJ.mjs.map