@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
package/src/query/query.ts
CHANGED
|
@@ -3,53 +3,29 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import type * as EffectArray from 'effect/Array';
|
|
6
|
-
import * as
|
|
7
|
-
|
|
8
|
-
import type
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import { type ForeignKey, type QueryAST } from '@dxos/echo-protocol';
|
|
12
|
-
import { assertArgument } from '@dxos/invariant';
|
|
13
|
-
import { DXN, ObjectId } from '@dxos/keys';
|
|
14
|
-
|
|
15
|
-
import { getTypeReference } from '../internal';
|
|
16
|
-
import type * as Obj from '../Obj';
|
|
17
|
-
import * as Ref from '../Ref';
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
7
|
+
|
|
8
|
+
import { type QueryAST } from '@dxos/echo-protocol';
|
|
9
|
+
|
|
10
|
+
import type * as Ref from '../Ref';
|
|
18
11
|
import type * as Type from '../Type';
|
|
19
12
|
|
|
13
|
+
import { Filter, FilterClass } from './filter';
|
|
14
|
+
import { type Order } from './order';
|
|
15
|
+
import { getTypeDXNFromSpecifier } from './util';
|
|
16
|
+
|
|
17
|
+
// TODO(burdon): Query namespace (and move Filter, Order into Query namespace).
|
|
20
18
|
// TODO(dmaretskyi): Split up into interfaces for objects and relations so they can have separate verbs.
|
|
21
19
|
// TODO(dmaretskyi): Undirected relation traversals.
|
|
22
20
|
// TODO(wittjosiah): Make Filter & Query pipeable.
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class OrderClass implements Order<any> {
|
|
32
|
-
private static variance: Order<any>['~Order'] = {} as Order<any>['~Order'];
|
|
33
|
-
|
|
34
|
-
static is(value: unknown): value is Order<any> {
|
|
35
|
-
return typeof value === 'object' && value !== null && '~Order' in value;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
constructor(public readonly ast: QueryAST.Order) {}
|
|
39
|
-
|
|
40
|
-
'~Order' = OrderClass.variance;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export namespace Order {
|
|
44
|
-
export const natural: Order<any> = new OrderClass({ kind: 'natural' });
|
|
45
|
-
export const property = <T>(property: keyof T & string, direction: QueryAST.OrderDirection): Order<T> =>
|
|
46
|
-
new OrderClass({
|
|
47
|
-
kind: 'property',
|
|
48
|
-
property,
|
|
49
|
-
direction,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* All property paths inside T that are references.
|
|
24
|
+
*/
|
|
25
|
+
// TODO(dmaretskyi): Filter only properties that are references (or optional references, or unions that include references).
|
|
26
|
+
type RefPropKey<T> = keyof T & string;
|
|
52
27
|
|
|
28
|
+
// TODO(burdon): Narrow T to Entity.Unknown?
|
|
53
29
|
export interface Query<T> {
|
|
54
30
|
// TODO(dmaretskyi): See new effect-schema approach to variance.
|
|
55
31
|
'~Query': { value: T };
|
|
@@ -187,456 +163,8 @@ export declare namespace Query {
|
|
|
187
163
|
export type Any = Query<any>;
|
|
188
164
|
|
|
189
165
|
export type Type<Q extends Any> = Q extends Query<infer T> ? T : never;
|
|
190
|
-
|
|
191
|
-
export type TextSearchOptions = {
|
|
192
|
-
// TODO(dmaretskyi): Hybrid search.
|
|
193
|
-
type?: 'full-text' | 'vector';
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export interface Filter<T> {
|
|
198
|
-
// TODO(dmaretskyi): See new effect-schema approach to variance.
|
|
199
|
-
'~Filter': { value: Types.Contravariant<T> };
|
|
200
|
-
|
|
201
|
-
ast: QueryAST.Filter;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
type Intersection<Types extends readonly unknown[]> = Types extends [infer First, ...infer Rest]
|
|
205
|
-
? First & Intersection<Rest>
|
|
206
|
-
: unknown;
|
|
207
|
-
|
|
208
|
-
interface FilterAPI {
|
|
209
|
-
is(value: unknown): value is Filter.Any;
|
|
210
|
-
|
|
211
|
-
/** Construct a filter from an ast. */
|
|
212
|
-
fromAst(ast: QueryAST.Filter): Filter<Obj.Any>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Filter that matches all objects.
|
|
216
|
-
*/
|
|
217
|
-
// TODO(dmaretskyi): `Obj.Any` would be more type-safe, but causes annoying errors in existing code
|
|
218
|
-
everything(): Filter<Obj.AnyProps>;
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Filter that matches no objects.
|
|
222
|
-
*/
|
|
223
|
-
// TODO(dmaretskyi): Filter<never>?
|
|
224
|
-
nothing(): Filter<any>;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Filter by object IDs.
|
|
228
|
-
*/
|
|
229
|
-
// TODO(dmaretskyi): Rename to `Filter.id`.
|
|
230
|
-
ids(...id: ObjectId[]): Filter<Obj.AnyProps>;
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Filter by type.
|
|
234
|
-
*/
|
|
235
|
-
type<S extends Schema.Schema.All>(
|
|
236
|
-
schema: S | string,
|
|
237
|
-
props?: Filter.Props<Schema.Schema.Type<S>>,
|
|
238
|
-
): Filter<Schema.Schema.Type<S>>;
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Filter by non-qualified typename.
|
|
242
|
-
*/
|
|
243
|
-
typename(typename: string): Filter<Obj.AnyProps>;
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Filter by fully qualified type DXN.
|
|
247
|
-
*/
|
|
248
|
-
typeDXN(dxn: DXN): Filter<Obj.AnyProps>;
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Filter by tag.
|
|
252
|
-
*/
|
|
253
|
-
tag(tag: string): Filter<Obj.Any>;
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Filter by properties.
|
|
257
|
-
*/
|
|
258
|
-
props<T>(props: Filter.Props<T>): Filter<T>;
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Full-text or vector search.
|
|
262
|
-
*/
|
|
263
|
-
text(
|
|
264
|
-
// TODO(dmaretskyi): Consider passing a vector here, but really the embedding should be done on the query-executor side.
|
|
265
|
-
text: string,
|
|
266
|
-
options?: Query.TextSearchOptions,
|
|
267
|
-
): Filter<any>;
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Filter by foreign keys.
|
|
271
|
-
*/
|
|
272
|
-
foreignKeys<S extends Schema.Schema.All>(schema: S, keys: ForeignKey[]): Filter<Schema.Schema.Type<S>>;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Predicate for property to be equal to the provided value.
|
|
276
|
-
*/
|
|
277
|
-
eq<T>(value: T): Filter<T>;
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Predicate for property to be not equal to the provided value.
|
|
281
|
-
*/
|
|
282
|
-
neq<T>(value: T): Filter<T>;
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Predicate for property to be greater than the provided value.
|
|
286
|
-
*/
|
|
287
|
-
gt<T>(value: T): Filter<T>;
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Predicate for property to be greater than the provided value.
|
|
291
|
-
*/
|
|
292
|
-
gt<T>(value: T): Filter<T>;
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Predicate for property to be greater than or equal to the provided value.
|
|
296
|
-
*/
|
|
297
|
-
gte<T>(value: T): Filter<T>;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Predicate for property to be less than the provided value.
|
|
301
|
-
*/
|
|
302
|
-
lt<T>(value: T): Filter<T>;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Predicate for property to be less than or equal to the provided value.
|
|
306
|
-
*/
|
|
307
|
-
lte<T>(value: T): Filter<T>;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Predicate for property to be in the provided array.
|
|
311
|
-
* @param values - Values to check against.
|
|
312
|
-
*/
|
|
313
|
-
in<T>(...values: T[]): Filter<T>;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Predicate for an array property to contain the provided value.
|
|
317
|
-
* @param value - Value to check against.
|
|
318
|
-
*/
|
|
319
|
-
contains<T>(value: T): Filter<readonly T[] | undefined>;
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Predicate for property to be in the provided range.
|
|
323
|
-
* @param from - Start of the range (inclusive).
|
|
324
|
-
* @param to - End of the range (exclusive).
|
|
325
|
-
*/
|
|
326
|
-
between<T>(from: T, to: T): Filter<unknown>;
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Negate the filter.
|
|
330
|
-
*/
|
|
331
|
-
not<F extends Filter.Any>(filter: F): Filter<Filter.Type<F>>;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Combine filters with a logical AND.
|
|
335
|
-
*/
|
|
336
|
-
and<FS extends Filter.Any[]>(...filters: FS): Filter<Filter.And<FS>>;
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Combine filters with a logical OR.
|
|
340
|
-
*/
|
|
341
|
-
or<FS extends Filter.Any[]>(...filters: FS): Filter<Filter.Or<FS>>;
|
|
342
|
-
|
|
343
|
-
// TODO(dmaretskyi): Add `Filter.match` to support pattern matching on string props.
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export declare namespace Filter {
|
|
347
|
-
type Props<T> = {
|
|
348
|
-
// Predicate or a value as a shorthand for `eq`.
|
|
349
|
-
[K in keyof T & string]?: Filter<T[K]> | T[K];
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
type Any = Filter<any>;
|
|
353
|
-
|
|
354
|
-
type Type<F extends Any> = F extends Filter<infer T> ? T : never;
|
|
355
|
-
|
|
356
|
-
type And<FS extends readonly Any[]> = Schema.Simplify<Intersection<{ [K in keyof FS]: Type<FS[K]> }>>;
|
|
357
|
-
|
|
358
|
-
type Or<FS extends readonly Any[]> = Schema.Simplify<{ [K in keyof FS]: Type<FS[K]> }[number]>;
|
|
359
166
|
}
|
|
360
167
|
|
|
361
|
-
// TODO(dmaretskyi): Separate object instead of statics for better devex with type errors.
|
|
362
|
-
class FilterClass implements Filter<any> {
|
|
363
|
-
private static variance: Filter<any>['~Filter'] = {} as Filter<any>['~Filter'];
|
|
364
|
-
|
|
365
|
-
static is(value: unknown): value is Filter<any> {
|
|
366
|
-
return typeof value === 'object' && value !== null && '~Filter' in value;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
static fromAst(ast: QueryAST.Filter): Filter<any> {
|
|
370
|
-
return new FilterClass(ast);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
static everything(): FilterClass {
|
|
374
|
-
return new FilterClass({
|
|
375
|
-
type: 'object',
|
|
376
|
-
typename: null,
|
|
377
|
-
props: {},
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
static nothing(): FilterClass {
|
|
382
|
-
return new FilterClass({
|
|
383
|
-
type: 'not',
|
|
384
|
-
filter: {
|
|
385
|
-
type: 'object',
|
|
386
|
-
typename: null,
|
|
387
|
-
props: {},
|
|
388
|
-
},
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
static relation() {
|
|
393
|
-
return new FilterClass({
|
|
394
|
-
type: 'object',
|
|
395
|
-
typename: null,
|
|
396
|
-
props: {},
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
static ids(...ids: ObjectId[]): Filter<any> {
|
|
401
|
-
assertArgument(
|
|
402
|
-
ids.every((id) => ObjectId.isValid(id)),
|
|
403
|
-
'ids',
|
|
404
|
-
'ids must be valid',
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
if (ids.length === 0) {
|
|
408
|
-
return Filter.nothing();
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return new FilterClass({
|
|
412
|
-
type: 'object',
|
|
413
|
-
typename: null,
|
|
414
|
-
id: ids,
|
|
415
|
-
props: {},
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
static type<S extends Schema.Schema.All>(
|
|
420
|
-
schema: S | string,
|
|
421
|
-
props?: Filter.Props<Schema.Schema.Type<S>>,
|
|
422
|
-
): Filter<Schema.Schema.Type<S>> {
|
|
423
|
-
const dxn = getTypeDXNFromSpecifier(schema);
|
|
424
|
-
return new FilterClass({
|
|
425
|
-
type: 'object',
|
|
426
|
-
typename: dxn.toString(),
|
|
427
|
-
...propsFilterToAst(props ?? {}),
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
static typename(typename: string): Filter<any> {
|
|
432
|
-
assertArgument(!typename.startsWith('dxn:'), 'typename', 'Typename must no be qualified');
|
|
433
|
-
return new FilterClass({
|
|
434
|
-
type: 'object',
|
|
435
|
-
typename: DXN.fromTypename(typename).toString(),
|
|
436
|
-
props: {},
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
static typeDXN(dxn: DXN): Filter<any> {
|
|
441
|
-
return new FilterClass({
|
|
442
|
-
type: 'object',
|
|
443
|
-
typename: dxn.toString(),
|
|
444
|
-
props: {},
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
static tag(tag: string): Filter<any> {
|
|
449
|
-
return new FilterClass({
|
|
450
|
-
type: 'tag',
|
|
451
|
-
tag,
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
static props<T>(props: Filter.Props<T>): Filter<T> {
|
|
456
|
-
return new FilterClass({
|
|
457
|
-
type: 'object',
|
|
458
|
-
typename: null,
|
|
459
|
-
...propsFilterToAst(props),
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
static text(text: string, options?: Query.TextSearchOptions): Filter<any> {
|
|
464
|
-
return new FilterClass({
|
|
465
|
-
type: 'text-search',
|
|
466
|
-
text,
|
|
467
|
-
searchKind: options?.type,
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
static foreignKeys<S extends Schema.Schema.All>(
|
|
472
|
-
schema: S | string,
|
|
473
|
-
keys: ForeignKey[],
|
|
474
|
-
): Filter<Schema.Schema.Type<S>> {
|
|
475
|
-
const dxn = getTypeDXNFromSpecifier(schema);
|
|
476
|
-
return new FilterClass({
|
|
477
|
-
type: 'object',
|
|
478
|
-
typename: dxn.toString(),
|
|
479
|
-
props: {},
|
|
480
|
-
foreignKeys: keys,
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
static eq<T>(value: T): Filter<T> {
|
|
485
|
-
if (!Ref.isRef(value) && typeof value === 'object' && value !== null) {
|
|
486
|
-
throw new TypeError('Cannot use object as a value for eq filter');
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
return new FilterClass({
|
|
490
|
-
type: 'compare',
|
|
491
|
-
operator: 'eq',
|
|
492
|
-
value: Ref.isRef(value) ? value.noInline().encode() : value,
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
static neq<T>(value: T): Filter<T> {
|
|
497
|
-
return new FilterClass({
|
|
498
|
-
type: 'compare',
|
|
499
|
-
operator: 'neq',
|
|
500
|
-
value,
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
static gt<T>(value: T): Filter<T> {
|
|
505
|
-
return new FilterClass({
|
|
506
|
-
type: 'compare',
|
|
507
|
-
operator: 'gt',
|
|
508
|
-
value,
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
static gte<T>(value: T): Filter<T> {
|
|
513
|
-
return new FilterClass({
|
|
514
|
-
type: 'compare',
|
|
515
|
-
operator: 'gte',
|
|
516
|
-
value,
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
static lt<T>(value: T): Filter<T> {
|
|
521
|
-
return new FilterClass({
|
|
522
|
-
type: 'compare',
|
|
523
|
-
operator: 'lt',
|
|
524
|
-
value,
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
static lte<T>(value: T): Filter<T> {
|
|
529
|
-
return new FilterClass({
|
|
530
|
-
type: 'compare',
|
|
531
|
-
operator: 'lte',
|
|
532
|
-
value,
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
static in<T>(...values: T[]): Filter<T> {
|
|
537
|
-
return new FilterClass({
|
|
538
|
-
type: 'in',
|
|
539
|
-
values,
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
static contains<T>(value: T): Filter<readonly T[] | undefined> {
|
|
544
|
-
return new FilterClass({
|
|
545
|
-
type: 'contains',
|
|
546
|
-
value,
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
static between<T>(from: T, to: T): Filter<unknown> {
|
|
551
|
-
return new FilterClass({
|
|
552
|
-
type: 'range',
|
|
553
|
-
from,
|
|
554
|
-
to,
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
static not<F extends Filter.Any>(filter: F): Filter<Filter.Type<F>> {
|
|
559
|
-
return new FilterClass({
|
|
560
|
-
type: 'not',
|
|
561
|
-
filter: filter.ast,
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
static and<T>(...filters: Filter<T>[]): Filter<T> {
|
|
566
|
-
return new FilterClass({
|
|
567
|
-
type: 'and',
|
|
568
|
-
filters: filters.map((f) => f.ast),
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
static or<T>(...filters: Filter<T>[]): Filter<T> {
|
|
573
|
-
return new FilterClass({
|
|
574
|
-
type: 'or',
|
|
575
|
-
filters: filters.map((f) => f.ast),
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
private constructor(public readonly ast: QueryAST.Filter) {}
|
|
580
|
-
|
|
581
|
-
'~Filter' = FilterClass.variance;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
export const Filter: FilterAPI = FilterClass;
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* All property paths inside T that are references.
|
|
588
|
-
*/
|
|
589
|
-
// TODO(dmaretskyi): Filter only properties that are references (or optional references, or unions that include references).
|
|
590
|
-
type RefPropKey<T> = keyof T & string;
|
|
591
|
-
|
|
592
|
-
const propsFilterToAst = (predicates: Filter.Props<any>): Pick<QueryAST.FilterObject, 'id' | 'props'> => {
|
|
593
|
-
let idFilter: readonly ObjectId[] | undefined;
|
|
594
|
-
if ('id' in predicates) {
|
|
595
|
-
assertArgument(
|
|
596
|
-
typeof predicates.id === 'string' || Array.isArray(predicates.id),
|
|
597
|
-
'predicates.id',
|
|
598
|
-
'invalid id filter',
|
|
599
|
-
);
|
|
600
|
-
idFilter = typeof predicates.id === 'string' ? [predicates.id] : predicates.id;
|
|
601
|
-
Schema.Array(ObjectId).pipe(Schema.validateSync)(idFilter);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
return {
|
|
605
|
-
id: idFilter,
|
|
606
|
-
props: Object.fromEntries(
|
|
607
|
-
Object.entries(predicates)
|
|
608
|
-
.filter(([prop, _value]) => prop !== 'id')
|
|
609
|
-
.map(([prop, predicate]) => [prop, processPredicate(predicate)]),
|
|
610
|
-
) as Record<string, QueryAST.Filter>,
|
|
611
|
-
};
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
const processPredicate = (predicate: any): QueryAST.Filter => {
|
|
615
|
-
return Match.value(predicate).pipe(
|
|
616
|
-
Match.withReturnType<QueryAST.Filter>(),
|
|
617
|
-
Match.when(Filter.is, (predicate) => predicate.ast),
|
|
618
|
-
// TODO(wittjosiah): Add support for array predicates.
|
|
619
|
-
Match.when(Array.isArray, (_predicate) => {
|
|
620
|
-
throw new Error('Array predicates are not yet supported.');
|
|
621
|
-
}),
|
|
622
|
-
Match.when(
|
|
623
|
-
(predicate: any) => !Ref.isRef(predicate) && typeof predicate === 'object' && predicate !== null,
|
|
624
|
-
(predicate) => {
|
|
625
|
-
const nestedProps = Object.fromEntries(
|
|
626
|
-
Object.entries(predicate).map(([key, value]) => [key, processPredicate(value)]),
|
|
627
|
-
);
|
|
628
|
-
|
|
629
|
-
return {
|
|
630
|
-
type: 'object',
|
|
631
|
-
typename: null,
|
|
632
|
-
props: nestedProps,
|
|
633
|
-
};
|
|
634
|
-
},
|
|
635
|
-
),
|
|
636
|
-
Match.orElse((value) => Filter.eq(value).ast),
|
|
637
|
-
);
|
|
638
|
-
};
|
|
639
|
-
|
|
640
168
|
// TODO(dmaretskyi): Separate object instead of statics for better devex with type errors.
|
|
641
169
|
class QueryClass implements Query<any> {
|
|
642
170
|
private static variance: Query<any>['~Query'] = {} as Query<any>['~Query'];
|
|
@@ -773,17 +301,3 @@ class QueryClass implements Query<any> {
|
|
|
773
301
|
}
|
|
774
302
|
|
|
775
303
|
export const Query: QueryAPI = QueryClass;
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* @param input schema or a typename string
|
|
779
|
-
* @return type DXN
|
|
780
|
-
*/
|
|
781
|
-
const getTypeDXNFromSpecifier = (input: Schema.Schema.All | string): DXN => {
|
|
782
|
-
if (Schema.isSchema(input)) {
|
|
783
|
-
return getTypeReference(input)?.toDXN() ?? raise(new TypeError('Schema has no DXN'));
|
|
784
|
-
} else {
|
|
785
|
-
assertArgument(typeof input === 'string', 'input');
|
|
786
|
-
assertArgument(!input.startsWith('dxn:'), 'input');
|
|
787
|
-
return DXN.fromTypename(input);
|
|
788
|
-
}
|
|
789
|
-
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import * as Type from '../Type';
|
|
8
|
+
|
|
9
|
+
// TODO(burdon): Rationalize with ../testing
|
|
10
|
+
|
|
11
|
+
export const Person = Schema.Struct({
|
|
12
|
+
name: Schema.String,
|
|
13
|
+
email: Schema.optional(Schema.String),
|
|
14
|
+
age: Schema.optional(Schema.Number),
|
|
15
|
+
fields: Schema.Struct({
|
|
16
|
+
label: Schema.String,
|
|
17
|
+
value: Schema.String,
|
|
18
|
+
}).pipe(Schema.Array, Schema.optional),
|
|
19
|
+
}).pipe(
|
|
20
|
+
Type.Obj({
|
|
21
|
+
typename: 'dxos.org/type/Person',
|
|
22
|
+
version: '0.1.0',
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
27
|
+
|
|
28
|
+
export const Organization = Schema.Struct({
|
|
29
|
+
name: Schema.String,
|
|
30
|
+
properties: Schema.optional(
|
|
31
|
+
Schema.Record({
|
|
32
|
+
key: Schema.String,
|
|
33
|
+
value: Schema.String,
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
}).pipe(
|
|
37
|
+
Type.Obj({
|
|
38
|
+
typename: 'dxos.org/type/Organization',
|
|
39
|
+
version: '0.1.0',
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
44
|
+
|
|
45
|
+
export const WorksFor = Schema.Struct({
|
|
46
|
+
since: Schema.String,
|
|
47
|
+
}).pipe(
|
|
48
|
+
Type.Relation({
|
|
49
|
+
typename: 'dxos.org/type/WorksFor',
|
|
50
|
+
version: '0.1.0',
|
|
51
|
+
source: Person,
|
|
52
|
+
target: Organization,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
|
|
57
|
+
|
|
58
|
+
export const Task = Schema.Struct({
|
|
59
|
+
title: Schema.String,
|
|
60
|
+
createdAt: Schema.String,
|
|
61
|
+
assignee: Schema.optional(Type.Ref(Person)),
|
|
62
|
+
}).pipe(Type.Obj({ typename: 'dxos.org/type/Task', version: '0.1.0' }));
|
|
63
|
+
|
|
64
|
+
export interface Task extends Schema.Schema.Type<typeof Task> {}
|
|
@@ -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
|
+
};
|