@eventcatalog/sdk 2.17.2 → 2.17.4
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 +43 -3
- package/dist/index.d.ts +43 -3
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -473,7 +473,11 @@ declare const _default: (path: string) => {
|
|
|
473
473
|
*
|
|
474
474
|
*/
|
|
475
475
|
writeEvent: (event: Event, options?: {
|
|
476
|
-
path
|
|
476
|
+
path? /**
|
|
477
|
+
* Returns all events from EventCatalog
|
|
478
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
479
|
+
* @returns Event[]|Undefined
|
|
480
|
+
*/: string;
|
|
477
481
|
override?: boolean;
|
|
478
482
|
versionExistingContent?: boolean;
|
|
479
483
|
format?: "md" | "mdx";
|
|
@@ -490,7 +494,12 @@ declare const _default: (path: string) => {
|
|
|
490
494
|
id: string;
|
|
491
495
|
version?: string;
|
|
492
496
|
}, options?: {
|
|
493
|
-
path
|
|
497
|
+
path? /**
|
|
498
|
+
* Remove an event by an Event id
|
|
499
|
+
*
|
|
500
|
+
* @param id - The id of the event you want to remove
|
|
501
|
+
*
|
|
502
|
+
*/: string;
|
|
494
503
|
format?: "md" | "mdx";
|
|
495
504
|
override?: boolean;
|
|
496
505
|
}) => Promise<void>;
|
|
@@ -546,6 +555,15 @@ declare const _default: (path: string) => {
|
|
|
546
555
|
* @returns
|
|
547
556
|
*/
|
|
548
557
|
eventHasVersion: (id: string, version?: string) => Promise<boolean>;
|
|
558
|
+
addExampleToEvent: (id: string, example: {
|
|
559
|
+
content: string;
|
|
560
|
+
fileName: string;
|
|
561
|
+
}, version?: string) => Promise<void>;
|
|
562
|
+
getExamplesFromEvent: (id: string, version?: string) => Promise<{
|
|
563
|
+
fileName: string;
|
|
564
|
+
content: string;
|
|
565
|
+
}[]>;
|
|
566
|
+
removeExampleFromEvent: (id: string, fileName: string, version?: string) => Promise<void>;
|
|
549
567
|
/**
|
|
550
568
|
* ================================
|
|
551
569
|
* Commands
|
|
@@ -650,6 +668,15 @@ declare const _default: (path: string) => {
|
|
|
650
668
|
* @returns
|
|
651
669
|
*/
|
|
652
670
|
commandHasVersion: (id: string, version?: string) => Promise<boolean>;
|
|
671
|
+
addExampleToCommand: (id: string, example: {
|
|
672
|
+
content: string;
|
|
673
|
+
fileName: string;
|
|
674
|
+
}, version?: string) => Promise<void>;
|
|
675
|
+
getExamplesFromCommand: (id: string, version?: string) => Promise<{
|
|
676
|
+
fileName: string;
|
|
677
|
+
content: string;
|
|
678
|
+
}[]>;
|
|
679
|
+
removeExampleFromCommand: (id: string, fileName: string, version?: string) => Promise<void>;
|
|
653
680
|
/**
|
|
654
681
|
* ================================
|
|
655
682
|
* Queries
|
|
@@ -754,6 +781,15 @@ declare const _default: (path: string) => {
|
|
|
754
781
|
* @returns
|
|
755
782
|
*/
|
|
756
783
|
queryHasVersion: (id: string, version?: string) => Promise<boolean>;
|
|
784
|
+
addExampleToQuery: (id: string, example: {
|
|
785
|
+
content: string;
|
|
786
|
+
fileName: string;
|
|
787
|
+
}, version?: string) => Promise<void>;
|
|
788
|
+
getExamplesFromQuery: (id: string, version?: string) => Promise<{
|
|
789
|
+
fileName: string;
|
|
790
|
+
content: string;
|
|
791
|
+
}[]>;
|
|
792
|
+
removeExampleFromQuery: (id: string, fileName: string, version?: string) => Promise<void>;
|
|
757
793
|
/**
|
|
758
794
|
* ================================
|
|
759
795
|
* Channels
|
|
@@ -1678,7 +1714,11 @@ declare const _default: (path: string) => {
|
|
|
1678
1714
|
version?: string;
|
|
1679
1715
|
}, options?: {
|
|
1680
1716
|
path?: string;
|
|
1681
|
-
format
|
|
1717
|
+
format? /**
|
|
1718
|
+
* Returns all commands from EventCatalog
|
|
1719
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
1720
|
+
* @returns Command[]|Undefined
|
|
1721
|
+
*/: "md" | "mdx";
|
|
1682
1722
|
override?: boolean;
|
|
1683
1723
|
}) => Promise<void>;
|
|
1684
1724
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -473,7 +473,11 @@ declare const _default: (path: string) => {
|
|
|
473
473
|
*
|
|
474
474
|
*/
|
|
475
475
|
writeEvent: (event: Event, options?: {
|
|
476
|
-
path
|
|
476
|
+
path? /**
|
|
477
|
+
* Returns all events from EventCatalog
|
|
478
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
479
|
+
* @returns Event[]|Undefined
|
|
480
|
+
*/: string;
|
|
477
481
|
override?: boolean;
|
|
478
482
|
versionExistingContent?: boolean;
|
|
479
483
|
format?: "md" | "mdx";
|
|
@@ -490,7 +494,12 @@ declare const _default: (path: string) => {
|
|
|
490
494
|
id: string;
|
|
491
495
|
version?: string;
|
|
492
496
|
}, options?: {
|
|
493
|
-
path
|
|
497
|
+
path? /**
|
|
498
|
+
* Remove an event by an Event id
|
|
499
|
+
*
|
|
500
|
+
* @param id - The id of the event you want to remove
|
|
501
|
+
*
|
|
502
|
+
*/: string;
|
|
494
503
|
format?: "md" | "mdx";
|
|
495
504
|
override?: boolean;
|
|
496
505
|
}) => Promise<void>;
|
|
@@ -546,6 +555,15 @@ declare const _default: (path: string) => {
|
|
|
546
555
|
* @returns
|
|
547
556
|
*/
|
|
548
557
|
eventHasVersion: (id: string, version?: string) => Promise<boolean>;
|
|
558
|
+
addExampleToEvent: (id: string, example: {
|
|
559
|
+
content: string;
|
|
560
|
+
fileName: string;
|
|
561
|
+
}, version?: string) => Promise<void>;
|
|
562
|
+
getExamplesFromEvent: (id: string, version?: string) => Promise<{
|
|
563
|
+
fileName: string;
|
|
564
|
+
content: string;
|
|
565
|
+
}[]>;
|
|
566
|
+
removeExampleFromEvent: (id: string, fileName: string, version?: string) => Promise<void>;
|
|
549
567
|
/**
|
|
550
568
|
* ================================
|
|
551
569
|
* Commands
|
|
@@ -650,6 +668,15 @@ declare const _default: (path: string) => {
|
|
|
650
668
|
* @returns
|
|
651
669
|
*/
|
|
652
670
|
commandHasVersion: (id: string, version?: string) => Promise<boolean>;
|
|
671
|
+
addExampleToCommand: (id: string, example: {
|
|
672
|
+
content: string;
|
|
673
|
+
fileName: string;
|
|
674
|
+
}, version?: string) => Promise<void>;
|
|
675
|
+
getExamplesFromCommand: (id: string, version?: string) => Promise<{
|
|
676
|
+
fileName: string;
|
|
677
|
+
content: string;
|
|
678
|
+
}[]>;
|
|
679
|
+
removeExampleFromCommand: (id: string, fileName: string, version?: string) => Promise<void>;
|
|
653
680
|
/**
|
|
654
681
|
* ================================
|
|
655
682
|
* Queries
|
|
@@ -754,6 +781,15 @@ declare const _default: (path: string) => {
|
|
|
754
781
|
* @returns
|
|
755
782
|
*/
|
|
756
783
|
queryHasVersion: (id: string, version?: string) => Promise<boolean>;
|
|
784
|
+
addExampleToQuery: (id: string, example: {
|
|
785
|
+
content: string;
|
|
786
|
+
fileName: string;
|
|
787
|
+
}, version?: string) => Promise<void>;
|
|
788
|
+
getExamplesFromQuery: (id: string, version?: string) => Promise<{
|
|
789
|
+
fileName: string;
|
|
790
|
+
content: string;
|
|
791
|
+
}[]>;
|
|
792
|
+
removeExampleFromQuery: (id: string, fileName: string, version?: string) => Promise<void>;
|
|
757
793
|
/**
|
|
758
794
|
* ================================
|
|
759
795
|
* Channels
|
|
@@ -1678,7 +1714,11 @@ declare const _default: (path: string) => {
|
|
|
1678
1714
|
version?: string;
|
|
1679
1715
|
}, options?: {
|
|
1680
1716
|
path?: string;
|
|
1681
|
-
format
|
|
1717
|
+
format? /**
|
|
1718
|
+
* Returns all commands from EventCatalog
|
|
1719
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
1720
|
+
* @returns Command[]|Undefined
|
|
1721
|
+
*/: "md" | "mdx";
|
|
1682
1722
|
override?: boolean;
|
|
1683
1723
|
}) => Promise<void>;
|
|
1684
1724
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1096,6 +1096,55 @@ var getFileFromResource = async (catalogDir, id, file, version) => {
|
|
|
1096
1096
|
var getVersionedDirectory = (sourceDirectory, version) => {
|
|
1097
1097
|
return (0, import_path.join)(sourceDirectory, "versioned", version);
|
|
1098
1098
|
};
|
|
1099
|
+
var CONFIG_FILES = ["examples.config.yaml", "examples.config.yml", "examples.config.json"];
|
|
1100
|
+
function resolveExamplePath(examplesDir, fileName) {
|
|
1101
|
+
const resolved = import_node_path3.default.resolve(examplesDir, fileName);
|
|
1102
|
+
if (!resolved.startsWith(import_node_path3.default.resolve(examplesDir) + import_node_path3.default.sep) && resolved !== import_node_path3.default.resolve(examplesDir)) {
|
|
1103
|
+
throw new Error(`Invalid example fileName: path traversal detected in "${fileName}"`);
|
|
1104
|
+
}
|
|
1105
|
+
return resolved;
|
|
1106
|
+
}
|
|
1107
|
+
var addExampleToResource = async (catalogDir, id, example, version) => {
|
|
1108
|
+
const pathToResource = await findFileById(catalogDir, id, version);
|
|
1109
|
+
if (!pathToResource) throw new Error("Cannot find directory to write example to");
|
|
1110
|
+
const examplesDir = (0, import_path.join)((0, import_path.dirname)(pathToResource), "examples");
|
|
1111
|
+
const targetPath = resolveExamplePath(examplesDir, example.fileName);
|
|
1112
|
+
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(targetPath), { recursive: true });
|
|
1113
|
+
import_node_fs2.default.writeFileSync(targetPath, example.content);
|
|
1114
|
+
};
|
|
1115
|
+
var getExamplesFromResource = async (catalogDir, id, version) => {
|
|
1116
|
+
const pathToResource = await findFileById(catalogDir, id, version);
|
|
1117
|
+
if (!pathToResource) throw new Error("Cannot find resource");
|
|
1118
|
+
const examplesDir = (0, import_path.join)((0, import_path.dirname)(pathToResource), "examples");
|
|
1119
|
+
if (!import_node_fs2.default.existsSync(examplesDir)) return [];
|
|
1120
|
+
const collectFiles = (dir, baseDir) => {
|
|
1121
|
+
const results = [];
|
|
1122
|
+
const entries = import_node_fs2.default.readdirSync(dir, { withFileTypes: true });
|
|
1123
|
+
for (const entry of entries) {
|
|
1124
|
+
const fullPath = (0, import_path.join)(dir, entry.name);
|
|
1125
|
+
if (entry.isDirectory()) {
|
|
1126
|
+
results.push(...collectFiles(fullPath, baseDir));
|
|
1127
|
+
} else if (entry.isFile() && !CONFIG_FILES.includes(entry.name)) {
|
|
1128
|
+
results.push({
|
|
1129
|
+
fileName: import_node_path3.default.relative(baseDir, fullPath),
|
|
1130
|
+
content: import_node_fs2.default.readFileSync(fullPath, "utf-8")
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return results;
|
|
1135
|
+
};
|
|
1136
|
+
return collectFiles(examplesDir, examplesDir).sort((a, b) => a.fileName.localeCompare(b.fileName));
|
|
1137
|
+
};
|
|
1138
|
+
var removeExampleFromResource = async (catalogDir, id, fileName, version) => {
|
|
1139
|
+
const pathToResource = await findFileById(catalogDir, id, version);
|
|
1140
|
+
if (!pathToResource) throw new Error("Cannot find resource");
|
|
1141
|
+
const examplesDir = (0, import_path.join)((0, import_path.dirname)(pathToResource), "examples");
|
|
1142
|
+
const examplePath = resolveExamplePath(examplesDir, fileName);
|
|
1143
|
+
if (!import_node_fs2.default.existsSync(examplePath)) {
|
|
1144
|
+
throw new Error(`Example file ${fileName} does not exist in resource ${id}${version ? ` v(${version})` : ""}`);
|
|
1145
|
+
}
|
|
1146
|
+
import_node_fs2.default.unlinkSync(examplePath);
|
|
1147
|
+
};
|
|
1099
1148
|
var isLatestVersion = async (catalogDir, id, version) => {
|
|
1100
1149
|
const resource = await getResource(catalogDir, id, version);
|
|
1101
1150
|
if (!resource) return false;
|
|
@@ -1136,6 +1185,9 @@ var eventHasVersion = (directory) => async (id, version) => {
|
|
|
1136
1185
|
const file = await findFileById(directory, id, version);
|
|
1137
1186
|
return !!file;
|
|
1138
1187
|
};
|
|
1188
|
+
var addExampleToEvent = (directory) => async (id, example, version) => addExampleToResource(directory, id, example, version);
|
|
1189
|
+
var getExamplesFromEvent = (directory) => async (id, version) => getExamplesFromResource(directory, id, version);
|
|
1190
|
+
var removeExampleFromEvent = (directory) => async (id, fileName, version) => removeExampleFromResource(directory, id, fileName, version);
|
|
1139
1191
|
|
|
1140
1192
|
// src/commands.ts
|
|
1141
1193
|
var import_promises3 = __toESM(require("fs/promises"));
|
|
@@ -1171,6 +1223,9 @@ var commandHasVersion = (directory) => async (id, version) => {
|
|
|
1171
1223
|
const file = await findFileById(directory, id, version);
|
|
1172
1224
|
return !!file;
|
|
1173
1225
|
};
|
|
1226
|
+
var addExampleToCommand = (directory) => async (id, example, version) => addExampleToResource(directory, id, example, version);
|
|
1227
|
+
var getExamplesFromCommand = (directory) => async (id, version) => getExamplesFromResource(directory, id, version);
|
|
1228
|
+
var removeExampleFromCommand = (directory) => async (id, fileName, version) => removeExampleFromResource(directory, id, fileName, version);
|
|
1174
1229
|
|
|
1175
1230
|
// src/queries.ts
|
|
1176
1231
|
var import_promises4 = __toESM(require("fs/promises"));
|
|
@@ -1208,6 +1263,9 @@ var queryHasVersion = (directory) => async (id, version) => {
|
|
|
1208
1263
|
const file = await findFileById(directory, id, version);
|
|
1209
1264
|
return !!file;
|
|
1210
1265
|
};
|
|
1266
|
+
var addExampleToQuery = (directory) => async (id, example, version) => addExampleToResource(directory, id, example, version);
|
|
1267
|
+
var getExamplesFromQuery = (directory) => async (id, version) => getExamplesFromResource(directory, id, version);
|
|
1268
|
+
var removeExampleFromQuery = (directory) => async (id, fileName, version) => removeExampleFromResource(directory, id, fileName, version);
|
|
1211
1269
|
|
|
1212
1270
|
// src/services.ts
|
|
1213
1271
|
var import_promises5 = __toESM(require("fs/promises"));
|
|
@@ -1983,6 +2041,7 @@ var dumpCatalog = (directory) => async (options) => {
|
|
|
1983
2041
|
// src/snapshots.ts
|
|
1984
2042
|
var import_node_fs8 = __toESM(require("fs"));
|
|
1985
2043
|
var import_node_path16 = __toESM(require("path"));
|
|
2044
|
+
var import_node_crypto = require("crypto");
|
|
1986
2045
|
var import_node_child_process = require("child_process");
|
|
1987
2046
|
var import_semver6 = require("semver");
|
|
1988
2047
|
|
|
@@ -2173,6 +2232,8 @@ var pickCoreFields = (resource) => {
|
|
|
2173
2232
|
if (resource.receives) picked.receives = resource.receives;
|
|
2174
2233
|
if (resource.deprecated) picked.deprecated = resource.deprecated;
|
|
2175
2234
|
if (resource.owners) picked.owners = resource.owners;
|
|
2235
|
+
if (resource.schemaPath) picked.schemaPath = resource.schemaPath;
|
|
2236
|
+
if (resource.schemaHash) picked.schemaHash = resource.schemaHash;
|
|
2176
2237
|
return picked;
|
|
2177
2238
|
};
|
|
2178
2239
|
var deduplicateByLatestVersion = (resources) => {
|
|
@@ -2200,6 +2261,16 @@ var detectGitInfo = (catalogDir) => {
|
|
|
2200
2261
|
return void 0;
|
|
2201
2262
|
}
|
|
2202
2263
|
};
|
|
2264
|
+
var enrichWithSchemaHashes = async (getSchemaForMessage2, resources) => {
|
|
2265
|
+
await Promise.all(
|
|
2266
|
+
resources.map(async (resource) => {
|
|
2267
|
+
if (!resource.schemaPath) return;
|
|
2268
|
+
const schema = await getSchemaForMessage2(resource.id, resource.version);
|
|
2269
|
+
if (!schema) return;
|
|
2270
|
+
resource.schemaHash = (0, import_node_crypto.createHash)("sha256").update(schema.schema).digest("hex");
|
|
2271
|
+
})
|
|
2272
|
+
);
|
|
2273
|
+
};
|
|
2203
2274
|
var createSnapshot = (directory) => {
|
|
2204
2275
|
return async (options) => {
|
|
2205
2276
|
const { label, outputDir, git } = options || {};
|
|
@@ -2212,6 +2283,11 @@ var createSnapshot = (directory) => {
|
|
|
2212
2283
|
sdk.getQueries(),
|
|
2213
2284
|
sdk.getChannels()
|
|
2214
2285
|
]);
|
|
2286
|
+
await Promise.all([
|
|
2287
|
+
enrichWithSchemaHashes(sdk.getSchemaForMessage, events || []),
|
|
2288
|
+
enrichWithSchemaHashes(sdk.getSchemaForMessage, commands || []),
|
|
2289
|
+
enrichWithSchemaHashes(sdk.getSchemaForMessage, queries || [])
|
|
2290
|
+
]);
|
|
2215
2291
|
const snapshotDomains = stripToCore(domains);
|
|
2216
2292
|
const snapshotServices = stripToCore(services);
|
|
2217
2293
|
const snapshotEvents = stripToCore(events);
|
|
@@ -2574,6 +2650,9 @@ var src_default = (path8) => {
|
|
|
2574
2650
|
* @returns
|
|
2575
2651
|
*/
|
|
2576
2652
|
eventHasVersion: eventHasVersion((0, import_node_path22.join)(path8)),
|
|
2653
|
+
addExampleToEvent: addExampleToEvent((0, import_node_path22.join)(path8)),
|
|
2654
|
+
getExamplesFromEvent: getExamplesFromEvent((0, import_node_path22.join)(path8)),
|
|
2655
|
+
removeExampleFromEvent: removeExampleFromEvent((0, import_node_path22.join)(path8)),
|
|
2577
2656
|
/**
|
|
2578
2657
|
* ================================
|
|
2579
2658
|
* Commands
|
|
@@ -2651,6 +2730,9 @@ var src_default = (path8) => {
|
|
|
2651
2730
|
* @returns
|
|
2652
2731
|
*/
|
|
2653
2732
|
commandHasVersion: commandHasVersion((0, import_node_path22.join)(path8)),
|
|
2733
|
+
addExampleToCommand: addExampleToCommand((0, import_node_path22.join)(path8)),
|
|
2734
|
+
getExamplesFromCommand: getExamplesFromCommand((0, import_node_path22.join)(path8)),
|
|
2735
|
+
removeExampleFromCommand: removeExampleFromCommand((0, import_node_path22.join)(path8)),
|
|
2654
2736
|
/**
|
|
2655
2737
|
* ================================
|
|
2656
2738
|
* Queries
|
|
@@ -2728,6 +2810,9 @@ var src_default = (path8) => {
|
|
|
2728
2810
|
* @returns
|
|
2729
2811
|
*/
|
|
2730
2812
|
queryHasVersion: queryHasVersion((0, import_node_path22.join)(path8)),
|
|
2813
|
+
addExampleToQuery: addExampleToQuery((0, import_node_path22.join)(path8)),
|
|
2814
|
+
getExamplesFromQuery: getExamplesFromQuery((0, import_node_path22.join)(path8)),
|
|
2815
|
+
removeExampleFromQuery: removeExampleFromQuery((0, import_node_path22.join)(path8)),
|
|
2731
2816
|
/**
|
|
2732
2817
|
* ================================
|
|
2733
2818
|
* Channels
|