@eventcatalog/sdk 2.2.10 → 2.3.0
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/channels.js +20 -4
- package/dist/channels.js.map +1 -1
- package/dist/channels.mjs +21 -5
- package/dist/channels.mjs.map +1 -1
- package/dist/commands.js +20 -4
- package/dist/commands.js.map +1 -1
- package/dist/commands.mjs +21 -5
- package/dist/commands.mjs.map +1 -1
- package/dist/custom-docs.js +20 -4
- package/dist/custom-docs.js.map +1 -1
- package/dist/custom-docs.mjs +21 -5
- package/dist/custom-docs.mjs.map +1 -1
- package/dist/domains.js +20 -4
- package/dist/domains.js.map +1 -1
- package/dist/domains.mjs +21 -5
- package/dist/domains.mjs.map +1 -1
- package/dist/eventcatalog.js +20 -4
- package/dist/eventcatalog.js.map +1 -1
- package/dist/eventcatalog.mjs +21 -5
- package/dist/eventcatalog.mjs.map +1 -1
- package/dist/events.js +20 -4
- package/dist/events.js.map +1 -1
- package/dist/events.mjs +21 -5
- package/dist/events.mjs.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -5
- package/dist/index.mjs.map +1 -1
- package/dist/queries.js +20 -4
- package/dist/queries.js.map +1 -1
- package/dist/queries.mjs +21 -5
- package/dist/queries.mjs.map +1 -1
- package/dist/services.js +20 -4
- package/dist/services.js.map +1 -1
- package/dist/services.mjs +21 -5
- package/dist/services.mjs.map +1 -1
- package/dist/teams.js +20 -4
- package/dist/teams.js.map +1 -1
- package/dist/teams.mjs +21 -5
- package/dist/teams.mjs.map +1 -1
- package/dist/users.js +20 -4
- package/dist/users.js.map +1 -1
- package/dist/users.mjs +21 -5
- package/dist/users.mjs.map +1 -1
- package/package.json +1 -1
package/dist/domains.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/domains.ts","../src/internal/resources.ts","../src/internal/utils.ts"],"sourcesContent":["import type { Domain, UbiquitousLanguageDictionary } from './types';\nimport fs from 'node:fs/promises';\nimport path, { join } from 'node:path';\nimport fsSync from 'node:fs';\nimport {\n addFileToResource,\n getResource,\n getResourcePath,\n getResources,\n rmResourceById,\n versionResource,\n writeResource,\n} from './internal/resources';\nimport { findFileById, readMdxFile, uniqueVersions } from './internal/utils';\nimport matter from 'gray-matter';\n\n/**\n * Returns a domain from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the domain\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomain } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the domain\n * const domain = await getDomain('Payment');\n *\n * // Gets a version of the domain\n * const domain = await getDomain('Payment', '0.0.1');\n * ```\n */\nexport const getDomain =\n (directory: string) =>\n async (id: string, version?: string): Promise<Domain> =>\n getResource(directory, id, version, { type: 'domain' }) as Promise<Domain>;\n\n/**\n * Returns all domains from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the domains.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomains } = utils('/path/to/eventcatalog');\n *\n * // Gets all domains (and versions) from the catalog\n * const domains = await getDomains();\n *\n * // Gets all domains (only latest version) from the catalog\n * const domains = await getDomains({ latestOnly: true });\n * ```\n */\nexport const getDomains =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Domain[]> =>\n getResources(directory, {\n type: 'domains',\n ignore: ['**/services/**', '**/events/**', '**/commands/**', '**/queries/**', '**/flows/**'],\n ...options,\n }) as Promise<Domain[]>;\n\n/**\n * Write a domain to EventCatalog.\n *\n * You can optionally overide the path of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a domain\n * // Domain would be written to domains/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Payment domain',\n * version: '0.0.1',\n * summary: 'Domain for all things to do with payments',\n * markdown: '# Hello world',\n * });\n *\n * // Write a domain to the catalog but override the path\n * // Domain would be written to domains/Inventory/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/Payment\"});\n *\n * // Write a domain to the catalog and override the existing content (if there is any)\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { override: true });\n *\n * // Write a domain to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeDomain =\n (directory: string) =>\n async (\n domain: Domain,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n ) => {\n const resource: Domain = { ...domain };\n\n if (Array.isArray(domain.services)) {\n resource.services = uniqueVersions(domain.services);\n }\n\n return await writeResource(directory, resource, { ...options, type: 'domain' });\n };\n\n/**\n * Version a domain by it's id.\n *\n * Takes the latest domain and moves it to a versioned directory.\n * All files with this domain are also versioned. (e.g /domains/Payment/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionDomain } = utils('/path/to/eventcatalog');\n *\n * // moves the latest Payment domain to a versioned directory\n * // the version within that domain is used as the version number.\n * await versionDomain('Payment');\n *\n * ```\n */\nexport const versionDomain = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a domain at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomain } = utils('/path/to/eventcatalog');\n *\n * // Removes the domain at domains/Payment\n * await rmDomain('/Payment');\n * ```\n */\nexport const rmDomain = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a domain by it's id.\n *\n * Optionally specify a version to delete a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomainById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest Payment event\n * await rmDomainById('Payment');\n *\n * // deletes a specific version of the Payment event\n * await rmDomainById('Payment', '0.0.1');\n * ```\n */\nexport const rmDomainById = (directory: string) => async (id: string, version?: string, persistFiles?: boolean) =>\n rmResourceById(directory, id, version, { type: 'domain', persistFiles });\n\n/**\n * Add a file to a domain by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToDomain } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToDomain =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Adds a ubiquitous language dictionary to a domain.\n *\n * Optionally specify a version to add a ubiquitous language dictionary to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addUbiquitousLanguageToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a ubiquitous language dictionary to the latest Payment domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] });\n *\n * // Adds a ubiquitous language dictionary to a specific version of the domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] }, '0.0.1');\n * ```\n */\n\nexport const addUbiquitousLanguageToDomain =\n (directory: string) => async (id: string, ubiquitousLanguageDictionary: UbiquitousLanguageDictionary, version?: string) => {\n const content = matter.stringify('', {\n ...ubiquitousLanguageDictionary,\n });\n await addFileToResource(directory, id, { content, fileName: 'ubiquitous-language.mdx' }, version);\n };\n\n/**\n * Returns the ubiquitous language dictionary from a domain.\n *\n * Optionally specify a version to get the ubiquitous language dictionary from a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUbiquitousLanguageFromDomain } = utils('/path/to/eventcatalog');\n *\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment');\n *\n * // Returns the ubiquitous language dictionary from a specific version of the domain\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment', '0.0.1');\n * ```\n */\nexport const getUbiquitousLanguageFromDomain = (directory: string) => async (id: string, version?: string) => {\n const pathToDomain = (await findFileById(directory, id, version)) || '';\n const pathToUbiquitousLanguage = path.join(path.dirname(pathToDomain), 'ubiquitous-language.mdx');\n\n const fileExists = fsSync.existsSync(pathToUbiquitousLanguage);\n\n if (!fileExists) {\n return undefined;\n }\n\n const content = await readMdxFile(pathToUbiquitousLanguage);\n\n return content;\n};\n\n/**\n * Check to see if the catalog has a version for the given domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { domainHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await domainHasVersion('Orders', '0.0.1');\n * await domainHasVersion('Orders', 'latest');\n * await domainHasVersion('Orders', '0.0.x');*\n *\n * ```\n */\nexport const domainHasVersion = (directory: string) => async (id: string, version?: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n\n/**\n * Add a service to a domain by it's id.\n *\n * Optionally specify a version to add the service to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds a service to the domain\n * const { addServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a service (Orders Service) to the domain (Orders)\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' });\n * // Adds a service (Orders Service) to the domain (Orders) with a specific version\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' }, '1.0.0');\n * ```\n */\n\nexport const addServiceToDomain =\n (directory: string) => async (id: string, service: { id: string; version: string }, version?: string) => {\n let domain: Domain = await getDomain(directory)(id, version);\n const domainPath = await getResourcePath(directory, id, version);\n\n // Get the extension of the file\n const extension = path.extname(domainPath?.fullPath || '');\n\n if (domain.services === undefined) {\n domain.services = [];\n }\n\n const serviceExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);\n\n if (serviceExistsInList) {\n return;\n }\n\n // Add service to the list\n domain.services.push(service);\n\n await rmDomainById(directory)(id, version, true);\n await writeDomain(directory)(domain, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n const sourceDirectory = dirname(file);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, 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(sourceDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string }\n): Promise<Resource | undefined> => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n const { data, content } = matter.read(file);\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[] }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n })\n );\n }\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string\n) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), file.content);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname } 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 const semverRange = validRange(version);\n\n if (semverRange && valid(version)) {\n const match = parsedFiles.filter((c) => satisfies(c.version, semverRange));\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // Order by version\n const sorted = parsedFiles.sort((a, b) => {\n return a.version.localeCompare(b.version);\n });\n\n // latest version\n const match = sorted.length > 0 ? [sorted[sorted.length - 1]] : [];\n\n if (match.length > 0) {\n return match[0].path;\n }\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n const baseDir = pattern.includes('**') ? pattern.split('**')[0] : dirname(pattern);\n const files = globSync(pattern, { cwd: baseDir, ignore: ['node_modules/**', ...ignoreList] });\n return files;\n } catch (error) {\n throw new Error(`Error finding files: ${error}`);\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 const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${id}['\"]?\\\\s*$`, 'm');\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,mBAAe;AACf,IAAAC,oBAA2B;AAC3B,IAAAC,kBAAmB;;;ACHnB,kBAA8B;;;ACA9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AW,IAAI,OAAO,KAAM;AACrE,QAAM,2BAA2B,kBAAAF,QAAK,KAAK,kBAAAA,QAAK,QAAQ,YAAY,GAAG,yBAAyB;AAEhG,QAAM,aAAa,gBAAAG,QAAO,WAAW,wBAAwB;AAE7D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,YAAY,wBAAwB;AAE1D,SAAO;AACT;AAkBO,IAAM,mBAAmB,CAAC,cAAsB,OAAO,IAAY,YAAqB;AAC7F,QAAM,OAAO,MAAM,aAAa,WAAW,IAAI,OAAO;AACtD,SAAO,CAAC,CAAC;AACX;AAqBO,IAAM,qBACX,CAAC,cAAsB,OAAO,IAAY,SAA0C,YAAqB;AACvG,MAAI,SAAiB,MAAM,UAAU,SAAS,EAAE,IAAI,OAAO;AAC3D,QAAM,aAAa,MAAM,gBAAgB,WAAW,IAAI,OAAO;AAG/D,QAAM,YAAY,kBAAAH,QAAK,QAAQ,YAAY,YAAY,EAAE;AAEzD,MAAI,OAAO,aAAa,QAAW;AACjC,WAAO,WAAW,CAAC;AAAA,EACrB;AAEA,QAAM,sBAAsB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,MAAM,EAAE,YAAY,QAAQ,OAAO;AAE5G,MAAI,qBAAqB;AACvB;AAAA,EACF;AAGA,SAAO,SAAS,KAAK,OAAO;AAE5B,QAAM,aAAa,SAAS,EAAE,IAAI,SAAS,IAAI;AAC/C,QAAM,YAAY,SAAS,EAAE,QAAQ,EAAE,QAAQ,cAAc,QAAQ,OAAO,MAAM,CAAC;AACrF;","names":["import_promises","import_node_path","import_node_fs","path","matter","match","fsSync","import_gray_matter","import_node_fs","import_semver","matter","fsSync","fs","file","path","import_gray_matter","path","fs","matter","fsSync"]}
|
|
1
|
+
{"version":3,"sources":["../src/domains.ts","../src/internal/resources.ts","../src/internal/utils.ts"],"sourcesContent":["import type { Domain, UbiquitousLanguageDictionary } from './types';\nimport fs from 'node:fs/promises';\nimport path, { join } from 'node:path';\nimport fsSync from 'node:fs';\nimport {\n addFileToResource,\n getResource,\n getResourcePath,\n getResources,\n rmResourceById,\n versionResource,\n writeResource,\n} from './internal/resources';\nimport { findFileById, readMdxFile, uniqueVersions } from './internal/utils';\nimport matter from 'gray-matter';\n\n/**\n * Returns a domain from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the domain\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomain } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the domain\n * const domain = await getDomain('Payment');\n *\n * // Gets a version of the domain\n * const domain = await getDomain('Payment', '0.0.1');\n * ```\n */\nexport const getDomain =\n (directory: string) =>\n async (id: string, version?: string): Promise<Domain> =>\n getResource(directory, id, version, { type: 'domain' }) as Promise<Domain>;\n\n/**\n * Returns all domains from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the domains.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomains } = utils('/path/to/eventcatalog');\n *\n * // Gets all domains (and versions) from the catalog\n * const domains = await getDomains();\n *\n * // Gets all domains (only latest version) from the catalog\n * const domains = await getDomains({ latestOnly: true });\n * ```\n */\nexport const getDomains =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Domain[]> =>\n getResources(directory, {\n type: 'domains',\n ignore: ['**/services/**', '**/events/**', '**/commands/**', '**/queries/**', '**/flows/**'],\n ...options,\n }) as Promise<Domain[]>;\n\n/**\n * Write a domain to EventCatalog.\n *\n * You can optionally overide the path of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a domain\n * // Domain would be written to domains/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Payment domain',\n * version: '0.0.1',\n * summary: 'Domain for all things to do with payments',\n * markdown: '# Hello world',\n * });\n *\n * // Write a domain to the catalog but override the path\n * // Domain would be written to domains/Inventory/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/Payment\"});\n *\n * // Write a domain to the catalog and override the existing content (if there is any)\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { override: true });\n *\n * // Write a domain to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeDomain =\n (directory: string) =>\n async (\n domain: Domain,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n ) => {\n const resource: Domain = { ...domain };\n\n if (Array.isArray(domain.services)) {\n resource.services = uniqueVersions(domain.services);\n }\n\n return await writeResource(directory, resource, { ...options, type: 'domain' });\n };\n\n/**\n * Version a domain by it's id.\n *\n * Takes the latest domain and moves it to a versioned directory.\n * All files with this domain are also versioned. (e.g /domains/Payment/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionDomain } = utils('/path/to/eventcatalog');\n *\n * // moves the latest Payment domain to a versioned directory\n * // the version within that domain is used as the version number.\n * await versionDomain('Payment');\n *\n * ```\n */\nexport const versionDomain = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a domain at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomain } = utils('/path/to/eventcatalog');\n *\n * // Removes the domain at domains/Payment\n * await rmDomain('/Payment');\n * ```\n */\nexport const rmDomain = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a domain by it's id.\n *\n * Optionally specify a version to delete a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomainById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest Payment event\n * await rmDomainById('Payment');\n *\n * // deletes a specific version of the Payment event\n * await rmDomainById('Payment', '0.0.1');\n * ```\n */\nexport const rmDomainById = (directory: string) => async (id: string, version?: string, persistFiles?: boolean) =>\n rmResourceById(directory, id, version, { type: 'domain', persistFiles });\n\n/**\n * Add a file to a domain by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToDomain } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToDomain =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Adds a ubiquitous language dictionary to a domain.\n *\n * Optionally specify a version to add a ubiquitous language dictionary to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addUbiquitousLanguageToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a ubiquitous language dictionary to the latest Payment domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] });\n *\n * // Adds a ubiquitous language dictionary to a specific version of the domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] }, '0.0.1');\n * ```\n */\n\nexport const addUbiquitousLanguageToDomain =\n (directory: string) => async (id: string, ubiquitousLanguageDictionary: UbiquitousLanguageDictionary, version?: string) => {\n const content = matter.stringify('', {\n ...ubiquitousLanguageDictionary,\n });\n await addFileToResource(directory, id, { content, fileName: 'ubiquitous-language.mdx' }, version);\n };\n\n/**\n * Returns the ubiquitous language dictionary from a domain.\n *\n * Optionally specify a version to get the ubiquitous language dictionary from a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUbiquitousLanguageFromDomain } = utils('/path/to/eventcatalog');\n *\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment');\n *\n * // Returns the ubiquitous language dictionary from a specific version of the domain\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment', '0.0.1');\n * ```\n */\nexport const getUbiquitousLanguageFromDomain = (directory: string) => async (id: string, version?: string) => {\n const pathToDomain = (await findFileById(directory, id, version)) || '';\n const pathToUbiquitousLanguage = path.join(path.dirname(pathToDomain), 'ubiquitous-language.mdx');\n\n const fileExists = fsSync.existsSync(pathToUbiquitousLanguage);\n\n if (!fileExists) {\n return undefined;\n }\n\n const content = await readMdxFile(pathToUbiquitousLanguage);\n\n return content;\n};\n\n/**\n * Check to see if the catalog has a version for the given domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { domainHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await domainHasVersion('Orders', '0.0.1');\n * await domainHasVersion('Orders', 'latest');\n * await domainHasVersion('Orders', '0.0.x');*\n *\n * ```\n */\nexport const domainHasVersion = (directory: string) => async (id: string, version?: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n\n/**\n * Add a service to a domain by it's id.\n *\n * Optionally specify a version to add the service to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds a service to the domain\n * const { addServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a service (Orders Service) to the domain (Orders)\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' });\n * // Adds a service (Orders Service) to the domain (Orders) with a specific version\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' }, '1.0.0');\n * ```\n */\n\nexport const addServiceToDomain =\n (directory: string) => async (id: string, service: { id: string; version: string }, version?: string) => {\n let domain: Domain = await getDomain(directory)(id, version);\n const domainPath = await getResourcePath(directory, id, version);\n\n // Get the extension of the file\n const extension = path.extname(domainPath?.fullPath || '');\n\n if (domain.services === undefined) {\n domain.services = [];\n }\n\n const serviceExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);\n\n if (serviceExistsInList) {\n return;\n }\n\n // Add service to the list\n domain.services.push(service);\n\n await rmDomainById(directory)(id, version, true);\n await writeDomain(directory)(domain, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n const sourceDirectory = dirname(file);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, 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(sourceDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string }\n): Promise<Resource | undefined> => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n const { data, content } = matter.read(file);\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[] }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n })\n );\n }\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string\n) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), file.content);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\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 const semverRange = validRange(version);\n\n if (semverRange && valid(version)) {\n const match = parsedFiles.filter((c) => satisfies(c.version, semverRange));\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // Order by version\n const sorted = parsedFiles.sort((a, b) => {\n return a.version.localeCompare(b.version);\n });\n\n // latest version\n const match = sorted.length > 0 ? [sorted[sorted.length - 1]] : [];\n\n if (match.length > 0) {\n return match[0].path;\n }\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 const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${id}['\"]?\\\\s*$`, 'm');\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,mBAAe;AACf,IAAAC,oBAA2B;AAC3B,IAAAC,kBAAmB;;;ACHnB,kBAA8B;;;ACA9B,kBAAyB;AACzB,qBAAmB;AACnB,sBAAsD;AACtD,uBAA4F;AAC5F,yBAAmB;AACnB,oBAA6C;AAKtC,IAAM,gBAAgB,OAAO,YAAoB,IAAY,YAAoB;AACtF,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,oBAAoB;AAC9D,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,oBAAoB;AAE9D,QAAM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AAW,IAAI,EAAE,SAAS,UAAU,0BAA0B,GAAG,OAAO;AAClG;AAmBK,IAAM,kCAAkC,CAAC,cAAsB,OAAO,IAAY,YAAqB;AAC5G,QAAM,eAAgB,MAAM,aAAa,WAAW,IAAI,OAAO,KAAM;AACrE,QAAM,2BAA2B,kBAAAF,QAAK,KAAK,kBAAAA,QAAK,QAAQ,YAAY,GAAG,yBAAyB;AAEhG,QAAM,aAAa,gBAAAG,QAAO,WAAW,wBAAwB;AAE7D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,YAAY,wBAAwB;AAE1D,SAAO;AACT;AAkBO,IAAM,mBAAmB,CAAC,cAAsB,OAAO,IAAY,YAAqB;AAC7F,QAAM,OAAO,MAAM,aAAa,WAAW,IAAI,OAAO;AACtD,SAAO,CAAC,CAAC;AACX;AAqBO,IAAM,qBACX,CAAC,cAAsB,OAAO,IAAY,SAA0C,YAAqB;AACvG,MAAI,SAAiB,MAAM,UAAU,SAAS,EAAE,IAAI,OAAO;AAC3D,QAAM,aAAa,MAAM,gBAAgB,WAAW,IAAI,OAAO;AAG/D,QAAM,YAAY,kBAAAH,QAAK,QAAQ,YAAY,YAAY,EAAE;AAEzD,MAAI,OAAO,aAAa,QAAW;AACjC,WAAO,WAAW,CAAC;AAAA,EACrB;AAEA,QAAM,sBAAsB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,MAAM,EAAE,YAAY,QAAQ,OAAO;AAE5G,MAAI,qBAAqB;AACvB;AAAA,EACF;AAGA,SAAO,SAAS,KAAK,OAAO;AAE5B,QAAM,aAAa,SAAS,EAAE,IAAI,SAAS,IAAI;AAC/C,QAAM,YAAY,SAAS,EAAE,QAAQ,EAAE,QAAQ,cAAc,QAAQ,OAAO,MAAM,CAAC;AACrF;","names":["import_promises","import_node_path","import_node_fs","path","matter","match","fsSync","import_gray_matter","import_node_fs","import_semver","matter","fsSync","fs","file","path","import_gray_matter","path","fs","matter","fsSync"]}
|
package/dist/domains.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { dirname as dirname2, join as join2 } from "path";
|
|
|
10
10
|
import { globSync } from "glob";
|
|
11
11
|
import fsSync from "node:fs";
|
|
12
12
|
import { copy } from "fs-extra";
|
|
13
|
-
import { join, dirname } from "node:path";
|
|
13
|
+
import { join, dirname, normalize, resolve, relative } from "node:path";
|
|
14
14
|
import matter from "gray-matter";
|
|
15
15
|
import { satisfies, validRange, valid } from "semver";
|
|
16
16
|
var versionExists = async (catalogDir, id, version) => {
|
|
@@ -44,12 +44,28 @@ var findFileById = async (catalogDir, id, version) => {
|
|
|
44
44
|
};
|
|
45
45
|
var getFiles = async (pattern, ignore = "") => {
|
|
46
46
|
try {
|
|
47
|
+
const normalizedInputPattern = normalize(pattern);
|
|
48
|
+
const absoluteBaseDir = resolve(
|
|
49
|
+
normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : dirname(normalizedInputPattern)
|
|
50
|
+
);
|
|
51
|
+
let relativePattern = relative(absoluteBaseDir, normalizedInputPattern);
|
|
52
|
+
relativePattern = relativePattern.replace(/\\/g, "/");
|
|
47
53
|
const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
const files = globSync(relativePattern, {
|
|
55
|
+
cwd: absoluteBaseDir,
|
|
56
|
+
ignore: ["node_modules/**", ...ignoreList],
|
|
57
|
+
absolute: true,
|
|
58
|
+
nodir: true
|
|
59
|
+
});
|
|
60
|
+
return files.map(normalize);
|
|
51
61
|
} catch (error) {
|
|
52
|
-
|
|
62
|
+
const absoluteBaseDirForError = resolve(
|
|
63
|
+
normalize(pattern).includes("**") ? normalize(pattern).split("**")[0] : dirname(normalize(pattern))
|
|
64
|
+
);
|
|
65
|
+
const relativePatternForError = relative(absoluteBaseDirForError, normalize(pattern)).replace(/\\/g, "/");
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
|
|
68
|
+
);
|
|
53
69
|
}
|
|
54
70
|
};
|
|
55
71
|
var readMdxFile = async (path2) => {
|
package/dist/domains.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/domains.ts","../src/internal/resources.ts","../src/internal/utils.ts"],"sourcesContent":["import type { Domain, UbiquitousLanguageDictionary } from './types';\nimport fs from 'node:fs/promises';\nimport path, { join } from 'node:path';\nimport fsSync from 'node:fs';\nimport {\n addFileToResource,\n getResource,\n getResourcePath,\n getResources,\n rmResourceById,\n versionResource,\n writeResource,\n} from './internal/resources';\nimport { findFileById, readMdxFile, uniqueVersions } from './internal/utils';\nimport matter from 'gray-matter';\n\n/**\n * Returns a domain from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the domain\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomain } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the domain\n * const domain = await getDomain('Payment');\n *\n * // Gets a version of the domain\n * const domain = await getDomain('Payment', '0.0.1');\n * ```\n */\nexport const getDomain =\n (directory: string) =>\n async (id: string, version?: string): Promise<Domain> =>\n getResource(directory, id, version, { type: 'domain' }) as Promise<Domain>;\n\n/**\n * Returns all domains from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the domains.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomains } = utils('/path/to/eventcatalog');\n *\n * // Gets all domains (and versions) from the catalog\n * const domains = await getDomains();\n *\n * // Gets all domains (only latest version) from the catalog\n * const domains = await getDomains({ latestOnly: true });\n * ```\n */\nexport const getDomains =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Domain[]> =>\n getResources(directory, {\n type: 'domains',\n ignore: ['**/services/**', '**/events/**', '**/commands/**', '**/queries/**', '**/flows/**'],\n ...options,\n }) as Promise<Domain[]>;\n\n/**\n * Write a domain to EventCatalog.\n *\n * You can optionally overide the path of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a domain\n * // Domain would be written to domains/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Payment domain',\n * version: '0.0.1',\n * summary: 'Domain for all things to do with payments',\n * markdown: '# Hello world',\n * });\n *\n * // Write a domain to the catalog but override the path\n * // Domain would be written to domains/Inventory/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/Payment\"});\n *\n * // Write a domain to the catalog and override the existing content (if there is any)\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { override: true });\n *\n * // Write a domain to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeDomain =\n (directory: string) =>\n async (\n domain: Domain,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n ) => {\n const resource: Domain = { ...domain };\n\n if (Array.isArray(domain.services)) {\n resource.services = uniqueVersions(domain.services);\n }\n\n return await writeResource(directory, resource, { ...options, type: 'domain' });\n };\n\n/**\n * Version a domain by it's id.\n *\n * Takes the latest domain and moves it to a versioned directory.\n * All files with this domain are also versioned. (e.g /domains/Payment/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionDomain } = utils('/path/to/eventcatalog');\n *\n * // moves the latest Payment domain to a versioned directory\n * // the version within that domain is used as the version number.\n * await versionDomain('Payment');\n *\n * ```\n */\nexport const versionDomain = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a domain at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomain } = utils('/path/to/eventcatalog');\n *\n * // Removes the domain at domains/Payment\n * await rmDomain('/Payment');\n * ```\n */\nexport const rmDomain = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a domain by it's id.\n *\n * Optionally specify a version to delete a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomainById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest Payment event\n * await rmDomainById('Payment');\n *\n * // deletes a specific version of the Payment event\n * await rmDomainById('Payment', '0.0.1');\n * ```\n */\nexport const rmDomainById = (directory: string) => async (id: string, version?: string, persistFiles?: boolean) =>\n rmResourceById(directory, id, version, { type: 'domain', persistFiles });\n\n/**\n * Add a file to a domain by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToDomain } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToDomain =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Adds a ubiquitous language dictionary to a domain.\n *\n * Optionally specify a version to add a ubiquitous language dictionary to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addUbiquitousLanguageToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a ubiquitous language dictionary to the latest Payment domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] });\n *\n * // Adds a ubiquitous language dictionary to a specific version of the domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] }, '0.0.1');\n * ```\n */\n\nexport const addUbiquitousLanguageToDomain =\n (directory: string) => async (id: string, ubiquitousLanguageDictionary: UbiquitousLanguageDictionary, version?: string) => {\n const content = matter.stringify('', {\n ...ubiquitousLanguageDictionary,\n });\n await addFileToResource(directory, id, { content, fileName: 'ubiquitous-language.mdx' }, version);\n };\n\n/**\n * Returns the ubiquitous language dictionary from a domain.\n *\n * Optionally specify a version to get the ubiquitous language dictionary from a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUbiquitousLanguageFromDomain } = utils('/path/to/eventcatalog');\n *\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment');\n *\n * // Returns the ubiquitous language dictionary from a specific version of the domain\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment', '0.0.1');\n * ```\n */\nexport const getUbiquitousLanguageFromDomain = (directory: string) => async (id: string, version?: string) => {\n const pathToDomain = (await findFileById(directory, id, version)) || '';\n const pathToUbiquitousLanguage = path.join(path.dirname(pathToDomain), 'ubiquitous-language.mdx');\n\n const fileExists = fsSync.existsSync(pathToUbiquitousLanguage);\n\n if (!fileExists) {\n return undefined;\n }\n\n const content = await readMdxFile(pathToUbiquitousLanguage);\n\n return content;\n};\n\n/**\n * Check to see if the catalog has a version for the given domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { domainHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await domainHasVersion('Orders', '0.0.1');\n * await domainHasVersion('Orders', 'latest');\n * await domainHasVersion('Orders', '0.0.x');*\n *\n * ```\n */\nexport const domainHasVersion = (directory: string) => async (id: string, version?: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n\n/**\n * Add a service to a domain by it's id.\n *\n * Optionally specify a version to add the service to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds a service to the domain\n * const { addServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a service (Orders Service) to the domain (Orders)\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' });\n * // Adds a service (Orders Service) to the domain (Orders) with a specific version\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' }, '1.0.0');\n * ```\n */\n\nexport const addServiceToDomain =\n (directory: string) => async (id: string, service: { id: string; version: string }, version?: string) => {\n let domain: Domain = await getDomain(directory)(id, version);\n const domainPath = await getResourcePath(directory, id, version);\n\n // Get the extension of the file\n const extension = path.extname(domainPath?.fullPath || '');\n\n if (domain.services === undefined) {\n domain.services = [];\n }\n\n const serviceExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);\n\n if (serviceExistsInList) {\n return;\n }\n\n // Add service to the list\n domain.services.push(service);\n\n await rmDomainById(directory)(id, version, true);\n await writeDomain(directory)(domain, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n const sourceDirectory = dirname(file);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, 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(sourceDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string }\n): Promise<Resource | undefined> => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n const { data, content } = matter.read(file);\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[] }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n })\n );\n }\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string\n) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), file.content);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname } 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 const semverRange = validRange(version);\n\n if (semverRange && valid(version)) {\n const match = parsedFiles.filter((c) => satisfies(c.version, semverRange));\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // Order by version\n const sorted = parsedFiles.sort((a, b) => {\n return a.version.localeCompare(b.version);\n });\n\n // latest version\n const match = sorted.length > 0 ? [sorted[sorted.length - 1]] : [];\n\n if (match.length > 0) {\n return match[0].path;\n }\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n const baseDir = pattern.includes('**') ? pattern.split('**')[0] : dirname(pattern);\n const files = globSync(pattern, { cwd: baseDir, ignore: ['node_modules/**', ...ignoreList] });\n return files;\n } catch (error) {\n throw new Error(`Error finding files: ${error}`);\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 const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${id}['\"]?\\\\s*$`, 'm');\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 (!u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AO;AAClG;AAmBK,IAAM,kCAAkC,CAAC,cAAsB,OAAO,IAAY,YAAqB;AAC5G,QAAM,eAAgB,MAAM,aAAa,WAAW,IAAI,OAAO,KAAM;AACrE,QAAM,2BAA2B,KAAK,KAAK,KAAK,QAAQ,YAAY,GAAG,yBAAyB;AAEhG,QAAM,aAAaI,QAAO,WAAW,wBAAwB;AAE7D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,YAAY,wBAAwB;AAE1D,SAAO;AACT;AAkBO,IAAM,mBAAmB,CAAC,cAAsB,OAAO,IAAY,YAAqB;AAC7F,QAAM,OAAO,MAAM,aAAa,WAAW,IAAI,OAAO;AACtD,SAAO,CAAC,CAAC;AACX;AAqBO,IAAM,qBACX,CAAC,cAAsB,OAAO,IAAY,SAA0C,YAAqB;AACvG,MAAI,SAAiB,MAAM,UAAU,SAAS,EAAE,IAAI,OAAO;AAC3D,QAAM,aAAa,MAAM,gBAAgB,WAAW,IAAI,OAAO;AAG/D,QAAM,YAAY,KAAK,QAAQ,YAAY,YAAY,EAAE;AAEzD,MAAI,OAAO,aAAa,QAAW;AACjC,WAAO,WAAW,CAAC;AAAA,EACrB;AAEA,QAAM,sBAAsB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,MAAM,EAAE,YAAY,QAAQ,OAAO;AAE5G,MAAI,qBAAqB;AACvB;AAAA,EACF;AAGA,SAAO,SAAS,KAAK,OAAO;AAE5B,QAAM,aAAa,SAAS,EAAE,IAAI,SAAS,IAAI;AAC/C,QAAM,YAAY,SAAS,EAAE,QAAQ,EAAE,QAAQ,cAAc,QAAQ,OAAO,MAAM,CAAC;AACrF;","names":["fs","join","fsSync","dirname","join","path","match","matter","fsSync","satisfies","dirname","file","join","path","join","matter","path","fs","join","fsSync"]}
|
|
1
|
+
{"version":3,"sources":["../src/domains.ts","../src/internal/resources.ts","../src/internal/utils.ts"],"sourcesContent":["import type { Domain, UbiquitousLanguageDictionary } from './types';\nimport fs from 'node:fs/promises';\nimport path, { join } from 'node:path';\nimport fsSync from 'node:fs';\nimport {\n addFileToResource,\n getResource,\n getResourcePath,\n getResources,\n rmResourceById,\n versionResource,\n writeResource,\n} from './internal/resources';\nimport { findFileById, readMdxFile, uniqueVersions } from './internal/utils';\nimport matter from 'gray-matter';\n\n/**\n * Returns a domain from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the domain\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomain } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the domain\n * const domain = await getDomain('Payment');\n *\n * // Gets a version of the domain\n * const domain = await getDomain('Payment', '0.0.1');\n * ```\n */\nexport const getDomain =\n (directory: string) =>\n async (id: string, version?: string): Promise<Domain> =>\n getResource(directory, id, version, { type: 'domain' }) as Promise<Domain>;\n\n/**\n * Returns all domains from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the domains.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getDomains } = utils('/path/to/eventcatalog');\n *\n * // Gets all domains (and versions) from the catalog\n * const domains = await getDomains();\n *\n * // Gets all domains (only latest version) from the catalog\n * const domains = await getDomains({ latestOnly: true });\n * ```\n */\nexport const getDomains =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Domain[]> =>\n getResources(directory, {\n type: 'domains',\n ignore: ['**/services/**', '**/events/**', '**/commands/**', '**/queries/**', '**/flows/**'],\n ...options,\n }) as Promise<Domain[]>;\n\n/**\n * Write a domain to EventCatalog.\n *\n * You can optionally overide the path of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a domain\n * // Domain would be written to domains/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Payment domain',\n * version: '0.0.1',\n * summary: 'Domain for all things to do with payments',\n * markdown: '# Hello world',\n * });\n *\n * // Write a domain to the catalog but override the path\n * // Domain would be written to domains/Inventory/Payment\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/Payment\"});\n *\n * // Write a domain to the catalog and override the existing content (if there is any)\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { override: true });\n *\n * // Write a domain to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\n * await writeDomain({\n * id: 'Payment',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeDomain =\n (directory: string) =>\n async (\n domain: Domain,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n ) => {\n const resource: Domain = { ...domain };\n\n if (Array.isArray(domain.services)) {\n resource.services = uniqueVersions(domain.services);\n }\n\n return await writeResource(directory, resource, { ...options, type: 'domain' });\n };\n\n/**\n * Version a domain by it's id.\n *\n * Takes the latest domain and moves it to a versioned directory.\n * All files with this domain are also versioned. (e.g /domains/Payment/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionDomain } = utils('/path/to/eventcatalog');\n *\n * // moves the latest Payment domain to a versioned directory\n * // the version within that domain is used as the version number.\n * await versionDomain('Payment');\n *\n * ```\n */\nexport const versionDomain = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a domain at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomain } = utils('/path/to/eventcatalog');\n *\n * // Removes the domain at domains/Payment\n * await rmDomain('/Payment');\n * ```\n */\nexport const rmDomain = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a domain by it's id.\n *\n * Optionally specify a version to delete a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmDomainById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest Payment event\n * await rmDomainById('Payment');\n *\n * // deletes a specific version of the Payment event\n * await rmDomainById('Payment', '0.0.1');\n * ```\n */\nexport const rmDomainById = (directory: string) => async (id: string, version?: string, persistFiles?: boolean) =>\n rmResourceById(directory, id, version, { type: 'domain', persistFiles });\n\n/**\n * Add a file to a domain by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToDomain } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the Payment event\n * await addFileToDomain('Payment', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToDomain =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Adds a ubiquitous language dictionary to a domain.\n *\n * Optionally specify a version to add a ubiquitous language dictionary to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addUbiquitousLanguageToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a ubiquitous language dictionary to the latest Payment domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] });\n *\n * // Adds a ubiquitous language dictionary to a specific version of the domain\n * await addUbiquitousLanguageToDomain('Payment', { dictionary: [{ id: 'Order', name: 'Order', summary: 'All things to do with the payment systems', description: 'This is a description', icon: 'KeyIcon' }] }, '0.0.1');\n * ```\n */\n\nexport const addUbiquitousLanguageToDomain =\n (directory: string) => async (id: string, ubiquitousLanguageDictionary: UbiquitousLanguageDictionary, version?: string) => {\n const content = matter.stringify('', {\n ...ubiquitousLanguageDictionary,\n });\n await addFileToResource(directory, id, { content, fileName: 'ubiquitous-language.mdx' }, version);\n };\n\n/**\n * Returns the ubiquitous language dictionary from a domain.\n *\n * Optionally specify a version to get the ubiquitous language dictionary from a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUbiquitousLanguageFromDomain } = utils('/path/to/eventcatalog');\n *\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment');\n *\n * // Returns the ubiquitous language dictionary from a specific version of the domain\n * const ubiquitousLanguage = await getUbiquitousLanguageFromDomain('Payment', '0.0.1');\n * ```\n */\nexport const getUbiquitousLanguageFromDomain = (directory: string) => async (id: string, version?: string) => {\n const pathToDomain = (await findFileById(directory, id, version)) || '';\n const pathToUbiquitousLanguage = path.join(path.dirname(pathToDomain), 'ubiquitous-language.mdx');\n\n const fileExists = fsSync.existsSync(pathToUbiquitousLanguage);\n\n if (!fileExists) {\n return undefined;\n }\n\n const content = await readMdxFile(pathToUbiquitousLanguage);\n\n return content;\n};\n\n/**\n * Check to see if the catalog has a version for the given domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { domainHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await domainHasVersion('Orders', '0.0.1');\n * await domainHasVersion('Orders', 'latest');\n * await domainHasVersion('Orders', '0.0.x');*\n *\n * ```\n */\nexport const domainHasVersion = (directory: string) => async (id: string, version?: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n\n/**\n * Add a service to a domain by it's id.\n *\n * Optionally specify a version to add the service to a specific version of the domain.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds a service to the domain\n * const { addServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Adds a service (Orders Service) to the domain (Orders)\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' });\n * // Adds a service (Orders Service) to the domain (Orders) with a specific version\n * await addServiceToDomain('Orders', { service: 'Order Service', version: '2.0.0' }, '1.0.0');\n * ```\n */\n\nexport const addServiceToDomain =\n (directory: string) => async (id: string, service: { id: string; version: string }, version?: string) => {\n let domain: Domain = await getDomain(directory)(id, version);\n const domainPath = await getResourcePath(directory, id, version);\n\n // Get the extension of the file\n const extension = path.extname(domainPath?.fullPath || '');\n\n if (domain.services === undefined) {\n domain.services = [];\n }\n\n const serviceExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);\n\n if (serviceExistsInList) {\n return;\n }\n\n // Add service to the list\n domain.services.push(service);\n\n await rmDomainById(directory)(id, version, true);\n await writeDomain(directory)(domain, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n const sourceDirectory = dirname(file);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, 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(sourceDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string }\n): Promise<Resource | undefined> => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n const { data, content } = matter.read(file);\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[] }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n })\n );\n }\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string\n) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), file.content);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\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 const semverRange = validRange(version);\n\n if (semverRange && valid(version)) {\n const match = parsedFiles.filter((c) => satisfies(c.version, semverRange));\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // Order by version\n const sorted = parsedFiles.sort((a, b) => {\n return a.version.localeCompare(b.version);\n });\n\n // latest version\n const match = sorted.length > 0 ? [sorted[sorted.length - 1]] : [];\n\n if (match.length > 0) {\n return match[0].path;\n }\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 const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${id}['\"]?\\\\s*$`, 'm');\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,SAAQ;AACf,OAAO,QAAQ,QAAAC,aAAY;AAC3B,OAAOC,aAAY;;;ACHnB,SAAS,WAAAC,UAAS,QAAAC,aAAY;;;ACA9B,SAAS,gBAAgB;AACzB,OAAO,YAAY;AACnB,SAAS,YAA6C;AACtD,SAAS,MAAM,SAAS,WAAiC,SAAmB,gBAAgB;AAC5F,OAAO,YAAY;AACnB,SAAS,WAAW,YAAY,aAAa;AAKtC,IAAM,gBAAgB,OAAO,YAAoB,IAAY,YAAoB;AACtF,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,oBAAoB;AAC9D,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,oBAAoB;AAE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AM,aAAa,WAAW,IAAI,OAAO,KAAM;AACrE,QAAM,2BAA2B,KAAK,KAAK,KAAK,QAAQ,YAAY,GAAG,yBAAyB;AAEhG,QAAM,aAAaI,QAAO,WAAW,wBAAwB;AAE7D,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,YAAY,wBAAwB;AAE1D,SAAO;AACT;AAkBO,IAAM,mBAAmB,CAAC,cAAsB,OAAO,IAAY,YAAqB;AAC7F,QAAM,OAAO,MAAM,aAAa,WAAW,IAAI,OAAO;AACtD,SAAO,CAAC,CAAC;AACX;AAqBO,IAAM,qBACX,CAAC,cAAsB,OAAO,IAAY,SAA0C,YAAqB;AACvG,MAAI,SAAiB,MAAM,UAAU,SAAS,EAAE,IAAI,OAAO;AAC3D,QAAM,aAAa,MAAM,gBAAgB,WAAW,IAAI,OAAO;AAG/D,QAAM,YAAY,KAAK,QAAQ,YAAY,YAAY,EAAE;AAEzD,MAAI,OAAO,aAAa,QAAW;AACjC,WAAO,WAAW,CAAC;AAAA,EACrB;AAEA,QAAM,sBAAsB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,MAAM,EAAE,YAAY,QAAQ,OAAO;AAE5G,MAAI,qBAAqB;AACvB;AAAA,EACF;AAGA,SAAO,SAAS,KAAK,OAAO;AAE5B,QAAM,aAAa,SAAS,EAAE,IAAI,SAAS,IAAI;AAC/C,QAAM,YAAY,SAAS,EAAE,QAAQ,EAAE,QAAQ,cAAc,QAAQ,OAAO,MAAM,CAAC;AACrF;","names":["fs","join","fsSync","dirname","join","path","match","matter","fsSync","satisfies","dirname","file","join","path","join","matter","path","fs","join","fsSync"]}
|
package/dist/eventcatalog.js
CHANGED
|
@@ -81,12 +81,28 @@ var findFileById = async (catalogDir, id, version) => {
|
|
|
81
81
|
};
|
|
82
82
|
var getFiles = async (pattern, ignore = "") => {
|
|
83
83
|
try {
|
|
84
|
+
const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
|
|
85
|
+
const absoluteBaseDir = (0, import_node_path.resolve)(
|
|
86
|
+
normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
|
|
87
|
+
);
|
|
88
|
+
let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
|
|
89
|
+
relativePattern = relativePattern.replace(/\\/g, "/");
|
|
84
90
|
const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
const files = (0, import_glob.globSync)(relativePattern, {
|
|
92
|
+
cwd: absoluteBaseDir,
|
|
93
|
+
ignore: ["node_modules/**", ...ignoreList],
|
|
94
|
+
absolute: true,
|
|
95
|
+
nodir: true
|
|
96
|
+
});
|
|
97
|
+
return files.map(import_node_path.normalize);
|
|
88
98
|
} catch (error) {
|
|
89
|
-
|
|
99
|
+
const absoluteBaseDirForError = (0, import_node_path.resolve)(
|
|
100
|
+
(0, import_node_path.normalize)(pattern).includes("**") ? (0, import_node_path.normalize)(pattern).split("**")[0] : (0, import_node_path.dirname)((0, import_node_path.normalize)(pattern))
|
|
101
|
+
);
|
|
102
|
+
const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
|
|
105
|
+
);
|
|
90
106
|
}
|
|
91
107
|
};
|
|
92
108
|
var readMdxFile = async (path4) => {
|