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