@eventcatalog/sdk 2.11.0 → 2.12.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/README.md +86 -1
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/{eventcatalog.js → cli/index.js} +505 -378
- package/dist/cli/index.js.map +1 -0
- package/dist/{eventcatalog.mjs → cli/index.mjs} +583 -436
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cli-docs.d.mts +43 -0
- package/dist/cli-docs.d.ts +43 -0
- package/dist/cli-docs.js +1513 -0
- package/dist/cli-docs.js.map +1 -0
- package/dist/cli-docs.mjs +1485 -0
- package/dist/cli-docs.mjs.map +1 -0
- package/dist/index.d.mts +330 -3
- package/dist/index.d.ts +330 -3
- package/package.json +13 -4
- package/dist/channels.d.mts +0 -214
- package/dist/channels.d.ts +0 -214
- package/dist/channels.js +0 -432
- package/dist/channels.js.map +0 -1
- package/dist/channels.mjs +0 -384
- package/dist/channels.mjs.map +0 -1
- package/dist/commands.d.mts +0 -274
- package/dist/commands.d.ts +0 -274
- package/dist/commands.js +0 -394
- package/dist/commands.js.map +0 -1
- package/dist/commands.mjs +0 -350
- package/dist/commands.mjs.map +0 -1
- package/dist/containers.d.mts +0 -179
- package/dist/containers.d.ts +0 -179
- package/dist/containers.js +0 -388
- package/dist/containers.js.map +0 -1
- package/dist/containers.mjs +0 -345
- package/dist/containers.mjs.map +0 -1
- package/dist/custom-docs.d.mts +0 -89
- package/dist/custom-docs.d.ts +0 -89
- package/dist/custom-docs.js +0 -164
- package/dist/custom-docs.js.map +0 -1
- package/dist/custom-docs.mjs +0 -122
- package/dist/custom-docs.mjs.map +0 -1
- package/dist/data-products.d.mts +0 -225
- package/dist/data-products.d.ts +0 -225
- package/dist/data-products.js +0 -375
- package/dist/data-products.js.map +0 -1
- package/dist/data-products.mjs +0 -332
- package/dist/data-products.mjs.map +0 -1
- package/dist/data-stores.d.mts +0 -179
- package/dist/data-stores.d.ts +0 -179
- package/dist/data-stores.js +0 -401
- package/dist/data-stores.js.map +0 -1
- package/dist/data-stores.mjs +0 -356
- package/dist/data-stores.mjs.map +0 -1
- package/dist/domains.d.mts +0 -347
- package/dist/domains.d.ts +0 -347
- package/dist/domains.js +0 -547
- package/dist/domains.js.map +0 -1
- package/dist/domains.mjs +0 -498
- package/dist/domains.mjs.map +0 -1
- package/dist/entities.d.mts +0 -174
- package/dist/entities.d.ts +0 -174
- package/dist/entities.js +0 -348
- package/dist/entities.js.map +0 -1
- package/dist/entities.mjs +0 -307
- package/dist/entities.mjs.map +0 -1
- package/dist/eventcatalog.d.mts +0 -21
- package/dist/eventcatalog.d.ts +0 -21
- package/dist/eventcatalog.js.map +0 -1
- package/dist/eventcatalog.mjs.map +0 -1
- package/dist/events.d.mts +0 -276
- package/dist/events.d.ts +0 -276
- package/dist/events.js +0 -393
- package/dist/events.js.map +0 -1
- package/dist/events.mjs +0 -349
- package/dist/events.mjs.map +0 -1
- package/dist/messages.d.mts +0 -65
- package/dist/messages.d.ts +0 -65
- package/dist/messages.js +0 -312
- package/dist/messages.js.map +0 -1
- package/dist/messages.mjs +0 -269
- package/dist/messages.mjs.map +0 -1
- package/dist/queries.d.mts +0 -276
- package/dist/queries.d.ts +0 -276
- package/dist/queries.js +0 -394
- package/dist/queries.js.map +0 -1
- package/dist/queries.mjs +0 -350
- package/dist/queries.mjs.map +0 -1
- package/dist/services.d.mts +0 -384
- package/dist/services.d.ts +0 -384
- package/dist/services.js +0 -577
- package/dist/services.js.map +0 -1
- package/dist/services.mjs +0 -526
- package/dist/services.mjs.map +0 -1
- package/dist/teams.d.mts +0 -90
- package/dist/teams.d.ts +0 -90
- package/dist/teams.js +0 -246
- package/dist/teams.js.map +0 -1
- package/dist/teams.mjs +0 -202
- package/dist/teams.mjs.map +0 -1
- package/dist/types.d.d.mts +0 -331
- package/dist/types.d.d.ts +0 -331
- package/dist/types.d.js +0 -19
- package/dist/types.d.js.map +0 -1
- package/dist/types.d.mjs +0 -1
- package/dist/types.d.mjs.map +0 -1
- package/dist/users.d.mts +0 -83
- package/dist/users.d.ts +0 -83
- package/dist/users.js +0 -127
- package/dist/users.js.map +0 -1
- package/dist/users.mjs +0 -88
- package/dist/users.mjs.map +0 -1
package/dist/channels.d.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { Channel } from './types.d.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns a channel from EventCatalog.
|
|
5
|
-
*
|
|
6
|
-
* You can optionally specify a version to get a specific version of the channel
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import utils from '@eventcatalog/utils';
|
|
11
|
-
*
|
|
12
|
-
* const { getChannel } = utils('/path/to/eventcatalog');
|
|
13
|
-
*
|
|
14
|
-
* // Gets the latest version of the channel
|
|
15
|
-
* const channel = await getChannel('InventoryChannel');
|
|
16
|
-
*
|
|
17
|
-
* // Gets a version of the channel
|
|
18
|
-
* const channel = await getChannel('InventoryChannel', '0.0.1');
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare const getChannel: (directory: string) => (id: string, version?: string) => Promise<Channel>;
|
|
22
|
-
/**
|
|
23
|
-
* Returns all channels from EventCatalog.
|
|
24
|
-
*
|
|
25
|
-
* You can optionally specify if you want to get the latest version of the channels.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* import utils from '@eventcatalog/utils';
|
|
30
|
-
*
|
|
31
|
-
* const { getChannels } = utils('/path/to/eventcatalog');
|
|
32
|
-
*
|
|
33
|
-
* // Gets all channels (and versions) from the catalog
|
|
34
|
-
* const channels = await getChannels();
|
|
35
|
-
*
|
|
36
|
-
* // Gets all channels (only latest version) from the catalog
|
|
37
|
-
* const channels = await getChannels({ latestOnly: true });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare const getChannels: (directory: string) => (options?: {
|
|
41
|
-
latestOnly?: boolean;
|
|
42
|
-
}) => Promise<Channel[]>;
|
|
43
|
-
/**
|
|
44
|
-
* Write a channel to EventCatalog.
|
|
45
|
-
*
|
|
46
|
-
* You can optionally override the path of the channel.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* import utils from '@eventcatalog/utils';
|
|
51
|
-
*
|
|
52
|
-
* const { writeChannel } = utils('/path/to/eventcatalog');
|
|
53
|
-
*
|
|
54
|
-
* // Write a channel to the catalog
|
|
55
|
-
* // channel would be written to channels/inventory.{env}.events
|
|
56
|
-
* await writeChannel({
|
|
57
|
-
* id: 'inventory.{env}.events',
|
|
58
|
-
* name: 'Inventory channel',
|
|
59
|
-
* version: '0.0.1',
|
|
60
|
-
* summary: 'This is a summary',
|
|
61
|
-
* markdown: '# Hello world',
|
|
62
|
-
* address: inventory.{env}.events,
|
|
63
|
-
* protocols: ['http'],
|
|
64
|
-
* });
|
|
65
|
-
*
|
|
66
|
-
* // Write a channel to the catalog but override the path
|
|
67
|
-
* // channel would be written to channels/Inventory/InventoryChannel
|
|
68
|
-
* await writeChannel({
|
|
69
|
-
* id: 'InventoryChannel',
|
|
70
|
-
* name: 'Update Inventory',
|
|
71
|
-
* version: '0.0.1',
|
|
72
|
-
* summary: 'This is a summary',
|
|
73
|
-
* markdown: '# Hello world',
|
|
74
|
-
* address: inventory.{env}.events,
|
|
75
|
-
* protocols: ['http'],
|
|
76
|
-
* }, { path: "/channels/Inventory/InventoryChannel"});
|
|
77
|
-
*
|
|
78
|
-
* // Write a channel to the catalog and override the existing content (if there is any)
|
|
79
|
-
* await writeChannel({
|
|
80
|
-
* id: 'InventoryChannel',
|
|
81
|
-
* name: 'Update Inventory',
|
|
82
|
-
* version: '0.0.1',
|
|
83
|
-
* summary: 'This is a summary',
|
|
84
|
-
* markdown: '# Hello world',
|
|
85
|
-
* address: inventory.{env}.events,
|
|
86
|
-
* protocols: ['http'],
|
|
87
|
-
* }, { override: true });
|
|
88
|
-
*
|
|
89
|
-
* // Write a channel to the catalog and version the previous version
|
|
90
|
-
* // only works if the new version is greater than the previous version
|
|
91
|
-
* await writeChannel({
|
|
92
|
-
* id: 'InventoryChannel',
|
|
93
|
-
* name: 'Update Inventory',
|
|
94
|
-
* version: '0.0.1',
|
|
95
|
-
* summary: 'This is a summary',
|
|
96
|
-
* markdown: '# Hello world',
|
|
97
|
-
* address: inventory.{env}.events,
|
|
98
|
-
* protocols: ['http'],
|
|
99
|
-
* }, { versionExistingContent: true });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare const writeChannel: (directory: string) => (channel: Channel, options?: {
|
|
103
|
-
path?: string;
|
|
104
|
-
override?: boolean;
|
|
105
|
-
versionExistingContent?: boolean;
|
|
106
|
-
format?: "md" | "mdx";
|
|
107
|
-
}) => Promise<void>;
|
|
108
|
-
/**
|
|
109
|
-
* Delete a channel at it's given path.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* import utils from '@eventcatalog/utils';
|
|
114
|
-
*
|
|
115
|
-
* const { rmChannel } = utils('/path/to/eventcatalog');
|
|
116
|
-
*
|
|
117
|
-
* // removes a channel at the given path (channels dir is appended to the given path)
|
|
118
|
-
* // Removes the channel at channels/InventoryChannel
|
|
119
|
-
* await rmChannel('/InventoryChannel');
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
declare const rmChannel: (directory: string) => (path: string) => Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Delete a channel by it's id.
|
|
125
|
-
*
|
|
126
|
-
* Optionally specify a version to delete a specific version of the channel.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* import utils from '@eventcatalog/utils';
|
|
131
|
-
*
|
|
132
|
-
* const { rmChannelById } = utils('/path/to/eventcatalog');
|
|
133
|
-
*
|
|
134
|
-
* // deletes the latest InventoryChannel channel
|
|
135
|
-
* await rmChannelById('inventory.{env}.events');
|
|
136
|
-
*
|
|
137
|
-
* // deletes a specific version of the InventoryChannel channel
|
|
138
|
-
* await rmChannelById('inventory.{env}.events', '0.0.1');
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
declare const rmChannelById: (directory: string) => (id: string, version?: string, persistFiles?: boolean) => Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* Version a channel by it's id.
|
|
144
|
-
*
|
|
145
|
-
* Takes the latest channel and moves it to a versioned directory.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* import utils from '@eventcatalog/utils';
|
|
150
|
-
*
|
|
151
|
-
* const { versionChannel } = utils('/path/to/eventcatalog');
|
|
152
|
-
*
|
|
153
|
-
* // moves the latest inventory.{env}.events channel to a versioned directory
|
|
154
|
-
* // the version within that channel is used as the version number.
|
|
155
|
-
* await versionChannel('inventory.{env}.events');
|
|
156
|
-
*
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
declare const versionChannel: (directory: string) => (id: string) => Promise<void>;
|
|
160
|
-
/**
|
|
161
|
-
* Check to see if the catalog has a version for the given channel.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* import utils from '@eventcatalog/utils';
|
|
166
|
-
*
|
|
167
|
-
* const { channelHasVersion } = utils('/path/to/eventcatalog');
|
|
168
|
-
*
|
|
169
|
-
* // returns true if version is found for the given event and version (supports semver)
|
|
170
|
-
* await channelHasVersion('inventory.{env}.events', '0.0.1');
|
|
171
|
-
* await channelHasVersion('inventory.{env}.events', 'latest');
|
|
172
|
-
* await channelHasVersion('inventory.{env}.events', '0.0.x');*
|
|
173
|
-
*
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
declare const channelHasVersion: (directory: string) => (id: string, version?: string) => Promise<boolean>;
|
|
177
|
-
/**
|
|
178
|
-
* Add an event/command/query to a channel by it's id.
|
|
179
|
-
*
|
|
180
|
-
* Optionally specify a version to add the message to a specific version of the service.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* import utils from '@eventcatalog/utils';
|
|
185
|
-
*
|
|
186
|
-
* // Adds an event to the service or command to the service
|
|
187
|
-
* const { addEventToChannel, addCommandToChannel, addQueryToChannel } = utils('/path/to/eventcatalog');
|
|
188
|
-
*
|
|
189
|
-
* // Adds a new event (InventoryUpdatedEvent) that the InventoryService will send
|
|
190
|
-
* await addEventToChannel('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
|
|
191
|
-
* * // Adds a new event (OrderComplete) that the InventoryService will receive
|
|
192
|
-
* await addEventToChannel('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });
|
|
193
|
-
*
|
|
194
|
-
* // Adds a new command (UpdateInventoryCommand) that the InventoryService will send
|
|
195
|
-
* await addCommandToChannel('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });
|
|
196
|
-
* // Adds a new command (VerifyInventory) that the InventoryService will receive
|
|
197
|
-
* await addCommandToChannel('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });
|
|
198
|
-
*
|
|
199
|
-
* // Adds a new query (GetInventoryQuery) that the InventoryService will send
|
|
200
|
-
* await addQueryToChannel('InventoryService', 'sends', { query: 'GetInventoryQuery', version: '2.0.0' });
|
|
201
|
-
* // Adds a new query (GetOrder) that the InventoryService will receive
|
|
202
|
-
* await addQueryToChannel('InventoryService', 'receives', { query: 'GetOrder', version: '1.0.0' });
|
|
203
|
-
*
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
declare const addMessageToChannel: (directory: string, collection: string) => (id: string, _message: {
|
|
207
|
-
id: string;
|
|
208
|
-
version: string;
|
|
209
|
-
parameters?: {
|
|
210
|
-
[key: string]: string;
|
|
211
|
-
};
|
|
212
|
-
}, version?: string) => Promise<void>;
|
|
213
|
-
|
|
214
|
-
export { addMessageToChannel, channelHasVersion, getChannel, getChannels, rmChannel, rmChannelById, versionChannel, writeChannel };
|
package/dist/channels.js
DELETED
|
@@ -1,432 +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/channels.ts
|
|
31
|
-
var channels_exports = {};
|
|
32
|
-
__export(channels_exports, {
|
|
33
|
-
addMessageToChannel: () => addMessageToChannel,
|
|
34
|
-
channelHasVersion: () => channelHasVersion,
|
|
35
|
-
getChannel: () => getChannel,
|
|
36
|
-
getChannels: () => getChannels,
|
|
37
|
-
rmChannel: () => rmChannel,
|
|
38
|
-
rmChannelById: () => rmChannelById,
|
|
39
|
-
versionChannel: () => versionChannel,
|
|
40
|
-
writeChannel: () => writeChannel
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(channels_exports);
|
|
43
|
-
var import_promises5 = __toESM(require("fs/promises"));
|
|
44
|
-
var import_node_path7 = require("path");
|
|
45
|
-
|
|
46
|
-
// src/internal/resources.ts
|
|
47
|
-
var import_path = require("path");
|
|
48
|
-
|
|
49
|
-
// src/internal/utils.ts
|
|
50
|
-
var import_glob = require("glob");
|
|
51
|
-
var import_node_fs = __toESM(require("fs"));
|
|
52
|
-
var import_fs_extra = require("fs-extra");
|
|
53
|
-
var import_node_path = require("path");
|
|
54
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
55
|
-
var import_semver = require("semver");
|
|
56
|
-
var versionExists = async (catalogDir, id, version) => {
|
|
57
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
58
|
-
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
59
|
-
return matchedFiles.length > 0;
|
|
60
|
-
};
|
|
61
|
-
var findFileById = async (catalogDir, id, version) => {
|
|
62
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
63
|
-
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
64
|
-
const latestVersion = matchedFiles.find((path2) => !path2.includes("versioned"));
|
|
65
|
-
if (!version) {
|
|
66
|
-
return latestVersion;
|
|
67
|
-
}
|
|
68
|
-
const parsedFiles = matchedFiles.map((path2) => {
|
|
69
|
-
const { data } = import_gray_matter.default.read(path2);
|
|
70
|
-
return { ...data, path: path2 };
|
|
71
|
-
});
|
|
72
|
-
if (version === "latest") {
|
|
73
|
-
return latestVersion;
|
|
74
|
-
}
|
|
75
|
-
const exactMatch = parsedFiles.find((c) => c.version === version);
|
|
76
|
-
if (exactMatch) {
|
|
77
|
-
return exactMatch.path;
|
|
78
|
-
}
|
|
79
|
-
const semverRange = (0, import_semver.validRange)(version);
|
|
80
|
-
if (semverRange) {
|
|
81
|
-
const match = parsedFiles.filter((c) => {
|
|
82
|
-
try {
|
|
83
|
-
return (0, import_semver.satisfies)(c.version, semverRange);
|
|
84
|
-
} catch (error) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return match.length > 0 ? match[0].path : void 0;
|
|
89
|
-
}
|
|
90
|
-
return void 0;
|
|
91
|
-
};
|
|
92
|
-
var getFiles = async (pattern, ignore = "") => {
|
|
93
|
-
try {
|
|
94
|
-
const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
|
|
95
|
-
const absoluteBaseDir = (0, import_node_path.resolve)(
|
|
96
|
-
normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
|
|
97
|
-
);
|
|
98
|
-
let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
|
|
99
|
-
relativePattern = relativePattern.replace(/\\/g, "/");
|
|
100
|
-
const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
|
|
101
|
-
const files = (0, import_glob.globSync)(relativePattern, {
|
|
102
|
-
cwd: absoluteBaseDir,
|
|
103
|
-
ignore: ["node_modules/**", ...ignoreList],
|
|
104
|
-
absolute: true,
|
|
105
|
-
nodir: true
|
|
106
|
-
});
|
|
107
|
-
return files.map(import_node_path.normalize);
|
|
108
|
-
} catch (error) {
|
|
109
|
-
const absoluteBaseDirForError = (0, import_node_path.resolve)(
|
|
110
|
-
(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))
|
|
111
|
-
);
|
|
112
|
-
const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var searchFilesForId = async (files, id, version) => {
|
|
119
|
-
const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
120
|
-
const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${escapedId}['"]?\\s*$`, "m");
|
|
121
|
-
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
122
|
-
const matches = files.map((file) => {
|
|
123
|
-
const content = import_node_fs.default.readFileSync(file, "utf-8");
|
|
124
|
-
const hasIdMatch = content.match(idRegex);
|
|
125
|
-
if (version && !content.match(versionRegex)) {
|
|
126
|
-
return void 0;
|
|
127
|
-
}
|
|
128
|
-
if (hasIdMatch) {
|
|
129
|
-
return file;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
133
|
-
};
|
|
134
|
-
var copyDir = async (catalogDir, source, target, filter) => {
|
|
135
|
-
const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
|
|
136
|
-
import_node_fs.default.mkdirSync(tmpDirectory, { recursive: true });
|
|
137
|
-
await (0, import_fs_extra.copy)(source, tmpDirectory, {
|
|
138
|
-
overwrite: true,
|
|
139
|
-
filter
|
|
140
|
-
});
|
|
141
|
-
await (0, import_fs_extra.copy)(tmpDirectory, target, {
|
|
142
|
-
overwrite: true,
|
|
143
|
-
filter
|
|
144
|
-
});
|
|
145
|
-
import_node_fs.default.rmSync(tmpDirectory, { recursive: true });
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/internal/resources.ts
|
|
149
|
-
var import_gray_matter2 = __toESM(require("gray-matter"));
|
|
150
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
151
|
-
var import_node_fs2 = __toESM(require("fs"));
|
|
152
|
-
var import_semver2 = require("semver");
|
|
153
|
-
var import_proper_lockfile = require("proper-lockfile");
|
|
154
|
-
var import_node_path2 = require("path");
|
|
155
|
-
var import_node_path3 = __toESM(require("path"));
|
|
156
|
-
var versionResource = async (catalogDir, id) => {
|
|
157
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
158
|
-
const matchedFiles = await searchFilesForId(files, id);
|
|
159
|
-
if (matchedFiles.length === 0) {
|
|
160
|
-
throw new Error(`No resource found with id: ${id}`);
|
|
161
|
-
}
|
|
162
|
-
const file = matchedFiles[0];
|
|
163
|
-
const sourceDirectory = (0, import_path.dirname)(file).replace(/[/\\]versioned[/\\][^/\\]+[/\\]/, import_node_path3.default.sep);
|
|
164
|
-
const { data: { version = "0.0.1" } = {} } = import_gray_matter2.default.read(file);
|
|
165
|
-
const targetDirectory = getVersionedDirectory(sourceDirectory, version);
|
|
166
|
-
import_node_fs2.default.mkdirSync(targetDirectory, { recursive: true });
|
|
167
|
-
const ignoreListToCopy = ["events", "commands", "queries", "versioned"];
|
|
168
|
-
await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {
|
|
169
|
-
const folderName = (0, import_node_path2.basename)(src);
|
|
170
|
-
if (ignoreListToCopy.includes(folderName)) {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
return true;
|
|
174
|
-
});
|
|
175
|
-
await import_promises.default.readdir(sourceDirectory).then(async (resourceFiles) => {
|
|
176
|
-
await Promise.all(
|
|
177
|
-
resourceFiles.map(async (file2) => {
|
|
178
|
-
if (ignoreListToCopy.includes(file2)) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (file2 !== "versioned") {
|
|
182
|
-
import_node_fs2.default.rmSync((0, import_path.join)(sourceDirectory, file2), { recursive: true });
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
);
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
var writeResource = async (catalogDir, resource, options = {
|
|
189
|
-
path: "",
|
|
190
|
-
type: "",
|
|
191
|
-
override: false,
|
|
192
|
-
versionExistingContent: false,
|
|
193
|
-
format: "mdx"
|
|
194
|
-
}) => {
|
|
195
|
-
const path2 = options.path || `/${resource.id}`;
|
|
196
|
-
const fullPath = (0, import_path.join)(catalogDir, path2);
|
|
197
|
-
const format = options.format || "mdx";
|
|
198
|
-
import_node_fs2.default.mkdirSync(fullPath, { recursive: true });
|
|
199
|
-
const lockPath = (0, import_path.join)(fullPath, `index.${format}`);
|
|
200
|
-
if (!import_node_fs2.default.existsSync(lockPath)) {
|
|
201
|
-
import_node_fs2.default.writeFileSync(lockPath, "");
|
|
202
|
-
}
|
|
203
|
-
try {
|
|
204
|
-
await (0, import_proper_lockfile.lock)(lockPath, {
|
|
205
|
-
retries: 5,
|
|
206
|
-
stale: 1e4
|
|
207
|
-
// 10 seconds
|
|
208
|
-
});
|
|
209
|
-
const exists = await versionExists(catalogDir, resource.id, resource.version);
|
|
210
|
-
if (exists && !options.override) {
|
|
211
|
-
throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
|
|
212
|
-
}
|
|
213
|
-
const { markdown, ...frontmatter } = resource;
|
|
214
|
-
if (options.versionExistingContent && !exists) {
|
|
215
|
-
const currentResource = await getResource(catalogDir, resource.id);
|
|
216
|
-
if (currentResource) {
|
|
217
|
-
if ((0, import_semver2.satisfies)(resource.version, `>${currentResource.version}`)) {
|
|
218
|
-
await versionResource(catalogDir, resource.id);
|
|
219
|
-
} else {
|
|
220
|
-
throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
|
|
225
|
-
import_node_fs2.default.writeFileSync(lockPath, document);
|
|
226
|
-
} finally {
|
|
227
|
-
await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var getResource = async (catalogDir, id, version, options, filePath) => {
|
|
232
|
-
const attachSchema = options?.attachSchema || false;
|
|
233
|
-
const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
|
|
234
|
-
if (!file || !import_node_fs2.default.existsSync(file)) return;
|
|
235
|
-
const { data, content } = import_gray_matter2.default.read(file);
|
|
236
|
-
if (attachSchema && data?.schemaPath) {
|
|
237
|
-
const resourceDirectory = (0, import_path.dirname)(file);
|
|
238
|
-
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
239
|
-
if (import_node_fs2.default.existsSync(pathToSchema)) {
|
|
240
|
-
const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
|
|
241
|
-
try {
|
|
242
|
-
data.schema = JSON.parse(schema);
|
|
243
|
-
} catch (error) {
|
|
244
|
-
data.schema = schema;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
...data,
|
|
250
|
-
markdown: content.trim()
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
var getResourcePath = async (catalogDir, id, version) => {
|
|
254
|
-
const file = await findFileById(catalogDir, id, version);
|
|
255
|
-
if (!file) return;
|
|
256
|
-
return {
|
|
257
|
-
fullPath: file,
|
|
258
|
-
relativePath: file.replace(catalogDir, ""),
|
|
259
|
-
directory: (0, import_path.dirname)(file.replace(catalogDir, ""))
|
|
260
|
-
};
|
|
261
|
-
};
|
|
262
|
-
var getResources = async (catalogDir, {
|
|
263
|
-
type,
|
|
264
|
-
latestOnly = false,
|
|
265
|
-
ignore = [],
|
|
266
|
-
pattern = "",
|
|
267
|
-
attachSchema = false
|
|
268
|
-
}) => {
|
|
269
|
-
const ignoreList = latestOnly ? `**/versioned/**` : "";
|
|
270
|
-
const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
|
|
271
|
-
const files = await getFiles(filePattern, [ignoreList, ...ignore]);
|
|
272
|
-
if (files.length === 0) return;
|
|
273
|
-
return files.map((file) => {
|
|
274
|
-
const { data, content } = import_gray_matter2.default.read(file);
|
|
275
|
-
if (attachSchema && data?.schemaPath) {
|
|
276
|
-
const resourceDirectory = (0, import_path.dirname)(file);
|
|
277
|
-
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
278
|
-
if (import_node_fs2.default.existsSync(pathToSchema)) {
|
|
279
|
-
const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
|
|
280
|
-
try {
|
|
281
|
-
data.schema = JSON.parse(schema);
|
|
282
|
-
} catch (error) {
|
|
283
|
-
data.schema = schema;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return {
|
|
288
|
-
...data,
|
|
289
|
-
markdown: content.trim()
|
|
290
|
-
};
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
var rmResourceById = async (catalogDir, id, version, options) => {
|
|
294
|
-
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
295
|
-
const matchedFiles = await searchFilesForId(files, id, version);
|
|
296
|
-
if (matchedFiles.length === 0) {
|
|
297
|
-
throw new Error(`No ${options?.type || "resource"} found with id: ${id}`);
|
|
298
|
-
}
|
|
299
|
-
if (options?.persistFiles) {
|
|
300
|
-
await Promise.all(
|
|
301
|
-
matchedFiles.map(async (file) => {
|
|
302
|
-
await import_promises.default.rm(file, { recursive: true });
|
|
303
|
-
await waitForFileRemoval(file);
|
|
304
|
-
})
|
|
305
|
-
);
|
|
306
|
-
} else {
|
|
307
|
-
await Promise.all(
|
|
308
|
-
matchedFiles.map(async (file) => {
|
|
309
|
-
const directory = (0, import_path.dirname)(file);
|
|
310
|
-
await import_promises.default.rm(directory, { recursive: true, force: true });
|
|
311
|
-
await waitForFileRemoval(directory);
|
|
312
|
-
})
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
var waitForFileRemoval = async (path2, maxRetries = 50, delay = 10) => {
|
|
317
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
318
|
-
try {
|
|
319
|
-
await import_promises.default.access(path2);
|
|
320
|
-
await new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
321
|
-
} catch (error) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
throw new Error(`File/directory ${path2} was not removed after ${maxRetries} attempts`);
|
|
326
|
-
};
|
|
327
|
-
var getVersionedDirectory = (sourceDirectory, version) => {
|
|
328
|
-
return (0, import_path.join)(sourceDirectory, "versioned", version);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// src/events.ts
|
|
332
|
-
var import_promises2 = __toESM(require("fs/promises"));
|
|
333
|
-
var import_node_path4 = require("path");
|
|
334
|
-
var getEvent = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "event", ...options });
|
|
335
|
-
var writeEvent = (directory) => async (event, options = {
|
|
336
|
-
path: "",
|
|
337
|
-
override: false,
|
|
338
|
-
format: "mdx"
|
|
339
|
-
}) => writeResource(directory, { ...event }, { ...options, type: "event" });
|
|
340
|
-
var rmEventById = (directory) => async (id, version, persistFiles) => {
|
|
341
|
-
await rmResourceById(directory, id, version, { type: "event", persistFiles });
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
// src/commands.ts
|
|
345
|
-
var import_promises3 = __toESM(require("fs/promises"));
|
|
346
|
-
var import_node_path5 = require("path");
|
|
347
|
-
var getCommand = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "command", ...options });
|
|
348
|
-
var writeCommand = (directory) => async (command, options = {
|
|
349
|
-
path: "",
|
|
350
|
-
override: false,
|
|
351
|
-
versionExistingContent: false,
|
|
352
|
-
format: "mdx"
|
|
353
|
-
}) => writeResource(directory, { ...command }, { ...options, type: "command" });
|
|
354
|
-
var rmCommandById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "command", persistFiles });
|
|
355
|
-
|
|
356
|
-
// src/queries.ts
|
|
357
|
-
var import_promises4 = __toESM(require("fs/promises"));
|
|
358
|
-
var import_node_path6 = require("path");
|
|
359
|
-
var getQuery = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "query", ...options });
|
|
360
|
-
var writeQuery = (directory) => async (query, options = {
|
|
361
|
-
path: "",
|
|
362
|
-
override: false,
|
|
363
|
-
versionExistingContent: false,
|
|
364
|
-
format: "mdx"
|
|
365
|
-
}) => writeResource(directory, { ...query }, { ...options, type: "query" });
|
|
366
|
-
var rmQueryById = (directory) => async (id, version, persistFiles) => {
|
|
367
|
-
await rmResourceById(directory, id, version, { type: "query", persistFiles });
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// src/channels.ts
|
|
371
|
-
var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
|
|
372
|
-
var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
|
|
373
|
-
var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
|
|
374
|
-
var rmChannel = (directory) => async (path2) => {
|
|
375
|
-
await import_promises5.default.rm((0, import_node_path7.join)(directory, path2), { recursive: true });
|
|
376
|
-
};
|
|
377
|
-
var rmChannelById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "channel", persistFiles });
|
|
378
|
-
var versionChannel = (directory) => async (id) => versionResource(directory, id);
|
|
379
|
-
var channelHasVersion = (directory) => async (id, version) => {
|
|
380
|
-
const file = await findFileById(directory, id, version);
|
|
381
|
-
return !!file;
|
|
382
|
-
};
|
|
383
|
-
var addMessageToChannel = (directory, collection) => async (id, _message, version) => {
|
|
384
|
-
let channel = await getChannel(directory)(id, version);
|
|
385
|
-
const functions = {
|
|
386
|
-
events: {
|
|
387
|
-
getMessage: getEvent,
|
|
388
|
-
rmMessageById: rmEventById,
|
|
389
|
-
writeMessage: writeEvent
|
|
390
|
-
},
|
|
391
|
-
commands: {
|
|
392
|
-
getMessage: getCommand,
|
|
393
|
-
rmMessageById: rmCommandById,
|
|
394
|
-
writeMessage: writeCommand
|
|
395
|
-
},
|
|
396
|
-
queries: {
|
|
397
|
-
getMessage: getQuery,
|
|
398
|
-
rmMessageById: rmQueryById,
|
|
399
|
-
writeMessage: writeQuery
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
const { getMessage, rmMessageById, writeMessage } = functions[collection];
|
|
403
|
-
const message = await getMessage(directory)(_message.id, _message.version);
|
|
404
|
-
const messagePath = await getResourcePath(directory, _message.id, _message.version);
|
|
405
|
-
const extension = (0, import_node_path7.extname)(messagePath?.fullPath || "");
|
|
406
|
-
if (!message) throw new Error(`Message ${_message.id} with version ${_message.version} not found`);
|
|
407
|
-
if (message.channels === void 0) {
|
|
408
|
-
message.channels = [];
|
|
409
|
-
}
|
|
410
|
-
const channelInfo = { id, version: channel.version, ..._message.parameters && { parameters: _message.parameters } };
|
|
411
|
-
message.channels.push(channelInfo);
|
|
412
|
-
const existingResource = await findFileById(directory, _message.id, _message.version);
|
|
413
|
-
if (!existingResource) {
|
|
414
|
-
throw new Error(`Cannot find message ${id} in the catalog`);
|
|
415
|
-
}
|
|
416
|
-
const path2 = existingResource.split(`/[\\/]+${collection}`)[0];
|
|
417
|
-
const pathToResource = (0, import_node_path7.join)(path2, collection);
|
|
418
|
-
await rmMessageById(directory)(_message.id, _message.version, true);
|
|
419
|
-
await writeMessage(pathToResource)(message, { format: extension === ".md" ? "md" : "mdx" });
|
|
420
|
-
};
|
|
421
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
422
|
-
0 && (module.exports = {
|
|
423
|
-
addMessageToChannel,
|
|
424
|
-
channelHasVersion,
|
|
425
|
-
getChannel,
|
|
426
|
-
getChannels,
|
|
427
|
-
rmChannel,
|
|
428
|
-
rmChannelById,
|
|
429
|
-
versionChannel,
|
|
430
|
-
writeChannel
|
|
431
|
-
});
|
|
432
|
-
//# sourceMappingURL=channels.js.map
|