@eventcatalog/sdk 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/events.d.mts +2 -1
- package/dist/events.d.ts +2 -1
- package/dist/events.js +59 -47
- package/dist/events.js.map +1 -1
- package/dist/events.mjs +60 -48
- package/dist/events.mjs.map +1 -1
- package/dist/index.d.mts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +119 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -56
- package/dist/index.mjs.map +1 -1
- package/dist/services.d.mts +133 -0
- package/dist/services.d.ts +133 -0
- package/dist/{docs.js → services.js} +75 -70
- package/dist/services.js.map +1 -0
- package/dist/{docs.mjs → services.mjs} +67 -59
- package/dist/services.mjs.map +1 -0
- package/dist/types.d.d.mts +53 -12
- package/dist/types.d.d.ts +53 -12
- package/dist/types.d.js.map +1 -1
- package/package.json +2 -2
- package/dist/docs.d.mts +0 -2
- package/dist/docs.d.ts +0 -2
- package/dist/docs.js.map +0 -1
- package/dist/docs.mjs.map +0 -1
- package/dist/internal/utils.d.mts +0 -19
- package/dist/internal/utils.d.ts +0 -19
- package/dist/internal/utils.js +0 -103
- package/dist/internal/utils.js.map +0 -1
- package/dist/internal/utils.mjs +0 -64
- package/dist/internal/utils.mjs.map +0 -1
- package/dist/test/events.test.d.mts +0 -2
- package/dist/test/events.test.d.ts +0 -2
- package/dist/test/events.test.js +0 -16828
- package/dist/test/events.test.js.map +0 -1
- package/dist/test/events.test.mjs +0 -16813
- package/dist/test/events.test.mjs.map +0 -1
package/dist/internal/utils.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;AAAA,EAChE;AAGA,SAAO,aAAa,KAAK,CAAC,SAAS,KAAK,SAAS,aAAa,OAAO,EAAE,CAAC;AAC1E;AAEO,IAAM,WAAW,OAAO,YAAoB;AACjD,MAAI;AACF,UAAM,QAAQ,MAAM,KAAK,SAAS,EAAE,QAAQ,kBAAkB,CAAC;AAC/D,WAAO;AAA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