@dxos/echo-generator 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b
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/dist/lib/browser/index.mjs +31 -24
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +31 -24
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/data.d.ts +1 -1
- package/dist/types/src/data.d.ts.map +1 -1
- package/dist/types/src/generator.d.ts +3 -3
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +2 -2
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -14
- package/src/data.ts +12 -10
- package/src/generator.test.ts +13 -10
- package/src/generator.ts +17 -12
- package/src/types.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.3c1ae3b",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
16
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -24,24 +25,23 @@
|
|
|
24
25
|
"src"
|
|
25
26
|
],
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@automerge/automerge": "3.1.
|
|
28
|
-
"effect": "3.
|
|
29
|
-
"@dxos/client": "0.8.4-main.
|
|
30
|
-
"@dxos/echo
|
|
31
|
-
"@dxos/echo-
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/log": "0.8.4-main.
|
|
35
|
-
"@dxos/node-std": "0.8.4-main.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/util": "0.8.4-main.2e9d522"
|
|
28
|
+
"@automerge/automerge": "3.1.2",
|
|
29
|
+
"effect": "3.18.3",
|
|
30
|
+
"@dxos/client": "0.8.4-main.3c1ae3b",
|
|
31
|
+
"@dxos/echo": "0.8.4-main.3c1ae3b",
|
|
32
|
+
"@dxos/echo-db": "0.8.4-main.3c1ae3b",
|
|
33
|
+
"@dxos/live-object": "0.8.4-main.3c1ae3b",
|
|
34
|
+
"@dxos/invariant": "0.8.4-main.3c1ae3b",
|
|
35
|
+
"@dxos/log": "0.8.4-main.3c1ae3b",
|
|
36
|
+
"@dxos/node-std": "0.8.4-main.3c1ae3b",
|
|
37
|
+
"@dxos/util": "0.8.4-main.3c1ae3b"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@dxos/random": "0.8.4-main.
|
|
40
|
+
"@dxos/random": "0.8.4-main.3c1ae3b"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"effect": "^3.13.3",
|
|
44
|
-
"@dxos/random": "0.8.4-main.
|
|
44
|
+
"@dxos/random": "0.8.4-main.3c1ae3b"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
package/src/data.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { next as A } from '@automerge/automerge';
|
|
6
|
-
import
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { type Space } from '@dxos/client/echo';
|
|
9
|
+
import { Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { EchoObjectSchema } from '@dxos/echo/internal';
|
|
11
|
+
import { createDocAccessor } from '@dxos/echo-db';
|
|
10
12
|
import { faker } from '@dxos/random';
|
|
11
13
|
|
|
12
14
|
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
@@ -26,7 +28,7 @@ export const Priority = [1, 2, 3, 4, 5];
|
|
|
26
28
|
export enum TestSchemaType {
|
|
27
29
|
document = 'example.com/type/Document',
|
|
28
30
|
organization = 'example.com/type/Organization',
|
|
29
|
-
contact = 'example.com/type/
|
|
31
|
+
contact = 'example.com/type/Person',
|
|
30
32
|
project = 'example.com/type/Project',
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -37,21 +39,21 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
37
39
|
const document = Schema.Struct({
|
|
38
40
|
title: Schema.String.annotations({ description: 'title of the document' }),
|
|
39
41
|
content: Schema.String,
|
|
40
|
-
}).pipe(
|
|
42
|
+
}).pipe(EchoObjectSchema({ typename: TestSchemaType.document, version: '0.1.0' }));
|
|
41
43
|
|
|
42
44
|
const organization = Schema.Struct({
|
|
43
45
|
name: Schema.String.annotations({ description: 'name of the company or organization' }),
|
|
44
46
|
website: Schema.optional(Schema.String.annotations({ description: 'public website URL' })),
|
|
45
47
|
description: Schema.String.annotations({ description: 'short summary of the company' }),
|
|
46
|
-
}).pipe(
|
|
48
|
+
}).pipe(EchoObjectSchema({ typename: TestSchemaType.organization, version: '0.1.0' }));
|
|
47
49
|
|
|
48
50
|
const contact = Schema.Struct({
|
|
49
51
|
name: Schema.String.annotations({ description: 'name of the person' }),
|
|
50
52
|
email: Schema.optional(Schema.String),
|
|
51
|
-
org: Schema.optional(Ref(organization)),
|
|
53
|
+
org: Schema.optional(Type.Ref(organization)),
|
|
52
54
|
lat: Schema.optional(Schema.Number),
|
|
53
55
|
lng: Schema.optional(Schema.Number),
|
|
54
|
-
}).pipe(
|
|
56
|
+
}).pipe(EchoObjectSchema({ typename: TestSchemaType.contact, version: '0.1.0' }));
|
|
55
57
|
|
|
56
58
|
const project = Schema.Struct({
|
|
57
59
|
name: Schema.String.annotations({ description: 'name of the project' }),
|
|
@@ -61,8 +63,8 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
61
63
|
status: Schema.String,
|
|
62
64
|
priority: Schema.Number,
|
|
63
65
|
active: Schema.Boolean,
|
|
64
|
-
org: Schema.optional(Ref(organization)),
|
|
65
|
-
}).pipe(
|
|
66
|
+
org: Schema.optional(Type.Ref(organization)),
|
|
67
|
+
}).pipe(EchoObjectSchema({ typename: TestSchemaType.project, version: '0.1.0' }));
|
|
66
68
|
|
|
67
69
|
return {
|
|
68
70
|
[TestSchemaType.document]: document,
|
package/src/generator.test.ts
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { next as A } from '@automerge/automerge';
|
|
6
|
-
import
|
|
6
|
+
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 } from '@dxos/echo';
|
|
11
|
+
import { TypedObject } from '@dxos/echo/internal';
|
|
10
12
|
import { getObjectCore } from '@dxos/echo-db';
|
|
11
|
-
import { TypedObject, getType } from '@dxos/echo-schema';
|
|
12
13
|
import { faker } from '@dxos/random';
|
|
13
14
|
|
|
14
|
-
import { createSpaceObjectGenerator, createTestObjectGenerator
|
|
15
|
+
import { TestSchemaType, createSpaceObjectGenerator, createTestObjectGenerator } from './data';
|
|
15
16
|
import { SpaceObjectGenerator } from './generator';
|
|
16
17
|
|
|
17
18
|
faker.seed(3);
|
|
@@ -43,7 +44,7 @@ describe('TestObjectGenerator', () => {
|
|
|
43
44
|
|
|
44
45
|
// Create org object.
|
|
45
46
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
46
|
-
expect(
|
|
47
|
+
expect(Obj.getTypeDXN(organization)).to.exist;
|
|
47
48
|
|
|
48
49
|
// Expect at least one person object with a linked org reference.
|
|
49
50
|
const objects = await generator.createObjects({ [TestSchemaType.contact]: 10 });
|
|
@@ -59,14 +60,14 @@ describe('TestObjectGenerator', () => {
|
|
|
59
60
|
const generator = createSpaceObjectGenerator(space);
|
|
60
61
|
await generator.addSchemas();
|
|
61
62
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
62
|
-
schemaId.push(
|
|
63
|
+
schemaId.push(Obj.getTypeDXN(organization)!.toString());
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
{
|
|
66
67
|
const generator = createSpaceObjectGenerator(space);
|
|
67
68
|
await generator.addSchemas();
|
|
68
69
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
69
|
-
schemaId.push(
|
|
70
|
+
schemaId.push(Obj.getTypeDXN(organization)!.toString());
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
expect(schemaId[0]).not.to.be.undefined;
|
|
@@ -78,7 +79,7 @@ describe('TestObjectGenerator', () => {
|
|
|
78
79
|
const generator = createSpaceObjectGenerator(space);
|
|
79
80
|
await generator.addSchemas();
|
|
80
81
|
const document = await generator.createObject({ types: [TestSchemaType.document] });
|
|
81
|
-
expect(
|
|
82
|
+
expect(Obj.getTypeDXN(document)).to.exist;
|
|
82
83
|
|
|
83
84
|
const beforeChangesCount = A.getAllChanges(getObjectCore(document).docHandle!.doc()).length;
|
|
84
85
|
|
|
@@ -106,7 +107,9 @@ describe('TestObjectGenerator', () => {
|
|
|
106
107
|
const { space } = await setupTest();
|
|
107
108
|
const generator = new SpaceObjectGenerator<Types>(
|
|
108
109
|
space,
|
|
109
|
-
{
|
|
110
|
+
{
|
|
111
|
+
[Types.task]: Task,
|
|
112
|
+
},
|
|
110
113
|
{
|
|
111
114
|
[Types.task]: () => ({ name: 'Default' }),
|
|
112
115
|
},
|
|
@@ -121,7 +124,7 @@ describe('TestObjectGenerator', () => {
|
|
|
121
124
|
await generator.addSchemas();
|
|
122
125
|
|
|
123
126
|
const todo = await generator.createObject({ types: [Types.task] });
|
|
124
|
-
expect(
|
|
127
|
+
expect(Obj.getTypeDXN(todo)).to.exist;
|
|
125
128
|
});
|
|
126
129
|
|
|
127
130
|
test('references', async () => {
|
|
@@ -141,7 +144,7 @@ describe('TestObjectGenerator', () => {
|
|
|
141
144
|
test('create project', async () => {
|
|
142
145
|
const generator = createTestObjectGenerator();
|
|
143
146
|
const project = await generator.createObject({ types: [TestSchemaType.project] });
|
|
144
|
-
expect(
|
|
147
|
+
expect(Obj.getTypeDXN(project)).to.exist;
|
|
145
148
|
});
|
|
146
149
|
|
|
147
150
|
test('create object with not type', async () => {
|
package/src/generator.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { Filter, type Space } from '@dxos/client/echo';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
9
|
+
import { EchoSchema, getTypeAnnotation } from '@dxos/echo/internal';
|
|
8
10
|
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
9
|
-
import { getTypeAnnotation, EchoSchema, getSchema } from '@dxos/echo-schema';
|
|
10
11
|
import { invariant } from '@dxos/invariant';
|
|
11
|
-
import {
|
|
12
|
+
import { type Live, isLiveObject, live } from '@dxos/live-object';
|
|
12
13
|
import { faker } from '@dxos/random';
|
|
13
14
|
import { entries, range } from '@dxos/util';
|
|
14
15
|
|
|
@@ -28,10 +29,10 @@ import {
|
|
|
28
29
|
export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
29
30
|
// prettier-ignore
|
|
30
31
|
constructor(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
protected readonly _schemas: TestSchemaMap<T>,
|
|
33
|
+
private readonly _generators: TestGeneratorMap<T>,
|
|
34
|
+
private readonly _provider?: TestObjectProvider<T>,
|
|
35
|
+
) {}
|
|
35
36
|
|
|
36
37
|
get schemas(): (EchoSchema | Schema.Schema.AnyNoContext)[] {
|
|
37
38
|
return Object.values(this._schemas);
|
|
@@ -53,7 +54,7 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const schema = this.getSchema(type);
|
|
56
|
-
return schema ?
|
|
57
|
+
return schema ? Obj.make(schema, data) : live(data);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
@@ -85,7 +86,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
85
86
|
) {
|
|
86
87
|
super(schemaMap, generators, async (type: T) => {
|
|
87
88
|
const schema = this.getSchema(type);
|
|
88
|
-
const
|
|
89
|
+
const objects = await this._space.db.query(schema ? Filter.type(schema) : Filter.nothing()).run();
|
|
89
90
|
return objects;
|
|
90
91
|
});
|
|
91
92
|
}
|
|
@@ -101,7 +102,11 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
101
102
|
return result;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
override async createObject({
|
|
105
|
+
override async createObject({
|
|
106
|
+
types,
|
|
107
|
+
}: {
|
|
108
|
+
types?: T[];
|
|
109
|
+
} = {}): Promise<AnyLiveObject<any>> {
|
|
105
110
|
return this._space.db.add(await super.createObject({ types }));
|
|
106
111
|
}
|
|
107
112
|
|
|
@@ -121,14 +126,14 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
121
126
|
if (existingSchema != null) {
|
|
122
127
|
return existingSchema;
|
|
123
128
|
}
|
|
124
|
-
this._space.db.graph.schemaRegistry.
|
|
129
|
+
await this._space.db.graph.schemaRegistry.register([schema]);
|
|
125
130
|
return schema;
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams): Promise<void> {
|
|
130
135
|
invariant(this._mutations, 'Mutations not defined.');
|
|
131
|
-
const type = getTypeAnnotation(getSchema(object)!)!.typename as T;
|
|
136
|
+
const type = getTypeAnnotation(Obj.getSchema(object)!)!.typename as T;
|
|
132
137
|
invariant(type && this._mutations?.[type], 'Invalid object type.');
|
|
133
138
|
|
|
134
139
|
await this._mutations;
|
package/src/types.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
+
import { type EchoSchema } from '@dxos/echo/internal';
|
|
7
8
|
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
8
|
-
import { type EchoSchema } from '@dxos/echo-schema';
|
|
9
9
|
import { type Live } from '@dxos/live-object';
|
|
10
10
|
|
|
11
11
|
// TODO(burdon): Use echo-schema types.
|