prostgles-server 4.2.619 → 4.2.621
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/debug/access-profile-source.patch +14 -0
- package/debug/client-profile-perf.cjs +17 -0
- package/debug/client-publish-types-test.log +16 -0
- package/debug/client-schema-test.log +10 -0
- package/debug/client-schema-types/DBGeneratedSchema.ts +59 -0
- package/debug/client-typecheck.ts +11 -0
- package/debug/profile-perf.cjs +26 -0
- package/debug/prostgles-types-4.0.282.tgz +0 -0
- package/debug/publish-schema-test.log +16 -0
- package/debug/run-client-schema.cjs +3 -0
- package/debug/run-publish-schema.cjs +3 -0
- package/debug/server-lib-tests.log +28 -0
- package/debug/types-pack.log +162 -0
- package/dist/DBSchemaBuilder/DBSchemaBuilder.d.ts +6 -0
- package/dist/DBSchemaBuilder/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/constants.d.ts +2 -0
- package/dist/DBSchemaBuilder/constants.d.ts.map +1 -0
- package/dist/DBSchemaBuilder/constants.js +5 -0
- package/dist/DBSchemaBuilder/constants.js.map +1 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.d.ts +9 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.d.ts.map +1 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.js +97 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.js.map +1 -0
- package/dist/DBSchemaBuilder/getColumnTypescriptDefinition.js +2 -2
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts +3 -1
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.js +7 -5
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.js.map +1 -1
- package/dist/DBSchemaBuilder/getPublishSchemas.d.ts +4 -0
- package/dist/DBSchemaBuilder/getPublishSchemas.d.ts.map +1 -0
- package/dist/DBSchemaBuilder/getPublishSchemas.js +34 -0
- package/dist/DBSchemaBuilder/getPublishSchemas.js.map +1 -0
- package/dist/DboBuilder/DboBuilder.d.ts +5 -8
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +11 -14
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts +1 -1
- package/dist/Prostgles.d.ts +3 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +9 -3
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +3 -2
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +16 -5
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/defineServerFunction.d.ts +5 -3
- package/dist/PublishParser/defineServerFunction.d.ts.map +1 -1
- package/dist/PublishParser/defineServerFunction.js.map +1 -1
- package/dist/PublishParser/getFileTableRules.d.ts +2 -2
- package/dist/PublishParser/getFileTableRules.d.ts.map +1 -1
- package/dist/PublishParser/getFileTableRules.js +2 -2
- package/dist/PublishParser/getFileTableRules.js.map +1 -1
- package/dist/PublishParser/getPublishedTableNames.d.ts +4 -0
- package/dist/PublishParser/getPublishedTableNames.d.ts.map +1 -0
- package/dist/PublishParser/getPublishedTableNames.js +23 -0
- package/dist/PublishParser/getPublishedTableNames.js.map +1 -0
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +2 -13
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.d.ts +13 -6
- package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
- package/dist/PublishParser/validatePublishProfiles.d.ts +7 -0
- package/dist/PublishParser/validatePublishProfiles.d.ts.map +1 -0
- package/dist/PublishParser/validatePublishProfiles.js +27 -0
- package/dist/PublishParser/validatePublishProfiles.js.map +1 -0
- package/dist/SchemaWatch/SchemaWatch.js +1 -1
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/TableHooks/TableHooks.d.ts +7 -5
- package/dist/TableHooks/TableHooks.d.ts.map +1 -1
- package/dist/WebsocketAPI/getClientHandlers.d.ts +3 -3
- package/dist/WebsocketAPI/getClientHandlers.d.ts.map +1 -1
- package/dist/WebsocketAPI/getClientHandlers.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/initProstgles.d.ts +2 -2
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +2 -4
- package/dist/initProstgles.js.map +1 -1
- package/dist/updateConfiguration.d.ts.map +1 -1
- package/dist/updateConfiguration.js +6 -2
- package/dist/updateConfiguration.js.map +1 -1
- package/eslint.config.mjs +1 -1
- package/lib/DBSchemaBuilder/DBSchemaBuilder.ts +10 -0
- package/lib/DBSchemaBuilder/constants.ts +1 -0
- package/lib/DBSchemaBuilder/getClientDBGeneratedSchemas.ts +116 -0
- package/lib/DBSchemaBuilder/getColumnTypescriptDefinition.ts +2 -2
- package/lib/DBSchemaBuilder/getDBGeneratedSchema.ts +11 -4
- package/lib/DBSchemaBuilder/getPublishSchemas.ts +41 -0
- package/lib/DboBuilder/DboBuilder.ts +15 -22
- package/lib/Prostgles.ts +10 -4
- package/lib/PublishParser/PublishParser.ts +25 -5
- package/lib/PublishParser/defineServerFunction.ts +5 -3
- package/lib/PublishParser/getFileTableRules.ts +3 -2
- package/lib/PublishParser/getPublishedTableNames.ts +29 -0
- package/lib/PublishParser/getSchemaFromPublish.ts +2 -17
- package/lib/PublishParser/publishTypesAndUtils.ts +13 -5
- package/lib/PublishParser/validatePublishProfiles.ts +22 -0
- package/lib/SchemaWatch/SchemaWatch.ts +1 -1
- package/lib/TableHooks/TableHooks.ts +14 -7
- package/lib/WebsocketAPI/getClientHandlers.ts +4 -4
- package/lib/index.ts +2 -2
- package/lib/initProstgles.ts +7 -19
- package/lib/updateConfiguration.ts +5 -1
- package/package.json +2 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { validateClientSchemaName } from "../DBSchemaBuilder/getClientDBGeneratedSchemas";
|
|
2
|
+
import type { PublishProfile } from "./publishTypesAndUtils";
|
|
3
|
+
|
|
4
|
+
export const validatePublishProfiles = (profiles: PublishProfile[]) => {
|
|
5
|
+
const names = new Set<string>();
|
|
6
|
+
const userTypes = new Set<string>();
|
|
7
|
+
const entries = profiles.map((profile, index) => {
|
|
8
|
+
const name = profile.name ?? `Publish${index + 1}Schema`;
|
|
9
|
+
validateClientSchemaName(name);
|
|
10
|
+
if (names.has(name)) throw new Error(`Duplicate publish schema name: ${name}`);
|
|
11
|
+
names.add(name);
|
|
12
|
+
if (!profile.userTypes.length) {
|
|
13
|
+
throw new Error(`Publish ${name}: userTypes must not be empty`);
|
|
14
|
+
}
|
|
15
|
+
for (const userType of profile.userTypes) {
|
|
16
|
+
if (userTypes.has(userType)) throw new Error(`Duplicate publish user type: ${userType}`);
|
|
17
|
+
userTypes.add(userType);
|
|
18
|
+
}
|
|
19
|
+
return { ...profile, name };
|
|
20
|
+
});
|
|
21
|
+
return entries;
|
|
22
|
+
};
|
|
@@ -81,7 +81,7 @@ export class SchemaWatch {
|
|
|
81
81
|
console.log("watchSchema: Re-writing TS schema");
|
|
82
82
|
|
|
83
83
|
await this.dboBuilder.prostgles.refreshDBO();
|
|
84
|
-
this.dboBuilder.prostgles.writeDBSchema(true);
|
|
84
|
+
await this.dboBuilder.prostgles.writeDBSchema(true);
|
|
85
85
|
}
|
|
86
86
|
} else {
|
|
87
87
|
/* Full re-init. Sockets must reconnect */
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type pgPromise from "pg-promise";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AnyObject,
|
|
4
|
+
DBSchema,
|
|
5
|
+
InsertDataWithNested,
|
|
6
|
+
} from "prostgles-types";
|
|
3
7
|
|
|
4
8
|
import type { DbTxTableHandlers } from "../DboBuilder/DboBuilderTypes";
|
|
5
9
|
import type { DBOFullyTyped } from "../DBSchemaBuilder/DBSchemaBuilder";
|
|
@@ -10,13 +14,13 @@ import type {
|
|
|
10
14
|
TransactionCallbacks,
|
|
11
15
|
} from "../PublishParser/PublishParser";
|
|
12
16
|
|
|
13
|
-
export type TableHooks<S = void, Context = undefined> =
|
|
14
|
-
|
|
15
|
-
Partial<{
|
|
17
|
+
export type TableHooks<S = void, Context = undefined> = S extends DBSchema
|
|
18
|
+
? Partial<{
|
|
16
19
|
[tableName in keyof S]: TableHooksDefinition<
|
|
17
20
|
Required<S[tableName]["columns"]>,
|
|
18
21
|
DBOFullyTyped<S>,
|
|
19
|
-
Context
|
|
22
|
+
Context,
|
|
23
|
+
InsertDataWithNested<S[tableName]["columns"], S, tableName>
|
|
20
24
|
>;
|
|
21
25
|
}>
|
|
22
26
|
: Record<string, TableHooksDefinition<AnyObject, DbTxTableHandlers, Context>>;
|
|
@@ -25,6 +29,7 @@ export type TableHooksDefinition<
|
|
|
25
29
|
RowDataType = AnyObject,
|
|
26
30
|
DBX = DbTxTableHandlers,
|
|
27
31
|
Context = undefined,
|
|
32
|
+
InputDataType = RowDataType,
|
|
28
33
|
> = {
|
|
29
34
|
/**
|
|
30
35
|
* Runs sequentially before data validation and mutation SQL for each insert row,
|
|
@@ -33,19 +38,21 @@ export type TableHooksDefinition<
|
|
|
33
38
|
* Also runs when generating SQL statements (including updateBatch).
|
|
34
39
|
* File inserts/updates reject SQL-only requests; file updates lock matching rows before hooks.
|
|
35
40
|
* May replace the pending data and pass `hookContext` to the next hook.
|
|
41
|
+
* Data is the raw input, including nested inserts and values awaiting PostgreSQL casts.
|
|
36
42
|
* Register `onCommit`/`onRollback` before starting external work so cleanup also runs if the
|
|
37
43
|
* hook throws. These callbacks are awaited after the outer transaction finishes and receive
|
|
38
44
|
* the non-transactional `db` and `dbo` objects.
|
|
39
45
|
*/
|
|
40
|
-
beforeEach?: BeforeEachTsTrigger<
|
|
46
|
+
beforeEach?: BeforeEachTsTrigger<InputDataType, DBX, Context>[];
|
|
41
47
|
|
|
42
48
|
/**
|
|
43
49
|
* Runs once per affected row after SQL, inside the same transaction.
|
|
44
50
|
* `row` is the inserted/updated row or the deleted row's pre-delete state. Throwing rolls back.
|
|
51
|
+
* `data` is the input for the operation, including the whole array for bulk inserts.
|
|
45
52
|
* Use `onCommit` for side effects that must only run after the transaction commits.
|
|
46
53
|
* Its callback receives the non-transactional `db` and `dbo` objects.
|
|
47
54
|
*/
|
|
48
|
-
afterEach?: AfterEachTsTrigger<RowDataType, DBX, Context>[];
|
|
55
|
+
afterEach?: AfterEachTsTrigger<RowDataType, DBX, Context, InputDataType>[];
|
|
49
56
|
|
|
50
57
|
/**
|
|
51
58
|
* Runs once after all applicable `afterEach` hooks, inside the same transaction.
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type TableHandler,
|
|
8
8
|
} from "prostgles-types";
|
|
9
9
|
import type { AuthClientRequest } from "../Auth/AuthTypes";
|
|
10
|
-
import type {
|
|
10
|
+
import type { DBOFullyTypedClient } from "../DBSchemaBuilder/DBSchemaBuilder";
|
|
11
11
|
import type { Prostgles } from "../Prostgles";
|
|
12
12
|
import type { ServerFunctionDefinition } from "../PublishParser/defineServerFunction";
|
|
13
13
|
import type { PermissionScope } from "../PublishParser/publishTypesAndUtils";
|
|
@@ -16,7 +16,7 @@ import { getClientSchema } from "./getClientSchema";
|
|
|
16
16
|
|
|
17
17
|
export type ClientHandlers<S = void> = {
|
|
18
18
|
clientSql: SQLHandler;
|
|
19
|
-
clientDb:
|
|
19
|
+
clientDb: DBOFullyTypedClient<S>;
|
|
20
20
|
clientMethods: Record<string, ServerFunctionDefinition>;
|
|
21
21
|
clientSchema: ClientSchema;
|
|
22
22
|
};
|
|
@@ -24,7 +24,7 @@ export const getClientHandlers = async <S = void>(
|
|
|
24
24
|
prostgles: Prostgles,
|
|
25
25
|
clientReq: AuthClientRequest,
|
|
26
26
|
scope: PermissionScope | undefined,
|
|
27
|
-
): Promise<ClientHandlers
|
|
27
|
+
): Promise<ClientHandlers<S>> => {
|
|
28
28
|
prostgles.checkNotDestroyed();
|
|
29
29
|
const clientSchema =
|
|
30
30
|
clientReq.socket?.prostgles?.get(prostgles.appId) ??
|
|
@@ -67,7 +67,7 @@ export const getClientHandlers = async <S = void>(
|
|
|
67
67
|
const clientDb = {
|
|
68
68
|
...tableHandlers,
|
|
69
69
|
...txNotAllowed,
|
|
70
|
-
} as
|
|
70
|
+
} as DBOFullyTypedClient<S>;
|
|
71
71
|
|
|
72
72
|
const clientMethods: Record<string, ServerFunctionDefinition> = Object.fromEntries(
|
|
73
73
|
clientSchema.methods.map(({ name, input, description, output }) => {
|
package/lib/index.ts
CHANGED
|
@@ -20,8 +20,8 @@ export const createProstgles = <S = void, SUser extends SessionUser = SessionUse
|
|
|
20
20
|
};
|
|
21
21
|
export * from "./PublishParser/defineServerFunction";
|
|
22
22
|
export * from "./Auth/AuthTypes";
|
|
23
|
-
export type { PublishParams } from "./PublishParser/publishTypesAndUtils";
|
|
24
|
-
export type { DBOFullyTyped } from "./DBSchemaBuilder/DBSchemaBuilder";
|
|
23
|
+
export type { PublishParams, PublishProfile } from "./PublishParser/publishTypesAndUtils";
|
|
24
|
+
export type { DBOFullyTyped, DBOFullyTypedClient } from "./DBSchemaBuilder/DBSchemaBuilder";
|
|
25
25
|
export type { DBHandlerServer } from "./Prostgles";
|
|
26
26
|
export type { StorageClient as CloudClient } from "./StorageClient/StorageClientTypes";
|
|
27
27
|
export * from "./StorageClient/getLocalStorageClient";
|
package/lib/initProstgles.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { getDbConnection } from "./getDbConnection";
|
|
|
12
12
|
import type { DBHandlerServer, Prostgles } from "./Prostgles";
|
|
13
13
|
import { getIsSuperUser } from "./Prostgles";
|
|
14
14
|
import type { ProstglesInitOptions } from "./ProstglesTypes";
|
|
15
|
-
import {
|
|
15
|
+
import type { PermissionScope } from "./PublishParser/PublishParser";
|
|
16
16
|
import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
|
|
17
17
|
import { runSQLFile } from "./TableConfig/runSQLFile";
|
|
18
18
|
import { updateConfiguration, type clientOnlyUpdateKeys } from "./updateConfiguration";
|
|
@@ -92,15 +92,9 @@ export type CreateContextParams<S> = OnReadyParamsCommon & {
|
|
|
92
92
|
dbo: DBOFullyTyped<S>;
|
|
93
93
|
onCleanup: (cleanup: ContextCleanup) => void;
|
|
94
94
|
};
|
|
95
|
-
export type CreateContext<S, Context> = (
|
|
96
|
-
params: CreateContextParams<S>,
|
|
97
|
-
) => MaybePromise<Context>;
|
|
95
|
+
export type CreateContext<S, Context> = (params: CreateContextParams<S>) => MaybePromise<Context>;
|
|
98
96
|
|
|
99
|
-
export type OnReadyCallback<
|
|
100
|
-
S,
|
|
101
|
-
SUser extends SessionUser,
|
|
102
|
-
Context = undefined,
|
|
103
|
-
> = (
|
|
97
|
+
export type OnReadyCallback<S, SUser extends SessionUser, Context = undefined> = (
|
|
104
98
|
params: OnReadyParams<S, Context>,
|
|
105
99
|
update: (newOpts: UpdatableOptions<S, SUser, Context>, force?: true) => Promise<void>,
|
|
106
100
|
) => void | Promise<void>;
|
|
@@ -109,11 +103,7 @@ export type OnReadyCallbackBasic = (
|
|
|
109
103
|
update: (newOpts: UpdatableOptions<void, SessionUser, any>, force?: true) => Promise<void>,
|
|
110
104
|
) => void | Promise<void>;
|
|
111
105
|
|
|
112
|
-
export type InitResult<
|
|
113
|
-
S = void,
|
|
114
|
-
SUser extends SessionUser = SessionUser,
|
|
115
|
-
Context = undefined,
|
|
116
|
-
> = {
|
|
106
|
+
export type InitResult<S = void, SUser extends SessionUser = SessionUser, Context = undefined> = {
|
|
117
107
|
db: DBOFullyTyped<S>;
|
|
118
108
|
context: Context;
|
|
119
109
|
sql: SQLHandler;
|
|
@@ -126,7 +116,7 @@ export type InitResult<
|
|
|
126
116
|
*/
|
|
127
117
|
getTSSchema: typeof DboBuilder.prototype.getTsDefinitions;
|
|
128
118
|
getSchema: typeof DboBuilder.prototype.getSchema;
|
|
129
|
-
reWriteDBSchema: () => void
|
|
119
|
+
reWriteDBSchema: () => Promise<void>;
|
|
130
120
|
update: (newOpts: UpdatableOptions<S, SUser, Context>, force?: true) => Promise<void>;
|
|
131
121
|
restart: () => Promise<InitResult<S, SUser, Context>>;
|
|
132
122
|
options: ProstglesInitOptions<S, SUser, Context>;
|
|
@@ -259,10 +249,8 @@ export const initProstgles = async function (
|
|
|
259
249
|
/* 3.9 Check auth config */
|
|
260
250
|
this.initAuthHandler();
|
|
261
251
|
|
|
262
|
-
this.publishParser = new PublishParser(this);
|
|
263
|
-
this.dboBuilder.publishParser = this.publishParser;
|
|
264
|
-
|
|
265
252
|
/* 4. Set publish and auth listeners */
|
|
253
|
+
this.initPublishParser();
|
|
266
254
|
this.setupSocketIO();
|
|
267
255
|
} else if (this.opts.auth) {
|
|
268
256
|
throw "Auth config does not work without publish";
|
|
@@ -270,7 +258,7 @@ export const initProstgles = async function (
|
|
|
270
258
|
|
|
271
259
|
this.dbEventsManager = new DBEventsManager(db, pgp);
|
|
272
260
|
|
|
273
|
-
this.writeDBSchema();
|
|
261
|
+
await this.writeDBSchema();
|
|
274
262
|
|
|
275
263
|
/* 5. Finish init and provide DBO object */
|
|
276
264
|
try {
|
|
@@ -32,6 +32,9 @@ export const updateConfiguration = async (
|
|
|
32
32
|
if (includes(optionsThatChanged, "schema")) {
|
|
33
33
|
await prgl.refreshDBO();
|
|
34
34
|
}
|
|
35
|
+
if (includes(optionsThatChanged, "publish")) {
|
|
36
|
+
prgl.initPublishParser();
|
|
37
|
+
}
|
|
35
38
|
if (includes(optionsThatChanged, "auth")) {
|
|
36
39
|
prgl.initAuthHandler();
|
|
37
40
|
}
|
|
@@ -42,10 +45,11 @@ export const updateConfiguration = async (
|
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
if (
|
|
48
|
+
includes(optionsThatChanged, "publish") ||
|
|
45
49
|
includes(optionsThatChanged, "tsGeneratedTypesDir") ||
|
|
46
50
|
includes(optionsThatChanged, "tsGeneratedTypesFunctionsPath")
|
|
47
51
|
) {
|
|
48
|
-
prgl.writeDBSchema();
|
|
52
|
+
await prgl.writeDBSchema();
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
if (isEmpty(newOpts)) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.621",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"pg": "^8.23.0",
|
|
58
58
|
"pg-cursor": "^2.22.0",
|
|
59
59
|
"pg-promise": "^12.7.1",
|
|
60
|
-
"prostgles-types": "^4.0.
|
|
60
|
+
"prostgles-types": "^4.0.284"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.22.0",
|