postgresdk 0.8.0 → 0.9.0
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 +14 -11
- package/dist/emit-client.d.ts +2 -2
- package/dist/emit-include-methods.d.ts +1 -1
- package/dist/index.js +14 -11
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1979,7 +1979,7 @@ function buildIncludeSpec(path) {
|
|
|
1979
1979
|
const rootKey = path[0];
|
|
1980
1980
|
return rootKey ? { [rootKey]: spec } : {};
|
|
1981
1981
|
}
|
|
1982
|
-
function generateIncludeMethods(table, graph, opts) {
|
|
1982
|
+
function generateIncludeMethods(table, graph, opts, allTables) {
|
|
1983
1983
|
const methods = [];
|
|
1984
1984
|
const baseTableName = table.name;
|
|
1985
1985
|
if (opts.skipJunctionTables && isJunctionTable(table)) {
|
|
@@ -1993,9 +1993,11 @@ function generateIncludeMethods(table, graph, opts) {
|
|
|
1993
1993
|
for (const [key, edge] of Object.entries(currentEdges)) {
|
|
1994
1994
|
if (visited.has(edge.target))
|
|
1995
1995
|
continue;
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1996
|
+
if (opts.skipJunctionTables && allTables) {
|
|
1997
|
+
const targetTable = allTables.find((t) => t.name === edge.target);
|
|
1998
|
+
if (targetTable && isJunctionTable(targetTable)) {
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
1999
2001
|
}
|
|
2000
2002
|
const newPath = [...path, key];
|
|
2001
2003
|
const newIsMany = [...isMany, edge.kind === "many"];
|
|
@@ -2063,7 +2065,7 @@ function generateIncludeMethods(table, graph, opts) {
|
|
|
2063
2065
|
}
|
|
2064
2066
|
|
|
2065
2067
|
// src/emit-client.ts
|
|
2066
|
-
function emitClient(table, graph, opts) {
|
|
2068
|
+
function emitClient(table, graph, opts, model) {
|
|
2067
2069
|
const Type = pascal(table.name);
|
|
2068
2070
|
const ext = opts.useJsExtensions ? ".js" : "";
|
|
2069
2071
|
const pkCols = Array.isArray(table.pk) ? table.pk : table.pk ? [table.pk] : [];
|
|
@@ -2071,10 +2073,11 @@ function emitClient(table, graph, opts) {
|
|
|
2071
2073
|
const hasCompositePk = safePk.length > 1;
|
|
2072
2074
|
const pkType = hasCompositePk ? `{ ${safePk.map((c) => `${c}: string`).join("; ")} }` : `string`;
|
|
2073
2075
|
const pkPathExpr = hasCompositePk ? safePk.map((c) => `pk.${c}`).join(` + "/" + `) : `pk`;
|
|
2076
|
+
const allTables = model ? Object.values(model.tables) : undefined;
|
|
2074
2077
|
const includeMethods = generateIncludeMethods(table, graph, {
|
|
2075
2078
|
maxDepth: opts.includeMethodsDepth ?? 2,
|
|
2076
2079
|
skipJunctionTables: opts.skipJunctionTables ?? true
|
|
2077
|
-
});
|
|
2080
|
+
}, allTables);
|
|
2078
2081
|
const importedTypes = new Set;
|
|
2079
2082
|
importedTypes.add(table.name);
|
|
2080
2083
|
for (const method of includeMethods) {
|
|
@@ -2084,7 +2087,7 @@ function emitClient(table, graph, opts) {
|
|
|
2084
2087
|
}
|
|
2085
2088
|
const typeImports = `import type { Insert${Type}, Update${Type}, Select${Type} } from "./types/${table.name}${ext}";`;
|
|
2086
2089
|
const otherTableImports = [];
|
|
2087
|
-
for (const target of importedTypes) {
|
|
2090
|
+
for (const target of Array.from(importedTypes)) {
|
|
2088
2091
|
if (target !== table.name) {
|
|
2089
2092
|
otherTableImports.push(`import type { Select${pascal(target)} } from "./types/${target}${ext}";`);
|
|
2090
2093
|
}
|
|
@@ -4083,11 +4086,11 @@ async function generate(configPath) {
|
|
|
4083
4086
|
files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
|
|
4084
4087
|
files.push({
|
|
4085
4088
|
path: join(serverDir, "include-builder.ts"),
|
|
4086
|
-
content: emitIncludeBuilder(graph, cfg.
|
|
4089
|
+
content: emitIncludeBuilder(graph, cfg.includeMethodsDepth || 2)
|
|
4087
4090
|
});
|
|
4088
4091
|
files.push({
|
|
4089
4092
|
path: join(serverDir, "include-loader.ts"),
|
|
4090
|
-
content: emitIncludeLoader(graph, model, cfg.
|
|
4093
|
+
content: emitIncludeLoader(graph, model, cfg.includeMethodsDepth || 2, cfg.useJsExtensions)
|
|
4091
4094
|
});
|
|
4092
4095
|
files.push({ path: join(serverDir, "logger.ts"), content: emitLogger() });
|
|
4093
4096
|
if (normalizedAuth?.strategy && normalizedAuth.strategy !== "none") {
|
|
@@ -4113,7 +4116,7 @@ async function generate(configPath) {
|
|
|
4113
4116
|
if (serverFramework === "hono") {
|
|
4114
4117
|
routeContent = emitHonoRoutes(table, graph, {
|
|
4115
4118
|
softDeleteColumn: cfg.softDeleteColumn || null,
|
|
4116
|
-
includeDepthLimit: cfg.
|
|
4119
|
+
includeDepthLimit: cfg.includeMethodsDepth || 2,
|
|
4117
4120
|
authStrategy: normalizedAuth?.strategy,
|
|
4118
4121
|
useJsExtensions: cfg.useJsExtensions
|
|
4119
4122
|
});
|
|
@@ -4130,7 +4133,7 @@ async function generate(configPath) {
|
|
|
4130
4133
|
useJsExtensions: cfg.useJsExtensionsClient,
|
|
4131
4134
|
includeMethodsDepth: cfg.includeMethodsDepth ?? 2,
|
|
4132
4135
|
skipJunctionTables: cfg.skipJunctionTables ?? true
|
|
4133
|
-
})
|
|
4136
|
+
}, model)
|
|
4134
4137
|
});
|
|
4135
4138
|
}
|
|
4136
4139
|
files.push({
|
package/dist/emit-client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Table } from "./introspect";
|
|
1
|
+
import type { Table, Model } from "./introspect";
|
|
2
2
|
import type { Graph } from "./rel-classify";
|
|
3
3
|
export declare function emitClient(table: Table, graph: Graph, opts: {
|
|
4
4
|
useJsExtensions?: boolean;
|
|
5
5
|
includeMethodsDepth?: number;
|
|
6
6
|
skipJunctionTables?: boolean;
|
|
7
|
-
}): string;
|
|
7
|
+
}, model?: Model): string;
|
|
8
8
|
export declare function emitClientIndex(tables: Table[], useJsExtensions?: boolean): string;
|
package/dist/index.js
CHANGED
|
@@ -1716,7 +1716,7 @@ function buildIncludeSpec(path) {
|
|
|
1716
1716
|
const rootKey = path[0];
|
|
1717
1717
|
return rootKey ? { [rootKey]: spec } : {};
|
|
1718
1718
|
}
|
|
1719
|
-
function generateIncludeMethods(table, graph, opts) {
|
|
1719
|
+
function generateIncludeMethods(table, graph, opts, allTables) {
|
|
1720
1720
|
const methods = [];
|
|
1721
1721
|
const baseTableName = table.name;
|
|
1722
1722
|
if (opts.skipJunctionTables && isJunctionTable(table)) {
|
|
@@ -1730,9 +1730,11 @@ function generateIncludeMethods(table, graph, opts) {
|
|
|
1730
1730
|
for (const [key, edge] of Object.entries(currentEdges)) {
|
|
1731
1731
|
if (visited.has(edge.target))
|
|
1732
1732
|
continue;
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1733
|
+
if (opts.skipJunctionTables && allTables) {
|
|
1734
|
+
const targetTable = allTables.find((t) => t.name === edge.target);
|
|
1735
|
+
if (targetTable && isJunctionTable(targetTable)) {
|
|
1736
|
+
continue;
|
|
1737
|
+
}
|
|
1736
1738
|
}
|
|
1737
1739
|
const newPath = [...path, key];
|
|
1738
1740
|
const newIsMany = [...isMany, edge.kind === "many"];
|
|
@@ -1800,7 +1802,7 @@ function generateIncludeMethods(table, graph, opts) {
|
|
|
1800
1802
|
}
|
|
1801
1803
|
|
|
1802
1804
|
// src/emit-client.ts
|
|
1803
|
-
function emitClient(table, graph, opts) {
|
|
1805
|
+
function emitClient(table, graph, opts, model) {
|
|
1804
1806
|
const Type = pascal(table.name);
|
|
1805
1807
|
const ext = opts.useJsExtensions ? ".js" : "";
|
|
1806
1808
|
const pkCols = Array.isArray(table.pk) ? table.pk : table.pk ? [table.pk] : [];
|
|
@@ -1808,10 +1810,11 @@ function emitClient(table, graph, opts) {
|
|
|
1808
1810
|
const hasCompositePk = safePk.length > 1;
|
|
1809
1811
|
const pkType = hasCompositePk ? `{ ${safePk.map((c) => `${c}: string`).join("; ")} }` : `string`;
|
|
1810
1812
|
const pkPathExpr = hasCompositePk ? safePk.map((c) => `pk.${c}`).join(` + "/" + `) : `pk`;
|
|
1813
|
+
const allTables = model ? Object.values(model.tables) : undefined;
|
|
1811
1814
|
const includeMethods = generateIncludeMethods(table, graph, {
|
|
1812
1815
|
maxDepth: opts.includeMethodsDepth ?? 2,
|
|
1813
1816
|
skipJunctionTables: opts.skipJunctionTables ?? true
|
|
1814
|
-
});
|
|
1817
|
+
}, allTables);
|
|
1815
1818
|
const importedTypes = new Set;
|
|
1816
1819
|
importedTypes.add(table.name);
|
|
1817
1820
|
for (const method of includeMethods) {
|
|
@@ -1821,7 +1824,7 @@ function emitClient(table, graph, opts) {
|
|
|
1821
1824
|
}
|
|
1822
1825
|
const typeImports = `import type { Insert${Type}, Update${Type}, Select${Type} } from "./types/${table.name}${ext}";`;
|
|
1823
1826
|
const otherTableImports = [];
|
|
1824
|
-
for (const target of importedTypes) {
|
|
1827
|
+
for (const target of Array.from(importedTypes)) {
|
|
1825
1828
|
if (target !== table.name) {
|
|
1826
1829
|
otherTableImports.push(`import type { Select${pascal(target)} } from "./types/${target}${ext}";`);
|
|
1827
1830
|
}
|
|
@@ -3820,11 +3823,11 @@ async function generate(configPath) {
|
|
|
3820
3823
|
files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
|
|
3821
3824
|
files.push({
|
|
3822
3825
|
path: join(serverDir, "include-builder.ts"),
|
|
3823
|
-
content: emitIncludeBuilder(graph, cfg.
|
|
3826
|
+
content: emitIncludeBuilder(graph, cfg.includeMethodsDepth || 2)
|
|
3824
3827
|
});
|
|
3825
3828
|
files.push({
|
|
3826
3829
|
path: join(serverDir, "include-loader.ts"),
|
|
3827
|
-
content: emitIncludeLoader(graph, model, cfg.
|
|
3830
|
+
content: emitIncludeLoader(graph, model, cfg.includeMethodsDepth || 2, cfg.useJsExtensions)
|
|
3828
3831
|
});
|
|
3829
3832
|
files.push({ path: join(serverDir, "logger.ts"), content: emitLogger() });
|
|
3830
3833
|
if (normalizedAuth?.strategy && normalizedAuth.strategy !== "none") {
|
|
@@ -3850,7 +3853,7 @@ async function generate(configPath) {
|
|
|
3850
3853
|
if (serverFramework === "hono") {
|
|
3851
3854
|
routeContent = emitHonoRoutes(table, graph, {
|
|
3852
3855
|
softDeleteColumn: cfg.softDeleteColumn || null,
|
|
3853
|
-
includeDepthLimit: cfg.
|
|
3856
|
+
includeDepthLimit: cfg.includeMethodsDepth || 2,
|
|
3854
3857
|
authStrategy: normalizedAuth?.strategy,
|
|
3855
3858
|
useJsExtensions: cfg.useJsExtensions
|
|
3856
3859
|
});
|
|
@@ -3867,7 +3870,7 @@ async function generate(configPath) {
|
|
|
3867
3870
|
useJsExtensions: cfg.useJsExtensionsClient,
|
|
3868
3871
|
includeMethodsDepth: cfg.includeMethodsDepth ?? 2,
|
|
3869
3872
|
skipJunctionTables: cfg.skipJunctionTables ?? true
|
|
3870
|
-
})
|
|
3873
|
+
}, model)
|
|
3871
3874
|
});
|
|
3872
3875
|
}
|
|
3873
3876
|
files.push({
|
package/dist/types.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface Config {
|
|
|
24
24
|
outServer?: string;
|
|
25
25
|
outClient?: string;
|
|
26
26
|
softDeleteColumn?: string | null;
|
|
27
|
-
|
|
27
|
+
dateType?: "date" | "string";
|
|
28
28
|
includeMethodsDepth?: number;
|
|
29
29
|
skipJunctionTables?: boolean;
|
|
30
30
|
serverFramework?: "hono" | "express" | "fastify";
|