@eventcatalog/sdk 0.0.1 → 0.0.3
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 +0 -1
- package/dist/docs.d.mts +2 -0
- package/dist/docs.d.ts +2 -0
- package/dist/docs.js +181 -0
- package/dist/docs.js.map +1 -0
- package/dist/docs.mjs +138 -0
- package/dist/docs.mjs.map +1 -0
- package/dist/events.d.mts +171 -0
- package/dist/events.d.ts +171 -0
- package/dist/events.js +179 -0
- package/dist/events.js.map +1 -0
- package/dist/events.mjs +138 -0
- package/dist/events.mjs.map +1 -0
- package/dist/index.d.mts +70 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +222 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +191 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/utils.d.mts +19 -0
- package/dist/internal/utils.d.ts +19 -0
- package/dist/internal/utils.js +103 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/internal/utils.mjs +64 -0
- package/dist/internal/utils.mjs.map +1 -0
- package/dist/test/events.test.d.mts +2 -0
- package/dist/test/events.test.d.ts +2 -0
- package/dist/test/events.test.js +16828 -0
- package/dist/test/events.test.js.map +1 -0
- package/dist/test/events.test.mjs +16813 -0
- package/dist/test/events.test.mjs.map +1 -0
- package/dist/types.d.d.mts +20 -0
- package/dist/types.d.d.ts +20 -0
- package/dist/types.d.js +19 -0
- package/dist/types.d.js.map +1 -0
- package/dist/types.d.mjs +1 -0
- package/dist/types.d.mjs.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Event } from './types.d.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Init the SDK for EventCatalog
|
|
5
|
+
*
|
|
6
|
+
* @param path - The path to the EventCatalog directory
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: (path: string) => {
|
|
10
|
+
/**
|
|
11
|
+
* Returns an events from EventCatalog
|
|
12
|
+
* @param id - The id of the event to retrieve
|
|
13
|
+
* @param version - Optional id of the version to get
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getEvent: (id: string, version?: string) => Promise<Event>;
|
|
17
|
+
/**
|
|
18
|
+
* Adds an event to EventCatalog
|
|
19
|
+
*
|
|
20
|
+
* @param event - The event to write
|
|
21
|
+
* @param options - Optional options to write the event
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
writeEvent: (event: Event, options?: {
|
|
25
|
+
path: string;
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
|
|
29
|
+
*
|
|
30
|
+
* @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
rmEvent: (path: string) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Remove an event by an Event id
|
|
36
|
+
*
|
|
37
|
+
* @param id - The id of the event you want to remove
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
rmEventById: (id: string, version?: string) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Moves a given event id to the version directory
|
|
43
|
+
* @param directory
|
|
44
|
+
*/
|
|
45
|
+
versionEvent: (id: string) => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Adds a file to the given event
|
|
48
|
+
* @param id - The id of the event to add the file to
|
|
49
|
+
* @param file - File contents to add including the content and the file name
|
|
50
|
+
* @param version - Optional version of the event to add the file to
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
addFileToEvent: (id: string, file: {
|
|
54
|
+
content: string;
|
|
55
|
+
fileName: string;
|
|
56
|
+
}, version?: string) => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Adds a schema to the given event
|
|
59
|
+
* @param id - The id of the event to add the schema to
|
|
60
|
+
* @param schema - Schema contents to add including the content and the file name
|
|
61
|
+
* @param version - Optional version of the event to add the schema to
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
addSchemaToEvent: (id: string, schema: {
|
|
65
|
+
schema: string;
|
|
66
|
+
fileName: string;
|
|
67
|
+
}, version?: string) => Promise<void>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { _default as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
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/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
default: () => src_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_node_path4 = require("path");
|
|
37
|
+
|
|
38
|
+
// src/events.ts
|
|
39
|
+
var import_gray_matter = __toESM(require("gray-matter"));
|
|
40
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
41
|
+
var import_node_path2 = require("path");
|
|
42
|
+
var import_node_path3 = require("path");
|
|
43
|
+
|
|
44
|
+
// src/internal/utils.ts
|
|
45
|
+
var import_glob = require("glob");
|
|
46
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
47
|
+
var import_fs_extra = require("fs-extra");
|
|
48
|
+
var import_node_path = require("path");
|
|
49
|
+
var versionExists = async (catalogDir, id, version) => {
|
|
50
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
51
|
+
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
52
|
+
return matchedFiles.length > 0;
|
|
53
|
+
};
|
|
54
|
+
var findFileById = async (catalogDir, id, version) => {
|
|
55
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
56
|
+
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
57
|
+
if (!version) {
|
|
58
|
+
return matchedFiles.find((path) => !path.includes("versioned"));
|
|
59
|
+
}
|
|
60
|
+
return matchedFiles.find((path) => path.includes(`versioned/${version}`));
|
|
61
|
+
};
|
|
62
|
+
var getFiles = async (pattern) => {
|
|
63
|
+
try {
|
|
64
|
+
const files = await (0, import_glob.glob)(pattern, { ignore: "node_modules/**" });
|
|
65
|
+
return files;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`Error finding files: ${error}`);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var searchFilesForId = async (files, id, version) => {
|
|
71
|
+
const idRegex = new RegExp(`^id:\\s*['"]?${id}['"]?\\s*$`, "m");
|
|
72
|
+
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
73
|
+
const matches = await Promise.all(
|
|
74
|
+
files.map(async (file) => {
|
|
75
|
+
const content = await import_promises.default.readFile(file, "utf-8");
|
|
76
|
+
const hasIdMatch = content.match(idRegex);
|
|
77
|
+
if (version && !content.match(versionRegex)) {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
if (hasIdMatch) {
|
|
81
|
+
return file;
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
86
|
+
};
|
|
87
|
+
var copyDir = async (catalogDir, source, target, filter) => {
|
|
88
|
+
const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
|
|
89
|
+
await import_promises.default.mkdir(tmpDirectory, { recursive: true });
|
|
90
|
+
await (0, import_fs_extra.copy)(source, tmpDirectory, {
|
|
91
|
+
overwrite: true,
|
|
92
|
+
filter
|
|
93
|
+
});
|
|
94
|
+
await (0, import_fs_extra.copy)(tmpDirectory, target, {
|
|
95
|
+
overwrite: true,
|
|
96
|
+
filter
|
|
97
|
+
});
|
|
98
|
+
await import_promises.default.rm(tmpDirectory, { recursive: true });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/events.ts
|
|
102
|
+
var getEvent = (directory) => async (id, version) => {
|
|
103
|
+
const file = await findFileById(directory, id, version);
|
|
104
|
+
if (!file) throw new Error(`No event found for the given id: ${id}` + (version ? ` and version ${version}` : ""));
|
|
105
|
+
const { data, content } = import_gray_matter.default.read(file);
|
|
106
|
+
return {
|
|
107
|
+
...data,
|
|
108
|
+
markdown: content.trim()
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
var writeEvent = (directory) => async (event, options = { path: "" }) => {
|
|
112
|
+
const path = options.path || `/${event.id}`;
|
|
113
|
+
const exists = await versionExists(directory, event.id, event.version);
|
|
114
|
+
if (exists) {
|
|
115
|
+
throw new Error(`Failed to write event as the version ${event.version} already exists`);
|
|
116
|
+
}
|
|
117
|
+
const { markdown, ...frontmatter } = event;
|
|
118
|
+
const document = import_gray_matter.default.stringify(markdown.trim(), frontmatter);
|
|
119
|
+
await import_promises2.default.mkdir((0, import_node_path2.join)(directory, path), { recursive: true });
|
|
120
|
+
await import_promises2.default.writeFile((0, import_node_path2.join)(directory, path, "index.md"), document);
|
|
121
|
+
};
|
|
122
|
+
var rmEvent = (directory) => async (path) => {
|
|
123
|
+
await import_promises2.default.rm((0, import_node_path2.join)(directory, path), { recursive: true });
|
|
124
|
+
};
|
|
125
|
+
var rmEventById = (directory) => async (id, version) => {
|
|
126
|
+
const files = await getFiles(`${directory}/**/index.md`);
|
|
127
|
+
const matchedFiles = await searchFilesForId(files, id, version);
|
|
128
|
+
if (matchedFiles.length === 0) {
|
|
129
|
+
throw new Error(`No event found with id: ${id}`);
|
|
130
|
+
}
|
|
131
|
+
await Promise.all(matchedFiles.map((file) => import_promises2.default.rm(file)));
|
|
132
|
+
};
|
|
133
|
+
var versionEvent = (directory) => async (id) => {
|
|
134
|
+
const files = await getFiles(`${directory}/**/index.md`);
|
|
135
|
+
const matchedFiles = await searchFilesForId(files, id);
|
|
136
|
+
if (matchedFiles.length === 0) {
|
|
137
|
+
throw new Error(`No event found with id: ${id}`);
|
|
138
|
+
}
|
|
139
|
+
const file = matchedFiles[0];
|
|
140
|
+
const eventDirectory = (0, import_node_path3.dirname)(file);
|
|
141
|
+
const { data: { version = "0.0.1" } = {} } = import_gray_matter.default.read(file);
|
|
142
|
+
const targetDirectory = (0, import_node_path2.join)(eventDirectory, "versioned", version);
|
|
143
|
+
await import_promises2.default.mkdir(targetDirectory, { recursive: true });
|
|
144
|
+
await copyDir(directory, eventDirectory, targetDirectory, (src) => {
|
|
145
|
+
return !src.includes("versioned");
|
|
146
|
+
});
|
|
147
|
+
await import_promises2.default.readdir(eventDirectory).then(async (resourceFiles) => {
|
|
148
|
+
await Promise.all(
|
|
149
|
+
resourceFiles.map(async (file2) => {
|
|
150
|
+
if (file2 !== "versioned") {
|
|
151
|
+
await import_promises2.default.rm((0, import_node_path2.join)(eventDirectory, file2), { recursive: true });
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
var addFileToEvent = (directory) => async (id, file, version) => {
|
|
158
|
+
const pathToEvent = await findFileById(directory, id, version);
|
|
159
|
+
if (!pathToEvent) throw new Error("Cannot find directory to write file to");
|
|
160
|
+
const contentDirectory = (0, import_node_path3.dirname)(pathToEvent);
|
|
161
|
+
await import_promises2.default.writeFile((0, import_node_path2.join)(contentDirectory, file.fileName), file.content);
|
|
162
|
+
};
|
|
163
|
+
var addSchemaToEvent = (directory) => async (id, schema, version) => {
|
|
164
|
+
await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/index.ts
|
|
168
|
+
var src_default = (path) => {
|
|
169
|
+
return {
|
|
170
|
+
/**
|
|
171
|
+
* Returns an events from EventCatalog
|
|
172
|
+
* @param id - The id of the event to retrieve
|
|
173
|
+
* @param version - Optional id of the version to get
|
|
174
|
+
* @returns
|
|
175
|
+
*/
|
|
176
|
+
getEvent: getEvent((0, import_node_path4.join)(path, "events")),
|
|
177
|
+
/**
|
|
178
|
+
* Adds an event to EventCatalog
|
|
179
|
+
*
|
|
180
|
+
* @param event - The event to write
|
|
181
|
+
* @param options - Optional options to write the event
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
184
|
+
writeEvent: writeEvent((0, import_node_path4.join)(path, "events")),
|
|
185
|
+
/**
|
|
186
|
+
* Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
|
|
187
|
+
*
|
|
188
|
+
* @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
|
|
189
|
+
*
|
|
190
|
+
*/
|
|
191
|
+
rmEvent: rmEvent((0, import_node_path4.join)(path, "events")),
|
|
192
|
+
/**
|
|
193
|
+
* Remove an event by an Event id
|
|
194
|
+
*
|
|
195
|
+
* @param id - The id of the event you want to remove
|
|
196
|
+
*
|
|
197
|
+
*/
|
|
198
|
+
rmEventById: rmEventById((0, import_node_path4.join)(path, "events")),
|
|
199
|
+
/**
|
|
200
|
+
* Moves a given event id to the version directory
|
|
201
|
+
* @param directory
|
|
202
|
+
*/
|
|
203
|
+
versionEvent: versionEvent((0, import_node_path4.join)(path, "events")),
|
|
204
|
+
/**
|
|
205
|
+
* Adds a file to the given event
|
|
206
|
+
* @param id - The id of the event to add the file to
|
|
207
|
+
* @param file - File contents to add including the content and the file name
|
|
208
|
+
* @param version - Optional version of the event to add the file to
|
|
209
|
+
* @returns
|
|
210
|
+
*/
|
|
211
|
+
addFileToEvent: addFileToEvent((0, import_node_path4.join)(path, "events")),
|
|
212
|
+
/**
|
|
213
|
+
* Adds a schema to the given event
|
|
214
|
+
* @param id - The id of the event to add the schema to
|
|
215
|
+
* @param schema - Schema contents to add including the content and the file name
|
|
216
|
+
* @param version - Optional version of the event to add the schema to
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
219
|
+
addSchemaToEvent: addSchemaToEvent((0, import_node_path4.join)(path, "events"))
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/events.ts","../src/internal/utils.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { rmEvent, rmEventById, writeEvent, versionEvent, getEvent, addFileToEvent, addSchemaToEvent } from './events';\n\n/**\n * Init the SDK for EventCatalog\n *\n * @param path - The path to the EventCatalog directory\n *\n */\nexport default (path: string) => {\n return {\n /**\n * Returns an events from EventCatalog\n * @param id - The id of the event to retrieve\n * @param version - Optional id of the version to get\n * @returns\n */\n getEvent: getEvent(join(path, 'events')),\n /**\n * Adds an event to EventCatalog\n *\n * @param event - The event to write\n * @param options - Optional options to write the event\n *\n */\n writeEvent: writeEvent(join(path, 'events')),\n /**\n * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`\n *\n */\n rmEvent: rmEvent(join(path, 'events')),\n /**\n * Remove an event by an Event id\n *\n * @param id - The id of the event you want to remove\n *\n */\n rmEventById: rmEventById(join(path, 'events')),\n /**\n * Moves a given event id to the version directory\n * @param directory\n */\n versionEvent: versionEvent(join(path, 'events')),\n /**\n * Adds a file to the given event\n * @param id - The id of the event to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the event to add the file to\n * @returns\n */\n addFileToEvent: addFileToEvent(join(path, 'events')),\n /**\n * Adds a schema to the given event\n * @param id - The id of the event to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the event to add the schema to\n * @returns\n */\n addSchemaToEvent: addSchemaToEvent(join(path, 'events')),\n };\n};\n","import matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { dirname } from 'node:path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './internal/utils';\nimport type { Event } from './types';\n\n/**\n * Returns an event from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the event\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getEvent } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * cont event = await getEvent('InventoryAdjusted');\n *\n * // Gets a version of the event\n * cont event = await getEvent('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const getEvent =\n (directory: string) =>\n async (id: string, version?: string): Promise<Event> => {\n const file = await findFileById(directory, id, version);\n\n if (!file) throw new Error(`No event found for the given id: ${id}` + (version ? ` and version ${version}` : ''));\n\n const { data, content } = matter.read(file);\n\n return {\n ...data,\n markdown: content.trim(),\n } as Event;\n };\n\n/**\n * Write an event to EventCatalog.\n *\n * You can optionally overide the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeEvent } = utils('/path/to/eventcatalog');\n *\n * // Write an event to the catalog\n * // Event would be written to events/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write an event to the catalog but override the path\n * // Event would be written to events/Inventory/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryAdjusted\"});\n * ```\n */\nexport const writeEvent =\n (directory: string) =>\n async (event: Event, options: { path: string } = { path: '' }) => {\n // Get the path\n const path = options.path || `/${event.id}`;\n const exists = await versionExists(directory, event.id, event.version);\n\n if (exists) {\n throw new Error(`Failed to write event as the version ${event.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = event;\n const document = matter.stringify(markdown.trim(), frontmatter);\n await fs.mkdir(join(directory, path), { recursive: true });\n await fs.writeFile(join(directory, path, 'index.md'), document);\n };\n\n/**\n * Delete an event at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEvent } = utils('/path/to/eventcatalog');\n *\n * // removes an event at the given path (events dir is appended to the given path)\n * // Removes the event at events/InventoryAdjusted\n * await rmEvent('/InventoryAdjusted');\n * ```\n */\nexport const rmEvent = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete an event by it's id.\n *\n * Optionally specify a version to delete a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEventById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryAdjusted event\n * await rmEventById('InventoryAdjusted');\n *\n * // deletes a specific version of the InventoryAdjusted event\n * await rmEventById('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const rmEventById = (directory: string) => async (id: string, version?: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${directory}/**/index.md`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No event found with id: ${id}`);\n }\n\n await Promise.all(matchedFiles.map((file) => fs.rm(file)));\n};\n\n/**\n * Version an event by it's id.\n *\n * Takes the latest event and moves it to a versioned directory.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionEvent } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryAdjusted event to a versioned directory\n * // the version within that event is used as the version number.\n * await verionEvent('InventoryAdjusted');\n *\n * ```\n */\nexport const versionEvent = (directory: string) => async (id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${directory}/**/index.md`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No event found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n const eventDirectory = dirname(file);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = join(eventDirectory, 'versioned', version);\n\n await fs.mkdir(targetDirectory, { recursive: true });\n\n // Copy the event to the versioned directory\n await copyDir(directory, eventDirectory, targetDirectory, (src) => {\n return !src.includes('versioned');\n });\n\n // Remove all the files in the root of the resource as they have now been versioned\n await fs.readdir(eventDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n if (file !== 'versioned') {\n await fs.rm(join(eventDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\n/**\n * Add a file to an event by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToEvent } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToEvent =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) => {\n const pathToEvent = await findFileById(directory, id, version);\n if (!pathToEvent) throw new Error('Cannot find directory to write file to');\n const contentDirectory = dirname(pathToEvent);\n await fs.writeFile(join(contentDirectory, file.fileName), file.content);\n };\n\n/**\n * Add a schema to an event by it's id.\n *\n * Optionally specify a version to add a schame to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToEvent } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToEvent =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n","import { glob } from 'glob';\nimport fs from 'node:fs/promises';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join } from 'node:path';\n\n/**\n * Returns true if a given version of a resource id exists in the catalog\n */\nexport const versionExists = async (catalogDir: string, id: string, version: string) => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n\n // Return the latest one\n if (!version) {\n return matchedFiles.find((path) => !path.includes('versioned'));\n }\n\n // Find the versioned event\n return matchedFiles.find((path) => path.includes(`versioned/${version}`));\n};\n\nexport const getFiles = async (pattern: string) => {\n try {\n const files = await glob(pattern, { ignore: 'node_modules/**' });\n return files;\n } catch (error) {\n throw new Error(`Error finding files: ${error}`);\n }\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n const idRegex = new RegExp(`^id:\\\\s*['\"]?${id}['\"]?\\\\s*$`, 'm');\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = await Promise.all(\n files.map(async (file) => {\n const content = await fs.readFile(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n })\n );\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n await fs.mkdir(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n await fs.rm(tmpDirectory, { recursive: true });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,oBAAqB;;;ACArB,yBAAmB;AACnB,IAAAC,mBAAe;AACf,IAAAC,oBAAqB;AACrB,IAAAA,oBAAwB;;;ACHxB,kBAAqB;AAC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BAAgB,mBAAe,wBAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQnD,kBAAkB,qBAAiB,wBAAK,MAAM,QAAQ,CAAC;AAAA,EACzD;AACF;","names":["import_node_path","import_promises","import_node_path","fs","matter","fs","file"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { join as join3 } from "path";
|
|
3
|
+
|
|
4
|
+
// src/events.ts
|
|
5
|
+
import matter from "gray-matter";
|
|
6
|
+
import fs2 from "fs/promises";
|
|
7
|
+
import { join as join2 } from "path";
|
|
8
|
+
import { dirname } from "path";
|
|
9
|
+
|
|
10
|
+
// src/internal/utils.ts
|
|
11
|
+
import { glob } from "glob";
|
|
12
|
+
import fs from "fs/promises";
|
|
13
|
+
import { copy } from "fs-extra";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
var versionExists = async (catalogDir, id, version) => {
|
|
16
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
17
|
+
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
18
|
+
return matchedFiles.length > 0;
|
|
19
|
+
};
|
|
20
|
+
var findFileById = async (catalogDir, id, version) => {
|
|
21
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
22
|
+
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
23
|
+
if (!version) {
|
|
24
|
+
return matchedFiles.find((path) => !path.includes("versioned"));
|
|
25
|
+
}
|
|
26
|
+
return matchedFiles.find((path) => path.includes(`versioned/${version}`));
|
|
27
|
+
};
|
|
28
|
+
var getFiles = async (pattern) => {
|
|
29
|
+
try {
|
|
30
|
+
const files = await glob(pattern, { ignore: "node_modules/**" });
|
|
31
|
+
return files;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(`Error finding files: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var searchFilesForId = async (files, id, version) => {
|
|
37
|
+
const idRegex = new RegExp(`^id:\\s*['"]?${id}['"]?\\s*$`, "m");
|
|
38
|
+
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
39
|
+
const matches = await Promise.all(
|
|
40
|
+
files.map(async (file) => {
|
|
41
|
+
const content = await fs.readFile(file, "utf-8");
|
|
42
|
+
const hasIdMatch = content.match(idRegex);
|
|
43
|
+
if (version && !content.match(versionRegex)) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
if (hasIdMatch) {
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
52
|
+
};
|
|
53
|
+
var copyDir = async (catalogDir, source, target, filter) => {
|
|
54
|
+
const tmpDirectory = join(catalogDir, "tmp");
|
|
55
|
+
await fs.mkdir(tmpDirectory, { recursive: true });
|
|
56
|
+
await copy(source, tmpDirectory, {
|
|
57
|
+
overwrite: true,
|
|
58
|
+
filter
|
|
59
|
+
});
|
|
60
|
+
await copy(tmpDirectory, target, {
|
|
61
|
+
overwrite: true,
|
|
62
|
+
filter
|
|
63
|
+
});
|
|
64
|
+
await fs.rm(tmpDirectory, { recursive: true });
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/events.ts
|
|
68
|
+
var getEvent = (directory) => async (id, version) => {
|
|
69
|
+
const file = await findFileById(directory, id, version);
|
|
70
|
+
if (!file) throw new Error(`No event found for the given id: ${id}` + (version ? ` and version ${version}` : ""));
|
|
71
|
+
const { data, content } = matter.read(file);
|
|
72
|
+
return {
|
|
73
|
+
...data,
|
|
74
|
+
markdown: content.trim()
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
var writeEvent = (directory) => async (event, options = { path: "" }) => {
|
|
78
|
+
const path = options.path || `/${event.id}`;
|
|
79
|
+
const exists = await versionExists(directory, event.id, event.version);
|
|
80
|
+
if (exists) {
|
|
81
|
+
throw new Error(`Failed to write event as the version ${event.version} already exists`);
|
|
82
|
+
}
|
|
83
|
+
const { markdown, ...frontmatter } = event;
|
|
84
|
+
const document = matter.stringify(markdown.trim(), frontmatter);
|
|
85
|
+
await fs2.mkdir(join2(directory, path), { recursive: true });
|
|
86
|
+
await fs2.writeFile(join2(directory, path, "index.md"), document);
|
|
87
|
+
};
|
|
88
|
+
var rmEvent = (directory) => async (path) => {
|
|
89
|
+
await fs2.rm(join2(directory, path), { recursive: true });
|
|
90
|
+
};
|
|
91
|
+
var rmEventById = (directory) => async (id, version) => {
|
|
92
|
+
const files = await getFiles(`${directory}/**/index.md`);
|
|
93
|
+
const matchedFiles = await searchFilesForId(files, id, version);
|
|
94
|
+
if (matchedFiles.length === 0) {
|
|
95
|
+
throw new Error(`No event found with id: ${id}`);
|
|
96
|
+
}
|
|
97
|
+
await Promise.all(matchedFiles.map((file) => fs2.rm(file)));
|
|
98
|
+
};
|
|
99
|
+
var versionEvent = (directory) => async (id) => {
|
|
100
|
+
const files = await getFiles(`${directory}/**/index.md`);
|
|
101
|
+
const matchedFiles = await searchFilesForId(files, id);
|
|
102
|
+
if (matchedFiles.length === 0) {
|
|
103
|
+
throw new Error(`No event found with id: ${id}`);
|
|
104
|
+
}
|
|
105
|
+
const file = matchedFiles[0];
|
|
106
|
+
const eventDirectory = dirname(file);
|
|
107
|
+
const { data: { version = "0.0.1" } = {} } = matter.read(file);
|
|
108
|
+
const targetDirectory = join2(eventDirectory, "versioned", version);
|
|
109
|
+
await fs2.mkdir(targetDirectory, { recursive: true });
|
|
110
|
+
await copyDir(directory, eventDirectory, targetDirectory, (src) => {
|
|
111
|
+
return !src.includes("versioned");
|
|
112
|
+
});
|
|
113
|
+
await fs2.readdir(eventDirectory).then(async (resourceFiles) => {
|
|
114
|
+
await Promise.all(
|
|
115
|
+
resourceFiles.map(async (file2) => {
|
|
116
|
+
if (file2 !== "versioned") {
|
|
117
|
+
await fs2.rm(join2(eventDirectory, file2), { recursive: true });
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var addFileToEvent = (directory) => async (id, file, version) => {
|
|
124
|
+
const pathToEvent = await findFileById(directory, id, version);
|
|
125
|
+
if (!pathToEvent) throw new Error("Cannot find directory to write file to");
|
|
126
|
+
const contentDirectory = dirname(pathToEvent);
|
|
127
|
+
await fs2.writeFile(join2(contentDirectory, file.fileName), file.content);
|
|
128
|
+
};
|
|
129
|
+
var addSchemaToEvent = (directory) => async (id, schema, version) => {
|
|
130
|
+
await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/index.ts
|
|
134
|
+
var src_default = (path) => {
|
|
135
|
+
return {
|
|
136
|
+
/**
|
|
137
|
+
* Returns an events from EventCatalog
|
|
138
|
+
* @param id - The id of the event to retrieve
|
|
139
|
+
* @param version - Optional id of the version to get
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
getEvent: getEvent(join3(path, "events")),
|
|
143
|
+
/**
|
|
144
|
+
* Adds an event to EventCatalog
|
|
145
|
+
*
|
|
146
|
+
* @param event - The event to write
|
|
147
|
+
* @param options - Optional options to write the event
|
|
148
|
+
*
|
|
149
|
+
*/
|
|
150
|
+
writeEvent: writeEvent(join3(path, "events")),
|
|
151
|
+
/**
|
|
152
|
+
* Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
|
|
153
|
+
*
|
|
154
|
+
* @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
rmEvent: rmEvent(join3(path, "events")),
|
|
158
|
+
/**
|
|
159
|
+
* Remove an event by an Event id
|
|
160
|
+
*
|
|
161
|
+
* @param id - The id of the event you want to remove
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
rmEventById: rmEventById(join3(path, "events")),
|
|
165
|
+
/**
|
|
166
|
+
* Moves a given event id to the version directory
|
|
167
|
+
* @param directory
|
|
168
|
+
*/
|
|
169
|
+
versionEvent: versionEvent(join3(path, "events")),
|
|
170
|
+
/**
|
|
171
|
+
* Adds a file to the given event
|
|
172
|
+
* @param id - The id of the event to add the file to
|
|
173
|
+
* @param file - File contents to add including the content and the file name
|
|
174
|
+
* @param version - Optional version of the event to add the file to
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
addFileToEvent: addFileToEvent(join3(path, "events")),
|
|
178
|
+
/**
|
|
179
|
+
* Adds a schema to the given event
|
|
180
|
+
* @param id - The id of the event to add the schema to
|
|
181
|
+
* @param schema - Schema contents to add including the content and the file name
|
|
182
|
+
* @param version - Optional version of the event to add the schema to
|
|
183
|
+
* @returns
|
|
184
|
+
*/
|
|
185
|
+
addSchemaToEvent: addSchemaToEvent(join3(path, "events"))
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
export {
|
|
189
|
+
src_default as default
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/events.ts","../src/internal/utils.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { rmEvent, rmEventById, writeEvent, versionEvent, getEvent, addFileToEvent, addSchemaToEvent } from './events';\n\n/**\n * Init the SDK for EventCatalog\n *\n * @param path - The path to the EventCatalog directory\n *\n */\nexport default (path: string) => {\n return {\n /**\n * Returns an events from EventCatalog\n * @param id - The id of the event to retrieve\n * @param version - Optional id of the version to get\n * @returns\n */\n getEvent: getEvent(join(path, 'events')),\n /**\n * Adds an event to EventCatalog\n *\n * @param event - The event to write\n * @param options - Optional options to write the event\n *\n */\n writeEvent: writeEvent(join(path, 'events')),\n /**\n * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`\n *\n */\n rmEvent: rmEvent(join(path, 'events')),\n /**\n * Remove an event by an Event id\n *\n * @param id - The id of the event you want to remove\n *\n */\n rmEventById: rmEventById(join(path, 'events')),\n /**\n * Moves a given event id to the version directory\n * @param directory\n */\n versionEvent: versionEvent(join(path, 'events')),\n /**\n * Adds a file to the given event\n * @param id - The id of the event to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the event to add the file to\n * @returns\n */\n addFileToEvent: addFileToEvent(join(path, 'events')),\n /**\n * Adds a schema to the given event\n * @param id - The id of the event to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the event to add the schema to\n * @returns\n */\n addSchemaToEvent: addSchemaToEvent(join(path, 'events')),\n };\n};\n","import matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { dirname } from 'node:path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './internal/utils';\nimport type { Event } from './types';\n\n/**\n * Returns an event from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the event\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getEvent } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * cont event = await getEvent('InventoryAdjusted');\n *\n * // Gets a version of the event\n * cont event = await getEvent('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const getEvent =\n (directory: string) =>\n async (id: string, version?: string): Promise<Event> => {\n const file = await findFileById(directory, id, version);\n\n if (!file) throw new Error(`No event found for the given id: ${id}` + (version ? ` and version ${version}` : ''));\n\n const { data, content } = matter.read(file);\n\n return {\n ...data,\n markdown: content.trim(),\n } as Event;\n };\n\n/**\n * Write an event to EventCatalog.\n *\n * You can optionally overide the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeEvent } = utils('/path/to/eventcatalog');\n *\n * // Write an event to the catalog\n * // Event would be written to events/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write an event to the catalog but override the path\n * // Event would be written to events/Inventory/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryAdjusted\"});\n * ```\n */\nexport const writeEvent =\n (directory: string) =>\n async (event: Event, options: { path: string } = { path: '' }) => {\n // Get the path\n const path = options.path || `/${event.id}`;\n const exists = await versionExists(directory, event.id, event.version);\n\n if (exists) {\n throw new Error(`Failed to write event as the version ${event.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = event;\n const document = matter.stringify(markdown.trim(), frontmatter);\n await fs.mkdir(join(directory, path), { recursive: true });\n await fs.writeFile(join(directory, path, 'index.md'), document);\n };\n\n/**\n * Delete an event at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEvent } = utils('/path/to/eventcatalog');\n *\n * // removes an event at the given path (events dir is appended to the given path)\n * // Removes the event at events/InventoryAdjusted\n * await rmEvent('/InventoryAdjusted');\n * ```\n */\nexport const rmEvent = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete an event by it's id.\n *\n * Optionally specify a version to delete a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEventById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryAdjusted event\n * await rmEventById('InventoryAdjusted');\n *\n * // deletes a specific version of the InventoryAdjusted event\n * await rmEventById('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const rmEventById = (directory: string) => async (id: string, version?: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${directory}/**/index.md`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No event found with id: ${id}`);\n }\n\n await Promise.all(matchedFiles.map((file) => fs.rm(file)));\n};\n\n/**\n * Version an event by it's id.\n *\n * Takes the latest event and moves it to a versioned directory.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionEvent } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryAdjusted event to a versioned directory\n * // the version within that event is used as the version number.\n * await verionEvent('InventoryAdjusted');\n *\n * ```\n */\nexport const versionEvent = (directory: string) => async (id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${directory}/**/index.md`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No event found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n const eventDirectory = dirname(file);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = join(eventDirectory, 'versioned', version);\n\n await fs.mkdir(targetDirectory, { recursive: true });\n\n // Copy the event to the versioned directory\n await copyDir(directory, eventDirectory, targetDirectory, (src) => {\n return !src.includes('versioned');\n });\n\n // Remove all the files in the root of the resource as they have now been versioned\n await fs.readdir(eventDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n if (file !== 'versioned') {\n await fs.rm(join(eventDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\n/**\n * Add a file to an event by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToEvent } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToEvent =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) => {\n const pathToEvent = await findFileById(directory, id, version);\n if (!pathToEvent) throw new Error('Cannot find directory to write file to');\n const contentDirectory = dirname(pathToEvent);\n await fs.writeFile(join(contentDirectory, file.fileName), file.content);\n };\n\n/**\n * Add a schema to an event by it's id.\n *\n * Optionally specify a version to add a schame to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToEvent } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToEvent =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n","import { glob } from 'glob';\nimport fs from 'node:fs/promises';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join } from 'node:path';\n\n/**\n * Returns true if a given version of a resource id exists in the catalog\n */\nexport const versionExists = async (catalogDir: string, id: string, version: string) => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n\n // Return the latest one\n if (!version) {\n return matchedFiles.find((path) => !path.includes('versioned'));\n }\n\n // Find the versioned event\n return matchedFiles.find((path) => path.includes(`versioned/${version}`));\n};\n\nexport const getFiles = async (pattern: string) => {\n try {\n const files = await glob(pattern, { ignore: 'node_modules/**' });\n return files;\n } catch (error) {\n throw new Error(`Error finding files: ${error}`);\n }\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n const idRegex = new RegExp(`^id:\\\\s*['\"]?${id}['\"]?\\\\s*$`, 'm');\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = await Promise.all(\n files.map(async (file) => {\n const content = await fs.readFile(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n })\n );\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n await fs.mkdir(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n await fs.rm(tmpDirectory, { recursive: true });\n};\n"],"mappings":";AAAA,SAAS,QAAAA,aAAY;;;ACArB,OAAO,YAAY;AACnB,OAAOC,SAAQ;AACf,SAAS,QAAAC,aAAY;AACrB,SAAS,eAAe;;;ACHxB,SAAS,YAAY;AACrB,OAAO,QAAQ;AACf,SAAS,YAA6C;AACtD,SAAS,YAAY;AAKd,IAAM,gBAAgB,OAAO,YAAoB,IAAY,YAAoB;AACtF,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,cAAc;AACxD,QAAM,eAAgB,MAAM,iBAAiB,OAAO,IAAI,OAAO,KAAM,CAAC;AACtE,SAAO,aAAa,SAAS;AAC/B;AAEO,IAAM,eAAe,OAAO,YAAoB,IAAY,YAAkD;AACnH,QAAM,QAAQ,MAAM,S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AC1E,QAAM,mBAAmB,QAAQ,WAAW;AAC5C,QAAMF,IAAG,UAAUC,MAAK,kBAAkB,KAAK,QAAQ,GAAG,KAAK,OAAO;AACxE;AAoCK,IAAM,mBACX,CAAC,cAAsB,OAAO,IAAY,QAA8C,YAAqB;AAC3G,QAAM,eAAe,SAAS,EAAE,IAAI,EAAE,SAAS,OAAO,QAAQ,UAAU,OAAO,SAAS,GAAG,OAAO;AACpG;;;ADpPF,IAAO,cAAQ,CAAC,SAAiB;AAC/B,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOL,UAAU,SAASE,MAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQvC,YAAY,WAAWA,MAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO3C,SAAS,QAAQA,MAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOrC,aAAa,YAAYA,MAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,IAK7C,cAAc,aAAaA,MAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQ/C,gBAAgB,eAAeA,MAAK,MAAM,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQnD,kBAAkB,iBAAiBA,MAAK,MAAM,QAAQ,CAAC;AAAA,EACzD;AACF;","names":["join","fs","join","fs","join","file","join"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CopyFilterAsync, CopyFilterSync } from 'fs-extra';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if a given version of a resource id exists in the catalog
|
|
5
|
+
*/
|
|
6
|
+
declare const versionExists: (catalogDir: string, id: string, version: string) => Promise<boolean>;
|
|
7
|
+
declare const findFileById: (catalogDir: string, id: string, version?: string) => Promise<string | undefined>;
|
|
8
|
+
declare const getFiles: (pattern: string) => Promise<string[]>;
|
|
9
|
+
declare const searchFilesForId: (files: string[], id: string, version?: string) => Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Function to copy a directory from source to target, uses a tmp directory
|
|
12
|
+
* @param catalogDir
|
|
13
|
+
* @param source
|
|
14
|
+
* @param target
|
|
15
|
+
* @param filter
|
|
16
|
+
*/
|
|
17
|
+
declare const copyDir: (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => Promise<void>;
|
|
18
|
+
|
|
19
|
+
export { copyDir, findFileById, getFiles, searchFilesForId, versionExists };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CopyFilterAsync, CopyFilterSync } from 'fs-extra';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if a given version of a resource id exists in the catalog
|
|
5
|
+
*/
|
|
6
|
+
declare const versionExists: (catalogDir: string, id: string, version: string) => Promise<boolean>;
|
|
7
|
+
declare const findFileById: (catalogDir: string, id: string, version?: string) => Promise<string | undefined>;
|
|
8
|
+
declare const getFiles: (pattern: string) => Promise<string[]>;
|
|
9
|
+
declare const searchFilesForId: (files: string[], id: string, version?: string) => Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Function to copy a directory from source to target, uses a tmp directory
|
|
12
|
+
* @param catalogDir
|
|
13
|
+
* @param source
|
|
14
|
+
* @param target
|
|
15
|
+
* @param filter
|
|
16
|
+
*/
|
|
17
|
+
declare const copyDir: (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => Promise<void>;
|
|
18
|
+
|
|
19
|
+
export { copyDir, findFileById, getFiles, searchFilesForId, versionExists };
|