postgresdk 0.13.0 → 0.13.1
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 +39 -19
- package/dist/emit-shared-types.d.ts +1 -0
- package/dist/index.js +39 -19
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -578,7 +578,7 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
578
578
|
path: newPath,
|
|
579
579
|
isMany: newIsMany,
|
|
580
580
|
targets: newTargets,
|
|
581
|
-
returnType: `{
|
|
581
|
+
returnType: `PaginatedResponse<${buildReturnType(baseTableName, newPath, newIsMany, newTargets, graph)}>`,
|
|
582
582
|
includeSpec: buildIncludeSpec(newPath)
|
|
583
583
|
});
|
|
584
584
|
methods.push({
|
|
@@ -618,7 +618,7 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
618
618
|
path: combinedPath,
|
|
619
619
|
isMany: [edge1.kind === "many", edge2.kind === "many"],
|
|
620
620
|
targets: [edge1.target, edge2.target],
|
|
621
|
-
returnType: `
|
|
621
|
+
returnType: `PaginatedResponse<Select${pascal(baseTableName)} & { ${type1}; ${type2} }>`,
|
|
622
622
|
includeSpec: { [key1]: true, [key2]: true }
|
|
623
623
|
});
|
|
624
624
|
methods.push({
|
|
@@ -785,7 +785,7 @@ function generateResourceWithSDK(table, model, graph, config) {
|
|
|
785
785
|
const endpoints = [];
|
|
786
786
|
sdkMethods.push({
|
|
787
787
|
name: "list",
|
|
788
|
-
signature: `list(params?: ListParams): Promise<{
|
|
788
|
+
signature: `list(params?: ListParams): Promise<PaginatedResponse<${Type}>>`,
|
|
789
789
|
description: `List ${tableName} with filtering, sorting, and pagination. Returns paginated results with metadata.`,
|
|
790
790
|
example: `// Get all ${tableName}
|
|
791
791
|
const result = await sdk.${tableName}.list();
|
|
@@ -812,7 +812,7 @@ const currentPage = Math.floor(filtered.offset / filtered.limit) + 1;`,
|
|
|
812
812
|
path: basePath,
|
|
813
813
|
description: `List all ${tableName} records with pagination metadata`,
|
|
814
814
|
queryParameters: generateQueryParams(table, enums),
|
|
815
|
-
responseBody: `{
|
|
815
|
+
responseBody: `PaginatedResponse<${Type}>`
|
|
816
816
|
});
|
|
817
817
|
if (hasSinglePK) {
|
|
818
818
|
sdkMethods.push({
|
|
@@ -2735,6 +2735,31 @@ export type PaginationParams = z.infer<typeof PaginationParamsSchema>;
|
|
|
2735
2735
|
`;
|
|
2736
2736
|
}
|
|
2737
2737
|
|
|
2738
|
+
// src/emit-shared-types.ts
|
|
2739
|
+
function emitSharedTypes() {
|
|
2740
|
+
return `/**
|
|
2741
|
+
* Shared types used across all SDK operations
|
|
2742
|
+
*/
|
|
2743
|
+
|
|
2744
|
+
/**
|
|
2745
|
+
* Paginated response structure returned by list operations
|
|
2746
|
+
* @template T - The type of records in the data array
|
|
2747
|
+
*/
|
|
2748
|
+
export interface PaginatedResponse<T> {
|
|
2749
|
+
/** Array of records for the current page */
|
|
2750
|
+
data: T[];
|
|
2751
|
+
/** Total number of records matching the query (across all pages) */
|
|
2752
|
+
total: number;
|
|
2753
|
+
/** Maximum number of records per page */
|
|
2754
|
+
limit: number;
|
|
2755
|
+
/** Number of records skipped (for pagination) */
|
|
2756
|
+
offset: number;
|
|
2757
|
+
/** Whether there are more records available after this page */
|
|
2758
|
+
hasMore: boolean;
|
|
2759
|
+
}
|
|
2760
|
+
`;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2738
2763
|
// src/emit-routes-hono.ts
|
|
2739
2764
|
init_utils();
|
|
2740
2765
|
function emitHonoRoutes(table, _graph, opts) {
|
|
@@ -3003,7 +3028,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
3003
3028
|
* @returns The record with nested ${method.path.join(" and ")} if found, null otherwise
|
|
3004
3029
|
*/
|
|
3005
3030
|
async ${method.name}(pk: ${pkType}): Promise<${method.returnType}> {
|
|
3006
|
-
const results = await this.post<{
|
|
3031
|
+
const results = await this.post<PaginatedResponse<${baseReturnType}>>(\`\${this.resource}/list\`, {
|
|
3007
3032
|
where: ${pkWhere},
|
|
3008
3033
|
include: ${JSON.stringify(method.includeSpec)},
|
|
3009
3034
|
limit: 1
|
|
@@ -3034,6 +3059,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
3034
3059
|
*/
|
|
3035
3060
|
import { BaseClient } from "./base-client${ext}";
|
|
3036
3061
|
import type { Where } from "./where-types${ext}";
|
|
3062
|
+
import type { PaginatedResponse } from "./types/shared${ext}";
|
|
3037
3063
|
${typeImports}
|
|
3038
3064
|
${otherTableImports.join(`
|
|
3039
3065
|
`)}
|
|
@@ -3081,20 +3107,8 @@ export class ${Type}Client extends BaseClient {
|
|
|
3081
3107
|
where?: Where<Select${Type}>;
|
|
3082
3108
|
orderBy?: string | string[];
|
|
3083
3109
|
order?: "asc" | "desc" | ("asc" | "desc")[];
|
|
3084
|
-
}): Promise<{
|
|
3085
|
-
|
|
3086
|
-
total: number;
|
|
3087
|
-
limit: number;
|
|
3088
|
-
offset: number;
|
|
3089
|
-
hasMore: boolean;
|
|
3090
|
-
}> {
|
|
3091
|
-
return this.post<{
|
|
3092
|
-
data: Select${Type}[];
|
|
3093
|
-
total: number;
|
|
3094
|
-
limit: number;
|
|
3095
|
-
offset: number;
|
|
3096
|
-
hasMore: boolean;
|
|
3097
|
-
}>(\`\${this.resource}/list\`, params ?? {});
|
|
3110
|
+
}): Promise<PaginatedResponse<Select${Type}>> {
|
|
3111
|
+
return this.post<PaginatedResponse<Select${Type}>>(\`\${this.resource}/list\`, params ?? {});
|
|
3098
3112
|
}
|
|
3099
3113
|
|
|
3100
3114
|
/**
|
|
@@ -3205,6 +3219,11 @@ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${
|
|
|
3205
3219
|
out += `export type { Insert${Type}, Update${Type}, Select${Type} } from "./types/${t.name}${ext}";
|
|
3206
3220
|
`;
|
|
3207
3221
|
}
|
|
3222
|
+
out += `
|
|
3223
|
+
// Shared types
|
|
3224
|
+
`;
|
|
3225
|
+
out += `export type { PaginatedResponse } from "./types/shared${ext}";
|
|
3226
|
+
`;
|
|
3208
3227
|
return out;
|
|
3209
3228
|
}
|
|
3210
3229
|
|
|
@@ -5439,6 +5458,7 @@ async function generate(configPath) {
|
|
|
5439
5458
|
files.push({ path: join(serverDir, "include-spec.ts"), content: includeSpec });
|
|
5440
5459
|
files.push({ path: join(clientDir, "include-spec.ts"), content: includeSpec });
|
|
5441
5460
|
files.push({ path: join(clientDir, "params", "shared.ts"), content: emitSharedParamsZod() });
|
|
5461
|
+
files.push({ path: join(clientDir, "types", "shared.ts"), content: emitSharedTypes() });
|
|
5442
5462
|
files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
|
|
5443
5463
|
files.push({ path: join(clientDir, "where-types.ts"), content: emitWhereTypes() });
|
|
5444
5464
|
files.push({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function emitSharedTypes(): string;
|
package/dist/index.js
CHANGED
|
@@ -577,7 +577,7 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
577
577
|
path: newPath,
|
|
578
578
|
isMany: newIsMany,
|
|
579
579
|
targets: newTargets,
|
|
580
|
-
returnType: `{
|
|
580
|
+
returnType: `PaginatedResponse<${buildReturnType(baseTableName, newPath, newIsMany, newTargets, graph)}>`,
|
|
581
581
|
includeSpec: buildIncludeSpec(newPath)
|
|
582
582
|
});
|
|
583
583
|
methods.push({
|
|
@@ -617,7 +617,7 @@ function generateIncludeMethods(table, graph, opts, allTables) {
|
|
|
617
617
|
path: combinedPath,
|
|
618
618
|
isMany: [edge1.kind === "many", edge2.kind === "many"],
|
|
619
619
|
targets: [edge1.target, edge2.target],
|
|
620
|
-
returnType: `
|
|
620
|
+
returnType: `PaginatedResponse<Select${pascal(baseTableName)} & { ${type1}; ${type2} }>`,
|
|
621
621
|
includeSpec: { [key1]: true, [key2]: true }
|
|
622
622
|
});
|
|
623
623
|
methods.push({
|
|
@@ -784,7 +784,7 @@ function generateResourceWithSDK(table, model, graph, config) {
|
|
|
784
784
|
const endpoints = [];
|
|
785
785
|
sdkMethods.push({
|
|
786
786
|
name: "list",
|
|
787
|
-
signature: `list(params?: ListParams): Promise<{
|
|
787
|
+
signature: `list(params?: ListParams): Promise<PaginatedResponse<${Type}>>`,
|
|
788
788
|
description: `List ${tableName} with filtering, sorting, and pagination. Returns paginated results with metadata.`,
|
|
789
789
|
example: `// Get all ${tableName}
|
|
790
790
|
const result = await sdk.${tableName}.list();
|
|
@@ -811,7 +811,7 @@ const currentPage = Math.floor(filtered.offset / filtered.limit) + 1;`,
|
|
|
811
811
|
path: basePath,
|
|
812
812
|
description: `List all ${tableName} records with pagination metadata`,
|
|
813
813
|
queryParameters: generateQueryParams(table, enums),
|
|
814
|
-
responseBody: `{
|
|
814
|
+
responseBody: `PaginatedResponse<${Type}>`
|
|
815
815
|
});
|
|
816
816
|
if (hasSinglePK) {
|
|
817
817
|
sdkMethods.push({
|
|
@@ -1975,6 +1975,31 @@ export type PaginationParams = z.infer<typeof PaginationParamsSchema>;
|
|
|
1975
1975
|
`;
|
|
1976
1976
|
}
|
|
1977
1977
|
|
|
1978
|
+
// src/emit-shared-types.ts
|
|
1979
|
+
function emitSharedTypes() {
|
|
1980
|
+
return `/**
|
|
1981
|
+
* Shared types used across all SDK operations
|
|
1982
|
+
*/
|
|
1983
|
+
|
|
1984
|
+
/**
|
|
1985
|
+
* Paginated response structure returned by list operations
|
|
1986
|
+
* @template T - The type of records in the data array
|
|
1987
|
+
*/
|
|
1988
|
+
export interface PaginatedResponse<T> {
|
|
1989
|
+
/** Array of records for the current page */
|
|
1990
|
+
data: T[];
|
|
1991
|
+
/** Total number of records matching the query (across all pages) */
|
|
1992
|
+
total: number;
|
|
1993
|
+
/** Maximum number of records per page */
|
|
1994
|
+
limit: number;
|
|
1995
|
+
/** Number of records skipped (for pagination) */
|
|
1996
|
+
offset: number;
|
|
1997
|
+
/** Whether there are more records available after this page */
|
|
1998
|
+
hasMore: boolean;
|
|
1999
|
+
}
|
|
2000
|
+
`;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
1978
2003
|
// src/emit-routes-hono.ts
|
|
1979
2004
|
init_utils();
|
|
1980
2005
|
function emitHonoRoutes(table, _graph, opts) {
|
|
@@ -2243,7 +2268,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
2243
2268
|
* @returns The record with nested ${method.path.join(" and ")} if found, null otherwise
|
|
2244
2269
|
*/
|
|
2245
2270
|
async ${method.name}(pk: ${pkType}): Promise<${method.returnType}> {
|
|
2246
|
-
const results = await this.post<{
|
|
2271
|
+
const results = await this.post<PaginatedResponse<${baseReturnType}>>(\`\${this.resource}/list\`, {
|
|
2247
2272
|
where: ${pkWhere},
|
|
2248
2273
|
include: ${JSON.stringify(method.includeSpec)},
|
|
2249
2274
|
limit: 1
|
|
@@ -2274,6 +2299,7 @@ function emitClient(table, graph, opts, model) {
|
|
|
2274
2299
|
*/
|
|
2275
2300
|
import { BaseClient } from "./base-client${ext}";
|
|
2276
2301
|
import type { Where } from "./where-types${ext}";
|
|
2302
|
+
import type { PaginatedResponse } from "./types/shared${ext}";
|
|
2277
2303
|
${typeImports}
|
|
2278
2304
|
${otherTableImports.join(`
|
|
2279
2305
|
`)}
|
|
@@ -2321,20 +2347,8 @@ export class ${Type}Client extends BaseClient {
|
|
|
2321
2347
|
where?: Where<Select${Type}>;
|
|
2322
2348
|
orderBy?: string | string[];
|
|
2323
2349
|
order?: "asc" | "desc" | ("asc" | "desc")[];
|
|
2324
|
-
}): Promise<{
|
|
2325
|
-
|
|
2326
|
-
total: number;
|
|
2327
|
-
limit: number;
|
|
2328
|
-
offset: number;
|
|
2329
|
-
hasMore: boolean;
|
|
2330
|
-
}> {
|
|
2331
|
-
return this.post<{
|
|
2332
|
-
data: Select${Type}[];
|
|
2333
|
-
total: number;
|
|
2334
|
-
limit: number;
|
|
2335
|
-
offset: number;
|
|
2336
|
-
hasMore: boolean;
|
|
2337
|
-
}>(\`\${this.resource}/list\`, params ?? {});
|
|
2350
|
+
}): Promise<PaginatedResponse<Select${Type}>> {
|
|
2351
|
+
return this.post<PaginatedResponse<Select${Type}>>(\`\${this.resource}/list\`, params ?? {});
|
|
2338
2352
|
}
|
|
2339
2353
|
|
|
2340
2354
|
/**
|
|
@@ -2445,6 +2459,11 @@ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${
|
|
|
2445
2459
|
out += `export type { Insert${Type}, Update${Type}, Select${Type} } from "./types/${t.name}${ext}";
|
|
2446
2460
|
`;
|
|
2447
2461
|
}
|
|
2462
|
+
out += `
|
|
2463
|
+
// Shared types
|
|
2464
|
+
`;
|
|
2465
|
+
out += `export type { PaginatedResponse } from "./types/shared${ext}";
|
|
2466
|
+
`;
|
|
2448
2467
|
return out;
|
|
2449
2468
|
}
|
|
2450
2469
|
|
|
@@ -4679,6 +4698,7 @@ async function generate(configPath) {
|
|
|
4679
4698
|
files.push({ path: join(serverDir, "include-spec.ts"), content: includeSpec });
|
|
4680
4699
|
files.push({ path: join(clientDir, "include-spec.ts"), content: includeSpec });
|
|
4681
4700
|
files.push({ path: join(clientDir, "params", "shared.ts"), content: emitSharedParamsZod() });
|
|
4701
|
+
files.push({ path: join(clientDir, "types", "shared.ts"), content: emitSharedTypes() });
|
|
4682
4702
|
files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
|
|
4683
4703
|
files.push({ path: join(clientDir, "where-types.ts"), content: emitWhereTypes() });
|
|
4684
4704
|
files.push({
|