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,9 +1,8 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import { isDefined } from "prostgles-types";
|
|
4
|
-
import { getResolvedTypes } from "./getResolvedTypes";
|
|
5
|
-
import { getObjectEntries } from "prostgles-types";
|
|
3
|
+
import { getObjectEntries, isDefined, TableHandler } from "prostgles-types";
|
|
6
4
|
import { definitions } from "./clientTypes";
|
|
5
|
+
import { getResolvedTypes } from "./getResolvedTypes";
|
|
7
6
|
import { TS_Function, TS_Type } from "./getSerializableType";
|
|
8
7
|
|
|
9
8
|
const testFolderPath = `${__dirname}/../../../tests/`;
|
|
@@ -14,8 +13,8 @@ export const generateClientDocs = () => {
|
|
|
14
13
|
`${testFolderPath}/client/node_modules/prostgles-client/dist/prostgles.d.ts`
|
|
15
14
|
);
|
|
16
15
|
const excludedTypes = [
|
|
17
|
-
"FullFilter",
|
|
18
|
-
"FullFilter<T, S> | undefined",
|
|
16
|
+
// "FullFilter",
|
|
17
|
+
// "FullFilter<T, S> | undefined",
|
|
19
18
|
"FieldFilter | undefined",
|
|
20
19
|
"SyncOptions",
|
|
21
20
|
"SyncOneOptions",
|
|
@@ -24,10 +23,7 @@ export const generateClientDocs = () => {
|
|
|
24
23
|
const { resolvedTypes, visitedMaps } = getResolvedTypes({
|
|
25
24
|
filePath: clientFilePath,
|
|
26
25
|
filter: {
|
|
27
|
-
nodeNames: [
|
|
28
|
-
// "ViewHandlerClient",
|
|
29
|
-
"TableHandlerClient",
|
|
30
|
-
],
|
|
26
|
+
nodeNames: ["TableHandlerClient"],
|
|
31
27
|
excludedTypes,
|
|
32
28
|
},
|
|
33
29
|
});
|
|
@@ -57,8 +53,51 @@ export const generateClientDocs = () => {
|
|
|
57
53
|
}
|
|
58
54
|
);
|
|
59
55
|
|
|
60
|
-
const docPath = `${docsFolder}
|
|
61
|
-
|
|
56
|
+
const docPath = `${docsFolder}METHODS.md`;
|
|
57
|
+
|
|
58
|
+
const tableHandler = definitions[0];
|
|
59
|
+
const isomotphicMethodNames = {
|
|
60
|
+
count: 1,
|
|
61
|
+
delete: 1,
|
|
62
|
+
find: 1,
|
|
63
|
+
insert: 1,
|
|
64
|
+
update: 1,
|
|
65
|
+
findOne: 1,
|
|
66
|
+
getColumns: 1,
|
|
67
|
+
getInfo: 1,
|
|
68
|
+
size: 1,
|
|
69
|
+
subscribe: 1,
|
|
70
|
+
subscribeOne: 1,
|
|
71
|
+
updateBatch: 1,
|
|
72
|
+
upsert: 1,
|
|
73
|
+
} satisfies Record<keyof TableHandler, 1>;
|
|
74
|
+
|
|
75
|
+
const isomorphicMd = getMethodsDocs(
|
|
76
|
+
getObjectEntries(tableHandler.properties).filter(
|
|
77
|
+
([methodName]) => isomotphicMethodNames[methodName]
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
const clientMd = getMethodsDocs(
|
|
81
|
+
getObjectEntries(tableHandler.properties).filter(
|
|
82
|
+
([methodName]) => !isomotphicMethodNames[methodName]
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const result = [
|
|
87
|
+
`# Isomorphic Methods`,
|
|
88
|
+
``,
|
|
89
|
+
`The following methods are available on the client and server.`,
|
|
90
|
+
``,
|
|
91
|
+
isomorphicMd.join("\n\n"),
|
|
92
|
+
|
|
93
|
+
`# Client Methods`,
|
|
94
|
+
``,
|
|
95
|
+
`The following methods are available on the client.`,
|
|
96
|
+
``,
|
|
97
|
+
clientMd.join("\n\n"),
|
|
98
|
+
].join("\n");
|
|
99
|
+
|
|
100
|
+
fs.writeFileSync(docPath, result, { encoding: "utf-8" });
|
|
62
101
|
};
|
|
63
102
|
|
|
64
103
|
const getAliasWithoutGenerics = (type: TS_Type) => {
|
|
@@ -66,45 +105,65 @@ const getAliasWithoutGenerics = (type: TS_Type) => {
|
|
|
66
105
|
return type.aliasSymbolescapedName || type.alias;
|
|
67
106
|
};
|
|
68
107
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const mdxContent = getObjectEntries(tableHandler.properties).map(([methodName, _methodInfo]) => {
|
|
108
|
+
const getMethodsDocs = (methods: [name: string, TS_Type][]) => {
|
|
109
|
+
return methods.map(([methodName, _methodInfo]) => {
|
|
72
110
|
const methodInfo = (
|
|
73
111
|
_methodInfo.type === "function" ?
|
|
74
112
|
(_methodInfo as TS_Function)
|
|
75
113
|
// : _methodInfo.type === "union" ? _methodInfo.types.find((t) => t.type === "function")
|
|
76
114
|
: undefined) as TS_Function | undefined;
|
|
77
115
|
if (!methodInfo) return "";
|
|
116
|
+
const args = `${methodInfo.arguments
|
|
117
|
+
.map((arg) => `${arg.name}${arg.optional ? "?" : ""}: ${getAliasWithoutGenerics(arg)}`)
|
|
118
|
+
.join(", ")}`;
|
|
119
|
+
const rType = `${methodInfo.returnType.aliasSymbolescapedName || methodInfo.returnType.alias}`
|
|
120
|
+
.replaceAll("<", "<")
|
|
121
|
+
.replaceAll(">", ">");
|
|
78
122
|
return [
|
|
79
|
-
`## ${methodName}()
|
|
123
|
+
`## ${methodName}<span style="opacity: 0.6;">(${args}): ${rType}</span>`,
|
|
80
124
|
methodInfo.comments ?? "",
|
|
81
|
-
`\`\`\`typescript
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
\`\`\``,
|
|
86
|
-
`#### Arguments`,
|
|
125
|
+
`\`\`\`typescript`,
|
|
126
|
+
`${methodName}: (): `,
|
|
127
|
+
`\`\`\``,
|
|
128
|
+
`#### Parameters`,
|
|
87
129
|
``,
|
|
88
130
|
...methodInfo.arguments.map((arg) => {
|
|
89
131
|
return renderType(arg, 2, { name: arg.name, optional: arg.optional });
|
|
90
132
|
}),
|
|
91
|
-
`#### Return type`,
|
|
92
|
-
renderType(methodInfo.returnType, 0, undefined),
|
|
133
|
+
// `#### Return type`,
|
|
134
|
+
`#### ` + renderType(methodInfo.returnType, 0, undefined),
|
|
93
135
|
].join("\n");
|
|
94
136
|
});
|
|
95
|
-
const result = mdxContent.join("\n\n");
|
|
96
|
-
fs.writeFileSync(filePath, result, { encoding: "utf-8" });
|
|
97
137
|
};
|
|
98
138
|
|
|
139
|
+
const renderedAliases = new Set<string>();
|
|
99
140
|
const renderType = (
|
|
100
141
|
type: TS_Type,
|
|
101
142
|
indent = 2,
|
|
102
143
|
argOrProp: { name: string; optional: boolean } | undefined
|
|
103
144
|
): string => {
|
|
104
145
|
const indentText = " ".repeat(indent);
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
146
|
+
const typeAlias = `\`${type.aliasSymbolescapedName || type.alias}\``;
|
|
147
|
+
const typeText =
|
|
148
|
+
type.aliasSymbolescapedName && type.type === "object" ?
|
|
149
|
+
`<span style="color: green;">${type.aliasSymbolescapedName}</span>`
|
|
150
|
+
: typeAlias;
|
|
151
|
+
const title = [
|
|
152
|
+
`${indentText}${argOrProp?.name ? `- **${argOrProp.name}**: ` : ""}${typeAlias}`,
|
|
153
|
+
`${type.comments ? `${removeLineBreaks(type.comments, indentText + " ")}` : ""}`,
|
|
154
|
+
].join("\n\n");
|
|
155
|
+
|
|
156
|
+
if (typeAlias?.includes("FullFilter")) {
|
|
157
|
+
// debugger;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Re-use rendered types by linking them through an anchor tag
|
|
161
|
+
*/
|
|
162
|
+
if (type.aliasSymbolescapedName && argOrProp?.name) {
|
|
163
|
+
renderedAliases.add(type.aliasSymbolescapedName);
|
|
164
|
+
console.log(type.aliasSymbolescapedName);
|
|
165
|
+
}
|
|
166
|
+
|
|
108
167
|
if (type.type === "primitive" || type.type === "literal") {
|
|
109
168
|
return title;
|
|
110
169
|
}
|
|
@@ -133,10 +192,19 @@ const renderType = (
|
|
|
133
192
|
return title;
|
|
134
193
|
};
|
|
135
194
|
|
|
136
|
-
const removeLineBreaks = (str
|
|
195
|
+
const removeLineBreaks = (str: string, indent: string) =>
|
|
137
196
|
str
|
|
138
197
|
.split("\n")
|
|
139
198
|
.map((line) => {
|
|
140
|
-
|
|
199
|
+
return `${indent}${line.trimStart()}`;
|
|
141
200
|
})
|
|
142
|
-
.join("
|
|
201
|
+
.join("\n");
|
|
202
|
+
|
|
203
|
+
const renderTypeAlias = (type: TS_Type) => {
|
|
204
|
+
const typeAlias = type.aliasSymbolescapedName || type.alias;
|
|
205
|
+
const style = type.aliasSymbolescapedName ? `style="color: green;"` : "";
|
|
206
|
+
// if (renderedAliases.has(typeAlias)) {
|
|
207
|
+
// return `<a ${style} href="#${typeAlias}">${typeAlias}</a>`;
|
|
208
|
+
// }
|
|
209
|
+
return `<span ${style}>${typeAlias}</span>`;
|
|
210
|
+
};
|
|
@@ -15,7 +15,6 @@ export const generateServerDocs = () => {
|
|
|
15
15
|
);
|
|
16
16
|
const {
|
|
17
17
|
resolvedTypes: [ProstglesInitOptions],
|
|
18
|
-
visitedMaps,
|
|
19
18
|
} = getResolvedTypes({
|
|
20
19
|
filePath: serverFilePath,
|
|
21
20
|
filter: {
|
|
@@ -28,8 +27,15 @@ export const generateServerDocs = () => {
|
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const serverTypesStr = [
|
|
31
|
+
`import type { TS_Type } from "./getSerializableType";`,
|
|
32
|
+
`export const definitions = ${JSON.stringify([ProstglesInitOptions], null, 2)} as const satisfies TS_Type[];`,
|
|
33
|
+
].join("\n");
|
|
34
|
+
fs.writeFileSync(`${docsFolder}/utils/serverTypes.ts`, serverTypesStr, { encoding: "utf-8" });
|
|
35
|
+
|
|
36
|
+
const prostglesInitOpts = (definitions as any)[0];
|
|
37
|
+
if (!ProstglesInitOptions || !prostglesInitOpts)
|
|
38
|
+
throw new Error("ProstglesInitOptions not found");
|
|
33
39
|
const docs = [
|
|
34
40
|
`# Overview`,
|
|
35
41
|
`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.`,
|
|
@@ -44,8 +50,8 @@ export const generateServerDocs = () => {
|
|
|
44
50
|
`Basic example:`,
|
|
45
51
|
`\`\`\`typescript`,
|
|
46
52
|
`import prostgles from "prostgles-server";`,
|
|
47
|
-
`import {
|
|
48
|
-
`prostgles<
|
|
53
|
+
`import { DBGeneratedSchema } from "./DBGeneratedSchema";`,
|
|
54
|
+
`prostgles<DBGeneratedSchema>({`,
|
|
49
55
|
` dbConnection: {`,
|
|
50
56
|
` host: "localhost",`,
|
|
51
57
|
` port: 5432,`,
|
|
@@ -66,6 +72,7 @@ export const generateServerDocs = () => {
|
|
|
66
72
|
`\`\`\``,
|
|
67
73
|
`### Configuration options`,
|
|
68
74
|
...getObjectEntries(prostglesInitOpts.properties).map(([propName, prop]) => {
|
|
75
|
+
//@ts-ignore
|
|
69
76
|
const title = ` - <strong>${propName}</strong> \`${(prop as TS_Type).aliasSymbolescapedName || (prop as TS_Type).alias}\``;
|
|
70
77
|
const comments = (prop as TS_Type).comments || "";
|
|
71
78
|
if (!comments) return title;
|
|
@@ -73,10 +80,5 @@ export const generateServerDocs = () => {
|
|
|
73
80
|
}),
|
|
74
81
|
].join("\n");
|
|
75
82
|
|
|
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
83
|
fs.writeFileSync(`${docsFolder}SERVER.md`, docs, { encoding: "utf-8" });
|
|
82
84
|
};
|
|
@@ -4,8 +4,8 @@ import { AnyObject, isDefined } from "prostgles-types";
|
|
|
4
4
|
type TS_Base = {
|
|
5
5
|
alias?: string;
|
|
6
6
|
aliasSymbolescapedName?: string;
|
|
7
|
-
intersectionParent?: string;
|
|
8
7
|
comments?: string;
|
|
8
|
+
intersectionParent?: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export type TS_Literal = TS_Base & {
|
|
@@ -359,12 +359,22 @@ export const getSerializableType = (
|
|
|
359
359
|
opts,
|
|
360
360
|
depth + 1
|
|
361
361
|
);
|
|
362
|
-
|
|
362
|
+
|
|
363
|
+
if (intersectionType.type === "object") {
|
|
364
|
+
intersectionType.intersectionParent = aliasSymbolescapedName;
|
|
365
|
+
}
|
|
363
366
|
return intersectionType;
|
|
364
367
|
});
|
|
365
368
|
if (intersectionTypes.every((t) => t.type === "object")) {
|
|
366
369
|
const properties = (intersectionTypes as TS_Object[]).reduce((acc, t) => {
|
|
367
|
-
|
|
370
|
+
const propertiesWithParentObject = Object.entries(t.properties).reduce(
|
|
371
|
+
(acc, [k, v]) => ({
|
|
372
|
+
...acc,
|
|
373
|
+
[k]: { ...v, intersectionParent: t.aliasSymbolescapedName },
|
|
374
|
+
}),
|
|
375
|
+
{}
|
|
376
|
+
);
|
|
377
|
+
return { ...acc, ...propertiesWithParentObject };
|
|
368
378
|
}, {});
|
|
369
379
|
return withAlias({
|
|
370
380
|
type: "object",
|
|
@@ -2,10 +2,8 @@ import * as path from "path";
|
|
|
2
2
|
import * as ts from "typescript";
|
|
3
3
|
|
|
4
4
|
export const loadTsFile = (filePath: string) => {
|
|
5
|
-
// Normalize file path
|
|
6
5
|
const absolutePath = path.resolve(filePath);
|
|
7
6
|
|
|
8
|
-
// Create compiler host and program
|
|
9
7
|
const configPath = ts.findConfigFile(
|
|
10
8
|
path.dirname(absolutePath),
|
|
11
9
|
ts.sys.fileExists,
|
|
@@ -16,7 +14,6 @@ export const loadTsFile = (filePath: string) => {
|
|
|
16
14
|
throw new Error("Could not find a valid 'tsconfig.json'.");
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
// Parse the config file
|
|
20
17
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
21
18
|
const parsedConfig = ts.parseJsonConfigFileContent(
|
|
22
19
|
configFile.config,
|
|
@@ -24,7 +21,6 @@ export const loadTsFile = (filePath: string) => {
|
|
|
24
21
|
path.dirname(configPath)
|
|
25
22
|
);
|
|
26
23
|
|
|
27
|
-
// Create program
|
|
28
24
|
const program = ts.createProgram({
|
|
29
25
|
rootNames: [absolutePath],
|
|
30
26
|
options: parsedConfig.options,
|
|
@@ -46,15 +46,10 @@ export const definitions = [
|
|
|
46
46
|
"optional": false,
|
|
47
47
|
"comments": "Called when the prostgles server is ready to accept connections.\nIt waits for auth, tableConfig and other async configurations to complete before executing"
|
|
48
48
|
},
|
|
49
|
-
"dbOptions": {
|
|
50
|
-
"type": "reference",
|
|
51
|
-
"alias": "IDefaults",
|
|
52
|
-
"optional": true
|
|
53
|
-
},
|
|
54
49
|
"tsGeneratedTypesDir": {
|
|
55
50
|
"type": "reference",
|
|
56
51
|
"alias": "string | undefined",
|
|
57
|
-
"comments": "If defined then a `
|
|
52
|
+
"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",
|
|
58
53
|
"optional": true
|
|
59
54
|
},
|
|
60
55
|
"disableRealtime": {
|
|
@@ -295,7 +290,7 @@ export const definitions = [
|
|
|
295
290
|
}
|
|
296
291
|
],
|
|
297
292
|
"optional": true,
|
|
298
|
-
"comments": "If truthy then
|
|
293
|
+
"comments": "If truthy then DBGeneratedSchema.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server"
|
|
299
294
|
},
|
|
300
295
|
"keywords": {
|
|
301
296
|
"type": "reference",
|
|
@@ -310,8 +305,7 @@ export const definitions = [
|
|
|
310
305
|
},
|
|
311
306
|
"fileTable": {
|
|
312
307
|
"type": "reference",
|
|
313
|
-
"alias": "FileTableConfig",
|
|
314
|
-
"aliasSymbolescapedName": "FileTableConfig",
|
|
308
|
+
"alias": "FileTableConfig | undefined",
|
|
315
309
|
"comments": "Enables file storage and serving.\nCurrently supports saving files locally or to AWS S3",
|
|
316
310
|
"optional": true
|
|
317
311
|
},
|