@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
|
@@ -1,16 +1,112 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
Type_exports
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-L4PBAJDP.mjs";
|
|
5
|
+
import "../chunk-AXWVDOP7.mjs";
|
|
6
|
+
import {
|
|
7
|
+
EchoObject,
|
|
8
|
+
EchoRelation,
|
|
9
|
+
EchoSchema,
|
|
10
|
+
Expando,
|
|
11
|
+
Ref,
|
|
12
|
+
StoredSchema,
|
|
13
|
+
TypedObject,
|
|
14
|
+
getSchemaTypename,
|
|
15
|
+
live,
|
|
16
|
+
toJsonSchema
|
|
17
|
+
} from "../chunk-YTNLFBIK.mjs";
|
|
5
18
|
|
|
6
|
-
// src/testing/types.ts
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
// src/internal/testing/types.ts
|
|
20
|
+
import * as Schema from "effect/Schema";
|
|
21
|
+
function _define_property(obj, key, value) {
|
|
22
|
+
if (key in obj) {
|
|
23
|
+
Object.defineProperty(obj, key, {
|
|
24
|
+
value,
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
obj[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
(function(Testing3) {
|
|
35
|
+
const Circle = Schema.Struct({
|
|
36
|
+
type: Schema.Literal("circle"),
|
|
37
|
+
radius: Schema.Number
|
|
38
|
+
});
|
|
39
|
+
const Square = Schema.Struct({
|
|
40
|
+
type: Schema.Literal("square"),
|
|
41
|
+
side: Schema.Number
|
|
42
|
+
});
|
|
43
|
+
const Shape = Schema.Union(Circle, Square);
|
|
44
|
+
const TestNestedSchema = Schema.mutable(Schema.Struct({
|
|
45
|
+
field: Schema.String
|
|
46
|
+
}));
|
|
47
|
+
Testing3.TestNestedType = TestNestedSchema.pipe(EchoObject({
|
|
48
|
+
typename: "example.com/type/TestNested",
|
|
49
|
+
version: "0.1.0"
|
|
50
|
+
}));
|
|
51
|
+
class EmptySchemaType extends TypedObject({
|
|
52
|
+
typename: "example.com/type/Empty",
|
|
53
|
+
version: "0.1.0"
|
|
54
|
+
})({}) {
|
|
55
|
+
}
|
|
56
|
+
Testing3.EmptySchemaType = EmptySchemaType;
|
|
57
|
+
const fields = {
|
|
58
|
+
string: Schema.String,
|
|
59
|
+
number: Schema.Number,
|
|
60
|
+
nullableShapeArray: Schema.mutable(Schema.Array(Schema.Union(Shape, Schema.Null))),
|
|
61
|
+
boolean: Schema.Boolean,
|
|
62
|
+
null: Schema.Null,
|
|
63
|
+
undefined: Schema.Undefined,
|
|
64
|
+
stringArray: Schema.mutable(Schema.Array(Schema.String)),
|
|
65
|
+
twoDimNumberArray: Schema.mutable(Schema.Array(Schema.mutable(Schema.Array(Schema.Number)))),
|
|
66
|
+
object: TestNestedSchema,
|
|
67
|
+
objectArray: Schema.mutable(Schema.Array(TestNestedSchema)),
|
|
68
|
+
nested: Schema.optional(Ref(Testing3.TestNestedType)),
|
|
69
|
+
other: Schema.Any
|
|
70
|
+
};
|
|
71
|
+
Testing3.TestSchema = Schema.mutable(Schema.partial(Schema.Struct(fields)));
|
|
72
|
+
class TestSchemaType extends TypedObject({
|
|
73
|
+
typename: "example.com/type/Test",
|
|
74
|
+
version: "0.1.0"
|
|
75
|
+
})(fields, {
|
|
76
|
+
partial: true
|
|
77
|
+
}) {
|
|
78
|
+
}
|
|
79
|
+
Testing3.TestSchemaType = TestSchemaType;
|
|
80
|
+
Testing3.TestType = Testing3.TestSchema.pipe(EchoObject({
|
|
81
|
+
typename: "example.com/type/Test",
|
|
82
|
+
version: "0.1.0"
|
|
83
|
+
}));
|
|
84
|
+
class TestClass {
|
|
85
|
+
toJSON() {
|
|
86
|
+
return {
|
|
87
|
+
field: this.field
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
constructor() {
|
|
91
|
+
_define_property(this, "field", "value");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
Testing3.TestClass = TestClass;
|
|
95
|
+
Testing3.TestSchemaWithClass = Schema.mutable(Schema.extend(Testing3.TestSchema, Schema.mutable(Schema.Struct({
|
|
96
|
+
classInstance: Schema.optional(Schema.instanceOf(TestClass))
|
|
97
|
+
}))));
|
|
98
|
+
class Contact extends TypedObject({
|
|
99
|
+
typename: "example.com/type/Contact",
|
|
100
|
+
version: "0.1.0"
|
|
101
|
+
})({
|
|
10
102
|
name: Schema.String,
|
|
11
103
|
username: Schema.String,
|
|
12
104
|
email: Schema.String,
|
|
13
|
-
|
|
105
|
+
phoneNumbers: Schema.optional(Schema.Array(Schema.Struct({
|
|
106
|
+
label: Schema.String,
|
|
107
|
+
number: Schema.String
|
|
108
|
+
}))),
|
|
109
|
+
tasks: Schema.suspend(() => Schema.mutable(Schema.Array(Ref(Task)))),
|
|
14
110
|
address: Schema.Struct({
|
|
15
111
|
city: Schema.optional(Schema.String),
|
|
16
112
|
state: Schema.optional(Schema.String),
|
|
@@ -20,51 +116,183 @@ import { Schema } from "effect";
|
|
|
20
116
|
lng: Schema.optional(Schema.Number)
|
|
21
117
|
})
|
|
22
118
|
})
|
|
23
|
-
}
|
|
24
|
-
|
|
119
|
+
}, {
|
|
120
|
+
partial: true
|
|
121
|
+
}) {
|
|
122
|
+
}
|
|
123
|
+
Testing3.Contact = Contact;
|
|
124
|
+
class Task extends TypedObject({
|
|
125
|
+
typename: "example.com/type/Task",
|
|
25
126
|
version: "0.1.0"
|
|
26
|
-
})
|
|
27
|
-
Testing2.Contact = _Contact;
|
|
28
|
-
const _Task = Schema.Struct({
|
|
127
|
+
})({
|
|
29
128
|
title: Schema.optional(Schema.String),
|
|
30
129
|
completed: Schema.optional(Schema.Boolean),
|
|
31
|
-
assignee: Schema.optional(
|
|
32
|
-
previous: Schema.optional(Schema.suspend(() =>
|
|
33
|
-
subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend(() =>
|
|
130
|
+
assignee: Schema.optional(Ref(Contact)),
|
|
131
|
+
previous: Schema.optional(Schema.suspend(() => Ref(Task))),
|
|
132
|
+
subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend(() => Ref(Task))))),
|
|
34
133
|
description: Schema.optional(Schema.String)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
134
|
+
}, {
|
|
135
|
+
partial: true
|
|
136
|
+
}) {
|
|
137
|
+
}
|
|
138
|
+
Testing3.Task = Task;
|
|
40
139
|
(function(RecordType) {
|
|
41
140
|
RecordType[RecordType["UNDEFINED"] = 0] = "UNDEFINED";
|
|
42
141
|
RecordType[RecordType["PERSONAL"] = 1] = "PERSONAL";
|
|
43
142
|
RecordType[RecordType["WORK"] = 2] = "WORK";
|
|
44
|
-
})(
|
|
45
|
-
|
|
46
|
-
|
|
143
|
+
})(Testing3.RecordType || (Testing3.RecordType = {}));
|
|
144
|
+
class Container extends TypedObject({
|
|
145
|
+
typename: "example.com/type/Container",
|
|
146
|
+
version: "0.1.0"
|
|
147
|
+
})({
|
|
148
|
+
objects: Schema.mutable(Schema.Array(Ref(Expando))),
|
|
47
149
|
records: Schema.mutable(Schema.Array(Schema.partial(Schema.Struct({
|
|
48
150
|
title: Schema.String,
|
|
49
151
|
description: Schema.String,
|
|
50
|
-
contacts: Schema.mutable(Schema.Array(
|
|
51
|
-
type: Schema.Enums(
|
|
152
|
+
contacts: Schema.mutable(Schema.Array(Ref(Contact))),
|
|
153
|
+
type: Schema.Enums(Testing3.RecordType)
|
|
154
|
+
}))))
|
|
155
|
+
}, {
|
|
156
|
+
partial: true
|
|
157
|
+
}) {
|
|
158
|
+
}
|
|
159
|
+
Testing3.Container = Container;
|
|
160
|
+
Testing3.HasManager = Schema.Struct({
|
|
161
|
+
since: Schema.optional(Schema.String)
|
|
162
|
+
}).pipe(EchoRelation({
|
|
163
|
+
typename: "example.com/type/HasManager",
|
|
164
|
+
version: "0.1.0",
|
|
165
|
+
source: Contact,
|
|
166
|
+
target: Contact
|
|
167
|
+
}));
|
|
168
|
+
})(Testing || (Testing = {}));
|
|
169
|
+
var Testing;
|
|
170
|
+
|
|
171
|
+
// src/internal/testing/utils.ts
|
|
172
|
+
import { effect } from "@preact/signals-core";
|
|
173
|
+
import { registerSignalsRuntime } from "@dxos/echo-signals";
|
|
174
|
+
import { deepMapValues } from "@dxos/util";
|
|
175
|
+
registerSignalsRuntime();
|
|
176
|
+
var updateCounter = (touch) => {
|
|
177
|
+
let updateCount = -1;
|
|
178
|
+
const unsubscribe = effect(() => {
|
|
179
|
+
touch();
|
|
180
|
+
updateCount++;
|
|
181
|
+
});
|
|
182
|
+
return {
|
|
183
|
+
// https://github.com/tc39/proposal-explicit-resource-management
|
|
184
|
+
[Symbol.dispose]: unsubscribe,
|
|
185
|
+
get count() {
|
|
186
|
+
return updateCount;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
var prepareAstForCompare = (obj) => deepMapValues(obj, (value, recurse, key) => {
|
|
191
|
+
if (typeof value === "function") {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
if (value instanceof RegExp) {
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
if (typeof value === "object") {
|
|
198
|
+
const clone = {
|
|
199
|
+
...value
|
|
200
|
+
};
|
|
201
|
+
for (const sym of Object.getOwnPropertySymbols(clone)) {
|
|
202
|
+
clone[sym.toString()] = clone[sym];
|
|
203
|
+
delete clone[sym];
|
|
204
|
+
}
|
|
205
|
+
return recurse(clone);
|
|
206
|
+
}
|
|
207
|
+
return recurse(value);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// src/testing/types.ts
|
|
211
|
+
import * as Schema2 from "effect/Schema";
|
|
212
|
+
(function(Testing3) {
|
|
213
|
+
const _Contact = Schema2.Struct({
|
|
214
|
+
name: Schema2.String,
|
|
215
|
+
username: Schema2.String,
|
|
216
|
+
email: Schema2.String,
|
|
217
|
+
tasks: Schema2.mutable(Schema2.Array(Schema2.suspend(() => Type_exports.Ref(Testing3.Task)))),
|
|
218
|
+
address: Schema2.Struct({
|
|
219
|
+
city: Schema2.optional(Schema2.String),
|
|
220
|
+
state: Schema2.optional(Schema2.String),
|
|
221
|
+
zip: Schema2.optional(Schema2.String),
|
|
222
|
+
coordinates: Schema2.Struct({
|
|
223
|
+
lat: Schema2.optional(Schema2.Number),
|
|
224
|
+
lng: Schema2.optional(Schema2.Number)
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
}).pipe(Schema2.partial, Type_exports.Obj({
|
|
228
|
+
typename: "example.com/type/Contact",
|
|
229
|
+
version: "0.1.0"
|
|
230
|
+
}));
|
|
231
|
+
Testing3.Contact = _Contact;
|
|
232
|
+
const _Task = Schema2.Struct({
|
|
233
|
+
title: Schema2.optional(Schema2.String),
|
|
234
|
+
completed: Schema2.optional(Schema2.Boolean),
|
|
235
|
+
assignee: Schema2.optional(Type_exports.Ref(Testing3.Contact)),
|
|
236
|
+
previous: Schema2.optional(Schema2.suspend(() => Type_exports.Ref(Testing3.Task))),
|
|
237
|
+
subTasks: Schema2.optional(Schema2.mutable(Schema2.Array(Schema2.suspend(() => Type_exports.Ref(Testing3.Task))))),
|
|
238
|
+
description: Schema2.optional(Schema2.String)
|
|
239
|
+
}).pipe(Schema2.partial, Type_exports.Obj({
|
|
240
|
+
typename: "example.com/type/Task",
|
|
241
|
+
version: "0.1.0"
|
|
242
|
+
}));
|
|
243
|
+
Testing3.Task = _Task;
|
|
244
|
+
(function(RecordType) {
|
|
245
|
+
RecordType[RecordType["UNDEFINED"] = 0] = "UNDEFINED";
|
|
246
|
+
RecordType[RecordType["PERSONAL"] = 1] = "PERSONAL";
|
|
247
|
+
RecordType[RecordType["WORK"] = 2] = "WORK";
|
|
248
|
+
})(Testing3.RecordType || (Testing3.RecordType = {}));
|
|
249
|
+
Testing3.Container = Schema2.Struct({
|
|
250
|
+
objects: Schema2.mutable(Schema2.Array(Type_exports.Ref(Type_exports.Expando))),
|
|
251
|
+
records: Schema2.mutable(Schema2.Array(Schema2.partial(Schema2.Struct({
|
|
252
|
+
title: Schema2.String,
|
|
253
|
+
description: Schema2.String,
|
|
254
|
+
contacts: Schema2.mutable(Schema2.Array(Type_exports.Ref(Testing3.Contact))),
|
|
255
|
+
type: Schema2.Enums(Testing3.RecordType)
|
|
52
256
|
}))))
|
|
53
|
-
}).pipe(
|
|
257
|
+
}).pipe(Schema2.partial, Type_exports.Obj({
|
|
54
258
|
typename: "example.com/type/Container",
|
|
55
259
|
version: "0.1.0"
|
|
56
260
|
}));
|
|
57
|
-
|
|
58
|
-
since:
|
|
261
|
+
Testing3.WorksFor = Schema2.Struct({
|
|
262
|
+
since: Schema2.optional(Schema2.String)
|
|
59
263
|
}).pipe(Type_exports.Relation({
|
|
60
264
|
typename: "example.com/type/WorksFor",
|
|
61
265
|
version: "0.1.0",
|
|
62
|
-
source:
|
|
63
|
-
target:
|
|
266
|
+
source: Testing3.Contact,
|
|
267
|
+
target: Testing3.Contact
|
|
64
268
|
}));
|
|
65
|
-
})(
|
|
66
|
-
var
|
|
269
|
+
})(Testing2 || (Testing2 = {}));
|
|
270
|
+
var Testing2;
|
|
271
|
+
|
|
272
|
+
// src/testing/echo-schema.ts
|
|
273
|
+
import { effect as effect2 } from "@preact/signals-core";
|
|
274
|
+
import { registerSignalsRuntime as registerSignalsRuntime2 } from "@dxos/echo-signals";
|
|
275
|
+
import { assertArgument } from "@dxos/invariant";
|
|
276
|
+
registerSignalsRuntime2();
|
|
277
|
+
var createEchoSchema = (schema) => {
|
|
278
|
+
const typename = getSchemaTypename(schema);
|
|
279
|
+
assertArgument(typename, "typename", "Schema does not have a typename.");
|
|
280
|
+
const echoSchema = new EchoSchema(live(StoredSchema, {
|
|
281
|
+
typename,
|
|
282
|
+
version: "0.1.0",
|
|
283
|
+
jsonSchema: toJsonSchema(schema)
|
|
284
|
+
}));
|
|
285
|
+
effect2(() => {
|
|
286
|
+
const _ = echoSchema.jsonSchema;
|
|
287
|
+
echoSchema._invalidate();
|
|
288
|
+
});
|
|
289
|
+
return echoSchema;
|
|
290
|
+
};
|
|
67
291
|
export {
|
|
68
|
-
Testing
|
|
292
|
+
Testing2 as Testing,
|
|
293
|
+
Testing as TestingDeprecated,
|
|
294
|
+
createEchoSchema,
|
|
295
|
+
prepareAstForCompare,
|
|
296
|
+
updateCounter
|
|
69
297
|
};
|
|
70
298
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/testing/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { Type } from '..';\n\n// TODO(burdon): These are non-canonical test types, so we really shouldn't export and use in other classes (compare with @dxos/sdk/testing).\nexport namespace Testing {\n const _Contact = Schema.Struct({\n name: Schema.String,\n username: Schema.String,\n email: Schema.String,\n tasks: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task)))),\n address: Schema.Struct({\n city: Schema.optional(Schema.String),\n state: Schema.optional(Schema.String),\n zip: Schema.optional(Schema.String),\n coordinates: Schema.Struct({\n lat: Schema.optional(Schema.Number),\n lng: Schema.optional(Schema.Number),\n }),\n }),\n }).pipe(\n Schema.partial,\n Type.Obj({\n typename: 'example.com/type/Contact',\n version: '0.1.0',\n }),\n );\n export interface Contact extends Schema.Schema.Type<typeof _Contact> {}\n export const Contact: Schema.Schema<Contact, Schema.Schema.Encoded<typeof _Contact>, never> = _Contact;\n\n const _Task = Schema.Struct({\n title: Schema.optional(Schema.String),\n completed: Schema.optional(Schema.Boolean),\n assignee: Schema.optional(Type.Ref(Contact)),\n previous: Schema.optional(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))),\n subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))))),\n description: Schema.optional(Schema.String),\n }).pipe(\n Schema.partial,\n Type.Obj({\n typename: 'example.com/type/Task',\n version: '0.1.0',\n }),\n );\n export interface Task extends Schema.Schema.Type<typeof _Task> {}\n export const Task: Schema.Schema<Task, Schema.Schema.Encoded<typeof _Task>, never> = _Task;\n\n export enum RecordType {\n UNDEFINED = 0,\n PERSONAL = 1,\n WORK = 2,\n }\n\n export const Container = Schema.Struct({\n objects: Schema.mutable(Schema.Array(Type.Ref(Type.Expando))),\n records: Schema.mutable(\n Schema.Array(\n Schema.partial(\n Schema.Struct({\n title: Schema.String,\n description: Schema.String,\n contacts: Schema.mutable(Schema.Array(Type.Ref(Contact))),\n type: Schema.Enums(RecordType),\n }),\n ),\n ),\n ),\n }).pipe(\n Schema.partial,\n Type.Obj({\n typename: 'example.com/type/Container',\n version: '0.1.0',\n }),\n );\n\n export const WorksFor = Schema.Struct({\n since: Schema.optional(Schema.String),\n }).pipe(\n Type.Relation({\n typename: 'example.com/type/WorksFor',\n version: '0.1.0',\n source: Contact,\n target: Contact,\n }),\n );\n export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Schema", "Testing", "
|
|
3
|
+
"sources": ["../../../../src/internal/testing/types.ts", "../../../../src/internal/testing/utils.ts", "../../../../src/testing/types.ts", "../../../../src/testing/echo-schema.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { EchoObject, EchoRelation, Expando, TypedObject } from '../object';\nimport { Ref, type Ref$ } from '../ref';\n\n// TODO(burdon): These are non-canonical test types, so we really shouldn't export and use in other classes (compare with @dxos/sdk/testing).\nexport namespace Testing {\n //\n // Primitives\n //\n\n const Circle = Schema.Struct({ type: Schema.Literal('circle'), radius: Schema.Number });\n const Square = Schema.Struct({ type: Schema.Literal('square'), side: Schema.Number });\n const Shape = Schema.Union(Circle, Square);\n\n //\n // Simple types\n //\n\n const TestNestedSchema = Schema.mutable(Schema.Struct({ field: Schema.String }));\n export type TestNestedSchema = Schema.Schema.Type<typeof TestNestedSchema>;\n export const TestNestedType = TestNestedSchema.pipe(\n EchoObject({ typename: 'example.com/type/TestNested', version: '0.1.0' }),\n );\n\n //\n // Complex types\n // TODO(burdon): Change to Type.Obj.\n //\n\n export class EmptySchemaType extends TypedObject({\n typename: 'example.com/type/Empty',\n version: '0.1.0',\n })({}) {}\n\n const fields = {\n string: Schema.String,\n number: Schema.Number,\n nullableShapeArray: Schema.mutable(Schema.Array(Schema.Union(Shape, Schema.Null))),\n boolean: Schema.Boolean,\n null: Schema.Null,\n undefined: Schema.Undefined,\n stringArray: Schema.mutable(Schema.Array(Schema.String)),\n twoDimNumberArray: Schema.mutable(Schema.Array(Schema.mutable(Schema.Array(Schema.Number)))),\n object: TestNestedSchema,\n objectArray: Schema.mutable(Schema.Array(TestNestedSchema)),\n nested: Schema.optional(Ref(TestNestedType)),\n other: Schema.Any,\n };\n\n export const TestSchema = Schema.mutable(Schema.partial(Schema.Struct(fields)));\n export type TestSchema = Schema.Schema.Type<typeof TestSchema>;\n\n export class TestSchemaType extends TypedObject({\n typename: 'example.com/type/Test',\n version: '0.1.0',\n })(fields, { partial: true }) {} // TODO(burdon): Partial?\n\n // TODO(burdon): Why do we use need this rather then TestSchemaType?\n export const TestType = TestSchema.pipe(\n EchoObject({\n typename: 'example.com/type/Test',\n version: '0.1.0',\n }),\n );\n\n export class TestClass {\n field = 'value';\n toJSON() {\n return { field: this.field };\n }\n }\n\n // TODO(dmaretskyi): Another top-level Schema.mutable call as a workaround for the regression in the last minor.\n export const TestSchemaWithClass = Schema.mutable(\n Schema.extend(\n TestSchema,\n Schema.mutable(\n Schema.Struct({\n classInstance: Schema.optional(Schema.instanceOf(TestClass)),\n }),\n ),\n ),\n );\n\n export type TestSchemaWithClass = Schema.Schema.Type<typeof TestSchemaWithClass>;\n\n export class Contact extends TypedObject({\n typename: 'example.com/type/Contact',\n version: '0.1.0',\n })(\n {\n name: Schema.String,\n username: Schema.String,\n email: Schema.String,\n phoneNumbers: Schema.optional(Schema.Array(Schema.Struct({ label: Schema.String, number: Schema.String }))),\n tasks: Schema.suspend((): Schema.mutable<Schema.Array$<Ref$<Task>>> => Schema.mutable(Schema.Array(Ref(Task)))),\n address: Schema.Struct({\n city: Schema.optional(Schema.String),\n state: Schema.optional(Schema.String),\n zip: Schema.optional(Schema.String),\n coordinates: Schema.Struct({\n lat: Schema.optional(Schema.Number),\n lng: Schema.optional(Schema.Number),\n }),\n }),\n },\n { partial: true },\n ) {}\n\n export class Task extends TypedObject({\n typename: 'example.com/type/Task',\n version: '0.1.0',\n })(\n {\n title: Schema.optional(Schema.String),\n completed: Schema.optional(Schema.Boolean),\n assignee: Schema.optional(Ref(Contact)),\n previous: Schema.optional(Schema.suspend((): Ref$<Task> => Ref(Task))),\n subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Ref$<Task> => Ref(Task))))),\n description: Schema.optional(Schema.String),\n },\n { partial: true },\n ) {}\n\n // TOOD(burdon): Ref$ breaks if using new syntax (since ID is not declared).\n\n // export const Task = Schema.Struct({\n // title: Schema.String,\n // completed: Schema.Boolean,\n // assignee: Schema.optional(Ref(Schema.suspend((): Ref$<Contact> => Ref(Contact)))),\n // previous: Schema.optional(Ref(Schema.suspend((): Ref$<Task> => Ref(Task)))),\n // subTasks: Schema.optional(Schema.Array(Ref(Schema.suspend((): Ref$<Task> => Ref(Task))))),\n // description: Schema.optional(Schema.String),\n // }).pipe(\n // EchoObject({\n // typename: 'example.com/type/Task',\n // version: '0.1.0',\n // }),\n // );\n\n // export type Task = Schema.Schema.Type<typeof Task>;\n\n // export const Contact = Schema.Struct({\n // name: Schema.String,\n // username: Schema.String,\n // email: Schema.String,\n // // TOOD(burdon): Should model via relations?\n // // tasks: Schema.mutable(Schema.Array(Ref(Task))),\n // address: Schema.Struct({\n // city: Schema.optional(Schema.String),\n // state: Schema.optional(Schema.String),\n // zip: Schema.optional(Schema.String),\n // coordinates: Schema.Struct({\n // lat: Schema.optional(Schema.Number),\n // lng: Schema.optional(Schema.Number),\n // }),\n // }),\n // }).pipe(\n // EchoObject({\n // typename: 'example.com/type/Contact',\n // version: '0.1.0',\n // }),\n // );\n\n // export type Contact = Schema.Schema.Type<typeof Contact>;\n\n export enum RecordType {\n UNDEFINED = 0,\n PERSONAL = 1,\n WORK = 2,\n }\n\n export class Container extends TypedObject({\n typename: 'example.com/type/Container',\n version: '0.1.0',\n })(\n {\n objects: Schema.mutable(Schema.Array(Ref(Expando))),\n records: Schema.mutable(\n Schema.Array(\n Schema.partial(\n Schema.Struct({\n title: Schema.String,\n description: Schema.String,\n contacts: Schema.mutable(Schema.Array(Ref(Contact))),\n type: Schema.Enums(RecordType),\n }),\n ),\n ),\n ),\n },\n { partial: true },\n ) {}\n\n export const HasManager = Schema.Struct({\n since: Schema.optional(Schema.String),\n }).pipe(\n EchoRelation({\n typename: 'example.com/type/HasManager',\n version: '0.1.0',\n source: Contact,\n target: Contact,\n }),\n );\n export interface HasManager extends Schema.Schema.Type<typeof HasManager> {}\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { effect } from '@preact/signals-core';\nimport type * as SchemaAST from 'effect/SchemaAST';\n\nimport { registerSignalsRuntime } from '@dxos/echo-signals';\nimport { deepMapValues } from '@dxos/util';\n\nregisterSignalsRuntime();\n\n// TODO(burdon): Move to util.\nexport const updateCounter = (touch: () => void) => {\n let updateCount = -1;\n const unsubscribe = effect(() => {\n touch();\n updateCount++;\n });\n\n return {\n // https://github.com/tc39/proposal-explicit-resource-management\n [Symbol.dispose]: unsubscribe,\n get count() {\n return updateCount;\n },\n };\n};\n\n/**\n * Converts AST to a format that can be compared with test matchers.\n */\nexport const prepareAstForCompare = (obj: SchemaAST.AST): any =>\n deepMapValues(obj, (value: any, recurse, key) => {\n if (typeof value === 'function') {\n return null;\n }\n\n if (value instanceof RegExp) {\n return value;\n }\n\n // Convert symbols to strings.\n if (typeof value === 'object') {\n const clone = { ...value };\n for (const sym of Object.getOwnPropertySymbols(clone as any)) {\n clone[sym.toString()] = clone[sym];\n delete clone[sym];\n }\n return recurse(clone);\n }\n\n return recurse(value);\n });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Type } from '..';\n\n// TODO(burdon): These are non-canonical test types, so we really shouldn't export and use in other classes (compare with @dxos/sdk/testing).\nexport namespace Testing {\n const _Contact = Schema.Struct({\n name: Schema.String,\n username: Schema.String,\n email: Schema.String,\n tasks: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task)))),\n address: Schema.Struct({\n city: Schema.optional(Schema.String),\n state: Schema.optional(Schema.String),\n zip: Schema.optional(Schema.String),\n coordinates: Schema.Struct({\n lat: Schema.optional(Schema.Number),\n lng: Schema.optional(Schema.Number),\n }),\n }),\n }).pipe(\n Schema.partial,\n Type.Obj({\n typename: 'example.com/type/Contact',\n version: '0.1.0',\n }),\n );\n export interface Contact extends Schema.Schema.Type<typeof _Contact> {}\n export const Contact: Schema.Schema<Contact, Schema.Schema.Encoded<typeof _Contact>, never> = _Contact;\n\n const _Task = Schema.Struct({\n title: Schema.optional(Schema.String),\n completed: Schema.optional(Schema.Boolean),\n assignee: Schema.optional(Type.Ref(Contact)),\n previous: Schema.optional(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))),\n subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))))),\n description: Schema.optional(Schema.String),\n }).pipe(\n Schema.partial,\n Type.Obj({\n typename: 'example.com/type/Task',\n version: '0.1.0',\n }),\n );\n export interface Task extends Schema.Schema.Type<typeof _Task> {}\n export const Task: Schema.Schema<Task, Schema.Schema.Encoded<typeof _Task>, never> = _Task;\n\n export enum RecordType {\n UNDEFINED = 0,\n PERSONAL = 1,\n WORK = 2,\n }\n\n export const Container = Schema.Struct({\n objects: Schema.mutable(Schema.Array(Type.Ref(Type.Expando))),\n records: Schema.mutable(\n Schema.Array(\n Schema.partial(\n Schema.Struct({\n title: Schema.String,\n description: Schema.String,\n contacts: Schema.mutable(Schema.Array(Type.Ref(Contact))),\n type: Schema.Enums(RecordType),\n }),\n ),\n ),\n ),\n }).pipe(\n Schema.partial,\n Type.Obj({\n typename: 'example.com/type/Container',\n version: '0.1.0',\n }),\n );\n\n export const WorksFor = Schema.Struct({\n since: Schema.optional(Schema.String),\n }).pipe(\n Type.Relation({\n typename: 'example.com/type/WorksFor',\n version: '0.1.0',\n source: Contact,\n target: Contact,\n }),\n );\n export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { effect } from '@preact/signals-core';\nimport type * as Schema from 'effect/Schema';\n\nimport { registerSignalsRuntime } from '@dxos/echo-signals';\nimport { assertArgument } from '@dxos/invariant';\n\nimport { EchoSchema, StoredSchema, getSchemaTypename, live, toJsonSchema } from '../internal';\n\n// NOTE: Registration is done here is this is the module that calls out to `effect`.\nregisterSignalsRuntime();\n\n/**\n * Create a reactive mutable schema that updates when the JSON schema is updated.\n */\n// TODO(dmaretskyi): Should be replaced by registration of typed object.\nexport const createEchoSchema = (schema: Schema.Schema.AnyNoContext): EchoSchema => {\n const typename = getSchemaTypename(schema);\n assertArgument(typename, 'typename', 'Schema does not have a typename.');\n\n const echoSchema = new EchoSchema(\n live(StoredSchema, {\n typename,\n version: '0.1.0',\n jsonSchema: toJsonSchema(schema),\n }),\n );\n\n // TODO(burdon): Unsubscribe is never called.\n effect(() => {\n const _ = echoSchema.jsonSchema;\n echoSchema._invalidate();\n });\n\n return echoSchema;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAIA,YAAYA,YAAY;A;;;;;;;;;;;;;UAMPC,UAAAA;AAKf,QAAMC,SAAgBC,cAAO;IAAEC,MAAaC,eAAQ,QAAA;IAAWC,QAAeC;EAAO,CAAA;AACrF,QAAMC,SAAgBL,cAAO;IAAEC,MAAaC,eAAQ,QAAA;IAAWI,MAAaF;EAAO,CAAA;AACnF,QAAMG,QAAeC,aAAMT,QAAQM,MAAAA;AAMnC,QAAMI,mBAA0BC,eAAeV,cAAO;IAAEW,OAAcC;EAAO,CAAA,CAAA;WAEhEC,iBAAiBJ,iBAAiBK,KAC7CC,WAAW;IAAEC,UAAU;IAA+BC,SAAS;EAAQ,CAAA,CAAA;EAQlE,MAAMC,wBAAwBC,YAAY;IAC/CH,UAAU;IACVC,SAAS;EACX,CAAA,EAAG,CAAC,CAAA,EAAA;EAAI;WAHKC,kBAAAA;AAKb,QAAME,SAAS;IACbC,QAAeT;IACfU,QAAelB;IACfmB,oBAA2Bb,eAAec,aAAahB,aAAMD,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iBAAgBZ,cAAM;EACtC,CAAA,EAAGmB,KACDZ,aAAKoC,SAAS;IACZrB,UAAU;IACVC,SAAS;IACTqB,QAAMhD,SAAE4B;IACRqB,QAAMjD,SAAE4B;EACV,CAAA,CAAA;AAGJ,GAjFiB5B,aAAAA,WAAAA,CAAAA,EAAAA;;;;ACLjB,SAASkD,UAAAA,eAAc;AAGvB,SAASC,0BAAAA,+BAA8B;AACvC,SAASC,sBAAsB;AAK/BC,wBAAAA;AAMO,IAAMC,mBAAmB,CAACC,WAAAA;AAC/B,QAAMC,WAAWC,kBAAkBF,MAAAA;AACnCG,iBAAeF,UAAU,YAAY,kCAAA;AAErC,QAAMG,aAAa,IAAIC,WACrBC,KAAKC,cAAc;IACjBN;IACAO,SAAS;IACTC,YAAYC,aAAaV,MAAAA;EAC3B,CAAA,CAAA;AAIFW,EAAAA,QAAO,MAAA;AACL,UAAMC,IAAIR,WAAWK;AACrBL,eAAWS,YAAW;EACxB,CAAA;AAEA,SAAOT;AACT;",
|
|
6
|
+
"names": ["Schema", "Testing", "Circle", "Struct", "type", "Literal", "radius", "Number", "Square", "side", "Shape", "Union", "TestNestedSchema", "mutable", "field", "String", "TestNestedType", "pipe", "EchoObject", "typename", "version", "EmptySchemaType", "TypedObject", "fields", "string", "number", "nullableShapeArray", "Array", "Null", "boolean", "Boolean", "null", "undefined", "Undefined", "stringArray", "twoDimNumberArray", "object", "objectArray", "nested", "optional", "Ref", "other", "Any", "TestSchema", "partial", "TestSchemaType", "TestType", "TestClass", "toJSON", "TestSchemaWithClass", "extend", "classInstance", "instanceOf", "Contact", "name", "username", "email", "phoneNumbers", "label", "tasks", "suspend", "Task", "address", "city", "state", "zip", "coordinates", "lat", "lng", "title", "completed", "assignee", "previous", "subTasks", "description", "RecordType", "Container", "objects", "Expando", "records", "contacts", "Enums", "HasManager", "since", "EchoRelation", "source", "target", "effect", "registerSignalsRuntime", "deepMapValues", "registerSignalsRuntime", "updateCounter", "touch", "updateCount", "unsubscribe", "effect", "Symbol", "dispose", "count", "prepareAstForCompare", "obj", "deepMapValues", "value", "recurse", "key", "RegExp", "clone", "sym", "Object", "getOwnPropertySymbols", "toString", "Schema", "Testing", "_Contact", "Struct", "name", "String", "username", "email", "tasks", "mutable", "Array", "suspend", "Type", "Ref", "Task", "address", "city", "optional", "state", "zip", "coordinates", "lat", "Number", "lng", "pipe", "partial", "Obj", "typename", "version", "Contact", "_Task", "title", "completed", "Boolean", "assignee", "previous", "subTasks", "description", "RecordType", "Container", "objects", "Expando", "records", "contacts", "type", "Enums", "WorksFor", "since", "Relation", "source", "target", "effect", "registerSignalsRuntime", "assertArgument", "registerSignalsRuntime", "createEchoSchema", "schema", "typename", "getSchemaTypename", "assertArgument", "echoSchema", "EchoSchema", "live", "StoredSchema", "version", "jsonSchema", "toJsonSchema", "effect", "_", "_invalidate"]
|
|
7
7
|
}
|
package/dist/types/src/Obj.d.ts
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as EchoSchema from '@dxos/echo-schema';
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
3
2
|
import { type DXN } from '@dxos/keys';
|
|
4
|
-
import
|
|
3
|
+
import * as LiveObject from '@dxos/live-object';
|
|
4
|
+
import * as EchoSchema from './internal';
|
|
5
5
|
import type * as Ref from './Ref';
|
|
6
6
|
import type * as Relation from './Relation';
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import * as Type from './Type';
|
|
8
|
+
/**
|
|
9
|
+
* NOTE: Don't export: Obj.Any and Obj.Obj form the public API.
|
|
10
|
+
*/
|
|
11
|
+
interface BaseObj extends EchoSchema.HasId, Type.OfKind<EchoSchema.EntityKind.Object> {
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Object type with specific properties.
|
|
13
15
|
*/
|
|
14
|
-
export type Obj<Props> =
|
|
16
|
+
export type Obj<Props> = BaseObj & Props;
|
|
15
17
|
/**
|
|
16
18
|
* Base type for all ECHO objects.
|
|
17
19
|
*/
|
|
18
|
-
export interface Any extends
|
|
20
|
+
export interface Any extends BaseObj {
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
export declare const Any: Type.obj<Schema.Struct<{}>>;
|
|
23
|
+
type Props<T = any> = {
|
|
21
24
|
id?: EchoSchema.ObjectId;
|
|
22
25
|
} & Type.Properties<T>;
|
|
23
|
-
export type MakeProps<
|
|
26
|
+
export type MakeProps<T extends Type.Obj.Any> = NoInfer<Props<Schema.Schema.Type<T>>> & {
|
|
27
|
+
[Meta]?: Partial<EchoSchema.ObjectMeta>;
|
|
28
|
+
};
|
|
29
|
+
export declare const Meta: unique symbol;
|
|
24
30
|
/**
|
|
25
31
|
* Creates new object.
|
|
32
|
+
* @param schema - Object schema.
|
|
33
|
+
* @param props - Object properties.
|
|
34
|
+
* @param meta - Object metadata (deprecated) -- pass with Obj.Meta.
|
|
35
|
+
*
|
|
36
|
+
* Meta can be passed as a symbol in `props`.
|
|
37
|
+
*
|
|
38
|
+
* Example:
|
|
39
|
+
* ```ts
|
|
40
|
+
* const obj = Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' });
|
|
41
|
+
* ```
|
|
26
42
|
*/
|
|
27
|
-
export declare const make: <S extends Type.Obj.Any>(schema: S, props: MakeProps<S>, meta?: EchoSchema.ObjectMeta) => LiveObject.Live<Schema.Schema.Type<S>>;
|
|
43
|
+
export declare const make: <S extends Type.Obj.Any>(schema: S, props: MakeProps<S>, meta?: Partial<EchoSchema.ObjectMeta>) => LiveObject.Live<Schema.Schema.Type<S>>;
|
|
28
44
|
export declare const isObject: (obj: unknown) => obj is Any;
|
|
29
45
|
/**
|
|
30
46
|
* Test if object or relation is an instance of a schema.
|
|
@@ -34,7 +50,7 @@ export declare const isObject: (obj: unknown) => obj is Any;
|
|
|
34
50
|
* const johnIsPerson = Obj.instanceOf(Person)(john);
|
|
35
51
|
*
|
|
36
52
|
* const isPerson = Obj.instanceOf(Person);
|
|
37
|
-
* if(isPerson(john)) {
|
|
53
|
+
* if (isPerson(john)) {
|
|
38
54
|
* // john is Person
|
|
39
55
|
* }
|
|
40
56
|
* ```
|
|
@@ -44,7 +60,7 @@ export declare const instanceOf: {
|
|
|
44
60
|
<S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
|
|
45
61
|
};
|
|
46
62
|
export declare const getSchema: (obj: unknown | undefined) => Schema.Schema.AnyNoContext | undefined;
|
|
47
|
-
export declare const getDXN: (obj: Any) => DXN;
|
|
63
|
+
export declare const getDXN: (obj: Any | Relation.Any) => DXN;
|
|
48
64
|
/**
|
|
49
65
|
* @returns The DXN of the object's type.
|
|
50
66
|
* @example dxn:example.com/type/Contact:1.0.0
|
|
@@ -54,10 +70,28 @@ export declare const getTypeDXN: (obj: EchoSchema.BaseObject) => DXN | undefined
|
|
|
54
70
|
* @returns The typename of the object's type.
|
|
55
71
|
* @example `example.com/type/Contact`
|
|
56
72
|
*/
|
|
57
|
-
export declare const getTypename: (obj: Any) => string | undefined;
|
|
58
|
-
export declare const getMeta: (obj: Any) => EchoSchema.ObjectMeta;
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
export declare const getTypename: (obj: Any | Relation.Any) => string | undefined;
|
|
74
|
+
export declare const getMeta: (obj: Any | Relation.Any) => EchoSchema.ObjectMeta;
|
|
75
|
+
/**
|
|
76
|
+
* @returns Foreign keys for the object from the specified source.
|
|
77
|
+
*/
|
|
78
|
+
export declare const getKeys: {
|
|
79
|
+
(obj: Any | Relation.Any, source: string): EchoSchema.ForeignKey[];
|
|
80
|
+
(source: string): (obj: Any | Relation.Any) => EchoSchema.ForeignKey[];
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Delete all keys from the object for the specified source.
|
|
84
|
+
* @param obj
|
|
85
|
+
* @param source
|
|
86
|
+
*/
|
|
87
|
+
export declare const deleteKeys: (obj: Any | Relation.Any, source: string) => void;
|
|
88
|
+
export declare const isDeleted: (obj: Any | Relation.Any) => boolean;
|
|
89
|
+
export declare const getLabel: (obj: Any | Relation.Any) => string | undefined;
|
|
90
|
+
export declare const setLabel: (obj: Any | Relation.Any, label: string) => void;
|
|
91
|
+
export type Comparator = (a: Any, b: Any) => number;
|
|
92
|
+
export declare const sortByLabel: Comparator;
|
|
93
|
+
export declare const sortByTypename: Comparator;
|
|
94
|
+
export declare const sort: (...comparators: Comparator[]) => Comparator;
|
|
61
95
|
/**
|
|
62
96
|
* JSON representation of an object.
|
|
63
97
|
*/
|
|
@@ -73,9 +107,69 @@ export declare const toJSON: (obj: Any | Relation.Any) => JSON;
|
|
|
73
107
|
* References and schemas will be resolvable if the `refResolver` is provided.
|
|
74
108
|
*
|
|
75
109
|
* The function need to be async to support resolving the schema as well as the relation endpoints.
|
|
110
|
+
*
|
|
111
|
+
* @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.
|
|
112
|
+
* @param options.dxn - Override object DXN. Changes the result of `Obj.getDXN`.
|
|
76
113
|
*/
|
|
77
114
|
export declare const fromJSON: (json: unknown, options?: {
|
|
78
115
|
refResolver?: Ref.Resolver;
|
|
116
|
+
dxn?: DXN;
|
|
79
117
|
}) => Promise<Any>;
|
|
118
|
+
/**
|
|
119
|
+
* Returns an immutable snapshot of an object.
|
|
120
|
+
*/
|
|
121
|
+
export declare const getSnapshot: <T extends Any>(obj: Obj<T>) => T;
|
|
122
|
+
export type CloneOptions = {
|
|
123
|
+
/**
|
|
124
|
+
* Retain the original object's ID.
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
retainId?: boolean;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Clones an object or relation.
|
|
131
|
+
* This does not clone referenced objects, only the properties in the object.
|
|
132
|
+
* @returns A new object with the same schema and properties.
|
|
133
|
+
*/
|
|
134
|
+
export declare const clone: <T extends Any | Relation.Any>(obj: T, opts?: CloneOptions) => T;
|
|
135
|
+
export declare const VersionTypeId: symbol;
|
|
136
|
+
export type VersionType = typeof VersionTypeId;
|
|
137
|
+
/**
|
|
138
|
+
* Represent object version.
|
|
139
|
+
* May be backed by Automerge.
|
|
140
|
+
* Objects with no history are not versioned.
|
|
141
|
+
*/
|
|
142
|
+
export interface Version {
|
|
143
|
+
/**
|
|
144
|
+
* Whether the object is versioned.
|
|
145
|
+
*/
|
|
146
|
+
versioned: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Automerge heads.
|
|
149
|
+
*/
|
|
150
|
+
automergeHeads?: string[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Checks that `obj` is a version object.
|
|
154
|
+
*/
|
|
155
|
+
export declare const isVersion: (obj: unknown) => obj is Version;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the version of the object.
|
|
158
|
+
*/
|
|
159
|
+
export declare const version: (obj: Any | Relation.Any) => Version;
|
|
160
|
+
/**
|
|
161
|
+
* Checks that `version` is a valid version object.
|
|
162
|
+
*/
|
|
163
|
+
export declare const versionValid: (version: Version) => boolean;
|
|
164
|
+
export type VersionCompareResult = 'unversioned' | 'equal' | 'different';
|
|
165
|
+
/**
|
|
166
|
+
* Compares two versions.
|
|
167
|
+
* @param version1
|
|
168
|
+
* @param version2
|
|
169
|
+
* @returns 'unversioned' if either object is unversioned, 'equal' if the versions are equal, 'different' if the versions are different.
|
|
170
|
+
*/
|
|
171
|
+
export declare const compareVersions: (version1: Version, version2: Version) => VersionCompareResult;
|
|
172
|
+
export declare const encodeVersion: (version: Version) => string;
|
|
173
|
+
export declare const decodeVersion: (version: string) => Version;
|
|
80
174
|
export {};
|
|
81
175
|
//# sourceMappingURL=Obj.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Obj.d.ts","sourceRoot":"","sources":["../../../src/Obj.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Obj.d.ts","sourceRoot":"","sources":["../../../src/Obj.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,MAAM,eAAe,CA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":"AAIA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/Ref.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,KAAK,GAAG,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACvC,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE1C,eAAO,MAAM,KAAK;;;;EAAsB,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC;AAE9C,eAAO,MAAM,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,GAA0B,CAAC;AAE5E,eAAO,MAAM,IAAI,+DAAsB,CAAC;AAGxC,eAAO,MAAM,OAAO,wDAAyB,CAAC"}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as EchoSchema from '@dxos/echo-schema';
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
3
2
|
import { DXN } from '@dxos/keys';
|
|
4
3
|
import { type Live } from '@dxos/live-object';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import * as EchoSchema from './internal';
|
|
5
|
+
import * as Obj from './Obj';
|
|
6
|
+
import * as Type from './Type';
|
|
7
|
+
/**
|
|
8
|
+
* NOTE: Don't export: Relation.Relation and Relation.Any form the public API.
|
|
9
|
+
*/
|
|
10
|
+
interface BaseRelation<Source, Target> extends EchoSchema.HasId, Type.Relation.Endpoints<Source, Target>, Type.OfKind<EchoSchema.EntityKind.Relation> {
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Relation type with specific properties.
|
|
12
14
|
*/
|
|
13
|
-
export type Relation<Source extends Obj.Any, Target extends Obj.Any, Props> =
|
|
15
|
+
export type Relation<Source extends Obj.Any, Target extends Obj.Any, Props> = BaseRelation<Source, Target> & Props;
|
|
14
16
|
/**
|
|
15
17
|
* Base type for all ECHO relations.
|
|
16
18
|
*/
|
|
17
|
-
export interface Any extends
|
|
19
|
+
export interface Any extends BaseRelation<Obj.Any, Obj.Any> {
|
|
18
20
|
}
|
|
21
|
+
export declare const Any: Type.relation<Schema.Struct<{}>, Type.obj<Schema.Struct<{}>>, Type.obj<Schema.Struct<{}>>>;
|
|
19
22
|
export declare const Source: unique symbol;
|
|
20
23
|
export type Source = typeof Source;
|
|
21
24
|
export declare const Target: unique symbol;
|