@dxos/echo-generator 0.3.7-main.0ee8374 → 0.3.7-main.3ea49a6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +31 -24
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +31 -24
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/generator.d.ts +5 -4
- package/dist/types/src/generator.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/generator.test.ts +33 -2
- package/src/generator.ts +31 -32
|
@@ -16,22 +16,27 @@ var range = (fn, length) => Array.from({
|
|
|
16
16
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
17
17
|
var TestObjectGenerator = class {
|
|
18
18
|
// prettier-ignore
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
19
|
+
constructor(_schemas, _generators, _provider) {
|
|
20
|
+
this._schemas = _schemas;
|
|
21
21
|
this._generators = _generators;
|
|
22
22
|
this._provider = _provider;
|
|
23
23
|
}
|
|
24
24
|
get schemas() {
|
|
25
|
-
return Object.values(this.
|
|
25
|
+
return Object.values(this._schemas);
|
|
26
26
|
}
|
|
27
|
-
getSchema(
|
|
28
|
-
return this.schemas.find((schema) => schema.typename ===
|
|
27
|
+
getSchema(type) {
|
|
28
|
+
return this.schemas.find((schema) => schema.typename === type);
|
|
29
29
|
}
|
|
30
|
+
setSchema(type, schema) {
|
|
31
|
+
this._schemas[type] = schema;
|
|
32
|
+
}
|
|
33
|
+
// TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
|
|
30
34
|
createObject({ types } = {}) {
|
|
31
|
-
const type = faker.helpers.arrayElement(types ?? Object.keys(this.
|
|
35
|
+
const type = faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
32
36
|
const data = this._generators[type](this._provider);
|
|
37
|
+
const schema = this.getSchema(type);
|
|
33
38
|
return new Expando(data, {
|
|
34
|
-
schema
|
|
39
|
+
schema
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
42
|
// TODO(burdon): Create batch.
|
|
@@ -49,17 +54,29 @@ var TestObjectGenerator = class {
|
|
|
49
54
|
}
|
|
50
55
|
};
|
|
51
56
|
var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
52
|
-
constructor(
|
|
53
|
-
super(
|
|
54
|
-
const { objects } = this._space.db.query((object) => {
|
|
55
|
-
return object.__schema ===
|
|
57
|
+
constructor(_space, schemaMap, generators) {
|
|
58
|
+
super(schemaMap, generators, (type) => {
|
|
59
|
+
const { objects: objects2 } = this._space.db.query((object) => {
|
|
60
|
+
return object.__schema?.id === this.getSchema(type)?.id;
|
|
56
61
|
});
|
|
57
|
-
return
|
|
62
|
+
return objects2;
|
|
63
|
+
});
|
|
64
|
+
this._space = _space;
|
|
65
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
66
|
+
Object.keys(schemaMap).forEach((type) => {
|
|
67
|
+
const schema = objects.find((object) => object.typename === type);
|
|
68
|
+
if (schema) {
|
|
69
|
+
this.setSchema(type, schema);
|
|
70
|
+
}
|
|
58
71
|
});
|
|
59
|
-
this._space = space;
|
|
60
72
|
}
|
|
61
73
|
addSchemas() {
|
|
62
|
-
|
|
74
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
75
|
+
this.schemas.forEach((schema) => {
|
|
76
|
+
if (!objects.find((object) => object.typename === schema.typename)) {
|
|
77
|
+
this._space.db.add(schema);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
63
80
|
return this.schemas;
|
|
64
81
|
}
|
|
65
82
|
createObject({ types } = {}) {
|
|
@@ -68,16 +85,6 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
68
85
|
}));
|
|
69
86
|
}
|
|
70
87
|
};
|
|
71
|
-
var mergeSchemaMap = (space, schemaMap) => {
|
|
72
|
-
const { objects } = space.db.query(Schema.filter());
|
|
73
|
-
Object.keys(schemaMap).forEach((type) => {
|
|
74
|
-
const schema = objects.find((object) => object.typename === type);
|
|
75
|
-
if (schema) {
|
|
76
|
-
schemaMap[type] = schema;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return schemaMap;
|
|
80
|
-
};
|
|
81
88
|
|
|
82
89
|
// packages/core/echo/echo-generator/src/data.ts
|
|
83
90
|
var Status = [
|
|
@@ -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\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\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\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/schema/document',\n organization = 'example.com/schema/organization',\n contact = 'example.com/schema/contact',\n project = 'example.com/schema/project',\n}\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n typename: TestSchemaType.document,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: TestSchemaType.organization,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const contact = new Schema({\n typename: TestSchemaType.contact,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: TestSchemaType.project,\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: () => ({\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]: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n [TestSchemaType.contact]: (provider) => {\n const organizations = provider?.(TestSchemaType.organization);\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\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]: () => ({\n title: 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\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\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\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n public readonly schema: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this.schema);\n }\n\n getSchema(typename: string) {\n return this.schemas.find((schema) => schema.typename === typename);\n }\n\n createObject({ types }: { types?: T[] } = {}): TypedObject {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this.schema) as T[]));\n const data = this._generators[type](this._provider);\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n return new Expando(data, { schema: this.schema[type] });\n }\n\n // TODO(burdon): Create batch.\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n createObjects(map: Partial<Record<T, number>>): Expando[] {\n const objects: Expando[] = [];\n Object.entries<number>(map as any).forEach(([type, count]) => {\n range(() => objects.push(this.createObject({ types: [type as T] })), count);\n });\n\n return objects;\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n private readonly _space: Space;\n\n constructor(space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(mergeSchemaMap(space, schemaMap), generators, (type: T) => {\n const { objects } = this._space.db.query((object) => {\n return object.__schema === schemaMap[type];\n });\n\n return objects;\n });\n\n this._space = space;\n }\n\n addSchemas() {\n this.schemas.forEach((schema) => this._space.db.add(schema));\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n\n/**\n * Merge existing schema in space with defaults.\n */\nconst mergeSchemaMap = <T extends string>(space: Space, schemaMap: TestSchemaMap<T>) => {\n const { objects } = space.db.query(Schema.filter());\n Object.keys(schemaMap).forEach((type) => {\n const schema = objects.find((object) => object.typename === type);\n if (schema) {\n (schemaMap as any)[type] = schema;\n }\n });\n\n return schemaMap;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
-
"mappings": ";;;AAOA,SAASA,SAAAA,cAAa;AAEtB,SAASC,UAAAA,SAAoBC,kBAAkB;;;
|
|
6
|
-
"names": ["faker", "Schema", "TextObject", "faker", "Expando", "Schema", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\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\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\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/schema/document',\n organization = 'example.com/schema/organization',\n contact = 'example.com/schema/contact',\n project = 'example.com/schema/project',\n}\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n typename: TestSchemaType.document,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: TestSchemaType.organization,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const contact = new Schema({\n typename: TestSchemaType.contact,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: TestSchemaType.project,\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: () => ({\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]: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n [TestSchemaType.contact]: (provider) => {\n const organizations = provider?.(TestSchemaType.organization);\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\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]: () => ({\n title: 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\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n private readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T) {\n return this.schemas.find((schema) => schema.typename === type);\n }\n\n protected setSchema(type: T, schema: Schema) {\n this._schemas[type] = schema;\n }\n\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n createObject({ types }: { types?: T[] } = {}): TypedObject {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = this._generators[type](this._provider);\n const schema = this.getSchema(type);\n return new Expando(data, { schema });\n }\n\n // TODO(burdon): Create batch.\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n createObjects(map: Partial<Record<T, number>>): Expando[] {\n const objects: Expando[] = [];\n Object.entries<number>(map as any).forEach(([type, count]) => {\n range(() => objects.push(this.createObject({ types: [type as T] })), count);\n });\n\n return objects;\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(private readonly _space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(schemaMap, generators, (type: T) => {\n const { objects } = this._space.db.query((object) => {\n return object.__schema?.id === this.getSchema(type)?.id;\n });\n\n return 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 const { objects } = this._space.db.query(Schema.filter());\n Object.keys(schemaMap).forEach((type) => {\n const schema = objects.find((object) => object.typename === type);\n if (schema) {\n this.setSchema(type as T, schema);\n }\n });\n }\n\n addSchemas() {\n const { objects } = this._space.db.query(Schema.filter());\n this.schemas.forEach((schema) => {\n if (!objects.find((object) => object.typename === schema.typename)) {\n this._space.db.add(schema);\n }\n });\n\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
+
"mappings": ";;;AAOA,SAASA,SAAAA,cAAa;AAEtB,SAASC,UAAAA,SAAoBC,kBAAkB;;;ACL/C,SAASC,aAAa;AAEtB,SAASC,SAA2BC,cAA0B;;;ACDvD,IAAMC,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;;;ADML,IAAMC,sBAAN,MAAMA;;EAEXC,YACmBC,UACAC,aACAC,WACjB;oBAHiBF;uBACAC;qBACAC;EAChB;EAEH,IAAIC,UAAoB;AACtB,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;EAEAM,UAAUC,MAAS;AACjB,WAAO,KAAKJ,QAAQK,KAAK,CAACC,WAAWA,OAAOC,aAAaH,IAAAA;EAC3D;EAEUI,UAAUJ,MAASE,QAAgB;AAC3C,SAAKT,SAASO,IAAAA,IAAQE;EACxB;;EAGAG,aAAa,EAAEC,MAAK,IAAsB,CAAC,GAAgB;AACzD,UAAMN,OAAOO,MAAMC,QAAQC,aAAaH,SAAUT,OAAOa,KAAK,KAAKjB,QAAQ,CAAA;AAC3E,UAAMkB,OAAO,KAAKjB,YAAYM,IAAAA,EAAM,KAAKL,SAAS;AAClD,UAAMO,SAAS,KAAKH,UAAUC,IAAAA;AAC9B,WAAO,IAAIY,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KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAoB;EACpD;IAAED,KAAK;IAASC,KAAK;EAAiB;EACtC;IAAED,KAAK;IAAmBC,KAAK;EAAkB;EACjD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAoB;EACpD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAqBC,KAAK;EAAmB;EACpD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAmBC,KAAK;EAAmB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAoB;EACpD;IAAED,KAAK;IAAqBC,KAAK;EAAiB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAoB;EACpD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAqBC,KAAK;EAAkB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAmBC,KAAK;EAAmB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;;",
|
|
6
|
+
"names": ["faker", "Schema", "TextObject", "faker", "Expando", "Schema", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "getSchema", "type", "find", "schema", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "Expando", "createObjects", "map", "objects", "entries", "forEach", "count", "range", "push", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "db", "query", "object", "__schema", "id", "Schema", "filter", "addSchemas", "add", "Status", "Priority", "TestSchemaType", "document", "organization", "contact", "project", "testSchemas", "Schema", "typename", "props", "id", "type", "PropType", "STRING", "REF", "ref", "NUMBER", "BOOLEAN", "testObjectGenerators", "title", "faker", "lorem", "sentence", "content", "sentences", "min", "max", "number", "int", "name", "company", "website", "datatype", "boolean", "probability", "internet", "url", "undefined", "description", "TextObject", "provider", "organizations", "location", "helpers", "arrayElement", "locations", "person", "fullName", "email", "org", "length", "commerce", "productName", "repo", "status", "priority", "active", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator", "lat", "lng"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1057,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1057,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":10516,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":37173,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"}],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":634,"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/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":23093},"packages/core/echo/echo-generator/dist/lib/browser/index.mjs":{"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true}],"exports":["Priority","SpaceObjectGenerator","Status","TestObjectGenerator","TestSchemaType","createSpaceObjectGenerator","createTestObjectGenerator","range","testObjectGenerators","testSchemas"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":10590},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":2245},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":91},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":13459}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -49,22 +49,27 @@ var range = (fn, length) => Array.from({
|
|
|
49
49
|
// packages/core/echo/echo-generator/src/generator.ts
|
|
50
50
|
var TestObjectGenerator = class {
|
|
51
51
|
// prettier-ignore
|
|
52
|
-
constructor(
|
|
53
|
-
this.
|
|
52
|
+
constructor(_schemas, _generators, _provider) {
|
|
53
|
+
this._schemas = _schemas;
|
|
54
54
|
this._generators = _generators;
|
|
55
55
|
this._provider = _provider;
|
|
56
56
|
}
|
|
57
57
|
get schemas() {
|
|
58
|
-
return Object.values(this.
|
|
58
|
+
return Object.values(this._schemas);
|
|
59
59
|
}
|
|
60
|
-
getSchema(
|
|
61
|
-
return this.schemas.find((schema) => schema.typename ===
|
|
60
|
+
getSchema(type) {
|
|
61
|
+
return this.schemas.find((schema) => schema.typename === type);
|
|
62
62
|
}
|
|
63
|
+
setSchema(type, schema) {
|
|
64
|
+
this._schemas[type] = schema;
|
|
65
|
+
}
|
|
66
|
+
// TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
|
|
63
67
|
createObject({ types } = {}) {
|
|
64
|
-
const type = import_faker.faker.helpers.arrayElement(types ?? Object.keys(this.
|
|
68
|
+
const type = import_faker.faker.helpers.arrayElement(types ?? Object.keys(this._schemas));
|
|
65
69
|
const data = this._generators[type](this._provider);
|
|
70
|
+
const schema = this.getSchema(type);
|
|
66
71
|
return new import_echo.Expando(data, {
|
|
67
|
-
schema
|
|
72
|
+
schema
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
75
|
// TODO(burdon): Create batch.
|
|
@@ -82,17 +87,29 @@ var TestObjectGenerator = class {
|
|
|
82
87
|
}
|
|
83
88
|
};
|
|
84
89
|
var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
85
|
-
constructor(
|
|
86
|
-
super(
|
|
87
|
-
const { objects } = this._space.db.query((object) => {
|
|
88
|
-
return object.__schema ===
|
|
90
|
+
constructor(_space, schemaMap, generators) {
|
|
91
|
+
super(schemaMap, generators, (type) => {
|
|
92
|
+
const { objects: objects2 } = this._space.db.query((object) => {
|
|
93
|
+
return object.__schema?.id === this.getSchema(type)?.id;
|
|
89
94
|
});
|
|
90
|
-
return
|
|
95
|
+
return objects2;
|
|
96
|
+
});
|
|
97
|
+
this._space = _space;
|
|
98
|
+
const { objects } = this._space.db.query(import_echo.Schema.filter());
|
|
99
|
+
Object.keys(schemaMap).forEach((type) => {
|
|
100
|
+
const schema = objects.find((object) => object.typename === type);
|
|
101
|
+
if (schema) {
|
|
102
|
+
this.setSchema(type, schema);
|
|
103
|
+
}
|
|
91
104
|
});
|
|
92
|
-
this._space = space;
|
|
93
105
|
}
|
|
94
106
|
addSchemas() {
|
|
95
|
-
|
|
107
|
+
const { objects } = this._space.db.query(import_echo.Schema.filter());
|
|
108
|
+
this.schemas.forEach((schema) => {
|
|
109
|
+
if (!objects.find((object) => object.typename === schema.typename)) {
|
|
110
|
+
this._space.db.add(schema);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
96
113
|
return this.schemas;
|
|
97
114
|
}
|
|
98
115
|
createObject({ types } = {}) {
|
|
@@ -101,16 +118,6 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
101
118
|
}));
|
|
102
119
|
}
|
|
103
120
|
};
|
|
104
|
-
var mergeSchemaMap = (space, schemaMap) => {
|
|
105
|
-
const { objects } = space.db.query(import_echo.Schema.filter());
|
|
106
|
-
Object.keys(schemaMap).forEach((type) => {
|
|
107
|
-
const schema = objects.find((object) => object.typename === type);
|
|
108
|
-
if (schema) {
|
|
109
|
-
schemaMap[type] = schema;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return schemaMap;
|
|
113
|
-
};
|
|
114
121
|
|
|
115
122
|
// packages/core/echo/echo-generator/src/data.ts
|
|
116
123
|
var Status = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/data.ts", "../../../src/generator.ts", "../../../src/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './data';\nexport * from './generator';\nexport * from './util';\n", "//\n// Copyright 2023 DXOS.org\n//\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\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\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/schema/document',\n organization = 'example.com/schema/organization',\n contact = 'example.com/schema/contact',\n project = 'example.com/schema/project',\n}\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n typename: TestSchemaType.document,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: TestSchemaType.organization,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const contact = new Schema({\n typename: TestSchemaType.contact,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: TestSchemaType.project,\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: () => ({\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]: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n [TestSchemaType.contact]: (provider) => {\n const organizations = provider?.(TestSchemaType.organization);\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\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]: () => ({\n title: 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\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\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\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n public readonly schema: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this.schema);\n }\n\n getSchema(typename: string) {\n return this.schemas.find((schema) => schema.typename === typename);\n }\n\n createObject({ types }: { types?: T[] } = {}): TypedObject {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this.schema) as T[]));\n const data = this._generators[type](this._provider);\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n return new Expando(data, { schema: this.schema[type] });\n }\n\n // TODO(burdon): Create batch.\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n createObjects(map: Partial<Record<T, number>>): Expando[] {\n const objects: Expando[] = [];\n Object.entries<number>(map as any).forEach(([type, count]) => {\n range(() => objects.push(this.createObject({ types: [type as T] })), count);\n });\n\n return objects;\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n private readonly _space: Space;\n\n constructor(space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(mergeSchemaMap(space, schemaMap), generators, (type: T) => {\n const { objects } = this._space.db.query((object) => {\n return object.__schema === schemaMap[type];\n });\n\n return objects;\n });\n\n this._space = space;\n }\n\n addSchemas() {\n this.schemas.forEach((schema) => this._space.db.add(schema));\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n\n/**\n * Merge existing schema in space with defaults.\n */\nconst mergeSchemaMap = <T extends string>(space: Space, schemaMap: TestSchemaMap<T>) => {\n const { objects } = space.db.query(Schema.filter());\n Object.keys(schemaMap).forEach((type) => {\n const schema = objects.find((object) => object.typename === type);\n if (schema) {\n (schemaMap as any)[type] = schema;\n }\n });\n\n return schemaMap;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;ACOA,IAAAA,gBAAsB;AAEtB,IAAAC,eAA+C;;;
|
|
6
|
-
"names": ["import_faker", "import_echo", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from './data';\nexport * from './generator';\nexport * from './util';\n", "//\n// Copyright 2023 DXOS.org\n//\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\nimport { faker } from '@faker-js/faker';\n\nimport { Schema, type Space, TextObject } from '@dxos/client/echo';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestGeneratorMap, type TestSchemaMap } from './types';\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/schema/document',\n organization = 'example.com/schema/organization',\n contact = 'example.com/schema/contact',\n project = 'example.com/schema/project',\n}\n\nexport const testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = new Schema({\n typename: TestSchemaType.document,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'content',\n type: Schema.PropType.STRING, // TODO(burdon): Rich text.\n },\n ],\n });\n\n const organization = new Schema({\n typename: TestSchemaType.organization,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'website',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING,\n },\n ],\n });\n\n const contact = new Schema({\n typename: TestSchemaType.contact,\n props: [\n {\n id: 'name',\n type: Schema.PropType.STRING,\n },\n {\n id: 'email',\n type: Schema.PropType.STRING,\n },\n {\n id: 'org',\n type: Schema.PropType.REF,\n ref: organization,\n },\n // TODO(burdon): Convert to object with nested props.\n {\n id: 'lat',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'lng',\n type: Schema.PropType.NUMBER,\n },\n ],\n });\n\n const project = new Schema({\n typename: TestSchemaType.project,\n props: [\n {\n id: 'title',\n type: Schema.PropType.STRING,\n },\n {\n id: 'description',\n type: Schema.PropType.STRING, // TODO(burdon): Text.\n },\n {\n id: 'repo',\n type: Schema.PropType.STRING,\n },\n {\n id: 'status',\n type: Schema.PropType.STRING,\n },\n {\n id: 'priority',\n type: Schema.PropType.NUMBER,\n },\n {\n id: 'active',\n type: Schema.PropType.BOOLEAN,\n },\n ],\n });\n\n return {\n [TestSchemaType.document]: document,\n [TestSchemaType.organization]: organization,\n [TestSchemaType.contact]: contact,\n [TestSchemaType.project]: project,\n };\n};\n\nexport const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {\n [TestSchemaType.document]: () => ({\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]: () => ({\n name: faker.company.name(),\n website: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,\n description: new TextObject(faker.lorem.sentences()),\n }),\n\n [TestSchemaType.contact]: (provider) => {\n const organizations = provider?.(TestSchemaType.organization);\n const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;\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]: () => ({\n title: 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\nexport const createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);\n\nexport const createSpaceObjectGenerator = (space: Space) =>\n new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);\n\nconst locations = [\n { lat: 139.74946157054467, lng: 35.686962764371174 },\n { lat: -73.98196278740681, lng: 40.75192492259464 },\n { lat: -99.1329340602939, lng: 19.444388301415472 },\n { lat: 72.85504343876647, lng: 19.0189362343566 },\n { lat: -46.62696583905523, lng: -23.55673372837896 },\n { lat: 77.22805816860182, lng: 28.671938757181522 },\n { lat: 121.43455881982015, lng: 31.218398311228327 },\n { lat: 88.32272979950551, lng: 22.49691515689642 },\n { lat: 90.40663360810754, lng: 23.725005570312817 },\n { lat: -58.399477232331435, lng: -34.600555749907414 },\n { lat: -118.18192636994041, lng: 33.99192410876543 },\n { lat: 66.98806305137339, lng: 24.87193814681484 },\n { lat: 31.248022361126118, lng: 30.051906205103705 },\n { lat: -43.22696665284366, lng: -22.923077315615956 },\n { lat: 135.4581989565952, lng: 34.75198107491417 },\n { lat: 116.38633982565943, lng: 39.93083808990906 },\n { lat: 120.9802713035424, lng: 14.606104813440538 },\n { lat: 37.6135769672714, lng: 55.75410998124818 },\n { lat: 29.008055727002613, lng: 41.10694201243979 },\n { lat: 2.33138946713035, lng: 48.86863878981461 },\n { lat: 126.99778513820195, lng: 37.56829495838895 },\n { lat: 3.3895852125984334, lng: 6.445207512093191 },\n { lat: 106.82749176247012, lng: -6.172471846798885 },\n { lat: -87.75200083270931, lng: 41.83193651927843 },\n { lat: 113.32306427226172, lng: 23.14692716047989 },\n { lat: -0.11866770247593195, lng: 51.5019405883275 },\n { lat: -77.05200795343472, lng: -12.04606681752557 },\n { lat: 51.42239817500899, lng: 35.673888627001304 },\n { lat: 15.313026023171744, lng: -4.327778243275986 },\n { lat: -74.08528981377441, lng: 4.598369421147822 },\n { lat: 114.1201772298325, lng: 22.554316369677963 },\n { lat: 114.26807118958311, lng: 30.581977209337822 },\n { lat: 114.18306345846304, lng: 22.30692675357551 },\n { lat: 117.19807322410043, lng: 39.13197212310894 },\n { lat: 80.27805287890033, lng: 13.091933670856292 },\n { lat: 121.568333333333, lng: 25.0358333333333 },\n { lat: 77.55806386521755, lng: 12.97194099507442 },\n { lat: 100.51469879369489, lng: 13.751945064087977 },\n { lat: 74.34807892054346, lng: 31.56191739488844 },\n { lat: 106.59303578916195, lng: 29.566922888044644 },\n { lat: 78.47800771287751, lng: 17.401928991511454 },\n { lat: -70.66898671317483, lng: -33.448067956934096 },\n { lat: -80.22605193945003, lng: 25.789556555021534 },\n { lat: -43.916950376804834, lng: -19.91308016391116 },\n { lat: -3.6852975446125242, lng: 40.40197212311381 },\n { lat: -75.17194183200792, lng: 40.001919022526465 },\n { lat: 72.57805776168215, lng: 23.031998775062675 },\n { lat: 106.69308136207889, lng: 10.781971309193409 },\n { lat: -79.42196665298843, lng: 43.70192573640844 },\n { lat: 103.85387481909902, lng: 1.2949793251059418 },\n { lat: 13.23248118266855, lng: -8.836340255012658 },\n { lat: 44.391922914564134, lng: 33.34059435615865 },\n { lat: 2.181424460619155, lng: 41.385245438547486 },\n { lat: 88.32994665421205, lng: 22.580390440861947 },\n { lat: -96.84196278749818, lng: 32.82196968167733 },\n { lat: 123.44802765120869, lng: 41.80692512604918 },\n { lat: 32.532233380011576, lng: 15.590024084277673 },\n { lat: 73.84805776168719, lng: 18.531963374654026 },\n { lat: 151.1832339501475, lng: -33.91806510862875 },\n { lat: 30.314074200315076, lng: 59.94096036375191 },\n { lat: 91.79802154756635, lng: 22.33193814680459 },\n { lat: 113.74277634138707, lng: 23.050834758613007 },\n { lat: -84.40189524187565, lng: 33.83195971260585 },\n { lat: -71.07195953218684, lng: 42.33190600170229 },\n { lat: 46.770795798688255, lng: 24.642779007816443 },\n { lat: -95.341925149146, lng: 29.821920243188856 },\n { lat: 105.8480683412422, lng: 21.035273107737055 },\n { lat: -77.01136443943716, lng: 38.901495235087054 },\n { lat: -103.33198008081848, lng: 20.671961950508944 },\n { lat: 144.97307037590406, lng: -37.81808545369631 },\n { lat: 29.948050030391755, lng: 31.201965205759393 },\n { lat: 104.06807363094873, lng: 30.671945877957796 },\n { lat: -83.0820016464927, lng: 42.33190600170229 },\n { lat: 96.16473175266185, lng: 16.785299963188777 },\n { lat: 108.89305043760862, lng: 34.27697130928732 },\n { lat: -51.20195790450316, lng: -30.048068770722466 },\n { lat: 121.465, lng: 25.0127777777778 },\n { lat: 72.83809356897484, lng: 21.20192960187819 },\n { lat: 109.60911291406296, lng: 23.09653464659317 },\n { lat: -4.041994118507091, lng: 5.321942826098564 },\n { lat: -47.91799814700306, lng: -15.781394372878992 },\n { lat: 32.862445782356644, lng: 39.929184444075474 },\n { lat: -100.33193064232995, lng: 25.671940995125283 },\n { lat: 139.60202098994017, lng: 35.43065615270891 },\n { lat: 118.77802846499208, lng: 32.05196500231233 },\n { lat: -73.58524281670213, lng: 45.50194506421502 },\n { lat: 106.7180927553083, lng: 26.581988806001448 },\n { lat: -34.91755136960728, lng: -8.073699467249241 },\n { lat: 126.64803904445057, lng: 45.75192980542715 },\n { lat: -38.58192718342411, lng: -3.7480720258257634 },\n { lat: -112.07193755969467, lng: 33.5419257363676 },\n { lat: 117.67001623440774, lng: 24.520375385531167 },\n { lat: -38.48193328693924, lng: -12.968026046044827 },\n { lat: 129.00810170722048, lng: 35.09699877511093 },\n { lat: -122.41716877355225, lng: 37.76919562968743 },\n { lat: 28.028063865019476, lng: -26.16809888138414 },\n { lat: 13.399602764700546, lng: 52.523764522251156 },\n { lat: 3.048606670909237, lng: 36.765010656628135 },\n { lat: 125.75274485499392, lng: 39.02138455800434 },\n { lat: 12.481312562873995, lng: 41.89790148509894 },\n];\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { faker } from '@faker-js/faker';\n\nimport { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';\n\nimport { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } from './types';\nimport { range } from './util';\n\n/**\n * Typed object generator.\n */\nexport class TestObjectGenerator<T extends string> {\n // prettier-ignore\n constructor(\n private readonly _schemas: TestSchemaMap<T>,\n private readonly _generators: TestGeneratorMap<T>,\n private readonly _provider?: TestObjectProvider<T>\n ) {}\n\n get schemas(): Schema[] {\n return Object.values(this._schemas);\n }\n\n getSchema(type: T) {\n return this.schemas.find((schema) => schema.typename === type);\n }\n\n protected setSchema(type: T, schema: Schema) {\n this._schemas[type] = schema;\n }\n\n // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).\n createObject({ types }: { types?: T[] } = {}): TypedObject {\n const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));\n const data = this._generators[type](this._provider);\n const schema = this.getSchema(type);\n return new Expando(data, { schema });\n }\n\n // TODO(burdon): Create batch.\n // TODO(burdon): Based on dependencies (e.g., organization before contact).\n createObjects(map: Partial<Record<T, number>>): Expando[] {\n const objects: Expando[] = [];\n Object.entries<number>(map as any).forEach(([type, count]) => {\n range(() => objects.push(this.createObject({ types: [type as T] })), count);\n });\n\n return objects;\n }\n}\n\n/**\n * Typed object generator for a space.\n */\nexport class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {\n constructor(private readonly _space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {\n super(schemaMap, generators, (type: T) => {\n const { objects } = this._space.db.query((object) => {\n return object.__schema?.id === this.getSchema(type)?.id;\n });\n\n return 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 const { objects } = this._space.db.query(Schema.filter());\n Object.keys(schemaMap).forEach((type) => {\n const schema = objects.find((object) => object.typename === type);\n if (schema) {\n this.setSchema(type as T, schema);\n }\n });\n }\n\n addSchemas() {\n const { objects } = this._space.db.query(Schema.filter());\n this.schemas.forEach((schema) => {\n if (!objects.find((object) => object.typename === schema.typename)) {\n this._space.db.add(schema);\n }\n });\n\n return this.schemas;\n }\n\n override createObject({ types }: { types?: T[] } = {}): Expando {\n return this._space.db.add(super.createObject({ types }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(burdon): Util.\nexport const range = <T>(fn: (i: number) => T | undefined, length: number): T[] =>\n Array.from({ length })\n .map((_, i) => fn(i))\n .filter(Boolean) as T[];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;ACOA,IAAAA,gBAAsB;AAEtB,IAAAC,eAA+C;;;ACL/C,mBAAsB;AAEtB,kBAA8D;;;ACDvD,IAAMC,QAAQ,CAAIC,IAAkCC,WACzDC,MAAMC,KAAK;EAAEF;AAAO,CAAA,EACjBG,IAAI,CAACC,GAAGC,MAAMN,GAAGM,CAAAA,CAAAA,EACjBC,OAAOC,OAAAA;;;ADML,IAAMC,sBAAN,MAAMA;;EAEXC,YACmBC,UACAC,aACAC,WACjB;oBAHiBF;uBACAC;qBACAC;EAChB;EAEH,IAAIC,UAAoB;AACtB,WAAOC,OAAOC,OAAO,KAAKL,QAAQ;EACpC;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AK;EAAkB;EAClD;IAAED,KAAK;IAAqBC,KAAK;EAAkB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAoBC,KAAK;EAAmB;EACnD;IAAED,KAAK;IAAmBC,KAAK;EAAmB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;EAClD;IAAED,KAAK;IAAoBC,KAAK;EAAkB;;",
|
|
6
|
+
"names": ["import_faker", "import_echo", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "TestObjectGenerator", "constructor", "_schemas", "_generators", "_provider", "schemas", "Object", "values", "getSchema", "type", "find", "schema", "typename", "setSchema", "createObject", "types", "faker", "helpers", "arrayElement", "keys", "data", "Expando", "createObjects", "map", "objects", "entries", "forEach", "count", "range", "push", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "db", "query", "object", "__schema", "id", "Schema", "filter", "addSchemas", "add", "Status", "Priority", "TestSchemaType", "document", "organization", "contact", "project", "testSchemas", "Schema", "typename", "props", "id", "type", "PropType", "STRING", "REF", "ref", "NUMBER", "BOOLEAN", "testObjectGenerators", "title", "faker", "lorem", "sentence", "content", "sentences", "min", "max", "number", "int", "name", "company", "website", "datatype", "boolean", "probability", "internet", "url", "undefined", "description", "TextObject", "provider", "organizations", "location", "helpers", "arrayElement", "locations", "person", "fullName", "email", "org", "length", "commerce", "productName", "repo", "status", "priority", "active", "createTestObjectGenerator", "TestObjectGenerator", "createSpaceObjectGenerator", "space", "SpaceObjectGenerator", "lat", "lng"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1057,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":1057,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":10516,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"},"packages/core/echo/echo-generator/src/data.ts":{"bytes":37173,"imports":[{"path":"@faker-js/faker","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"packages/core/echo/echo-generator/src/generator.ts","kind":"import-statement","original":"./generator"}],"format":"esm"},"packages/core/echo/echo-generator/src/index.ts":{"bytes":634,"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/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":23256},"packages/core/echo/echo-generator/dist/lib/node/index.cjs":{"imports":[{"path":"@faker-js/faker","kind":"require-call","external":true},{"path":"@dxos/client/echo","kind":"require-call","external":true},{"path":"@faker-js/faker","kind":"require-call","external":true},{"path":"@dxos/client/echo","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":521},"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":11082},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":2295},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":91}},"bytes":15418}}}
|
|
@@ -4,12 +4,13 @@ import { type TestGeneratorMap, type TestObjectProvider, type TestSchemaMap } fr
|
|
|
4
4
|
* Typed object generator.
|
|
5
5
|
*/
|
|
6
6
|
export declare class TestObjectGenerator<T extends string> {
|
|
7
|
-
readonly
|
|
7
|
+
private readonly _schemas;
|
|
8
8
|
private readonly _generators;
|
|
9
9
|
private readonly _provider?;
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(_schemas: TestSchemaMap<T>, _generators: TestGeneratorMap<T>, _provider?: TestObjectProvider<T> | undefined);
|
|
11
11
|
get schemas(): Schema[];
|
|
12
|
-
getSchema(
|
|
12
|
+
getSchema(type: T): Schema | undefined;
|
|
13
|
+
protected setSchema(type: T, schema: Schema): void;
|
|
13
14
|
createObject({ types }?: {
|
|
14
15
|
types?: T[];
|
|
15
16
|
}): TypedObject;
|
|
@@ -20,7 +21,7 @@ export declare class TestObjectGenerator<T extends string> {
|
|
|
20
21
|
*/
|
|
21
22
|
export declare class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {
|
|
22
23
|
private readonly _space;
|
|
23
|
-
constructor(
|
|
24
|
+
constructor(_space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>);
|
|
24
25
|
addSchemas(): Schema[];
|
|
25
26
|
createObject({ types }?: {
|
|
26
27
|
types?: T[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAElF,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7F;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,MAAM;IAG7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAFV,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAChC,SAAS,CAAC,mCAAuB;IAGpD,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;IAED,SAAS,CAAC,IAAI,EAAE,CAAC;IAIjB,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM;IAK3C,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,WAAW;IAS1D,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE;CAQ1D;AAED;;GAEG;AACH,qBAAa,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAoBxG,UAAU;IAWD,YAAY,CAAC,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;KAAO,GAAG,OAAO;CAGhE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-generator",
|
|
3
|
-
"version": "0.3.7-main.
|
|
3
|
+
"version": "0.3.7-main.3ea49a6",
|
|
4
4
|
"description": "ECHO data generator for testing.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@faker-js/faker": "^8.0.2",
|
|
20
|
-
"@dxos/
|
|
21
|
-
"@dxos/
|
|
20
|
+
"@dxos/client": "0.3.7-main.3ea49a6",
|
|
21
|
+
"@dxos/node-std": "0.3.7-main.3ea49a6"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {},
|
|
24
24
|
"publishConfig": {
|
package/src/generator.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { faker } from '@faker-js/faker';
|
|
|
6
6
|
import { expect } from 'chai';
|
|
7
7
|
|
|
8
8
|
import { Client } from '@dxos/client';
|
|
9
|
+
import { debug } from '@dxos/client/echo';
|
|
9
10
|
import { describe, test } from '@dxos/test';
|
|
10
11
|
|
|
11
12
|
import { createSpaceObjectGenerator, createTestObjectGenerator, TestSchemaType } from './data';
|
|
@@ -26,9 +27,8 @@ describe('TestObjectGenerator', () => {
|
|
|
26
27
|
await client.initialize();
|
|
27
28
|
await client.halo.createIdentity();
|
|
28
29
|
const space = await client.spaces.create();
|
|
29
|
-
const generator = createSpaceObjectGenerator(space);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const generator = createSpaceObjectGenerator(space);
|
|
32
32
|
generator.addSchemas();
|
|
33
33
|
|
|
34
34
|
// Create org object.
|
|
@@ -41,4 +41,35 @@ describe('TestObjectGenerator', () => {
|
|
|
41
41
|
|
|
42
42
|
await client.destroy();
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
test.only('idempotence', async () => {
|
|
46
|
+
const client = new Client();
|
|
47
|
+
await client.initialize();
|
|
48
|
+
await client.halo.createIdentity();
|
|
49
|
+
const space = await client.spaces.create();
|
|
50
|
+
|
|
51
|
+
const schemaId: string[] = [];
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
const generator = createSpaceObjectGenerator(space);
|
|
55
|
+
generator.addSchemas();
|
|
56
|
+
const organization = generator.createObject({ types: [TestSchemaType.organization] });
|
|
57
|
+
schemaId.push(organization.__schema!.id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
{
|
|
61
|
+
const generator = createSpaceObjectGenerator(space);
|
|
62
|
+
generator.addSchemas();
|
|
63
|
+
const organization = generator.createObject({ types: [TestSchemaType.organization] });
|
|
64
|
+
schemaId.push(organization.__schema!.id);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
expect(schemaId[0]).to.eq(schemaId[1]);
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
console.log(space.db.objects.map((object) => object[debug]));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await client.destroy();
|
|
74
|
+
});
|
|
44
75
|
});
|
package/src/generator.ts
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
// TODO(burdon): Reconcile with @dxos/plugin-debug, @dxos/aurora/testing.
|
|
6
|
-
// TODO(burdon): Bug when adding stale objects to space (e.g., static objects already added in previous story invocation).
|
|
7
|
-
|
|
8
5
|
import { faker } from '@faker-js/faker';
|
|
9
6
|
|
|
10
7
|
import { Expando, type TypedObject, Schema, type Space } from '@dxos/client/echo';
|
|
@@ -18,24 +15,29 @@ import { range } from './util';
|
|
|
18
15
|
export class TestObjectGenerator<T extends string> {
|
|
19
16
|
// prettier-ignore
|
|
20
17
|
constructor(
|
|
21
|
-
|
|
18
|
+
private readonly _schemas: TestSchemaMap<T>,
|
|
22
19
|
private readonly _generators: TestGeneratorMap<T>,
|
|
23
20
|
private readonly _provider?: TestObjectProvider<T>
|
|
24
21
|
) {}
|
|
25
22
|
|
|
26
23
|
get schemas(): Schema[] {
|
|
27
|
-
return Object.values(this.
|
|
24
|
+
return Object.values(this._schemas);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getSchema(type: T) {
|
|
28
|
+
return this.schemas.find((schema) => schema.typename === type);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
protected setSchema(type: T, schema: Schema) {
|
|
32
|
+
this._schemas[type] = schema;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
|
|
34
36
|
createObject({ types }: { types?: T[] } = {}): TypedObject {
|
|
35
|
-
const type = faker.helpers.arrayElement(types ?? (Object.keys(this.
|
|
37
|
+
const type = faker.helpers.arrayElement(types ?? (Object.keys(this._schemas) as T[]));
|
|
36
38
|
const data = this._generators[type](this._provider);
|
|
37
|
-
|
|
38
|
-
return new Expando(data, { schema
|
|
39
|
+
const schema = this.getSchema(type);
|
|
40
|
+
return new Expando(data, { schema });
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
// TODO(burdon): Create batch.
|
|
@@ -54,22 +56,34 @@ export class TestObjectGenerator<T extends string> {
|
|
|
54
56
|
* Typed object generator for a space.
|
|
55
57
|
*/
|
|
56
58
|
export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<T> {
|
|
57
|
-
private readonly _space: Space
|
|
58
|
-
|
|
59
|
-
constructor(space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {
|
|
60
|
-
super(mergeSchemaMap(space, schemaMap), generators, (type: T) => {
|
|
59
|
+
constructor(private readonly _space: Space, schemaMap: TestSchemaMap<T>, generators: TestGeneratorMap<T>) {
|
|
60
|
+
super(schemaMap, generators, (type: T) => {
|
|
61
61
|
const { objects } = this._space.db.query((object) => {
|
|
62
|
-
return object.__schema ===
|
|
62
|
+
return object.__schema?.id === this.getSchema(type)?.id;
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
return objects;
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
// TODO(burdon): Map initially are objects that have not been added to the space.
|
|
69
|
+
// Merge existing schema in space with defaults.
|
|
70
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
71
|
+
Object.keys(schemaMap).forEach((type) => {
|
|
72
|
+
const schema = objects.find((object) => object.typename === type);
|
|
73
|
+
if (schema) {
|
|
74
|
+
this.setSchema(type as T, schema);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
addSchemas() {
|
|
72
|
-
|
|
80
|
+
const { objects } = this._space.db.query(Schema.filter());
|
|
81
|
+
this.schemas.forEach((schema) => {
|
|
82
|
+
if (!objects.find((object) => object.typename === schema.typename)) {
|
|
83
|
+
this._space.db.add(schema);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
73
87
|
return this.schemas;
|
|
74
88
|
}
|
|
75
89
|
|
|
@@ -77,18 +91,3 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
|
|
|
77
91
|
return this._space.db.add(super.createObject({ types }));
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Merge existing schema in space with defaults.
|
|
83
|
-
*/
|
|
84
|
-
const mergeSchemaMap = <T extends string>(space: Space, schemaMap: TestSchemaMap<T>) => {
|
|
85
|
-
const { objects } = space.db.query(Schema.filter());
|
|
86
|
-
Object.keys(schemaMap).forEach((type) => {
|
|
87
|
-
const schema = objects.find((object) => object.typename === type);
|
|
88
|
-
if (schema) {
|
|
89
|
-
(schemaMap as any)[type] = schema;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return schemaMap;
|
|
94
|
-
};
|