@spfn/core 0.1.0-alpha.68 → 0.1.0-alpha.72
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/dist/client/index.d.ts +2 -1
- package/dist/codegen/generators/index.js +59 -57
- package/dist/codegen/generators/index.js.map +1 -1
- package/dist/codegen/index.d.ts +2 -1
- package/dist/codegen/index.js +59 -57
- package/dist/codegen/index.js.map +1 -1
- package/dist/{database-errors-CoPrcOpq.d.ts → database-errors-BNNmLTJE.d.ts} +4 -4
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/errors/index.d.ts +20 -3
- package/dist/errors/index.js +15 -3
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +115 -109
- package/dist/index.js.map +1 -1
- package/dist/route/index.d.ts +5 -157
- package/dist/route/index.js +86 -96
- package/dist/route/index.js.map +1 -1
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +115 -109
- package/dist/server/index.js.map +1 -1
- package/dist/types-Dzggq1Yb.d.ts +170 -0
- package/package.json +1 -1
- package/dist/types-CAON3Mmg.d.ts +0 -57
package/dist/client/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import '../auto-loader-JFaZ9gON.js';
|
|
2
|
-
import { a as RouteContract, I as InferContract } from '../types-
|
|
2
|
+
import { a as RouteContract, I as InferContract } from '../types-Dzggq1Yb.js';
|
|
3
3
|
import 'hono';
|
|
4
4
|
import 'hono/utils/http-status';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
|
+
import '../error-handler-wjLL3v-a.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Contract-Based API Client
|
|
@@ -303,21 +303,28 @@ function generateTypeName(mapping) {
|
|
|
303
303
|
}
|
|
304
304
|
return name;
|
|
305
305
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
306
|
+
function generateFunctionName(mapping) {
|
|
307
|
+
let name = mapping.contractName;
|
|
308
|
+
if (name.endsWith("Contract")) {
|
|
309
|
+
name = name.slice(0, -8);
|
|
310
|
+
}
|
|
311
|
+
return name;
|
|
312
|
+
}
|
|
313
|
+
function generateFunctionCode(mapping, options) {
|
|
314
|
+
const functionName = generateFunctionName(mapping);
|
|
308
315
|
const hasParams = mapping.hasParams || mapping.path.includes(":");
|
|
309
316
|
const hasQuery = mapping.hasQuery || false;
|
|
310
317
|
const hasBody = mapping.hasBody || false;
|
|
311
318
|
let code = "";
|
|
312
319
|
if (options.includeJsDoc !== false) {
|
|
313
|
-
code +=
|
|
320
|
+
code += `/**
|
|
314
321
|
`;
|
|
315
|
-
code += `
|
|
322
|
+
code += ` * ${mapping.method} ${mapping.path}
|
|
316
323
|
`;
|
|
317
|
-
code += `
|
|
324
|
+
code += ` */
|
|
318
325
|
`;
|
|
319
326
|
}
|
|
320
|
-
code += `
|
|
327
|
+
code += `export const ${functionName} = (`;
|
|
321
328
|
const params = [];
|
|
322
329
|
const typeName = generateTypeName(mapping);
|
|
323
330
|
if (hasParams) {
|
|
@@ -337,33 +344,11 @@ function generateMethodCode(mapping, options) {
|
|
|
337
344
|
if (params.length > 0) {
|
|
338
345
|
code += `, options`;
|
|
339
346
|
}
|
|
340
|
-
code += `)
|
|
347
|
+
code += `);
|
|
348
|
+
|
|
341
349
|
`;
|
|
342
350
|
return code;
|
|
343
351
|
}
|
|
344
|
-
function generateMethodName(mapping) {
|
|
345
|
-
const method = mapping.method.toLowerCase();
|
|
346
|
-
if (mapping.path === "/" || mapping.path.match(/^\/[\w-]+$/)) {
|
|
347
|
-
if (method === "get") {
|
|
348
|
-
return "list";
|
|
349
|
-
}
|
|
350
|
-
if (method === "post") {
|
|
351
|
-
return "create";
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (mapping.path.includes(":")) {
|
|
355
|
-
if (method === "get") {
|
|
356
|
-
return "getById";
|
|
357
|
-
}
|
|
358
|
-
if (method === "put" || method === "patch") {
|
|
359
|
-
return "update";
|
|
360
|
-
}
|
|
361
|
-
if (method === "delete") {
|
|
362
|
-
return "delete";
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return method;
|
|
366
|
-
}
|
|
367
352
|
function countUniqueContractFiles(mappings) {
|
|
368
353
|
const files = /* @__PURE__ */ new Set();
|
|
369
354
|
for (let i = 0; i < mappings.length; i++) {
|
|
@@ -392,11 +377,11 @@ async function generateSplitClient(_mappings, grouped, options) {
|
|
|
392
377
|
const filePath = `${outputDir}/${kebabName}.ts`;
|
|
393
378
|
await writeFile(filePath, code, "utf-8");
|
|
394
379
|
}
|
|
395
|
-
const indexCode = generateIndexFile(
|
|
380
|
+
const indexCode = generateIndexFile(grouped, options);
|
|
396
381
|
const indexPath = `${outputDir}/index.ts`;
|
|
397
382
|
await writeFile(indexPath, indexCode, "utf-8");
|
|
398
383
|
}
|
|
399
|
-
function generateResourceFile(
|
|
384
|
+
function generateResourceFile(_resourceName, routes, options) {
|
|
400
385
|
let code = "";
|
|
401
386
|
code += generateHeader();
|
|
402
387
|
code += `import { client } from '@spfn/core/client';
|
|
@@ -447,52 +432,63 @@ function generateResourceFile(resourceName, routes, options) {
|
|
|
447
432
|
`;
|
|
448
433
|
}
|
|
449
434
|
}
|
|
450
|
-
code +=
|
|
435
|
+
code += `// ============================================
|
|
451
436
|
`;
|
|
452
|
-
code +=
|
|
437
|
+
code += `// API Functions
|
|
453
438
|
`;
|
|
454
|
-
code +=
|
|
455
|
-
|
|
456
|
-
code += `export const ${resourceName} = {
|
|
439
|
+
code += `// ============================================
|
|
440
|
+
|
|
457
441
|
`;
|
|
458
442
|
for (let i = 0; i < routes.length; i++) {
|
|
459
443
|
const route = routes[i];
|
|
460
|
-
code +=
|
|
444
|
+
code += generateFunctionCode(route, options);
|
|
461
445
|
}
|
|
462
|
-
code += `} as const;
|
|
463
|
-
`;
|
|
464
446
|
return code;
|
|
465
447
|
}
|
|
466
|
-
function
|
|
467
|
-
if (str.length === 0) {
|
|
468
|
-
return str;
|
|
469
|
-
}
|
|
470
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
471
|
-
}
|
|
472
|
-
function generateIndexFile(resourceNames, options) {
|
|
448
|
+
function generateIndexFile(grouped, options) {
|
|
473
449
|
let code = "";
|
|
474
450
|
const apiName = options.apiName || "api";
|
|
451
|
+
const resourceNames = Object.keys(grouped);
|
|
475
452
|
code += generateHeader();
|
|
476
453
|
code += `export { client } from '@spfn/core/client';
|
|
477
454
|
|
|
478
455
|
`;
|
|
479
456
|
for (let i = 0; i < resourceNames.length; i++) {
|
|
480
457
|
const resourceName = resourceNames[i];
|
|
458
|
+
const routes = grouped[resourceName];
|
|
481
459
|
const kebabName = toKebabCase(resourceName);
|
|
482
|
-
|
|
460
|
+
const typeNames = [];
|
|
461
|
+
for (let j = 0; j < routes.length; j++) {
|
|
462
|
+
const route = routes[j];
|
|
463
|
+
const typeName = generateTypeName(route);
|
|
464
|
+
typeNames.push(`${typeName}Response`);
|
|
465
|
+
if (route.hasQuery) {
|
|
466
|
+
typeNames.push(`${typeName}Query`);
|
|
467
|
+
}
|
|
468
|
+
if (route.hasParams || route.path.includes(":")) {
|
|
469
|
+
typeNames.push(`${typeName}Params`);
|
|
470
|
+
}
|
|
471
|
+
if (route.hasBody) {
|
|
472
|
+
typeNames.push(`${typeName}Body`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (typeNames.length > 0) {
|
|
476
|
+
code += `export type { ${typeNames.join(", ")} } from './${kebabName}.js';
|
|
483
477
|
`;
|
|
478
|
+
}
|
|
484
479
|
}
|
|
485
480
|
code += `
|
|
486
481
|
`;
|
|
487
482
|
for (let i = 0; i < resourceNames.length; i++) {
|
|
488
483
|
const resourceName = resourceNames[i];
|
|
484
|
+
const routes = grouped[resourceName];
|
|
489
485
|
const kebabName = toKebabCase(resourceName);
|
|
490
|
-
|
|
486
|
+
const functionNames = routes.map((route) => generateFunctionName(route));
|
|
487
|
+
code += `import { ${functionNames.join(", ")} } from './${kebabName}.js';
|
|
491
488
|
`;
|
|
492
489
|
}
|
|
493
490
|
code += `
|
|
494
491
|
`;
|
|
495
|
-
const resourceKeys = resourceNames.map((name) => toCamelCase2(name));
|
|
496
492
|
code += `/**
|
|
497
493
|
`;
|
|
498
494
|
code += ` * Type-safe API client
|
|
@@ -501,17 +497,23 @@ function generateIndexFile(resourceNames, options) {
|
|
|
501
497
|
`;
|
|
502
498
|
code += `export const ${apiName} = {
|
|
503
499
|
`;
|
|
500
|
+
let isFirst = true;
|
|
504
501
|
for (let i = 0; i < resourceNames.length; i++) {
|
|
505
502
|
const resourceName = resourceNames[i];
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
503
|
+
const routes = grouped[resourceName];
|
|
504
|
+
for (let j = 0; j < routes.length; j++) {
|
|
505
|
+
const route = routes[j];
|
|
506
|
+
const functionName = generateFunctionName(route);
|
|
507
|
+
if (!isFirst) {
|
|
508
|
+
code += `,
|
|
512
509
|
`;
|
|
510
|
+
}
|
|
511
|
+
code += ` ${functionName}`;
|
|
512
|
+
isFirst = false;
|
|
513
|
+
}
|
|
513
514
|
}
|
|
514
|
-
code += `
|
|
515
|
+
code += `
|
|
516
|
+
} as const;
|
|
515
517
|
`;
|
|
516
518
|
return code;
|
|
517
519
|
}
|