@dxos/echo-generator 0.3.4 → 0.3.5-main.1429e83

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/src/data.ts CHANGED
@@ -24,6 +24,7 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
24
24
  {
25
25
  id: 'name',
26
26
  type: Schema.PropType.STRING,
27
+ // TODO(burdon): primary: true,
27
28
  },
28
29
  {
29
30
  id: 'content',
@@ -33,8 +34,8 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
33
34
  });
34
35
 
35
36
  const organization = new Schema({
37
+ typename: 'example.com/schema/organization',
36
38
  props: [
37
- // TODO(burdon): Add metadata for default label.
38
39
  {
39
40
  id: 'name',
40
41
  type: Schema.PropType.STRING,
@@ -44,13 +45,14 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
44
45
  type: Schema.PropType.STRING,
45
46
  },
46
47
  {
47
- id: 'active',
48
- type: Schema.PropType.BOOLEAN,
48
+ id: 'description',
49
+ type: Schema.PropType.STRING,
49
50
  },
50
51
  ],
51
52
  });
52
53
 
53
54
  const person = new Schema({
55
+ typename: 'example.com/schema/person',
54
56
  props: [
55
57
  {
56
58
  id: 'name',
@@ -65,15 +67,29 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
65
67
  type: Schema.PropType.REF,
66
68
  ref: organization,
67
69
  },
70
+ // TODO(burdon): Convert to object with nested props.
71
+ {
72
+ id: 'lat',
73
+ type: Schema.PropType.NUMBER,
74
+ },
75
+ {
76
+ id: 'lng',
77
+ type: Schema.PropType.NUMBER,
78
+ },
68
79
  ],
69
80
  });
70
81
 
71
82
  const project = new Schema({
83
+ typename: 'example.com/schema/project',
72
84
  props: [
73
85
  {
74
86
  id: 'title',
75
87
  type: Schema.PropType.STRING,
76
88
  },
89
+ {
90
+ id: 'description',
91
+ type: Schema.PropType.STRING, // TODO(burdon): Text.
92
+ },
77
93
  {
78
94
  id: 'repo',
79
95
  type: Schema.PropType.STRING,
@@ -86,6 +102,10 @@ export const testSchemas = (): TestSchemaMap<TestSchemaType> => {
86
102
  id: 'priority',
87
103
  type: Schema.PropType.NUMBER,
88
104
  },
105
+ {
106
+ id: 'active',
107
+ type: Schema.PropType.BOOLEAN,
108
+ },
89
109
  ],
90
110
  });
91
111
 
@@ -106,6 +126,7 @@ export const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
106
126
 
107
127
  person: (provider) => {
108
128
  const organizations = provider?.('organization');
129
+ const location = faker.datatype.boolean() ? faker.helpers.arrayElement(locations) : undefined;
109
130
  return {
110
131
  name: faker.person.fullName(),
111
132
  email: faker.datatype.boolean({ probability: 0.5 }) ? faker.internet.email() : undefined,
@@ -113,6 +134,7 @@ export const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
113
134
  organizations?.length && faker.datatype.boolean({ probability: 0.3 })
114
135
  ? faker.helpers.arrayElement(organizations)
115
136
  : undefined,
137
+ ...location,
116
138
  };
117
139
  },
118
140
 
@@ -121,6 +143,7 @@ export const testObjectGenerators: TestGeneratorMap<TestSchemaType> = {
121
143
  repo: faker.datatype.boolean({ probability: 0.3 }) ? faker.internet.url() : undefined,
122
144
  status: faker.helpers.arrayElement(Status),
123
145
  priority: faker.helpers.arrayElement(Priority),
146
+ active: faker.datatype.boolean(),
124
147
  }),
125
148
  };
126
149
 
@@ -128,3 +151,106 @@ export const createTestObjectGenerator = () => new TestObjectGenerator(testSchem
128
151
 
129
152
  export const createSpaceObjectGenerator = (space: Space) =>
130
153
  new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators);
154
+
155
+ const locations = [
156
+ { lat: 139.74946157054467, lng: 35.686962764371174 },
157
+ { lat: -73.98196278740681, lng: 40.75192492259464 },
158
+ { lat: -99.1329340602939, lng: 19.444388301415472 },
159
+ { lat: 72.85504343876647, lng: 19.0189362343566 },
160
+ { lat: -46.62696583905523, lng: -23.55673372837896 },
161
+ { lat: 77.22805816860182, lng: 28.671938757181522 },
162
+ { lat: 121.43455881982015, lng: 31.218398311228327 },
163
+ { lat: 88.32272979950551, lng: 22.49691515689642 },
164
+ { lat: 90.40663360810754, lng: 23.725005570312817 },
165
+ { lat: -58.399477232331435, lng: -34.600555749907414 },
166
+ { lat: -118.18192636994041, lng: 33.99192410876543 },
167
+ { lat: 66.98806305137339, lng: 24.87193814681484 },
168
+ { lat: 31.248022361126118, lng: 30.051906205103705 },
169
+ { lat: -43.22696665284366, lng: -22.923077315615956 },
170
+ { lat: 135.4581989565952, lng: 34.75198107491417 },
171
+ { lat: 116.38633982565943, lng: 39.93083808990906 },
172
+ { lat: 120.9802713035424, lng: 14.606104813440538 },
173
+ { lat: 37.6135769672714, lng: 55.75410998124818 },
174
+ { lat: 29.008055727002613, lng: 41.10694201243979 },
175
+ { lat: 2.33138946713035, lng: 48.86863878981461 },
176
+ { lat: 126.99778513820195, lng: 37.56829495838895 },
177
+ { lat: 3.3895852125984334, lng: 6.445207512093191 },
178
+ { lat: 106.82749176247012, lng: -6.172471846798885 },
179
+ { lat: -87.75200083270931, lng: 41.83193651927843 },
180
+ { lat: 113.32306427226172, lng: 23.14692716047989 },
181
+ { lat: -0.11866770247593195, lng: 51.5019405883275 },
182
+ { lat: -77.05200795343472, lng: -12.04606681752557 },
183
+ { lat: 51.42239817500899, lng: 35.673888627001304 },
184
+ { lat: 15.313026023171744, lng: -4.327778243275986 },
185
+ { lat: -74.08528981377441, lng: 4.598369421147822 },
186
+ { lat: 114.1201772298325, lng: 22.554316369677963 },
187
+ { lat: 114.26807118958311, lng: 30.581977209337822 },
188
+ { lat: 114.18306345846304, lng: 22.30692675357551 },
189
+ { lat: 117.19807322410043, lng: 39.13197212310894 },
190
+ { lat: 80.27805287890033, lng: 13.091933670856292 },
191
+ { lat: 121.568333333333, lng: 25.0358333333333 },
192
+ { lat: 77.55806386521755, lng: 12.97194099507442 },
193
+ { lat: 100.51469879369489, lng: 13.751945064087977 },
194
+ { lat: 74.34807892054346, lng: 31.56191739488844 },
195
+ { lat: 106.59303578916195, lng: 29.566922888044644 },
196
+ { lat: 78.47800771287751, lng: 17.401928991511454 },
197
+ { lat: -70.66898671317483, lng: -33.448067956934096 },
198
+ { lat: -80.22605193945003, lng: 25.789556555021534 },
199
+ { lat: -43.916950376804834, lng: -19.91308016391116 },
200
+ { lat: -3.6852975446125242, lng: 40.40197212311381 },
201
+ { lat: -75.17194183200792, lng: 40.001919022526465 },
202
+ { lat: 72.57805776168215, lng: 23.031998775062675 },
203
+ { lat: 106.69308136207889, lng: 10.781971309193409 },
204
+ { lat: -79.42196665298843, lng: 43.70192573640844 },
205
+ { lat: 103.85387481909902, lng: 1.2949793251059418 },
206
+ { lat: 13.23248118266855, lng: -8.836340255012658 },
207
+ { lat: 44.391922914564134, lng: 33.34059435615865 },
208
+ { lat: 2.181424460619155, lng: 41.385245438547486 },
209
+ { lat: 88.32994665421205, lng: 22.580390440861947 },
210
+ { lat: -96.84196278749818, lng: 32.82196968167733 },
211
+ { lat: 123.44802765120869, lng: 41.80692512604918 },
212
+ { lat: 32.532233380011576, lng: 15.590024084277673 },
213
+ { lat: 73.84805776168719, lng: 18.531963374654026 },
214
+ { lat: 151.1832339501475, lng: -33.91806510862875 },
215
+ { lat: 30.314074200315076, lng: 59.94096036375191 },
216
+ { lat: 91.79802154756635, lng: 22.33193814680459 },
217
+ { lat: 113.74277634138707, lng: 23.050834758613007 },
218
+ { lat: -84.40189524187565, lng: 33.83195971260585 },
219
+ { lat: -71.07195953218684, lng: 42.33190600170229 },
220
+ { lat: 46.770795798688255, lng: 24.642779007816443 },
221
+ { lat: -95.341925149146, lng: 29.821920243188856 },
222
+ { lat: 105.8480683412422, lng: 21.035273107737055 },
223
+ { lat: -77.01136443943716, lng: 38.901495235087054 },
224
+ { lat: -103.33198008081848, lng: 20.671961950508944 },
225
+ { lat: 144.97307037590406, lng: -37.81808545369631 },
226
+ { lat: 29.948050030391755, lng: 31.201965205759393 },
227
+ { lat: 104.06807363094873, lng: 30.671945877957796 },
228
+ { lat: -83.0820016464927, lng: 42.33190600170229 },
229
+ { lat: 96.16473175266185, lng: 16.785299963188777 },
230
+ { lat: 108.89305043760862, lng: 34.27697130928732 },
231
+ { lat: -51.20195790450316, lng: -30.048068770722466 },
232
+ { lat: 121.465, lng: 25.0127777777778 },
233
+ { lat: 72.83809356897484, lng: 21.20192960187819 },
234
+ { lat: 109.60911291406296, lng: 23.09653464659317 },
235
+ { lat: -4.041994118507091, lng: 5.321942826098564 },
236
+ { lat: -47.91799814700306, lng: -15.781394372878992 },
237
+ { lat: 32.862445782356644, lng: 39.929184444075474 },
238
+ { lat: -100.33193064232995, lng: 25.671940995125283 },
239
+ { lat: 139.60202098994017, lng: 35.43065615270891 },
240
+ { lat: 118.77802846499208, lng: 32.05196500231233 },
241
+ { lat: -73.58524281670213, lng: 45.50194506421502 },
242
+ { lat: 106.7180927553083, lng: 26.581988806001448 },
243
+ { lat: -34.91755136960728, lng: -8.073699467249241 },
244
+ { lat: 126.64803904445057, lng: 45.75192980542715 },
245
+ { lat: -38.58192718342411, lng: -3.7480720258257634 },
246
+ { lat: -112.07193755969467, lng: 33.5419257363676 },
247
+ { lat: 117.67001623440774, lng: 24.520375385531167 },
248
+ { lat: -38.48193328693924, lng: -12.968026046044827 },
249
+ { lat: 129.00810170722048, lng: 35.09699877511093 },
250
+ { lat: -122.41716877355225, lng: 37.76919562968743 },
251
+ { lat: 28.028063865019476, lng: -26.16809888138414 },
252
+ { lat: 13.399602764700546, lng: 52.523764522251156 },
253
+ { lat: 3.048606670909237, lng: 36.765010656628135 },
254
+ { lat: 12.481312562873995, lng: 41.89790148509894 },
255
+ { lat: 125.75274485499392, lng: 39.02138455800434 },
256
+ ];
package/src/generator.ts CHANGED
@@ -27,10 +27,15 @@ export class TestObjectGenerator<T extends string> {
27
27
  return Object.values(this.schema);
28
28
  }
29
29
 
30
+ getSchema(typename: string) {
31
+ return this.schemas.find((schema) => schema.typename === typename);
32
+ }
33
+
30
34
  createObject({ types }: { types?: T[] } = {}): Expando {
31
35
  const type = faker.helpers.arrayElement(types ?? (Object.keys(this.schema) as T[]));
32
36
  const factory = this._generators[type];
33
37
  const data = factory(this._provider);
38
+ // TODO(burdon): Runtime type check via: https://github.com/Effect-TS/schema (or zod).
34
39
  return new Expando(data, { schema: this.schema[type] });
35
40
  }
36
41
 
@@ -57,6 +62,7 @@ export class SpaceObjectGenerator<T extends string> extends TestObjectGenerator<
57
62
 
58
63
  addSchemas() {
59
64
  this.schemas.forEach((schema) => this._space.db.add(schema));
65
+ return this.schemas;
60
66
  }
61
67
 
62
68
  override createObject({ types }: { types?: T[] } = {}): Expando {