@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,726 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Option from 'effect/Option';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
import { describe, expect, test } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import { type JsonProp, findAnnotation } from '@dxos/effect';
|
|
11
|
+
import { ObjectId } from '@dxos/keys';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
EntityKind,
|
|
16
|
+
FieldLookupAnnotationId,
|
|
17
|
+
GeneratorAnnotation,
|
|
18
|
+
LabelAnnotation,
|
|
19
|
+
PropertyMeta,
|
|
20
|
+
getTypeAnnotation,
|
|
21
|
+
getTypeIdentifierAnnotation,
|
|
22
|
+
} from '../ast';
|
|
23
|
+
import { Email, FormatAnnotation, FormatEnum } from '../formats';
|
|
24
|
+
import { JsonSchemaType, getNormalizedEchoAnnotations, getSchemaProperty, setSchemaProperty } from '../json-schema';
|
|
25
|
+
import { EchoObject, TypedObject } from '../object';
|
|
26
|
+
import { Ref, createSchemaReference, getReferenceAst, getSchemaReference } from '../ref';
|
|
27
|
+
import { StoredSchema } from '../schema';
|
|
28
|
+
import { Testing, prepareAstForCompare } from '../testing';
|
|
29
|
+
|
|
30
|
+
import { toEffectSchema, toJsonSchema } from './json-schema';
|
|
31
|
+
|
|
32
|
+
const EXAMPLE_NAMESPACE = '@example';
|
|
33
|
+
|
|
34
|
+
describe('effect-to-json', () => {
|
|
35
|
+
test('type annotation', () => {
|
|
36
|
+
class Test extends TypedObject({
|
|
37
|
+
typename: 'example.com/type/Test',
|
|
38
|
+
version: '0.1.0',
|
|
39
|
+
})({ name: Schema.String }) {}
|
|
40
|
+
const jsonSchema = toJsonSchema(Test);
|
|
41
|
+
expect((jsonSchema as any).$id).toEqual('dxn:type:example.com/type/Test');
|
|
42
|
+
expect((jsonSchema as any).version).toEqual('0.1.0');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('property meta annotation', () => {
|
|
46
|
+
const meta = { maxLength: 0 };
|
|
47
|
+
class Test extends TypedObject({
|
|
48
|
+
typename: 'example.com/type/Test',
|
|
49
|
+
version: '0.1.0',
|
|
50
|
+
})({
|
|
51
|
+
name: Schema.String.pipe(PropertyMeta(EXAMPLE_NAMESPACE, meta)),
|
|
52
|
+
}) {}
|
|
53
|
+
const jsonSchema = toJsonSchema(Test);
|
|
54
|
+
expect(getNormalizedEchoAnnotations(jsonSchema.properties!.name!)!.meta![EXAMPLE_NAMESPACE]).to.deep.eq(meta);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('reference annotation', () => {
|
|
58
|
+
class Nested extends TypedObject({ typename: 'example.com/type/TestNested', version: '0.1.0' })({
|
|
59
|
+
name: Schema.String,
|
|
60
|
+
}) {}
|
|
61
|
+
class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
|
|
62
|
+
name: Ref(Nested),
|
|
63
|
+
}) {}
|
|
64
|
+
const jsonSchema = toJsonSchema(Test);
|
|
65
|
+
// log.info('schema', { jsonSchema });
|
|
66
|
+
const nested = jsonSchema.properties!.name;
|
|
67
|
+
expectReferenceAnnotation(nested);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// TODO(ZaymonFC): @dmaretskyi we still need to fix this.
|
|
71
|
+
// TODO(dmaretskyi): Remove FieldLookupAnnotationId.
|
|
72
|
+
test.skip('reference annotation with lookup property', () => {
|
|
73
|
+
class Nested extends TypedObject({ typename: 'example.com/type/TestNested', version: '0.1.0' })({
|
|
74
|
+
name: Schema.String,
|
|
75
|
+
}) {}
|
|
76
|
+
class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
|
|
77
|
+
name: Ref(Nested).annotations({ [FieldLookupAnnotationId]: 'name' }),
|
|
78
|
+
}) {}
|
|
79
|
+
const jsonSchema = toJsonSchema(Test);
|
|
80
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
81
|
+
|
|
82
|
+
const annotation = findAnnotation<string>(effectSchema.ast, FieldLookupAnnotationId);
|
|
83
|
+
expect(annotation).to.not.toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('array of references', () => {
|
|
87
|
+
class Nested extends TypedObject({ typename: 'example.com/type/TestNested', version: '0.1.0' })({
|
|
88
|
+
name: Schema.String,
|
|
89
|
+
}) {}
|
|
90
|
+
class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
|
|
91
|
+
name: Schema.Array(Ref(Nested)),
|
|
92
|
+
}) {}
|
|
93
|
+
|
|
94
|
+
const jsonSchema = toJsonSchema(Test);
|
|
95
|
+
expectReferenceAnnotation((jsonSchema.properties!.name as any).items);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('optional references', () => {
|
|
99
|
+
class Nested extends TypedObject({ typename: 'example.com/type/TestNested', version: '0.1.0' })({
|
|
100
|
+
name: Schema.String,
|
|
101
|
+
}) {}
|
|
102
|
+
class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
|
|
103
|
+
name: Schema.optional(Ref(Nested)),
|
|
104
|
+
}) {}
|
|
105
|
+
const jsonSchema = toJsonSchema(Test);
|
|
106
|
+
expectReferenceAnnotation(jsonSchema.properties!.name);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('regular objects are not annotated', () => {
|
|
110
|
+
const object = Schema.Struct({ name: Schema.Struct({ name: Schema.String }) });
|
|
111
|
+
const jsonSchema = toJsonSchema(object);
|
|
112
|
+
expect(getNormalizedEchoAnnotations(jsonSchema)).to.be.undefined;
|
|
113
|
+
expect(getNormalizedEchoAnnotations(jsonSchema.properties!.name!)).to.be.undefined;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('annotations', () => {
|
|
117
|
+
class TestSchema extends TypedObject({ typename: 'example.com/type/Contact', version: '0.1.0' })({
|
|
118
|
+
name: Schema.String.annotations({ description: 'Person name', title: 'Name' }),
|
|
119
|
+
email: Schema.String.pipe(FormatAnnotation.set(FormatEnum.Email)).annotations({
|
|
120
|
+
description: 'Email address',
|
|
121
|
+
}),
|
|
122
|
+
}) {}
|
|
123
|
+
const jsonSchema = toJsonSchema(TestSchema);
|
|
124
|
+
expect(jsonSchema).to.deep.eq({
|
|
125
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
126
|
+
$id: 'dxn:type:example.com/type/Contact',
|
|
127
|
+
|
|
128
|
+
entityKind: EntityKind.Object,
|
|
129
|
+
typename: 'example.com/type/Contact',
|
|
130
|
+
version: '0.1.0',
|
|
131
|
+
|
|
132
|
+
type: 'object',
|
|
133
|
+
required: ['name', 'email', 'id'],
|
|
134
|
+
properties: {
|
|
135
|
+
id: { type: 'string' },
|
|
136
|
+
name: { type: 'string', title: 'Name', description: 'Person name' },
|
|
137
|
+
email: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
|
|
140
|
+
description: 'Email address',
|
|
141
|
+
format: 'email',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
propertyOrder: ['name', 'email', 'id'],
|
|
145
|
+
additionalProperties: false,
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('handles suspend -- Contact schema serialization', () => {
|
|
150
|
+
const schema = toJsonSchema(Testing.Contact);
|
|
151
|
+
expect(Object.keys(schema.properties!)).toEqual([
|
|
152
|
+
'id',
|
|
153
|
+
'name',
|
|
154
|
+
'username',
|
|
155
|
+
'email',
|
|
156
|
+
'phoneNumbers',
|
|
157
|
+
'tasks',
|
|
158
|
+
'address',
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('reference property by ref', () => {
|
|
163
|
+
class Organization extends TypedObject({ typename: 'example.com/type/Organization', version: '0.1.0' })({
|
|
164
|
+
field: Schema.String,
|
|
165
|
+
}) {}
|
|
166
|
+
|
|
167
|
+
class Contact extends TypedObject({ typename: 'example.com/type/Contact', version: '0.1.0' })({
|
|
168
|
+
name: Schema.String,
|
|
169
|
+
organization: Ref(Organization).annotations({ description: 'Contact organization' }),
|
|
170
|
+
}) {}
|
|
171
|
+
|
|
172
|
+
// log.info('Contact', { ast: Contact.ast });
|
|
173
|
+
|
|
174
|
+
const jsonSchema = toJsonSchema(Contact);
|
|
175
|
+
expect(jsonSchema).toEqual({
|
|
176
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
177
|
+
$id: 'dxn:type:example.com/type/Contact',
|
|
178
|
+
|
|
179
|
+
entityKind: EntityKind.Object,
|
|
180
|
+
typename: 'example.com/type/Contact',
|
|
181
|
+
version: '0.1.0',
|
|
182
|
+
|
|
183
|
+
type: 'object',
|
|
184
|
+
additionalProperties: false,
|
|
185
|
+
|
|
186
|
+
properties: {
|
|
187
|
+
id: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
},
|
|
190
|
+
name: {
|
|
191
|
+
type: 'string',
|
|
192
|
+
},
|
|
193
|
+
organization: {
|
|
194
|
+
allOf: [
|
|
195
|
+
{
|
|
196
|
+
$id: '/schemas/echo/ref',
|
|
197
|
+
$ref: '/schemas/echo/ref',
|
|
198
|
+
reference: {
|
|
199
|
+
schema: {
|
|
200
|
+
$ref: 'dxn:type:example.com/type/Organization',
|
|
201
|
+
},
|
|
202
|
+
schemaVersion: '0.1.0',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
description: 'Contact organization',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
required: ['name', 'organization', 'id'],
|
|
210
|
+
propertyOrder: ['name', 'organization', 'id'],
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('add reference property', () => {
|
|
215
|
+
class Organization extends TypedObject({ typename: 'example.com/type/Organization', version: '0.1.0' })({
|
|
216
|
+
field: Schema.String,
|
|
217
|
+
}) {}
|
|
218
|
+
|
|
219
|
+
class Contact extends TypedObject({ typename: 'example.com/type/Contact', version: '0.1.0' })({
|
|
220
|
+
name: Schema.String,
|
|
221
|
+
organization: Ref(Organization).annotations({ description: 'Contact organization' }),
|
|
222
|
+
}) {}
|
|
223
|
+
|
|
224
|
+
const jsonSchema = toJsonSchema(Contact);
|
|
225
|
+
setSchemaProperty(jsonSchema, 'organization' as JsonProp, createSchemaReference(Organization.typename));
|
|
226
|
+
const { typename } = getSchemaReference(getSchemaProperty(jsonSchema, 'organization' as JsonProp) ?? {}) ?? {};
|
|
227
|
+
expect(typename).to.eq(Organization.typename);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('serialize circular schema (StoredSchema)', () => {
|
|
231
|
+
const jsonSchema = toJsonSchema(StoredSchema);
|
|
232
|
+
expect(Object.keys(jsonSchema.properties!).length).toBeGreaterThan(0);
|
|
233
|
+
|
|
234
|
+
// TODO(dmaretskyi): Currently unable to deserialize.
|
|
235
|
+
// const effectSchema = toEffectSchema(jsonSchema);
|
|
236
|
+
log('schema', { jsonSchema });
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('tuple schema with description', () => {
|
|
240
|
+
const schema = Schema.Struct({
|
|
241
|
+
args: Schema.Tuple(
|
|
242
|
+
Schema.String.annotations({ description: 'The source currency' }),
|
|
243
|
+
Schema.String.annotations({ description: 'The target currency' }),
|
|
244
|
+
),
|
|
245
|
+
});
|
|
246
|
+
const jsonSchema = toJsonSchema(schema);
|
|
247
|
+
log('schema', { jsonSchema });
|
|
248
|
+
|
|
249
|
+
(Schema.asserts(JsonSchemaType) as any)(jsonSchema);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('reference with title annotation', () => {
|
|
253
|
+
const schema = Schema.Struct({
|
|
254
|
+
contact: Ref(Testing.Contact).annotations({ title: 'Custom Title' }),
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// log.info('schema before', { ast: schema.ast });
|
|
258
|
+
|
|
259
|
+
const jsonSchema = toJsonSchema(schema);
|
|
260
|
+
// log.info('json schema', { jsonSchema });
|
|
261
|
+
|
|
262
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
263
|
+
// log.info('effect schema', { ast: effectSchema.ast });
|
|
264
|
+
|
|
265
|
+
expect(
|
|
266
|
+
effectSchema.pipe(
|
|
267
|
+
Schema.pluck('contact'),
|
|
268
|
+
Schema.typeSchema,
|
|
269
|
+
(s) => s.ast,
|
|
270
|
+
SchemaAST.getAnnotation(SchemaAST.TitleAnnotationId),
|
|
271
|
+
Option.getOrUndefined,
|
|
272
|
+
),
|
|
273
|
+
).to.eq('Custom Title');
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('relation schema', () => {
|
|
277
|
+
const schema = Testing.HasManager;
|
|
278
|
+
const jsonSchema = toJsonSchema(schema);
|
|
279
|
+
expect(jsonSchema).toEqual({
|
|
280
|
+
$id: 'dxn:type:example.com/type/HasManager',
|
|
281
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
282
|
+
entityKind: 'relation',
|
|
283
|
+
typename: 'example.com/type/HasManager',
|
|
284
|
+
version: '0.1.0',
|
|
285
|
+
relationSource: {
|
|
286
|
+
// TODO(dmaretskyi): Should those point to specific schema version?
|
|
287
|
+
$ref: 'dxn:type:example.com/type/Contact',
|
|
288
|
+
},
|
|
289
|
+
relationTarget: {
|
|
290
|
+
// TODO(dmaretskyi): Should those point to specific schema version?
|
|
291
|
+
$ref: 'dxn:type:example.com/type/Contact',
|
|
292
|
+
},
|
|
293
|
+
type: 'object',
|
|
294
|
+
properties: {
|
|
295
|
+
id: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
},
|
|
298
|
+
since: {
|
|
299
|
+
type: 'string',
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
propertyOrder: ['since', 'id'],
|
|
303
|
+
required: ['id'],
|
|
304
|
+
additionalProperties: false,
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('label prop', () => {
|
|
309
|
+
const Organization = Schema.Struct({
|
|
310
|
+
id: ObjectId,
|
|
311
|
+
name: Schema.String,
|
|
312
|
+
}).pipe(
|
|
313
|
+
EchoObject({
|
|
314
|
+
typename: 'example.com/type/Organization',
|
|
315
|
+
version: '0.1.0',
|
|
316
|
+
}),
|
|
317
|
+
LabelAnnotation.set(['name']),
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const jsonSchema = toJsonSchema(Organization);
|
|
321
|
+
expect(jsonSchema).toEqual({
|
|
322
|
+
$id: 'dxn:type:example.com/type/Organization',
|
|
323
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
324
|
+
typename: 'example.com/type/Organization',
|
|
325
|
+
version: '0.1.0',
|
|
326
|
+
entityKind: 'object',
|
|
327
|
+
type: 'object',
|
|
328
|
+
properties: {
|
|
329
|
+
id: {
|
|
330
|
+
type: 'string',
|
|
331
|
+
pattern: '^[0-7][0-9A-HJKMNP-TV-Z]{25}$',
|
|
332
|
+
description: 'A Universally Unique Lexicographically Sortable Identifier',
|
|
333
|
+
},
|
|
334
|
+
name: {
|
|
335
|
+
type: 'string',
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
annotations: {
|
|
339
|
+
labelProp: ['name'],
|
|
340
|
+
},
|
|
341
|
+
propertyOrder: ['id', 'name'],
|
|
342
|
+
required: ['id', 'name'],
|
|
343
|
+
additionalProperties: false,
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('object id with description', () => {
|
|
348
|
+
const schema = Schema.Struct({
|
|
349
|
+
id: ObjectId.annotations({ description: 'The id' }),
|
|
350
|
+
});
|
|
351
|
+
// log.info('schema', { schema: ObjectId.ast });
|
|
352
|
+
const jsonSchema = toJsonSchema(schema);
|
|
353
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
354
|
+
{
|
|
355
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
356
|
+
"additionalProperties": false,
|
|
357
|
+
"properties": {
|
|
358
|
+
"id": {
|
|
359
|
+
"description": "The id",
|
|
360
|
+
"pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$",
|
|
361
|
+
"type": "string",
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
"propertyOrder": [
|
|
365
|
+
"id",
|
|
366
|
+
],
|
|
367
|
+
"required": [
|
|
368
|
+
"id",
|
|
369
|
+
],
|
|
370
|
+
"type": "object",
|
|
371
|
+
}
|
|
372
|
+
`);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test('email schema', () => {
|
|
376
|
+
const schema = Email;
|
|
377
|
+
const jsonSchema = toJsonSchema(schema);
|
|
378
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
379
|
+
{
|
|
380
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
381
|
+
"description": "Email address",
|
|
382
|
+
"format": "email",
|
|
383
|
+
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
384
|
+
"title": "Email",
|
|
385
|
+
"type": "string",
|
|
386
|
+
}
|
|
387
|
+
`);
|
|
388
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
389
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(schema.ast));
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const expectReferenceAnnotation = (object: JsonSchemaType) => {
|
|
393
|
+
expect(object.reference).to.deep.eq({
|
|
394
|
+
schema: {
|
|
395
|
+
$ref: 'dxn:type:example.com/type/TestNested',
|
|
396
|
+
},
|
|
397
|
+
schemaVersion: '0.1.0',
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
describe('json-to-effect', () => {
|
|
403
|
+
describe('field schema', () => {
|
|
404
|
+
test('email', () => {
|
|
405
|
+
const schema = Email;
|
|
406
|
+
expect(toJsonSchema(schema)).to.deep.eq({
|
|
407
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
408
|
+
type: 'string',
|
|
409
|
+
format: 'email',
|
|
410
|
+
title: 'Email',
|
|
411
|
+
description: 'Email address',
|
|
412
|
+
// TODO(dmaretskyi): omit pattern.
|
|
413
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
for (const partial of [false, true]) {
|
|
419
|
+
test(`deserialized equals original ${partial ? 'with partial' : ''}`, () => {
|
|
420
|
+
class Organization extends TypedObject({ typename: 'example.com/type/Organization', version: '0.1.0' })({
|
|
421
|
+
field: Schema.String,
|
|
422
|
+
}) {}
|
|
423
|
+
|
|
424
|
+
class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })(
|
|
425
|
+
{
|
|
426
|
+
string: Schema.String,
|
|
427
|
+
number: Schema.Number.pipe(PropertyMeta(EXAMPLE_NAMESPACE, { is_date: true })),
|
|
428
|
+
boolean: Schema.Boolean,
|
|
429
|
+
array: Schema.Array(Schema.String),
|
|
430
|
+
twoDArray: Schema.Array(Schema.Array(Schema.String)),
|
|
431
|
+
record: Schema.Record({ key: Schema.String, value: Schema.Number }),
|
|
432
|
+
object: Schema.Struct({ id: Schema.String, field: Ref(Organization) }),
|
|
433
|
+
echoObject: Ref(Organization),
|
|
434
|
+
echoObjectArray: Schema.Array(Ref(Organization)),
|
|
435
|
+
email: Schema.String.pipe(FormatAnnotation.set(FormatEnum.Email)),
|
|
436
|
+
null: Schema.Null,
|
|
437
|
+
},
|
|
438
|
+
partial ? { partial } : {},
|
|
439
|
+
) {}
|
|
440
|
+
|
|
441
|
+
const jsonSchema = toJsonSchema(Test);
|
|
442
|
+
// log.info('schema', { jsonSchema });
|
|
443
|
+
|
|
444
|
+
const schema = toEffectSchema(jsonSchema);
|
|
445
|
+
|
|
446
|
+
expect(() => expect(schema.ast).to.deep.eq(Test.ast)).to.throw();
|
|
447
|
+
expect(() => expect(prepareAstForCompare(Test.ast)).to.deep.eq(Test.ast)).to.throw();
|
|
448
|
+
expect(() => expect(schema.ast).to.deep.eq(prepareAstForCompare(Test.ast))).to.throw();
|
|
449
|
+
// log.info('', { original: prepareAstForCompare(Schema.ast), deserialized: prepareAstForCompare(schema.ast) });
|
|
450
|
+
expect(prepareAstForCompare(schema.ast)).to.deep.eq(prepareAstForCompare(Test.ast));
|
|
451
|
+
|
|
452
|
+
// TODO(dmaretskyi): Fix.
|
|
453
|
+
// expect(
|
|
454
|
+
// SchemaAST.getPropertySignatures(schema.ast).find((prop) => prop.name === 'email')!.type.annotations[
|
|
455
|
+
// FormatAnnotationId
|
|
456
|
+
// ],
|
|
457
|
+
// ).toEqual('email');
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
test('legacy schema with dxn:type $id gets decoded', () => {
|
|
462
|
+
const jsonSchema: JsonSchemaType = {
|
|
463
|
+
$id: 'dxn:type:example.com/type/Project',
|
|
464
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
465
|
+
additionalProperties: false,
|
|
466
|
+
echo: {
|
|
467
|
+
type: {
|
|
468
|
+
schemaId: '01JERV1HQCQZDQ4NVCJ42QB38F',
|
|
469
|
+
typename: 'example.com/type/Project',
|
|
470
|
+
version: '0.1.0',
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
properties: {
|
|
474
|
+
description: {
|
|
475
|
+
type: 'string',
|
|
476
|
+
},
|
|
477
|
+
id: {
|
|
478
|
+
type: 'string',
|
|
479
|
+
},
|
|
480
|
+
name: {
|
|
481
|
+
echo: {
|
|
482
|
+
generator: 'commerce.productName',
|
|
483
|
+
},
|
|
484
|
+
type: 'string',
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
required: ['id'],
|
|
488
|
+
type: 'object',
|
|
489
|
+
version: '0.1.0',
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const schema = toEffectSchema(jsonSchema);
|
|
493
|
+
expect(getTypeAnnotation(schema)).to.deep.eq({
|
|
494
|
+
kind: EntityKind.Object,
|
|
495
|
+
typename: 'example.com/type/Project',
|
|
496
|
+
version: '0.1.0',
|
|
497
|
+
});
|
|
498
|
+
expect(getTypeIdentifierAnnotation(schema)).to.deep.eq('dxn:echo:@:01JERV1HQCQZDQ4NVCJ42QB38F');
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test('symbol annotations get compared', () => {
|
|
502
|
+
const schema1 = Schema.String.pipe(FormatAnnotation.set(FormatEnum.Email));
|
|
503
|
+
const schema2 = Schema.String.pipe(FormatAnnotation.set(FormatEnum.Currency));
|
|
504
|
+
expect(prepareAstForCompare(schema1.ast)).not.to.deep.eq(prepareAstForCompare(schema2.ast));
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
test('description gets preserved', () => {
|
|
508
|
+
const schema = Schema.Struct({
|
|
509
|
+
name: Schema.String.annotations({ description: 'Name' }),
|
|
510
|
+
});
|
|
511
|
+
const jsonSchema = toJsonSchema(schema);
|
|
512
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
513
|
+
const jsonSchema2 = toJsonSchema(effectSchema);
|
|
514
|
+
expect(jsonSchema2.properties!.name.description).to.eq('Name');
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
test('relation schema roundtrip', () => {
|
|
518
|
+
const schema = Testing.HasManager;
|
|
519
|
+
const jsonSchema = toJsonSchema(schema);
|
|
520
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
521
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(schema.ast));
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
test('generator annotation', () => {
|
|
525
|
+
const schema = Schema.Struct({
|
|
526
|
+
name: Schema.String.pipe(GeneratorAnnotation.set('commerce.productName')),
|
|
527
|
+
});
|
|
528
|
+
const jsonSchema = toJsonSchema(schema);
|
|
529
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
530
|
+
{
|
|
531
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
532
|
+
"additionalProperties": false,
|
|
533
|
+
"properties": {
|
|
534
|
+
"name": {
|
|
535
|
+
"annotations": {
|
|
536
|
+
"generator": "commerce.productName",
|
|
537
|
+
},
|
|
538
|
+
"type": "string",
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
"propertyOrder": [
|
|
542
|
+
"name",
|
|
543
|
+
],
|
|
544
|
+
"required": [
|
|
545
|
+
"name",
|
|
546
|
+
],
|
|
547
|
+
"type": "object",
|
|
548
|
+
}
|
|
549
|
+
`);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// test('generator annotation on object', () => {
|
|
553
|
+
// const schema = Schema.Struct({
|
|
554
|
+
// });
|
|
555
|
+
// const jsonSchema = toJsonSchema(schema);
|
|
556
|
+
// expect(jsonSchema).toMatchInlineSnapshot();
|
|
557
|
+
// });
|
|
558
|
+
|
|
559
|
+
test('default annotation ', () => {
|
|
560
|
+
const schema = Schema.Struct({
|
|
561
|
+
str: Schema.String.annotations({
|
|
562
|
+
default: 'foo',
|
|
563
|
+
}),
|
|
564
|
+
arr: Schema.Array(Schema.String).annotations({
|
|
565
|
+
default: [],
|
|
566
|
+
}),
|
|
567
|
+
obj: Schema.Struct({
|
|
568
|
+
foo: Schema.optional(Schema.String).annotations({
|
|
569
|
+
default: 'bar',
|
|
570
|
+
}),
|
|
571
|
+
}),
|
|
572
|
+
});
|
|
573
|
+
const jsonSchema = toJsonSchema(schema);
|
|
574
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
575
|
+
{
|
|
576
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
577
|
+
"additionalProperties": false,
|
|
578
|
+
"properties": {
|
|
579
|
+
"arr": {
|
|
580
|
+
"default": [],
|
|
581
|
+
"items": {
|
|
582
|
+
"type": "string",
|
|
583
|
+
},
|
|
584
|
+
"type": "array",
|
|
585
|
+
},
|
|
586
|
+
"obj": {
|
|
587
|
+
"additionalProperties": false,
|
|
588
|
+
"properties": {
|
|
589
|
+
"foo": {
|
|
590
|
+
"default": "bar",
|
|
591
|
+
"type": "string",
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
"propertyOrder": [
|
|
595
|
+
"foo",
|
|
596
|
+
],
|
|
597
|
+
"required": [],
|
|
598
|
+
"type": "object",
|
|
599
|
+
},
|
|
600
|
+
"str": {
|
|
601
|
+
"default": "foo",
|
|
602
|
+
"type": "string",
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
"propertyOrder": [
|
|
606
|
+
"str",
|
|
607
|
+
"arr",
|
|
608
|
+
"obj",
|
|
609
|
+
],
|
|
610
|
+
"required": [
|
|
611
|
+
"str",
|
|
612
|
+
"arr",
|
|
613
|
+
"obj",
|
|
614
|
+
],
|
|
615
|
+
"type": "object",
|
|
616
|
+
}
|
|
617
|
+
`);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
test('schema with optional referece', () => {
|
|
621
|
+
const TestSchema = Schema.Struct({
|
|
622
|
+
contact: Schema.optional(Ref(Testing.Contact)),
|
|
623
|
+
});
|
|
624
|
+
const jsonSchema = toJsonSchema(TestSchema);
|
|
625
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
626
|
+
{
|
|
627
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
628
|
+
"additionalProperties": false,
|
|
629
|
+
"properties": {
|
|
630
|
+
"contact": {
|
|
631
|
+
"$id": "/schemas/echo/ref",
|
|
632
|
+
"$ref": "/schemas/echo/ref",
|
|
633
|
+
"reference": {
|
|
634
|
+
"schema": {
|
|
635
|
+
"$ref": "dxn:type:example.com/type/Contact",
|
|
636
|
+
},
|
|
637
|
+
"schemaVersion": "0.1.0",
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
"propertyOrder": [
|
|
642
|
+
"contact",
|
|
643
|
+
],
|
|
644
|
+
"required": [],
|
|
645
|
+
"type": "object",
|
|
646
|
+
}
|
|
647
|
+
`);
|
|
648
|
+
|
|
649
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
650
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(TestSchema.ast));
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
describe('reference', () => {
|
|
655
|
+
test('reference annotation', () => {
|
|
656
|
+
const schema = Ref(Testing.Contact);
|
|
657
|
+
const jsonSchema = toJsonSchema(schema);
|
|
658
|
+
expect(jsonSchema).toEqual({
|
|
659
|
+
$id: '/schemas/echo/ref',
|
|
660
|
+
$ref: '/schemas/echo/ref',
|
|
661
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
662
|
+
reference: {
|
|
663
|
+
schema: {
|
|
664
|
+
$ref: 'dxn:type:example.com/type/Contact',
|
|
665
|
+
},
|
|
666
|
+
schemaVersion: '0.1.0',
|
|
667
|
+
},
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
test('title annotation', () => {
|
|
672
|
+
const schema = Ref(Testing.Contact).annotations({ title: 'My custom title' });
|
|
673
|
+
const jsonSchema = toJsonSchema(schema);
|
|
674
|
+
expect(jsonSchema).toEqual({
|
|
675
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
676
|
+
allOf: [
|
|
677
|
+
{
|
|
678
|
+
$id: '/schemas/echo/ref',
|
|
679
|
+
$ref: '/schemas/echo/ref',
|
|
680
|
+
reference: {
|
|
681
|
+
schema: {
|
|
682
|
+
$ref: 'dxn:type:example.com/type/Contact',
|
|
683
|
+
},
|
|
684
|
+
schemaVersion: '0.1.0',
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
],
|
|
688
|
+
title: 'My custom title',
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
test('description annotation', () => {
|
|
693
|
+
const schema = Ref(Testing.Contact).annotations({ description: 'My custom description' });
|
|
694
|
+
const jsonSchema = toJsonSchema(schema);
|
|
695
|
+
expect(jsonSchema).toEqual({
|
|
696
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
697
|
+
allOf: [
|
|
698
|
+
{
|
|
699
|
+
$id: '/schemas/echo/ref',
|
|
700
|
+
$ref: '/schemas/echo/ref',
|
|
701
|
+
reference: {
|
|
702
|
+
schema: {
|
|
703
|
+
$ref: 'dxn:type:example.com/type/Contact',
|
|
704
|
+
},
|
|
705
|
+
schemaVersion: '0.1.0',
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
],
|
|
709
|
+
description: 'My custom description',
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
713
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(schema.ast));
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
test('serialize and deserialize', () => {
|
|
717
|
+
const schema = Ref(Testing.Contact);
|
|
718
|
+
const jsonSchema = toJsonSchema(schema);
|
|
719
|
+
const deserializedSchema = toEffectSchema(jsonSchema);
|
|
720
|
+
const refAst = getReferenceAst(deserializedSchema.ast);
|
|
721
|
+
expect(refAst).toEqual({
|
|
722
|
+
typename: Testing.Contact.typename,
|
|
723
|
+
version: Testing.Contact.version,
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
});
|