@dxos/echo 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d
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/dist/lib/browser/{chunk-MWLA34S5.mjs → chunk-7GH6RXJ3.mjs} +2513 -2673
- package/dist/lib/browser/chunk-7GH6RXJ3.mjs.map +7 -0
- package/dist/lib/browser/chunk-E4UTVJNF.mjs +1111 -0
- package/dist/lib/browser/chunk-E4UTVJNF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +21 -19
- package/dist/lib/browser/internal/index.mjs +55 -45
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +247 -217
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs +1111 -0
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-YTNLFBIK.mjs → chunk-M4B6BMD2.mjs} +2513 -2673
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +21 -19
- package/dist/lib/node-esm/internal/index.mjs +55 -45
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +247 -217
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Annotation.d.ts +2 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +137 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +36 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Format.d.ts +4 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +9 -0
- package/dist/types/src/JsonSchema.d.ts.map +1 -0
- package/dist/types/src/Key.d.ts +1 -0
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +85 -62
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +10 -10
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +14 -11
- 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 +39 -49
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +14 -18
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +7 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +174 -0
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/index.d.ts +3 -0
- package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/util.d.ts +26 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
- package/dist/types/src/internal/entities/entity.d.ts +10 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/{object → entities}/expando.d.ts +3 -1
- package/dist/types/src/internal/entities/expando.d.ts.map +1 -0
- package/dist/types/src/internal/entities/index.d.ts +6 -0
- package/dist/types/src/internal/entities/index.d.ts.map +1 -0
- package/dist/types/src/internal/entities/model.d.ts +70 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +11 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +55 -0
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
- package/dist/types/src/internal/entities/util.d.ts +2 -0
- package/dist/types/src/internal/entities/util.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +2 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -1
- package/dist/types/src/internal/formats/types.d.ts +7 -7
- package/dist/types/src/internal/formats/types.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +6 -10
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +2 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/{json → json-schema}/json-schema.d.ts +2 -5
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -1
- package/dist/types/src/internal/object/{create.d.ts → create-object.d.ts} +9 -10
- package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +2 -2
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/object/ids.d.ts.map +1 -1
- package/dist/types/src/internal/object/index.d.ts +3 -12
- package/dist/types/src/internal/object/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts +1 -2
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/object/typed-object.d.ts +1 -1
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -1
- package/dist/types/src/internal/proxy/index.d.ts +3 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +16 -0
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +1 -1
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref.d.ts +15 -12
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +9 -9
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/index.d.ts +3 -4
- package/dist/types/src/internal/schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts +18 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +1 -1
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -1
- package/dist/types/src/internal/types/base.d.ts +37 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/{ast/entity-kind.d.ts → types/entity.d.ts} +3 -1
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +5 -2
- package/dist/types/src/internal/types/index.d.ts.map +1 -1
- package/dist/types/src/internal/{object → types}/meta.d.ts +20 -11
- package/dist/types/src/internal/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/types/typename.d.ts +13 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/{object → types}/version.d.ts +3 -2
- package/dist/types/src/internal/types/version.d.ts.map +1 -0
- package/dist/types/src/query/filter.d.ts +167 -0
- package/dist/types/src/query/filter.d.ts.map +1 -0
- package/dist/types/src/query/index.d.ts +3 -1
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/query/order.d.ts +12 -0
- package/dist/types/src/query/order.d.ts.map +1 -0
- package/dist/types/src/query/query.d.ts +9 -144
- package/dist/types/src/query/query.d.ts.map +1 -1
- package/dist/types/src/query/testing.d.ts +51 -0
- package/dist/types/src/query/testing.d.ts.map +1 -0
- package/dist/types/src/{internal/query/query.d.ts → query/types.d.ts} +1 -1
- package/dist/types/src/query/types.d.ts.map +1 -0
- package/dist/types/src/query/util.d.ts +8 -0
- package/dist/types/src/query/util.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -3
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +337 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/{internal/testing/utils.d.ts → testing/util.d.ts} +11 -5
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -38
- package/src/Annotation.ts +17 -0
- package/src/Database.ts +189 -0
- package/src/Entity.ts +51 -0
- package/src/Format.ts +11 -0
- package/src/JsonSchema.ts +16 -0
- package/src/Key.ts +3 -0
- package/src/Obj.ts +260 -147
- package/src/Ref.ts +9 -9
- package/src/Relation.ts +58 -44
- package/src/Tag.ts +40 -0
- package/src/Type.ts +96 -83
- package/src/index.ts +10 -4
- package/src/internal/README.md +83 -0
- package/src/internal/{ast → annotations}/annotations.test.ts +13 -15
- package/src/internal/annotations/annotations.ts +463 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +70 -0
- package/src/internal/entities/entity.ts +109 -0
- package/src/internal/{object → entities}/expando.ts +7 -5
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/entities/model.ts +129 -0
- package/src/internal/entities/object.ts +45 -0
- package/src/internal/entities/relation.ts +155 -0
- package/src/internal/entities/util.ts +33 -0
- package/src/internal/formats/date.test.ts +1 -1
- package/src/internal/formats/date.ts +5 -5
- package/src/internal/formats/format.test.ts +5 -5
- package/src/internal/formats/format.ts +3 -0
- package/src/internal/formats/number.ts +5 -5
- package/src/internal/formats/object.ts +2 -2
- package/src/internal/formats/string.ts +9 -9
- package/src/internal/formats/types.ts +44 -39
- package/src/internal/index.ts +29 -13
- package/src/internal/{json → json-schema}/annotations.ts +1 -1
- package/src/internal/json-schema/index.ts +2 -0
- package/src/internal/json-schema/json-schema-type.ts +4 -3
- package/src/internal/{json → json-schema}/json-schema.test.ts +230 -97
- package/src/internal/{json → json-schema}/json-schema.ts +67 -87
- package/src/internal/object/common.ts +3 -4
- package/src/internal/object/{create.test.ts → create-object.test.ts} +31 -33
- package/src/internal/object/{create.ts → create-object.ts} +34 -35
- package/src/internal/object/deleted.ts +6 -6
- package/src/internal/object/ids.ts +1 -1
- package/src/internal/object/index.ts +3 -12
- package/src/internal/object/inspect.ts +3 -5
- package/src/internal/object/json-serializer.test.ts +33 -38
- package/src/internal/object/json-serializer.ts +43 -38
- package/src/internal/object/schema-validator.ts +3 -2
- package/src/internal/object/typed-object.test.ts +1 -1
- package/src/internal/object/typed-object.ts +17 -4
- package/src/internal/proxy/handler.test.ts +30 -20
- package/src/internal/proxy/index.ts +6 -0
- package/src/internal/proxy/{reactive-object.ts → make-object.ts} +19 -14
- package/src/internal/proxy/schema.test.ts +5 -4
- package/src/internal/proxy/typed-handler.test.ts +28 -28
- package/src/internal/proxy/typed-handler.ts +11 -6
- package/src/internal/proxy/typed-object.test.ts +17 -12
- package/src/internal/ref/ref.test.ts +9 -8
- package/src/internal/ref/ref.ts +24 -20
- package/src/internal/{projection → schema}/compose.test.ts +5 -6
- package/src/internal/{projection → schema}/compose.ts +2 -1
- package/src/internal/schema/echo-schema.ts +30 -28
- package/src/internal/schema/index.ts +3 -4
- package/src/internal/schema/manipulation.ts +7 -1
- package/src/internal/schema/persistent-schema.ts +28 -0
- package/src/internal/schema/runtime-schema-registry.ts +4 -4
- package/src/internal/types/base.ts +58 -0
- package/src/internal/{ast/entity-kind.ts → types/entity.ts} +8 -0
- package/src/internal/types/index.ts +5 -2
- package/src/internal/{object → types}/meta.ts +32 -18
- package/src/internal/types/typename.ts +45 -0
- package/src/internal/types/version.ts +20 -0
- package/src/query/filter.ts +455 -0
- package/src/query/index.ts +4 -1
- package/src/query/order.ts +34 -0
- package/src/query/query.test.ts +188 -216
- package/src/query/query.ts +24 -505
- package/src/query/testing.ts +64 -0
- package/src/query/util.ts +25 -0
- package/src/testing/api.test.ts +100 -0
- package/src/testing/index.ts +3 -3
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +213 -0
- package/src/{internal/testing/utils.ts → testing/util.ts} +38 -14
- package/dist/lib/browser/chunk-MWLA34S5.mjs.map +0 -7
- package/dist/lib/browser/chunk-OAZJQHVO.mjs +0 -453
- package/dist/lib/browser/chunk-OAZJQHVO.mjs.map +0 -7
- package/dist/lib/browser/chunk-ORIE2FMS.mjs +0 -514
- package/dist/lib/browser/chunk-ORIE2FMS.mjs.map +0 -7
- package/dist/lib/browser/query/index.mjs +0 -23
- package/dist/lib/browser/query/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs +0 -453
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs +0 -514
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YTNLFBIK.mjs.map +0 -7
- package/dist/lib/node-esm/query/index.mjs +0 -23
- package/dist/lib/node-esm/query/index.mjs.map +0 -7
- package/dist/types/src/internal/ast/annotation-helper.d.ts +0 -8
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.d.ts +0 -119
- package/dist/types/src/internal/ast/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +0 -1
- package/dist/types/src/internal/ast/index.d.ts +0 -5
- package/dist/types/src/internal/ast/index.d.ts.map +0 -1
- package/dist/types/src/internal/ast/types.d.ts +0 -6
- package/dist/types/src/internal/ast/types.d.ts.map +0 -1
- package/dist/types/src/internal/json/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json/index.d.ts +0 -2
- package/dist/types/src/internal/json/index.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/accessors.d.ts +0 -29
- package/dist/types/src/internal/object/accessors.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.test.d.ts +0 -2
- package/dist/types/src/internal/object/create.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/entity.d.ts +0 -22
- package/dist/types/src/internal/object/entity.d.ts.map +0 -1
- package/dist/types/src/internal/object/expando.d.ts.map +0 -1
- package/dist/types/src/internal/object/meta.d.ts.map +0 -1
- package/dist/types/src/internal/object/model.d.ts +0 -117
- package/dist/types/src/internal/object/model.d.ts.map +0 -1
- package/dist/types/src/internal/object/relation.d.ts +0 -17
- package/dist/types/src/internal/object/relation.d.ts.map +0 -1
- package/dist/types/src/internal/object/typed-relation.d.ts +0 -32
- package/dist/types/src/internal/object/typed-relation.d.ts.map +0 -1
- package/dist/types/src/internal/object/typename.d.ts +0 -15
- package/dist/types/src/internal/object/typename.d.ts.map +0 -1
- package/dist/types/src/internal/object/version.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/projection/index.d.ts +0 -2
- package/dist/types/src/internal/projection/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-object.d.ts +0 -15
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +0 -1
- package/dist/types/src/internal/query/index.d.ts +0 -2
- package/dist/types/src/internal/query/index.d.ts.map +0 -1
- package/dist/types/src/internal/query/query.d.ts.map +0 -1
- package/dist/types/src/internal/schema/stored-schema.d.ts +0 -13
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +0 -1
- package/dist/types/src/internal/testing/index.d.ts +0 -3
- package/dist/types/src/internal/testing/index.d.ts.map +0 -1
- package/dist/types/src/internal/testing/types.d.ts +0 -455
- package/dist/types/src/internal/testing/types.d.ts.map +0 -1
- package/dist/types/src/internal/testing/utils.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.d.ts +0 -79
- package/dist/types/src/internal/types/types.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.test.d.ts +0 -2
- package/dist/types/src/internal/types/types.test.d.ts.map +0 -1
- package/dist/types/src/internal/types/util.d.ts +0 -5
- package/dist/types/src/internal/types/util.d.ts.map +0 -1
- package/dist/types/src/query/tag.d.ts +0 -18
- package/dist/types/src/query/tag.d.ts.map +0 -1
- package/dist/types/src/testing/echo-schema.d.ts +0 -7
- package/dist/types/src/testing/echo-schema.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/internal/ast/annotation-helper.ts +0 -22
- package/src/internal/ast/annotations.ts +0 -212
- package/src/internal/ast/index.ts +0 -8
- package/src/internal/ast/types.ts +0 -17
- package/src/internal/json/index.ts +0 -5
- package/src/internal/object/accessors.ts +0 -115
- package/src/internal/object/entity.ts +0 -204
- package/src/internal/object/model.ts +0 -170
- package/src/internal/object/relation.ts +0 -24
- package/src/internal/object/typed-relation.ts +0 -85
- package/src/internal/object/typename.ts +0 -61
- package/src/internal/object/version.ts +0 -22
- package/src/internal/projection/index.ts +0 -5
- package/src/internal/query/index.ts +0 -5
- package/src/internal/schema/stored-schema.ts +0 -26
- package/src/internal/testing/index.ts +0 -6
- package/src/internal/testing/types.ts +0 -211
- package/src/internal/types/types.test.ts +0 -48
- package/src/internal/types/types.ts +0 -176
- package/src/internal/types/util.ts +0 -9
- package/src/query/tag.ts +0 -35
- package/src/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -91
- /package/dist/types/src/internal/{ast → annotations}/annotations.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/annotations.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/effect-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.test.d.ts +0 -0
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
- /package/src/internal/{json → json-schema}/effect-schema.test.ts +0 -0
- /package/src/{internal/query/query.ts → query/types.ts} +0 -0
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
-
import type * as Types from 'effect/Types';
|
|
8
|
-
|
|
9
|
-
import { raise } from '@dxos/debug';
|
|
10
|
-
import { invariant } from '@dxos/invariant';
|
|
11
|
-
import { DXN } from '@dxos/keys';
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
EntityKind,
|
|
15
|
-
type TypeAnnotation,
|
|
16
|
-
TypeAnnotationId,
|
|
17
|
-
type TypeMeta,
|
|
18
|
-
getEntityKind,
|
|
19
|
-
getSchemaTypename,
|
|
20
|
-
getTypeIdentifierAnnotation,
|
|
21
|
-
} from '../ast';
|
|
22
|
-
import { type HasId, type ToMutable } from '../types';
|
|
23
|
-
|
|
24
|
-
import { type RelationSourceTargetRefs } from './relation';
|
|
25
|
-
|
|
26
|
-
// TODO(burdon): Define Schema type for `typename` and use consistently for all DXN-like properties.
|
|
27
|
-
|
|
28
|
-
// type RequiredKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];
|
|
29
|
-
type EchoTypeSchemaProps<T, ExtraFields = {}> = Types.Simplify<HasId & ToMutable<T> & ExtraFields>;
|
|
30
|
-
|
|
31
|
-
export interface EchoTypeSchema<Self extends Schema.Schema.Any, ExtraFields = {}>
|
|
32
|
-
extends TypeMeta,
|
|
33
|
-
Schema.AnnotableClass<
|
|
34
|
-
EchoTypeSchema<Self, ExtraFields>,
|
|
35
|
-
EchoTypeSchemaProps<Schema.Schema.Type<Self>, ExtraFields>,
|
|
36
|
-
EchoTypeSchemaProps<Schema.Schema.Encoded<Self>, ExtraFields>,
|
|
37
|
-
Schema.Schema.Context<Self>
|
|
38
|
-
> {
|
|
39
|
-
// make(
|
|
40
|
-
// props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
|
|
41
|
-
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
42
|
-
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
43
|
-
// options?: MakeOptions,
|
|
44
|
-
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>>;
|
|
45
|
-
|
|
46
|
-
instanceOf(value: unknown): boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Pipeable function to add ECHO object annotations to a schema.
|
|
51
|
-
*/
|
|
52
|
-
// TODO(dmaretskyi): Rename EchoObjectSchema.
|
|
53
|
-
export const EchoObject: {
|
|
54
|
-
// TODO(burdon): Tighten Self type to Schema.TypeLiteral or Schema.Struct to facilitate definition of `make` method.
|
|
55
|
-
// (meta: TypeMeta): <Self extends Schema.Struct<Fields>, Fields extends Schema.Struct.Fields>(self: Self) => EchoObjectSchema<Self, Fields>;
|
|
56
|
-
(meta: TypeMeta): <Self extends Schema.Schema.Any>(self: Self) => EchoTypeSchema<Self>;
|
|
57
|
-
} = ({ typename, version }) => {
|
|
58
|
-
return <Self extends Schema.Schema.Any>(self: Self): EchoTypeSchema<Self> => {
|
|
59
|
-
invariant(typeof TypeAnnotationId === 'symbol', 'Sanity.');
|
|
60
|
-
invariant(SchemaAST.isTypeLiteral(self.ast), 'Schema must be a TypeLiteral.');
|
|
61
|
-
|
|
62
|
-
// TODO(dmaretskyi): Does `Schema.mutable` work for deep mutability here?
|
|
63
|
-
// TODO(dmaretskyi): Do not do mutable here.
|
|
64
|
-
const schemaWithId = Schema.extend(Schema.mutable(self), Schema.Struct({ id: Schema.String }));
|
|
65
|
-
const ast = SchemaAST.annotations(schemaWithId.ast, {
|
|
66
|
-
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
67
|
-
...self.ast.annotations,
|
|
68
|
-
[TypeAnnotationId]: { kind: EntityKind.Object, typename, version } satisfies TypeAnnotation,
|
|
69
|
-
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return makeEchoObjectSchema<Self>(/* self.fields, */ ast, typename, version);
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export type EchoRelationOptions<
|
|
77
|
-
TSource extends Schema.Schema.AnyNoContext,
|
|
78
|
-
TTarget extends Schema.Schema.AnyNoContext,
|
|
79
|
-
> = TypeMeta & {
|
|
80
|
-
source: TSource;
|
|
81
|
-
target: TTarget;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// TODO(dmaretskyi): Rename EchoRelationSchema.
|
|
85
|
-
export const EchoRelation = <Source extends Schema.Schema.AnyNoContext, Target extends Schema.Schema.AnyNoContext>(
|
|
86
|
-
options: EchoRelationOptions<Source, Target>,
|
|
87
|
-
) => {
|
|
88
|
-
const sourceDXN = getDXNForRelationSchemaRef(options.source);
|
|
89
|
-
const targetDXN = getDXNForRelationSchemaRef(options.target);
|
|
90
|
-
if (getEntityKind(options.source) !== EntityKind.Object) {
|
|
91
|
-
raise(new Error('Source schema must be an echo object schema.'));
|
|
92
|
-
}
|
|
93
|
-
if (getEntityKind(options.target) !== EntityKind.Object) {
|
|
94
|
-
raise(new Error('Target schema must be an echo object schema.'));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return <Self extends Schema.Schema.Any>(
|
|
98
|
-
self: Self,
|
|
99
|
-
): EchoTypeSchema<Self, RelationSourceTargetRefs<Schema.Schema.Type<Source>, Schema.Schema.Type<Target>>> => {
|
|
100
|
-
invariant(SchemaAST.isTypeLiteral(self.ast), 'Schema must be a TypeLiteral.');
|
|
101
|
-
|
|
102
|
-
// TODO(dmaretskyi): Does `Schema.mutable` work for deep mutability here?
|
|
103
|
-
// TODO(dmaretskyi): Do not do mutable here.
|
|
104
|
-
const schemaWithId = Schema.extend(Schema.mutable(self), Schema.Struct({ id: Schema.String }));
|
|
105
|
-
const ast = SchemaAST.annotations(schemaWithId.ast, {
|
|
106
|
-
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
107
|
-
...self.ast.annotations,
|
|
108
|
-
[TypeAnnotationId]: {
|
|
109
|
-
kind: EntityKind.Relation,
|
|
110
|
-
typename: options.typename,
|
|
111
|
-
version: options.version,
|
|
112
|
-
sourceSchema: sourceDXN,
|
|
113
|
-
targetSchema: targetDXN,
|
|
114
|
-
} satisfies TypeAnnotation,
|
|
115
|
-
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return makeEchoObjectSchema<Self>(/* self.fields, */ ast, options.typename, options.version);
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const getDXNForRelationSchemaRef = (schema: Schema.Schema.Any): string => {
|
|
123
|
-
const identifier = getTypeIdentifierAnnotation(schema);
|
|
124
|
-
if (identifier) {
|
|
125
|
-
return identifier;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const typename = getSchemaTypename(schema);
|
|
129
|
-
if (!typename) {
|
|
130
|
-
throw new Error('Schema must have a typename');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return DXN.fromTypename(typename).toString();
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// type MakeOptions =
|
|
137
|
-
// | boolean
|
|
138
|
-
// | {
|
|
139
|
-
// readonly disableValidation?: boolean;
|
|
140
|
-
// };
|
|
141
|
-
|
|
142
|
-
// NOTE: Utils copied from Effect `Schema.ts`.
|
|
143
|
-
// const _ownKeys = (o: object): Array<PropertyKey> =>
|
|
144
|
-
// (Object.keys(o) as Array<PropertyKey>).concat(Object.getOwnPropertySymbols(o));
|
|
145
|
-
|
|
146
|
-
// const _lazilyMergeDefaults = (
|
|
147
|
-
// fields: Schema.Struct.Fields,
|
|
148
|
-
// out: Record<PropertyKey, unknown>,
|
|
149
|
-
// ): { [x: string | symbol]: unknown } => {
|
|
150
|
-
// const ownKeys = _ownKeys(fields);
|
|
151
|
-
// for (const key of ownKeys) {
|
|
152
|
-
// const field = fields[key];
|
|
153
|
-
// if (out[key] === undefined && Schema.isPropertySignature(field)) {
|
|
154
|
-
// const ast = field.ast;
|
|
155
|
-
// const defaultValue = ast._tag === 'PropertySignatureDeclaration' ? ast.defaultValue : ast.to.defaultValue;
|
|
156
|
-
// if (defaultValue !== undefined) {
|
|
157
|
-
// out[key] = defaultValue();
|
|
158
|
-
// }
|
|
159
|
-
// }
|
|
160
|
-
// }
|
|
161
|
-
// return out;
|
|
162
|
-
// };
|
|
163
|
-
|
|
164
|
-
// const _getDisableValidationMakeOption = (options: MakeOptions | undefined): boolean =>
|
|
165
|
-
// Predicate.isBoolean(options) ? options : options?.disableValidation ?? false;
|
|
166
|
-
|
|
167
|
-
const makeEchoObjectSchema = <Self extends Schema.Schema.Any>(
|
|
168
|
-
// fields: Fields,
|
|
169
|
-
ast: SchemaAST.AST,
|
|
170
|
-
typename: string,
|
|
171
|
-
version: string,
|
|
172
|
-
): EchoTypeSchema<Self> => {
|
|
173
|
-
return class EchoObjectSchemaClass extends Schema.make<
|
|
174
|
-
EchoTypeSchemaProps<Schema.Schema.Type<Self>>,
|
|
175
|
-
EchoTypeSchemaProps<Schema.Schema.Encoded<Self>>,
|
|
176
|
-
Schema.Schema.Context<Self>
|
|
177
|
-
>(ast) {
|
|
178
|
-
static readonly typename = typename;
|
|
179
|
-
static readonly version = version;
|
|
180
|
-
|
|
181
|
-
static override annotations(
|
|
182
|
-
annotations: Schema.Annotations.GenericSchema<EchoTypeSchemaProps<Schema.Schema.Type<Self>>>,
|
|
183
|
-
): EchoTypeSchema<Self> {
|
|
184
|
-
const schema = Schema.make<EchoTypeSchemaProps<Schema.Schema.Type<Self>>>(ast).annotations(annotations);
|
|
185
|
-
return makeEchoObjectSchema<Self>(/* fields, */ schema.ast, typename, version);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// static make(
|
|
189
|
-
// props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
|
|
190
|
-
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
191
|
-
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
192
|
-
// options?: MakeOptions,
|
|
193
|
-
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
|
|
194
|
-
// const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
|
|
195
|
-
// return _getDisableValidationMakeOption(options)
|
|
196
|
-
// ? propsWithDefaults
|
|
197
|
-
// : ParseResult.validateSync(this)(propsWithDefaults);
|
|
198
|
-
// }
|
|
199
|
-
|
|
200
|
-
static instanceOf(value: unknown): boolean {
|
|
201
|
-
return Schema.is(this)(value);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { type ForeignKey } from '@dxos/echo-protocol';
|
|
8
|
-
import { invariant } from '@dxos/invariant';
|
|
9
|
-
import { DXN, ObjectId } from '@dxos/keys';
|
|
10
|
-
import { assumeType } from '@dxos/util';
|
|
11
|
-
|
|
12
|
-
import { EntityKind } from '../ast';
|
|
13
|
-
|
|
14
|
-
import { type ObjectMeta } from './meta';
|
|
15
|
-
import type { Version } from './version';
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
// Defines the internal model of the echo object.
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Entity kind.
|
|
23
|
-
*/
|
|
24
|
-
export const EntityKindId = Symbol('@dxos/echo/EntityKind');
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* DXN to the object itself.
|
|
28
|
-
*/
|
|
29
|
-
export const SelfDXNId = Symbol('@dxos/echo/DXN');
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Property name for self DXN when object is serialized to JSON.
|
|
33
|
-
*/
|
|
34
|
-
export const ATTR_SELF_DXN = '@dxn';
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* DXN to the object type.
|
|
38
|
-
*/
|
|
39
|
-
export const TypeId = Symbol('@dxos/echo/Type');
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Property name for typename when object is serialized to JSON.
|
|
43
|
-
*/
|
|
44
|
-
export const ATTR_TYPE = '@type';
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Reference to the object schema.
|
|
48
|
-
*/
|
|
49
|
-
export const SchemaId = Symbol('@dxos/echo/Schema');
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Deletion marker.
|
|
53
|
-
*/
|
|
54
|
-
export const DeletedId = Symbol('@dxos/echo/Deleted');
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Property name for deleted when object is serialized to JSON.
|
|
58
|
-
*/
|
|
59
|
-
export const ATTR_DELETED = '@deleted';
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Metadata section.
|
|
63
|
-
*/
|
|
64
|
-
export const MetaId = Symbol('@dxos/echo/Meta');
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Property name for meta when object is serialized to JSON.
|
|
68
|
-
*/
|
|
69
|
-
export const ATTR_META = '@meta';
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Used to access relation source ref on live ECHO objects.
|
|
73
|
-
* Reading this symbol must return `Live<EchoObject<any>>` or a DXN.
|
|
74
|
-
*/
|
|
75
|
-
export const RelationSourceDXNId: unique symbol = Symbol('@dxos/echo/RelationSourceDXN');
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Property name for relation source when object is serialized to JSON.
|
|
79
|
-
*/
|
|
80
|
-
export const ATTR_RELATION_SOURCE = '@relationSource';
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Used to access relation target ref on live ECHO objects.
|
|
84
|
-
* Reading this symbol must return `Live<EchoObject<any>>` or a DXN.
|
|
85
|
-
*/
|
|
86
|
-
export const RelationTargetDXNId: unique symbol = Symbol('@dxos/echo/RelationTargetDXN');
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Property name for relation target when object is serialized to JSON.
|
|
90
|
-
*/
|
|
91
|
-
export const ATTR_RELATION_TARGET = '@relationTarget';
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Used to access relation source ref on live ECHO objects.
|
|
95
|
-
* Reading this symbol must return `Live<EchoObject<any>>` or a DXN.
|
|
96
|
-
*/
|
|
97
|
-
export const RelationSourceId: unique symbol = Symbol('@dxos/echo/RelationSource');
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Used to access relation target ref on live ECHO objects.
|
|
101
|
-
* Reading this symbol must return `Live<EchoObject<any>>` or a DXN.
|
|
102
|
-
*/
|
|
103
|
-
export const RelationTargetId: unique symbol = Symbol('@dxos/echo/RelationTarget');
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Getter to get object version.
|
|
107
|
-
*/
|
|
108
|
-
export const ObjectVersionId: unique symbol = Symbol('@dxos/echo/ObjectVersion');
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Internal runtime representation of an object.
|
|
112
|
-
* The fields are accessed through getter functions.
|
|
113
|
-
*/
|
|
114
|
-
export interface InternalObjectProps {
|
|
115
|
-
id: ObjectId;
|
|
116
|
-
readonly [SelfDXNId]?: DXN;
|
|
117
|
-
|
|
118
|
-
// Echo supports untyped objects O_O.
|
|
119
|
-
readonly [TypeId]?: DXN;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Returns the schema for the object.
|
|
123
|
-
*/
|
|
124
|
-
readonly [SchemaId]?: Schema.Schema.AnyNoContext;
|
|
125
|
-
readonly [EntityKindId]: EntityKind;
|
|
126
|
-
readonly [DeletedId]?: boolean;
|
|
127
|
-
readonly [MetaId]?: ObjectMeta;
|
|
128
|
-
readonly [RelationSourceDXNId]?: DXN;
|
|
129
|
-
readonly [RelationTargetDXNId]?: DXN;
|
|
130
|
-
readonly [RelationSourceId]?: InternalObjectProps;
|
|
131
|
-
readonly [RelationTargetId]?: InternalObjectProps;
|
|
132
|
-
readonly [ObjectVersionId]?: Version;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* JSON representation of an object or relation.
|
|
137
|
-
*/
|
|
138
|
-
export interface ObjectJSON {
|
|
139
|
-
id: string;
|
|
140
|
-
[ATTR_SELF_DXN]?: DXN.String;
|
|
141
|
-
[ATTR_TYPE]: DXN.String;
|
|
142
|
-
[ATTR_DELETED]?: boolean;
|
|
143
|
-
[ATTR_META]?: ObjectMetaJSON;
|
|
144
|
-
[ATTR_RELATION_SOURCE]?: DXN.String;
|
|
145
|
-
[ATTR_RELATION_TARGET]?: DXN.String;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface ObjectMetaJSON {
|
|
149
|
-
keys: ForeignKey[];
|
|
150
|
-
tags?: string[];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// NOTE: Keep as `function` to avoid type inference issues.
|
|
154
|
-
// eslint-disable-next-line prefer-arrow-functions/prefer-arrow-functions
|
|
155
|
-
export function assertObjectModelShape(obj: unknown): asserts obj is InternalObjectProps {
|
|
156
|
-
invariant(typeof obj === 'object' && obj !== null, 'Invalid object model: not an object');
|
|
157
|
-
assumeType<InternalObjectProps>(obj);
|
|
158
|
-
invariant(ObjectId.isValid(obj.id), 'Invalid object model: invalid id');
|
|
159
|
-
invariant(obj[TypeId] === undefined || obj[TypeId] instanceof DXN, 'Invalid object model: invalid type');
|
|
160
|
-
invariant(
|
|
161
|
-
obj[EntityKindId] === EntityKind.Object || obj[EntityKindId] === EntityKind.Relation,
|
|
162
|
-
'Invalid object model: invalid entity kind',
|
|
163
|
-
);
|
|
164
|
-
if (obj[EntityKindId] === EntityKind.Relation) {
|
|
165
|
-
invariant(obj[RelationSourceDXNId] instanceof DXN, 'Invalid object model: invalid relation source');
|
|
166
|
-
invariant(obj[RelationTargetDXNId] instanceof DXN, 'Invalid object model: invalid relation target');
|
|
167
|
-
invariant(!(obj[RelationSourceId] instanceof DXN), 'Invalid object model: source pointer is a DXN');
|
|
168
|
-
invariant(!(obj[RelationTargetId] instanceof DXN), 'Invalid object model: target pointer is a DXN');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { RelationSourceId, RelationTargetId } from './model';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Source and target props on relations.
|
|
9
|
-
*/
|
|
10
|
-
// TODO(burdon): any?
|
|
11
|
-
export type RelationSourceTargetRefs<Source = any, Target = any> = {
|
|
12
|
-
/**
|
|
13
|
-
* Source ECHO live object.
|
|
14
|
-
*/
|
|
15
|
-
[RelationSourceId]: Source;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Target ECHO live object.
|
|
19
|
-
*/
|
|
20
|
-
[RelationTargetId]: Target;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type RelationSource<R> = R extends RelationSourceTargetRefs<infer Source, infer _Target> ? Source : never;
|
|
24
|
-
export type RelationTarget<R> = R extends RelationSourceTargetRefs<infer _Source, infer Target> ? Target : never;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { invariant } from '@dxos/invariant';
|
|
8
|
-
|
|
9
|
-
import { EntityKind, SchemaVersion, type TypeAnnotation, TypeAnnotationId, type TypeMeta, Typename } from '../ast';
|
|
10
|
-
import { type HasId } from '../types';
|
|
11
|
-
|
|
12
|
-
import { type TypedObjectFields, type TypedObjectOptions, makeTypedEntityClass } from './common';
|
|
13
|
-
import { type RelationSourceTargetRefs } from './relation';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Definition for an object type that can be stored in an ECHO database.
|
|
17
|
-
* Implements effect schema to define object properties.
|
|
18
|
-
* Has a typename and version.
|
|
19
|
-
*
|
|
20
|
-
* In contrast to {@link EchoSchema} this definition is not recorded in the database.
|
|
21
|
-
*/
|
|
22
|
-
export interface TypedRelation<A = any, I = any> extends TypeMeta, Schema.Schema<A, I> {}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Typed object that could be used as a prototype in class definitions.
|
|
26
|
-
* This is an internal API type.
|
|
27
|
-
* Use {@link TypedRelation} for the common use-cases.
|
|
28
|
-
*/
|
|
29
|
-
export interface TypedRelationPrototype<A = any, I = any> extends TypedRelation<A, I> {
|
|
30
|
-
/** Type constructor. */
|
|
31
|
-
new (): HasId & A;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type TypedRelationProps = TypeMeta & {
|
|
35
|
-
// TODO(dmaretskyi): Remove after all legacy types has been removed.
|
|
36
|
-
disableValidation?: boolean;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Base class factory for typed objects.
|
|
41
|
-
* @deprecated Use {@link EchoRelation} instead.
|
|
42
|
-
*/
|
|
43
|
-
export const TypedRelation = ({
|
|
44
|
-
typename: typenameParam,
|
|
45
|
-
version: versionParam,
|
|
46
|
-
disableValidation,
|
|
47
|
-
}: TypedRelationProps) => {
|
|
48
|
-
const typename = Typename.make(typenameParam, { disableValidation });
|
|
49
|
-
const version = SchemaVersion.make(versionParam, { disableValidation });
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Return class definition factory.
|
|
53
|
-
*/
|
|
54
|
-
return <SchemaFields extends Schema.Struct.Fields, Options extends TypedObjectOptions>(
|
|
55
|
-
fields: SchemaFields,
|
|
56
|
-
options?: Options,
|
|
57
|
-
): TypedRelationPrototype<
|
|
58
|
-
TypedObjectFields<SchemaFields, Options> & RelationSourceTargetRefs,
|
|
59
|
-
Schema.Struct.Encoded<SchemaFields>
|
|
60
|
-
> => {
|
|
61
|
-
// Create schema from fields.
|
|
62
|
-
const schema: Schema.Schema.All = options?.record
|
|
63
|
-
? Schema.Struct(fields, { key: Schema.String, value: Schema.Any })
|
|
64
|
-
: Schema.Struct(fields);
|
|
65
|
-
|
|
66
|
-
// Set ECHO object id property.
|
|
67
|
-
const typeSchema = Schema.extend(
|
|
68
|
-
Schema.mutable(options?.partial ? Schema.partial(schema) : schema),
|
|
69
|
-
Schema.Struct({ id: Schema.String }),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// Set ECHO annotations.
|
|
73
|
-
invariant(typeof EntityKind.Relation === 'string');
|
|
74
|
-
const annotatedSchema = typeSchema.annotations({
|
|
75
|
-
[TypeAnnotationId]: { kind: EntityKind.Relation, typename, version } satisfies TypeAnnotation,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Return class definition.
|
|
80
|
-
* NOTE: Actual reactive ECHO objects must be created via the `live(Type)` function.
|
|
81
|
-
*/
|
|
82
|
-
// TODO(burdon): This is missing fields required by TypedRelation (e.g., Type, Encoded, Context)?
|
|
83
|
-
return class TypedRelation extends makeTypedEntityClass(typename, version, annotatedSchema as any) {} as any;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { invariant } from '@dxos/invariant';
|
|
6
|
-
import { DXN } from '@dxos/keys';
|
|
7
|
-
|
|
8
|
-
import { getSchemaTypename } from '../ast';
|
|
9
|
-
import { type BaseObject } from '../types';
|
|
10
|
-
|
|
11
|
-
import { getSchema } from './accessors';
|
|
12
|
-
import { TypeId } from './model';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Gets the typename of the object without the version.
|
|
16
|
-
* Returns only the name portion, not the DXN.
|
|
17
|
-
* @example "example.org/type/Contact"
|
|
18
|
-
*/
|
|
19
|
-
export const getTypename = (obj: BaseObject): string | undefined => {
|
|
20
|
-
const schema = getSchema(obj);
|
|
21
|
-
if (schema != null) {
|
|
22
|
-
// Try to extract typename from DXN.
|
|
23
|
-
return getSchemaTypename(schema);
|
|
24
|
-
} else {
|
|
25
|
-
const type = getType(obj);
|
|
26
|
-
return type?.asTypeDXN()?.type;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
// TODO(dmaretskyi): Rename setTypeDXN.
|
|
34
|
-
export const setTypename = (obj: any, typename: DXN) => {
|
|
35
|
-
invariant(typename instanceof DXN, 'Invalid type.');
|
|
36
|
-
Object.defineProperty(obj, TypeId, {
|
|
37
|
-
value: typename,
|
|
38
|
-
writable: false,
|
|
39
|
-
enumerable: false,
|
|
40
|
-
configurable: false,
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @returns Object type as {@link DXN}.
|
|
46
|
-
* @returns undefined if the object doesn't have a type.
|
|
47
|
-
* @example `dxn:example.com/type/Contact:1.0.0`
|
|
48
|
-
*/
|
|
49
|
-
export const getType = (obj: BaseObject): DXN | undefined => {
|
|
50
|
-
if (!obj) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const type = (obj as any)[TypeId];
|
|
55
|
-
if (!type) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
invariant(type instanceof DXN, 'Invalid object.');
|
|
60
|
-
return type;
|
|
61
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// NOTE: Those types must match the ones defined at @dxos/echo. We duplicated them murely due to technical constrains.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Getter to get object version.
|
|
7
|
-
*/
|
|
8
|
-
//
|
|
9
|
-
// Copyright 2025 DXOS.org
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
export const VersionTypeId: unique symbol = Symbol('@dxos/echo/Version');
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Represent object version.
|
|
16
|
-
* May be backed by Automerge.
|
|
17
|
-
* Objects with no history are not versioned.
|
|
18
|
-
*/
|
|
19
|
-
export interface Version {
|
|
20
|
-
[VersionTypeId]: {};
|
|
21
|
-
automergeHeads?: string[];
|
|
22
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { SchemaVersion, Typename } from '../ast';
|
|
8
|
-
import { JsonSchemaType } from '../json-schema';
|
|
9
|
-
import { EchoObject } from '../object';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Persistent representation of a schema.
|
|
13
|
-
*/
|
|
14
|
-
export const StoredSchema = Schema.Struct({
|
|
15
|
-
name: Schema.optional(Schema.String),
|
|
16
|
-
typename: Typename,
|
|
17
|
-
version: SchemaVersion,
|
|
18
|
-
jsonSchema: JsonSchemaType,
|
|
19
|
-
}).pipe(
|
|
20
|
-
EchoObject({
|
|
21
|
-
typename: 'dxos.org/type/Schema',
|
|
22
|
-
version: '0.1.0',
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
export type StoredSchema = Schema.Schema.Type<typeof StoredSchema>;
|