@pikku/cli 0.12.4 → 0.12.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/cli.schema.json +1 -1
- package/console-app/assets/{index-AX4YS8AA.js → index-sUj3oFEL.js} +1 -1
- package/console-app/index.html +1 -1
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +6 -6
- package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.js +1 -1
- package/dist/.pikku/agent/pikku-agent-wirings.gen.d.ts +1 -1
- package/dist/.pikku/agent/pikku-agent-wirings.gen.js +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
- package/dist/.pikku/channel/pikku-channels-meta.gen.js +1 -1
- package/dist/.pikku/channel/pikku-channels.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channels.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.js +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +11 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
- package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +13 -13
- package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.json +88 -86
- package/dist/.pikku/function/pikku-functions.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
- package/dist/.pikku/pikku-services.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.js +1 -1
- package/dist/.pikku/pikku-websocket.gen.d.ts +1 -1
- package/dist/.pikku/pikku-websocket.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-remote-rpc-workers.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +1 -1
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +1 -1
- package/dist/.pikku/schemas/register.gen.js +5 -3
- package/dist/.pikku/schemas/schemas/ConsoleCommandInput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/WatchInput.schema.json +1 -0
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +34 -5
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +5 -5
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
- package/dist/src/cli.wiring.js +11 -1
- package/dist/src/functions/commands/all.js +16 -1
- package/dist/src/functions/commands/console.d.ts +3 -0
- package/dist/src/functions/commands/console.js +8 -1
- package/dist/src/functions/commands/new-addon.js +24 -18
- package/dist/src/functions/commands/versions-check.js +4 -4
- package/dist/src/functions/commands/versions-init.js +1 -1
- package/dist/src/functions/commands/versions-update.js +1 -1
- package/dist/src/functions/commands/watch.d.ts +7 -1
- package/dist/src/functions/commands/watch.js +10 -3
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +2 -2
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +2 -2
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-http-wrapper.js +2 -2
- package/dist/src/functions/wirings/ai-agent/pikku-command-public-agent.js +1 -1
- package/dist/src/functions/wirings/ai-agent/serialize-ai-agent-types.js +12 -6
- package/dist/src/functions/wirings/ai-agent/serialize-public-agent.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/serialize-public-agent.js +5 -5
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +1 -1
- package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +1 -1
- package/dist/src/functions/wirings/cli/serialize-channel-cli.js +2 -2
- package/dist/src/functions/wirings/console/pikku-command-console-functions.js +1 -1
- package/dist/src/functions/wirings/console/serialize-console-functions.d.ts +1 -1
- package/dist/src/functions/wirings/console/serialize-console-functions.js +15 -2
- package/dist/src/functions/wirings/functions/serialize-function-types.js +15 -15
- package/dist/src/functions/wirings/rpc/pikku-command-public-rpc.js +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +1 -1
- package/dist/src/functions/wirings/rpc/serialize-public-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/serialize-public-rpc.js +4 -4
- package/dist/src/functions/wirings/rpc/serialize-rpc-wrapper.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/serialize-rpc-wrapper.js +6 -6
- package/dist/src/functions/wirings/workflow/serialize-workflow-types.js +63 -8
- package/dist/src/services.js +1 -1
- package/dist/src/utils/pikku-cli-config.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/dist/src/utils/openapi/codegen.d.ts +0 -20
- package/dist/src/utils/openapi/codegen.js +0 -456
- package/dist/src/utils/openapi/naming.d.ts +0 -30
- package/dist/src/utils/openapi/naming.js +0 -167
- package/dist/src/utils/openapi/parse-openapi.d.ts +0 -61
- package/dist/src/utils/openapi/parse-openapi.js +0 -306
- package/dist/src/utils/openapi/zod-codegen.d.ts +0 -1
- package/dist/src/utils/openapi/zod-codegen.js +0 -1
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
import { schemaToZod, schemaVarName, createContext, } from './zod-codegen.js';
|
|
2
|
-
import { generateOperationNames, detectCommonPrefix, } from './naming.js';
|
|
3
|
-
const GENERIC_SUMMARIES = new Set([
|
|
4
|
-
'index',
|
|
5
|
-
'show',
|
|
6
|
-
'create',
|
|
7
|
-
'update',
|
|
8
|
-
'destroy',
|
|
9
|
-
'delete',
|
|
10
|
-
'list',
|
|
11
|
-
]);
|
|
12
|
-
/** Map from HTTP status code to pikku error class name */
|
|
13
|
-
const STATUS_TO_ERROR = {
|
|
14
|
-
400: 'BadRequestError',
|
|
15
|
-
401: 'UnauthorizedError',
|
|
16
|
-
403: 'ForbiddenError',
|
|
17
|
-
404: 'NotFoundError',
|
|
18
|
-
405: 'MethodNotAllowedError',
|
|
19
|
-
409: 'ConflictError',
|
|
20
|
-
422: 'UnprocessableContentError',
|
|
21
|
-
429: 'TooManyRequestsError',
|
|
22
|
-
500: 'InternalServerError',
|
|
23
|
-
};
|
|
24
|
-
function capitalize(str) {
|
|
25
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
26
|
-
}
|
|
27
|
-
function humanDescription(named, parsed) {
|
|
28
|
-
const summary = parsed.summary?.trim();
|
|
29
|
-
const description = parsed.description?.trim();
|
|
30
|
-
// Summary is preferred — it's the operation's intent
|
|
31
|
-
if (summary && !GENERIC_SUMMARIES.has(summary.toLowerCase())) {
|
|
32
|
-
// If description adds info beyond summary, combine them
|
|
33
|
-
if (description &&
|
|
34
|
-
!GENERIC_SUMMARIES.has(description.toLowerCase()) &&
|
|
35
|
-
description.toLowerCase() !== summary.toLowerCase()) {
|
|
36
|
-
const sep = summary.endsWith('.') ? ' ' : '. ';
|
|
37
|
-
return `${capitalize(summary)}${sep}${capitalize(description)}`;
|
|
38
|
-
}
|
|
39
|
-
return capitalize(summary);
|
|
40
|
-
}
|
|
41
|
-
if (description && !GENERIC_SUMMARIES.has(description.toLowerCase())) {
|
|
42
|
-
return capitalize(description);
|
|
43
|
-
}
|
|
44
|
-
if (parsed.responseDescription) {
|
|
45
|
-
return capitalize(parsed.responseDescription);
|
|
46
|
-
}
|
|
47
|
-
const words = named.functionName
|
|
48
|
-
.replace(/([A-Z])/g, ' $1')
|
|
49
|
-
.trim()
|
|
50
|
-
.toLowerCase();
|
|
51
|
-
return capitalize(words);
|
|
52
|
-
}
|
|
53
|
-
function getErrorClassesForResponses(errorResponses) {
|
|
54
|
-
const classes = [];
|
|
55
|
-
for (const err of errorResponses) {
|
|
56
|
-
const cls = STATUS_TO_ERROR[err.statusCode];
|
|
57
|
-
if (cls && !classes.includes(cls)) {
|
|
58
|
-
classes.push(cls);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return classes;
|
|
62
|
-
}
|
|
63
|
-
export function generateAddonFromOpenAPI(spec, vars, flags) {
|
|
64
|
-
const files = {};
|
|
65
|
-
const { name } = vars;
|
|
66
|
-
// Build context for Zod codegen with component schema refs
|
|
67
|
-
const schemaRefs = new Map();
|
|
68
|
-
for (const schemaName of Object.keys(spec.componentSchemas)) {
|
|
69
|
-
schemaRefs.set(schemaName, schemaVarName(schemaName));
|
|
70
|
-
}
|
|
71
|
-
const ctx = createContext(schemaRefs);
|
|
72
|
-
// Generate operation names
|
|
73
|
-
const paths = spec.operations.map((op) => op.path);
|
|
74
|
-
const commonPrefix = detectCommonPrefix(paths);
|
|
75
|
-
const namedOps = generateOperationNames(spec.operations.map((op) => ({
|
|
76
|
-
method: op.method,
|
|
77
|
-
path: op.path,
|
|
78
|
-
operationId: op.operationId,
|
|
79
|
-
})), commonPrefix);
|
|
80
|
-
// Pair named operations with their parsed data
|
|
81
|
-
const opPairs = namedOps.map((named, i) => ({ named, parsed: spec.operations[i] }));
|
|
82
|
-
// Generate types file with shared schemas (only if there are any)
|
|
83
|
-
if (Object.keys(spec.componentSchemas).length > 0) {
|
|
84
|
-
files[`src/${name}.types.ts`] = generateTypesFile(spec, ctx);
|
|
85
|
-
}
|
|
86
|
-
// Generate function files
|
|
87
|
-
const functionExports = [];
|
|
88
|
-
for (const { named, parsed } of opPairs) {
|
|
89
|
-
const funcCtx = createContext(schemaRefs);
|
|
90
|
-
const funcCode = generateFunctionFile(named, parsed, vars, funcCtx, spec, flags);
|
|
91
|
-
files[`src/functions/${named.functionName}.function.ts`] = funcCode;
|
|
92
|
-
functionExports.push(named.functionName);
|
|
93
|
-
}
|
|
94
|
-
// Generate index.ts with all exports
|
|
95
|
-
files['src/index.ts'] = generateIndexFile(functionExports);
|
|
96
|
-
// Generate typed API service class with route map
|
|
97
|
-
files[`src/${name}-api.service.ts`] = generateServiceFile(spec, opPairs, vars, flags);
|
|
98
|
-
// Generate variable file for BASE_URL
|
|
99
|
-
files[`src/${name}.variable.ts`] = generateVariableFile(spec, vars);
|
|
100
|
-
return files;
|
|
101
|
-
}
|
|
102
|
-
function generateTypesFile(spec, ctx) {
|
|
103
|
-
const lines = [];
|
|
104
|
-
lines.push("import { z } from 'zod'");
|
|
105
|
-
lines.push('');
|
|
106
|
-
lines.push(`// Shared schemas from ${spec.info.title} v${spec.info.version}`);
|
|
107
|
-
lines.push('');
|
|
108
|
-
for (const [name, schema] of Object.entries(spec.componentSchemas)) {
|
|
109
|
-
const varName = schemaVarName(name);
|
|
110
|
-
const zodCode = schemaToZod(schema, ctx);
|
|
111
|
-
lines.push(`export const ${varName} = ${zodCode}`);
|
|
112
|
-
lines.push(`export type ${name} = z.infer<typeof ${varName}>`);
|
|
113
|
-
lines.push('');
|
|
114
|
-
}
|
|
115
|
-
return lines.join('\n');
|
|
116
|
-
}
|
|
117
|
-
function generateFunctionFile(named, parsed, vars, ctx, spec, flags) {
|
|
118
|
-
const lines = [];
|
|
119
|
-
const { camelName } = vars;
|
|
120
|
-
// Tag description as file header
|
|
121
|
-
if (parsed.tags.length > 0) {
|
|
122
|
-
const tag = parsed.tags[0];
|
|
123
|
-
const tagDesc = spec.tagDescriptions[tag];
|
|
124
|
-
if (tagDesc) {
|
|
125
|
-
lines.push(`// ${tag} — ${tagDesc}`);
|
|
126
|
-
lines.push('');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const hasInput = parsed.pathParams.length > 0 ||
|
|
130
|
-
parsed.queryParams.length > 0 ||
|
|
131
|
-
parsed.headerParams.length > 0 ||
|
|
132
|
-
parsed.requestBody;
|
|
133
|
-
const pascalName = named.functionName.charAt(0).toUpperCase() + named.functionName.slice(1);
|
|
134
|
-
const inputName = `${pascalName}Input`;
|
|
135
|
-
const outputName = `${pascalName}Output`;
|
|
136
|
-
// Determine error imports needed
|
|
137
|
-
const errorClasses = getErrorClassesForResponses(parsed.errorResponses);
|
|
138
|
-
lines.push("import { z } from 'zod'");
|
|
139
|
-
lines.push("import { pikkuSessionlessFunc } from '#pikku'");
|
|
140
|
-
if (errorClasses.length > 0) {
|
|
141
|
-
lines.push(`import { ${errorClasses.join(', ')} } from '@pikku/core/errors'`);
|
|
142
|
-
}
|
|
143
|
-
lines.push('');
|
|
144
|
-
// Build Input schema (exported for pikku schema discovery)
|
|
145
|
-
if (hasInput) {
|
|
146
|
-
const inputCode = buildInputSchema(parsed, ctx);
|
|
147
|
-
lines.push(`export const ${inputName} = ${inputCode}`);
|
|
148
|
-
lines.push('');
|
|
149
|
-
}
|
|
150
|
-
// Build Output schema (exported for pikku schema discovery)
|
|
151
|
-
if (parsed.responseSchema) {
|
|
152
|
-
const outputCode = buildOutputSchema(parsed.responseSchema, ctx);
|
|
153
|
-
lines.push(`export const ${outputName} = ${outputCode}`);
|
|
154
|
-
lines.push('');
|
|
155
|
-
}
|
|
156
|
-
const description = humanDescription(named, parsed);
|
|
157
|
-
const method = parsed.method.toUpperCase();
|
|
158
|
-
const funcConfig = [];
|
|
159
|
-
funcConfig.push(` description: ${JSON.stringify(description)},`);
|
|
160
|
-
if (hasInput)
|
|
161
|
-
funcConfig.push(` input: ${inputName},`);
|
|
162
|
-
if (parsed.responseSchema) {
|
|
163
|
-
funcConfig.push(` output: ${outputName},`);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
funcConfig.push(' output: z.void(),');
|
|
167
|
-
}
|
|
168
|
-
if (errorClasses.length > 0) {
|
|
169
|
-
funcConfig.push(` errors: [${errorClasses.join(', ')}],`);
|
|
170
|
-
}
|
|
171
|
-
if (flags.mcp) {
|
|
172
|
-
funcConfig.push(' mcp: true,');
|
|
173
|
-
}
|
|
174
|
-
const funcParams = hasInput ? `{ ${camelName} }, data` : `{ ${camelName} }`;
|
|
175
|
-
const returnCast = parsed.responseSchema ? ' as any' : '';
|
|
176
|
-
funcConfig.push(` func: async (${funcParams}) => {`, ` return ${camelName}.call('${method}', '${parsed.path}'${hasInput ? ', data' : ''})${returnCast}`, ' },');
|
|
177
|
-
lines.push(`export const ${named.functionName} = pikkuSessionlessFunc({`);
|
|
178
|
-
lines.push(funcConfig.join('\n'));
|
|
179
|
-
lines.push('})');
|
|
180
|
-
lines.push('');
|
|
181
|
-
return lines.join('\n');
|
|
182
|
-
}
|
|
183
|
-
function buildInputSchema(parsed, ctx) {
|
|
184
|
-
const props = [];
|
|
185
|
-
for (const param of parsed.pathParams) {
|
|
186
|
-
props.push(formatParamProp(param, ctx));
|
|
187
|
-
}
|
|
188
|
-
for (const param of parsed.queryParams) {
|
|
189
|
-
props.push(formatParamProp(param, ctx));
|
|
190
|
-
}
|
|
191
|
-
for (const param of parsed.headerParams) {
|
|
192
|
-
props.push(formatParamProp(param, ctx));
|
|
193
|
-
}
|
|
194
|
-
if (parsed.requestBody) {
|
|
195
|
-
if (parsed.requestBody.properties) {
|
|
196
|
-
const requiredSet = new Set(parsed.requestBody.required ?? []);
|
|
197
|
-
for (const [key, propSchema] of Object.entries(parsed.requestBody.properties)) {
|
|
198
|
-
// Skip readOnly properties from input
|
|
199
|
-
if (propSchema.readOnly)
|
|
200
|
-
continue;
|
|
201
|
-
const isOptional = !requiredSet.has(key);
|
|
202
|
-
const zodCode = schemaToZod(propSchema, ctx, { optional: isOptional });
|
|
203
|
-
const withDesc = propSchema.description
|
|
204
|
-
? `${zodCode}.describe(${JSON.stringify(propSchema.description)})`
|
|
205
|
-
: zodCode;
|
|
206
|
-
props.push(` ${key}: ${withDesc},`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
const bodyZod = schemaToZod(parsed.requestBody, ctx);
|
|
211
|
-
props.push(` body: ${bodyZod},`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return `z.object({\n${props.join('\n')}\n})`;
|
|
215
|
-
}
|
|
216
|
-
function formatParamProp(param, ctx) {
|
|
217
|
-
const zodCode = schemaToZod(param.schema, ctx, { optional: !param.required });
|
|
218
|
-
let descParts = [];
|
|
219
|
-
if (param.description)
|
|
220
|
-
descParts.push(param.description);
|
|
221
|
-
if (param.example !== undefined)
|
|
222
|
-
descParts.push(`Example: ${JSON.stringify(param.example)}`);
|
|
223
|
-
const desc = descParts.length > 0
|
|
224
|
-
? `${zodCode}.describe(${JSON.stringify(descParts.join('. '))})`
|
|
225
|
-
: zodCode;
|
|
226
|
-
return ` ${param.name}: ${desc},`;
|
|
227
|
-
}
|
|
228
|
-
function buildOutputSchema(schema, ctx) {
|
|
229
|
-
// For output schemas, filter out writeOnly properties
|
|
230
|
-
if (schema.properties) {
|
|
231
|
-
const filteredProps = {};
|
|
232
|
-
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
233
|
-
if (!propSchema.writeOnly) {
|
|
234
|
-
filteredProps[key] = propSchema;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const filteredSchema = { ...schema, properties: filteredProps };
|
|
238
|
-
return schemaToZod(filteredSchema, ctx);
|
|
239
|
-
}
|
|
240
|
-
return schemaToZod(schema, ctx);
|
|
241
|
-
}
|
|
242
|
-
function generateIndexFile(functionExports) {
|
|
243
|
-
const lines = [];
|
|
244
|
-
for (const name of functionExports) {
|
|
245
|
-
lines.push(`export { ${name} } from './functions/${name}.function.js'`);
|
|
246
|
-
}
|
|
247
|
-
lines.push('');
|
|
248
|
-
return lines.join('\n');
|
|
249
|
-
}
|
|
250
|
-
function generateServiceFile(spec, opPairs, vars, flags) {
|
|
251
|
-
const { name, pascalName, screamingName, displayName } = vars;
|
|
252
|
-
const lines = [];
|
|
253
|
-
// Always import all error classes used in the switch statement
|
|
254
|
-
const allErrorClasses = new Set(Object.values(STATUS_TO_ERROR));
|
|
255
|
-
if (flags.oauth) {
|
|
256
|
-
lines.push("import { OAuth2Client } from '@pikku/core/oauth2'");
|
|
257
|
-
lines.push("import type { TypedSecretService } from '#pikku/secrets/pikku-secrets.gen.js'");
|
|
258
|
-
}
|
|
259
|
-
else if (flags.secret) {
|
|
260
|
-
lines.push(`import type { ${pascalName}Secrets } from './${name}.secret.js'`);
|
|
261
|
-
}
|
|
262
|
-
if (allErrorClasses.size > 0) {
|
|
263
|
-
lines.push(`import { ${[...allErrorClasses].sort().join(', ')} } from '@pikku/core/errors'`);
|
|
264
|
-
}
|
|
265
|
-
lines.push(`import type { TypedVariablesService } from '#pikku/variables/pikku-variables.gen.js'`);
|
|
266
|
-
lines.push('');
|
|
267
|
-
if (flags.oauth) {
|
|
268
|
-
// Use OAuth2 details from spec if available
|
|
269
|
-
const oauthScheme = Object.values(spec.securitySchemes).find((s) => s.type === 'oauth2');
|
|
270
|
-
const authUrl = oauthScheme?.flows?.authorizationUrl ??
|
|
271
|
-
'https://example.com/oauth2/authorize';
|
|
272
|
-
const tokenUrl = oauthScheme?.flows?.tokenUrl ?? 'https://example.com/oauth2/token';
|
|
273
|
-
const scopes = oauthScheme?.flows?.scopes
|
|
274
|
-
? Object.keys(oauthScheme.flows.scopes)
|
|
275
|
-
: ['read', 'write'];
|
|
276
|
-
lines.push(`export const ${screamingName}_OAUTH2_CONFIG = {`);
|
|
277
|
-
lines.push(` tokenSecretId: '${screamingName}_TOKENS',`);
|
|
278
|
-
lines.push(` authorizationUrl: ${JSON.stringify(authUrl)},`);
|
|
279
|
-
lines.push(` tokenUrl: ${JSON.stringify(tokenUrl)},`);
|
|
280
|
-
lines.push(` scopes: ${JSON.stringify(scopes)},`);
|
|
281
|
-
lines.push('}');
|
|
282
|
-
lines.push('');
|
|
283
|
-
}
|
|
284
|
-
// Generate route map from parsed operations
|
|
285
|
-
const routes = {};
|
|
286
|
-
for (const { parsed } of opPairs) {
|
|
287
|
-
const key = `${parsed.method.toUpperCase()} ${parsed.path}`;
|
|
288
|
-
const route = {
|
|
289
|
-
path: parsed.pathParams.map((p) => p.name),
|
|
290
|
-
query: parsed.queryParams.map((p) => p.name),
|
|
291
|
-
headers: parsed.headerParams.map((p) => p.name),
|
|
292
|
-
};
|
|
293
|
-
if (parsed.errorResponses.length > 0) {
|
|
294
|
-
route.errors = {};
|
|
295
|
-
for (const err of parsed.errorResponses) {
|
|
296
|
-
route.errors[err.statusCode] = err.description;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
routes[key] = route;
|
|
300
|
-
}
|
|
301
|
-
lines.push(`const ROUTES: Record<string, { path: string[], query: string[], headers: string[], errors?: Record<number, string> }> = ${JSON.stringify(routes, null, 2)}`);
|
|
302
|
-
lines.push('');
|
|
303
|
-
// Class declaration
|
|
304
|
-
lines.push(`export class ${pascalName}Service {`);
|
|
305
|
-
lines.push(' private baseUrl: string');
|
|
306
|
-
if (flags.oauth) {
|
|
307
|
-
lines.push(' private oauth: OAuth2Client');
|
|
308
|
-
lines.push('');
|
|
309
|
-
lines.push(` constructor(secrets: TypedSecretService, variables: TypedVariablesService) {`);
|
|
310
|
-
lines.push(` this.baseUrl = variables.get('${screamingName}_BASE_URL') as string`);
|
|
311
|
-
lines.push(' this.oauth = new OAuth2Client(');
|
|
312
|
-
lines.push(` ${screamingName}_OAUTH2_CONFIG,`);
|
|
313
|
-
lines.push(` '${screamingName}_APP_CREDENTIALS',`);
|
|
314
|
-
lines.push(' secrets');
|
|
315
|
-
lines.push(' )');
|
|
316
|
-
lines.push(' }');
|
|
317
|
-
}
|
|
318
|
-
else if (flags.secret) {
|
|
319
|
-
lines.push('');
|
|
320
|
-
lines.push(` constructor(private creds: ${pascalName}Secrets, variables: TypedVariablesService) {`);
|
|
321
|
-
lines.push(` this.baseUrl = variables.get('${screamingName}_BASE_URL') as string`);
|
|
322
|
-
lines.push(' }');
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
lines.push('');
|
|
326
|
-
lines.push(` constructor(variables: TypedVariablesService) {`);
|
|
327
|
-
lines.push(` this.baseUrl = variables.get('${screamingName}_BASE_URL') as string`);
|
|
328
|
-
lines.push(' }');
|
|
329
|
-
}
|
|
330
|
-
lines.push('');
|
|
331
|
-
// call() method — splits data into path/query/headers/body using route map
|
|
332
|
-
lines.push(' async call<T>(');
|
|
333
|
-
lines.push(" method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',");
|
|
334
|
-
lines.push(' path: string,');
|
|
335
|
-
lines.push(' data?: Record<string, unknown>');
|
|
336
|
-
lines.push(' ): Promise<T> {');
|
|
337
|
-
lines.push(' const route = ROUTES[`${method} ${path}`]');
|
|
338
|
-
lines.push(' let endpoint = path');
|
|
339
|
-
lines.push(' let body: Record<string, unknown> | undefined');
|
|
340
|
-
lines.push(' const query: Record<string, string> = {}');
|
|
341
|
-
lines.push(' const headers: Record<string, string> = {');
|
|
342
|
-
lines.push(" 'Content-Type': 'application/json',");
|
|
343
|
-
lines.push(' }');
|
|
344
|
-
lines.push('');
|
|
345
|
-
lines.push(' if (data && route) {');
|
|
346
|
-
lines.push(' // Interpolate path params');
|
|
347
|
-
lines.push(' for (const param of route.path) {');
|
|
348
|
-
lines.push(' if (data[param] !== undefined) {');
|
|
349
|
-
lines.push(' endpoint = endpoint.replace(`{${param}}`, String(data[param]))');
|
|
350
|
-
lines.push(' }');
|
|
351
|
-
lines.push(' }');
|
|
352
|
-
lines.push(' // Extract query params');
|
|
353
|
-
lines.push(' for (const param of route.query) {');
|
|
354
|
-
lines.push(' if (data[param] !== undefined) {');
|
|
355
|
-
lines.push(' query[param] = String(data[param])');
|
|
356
|
-
lines.push(' }');
|
|
357
|
-
lines.push(' }');
|
|
358
|
-
lines.push(' // Extract header params');
|
|
359
|
-
lines.push(' for (const param of route.headers) {');
|
|
360
|
-
lines.push(' if (data[param] !== undefined) {');
|
|
361
|
-
lines.push(' headers[param] = String(data[param])');
|
|
362
|
-
lines.push(' }');
|
|
363
|
-
lines.push(' }');
|
|
364
|
-
lines.push(' // Everything else goes into body');
|
|
365
|
-
lines.push(' const pathQueryHeaders = new Set([...route.path, ...route.query, ...route.headers])');
|
|
366
|
-
lines.push(' const remaining = Object.fromEntries(');
|
|
367
|
-
lines.push(' Object.entries(data).filter(([k]) => !pathQueryHeaders.has(k))');
|
|
368
|
-
lines.push(' )');
|
|
369
|
-
lines.push(' if (Object.keys(remaining).length > 0) {');
|
|
370
|
-
lines.push(' body = remaining');
|
|
371
|
-
lines.push(' }');
|
|
372
|
-
lines.push(' }');
|
|
373
|
-
lines.push('');
|
|
374
|
-
lines.push(' const url = new URL(`${this.baseUrl}${endpoint}`)');
|
|
375
|
-
lines.push(' for (const [key, value] of Object.entries(query)) {');
|
|
376
|
-
lines.push(' url.searchParams.set(key, value)');
|
|
377
|
-
lines.push(' }');
|
|
378
|
-
lines.push('');
|
|
379
|
-
if (flags.oauth) {
|
|
380
|
-
lines.push(' const response = await this.oauth.request(url.toString(), {');
|
|
381
|
-
lines.push(' method,');
|
|
382
|
-
lines.push(' headers,');
|
|
383
|
-
lines.push(' body: body ? JSON.stringify(body) : undefined,');
|
|
384
|
-
lines.push(' })');
|
|
385
|
-
}
|
|
386
|
-
else if (flags.secret) {
|
|
387
|
-
// Use apiKey details from spec if available
|
|
388
|
-
const apiKeyScheme = Object.values(spec.securitySchemes).find((s) => s.type === 'apiKey');
|
|
389
|
-
if (apiKeyScheme?.name && apiKeyScheme?.in === 'header') {
|
|
390
|
-
lines.push(` headers[${JSON.stringify(apiKeyScheme.name)}] = this.creds.apiKey`);
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
lines.push(' headers.Authorization = `Bearer ${this.creds.apiKey}`');
|
|
394
|
-
}
|
|
395
|
-
lines.push('');
|
|
396
|
-
lines.push(' const response = await fetch(url.toString(), {');
|
|
397
|
-
lines.push(' method,');
|
|
398
|
-
lines.push(' headers,');
|
|
399
|
-
lines.push(' body: body ? JSON.stringify(body) : undefined,');
|
|
400
|
-
lines.push(' })');
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
lines.push(' const response = await fetch(url.toString(), {');
|
|
404
|
-
lines.push(' method,');
|
|
405
|
-
lines.push(' headers,');
|
|
406
|
-
lines.push(' body: body ? JSON.stringify(body) : undefined,');
|
|
407
|
-
lines.push(' })');
|
|
408
|
-
}
|
|
409
|
-
lines.push('');
|
|
410
|
-
lines.push(' if (!response.ok) {');
|
|
411
|
-
lines.push(' const errorText = await response.text()');
|
|
412
|
-
lines.push(' const errorMessage = route?.errors?.[response.status] ?? errorText');
|
|
413
|
-
lines.push(' switch (response.status) {');
|
|
414
|
-
lines.push(' case 400: throw new BadRequestError(errorMessage)');
|
|
415
|
-
lines.push(' case 401: throw new UnauthorizedError(errorMessage)');
|
|
416
|
-
lines.push(' case 403: throw new ForbiddenError(errorMessage)');
|
|
417
|
-
lines.push(' case 404: throw new NotFoundError(errorMessage)');
|
|
418
|
-
lines.push(' case 405: throw new MethodNotAllowedError(errorMessage)');
|
|
419
|
-
lines.push(' case 409: throw new ConflictError(errorMessage)');
|
|
420
|
-
lines.push(' case 422: throw new UnprocessableContentError(errorMessage)');
|
|
421
|
-
lines.push(' case 429: throw new TooManyRequestsError(errorMessage)');
|
|
422
|
-
lines.push(' case 500: throw new InternalServerError(errorMessage)');
|
|
423
|
-
lines.push(` default: throw new Error(\`${displayName} API error (\${response.status}): \${errorText}\`)`);
|
|
424
|
-
lines.push(' }');
|
|
425
|
-
lines.push(' }');
|
|
426
|
-
lines.push('');
|
|
427
|
-
lines.push(' const text = await response.text()');
|
|
428
|
-
lines.push(' if (!text) return {} as T');
|
|
429
|
-
lines.push(' return JSON.parse(text) as T');
|
|
430
|
-
lines.push(' }');
|
|
431
|
-
lines.push('}');
|
|
432
|
-
lines.push('');
|
|
433
|
-
return lines.join('\n');
|
|
434
|
-
}
|
|
435
|
-
function generateVariableFile(spec, vars) {
|
|
436
|
-
const { camelName, screamingName, displayName } = vars;
|
|
437
|
-
const serverUrls = spec.serverUrls.length > 0 ? spec.serverUrls : [];
|
|
438
|
-
const defaultUrl = serverUrls[0];
|
|
439
|
-
const lines = [];
|
|
440
|
-
lines.push("import { z } from 'zod'");
|
|
441
|
-
lines.push("import { wireVariable } from '@pikku/core/variable'");
|
|
442
|
-
lines.push('');
|
|
443
|
-
const schemaVarName = `${camelName}BaseUrlSchema`;
|
|
444
|
-
const urlsLiteral = serverUrls.map((u) => JSON.stringify(u)).join(', ');
|
|
445
|
-
lines.push(`export const ${schemaVarName} = z.enum([${urlsLiteral}]).default(${JSON.stringify(defaultUrl)})`);
|
|
446
|
-
lines.push('');
|
|
447
|
-
lines.push(`wireVariable({`);
|
|
448
|
-
lines.push(` name: '${screamingName}_BASE_URL',`);
|
|
449
|
-
lines.push(` displayName: '${displayName} Base URL',`);
|
|
450
|
-
lines.push(` description: 'The base URL for the ${displayName} API.',`);
|
|
451
|
-
lines.push(` variableId: '${screamingName}_BASE_URL',`);
|
|
452
|
-
lines.push(` schema: ${schemaVarName},`);
|
|
453
|
-
lines.push(`})`);
|
|
454
|
-
lines.push('');
|
|
455
|
-
return lines.join('\n');
|
|
456
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derives function/method names from HTTP method + path.
|
|
3
|
-
* Uses operationId when available, otherwise generates from path segments.
|
|
4
|
-
*/
|
|
5
|
-
export declare function singularize(word: string): string;
|
|
6
|
-
export declare function toCamelCase(str: string): string;
|
|
7
|
-
export declare function toPascalCase(str: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* Strip common API prefix from paths (e.g. /api/v2/).
|
|
10
|
-
* Uses majority voting — a prefix shared by >75% of paths is stripped,
|
|
11
|
-
* so a few outlier paths (e.g. /oauth/...) don't break detection.
|
|
12
|
-
*/
|
|
13
|
-
export declare function detectCommonPrefix(paths: string[]): string;
|
|
14
|
-
interface OperationForNaming {
|
|
15
|
-
method: string;
|
|
16
|
-
path: string;
|
|
17
|
-
operationId?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface NamedOperation {
|
|
20
|
-
method: string;
|
|
21
|
-
path: string;
|
|
22
|
-
functionName: string;
|
|
23
|
-
methodName: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Generate function names for a list of operations.
|
|
27
|
-
* Handles collision detection and auto-deduplication.
|
|
28
|
-
*/
|
|
29
|
-
export declare function generateOperationNames(operations: OperationForNaming[], commonPrefix: string): NamedOperation[];
|
|
30
|
-
export {};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derives function/method names from HTTP method + path.
|
|
3
|
-
* Uses operationId when available, otherwise generates from path segments.
|
|
4
|
-
*/
|
|
5
|
-
const IRREGULAR_PLURALS = {
|
|
6
|
-
addresses: 'address',
|
|
7
|
-
statuses: 'status',
|
|
8
|
-
indices: 'index',
|
|
9
|
-
analyses: 'analysis',
|
|
10
|
-
quizzes: 'quiz',
|
|
11
|
-
matrices: 'matrix',
|
|
12
|
-
vertices: 'vertex',
|
|
13
|
-
aliases: 'alias',
|
|
14
|
-
buses: 'bus',
|
|
15
|
-
};
|
|
16
|
-
export function singularize(word) {
|
|
17
|
-
const lower = word.toLowerCase();
|
|
18
|
-
if (IRREGULAR_PLURALS[lower]) {
|
|
19
|
-
const singular = IRREGULAR_PLURALS[lower];
|
|
20
|
-
return word[0] === word[0].toUpperCase()
|
|
21
|
-
? singular.charAt(0).toUpperCase() + singular.slice(1)
|
|
22
|
-
: singular;
|
|
23
|
-
}
|
|
24
|
-
if (lower.endsWith('ies') && lower.length > 4) {
|
|
25
|
-
return word.slice(0, -3) + 'y';
|
|
26
|
-
}
|
|
27
|
-
// -shes, -ches, -xes, -zes, -sses → drop "es"
|
|
28
|
-
if (lower.endsWith('shes') || lower.endsWith('ches') || lower.endsWith('xes') || lower.endsWith('zes') || lower.endsWith('sses')) {
|
|
29
|
-
return word.slice(0, -2);
|
|
30
|
-
}
|
|
31
|
-
// General: drop trailing "s" (covers courses→course, products→product, etc.)
|
|
32
|
-
if (lower.endsWith('s') && !lower.endsWith('ss') && !lower.endsWith('us') && lower.length > 2) {
|
|
33
|
-
return word.slice(0, -1);
|
|
34
|
-
}
|
|
35
|
-
return word;
|
|
36
|
-
}
|
|
37
|
-
export function toCamelCase(str) {
|
|
38
|
-
return str
|
|
39
|
-
.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase())
|
|
40
|
-
.replace(/^[A-Z]/, (c) => c.toLowerCase());
|
|
41
|
-
}
|
|
42
|
-
export function toPascalCase(str) {
|
|
43
|
-
const camel = toCamelCase(str);
|
|
44
|
-
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Strip common API prefix from paths (e.g. /api/v2/).
|
|
48
|
-
* Uses majority voting — a prefix shared by >75% of paths is stripped,
|
|
49
|
-
* so a few outlier paths (e.g. /oauth/...) don't break detection.
|
|
50
|
-
*/
|
|
51
|
-
export function detectCommonPrefix(paths) {
|
|
52
|
-
if (paths.length === 0)
|
|
53
|
-
return '';
|
|
54
|
-
const segments = paths.map((p) => p.replace(/^\//, '').split('/'));
|
|
55
|
-
const threshold = Math.ceil(paths.length * 0.75);
|
|
56
|
-
// Find the longest prefix shared by at least `threshold` paths
|
|
57
|
-
let prefixLen = 0;
|
|
58
|
-
for (let i = 0; i < 10; i++) {
|
|
59
|
-
// Count how many paths have the same segment at position i as the first path
|
|
60
|
-
const candidateSeg = segments[0][i];
|
|
61
|
-
if (!candidateSeg || candidateSeg.startsWith('{'))
|
|
62
|
-
break;
|
|
63
|
-
const count = segments.filter((s) => s.length > i + 1 && s[i] === candidateSeg).length;
|
|
64
|
-
if (count >= threshold) {
|
|
65
|
-
prefixLen = i + 1;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (prefixLen === 0)
|
|
72
|
-
return '';
|
|
73
|
-
return '/' + segments[0].slice(0, prefixLen).join('/') + '/';
|
|
74
|
-
}
|
|
75
|
-
/** Convert operationId to camelCase function name */
|
|
76
|
-
function fromOperationId(operationId) {
|
|
77
|
-
// operationId might be snake_case, camelCase, PascalCase, or kebab-case
|
|
78
|
-
return toCamelCase(operationId
|
|
79
|
-
.replace(/[^a-zA-Z0-9_-]/g, '_')
|
|
80
|
-
.replace(/_+/g, '_')
|
|
81
|
-
.replace(/^_|_$/g, ''));
|
|
82
|
-
}
|
|
83
|
-
const METHOD_PREFIXES = {
|
|
84
|
-
get: 'get',
|
|
85
|
-
post: 'create',
|
|
86
|
-
put: 'update',
|
|
87
|
-
patch: 'update',
|
|
88
|
-
delete: 'delete',
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Generate function names for a list of operations.
|
|
92
|
-
* Handles collision detection and auto-deduplication.
|
|
93
|
-
*/
|
|
94
|
-
export function generateOperationNames(operations, commonPrefix) {
|
|
95
|
-
const results = [];
|
|
96
|
-
const usedNames = new Map();
|
|
97
|
-
for (const op of operations) {
|
|
98
|
-
let name;
|
|
99
|
-
if (op.operationId) {
|
|
100
|
-
name = fromOperationId(op.operationId);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
name = deriveNameFromPath(op.method, op.path, commonPrefix);
|
|
104
|
-
}
|
|
105
|
-
// Handle collisions
|
|
106
|
-
const existing = usedNames.get(name) ?? 0;
|
|
107
|
-
if (existing > 0) {
|
|
108
|
-
usedNames.set(name, existing + 1);
|
|
109
|
-
name = `${name}${existing + 1}`;
|
|
110
|
-
}
|
|
111
|
-
usedNames.set(name, (usedNames.get(name) ?? 0) || 1);
|
|
112
|
-
results.push({
|
|
113
|
-
method: op.method,
|
|
114
|
-
path: op.path,
|
|
115
|
-
functionName: name,
|
|
116
|
-
methodName: name,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return results;
|
|
120
|
-
}
|
|
121
|
-
function deriveNameFromPath(method, path, commonPrefix) {
|
|
122
|
-
// Strip common prefix
|
|
123
|
-
let cleanPath = path;
|
|
124
|
-
if (commonPrefix && cleanPath.startsWith(commonPrefix)) {
|
|
125
|
-
cleanPath = '/' + cleanPath.slice(commonPrefix.length);
|
|
126
|
-
}
|
|
127
|
-
const segments = cleanPath
|
|
128
|
-
.replace(/^\//, '')
|
|
129
|
-
.split('/')
|
|
130
|
-
.filter(Boolean);
|
|
131
|
-
const methodLower = method.toLowerCase();
|
|
132
|
-
const prefix = METHOD_PREFIXES[methodLower] || methodLower;
|
|
133
|
-
// Separate param and non-param segments
|
|
134
|
-
const nonParams = [];
|
|
135
|
-
let hasTrailingParam = false;
|
|
136
|
-
for (let i = 0; i < segments.length; i++) {
|
|
137
|
-
if (segments[i].startsWith('{')) {
|
|
138
|
-
if (i === segments.length - 1) {
|
|
139
|
-
hasTrailingParam = true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
nonParams.push(segments[i]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (nonParams.length === 0) {
|
|
147
|
-
return prefix;
|
|
148
|
-
}
|
|
149
|
-
// For GET with trailing param: singularize the last non-param segment
|
|
150
|
-
// For GET without trailing param: keep plural (list)
|
|
151
|
-
// For POST without trailing param: use prefix (create)
|
|
152
|
-
const parts = nonParams.map((seg, i) => {
|
|
153
|
-
const isLast = i === nonParams.length - 1;
|
|
154
|
-
let word = seg;
|
|
155
|
-
if (isLast && hasTrailingParam) {
|
|
156
|
-
word = singularize(word);
|
|
157
|
-
}
|
|
158
|
-
// For GET on collection (no trailing param), use "list" prefix instead of "get"
|
|
159
|
-
return toPascalCase(word);
|
|
160
|
-
});
|
|
161
|
-
// For GET on collection, use "list" instead of "get"
|
|
162
|
-
let finalPrefix = prefix;
|
|
163
|
-
if (methodLower === 'get' && !hasTrailingParam) {
|
|
164
|
-
finalPrefix = 'list';
|
|
165
|
-
}
|
|
166
|
-
return finalPrefix + parts.join('');
|
|
167
|
-
}
|