@eventcatalog/sdk 2.8.0 → 2.8.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.
@@ -0,0 +1,179 @@
1
+ import { Container } from './types.d.mjs';
2
+
3
+ /**
4
+ * Returns an container (e.g. data store) from EventCatalog.
5
+ *
6
+ * You can optionally specify a version to get a specific version of the container
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 container
15
+ * const container = await getContainer('User');
16
+ *
17
+ * // Gets a version of the entity
18
+ * const container = await getContainer('User', '0.0.1');
19
+ *
20
+ * ```
21
+ */
22
+ declare const getContainer: (directory: string) => (id: string, version?: string) => Promise<Container>;
23
+ /**
24
+ * Returns all containers (e.g. data stores) from EventCatalog.
25
+ *
26
+ * You can optionally specify if you want to get the latest version of the containers.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import utils from '@eventcatalog/utils';
31
+ *
32
+ * const { getContainers } = utils('/path/to/eventcatalog');
33
+ *
34
+ * // Gets all containers (and versions) from the catalog
35
+ * const containers = await getContainers();
36
+ *
37
+ * // Gets all entities (only latest version) from the catalog
38
+ * const containers = await getContainers({ latestOnly: true });
39
+ *
40
+ * ```
41
+ */
42
+ declare const getContainers: (directory: string) => (options?: {
43
+ latestOnly?: boolean;
44
+ }) => Promise<Container[]>;
45
+ /**
46
+ * Write a container (e.g. data store) to EventCatalog.
47
+ */
48
+ declare const writeContainer: (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 container (e.g. data store) by its id.
56
+ *
57
+ * Takes the latest container and moves it to a versioned directory.
58
+ * All files with this container are also versioned (e.g /containers/orders-db/schema.json)
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import utils from '@eventcatalog/utils';
63
+ *
64
+ * const { versionContainer } = utils('/path/to/eventcatalog');
65
+ *
66
+ * // moves the latest orders-db container to a versioned directory
67
+ * // the version within that container is used as the version number.
68
+ * await versionContainer('orders-db');
69
+ *
70
+ * ```
71
+ */
72
+ declare const versionContainer: (directory: string) => (id: string) => Promise<void>;
73
+ /**
74
+ * Delete an container (e.g. data store) at its given path.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import utils from '@eventcatalog/utils';
79
+ *
80
+ * const { rmContainer } = utils('/path/to/eventcatalog');
81
+ *
82
+ * // removes an container at the given path (containers dir is appended to the given path)
83
+ * // Removes the container at containers/orders-db
84
+ * await rmContainer('/orders-db');
85
+ * ```
86
+ */
87
+ declare const rmContainer: (directory: string) => (path: string) => Promise<void>;
88
+ /**
89
+ * Delete an container (e.g. data store) by its id.
90
+ *
91
+ * Optionally specify a version to delete a specific version of the container.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import utils from '@eventcatalog/utils';
96
+ *
97
+ * const { rmContainerById } = utils('/path/to/eventcatalog');
98
+ *
99
+ * // deletes the latest orders-db container
100
+ * await rmContainerById('orders-db');
101
+ *
102
+ * // deletes a specific version of the orders-db container
103
+ * await rmContainerById('orders-db', '0.0.1');
104
+ * ```
105
+ */
106
+ declare const rmContainerById: (directory: string) => (id: string, version?: string, persistFiles?: boolean) => Promise<void>;
107
+ /**
108
+ * Check to see if the catalog has a version for the given container (e.g. data store).
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import utils from '@eventcatalog/utils';
113
+ *
114
+ * const { containerHasVersion } = utils('/path/to/eventcatalog');
115
+ *
116
+ * // returns true if version is found for the given entity and version (supports semver)
117
+ * await containerHasVersion('orders-db', '0.0.1');
118
+ * await containerHasVersion('orders-db', 'latest');
119
+ * await containerHasVersion('orders-db', '0.0.x');
120
+ *
121
+ * ```
122
+ */
123
+ declare const containerHasVersion: (directory: string) => (id: string, version?: string) => Promise<boolean>;
124
+ /**
125
+ * Add a file to a container (e.g. data store) by it's id.
126
+ *
127
+ * Optionally specify a version to add a file to a specific version of the container.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import utils from '@eventcatalog/utils';
132
+ *
133
+ * const { addFileToContainer } = utils('/path/to/eventcatalog');
134
+ *
135
+ * // adds a file to the latest InventoryAdjusted event
136
+ * await addFileToContainer('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' });
137
+ *
138
+ * // adds a file to a specific version of the InventoryAdjusted event
139
+ * await addFileToContainer('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');
140
+ *
141
+ * ```
142
+ */
143
+ declare const addFileToContainer: (directory: string) => (id: string, file: {
144
+ content: string;
145
+ fileName: string;
146
+ }, version?: string) => Promise<void>;
147
+ /**
148
+ * Write an data store (e.g. data store) 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 { writeContainerToService } = utils('/path/to/eventcatalog');
157
+ *
158
+ * // Write a container to a given service in the catalog
159
+ * // Container would be written to services/Inventory/containers/orders-db
160
+ * await writeContainerToService({
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 writeContainerToService: (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 { addFileToContainer, containerHasVersion, getContainer, getContainers, rmContainer, rmContainerById, versionContainer, writeContainer, writeContainerToService };
@@ -0,0 +1,179 @@
1
+ import { Container } from './types.d.js';
2
+
3
+ /**
4
+ * Returns an container (e.g. data store) from EventCatalog.
5
+ *
6
+ * You can optionally specify a version to get a specific version of the container
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 container
15
+ * const container = await getContainer('User');
16
+ *
17
+ * // Gets a version of the entity
18
+ * const container = await getContainer('User', '0.0.1');
19
+ *
20
+ * ```
21
+ */
22
+ declare const getContainer: (directory: string) => (id: string, version?: string) => Promise<Container>;
23
+ /**
24
+ * Returns all containers (e.g. data stores) from EventCatalog.
25
+ *
26
+ * You can optionally specify if you want to get the latest version of the containers.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import utils from '@eventcatalog/utils';
31
+ *
32
+ * const { getContainers } = utils('/path/to/eventcatalog');
33
+ *
34
+ * // Gets all containers (and versions) from the catalog
35
+ * const containers = await getContainers();
36
+ *
37
+ * // Gets all entities (only latest version) from the catalog
38
+ * const containers = await getContainers({ latestOnly: true });
39
+ *
40
+ * ```
41
+ */
42
+ declare const getContainers: (directory: string) => (options?: {
43
+ latestOnly?: boolean;
44
+ }) => Promise<Container[]>;
45
+ /**
46
+ * Write a container (e.g. data store) to EventCatalog.
47
+ */
48
+ declare const writeContainer: (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 container (e.g. data store) by its id.
56
+ *
57
+ * Takes the latest container and moves it to a versioned directory.
58
+ * All files with this container are also versioned (e.g /containers/orders-db/schema.json)
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import utils from '@eventcatalog/utils';
63
+ *
64
+ * const { versionContainer } = utils('/path/to/eventcatalog');
65
+ *
66
+ * // moves the latest orders-db container to a versioned directory
67
+ * // the version within that container is used as the version number.
68
+ * await versionContainer('orders-db');
69
+ *
70
+ * ```
71
+ */
72
+ declare const versionContainer: (directory: string) => (id: string) => Promise<void>;
73
+ /**
74
+ * Delete an container (e.g. data store) at its given path.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import utils from '@eventcatalog/utils';
79
+ *
80
+ * const { rmContainer } = utils('/path/to/eventcatalog');
81
+ *
82
+ * // removes an container at the given path (containers dir is appended to the given path)
83
+ * // Removes the container at containers/orders-db
84
+ * await rmContainer('/orders-db');
85
+ * ```
86
+ */
87
+ declare const rmContainer: (directory: string) => (path: string) => Promise<void>;
88
+ /**
89
+ * Delete an container (e.g. data store) by its id.
90
+ *
91
+ * Optionally specify a version to delete a specific version of the container.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import utils from '@eventcatalog/utils';
96
+ *
97
+ * const { rmContainerById } = utils('/path/to/eventcatalog');
98
+ *
99
+ * // deletes the latest orders-db container
100
+ * await rmContainerById('orders-db');
101
+ *
102
+ * // deletes a specific version of the orders-db container
103
+ * await rmContainerById('orders-db', '0.0.1');
104
+ * ```
105
+ */
106
+ declare const rmContainerById: (directory: string) => (id: string, version?: string, persistFiles?: boolean) => Promise<void>;
107
+ /**
108
+ * Check to see if the catalog has a version for the given container (e.g. data store).
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import utils from '@eventcatalog/utils';
113
+ *
114
+ * const { containerHasVersion } = utils('/path/to/eventcatalog');
115
+ *
116
+ * // returns true if version is found for the given entity and version (supports semver)
117
+ * await containerHasVersion('orders-db', '0.0.1');
118
+ * await containerHasVersion('orders-db', 'latest');
119
+ * await containerHasVersion('orders-db', '0.0.x');
120
+ *
121
+ * ```
122
+ */
123
+ declare const containerHasVersion: (directory: string) => (id: string, version?: string) => Promise<boolean>;
124
+ /**
125
+ * Add a file to a container (e.g. data store) by it's id.
126
+ *
127
+ * Optionally specify a version to add a file to a specific version of the container.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import utils from '@eventcatalog/utils';
132
+ *
133
+ * const { addFileToContainer } = utils('/path/to/eventcatalog');
134
+ *
135
+ * // adds a file to the latest InventoryAdjusted event
136
+ * await addFileToContainer('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' });
137
+ *
138
+ * // adds a file to a specific version of the InventoryAdjusted event
139
+ * await addFileToContainer('InventoryAdjusted', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');
140
+ *
141
+ * ```
142
+ */
143
+ declare const addFileToContainer: (directory: string) => (id: string, file: {
144
+ content: string;
145
+ fileName: string;
146
+ }, version?: string) => Promise<void>;
147
+ /**
148
+ * Write an data store (e.g. data store) 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 { writeContainerToService } = utils('/path/to/eventcatalog');
157
+ *
158
+ * // Write a container to a given service in the catalog
159
+ * // Container would be written to services/Inventory/containers/orders-db
160
+ * await writeContainerToService({
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 writeContainerToService: (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 { addFileToContainer, containerHasVersion, getContainer, getContainers, rmContainer, rmContainerById, versionContainer, writeContainer, writeContainerToService };