@dxos/echo 0.8.4-main.67995b8 → 0.8.4-main.72ec0f3
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-BIDAASFK.mjs +3727 -0
- package/dist/lib/browser/chunk-BIDAASFK.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs +410 -0
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs +585 -0
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +17 -4
- package/dist/lib/browser/internal/index.mjs +336 -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 +13 -0
- package/dist/lib/browser/query/index.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +231 -34
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-3SVRRCUU.mjs +3727 -0
- package/dist/lib/node-esm/chunk-3SVRRCUU.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs +585 -0
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs +410 -0
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +17 -4
- package/dist/lib/node-esm/internal/index.mjs +336 -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 +13 -0
- package/dist/lib/node-esm/query/index.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +231 -34
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Obj.d.ts +127 -19
- 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/Tag.d.ts +17 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- 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 +68 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -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 +131 -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 +28 -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 +37 -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 +33 -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 +16 -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/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 +381 -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 +1 -1
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/query/{dsl.d.ts → query.d.ts} +52 -22
- 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/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 +170 -55
- package/dist/types/src/testing/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +40 -28
- package/src/Obj.ts +298 -29
- package/src/Ref.ts +1 -2
- package/src/Relation.ts +25 -13
- package/src/Tag.ts +39 -0
- package/src/Type.ts +32 -31
- package/src/errors.ts +18 -0
- package/src/index.ts +5 -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 +226 -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 +849 -0
- package/src/internal/json/json-schema.ts +519 -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 +153 -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 +248 -0
- package/src/internal/object/expando.ts +21 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +19 -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 +61 -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 +88 -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 +92 -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 +144 -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/query.test.ts +401 -0
- package/src/query/{dsl.ts → query.ts} +188 -45
- 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 +40 -23
- 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
- package/src/query/dsl.test.ts +0 -323
package/src/Type.ts
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import { type Simplify } from 'effect/Schema';
|
|
5
|
+
import type * as EffectSchema from 'effect/Schema';
|
|
7
6
|
|
|
8
7
|
import { type EncodedReference } from '@dxos/echo-protocol';
|
|
9
|
-
import * as EchoSchema from '@dxos/echo-schema';
|
|
10
|
-
import { type ToMutable } from '@dxos/echo-schema';
|
|
11
8
|
import { invariant } from '@dxos/invariant';
|
|
12
9
|
import type * as Keys from '@dxos/keys';
|
|
13
10
|
|
|
11
|
+
import { type ToMutable } from './internal';
|
|
12
|
+
import * as EchoSchema from './internal';
|
|
14
13
|
import type * as RelationModule from './Relation';
|
|
15
14
|
|
|
16
15
|
//
|
|
@@ -39,7 +38,7 @@ export type Schema = EchoSchema.EchoSchema;
|
|
|
39
38
|
/**
|
|
40
39
|
* Returns all properties of an object or relation except for the id and kind.
|
|
41
40
|
*/
|
|
42
|
-
export type Properties<T> = Omit<T, 'id' | KindId | RelationModule.Source | RelationModule.Target>;
|
|
41
|
+
export type Properties<T = any> = Omit<T, 'id' | KindId | RelationModule.Source | RelationModule.Target>;
|
|
43
42
|
|
|
44
43
|
//
|
|
45
44
|
// Obj
|
|
@@ -55,45 +54,47 @@ interface ObjJsonProps {
|
|
|
55
54
|
* This typedef avoids `TS4023` error (name from external module cannot be used named).
|
|
56
55
|
* See Effect's note on interface types.
|
|
57
56
|
*/
|
|
58
|
-
export interface obj<Self extends
|
|
57
|
+
export interface obj<Self extends EffectSchema.Schema.Any>
|
|
59
58
|
extends EchoSchema.TypeMeta,
|
|
60
|
-
|
|
59
|
+
EffectSchema.AnnotableClass<
|
|
61
60
|
obj<Self>,
|
|
62
|
-
OfKind<EchoSchema.EntityKind.Object> & ToMutable<
|
|
63
|
-
Simplify<ObjJsonProps & ToMutable<
|
|
64
|
-
|
|
61
|
+
OfKind<EchoSchema.EntityKind.Object> & ToMutable<EffectSchema.Schema.Type<Self>>,
|
|
62
|
+
EffectSchema.Simplify<ObjJsonProps & ToMutable<EffectSchema.Schema.Encoded<Self>>>,
|
|
63
|
+
EffectSchema.Schema.Context<Self>
|
|
65
64
|
> {}
|
|
66
65
|
|
|
67
66
|
/**
|
|
68
67
|
* Object schema.
|
|
69
68
|
*/
|
|
70
69
|
export const Obj: {
|
|
71
|
-
(opts: EchoSchema.TypeMeta): <Self extends
|
|
70
|
+
(opts: EchoSchema.TypeMeta): <Self extends EffectSchema.Schema.Any>(self: Self) => obj<Self>;
|
|
72
71
|
} = EchoSchema.EchoObject as any;
|
|
73
72
|
|
|
74
73
|
/**
|
|
75
74
|
* Object schema type definitions.
|
|
76
75
|
*/
|
|
77
|
-
export namespace Obj {
|
|
76
|
+
export declare namespace Obj {
|
|
78
77
|
/**
|
|
79
78
|
* Type that represents an arbitrary schema type of an object.
|
|
80
79
|
* NOTE: This is not an instance type.
|
|
81
80
|
*/
|
|
82
81
|
// TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.
|
|
83
|
-
|
|
82
|
+
// TODO(burdon): This erases the ECHO type info (e.g., id, typename).
|
|
83
|
+
export type Any = EffectSchema.Schema.AnyNoContext;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
//
|
|
87
87
|
// Expando
|
|
88
88
|
//
|
|
89
89
|
|
|
90
|
+
// TODO(burdon): We're using Expando in many places as a base type.
|
|
90
91
|
export interface Expando extends OfKind<EchoSchema.EntityKind.Object> {
|
|
91
92
|
[key: string]: any;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
type ExpandoEncoded = Simplify<ObjJsonProps & { [key: string]: any }>;
|
|
95
|
+
type ExpandoEncoded = EffectSchema.Simplify<ObjJsonProps & { [key: string]: any }>;
|
|
95
96
|
|
|
96
|
-
export const Expando:
|
|
97
|
+
export const Expando: EffectSchema.Schema<Expando, ExpandoEncoded, never> = EchoSchema.Expando as any;
|
|
97
98
|
|
|
98
99
|
//
|
|
99
100
|
// Relation
|
|
@@ -112,17 +113,17 @@ interface RelationJsonProps {
|
|
|
112
113
|
* See Effect's note on interface types.
|
|
113
114
|
*/
|
|
114
115
|
export interface relation<
|
|
115
|
-
Self extends
|
|
116
|
-
SourceSchema extends
|
|
117
|
-
TargetSchema extends
|
|
116
|
+
Self extends EffectSchema.Schema.Any,
|
|
117
|
+
SourceSchema extends EffectSchema.Schema.Any,
|
|
118
|
+
TargetSchema extends EffectSchema.Schema.Any,
|
|
118
119
|
> extends EchoSchema.TypeMeta,
|
|
119
|
-
|
|
120
|
+
EffectSchema.AnnotableClass<
|
|
120
121
|
relation<Self, SourceSchema, TargetSchema>,
|
|
121
122
|
OfKind<EchoSchema.EntityKind.Relation> &
|
|
122
|
-
Relation.Endpoints<
|
|
123
|
-
ToMutable<
|
|
124
|
-
Simplify<RelationJsonProps & ToMutable<
|
|
125
|
-
|
|
123
|
+
Relation.Endpoints<EffectSchema.Schema.Type<SourceSchema>, EffectSchema.Schema.Type<TargetSchema>> &
|
|
124
|
+
ToMutable<EffectSchema.Schema.Type<Self>>,
|
|
125
|
+
EffectSchema.Simplify<RelationJsonProps & ToMutable<EffectSchema.Schema.Encoded<Self>>>,
|
|
126
|
+
EffectSchema.Schema.Context<Self>
|
|
126
127
|
> {}
|
|
127
128
|
|
|
128
129
|
/**
|
|
@@ -130,9 +131,9 @@ export interface relation<
|
|
|
130
131
|
*/
|
|
131
132
|
// TODO(dmaretskyi): I have to redefine the type here so that the definition uses symbols from @dxos/echo/Relation.
|
|
132
133
|
export const Relation: {
|
|
133
|
-
<Source extends
|
|
134
|
+
<Source extends EffectSchema.Schema.AnyNoContext, Target extends EffectSchema.Schema.AnyNoContext>(
|
|
134
135
|
opts: EchoSchema.EchoRelationOptions<Source, Target>,
|
|
135
|
-
): <Self extends
|
|
136
|
+
): <Self extends EffectSchema.Schema.Any>(self: Self) => relation<Self, Source, Target>;
|
|
136
137
|
} = EchoSchema.EchoRelation as any;
|
|
137
138
|
|
|
138
139
|
/**
|
|
@@ -144,7 +145,7 @@ export namespace Relation {
|
|
|
144
145
|
* NOTE: This is not an instance type.
|
|
145
146
|
*/
|
|
146
147
|
// TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.
|
|
147
|
-
export type Any =
|
|
148
|
+
export type Any = EffectSchema.Schema.AnyNoContext;
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* Get relation source type.
|
|
@@ -172,15 +173,15 @@ export namespace Relation {
|
|
|
172
173
|
* This typedef avoids `TS4023` error (name from external module cannot be used named).
|
|
173
174
|
* See Effect's note on interface types.
|
|
174
175
|
*/
|
|
175
|
-
export interface ref<TargetSchema extends
|
|
176
|
-
extends EchoSchema.Ref$<
|
|
176
|
+
export interface ref<TargetSchema extends EffectSchema.Schema.Any>
|
|
177
|
+
extends EchoSchema.Ref$<EffectSchema.Schema.Type<TargetSchema>> {}
|
|
177
178
|
|
|
178
179
|
/**
|
|
179
180
|
* Ref schema.
|
|
180
181
|
*/
|
|
181
182
|
export const Ref: <S extends Obj.Any>(schema: S) => ref<S> = EchoSchema.Ref;
|
|
182
183
|
|
|
183
|
-
export interface Ref<T> extends
|
|
184
|
+
export interface Ref<T> extends EffectSchema.SchemaClass<EchoSchema.Ref<T>, EncodedReference> {}
|
|
184
185
|
|
|
185
186
|
// TODO(buurdon): Move to Ref?
|
|
186
187
|
export namespace Ref {
|
|
@@ -188,7 +189,7 @@ export namespace Ref {
|
|
|
188
189
|
* Type that represents an arbitrary schema type of a reference.
|
|
189
190
|
* NOTE: This is not an instance type.
|
|
190
191
|
*/
|
|
191
|
-
export type Any =
|
|
192
|
+
export type Any = EffectSchema.Schema<EchoSchema.Ref<any>, EncodedReference>;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
/**
|
|
@@ -241,4 +242,4 @@ export const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {
|
|
|
241
242
|
// TODO(dmaretskyi): Remove re-exports.
|
|
242
243
|
export { SpaceId, ObjectId, DXN } from '@dxos/keys';
|
|
243
244
|
|
|
244
|
-
export { Format, JsonSchemaType as JsonSchema, toEffectSchema, toJsonSchema } from '
|
|
245
|
+
export { Format, JsonSchemaType as JsonSchema, toEffectSchema, toJsonSchema } from './internal';
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { BaseError, type BaseErrorOptions } from '@dxos/errors';
|
|
6
|
+
import { type DXN } from '@dxos/keys';
|
|
7
|
+
|
|
8
|
+
export class SchemaNotFoundError extends BaseError.extend('SCHEMA_NOT_FOUND', 'Schema not found') {
|
|
9
|
+
constructor(schema: string, options?: BaseErrorOptions) {
|
|
10
|
+
super({ context: { schema }, ...options });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ObjectNotFoundError extends BaseError.extend('OBJECT_NOT_FOUND', 'Object not found') {
|
|
15
|
+
constructor(dxn: DXN, options?: BaseErrorOptions) {
|
|
16
|
+
super({ context: { dxn }, ...options });
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
export * from './errors';
|
|
6
|
+
export * from './query';
|
|
7
|
+
|
|
5
8
|
export * as Key from './Key';
|
|
6
9
|
export * as Obj from './Obj';
|
|
7
10
|
export * as Ref from './Ref';
|
|
8
11
|
export * as Relation from './Relation';
|
|
12
|
+
export * as Tag from './Tag';
|
|
9
13
|
export * as Type from './Type';
|
|
10
14
|
|
|
15
|
+
export { QueryAST } from '@dxos/echo-protocol';
|
|
11
16
|
export { DXN } from '@dxos/keys';
|
|
12
|
-
export { Filter, Query } from './query';
|
|
13
17
|
export { type Live } from '@dxos/live-object';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Option from 'effect/Option';
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
export interface AnnotationHelper<T> {
|
|
10
|
+
get: (schema: Schema.Schema.Any) => Option.Option<T>;
|
|
11
|
+
set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {
|
|
15
|
+
return {
|
|
16
|
+
get: (schema) => SchemaAST.getAnnotation(schema.ast, id),
|
|
17
|
+
set:
|
|
18
|
+
(value) =>
|
|
19
|
+
<S extends Schema.Schema.Any>(schema: S) =>
|
|
20
|
+
schema.annotations({ [id]: value }) as S,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { EchoObject, getLabel } from '../object';
|
|
9
|
+
|
|
10
|
+
import { LabelAnnotation, SchemaVersion, Typename } from './annotations';
|
|
11
|
+
|
|
12
|
+
// TODO(dmaretskyi): Use one of the testing schemas.
|
|
13
|
+
const TestObject = Schema.Struct({
|
|
14
|
+
name: Schema.optional(Schema.String),
|
|
15
|
+
fallbackName: Schema.optional(Schema.String),
|
|
16
|
+
other: Schema.String,
|
|
17
|
+
}).pipe(LabelAnnotation.set(['name', 'fallbackName']));
|
|
18
|
+
|
|
19
|
+
const a: Schema.Struct<typeof TestObject.fields> = TestObject;
|
|
20
|
+
console.log(a);
|
|
21
|
+
|
|
22
|
+
type TestObject = Schema.Schema.Type<typeof TestObject>;
|
|
23
|
+
|
|
24
|
+
const TestEchoSchema = TestObject.pipe(
|
|
25
|
+
EchoObject({
|
|
26
|
+
typename: 'dxos.org/type/Test',
|
|
27
|
+
version: '0.1.0',
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
type TestEchoSchema = Schema.Schema.Type<typeof TestEchoSchema>;
|
|
31
|
+
|
|
32
|
+
describe('annotations', () => {
|
|
33
|
+
describe('Typename', () => {
|
|
34
|
+
test('should validate typename', ({ expect }) => {
|
|
35
|
+
// Valid.
|
|
36
|
+
expect(Typename.make('dxos.org/type/foo')).to.exist;
|
|
37
|
+
expect(Typename.make('dxos.org/type/foo-bar')).to.exist;
|
|
38
|
+
expect(Typename.make('dxos.org/type/foo_bar')).to.exist;
|
|
39
|
+
|
|
40
|
+
// Invalid.
|
|
41
|
+
expect(() => Typename.make('dxn:dxos.org')).to.throw();
|
|
42
|
+
expect(() => Typename.make('2dxos.org')).to.throw();
|
|
43
|
+
expect(() => Typename.make('dxos org')).to.throw();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('should validate version', ({ expect }) => {
|
|
47
|
+
// Valid.
|
|
48
|
+
expect(SchemaVersion.make('0.1.0')).to.exist;
|
|
49
|
+
|
|
50
|
+
// Invalid.
|
|
51
|
+
expect(() => SchemaVersion.make('0.1.x')).to.throw();
|
|
52
|
+
expect(() => SchemaVersion.make('0.1.0-alpha')).to.throw();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('getLabel', () => {
|
|
57
|
+
test('should return first available label value', ({ expect }) => {
|
|
58
|
+
const obj: TestObject = {
|
|
59
|
+
name: 'Primary Name',
|
|
60
|
+
fallbackName: 'Fallback Name',
|
|
61
|
+
other: 'Other',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(getLabel(TestObject, obj)).toEqual('Primary Name');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('should fallback to second path if first is undefined', ({ expect }) => {
|
|
68
|
+
const obj: TestObject = {
|
|
69
|
+
name: undefined,
|
|
70
|
+
fallbackName: 'Fallback Name',
|
|
71
|
+
other: 'Other',
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
expect(getLabel(TestObject, obj)).toEqual('Fallback Name');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('should return undefined if no label paths resolve', ({ expect }) => {
|
|
78
|
+
const obj: TestObject = {
|
|
79
|
+
name: undefined,
|
|
80
|
+
fallbackName: undefined,
|
|
81
|
+
other: 'Other',
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
expect(getLabel(TestObject, obj)).toBeUndefined();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should return label from echo object', ({ expect }) => {
|
|
88
|
+
const obj: TestEchoSchema = {
|
|
89
|
+
id: 'test',
|
|
90
|
+
name: 'Primary Name',
|
|
91
|
+
fallbackName: 'Fallback Name',
|
|
92
|
+
other: 'Other',
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
expect(getLabel(TestEchoSchema, obj)).toEqual('Primary Name');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
9
|
+
|
|
10
|
+
import { assertArgument } from '@dxos/invariant';
|
|
11
|
+
import { DXN } from '@dxos/keys';
|
|
12
|
+
import { type Primitive } from '@dxos/util';
|
|
13
|
+
|
|
14
|
+
import { createAnnotationHelper } from './annotation-helper';
|
|
15
|
+
import { EntityKind } from './entity-kind';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* If property is optional returns the nested property, otherwise returns the property.
|
|
19
|
+
*/
|
|
20
|
+
// TODO(wittjosiah): Is there a way to do this as a generic?
|
|
21
|
+
export const unwrapOptional = (property: SchemaAST.PropertySignature) => {
|
|
22
|
+
if (!property.isOptional || !SchemaAST.isUnion(property.type)) {
|
|
23
|
+
return property;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return property.type.types[0];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* ECHO identifier (for a stored schema).
|
|
31
|
+
* Must be a `dxn:echo:` URI.
|
|
32
|
+
*/
|
|
33
|
+
export const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');
|
|
34
|
+
|
|
35
|
+
export const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>
|
|
36
|
+
Function.flow(
|
|
37
|
+
SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),
|
|
38
|
+
Option.getOrElse(() => undefined),
|
|
39
|
+
)(schema.ast);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ECHO type.
|
|
43
|
+
*/
|
|
44
|
+
export const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');
|
|
45
|
+
|
|
46
|
+
// TODO(burdon): Create echo-schema Format types.
|
|
47
|
+
// TODO(burdon): Reconcile with "short" DXN.
|
|
48
|
+
export const Typename = Schema.String.pipe(Schema.pattern(/^[a-zA-Z]\w+\.[a-zA-Z]\w{1,}\/[\w/_-]+$/));
|
|
49
|
+
export const SchemaVersion = Schema.String.pipe(Schema.pattern(/^\d+.\d+.\d+$/));
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Payload stored under {@link TypeAnnotationId}.
|
|
53
|
+
*/
|
|
54
|
+
// TODO(dmaretskyi): Rename getTypeAnnotation to represent commonality between objects and relations (e.g. `entity`).
|
|
55
|
+
export const TypeAnnotation = Schema.Struct({
|
|
56
|
+
kind: Schema.Enums(EntityKind),
|
|
57
|
+
typename: Typename,
|
|
58
|
+
version: SchemaVersion,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* If this is a relation, the schema of the source object.
|
|
62
|
+
* Must be present if entity kind is {@link EntityKind.Relation}.
|
|
63
|
+
*/
|
|
64
|
+
sourceSchema: Schema.optional(DXN.Schema),
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* If this is a relation, the schema of the target object.
|
|
68
|
+
* Must be present if entity kind is {@link EntityKind.Relation}.
|
|
69
|
+
*/
|
|
70
|
+
targetSchema: Schema.optional(DXN.Schema),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}
|
|
74
|
+
|
|
75
|
+
export type TypeMeta = Pick<TypeAnnotation, 'typename' | 'version'>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @returns {@link TypeAnnotation} from a schema.
|
|
79
|
+
* Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.
|
|
80
|
+
*/
|
|
81
|
+
export const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {
|
|
82
|
+
assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');
|
|
83
|
+
return Function.flow(
|
|
84
|
+
SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),
|
|
85
|
+
Option.getOrElse(() => undefined),
|
|
86
|
+
)(schema.ast);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @returns {@link EntityKind} from a schema.
|
|
91
|
+
*/
|
|
92
|
+
export const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated Use {@link Type.getTypename} instead.
|
|
96
|
+
* @returns Schema typename (without dxn: prefix or version number).
|
|
97
|
+
*/
|
|
98
|
+
export const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Use {@link Type.getVersion} instead.
|
|
102
|
+
* @returns Schema version in semver format.
|
|
103
|
+
*/
|
|
104
|
+
export const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* PropertyMeta (metadata for dynamic schema properties).
|
|
108
|
+
* For user-defined annotations.
|
|
109
|
+
*/
|
|
110
|
+
export const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');
|
|
111
|
+
|
|
112
|
+
export type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];
|
|
113
|
+
|
|
114
|
+
export type PropertyMetaAnnotation = {
|
|
115
|
+
[name: string]: PropertyMetaValue;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const PropertyMeta = (name: string, value: PropertyMetaValue) => {
|
|
119
|
+
return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {
|
|
120
|
+
const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;
|
|
121
|
+
return self.annotations({
|
|
122
|
+
[PropertyMetaAnnotationId]: {
|
|
123
|
+
...existingMeta,
|
|
124
|
+
[name]: value,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>
|
|
131
|
+
Function.pipe(
|
|
132
|
+
SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),
|
|
133
|
+
Option.map((meta) => meta[name] as T),
|
|
134
|
+
Option.getOrElse(() => undefined),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Schema reference.
|
|
139
|
+
*/
|
|
140
|
+
export const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');
|
|
141
|
+
|
|
142
|
+
export type ReferenceAnnotationValue = TypeAnnotation;
|
|
143
|
+
|
|
144
|
+
export const getReferenceAnnotation = (schema: Schema.Schema.AnyNoContext) =>
|
|
145
|
+
Function.pipe(
|
|
146
|
+
SchemaAST.getAnnotation<ReferenceAnnotationValue>(ReferenceAnnotationId)(schema.ast),
|
|
147
|
+
Option.getOrElse(() => undefined),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* SchemaMeta.
|
|
152
|
+
*/
|
|
153
|
+
export const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');
|
|
154
|
+
|
|
155
|
+
export type SchemaMeta = TypeMeta & { id: string };
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Identifies a schema as a view.
|
|
159
|
+
*/
|
|
160
|
+
export const ViewAnnotationId = Symbol.for('@dxos/schema/annotation/View');
|
|
161
|
+
export const ViewAnnotation = createAnnotationHelper<boolean>(ViewAnnotationId);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Identifies label property or JSON path expression.
|
|
165
|
+
* Either a string or an array of strings representing field accessors each matched in priority order.
|
|
166
|
+
*/
|
|
167
|
+
export const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');
|
|
168
|
+
export const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Identifies description property or JSON path expression.
|
|
172
|
+
* A string representing field accessor.
|
|
173
|
+
*/
|
|
174
|
+
export const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');
|
|
175
|
+
export const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Identifies if a property should be included in a form or not.
|
|
179
|
+
* By default, all properties are included in forms, so this is opt-out.
|
|
180
|
+
*/
|
|
181
|
+
export const FormAnnotationId = Symbol.for('@dxos/schema/annotation/Form');
|
|
182
|
+
export const FormAnnotation = createAnnotationHelper<boolean>(FormAnnotationId);
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Default field to be used on referenced schema to lookup the value.
|
|
186
|
+
*/
|
|
187
|
+
export const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Generate test data.
|
|
191
|
+
*/
|
|
192
|
+
export const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');
|
|
193
|
+
|
|
194
|
+
export type GeneratorAnnotationValue =
|
|
195
|
+
| string
|
|
196
|
+
| {
|
|
197
|
+
generator: string;
|
|
198
|
+
args?: any[];
|
|
199
|
+
probability?: number;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @returns DXN of the schema.
|
|
206
|
+
*
|
|
207
|
+
* For non-stored schema returns `dxn:type:`.
|
|
208
|
+
* For stored schema returns `dxn:echo:`.
|
|
209
|
+
* @deprecated Use `Type.getDXN`.
|
|
210
|
+
*/
|
|
211
|
+
export const getSchemaDXN = (schema: Schema.Schema.All): DXN | undefined => {
|
|
212
|
+
assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');
|
|
213
|
+
|
|
214
|
+
const id = getTypeIdentifierAnnotation(schema);
|
|
215
|
+
if (id) {
|
|
216
|
+
return DXN.parse(id);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// TODO(dmaretskyi): Add support for dynamic schema.
|
|
220
|
+
const objectAnnotation = getTypeAnnotation(schema);
|
|
221
|
+
if (!objectAnnotation) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return DXN.fromTypenameAndVersion(objectAnnotation.typename, objectAnnotation.version);
|
|
226
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Kinds of entities stored in ECHO: objects and relations.
|
|
9
|
+
*/
|
|
10
|
+
export enum EntityKind {
|
|
11
|
+
Object = 'object',
|
|
12
|
+
Relation = 'relation',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const EntityKindSchema = Schema.Enums(EntityKind);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { PropertyMeta } from './annotations';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const FIELD_PATH_ANNOTATION = 'path';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sets the path for the field.
|
|
14
|
+
* @param path Data source path in the json path format. This is the field path in the source object.
|
|
15
|
+
*/
|
|
16
|
+
// TODO(burdon): Field, vs. path vs. property.
|
|
17
|
+
export const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { log } from '@dxos/log';
|
|
9
|
+
|
|
10
|
+
import { toJsonSchema } from '../json';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
DateOnly,
|
|
14
|
+
DateTime,
|
|
15
|
+
type SimpleDate,
|
|
16
|
+
type SimpleDateTime,
|
|
17
|
+
type SimpleTime,
|
|
18
|
+
TimeOnly,
|
|
19
|
+
toSimpleDate,
|
|
20
|
+
toSimpleTime,
|
|
21
|
+
} from './date';
|
|
22
|
+
|
|
23
|
+
describe.skip('date', () => {
|
|
24
|
+
test('basic', () => {
|
|
25
|
+
const date = new Date('2024-12-31T23:59:59Z');
|
|
26
|
+
expect(toSimpleDate(date)).to.deep.eq({ year: 2024, month: 12, day: 31 });
|
|
27
|
+
expect(toSimpleTime(date)).to.deep.eq({ hours: 23, minutes: 59, seconds: 59 });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Date', ({ expect }) => {
|
|
31
|
+
const jsonSchema = toJsonSchema(DateOnly);
|
|
32
|
+
log('schema', { jsonSchema });
|
|
33
|
+
const v1: SimpleDate = { year: 1999, month: 12, day: 31 };
|
|
34
|
+
const str = Schema.encodeUnknownSync(DateOnly)(v1);
|
|
35
|
+
const v2 = Schema.decodeUnknownSync(DateOnly)(str);
|
|
36
|
+
expect(v1).to.deep.eq(v2);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Time', ({ expect }) => {
|
|
40
|
+
const jsonSchema = toJsonSchema(TimeOnly);
|
|
41
|
+
log('schema', { jsonSchema });
|
|
42
|
+
const v1: SimpleTime = { hours: 23, minutes: 59, seconds: 59 };
|
|
43
|
+
const str = Schema.encodeUnknownSync(TimeOnly)(v1);
|
|
44
|
+
const v2 = Schema.decodeUnknownSync(TimeOnly)(str);
|
|
45
|
+
expect(v1).to.deep.eq(v2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('DateTime', ({ expect }) => {
|
|
49
|
+
const jsonSchema = toJsonSchema(DateTime);
|
|
50
|
+
log('schema', { jsonSchema });
|
|
51
|
+
const v1: SimpleDateTime = { year: 1999, month: 12, day: 31, hours: 23, minutes: 59, seconds: 59 };
|
|
52
|
+
const str = Schema.encodeUnknownSync(DateTime)(v1);
|
|
53
|
+
const v2 = Schema.decodeUnknownSync(DateTime)(str);
|
|
54
|
+
expect(v1).to.deep.eq(v2);
|
|
55
|
+
});
|
|
56
|
+
});
|