@eventcatalog/sdk 1.0.0 → 1.1.1

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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { join as join7 } from "node:path";
2
+ import { join as join8 } from "node:path";
3
3
 
4
4
  // src/events.ts
5
5
  import fs3 from "node:fs/promises";
@@ -208,9 +208,35 @@ var commandHasVersion = (directory) => async (id, version) => {
208
208
  return !!file;
209
209
  };
210
210
 
211
- // src/services.ts
211
+ // src/queries.ts
212
212
  import fs5 from "node:fs/promises";
213
- import { join as join5, dirname as dirname2 } from "node:path";
213
+ import { join as join5 } from "node:path";
214
+ var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
215
+ var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
216
+ var writeQueryToService = (directory) => async (query, service, options = { path: "" }) => {
217
+ let pathForQuery = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/queries` : `/${service.id}/queries`;
218
+ pathForQuery = join5(pathForQuery, query.id);
219
+ await writeResource(directory, { ...query }, { ...options, path: pathForQuery, type: "query" });
220
+ };
221
+ var rmQuery = (directory) => async (path) => {
222
+ await fs5.rm(join5(directory, path), { recursive: true });
223
+ };
224
+ var rmQueryById = (directory) => async (id, version) => {
225
+ await rmResourceById(directory, id, version, { type: "query" });
226
+ };
227
+ var versionQuery = (directory) => async (id) => versionResource(directory, id);
228
+ var addFileToQuery = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
229
+ var addSchemaToQuery = (directory) => async (id, schema, version) => {
230
+ await addFileToQuery(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);
231
+ };
232
+ var queryHasVersion = (directory) => async (id, version) => {
233
+ const file = await findFileById(directory, id, version);
234
+ return !!file;
235
+ };
236
+
237
+ // src/services.ts
238
+ import fs6 from "node:fs/promises";
239
+ import { join as join6, dirname as dirname2 } from "node:path";
214
240
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
215
241
  var writeService = (directory) => async (service, options = { path: "" }) => {
216
242
  const resource = { ...service };
@@ -224,12 +250,12 @@ var writeService = (directory) => async (service, options = { path: "" }) => {
224
250
  };
225
251
  var writeServiceToDomain = (directory) => async (service, domain, options = { path: "" }) => {
226
252
  let pathForService = domain.version && domain.version !== "latest" ? `/${domain.id}/versioned/${domain.version}/services` : `/${domain.id}/services`;
227
- pathForService = join5(pathForService, service.id);
253
+ pathForService = join6(pathForService, service.id);
228
254
  await writeResource(directory, { ...service }, { ...options, path: pathForService, type: "service" });
229
255
  };
230
256
  var versionService = (directory) => async (id) => versionResource(directory, id);
231
257
  var rmService = (directory) => async (path) => {
232
- await fs5.rm(join5(directory, path), { recursive: true });
258
+ await fs6.rm(join6(directory, path), { recursive: true });
233
259
  };
234
260
  var rmServiceById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "service" });
235
261
  var addFileToService = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -247,7 +273,7 @@ var getSpecificationFilesForService = (directory) => async (id, version) => {
247
273
  throw new Error(`Specification file name for ${specFile} is undefined`);
248
274
  }
249
275
  const rawFile = await getFileFromResource(directory, id, { fileName }, version);
250
- return { key: specFile, content: rawFile, fileName, path: join5(dirname2(filePathToService), fileName) };
276
+ return { key: specFile, content: rawFile, fileName, path: join6(dirname2(filePathToService), fileName) };
251
277
  });
252
278
  specs = await Promise.all(getSpecs);
253
279
  }
@@ -287,13 +313,13 @@ var serviceHasVersion = (directory) => async (id, version) => {
287
313
  };
288
314
 
289
315
  // src/domains.ts
290
- import fs6 from "node:fs/promises";
291
- import { join as join6 } from "node:path";
316
+ import fs7 from "node:fs/promises";
317
+ import { join as join7 } from "node:path";
292
318
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
293
319
  var writeDomain = (directory) => async (domain, options = { path: "" }) => writeResource(directory, { ...domain }, { ...options, type: "domain" });
294
320
  var versionDomain = (directory) => async (id) => versionResource(directory, id);
295
321
  var rmDomain = (directory) => async (path) => {
296
- await fs6.rm(join6(directory, path), { recursive: true });
322
+ await fs7.rm(join7(directory, path), { recursive: true });
297
323
  };
298
324
  var rmDomainById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "domain" });
299
325
  var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -324,7 +350,7 @@ var src_default = (path) => {
324
350
  * @param version - Optional id of the version to get (supports semver)
325
351
  * @returns Event|Undefined
326
352
  */
327
- getEvent: getEvent(join7(path)),
353
+ getEvent: getEvent(join8(path)),
328
354
  /**
329
355
  * Adds an event to EventCatalog
330
356
  *
@@ -332,7 +358,7 @@ var src_default = (path) => {
332
358
  * @param options - Optional options to write the event
333
359
  *
334
360
  */
335
- writeEvent: writeEvent(join7(path, "events")),
361
+ writeEvent: writeEvent(join8(path, "events")),
336
362
  /**
337
363
  * Adds an event to a service in EventCatalog
338
364
  *
@@ -341,26 +367,26 @@ var src_default = (path) => {
341
367
  * @param options - Optional options to write the event
342
368
  *
343
369
  */
344
- writeEventToService: writeEventToService(join7(path, "services")),
370
+ writeEventToService: writeEventToService(join8(path, "services")),
345
371
  /**
346
372
  * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
347
373
  *
348
374
  * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
349
375
  *
350
376
  */
351
- rmEvent: rmEvent(join7(path, "events")),
377
+ rmEvent: rmEvent(join8(path, "events")),
352
378
  /**
353
379
  * Remove an event by an Event id
354
380
  *
355
381
  * @param id - The id of the event you want to remove
356
382
  *
357
383
  */
358
- rmEventById: rmEventById(join7(path)),
384
+ rmEventById: rmEventById(join8(path)),
359
385
  /**
360
386
  * Moves a given event id to the version directory
361
387
  * @param directory
362
388
  */
363
- versionEvent: versionEvent(join7(path)),
389
+ versionEvent: versionEvent(join8(path)),
364
390
  /**
365
391
  * Adds a file to the given event
366
392
  * @param id - The id of the event to add the file to
@@ -368,7 +394,7 @@ var src_default = (path) => {
368
394
  * @param version - Optional version of the event to add the file to
369
395
  * @returns
370
396
  */
371
- addFileToEvent: addFileToEvent(join7(path)),
397
+ addFileToEvent: addFileToEvent(join8(path)),
372
398
  /**
373
399
  * Adds a schema to the given event
374
400
  * @param id - The id of the event to add the schema to
@@ -376,14 +402,14 @@ var src_default = (path) => {
376
402
  * @param version - Optional version of the event to add the schema to
377
403
  * @returns
378
404
  */
379
- addSchemaToEvent: addSchemaToEvent(join7(path)),
405
+ addSchemaToEvent: addSchemaToEvent(join8(path)),
380
406
  /**
381
407
  * Check to see if an event version exists
382
408
  * @param id - The id of the event
383
409
  * @param version - The version of the event (supports semver)
384
410
  * @returns
385
411
  */
386
- eventHasVersion: eventHasVersion(join7(path)),
412
+ eventHasVersion: eventHasVersion(join8(path)),
387
413
  /**
388
414
  * ================================
389
415
  * Commands
@@ -395,7 +421,7 @@ var src_default = (path) => {
395
421
  * @param version - Optional id of the version to get (supports semver)
396
422
  * @returns Command|Undefined
397
423
  */
398
- getCommand: getCommand(join7(path)),
424
+ getCommand: getCommand(join8(path)),
399
425
  /**
400
426
  * Adds an command to EventCatalog
401
427
  *
@@ -403,7 +429,7 @@ var src_default = (path) => {
403
429
  * @param options - Optional options to write the command
404
430
  *
405
431
  */
406
- writeCommand: writeCommand(join7(path, "commands")),
432
+ writeCommand: writeCommand(join8(path, "commands")),
407
433
  /**
408
434
  * Adds a command to a service in EventCatalog
409
435
  *
@@ -412,26 +438,26 @@ var src_default = (path) => {
412
438
  * @param options - Optional options to write the command
413
439
  *
414
440
  */
415
- writeCommandToService: writeCommandToService(join7(path, "services")),
441
+ writeCommandToService: writeCommandToService(join8(path, "services")),
416
442
  /**
417
443
  * Remove an command to EventCatalog (modeled on the standard POSIX rm utility)
418
444
  *
419
445
  * @param path - The path to your command, e.g. `/Inventory/InventoryAdjusted`
420
446
  *
421
447
  */
422
- rmCommand: rmCommand(join7(path, "commands")),
448
+ rmCommand: rmCommand(join8(path, "commands")),
423
449
  /**
424
450
  * Remove an command by an Event id
425
451
  *
426
452
  * @param id - The id of the command you want to remove
427
453
  *
428
454
  */
429
- rmCommandById: rmCommandById(join7(path)),
455
+ rmCommandById: rmCommandById(join8(path)),
430
456
  /**
431
457
  * Moves a given command id to the version directory
432
458
  * @param directory
433
459
  */
434
- versionCommand: versionCommand(join7(path)),
460
+ versionCommand: versionCommand(join8(path)),
435
461
  /**
436
462
  * Adds a file to the given command
437
463
  * @param id - The id of the command to add the file to
@@ -439,7 +465,7 @@ var src_default = (path) => {
439
465
  * @param version - Optional version of the command to add the file to
440
466
  * @returns
441
467
  */
442
- addFileToCommand: addFileToCommand(join7(path)),
468
+ addFileToCommand: addFileToCommand(join8(path)),
443
469
  /**
444
470
  * Adds a schema to the given command
445
471
  * @param id - The id of the command to add the schema to
@@ -447,14 +473,85 @@ var src_default = (path) => {
447
473
  * @param version - Optional version of the command to add the schema to
448
474
  * @returns
449
475
  */
450
- addSchemaToCommand: addSchemaToCommand(join7(path)),
476
+ addSchemaToCommand: addSchemaToCommand(join8(path)),
451
477
  /**
452
478
  * Check to see if a command version exists
453
479
  * @param id - The id of the command
454
480
  * @param version - The version of the command (supports semver)
455
481
  * @returns
456
482
  */
457
- commandHasVersion: commandHasVersion(join7(path)),
483
+ commandHasVersion: commandHasVersion(join8(path)),
484
+ /**
485
+ * ================================
486
+ * Queries
487
+ * ================================
488
+ */
489
+ /**
490
+ * Returns a query from EventCatalog
491
+ * @param id - The id of the query to retrieve
492
+ * @param version - Optional id of the version to get (supports semver)
493
+ * @returns Query|Undefined
494
+ */
495
+ getQuery: getQuery(join8(path)),
496
+ /**
497
+ * Adds a query to EventCatalog
498
+ *
499
+ * @param query - The query to write
500
+ * @param options - Optional options to write the event
501
+ *
502
+ */
503
+ writeQuery: writeQuery(join8(path, "queries")),
504
+ /**
505
+ * Adds a query to a service in EventCatalog
506
+ *
507
+ * @param query - The query to write to the service
508
+ * @param service - The service and it's id to write to the query to
509
+ * @param options - Optional options to write the query
510
+ *
511
+ */
512
+ writeQueryToService: writeQueryToService(join8(path, "services")),
513
+ /**
514
+ * Remove an query to EventCatalog (modeled on the standard POSIX rm utility)
515
+ *
516
+ * @param path - The path to your query, e.g. `/Orders/GetOrder`
517
+ *
518
+ */
519
+ rmQuery: rmQuery(join8(path, "queries")),
520
+ /**
521
+ * Remove a query by a Query id
522
+ *
523
+ * @param id - The id of the query you want to remove
524
+ *
525
+ */
526
+ rmQueryById: rmQueryById(join8(path)),
527
+ /**
528
+ * Moves a given query id to the version directory
529
+ * @param directory
530
+ */
531
+ versionQuery: versionQuery(join8(path)),
532
+ /**
533
+ * Adds a file to the given query
534
+ * @param id - The id of the query to add the file to
535
+ * @param file - File contents to add including the content and the file name
536
+ * @param version - Optional version of the query to add the file to
537
+ * @returns
538
+ */
539
+ addFileToQuery: addFileToQuery(join8(path)),
540
+ /**
541
+ * Adds a schema to the given query
542
+ * @param id - The id of the query to add the schema to
543
+ * @param schema - Schema contents to add including the content and the file name
544
+ * @param version - Optional version of the query to add the schema to
545
+ * @returns
546
+ */
547
+ addSchemaToQuery: addSchemaToQuery(join8(path)),
548
+ /**
549
+ * Check to see if an query version exists
550
+ * @param id - The id of the query
551
+ * @param version - The version of the query (supports semver)
552
+ * @returns
553
+ */
554
+ queryHasVersion: queryHasVersion(join8(path)),
458
555
  /**
459
556
  * ================================
460
557
  * SERVICES
@@ -467,7 +564,7 @@ var src_default = (path) => {
467
564
  * @param options - Optional options to write the event
468
565
  *
469
566
  */
470
- writeService: writeService(join7(path, "services")),
567
+ writeService: writeService(join8(path, "services")),
471
568
  /**
472
569
  * Adds a service to a domain in EventCatalog
473
570
  *
@@ -476,33 +573,33 @@ var src_default = (path) => {
476
573
  * @param options - Optional options to write the event
477
574
  *
478
575
  */
479
- writeServiceToDomain: writeServiceToDomain(join7(path, "domains")),
576
+ writeServiceToDomain: writeServiceToDomain(join8(path, "domains")),
480
577
  /**
481
578
  * Returns a service from EventCatalog
482
579
  * @param id - The id of the service to retrieve
483
580
  * @param version - Optional id of the version to get (supports semver)
484
581
  * @returns Service|Undefined
485
582
  */
486
- getService: getService(join7(path)),
583
+ getService: getService(join8(path)),
487
584
  /**
488
585
  * Moves a given service id to the version directory
489
586
  * @param directory
490
587
  */
491
- versionService: versionService(join7(path)),
588
+ versionService: versionService(join8(path)),
492
589
  /**
493
590
  * Remove a service from EventCatalog (modeled on the standard POSIX rm utility)
494
591
  *
495
592
  * @param path - The path to your service, e.g. `/InventoryService`
496
593
  *
497
594
  */
498
- rmService: rmService(join7(path, "services")),
595
+ rmService: rmService(join8(path, "services")),
499
596
  /**
500
597
  * Remove an service by an service id
501
598
  *
502
599
  * @param id - The id of the service you want to remove
503
600
  *
504
601
  */
505
- rmServiceById: rmServiceById(join7(path)),
602
+ rmServiceById: rmServiceById(join8(path)),
506
603
  /**
507
604
  * Adds a file to the given service
508
605
  * @param id - The id of the service to add the file to
@@ -510,21 +607,21 @@ var src_default = (path) => {
510
607
  * @param version - Optional version of the service to add the file to
511
608
  * @returns
512
609
  */
513
- addFileToService: addFileToService(join7(path)),
610
+ addFileToService: addFileToService(join8(path)),
514
611
  /**
515
612
  * Returns the specifications for a given service
516
613
  * @param id - The id of the service to retrieve the specifications for
517
614
  * @param version - Optional version of the service
518
615
  * @returns
519
616
  */
520
- getSpecificationFilesForService: getSpecificationFilesForService(join7(path)),
617
+ getSpecificationFilesForService: getSpecificationFilesForService(join8(path)),
521
618
  /**
522
619
  * Check to see if a service version exists
523
620
  * @param id - The id of the service
524
621
  * @param version - The version of the service (supports semver)
525
622
  * @returns
526
623
  */
527
- serviceHasVersion: serviceHasVersion(join7(path)),
624
+ serviceHasVersion: serviceHasVersion(join8(path)),
528
625
  /**
529
626
  * ================================
530
627
  * Domains
@@ -537,33 +634,33 @@ var src_default = (path) => {
537
634
  * @param options - Optional options to write the event
538
635
  *
539
636
  */
540
- writeDomain: writeDomain(join7(path, "domains")),
637
+ writeDomain: writeDomain(join8(path, "domains")),
541
638
  /**
542
639
  * Returns a domain from EventCatalog
543
640
  * @param id - The id of the domain to retrieve
544
641
  * @param version - Optional id of the version to get (supports semver)
545
642
  * @returns Domain|Undefined
546
643
  */
547
- getDomain: getDomain(join7(path, "domains")),
644
+ getDomain: getDomain(join8(path, "domains")),
548
645
  /**
549
646
  * Moves a given domain id to the version directory
550
647
  * @param directory
551
648
  */
552
- versionDomain: versionDomain(join7(path, "domains")),
649
+ versionDomain: versionDomain(join8(path, "domains")),
553
650
  /**
554
651
  * Remove a domain from EventCatalog (modeled on the standard POSIX rm utility)
555
652
  *
556
653
  * @param path - The path to your domain, e.g. `/Payment`
557
654
  *
558
655
  */
559
- rmDomain: rmDomain(join7(path, "domains")),
656
+ rmDomain: rmDomain(join8(path, "domains")),
560
657
  /**
561
658
  * Remove an service by an domain id
562
659
  *
563
660
  * @param id - The id of the domain you want to remove
564
661
  *
565
662
  */
566
- rmDomainById: rmDomainById(join7(path, "domains")),
663
+ rmDomainById: rmDomainById(join8(path, "domains")),
567
664
  /**
568
665
  * Adds a file to the given domain
569
666
  * @param id - The id of the domain to add the file to
@@ -571,7 +668,7 @@ var src_default = (path) => {
571
668
  * @param version - Optional version of the domain to add the file to
572
669
  * @returns
573
670
  */
574
- addFileToDomain: addFileToDomain(join7(path, "domains")),
671
+ addFileToDomain: addFileToDomain(join8(path, "domains")),
575
672
  /**
576
673
  * Add an event to a service by it's id.
577
674
  *
@@ -591,7 +688,7 @@ var src_default = (path) => {
591
688
  *
592
689
  * ```
593
690
  */
594
- addEventToService: addMessageToService(join7(path)),
691
+ addEventToService: addMessageToService(join8(path)),
595
692
  /**
596
693
  * Add a command to a service by it's id.
597
694
  *
@@ -611,14 +708,14 @@ var src_default = (path) => {
611
708
  *
612
709
  * ```
613
710
  */
614
- addCommandToService: addMessageToService(join7(path)),
711
+ addCommandToService: addMessageToService(join8(path)),
615
712
  /**
616
713
  * Check to see if a domain version exists
617
714
  * @param id - The id of the domain
618
715
  * @param version - The version of the domain (supports semver)
619
716
  * @returns
620
717
  */
621
- domainHasVersion: domainHasVersion(join7(path)),
718
+ domainHasVersion: domainHasVersion(join8(path)),
622
719
  /**
623
720
  * Adds a given service to a domain
624
721
  * @param id - The id of the domain
@@ -626,7 +723,7 @@ var src_default = (path) => {
626
723
  * @param version - (Optional) The version of the domain to add the service to
627
724
  * @returns
628
725
  */
629
- addServiceToDomain: addServiceToDomain(join7(path, "domains"))
726
+ addServiceToDomain: addServiceToDomain(join8(path, "domains"))
630
727
  };
631
728
  };
632
729
  export {