@dxos/echo-generator 0.7.1 → 0.7.2-main.f1adc9f

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.
@@ -25,8 +25,7 @@ __export(node_exports, {
25
25
  TestSchemaType: () => TestSchemaType,
26
26
  createSpaceObjectGenerator: () => createSpaceObjectGenerator,
27
27
  createTestObjectGenerator: () => createTestObjectGenerator,
28
- randomText: () => randomText,
29
- range: () => range
28
+ randomText: () => randomText
30
29
  });
31
30
  module.exports = __toCommonJS(node_exports);
32
31
  var import_automerge = require("@dxos/automerge/automerge");
@@ -37,18 +36,7 @@ var import_echo2 = require("@dxos/client/echo");
37
36
  var import_echo_schema2 = require("@dxos/echo-schema");
38
37
  var import_invariant = require("@dxos/invariant");
39
38
  var import_random2 = require("@dxos/random");
40
- var range = (fn, length) => Array.from({
41
- length
42
- }).map((_, i) => fn(i)).filter(Boolean);
43
- var randomText = (length) => {
44
- let result = "";
45
- const characters = "abcdefghijklmnopqrstuvwxyz";
46
- const charactersLength = characters.length;
47
- for (let index = 0; index < length; index++) {
48
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
49
- }
50
- return result;
51
- };
39
+ var import_util = require("@dxos/util");
52
40
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-generator/src/generator.ts";
53
41
  var TestObjectGenerator = class {
54
42
  // prettier-ignore
@@ -75,15 +63,14 @@ var TestObjectGenerator = class {
75
63
  const schema = this.getSchema(type);
76
64
  return schema ? (0, import_echo_schema2.create)(schema, data) : (0, import_echo_schema2.create)(data);
77
65
  }
78
- // TODO(burdon): Create batch.
79
66
  // TODO(burdon): Based on dependencies (e.g., organization before contact).
80
67
  async createObjects(map) {
81
68
  const tasks = Object.entries(map).map(([type, count]) => {
82
- return range(() => this.createObject({
69
+ return (0, import_util.range)(count, () => this.createObject({
83
70
  types: [
84
71
  type
85
72
  ]
86
- }), count);
73
+ }));
87
74
  }).flatMap((t) => t);
88
75
  return Promise.all(tasks);
89
76
  }
@@ -135,7 +122,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
135
122
  async mutateObject(object, params) {
136
123
  (0, import_invariant.invariant)(this._mutations, "Mutations not defined.", {
137
124
  F: __dxlog_file,
138
- L: 131,
125
+ L: 130,
139
126
  S: this,
140
127
  A: [
141
128
  "this._mutations",
@@ -145,7 +132,7 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
145
132
  const type = (0, import_echo_schema2.getObjectAnnotation)((0, import_echo_schema2.getSchema)(object)).typename;
146
133
  (0, import_invariant.invariant)(type && this._mutations?.[type], "Invalid object type.", {
147
134
  F: __dxlog_file,
148
- L: 133,
135
+ L: 132,
149
136
  S: this,
150
137
  A: [
151
138
  "type && this._mutations?.[type]",
@@ -160,6 +147,15 @@ var SpaceObjectGenerator = class extends TestObjectGenerator {
160
147
  }
161
148
  }
162
149
  };
150
+ var randomText = (length) => {
151
+ let result = "";
152
+ const characters = "abcdefghijklmnopqrstuvwxyz";
153
+ const charactersLength = characters.length;
154
+ for (let index = 0; index < length; index++) {
155
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
156
+ }
157
+ return result;
158
+ };
163
159
  var Status = [
164
160
  "pending",
165
161
  "active",
@@ -179,30 +175,20 @@ var TestSchemaType;
179
175
  TestSchemaType2["contact"] = "example.com/type/contact";
180
176
  TestSchemaType2["project"] = "example.com/type/project";
181
177
  })(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
178
  var testSchemas = () => {
199
- const document = createDynamicSchema("example.com/type/document", {
179
+ const document = (0, import_echo_schema.createMutableSchema)({
180
+ typename: "example.com/type/document",
181
+ version: "0.1.0"
182
+ }, {
200
183
  title: import_echo_schema.S.String.annotations({
201
184
  description: "title of the document"
202
185
  }),
203
186
  content: import_echo_schema.S.String
204
187
  });
205
- const organization = createDynamicSchema("example.com/type/organization", {
188
+ const organization = (0, import_echo_schema.createMutableSchema)({
189
+ typename: "example.com/type/organization",
190
+ version: "0.1.0"
191
+ }, {
206
192
  name: import_echo_schema.S.String.annotations({
207
193
  description: "name of the company or organization"
208
194
  }),
@@ -213,7 +199,10 @@ var testSchemas = () => {
213
199
  description: "short summary of the company"
214
200
  })
215
201
  });
216
- const contact = createDynamicSchema("example.com/type/contact", {
202
+ const contact = (0, import_echo_schema.createMutableSchema)({
203
+ typename: "example.com/type/contact",
204
+ version: "0.1.0"
205
+ }, {
217
206
  name: import_echo_schema.S.String.annotations({
218
207
  description: "name of the person"
219
208
  }),
@@ -222,7 +211,10 @@ var testSchemas = () => {
222
211
  lat: import_echo_schema.S.Number,
223
212
  lng: import_echo_schema.S.Number
224
213
  });
225
- const project = createDynamicSchema("example.com/type/project", {
214
+ const project = (0, import_echo_schema.createMutableSchema)({
215
+ typename: "example.com/type/project",
216
+ version: "0.1.0"
217
+ }, {
226
218
  name: import_echo_schema.S.String.annotations({
227
219
  description: "name of the project"
228
220
  }),
@@ -261,7 +253,7 @@ var testObjectGenerators = {
261
253
  }),
262
254
  ["example.com/type/contact"]: async (provider) => {
263
255
  const organizations = await provider?.("example.com/type/organization");
264
- const location = import_random.faker.datatype.boolean() ? import_random.faker.helpers.arrayElement(locations) : void 0;
256
+ const { location } = import_random.faker.datatype.boolean() ? import_random.faker.geo.airport() : {};
265
257
  return {
266
258
  name: import_random.faker.person.fullName(),
267
259
  email: import_random.faker.datatype.boolean({
@@ -307,408 +299,6 @@ var testObjectMutators = {
307
299
  };
308
300
  var createTestObjectGenerator = () => new TestObjectGenerator(testSchemas(), testObjectGenerators);
309
301
  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
302
  // Annotate the CommonJS export names for ESM import in node:
713
303
  0 && (module.exports = {
714
304
  Priority,
@@ -718,7 +308,6 @@ var locations = [
718
308
  TestSchemaType,
719
309
  createSpaceObjectGenerator,
720
310
  createTestObjectGenerator,
721
- randomText,
722
- range
311
+ randomText
723
312
  });
724
313
  //# sourceMappingURL=index.cjs.map