@eventcatalog/sdk 2.17.0 → 2.17.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/dist/index.d.mts +14 -20
- package/dist/index.d.ts +14 -20
- package/dist/index.js +51 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1583,7 +1583,8 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
|
|
|
1583
1583
|
};
|
|
1584
1584
|
|
|
1585
1585
|
// src/messages.ts
|
|
1586
|
-
import { dirname as dirname5 } from "path";
|
|
1586
|
+
import { dirname as dirname5, join as join9 } from "path";
|
|
1587
|
+
import fsSync4 from "fs";
|
|
1587
1588
|
import matter4 from "gray-matter";
|
|
1588
1589
|
import { satisfies as satisfies4, validRange as validRange3 } from "semver";
|
|
1589
1590
|
var getMessageBySchemaPath = (directory) => async (path8, options) => {
|
|
@@ -1677,17 +1678,31 @@ var getProducersOfSchema = (directory) => async (path8) => {
|
|
|
1677
1678
|
return [];
|
|
1678
1679
|
}
|
|
1679
1680
|
};
|
|
1681
|
+
var getSchemaForMessage = (directory) => async (id, version) => {
|
|
1682
|
+
const file = await findFileById(directory, id, version);
|
|
1683
|
+
if (!file || !fsSync4.existsSync(file)) return void 0;
|
|
1684
|
+
const { data } = matter4.read(file);
|
|
1685
|
+
if (!data.schemaPath) return void 0;
|
|
1686
|
+
const resourceDirectory = dirname5(file);
|
|
1687
|
+
const pathToSchema = join9(resourceDirectory, data.schemaPath);
|
|
1688
|
+
if (!fsSync4.existsSync(pathToSchema)) return void 0;
|
|
1689
|
+
const schema = fsSync4.readFileSync(pathToSchema, "utf8");
|
|
1690
|
+
return {
|
|
1691
|
+
schema,
|
|
1692
|
+
fileName: data.schemaPath
|
|
1693
|
+
};
|
|
1694
|
+
};
|
|
1680
1695
|
|
|
1681
1696
|
// src/custom-docs.ts
|
|
1682
1697
|
import path3, { join as join10 } from "path";
|
|
1683
|
-
import
|
|
1698
|
+
import fsSync5 from "fs";
|
|
1684
1699
|
import fs8 from "fs/promises";
|
|
1685
1700
|
import matter5 from "gray-matter";
|
|
1686
1701
|
import slugify from "slugify";
|
|
1687
1702
|
var getCustomDoc = (directory) => async (filePath) => {
|
|
1688
1703
|
const fullPath = path3.join(directory, filePath);
|
|
1689
1704
|
const fullPathWithExtension = fullPath.endsWith(".mdx") ? fullPath : `${fullPath}.mdx`;
|
|
1690
|
-
const fileExists =
|
|
1705
|
+
const fileExists = fsSync5.existsSync(fullPathWithExtension);
|
|
1691
1706
|
if (!fileExists) {
|
|
1692
1707
|
return void 0;
|
|
1693
1708
|
}
|
|
@@ -1705,9 +1720,9 @@ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) =>
|
|
|
1705
1720
|
const name = fileName || slugify(customDoc.title, { lower: true });
|
|
1706
1721
|
const withExtension = name.endsWith(".mdx") ? name : `${name}.mdx`;
|
|
1707
1722
|
const fullPath = path3.join(directory, options.path || "", withExtension);
|
|
1708
|
-
|
|
1723
|
+
fsSync5.mkdirSync(path3.dirname(fullPath), { recursive: true });
|
|
1709
1724
|
const document = matter5.stringify(customDoc.markdown.trim(), rest);
|
|
1710
|
-
|
|
1725
|
+
fsSync5.writeFileSync(fullPath, document);
|
|
1711
1726
|
invalidateFileCache();
|
|
1712
1727
|
};
|
|
1713
1728
|
var rmCustomDoc = (directory) => async (filePath) => {
|
|
@@ -1718,13 +1733,13 @@ var rmCustomDoc = (directory) => async (filePath) => {
|
|
|
1718
1733
|
|
|
1719
1734
|
// src/teams.ts
|
|
1720
1735
|
import fs9 from "fs/promises";
|
|
1721
|
-
import
|
|
1736
|
+
import fsSync7 from "fs";
|
|
1722
1737
|
import { join as join12 } from "path";
|
|
1723
1738
|
import matter7 from "gray-matter";
|
|
1724
1739
|
import path4 from "path";
|
|
1725
1740
|
|
|
1726
1741
|
// src/users.ts
|
|
1727
|
-
import
|
|
1742
|
+
import fsSync6 from "fs";
|
|
1728
1743
|
import { join as join11 } from "path";
|
|
1729
1744
|
import matter6 from "gray-matter";
|
|
1730
1745
|
var getUser = (catalogDir) => async (id) => {
|
|
@@ -1763,12 +1778,12 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
|
|
|
1763
1778
|
}
|
|
1764
1779
|
const { markdown, ...frontmatter } = resource;
|
|
1765
1780
|
const document = matter6.stringify(markdown, frontmatter);
|
|
1766
|
-
|
|
1767
|
-
|
|
1781
|
+
fsSync6.mkdirSync(join11(catalogDir, ""), { recursive: true });
|
|
1782
|
+
fsSync6.writeFileSync(join11(catalogDir, "", `${resource.id}.mdx`), document);
|
|
1768
1783
|
invalidateFileCache();
|
|
1769
1784
|
};
|
|
1770
1785
|
var rmUserById = (catalogDir) => async (id) => {
|
|
1771
|
-
|
|
1786
|
+
fsSync6.rmSync(join11(catalogDir, `${id}.mdx`), { recursive: true });
|
|
1772
1787
|
invalidateFileCache();
|
|
1773
1788
|
};
|
|
1774
1789
|
|
|
@@ -1807,8 +1822,8 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
|
|
|
1807
1822
|
}
|
|
1808
1823
|
const { markdown, ...frontmatter } = resource;
|
|
1809
1824
|
const document = matter7.stringify(markdown, frontmatter);
|
|
1810
|
-
|
|
1811
|
-
|
|
1825
|
+
fsSync7.mkdirSync(join12(catalogDir, ""), { recursive: true });
|
|
1826
|
+
fsSync7.writeFileSync(join12(catalogDir, "", `${resource.id}.mdx`), document);
|
|
1812
1827
|
invalidateFileCache();
|
|
1813
1828
|
};
|
|
1814
1829
|
var rmTeamById = (catalogDir) => async (id) => {
|
|
@@ -2244,7 +2259,7 @@ var listSnapshots = (directory) => async () => {
|
|
|
2244
2259
|
|
|
2245
2260
|
// src/changelogs.ts
|
|
2246
2261
|
import path7, { dirname as dirname6 } from "path";
|
|
2247
|
-
import
|
|
2262
|
+
import fsSync8 from "fs";
|
|
2248
2263
|
import fs12 from "fs/promises";
|
|
2249
2264
|
import matter8 from "gray-matter";
|
|
2250
2265
|
var writeChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
@@ -2263,9 +2278,9 @@ var writeChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
|
2263
2278
|
if (!fm.badges || fm.badges.length === 0) {
|
|
2264
2279
|
delete fm.badges;
|
|
2265
2280
|
}
|
|
2266
|
-
|
|
2281
|
+
fsSync8.mkdirSync(resourceDir, { recursive: true });
|
|
2267
2282
|
const document = matter8.stringify(markdown.trim(), fm);
|
|
2268
|
-
|
|
2283
|
+
fsSync8.writeFileSync(changelogPath, document);
|
|
2269
2284
|
invalidateFileCache();
|
|
2270
2285
|
};
|
|
2271
2286
|
var appendChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
@@ -2277,7 +2292,7 @@ var appendChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
|
2277
2292
|
const resourceDir = dirname6(resourceFile);
|
|
2278
2293
|
const mdxPath = path7.join(resourceDir, "changelog.mdx");
|
|
2279
2294
|
const mdPath = path7.join(resourceDir, "changelog.md");
|
|
2280
|
-
const existingPath =
|
|
2295
|
+
const existingPath = fsSync8.existsSync(mdxPath) ? mdxPath : fsSync8.existsSync(mdPath) ? mdPath : void 0;
|
|
2281
2296
|
if (!existingPath) {
|
|
2282
2297
|
return writeChangelog(catalogDir)(id, changelog, options);
|
|
2283
2298
|
}
|
|
@@ -2297,7 +2312,7 @@ ${existingContent}`;
|
|
|
2297
2312
|
delete fm.badges;
|
|
2298
2313
|
}
|
|
2299
2314
|
const document = matter8.stringify(combined, fm);
|
|
2300
|
-
|
|
2315
|
+
fsSync8.writeFileSync(existingPath, document);
|
|
2301
2316
|
invalidateFileCache();
|
|
2302
2317
|
};
|
|
2303
2318
|
var getChangelog = (catalogDir) => async (id, options = {}) => {
|
|
@@ -2307,7 +2322,7 @@ var getChangelog = (catalogDir) => async (id, options = {}) => {
|
|
|
2307
2322
|
const resourceDir = dirname6(resourceFile);
|
|
2308
2323
|
const mdxPath = path7.join(resourceDir, "changelog.mdx");
|
|
2309
2324
|
const mdPath = path7.join(resourceDir, "changelog.md");
|
|
2310
|
-
const changelogPath =
|
|
2325
|
+
const changelogPath = fsSync8.existsSync(mdxPath) ? mdxPath : fsSync8.existsSync(mdPath) ? mdPath : void 0;
|
|
2311
2326
|
if (!changelogPath) return void 0;
|
|
2312
2327
|
const { data, content } = matter8.read(changelogPath);
|
|
2313
2328
|
return { ...data, markdown: content.trim() };
|
|
@@ -2321,10 +2336,10 @@ var rmChangelog = (catalogDir) => async (id, options = {}) => {
|
|
|
2321
2336
|
const resourceDir = dirname6(resourceFile);
|
|
2322
2337
|
const mdxPath = path7.join(resourceDir, "changelog.mdx");
|
|
2323
2338
|
const mdPath = path7.join(resourceDir, "changelog.md");
|
|
2324
|
-
if (
|
|
2339
|
+
if (fsSync8.existsSync(mdxPath)) {
|
|
2325
2340
|
await fs12.rm(mdxPath);
|
|
2326
2341
|
}
|
|
2327
|
-
if (
|
|
2342
|
+
if (fsSync8.existsSync(mdPath)) {
|
|
2328
2343
|
await fs12.rm(mdPath);
|
|
2329
2344
|
}
|
|
2330
2345
|
invalidateFileCache();
|
|
@@ -3331,6 +3346,14 @@ var src_default = (path8) => {
|
|
|
3331
3346
|
* @returns Service[]
|
|
3332
3347
|
*/
|
|
3333
3348
|
getProducersOfSchema: getProducersOfSchema(join18(path8)),
|
|
3349
|
+
/**
|
|
3350
|
+
* Returns the schema for a given message (event, command or query) by its id and version.
|
|
3351
|
+
* If no version is given, the latest version is used.
|
|
3352
|
+
* @param id - The id of the message to get the schema for
|
|
3353
|
+
* @param version - Optional version of the message
|
|
3354
|
+
* @returns { schema: string, fileName: string } | undefined
|
|
3355
|
+
*/
|
|
3356
|
+
getSchemaForMessage: getSchemaForMessage(join18(path8)),
|
|
3334
3357
|
/**
|
|
3335
3358
|
* Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
|
|
3336
3359
|
* @param id - The id of the resource to get the owners for
|