@eventcatalog/sdk 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/events.ts","../src/internal/utils.ts","../src/internal/resources.ts","../src/commands.ts","../src/queries.ts","../src/services.ts","../src/domains.ts"],"sourcesContent":["import { join } from 'node:path';\nimport {\n rmEvent,\n rmEventById,\n writeEvent,\n writeEventToService,\n versionEvent,\n getEvent,\n addFileToEvent,\n addSchemaToEvent,\n eventHasVersion,\n} from './events';\nimport {\n rmCommand,\n rmCommandById,\n writeCommand,\n writeCommandToService,\n versionCommand,\n getCommand,\n addFileToCommand,\n addSchemaToCommand,\n commandHasVersion,\n} from './commands';\nimport {\n rmQuery,\n rmQueryById,\n writeQuery,\n writeQueryToService,\n versionQuery,\n getQuery,\n addFileToQuery,\n addSchemaToQuery,\n queryHasVersion,\n} from './queries';\nimport {\n writeService,\n writeServiceToDomain,\n getService,\n versionService,\n rmService,\n rmServiceById,\n addFileToService,\n addMessageToService,\n serviceHasVersion,\n getSpecificationFilesForService,\n writeVersionedService,\n} from './services';\nimport {\n writeDomain,\n getDomain,\n versionDomain,\n rmDomain,\n rmDomainById,\n addFileToDomain,\n domainHasVersion,\n addServiceToDomain,\n} from './domains';\n\n/**\n * Init the SDK for EventCatalog\n *\n * @param path - The path to the EventCatalog directory\n *\n */\nexport default (path: string) => {\n return {\n /**\n * Returns an events from EventCatalog\n * @param id - The id of the event to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Event|Undefined\n */\n getEvent: getEvent(join(path)),\n /**\n * Adds an event to EventCatalog\n *\n * @param event - The event to write\n * @param options - Optional options to write the event\n *\n */\n writeEvent: writeEvent(join(path, 'events')),\n /**\n * Adds an event to a service in EventCatalog\n *\n * @param event - The event to write to the service\n * @param service - The service and it's id to write to the event to\n * @param options - Optional options to write the event\n *\n */\n writeEventToService: writeEventToService(join(path, 'services')),\n /**\n * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`\n *\n */\n rmEvent: rmEvent(join(path, 'events')),\n /**\n * Remove an event by an Event id\n *\n * @param id - The id of the event you want to remove\n *\n */\n rmEventById: rmEventById(join(path)),\n /**\n * Moves a given event id to the version directory\n * @param directory\n */\n versionEvent: versionEvent(join(path)),\n /**\n * Adds a file to the given event\n * @param id - The id of the event to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the event to add the file to\n * @returns\n */\n addFileToEvent: addFileToEvent(join(path)),\n /**\n * Adds a schema to the given event\n * @param id - The id of the event to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the event to add the schema to\n * @returns\n */\n addSchemaToEvent: addSchemaToEvent(join(path)),\n /**\n * Check to see if an event version exists\n * @param id - The id of the event\n * @param version - The version of the event (supports semver)\n * @returns\n */\n eventHasVersion: eventHasVersion(join(path)),\n\n /**\n * ================================\n * Commands\n * ================================\n */\n\n /**\n * Returns a command from EventCatalog\n * @param id - The id of the command to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Command|Undefined\n */\n getCommand: getCommand(join(path)),\n /**\n * Adds an command to EventCatalog\n *\n * @param command - The command to write\n * @param options - Optional options to write the command\n *\n */\n writeCommand: writeCommand(join(path, 'commands')),\n\n /**\n * Adds a command to a service in EventCatalog\n *\n * @param command - The command to write to the service\n * @param service - The service and it's id to write to the command to\n * @param options - Optional options to write the command\n *\n */\n writeCommandToService: writeCommandToService(join(path, 'services')),\n\n /**\n * Remove an command to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your command, e.g. `/Inventory/InventoryAdjusted`\n *\n */\n rmCommand: rmCommand(join(path, 'commands')),\n /**\n * Remove an command by an Event id\n *\n * @param id - The id of the command you want to remove\n *\n */\n rmCommandById: rmCommandById(join(path)),\n /**\n * Moves a given command id to the version directory\n * @param directory\n */\n versionCommand: versionCommand(join(path)),\n /**\n * Adds a file to the given command\n * @param id - The id of the command to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the command to add the file to\n * @returns\n */\n addFileToCommand: addFileToCommand(join(path)),\n /**\n * Adds a schema to the given command\n * @param id - The id of the command to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the command to add the schema to\n * @returns\n */\n addSchemaToCommand: addSchemaToCommand(join(path)),\n\n /**\n * Check to see if a command version exists\n * @param id - The id of the command\n * @param version - The version of the command (supports semver)\n * @returns\n */\n commandHasVersion: commandHasVersion(join(path)),\n\n /**\n * ================================\n * Queries\n * ================================\n */\n\n /**\n * Returns a query from EventCatalog\n * @param id - The id of the query to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Query|Undefined\n */\n getQuery: getQuery(join(path)),\n /**\n * Adds a query to EventCatalog\n *\n * @param query - The query to write\n * @param options - Optional options to write the event\n *\n */\n writeQuery: writeQuery(join(path, 'queries')),\n /**\n * Adds a query to a service in EventCatalog\n *\n * @param query - The query to write to the service\n * @param service - The service and it's id to write to the query to\n * @param options - Optional options to write the query\n *\n */\n writeQueryToService: writeQueryToService(join(path, 'services')),\n /**\n * Remove an query to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your query, e.g. `/Orders/GetOrder`\n *\n */\n rmQuery: rmQuery(join(path, 'queries')),\n /**\n * Remove a query by a Query id\n *\n * @param id - The id of the query you want to remove\n *\n */\n rmQueryById: rmQueryById(join(path)),\n /**\n * Moves a given query id to the version directory\n * @param directory\n */\n versionQuery: versionQuery(join(path)),\n /**\n * Adds a file to the given query\n * @param id - The id of the query to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the query to add the file to\n * @returns\n */\n addFileToQuery: addFileToQuery(join(path)),\n /**\n * Adds a schema to the given query\n * @param id - The id of the query to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the query to add the schema to\n * @returns\n */\n addSchemaToQuery: addSchemaToQuery(join(path)),\n /**\n * Check to see if an query version exists\n * @param id - The id of the query\n * @param version - The version of the query (supports semver)\n * @returns\n */\n queryHasVersion: queryHasVersion(join(path)),\n\n /**\n * ================================\n * SERVICES\n * ================================\n */\n\n /**\n * Adds a service to EventCatalog\n *\n * @param service - The service to write\n * @param options - Optional options to write the event\n *\n */\n writeService: writeService(join(path, 'services')),\n\n /**\n * Adds a versioned service to EventCatalog\n *\n * @param service - The service to write\n *\n */\n writeVersionedService: writeVersionedService(join(path, 'services')),\n\n /**\n * Adds a service to a domain in EventCatalog\n *\n * @param service - The service to write\n * @param domain - The domain to add the service to\n * @param options - Optional options to write the event\n *\n */\n writeServiceToDomain: writeServiceToDomain(join(path, 'domains')),\n /**\n * Returns a service from EventCatalog\n * @param id - The id of the service to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Service|Undefined\n */\n getService: getService(join(path)),\n /**\n * Moves a given service id to the version directory\n * @param directory\n */\n versionService: versionService(join(path)),\n /**\n * Remove a service from EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your service, e.g. `/InventoryService`\n *\n */\n rmService: rmService(join(path, 'services')),\n /**\n * Remove an service by an service id\n *\n * @param id - The id of the service you want to remove\n *\n */\n rmServiceById: rmServiceById(join(path)),\n /**\n * Adds a file to the given service\n * @param id - The id of the service to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the service to add the file to\n * @returns\n */\n addFileToService: addFileToService(join(path)),\n\n /**\n * Returns the specifications for a given service\n * @param id - The id of the service to retrieve the specifications for\n * @param version - Optional version of the service\n * @returns\n */\n getSpecificationFilesForService: getSpecificationFilesForService(join(path)),\n\n /**\n * Check to see if a service version exists\n * @param id - The id of the service\n * @param version - The version of the service (supports semver)\n * @returns\n */\n serviceHasVersion: serviceHasVersion(join(path)),\n\n /**\n * ================================\n * Domains\n * ================================\n */\n\n /**\n * Adds a domain to EventCatalog\n *\n * @param domain - The domain to write\n * @param options - Optional options to write the event\n *\n */\n writeDomain: writeDomain(join(path, 'domains')),\n\n /**\n * Returns a domain from EventCatalog\n * @param id - The id of the domain to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Domain|Undefined\n */\n getDomain: getDomain(join(path, 'domains')),\n /**\n * Moves a given domain id to the version directory\n * @param directory\n */\n versionDomain: versionDomain(join(path, 'domains')),\n /**\n * Remove a domain from EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your domain, e.g. `/Payment`\n *\n */\n rmDomain: rmDomain(join(path, 'domains')),\n /**\n * Remove an service by an domain id\n *\n * @param id - The id of the domain you want to remove\n *\n */\n rmDomainById: rmDomainById(join(path, 'domains')),\n /**\n * Adds a file to the given domain\n * @param id - The id of the domain to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the domain to add the file to\n * @returns\n */\n addFileToDomain: addFileToDomain(join(path, 'domains')),\n /**\n * Add an event to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addEventToService } = utils('/path/to/eventcatalog');\n *\n * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send\n * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });\n *\n * // adds a new event (OrderComplete) that the InventoryService will receive\n * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });\n *\n * ```\n */\n addEventToService: addMessageToService(join(path)),\n /**\n * Add a command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addCommandToService } = utils('/path/to/eventcatalog');\n *\n * // adds a new command (UpdateInventoryCommand) that the InventoryService will send\n * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });\n *\n * // adds a new command (VerifyInventory) that the InventoryService will receive\n * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '2.0.0' });\n *\n * ```\n */\n addCommandToService: addMessageToService(join(path)),\n\n /**\n * Check to see if a domain version exists\n * @param id - The id of the domain\n * @param version - The version of the domain (supports semver)\n * @returns\n */\n domainHasVersion: domainHasVersion(join(path)),\n\n /**\n * Adds a given service to a domain\n * @param id - The id of the domain\n * @param service - The id and version of the service to add\n * @param version - (Optional) The version of the domain to add the service to\n * @returns\n */\n addServiceToDomain: addServiceToDomain(join(path, 'domains')),\n };\n};\n","import fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { findFileById } from './internal/utils';\nimport type { Event } from './types';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\n\n/**\n * Returns an event from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the event\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getEvent } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const event = await getEvent('InventoryAdjusted');\n *\n * // Gets a version of the event\n * const event = await getEvent('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const getEvent =\n (directory: string) =>\n async (id: string, version?: string): Promise<Event> =>\n getResource(directory, id, version, { type: 'event' }) as Promise<Event>;\n\n/**\n * Write an event to EventCatalog.\n *\n * You can optionally overide the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeEvent } = utils('/path/to/eventcatalog');\n *\n * // Write an event to the catalog\n * // Event would be written to events/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write an event to the catalog but override the path\n * // Event would be written to events/Inventory/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryAdjusted\"});\n * ```\n */\nexport const writeEvent =\n (directory: string) =>\n async (event: Event, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...event }, { ...options, type: 'event' });\n/**\n * Write an event to a service in EventCatalog.\n *\n * You can optionally override the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeEventToService } = utils('/path/to/eventcatalog');\n *\n * // Write an event to a given service in the catalog\n * // Event would be written to services/Inventory/events/InventoryAdjusted\n * await writeEventToService({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { id: 'Inventory' });\n * ```\n */\nexport const writeEventToService =\n (directory: string) =>\n async (event: Event, service: { id: string; version?: string }, options: { path: string } = { path: '' }) => {\n let pathForEvent =\n service.version && service.version !== 'latest'\n ? `/${service.id}/versioned/${service.version}/events`\n : `/${service.id}/events`;\n pathForEvent = join(pathForEvent, event.id);\n await writeResource(directory, { ...event }, { ...options, path: pathForEvent, type: 'event' });\n };\n\n/**\n * Delete an event at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEvent } = utils('/path/to/eventcatalog');\n *\n * // removes an event at the given path (events dir is appended to the given path)\n * // Removes the event at events/InventoryAdjusted\n * await rmEvent('/InventoryAdjusted');\n * ```\n */\nexport const rmEvent = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete an event by it's id.\n *\n * Optionally specify a version to delete a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEventById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryAdjusted event\n * await rmEventById('InventoryAdjusted');\n *\n * // deletes a specific version of the InventoryAdjusted event\n * await rmEventById('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const rmEventById = (directory: string) => async (id: string, version?: string) => {\n await rmResourceById(directory, id, version, { type: 'event' });\n};\n\n/**\n * Version an event by it's id.\n *\n * Takes the latest event and moves it to a versioned directory.\n * All files with this event are also versioned (e.g /events/InventoryAdjusted/schema.json)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionEvent } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryAdjusted event to a versioned directory\n * // the version within that event is used as the version number.\n * await versionEvent('InventoryAdjusted');\n *\n * ```\n */\nexport const versionEvent = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Add a file to an event by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToEvent } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToEvent =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Add a schema to an event by it's id.\n *\n * Optionally specify a version to add a schema to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToEvent } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToEvent =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n\n/**\n * Check to see if the catalog has a version for the given event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { eventHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await eventHasVersion('InventoryAdjusted', '0.0.1');\n * await eventHasVersion('InventoryAdjusted', 'latest');\n * await eventHasVersion('InventoryAdjusted', '0.0.x');*\n *\n * ```\n */\nexport const eventHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import { glob } from 'glob';\nimport fs from 'node:fs/promises';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join } 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`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n 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) => {\n try {\n const files = await glob(pattern, { ignore: 'node_modules/**' });\n return files;\n } catch (error) {\n throw new Error(`Error finding files: ${error}`);\n }\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${id}['\"]?\\\\s*$`, 'm');\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = await Promise.all(\n files.map(async (file) => {\n const content = await fs.readFile(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n })\n );\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n await fs.mkdir(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n await fs.rm(tmpDirectory, { recursive: true });\n};\n\n// Makes sure values in sends/recieves are unique\nexport const uniqueMessages = (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","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 { Message, Service } from '../types';\n\ntype Resource = Service | Message;\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`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No event 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 await fs.mkdir(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 await fs.rm(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 } = { path: '', type: '' }\n) => {\n // Get the path\n const path = options.path || `/${resource.id}`;\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists) {\n throw new Error(`Failed to write ${options.type} as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n const document = matter.stringify(markdown.trim(), frontmatter);\n await fs.mkdir(join(catalogDir, path), { recursive: true });\n await fs.writeFile(join(catalogDir, path, 'index.md'), document);\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 rmResourceById = async (catalogDir: string, id: string, version?: string, options?: { type: string }) => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\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 await Promise.all(matchedFiles.map((file) => fs.rm(file)));\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 await fs.writeFile(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 fs.readFile(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 fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { Command } from './types';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\nimport { findFileById } from './internal/utils';\nimport { addMessageToService } from './services';\n\n/**\n * Returns a command from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the command\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getCommand } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the command\n * const command = await getCommand('UpdateInventory');\n *\n * // Gets a version of the command\n * const command = await getCommand('UpdateInventory', '0.0.1');\n * ```\n */\nexport const getCommand =\n (directory: string) =>\n async (id: string, version?: string): Promise<Command> =>\n getResource(directory, id, version, { type: 'command' }) as Promise<Command>;\n\n/**\n * Write a command to EventCatalog.\n *\n * You can optionally override the path of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeCommand } = utils('/path/to/eventcatalog');\n *\n * // Write a command to the catalog\n * // Command would be written to commands/UpdateInventory\n * await writeCommand({\n * id: 'UpdateInventory',\n * name: 'Update Inventory',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write a command to the catalog but override the path\n * // Command would be written to commands/Inventory/UpdateInventory\n * await writeCommand({\n * id: 'UpdateInventory',\n * name: 'Update Inventory',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/UpdateInventory\"});\n * ```\n */\nexport const writeCommand =\n (directory: string) =>\n async (command: Command, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...command }, { ...options, type: 'command' });\n\n/**\n * Write an command to a service in EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeCommandToService } = utils('/path/to/eventcatalog');\n *\n * // Write an event to a given service in the catalog\n * // Event would be written to services/Inventory/commands/UpdateInventory\n * await writeCommandToService({\n * id: 'UpdateInventory',\n * name: 'Update Inventory',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { id: 'Inventory' });\n * ```\n */\nexport const writeCommandToService =\n (directory: string) =>\n async (command: Command, service: { id: string; version?: string }, options: { path: string } = { path: '' }) => {\n let pathForEvent =\n service.version && service.version !== 'latest'\n ? `/${service.id}/versioned/${service.version}/commands`\n : `/${service.id}/commands`;\n pathForEvent = join(pathForEvent, command.id);\n\n await writeResource(directory, { ...command }, { ...options, path: pathForEvent, type: 'command' });\n };\n\n/**\n * Delete a command at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmCommand } = utils('/path/to/eventcatalog');\n *\n * // removes a command at the given path (commands dir is appended to the given path)\n * // Removes the command at commands/UpdateInventory\n * await rmCommand('/UpdateInventory');\n * ```\n */\nexport const rmCommand = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a command by it's id.\n *\n * Optionally specify a version to delete a specific version of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmCommandById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest UpdateInventory command\n * await rmCommandById('UpdateInventory');\n *\n * // deletes a specific version of the UpdateInventory command\n * await rmCommandById('UpdateInventory', '0.0.1');\n * ```\n */\nexport const rmCommandById = (directory: string) => async (id: string, version?: string) =>\n rmResourceById(directory, id, version, { type: 'command' });\n\n/**\n * Version a command by it's id.\n *\n * Takes the latest command and moves it to a versioned directory.\n * All files with this command are also versioned (e.g /commands/UpdateInventory/schema.json)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionCommand } = utils('/path/to/eventcatalog');\n *\n * // moves the latest UpdateInventory command to a versioned directory\n * // the version within that command is used as the version number.\n * await versionCommand('UpdateInventory');\n *\n * ```\n */\nexport const versionCommand = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Add a file to a command by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToCommand } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest UpdateInventory command\n * await addFileToCommand('UpdateInventory', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the UpdateInventory command\n * await addFileToCommand('UpdateInventory', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToCommand =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Add a schema to a command by it's id.\n *\n * Optionally specify a version to add a schema to a specific version of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToCommand } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest UpdateInventory command\n * await addSchemaToCommand('UpdateInventory', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the UpdateInventory command\n * await addSchemaToCommand('UpdateInventory', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToCommand =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToCommand(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n\n/**\n * Check to see if the catalog has a version for the given command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { commandHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await commandHasVersion('InventoryAdjusted', '0.0.1');\n * await commandHasVersion('InventoryAdjusted', 'latest');\n * await commandHasVersion('InventoryAdjusted', '0.0.x');*\n *\n * ```\n */\nexport const commandHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { findFileById } from './internal/utils';\nimport type { Query } from './types';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\n\n/**\n * Returns a query from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the query\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getQuery } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const event = await getQuery('GetOrder');\n *\n * // Gets a version of the event\n * const event = await getQuery('GetOrder', '0.0.1');\n * ```\n */\nexport const getQuery =\n (directory: string) =>\n async (id: string, version?: string): Promise<Query> =>\n getResource(directory, id, version, { type: 'query' }) as Promise<Query>;\n\n/**\n * Write a query to EventCatalog.\n *\n * You can optionally override the path of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeQuery } = utils('/path/to/eventcatalog');\n *\n * // Write an event to the catalog\n * // Event would be written to queries/GetOrder\n * await writeQuery({\n * id: 'GetOrder',\n * name: 'Get Order',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write an event to the catalog but override the path\n * // Event would be written to queries/Inventory/GetOrder\n * await writeQuery({\n * id: 'GetOrder',\n * name: 'Get Order',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Orders/GetOrder\"});\n * ```\n */\nexport const writeQuery =\n (directory: string) =>\n async (query: Query, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...query }, { ...options, type: 'query' });\n/**\n * Write a query to a service in EventCatalog.\n *\n * You can optionally override the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeQueryToService } = utils('/path/to/eventcatalog');\n *\n * // Write an event to a given service in the catalog\n * // Event would be written to services/Orders/queries/GetOrder\n * await writeQueryToService({\n * id: 'GetOrder',\n * name: 'Get Order',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { id: 'Orders' });\n * ```\n */\nexport const writeQueryToService =\n (directory: string) =>\n async (query: Query, service: { id: string; version?: string }, options: { path: string } = { path: '' }) => {\n let pathForQuery =\n service.version && service.version !== 'latest'\n ? `/${service.id}/versioned/${service.version}/queries`\n : `/${service.id}/queries`;\n pathForQuery = join(pathForQuery, query.id);\n await writeResource(directory, { ...query }, { ...options, path: pathForQuery, type: 'query' });\n };\n\n/**\n * Delete a query at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmQuery } = utils('/path/to/eventcatalog');\n *\n * // removes an query at the given path (queries dir is appended to the given path)\n * // Removes the query at queries/GetOrders\n * await rmQuery('/GetOrders');\n * ```\n */\nexport const rmQuery = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a query by it's id.\n *\n * Optionally specify a version to delete a specific version of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmQueryById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryAdjusted query\n * await rmQueryById('GetOrder');\n *\n * // deletes a specific version of the GetOrder query\n * await rmQueryById('GetOrder', '0.0.1');\n * ```\n */\nexport const rmQueryById = (directory: string) => async (id: string, version?: string) => {\n await rmResourceById(directory, id, version, { type: 'query' });\n};\n\n/**\n * Version a query by it's id.\n *\n * Takes the latest query and moves it to a versioned directory.\n * All files with this query are also versioned (e.g /queries/GetOrder/schema.json)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionQuery } = utils('/path/to/eventcatalog');\n *\n * // moves the latest GetOrder query to a versioned directory\n * // the version within that query is used as the version number.\n * await versionQuery('GetOrder');\n *\n * ```\n */\nexport const versionQuery = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Add a file to a query by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToQuery } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest GetOrder query\n * await addFileToQuery('GetOrder', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the GetOrder query\n * await addFileToQuery('GetOrder', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToQuery =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Add a schema to a query by it's id.\n *\n * Optionally specify a version to add a schema to a specific version of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToQuery } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest GetOrder query\n * await addSchemaToQuery('GetOrder', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the GetOrder query\n * await addSchemaToQuery('GetOrder', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToQuery =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToQuery(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n\n/**\n * Check to see if the catalog has a version for the given query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { queryHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await queryHasVersion('GetOrder', '0.0.1');\n * await queryHasVersion('GetOrder', 'latest');\n * await queryHasVersion('GetOrder', '0.0.x');*\n *\n * ```\n */\nexport const queryHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import type { Service, Specifications } from './types';\nimport fs from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport {\n addFileToResource,\n getFileFromResource,\n getResource,\n rmResourceById,\n versionResource,\n writeResource,\n getVersionedDirectory,\n} from './internal/resources';\nimport { findFileById, uniqueMessages } from './internal/utils';\n\n/**\n * Returns a service from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the service\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getService } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const service = await getService('InventoryService');\n *\n * // Gets a version of the event\n * const service = await getService('InventoryService', '0.0.1');\n * ```\n */\nexport const getService =\n (directory: string) =>\n async (id: string, version?: string): Promise<Service> =>\n getResource(directory, id, version, { type: 'service' }) as Promise<Service>;\n/**\n * Write a Service to EventCatalog.\n *\n * You can optionally overide the path of the Service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeService } = utils('/path/to/eventcatalog');\n *\n * // Write a Service\n * // Service would be written to services/InventoryService\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * });\n *\n * // Write a service to the catalog but override the path\n * // Service would be written to services/Inventory/InventoryService\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryService\"});\n * ```\n */\nexport const writeService =\n (directory: string) =>\n async (service: Service, options: { path: string } = { path: '' }) => {\n const resource: Service = { ...service };\n\n if (Array.isArray(service.sends)) {\n resource.sends = uniqueMessages(service.sends);\n }\n\n if (Array.isArray(service.receives)) {\n resource.receives = uniqueMessages(service.receives);\n }\n\n return writeResource(directory, resource, { ...options, type: 'service' });\n };\n\n/**\n * Write a versioned service to EventCatalog.\n *\n * You can optionally overide the path of the Service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeVersionedService } = utils('/path/to/eventcatalog');\n *\n * // Write a service\n * // Service would be written to services/InventoryService/versioned/0.0.1\n * await writeVersionedService({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * });\n *\n * ```\n */\nexport const writeVersionedService = (directory: string) => async (service: Service) => {\n const resource: Service = { ...service };\n const path = getVersionedDirectory(service.id, service.version);\n\n return await writeService(directory)(resource, { path: path });\n};\n\n/**\n * Write a service to a domain in EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a service to a domain\n * // Service would be written to domains/Shopping/services/InventoryService\n * await writeServiceToDomain({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * }, { id: 'Shopping' });\n * ```\n */\nexport const writeServiceToDomain =\n (directory: string) =>\n async (\n service: Service,\n domain: { id: string; version?: string; direction?: string },\n options: { path: string } = { path: '' }\n ) => {\n let pathForService =\n domain.version && domain.version !== 'latest'\n ? `/${domain.id}/versioned/${domain.version}/services`\n : `/${domain.id}/services`;\n pathForService = join(pathForService, service.id);\n\n //\n await writeResource(directory, { ...service }, { ...options, path: pathForService, type: 'service' });\n };\n\n/**\n * Version a service by it's id.\n *\n * Takes the latest service and moves it to a versioned directory.\n * All files with this service are also versioned. (e.g /services/InventoryService/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionService } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryService service to a versioned directory\n * // the version within that service is used as the version number.\n * await versionService('InventoryService');\n *\n * ```\n */\nexport const versionService = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a service at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmService } = utils('/path/to/eventcatalog');\n *\n * // Removes the service at services/InventoryService\n * await rmService('/InventoryService');\n * ```\n */\nexport const rmService = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a service by it's id.\n *\n * Optionally specify a version to delete a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmServiceById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryService event\n * await rmServiceById('InventoryService');\n *\n * // deletes a specific version of the InventoryService event\n * await rmServiceById('InventoryService', '0.0.1');\n * ```\n */\nexport const rmServiceById = (directory: string) => async (id: string, version?: string) =>\n rmResourceById(directory, id, version, { type: 'service' });\n\n/**\n * Add a file to a service by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToService } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryService event\n * await addFileToService('InventoryService', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryService event\n * await addFileToService('InventoryService', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToService =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Returns specification files for a service\n *\n * Optionally specify a version to of the service\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getSpecificationFilesForService } = utils('/path/to/eventcatalog');\n *\n * // returns a list of specification files for a service\n * await getSpecificationFilesForService('InventoryService', '0.0.1');\n *\n * ```\n */\n\nexport const getSpecificationFilesForService = (directory: string) => async (id: string, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const filePathToService = await findFileById(directory, id, version);\n\n if (!filePathToService) throw new Error('Cannot find directory of service');\n\n let specs = [] as any;\n if (service.specifications) {\n const serviceSpecifications = service.specifications;\n const specificationFiles = Object.keys(serviceSpecifications);\n\n const getSpecs = specificationFiles.map(async (specFile) => {\n const fileName = serviceSpecifications[specFile as keyof Specifications];\n\n if (!fileName) {\n throw new Error(`Specification file name for ${specFile} is undefined`);\n }\n const rawFile = await getFileFromResource(directory, id, { fileName }, version);\n\n return { key: specFile, content: rawFile, fileName: fileName, path: join(dirname(filePathToService), fileName) };\n });\n\n specs = await Promise.all(getSpecs);\n }\n return specs;\n};\n\n/**\n * Add an event/command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds an event to the service or command to the service\n * const { addEventToService, addCommandToService } = utils('/path/to/eventcatalog');\n *\n * // Adds a new event (InventoryUpdatedEvent) that the InventoryService will send\n * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });\n * * // Adds a new event (OrderComplete) that the InventoryService will receive\n * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });\n *\n * // Adds a new command (UpdateInventoryCommand) that the InventoryService will send\n * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });\n * // Adds a new command (VerifyInventory) that the InventoryService will receive\n * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });\n *\n * ```\n */\n\nexport const addMessageToService =\n (directory: string) => async (id: string, direction: string, event: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n\n if (direction === 'sends') {\n if (service.sends === undefined) {\n service.sends = [];\n }\n // We first check if the event is already in the list\n for (let i = 0; i < service.sends.length; i++) {\n if (service.sends[i].id === event.id && service.sends[i].version === event.version) {\n return;\n }\n }\n service.sends.push({ id: event.id, version: event.version });\n } else if (direction === 'receives') {\n if (service.receives === undefined) {\n service.receives = [];\n }\n // We first check if the event is already in the list\n for (let i = 0; i < service.receives.length; i++) {\n if (service.receives[i].id === event.id && service.receives[i].version === event.version) {\n return;\n }\n }\n service.receives.push({ id: event.id, version: event.version });\n } else {\n throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);\n }\n\n await rmServiceById(directory)(id, version);\n await writeService(directory)(service);\n };\n\n/**\n * Check to see if the catalog has a version for the given service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { serviceHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await serviceHasVersion('InventoryService', '0.0.1');\n * await serviceHasVersion('InventoryService', 'latest');\n * await serviceHasVersion('InventoryService', '0.0.x');*\n *\n * ```\n */\nexport const serviceHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import type { Domain } from './types';\nimport fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\nimport { findFileById } from './internal/utils';\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 * 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 * // Event 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 * // Event 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 */\nexport const writeDomain =\n (directory: string) =>\n async (domain: Domain, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...domain }, { ...options, type: 'domain' });\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) =>\n rmResourceById(directory, id, version, { type: 'domain' });\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 * 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 an event/command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\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\n if (domain.services === undefined) {\n domain.services = [];\n }\n\n const eventExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);\n\n if (eventExistsInList) {\n return;\n }\n\n // Add service to the list\n domain.services.push(service);\n\n await rmDomainById(directory)(id, version);\n await writeDomain(directory)(domain);\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,oBAAqB;;;ACArB,IAAAC,mBAAe;AACf,IAAAC,oBAAqB;;;ACDrB,kBAAqB;AACrB,sBAAe;AACf,sBAAsD;AACtD,uBAAqB;AACrB,yBAAmB;AACnB,oBAA6C;AAKtC,IAAM,gBAAgB,OAAO,YAAoB,IAAY,YAAoB;AACtF,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,cAAc;AACxD,QAAM,eAAgB,MAAM,iBAAiB,OAAO,IAAI,OAAO,KAAM,CAAC;AACtE,SAAO,aAAa,SAAS;AAC/B;AAEO,IAAM,eAAe,OAAO,YAAoB,IAAY,YAAkD;AACnH,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,cAAc;AACxD,QAAM,eAAgB,MAAM,iBAAiB,OAAO,EAAE,KAAM,CAAC;AAC7D,QAAM,gBAAgB,aAAa,KAAK,CAAC,SAAS,CAAC,KAAK,SAAS,WAAW,CAAC;AAG7E,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAGA,QAAM,cAAc,aAAa,IAAI,CAAC,SAAS;AAC7C,UAAM,EAAE,KAAK,IAAI,mBA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AAAA,IAOxC,cAAc,iBAAa,wBAAK,MAAM,SAAS,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQhD,iBAAiB,oBAAgB,wBAAK,MAAM,SAAS,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAoBtD,mBAAmB,wBAAoB,wBAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAoBjD,qBAAqB,wBAAoB,wBAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQnD,kBAAkB,qBAAiB,wBAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAS7C,oBAAoB,uBAAmB,wBAAK,MAAM,SAAS,CAAC;AAAA,EAC9D;AACF;","names":["import_node_path","import_promises","import_node_path","matter","match","fs","import_gray_matter","import_promises","matter","fs","file","fs","import_promises","import_node_path","fs","import_promises","import_node_path","fs","import_promises","import_node_path","fs","import_promises","import_node_path","fs"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/events.ts","../src/internal/utils.ts","../src/internal/resources.ts","../src/commands.ts","../src/queries.ts","../src/services.ts","../src/domains.ts"],"sourcesContent":["import { join } from 'node:path';\nimport {\n rmEvent,\n rmEventById,\n writeEvent,\n writeEventToService,\n versionEvent,\n getEvent,\n addFileToEvent,\n addSchemaToEvent,\n eventHasVersion,\n} from './events';\nimport {\n rmCommand,\n rmCommandById,\n writeCommand,\n writeCommandToService,\n versionCommand,\n getCommand,\n addFileToCommand,\n addSchemaToCommand,\n commandHasVersion,\n} from './commands';\nimport {\n rmQuery,\n rmQueryById,\n writeQuery,\n writeQueryToService,\n versionQuery,\n getQuery,\n addFileToQuery,\n addSchemaToQuery,\n queryHasVersion,\n} from './queries';\nimport {\n writeService,\n writeServiceToDomain,\n getService,\n versionService,\n rmService,\n rmServiceById,\n addFileToService,\n addMessageToService,\n serviceHasVersion,\n getSpecificationFilesForService,\n writeVersionedService,\n} from './services';\nimport {\n writeDomain,\n getDomain,\n versionDomain,\n rmDomain,\n rmDomainById,\n addFileToDomain,\n domainHasVersion,\n addServiceToDomain,\n} from './domains';\n\n/**\n * Init the SDK for EventCatalog\n *\n * @param path - The path to the EventCatalog directory\n *\n */\nexport default (path: string) => {\n return {\n /**\n * Returns an events from EventCatalog\n * @param id - The id of the event to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Event|Undefined\n */\n getEvent: getEvent(join(path)),\n /**\n * Adds an event to EventCatalog\n *\n * @param event - The event to write\n * @param options - Optional options to write the event\n *\n */\n writeEvent: writeEvent(join(path, 'events')),\n /**\n * Adds an event to a service in EventCatalog\n *\n * @param event - The event to write to the service\n * @param service - The service and it's id to write to the event to\n * @param options - Optional options to write the event\n *\n */\n writeEventToService: writeEventToService(join(path, 'services')),\n /**\n * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`\n *\n */\n rmEvent: rmEvent(join(path, 'events')),\n /**\n * Remove an event by an Event id\n *\n * @param id - The id of the event you want to remove\n *\n */\n rmEventById: rmEventById(join(path)),\n /**\n * Moves a given event id to the version directory\n * @param directory\n */\n versionEvent: versionEvent(join(path)),\n /**\n * Adds a file to the given event\n * @param id - The id of the event to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the event to add the file to\n * @returns\n */\n addFileToEvent: addFileToEvent(join(path)),\n /**\n * Adds a schema to the given event\n * @param id - The id of the event to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the event to add the schema to\n * @returns\n */\n addSchemaToEvent: addSchemaToEvent(join(path)),\n /**\n * Check to see if an event version exists\n * @param id - The id of the event\n * @param version - The version of the event (supports semver)\n * @returns\n */\n eventHasVersion: eventHasVersion(join(path)),\n\n /**\n * ================================\n * Commands\n * ================================\n */\n\n /**\n * Returns a command from EventCatalog\n * @param id - The id of the command to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Command|Undefined\n */\n getCommand: getCommand(join(path)),\n /**\n * Adds an command to EventCatalog\n *\n * @param command - The command to write\n * @param options - Optional options to write the command\n *\n */\n writeCommand: writeCommand(join(path, 'commands')),\n\n /**\n * Adds a command to a service in EventCatalog\n *\n * @param command - The command to write to the service\n * @param service - The service and it's id to write to the command to\n * @param options - Optional options to write the command\n *\n */\n writeCommandToService: writeCommandToService(join(path, 'services')),\n\n /**\n * Remove an command to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your command, e.g. `/Inventory/InventoryAdjusted`\n *\n */\n rmCommand: rmCommand(join(path, 'commands')),\n /**\n * Remove an command by an Event id\n *\n * @param id - The id of the command you want to remove\n *\n */\n rmCommandById: rmCommandById(join(path)),\n /**\n * Moves a given command id to the version directory\n * @param directory\n */\n versionCommand: versionCommand(join(path)),\n /**\n * Adds a file to the given command\n * @param id - The id of the command to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the command to add the file to\n * @returns\n */\n addFileToCommand: addFileToCommand(join(path)),\n /**\n * Adds a schema to the given command\n * @param id - The id of the command to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the command to add the schema to\n * @returns\n */\n addSchemaToCommand: addSchemaToCommand(join(path)),\n\n /**\n * Check to see if a command version exists\n * @param id - The id of the command\n * @param version - The version of the command (supports semver)\n * @returns\n */\n commandHasVersion: commandHasVersion(join(path)),\n\n /**\n * ================================\n * Queries\n * ================================\n */\n\n /**\n * Returns a query from EventCatalog\n * @param id - The id of the query to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Query|Undefined\n */\n getQuery: getQuery(join(path)),\n /**\n * Adds a query to EventCatalog\n *\n * @param query - The query to write\n * @param options - Optional options to write the event\n *\n */\n writeQuery: writeQuery(join(path, 'queries')),\n /**\n * Adds a query to a service in EventCatalog\n *\n * @param query - The query to write to the service\n * @param service - The service and it's id to write to the query to\n * @param options - Optional options to write the query\n *\n */\n writeQueryToService: writeQueryToService(join(path, 'services')),\n /**\n * Remove an query to EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your query, e.g. `/Orders/GetOrder`\n *\n */\n rmQuery: rmQuery(join(path, 'queries')),\n /**\n * Remove a query by a Query id\n *\n * @param id - The id of the query you want to remove\n *\n */\n rmQueryById: rmQueryById(join(path)),\n /**\n * Moves a given query id to the version directory\n * @param directory\n */\n versionQuery: versionQuery(join(path)),\n /**\n * Adds a file to the given query\n * @param id - The id of the query to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the query to add the file to\n * @returns\n */\n addFileToQuery: addFileToQuery(join(path)),\n /**\n * Adds a schema to the given query\n * @param id - The id of the query to add the schema to\n * @param schema - Schema contents to add including the content and the file name\n * @param version - Optional version of the query to add the schema to\n * @returns\n */\n addSchemaToQuery: addSchemaToQuery(join(path)),\n /**\n * Check to see if an query version exists\n * @param id - The id of the query\n * @param version - The version of the query (supports semver)\n * @returns\n */\n queryHasVersion: queryHasVersion(join(path)),\n\n /**\n * ================================\n * SERVICES\n * ================================\n */\n\n /**\n * Adds a service to EventCatalog\n *\n * @param service - The service to write\n * @param options - Optional options to write the event\n *\n */\n writeService: writeService(join(path, 'services')),\n\n /**\n * Adds a versioned service to EventCatalog\n *\n * @param service - The service to write\n *\n */\n writeVersionedService: writeVersionedService(join(path, 'services')),\n\n /**\n * Adds a service to a domain in EventCatalog\n *\n * @param service - The service to write\n * @param domain - The domain to add the service to\n * @param options - Optional options to write the event\n *\n */\n writeServiceToDomain: writeServiceToDomain(join(path, 'domains')),\n /**\n * Returns a service from EventCatalog\n * @param id - The id of the service to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Service|Undefined\n */\n getService: getService(join(path)),\n /**\n * Moves a given service id to the version directory\n * @param directory\n */\n versionService: versionService(join(path)),\n /**\n * Remove a service from EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your service, e.g. `/InventoryService`\n *\n */\n rmService: rmService(join(path, 'services')),\n /**\n * Remove an service by an service id\n *\n * @param id - The id of the service you want to remove\n *\n */\n rmServiceById: rmServiceById(join(path)),\n /**\n * Adds a file to the given service\n * @param id - The id of the service to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the service to add the file to\n * @returns\n */\n addFileToService: addFileToService(join(path)),\n\n /**\n * Returns the specifications for a given service\n * @param id - The id of the service to retrieve the specifications for\n * @param version - Optional version of the service\n * @returns\n */\n getSpecificationFilesForService: getSpecificationFilesForService(join(path)),\n\n /**\n * Check to see if a service version exists\n * @param id - The id of the service\n * @param version - The version of the service (supports semver)\n * @returns\n */\n serviceHasVersion: serviceHasVersion(join(path)),\n\n /**\n * ================================\n * Domains\n * ================================\n */\n\n /**\n * Adds a domain to EventCatalog\n *\n * @param domain - The domain to write\n * @param options - Optional options to write the event\n *\n */\n writeDomain: writeDomain(join(path, 'domains')),\n\n /**\n * Returns a domain from EventCatalog\n * @param id - The id of the domain to retrieve\n * @param version - Optional id of the version to get (supports semver)\n * @returns Domain|Undefined\n */\n getDomain: getDomain(join(path, 'domains')),\n /**\n * Moves a given domain id to the version directory\n * @param directory\n */\n versionDomain: versionDomain(join(path, 'domains')),\n /**\n * Remove a domain from EventCatalog (modeled on the standard POSIX rm utility)\n *\n * @param path - The path to your domain, e.g. `/Payment`\n *\n */\n rmDomain: rmDomain(join(path, 'domains')),\n /**\n * Remove an service by an domain id\n *\n * @param id - The id of the domain you want to remove\n *\n */\n rmDomainById: rmDomainById(join(path, 'domains')),\n /**\n * Adds a file to the given domain\n * @param id - The id of the domain to add the file to\n * @param file - File contents to add including the content and the file name\n * @param version - Optional version of the domain to add the file to\n * @returns\n */\n addFileToDomain: addFileToDomain(join(path, 'domains')),\n /**\n * Add an event to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addEventToService } = utils('/path/to/eventcatalog');\n *\n * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send\n * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });\n *\n * // adds a new event (OrderComplete) that the InventoryService will receive\n * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });\n *\n * ```\n */\n addEventToService: addMessageToService(join(path)),\n /**\n * Add a command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addCommandToService } = utils('/path/to/eventcatalog');\n *\n * // adds a new command (UpdateInventoryCommand) that the InventoryService will send\n * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });\n *\n * // adds a new command (VerifyInventory) that the InventoryService will receive\n * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '2.0.0' });\n *\n * ```\n */\n addCommandToService: addMessageToService(join(path)),\n\n /**\n * Check to see if a domain version exists\n * @param id - The id of the domain\n * @param version - The version of the domain (supports semver)\n * @returns\n */\n domainHasVersion: domainHasVersion(join(path)),\n\n /**\n * Adds a given service to a domain\n * @param id - The id of the domain\n * @param service - The id and version of the service to add\n * @param version - (Optional) The version of the domain to add the service to\n * @returns\n */\n addServiceToDomain: addServiceToDomain(join(path, 'domains')),\n };\n};\n","import fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { findFileById } from './internal/utils';\nimport type { Event } from './types';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\n\n/**\n * Returns an event from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the event\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getEvent } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const event = await getEvent('InventoryAdjusted');\n *\n * // Gets a version of the event\n * const event = await getEvent('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const getEvent =\n (directory: string) =>\n async (id: string, version?: string): Promise<Event> =>\n getResource(directory, id, version, { type: 'event' }) as Promise<Event>;\n\n/**\n * Write an event to EventCatalog.\n *\n * You can optionally overide the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeEvent } = utils('/path/to/eventcatalog');\n *\n * // Write an event to the catalog\n * // Event would be written to events/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write an event to the catalog but override the path\n * // Event would be written to events/Inventory/InventoryAdjusted\n * await writeEvent({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryAdjusted\"});\n * ```\n */\nexport const writeEvent =\n (directory: string) =>\n async (event: Event, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...event }, { ...options, type: 'event' });\n/**\n * Write an event to a service in EventCatalog.\n *\n * You can optionally override the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeEventToService } = utils('/path/to/eventcatalog');\n *\n * // Write an event to a given service in the catalog\n * // Event would be written to services/Inventory/events/InventoryAdjusted\n * await writeEventToService({\n * id: 'InventoryAdjusted',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { id: 'Inventory' });\n * ```\n */\nexport const writeEventToService =\n (directory: string) =>\n async (event: Event, service: { id: string; version?: string }, options: { path: string } = { path: '' }) => {\n let pathForEvent =\n service.version && service.version !== 'latest'\n ? `/${service.id}/versioned/${service.version}/events`\n : `/${service.id}/events`;\n pathForEvent = join(pathForEvent, event.id);\n await writeResource(directory, { ...event }, { ...options, path: pathForEvent, type: 'event' });\n };\n\n/**\n * Delete an event at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEvent } = utils('/path/to/eventcatalog');\n *\n * // removes an event at the given path (events dir is appended to the given path)\n * // Removes the event at events/InventoryAdjusted\n * await rmEvent('/InventoryAdjusted');\n * ```\n */\nexport const rmEvent = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete an event by it's id.\n *\n * Optionally specify a version to delete a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmEventById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryAdjusted event\n * await rmEventById('InventoryAdjusted');\n *\n * // deletes a specific version of the InventoryAdjusted event\n * await rmEventById('InventoryAdjusted', '0.0.1');\n * ```\n */\nexport const rmEventById = (directory: string) => async (id: string, version?: string) => {\n await rmResourceById(directory, id, version, { type: 'event' });\n};\n\n/**\n * Version an event by it's id.\n *\n * Takes the latest event and moves it to a versioned directory.\n * All files with this event are also versioned (e.g /events/InventoryAdjusted/schema.json)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionEvent } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryAdjusted event to a versioned directory\n * // the version within that event is used as the version number.\n * await versionEvent('InventoryAdjusted');\n *\n * ```\n */\nexport const versionEvent = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Add a file to an event by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToEvent } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addFileToEvent('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToEvent =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Add a schema to an event by it's id.\n *\n * Optionally specify a version to add a schema to a specific version of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToEvent } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the InventoryAdjusted event\n * await addSchemaToEvent('InventoryAdjusted', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToEvent =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n\n/**\n * Check to see if the catalog has a version for the given event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { eventHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await eventHasVersion('InventoryAdjusted', '0.0.1');\n * await eventHasVersion('InventoryAdjusted', 'latest');\n * await eventHasVersion('InventoryAdjusted', '0.0.x');*\n *\n * ```\n */\nexport const eventHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import { glob } from 'glob';\nimport fs from 'node:fs/promises';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join } 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`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n 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) => {\n try {\n const files = await glob(pattern, { ignore: 'node_modules/**' });\n return files;\n } catch (error) {\n throw new Error(`Error finding files: ${error}`);\n }\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${id}['\"]?\\\\s*$`, 'm');\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = await Promise.all(\n files.map(async (file) => {\n const content = await fs.readFile(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n })\n );\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n await fs.mkdir(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n await fs.rm(tmpDirectory, { recursive: true });\n};\n\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","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 { Message, Service } from '../types';\n\ntype Resource = Service | Message;\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`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No event 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 await fs.mkdir(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 await fs.rm(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 } = { path: '', type: '' }\n) => {\n // Get the path\n const path = options.path || `/${resource.id}`;\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists) {\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 const document = matter.stringify(markdown.trim(), frontmatter);\n await fs.mkdir(join(catalogDir, path), { recursive: true });\n await fs.writeFile(join(catalogDir, path, 'index.md'), document);\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 rmResourceById = async (catalogDir: string, id: string, version?: string, options?: { type: string }) => {\n const files = await getFiles(`${catalogDir}/**/index.md`);\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 await Promise.all(matchedFiles.map((file) => fs.rm(file)));\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 await fs.writeFile(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 fs.readFile(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 fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { Command } from './types';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\nimport { findFileById } from './internal/utils';\nimport { addMessageToService } from './services';\n\n/**\n * Returns a command from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the command\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getCommand } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the command\n * const command = await getCommand('UpdateInventory');\n *\n * // Gets a version of the command\n * const command = await getCommand('UpdateInventory', '0.0.1');\n * ```\n */\nexport const getCommand =\n (directory: string) =>\n async (id: string, version?: string): Promise<Command> =>\n getResource(directory, id, version, { type: 'command' }) as Promise<Command>;\n\n/**\n * Write a command to EventCatalog.\n *\n * You can optionally override the path of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeCommand } = utils('/path/to/eventcatalog');\n *\n * // Write a command to the catalog\n * // Command would be written to commands/UpdateInventory\n * await writeCommand({\n * id: 'UpdateInventory',\n * name: 'Update Inventory',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write a command to the catalog but override the path\n * // Command would be written to commands/Inventory/UpdateInventory\n * await writeCommand({\n * id: 'UpdateInventory',\n * name: 'Update Inventory',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/UpdateInventory\"});\n * ```\n */\nexport const writeCommand =\n (directory: string) =>\n async (command: Command, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...command }, { ...options, type: 'command' });\n\n/**\n * Write an command to a service in EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeCommandToService } = utils('/path/to/eventcatalog');\n *\n * // Write an event to a given service in the catalog\n * // Event would be written to services/Inventory/commands/UpdateInventory\n * await writeCommandToService({\n * id: 'UpdateInventory',\n * name: 'Update Inventory',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { id: 'Inventory' });\n * ```\n */\nexport const writeCommandToService =\n (directory: string) =>\n async (command: Command, service: { id: string; version?: string }, options: { path: string } = { path: '' }) => {\n let pathForEvent =\n service.version && service.version !== 'latest'\n ? `/${service.id}/versioned/${service.version}/commands`\n : `/${service.id}/commands`;\n pathForEvent = join(pathForEvent, command.id);\n\n await writeResource(directory, { ...command }, { ...options, path: pathForEvent, type: 'command' });\n };\n\n/**\n * Delete a command at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmCommand } = utils('/path/to/eventcatalog');\n *\n * // removes a command at the given path (commands dir is appended to the given path)\n * // Removes the command at commands/UpdateInventory\n * await rmCommand('/UpdateInventory');\n * ```\n */\nexport const rmCommand = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a command by it's id.\n *\n * Optionally specify a version to delete a specific version of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmCommandById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest UpdateInventory command\n * await rmCommandById('UpdateInventory');\n *\n * // deletes a specific version of the UpdateInventory command\n * await rmCommandById('UpdateInventory', '0.0.1');\n * ```\n */\nexport const rmCommandById = (directory: string) => async (id: string, version?: string) =>\n rmResourceById(directory, id, version, { type: 'command' });\n\n/**\n * Version a command by it's id.\n *\n * Takes the latest command and moves it to a versioned directory.\n * All files with this command are also versioned (e.g /commands/UpdateInventory/schema.json)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionCommand } = utils('/path/to/eventcatalog');\n *\n * // moves the latest UpdateInventory command to a versioned directory\n * // the version within that command is used as the version number.\n * await versionCommand('UpdateInventory');\n *\n * ```\n */\nexport const versionCommand = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Add a file to a command by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToCommand } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest UpdateInventory command\n * await addFileToCommand('UpdateInventory', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the UpdateInventory command\n * await addFileToCommand('UpdateInventory', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToCommand =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Add a schema to a command by it's id.\n *\n * Optionally specify a version to add a schema to a specific version of the command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToCommand } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest UpdateInventory command\n * await addSchemaToCommand('UpdateInventory', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the UpdateInventory command\n * await addSchemaToCommand('UpdateInventory', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToCommand =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToCommand(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n\n/**\n * Check to see if the catalog has a version for the given command.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { commandHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await commandHasVersion('InventoryAdjusted', '0.0.1');\n * await commandHasVersion('InventoryAdjusted', 'latest');\n * await commandHasVersion('InventoryAdjusted', '0.0.x');*\n *\n * ```\n */\nexport const commandHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { findFileById } from './internal/utils';\nimport type { Query } from './types';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\n\n/**\n * Returns a query from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the query\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getQuery } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const event = await getQuery('GetOrder');\n *\n * // Gets a version of the event\n * const event = await getQuery('GetOrder', '0.0.1');\n * ```\n */\nexport const getQuery =\n (directory: string) =>\n async (id: string, version?: string): Promise<Query> =>\n getResource(directory, id, version, { type: 'query' }) as Promise<Query>;\n\n/**\n * Write a query to EventCatalog.\n *\n * You can optionally override the path of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeQuery } = utils('/path/to/eventcatalog');\n *\n * // Write an event to the catalog\n * // Event would be written to queries/GetOrder\n * await writeQuery({\n * id: 'GetOrder',\n * name: 'Get Order',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * });\n *\n * // Write an event to the catalog but override the path\n * // Event would be written to queries/Inventory/GetOrder\n * await writeQuery({\n * id: 'GetOrder',\n * name: 'Get Order',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Orders/GetOrder\"});\n * ```\n */\nexport const writeQuery =\n (directory: string) =>\n async (query: Query, options: { path: string } = { path: '' }) =>\n writeResource(directory, { ...query }, { ...options, type: 'query' });\n/**\n * Write a query to a service in EventCatalog.\n *\n * You can optionally override the path of the event.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeQueryToService } = utils('/path/to/eventcatalog');\n *\n * // Write an event to a given service in the catalog\n * // Event would be written to services/Orders/queries/GetOrder\n * await writeQueryToService({\n * id: 'GetOrder',\n * name: 'Get Order',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { id: 'Orders' });\n * ```\n */\nexport const writeQueryToService =\n (directory: string) =>\n async (query: Query, service: { id: string; version?: string }, options: { path: string } = { path: '' }) => {\n let pathForQuery =\n service.version && service.version !== 'latest'\n ? `/${service.id}/versioned/${service.version}/queries`\n : `/${service.id}/queries`;\n pathForQuery = join(pathForQuery, query.id);\n await writeResource(directory, { ...query }, { ...options, path: pathForQuery, type: 'query' });\n };\n\n/**\n * Delete a query at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmQuery } = utils('/path/to/eventcatalog');\n *\n * // removes an query at the given path (queries dir is appended to the given path)\n * // Removes the query at queries/GetOrders\n * await rmQuery('/GetOrders');\n * ```\n */\nexport const rmQuery = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a query by it's id.\n *\n * Optionally specify a version to delete a specific version of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmQueryById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryAdjusted query\n * await rmQueryById('GetOrder');\n *\n * // deletes a specific version of the GetOrder query\n * await rmQueryById('GetOrder', '0.0.1');\n * ```\n */\nexport const rmQueryById = (directory: string) => async (id: string, version?: string) => {\n await rmResourceById(directory, id, version, { type: 'query' });\n};\n\n/**\n * Version a query by it's id.\n *\n * Takes the latest query and moves it to a versioned directory.\n * All files with this query are also versioned (e.g /queries/GetOrder/schema.json)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionQuery } = utils('/path/to/eventcatalog');\n *\n * // moves the latest GetOrder query to a versioned directory\n * // the version within that query is used as the version number.\n * await versionQuery('GetOrder');\n *\n * ```\n */\nexport const versionQuery = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Add a file to a query by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToQuery } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest GetOrder query\n * await addFileToQuery('GetOrder', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the GetOrder query\n * await addFileToQuery('GetOrder', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\nexport const addFileToQuery =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Add a schema to a query by it's id.\n *\n * Optionally specify a version to add a schema to a specific version of the query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addSchemaToQuery } = utils('/path/to/eventcatalog');\n *\n * // JSON schema example\n * const schema = {\n * \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n * \"type\": \"object\",\n * \"properties\": {\n * \"name\": {\n * \"type\": \"string\"\n * },\n * \"age\": {\n * \"type\": \"number\"\n * }\n * },\n * \"required\": [\"name\", \"age\"]\n * };\n *\n * // adds a schema to the latest GetOrder query\n * await addSchemaToQuery('GetOrder', { schema, fileName: 'schema.json' });\n *\n * // adds a file to a specific version of the GetOrder query\n * await addSchemaToQuery('GetOrder', { schema, fileName: 'schema.json' }, '0.0.1');\n *\n * ```\n */\nexport const addSchemaToQuery =\n (directory: string) => async (id: string, schema: { schema: string; fileName: string }, version?: string) => {\n await addFileToQuery(directory)(id, { content: schema.schema, fileName: schema.fileName }, version);\n };\n\n/**\n * Check to see if the catalog has a version for the given query.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { queryHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await queryHasVersion('GetOrder', '0.0.1');\n * await queryHasVersion('GetOrder', 'latest');\n * await queryHasVersion('GetOrder', '0.0.x');*\n *\n * ```\n */\nexport const queryHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import type { Service, Specifications } from './types';\nimport fs from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport {\n addFileToResource,\n getFileFromResource,\n getResource,\n rmResourceById,\n versionResource,\n writeResource,\n getVersionedDirectory,\n} from './internal/resources';\nimport { findFileById, uniqueVersions } from './internal/utils';\n\n/**\n * Returns a service from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the service\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getService } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const service = await getService('InventoryService');\n *\n * // Gets a version of the event\n * const service = await getService('InventoryService', '0.0.1');\n * ```\n */\nexport const getService =\n (directory: string) =>\n async (id: string, version?: string): Promise<Service> =>\n getResource(directory, id, version, { type: 'service' }) as Promise<Service>;\n/**\n * Write a Service to EventCatalog.\n *\n * You can optionally overide the path of the Service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeService } = utils('/path/to/eventcatalog');\n *\n * // Write a Service\n * // Service would be written to services/InventoryService\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * });\n *\n * // Write a service to the catalog but override the path\n * // Service would be written to services/Inventory/InventoryService\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryService\"});\n * ```\n */\nexport const writeService =\n (directory: string) =>\n async (service: Service, options: { path: string } = { path: '' }) => {\n const resource: Service = { ...service };\n\n if (Array.isArray(service.sends)) {\n resource.sends = uniqueVersions(service.sends);\n }\n\n if (Array.isArray(service.receives)) {\n resource.receives = uniqueVersions(service.receives);\n }\n\n return writeResource(directory, resource, { ...options, type: 'service' });\n };\n\n/**\n * Write a versioned service to EventCatalog.\n *\n * You can optionally overide the path of the Service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeVersionedService } = utils('/path/to/eventcatalog');\n *\n * // Write a service\n * // Service would be written to services/InventoryService/versioned/0.0.1\n * await writeVersionedService({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * });\n *\n * ```\n */\nexport const writeVersionedService = (directory: string) => async (service: Service) => {\n const resource: Service = { ...service };\n const path = getVersionedDirectory(service.id, service.version);\n\n return await writeService(directory)(resource, { path: path });\n};\n\n/**\n * Write a service to a domain in EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a service to a domain\n * // Service would be written to domains/Shopping/services/InventoryService\n * await writeServiceToDomain({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * }, { id: 'Shopping' });\n * ```\n */\nexport const writeServiceToDomain =\n (directory: string) =>\n async (\n service: Service,\n domain: { id: string; version?: string; direction?: string },\n options: { path: string } = { path: '' }\n ) => {\n let pathForService =\n domain.version && domain.version !== 'latest'\n ? `/${domain.id}/versioned/${domain.version}/services`\n : `/${domain.id}/services`;\n pathForService = join(pathForService, service.id);\n\n //\n await writeResource(directory, { ...service }, { ...options, path: pathForService, type: 'service' });\n };\n\n/**\n * Version a service by it's id.\n *\n * Takes the latest service and moves it to a versioned directory.\n * All files with this service are also versioned. (e.g /services/InventoryService/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionService } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryService service to a versioned directory\n * // the version within that service is used as the version number.\n * await versionService('InventoryService');\n *\n * ```\n */\nexport const versionService = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a service at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmService } = utils('/path/to/eventcatalog');\n *\n * // Removes the service at services/InventoryService\n * await rmService('/InventoryService');\n * ```\n */\nexport const rmService = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a service by it's id.\n *\n * Optionally specify a version to delete a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmServiceById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryService event\n * await rmServiceById('InventoryService');\n *\n * // deletes a specific version of the InventoryService event\n * await rmServiceById('InventoryService', '0.0.1');\n * ```\n */\nexport const rmServiceById = (directory: string) => async (id: string, version?: string) =>\n rmResourceById(directory, id, version, { type: 'service' });\n\n/**\n * Add a file to a service by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToService } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryService event\n * await addFileToService('InventoryService', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryService event\n * await addFileToService('InventoryService', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToService =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Returns specification files for a service\n *\n * Optionally specify a version to of the service\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getSpecificationFilesForService } = utils('/path/to/eventcatalog');\n *\n * // returns a list of specification files for a service\n * await getSpecificationFilesForService('InventoryService', '0.0.1');\n *\n * ```\n */\n\nexport const getSpecificationFilesForService = (directory: string) => async (id: string, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const filePathToService = await findFileById(directory, id, version);\n\n if (!filePathToService) throw new Error('Cannot find directory of service');\n\n let specs = [] as any;\n if (service.specifications) {\n const serviceSpecifications = service.specifications;\n const specificationFiles = Object.keys(serviceSpecifications);\n\n const getSpecs = specificationFiles.map(async (specFile) => {\n const fileName = serviceSpecifications[specFile as keyof Specifications];\n\n if (!fileName) {\n throw new Error(`Specification file name for ${specFile} is undefined`);\n }\n const rawFile = await getFileFromResource(directory, id, { fileName }, version);\n\n return { key: specFile, content: rawFile, fileName: fileName, path: join(dirname(filePathToService), fileName) };\n });\n\n specs = await Promise.all(getSpecs);\n }\n return specs;\n};\n\n/**\n * Add an event/command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds an event to the service or command to the service\n * const { addEventToService, addCommandToService } = utils('/path/to/eventcatalog');\n *\n * // Adds a new event (InventoryUpdatedEvent) that the InventoryService will send\n * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });\n * * // Adds a new event (OrderComplete) that the InventoryService will receive\n * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });\n *\n * // Adds a new command (UpdateInventoryCommand) that the InventoryService will send\n * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });\n * // Adds a new command (VerifyInventory) that the InventoryService will receive\n * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });\n *\n * ```\n */\n\nexport const addMessageToService =\n (directory: string) => async (id: string, direction: string, event: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n\n if (direction === 'sends') {\n if (service.sends === undefined) {\n service.sends = [];\n }\n // We first check if the event is already in the list\n for (let i = 0; i < service.sends.length; i++) {\n if (service.sends[i].id === event.id && service.sends[i].version === event.version) {\n return;\n }\n }\n service.sends.push({ id: event.id, version: event.version });\n } else if (direction === 'receives') {\n if (service.receives === undefined) {\n service.receives = [];\n }\n // We first check if the event is already in the list\n for (let i = 0; i < service.receives.length; i++) {\n if (service.receives[i].id === event.id && service.receives[i].version === event.version) {\n return;\n }\n }\n service.receives.push({ id: event.id, version: event.version });\n } else {\n throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);\n }\n\n await rmServiceById(directory)(id, version);\n await writeService(directory)(service);\n };\n\n/**\n * Check to see if the catalog has a version for the given service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { serviceHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await serviceHasVersion('InventoryService', '0.0.1');\n * await serviceHasVersion('InventoryService', 'latest');\n * await serviceHasVersion('InventoryService', '0.0.x');*\n *\n * ```\n */\nexport const serviceHasVersion = (directory: string) => async (id: string, version: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n","import type { Domain } from './types';\nimport fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { addFileToResource, getResource, rmResourceById, versionResource, writeResource } from './internal/resources';\nimport { findFileById, uniqueVersions } from './internal/utils';\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 * 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 * // Event 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 * // Event 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 */\nexport const writeDomain =\n (directory: string) =>\n async (domain: Domain, options: { path: string } = { path: '' }) => {\n const resource: Domain = { ...domain };\n\n if (Array.isArray(domain.services)) {\n resource.services = uniqueVersions(domain.services);\n }\n\n return 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) =>\n rmResourceById(directory, id, version, { type: 'domain' });\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 * 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 an event/command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\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\n if (domain.services === undefined) {\n domain.services = [];\n }\n\n const eventExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);\n\n if (eventExistsInList) {\n return;\n }\n\n // Add service to the list\n domain.services.push(service);\n\n await rmDomainById(directory)(id, version);\n await writeDomain(directory)(domain);\n };\n"],"mappings":";;;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAoBjD,qBAAqB,wBAAoB,wBAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQnD,kBAAkB,qBAAiB,wBAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAS7C,oBAAoB,uBAAmB,wBAAK,MAAM,SAAS,CAAC;AAAA,EAC9D;AACF;","names":["import_node_path","import_promises","import_node_path","matter","match","fs","import_gray_matter","import_promises","matter","fs","file","fs","import_promises","import_node_path","fs","import_promises","import_node_path","fs","import_promises","import_node_path","fs","import_promises","import_node_path","fs"]}
package/dist/index.mjs CHANGED
@@ -79,7 +79,7 @@ var copyDir = async (catalogDir, source, target, filter) => {
79
79
  });
80
80
  await fs.rm(tmpDirectory, { recursive: true });
81
81
  };
82
- var uniqueMessages = (messages) => {
82
+ var uniqueVersions = (messages) => {
83
83
  const uniqueSet = /* @__PURE__ */ new Set();
84
84
  return messages.filter((message) => {
85
85
  const key = `${message.id}-${message.version}`;
@@ -123,7 +123,7 @@ var writeResource = async (catalogDir, resource, options = { path: "", type: ""
123
123
  const path = options.path || `/${resource.id}`;
124
124
  const exists = await versionExists(catalogDir, resource.id, resource.version);
125
125
  if (exists) {
126
- throw new Error(`Failed to write ${options.type} as the version ${resource.version} already exists`);
126
+ throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
127
127
  }
128
128
  const { markdown, ...frontmatter } = resource;
129
129
  const document = matter2.stringify(markdown.trim(), frontmatter);
@@ -244,10 +244,10 @@ var getService = (directory) => async (id, version) => getResource(directory, id
244
244
  var writeService = (directory) => async (service, options = { path: "" }) => {
245
245
  const resource = { ...service };
246
246
  if (Array.isArray(service.sends)) {
247
- resource.sends = uniqueMessages(service.sends);
247
+ resource.sends = uniqueVersions(service.sends);
248
248
  }
249
249
  if (Array.isArray(service.receives)) {
250
- resource.receives = uniqueMessages(service.receives);
250
+ resource.receives = uniqueVersions(service.receives);
251
251
  }
252
252
  return writeResource(directory, resource, { ...options, type: "service" });
253
253
  };
@@ -324,7 +324,13 @@ var serviceHasVersion = (directory) => async (id, version) => {
324
324
  import fs7 from "node:fs/promises";
325
325
  import { join as join7 } from "node:path";
326
326
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
327
- var writeDomain = (directory) => async (domain, options = { path: "" }) => writeResource(directory, { ...domain }, { ...options, type: "domain" });
327
+ var writeDomain = (directory) => async (domain, options = { path: "" }) => {
328
+ const resource = { ...domain };
329
+ if (Array.isArray(domain.services)) {
330
+ resource.services = uniqueVersions(domain.services);
331
+ }
332
+ return writeResource(directory, resource, { ...options, type: "domain" });
333
+ };
328
334
  var versionDomain = (directory) => async (id) => versionResource(directory, id);
329
335
  var rmDomain = (directory) => async (path) => {
330
336
  await fs7.rm(join7(directory, path), { recursive: true });