@eventcatalog/sdk 2.11.0 → 2.12.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/README.md +86 -1
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/{eventcatalog.js → cli/index.js} +588 -378
- package/dist/cli/index.js.map +1 -0
- package/dist/{eventcatalog.mjs → cli/index.mjs} +666 -436
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cli-docs.d.mts +43 -0
- package/dist/cli-docs.d.ts +43 -0
- package/dist/cli-docs.js +1614 -0
- package/dist/cli-docs.js.map +1 -0
- package/dist/cli-docs.mjs +1586 -0
- package/dist/cli-docs.mjs.map +1 -0
- package/dist/index.d.mts +443 -25
- package/dist/index.d.ts +443 -25
- package/dist/index.js +204 -121
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -4
- package/dist/channels.d.mts +0 -214
- package/dist/channels.d.ts +0 -214
- package/dist/channels.js +0 -432
- package/dist/channels.js.map +0 -1
- package/dist/channels.mjs +0 -384
- package/dist/channels.mjs.map +0 -1
- package/dist/commands.d.mts +0 -274
- package/dist/commands.d.ts +0 -274
- package/dist/commands.js +0 -394
- package/dist/commands.js.map +0 -1
- package/dist/commands.mjs +0 -350
- package/dist/commands.mjs.map +0 -1
- package/dist/containers.d.mts +0 -179
- package/dist/containers.d.ts +0 -179
- package/dist/containers.js +0 -388
- package/dist/containers.js.map +0 -1
- package/dist/containers.mjs +0 -345
- package/dist/containers.mjs.map +0 -1
- package/dist/custom-docs.d.mts +0 -89
- package/dist/custom-docs.d.ts +0 -89
- package/dist/custom-docs.js +0 -164
- package/dist/custom-docs.js.map +0 -1
- package/dist/custom-docs.mjs +0 -122
- package/dist/custom-docs.mjs.map +0 -1
- package/dist/data-products.d.mts +0 -225
- package/dist/data-products.d.ts +0 -225
- package/dist/data-products.js +0 -375
- package/dist/data-products.js.map +0 -1
- package/dist/data-products.mjs +0 -332
- package/dist/data-products.mjs.map +0 -1
- package/dist/data-stores.d.mts +0 -179
- package/dist/data-stores.d.ts +0 -179
- package/dist/data-stores.js +0 -401
- package/dist/data-stores.js.map +0 -1
- package/dist/data-stores.mjs +0 -356
- package/dist/data-stores.mjs.map +0 -1
- package/dist/domains.d.mts +0 -347
- package/dist/domains.d.ts +0 -347
- package/dist/domains.js +0 -547
- package/dist/domains.js.map +0 -1
- package/dist/domains.mjs +0 -498
- package/dist/domains.mjs.map +0 -1
- package/dist/entities.d.mts +0 -174
- package/dist/entities.d.ts +0 -174
- package/dist/entities.js +0 -348
- package/dist/entities.js.map +0 -1
- package/dist/entities.mjs +0 -307
- package/dist/entities.mjs.map +0 -1
- package/dist/eventcatalog.d.mts +0 -21
- package/dist/eventcatalog.d.ts +0 -21
- package/dist/eventcatalog.js.map +0 -1
- package/dist/eventcatalog.mjs.map +0 -1
- package/dist/events.d.mts +0 -276
- package/dist/events.d.ts +0 -276
- package/dist/events.js +0 -393
- package/dist/events.js.map +0 -1
- package/dist/events.mjs +0 -349
- package/dist/events.mjs.map +0 -1
- package/dist/messages.d.mts +0 -65
- package/dist/messages.d.ts +0 -65
- package/dist/messages.js +0 -312
- package/dist/messages.js.map +0 -1
- package/dist/messages.mjs +0 -269
- package/dist/messages.mjs.map +0 -1
- package/dist/queries.d.mts +0 -276
- package/dist/queries.d.ts +0 -276
- package/dist/queries.js +0 -394
- package/dist/queries.js.map +0 -1
- package/dist/queries.mjs +0 -350
- package/dist/queries.mjs.map +0 -1
- package/dist/services.d.mts +0 -384
- package/dist/services.d.ts +0 -384
- package/dist/services.js +0 -577
- package/dist/services.js.map +0 -1
- package/dist/services.mjs +0 -526
- package/dist/services.mjs.map +0 -1
- package/dist/teams.d.mts +0 -90
- package/dist/teams.d.ts +0 -90
- package/dist/teams.js +0 -246
- package/dist/teams.js.map +0 -1
- package/dist/teams.mjs +0 -202
- package/dist/teams.mjs.map +0 -1
- package/dist/types.d.d.mts +0 -331
- package/dist/types.d.d.ts +0 -331
- package/dist/types.d.js +0 -19
- package/dist/types.d.js.map +0 -1
- package/dist/types.d.mjs +0 -1
- package/dist/types.d.mjs.map +0 -1
- package/dist/users.d.mts +0 -83
- package/dist/users.d.ts +0 -83
- package/dist/users.js +0 -127
- package/dist/users.js.map +0 -1
- package/dist/users.mjs +0 -88
- package/dist/users.mjs.map +0 -1
package/dist/services.js
DELETED
|
@@ -1,577 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/services.ts
|
|
31
|
-
var services_exports = {};
|
|
32
|
-
__export(services_exports, {
|
|
33
|
-
addDataStoreToService: () => addDataStoreToService,
|
|
34
|
-
addEntityToService: () => addEntityToService,
|
|
35
|
-
addFileToService: () => addFileToService,
|
|
36
|
-
addMessageToService: () => addMessageToService,
|
|
37
|
-
getService: () => getService,
|
|
38
|
-
getServiceByPath: () => getServiceByPath,
|
|
39
|
-
getServices: () => getServices,
|
|
40
|
-
getSpecificationFilesForService: () => getSpecificationFilesForService,
|
|
41
|
-
isService: () => isService,
|
|
42
|
-
rmService: () => rmService,
|
|
43
|
-
rmServiceById: () => rmServiceById,
|
|
44
|
-
serviceHasVersion: () => serviceHasVersion,
|
|
45
|
-
toService: () => toService,
|
|
46
|
-
versionService: () => versionService,
|
|
47
|
-
writeService: () => writeService,
|
|
48
|
-
writeServiceToDomain: () => writeServiceToDomain,
|
|
49
|
-
writeVersionedService: () => writeVersionedService
|
|
50
|
-
});
|
|
51
|
-
module.exports = __toCommonJS(services_exports);
|
|
52
|
-
var import_promises2 = __toESM(require("fs/promises"));
|
|
53
|
-
var import_node_path4 = require("path");
|
|
54
|
-
|
|
55
|
-
// src/internal/resources.ts
|
|
56
|
-
var import_path = require("path");
|
|
57
|
-
|
|
58
|
-
// src/internal/utils.ts
|
|
59
|
-
var import_glob = require("glob");
|
|
60
|
-
var import_node_fs = __toESM(require("fs"));
|
|
61
|
-
var import_fs_extra = require("fs-extra");
|
|
62
|
-
var import_node_path = require("path");
|
|
63
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
64
|
-
var import_semver = require("semver");
|
|
65
|
-
var versionExists = async (catalogDir, id, version) => {
|
|
66
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
67
|
-
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
68
|
-
return matchedFiles.length > 0;
|
|
69
|
-
};
|
|
70
|
-
var findFileById = async (catalogDir, id, version) => {
|
|
71
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
72
|
-
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
73
|
-
const latestVersion = matchedFiles.find((path2) => !path2.includes("versioned"));
|
|
74
|
-
if (!version) {
|
|
75
|
-
return latestVersion;
|
|
76
|
-
}
|
|
77
|
-
const parsedFiles = matchedFiles.map((path2) => {
|
|
78
|
-
const { data } = import_gray_matter.default.read(path2);
|
|
79
|
-
return { ...data, path: path2 };
|
|
80
|
-
});
|
|
81
|
-
if (version === "latest") {
|
|
82
|
-
return latestVersion;
|
|
83
|
-
}
|
|
84
|
-
const exactMatch = parsedFiles.find((c) => c.version === version);
|
|
85
|
-
if (exactMatch) {
|
|
86
|
-
return exactMatch.path;
|
|
87
|
-
}
|
|
88
|
-
const semverRange = (0, import_semver.validRange)(version);
|
|
89
|
-
if (semverRange) {
|
|
90
|
-
const match = parsedFiles.filter((c) => {
|
|
91
|
-
try {
|
|
92
|
-
return (0, import_semver.satisfies)(c.version, semverRange);
|
|
93
|
-
} catch (error) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return match.length > 0 ? match[0].path : void 0;
|
|
98
|
-
}
|
|
99
|
-
return void 0;
|
|
100
|
-
};
|
|
101
|
-
var getFiles = async (pattern, ignore = "") => {
|
|
102
|
-
try {
|
|
103
|
-
const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
|
|
104
|
-
const absoluteBaseDir = (0, import_node_path.resolve)(
|
|
105
|
-
normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
|
|
106
|
-
);
|
|
107
|
-
let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
|
|
108
|
-
relativePattern = relativePattern.replace(/\\/g, "/");
|
|
109
|
-
const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
|
|
110
|
-
const files = (0, import_glob.globSync)(relativePattern, {
|
|
111
|
-
cwd: absoluteBaseDir,
|
|
112
|
-
ignore: ["node_modules/**", ...ignoreList],
|
|
113
|
-
absolute: true,
|
|
114
|
-
nodir: true
|
|
115
|
-
});
|
|
116
|
-
return files.map(import_node_path.normalize);
|
|
117
|
-
} catch (error) {
|
|
118
|
-
const absoluteBaseDirForError = (0, import_node_path.resolve)(
|
|
119
|
-
(0, import_node_path.normalize)(pattern).includes("**") ? (0, import_node_path.normalize)(pattern).split("**")[0] : (0, import_node_path.dirname)((0, import_node_path.normalize)(pattern))
|
|
120
|
-
);
|
|
121
|
-
const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
|
|
122
|
-
throw new Error(
|
|
123
|
-
`Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
var searchFilesForId = async (files, id, version) => {
|
|
128
|
-
const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
129
|
-
const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${escapedId}['"]?\\s*$`, "m");
|
|
130
|
-
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
131
|
-
const matches = files.map((file) => {
|
|
132
|
-
const content = import_node_fs.default.readFileSync(file, "utf-8");
|
|
133
|
-
const hasIdMatch = content.match(idRegex);
|
|
134
|
-
if (version && !content.match(versionRegex)) {
|
|
135
|
-
return void 0;
|
|
136
|
-
}
|
|
137
|
-
if (hasIdMatch) {
|
|
138
|
-
return file;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
142
|
-
};
|
|
143
|
-
var copyDir = async (catalogDir, source, target, filter) => {
|
|
144
|
-
const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
|
|
145
|
-
import_node_fs.default.mkdirSync(tmpDirectory, { recursive: true });
|
|
146
|
-
await (0, import_fs_extra.copy)(source, tmpDirectory, {
|
|
147
|
-
overwrite: true,
|
|
148
|
-
filter
|
|
149
|
-
});
|
|
150
|
-
await (0, import_fs_extra.copy)(tmpDirectory, target, {
|
|
151
|
-
overwrite: true,
|
|
152
|
-
filter
|
|
153
|
-
});
|
|
154
|
-
import_node_fs.default.rmSync(tmpDirectory, { recursive: true });
|
|
155
|
-
};
|
|
156
|
-
var uniqueVersions = (messages) => {
|
|
157
|
-
const uniqueSet = /* @__PURE__ */ new Set();
|
|
158
|
-
return messages.filter((message) => {
|
|
159
|
-
const key = `${message.id}-${message.version}`;
|
|
160
|
-
if (!uniqueSet.has(key)) {
|
|
161
|
-
uniqueSet.add(key);
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// src/internal/resources.ts
|
|
169
|
-
var import_gray_matter2 = __toESM(require("gray-matter"));
|
|
170
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
171
|
-
var import_node_fs2 = __toESM(require("fs"));
|
|
172
|
-
var import_semver2 = require("semver");
|
|
173
|
-
var import_proper_lockfile = require("proper-lockfile");
|
|
174
|
-
var import_node_path2 = require("path");
|
|
175
|
-
var import_node_path3 = __toESM(require("path"));
|
|
176
|
-
var versionResource = async (catalogDir, id) => {
|
|
177
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
178
|
-
const matchedFiles = await searchFilesForId(files, id);
|
|
179
|
-
if (matchedFiles.length === 0) {
|
|
180
|
-
throw new Error(`No resource found with id: ${id}`);
|
|
181
|
-
}
|
|
182
|
-
const file = matchedFiles[0];
|
|
183
|
-
const sourceDirectory = (0, import_path.dirname)(file).replace(/[/\\]versioned[/\\][^/\\]+[/\\]/, import_node_path3.default.sep);
|
|
184
|
-
const { data: { version = "0.0.1" } = {} } = import_gray_matter2.default.read(file);
|
|
185
|
-
const targetDirectory = getVersionedDirectory(sourceDirectory, version);
|
|
186
|
-
import_node_fs2.default.mkdirSync(targetDirectory, { recursive: true });
|
|
187
|
-
const ignoreListToCopy = ["events", "commands", "queries", "versioned"];
|
|
188
|
-
await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {
|
|
189
|
-
const folderName = (0, import_node_path2.basename)(src);
|
|
190
|
-
if (ignoreListToCopy.includes(folderName)) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
return true;
|
|
194
|
-
});
|
|
195
|
-
await import_promises.default.readdir(sourceDirectory).then(async (resourceFiles) => {
|
|
196
|
-
await Promise.all(
|
|
197
|
-
resourceFiles.map(async (file2) => {
|
|
198
|
-
if (ignoreListToCopy.includes(file2)) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (file2 !== "versioned") {
|
|
202
|
-
import_node_fs2.default.rmSync((0, import_path.join)(sourceDirectory, file2), { recursive: true });
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
);
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
var writeResource = async (catalogDir, resource, options = {
|
|
209
|
-
path: "",
|
|
210
|
-
type: "",
|
|
211
|
-
override: false,
|
|
212
|
-
versionExistingContent: false,
|
|
213
|
-
format: "mdx"
|
|
214
|
-
}) => {
|
|
215
|
-
const path2 = options.path || `/${resource.id}`;
|
|
216
|
-
const fullPath = (0, import_path.join)(catalogDir, path2);
|
|
217
|
-
const format = options.format || "mdx";
|
|
218
|
-
import_node_fs2.default.mkdirSync(fullPath, { recursive: true });
|
|
219
|
-
const lockPath = (0, import_path.join)(fullPath, `index.${format}`);
|
|
220
|
-
if (!import_node_fs2.default.existsSync(lockPath)) {
|
|
221
|
-
import_node_fs2.default.writeFileSync(lockPath, "");
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
await (0, import_proper_lockfile.lock)(lockPath, {
|
|
225
|
-
retries: 5,
|
|
226
|
-
stale: 1e4
|
|
227
|
-
// 10 seconds
|
|
228
|
-
});
|
|
229
|
-
const exists = await versionExists(catalogDir, resource.id, resource.version);
|
|
230
|
-
if (exists && !options.override) {
|
|
231
|
-
throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
|
|
232
|
-
}
|
|
233
|
-
const { markdown, ...frontmatter } = resource;
|
|
234
|
-
if (options.versionExistingContent && !exists) {
|
|
235
|
-
const currentResource = await getResource(catalogDir, resource.id);
|
|
236
|
-
if (currentResource) {
|
|
237
|
-
if ((0, import_semver2.satisfies)(resource.version, `>${currentResource.version}`)) {
|
|
238
|
-
await versionResource(catalogDir, resource.id);
|
|
239
|
-
} else {
|
|
240
|
-
throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
|
|
245
|
-
import_node_fs2.default.writeFileSync(lockPath, document);
|
|
246
|
-
} finally {
|
|
247
|
-
await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
var getResource = async (catalogDir, id, version, options, filePath) => {
|
|
252
|
-
const attachSchema = options?.attachSchema || false;
|
|
253
|
-
const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
|
|
254
|
-
if (!file || !import_node_fs2.default.existsSync(file)) return;
|
|
255
|
-
const { data, content } = import_gray_matter2.default.read(file);
|
|
256
|
-
if (attachSchema && data?.schemaPath) {
|
|
257
|
-
const resourceDirectory = (0, import_path.dirname)(file);
|
|
258
|
-
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
259
|
-
if (import_node_fs2.default.existsSync(pathToSchema)) {
|
|
260
|
-
const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
|
|
261
|
-
try {
|
|
262
|
-
data.schema = JSON.parse(schema);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
data.schema = schema;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return {
|
|
269
|
-
...data,
|
|
270
|
-
markdown: content.trim()
|
|
271
|
-
};
|
|
272
|
-
};
|
|
273
|
-
var getResourcePath = async (catalogDir, id, version) => {
|
|
274
|
-
const file = await findFileById(catalogDir, id, version);
|
|
275
|
-
if (!file) return;
|
|
276
|
-
return {
|
|
277
|
-
fullPath: file,
|
|
278
|
-
relativePath: file.replace(catalogDir, ""),
|
|
279
|
-
directory: (0, import_path.dirname)(file.replace(catalogDir, ""))
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
var toResource = async (catalogDir, rawContents) => {
|
|
283
|
-
const { data, content } = (0, import_gray_matter2.default)(rawContents);
|
|
284
|
-
return {
|
|
285
|
-
...data,
|
|
286
|
-
markdown: content.trim()
|
|
287
|
-
};
|
|
288
|
-
};
|
|
289
|
-
var getResources = async (catalogDir, {
|
|
290
|
-
type,
|
|
291
|
-
latestOnly = false,
|
|
292
|
-
ignore = [],
|
|
293
|
-
pattern = "",
|
|
294
|
-
attachSchema = false
|
|
295
|
-
}) => {
|
|
296
|
-
const ignoreList = latestOnly ? `**/versioned/**` : "";
|
|
297
|
-
const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
|
|
298
|
-
const files = await getFiles(filePattern, [ignoreList, ...ignore]);
|
|
299
|
-
if (files.length === 0) return;
|
|
300
|
-
return files.map((file) => {
|
|
301
|
-
const { data, content } = import_gray_matter2.default.read(file);
|
|
302
|
-
if (attachSchema && data?.schemaPath) {
|
|
303
|
-
const resourceDirectory = (0, import_path.dirname)(file);
|
|
304
|
-
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
305
|
-
if (import_node_fs2.default.existsSync(pathToSchema)) {
|
|
306
|
-
const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
|
|
307
|
-
try {
|
|
308
|
-
data.schema = JSON.parse(schema);
|
|
309
|
-
} catch (error) {
|
|
310
|
-
data.schema = schema;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
...data,
|
|
316
|
-
markdown: content.trim()
|
|
317
|
-
};
|
|
318
|
-
});
|
|
319
|
-
};
|
|
320
|
-
var rmResourceById = async (catalogDir, id, version, options) => {
|
|
321
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
322
|
-
const matchedFiles = await searchFilesForId(files, id, version);
|
|
323
|
-
if (matchedFiles.length === 0) {
|
|
324
|
-
throw new Error(`No ${options?.type || "resource"} found with id: ${id}`);
|
|
325
|
-
}
|
|
326
|
-
if (options?.persistFiles) {
|
|
327
|
-
await Promise.all(
|
|
328
|
-
matchedFiles.map(async (file) => {
|
|
329
|
-
await import_promises.default.rm(file, { recursive: true });
|
|
330
|
-
await waitForFileRemoval(file);
|
|
331
|
-
})
|
|
332
|
-
);
|
|
333
|
-
} else {
|
|
334
|
-
await Promise.all(
|
|
335
|
-
matchedFiles.map(async (file) => {
|
|
336
|
-
const directory = (0, import_path.dirname)(file);
|
|
337
|
-
await import_promises.default.rm(directory, { recursive: true, force: true });
|
|
338
|
-
await waitForFileRemoval(directory);
|
|
339
|
-
})
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
var waitForFileRemoval = async (path2, maxRetries = 50, delay = 10) => {
|
|
344
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
345
|
-
try {
|
|
346
|
-
await import_promises.default.access(path2);
|
|
347
|
-
await new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
348
|
-
} catch (error) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
throw new Error(`File/directory ${path2} was not removed after ${maxRetries} attempts`);
|
|
353
|
-
};
|
|
354
|
-
var addFileToResource = async (catalogDir, id, file, version, options) => {
|
|
355
|
-
let pathToResource;
|
|
356
|
-
if (options?.path) {
|
|
357
|
-
pathToResource = (0, import_path.join)(catalogDir, options.path, "index.mdx");
|
|
358
|
-
} else {
|
|
359
|
-
pathToResource = await findFileById(catalogDir, id, version);
|
|
360
|
-
}
|
|
361
|
-
if (!pathToResource) throw new Error("Cannot find directory to write file to");
|
|
362
|
-
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(pathToResource), { recursive: true });
|
|
363
|
-
let fileContent = file.content.trim();
|
|
364
|
-
try {
|
|
365
|
-
const json = JSON.parse(fileContent);
|
|
366
|
-
fileContent = JSON.stringify(json, null, 2);
|
|
367
|
-
} catch (error) {
|
|
368
|
-
}
|
|
369
|
-
import_node_fs2.default.writeFileSync((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName), fileContent);
|
|
370
|
-
};
|
|
371
|
-
var getFileFromResource = async (catalogDir, id, file, version) => {
|
|
372
|
-
const pathToResource = await findFileById(catalogDir, id, version);
|
|
373
|
-
if (!pathToResource) throw new Error("Cannot find directory of resource");
|
|
374
|
-
const exists = await import_promises.default.access((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName)).then(() => true).catch(() => false);
|
|
375
|
-
if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);
|
|
376
|
-
return import_node_fs2.default.readFileSync((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName), "utf-8");
|
|
377
|
-
};
|
|
378
|
-
var getVersionedDirectory = (sourceDirectory, version) => {
|
|
379
|
-
return (0, import_path.join)(sourceDirectory, "versioned", version);
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// src/services.ts
|
|
383
|
-
var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
|
|
384
|
-
var getServiceByPath = (directory) => async (path2) => {
|
|
385
|
-
const service = await getResource(directory, void 0, void 0, { type: "service" }, path2);
|
|
386
|
-
return service;
|
|
387
|
-
};
|
|
388
|
-
var getServices = (directory) => async (options) => getResources(directory, {
|
|
389
|
-
type: "services",
|
|
390
|
-
ignore: ["**/events/**", "**/commands/**", "**/queries/**", "**/entities/**", "**/subdomains/**/entities/**"],
|
|
391
|
-
...options
|
|
392
|
-
});
|
|
393
|
-
var writeService = (directory) => async (service, options = {
|
|
394
|
-
path: "",
|
|
395
|
-
override: false,
|
|
396
|
-
format: "mdx"
|
|
397
|
-
}) => {
|
|
398
|
-
const resource = { ...service };
|
|
399
|
-
if (Array.isArray(service.sends)) {
|
|
400
|
-
resource.sends = uniqueVersions(service.sends);
|
|
401
|
-
}
|
|
402
|
-
if (Array.isArray(service.receives)) {
|
|
403
|
-
resource.receives = uniqueVersions(service.receives);
|
|
404
|
-
}
|
|
405
|
-
return await writeResource(directory, resource, { ...options, type: "service" });
|
|
406
|
-
};
|
|
407
|
-
var writeVersionedService = (directory) => async (service) => {
|
|
408
|
-
const resource = { ...service };
|
|
409
|
-
const path2 = getVersionedDirectory(service.id, service.version);
|
|
410
|
-
return await writeService(directory)(resource, { path: path2 });
|
|
411
|
-
};
|
|
412
|
-
var writeServiceToDomain = (directory) => async (service, domain, options = { path: "", format: "mdx", override: false }) => {
|
|
413
|
-
let pathForService = domain.version && domain.version !== "latest" ? `/${domain.id}/versioned/${domain.version}/services` : `/${domain.id}/services`;
|
|
414
|
-
pathForService = (0, import_node_path4.join)(pathForService, service.id);
|
|
415
|
-
await writeResource(directory, { ...service }, { ...options, path: pathForService, type: "service" });
|
|
416
|
-
};
|
|
417
|
-
var versionService = (directory) => async (id) => versionResource(directory, id);
|
|
418
|
-
var rmService = (directory) => async (path2) => {
|
|
419
|
-
await import_promises2.default.rm((0, import_node_path4.join)(directory, path2), { recursive: true });
|
|
420
|
-
};
|
|
421
|
-
var rmServiceById = (directory) => async (id, version, persistFiles) => {
|
|
422
|
-
await rmResourceById(directory, id, version, { type: "service", persistFiles });
|
|
423
|
-
};
|
|
424
|
-
var addFileToService = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
|
|
425
|
-
var getSpecificationFilesForService = (directory) => async (id, version) => {
|
|
426
|
-
let service = await getService(directory)(id, version);
|
|
427
|
-
const filePathToService = await findFileById(directory, id, version);
|
|
428
|
-
if (!filePathToService) throw new Error("Cannot find directory of service");
|
|
429
|
-
let specs = [];
|
|
430
|
-
if (service.specifications) {
|
|
431
|
-
const serviceSpecifications = service.specifications;
|
|
432
|
-
let specificationFiles;
|
|
433
|
-
if (Array.isArray(serviceSpecifications)) {
|
|
434
|
-
specificationFiles = serviceSpecifications.map((spec) => ({ key: spec.type, path: spec.path }));
|
|
435
|
-
} else {
|
|
436
|
-
specificationFiles = Object.keys(serviceSpecifications).map((spec) => ({
|
|
437
|
-
key: spec,
|
|
438
|
-
path: serviceSpecifications[spec]
|
|
439
|
-
}));
|
|
440
|
-
}
|
|
441
|
-
const getSpecs = specificationFiles.map(async ({ key, path: fileName }) => {
|
|
442
|
-
if (!fileName) {
|
|
443
|
-
throw new Error(`Specification file name for ${fileName} is undefined`);
|
|
444
|
-
}
|
|
445
|
-
const rawFile = await getFileFromResource(directory, id, { fileName }, version);
|
|
446
|
-
return { key, content: rawFile, fileName, path: (0, import_node_path4.join)((0, import_node_path4.dirname)(filePathToService), fileName) };
|
|
447
|
-
});
|
|
448
|
-
specs = await Promise.all(getSpecs);
|
|
449
|
-
}
|
|
450
|
-
return specs;
|
|
451
|
-
};
|
|
452
|
-
var addMessageToService = (directory) => async (id, direction, event, version) => {
|
|
453
|
-
let service = await getService(directory)(id, version);
|
|
454
|
-
const servicePath = await getResourcePath(directory, id, version);
|
|
455
|
-
const extension = (0, import_node_path4.extname)(servicePath?.fullPath || "");
|
|
456
|
-
if (direction === "sends") {
|
|
457
|
-
if (service.sends === void 0) {
|
|
458
|
-
service.sends = [];
|
|
459
|
-
}
|
|
460
|
-
for (let i = 0; i < service.sends.length; i++) {
|
|
461
|
-
if (service.sends[i].id === event.id && service.sends[i].version === event.version) {
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
service.sends.push({ id: event.id, version: event.version });
|
|
466
|
-
} else if (direction === "receives") {
|
|
467
|
-
if (service.receives === void 0) {
|
|
468
|
-
service.receives = [];
|
|
469
|
-
}
|
|
470
|
-
for (let i = 0; i < service.receives.length; i++) {
|
|
471
|
-
if (service.receives[i].id === event.id && service.receives[i].version === event.version) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
service.receives.push({ id: event.id, version: event.version });
|
|
476
|
-
} else {
|
|
477
|
-
throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);
|
|
478
|
-
}
|
|
479
|
-
const existingResource = await findFileById(directory, id, version);
|
|
480
|
-
if (!existingResource) {
|
|
481
|
-
throw new Error(`Cannot find service ${id} in the catalog`);
|
|
482
|
-
}
|
|
483
|
-
const path2 = existingResource.split(/[\\/]+services/)[0];
|
|
484
|
-
const pathToResource = (0, import_node_path4.join)(path2, "services");
|
|
485
|
-
await rmServiceById(directory)(id, version);
|
|
486
|
-
await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
|
|
487
|
-
};
|
|
488
|
-
var serviceHasVersion = (directory) => async (id, version) => {
|
|
489
|
-
const file = await findFileById(directory, id, version);
|
|
490
|
-
return !!file;
|
|
491
|
-
};
|
|
492
|
-
var isService = (directory) => async (path2) => {
|
|
493
|
-
const service = await getServiceByPath(directory)(path2);
|
|
494
|
-
const relativePath = (0, import_node_path4.relative)(directory, path2);
|
|
495
|
-
const segments = relativePath.split(/[/\\]+/);
|
|
496
|
-
return !!service && segments.includes("services");
|
|
497
|
-
};
|
|
498
|
-
var toService = (directory) => async (file) => toResource(directory, file);
|
|
499
|
-
var addEntityToService = (directory) => async (id, entity, version) => {
|
|
500
|
-
let service = await getService(directory)(id, version);
|
|
501
|
-
const servicePath = await getResourcePath(directory, id, version);
|
|
502
|
-
const extension = (0, import_node_path4.extname)(servicePath?.fullPath || "");
|
|
503
|
-
if (service.entities === void 0) {
|
|
504
|
-
service.entities = [];
|
|
505
|
-
}
|
|
506
|
-
for (let i = 0; i < service.entities.length; i++) {
|
|
507
|
-
if (service.entities[i].id === entity.id && service.entities[i].version === entity.version) {
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
service.entities.push({ id: entity.id, version: entity.version });
|
|
512
|
-
const existingResource = await findFileById(directory, id, version);
|
|
513
|
-
if (!existingResource) {
|
|
514
|
-
throw new Error(`Cannot find service ${id} in the catalog`);
|
|
515
|
-
}
|
|
516
|
-
const path2 = existingResource.split(/[\\/]+services/)[0];
|
|
517
|
-
const pathToResource = (0, import_node_path4.join)(path2, "services");
|
|
518
|
-
await rmServiceById(directory)(id, version);
|
|
519
|
-
await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
|
|
520
|
-
};
|
|
521
|
-
var addDataStoreToService = (directory) => async (id, operation, dataStore, version) => {
|
|
522
|
-
let service = await getService(directory)(id, version);
|
|
523
|
-
const servicePath = await getResourcePath(directory, id, version);
|
|
524
|
-
const extension = (0, import_node_path4.extname)(servicePath?.fullPath || "");
|
|
525
|
-
if (operation === "writesTo") {
|
|
526
|
-
if (service.writesTo === void 0) {
|
|
527
|
-
service.writesTo = [];
|
|
528
|
-
}
|
|
529
|
-
for (let i = 0; i < service.writesTo.length; i++) {
|
|
530
|
-
if (service.writesTo[i].id === dataStore.id && service.writesTo[i].version === dataStore.version) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
service.writesTo.push({ id: dataStore.id, version: dataStore.version });
|
|
535
|
-
} else if (operation === "readsFrom") {
|
|
536
|
-
if (service.readsFrom === void 0) {
|
|
537
|
-
service.readsFrom = [];
|
|
538
|
-
}
|
|
539
|
-
for (let i = 0; i < service.readsFrom.length; i++) {
|
|
540
|
-
if (service.readsFrom[i].id === dataStore.id && service.readsFrom[i].version === dataStore.version) {
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
service.readsFrom.push({ id: dataStore.id, version: dataStore.version });
|
|
545
|
-
} else {
|
|
546
|
-
throw new Error(`Operation ${operation} is invalid, only 'writesTo' and 'readsFrom' are supported`);
|
|
547
|
-
}
|
|
548
|
-
const existingResource = await findFileById(directory, id, version);
|
|
549
|
-
if (!existingResource) {
|
|
550
|
-
throw new Error(`Cannot find service ${id} in the catalog`);
|
|
551
|
-
}
|
|
552
|
-
const path2 = existingResource.split(/[\\/]+services/)[0];
|
|
553
|
-
const pathToResource = (0, import_node_path4.join)(path2, "services");
|
|
554
|
-
await rmServiceById(directory)(id, version);
|
|
555
|
-
await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
|
|
556
|
-
};
|
|
557
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
558
|
-
0 && (module.exports = {
|
|
559
|
-
addDataStoreToService,
|
|
560
|
-
addEntityToService,
|
|
561
|
-
addFileToService,
|
|
562
|
-
addMessageToService,
|
|
563
|
-
getService,
|
|
564
|
-
getServiceByPath,
|
|
565
|
-
getServices,
|
|
566
|
-
getSpecificationFilesForService,
|
|
567
|
-
isService,
|
|
568
|
-
rmService,
|
|
569
|
-
rmServiceById,
|
|
570
|
-
serviceHasVersion,
|
|
571
|
-
toService,
|
|
572
|
-
versionService,
|
|
573
|
-
writeService,
|
|
574
|
-
writeServiceToDomain,
|
|
575
|
-
writeVersionedService
|
|
576
|
-
});
|
|
577
|
-
//# sourceMappingURL=services.js.map
|