@dxos/echo 0.8.4-main.84f28bd → 0.8.4-main.ae835ea
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/README.md +1 -1
- package/dist/lib/browser/chunk-JUTFUT73.mjs +175 -0
- package/dist/lib/browser/chunk-JUTFUT73.mjs.map +7 -0
- package/dist/lib/browser/chunk-KEBVBR65.mjs +3727 -0
- package/dist/lib/browser/chunk-KEBVBR65.mjs.map +7 -0
- package/dist/lib/browser/chunk-WO76TDT6.mjs +814 -0
- package/dist/lib/browser/chunk-WO76TDT6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +17 -4
- 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/query/index.mjs +15 -0
- package/dist/lib/browser/query/index.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +245 -32
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-DWZYQ2UR.mjs +3727 -0
- package/dist/lib/node-esm/chunk-DWZYQ2UR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KBD3A2I6.mjs +175 -0
- package/dist/lib/node-esm/chunk-KBD3A2I6.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ZSSII3JW.mjs +814 -0
- package/dist/lib/node-esm/chunk-ZSSII3JW.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +17 -4
- 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/query/index.mjs +15 -0
- package/dist/lib/node-esm/query/index.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +245 -32
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Obj.d.ts +123 -16
- 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 +11 -8
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +17 -18
- 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 -1
- 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 +131 -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} +52 -22
- 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 +34 -16
- package/src/Obj.ts +279 -29
- package/src/Ref.ts +1 -2
- package/src/Relation.ts +25 -13
- package/src/Type.ts +32 -31
- package/src/errors.ts +18 -0
- package/src/index.ts +4 -1
- package/src/internal/ast/annotation-helper.ts +22 -0
- package/src/internal/ast/annotations.test.ts +98 -0
- package/src/internal/ast/annotations.ts +226 -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} +188 -45
- package/src/query/tag.ts +37 -0
- package/src/test/api.test.ts +17 -10
- 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-SVSJEELN.mjs +0 -619
- package/dist/lib/browser/chunk-SVSJEELN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-53HXWYR6.mjs +0 -619
- package/dist/lib/node-esm/chunk-53HXWYR6.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 -323
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { QueryAST } from '@dxos/echo-protocol';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
10
|
+
import { log } from '@dxos/log';
|
|
11
|
+
|
|
12
|
+
import * as Obj from '../Obj';
|
|
13
|
+
import * as Ref from '../Ref';
|
|
14
|
+
import * as Type from '../Type';
|
|
15
|
+
|
|
16
|
+
import { Filter, Order, Query } from './query';
|
|
17
|
+
|
|
18
|
+
//
|
|
19
|
+
// Example schema
|
|
20
|
+
//
|
|
21
|
+
|
|
22
|
+
// TODO(dmaretskyi): Need common set of test types.
|
|
23
|
+
const Person = Schema.Struct({
|
|
24
|
+
name: Schema.String,
|
|
25
|
+
email: Schema.optional(Schema.String),
|
|
26
|
+
age: Schema.optional(Schema.Number),
|
|
27
|
+
fields: Schema.Struct({
|
|
28
|
+
label: Schema.String,
|
|
29
|
+
value: Schema.String,
|
|
30
|
+
}).pipe(Schema.Array, Schema.optional),
|
|
31
|
+
}).pipe(
|
|
32
|
+
Type.Obj({
|
|
33
|
+
typename: 'dxos.org/type/Person',
|
|
34
|
+
version: '0.1.0',
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
38
|
+
|
|
39
|
+
const Organization = Schema.Struct({
|
|
40
|
+
name: Schema.String,
|
|
41
|
+
properties: Schema.optional(
|
|
42
|
+
Schema.Record({
|
|
43
|
+
key: Schema.String,
|
|
44
|
+
value: Schema.String,
|
|
45
|
+
}),
|
|
46
|
+
),
|
|
47
|
+
}).pipe(
|
|
48
|
+
Type.Obj({
|
|
49
|
+
typename: 'dxos.org/type/Organization',
|
|
50
|
+
version: '0.1.0',
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
54
|
+
|
|
55
|
+
const WorksFor = Schema.Struct({
|
|
56
|
+
since: Schema.String,
|
|
57
|
+
}).pipe(
|
|
58
|
+
Type.Relation({
|
|
59
|
+
typename: 'dxos.org/type/WorksFor',
|
|
60
|
+
version: '0.1.0',
|
|
61
|
+
source: Person,
|
|
62
|
+
target: Organization,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
|
|
66
|
+
|
|
67
|
+
const Task = Schema.Struct({
|
|
68
|
+
title: Schema.String,
|
|
69
|
+
createdAt: Schema.String,
|
|
70
|
+
assignee: Schema.optional(Type.Ref(Person)),
|
|
71
|
+
}).pipe(Type.Obj({ typename: 'dxos.org/type/Task', version: '0.1.0' }));
|
|
72
|
+
interface Task extends Schema.Schema.Type<typeof Task> {}
|
|
73
|
+
|
|
74
|
+
//
|
|
75
|
+
// Example queries
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
describe('query api', () => {
|
|
79
|
+
describe('Query', () => {
|
|
80
|
+
test('get all people', () => {
|
|
81
|
+
const getAllPeople = Query.type(Person);
|
|
82
|
+
|
|
83
|
+
log('query', { ast: getAllPeople.ast });
|
|
84
|
+
Schema.validateSync(QueryAST.Query)(getAllPeople.ast);
|
|
85
|
+
console.log('getAllPeople', JSON.stringify(getAllPeople.ast, null, 2));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('get all people ordered by name', () => {
|
|
89
|
+
const getAllPeopleOrderedByName = Query.type(Person).orderBy(Order.property('name', 'asc'));
|
|
90
|
+
|
|
91
|
+
log('query', { ast: getAllPeopleOrderedByName.ast });
|
|
92
|
+
Schema.validateSync(QueryAST.Query)(getAllPeopleOrderedByName.ast);
|
|
93
|
+
console.log('getAllPeopleOrderedByName', JSON.stringify(getAllPeopleOrderedByName.ast, null, 2));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('get all people named Fred', () => {
|
|
97
|
+
const PeopleNamedFred = Query.select(Filter.type(Person, { name: 'Fred' }));
|
|
98
|
+
|
|
99
|
+
log('query', { ast: PeopleNamedFred.ast });
|
|
100
|
+
Schema.validateSync(QueryAST.Query)(PeopleNamedFred.ast);
|
|
101
|
+
console.log('PeopleNamedFred', JSON.stringify(PeopleNamedFred.ast, null, 2));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('get all people with field of "label" set to "Research"', () => {
|
|
105
|
+
const PeopleWithFieldLabelSetToResearch = Query.select(
|
|
106
|
+
Filter.type(Person, { fields: Filter.contains({ label: 'label', value: 'Research' }) }),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
log('query', { ast: PeopleWithFieldLabelSetToResearch.ast });
|
|
110
|
+
Schema.validateSync(QueryAST.Query)(PeopleWithFieldLabelSetToResearch.ast);
|
|
111
|
+
console.log('PeopleWithFieldLabelSetToResearch', JSON.stringify(PeopleWithFieldLabelSetToResearch.ast, null, 2));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('get all orgs with property "label" set to "Research"', () => {
|
|
115
|
+
const OrgsWithPropertyLabelSetToResearch = Query.select(
|
|
116
|
+
Filter.type(Organization, { properties: { label: 'Research' } }),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
log('query', { ast: OrgsWithPropertyLabelSetToResearch.ast });
|
|
120
|
+
Schema.validateSync(QueryAST.Query)(OrgsWithPropertyLabelSetToResearch.ast);
|
|
121
|
+
console.log(
|
|
122
|
+
'OrgsWithPropertyLabelSetToResearch',
|
|
123
|
+
JSON.stringify(OrgsWithPropertyLabelSetToResearch.ast, null, 2),
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('get all orgs Fred worked for since 2020', () => {
|
|
128
|
+
const fred = Obj.make(Person, { name: 'Fred' });
|
|
129
|
+
const OrganizationsFredWorkedForSince2020 = Query.select(Filter.type(Person, { id: fred.id }))
|
|
130
|
+
.sourceOf(WorksFor, { since: Filter.gt('2020') })
|
|
131
|
+
.target();
|
|
132
|
+
|
|
133
|
+
log('query', { ast: OrganizationsFredWorkedForSince2020.ast });
|
|
134
|
+
Schema.validateSync(QueryAST.Query)(OrganizationsFredWorkedForSince2020.ast);
|
|
135
|
+
console.log(
|
|
136
|
+
'OrganizationsFredWorkedForSince2020',
|
|
137
|
+
JSON.stringify(OrganizationsFredWorkedForSince2020.ast, null, 2),
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('get all tasks for Fred', () => {
|
|
142
|
+
const fred = Obj.make(Person, { name: 'Fred' });
|
|
143
|
+
const TasksForFred = Query.select(Filter.type(Person, { id: fred.id })).referencedBy(Task, 'assignee');
|
|
144
|
+
|
|
145
|
+
log('query', { ast: TasksForFred.ast });
|
|
146
|
+
Schema.validateSync(QueryAST.Query)(TasksForFred.ast);
|
|
147
|
+
console.log('TasksForFred', JSON.stringify(TasksForFred.ast, null, 2));
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('get all tasks for employees of Cyberdyne', () => {
|
|
151
|
+
const TasksForEmployeesOfCyberdyne = Query.select(Filter.type(Organization, { name: 'Cyberdyne' }))
|
|
152
|
+
.targetOf(WorksFor)
|
|
153
|
+
.source()
|
|
154
|
+
.referencedBy(Task, 'assignee');
|
|
155
|
+
|
|
156
|
+
log('query', { ast: TasksForEmployeesOfCyberdyne.ast });
|
|
157
|
+
Schema.validateSync(QueryAST.Query)(TasksForEmployeesOfCyberdyne.ast);
|
|
158
|
+
console.log('TasksForEmployeesOfCyberdyne', JSON.stringify(TasksForEmployeesOfCyberdyne.ast, null, 2));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('get all people or orgs', () => {
|
|
162
|
+
const PeopleOrOrganizations = Query.all(
|
|
163
|
+
Query.select(Filter.type(Person)),
|
|
164
|
+
Query.select(Filter.type(Organization)),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
log('query', { ast: PeopleOrOrganizations.ast });
|
|
168
|
+
Schema.validateSync(QueryAST.Query)(PeopleOrOrganizations.ast);
|
|
169
|
+
console.log('PeopleOrOrganizations', JSON.stringify(PeopleOrOrganizations.ast, null, 2));
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('get all people not in orgs', () => {
|
|
173
|
+
const PeopleNotInOrganizations = Query.without(
|
|
174
|
+
Query.select(Filter.type(Person)),
|
|
175
|
+
Query.select(Filter.type(Person)).sourceOf(WorksFor).source(),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
log('query', { ast: PeopleNotInOrganizations.ast });
|
|
179
|
+
Schema.validateSync(QueryAST.Query)(PeopleNotInOrganizations.ast);
|
|
180
|
+
console.log('PeopleNotInOrganizations', JSON.stringify(PeopleNotInOrganizations.ast, null, 2));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('get assignees of all tasks created after 2020', () => {
|
|
184
|
+
const AssigneesOfAllTasksCreatedAfter2020 = Query.select(
|
|
185
|
+
Filter.type(Task, { createdAt: Filter.gt('2020') }),
|
|
186
|
+
).reference('assignee');
|
|
187
|
+
|
|
188
|
+
log('query', { ast: AssigneesOfAllTasksCreatedAfter2020.ast });
|
|
189
|
+
Schema.validateSync(QueryAST.Query)(AssigneesOfAllTasksCreatedAfter2020.ast);
|
|
190
|
+
console.log(
|
|
191
|
+
'AssigneesOfAllTasksCreatedAfter2020',
|
|
192
|
+
JSON.stringify(AssigneesOfAllTasksCreatedAfter2020.ast, null, 2),
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('untyped full-text search', () => {
|
|
197
|
+
const contactFullTextSearch = Query.select(Filter.text('Bill'));
|
|
198
|
+
|
|
199
|
+
log('query', { ast: contactFullTextSearch.ast });
|
|
200
|
+
Schema.validateSync(QueryAST.Query)(contactFullTextSearch.ast);
|
|
201
|
+
expect(contactFullTextSearch.ast).toMatchInlineSnapshot(`
|
|
202
|
+
{
|
|
203
|
+
"filter": {
|
|
204
|
+
"searchKind": undefined,
|
|
205
|
+
"text": "Bill",
|
|
206
|
+
"type": "text-search",
|
|
207
|
+
},
|
|
208
|
+
"type": "select",
|
|
209
|
+
}
|
|
210
|
+
`);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('typed full-text search', () => {
|
|
214
|
+
const contactFullTextSearch = Query.select(Filter.type(Person)).select(Filter.text('Bill'));
|
|
215
|
+
|
|
216
|
+
log('query', { ast: contactFullTextSearch.ast });
|
|
217
|
+
Schema.validateSync(QueryAST.Query)(contactFullTextSearch.ast);
|
|
218
|
+
expect(contactFullTextSearch.ast).toMatchInlineSnapshot(`
|
|
219
|
+
{
|
|
220
|
+
"filter": {
|
|
221
|
+
"searchKind": undefined,
|
|
222
|
+
"text": "Bill",
|
|
223
|
+
"type": "text-search",
|
|
224
|
+
},
|
|
225
|
+
"selection": {
|
|
226
|
+
"filter": {
|
|
227
|
+
"id": undefined,
|
|
228
|
+
"props": {},
|
|
229
|
+
"type": "object",
|
|
230
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
231
|
+
},
|
|
232
|
+
"type": "select",
|
|
233
|
+
},
|
|
234
|
+
"type": "filter",
|
|
235
|
+
}
|
|
236
|
+
`);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('filter by ref', () => {
|
|
240
|
+
const fred = Obj.make(Person, { name: 'Fred' });
|
|
241
|
+
const tasksByFred = Filter.type(Task, { assignee: Ref.make(fred) });
|
|
242
|
+
expect(tasksByFred.ast).toEqual({
|
|
243
|
+
props: {
|
|
244
|
+
assignee: {
|
|
245
|
+
operator: 'eq',
|
|
246
|
+
type: 'compare',
|
|
247
|
+
value: {
|
|
248
|
+
'/': DXN.fromLocalObjectId(fred.id).toString(),
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
type: 'object',
|
|
253
|
+
typename: 'dxn:type:dxos.org/type/Task:0.1.0',
|
|
254
|
+
});
|
|
255
|
+
console.log('tasksByFred', JSON.stringify(tasksByFred.ast, null, 2));
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('select orgs and people', () => {
|
|
259
|
+
const orgsAndPeople = Query.select(Filter.or(Filter.type(Organization), Filter.type(Person)));
|
|
260
|
+
|
|
261
|
+
Schema.validateSync(QueryAST.Query)(orgsAndPeople.ast);
|
|
262
|
+
expect(orgsAndPeople.ast).toMatchInlineSnapshot(`
|
|
263
|
+
{
|
|
264
|
+
"filter": {
|
|
265
|
+
"filters": [
|
|
266
|
+
{
|
|
267
|
+
"id": undefined,
|
|
268
|
+
"props": {},
|
|
269
|
+
"type": "object",
|
|
270
|
+
"typename": "dxn:type:dxos.org/type/Organization:0.1.0",
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"id": undefined,
|
|
274
|
+
"props": {},
|
|
275
|
+
"type": "object",
|
|
276
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
"type": "or",
|
|
280
|
+
},
|
|
281
|
+
"type": "select",
|
|
282
|
+
}
|
|
283
|
+
`);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('select everything but orgs and people', () => {
|
|
287
|
+
const everythingButOrgsAndPeople = Query.select(
|
|
288
|
+
Filter.not(Filter.or(Filter.type(Organization), Filter.type(Person))),
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
Schema.validateSync(QueryAST.Query)(everythingButOrgsAndPeople.ast);
|
|
292
|
+
expect(everythingButOrgsAndPeople.ast).toMatchInlineSnapshot(`
|
|
293
|
+
{
|
|
294
|
+
"filter": {
|
|
295
|
+
"filter": {
|
|
296
|
+
"filters": [
|
|
297
|
+
{
|
|
298
|
+
"id": undefined,
|
|
299
|
+
"props": {},
|
|
300
|
+
"type": "object",
|
|
301
|
+
"typename": "dxn:type:dxos.org/type/Organization:0.1.0",
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"id": undefined,
|
|
305
|
+
"props": {},
|
|
306
|
+
"type": "object",
|
|
307
|
+
"typename": "dxn:type:dxos.org/type/Person:0.1.0",
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
"type": "or",
|
|
311
|
+
},
|
|
312
|
+
"type": "not",
|
|
313
|
+
},
|
|
314
|
+
"type": "select",
|
|
315
|
+
}
|
|
316
|
+
`);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('select deleted tasks', () => {
|
|
320
|
+
const deletedTasks = Query.select(Filter.type(Task)).options({
|
|
321
|
+
deleted: 'only',
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
Schema.validateSync(QueryAST.Query)(deletedTasks.ast);
|
|
325
|
+
expect(deletedTasks.ast).toMatchInlineSnapshot(`
|
|
326
|
+
{
|
|
327
|
+
"options": {
|
|
328
|
+
"deleted": "only",
|
|
329
|
+
},
|
|
330
|
+
"query": {
|
|
331
|
+
"filter": {
|
|
332
|
+
"id": undefined,
|
|
333
|
+
"props": {},
|
|
334
|
+
"type": "object",
|
|
335
|
+
"typename": "dxn:type:dxos.org/type/Task:0.1.0",
|
|
336
|
+
},
|
|
337
|
+
"type": "select",
|
|
338
|
+
},
|
|
339
|
+
"type": "options",
|
|
340
|
+
}
|
|
341
|
+
`);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('filter by tags', () => {
|
|
345
|
+
const query = Query.select(Filter.type(Task)).select(Filter.tag('important'));
|
|
346
|
+
Schema.validateSync(QueryAST.Query)(query.ast);
|
|
347
|
+
expect(query.ast).toMatchInlineSnapshot(`
|
|
348
|
+
{
|
|
349
|
+
"filter": {
|
|
350
|
+
"tag": "important",
|
|
351
|
+
"type": "tag",
|
|
352
|
+
},
|
|
353
|
+
"selection": {
|
|
354
|
+
"filter": {
|
|
355
|
+
"id": undefined,
|
|
356
|
+
"props": {},
|
|
357
|
+
"type": "object",
|
|
358
|
+
"typename": "dxn:type:dxos.org/type/Task:0.1.0",
|
|
359
|
+
},
|
|
360
|
+
"type": "select",
|
|
361
|
+
},
|
|
362
|
+
"type": "filter",
|
|
363
|
+
}
|
|
364
|
+
`);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test.skip('chain', () => {
|
|
368
|
+
// NOTE: Can't support props without type since they can't be inferred.
|
|
369
|
+
// const f1: Filter<Person> = Filter.props({ name: 'Fred' });
|
|
370
|
+
|
|
371
|
+
// const x = Query.select(Filter.props({ id: '123' }));
|
|
372
|
+
const y = Query.select(Filter.type(Person));
|
|
373
|
+
|
|
374
|
+
const or = Filter.or(Filter.type(Person, { id: Filter.in('1', '2', '3') }), Filter.type(Organization));
|
|
375
|
+
|
|
376
|
+
const and = Filter.and(
|
|
377
|
+
Filter.type(Person, { id: Filter.in('1', '2', '3') }),
|
|
378
|
+
Filter.type(Person, { name: 'Fred' }),
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
const q = Query
|
|
382
|
+
//
|
|
383
|
+
// NOTE: Can't support functions since they can't be serialized (to server).
|
|
384
|
+
// .filter((object) => Math.random() > 0.5)
|
|
385
|
+
.select(Filter.type(Person))
|
|
386
|
+
.select(Filter.type(Person, { name: 'Fred' }))
|
|
387
|
+
.select({ age: Filter.between(20, 40) })
|
|
388
|
+
.select(Filter.and(Filter.type(Person), Filter.type(Person, { name: Filter.in('bob', 'bill') })));
|
|
389
|
+
|
|
390
|
+
log('stuff', { fOr: or, fAnd: and, q, y });
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
describe('Filter', () => {
|
|
395
|
+
test('Filter.or(Filter.typename(...))', () => {
|
|
396
|
+
const filter = Filter.or(Filter.typename('dxos.org/type/Person'));
|
|
397
|
+
// TODO(dmaretskyi): Give vitest type-tests a try.
|
|
398
|
+
const _isAssignable: Obj.Any = null as any as Filter.Type<typeof filter>;
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|