@dxos/echo-generator 0.8.1 → 0.8.2-main.2f9c567
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 +26 -25
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +23 -22
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +26 -25
- 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.map +1 -1
- package/dist/types/src/generator.d.ts +13 -12
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +7 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +14 -12
- package/src/data.ts +21 -19
- package/src/generator.test.ts +5 -4
- package/src/generator.ts +18 -16
- package/src/types.ts +8 -6
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/core/echo/echo-generator/src/data.ts
|
|
4
|
+
import { Schema } from "effect";
|
|
4
5
|
import { next as A } from "@dxos/automerge/automerge";
|
|
5
6
|
import { createDocAccessor } from "@dxos/client/echo";
|
|
6
|
-
import { Ref
|
|
7
|
-
import { createEchoSchema
|
|
7
|
+
import { Ref } from "@dxos/echo-schema";
|
|
8
|
+
import { createEchoSchema } from "@dxos/live-object";
|
|
8
9
|
import { faker as faker2 } from "@dxos/random";
|
|
9
10
|
|
|
10
11
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
11
12
|
import { Filter } from "@dxos/client/echo";
|
|
12
|
-
import { getTypeAnnotation, EchoSchema } from "@dxos/echo-schema";
|
|
13
|
+
import { getTypeAnnotation, EchoSchema, getSchema } from "@dxos/echo-schema";
|
|
13
14
|
import { invariant } from "@dxos/invariant";
|
|
14
|
-
import {
|
|
15
|
+
import { live, isLiveObject } from "@dxos/live-object";
|
|
15
16
|
import { faker } from "@dxos/random";
|
|
16
17
|
import { range } from "@dxos/util";
|
|
17
18
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-generator/src/generator.ts";
|
|
@@ -34,11 +35,11 @@ var TestObjectGenerator = class {
|
|
|
34
35
|
async createObject({ types } = {}) {
|
|
35
36
|
const type = faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
36
37
|
const data = await this._generators[type](this._provider);
|
|
37
|
-
if (
|
|
38
|
+
if (isLiveObject(data)) {
|
|
38
39
|
return data;
|
|
39
40
|
}
|
|
40
41
|
const schema = this.getSchema(type);
|
|
41
|
-
return schema ?
|
|
42
|
+
return schema ? live(schema, data) : live(data);
|
|
42
43
|
}
|
|
43
44
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
44
45
|
async createObjects(map) {
|
|
@@ -99,7 +100,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
99
100
|
async mutateObject(object, params) {
|
|
100
101
|
invariant(this._mutations, "Mutations not defined.", {
|
|
101
102
|
F: __dxlog_file,
|
|
102
|
-
L:
|
|
103
|
+
L: 123,
|
|
103
104
|
S: this,
|
|
104
105
|
A: [
|
|
105
106
|
"this._mutations",
|
|
@@ -109,7 +110,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
109
110
|
const type = getTypeAnnotation(getSchema(object)).typename;
|
|
110
111
|
invariant(type && this._mutations?.[type], "Invalid object type.", {
|
|
111
112
|
F: __dxlog_file,
|
|
112
|
-
L:
|
|
113
|
+
L: 125,
|
|
113
114
|
S: this,
|
|
114
115
|
A: [
|
|
115
116
|
"type && this._mutations?.[type]",
|
|
@@ -161,22 +162,22 @@ var testSchemas = () => {
|
|
|
161
162
|
typename: "example.com/type/document",
|
|
162
163
|
version: "0.1.0"
|
|
163
164
|
}, {
|
|
164
|
-
title:
|
|
165
|
+
title: Schema.String.annotations({
|
|
165
166
|
description: "title of the document"
|
|
166
167
|
}),
|
|
167
|
-
content:
|
|
168
|
+
content: Schema.String
|
|
168
169
|
});
|
|
169
170
|
const organization = createEchoSchema({
|
|
170
171
|
typename: "example.com/type/organization",
|
|
171
172
|
version: "0.1.0"
|
|
172
173
|
}, {
|
|
173
|
-
name:
|
|
174
|
+
name: Schema.String.annotations({
|
|
174
175
|
description: "name of the company or organization"
|
|
175
176
|
}),
|
|
176
|
-
website:
|
|
177
|
+
website: Schema.String.annotations({
|
|
177
178
|
description: "public website URL"
|
|
178
179
|
}),
|
|
179
|
-
description:
|
|
180
|
+
description: Schema.String.annotations({
|
|
180
181
|
description: "short summary of the company"
|
|
181
182
|
})
|
|
182
183
|
});
|
|
@@ -184,27 +185,27 @@ var testSchemas = () => {
|
|
|
184
185
|
typename: "example.com/type/contact",
|
|
185
186
|
version: "0.1.0"
|
|
186
187
|
}, {
|
|
187
|
-
name:
|
|
188
|
+
name: Schema.String.annotations({
|
|
188
189
|
description: "name of the person"
|
|
189
190
|
}),
|
|
190
|
-
email:
|
|
191
|
+
email: Schema.String,
|
|
191
192
|
org: Ref(organization),
|
|
192
|
-
lat:
|
|
193
|
-
lng:
|
|
193
|
+
lat: Schema.Number,
|
|
194
|
+
lng: Schema.Number
|
|
194
195
|
});
|
|
195
196
|
const project = createEchoSchema({
|
|
196
197
|
typename: "example.com/type/project",
|
|
197
198
|
version: "0.1.0"
|
|
198
199
|
}, {
|
|
199
|
-
name:
|
|
200
|
+
name: Schema.String.annotations({
|
|
200
201
|
description: "name of the project"
|
|
201
202
|
}),
|
|
202
|
-
description:
|
|
203
|
-
website:
|
|
204
|
-
repo:
|
|
205
|
-
status:
|
|
206
|
-
priority:
|
|
207
|
-
active:
|
|
203
|
+
description: Schema.String,
|
|
204
|
+
website: Schema.String,
|
|
205
|
+
repo: Schema.String,
|
|
206
|
+
status: Schema.String,
|
|
207
|
+
priority: Schema.Number,
|
|
208
|
+
active: Schema.Boolean,
|
|
208
209
|
org: Ref(organization)
|
|
209
210
|
});
|
|
210
211
|
return {
|
|
@@ -242,7 +243,7 @@ var testObjectGenerators = {
|
|
|
242
243
|
}) ? faker2.internet.email() : void 0,
|
|
243
244
|
org: organizations?.length && faker2.datatype.boolean({
|
|
244
245
|
probability: 0.3
|
|
245
|
-
}) ?
|
|
246
|
+
}) ? Ref.make(faker2.helpers.arrayElement(organizations)) : void 0,
|
|
246
247
|
...location
|
|
247
248
|
};
|
|
248
249
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { Ref, S } from '@dxos/echo-schema';\nimport { createEchoSchema, makeRef } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';\nimport { randomText } from './util';\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/type/document',\n organization = 'example.com/type/organization',\n contact = 'example.com/type/contact',\n project = 'example.com/type/project',\n}\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createEchoSchema(\n {\n typename: TestSchemaType.document,\n version: '0.1.0',\n },\n {\n title: S.String.annotations({ description: 'title of the document' }),\n content: S.String,\n },\n );\n\n const organization = createEchoSchema(\n {\n typename: TestSchemaType.organization,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the company or organization' }),\n website: S.String.annotations({ description: 'public website URL' }),\n description: S.String.annotations({ description: 'short summary of the company' }),\n },\n );\n\n const contact = createEchoSchema(\n {\n typename: TestSchemaType.contact,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the person' }),\n email: S.String,\n org: Ref(organization),\n lat: S.Number,\n lng: S.Number,\n },\n );\n\n const project = createEchoSchema(\n {\n typename: TestSchemaType.project,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the project' }),\n description: S.String,\n website: S.String,\n repo: S.String,\n status: S.String,\n priority: S.Number,\n active: S.Boolean,\n org: Ref(organization),\n },\n );\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nconst testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: async () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: async () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: faker.lorem.sentences(),\n }),\n\n [TestSchemaType.contact]: async (provider) => {\n const organizations = await provider?.(TestSchemaType.organization);\n const { location } = faker.datatype.boolean() ? faker.geo.airport() : {};\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? makeRef(faker.helpers.arrayElement(organizations))\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: async () => ({\n name: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nconst testObjectMutators: TestMutationsMap<TestSchemaType> = {\n [TestSchemaType.document]: async (object, params) => {\n const accessor = createDocAccessor(object, ['content']);\n for (let i = 0; i < params.count; i++) {\n const length = object.content?.content?.length ?? 0;\n accessor.handle.change((doc) => {\n A.splice(\n doc,\n accessor.path.slice(),\n 0,\n params.maxContentLength >= length ? 0 : params.mutationSize,\n randomText(params.mutationSize),\n );\n });\n }\n },\n [TestSchemaType.organization]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.contact]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.project]: async () => {\n throw new Error('Method not implemented.');\n },\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport { getTypeAnnotation, EchoSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | S.Schema.AnyNoContext)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | S.Schema.AnyNoContext | undefined {\n return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | S.Schema.AnyNoContext) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | S.Schema.AnyNoContext)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema.AnyNoContext);\n this.setSchema(typename as T, echoSchema);\n result.push(echoSchema);\n }\n\n return result;\n }\n\n override async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveEchoObject<any>> {\n return this._space.db.add(await super.createObject({ types }));\n }\n\n private async _maybeRegisterSchema(\n typename: string,\n schema: EchoSchema | S.Schema.AnyNoContext,\n ): Promise<EchoSchema | S.Schema.AnyNoContext> {\n if (schema instanceof EchoSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);\n return registeredSchema;\n } else {\n const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.graph.schemaRegistry.addSchema([schema]);\n return schema;\n }\n }\n\n async mutateObject(object: ReactiveEchoObject<any>, params: MutationsProviderParams) {\n invariant(this._mutations, 'Mutations not defined.');\n const type = getTypeAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations;\n }\n\n async mutateObjects(objects: ReactiveEchoObject<any>[], params: MutationsProviderParams) {\n for (const object of objects) {\n await this.mutateObject(object, params);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const randomText = (length: number) => {\n let result = '';\n const characters = 'abcdefghijklmnopqrstuvwxyz';\n const charactersLength = characters.length;\n for (let index = 0; index < length; index++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n\n return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,QAAQC,SAAS;AAC1B,SAASC,yBAAqC;AAC9C,SAASC,
|
|
6
|
-
"names": ["next", "A", "createDocAccessor", "Ref", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { Ref } from '@dxos/echo-schema';\nimport { createEchoSchema } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';\nimport { randomText } from './util';\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/type/document',\n organization = 'example.com/type/organization',\n contact = 'example.com/type/contact',\n project = 'example.com/type/project',\n}\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createEchoSchema(\n {\n typename: TestSchemaType.document,\n version: '0.1.0',\n },\n {\n title: Schema.String.annotations({ description: 'title of the document' }),\n content: Schema.String,\n },\n );\n\n const organization = createEchoSchema(\n {\n typename: TestSchemaType.organization,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the company or organization' }),\n website: Schema.String.annotations({ description: 'public website URL' }),\n description: Schema.String.annotations({ description: 'short summary of the company' }),\n },\n );\n\n const contact = createEchoSchema(\n {\n typename: TestSchemaType.contact,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the person' }),\n email: Schema.String,\n org: Ref(organization),\n lat: Schema.Number,\n lng: Schema.Number,\n },\n );\n\n const project = createEchoSchema(\n {\n typename: TestSchemaType.project,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the project' }),\n description: Schema.String,\n website: Schema.String,\n repo: Schema.String,\n status: Schema.String,\n priority: Schema.Number,\n active: Schema.Boolean,\n org: Ref(organization),\n },\n );\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nconst testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: async () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: async () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: faker.lorem.sentences(),\n }),\n\n [TestSchemaType.contact]: async (provider) => {\n const organizations = await provider?.(TestSchemaType.organization);\n const { location } = faker.datatype.boolean() ? faker.geo.airport() : {};\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? Ref.make(faker.helpers.arrayElement(organizations))\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: async () => ({\n name: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nconst testObjectMutators: TestMutationsMap<TestSchemaType> = {\n [TestSchemaType.document]: async (object, params) => {\n const accessor = createDocAccessor(object, ['content']);\n for (let i = 0; i < params.count; i++) {\n const length = object.content?.content?.length ?? 0;\n accessor.handle.change((doc) => {\n A.splice(\n doc,\n accessor.path.slice(),\n 0,\n params.maxContentLength >= length ? 0 : params.mutationSize,\n randomText(params.mutationSize),\n );\n });\n }\n },\n [TestSchemaType.organization]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.contact]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.project]: async () => {\n throw new Error('Method not implemented.');\n },\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type AnyLiveObject } from '@dxos/echo-db';\nimport { getTypeAnnotation, EchoSchema, getSchema } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { live, isLiveObject, type Live } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | Schema.Schema.AnyNoContext)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | Schema.Schema.AnyNoContext | undefined {\n return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<Live<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isLiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? live(schema, data) : live(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | Schema.Schema.AnyNoContext)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | Schema.Schema.AnyNoContext);\n this.setSchema(typename as T, echoSchema);\n result.push(echoSchema);\n }\n\n return result;\n }\n\n override async createObject({ types }: { types?: T[] } = {}): Promise<AnyLiveObject<any>> {\n return this._space.db.add(await super.createObject({ types }));\n }\n\n private async _maybeRegisterSchema(\n typename: string,\n schema: EchoSchema | Schema.Schema.AnyNoContext,\n ): Promise<EchoSchema | Schema.Schema.AnyNoContext> {\n if (schema instanceof EchoSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);\n return registeredSchema;\n } else {\n const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.graph.schemaRegistry.addSchema([schema]);\n return schema;\n }\n }\n\n async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams) {\n invariant(this._mutations, 'Mutations not defined.');\n const type = getTypeAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations;\n }\n\n async mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams) {\n for (const object of objects) {\n await this.mutateObject(object, params);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const randomText = (length: number) => {\n let result = '';\n const characters = 'abcdefghijklmnopqrstuvwxyz';\n const charactersLength = characters.length;\n for (let index = 0; index < length; index++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,cAAc;AAEvB,SAASC,QAAQC,SAAS;AAC1B,SAASC,yBAAqC;AAC9C,SAASC,WAAW;AACpB,SAASC,wBAAwB;AACjC,SAASC,SAAAA,cAAa;;;ACJtB,SAASC,cAA0B;AAEnC,SAASC,mBAAmBC,YAAYC,iBAAiB;AACzD,SAASC,iBAAiB;AAC1B,SAASC,MAAMC,oBAA+B;AAC9C,SAASC,aAAa;AACtB,SAASC,aAAa;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC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"next", "A", "createDocAccessor", "Ref", "createEchoSchema", "faker", "Filter", "getTypeAnnotation", "EchoSchema", "getSchema", "invariant", "live", "isLiveObject", "faker", "range", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "type", "find", "schema", "typename", "setSchema", "createObject", "types", "helpers", "arrayElement", "keys", "data", "createObjects", "map", "tasks", "entries", "count", "flatMap", "t", "Promise", "all", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "_mutations", "db", "query", "run", "objects", "addSchemas", "result", "echoSchema", "_maybeRegisterSchema", "push", "add", "existingSchema", "schemaRegistry", "registeredSchema", "register", "graph", "addSchema", "mutateObject", "object", "params", "mutateObjects", "randomText", "length", "result", "characters", "charactersLength", "index", "charAt", "Math", "floor", "random", "Status", "Priority", "TestSchemaType", "testSchemas", "document", "createEchoSchema", "typename", "version", "title", "Schema", "String", "annotations", "description", "content", "organization", "name", "website", "contact", "email", "org", "Ref", "lat", "Number", "lng", "project", "repo", "status", "priority", "active", "Boolean", "testObjectGenerators", "faker", "lorem", "sentence", "sentences", "min", "max", "number", "int", "company", "datatype", "boolean", "probability", "internet", "url", "undefined", "provider", "organizations", "location", "geo", "airport", "person", "fullName", "length", "make", "helpers", "arrayElement", "commerce", "productName", "testObjectMutators", "object", "params", "accessor", "createDocAccessor", "i", "count", "handle", "change", "doc", "A", "splice", "path", "slice", "maxContentLength", "mutationSize", "randomText", "Error", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":15773,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":18896,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/types.ts":{"bytes":1745,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":751,"imports":[{"path":"packages/core/echo/echo-generator/src/data.ts","kind":"import-statement","original":"./data"},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18027},"packages/core/echo/echo-generator/dist/lib/browser/index.mjs":{"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Priority","SpaceObjectGenerator","Status","TestObjectGenerator","TestSchemaType","createSpaceObjectGenerator","createTestObjectGenerator","randomText"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":4688},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3709},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9140}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(node_exports, {
|
|
|
28
28
|
randomText: () => randomText
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(node_exports);
|
|
31
|
+
var import_effect = require("effect");
|
|
31
32
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
32
33
|
var import_echo = require("@dxos/client/echo");
|
|
33
34
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
@@ -59,11 +60,11 @@ var TestObjectGenerator = class {
|
|
|
59
60
|
async createObject({ types } = {}) {
|
|
60
61
|
const type = import_random2.faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
61
62
|
const data = await this._generators[type](this._provider);
|
|
62
|
-
if ((0, import_live_object2.
|
|
63
|
+
if ((0, import_live_object2.isLiveObject)(data)) {
|
|
63
64
|
return data;
|
|
64
65
|
}
|
|
65
66
|
const schema = this.getSchema(type);
|
|
66
|
-
return schema ? (0, import_live_object2.
|
|
67
|
+
return schema ? (0, import_live_object2.live)(schema, data) : (0, import_live_object2.live)(data);
|
|
67
68
|
}
|
|
68
69
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
69
70
|
async createObjects(map) {
|
|
@@ -124,17 +125,17 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
124
125
|
async mutateObject(object, params) {
|
|
125
126
|
(0, import_invariant.invariant)(this._mutations, "Mutations not defined.", {
|
|
126
127
|
F: __dxlog_file,
|
|
127
|
-
L:
|
|
128
|
+
L: 123,
|
|
128
129
|
S: this,
|
|
129
130
|
A: [
|
|
130
131
|
"this._mutations",
|
|
131
132
|
"'Mutations not defined.'"
|
|
132
133
|
]
|
|
133
134
|
});
|
|
134
|
-
const type = (0, import_echo_schema2.getTypeAnnotation)((0,
|
|
135
|
+
const type = (0, import_echo_schema2.getTypeAnnotation)((0, import_echo_schema2.getSchema)(object)).typename;
|
|
135
136
|
(0, import_invariant.invariant)(type && this._mutations?.[type], "Invalid object type.", {
|
|
136
137
|
F: __dxlog_file,
|
|
137
|
-
L:
|
|
138
|
+
L: 125,
|
|
138
139
|
S: this,
|
|
139
140
|
A: [
|
|
140
141
|
"type && this._mutations?.[type]",
|
|
@@ -182,22 +183,22 @@ var testSchemas = () => {
|
|
|
182
183
|
typename: "example.com/type/document",
|
|
183
184
|
version: "0.1.0"
|
|
184
185
|
}, {
|
|
185
|
-
title:
|
|
186
|
+
title: import_effect.Schema.String.annotations({
|
|
186
187
|
description: "title of the document"
|
|
187
188
|
}),
|
|
188
|
-
content:
|
|
189
|
+
content: import_effect.Schema.String
|
|
189
190
|
});
|
|
190
191
|
const organization = (0, import_live_object.createEchoSchema)({
|
|
191
192
|
typename: "example.com/type/organization",
|
|
192
193
|
version: "0.1.0"
|
|
193
194
|
}, {
|
|
194
|
-
name:
|
|
195
|
+
name: import_effect.Schema.String.annotations({
|
|
195
196
|
description: "name of the company or organization"
|
|
196
197
|
}),
|
|
197
|
-
website:
|
|
198
|
+
website: import_effect.Schema.String.annotations({
|
|
198
199
|
description: "public website URL"
|
|
199
200
|
}),
|
|
200
|
-
description:
|
|
201
|
+
description: import_effect.Schema.String.annotations({
|
|
201
202
|
description: "short summary of the company"
|
|
202
203
|
})
|
|
203
204
|
});
|
|
@@ -205,27 +206,27 @@ var testSchemas = () => {
|
|
|
205
206
|
typename: "example.com/type/contact",
|
|
206
207
|
version: "0.1.0"
|
|
207
208
|
}, {
|
|
208
|
-
name:
|
|
209
|
+
name: import_effect.Schema.String.annotations({
|
|
209
210
|
description: "name of the person"
|
|
210
211
|
}),
|
|
211
|
-
email:
|
|
212
|
+
email: import_effect.Schema.String,
|
|
212
213
|
org: (0, import_echo_schema.Ref)(organization),
|
|
213
|
-
lat:
|
|
214
|
-
lng:
|
|
214
|
+
lat: import_effect.Schema.Number,
|
|
215
|
+
lng: import_effect.Schema.Number
|
|
215
216
|
});
|
|
216
217
|
const project = (0, import_live_object.createEchoSchema)({
|
|
217
218
|
typename: "example.com/type/project",
|
|
218
219
|
version: "0.1.0"
|
|
219
220
|
}, {
|
|
220
|
-
name:
|
|
221
|
+
name: import_effect.Schema.String.annotations({
|
|
221
222
|
description: "name of the project"
|
|
222
223
|
}),
|
|
223
|
-
description:
|
|
224
|
-
website:
|
|
225
|
-
repo:
|
|
226
|
-
status:
|
|
227
|
-
priority:
|
|
228
|
-
active:
|
|
224
|
+
description: import_effect.Schema.String,
|
|
225
|
+
website: import_effect.Schema.String,
|
|
226
|
+
repo: import_effect.Schema.String,
|
|
227
|
+
status: import_effect.Schema.String,
|
|
228
|
+
priority: import_effect.Schema.Number,
|
|
229
|
+
active: import_effect.Schema.Boolean,
|
|
229
230
|
org: (0, import_echo_schema.Ref)(organization)
|
|
230
231
|
});
|
|
231
232
|
return {
|
|
@@ -263,7 +264,7 @@ var testObjectGenerators = {
|
|
|
263
264
|
}) ? import_random.faker.internet.email() : void 0,
|
|
264
265
|
org: organizations?.length && import_random.faker.datatype.boolean({
|
|
265
266
|
probability: 0.3
|
|
266
|
-
}) ?
|
|
267
|
+
}) ? import_echo_schema.Ref.make(import_random.faker.helpers.arrayElement(organizations)) : void 0,
|
|
267
268
|
...location
|
|
268
269
|
};
|
|
269
270
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { Ref, S } from '@dxos/echo-schema';\nimport { createEchoSchema, makeRef } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';\nimport { randomText } from './util';\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/type/document',\n organization = 'example.com/type/organization',\n contact = 'example.com/type/contact',\n project = 'example.com/type/project',\n}\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createEchoSchema(\n {\n typename: TestSchemaType.document,\n version: '0.1.0',\n },\n {\n title: S.String.annotations({ description: 'title of the document' }),\n content: S.String,\n },\n );\n\n const organization = createEchoSchema(\n {\n typename: TestSchemaType.organization,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the company or organization' }),\n website: S.String.annotations({ description: 'public website URL' }),\n description: S.String.annotations({ description: 'short summary of the company' }),\n },\n );\n\n const contact = createEchoSchema(\n {\n typename: TestSchemaType.contact,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the person' }),\n email: S.String,\n org: Ref(organization),\n lat: S.Number,\n lng: S.Number,\n },\n );\n\n const project = createEchoSchema(\n {\n typename: TestSchemaType.project,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the project' }),\n description: S.String,\n website: S.String,\n repo: S.String,\n status: S.String,\n priority: S.Number,\n active: S.Boolean,\n org: Ref(organization),\n },\n );\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nconst testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: async () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: async () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: faker.lorem.sentences(),\n }),\n\n [TestSchemaType.contact]: async (provider) => {\n const organizations = await provider?.(TestSchemaType.organization);\n const { location } = faker.datatype.boolean() ? faker.geo.airport() : {};\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? makeRef(faker.helpers.arrayElement(organizations))\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: async () => ({\n name: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nconst testObjectMutators: TestMutationsMap<TestSchemaType> = {\n [TestSchemaType.document]: async (object, params) => {\n const accessor = createDocAccessor(object, ['content']);\n for (let i = 0; i < params.count; i++) {\n const length = object.content?.content?.length ?? 0;\n accessor.handle.change((doc) => {\n A.splice(\n doc,\n accessor.path.slice(),\n 0,\n params.maxContentLength >= length ? 0 : params.mutationSize,\n randomText(params.mutationSize),\n );\n });\n }\n },\n [TestSchemaType.organization]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.contact]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.project]: async () => {\n throw new Error('Method not implemented.');\n },\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport { getTypeAnnotation, EchoSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | S.Schema.AnyNoContext)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | S.Schema.AnyNoContext | undefined {\n return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | S.Schema.AnyNoContext) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | S.Schema.AnyNoContext)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema.AnyNoContext);\n this.setSchema(typename as T, echoSchema);\n result.push(echoSchema);\n }\n\n return result;\n }\n\n override async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveEchoObject<any>> {\n return this._space.db.add(await super.createObject({ types }));\n }\n\n private async _maybeRegisterSchema(\n typename: string,\n schema: EchoSchema | S.Schema.AnyNoContext,\n ): Promise<EchoSchema | S.Schema.AnyNoContext> {\n if (schema instanceof EchoSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);\n return registeredSchema;\n } else {\n const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.graph.schemaRegistry.addSchema([schema]);\n return schema;\n }\n }\n\n async mutateObject(object: ReactiveEchoObject<any>, params: MutationsProviderParams) {\n invariant(this._mutations, 'Mutations not defined.');\n const type = getTypeAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations;\n }\n\n async mutateObjects(objects: ReactiveEchoObject<any>[], params: MutationsProviderParams) {\n for (const object of objects) {\n await this.mutateObject(object, params);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const randomText = (length: number) => {\n let result = '';\n const characters = 'abcdefghijklmnopqrstuvwxyz';\n const charactersLength = characters.length;\n for (let index = 0; index < length; index++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n\n return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAA0B;AAC1B,kBAA8C;AAC9C,
|
|
6
|
-
"names": ["import_echo", "import_echo_schema", "import_live_object", "import_random", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "getSchema", "type", "find", "schema", "getTypeAnnotation", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { Ref } from '@dxos/echo-schema';\nimport { createEchoSchema } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';\nimport { randomText } from './util';\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/type/document',\n organization = 'example.com/type/organization',\n contact = 'example.com/type/contact',\n project = 'example.com/type/project',\n}\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createEchoSchema(\n {\n typename: TestSchemaType.document,\n version: '0.1.0',\n },\n {\n title: Schema.String.annotations({ description: 'title of the document' }),\n content: Schema.String,\n },\n );\n\n const organization = createEchoSchema(\n {\n typename: TestSchemaType.organization,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the company or organization' }),\n website: Schema.String.annotations({ description: 'public website URL' }),\n description: Schema.String.annotations({ description: 'short summary of the company' }),\n },\n );\n\n const contact = createEchoSchema(\n {\n typename: TestSchemaType.contact,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the person' }),\n email: Schema.String,\n org: Ref(organization),\n lat: Schema.Number,\n lng: Schema.Number,\n },\n );\n\n const project = createEchoSchema(\n {\n typename: TestSchemaType.project,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the project' }),\n description: Schema.String,\n website: Schema.String,\n repo: Schema.String,\n status: Schema.String,\n priority: Schema.Number,\n active: Schema.Boolean,\n org: Ref(organization),\n },\n );\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nconst testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: async () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: async () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: faker.lorem.sentences(),\n }),\n\n [TestSchemaType.contact]: async (provider) => {\n const organizations = await provider?.(TestSchemaType.organization);\n const { location } = faker.datatype.boolean() ? faker.geo.airport() : {};\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? Ref.make(faker.helpers.arrayElement(organizations))\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: async () => ({\n name: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nconst testObjectMutators: TestMutationsMap<TestSchemaType> = {\n [TestSchemaType.document]: async (object, params) => {\n const accessor = createDocAccessor(object, ['content']);\n for (let i = 0; i < params.count; i++) {\n const length = object.content?.content?.length ?? 0;\n accessor.handle.change((doc) => {\n A.splice(\n doc,\n accessor.path.slice(),\n 0,\n params.maxContentLength >= length ? 0 : params.mutationSize,\n randomText(params.mutationSize),\n );\n });\n }\n },\n [TestSchemaType.organization]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.contact]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.project]: async () => {\n throw new Error('Method not implemented.');\n },\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type AnyLiveObject } from '@dxos/echo-db';\nimport { getTypeAnnotation, EchoSchema, getSchema } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { live, isLiveObject, type Live } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | Schema.Schema.AnyNoContext)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | Schema.Schema.AnyNoContext | undefined {\n return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<Live<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isLiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? live(schema, data) : live(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | Schema.Schema.AnyNoContext)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | Schema.Schema.AnyNoContext);\n this.setSchema(typename as T, echoSchema);\n result.push(echoSchema);\n }\n\n return result;\n }\n\n override async createObject({ types }: { types?: T[] } = {}): Promise<AnyLiveObject<any>> {\n return this._space.db.add(await super.createObject({ types }));\n }\n\n private async _maybeRegisterSchema(\n typename: string,\n schema: EchoSchema | Schema.Schema.AnyNoContext,\n ): Promise<EchoSchema | Schema.Schema.AnyNoContext> {\n if (schema instanceof EchoSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);\n return registeredSchema;\n } else {\n const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.graph.schemaRegistry.addSchema([schema]);\n return schema;\n }\n }\n\n async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams) {\n invariant(this._mutations, 'Mutations not defined.');\n const type = getTypeAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations;\n }\n\n async mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams) {\n for (const object of objects) {\n await this.mutateObject(object, params);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const randomText = (length: number) => {\n let result = '';\n const characters = 'abcdefghijklmnopqrstuvwxyz';\n const charactersLength = characters.length;\n for (let index = 0; index < length; index++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAuB;AAEvB,uBAA0B;AAC1B,kBAA8C;AAC9C,yBAAoB;AACpB,yBAAiC;AACjC,oBAAsB;ACJtB,IAAAA,eAAmC;AAEnC,IAAAC,sBAAyD;AACzD,uBAA0B;AAC1B,IAAAC,sBAA8C;AAC9C,IAAAC,iBAAsB;AACtB,kBAAsB;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC,UAAuD;AACzD,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAM,UAAUC,MAA8D;AACtE,WAAO,KAAKJ,QAAQK,KAAK,CAACC,eAAWC,uCAAkBD,MAAAA,EAASE,aAAaJ,IAAAA;EAC/E;EAEUK,UAAUL,MAASE,QAAiD;AAC5E,SAAKT,SAASO,IAAAA,IAAQE;EACxB;EAEA,MAAMI,aAAa,EAAEC,MAAK,IAAs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"TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "getSchema", "type", "find", "schema", "getTypeAnnotation", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "isLiveObject", "live", "createObjects", "map", "tasks", "entries", "count", "range", "flatMap", "t", "Promise", "all", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "_mutations", "db", "query", "Filter", "run", "objects", "addSchemas", "result", "echoSchema", "_maybeRegisterSchema", "push", "add", "EchoSchema", "existingSchema", "schemaRegistry", "registeredSchema", "register", "graph", "addSchema", "mutateObject", "object", "params", "invariant", "mutateObjects", "randomText", "length", "characters", "charactersLength", "index", "charAt", "Math", "floor", "random", "Status", "Priority", "TestSchemaType", "testSchemas", "document", "createEchoSchema", "version", "title", "Schema", "String", "annotations", "description", "content", "organization", "name", "website", "contact", "email", "org", "Ref", "lat", "Number", "lng", "project", "repo", "status", "priority", "active", "Boolean", "testObjectGenerators", "lorem", "sentence", "sentences", "min", "max", "number", "int", "company", "datatype", "boolean", "probability", "internet", "url", "undefined", "provider", "organizations", "location", "geo", "airport", "person", "fullName", "make", "commerce", "productName", "testObjectMutators", "accessor", "createDocAccessor", "i", "handle", "change", "doc", "A", "splice", "path", "slice", "maxContentLength", "mutationSize", "Error", "createTestObjectGenerator", "createSpaceObjectGenerator", "space"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":15773,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":18896,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/types.ts":{"bytes":1745,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":751,"imports":[{"path":"packages/core/echo/echo-generator/src/data.ts","kind":"import-statement","original":"./data"},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18025},"packages/core/echo/echo-generator/dist/lib/node/index.cjs":{"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Priority","SpaceObjectGenerator","Status","TestObjectGenerator","TestSchemaType","createSpaceObjectGenerator","createTestObjectGenerator","randomText"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":4688},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3709},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9106}}}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// packages/core/echo/echo-generator/src/data.ts
|
|
4
|
+
import { Schema } from "effect";
|
|
4
5
|
import { next as A } from "@dxos/automerge/automerge";
|
|
5
6
|
import { createDocAccessor } from "@dxos/client/echo";
|
|
6
|
-
import { Ref
|
|
7
|
-
import { createEchoSchema
|
|
7
|
+
import { Ref } from "@dxos/echo-schema";
|
|
8
|
+
import { createEchoSchema } from "@dxos/live-object";
|
|
8
9
|
import { faker as faker2 } from "@dxos/random";
|
|
9
10
|
|
|
10
11
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
11
12
|
import { Filter } from "@dxos/client/echo";
|
|
12
|
-
import { getTypeAnnotation, EchoSchema } from "@dxos/echo-schema";
|
|
13
|
+
import { getTypeAnnotation, EchoSchema, getSchema } from "@dxos/echo-schema";
|
|
13
14
|
import { invariant } from "@dxos/invariant";
|
|
14
|
-
import {
|
|
15
|
+
import { live, isLiveObject } from "@dxos/live-object";
|
|
15
16
|
import { faker } from "@dxos/random";
|
|
16
17
|
import { range } from "@dxos/util";
|
|
17
18
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-generator/src/generator.ts";
|
|
@@ -34,11 +35,11 @@ var TestObjectGenerator = class {
|
|
|
34
35
|
async createObject({ types } = {}) {
|
|
35
36
|
const type = faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
36
37
|
const data = await this._generators[type](this._provider);
|
|
37
|
-
if (
|
|
38
|
+
if (isLiveObject(data)) {
|
|
38
39
|
return data;
|
|
39
40
|
}
|
|
40
41
|
const schema = this.getSchema(type);
|
|
41
|
-
return schema ?
|
|
42
|
+
return schema ? live(schema, data) : live(data);
|
|
42
43
|
}
|
|
43
44
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
44
45
|
async createObjects(map) {
|
|
@@ -99,7 +100,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
99
100
|
async mutateObject(object, params) {
|
|
100
101
|
invariant(this._mutations, "Mutations not defined.", {
|
|
101
102
|
F: __dxlog_file,
|
|
102
|
-
L:
|
|
103
|
+
L: 123,
|
|
103
104
|
S: this,
|
|
104
105
|
A: [
|
|
105
106
|
"this._mutations",
|
|
@@ -109,7 +110,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
109
110
|
const type = getTypeAnnotation(getSchema(object)).typename;
|
|
110
111
|
invariant(type && this._mutations?.[type], "Invalid object type.", {
|
|
111
112
|
F: __dxlog_file,
|
|
112
|
-
L:
|
|
113
|
+
L: 125,
|
|
113
114
|
S: this,
|
|
114
115
|
A: [
|
|
115
116
|
"type && this._mutations?.[type]",
|
|
@@ -161,22 +162,22 @@ var testSchemas = () => {
|
|
|
161
162
|
typename: "example.com/type/document",
|
|
162
163
|
version: "0.1.0"
|
|
163
164
|
}, {
|
|
164
|
-
title:
|
|
165
|
+
title: Schema.String.annotations({
|
|
165
166
|
description: "title of the document"
|
|
166
167
|
}),
|
|
167
|
-
content:
|
|
168
|
+
content: Schema.String
|
|
168
169
|
});
|
|
169
170
|
const organization = createEchoSchema({
|
|
170
171
|
typename: "example.com/type/organization",
|
|
171
172
|
version: "0.1.0"
|
|
172
173
|
}, {
|
|
173
|
-
name:
|
|
174
|
+
name: Schema.String.annotations({
|
|
174
175
|
description: "name of the company or organization"
|
|
175
176
|
}),
|
|
176
|
-
website:
|
|
177
|
+
website: Schema.String.annotations({
|
|
177
178
|
description: "public website URL"
|
|
178
179
|
}),
|
|
179
|
-
description:
|
|
180
|
+
description: Schema.String.annotations({
|
|
180
181
|
description: "short summary of the company"
|
|
181
182
|
})
|
|
182
183
|
});
|
|
@@ -184,27 +185,27 @@ var testSchemas = () => {
|
|
|
184
185
|
typename: "example.com/type/contact",
|
|
185
186
|
version: "0.1.0"
|
|
186
187
|
}, {
|
|
187
|
-
name:
|
|
188
|
+
name: Schema.String.annotations({
|
|
188
189
|
description: "name of the person"
|
|
189
190
|
}),
|
|
190
|
-
email:
|
|
191
|
+
email: Schema.String,
|
|
191
192
|
org: Ref(organization),
|
|
192
|
-
lat:
|
|
193
|
-
lng:
|
|
193
|
+
lat: Schema.Number,
|
|
194
|
+
lng: Schema.Number
|
|
194
195
|
});
|
|
195
196
|
const project = createEchoSchema({
|
|
196
197
|
typename: "example.com/type/project",
|
|
197
198
|
version: "0.1.0"
|
|
198
199
|
}, {
|
|
199
|
-
name:
|
|
200
|
+
name: Schema.String.annotations({
|
|
200
201
|
description: "name of the project"
|
|
201
202
|
}),
|
|
202
|
-
description:
|
|
203
|
-
website:
|
|
204
|
-
repo:
|
|
205
|
-
status:
|
|
206
|
-
priority:
|
|
207
|
-
active:
|
|
203
|
+
description: Schema.String,
|
|
204
|
+
website: Schema.String,
|
|
205
|
+
repo: Schema.String,
|
|
206
|
+
status: Schema.String,
|
|
207
|
+
priority: Schema.Number,
|
|
208
|
+
active: Schema.Boolean,
|
|
208
209
|
org: Ref(organization)
|
|
209
210
|
});
|
|
210
211
|
return {
|
|
@@ -242,7 +243,7 @@ var testObjectGenerators = {
|
|
|
242
243
|
}) ? faker2.internet.email() : void 0,
|
|
243
244
|
org: organizations?.length && faker2.datatype.boolean({
|
|
244
245
|
probability: 0.3
|
|
245
|
-
}) ?
|
|
246
|
+
}) ? Ref.make(faker2.helpers.arrayElement(organizations)) : void 0,
|
|
246
247
|
...location
|
|
247
248
|
};
|
|
248
249
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { Ref, S } from '@dxos/echo-schema';\nimport { createEchoSchema, makeRef } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';\nimport { randomText } from './util';\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/type/document',\n organization = 'example.com/type/organization',\n contact = 'example.com/type/contact',\n project = 'example.com/type/project',\n}\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createEchoSchema(\n {\n typename: TestSchemaType.document,\n version: '0.1.0',\n },\n {\n title: S.String.annotations({ description: 'title of the document' }),\n content: S.String,\n },\n );\n\n const organization = createEchoSchema(\n {\n typename: TestSchemaType.organization,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the company or organization' }),\n website: S.String.annotations({ description: 'public website URL' }),\n description: S.String.annotations({ description: 'short summary of the company' }),\n },\n );\n\n const contact = createEchoSchema(\n {\n typename: TestSchemaType.contact,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the person' }),\n email: S.String,\n org: Ref(organization),\n lat: S.Number,\n lng: S.Number,\n },\n );\n\n const project = createEchoSchema(\n {\n typename: TestSchemaType.project,\n version: '0.1.0',\n },\n {\n name: S.String.annotations({ description: 'name of the project' }),\n description: S.String,\n website: S.String,\n repo: S.String,\n status: S.String,\n priority: S.Number,\n active: S.Boolean,\n org: Ref(organization),\n },\n );\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nconst testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: async () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: async () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: faker.lorem.sentences(),\n }),\n\n [TestSchemaType.contact]: async (provider) => {\n const organizations = await provider?.(TestSchemaType.organization);\n const { location } = faker.datatype.boolean() ? faker.geo.airport() : {};\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? makeRef(faker.helpers.arrayElement(organizations))\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: async () => ({\n name: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nconst testObjectMutators: TestMutationsMap<TestSchemaType> = {\n [TestSchemaType.document]: async (object, params) => {\n const accessor = createDocAccessor(object, ['content']);\n for (let i = 0; i < params.count; i++) {\n const length = object.content?.content?.length ?? 0;\n accessor.handle.change((doc) => {\n A.splice(\n doc,\n accessor.path.slice(),\n 0,\n params.maxContentLength >= length ? 0 : params.mutationSize,\n randomText(params.mutationSize),\n );\n });\n }\n },\n [TestSchemaType.organization]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.contact]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.project]: async () => {\n throw new Error('Method not implemented.');\n },\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport { getTypeAnnotation, EchoSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | S.Schema.AnyNoContext)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | S.Schema.AnyNoContext | undefined {\n return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | S.Schema.AnyNoContext) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | S.Schema.AnyNoContext)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema.AnyNoContext);\n this.setSchema(typename as T, echoSchema);\n result.push(echoSchema);\n }\n\n return result;\n }\n\n override async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveEchoObject<any>> {\n return this._space.db.add(await super.createObject({ types }));\n }\n\n private async _maybeRegisterSchema(\n typename: string,\n schema: EchoSchema | S.Schema.AnyNoContext,\n ): Promise<EchoSchema | S.Schema.AnyNoContext> {\n if (schema instanceof EchoSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);\n return registeredSchema;\n } else {\n const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.graph.schemaRegistry.addSchema([schema]);\n return schema;\n }\n }\n\n async mutateObject(object: ReactiveEchoObject<any>, params: MutationsProviderParams) {\n invariant(this._mutations, 'Mutations not defined.');\n const type = getTypeAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations;\n }\n\n async mutateObjects(objects: ReactiveEchoObject<any>[], params: MutationsProviderParams) {\n for (const object of objects) {\n await this.mutateObject(object, params);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const randomText = (length: number) => {\n let result = '';\n const characters = 'abcdefghijklmnopqrstuvwxyz';\n const charactersLength = characters.length;\n for (let index = 0; index < length; index++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n\n return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,QAAQC,SAAS;AAC1B,SAASC,yBAAqC;AAC9C,SAASC,
|
|
6
|
-
"names": ["next", "A", "createDocAccessor", "Ref", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { Ref } from '@dxos/echo-schema';\nimport { createEchoSchema } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestMutationsMap, type TestSchemaMap } from './types';\nimport { randomText } from './util';\n\n// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.\n// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).\n\n// TODO(burdon): Handle restricted values.\nexport const Status = ['pending', 'active', 'done'];\nexport const Priority = [1, 2, 3, 4, 5];\n\nexport enum TestSchemaType {\n document = 'example.com/type/document',\n organization = 'example.com/type/organization',\n contact = 'example.com/type/contact',\n project = 'example.com/type/project',\n}\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createEchoSchema(\n {\n typename: TestSchemaType.document,\n version: '0.1.0',\n },\n {\n title: Schema.String.annotations({ description: 'title of the document' }),\n content: Schema.String,\n },\n );\n\n const organization = createEchoSchema(\n {\n typename: TestSchemaType.organization,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the company or organization' }),\n website: Schema.String.annotations({ description: 'public website URL' }),\n description: Schema.String.annotations({ description: 'short summary of the company' }),\n },\n );\n\n const contact = createEchoSchema(\n {\n typename: TestSchemaType.contact,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the person' }),\n email: Schema.String,\n org: Ref(organization),\n lat: Schema.Number,\n lng: Schema.Number,\n },\n );\n\n const project = createEchoSchema(\n {\n typename: TestSchemaType.project,\n version: '0.1.0',\n },\n {\n name: Schema.String.annotations({ description: 'name of the project' }),\n description: Schema.String,\n website: Schema.String,\n repo: Schema.String,\n status: Schema.String,\n priority: Schema.Number,\n active: Schema.Boolean,\n org: Ref(organization),\n },\n );\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nconst testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: async () => ({\n title: faker.lorem.sentence(3),\n content: faker.lorem.sentences({ min: 1, max: faker.number.int({ min: 1, max: 3 }) }),\n }),\n\n [TestSchemaType.organization]: async () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: faker.lorem.sentences(),\n }),\n\n [TestSchemaType.contact]: async (provider) => {\n const organizations = await provider?.(TestSchemaType.organization);\n const { location } = faker.datatype.boolean() ? faker.geo.airport() : {};\n return {\n name: faker.person.fullName(),\n email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,\n org:\n organizations?.length && faker.datatype.boolean({ probability: 0.3 })\n ? Ref.make(faker.helpers.arrayElement(organizations))\n : undefined,\n ...location,\n };\n },\n\n [TestSchemaType.project]: async () => ({\n name: faker.commerce.productName(),\n repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n status: faker.helpers.arrayElement(Status),\n priority: faker.helpers.arrayElement(Priority),\n active: faker.datatype.boolean(),\n }),\n};\n\nconst testObjectMutators: TestMutationsMap<TestSchemaType> = {\n [TestSchemaType.document]: async (object, params) => {\n const accessor = createDocAccessor(object, ['content']);\n for (let i = 0; i < params.count; i++) {\n const length = object.content?.content?.length ?? 0;\n accessor.handle.change((doc) => {\n A.splice(\n doc,\n accessor.path.slice(),\n 0,\n params.maxContentLength >= length ? 0 : params.mutationSize,\n randomText(params.mutationSize),\n );\n });\n }\n },\n [TestSchemaType.organization]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.contact]: async () => {\n throw new Error('Method not implemented.');\n },\n [TestSchemaType.project]: async () => {\n throw new Error('Method not implemented.');\n },\n};\n\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type AnyLiveObject } from '@dxos/echo-db';\nimport { getTypeAnnotation, EchoSchema, getSchema } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { live, isLiveObject, type Live } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | Schema.Schema.AnyNoContext)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | Schema.Schema.AnyNoContext | undefined {\n return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<Live<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isLiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? live(schema, data) : live(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | Schema.Schema.AnyNoContext)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | Schema.Schema.AnyNoContext);\n this.setSchema(typename as T, echoSchema);\n result.push(echoSchema);\n }\n\n return result;\n }\n\n override async createObject({ types }: { types?: T[] } = {}): Promise<AnyLiveObject<any>> {\n return this._space.db.add(await super.createObject({ types }));\n }\n\n private async _maybeRegisterSchema(\n typename: string,\n schema: EchoSchema | Schema.Schema.AnyNoContext,\n ): Promise<EchoSchema | Schema.Schema.AnyNoContext> {\n if (schema instanceof EchoSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);\n return registeredSchema;\n } else {\n const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.graph.schemaRegistry.addSchema([schema]);\n return schema;\n }\n }\n\n async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams) {\n invariant(this._mutations, 'Mutations not defined.');\n const type = getTypeAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations;\n }\n\n async mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams) {\n for (const object of objects) {\n await this.mutateObject(object, params);\n }\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const randomText = (length: number) => {\n let result = '';\n const characters = 'abcdefghijklmnopqrstuvwxyz';\n const charactersLength = characters.length;\n for (let index = 0; index < length; index++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,cAAc;AAEvB,SAASC,QAAQC,SAAS;AAC1B,SAASC,yBAAqC;AAC9C,SAASC,WAAW;AACpB,SAASC,wBAAwB;AACjC,SAASC,SAAAA,cAAa;;;ACJtB,SAASC,cAA0B;AAEnC,SAASC,mBAAmBC,YAAYC,iBAAiB;AACzD,SAASC,iBAAiB;AAC1B,SAASC,MAAMC,oBAA+B;AAC9C,SAASC,aAAa;AACtB,SAASC,aAAa;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC,UAAuD;AACzD,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAR,UAAUc,MAA8D;AACtE,WAAO,KAAKH,QAAQI,KAAK,CAACC,WAAWlB,kBAAkBkB,MAAAA,EAASC,aAAaH,IAAAA;EAC/E;EAEUI,UAAUJ,MAASE,QAAiD;AAC5E,SAAKR,SAASM,IAAAA,IAAQE;EACxB;EAEA,MAAMG,aAAa,EAAEC,MAAK,IAAsB,CAAC,GAAuB;AACtE,UAAM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aAAaxD,MAAAA;IACnC2B,UAAUI,OAAMwB,QAAQC,aAAavD,QAAAA;IACrC2B,QAAQG,OAAMS,SAASC,QAAO;EAChC;AACF;AAEA,IAAMkB,qBAAuD;EAC3D,CAAA,2BAAA,GAA2B,OAAOC,QAAQC,WAAAA;AACxC,UAAMC,WAAWC,kBAAkBH,QAAQ;MAAC;KAAU;AACtD,aAASI,IAAI,GAAGA,IAAIH,OAAOI,OAAOD,KAAK;AACrC,YAAMX,SAASO,OAAO/C,SAASA,SAASwC,UAAU;AAClDS,eAASI,OAAOC,OAAO,CAACC,QAAAA;AACtBC,UAAEC,OACAF,KACAN,SAASS,KAAKC,MAAK,GACnB,GACAX,OAAOY,oBAAoBpB,SAAS,IAAIQ,OAAOa,cAC/CC,WAAWd,OAAOa,YAAY,CAAA;MAElC,CAAA;IACF;EACF;EACA,CAAA,+BAAA,GAA+B,YAAA;AAC7B,UAAM,IAAIE,MAAM,yBAAA;EAClB;EACA,CAAA,0BAAA,GAA0B,YAAA;AACxB,UAAM,IAAIA,MAAM,yBAAA;EAClB;EACA,CAAA,0BAAA,GAA0B,YAAA;AACxB,UAAM,IAAIA,MAAM,yBAAA;EAClB;AACF;AAEO,IAAMC,4BAA4B,MAAM,IAAIC,oBAAoB3E,YAAAA,GAAe2B,oBAAAA;AAE/E,IAAMiD,6BAA6B,CAACC,UACzC,IAAIC,qBAAqBD,OAAO7E,YAAAA,GAAe2B,sBAAsB6B,kBAAAA;",
|
|
6
|
+
"names": ["Schema", "next", "A", "createDocAccessor", "Ref", "createEchoSchema", "faker", "Filter", "getTypeAnnotation", "EchoSchema", "getSchema", "invariant", "live", "isLiveObject", "faker", "range", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "type", "find", "schema", "typename", "setSchema", "createObject", "types", "helpers", "arrayElement", "keys", "data", "createObjects", "map", "tasks", "entries", "count", "flatMap", "t", "Promise", "all", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "_mutations", "db", "query", "run", "objects", "addSchemas", "result", "echoSchema", "_maybeRegisterSchema", "push", "add", "existingSchema", "schemaRegistry", "registeredSchema", "register", "graph", "addSchema", "mutateObject", "object", "params", "mutateObjects", "randomText", "length", "result", "characters", "charactersLength", "index", "charAt", "Math", "floor", "random", "Status", "Priority", "TestSchemaType", "testSchemas", "document", "createEchoSchema", "typename", "version", "title", "Schema", "String", "annotations", "description", "content", "organization", "name", "website", "contact", "email", "org", "Ref", "lat", "Number", "lng", "project", "repo", "status", "priority", "active", "Boolean", "testObjectGenerators", "faker", "lorem", "sentence", "sentences", "min", "max", "number", "int", "company", "datatype", "boolean", "probability", "internet", "url", "undefined", "provider", "organizations", "location", "geo", "airport", "person", "fullName", "length", "make", "helpers", "arrayElement", "commerce", "productName", "testObjectMutators", "object", "params", "accessor", "createDocAccessor", "i", "count", "handle", "change", "doc", "A", "splice", "path", "slice", "maxContentLength", "mutationSize", "randomText", "Error", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":15773,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":18896,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/types.ts":{"bytes":1745,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":751,"imports":[{"path":"packages/core/echo/echo-generator/src/data.ts","kind":"import-statement","original":"./data"},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"},{"path":"packages/core/echo/echo-generator/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/core/echo/echo-generator/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18027},"packages/core/echo/echo-generator/dist/lib/node-esm/index.mjs":{"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/automerge/automerge","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Priority","SpaceObjectGenerator","Status","TestObjectGenerator","TestSchemaType","createSpaceObjectGenerator","createTestObjectGenerator","randomText"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":4688},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3709},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9199}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/data.ts"],"names":[],"mappings":"AAOA,OAAO,EAAqB,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAKlE,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQxE,eAAO,MAAM,MAAM,UAAgC,CAAC;AACpD,eAAO,MAAM,QAAQ,UAAkB,CAAC;AAExC,oBAAY,cAAc;IACxB,QAAQ,8BAA8B;IACtC,YAAY,kCAAkC;IAC9C,OAAO,6BAA6B;IACpC,OAAO,6BAA6B;CACrC;AA+HD,eAAO,MAAM,yBAAyB,2CAAqE,CAAC;AAE5G,eAAO,MAAM,0BAA0B,UAAW,KAAK,yCACmC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type Schema } from 'effect';
|
|
1
2
|
import { type Space } from '@dxos/client/echo';
|
|
2
|
-
import { type
|
|
3
|
-
import { EchoSchema
|
|
4
|
-
import { type
|
|
3
|
+
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
4
|
+
import { EchoSchema } from '@dxos/echo-schema';
|
|
5
|
+
import { type Live } from '@dxos/live-object';
|
|
5
6
|
import { type TestSchemaType } from './data';
|
|
6
7
|
import { type MutationsProviderParams, type TestGeneratorMap, type TestMutationsMap, type TestObjectProvider, type TestSchemaMap } from './types';
|
|
7
8
|
/**
|
|
@@ -12,13 +13,13 @@ export declare class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
12
13
|
private readonly _generators;
|
|
13
14
|
private readonly _provider?;
|
|
14
15
|
constructor(_schemas: TestSchemaMap<T>, _generators: TestGeneratorMap<T>, _provider?: TestObjectProvider<T> | undefined);
|
|
15
|
-
get schemas(): (EchoSchema |
|
|
16
|
-
getSchema(type: T): EchoSchema |
|
|
17
|
-
protected setSchema(type: T, schema: EchoSchema |
|
|
16
|
+
get schemas(): (EchoSchema | Schema.Schema.AnyNoContext)[];
|
|
17
|
+
getSchema(type: T): EchoSchema | Schema.Schema.AnyNoContext | undefined;
|
|
18
|
+
protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext): void;
|
|
18
19
|
createObject({ types }?: {
|
|
19
20
|
types?: T[];
|
|
20
|
-
}): Promise<
|
|
21
|
-
createObjects(map: Partial<Record<T, number>>): Promise<
|
|
21
|
+
}): Promise<Live<any>>;
|
|
22
|
+
createObjects(map: Partial<Record<T, number>>): Promise<any[]>;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Typed object generator for a space.
|
|
@@ -27,12 +28,12 @@ export declare class SpaceObjectGenerator<T extends string> extends TestObjectGe
|
|
|
27
28
|
private readonly _space;
|
|
28
29
|
private readonly _mutations?;
|
|
29
30
|
constructor(_space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>, _mutations?: TestMutationsMap<T> | undefined);
|
|
30
|
-
addSchemas(): Promise<(
|
|
31
|
+
addSchemas(): Promise<(Schema.Schema.AnyNoContext | EchoSchema<any, any>)[]>;
|
|
31
32
|
createObject({ types }?: {
|
|
32
33
|
types?: T[];
|
|
33
|
-
}): Promise<
|
|
34
|
+
}): Promise<AnyLiveObject<any>>;
|
|
34
35
|
private _maybeRegisterSchema;
|
|
35
|
-
mutateObject(object:
|
|
36
|
-
mutateObjects(objects:
|
|
36
|
+
mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams): Promise<void>;
|
|
37
|
+
mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams): Promise<void>;
|
|
37
38
|
}
|
|
38
39
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAqB,UAAU,EAAa,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EAAsB,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAIlE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc;IAG9D,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAFR,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC5B,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAChC,SAAS,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,YAAA;IAGpD,IAAI,OAAO,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAEzD;IAED,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,SAAS;IAIvE,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY;IAItE,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAYjE,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;CASpD;AAED;;GAEG;AACH,qBAAa,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IAE9E,OAAO,CAAC,QAAQ,CAAC,MAAM;IAGvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAHX,MAAM,EAAE,KAAK,EAC9B,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAC3B,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACd,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,YAAA;IAQ7C,UAAU;IAWD,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YAI3E,oBAAoB;IAqB5B,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,uBAAuB;IAQxE,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,uBAAuB;CAKnF"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
1
|
+
import { type Schema } from 'effect';
|
|
2
|
+
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
3
|
+
import { type EchoSchema } from '@dxos/echo-schema';
|
|
4
|
+
import { type Live } from '@dxos/live-object';
|
|
4
5
|
export type TestObject = {
|
|
5
6
|
id: string;
|
|
6
7
|
} & Record<string, any>;
|
|
7
|
-
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema |
|
|
8
|
-
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<
|
|
8
|
+
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema | Schema.Schema.AnyNoContext>;
|
|
9
|
+
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<Live<any>[]>;
|
|
9
10
|
export type TestGeneratorMap<T extends string = string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
|
|
10
11
|
export type TestMutationsMap<T extends string = string> = Record<T, TestObjectMutators>;
|
|
11
12
|
export type MutationsProviderParams = {
|
|
@@ -13,5 +14,5 @@ export type MutationsProviderParams = {
|
|
|
13
14
|
mutationSize: number;
|
|
14
15
|
maxContentLength: number;
|
|
15
16
|
};
|
|
16
|
-
export type TestObjectMutators = (object:
|
|
17
|
+
export type TestObjectMutators = (object: AnyLiveObject<any>, params: MutationsProviderParams) => Promise<void>;
|
|
17
18
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAG9C,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE9D,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAE1G,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAE9F,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,CAC9D,CAAC,EACD,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,SAAS,KAAK,GAAG,CACrD,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;AAExF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2-main.2f9c567",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -24,21 +24,23 @@
|
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/echo-schema": "0.8.
|
|
32
|
-
"@dxos/live-object": "0.8.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
27
|
+
"effect": "3.14.21",
|
|
28
|
+
"@dxos/automerge": "0.8.2-main.2f9c567",
|
|
29
|
+
"@dxos/client": "0.8.2-main.2f9c567",
|
|
30
|
+
"@dxos/echo-db": "0.8.2-main.2f9c567",
|
|
31
|
+
"@dxos/echo-schema": "0.8.2-main.2f9c567",
|
|
32
|
+
"@dxos/live-object": "0.8.2-main.2f9c567",
|
|
33
|
+
"@dxos/invariant": "0.8.2-main.2f9c567",
|
|
34
|
+
"@dxos/node-std": "0.8.2-main.2f9c567",
|
|
35
|
+
"@dxos/schema": "0.8.2-main.2f9c567",
|
|
36
|
+
"@dxos/util": "0.8.2-main.2f9c567"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@dxos/random": "0.8.
|
|
39
|
+
"@dxos/random": "0.8.2-main.2f9c567"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"
|
|
42
|
+
"effect": "^3.13.3",
|
|
43
|
+
"@dxos/random": "0.8.2-main.2f9c567"
|
|
42
44
|
},
|
|
43
45
|
"publishConfig": {
|
|
44
46
|
"access": "public"
|
package/src/data.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
5
7
|
import { next as A } from '@dxos/automerge/automerge';
|
|
6
8
|
import { createDocAccessor, type Space } from '@dxos/client/echo';
|
|
7
|
-
import { Ref
|
|
8
|
-
import { createEchoSchema
|
|
9
|
+
import { Ref } from '@dxos/echo-schema';
|
|
10
|
+
import { createEchoSchema } from '@dxos/live-object';
|
|
9
11
|
import { faker } from '@dxos/random';
|
|
10
12
|
|
|
11
13
|
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
@@ -33,8 +35,8 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
33
35
|
version: '0.1.0',
|
|
34
36
|
},
|
|
35
37
|
{
|
|
36
|
-
title:
|
|
37
|
-
content:
|
|
38
|
+
title: Schema.String.annotations({ description: 'title of the document' }),
|
|
39
|
+
content: Schema.String,
|
|
38
40
|
},
|
|
39
41
|
);
|
|
40
42
|
|
|
@@ -44,9 +46,9 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
44
46
|
version: '0.1.0',
|
|
45
47
|
},
|
|
46
48
|
{
|
|
47
|
-
name:
|
|
48
|
-
website:
|
|
49
|
-
description:
|
|
49
|
+
name: Schema.String.annotations({ description: 'name of the company or organization' }),
|
|
50
|
+
website: Schema.String.annotations({ description: 'public website URL' }),
|
|
51
|
+
description: Schema.String.annotations({ description: 'short summary of the company' }),
|
|
50
52
|
},
|
|
51
53
|
);
|
|
52
54
|
|
|
@@ -56,11 +58,11 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
56
58
|
version: '0.1.0',
|
|
57
59
|
},
|
|
58
60
|
{
|
|
59
|
-
name:
|
|
60
|
-
email:
|
|
61
|
+
name: Schema.String.annotations({ description: 'name of the person' }),
|
|
62
|
+
email: Schema.String,
|
|
61
63
|
org: Ref(organization),
|
|
62
|
-
lat:
|
|
63
|
-
lng:
|
|
64
|
+
lat: Schema.Number,
|
|
65
|
+
lng: Schema.Number,
|
|
64
66
|
},
|
|
65
67
|
);
|
|
66
68
|
|
|
@@ -70,13 +72,13 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
70
72
|
version: '0.1.0',
|
|
71
73
|
},
|
|
72
74
|
{
|
|
73
|
-
name:
|
|
74
|
-
description:
|
|
75
|
-
website:
|
|
76
|
-
repo:
|
|
77
|
-
status:
|
|
78
|
-
priority:
|
|
79
|
-
active:
|
|
75
|
+
name: Schema.String.annotations({ description: 'name of the project' }),
|
|
76
|
+
description: Schema.String,
|
|
77
|
+
website: Schema.String,
|
|
78
|
+
repo: Schema.String,
|
|
79
|
+
status: Schema.String,
|
|
80
|
+
priority: Schema.Number,
|
|
81
|
+
active: Schema.Boolean,
|
|
80
82
|
org: Ref(organization),
|
|
81
83
|
},
|
|
82
84
|
);
|
|
@@ -109,7 +111,7 @@ const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
|
109
111
|
email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,
|
|
110
112
|
org:
|
|
111
113
|
organizations?.length && faker.datatype.boolean({ probability: 0.3 })
|
|
112
|
-
?
|
|
114
|
+
? Ref.make(faker.helpers.arrayElement(organizations))
|
|
113
115
|
: undefined,
|
|
114
116
|
...location,
|
|
115
117
|
};
|
package/src/generator.test.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema } from 'effect';
|
|
5
6
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
7
|
|
|
7
8
|
import { next as A } from '@dxos/automerge/automerge';
|
|
8
9
|
import { Client } from '@dxos/client';
|
|
9
10
|
import { getObjectCore } from '@dxos/echo-db';
|
|
10
|
-
import {
|
|
11
|
+
import { TypedObject } from '@dxos/echo-schema';
|
|
11
12
|
import { getType } from '@dxos/live-object';
|
|
12
13
|
import { faker } from '@dxos/random';
|
|
13
14
|
|
|
@@ -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(getType(organization)!.
|
|
63
|
+
schemaId.push(getType(organization)!.asEchoDXN()!.echoId!);
|
|
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(getType(organization)!.
|
|
70
|
+
schemaId.push(getType(organization)!.asEchoDXN()!.echoId!);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
expect(schemaId[0]).not.to.be.undefined;
|
|
@@ -96,7 +97,7 @@ describe('TestObjectGenerator', () => {
|
|
|
96
97
|
typename: 'example.org/type/Task',
|
|
97
98
|
version: '0.1.0',
|
|
98
99
|
})({
|
|
99
|
-
name:
|
|
100
|
+
name: Schema.optional(Schema.String),
|
|
100
101
|
}) {}
|
|
101
102
|
|
|
102
103
|
enum Types {
|
package/src/generator.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Schema } from 'effect';
|
|
6
|
+
|
|
5
7
|
import { Filter, type Space } from '@dxos/client/echo';
|
|
6
|
-
import { type
|
|
7
|
-
import { getTypeAnnotation, EchoSchema,
|
|
8
|
+
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
9
|
+
import { getTypeAnnotation, EchoSchema, getSchema } from '@dxos/echo-schema';
|
|
8
10
|
import { invariant } from '@dxos/invariant';
|
|
9
|
-
import {
|
|
11
|
+
import { live, isLiveObject, type Live } from '@dxos/live-object';
|
|
10
12
|
import { faker } from '@dxos/random';
|
|
11
13
|
import { range } from '@dxos/util';
|
|
12
14
|
|
|
@@ -30,27 +32,27 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
30
32
|
private readonly _provider?: TestObjectProvider<T>,
|
|
31
33
|
) {}
|
|
32
34
|
|
|
33
|
-
get schemas(): (EchoSchema |
|
|
35
|
+
get schemas(): (EchoSchema | Schema.Schema.AnyNoContext)[] {
|
|
34
36
|
return Object.values(this._schemas);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
getSchema(type: T): EchoSchema |
|
|
39
|
+
getSchema(type: T): EchoSchema | Schema.Schema.AnyNoContext | undefined {
|
|
38
40
|
return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
protected setSchema(type: T, schema: EchoSchema |
|
|
43
|
+
protected setSchema(type: T, schema: EchoSchema | Schema.Schema.AnyNoContext) {
|
|
42
44
|
this._schemas[type] = schema;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
async createObject({ types }: { types?: T[] } = {}): Promise<
|
|
47
|
+
async createObject({ types }: { types?: T[] } = {}): Promise<Live<any>> {
|
|
46
48
|
const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));
|
|
47
49
|
const data = await this._generators[type](this._provider);
|
|
48
|
-
if (
|
|
50
|
+
if (isLiveObject(data)) {
|
|
49
51
|
return data;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
const schema = this.getSchema(type);
|
|
53
|
-
return schema ?
|
|
55
|
+
return schema ? live(schema, data) : live(data);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
@@ -82,9 +84,9 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
async addSchemas() {
|
|
85
|
-
const result: (EchoSchema |
|
|
87
|
+
const result: (EchoSchema | Schema.Schema.AnyNoContext)[] = [];
|
|
86
88
|
for (const [typename, schema] of Object.entries(this._schemas)) {
|
|
87
|
-
const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema |
|
|
89
|
+
const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | Schema.Schema.AnyNoContext);
|
|
88
90
|
this.setSchema(typename as T, echoSchema);
|
|
89
91
|
result.push(echoSchema);
|
|
90
92
|
}
|
|
@@ -92,14 +94,14 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
92
94
|
return result;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
override async createObject({ types }: { types?: T[] } = {}): Promise<
|
|
97
|
+
override async createObject({ types }: { types?: T[] } = {}): Promise<AnyLiveObject<any>> {
|
|
96
98
|
return this._space.db.add(await super.createObject({ types }));
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
private async _maybeRegisterSchema(
|
|
100
102
|
typename: string,
|
|
101
|
-
schema: EchoSchema |
|
|
102
|
-
): Promise<EchoSchema |
|
|
103
|
+
schema: EchoSchema | Schema.Schema.AnyNoContext,
|
|
104
|
+
): Promise<EchoSchema | Schema.Schema.AnyNoContext> {
|
|
103
105
|
if (schema instanceof EchoSchema) {
|
|
104
106
|
const existingSchema = this._space.db.schemaRegistry.getSchema(typename);
|
|
105
107
|
if (existingSchema != null) {
|
|
@@ -117,7 +119,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
async mutateObject(object:
|
|
122
|
+
async mutateObject(object: AnyLiveObject<any>, params: MutationsProviderParams) {
|
|
121
123
|
invariant(this._mutations, 'Mutations not defined.');
|
|
122
124
|
const type = getTypeAnnotation(getSchema(object)!)!.typename as T;
|
|
123
125
|
invariant(type && this._mutations?.[type], 'Invalid object type.');
|
|
@@ -125,7 +127,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
125
127
|
await this._mutations;
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
async mutateObjects(objects:
|
|
130
|
+
async mutateObjects(objects: AnyLiveObject<any>[], params: MutationsProviderParams) {
|
|
129
131
|
for (const object of objects) {
|
|
130
132
|
await this.mutateObject(object, params);
|
|
131
133
|
}
|
package/src/types.ts
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
6
|
-
|
|
7
|
-
import { type
|
|
5
|
+
import { type Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
8
|
+
import { type EchoSchema } from '@dxos/echo-schema';
|
|
9
|
+
import { type Live } from '@dxos/live-object';
|
|
8
10
|
|
|
9
11
|
// TODO(burdon): Use echo-schema types.
|
|
10
12
|
export type TestObject = { id: string } & Record<string, any>;
|
|
11
13
|
|
|
12
|
-
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema |
|
|
14
|
+
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema | Schema.Schema.AnyNoContext>;
|
|
13
15
|
|
|
14
|
-
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<
|
|
16
|
+
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<Live<any>[]>;
|
|
15
17
|
|
|
16
18
|
export type TestGeneratorMap<T extends string = string> = Record<
|
|
17
19
|
T,
|
|
@@ -26,4 +28,4 @@ export type MutationsProviderParams = {
|
|
|
26
28
|
maxContentLength: number;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
|
-
export type TestObjectMutators = (object:
|
|
31
|
+
export type TestObjectMutators = (object: AnyLiveObject<any>, params: MutationsProviderParams) => Promise<void>;
|