@eventcatalog/sdk 2.9.1 → 2.9.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/README.md +1 -1
- package/dist/channels.mjs +20 -27
- package/dist/channels.mjs.map +1 -1
- package/dist/commands.mjs +18 -19
- package/dist/commands.mjs.map +1 -1
- package/dist/containers.mjs +18 -19
- package/dist/containers.mjs.map +1 -1
- package/dist/custom-docs.mjs +15 -19
- package/dist/custom-docs.mjs.map +1 -1
- package/dist/data-stores.mjs +18 -19
- package/dist/data-stores.mjs.map +1 -1
- package/dist/domains.mjs +25 -26
- package/dist/domains.mjs.map +1 -1
- package/dist/entities.mjs +18 -19
- package/dist/entities.mjs.map +1 -1
- package/dist/eventcatalog.js +2 -2
- package/dist/eventcatalog.js.map +1 -1
- package/dist/eventcatalog.mjs +37 -37
- package/dist/eventcatalog.mjs.map +1 -1
- package/dist/events.mjs +18 -19
- package/dist/events.mjs.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -38
- package/dist/index.mjs.map +1 -1
- package/dist/messages.mjs +14 -19
- package/dist/messages.mjs.map +1 -1
- package/dist/queries.mjs +18 -19
- package/dist/queries.mjs.map +1 -1
- package/dist/services.mjs +31 -32
- package/dist/services.mjs.map +1 -1
- package/dist/teams.mjs +16 -21
- package/dist/teams.mjs.map +1 -1
- package/dist/types.d.d.mts +1 -0
- package/dist/types.d.d.ts +1 -0
- package/dist/types.d.js.map +1 -1
- package/dist/users.mjs +6 -7
- package/dist/users.mjs.map +1 -1
- package/package.json +5 -1
package/dist/users.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// src/users.ts
|
|
2
|
-
import
|
|
3
|
-
import { join as join2 } from "path";
|
|
2
|
+
import fsSync from "node:fs";
|
|
3
|
+
import { join as join2 } from "node:path";
|
|
4
4
|
import matter2 from "gray-matter";
|
|
5
5
|
|
|
6
6
|
// src/internal/utils.ts
|
|
7
7
|
import { globSync } from "glob";
|
|
8
|
-
import fsSync from "fs";
|
|
9
8
|
import { copy } from "fs-extra";
|
|
10
|
-
import { join, dirname, normalize, resolve, relative } from "path";
|
|
9
|
+
import { join, dirname, normalize, resolve, relative } from "node:path";
|
|
11
10
|
import matter from "gray-matter";
|
|
12
11
|
import { satisfies, validRange } from "semver";
|
|
13
12
|
var getFiles = async (pattern, ignore = "") => {
|
|
@@ -74,11 +73,11 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
|
|
|
74
73
|
}
|
|
75
74
|
const { markdown, ...frontmatter } = resource;
|
|
76
75
|
const document = matter2.stringify(markdown, frontmatter);
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
fsSync.mkdirSync(join2(catalogDir, ""), { recursive: true });
|
|
77
|
+
fsSync.writeFileSync(join2(catalogDir, "", `${resource.id}.mdx`), document);
|
|
79
78
|
};
|
|
80
79
|
var rmUserById = (catalogDir) => async (id) => {
|
|
81
|
-
|
|
80
|
+
fsSync.rmSync(join2(catalogDir, `${id}.mdx`), { recursive: true });
|
|
82
81
|
};
|
|
83
82
|
export {
|
|
84
83
|
getUser,
|
package/dist/users.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/users.ts","../src/internal/utils.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { join } from 'node:path';\nimport type { User } from './types';\nimport matter from 'gray-matter';\nimport { getFiles } from './internal/utils';\n\n/**\n * Returns a user from EventCatalog.\n *\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUser } = utils('/path/to/eventcatalog');\n *\n * // Gets the user with the given id\n * const user = await getUser('eventcatalog-core-user');\n *\n * ```\n */\nexport const getUser =\n (catalogDir: string) =>\n async (id: string): Promise<User | undefined> => {\n const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);\n\n if (files.length == 0) return undefined;\n const file = files[0];\n\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n avatarUrl: data.avatarUrl,\n markdown: content.trim(),\n } as User;\n };\n\n/**\n * Returns all users from EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUsers } = utils('/path/to/eventcatalog');\n *\n * // Gets all users from the catalog\n * const channels = await getUsers();\n *\n * ```\n */\nexport const getUsers =\n (catalogDir: string) =>\n async (options?: {}): Promise<User[]> => {\n const files = await getFiles(`${catalogDir}/users/*.{md,mdx}`);\n if (files.length === 0) return [];\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n avatarUrl: data.avatarUrl,\n markdown: content.trim(),\n } as User;\n });\n };\n\n/**\n * Write a user to EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeUser } = utils('/path/to/eventcatalog');\n *\n * // Write a user to the catalog\n * // user would be written to users/eventcatalog-tech-lead\n * await writeUser({\n * id: 'eventcatalog-tech-lead',\n * name: 'EventCatalog Tech Lead',\n * email: 'test@test.com',\n * avatarUrl: 'https://pbs.twimg.com/profile_images/1262283153563140096/DYRDqKg6_400x400.png',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * });\n *\n * // Write a team to the catalog and override the existing content (if there is any)\n * await writeUser({\n * id: 'eventcatalog-tech-lead',\n * name: 'EventCatalog Tech Lead',\n * email: 'test@test.com',\n * avatarUrl: 'https://pbs.twimg.com/profile_images/1262283153563140096/DYRDqKg6_400x400.png',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * }, { override: true });\n *\n * ```\n */\nexport const writeUser =\n (catalogDir: string) =>\n async (user: User, options: { override?: boolean } = {}) => {\n const resource: User = { ...user };\n\n // Get the path\n const currentUser = await getUser(catalogDir)(resource.id);\n const exists = currentUser !== undefined;\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (user) as it already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n const document = matter.stringify(markdown, frontmatter);\n fsSync.mkdirSync(join(catalogDir, ''), { recursive: true });\n fsSync.writeFileSync(join(catalogDir, '', `${resource.id}.mdx`), document);\n };\n\n/**\n * Delete a user by it's id.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmUserById } = utils('/path/to/eventcatalog');\n *\n * // deletes the user with id eventcatalog-core-user\n * await rmUserById('eventcatalog-core-user');\n *\n * ```\n */\nexport const rmUserById = (catalogDir: string) => async (id: string) => {\n fsSync.rmSync(join(catalogDir, `${id}.mdx`), { recursive: true });\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname, normalize, sep as pathSeparator, resolve, basename, relative } from 'node:path';\nimport matter from 'gray-matter';\nimport { satisfies, validRange, valid } from 'semver';\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,mdx}`);\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,mdx}`);\n\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n const latestVersion = matchedFiles.find((path) => !path.includes('versioned'));\n\n // If no version is provided, return the latest version\n if (!version) {\n return latestVersion;\n }\n\n // map files into gray matter to get versions\n const parsedFiles = matchedFiles.map((path) => {\n const { data } = matter.read(path);\n return { ...data, path };\n }) as any[];\n\n // Handle 'latest' version - return the latest (non-versioned) file\n if (version === 'latest') {\n return latestVersion;\n }\n\n // First, check for exact version match (handles non-semver versions like '1', '2', etc.)\n const exactMatch = parsedFiles.find((c) => c.version === version);\n if (exactMatch) {\n return exactMatch.path;\n }\n\n // Try semver range matching\n const semverRange = validRange(version);\n\n if (semverRange) {\n const match = parsedFiles.filter((c) => {\n try {\n return satisfies(c.version, semverRange);\n } catch (error) {\n // If satisfies fails (e.g., comparing semver range with non-semver version), skip this file\n return false;\n }\n });\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // If no exact match and no valid semver range, return undefined\n return undefined;\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n // 1. Normalize the input pattern to handle mixed separators potentially\n const normalizedInputPattern = normalize(pattern);\n\n // 2. Determine the absolute base directory (cwd for glob)\n // Resolve ensures it's absolute. Handles cases with/without globstar.\n const absoluteBaseDir = resolve(\n normalizedInputPattern.includes('**') ? normalizedInputPattern.split('**')[0] : dirname(normalizedInputPattern)\n );\n\n // 3. Determine the pattern part relative to the absolute base directory\n // We extract the part of the normalized pattern that comes *after* the absoluteBaseDir\n let relativePattern = relative(absoluteBaseDir, normalizedInputPattern);\n\n // On Windows, relative() might return empty string if paths are identical,\n // or might need normalization if the original pattern didn't have `**`\n // Example: pattern = 'dir/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\file.md'\n // relative() -> 'file.md'\n // Example: pattern = 'dir/**/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\**\\file.md'\n // relative() -> '**\\file.md'\n // Convert separators in the relative pattern to forward slashes for glob\n relativePattern = relativePattern.replace(/\\\\/g, '/');\n\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n\n const files = globSync(relativePattern, {\n cwd: absoluteBaseDir,\n ignore: ['node_modules/**', ...ignoreList],\n absolute: true,\n nodir: true,\n });\n\n // 5. Normalize results for consistency before returning\n return files.map(normalize);\n } catch (error: any) {\n // Add more diagnostic info to the error\n const absoluteBaseDirForError = resolve(\n normalize(pattern).includes('**') ? normalize(pattern).split('**')[0] : dirname(normalize(pattern))\n );\n const relativePatternForError = relative(absoluteBaseDirForError, normalize(pattern)).replace(/\\\\/g, '/');\n throw new Error(\n `Error finding files for pattern \"${pattern}\" (using cwd: \"${absoluteBaseDirForError}\", globPattern: \"${relativePatternForError}\"): ${error.message}`\n );\n }\n};\n\nexport const readMdxFile = async (path: string) => {\n const { data } = matter.read(path);\n const { markdown, ...frontmatter } = data;\n return { ...frontmatter, markdown };\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n // Escape the id to avoid regex issues\n const escapedId = id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${escapedId}['\"]?\\\\s*$`, 'm');\n\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = files.map((file) => {\n const content = fsSync.readFileSync(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 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 fsSync.mkdirSync(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 fsSync.rmSync(tmpDirectory, { recursive: true });\n};\n\n// Makes sure values in sends/recieves are unique\nexport const uniqueVersions = (messages: { id: string; version: string }[]): { id: string; version: string }[] => {\n const uniqueSet = new Set();\n\n return messages.filter((message) => {\n const key = `${message.id}-${message.version}`;\n if (!uniqueSet.has(key)) {\n uniqueSet.add(key);\n return true;\n }\n return false;\n });\n};\n"],"mappings":";AACA,OAAOA,aAAY;AACnB,SAAS,QAAAC,aAAY;AAErB,OAAOC,aAAY;;;ACJnB,SAAS,gBAAgB;AACzB,OAAO,YAAY;AACn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AW,KAAK,CAAC;AAClE;","names":["fsSync","join","matter","matter","fsSync","join"]}
|
|
1
|
+
{"version":3,"sources":["../src/users.ts","../src/internal/utils.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { join } from 'node:path';\nimport type { User } from './types';\nimport matter from 'gray-matter';\nimport { getFiles } from './internal/utils';\n\n/**\n * Returns a user from EventCatalog.\n *\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUser } = utils('/path/to/eventcatalog');\n *\n * // Gets the user with the given id\n * const user = await getUser('eventcatalog-core-user');\n *\n * ```\n */\nexport const getUser =\n (catalogDir: string) =>\n async (id: string): Promise<User | undefined> => {\n const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);\n\n if (files.length == 0) return undefined;\n const file = files[0];\n\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n avatarUrl: data.avatarUrl,\n markdown: content.trim(),\n } as User;\n };\n\n/**\n * Returns all users from EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUsers } = utils('/path/to/eventcatalog');\n *\n * // Gets all users from the catalog\n * const channels = await getUsers();\n *\n * ```\n */\nexport const getUsers =\n (catalogDir: string) =>\n async (options?: {}): Promise<User[]> => {\n const files = await getFiles(`${catalogDir}/users/*.{md,mdx}`);\n if (files.length === 0) return [];\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n avatarUrl: data.avatarUrl,\n markdown: content.trim(),\n } as User;\n });\n };\n\n/**\n * Write a user to EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeUser } = utils('/path/to/eventcatalog');\n *\n * // Write a user to the catalog\n * // user would be written to users/eventcatalog-tech-lead\n * await writeUser({\n * id: 'eventcatalog-tech-lead',\n * name: 'EventCatalog Tech Lead',\n * email: 'test@test.com',\n * avatarUrl: 'https://pbs.twimg.com/profile_images/1262283153563140096/DYRDqKg6_400x400.png',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * });\n *\n * // Write a team to the catalog and override the existing content (if there is any)\n * await writeUser({\n * id: 'eventcatalog-tech-lead',\n * name: 'EventCatalog Tech Lead',\n * email: 'test@test.com',\n * avatarUrl: 'https://pbs.twimg.com/profile_images/1262283153563140096/DYRDqKg6_400x400.png',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * }, { override: true });\n *\n * ```\n */\nexport const writeUser =\n (catalogDir: string) =>\n async (user: User, options: { override?: boolean } = {}) => {\n const resource: User = { ...user };\n\n // Get the path\n const currentUser = await getUser(catalogDir)(resource.id);\n const exists = currentUser !== undefined;\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (user) as it already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n const document = matter.stringify(markdown, frontmatter);\n fsSync.mkdirSync(join(catalogDir, ''), { recursive: true });\n fsSync.writeFileSync(join(catalogDir, '', `${resource.id}.mdx`), document);\n };\n\n/**\n * Delete a user by it's id.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmUserById } = utils('/path/to/eventcatalog');\n *\n * // deletes the user with id eventcatalog-core-user\n * await rmUserById('eventcatalog-core-user');\n *\n * ```\n */\nexport const rmUserById = (catalogDir: string) => async (id: string) => {\n fsSync.rmSync(join(catalogDir, `${id}.mdx`), { recursive: true });\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname, normalize, sep as pathSeparator, resolve, basename, relative } from 'node:path';\nimport matter from 'gray-matter';\nimport { satisfies, validRange, valid } from 'semver';\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,mdx}`);\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,mdx}`);\n\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n const latestVersion = matchedFiles.find((path) => !path.includes('versioned'));\n\n // If no version is provided, return the latest version\n if (!version) {\n return latestVersion;\n }\n\n // map files into gray matter to get versions\n const parsedFiles = matchedFiles.map((path) => {\n const { data } = matter.read(path);\n return { ...data, path };\n }) as any[];\n\n // Handle 'latest' version - return the latest (non-versioned) file\n if (version === 'latest') {\n return latestVersion;\n }\n\n // First, check for exact version match (handles non-semver versions like '1', '2', etc.)\n const exactMatch = parsedFiles.find((c) => c.version === version);\n if (exactMatch) {\n return exactMatch.path;\n }\n\n // Try semver range matching\n const semverRange = validRange(version);\n\n if (semverRange) {\n const match = parsedFiles.filter((c) => {\n try {\n return satisfies(c.version, semverRange);\n } catch (error) {\n // If satisfies fails (e.g., comparing semver range with non-semver version), skip this file\n return false;\n }\n });\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // If no exact match and no valid semver range, return undefined\n return undefined;\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n // 1. Normalize the input pattern to handle mixed separators potentially\n const normalizedInputPattern = normalize(pattern);\n\n // 2. Determine the absolute base directory (cwd for glob)\n // Resolve ensures it's absolute. Handles cases with/without globstar.\n const absoluteBaseDir = resolve(\n normalizedInputPattern.includes('**') ? normalizedInputPattern.split('**')[0] : dirname(normalizedInputPattern)\n );\n\n // 3. Determine the pattern part relative to the absolute base directory\n // We extract the part of the normalized pattern that comes *after* the absoluteBaseDir\n let relativePattern = relative(absoluteBaseDir, normalizedInputPattern);\n\n // On Windows, relative() might return empty string if paths are identical,\n // or might need normalization if the original pattern didn't have `**`\n // Example: pattern = 'dir/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\file.md'\n // relative() -> 'file.md'\n // Example: pattern = 'dir/**/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\**\\file.md'\n // relative() -> '**\\file.md'\n // Convert separators in the relative pattern to forward slashes for glob\n relativePattern = relativePattern.replace(/\\\\/g, '/');\n\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n\n const files = globSync(relativePattern, {\n cwd: absoluteBaseDir,\n ignore: ['node_modules/**', ...ignoreList],\n absolute: true,\n nodir: true,\n });\n\n // 5. Normalize results for consistency before returning\n return files.map(normalize);\n } catch (error: any) {\n // Add more diagnostic info to the error\n const absoluteBaseDirForError = resolve(\n normalize(pattern).includes('**') ? normalize(pattern).split('**')[0] : dirname(normalize(pattern))\n );\n const relativePatternForError = relative(absoluteBaseDirForError, normalize(pattern)).replace(/\\\\/g, '/');\n throw new Error(\n `Error finding files for pattern \"${pattern}\" (using cwd: \"${absoluteBaseDirForError}\", globPattern: \"${relativePatternForError}\"): ${error.message}`\n );\n }\n};\n\nexport const readMdxFile = async (path: string) => {\n const { data } = matter.read(path);\n const { markdown, ...frontmatter } = data;\n return { ...frontmatter, markdown };\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n // Escape the id to avoid regex issues\n const escapedId = id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${escapedId}['\"]?\\\\s*$`, 'm');\n\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = files.map((file) => {\n const content = fsSync.readFileSync(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 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 fsSync.mkdirSync(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 fsSync.rmSync(tmpDirectory, { recursive: true });\n};\n\n// Makes sure values in sends/recieves are unique\nexport const uniqueVersions = (messages: { id: string; version: string }[]): { id: string; version: string }[] => {\n const uniqueSet = new Set();\n\n return messages.filter((message) => {\n const key = `${message.id}-${message.version}`;\n if (!uniqueSet.has(key)) {\n uniqueSet.add(key);\n return true;\n }\n return false;\n });\n};\n"],"mappings":";AACA,OAAO,YAAY;AACnB,SAAS,QAAAA,aAAY;AAErB,OAAOC,aAAY;;;ACJnB,SAAS,gBAAgB;AAEzB,SAAS,YAA6C;AACtD,SAAS,MAAM,SAAS,WAAiC,SAAmB,gBAAgB;AAC5F,OAAO,YAAY;AACnB,SAAS,WAAW,kBAAyB;AA0DtC,IAAM,WAAW,OAAO,SAAiB,SAA4B,OAAO;AACjF,MAAI;AAEF,UAAM,yBAAyB,UAAU,OAAO;AAIhD,UAAM,kBAAkB;AAAA,MACtB,uBAAuB,SAAS,IAAI,IAAI,uBAAuB,MAAM,IAAI,EAAE,CAAC,IAAI,QAAQ,sBAAsB;AAAA,IAChH;AAIA,QAAI,kBAAkB,SAAS,iBAAiB,sBAAsB;AAStE,sBAAkB,gBAAgB,QAAQ,OAAO,GAAG;AAEpD,UAAM,aAAa,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAE3D,UAAM,QAAQ,SAAS,iBAAiB;AAAA,MACtC,KAAK;AAAA,MACL,QAAQ,CAAC,mBAAmB,GAAG,UAAU;AAAA,MACzC,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAGD,WAAO,MAAM,IAAI,SAAS;AAAA,EAC5B,SAAS,OAAY;AAEnB,UAAM,0BAA0B;AAAA,MAC9B,UAAU,O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,SAAS,EAAE;AACzD,QAAM,SAAS,gBAAgB;AAE/B,MAAI,UAAU,CAAC,QAAQ,UAAU;AAC/B,UAAM,IAAI,MAAM,mBAAmB,SAAS,EAAE,8BAA8B;AAAA,EAC9E;AAEA,QAAM,EAAE,UAAU,GAAG,YAAY,IAAI;AAErC,QAAM,WAAWA,QAAO,UAAU,UAAU,WAAW;AACvD,SAAO,UAAUC,MAAK,YAAY,EAAE,GAAG,EAAE,WAAW,KAAK,CAAC;AAC1D,SAAO,cAAcA,MAAK,YAAY,IAAI,GAAG,SAAS,EAAE,MAAM,GAAG,QAAQ;AAC3E;AAgBK,IAAM,aAAa,CAAC,eAAuB,OAAO,OAAe;AACtE,SAAO,OAAOA,MAAK,YAAY,GAAG,EAAE,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;AAClE;","names":["join","matter","matter","join"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventcatalog/sdk",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.5",
|
|
4
4
|
"description": "SDK to integrate with EventCatalog",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"semver": "7.6.3",
|
|
45
45
|
"slugify": "^1.6.6"
|
|
46
46
|
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/event-catalog/sdk"
|
|
50
|
+
},
|
|
47
51
|
"scripts": {
|
|
48
52
|
"build": "tsup",
|
|
49
53
|
"test": "vitest",
|