@eventcatalog/sdk 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels.d.mts +35 -1
- package/dist/channels.d.ts +35 -1
- package/dist/channels.js +34 -3
- package/dist/channels.js.map +1 -1
- package/dist/channels.mjs +33 -3
- package/dist/channels.mjs.map +1 -1
- package/dist/commands.d.mts +34 -1
- package/dist/commands.d.ts +34 -1
- package/dist/commands.js +34 -3
- package/dist/commands.js.map +1 -1
- package/dist/commands.mjs +33 -3
- package/dist/commands.mjs.map +1 -1
- package/dist/domains.d.mts +34 -1
- package/dist/domains.d.ts +34 -1
- package/dist/domains.js +34 -3
- package/dist/domains.js.map +1 -1
- package/dist/domains.mjs +33 -3
- package/dist/domains.mjs.map +1 -1
- package/dist/events.d.mts +34 -1
- package/dist/events.d.ts +34 -1
- package/dist/events.js +34 -3
- package/dist/events.js.map +1 -1
- package/dist/events.mjs +33 -3
- package/dist/events.mjs.map +1 -1
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +73 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -3
- package/dist/index.mjs.map +1 -1
- package/dist/queries.d.mts +33 -1
- package/dist/queries.d.ts +33 -1
- package/dist/queries.js +34 -3
- package/dist/queries.js.map +1 -1
- package/dist/queries.mjs +33 -3
- package/dist/queries.mjs.map +1 -1
- package/dist/services.d.mts +34 -1
- package/dist/services.d.ts +34 -1
- package/dist/services.js +34 -3
- package/dist/services.js.map +1 -1
- package/dist/services.mjs +33 -3
- package/dist/services.mjs.map +1 -1
- package/package.json +1 -1
package/dist/events.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/events.ts","../src/internal/utils.ts","../src/internal/resources.ts"],"sourcesContent":["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 * // Write a event to the catalog and override the existing content (if there is any)\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 * }, { override: true });\n * ```\n */\nexport const writeEvent =\n (directory: string) =>\n async (event: Event, options: { path?: string; override?: boolean } = { path: '', override: false }) =>\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; override?: boolean } = { path: '', type: '', override: false }\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 && !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 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"],"mappings":";AAAA,OAAOA,SAAQ;AACf,SAAS,QAAAC,aAAY;;;ACDrB,SAAS,YAAY;AACrB,OAAO,QAAQ;AACf,SAAS,YAA6C;AACtD,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,WAAW,YAAY,aAAa;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,OAAO,KAAK,IAAI;AACjC,WAAO,EAAE,GAAG,MAAM,KAAK;AAAA,EACzB,CAAC;AAED,QAAM,cAAc,WAAW,OAAO;AAEtC,MAAI,eAA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AAM,iBACX,CAAC,cAAsB,OAAO,IAAY,MAA6C,YACrF,kBAAkB,WAAW,IAAI,MAAM,OAAO;AAoC3C,IAAM,mBACX,CAAC,cAAsB,OAAO,IAAY,QAA8C,YAAqB;AAC3G,QAAM,eAAe,SAAS,EAAE,IAAI,EAAE,SAAS,OAAO,QAAQ,UAAU,OAAO,SAAS,GAAG,OAAO;AACpG;AAkBK,IAAM,kBAAkB,CAAC,cAAsB,OAAO,IAAY,YAAoB;AAC3F,QAAM,OAAO,MAAM,aAAa,WAAW,IAAI,OAAO;AACtD,SAAO,CAAC,CAAC;AACX;","names":["fs","join","match","join","matter","fs","file","join","join","join","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/events.ts","../src/internal/utils.ts","../src/internal/resources.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { findFileById } from './internal/utils';\nimport type { Event } from './types';\nimport {\n addFileToResource,\n getResource,\n getResources,\n rmResourceById,\n versionResource,\n writeResource,\n} 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 * Returns all events from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the events.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getEvents } = utils('/path/to/eventcatalog');\n *\n * // Gets all events (and versions) from the catalog\n * const events = await getEvents();\n *\n * // Gets all events (only latest version) from the catalog\n * const events = await getEvents({ latestOnly: true });\n * ```\n */\nexport const getEvents =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Event[]> =>\n getResources(directory, { type: 'events', ...options }) 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 * // Write a event to the catalog and override the existing content (if there is any)\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 * }, { override: true });\n *\n * // Write a event to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\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 * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeEvent =\n (directory: string) =>\n async (\n event: Event,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean } = { path: '', override: false }\n ) =>\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, ignore: string = '') => {\n try {\n const files = await glob(pattern, { ignore: ['node_modules/**', ignore] });\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, getFilesByType, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport { Message, Service } from '../types';\nimport { satisfies, validRange, valid } from 'semver';\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; override?: boolean; versionExistingContent?: boolean } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n }\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 && !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 // Should we version the existing content?\n if (options.versionExistingContent) {\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 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 getResources = async (\n catalogDir: string,\n { type, latestOnly = false }: { type: string; latestOnly?: boolean }\n): Promise<Resource[] | undefined> => {\n const ignore = latestOnly ? `**/versioned/**` : '';\n const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, ignore);\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (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"],"mappings":";AAAA,OAAOA,SAAQ;AACf,SAAS,QAAAC,aAAY;;;ACDrB,SAAS,YAAY;AACrB,OAAO,QAAQ;AACf,SAAS,YAA6C;AACtD,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,SAAS,WAAW,YAAY,aAAa;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,YAAo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AM,QAAQ,CAAC;AAChE;AAoBO,IAAM,eAAe,CAAC,cAAsB,OAAO,OAAe,gBAAgB,WAAW,EAAE;AAqB/F,IAAM,iBACX,CAAC,cAAsB,OAAO,IAAY,MAA6C,YACrF,kBAAkB,WAAW,IAAI,MAAM,OAAO;AAoC3C,IAAM,mBACX,CAAC,cAAsB,OAAO,IAAY,QAA8C,YAAqB;AAC3G,QAAM,eAAe,SAAS,EAAE,IAAI,EAAE,SAAS,OAAO,QAAQ,UAAU,OAAO,SAAS,GAAG,OAAO;AACpG;AAkBK,IAAM,kBAAkB,CAAC,cAAsB,OAAO,IAAY,YAAoB;AAC3F,QAAM,OAAO,MAAM,aAAa,WAAW,IAAI,OAAO;AACtD,SAAO,CAAC,CAAC;AACX;","names":["fs","join","match","join","matter","fs","satisfies","file","join","join","join","fs"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -14,6 +14,14 @@ declare const _default: (path: string) => {
|
|
|
14
14
|
* @returns Event|Undefined
|
|
15
15
|
*/
|
|
16
16
|
getEvent: (id: string, version?: string) => Promise<Event>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns all events from EventCatalog
|
|
19
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
20
|
+
* @returns Event[]|Undefined
|
|
21
|
+
*/
|
|
22
|
+
getEvents: (options?: {
|
|
23
|
+
latestOnly?: boolean;
|
|
24
|
+
}) => Promise<Event[]>;
|
|
17
25
|
/**
|
|
18
26
|
* Adds an event to EventCatalog
|
|
19
27
|
*
|
|
@@ -24,6 +32,7 @@ declare const _default: (path: string) => {
|
|
|
24
32
|
writeEvent: (event: Event, options?: {
|
|
25
33
|
path?: string;
|
|
26
34
|
override?: boolean;
|
|
35
|
+
versionExistingContent?: boolean;
|
|
27
36
|
}) => Promise<void>;
|
|
28
37
|
/**
|
|
29
38
|
* Adds an event to a service in EventCatalog
|
|
@@ -99,6 +108,14 @@ declare const _default: (path: string) => {
|
|
|
99
108
|
* @returns Command|Undefined
|
|
100
109
|
*/
|
|
101
110
|
getCommand: (id: string, version?: string) => Promise<Command>;
|
|
111
|
+
/**
|
|
112
|
+
* Returns all commands from EventCatalog
|
|
113
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
114
|
+
* @returns Command[]|Undefined
|
|
115
|
+
*/
|
|
116
|
+
getCommands: (options: {
|
|
117
|
+
latestOnly?: boolean;
|
|
118
|
+
}) => Promise<Command[]>;
|
|
102
119
|
/**
|
|
103
120
|
* Adds an command to EventCatalog
|
|
104
121
|
*
|
|
@@ -109,6 +126,7 @@ declare const _default: (path: string) => {
|
|
|
109
126
|
writeCommand: (command: Command, options?: {
|
|
110
127
|
path?: string;
|
|
111
128
|
override?: boolean;
|
|
129
|
+
versionExistingContent?: boolean;
|
|
112
130
|
}) => Promise<void>;
|
|
113
131
|
/**
|
|
114
132
|
* Adds a command to a service in EventCatalog
|
|
@@ -184,6 +202,14 @@ declare const _default: (path: string) => {
|
|
|
184
202
|
* @returns Query|Undefined
|
|
185
203
|
*/
|
|
186
204
|
getQuery: (id: string, version?: string) => Promise<Query>;
|
|
205
|
+
/**
|
|
206
|
+
* Returns all queries from EventCatalog
|
|
207
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
208
|
+
* @returns Query[]|Undefined
|
|
209
|
+
*/
|
|
210
|
+
getQueries: (options: {
|
|
211
|
+
latestOnly?: boolean;
|
|
212
|
+
}) => Promise<Query[]>;
|
|
187
213
|
/**
|
|
188
214
|
* Adds a query to EventCatalog
|
|
189
215
|
*
|
|
@@ -194,6 +220,7 @@ declare const _default: (path: string) => {
|
|
|
194
220
|
writeQuery: (query: Query, options?: {
|
|
195
221
|
path?: string;
|
|
196
222
|
override?: boolean;
|
|
223
|
+
versionExistingContent?: boolean;
|
|
197
224
|
}) => Promise<void>;
|
|
198
225
|
/**
|
|
199
226
|
* Adds a query to a service in EventCatalog
|
|
@@ -269,6 +296,14 @@ declare const _default: (path: string) => {
|
|
|
269
296
|
* @returns Channel|Undefined
|
|
270
297
|
*/
|
|
271
298
|
getChannel: (id: string, version?: string) => Promise<Channel>;
|
|
299
|
+
/**
|
|
300
|
+
* Returns all channels from EventCatalog
|
|
301
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
302
|
+
* @returns Channel[]|Undefined
|
|
303
|
+
*/
|
|
304
|
+
getChannels: (options?: {
|
|
305
|
+
latestOnly?: boolean;
|
|
306
|
+
}) => Promise<Channel[]>;
|
|
272
307
|
/**
|
|
273
308
|
* Adds an channel to EventCatalog
|
|
274
309
|
*
|
|
@@ -279,6 +314,7 @@ declare const _default: (path: string) => {
|
|
|
279
314
|
writeChannel: (channel: Channel, options?: {
|
|
280
315
|
path?: string;
|
|
281
316
|
override?: boolean;
|
|
317
|
+
versionExistingContent?: boolean;
|
|
282
318
|
}) => Promise<void>;
|
|
283
319
|
/**
|
|
284
320
|
* Remove an channel to EventCatalog (modeled on the standard POSIX rm utility)
|
|
@@ -390,6 +426,7 @@ declare const _default: (path: string) => {
|
|
|
390
426
|
writeService: (service: Service, options?: {
|
|
391
427
|
path?: string;
|
|
392
428
|
override?: boolean;
|
|
429
|
+
versionExistingContent?: boolean;
|
|
393
430
|
}) => Promise<void>;
|
|
394
431
|
/**
|
|
395
432
|
* Adds a versioned service to EventCatalog
|
|
@@ -420,6 +457,18 @@ declare const _default: (path: string) => {
|
|
|
420
457
|
* @returns Service|Undefined
|
|
421
458
|
*/
|
|
422
459
|
getService: (id: string, version?: string) => Promise<Service>;
|
|
460
|
+
/**
|
|
461
|
+
* Returns all services from EventCatalog
|
|
462
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
463
|
+
* @returns Service[]|Undefined
|
|
464
|
+
*/
|
|
465
|
+
getServices: (options?: {
|
|
466
|
+
latestOnly? /**
|
|
467
|
+
* Returns all events from EventCatalog
|
|
468
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
469
|
+
* @returns Event[]|Undefined
|
|
470
|
+
*/: boolean;
|
|
471
|
+
}) => Promise<Service[]>;
|
|
423
472
|
/**
|
|
424
473
|
* Moves a given service id to the version directory
|
|
425
474
|
* @param directory
|
|
@@ -548,6 +597,7 @@ declare const _default: (path: string) => {
|
|
|
548
597
|
writeDomain: (domain: Domain, options?: {
|
|
549
598
|
path?: string;
|
|
550
599
|
override?: boolean;
|
|
600
|
+
versionExistingContent?: boolean;
|
|
551
601
|
}) => Promise<void>;
|
|
552
602
|
/**
|
|
553
603
|
* Returns a domain from EventCatalog
|
|
@@ -556,6 +606,14 @@ declare const _default: (path: string) => {
|
|
|
556
606
|
* @returns Domain|Undefined
|
|
557
607
|
*/
|
|
558
608
|
getDomain: (id: string, version?: string) => Promise<Domain>;
|
|
609
|
+
/**
|
|
610
|
+
* Returns all domains from EventCatalog
|
|
611
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
612
|
+
* @returns Domain[]|Undefined
|
|
613
|
+
*/
|
|
614
|
+
getDomains: (options?: {
|
|
615
|
+
latestOnly?: boolean;
|
|
616
|
+
}) => Promise<Domain[]>;
|
|
559
617
|
/**
|
|
560
618
|
* Moves a given domain id to the version directory
|
|
561
619
|
* @param directory
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ declare const _default: (path: string) => {
|
|
|
14
14
|
* @returns Event|Undefined
|
|
15
15
|
*/
|
|
16
16
|
getEvent: (id: string, version?: string) => Promise<Event>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns all events from EventCatalog
|
|
19
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
20
|
+
* @returns Event[]|Undefined
|
|
21
|
+
*/
|
|
22
|
+
getEvents: (options?: {
|
|
23
|
+
latestOnly?: boolean;
|
|
24
|
+
}) => Promise<Event[]>;
|
|
17
25
|
/**
|
|
18
26
|
* Adds an event to EventCatalog
|
|
19
27
|
*
|
|
@@ -24,6 +32,7 @@ declare const _default: (path: string) => {
|
|
|
24
32
|
writeEvent: (event: Event, options?: {
|
|
25
33
|
path?: string;
|
|
26
34
|
override?: boolean;
|
|
35
|
+
versionExistingContent?: boolean;
|
|
27
36
|
}) => Promise<void>;
|
|
28
37
|
/**
|
|
29
38
|
* Adds an event to a service in EventCatalog
|
|
@@ -99,6 +108,14 @@ declare const _default: (path: string) => {
|
|
|
99
108
|
* @returns Command|Undefined
|
|
100
109
|
*/
|
|
101
110
|
getCommand: (id: string, version?: string) => Promise<Command>;
|
|
111
|
+
/**
|
|
112
|
+
* Returns all commands from EventCatalog
|
|
113
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
114
|
+
* @returns Command[]|Undefined
|
|
115
|
+
*/
|
|
116
|
+
getCommands: (options: {
|
|
117
|
+
latestOnly?: boolean;
|
|
118
|
+
}) => Promise<Command[]>;
|
|
102
119
|
/**
|
|
103
120
|
* Adds an command to EventCatalog
|
|
104
121
|
*
|
|
@@ -109,6 +126,7 @@ declare const _default: (path: string) => {
|
|
|
109
126
|
writeCommand: (command: Command, options?: {
|
|
110
127
|
path?: string;
|
|
111
128
|
override?: boolean;
|
|
129
|
+
versionExistingContent?: boolean;
|
|
112
130
|
}) => Promise<void>;
|
|
113
131
|
/**
|
|
114
132
|
* Adds a command to a service in EventCatalog
|
|
@@ -184,6 +202,14 @@ declare const _default: (path: string) => {
|
|
|
184
202
|
* @returns Query|Undefined
|
|
185
203
|
*/
|
|
186
204
|
getQuery: (id: string, version?: string) => Promise<Query>;
|
|
205
|
+
/**
|
|
206
|
+
* Returns all queries from EventCatalog
|
|
207
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
208
|
+
* @returns Query[]|Undefined
|
|
209
|
+
*/
|
|
210
|
+
getQueries: (options: {
|
|
211
|
+
latestOnly?: boolean;
|
|
212
|
+
}) => Promise<Query[]>;
|
|
187
213
|
/**
|
|
188
214
|
* Adds a query to EventCatalog
|
|
189
215
|
*
|
|
@@ -194,6 +220,7 @@ declare const _default: (path: string) => {
|
|
|
194
220
|
writeQuery: (query: Query, options?: {
|
|
195
221
|
path?: string;
|
|
196
222
|
override?: boolean;
|
|
223
|
+
versionExistingContent?: boolean;
|
|
197
224
|
}) => Promise<void>;
|
|
198
225
|
/**
|
|
199
226
|
* Adds a query to a service in EventCatalog
|
|
@@ -269,6 +296,14 @@ declare const _default: (path: string) => {
|
|
|
269
296
|
* @returns Channel|Undefined
|
|
270
297
|
*/
|
|
271
298
|
getChannel: (id: string, version?: string) => Promise<Channel>;
|
|
299
|
+
/**
|
|
300
|
+
* Returns all channels from EventCatalog
|
|
301
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
302
|
+
* @returns Channel[]|Undefined
|
|
303
|
+
*/
|
|
304
|
+
getChannels: (options?: {
|
|
305
|
+
latestOnly?: boolean;
|
|
306
|
+
}) => Promise<Channel[]>;
|
|
272
307
|
/**
|
|
273
308
|
* Adds an channel to EventCatalog
|
|
274
309
|
*
|
|
@@ -279,6 +314,7 @@ declare const _default: (path: string) => {
|
|
|
279
314
|
writeChannel: (channel: Channel, options?: {
|
|
280
315
|
path?: string;
|
|
281
316
|
override?: boolean;
|
|
317
|
+
versionExistingContent?: boolean;
|
|
282
318
|
}) => Promise<void>;
|
|
283
319
|
/**
|
|
284
320
|
* Remove an channel to EventCatalog (modeled on the standard POSIX rm utility)
|
|
@@ -390,6 +426,7 @@ declare const _default: (path: string) => {
|
|
|
390
426
|
writeService: (service: Service, options?: {
|
|
391
427
|
path?: string;
|
|
392
428
|
override?: boolean;
|
|
429
|
+
versionExistingContent?: boolean;
|
|
393
430
|
}) => Promise<void>;
|
|
394
431
|
/**
|
|
395
432
|
* Adds a versioned service to EventCatalog
|
|
@@ -420,6 +457,18 @@ declare const _default: (path: string) => {
|
|
|
420
457
|
* @returns Service|Undefined
|
|
421
458
|
*/
|
|
422
459
|
getService: (id: string, version?: string) => Promise<Service>;
|
|
460
|
+
/**
|
|
461
|
+
* Returns all services from EventCatalog
|
|
462
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
463
|
+
* @returns Service[]|Undefined
|
|
464
|
+
*/
|
|
465
|
+
getServices: (options?: {
|
|
466
|
+
latestOnly? /**
|
|
467
|
+
* Returns all events from EventCatalog
|
|
468
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
469
|
+
* @returns Event[]|Undefined
|
|
470
|
+
*/: boolean;
|
|
471
|
+
}) => Promise<Service[]>;
|
|
423
472
|
/**
|
|
424
473
|
* Moves a given service id to the version directory
|
|
425
474
|
* @param directory
|
|
@@ -548,6 +597,7 @@ declare const _default: (path: string) => {
|
|
|
548
597
|
writeDomain: (domain: Domain, options?: {
|
|
549
598
|
path?: string;
|
|
550
599
|
override?: boolean;
|
|
600
|
+
versionExistingContent?: boolean;
|
|
551
601
|
}) => Promise<void>;
|
|
552
602
|
/**
|
|
553
603
|
* Returns a domain from EventCatalog
|
|
@@ -556,6 +606,14 @@ declare const _default: (path: string) => {
|
|
|
556
606
|
* @returns Domain|Undefined
|
|
557
607
|
*/
|
|
558
608
|
getDomain: (id: string, version?: string) => Promise<Domain>;
|
|
609
|
+
/**
|
|
610
|
+
* Returns all domains from EventCatalog
|
|
611
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
612
|
+
* @returns Domain[]|Undefined
|
|
613
|
+
*/
|
|
614
|
+
getDomains: (options?: {
|
|
615
|
+
latestOnly?: boolean;
|
|
616
|
+
}) => Promise<Domain[]>;
|
|
559
617
|
/**
|
|
560
618
|
* Moves a given domain id to the version directory
|
|
561
619
|
* @param directory
|
package/dist/index.js
CHANGED
|
@@ -75,9 +75,9 @@ var findFileById = async (catalogDir, id, version) => {
|
|
|
75
75
|
return match[0].path;
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
var getFiles = async (pattern) => {
|
|
78
|
+
var getFiles = async (pattern, ignore = "") => {
|
|
79
79
|
try {
|
|
80
|
-
const files = await (0, import_glob.glob)(pattern, { ignore: "node_modules/**" });
|
|
80
|
+
const files = await (0, import_glob.glob)(pattern, { ignore: ["node_modules/**", ignore] });
|
|
81
81
|
return files;
|
|
82
82
|
} catch (error) {
|
|
83
83
|
throw new Error(`Error finding files: ${error}`);
|
|
@@ -129,6 +129,7 @@ var uniqueVersions = (messages) => {
|
|
|
129
129
|
var import_path = require("path");
|
|
130
130
|
var import_gray_matter2 = __toESM(require("gray-matter"));
|
|
131
131
|
var import_promises2 = __toESM(require("fs/promises"));
|
|
132
|
+
var import_semver2 = require("semver");
|
|
132
133
|
var versionResource = async (catalogDir, id) => {
|
|
133
134
|
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
134
135
|
const matchedFiles = await searchFilesForId(files, id);
|
|
@@ -153,13 +154,28 @@ var versionResource = async (catalogDir, id) => {
|
|
|
153
154
|
);
|
|
154
155
|
});
|
|
155
156
|
};
|
|
156
|
-
var writeResource = async (catalogDir, resource, options = {
|
|
157
|
+
var writeResource = async (catalogDir, resource, options = {
|
|
158
|
+
path: "",
|
|
159
|
+
type: "",
|
|
160
|
+
override: false,
|
|
161
|
+
versionExistingContent: false
|
|
162
|
+
}) => {
|
|
157
163
|
const path = options.path || `/${resource.id}`;
|
|
158
164
|
const exists = await versionExists(catalogDir, resource.id, resource.version);
|
|
159
165
|
if (exists && !options.override) {
|
|
160
166
|
throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
|
|
161
167
|
}
|
|
162
168
|
const { markdown, ...frontmatter } = resource;
|
|
169
|
+
if (options.versionExistingContent) {
|
|
170
|
+
const currentResource = await getResource(catalogDir, resource.id);
|
|
171
|
+
if (currentResource) {
|
|
172
|
+
if ((0, import_semver2.satisfies)(resource.version, `>${currentResource.version}`)) {
|
|
173
|
+
await versionResource(catalogDir, resource.id);
|
|
174
|
+
} else {
|
|
175
|
+
throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
163
179
|
const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
|
|
164
180
|
await import_promises2.default.mkdir((0, import_path.join)(catalogDir, path), { recursive: true });
|
|
165
181
|
await import_promises2.default.writeFile((0, import_path.join)(catalogDir, path, "index.md"), document);
|
|
@@ -173,6 +189,18 @@ var getResource = async (catalogDir, id, version, options) => {
|
|
|
173
189
|
markdown: content.trim()
|
|
174
190
|
};
|
|
175
191
|
};
|
|
192
|
+
var getResources = async (catalogDir, { type, latestOnly = false }) => {
|
|
193
|
+
const ignore = latestOnly ? `**/versioned/**` : "";
|
|
194
|
+
const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, ignore);
|
|
195
|
+
if (files.length === 0) return;
|
|
196
|
+
return files.map((file) => {
|
|
197
|
+
const { data, content } = import_gray_matter2.default.read(file);
|
|
198
|
+
return {
|
|
199
|
+
...data,
|
|
200
|
+
markdown: content.trim()
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
};
|
|
176
204
|
var rmResourceById = async (catalogDir, id, version, options) => {
|
|
177
205
|
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
178
206
|
const matchedFiles = await searchFilesForId(files, id, version);
|
|
@@ -199,6 +227,7 @@ var getVersionedDirectory = (sourceDirectory, version) => {
|
|
|
199
227
|
|
|
200
228
|
// src/events.ts
|
|
201
229
|
var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
|
|
230
|
+
var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
|
|
202
231
|
var writeEvent = (directory) => async (event, options = { path: "", override: false }) => writeResource(directory, { ...event }, { ...options, type: "event" });
|
|
203
232
|
var writeEventToService = (directory) => async (event, service, options = { path: "" }) => {
|
|
204
233
|
let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/events` : `/${service.id}/events`;
|
|
@@ -225,6 +254,7 @@ var eventHasVersion = (directory) => async (id, version) => {
|
|
|
225
254
|
var import_promises4 = __toESM(require("fs/promises"));
|
|
226
255
|
var import_node_path3 = require("path");
|
|
227
256
|
var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
|
|
257
|
+
var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
|
|
228
258
|
var writeCommand = (directory) => async (command, options = { path: "" }) => writeResource(directory, { ...command }, { ...options, type: "command" });
|
|
229
259
|
var writeCommandToService = (directory) => async (command, service, options = { path: "" }) => {
|
|
230
260
|
let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/commands` : `/${service.id}/commands`;
|
|
@@ -250,6 +280,7 @@ var import_promises5 = __toESM(require("fs/promises"));
|
|
|
250
280
|
var import_node_path4 = require("path");
|
|
251
281
|
var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
|
|
252
282
|
var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
|
|
283
|
+
var getQueries = (directory) => async (options) => getResources(directory, { type: "queries", ...options });
|
|
253
284
|
var writeQueryToService = (directory) => async (query, service, options = { path: "" }) => {
|
|
254
285
|
let pathForQuery = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/queries` : `/${service.id}/queries`;
|
|
255
286
|
pathForQuery = (0, import_node_path4.join)(pathForQuery, query.id);
|
|
@@ -275,6 +306,7 @@ var queryHasVersion = (directory) => async (id, version) => {
|
|
|
275
306
|
var import_promises6 = __toESM(require("fs/promises"));
|
|
276
307
|
var import_node_path5 = require("path");
|
|
277
308
|
var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
|
|
309
|
+
var getServices = (directory) => async (options) => getResources(directory, { type: "services", ...options });
|
|
278
310
|
var writeService = (directory) => async (service, options = { path: "" }) => {
|
|
279
311
|
const resource = { ...service };
|
|
280
312
|
if (Array.isArray(service.sends)) {
|
|
@@ -358,6 +390,7 @@ var serviceHasVersion = (directory) => async (id, version) => {
|
|
|
358
390
|
var import_promises7 = __toESM(require("fs/promises"));
|
|
359
391
|
var import_node_path6 = require("path");
|
|
360
392
|
var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
|
|
393
|
+
var getDomains = (directory) => async (options) => getResources(directory, { type: "domains", ...options });
|
|
361
394
|
var writeDomain = (directory) => async (domain, options = { path: "" }) => {
|
|
362
395
|
const resource = { ...domain };
|
|
363
396
|
if (Array.isArray(domain.services)) {
|
|
@@ -393,6 +426,7 @@ var addServiceToDomain = (directory) => async (id, service, version) => {
|
|
|
393
426
|
var import_promises8 = __toESM(require("fs/promises"));
|
|
394
427
|
var import_node_path7 = require("path");
|
|
395
428
|
var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
|
|
429
|
+
var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
|
|
396
430
|
var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
|
|
397
431
|
var rmChannel = (directory) => async (path) => {
|
|
398
432
|
await import_promises8.default.rm((0, import_node_path7.join)(directory, path), { recursive: true });
|
|
@@ -444,6 +478,12 @@ var src_default = (path) => {
|
|
|
444
478
|
* @returns Event|Undefined
|
|
445
479
|
*/
|
|
446
480
|
getEvent: getEvent((0, import_node_path8.join)(path)),
|
|
481
|
+
/**
|
|
482
|
+
* Returns all events from EventCatalog
|
|
483
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
484
|
+
* @returns Event[]|Undefined
|
|
485
|
+
*/
|
|
486
|
+
getEvents: getEvents((0, import_node_path8.join)(path)),
|
|
447
487
|
/**
|
|
448
488
|
* Adds an event to EventCatalog
|
|
449
489
|
*
|
|
@@ -515,6 +555,12 @@ var src_default = (path) => {
|
|
|
515
555
|
* @returns Command|Undefined
|
|
516
556
|
*/
|
|
517
557
|
getCommand: getCommand((0, import_node_path8.join)(path)),
|
|
558
|
+
/**
|
|
559
|
+
* Returns all commands from EventCatalog
|
|
560
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
561
|
+
* @returns Command[]|Undefined
|
|
562
|
+
*/
|
|
563
|
+
getCommands: getCommands((0, import_node_path8.join)(path)),
|
|
518
564
|
/**
|
|
519
565
|
* Adds an command to EventCatalog
|
|
520
566
|
*
|
|
@@ -586,6 +632,12 @@ var src_default = (path) => {
|
|
|
586
632
|
* @returns Query|Undefined
|
|
587
633
|
*/
|
|
588
634
|
getQuery: getQuery((0, import_node_path8.join)(path)),
|
|
635
|
+
/**
|
|
636
|
+
* Returns all queries from EventCatalog
|
|
637
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
638
|
+
* @returns Query[]|Undefined
|
|
639
|
+
*/
|
|
640
|
+
getQueries: getQueries((0, import_node_path8.join)(path)),
|
|
589
641
|
/**
|
|
590
642
|
* Adds a query to EventCatalog
|
|
591
643
|
*
|
|
@@ -657,6 +709,12 @@ var src_default = (path) => {
|
|
|
657
709
|
* @returns Channel|Undefined
|
|
658
710
|
*/
|
|
659
711
|
getChannel: getChannel((0, import_node_path8.join)(path)),
|
|
712
|
+
/**
|
|
713
|
+
* Returns all channels from EventCatalog
|
|
714
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
715
|
+
* @returns Channel[]|Undefined
|
|
716
|
+
*/
|
|
717
|
+
getChannels: getChannels((0, import_node_path8.join)(path)),
|
|
660
718
|
/**
|
|
661
719
|
* Adds an channel to EventCatalog
|
|
662
720
|
*
|
|
@@ -778,6 +836,12 @@ var src_default = (path) => {
|
|
|
778
836
|
* @returns Service|Undefined
|
|
779
837
|
*/
|
|
780
838
|
getService: getService((0, import_node_path8.join)(path)),
|
|
839
|
+
/**
|
|
840
|
+
* Returns all services from EventCatalog
|
|
841
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
842
|
+
* @returns Service[]|Undefined
|
|
843
|
+
*/
|
|
844
|
+
getServices: getServices((0, import_node_path8.join)(path)),
|
|
781
845
|
/**
|
|
782
846
|
* Moves a given service id to the version directory
|
|
783
847
|
* @param directory
|
|
@@ -899,6 +963,12 @@ var src_default = (path) => {
|
|
|
899
963
|
* @returns Domain|Undefined
|
|
900
964
|
*/
|
|
901
965
|
getDomain: getDomain((0, import_node_path8.join)(path, "domains")),
|
|
966
|
+
/**
|
|
967
|
+
* Returns all domains from EventCatalog
|
|
968
|
+
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
969
|
+
* @returns Domain[]|Undefined
|
|
970
|
+
*/
|
|
971
|
+
getDomains: getDomains((0, import_node_path8.join)(path)),
|
|
902
972
|
/**
|
|
903
973
|
* Moves a given domain id to the version directory
|
|
904
974
|
* @param directory
|