@dxos/echo 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549
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-BIDAASFK.mjs → chunk-7GH6RXJ3.mjs} +2246 -2290
- 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 +18 -8
- package/dist/lib/browser/internal/index.mjs +45 -45
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +252 -191
- 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-3SVRRCUU.mjs → chunk-M4B6BMD2.mjs} +2246 -2290
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +18 -8
- package/dist/lib/node-esm/internal/index.mjs +45 -45
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +252 -191
- 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 +79 -70
- 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 +1 -1
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +39 -49
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +6 -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 -1
- 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} +8 -9
- 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 -11
- 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/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 -0
- 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 -145
- 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/{types.d.ts → test-schema.d.ts} +166 -57
- 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 +248 -181
- package/src/Ref.ts +9 -9
- package/src/Relation.ts +58 -44
- package/src/Tag.ts +2 -1
- package/src/Type.ts +96 -83
- package/src/index.ts +9 -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/{object → entities}/model.ts +49 -90
- 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 +48 -38
- package/src/internal/{json → json-schema}/json-schema.ts +16 -7
- package/src/internal/object/common.ts +3 -4
- package/src/internal/object/{create.test.ts → create-object.test.ts} +30 -32
- package/src/internal/object/{create.ts → create-object.ts} +33 -34
- package/src/internal/object/deleted.ts +6 -6
- package/src/internal/object/ids.ts +1 -1
- package/src/internal/object/index.ts +3 -11
- 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 +11 -5
- 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 +8 -3
- package/src/internal/proxy/typed-object.test.ts +16 -11
- package/src/internal/ref/ref.test.ts +8 -7
- 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 +1 -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 -17
- 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 +48 -115
- package/src/query/query.ts +16 -502
- 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-BIDAASFK.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs +0 -410
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs +0 -585
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs.map +0 -7
- package/dist/lib/browser/query/index.mjs +0 -13
- package/dist/lib/browser/query/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3SVRRCUU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs +0 -585
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs +0 -410
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs.map +0 -7
- package/dist/lib/node-esm/query/index.mjs +0 -13
- 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 -131
- 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 -37
- 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 -33
- 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/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 -381
- 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/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.map +0 -1
- package/src/internal/ast/annotation-helper.ts +0 -22
- package/src/internal/ast/annotations.ts +0 -226
- 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 -153
- package/src/internal/object/entity.ts +0 -248
- package/src/internal/object/relation.ts +0 -24
- 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 -144
- 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/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -108
- /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
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { EchoObjectSchema } from '../entities';
|
|
9
|
+
import { TypedObject } from '../object';
|
|
10
|
+
import { getSchema } from '../types';
|
|
9
11
|
|
|
10
|
-
import {
|
|
12
|
+
import { makeObject } from './make-object';
|
|
11
13
|
|
|
12
14
|
const Organization = Schema.Struct({
|
|
13
15
|
name: Schema.String,
|
|
14
16
|
}).pipe(
|
|
15
|
-
|
|
17
|
+
EchoObjectSchema({
|
|
16
18
|
typename: 'example.com/type/Organization',
|
|
17
19
|
version: '0.1.0',
|
|
18
20
|
}),
|
|
@@ -24,10 +26,13 @@ const Contact = Schema.Struct(
|
|
|
24
26
|
{
|
|
25
27
|
name: Schema.String,
|
|
26
28
|
},
|
|
27
|
-
{
|
|
29
|
+
{
|
|
30
|
+
key: Schema.String,
|
|
31
|
+
value: Schema.Any,
|
|
32
|
+
},
|
|
28
33
|
).pipe(
|
|
29
34
|
Schema.partial,
|
|
30
|
-
|
|
35
|
+
EchoObjectSchema({
|
|
31
36
|
typename: 'example.com/type/Person',
|
|
32
37
|
version: '0.1.0',
|
|
33
38
|
}),
|
|
@@ -37,15 +42,15 @@ interface Contact extends Schema.Schema.Type<typeof Contact> {}
|
|
|
37
42
|
|
|
38
43
|
const TEST_ORG: Omit<Organization, 'id'> = { name: 'Test' };
|
|
39
44
|
|
|
40
|
-
describe('
|
|
45
|
+
describe('EchoObjectSchema class DSL', () => {
|
|
41
46
|
test('can get object schema', async () => {
|
|
42
|
-
const obj =
|
|
47
|
+
const obj = makeObject(Organization, TEST_ORG);
|
|
43
48
|
expect(getSchema(obj)).to.deep.eq(Organization);
|
|
44
49
|
});
|
|
45
50
|
|
|
46
51
|
describe('class options', () => {
|
|
47
52
|
test('can assign undefined to partial fields', async () => {
|
|
48
|
-
const person =
|
|
53
|
+
const person = makeObject(Contact, { name: 'John' });
|
|
49
54
|
person.name = undefined;
|
|
50
55
|
person.recordField = 'hello';
|
|
51
56
|
expect(person.name).to.be.undefined;
|
|
@@ -65,13 +70,13 @@ describe('EchoObject class DSL', () => {
|
|
|
65
70
|
);
|
|
66
71
|
|
|
67
72
|
{
|
|
68
|
-
const object =
|
|
73
|
+
const object = makeObject(schema, {});
|
|
69
74
|
(object.meta ??= {}).test = 100;
|
|
70
75
|
expect(object.meta.test).to.eq(100);
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
{
|
|
74
|
-
const object =
|
|
79
|
+
const object = makeObject(schema, {});
|
|
75
80
|
object.meta = { test: { value: 300 } };
|
|
76
81
|
expect(object.meta.test.value).to.eq(300);
|
|
77
82
|
}
|
|
@@ -92,7 +97,7 @@ describe('EchoObject class DSL', () => {
|
|
|
92
97
|
meta: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
93
98
|
}) {}
|
|
94
99
|
|
|
95
|
-
const object =
|
|
100
|
+
const object = makeObject(Test2, {});
|
|
96
101
|
(object.meta ??= {}).test = 100;
|
|
97
102
|
expect(object.meta.test).to.eq(100);
|
|
98
103
|
}
|
|
@@ -7,14 +7,15 @@ import { describe, expect, test } from 'vitest';
|
|
|
7
7
|
|
|
8
8
|
import { DXN, ObjectId } from '@dxos/keys';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { EchoObjectSchema, getObjectDXN } from '../entities';
|
|
11
|
+
import { createObject } from '../object';
|
|
11
12
|
|
|
12
13
|
import { Ref, getReferenceAst } from './ref';
|
|
13
14
|
|
|
14
15
|
const Task = Schema.Struct({
|
|
15
16
|
title: Schema.optional(Schema.String),
|
|
16
17
|
}).pipe(
|
|
17
|
-
|
|
18
|
+
EchoObjectSchema({
|
|
18
19
|
typename: 'example.com/type/Task',
|
|
19
20
|
version: '0.1.0',
|
|
20
21
|
}),
|
|
@@ -27,7 +28,7 @@ const Contact = Schema.Struct({
|
|
|
27
28
|
email: Schema.optional(Schema.String),
|
|
28
29
|
tasks: Schema.mutable(Schema.Array(Ref(Task))),
|
|
29
30
|
}).pipe(
|
|
30
|
-
|
|
31
|
+
EchoObjectSchema({
|
|
31
32
|
typename: 'example.com/type/Person',
|
|
32
33
|
version: '0.1.0',
|
|
33
34
|
}),
|
|
@@ -49,8 +50,8 @@ describe('Ref', () => {
|
|
|
49
50
|
|
|
50
51
|
// TODO(dmaretskyi): Figure out how to expose this in the API.
|
|
51
52
|
test.skip('encode with inlined target', () => {
|
|
52
|
-
const task =
|
|
53
|
-
const contact =
|
|
53
|
+
const task = createObject(Task, { title: 'Fix bugs' });
|
|
54
|
+
const contact = createObject(Contact, { name: 'John Doe', tasks: [Ref.make(task)] });
|
|
54
55
|
|
|
55
56
|
const json = JSON.parse(JSON.stringify(contact));
|
|
56
57
|
expect(json).toEqual({
|
|
@@ -70,8 +71,8 @@ describe('Ref', () => {
|
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
test('encode without inlining target', () => {
|
|
73
|
-
const task =
|
|
74
|
-
const contact =
|
|
74
|
+
const task = createObject(Task, { title: 'Fix bugs' });
|
|
75
|
+
const contact = createObject(Contact, { name: 'John Doe', tasks: [Ref.make(task).noInline()] });
|
|
75
76
|
|
|
76
77
|
const json = JSON.parse(JSON.stringify(contact));
|
|
77
78
|
expect(json).toEqual({
|
package/src/internal/ref/ref.ts
CHANGED
|
@@ -13,16 +13,15 @@ import { compositeRuntime } from '@dxos/echo-signals/runtime';
|
|
|
13
13
|
import { assertArgument, invariant } from '@dxos/invariant';
|
|
14
14
|
import { DXN, ObjectId } from '@dxos/keys';
|
|
15
15
|
|
|
16
|
-
import { ReferenceAnnotationId, getSchemaDXN, getTypeAnnotation, getTypeIdentifierAnnotation } from '../
|
|
16
|
+
import { ReferenceAnnotationId, getSchemaDXN, getTypeAnnotation, getTypeIdentifierAnnotation } from '../annotations';
|
|
17
17
|
import { type JsonSchemaType } from '../json-schema';
|
|
18
|
-
import type {
|
|
18
|
+
import type { AnyProperties, WithId } from '../types';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* The `$id` and `$ref` fields for an ECHO reference schema.
|
|
22
22
|
*/
|
|
23
23
|
export const JSON_SCHEMA_ECHO_REF_ID = '/schemas/echo/ref';
|
|
24
24
|
|
|
25
|
-
// TODO(burdon): Define return type.
|
|
26
25
|
export const getSchemaReference = (property: JsonSchemaType): { typename: string } | undefined => {
|
|
27
26
|
const { $id, reference: { schema: { $ref } = {} } = {} } = property;
|
|
28
27
|
if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {
|
|
@@ -71,16 +70,18 @@ export const RefTypeId: unique symbol = Symbol('@dxos/echo/internal/Ref');
|
|
|
71
70
|
/**
|
|
72
71
|
* Reference Schema.
|
|
73
72
|
*/
|
|
74
|
-
export interface
|
|
73
|
+
export interface RefSchema<T extends WithId> extends Schema.SchemaClass<Ref<T>, EncodedReference> {}
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Type of the `Ref` function and extra methods attached to it.
|
|
77
|
+
*/
|
|
77
78
|
export interface RefFn {
|
|
78
|
-
<S extends Schema.Schema.Any>(schema: S):
|
|
79
|
+
<S extends Schema.Schema.Any>(schema: S): RefSchema<Schema.Schema.Type<S>>;
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
82
|
* @returns True if the object is a reference.
|
|
82
83
|
*/
|
|
83
|
-
isRef: (obj:
|
|
84
|
+
isRef: (obj: unknown) => obj is Ref<any>;
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* @returns True if the reference points to the given object id.
|
|
@@ -90,7 +91,7 @@ export interface RefFn {
|
|
|
90
91
|
/**
|
|
91
92
|
* @returns True if the schema is a reference schema.
|
|
92
93
|
*/
|
|
93
|
-
isRefSchema: (schema: Schema.Schema<any, any>) => schema is
|
|
94
|
+
isRefSchema: (schema: Schema.Schema<any, any>) => schema is RefSchema<any>;
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* @returns True if the schema AST is a reference schema.
|
|
@@ -100,7 +101,7 @@ export interface RefFn {
|
|
|
100
101
|
/**
|
|
101
102
|
* Constructs a reference that points to the given object.
|
|
102
103
|
*/
|
|
103
|
-
// TODO(burdon):
|
|
104
|
+
// TODO(burdon): Narrow to Obj.Any?
|
|
104
105
|
make: <T extends WithId>(object: T) => Ref<T>;
|
|
105
106
|
|
|
106
107
|
/**
|
|
@@ -108,10 +109,11 @@ export interface RefFn {
|
|
|
108
109
|
*/
|
|
109
110
|
fromDXN: (dxn: DXN) => Ref<any>;
|
|
110
111
|
}
|
|
112
|
+
|
|
111
113
|
/**
|
|
112
114
|
* Schema builder for references.
|
|
113
115
|
*/
|
|
114
|
-
export const Ref: RefFn = <S extends Schema.Schema.Any>(schema: S):
|
|
116
|
+
export const Ref: RefFn = <S extends Schema.Schema.Any>(schema: S): RefSchema<Schema.Schema.Type<S>> => {
|
|
115
117
|
assertArgument(Schema.isSchema(schema), 'schema', 'Must call with an instance of effect-schema');
|
|
116
118
|
|
|
117
119
|
const annotation = getTypeAnnotation(schema);
|
|
@@ -201,7 +203,7 @@ Ref.isRef = (obj: any): obj is Ref<any> => {
|
|
|
201
203
|
|
|
202
204
|
Ref.hasObjectId = (id: ObjectId) => (ref: Ref<any>) => ref.dxn.isLocalObjectId() && ref.dxn.parts[1] === id;
|
|
203
205
|
|
|
204
|
-
Ref.isRefSchema = (schema: Schema.Schema<any, any>): schema is
|
|
206
|
+
Ref.isRefSchema = (schema: Schema.Schema<any, any>): schema is RefSchema<any> => {
|
|
205
207
|
return Ref.isRefSchemaAST(schema.ast);
|
|
206
208
|
};
|
|
207
209
|
|
|
@@ -209,7 +211,7 @@ Ref.isRefSchemaAST = (ast: SchemaAST.AST): boolean => {
|
|
|
209
211
|
return SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome);
|
|
210
212
|
};
|
|
211
213
|
|
|
212
|
-
Ref.make = <T extends
|
|
214
|
+
Ref.make = <T extends AnyProperties>(obj: T): Ref<T> => {
|
|
213
215
|
if (typeof obj !== 'object' || obj === null) {
|
|
214
216
|
throw new TypeError('Expected: ECHO object.');
|
|
215
217
|
}
|
|
@@ -242,7 +244,7 @@ export const createEchoReferenceSchema = (
|
|
|
242
244
|
echoId: string | undefined,
|
|
243
245
|
typename: string | undefined,
|
|
244
246
|
version: string | undefined,
|
|
245
|
-
schemaName?: string,
|
|
247
|
+
schemaName?: string, // TODO(burdon): Not used.
|
|
246
248
|
): Schema.SchemaClass<Ref<any>, EncodedReference> => {
|
|
247
249
|
if (!echoId && !typename) {
|
|
248
250
|
throw new TypeError('Either echoId or typename must be provided.');
|
|
@@ -315,12 +317,12 @@ export interface RefResolver {
|
|
|
315
317
|
* @param load If true the resolver should attempt to load the object from disk.
|
|
316
318
|
* @param onLoad Callback to call when the object is loaded.
|
|
317
319
|
*/
|
|
318
|
-
resolveSync(dxn: DXN, load: boolean, onLoad?: () => void):
|
|
320
|
+
resolveSync(dxn: DXN, load: boolean, onLoad?: () => void): AnyProperties | undefined;
|
|
319
321
|
|
|
320
322
|
/**
|
|
321
323
|
* Resolver ref asynchronously.
|
|
322
324
|
*/
|
|
323
|
-
resolve(dxn: DXN): Promise<
|
|
325
|
+
resolve(dxn: DXN): Promise<AnyProperties | undefined>;
|
|
324
326
|
|
|
325
327
|
// TODO(dmaretskyi): Combine with `resolve`.
|
|
326
328
|
resolveSchema(dxn: DXN): Promise<Schema.Schema.AnyNoContext | undefined>;
|
|
@@ -432,6 +434,7 @@ export class RefImpl<T> implements Ref<T> {
|
|
|
432
434
|
|
|
433
435
|
/**
|
|
434
436
|
* Internal method to set the resolver.
|
|
437
|
+
*
|
|
435
438
|
* @internal
|
|
436
439
|
*/
|
|
437
440
|
_setResolver(resolver: RefResolver): void {
|
|
@@ -441,6 +444,7 @@ export class RefImpl<T> implements Ref<T> {
|
|
|
441
444
|
/**
|
|
442
445
|
* Internal method to get the saved target.
|
|
443
446
|
* Not the same as `target` which is resolved from the resolver.
|
|
447
|
+
*
|
|
444
448
|
* @internal
|
|
445
449
|
*/
|
|
446
450
|
_getSavedTarget(): T | undefined {
|
|
@@ -459,7 +463,7 @@ export const setRefResolver = (ref: Ref<any>, resolver: RefResolver) => {
|
|
|
459
463
|
/**
|
|
460
464
|
* Internal API for getting the saved target on a reference.
|
|
461
465
|
*/
|
|
462
|
-
export const getRefSavedTarget = (ref: Ref<any>):
|
|
466
|
+
export const getRefSavedTarget = (ref: Ref<any>): AnyProperties | undefined => {
|
|
463
467
|
invariant(ref instanceof RefImpl, 'Ref is not an instance of RefImpl');
|
|
464
468
|
return ref._getSavedTarget();
|
|
465
469
|
};
|
|
@@ -482,10 +486,10 @@ export const refFromEncodedReference = (encodedReference: EncodedReference, reso
|
|
|
482
486
|
};
|
|
483
487
|
|
|
484
488
|
export class StaticRefResolver implements RefResolver {
|
|
485
|
-
public objects = new Map<ObjectId,
|
|
489
|
+
public objects = new Map<ObjectId, AnyProperties>();
|
|
486
490
|
public schemas = new Map<DXN.String, Schema.Schema.AnyNoContext>();
|
|
487
491
|
|
|
488
|
-
addObject(obj:
|
|
492
|
+
addObject(obj: AnyProperties): this {
|
|
489
493
|
this.objects.set(obj.id, obj);
|
|
490
494
|
return this;
|
|
491
495
|
}
|
|
@@ -497,7 +501,7 @@ export class StaticRefResolver implements RefResolver {
|
|
|
497
501
|
return this;
|
|
498
502
|
}
|
|
499
503
|
|
|
500
|
-
resolveSync(dxn: DXN, _load: boolean, _onLoad?: () => void):
|
|
504
|
+
resolveSync(dxn: DXN, _load: boolean, _onLoad?: () => void): AnyProperties | undefined {
|
|
501
505
|
const id = dxn?.asEchoDXN()?.echoId;
|
|
502
506
|
if (id == null) {
|
|
503
507
|
return undefined;
|
|
@@ -506,7 +510,7 @@ export class StaticRefResolver implements RefResolver {
|
|
|
506
510
|
return this.objects.get(id);
|
|
507
511
|
}
|
|
508
512
|
|
|
509
|
-
async resolve(dxn: DXN): Promise<
|
|
513
|
+
async resolve(dxn: DXN): Promise<AnyProperties | undefined> {
|
|
510
514
|
const id = dxn?.asEchoDXN()?.echoId;
|
|
511
515
|
if (id == null) {
|
|
512
516
|
return undefined;
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import { FieldPath } from '../
|
|
9
|
-
import { FormatAnnotation,
|
|
10
|
-
import { toJsonSchema } from '../json';
|
|
11
|
-
import { ECHO_ANNOTATIONS_NS_KEY } from '../json-schema';
|
|
8
|
+
import { FieldPath } from '../annotations';
|
|
9
|
+
import { FormatAnnotation, TypeFormat } from '../formats';
|
|
10
|
+
import { ECHO_ANNOTATIONS_NS_KEY, toJsonSchema } from '../json-schema';
|
|
12
11
|
import { TypedObject } from '../object';
|
|
13
12
|
|
|
14
13
|
import { composeSchema } from './compose';
|
|
@@ -21,7 +20,7 @@ describe('schema composition', () => {
|
|
|
21
20
|
}) {}
|
|
22
21
|
|
|
23
22
|
const OverlaySchema = Schema.Struct({
|
|
24
|
-
email: Schema.String.pipe(FieldPath('$.email'), FormatAnnotation.set(
|
|
23
|
+
email: Schema.String.pipe(FieldPath('$.email'), FormatAnnotation.set(TypeFormat.Email)),
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
const baseSchema = toJsonSchema(BaseType);
|
|
@@ -30,7 +29,7 @@ describe('schema composition', () => {
|
|
|
30
29
|
expect(composedSchema.properties).to.deep.eq({
|
|
31
30
|
email: {
|
|
32
31
|
type: 'string',
|
|
33
|
-
format:
|
|
32
|
+
format: TypeFormat.Email,
|
|
34
33
|
// TODO(dmaretskyi): Should use the new field.
|
|
35
34
|
[ECHO_ANNOTATIONS_NS_KEY]: {
|
|
36
35
|
meta: {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { invariant } from '@dxos/invariant';
|
|
6
6
|
|
|
7
7
|
import { type JsonSchemaType } from '../json-schema';
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
import { getSnapshot } from './snapshot';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Creates a composite schema from the source and projection schemas.
|
|
@@ -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';
|
|
@@ -8,7 +8,7 @@ import * as SchemaAST from 'effect/SchemaAST';
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { DXN } from '@dxos/keys';
|
|
10
10
|
|
|
11
|
-
import { type TypeAnnotation, TypeAnnotationId, TypeIdentifierAnnotationId } from '../
|
|
11
|
+
import { type TypeAnnotation, TypeAnnotationId, TypeIdentifierAnnotationId } from '../annotations';
|
|
12
12
|
|
|
13
13
|
// TODO(ZaymonFC): Do this one at a time. This might be dangerous.
|
|
14
14
|
export const addFieldsToSchema = (
|
|
@@ -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
|
+
};
|