prostgles-server 4.2.180 → 4.2.181
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/package.json +1 -1
- 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
package/lib/initProstgles.ts
CHANGED
|
@@ -99,9 +99,9 @@ export const initProstgles = async function (
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const conObj =
|
|
102
|
-
typeof this.opts.dbConnection === "string"
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
typeof this.opts.dbConnection === "string" ?
|
|
103
|
+
{ connectionString: this.opts.dbConnection }
|
|
104
|
+
: this.opts.dbConnection;
|
|
105
105
|
const application_name = `prostgles ${this.appId} ${existingAppName}`;
|
|
106
106
|
|
|
107
107
|
/* 1. Connect to db */
|
|
@@ -262,64 +262,63 @@ export const initProstgles = async function (
|
|
|
262
262
|
|
|
263
263
|
type GetDbConnectionArgs = Pick<
|
|
264
264
|
ProstglesInitOptions,
|
|
265
|
-
"DEBUG_MODE" | "onQuery" | "dbConnection" | "
|
|
265
|
+
"DEBUG_MODE" | "onQuery" | "dbConnection" | "onNotice"
|
|
266
266
|
>;
|
|
267
267
|
const getDbConnection = function ({
|
|
268
268
|
dbConnection,
|
|
269
269
|
onQuery,
|
|
270
270
|
DEBUG_MODE,
|
|
271
|
-
dbOptions,
|
|
272
271
|
onNotice,
|
|
273
272
|
}: GetDbConnectionArgs): { db: DB; pgp: PGP } {
|
|
274
273
|
const onQueryOrError:
|
|
275
274
|
| undefined
|
|
276
275
|
| ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) =
|
|
277
|
-
!onQuery && !DEBUG_MODE
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
276
|
+
!onQuery && !DEBUG_MODE ?
|
|
277
|
+
undefined
|
|
278
|
+
: (error, ctx) => {
|
|
279
|
+
if (onQuery) {
|
|
280
|
+
onQuery(error, ctx);
|
|
281
|
+
} else if (DEBUG_MODE) {
|
|
282
|
+
if (error) {
|
|
283
|
+
console.error(error, ctx);
|
|
284
|
+
} else {
|
|
285
|
+
console.log(ctx);
|
|
288
286
|
}
|
|
289
|
-
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
290
289
|
|
|
291
290
|
const pgp: PGP = pgPromise({
|
|
292
|
-
...(onQueryOrError
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
...(onNotice || DEBUG_MODE
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
291
|
+
...(onQueryOrError ?
|
|
292
|
+
{
|
|
293
|
+
query: (ctx) => onQueryOrError(undefined, ctx),
|
|
294
|
+
error: onQueryOrError,
|
|
295
|
+
}
|
|
296
|
+
: {}),
|
|
297
|
+
...(onNotice || DEBUG_MODE ?
|
|
298
|
+
{
|
|
299
|
+
connect: function ({ client, useCount }) {
|
|
300
|
+
const isFresh = !useCount;
|
|
301
|
+
if (isFresh && !client.listeners("notice").length) {
|
|
302
|
+
client.on("notice", function (msg) {
|
|
303
|
+
if (onNotice) {
|
|
304
|
+
onNotice(msg, msg?.message);
|
|
305
|
+
} else {
|
|
306
|
+
console.log("notice: %j", msg?.message);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (isFresh && !client.listeners("error").length) {
|
|
311
|
+
client.on("error", function (msg) {
|
|
312
|
+
if (onNotice) {
|
|
313
|
+
onNotice(msg, msg?.message);
|
|
314
|
+
} else {
|
|
315
|
+
console.log("error: %j", msg?.message);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
}
|
|
321
|
+
: {}),
|
|
323
322
|
});
|
|
324
323
|
// pgp.pg.defaults.max = 70;
|
|
325
324
|
|
|
@@ -340,9 +339,9 @@ const getDbConnection = function ({
|
|
|
340
339
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
|
|
341
340
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
|
|
342
341
|
|
|
343
|
-
if (dbOptions) {
|
|
344
|
-
|
|
345
|
-
}
|
|
342
|
+
// if (dbOptions) {
|
|
343
|
+
// Object.assign(pgp.pg.defaults, dbOptions);
|
|
344
|
+
// }
|
|
346
345
|
|
|
347
346
|
return {
|
|
348
347
|
db: pgp(dbConnection),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type DBGeneratedSchema = {
|
|
2
2
|
items: {
|
|
3
3
|
is_view: false;
|
|
4
4
|
select: true;
|
|
@@ -188,20 +188,25 @@ export type DBSchemaGenerated = {
|
|
|
188
188
|
update: true;
|
|
189
189
|
delete: true;
|
|
190
190
|
columns: {
|
|
191
|
-
colOneOf: "a" | "b" | "c"
|
|
192
|
-
json: {
|
|
193
|
-
|
|
194
|
-
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
191
|
+
colOneOf: "a" | "b" | "c";
|
|
192
|
+
json: {
|
|
193
|
+
a: boolean;
|
|
194
|
+
arr: "1" | "2" | "3";
|
|
195
|
+
arr1: 1 | 2 | 3;
|
|
196
|
+
arr2: number[];
|
|
197
|
+
arrStr?: null | string[];
|
|
198
|
+
o?: null | { o1: number } | { o2: boolean };
|
|
199
|
+
};
|
|
200
|
+
jsonOneOf?: null | { command: "a" } | { command: "b"; option: number[] };
|
|
201
|
+
status?:
|
|
202
|
+
| null
|
|
203
|
+
| { ok: string }
|
|
204
|
+
| { err: string }
|
|
205
|
+
| { loading: { loaded: number; total: number } };
|
|
206
|
+
table_config?: null | {
|
|
207
|
+
referencedTables?: { name: string; minFiles: number }[];
|
|
208
|
+
recType?: null | Record<"a" | "b", { bools: boolean[] }>;
|
|
209
|
+
};
|
|
205
210
|
};
|
|
206
211
|
};
|
|
207
212
|
tr1: {
|
|
@@ -261,8 +266,8 @@ export type DBSchemaGenerated = {
|
|
|
261
266
|
columns: {
|
|
262
267
|
email: string;
|
|
263
268
|
id?: number;
|
|
264
|
-
preferences: {
|
|
265
|
-
status: "active" | "disabled" | "pending"
|
|
269
|
+
preferences: { showIntro?: boolean; theme?: "light" | "dark" | "auto"; others: any[] };
|
|
270
|
+
status: "active" | "disabled" | "pending";
|
|
266
271
|
};
|
|
267
272
|
};
|
|
268
273
|
users_public_info: {
|
|
@@ -316,5 +321,4 @@ export type DBSchemaGenerated = {
|
|
|
316
321
|
tsv?: null | string;
|
|
317
322
|
};
|
|
318
323
|
};
|
|
319
|
-
|
|
320
|
-
}
|
|
324
|
+
};
|
|
@@ -2,7 +2,7 @@ import { ViewHandler } from "prostgles-types";
|
|
|
2
2
|
import type { DBOFullyTyped } from "../DBSchemaBuilder";
|
|
3
3
|
import type { DBHandlerServer } from "../DboBuilder/DboBuilder";
|
|
4
4
|
import { Publish } from "../PublishParser/PublishParser";
|
|
5
|
-
import {
|
|
5
|
+
import { DBGeneratedSchema } from "./DBoGenerated";
|
|
6
6
|
|
|
7
7
|
type DBSchema2 = {
|
|
8
8
|
tr2: {
|
|
@@ -18,24 +18,27 @@ type DBSchema2 = {
|
|
|
18
18
|
tr1_id?: null | number;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
}
|
|
22
|
-
export const testDboTypes =
|
|
23
|
-
|
|
21
|
+
};
|
|
22
|
+
export const testDboTypes = () => {
|
|
23
|
+
async () => {
|
|
24
24
|
const dbo = {} as DBOFullyTyped;
|
|
25
25
|
dbo.someTable?.find;
|
|
26
26
|
|
|
27
27
|
const dbo1 = {} as DBHandlerServer;
|
|
28
28
|
dbo1.w?.find;
|
|
29
29
|
|
|
30
|
-
const db = {} as DBOFullyTyped<
|
|
30
|
+
const db = {} as DBOFullyTyped<DBGeneratedSchema>;
|
|
31
31
|
db.items2.find;
|
|
32
32
|
|
|
33
|
-
const r = await db.items2.find(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
id: 1,
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const r = await db.items2.find(
|
|
34
|
+
{},
|
|
35
|
+
{
|
|
36
|
+
select: { id: 1 },
|
|
37
|
+
orderBy: {
|
|
38
|
+
id: 1,
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
);
|
|
39
42
|
|
|
40
43
|
r[0]?.id;
|
|
41
44
|
|
|
@@ -43,39 +46,50 @@ export const testDboTypes = () => {
|
|
|
43
46
|
r[0]?.bad_col;
|
|
44
47
|
|
|
45
48
|
const tr2 = {} as ViewHandler<DBSchema2["tr2"]["columns"], DBSchema2>;
|
|
46
|
-
tr2.find(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
tr2.find(
|
|
50
|
+
{},
|
|
51
|
+
{
|
|
52
|
+
select: { id: 1 },
|
|
53
|
+
orderBy: { tr1_id: 1 },
|
|
54
|
+
}
|
|
55
|
+
);
|
|
50
56
|
|
|
51
|
-
tr2.find(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
tr2.find(
|
|
58
|
+
{},
|
|
59
|
+
{
|
|
60
|
+
//@ts-expect-error
|
|
61
|
+
select: { bad_col: 1 },
|
|
62
|
+
}
|
|
63
|
+
);
|
|
55
64
|
|
|
56
|
-
tr2.find(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
tr2.find(
|
|
66
|
+
{},
|
|
67
|
+
{
|
|
68
|
+
//@ts-expect-error
|
|
69
|
+
orderBy: { bad_col: 1 },
|
|
70
|
+
}
|
|
71
|
+
);
|
|
60
72
|
|
|
61
|
-
(await db.items2.find({}, { select: { items_id: 1 }, returnType: "values" })) satisfies (
|
|
62
|
-
|
|
73
|
+
(await db.items2.find({}, { select: { items_id: 1 }, returnType: "values" })) satisfies (
|
|
74
|
+
| number
|
|
75
|
+
| null
|
|
76
|
+
)[];
|
|
63
77
|
|
|
64
|
-
const publish: Publish<
|
|
78
|
+
const publish: Publish<DBGeneratedSchema> = {
|
|
65
79
|
items: {
|
|
66
80
|
insert: {
|
|
67
|
-
fields: {
|
|
68
|
-
name: 1,
|
|
81
|
+
fields: {
|
|
82
|
+
name: 1,
|
|
69
83
|
//@ts-expect-error
|
|
70
|
-
bad_col: 1
|
|
84
|
+
bad_col: 1,
|
|
71
85
|
},
|
|
72
86
|
validate: async (row) => ({
|
|
73
87
|
...row,
|
|
74
|
-
h: [""]
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
}
|
|
88
|
+
h: [""],
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
78
92
|
};
|
|
79
93
|
publish;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
94
|
+
};
|
|
95
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.181",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"test-only": "cd tests/ && ./test.sh",
|
|
16
16
|
"test-quick": "cd tests/ && ./test.sh -quick",
|
|
17
17
|
"test": "rm -rf ./node_modules/* && rm -rf ./dist/* && npm i && npm run lint && npm run test-only",
|
|
18
|
-
"
|
|
18
|
+
"generate-docs": "rm -f ./documentation/*.md && cd documentation/utils && npm start",
|
|
19
|
+
"pushpublish": "npm run generate-docs && npm version patch --git-tag-version false && git push && npm publish"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"pg": "^8.11.5",
|
|
55
56
|
"pg-cursor": "^2.11.0",
|
|
56
57
|
"pg-promise": "^11.9.1",
|
|
57
|
-
"prostgles-types": "^4.0.
|
|
58
|
+
"prostgles-types": "^4.0.119"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@types/express": "^4.17.21",
|