@dxos/echo 0.8.2-main.36232bc → 0.8.2-main.5ca3450

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.
Files changed (56) hide show
  1. package/dist/lib/browser/index.mjs +48 -33
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +48 -29
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +48 -33
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/{Database.d.ts → experimental/database.d.ts} +1 -1
  11. package/dist/types/src/experimental/database.d.ts.map +1 -0
  12. package/dist/types/src/experimental/index.d.ts +1 -0
  13. package/dist/types/src/experimental/index.d.ts.map +1 -0
  14. package/dist/types/src/{Queue.d.ts → experimental/queue.d.ts} +1 -1
  15. package/dist/types/src/experimental/queue.d.ts.map +1 -0
  16. package/dist/types/src/{Space.d.ts → experimental/space.d.ts} +1 -1
  17. package/dist/types/src/experimental/space.d.ts.map +1 -0
  18. package/dist/types/src/index.d.ts +3 -6
  19. package/dist/types/src/index.d.ts.map +1 -1
  20. package/dist/types/src/query/api.d.ts +116 -0
  21. package/dist/types/src/query/api.d.ts.map +1 -0
  22. package/dist/types/src/query/ast.d.ts +188 -0
  23. package/dist/types/src/query/ast.d.ts.map +1 -0
  24. package/dist/types/src/query/query.test.d.ts +2 -0
  25. package/dist/types/src/query/query.test.d.ts.map +1 -0
  26. package/dist/types/src/type/Relation.d.ts +16 -0
  27. package/dist/types/src/type/Relation.d.ts.map +1 -0
  28. package/dist/types/src/type/Type.d.ts +80 -0
  29. package/dist/types/src/type/Type.d.ts.map +1 -0
  30. package/dist/types/src/type/Type.test.d.ts +2 -0
  31. package/dist/types/src/type/Type.test.d.ts.map +1 -0
  32. package/dist/types/src/type/index.d.ts +3 -0
  33. package/dist/types/src/type/index.d.ts.map +1 -0
  34. package/dist/types/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +14 -14
  36. package/src/{Database.ts → experimental/database.ts} +1 -1
  37. package/src/experimental/index.ts +7 -0
  38. package/src/{Queue.ts → experimental/queue.ts} +1 -1
  39. package/src/index.ts +3 -7
  40. package/src/query/api.ts +291 -0
  41. package/src/query/ast.ts +149 -0
  42. package/src/query/query.test.ts +135 -0
  43. package/src/type/Relation.ts +17 -0
  44. package/src/type/Type.test.ts +106 -0
  45. package/src/type/Type.ts +143 -0
  46. package/src/type/index.ts +6 -0
  47. package/dist/types/src/Database.d.ts.map +0 -1
  48. package/dist/types/src/Queue.d.ts.map +0 -1
  49. package/dist/types/src/Space.d.ts.map +0 -1
  50. package/dist/types/src/Type.d.ts +0 -49
  51. package/dist/types/src/Type.d.ts.map +0 -1
  52. package/dist/types/src/api.test.d.ts +0 -2
  53. package/dist/types/src/api.test.d.ts.map +0 -1
  54. package/src/Type.ts +0 -99
  55. package/src/api.test.ts +0 -92
  56. /package/src/{Space.ts → experimental/space.ts} +0 -0
@@ -0,0 +1,143 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Schema } from 'effect';
6
+
7
+ import { type AnyLiveObject as AnyLiveObject$ } from '@dxos/echo-db';
8
+ import {
9
+ type BaseEchoObject,
10
+ type BaseObject,
11
+ type BaseSchema,
12
+ type EchoSchema,
13
+ EchoObject,
14
+ EntityKind,
15
+ Expando as Expando$,
16
+ type ImmutableSchema,
17
+ type JsonSchemaType,
18
+ ObjectId as ObjectId$,
19
+ Ref as Ref$,
20
+ SpaceIdSchema as SpaceIdSchema$,
21
+ type StoredSchema,
22
+ type TypeMeta,
23
+ getTypeAnnotation,
24
+ getSchema as getSchema$,
25
+ getSchemaDXN,
26
+ getSchemaTypename,
27
+ getSchemaVersion,
28
+ isInstanceOf,
29
+ toJsonSchema as toJsonSchema$,
30
+ } from '@dxos/echo-schema';
31
+ import { invariant } from '@dxos/invariant';
32
+ import { SpaceId as SpaceId$ } from '@dxos/keys';
33
+ import { live as live$ } from '@dxos/live-object';
34
+
35
+ // TODO(burdon): Type vs. Ref vs. Relation vs. Object.
36
+
37
+ /**
38
+ * Type System API.
39
+ *
40
+ * @category api namespace
41
+ * @since 0.9.0
42
+ */
43
+ export namespace Type {
44
+ //
45
+ // Keys
46
+ //
47
+
48
+ export const SpaceIdSchema = SpaceIdSchema$; // TODO(burdon): Reconcile with SpaceId as with ObjectId.
49
+ export const SpaceId = SpaceId$;
50
+ export type SpaceId = SpaceId$;
51
+
52
+ export const ObjectId = ObjectId$;
53
+ export type ObjectId = ObjectId$;
54
+
55
+ //
56
+ // Objects
57
+ //
58
+
59
+ export const Kind = EntityKind;
60
+ export type AnyObject = BaseEchoObject;
61
+ export type AnyLiveObject<T extends BaseObject> = AnyLiveObject$<T>;
62
+
63
+ //
64
+ // Schema
65
+ //
66
+
67
+ export type JsonSchema = JsonSchemaType;
68
+
69
+ /**
70
+ * A schema that can be extended with arbitrary properties.
71
+ */
72
+ export const Expando = Expando$;
73
+ export type Expando = Expando$;
74
+
75
+ // TODO(burdon): Review/remove.
76
+ export type Abstract<T = any> = BaseSchema<T>;
77
+ export type ImmutableType<T> = ImmutableSchema<T>;
78
+ export type MutableType<T> = EchoSchema<T>;
79
+ export type StoredType = StoredSchema;
80
+
81
+ export const create = live$;
82
+
83
+ /**
84
+ * Defines an ECHO type.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * import { Type } from '@dxos/echo';
89
+ * const Organization = Schema.Struct({
90
+ * name: Schema.String,
91
+ * }).pipe(Type.def({
92
+ * typename: 'example.com/type/Organization',
93
+ * version: '0.1.0',
94
+ * }));
95
+ * ```
96
+ */
97
+ export const def = (meta: TypeMeta) => EchoObject(meta);
98
+
99
+ //
100
+ // Refs
101
+ //
102
+
103
+ /**
104
+ * Defines a reference to an ECHO object.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import { Type } from '@dxos/echo';
109
+ * const Person = Schema.Struct({
110
+ * name: Schema.String,
111
+ * organization: Type.Ref(Organization),
112
+ * }).pipe(Type.def({
113
+ * typename: 'example.com/type/Person',
114
+ * version: '0.1.0',
115
+ * }));
116
+ * ```
117
+ */
118
+ export const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);
119
+
120
+ export const ref = Ref$.make;
121
+
122
+ //
123
+ // Object utils
124
+ //
125
+
126
+ export const getMeta = getTypeAnnotation;
127
+ export const getSchema = getSchema$;
128
+ export const instanceOf = isInstanceOf;
129
+
130
+ //
131
+ // Type utils
132
+ //
133
+
134
+ // TODO(burdon): Reconcile getDXN and getTypename.
135
+ export const getDXN = getSchemaDXN;
136
+ export const getTypename = (schema: Schema.Schema.AnyNoContext): string => {
137
+ const typename = getSchemaTypename(schema);
138
+ invariant(typename, 'Invalid object');
139
+ return typename;
140
+ };
141
+ export const getVersion = getSchemaVersion;
142
+ export const toJsonSchema = toJsonSchema$;
143
+ }
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export { Type } from './Type';
6
+ export * as Relation from './Relation';
@@ -1 +0,0 @@
1
- {"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../../src/Database.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC,GAAE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../../../src/Queue.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC,GAAE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Space.d.ts","sourceRoot":"","sources":["../../../src/Space.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC,GAAE"}
@@ -1,49 +0,0 @@
1
- import { type Schema } from 'effect';
2
- import { type BaseSchema, type EchoSchema, type Expando as Expando$, type ImmutableSchema, type JsonSchemaType, type TypeMeta, EntityKind, ObjectId, Ref as Ref$, getTypeAnnotation, getSchema, getSchemaDXN, getSchemaTypename, getSchemaVersion, isInstanceOf } from '@dxos/echo-schema';
3
- export type { TypeMeta as Meta, JsonSchemaType as JsonSchema };
4
- export { EntityKind as Kind, ObjectId, getTypeAnnotation as getMeta, getSchema, getSchemaDXN as getDXN, getSchemaTypename as getTypename, getSchemaVersion as getVersion, isInstanceOf as instanceOf, };
5
- /**
6
- * Type API.
7
- *
8
- * @category api namespace
9
- * @since 0.9.0
10
- */
11
- export declare namespace Type {
12
- /**
13
- * A schema that can be extended with arbitrary properties.
14
- */
15
- type Expando = Expando$;
16
- type Abstract<T = any> = BaseSchema<T>;
17
- type ImmutableType<T> = ImmutableSchema<T>;
18
- type MutableType<T> = EchoSchema<T>;
19
- }
20
- export declare const ref: <T extends import("@dxos/echo-schema").BaseObject>(obj: T) => Ref$<T>;
21
- export declare const create: {
22
- <T extends import("@dxos/echo-schema").BaseObject>(obj: T): import("@dxos/live-object").Live<T>;
23
- <T extends import("@dxos/echo-schema").BaseObject>(schema: Schema.Schema<T, any, never>, obj: NoInfer<import("@dxos/echo-schema").ExcludeId<T>>, meta?: import("@dxos/echo-schema").ObjectMeta): import("@dxos/live-object").Live<T>;
24
- };
25
- /**
26
- * Defines an ECHO type.
27
- *
28
- * @example
29
- * ```ts
30
- * const Organization = S.Struct({
31
- * name: S.String,
32
- * }).pipe(Type.def({ typename: 'example.com/type/Organization', version: '1.0.0' }));
33
- * ```
34
- */
35
- export declare const def: (meta: TypeMeta) => <Self extends Schema.Schema.Any>(self: Self) => import("@dxos/echo-schema").EchoObjectSchema<Self>;
36
- /**
37
- * Defines a reference to an ECHO object.
38
- *
39
- * @example
40
- * ```ts
41
- * import { Type } from '@dxos/echo';
42
- * const Contact = S.Struct({
43
- * name: S.String,
44
- * organization: Type.Ref(Organization),
45
- * }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));
46
- * ```
47
- */
48
- export declare const Ref: <S extends Schema.Schema.AnyNoContext>(self: S) => import("@dxos/echo-schema").Ref$<Schema.Schema.Type<S>>;
49
- //# sourceMappingURL=Type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Type.d.ts","sourceRoot":"","sources":["../../../src/Type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,QAAQ,EAEb,UAAU,EACV,QAAQ,EACR,GAAG,IAAI,IAAI,EACX,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAW3B,YAAY,EAAE,QAAQ,IAAI,IAAI,EAAE,cAAc,IAAI,UAAU,EAAE,CAAC;AAC/D,OAAO,EACL,UAAU,IAAI,IAAI,EAClB,QAAQ,EACR,iBAAiB,IAAI,OAAO,EAC5B,SAAS,EACT,YAAY,IAAI,MAAM,EACtB,iBAAiB,IAAI,WAAW,EAChC,gBAAgB,IAAI,UAAU,EAC9B,YAAY,IAAI,UAAU,GAC3B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B;;OAEG;IACH,KAAY,OAAO,GAAG,QAAQ,CAAC;IAE/B,KAAY,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,KAAY,aAAa,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;IAClD,KAAY,WAAW,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;CAC5C;AAMD,eAAO,MAAM,GAAG,uEAAU,CAAC;AAC3B,eAAO,MAAM,MAAM;;;CAAU,CAAC;AAM9B;;;;;;;;;GASG;AACH,eAAO,MAAM,GAAG,SAAU,QAAQ,uGAAqB,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,YAAY,QAAQ,CAAC,4DAAsC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=api.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.test.d.ts","sourceRoot":"","sources":["../../../src/api.test.ts"],"names":[],"mappings":""}
package/src/Type.ts DELETED
@@ -1,99 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type Schema } from 'effect';
6
-
7
- import {
8
- type BaseSchema,
9
- type EchoSchema,
10
- type Expando as Expando$,
11
- type ImmutableSchema,
12
- type JsonSchemaType,
13
- type TypeMeta,
14
- EchoObject,
15
- EntityKind,
16
- ObjectId,
17
- Ref as Ref$,
18
- getTypeAnnotation,
19
- getSchema,
20
- getSchemaDXN,
21
- getSchemaTypename,
22
- getSchemaVersion,
23
- isInstanceOf,
24
- } from '@dxos/echo-schema';
25
- import { live as create$, makeRef } from '@dxos/live-object';
26
-
27
- // NOTES:
28
- // - New Echo package and namespaces allow for incremental migration; vastly simplifies imports.
29
- // - Split into separate ECHO namespaces: Database, Space, Type, Query, Queue.
30
- // - Example; import { Database, Type, Query, Queue } from '@dxos/echo';
31
- // - Use `declare namespace` for types (no code is generated). See Effect pattern, where Schema is a namespace, interface, and function.
32
- // - Test with @dxos/schema/testing types.
33
- // - Define user (Composer) types in namespace (e.g., of plugin) and drop Type suffix; remove all deprecated Braneframe types.
34
-
35
- export type { TypeMeta as Meta, JsonSchemaType as JsonSchema };
36
- export {
37
- EntityKind as Kind,
38
- ObjectId,
39
- getTypeAnnotation as getMeta,
40
- getSchema,
41
- getSchemaDXN as getDXN,
42
- getSchemaTypename as getTypename,
43
- getSchemaVersion as getVersion,
44
- isInstanceOf as instanceOf,
45
- };
46
-
47
- /**
48
- * Type API.
49
- *
50
- * @category api namespace
51
- * @since 0.9.0
52
- */
53
- export declare namespace Type {
54
- /**
55
- * A schema that can be extended with arbitrary properties.
56
- */
57
- export type Expando = Expando$;
58
-
59
- export type Abstract<T = any> = BaseSchema<T>;
60
- export type ImmutableType<T> = ImmutableSchema<T>;
61
- export type MutableType<T> = EchoSchema<T>;
62
- }
63
-
64
- //
65
- // Constructors
66
- //
67
-
68
- export const ref = makeRef;
69
- export const create = create$;
70
-
71
- //
72
- // Combinators
73
- //
74
-
75
- /**
76
- * Defines an ECHO type.
77
- *
78
- * @example
79
- * ```ts
80
- * const Organization = S.Struct({
81
- * name: S.String,
82
- * }).pipe(Type.def({ typename: 'example.com/type/Organization', version: '1.0.0' }));
83
- * ```
84
- */
85
- export const def = (meta: TypeMeta) => EchoObject(meta);
86
-
87
- /**
88
- * Defines a reference to an ECHO object.
89
- *
90
- * @example
91
- * ```ts
92
- * import { Type } from '@dxos/echo';
93
- * const Contact = S.Struct({
94
- * name: S.String,
95
- * organization: Type.Ref(Organization),
96
- * }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));
97
- * ```
98
- */
99
- export const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);
package/src/api.test.ts DELETED
@@ -1,92 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema as S } from 'effect';
6
- import { describe, test } from 'vitest';
7
-
8
- import { raise } from '@dxos/debug';
9
- import { FormatEnum, FormatAnnotation } from '@dxos/echo-schema';
10
-
11
- // Deliberately testing top-level import as if external consumer for @dxos/echo.
12
- import { Type } from '.';
13
-
14
- namespace Testing {
15
- export const Organization = S.Struct({
16
- id: Type.ObjectId,
17
- name: S.String,
18
- }).pipe(
19
- Type.def({
20
- typename: 'example.com/type/Organization',
21
- version: '0.1.0',
22
- }),
23
- );
24
-
25
- export interface Organization extends S.Schema.Type<typeof Organization> {}
26
-
27
- export const Contact = S.Struct({
28
- name: S.String,
29
- dob: S.optional(S.String),
30
- email: S.optional(S.String.pipe(FormatAnnotation.set(FormatEnum.Email))),
31
- organization: S.optional(Type.Ref(Organization)),
32
- }).pipe(
33
- Type.def({
34
- typename: 'example.com/type/Contact',
35
- version: '0.1.0',
36
- }),
37
- );
38
-
39
- export interface Contact extends S.Schema.Type<typeof Contact> {}
40
-
41
- export const Message = S.Struct({
42
- // TODO(burdon): Support S.Date; Custom Timestamp (with defaults).
43
- // TODO(burdon): Support defaults (update create and create).
44
- timestamp: S.String.pipe(
45
- S.propertySignature,
46
- S.withConstructorDefault(() => new Date().toISOString()),
47
- ),
48
- });
49
-
50
- // TODO(burdon): Fix (Type.def currently removes TypeLiteral that implements the `make` function)..
51
- // }).pipe(
52
- // Type.def({
53
- // typename: 'example.com/type/Message',
54
- // version: '0.1.0',
55
- // }),
56
- // );
57
-
58
- export interface Message extends S.Schema.Type<typeof Message> {}
59
- }
60
-
61
- describe('Experimental API review', () => {
62
- test('type checks', ({ expect }) => {
63
- const contact = Type.create(Testing.Contact, { name: 'Test' });
64
- const type: S.Schema<Testing.Contact> = Type.getSchema(contact) ?? raise(new Error('No schema found'));
65
-
66
- expect(Type.getDXN(type)?.typename).to.eq(Testing.Contact.typename);
67
- expect(Type.getTypename(type)).to.eq('example.com/type/Contact');
68
- expect(Type.getVersion(type)).to.eq('0.1.0');
69
- expect(Type.getMeta(type)).to.deep.eq({
70
- kind: Type.Kind.Object,
71
- typename: 'example.com/type/Contact',
72
- version: '0.1.0',
73
- });
74
- });
75
-
76
- test('instance checks', ({ expect }) => {
77
- const organization = Type.create(Testing.Organization, { name: 'DXOS' });
78
- const contact = Type.create(Testing.Contact, { name: 'Test', organization: Type.ref(organization) });
79
-
80
- expect(S.is(Testing.Contact)(contact)).to.be.true;
81
- expect(Testing.Contact.instanceOf(contact)).to.be.true;
82
- expect(Type.instanceOf(Testing.Contact, contact)).to.be.true;
83
- expect(Type.instanceOf(Testing.Organization, organization)).to.be.true;
84
- });
85
-
86
- test('default props', ({ expect }) => {
87
- // TODO(burdon): Doesn't work after pipe(Type.def).
88
- // Property 'make' does not exist on type 'EchoObjectSchema<Struct<{ timestamp: PropertySignature<":", string, never, ":", string, true, never>; }>>'.ts(2339)
89
- const message = Type.create(Testing.Message, Testing.Message.make({}));
90
- expect(message.timestamp).to.exist;
91
- });
92
- });
File without changes