@eventcatalog/sdk 2.11.0 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +86 -1
  2. package/dist/cli/index.d.mts +1 -0
  3. package/dist/cli/index.d.ts +1 -0
  4. package/dist/{eventcatalog.js → cli/index.js} +588 -378
  5. package/dist/cli/index.js.map +1 -0
  6. package/dist/{eventcatalog.mjs → cli/index.mjs} +666 -436
  7. package/dist/cli/index.mjs.map +1 -0
  8. package/dist/cli-docs.d.mts +43 -0
  9. package/dist/cli-docs.d.ts +43 -0
  10. package/dist/cli-docs.js +1614 -0
  11. package/dist/cli-docs.js.map +1 -0
  12. package/dist/cli-docs.mjs +1586 -0
  13. package/dist/cli-docs.mjs.map +1 -0
  14. package/dist/index.d.mts +443 -25
  15. package/dist/index.d.ts +443 -25
  16. package/dist/index.js +204 -121
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +204 -121
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +13 -4
  21. package/dist/channels.d.mts +0 -214
  22. package/dist/channels.d.ts +0 -214
  23. package/dist/channels.js +0 -432
  24. package/dist/channels.js.map +0 -1
  25. package/dist/channels.mjs +0 -384
  26. package/dist/channels.mjs.map +0 -1
  27. package/dist/commands.d.mts +0 -274
  28. package/dist/commands.d.ts +0 -274
  29. package/dist/commands.js +0 -394
  30. package/dist/commands.js.map +0 -1
  31. package/dist/commands.mjs +0 -350
  32. package/dist/commands.mjs.map +0 -1
  33. package/dist/containers.d.mts +0 -179
  34. package/dist/containers.d.ts +0 -179
  35. package/dist/containers.js +0 -388
  36. package/dist/containers.js.map +0 -1
  37. package/dist/containers.mjs +0 -345
  38. package/dist/containers.mjs.map +0 -1
  39. package/dist/custom-docs.d.mts +0 -89
  40. package/dist/custom-docs.d.ts +0 -89
  41. package/dist/custom-docs.js +0 -164
  42. package/dist/custom-docs.js.map +0 -1
  43. package/dist/custom-docs.mjs +0 -122
  44. package/dist/custom-docs.mjs.map +0 -1
  45. package/dist/data-products.d.mts +0 -225
  46. package/dist/data-products.d.ts +0 -225
  47. package/dist/data-products.js +0 -375
  48. package/dist/data-products.js.map +0 -1
  49. package/dist/data-products.mjs +0 -332
  50. package/dist/data-products.mjs.map +0 -1
  51. package/dist/data-stores.d.mts +0 -179
  52. package/dist/data-stores.d.ts +0 -179
  53. package/dist/data-stores.js +0 -401
  54. package/dist/data-stores.js.map +0 -1
  55. package/dist/data-stores.mjs +0 -356
  56. package/dist/data-stores.mjs.map +0 -1
  57. package/dist/domains.d.mts +0 -347
  58. package/dist/domains.d.ts +0 -347
  59. package/dist/domains.js +0 -547
  60. package/dist/domains.js.map +0 -1
  61. package/dist/domains.mjs +0 -498
  62. package/dist/domains.mjs.map +0 -1
  63. package/dist/entities.d.mts +0 -174
  64. package/dist/entities.d.ts +0 -174
  65. package/dist/entities.js +0 -348
  66. package/dist/entities.js.map +0 -1
  67. package/dist/entities.mjs +0 -307
  68. package/dist/entities.mjs.map +0 -1
  69. package/dist/eventcatalog.d.mts +0 -21
  70. package/dist/eventcatalog.d.ts +0 -21
  71. package/dist/eventcatalog.js.map +0 -1
  72. package/dist/eventcatalog.mjs.map +0 -1
  73. package/dist/events.d.mts +0 -276
  74. package/dist/events.d.ts +0 -276
  75. package/dist/events.js +0 -393
  76. package/dist/events.js.map +0 -1
  77. package/dist/events.mjs +0 -349
  78. package/dist/events.mjs.map +0 -1
  79. package/dist/messages.d.mts +0 -65
  80. package/dist/messages.d.ts +0 -65
  81. package/dist/messages.js +0 -312
  82. package/dist/messages.js.map +0 -1
  83. package/dist/messages.mjs +0 -269
  84. package/dist/messages.mjs.map +0 -1
  85. package/dist/queries.d.mts +0 -276
  86. package/dist/queries.d.ts +0 -276
  87. package/dist/queries.js +0 -394
  88. package/dist/queries.js.map +0 -1
  89. package/dist/queries.mjs +0 -350
  90. package/dist/queries.mjs.map +0 -1
  91. package/dist/services.d.mts +0 -384
  92. package/dist/services.d.ts +0 -384
  93. package/dist/services.js +0 -577
  94. package/dist/services.js.map +0 -1
  95. package/dist/services.mjs +0 -526
  96. package/dist/services.mjs.map +0 -1
  97. package/dist/teams.d.mts +0 -90
  98. package/dist/teams.d.ts +0 -90
  99. package/dist/teams.js +0 -246
  100. package/dist/teams.js.map +0 -1
  101. package/dist/teams.mjs +0 -202
  102. package/dist/teams.mjs.map +0 -1
  103. package/dist/types.d.d.mts +0 -331
  104. package/dist/types.d.d.ts +0 -331
  105. package/dist/types.d.js +0 -19
  106. package/dist/types.d.js.map +0 -1
  107. package/dist/types.d.mjs +0 -1
  108. package/dist/types.d.mjs.map +0 -1
  109. package/dist/users.d.mts +0 -83
  110. package/dist/users.d.ts +0 -83
  111. package/dist/users.js +0 -127
  112. package/dist/users.js.map +0 -1
  113. package/dist/users.mjs +0 -88
  114. package/dist/users.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/services.ts","../src/internal/resources.ts","../src/internal/utils.ts"],"sourcesContent":["import type { Service, Specifications } from './types';\nimport fs from 'node:fs/promises';\nimport { join, dirname, extname, relative } from 'node:path';\nimport {\n addFileToResource,\n getFileFromResource,\n getResource,\n rmResourceById,\n versionResource,\n writeResource,\n getVersionedDirectory,\n getResources,\n getResourcePath,\n toResource,\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/**\n * Returns a service from EventCatalog by it's path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getServiceByPath } = utils('/path/to/eventcatalog');\n *\n * // Returns a service from the catalog by it's path\n * const service = await getServiceByPath('/services/InventoryService/index.mdx');\n * ```\n */\nexport const getServiceByPath = (directory: string) => async (path: string) => {\n const service = await getResource(directory, undefined, undefined, { type: 'service' }, path);\n return service as Service;\n};\n\n/**\n * Returns all services from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the services.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getServices } = utils('/path/to/eventcatalog');\n *\n * // Gets all services (and versions) from the catalog\n * const services = await getServices();\n *\n * // Gets all services (only latest version) from the catalog\n * const services = await getServices({ latestOnly: true });\n * ```\n */\nexport const getServices =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Service[]> =>\n getResources(directory, {\n type: 'services',\n ignore: ['**/events/**', '**/commands/**', '**/queries/**', '**/entities/**', '**/subdomains/**/entities/**'],\n ...options,\n }) as Promise<Service[]>;\n\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 * // Write a service to the catalog and override the existing content (if there is any)\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 * }, { override: true });\n *\n * // Write a service to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\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 * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeService =\n (directory: string) =>\n async (\n service: Service,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n override: false,\n format: 'mdx',\n }\n ) => {\n const resource: Service = { ...service };\n\n if (Array.isArray(service.sends)) {\n resource.sends = uniqueVersions(service.sends as { id: string; version: string }[]);\n }\n\n if (Array.isArray(service.receives)) {\n resource.receives = uniqueVersions(service.receives as { id: string; version: string }[]);\n }\n\n return await 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; format?: 'md' | 'mdx'; override?: boolean } = { path: '', format: 'mdx', override: false }\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, persistFiles?: boolean) => {\n await rmResourceById(directory, id, version, { type: 'service', persistFiles });\n};\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 let specificationFiles;\n\n if (Array.isArray(serviceSpecifications)) {\n specificationFiles = serviceSpecifications.map((spec) => ({ key: spec.type, path: spec.path }));\n } else {\n specificationFiles = Object.keys(serviceSpecifications).map((spec) => ({\n key: spec,\n path: serviceSpecifications[spec as keyof Specifications] as string,\n }));\n }\n\n const getSpecs = specificationFiles.map(async ({ key, path: fileName }) => {\n if (!fileName) {\n throw new Error(`Specification file name for ${fileName} is undefined`);\n }\n const rawFile = await getFileFromResource(directory, id, { fileName }, version);\n\n return { key, 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 const servicePath = await getResourcePath(directory, id, version);\n const extension = extname(servicePath?.fullPath || '');\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 const existingResource = await findFileById(directory, id, version);\n\n if (!existingResource) {\n throw new Error(`Cannot find service ${id} in the catalog`);\n }\n\n // Get where the service was located, make sure it goes back there.\n const path = existingResource.split(/[\\\\/]+services/)[0];\n const pathToResource = join(path, 'services');\n\n await rmServiceById(directory)(id, version);\n await writeService(pathToResource)(service, { format: extension === '.md' ? 'md' : 'mdx' });\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\n/**\n * Check to see if the path is a service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { isService } = utils('/path/to/eventcatalog');\n *\n * // returns true if the path is a service\n * await isService('/services/InventoryService/index.mdx');\n * ```\n */\nexport const isService = (directory: string) => async (path: string) => {\n const service = await getServiceByPath(directory)(path);\n // Get relative path from root directory\n const relativePath = relative(directory, path);\n\n // Split into path segments using regex to handle both / and \\\n const segments = relativePath.split(/[/\\\\]+/);\n\n // needs to workf or windows too\n return !!service && segments.includes('services');\n};\n\n/**\n * Takes a given raw file and converts it to a service.\n *\n * @param directory - The directory to convert the file to a service.\n * @returns The service.\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { toService } = utils('/path/to/eventcatalog');\n *\n * // Read the file from somewhere\n * const file = fs.readFileSync('/path/to/services/InventoryService/index.mdx', 'utf8');\n *\n * // Converts the raw file to a service\n * await toService(file);\n * ```\n */\nexport const toService = (directory: string) => async (file: string) => toResource(directory, file) as Promise<Service>;\n\n/**\n * Add an entity to a service by its id.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addEntityToService } = utils('/path/to/eventcatalog');\n *\n * // adds a new entity (User) to the InventoryService\n * await addEntityToService('InventoryService', { id: 'User', version: '1.0.0' });\n *\n * // adds a new entity (Product) to a specific version of the InventoryService\n * await addEntityToService('InventoryService', { id: 'Product', version: '1.0.0' }, '2.0.0');\n *\n * ```\n */\nexport const addEntityToService =\n (directory: string) => async (id: string, entity: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const servicePath = await getResourcePath(directory, id, version);\n const extension = extname(servicePath?.fullPath || '');\n\n if (service.entities === undefined) {\n service.entities = [];\n }\n\n // Check if the entity is already in the list\n for (let i = 0; i < service.entities.length; i++) {\n if (service.entities[i].id === entity.id && service.entities[i].version === entity.version) {\n return;\n }\n }\n\n service.entities.push({ id: entity.id, version: entity.version });\n\n const existingResource = await findFileById(directory, id, version);\n\n if (!existingResource) {\n throw new Error(`Cannot find service ${id} in the catalog`);\n }\n\n // Get where the service was located, make sure it goes back there.\n const path = existingResource.split(/[\\\\/]+services/)[0];\n const pathToResource = join(path, 'services');\n\n await rmServiceById(directory)(id, version);\n await writeService(pathToResource)(service, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n\n/**\n * Add a data store to a service by it's id.\n *\n * Optionally specify a version to add the data store to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds an data store to the service\n * const { addDataStoreToService } = utils('/path/to/eventcatalog');\n *\n * // Adds a new data store (orders-db) that the InventoryService will write to\n * await addDataStoreToService('InventoryService', 'writesTo', { id: 'orders-db', version: '2.0.0' });\n *\n * * // Adds a new data store (OrderComplete) that the InventoryService will read from\n * await addDataStoreToService('InventoryService', 'readsFrom', { id: 'orders-db', version: '1.0.0' });\n *\n * ```\n */\n\nexport const addDataStoreToService =\n (directory: string) =>\n async (id: string, operation: 'writesTo' | 'readsFrom', dataStore: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const servicePath = await getResourcePath(directory, id, version);\n const extension = extname(servicePath?.fullPath || '');\n\n if (operation === 'writesTo') {\n if (service.writesTo === undefined) {\n service.writesTo = [];\n }\n\n // We first check if the data store is already in the list\n for (let i = 0; i < service.writesTo.length; i++) {\n if (service.writesTo[i].id === dataStore.id && service.writesTo[i].version === dataStore.version) {\n return;\n }\n }\n\n service.writesTo.push({ id: dataStore.id, version: dataStore.version });\n } else if (operation === 'readsFrom') {\n if (service.readsFrom === undefined) {\n service.readsFrom = [];\n }\n\n // We first check if the data store is already in the list\n for (let i = 0; i < service.readsFrom.length; i++) {\n if (service.readsFrom[i].id === dataStore.id && service.readsFrom[i].version === dataStore.version) {\n return;\n }\n }\n service.readsFrom.push({ id: dataStore.id, version: dataStore.version });\n } else {\n throw new Error(`Operation ${operation} is invalid, only 'writesTo' and 'readsFrom' are supported`);\n }\n\n const existingResource = await findFileById(directory, id, version);\n\n if (!existingResource) {\n throw new Error(`Cannot find service ${id} in the catalog`);\n }\n\n // Get where the service was located, make sure it goes back there.\n const path = existingResource.split(/[\\\\/]+services/)[0];\n const pathToResource = join(path, 'services');\n\n await rmServiceById(directory)(id, version);\n await writeService(pathToResource)(service, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\nimport { basename } from 'node:path';\nimport path from 'node:path';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n // Handle both forward and back slashes for cross-platform compatibility (Windows uses \\, Unix uses /)\n const sourceDirectory = dirname(file).replace(/[/\\\\]versioned[/\\\\][^/\\\\]+[/\\\\]/, path.sep);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n const ignoreListToCopy = ['events', 'commands', 'queries', 'versioned'];\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {\n // get the folder name\n const folderName = basename(src);\n\n if (ignoreListToCopy.includes(folderName)) {\n return false;\n }\n return true;\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 // Dont remove anything in the ignore list\n if (ignoreListToCopy.includes(file)) {\n return;\n }\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id?: string,\n version?: string,\n options?: { type: string; attachSchema?: boolean },\n filePath?: string\n): Promise<Resource | undefined> => {\n const attachSchema = options?.attachSchema || false;\n const file = filePath || (id ? await findFileById(catalogDir, id, version) : undefined);\n if (!file || !fsSync.existsSync(file)) return;\n\n const { data, content } = matter.read(file);\n\n if (attachSchema && data?.schemaPath) {\n const resourceDirectory = dirname(file);\n const pathToSchema = join(resourceDirectory, data.schemaPath);\n if (fsSync.existsSync(pathToSchema)) {\n const schema = fsSync.readFileSync(pathToSchema, 'utf8');\n // Try to parse the schema\n try {\n data.schema = JSON.parse(schema);\n } catch (error) {\n data.schema = schema;\n }\n }\n }\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResourceFolderName = async (catalogDir: string, id: string, version?: string) => {\n const paths = await getResourcePath(catalogDir, id, version);\n if (!paths) return;\n return paths?.directory.split(path.sep).filter(Boolean).pop();\n};\n\nexport const toResource = async (catalogDir: string, rawContents: string) => {\n const { data, content } = matter(rawContents);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n attachSchema = false,\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[]; attachSchema?: boolean }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n\n // Attach the schema if the attachSchema option is set to true\n if (attachSchema && data?.schemaPath) {\n const resourceDirectory = dirname(file);\n const pathToSchema = join(resourceDirectory, data.schemaPath);\n if (fsSync.existsSync(pathToSchema)) {\n const schema = fsSync.readFileSync(pathToSchema, 'utf8');\n // Try to parse the schema\n try {\n data.schema = JSON.parse(schema);\n } catch (error) {\n data.schema = schema;\n }\n }\n }\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n // Verify file is actually removed\n await waitForFileRemoval(file);\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n // Verify directory is actually removed\n await waitForFileRemoval(directory);\n })\n );\n }\n};\n\n// Helper function to ensure file/directory is completely removed\nconst waitForFileRemoval = async (path: string, maxRetries: number = 50, delay: number = 10): Promise<void> => {\n for (let i = 0; i < maxRetries; i++) {\n try {\n await fs.access(path);\n // If access succeeds, file still exists, wait and retry\n await new Promise((resolve) => setTimeout(resolve, delay));\n } catch (error) {\n // If access fails, file is removed\n return;\n }\n }\n // If we reach here, file still exists after all retries\n throw new Error(`File/directory ${path} was not removed after ${maxRetries} attempts`);\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string,\n options?: { path?: string }\n) => {\n let pathToResource: string | undefined;\n\n if (options?.path) {\n pathToResource = join(catalogDir, options.path, 'index.mdx');\n } else {\n // Fall back to global lookup (existing behavior)\n pathToResource = await findFileById(catalogDir, id, version);\n }\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n // Create the directory if it doesn't exist\n fsSync.mkdirSync(path.dirname(pathToResource), { recursive: true });\n\n let fileContent = file.content.trim();\n\n try {\n const json = JSON.parse(fileContent);\n fileContent = JSON.stringify(json, null, 2);\n } catch (error) {\n // Just silently fail if the file is not valid JSON\n // Write it as it is\n }\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), fileContent);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\n};\n\nexport const isLatestVersion = async (catalogDir: string, id: string, version?: string) => {\n const resource = await getResource(catalogDir, id, version);\n if (!resource) return false;\n\n const pathToResource = await getResourcePath(catalogDir, id, version);\n\n return !pathToResource?.relativePath.replace(/\\\\/g, '/').includes('/versioned/');\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname, normalize, sep as pathSeparator, resolve, basename, relative } from 'node:path';\nimport matter from 'gray-matter';\nimport { satisfies, validRange, valid } from 'semver';\n\n/**\n * Returns true if a given version of a resource id exists in the catalog\n */\nexport const versionExists = async (catalogDir: string, id: string, version: string) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n const latestVersion = matchedFiles.find((path) => !path.includes('versioned'));\n\n // If no version is provided, return the latest version\n if (!version) {\n return latestVersion;\n }\n\n // map files into gray matter to get versions\n const parsedFiles = matchedFiles.map((path) => {\n const { data } = matter.read(path);\n return { ...data, path };\n }) as any[];\n\n // Handle 'latest' version - return the latest (non-versioned) file\n if (version === 'latest') {\n return latestVersion;\n }\n\n // First, check for exact version match (handles non-semver versions like '1', '2', etc.)\n const exactMatch = parsedFiles.find((c) => c.version === version);\n if (exactMatch) {\n return exactMatch.path;\n }\n\n // Try semver range matching\n const semverRange = validRange(version);\n\n if (semverRange) {\n const match = parsedFiles.filter((c) => {\n try {\n return satisfies(c.version, semverRange);\n } catch (error) {\n // If satisfies fails (e.g., comparing semver range with non-semver version), skip this file\n return false;\n }\n });\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // If no exact match and no valid semver range, return undefined\n return undefined;\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n // 1. Normalize the input pattern to handle mixed separators potentially\n const normalizedInputPattern = normalize(pattern);\n\n // 2. Determine the absolute base directory (cwd for glob)\n // Resolve ensures it's absolute. Handles cases with/without globstar.\n const absoluteBaseDir = resolve(\n normalizedInputPattern.includes('**') ? normalizedInputPattern.split('**')[0] : dirname(normalizedInputPattern)\n );\n\n // 3. Determine the pattern part relative to the absolute base directory\n // We extract the part of the normalized pattern that comes *after* the absoluteBaseDir\n let relativePattern = relative(absoluteBaseDir, normalizedInputPattern);\n\n // On Windows, relative() might return empty string if paths are identical,\n // or might need normalization if the original pattern didn't have `**`\n // Example: pattern = 'dir/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\file.md'\n // relative() -> 'file.md'\n // Example: pattern = 'dir/**/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\**\\file.md'\n // relative() -> '**\\file.md'\n // Convert separators in the relative pattern to forward slashes for glob\n relativePattern = relativePattern.replace(/\\\\/g, '/');\n\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n\n const files = globSync(relativePattern, {\n cwd: absoluteBaseDir,\n ignore: ['node_modules/**', ...ignoreList],\n absolute: true,\n nodir: true,\n });\n\n // 5. Normalize results for consistency before returning\n return files.map(normalize);\n } catch (error: any) {\n // Add more diagnostic info to the error\n const absoluteBaseDirForError = resolve(\n normalize(pattern).includes('**') ? normalize(pattern).split('**')[0] : dirname(normalize(pattern))\n );\n const relativePatternForError = relative(absoluteBaseDirForError, normalize(pattern)).replace(/\\\\/g, '/');\n throw new Error(\n `Error finding files for pattern \"${pattern}\" (using cwd: \"${absoluteBaseDirForError}\", globPattern: \"${relativePatternForError}\"): ${error.message}`\n );\n }\n};\n\nexport const readMdxFile = async (path: string) => {\n const { data } = matter.read(path);\n const { markdown, ...frontmatter } = data;\n return { ...frontmatter, markdown };\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n // Escape the id to avoid regex issues\n const escapedId = id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${escapedId}['\"]?\\\\s*$`, 'm');\n\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = files.map((file) => {\n const content = fsSync.readFileSync(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n });\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n fsSync.mkdirSync(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n fsSync.rmSync(tmpDirectory, { recursive: true });\n};\n\n// Makes sure values in sends/recieves are unique\nexport const uniqueVersions = (messages: { id: string; version: string }[]): { id: string; version: string }[] => {\n const uniqueSet = new Set();\n\n return messages.filter((message) => {\n const key = `${message.id}-${message.version}`;\n if (!uniqueSet.has(key)) {\n uniqueSet.add(key);\n return true;\n }\n return false;\n });\n};\n"],"mappings":";AACA,OAAOA,SAAQ;AACf,SAAS,QAAAC,OAAM,WAAAC,UAAS,SAAS,YAAAC,iBAAgB;;;ACFjD,SAAS,WAAAC,UAAS,QAAAC,aAAY;;;ACA9B,SAAS,gBAAgB;AACzB,OAAO,YAAY;AACnB,SAAS,YAA6C;AACtD,SAAS,MAAM,SAAS,WAAiC,SAAmB,gBAAgB;AAC5F,OAAO,YAAY;AACnB,SAAS,WAAW,kBAAyB;AAKtC,IAAM,gBAAgB,OAAO,YAAoB,IAAY,YAAoB;AACtF,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,oBAAoB;AAC9D,QAAM,eAAgB,MAAM,iBAAiB,OAAO,IAAI,OAAO,KAAM,CAAC;AACtE,SAAO,aAAa,SAAS;AAC/B;AAEO,IAAM,eAAe,OAAO,YAAoB,IAAY,YAAkD;AACnH,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,oBAAoB;AAE9D,QAAM,eAAgB,MAAM,iBAAiB,OAAO,EAAE,KAAM,CAAC;AAC7D,QAAM,gBAAgB,aAAa,KAAK,CAACC,UAAS,CAACA,MAAK,SAAS,WAAW,CAAC;AAG7E,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAGA,QAAM,cAAc,aAAa,IAAI,CAACA,UAAS;AAC7C,UAAM,EAAE,KAAK,IAAI,OAAO,KAAKA,KAAI;AACjC,WAAO,EAAE,GAAG,MAAM,MAAAA,MAAK;AAAA,EACzB,CAAC;AAGD,MAAI,YAAY,UAAU;AACxB,WAAO;AAAA,EACT;AAGA,QAAM,aAAa,YAAY,KAAK,CAAC,MAAM,EAAE,YAAY,OAAO;AAChE,MAAI,YAAY;AACd,WAAO,WAAW;AAAA,EACpB;AAGA,QAAM,cAAc,WAAW,OAAO;AAEt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C,cAAQ,WAAW,CAAC;AAAA,IACtB;AAGA,aAAS,IAAI,GAAG,IAAI,QAAQ,SAAS,QAAQ,KAAK;AAChD,UAAI,QAAQ,SAAS,CAAC,EAAE,OAAO,UAAU,MAAM,QAAQ,SAAS,CAAC,EAAE,YAAY,UAAU,SAAS;AAChG;AAAA,MACF;AAAA,IACF;AAEA,YAAQ,SAAS,KAAK,EAAE,IAAI,UAAU,IAAI,SAAS,UAAU,QAAQ,CAAC;AAAA,EACxE,WAAW,cAAc,aAAa;AACpC,QAAI,QAAQ,cAAc,QAAW;AACnC,cAAQ,YAAY,CAAC;AAAA,IACvB;AAGA,aAAS,IAAI,GAAG,IAAI,QAAQ,UAAU,QAAQ,KAAK;AACjD,UAAI,QAAQ,UAAU,CAAC,EAAE,OAAO,UAAU,MAAM,QAAQ,UAAU,CAAC,EAAE,YAAY,UAAU,SAAS;AAClG;AAAA,MACF;AAAA,IACF;AACA,YAAQ,UAAU,KAAK,EAAE,IAAI,UAAU,IAAI,SAAS,UAAU,QAAQ,CAAC;AAAA,EACzE,OAAO;AACL,UAAM,IAAI,MAAM,aAAa,SAAS,4DAA4D;AAAA,EACpG;AAEA,QAAM,mBAAmB,MAAM,aAAa,WAAW,IAAI,OAAO;AAElE,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI,MAAM,uBAAuB,EAAE,iBAAiB;AAAA,EAC5D;AAGA,QAAMA,QAAO,iBAAiB,MAAM,gBAAgB,EAAE,CAAC;AACvD,QAAM,iBAAiBC,MAAKD,OAAM,UAAU;AAE5C,QAAM,cAAc,SAAS,EAAE,IAAI,OAAO;AAC1C,QAAM,aAAa,cAAc,EAAE,SAAS,EAAE,QAAQ,cAAc,QAAQ,OAAO,MAAM,CAAC;AAC5F;","names":["fs","join","dirname","relative","dirname","join","path","matter","fsSync","satisfies","basename","dirname","file","join","path","matter","dirname","join","fsSync","path","resolve","path","join","fs","dirname","relative"]}
package/dist/teams.d.mts DELETED
@@ -1,90 +0,0 @@
1
- import { Team } from './types.d.mjs';
2
-
3
- /**
4
- * Returns a team from EventCatalog.
5
- *
6
- *
7
- * @example
8
- * ```ts
9
- * import utils from '@eventcatalog/utils';
10
- *
11
- * const { getTeam } = utils('/path/to/eventcatalog');
12
- *
13
- * // Gets the team with the given id
14
- * const team = await getTeam('eventcatalog-core-team');
15
- *
16
- * ```
17
- */
18
- declare const getTeam: (catalogDir: string) => (id: string) => Promise<Team | undefined>;
19
- /**
20
- * Returns all teams from EventCatalog.
21
- *
22
- * @example
23
- * ```ts
24
- * import utils from '@eventcatalog/utils';
25
- *
26
- * const { getTeams } = utils('/path/to/eventcatalog');
27
- *
28
- * // Gets all teams from the catalog
29
- * const channels = await getTeams();
30
- *
31
- * ```
32
- */
33
- declare const getTeams: (catalogDir: string) => (options?: {}) => Promise<Team[]>;
34
- /**
35
- * Write a team to EventCatalog.
36
- *
37
- * @example
38
- * ```ts
39
- * import utils from '@eventcatalog/utils';
40
- *
41
- * const { writeTeam } = utils('/path/to/eventcatalog');
42
- *
43
- * // Write a team to the catalog
44
- * // team would be written to teams/EventCatalogCoreTeam
45
- * await writeTeam({
46
- * id: 'eventcatalog-core-team',
47
- * name: 'EventCatalogCoreTeam',
48
- * members: ['dboyne', 'asmith', 'msmith'],
49
- * email: 'test@test.com',
50
- * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123
51
- * });
52
- *
53
- * // Write a team to the catalog and override the existing content (if there is any)
54
- * await writeTeam({
55
- * id: 'eventcatalog-core-team',
56
- * name: 'EventCatalogCoreTeam',
57
- * members: ['dboyne', 'asmith', 'msmith'],
58
- * email: 'test@test.com',
59
- * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123
60
- * }, { override: true });
61
- *
62
- * ```
63
- */
64
- declare const writeTeam: (catalogDir: string) => (team: Team, options?: {
65
- override?: boolean;
66
- }) => Promise<void>;
67
- /**
68
- * Delete a team by it's id.
69
- *
70
- * @example
71
- * ```ts
72
- * import utils from '@eventcatalog/utils';
73
- *
74
- * const { rmTeamById } = utils('/path/to/eventcatalog');
75
- *
76
- * // deletes the EventCatalogCoreTeam team
77
- * await rmTeamById('eventcatalog-core-team');
78
- *
79
- * ```
80
- */
81
- declare const rmTeamById: (catalogDir: string) => (id: string) => Promise<void>;
82
- /**
83
- * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
84
- * @param id - The id of the resource to get the owners for
85
- * @param version - Optional version of the resource
86
- * @returns { owners: User[] }
87
- */
88
- declare const getOwnersForResource: (catalogDir: string) => (id: string, version?: string) => Promise<Team[]>;
89
-
90
- export { getOwnersForResource, getTeam, getTeams, rmTeamById, writeTeam };
package/dist/teams.d.ts DELETED
@@ -1,90 +0,0 @@
1
- import { Team } from './types.d.js';
2
-
3
- /**
4
- * Returns a team from EventCatalog.
5
- *
6
- *
7
- * @example
8
- * ```ts
9
- * import utils from '@eventcatalog/utils';
10
- *
11
- * const { getTeam } = utils('/path/to/eventcatalog');
12
- *
13
- * // Gets the team with the given id
14
- * const team = await getTeam('eventcatalog-core-team');
15
- *
16
- * ```
17
- */
18
- declare const getTeam: (catalogDir: string) => (id: string) => Promise<Team | undefined>;
19
- /**
20
- * Returns all teams from EventCatalog.
21
- *
22
- * @example
23
- * ```ts
24
- * import utils from '@eventcatalog/utils';
25
- *
26
- * const { getTeams } = utils('/path/to/eventcatalog');
27
- *
28
- * // Gets all teams from the catalog
29
- * const channels = await getTeams();
30
- *
31
- * ```
32
- */
33
- declare const getTeams: (catalogDir: string) => (options?: {}) => Promise<Team[]>;
34
- /**
35
- * Write a team to EventCatalog.
36
- *
37
- * @example
38
- * ```ts
39
- * import utils from '@eventcatalog/utils';
40
- *
41
- * const { writeTeam } = utils('/path/to/eventcatalog');
42
- *
43
- * // Write a team to the catalog
44
- * // team would be written to teams/EventCatalogCoreTeam
45
- * await writeTeam({
46
- * id: 'eventcatalog-core-team',
47
- * name: 'EventCatalogCoreTeam',
48
- * members: ['dboyne', 'asmith', 'msmith'],
49
- * email: 'test@test.com',
50
- * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123
51
- * });
52
- *
53
- * // Write a team to the catalog and override the existing content (if there is any)
54
- * await writeTeam({
55
- * id: 'eventcatalog-core-team',
56
- * name: 'EventCatalogCoreTeam',
57
- * members: ['dboyne', 'asmith', 'msmith'],
58
- * email: 'test@test.com',
59
- * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123
60
- * }, { override: true });
61
- *
62
- * ```
63
- */
64
- declare const writeTeam: (catalogDir: string) => (team: Team, options?: {
65
- override?: boolean;
66
- }) => Promise<void>;
67
- /**
68
- * Delete a team by it's id.
69
- *
70
- * @example
71
- * ```ts
72
- * import utils from '@eventcatalog/utils';
73
- *
74
- * const { rmTeamById } = utils('/path/to/eventcatalog');
75
- *
76
- * // deletes the EventCatalogCoreTeam team
77
- * await rmTeamById('eventcatalog-core-team');
78
- *
79
- * ```
80
- */
81
- declare const rmTeamById: (catalogDir: string) => (id: string) => Promise<void>;
82
- /**
83
- * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
84
- * @param id - The id of the resource to get the owners for
85
- * @param version - Optional version of the resource
86
- * @returns { owners: User[] }
87
- */
88
- declare const getOwnersForResource: (catalogDir: string) => (id: string, version?: string) => Promise<Team[]>;
89
-
90
- export { getOwnersForResource, getTeam, getTeams, rmTeamById, writeTeam };
package/dist/teams.js DELETED
@@ -1,246 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/teams.ts
31
- var teams_exports = {};
32
- __export(teams_exports, {
33
- getOwnersForResource: () => getOwnersForResource,
34
- getTeam: () => getTeam,
35
- getTeams: () => getTeams,
36
- rmTeamById: () => rmTeamById,
37
- writeTeam: () => writeTeam
38
- });
39
- module.exports = __toCommonJS(teams_exports);
40
- var import_promises2 = __toESM(require("fs/promises"));
41
- var import_node_fs4 = __toESM(require("fs"));
42
- var import_node_path5 = require("path");
43
- var import_gray_matter4 = __toESM(require("gray-matter"));
44
-
45
- // src/internal/utils.ts
46
- var import_glob = require("glob");
47
- var import_node_fs = __toESM(require("fs"));
48
- var import_fs_extra = require("fs-extra");
49
- var import_node_path = require("path");
50
- var import_gray_matter = __toESM(require("gray-matter"));
51
- var import_semver = require("semver");
52
- var findFileById = async (catalogDir, id, version) => {
53
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
54
- const matchedFiles = await searchFilesForId(files, id) || [];
55
- const latestVersion = matchedFiles.find((path3) => !path3.includes("versioned"));
56
- if (!version) {
57
- return latestVersion;
58
- }
59
- const parsedFiles = matchedFiles.map((path3) => {
60
- const { data } = import_gray_matter.default.read(path3);
61
- return { ...data, path: path3 };
62
- });
63
- if (version === "latest") {
64
- return latestVersion;
65
- }
66
- const exactMatch = parsedFiles.find((c) => c.version === version);
67
- if (exactMatch) {
68
- return exactMatch.path;
69
- }
70
- const semverRange = (0, import_semver.validRange)(version);
71
- if (semverRange) {
72
- const match = parsedFiles.filter((c) => {
73
- try {
74
- return (0, import_semver.satisfies)(c.version, semverRange);
75
- } catch (error) {
76
- return false;
77
- }
78
- });
79
- return match.length > 0 ? match[0].path : void 0;
80
- }
81
- return void 0;
82
- };
83
- var getFiles = async (pattern, ignore = "") => {
84
- try {
85
- const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
86
- const absoluteBaseDir = (0, import_node_path.resolve)(
87
- normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
88
- );
89
- let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
90
- relativePattern = relativePattern.replace(/\\/g, "/");
91
- const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
92
- const files = (0, import_glob.globSync)(relativePattern, {
93
- cwd: absoluteBaseDir,
94
- ignore: ["node_modules/**", ...ignoreList],
95
- absolute: true,
96
- nodir: true
97
- });
98
- return files.map(import_node_path.normalize);
99
- } catch (error) {
100
- const absoluteBaseDirForError = (0, import_node_path.resolve)(
101
- (0, import_node_path.normalize)(pattern).includes("**") ? (0, import_node_path.normalize)(pattern).split("**")[0] : (0, import_node_path.dirname)((0, import_node_path.normalize)(pattern))
102
- );
103
- const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
104
- throw new Error(
105
- `Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
106
- );
107
- }
108
- };
109
- var searchFilesForId = async (files, id, version) => {
110
- const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
111
- const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${escapedId}['"]?\\s*$`, "m");
112
- const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
113
- const matches = files.map((file) => {
114
- const content = import_node_fs.default.readFileSync(file, "utf-8");
115
- const hasIdMatch = content.match(idRegex);
116
- if (version && !content.match(versionRegex)) {
117
- return void 0;
118
- }
119
- if (hasIdMatch) {
120
- return file;
121
- }
122
- });
123
- return matches.filter(Boolean).filter((file) => file !== void 0);
124
- };
125
-
126
- // src/internal/resources.ts
127
- var import_path = require("path");
128
- var import_gray_matter2 = __toESM(require("gray-matter"));
129
- var import_promises = __toESM(require("fs/promises"));
130
- var import_node_fs2 = __toESM(require("fs"));
131
- var import_semver2 = require("semver");
132
- var import_proper_lockfile = require("proper-lockfile");
133
- var import_node_path2 = require("path");
134
- var import_node_path3 = __toESM(require("path"));
135
- var getResource = async (catalogDir, id, version, options, filePath) => {
136
- const attachSchema = options?.attachSchema || false;
137
- const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
138
- if (!file || !import_node_fs2.default.existsSync(file)) return;
139
- const { data, content } = import_gray_matter2.default.read(file);
140
- if (attachSchema && data?.schemaPath) {
141
- const resourceDirectory = (0, import_path.dirname)(file);
142
- const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
143
- if (import_node_fs2.default.existsSync(pathToSchema)) {
144
- const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
145
- try {
146
- data.schema = JSON.parse(schema);
147
- } catch (error) {
148
- data.schema = schema;
149
- }
150
- }
151
- }
152
- return {
153
- ...data,
154
- markdown: content.trim()
155
- };
156
- };
157
-
158
- // src/teams.ts
159
- var import_node_path6 = __toESM(require("path"));
160
-
161
- // src/users.ts
162
- var import_node_fs3 = __toESM(require("fs"));
163
- var import_node_path4 = require("path");
164
- var import_gray_matter3 = __toESM(require("gray-matter"));
165
- var getUser = (catalogDir) => async (id) => {
166
- const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
167
- if (files.length == 0) return void 0;
168
- const file = files[0];
169
- const { data, content } = import_gray_matter3.default.read(file);
170
- return {
171
- ...data,
172
- id: data.id,
173
- name: data.name,
174
- avatarUrl: data.avatarUrl,
175
- markdown: content.trim()
176
- };
177
- };
178
-
179
- // src/teams.ts
180
- var getTeam = (catalogDir) => async (id) => {
181
- const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
182
- if (files.length == 0) return void 0;
183
- const file = files[0];
184
- const { data, content } = import_gray_matter4.default.read(file);
185
- return {
186
- ...data,
187
- id: data.id,
188
- name: data.name,
189
- markdown: content.trim()
190
- };
191
- };
192
- var getTeams = (catalogDir) => async (options) => {
193
- const files = await getFiles(`${catalogDir}/*.{md,mdx}`);
194
- if (files.length === 0) return [];
195
- return files.map((file) => {
196
- const { data, content } = import_gray_matter4.default.read(file);
197
- return {
198
- ...data,
199
- id: data.id,
200
- name: data.name,
201
- markdown: content.trim()
202
- };
203
- });
204
- };
205
- var writeTeam = (catalogDir) => async (team, options = {}) => {
206
- const resource = { ...team };
207
- const currentTeam = await getTeam(catalogDir)(resource.id);
208
- const exists = currentTeam !== void 0;
209
- if (exists && !options.override) {
210
- throw new Error(`Failed to write ${resource.id} (team) as it already exists`);
211
- }
212
- const { markdown, ...frontmatter } = resource;
213
- const document = import_gray_matter4.default.stringify(markdown, frontmatter);
214
- import_node_fs4.default.mkdirSync((0, import_node_path5.join)(catalogDir, ""), { recursive: true });
215
- import_node_fs4.default.writeFileSync((0, import_node_path5.join)(catalogDir, "", `${resource.id}.mdx`), document);
216
- };
217
- var rmTeamById = (catalogDir) => async (id) => {
218
- await import_promises2.default.rm((0, import_node_path5.join)(catalogDir, `${id}.mdx`), { recursive: true });
219
- };
220
- var getOwnersForResource = (catalogDir) => async (id, version) => {
221
- const resource = await getResource(catalogDir, id, version);
222
- let owners = [];
223
- if (!resource) return [];
224
- if (!resource.owners) return [];
225
- for (const owner of resource.owners) {
226
- const team = await getTeam(import_node_path6.default.join(catalogDir, "teams"))(owner);
227
- if (team) {
228
- owners.push(team);
229
- } else {
230
- const user = await getUser(import_node_path6.default.join(catalogDir, "users"))(owner);
231
- if (user) {
232
- owners.push(user);
233
- }
234
- }
235
- }
236
- return owners;
237
- };
238
- // Annotate the CommonJS export names for ESM import in node:
239
- 0 && (module.exports = {
240
- getOwnersForResource,
241
- getTeam,
242
- getTeams,
243
- rmTeamById,
244
- writeTeam
245
- });
246
- //# sourceMappingURL=teams.js.map
package/dist/teams.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/teams.ts","../src/internal/utils.ts","../src/internal/resources.ts","../src/users.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { join } from 'node:path';\nimport type { Team } from './types';\nimport matter from 'gray-matter';\nimport { getFiles } from './internal/utils';\nimport { getResource } from './internal/resources';\nimport path from 'node:path';\nimport { getUser, getUsers } from './users';\n\n/**\n * Returns a team from EventCatalog.\n *\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getTeam } = utils('/path/to/eventcatalog');\n *\n * // Gets the team with the given id\n * const team = await getTeam('eventcatalog-core-team');\n *\n * ```\n */\nexport const getTeam =\n (catalogDir: string) =>\n async (id: string): Promise<Team | undefined> => {\n const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);\n\n if (files.length == 0) return undefined;\n const file = files[0];\n\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n markdown: content.trim(),\n } as Team;\n };\n\n/**\n * Returns all teams from EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getTeams } = utils('/path/to/eventcatalog');\n *\n * // Gets all teams from the catalog\n * const channels = await getTeams();\n *\n * ```\n */\nexport const getTeams =\n (catalogDir: string) =>\n async (options?: {}): Promise<Team[]> => {\n const files = await getFiles(`${catalogDir}/*.{md,mdx}`);\n if (files.length === 0) return [];\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n markdown: content.trim(),\n } as Team;\n });\n };\n\n/**\n * Write a team to EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeTeam } = utils('/path/to/eventcatalog');\n *\n * // Write a team to the catalog\n * // team would be written to teams/EventCatalogCoreTeam\n * await writeTeam({\n * id: 'eventcatalog-core-team',\n * name: 'EventCatalogCoreTeam',\n * members: ['dboyne', 'asmith', 'msmith'],\n * email: 'test@test.com',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * });\n *\n * // Write a team to the catalog and override the existing content (if there is any)\n * await writeTeam({\n * id: 'eventcatalog-core-team',\n * name: 'EventCatalogCoreTeam',\n * members: ['dboyne', 'asmith', 'msmith'],\n * email: 'test@test.com',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * }, { override: true });\n *\n * ```\n */\nexport const writeTeam =\n (catalogDir: string) =>\n async (team: Team, options: { override?: boolean } = {}) => {\n const resource: Team = { ...team };\n\n // Get the path\n const currentTeam = await getTeam(catalogDir)(resource.id);\n const exists = currentTeam !== undefined;\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (team) as it already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n const document = matter.stringify(markdown, frontmatter);\n fsSync.mkdirSync(join(catalogDir, ''), { recursive: true });\n fsSync.writeFileSync(join(catalogDir, '', `${resource.id}.mdx`), document);\n };\n\n/**\n * Delete a team by it's id.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmTeamById } = utils('/path/to/eventcatalog');\n *\n * // deletes the EventCatalogCoreTeam team\n * await rmTeamById('eventcatalog-core-team');\n *\n * ```\n */\nexport const rmTeamById = (catalogDir: string) => async (id: string) => {\n await fs.rm(join(catalogDir, `${id}.mdx`), { recursive: true });\n};\n\n/**\n * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)\n * @param id - The id of the resource to get the owners for\n * @param version - Optional version of the resource\n * @returns { owners: User[] }\n */\nexport const getOwnersForResource = (catalogDir: string) => async (id: string, version?: string) => {\n const resource = await getResource(catalogDir, id, version);\n let owners: Team[] = [];\n if (!resource) return [];\n\n if (!resource.owners) return [];\n\n // First check if the owner is a team\n for (const owner of resource.owners) {\n const team = await getTeam(path.join(catalogDir, 'teams'))(owner);\n if (team) {\n owners.push(team);\n } else {\n // If the owner is not a team, check if it's a user\n const user = await getUser(path.join(catalogDir, 'users'))(owner);\n if (user) {\n owners.push(user);\n }\n }\n }\n\n return owners;\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname, normalize, sep as pathSeparator, resolve, basename, relative } from 'node:path';\nimport matter from 'gray-matter';\nimport { satisfies, validRange, valid } from 'semver';\n\n/**\n * Returns true if a given version of a resource id exists in the catalog\n */\nexport const versionExists = async (catalogDir: string, id: string, version: string) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n const latestVersion = matchedFiles.find((path) => !path.includes('versioned'));\n\n // If no version is provided, return the latest version\n if (!version) {\n return latestVersion;\n }\n\n // map files into gray matter to get versions\n const parsedFiles = matchedFiles.map((path) => {\n const { data } = matter.read(path);\n return { ...data, path };\n }) as any[];\n\n // Handle 'latest' version - return the latest (non-versioned) file\n if (version === 'latest') {\n return latestVersion;\n }\n\n // First, check for exact version match (handles non-semver versions like '1', '2', etc.)\n const exactMatch = parsedFiles.find((c) => c.version === version);\n if (exactMatch) {\n return exactMatch.path;\n }\n\n // Try semver range matching\n const semverRange = validRange(version);\n\n if (semverRange) {\n const match = parsedFiles.filter((c) => {\n try {\n return satisfies(c.version, semverRange);\n } catch (error) {\n // If satisfies fails (e.g., comparing semver range with non-semver version), skip this file\n return false;\n }\n });\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // If no exact match and no valid semver range, return undefined\n return undefined;\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n // 1. Normalize the input pattern to handle mixed separators potentially\n const normalizedInputPattern = normalize(pattern);\n\n // 2. Determine the absolute base directory (cwd for glob)\n // Resolve ensures it's absolute. Handles cases with/without globstar.\n const absoluteBaseDir = resolve(\n normalizedInputPattern.includes('**') ? normalizedInputPattern.split('**')[0] : dirname(normalizedInputPattern)\n );\n\n // 3. Determine the pattern part relative to the absolute base directory\n // We extract the part of the normalized pattern that comes *after* the absoluteBaseDir\n let relativePattern = relative(absoluteBaseDir, normalizedInputPattern);\n\n // On Windows, relative() might return empty string if paths are identical,\n // or might need normalization if the original pattern didn't have `**`\n // Example: pattern = 'dir/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\file.md'\n // relative() -> 'file.md'\n // Example: pattern = 'dir/**/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\**\\file.md'\n // relative() -> '**\\file.md'\n // Convert separators in the relative pattern to forward slashes for glob\n relativePattern = relativePattern.replace(/\\\\/g, '/');\n\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n\n const files = globSync(relativePattern, {\n cwd: absoluteBaseDir,\n ignore: ['node_modules/**', ...ignoreList],\n absolute: true,\n nodir: true,\n });\n\n // 5. Normalize results for consistency before returning\n return files.map(normalize);\n } catch (error: any) {\n // Add more diagnostic info to the error\n const absoluteBaseDirForError = resolve(\n normalize(pattern).includes('**') ? normalize(pattern).split('**')[0] : dirname(normalize(pattern))\n );\n const relativePatternForError = relative(absoluteBaseDirForError, normalize(pattern)).replace(/\\\\/g, '/');\n throw new Error(\n `Error finding files for pattern \"${pattern}\" (using cwd: \"${absoluteBaseDirForError}\", globPattern: \"${relativePatternForError}\"): ${error.message}`\n );\n }\n};\n\nexport const readMdxFile = async (path: string) => {\n const { data } = matter.read(path);\n const { markdown, ...frontmatter } = data;\n return { ...frontmatter, markdown };\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n // Escape the id to avoid regex issues\n const escapedId = id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${escapedId}['\"]?\\\\s*$`, 'm');\n\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = files.map((file) => {\n const content = fsSync.readFileSync(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n });\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n fsSync.mkdirSync(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n fsSync.rmSync(tmpDirectory, { recursive: true });\n};\n\n// Makes sure values in sends/recieves are unique\nexport const uniqueVersions = (messages: { id: string; version: string }[]): { id: string; version: string }[] => {\n const uniqueSet = new Set();\n\n return messages.filter((message) => {\n const key = `${message.id}-${message.version}`;\n if (!uniqueSet.has(key)) {\n uniqueSet.add(key);\n return true;\n }\n return false;\n });\n};\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\nimport { basename } from 'node:path';\nimport path from 'node:path';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n // Handle both forward and back slashes for cross-platform compatibility (Windows uses \\, Unix uses /)\n const sourceDirectory = dirname(file).replace(/[/\\\\]versioned[/\\\\][^/\\\\]+[/\\\\]/, path.sep);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n const ignoreListToCopy = ['events', 'commands', 'queries', 'versioned'];\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {\n // get the folder name\n const folderName = basename(src);\n\n if (ignoreListToCopy.includes(folderName)) {\n return false;\n }\n return true;\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 // Dont remove anything in the ignore list\n if (ignoreListToCopy.includes(file)) {\n return;\n }\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id?: string,\n version?: string,\n options?: { type: string; attachSchema?: boolean },\n filePath?: string\n): Promise<Resource | undefined> => {\n const attachSchema = options?.attachSchema || false;\n const file = filePath || (id ? await findFileById(catalogDir, id, version) : undefined);\n if (!file || !fsSync.existsSync(file)) return;\n\n const { data, content } = matter.read(file);\n\n if (attachSchema && data?.schemaPath) {\n const resourceDirectory = dirname(file);\n const pathToSchema = join(resourceDirectory, data.schemaPath);\n if (fsSync.existsSync(pathToSchema)) {\n const schema = fsSync.readFileSync(pathToSchema, 'utf8');\n // Try to parse the schema\n try {\n data.schema = JSON.parse(schema);\n } catch (error) {\n data.schema = schema;\n }\n }\n }\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResourceFolderName = async (catalogDir: string, id: string, version?: string) => {\n const paths = await getResourcePath(catalogDir, id, version);\n if (!paths) return;\n return paths?.directory.split(path.sep).filter(Boolean).pop();\n};\n\nexport const toResource = async (catalogDir: string, rawContents: string) => {\n const { data, content } = matter(rawContents);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n attachSchema = false,\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[]; attachSchema?: boolean }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n\n // Attach the schema if the attachSchema option is set to true\n if (attachSchema && data?.schemaPath) {\n const resourceDirectory = dirname(file);\n const pathToSchema = join(resourceDirectory, data.schemaPath);\n if (fsSync.existsSync(pathToSchema)) {\n const schema = fsSync.readFileSync(pathToSchema, 'utf8');\n // Try to parse the schema\n try {\n data.schema = JSON.parse(schema);\n } catch (error) {\n data.schema = schema;\n }\n }\n }\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n // Verify file is actually removed\n await waitForFileRemoval(file);\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n // Verify directory is actually removed\n await waitForFileRemoval(directory);\n })\n );\n }\n};\n\n// Helper function to ensure file/directory is completely removed\nconst waitForFileRemoval = async (path: string, maxRetries: number = 50, delay: number = 10): Promise<void> => {\n for (let i = 0; i < maxRetries; i++) {\n try {\n await fs.access(path);\n // If access succeeds, file still exists, wait and retry\n await new Promise((resolve) => setTimeout(resolve, delay));\n } catch (error) {\n // If access fails, file is removed\n return;\n }\n }\n // If we reach here, file still exists after all retries\n throw new Error(`File/directory ${path} was not removed after ${maxRetries} attempts`);\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string,\n options?: { path?: string }\n) => {\n let pathToResource: string | undefined;\n\n if (options?.path) {\n pathToResource = join(catalogDir, options.path, 'index.mdx');\n } else {\n // Fall back to global lookup (existing behavior)\n pathToResource = await findFileById(catalogDir, id, version);\n }\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n // Create the directory if it doesn't exist\n fsSync.mkdirSync(path.dirname(pathToResource), { recursive: true });\n\n let fileContent = file.content.trim();\n\n try {\n const json = JSON.parse(fileContent);\n fileContent = JSON.stringify(json, null, 2);\n } catch (error) {\n // Just silently fail if the file is not valid JSON\n // Write it as it is\n }\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), fileContent);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\n};\n\nexport const isLatestVersion = async (catalogDir: string, id: string, version?: string) => {\n const resource = await getResource(catalogDir, id, version);\n if (!resource) return false;\n\n const pathToResource = await getResourcePath(catalogDir, id, version);\n\n return !pathToResource?.relativePath.replace(/\\\\/g, '/').includes('/versioned/');\n};\n","import fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { join } from 'node:path';\nimport type { User } from './types';\nimport matter from 'gray-matter';\nimport { getFiles } from './internal/utils';\n\n/**\n * Returns a user from EventCatalog.\n *\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUser } = utils('/path/to/eventcatalog');\n *\n * // Gets the user with the given id\n * const user = await getUser('eventcatalog-core-user');\n *\n * ```\n */\nexport const getUser =\n (catalogDir: string) =>\n async (id: string): Promise<User | undefined> => {\n const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);\n\n if (files.length == 0) return undefined;\n const file = files[0];\n\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n avatarUrl: data.avatarUrl,\n markdown: content.trim(),\n } as User;\n };\n\n/**\n * Returns all users from EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getUsers } = utils('/path/to/eventcatalog');\n *\n * // Gets all users from the catalog\n * const channels = await getUsers();\n *\n * ```\n */\nexport const getUsers =\n (catalogDir: string) =>\n async (options?: {}): Promise<User[]> => {\n const files = await getFiles(`${catalogDir}/users/*.{md,mdx}`);\n if (files.length === 0) return [];\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n id: data.id,\n name: data.name,\n avatarUrl: data.avatarUrl,\n markdown: content.trim(),\n } as User;\n });\n };\n\n/**\n * Write a user to EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeUser } = utils('/path/to/eventcatalog');\n *\n * // Write a user to the catalog\n * // user would be written to users/eventcatalog-tech-lead\n * await writeUser({\n * id: 'eventcatalog-tech-lead',\n * name: 'EventCatalog Tech Lead',\n * email: 'test@test.com',\n * avatarUrl: 'https://pbs.twimg.com/profile_images/1262283153563140096/DYRDqKg6_400x400.png',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * });\n *\n * // Write a team to the catalog and override the existing content (if there is any)\n * await writeUser({\n * id: 'eventcatalog-tech-lead',\n * name: 'EventCatalog Tech Lead',\n * email: 'test@test.com',\n * avatarUrl: 'https://pbs.twimg.com/profile_images/1262283153563140096/DYRDqKg6_400x400.png',\n * slackDirectMessageUrl: https://yourteam.slack.com/channels/boyney123\n * }, { override: true });\n *\n * ```\n */\nexport const writeUser =\n (catalogDir: string) =>\n async (user: User, options: { override?: boolean } = {}) => {\n const resource: User = { ...user };\n\n // Get the path\n const currentUser = await getUser(catalogDir)(resource.id);\n const exists = currentUser !== undefined;\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (user) as it already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n const document = matter.stringify(markdown, frontmatter);\n fsSync.mkdirSync(join(catalogDir, ''), { recursive: true });\n fsSync.writeFileSync(join(catalogDir, '', `${resource.id}.mdx`), document);\n };\n\n/**\n * Delete a user by it's id.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmUserById } = utils('/path/to/eventcatalog');\n *\n * // deletes the user with id eventcatalog-core-user\n * await rmUserById('eventcatalog-core-user');\n *\n * ```\n */\nexport const rmUserById = (catalogDir: string) => async (id: string) => {\n fsSync.rmSync(join(catalogDir, `${id}.mdx`), { recursive: true });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAe;AACf,IAAAC,kBAAmB;AACnB,IAAAC,oBAAqB;AAErB,IAAAC,sBAAmB;;;ACJnB,kBAAyB;AACzB,qBAAmB;AACnB,sBAAsD;AACtD,uBAA4F;AAC5F,yBAAmB;AACnB,oBAA6C;AAWtC,IAAM,eAAe,OAAO,YAAoB,IAAY,YAAkD;AACnH,QAAM,QAAQ,MAAM,SAAS,GAAG,UAAU,oBAAoB;AAE9D,QAAM,eAAgB,MAAM,iBAAiB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BAAK,YAAY,GAAG,EAAE,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;AAChE;AAQO,IAAM,uBAAuB,CAAC,eAAuB,OAAO,IAAY,YAAqB;AAClG,QAAM,WAAW,MAAM,YAAY,YAAY,IAAI,OAAO;AAC1D,MAAI,SAAiB,CAAC;AACtB,MAAI,CAAC,SAAU,QAAO,CAAC;AAEvB,MAAI,CAAC,SAAS,OAAQ,QAAO,CAAC;AAG9B,aAAW,SAAS,SAAS,QAAQ;AACnC,UAAM,OAAO,MAAM,QAAQ,kBAAAC,QAAK,KAAK,YAAY,OAAO,CAAC,EAAE,KAAK;AAChE,QAAI,MAAM;AACR,aAAO,KAAK,IAAI;AAAA,IAClB,OAAO;AAEL,YAAM,OAAO,MAAM,QAAQ,kBAAAA,QAAK,KAAK,YAAY,OAAO,CAAC,EAAE,KAAK;AAChE,UAAI,MAAM;AACR,eAAO,KAAK,IAAI;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_promises","import_node_fs","import_node_path","import_gray_matter","path","matter","fsSync","import_gray_matter","import_node_fs","import_semver","import_node_path","fsSync","matter","import_node_path","import_node_fs","import_node_path","import_gray_matter","matter","matter","fsSync","fs","path"]}