@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/codegen/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { G as Generator, a as GeneratorTrigger } from '../index-DHiAqhKv.js';
|
|
2
2
|
export { C as ContractGeneratorConfig, b as GeneratorOptions, c as createContractGenerator } from '../index-DHiAqhKv.js';
|
|
3
3
|
import '../auto-loader-JFaZ9gON.js';
|
|
4
|
-
import { H as HttpMethod } from '../types-
|
|
4
|
+
import { H as HttpMethod } from '../types-Dzggq1Yb.js';
|
|
5
5
|
import 'hono';
|
|
6
6
|
import 'hono/utils/http-status';
|
|
7
7
|
import '@sinclair/typebox';
|
|
8
|
+
import '../error-handler-wjLL3v-a.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Codegen Orchestrator
|
package/dist/codegen/index.js
CHANGED
|
@@ -1222,21 +1222,28 @@ function generateTypeName(mapping) {
|
|
|
1222
1222
|
}
|
|
1223
1223
|
return name;
|
|
1224
1224
|
}
|
|
1225
|
-
function
|
|
1226
|
-
|
|
1225
|
+
function generateFunctionName(mapping) {
|
|
1226
|
+
let name = mapping.contractName;
|
|
1227
|
+
if (name.endsWith("Contract")) {
|
|
1228
|
+
name = name.slice(0, -8);
|
|
1229
|
+
}
|
|
1230
|
+
return name;
|
|
1231
|
+
}
|
|
1232
|
+
function generateFunctionCode(mapping, options) {
|
|
1233
|
+
const functionName = generateFunctionName(mapping);
|
|
1227
1234
|
const hasParams = mapping.hasParams || mapping.path.includes(":");
|
|
1228
1235
|
const hasQuery = mapping.hasQuery || false;
|
|
1229
1236
|
const hasBody = mapping.hasBody || false;
|
|
1230
1237
|
let code = "";
|
|
1231
1238
|
if (options.includeJsDoc !== false) {
|
|
1232
|
-
code +=
|
|
1239
|
+
code += `/**
|
|
1233
1240
|
`;
|
|
1234
|
-
code += `
|
|
1241
|
+
code += ` * ${mapping.method} ${mapping.path}
|
|
1235
1242
|
`;
|
|
1236
|
-
code += `
|
|
1243
|
+
code += ` */
|
|
1237
1244
|
`;
|
|
1238
1245
|
}
|
|
1239
|
-
code += `
|
|
1246
|
+
code += `export const ${functionName} = (`;
|
|
1240
1247
|
const params = [];
|
|
1241
1248
|
const typeName = generateTypeName(mapping);
|
|
1242
1249
|
if (hasParams) {
|
|
@@ -1256,33 +1263,11 @@ function generateMethodCode(mapping, options) {
|
|
|
1256
1263
|
if (params.length > 0) {
|
|
1257
1264
|
code += `, options`;
|
|
1258
1265
|
}
|
|
1259
|
-
code += `)
|
|
1266
|
+
code += `);
|
|
1267
|
+
|
|
1260
1268
|
`;
|
|
1261
1269
|
return code;
|
|
1262
1270
|
}
|
|
1263
|
-
function generateMethodName(mapping) {
|
|
1264
|
-
const method = mapping.method.toLowerCase();
|
|
1265
|
-
if (mapping.path === "/" || mapping.path.match(/^\/[\w-]+$/)) {
|
|
1266
|
-
if (method === "get") {
|
|
1267
|
-
return "list";
|
|
1268
|
-
}
|
|
1269
|
-
if (method === "post") {
|
|
1270
|
-
return "create";
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
if (mapping.path.includes(":")) {
|
|
1274
|
-
if (method === "get") {
|
|
1275
|
-
return "getById";
|
|
1276
|
-
}
|
|
1277
|
-
if (method === "put" || method === "patch") {
|
|
1278
|
-
return "update";
|
|
1279
|
-
}
|
|
1280
|
-
if (method === "delete") {
|
|
1281
|
-
return "delete";
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
return method;
|
|
1285
|
-
}
|
|
1286
1271
|
function countUniqueContractFiles(mappings) {
|
|
1287
1272
|
const files = /* @__PURE__ */ new Set();
|
|
1288
1273
|
for (let i = 0; i < mappings.length; i++) {
|
|
@@ -1311,11 +1296,11 @@ async function generateSplitClient(_mappings, grouped, options) {
|
|
|
1311
1296
|
const filePath = `${outputDir}/${kebabName}.ts`;
|
|
1312
1297
|
await writeFile(filePath, code, "utf-8");
|
|
1313
1298
|
}
|
|
1314
|
-
const indexCode = generateIndexFile(
|
|
1299
|
+
const indexCode = generateIndexFile(grouped, options);
|
|
1315
1300
|
const indexPath = `${outputDir}/index.ts`;
|
|
1316
1301
|
await writeFile(indexPath, indexCode, "utf-8");
|
|
1317
1302
|
}
|
|
1318
|
-
function generateResourceFile(
|
|
1303
|
+
function generateResourceFile(_resourceName, routes, options) {
|
|
1319
1304
|
let code = "";
|
|
1320
1305
|
code += generateHeader();
|
|
1321
1306
|
code += `import { client } from '@spfn/core/client';
|
|
@@ -1366,52 +1351,63 @@ function generateResourceFile(resourceName, routes, options) {
|
|
|
1366
1351
|
`;
|
|
1367
1352
|
}
|
|
1368
1353
|
}
|
|
1369
|
-
code +=
|
|
1354
|
+
code += `// ============================================
|
|
1370
1355
|
`;
|
|
1371
|
-
code +=
|
|
1356
|
+
code += `// API Functions
|
|
1372
1357
|
`;
|
|
1373
|
-
code +=
|
|
1374
|
-
|
|
1375
|
-
code += `export const ${resourceName} = {
|
|
1358
|
+
code += `// ============================================
|
|
1359
|
+
|
|
1376
1360
|
`;
|
|
1377
1361
|
for (let i = 0; i < routes.length; i++) {
|
|
1378
1362
|
const route = routes[i];
|
|
1379
|
-
code +=
|
|
1363
|
+
code += generateFunctionCode(route, options);
|
|
1380
1364
|
}
|
|
1381
|
-
code += `} as const;
|
|
1382
|
-
`;
|
|
1383
1365
|
return code;
|
|
1384
1366
|
}
|
|
1385
|
-
function
|
|
1386
|
-
if (str.length === 0) {
|
|
1387
|
-
return str;
|
|
1388
|
-
}
|
|
1389
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
1390
|
-
}
|
|
1391
|
-
function generateIndexFile(resourceNames, options) {
|
|
1367
|
+
function generateIndexFile(grouped, options) {
|
|
1392
1368
|
let code = "";
|
|
1393
1369
|
const apiName = options.apiName || "api";
|
|
1370
|
+
const resourceNames = Object.keys(grouped);
|
|
1394
1371
|
code += generateHeader();
|
|
1395
1372
|
code += `export { client } from '@spfn/core/client';
|
|
1396
1373
|
|
|
1397
1374
|
`;
|
|
1398
1375
|
for (let i = 0; i < resourceNames.length; i++) {
|
|
1399
1376
|
const resourceName = resourceNames[i];
|
|
1377
|
+
const routes = grouped[resourceName];
|
|
1400
1378
|
const kebabName = toKebabCase(resourceName);
|
|
1401
|
-
|
|
1379
|
+
const typeNames = [];
|
|
1380
|
+
for (let j = 0; j < routes.length; j++) {
|
|
1381
|
+
const route = routes[j];
|
|
1382
|
+
const typeName = generateTypeName(route);
|
|
1383
|
+
typeNames.push(`${typeName}Response`);
|
|
1384
|
+
if (route.hasQuery) {
|
|
1385
|
+
typeNames.push(`${typeName}Query`);
|
|
1386
|
+
}
|
|
1387
|
+
if (route.hasParams || route.path.includes(":")) {
|
|
1388
|
+
typeNames.push(`${typeName}Params`);
|
|
1389
|
+
}
|
|
1390
|
+
if (route.hasBody) {
|
|
1391
|
+
typeNames.push(`${typeName}Body`);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
if (typeNames.length > 0) {
|
|
1395
|
+
code += `export type { ${typeNames.join(", ")} } from './${kebabName}.js';
|
|
1402
1396
|
`;
|
|
1397
|
+
}
|
|
1403
1398
|
}
|
|
1404
1399
|
code += `
|
|
1405
1400
|
`;
|
|
1406
1401
|
for (let i = 0; i < resourceNames.length; i++) {
|
|
1407
1402
|
const resourceName = resourceNames[i];
|
|
1403
|
+
const routes = grouped[resourceName];
|
|
1408
1404
|
const kebabName = toKebabCase(resourceName);
|
|
1409
|
-
|
|
1405
|
+
const functionNames = routes.map((route) => generateFunctionName(route));
|
|
1406
|
+
code += `import { ${functionNames.join(", ")} } from './${kebabName}.js';
|
|
1410
1407
|
`;
|
|
1411
1408
|
}
|
|
1412
1409
|
code += `
|
|
1413
1410
|
`;
|
|
1414
|
-
const resourceKeys = resourceNames.map((name) => toCamelCase2(name));
|
|
1415
1411
|
code += `/**
|
|
1416
1412
|
`;
|
|
1417
1413
|
code += ` * Type-safe API client
|
|
@@ -1420,17 +1416,23 @@ function generateIndexFile(resourceNames, options) {
|
|
|
1420
1416
|
`;
|
|
1421
1417
|
code += `export const ${apiName} = {
|
|
1422
1418
|
`;
|
|
1419
|
+
let isFirst = true;
|
|
1423
1420
|
for (let i = 0; i < resourceNames.length; i++) {
|
|
1424
1421
|
const resourceName = resourceNames[i];
|
|
1425
|
-
const
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1422
|
+
const routes = grouped[resourceName];
|
|
1423
|
+
for (let j = 0; j < routes.length; j++) {
|
|
1424
|
+
const route = routes[j];
|
|
1425
|
+
const functionName = generateFunctionName(route);
|
|
1426
|
+
if (!isFirst) {
|
|
1427
|
+
code += `,
|
|
1431
1428
|
`;
|
|
1429
|
+
}
|
|
1430
|
+
code += ` ${functionName}`;
|
|
1431
|
+
isFirst = false;
|
|
1432
|
+
}
|
|
1432
1433
|
}
|
|
1433
|
-
code += `
|
|
1434
|
+
code += `
|
|
1435
|
+
} as const;
|
|
1434
1436
|
`;
|
|
1435
1437
|
return code;
|
|
1436
1438
|
}
|