@kivacore/tanstack-db-generator 0.0.0 → 0.9.7
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 +138 -1
- package/dist/cli.js +1292 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +1216 -0
- package/package.json +41 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1292 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { readFileSync as readFileSync2, existsSync as existsSync3 } from "fs";
|
|
5
|
+
import { resolve, dirname, join as join5 } from "path";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
|
|
8
|
+
// src/generator.ts
|
|
9
|
+
import { join as join4 } from "path";
|
|
10
|
+
|
|
11
|
+
// src/parser.ts
|
|
12
|
+
var DATA_SOURCE_PATH_REGEX = /^\/v1\/apps\/([^\/]+)\/data-sources\/([^\/]+)\/(items)(?:\/\{recordId\})?$/;
|
|
13
|
+
function extractDataSources(spec) {
|
|
14
|
+
const dataSourceMap = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
16
|
+
const match = path.match(DATA_SOURCE_PATH_REGEX);
|
|
17
|
+
if (!match) continue;
|
|
18
|
+
const [
|
|
19
|
+
,
|
|
20
|
+
appName,
|
|
21
|
+
dataSourceName
|
|
22
|
+
] = match;
|
|
23
|
+
const key = `${appName}/${dataSourceName}`;
|
|
24
|
+
let dataSource = dataSourceMap.get(key);
|
|
25
|
+
if (!dataSource) {
|
|
26
|
+
dataSource = {
|
|
27
|
+
appName,
|
|
28
|
+
dataSourceName,
|
|
29
|
+
entityName: getEntityName(appName, dataSourceName),
|
|
30
|
+
endpoints: {}
|
|
31
|
+
};
|
|
32
|
+
dataSourceMap.set(key, dataSource);
|
|
33
|
+
}
|
|
34
|
+
if (pathItem.get) {
|
|
35
|
+
if (path.includes("{recordId}")) {
|
|
36
|
+
dataSource.endpoints.get = createOperationInfo(path, "get", pathItem.get);
|
|
37
|
+
} else {
|
|
38
|
+
dataSource.endpoints.list = createOperationInfo(path, "get", pathItem.get);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (pathItem.post) {
|
|
42
|
+
dataSource.endpoints.create = createOperationInfo(path, "post", pathItem.post);
|
|
43
|
+
}
|
|
44
|
+
if (pathItem.patch) {
|
|
45
|
+
dataSource.endpoints.update = createOperationInfo(path, "patch", pathItem.patch);
|
|
46
|
+
}
|
|
47
|
+
if (pathItem.delete) {
|
|
48
|
+
if (path.includes("{recordId}")) {
|
|
49
|
+
dataSource.endpoints.delete = createOperationInfo(path, "delete", pathItem.delete);
|
|
50
|
+
} else {
|
|
51
|
+
dataSource.endpoints.deleteMany = createOperationInfo(path, "delete", pathItem.delete);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Array.from(dataSourceMap.values());
|
|
56
|
+
}
|
|
57
|
+
function createOperationInfo(path, method, operation) {
|
|
58
|
+
return {
|
|
59
|
+
path,
|
|
60
|
+
method,
|
|
61
|
+
operationId: operation.operationId,
|
|
62
|
+
parameters: operation.parameters,
|
|
63
|
+
requestBody: operation.requestBody,
|
|
64
|
+
responseSchema: extractResponseSchema(operation),
|
|
65
|
+
summary: operation.summary,
|
|
66
|
+
description: operation.description
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function extractResponseSchema(operation) {
|
|
70
|
+
const successResponse = operation.responses?.["200"] || operation.responses?.["201"];
|
|
71
|
+
if (!successResponse?.content?.["application/json"]?.schema) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return successResponse.content["application/json"].schema;
|
|
75
|
+
}
|
|
76
|
+
function getEntityName(appName, dataSourceName) {
|
|
77
|
+
const toPascalCase3 = (str) => str.split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
78
|
+
return `${toPascalCase3(appName)}${toPascalCase3(dataSourceName)}Entity`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/parser-endpoints.ts
|
|
82
|
+
var ENDPOINT_GROUPS = [
|
|
83
|
+
{ name: "users", pattern: /^\/v1\/users/ },
|
|
84
|
+
{ name: "notifications", pattern: /^\/v1\/notifications/ },
|
|
85
|
+
// Support both /v1/enums and /v1/apps/enums
|
|
86
|
+
{ name: "enums", pattern: /^\/v1\/(?:apps\/)?enums/ }
|
|
87
|
+
];
|
|
88
|
+
function extractNonDataSourceEndpoints(spec) {
|
|
89
|
+
const groups = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const group of ENDPOINT_GROUPS) {
|
|
91
|
+
groups.set(group.name, {
|
|
92
|
+
name: group.name,
|
|
93
|
+
basePath: `/v1/${group.name}`,
|
|
94
|
+
endpoints: []
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
98
|
+
if (path.includes("/data-sources/")) continue;
|
|
99
|
+
const group = ENDPOINT_GROUPS.find((g) => g.pattern.test(path));
|
|
100
|
+
if (!group) continue;
|
|
101
|
+
const endpointGroup = groups.get(group.name);
|
|
102
|
+
if (!endpointGroup) continue;
|
|
103
|
+
const methods = [
|
|
104
|
+
"get",
|
|
105
|
+
"post",
|
|
106
|
+
"patch",
|
|
107
|
+
"put",
|
|
108
|
+
"delete"
|
|
109
|
+
];
|
|
110
|
+
for (const method of methods) {
|
|
111
|
+
const operation = pathItem[method];
|
|
112
|
+
if (!operation) continue;
|
|
113
|
+
endpointGroup.endpoints.push({
|
|
114
|
+
path,
|
|
115
|
+
method,
|
|
116
|
+
operationId: operation.operationId || `${method}_${path.replace(/[^a-zA-Z0-9]/g, "_")}`,
|
|
117
|
+
tag: operation.tags?.[0] || group.name,
|
|
118
|
+
operation
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return Array.from(groups.values()).filter((g) => g.endpoints.length > 0);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/generators/collections.ts
|
|
126
|
+
import { writeFileSync } from "fs";
|
|
127
|
+
import { join as join2 } from "path";
|
|
128
|
+
|
|
129
|
+
// src/utils/typegen.ts
|
|
130
|
+
function resolveSchema(schema, spec) {
|
|
131
|
+
if (schema && schema.$ref) {
|
|
132
|
+
const ref = schema.$ref;
|
|
133
|
+
const path = ref.replace("#/", "").split("/");
|
|
134
|
+
let current = spec;
|
|
135
|
+
for (const segment of path) {
|
|
136
|
+
current = current?.[segment];
|
|
137
|
+
if (!current) break;
|
|
138
|
+
}
|
|
139
|
+
return current || {};
|
|
140
|
+
}
|
|
141
|
+
return schema || {};
|
|
142
|
+
}
|
|
143
|
+
function resolveSchemaProperties(schema, spec) {
|
|
144
|
+
let properties = {};
|
|
145
|
+
if (schema.allOf) {
|
|
146
|
+
for (const subSchema of schema.allOf) {
|
|
147
|
+
const resolved = resolveSchema(subSchema, spec);
|
|
148
|
+
if (resolved.properties) {
|
|
149
|
+
const resolvedProps = {};
|
|
150
|
+
for (const [key, value] of Object.entries(resolved.properties)) {
|
|
151
|
+
resolvedProps[key] = resolveSchema(value, spec);
|
|
152
|
+
}
|
|
153
|
+
properties = { ...properties, ...resolvedProps };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (schema.properties) {
|
|
158
|
+
const resolvedProps = {};
|
|
159
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
160
|
+
resolvedProps[key] = resolveSchema(value, spec);
|
|
161
|
+
}
|
|
162
|
+
properties = { ...properties, ...resolvedProps };
|
|
163
|
+
}
|
|
164
|
+
return properties;
|
|
165
|
+
}
|
|
166
|
+
function getTypeScriptType(schema, spec) {
|
|
167
|
+
const isNullable = !!schema.nullable;
|
|
168
|
+
const wrapNullable = (type) => isNullable ? `${type} | null` : type;
|
|
169
|
+
if (schema.allOf) {
|
|
170
|
+
const allOfSchemas = schema.allOf;
|
|
171
|
+
if (allOfSchemas.length === 1) {
|
|
172
|
+
const resolved = resolveSchema(allOfSchemas[0], spec);
|
|
173
|
+
const ref = allOfSchemas[0].$ref;
|
|
174
|
+
if (ref) {
|
|
175
|
+
const typeName = ref.split("/").pop() || "any";
|
|
176
|
+
return wrapNullable(typeName);
|
|
177
|
+
}
|
|
178
|
+
return wrapNullable(getTypeScriptType(resolved, spec));
|
|
179
|
+
}
|
|
180
|
+
let mergedProps = {};
|
|
181
|
+
for (const sub of allOfSchemas) {
|
|
182
|
+
const resolved = resolveSchema(sub, spec);
|
|
183
|
+
const props2 = resolveSchemaProperties(resolved, spec);
|
|
184
|
+
mergedProps = { ...mergedProps, ...props2 };
|
|
185
|
+
}
|
|
186
|
+
const props = Object.entries(mergedProps).map(([key, value]) => `${key}: ${getTypeScriptType(resolveSchema(value, spec), spec)}`).join("; ");
|
|
187
|
+
return wrapNullable(`{ ${props} }`);
|
|
188
|
+
}
|
|
189
|
+
if (schema.oneOf) {
|
|
190
|
+
const types = schema.oneOf.map((s) => getTypeScriptType(resolveSchema(s, spec), spec)).filter((type, index, self) => self.indexOf(type) === index);
|
|
191
|
+
return wrapNullable(types.join(" | "));
|
|
192
|
+
}
|
|
193
|
+
switch (schema.type) {
|
|
194
|
+
case "string":
|
|
195
|
+
if (schema.enum) {
|
|
196
|
+
return wrapNullable(schema.enum.map((v) => `'${v}'`).join(" | "));
|
|
197
|
+
}
|
|
198
|
+
return wrapNullable("string");
|
|
199
|
+
case "number":
|
|
200
|
+
case "integer":
|
|
201
|
+
return wrapNullable("number");
|
|
202
|
+
case "boolean":
|
|
203
|
+
return wrapNullable("boolean");
|
|
204
|
+
case "array":
|
|
205
|
+
if (schema.items) {
|
|
206
|
+
return wrapNullable(`Array<${getTypeScriptType(resolveSchema(schema.items, spec), spec)}>`);
|
|
207
|
+
}
|
|
208
|
+
return wrapNullable("Array<any>");
|
|
209
|
+
case "object":
|
|
210
|
+
if (schema.properties) {
|
|
211
|
+
const props = Object.entries(schema.properties).map(([key, value]) => `${key}: ${getTypeScriptType(resolveSchema(value, spec), spec)}`).join("; ");
|
|
212
|
+
return wrapNullable(`{ ${props} }`);
|
|
213
|
+
}
|
|
214
|
+
return wrapNullable("Record<string, any>");
|
|
215
|
+
default:
|
|
216
|
+
if (schema.properties) {
|
|
217
|
+
const props = Object.entries(schema.properties).map(([key, value]) => `${key}: ${getTypeScriptType(resolveSchema(value, spec), spec)}`).join("; ");
|
|
218
|
+
return wrapNullable(`{ ${props} }`);
|
|
219
|
+
}
|
|
220
|
+
return wrapNullable("any");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function generateInterfaceFromSchema(name, schema, spec) {
|
|
224
|
+
const properties = resolveSchemaProperties(schema, spec);
|
|
225
|
+
const lines = [];
|
|
226
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
227
|
+
const resolved = resolveSchema(propSchema, spec);
|
|
228
|
+
const type = getTypeScriptType(resolved, spec);
|
|
229
|
+
const isOptional = !schema.required?.includes(propName) || !!resolved.readOnly;
|
|
230
|
+
const propDesc = resolved.description ? `
|
|
231
|
+
/** ${sanitizeJsDoc(resolved.description)} */` : "";
|
|
232
|
+
lines.push(`${propDesc}
|
|
233
|
+
${propName}${isOptional ? "?" : ""}: ${type};`);
|
|
234
|
+
}
|
|
235
|
+
const ifaceDesc = schema.description ? `/** ${sanitizeJsDoc(schema.description)} */
|
|
236
|
+
` : "";
|
|
237
|
+
return `${ifaceDesc}export interface ${name} {
|
|
238
|
+
${lines.join("\n")}
|
|
239
|
+
}`;
|
|
240
|
+
}
|
|
241
|
+
function generateInterfacesForNames(spec, names) {
|
|
242
|
+
const out = [];
|
|
243
|
+
const unique = Array.from(new Set(names)).filter((n) => !!n);
|
|
244
|
+
for (const name of unique) {
|
|
245
|
+
const schema = spec.components?.schemas?.[name];
|
|
246
|
+
if (schema) {
|
|
247
|
+
out.push(generateInterfaceFromSchema(name, schema, spec));
|
|
248
|
+
} else {
|
|
249
|
+
out.push(`/** Unresolved schema for ${name}. */
|
|
250
|
+
export interface ${name} { [key: string]: any }`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return out.join("\n\n");
|
|
254
|
+
}
|
|
255
|
+
function sanitizeJsDoc(text) {
|
|
256
|
+
return String(text).replace(/\*\//g, "*/").trim();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/utils/file.ts
|
|
260
|
+
import {
|
|
261
|
+
mkdirSync,
|
|
262
|
+
existsSync,
|
|
263
|
+
readdirSync,
|
|
264
|
+
unlinkSync
|
|
265
|
+
} from "fs";
|
|
266
|
+
import { join } from "path";
|
|
267
|
+
function ensureDirSync(dir) {
|
|
268
|
+
if (!existsSync(dir)) {
|
|
269
|
+
mkdirSync(dir, { recursive: true });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function removeGeneratedCollectionFilesSync(dir) {
|
|
273
|
+
if (!existsSync(dir)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
277
|
+
if (!entry.isFile()) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (!entry.name.endsWith(".collection.ts")) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
unlinkSync(join(dir, entry.name));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/generators/collections.ts
|
|
288
|
+
async function generateCollections(spec, dataSources, outputDir) {
|
|
289
|
+
removeGeneratedCollectionFilesSync(outputDir);
|
|
290
|
+
const typesContent = generateCollectionTypes();
|
|
291
|
+
writeFileSync(join2(outputDir, "types.ts"), typesContent);
|
|
292
|
+
for (const dataSource of dataSources) {
|
|
293
|
+
const collectionContent = generateCollectionFile(spec, dataSource);
|
|
294
|
+
const fileName = `${dataSource.appName}-${dataSource.dataSourceName}.collection.ts`;
|
|
295
|
+
writeFileSync(join2(outputDir, fileName), collectionContent);
|
|
296
|
+
}
|
|
297
|
+
const indexContent = generateCollectionsIndex(dataSources);
|
|
298
|
+
writeFileSync(join2(outputDir, "index.ts"), indexContent);
|
|
299
|
+
}
|
|
300
|
+
function generateCollectionFile(spec, dataSource) {
|
|
301
|
+
const {
|
|
302
|
+
appName,
|
|
303
|
+
dataSourceName,
|
|
304
|
+
entityName,
|
|
305
|
+
endpoints
|
|
306
|
+
} = dataSource;
|
|
307
|
+
const hookName = `use${toPascalCase(appName)}${toPascalCase(dataSourceName)}Collection`;
|
|
308
|
+
const methods = [];
|
|
309
|
+
if (endpoints.list) {
|
|
310
|
+
methods.push(generateListMethod(spec, endpoints.list, entityName));
|
|
311
|
+
}
|
|
312
|
+
if (endpoints.get) {
|
|
313
|
+
methods.push(generateGetMethod(spec, endpoints.get, entityName));
|
|
314
|
+
}
|
|
315
|
+
if (endpoints.create) {
|
|
316
|
+
methods.push(generateCreateMethod(spec, endpoints.create, entityName));
|
|
317
|
+
}
|
|
318
|
+
if (endpoints.update) {
|
|
319
|
+
methods.push(generateUpdateMethod(spec, endpoints.update, entityName));
|
|
320
|
+
}
|
|
321
|
+
if (endpoints.delete) {
|
|
322
|
+
methods.push(generateDeleteMethod(spec, endpoints.delete));
|
|
323
|
+
}
|
|
324
|
+
if (endpoints.deleteMany) {
|
|
325
|
+
methods.push(generateDeleteManyMethod(spec, endpoints.deleteMany));
|
|
326
|
+
}
|
|
327
|
+
const inlineTypes = generateInterfacesForNames(spec, [entityName]);
|
|
328
|
+
return `// Generated collection for ${appName}/${dataSourceName}
|
|
329
|
+
import { useMemo } from 'react';
|
|
330
|
+
import { useDocyrusClient } from '@kivacore/signin';
|
|
331
|
+
import type { QueryParamValue } from '@kivacore/api-client';
|
|
332
|
+
import type { ICollectionListParams } from './types';
|
|
333
|
+
|
|
334
|
+
${inlineTypes ? `${inlineTypes}
|
|
335
|
+
|
|
336
|
+
` : ""}export function ${hookName}() {
|
|
337
|
+
const client = useDocyrusClient();
|
|
338
|
+
|
|
339
|
+
/*
|
|
340
|
+
* Memoize the returned object so its identity is stable across renders.
|
|
341
|
+
* Consumers commonly put the collection in useCallback/useMemo deps
|
|
342
|
+
* (e.g. on a delete/save handler) \u2014 without memoization, every render
|
|
343
|
+
* produces a fresh object, those callbacks rebuild, and any effect that
|
|
344
|
+
* tracks them via deps fires every render. That's what triggers the
|
|
345
|
+
* infinite-loop case in <DataGrid>: an unstable handler reaches the
|
|
346
|
+
* grid's column-applier effect, which calls table.setColumnVisibility
|
|
347
|
+
* \u2192 store.set \u2192 store.notify \u2192 re-render \u2192 unstable collection again.
|
|
348
|
+
*/
|
|
349
|
+
return useMemo(() => ({
|
|
350
|
+
${methods.join(",\n\n")}
|
|
351
|
+
}), [client]);
|
|
352
|
+
}
|
|
353
|
+
`;
|
|
354
|
+
}
|
|
355
|
+
function generateListMethod(spec, endpoint, entityName) {
|
|
356
|
+
const jsDoc = buildDsListJsDoc();
|
|
357
|
+
const url = endpoint.path;
|
|
358
|
+
return ` ${jsDoc}list: (params?: ICollectionListParams): Promise<Array<${entityName}>> => client!.get('${url}', params as Record<string, QueryParamValue> | undefined)`;
|
|
359
|
+
}
|
|
360
|
+
function generateGetMethod(spec, endpoint, entityName) {
|
|
361
|
+
const jsDoc = buildDsJsDoc(spec, endpoint, entityName);
|
|
362
|
+
return ` ${jsDoc}get: (recordId: string, params?: { columns?: Array<string> }): Promise<${entityName}> => client!.get('${endpoint.path}'.replace('{recordId}', recordId), params)`;
|
|
363
|
+
}
|
|
364
|
+
function generateCreateMethod(spec, endpoint, entityName) {
|
|
365
|
+
const jsDoc = buildDsJsDoc(spec, endpoint, entityName);
|
|
366
|
+
return ` ${jsDoc}create: (data: Record<string, any>): Promise<${entityName}> => client!.post('${endpoint.path}', data)`;
|
|
367
|
+
}
|
|
368
|
+
function generateUpdateMethod(spec, endpoint, entityName) {
|
|
369
|
+
const jsDoc = buildDsJsDoc(spec, endpoint, entityName);
|
|
370
|
+
return ` ${jsDoc}update: (recordId: string, data: Record<string, any>): Promise<${entityName}> => client!.patch('${endpoint.path}'.replace('{recordId}', recordId), data)`;
|
|
371
|
+
}
|
|
372
|
+
function generateDeleteMethod(spec, endpoint) {
|
|
373
|
+
const jsDoc = buildDsJsDoc(spec, endpoint, "void");
|
|
374
|
+
return ` ${jsDoc}delete: (recordId: string): Promise<void> => client!.delete('${endpoint.path}'.replace('{recordId}', recordId))`;
|
|
375
|
+
}
|
|
376
|
+
function generateDeleteManyMethod(spec, endpoint) {
|
|
377
|
+
const jsDoc = buildDsJsDoc(spec, endpoint, "void");
|
|
378
|
+
return ` ${jsDoc}deleteMany: (data: { recordIds: Array<string> }): Promise<void> => client!.delete('${endpoint.path}', data)`;
|
|
379
|
+
}
|
|
380
|
+
function generateCollectionsIndex(dataSources) {
|
|
381
|
+
const exports = dataSources.map((ds) => {
|
|
382
|
+
const hookName = `use${toPascalCase(ds.appName)}${toPascalCase(ds.dataSourceName)}Collection`;
|
|
383
|
+
const fileName = `${ds.appName}-${ds.dataSourceName}.collection`;
|
|
384
|
+
return `export { ${hookName} } from './${fileName}';`;
|
|
385
|
+
});
|
|
386
|
+
return `// Generated collections index
|
|
387
|
+
export type { ICollectionListParams, ICollectionFilterRule, ICollectionFilterGroup, ICollectionCalculation, ICollectionOrderBy, ICollectionFormula, ICollectionBlockFormula, ICollectionChildQuery, ICollectionPivotMatrix, ICollectionPivot } from './types';
|
|
388
|
+
${exports.join("\n")}
|
|
389
|
+
`;
|
|
390
|
+
}
|
|
391
|
+
function toPascalCase(str) {
|
|
392
|
+
return str.split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
393
|
+
}
|
|
394
|
+
function buildDsJsDoc(_spec, endpoint, _entityName, _container) {
|
|
395
|
+
const summary = endpoint.summary ? sanitizeJsDoc2(endpoint.summary) : null;
|
|
396
|
+
if (!summary) return "";
|
|
397
|
+
return `/** ${summary} */
|
|
398
|
+
`;
|
|
399
|
+
}
|
|
400
|
+
function sanitizeJsDoc2(text) {
|
|
401
|
+
return String(text).replace(/\*\//g, "*/").trim();
|
|
402
|
+
}
|
|
403
|
+
function generateCollectionTypes() {
|
|
404
|
+
return `// Generated shared types for collections
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* A single filter rule that matches a field against a value using an operator.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* \`\`\`ts
|
|
411
|
+
* // Exact match
|
|
412
|
+
* { field: "status", operator: "eq", value: "active" }
|
|
413
|
+
*
|
|
414
|
+
* // Greater than
|
|
415
|
+
* { field: "amount", operator: "gt", value: 100 }
|
|
416
|
+
*
|
|
417
|
+
* // Contains text
|
|
418
|
+
* { field: "name", operator: "contains", value: "john" }
|
|
419
|
+
*
|
|
420
|
+
* // Is null check
|
|
421
|
+
* { field: "deleted_at", operator: "is_null" }
|
|
422
|
+
*
|
|
423
|
+
* // In list
|
|
424
|
+
* { field: "status", operator: "in", value: ["active", "pending"] }
|
|
425
|
+
*
|
|
426
|
+
* // With filter type for value casting
|
|
427
|
+
* { field: "created_on", operator: "gte", value: "2024-01-01", filterType: "date" }
|
|
428
|
+
* \`\`\`
|
|
429
|
+
*/
|
|
430
|
+
export interface ICollectionFilterRule {
|
|
431
|
+
/** Filter field/column slug */
|
|
432
|
+
field?: string;
|
|
433
|
+
/** Filter operator */
|
|
434
|
+
operator: string;
|
|
435
|
+
/** Filter value. Can be a string, number, boolean, or an array of strings/numbers */
|
|
436
|
+
value?: unknown;
|
|
437
|
+
/** Filter type for value casting */
|
|
438
|
+
filterType?: string | null;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* A group of filter rules combined with a logical combinator.
|
|
443
|
+
* Groups can be nested to create complex filter expressions.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* \`\`\`ts
|
|
447
|
+
* // Simple AND filter
|
|
448
|
+
* {
|
|
449
|
+
* rules: [
|
|
450
|
+
* { field: "status", operator: "eq", value: "active" },
|
|
451
|
+
* { field: "age", operator: "gte", value: 18 }
|
|
452
|
+
* ],
|
|
453
|
+
* combinator: "and"
|
|
454
|
+
* }
|
|
455
|
+
*
|
|
456
|
+
* // Nested OR inside AND
|
|
457
|
+
* {
|
|
458
|
+
* rules: [
|
|
459
|
+
* { field: "status", operator: "eq", value: "active" },
|
|
460
|
+
* {
|
|
461
|
+
* rules: [
|
|
462
|
+
* { field: "role", operator: "eq", value: "admin" },
|
|
463
|
+
* { field: "role", operator: "eq", value: "editor" }
|
|
464
|
+
* ],
|
|
465
|
+
* combinator: "or"
|
|
466
|
+
* }
|
|
467
|
+
* ],
|
|
468
|
+
* combinator: "and"
|
|
469
|
+
* }
|
|
470
|
+
*
|
|
471
|
+
* // Negated group
|
|
472
|
+
* {
|
|
473
|
+
* rules: [{ field: "status", operator: "eq", value: "archived" }],
|
|
474
|
+
* not: true
|
|
475
|
+
* }
|
|
476
|
+
* \`\`\`
|
|
477
|
+
*/
|
|
478
|
+
export interface ICollectionFilterGroup {
|
|
479
|
+
/** List of filter rules or nested groups */
|
|
480
|
+
rules: Array<ICollectionFilterRule | ICollectionFilterGroup>;
|
|
481
|
+
/** Combinator for filter rules (and/or) */
|
|
482
|
+
combinator?: "and" | "or";
|
|
483
|
+
/** Negate the entire filter group */
|
|
484
|
+
not?: boolean;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* An aggregate calculation to apply on a field.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* \`\`\`ts
|
|
492
|
+
* // Sum of amount
|
|
493
|
+
* { func: "sum", field: "amount" }
|
|
494
|
+
*
|
|
495
|
+
* // Count distinct users with alias
|
|
496
|
+
* { func: "count", field: "user_id", isDistinct: true, name: "unique_users" }
|
|
497
|
+
*
|
|
498
|
+
* // Average with alias
|
|
499
|
+
* { func: "avg", field: "score", name: "avg_score" }
|
|
500
|
+
*
|
|
501
|
+
* // Min with number type
|
|
502
|
+
* { func: "min", field: "price", name: "min_price", numberType: "decimal" }
|
|
503
|
+
* \`\`\`
|
|
504
|
+
*/
|
|
505
|
+
export interface ICollectionCalculation {
|
|
506
|
+
/** Aggregation function name (count, sum, avg, min, max) */
|
|
507
|
+
func: string;
|
|
508
|
+
/** Field/column name to aggregate */
|
|
509
|
+
field: string;
|
|
510
|
+
/** Alias for the calculation result column */
|
|
511
|
+
name?: string | null;
|
|
512
|
+
/** Aggregate unique values only */
|
|
513
|
+
isDistinct?: boolean;
|
|
514
|
+
/** Aggregate values greater than this (use only if necessary) */
|
|
515
|
+
minValue?: number | null;
|
|
516
|
+
/** Aggregate values less than this (use only if necessary) */
|
|
517
|
+
maxValue?: number | null;
|
|
518
|
+
/** Number type for the calculation result value */
|
|
519
|
+
numberType?: "bigint" | "int" | "decimal";
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Sort order specification. Can be a string (e.g. "created_on desc"), an object, or an array of objects for multi-column sorting.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* \`\`\`ts
|
|
527
|
+
* // Simple string (e.g. "created_on desc")
|
|
528
|
+
* "created_on desc"
|
|
529
|
+
*
|
|
530
|
+
* // Object with direction
|
|
531
|
+
* { field: "created_on", direction: "desc" }
|
|
532
|
+
*
|
|
533
|
+
* // Multi-column sort
|
|
534
|
+
* [
|
|
535
|
+
* { field: "status", direction: "asc" },
|
|
536
|
+
* { field: "created_on", direction: "desc" }
|
|
537
|
+
* ]
|
|
538
|
+
* \`\`\`
|
|
539
|
+
*/
|
|
540
|
+
export type ICollectionOrderBy = string | { field: string; direction?: "asc" | "desc" } | Array<{ field: string; direction?: "asc" | "desc" }>;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* A simple formula that computes a virtual column using a function and arguments.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* \`\`\`ts
|
|
547
|
+
* // Concatenate columns
|
|
548
|
+
* { func: "concat", args: ["first_name", "' '", "last_name"] }
|
|
549
|
+
*
|
|
550
|
+
* // Arithmetic
|
|
551
|
+
* { func: "multiply", args: ["quantity", "unit_price"] }
|
|
552
|
+
*
|
|
553
|
+
* // Coalesce
|
|
554
|
+
* { func: "coalesce", args: ["nickname", "first_name"] }
|
|
555
|
+
* \`\`\`
|
|
556
|
+
*/
|
|
557
|
+
export interface ICollectionFormula {
|
|
558
|
+
/** Formula function name (e.g. "add", "subtract", "multiply", "divide", "concat", "coalesce") */
|
|
559
|
+
func: string;
|
|
560
|
+
/** Arguments for the formula function (column names or literal values) */
|
|
561
|
+
args: Array<string | number>;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* A block-based formula using a structured expression tree, supporting subqueries.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* \`\`\`ts
|
|
569
|
+
* {
|
|
570
|
+
* expression: {
|
|
571
|
+
* alias: "total_orders",
|
|
572
|
+
* inputs: [{ kind: "aggregate", name: "count", inputs: [] }],
|
|
573
|
+
* from: "orders",
|
|
574
|
+
* with: { "customer_id": "id" },
|
|
575
|
+
* }
|
|
576
|
+
* }
|
|
577
|
+
* \`\`\`
|
|
578
|
+
*/
|
|
579
|
+
export interface ICollectionBlockFormula {
|
|
580
|
+
expression: {
|
|
581
|
+
/** Optional alias for the computed column */
|
|
582
|
+
alias?: string;
|
|
583
|
+
/** Expression tree blocks */
|
|
584
|
+
inputs: Array<Record<string, unknown>>;
|
|
585
|
+
/** Source table for the subquery */
|
|
586
|
+
from: string;
|
|
587
|
+
/** Join condition: column name or mapping of subquery columns to parent columns */
|
|
588
|
+
with: string | Record<string, string>;
|
|
589
|
+
/** Optional filters inside the subquery */
|
|
590
|
+
filters?: ICollectionFilterGroup;
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* A child query definition that fetches related data as a nested array.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* \`\`\`ts
|
|
599
|
+
* {
|
|
600
|
+
* from: "custom_order_items",
|
|
601
|
+
* using: "order_id",
|
|
602
|
+
* columns: ["product_name", "quantity", "price"],
|
|
603
|
+
* filters: {
|
|
604
|
+
* rules: [{ field: "status", operator: "neq", value: "cancelled" }]
|
|
605
|
+
* },
|
|
606
|
+
* orderBy: { field: "quantity", direction: "desc" },
|
|
607
|
+
* limit: 10
|
|
608
|
+
* }
|
|
609
|
+
* \`\`\`
|
|
610
|
+
*/
|
|
611
|
+
export interface ICollectionChildQuery {
|
|
612
|
+
/** The slug of the child data source in "appSlug_slug" format */
|
|
613
|
+
from: string;
|
|
614
|
+
/** The field in child data source that references parent record */
|
|
615
|
+
using: string;
|
|
616
|
+
/** Columns to select from child records */
|
|
617
|
+
columns?: Array<string> | null;
|
|
618
|
+
/** Filters to apply to child records */
|
|
619
|
+
filters?: ICollectionFilterGroup | null;
|
|
620
|
+
/** Aggregations for child records */
|
|
621
|
+
calculations?: Array<ICollectionCalculation> | null;
|
|
622
|
+
/** Sorting for child records. Can be a string, an object, or an array of strings/objects */
|
|
623
|
+
orderBy?: ICollectionOrderBy | null;
|
|
624
|
+
/** Maximum number of child records per parent. Default is 100 */
|
|
625
|
+
limit?: number;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* A single pivot matrix (CTE) query definition for cross-tab / matrix-style queries.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* \`\`\`ts
|
|
633
|
+
* // Pivot by status
|
|
634
|
+
* {
|
|
635
|
+
* using: "id",
|
|
636
|
+
* columns: "status",
|
|
637
|
+
* spread: true
|
|
638
|
+
* }
|
|
639
|
+
*
|
|
640
|
+
* // Pivot by month with date range
|
|
641
|
+
* {
|
|
642
|
+
* using: "id",
|
|
643
|
+
* columns: "month",
|
|
644
|
+
* spread: true,
|
|
645
|
+
* dateRange: {
|
|
646
|
+
* interval: "month",
|
|
647
|
+
* min: "2024-01-01",
|
|
648
|
+
* max: "2024-12-31"
|
|
649
|
+
* }
|
|
650
|
+
* }
|
|
651
|
+
* \`\`\`
|
|
652
|
+
*/
|
|
653
|
+
export interface ICollectionPivotMatrix {
|
|
654
|
+
/** Join this query using this field */
|
|
655
|
+
using: string;
|
|
656
|
+
/** Columns to select from this query */
|
|
657
|
+
columns: string;
|
|
658
|
+
/** Spread jsonb columns as separate columns */
|
|
659
|
+
spread?: boolean;
|
|
660
|
+
/** Filters for matrix query */
|
|
661
|
+
filters?: ICollectionFilterGroup;
|
|
662
|
+
/** Number of records to return */
|
|
663
|
+
limit?: number;
|
|
664
|
+
/** Generate date range series for the query */
|
|
665
|
+
dateRange?: {
|
|
666
|
+
/** Date range interval */
|
|
667
|
+
interval: "day" | "week" | "month" | "year" | "hour" | "minute" | "second";
|
|
668
|
+
/** Number of intervals to increment */
|
|
669
|
+
increment?: number;
|
|
670
|
+
/** Minimum datetime value (ISO format) */
|
|
671
|
+
min: string;
|
|
672
|
+
/** Maximum datetime value (ISO format) */
|
|
673
|
+
max: string;
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Pivot configuration for matrix-style queries.
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* \`\`\`ts
|
|
682
|
+
* {
|
|
683
|
+
* matrix: [
|
|
684
|
+
* {
|
|
685
|
+
* using: "id",
|
|
686
|
+
* columns: "status",
|
|
687
|
+
* spread: true
|
|
688
|
+
* }
|
|
689
|
+
* ],
|
|
690
|
+
* hideEmptyRows: true,
|
|
691
|
+
* orderBy: { field: "name", direction: "asc" },
|
|
692
|
+
* limit: 50
|
|
693
|
+
* }
|
|
694
|
+
* \`\`\`
|
|
695
|
+
*/
|
|
696
|
+
export interface ICollectionPivot {
|
|
697
|
+
/** List of matrix (CTE) queries / data sources */
|
|
698
|
+
matrix: Array<ICollectionPivotMatrix>;
|
|
699
|
+
/** Don't include rows with no matching data */
|
|
700
|
+
hideEmptyRows?: boolean;
|
|
701
|
+
/** Sorting for pivot results. Can be a string, an object, or an array of strings/objects */
|
|
702
|
+
orderBy?: ICollectionOrderBy | null;
|
|
703
|
+
/** Maximum number of pivot result rows. Default is 1000 */
|
|
704
|
+
limit?: number;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Parameters for listing data source records with filtering, sorting, pagination, and more.
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* \`\`\`ts
|
|
712
|
+
* // Basic: fetch specific columns with pagination
|
|
713
|
+
* collection.list({
|
|
714
|
+
* columns: ["name", "email", "status"],
|
|
715
|
+
* limit: 25,
|
|
716
|
+
* offset: 0
|
|
717
|
+
* })
|
|
718
|
+
*
|
|
719
|
+
* // Columns with relation expansion
|
|
720
|
+
* // Fetch related account columns inline using parentheses syntax:
|
|
721
|
+
* // "related_account(name,phone)" => { related_account: { name: "...", phone: "..." } }
|
|
722
|
+
* // Use aliases with ":" prefix:
|
|
723
|
+
* // "f:firstname" => { f: "..." }
|
|
724
|
+
* // Use spread with "..." prefix:
|
|
725
|
+
* // "...related_account(accountName:name)" => { accountName: "..." }
|
|
726
|
+
* collection.list({
|
|
727
|
+
* columns: ["firstname", "lastname", "related_account(name,phone)"],
|
|
728
|
+
* expand: ["related_account"]
|
|
729
|
+
* })
|
|
730
|
+
*
|
|
731
|
+
* // Filtering with nested groups
|
|
732
|
+
* collection.list({
|
|
733
|
+
* filters: {
|
|
734
|
+
* rules: [
|
|
735
|
+
* { field: "status", operator: "eq", value: "active" },
|
|
736
|
+
* {
|
|
737
|
+
* rules: [
|
|
738
|
+
* { field: "role", operator: "eq", value: "admin" },
|
|
739
|
+
* { field: "role", operator: "eq", value: "editor" }
|
|
740
|
+
* ],
|
|
741
|
+
* combinator: "or"
|
|
742
|
+
* }
|
|
743
|
+
* ],
|
|
744
|
+
* combinator: "and"
|
|
745
|
+
* },
|
|
746
|
+
* orderBy: [
|
|
747
|
+
* { field: "created_on", direction: "desc" }
|
|
748
|
+
* ],
|
|
749
|
+
* limit: 50
|
|
750
|
+
* })
|
|
751
|
+
*
|
|
752
|
+
* // Calculations (aggregations)
|
|
753
|
+
* collection.list({
|
|
754
|
+
* calculations: [
|
|
755
|
+
* { func: "sum", field: "amount", name: "total_amount" },
|
|
756
|
+
* { func: "count", field: "id", name: "record_count" }
|
|
757
|
+
* ]
|
|
758
|
+
* })
|
|
759
|
+
*
|
|
760
|
+
* // Formulas (virtual columns)
|
|
761
|
+
* collection.list({
|
|
762
|
+
* columns: ["name"],
|
|
763
|
+
* formulas: {
|
|
764
|
+
* full_address: { func: "concat", args: ["city", "', '", "country"] }
|
|
765
|
+
* }
|
|
766
|
+
* })
|
|
767
|
+
*
|
|
768
|
+
* // Child queries (nested related data)
|
|
769
|
+
* collection.list({
|
|
770
|
+
* columns: ["name", "email"],
|
|
771
|
+
* childQueries: {
|
|
772
|
+
* orders: {
|
|
773
|
+
* from: "custom_orders",
|
|
774
|
+
* using: "customer_id",
|
|
775
|
+
* columns: ["order_date", "total"],
|
|
776
|
+
* orderBy: { field: "order_date", direction: "desc" },
|
|
777
|
+
* limit: 5
|
|
778
|
+
* }
|
|
779
|
+
* }
|
|
780
|
+
* })
|
|
781
|
+
*
|
|
782
|
+
* // Pivot (matrix-style query)
|
|
783
|
+
* collection.list({
|
|
784
|
+
* columns: ["name"],
|
|
785
|
+
* pivot: {
|
|
786
|
+
* matrix: [{
|
|
787
|
+
* using: "id",
|
|
788
|
+
* columns: "status",
|
|
789
|
+
* spread: true
|
|
790
|
+
* }],
|
|
791
|
+
* hideEmptyRows: true
|
|
792
|
+
* }
|
|
793
|
+
* })
|
|
794
|
+
*
|
|
795
|
+
* // Full count with keyword search
|
|
796
|
+
* collection.list({
|
|
797
|
+
* filterKeyword: "john",
|
|
798
|
+
* limit: 10,
|
|
799
|
+
* fullCount: true
|
|
800
|
+
* })
|
|
801
|
+
* \`\`\`
|
|
802
|
+
*/
|
|
803
|
+
export interface ICollectionListParams {
|
|
804
|
+
/**
|
|
805
|
+
* List of columns to fetch.
|
|
806
|
+
*
|
|
807
|
+
* Each column can be specified by its name or as expanded columns inside parentheses.
|
|
808
|
+
* Columns can take aliases using the ":" character and be spread using the "..." prefix.
|
|
809
|
+
* - \`["name", "email"]\` \u2014 fetch columns as-is
|
|
810
|
+
* - \`["related_account(name,phone)"]\` \u2014 expand relation columns
|
|
811
|
+
* - \`["f:firstname"]\` \u2014 alias a column
|
|
812
|
+
* - \`["...related_account(accountName:name)"]\` \u2014 spread relation into top-level keys
|
|
813
|
+
*/
|
|
814
|
+
columns?: Array<string>;
|
|
815
|
+
/** List of distinct columns to deduplicate data. Use only when strictly necessary for performance reasons */
|
|
816
|
+
distinctColumns?: Array<string>;
|
|
817
|
+
/** Second-axis columns for pivotal queries */
|
|
818
|
+
rows?: Array<string>;
|
|
819
|
+
/** Named formulas to compute on the data. Keys are formula names (used as column aliases), values are formula definitions */
|
|
820
|
+
formulas?: Record<string, ICollectionFormula | ICollectionBlockFormula> | null;
|
|
821
|
+
/** Child queries to fetch related records as nested lists */
|
|
822
|
+
childQueries?: Record<string, ICollectionChildQuery> | null;
|
|
823
|
+
/** List of aggregate calculation rules to apply on the result set */
|
|
824
|
+
calculations?: Array<ICollectionCalculation> | null;
|
|
825
|
+
/** Filter rules to narrow down results. Supports nested groups with AND/OR combinators */
|
|
826
|
+
filters?: ICollectionFilterGroup | null;
|
|
827
|
+
/** Keyword to search using full-text search */
|
|
828
|
+
filterKeyword?: string;
|
|
829
|
+
/** List of columns or orderBy rules to sort data. Can be a string (e.g. "created_on desc"), an object, or an array of strings/objects */
|
|
830
|
+
orderBy?: ICollectionOrderBy | null;
|
|
831
|
+
/** Number of records to return. Default is 100 */
|
|
832
|
+
limit?: number;
|
|
833
|
+
/** Number of records to skip for pagination. Default is 0 */
|
|
834
|
+
offset?: number;
|
|
835
|
+
/** Return the total count of records matching the filters */
|
|
836
|
+
fullCount?: boolean;
|
|
837
|
+
/** List of specific fields to expand */
|
|
838
|
+
expand?: Array<string>;
|
|
839
|
+
/** Pivot configuration for matrix-style cross-tab queries */
|
|
840
|
+
pivot?: ICollectionPivot | null;
|
|
841
|
+
}
|
|
842
|
+
`;
|
|
843
|
+
}
|
|
844
|
+
function buildDsListJsDoc() {
|
|
845
|
+
return `/** List records with optional filtering, sorting, and pagination. */
|
|
846
|
+
`;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
// src/generators/endpoint-collections.ts
|
|
850
|
+
import { writeFileSync as writeFileSync2, readFileSync, existsSync as existsSync2 } from "fs";
|
|
851
|
+
import { join as join3 } from "path";
|
|
852
|
+
async function generateEndpointCollections(spec, endpointGroups, outputDir) {
|
|
853
|
+
const exportLines = [];
|
|
854
|
+
for (const group of endpointGroups) {
|
|
855
|
+
const collectionContent = generateEndpointCollectionFile(group, spec);
|
|
856
|
+
const fileName = `${group.name}.collection.ts`;
|
|
857
|
+
writeFileSync2(join3(outputDir, fileName), collectionContent);
|
|
858
|
+
const hookName = `use${toPascalCase2(group.name)}Collection`;
|
|
859
|
+
exportLines.push(`export { ${hookName} } from './${group.name}.collection';`);
|
|
860
|
+
}
|
|
861
|
+
const indexPath = join3(outputDir, "index.ts");
|
|
862
|
+
let indexContent = existsSync2(indexPath) ? readFileSync(indexPath, "utf-8") : `// Generated collections index
|
|
863
|
+
`;
|
|
864
|
+
let updated = false;
|
|
865
|
+
for (const line of exportLines) {
|
|
866
|
+
if (!indexContent.includes(line)) {
|
|
867
|
+
indexContent += `${(indexContent.endsWith("\n") ? "" : "\n") + line}
|
|
868
|
+
`;
|
|
869
|
+
updated = true;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (updated) {
|
|
873
|
+
writeFileSync2(indexPath, indexContent);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function generateEndpointCollectionFile(group, spec) {
|
|
877
|
+
const hookName = `use${toPascalCase2(group.name)}Collection`;
|
|
878
|
+
const methods = group.endpoints.map((endpoint) => {
|
|
879
|
+
return generateEndpointMethod(endpoint, spec);
|
|
880
|
+
}).join(",\n\n");
|
|
881
|
+
const typeNames = getImportTypes(group, spec);
|
|
882
|
+
const inlineTypes = typeNames.length > 0 ? `${generateInterfacesForNames(spec, typeNames)}
|
|
883
|
+
|
|
884
|
+
` : "";
|
|
885
|
+
return `// Generated collection for ${group.name}
|
|
886
|
+
import { useMemo } from 'react';
|
|
887
|
+
import { useDocyrusClient } from '@kivacore/signin';
|
|
888
|
+
|
|
889
|
+
${inlineTypes}export function ${hookName}() {
|
|
890
|
+
const client = useDocyrusClient();
|
|
891
|
+
|
|
892
|
+
// Memoized so the returned object's identity is stable across renders.
|
|
893
|
+
// Same rationale as the data-source collection hooks \u2014 see the comment
|
|
894
|
+
// in collections.ts.
|
|
895
|
+
return useMemo(() => ({
|
|
896
|
+
${methods}
|
|
897
|
+
}), [client]);
|
|
898
|
+
}
|
|
899
|
+
`;
|
|
900
|
+
}
|
|
901
|
+
function generateEndpointMethod(endpoint, spec) {
|
|
902
|
+
const methodName = endpoint.operationId;
|
|
903
|
+
const hasPathParams = endpoint.path.includes("{");
|
|
904
|
+
const pathParams = extractPathParams(endpoint.path);
|
|
905
|
+
const pathParamTypes = getPathParamTypes(endpoint);
|
|
906
|
+
const paramType = getRequestBodyType(endpoint.operation);
|
|
907
|
+
const returnType = getResponseType(endpoint.operation);
|
|
908
|
+
const params = [];
|
|
909
|
+
if (hasPathParams) {
|
|
910
|
+
params.push(...pathParams.map((p) => `${p}: ${pathParamTypes[p] || "string"}`));
|
|
911
|
+
}
|
|
912
|
+
if (endpoint.operation.requestBody) {
|
|
913
|
+
params.push(`data: ${paramType || "any"}`);
|
|
914
|
+
}
|
|
915
|
+
let pathCode = `'${endpoint.path}'`;
|
|
916
|
+
if (hasPathParams) {
|
|
917
|
+
pathParams.forEach((param) => {
|
|
918
|
+
pathCode = `${pathCode}.replace('{${param}}', ${param}.toString())`;
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
const method = endpoint.method.toLowerCase();
|
|
922
|
+
const hasData = endpoint.operation.requestBody;
|
|
923
|
+
const returnTypeAnnotation = returnType ? `: Promise<${returnType}>` : "";
|
|
924
|
+
const genericType = returnType ? `<${returnType}>` : "";
|
|
925
|
+
const jsDoc = buildEndpointJsDoc(endpoint, spec, {
|
|
926
|
+
returnType,
|
|
927
|
+
hasData,
|
|
928
|
+
pathParams,
|
|
929
|
+
pathParamTypes
|
|
930
|
+
});
|
|
931
|
+
return ` ${jsDoc}${methodName}: (${params.join(", ")})${returnTypeAnnotation} => client!.${method}${genericType}(${pathCode}${hasData ? ", data" : ""})`;
|
|
932
|
+
}
|
|
933
|
+
function extractPathParams(path) {
|
|
934
|
+
const matches = path.match(/\{([^}]+)\}/g);
|
|
935
|
+
if (!matches) return [];
|
|
936
|
+
return matches.map((m) => m.slice(1, -1));
|
|
937
|
+
}
|
|
938
|
+
function getImportTypes(group, spec) {
|
|
939
|
+
const types = /* @__PURE__ */ new Set();
|
|
940
|
+
for (const endpoint of group.endpoints) {
|
|
941
|
+
const refs = extractRefsFromOperation(endpoint.operation);
|
|
942
|
+
refs.forEach((ref) => {
|
|
943
|
+
const typeName = ref.split("/").pop();
|
|
944
|
+
if (typeName) types.add(typeName);
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
const visited = /* @__PURE__ */ new Set();
|
|
948
|
+
const queue = Array.from(types);
|
|
949
|
+
while (queue.length > 0) {
|
|
950
|
+
const name = queue.pop();
|
|
951
|
+
if (!name) continue;
|
|
952
|
+
if (visited.has(name)) continue;
|
|
953
|
+
visited.add(name);
|
|
954
|
+
const schema = spec.components?.schemas?.[name];
|
|
955
|
+
if (!schema) continue;
|
|
956
|
+
const nestedRefs = extractRefsFromSchema(schema);
|
|
957
|
+
for (const ref of nestedRefs) {
|
|
958
|
+
const nestedName = ref.split("/").pop();
|
|
959
|
+
if (nestedName && !types.has(nestedName)) {
|
|
960
|
+
types.add(nestedName);
|
|
961
|
+
queue.push(nestedName);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return Array.from(types);
|
|
966
|
+
}
|
|
967
|
+
function extractRefsFromOperation(operation) {
|
|
968
|
+
const refs = [];
|
|
969
|
+
if (operation.requestBody?.content?.["application/json"]?.schema?.$ref) {
|
|
970
|
+
refs.push(operation.requestBody.content["application/json"].schema.$ref);
|
|
971
|
+
}
|
|
972
|
+
Object.values(operation.responses || {}).forEach((response) => {
|
|
973
|
+
if (response.content?.["application/json"]?.schema?.$ref) {
|
|
974
|
+
refs.push(response.content["application/json"].schema.$ref);
|
|
975
|
+
}
|
|
976
|
+
if (response.content?.["application/json"]?.schema?.properties?.data?.$ref) {
|
|
977
|
+
refs.push(response.content["application/json"].schema.properties.data.$ref);
|
|
978
|
+
}
|
|
979
|
+
if (response.content?.["application/json"]?.schema?.properties?.data?.type === "array" && response.content["application/json"].schema.properties.data.items?.$ref) {
|
|
980
|
+
refs.push(response.content["application/json"].schema.properties.data.items.$ref);
|
|
981
|
+
}
|
|
982
|
+
if (response.content?.["application/json"]?.schema?.type === "array" && response.content["application/json"].schema.items?.$ref) {
|
|
983
|
+
refs.push(response.content["application/json"].schema.items.$ref);
|
|
984
|
+
}
|
|
985
|
+
const schema = response.content?.["application/json"]?.schema;
|
|
986
|
+
const dataSchema = schema?.properties?.data;
|
|
987
|
+
if (dataSchema?.type === "object" && dataSchema.patternProperties) {
|
|
988
|
+
const found = findArrayItemRefInPatternProperties(dataSchema);
|
|
989
|
+
if (found?.ref) refs.push(found.ref);
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
return refs;
|
|
993
|
+
}
|
|
994
|
+
function extractRefsFromSchema(schema) {
|
|
995
|
+
const refs = [];
|
|
996
|
+
if (!schema || typeof schema !== "object") return refs;
|
|
997
|
+
if (schema.$ref) {
|
|
998
|
+
refs.push(schema.$ref);
|
|
999
|
+
}
|
|
1000
|
+
if (schema.allOf) {
|
|
1001
|
+
for (const sub of schema.allOf) {
|
|
1002
|
+
refs.push(...extractRefsFromSchema(sub));
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
if (schema.oneOf) {
|
|
1006
|
+
for (const sub of schema.oneOf) {
|
|
1007
|
+
refs.push(...extractRefsFromSchema(sub));
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
if (schema.items) {
|
|
1011
|
+
refs.push(...extractRefsFromSchema(schema.items));
|
|
1012
|
+
}
|
|
1013
|
+
if (schema.properties) {
|
|
1014
|
+
for (const value of Object.values(schema.properties)) {
|
|
1015
|
+
refs.push(...extractRefsFromSchema(value));
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return refs;
|
|
1019
|
+
}
|
|
1020
|
+
function getRequestBodyType(operation) {
|
|
1021
|
+
const { requestBody } = operation;
|
|
1022
|
+
if (!requestBody) return null;
|
|
1023
|
+
if (typeof requestBody === "string" || requestBody.$ref) {
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
if (!requestBody.content?.["application/json"]?.schema) return null;
|
|
1027
|
+
const { schema } = requestBody.content["application/json"];
|
|
1028
|
+
if (schema.$ref) {
|
|
1029
|
+
return schema.$ref.split("/").pop() || null;
|
|
1030
|
+
}
|
|
1031
|
+
return null;
|
|
1032
|
+
}
|
|
1033
|
+
function getResponseType(operation) {
|
|
1034
|
+
const successResponse = operation.responses?.["200"] || operation.responses?.["201"];
|
|
1035
|
+
if (!successResponse?.content?.["application/json"]?.schema) return null;
|
|
1036
|
+
const { schema } = successResponse.content["application/json"];
|
|
1037
|
+
if (schema.$ref) {
|
|
1038
|
+
return schema.$ref.split("/").pop() || null;
|
|
1039
|
+
}
|
|
1040
|
+
if (schema.properties?.data?.$ref) {
|
|
1041
|
+
return schema.properties.data.$ref.split("/").pop() || null;
|
|
1042
|
+
}
|
|
1043
|
+
if (schema.properties?.data?.type === "array" && schema.properties.data.items?.$ref) {
|
|
1044
|
+
const typeName = schema.properties.data.items.$ref.split("/").pop();
|
|
1045
|
+
return typeName ? `Array<${typeName}>` : null;
|
|
1046
|
+
}
|
|
1047
|
+
if (schema.type === "array" && schema.items?.$ref) {
|
|
1048
|
+
const typeName = schema.items.$ref.split("/").pop();
|
|
1049
|
+
return typeName ? `Array<${typeName}>` : null;
|
|
1050
|
+
}
|
|
1051
|
+
if (schema.properties?.data?.type === "object" && schema.properties.data.patternProperties) {
|
|
1052
|
+
const found = findArrayItemRefInPatternProperties(schema.properties.data);
|
|
1053
|
+
if (found && found.typeName && found.depth > 0) {
|
|
1054
|
+
let t = `Array<${found.typeName}>`;
|
|
1055
|
+
for (let i = 0; i < found.depth; i++) {
|
|
1056
|
+
t = `Record<string, ${t}>`;
|
|
1057
|
+
}
|
|
1058
|
+
return t;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return null;
|
|
1062
|
+
}
|
|
1063
|
+
function toPascalCase2(str) {
|
|
1064
|
+
return str.split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
1065
|
+
}
|
|
1066
|
+
function getPathParamTypes(endpoint) {
|
|
1067
|
+
const types = {};
|
|
1068
|
+
const params = endpoint.operation?.parameters || [];
|
|
1069
|
+
for (const p of params) {
|
|
1070
|
+
if (p.in === "path") {
|
|
1071
|
+
const t = getTsTypeFromSchema(p.schema);
|
|
1072
|
+
if (t) types[p.name] = t;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return types;
|
|
1076
|
+
}
|
|
1077
|
+
function getTsTypeFromSchema(schema) {
|
|
1078
|
+
if (!schema) return null;
|
|
1079
|
+
if (schema.$ref) return schema.$ref.split("/").pop() || null;
|
|
1080
|
+
switch (schema.type) {
|
|
1081
|
+
case "string":
|
|
1082
|
+
return "string";
|
|
1083
|
+
case "number":
|
|
1084
|
+
case "integer":
|
|
1085
|
+
return "number";
|
|
1086
|
+
case "boolean":
|
|
1087
|
+
return "boolean";
|
|
1088
|
+
default:
|
|
1089
|
+
return null;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
function findArrayItemRefInPatternProperties(schema) {
|
|
1093
|
+
if (!schema || schema.type !== "object" || !schema.patternProperties) return null;
|
|
1094
|
+
const patterns = schema.patternProperties;
|
|
1095
|
+
for (const key of Object.keys(patterns)) {
|
|
1096
|
+
const node = patterns[key];
|
|
1097
|
+
if (!node) continue;
|
|
1098
|
+
if (node.type === "array" && node.items?.$ref) {
|
|
1099
|
+
const ref = node.items.$ref;
|
|
1100
|
+
const typeName = ref.split("/").pop() || "";
|
|
1101
|
+
return { ref, typeName, depth: 1 };
|
|
1102
|
+
}
|
|
1103
|
+
if (node.type === "object" && node.patternProperties) {
|
|
1104
|
+
const found = findArrayItemRefInPatternProperties(node);
|
|
1105
|
+
if (found) {
|
|
1106
|
+
return { ...found, depth: found.depth + 1 };
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return null;
|
|
1111
|
+
}
|
|
1112
|
+
function buildEndpointJsDoc(endpoint, spec, ctx) {
|
|
1113
|
+
const op = endpoint.operation || {};
|
|
1114
|
+
const lines = [];
|
|
1115
|
+
const title = op.summary || "";
|
|
1116
|
+
const desc = op.description || "";
|
|
1117
|
+
if (title) lines.push(sanitizeJsDoc3(title));
|
|
1118
|
+
if (desc && desc !== title) lines.push(sanitizeJsDoc3(desc));
|
|
1119
|
+
const parameters = Array.isArray(op.parameters) ? op.parameters : [];
|
|
1120
|
+
for (const p of parameters) {
|
|
1121
|
+
const param = resolveParameter(p, spec);
|
|
1122
|
+
if (!param) continue;
|
|
1123
|
+
if (param.in === "path") {
|
|
1124
|
+
lines.push(`@param ${param.name} - ${sanitizeJsDoc3(param.description || "")}`.trim());
|
|
1125
|
+
}
|
|
1126
|
+
if (param.in === "query") {
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
if (ctx.hasData) {
|
|
1130
|
+
lines.push(`@param data - Request body`);
|
|
1131
|
+
}
|
|
1132
|
+
if (ctx.returnType) {
|
|
1133
|
+
lines.push(`@returns ${ctx.returnType}`);
|
|
1134
|
+
}
|
|
1135
|
+
if (lines.length === 0) return "";
|
|
1136
|
+
return `/**
|
|
1137
|
+
* ${lines.join("\n * ")}
|
|
1138
|
+
*/
|
|
1139
|
+
`;
|
|
1140
|
+
}
|
|
1141
|
+
function resolveParameter(p, spec) {
|
|
1142
|
+
if (p && p.$ref) {
|
|
1143
|
+
const ref = p.$ref;
|
|
1144
|
+
const path = ref.replace("#/", "").split("/");
|
|
1145
|
+
let current = spec;
|
|
1146
|
+
for (const seg of path) current = current?.[seg];
|
|
1147
|
+
return current || null;
|
|
1148
|
+
}
|
|
1149
|
+
return p;
|
|
1150
|
+
}
|
|
1151
|
+
function sanitizeJsDoc3(text) {
|
|
1152
|
+
return String(text).replace(/\*\//g, "*/").trim();
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/generator.ts
|
|
1156
|
+
async function generateFromOpenAPI(spec, outputDir, options = {}) {
|
|
1157
|
+
const allDataSources = extractDataSources(spec);
|
|
1158
|
+
const selectedAppNames = normalizeFilterValues(options.apps);
|
|
1159
|
+
const selectedDataSourceKeys = normalizeDataSourceKeys(options.dataSources);
|
|
1160
|
+
const isDataSourceFiltered = selectedAppNames.size > 0 || selectedDataSourceKeys.size > 0;
|
|
1161
|
+
validateAppFilters(allDataSources, selectedAppNames);
|
|
1162
|
+
validateDataSourceFilters(allDataSources, selectedDataSourceKeys);
|
|
1163
|
+
const dataSources = allDataSources.filter((dataSource) => {
|
|
1164
|
+
return matchesAppFilter(dataSource, selectedAppNames) && matchesDataSourceFilter(dataSource, selectedDataSourceKeys);
|
|
1165
|
+
});
|
|
1166
|
+
const endpointGroups = extractNonDataSourceEndpoints(spec);
|
|
1167
|
+
if (isDataSourceFiltered && dataSources.length === 0) {
|
|
1168
|
+
throw new Error("No data sources matched the combined --apps and --dataSources filters");
|
|
1169
|
+
}
|
|
1170
|
+
console.info(`Found ${allDataSources.length} data sources`);
|
|
1171
|
+
if (isDataSourceFiltered) {
|
|
1172
|
+
console.info(`Generating ${dataSources.length} selected data sources`);
|
|
1173
|
+
}
|
|
1174
|
+
console.info(`Found ${endpointGroups.length} endpoint groups`);
|
|
1175
|
+
ensureDirSync(outputDir);
|
|
1176
|
+
ensureDirSync(join4(outputDir, "collections"));
|
|
1177
|
+
await generateCollections(spec, dataSources, join4(outputDir, "collections"));
|
|
1178
|
+
await generateEndpointCollections(spec, endpointGroups, join4(outputDir, "collections"));
|
|
1179
|
+
await generateIndexFile(outputDir);
|
|
1180
|
+
}
|
|
1181
|
+
function normalizeFilterValues(values) {
|
|
1182
|
+
return new Set(
|
|
1183
|
+
(values ?? []).map((value) => value.trim()).filter(Boolean)
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
function normalizeDataSourceKeys(dataSources) {
|
|
1187
|
+
return normalizeFilterValues(dataSources);
|
|
1188
|
+
}
|
|
1189
|
+
function validateAppFilters(dataSources, selectedApps) {
|
|
1190
|
+
const availableApps = new Set(dataSources.map((dataSource) => dataSource.appName));
|
|
1191
|
+
const missingApps = Array.from(selectedApps).filter((appName) => !availableApps.has(appName));
|
|
1192
|
+
if (missingApps.length > 0) {
|
|
1193
|
+
throw new Error(`Unknown apps requested: ${missingApps.join(", ")}`);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
function validateDataSourceFilters(dataSources, selectedKeys) {
|
|
1197
|
+
const availableKeys = new Set(
|
|
1198
|
+
dataSources.map((dataSource) => getDataSourceKey(dataSource))
|
|
1199
|
+
);
|
|
1200
|
+
const missingKeys = Array.from(selectedKeys).filter((key) => !availableKeys.has(key));
|
|
1201
|
+
if (missingKeys.length > 0) {
|
|
1202
|
+
throw new Error(`Unknown data sources requested: ${missingKeys.join(", ")}`);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function matchesAppFilter(dataSource, selectedApps) {
|
|
1206
|
+
return selectedApps.size === 0 || selectedApps.has(dataSource.appName);
|
|
1207
|
+
}
|
|
1208
|
+
function matchesDataSourceFilter(dataSource, selectedKeys) {
|
|
1209
|
+
return selectedKeys.size === 0 || selectedKeys.has(getDataSourceKey(dataSource));
|
|
1210
|
+
}
|
|
1211
|
+
function getDataSourceKey(dataSource) {
|
|
1212
|
+
return `${dataSource.appName}/${dataSource.dataSourceName}`;
|
|
1213
|
+
}
|
|
1214
|
+
async function generateIndexFile(outputDir) {
|
|
1215
|
+
const indexContent = `// Generated by tanstack-db-generator
|
|
1216
|
+
export * from './collections';
|
|
1217
|
+
`;
|
|
1218
|
+
const { writeFileSync: writeFileSync3 } = await import("fs");
|
|
1219
|
+
writeFileSync3(join4(outputDir, "index.ts"), indexContent);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
// src/cli.ts
|
|
1223
|
+
var program = new Command();
|
|
1224
|
+
program.name("tanstack-db-generator").description("Generate TanStack Query collections and TypeScript types from OpenAPI 3.1.0 specification").version("0.0.0").argument("<openapi-spec>", "Path to OpenAPI 3.1.0 specification file (JSON format)").option("-o, --output <dir>", "Output directory (defaults to src in same folder as spec file)").option(
|
|
1225
|
+
"--apps <appSlugs...>",
|
|
1226
|
+
"Generate only data source collections for the matching app slugs. Use one or more appSlug values separated by spaces."
|
|
1227
|
+
).option(
|
|
1228
|
+
"--dataSources <pairs...>",
|
|
1229
|
+
"Generate only the matching data source collections. Use appSlug/dataSourceSlug pairs separated by spaces."
|
|
1230
|
+
).option("-w, --watch", "Watch for changes in the OpenAPI spec file").action(async (specPath, options) => {
|
|
1231
|
+
try {
|
|
1232
|
+
const resolvedPath = resolve(specPath);
|
|
1233
|
+
if (!existsSync3(resolvedPath)) {
|
|
1234
|
+
console.warn(`Error: OpenAPI spec file not found: ${resolvedPath}`);
|
|
1235
|
+
process.exit(1);
|
|
1236
|
+
}
|
|
1237
|
+
const outputDir = options.output || join5(dirname(resolvedPath), "src");
|
|
1238
|
+
console.info("\u{1F680} TanStack DB Generator");
|
|
1239
|
+
console.info(`Spec file: ${resolvedPath}`);
|
|
1240
|
+
console.info(`Output directory: ${outputDir}`);
|
|
1241
|
+
const selectedApps = parseAppSlugs(options.apps);
|
|
1242
|
+
const selectedDataSources = parseDataSourcePairs(options.dataSources);
|
|
1243
|
+
if (selectedApps.length > 0) {
|
|
1244
|
+
console.info(`Filtered apps: ${selectedApps.join(", ")}`);
|
|
1245
|
+
}
|
|
1246
|
+
if (selectedDataSources.length > 0) {
|
|
1247
|
+
console.info(`Filtered data sources: ${selectedDataSources.join(", ")}`);
|
|
1248
|
+
}
|
|
1249
|
+
const specContent = readFileSync2(resolvedPath, "utf-8");
|
|
1250
|
+
const spec = JSON.parse(specContent);
|
|
1251
|
+
if (spec.openapi !== "3.1.0") {
|
|
1252
|
+
console.warn(`Error: Expected OpenAPI version 3.1.0, got ${spec.openapi}`);
|
|
1253
|
+
process.exit(1);
|
|
1254
|
+
}
|
|
1255
|
+
await generateFromOpenAPI(spec, outputDir, {
|
|
1256
|
+
apps: selectedApps,
|
|
1257
|
+
dataSources: selectedDataSources
|
|
1258
|
+
});
|
|
1259
|
+
console.info("\u2705 Generation completed successfully!");
|
|
1260
|
+
if (options.watch) {
|
|
1261
|
+
console.info("\u{1F440} Watching for changes...");
|
|
1262
|
+
}
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
console.warn("Error:", error);
|
|
1265
|
+
process.exit(1);
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
program.parse();
|
|
1269
|
+
function parseDataSourcePairs(input) {
|
|
1270
|
+
return parseOptionValues(input).map((value) => {
|
|
1271
|
+
if (!/^[^/\s]+\/[^/\s]+$/.test(value)) {
|
|
1272
|
+
throw new Error(
|
|
1273
|
+
`Invalid data source selector "${value}". Expected appSlug/dataSourceSlug.`
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
return value;
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
function parseAppSlugs(input) {
|
|
1280
|
+
return parseOptionValues(input).map((value) => {
|
|
1281
|
+
if (!/^[^/\s]+$/.test(value)) {
|
|
1282
|
+
throw new Error(`Invalid app selector "${value}". Expected appSlug.`);
|
|
1283
|
+
}
|
|
1284
|
+
return value;
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
function parseOptionValues(input) {
|
|
1288
|
+
if (!input || input.length === 0) {
|
|
1289
|
+
return [];
|
|
1290
|
+
}
|
|
1291
|
+
return input.flatMap((value) => value.split(",")).map((value) => value.trim()).filter(Boolean);
|
|
1292
|
+
}
|