@eventcatalog/sdk 1.2.3 → 1.3.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/channels.d.mts +22 -1
- package/dist/channels.d.ts +22 -1
- package/dist/channels.js +24 -3
- package/dist/channels.js.map +1 -1
- package/dist/channels.mjs +23 -3
- package/dist/channels.mjs.map +1 -1
- package/dist/commands.d.mts +22 -1
- package/dist/commands.d.ts +22 -1
- package/dist/commands.js +17 -2
- package/dist/commands.js.map +1 -1
- package/dist/commands.mjs +16 -2
- package/dist/commands.mjs.map +1 -1
- package/dist/domains.d.mts +22 -1
- package/dist/domains.d.ts +22 -1
- package/dist/domains.js +17 -2
- package/dist/domains.js.map +1 -1
- package/dist/domains.mjs +16 -2
- package/dist/domains.mjs.map +1 -1
- package/dist/events.d.mts +22 -1
- package/dist/events.d.ts +22 -1
- package/dist/events.js +17 -2
- package/dist/events.js.map +1 -1
- package/dist/events.mjs +16 -2
- package/dist/events.mjs.map +1 -1
- package/dist/index.d.mts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +70 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -4
- package/dist/index.mjs.map +1 -1
- package/dist/queries.d.mts +22 -1
- package/dist/queries.d.ts +22 -1
- package/dist/queries.js +17 -2
- package/dist/queries.js.map +1 -1
- package/dist/queries.mjs +16 -2
- package/dist/queries.mjs.map +1 -1
- package/dist/services.d.mts +22 -1
- package/dist/services.d.ts +22 -1
- package/dist/services.js +24 -3
- package/dist/services.js.map +1 -1
- package/dist/services.mjs +23 -3
- package/dist/services.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -41,9 +41,9 @@ var findFileById = async (catalogDir, id, version) => {
|
|
|
41
41
|
return match[0].path;
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
var getFiles = async (pattern) => {
|
|
44
|
+
var getFiles = async (pattern, ignore = "") => {
|
|
45
45
|
try {
|
|
46
|
-
const files = await glob(pattern, { ignore: "node_modules/**" });
|
|
46
|
+
const files = await glob(pattern, { ignore: ["node_modules/**", ignore] });
|
|
47
47
|
return files;
|
|
48
48
|
} catch (error) {
|
|
49
49
|
throw new Error(`Error finding files: ${error}`);
|
|
@@ -155,6 +155,18 @@ var getResource = async (catalogDir, id, version, options) => {
|
|
|
155
155
|
markdown: content.trim()
|
|
156
156
|
};
|
|
157
157
|
};
|
|
158
|
+
var getResources = async (catalogDir, { type, latestOnly = false }) => {
|
|
159
|
+
const ignore = latestOnly ? `**/versioned/**` : "";
|
|
160
|
+
const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, ignore);
|
|
161
|
+
if (files.length === 0) return;
|
|
162
|
+
return files.map((file) => {
|
|
163
|
+
const { data, content } = matter2.read(file);
|
|
164
|
+
return {
|
|
165
|
+
...data,
|
|
166
|
+
markdown: content.trim()
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
};
|
|
158
170
|
var rmResourceById = async (catalogDir, id, version, options) => {
|
|
159
171
|
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
160
172
|
const matchedFiles = await searchFilesForId(files, id, version);
|
|
@@ -181,6 +193,7 @@ var getVersionedDirectory = (sourceDirectory, version) => {
|
|
|
181
193
|
|
|
182
194
|
// src/events.ts
|
|
183
195
|
var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
|
|
196
|
+
var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
|
|
184
197
|
var writeEvent = (directory) => async (event, options = { path: "", override: false }) => writeResource(directory, { ...event }, { ...options, type: "event" });
|
|
185
198
|
var writeEventToService = (directory) => async (event, service, options = { path: "" }) => {
|
|
186
199
|
let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/events` : `/${service.id}/events`;
|
|
@@ -207,6 +220,7 @@ var eventHasVersion = (directory) => async (id, version) => {
|
|
|
207
220
|
import fs4 from "node:fs/promises";
|
|
208
221
|
import { join as join4 } from "node:path";
|
|
209
222
|
var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
|
|
223
|
+
var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
|
|
210
224
|
var writeCommand = (directory) => async (command, options = { path: "" }) => writeResource(directory, { ...command }, { ...options, type: "command" });
|
|
211
225
|
var writeCommandToService = (directory) => async (command, service, options = { path: "" }) => {
|
|
212
226
|
let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/commands` : `/${service.id}/commands`;
|
|
@@ -232,6 +246,7 @@ import fs5 from "node:fs/promises";
|
|
|
232
246
|
import { join as join5 } from "node:path";
|
|
233
247
|
var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
|
|
234
248
|
var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
|
|
249
|
+
var getQueries = (directory) => async (options) => getResources(directory, { type: "queries", ...options });
|
|
235
250
|
var writeQueryToService = (directory) => async (query, service, options = { path: "" }) => {
|
|
236
251
|
let pathForQuery = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/queries` : `/${service.id}/queries`;
|
|
237
252
|
pathForQuery = join5(pathForQuery, query.id);
|
|
@@ -257,6 +272,7 @@ var queryHasVersion = (directory) => async (id, version) => {
|
|
|
257
272
|
import fs6 from "node:fs/promises";
|
|
258
273
|
import { join as join6, dirname as dirname2 } from "node:path";
|
|
259
274
|
var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
|
|
275
|
+
var getServices = (directory) => async (options) => getResources(directory, { type: "services", ...options });
|
|
260
276
|
var writeService = (directory) => async (service, options = { path: "" }) => {
|
|
261
277
|
const resource = { ...service };
|
|
262
278
|
if (Array.isArray(service.sends)) {
|
|
@@ -328,8 +344,14 @@ var addMessageToService = (directory) => async (id, direction, event, version) =
|
|
|
328
344
|
} else {
|
|
329
345
|
throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);
|
|
330
346
|
}
|
|
347
|
+
const existingResource = await findFileById(directory, id, version);
|
|
348
|
+
if (!existingResource) {
|
|
349
|
+
throw new Error(`Cannot find service ${id} in the catalog`);
|
|
350
|
+
}
|
|
351
|
+
const path = existingResource.split("/services")[0];
|
|
352
|
+
const pathToResource = join6(path, "services");
|
|
331
353
|
await rmServiceById(directory)(id, version);
|
|
332
|
-
await writeService(
|
|
354
|
+
await writeService(pathToResource)(service);
|
|
333
355
|
};
|
|
334
356
|
var serviceHasVersion = (directory) => async (id, version) => {
|
|
335
357
|
const file = await findFileById(directory, id, version);
|
|
@@ -340,6 +362,7 @@ var serviceHasVersion = (directory) => async (id, version) => {
|
|
|
340
362
|
import fs7 from "node:fs/promises";
|
|
341
363
|
import { join as join7 } from "node:path";
|
|
342
364
|
var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
|
|
365
|
+
var getDomains = (directory) => async (options) => getResources(directory, { type: "domains", ...options });
|
|
343
366
|
var writeDomain = (directory) => async (domain, options = { path: "" }) => {
|
|
344
367
|
const resource = { ...domain };
|
|
345
368
|
if (Array.isArray(domain.services)) {
|
|
@@ -375,6 +398,7 @@ var addServiceToDomain = (directory) => async (id, service, version) => {
|
|
|
375
398
|
import fs8 from "node:fs/promises";
|
|
376
399
|
import { join as join8 } from "node:path";
|
|
377
400
|
var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
|
|
401
|
+
var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
|
|
378
402
|
var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
|
|
379
403
|
var rmChannel = (directory) => async (path) => {
|
|
380
404
|
await fs8.rm(join8(directory, path), { recursive: true });
|
|
@@ -412,8 +436,14 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
|
|
|
412
436
|
}
|
|
413
437
|
const channelInfo = { id, version: channel.version, ..._message.parameters && { parameters: _message.parameters } };
|
|
414
438
|
message.channels.push(channelInfo);
|
|
439
|
+
const existingResource = await findFileById(directory, _message.id, _message.version);
|
|
440
|
+
if (!existingResource) {
|
|
441
|
+
throw new Error(`Cannot find message ${id} in the catalog`);
|
|
442
|
+
}
|
|
443
|
+
const path = existingResource.split(`/${collection}`)[0];
|
|
444
|
+
const pathToResource = join8(path, collection);
|
|
415
445
|
await rmMessageById(directory)(_message.id, _message.version);
|
|
416
|
-
await writeMessage(
|
|
446
|
+
await writeMessage(pathToResource)(message);
|
|
417
447
|
};
|
|
418
448
|
|
|
419
449
|
// src/index.ts
|
|
@@ -426,6 +456,12 @@ var src_default = (path) => {
|
|
|
426
456
|
* @returns Event|Undefined
|
|
427
457
|
*/
|
|
428
458
|
getEvent: getEvent(join9(path)),
|
|
459
|
+
/**
|
|
460
|
+
* Returns all events from EventCatalog
|
|
461
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
462
|
+
* @returns Event[]|Undefined
|
|
463
|
+
*/
|
|
464
|
+
getEvents: getEvents(join9(path)),
|
|
429
465
|
/**
|
|
430
466
|
* Adds an event to EventCatalog
|
|
431
467
|
*
|
|
@@ -497,6 +533,12 @@ var src_default = (path) => {
|
|
|
497
533
|
* @returns Command|Undefined
|
|
498
534
|
*/
|
|
499
535
|
getCommand: getCommand(join9(path)),
|
|
536
|
+
/**
|
|
537
|
+
* Returns all commands from EventCatalog
|
|
538
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
539
|
+
* @returns Command[]|Undefined
|
|
540
|
+
*/
|
|
541
|
+
getCommands: getCommands(join9(path)),
|
|
500
542
|
/**
|
|
501
543
|
* Adds an command to EventCatalog
|
|
502
544
|
*
|
|
@@ -568,6 +610,12 @@ var src_default = (path) => {
|
|
|
568
610
|
* @returns Query|Undefined
|
|
569
611
|
*/
|
|
570
612
|
getQuery: getQuery(join9(path)),
|
|
613
|
+
/**
|
|
614
|
+
* Returns all queries from EventCatalog
|
|
615
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
616
|
+
* @returns Query[]|Undefined
|
|
617
|
+
*/
|
|
618
|
+
getQueries: getQueries(join9(path)),
|
|
571
619
|
/**
|
|
572
620
|
* Adds a query to EventCatalog
|
|
573
621
|
*
|
|
@@ -639,6 +687,12 @@ var src_default = (path) => {
|
|
|
639
687
|
* @returns Channel|Undefined
|
|
640
688
|
*/
|
|
641
689
|
getChannel: getChannel(join9(path)),
|
|
690
|
+
/**
|
|
691
|
+
* Returns all channels from EventCatalog
|
|
692
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
693
|
+
* @returns Channel[]|Undefined
|
|
694
|
+
*/
|
|
695
|
+
getChannels: getChannels(join9(path)),
|
|
642
696
|
/**
|
|
643
697
|
* Adds an channel to EventCatalog
|
|
644
698
|
*
|
|
@@ -760,6 +814,12 @@ var src_default = (path) => {
|
|
|
760
814
|
* @returns Service|Undefined
|
|
761
815
|
*/
|
|
762
816
|
getService: getService(join9(path)),
|
|
817
|
+
/**
|
|
818
|
+
* Returns all services from EventCatalog
|
|
819
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
820
|
+
* @returns Service[]|Undefined
|
|
821
|
+
*/
|
|
822
|
+
getServices: getServices(join9(path)),
|
|
763
823
|
/**
|
|
764
824
|
* Moves a given service id to the version directory
|
|
765
825
|
* @param directory
|
|
@@ -881,6 +941,12 @@ var src_default = (path) => {
|
|
|
881
941
|
* @returns Domain|Undefined
|
|
882
942
|
*/
|
|
883
943
|
getDomain: getDomain(join9(path, "domains")),
|
|
944
|
+
/**
|
|
945
|
+
* Returns all domains from EventCatalog
|
|
946
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
947
|
+
* @returns Domain[]|Undefined
|
|
948
|
+
*/
|
|
949
|
+
getDomains: getDomains(join9(path)),
|
|
884
950
|
/**
|
|
885
951
|
* Moves a given domain id to the version directory
|
|
886
952
|
* @param directory
|