@dxos/echo 0.8.3-main.672df60 → 0.8.3-staging.0fa589b

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 (57) hide show
  1. package/README.md +25 -23
  2. package/dist/lib/browser/chunk-UYPR62ZB.mjs +624 -0
  3. package/dist/lib/browser/chunk-UYPR62ZB.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +11 -280
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +70 -0
  8. package/dist/lib/browser/testing/index.mjs.map +7 -0
  9. package/dist/lib/node/chunk-4HQE2F3L.cjs +644 -0
  10. package/dist/lib/node/chunk-4HQE2F3L.cjs.map +7 -0
  11. package/dist/lib/node/index.cjs +11 -282
  12. package/dist/lib/node/index.cjs.map +4 -4
  13. package/dist/lib/node/meta.json +1 -1
  14. package/dist/lib/node/testing/index.cjs +89 -0
  15. package/dist/lib/node/testing/index.cjs.map +7 -0
  16. package/dist/lib/node-esm/chunk-BYBICDIO.mjs +624 -0
  17. package/dist/lib/node-esm/chunk-BYBICDIO.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +11 -280
  19. package/dist/lib/node-esm/index.mjs.map +4 -4
  20. package/dist/lib/node-esm/meta.json +1 -1
  21. package/dist/lib/node-esm/testing/index.mjs +70 -0
  22. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  23. package/dist/types/src/Key.d.ts +2 -0
  24. package/dist/types/src/Key.d.ts.map +1 -0
  25. package/dist/types/src/Obj.d.ts +37 -18
  26. package/dist/types/src/Obj.d.ts.map +1 -1
  27. package/dist/types/src/Ref.d.ts +9 -3
  28. package/dist/types/src/Ref.d.ts.map +1 -1
  29. package/dist/types/src/Relation.d.ts +36 -10
  30. package/dist/types/src/Relation.d.ts.map +1 -1
  31. package/dist/types/src/Type.d.ts +82 -17
  32. package/dist/types/src/Type.d.ts.map +1 -1
  33. package/dist/types/src/index.d.ts +5 -3
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/query/dsl.d.ts +218 -0
  36. package/dist/types/src/query/dsl.d.ts.map +1 -0
  37. package/dist/types/src/query/dsl.test.d.ts +2 -0
  38. package/dist/types/src/query/dsl.test.d.ts.map +1 -0
  39. package/dist/types/src/query/index.d.ts +2 -0
  40. package/dist/types/src/query/index.d.ts.map +1 -0
  41. package/dist/types/src/testing/index.d.ts +2 -0
  42. package/dist/types/src/testing/index.d.ts.map +1 -0
  43. package/dist/types/src/testing/types.d.ts +113 -0
  44. package/dist/types/src/testing/types.d.ts.map +1 -0
  45. package/package.json +56 -12
  46. package/src/Key.ts +5 -0
  47. package/src/Obj.ts +66 -25
  48. package/src/Ref.ts +9 -6
  49. package/src/Relation.ts +75 -13
  50. package/src/Type.ts +122 -18
  51. package/src/index.ts +5 -3
  52. package/src/query/dsl.test.ts +323 -0
  53. package/src/query/dsl.ts +646 -0
  54. package/src/query/index.ts +5 -0
  55. package/src/test/api.test.ts +54 -9
  56. package/src/testing/index.ts +5 -0
  57. package/src/testing/types.ts +91 -0
@@ -8,7 +8,7 @@ import { describe, test } from 'vitest';
8
8
  import { raise } from '@dxos/debug';
9
9
  import { FormatEnum, FormatAnnotation } from '@dxos/echo-schema';
10
10
 
11
- import { Obj, Ref, Type, type Live } from '../index';
11
+ import { Obj, Ref, Relation, Type, type Live } from '../index';
12
12
 
13
13
  namespace Testing {
14
14
  export const Organization = Schema.Struct({
@@ -61,12 +61,11 @@ namespace Testing {
61
61
  // id: Type.ObjectId,
62
62
  role: Schema.String,
63
63
  }).pipe(
64
- // Type.Relation
65
- Type.Obj({
66
- typename: 'example.com/type/WorksFor',
64
+ Type.Relation({
65
+ typename: 'example.com/relation/WorksFor',
67
66
  version: '0.1.0',
68
- // source: Person,
69
- // target: Organization,
67
+ source: Person,
68
+ target: Organization,
70
69
  }),
71
70
  );
72
71
 
@@ -116,13 +115,59 @@ describe('Experimental API review', () => {
116
115
  });
117
116
 
118
117
  expect(Schema.is(Testing.Person)(contact)).to.be.true;
119
- expect(Testing.Person.instanceOf(contact)).to.be.true;
120
- expect(Obj.instanceOf(Testing.Person)(contact)).to.be.true;
121
- expect(Obj.instanceOf(Testing.Organization)(organization)).to.be.true;
118
+ expect(Obj.instanceOf(Testing.Person, contact)).to.be.true;
119
+ expect(Obj.instanceOf(Testing.Organization, organization)).to.be.true;
120
+
121
+ const isPerson = Obj.instanceOf(Testing.Person);
122
+ const x: any = {};
123
+ if (isPerson(x)) {
124
+ x.name;
125
+ }
122
126
  });
123
127
 
124
128
  test('default props', ({ expect }) => {
125
129
  const message = Obj.make(Testing.Message, Testing.MessageStruct.make({}));
126
130
  expect(message.timestamp).to.exist;
127
131
  });
132
+
133
+ test('Obj.isObject', ({ expect }) => {
134
+ const guy = Obj.make(Testing.Person, { name: 'Test' });
135
+ expect(Obj.isObject(guy)).to.be.true;
136
+ expect(Obj.isObject(null)).to.be.false;
137
+ expect(Obj.isObject(undefined)).to.be.false;
138
+ expect(Obj.isObject(1)).to.be.false;
139
+ expect(Obj.isObject('string')).to.be.false;
140
+ });
141
+
142
+ test('create relation', ({ expect }) => {
143
+ const person = Obj.make(Testing.Person, { name: 'Test' });
144
+ const organization = Obj.make(Testing.Organization, { name: 'DXOS' });
145
+ const worksFor = Relation.make(Testing.WorksFor, {
146
+ [Relation.Source]: person,
147
+ [Relation.Target]: organization,
148
+ role: 'CEO',
149
+ });
150
+ expect(Relation.getSource(worksFor)).to.eq(person);
151
+ expect(Relation.getTarget(worksFor)).to.eq(organization);
152
+ });
153
+
154
+ test.skip('type narrowing', () => {
155
+ const a: Obj.Any | Relation.Any = null as any;
156
+
157
+ {
158
+ if (Obj.isObject(a)) {
159
+ a;
160
+ } else {
161
+ a;
162
+ }
163
+ }
164
+
165
+ {
166
+ if (Relation.isRelation(a)) {
167
+ a;
168
+ } else {
169
+ a;
170
+ }
171
+ }
172
+ });
128
173
  });
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './types';
@@ -0,0 +1,91 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Schema } from 'effect';
6
+
7
+ import { Type } from '..';
8
+
9
+ // TODO(burdon): These are non-canonical test types, so we really shouldn't export and use in other classes (compare with @dxos/sdk/testing).
10
+ export namespace Testing {
11
+ const _Contact = Schema.Struct({
12
+ name: Schema.String,
13
+ username: Schema.String,
14
+ email: Schema.String,
15
+ tasks: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task)))),
16
+ address: Schema.Struct({
17
+ city: Schema.optional(Schema.String),
18
+ state: Schema.optional(Schema.String),
19
+ zip: Schema.optional(Schema.String),
20
+ coordinates: Schema.Struct({
21
+ lat: Schema.optional(Schema.Number),
22
+ lng: Schema.optional(Schema.Number),
23
+ }),
24
+ }),
25
+ }).pipe(
26
+ Schema.partial,
27
+ Type.Obj({
28
+ typename: 'example.com/type/Contact',
29
+ version: '0.1.0',
30
+ }),
31
+ );
32
+ export interface Contact extends Schema.Schema.Type<typeof _Contact> {}
33
+ export const Contact: Schema.Schema<Contact, Schema.Schema.Encoded<typeof _Contact>, never> = _Contact;
34
+
35
+ const _Task = Schema.Struct({
36
+ title: Schema.optional(Schema.String),
37
+ completed: Schema.optional(Schema.Boolean),
38
+ assignee: Schema.optional(Type.Ref(Contact)),
39
+ previous: Schema.optional(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))),
40
+ subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))))),
41
+ description: Schema.optional(Schema.String),
42
+ }).pipe(
43
+ Schema.partial,
44
+ Type.Obj({
45
+ typename: 'example.com/type/Task',
46
+ version: '0.1.0',
47
+ }),
48
+ );
49
+ export interface Task extends Schema.Schema.Type<typeof _Task> {}
50
+ export const Task: Schema.Schema<Task, Schema.Schema.Encoded<typeof _Task>, never> = _Task;
51
+
52
+ export enum RecordType {
53
+ UNDEFINED = 0,
54
+ PERSONAL = 1,
55
+ WORK = 2,
56
+ }
57
+
58
+ export const Container = Schema.Struct({
59
+ objects: Schema.mutable(Schema.Array(Type.Ref(Type.Expando))),
60
+ records: Schema.mutable(
61
+ Schema.Array(
62
+ Schema.partial(
63
+ Schema.Struct({
64
+ title: Schema.String,
65
+ description: Schema.String,
66
+ contacts: Schema.mutable(Schema.Array(Type.Ref(Contact))),
67
+ type: Schema.Enums(RecordType),
68
+ }),
69
+ ),
70
+ ),
71
+ ),
72
+ }).pipe(
73
+ Schema.partial,
74
+ Type.Obj({
75
+ typename: 'example.com/type/Container',
76
+ version: '0.1.0',
77
+ }),
78
+ );
79
+
80
+ export const WorksFor = Schema.Struct({
81
+ since: Schema.optional(Schema.String),
82
+ }).pipe(
83
+ Type.Relation({
84
+ typename: 'example.com/type/WorksFor',
85
+ version: '0.1.0',
86
+ source: Contact,
87
+ target: Contact,
88
+ }),
89
+ );
90
+ export interface WorksFor extends Schema.Schema.Type<typeof WorksFor> {}
91
+ }