@eventcatalog/sdk 2.17.3 → 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 +67 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1062,6 +1062,55 @@ var getFileFromResource = async (catalogDir, id, file, version) => {
|
|
|
1062
1062
|
var getVersionedDirectory = (sourceDirectory, version) => {
|
|
1063
1063
|
return join2(sourceDirectory, "versioned", version);
|
|
1064
1064
|
};
|
|
1065
|
+
var CONFIG_FILES = ["examples.config.yaml", "examples.config.yml", "examples.config.json"];
|
|
1066
|
+
function resolveExamplePath(examplesDir, fileName) {
|
|
1067
|
+
const resolved = path.resolve(examplesDir, fileName);
|
|
1068
|
+
if (!resolved.startsWith(path.resolve(examplesDir) + path.sep) && resolved !== path.resolve(examplesDir)) {
|
|
1069
|
+
throw new Error(`Invalid example fileName: path traversal detected in "${fileName}"`);
|
|
1070
|
+
}
|
|
1071
|
+
return resolved;
|
|
1072
|
+
}
|
|
1073
|
+
var addExampleToResource = async (catalogDir, id, example, version) => {
|
|
1074
|
+
const pathToResource = await findFileById(catalogDir, id, version);
|
|
1075
|
+
if (!pathToResource) throw new Error("Cannot find directory to write example to");
|
|
1076
|
+
const examplesDir = join2(dirname2(pathToResource), "examples");
|
|
1077
|
+
const targetPath = resolveExamplePath(examplesDir, example.fileName);
|
|
1078
|
+
fsSync2.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
1079
|
+
fsSync2.writeFileSync(targetPath, example.content);
|
|
1080
|
+
};
|
|
1081
|
+
var getExamplesFromResource = async (catalogDir, id, version) => {
|
|
1082
|
+
const pathToResource = await findFileById(catalogDir, id, version);
|
|
1083
|
+
if (!pathToResource) throw new Error("Cannot find resource");
|
|
1084
|
+
const examplesDir = join2(dirname2(pathToResource), "examples");
|
|
1085
|
+
if (!fsSync2.existsSync(examplesDir)) return [];
|
|
1086
|
+
const collectFiles = (dir, baseDir) => {
|
|
1087
|
+
const results = [];
|
|
1088
|
+
const entries = fsSync2.readdirSync(dir, { withFileTypes: true });
|
|
1089
|
+
for (const entry of entries) {
|
|
1090
|
+
const fullPath = join2(dir, entry.name);
|
|
1091
|
+
if (entry.isDirectory()) {
|
|
1092
|
+
results.push(...collectFiles(fullPath, baseDir));
|
|
1093
|
+
} else if (entry.isFile() && !CONFIG_FILES.includes(entry.name)) {
|
|
1094
|
+
results.push({
|
|
1095
|
+
fileName: path.relative(baseDir, fullPath),
|
|
1096
|
+
content: fsSync2.readFileSync(fullPath, "utf-8")
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return results;
|
|
1101
|
+
};
|
|
1102
|
+
return collectFiles(examplesDir, examplesDir).sort((a, b) => a.fileName.localeCompare(b.fileName));
|
|
1103
|
+
};
|
|
1104
|
+
var removeExampleFromResource = async (catalogDir, id, fileName, version) => {
|
|
1105
|
+
const pathToResource = await findFileById(catalogDir, id, version);
|
|
1106
|
+
if (!pathToResource) throw new Error("Cannot find resource");
|
|
1107
|
+
const examplesDir = join2(dirname2(pathToResource), "examples");
|
|
1108
|
+
const examplePath = resolveExamplePath(examplesDir, fileName);
|
|
1109
|
+
if (!fsSync2.existsSync(examplePath)) {
|
|
1110
|
+
throw new Error(`Example file ${fileName} does not exist in resource ${id}${version ? ` v(${version})` : ""}`);
|
|
1111
|
+
}
|
|
1112
|
+
fsSync2.unlinkSync(examplePath);
|
|
1113
|
+
};
|
|
1065
1114
|
var isLatestVersion = async (catalogDir, id, version) => {
|
|
1066
1115
|
const resource = await getResource(catalogDir, id, version);
|
|
1067
1116
|
if (!resource) return false;
|
|
@@ -1102,6 +1151,9 @@ var eventHasVersion = (directory) => async (id, version) => {
|
|
|
1102
1151
|
const file = await findFileById(directory, id, version);
|
|
1103
1152
|
return !!file;
|
|
1104
1153
|
};
|
|
1154
|
+
var addExampleToEvent = (directory) => async (id, example, version) => addExampleToResource(directory, id, example, version);
|
|
1155
|
+
var getExamplesFromEvent = (directory) => async (id, version) => getExamplesFromResource(directory, id, version);
|
|
1156
|
+
var removeExampleFromEvent = (directory) => async (id, fileName, version) => removeExampleFromResource(directory, id, fileName, version);
|
|
1105
1157
|
|
|
1106
1158
|
// src/commands.ts
|
|
1107
1159
|
import fs3 from "fs/promises";
|
|
@@ -1137,6 +1189,9 @@ var commandHasVersion = (directory) => async (id, version) => {
|
|
|
1137
1189
|
const file = await findFileById(directory, id, version);
|
|
1138
1190
|
return !!file;
|
|
1139
1191
|
};
|
|
1192
|
+
var addExampleToCommand = (directory) => async (id, example, version) => addExampleToResource(directory, id, example, version);
|
|
1193
|
+
var getExamplesFromCommand = (directory) => async (id, version) => getExamplesFromResource(directory, id, version);
|
|
1194
|
+
var removeExampleFromCommand = (directory) => async (id, fileName, version) => removeExampleFromResource(directory, id, fileName, version);
|
|
1140
1195
|
|
|
1141
1196
|
// src/queries.ts
|
|
1142
1197
|
import fs4 from "fs/promises";
|
|
@@ -1174,6 +1229,9 @@ var queryHasVersion = (directory) => async (id, version) => {
|
|
|
1174
1229
|
const file = await findFileById(directory, id, version);
|
|
1175
1230
|
return !!file;
|
|
1176
1231
|
};
|
|
1232
|
+
var addExampleToQuery = (directory) => async (id, example, version) => addExampleToResource(directory, id, example, version);
|
|
1233
|
+
var getExamplesFromQuery = (directory) => async (id, version) => getExamplesFromResource(directory, id, version);
|
|
1234
|
+
var removeExampleFromQuery = (directory) => async (id, fileName, version) => removeExampleFromResource(directory, id, fileName, version);
|
|
1177
1235
|
|
|
1178
1236
|
// src/services.ts
|
|
1179
1237
|
import fs5 from "fs/promises";
|
|
@@ -2558,6 +2616,9 @@ var src_default = (path8) => {
|
|
|
2558
2616
|
* @returns
|
|
2559
2617
|
*/
|
|
2560
2618
|
eventHasVersion: eventHasVersion(join18(path8)),
|
|
2619
|
+
addExampleToEvent: addExampleToEvent(join18(path8)),
|
|
2620
|
+
getExamplesFromEvent: getExamplesFromEvent(join18(path8)),
|
|
2621
|
+
removeExampleFromEvent: removeExampleFromEvent(join18(path8)),
|
|
2561
2622
|
/**
|
|
2562
2623
|
* ================================
|
|
2563
2624
|
* Commands
|
|
@@ -2635,6 +2696,9 @@ var src_default = (path8) => {
|
|
|
2635
2696
|
* @returns
|
|
2636
2697
|
*/
|
|
2637
2698
|
commandHasVersion: commandHasVersion(join18(path8)),
|
|
2699
|
+
addExampleToCommand: addExampleToCommand(join18(path8)),
|
|
2700
|
+
getExamplesFromCommand: getExamplesFromCommand(join18(path8)),
|
|
2701
|
+
removeExampleFromCommand: removeExampleFromCommand(join18(path8)),
|
|
2638
2702
|
/**
|
|
2639
2703
|
* ================================
|
|
2640
2704
|
* Queries
|
|
@@ -2712,6 +2776,9 @@ var src_default = (path8) => {
|
|
|
2712
2776
|
* @returns
|
|
2713
2777
|
*/
|
|
2714
2778
|
queryHasVersion: queryHasVersion(join18(path8)),
|
|
2779
|
+
addExampleToQuery: addExampleToQuery(join18(path8)),
|
|
2780
|
+
getExamplesFromQuery: getExamplesFromQuery(join18(path8)),
|
|
2781
|
+
removeExampleFromQuery: removeExampleFromQuery(join18(path8)),
|
|
2715
2782
|
/**
|
|
2716
2783
|
* ================================
|
|
2717
2784
|
* Channels
|