postgresdk 0.18.13 → 0.18.14
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/cli.js +49 -9
- package/dist/emit-client.d.ts +4 -1
- package/dist/emit-include-methods.d.ts +2 -0
- package/dist/index.js +49 -9
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -605,12 +605,16 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
605
605
|
const newIsMany = [...isMany, edge.kind === "many"];
|
|
606
606
|
const newTargets = [...targets, edge.target];
|
|
607
607
|
const methodSuffix = pathToMethodSuffix(newPath);
|
|
608
|
+
const baseType = buildReturnType(baseTableName, newPath, newIsMany, newTargets, graph);
|
|
609
|
+
const typeName = `Select${pascal(baseTableName)}${methodSuffix}`;
|
|
608
610
|
methods.push({
|
|
609
611
|
name: `list${methodSuffix}`,
|
|
610
612
|
path: newPath,
|
|
611
613
|
isMany: newIsMany,
|
|
612
614
|
targets: newTargets,
|
|
613
|
-
returnType: `PaginatedResponse<${
|
|
615
|
+
returnType: `PaginatedResponse<${baseType}>`,
|
|
616
|
+
typeName,
|
|
617
|
+
baseType,
|
|
614
618
|
includeSpec: buildIncludeSpec(newPath)
|
|
615
619
|
});
|
|
616
620
|
methods.push({
|
|
@@ -618,7 +622,9 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
618
622
|
path: newPath,
|
|
619
623
|
isMany: newIsMany,
|
|
620
624
|
targets: newTargets,
|
|
621
|
-
returnType: `${
|
|
625
|
+
returnType: `${baseType} | null`,
|
|
626
|
+
typeName,
|
|
627
|
+
baseType,
|
|
622
628
|
includeSpec: buildIncludeSpec(newPath)
|
|
623
629
|
});
|
|
624
630
|
explore(edge.target, newPath, newIsMany, newTargets, new Set([...visited, edge.target]), depth + 1);
|
|
@@ -645,12 +651,16 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
645
651
|
const combinedSuffix = `With${pascal(key1)}And${pascal(key2)}`;
|
|
646
652
|
const type1 = `${key1}: ${edge1.kind === "many" ? `Select${pascal(edge1.target)}[]` : `Select${pascal(edge1.target)}`}`;
|
|
647
653
|
const type2 = `${key2}: ${edge2.kind === "many" ? `Select${pascal(edge2.target)}[]` : `Select${pascal(edge2.target)}`}`;
|
|
654
|
+
const combinedBaseType = `Select${pascal(baseTableName)} & { ${type1}; ${type2} }`;
|
|
655
|
+
const combinedTypeName = `Select${pascal(baseTableName)}${combinedSuffix}`;
|
|
648
656
|
methods.push({
|
|
649
657
|
name: `list${combinedSuffix}`,
|
|
650
658
|
path: combinedPath,
|
|
651
659
|
isMany: [edge1.kind === "many", edge2.kind === "many"],
|
|
652
660
|
targets: [edge1.target, edge2.target],
|
|
653
|
-
returnType: `PaginatedResponse
|
|
661
|
+
returnType: `PaginatedResponse<${combinedBaseType}>`,
|
|
662
|
+
typeName: combinedTypeName,
|
|
663
|
+
baseType: combinedBaseType,
|
|
654
664
|
includeSpec: { [key1]: true, [key2]: true }
|
|
655
665
|
});
|
|
656
666
|
methods.push({
|
|
@@ -658,7 +668,9 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
658
668
|
path: combinedPath,
|
|
659
669
|
isMany: [edge1.kind === "many", edge2.kind === "many"],
|
|
660
670
|
targets: [edge1.target, edge2.target],
|
|
661
|
-
returnType:
|
|
671
|
+
returnType: `${combinedBaseType} | null`,
|
|
672
|
+
typeName: combinedTypeName,
|
|
673
|
+
baseType: combinedBaseType,
|
|
662
674
|
includeSpec: { [key1]: true, [key2]: true }
|
|
663
675
|
});
|
|
664
676
|
}
|
|
@@ -3560,6 +3572,15 @@ function emitClient(table, graph, opts, model) {
|
|
|
3560
3572
|
otherTableImports.push(`import type { Select${pascal(target)} } from "./types/${target}${ext}";`);
|
|
3561
3573
|
}
|
|
3562
3574
|
}
|
|
3575
|
+
const seenTypeNames = new Set;
|
|
3576
|
+
let typeAliasesCode = "";
|
|
3577
|
+
for (const method of includeMethods) {
|
|
3578
|
+
if (!seenTypeNames.has(method.typeName)) {
|
|
3579
|
+
seenTypeNames.add(method.typeName);
|
|
3580
|
+
typeAliasesCode += `export type ${method.typeName} = ${method.baseType};
|
|
3581
|
+
`;
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3563
3584
|
let includeMethodsCode = "";
|
|
3564
3585
|
for (const method of includeMethods) {
|
|
3565
3586
|
const isGetByPk = method.name.startsWith("getByPk");
|
|
@@ -3644,7 +3665,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
3644
3665
|
}
|
|
3645
3666
|
if (isGetByPk) {
|
|
3646
3667
|
const pkWhere = hasCompositePk ? `{ ${safePk.map((col) => `${col}: pk.${col}`).join(", ")} }` : `{ ${safePk[0] || "id"}: pk }`;
|
|
3647
|
-
const baseReturnType = method.
|
|
3668
|
+
const baseReturnType = method.typeName;
|
|
3648
3669
|
let transformCode = "";
|
|
3649
3670
|
if (includeParamNames.length > 0) {
|
|
3650
3671
|
const destructure = includeParamNames.map((name) => name).join(", ");
|
|
@@ -3680,7 +3701,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
3680
3701
|
* @param params - Optional include options (including select/exclude for base and nested tables)
|
|
3681
3702
|
* @returns The record with nested ${method.path.join(" and ")} if found, null otherwise
|
|
3682
3703
|
*/
|
|
3683
|
-
async ${method.name}(pk: ${pkType}, params?: ${paramsType}): Promise<${method.
|
|
3704
|
+
async ${method.name}(pk: ${pkType}, params?: ${paramsType}): Promise<${method.typeName} | null> {${transformCode}
|
|
3684
3705
|
const results = await this.post<PaginatedResponse<${baseReturnType}>>(\`\${this.resource}/list\`, {
|
|
3685
3706
|
where: ${pkWhere},
|
|
3686
3707
|
select: params?.select,
|
|
@@ -3729,7 +3750,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
3729
3750
|
* @param params - Query parameters (where, orderBy, order, limit, offset) and include options
|
|
3730
3751
|
* @returns Paginated results with nested ${method.path.join(" and ")} included
|
|
3731
3752
|
*/
|
|
3732
|
-
async ${method.name}(params?: ${paramsType}): Promise<${method.
|
|
3753
|
+
async ${method.name}(params?: ${paramsType}): Promise<PaginatedResponse<${method.typeName}>> {${transformCode}
|
|
3733
3754
|
}
|
|
3734
3755
|
`;
|
|
3735
3756
|
}
|
|
@@ -3751,6 +3772,7 @@ ${includeResolverImport}
|
|
|
3751
3772
|
${otherTableImports.join(`
|
|
3752
3773
|
`)}
|
|
3753
3774
|
|
|
3775
|
+
${typeAliasesCode}
|
|
3754
3776
|
/**
|
|
3755
3777
|
* Client for ${table.name} table operations
|
|
3756
3778
|
*/
|
|
@@ -4206,7 +4228,7 @@ ${hasJsonbColumns ? ` /**
|
|
|
4206
4228
|
${includeMethodsCode}}
|
|
4207
4229
|
`;
|
|
4208
4230
|
}
|
|
4209
|
-
function emitClientIndex(tables, useJsExtensions) {
|
|
4231
|
+
function emitClientIndex(tables, useJsExtensions, graph, includeOpts) {
|
|
4210
4232
|
const ext = useJsExtensions ? ".js" : "";
|
|
4211
4233
|
let out = `/**
|
|
4212
4234
|
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
@@ -4296,6 +4318,24 @@ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${
|
|
|
4296
4318
|
`;
|
|
4297
4319
|
out += `export type { PaginatedResponse } from "./types/shared${ext}";
|
|
4298
4320
|
`;
|
|
4321
|
+
if (graph && includeOpts) {
|
|
4322
|
+
const opts = { maxDepth: includeOpts.maxDepth, skipJunctionTables: includeOpts.skipJunctionTables };
|
|
4323
|
+
for (const t of tables) {
|
|
4324
|
+
const methods = generateIncludeMethods(t, graph, opts, tables);
|
|
4325
|
+
const seenTypeNames = new Set;
|
|
4326
|
+
const typeNames = [];
|
|
4327
|
+
for (const method of methods) {
|
|
4328
|
+
if (!seenTypeNames.has(method.typeName)) {
|
|
4329
|
+
seenTypeNames.add(method.typeName);
|
|
4330
|
+
typeNames.push(method.typeName);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
if (typeNames.length > 0) {
|
|
4334
|
+
out += `export type { ${typeNames.join(", ")} } from "./${t.name}${ext}";
|
|
4335
|
+
`;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4299
4339
|
return out;
|
|
4300
4340
|
}
|
|
4301
4341
|
|
|
@@ -7277,7 +7317,7 @@ async function generate(configPath) {
|
|
|
7277
7317
|
}
|
|
7278
7318
|
files.push({
|
|
7279
7319
|
path: join(clientDir, "index.ts"),
|
|
7280
|
-
content: emitClientIndex(Object.values(model.tables), cfg.useJsExtensionsClient)
|
|
7320
|
+
content: emitClientIndex(Object.values(model.tables), cfg.useJsExtensionsClient, graph, { maxDepth: cfg.includeMethodsDepth ?? 2, skipJunctionTables: cfg.skipJunctionTables ?? true })
|
|
7281
7321
|
});
|
|
7282
7322
|
if (serverFramework === "hono") {
|
|
7283
7323
|
files.push({
|
package/dist/emit-client.d.ts
CHANGED
|
@@ -5,4 +5,7 @@ export declare function emitClient(table: Table, graph: Graph, opts: {
|
|
|
5
5
|
includeMethodsDepth?: number;
|
|
6
6
|
skipJunctionTables?: boolean;
|
|
7
7
|
}, model?: Model): string;
|
|
8
|
-
export declare function emitClientIndex(tables: Table[], useJsExtensions?: boolean
|
|
8
|
+
export declare function emitClientIndex(tables: Table[], useJsExtensions?: boolean, graph?: Graph, includeOpts?: {
|
|
9
|
+
maxDepth: number;
|
|
10
|
+
skipJunctionTables: boolean;
|
|
11
|
+
}): string;
|
package/dist/index.js
CHANGED
|
@@ -604,12 +604,16 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
604
604
|
const newIsMany = [...isMany, edge.kind === "many"];
|
|
605
605
|
const newTargets = [...targets, edge.target];
|
|
606
606
|
const methodSuffix = pathToMethodSuffix(newPath);
|
|
607
|
+
const baseType = buildReturnType(baseTableName, newPath, newIsMany, newTargets, graph);
|
|
608
|
+
const typeName = `Select${pascal(baseTableName)}${methodSuffix}`;
|
|
607
609
|
methods.push({
|
|
608
610
|
name: `list${methodSuffix}`,
|
|
609
611
|
path: newPath,
|
|
610
612
|
isMany: newIsMany,
|
|
611
613
|
targets: newTargets,
|
|
612
|
-
returnType: `PaginatedResponse<${
|
|
614
|
+
returnType: `PaginatedResponse<${baseType}>`,
|
|
615
|
+
typeName,
|
|
616
|
+
baseType,
|
|
613
617
|
includeSpec: buildIncludeSpec(newPath)
|
|
614
618
|
});
|
|
615
619
|
methods.push({
|
|
@@ -617,7 +621,9 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
617
621
|
path: newPath,
|
|
618
622
|
isMany: newIsMany,
|
|
619
623
|
targets: newTargets,
|
|
620
|
-
returnType: `${
|
|
624
|
+
returnType: `${baseType} | null`,
|
|
625
|
+
typeName,
|
|
626
|
+
baseType,
|
|
621
627
|
includeSpec: buildIncludeSpec(newPath)
|
|
622
628
|
});
|
|
623
629
|
explore(edge.target, newPath, newIsMany, newTargets, new Set([...visited, edge.target]), depth + 1);
|
|
@@ -644,12 +650,16 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
644
650
|
const combinedSuffix = `With${pascal(key1)}And${pascal(key2)}`;
|
|
645
651
|
const type1 = `${key1}: ${edge1.kind === "many" ? `Select${pascal(edge1.target)}[]` : `Select${pascal(edge1.target)}`}`;
|
|
646
652
|
const type2 = `${key2}: ${edge2.kind === "many" ? `Select${pascal(edge2.target)}[]` : `Select${pascal(edge2.target)}`}`;
|
|
653
|
+
const combinedBaseType = `Select${pascal(baseTableName)} & { ${type1}; ${type2} }`;
|
|
654
|
+
const combinedTypeName = `Select${pascal(baseTableName)}${combinedSuffix}`;
|
|
647
655
|
methods.push({
|
|
648
656
|
name: `list${combinedSuffix}`,
|
|
649
657
|
path: combinedPath,
|
|
650
658
|
isMany: [edge1.kind === "many", edge2.kind === "many"],
|
|
651
659
|
targets: [edge1.target, edge2.target],
|
|
652
|
-
returnType: `PaginatedResponse
|
|
660
|
+
returnType: `PaginatedResponse<${combinedBaseType}>`,
|
|
661
|
+
typeName: combinedTypeName,
|
|
662
|
+
baseType: combinedBaseType,
|
|
653
663
|
includeSpec: { [key1]: true, [key2]: true }
|
|
654
664
|
});
|
|
655
665
|
methods.push({
|
|
@@ -657,7 +667,9 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
657
667
|
path: combinedPath,
|
|
658
668
|
isMany: [edge1.kind === "many", edge2.kind === "many"],
|
|
659
669
|
targets: [edge1.target, edge2.target],
|
|
660
|
-
returnType:
|
|
670
|
+
returnType: `${combinedBaseType} | null`,
|
|
671
|
+
typeName: combinedTypeName,
|
|
672
|
+
baseType: combinedBaseType,
|
|
661
673
|
includeSpec: { [key1]: true, [key2]: true }
|
|
662
674
|
});
|
|
663
675
|
}
|
|
@@ -2599,6 +2611,15 @@ function emitClient(table, graph, opts, model) {
|
|
|
2599
2611
|
otherTableImports.push(`import type { Select${pascal(target)} } from "./types/${target}${ext}";`);
|
|
2600
2612
|
}
|
|
2601
2613
|
}
|
|
2614
|
+
const seenTypeNames = new Set;
|
|
2615
|
+
let typeAliasesCode = "";
|
|
2616
|
+
for (const method of includeMethods) {
|
|
2617
|
+
if (!seenTypeNames.has(method.typeName)) {
|
|
2618
|
+
seenTypeNames.add(method.typeName);
|
|
2619
|
+
typeAliasesCode += `export type ${method.typeName} = ${method.baseType};
|
|
2620
|
+
`;
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2602
2623
|
let includeMethodsCode = "";
|
|
2603
2624
|
for (const method of includeMethods) {
|
|
2604
2625
|
const isGetByPk = method.name.startsWith("getByPk");
|
|
@@ -2683,7 +2704,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
2683
2704
|
}
|
|
2684
2705
|
if (isGetByPk) {
|
|
2685
2706
|
const pkWhere = hasCompositePk ? `{ ${safePk.map((col) => `${col}: pk.${col}`).join(", ")} }` : `{ ${safePk[0] || "id"}: pk }`;
|
|
2686
|
-
const baseReturnType = method.
|
|
2707
|
+
const baseReturnType = method.typeName;
|
|
2687
2708
|
let transformCode = "";
|
|
2688
2709
|
if (includeParamNames.length > 0) {
|
|
2689
2710
|
const destructure = includeParamNames.map((name) => name).join(", ");
|
|
@@ -2719,7 +2740,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
2719
2740
|
* @param params - Optional include options (including select/exclude for base and nested tables)
|
|
2720
2741
|
* @returns The record with nested ${method.path.join(" and ")} if found, null otherwise
|
|
2721
2742
|
*/
|
|
2722
|
-
async ${method.name}(pk: ${pkType}, params?: ${paramsType}): Promise<${method.
|
|
2743
|
+
async ${method.name}(pk: ${pkType}, params?: ${paramsType}): Promise<${method.typeName} | null> {${transformCode}
|
|
2723
2744
|
const results = await this.post<PaginatedResponse<${baseReturnType}>>(\`\${this.resource}/list\`, {
|
|
2724
2745
|
where: ${pkWhere},
|
|
2725
2746
|
select: params?.select,
|
|
@@ -2768,7 +2789,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
2768
2789
|
* @param params - Query parameters (where, orderBy, order, limit, offset) and include options
|
|
2769
2790
|
* @returns Paginated results with nested ${method.path.join(" and ")} included
|
|
2770
2791
|
*/
|
|
2771
|
-
async ${method.name}(params?: ${paramsType}): Promise<${method.
|
|
2792
|
+
async ${method.name}(params?: ${paramsType}): Promise<PaginatedResponse<${method.typeName}>> {${transformCode}
|
|
2772
2793
|
}
|
|
2773
2794
|
`;
|
|
2774
2795
|
}
|
|
@@ -2790,6 +2811,7 @@ ${includeResolverImport}
|
|
|
2790
2811
|
${otherTableImports.join(`
|
|
2791
2812
|
`)}
|
|
2792
2813
|
|
|
2814
|
+
${typeAliasesCode}
|
|
2793
2815
|
/**
|
|
2794
2816
|
* Client for ${table.name} table operations
|
|
2795
2817
|
*/
|
|
@@ -3245,7 +3267,7 @@ ${hasJsonbColumns ? ` /**
|
|
|
3245
3267
|
${includeMethodsCode}}
|
|
3246
3268
|
`;
|
|
3247
3269
|
}
|
|
3248
|
-
function emitClientIndex(tables, useJsExtensions) {
|
|
3270
|
+
function emitClientIndex(tables, useJsExtensions, graph, includeOpts) {
|
|
3249
3271
|
const ext = useJsExtensions ? ".js" : "";
|
|
3250
3272
|
let out = `/**
|
|
3251
3273
|
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
@@ -3335,6 +3357,24 @@ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${
|
|
|
3335
3357
|
`;
|
|
3336
3358
|
out += `export type { PaginatedResponse } from "./types/shared${ext}";
|
|
3337
3359
|
`;
|
|
3360
|
+
if (graph && includeOpts) {
|
|
3361
|
+
const opts = { maxDepth: includeOpts.maxDepth, skipJunctionTables: includeOpts.skipJunctionTables };
|
|
3362
|
+
for (const t of tables) {
|
|
3363
|
+
const methods = generateIncludeMethods(t, graph, opts, tables);
|
|
3364
|
+
const seenTypeNames = new Set;
|
|
3365
|
+
const typeNames = [];
|
|
3366
|
+
for (const method of methods) {
|
|
3367
|
+
if (!seenTypeNames.has(method.typeName)) {
|
|
3368
|
+
seenTypeNames.add(method.typeName);
|
|
3369
|
+
typeNames.push(method.typeName);
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
if (typeNames.length > 0) {
|
|
3373
|
+
out += `export type { ${typeNames.join(", ")} } from "./${t.name}${ext}";
|
|
3374
|
+
`;
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3338
3378
|
return out;
|
|
3339
3379
|
}
|
|
3340
3380
|
|
|
@@ -6316,7 +6356,7 @@ async function generate(configPath) {
|
|
|
6316
6356
|
}
|
|
6317
6357
|
files.push({
|
|
6318
6358
|
path: join(clientDir, "index.ts"),
|
|
6319
|
-
content: emitClientIndex(Object.values(model.tables), cfg.useJsExtensionsClient)
|
|
6359
|
+
content: emitClientIndex(Object.values(model.tables), cfg.useJsExtensionsClient, graph, { maxDepth: cfg.includeMethodsDepth ?? 2, skipJunctionTables: cfg.skipJunctionTables ?? true })
|
|
6320
6360
|
});
|
|
6321
6361
|
if (serverFramework === "hono") {
|
|
6322
6362
|
files.push({
|