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