@dxos/echo 0.8.4-main.5ea62a8 → 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-7GH6RXJ3.mjs +3683 -0
- 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 +24 -1
- package/dist/lib/browser/internal/index.mjs +336 -0
- package/dist/lib/browser/internal/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +289 -31
- 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-M4B6BMD2.mjs +3683 -0
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +24 -1
- package/dist/lib/node-esm/internal/index.mjs +336 -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/testing/index.mjs +289 -31
- 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 +121 -50
- 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 +18 -14
- 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 -50
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +68 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +9 -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 +2 -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/entities/expando.d.ts +16 -0
- 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/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 +32 -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 +11 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
- 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 +2 -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 +5 -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/json-schema/json-schema.d.ts +29 -0
- 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 +2 -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 +18 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.d.ts +39 -0
- 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 +6 -0
- package/dist/types/src/internal/object/deleted.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 +8 -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 +31 -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/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/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/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/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/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 +209 -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/compose.d.ts +6 -0
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
- package/dist/types/src/internal/schema/compose.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 +6 -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/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 +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/types/base.d.ts +37 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/types/entity.d.ts +12 -0
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +6 -0
- package/dist/types/src/internal/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/types/meta.d.ts +40 -0
- 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/types/version.d.ts +15 -0
- 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 +4 -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 +112 -0
- 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/testing.d.ts +51 -0
- package/dist/types/src/query/testing.d.ts.map +1 -0
- package/dist/types/src/query/types.d.ts +17 -0
- 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 -1
- 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/testing/util.d.ts +16 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -29
- 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 +353 -107
- package/src/Ref.ts +9 -10
- package/src/Relation.ts +68 -43
- package/src/Tag.ts +40 -0
- package/src/Type.ts +97 -85
- package/src/errors.ts +18 -0
- package/src/index.ts +13 -4
- package/src/internal/README.md +83 -0
- package/src/internal/annotations/annotations.test.ts +96 -0
- 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/entities/expando.ts +23 -0
- 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 +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 +55 -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 +180 -0
- package/src/internal/index.ts +38 -0
- package/src/internal/json-schema/annotations.ts +50 -0
- package/src/internal/json-schema/effect-schema.test.ts +143 -0
- package/src/internal/json-schema/index.ts +8 -0
- package/src/internal/json-schema/json-schema-normalize.ts +109 -0
- package/src/internal/json-schema/json-schema-type.ts +404 -0
- package/src/internal/json-schema/json-schema.test.ts +859 -0
- package/src/internal/json-schema/json-schema.ts +528 -0
- package/src/internal/object/common.ts +75 -0
- package/src/internal/object/create-object.test.ts +116 -0
- package/src/internal/object/create-object.ts +95 -0
- package/src/internal/object/deleted.ts +19 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +11 -0
- package/src/internal/object/inspect.ts +46 -0
- package/src/internal/object/json-serializer.test.ts +94 -0
- package/src/internal/object/json-serializer.ts +230 -0
- package/src/internal/object/schema-validator.test.ts +186 -0
- package/src/internal/object/schema-validator.ts +242 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +94 -0
- package/src/internal/proxy/handler.test.ts +173 -0
- package/src/internal/proxy/index.ts +6 -0
- package/src/internal/proxy/make-object.ts +113 -0
- package/src/internal/proxy/schema.test.ts +137 -0
- package/src/internal/proxy/typed-handler.test.ts +102 -0
- package/src/internal/proxy/typed-handler.ts +233 -0
- package/src/internal/proxy/typed-object.test.ts +105 -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 +101 -0
- package/src/internal/ref/ref.ts +525 -0
- package/src/internal/schema/compose.test.ts +42 -0
- package/src/internal/schema/compose.ts +37 -0
- package/src/internal/schema/echo-schema.ts +385 -0
- package/src/internal/schema/index.ts +9 -0
- package/src/internal/schema/manipulation.ts +92 -0
- package/src/internal/schema/persistent-schema.ts +28 -0
- package/src/internal/schema/runtime-schema-registry.ts +78 -0
- package/src/internal/schema/snapshot.ts +25 -0
- package/src/internal/types/base.ts +58 -0
- package/src/internal/types/entity.ts +23 -0
- package/src/internal/types/index.ts +9 -0
- package/src/internal/types/meta.ts +76 -0
- 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 +5 -1
- package/src/query/order.ts +34 -0
- package/src/query/query.test.ts +334 -0
- package/src/query/query.ts +303 -0
- package/src/query/testing.ts +64 -0
- package/src/query/types.ts +23 -0
- package/src/query/util.ts +25 -0
- package/src/testing/api.test.ts +100 -0
- package/src/testing/index.ts +3 -1
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +213 -0
- package/src/testing/util.ts +78 -0
- package/dist/lib/browser/chunk-2KNTYMIW.mjs +0 -697
- package/dist/lib/browser/chunk-2KNTYMIW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EXNNC62J.mjs +0 -697
- package/dist/lib/node-esm/chunk-EXNNC62J.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 +0 -218
- 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/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.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 -324
- package/src/query/dsl.ts +0 -646
- package/src/test/api.test.ts +0 -173
- package/src/testing/types.ts +0 -91
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
// TODO(wittjosiah): Remove. Use ordering in queries instead.
|
|
8
|
+
|
|
9
|
+
/** @deprecated */
|
|
10
|
+
const SortDirection = Schema.Union(Schema.Literal('asc'), Schema.Literal('desc'));
|
|
11
|
+
/** @deprecated */
|
|
12
|
+
export type SortDirectionType = Schema.Schema.Type<typeof SortDirection>;
|
|
13
|
+
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
const FieldSort = Schema.Struct({
|
|
16
|
+
fieldId: Schema.String,
|
|
17
|
+
direction: SortDirection,
|
|
18
|
+
}).pipe(Schema.mutable);
|
|
19
|
+
|
|
20
|
+
/** @deprecated */
|
|
21
|
+
export interface FieldSortType extends Schema.Schema.Type<typeof FieldSort> {}
|
|
22
|
+
/** @deprecated */
|
|
23
|
+
export const FieldSortType: Schema.Schema<FieldSortType> = FieldSort;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
import { assertArgument } from '@dxos/invariant';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
10
|
+
|
|
11
|
+
import { getTypeReference } from '../internal';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param input schema or a typename string
|
|
15
|
+
* @return type DXN
|
|
16
|
+
*/
|
|
17
|
+
export const getTypeDXNFromSpecifier = (input: Schema.Schema.All | string): DXN => {
|
|
18
|
+
if (Schema.isSchema(input)) {
|
|
19
|
+
return getTypeReference(input)?.toDXN() ?? raise(new TypeError('Schema has no DXN'));
|
|
20
|
+
} else {
|
|
21
|
+
assertArgument(typeof input === 'string', 'input');
|
|
22
|
+
assertArgument(!input.startsWith('dxn:'), 'input');
|
|
23
|
+
return DXN.fromTypename(input);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { raise } from '@dxos/debug';
|
|
9
|
+
|
|
10
|
+
import { Entity, Obj, Ref, Relation, Type } from '../index';
|
|
11
|
+
|
|
12
|
+
import { TestSchema } from './test-schema';
|
|
13
|
+
|
|
14
|
+
describe('Experimental API review', () => {
|
|
15
|
+
test('type checks', ({ expect }) => {
|
|
16
|
+
const contact = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
17
|
+
const type: Schema.Schema<TestSchema.Person> = Obj.getSchema(contact) ?? raise(new Error('No schema found'));
|
|
18
|
+
|
|
19
|
+
expect(Type.getDXN(type)?.typename).to.eq(TestSchema.Person.typename);
|
|
20
|
+
expect(Type.getTypename(type)).to.eq('example.com/type/Person');
|
|
21
|
+
expect(Type.getVersion(type)).to.eq('0.1.0');
|
|
22
|
+
expect(Type.getMeta(type)).to.deep.eq({
|
|
23
|
+
kind: Entity.Kind.Object,
|
|
24
|
+
typename: 'example.com/type/Person',
|
|
25
|
+
version: '0.1.0',
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('instance checks', ({ expect }) => {
|
|
30
|
+
const organization = Obj.make(TestSchema.Organization, { name: 'DXOS' });
|
|
31
|
+
const contact = Obj.make(TestSchema.Person, {
|
|
32
|
+
name: 'Test',
|
|
33
|
+
employer: Ref.make(organization),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(Schema.is(TestSchema.Person)(contact)).to.be.true;
|
|
37
|
+
expect(Obj.instanceOf(TestSchema.Person, contact)).to.be.true;
|
|
38
|
+
expect(Obj.instanceOf(TestSchema.Organization, organization)).to.be.true;
|
|
39
|
+
|
|
40
|
+
const isPerson = Obj.instanceOf(TestSchema.Person);
|
|
41
|
+
const x: any = {};
|
|
42
|
+
if (isPerson(x)) {
|
|
43
|
+
x.name;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('default props', ({ expect }) => {
|
|
48
|
+
const message = Obj.make(TestSchema.Message, TestSchema.MessageStruct.make({}));
|
|
49
|
+
expect(message.timestamp).to.exist;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('Obj.isObject', ({ expect }) => {
|
|
53
|
+
const guy = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
54
|
+
expect(Obj.isObject(guy)).to.be.true;
|
|
55
|
+
expect(Obj.isObject(null)).to.be.false;
|
|
56
|
+
expect(Obj.isObject(undefined)).to.be.false;
|
|
57
|
+
expect(Obj.isObject(1)).to.be.false;
|
|
58
|
+
expect(Obj.isObject('string')).to.be.false;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('create relation', ({ expect }) => {
|
|
62
|
+
const person = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
63
|
+
const organization = Obj.make(TestSchema.Organization, { name: 'DXOS' });
|
|
64
|
+
const worksFor = Relation.make(TestSchema.EmployedBy, {
|
|
65
|
+
[Relation.Source]: person,
|
|
66
|
+
[Relation.Target]: organization,
|
|
67
|
+
role: 'CEO',
|
|
68
|
+
});
|
|
69
|
+
expect(Relation.getSource(worksFor)).to.eq(person);
|
|
70
|
+
expect(Relation.getTarget(worksFor)).to.eq(organization);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('version', ({ expect }) => {
|
|
74
|
+
const person = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
75
|
+
const version = Obj.version(person);
|
|
76
|
+
expect(Obj.isVersion(version)).to.be.true;
|
|
77
|
+
expect(Obj.versionValid(version)).to.be.false;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// TODO(burdon): Implement test.
|
|
81
|
+
test.skip('type narrowing', () => {
|
|
82
|
+
const any: Entity.Unknown = null as any;
|
|
83
|
+
|
|
84
|
+
{
|
|
85
|
+
if (Obj.isObject(any)) {
|
|
86
|
+
any;
|
|
87
|
+
} else {
|
|
88
|
+
any;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
{
|
|
93
|
+
if (Relation.isRelation(any)) {
|
|
94
|
+
any;
|
|
95
|
+
} else {
|
|
96
|
+
any;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
package/src/testing/index.ts
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { DatabaseDirectory, ObjectStructure } from '@dxos/echo-protocol';
|
|
6
|
+
import { DXN, ObjectId, PublicKey } from '@dxos/keys';
|
|
7
|
+
|
|
8
|
+
import { Type } from '../index';
|
|
9
|
+
|
|
10
|
+
import { TestSchema } from './test-schema';
|
|
11
|
+
|
|
12
|
+
const spaceKey = PublicKey.random();
|
|
13
|
+
|
|
14
|
+
// TODO(burdon): Use Obj.make.
|
|
15
|
+
|
|
16
|
+
export const PEOPLE = {
|
|
17
|
+
alice: DatabaseDirectory.make({
|
|
18
|
+
spaceKey: spaceKey.toHex(),
|
|
19
|
+
objects: {
|
|
20
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
21
|
+
type: Type.getDXN(TestSchema.Person)!.toString(),
|
|
22
|
+
data: {
|
|
23
|
+
name: 'Alice',
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
bob: DatabaseDirectory.make({
|
|
29
|
+
spaceKey: spaceKey.toHex(),
|
|
30
|
+
objects: {
|
|
31
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
32
|
+
type: Type.getDXN(TestSchema.Person)!.toString(),
|
|
33
|
+
data: {
|
|
34
|
+
name: 'Bob',
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const ORGS = {
|
|
42
|
+
dxos: DatabaseDirectory.make({
|
|
43
|
+
spaceKey: spaceKey.toHex(),
|
|
44
|
+
objects: {
|
|
45
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
46
|
+
type: Type.getDXN(TestSchema.Organization)!.toString(),
|
|
47
|
+
data: {
|
|
48
|
+
name: 'DXOS',
|
|
49
|
+
founded: '2023',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
cyberdyne: DatabaseDirectory.make({
|
|
55
|
+
spaceKey: spaceKey.toHex(),
|
|
56
|
+
objects: {
|
|
57
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
58
|
+
type: Type.getDXN(TestSchema.Organization)!.toString(),
|
|
59
|
+
data: {
|
|
60
|
+
name: 'Cyberdyne Systems',
|
|
61
|
+
founded: '1984',
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const WORKS_FOR = {
|
|
69
|
+
fredWorksForCyberdyne: DatabaseDirectory.make({
|
|
70
|
+
spaceKey: spaceKey.toHex(),
|
|
71
|
+
objects: {
|
|
72
|
+
[ObjectId.random()]: ObjectStructure.makeRelation({
|
|
73
|
+
type: Type.getDXN(TestSchema.EmployedBy)!.toString(),
|
|
74
|
+
source: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.bob.objects!)[0]).toString() },
|
|
75
|
+
target: { '/': DXN.fromLocalObjectId(Object.keys(ORGS.cyberdyne.objects!)[0]).toString() },
|
|
76
|
+
data: {
|
|
77
|
+
since: '2020',
|
|
78
|
+
position: 'Engineer',
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
aliceWorksForAperture: DatabaseDirectory.make({
|
|
84
|
+
spaceKey: spaceKey.toHex(),
|
|
85
|
+
objects: {
|
|
86
|
+
[ObjectId.random()]: ObjectStructure.makeRelation({
|
|
87
|
+
type: Type.getDXN(TestSchema.EmployedBy)!.toString(),
|
|
88
|
+
source: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.alice.objects!)[0]).toString() },
|
|
89
|
+
target: { '/': DXN.fromLocalObjectId(Object.keys(ORGS.dxos.objects!)[0]).toString() },
|
|
90
|
+
data: {
|
|
91
|
+
since: '2018',
|
|
92
|
+
position: 'Research Scientist',
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const TASKS = {
|
|
100
|
+
task1: DatabaseDirectory.make({
|
|
101
|
+
spaceKey: spaceKey.toHex(),
|
|
102
|
+
objects: {
|
|
103
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
104
|
+
type: Type.getDXN(TestSchema.Task)!.toString(),
|
|
105
|
+
data: {
|
|
106
|
+
title: 'Complete project documentation',
|
|
107
|
+
description: 'Write comprehensive documentation for the new system',
|
|
108
|
+
status: 'in-progress',
|
|
109
|
+
dueDate: '2023-12-31',
|
|
110
|
+
assignee: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.bob.objects!)[0]).toString() },
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
task2: DatabaseDirectory.make({
|
|
116
|
+
spaceKey: spaceKey.toHex(),
|
|
117
|
+
objects: {
|
|
118
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
119
|
+
type: Type.getDXN(TestSchema.Task)!.toString(),
|
|
120
|
+
data: {
|
|
121
|
+
title: 'Run experiments',
|
|
122
|
+
description: 'Conduct series of experiments on the portal device',
|
|
123
|
+
status: 'pending',
|
|
124
|
+
dueDate: '2023-11-15',
|
|
125
|
+
assignee: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.alice.objects!)[0]).toString() },
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import * as Obj from '../Obj';
|
|
8
|
+
import * as Type from '../Type';
|
|
9
|
+
|
|
10
|
+
export namespace TestSchema {
|
|
11
|
+
//
|
|
12
|
+
// Example
|
|
13
|
+
//
|
|
14
|
+
|
|
15
|
+
const Nested = Schema.Struct({
|
|
16
|
+
field: Schema.String,
|
|
17
|
+
}).pipe(Schema.mutable);
|
|
18
|
+
|
|
19
|
+
export class TestClass {
|
|
20
|
+
field = 'value';
|
|
21
|
+
toJSON() {
|
|
22
|
+
return { field: this.field };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
27
|
+
export const ExampleSchema = Schema.Struct({
|
|
28
|
+
string: Schema.String,
|
|
29
|
+
number: Schema.Number,
|
|
30
|
+
boolean: Schema.Boolean,
|
|
31
|
+
null: Schema.Null,
|
|
32
|
+
undefined: Schema.Undefined,
|
|
33
|
+
stringArray: Schema.mutable(Schema.Array(Schema.String)),
|
|
34
|
+
twoDimNumberArray: Schema.mutable(Schema.Array(Schema.mutable(Schema.Array(Schema.Number)))),
|
|
35
|
+
nested: Schema.mutable(Nested),
|
|
36
|
+
nestedArray: Schema.mutable(Schema.Array(Nested)),
|
|
37
|
+
nestedNullableArray: Schema.mutable(Schema.Array(Schema.Union(Nested, Schema.Null))),
|
|
38
|
+
reference: Schema.suspend((): Type.Ref<Example> => Type.Ref(Example)),
|
|
39
|
+
referenceArray: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Example> => Type.Ref(Example)))),
|
|
40
|
+
classInstance: Schema.instanceOf(TestClass),
|
|
41
|
+
other: Schema.Any,
|
|
42
|
+
}).pipe(Schema.partial, Schema.mutable);
|
|
43
|
+
|
|
44
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
45
|
+
export interface ExampleSchema extends Schema.Schema.Type<typeof ExampleSchema> {}
|
|
46
|
+
|
|
47
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
48
|
+
export const Example = ExampleSchema.pipe(
|
|
49
|
+
Type.Obj({
|
|
50
|
+
typename: 'example.com/type/Example',
|
|
51
|
+
version: '0.1.0',
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
56
|
+
export interface Example extends Schema.Schema.Type<typeof Example> {}
|
|
57
|
+
|
|
58
|
+
//
|
|
59
|
+
// Message
|
|
60
|
+
//
|
|
61
|
+
|
|
62
|
+
// TODO(burdon): Support defaults directly on Type: `make` is erased by `pipe(Type.Obj)`.
|
|
63
|
+
export const MessageStruct = Schema.Struct({
|
|
64
|
+
// TODO(burdon): Support S.Date; Custom Timestamp (with defaults).
|
|
65
|
+
// TODO(burdon): Support defaults (update create and create).
|
|
66
|
+
timestamp: Schema.String.pipe(
|
|
67
|
+
Schema.propertySignature,
|
|
68
|
+
Schema.withConstructorDefault(() => new Date().toISOString()),
|
|
69
|
+
),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const Message = MessageStruct.pipe(
|
|
73
|
+
Type.Obj({
|
|
74
|
+
typename: 'example.com/type/Message',
|
|
75
|
+
version: '0.1.0',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export interface Message extends Schema.Schema.Type<typeof Message> {}
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
// Organization
|
|
83
|
+
//
|
|
84
|
+
|
|
85
|
+
export const Organization = Schema.Struct({
|
|
86
|
+
name: Schema.String,
|
|
87
|
+
}).pipe(
|
|
88
|
+
Type.Obj({
|
|
89
|
+
typename: 'example.com/type/Organization',
|
|
90
|
+
version: '0.1.0',
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
95
|
+
|
|
96
|
+
//
|
|
97
|
+
// Person
|
|
98
|
+
//
|
|
99
|
+
|
|
100
|
+
export const Person = Schema.Struct({
|
|
101
|
+
name: Schema.String,
|
|
102
|
+
username: Schema.String,
|
|
103
|
+
email: Schema.String,
|
|
104
|
+
tasks: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task)))),
|
|
105
|
+
employer: Schema.optional(Type.Ref(Organization)),
|
|
106
|
+
address: Schema.Struct({
|
|
107
|
+
city: Schema.optional(Schema.String),
|
|
108
|
+
state: Schema.optional(Schema.String),
|
|
109
|
+
zip: Schema.optional(Schema.String),
|
|
110
|
+
coordinates: Schema.Struct({
|
|
111
|
+
lat: Schema.optional(Schema.Number),
|
|
112
|
+
lng: Schema.optional(Schema.Number),
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
}).pipe(
|
|
116
|
+
Schema.partial,
|
|
117
|
+
Type.Obj({
|
|
118
|
+
typename: 'example.com/type/Person',
|
|
119
|
+
version: '0.1.0',
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
export interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
124
|
+
|
|
125
|
+
//
|
|
126
|
+
// Task
|
|
127
|
+
//
|
|
128
|
+
|
|
129
|
+
export const Task = Schema.Struct({
|
|
130
|
+
title: Schema.optional(Schema.String),
|
|
131
|
+
deadline: Schema.optional(Schema.String),
|
|
132
|
+
completed: Schema.optional(Schema.Boolean),
|
|
133
|
+
assignee: Schema.optional(Type.Ref(Person)),
|
|
134
|
+
previous: Schema.optional(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))),
|
|
135
|
+
subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))))),
|
|
136
|
+
description: Schema.optional(Schema.String),
|
|
137
|
+
}).pipe(
|
|
138
|
+
Schema.partial,
|
|
139
|
+
Type.Obj({
|
|
140
|
+
typename: 'example.com/type/Task',
|
|
141
|
+
version: '0.1.0',
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export interface Task extends Schema.Schema.Type<typeof Task> {}
|
|
146
|
+
|
|
147
|
+
//
|
|
148
|
+
// HasManager
|
|
149
|
+
//
|
|
150
|
+
|
|
151
|
+
export const HasManager = Schema.Struct({}).pipe(
|
|
152
|
+
Type.Relation({
|
|
153
|
+
typename: 'example.com/type/HasManager',
|
|
154
|
+
version: '0.1.0',
|
|
155
|
+
source: Person,
|
|
156
|
+
target: Person,
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
export interface HasManager extends Schema.Schema.Type<typeof HasManager> {}
|
|
161
|
+
|
|
162
|
+
//
|
|
163
|
+
// EmployedBy
|
|
164
|
+
//
|
|
165
|
+
|
|
166
|
+
export const EmployedBy = Schema.Struct({
|
|
167
|
+
role: Schema.String,
|
|
168
|
+
since: Schema.optional(Schema.String),
|
|
169
|
+
}).pipe(
|
|
170
|
+
Type.Relation({
|
|
171
|
+
typename: 'example.com/type/EmployedBy',
|
|
172
|
+
version: '0.1.0',
|
|
173
|
+
source: Person,
|
|
174
|
+
target: Organization,
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
export interface EmployedBy extends Schema.Schema.Type<typeof EmployedBy> {}
|
|
179
|
+
|
|
180
|
+
//
|
|
181
|
+
// RecordType
|
|
182
|
+
//
|
|
183
|
+
|
|
184
|
+
export enum RecordType {
|
|
185
|
+
UNDEFINED = 0,
|
|
186
|
+
PERSONAL = 1,
|
|
187
|
+
WORK = 2,
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export const Container = Schema.Struct({
|
|
191
|
+
objects: Schema.mutable(Schema.Array(Type.Ref(Obj.Any))),
|
|
192
|
+
records: Schema.mutable(
|
|
193
|
+
Schema.Array(
|
|
194
|
+
Schema.partial(
|
|
195
|
+
Schema.Struct({
|
|
196
|
+
title: Schema.String,
|
|
197
|
+
description: Schema.String,
|
|
198
|
+
contacts: Schema.mutable(Schema.Array(Type.Ref(Person))),
|
|
199
|
+
type: Schema.Enums(RecordType),
|
|
200
|
+
}),
|
|
201
|
+
),
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
}).pipe(
|
|
205
|
+
Schema.partial,
|
|
206
|
+
Type.Obj({
|
|
207
|
+
typename: 'example.com/type/Container',
|
|
208
|
+
version: '0.1.0',
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
export interface Container extends Schema.Schema.Type<typeof Container> {}
|
|
213
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { effect } from '@preact/signals-core';
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
7
|
+
import type * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
import { registerSignalsRuntime } from '@dxos/echo-signals';
|
|
10
|
+
import { assertArgument } from '@dxos/invariant';
|
|
11
|
+
import { deepMapValues } from '@dxos/util';
|
|
12
|
+
|
|
13
|
+
import { EchoSchema, PersistentSchema, getSchemaTypename, makeObject, toJsonSchema } from '../internal';
|
|
14
|
+
|
|
15
|
+
registerSignalsRuntime();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a reactive mutable schema that updates when the JSON schema is updated.
|
|
19
|
+
*/
|
|
20
|
+
// TODO(dmaretskyi): Should be replaced by registration of typed object.
|
|
21
|
+
export const createEchoSchema = (schema: Schema.Schema.AnyNoContext, version = '0.1.0'): EchoSchema => {
|
|
22
|
+
const jsonSchema = toJsonSchema(schema);
|
|
23
|
+
const typename = getSchemaTypename(schema);
|
|
24
|
+
assertArgument(typename, 'typename', 'Schema does not have a typename.');
|
|
25
|
+
const echoSchema = new EchoSchema(makeObject(PersistentSchema, { typename, version, jsonSchema }));
|
|
26
|
+
|
|
27
|
+
// TODO(burdon): Unsubscribe is never called.
|
|
28
|
+
effect(() => {
|
|
29
|
+
const _ = echoSchema.jsonSchema;
|
|
30
|
+
echoSchema._invalidate();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return echoSchema;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Converts AST to a format that can be compared with test matchers.
|
|
38
|
+
*/
|
|
39
|
+
export const prepareAstForCompare = (obj: SchemaAST.AST): any =>
|
|
40
|
+
deepMapValues(obj, (value: any, recurse: any) => {
|
|
41
|
+
if (typeof value === 'function') {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (value instanceof RegExp) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Convert symbols to strings.
|
|
50
|
+
if (typeof value === 'object') {
|
|
51
|
+
const clone = { ...value };
|
|
52
|
+
for (const sym of Object.getOwnPropertySymbols(clone as any)) {
|
|
53
|
+
clone[sym.toString()] = clone[sym];
|
|
54
|
+
delete clone[sym];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return recurse(clone);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return recurse(value);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// TODO(burdon): Use @dxos/util.
|
|
64
|
+
export const updateCounter = (touch: () => void) => {
|
|
65
|
+
let updateCount = -1;
|
|
66
|
+
const unsubscribe = effect(() => {
|
|
67
|
+
touch();
|
|
68
|
+
updateCount++;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
// https://github.com/tc39/proposal-explicit-resource-management
|
|
73
|
+
[Symbol.dispose]: unsubscribe,
|
|
74
|
+
get count() {
|
|
75
|
+
return updateCount;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|