prostgles-server 4.2.591 → 4.2.593

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.
Files changed (27) hide show
  1. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.d.ts +15 -0
  2. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.d.ts.map +1 -0
  3. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.js +17 -0
  4. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.js.map +1 -0
  5. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.d.ts +80 -0
  6. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.d.ts.map +1 -1
  7. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.js +31 -18
  8. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.js.map +1 -1
  9. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.spec.js +2 -0
  10. package/dist/DBSchemaBuilder/getServerFunctionReturnTypes.spec.js.map +1 -1
  11. package/dist/DBSchemaBuilder/resolveTypeToStructure.d.ts +1 -1
  12. package/dist/DBSchemaBuilder/resolveTypeToStructure.d.ts.map +1 -1
  13. package/dist/DBSchemaBuilder/resolveTypeToStructure.js +12 -11
  14. package/dist/DBSchemaBuilder/resolveTypeToStructure.js.map +1 -1
  15. package/dist/PublishParser/defineServerFunction.d.ts +16 -4
  16. package/dist/PublishParser/defineServerFunction.d.ts.map +1 -1
  17. package/dist/PublishParser/defineServerFunction.js +17 -0
  18. package/dist/PublishParser/defineServerFunction.js.map +1 -1
  19. package/dist/PublishParser/defineServerFunction.spec.js +19 -0
  20. package/dist/PublishParser/defineServerFunction.spec.js.map +1 -1
  21. package/lib/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.ts +16 -0
  22. package/lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts +52 -20
  23. package/lib/DBSchemaBuilder/getServerFunctionReturnTypes.spec.ts +5 -0
  24. package/lib/DBSchemaBuilder/resolveTypeToStructure.ts +21 -36
  25. package/lib/PublishParser/defineServerFunction.spec.ts +34 -1
  26. package/lib/PublishParser/defineServerFunction.ts +27 -10
  27. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ import type { FixtureSchema } from "./getServerFunctionReturnTypes.fixture";
2
+ export declare const externalFunctions: {
3
+ readonly externalScalar: {
4
+ input?: {
5
+ value: "string";
6
+ } | undefined;
7
+ description?: string;
8
+ run: (args: import("prostgles-types").JSONB.GetObjectType<{
9
+ value: "string";
10
+ }>, context: import("..").RestrictedFunctionContext<FixtureSchema, import("..").SessionUser>) => import("prostgles-types").MaybePromise<string>;
11
+ } & {
12
+ unrestrictedDbAccess?: undefined;
13
+ } & import("..").ServerFunctionContextMarker<FixtureSchema, import("..").SessionUser>;
14
+ };
15
+ //# sourceMappingURL=getServerFunctionReturnTypes.external.fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getServerFunctionReturnTypes.external.fixture.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAI5E,eAAO,MAAM,iBAAiB;;;;;;;;;;;;CAU5B,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.externalFunctions = void 0;
4
+ const __1 = require("..");
5
+ const defineFixtureFunctions = (0, __1.createFunctionsDefiner)();
6
+ exports.externalFunctions = defineFixtureFunctions({
7
+ externalScalar: (0, __1.defineFunction)({
8
+ input: { value: "string" },
9
+ run: ({ value }, { dbo }) => {
10
+ void dbo.orders.find();
11
+ // @ts-expect-error The schema must reach functions defined in another file.
12
+ void dbo.missingTable;
13
+ return value;
14
+ },
15
+ }),
16
+ });
17
+ //# sourceMappingURL=getServerFunctionReturnTypes.external.fixture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getServerFunctionReturnTypes.external.fixture.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.external.fixture.ts"],"names":[],"mappings":";;;AAAA,0BAA4D;AAG5D,MAAM,sBAAsB,GAAG,IAAA,0BAAsB,GAAiB,CAAC;AAE1D,QAAA,iBAAiB,GAAG,sBAAsB,CAAC;IACtD,cAAc,EAAE,IAAA,kBAAc,EAAC;QAC7B,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;QAC1B,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;YAC1B,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACvB,4EAA4E;YAC5E,KAAK,GAAG,CAAC,YAAY,CAAC;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;CACH,CAAC,CAAC"}
@@ -1,2 +1,82 @@
1
+ type RecursiveResult = {
2
+ value: string;
3
+ next?: RecursiveResult;
4
+ };
5
+ type SampleSchema = {
6
+ name: string;
7
+ path: string;
8
+ } & ({
9
+ type: "sql";
10
+ file: string;
11
+ } | {
12
+ type: "dir";
13
+ workspaceConfig?: {
14
+ workspaces: {
15
+ options?: {
16
+ hideCounts?: boolean;
17
+ tableListEndInfo?: "count" | "size" | "none";
18
+ };
19
+ }[];
20
+ };
21
+ });
22
+ export type FixtureSchema = {
23
+ orders: {
24
+ columns: {
25
+ id: string;
26
+ };
27
+ };
28
+ };
29
+ export declare const stateServerFunctions: {
30
+ public: {
31
+ readonly userFilter: {
32
+ readonly type: "public";
33
+ };
34
+ readonly functions: {
35
+ readonly recursiveResult: {
36
+ input?: Record<string, import("prostgles-types").JSONB.FieldType> | undefined;
37
+ description?: string;
38
+ run: (args: import("prostgles-types").JSONB.GetObjectType<Record<string, import("prostgles-types").JSONB.FieldType>>, context: import("..").RestrictedFunctionContext<FixtureSchema, import("..").SessionUser>) => import("prostgles-types").MaybePromise<RecursiveResult>;
39
+ } & {
40
+ unrestrictedDbAccess?: undefined;
41
+ } & import("..").ServerFunctionContextMarker<FixtureSchema, import("..").SessionUser>;
42
+ readonly sampleSchemas: {
43
+ input?: Record<string, import("prostgles-types").JSONB.FieldType> | undefined;
44
+ description?: string;
45
+ run: (args: import("prostgles-types").JSONB.GetObjectType<Record<string, import("prostgles-types").JSONB.FieldType>>, context: import("..").RestrictedFunctionContext<FixtureSchema, import("..").SessionUser>) => import("prostgles-types").MaybePromise<SampleSchema[]>;
46
+ } & {
47
+ unrestrictedDbAccess?: undefined;
48
+ } & import("..").ServerFunctionContextMarker<FixtureSchema, import("..").SessionUser>;
49
+ readonly scalarResult: {
50
+ input?: {
51
+ value: "number";
52
+ } | undefined;
53
+ description?: string;
54
+ run: (args: import("prostgles-types").JSONB.GetObjectType<{
55
+ value: "number";
56
+ }>, context: import("..").RestrictedFunctionContext<FixtureSchema, import("..").SessionUser>) => import("prostgles-types").MaybePromise<number>;
57
+ } & {
58
+ unrestrictedDbAccess?: undefined;
59
+ } & import("..").ServerFunctionContextMarker<FixtureSchema, import("..").SessionUser>;
60
+ };
61
+ };
62
+ external: {
63
+ readonly userFilter: {
64
+ readonly type: "public";
65
+ };
66
+ readonly functions: {
67
+ readonly externalScalar: {
68
+ input?: {
69
+ value: "string";
70
+ } | undefined;
71
+ description?: string;
72
+ run: (args: import("prostgles-types").JSONB.GetObjectType<{
73
+ value: "string";
74
+ }>, context: import("..").RestrictedFunctionContext<FixtureSchema, import("..").SessionUser>) => import("prostgles-types").MaybePromise<string>;
75
+ } & {
76
+ unrestrictedDbAccess?: undefined;
77
+ } & import("..").ServerFunctionContextMarker<FixtureSchema, import("..").SessionUser>;
78
+ };
79
+ };
80
+ };
1
81
  export {};
2
82
  //# sourceMappingURL=getServerFunctionReturnTypes.fixture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getServerFunctionReturnTypes.fixture.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"getServerFunctionReturnTypes.fixture.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts"],"names":[],"mappings":"AAGA,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,CACA;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,eAAe,CAAC,EAAE;QAChB,UAAU,EAAE;YACV,OAAO,CAAC,EAAE;gBACR,UAAU,CAAC,EAAE,OAAO,CAAC;gBACrB,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;aAC9C,CAAC;SACH,EAAE,CAAC;KACL,CAAC;CACH,CACJ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE;QACN,OAAO,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;KACzB,CAAC;CACH,CAAC;AAIF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhC,CAAC"}
@@ -33,27 +33,40 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.stateServerFunctions = void 0;
36
37
  const __1 = __importStar(require(".."));
38
+ const getServerFunctionReturnTypes_external_fixture_1 = require("./getServerFunctionReturnTypes.external.fixture");
39
+ const defineFixtureFunctionGroup = (0, __1.createFunctionGroupDefiner)();
40
+ exports.stateServerFunctions = {
41
+ public: defineFixtureFunctionGroup({
42
+ userFilter: { type: "public" },
43
+ functions: {
44
+ recursiveResult: (0, __1.defineFunction)({
45
+ run: () => ({ value: "ok" }),
46
+ }),
47
+ sampleSchemas: (0, __1.defineFunction)({
48
+ run: () => [],
49
+ }),
50
+ scalarResult: (0, __1.defineFunction)({
51
+ input: { value: "number" },
52
+ run: ({ value }, { dbo }) => {
53
+ value;
54
+ void dbo.orders.find();
55
+ // @ts-expect-error The schema must reach a function defined in another object.
56
+ void dbo.missingTable;
57
+ return value;
58
+ },
59
+ }),
60
+ },
61
+ }),
62
+ external: defineFixtureFunctionGroup({
63
+ userFilter: { type: "public" },
64
+ functions: getServerFunctionReturnTypes_external_fixture_1.externalFunctions,
65
+ }),
66
+ };
37
67
  void (0, __1.default)({
38
68
  dbConnection: "",
39
69
  onReady: () => { },
40
- functions: {
41
- public: {
42
- userFilter: { type: "public" },
43
- functions: {
44
- recursiveResult: (0, __1.defineFunction)({
45
- run: () => ({ value: "ok" }),
46
- }),
47
- scalarResult: (0, __1.defineFunction)({
48
- run: (_args, { dbo }) => {
49
- void dbo.orders.find();
50
- // @ts-expect-error The surrounding prostgles schema must reach defineFunction.
51
- void dbo.missingTable;
52
- return 42;
53
- },
54
- }),
55
- },
56
- },
57
- },
70
+ functions: exports.stateServerFunctions,
58
71
  });
59
72
  //# sourceMappingURL=getServerFunctionReturnTypes.fixture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getServerFunctionReturnTypes.fixture.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAA+C;AAa/C,KAAK,IAAA,WAAS,EAAgB;IAC5B,YAAY,EAAE,EAAE;IAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,SAAS,EAAE;QACT,MAAM,EAAE;YACN,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,SAAS,EAAE;gBACT,eAAe,EAAE,IAAA,kBAAc,EAAC;oBAC9B,GAAG,EAAE,GAAoB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;iBAC9C,CAAC;gBACF,YAAY,EAAE,IAAA,kBAAc,EAAC;oBAC3B,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;wBACtB,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;wBACvB,+EAA+E;wBAC/E,KAAK,GAAG,CAAC,YAAY,CAAC;wBACtB,OAAO,EAAE,CAAC;oBACZ,CAAC;iBACF,CAAC;aACH;SACF;KACF;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"getServerFunctionReturnTypes.fixture.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAA2E;AAC3E,mHAAoF;AA+BpF,MAAM,0BAA0B,GAAG,IAAA,8BAA0B,GAAiB,CAAC;AAElE,QAAA,oBAAoB,GAAG;IAClC,MAAM,EAAE,0BAA0B,CAAC;QACjC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,SAAS,EAAE;YACT,eAAe,EAAE,IAAA,kBAAc,EAAC;gBAC9B,GAAG,EAAE,GAAoB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aAC9C,CAAC;YACF,aAAa,EAAE,IAAA,kBAAc,EAAC;gBAC5B,GAAG,EAAE,GAAmB,EAAE,CAAC,EAAE;aAC9B,CAAC;YACF,YAAY,EAAE,IAAA,kBAAc,EAAC;gBAC3B,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;gBAC1B,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;oBAC1B,KAAsB,CAAC;oBACvB,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;oBACvB,+EAA+E;oBAC/E,KAAK,GAAG,CAAC,YAAY,CAAC;oBACtB,OAAO,KAAK,CAAC;gBACf,CAAC;aACF,CAAC;SACH;KACF,CAAC;IACF,QAAQ,EAAE,0BAA0B,CAAC;QACnC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,SAAS,EAAE,iEAAiB;KAC7B,CAAC;CACH,CAAC;AAEF,KAAK,IAAA,WAAS,EAAgB;IAC5B,YAAY,EAAE,EAAE;IAChB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,SAAS,EAAE,4BAAoB;CAChC,CAAC,CAAC"}
@@ -12,7 +12,9 @@ void (0, node_test_1.describe)("getServerFunctionReturnTypes", async () => {
12
12
  const fixturePath = (0, node_path_1.resolve)(__dirname, "../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.fixture.ts");
13
13
  const result = (0, getServerFunctionReturnTypes_1.getServerFunctionReturnTypes)(fixturePath);
14
14
  node_assert_1.default.equal(result.get("scalarResult"), "number");
15
+ node_assert_1.default.equal(result.get("externalScalar"), "string");
15
16
  node_assert_1.default.equal(result.get("recursiveResult"), "{ value: string; next?: unknown }");
17
+ node_assert_1.default.equal(result.get("sampleSchemas"), 'Array<(({ name: string; path: string } & { type: "sql"; file: string }) | ({ name: string; path: string } & { type: "dir"; workspaceConfig?: (undefined | { workspaces: Array<{ options?: (undefined | { hideCounts?: (undefined | false | true); tableListEndInfo?: (undefined | "count" | "size" | "none") }) }> }) }))>');
16
18
  });
17
19
  });
18
20
  //# sourceMappingURL=getServerFunctionReturnTypes.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getServerFunctionReturnTypes.spec.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getServerFunctionReturnTypes.spec.ts"],"names":[],"mappings":";;;;;AAAA,8DAAiC;AACjC,yCAAoC;AACpC,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,CAAC,CAAC;QACjF,qBAAM,CAAC,KAAK,CACV,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,EAC3B,4TAA4T,CAC7T,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -3,5 +3,5 @@ import * as ts from "typescript";
3
3
  * Recursively resolve a type to its structural representation
4
4
  * using only built-in/primitive types
5
5
  */
6
- export declare const resolveTypeToStructure: (globalBuiltIns: Set<string>, functionName: string, checker: ts.TypeChecker, type: ts.Type, parentTypes?: ts.Type[], maxDepth?: number) => string;
6
+ export declare const resolveTypeToStructure: (globalBuiltIns: Set<string>, functionName: string, checker: ts.TypeChecker, type: ts.Type, parentTypes?: ts.Type[], maxDepth?: number, depth?: number) => string;
7
7
  //# sourceMappingURL=resolveTypeToStructure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTypeToStructure.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/resolveTypeToStructure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAC3B,cAAc,MAAM,EACpB,SAAS,EAAE,CAAC,WAAW,EACvB,MAAM,EAAE,CAAC,IAAI,EACb,cAAa,EAAE,CAAC,IAAI,EAAO,EAC3B,iBAAa,KACZ,MA6LF,CAAC"}
1
+ {"version":3,"file":"resolveTypeToStructure.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/resolveTypeToStructure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GACjC,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAC3B,cAAc,MAAM,EACpB,SAAS,EAAE,CAAC,WAAW,EACvB,MAAM,EAAE,CAAC,IAAI,EACb,cAAa,EAAE,CAAC,IAAI,EAAO,EAC3B,iBAAa,EACb,cAAS,KACR,MA6KF,CAAC"}
@@ -39,14 +39,15 @@ const ts = __importStar(require("typescript"));
39
39
  * Recursively resolve a type to its structural representation
40
40
  * using only built-in/primitive types
41
41
  */
42
- const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, parentTypes = [], maxDepth = 10) => {
43
- const depth = parentTypes.length;
42
+ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, parentTypes = [], maxDepth = 10, depth = 0) => {
44
43
  const getParentNames = () => parentTypes.map((t) => checker.typeToString(t));
45
44
  if (depth > maxDepth) {
46
45
  console.warn(`Max type resolution depth (${maxDepth}) reached for function ${JSON.stringify(functionName)} ReturnType`, getParentNames().join(" -> "));
47
46
  return "unknown";
48
47
  }
49
48
  const nextParentTypes = [...parentTypes, type];
49
+ /** Unions, intersections, and containers track cycles without consuming structural depth. */
50
+ const resolveChild = (childType, isNestedStructure = false) => (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, childType, nextParentTypes, maxDepth, depth + (isNestedStructure ? 1 : 0));
50
51
  if (type.flags & ts.TypeFlags.String)
51
52
  return "string";
52
53
  if (type.flags & ts.TypeFlags.Number)
@@ -81,7 +82,7 @@ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, par
81
82
  return "unknown";
82
83
  // Handle union types
83
84
  if (type.isUnion()) {
84
- const parts = type.types.map((t) => (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, t, nextParentTypes));
85
+ const parts = type.types.map((t) => resolveChild(t));
85
86
  // Deduplicate
86
87
  const unique = [...new Set(parts)];
87
88
  if (unique.includes("unknown"))
@@ -92,7 +93,7 @@ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, par
92
93
  }
93
94
  // Handle intersection types
94
95
  if (type.isIntersection()) {
95
- const parts = type.types.map((t) => (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, t, nextParentTypes));
96
+ const parts = type.types.map((t) => resolveChild(t));
96
97
  return `(${parts.join(" & ")})`;
97
98
  }
98
99
  // Handle Promise<T> - unwrap to Promise<ResolvedT>
@@ -113,14 +114,14 @@ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, par
113
114
  // Handle tuple types
114
115
  if (checker.isTupleType(type)) {
115
116
  const typeArgs = checker.getTypeArguments(type);
116
- const elements = typeArgs.map((t) => (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, t, nextParentTypes));
117
+ const elements = typeArgs.map((t) => resolveChild(t));
117
118
  return `[${elements.join(", ")}]`;
118
119
  }
119
120
  if (typeName && globalBuiltIns.has(typeName)) {
120
121
  // Check for type arguments (e.g., ReadableStream<Uint8Array>)
121
122
  const typeArgs = checker.getTypeArguments(type);
122
123
  if (typeArgs.length > 0) {
123
- const resolvedArgs = typeArgs.map((t) => (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, t, nextParentTypes));
124
+ const resolvedArgs = typeArgs.map((t) => resolveChild(t));
124
125
  return `${typeName}<${resolvedArgs.join(", ")}>`;
125
126
  }
126
127
  return typeName;
@@ -132,11 +133,11 @@ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, par
132
133
  const sig = callSignatures[0];
133
134
  const params = sig.getParameters().map((param) => {
134
135
  const paramType = checker.getTypeOfSymbolAtLocation(param, param.valueDeclaration);
135
- const paramTypeStr = (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, paramType, nextParentTypes);
136
+ const paramTypeStr = resolveChild(paramType, true);
136
137
  const isOptional = param.flags & ts.SymbolFlags.Optional;
137
138
  return `${param.getName()}${isOptional ? "?" : ""}: ${paramTypeStr}`;
138
139
  });
139
- const returnType = (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, checker.getReturnTypeOfSignature(sig), nextParentTypes);
140
+ const returnType = resolveChild(checker.getReturnTypeOfSignature(sig), true);
140
141
  return `((${params.join(", ")}) => ${returnType})`;
141
142
  }
142
143
  // Handle object types - expand to structural form
@@ -157,7 +158,7 @@ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, par
157
158
  // get the type directly from the symbol
158
159
  propType = checker.getTypeOfSymbol(prop);
159
160
  }
160
- const propTypeStr = (0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, propType, nextParentTypes);
161
+ const propTypeStr = resolveChild(propType, true);
161
162
  const isOptional = prop.flags & ts.SymbolFlags.Optional;
162
163
  const propName = prop.getName();
163
164
  // Handle property names that need quoting
@@ -169,10 +170,10 @@ const resolveTypeToStructure = (globalBuiltIns, functionName, checker, type, par
169
170
  const stringIndexType = type.getStringIndexType();
170
171
  const numberIndexType = type.getNumberIndexType();
171
172
  if (stringIndexType) {
172
- members.push(`[key: string]: ${(0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, stringIndexType, nextParentTypes)}`);
173
+ members.push(`[key: string]: ${resolveChild(stringIndexType, true)}`);
173
174
  }
174
175
  if (numberIndexType) {
175
- members.push(`[key: number]: ${(0, exports.resolveTypeToStructure)(globalBuiltIns, functionName, checker, numberIndexType, nextParentTypes)}`);
176
+ members.push(`[key: number]: ${resolveChild(numberIndexType, true)}`);
176
177
  }
177
178
  if (members.length === 0) {
178
179
  // Empty object or object with no enumerable properties
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTypeToStructure.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/resolveTypeToStructure.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,cAA2B,EAC3B,YAAoB,EACpB,OAAuB,EACvB,IAAa,EACb,cAAyB,EAAE,EAC3B,QAAQ,GAAG,EAAE,EACL,EAAE;IACV,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC;IACjC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,C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OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,uDAAuD;YACvD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACrC,CAAC;IAED,qDAAqD;IACrD,OAAO,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC;AArLW,QAAA,sBAAsB,0BAqLjC"}
@@ -21,7 +21,7 @@ export type ServerFunctionDefinition = {
21
21
  run: (...args: any[]) => MaybePromise<unknown>;
22
22
  };
23
23
  declare const serverFunctionContext: unique symbol;
24
- type ServerFunctionContextMarker<S, SUser extends SessionUser> = {
24
+ export type ServerFunctionContextMarker<S, SUser extends SessionUser> = {
25
25
  [serverFunctionContext]?: [S, SUser];
26
26
  };
27
27
  type DefineFunctionArgs<TInput extends Record<string, JSONB.FieldType> | undefined, Context, Return> = {
@@ -41,9 +41,21 @@ type UsersTableRow<S> = S extends DBSchema ? S extends {
41
41
  };
42
42
  } ? UserRow : AnyObject : AnyObject;
43
43
  type ValidDbSchema<S> = S extends DBSchema ? S : void;
44
- export type ServerFunctionDefinitions<S = void, SUser extends SessionUser = SessionUser> = Record<string, {
44
+ export type ServerFunctionGroupFunctions<S = void, SUser extends SessionUser = SessionUser> = Record<string, ServerFunctionDefinition & ServerFunctionContextMarker<S, SUser>>;
45
+ export type ServerFunctionGroup<S = void, SUser extends SessionUser = SessionUser> = {
45
46
  userFilter: FullFilter<UsersTableRow<S>, ValidDbSchema<S>>;
46
- functions: Record<string, ServerFunctionDefinition & ServerFunctionContextMarker<S, SUser>>;
47
- }>;
47
+ functions: ServerFunctionGroupFunctions<S, SUser>;
48
+ };
49
+ export type ServerFunctionDefinitions<S = void, SUser extends SessionUser = SessionUser> = Record<string, ServerFunctionGroup<S, SUser>>;
50
+ /**
51
+ * Creates a schema-aware identity helper for defining a server function group
52
+ * while preserving its inferred function names and return types.
53
+ */
54
+ export declare const createFunctionGroupDefiner: <S = void, SUser extends SessionUser = SessionUser>() => <const T extends ServerFunctionGroup<S, SUser>>(group: T) => T;
55
+ /**
56
+ * Creates a schema-aware identity helper for function maps that are composed
57
+ * into a server function group elsewhere.
58
+ */
59
+ export declare const createFunctionsDefiner: <S = void, SUser extends SessionUser = SessionUser>() => <const T extends ServerFunctionGroupFunctions<S, SUser>>(functions: T) => T;
48
60
  export {};
49
61
  //# sourceMappingURL=defineServerFunction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineServerFunction.d.ts","sourceRoot":"","sources":["../../lib/PublishParser/defineServerFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,KAAK,EACL,wBAAwB,EACxB,YAAY,EACZ,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,KAAK,mBAAmB,CAAC,CAAC,EAAE,KAAK,SAAS,WAAW,IAAI,IAAI,CAC3D,aAAa,CAAC,CAAC,EAAE,KAAK,CAAC,EACvB,QAAQ,GAAG,WAAW,GAAG,YAAY,CACtC,GAAG;IACF,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,EAAE,CAAC,SAAS,QAAQ,GACtB,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,SAAS,SAAS,GACrC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,GAC/B,KAAK,CAAC,MAAM,CAAC,GACf,KAAK,CAAC,MAAM,CAAC,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,CACnC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AS,WAAW,GAAG,WAAW,IACrC,MAAM,CACR,MAAM,EACN;IACE,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,SAAS,EAAE,MAAM,CACf,MAAM,EACN,wBAAwB,GAAG,2BAA2B,CAAC,CAAC,EAAE,KAAK,CAAC,CACjE,CAAC;CACH,CACF,CAAC"}
1
+ {"version":3,"file":"defineServerFunction.d.ts","sourceRoot":"","sources":["../../lib/PublishParser/defineServerFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,UAAU,EACV,KAAK,EACL,wBAAwB,EACxB,YAAY,EACZ,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,KAAK,mBAAmB,CAAC,CAAC,EAAE,KAAK,SAAS,WAAW,IAAI,IAAI,CAC3D,aAAa,CAAC,CAAC,EAAE,KAAK,CAAC,EACvB,QAAQ,GAAG,WAAW,GAAG,YAAY,CACtC,GAAG;IACF,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,EAAE,CAAC,SAAS,QAAQ,GACtB,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,SAAS,SAAS,GACrC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,GAC/B,KAAK,CAAC,MAAM,CAAC,GACf,KAAK,CAAC,MAAM,CAAC,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,yBAAyB,CACnC,CAAC,GAAG,IAAI,EACR,KAAK,SAAS,WA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CAAC,MAAM,EAAE,wBAAwB,GAAG,2BAA2B,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAErF,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,IAAI;IACnF,UAAU,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,SAAS,EAAE,4BAA4B,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,IAAI,MAAM,CAC/F,MAAM,EACN,mBAAmB,CAAC,CAAC,EAAE,KAAK,CAAC,CAC9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,QAClF,KAAK,CAAC,CAAC,SAAS,mBAAmB,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,KAAG,CACnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,GAAG,IAAI,EAAE,KAAK,SAAS,WAAW,GAAG,WAAW,QAC9E,KAAK,CAAC,CAAC,SAAS,4BAA4B,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,KAAG,CAChF,CAAC"}
@@ -1,7 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFunctionsDefiner = exports.createFunctionGroupDefiner = void 0;
3
4
  exports.defineFunction = defineFunction;
4
5
  function defineFunction(args) {
5
6
  return args;
6
7
  }
8
+ /**
9
+ * Creates a schema-aware identity helper for defining a server function group
10
+ * while preserving its inferred function names and return types.
11
+ */
12
+ const createFunctionGroupDefiner = () => {
13
+ return (group) => group;
14
+ };
15
+ exports.createFunctionGroupDefiner = createFunctionGroupDefiner;
16
+ /**
17
+ * Creates a schema-aware identity helper for function maps that are composed
18
+ * into a server function group elsewhere.
19
+ */
20
+ const createFunctionsDefiner = () => {
21
+ return (functions) => functions;
22
+ };
23
+ exports.createFunctionsDefiner = createFunctionsDefiner;
7
24
  //# sourceMappingURL=defineServerFunction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineServerFunction.js","sourceRoot":"","sources":["../../lib/PublishParser/defineServerFunction.ts"],"names":[],"mappings":";;AAqFA,wCAEC;AAFD,SAAgB,cAAc,CAAC,IAAa;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"defineServerFunction.js","sourceRoot":"","sources":["../../lib/PublishParser/defineServerFunction.ts"],"names":[],"mappings":";;;AAqFA,wCAEC;AAFD,SAAgB,cAAc,CAAC,IAAa;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AA0BD;;;GAGG;AACI,MAAM,0BAA0B,GAAG,GAAsD,EAAE;IAChG,OAAO,CAAgD,KAAQ,EAAK,EAAE,CAAC,KAAK,CAAC;AAC/E,CAAC,CAAC;AAFW,QAAA,0BAA0B,8BAErC;AAEF;;;GAGG;AACI,MAAM,sBAAsB,GAAG,GAAsD,EAAE;IAC5F,OAAO,CAAyD,SAAY,EAAK,EAAE,CAAC,SAAS,CAAC;AAChG,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC"}
@@ -22,6 +22,25 @@ void (0, node_test_1.describe)("defineFunction type test", async () => {
22
22
  });
23
23
  //@ts-expect-error run is required
24
24
  (0, defineServerFunction_1.defineFunction)({ description: "invalid" });
25
+ const defineTestFunctions = (0, defineServerFunction_1.createFunctionsDefiner)();
26
+ const functions = defineTestFunctions({
27
+ getItem: (0, defineServerFunction_1.defineFunction)({
28
+ run: (_args, { dbo }) => {
29
+ void dbo.items.find();
30
+ // @ts-expect-error The schema is retained without a satisfies assertion.
31
+ void dbo.missingTable;
32
+ return { id: 1 };
33
+ },
34
+ }),
35
+ });
36
+ const defineTestFunctionGroup = (0, defineServerFunction_1.createFunctionGroupDefiner)();
37
+ const group = defineTestFunctionGroup({
38
+ userFilter: { type: "public" },
39
+ functions,
40
+ });
41
+ group.functions.getItem;
42
+ // @ts-expect-error A group must have a user filter.
43
+ defineTestFunctionGroup({ functions });
25
44
  });
26
45
  });
27
46
  //# sourceMappingURL=defineServerFunction.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineServerFunction.spec.js","sourceRoot":"","sources":["../../lib/PublishParser/defineServerFunction.spec.ts"],"names":[],"mappings":";;AAAA,yCAA2C;AAC3C,iEAAwD;AAExD,KAAK,IAAA,oBAAQ,EAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;IACnD,MAAM,IAAA,gBAAI,EAAC,WAAW,EAAE,GAAG,EAAE;QAC3B,IAAA,qCAAc,EAAC;YACb,KAAK,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE;YACnC,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;gBACrB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBAEhB,2DAA2D;gBAC3D,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAE3B,kBAAkB;gBAClB,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBACd,CAAC;YACH,CAAC;SACF,CAAC,CAAC;QAEH,IAAA,qCAAc,EAAC;YACb,oBAAoB,EAAE,IAAI;YAC1B,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC;SACpD,CAAC,CAAC;QAEH,kCAAkC;QAClC,IAAA,qCAAc,EAAC,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,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YAAY,CAAC;oBACtB,OAAO,EAAE,EAAE,EAAE,CAAU,EAAE,CAAC;gBAC5B,CAAC;aACF,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,uBAAuB,GAAG,IAAA,iDAA0B,GAAc,CAAC;QACzE,MAAM,KAAK,GAAG,uBAAuB,CAAC;YACpC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,SAAS;SACV,CAAC,CAAC;QAEH,KAAK,CAAC,SAAS,CAAC,OAA+C,CAAC;QAEhE,oDAAoD;QACpD,uBAAuB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { defineFunction, createFunctionsDefiner } from "..";
2
+ import type { FixtureSchema } from "./getServerFunctionReturnTypes.fixture";
3
+
4
+ const defineFixtureFunctions = createFunctionsDefiner<FixtureSchema>();
5
+
6
+ export const externalFunctions = defineFixtureFunctions({
7
+ externalScalar: defineFunction({
8
+ input: { value: "string" },
9
+ run: ({ value }, { dbo }) => {
10
+ void dbo.orders.find();
11
+ // @ts-expect-error The schema must reach functions defined in another file.
12
+ void dbo.missingTable;
13
+ return value;
14
+ },
15
+ }),
16
+ });
@@ -1,35 +1,67 @@
1
- import prostgles, { defineFunction } from "..";
1
+ import prostgles, { defineFunction, createFunctionGroupDefiner } from "..";
2
+ import { externalFunctions } from "./getServerFunctionReturnTypes.external.fixture";
2
3
 
3
4
  type RecursiveResult = {
4
5
  value: string;
5
6
  next?: RecursiveResult;
6
7
  };
7
8
 
8
- type FixtureSchema = {
9
+ type SampleSchema = {
10
+ name: string;
11
+ path: string;
12
+ } & (
13
+ | { type: "sql"; file: string }
14
+ | {
15
+ type: "dir";
16
+ workspaceConfig?: {
17
+ workspaces: {
18
+ options?: {
19
+ hideCounts?: boolean;
20
+ tableListEndInfo?: "count" | "size" | "none";
21
+ };
22
+ }[];
23
+ };
24
+ }
25
+ );
26
+
27
+ export type FixtureSchema = {
9
28
  orders: {
10
29
  columns: { id: string };
11
30
  };
12
31
  };
13
32
 
33
+ const defineFixtureFunctionGroup = createFunctionGroupDefiner<FixtureSchema>();
34
+
35
+ export const stateServerFunctions = {
36
+ public: defineFixtureFunctionGroup({
37
+ userFilter: { type: "public" },
38
+ functions: {
39
+ recursiveResult: defineFunction({
40
+ run: (): RecursiveResult => ({ value: "ok" }),
41
+ }),
42
+ sampleSchemas: defineFunction({
43
+ run: (): SampleSchema[] => [],
44
+ }),
45
+ scalarResult: defineFunction({
46
+ input: { value: "number" },
47
+ run: ({ value }, { dbo }) => {
48
+ value satisfies number;
49
+ void dbo.orders.find();
50
+ // @ts-expect-error The schema must reach a function defined in another object.
51
+ void dbo.missingTable;
52
+ return value;
53
+ },
54
+ }),
55
+ },
56
+ }),
57
+ external: defineFixtureFunctionGroup({
58
+ userFilter: { type: "public" },
59
+ functions: externalFunctions,
60
+ }),
61
+ };
62
+
14
63
  void prostgles<FixtureSchema>({
15
64
  dbConnection: "",
16
65
  onReady: () => {},
17
- functions: {
18
- public: {
19
- userFilter: { type: "public" },
20
- functions: {
21
- recursiveResult: defineFunction({
22
- run: (): RecursiveResult => ({ value: "ok" }),
23
- }),
24
- scalarResult: defineFunction({
25
- run: (_args, { dbo }) => {
26
- void dbo.orders.find();
27
- // @ts-expect-error The surrounding prostgles schema must reach defineFunction.
28
- void dbo.missingTable;
29
- return 42;
30
- },
31
- }),
32
- },
33
- },
34
- },
66
+ functions: stateServerFunctions,
35
67
  });
@@ -13,6 +13,11 @@ void describe("getServerFunctionReturnTypes", async () => {
13
13
  const result = getServerFunctionReturnTypes(fixturePath);
14
14
 
15
15
  assert.equal(result.get("scalarResult"), "number");
16
+ assert.equal(result.get("externalScalar"), "string");
16
17
  assert.equal(result.get("recursiveResult"), "{ value: string; next?: unknown }");
18
+ assert.equal(
19
+ result.get("sampleSchemas"),
20
+ 'Array<(({ name: string; path: string } & { type: "sql"; file: string }) | ({ name: string; path: string } & { type: "dir"; workspaceConfig?: (undefined | { workspaces: Array<{ options?: (undefined | { hideCounts?: (undefined | false | true); tableListEndInfo?: (undefined | "count" | "size" | "none") }) }> }) }))>',
21
+ );
17
22
  });
18
23
  });
@@ -11,8 +11,8 @@ export const resolveTypeToStructure = (
11
11
  type: ts.Type,
12
12
  parentTypes: ts.Type[] = [],
13
13
  maxDepth = 10,
14
+ depth = 0,
14
15
  ): string => {
15
- const depth = parentTypes.length;
16
16
  const getParentNames = () => parentTypes.map((t) => checker.typeToString(t));
17
17
  if (depth > maxDepth) {
18
18
  console.warn(
@@ -23,6 +23,17 @@ export const resolveTypeToStructure = (
23
23
  }
24
24
 
25
25
  const nextParentTypes = [...parentTypes, type];
26
+ /** Unions, intersections, and containers track cycles without consuming structural depth. */
27
+ const resolveChild = (childType: ts.Type, isNestedStructure = false) =>
28
+ resolveTypeToStructure(
29
+ globalBuiltIns,
30
+ functionName,
31
+ checker,
32
+ childType,
33
+ nextParentTypes,
34
+ maxDepth,
35
+ depth + (isNestedStructure ? 1 : 0),
36
+ );
26
37
 
27
38
  if (type.flags & ts.TypeFlags.String) return "string";
28
39
  if (type.flags & ts.TypeFlags.Number) return "number";
@@ -48,9 +59,7 @@ export const resolveTypeToStructure = (
48
59
 
49
60
  // Handle union types
50
61
  if (type.isUnion()) {
51
- const parts = type.types.map((t) =>
52
- resolveTypeToStructure(globalBuiltIns, functionName, checker, t, nextParentTypes),
53
- );
62
+ const parts = type.types.map((t) => resolveChild(t));
54
63
  // Deduplicate
55
64
  const unique = [...new Set(parts)];
56
65
  if (unique.includes("unknown")) return "unknown";
@@ -60,9 +69,7 @@ export const resolveTypeToStructure = (
60
69
 
61
70
  // Handle intersection types
62
71
  if (type.isIntersection()) {
63
- const parts = type.types.map((t) =>
64
- resolveTypeToStructure(globalBuiltIns, functionName, checker, t, nextParentTypes),
65
- );
72
+ const parts = type.types.map((t) => resolveChild(t));
66
73
  return `(${parts.join(" & ")})`;
67
74
  }
68
75
 
@@ -91,9 +98,7 @@ export const resolveTypeToStructure = (
91
98
  // Handle tuple types
92
99
  if (checker.isTupleType(type)) {
93
100
  const typeArgs = checker.getTypeArguments(type as ts.TypeReference);
94
- const elements = typeArgs.map((t) =>
95
- resolveTypeToStructure(globalBuiltIns, functionName, checker, t, nextParentTypes),
96
- );
101
+ const elements = typeArgs.map((t) => resolveChild(t));
97
102
  return `[${elements.join(", ")}]`;
98
103
  }
99
104
 
@@ -101,9 +106,7 @@ export const resolveTypeToStructure = (
101
106
  // Check for type arguments (e.g., ReadableStream<Uint8Array>)
102
107
  const typeArgs = checker.getTypeArguments(type as ts.TypeReference);
103
108
  if (typeArgs.length > 0) {
104
- const resolvedArgs = typeArgs.map((t) =>
105
- resolveTypeToStructure(globalBuiltIns, functionName, checker, t, nextParentTypes),
106
- );
109
+ const resolvedArgs = typeArgs.map((t) => resolveChild(t));
107
110
  return `${typeName}<${resolvedArgs.join(", ")}>`;
108
111
  }
109
112
  return typeName;
@@ -119,23 +122,11 @@ export const resolveTypeToStructure = (
119
122
  const sig = callSignatures[0]!;
120
123
  const params = sig.getParameters().map((param) => {
121
124
  const paramType = checker.getTypeOfSymbolAtLocation(param, param.valueDeclaration!);
122
- const paramTypeStr = resolveTypeToStructure(
123
- globalBuiltIns,
124
- functionName,
125
- checker,
126
- paramType,
127
- nextParentTypes,
128
- );
125
+ const paramTypeStr = resolveChild(paramType, true);
129
126
  const isOptional = param.flags & ts.SymbolFlags.Optional;
130
127
  return `${param.getName()}${isOptional ? "?" : ""}: ${paramTypeStr}`;
131
128
  });
132
- const returnType = resolveTypeToStructure(
133
- globalBuiltIns,
134
- functionName,
135
- checker,
136
- checker.getReturnTypeOfSignature(sig),
137
- nextParentTypes,
138
- );
129
+ const returnType = resolveChild(checker.getReturnTypeOfSignature(sig), true);
139
130
  return `((${params.join(", ")}) => ${returnType})`;
140
131
  }
141
132
 
@@ -158,13 +149,7 @@ export const resolveTypeToStructure = (
158
149
  propType = checker.getTypeOfSymbol(prop);
159
150
  }
160
151
 
161
- const propTypeStr = resolveTypeToStructure(
162
- globalBuiltIns,
163
- functionName,
164
- checker,
165
- propType,
166
- nextParentTypes,
167
- );
152
+ const propTypeStr = resolveChild(propType, true);
168
153
  const isOptional = prop.flags & ts.SymbolFlags.Optional;
169
154
  const propName = prop.getName();
170
155
 
@@ -181,12 +166,12 @@ export const resolveTypeToStructure = (
181
166
 
182
167
  if (stringIndexType) {
183
168
  members.push(
184
- `[key: string]: ${resolveTypeToStructure(globalBuiltIns, functionName, checker, stringIndexType, nextParentTypes)}`,
169
+ `[key: string]: ${resolveChild(stringIndexType, true)}`,
185
170
  );
186
171
  }
187
172
  if (numberIndexType) {
188
173
  members.push(
189
- `[key: number]: ${resolveTypeToStructure(globalBuiltIns, functionName, checker, numberIndexType, nextParentTypes)}`,
174
+ `[key: number]: ${resolveChild(numberIndexType, true)}`,
190
175
  );
191
176
  }
192
177
 
@@ -1,5 +1,15 @@
1
1
  import { describe, test } from "node:test";
2
- import { defineFunction } from "./defineServerFunction";
2
+ import {
3
+ defineFunction,
4
+ createFunctionGroupDefiner,
5
+ createFunctionsDefiner,
6
+ } from "./defineServerFunction";
7
+
8
+ type TestSchema = {
9
+ items: {
10
+ columns: { id: number };
11
+ };
12
+ };
3
13
 
4
14
  void describe("defineFunction type test", async () => {
5
15
  await test("Type test", () => {
@@ -25,5 +35,28 @@ void describe("defineFunction type test", async () => {
25
35
 
26
36
  //@ts-expect-error run is required
27
37
  defineFunction({ description: "invalid" });
38
+
39
+ const defineTestFunctions = createFunctionsDefiner<TestSchema>();
40
+ const functions = defineTestFunctions({
41
+ getItem: defineFunction({
42
+ run: (_args, { dbo }) => {
43
+ void dbo.items.find();
44
+ // @ts-expect-error The schema is retained without a satisfies assertion.
45
+ void dbo.missingTable;
46
+ return { id: 1 as const };
47
+ },
48
+ }),
49
+ });
50
+
51
+ const defineTestFunctionGroup = createFunctionGroupDefiner<TestSchema>();
52
+ const group = defineTestFunctionGroup({
53
+ userFilter: { type: "public" },
54
+ functions,
55
+ });
56
+
57
+ group.functions.getItem satisfies (typeof functions)["getItem"];
58
+
59
+ // @ts-expect-error A group must have a user filter.
60
+ defineTestFunctionGroup({ functions });
28
61
  });
29
62
  });
@@ -48,7 +48,7 @@ export type ServerFunctionDefinition = {
48
48
  };
49
49
 
50
50
  declare const serverFunctionContext: unique symbol;
51
- type ServerFunctionContextMarker<S, SUser extends SessionUser> = {
51
+ export type ServerFunctionContextMarker<S, SUser extends SessionUser> = {
52
52
  [serverFunctionContext]?: [S, SUser];
53
53
  };
54
54
 
@@ -96,16 +96,33 @@ type UsersTableRow<S> =
96
96
 
97
97
  type ValidDbSchema<S> = S extends DBSchema ? S : void;
98
98
 
99
- export type ServerFunctionDefinitions<
99
+ export type ServerFunctionGroupFunctions<
100
100
  S = void,
101
101
  SUser extends SessionUser = SessionUser,
102
- > = Record<
102
+ > = Record<string, ServerFunctionDefinition & ServerFunctionContextMarker<S, SUser>>;
103
+
104
+ export type ServerFunctionGroup<S = void, SUser extends SessionUser = SessionUser> = {
105
+ userFilter: FullFilter<UsersTableRow<S>, ValidDbSchema<S>>;
106
+ functions: ServerFunctionGroupFunctions<S, SUser>;
107
+ };
108
+
109
+ export type ServerFunctionDefinitions<S = void, SUser extends SessionUser = SessionUser> = Record<
103
110
  string,
104
- {
105
- userFilter: FullFilter<UsersTableRow<S>, ValidDbSchema<S>>;
106
- functions: Record<
107
- string,
108
- ServerFunctionDefinition & ServerFunctionContextMarker<S, SUser>
109
- >;
110
- }
111
+ ServerFunctionGroup<S, SUser>
111
112
  >;
113
+
114
+ /**
115
+ * Creates a schema-aware identity helper for defining a server function group
116
+ * while preserving its inferred function names and return types.
117
+ */
118
+ export const createFunctionGroupDefiner = <S = void, SUser extends SessionUser = SessionUser>() => {
119
+ return <const T extends ServerFunctionGroup<S, SUser>>(group: T): T => group;
120
+ };
121
+
122
+ /**
123
+ * Creates a schema-aware identity helper for function maps that are composed
124
+ * into a server function group elsewhere.
125
+ */
126
+ export const createFunctionsDefiner = <S = void, SUser extends SessionUser = SessionUser>() => {
127
+ return <const T extends ServerFunctionGroupFunctions<S, SUser>>(functions: T): T => functions;
128
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.591",
3
+ "version": "4.2.593",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",