@dxos/echo-generator 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-generator",
3
- "version": "0.8.4-main.d05539e30a",
3
+ "version": "0.8.4-main.d9fc60f731",
4
4
  "description": "ECHO data generator for testing.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -25,23 +25,21 @@
25
25
  "src"
26
26
  ],
27
27
  "dependencies": {
28
- "@automerge/automerge": "3.2.6",
29
- "effect": "3.20.0",
30
- "@dxos/client": "0.8.4-main.d05539e30a",
31
- "@dxos/context": "0.8.4-main.d05539e30a",
32
- "@dxos/echo": "0.8.4-main.d05539e30a",
33
- "@dxos/echo-db": "0.8.4-main.d05539e30a",
34
- "@dxos/log": "0.8.4-main.d05539e30a",
35
- "@dxos/invariant": "0.8.4-main.d05539e30a",
36
- "@dxos/node-std": "0.8.4-main.d05539e30a",
37
- "@dxos/util": "0.8.4-main.d05539e30a"
28
+ "@automerge/automerge": "3.3.0-fragments.1",
29
+ "effect": "3.21.2",
30
+ "@dxos/echo": "0.8.4-main.d9fc60f731",
31
+ "@dxos/client": "0.8.4-main.d9fc60f731",
32
+ "@dxos/echo-db": "0.8.4-main.d9fc60f731",
33
+ "@dxos/invariant": "0.8.4-main.d9fc60f731",
34
+ "@dxos/util": "0.8.4-main.d9fc60f731",
35
+ "@dxos/node-std": "0.8.4-main.d9fc60f731"
38
36
  },
39
37
  "devDependencies": {
40
- "@dxos/random": "0.8.4-main.d05539e30a"
38
+ "@dxos/random": "0.8.4-main.d9fc60f731"
41
39
  },
42
40
  "peerDependencies": {
43
- "effect": "3.20.0",
44
- "@dxos/random": "0.8.4-main.d05539e30a"
41
+ "effect": "3.21.2",
42
+ "@dxos/random": "0.8.4-main.d9fc60f731"
45
43
  },
46
44
  "publishConfig": {
47
45
  "access": "public"
package/src/data.ts CHANGED
@@ -6,7 +6,7 @@ import { next as A } from '@automerge/automerge';
6
6
  import * as Schema from 'effect/Schema';
7
7
 
8
8
  import { type Space } from '@dxos/client/echo';
9
- import { Ref, Type } from '@dxos/echo';
9
+ import { DXN, Ref, Type } from '@dxos/echo';
10
10
  import { createDocAccessor } from '@dxos/echo-db';
11
11
  import { random } from '@dxos/random';
12
12
 
@@ -38,13 +38,13 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
38
38
  const document = Schema.Struct({
39
39
  title: Schema.String.annotations({ description: 'title of the document' }),
40
40
  content: Schema.String,
41
- }).pipe(Type.object({ typename: TestSchemaType.document, version: '0.1.0' }));
41
+ }).pipe(Type.makeObject(DXN.make(TestSchemaType.document, '0.1.0')));
42
42
 
43
43
  const organization = Schema.Struct({
44
44
  name: Schema.String.annotations({ description: 'name of the company or organization' }),
45
45
  website: Schema.optional(Schema.String.annotations({ description: 'public website URL' })),
46
46
  description: Schema.String.annotations({ description: 'short summary of the company' }),
47
- }).pipe(Type.object({ typename: TestSchemaType.organization, version: '0.1.0' }));
47
+ }).pipe(Type.makeObject(DXN.make(TestSchemaType.organization, '0.1.0')));
48
48
 
49
49
  const contact = Schema.Struct({
50
50
  name: Schema.String.annotations({ description: 'name of the person' }),
@@ -52,7 +52,7 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
52
52
  org: Schema.optional(Ref.Ref(organization)),
53
53
  lat: Schema.optional(Schema.Number),
54
54
  lng: Schema.optional(Schema.Number),
55
- }).pipe(Type.object({ typename: TestSchemaType.contact, version: '0.1.0' }));
55
+ }).pipe(Type.makeObject(DXN.make(TestSchemaType.contact, '0.1.0')));
56
56
 
57
57
  const project = Schema.Struct({
58
58
  name: Schema.String.annotations({ description: 'name of the project' }),
@@ -63,7 +63,7 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
63
63
  priority: Schema.Number,
64
64
  active: Schema.Boolean,
65
65
  org: Schema.optional(Ref.Ref(organization)),
66
- }).pipe(Type.object({ typename: TestSchemaType.project, version: '0.1.0' }));
66
+ }).pipe(Type.makeObject(DXN.make(TestSchemaType.project, '0.1.0')));
67
67
 
68
68
  return {
69
69
  [TestSchemaType.document]: document,
@@ -7,7 +7,7 @@ import * as Schema from 'effect/Schema';
7
7
  import { describe, expect, onTestFinished, test } from 'vitest';
8
8
 
9
9
  import { Client } from '@dxos/client';
10
- import { Obj, Type } from '@dxos/echo';
10
+ import { DXN, Obj, Type } from '@dxos/echo';
11
11
  import { getObjectCore } from '@dxos/echo-db';
12
12
  import { random } from '@dxos/random';
13
13
 
@@ -43,7 +43,7 @@ describe('TestObjectGenerator', () => {
43
43
 
44
44
  // Create org object.
45
45
  const organization = await generator.createObject({ types: [TestSchemaType.organization] });
46
- expect(Obj.getTypeDXN(organization)).to.exist;
46
+ expect(Obj.getTypeURI(organization)).to.exist;
47
47
 
48
48
  // Expect at least one person object with a linked org reference.
49
49
  const objects = await generator.createObjects({ [TestSchemaType.contact]: 10 });
@@ -59,14 +59,14 @@ describe('TestObjectGenerator', () => {
59
59
  const generator = createSpaceObjectGenerator(space);
60
60
  await generator.addSchemas();
61
61
  const organization = await generator.createObject({ types: [TestSchemaType.organization] });
62
- schemaId.push(Obj.getTypeDXN(organization)!.toString());
62
+ schemaId.push(Obj.getTypeURI(organization)!.toString());
63
63
  }
64
64
 
65
65
  {
66
66
  const generator = createSpaceObjectGenerator(space);
67
67
  await generator.addSchemas();
68
68
  const organization = await generator.createObject({ types: [TestSchemaType.organization] });
69
- schemaId.push(Obj.getTypeDXN(organization)!.toString());
69
+ schemaId.push(Obj.getTypeURI(organization)!.toString());
70
70
  }
71
71
 
72
72
  expect(schemaId[0]).not.to.be.undefined;
@@ -79,7 +79,7 @@ describe('TestObjectGenerator', () => {
79
79
  const generator = createSpaceObjectGenerator(space);
80
80
  await generator.addSchemas();
81
81
  const document = await generator.createObject({ types: [TestSchemaType.document] });
82
- expect(Obj.getTypeDXN(document)).to.exist;
82
+ expect(Obj.getTypeURI(document)).to.exist;
83
83
 
84
84
  const beforeChangesCount = A.getAllChanges(getObjectCore(document).docHandle!.doc()).length;
85
85
 
@@ -95,12 +95,7 @@ describe('TestObjectGenerator', () => {
95
95
  test('create object with in memory schema', async () => {
96
96
  const Task = Schema.Struct({
97
97
  name: Schema.optional(Schema.String),
98
- }).pipe(
99
- Type.object({
100
- typename: 'com.example.type.task',
101
- version: '0.1.0',
102
- }),
103
- );
98
+ }).pipe(Type.makeObject(DXN.make('com.example.type.task', '0.1.0')));
104
99
 
105
100
  enum Types {
106
101
  task = 'com.example.type.task',
@@ -126,7 +121,7 @@ describe('TestObjectGenerator', () => {
126
121
  await generator.addSchemas();
127
122
 
128
123
  const todo = await generator.createObject({ types: [Types.task] });
129
- expect(Obj.getTypeDXN(todo)).to.exist;
124
+ expect(Obj.getTypeURI(todo)).to.exist;
130
125
  });
131
126
 
132
127
  test('references', async () => {
@@ -146,7 +141,7 @@ describe('TestObjectGenerator', () => {
146
141
  test('create project', async () => {
147
142
  const generator = createTestObjectGenerator();
148
143
  const project = await generator.createObject({ types: [TestSchemaType.project] });
149
- expect(Obj.getTypeDXN(project)).to.exist;
144
+ expect(Obj.getTypeURI(project)).to.exist;
150
145
  });
151
146
 
152
147
  test('create object with not type', async () => {
package/src/generator.ts CHANGED
@@ -3,8 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type Space } from '@dxos/client/echo';
6
- import { Filter, Obj, type Type } from '@dxos/echo';
7
- import { EchoSchema, getTypeAnnotation } from '@dxos/echo/internal';
6
+ import { Filter, Obj, Type } from '@dxos/echo';
8
7
  import { isProxy } from '@dxos/echo/internal';
9
8
  import { invariant } from '@dxos/invariant';
10
9
  import { random } from '@dxos/random';
@@ -36,10 +35,10 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
36
35
  }
37
36
 
38
37
  getSchema(type: T): Type.AnyObj | undefined {
39
- return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);
38
+ return this.schemas.find((schema) => Type.getTypename(schema) === type);
40
39
  }
41
40
 
42
- protected setSchema(type: T, schema: Type.AnyObj): void {
41
+ protected setSchema(type: T, schema: Type.AnyEntity): void {
43
42
  this._schemas[type] = schema;
44
43
  }
45
44
 
@@ -90,7 +89,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
90
89
  }
91
90
 
92
91
  async addSchemas() {
93
- const result: Type.AnyObj[] = [];
92
+ const result: Type.AnyEntity[] = [];
94
93
  for (const [typename, schema] of Object.entries(this._schemas)) {
95
94
  const echoSchema = await this._maybeRegisterSchema(typename, schema as Type.AnyObj);
96
95
  this.setSchema(typename as T, echoSchema);
@@ -108,27 +107,34 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
108
107
  return this._space.db.add(await super.createObject({ types }));
109
108
  }
110
109
 
111
- private async _maybeRegisterSchema(typename: string, schema: Type.AnyObj): Promise<Type.AnyObj> {
112
- if (schema instanceof EchoSchema) {
113
- const existingSchema = this._space.internal.db.schemaRegistry.getSchema(typename);
110
+ private async _maybeRegisterSchema(typename: string, schema: Type.AnyObj): Promise<Type.AnyEntity> {
111
+ if (Type.isTypeKind(schema)) {
112
+ const types = this._space.internal.db.graph.registry.list().filter(Type.isType);
113
+ const version = Type.getVersion(schema);
114
+ const existingSchema = types.find(
115
+ (t) => Type.isTypeKind(t) && Type.getTypename(t) === typename && Type.getVersion(t) === version,
116
+ );
114
117
  if (existingSchema != null) {
115
118
  return existingSchema;
116
119
  }
117
- const [registeredSchema] = await this._space.internal.db.schemaRegistry.register([schema]);
118
- return registeredSchema;
120
+ return this._space.internal.db.addType(schema);
119
121
  } else {
120
- const existingSchema = this._space.internal.db.graph.schemaRegistry.getSchema(typename);
122
+ const allTypes = this._space.internal.db.graph.registry.list().filter(Type.isType);
123
+ const version = Type.getVersion(schema);
124
+ const existingSchema = [...allTypes].find(
125
+ (s) => Type.getTypename(s) === typename && Type.getVersion(s) === version,
126
+ );
121
127
  if (existingSchema != null) {
122
128
  return existingSchema;
123
129
  }
124
- await this._space.internal.db.graph.schemaRegistry.register([schema]);
130
+ this._space.internal.db.graph.registry.add([schema]);
125
131
  return schema;
126
132
  }
127
133
  }
128
134
 
129
135
  async mutateObject(object: Obj.Any, params: MutationsProviderProps): Promise<void> {
130
136
  invariant(this._mutations, 'Mutations not defined.');
131
- const type = getTypeAnnotation(Obj.getSchema(object)!)!.typename as T;
137
+ const type = Type.getTypename(Obj.getType(object)!) as T;
132
138
  invariant(type && this._mutations?.[type], 'Invalid object type.');
133
139
 
134
140
  await this._mutations![type](object, params);
package/src/types.ts CHANGED
@@ -7,7 +7,7 @@ import { type Obj, type Type } from '@dxos/echo';
7
7
  // TODO(burdon): Use echo-schema types.
8
8
  export type TestObject = { id: string } & Record<string, any>;
9
9
 
10
- export type TestSchemaMap<T extends string = string> = Record<T, Type.AnyObj>;
10
+ export type TestSchemaMap<T extends string = string> = Record<T, Type.AnyEntity>;
11
11
 
12
12
  export type TestObjectProvider<T extends string = string> = (type: T) => Promise<any[]>;
13
13