@dxos/echo 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a
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-HKFCK2GL.mjs +175 -0
- package/dist/lib/browser/chunk-HKFCK2GL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-MTR3E5S2.mjs → chunk-MAAYELT7.mjs} +501 -457
- package/dist/lib/browser/chunk-MAAYELT7.mjs.map +7 -0
- package/dist/lib/browser/chunk-MB6MMNFP.mjs +3857 -0
- package/dist/lib/browser/chunk-MB6MMNFP.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +14 -5
- package/dist/lib/browser/internal/index.mjs +332 -0
- package/dist/lib/browser/internal/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/query/index.mjs +15 -0
- package/dist/lib/browser/query/index.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +260 -32
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-MYZLAJSR.mjs → chunk-5NWDGIBT.mjs} +501 -457
- package/dist/lib/node-esm/chunk-5NWDGIBT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-AUAH4E2J.mjs +175 -0
- package/dist/lib/node-esm/chunk-AUAH4E2J.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-BQRA4VLX.mjs +3857 -0
- package/dist/lib/node-esm/chunk-BQRA4VLX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +14 -5
- package/dist/lib/node-esm/internal/index.mjs +332 -0
- package/dist/lib/node-esm/internal/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/query/index.mjs +15 -0
- package/dist/lib/node-esm/query/index.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +260 -32
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Obj.d.ts +22 -5
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +1 -1
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +5 -4
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +16 -17
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +72 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/ast/annotation-helper.d.ts +8 -0
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +1 -0
- package/dist/types/src/internal/ast/annotations.d.ts +125 -0
- package/dist/types/src/internal/ast/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/ast/annotations.test.d.ts +2 -0
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/ast/entity-kind.d.ts +10 -0
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +1 -0
- package/dist/types/src/internal/ast/index.d.ts +5 -0
- package/dist/types/src/internal/ast/index.d.ts.map +1 -0
- package/dist/types/src/internal/ast/types.d.ts +6 -0
- package/dist/types/src/internal/ast/types.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.d.ts +63 -0
- package/dist/types/src/internal/formats/date.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.test.d.ts +2 -0
- package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +30 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.test.d.ts +2 -0
- package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/index.d.ts +8 -0
- package/dist/types/src/internal/formats/index.d.ts.map +1 -0
- package/dist/types/src/internal/formats/number.d.ts +31 -0
- package/dist/types/src/internal/formats/number.d.ts.map +1 -0
- package/dist/types/src/internal/formats/object.d.ts +35 -0
- package/dist/types/src/internal/formats/object.d.ts.map +1 -0
- package/dist/types/src/internal/formats/select.d.ts +11 -0
- package/dist/types/src/internal/formats/select.d.ts.map +1 -0
- package/dist/types/src/internal/formats/string.d.ts +38 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -0
- package/dist/types/src/internal/formats/types.d.ts +68 -0
- package/dist/types/src/internal/formats/types.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +15 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/json/annotations.d.ts +19 -0
- package/dist/types/src/internal/json/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json/effect-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json/index.d.ts +2 -0
- package/dist/types/src/internal/json/index.d.ts.map +1 -0
- package/dist/types/src/internal/json/json-schema.d.ts +28 -0
- package/dist/types/src/internal/json/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json/json-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +3 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/object/accessors.d.ts +37 -0
- package/dist/types/src/internal/object/accessors.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts +18 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -0
- package/dist/types/src/internal/object/create.d.ts +40 -0
- package/dist/types/src/internal/object/create.d.ts.map +1 -0
- package/dist/types/src/internal/object/create.test.d.ts +2 -0
- package/dist/types/src/internal/object/create.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +6 -0
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/object/entity.d.ts +33 -0
- package/dist/types/src/internal/object/entity.d.ts.map +1 -0
- package/dist/types/src/internal/object/expando.d.ts +14 -0
- package/dist/types/src/internal/object/expando.d.ts.map +1 -0
- package/dist/types/src/internal/object/ids.d.ts +6 -0
- package/dist/types/src/internal/object/ids.d.ts.map +1 -0
- package/dist/types/src/internal/object/index.d.ts +16 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -0
- package/dist/types/src/internal/object/inspect.d.ts +2 -0
- package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.d.ts +32 -0
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/meta.d.ts +31 -0
- package/dist/types/src/internal/object/meta.d.ts.map +1 -0
- package/dist/types/src/internal/object/model.d.ts +117 -0
- package/dist/types/src/internal/object/model.d.ts.map +1 -0
- package/dist/types/src/internal/object/relation.d.ts +17 -0
- package/dist/types/src/internal/object/relation.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.d.ts +15 -0
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.d.ts +31 -0
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/typename.d.ts +15 -0
- package/dist/types/src/internal/object/typename.d.ts.map +1 -0
- package/dist/types/src/internal/object/version.d.ts +14 -0
- package/dist/types/src/internal/object/version.d.ts.map +1 -0
- package/dist/types/src/internal/projection/compose.d.ts +6 -0
- package/dist/types/src/internal/projection/compose.d.ts.map +1 -0
- package/dist/types/src/internal/projection/compose.test.d.ts +2 -0
- package/dist/types/src/internal/projection/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/projection/index.d.ts +2 -0
- package/dist/types/src/internal/projection/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive-object.d.ts +15 -0
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +44 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/query/index.d.ts +2 -0
- package/dist/types/src/internal/query/index.d.ts.map +1 -0
- package/dist/types/src/internal/query/query.d.ts +17 -0
- package/dist/types/src/internal/query/query.d.ts.map +1 -0
- package/dist/types/src/internal/ref/index.d.ts +3 -0
- package/dist/types/src/internal/ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.d.ts +206 -0
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
- package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +168 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/index.d.ts +7 -0
- package/dist/types/src/internal/schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +18 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -0
- package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
- package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/schema/stored-schema.d.ts +13 -0
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +1 -0
- package/dist/types/src/internal/testing/index.d.ts +3 -0
- package/dist/types/src/internal/testing/index.d.ts.map +1 -0
- package/dist/types/src/internal/testing/types.d.ts +455 -0
- package/dist/types/src/internal/testing/types.d.ts.map +1 -0
- package/dist/types/src/internal/testing/utils.d.ts +10 -0
- package/dist/types/src/internal/testing/utils.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +3 -0
- package/dist/types/src/internal/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/types/types.d.ts +79 -0
- package/dist/types/src/internal/types/types.d.ts.map +1 -0
- package/dist/types/src/internal/types/types.test.d.ts +2 -0
- package/dist/types/src/internal/types/types.test.d.ts.map +1 -0
- package/dist/types/src/internal/types/util.d.ts +5 -0
- package/dist/types/src/internal/types/util.d.ts.map +1 -0
- package/dist/types/src/query/index.d.ts +2 -1
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/query/{dsl.d.ts → query.d.ts} +34 -24
- package/dist/types/src/query/query.d.ts.map +1 -0
- package/dist/types/src/query/query.test.d.ts +2 -0
- package/dist/types/src/query/query.test.d.ts.map +1 -0
- package/dist/types/src/query/tag.d.ts +17 -0
- package/dist/types/src/query/tag.d.ts.map +1 -0
- package/dist/types/src/testing/echo-schema.d.ts +7 -0
- package/dist/types/src/testing/echo-schema.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +18 -18
- package/dist/types/src/testing/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -17
- package/src/Obj.ts +77 -12
- package/src/Ref.ts +1 -2
- package/src/Relation.ts +15 -5
- package/src/Type.ts +29 -30
- package/src/errors.ts +18 -0
- package/src/index.ts +4 -2
- package/src/internal/ast/annotation-helper.ts +22 -0
- package/src/internal/ast/annotations.test.ts +98 -0
- package/src/internal/ast/annotations.ts +219 -0
- package/src/internal/ast/entity-kind.ts +15 -0
- package/src/internal/ast/index.ts +8 -0
- package/src/internal/ast/types.ts +17 -0
- package/src/internal/formats/date.test.ts +56 -0
- package/src/internal/formats/date.ts +217 -0
- package/src/internal/formats/format.test.ts +77 -0
- package/src/internal/formats/format.ts +52 -0
- package/src/internal/formats/index.ts +12 -0
- package/src/internal/formats/number.ts +89 -0
- package/src/internal/formats/object.ts +80 -0
- package/src/internal/formats/select.ts +16 -0
- package/src/internal/formats/string.ts +76 -0
- package/src/internal/formats/types.ts +175 -0
- package/src/internal/index.ts +22 -0
- package/src/internal/json/annotations.ts +50 -0
- package/src/internal/json/effect-schema.test.ts +143 -0
- package/src/internal/json/index.ts +5 -0
- package/src/internal/json/json-schema.test.ts +857 -0
- package/src/internal/json/json-schema.ts +519 -0
- package/src/internal/json-schema/index.ts +6 -0
- package/src/internal/json-schema/json-schema-normalize.ts +109 -0
- package/src/internal/json-schema/json-schema-type.ts +403 -0
- package/src/internal/object/accessors.ts +153 -0
- package/src/internal/object/common.ts +76 -0
- package/src/internal/object/create.test.ts +118 -0
- package/src/internal/object/create.ts +96 -0
- package/src/internal/object/deleted.ts +19 -0
- package/src/internal/object/entity.ts +248 -0
- package/src/internal/object/expando.ts +21 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +19 -0
- package/src/internal/object/inspect.ts +48 -0
- package/src/internal/object/json-serializer.test.ts +99 -0
- package/src/internal/object/json-serializer.ts +225 -0
- package/src/internal/object/meta.ts +61 -0
- package/src/internal/object/model.ts +170 -0
- package/src/internal/object/relation.ts +24 -0
- package/src/internal/object/schema-validator.test.ts +186 -0
- package/src/internal/object/schema-validator.ts +241 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +88 -0
- package/src/internal/object/typename.ts +61 -0
- package/src/internal/object/version.ts +22 -0
- package/src/internal/projection/compose.test.ts +43 -0
- package/src/internal/projection/compose.ts +36 -0
- package/src/internal/projection/index.ts +5 -0
- package/src/internal/proxy/handler.test.ts +163 -0
- package/src/internal/proxy/reactive-object.ts +108 -0
- package/src/internal/proxy/schema.test.ts +136 -0
- package/src/internal/proxy/typed-handler.test.ts +102 -0
- package/src/internal/proxy/typed-handler.ts +228 -0
- package/src/internal/proxy/typed-object.test.ts +100 -0
- package/src/internal/query/index.ts +5 -0
- package/src/internal/query/query.ts +23 -0
- package/src/internal/ref/index.ts +6 -0
- package/src/internal/ref/ref-array.ts +39 -0
- package/src/internal/ref/ref.test.ts +100 -0
- package/src/internal/ref/ref.ts +521 -0
- package/src/internal/schema/echo-schema.ts +383 -0
- package/src/internal/schema/index.ts +10 -0
- package/src/internal/schema/manipulation.ts +92 -0
- package/src/internal/schema/runtime-schema-registry.ts +78 -0
- package/src/internal/schema/snapshot.ts +25 -0
- package/src/internal/schema/stored-schema.ts +26 -0
- package/src/internal/testing/index.ts +6 -0
- package/src/internal/testing/types.ts +211 -0
- package/src/internal/testing/utils.ts +54 -0
- package/src/internal/types/index.ts +6 -0
- package/src/internal/types/types.test.ts +48 -0
- package/src/internal/types/types.ts +176 -0
- package/src/internal/types/util.ts +9 -0
- package/src/query/index.ts +2 -1
- package/src/query/query.test.ts +401 -0
- package/src/query/{dsl.ts → query.ts} +131 -46
- package/src/query/tag.ts +37 -0
- package/src/test/api.test.ts +9 -9
- package/src/testing/echo-schema.ts +39 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/types.ts +1 -1
- package/dist/lib/browser/chunk-MTR3E5S2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MYZLAJSR.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
- package/src/query/dsl.test.ts +0 -332
|
@@ -0,0 +1,383 @@
|
|
|
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 { invariant } from '@dxos/invariant';
|
|
9
|
+
import { type ObjectId } from '@dxos/keys';
|
|
10
|
+
|
|
11
|
+
import { type SchemaMeta, SchemaMetaSymbol, type TypeAnnotation, getTypeAnnotation } from '../ast';
|
|
12
|
+
import { toEffectSchema, toJsonSchema } from '../json';
|
|
13
|
+
import { type JsonSchemaType } from '../json-schema';
|
|
14
|
+
import { type TypedObject, type TypedObjectPrototype } from '../object';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
addFieldsToSchema,
|
|
18
|
+
removeFieldsFromSchema,
|
|
19
|
+
setTypenameInSchema,
|
|
20
|
+
updateFieldNameInSchema,
|
|
21
|
+
updateFieldsInSchema,
|
|
22
|
+
} from './manipulation';
|
|
23
|
+
import { getSnapshot } from './snapshot';
|
|
24
|
+
import { StoredSchema } from './stored-schema';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Base schema type.
|
|
28
|
+
*/
|
|
29
|
+
// TODO(burdon): Merge with ImmutableSchema.
|
|
30
|
+
export interface BaseSchema<A = any, I = any> extends TypedObject<A, I> {
|
|
31
|
+
get readonly(): boolean;
|
|
32
|
+
// TODO(burdon): Change to external function.
|
|
33
|
+
get mutable(): EchoSchema<A, I>;
|
|
34
|
+
get snapshot(): Schema.Schema<A, I>;
|
|
35
|
+
get jsonSchema(): JsonSchemaType;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Immutable schema type.
|
|
40
|
+
* @deprecated Use `Schema.Schema.AnyNoContext` instead.
|
|
41
|
+
*/
|
|
42
|
+
// TODO(burdon): Common abstract base class?
|
|
43
|
+
export class ImmutableSchema<A = any, I = any> implements BaseSchema<A, I> {
|
|
44
|
+
private readonly _objectAnnotation: TypeAnnotation;
|
|
45
|
+
constructor(private readonly _schema: Schema.Schema<A, I>) {
|
|
46
|
+
this._objectAnnotation = getTypeAnnotation(this._schema)!;
|
|
47
|
+
invariant(this._objectAnnotation);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//
|
|
51
|
+
// Effect Schema (push to abstract base class).
|
|
52
|
+
//
|
|
53
|
+
|
|
54
|
+
public get [Schema.TypeId]() {
|
|
55
|
+
return schemaVariance;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get Type() {
|
|
59
|
+
return this._schema.Type;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public get Encoded() {
|
|
63
|
+
return this._schema.Encoded;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public get Context() {
|
|
67
|
+
return this._schema.Context;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public get ast(): SchemaAST.AST {
|
|
71
|
+
return this._schema.ast;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public get annotations() {
|
|
75
|
+
return this._schema.annotations;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public get pipe() {
|
|
79
|
+
return this._schema.pipe;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//
|
|
83
|
+
// TypedObject
|
|
84
|
+
//
|
|
85
|
+
|
|
86
|
+
get typename(): string {
|
|
87
|
+
return this._objectAnnotation.typename;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get version(): string {
|
|
91
|
+
return this._objectAnnotation.version;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//
|
|
95
|
+
// BaseSchema
|
|
96
|
+
//
|
|
97
|
+
|
|
98
|
+
get readonly(): boolean {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get snapshot(): Schema.Schema.AnyNoContext {
|
|
103
|
+
return this._schema;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// TODO(burdon): Change from getter since this is expensive.
|
|
107
|
+
get jsonSchema(): JsonSchemaType {
|
|
108
|
+
return toJsonSchema(this._schema);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get mutable(): EchoSchema {
|
|
112
|
+
throw new Error('Schema is readonly.');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Defines an effect-schema for the `EchoSchema` type.
|
|
118
|
+
*
|
|
119
|
+
* This is here so that `EchoSchema` class can be used as a part of another schema definition (e.g., `ref(EchoSchema)`).
|
|
120
|
+
*/
|
|
121
|
+
const EchoSchemaConstructor = (): TypedObjectPrototype => {
|
|
122
|
+
/**
|
|
123
|
+
* Return class definition satisfying Schema.Schema.
|
|
124
|
+
*/
|
|
125
|
+
return class {
|
|
126
|
+
private static get _schema() {
|
|
127
|
+
// The field is DynamicEchoSchema in runtime, but is serialized as StoredEchoSchema in automerge.
|
|
128
|
+
return Schema.Union(StoredSchema, Schema.instanceOf(EchoSchema)).annotations(StoredSchema.ast.annotations);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static readonly [Schema.TypeId] = schemaVariance;
|
|
132
|
+
|
|
133
|
+
static get ast() {
|
|
134
|
+
const schema = this._schema;
|
|
135
|
+
return schema.ast;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static get annotations() {
|
|
139
|
+
const schema = this._schema;
|
|
140
|
+
return schema.annotations.bind(schema);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static get pipe() {
|
|
144
|
+
const schema = this._schema;
|
|
145
|
+
return schema.pipe.bind(schema);
|
|
146
|
+
}
|
|
147
|
+
} as any;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const isMutable = (schema: Schema.Schema.AnyNoContext): schema is EchoSchema => {
|
|
151
|
+
return schema instanceof EchoSchema;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// NOTE: Keep in this file.
|
|
155
|
+
const schemaVariance = {
|
|
156
|
+
_A: (_: any) => _,
|
|
157
|
+
_I: (_: any) => _,
|
|
158
|
+
_R: (_: never) => _,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Represents a schema that is stored in the ECHO database.
|
|
163
|
+
* Schema can me mutable or readonly (specified by the {@link EchoSchema.readonly} field).
|
|
164
|
+
*
|
|
165
|
+
* Schema that can be modified at runtime via the API.
|
|
166
|
+
* Is an instance of effect-schema (`Schema.Schema.AnyNoContext`) so it can be used in the same way as a regular schema.
|
|
167
|
+
* IMPORTANT: The schema AST will change reactively when the schema is updated, including synced updates from remote peers.
|
|
168
|
+
*
|
|
169
|
+
* The class constructor is a schema instance itself, and can be used in the echo object definitions:
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* export class TableType extends Schema.Struct({...}).pipe(Type.Obj({ typename: 'example.org/type/Table', version: '0.1.0' })){
|
|
174
|
+
* title: Schema.String,
|
|
175
|
+
* schema: Schema.optional(ref(EchoSchema)),
|
|
176
|
+
* props: Schema.mutable(S.Array(TablePropSchema)),
|
|
177
|
+
* }) {}
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* The ECHO API will translate any references to StoredSchema objects to be resolved as EchoSchema objects.
|
|
181
|
+
*/
|
|
182
|
+
export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implements BaseSchema<A, I> {
|
|
183
|
+
private _schema: Schema.Schema.AnyNoContext | undefined;
|
|
184
|
+
private _isDirty = true;
|
|
185
|
+
|
|
186
|
+
constructor(private readonly _storedSchema: StoredSchema) {
|
|
187
|
+
super();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
//
|
|
191
|
+
// Effect Schema (push to abstract base class).
|
|
192
|
+
//
|
|
193
|
+
|
|
194
|
+
public get [Schema.TypeId]() {
|
|
195
|
+
return schemaVariance;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public get Type() {
|
|
199
|
+
return this._storedSchema as A;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public get Encoded() {
|
|
203
|
+
return this._storedSchema as I;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public get Context() {
|
|
207
|
+
const schema = this._getSchema();
|
|
208
|
+
return schema.Context;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
public get ast() {
|
|
212
|
+
const schema = this._getSchema();
|
|
213
|
+
return schema.ast;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public get annotations() {
|
|
217
|
+
const schema = this._getSchema();
|
|
218
|
+
return schema.annotations.bind(schema);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public get pipe(): Schema.Schema.AnyNoContext['pipe'] {
|
|
222
|
+
const schema = this._getSchema();
|
|
223
|
+
return schema.pipe.bind(schema);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
//
|
|
227
|
+
// BaseSchema
|
|
228
|
+
//
|
|
229
|
+
|
|
230
|
+
public get typename(): string {
|
|
231
|
+
return this._storedSchema.typename;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public get version(): string {
|
|
235
|
+
return this._storedSchema.version;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public get readonly(): boolean {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Returns an immutable schema snapshot of the current state of the schema.
|
|
244
|
+
*/
|
|
245
|
+
public get snapshot(): Schema.Schema.AnyNoContext {
|
|
246
|
+
return this._getSchema();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @reactive
|
|
251
|
+
*/
|
|
252
|
+
public get jsonSchema(): JsonSchemaType {
|
|
253
|
+
return this._storedSchema.jsonSchema;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Returns a mutable schema.
|
|
258
|
+
*/
|
|
259
|
+
public get mutable(): EchoSchema {
|
|
260
|
+
invariant(!this.readonly, 'Schema is not mutable');
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
//
|
|
265
|
+
// Mutable Schema
|
|
266
|
+
//
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Id of the ECHO object containing the schema.
|
|
270
|
+
*/
|
|
271
|
+
public get id(): ObjectId {
|
|
272
|
+
return this._storedSchema.id;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Short name of the schema.
|
|
277
|
+
*/
|
|
278
|
+
public get name(): string | undefined {
|
|
279
|
+
return this._storedSchema.name;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public get [SchemaMetaSymbol](): SchemaMeta {
|
|
283
|
+
return { id: this.id, typename: this.typename, version: this._storedSchema.version };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Reference to the underlying stored schema object.
|
|
288
|
+
*/
|
|
289
|
+
public get storedSchema(): StoredSchema {
|
|
290
|
+
return this._storedSchema;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
public getProperties(): SchemaAST.PropertySignature[] {
|
|
294
|
+
const ast = this._getSchema().ast;
|
|
295
|
+
invariant(SchemaAST.isTypeLiteral(ast));
|
|
296
|
+
return [...ast.propertySignatures].filter((p) => p.name !== 'id').map(unwrapOptionality);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
//
|
|
300
|
+
// Mutation methods.
|
|
301
|
+
// TODO(burdon): Create separate interface for dynamic schema.
|
|
302
|
+
// TODO(burdon): Deprecate direct manipulation? Use JSONSchema directly.
|
|
303
|
+
//
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @throws Error if the schema is readonly.
|
|
307
|
+
*/
|
|
308
|
+
public updateTypename(typename: string): void {
|
|
309
|
+
const updated = setTypenameInSchema(this._getSchema(), typename);
|
|
310
|
+
this._storedSchema.typename = typename;
|
|
311
|
+
this._storedSchema.jsonSchema = toJsonSchema(updated);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @throws Error if the schema is readonly.
|
|
316
|
+
*/
|
|
317
|
+
public addFields(fields: Schema.Struct.Fields): void {
|
|
318
|
+
const extended = addFieldsToSchema(this._getSchema(), fields);
|
|
319
|
+
this._storedSchema.jsonSchema = toJsonSchema(extended);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @throws Error if the schema is readonly.
|
|
324
|
+
*/
|
|
325
|
+
public updateFields(fields: Schema.Struct.Fields): void {
|
|
326
|
+
const updated = updateFieldsInSchema(this._getSchema(), fields);
|
|
327
|
+
this._storedSchema.jsonSchema = toJsonSchema(updated);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* @throws Error if the schema is readonly.
|
|
332
|
+
*/
|
|
333
|
+
public updateFieldPropertyName({ before, after }: { before: PropertyKey; after: PropertyKey }): void {
|
|
334
|
+
const renamed = updateFieldNameInSchema(this._getSchema(), { before, after });
|
|
335
|
+
this._storedSchema.jsonSchema = toJsonSchema(renamed);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* @throws Error if the schema is readonly.
|
|
340
|
+
*/
|
|
341
|
+
public removeFields(fieldNames: string[]): void {
|
|
342
|
+
const removed = removeFieldsFromSchema(this._getSchema(), fieldNames);
|
|
343
|
+
this._storedSchema.jsonSchema = toJsonSchema(removed);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
//
|
|
347
|
+
// Internals
|
|
348
|
+
//
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Called by EchoSchemaRegistry on update.
|
|
352
|
+
*/
|
|
353
|
+
_invalidate(): void {
|
|
354
|
+
this._isDirty = true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Rebuilds this schema if it is dirty.
|
|
359
|
+
*/
|
|
360
|
+
_rebuild(): void {
|
|
361
|
+
if (this._isDirty || this._schema == null) {
|
|
362
|
+
this._schema = toEffectSchema(getSnapshot(this._storedSchema.jsonSchema));
|
|
363
|
+
this._isDirty = false;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private _getSchema(): Schema.Schema.AnyNoContext {
|
|
368
|
+
this._rebuild();
|
|
369
|
+
return this._schema!;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// TODO(burdon): Move to effect.
|
|
374
|
+
const unwrapOptionality = (property: SchemaAST.PropertySignature): SchemaAST.PropertySignature => {
|
|
375
|
+
if (!SchemaAST.isUnion(property.type)) {
|
|
376
|
+
return property;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
...property,
|
|
381
|
+
type: property.type.types.find((type) => !SchemaAST.isUndefinedKeyword(type))!,
|
|
382
|
+
} as any;
|
|
383
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { invariant } from '@dxos/invariant';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
10
|
+
|
|
11
|
+
import { type TypeAnnotation, TypeAnnotationId, TypeIdentifierAnnotationId } from '../ast';
|
|
12
|
+
|
|
13
|
+
// TODO(ZaymonFC): Do this one at a time. This might be dangerous.
|
|
14
|
+
export const addFieldsToSchema = (
|
|
15
|
+
schema: Schema.Schema.AnyNoContext,
|
|
16
|
+
fields: Schema.Struct.Fields,
|
|
17
|
+
): Schema.Schema.AnyNoContext => {
|
|
18
|
+
const schemaExtension = Schema.partial(Schema.Struct(fields));
|
|
19
|
+
return Schema.extend(schema, schemaExtension).annotations(
|
|
20
|
+
schema.ast.annotations,
|
|
21
|
+
) as any as Schema.Schema.AnyNoContext;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const updateFieldsInSchema = (
|
|
25
|
+
schema: Schema.Schema.AnyNoContext,
|
|
26
|
+
fields: Schema.Struct.Fields,
|
|
27
|
+
): Schema.Schema.AnyNoContext => {
|
|
28
|
+
const ast = schema.ast as SchemaAST.TypeLiteral;
|
|
29
|
+
invariant(SchemaAST.isTypeLiteral(ast));
|
|
30
|
+
|
|
31
|
+
const updatedProperties = [...ast.propertySignatures];
|
|
32
|
+
const propertiesToUpdate = (Schema.partial(Schema.Struct(fields)).ast as SchemaAST.TypeLiteral).propertySignatures;
|
|
33
|
+
for (const property of propertiesToUpdate) {
|
|
34
|
+
const index = updatedProperties.findIndex((p) => p.name === property.name);
|
|
35
|
+
if (index !== -1) {
|
|
36
|
+
updatedProperties[index] = property;
|
|
37
|
+
} else {
|
|
38
|
+
updatedProperties.push(property);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return Schema.make(new SchemaAST.TypeLiteral(updatedProperties, ast.indexSignatures, ast.annotations));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const removeFieldsFromSchema = (
|
|
46
|
+
schema: Schema.Schema.AnyNoContext,
|
|
47
|
+
fieldNames: string[],
|
|
48
|
+
): Schema.Schema.AnyNoContext => {
|
|
49
|
+
return Schema.make(SchemaAST.omit(schema.ast, fieldNames)).annotations(schema.ast.annotations);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const updateFieldNameInSchema = (
|
|
53
|
+
schema: Schema.Schema.AnyNoContext,
|
|
54
|
+
{ before, after }: { before: PropertyKey; after: PropertyKey },
|
|
55
|
+
): Schema.Schema.AnyNoContext => {
|
|
56
|
+
const ast = schema.ast as SchemaAST.TypeLiteral;
|
|
57
|
+
invariant(SchemaAST.isTypeLiteral(ast));
|
|
58
|
+
|
|
59
|
+
return Schema.make(
|
|
60
|
+
new SchemaAST.TypeLiteral(
|
|
61
|
+
ast.propertySignatures.map((p) =>
|
|
62
|
+
p.name === before
|
|
63
|
+
? new SchemaAST.PropertySignature(after, p.type, p.isOptional, p.isReadonly, p.annotations)
|
|
64
|
+
: p,
|
|
65
|
+
),
|
|
66
|
+
ast.indexSignatures,
|
|
67
|
+
ast.annotations,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const setTypenameInSchema = (
|
|
73
|
+
schema: Schema.Schema.AnyNoContext,
|
|
74
|
+
typename: string,
|
|
75
|
+
): Schema.Schema.AnyNoContext => {
|
|
76
|
+
const existingAnnotation = schema.ast.annotations[TypeAnnotationId] as TypeAnnotation;
|
|
77
|
+
invariant(existingAnnotation, `Missing ${String(TypeAnnotationId)}`);
|
|
78
|
+
|
|
79
|
+
return schema.annotations({
|
|
80
|
+
...schema.ast.annotations,
|
|
81
|
+
[TypeAnnotationId]: {
|
|
82
|
+
kind: existingAnnotation.kind,
|
|
83
|
+
typename,
|
|
84
|
+
version: existingAnnotation.version,
|
|
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
|
+
},
|
|
91
|
+
});
|
|
92
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { type DXN } from '@dxos/keys';
|
|
10
|
+
import { defaultMap } from '@dxos/util';
|
|
11
|
+
|
|
12
|
+
import { getSchemaTypename, getSchemaVersion } from '../ast';
|
|
13
|
+
|
|
14
|
+
import { StoredSchema } from './stored-schema';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Runtime registry of static schema objects (i.e., not Dynamic .
|
|
18
|
+
*/
|
|
19
|
+
// TODO(burdon): Reconcile with EchoSchemaRegistry.
|
|
20
|
+
export class RuntimeSchemaRegistry {
|
|
21
|
+
private readonly _registry = new Map<string, Schema.Schema.AnyNoContext[]>();
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
this._registry.set(StoredSchema.typename, [StoredSchema]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get schemas(): Schema.Schema.AnyNoContext[] {
|
|
28
|
+
return Array.from(this._registry.values()).flat();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
hasSchema<S extends Schema.Schema.AnyNoContext>(schema: S): boolean {
|
|
32
|
+
const typename = getSchemaTypename(schema);
|
|
33
|
+
const version = getSchemaVersion(schema);
|
|
34
|
+
invariant(typename, 'Invalid schema');
|
|
35
|
+
|
|
36
|
+
const schemas = this._registry.get(typename);
|
|
37
|
+
return schemas?.some((schema) => getSchemaVersion(schema) === version) ?? false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getSchemaByDXN(dxn: DXN): Schema.Schema.AnyNoContext | undefined {
|
|
41
|
+
const components = dxn.asTypeDXN();
|
|
42
|
+
if (!components) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { type, version } = components;
|
|
47
|
+
const allSchemas = this._registry.get(type) ?? [];
|
|
48
|
+
if (version) {
|
|
49
|
+
return allSchemas.find((s) => getSchemaVersion(s) === version);
|
|
50
|
+
} else {
|
|
51
|
+
// If no version is specified, return the earliest version for backwards compatibility.
|
|
52
|
+
// TODO(dmaretskyi): Probably not correct to compare lexicographically, but it's good enough for now.
|
|
53
|
+
return allSchemas.sort((a, b) =>
|
|
54
|
+
(getSchemaVersion(a) ?? '0.0.0').localeCompare(getSchemaVersion(b) ?? '0.0.0'),
|
|
55
|
+
)[0];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use getSchemaByDXN.
|
|
61
|
+
*/
|
|
62
|
+
getSchema(typename: string): Schema.Schema.AnyNoContext | undefined {
|
|
63
|
+
return this._registry.get(typename)?.[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
addSchema(types: Schema.Schema.AnyNoContext[]): void {
|
|
67
|
+
types.forEach((schema) => {
|
|
68
|
+
const typename = getSchemaTypename(schema) ?? raise(new TypeError('Schema has no typename'));
|
|
69
|
+
const version = getSchemaVersion(schema) ?? raise(new TypeError('Schema has no version'));
|
|
70
|
+
const versions = defaultMap(this._registry, typename, () => []);
|
|
71
|
+
if (versions.some((schema) => getSchemaVersion(schema) === version)) {
|
|
72
|
+
throw new Error(`Schema version already registered: ${typename}:${version}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
versions.push(schema);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns a non-reactive snapshot of the given live object.
|
|
7
|
+
* @deprecated Use `getSnapshot` from `@dxos/live-object` instead.
|
|
8
|
+
*/
|
|
9
|
+
// TODO(wittjosiah): Types.
|
|
10
|
+
export const getSnapshot = (object: any): any => {
|
|
11
|
+
if (typeof object !== 'object') {
|
|
12
|
+
return object;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(object)) {
|
|
16
|
+
return object.map(getSnapshot);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const result: any = {};
|
|
20
|
+
for (const key in object) {
|
|
21
|
+
result[key] = getSnapshot(object[key]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { SchemaVersion, Typename } from '../ast';
|
|
8
|
+
import { JsonSchemaType } from '../json-schema';
|
|
9
|
+
import { EchoObject } from '../object';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Persistent representation of a schema.
|
|
13
|
+
*/
|
|
14
|
+
export const StoredSchema = Schema.Struct({
|
|
15
|
+
name: Schema.optional(Schema.String),
|
|
16
|
+
typename: Typename,
|
|
17
|
+
version: SchemaVersion,
|
|
18
|
+
jsonSchema: JsonSchemaType,
|
|
19
|
+
}).pipe(
|
|
20
|
+
EchoObject({
|
|
21
|
+
typename: 'dxos.org/type/Schema',
|
|
22
|
+
version: '0.1.0',
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export type StoredSchema = Schema.Schema.Type<typeof StoredSchema>;
|