@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
package/src/Obj.ts
CHANGED
|
@@ -5,53 +5,89 @@
|
|
|
5
5
|
import * as Function from 'effect/Function';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
+
import { type ForeignKey } from '@dxos/echo-protocol';
|
|
8
9
|
import { assertArgument, invariant } from '@dxos/invariant';
|
|
9
|
-
import { type DXN } from '@dxos/keys';
|
|
10
|
-
import
|
|
10
|
+
import { type DXN, ObjectId } from '@dxos/keys';
|
|
11
|
+
import { getSnapshot as getSnapshot$ } from '@dxos/live-object';
|
|
11
12
|
import { assumeType, deepMapValues } from '@dxos/util';
|
|
12
13
|
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
import * as Entity from './Entity';
|
|
15
|
+
import {
|
|
16
|
+
type AnyEchoObject,
|
|
17
|
+
type AnyProperties,
|
|
18
|
+
type InternalObjectProps,
|
|
19
|
+
MetaId,
|
|
20
|
+
type ObjectJSON,
|
|
21
|
+
type ObjectMeta,
|
|
22
|
+
ObjectVersionId,
|
|
23
|
+
VersionTypeId,
|
|
24
|
+
getDescription as getDescription$,
|
|
25
|
+
getLabel as getLabel$,
|
|
26
|
+
getMeta as getMeta$,
|
|
27
|
+
getObjectDXN,
|
|
28
|
+
getSchema as getSchema$,
|
|
29
|
+
getSchemaTypename,
|
|
30
|
+
getTypeAnnotation,
|
|
31
|
+
getTypeDXN as getTypeDXN$,
|
|
32
|
+
isDeleted as isDeleted$,
|
|
33
|
+
isInstanceOf,
|
|
34
|
+
makeObject,
|
|
35
|
+
objectFromJSON,
|
|
36
|
+
objectToJSON,
|
|
37
|
+
setDescription as setDescription$,
|
|
38
|
+
setLabel as setLabel$,
|
|
39
|
+
} from './internal';
|
|
40
|
+
import * as Ref from './Ref';
|
|
17
41
|
import * as Type from './Type';
|
|
18
42
|
|
|
19
43
|
/**
|
|
20
|
-
*
|
|
44
|
+
* Base type for all ECHO objects.
|
|
45
|
+
* @private
|
|
21
46
|
*/
|
|
22
|
-
interface BaseObj extends
|
|
47
|
+
interface BaseObj extends AnyEchoObject, Entity.OfKind<typeof Entity.Kind.Object> {}
|
|
23
48
|
|
|
24
49
|
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
export type Obj<Props> = BaseObj & Props;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Base type for all ECHO objects.
|
|
50
|
+
* Base type for all Obj objects.
|
|
31
51
|
*/
|
|
32
52
|
export interface Any extends BaseObj {}
|
|
33
53
|
|
|
34
54
|
export const Any = Schema.Struct({}).pipe(
|
|
35
55
|
Type.Obj({
|
|
36
|
-
typename: 'dxos.org/
|
|
56
|
+
typename: 'dxos.org/type/Any',
|
|
37
57
|
version: '0.1.0',
|
|
38
58
|
}),
|
|
39
59
|
);
|
|
40
60
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
61
|
+
/**
|
|
62
|
+
* Object type with specific properties.
|
|
63
|
+
*/
|
|
64
|
+
export type Obj<Props> = BaseObj & Props;
|
|
46
65
|
|
|
47
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Object with arbitrary properties.
|
|
68
|
+
*
|
|
69
|
+
* NOTE: Due to how typescript works, this type is not assignable to a specific schema type.
|
|
70
|
+
* In that case, use `Obj.instanceOf` to check if an object is of a specific type.
|
|
71
|
+
*/
|
|
72
|
+
export interface AnyProps extends BaseObj, AnyProperties {}
|
|
48
73
|
|
|
49
|
-
const
|
|
74
|
+
const defaultMeta: ObjectMeta = {
|
|
50
75
|
keys: [],
|
|
51
76
|
};
|
|
52
77
|
|
|
78
|
+
type Props<T = any> = {
|
|
79
|
+
id?: ObjectId;
|
|
80
|
+
[Meta]?: Partial<ObjectMeta>;
|
|
81
|
+
} & Type.Properties<T>;
|
|
82
|
+
|
|
83
|
+
// TODO(burdon): Should we allow the caller to set the id?
|
|
84
|
+
export type MakeProps<T extends Schema.Schema.AnyNoContext> = {
|
|
85
|
+
id?: ObjectId;
|
|
86
|
+
[Meta]?: Partial<ObjectMeta>;
|
|
87
|
+
} & NoInfer<Props<Schema.Schema.Type<T>>>;
|
|
88
|
+
|
|
53
89
|
/**
|
|
54
|
-
* Creates new object.
|
|
90
|
+
* Creates a new object of the given types.
|
|
55
91
|
* @param schema - Object schema.
|
|
56
92
|
* @param props - Object properties.
|
|
57
93
|
* @param meta - Object metadata (deprecated) -- pass with Obj.Meta.
|
|
@@ -63,38 +99,96 @@ const DEFAULT_META: EchoSchema.ObjectMeta = {
|
|
|
63
99
|
* const obj = Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' });
|
|
64
100
|
* ```
|
|
65
101
|
*/
|
|
66
|
-
export const make = <S extends
|
|
102
|
+
export const make = <S extends Schema.Schema.AnyNoContext>(
|
|
67
103
|
schema: S,
|
|
68
104
|
props: MakeProps<S>,
|
|
69
|
-
meta?: Partial<
|
|
70
|
-
):
|
|
71
|
-
assertArgument(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (props[EchoSchema.MetaId] != null) {
|
|
78
|
-
// Set default fields on meta on creation.
|
|
79
|
-
meta = { ...structuredClone(DEFAULT_META), ...props[EchoSchema.MetaId] };
|
|
80
|
-
delete props[EchoSchema.MetaId];
|
|
105
|
+
meta?: Partial<ObjectMeta>,
|
|
106
|
+
): Obj<Schema.Schema.Type<S>> => {
|
|
107
|
+
assertArgument(getTypeAnnotation(schema)?.kind === Entity.Kind.Object, 'schema', 'Expected an object schema');
|
|
108
|
+
|
|
109
|
+
// Set default fields on meta on creation.
|
|
110
|
+
if (props[MetaId] != null) {
|
|
111
|
+
meta = { ...structuredClone(defaultMeta), ...props[MetaId] };
|
|
112
|
+
delete props[MetaId];
|
|
81
113
|
}
|
|
82
114
|
|
|
83
|
-
|
|
115
|
+
// Filter undefined values.
|
|
116
|
+
const filterUndefined = Object.fromEntries(Object.entries(props).filter(([_, v]) => v !== undefined));
|
|
117
|
+
|
|
118
|
+
return makeObject<Schema.Schema.Type<S>>(schema, filterUndefined as any, {
|
|
119
|
+
...defaultMeta,
|
|
120
|
+
...meta,
|
|
121
|
+
});
|
|
84
122
|
};
|
|
85
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Determine if object is an ECHO object.
|
|
126
|
+
*/
|
|
86
127
|
export const isObject = (obj: unknown): obj is Any => {
|
|
87
|
-
assumeType<
|
|
88
|
-
return typeof obj === 'object' && obj !== null && obj[
|
|
128
|
+
assumeType<InternalObjectProps>(obj);
|
|
129
|
+
return typeof obj === 'object' && obj !== null && obj[Entity.KindId] === Entity.Kind.Object;
|
|
89
130
|
};
|
|
90
131
|
|
|
132
|
+
//
|
|
133
|
+
// Snapshot
|
|
134
|
+
//
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Returns an immutable snapshot of an object.
|
|
138
|
+
*/
|
|
139
|
+
export const getSnapshot: <T extends Any>(obj: Obj<T>) => T = getSnapshot$;
|
|
140
|
+
|
|
141
|
+
export type CloneOptions = {
|
|
142
|
+
/**
|
|
143
|
+
* Retain the original object's ID.
|
|
144
|
+
* @default false
|
|
145
|
+
*/
|
|
146
|
+
retainId?: boolean;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Clones an object or relation.
|
|
151
|
+
* This does not clone referenced objects, only the properties in the object.
|
|
152
|
+
* @returns A new object with the same schema and properties.
|
|
153
|
+
*/
|
|
154
|
+
export const clone = <T extends Any>(obj: T, opts?: CloneOptions): T => {
|
|
155
|
+
const { id, ...data } = obj;
|
|
156
|
+
const schema = getSchema$(obj);
|
|
157
|
+
invariant(schema != null, 'Object should have a schema');
|
|
158
|
+
const props: any = deepMapValues(data, (value, recurse) => {
|
|
159
|
+
if (Ref.isRef(value)) {
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
return recurse(value);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (opts?.retainId) {
|
|
166
|
+
props.id = id;
|
|
167
|
+
}
|
|
168
|
+
const meta = getMeta(obj);
|
|
169
|
+
props[MetaId] = deepMapValues(meta, (value, recurse) => {
|
|
170
|
+
if (Ref.isRef(value)) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
return recurse(value);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return make(schema as Type.Obj.Any, props);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
//
|
|
180
|
+
// Type
|
|
181
|
+
//
|
|
182
|
+
|
|
183
|
+
// TODO(burdon): To discuss: prefer over ObjectId or Key.ObjectId or Type.ID?
|
|
184
|
+
export const ID = ObjectId;
|
|
185
|
+
export type ID = ObjectId;
|
|
186
|
+
|
|
91
187
|
/**
|
|
92
188
|
* Test if object or relation is an instance of a schema.
|
|
93
189
|
* @example
|
|
94
190
|
* ```ts
|
|
95
191
|
* const john = Obj.make(Person, { name: 'John' });
|
|
96
|
-
* const johnIsPerson = Obj.instanceOf(Person)(john);
|
|
97
|
-
*
|
|
98
192
|
* const isPerson = Obj.instanceOf(Person);
|
|
99
193
|
* if (isPerson(john)) {
|
|
100
194
|
* // john is Person
|
|
@@ -102,52 +196,60 @@ export const isObject = (obj: unknown): obj is Any => {
|
|
|
102
196
|
* ```
|
|
103
197
|
*/
|
|
104
198
|
export const instanceOf: {
|
|
105
|
-
<S extends Type.
|
|
106
|
-
<S extends Type.
|
|
107
|
-
} = ((
|
|
108
|
-
...args: [schema: Type.Relation.Any | Type.Obj.Any, value: unknown] | [schema: Type.Relation.Any | Type.Obj.Any]
|
|
109
|
-
) => {
|
|
199
|
+
<S extends Type.Entity.Any>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
|
|
200
|
+
<S extends Type.Entity.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
|
|
201
|
+
} = ((...args: [schema: Type.Entity.Any, value: unknown] | [schema: Type.Entity.Any]) => {
|
|
110
202
|
if (args.length === 1) {
|
|
111
|
-
return (
|
|
203
|
+
return (entity: unknown) => isInstanceOf(args[0], entity);
|
|
112
204
|
}
|
|
113
205
|
|
|
114
|
-
return
|
|
206
|
+
return isInstanceOf(args[0], args[1]);
|
|
115
207
|
}) as any;
|
|
116
208
|
|
|
117
|
-
export const getSchema = EchoSchema.getSchema;
|
|
118
|
-
|
|
119
209
|
// TODO(dmaretskyi): Allow returning undefined.
|
|
120
|
-
export const getDXN = (
|
|
121
|
-
assertArgument(!Schema.isSchema(
|
|
122
|
-
const dxn =
|
|
210
|
+
export const getDXN = (entity: Entity.Unknown): DXN => {
|
|
211
|
+
assertArgument(!Schema.isSchema(entity), 'obj', 'Object should not be a schema.');
|
|
212
|
+
const dxn = getObjectDXN(entity);
|
|
123
213
|
invariant(dxn != null, 'Invalid object.');
|
|
124
214
|
return dxn;
|
|
125
215
|
};
|
|
126
216
|
|
|
127
217
|
/**
|
|
128
218
|
* @returns The DXN of the object's type.
|
|
129
|
-
* @example dxn:example.com/type/
|
|
219
|
+
* @example dxn:example.com/type/Person:1.0.0
|
|
220
|
+
*/
|
|
221
|
+
// TODO(burdon): Must define and return type for expando.
|
|
222
|
+
export const getTypeDXN = getTypeDXN$;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Get the schema of the object.
|
|
130
226
|
*/
|
|
131
|
-
|
|
132
|
-
export const getTypeDXN = EchoSchema.getType;
|
|
227
|
+
export const getSchema = getSchema$;
|
|
133
228
|
|
|
134
229
|
/**
|
|
135
230
|
* @returns The typename of the object's type.
|
|
136
|
-
* @example `example.com/type/
|
|
231
|
+
* @example `example.com/type/Person`
|
|
137
232
|
*/
|
|
138
|
-
export const getTypename = (
|
|
139
|
-
const schema = getSchema(
|
|
233
|
+
export const getTypename = (entity: Entity.Unknown): string | undefined => {
|
|
234
|
+
const schema = getSchema$(entity);
|
|
140
235
|
if (schema == null) {
|
|
141
236
|
// Try to extract typename from DXN.
|
|
142
|
-
return
|
|
237
|
+
return getTypeDXN$(entity)?.asTypeDXN()?.type;
|
|
143
238
|
}
|
|
144
239
|
|
|
145
|
-
return
|
|
240
|
+
return getSchemaTypename(schema);
|
|
146
241
|
};
|
|
147
242
|
|
|
243
|
+
//
|
|
244
|
+
// Meta
|
|
245
|
+
//
|
|
246
|
+
|
|
247
|
+
export const Meta: unique symbol = MetaId as any;
|
|
248
|
+
|
|
249
|
+
// TODO(burdon): Narrow type.
|
|
148
250
|
// TODO(dmaretskyi): Allow returning undefined.
|
|
149
|
-
export const getMeta = (
|
|
150
|
-
const meta =
|
|
251
|
+
export const getMeta = (entity: AnyProperties): ObjectMeta => {
|
|
252
|
+
const meta = getMeta$(entity);
|
|
151
253
|
invariant(meta != null, 'Invalid object.');
|
|
152
254
|
return meta;
|
|
153
255
|
};
|
|
@@ -156,21 +258,21 @@ export const getMeta = (obj: Any | Relation.Any): EchoSchema.ObjectMeta => {
|
|
|
156
258
|
* @returns Foreign keys for the object from the specified source.
|
|
157
259
|
*/
|
|
158
260
|
export const getKeys: {
|
|
159
|
-
(
|
|
160
|
-
(source: string): (
|
|
161
|
-
} = Function.dual(2, (
|
|
162
|
-
const meta =
|
|
261
|
+
(entity: Entity.Unknown, source: string): ForeignKey[];
|
|
262
|
+
(source: string): (entity: Entity.Unknown) => ForeignKey[];
|
|
263
|
+
} = Function.dual(2, (entity: Entity.Unknown, source?: string): ForeignKey[] => {
|
|
264
|
+
const meta = getMeta(entity);
|
|
163
265
|
invariant(meta != null, 'Invalid object.');
|
|
164
266
|
return meta.keys.filter((key) => key.source === source);
|
|
165
267
|
});
|
|
166
268
|
|
|
167
269
|
/**
|
|
168
270
|
* Delete all keys from the object for the specified source.
|
|
169
|
-
* @param
|
|
271
|
+
* @param entity
|
|
170
272
|
* @param source
|
|
171
273
|
*/
|
|
172
|
-
export const deleteKeys = (
|
|
173
|
-
const meta =
|
|
274
|
+
export const deleteKeys = (entity: Entity.Unknown, source: string) => {
|
|
275
|
+
const meta = getMeta(entity);
|
|
174
276
|
for (let i = 0; i < meta.keys.length; i++) {
|
|
175
277
|
if (meta.keys[i].source === source) {
|
|
176
278
|
meta.keys.splice(i, 1);
|
|
@@ -179,124 +281,134 @@ export const deleteKeys = (obj: Any | Relation.Any, source: string) => {
|
|
|
179
281
|
}
|
|
180
282
|
};
|
|
181
283
|
|
|
284
|
+
export const addTag = (entity: Entity.Unknown, tag: string) => {
|
|
285
|
+
const meta = getMeta(entity);
|
|
286
|
+
meta.tags ??= [];
|
|
287
|
+
meta.tags.push(tag);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export const removeTag = (entity: Entity.Unknown, tag: string) => {
|
|
291
|
+
const meta = getMeta(entity);
|
|
292
|
+
if (!meta.tags) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
for (let i = 0; i < meta.tags.length; i++) {
|
|
296
|
+
if (meta.tags[i] === tag) {
|
|
297
|
+
meta.tags.splice(i, 1);
|
|
298
|
+
i--;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
182
303
|
// TODO(dmaretskyi): Default to `false`.
|
|
183
|
-
export const isDeleted = (
|
|
184
|
-
const deleted =
|
|
304
|
+
export const isDeleted = (entity: Entity.Unknown): boolean => {
|
|
305
|
+
const deleted = isDeleted$(entity);
|
|
185
306
|
invariant(typeof deleted === 'boolean', 'Invalid object.');
|
|
186
307
|
return deleted;
|
|
187
308
|
};
|
|
188
309
|
|
|
189
|
-
|
|
190
|
-
|
|
310
|
+
//
|
|
311
|
+
// Annotations
|
|
312
|
+
//
|
|
313
|
+
|
|
314
|
+
export const getLabel = (entity: Entity.Unknown): string | undefined => {
|
|
315
|
+
const schema = getSchema$(entity);
|
|
191
316
|
if (schema != null) {
|
|
192
|
-
return
|
|
317
|
+
return getLabel$(schema, entity);
|
|
193
318
|
}
|
|
194
319
|
};
|
|
195
320
|
|
|
196
|
-
export const setLabel = (
|
|
197
|
-
const schema = getSchema(
|
|
321
|
+
export const setLabel = (entity: Entity.Unknown, label: string) => {
|
|
322
|
+
const schema = getSchema$(entity);
|
|
198
323
|
if (schema != null) {
|
|
199
|
-
|
|
324
|
+
setLabel$(schema, entity, label);
|
|
200
325
|
}
|
|
201
326
|
};
|
|
202
327
|
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
328
|
+
export const getDescription = (entity: Entity.Unknown): string | undefined => {
|
|
329
|
+
const schema = getSchema$(entity);
|
|
330
|
+
if (schema != null) {
|
|
331
|
+
return getDescription$(schema, entity);
|
|
206
332
|
}
|
|
333
|
+
};
|
|
207
334
|
|
|
208
|
-
|
|
209
|
-
|
|
335
|
+
export const setDescription = (entity: Entity.Unknown, description: string) => {
|
|
336
|
+
const schema = getSchema$(entity);
|
|
337
|
+
if (schema != null) {
|
|
338
|
+
setDescription$(schema, entity, description);
|
|
210
339
|
}
|
|
211
|
-
|
|
212
|
-
return a.localeCompare(b);
|
|
213
340
|
};
|
|
214
341
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
export const sortByTypename: Comparator = (a: Any, b: Any) => compare(getTypename(a), getTypename(b));
|
|
219
|
-
export const sort = (...comparators: Comparator[]): Comparator => {
|
|
220
|
-
return (a: Any, b: Any) => {
|
|
221
|
-
for (const comparator of comparators) {
|
|
222
|
-
const result = comparator(a, b);
|
|
223
|
-
if (result !== 0) {
|
|
224
|
-
return result;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return 0;
|
|
229
|
-
};
|
|
230
|
-
};
|
|
342
|
+
//
|
|
343
|
+
// JSON
|
|
344
|
+
//
|
|
231
345
|
|
|
232
346
|
/**
|
|
233
347
|
* JSON representation of an object.
|
|
234
348
|
*/
|
|
235
|
-
export type JSON =
|
|
349
|
+
export type JSON = ObjectJSON;
|
|
236
350
|
|
|
237
351
|
/**
|
|
238
352
|
* Converts object to its JSON representation.
|
|
239
353
|
*
|
|
240
354
|
* The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
|
|
241
355
|
*/
|
|
242
|
-
|
|
243
|
-
export const toJSON = (obj: Any | Relation.Any): JSON => EchoSchema.objectToJSON(obj);
|
|
356
|
+
export const toJSON = (entity: Entity.Unknown): JSON => objectToJSON(entity);
|
|
244
357
|
|
|
245
358
|
/**
|
|
246
359
|
* Creates an object from its json representation, performing schema validation.
|
|
247
360
|
* References and schemas will be resolvable if the `refResolver` is provided.
|
|
248
361
|
*
|
|
249
|
-
* The function
|
|
362
|
+
* The function must be async to support resolving the schema as well as the relation endpoints.
|
|
250
363
|
*
|
|
251
364
|
* @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.
|
|
252
365
|
* @param options.dxn - Override object DXN. Changes the result of `Obj.getDXN`.
|
|
253
366
|
*/
|
|
254
367
|
export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<Any> =
|
|
255
|
-
|
|
368
|
+
objectFromJSON as any;
|
|
256
369
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
export const getSnapshot: <T extends Any>(obj: Obj<T>) => T = LiveObject.getSnapshot;
|
|
370
|
+
//
|
|
371
|
+
// Sorting
|
|
372
|
+
//
|
|
261
373
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*/
|
|
267
|
-
retainId?: boolean;
|
|
268
|
-
};
|
|
374
|
+
const compare = (a?: string, b?: string) => {
|
|
375
|
+
if (a == null) {
|
|
376
|
+
return b == null ? 0 : 1;
|
|
377
|
+
}
|
|
269
378
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* This does not clone referenced objects, only the properties in the object.
|
|
273
|
-
* @returns A new object with the same schema and properties.
|
|
274
|
-
*/
|
|
275
|
-
export const clone = <T extends Any | Relation.Any>(obj: T, opts?: CloneOptions): T => {
|
|
276
|
-
const { id, ...data } = obj;
|
|
277
|
-
const schema = getSchema(obj);
|
|
278
|
-
invariant(schema != null, 'Object should have a schema');
|
|
279
|
-
const props: any = deepMapValues(data, (value, recurse) => {
|
|
280
|
-
if (EchoSchema.Ref.isRef(value)) {
|
|
281
|
-
return value;
|
|
282
|
-
}
|
|
283
|
-
return recurse(value);
|
|
284
|
-
});
|
|
285
|
-
if (opts?.retainId) {
|
|
286
|
-
props.id = id;
|
|
379
|
+
if (b == null) {
|
|
380
|
+
return -1;
|
|
287
381
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
382
|
+
|
|
383
|
+
return a.localeCompare(b);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
export type Comparator = (a: Entity.Unknown, b: Entity.Unknown) => number;
|
|
387
|
+
|
|
388
|
+
export const sortByLabel: Comparator = (a: Entity.Unknown, b: Entity.Unknown) => compare(getLabel(a), getLabel(b));
|
|
389
|
+
export const sortByTypename: Comparator = (a: Entity.Unknown, b: Entity.Unknown) =>
|
|
390
|
+
compare(getTypename(a), getTypename(b));
|
|
391
|
+
export const sort = (...comparators: Comparator[]): Comparator => {
|
|
392
|
+
return (a: Entity.Unknown, b: Entity.Unknown) => {
|
|
393
|
+
for (const comparator of comparators) {
|
|
394
|
+
const result = comparator(a, b);
|
|
395
|
+
if (result !== 0) {
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
292
398
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
399
|
+
|
|
400
|
+
return 0;
|
|
401
|
+
};
|
|
296
402
|
};
|
|
297
403
|
|
|
298
|
-
|
|
299
|
-
|
|
404
|
+
//
|
|
405
|
+
// Version
|
|
406
|
+
//
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Unique symbol for version type identification.
|
|
410
|
+
*/
|
|
411
|
+
export { VersionTypeId };
|
|
300
412
|
|
|
301
413
|
/**
|
|
302
414
|
* Represent object version.
|
|
@@ -325,18 +437,19 @@ const unversioned: Version = {
|
|
|
325
437
|
/**
|
|
326
438
|
* Checks that `obj` is a version object.
|
|
327
439
|
*/
|
|
328
|
-
export const isVersion = (
|
|
329
|
-
return
|
|
440
|
+
export const isVersion = (entity: unknown): entity is Version => {
|
|
441
|
+
return entity != null && typeof entity === 'object' && VersionTypeId in entity;
|
|
330
442
|
};
|
|
331
443
|
|
|
332
444
|
/**
|
|
333
445
|
* Returns the version of the object.
|
|
334
446
|
*/
|
|
335
|
-
export const version = (
|
|
336
|
-
const version = (
|
|
447
|
+
export const version = (entity: Entity.Unknown): Version => {
|
|
448
|
+
const version = (entity as any)[ObjectVersionId];
|
|
337
449
|
if (version === undefined) {
|
|
338
450
|
return unversioned;
|
|
339
451
|
}
|
|
452
|
+
|
|
340
453
|
return version;
|
|
341
454
|
};
|
|
342
455
|
|
package/src/Ref.ts
CHANGED
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { Ref as Ref$, RefArray, type RefResolver } from './internal';
|
|
6
6
|
import type * as Obj from './Obj';
|
|
7
7
|
|
|
8
|
-
export type Ref<T> =
|
|
9
|
-
export type Any =
|
|
8
|
+
export type Ref<T> = Ref$<T>;
|
|
9
|
+
export type Any = Ref$<Obj.Any>;
|
|
10
10
|
|
|
11
|
-
export const Array =
|
|
11
|
+
export const Array = RefArray;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Extract reference target.
|
|
15
15
|
*/
|
|
16
|
-
export type Target<R extends Any> = R extends
|
|
16
|
+
export type Target<R extends Any> = R extends Ref$<infer T> ? T : never;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Reference resolver.
|
|
20
20
|
*/
|
|
21
|
-
export type Resolver =
|
|
21
|
+
export type Resolver = RefResolver;
|
|
22
22
|
|
|
23
|
-
export const isRef: (value: unknown) => value is Any =
|
|
23
|
+
export const isRef: (value: unknown) => value is Any = Ref$.isRef;
|
|
24
24
|
|
|
25
|
-
export const make =
|
|
25
|
+
export const make = Ref$.make;
|
|
26
26
|
|
|
27
27
|
// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.
|
|
28
|
-
export const fromDXN =
|
|
28
|
+
export const fromDXN = Ref$.fromDXN;
|