@dxos/echo-generator 0.7.4 → 0.7.5-main.9cb18ac

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.
@@ -3,13 +3,13 @@ import "@dxos/node-std/globals";
3
3
  // packages/core/echo/echo-generator/src/data.ts
4
4
  import { next as A } from "@dxos/automerge/automerge";
5
5
  import { createDocAccessor } from "@dxos/client/echo";
6
- import { ref, S } from "@dxos/echo-schema";
7
- import { createMutableSchema } from "@dxos/live-object";
6
+ import { Ref, S } from "@dxos/echo-schema";
7
+ import { createEchoSchema, makeRef } from "@dxos/live-object";
8
8
  import { faker as faker2 } from "@dxos/random";
9
9
 
10
10
  // packages/core/echo/echo-generator/src/generator.ts
11
11
  import { Filter } from "@dxos/client/echo";
12
- import { getObjectAnnotation, MutableSchema } from "@dxos/echo-schema";
12
+ import { getObjectAnnotation, EchoSchema } from "@dxos/echo-schema";
13
13
  import { invariant } from "@dxos/invariant";
14
14
  import { create, getSchema, isReactiveObject } from "@dxos/live-object";
15
15
  import { faker } from "@dxos/random";
@@ -60,15 +60,13 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
60
60
  });
61
61
  this._space = _space;
62
62
  this._mutations = _mutations;
63
- Object.entries(schemaMap).forEach(([type, dynamicSchema]) => {
64
- const schema = this._maybeRegisterSchema(type, dynamicSchema);
65
- this.setSchema(type, schema);
66
- });
67
63
  }
68
- addSchemas() {
64
+ async addSchemas() {
69
65
  const result = [];
70
66
  for (const [typename, schema] of Object.entries(this._schemas)) {
71
- result.push(this._maybeRegisterSchema(typename, schema));
67
+ const echoSchema = await this._maybeRegisterSchema(typename, schema);
68
+ this.setSchema(typename, echoSchema);
69
+ result.push(echoSchema);
72
70
  }
73
71
  return result;
74
72
  }
@@ -77,14 +75,16 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
77
75
  types
78
76
  }));
79
77
  }
80
- _maybeRegisterSchema(typename, schema) {
81
- if (schema instanceof MutableSchema) {
78
+ async _maybeRegisterSchema(typename, schema) {
79
+ if (schema instanceof EchoSchema) {
82
80
  const existingSchema = this._space.db.schemaRegistry.getSchema(typename);
83
81
  if (existingSchema != null) {
84
82
  return existingSchema;
85
83
  }
86
- this._space.db.add(schema.storedSchema);
87
- return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);
84
+ const [registeredSchema] = await this._space.db.schemaRegistry.register([
85
+ schema
86
+ ]);
87
+ return registeredSchema;
88
88
  } else {
89
89
  const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);
90
90
  if (existingSchema != null) {
@@ -99,7 +99,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
99
99
  async mutateObject(object, params) {
100
100
  invariant(this._mutations, "Mutations not defined.", {
101
101
  F: __dxlog_file,
102
- L: 123,
102
+ L: 121,
103
103
  S: this,
104
104
  A: [
105
105
  "this._mutations",
@@ -109,7 +109,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
109
109
  const type = getObjectAnnotation(getSchema(object)).typename;
110
110
  invariant(type && this._mutations?.[type], "Invalid object type.", {
111
111
  F: __dxlog_file,
112
- L: 125,
112
+ L: 123,
113
113
  S: this,
114
114
  A: [
115
115
  "type && this._mutations?.[type]",
@@ -157,7 +157,7 @@ var TestSchemaType;
157
157
  TestSchemaType2["project"] = "example.com/type/project";
158
158
  })(TestSchemaType || (TestSchemaType = {}));
159
159
  var testSchemas = () => {
160
- const document = createMutableSchema({
160
+ const document = createEchoSchema({
161
161
  typename: "example.com/type/document",
162
162
  version: "0.1.0"
163
163
  }, {
@@ -166,7 +166,7 @@ var testSchemas = () => {
166
166
  }),
167
167
  content: S.String
168
168
  });
169
- const organization = createMutableSchema({
169
+ const organization = createEchoSchema({
170
170
  typename: "example.com/type/organization",
171
171
  version: "0.1.0"
172
172
  }, {
@@ -180,7 +180,7 @@ var testSchemas = () => {
180
180
  description: "short summary of the company"
181
181
  })
182
182
  });
183
- const contact = createMutableSchema({
183
+ const contact = createEchoSchema({
184
184
  typename: "example.com/type/contact",
185
185
  version: "0.1.0"
186
186
  }, {
@@ -188,11 +188,11 @@ var testSchemas = () => {
188
188
  description: "name of the person"
189
189
  }),
190
190
  email: S.String,
191
- org: ref(organization),
191
+ org: Ref(organization),
192
192
  lat: S.Number,
193
193
  lng: S.Number
194
194
  });
195
- const project = createMutableSchema({
195
+ const project = createEchoSchema({
196
196
  typename: "example.com/type/project",
197
197
  version: "0.1.0"
198
198
  }, {
@@ -205,7 +205,7 @@ var testSchemas = () => {
205
205
  status: S.String,
206
206
  priority: S.Number,
207
207
  active: S.Boolean,
208
- org: ref(organization)
208
+ org: Ref(organization)
209
209
  });
210
210
  return {
211
211
  ["example.com/type/document"]: document,
@@ -242,7 +242,7 @@ var testObjectGenerators = {
242
242
  }) ? faker2.internet.email() : void 0,
243
243
  org: organizations?.length && faker2.datatype.boolean({
244
244
  probability: 0.3
245
- }) ? faker2.helpers.arrayElement(organizations) : void 0,
245
+ }) ? makeRef(faker2.helpers.arrayElement(organizations)) : void 0,
246
246
  ...location
247
247
  };
248
248
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { ref, S } from '@dxos/echo-schema';\nimport { createMutableSchema } 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 = createMutableSchema(\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 = createMutableSchema(\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 = createMutableSchema(\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 = createMutableSchema(\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 ? 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 { getObjectAnnotation, MutableSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (MutableSchema | S.Schema<any>)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): MutableSchema | S.Schema<any> | undefined {\n return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: MutableSchema | S.Schema<any>) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n\n // TODO(burdon): Map initially are objects that have not been added to the space.\n // Merge existing schema in space with defaults.\n Object.entries<MutableSchema | S.Schema<any>>(schemaMap).forEach(([type, dynamicSchema]) => {\n const schema = this._maybeRegisterSchema(type, dynamicSchema);\n this.setSchema(type as T, schema);\n });\n }\n\n addSchemas() {\n const result: (MutableSchema | S.Schema<any>)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n result.push(this._maybeRegisterSchema(typename, schema as MutableSchema | S.Schema<any>));\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 _maybeRegisterSchema(typename: string, schema: MutableSchema | S.Schema<any>): MutableSchema | S.Schema<any> {\n if (schema instanceof MutableSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.add(schema.storedSchema);\n return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);\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 = getObjectAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations![type](object, params);\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,2BAA2B;AACpC,SAASC,SAAAA,cAAa;;;ACJtB,SAASC,cAA0B;AAEnC,SAASC,qBAAqBC,qBAA6B;AAC3D,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,WAAWC,wBAA6C;AACzE,SAASC,aAAa;AACtB,SAASC,aAAa;;AAcf,IAAMC,sBAAN,MAAMA;;EAE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EO,IAAMC,4BAA4B,MAAM,IAAIC,oBAAoB1E,YAAAA,GAAe2B,oBAAAA;AAE/E,IAAMgD,6BAA6B,CAACC,UACzC,IAAIC,qBAAqBD,OAAO5E,YAAAA,GAAe2B,sBAAsB4B,kBAAAA;",
6
- "names": ["next", "A", "createDocAccessor", "ref", "S", "createMutableSchema", "faker", "Filter", "getObjectAnnotation", "MutableSchema", "invariant", "create", "getSchema", "isReactiveObject", "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", "forEach", "dynamicSchema", "_maybeRegisterSchema", "addSchemas", "result", "push", "add", "existingSchema", "schemaRegistry", "storedSchema", "registerSchema", "graph", "addSchema", "mutateObject", "object", "params", "mutateObjects", "randomText", "length", "result", "characters", "charactersLength", "index", "charAt", "Math", "floor", "random", "Status", "Priority", "TestSchemaType", "testSchemas", "document", "createMutableSchema", "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", "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"]
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 { getObjectAnnotation, EchoSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | S.Schema<any>)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | S.Schema<any> | undefined {\n return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | S.Schema<any>) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | S.Schema<any>)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema<any>);\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<any>,\n ): Promise<EchoSchema | S.Schema<any>> {\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 = getObjectAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations![type](object, params);\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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,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", "getObjectAnnotation", "EchoSchema", "invariant", "create", "getSchema", "isReactiveObject", "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":16518,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":18563,"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":1729,"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":18205},"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/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":4583},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3807},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9133}}}
1
+ {"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":15721,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":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":1721,"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":17851},"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/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":3729},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9058}}}
@@ -85,15 +85,13 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
85
85
  });
86
86
  this._space = _space;
87
87
  this._mutations = _mutations;
88
- Object.entries(schemaMap).forEach(([type, dynamicSchema]) => {
89
- const schema = this._maybeRegisterSchema(type, dynamicSchema);
90
- this.setSchema(type, schema);
91
- });
92
88
  }
93
- addSchemas() {
89
+ async addSchemas() {
94
90
  const result = [];
95
91
  for (const [typename, schema] of Object.entries(this._schemas)) {
96
- result.push(this._maybeRegisterSchema(typename, schema));
92
+ const echoSchema = await this._maybeRegisterSchema(typename, schema);
93
+ this.setSchema(typename, echoSchema);
94
+ result.push(echoSchema);
97
95
  }
98
96
  return result;
99
97
  }
@@ -102,14 +100,16 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
102
100
  types
103
101
  }));
104
102
  }
105
- _maybeRegisterSchema(typename, schema) {
106
- if (schema instanceof import_echo_schema2.MutableSchema) {
103
+ async _maybeRegisterSchema(typename, schema) {
104
+ if (schema instanceof import_echo_schema2.EchoSchema) {
107
105
  const existingSchema = this._space.db.schemaRegistry.getSchema(typename);
108
106
  if (existingSchema != null) {
109
107
  return existingSchema;
110
108
  }
111
- this._space.db.add(schema.storedSchema);
112
- return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);
109
+ const [registeredSchema] = await this._space.db.schemaRegistry.register([
110
+ schema
111
+ ]);
112
+ return registeredSchema;
113
113
  } else {
114
114
  const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);
115
115
  if (existingSchema != null) {
@@ -124,7 +124,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
124
124
  async mutateObject(object, params) {
125
125
  (0, import_invariant.invariant)(this._mutations, "Mutations not defined.", {
126
126
  F: __dxlog_file,
127
- L: 123,
127
+ L: 121,
128
128
  S: this,
129
129
  A: [
130
130
  "this._mutations",
@@ -134,7 +134,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
134
134
  const type = (0, import_echo_schema2.getObjectAnnotation)((0, import_live_object2.getSchema)(object)).typename;
135
135
  (0, import_invariant.invariant)(type && this._mutations?.[type], "Invalid object type.", {
136
136
  F: __dxlog_file,
137
- L: 125,
137
+ L: 123,
138
138
  S: this,
139
139
  A: [
140
140
  "type && this._mutations?.[type]",
@@ -178,7 +178,7 @@ var TestSchemaType;
178
178
  TestSchemaType2["project"] = "example.com/type/project";
179
179
  })(TestSchemaType || (TestSchemaType = {}));
180
180
  var testSchemas = () => {
181
- const document = (0, import_live_object.createMutableSchema)({
181
+ const document = (0, import_live_object.createEchoSchema)({
182
182
  typename: "example.com/type/document",
183
183
  version: "0.1.0"
184
184
  }, {
@@ -187,7 +187,7 @@ var testSchemas = () => {
187
187
  }),
188
188
  content: import_echo_schema.S.String
189
189
  });
190
- const organization = (0, import_live_object.createMutableSchema)({
190
+ const organization = (0, import_live_object.createEchoSchema)({
191
191
  typename: "example.com/type/organization",
192
192
  version: "0.1.0"
193
193
  }, {
@@ -201,7 +201,7 @@ var testSchemas = () => {
201
201
  description: "short summary of the company"
202
202
  })
203
203
  });
204
- const contact = (0, import_live_object.createMutableSchema)({
204
+ const contact = (0, import_live_object.createEchoSchema)({
205
205
  typename: "example.com/type/contact",
206
206
  version: "0.1.0"
207
207
  }, {
@@ -209,11 +209,11 @@ var testSchemas = () => {
209
209
  description: "name of the person"
210
210
  }),
211
211
  email: import_echo_schema.S.String,
212
- org: (0, import_echo_schema.ref)(organization),
212
+ org: (0, import_echo_schema.Ref)(organization),
213
213
  lat: import_echo_schema.S.Number,
214
214
  lng: import_echo_schema.S.Number
215
215
  });
216
- const project = (0, import_live_object.createMutableSchema)({
216
+ const project = (0, import_live_object.createEchoSchema)({
217
217
  typename: "example.com/type/project",
218
218
  version: "0.1.0"
219
219
  }, {
@@ -226,7 +226,7 @@ var testSchemas = () => {
226
226
  status: import_echo_schema.S.String,
227
227
  priority: import_echo_schema.S.Number,
228
228
  active: import_echo_schema.S.Boolean,
229
- org: (0, import_echo_schema.ref)(organization)
229
+ org: (0, import_echo_schema.Ref)(organization)
230
230
  });
231
231
  return {
232
232
  ["example.com/type/document"]: document,
@@ -263,7 +263,7 @@ var testObjectGenerators = {
263
263
  }) ? import_random.faker.internet.email() : void 0,
264
264
  org: organizations?.length && import_random.faker.datatype.boolean({
265
265
  probability: 0.3
266
- }) ? import_random.faker.helpers.arrayElement(organizations) : void 0,
266
+ }) ? (0, import_live_object.makeRef)(import_random.faker.helpers.arrayElement(organizations)) : void 0,
267
267
  ...location
268
268
  };
269
269
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { ref, S } from '@dxos/echo-schema';\nimport { createMutableSchema } 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 = createMutableSchema(\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 = createMutableSchema(\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 = createMutableSchema(\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 = createMutableSchema(\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 ? 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 { getObjectAnnotation, MutableSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (MutableSchema | S.Schema<any>)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): MutableSchema | S.Schema<any> | undefined {\n return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: MutableSchema | S.Schema<any>) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n\n // TODO(burdon): Map initially are objects that have not been added to the space.\n // Merge existing schema in space with defaults.\n Object.entries<MutableSchema | S.Schema<any>>(schemaMap).forEach(([type, dynamicSchema]) => {\n const schema = this._maybeRegisterSchema(type, dynamicSchema);\n this.setSchema(type as T, schema);\n });\n }\n\n addSchemas() {\n const result: (MutableSchema | S.Schema<any>)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n result.push(this._maybeRegisterSchema(typename, schema as MutableSchema | S.Schema<any>));\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 _maybeRegisterSchema(typename: string, schema: MutableSchema | S.Schema<any>): MutableSchema | S.Schema<any> {\n if (schema instanceof MutableSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.add(schema.storedSchema);\n return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);\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 = getObjectAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations![type](object, params);\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,yBAAoC;AACpC,oBAAsB;ACJtB,IAAAA,eAAmC;AAEnC,IAAAC,sBAA2D;AAC3D,uBAA0B;AAC1B,IAAAC,sBAAyE;AACzE,IAAAC,iBAAsB;AACtB,kBAAsB;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC,UAA6C;AAC/C,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAM,UAAUC,MAAoD;AAC5D,WAAO,KAAKJ,QAAQK,KAAK,CAACC,eAAWC,yCAAoBD,MAAAA,EAASE,aAAaJ,IAAAA;EACjF;EAEUK,UAAUL,MAASE,QAAuC;AAClE,SAAKT,SAASO,IAAAA,IAAQE;EACxB;EAEA,MAAMI,aAAa,EAAEC,MAAK,IAAsB,CAAC,GAAiC;AAChF,UAAMP,OAAOQ,qBAAMC,QAAQC,aAAaH,SAAUV,OAAOc,KAAK,KAAKlB,QAAQ,CAAA;AAC3E,UAAMmB,OAAO,MAA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B,aAAa;IACrChC,MAAMrE,cAAAA,MAAM0G,SAASC,YAAW;IAChC5B,MAAM/E,cAAAA,MAAM6F,SAASC,QAAQ;MAAEC,aAAa;IAAI,CAAA,IAAK/F,cAAAA,MAAMgG,SAASC,IAAG,IAAKC;IAC5ElB,QAAQhF,cAAAA,MAAMC,QAAQC,aAAaqD,MAAAA;IACnC0B,UAAUjF,cAAAA,MAAMC,QAAQC,aAAasD,QAAAA;IACrC0B,QAAQlF,cAAAA,MAAM6F,SAASC,QAAO;EAChC;AACF;AAEA,IAAMc,qBAAuD;EAC3D,CAAA,2BAAA,GAA2B,OAAOlE,QAAQC,WAAAA;AACxC,UAAMkE,eAAWC,+BAAkBpE,QAAQ;MAAC;KAAU;AACtD,aAASqE,IAAI,GAAGA,IAAIpE,OAAOhC,OAAOoG,KAAK;AACrC,YAAMhE,SAASL,OAAOyB,SAASA,SAASpB,UAAU;AAClD8D,eAASG,OAAOC,OAAO,CAACC,QAAAA;AACtBC,yBAAAA,KAAEC,OACAF,KACAL,SAASQ,KAAKC,MAAK,GACnB,GACA3E,OAAO4E,oBAAoBxE,SAAS,IAAIJ,OAAO6E,cAC/C1E,WAAWH,OAAO6E,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,oBAAoB2E,YAAAA,GAAe0B,oBAAAA;AAE/E,IAAMuC,6BAA6B,CAACC,UACzC,IAAI3G,qBAAqB2G,OAAOlE,YAAAA,GAAe0B,sBAAsBwB,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", "getObjectAnnotation", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "isReactiveObject", "create", "createObjects", "map", "tasks", "entries", "count", "range", "flatMap", "t", "Promise", "all", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "_mutations", "db", "query", "Filter", "run", "objects", "forEach", "dynamicSchema", "_maybeRegisterSchema", "addSchemas", "result", "push", "add", "MutableSchema", "existingSchema", "schemaRegistry", "storedSchema", "registerSchema", "graph", "addSchema", "mutateObject", "object", "params", "invariant", "mutateObjects", "randomText", "length", "characters", "charactersLength", "index", "charAt", "Math", "floor", "random", "Status", "Priority", "TestSchemaType", "testSchemas", "document", "createMutableSchema", "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", "commerce", "productName", "testObjectMutators", "accessor", "createDocAccessor", "i", "handle", "change", "doc", "A", "splice", "path", "slice", "maxContentLength", "mutationSize", "Error", "createTestObjectGenerator", "createSpaceObjectGenerator", "space"]
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 { getObjectAnnotation, EchoSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | S.Schema<any>)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | S.Schema<any> | undefined {\n return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | S.Schema<any>) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | S.Schema<any>)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema<any>);\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<any>,\n ): Promise<EchoSchema | S.Schema<any>> {\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 = getObjectAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations![type](object, params);\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,sBAAwD;AACxD,uBAA0B;AAC1B,IAAAC,sBAAyE;AACzE,IAAAC,iBAAsB;AACtB,kBAAsB;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC,U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B,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", "getObjectAnnotation", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "isReactiveObject", "create", "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
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":16518,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":18563,"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":1729,"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":18203},"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/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":4583},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3807},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9099}}}
1
+ {"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":15721,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":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":1721,"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":17849},"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/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":3729},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9024}}}
@@ -3,13 +3,13 @@ import { createRequire } from 'node:module';const require = createRequire(import
3
3
  // packages/core/echo/echo-generator/src/data.ts
4
4
  import { next as A } from "@dxos/automerge/automerge";
5
5
  import { createDocAccessor } from "@dxos/client/echo";
6
- import { ref, S } from "@dxos/echo-schema";
7
- import { createMutableSchema } from "@dxos/live-object";
6
+ import { Ref, S } from "@dxos/echo-schema";
7
+ import { createEchoSchema, makeRef } from "@dxos/live-object";
8
8
  import { faker as faker2 } from "@dxos/random";
9
9
 
10
10
  // packages/core/echo/echo-generator/src/generator.ts
11
11
  import { Filter } from "@dxos/client/echo";
12
- import { getObjectAnnotation, MutableSchema } from "@dxos/echo-schema";
12
+ import { getObjectAnnotation, EchoSchema } from "@dxos/echo-schema";
13
13
  import { invariant } from "@dxos/invariant";
14
14
  import { create, getSchema, isReactiveObject } from "@dxos/live-object";
15
15
  import { faker } from "@dxos/random";
@@ -60,15 +60,13 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
60
60
  });
61
61
  this._space = _space;
62
62
  this._mutations = _mutations;
63
- Object.entries(schemaMap).forEach(([type, dynamicSchema]) => {
64
- const schema = this._maybeRegisterSchema(type, dynamicSchema);
65
- this.setSchema(type, schema);
66
- });
67
63
  }
68
- addSchemas() {
64
+ async addSchemas() {
69
65
  const result = [];
70
66
  for (const [typename, schema] of Object.entries(this._schemas)) {
71
- result.push(this._maybeRegisterSchema(typename, schema));
67
+ const echoSchema = await this._maybeRegisterSchema(typename, schema);
68
+ this.setSchema(typename, echoSchema);
69
+ result.push(echoSchema);
72
70
  }
73
71
  return result;
74
72
  }
@@ -77,14 +75,16 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
77
75
  types
78
76
  }));
79
77
  }
80
- _maybeRegisterSchema(typename, schema) {
81
- if (schema instanceof MutableSchema) {
78
+ async _maybeRegisterSchema(typename, schema) {
79
+ if (schema instanceof EchoSchema) {
82
80
  const existingSchema = this._space.db.schemaRegistry.getSchema(typename);
83
81
  if (existingSchema != null) {
84
82
  return existingSchema;
85
83
  }
86
- this._space.db.add(schema.storedSchema);
87
- return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);
84
+ const [registeredSchema] = await this._space.db.schemaRegistry.register([
85
+ schema
86
+ ]);
87
+ return registeredSchema;
88
88
  } else {
89
89
  const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);
90
90
  if (existingSchema != null) {
@@ -99,7 +99,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
99
99
  async mutateObject(object, params) {
100
100
  invariant(this._mutations, "Mutations not defined.", {
101
101
  F: __dxlog_file,
102
- L: 123,
102
+ L: 121,
103
103
  S: this,
104
104
  A: [
105
105
  "this._mutations",
@@ -109,7 +109,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
109
109
  const type = getObjectAnnotation(getSchema(object)).typename;
110
110
  invariant(type && this._mutations?.[type], "Invalid object type.", {
111
111
  F: __dxlog_file,
112
- L: 125,
112
+ L: 123,
113
113
  S: this,
114
114
  A: [
115
115
  "type && this._mutations?.[type]",
@@ -157,7 +157,7 @@ var TestSchemaType;
157
157
  TestSchemaType2["project"] = "example.com/type/project";
158
158
  })(TestSchemaType || (TestSchemaType = {}));
159
159
  var testSchemas = () => {
160
- const document = createMutableSchema({
160
+ const document = createEchoSchema({
161
161
  typename: "example.com/type/document",
162
162
  version: "0.1.0"
163
163
  }, {
@@ -166,7 +166,7 @@ var testSchemas = () => {
166
166
  }),
167
167
  content: S.String
168
168
  });
169
- const organization = createMutableSchema({
169
+ const organization = createEchoSchema({
170
170
  typename: "example.com/type/organization",
171
171
  version: "0.1.0"
172
172
  }, {
@@ -180,7 +180,7 @@ var testSchemas = () => {
180
180
  description: "short summary of the company"
181
181
  })
182
182
  });
183
- const contact = createMutableSchema({
183
+ const contact = createEchoSchema({
184
184
  typename: "example.com/type/contact",
185
185
  version: "0.1.0"
186
186
  }, {
@@ -188,11 +188,11 @@ var testSchemas = () => {
188
188
  description: "name of the person"
189
189
  }),
190
190
  email: S.String,
191
- org: ref(organization),
191
+ org: Ref(organization),
192
192
  lat: S.Number,
193
193
  lng: S.Number
194
194
  });
195
- const project = createMutableSchema({
195
+ const project = createEchoSchema({
196
196
  typename: "example.com/type/project",
197
197
  version: "0.1.0"
198
198
  }, {
@@ -205,7 +205,7 @@ var testSchemas = () => {
205
205
  status: S.String,
206
206
  priority: S.Number,
207
207
  active: S.Boolean,
208
- org: ref(organization)
208
+ org: Ref(organization)
209
209
  });
210
210
  return {
211
211
  ["example.com/type/document"]: document,
@@ -242,7 +242,7 @@ var testObjectGenerators = {
242
242
  }) ? faker2.internet.email() : void 0,
243
243
  org: organizations?.length && faker2.datatype.boolean({
244
244
  probability: 0.3
245
- }) ? faker2.helpers.arrayElement(organizations) : void 0,
245
+ }) ? makeRef(faker2.helpers.arrayElement(organizations)) : void 0,
246
246
  ...location
247
247
  };
248
248
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { next as A } from '@dxos/automerge/automerge';\nimport { createDocAccessor, type Space } from '@dxos/client/echo';\nimport { ref, S } from '@dxos/echo-schema';\nimport { createMutableSchema } 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 = createMutableSchema(\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 = createMutableSchema(\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 = createMutableSchema(\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 = createMutableSchema(\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 ? 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 { getObjectAnnotation, MutableSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (MutableSchema | S.Schema<any>)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): MutableSchema | S.Schema<any> | undefined {\n return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: MutableSchema | S.Schema<any>) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n\n // TODO(burdon): Map initially are objects that have not been added to the space.\n // Merge existing schema in space with defaults.\n Object.entries<MutableSchema | S.Schema<any>>(schemaMap).forEach(([type, dynamicSchema]) => {\n const schema = this._maybeRegisterSchema(type, dynamicSchema);\n this.setSchema(type as T, schema);\n });\n }\n\n addSchemas() {\n const result: (MutableSchema | S.Schema<any>)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n result.push(this._maybeRegisterSchema(typename, schema as MutableSchema | S.Schema<any>));\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 _maybeRegisterSchema(typename: string, schema: MutableSchema | S.Schema<any>): MutableSchema | S.Schema<any> {\n if (schema instanceof MutableSchema) {\n const existingSchema = this._space.db.schemaRegistry.getSchema(typename);\n if (existingSchema != null) {\n return existingSchema;\n }\n this._space.db.add(schema.storedSchema);\n return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);\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 = getObjectAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations![type](object, params);\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,2BAA2B;AACpC,SAASC,SAAAA,cAAa;;;ACJtB,SAASC,cAA0B;AAEnC,SAASC,qBAAqBC,qBAA6B;AAC3D,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,WAAWC,wBAA6C;AACzE,SAASC,aAAa;AACtB,SAASC,aAAa;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC,UAA6C;AAC/C,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAN,UAAUY,MAAoD;AAC5D,WAAO,KAAKH,QAAQI,KAAK,CAACC,WAAWlB,oBAAoBkB,MAAAA,EAASC,aAAaH,IAAAA;EACjF;EAEUI,UAAUJ,MAASE,QAAuC;AAClE,SAAKR,SAASM,IAAAA,IAAQE;EACxB;EAEA,MAAMG,aAAa,EAAEC,MAAK,IAAsB,CAAC,GAAiC;AAChF,UAAMN,OAAOV,MAAMiB,QAAQC,aAAaF,SAAUR,OAAOW,K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,SAASC,IAAG,IAAKC;IAC5EnB,QAAQK,OAAMuB,QAAQC,aAAavD,MAAAA;IACnC2B,UAAUI,OAAMuB,QAAQC,aAAatD,QAAAA;IACrC2B,QAAQG,OAAMS,SAASC,QAAO;EAChC;AACF;AAEA,IAAMiB,qBAAuD;EAC3D,CAAA,2BAAA,GAA2B,OAAOC,QAAQC,WAAAA;AACxC,UAAMC,WAAWC,kBAAkBH,QAAQ;MAAC;KAAU;AACtD,aAASI,IAAI,GAAGA,IAAIH,OAAOI,OAAOD,KAAK;AACrC,YAAMV,SAASM,OAAO9C,SAASA,SAASwC,UAAU;AAClDQ,eAASI,OAAOC,OAAO,CAACC,QAAAA;AACtBC,UAAEC,OACAF,KACAN,SAASS,KAAKC,MAAK,GACnB,GACAX,OAAOY,oBAAoBnB,SAAS,IAAIO,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,oBAAoB1E,YAAAA,GAAe2B,oBAAAA;AAE/E,IAAMgD,6BAA6B,CAACC,UACzC,IAAIC,qBAAqBD,OAAO5E,YAAAA,GAAe2B,sBAAsB4B,kBAAAA;",
6
- "names": ["next", "A", "createDocAccessor", "ref", "S", "createMutableSchema", "faker", "Filter", "getObjectAnnotation", "MutableSchema", "invariant", "create", "getSchema", "isReactiveObject", "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", "forEach", "dynamicSchema", "_maybeRegisterSchema", "addSchemas", "result", "push", "add", "existingSchema", "schemaRegistry", "storedSchema", "registerSchema", "graph", "addSchema", "mutateObject", "object", "params", "mutateObjects", "randomText", "length", "result", "characters", "charactersLength", "index", "charAt", "Math", "floor", "random", "Status", "Priority", "TestSchemaType", "testSchemas", "document", "createMutableSchema", "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", "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"]
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 { getObjectAnnotation, EchoSchema, type S } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';\nimport { faker } from '@dxos/random';\nimport { range } from '@dxos/util';\n\nimport { type TestSchemaType } from './data';\nimport {\n type MutationsProviderParams,\n type TestGeneratorMap,\n type TestMutationsMap,\n type TestObjectProvider,\n type TestSchemaMap,\n} from './types';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string = TestSchemaType> {\n // prettier-ignore\n constructor(\n protected readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>,\n ) {}\n\n get schemas(): (EchoSchema | S.Schema<any>)[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T): EchoSchema | S.Schema<any> | undefined {\n return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);\n }\n\n protected setSchema(type: T, schema: EchoSchema | S.Schema<any>) {\n this._schemas[type] = schema;\n }\n\n async createObject({ types }: { types?: T[] } = {}): Promise<ReactiveObject<any>> {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = await this._generators[type](this._provider);\n if (isReactiveObject(data)) {\n return data;\n }\n\n const schema = this.getSchema(type);\n return schema ? create(schema, data) : create(data);\n }\n\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n async createObjects(map: Partial<Record<T, number>>) {\n const tasks = Object.entries<number>(map as any)\n .map(([type, count]) => {\n return range(count, () => this.createObject({ types: [type as T] }));\n })\n .flatMap((t) => t);\n\n return Promise.all(tasks);\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(\n private readonly _space: Space,\n schemaMap: TestSchemaMap<T>,\n generators: TestGeneratorMap<T>,\n private readonly _mutations?: TestMutationsMap<T>,\n ) {\n super(schemaMap, generators, async (type: T) => {\n const schema = this.getSchema(type);\n return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];\n });\n }\n\n async addSchemas() {\n const result: (EchoSchema | S.Schema<any>)[] = [];\n for (const [typename, schema] of Object.entries(this._schemas)) {\n const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema<any>);\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<any>,\n ): Promise<EchoSchema | S.Schema<any>> {\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 = getObjectAnnotation(getSchema(object)!)!.typename as T;\n invariant(type && this._mutations?.[type], 'Invalid object type.');\n\n await this._mutations![type](object, params);\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,qBAAqBC,kBAA0B;AACxD,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,WAAWC,wBAA6C;AACzE,SAASC,aAAa;AACtB,SAASC,aAAa;;AAcf,IAAMC,sBAAN,MAAMA;;EAEXC,YACqBC,UACFC,aACAC,WACjB;SAHmBF,WAAAA;SACFC,cAAAA;SACAC,YAAAA;EAChB;EAEH,IAAIC,UAA0C;AAC5C,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAN,UAA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MACN,GAAGG;IACL;EACF;EAEA,CAAA,0BAAA,GAA0B,aAAa;IACrCjC,MAAMgB,OAAM0B,SAASC,YAAW;IAChCjC,MAAMM,OAAMS,SAASC,QAAQ;MAAEC,aAAa;IAAI,CAAA,IAAKX,OAAMY,SAASC,IAAG,IAAKC;IAC5EnB,QAAQK,OAAMwB,QAAQC,aAAaxD,MAAAA;IACnC2B,UAAUI,OAAMwB,QAAQC,aAAavD,QAAAA;IACrC2B,QAAQG,OAAMS,SAASC,QAAO;EAChC;AACF;AAEA,IAAMkB,qBAAuD;EAC3D,CAAA,2BAAA,GAA2B,OAAOC,QAAQC,WAAAA;AACxC,UAAMC,WAAWC,kBAAkBH,QAAQ;MAAC;KAAU;AACtD,aAASI,IAAI,GAAGA,IAAIH,OAAOI,OAAOD,KAAK;AACrC,YAAMX,SAASO,OAAO/C,SAASA,SAASwC,UAAU;AAClDS,eAASI,OAAOC,OAAO,CAACC,QAAAA;AACtBC,UAAEC,OACAF,KACAN,SAASS,KAAKC,MAAK,GACnB,GACAX,OAAOY,oBAAoBpB,SAAS,IAAIQ,OAAOa,cAC/CC,WAAWd,OAAOa,YAAY,CAAA;MAElC,CAAA;IACF;EACF;EACA,CAAA,+BAAA,GAA+B,YAAA;AAC7B,UAAM,IAAIE,MAAM,yBAAA;EAClB;EACA,CAAA,0BAAA,GAA0B,YAAA;AACxB,UAAM,IAAIA,MAAM,yBAAA;EAClB;EACA,CAAA,0BAAA,GAA0B,YAAA;AACxB,UAAM,IAAIA,MAAM,yBAAA;EAClB;AACF;AAEO,IAAMC,4BAA4B,MAAM,IAAIC,oBAAoB3E,YAAAA,GAAe2B,oBAAAA;AAE/E,IAAMiD,6BAA6B,CAACC,UACzC,IAAIC,qBAAqBD,OAAO7E,YAAAA,GAAe2B,sBAAsB6B,kBAAAA;",
6
+ "names": ["next", "A", "createDocAccessor", "Ref", "S", "createEchoSchema", "makeRef", "faker", "Filter", "getObjectAnnotation", "EchoSchema", "invariant", "create", "getSchema", "isReactiveObject", "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":16518,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":18563,"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":1729,"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":18205},"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/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":4583},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3807},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9192}}}
1
+ {"inputs":{"packages/core/echo/echo-generator/src/generator.ts":{"bytes":15721,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/random","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo-generator/src/util.ts":{"bytes":1624,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":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":1721,"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":17851},"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/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":3729},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":299},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9117}}}
@@ -1,6 +1,6 @@
1
1
  import { type Space } from '@dxos/client/echo';
2
2
  import { type ReactiveEchoObject } from '@dxos/echo-db';
3
- import { MutableSchema, type S } from '@dxos/echo-schema';
3
+ import { EchoSchema, type S } from '@dxos/echo-schema';
4
4
  import { type ReactiveObject } from '@dxos/live-object';
5
5
  import { type TestSchemaType } from './data';
6
6
  import { type MutationsProviderParams, type TestGeneratorMap, type TestMutationsMap, type TestObjectProvider, type TestSchemaMap } from './types';
@@ -12,9 +12,9 @@ export declare class TestObjectGenerator<T extends string = TestSchemaType> {
12
12
  private readonly _generators;
13
13
  private readonly _provider?;
14
14
  constructor(_schemas: TestSchemaMap<T>, _generators: TestGeneratorMap<T>, _provider?: TestObjectProvider<T> | undefined);
15
- get schemas(): (MutableSchema | S.Schema<any>)[];
16
- getSchema(type: T): MutableSchema | S.Schema<any> | undefined;
17
- protected setSchema(type: T, schema: MutableSchema | S.Schema<any>): void;
15
+ get schemas(): (EchoSchema | S.Schema<any>)[];
16
+ getSchema(type: T): EchoSchema | S.Schema<any> | undefined;
17
+ protected setSchema(type: T, schema: EchoSchema | S.Schema<any>): void;
18
18
  createObject({ types }?: {
19
19
  types?: T[];
20
20
  }): Promise<ReactiveObject<any>>;
@@ -27,7 +27,7 @@ export declare class SpaceObjectGenerator<T extends string> extends TestObjectGe
27
27
  private readonly _space;
28
28
  private readonly _mutations?;
29
29
  constructor(_space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>, _mutations?: TestMutationsMap<T> | undefined);
30
- addSchemas(): (MutableSchema | S.Schema<any, any, never>)[];
30
+ addSchemas(): Promise<(EchoSchema | S.Schema<any, any, never>)[]>;
31
31
  createObject({ types }?: {
32
32
  types?: T[];
33
33
  }): Promise<ReactiveEchoObject<any>>;
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAuB,aAAa,EAAE,KAAK,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAI7F,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,OAA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-schema';
2
+ import { type EchoSchema, type S } from '@dxos/echo-schema';
3
3
  import { type ReactiveObject } from '@dxos/live-object';
4
4
  export type TestObject = {
5
5
  id: string;
6
6
  } & Record<string, any>;
7
- export type TestSchemaMap<T extends string = string> = Record<T, MutableSchema | S.Schema<any>>;
7
+ export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema | S.Schema<any>>;
8
8
  export type TestObjectProvider<T extends string = string> = (type: T) => Promise<ReactiveObject<any>[]>;
9
9
  export type TestGeneratorMap<T extends string = string> = Record<T, (provider: TestObjectProvider<T> | undefined) => any>;
10
10
  export type TestMutationsMap<T extends string = string> = Record<T, TestObjectMutators>;
@@ -1 +1 @@
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,aAAa,EAAE,KAAK,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,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,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAEhG,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAExG,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,CAC9D,CAAC,EACD,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,C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AAC,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"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-generator",
3
- "version": "0.7.4",
3
+ "version": "0.7.5-main.9cb18ac",
4
4
  "description": "ECHO data generator for testing.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -23,21 +23,21 @@
23
23
  "src"
24
24
  ],
25
25
  "dependencies": {
26
- "@dxos/automerge": "0.7.4",
27
- "@dxos/client": "0.7.4",
28
- "@dxos/echo-db": "0.7.4",
29
- "@dxos/echo-schema": "0.7.4",
30
- "@dxos/invariant": "0.7.4",
31
- "@dxos/schema": "0.7.4",
32
- "@dxos/live-object": "0.7.4",
33
- "@dxos/util": "0.7.4",
34
- "@dxos/node-std": "0.7.4"
26
+ "@dxos/automerge": "0.7.5-main.9cb18ac",
27
+ "@dxos/client": "0.7.5-main.9cb18ac",
28
+ "@dxos/echo-schema": "0.7.5-main.9cb18ac",
29
+ "@dxos/echo-db": "0.7.5-main.9cb18ac",
30
+ "@dxos/invariant": "0.7.5-main.9cb18ac",
31
+ "@dxos/node-std": "0.7.5-main.9cb18ac",
32
+ "@dxos/live-object": "0.7.5-main.9cb18ac",
33
+ "@dxos/util": "0.7.5-main.9cb18ac",
34
+ "@dxos/schema": "0.7.5-main.9cb18ac"
35
35
  },
36
36
  "devDependencies": {
37
- "@dxos/random": "0.7.4"
37
+ "@dxos/random": "0.7.5-main.9cb18ac"
38
38
  },
39
39
  "peerDependencies": {
40
- "@dxos/random": "0.7.4"
40
+ "@dxos/random": "0.7.5-main.9cb18ac"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
package/src/data.ts CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { next as A } from '@dxos/automerge/automerge';
6
6
  import { createDocAccessor, type Space } from '@dxos/client/echo';
7
- import { ref, S } from '@dxos/echo-schema';
8
- import { createMutableSchema } from '@dxos/live-object';
7
+ import { Ref, S } from '@dxos/echo-schema';
8
+ import { createEchoSchema, makeRef } from '@dxos/live-object';
9
9
  import { faker } from '@dxos/random';
10
10
 
11
11
  import { SpaceObjectGenerator, TestObjectGenerator } from './generator';
@@ -27,7 +27,7 @@ export enum TestSchemaType {
27
27
  }
28
28
 
29
29
  const testSchemas = (): TestSchemaMap<TestSchemaType> => {
30
- const document = createMutableSchema(
30
+ const document = createEchoSchema(
31
31
  {
32
32
  typename: TestSchemaType.document,
33
33
  version: '0.1.0',
@@ -38,7 +38,7 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
38
38
  },
39
39
  );
40
40
 
41
- const organization = createMutableSchema(
41
+ const organization = createEchoSchema(
42
42
  {
43
43
  typename: TestSchemaType.organization,
44
44
  version: '0.1.0',
@@ -50,7 +50,7 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
50
50
  },
51
51
  );
52
52
 
53
- const contact = createMutableSchema(
53
+ const contact = createEchoSchema(
54
54
  {
55
55
  typename: TestSchemaType.contact,
56
56
  version: '0.1.0',
@@ -58,13 +58,13 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
58
58
  {
59
59
  name: S.String.annotations({ description: 'name of the person' }),
60
60
  email: S.String,
61
- org: ref(organization),
61
+ org: Ref(organization),
62
62
  lat: S.Number,
63
63
  lng: S.Number,
64
64
  },
65
65
  );
66
66
 
67
- const project = createMutableSchema(
67
+ const project = createEchoSchema(
68
68
  {
69
69
  typename: TestSchemaType.project,
70
70
  version: '0.1.0',
@@ -77,7 +77,7 @@ const testSchemas = (): TestSchemaMap<TestSchemaType> => {
77
77
  status: S.String,
78
78
  priority: S.Number,
79
79
  active: S.Boolean,
80
- org: ref(organization),
80
+ org: Ref(organization),
81
81
  },
82
82
  );
83
83
 
@@ -109,7 +109,7 @@ const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
109
109
  email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,
110
110
  org:
111
111
  organizations?.length && faker.datatype.boolean({ probability: 0.3 })
112
- ? faker.helpers.arrayElement(organizations)
112
+ ? makeRef(faker.helpers.arrayElement(organizations))
113
113
  : undefined,
114
114
  ...location,
115
115
  };
@@ -39,7 +39,7 @@ describe('TestObjectGenerator', () => {
39
39
  const { space } = await setupTest();
40
40
 
41
41
  const generator = createSpaceObjectGenerator(space);
42
- generator.addSchemas();
42
+ await generator.addSchemas();
43
43
 
44
44
  // Create org object.
45
45
  const organization = await generator.createObject({ types: [TestSchemaType.organization] });
@@ -47,7 +47,7 @@ describe('TestObjectGenerator', () => {
47
47
 
48
48
  // Expect at least one person object with a linked org reference.
49
49
  const objects = await generator.createObjects({ [TestSchemaType.contact]: 10 });
50
- expect(objects.some((object) => object.org === organization)).to.be.true;
50
+ expect(objects.some((object) => object.org?.target === organization)).to.be.true;
51
51
  });
52
52
 
53
53
  test('idempotence', async () => {
@@ -57,14 +57,14 @@ describe('TestObjectGenerator', () => {
57
57
 
58
58
  {
59
59
  const generator = createSpaceObjectGenerator(space);
60
- generator.addSchemas();
60
+ await generator.addSchemas();
61
61
  const organization = await generator.createObject({ types: [TestSchemaType.organization] });
62
62
  schemaId.push(getType(organization)!.objectId);
63
63
  }
64
64
 
65
65
  {
66
66
  const generator = createSpaceObjectGenerator(space);
67
- generator.addSchemas();
67
+ await generator.addSchemas();
68
68
  const organization = await generator.createObject({ types: [TestSchemaType.organization] });
69
69
  schemaId.push(getType(organization)!.objectId);
70
70
  }
@@ -76,7 +76,7 @@ describe('TestObjectGenerator', () => {
76
76
  test('mutations', async () => {
77
77
  const { space } = await setupTest();
78
78
  const generator = createSpaceObjectGenerator(space);
79
- generator.addSchemas();
79
+ await generator.addSchemas();
80
80
  const document = await generator.createObject({ types: [TestSchemaType.document] });
81
81
  expect(getType(document)).to.exist;
82
82
 
@@ -118,6 +118,7 @@ describe('TestObjectGenerator', () => {
118
118
  },
119
119
  },
120
120
  );
121
+ await generator.addSchemas();
121
122
 
122
123
  const todo = await generator.createObject({ types: [Types.task] });
123
124
  expect(getType(todo)).to.exist;
package/src/generator.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { Filter, type Space } from '@dxos/client/echo';
6
6
  import { type ReactiveEchoObject } from '@dxos/echo-db';
7
- import { getObjectAnnotation, MutableSchema, type S } from '@dxos/echo-schema';
7
+ import { getObjectAnnotation, EchoSchema, type S } from '@dxos/echo-schema';
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { create, getSchema, isReactiveObject, type ReactiveObject } from '@dxos/live-object';
10
10
  import { faker } from '@dxos/random';
@@ -30,15 +30,15 @@ export class TestObjectGenerator<T extends string = TestSchemaType> {
30
30
  private readonly _provider?: TestObjectProvider<T>,
31
31
  ) {}
32
32
 
33
- get schemas(): (MutableSchema | S.Schema<any>)[] {
33
+ get schemas(): (EchoSchema | S.Schema<any>)[] {
34
34
  return Object.values(this._schemas);
35
35
  }
36
36
 
37
- getSchema(type: T): MutableSchema | S.Schema<any> | undefined {
37
+ getSchema(type: T): EchoSchema | S.Schema<any> | undefined {
38
38
  return this.schemas.find((schema) => getObjectAnnotation(schema)!.typename === type);
39
39
  }
40
40
 
41
- protected setSchema(type: T, schema: MutableSchema | S.Schema<any>) {
41
+ protected setSchema(type: T, schema: EchoSchema | S.Schema<any>) {
42
42
  this._schemas[type] = schema;
43
43
  }
44
44
 
@@ -79,19 +79,14 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
79
79
  const schema = this.getSchema(type);
80
80
  return (schema && (await this._space.db.query(Filter.schema(schema)).run()).objects) ?? [];
81
81
  });
82
-
83
- // TODO(burdon): Map initially are objects that have not been added to the space.
84
- // Merge existing schema in space with defaults.
85
- Object.entries<MutableSchema | S.Schema<any>>(schemaMap).forEach(([type, dynamicSchema]) => {
86
- const schema = this._maybeRegisterSchema(type, dynamicSchema);
87
- this.setSchema(type as T, schema);
88
- });
89
82
  }
90
83
 
91
- addSchemas() {
92
- const result: (MutableSchema | S.Schema<any>)[] = [];
84
+ async addSchemas() {
85
+ const result: (EchoSchema | S.Schema<any>)[] = [];
93
86
  for (const [typename, schema] of Object.entries(this._schemas)) {
94
- result.push(this._maybeRegisterSchema(typename, schema as MutableSchema | S.Schema<any>));
87
+ const echoSchema = await this._maybeRegisterSchema(typename, schema as EchoSchema | S.Schema<any>);
88
+ this.setSchema(typename as T, echoSchema);
89
+ result.push(echoSchema);
95
90
  }
96
91
 
97
92
  return result;
@@ -101,14 +96,17 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
101
96
  return this._space.db.add(await super.createObject({ types }));
102
97
  }
103
98
 
104
- private _maybeRegisterSchema(typename: string, schema: MutableSchema | S.Schema<any>): MutableSchema | S.Schema<any> {
105
- if (schema instanceof MutableSchema) {
99
+ private async _maybeRegisterSchema(
100
+ typename: string,
101
+ schema: EchoSchema | S.Schema<any>,
102
+ ): Promise<EchoSchema | S.Schema<any>> {
103
+ if (schema instanceof EchoSchema) {
106
104
  const existingSchema = this._space.db.schemaRegistry.getSchema(typename);
107
105
  if (existingSchema != null) {
108
106
  return existingSchema;
109
107
  }
110
- this._space.db.add(schema.storedSchema);
111
- return this._space.db.schemaRegistry.registerSchema(schema.storedSchema);
108
+ const [registeredSchema] = await this._space.db.schemaRegistry.register([schema]);
109
+ return registeredSchema;
112
110
  } else {
113
111
  const existingSchema = this._space.db.graph.schemaRegistry.getSchema(typename);
114
112
  if (existingSchema != null) {
package/src/types.ts CHANGED
@@ -3,13 +3,13 @@
3
3
  //
4
4
 
5
5
  import { type ReactiveEchoObject } from '@dxos/echo-db';
6
- import { type MutableSchema, type S } from '@dxos/echo-schema';
6
+ import { type EchoSchema, type S } from '@dxos/echo-schema';
7
7
  import { type ReactiveObject } from '@dxos/live-object';
8
8
 
9
9
  // TODO(burdon): Use echo-schema types.
10
10
  export type TestObject = { id: string } & Record<string, any>;
11
11
 
12
- export type TestSchemaMap<T extends string = string> = Record<T, MutableSchema | S.Schema<any>>;
12
+ export type TestSchemaMap<T extends string = string> = Record<T, EchoSchema | S.Schema<any>>;
13
13
 
14
14
  export type TestObjectProvider<T extends string = string> = (type: T) => Promise<ReactiveObject<any>[]>;
15
15