@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
|
@@ -0,0 +1,103 @@
|
|
|
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/internal/utils.ts
|
|
31
|
+
var utils_exports = {};
|
|
32
|
+
__export(utils_exports, {
|
|
33
|
+
copyDir: () => copyDir,
|
|
34
|
+
findFileById: () => findFileById,
|
|
35
|
+
getFiles: () => getFiles,
|
|
36
|
+
searchFilesForId: () => searchFilesForId,
|
|
37
|
+
versionExists: () => versionExists
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(utils_exports);
|
|
40
|
+
var import_glob = require("glob");
|
|
41
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
42
|
+
var import_fs_extra = require("fs-extra");
|
|
43
|
+
var import_node_path = require("path");
|
|
44
|
+
var versionExists = async (catalogDir, id, version) => {
|
|
45
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
46
|
+
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
47
|
+
return matchedFiles.length > 0;
|
|
48
|
+
};
|
|
49
|
+
var findFileById = async (catalogDir, id, version) => {
|
|
50
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
51
|
+
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
52
|
+
if (!version) {
|
|
53
|
+
return matchedFiles.find((path) => !path.includes("versioned"));
|
|
54
|
+
}
|
|
55
|
+
return matchedFiles.find((path) => path.includes(`versioned/${version}`));
|
|
56
|
+
};
|
|
57
|
+
var getFiles = async (pattern) => {
|
|
58
|
+
try {
|
|
59
|
+
const files = await (0, import_glob.glob)(pattern, { ignore: "node_modules/**" });
|
|
60
|
+
return files;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new Error(`Error finding files: ${error}`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var searchFilesForId = async (files, id, version) => {
|
|
66
|
+
const idRegex = new RegExp(`^id:\\s*['"]?${id}['"]?\\s*$`, "m");
|
|
67
|
+
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
68
|
+
const matches = await Promise.all(
|
|
69
|
+
files.map(async (file) => {
|
|
70
|
+
const content = await import_promises.default.readFile(file, "utf-8");
|
|
71
|
+
const hasIdMatch = content.match(idRegex);
|
|
72
|
+
if (version && !content.match(versionRegex)) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
if (hasIdMatch) {
|
|
76
|
+
return file;
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
81
|
+
};
|
|
82
|
+
var copyDir = async (catalogDir, source, target, filter) => {
|
|
83
|
+
const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
|
|
84
|
+
await import_promises.default.mkdir(tmpDirectory, { recursive: true });
|
|
85
|
+
await (0, import_fs_extra.copy)(source, tmpDirectory, {
|
|
86
|
+
overwrite: true,
|
|
87
|
+
filter
|
|
88
|
+
});
|
|
89
|
+
await (0, import_fs_extra.copy)(tmpDirectory, target, {
|
|
90
|
+
overwrite: true,
|
|
91
|
+
filter
|
|
92
|
+
});
|
|
93
|
+
await import_promises.default.rm(tmpDirectory, { recursive: true });
|
|
94
|
+
};
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
copyDir,
|
|
98
|
+
findFileById,
|
|
99
|
+
getFiles,
|
|
100
|
+
searchFilesForId,
|
|
101
|
+
versionExists
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/internal/utils.ts"],"sourcesContent":["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;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,sBAAe;AACf,sBAAsD;AACtD,uBAAqB;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,SAAS,GAAG,UAAU,cAAc;AACxD,QAAM,eAAgB,MAAM,iBAAiB,OAAO,EAAE,KAAM,CAAC;AAG7D,MAAI,CAAC,SAAS;AACZ,WAAO,aAAa,KAAK,CAAC,SAAS,CAAC,KAAK,SAAS,WAAW,CAAC;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
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/internal/utils.ts
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import { copy } from "fs-extra";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
var versionExists = async (catalogDir, id, version) => {
|
|
7
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
8
|
+
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
9
|
+
return matchedFiles.length > 0;
|
|
10
|
+
};
|
|
11
|
+
var findFileById = async (catalogDir, id, version) => {
|
|
12
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
13
|
+
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
14
|
+
if (!version) {
|
|
15
|
+
return matchedFiles.find((path) => !path.includes("versioned"));
|
|
16
|
+
}
|
|
17
|
+
return matchedFiles.find((path) => path.includes(`versioned/${version}`));
|
|
18
|
+
};
|
|
19
|
+
var getFiles = async (pattern) => {
|
|
20
|
+
try {
|
|
21
|
+
const files = await glob(pattern, { ignore: "node_modules/**" });
|
|
22
|
+
return files;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw new Error(`Error finding files: ${error}`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var searchFilesForId = async (files, id, version) => {
|
|
28
|
+
const idRegex = new RegExp(`^id:\\s*['"]?${id}['"]?\\s*$`, "m");
|
|
29
|
+
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
30
|
+
const matches = await Promise.all(
|
|
31
|
+
files.map(async (file) => {
|
|
32
|
+
const content = await fs.readFile(file, "utf-8");
|
|
33
|
+
const hasIdMatch = content.match(idRegex);
|
|
34
|
+
if (version && !content.match(versionRegex)) {
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
if (hasIdMatch) {
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
43
|
+
};
|
|
44
|
+
var copyDir = async (catalogDir, source, target, filter) => {
|
|
45
|
+
const tmpDirectory = join(catalogDir, "tmp");
|
|
46
|
+
await fs.mkdir(tmpDirectory, { recursive: true });
|
|
47
|
+
await copy(source, tmpDirectory, {
|
|
48
|
+
overwrite: true,
|
|
49
|
+
filter
|
|
50
|
+
});
|
|
51
|
+
await copy(tmpDirectory, target, {
|
|
52
|
+
overwrite: true,
|
|
53
|
+
filter
|
|
54
|
+
});
|
|
55
|
+
await fs.rm(tmpDirectory, { recursive: true });
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
copyDir,
|
|
59
|
+
findFileById,
|
|
60
|
+
getFiles,
|
|
61
|
+
searchFilesForId,
|
|
62
|
+
versionExists
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/internal/utils.ts"],"sourcesContent":["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,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,SAAS,GAAG,UAAU,cAAc;AACxD,QAAM,eAAgB,MAAM,iBAAiB,OAAO,EAAE,KAAM,CAAC;AAG7D,MAAI,CAAC,SAAS;AACZ,WAAO,aAAa,KAAK,CAAC,SAAS,CAAC,KAAK,SAAS,WAAW,CAAC;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