@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
|
@@ -8,9 +8,8 @@ import * as SchemaAST from 'effect/SchemaAST';
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { type ObjectId } from '@dxos/keys';
|
|
10
10
|
|
|
11
|
-
import { type SchemaMeta, SchemaMetaSymbol, type TypeAnnotation, getTypeAnnotation } from '../
|
|
12
|
-
import { toEffectSchema, toJsonSchema } from '../json';
|
|
13
|
-
import { type JsonSchemaType } from '../json-schema';
|
|
11
|
+
import { type SchemaMeta, SchemaMetaSymbol, type TypeAnnotation, getTypeAnnotation } from '../annotations';
|
|
12
|
+
import { type JsonSchemaType, toEffectSchema, toJsonSchema } from '../json-schema';
|
|
14
13
|
import { type TypedObject, type TypedObjectPrototype } from '../object';
|
|
15
14
|
|
|
16
15
|
import {
|
|
@@ -20,14 +19,15 @@ import {
|
|
|
20
19
|
updateFieldNameInSchema,
|
|
21
20
|
updateFieldsInSchema,
|
|
22
21
|
} from './manipulation';
|
|
22
|
+
import { PersistentSchema } from './persistent-schema';
|
|
23
23
|
import { getSnapshot } from './snapshot';
|
|
24
|
-
import { StoredSchema } from './stored-schema';
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Base schema type.
|
|
28
27
|
*/
|
|
29
28
|
// TODO(burdon): Merge with ImmutableSchema.
|
|
30
29
|
export interface BaseSchema<A = any, I = any> extends TypedObject<A, I> {
|
|
30
|
+
// TODO(burdon): Different from mutable?
|
|
31
31
|
get readonly(): boolean;
|
|
32
32
|
// TODO(burdon): Change to external function.
|
|
33
33
|
get mutable(): EchoSchema<A, I>;
|
|
@@ -124,8 +124,10 @@ const EchoSchemaConstructor = (): TypedObjectPrototype => {
|
|
|
124
124
|
*/
|
|
125
125
|
return class {
|
|
126
126
|
private static get _schema() {
|
|
127
|
-
// The field is DynamicEchoSchema in runtime, but is serialized as
|
|
128
|
-
return Schema.Union(
|
|
127
|
+
// The field is DynamicEchoSchema in runtime, but is serialized as PersisentSchema in automerge.
|
|
128
|
+
return Schema.Union(PersistentSchema, Schema.instanceOf(EchoSchema)).annotations(
|
|
129
|
+
PersistentSchema.ast.annotations,
|
|
130
|
+
);
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
static readonly [Schema.TypeId] = schemaVariance;
|
|
@@ -159,7 +161,7 @@ const schemaVariance = {
|
|
|
159
161
|
};
|
|
160
162
|
|
|
161
163
|
/**
|
|
162
|
-
* Represents a schema that is
|
|
164
|
+
* Represents a schema that is persisted in the ECHO database.
|
|
163
165
|
* Schema can me mutable or readonly (specified by the {@link EchoSchema.readonly} field).
|
|
164
166
|
*
|
|
165
167
|
* Schema that can be modified at runtime via the API.
|
|
@@ -177,13 +179,13 @@ const schemaVariance = {
|
|
|
177
179
|
* }) {}
|
|
178
180
|
* ```
|
|
179
181
|
*
|
|
180
|
-
* The ECHO API will translate any references to
|
|
182
|
+
* The ECHO API will translate any references to PersistentSchema objects to be resolved as EchoSchema objects.
|
|
181
183
|
*/
|
|
182
184
|
export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implements BaseSchema<A, I> {
|
|
183
185
|
private _schema: Schema.Schema.AnyNoContext | undefined;
|
|
184
186
|
private _isDirty = true;
|
|
185
187
|
|
|
186
|
-
constructor(private readonly
|
|
188
|
+
constructor(private readonly _persistentSchema: PersistentSchema) {
|
|
187
189
|
super();
|
|
188
190
|
}
|
|
189
191
|
|
|
@@ -196,11 +198,11 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
public get Type() {
|
|
199
|
-
return this.
|
|
201
|
+
return this._persistentSchema as A;
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
public get Encoded() {
|
|
203
|
-
return this.
|
|
205
|
+
return this._persistentSchema as I;
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
public get Context() {
|
|
@@ -228,11 +230,11 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
228
230
|
//
|
|
229
231
|
|
|
230
232
|
public get typename(): string {
|
|
231
|
-
return this.
|
|
233
|
+
return this._persistentSchema.typename;
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
public get version(): string {
|
|
235
|
-
return this.
|
|
237
|
+
return this._persistentSchema.version;
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
public get readonly(): boolean {
|
|
@@ -250,7 +252,7 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
250
252
|
* @reactive
|
|
251
253
|
*/
|
|
252
254
|
public get jsonSchema(): JsonSchemaType {
|
|
253
|
-
return this.
|
|
255
|
+
return this._persistentSchema.jsonSchema;
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
/**
|
|
@@ -269,25 +271,25 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
269
271
|
* Id of the ECHO object containing the schema.
|
|
270
272
|
*/
|
|
271
273
|
public get id(): ObjectId {
|
|
272
|
-
return this.
|
|
274
|
+
return this._persistentSchema.id;
|
|
273
275
|
}
|
|
274
276
|
|
|
275
277
|
/**
|
|
276
278
|
* Short name of the schema.
|
|
277
279
|
*/
|
|
278
280
|
public get name(): string | undefined {
|
|
279
|
-
return this.
|
|
281
|
+
return this._persistentSchema.name;
|
|
280
282
|
}
|
|
281
283
|
|
|
282
284
|
public get [SchemaMetaSymbol](): SchemaMeta {
|
|
283
|
-
return { id: this.id, typename: this.typename, version: this.
|
|
285
|
+
return { id: this.id, typename: this.typename, version: this._persistentSchema.version };
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
/**
|
|
287
|
-
* Reference to the underlying
|
|
289
|
+
* Reference to the underlying persistent schema object.
|
|
288
290
|
*/
|
|
289
|
-
public get
|
|
290
|
-
return this.
|
|
291
|
+
public get persistentSchema(): PersistentSchema {
|
|
292
|
+
return this._persistentSchema;
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
public getProperties(): SchemaAST.PropertySignature[] {
|
|
@@ -307,8 +309,8 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
307
309
|
*/
|
|
308
310
|
public updateTypename(typename: string): void {
|
|
309
311
|
const updated = setTypenameInSchema(this._getSchema(), typename);
|
|
310
|
-
this.
|
|
311
|
-
this.
|
|
312
|
+
this._persistentSchema.typename = typename;
|
|
313
|
+
this._persistentSchema.jsonSchema = toJsonSchema(updated);
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
/**
|
|
@@ -316,7 +318,7 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
316
318
|
*/
|
|
317
319
|
public addFields(fields: Schema.Struct.Fields): void {
|
|
318
320
|
const extended = addFieldsToSchema(this._getSchema(), fields);
|
|
319
|
-
this.
|
|
321
|
+
this._persistentSchema.jsonSchema = toJsonSchema(extended);
|
|
320
322
|
}
|
|
321
323
|
|
|
322
324
|
/**
|
|
@@ -324,7 +326,7 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
324
326
|
*/
|
|
325
327
|
public updateFields(fields: Schema.Struct.Fields): void {
|
|
326
328
|
const updated = updateFieldsInSchema(this._getSchema(), fields);
|
|
327
|
-
this.
|
|
329
|
+
this._persistentSchema.jsonSchema = toJsonSchema(updated);
|
|
328
330
|
}
|
|
329
331
|
|
|
330
332
|
/**
|
|
@@ -332,7 +334,7 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
332
334
|
*/
|
|
333
335
|
public updateFieldPropertyName({ before, after }: { before: PropertyKey; after: PropertyKey }): void {
|
|
334
336
|
const renamed = updateFieldNameInSchema(this._getSchema(), { before, after });
|
|
335
|
-
this.
|
|
337
|
+
this._persistentSchema.jsonSchema = toJsonSchema(renamed);
|
|
336
338
|
}
|
|
337
339
|
|
|
338
340
|
/**
|
|
@@ -340,7 +342,7 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
340
342
|
*/
|
|
341
343
|
public removeFields(fieldNames: string[]): void {
|
|
342
344
|
const removed = removeFieldsFromSchema(this._getSchema(), fieldNames);
|
|
343
|
-
this.
|
|
345
|
+
this._persistentSchema.jsonSchema = toJsonSchema(removed);
|
|
344
346
|
}
|
|
345
347
|
|
|
346
348
|
//
|
|
@@ -359,12 +361,12 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
|
|
|
359
361
|
*/
|
|
360
362
|
_rebuild(): void {
|
|
361
363
|
if (this._isDirty || this._schema == null) {
|
|
362
|
-
this._schema = toEffectSchema(getSnapshot(this.
|
|
364
|
+
this._schema = toEffectSchema(getSnapshot(this._persistentSchema.jsonSchema));
|
|
363
365
|
this._isDirty = false;
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
368
|
|
|
367
|
-
|
|
369
|
+
_getSchema(): Schema.Schema.AnyNoContext {
|
|
368
370
|
this._rebuild();
|
|
369
371
|
return this._schema!;
|
|
370
372
|
}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './echo-schema';
|
|
6
|
-
export * from './snapshot';
|
|
7
|
-
export * from './stored-schema';
|
|
8
|
-
export * from './runtime-schema-registry';
|
|
9
6
|
export * from './manipulation';
|
|
10
|
-
export * from './
|
|
7
|
+
export * from './persistent-schema';
|
|
8
|
+
export * from './runtime-schema-registry';
|
|
9
|
+
export * from './snapshot';
|
|
@@ -6,8 +6,9 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
9
10
|
|
|
10
|
-
import { type TypeAnnotation, TypeAnnotationId } from '../
|
|
11
|
+
import { type TypeAnnotation, TypeAnnotationId, TypeIdentifierAnnotationId } from '../annotations';
|
|
11
12
|
|
|
12
13
|
// TODO(ZaymonFC): Do this one at a time. This might be dangerous.
|
|
13
14
|
export const addFieldsToSchema = (
|
|
@@ -82,5 +83,10 @@ export const setTypenameInSchema = (
|
|
|
82
83
|
typename,
|
|
83
84
|
version: existingAnnotation.version,
|
|
84
85
|
} satisfies TypeAnnotation,
|
|
86
|
+
[SchemaAST.JSONSchemaAnnotationId]: {
|
|
87
|
+
...(schema.ast.annotations[SchemaAST.JSONSchemaAnnotationId] ?? {}),
|
|
88
|
+
$id: schema.ast.annotations[TypeIdentifierAnnotationId] ?? DXN.fromTypename(typename).toString(),
|
|
89
|
+
typename,
|
|
90
|
+
},
|
|
85
91
|
});
|
|
86
92
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { TypenameSchema, VersionSchema } from '../annotations';
|
|
8
|
+
import { EchoObjectSchema } from '../entities';
|
|
9
|
+
import { JsonSchemaType } from '../json-schema';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Persistent representation of a schema.
|
|
13
|
+
*/
|
|
14
|
+
// TODO(burdon): Move.
|
|
15
|
+
const PersistentEchoSchema = Schema.Struct({
|
|
16
|
+
name: Schema.optional(Schema.String),
|
|
17
|
+
typename: TypenameSchema,
|
|
18
|
+
version: VersionSchema,
|
|
19
|
+
jsonSchema: JsonSchemaType,
|
|
20
|
+
}).pipe(
|
|
21
|
+
EchoObjectSchema({
|
|
22
|
+
typename: 'dxos.org/type/Schema',
|
|
23
|
+
version: '0.1.0',
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
export interface PersistentSchema extends Schema.Schema.Type<typeof PersistentEchoSchema> {}
|
|
27
|
+
export interface PersistentSchemaEncoded extends Schema.Schema.Encoded<typeof PersistentEchoSchema> {}
|
|
28
|
+
export const PersistentSchema: Schema.Schema<PersistentSchema, PersistentSchemaEncoded> = PersistentEchoSchema;
|
|
@@ -9,9 +9,9 @@ import { invariant } from '@dxos/invariant';
|
|
|
9
9
|
import { type DXN } from '@dxos/keys';
|
|
10
10
|
import { defaultMap } from '@dxos/util';
|
|
11
11
|
|
|
12
|
-
import { getSchemaTypename, getSchemaVersion } from '../
|
|
12
|
+
import { getSchemaTypename, getSchemaVersion } from '../annotations';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { PersistentSchema } from './persistent-schema';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Runtime registry of static schema objects (i.e., not Dynamic .
|
|
@@ -21,7 +21,7 @@ export class RuntimeSchemaRegistry {
|
|
|
21
21
|
private readonly _registry = new Map<string, Schema.Schema.AnyNoContext[]>();
|
|
22
22
|
|
|
23
23
|
constructor() {
|
|
24
|
-
this._registry.set(
|
|
24
|
+
this._registry.set(getSchemaTypename(PersistentSchema)!, [PersistentSchema]);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
get schemas(): Schema.Schema.AnyNoContext[] {
|
|
@@ -63,7 +63,7 @@ export class RuntimeSchemaRegistry {
|
|
|
63
63
|
return this._registry.get(typename)?.[0];
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
addSchema(types: Schema.Schema.AnyNoContext[]): void {
|
|
66
|
+
addSchema(types: readonly Schema.Schema.AnyNoContext[]): void {
|
|
67
67
|
types.forEach((schema) => {
|
|
68
68
|
const typename = getSchemaTypename(schema) ?? raise(new TypeError('Schema has no typename'));
|
|
69
69
|
const version = getSchemaVersion(schema) ?? raise(new TypeError('Schema has no version'));
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { type ObjectId } from '@dxos/keys';
|
|
9
|
+
|
|
10
|
+
import { type ATTR_META, type ObjectMeta } from './meta';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Marker interface for object with an `id`.
|
|
14
|
+
*/
|
|
15
|
+
export interface HasId {
|
|
16
|
+
readonly id: ObjectId;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Object that has an associated typename.
|
|
21
|
+
* The typename is retrievable using {@link getTypename}.
|
|
22
|
+
* The object can be used with {@link isInstanceOf} to check if it is an instance of a schema.
|
|
23
|
+
*/
|
|
24
|
+
export type HasTypename = {};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Base type for all data objects (reactive, ECHO, and other raw objects).
|
|
28
|
+
* NOTE: This describes the base type for all database objects.
|
|
29
|
+
* It is stricter than `T extends {}` or `T extends object`.
|
|
30
|
+
*/
|
|
31
|
+
// TODO(burdon): Make internal.
|
|
32
|
+
// TODO(burdon): Prefer Record<string, unknown>.
|
|
33
|
+
// TODO(burdon): Exclude "id", etc. from keys.
|
|
34
|
+
export type AnyProperties = Record<string, any>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Canonical type for all ECHO objects.
|
|
38
|
+
*/
|
|
39
|
+
export interface AnyEchoObject extends HasId, HasTypename {}
|
|
40
|
+
|
|
41
|
+
// TODO(dmaretskyi): Remove; this type effectively disables type safety due to `any`.
|
|
42
|
+
export type WithId<T extends AnyProperties = AnyProperties> = T & HasId;
|
|
43
|
+
|
|
44
|
+
export type ExcludeId<T extends AnyProperties> = Omit<T, 'id'>;
|
|
45
|
+
|
|
46
|
+
export type PropertyKey<T extends AnyProperties> = Extract<keyof ExcludeId<T>, string>;
|
|
47
|
+
|
|
48
|
+
// TODO(dmaretskyi): Remove. This should be using the symbol type.
|
|
49
|
+
export type WithMeta = { [ATTR_META]?: ObjectMeta };
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The raw object should not include the ECHO id, but may include metadata.
|
|
53
|
+
*/
|
|
54
|
+
export const RawObject = <S extends Schema.Schema.AnyNoContext>(
|
|
55
|
+
schema: S,
|
|
56
|
+
): Schema.Schema<ExcludeId<Schema.Schema.Type<S>> & WithMeta, Schema.Schema.Encoded<S>> => {
|
|
57
|
+
return Schema.make(SchemaAST.omit(schema.ast, ['id']));
|
|
58
|
+
};
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Entity kind.
|
|
9
|
+
*/
|
|
10
|
+
const EntityKindId = Symbol.for('@dxos/echo/EntityKind');
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Kinds of entities stored in ECHO: objects and relations.
|
|
9
14
|
*/
|
|
@@ -13,3 +18,6 @@ export enum EntityKind {
|
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
export const EntityKindSchema = Schema.Enums(EntityKind);
|
|
21
|
+
|
|
22
|
+
export const KindId: unique symbol = EntityKindId as any;
|
|
23
|
+
export type KindId = typeof KindId;
|
|
@@ -8,9 +8,17 @@ import { ForeignKey } from '@dxos/echo-protocol';
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { type Comparator, intersection } from '@dxos/util';
|
|
10
10
|
|
|
11
|
-
import { type
|
|
11
|
+
import { type AnyProperties, type WithMeta } from './base';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Property name for meta when object is serialized to JSON.
|
|
15
|
+
*/
|
|
16
|
+
export const ATTR_META = '@meta';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Metadata section.
|
|
20
|
+
*/
|
|
21
|
+
export const MetaId = Symbol.for('@dxos/echo/Meta');
|
|
14
22
|
|
|
15
23
|
//
|
|
16
24
|
// ObjectMeta
|
|
@@ -31,32 +39,38 @@ export const ObjectMetaSchema = Schema.mutable(
|
|
|
31
39
|
tags: Schema.optional(Schema.mutable(Schema.Array(Schema.String))),
|
|
32
40
|
}),
|
|
33
41
|
);
|
|
34
|
-
|
|
35
42
|
export type ObjectMeta = Schema.Schema.Type<typeof ObjectMetaSchema>;
|
|
36
43
|
|
|
37
|
-
export const foreignKey = (source: string, id: string): ForeignKey => ({ source, id });
|
|
38
|
-
export const foreignKeyEquals = (a: ForeignKey, b: ForeignKey) => a.source === b.source && a.id === b.id;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get metadata from object.
|
|
42
|
-
* Only callable on the object root.
|
|
43
|
-
* @deprecated Use {@link getMeta}.
|
|
44
|
-
*/
|
|
45
|
-
// TODO(dmaretskyi): Remove.
|
|
46
|
-
export const getObjectMeta = (obj: any): ObjectMeta => {
|
|
47
|
-
return getMeta(obj);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
44
|
/*
|
|
51
45
|
* Get metadata from object.
|
|
52
46
|
* Only callable on the object root.
|
|
47
|
+
*
|
|
48
|
+
* @internal (use Obj.getMeta or Relation.getMeta)
|
|
53
49
|
*/
|
|
54
|
-
|
|
50
|
+
// TODO(burdon): Refine type to BaseObj.
|
|
51
|
+
export const getMeta = (obj: AnyProperties): ObjectMeta => {
|
|
55
52
|
const metadata = (obj as any)[MetaId];
|
|
56
53
|
invariant(metadata, 'ObjectMeta not found.');
|
|
57
54
|
return metadata;
|
|
58
55
|
};
|
|
59
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Utility to split meta property from raw object.
|
|
59
|
+
* @deprecated Bad API.
|
|
60
|
+
*/
|
|
61
|
+
export const splitMeta = <T>(object: T & WithMeta): { object: T; meta?: ObjectMeta } => {
|
|
62
|
+
const meta = object[ATTR_META];
|
|
63
|
+
delete object[ATTR_META];
|
|
64
|
+
return { meta, object };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//
|
|
68
|
+
// Foreign keys
|
|
69
|
+
//
|
|
70
|
+
|
|
71
|
+
export const foreignKey = (source: string, id: string): ForeignKey => ({ source, id });
|
|
72
|
+
export const foreignKeyEquals = (a: ForeignKey, b: ForeignKey) => a.source === b.source && a.id === b.id;
|
|
73
|
+
|
|
60
74
|
// TODO(dmaretskyi): Move to echo-schema.
|
|
61
|
-
export const compareForeignKeys: Comparator<
|
|
75
|
+
export const compareForeignKeys: Comparator<AnyProperties> = (a: AnyProperties, b: AnyProperties) =>
|
|
62
76
|
intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Property name for typename when object is serialized to JSON.
|
|
9
|
+
*/
|
|
10
|
+
export const ATTR_TYPE = '@type';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* DXN to the object type.
|
|
14
|
+
*/
|
|
15
|
+
export const TypeId = Symbol.for('@dxos/echo/Type');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Reference to the object schema.
|
|
19
|
+
*/
|
|
20
|
+
export const SchemaId = Symbol.for('@dxos/echo/Schema');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the schema for the given object if one is defined.
|
|
24
|
+
*
|
|
25
|
+
* @internal (Use Obj.getSchema)
|
|
26
|
+
*/
|
|
27
|
+
// TODO(burdon): Narrow type.
|
|
28
|
+
// TODO(dmaretskyi): For echo objects, this always returns the root schema.
|
|
29
|
+
export const getSchema = (obj: unknown | undefined): Schema.Schema.AnyNoContext | undefined => {
|
|
30
|
+
if (obj) {
|
|
31
|
+
return (obj as any)[SchemaId];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export const setSchema = (obj: any, schema: Schema.Schema.AnyNoContext): void => {
|
|
39
|
+
Object.defineProperty(obj, SchemaId, {
|
|
40
|
+
value: schema,
|
|
41
|
+
writable: false,
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: false,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Version type symbol.
|
|
7
|
+
*/
|
|
8
|
+
export const VersionTypeId: unique symbol = Symbol.for('@dxos/echo/VersionTypeId');
|
|
9
|
+
|
|
10
|
+
export type VersionTypeId = typeof VersionTypeId;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represents the object version.
|
|
14
|
+
* May be backed by Automerge.
|
|
15
|
+
* Objects with no history are not versioned.
|
|
16
|
+
*/
|
|
17
|
+
export interface Version {
|
|
18
|
+
[VersionTypeId]: {};
|
|
19
|
+
automergeHeads?: string[];
|
|
20
|
+
}
|