@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
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