@eventcatalog/sdk 1.1.3 → 1.2.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 +9 -1
- package/dist/channels.d.mts +167 -0
- package/dist/channels.d.ts +167 -0
- package/dist/channels.js +259 -0
- package/dist/channels.js.map +1 -0
- package/dist/channels.mjs +212 -0
- package/dist/channels.mjs.map +1 -0
- package/dist/commands.js +1 -1
- package/dist/commands.js.map +1 -1
- package/dist/commands.mjs +1 -1
- package/dist/commands.mjs.map +1 -1
- package/dist/domains.js +1 -1
- package/dist/domains.js.map +1 -1
- package/dist/domains.mjs +1 -1
- package/dist/domains.mjs.map +1 -1
- package/dist/events.js +1 -1
- package/dist/events.js.map +1 -1
- package/dist/events.mjs +1 -1
- package/dist/events.mjs.map +1 -1
- package/dist/index.d.mts +187 -47
- package/dist/index.d.ts +187 -47
- package/dist/index.js +249 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +249 -87
- package/dist/index.mjs.map +1 -1
- package/dist/queries.js +1 -1
- package/dist/queries.js.map +1 -1
- package/dist/queries.mjs +1 -1
- package/dist/queries.mjs.map +1 -1
- package/dist/services.js +1 -1
- package/dist/services.js.map +1 -1
- package/dist/services.mjs +1 -1
- package/dist/services.mjs.map +1 -1
- package/dist/types.d.d.mts +27 -4
- package/dist/types.d.d.ts +27 -4
- package/dist/types.d.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,10 +68,18 @@ Thank you to our project sponsors.
|
|
|
68
68
|
|
|
69
69
|
<hr />
|
|
70
70
|
|
|
71
|
+
<div align="center">
|
|
72
|
+
<img alt="oso" src="./images/sponsors/oso-logo-green.png" width="40%" />
|
|
73
|
+
<p style="margin: 0; padding: 0;">Delivering Apache Kafka professional services to your business</p>
|
|
74
|
+
<a href="https://oso.sh/?utm_source=eventcatalog&utm_medium=web&utm_campaign=sponsorship" target="_blank" >Learn more</a>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<hr />
|
|
78
|
+
|
|
71
79
|
_Sponsors help make EventCatalog sustainable, want to help the project? Get in touch! Or [visit our sponsor page](https://www.eventcatalog.dev/support)._
|
|
72
80
|
|
|
73
81
|
# Enterprise support
|
|
74
82
|
|
|
75
83
|
Interested in collaborating with us? Our offerings include dedicated support, priority assistance, feature development, custom integrations, and more.
|
|
76
84
|
|
|
77
|
-
Find more details on our [services page](https://eventcatalog.dev/services)
|
|
85
|
+
Find more details on our [services page](https://eventcatalog.dev/services)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Channel } from './types.d.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a channel from EventCatalog.
|
|
5
|
+
*
|
|
6
|
+
* You can optionally specify a version to get a specific version of the channel
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import utils from '@eventcatalog/utils';
|
|
11
|
+
*
|
|
12
|
+
* const { getChannel } = utils('/path/to/eventcatalog');
|
|
13
|
+
*
|
|
14
|
+
* // Gets the latest version of the channel
|
|
15
|
+
* const channel = await getChannel('InventoryChannel');
|
|
16
|
+
*
|
|
17
|
+
* // Gets a version of the channel
|
|
18
|
+
* const channel = await getChannel('InventoryChannel', '0.0.1');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const getChannel: (directory: string) => (id: string, version?: string) => Promise<Channel>;
|
|
22
|
+
/**
|
|
23
|
+
* Write a channel to EventCatalog.
|
|
24
|
+
*
|
|
25
|
+
* You can optionally override the path of the channel.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import utils from '@eventcatalog/utils';
|
|
30
|
+
*
|
|
31
|
+
* const { writeChannel } = utils('/path/to/eventcatalog');
|
|
32
|
+
*
|
|
33
|
+
* // Write a channel to the catalog
|
|
34
|
+
* // channel would be written to channels/inventory.{env}.events
|
|
35
|
+
* await writeChannel({
|
|
36
|
+
* id: 'inventory.{env}.events',
|
|
37
|
+
* name: 'Inventory channel',
|
|
38
|
+
* version: '0.0.1',
|
|
39
|
+
* summary: 'This is a summary',
|
|
40
|
+
* markdown: '# Hello world',
|
|
41
|
+
* address: inventory.{env}.events,
|
|
42
|
+
* protocols: ['http'],
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Write a channel to the catalog but override the path
|
|
46
|
+
* // channel would be written to channels/Inventory/InventoryChannel
|
|
47
|
+
* await writeChannel({
|
|
48
|
+
* id: 'InventoryChannel',
|
|
49
|
+
* name: 'Update Inventory',
|
|
50
|
+
* version: '0.0.1',
|
|
51
|
+
* summary: 'This is a summary',
|
|
52
|
+
* markdown: '# Hello world',
|
|
53
|
+
* address: inventory.{env}.events,
|
|
54
|
+
* protocols: ['http'],
|
|
55
|
+
* }, { path: "/channels/Inventory/InventoryChannel"});
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const writeChannel: (directory: string) => (channel: Channel, options?: {
|
|
59
|
+
path: string;
|
|
60
|
+
}) => Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Delete a channel at it's given path.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import utils from '@eventcatalog/utils';
|
|
67
|
+
*
|
|
68
|
+
* const { rmChannel } = utils('/path/to/eventcatalog');
|
|
69
|
+
*
|
|
70
|
+
* // removes a channel at the given path (channels dir is appended to the given path)
|
|
71
|
+
* // Removes the channel at channels/InventoryChannel
|
|
72
|
+
* await rmChannel('/InventoryChannel');
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const rmChannel: (directory: string) => (path: string) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Delete a channel by it's id.
|
|
78
|
+
*
|
|
79
|
+
* Optionally specify a version to delete a specific version of the channel.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import utils from '@eventcatalog/utils';
|
|
84
|
+
*
|
|
85
|
+
* const { rmChannelById } = utils('/path/to/eventcatalog');
|
|
86
|
+
*
|
|
87
|
+
* // deletes the latest InventoryChannel channel
|
|
88
|
+
* await rmChannelById('inventory.{env}.events');
|
|
89
|
+
*
|
|
90
|
+
* // deletes a specific version of the InventoryChannel channel
|
|
91
|
+
* await rmChannelById('inventory.{env}.events', '0.0.1');
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare const rmChannelById: (directory: string) => (id: string, version?: string) => Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Version a channel by it's id.
|
|
97
|
+
*
|
|
98
|
+
* Takes the latest channel and moves it to a versioned directory.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import utils from '@eventcatalog/utils';
|
|
103
|
+
*
|
|
104
|
+
* const { versionChannel } = utils('/path/to/eventcatalog');
|
|
105
|
+
*
|
|
106
|
+
* // moves the latest inventory.{env}.events channel to a versioned directory
|
|
107
|
+
* // the version within that channel is used as the version number.
|
|
108
|
+
* await versionChannel('inventory.{env}.events');
|
|
109
|
+
*
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare const versionChannel: (directory: string) => (id: string) => Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Check to see if the catalog has a version for the given channel.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import utils from '@eventcatalog/utils';
|
|
119
|
+
*
|
|
120
|
+
* const { channelHasVersion } = utils('/path/to/eventcatalog');
|
|
121
|
+
*
|
|
122
|
+
* // returns true if version is found for the given event and version (supports semver)
|
|
123
|
+
* await channelHasVersion('inventory.{env}.events', '0.0.1');
|
|
124
|
+
* await channelHasVersion('inventory.{env}.events', 'latest');
|
|
125
|
+
* await channelHasVersion('inventory.{env}.events', '0.0.x');*
|
|
126
|
+
*
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare const channelHasVersion: (directory: string) => (id: string, version: string) => Promise<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Add an event/command/query to a channel by it's id.
|
|
132
|
+
*
|
|
133
|
+
* Optionally specify a version to add the message to a specific version of the service.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import utils from '@eventcatalog/utils';
|
|
138
|
+
*
|
|
139
|
+
* // Adds an event to the service or command to the service
|
|
140
|
+
* const { addEventToChannel, addCommandToChannel, addQueryToChannel } = utils('/path/to/eventcatalog');
|
|
141
|
+
*
|
|
142
|
+
* // Adds a new event (InventoryUpdatedEvent) that the InventoryService will send
|
|
143
|
+
* await addEventToChannel('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
|
|
144
|
+
* * // Adds a new event (OrderComplete) that the InventoryService will receive
|
|
145
|
+
* await addEventToChannel('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });
|
|
146
|
+
*
|
|
147
|
+
* // Adds a new command (UpdateInventoryCommand) that the InventoryService will send
|
|
148
|
+
* await addCommandToChannel('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });
|
|
149
|
+
* // Adds a new command (VerifyInventory) that the InventoryService will receive
|
|
150
|
+
* await addCommandToChannel('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });
|
|
151
|
+
*
|
|
152
|
+
* // Adds a new query (GetInventoryQuery) that the InventoryService will send
|
|
153
|
+
* await addQueryToChannel('InventoryService', 'sends', { query: 'GetInventoryQuery', version: '2.0.0' });
|
|
154
|
+
* // Adds a new query (GetOrder) that the InventoryService will receive
|
|
155
|
+
* await addQueryToChannel('InventoryService', 'receives', { query: 'GetOrder', version: '1.0.0' });
|
|
156
|
+
*
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare const addMessageToChannel: (directory: string, collection: string) => (id: string, _message: {
|
|
160
|
+
id: string;
|
|
161
|
+
version: string;
|
|
162
|
+
parameters?: {
|
|
163
|
+
[key: string]: string;
|
|
164
|
+
};
|
|
165
|
+
}, version?: string) => Promise<void>;
|
|
166
|
+
|
|
167
|
+
export { addMessageToChannel, channelHasVersion, getChannel, rmChannel, rmChannelById, versionChannel, writeChannel };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Channel } from './types.d.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a channel from EventCatalog.
|
|
5
|
+
*
|
|
6
|
+
* You can optionally specify a version to get a specific version of the channel
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import utils from '@eventcatalog/utils';
|
|
11
|
+
*
|
|
12
|
+
* const { getChannel } = utils('/path/to/eventcatalog');
|
|
13
|
+
*
|
|
14
|
+
* // Gets the latest version of the channel
|
|
15
|
+
* const channel = await getChannel('InventoryChannel');
|
|
16
|
+
*
|
|
17
|
+
* // Gets a version of the channel
|
|
18
|
+
* const channel = await getChannel('InventoryChannel', '0.0.1');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const getChannel: (directory: string) => (id: string, version?: string) => Promise<Channel>;
|
|
22
|
+
/**
|
|
23
|
+
* Write a channel to EventCatalog.
|
|
24
|
+
*
|
|
25
|
+
* You can optionally override the path of the channel.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import utils from '@eventcatalog/utils';
|
|
30
|
+
*
|
|
31
|
+
* const { writeChannel } = utils('/path/to/eventcatalog');
|
|
32
|
+
*
|
|
33
|
+
* // Write a channel to the catalog
|
|
34
|
+
* // channel would be written to channels/inventory.{env}.events
|
|
35
|
+
* await writeChannel({
|
|
36
|
+
* id: 'inventory.{env}.events',
|
|
37
|
+
* name: 'Inventory channel',
|
|
38
|
+
* version: '0.0.1',
|
|
39
|
+
* summary: 'This is a summary',
|
|
40
|
+
* markdown: '# Hello world',
|
|
41
|
+
* address: inventory.{env}.events,
|
|
42
|
+
* protocols: ['http'],
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Write a channel to the catalog but override the path
|
|
46
|
+
* // channel would be written to channels/Inventory/InventoryChannel
|
|
47
|
+
* await writeChannel({
|
|
48
|
+
* id: 'InventoryChannel',
|
|
49
|
+
* name: 'Update Inventory',
|
|
50
|
+
* version: '0.0.1',
|
|
51
|
+
* summary: 'This is a summary',
|
|
52
|
+
* markdown: '# Hello world',
|
|
53
|
+
* address: inventory.{env}.events,
|
|
54
|
+
* protocols: ['http'],
|
|
55
|
+
* }, { path: "/channels/Inventory/InventoryChannel"});
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const writeChannel: (directory: string) => (channel: Channel, options?: {
|
|
59
|
+
path: string;
|
|
60
|
+
}) => Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Delete a channel at it's given path.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import utils from '@eventcatalog/utils';
|
|
67
|
+
*
|
|
68
|
+
* const { rmChannel } = utils('/path/to/eventcatalog');
|
|
69
|
+
*
|
|
70
|
+
* // removes a channel at the given path (channels dir is appended to the given path)
|
|
71
|
+
* // Removes the channel at channels/InventoryChannel
|
|
72
|
+
* await rmChannel('/InventoryChannel');
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const rmChannel: (directory: string) => (path: string) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Delete a channel by it's id.
|
|
78
|
+
*
|
|
79
|
+
* Optionally specify a version to delete a specific version of the channel.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import utils from '@eventcatalog/utils';
|
|
84
|
+
*
|
|
85
|
+
* const { rmChannelById } = utils('/path/to/eventcatalog');
|
|
86
|
+
*
|
|
87
|
+
* // deletes the latest InventoryChannel channel
|
|
88
|
+
* await rmChannelById('inventory.{env}.events');
|
|
89
|
+
*
|
|
90
|
+
* // deletes a specific version of the InventoryChannel channel
|
|
91
|
+
* await rmChannelById('inventory.{env}.events', '0.0.1');
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare const rmChannelById: (directory: string) => (id: string, version?: string) => Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Version a channel by it's id.
|
|
97
|
+
*
|
|
98
|
+
* Takes the latest channel and moves it to a versioned directory.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import utils from '@eventcatalog/utils';
|
|
103
|
+
*
|
|
104
|
+
* const { versionChannel } = utils('/path/to/eventcatalog');
|
|
105
|
+
*
|
|
106
|
+
* // moves the latest inventory.{env}.events channel to a versioned directory
|
|
107
|
+
* // the version within that channel is used as the version number.
|
|
108
|
+
* await versionChannel('inventory.{env}.events');
|
|
109
|
+
*
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare const versionChannel: (directory: string) => (id: string) => Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Check to see if the catalog has a version for the given channel.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import utils from '@eventcatalog/utils';
|
|
119
|
+
*
|
|
120
|
+
* const { channelHasVersion } = utils('/path/to/eventcatalog');
|
|
121
|
+
*
|
|
122
|
+
* // returns true if version is found for the given event and version (supports semver)
|
|
123
|
+
* await channelHasVersion('inventory.{env}.events', '0.0.1');
|
|
124
|
+
* await channelHasVersion('inventory.{env}.events', 'latest');
|
|
125
|
+
* await channelHasVersion('inventory.{env}.events', '0.0.x');*
|
|
126
|
+
*
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare const channelHasVersion: (directory: string) => (id: string, version: string) => Promise<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Add an event/command/query to a channel by it's id.
|
|
132
|
+
*
|
|
133
|
+
* Optionally specify a version to add the message to a specific version of the service.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import utils from '@eventcatalog/utils';
|
|
138
|
+
*
|
|
139
|
+
* // Adds an event to the service or command to the service
|
|
140
|
+
* const { addEventToChannel, addCommandToChannel, addQueryToChannel } = utils('/path/to/eventcatalog');
|
|
141
|
+
*
|
|
142
|
+
* // Adds a new event (InventoryUpdatedEvent) that the InventoryService will send
|
|
143
|
+
* await addEventToChannel('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
|
|
144
|
+
* * // Adds a new event (OrderComplete) that the InventoryService will receive
|
|
145
|
+
* await addEventToChannel('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });
|
|
146
|
+
*
|
|
147
|
+
* // Adds a new command (UpdateInventoryCommand) that the InventoryService will send
|
|
148
|
+
* await addCommandToChannel('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });
|
|
149
|
+
* // Adds a new command (VerifyInventory) that the InventoryService will receive
|
|
150
|
+
* await addCommandToChannel('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });
|
|
151
|
+
*
|
|
152
|
+
* // Adds a new query (GetInventoryQuery) that the InventoryService will send
|
|
153
|
+
* await addQueryToChannel('InventoryService', 'sends', { query: 'GetInventoryQuery', version: '2.0.0' });
|
|
154
|
+
* // Adds a new query (GetOrder) that the InventoryService will receive
|
|
155
|
+
* await addQueryToChannel('InventoryService', 'receives', { query: 'GetOrder', version: '1.0.0' });
|
|
156
|
+
*
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare const addMessageToChannel: (directory: string, collection: string) => (id: string, _message: {
|
|
160
|
+
id: string;
|
|
161
|
+
version: string;
|
|
162
|
+
parameters?: {
|
|
163
|
+
[key: string]: string;
|
|
164
|
+
};
|
|
165
|
+
}, version?: string) => Promise<void>;
|
|
166
|
+
|
|
167
|
+
export { addMessageToChannel, channelHasVersion, getChannel, rmChannel, rmChannelById, versionChannel, writeChannel };
|
package/dist/channels.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
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/channels.ts
|
|
31
|
+
var channels_exports = {};
|
|
32
|
+
__export(channels_exports, {
|
|
33
|
+
addMessageToChannel: () => addMessageToChannel,
|
|
34
|
+
channelHasVersion: () => channelHasVersion,
|
|
35
|
+
getChannel: () => getChannel,
|
|
36
|
+
rmChannel: () => rmChannel,
|
|
37
|
+
rmChannelById: () => rmChannelById,
|
|
38
|
+
versionChannel: () => versionChannel,
|
|
39
|
+
writeChannel: () => writeChannel
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(channels_exports);
|
|
42
|
+
var import_promises6 = __toESM(require("fs/promises"));
|
|
43
|
+
var import_node_path5 = require("path");
|
|
44
|
+
|
|
45
|
+
// src/internal/resources.ts
|
|
46
|
+
var import_path = require("path");
|
|
47
|
+
|
|
48
|
+
// src/internal/utils.ts
|
|
49
|
+
var import_glob = require("glob");
|
|
50
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
51
|
+
var import_fs_extra = require("fs-extra");
|
|
52
|
+
var import_node_path = require("path");
|
|
53
|
+
var import_gray_matter = __toESM(require("gray-matter"));
|
|
54
|
+
var import_semver = require("semver");
|
|
55
|
+
var versionExists = async (catalogDir, id, version) => {
|
|
56
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
57
|
+
const matchedFiles = await searchFilesForId(files, id, version) || [];
|
|
58
|
+
return matchedFiles.length > 0;
|
|
59
|
+
};
|
|
60
|
+
var findFileById = async (catalogDir, id, version) => {
|
|
61
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
62
|
+
const matchedFiles = await searchFilesForId(files, id) || [];
|
|
63
|
+
const latestVersion = matchedFiles.find((path) => !path.includes("versioned"));
|
|
64
|
+
if (!version) {
|
|
65
|
+
return latestVersion;
|
|
66
|
+
}
|
|
67
|
+
const parsedFiles = matchedFiles.map((path) => {
|
|
68
|
+
const { data } = import_gray_matter.default.read(path);
|
|
69
|
+
return { ...data, path };
|
|
70
|
+
});
|
|
71
|
+
const semverRange = (0, import_semver.validRange)(version);
|
|
72
|
+
if (semverRange && (0, import_semver.valid)(version)) {
|
|
73
|
+
const match2 = parsedFiles.filter((c) => (0, import_semver.satisfies)(c.version, semverRange));
|
|
74
|
+
return match2.length > 0 ? match2[0].path : void 0;
|
|
75
|
+
}
|
|
76
|
+
const sorted = parsedFiles.sort((a, b) => {
|
|
77
|
+
return a.version.localeCompare(b.version);
|
|
78
|
+
});
|
|
79
|
+
const match = sorted.length > 0 ? [sorted[sorted.length - 1]] : [];
|
|
80
|
+
if (match.length > 0) {
|
|
81
|
+
return match[0].path;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var getFiles = async (pattern) => {
|
|
85
|
+
try {
|
|
86
|
+
const files = await (0, import_glob.glob)(pattern, { ignore: "node_modules/**" });
|
|
87
|
+
return files;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new Error(`Error finding files: ${error}`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var searchFilesForId = async (files, id, version) => {
|
|
93
|
+
const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${id}['"]?\\s*$`, "m");
|
|
94
|
+
const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
|
|
95
|
+
const matches = await Promise.all(
|
|
96
|
+
files.map(async (file) => {
|
|
97
|
+
const content = await import_promises.default.readFile(file, "utf-8");
|
|
98
|
+
const hasIdMatch = content.match(idRegex);
|
|
99
|
+
if (version && !content.match(versionRegex)) {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
if (hasIdMatch) {
|
|
103
|
+
return file;
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
return matches.filter(Boolean).filter((file) => file !== void 0);
|
|
108
|
+
};
|
|
109
|
+
var copyDir = async (catalogDir, source, target, filter) => {
|
|
110
|
+
const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
|
|
111
|
+
await import_promises.default.mkdir(tmpDirectory, { recursive: true });
|
|
112
|
+
await (0, import_fs_extra.copy)(source, tmpDirectory, {
|
|
113
|
+
overwrite: true,
|
|
114
|
+
filter
|
|
115
|
+
});
|
|
116
|
+
await (0, import_fs_extra.copy)(tmpDirectory, target, {
|
|
117
|
+
overwrite: true,
|
|
118
|
+
filter
|
|
119
|
+
});
|
|
120
|
+
await import_promises.default.rm(tmpDirectory, { recursive: true });
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/internal/resources.ts
|
|
124
|
+
var import_gray_matter2 = __toESM(require("gray-matter"));
|
|
125
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
126
|
+
var versionResource = async (catalogDir, id) => {
|
|
127
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
128
|
+
const matchedFiles = await searchFilesForId(files, id);
|
|
129
|
+
if (matchedFiles.length === 0) {
|
|
130
|
+
throw new Error(`No event found with id: ${id}`);
|
|
131
|
+
}
|
|
132
|
+
const file = matchedFiles[0];
|
|
133
|
+
const sourceDirectory = (0, import_path.dirname)(file);
|
|
134
|
+
const { data: { version = "0.0.1" } = {} } = import_gray_matter2.default.read(file);
|
|
135
|
+
const targetDirectory = getVersionedDirectory(sourceDirectory, version);
|
|
136
|
+
await import_promises2.default.mkdir(targetDirectory, { recursive: true });
|
|
137
|
+
await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {
|
|
138
|
+
return !src.includes("versioned");
|
|
139
|
+
});
|
|
140
|
+
await import_promises2.default.readdir(sourceDirectory).then(async (resourceFiles) => {
|
|
141
|
+
await Promise.all(
|
|
142
|
+
resourceFiles.map(async (file2) => {
|
|
143
|
+
if (file2 !== "versioned") {
|
|
144
|
+
await import_promises2.default.rm((0, import_path.join)(sourceDirectory, file2), { recursive: true });
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
var writeResource = async (catalogDir, resource, options = { path: "", type: "" }) => {
|
|
151
|
+
const path = options.path || `/${resource.id}`;
|
|
152
|
+
const exists = await versionExists(catalogDir, resource.id, resource.version);
|
|
153
|
+
if (exists) {
|
|
154
|
+
throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
|
|
155
|
+
}
|
|
156
|
+
const { markdown, ...frontmatter } = resource;
|
|
157
|
+
const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
|
|
158
|
+
await import_promises2.default.mkdir((0, import_path.join)(catalogDir, path), { recursive: true });
|
|
159
|
+
await import_promises2.default.writeFile((0, import_path.join)(catalogDir, path, "index.md"), document);
|
|
160
|
+
};
|
|
161
|
+
var getResource = async (catalogDir, id, version, options) => {
|
|
162
|
+
const file = await findFileById(catalogDir, id, version);
|
|
163
|
+
if (!file) return;
|
|
164
|
+
const { data, content } = import_gray_matter2.default.read(file);
|
|
165
|
+
return {
|
|
166
|
+
...data,
|
|
167
|
+
markdown: content.trim()
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
var rmResourceById = async (catalogDir, id, version, options) => {
|
|
171
|
+
const files = await getFiles(`${catalogDir}/**/index.md`);
|
|
172
|
+
const matchedFiles = await searchFilesForId(files, id, version);
|
|
173
|
+
if (matchedFiles.length === 0) {
|
|
174
|
+
throw new Error(`No ${options?.type || "resource"} found with id: ${id}`);
|
|
175
|
+
}
|
|
176
|
+
await Promise.all(matchedFiles.map((file) => import_promises2.default.rm(file)));
|
|
177
|
+
};
|
|
178
|
+
var getVersionedDirectory = (sourceDirectory, version) => {
|
|
179
|
+
return (0, import_path.join)(sourceDirectory, "versioned", version);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/events.ts
|
|
183
|
+
var import_promises3 = __toESM(require("fs/promises"));
|
|
184
|
+
var import_node_path2 = require("path");
|
|
185
|
+
var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
|
|
186
|
+
var writeEvent = (directory) => async (event, options = { path: "" }) => writeResource(directory, { ...event }, { ...options, type: "event" });
|
|
187
|
+
var rmEventById = (directory) => async (id, version) => {
|
|
188
|
+
await rmResourceById(directory, id, version, { type: "event" });
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/commands.ts
|
|
192
|
+
var import_promises4 = __toESM(require("fs/promises"));
|
|
193
|
+
var import_node_path3 = require("path");
|
|
194
|
+
var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
|
|
195
|
+
var writeCommand = (directory) => async (command, options = { path: "" }) => writeResource(directory, { ...command }, { ...options, type: "command" });
|
|
196
|
+
var rmCommandById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "command" });
|
|
197
|
+
|
|
198
|
+
// src/queries.ts
|
|
199
|
+
var import_promises5 = __toESM(require("fs/promises"));
|
|
200
|
+
var import_node_path4 = require("path");
|
|
201
|
+
var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
|
|
202
|
+
var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
|
|
203
|
+
var rmQueryById = (directory) => async (id, version) => {
|
|
204
|
+
await rmResourceById(directory, id, version, { type: "query" });
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/channels.ts
|
|
208
|
+
var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
|
|
209
|
+
var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
|
|
210
|
+
var rmChannel = (directory) => async (path) => {
|
|
211
|
+
await import_promises6.default.rm((0, import_node_path5.join)(directory, path), { recursive: true });
|
|
212
|
+
};
|
|
213
|
+
var rmChannelById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "channel" });
|
|
214
|
+
var versionChannel = (directory) => async (id) => versionResource(directory, id);
|
|
215
|
+
var channelHasVersion = (directory) => async (id, version) => {
|
|
216
|
+
const file = await findFileById(directory, id, version);
|
|
217
|
+
return !!file;
|
|
218
|
+
};
|
|
219
|
+
var addMessageToChannel = (directory, collection) => async (id, _message, version) => {
|
|
220
|
+
let channel = await getChannel(directory)(id, version);
|
|
221
|
+
const functions = {
|
|
222
|
+
events: {
|
|
223
|
+
getMessage: getEvent,
|
|
224
|
+
rmMessageById: rmEventById,
|
|
225
|
+
writeMessage: writeEvent
|
|
226
|
+
},
|
|
227
|
+
commands: {
|
|
228
|
+
getMessage: getCommand,
|
|
229
|
+
rmMessageById: rmCommandById,
|
|
230
|
+
writeMessage: writeCommand
|
|
231
|
+
},
|
|
232
|
+
queries: {
|
|
233
|
+
getMessage: getQuery,
|
|
234
|
+
rmMessageById: rmQueryById,
|
|
235
|
+
writeMessage: writeQuery
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
const { getMessage, rmMessageById, writeMessage } = functions[collection];
|
|
239
|
+
const message = await getMessage(directory)(_message.id, _message.version);
|
|
240
|
+
if (!message) throw new Error(`Message ${_message.id} with version ${_message.version} not found`);
|
|
241
|
+
if (message.channels === void 0) {
|
|
242
|
+
message.channels = [];
|
|
243
|
+
}
|
|
244
|
+
const channelInfo = { id, version: channel.version, ..._message.parameters && { parameters: _message.parameters } };
|
|
245
|
+
message.channels.push(channelInfo);
|
|
246
|
+
await rmMessageById(directory)(_message.id, _message.version);
|
|
247
|
+
await writeMessage(directory)(message);
|
|
248
|
+
};
|
|
249
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
250
|
+
0 && (module.exports = {
|
|
251
|
+
addMessageToChannel,
|
|
252
|
+
channelHasVersion,
|
|
253
|
+
getChannel,
|
|
254
|
+
rmChannel,
|
|
255
|
+
rmChannelById,
|
|
256
|
+
versionChannel,
|
|
257
|
+
writeChannel
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=channels.js.map
|