prostgles-server 4.2.180 → 4.2.182
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/README.md +48 -52
- package/dist/DBSchemaBuilder.d.ts +2 -2
- package/dist/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder.js +34 -26
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/getColumns.d.ts.map +1 -1
- package/dist/DboBuilder/getColumns.js +41 -16
- package/dist/DboBuilder/getColumns.js.map +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +1 -2
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +7 -5
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/initProstgles.js +12 -12
- package/dist/initProstgles.js.map +1 -1
- package/dist/typeTests/dboTypeCheck.d.ts.map +1 -1
- package/dist/typeTests/dboTypeCheck.js +11 -11
- package/dist/typeTests/dboTypeCheck.js.map +1 -1
- package/documentation/METHODS.md +1467 -0
- package/documentation/SERVER.md +6 -7
- package/documentation/utils/clientTypes.ts +8602 -2623
- package/documentation/utils/dist/clientTypes.d.ts +7307 -1801
- package/documentation/utils/dist/clientTypes.d.ts.map +1 -1
- package/documentation/utils/dist/clientTypes.js +8602 -2623
- package/documentation/utils/dist/generateClientDocs.d.ts +0 -1
- package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -1
- package/documentation/utils/dist/generateClientDocs.js +85 -35
- package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -1
- package/documentation/utils/dist/generateServerDocs.js +11 -10
- package/documentation/utils/dist/getResolvedTypes.js +1 -1
- package/documentation/utils/dist/getSerializableType.d.ts +1 -1
- package/documentation/utils/dist/getSerializableType.d.ts.map +1 -1
- package/documentation/utils/dist/getSerializableType.js +29 -23
- package/documentation/utils/dist/loadTsFile.d.ts.map +1 -1
- package/documentation/utils/dist/loadTsFile.js +0 -4
- package/documentation/utils/dist/serverTypes.d.ts +3 -9
- package/documentation/utils/dist/serverTypes.d.ts.map +1 -1
- package/documentation/utils/dist/serverTypes.js +3 -9
- package/documentation/utils/generateClientDocs.ts +99 -31
- package/documentation/utils/generateServerDocs.ts +12 -10
- package/documentation/utils/getSerializableType.ts +13 -3
- package/documentation/utils/loadTsFile.ts +0 -4
- package/documentation/utils/serverTypes.ts +3 -9
- package/documentation/utils/tsconfig.json +2 -2
- package/lib/DBSchemaBuilder.ts +148 -118
- package/lib/DboBuilder/getColumns.ts +63 -31
- package/lib/Prostgles.ts +1 -2
- package/lib/ProstglesTypes.ts +7 -4
- package/lib/initProstgles.ts +50 -51
- package/lib/typeTests/DBoGenerated.d.ts +23 -19
- package/lib/typeTests/dboTypeCheck.ts +49 -35
- package/package.json +4 -3
- package/documentation/CLIENT.md +0 -542
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClientDocs.d.ts","sourceRoot":"","sources":["../generateClientDocs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateClientDocs.d.ts","sourceRoot":"","sources":["../generateClientDocs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,YA0F9B,CAAC"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateClientDocs = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const prostgles_types_1 = require("prostgles-types");
|
|
7
|
-
const getResolvedTypes_1 = require("./getResolvedTypes");
|
|
8
|
-
const prostgles_types_2 = require("prostgles-types");
|
|
9
7
|
const clientTypes_1 = require("./clientTypes");
|
|
8
|
+
const getResolvedTypes_1 = require("./getResolvedTypes");
|
|
10
9
|
const testFolderPath = `${__dirname}/../../../tests/`;
|
|
11
10
|
const docsFolder = `${__dirname}/../../`;
|
|
12
11
|
const generateClientDocs = () => {
|
|
13
12
|
const clientFilePath = path.resolve(`${testFolderPath}/client/node_modules/prostgles-client/dist/prostgles.d.ts`);
|
|
14
13
|
const excludedTypes = [
|
|
15
|
-
"FullFilter",
|
|
16
|
-
"FullFilter<T, S> | undefined",
|
|
14
|
+
// "FullFilter",
|
|
15
|
+
// "FullFilter<T, S> | undefined",
|
|
17
16
|
"FieldFilter | undefined",
|
|
18
17
|
"SyncOptions",
|
|
19
18
|
"SyncOneOptions",
|
|
@@ -22,17 +21,14 @@ const generateClientDocs = () => {
|
|
|
22
21
|
const { resolvedTypes, visitedMaps } = (0, getResolvedTypes_1.getResolvedTypes)({
|
|
23
22
|
filePath: clientFilePath,
|
|
24
23
|
filter: {
|
|
25
|
-
nodeNames: [
|
|
26
|
-
// "ViewHandlerClient",
|
|
27
|
-
"TableHandlerClient",
|
|
28
|
-
],
|
|
24
|
+
nodeNames: ["TableHandlerClient"],
|
|
29
25
|
excludedTypes,
|
|
30
26
|
},
|
|
31
27
|
});
|
|
32
28
|
const jsonTypes = JSON.stringify([
|
|
33
29
|
...resolvedTypes,
|
|
34
30
|
...visitedMaps
|
|
35
|
-
.flatMap((m) => Array.from(m.values()).map((v) =>
|
|
31
|
+
.flatMap((m) => Array.from(m.values()).map((v) => excludedTypes.includes(v.resolvedType.alias ?? "") ? v.resolvedType : undefined))
|
|
36
32
|
.filter(prostgles_types_1.isDefined),
|
|
37
33
|
], null, 2);
|
|
38
34
|
fs.writeFileSync(`${__dirname}/../clientTypes.ts`, [
|
|
@@ -41,8 +37,38 @@ const generateClientDocs = () => {
|
|
|
41
37
|
].join("\n"), {
|
|
42
38
|
encoding: "utf-8",
|
|
43
39
|
});
|
|
44
|
-
const docPath = `${docsFolder}
|
|
45
|
-
|
|
40
|
+
const docPath = `${docsFolder}METHODS.md`;
|
|
41
|
+
const tableHandler = clientTypes_1.definitions[0];
|
|
42
|
+
const isomotphicMethodNames = {
|
|
43
|
+
count: 1,
|
|
44
|
+
delete: 1,
|
|
45
|
+
find: 1,
|
|
46
|
+
insert: 1,
|
|
47
|
+
update: 1,
|
|
48
|
+
findOne: 1,
|
|
49
|
+
getColumns: 1,
|
|
50
|
+
getInfo: 1,
|
|
51
|
+
size: 1,
|
|
52
|
+
subscribe: 1,
|
|
53
|
+
subscribeOne: 1,
|
|
54
|
+
updateBatch: 1,
|
|
55
|
+
upsert: 1,
|
|
56
|
+
};
|
|
57
|
+
const isomorphicMd = getMethodsDocs((0, prostgles_types_1.getObjectEntries)(tableHandler.properties).filter(([methodName]) => isomotphicMethodNames[methodName]));
|
|
58
|
+
const clientMd = getMethodsDocs((0, prostgles_types_1.getObjectEntries)(tableHandler.properties).filter(([methodName]) => !isomotphicMethodNames[methodName]));
|
|
59
|
+
const result = [
|
|
60
|
+
`# Isomorphic Methods`,
|
|
61
|
+
``,
|
|
62
|
+
`The following methods are available on the client and server.`,
|
|
63
|
+
``,
|
|
64
|
+
isomorphicMd.join("\n\n"),
|
|
65
|
+
`# Client Methods`,
|
|
66
|
+
``,
|
|
67
|
+
`The following methods are available on the client.`,
|
|
68
|
+
``,
|
|
69
|
+
clientMd.join("\n\n"),
|
|
70
|
+
].join("\n");
|
|
71
|
+
fs.writeFileSync(docPath, result, { encoding: "utf-8" });
|
|
46
72
|
};
|
|
47
73
|
exports.generateClientDocs = generateClientDocs;
|
|
48
74
|
const getAliasWithoutGenerics = (type) => {
|
|
@@ -50,47 +76,64 @@ const getAliasWithoutGenerics = (type) => {
|
|
|
50
76
|
return type.types.map(getAliasWithoutGenerics).join(" | ");
|
|
51
77
|
return type.aliasSymbolescapedName || type.alias;
|
|
52
78
|
};
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const mdxContent = (0, prostgles_types_2.getObjectEntries)(tableHandler.properties).map(([methodName, _methodInfo]) => {
|
|
56
|
-
var _a;
|
|
79
|
+
const getMethodsDocs = (methods) => {
|
|
80
|
+
return methods.map(([methodName, _methodInfo]) => {
|
|
57
81
|
const methodInfo = (_methodInfo.type === "function" ?
|
|
58
82
|
_methodInfo
|
|
59
83
|
// : _methodInfo.type === "union" ? _methodInfo.types.find((t) => t.type === "function")
|
|
60
84
|
: undefined);
|
|
61
85
|
if (!methodInfo)
|
|
62
86
|
return "";
|
|
87
|
+
const args = `${methodInfo.arguments
|
|
88
|
+
.map((arg) => `${arg.name}${arg.optional ? "?" : ""}: ${getAliasWithoutGenerics(arg)}`)
|
|
89
|
+
.join(", ")}`;
|
|
90
|
+
const rType = `${methodInfo.returnType.aliasSymbolescapedName || methodInfo.returnType.alias}`
|
|
91
|
+
.replaceAll("<", "<")
|
|
92
|
+
.replaceAll(">", ">");
|
|
63
93
|
return [
|
|
64
|
-
`## ${methodName}()
|
|
65
|
-
|
|
66
|
-
`\`\`\`typescript
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
\`\`\``,
|
|
71
|
-
`#### Arguments`,
|
|
94
|
+
`## ${methodName}<span style="opacity: 0.6;">(${args}): ${rType}</span>`,
|
|
95
|
+
methodInfo.comments ?? "",
|
|
96
|
+
`\`\`\`typescript`,
|
|
97
|
+
`${methodName}: (): `,
|
|
98
|
+
`\`\`\``,
|
|
99
|
+
`#### Parameters`,
|
|
72
100
|
``,
|
|
73
101
|
...methodInfo.arguments.map((arg) => {
|
|
74
102
|
return renderType(arg, 2, { name: arg.name, optional: arg.optional });
|
|
75
103
|
}),
|
|
76
|
-
`#### Return type`,
|
|
77
|
-
renderType(methodInfo.returnType, 0, undefined),
|
|
104
|
+
// `#### Return type`,
|
|
105
|
+
`#### ` + renderType(methodInfo.returnType, 0, undefined),
|
|
78
106
|
].join("\n");
|
|
79
107
|
});
|
|
80
|
-
const result = mdxContent.join("\n\n");
|
|
81
|
-
fs.writeFileSync(filePath, result, { encoding: "utf-8" });
|
|
82
108
|
};
|
|
83
|
-
|
|
109
|
+
const renderedAliases = new Set();
|
|
84
110
|
const renderType = (type, indent = 2, argOrProp) => {
|
|
85
111
|
const indentText = " ".repeat(indent);
|
|
86
|
-
const
|
|
112
|
+
const typeAlias = `\`${type.aliasSymbolescapedName || type.alias}\``;
|
|
113
|
+
const typeText = type.aliasSymbolescapedName && type.type === "object" ?
|
|
114
|
+
`<span style="color: green;">${type.aliasSymbolescapedName}</span>`
|
|
115
|
+
: typeAlias;
|
|
116
|
+
const title = [
|
|
117
|
+
`${indentText}${argOrProp?.name ? `- **${argOrProp.name}**: ` : ""}${typeAlias}`,
|
|
118
|
+
`${type.comments ? `${removeLineBreaks(type.comments, indentText + " ")}` : ""}`,
|
|
119
|
+
].join("\n\n");
|
|
120
|
+
if (typeAlias?.includes("FullFilter")) {
|
|
121
|
+
// debugger;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Re-use rendered types by linking them through an anchor tag
|
|
125
|
+
*/
|
|
126
|
+
if (type.aliasSymbolescapedName && argOrProp?.name) {
|
|
127
|
+
renderedAliases.add(type.aliasSymbolescapedName);
|
|
128
|
+
console.log(type.aliasSymbolescapedName);
|
|
129
|
+
}
|
|
87
130
|
if (type.type === "primitive" || type.type === "literal") {
|
|
88
131
|
return title;
|
|
89
132
|
}
|
|
90
133
|
if (type.type === "object") {
|
|
91
134
|
return (title +
|
|
92
135
|
`\n` +
|
|
93
|
-
(0,
|
|
136
|
+
(0, prostgles_types_1.getObjectEntries)(type.properties)
|
|
94
137
|
.map(([name, p]) => renderType(p, indent + 2, { name, optional: p.optional }))
|
|
95
138
|
.join("\n"));
|
|
96
139
|
}
|
|
@@ -106,10 +149,17 @@ const renderType = (type, indent = 2, argOrProp) => {
|
|
|
106
149
|
}
|
|
107
150
|
return title;
|
|
108
151
|
};
|
|
109
|
-
const removeLineBreaks = (str
|
|
152
|
+
const removeLineBreaks = (str, indent) => str
|
|
110
153
|
.split("\n")
|
|
111
154
|
.map((line) => {
|
|
112
|
-
|
|
113
|
-
return `${line}.`;
|
|
155
|
+
return `${indent}${line.trimStart()}`;
|
|
114
156
|
})
|
|
115
|
-
.join("
|
|
157
|
+
.join("\n");
|
|
158
|
+
const renderTypeAlias = (type) => {
|
|
159
|
+
const typeAlias = type.aliasSymbolescapedName || type.alias;
|
|
160
|
+
const style = type.aliasSymbolescapedName ? `style="color: green;"` : "";
|
|
161
|
+
// if (renderedAliases.has(typeAlias)) {
|
|
162
|
+
// return `<a ${style} href="#${typeAlias}">${typeAlias}</a>`;
|
|
163
|
+
// }
|
|
164
|
+
return `<span ${style}>${typeAlias}</span>`;
|
|
165
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateServerDocs.d.ts","sourceRoot":"","sources":["../generateServerDocs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"generateServerDocs.d.ts","sourceRoot":"","sources":["../generateServerDocs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,YAyE9B,CAAC"}
|
|
@@ -13,7 +13,7 @@ const generateServerDocs = () => {
|
|
|
13
13
|
// `${testFolderPath}/server/node_modules/prostgles-server/dist/DBSchemaBuilder.d.ts` // "DBOFullyTyped",
|
|
14
14
|
`${testFolderPath}/server/node_modules/prostgles-server/dist/ProstglesTypes.d.ts` // "ProstglesInitOptions",
|
|
15
15
|
);
|
|
16
|
-
const { resolvedTypes: [ProstglesInitOptions],
|
|
16
|
+
const { resolvedTypes: [ProstglesInitOptions], } = (0, getResolvedTypes_1.getResolvedTypes)({
|
|
17
17
|
filePath: serverFilePath,
|
|
18
18
|
filter: {
|
|
19
19
|
nodeNames: [
|
|
@@ -24,9 +24,14 @@ const generateServerDocs = () => {
|
|
|
24
24
|
maxDepth: 2,
|
|
25
25
|
},
|
|
26
26
|
});
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const serverTypesStr = [
|
|
28
|
+
`import type { TS_Type } from "./getSerializableType";`,
|
|
29
|
+
`export const definitions = ${JSON.stringify([ProstglesInitOptions], null, 2)} as const satisfies TS_Type[];`,
|
|
30
|
+
].join("\n");
|
|
31
|
+
fs.writeFileSync(`${docsFolder}/utils/serverTypes.ts`, serverTypesStr, { encoding: "utf-8" });
|
|
29
32
|
const prostglesInitOpts = serverTypes_1.definitions[0];
|
|
33
|
+
if (!ProstglesInitOptions || !prostglesInitOpts)
|
|
34
|
+
throw new Error("ProstglesInitOptions not found");
|
|
30
35
|
const docs = [
|
|
31
36
|
`# Overview`,
|
|
32
37
|
`Our Isomorphic Typescript API allows connecting to a PostgreSQL database to get a realtime view of the data and schema. Interact with the data with full end-to-end type safety.`,
|
|
@@ -41,8 +46,8 @@ const generateServerDocs = () => {
|
|
|
41
46
|
`Basic example:`,
|
|
42
47
|
`\`\`\`typescript`,
|
|
43
48
|
`import prostgles from "prostgles-server";`,
|
|
44
|
-
`import {
|
|
45
|
-
`prostgles<
|
|
49
|
+
`import { DBGeneratedSchema } from "./DBGeneratedSchema";`,
|
|
50
|
+
`prostgles<DBGeneratedSchema>({`,
|
|
46
51
|
` dbConnection: {`,
|
|
47
52
|
` host: "localhost",`,
|
|
48
53
|
` port: 5432,`,
|
|
@@ -63,6 +68,7 @@ const generateServerDocs = () => {
|
|
|
63
68
|
`\`\`\``,
|
|
64
69
|
`### Configuration options`,
|
|
65
70
|
...(0, prostgles_types_1.getObjectEntries)(prostglesInitOpts.properties).map(([propName, prop]) => {
|
|
71
|
+
//@ts-ignore
|
|
66
72
|
const title = ` - <strong>${propName}</strong> \`${prop.aliasSymbolescapedName || prop.alias}\``;
|
|
67
73
|
const comments = prop.comments || "";
|
|
68
74
|
if (!comments)
|
|
@@ -70,11 +76,6 @@ const generateServerDocs = () => {
|
|
|
70
76
|
return [title, ` ` + comments + " "].join("\n");
|
|
71
77
|
}),
|
|
72
78
|
].join("\n");
|
|
73
|
-
const serverTypesStr = [
|
|
74
|
-
`import type { TS_Type } from "./getSerializableType";`,
|
|
75
|
-
`export const definitions = ${JSON.stringify([ProstglesInitOptions], null, 2)} as const satisfies TS_Type[];`,
|
|
76
|
-
].join("\n");
|
|
77
|
-
fs.writeFileSync(`${docsFolder}/utils/serverTypes.ts`, serverTypesStr, { encoding: "utf-8" });
|
|
78
79
|
fs.writeFileSync(`${docsFolder}SERVER.md`, docs, { encoding: "utf-8" });
|
|
79
80
|
};
|
|
80
81
|
exports.generateServerDocs = generateServerDocs;
|
|
@@ -14,7 +14,7 @@ const getResolvedTypes = ({ filePath, filter }) => {
|
|
|
14
14
|
// console.log("node.name.text", node.getText());
|
|
15
15
|
// }
|
|
16
16
|
if (ts.isTypeAliasDeclaration(node)) {
|
|
17
|
-
if (!filter ||
|
|
17
|
+
if (!filter || filter?.nodeNames.includes(node.name.text)) {
|
|
18
18
|
const type1 = checker.getTypeAtLocation(node.type);
|
|
19
19
|
const { resolvedType, visited } = (0, getSerializableType_1.getSerializableType)(type1, checker, undefined, [], filter, 0);
|
|
20
20
|
results.push(resolvedType);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSerializableType.d.ts","sourceRoot":"","sources":["../getSerializableType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,KAAK,OAAO,GAAG;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,
|
|
1
|
+
{"version":3,"file":"getSerializableType.d.ts","sourceRoot":"","sources":["../getSerializableType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,KAAK,OAAO,GAAG;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG;IACnC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW,CAAC;CACzE,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG;IAChC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC7D,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,CAAC,OAAO,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC,EAAE,CAAC;IAC7D,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG;IACnC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,OAAO,GACf,YAAY,GACZ,UAAU,GACV,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,UAAU,GACV,YAAY,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,GAAG,CAC/B,MAAM,EACN;IAAE,YAAY,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAClE,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACtB,GAAG,IAAI,WACN,GAAG,WAAW,uDAER,MAAM,EAAE,QACjB,kBAAkB,GAAG,SAAS,SAC7B,MAAM;kBACI,OAAO;;CA8UzB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,eAAO,MAAM,WAAW,WACd,GAAG,IAAI,WACN,GAAG,WAAW,QACjB,kBAAkB;kBACP,OAAO;;CAMzB,CAAC"}
|
|
@@ -4,11 +4,10 @@ exports.resolveType = exports.getSerializableType = void 0;
|
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const prostgles_types_1 = require("prostgles-types");
|
|
6
6
|
const getSerializableType = (myType, checker, visited = new Map(), parentAliases, opts, depth) => {
|
|
7
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
8
7
|
let alias = "unknown";
|
|
9
|
-
const { escapedName } =
|
|
10
|
-
const aliasSymbolescapedName = escapedName
|
|
11
|
-
const symbol =
|
|
8
|
+
const { escapedName } = myType.aliasSymbol ?? {};
|
|
9
|
+
const aliasSymbolescapedName = escapedName?.toString();
|
|
10
|
+
const symbol = myType.aliasSymbol ?? myType.symbol;
|
|
12
11
|
const comments = symbol ? getSymbolComments(symbol, checker) : undefined;
|
|
13
12
|
try {
|
|
14
13
|
alias = checker.typeToString(myType);
|
|
@@ -19,21 +18,20 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
|
|
|
19
18
|
/* Circular resolved type */
|
|
20
19
|
const visitedType = visited.get(alias);
|
|
21
20
|
if (visitedType) {
|
|
22
|
-
return { resolvedType:
|
|
21
|
+
return { resolvedType: visitedType.referenceType ?? visitedType.resolvedType, visited };
|
|
23
22
|
}
|
|
24
23
|
const withAlias = (_type) => {
|
|
25
|
-
var _a;
|
|
26
24
|
const finalComments = _type.comments || comments;
|
|
27
25
|
const resolvedType = sortObjectsByKeyOrder({
|
|
28
|
-
alias:
|
|
26
|
+
alias: _type.alias ?? alias,
|
|
29
27
|
aliasSymbolescapedName,
|
|
30
28
|
..._type,
|
|
31
29
|
...(finalComments && { comments: finalComments }),
|
|
32
30
|
}, ["type", "alias", "aliasSymbolescapedName", "comments"]);
|
|
33
31
|
let referenceType;
|
|
34
|
-
if (
|
|
35
|
-
(escapedName &&
|
|
36
|
-
(
|
|
32
|
+
if (opts?.excludedTypes.includes(alias) ||
|
|
33
|
+
(escapedName && opts?.excludedTypes.includes(escapedName)) ||
|
|
34
|
+
(opts?.maxDepth !== undefined && depth >= opts.maxDepth)) {
|
|
37
35
|
referenceType =
|
|
38
36
|
resolvedType.type === "primitive" ?
|
|
39
37
|
resolvedType
|
|
@@ -45,9 +43,9 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
|
|
|
45
43
|
};
|
|
46
44
|
}
|
|
47
45
|
visited.set(alias, { resolvedType, referenceType, type: myType });
|
|
48
|
-
return { resolvedType: referenceType
|
|
46
|
+
return { resolvedType: referenceType ?? resolvedType, visited };
|
|
49
47
|
};
|
|
50
|
-
const unresolvedParentAliases =
|
|
48
|
+
const unresolvedParentAliases = parentAliases?.filter((a) => !visited.get(a)) ?? [];
|
|
51
49
|
/* Circular unresolved type */
|
|
52
50
|
if (unresolvedParentAliases.includes(alias)) {
|
|
53
51
|
return withAlias({
|
|
@@ -99,9 +97,9 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
|
|
|
99
97
|
if (checker.isArrayType(myType)) {
|
|
100
98
|
const itemType = checker.getTypeArguments(myType)[0];
|
|
101
99
|
if (itemType && checker.isTupleType(itemType)) {
|
|
102
|
-
const tupleTypes =
|
|
100
|
+
const tupleTypes = itemType.resolvedTypeArguments.map((d) => {
|
|
103
101
|
return (0, exports.getSerializableType)(d, checker, visited, nextUnresolvedParentAliases, opts, depth + 1).resolvedType;
|
|
104
|
-
})
|
|
102
|
+
}) ?? [];
|
|
105
103
|
return withAlias({
|
|
106
104
|
type: "tuple",
|
|
107
105
|
itemTypes: tupleTypes,
|
|
@@ -149,12 +147,12 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
|
|
|
149
147
|
if (objectType.objectFlags & ts.ObjectFlags.Reference) {
|
|
150
148
|
const typeReference = objectType;
|
|
151
149
|
const target = typeReference.target;
|
|
152
|
-
if (
|
|
150
|
+
if (target.symbol?.escapedName === "Promise") {
|
|
153
151
|
const _innerType = checker.getTypeArguments(typeReference)[0];
|
|
154
152
|
const defaultType = { type: "primitive", subType: "any" };
|
|
155
153
|
const resolvedInnerType = _innerType &&
|
|
156
154
|
(0, exports.getSerializableType)(_innerType, checker, visited, nextUnresolvedParentAliases, opts, depth + 1).resolvedType;
|
|
157
|
-
const innerType =
|
|
155
|
+
const innerType = resolvedInnerType?.type === "promise" ? defaultType : (resolvedInnerType ?? defaultType);
|
|
158
156
|
return withAlias({
|
|
159
157
|
type: "promise",
|
|
160
158
|
innerType,
|
|
@@ -173,8 +171,11 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
|
|
|
173
171
|
comments: propertyComments || undefined,
|
|
174
172
|
};
|
|
175
173
|
});
|
|
176
|
-
const comments =
|
|
177
|
-
|
|
174
|
+
const comments = myType.aliasSymbol?.declarations &&
|
|
175
|
+
getNonInternalTSDeclarations(myType.aliasSymbol?.declarations)
|
|
176
|
+
//@ts-ignore
|
|
177
|
+
?.flatMap((d) => (!d.jsDoc ? [] : d.jsDoc.map((jd) => jd.comment)))
|
|
178
|
+
.join("\n");
|
|
178
179
|
return withAlias({
|
|
179
180
|
type: "object",
|
|
180
181
|
properties,
|
|
@@ -187,12 +188,18 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
|
|
|
187
188
|
if (myType.isIntersection()) {
|
|
188
189
|
const intersectionTypes = myType.types.map((t) => {
|
|
189
190
|
const { resolvedType: intersectionType } = (0, exports.getSerializableType)(t, checker, visited, nextUnresolvedParentAliases, opts, depth + 1);
|
|
190
|
-
intersectionType.
|
|
191
|
+
if (intersectionType.type === "object") {
|
|
192
|
+
intersectionType.intersectionParent = aliasSymbolescapedName;
|
|
193
|
+
}
|
|
191
194
|
return intersectionType;
|
|
192
195
|
});
|
|
193
196
|
if (intersectionTypes.every((t) => t.type === "object")) {
|
|
194
197
|
const properties = intersectionTypes.reduce((acc, t) => {
|
|
195
|
-
|
|
198
|
+
const propertiesWithParentObject = Object.entries(t.properties).reduce((acc, [k, v]) => ({
|
|
199
|
+
...acc,
|
|
200
|
+
[k]: { ...v, intersectionParent: t.aliasSymbolescapedName },
|
|
201
|
+
}), {});
|
|
202
|
+
return { ...acc, ...propertiesWithParentObject };
|
|
196
203
|
}, {});
|
|
197
204
|
return withAlias({
|
|
198
205
|
type: "object",
|
|
@@ -244,9 +251,8 @@ const sortObjectsByKeyOrder = (obj, keyOrder) => {
|
|
|
244
251
|
const arraySort = (arrayToSort, keyOrder) => {
|
|
245
252
|
const keyOrderMap = new Map(keyOrder.map((value, index) => [value, index]));
|
|
246
253
|
return arrayToSort.sort((a, b) => {
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
const bIndex = (_b = keyOrderMap.get(b)) !== null && _b !== void 0 ? _b : Infinity;
|
|
254
|
+
const aIndex = keyOrderMap.get(a) ?? Infinity;
|
|
255
|
+
const bIndex = keyOrderMap.get(b) ?? Infinity;
|
|
250
256
|
return aIndex - bIndex;
|
|
251
257
|
});
|
|
252
258
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadTsFile.d.ts","sourceRoot":"","sources":["../loadTsFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM;;;;
|
|
1
|
+
{"version":3,"file":"loadTsFile.d.ts","sourceRoot":"","sources":["../loadTsFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM;;;;CAqC1C,CAAC"}
|
|
@@ -4,17 +4,13 @@ exports.loadTsFile = void 0;
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const ts = require("typescript");
|
|
6
6
|
const loadTsFile = (filePath) => {
|
|
7
|
-
// Normalize file path
|
|
8
7
|
const absolutePath = path.resolve(filePath);
|
|
9
|
-
// Create compiler host and program
|
|
10
8
|
const configPath = ts.findConfigFile(path.dirname(absolutePath), ts.sys.fileExists, "tsconfig.json");
|
|
11
9
|
if (!configPath) {
|
|
12
10
|
throw new Error("Could not find a valid 'tsconfig.json'.");
|
|
13
11
|
}
|
|
14
|
-
// Parse the config file
|
|
15
12
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
16
13
|
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
17
|
-
// Create program
|
|
18
14
|
const program = ts.createProgram({
|
|
19
15
|
rootNames: [absolutePath],
|
|
20
16
|
options: parsedConfig.options,
|
|
@@ -39,15 +39,10 @@ export declare const definitions: [{
|
|
|
39
39
|
readonly optional: false;
|
|
40
40
|
readonly comments: "Called when the prostgles server is ready to accept connections.\nIt waits for auth, tableConfig and other async configurations to complete before executing";
|
|
41
41
|
};
|
|
42
|
-
readonly dbOptions: {
|
|
43
|
-
readonly type: "reference";
|
|
44
|
-
readonly alias: "IDefaults";
|
|
45
|
-
readonly optional: true;
|
|
46
|
-
};
|
|
47
42
|
readonly tsGeneratedTypesDir: {
|
|
48
43
|
readonly type: "reference";
|
|
49
44
|
readonly alias: "string | undefined";
|
|
50
|
-
readonly comments: "If defined then a `
|
|
45
|
+
readonly comments: "If defined then a `DBGeneratedSchema.d.ts` file will be created in the provided directory.\nThis file exports a `DBGeneratedSchema` type which contains types for the database tables and\ncan be used as a generic type input for the prostgles instances to ensure type safety";
|
|
51
46
|
readonly optional: true;
|
|
52
47
|
};
|
|
53
48
|
readonly disableRealtime: {
|
|
@@ -257,7 +252,7 @@ export declare const definitions: [{
|
|
|
257
252
|
readonly subType: "boolean";
|
|
258
253
|
}];
|
|
259
254
|
readonly optional: true;
|
|
260
|
-
readonly comments: "If truthy then
|
|
255
|
+
readonly comments: "If truthy then DBGeneratedSchema.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server";
|
|
261
256
|
};
|
|
262
257
|
readonly keywords: {
|
|
263
258
|
readonly type: "reference";
|
|
@@ -272,8 +267,7 @@ export declare const definitions: [{
|
|
|
272
267
|
};
|
|
273
268
|
readonly fileTable: {
|
|
274
269
|
readonly type: "reference";
|
|
275
|
-
readonly alias: "FileTableConfig";
|
|
276
|
-
readonly aliasSymbolescapedName: "FileTableConfig";
|
|
270
|
+
readonly alias: "FileTableConfig | undefined";
|
|
277
271
|
readonly comments: "Enables file storage and serving.\nCurrently supports saving files locally or to AWS S3";
|
|
278
272
|
readonly optional: true;
|
|
279
273
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverTypes.d.ts","sourceRoot":"","sources":["../serverTypes.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"serverTypes.d.ts","sourceRoot":"","sources":["../serverTypes.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiVM,CAAC"}
|
|
@@ -48,15 +48,10 @@ exports.definitions = [
|
|
|
48
48
|
"optional": false,
|
|
49
49
|
"comments": "Called when the prostgles server is ready to accept connections.\nIt waits for auth, tableConfig and other async configurations to complete before executing"
|
|
50
50
|
},
|
|
51
|
-
"dbOptions": {
|
|
52
|
-
"type": "reference",
|
|
53
|
-
"alias": "IDefaults",
|
|
54
|
-
"optional": true
|
|
55
|
-
},
|
|
56
51
|
"tsGeneratedTypesDir": {
|
|
57
52
|
"type": "reference",
|
|
58
53
|
"alias": "string | undefined",
|
|
59
|
-
"comments": "If defined then a `
|
|
54
|
+
"comments": "If defined then a `DBGeneratedSchema.d.ts` file will be created in the provided directory.\nThis file exports a `DBGeneratedSchema` type which contains types for the database tables and\ncan be used as a generic type input for the prostgles instances to ensure type safety",
|
|
60
55
|
"optional": true
|
|
61
56
|
},
|
|
62
57
|
"disableRealtime": {
|
|
@@ -297,7 +292,7 @@ exports.definitions = [
|
|
|
297
292
|
}
|
|
298
293
|
],
|
|
299
294
|
"optional": true,
|
|
300
|
-
"comments": "If truthy then
|
|
295
|
+
"comments": "If truthy then DBGeneratedSchema.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server"
|
|
301
296
|
},
|
|
302
297
|
"keywords": {
|
|
303
298
|
"type": "reference",
|
|
@@ -312,8 +307,7 @@ exports.definitions = [
|
|
|
312
307
|
},
|
|
313
308
|
"fileTable": {
|
|
314
309
|
"type": "reference",
|
|
315
|
-
"alias": "FileTableConfig",
|
|
316
|
-
"aliasSymbolescapedName": "FileTableConfig",
|
|
310
|
+
"alias": "FileTableConfig | undefined",
|
|
317
311
|
"comments": "Enables file storage and serving.\nCurrently supports saving files locally or to AWS S3",
|
|
318
312
|
"optional": true
|
|
319
313
|
},
|