@eventcatalog/sdk 2.9.11 → 2.11.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.
@@ -0,0 +1,225 @@
1
+ import { DataProduct } from './types.d.mjs';
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 };
@@ -0,0 +1,225 @@
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 };