@eventcatalog/sdk 0.1.4 → 1.1.0

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";
@@ -163,10 +163,17 @@ var getFileFromResource = async (catalogDir, id, file, version) => {
163
163
  // src/events.ts
164
164
  var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
165
165
  var writeEvent = (directory) => async (event, options = { path: "" }) => writeResource(directory, { ...event }, { ...options, type: "event" });
166
+ var writeEventToService = (directory) => async (event, service, options = { path: "" }) => {
167
+ let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/events` : `/${service.id}/events`;
168
+ pathForEvent = join3(pathForEvent, event.id);
169
+ await writeResource(directory, { ...event }, { ...options, path: pathForEvent, type: "event" });
170
+ };
166
171
  var rmEvent = (directory) => async (path) => {
167
172
  await fs3.rm(join3(directory, path), { recursive: true });
168
173
  };
169
- var rmEventById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "event" });
174
+ var rmEventById = (directory) => async (id, version) => {
175
+ await rmResourceById(directory, id, version, { type: "event" });
176
+ };
170
177
  var versionEvent = (directory) => async (id) => versionResource(directory, id);
171
178
  var addFileToEvent = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
172
179
  var addSchemaToEvent = (directory) => async (id, schema, version) => {
@@ -182,6 +189,11 @@ import fs4 from "node:fs/promises";
182
189
  import { join as join4 } from "node:path";
183
190
  var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
184
191
  var writeCommand = (directory) => async (command, options = { path: "" }) => writeResource(directory, { ...command }, { ...options, type: "command" });
192
+ var writeCommandToService = (directory) => async (command, service, options = { path: "" }) => {
193
+ let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/commands` : `/${service.id}/commands`;
194
+ pathForEvent = join4(pathForEvent, command.id);
195
+ await writeResource(directory, { ...command }, { ...options, path: pathForEvent, type: "command" });
196
+ };
185
197
  var rmCommand = (directory) => async (path) => {
186
198
  await fs4.rm(join4(directory, path), { recursive: true });
187
199
  };
@@ -196,9 +208,35 @@ var commandHasVersion = (directory) => async (id, version) => {
196
208
  return !!file;
197
209
  };
198
210
 
199
- // src/services.ts
211
+ // src/queries.ts
200
212
  import fs5 from "node:fs/promises";
201
- 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";
202
240
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
203
241
  var writeService = (directory) => async (service, options = { path: "" }) => {
204
242
  const resource = { ...service };
@@ -210,9 +248,14 @@ var writeService = (directory) => async (service, options = { path: "" }) => {
210
248
  }
211
249
  return writeResource(directory, resource, { ...options, type: "service" });
212
250
  };
251
+ var writeServiceToDomain = (directory) => async (service, domain, options = { path: "" }) => {
252
+ let pathForService = domain.version && domain.version !== "latest" ? `/${domain.id}/versioned/${domain.version}/services` : `/${domain.id}/services`;
253
+ pathForService = join6(pathForService, service.id);
254
+ await writeResource(directory, { ...service }, { ...options, path: pathForService, type: "service" });
255
+ };
213
256
  var versionService = (directory) => async (id) => versionResource(directory, id);
214
257
  var rmService = (directory) => async (path) => {
215
- await fs5.rm(join5(directory, path), { recursive: true });
258
+ await fs6.rm(join6(directory, path), { recursive: true });
216
259
  };
217
260
  var rmServiceById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "service" });
218
261
  var addFileToService = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -230,7 +273,7 @@ var getSpecificationFilesForService = (directory) => async (id, version) => {
230
273
  throw new Error(`Specification file name for ${specFile} is undefined`);
231
274
  }
232
275
  const rawFile = await getFileFromResource(directory, id, { fileName }, version);
233
- return { key: specFile, content: rawFile, fileName, path: join5(dirname2(filePathToService), fileName) };
276
+ return { key: specFile, content: rawFile, fileName, path: join6(dirname2(filePathToService), fileName) };
234
277
  });
235
278
  specs = await Promise.all(getSpecs);
236
279
  }
@@ -270,13 +313,13 @@ var serviceHasVersion = (directory) => async (id, version) => {
270
313
  };
271
314
 
272
315
  // src/domains.ts
273
- import fs6 from "node:fs/promises";
274
- import { join as join6 } from "node:path";
316
+ import fs7 from "node:fs/promises";
317
+ import { join as join7 } from "node:path";
275
318
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
276
319
  var writeDomain = (directory) => async (domain, options = { path: "" }) => writeResource(directory, { ...domain }, { ...options, type: "domain" });
277
320
  var versionDomain = (directory) => async (id) => versionResource(directory, id);
278
321
  var rmDomain = (directory) => async (path) => {
279
- await fs6.rm(join6(directory, path), { recursive: true });
322
+ await fs7.rm(join7(directory, path), { recursive: true });
280
323
  };
281
324
  var rmDomainById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "domain" });
282
325
  var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -307,7 +350,7 @@ var src_default = (path) => {
307
350
  * @param version - Optional id of the version to get (supports semver)
308
351
  * @returns Event|Undefined
309
352
  */
310
- getEvent: getEvent(join7(path, "events")),
353
+ getEvent: getEvent(join8(path)),
311
354
  /**
312
355
  * Adds an event to EventCatalog
313
356
  *
@@ -315,26 +358,35 @@ var src_default = (path) => {
315
358
  * @param options - Optional options to write the event
316
359
  *
317
360
  */
318
- writeEvent: writeEvent(join7(path, "events")),
361
+ writeEvent: writeEvent(join8(path, "events")),
362
+ /**
363
+ * Adds an event to a service in EventCatalog
364
+ *
365
+ * @param event - The event to write to the service
366
+ * @param service - The service and it's id to write to the event to
367
+ * @param options - Optional options to write the event
368
+ *
369
+ */
370
+ writeEventToService: writeEventToService(join8(path, "services")),
319
371
  /**
320
372
  * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
321
373
  *
322
374
  * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
323
375
  *
324
376
  */
325
- rmEvent: rmEvent(join7(path, "events")),
377
+ rmEvent: rmEvent(join8(path, "events")),
326
378
  /**
327
379
  * Remove an event by an Event id
328
380
  *
329
381
  * @param id - The id of the event you want to remove
330
382
  *
331
383
  */
332
- rmEventById: rmEventById(join7(path, "events")),
384
+ rmEventById: rmEventById(join8(path)),
333
385
  /**
334
386
  * Moves a given event id to the version directory
335
387
  * @param directory
336
388
  */
337
- versionEvent: versionEvent(join7(path, "events")),
389
+ versionEvent: versionEvent(join8(path)),
338
390
  /**
339
391
  * Adds a file to the given event
340
392
  * @param id - The id of the event to add the file to
@@ -342,7 +394,7 @@ var src_default = (path) => {
342
394
  * @param version - Optional version of the event to add the file to
343
395
  * @returns
344
396
  */
345
- addFileToEvent: addFileToEvent(join7(path, "events")),
397
+ addFileToEvent: addFileToEvent(join8(path)),
346
398
  /**
347
399
  * Adds a schema to the given event
348
400
  * @param id - The id of the event to add the schema to
@@ -350,14 +402,14 @@ var src_default = (path) => {
350
402
  * @param version - Optional version of the event to add the schema to
351
403
  * @returns
352
404
  */
353
- addSchemaToEvent: addSchemaToEvent(join7(path, "events")),
405
+ addSchemaToEvent: addSchemaToEvent(join8(path)),
354
406
  /**
355
407
  * Check to see if an event version exists
356
408
  * @param id - The id of the event
357
409
  * @param version - The version of the event (supports semver)
358
410
  * @returns
359
411
  */
360
- eventHasVersion: eventHasVersion(join7(path, "events")),
412
+ eventHasVersion: eventHasVersion(join8(path)),
361
413
  /**
362
414
  * ================================
363
415
  * Commands
@@ -369,7 +421,7 @@ var src_default = (path) => {
369
421
  * @param version - Optional id of the version to get (supports semver)
370
422
  * @returns Command|Undefined
371
423
  */
372
- getCommand: getCommand(join7(path, "commands")),
424
+ getCommand: getCommand(join8(path)),
373
425
  /**
374
426
  * Adds an command to EventCatalog
375
427
  *
@@ -377,26 +429,35 @@ var src_default = (path) => {
377
429
  * @param options - Optional options to write the command
378
430
  *
379
431
  */
380
- writeCommand: writeCommand(join7(path, "commands")),
432
+ writeCommand: writeCommand(join8(path, "commands")),
433
+ /**
434
+ * Adds a command to a service in EventCatalog
435
+ *
436
+ * @param command - The command to write to the service
437
+ * @param service - The service and it's id to write to the command to
438
+ * @param options - Optional options to write the command
439
+ *
440
+ */
441
+ writeCommandToService: writeCommandToService(join8(path, "services")),
381
442
  /**
382
443
  * Remove an command to EventCatalog (modeled on the standard POSIX rm utility)
383
444
  *
384
445
  * @param path - The path to your command, e.g. `/Inventory/InventoryAdjusted`
385
446
  *
386
447
  */
387
- rmCommand: rmCommand(join7(path, "commands")),
448
+ rmCommand: rmCommand(join8(path, "commands")),
388
449
  /**
389
450
  * Remove an command by an Event id
390
451
  *
391
452
  * @param id - The id of the command you want to remove
392
453
  *
393
454
  */
394
- rmCommandById: rmCommandById(join7(path, "commands")),
455
+ rmCommandById: rmCommandById(join8(path)),
395
456
  /**
396
457
  * Moves a given command id to the version directory
397
458
  * @param directory
398
459
  */
399
- versionCommand: versionCommand(join7(path, "commands")),
460
+ versionCommand: versionCommand(join8(path)),
400
461
  /**
401
462
  * Adds a file to the given command
402
463
  * @param id - The id of the command to add the file to
@@ -404,7 +465,7 @@ var src_default = (path) => {
404
465
  * @param version - Optional version of the command to add the file to
405
466
  * @returns
406
467
  */
407
- addFileToCommand: addFileToCommand(join7(path, "commands")),
468
+ addFileToCommand: addFileToCommand(join8(path)),
408
469
  /**
409
470
  * Adds a schema to the given command
410
471
  * @param id - The id of the command to add the schema to
@@ -412,14 +473,85 @@ var src_default = (path) => {
412
473
  * @param version - Optional version of the command to add the schema to
413
474
  * @returns
414
475
  */
415
- addSchemaToCommand: addSchemaToCommand(join7(path, "commands")),
476
+ addSchemaToCommand: addSchemaToCommand(join8(path)),
416
477
  /**
417
478
  * Check to see if a command version exists
418
479
  * @param id - The id of the command
419
480
  * @param version - The version of the command (supports semver)
420
481
  * @returns
421
482
  */
422
- commandHasVersion: commandHasVersion(join7(path, "commands")),
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)),
423
555
  /**
424
556
  * ================================
425
557
  * SERVICES
@@ -432,33 +564,42 @@ var src_default = (path) => {
432
564
  * @param options - Optional options to write the event
433
565
  *
434
566
  */
435
- writeService: writeService(join7(path, "services")),
567
+ writeService: writeService(join8(path, "services")),
568
+ /**
569
+ * Adds a service to a domain in EventCatalog
570
+ *
571
+ * @param service - The service to write
572
+ * @param domain - The domain to add the service to
573
+ * @param options - Optional options to write the event
574
+ *
575
+ */
576
+ writeServiceToDomain: writeServiceToDomain(join8(path, "domains")),
436
577
  /**
437
578
  * Returns a service from EventCatalog
438
579
  * @param id - The id of the service to retrieve
439
580
  * @param version - Optional id of the version to get (supports semver)
440
581
  * @returns Service|Undefined
441
582
  */
442
- getService: getService(join7(path, "services")),
583
+ getService: getService(join8(path)),
443
584
  /**
444
585
  * Moves a given service id to the version directory
445
586
  * @param directory
446
587
  */
447
- versionService: versionService(join7(path, "services")),
588
+ versionService: versionService(join8(path)),
448
589
  /**
449
590
  * Remove a service from EventCatalog (modeled on the standard POSIX rm utility)
450
591
  *
451
592
  * @param path - The path to your service, e.g. `/InventoryService`
452
593
  *
453
594
  */
454
- rmService: rmService(join7(path, "services")),
595
+ rmService: rmService(join8(path, "services")),
455
596
  /**
456
597
  * Remove an service by an service id
457
598
  *
458
599
  * @param id - The id of the service you want to remove
459
600
  *
460
601
  */
461
- rmServiceById: rmServiceById(join7(path, "services")),
602
+ rmServiceById: rmServiceById(join8(path)),
462
603
  /**
463
604
  * Adds a file to the given service
464
605
  * @param id - The id of the service to add the file to
@@ -466,21 +607,21 @@ var src_default = (path) => {
466
607
  * @param version - Optional version of the service to add the file to
467
608
  * @returns
468
609
  */
469
- addFileToService: addFileToService(join7(path, "services")),
610
+ addFileToService: addFileToService(join8(path)),
470
611
  /**
471
612
  * Returns the specifications for a given service
472
613
  * @param id - The id of the service to retrieve the specifications for
473
614
  * @param version - Optional version of the service
474
615
  * @returns
475
616
  */
476
- getSpecificationFilesForService: getSpecificationFilesForService(join7(path, "services")),
617
+ getSpecificationFilesForService: getSpecificationFilesForService(join8(path)),
477
618
  /**
478
619
  * Check to see if a service version exists
479
620
  * @param id - The id of the service
480
621
  * @param version - The version of the service (supports semver)
481
622
  * @returns
482
623
  */
483
- serviceHasVersion: serviceHasVersion(join7(path, "services")),
624
+ serviceHasVersion: serviceHasVersion(join8(path)),
484
625
  /**
485
626
  * ================================
486
627
  * Domains
@@ -493,33 +634,33 @@ var src_default = (path) => {
493
634
  * @param options - Optional options to write the event
494
635
  *
495
636
  */
496
- writeDomain: writeDomain(join7(path, "domains")),
637
+ writeDomain: writeDomain(join8(path, "domains")),
497
638
  /**
498
639
  * Returns a domain from EventCatalog
499
640
  * @param id - The id of the domain to retrieve
500
641
  * @param version - Optional id of the version to get (supports semver)
501
642
  * @returns Domain|Undefined
502
643
  */
503
- getDomain: getDomain(join7(path, "domains")),
644
+ getDomain: getDomain(join8(path, "domains")),
504
645
  /**
505
646
  * Moves a given domain id to the version directory
506
647
  * @param directory
507
648
  */
508
- versionDomain: versionDomain(join7(path, "domains")),
649
+ versionDomain: versionDomain(join8(path, "domains")),
509
650
  /**
510
651
  * Remove a domain from EventCatalog (modeled on the standard POSIX rm utility)
511
652
  *
512
653
  * @param path - The path to your domain, e.g. `/Payment`
513
654
  *
514
655
  */
515
- rmDomain: rmDomain(join7(path, "domains")),
656
+ rmDomain: rmDomain(join8(path, "domains")),
516
657
  /**
517
658
  * Remove an service by an domain id
518
659
  *
519
660
  * @param id - The id of the domain you want to remove
520
661
  *
521
662
  */
522
- rmDomainById: rmDomainById(join7(path, "domains")),
663
+ rmDomainById: rmDomainById(join8(path, "domains")),
523
664
  /**
524
665
  * Adds a file to the given domain
525
666
  * @param id - The id of the domain to add the file to
@@ -527,7 +668,7 @@ var src_default = (path) => {
527
668
  * @param version - Optional version of the domain to add the file to
528
669
  * @returns
529
670
  */
530
- addFileToDomain: addFileToDomain(join7(path, "domains")),
671
+ addFileToDomain: addFileToDomain(join8(path, "domains")),
531
672
  /**
532
673
  * Add an event to a service by it's id.
533
674
  *
@@ -547,7 +688,7 @@ var src_default = (path) => {
547
688
  *
548
689
  * ```
549
690
  */
550
- addEventToService: addMessageToService(join7(path, "services")),
691
+ addEventToService: addMessageToService(join8(path)),
551
692
  /**
552
693
  * Add a command to a service by it's id.
553
694
  *
@@ -567,14 +708,14 @@ var src_default = (path) => {
567
708
  *
568
709
  * ```
569
710
  */
570
- addCommandToService: addMessageToService(join7(path, "services")),
711
+ addCommandToService: addMessageToService(join8(path)),
571
712
  /**
572
713
  * Check to see if a domain version exists
573
714
  * @param id - The id of the domain
574
715
  * @param version - The version of the domain (supports semver)
575
716
  * @returns
576
717
  */
577
- domainHasVersion: domainHasVersion(join7(path, "domains")),
718
+ domainHasVersion: domainHasVersion(join8(path)),
578
719
  /**
579
720
  * Adds a given service to a domain
580
721
  * @param id - The id of the domain
@@ -582,7 +723,7 @@ var src_default = (path) => {
582
723
  * @param version - (Optional) The version of the domain to add the service to
583
724
  * @returns
584
725
  */
585
- addServiceToDomain: addServiceToDomain(join7(path, "domains"))
726
+ addServiceToDomain: addServiceToDomain(join8(path, "domains"))
586
727
  };
587
728
  };
588
729
  export {