prostgles-server 4.2.178 → 4.2.180
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/.vscode/settings.json +10 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/DataValidator.js +4 -4
- package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.js +3 -3
- package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
- package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/update.js +45 -19
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -2
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +1 -1
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/Logging.d.ts +10 -3
- package/dist/Logging.d.ts.map +1 -1
- package/dist/Prostgles.d.ts +2 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +118 -53
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +77 -23
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/ProstglesTypes.js.map +1 -1
- package/dist/SyncReplication.js +2 -2
- package/dist/SyncReplication.js.map +1 -1
- package/dist/initProstgles.d.ts +9 -2
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +65 -57
- package/dist/initProstgles.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/documentation/CLIENT.md +542 -0
- package/documentation/SERVER.md +104 -0
- package/documentation/utils/clientTypes.ts +8436 -0
- package/documentation/utils/dist/clientTypes.d.ts +7705 -0
- package/documentation/utils/dist/clientTypes.d.ts.map +1 -0
- package/documentation/utils/dist/clientTypes.js +8438 -0
- package/documentation/utils/dist/definitions.d.ts +7705 -0
- package/documentation/utils/dist/definitions.d.ts.map +1 -0
- package/documentation/utils/dist/definitions.js +8438 -0
- package/documentation/utils/dist/generateClientDocs.d.ts +3 -0
- package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateClientDocs.js +115 -0
- package/documentation/utils/dist/generateDocs.d.ts +2 -0
- package/documentation/utils/dist/generateDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateDocs.js +6 -0
- package/documentation/utils/dist/generateMarkdown.d.ts +2 -0
- package/documentation/utils/dist/generateMarkdown.d.ts.map +1 -0
- package/documentation/utils/dist/generateMarkdown.js +68 -0
- package/documentation/utils/dist/generateServerDocs.d.ts +2 -0
- package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -0
- package/documentation/utils/dist/generateServerDocs.js +80 -0
- package/documentation/utils/dist/getResolvedTypes.d.ts +15 -0
- package/documentation/utils/dist/getResolvedTypes.d.ts.map +1 -0
- package/documentation/utils/dist/getResolvedTypes.js +29 -0
- package/documentation/utils/dist/getSerializableType.d.ts +69 -0
- package/documentation/utils/dist/getSerializableType.d.ts.map +1 -0
- package/documentation/utils/dist/getSerializableType.js +273 -0
- package/documentation/utils/dist/getSymbolComments.d.ts +11 -0
- package/documentation/utils/dist/getSymbolComments.d.ts.map +1 -0
- package/documentation/utils/dist/getSymbolComments.js +60 -0
- package/documentation/utils/dist/loadTsFile.d.ts +7 -0
- package/documentation/utils/dist/loadTsFile.d.ts.map +1 -0
- package/documentation/utils/dist/loadTsFile.js +33 -0
- package/documentation/utils/dist/moduleResolver.d.ts +9 -0
- package/documentation/utils/dist/moduleResolver.d.ts.map +1 -0
- package/documentation/utils/dist/moduleResolver.js +27 -0
- package/documentation/utils/dist/serverTypes.d.ts +307 -0
- package/documentation/utils/dist/serverTypes.d.ts.map +1 -0
- package/documentation/utils/dist/serverTypes.js +347 -0
- package/documentation/utils/generateClientDocs.ts +142 -0
- package/documentation/utils/generateDocs.ts +4 -0
- package/documentation/utils/generateServerDocs.ts +82 -0
- package/documentation/utils/getResolvedTypes.ts +45 -0
- package/documentation/utils/getSerializableType.ts +479 -0
- package/documentation/utils/loadTsFile.ts +45 -0
- package/documentation/utils/moduleResolver.ts +31 -0
- package/documentation/utils/node_modules/.package-lock.json +67 -0
- package/documentation/utils/node_modules/@types/node/LICENSE +21 -0
- package/documentation/utils/node_modules/@types/node/README.md +15 -0
- package/documentation/utils/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/documentation/utils/node_modules/@types/node/assert.d.ts +1040 -0
- package/documentation/utils/node_modules/@types/node/async_hooks.d.ts +541 -0
- package/documentation/utils/node_modules/@types/node/buffer.buffer.d.ts +385 -0
- package/documentation/utils/node_modules/@types/node/buffer.d.ts +1934 -0
- package/documentation/utils/node_modules/@types/node/child_process.d.ts +1548 -0
- package/documentation/utils/node_modules/@types/node/cluster.d.ts +578 -0
- package/documentation/utils/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
- package/documentation/utils/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/documentation/utils/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
- package/documentation/utils/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/documentation/utils/node_modules/@types/node/console.d.ts +452 -0
- package/documentation/utils/node_modules/@types/node/constants.d.ts +19 -0
- package/documentation/utils/node_modules/@types/node/crypto.d.ts +4519 -0
- package/documentation/utils/node_modules/@types/node/dgram.d.ts +596 -0
- package/documentation/utils/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- package/documentation/utils/node_modules/@types/node/dns/promises.d.ts +477 -0
- package/documentation/utils/node_modules/@types/node/dns.d.ts +864 -0
- package/documentation/utils/node_modules/@types/node/dom-events.d.ts +124 -0
- package/documentation/utils/node_modules/@types/node/domain.d.ts +170 -0
- package/documentation/utils/node_modules/@types/node/events.d.ts +931 -0
- package/documentation/utils/node_modules/@types/node/fs/promises.d.ts +1245 -0
- package/documentation/utils/node_modules/@types/node/fs.d.ts +4317 -0
- package/documentation/utils/node_modules/@types/node/globals.d.ts +468 -0
- package/documentation/utils/node_modules/@types/node/globals.typedarray.d.ts +21 -0
- package/documentation/utils/node_modules/@types/node/http.d.ts +1944 -0
- package/documentation/utils/node_modules/@types/node/http2.d.ts +2555 -0
- package/documentation/utils/node_modules/@types/node/https.d.ts +544 -0
- package/documentation/utils/node_modules/@types/node/index.d.ts +91 -0
- package/documentation/utils/node_modules/@types/node/inspector.d.ts +3696 -0
- package/documentation/utils/node_modules/@types/node/module.d.ts +315 -0
- package/documentation/utils/node_modules/@types/node/net.d.ts +1005 -0
- package/documentation/utils/node_modules/@types/node/os.d.ts +495 -0
- package/documentation/utils/node_modules/@types/node/package.json +220 -0
- package/documentation/utils/node_modules/@types/node/path.d.ts +200 -0
- package/documentation/utils/node_modules/@types/node/perf_hooks.d.ts +934 -0
- package/documentation/utils/node_modules/@types/node/process.d.ts +1879 -0
- package/documentation/utils/node_modules/@types/node/punycode.d.ts +117 -0
- package/documentation/utils/node_modules/@types/node/querystring.d.ts +153 -0
- package/documentation/utils/node_modules/@types/node/readline/promises.d.ts +162 -0
- package/documentation/utils/node_modules/@types/node/readline.d.ts +589 -0
- package/documentation/utils/node_modules/@types/node/repl.d.ts +430 -0
- package/documentation/utils/node_modules/@types/node/sea.d.ts +153 -0
- package/documentation/utils/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/documentation/utils/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/documentation/utils/node_modules/@types/node/stream/web.d.ts +524 -0
- package/documentation/utils/node_modules/@types/node/stream.d.ts +1726 -0
- package/documentation/utils/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/documentation/utils/node_modules/@types/node/test.d.ts +1938 -0
- package/documentation/utils/node_modules/@types/node/timers/promises.d.ts +97 -0
- package/documentation/utils/node_modules/@types/node/timers.d.ts +240 -0
- package/documentation/utils/node_modules/@types/node/tls.d.ts +1217 -0
- package/documentation/utils/node_modules/@types/node/trace_events.d.ts +197 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
- package/documentation/utils/node_modules/@types/node/ts5.6/index.d.ts +91 -0
- package/documentation/utils/node_modules/@types/node/tty.d.ts +208 -0
- package/documentation/utils/node_modules/@types/node/url.d.ts +955 -0
- package/documentation/utils/node_modules/@types/node/util.d.ts +2306 -0
- package/documentation/utils/node_modules/@types/node/v8.d.ts +808 -0
- package/documentation/utils/node_modules/@types/node/vm.d.ts +922 -0
- package/documentation/utils/node_modules/@types/node/wasi.d.ts +181 -0
- package/documentation/utils/node_modules/@types/node/worker_threads.d.ts +694 -0
- package/documentation/utils/node_modules/@types/node/zlib.d.ts +539 -0
- package/documentation/utils/node_modules/undici-types/LICENSE +21 -0
- package/documentation/utils/node_modules/undici-types/README.md +6 -0
- package/documentation/utils/node_modules/undici-types/agent.d.ts +31 -0
- package/documentation/utils/node_modules/undici-types/api.d.ts +43 -0
- package/documentation/utils/node_modules/undici-types/balanced-pool.d.ts +29 -0
- package/documentation/utils/node_modules/undici-types/cache.d.ts +36 -0
- package/documentation/utils/node_modules/undici-types/client.d.ts +108 -0
- package/documentation/utils/node_modules/undici-types/connector.d.ts +34 -0
- package/documentation/utils/node_modules/undici-types/content-type.d.ts +21 -0
- package/documentation/utils/node_modules/undici-types/cookies.d.ts +28 -0
- package/documentation/utils/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
- package/documentation/utils/node_modules/undici-types/dispatcher.d.ts +255 -0
- package/documentation/utils/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
- package/documentation/utils/node_modules/undici-types/errors.d.ts +149 -0
- package/documentation/utils/node_modules/undici-types/eventsource.d.ts +63 -0
- package/documentation/utils/node_modules/undici-types/fetch.d.ts +209 -0
- package/documentation/utils/node_modules/undici-types/file.d.ts +39 -0
- package/documentation/utils/node_modules/undici-types/filereader.d.ts +54 -0
- package/documentation/utils/node_modules/undici-types/formdata.d.ts +108 -0
- package/documentation/utils/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/documentation/utils/node_modules/undici-types/global-origin.d.ts +7 -0
- package/documentation/utils/node_modules/undici-types/handlers.d.ts +15 -0
- package/documentation/utils/node_modules/undici-types/header.d.ts +4 -0
- package/documentation/utils/node_modules/undici-types/index.d.ts +71 -0
- package/documentation/utils/node_modules/undici-types/interceptors.d.ts +15 -0
- package/documentation/utils/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/documentation/utils/node_modules/undici-types/mock-client.d.ts +25 -0
- package/documentation/utils/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/documentation/utils/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/documentation/utils/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/documentation/utils/node_modules/undici-types/package.json +55 -0
- package/documentation/utils/node_modules/undici-types/patch.d.ts +71 -0
- package/documentation/utils/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/documentation/utils/node_modules/undici-types/pool.d.ts +39 -0
- package/documentation/utils/node_modules/undici-types/proxy-agent.d.ts +28 -0
- package/documentation/utils/node_modules/undici-types/readable.d.ts +60 -0
- package/documentation/utils/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/documentation/utils/node_modules/undici-types/retry-handler.d.ts +116 -0
- package/documentation/utils/node_modules/undici-types/util.d.ts +18 -0
- package/documentation/utils/node_modules/undici-types/webidl.d.ts +222 -0
- package/documentation/utils/node_modules/undici-types/websocket.d.ts +152 -0
- package/documentation/utils/package-lock.json +75 -0
- package/documentation/utils/package.json +14 -0
- package/documentation/utils/serverTypes.ts +345 -0
- package/documentation/utils/tsconfig.json +28 -0
- package/examples/full-example-typescript/DBoGenerated.d.ts +2 -2
- package/examples/full-example-typescript/DBoGenerated.ts +2 -2
- package/examples/full-example-typescript/index.ts +39 -45
- package/examples/full-example-vanilla/index.js +51 -53
- package/examples/server/typescript/index.ts +24 -30
- package/lib/DboBuilder/TableHandler/DataValidator.ts +5 -5
- package/lib/DboBuilder/TableHandler/TableHandler.ts +1 -1
- package/lib/DboBuilder/TableHandler/insert.ts +3 -3
- package/lib/DboBuilder/TableHandler/update.ts +106 -48
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +2 -2
- package/lib/DboBuilder/parseUpdateRules.ts +1 -1
- package/lib/Logging.ts +7 -3
- package/lib/Prostgles.ts +209 -142
- package/lib/ProstglesTypes.ts +130 -51
- package/lib/SyncReplication.ts +2 -2
- package/lib/initProstgles.ts +145 -111
- package/lib/utils.ts +4 -5
- package/package.json +3 -2
- package/examples/server/typescript/index.d.ts +0 -2
- package/examples/server/typescript/index.d.ts.map +0 -1
- package/examples/server/typescript/index.js +0 -54
- package/examples/server/typescript/index.js.map +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { isDefined } from "prostgles-types";
|
|
4
|
+
import { getResolvedTypes } from "./getResolvedTypes";
|
|
5
|
+
import { getObjectEntries } from "prostgles-types";
|
|
6
|
+
import { definitions } from "./clientTypes";
|
|
7
|
+
import { TS_Function, TS_Type } from "./getSerializableType";
|
|
8
|
+
|
|
9
|
+
const testFolderPath = `${__dirname}/../../../tests/`;
|
|
10
|
+
const docsFolder = `${__dirname}/../../`;
|
|
11
|
+
|
|
12
|
+
export const generateClientDocs = () => {
|
|
13
|
+
const clientFilePath = path.resolve(
|
|
14
|
+
`${testFolderPath}/client/node_modules/prostgles-client/dist/prostgles.d.ts`
|
|
15
|
+
);
|
|
16
|
+
const excludedTypes = [
|
|
17
|
+
"FullFilter",
|
|
18
|
+
"FullFilter<T, S> | undefined",
|
|
19
|
+
"FieldFilter | undefined",
|
|
20
|
+
"SyncOptions",
|
|
21
|
+
"SyncOneOptions",
|
|
22
|
+
"PG_COLUMN_UDT_DATA_TYPE",
|
|
23
|
+
];
|
|
24
|
+
const { resolvedTypes, visitedMaps } = getResolvedTypes({
|
|
25
|
+
filePath: clientFilePath,
|
|
26
|
+
filter: {
|
|
27
|
+
nodeNames: [
|
|
28
|
+
// "ViewHandlerClient",
|
|
29
|
+
"TableHandlerClient",
|
|
30
|
+
],
|
|
31
|
+
excludedTypes,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const jsonTypes = JSON.stringify(
|
|
36
|
+
[
|
|
37
|
+
...resolvedTypes,
|
|
38
|
+
...visitedMaps
|
|
39
|
+
.flatMap((m) =>
|
|
40
|
+
Array.from(m.values()).map((v) =>
|
|
41
|
+
excludedTypes.includes(v.resolvedType.alias ?? "") ? v.resolvedType : undefined
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
.filter(isDefined),
|
|
45
|
+
] satisfies TS_Type[],
|
|
46
|
+
null,
|
|
47
|
+
2
|
|
48
|
+
);
|
|
49
|
+
fs.writeFileSync(
|
|
50
|
+
`${__dirname}/../clientTypes.ts`,
|
|
51
|
+
[
|
|
52
|
+
`import type { TS_Type } from "./getSerializableType";`,
|
|
53
|
+
`export const definitions = ${jsonTypes} as const satisfies TS_Type[];`,
|
|
54
|
+
].join("\n"),
|
|
55
|
+
{
|
|
56
|
+
encoding: "utf-8",
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const docPath = `${docsFolder}CLIENT.md`;
|
|
61
|
+
generateMDX(docPath);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getAliasWithoutGenerics = (type: TS_Type) => {
|
|
65
|
+
if (type.type === "union") return type.types.map(getAliasWithoutGenerics).join(" | ");
|
|
66
|
+
return type.aliasSymbolescapedName || type.alias;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const generateMDX = (filePath: string) => {
|
|
70
|
+
const tableHandler = definitions[0];
|
|
71
|
+
const mdxContent = getObjectEntries(tableHandler.properties).map(([methodName, _methodInfo]) => {
|
|
72
|
+
const methodInfo = (
|
|
73
|
+
_methodInfo.type === "function" ?
|
|
74
|
+
(_methodInfo as TS_Function)
|
|
75
|
+
// : _methodInfo.type === "union" ? _methodInfo.types.find((t) => t.type === "function")
|
|
76
|
+
: undefined) as TS_Function | undefined;
|
|
77
|
+
if (!methodInfo) return "";
|
|
78
|
+
return [
|
|
79
|
+
`## ${methodName}()`,
|
|
80
|
+
methodInfo.comments ?? "",
|
|
81
|
+
`\`\`\`typescript
|
|
82
|
+
${methodName}: (${methodInfo.arguments
|
|
83
|
+
.map((arg) => `${arg.name}${arg.optional ? "?" : ""}: ${getAliasWithoutGenerics(arg)}`)
|
|
84
|
+
.join(", ")}): ${methodInfo.returnType.aliasSymbolescapedName || methodInfo.returnType.alias}
|
|
85
|
+
\`\`\``,
|
|
86
|
+
`#### Arguments`,
|
|
87
|
+
``,
|
|
88
|
+
...methodInfo.arguments.map((arg) => {
|
|
89
|
+
return renderType(arg, 2, { name: arg.name, optional: arg.optional });
|
|
90
|
+
}),
|
|
91
|
+
`#### Return type`,
|
|
92
|
+
renderType(methodInfo.returnType, 0, undefined),
|
|
93
|
+
].join("\n");
|
|
94
|
+
});
|
|
95
|
+
const result = mdxContent.join("\n\n");
|
|
96
|
+
fs.writeFileSync(filePath, result, { encoding: "utf-8" });
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const renderType = (
|
|
100
|
+
type: TS_Type,
|
|
101
|
+
indent = 2,
|
|
102
|
+
argOrProp: { name: string; optional: boolean } | undefined
|
|
103
|
+
): string => {
|
|
104
|
+
const indentText = " ".repeat(indent);
|
|
105
|
+
const title = `${indentText}${argOrProp?.name ? `- **${argOrProp.name}**: ` : ""}\`${
|
|
106
|
+
type.aliasSymbolescapedName || type.alias
|
|
107
|
+
}\` ${type.comments ? ` - ${removeLineBreaks(type.comments)}` : ""}`;
|
|
108
|
+
if (type.type === "primitive" || type.type === "literal") {
|
|
109
|
+
return title;
|
|
110
|
+
}
|
|
111
|
+
if (type.type === "object") {
|
|
112
|
+
return (
|
|
113
|
+
title +
|
|
114
|
+
`\n` +
|
|
115
|
+
getObjectEntries(type.properties)
|
|
116
|
+
.map(([name, p]) => renderType(p, indent + 2, { name, optional: p.optional }))
|
|
117
|
+
.join("\n")
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (type.type === "promise") {
|
|
122
|
+
const innerType = renderType(type.innerType, indent, argOrProp);
|
|
123
|
+
// if (argOrProp?.name) {
|
|
124
|
+
// return [title, innerType].join("\n");
|
|
125
|
+
// }
|
|
126
|
+
return innerType;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (type.type === "array") {
|
|
130
|
+
return renderType(type.itemType, indent, argOrProp);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return title;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const removeLineBreaks = (str = "") =>
|
|
137
|
+
str
|
|
138
|
+
.split("\n")
|
|
139
|
+
.map((line) => {
|
|
140
|
+
if (!line.trim().endsWith(".")) return `${line}.`;
|
|
141
|
+
})
|
|
142
|
+
.join(" ");
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { getResolvedTypes } from "./getResolvedTypes";
|
|
4
|
+
import { definitions } from "./serverTypes";
|
|
5
|
+
import { getObjectEntries } from "prostgles-types";
|
|
6
|
+
import { TS_Type } from "./getSerializableType";
|
|
7
|
+
|
|
8
|
+
const testFolderPath = `${__dirname}/../../../tests/`;
|
|
9
|
+
const docsFolder = `${__dirname}/../../`;
|
|
10
|
+
|
|
11
|
+
export const generateServerDocs = () => {
|
|
12
|
+
const serverFilePath = path.resolve(
|
|
13
|
+
// `${testFolderPath}/server/node_modules/prostgles-server/dist/DBSchemaBuilder.d.ts` // "DBOFullyTyped",
|
|
14
|
+
`${testFolderPath}/server/node_modules/prostgles-server/dist/ProstglesTypes.d.ts` // "ProstglesInitOptions",
|
|
15
|
+
);
|
|
16
|
+
const {
|
|
17
|
+
resolvedTypes: [ProstglesInitOptions],
|
|
18
|
+
visitedMaps,
|
|
19
|
+
} = getResolvedTypes({
|
|
20
|
+
filePath: serverFilePath,
|
|
21
|
+
filter: {
|
|
22
|
+
nodeNames: [
|
|
23
|
+
"ProstglesInitOptions",
|
|
24
|
+
// "DBOFullyTyped",
|
|
25
|
+
],
|
|
26
|
+
excludedTypes: [],
|
|
27
|
+
maxDepth: 2,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (!ProstglesInitOptions) throw new Error("ProstglesInitOptions not found");
|
|
32
|
+
const prostglesInitOpts = definitions[0];
|
|
33
|
+
const docs = [
|
|
34
|
+
`# Overview`,
|
|
35
|
+
`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.`,
|
|
36
|
+
`### Installation`,
|
|
37
|
+
`To install the package, run:`,
|
|
38
|
+
`\`\`\`bash`,
|
|
39
|
+
`npm install prostgles-server`,
|
|
40
|
+
`\`\`\``,
|
|
41
|
+
`### Configuration`,
|
|
42
|
+
`To get started, you need to provide a configuration object to the server.`,
|
|
43
|
+
``,
|
|
44
|
+
`Basic example:`,
|
|
45
|
+
`\`\`\`typescript`,
|
|
46
|
+
`import prostgles from "prostgles-server";`,
|
|
47
|
+
`import { DBSchemaGenerated } from "./DBSchemaGenerated";`,
|
|
48
|
+
`prostgles<DBSchemaGenerated>({`,
|
|
49
|
+
` dbConnection: {`,
|
|
50
|
+
` host: "localhost",`,
|
|
51
|
+
` port: 5432,`,
|
|
52
|
+
` database: "postgres"`,
|
|
53
|
+
` user: process.env.PRGL_USER,`,
|
|
54
|
+
` password: process.env.PRGL_PWD`,
|
|
55
|
+
` },`,
|
|
56
|
+
` tsGeneratedTypesDir: __dirname,`,
|
|
57
|
+
` onReady: async ({ dbo }) => {`,
|
|
58
|
+
` try {`,
|
|
59
|
+
` await dbo.items.insert({ name: "a" });`,
|
|
60
|
+
` console.log(await dbo.items.find());`,
|
|
61
|
+
` } catch(err) {`,
|
|
62
|
+
` console.error(err)`,
|
|
63
|
+
` }`,
|
|
64
|
+
` },`,
|
|
65
|
+
`});`,
|
|
66
|
+
`\`\`\``,
|
|
67
|
+
`### Configuration options`,
|
|
68
|
+
...getObjectEntries(prostglesInitOpts.properties).map(([propName, prop]) => {
|
|
69
|
+
const title = ` - <strong>${propName}</strong> \`${(prop as TS_Type).aliasSymbolescapedName || (prop as TS_Type).alias}\``;
|
|
70
|
+
const comments = (prop as TS_Type).comments || "";
|
|
71
|
+
if (!comments) return title;
|
|
72
|
+
return [title, ` ` + comments + " "].join("\n");
|
|
73
|
+
}),
|
|
74
|
+
].join("\n");
|
|
75
|
+
|
|
76
|
+
const serverTypesStr = [
|
|
77
|
+
`import type { TS_Type } from "./getSerializableType";`,
|
|
78
|
+
`export const definitions = ${JSON.stringify([ProstglesInitOptions], null, 2)} as const satisfies TS_Type[];`,
|
|
79
|
+
].join("\n");
|
|
80
|
+
fs.writeFileSync(`${docsFolder}/utils/serverTypes.ts`, serverTypesStr, { encoding: "utf-8" });
|
|
81
|
+
fs.writeFileSync(`${docsFolder}SERVER.md`, docs, { encoding: "utf-8" });
|
|
82
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { getSerializableType, TS_Type, VisitedTypesMap } from "./getSerializableType";
|
|
3
|
+
import { loadTsFile } from "./loadTsFile";
|
|
4
|
+
|
|
5
|
+
type Args = {
|
|
6
|
+
filePath: string;
|
|
7
|
+
filter?: {
|
|
8
|
+
nodeNames: string[];
|
|
9
|
+
excludedTypes: string[];
|
|
10
|
+
maxDepth?: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export const getResolvedTypes = ({ filePath, filter }: Args) => {
|
|
14
|
+
const { checker, sourceFile } = loadTsFile(filePath);
|
|
15
|
+
|
|
16
|
+
const results: TS_Type[] = [];
|
|
17
|
+
const visitedMaps: VisitedTypesMap[] = [];
|
|
18
|
+
|
|
19
|
+
const visit = (node: ts.Node) => {
|
|
20
|
+
// const nodeText = node.getText();
|
|
21
|
+
// if (nodeText.includes("DBOFullyTyped")) {
|
|
22
|
+
// console.log("node.name.text", node.getText());
|
|
23
|
+
// }
|
|
24
|
+
if (ts.isTypeAliasDeclaration(node)) {
|
|
25
|
+
if (!filter || filter?.nodeNames.includes(node.name.text)) {
|
|
26
|
+
const type1 = checker.getTypeAtLocation(node.type);
|
|
27
|
+
const { resolvedType, visited } = getSerializableType(
|
|
28
|
+
type1,
|
|
29
|
+
checker,
|
|
30
|
+
undefined,
|
|
31
|
+
[],
|
|
32
|
+
filter,
|
|
33
|
+
0
|
|
34
|
+
);
|
|
35
|
+
results.push(resolvedType);
|
|
36
|
+
visitedMaps.push(visited);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ts.forEachChild(node, visit);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
visit(sourceFile);
|
|
44
|
+
return { resolvedTypes: results, visitedMaps };
|
|
45
|
+
};
|