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