@eventcatalog/sdk 0.0.9 → 0.0.11

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.d.mts CHANGED
@@ -10,8 +10,8 @@ declare const _default: (path: string) => {
10
10
  /**
11
11
  * Returns an events from EventCatalog
12
12
  * @param id - The id of the event to retrieve
13
- * @param version - Optional id of the version to get
14
- * @returns
13
+ * @param version - Optional id of the version to get (supports semver)
14
+ * @returns Event|Undefined
15
15
  */
16
16
  getEvent: (id: string, version?: string) => Promise<Event>;
17
17
  /**
@@ -65,6 +65,13 @@ declare const _default: (path: string) => {
65
65
  schema: string;
66
66
  fileName: string;
67
67
  }, version?: string) => Promise<void>;
68
+ /**
69
+ * Check to see if an event version exists
70
+ * @param id - The id of the event
71
+ * @param version - The version of the event (supports semver)
72
+ * @returns
73
+ */
74
+ eventHasVersion: (id: string, version: string) => Promise<boolean>;
68
75
  /**
69
76
  * ================================
70
77
  * Commands
@@ -73,8 +80,8 @@ declare const _default: (path: string) => {
73
80
  /**
74
81
  * Returns a command from EventCatalog
75
82
  * @param id - The id of the command to retrieve
76
- * @param version - Optional id of the version to get
77
- * @returns
83
+ * @param version - Optional id of the version to get (supports semver)
84
+ * @returns Command|Undefined
78
85
  */
79
86
  getCommand: (id: string, version?: string) => Promise<Command>;
80
87
  /**
@@ -128,6 +135,13 @@ declare const _default: (path: string) => {
128
135
  schema: string;
129
136
  fileName: string;
130
137
  }, version?: string) => Promise<void>;
138
+ /**
139
+ * Check to see if a command version exists
140
+ * @param id - The id of the command
141
+ * @param version - The version of the command (supports semver)
142
+ * @returns
143
+ */
144
+ commandHasVersion: (id: string, version: string) => Promise<boolean>;
131
145
  /**
132
146
  * ================================
133
147
  * SERVICES
@@ -146,8 +160,8 @@ declare const _default: (path: string) => {
146
160
  /**
147
161
  * Returns a service from EventCatalog
148
162
  * @param id - The id of the service to retrieve
149
- * @param version - Optional id of the version to get
150
- * @returns
163
+ * @param version - Optional id of the version to get (supports semver)
164
+ * @returns Service|Undefined
151
165
  */
152
166
  getService: (id: string, version?: string) => Promise<Service>;
153
167
  /**
@@ -180,6 +194,13 @@ declare const _default: (path: string) => {
180
194
  content: string;
181
195
  fileName: string;
182
196
  }, version?: string) => Promise<void>;
197
+ /**
198
+ * Check to see if a service version exists
199
+ * @param id - The id of the service
200
+ * @param version - The version of the service (supports semver)
201
+ * @returns
202
+ */
203
+ serviceHasVersion: (id: string, version: string) => Promise<boolean>;
183
204
  /**
184
205
  * ================================
185
206
  * Domains
@@ -198,8 +219,8 @@ declare const _default: (path: string) => {
198
219
  /**
199
220
  * Returns a domain from EventCatalog
200
221
  * @param id - The id of the domain to retrieve
201
- * @param version - Optional id of the version to get
202
- * @returns
222
+ * @param version - Optional id of the version to get (supports semver)
223
+ * @returns Domain|Undefined
203
224
  */
204
225
  getDomain: (id: string, version?: string) => Promise<Domain>;
205
226
  /**
@@ -278,6 +299,13 @@ declare const _default: (path: string) => {
278
299
  id: string;
279
300
  version: string;
280
301
  }, version?: string) => Promise<void>;
302
+ /**
303
+ * Check to see if a domain version exists
304
+ * @param id - The id of the domain
305
+ * @param version - The version of the domain (supports semver)
306
+ * @returns
307
+ */
308
+ domainHasVersion: (id: string, version: string) => Promise<boolean>;
281
309
  };
282
310
 
283
311
  export { _default as default };
package/dist/index.d.ts CHANGED
@@ -10,8 +10,8 @@ declare const _default: (path: string) => {
10
10
  /**
11
11
  * Returns an events from EventCatalog
12
12
  * @param id - The id of the event to retrieve
13
- * @param version - Optional id of the version to get
14
- * @returns
13
+ * @param version - Optional id of the version to get (supports semver)
14
+ * @returns Event|Undefined
15
15
  */
16
16
  getEvent: (id: string, version?: string) => Promise<Event>;
17
17
  /**
@@ -65,6 +65,13 @@ declare const _default: (path: string) => {
65
65
  schema: string;
66
66
  fileName: string;
67
67
  }, version?: string) => Promise<void>;
68
+ /**
69
+ * Check to see if an event version exists
70
+ * @param id - The id of the event
71
+ * @param version - The version of the event (supports semver)
72
+ * @returns
73
+ */
74
+ eventHasVersion: (id: string, version: string) => Promise<boolean>;
68
75
  /**
69
76
  * ================================
70
77
  * Commands
@@ -73,8 +80,8 @@ declare const _default: (path: string) => {
73
80
  /**
74
81
  * Returns a command from EventCatalog
75
82
  * @param id - The id of the command to retrieve
76
- * @param version - Optional id of the version to get
77
- * @returns
83
+ * @param version - Optional id of the version to get (supports semver)
84
+ * @returns Command|Undefined
78
85
  */
79
86
  getCommand: (id: string, version?: string) => Promise<Command>;
80
87
  /**
@@ -128,6 +135,13 @@ declare const _default: (path: string) => {
128
135
  schema: string;
129
136
  fileName: string;
130
137
  }, version?: string) => Promise<void>;
138
+ /**
139
+ * Check to see if a command version exists
140
+ * @param id - The id of the command
141
+ * @param version - The version of the command (supports semver)
142
+ * @returns
143
+ */
144
+ commandHasVersion: (id: string, version: string) => Promise<boolean>;
131
145
  /**
132
146
  * ================================
133
147
  * SERVICES
@@ -146,8 +160,8 @@ declare const _default: (path: string) => {
146
160
  /**
147
161
  * Returns a service from EventCatalog
148
162
  * @param id - The id of the service to retrieve
149
- * @param version - Optional id of the version to get
150
- * @returns
163
+ * @param version - Optional id of the version to get (supports semver)
164
+ * @returns Service|Undefined
151
165
  */
152
166
  getService: (id: string, version?: string) => Promise<Service>;
153
167
  /**
@@ -180,6 +194,13 @@ declare const _default: (path: string) => {
180
194
  content: string;
181
195
  fileName: string;
182
196
  }, version?: string) => Promise<void>;
197
+ /**
198
+ * Check to see if a service version exists
199
+ * @param id - The id of the service
200
+ * @param version - The version of the service (supports semver)
201
+ * @returns
202
+ */
203
+ serviceHasVersion: (id: string, version: string) => Promise<boolean>;
183
204
  /**
184
205
  * ================================
185
206
  * Domains
@@ -198,8 +219,8 @@ declare const _default: (path: string) => {
198
219
  /**
199
220
  * Returns a domain from EventCatalog
200
221
  * @param id - The id of the domain to retrieve
201
- * @param version - Optional id of the version to get
202
- * @returns
222
+ * @param version - Optional id of the version to get (supports semver)
223
+ * @returns Domain|Undefined
203
224
  */
204
225
  getDomain: (id: string, version?: string) => Promise<Domain>;
205
226
  /**
@@ -278,6 +299,13 @@ declare const _default: (path: string) => {
278
299
  id: string;
279
300
  version: string;
280
301
  }, version?: string) => Promise<void>;
302
+ /**
303
+ * Check to see if a domain version exists
304
+ * @param id - The id of the domain
305
+ * @param version - The version of the domain (supports semver)
306
+ * @returns
307
+ */
308
+ domainHasVersion: (id: string, version: string) => Promise<boolean>;
281
309
  };
282
310
 
283
311
  export { _default as default };
package/dist/index.js CHANGED
@@ -39,15 +39,13 @@ var import_node_path6 = require("path");
39
39
  var import_promises3 = __toESM(require("fs/promises"));
40
40
  var import_node_path2 = require("path");
41
41
 
42
- // src/internal/resources.ts
43
- var import_path = require("path");
44
-
45
42
  // src/internal/utils.ts
46
43
  var import_glob = require("glob");
47
44
  var import_promises = __toESM(require("fs/promises"));
48
45
  var import_fs_extra = require("fs-extra");
49
46
  var import_node_path = require("path");
50
47
  var import_gray_matter = __toESM(require("gray-matter"));
48
+ var import_semver = require("semver");
51
49
  var versionExists = async (catalogDir, id, version) => {
52
50
  const files = await getFiles(`${catalogDir}/**/index.md`);
53
51
  const matchedFiles = await searchFilesForId(files, id, version) || [];
@@ -60,14 +58,22 @@ var findFileById = async (catalogDir, id, version) => {
60
58
  if (!version) {
61
59
  return latestVersion;
62
60
  }
63
- const match = matchedFiles.find((path) => path.includes(`versioned/${version}`));
64
- if (!match && latestVersion) {
65
- const { data } = import_gray_matter.default.read(latestVersion);
66
- if (data.version === version) {
67
- return latestVersion;
68
- }
61
+ const parsedFiles = matchedFiles.map((path) => {
62
+ const { data } = import_gray_matter.default.read(path);
63
+ return { ...data, path };
64
+ });
65
+ const semverRange = (0, import_semver.validRange)(version);
66
+ if (semverRange) {
67
+ const match2 = parsedFiles.filter((c) => (0, import_semver.satisfies)(c.version, semverRange));
68
+ return match2.length > 0 ? match2[0].path : void 0;
69
+ }
70
+ const sorted = parsedFiles.sort((a, b) => {
71
+ return a.version.localeCompare(b.version);
72
+ });
73
+ const match = sorted.length > 0 ? [sorted[sorted.length - 1]] : [];
74
+ if (match.length > 0) {
75
+ return match[0].path;
69
76
  }
70
- return match;
71
77
  };
72
78
  var getFiles = async (pattern) => {
73
79
  try {
@@ -109,6 +115,7 @@ var copyDir = async (catalogDir, source, target, filter) => {
109
115
  };
110
116
 
111
117
  // src/internal/resources.ts
118
+ var import_path = require("path");
112
119
  var import_gray_matter2 = __toESM(require("gray-matter"));
113
120
  var import_promises2 = __toESM(require("fs/promises"));
114
121
  var versionResource = async (catalogDir, id) => {
@@ -148,10 +155,7 @@ var writeResource = async (catalogDir, resource, options = { path: "", type: ""
148
155
  };
149
156
  var getResource = async (catalogDir, id, version, options) => {
150
157
  const file = await findFileById(catalogDir, id, version);
151
- if (!file)
152
- throw new Error(
153
- `No ${options?.type || "resource"} found for the given id: ${id}` + (version ? ` and version ${version}` : "")
154
- );
158
+ if (!file) return;
155
159
  const { data, content } = import_gray_matter2.default.read(file);
156
160
  return {
157
161
  ...data,
@@ -184,6 +188,10 @@ var addFileToEvent = (directory) => async (id, file, version) => addFileToResour
184
188
  var addSchemaToEvent = (directory) => async (id, schema, version) => {
185
189
  await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);
186
190
  };
191
+ var eventHasVersion = (directory) => async (id, version) => {
192
+ const file = await findFileById(directory, id, version);
193
+ return !!file;
194
+ };
187
195
 
188
196
  // src/commands.ts
189
197
  var import_promises4 = __toESM(require("fs/promises"));
@@ -199,6 +207,10 @@ var addFileToCommand = (directory) => async (id, file, version) => addFileToReso
199
207
  var addSchemaToCommand = (directory) => async (id, schema, version) => {
200
208
  await addFileToCommand(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);
201
209
  };
210
+ var commandHasVersion = (directory) => async (id, version) => {
211
+ const file = await findFileById(directory, id, version);
212
+ return !!file;
213
+ };
202
214
 
203
215
  // src/services.ts
204
216
  var import_promises5 = __toESM(require("fs/promises"));
@@ -239,6 +251,10 @@ var addMessageToService = (directory) => async (id, direction, event, version) =
239
251
  await rmServiceById(directory)(id, version);
240
252
  await writeService(directory)(service);
241
253
  };
254
+ var serviceHasVersion = (directory) => async (id, version) => {
255
+ const file = await findFileById(directory, id, version);
256
+ return !!file;
257
+ };
242
258
 
243
259
  // src/domains.ts
244
260
  var import_promises6 = __toESM(require("fs/promises"));
@@ -251,6 +267,10 @@ var rmDomain = (directory) => async (path) => {
251
267
  };
252
268
  var rmDomainById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "domain" });
253
269
  var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
270
+ var domainHasVersion = (directory) => async (id, version) => {
271
+ const file = await findFileById(directory, id, version);
272
+ return !!file;
273
+ };
254
274
 
255
275
  // src/index.ts
256
276
  var src_default = (path) => {
@@ -258,8 +278,8 @@ var src_default = (path) => {
258
278
  /**
259
279
  * Returns an events from EventCatalog
260
280
  * @param id - The id of the event to retrieve
261
- * @param version - Optional id of the version to get
262
- * @returns
281
+ * @param version - Optional id of the version to get (supports semver)
282
+ * @returns Event|Undefined
263
283
  */
264
284
  getEvent: getEvent((0, import_node_path6.join)(path, "events")),
265
285
  /**
@@ -305,6 +325,13 @@ var src_default = (path) => {
305
325
  * @returns
306
326
  */
307
327
  addSchemaToEvent: addSchemaToEvent((0, import_node_path6.join)(path, "events")),
328
+ /**
329
+ * Check to see if an event version exists
330
+ * @param id - The id of the event
331
+ * @param version - The version of the event (supports semver)
332
+ * @returns
333
+ */
334
+ eventHasVersion: eventHasVersion((0, import_node_path6.join)(path, "events")),
308
335
  /**
309
336
  * ================================
310
337
  * Commands
@@ -313,8 +340,8 @@ var src_default = (path) => {
313
340
  /**
314
341
  * Returns a command from EventCatalog
315
342
  * @param id - The id of the command to retrieve
316
- * @param version - Optional id of the version to get
317
- * @returns
343
+ * @param version - Optional id of the version to get (supports semver)
344
+ * @returns Command|Undefined
318
345
  */
319
346
  getCommand: getCommand((0, import_node_path6.join)(path, "commands")),
320
347
  /**
@@ -360,6 +387,13 @@ var src_default = (path) => {
360
387
  * @returns
361
388
  */
362
389
  addSchemaToCommand: addSchemaToCommand((0, import_node_path6.join)(path, "commands")),
390
+ /**
391
+ * Check to see if a command version exists
392
+ * @param id - The id of the command
393
+ * @param version - The version of the command (supports semver)
394
+ * @returns
395
+ */
396
+ commandHasVersion: commandHasVersion((0, import_node_path6.join)(path, "commands")),
363
397
  /**
364
398
  * ================================
365
399
  * SERVICES
@@ -376,8 +410,8 @@ var src_default = (path) => {
376
410
  /**
377
411
  * Returns a service from EventCatalog
378
412
  * @param id - The id of the service to retrieve
379
- * @param version - Optional id of the version to get
380
- * @returns
413
+ * @param version - Optional id of the version to get (supports semver)
414
+ * @returns Service|Undefined
381
415
  */
382
416
  getService: getService((0, import_node_path6.join)(path, "services")),
383
417
  /**
@@ -407,6 +441,13 @@ var src_default = (path) => {
407
441
  * @returns
408
442
  */
409
443
  addFileToService: addFileToService((0, import_node_path6.join)(path, "services")),
444
+ /**
445
+ * Check to see if a service version exists
446
+ * @param id - The id of the service
447
+ * @param version - The version of the service (supports semver)
448
+ * @returns
449
+ */
450
+ serviceHasVersion: serviceHasVersion((0, import_node_path6.join)(path, "services")),
410
451
  /**
411
452
  * ================================
412
453
  * Domains
@@ -423,8 +464,8 @@ var src_default = (path) => {
423
464
  /**
424
465
  * Returns a domain from EventCatalog
425
466
  * @param id - The id of the domain to retrieve
426
- * @param version - Optional id of the version to get
427
- * @returns
467
+ * @param version - Optional id of the version to get (supports semver)
468
+ * @returns Domain|Undefined
428
469
  */
429
470
  getDomain: getDomain((0, import_node_path6.join)(path, "domains")),
430
471
  /**
@@ -493,7 +534,14 @@ var src_default = (path) => {
493
534
  *
494
535
  * ```
495
536
  */
496
- addCommandToService: addMessageToService((0, import_node_path6.join)(path, "services"))
537
+ addCommandToService: addMessageToService((0, import_node_path6.join)(path, "services")),
538
+ /**
539
+ * Check to see if a domain version exists
540
+ * @param id - The id of the domain
541
+ * @param version - The version of the domain (supports semver)
542
+ * @returns
543
+ */
544
+ domainHasVersion: domainHasVersion((0, import_node_path6.join)(path, "domains"))
497
545
  };
498
546
  };
499
547
  //# sourceMappingURL=index.js.map