@dxos/echo 0.8.4-main.b97322e → 0.8.4-main.c4373fc
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.
- package/README.md +1 -1
- package/dist/lib/browser/chunk-MWLA34S5.mjs +3843 -0
- package/dist/lib/browser/chunk-MWLA34S5.mjs.map +7 -0
- package/dist/lib/browser/chunk-OAZJQHVO.mjs +453 -0
- package/dist/lib/browser/chunk-OAZJQHVO.mjs.map +7 -0
- package/dist/lib/browser/chunk-ORIE2FMS.mjs +514 -0
- package/dist/lib/browser/chunk-ORIE2FMS.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +26 -5
- package/dist/lib/browser/internal/index.mjs +326 -0
- package/dist/lib/browser/internal/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/query/index.mjs +23 -0
- package/dist/lib/browser/query/index.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +260 -32
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs +453 -0
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs +514 -0
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YTNLFBIK.mjs +3843 -0
- package/dist/lib/node-esm/chunk-YTNLFBIK.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +26 -5
- package/dist/lib/node-esm/internal/index.mjs +326 -0
- package/dist/lib/node-esm/internal/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/query/index.mjs +23 -0
- package/dist/lib/node-esm/query/index.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +260 -32
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Obj.d.ts +111 -17
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +1 -1
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +11 -8
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +17 -18
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +72 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/ast/annotation-helper.d.ts +8 -0
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +1 -0
- package/dist/types/src/internal/ast/annotations.d.ts +119 -0
- package/dist/types/src/internal/ast/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/ast/annotations.test.d.ts +2 -0
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/ast/entity-kind.d.ts +10 -0
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +1 -0
- package/dist/types/src/internal/ast/index.d.ts +5 -0
- package/dist/types/src/internal/ast/index.d.ts.map +1 -0
- package/dist/types/src/internal/ast/types.d.ts +6 -0
- package/dist/types/src/internal/ast/types.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.d.ts +63 -0
- package/dist/types/src/internal/formats/date.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.test.d.ts +2 -0
- package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +30 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.test.d.ts +2 -0
- package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/index.d.ts +8 -0
- package/dist/types/src/internal/formats/index.d.ts.map +1 -0
- package/dist/types/src/internal/formats/number.d.ts +31 -0
- package/dist/types/src/internal/formats/number.d.ts.map +1 -0
- package/dist/types/src/internal/formats/object.d.ts +35 -0
- package/dist/types/src/internal/formats/object.d.ts.map +1 -0
- package/dist/types/src/internal/formats/select.d.ts +11 -0
- package/dist/types/src/internal/formats/select.d.ts.map +1 -0
- package/dist/types/src/internal/formats/string.d.ts +38 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -0
- package/dist/types/src/internal/formats/types.d.ts +68 -0
- package/dist/types/src/internal/formats/types.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +15 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/json/annotations.d.ts +19 -0
- package/dist/types/src/internal/json/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json/effect-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json/index.d.ts +2 -0
- package/dist/types/src/internal/json/index.d.ts.map +1 -0
- package/dist/types/src/internal/json/json-schema.d.ts +32 -0
- package/dist/types/src/internal/json/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json/json-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +3 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/object/accessors.d.ts +29 -0
- package/dist/types/src/internal/object/accessors.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts +18 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -0
- package/dist/types/src/internal/object/create.d.ts +40 -0
- package/dist/types/src/internal/object/create.d.ts.map +1 -0
- package/dist/types/src/internal/object/create.test.d.ts +2 -0
- package/dist/types/src/internal/object/create.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +6 -0
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/object/entity.d.ts +22 -0
- package/dist/types/src/internal/object/entity.d.ts.map +1 -0
- package/dist/types/src/internal/object/expando.d.ts +14 -0
- package/dist/types/src/internal/object/expando.d.ts.map +1 -0
- package/dist/types/src/internal/object/ids.d.ts +6 -0
- package/dist/types/src/internal/object/ids.d.ts.map +1 -0
- package/dist/types/src/internal/object/index.d.ts +17 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -0
- package/dist/types/src/internal/object/inspect.d.ts +2 -0
- package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.d.ts +32 -0
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/meta.d.ts +31 -0
- package/dist/types/src/internal/object/meta.d.ts.map +1 -0
- package/dist/types/src/internal/object/model.d.ts +117 -0
- package/dist/types/src/internal/object/model.d.ts.map +1 -0
- package/dist/types/src/internal/object/relation.d.ts +17 -0
- package/dist/types/src/internal/object/relation.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.d.ts +15 -0
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.d.ts +31 -0
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-relation.d.ts +32 -0
- package/dist/types/src/internal/object/typed-relation.d.ts.map +1 -0
- package/dist/types/src/internal/object/typename.d.ts +15 -0
- package/dist/types/src/internal/object/typename.d.ts.map +1 -0
- package/dist/types/src/internal/object/version.d.ts +14 -0
- package/dist/types/src/internal/object/version.d.ts.map +1 -0
- package/dist/types/src/internal/projection/compose.d.ts +6 -0
- package/dist/types/src/internal/projection/compose.d.ts.map +1 -0
- package/dist/types/src/internal/projection/compose.test.d.ts +2 -0
- package/dist/types/src/internal/projection/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/projection/index.d.ts +2 -0
- package/dist/types/src/internal/projection/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive-object.d.ts +15 -0
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +44 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/query/index.d.ts +2 -0
- package/dist/types/src/internal/query/index.d.ts.map +1 -0
- package/dist/types/src/internal/query/query.d.ts +17 -0
- package/dist/types/src/internal/query/query.d.ts.map +1 -0
- package/dist/types/src/internal/ref/index.d.ts +3 -0
- package/dist/types/src/internal/ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.d.ts +206 -0
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
- package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +168 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/index.d.ts +7 -0
- package/dist/types/src/internal/schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +18 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -0
- package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
- package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/schema/stored-schema.d.ts +13 -0
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +1 -0
- package/dist/types/src/internal/testing/index.d.ts +3 -0
- package/dist/types/src/internal/testing/index.d.ts.map +1 -0
- package/dist/types/src/internal/testing/types.d.ts +455 -0
- package/dist/types/src/internal/testing/types.d.ts.map +1 -0
- package/dist/types/src/internal/testing/utils.d.ts +10 -0
- package/dist/types/src/internal/testing/utils.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +3 -0
- package/dist/types/src/internal/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/types/types.d.ts +79 -0
- package/dist/types/src/internal/types/types.d.ts.map +1 -0
- package/dist/types/src/internal/types/types.test.d.ts +2 -0
- package/dist/types/src/internal/types/types.test.d.ts.map +1 -0
- package/dist/types/src/internal/types/util.d.ts +5 -0
- package/dist/types/src/internal/types/util.d.ts.map +1 -0
- package/dist/types/src/query/index.d.ts +2 -1
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/query/{dsl.d.ts → query.d.ts} +44 -15
- package/dist/types/src/query/query.d.ts.map +1 -0
- package/dist/types/src/query/query.test.d.ts +2 -0
- package/dist/types/src/query/query.test.d.ts.map +1 -0
- package/dist/types/src/query/tag.d.ts +18 -0
- package/dist/types/src/query/tag.d.ts.map +1 -0
- package/dist/types/src/testing/echo-schema.d.ts +7 -0
- package/dist/types/src/testing/echo-schema.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +18 -18
- package/dist/types/src/testing/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -16
- package/src/Obj.ts +250 -27
- package/src/Ref.ts +1 -2
- package/src/Relation.ts +25 -13
- package/src/Type.ts +32 -31
- package/src/errors.ts +18 -0
- package/src/index.ts +4 -1
- package/src/internal/ast/annotation-helper.ts +22 -0
- package/src/internal/ast/annotations.test.ts +98 -0
- package/src/internal/ast/annotations.ts +212 -0
- package/src/internal/ast/entity-kind.ts +15 -0
- package/src/internal/ast/index.ts +8 -0
- package/src/internal/ast/types.ts +17 -0
- package/src/internal/formats/date.test.ts +56 -0
- package/src/internal/formats/date.ts +217 -0
- package/src/internal/formats/format.test.ts +77 -0
- package/src/internal/formats/format.ts +52 -0
- package/src/internal/formats/index.ts +12 -0
- package/src/internal/formats/number.ts +89 -0
- package/src/internal/formats/object.ts +80 -0
- package/src/internal/formats/select.ts +16 -0
- package/src/internal/formats/string.ts +76 -0
- package/src/internal/formats/types.ts +175 -0
- package/src/internal/index.ts +22 -0
- package/src/internal/json/annotations.ts +50 -0
- package/src/internal/json/effect-schema.test.ts +143 -0
- package/src/internal/json/index.ts +5 -0
- package/src/internal/json/json-schema.test.ts +726 -0
- package/src/internal/json/json-schema.ts +548 -0
- package/src/internal/json-schema/index.ts +6 -0
- package/src/internal/json-schema/json-schema-normalize.ts +109 -0
- package/src/internal/json-schema/json-schema-type.ts +403 -0
- package/src/internal/object/accessors.ts +115 -0
- package/src/internal/object/common.ts +76 -0
- package/src/internal/object/create.test.ts +118 -0
- package/src/internal/object/create.ts +96 -0
- package/src/internal/object/deleted.ts +19 -0
- package/src/internal/object/entity.ts +204 -0
- package/src/internal/object/expando.ts +21 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +20 -0
- package/src/internal/object/inspect.ts +48 -0
- package/src/internal/object/json-serializer.test.ts +99 -0
- package/src/internal/object/json-serializer.ts +225 -0
- package/src/internal/object/meta.ts +62 -0
- package/src/internal/object/model.ts +170 -0
- package/src/internal/object/relation.ts +24 -0
- package/src/internal/object/schema-validator.test.ts +186 -0
- package/src/internal/object/schema-validator.ts +241 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +81 -0
- package/src/internal/object/typed-relation.ts +85 -0
- package/src/internal/object/typename.ts +61 -0
- package/src/internal/object/version.ts +22 -0
- package/src/internal/projection/compose.test.ts +43 -0
- package/src/internal/projection/compose.ts +36 -0
- package/src/internal/projection/index.ts +5 -0
- package/src/internal/proxy/handler.test.ts +163 -0
- package/src/internal/proxy/reactive-object.ts +108 -0
- package/src/internal/proxy/schema.test.ts +136 -0
- package/src/internal/proxy/typed-handler.test.ts +102 -0
- package/src/internal/proxy/typed-handler.ts +228 -0
- package/src/internal/proxy/typed-object.test.ts +100 -0
- package/src/internal/query/index.ts +5 -0
- package/src/internal/query/query.ts +23 -0
- package/src/internal/ref/index.ts +6 -0
- package/src/internal/ref/ref-array.ts +39 -0
- package/src/internal/ref/ref.test.ts +100 -0
- package/src/internal/ref/ref.ts +521 -0
- package/src/internal/schema/echo-schema.ts +383 -0
- package/src/internal/schema/index.ts +10 -0
- package/src/internal/schema/manipulation.ts +86 -0
- package/src/internal/schema/runtime-schema-registry.ts +78 -0
- package/src/internal/schema/snapshot.ts +25 -0
- package/src/internal/schema/stored-schema.ts +26 -0
- package/src/internal/testing/index.ts +6 -0
- package/src/internal/testing/types.ts +211 -0
- package/src/internal/testing/utils.ts +54 -0
- package/src/internal/types/index.ts +6 -0
- package/src/internal/types/types.test.ts +48 -0
- package/src/internal/types/types.ts +176 -0
- package/src/internal/types/util.ts +9 -0
- package/src/query/index.ts +2 -1
- package/src/query/{dsl.test.ts → query.test.ts} +41 -2
- package/src/query/{dsl.ts → query.ts} +170 -32
- package/src/query/tag.ts +35 -0
- package/src/test/api.test.ts +17 -10
- package/src/testing/echo-schema.ts +39 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/types.ts +1 -1
- package/dist/lib/browser/chunk-EUA7CM23.mjs +0 -619
- package/dist/lib/browser/chunk-EUA7CM23.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IV6BWGHK.mjs +0 -619
- package/dist/lib/node-esm/chunk-IV6BWGHK.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import type * as JSONSchema from 'effect/JSONSchema';
|
|
7
|
+
import * as Option from 'effect/Option';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
9
|
+
|
|
10
|
+
import { createAnnotationHelper } from '../ast';
|
|
11
|
+
import { type JsonSchemaType } from '../json-schema';
|
|
12
|
+
|
|
13
|
+
// TODO(burdon): Rename PropertyType.
|
|
14
|
+
export type ScalarType =
|
|
15
|
+
| JSONSchema.JsonSchema7Object
|
|
16
|
+
| JSONSchema.JsonSchema7String
|
|
17
|
+
| JSONSchema.JsonSchema7Number
|
|
18
|
+
| JSONSchema.JsonSchema7Boolean
|
|
19
|
+
| JSONSchema.JsonSchema7Ref;
|
|
20
|
+
|
|
21
|
+
// TODO(burdon): Rename ValueType and change to disciminated union.
|
|
22
|
+
// export type ValueType = 'array' | 'object' | 'string' | 'number' | 'boolean' | 'ref';
|
|
23
|
+
export enum TypeEnum {
|
|
24
|
+
Array = 'array', // TODO(burdon): Remove?
|
|
25
|
+
Object = 'object',
|
|
26
|
+
String = 'string',
|
|
27
|
+
Number = 'number',
|
|
28
|
+
Boolean = 'boolean',
|
|
29
|
+
Ref = 'ref',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// TODO(burdon): Ref?
|
|
33
|
+
export const getTypeEnum = (property: JsonSchemaType): TypeEnum | undefined => {
|
|
34
|
+
switch (property.type) {
|
|
35
|
+
case 'array':
|
|
36
|
+
return TypeEnum.Array;
|
|
37
|
+
case 'object':
|
|
38
|
+
return TypeEnum.Object;
|
|
39
|
+
case 'string':
|
|
40
|
+
return TypeEnum.String;
|
|
41
|
+
case 'number':
|
|
42
|
+
return TypeEnum.Number;
|
|
43
|
+
case 'boolean':
|
|
44
|
+
return TypeEnum.Boolean;
|
|
45
|
+
default:
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* https://json-schema.org/understanding-json-schema/reference/schema
|
|
52
|
+
* https://json-schema.org/understanding-json-schema/reference/string#built-in-formats
|
|
53
|
+
*/
|
|
54
|
+
export const FormatAnnotationId = Symbol.for('@dxos/schema/annotation/Format');
|
|
55
|
+
|
|
56
|
+
export const FormatAnnotation = createAnnotationHelper<FormatEnum>(FormatAnnotationId);
|
|
57
|
+
|
|
58
|
+
export const getFormatAnnotation = (node: SchemaAST.AST): FormatEnum | undefined =>
|
|
59
|
+
Function.pipe(SchemaAST.getAnnotation<FormatEnum>(FormatAnnotationId)(node), Option.getOrUndefined);
|
|
60
|
+
|
|
61
|
+
// TODO(burdon): Rename to FormatType and change to discriminated union.
|
|
62
|
+
export enum FormatEnum {
|
|
63
|
+
None = 'none',
|
|
64
|
+
String = 'string',
|
|
65
|
+
Number = 'number',
|
|
66
|
+
Boolean = 'boolean',
|
|
67
|
+
Ref = 'ref',
|
|
68
|
+
|
|
69
|
+
//
|
|
70
|
+
// { type: 'string' }
|
|
71
|
+
//
|
|
72
|
+
|
|
73
|
+
DID = 'did', // Users, etc.
|
|
74
|
+
DXN = 'dxn',
|
|
75
|
+
Email = 'email',
|
|
76
|
+
Formula = 'formula', // Spreadsheet formula.
|
|
77
|
+
Hostname = 'hostname',
|
|
78
|
+
JSON = 'json',
|
|
79
|
+
Markdown = 'markdown',
|
|
80
|
+
Regex = 'regex',
|
|
81
|
+
SingleSelect = 'single-select',
|
|
82
|
+
MultiSelect = 'multi-select',
|
|
83
|
+
URL = 'url',
|
|
84
|
+
UUID = 'uuid',
|
|
85
|
+
|
|
86
|
+
//
|
|
87
|
+
// { type: 'number' }
|
|
88
|
+
//
|
|
89
|
+
|
|
90
|
+
Currency = 'currency',
|
|
91
|
+
Integer = 'integer',
|
|
92
|
+
Percent = 'percent',
|
|
93
|
+
Timestamp = 'timestamp',
|
|
94
|
+
|
|
95
|
+
//
|
|
96
|
+
// { type: 'date' }
|
|
97
|
+
//
|
|
98
|
+
|
|
99
|
+
DateTime = 'date-time',
|
|
100
|
+
Date = 'date',
|
|
101
|
+
Time = 'time',
|
|
102
|
+
Duration = 'duration',
|
|
103
|
+
|
|
104
|
+
//
|
|
105
|
+
// { type: 'object' }
|
|
106
|
+
//
|
|
107
|
+
|
|
108
|
+
GeoPoint = 'lnglat',
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const FormatEnums = Object.values(FormatEnum).sort();
|
|
112
|
+
|
|
113
|
+
export const PropertyKind = {
|
|
114
|
+
type: TypeEnum,
|
|
115
|
+
format: FormatEnum,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Default formats
|
|
120
|
+
*/
|
|
121
|
+
export const typeToFormat: Partial<Record<TypeEnum, FormatEnum>> = {
|
|
122
|
+
[TypeEnum.String]: FormatEnum.String,
|
|
123
|
+
[TypeEnum.Number]: FormatEnum.Number,
|
|
124
|
+
[TypeEnum.Boolean]: FormatEnum.Boolean,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Map of format to type.
|
|
129
|
+
*/
|
|
130
|
+
export const formatToType: Record<FormatEnum, TypeEnum> = {
|
|
131
|
+
[FormatEnum.None]: undefined as any,
|
|
132
|
+
[FormatEnum.String]: TypeEnum.String,
|
|
133
|
+
[FormatEnum.Number]: TypeEnum.Number,
|
|
134
|
+
[FormatEnum.Boolean]: TypeEnum.Boolean,
|
|
135
|
+
[FormatEnum.Ref]: TypeEnum.Ref,
|
|
136
|
+
|
|
137
|
+
// Strings
|
|
138
|
+
[FormatEnum.DID]: TypeEnum.String,
|
|
139
|
+
[FormatEnum.DXN]: TypeEnum.String,
|
|
140
|
+
[FormatEnum.Email]: TypeEnum.String,
|
|
141
|
+
[FormatEnum.Formula]: TypeEnum.String,
|
|
142
|
+
[FormatEnum.Hostname]: TypeEnum.String,
|
|
143
|
+
[FormatEnum.JSON]: TypeEnum.String,
|
|
144
|
+
[FormatEnum.Markdown]: TypeEnum.String,
|
|
145
|
+
[FormatEnum.Regex]: TypeEnum.String,
|
|
146
|
+
[FormatEnum.URL]: TypeEnum.String,
|
|
147
|
+
[FormatEnum.UUID]: TypeEnum.String,
|
|
148
|
+
[FormatEnum.SingleSelect]: TypeEnum.String,
|
|
149
|
+
[FormatEnum.MultiSelect]: TypeEnum.Object,
|
|
150
|
+
|
|
151
|
+
// Dates
|
|
152
|
+
[FormatEnum.Date]: TypeEnum.String,
|
|
153
|
+
[FormatEnum.DateTime]: TypeEnum.String,
|
|
154
|
+
[FormatEnum.Duration]: TypeEnum.String,
|
|
155
|
+
[FormatEnum.Time]: TypeEnum.String,
|
|
156
|
+
|
|
157
|
+
// Numbers
|
|
158
|
+
[FormatEnum.Currency]: TypeEnum.Number,
|
|
159
|
+
[FormatEnum.Integer]: TypeEnum.Number,
|
|
160
|
+
[FormatEnum.Percent]: TypeEnum.Number,
|
|
161
|
+
[FormatEnum.Timestamp]: TypeEnum.Number,
|
|
162
|
+
|
|
163
|
+
// Objects
|
|
164
|
+
[FormatEnum.GeoPoint]: TypeEnum.Array,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Allowed value options for select.
|
|
169
|
+
*/
|
|
170
|
+
export const OptionsAnnotationId = Symbol.for('@dxos/schema/annotation/Options');
|
|
171
|
+
|
|
172
|
+
export const getOptionsAnnotation = (node: SchemaAST.AST): OptionsAnnotationType[] | undefined =>
|
|
173
|
+
Function.pipe(SchemaAST.getAnnotation<OptionsAnnotationType[]>(OptionsAnnotationId)(node), Option.getOrUndefined);
|
|
174
|
+
|
|
175
|
+
export type OptionsAnnotationType = string | number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export { JsonPath, splitJsonPath, JsonProp } from '@dxos/effect';
|
|
6
|
+
|
|
7
|
+
// TODO(dmaretskyi): Remove.
|
|
8
|
+
export { ObjectId } from '@dxos/keys';
|
|
9
|
+
export { ForeignKey } from '@dxos/echo-protocol';
|
|
10
|
+
|
|
11
|
+
export * from './ast';
|
|
12
|
+
export * from './formats';
|
|
13
|
+
export * from './json';
|
|
14
|
+
export * from './json-schema';
|
|
15
|
+
export * from './object';
|
|
16
|
+
export * from './types';
|
|
17
|
+
export { defineHiddenProperty } from '@dxos/live-object';
|
|
18
|
+
export * from './ref';
|
|
19
|
+
export * from './projection';
|
|
20
|
+
export * from './schema';
|
|
21
|
+
// TODO(dmaretskyi): Remove
|
|
22
|
+
export { live } from './proxy/reactive-object';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
|
+
|
|
7
|
+
import { GeneratorAnnotationId, LabelAnnotationId, PropertyMetaAnnotationId } from '../ast';
|
|
8
|
+
import { CurrencyAnnotationId, FormatAnnotationId } from '../formats';
|
|
9
|
+
import { type JsonSchemaEchoAnnotations, type JsonSchemaType } from '../json-schema';
|
|
10
|
+
|
|
11
|
+
//
|
|
12
|
+
// This file configures annotations for JSON encoding/decoding.
|
|
13
|
+
//
|
|
14
|
+
|
|
15
|
+
// Go on the root level.
|
|
16
|
+
type RootJsonSchemaProperty = keyof JsonSchemaType;
|
|
17
|
+
|
|
18
|
+
// Go on the namespaced `annotations` property.
|
|
19
|
+
type NamespacedJsonSchemaProperty = keyof JsonSchemaEchoAnnotations;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* List of annotations for JSON encoding/decoding.
|
|
23
|
+
* Omits default effect-schema annotations since they are encoded with default serializer.
|
|
24
|
+
*/
|
|
25
|
+
// TODO(burdon): Reconcile with `EchoAnnotations`.
|
|
26
|
+
export const CustomAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {
|
|
27
|
+
format: FormatAnnotationId,
|
|
28
|
+
currency: CurrencyAnnotationId,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* List of annotations for JSON decoding only.
|
|
33
|
+
* Includes default effect annotations.
|
|
34
|
+
*/
|
|
35
|
+
export const DecodedAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {
|
|
36
|
+
title: SchemaAST.TitleAnnotationId,
|
|
37
|
+
description: SchemaAST.DescriptionAnnotationId,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Annotations that go into ECHO namespace in json-schema.
|
|
42
|
+
*/
|
|
43
|
+
// TODO(dmaretskyi): Consider removing ECHO namespace and putting them at the top level.
|
|
44
|
+
// TODO(dmaretskyi): Move to format.ts when circular imports are solved
|
|
45
|
+
export const EchoAnnotations: Partial<Record<NamespacedJsonSchemaProperty, symbol>> = {
|
|
46
|
+
// TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.
|
|
47
|
+
meta: PropertyMetaAnnotationId,
|
|
48
|
+
generator: GeneratorAnnotationId,
|
|
49
|
+
labelProp: LabelAnnotationId,
|
|
50
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as JSONSchema from 'effect/JSONSchema';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
9
|
+
import { expect, test } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
|
|
13
|
+
test('json-schema annotations for filter refinement get combined', () => {
|
|
14
|
+
const type = Schema.Number.annotations({
|
|
15
|
+
jsonSchema: { foo: 'foo' },
|
|
16
|
+
}).pipe(Schema.filter(() => true, { jsonSchema: { bar: 'bar' } }));
|
|
17
|
+
|
|
18
|
+
const jsonSchema = JSONSchema.make(type);
|
|
19
|
+
expect(jsonSchema).toEqual({
|
|
20
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
21
|
+
foo: 'foo',
|
|
22
|
+
bar: 'bar',
|
|
23
|
+
type: 'number',
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('json-schema annotations on types do not override the default serialization', () => {
|
|
28
|
+
const type = Schema.Number.annotations({
|
|
29
|
+
jsonSchema: { foo: 'foo' },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const jsonSchema = JSONSchema.make(type);
|
|
33
|
+
expect(jsonSchema).toEqual({
|
|
34
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
35
|
+
foo: 'foo',
|
|
36
|
+
type: 'number',
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// pass
|
|
41
|
+
test('number with title and description annotations', () => {
|
|
42
|
+
const number = Schema.Number.annotations({
|
|
43
|
+
title: 'My Title',
|
|
44
|
+
description: 'My Description',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(JSONSchema.make(number)).toEqual({
|
|
48
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
49
|
+
type: 'number',
|
|
50
|
+
title: 'My Title',
|
|
51
|
+
description: 'My Description',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// pass
|
|
56
|
+
test('date with title and description annotations', () => {
|
|
57
|
+
const date = Schema.Date.annotations({
|
|
58
|
+
title: 'My Title',
|
|
59
|
+
description: 'My Description',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(JSONSchema.make(date)).toEqual({
|
|
63
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
64
|
+
$defs: {
|
|
65
|
+
DateFromString: {
|
|
66
|
+
description: 'a string to be decoded into a Date',
|
|
67
|
+
type: 'string',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
$ref: '#/$defs/DateFromString',
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// fail
|
|
75
|
+
test('declare', () => {
|
|
76
|
+
class MyType {}
|
|
77
|
+
const type = Schema.declare<MyType>((x) => x instanceof MyType, {
|
|
78
|
+
jsonSchema: {
|
|
79
|
+
type: 'my-type',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(JSONSchema.make(type)).toEqual({
|
|
84
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
85
|
+
type: 'my-type',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(type.pipe(Schema.is)(new MyType())).toBe(true);
|
|
89
|
+
expect(type.pipe(Schema.is)({})).toBe(false);
|
|
90
|
+
|
|
91
|
+
const withAnnotations = type.annotations({
|
|
92
|
+
title: 'My Title',
|
|
93
|
+
description: 'My Description',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(JSONSchema.make(withAnnotations)).toEqual({
|
|
97
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
98
|
+
type: 'my-type',
|
|
99
|
+
title: 'My Title',
|
|
100
|
+
description: 'My Description',
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// pass
|
|
105
|
+
test('declare with refinement', () => {
|
|
106
|
+
class MyType {}
|
|
107
|
+
const type = Schema.declare<MyType>((x) => x instanceof MyType, {
|
|
108
|
+
jsonSchema: {
|
|
109
|
+
type: 'my-type',
|
|
110
|
+
},
|
|
111
|
+
}).pipe(Schema.filter(() => true, { jsonSchema: {} }));
|
|
112
|
+
|
|
113
|
+
const named = type.annotations({
|
|
114
|
+
title: 'My Title',
|
|
115
|
+
description: 'My Description',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(JSONSchema.make(named)).toEqual({
|
|
119
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
120
|
+
type: 'my-type',
|
|
121
|
+
title: 'My Title',
|
|
122
|
+
description: 'My Description',
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("default title annotations don't get serialized", () => {
|
|
127
|
+
const schema = Schema.String;
|
|
128
|
+
|
|
129
|
+
expect(SchemaAST.getTitleAnnotation(schema.ast).pipe(Option.getOrUndefined)).toEqual('string');
|
|
130
|
+
expect(SchemaAST.getDescriptionAnnotation(schema.ast).pipe(Option.getOrUndefined)).toEqual('a string');
|
|
131
|
+
|
|
132
|
+
expect(JSONSchema.make(schema)).toEqual({
|
|
133
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
134
|
+
type: 'string',
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test.skip('ast comparison', () => {
|
|
139
|
+
log.info('ast', {
|
|
140
|
+
default: Schema.String.ast,
|
|
141
|
+
annotated: Schema.String.annotations({ title: 'Custom title', description: 'Custom description' }).ast,
|
|
142
|
+
});
|
|
143
|
+
});
|