@dxos/echo 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0

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 (51) hide show
  1. package/dist/lib/browser/index.mjs +76 -26
  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 +77 -25
  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 +76 -26
  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/type/Obj.d.ts +12 -0
  21. package/dist/types/src/type/Obj.d.ts.map +1 -0
  22. package/dist/types/src/type/Ref.d.ts +3 -0
  23. package/dist/types/src/type/Ref.d.ts.map +1 -0
  24. package/dist/types/src/type/Relation.d.ts +16 -0
  25. package/dist/types/src/type/Relation.d.ts.map +1 -0
  26. package/dist/types/src/type/Type.d.ts +77 -0
  27. package/dist/types/src/type/Type.d.ts.map +1 -0
  28. package/dist/types/src/{api.test.d.ts.map → type/api.test.d.ts.map} +1 -1
  29. package/dist/types/src/type/index.d.ts +5 -0
  30. package/dist/types/src/type/index.d.ts.map +1 -0
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +14 -14
  33. package/src/{Database.ts → experimental/database.ts} +1 -1
  34. package/src/experimental/index.ts +7 -0
  35. package/src/{Queue.ts → experimental/queue.ts} +1 -1
  36. package/src/index.ts +3 -7
  37. package/src/type/Obj.ts +18 -0
  38. package/src/type/Ref.ts +7 -0
  39. package/src/type/Relation.ts +17 -0
  40. package/src/type/Type.ts +134 -0
  41. package/src/type/api.test.ts +128 -0
  42. package/src/type/index.ts +8 -0
  43. package/dist/types/src/Database.d.ts.map +0 -1
  44. package/dist/types/src/Queue.d.ts.map +0 -1
  45. package/dist/types/src/Space.d.ts.map +0 -1
  46. package/dist/types/src/Type.d.ts +0 -49
  47. package/dist/types/src/Type.d.ts.map +0 -1
  48. package/src/Type.ts +0 -99
  49. package/src/api.test.ts +0 -92
  50. /package/dist/types/src/{api.test.d.ts → type/api.test.d.ts} +0 -0
  51. /package/src/{Space.ts → experimental/space.ts} +0 -0
@@ -5,4 +5,4 @@
5
5
  * @since 0.9.0
6
6
  */
7
7
  export declare namespace Queue { }
8
- //# sourceMappingURL=Queue.d.ts.map
8
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../../src/experimental/queue.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,yBAAiB,KAAK,CAAC,GAAE"}
@@ -5,4 +5,4 @@
5
5
  * @since 0.9.0
6
6
  */
7
7
  export declare namespace Space { }
8
- //# sourceMappingURL=Space.d.ts.map
8
+ //# sourceMappingURL=space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../../../src/experimental/space.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC,GAAE"}
@@ -1,7 +1,4 @@
1
- import { DXN } from '@dxos/keys';
2
- export { DXN };
3
- export * as Database from './Database';
4
- export * as Queue from './Queue';
5
- export * as Space from './Space';
6
- export * as Type from './Type';
1
+ export { Format, FormatEnum } from '@dxos/echo-schema';
2
+ export { DXN } from '@dxos/keys';
3
+ export * from './type';
7
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,GAAG,EAAE,CAAC;AAEf,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type AnyLiveObject as AnyLiveObject$ } from '@dxos/echo-db';
2
+ import { type BaseEchoObject, type BaseObject } from '@dxos/echo-schema';
3
+ export declare namespace Obj {
4
+ type Any = BaseEchoObject;
5
+ type Live<T extends BaseObject> = AnyLiveObject$<T>;
6
+ }
7
+ export declare const create: {
8
+ <T extends BaseObject>(obj: T): import("@dxos/live-object").Live<T>;
9
+ <T extends BaseObject>(schema: import("effect/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>;
10
+ };
11
+ export declare const getSchema: (obj: unknown | undefined) => import("effect/Schema").Schema.AnyNoContext | undefined;
12
+ //# sourceMappingURL=Obj.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Obj.d.ts","sourceRoot":"","sources":["../../../../src/type/Obj.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AAKlG,MAAM,CAAC,OAAO,WAAW,GAAG,CAAC;IAC3B,KAAY,GAAG,GAAG,cAAc,CAAC;IACjC,KAAY,IAAI,CAAC,CAAC,SAAS,UAAU,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,MAAM;;;CAAQ,CAAC;AAE5B,eAAO,MAAM,SAAS,uFAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Ref as Ref$ } from '@dxos/echo-schema';
2
+ export declare const make: <T extends import("@dxos/echo-schema").WithId>(object: T) => Ref$<T>;
3
+ //# sourceMappingURL=Ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../../src/type/Ref.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEhD,eAAO,MAAM,IAAI,sEAAY,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type RelationSourceTargetRefs } from '@dxos/echo-schema';
2
+ export declare const def: <TSource extends import("effect/Schema").Schema.AnyNoContext, TTarget extends import("effect/Schema").Schema.AnyNoContext>(options: {
3
+ typename: string;
4
+ version: string;
5
+ source: TSource;
6
+ target: TTarget;
7
+ }) => <Self extends import("effect/Schema").Schema.Any>(self: Self) => import("@dxos/echo-schema").EchoTypeSchema<Self, RelationSourceTargetRefs<import("effect/Schema").Schema.Type<TSource>, import("effect/Schema").Schema.Type<TTarget>>>;
8
+ /**
9
+ * Get relation target type.
10
+ */
11
+ export type Target<A> = A extends RelationSourceTargetRefs<infer T, infer _S> ? T : never;
12
+ /**
13
+ * Get relation source type.
14
+ */
15
+ export type Source<A> = A extends RelationSourceTargetRefs<infer _T, infer S> ? S : never;
16
+ //# sourceMappingURL=Relation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Relation.d.ts","sourceRoot":"","sources":["../../../../src/type/Relation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAEhF,eAAO,MAAM,GAAG;;;;;6OAAe,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,wBAAwB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,wBAAwB,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { type Schema } from 'effect';
2
+ import { type AnyLiveObject as AnyLiveObject$ } from '@dxos/echo-db';
3
+ import { type BaseEchoObject, type BaseObject, type BaseSchema, type EchoSchema, EntityKind, Expando as Expando$, type ImmutableSchema, type JsonSchemaType, ObjectId as ObjectId$, type StoredSchema, type TypeMeta } from '@dxos/echo-schema';
4
+ import { SpaceId as SpaceId$ } from '@dxos/keys';
5
+ /**
6
+ * Type System API.
7
+ *
8
+ * @category api namespace
9
+ * @since 0.9.0
10
+ */
11
+ export declare const SpaceId: Schema.Schema<SpaceId$, string, never> & {
12
+ byteLength: number;
13
+ encode: (value: Uint8Array) => SpaceId$;
14
+ decode: (value: SpaceId$) => Uint8Array;
15
+ isValid: (value: string) => value is SpaceId$;
16
+ random: () => SpaceId$;
17
+ };
18
+ export type SpaceId = SpaceId$;
19
+ export declare const ObjectId: import("@dxos/echo-schema").ObjectIdClass;
20
+ export type ObjectId = ObjectId$;
21
+ /**
22
+ * Defines a reference to an ECHO object.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { Type } from '@dxos/echo';
27
+ * const Person = Schema.Struct({
28
+ * name: Schema.String,
29
+ * organization: Type.Ref(Organization),
30
+ * }).pipe(Type.def({
31
+ * typename: 'example.com/type/Person',
32
+ * version: '0.1.0',
33
+ * }));
34
+ * ```
35
+ */
36
+ export declare const Ref: <S extends Schema.Schema.AnyNoContext>(self: S) => import("@dxos/echo-schema").Ref$<Schema.Schema.Type<S>>;
37
+ export declare const Kind: typeof EntityKind;
38
+ export type AnyObject = BaseEchoObject;
39
+ export type AnyLiveObject<T extends BaseObject> = AnyLiveObject$<T>;
40
+ export type JsonSchema = JsonSchemaType;
41
+ /**
42
+ * A schema that can be extended with arbitrary properties.
43
+ */
44
+ export declare const Expando: Schema.Schema<Expando$, Expando$, never>;
45
+ export type Expando = Expando$;
46
+ export type Abstract<T = any> = BaseSchema<T>;
47
+ export type ImmutableType<T> = ImmutableSchema<T>;
48
+ export type MutableType<T> = EchoSchema<T>;
49
+ export type StoredType = StoredSchema;
50
+ /**
51
+ * Defines an ECHO type.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { Type } from '@dxos/echo';
56
+ * const Organization = Schema.Struct({
57
+ * name: Schema.String,
58
+ * }).pipe(Type.def({
59
+ * typename: 'example.com/type/Organization',
60
+ * version: '0.1.0',
61
+ * }));
62
+ * ```
63
+ */
64
+ export declare const def: (meta: TypeMeta) => <Self extends Schema.Schema.Any>(self: Self) => import("@dxos/echo-schema").EchoTypeSchema<Self>;
65
+ export declare const create: {
66
+ <T extends BaseObject>(obj: T): import("@dxos/live-object").Live<T>;
67
+ <T extends 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>;
68
+ };
69
+ export declare const getSchema: (obj: unknown | undefined) => Schema.Schema.AnyNoContext | undefined;
70
+ export declare const instanceOf: <Schema extends Schema.Schema.AnyNoContext>(schema: Schema, object: any) => object is Schema.Schema.Type<Schema>;
71
+ export declare const getDXN: (schema: Schema.Schema.All) => import("@dxos/keys").DXN | undefined;
72
+ export declare const getMeta: (schema: Schema.Schema.All) => import("@dxos/echo-schema").TypeAnnotation | undefined;
73
+ export declare const getTypename: (schema: Schema.Schema.AnyNoContext) => string;
74
+ export declare const getVersion: (schema: Schema.Schema.All) => string | undefined;
75
+ export declare const isMutable: (schema: Schema.Schema.AnyNoContext) => boolean;
76
+ export declare const toJsonSchema: (schema: Schema.Schema.All) => JsonSchemaType;
77
+ //# sourceMappingURL=Type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Type.d.ts","sourceRoot":"","sources":["../../../../src/type/Type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,KAAK,aAAa,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,UAAU,EAEf,UAAU,EACV,OAAO,IAAI,QAAQ,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,QAAQ,IAAI,SAAS,EAErB,KAAK,YAAY,EACjB,KAAK,QAAQ,EASd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGjD;;;;;GAKG;AAMH,eAAO,MAAM,OAAO;;;;;;CAAW,CAAC;AAChC,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC;AAE/B,eAAO,MAAM,QAAQ,2CAAY,CAAC;AAClC,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC;AAEjC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,4DAAsC,CAAC;AAMxG,eAAO,MAAM,IAAI,mBAAa,CAAC;AAC/B,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC;AACvC,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAMpE,MAAM,MAAM,UAAU,GAAG,cAAc,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,OAAO,0CAAW,CAAC;AAChC,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC;AAG/B,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAC9C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;AAClD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAC3C,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,GAAG,GAAI,MAAM,QAAQ,qGAAqB,CAAC;AAMxD,eAAO,MAAM,MAAM;;;CAAQ,CAAC;AAE5B,eAAO,MAAM,SAAS,sEAAa,CAAC;AACpC,eAAO,MAAM,UAAU,kHAAe,CAAC;AAOvC,eAAO,MAAM,MAAM,qEAAe,CAAC;AACnC,eAAO,MAAM,OAAO,uFAAoB,CAAC;AACzC,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,CAAC,MAAM,CAAC,YAAY,KAAG,MAIhE,CAAC;AACF,eAAO,MAAM,UAAU,mDAAmB,CAAC;AAC3C,eAAO,MAAM,SAAS,iDAAa,CAAC;AACpC,eAAO,MAAM,YAAY,+CAAgB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.test.d.ts","sourceRoot":"","sources":["../../../src/api.test.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"api.test.d.ts","sourceRoot":"","sources":["../../../../src/type/api.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * as Obj from './Obj';
2
+ export * as Ref from './Ref';
3
+ export * as Relation from './Relation';
4
+ export * as Type from './Type';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/type/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":"5.7.3"}
1
+ {"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo",
3
- "version": "0.8.2-main.f11618f",
3
+ "version": "0.8.2-main.fbd8ed0",
4
4
  "description": "ECHO API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -22,19 +22,19 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@preact/signals-core": "^1.6.0",
25
- "effect": "3.13.3",
26
- "@dxos/debug": "0.8.2-main.f11618f",
27
- "@dxos/echo-schema": "0.8.2-main.f11618f",
28
- "@dxos/echo-protocol": "0.8.2-main.f11618f",
29
- "@dxos/echo-signals": "0.8.2-main.f11618f",
30
- "@dxos/echo-db": "0.8.2-main.f11618f",
31
- "@dxos/effect": "0.8.2-main.f11618f",
32
- "@dxos/invariant": "0.8.2-main.f11618f",
33
- "@dxos/live-object": "0.8.2-main.f11618f",
34
- "@dxos/log": "0.8.2-main.f11618f",
35
- "@dxos/node-std": "0.8.2-main.f11618f",
36
- "@dxos/util": "0.8.2-main.f11618f",
37
- "@dxos/keys": "0.8.2-main.f11618f"
25
+ "effect": "3.14.21",
26
+ "@dxos/debug": "0.8.2-main.fbd8ed0",
27
+ "@dxos/echo-db": "0.8.2-main.fbd8ed0",
28
+ "@dxos/echo-protocol": "0.8.2-main.fbd8ed0",
29
+ "@dxos/echo-schema": "0.8.2-main.fbd8ed0",
30
+ "@dxos/echo-signals": "0.8.2-main.fbd8ed0",
31
+ "@dxos/invariant": "0.8.2-main.fbd8ed0",
32
+ "@dxos/keys": "0.8.2-main.fbd8ed0",
33
+ "@dxos/live-object": "0.8.2-main.fbd8ed0",
34
+ "@dxos/log": "0.8.2-main.fbd8ed0",
35
+ "@dxos/effect": "0.8.2-main.fbd8ed0",
36
+ "@dxos/node-std": "0.8.2-main.fbd8ed0",
37
+ "@dxos/util": "0.8.2-main.fbd8ed0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
@@ -8,4 +8,4 @@
8
8
  * @category api namespace
9
9
  * @since 0.9.0
10
10
  */
11
- export declare namespace Database {}
11
+ export namespace Database {}
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // export type { Database } from './database';
6
+ // export type { Queue } from './queue';
7
+ // export type { Space } from './space';
@@ -8,4 +8,4 @@
8
8
  * @category api namespace
9
9
  * @since 0.9.0
10
10
  */
11
- export declare namespace Queue {}
11
+ export namespace Queue {}
package/src/index.ts CHANGED
@@ -2,11 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { DXN } from '@dxos/keys';
5
+ export { Format, FormatEnum } from '@dxos/echo-schema';
6
+ export { DXN } from '@dxos/keys';
6
7
 
7
- export { DXN };
8
-
9
- export * as Database from './Database';
10
- export * as Queue from './Queue';
11
- export * as Space from './Space';
12
- export * as Type from './Type';
8
+ export * from './type';
@@ -0,0 +1,18 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type AnyLiveObject as AnyLiveObject$ } from '@dxos/echo-db';
6
+ import { type BaseEchoObject, type BaseObject, getSchema as getSchema$ } from '@dxos/echo-schema';
7
+ import { live as live$ } from '@dxos/live-object';
8
+
9
+ // TODO(burdon): Remove from Type?
10
+
11
+ export declare namespace Obj {
12
+ export type Any = BaseEchoObject;
13
+ export type Live<T extends BaseObject> = AnyLiveObject$<T>;
14
+ }
15
+
16
+ export const create = live$;
17
+
18
+ export const getSchema = getSchema$;
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Ref as Ref$ } from '@dxos/echo-schema';
6
+
7
+ export const make = Ref$.make;
@@ -0,0 +1,17 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { EchoRelation, type RelationSourceTargetRefs } from '@dxos/echo-schema';
6
+
7
+ export const def = EchoRelation;
8
+
9
+ /**
10
+ * Get relation target type.
11
+ */
12
+ export type Target<A> = A extends RelationSourceTargetRefs<infer T, infer _S> ? T : never;
13
+
14
+ /**
15
+ * Get relation source type.
16
+ */
17
+ export type Source<A> = A extends RelationSourceTargetRefs<infer _T, infer S> ? S : never;
@@ -0,0 +1,134 @@
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
+ type StoredSchema,
21
+ type TypeMeta,
22
+ getTypeAnnotation,
23
+ getSchema as getSchema$,
24
+ getSchemaDXN,
25
+ getSchemaTypename,
26
+ getSchemaVersion,
27
+ isInstanceOf,
28
+ isMutable as isMutable$,
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
+ /**
36
+ * Type System API.
37
+ *
38
+ * @category api namespace
39
+ * @since 0.9.0
40
+ */
41
+
42
+ //
43
+ // Keys
44
+ //
45
+
46
+ export const SpaceId = SpaceId$;
47
+ export type SpaceId = SpaceId$;
48
+
49
+ export const ObjectId = ObjectId$;
50
+ export type ObjectId = ObjectId$;
51
+
52
+ /**
53
+ * Defines a reference to an ECHO object.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { Type } from '@dxos/echo';
58
+ * const Person = Schema.Struct({
59
+ * name: Schema.String,
60
+ * organization: Type.Ref(Organization),
61
+ * }).pipe(Type.def({
62
+ * typename: 'example.com/type/Person',
63
+ * version: '0.1.0',
64
+ * }));
65
+ * ```
66
+ */
67
+ export const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);
68
+
69
+ //
70
+ // Objects
71
+ //
72
+
73
+ export const Kind = EntityKind;
74
+ export type AnyObject = BaseEchoObject;
75
+ export type AnyLiveObject<T extends BaseObject> = AnyLiveObject$<T>;
76
+
77
+ //
78
+ // Schema
79
+ //
80
+
81
+ export type JsonSchema = JsonSchemaType;
82
+
83
+ /**
84
+ * A schema that can be extended with arbitrary properties.
85
+ */
86
+ export const Expando = Expando$;
87
+ export type Expando = Expando$;
88
+
89
+ // TODO(burdon): Review/remove.
90
+ export type Abstract<T = any> = BaseSchema<T>;
91
+ export type ImmutableType<T> = ImmutableSchema<T>;
92
+ export type MutableType<T> = EchoSchema<T>;
93
+ export type StoredType = StoredSchema;
94
+
95
+ /**
96
+ * Defines an ECHO type.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { Type } from '@dxos/echo';
101
+ * const Organization = Schema.Struct({
102
+ * name: Schema.String,
103
+ * }).pipe(Type.def({
104
+ * typename: 'example.com/type/Organization',
105
+ * version: '0.1.0',
106
+ * }));
107
+ * ```
108
+ */
109
+ export const def = (meta: TypeMeta) => EchoObject(meta);
110
+
111
+ //
112
+ // Object utils
113
+ //
114
+
115
+ export const create = live$;
116
+
117
+ export const getSchema = getSchema$;
118
+ export const instanceOf = isInstanceOf;
119
+
120
+ //
121
+ // Type utils
122
+ //
123
+
124
+ // TODO(burdon): Reconcile getDXN and getTypename.
125
+ export const getDXN = getSchemaDXN;
126
+ export const getMeta = getTypeAnnotation;
127
+ export const getTypename = (schema: Schema.Schema.AnyNoContext): string => {
128
+ const typename = getSchemaTypename(schema);
129
+ invariant(typename, 'Invalid object');
130
+ return typename;
131
+ };
132
+ export const getVersion = getSchemaVersion;
133
+ export const isMutable = isMutable$;
134
+ export const toJsonSchema = toJsonSchema$;
@@ -0,0 +1,128 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Schema } 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
+ import { Obj, Ref, Type } from '.';
12
+
13
+ namespace Testing {
14
+ export const Organization = Schema.Struct({
15
+ id: Type.ObjectId,
16
+ name: Schema.String,
17
+ }).pipe(
18
+ Type.def({
19
+ typename: 'example.com/type/Organization',
20
+ version: '0.1.0',
21
+ }),
22
+ );
23
+
24
+ export interface Organization extends Schema.Schema.Type<typeof Organization> {}
25
+
26
+ export const Person = Schema.Struct({
27
+ name: Schema.String,
28
+ dob: Schema.optional(Schema.String),
29
+ email: Schema.optional(Schema.String.pipe(FormatAnnotation.set(FormatEnum.Email))),
30
+ organization: Schema.optional(Type.Ref(Organization)),
31
+ }).pipe(
32
+ Type.def({
33
+ typename: 'example.com/type/Person',
34
+ version: '0.1.0',
35
+ }),
36
+ );
37
+
38
+ export interface Person extends Schema.Schema.Type<typeof Person> {}
39
+
40
+ // export const WorksFor = S.Struct({
41
+ // id: Type.ObjectId,
42
+ // since: S.String,
43
+ // jobTitle: S.String,
44
+ // ...Range({ from, to }),
45
+ // ...Provenance({ source: 'duckduckgo.com', confidence: 0.9 }), // keys
46
+ // ...Relation.make({ source: Contact, target: Organization }),
47
+ // }).pipe(
48
+ // Relation.def({
49
+ // typename: 'example.com/relation/WorksFor',
50
+ // version: '0.1.0',
51
+ // }),
52
+ // );
53
+
54
+ // {
55
+ // const contact = db.add(create(Contact, { name: 'Test' }));
56
+ // const organization = db.add(create(Organization, { name: 'DXOS' }));
57
+ // db.add(create(WorksFor, { source: contact, target: organization }));
58
+ // }
59
+
60
+ export const WorksFor = Schema.Struct({
61
+ // id: Type.ObjectId,
62
+ role: Schema.String,
63
+ }).pipe(
64
+ // Relation.def
65
+ Type.def({
66
+ typename: 'example.com/type/WorksFor',
67
+ version: '0.1.0',
68
+ // source: Person,
69
+ // target: Organization,
70
+ }),
71
+ );
72
+
73
+ export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
74
+
75
+ // TODO(burdon): Fix (Type.def currently removes TypeLiteral that implements the `make` function).
76
+ // Property 'make' does not exist on type 'EchoObjectSchema<Struct<{ timestamp: PropertySignature<":", string, never, ":", string, true, never>; }>>'.ts(2339)
77
+ export const MessageStruct = Schema.Struct({
78
+ // TODO(burdon): Support S.Date; Custom Timestamp (with defaults).
79
+ // TODO(burdon): Support defaults (update create and create).
80
+ timestamp: Schema.String.pipe(
81
+ Schema.propertySignature,
82
+ Schema.withConstructorDefault(() => new Date().toISOString()),
83
+ ),
84
+ });
85
+
86
+ export const Message = MessageStruct.pipe(
87
+ Type.def({
88
+ typename: 'example.com/type/Message',
89
+ version: '0.1.0',
90
+ }),
91
+ );
92
+
93
+ export interface Message extends Schema.Schema.Type<typeof Message> {}
94
+ }
95
+
96
+ describe('Experimental API review', () => {
97
+ test('type checks', ({ expect }) => {
98
+ const contact = Obj.create(Testing.Person, { name: 'Test' });
99
+ const type: Schema.Schema<Testing.Person> = Obj.getSchema(contact) ?? raise(new Error('No schema found'));
100
+
101
+ expect(Type.getDXN(type)?.typename).to.eq(Testing.Person.typename);
102
+ expect(Type.getTypename(type)).to.eq('example.com/type/Person');
103
+ expect(Type.getVersion(type)).to.eq('0.1.0');
104
+ expect(Type.getMeta(type)).to.deep.eq({
105
+ kind: Type.Kind.Object,
106
+ typename: 'example.com/type/Person',
107
+ version: '0.1.0',
108
+ });
109
+ });
110
+
111
+ test('instance checks', ({ expect }) => {
112
+ const organization: Obj.Obj.Live<Testing.Organization> = Obj.create(Testing.Organization, { name: 'DXOS' });
113
+ const contact: Obj.Obj.Live<Testing.Person> = Obj.create(Testing.Person, {
114
+ name: 'Test',
115
+ organization: Ref.make(organization),
116
+ });
117
+
118
+ expect(Schema.is(Testing.Person)(contact)).to.be.true;
119
+ expect(Testing.Person.instanceOf(contact)).to.be.true;
120
+ expect(Type.instanceOf(Testing.Person, contact)).to.be.true;
121
+ expect(Type.instanceOf(Testing.Organization, organization)).to.be.true;
122
+ });
123
+
124
+ test('default props', ({ expect }) => {
125
+ const message = Obj.create(Testing.Message, Testing.MessageStruct.make({}));
126
+ expect(message.timestamp).to.exist;
127
+ });
128
+ });
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * as Obj from './Obj';
6
+ export * as Ref from './Ref';
7
+ export * as Relation from './Relation';
8
+ export * as Type from './Type';
@@ -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"}