@dxos/echo-generator 0.7.1 → 0.7.2-staging.6d26b2a
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 +21 -428
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +19 -426
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +21 -428
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/data.d.ts.map +1 -1
- package/dist/types/src/generator.d.ts +4 -4
- package/dist/types/src/generator.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +6 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/data.ts +55 -155
- package/src/generator.test.ts +18 -18
- package/src/generator.ts +6 -7
- package/src/types.ts +10 -6
- package/src/util.ts +1 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -75,7 +75,6 @@ var TestObjectGenerator = class {
|
|
|
75
75
|
const schema = this.getSchema(type);
|
|
76
76
|
return schema ? (0, import_echo_schema2.create)(schema, data) : (0, import_echo_schema2.create)(data);
|
|
77
77
|
}
|
|
78
|
-
// TODO(burdon): Create batch.
|
|
79
78
|
// TODO(burdon): Based on dependencies (e.g., organization before contact).
|
|
80
79
|
async createObjects(map) {
|
|
81
80
|
const tasks = Object.entries(map).map(([type, count]) => {
|
|
@@ -135,7 +134,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
135
134
|
async mutateObject(object, params) {
|
|
136
135
|
(0, import_invariant.invariant)(this._mutations, "Mutations not defined.", {
|
|
137
136
|
F: __dxlog_file,
|
|
138
|
-
L:
|
|
137
|
+
L: 130,
|
|
139
138
|
S: this,
|
|
140
139
|
A: [
|
|
141
140
|
"this._mutations",
|
|
@@ -145,7 +144,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
|
|
|
145
144
|
const type = (0, import_echo_schema2.getObjectAnnotation)((0, import_echo_schema2.getSchema)(object)).typename;
|
|
146
145
|
(0, import_invariant.invariant)(type && this._mutations?.[type], "Invalid object type.", {
|
|
147
146
|
F: __dxlog_file,
|
|
148
|
-
L:
|
|
147
|
+
L: 132,
|
|
149
148
|
S: this,
|
|
150
149
|
A: [
|
|
151
150
|
"type && this._mutations?.[type]",
|
|
@@ -179,30 +178,20 @@ var TestSchemaType;
|
|
|
179
178
|
TestSchemaType2["contact"] = "example.com/type/contact";
|
|
180
179
|
TestSchemaType2["project"] = "example.com/type/project";
|
|
181
180
|
})(TestSchemaType || (TestSchemaType = {}));
|
|
182
|
-
var createDynamicSchema = (typename, fields) => {
|
|
183
|
-
const typeSchema = import_echo_schema.S.partial(import_echo_schema.S.Struct(fields)).pipe((0, import_echo_schema.EchoObject)(typename, "1.0.0"));
|
|
184
|
-
const typeAnnotation = (0, import_echo_schema.getObjectAnnotation)(typeSchema);
|
|
185
|
-
const schemaToStore = (0, import_echo_schema.createStoredSchema)({
|
|
186
|
-
typename,
|
|
187
|
-
version: "0.1.0"
|
|
188
|
-
});
|
|
189
|
-
const updatedSchema = typeSchema.annotations({
|
|
190
|
-
[import_echo_schema.ObjectAnnotationId]: {
|
|
191
|
-
...typeAnnotation,
|
|
192
|
-
schemaId: schemaToStore.id
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
schemaToStore.jsonSchema = (0, import_echo_schema.toJsonSchema)(updatedSchema);
|
|
196
|
-
return new import_echo_schema.MutableSchema(schemaToStore);
|
|
197
|
-
};
|
|
198
181
|
var testSchemas = () => {
|
|
199
|
-
const document =
|
|
182
|
+
const document = (0, import_echo_schema.createMutableSchema)({
|
|
183
|
+
typename: "example.com/type/document",
|
|
184
|
+
version: "0.1.0"
|
|
185
|
+
}, {
|
|
200
186
|
title: import_echo_schema.S.String.annotations({
|
|
201
187
|
description: "title of the document"
|
|
202
188
|
}),
|
|
203
189
|
content: import_echo_schema.S.String
|
|
204
190
|
});
|
|
205
|
-
const organization =
|
|
191
|
+
const organization = (0, import_echo_schema.createMutableSchema)({
|
|
192
|
+
typename: "example.com/type/organization",
|
|
193
|
+
version: "0.1.0"
|
|
194
|
+
}, {
|
|
206
195
|
name: import_echo_schema.S.String.annotations({
|
|
207
196
|
description: "name of the company or organization"
|
|
208
197
|
}),
|
|
@@ -213,7 +202,10 @@ var testSchemas = () => {
|
|
|
213
202
|
description: "short summary of the company"
|
|
214
203
|
})
|
|
215
204
|
});
|
|
216
|
-
const contact =
|
|
205
|
+
const contact = (0, import_echo_schema.createMutableSchema)({
|
|
206
|
+
typename: "example.com/type/contact",
|
|
207
|
+
version: "0.1.0"
|
|
208
|
+
}, {
|
|
217
209
|
name: import_echo_schema.S.String.annotations({
|
|
218
210
|
description: "name of the person"
|
|
219
211
|
}),
|
|
@@ -222,7 +214,10 @@ var testSchemas = () => {
|
|
|
222
214
|
lat: import_echo_schema.S.Number,
|
|
223
215
|
lng: import_echo_schema.S.Number
|
|
224
216
|
});
|
|
225
|
-
const project =
|
|
217
|
+
const project = (0, import_echo_schema.createMutableSchema)({
|
|
218
|
+
typename: "example.com/type/project",
|
|
219
|
+
version: "0.1.0"
|
|
220
|
+
}, {
|
|
226
221
|
name: import_echo_schema.S.String.annotations({
|
|
227
222
|
description: "name of the project"
|
|
228
223
|
}),
|
|
@@ -261,7 +256,7 @@ var testObjectGenerators = {
|
|
|
261
256
|
}),
|
|
262
257
|
["example.com/type/contact"]: async (provider) => {
|
|
263
258
|
const organizations = await provider?.("example.com/type/organization");
|
|
264
|
-
const location = import_random.faker.datatype.boolean() ? import_random.faker.
|
|
259
|
+
const { location } = import_random.faker.datatype.boolean() ? import_random.faker.geo.airport() : {};
|
|
265
260
|
return {
|
|
266
261
|
name: import_random.faker.person.fullName(),
|
|
267
262
|
email: import_random.faker.datatype.boolean({
|
|
@@ -307,408 +302,6 @@ var testObjectMutators = {
|
|
|
307
302
|
};
|
|
308
303
|
var createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);
|
|
309
304
|
var createSpaceObjectGenerator = (space) => new SpaceObjectGenerator(space, testSchemas(), testObjectGenerators, testObjectMutators);
|
|
310
|
-
var locations = [
|
|
311
|
-
{
|
|
312
|
-
lat: 139.74946157054467,
|
|
313
|
-
lng: 35.686962764371174
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
lat: -73.98196278740681,
|
|
317
|
-
lng: 40.75192492259464
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
lat: -99.1329340602939,
|
|
321
|
-
lng: 19.444388301415472
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
lat: 72.85504343876647,
|
|
325
|
-
lng: 19.0189362343566
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
lat: -46.62696583905523,
|
|
329
|
-
lng: -23.55673372837896
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
lat: 77.22805816860182,
|
|
333
|
-
lng: 28.671938757181522
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
lat: 121.43455881982015,
|
|
337
|
-
lng: 31.218398311228327
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
lat: 88.32272979950551,
|
|
341
|
-
lng: 22.49691515689642
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
lat: 90.40663360810754,
|
|
345
|
-
lng: 23.725005570312817
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
lat: -58.399477232331435,
|
|
349
|
-
lng: -34.600555749907414
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
lat: -118.18192636994041,
|
|
353
|
-
lng: 33.99192410876543
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
lat: 66.98806305137339,
|
|
357
|
-
lng: 24.87193814681484
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
lat: 31.248022361126118,
|
|
361
|
-
lng: 30.051906205103705
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
lat: -43.22696665284366,
|
|
365
|
-
lng: -22.923077315615956
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
lat: 135.4581989565952,
|
|
369
|
-
lng: 34.75198107491417
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
lat: 116.38633982565943,
|
|
373
|
-
lng: 39.93083808990906
|
|
374
|
-
},
|
|
375
|
-
{
|
|
376
|
-
lat: 120.9802713035424,
|
|
377
|
-
lng: 14.606104813440538
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
lat: 37.6135769672714,
|
|
381
|
-
lng: 55.75410998124818
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
lat: 29.008055727002613,
|
|
385
|
-
lng: 41.10694201243979
|
|
386
|
-
},
|
|
387
|
-
{
|
|
388
|
-
lat: 2.33138946713035,
|
|
389
|
-
lng: 48.86863878981461
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
lat: 126.99778513820195,
|
|
393
|
-
lng: 37.56829495838895
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
lat: 3.3895852125984334,
|
|
397
|
-
lng: 6.445207512093191
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
lat: 106.82749176247012,
|
|
401
|
-
lng: -6.172471846798885
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
lat: -87.75200083270931,
|
|
405
|
-
lng: 41.83193651927843
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
lat: 113.32306427226172,
|
|
409
|
-
lng: 23.14692716047989
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
lat: -0.11866770247593195,
|
|
413
|
-
lng: 51.5019405883275
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
lat: -77.05200795343472,
|
|
417
|
-
lng: -12.04606681752557
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
lat: 51.42239817500899,
|
|
421
|
-
lng: 35.673888627001304
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
lat: 15.313026023171744,
|
|
425
|
-
lng: -4.327778243275986
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
lat: -74.08528981377441,
|
|
429
|
-
lng: 4.598369421147822
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
lat: 114.1201772298325,
|
|
433
|
-
lng: 22.554316369677963
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
lat: 114.26807118958311,
|
|
437
|
-
lng: 30.581977209337822
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
lat: 114.18306345846304,
|
|
441
|
-
lng: 22.30692675357551
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
lat: 117.19807322410043,
|
|
445
|
-
lng: 39.13197212310894
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
lat: 80.27805287890033,
|
|
449
|
-
lng: 13.091933670856292
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
lat: 121.568333333333,
|
|
453
|
-
lng: 25.0358333333333
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
lat: 77.55806386521755,
|
|
457
|
-
lng: 12.97194099507442
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
lat: 100.51469879369489,
|
|
461
|
-
lng: 13.751945064087977
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
lat: 74.34807892054346,
|
|
465
|
-
lng: 31.56191739488844
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
lat: 106.59303578916195,
|
|
469
|
-
lng: 29.566922888044644
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
lat: 78.47800771287751,
|
|
473
|
-
lng: 17.401928991511454
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
lat: -70.66898671317483,
|
|
477
|
-
lng: -33.448067956934096
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
lat: -80.22605193945003,
|
|
481
|
-
lng: 25.789556555021534
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
lat: -43.916950376804834,
|
|
485
|
-
lng: -19.91308016391116
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
lat: -3.6852975446125242,
|
|
489
|
-
lng: 40.40197212311381
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
lat: -75.17194183200792,
|
|
493
|
-
lng: 40.001919022526465
|
|
494
|
-
},
|
|
495
|
-
{
|
|
496
|
-
lat: 72.57805776168215,
|
|
497
|
-
lng: 23.031998775062675
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
lat: 106.69308136207889,
|
|
501
|
-
lng: 10.781971309193409
|
|
502
|
-
},
|
|
503
|
-
{
|
|
504
|
-
lat: -79.42196665298843,
|
|
505
|
-
lng: 43.70192573640844
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
lat: 103.85387481909902,
|
|
509
|
-
lng: 1.2949793251059418
|
|
510
|
-
},
|
|
511
|
-
{
|
|
512
|
-
lat: 13.23248118266855,
|
|
513
|
-
lng: -8.836340255012658
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
lat: 44.391922914564134,
|
|
517
|
-
lng: 33.34059435615865
|
|
518
|
-
},
|
|
519
|
-
{
|
|
520
|
-
lat: 2.181424460619155,
|
|
521
|
-
lng: 41.385245438547486
|
|
522
|
-
},
|
|
523
|
-
{
|
|
524
|
-
lat: 88.32994665421205,
|
|
525
|
-
lng: 22.580390440861947
|
|
526
|
-
},
|
|
527
|
-
{
|
|
528
|
-
lat: -96.84196278749818,
|
|
529
|
-
lng: 32.82196968167733
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
lat: 123.44802765120869,
|
|
533
|
-
lng: 41.80692512604918
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
lat: 32.532233380011576,
|
|
537
|
-
lng: 15.590024084277673
|
|
538
|
-
},
|
|
539
|
-
{
|
|
540
|
-
lat: 73.84805776168719,
|
|
541
|
-
lng: 18.531963374654026
|
|
542
|
-
},
|
|
543
|
-
{
|
|
544
|
-
lat: 151.1832339501475,
|
|
545
|
-
lng: -33.91806510862875
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
lat: 30.314074200315076,
|
|
549
|
-
lng: 59.94096036375191
|
|
550
|
-
},
|
|
551
|
-
{
|
|
552
|
-
lat: 91.79802154756635,
|
|
553
|
-
lng: 22.33193814680459
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
lat: 113.74277634138707,
|
|
557
|
-
lng: 23.050834758613007
|
|
558
|
-
},
|
|
559
|
-
{
|
|
560
|
-
lat: -84.40189524187565,
|
|
561
|
-
lng: 33.83195971260585
|
|
562
|
-
},
|
|
563
|
-
{
|
|
564
|
-
lat: -71.07195953218684,
|
|
565
|
-
lng: 42.33190600170229
|
|
566
|
-
},
|
|
567
|
-
{
|
|
568
|
-
lat: 46.770795798688255,
|
|
569
|
-
lng: 24.642779007816443
|
|
570
|
-
},
|
|
571
|
-
{
|
|
572
|
-
lat: -95.341925149146,
|
|
573
|
-
lng: 29.821920243188856
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
lat: 105.8480683412422,
|
|
577
|
-
lng: 21.035273107737055
|
|
578
|
-
},
|
|
579
|
-
{
|
|
580
|
-
lat: -77.01136443943716,
|
|
581
|
-
lng: 38.901495235087054
|
|
582
|
-
},
|
|
583
|
-
{
|
|
584
|
-
lat: -103.33198008081848,
|
|
585
|
-
lng: 20.671961950508944
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
lat: 144.97307037590406,
|
|
589
|
-
lng: -37.81808545369631
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
lat: 29.948050030391755,
|
|
593
|
-
lng: 31.201965205759393
|
|
594
|
-
},
|
|
595
|
-
{
|
|
596
|
-
lat: 104.06807363094873,
|
|
597
|
-
lng: 30.671945877957796
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
lat: -83.0820016464927,
|
|
601
|
-
lng: 42.33190600170229
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
lat: 96.16473175266185,
|
|
605
|
-
lng: 16.785299963188777
|
|
606
|
-
},
|
|
607
|
-
{
|
|
608
|
-
lat: 108.89305043760862,
|
|
609
|
-
lng: 34.27697130928732
|
|
610
|
-
},
|
|
611
|
-
{
|
|
612
|
-
lat: -51.20195790450316,
|
|
613
|
-
lng: -30.048068770722466
|
|
614
|
-
},
|
|
615
|
-
{
|
|
616
|
-
lat: 121.465,
|
|
617
|
-
lng: 25.0127777777778
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
lat: 72.83809356897484,
|
|
621
|
-
lng: 21.20192960187819
|
|
622
|
-
},
|
|
623
|
-
{
|
|
624
|
-
lat: 109.60911291406296,
|
|
625
|
-
lng: 23.09653464659317
|
|
626
|
-
},
|
|
627
|
-
{
|
|
628
|
-
lat: -4.041994118507091,
|
|
629
|
-
lng: 5.321942826098564
|
|
630
|
-
},
|
|
631
|
-
{
|
|
632
|
-
lat: -47.91799814700306,
|
|
633
|
-
lng: -15.781394372878992
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
lat: 32.862445782356644,
|
|
637
|
-
lng: 39.929184444075474
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
lat: -100.33193064232995,
|
|
641
|
-
lng: 25.671940995125283
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
lat: 139.60202098994017,
|
|
645
|
-
lng: 35.43065615270891
|
|
646
|
-
},
|
|
647
|
-
{
|
|
648
|
-
lat: 118.77802846499208,
|
|
649
|
-
lng: 32.05196500231233
|
|
650
|
-
},
|
|
651
|
-
{
|
|
652
|
-
lat: -73.58524281670213,
|
|
653
|
-
lng: 45.50194506421502
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
lat: 106.7180927553083,
|
|
657
|
-
lng: 26.581988806001448
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
lat: -34.91755136960728,
|
|
661
|
-
lng: -8.073699467249241
|
|
662
|
-
},
|
|
663
|
-
{
|
|
664
|
-
lat: 126.64803904445057,
|
|
665
|
-
lng: 45.75192980542715
|
|
666
|
-
},
|
|
667
|
-
{
|
|
668
|
-
lat: -38.58192718342411,
|
|
669
|
-
lng: -3.7480720258257634
|
|
670
|
-
},
|
|
671
|
-
{
|
|
672
|
-
lat: -112.07193755969467,
|
|
673
|
-
lng: 33.5419257363676
|
|
674
|
-
},
|
|
675
|
-
{
|
|
676
|
-
lat: 117.67001623440774,
|
|
677
|
-
lng: 24.520375385531167
|
|
678
|
-
},
|
|
679
|
-
{
|
|
680
|
-
lat: -38.48193328693924,
|
|
681
|
-
lng: -12.968026046044827
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
lat: 129.00810170722048,
|
|
685
|
-
lng: 35.09699877511093
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
lat: -122.41716877355225,
|
|
689
|
-
lng: 37.76919562968743
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
lat: 28.028063865019476,
|
|
693
|
-
lng: -26.16809888138414
|
|
694
|
-
},
|
|
695
|
-
{
|
|
696
|
-
lat: 13.399602764700546,
|
|
697
|
-
lng: 52.523764522251156
|
|
698
|
-
},
|
|
699
|
-
{
|
|
700
|
-
lat: 3.048606670909237,
|
|
701
|
-
lng: 36.765010656628135
|
|
702
|
-
},
|
|
703
|
-
{
|
|
704
|
-
lat: 125.75274485499392,
|
|
705
|
-
lng: 39.02138455800434
|
|
706
|
-
},
|
|
707
|
-
{
|
|
708
|
-
lat: 12.481312562873995,
|
|
709
|
-
lng: 41.89790148509894
|
|
710
|
-
}
|
|
711
|
-
];
|
|
712
305
|
// Annotate the CommonJS export names for ESM import in node:
|
|
713
306
|
0 && (module.exports = {
|
|
714
307
|
Priority,
|
|
@@ -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 {\n createStoredSchema,\n getObjectAnnotation,\n ref,\n toJsonSchema,\n EchoObject,\n MutableSchema,\n ObjectAnnotationId,\n S,\n} from '@dxos/echo-schema';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestMutationsMap, type TestGeneratorMap, 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 createDynamicSchema = (typename: string, fields: S.Struct.Fields): MutableSchema => {\n const typeSchema = S.partial(S.Struct(fields)).pipe(EchoObject(typename, '1.0.0'));\n const typeAnnotation = getObjectAnnotation(typeSchema);\n const schemaToStore = createStoredSchema({ typename, version: '0.1.0' });\n const updatedSchema = typeSchema.annotations({\n [ObjectAnnotationId]: { ...typeAnnotation, schemaId: schemaToStore.id },\n });\n schemaToStore.jsonSchema = toJsonSchema(updatedSchema);\n return new MutableSchema(schemaToStore);\n};\n\nconst testSchemas = (): TestSchemaMap<TestSchemaType> => {\n const document = createDynamicSchema(TestSchemaType.document, {\n title: S.String.annotations({ description: 'title of the document' }),\n content: S.String,\n });\n\n const organization = createDynamicSchema(TestSchemaType.organization, {\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 const contact = createDynamicSchema(TestSchemaType.contact, {\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 const project = createDynamicSchema(TestSchemaType.project, {\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 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.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]: 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// TODO(burdon): Move to @dxos/random.\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 { type Space, Filter } from '@dxos/client/echo';\nimport { type EchoReactiveObject } from '@dxos/echo-db';\nimport {\n create,\n MutableSchema,\n type ReactiveObject,\n getObjectAnnotation,\n getSchema,\n isReactiveObject,\n type S,\n} from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { faker } from '@dxos/random';\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';\nimport { range } from './util';\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): Create batch.\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(() => this.createObject({ types: [type as T] }), count);\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<EchoReactiveObject<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: EchoReactiveObject<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;\n }\n\n async mutateObjects(objects: EchoReactiveObject<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\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\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 return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAA0B;AAC1B,kBAA8C;AAC9C,
|
|
6
|
-
"names": ["import_echo", "import_echo_schema", "import_random", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "randomText", "result", "characters", "charactersLength", "index", "charAt", "Math", "floor", "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", "tasks", "entries", "count", "flatMap", "t", "Promise", "all", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "_mutations", "db", "query", "Filter", "run", "objects", "forEach", "dynamicSchema", "_maybeRegisterSchema", "addSchemas", "push", "add", "MutableSchema", "existingSchema", "schemaRegistry", "storedSchema", "registerSchema", "graph", "addSchema", "mutateObject", "object", "params", "invariant", "mutateObjects", "Status", "Priority", "TestSchemaType", "
|
|
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 { createMutableSchema, ref, S } from '@dxos/echo-schema';\nimport { faker } from '@dxos/random';\n\nimport { SpaceObjectGenerator, TestObjectGenerator } from './generator';\nimport { type TestMutationsMap, type TestGeneratorMap, 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 { type Space, Filter } from '@dxos/client/echo';\nimport { type ReactiveEchoObject } from '@dxos/echo-db';\nimport {\n create,\n getObjectAnnotation,\n getSchema,\n isReactiveObject,\n MutableSchema,\n type ReactiveObject,\n type S,\n} from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { faker } from '@dxos/random';\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';\nimport { range } from './util';\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(() => this.createObject({ types: [type as T] }), count);\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;\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\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\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};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uD;EAC3D,CAAA,2BAAA,GAA2B,OAAOxD,QAAQC,WAAAA;AACxC,UAAMwD,eAAWC,+BAAkB1D,QAAQ;MAAC;KAAU;AACtD,aAASpE,IAAI,GAAGA,IAAIqE,OAAO9B,OAAOvC,KAAK;AACrC,YAAML,SAASyE,OAAOgB,SAASA,SAASzF,UAAU;AAClDkI,eAASE,OAAOC,OAAO,CAACC,QAAAA;AACtBC,yBAAAA,KAAEC,OACAF,KACAJ,SAASO,KAAKC,MAAK,GACnB,GACAhE,OAAOiE,oBAAoB3I,SAAS,IAAI0E,OAAOkE,cAC/CpI,WAAWkE,OAAOkE,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,IAAI7H,oBAAoB+D,YAAAA,GAAeyB,oBAAAA;AAE/E,IAAMsC,6BAA6B,CAACC,UACzC,IAAI/F,qBAAqB+F,OAAOhE,YAAAA,GAAeyB,sBAAsBwB,kBAAAA;",
|
|
6
|
+
"names": ["import_echo", "import_echo_schema", "import_random", "range", "fn", "length", "Array", "from", "map", "_", "i", "filter", "Boolean", "randomText", "result", "characters", "charactersLength", "index", "charAt", "Math", "floor", "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", "tasks", "entries", "count", "flatMap", "t", "Promise", "all", "SpaceObjectGenerator", "_space", "schemaMap", "generators", "_mutations", "db", "query", "Filter", "run", "objects", "forEach", "dynamicSchema", "_maybeRegisterSchema", "addSchemas", "push", "add", "MutableSchema", "existingSchema", "schemaRegistry", "storedSchema", "registerSchema", "graph", "addSchema", "mutateObject", "object", "params", "invariant", "mutateObjects", "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", "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", "handle", "change", "doc", "A", "splice", "path", "slice", "maxContentLength", "mutationSize", "Error", "createTestObjectGenerator", "createSpaceObjectGenerator", "space"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/echo/echo-generator/src/util.ts":{"bytes":2293,"imports":[],"format":"esm"},"packages/core/echo/echo-generator/src/generator.ts":{"bytes":16430,"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/random","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":18451,"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/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":1681,"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":18619},"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/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/random","kind":"import-statement","external":true}],"exports":["Priority","SpaceObjectGenerator","Status","TestObjectGenerator","TestSchemaType","createSpaceObjectGenerator","createTestObjectGenerator","randomText","range"],"entryPoint":"packages/core/echo/echo-generator/src/index.ts","inputs":{"packages/core/echo/echo-generator/src/data.ts":{"bytesInOutput":4547},"packages/core/echo/echo-generator/src/generator.ts":{"bytesInOutput":3735},"packages/core/echo/echo-generator/src/util.ts":{"bytesInOutput":390},"packages/core/echo/echo-generator/src/index.ts":{"bytesInOutput":0}},"bytes":9146}}}
|