@dxos/echo-generator 0.8.2-main.2f9c567 → 0.8.2-main.36232bc
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 +23 -23
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +21 -21
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +23 -23
- 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 +9 -10
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +4 -5
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +12 -14
- package/src/data.ts +19 -21
- package/src/generator.test.ts +4 -5
- package/src/generator.ts +13 -14
- package/src/types.ts +4 -6
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/core/echo/echo-generator/src/data.ts
|
|
4
|
-
import { Schema } from "effect";
|
|
5
4
|
import { next as A } from "@dxos/automerge/automerge";
|
|
6
5
|
import { createDocAccessor } from "@dxos/client/echo";
|
|
7
|
-
import { Ref } from "@dxos/echo-schema";
|
|
8
|
-
import { createEchoSchema } from "@dxos/live-object";
|
|
6
|
+
import { Ref, S } from "@dxos/echo-schema";
|
|
7
|
+
import { createEchoSchema, makeRef } from "@dxos/live-object";
|
|
9
8
|
import { faker as faker2 } from "@dxos/random";
|
|
10
9
|
|
|
11
10
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
12
11
|
import { Filter } from "@dxos/client/echo";
|
|
13
|
-
import { getTypeAnnotation, EchoSchema
|
|
12
|
+
import { getTypeAnnotation, EchoSchema } from "@dxos/echo-schema";
|
|
13
|
+
import { getSchema } from "@dxos/echo-schema";
|
|
14
14
|
import { invariant } from "@dxos/invariant";
|
|
15
15
|
import { live, isLiveObject } from "@dxos/live-object";
|
|
16
16
|
import { faker } from "@dxos/random";
|
|
@@ -100,7 +100,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
100
100
|
async mutateObject(object, params) {
|
|
101
101
|
invariant(this._mutations, "Mutations not defined.", {
|
|
102
102
|
F: __dxlog_file,
|
|
103
|
-
L:
|
|
103
|
+
L: 122,
|
|
104
104
|
S: this,
|
|
105
105
|
A: [
|
|
106
106
|
"this._mutations",
|
|
@@ -110,7 +110,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
110
110
|
const type = getTypeAnnotation(getSchema(object)).typename;
|
|
111
111
|
invariant(type && this._mutations?.[type], "Invalid object type.", {
|
|
112
112
|
F: __dxlog_file,
|
|
113
|
-
L:
|
|
113
|
+
L: 124,
|
|
114
114
|
S: this,
|
|
115
115
|
A: [
|
|
116
116
|
"type && this._mutations?.[type]",
|
|
@@ -162,22 +162,22 @@ var testSchemas = () => {
|
|
|
162
162
|
typename: "example.com/type/document",
|
|
163
163
|
version: "0.1.0"
|
|
164
164
|
}, {
|
|
165
|
-
title:
|
|
165
|
+
title: S.String.annotations({
|
|
166
166
|
description: "title of the document"
|
|
167
167
|
}),
|
|
168
|
-
content:
|
|
168
|
+
content: S.String
|
|
169
169
|
});
|
|
170
170
|
const organization = createEchoSchema({
|
|
171
171
|
typename: "example.com/type/organization",
|
|
172
172
|
version: "0.1.0"
|
|
173
173
|
}, {
|
|
174
|
-
name:
|
|
174
|
+
name: S.String.annotations({
|
|
175
175
|
description: "name of the company or organization"
|
|
176
176
|
}),
|
|
177
|
-
website:
|
|
177
|
+
website: S.String.annotations({
|
|
178
178
|
description: "public website URL"
|
|
179
179
|
}),
|
|
180
|
-
description:
|
|
180
|
+
description: S.String.annotations({
|
|
181
181
|
description: "short summary of the company"
|
|
182
182
|
})
|
|
183
183
|
});
|
|
@@ -185,27 +185,27 @@ var testSchemas = () => {
|
|
|
185
185
|
typename: "example.com/type/contact",
|
|
186
186
|
version: "0.1.0"
|
|
187
187
|
}, {
|
|
188
|
-
name:
|
|
188
|
+
name: S.String.annotations({
|
|
189
189
|
description: "name of the person"
|
|
190
190
|
}),
|
|
191
|
-
email:
|
|
191
|
+
email: S.String,
|
|
192
192
|
org: Ref(organization),
|
|
193
|
-
lat:
|
|
194
|
-
lng:
|
|
193
|
+
lat: S.Number,
|
|
194
|
+
lng: S.Number
|
|
195
195
|
});
|
|
196
196
|
const project = createEchoSchema({
|
|
197
197
|
typename: "example.com/type/project",
|
|
198
198
|
version: "0.1.0"
|
|
199
199
|
}, {
|
|
200
|
-
name:
|
|
200
|
+
name: S.String.annotations({
|
|
201
201
|
description: "name of the project"
|
|
202
202
|
}),
|
|
203
|
-
description:
|
|
204
|
-
website:
|
|
205
|
-
repo:
|
|
206
|
-
status:
|
|
207
|
-
priority:
|
|
208
|
-
active:
|
|
203
|
+
description: S.String,
|
|
204
|
+
website: S.String,
|
|
205
|
+
repo: S.String,
|
|
206
|
+
status: S.String,
|
|
207
|
+
priority: S.Number,
|
|
208
|
+
active: S.Boolean,
|
|
209
209
|
org: Ref(organization)
|
|
210
210
|
});
|
|
211
211
|
return {
|
|
@@ -243,7 +243,7 @@ var testObjectGenerators = {
|
|
|
243
243
|
}) ? faker2.internet.email() : void 0,
|
|
244
244
|
org: organizations?.length && faker2.datatype.boolean({
|
|
245
245
|
probability: 0.3
|
|
246
|
-
}) ?
|
|
246
|
+
}) ? makeRef(faker2.helpers.arrayElement(organizations)) : void 0,
|
|
247
247
|
...location
|
|
248
248
|
};
|
|
249
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 { 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,
|
|
6
|
-
"names": ["
|
|
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 { 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 | 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<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 | 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,KAAKC,SAAS;AACvB,SAASC,kBAAkBC,eAAe;AAC1C,SAASC,SAAAA,cAAa;;;ACJtB,SAASC,cAA0B;AAEnC,SAASC,mBAAmBC,kBAA0B;AACtD,SAASC,iBAAiB;AAC1B,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,UAAkD;AACpD,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAR,UAAUc,MAAyD;AACjE,WAAO,KAAKH,QAAQI,KAAK,CAACC,WAAWlB,kBAAkBkB,MAAAA,EAASC,aAAaH,IAAAA;EAC/E;EAEUI,UAAUJ,MAASE,QAA4C;AACvE,SAAKR,SAASM,IAAAA,IAAQE;EACxB;EAEA,MAAMG,aAAa,EAAEC,MAAK,IAAsB,CAAC,GAAuB;AACtE,UAAMN,OAAOV,MAAMiB,QAAQC,aAAaF,SAAUR,OAAOW,KAAK,KAAKf,QAAQ,CAAA;AAC3E,UAAMgB,OAAO,MAAM,KAAKf,YAAYK,IAAAA,EAAM,KAAKJ,SAAS;AACxD,QAAIP,aAAaqB,IAAAA,GAAO;AACtB,aAAOA;IACT;AAEA,UAAMR,SAAS,KAAKhB,UAAUc,IAAAA;AAC9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AAIH,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": ["next", "A", "createDocAccessor", "Ref", "S", "createEchoSchema", "makeRef", "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", "S", "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", "makeRef", "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":15821,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","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":18602,"imports":[{"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":1705,"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":17911},"packages/core/echo/echo-generator/dist/lib/browser/index.mjs":{"imports":[{"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/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":4586},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3745},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9074}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -28,7 +28,6 @@ __export(node_exports, {
|
|
|
28
28
|
randomText: () => randomText
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(node_exports);
|
|
31
|
-
var import_effect = require("effect");
|
|
32
31
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
33
32
|
var import_echo = require("@dxos/client/echo");
|
|
34
33
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
@@ -36,6 +35,7 @@ var import_live_object = require("@dxos/live-object");
|
|
|
36
35
|
var import_random = require("@dxos/random");
|
|
37
36
|
var import_echo2 = require("@dxos/client/echo");
|
|
38
37
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
38
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
39
39
|
var import_invariant = require("@dxos/invariant");
|
|
40
40
|
var import_live_object2 = require("@dxos/live-object");
|
|
41
41
|
var import_random2 = require("@dxos/random");
|
|
@@ -125,17 +125,17 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
125
125
|
async mutateObject(object, params) {
|
|
126
126
|
(0, import_invariant.invariant)(this._mutations, "Mutations not defined.", {
|
|
127
127
|
F: __dxlog_file,
|
|
128
|
-
L:
|
|
128
|
+
L: 122,
|
|
129
129
|
S: this,
|
|
130
130
|
A: [
|
|
131
131
|
"this._mutations",
|
|
132
132
|
"'Mutations not defined.'"
|
|
133
133
|
]
|
|
134
134
|
});
|
|
135
|
-
const type = (0, import_echo_schema2.getTypeAnnotation)((0,
|
|
135
|
+
const type = (0, import_echo_schema2.getTypeAnnotation)((0, import_echo_schema3.getSchema)(object)).typename;
|
|
136
136
|
(0, import_invariant.invariant)(type && this._mutations?.[type], "Invalid object type.", {
|
|
137
137
|
F: __dxlog_file,
|
|
138
|
-
L:
|
|
138
|
+
L: 124,
|
|
139
139
|
S: this,
|
|
140
140
|
A: [
|
|
141
141
|
"type && this._mutations?.[type]",
|
|
@@ -183,22 +183,22 @@ var testSchemas = () => {
|
|
|
183
183
|
typename: "example.com/type/document",
|
|
184
184
|
version: "0.1.0"
|
|
185
185
|
}, {
|
|
186
|
-
title:
|
|
186
|
+
title: import_echo_schema.S.String.annotations({
|
|
187
187
|
description: "title of the document"
|
|
188
188
|
}),
|
|
189
|
-
content:
|
|
189
|
+
content: import_echo_schema.S.String
|
|
190
190
|
});
|
|
191
191
|
const organization = (0, import_live_object.createEchoSchema)({
|
|
192
192
|
typename: "example.com/type/organization",
|
|
193
193
|
version: "0.1.0"
|
|
194
194
|
}, {
|
|
195
|
-
name:
|
|
195
|
+
name: import_echo_schema.S.String.annotations({
|
|
196
196
|
description: "name of the company or organization"
|
|
197
197
|
}),
|
|
198
|
-
website:
|
|
198
|
+
website: import_echo_schema.S.String.annotations({
|
|
199
199
|
description: "public website URL"
|
|
200
200
|
}),
|
|
201
|
-
description:
|
|
201
|
+
description: import_echo_schema.S.String.annotations({
|
|
202
202
|
description: "short summary of the company"
|
|
203
203
|
})
|
|
204
204
|
});
|
|
@@ -206,27 +206,27 @@ var testSchemas = () => {
|
|
|
206
206
|
typename: "example.com/type/contact",
|
|
207
207
|
version: "0.1.0"
|
|
208
208
|
}, {
|
|
209
|
-
name:
|
|
209
|
+
name: import_echo_schema.S.String.annotations({
|
|
210
210
|
description: "name of the person"
|
|
211
211
|
}),
|
|
212
|
-
email:
|
|
212
|
+
email: import_echo_schema.S.String,
|
|
213
213
|
org: (0, import_echo_schema.Ref)(organization),
|
|
214
|
-
lat:
|
|
215
|
-
lng:
|
|
214
|
+
lat: import_echo_schema.S.Number,
|
|
215
|
+
lng: import_echo_schema.S.Number
|
|
216
216
|
});
|
|
217
217
|
const project = (0, import_live_object.createEchoSchema)({
|
|
218
218
|
typename: "example.com/type/project",
|
|
219
219
|
version: "0.1.0"
|
|
220
220
|
}, {
|
|
221
|
-
name:
|
|
221
|
+
name: import_echo_schema.S.String.annotations({
|
|
222
222
|
description: "name of the project"
|
|
223
223
|
}),
|
|
224
|
-
description:
|
|
225
|
-
website:
|
|
226
|
-
repo:
|
|
227
|
-
status:
|
|
228
|
-
priority:
|
|
229
|
-
active:
|
|
224
|
+
description: import_echo_schema.S.String,
|
|
225
|
+
website: import_echo_schema.S.String,
|
|
226
|
+
repo: import_echo_schema.S.String,
|
|
227
|
+
status: import_echo_schema.S.String,
|
|
228
|
+
priority: import_echo_schema.S.Number,
|
|
229
|
+
active: import_echo_schema.S.Boolean,
|
|
230
230
|
org: (0, import_echo_schema.Ref)(organization)
|
|
231
231
|
});
|
|
232
232
|
return {
|
|
@@ -264,7 +264,7 @@ var testObjectGenerators = {
|
|
|
264
264
|
}) ? import_random.faker.internet.email() : void 0,
|
|
265
265
|
org: organizations?.length && import_random.faker.datatype.boolean({
|
|
266
266
|
probability: 0.3
|
|
267
|
-
}) ?
|
|
267
|
+
}) ? (0, import_live_object.makeRef)(import_random.faker.helpers.arrayElement(organizations)) : void 0,
|
|
268
268
|
...location
|
|
269
269
|
};
|
|
270
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 { 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,
|
|
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", "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", "
|
|
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 { 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 | 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<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 | 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,yBAAuB;AACvB,yBAA0C;AAC1C,oBAAsB;ACJtB,IAAAA,eAAmC;AAEnC,IAAAC,sBAAsD;AACtD,IAAAA,sBAA0B;AAC1B,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,UAAkD;AACpD,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAM,UAAUC,MAAyD;AACjE,WAAO,KAAKJ,QAAQK,KAAK,CAACC,eAAWC,uCAAkBD,MAAAA,EAASE,aAAaJ,IAAAA;EAC/E;EAEUK,UAAUL,MAASE,QAA4C;AACvE,SAAKT,SAASO,IAAAA,IAAQE;EACxB;EAEA,MAAMI,aAAa,EAAEC,MAAK,IAAsB,CAAC,GAAuB;AACtE,UAAMP,OAAOQ,qBAAMC,QAAQC,aAAaH,SAAUV,OAAOc,KAAK,KAAKlB,QAAQ,CAAA;AAC3E,UAAMmB,OAAO,MAAM,KAAKlB,YAAYM,IAAAA,EAAM,KAAKL,SAAS;AACxD,YAAIkB,kCAAaD,IAAAA,GAAO;AACtB,aAAOA;IACT;AAEA,UAAMV,SAAS,KAAKH,UAAUC,IAAAA;AAC9B,WAAOE,aAASY,0BAAKZ,QAAQU,IAAAA,QAAQE,0BAAKF,IAAAA;EAC5C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ACF;AAEA,IAAMe,qBAAuD;EAC3D,CAAA,2BAAA,GAA2B,OAAOnE,QAAQC,WAAAA;AACxC,UAAMmE,eAAWC,+BAAkBrE,QAAQ;MAAC;KAAU;AACtD,aAASsE,IAAI,GAAGA,IAAIrE,OAAO/B,OAAOoG,KAAK;AACrC,YAAMjE,SAASL,OAAOyB,SAASA,SAASpB,UAAU;AAClD+D,eAASG,OAAOC,OAAO,CAACC,QAAAA;AACtBC,yBAAAA,KAAEC,OACAF,KACAL,SAASQ,KAAKC,MAAK,GACnB,GACA5E,OAAO6E,oBAAoBzE,SAAS,IAAIJ,OAAO8E,cAC/C3E,WAAWH,OAAO8E,YAAY,CAAA;MAElC,CAAA;IACF;EACF;EACA,CAAA,+BAAA,GAA+B,YAAA;AAC7B,UAAM,IAAIC,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,IAAI3I,oBAAoB0E,YAAAA,GAAe0B,oBAAAA;AAE/E,IAAMwC,6BAA6B,CAACC,UACzC,IAAI3G,qBAAqB2G,OAAOnE,YAAAA,GAAe0B,sBAAsByB,kBAAAA;",
|
|
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", "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", "S", "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", "makeRef", "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":15821,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","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":18602,"imports":[{"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":1705,"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":17909},"packages/core/echo/echo-generator/dist/lib/node/index.cjs":{"imports":[{"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/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":4586},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3745},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9040}}}
|
|
@@ -1,16 +1,16 @@
|
|
|
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";
|
|
5
4
|
import { next as A } from "@dxos/automerge/automerge";
|
|
6
5
|
import { createDocAccessor } from "@dxos/client/echo";
|
|
7
|
-
import { Ref } from "@dxos/echo-schema";
|
|
8
|
-
import { createEchoSchema } from "@dxos/live-object";
|
|
6
|
+
import { Ref, S } from "@dxos/echo-schema";
|
|
7
|
+
import { createEchoSchema, makeRef } from "@dxos/live-object";
|
|
9
8
|
import { faker as faker2 } from "@dxos/random";
|
|
10
9
|
|
|
11
10
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
12
11
|
import { Filter } from "@dxos/client/echo";
|
|
13
|
-
import { getTypeAnnotation, EchoSchema
|
|
12
|
+
import { getTypeAnnotation, EchoSchema } from "@dxos/echo-schema";
|
|
13
|
+
import { getSchema } from "@dxos/echo-schema";
|
|
14
14
|
import { invariant } from "@dxos/invariant";
|
|
15
15
|
import { live, isLiveObject } from "@dxos/live-object";
|
|
16
16
|
import { faker } from "@dxos/random";
|
|
@@ -100,7 +100,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
100
100
|
async mutateObject(object, params) {
|
|
101
101
|
invariant(this._mutations, "Mutations not defined.", {
|
|
102
102
|
F: __dxlog_file,
|
|
103
|
-
L:
|
|
103
|
+
L: 122,
|
|
104
104
|
S: this,
|
|
105
105
|
A: [
|
|
106
106
|
"this._mutations",
|
|
@@ -110,7 +110,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
110
110
|
const type = getTypeAnnotation(getSchema(object)).typename;
|
|
111
111
|
invariant(type && this._mutations?.[type], "Invalid object type.", {
|
|
112
112
|
F: __dxlog_file,
|
|
113
|
-
L:
|
|
113
|
+
L: 124,
|
|
114
114
|
S: this,
|
|
115
115
|
A: [
|
|
116
116
|
"type && this._mutations?.[type]",
|
|
@@ -162,22 +162,22 @@ var testSchemas = () => {
|
|
|
162
162
|
typename: "example.com/type/document",
|
|
163
163
|
version: "0.1.0"
|
|
164
164
|
}, {
|
|
165
|
-
title:
|
|
165
|
+
title: S.String.annotations({
|
|
166
166
|
description: "title of the document"
|
|
167
167
|
}),
|
|
168
|
-
content:
|
|
168
|
+
content: S.String
|
|
169
169
|
});
|
|
170
170
|
const organization = createEchoSchema({
|
|
171
171
|
typename: "example.com/type/organization",
|
|
172
172
|
version: "0.1.0"
|
|
173
173
|
}, {
|
|
174
|
-
name:
|
|
174
|
+
name: S.String.annotations({
|
|
175
175
|
description: "name of the company or organization"
|
|
176
176
|
}),
|
|
177
|
-
website:
|
|
177
|
+
website: S.String.annotations({
|
|
178
178
|
description: "public website URL"
|
|
179
179
|
}),
|
|
180
|
-
description:
|
|
180
|
+
description: S.String.annotations({
|
|
181
181
|
description: "short summary of the company"
|
|
182
182
|
})
|
|
183
183
|
});
|
|
@@ -185,27 +185,27 @@ var testSchemas = () => {
|
|
|
185
185
|
typename: "example.com/type/contact",
|
|
186
186
|
version: "0.1.0"
|
|
187
187
|
}, {
|
|
188
|
-
name:
|
|
188
|
+
name: S.String.annotations({
|
|
189
189
|
description: "name of the person"
|
|
190
190
|
}),
|
|
191
|
-
email:
|
|
191
|
+
email: S.String,
|
|
192
192
|
org: Ref(organization),
|
|
193
|
-
lat:
|
|
194
|
-
lng:
|
|
193
|
+
lat: S.Number,
|
|
194
|
+
lng: S.Number
|
|
195
195
|
});
|
|
196
196
|
const project = createEchoSchema({
|
|
197
197
|
typename: "example.com/type/project",
|
|
198
198
|
version: "0.1.0"
|
|
199
199
|
}, {
|
|
200
|
-
name:
|
|
200
|
+
name: S.String.annotations({
|
|
201
201
|
description: "name of the project"
|
|
202
202
|
}),
|
|
203
|
-
description:
|
|
204
|
-
website:
|
|
205
|
-
repo:
|
|
206
|
-
status:
|
|
207
|
-
priority:
|
|
208
|
-
active:
|
|
203
|
+
description: S.String,
|
|
204
|
+
website: S.String,
|
|
205
|
+
repo: S.String,
|
|
206
|
+
status: S.String,
|
|
207
|
+
priority: S.Number,
|
|
208
|
+
active: S.Boolean,
|
|
209
209
|
org: Ref(organization)
|
|
210
210
|
});
|
|
211
211
|
return {
|
|
@@ -243,7 +243,7 @@ var testObjectGenerators = {
|
|
|
243
243
|
}) ? faker2.internet.email() : void 0,
|
|
244
244
|
org: organizations?.length && faker2.datatype.boolean({
|
|
245
245
|
probability: 0.3
|
|
246
|
-
}) ?
|
|
246
|
+
}) ? makeRef(faker2.helpers.arrayElement(organizations)) : void 0,
|
|
247
247
|
...location
|
|
248
248
|
};
|
|
249
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 { 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,
|
|
6
|
-
"names": ["
|
|
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 { 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 | 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<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 | 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,KAAKC,SAAS;AACvB,SAASC,kBAAkBC,eAAe;AAC1C,SAASC,SAAAA,cAAa;;;ACJtB,SAASC,cAA0B;AAEnC,SAASC,mBAAmBC,kBAA0B;AACtD,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,MAAMC,oBAA+B;AAC9C,SAASC,aAAa;AACtB,SAASC,aAAa;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;S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AAA;",
|
|
6
|
+
"names": ["next", "A", "createDocAccessor", "Ref", "S", "createEchoSchema", "makeRef", "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", "S", "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", "makeRef", "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":15821,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","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":18602,"imports":[{"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":1705,"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":17911},"packages/core/echo/echo-generator/dist/lib/node-esm/index.mjs":{"imports":[{"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/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":4586},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3745},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9133}}}
|
|
@@ -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":"AAKA,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,6 @@
|
|
|
1
|
-
import { type Schema } from 'effect';
|
|
2
1
|
import { type Space } from '@dxos/client/echo';
|
|
3
|
-
import { type
|
|
4
|
-
import { EchoSchema } from '@dxos/echo-schema';
|
|
2
|
+
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
3
|
+
import { EchoSchema, type S } from '@dxos/echo-schema';
|
|
5
4
|
import { type Live } from '@dxos/live-object';
|
|
6
5
|
import { type TestSchemaType } from './data';
|
|
7
6
|
import { type MutationsProviderParams, type TestGeneratorMap, type TestMutationsMap, type TestObjectProvider, type TestSchemaMap } from './types';
|
|
@@ -13,9 +12,9 @@ export declare class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
13
12
|
private readonly _generators;
|
|
14
13
|
private readonly _provider?;
|
|
15
14
|
constructor(_schemas: TestSchemaMap<T>, _generators: TestGeneratorMap<T>, _provider?: TestObjectProvider<T> | undefined);
|
|
16
|
-
get schemas(): (EchoSchema |
|
|
17
|
-
getSchema(type: T): EchoSchema |
|
|
18
|
-
protected setSchema(type: T, schema: EchoSchema |
|
|
15
|
+
get schemas(): (EchoSchema | S.Schema.AnyNoContext)[];
|
|
16
|
+
getSchema(type: T): EchoSchema | S.Schema.AnyNoContext | undefined;
|
|
17
|
+
protected setSchema(type: T, schema: EchoSchema | S.Schema.AnyNoContext): void;
|
|
19
18
|
createObject({ types }?: {
|
|
20
19
|
types?: T[];
|
|
21
20
|
}): Promise<Live<any>>;
|
|
@@ -28,12 +27,12 @@ export declare class SpaceObjectGenerator<T extends string> extends TestObjectGe
|
|
|
28
27
|
private readonly _space;
|
|
29
28
|
private readonly _mutations?;
|
|
30
29
|
constructor(_space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>, _mutations?: TestMutationsMap<T> | undefined);
|
|
31
|
-
addSchemas(): Promise<(
|
|
30
|
+
addSchemas(): Promise<(S.Schema.AnyNoContext | EchoSchema<any, any>)[]>;
|
|
32
31
|
createObject({ types }?: {
|
|
33
32
|
types?: T[];
|
|
34
|
-
}): Promise<
|
|
33
|
+
}): Promise<ReactiveEchoObject<any>>;
|
|
35
34
|
private _maybeRegisterSchema;
|
|
36
|
-
mutateObject(object:
|
|
37
|
-
mutateObjects(objects:
|
|
35
|
+
mutateObject(object: ReactiveEchoObject<any>, params: MutationsProviderParams): Promise<void>;
|
|
36
|
+
mutateObjects(objects: ReactiveEchoObject<any>[], params: MutationsProviderParams): Promise<void>;
|
|
38
37
|
}
|
|
39
38
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
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,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAqB,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAG1E,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,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAEpD;IAED,SAAS,CAAC,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
|
+
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
2
|
+
import { type EchoSchema, type S } from '@dxos/echo-schema';
|
|
4
3
|
import { type Live } from '@dxos/live-object';
|
|
5
4
|
export type TestObject = {
|
|
6
5
|
id: string;
|
|
7
6
|
} & Record<string, any>;
|
|
8
|
-
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema |
|
|
7
|
+
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema | S.Schema.AnyNoContext>;
|
|
9
8
|
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<Live<any>[]>;
|
|
10
9
|
export type TestGeneratorMap<T extends string = string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
|
|
11
10
|
export type TestMutationsMap<T extends string = string> = Record<T, TestObjectMutators>;
|
|
@@ -14,5 +13,5 @@ export type MutationsProviderParams = {
|
|
|
14
13
|
mutationSize: number;
|
|
15
14
|
maxContentLength: number;
|
|
16
15
|
};
|
|
17
|
-
export type TestObjectMutators = (object:
|
|
16
|
+
export type TestObjectMutators = (object: ReactiveEchoObject<any>, params: MutationsProviderParams) => Promise<void>;
|
|
18
17
|
//# 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,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAC5D,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,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAErG,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,kBAAkB,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.2-main.
|
|
3
|
+
"version": "0.8.2-main.36232bc",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -24,23 +24,21 @@
|
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/echo-
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/live-object": "0.8.2-main.
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/util": "0.8.2-main.2f9c567"
|
|
27
|
+
"@dxos/automerge": "0.8.2-main.36232bc",
|
|
28
|
+
"@dxos/client": "0.8.2-main.36232bc",
|
|
29
|
+
"@dxos/echo-db": "0.8.2-main.36232bc",
|
|
30
|
+
"@dxos/echo-schema": "0.8.2-main.36232bc",
|
|
31
|
+
"@dxos/invariant": "0.8.2-main.36232bc",
|
|
32
|
+
"@dxos/live-object": "0.8.2-main.36232bc",
|
|
33
|
+
"@dxos/node-std": "0.8.2-main.36232bc",
|
|
34
|
+
"@dxos/schema": "0.8.2-main.36232bc",
|
|
35
|
+
"@dxos/util": "0.8.2-main.36232bc"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@dxos/random": "0.8.2-main.
|
|
38
|
+
"@dxos/random": "0.8.2-main.36232bc"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
|
-
"
|
|
43
|
-
"@dxos/random": "0.8.2-main.2f9c567"
|
|
41
|
+
"@dxos/random": "0.8.2-main.36232bc"
|
|
44
42
|
},
|
|
45
43
|
"publishConfig": {
|
|
46
44
|
"access": "public"
|
package/src/data.ts
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
5
|
import { next as A } from '@dxos/automerge/automerge';
|
|
8
6
|
import { createDocAccessor, type Space } from '@dxos/client/echo';
|
|
9
|
-
import { Ref } from '@dxos/echo-schema';
|
|
10
|
-
import { createEchoSchema } from '@dxos/live-object';
|
|
7
|
+
import { Ref, S } from '@dxos/echo-schema';
|
|
8
|
+
import { createEchoSchema, makeRef } from '@dxos/live-object';
|
|
11
9
|
import { faker } from '@dxos/random';
|
|
12
10
|
|
|
13
11
|
import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
|
|
@@ -35,8 +33,8 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
35
33
|
version: '0.1.0',
|
|
36
34
|
},
|
|
37
35
|
{
|
|
38
|
-
title:
|
|
39
|
-
content:
|
|
36
|
+
title: S.String.annotations({ description: 'title of the document' }),
|
|
37
|
+
content: S.String,
|
|
40
38
|
},
|
|
41
39
|
);
|
|
42
40
|
|
|
@@ -46,9 +44,9 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
46
44
|
version: '0.1.0',
|
|
47
45
|
},
|
|
48
46
|
{
|
|
49
|
-
name:
|
|
50
|
-
website:
|
|
51
|
-
description:
|
|
47
|
+
name: S.String.annotations({ description: 'name of the company or organization' }),
|
|
48
|
+
website: S.String.annotations({ description: 'public website URL' }),
|
|
49
|
+
description: S.String.annotations({ description: 'short summary of the company' }),
|
|
52
50
|
},
|
|
53
51
|
);
|
|
54
52
|
|
|
@@ -58,11 +56,11 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
58
56
|
version: '0.1.0',
|
|
59
57
|
},
|
|
60
58
|
{
|
|
61
|
-
name:
|
|
62
|
-
email:
|
|
59
|
+
name: S.String.annotations({ description: 'name of the person' }),
|
|
60
|
+
email: S.String,
|
|
63
61
|
org: Ref(organization),
|
|
64
|
-
lat:
|
|
65
|
-
lng:
|
|
62
|
+
lat: S.Number,
|
|
63
|
+
lng: S.Number,
|
|
66
64
|
},
|
|
67
65
|
);
|
|
68
66
|
|
|
@@ -72,13 +70,13 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
|
|
|
72
70
|
version: '0.1.0',
|
|
73
71
|
},
|
|
74
72
|
{
|
|
75
|
-
name:
|
|
76
|
-
description:
|
|
77
|
-
website:
|
|
78
|
-
repo:
|
|
79
|
-
status:
|
|
80
|
-
priority:
|
|
81
|
-
active:
|
|
73
|
+
name: S.String.annotations({ description: 'name of the project' }),
|
|
74
|
+
description: S.String,
|
|
75
|
+
website: S.String,
|
|
76
|
+
repo: S.String,
|
|
77
|
+
status: S.String,
|
|
78
|
+
priority: S.Number,
|
|
79
|
+
active: S.Boolean,
|
|
82
80
|
org: Ref(organization),
|
|
83
81
|
},
|
|
84
82
|
);
|
|
@@ -111,7 +109,7 @@ const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
|
|
|
111
109
|
email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,
|
|
112
110
|
org:
|
|
113
111
|
organizations?.length && faker.datatype.boolean({ probability: 0.3 })
|
|
114
|
-
?
|
|
112
|
+
? makeRef(faker.helpers.arrayElement(organizations))
|
|
115
113
|
: undefined,
|
|
116
114
|
...location,
|
|
117
115
|
};
|
package/src/generator.test.ts
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
5
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { next as A } from '@dxos/automerge/automerge';
|
|
9
8
|
import { Client } from '@dxos/client';
|
|
10
9
|
import { getObjectCore } from '@dxos/echo-db';
|
|
11
|
-
import { TypedObject } from '@dxos/echo-schema';
|
|
10
|
+
import { S, TypedObject } from '@dxos/echo-schema';
|
|
12
11
|
import { getType } from '@dxos/live-object';
|
|
13
12
|
import { faker } from '@dxos/random';
|
|
14
13
|
|
|
@@ -60,14 +59,14 @@ describe('TestObjectGenerator', () => {
|
|
|
60
59
|
const generator = createSpaceObjectGenerator(space);
|
|
61
60
|
await generator.addSchemas();
|
|
62
61
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
63
|
-
schemaId.push(getType(organization)!.
|
|
62
|
+
schemaId.push(getType(organization)!.objectId);
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
{
|
|
67
66
|
const generator = createSpaceObjectGenerator(space);
|
|
68
67
|
await generator.addSchemas();
|
|
69
68
|
const organization = await generator.createObject({ types: [TestSchemaType.organization] });
|
|
70
|
-
schemaId.push(getType(organization)!.
|
|
69
|
+
schemaId.push(getType(organization)!.objectId);
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
expect(schemaId[0]).not.to.be.undefined;
|
|
@@ -97,7 +96,7 @@ describe('TestObjectGenerator', () => {
|
|
|
97
96
|
typename: 'example.org/type/Task',
|
|
98
97
|
version: '0.1.0',
|
|
99
98
|
})({
|
|
100
|
-
name:
|
|
99
|
+
name: S.optional(S.String),
|
|
101
100
|
}) {}
|
|
102
101
|
|
|
103
102
|
enum Types {
|
package/src/generator.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Schema } from 'effect';
|
|
6
|
-
|
|
7
5
|
import { Filter, type Space } from '@dxos/client/echo';
|
|
8
|
-
import { type
|
|
9
|
-
import { getTypeAnnotation, EchoSchema,
|
|
6
|
+
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
7
|
+
import { getTypeAnnotation, EchoSchema, type S } from '@dxos/echo-schema';
|
|
8
|
+
import { getSchema } from '@dxos/echo-schema';
|
|
10
9
|
import { invariant } from '@dxos/invariant';
|
|
11
10
|
import { live, isLiveObject, type Live } from '@dxos/live-object';
|
|
12
11
|
import { faker } from '@dxos/random';
|
|
@@ -32,15 +31,15 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
|
|
|
32
31
|
private readonly _provider?: TestObjectProvider<T>,
|
|
33
32
|
) {}
|
|
34
33
|
|
|
35
|
-
get schemas(): (EchoSchema |
|
|
34
|
+
get schemas(): (EchoSchema | S.Schema.AnyNoContext)[] {
|
|
36
35
|
return Object.values(this._schemas);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
getSchema(type: T): EchoSchema |
|
|
38
|
+
getSchema(type: T): EchoSchema | S.Schema.AnyNoContext | undefined {
|
|
40
39
|
return this.schemas.find((schema) => getTypeAnnotation(schema)!.typename === type);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
protected setSchema(type: T, schema: EchoSchema |
|
|
42
|
+
protected setSchema(type: T, schema: EchoSchema | S.Schema.AnyNoContext) {
|
|
44
43
|
this._schemas[type] = schema;
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -84,9 +83,9 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
async addSchemas() {
|
|
87
|
-
const result: (EchoSchema |
|
|
86
|
+
const result: (EchoSchema | S.Schema.AnyNoContext)[] = [];
|
|
88
87
|
for (const [typename, schema] of Object.entries(this._schemas)) {
|
|
89
|
-
const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema |
|
|
88
|
+
const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema.AnyNoContext);
|
|
90
89
|
this.setSchema(typename as T, echoSchema);
|
|
91
90
|
result.push(echoSchema);
|
|
92
91
|
}
|
|
@@ -94,14 +93,14 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
94
93
|
return result;
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
override async createObject({ types }: { types?: T[] } = {}): Promise<
|
|
96
|
+
override async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveEchoObject<any>> {
|
|
98
97
|
return this._space.db.add(await super.createObject({ types }));
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
private async _maybeRegisterSchema(
|
|
102
101
|
typename: string,
|
|
103
|
-
schema: EchoSchema |
|
|
104
|
-
): Promise<EchoSchema |
|
|
102
|
+
schema: EchoSchema | S.Schema.AnyNoContext,
|
|
103
|
+
): Promise<EchoSchema | S.Schema.AnyNoContext> {
|
|
105
104
|
if (schema instanceof EchoSchema) {
|
|
106
105
|
const existingSchema = this._space.db.schemaRegistry.getSchema(typename);
|
|
107
106
|
if (existingSchema != null) {
|
|
@@ -119,7 +118,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
async mutateObject(object:
|
|
121
|
+
async mutateObject(object: ReactiveEchoObject<any>, params: MutationsProviderParams) {
|
|
123
122
|
invariant(this._mutations, 'Mutations not defined.');
|
|
124
123
|
const type = getTypeAnnotation(getSchema(object)!)!.typename as T;
|
|
125
124
|
invariant(type && this._mutations?.[type], 'Invalid object type.');
|
|
@@ -127,7 +126,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
127
126
|
await this._mutations;
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
async mutateObjects(objects:
|
|
129
|
+
async mutateObjects(objects: ReactiveEchoObject<any>[], params: MutationsProviderParams) {
|
|
131
130
|
for (const object of objects) {
|
|
132
131
|
await this.mutateObject(object, params);
|
|
133
132
|
}
|
package/src/types.ts
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
6
|
-
|
|
7
|
-
import { type AnyLiveObject } from '@dxos/echo-db';
|
|
8
|
-
import { type EchoSchema } from '@dxos/echo-schema';
|
|
5
|
+
import { type ReactiveEchoObject } from '@dxos/echo-db';
|
|
6
|
+
import { type EchoSchema, type S } from '@dxos/echo-schema';
|
|
9
7
|
import { type Live } from '@dxos/live-object';
|
|
10
8
|
|
|
11
9
|
// TODO(burdon): Use echo-schema types.
|
|
12
10
|
export type TestObject = { id: string } & Record<string, any>;
|
|
13
11
|
|
|
14
|
-
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema |
|
|
12
|
+
export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema | S.Schema.AnyNoContext>;
|
|
15
13
|
|
|
16
14
|
export type TestObjectProvider<T extends string = string> = (type: T) => Promise<Live<any>[]>;
|
|
17
15
|
|
|
@@ -28,4 +26,4 @@ export type MutationsProviderParams = {
|
|
|
28
26
|
maxContentLength: number;
|
|
29
27
|
};
|
|
30
28
|
|
|
31
|
-
export type TestObjectMutators = (object:
|
|
29
|
+
export type TestObjectMutators = (object: ReactiveEchoObject<any>, params: MutationsProviderParams) => Promise<void>;
|