eventmodeler 0.6.0 → 0.6.2

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.
Files changed (73) hide show
  1. package/dist/index.js +7133 -34
  2. package/package.json +5 -4
  3. package/dist/api/client-config.js +0 -10
  4. package/dist/api/generated/client/client.gen.js +0 -235
  5. package/dist/api/generated/client/index.js +0 -6
  6. package/dist/api/generated/client/types.gen.js +0 -2
  7. package/dist/api/generated/client/utils.gen.js +0 -228
  8. package/dist/api/generated/client.gen.js +0 -4
  9. package/dist/api/generated/core/auth.gen.js +0 -14
  10. package/dist/api/generated/core/bodySerializer.gen.js +0 -57
  11. package/dist/api/generated/core/params.gen.js +0 -100
  12. package/dist/api/generated/core/pathSerializer.gen.js +0 -106
  13. package/dist/api/generated/core/queryKeySerializer.gen.js +0 -92
  14. package/dist/api/generated/core/serverSentEvents.gen.js +0 -133
  15. package/dist/api/generated/core/types.gen.js +0 -2
  16. package/dist/api/generated/core/utils.gen.js +0 -87
  17. package/dist/api/generated/index.js +0 -2
  18. package/dist/api/generated/sdk.gen.js +0 -4222
  19. package/dist/api/generated/types.gen.js +0 -2
  20. package/dist/api/generated/zod.gen.js +0 -7217
  21. package/dist/commands/add.js +0 -315
  22. package/dist/commands/auth.js +0 -14
  23. package/dist/commands/create.js +0 -192
  24. package/dist/commands/design.js +0 -108
  25. package/dist/commands/guide.js +0 -15
  26. package/dist/commands/init.js +0 -21
  27. package/dist/commands/list-schemas.js +0 -177
  28. package/dist/commands/list.js +0 -39
  29. package/dist/commands/loop.js +0 -101
  30. package/dist/commands/map.js +0 -40
  31. package/dist/commands/mark.js +0 -27
  32. package/dist/commands/move.js +0 -35
  33. package/dist/commands/remove.js +0 -170
  34. package/dist/commands/rename.js +0 -53
  35. package/dist/commands/resize.js +0 -30
  36. package/dist/commands/search.js +0 -14
  37. package/dist/commands/set.js +0 -199
  38. package/dist/commands/show-schemas.js +0 -259
  39. package/dist/commands/show.js +0 -56
  40. package/dist/commands/summary.js +0 -13
  41. package/dist/commands/update.js +0 -240
  42. package/dist/lib/auth.js +0 -331
  43. package/dist/lib/config.js +0 -80
  44. package/dist/lib/excalidraw-schema.js +0 -66
  45. package/dist/lib/globals.js +0 -8
  46. package/dist/lib/model.js +0 -11
  47. package/dist/lib/project-config.js +0 -103
  48. package/dist/lib/resolve.js +0 -59
  49. package/dist/lib/scenario.js +0 -15
  50. package/dist/slices/add-scenario/index.js +0 -103
  51. package/dist/slices/guide/guides/codegen.js +0 -339
  52. package/dist/slices/guide/guides/connect-slices.js +0 -202
  53. package/dist/slices/guide/guides/create-slices.js +0 -273
  54. package/dist/slices/guide/guides/explore.js +0 -238
  55. package/dist/slices/guide/guides/information-flow.js +0 -304
  56. package/dist/slices/guide/guides/scenarios.js +0 -214
  57. package/dist/slices/guide/index.js +0 -40
  58. package/dist/slices/help/index.js +0 -96
  59. package/dist/slices/help/topics/build-codegen.js +0 -109
  60. package/dist/slices/help/topics/build-slice.js +0 -147
  61. package/dist/slices/help/topics/check-completeness.js +0 -57
  62. package/dist/slices/help/topics/connect-slices.js +0 -99
  63. package/dist/slices/help/topics/explore-model.js +0 -112
  64. package/dist/slices/help/topics/json-reference.js +0 -188
  65. package/dist/slices/help/topics/linked-copies.js +0 -89
  66. package/dist/slices/help/topics/manipulate-canvas.js +0 -150
  67. package/dist/slices/help/topics/write-scenarios.js +0 -162
  68. package/dist/slices/init/index.js +0 -86
  69. package/dist/slices/init/loop.js +0 -60
  70. package/dist/slices/login/index.js +0 -20
  71. package/dist/slices/logout/index.js +0 -14
  72. package/dist/slices/open-app/index.js +0 -36
  73. package/dist/slices/whoami/index.js +0 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eventmodeler",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "CLI tool for event modeling - explore, design, and generate code from your event models",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,9 +12,10 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "generate": "openapi-ts",
15
- "build": "tsc",
16
- "dev": "tsc --watch",
17
- "prepublishOnly": "bun run generate && bun run build || npm run build"
15
+ "build": "bun build src/index.ts --outfile dist/index.js --target node --format esm --external commander --external zod --external @hey-api/client-fetch",
16
+ "typecheck": "tsc --noEmit",
17
+ "dev": "bun build src/index.ts --outfile dist/index.js --target node --format esm --external commander --external zod --external @hey-api/client-fetch --watch",
18
+ "prepublishOnly": "bun run build"
18
19
  },
19
20
  "keywords": [
20
21
  "event-modeling",
@@ -1,10 +0,0 @@
1
- import { getBackendUrl } from '../lib/config';
2
- import { getValidAccessToken } from '../lib/auth';
3
- export const createClientConfig = (config) => ({
4
- ...config,
5
- baseUrl: getBackendUrl(),
6
- auth: async () => {
7
- const token = await getValidAccessToken();
8
- return token ?? '';
9
- },
10
- });
@@ -1,235 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- import { createSseClient } from '../core/serverSentEvents.gen';
3
- import { getValidRequestBody } from '../core/utils.gen';
4
- import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils.gen';
5
- export const createClient = (config = {}) => {
6
- let _config = mergeConfigs(createConfig(), config);
7
- const getConfig = () => ({ ..._config });
8
- const setConfig = (config) => {
9
- _config = mergeConfigs(_config, config);
10
- return getConfig();
11
- };
12
- const interceptors = createInterceptors();
13
- const beforeRequest = async (options) => {
14
- const opts = {
15
- ..._config,
16
- ...options,
17
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
18
- headers: mergeHeaders(_config.headers, options.headers),
19
- serializedBody: undefined,
20
- };
21
- if (opts.security) {
22
- await setAuthParams({
23
- ...opts,
24
- security: opts.security,
25
- });
26
- }
27
- if (opts.requestValidator) {
28
- await opts.requestValidator(opts);
29
- }
30
- if (opts.body !== undefined && opts.bodySerializer) {
31
- opts.serializedBody = opts.bodySerializer(opts.body);
32
- }
33
- // remove Content-Type header if body is empty to avoid sending invalid requests
34
- if (opts.body === undefined || opts.serializedBody === '') {
35
- opts.headers.delete('Content-Type');
36
- }
37
- const url = buildUrl(opts);
38
- return { opts, url };
39
- };
40
- const request = async (options) => {
41
- // @ts-expect-error
42
- const { opts, url } = await beforeRequest(options);
43
- const requestInit = {
44
- redirect: 'follow',
45
- ...opts,
46
- body: getValidRequestBody(opts),
47
- };
48
- let request = new Request(url, requestInit);
49
- for (const fn of interceptors.request.fns) {
50
- if (fn) {
51
- request = await fn(request, opts);
52
- }
53
- }
54
- // fetch must be assigned here, otherwise it would throw the error:
55
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
56
- const _fetch = opts.fetch;
57
- let response;
58
- try {
59
- response = await _fetch(request);
60
- }
61
- catch (error) {
62
- // Handle fetch exceptions (AbortError, network errors, etc.)
63
- let finalError = error;
64
- for (const fn of interceptors.error.fns) {
65
- if (fn) {
66
- finalError = (await fn(error, undefined, request, opts));
67
- }
68
- }
69
- finalError = finalError || {};
70
- if (opts.throwOnError) {
71
- throw finalError;
72
- }
73
- // Return error response
74
- return opts.responseStyle === 'data'
75
- ? undefined
76
- : {
77
- error: finalError,
78
- request,
79
- response: undefined,
80
- };
81
- }
82
- for (const fn of interceptors.response.fns) {
83
- if (fn) {
84
- response = await fn(response, request, opts);
85
- }
86
- }
87
- const result = {
88
- request,
89
- response,
90
- };
91
- if (response.ok) {
92
- const parseAs = (opts.parseAs === 'auto'
93
- ? getParseAs(response.headers.get('Content-Type'))
94
- : opts.parseAs) ?? 'json';
95
- if (response.status === 204 || response.headers.get('Content-Length') === '0') {
96
- let emptyData;
97
- switch (parseAs) {
98
- case 'arrayBuffer':
99
- case 'blob':
100
- case 'text':
101
- emptyData = await response[parseAs]();
102
- break;
103
- case 'formData':
104
- emptyData = new FormData();
105
- break;
106
- case 'stream':
107
- emptyData = response.body;
108
- break;
109
- case 'json':
110
- default:
111
- emptyData = {};
112
- break;
113
- }
114
- return opts.responseStyle === 'data'
115
- ? emptyData
116
- : {
117
- data: emptyData,
118
- ...result,
119
- };
120
- }
121
- let data;
122
- switch (parseAs) {
123
- case 'arrayBuffer':
124
- case 'blob':
125
- case 'formData':
126
- case 'text':
127
- data = await response[parseAs]();
128
- break;
129
- case 'json': {
130
- // Some servers return 200 with no Content-Length and empty body.
131
- // response.json() would throw; read as text and parse if non-empty.
132
- const text = await response.text();
133
- data = text ? JSON.parse(text) : {};
134
- break;
135
- }
136
- case 'stream':
137
- return opts.responseStyle === 'data'
138
- ? response.body
139
- : {
140
- data: response.body,
141
- ...result,
142
- };
143
- }
144
- if (parseAs === 'json') {
145
- if (opts.responseValidator) {
146
- await opts.responseValidator(data);
147
- }
148
- if (opts.responseTransformer) {
149
- data = await opts.responseTransformer(data);
150
- }
151
- }
152
- return opts.responseStyle === 'data'
153
- ? data
154
- : {
155
- data,
156
- ...result,
157
- };
158
- }
159
- const textError = await response.text();
160
- let jsonError;
161
- try {
162
- jsonError = JSON.parse(textError);
163
- }
164
- catch {
165
- // noop
166
- }
167
- const error = jsonError ?? textError;
168
- let finalError = error;
169
- for (const fn of interceptors.error.fns) {
170
- if (fn) {
171
- finalError = (await fn(error, response, request, opts));
172
- }
173
- }
174
- finalError = finalError || {};
175
- if (opts.throwOnError) {
176
- throw finalError;
177
- }
178
- // TODO: we probably want to return error and improve types
179
- return opts.responseStyle === 'data'
180
- ? undefined
181
- : {
182
- error: finalError,
183
- ...result,
184
- };
185
- };
186
- const makeMethodFn = (method) => (options) => request({ ...options, method });
187
- const makeSseFn = (method) => async (options) => {
188
- const { opts, url } = await beforeRequest(options);
189
- return createSseClient({
190
- ...opts,
191
- body: opts.body,
192
- headers: opts.headers,
193
- method,
194
- onRequest: async (url, init) => {
195
- let request = new Request(url, init);
196
- for (const fn of interceptors.request.fns) {
197
- if (fn) {
198
- request = await fn(request, opts);
199
- }
200
- }
201
- return request;
202
- },
203
- serializedBody: getValidRequestBody(opts),
204
- url,
205
- });
206
- };
207
- const _buildUrl = (options) => buildUrl({ ..._config, ...options });
208
- return {
209
- buildUrl: _buildUrl,
210
- connect: makeMethodFn('CONNECT'),
211
- delete: makeMethodFn('DELETE'),
212
- get: makeMethodFn('GET'),
213
- getConfig,
214
- head: makeMethodFn('HEAD'),
215
- interceptors,
216
- options: makeMethodFn('OPTIONS'),
217
- patch: makeMethodFn('PATCH'),
218
- post: makeMethodFn('POST'),
219
- put: makeMethodFn('PUT'),
220
- request,
221
- setConfig,
222
- sse: {
223
- connect: makeSseFn('CONNECT'),
224
- delete: makeSseFn('DELETE'),
225
- get: makeSseFn('GET'),
226
- head: makeSseFn('HEAD'),
227
- options: makeSseFn('OPTIONS'),
228
- patch: makeSseFn('PATCH'),
229
- post: makeSseFn('POST'),
230
- put: makeSseFn('PUT'),
231
- trace: makeSseFn('TRACE'),
232
- },
233
- trace: makeMethodFn('TRACE'),
234
- };
235
- };
@@ -1,6 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
3
- export { buildClientParams } from '../core/params.gen';
4
- export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
5
- export { createClient } from './client.gen';
6
- export { createConfig, mergeHeaders } from './utils.gen';
@@ -1,2 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- export {};
@@ -1,228 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- import { getAuthToken } from '../core/auth.gen';
3
- import { jsonBodySerializer } from '../core/bodySerializer.gen';
4
- import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from '../core/pathSerializer.gen';
5
- import { getUrl } from '../core/utils.gen';
6
- export const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
7
- const querySerializer = (queryParams) => {
8
- const search = [];
9
- if (queryParams && typeof queryParams === 'object') {
10
- for (const name in queryParams) {
11
- const value = queryParams[name];
12
- if (value === undefined || value === null) {
13
- continue;
14
- }
15
- const options = parameters[name] || args;
16
- if (Array.isArray(value)) {
17
- const serializedArray = serializeArrayParam({
18
- allowReserved: options.allowReserved,
19
- explode: true,
20
- name,
21
- style: 'form',
22
- value,
23
- ...options.array,
24
- });
25
- if (serializedArray)
26
- search.push(serializedArray);
27
- }
28
- else if (typeof value === 'object') {
29
- const serializedObject = serializeObjectParam({
30
- allowReserved: options.allowReserved,
31
- explode: true,
32
- name,
33
- style: 'deepObject',
34
- value: value,
35
- ...options.object,
36
- });
37
- if (serializedObject)
38
- search.push(serializedObject);
39
- }
40
- else {
41
- const serializedPrimitive = serializePrimitiveParam({
42
- allowReserved: options.allowReserved,
43
- name,
44
- value: value,
45
- });
46
- if (serializedPrimitive)
47
- search.push(serializedPrimitive);
48
- }
49
- }
50
- }
51
- return search.join('&');
52
- };
53
- return querySerializer;
54
- };
55
- /**
56
- * Infers parseAs value from provided Content-Type header.
57
- */
58
- export const getParseAs = (contentType) => {
59
- if (!contentType) {
60
- // If no Content-Type header is provided, the best we can do is return the raw response body,
61
- // which is effectively the same as the 'stream' option.
62
- return 'stream';
63
- }
64
- const cleanContent = contentType.split(';')[0]?.trim();
65
- if (!cleanContent) {
66
- return;
67
- }
68
- if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
69
- return 'json';
70
- }
71
- if (cleanContent === 'multipart/form-data') {
72
- return 'formData';
73
- }
74
- if (['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))) {
75
- return 'blob';
76
- }
77
- if (cleanContent.startsWith('text/')) {
78
- return 'text';
79
- }
80
- return;
81
- };
82
- const checkForExistence = (options, name) => {
83
- if (!name) {
84
- return false;
85
- }
86
- if (options.headers.has(name) ||
87
- options.query?.[name] ||
88
- options.headers.get('Cookie')?.includes(`${name}=`)) {
89
- return true;
90
- }
91
- return false;
92
- };
93
- export const setAuthParams = async ({ security, ...options }) => {
94
- for (const auth of security) {
95
- if (checkForExistence(options, auth.name)) {
96
- continue;
97
- }
98
- const token = await getAuthToken(auth, options.auth);
99
- if (!token) {
100
- continue;
101
- }
102
- const name = auth.name ?? 'Authorization';
103
- switch (auth.in) {
104
- case 'query':
105
- if (!options.query) {
106
- options.query = {};
107
- }
108
- options.query[name] = token;
109
- break;
110
- case 'cookie':
111
- options.headers.append('Cookie', `${name}=${token}`);
112
- break;
113
- case 'header':
114
- default:
115
- options.headers.set(name, token);
116
- break;
117
- }
118
- }
119
- };
120
- export const buildUrl = (options) => getUrl({
121
- baseUrl: options.baseUrl,
122
- path: options.path,
123
- query: options.query,
124
- querySerializer: typeof options.querySerializer === 'function'
125
- ? options.querySerializer
126
- : createQuerySerializer(options.querySerializer),
127
- url: options.url,
128
- });
129
- export const mergeConfigs = (a, b) => {
130
- const config = { ...a, ...b };
131
- if (config.baseUrl?.endsWith('/')) {
132
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
133
- }
134
- config.headers = mergeHeaders(a.headers, b.headers);
135
- return config;
136
- };
137
- const headersEntries = (headers) => {
138
- const entries = [];
139
- headers.forEach((value, key) => {
140
- entries.push([key, value]);
141
- });
142
- return entries;
143
- };
144
- export const mergeHeaders = (...headers) => {
145
- const mergedHeaders = new Headers();
146
- for (const header of headers) {
147
- if (!header) {
148
- continue;
149
- }
150
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
151
- for (const [key, value] of iterator) {
152
- if (value === null) {
153
- mergedHeaders.delete(key);
154
- }
155
- else if (Array.isArray(value)) {
156
- for (const v of value) {
157
- mergedHeaders.append(key, v);
158
- }
159
- }
160
- else if (value !== undefined) {
161
- // assume object headers are meant to be JSON stringified, i.e., their
162
- // content value in OpenAPI specification is 'application/json'
163
- mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
164
- }
165
- }
166
- }
167
- return mergedHeaders;
168
- };
169
- class Interceptors {
170
- fns = [];
171
- clear() {
172
- this.fns = [];
173
- }
174
- eject(id) {
175
- const index = this.getInterceptorIndex(id);
176
- if (this.fns[index]) {
177
- this.fns[index] = null;
178
- }
179
- }
180
- exists(id) {
181
- const index = this.getInterceptorIndex(id);
182
- return Boolean(this.fns[index]);
183
- }
184
- getInterceptorIndex(id) {
185
- if (typeof id === 'number') {
186
- return this.fns[id] ? id : -1;
187
- }
188
- return this.fns.indexOf(id);
189
- }
190
- update(id, fn) {
191
- const index = this.getInterceptorIndex(id);
192
- if (this.fns[index]) {
193
- this.fns[index] = fn;
194
- return id;
195
- }
196
- return false;
197
- }
198
- use(fn) {
199
- this.fns.push(fn);
200
- return this.fns.length - 1;
201
- }
202
- }
203
- export const createInterceptors = () => ({
204
- error: new Interceptors(),
205
- request: new Interceptors(),
206
- response: new Interceptors(),
207
- });
208
- const defaultQuerySerializer = createQuerySerializer({
209
- allowReserved: false,
210
- array: {
211
- explode: true,
212
- style: 'form',
213
- },
214
- object: {
215
- explode: true,
216
- style: 'deepObject',
217
- },
218
- });
219
- const defaultHeaders = {
220
- 'Content-Type': 'application/json',
221
- };
222
- export const createConfig = (override = {}) => ({
223
- ...jsonBodySerializer,
224
- headers: defaultHeaders,
225
- parseAs: 'auto',
226
- querySerializer: defaultQuerySerializer,
227
- ...override,
228
- });
@@ -1,4 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- import { createClientConfig } from '../client-config';
3
- import { createClient, createConfig } from './client';
4
- export const client = createClient(createClientConfig(createConfig({ baseUrl: 'http://localhost:8080' })));
@@ -1,14 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- export const getAuthToken = async (auth, callback) => {
3
- const token = typeof callback === 'function' ? await callback(auth) : callback;
4
- if (!token) {
5
- return;
6
- }
7
- if (auth.scheme === 'bearer') {
8
- return `Bearer ${token}`;
9
- }
10
- if (auth.scheme === 'basic') {
11
- return `Basic ${btoa(token)}`;
12
- }
13
- return token;
14
- };
@@ -1,57 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- const serializeFormDataPair = (data, key, value) => {
3
- if (typeof value === 'string' || value instanceof Blob) {
4
- data.append(key, value);
5
- }
6
- else if (value instanceof Date) {
7
- data.append(key, value.toISOString());
8
- }
9
- else {
10
- data.append(key, JSON.stringify(value));
11
- }
12
- };
13
- const serializeUrlSearchParamsPair = (data, key, value) => {
14
- if (typeof value === 'string') {
15
- data.append(key, value);
16
- }
17
- else {
18
- data.append(key, JSON.stringify(value));
19
- }
20
- };
21
- export const formDataBodySerializer = {
22
- bodySerializer: (body) => {
23
- const data = new FormData();
24
- Object.entries(body).forEach(([key, value]) => {
25
- if (value === undefined || value === null) {
26
- return;
27
- }
28
- if (Array.isArray(value)) {
29
- value.forEach((v) => serializeFormDataPair(data, key, v));
30
- }
31
- else {
32
- serializeFormDataPair(data, key, value);
33
- }
34
- });
35
- return data;
36
- },
37
- };
38
- export const jsonBodySerializer = {
39
- bodySerializer: (body) => JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
40
- };
41
- export const urlSearchParamsBodySerializer = {
42
- bodySerializer: (body) => {
43
- const data = new URLSearchParams();
44
- Object.entries(body).forEach(([key, value]) => {
45
- if (value === undefined || value === null) {
46
- return;
47
- }
48
- if (Array.isArray(value)) {
49
- value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
50
- }
51
- else {
52
- serializeUrlSearchParamsPair(data, key, value);
53
- }
54
- });
55
- return data.toString();
56
- },
57
- };
@@ -1,100 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- const extraPrefixesMap = {
3
- $body_: 'body',
4
- $headers_: 'headers',
5
- $path_: 'path',
6
- $query_: 'query',
7
- };
8
- const extraPrefixes = Object.entries(extraPrefixesMap);
9
- const buildKeyMap = (fields, map) => {
10
- if (!map) {
11
- map = new Map();
12
- }
13
- for (const config of fields) {
14
- if ('in' in config) {
15
- if (config.key) {
16
- map.set(config.key, {
17
- in: config.in,
18
- map: config.map,
19
- });
20
- }
21
- }
22
- else if ('key' in config) {
23
- map.set(config.key, {
24
- map: config.map,
25
- });
26
- }
27
- else if (config.args) {
28
- buildKeyMap(config.args, map);
29
- }
30
- }
31
- return map;
32
- };
33
- const stripEmptySlots = (params) => {
34
- for (const [slot, value] of Object.entries(params)) {
35
- if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
36
- delete params[slot];
37
- }
38
- }
39
- };
40
- export const buildClientParams = (args, fields) => {
41
- const params = {
42
- body: {},
43
- headers: {},
44
- path: {},
45
- query: {},
46
- };
47
- const map = buildKeyMap(fields);
48
- let config;
49
- for (const [index, arg] of args.entries()) {
50
- if (fields[index]) {
51
- config = fields[index];
52
- }
53
- if (!config) {
54
- continue;
55
- }
56
- if ('in' in config) {
57
- if (config.key) {
58
- const field = map.get(config.key);
59
- const name = field.map || config.key;
60
- if (field.in) {
61
- params[field.in][name] = arg;
62
- }
63
- }
64
- else {
65
- params.body = arg;
66
- }
67
- }
68
- else {
69
- for (const [key, value] of Object.entries(arg ?? {})) {
70
- const field = map.get(key);
71
- if (field) {
72
- if (field.in) {
73
- const name = field.map || key;
74
- params[field.in][name] = value;
75
- }
76
- else {
77
- params[field.map] = value;
78
- }
79
- }
80
- else {
81
- const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
82
- if (extra) {
83
- const [prefix, slot] = extra;
84
- params[slot][key.slice(prefix.length)] = value;
85
- }
86
- else if ('allowExtra' in config && config.allowExtra) {
87
- for (const [slot, allowed] of Object.entries(config.allowExtra)) {
88
- if (allowed) {
89
- params[slot][key] = value;
90
- break;
91
- }
92
- }
93
- }
94
- }
95
- }
96
- }
97
- }
98
- stripEmptySlots(params);
99
- return params;
100
- };