@pgpmjs/core 3.1.0 → 3.1.1
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/esm/roles/index.js +43 -0
- package/package.json +3 -3
- package/roles/index.d.ts +1 -0
- package/roles/index.js +43 -0
package/esm/roles/index.js
CHANGED
|
@@ -9,8 +9,19 @@ function sqlLiteral(value) {
|
|
|
9
9
|
* Generate SQL to create base roles (anonymous, authenticated, administrator).
|
|
10
10
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
|
11
11
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
12
|
+
* @throws Error if roles is undefined or missing required properties
|
|
12
13
|
*/
|
|
13
14
|
export function generateCreateBaseRolesSQL(roles) {
|
|
15
|
+
if (!roles) {
|
|
16
|
+
throw new Error('generateCreateBaseRolesSQL: roles parameter is undefined. ' +
|
|
17
|
+
'Ensure getConnEnvOptions().roles is defined. ' +
|
|
18
|
+
'Check that pgpm.config.js or pgpm.json does not set db.roles to undefined.');
|
|
19
|
+
}
|
|
20
|
+
if (!roles.anonymous || !roles.authenticated || !roles.administrator) {
|
|
21
|
+
throw new Error('generateCreateBaseRolesSQL: roles is missing required properties. ' +
|
|
22
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}, administrator=${roles.administrator}. ` +
|
|
23
|
+
'Ensure all role names are defined in your configuration.');
|
|
24
|
+
}
|
|
14
25
|
const r = {
|
|
15
26
|
anonymous: roles.anonymous,
|
|
16
27
|
authenticated: roles.authenticated,
|
|
@@ -91,6 +102,14 @@ COMMIT;
|
|
|
91
102
|
* @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
|
|
92
103
|
*/
|
|
93
104
|
export function generateCreateUserSQL(username, password, roles, useLocksForRoles = false) {
|
|
105
|
+
if (!roles) {
|
|
106
|
+
throw new Error('generateCreateUserSQL: roles parameter is undefined. ' +
|
|
107
|
+
'Ensure getConnEnvOptions().roles is defined.');
|
|
108
|
+
}
|
|
109
|
+
if (!roles.anonymous || !roles.authenticated) {
|
|
110
|
+
throw new Error('generateCreateUserSQL: roles is missing required properties. ' +
|
|
111
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}.`);
|
|
112
|
+
}
|
|
94
113
|
const r = {
|
|
95
114
|
anonymous: roles.anonymous,
|
|
96
115
|
authenticated: roles.authenticated
|
|
@@ -186,6 +205,22 @@ COMMIT;
|
|
|
186
205
|
* @param connections - Test user credentials from getConnEnvOptions().connections!
|
|
187
206
|
*/
|
|
188
207
|
export function generateCreateTestUsersSQL(roles, connections) {
|
|
208
|
+
if (!roles) {
|
|
209
|
+
throw new Error('generateCreateTestUsersSQL: roles parameter is undefined. ' +
|
|
210
|
+
'Ensure getConnEnvOptions().roles is defined.');
|
|
211
|
+
}
|
|
212
|
+
if (!roles.anonymous || !roles.authenticated || !roles.administrator) {
|
|
213
|
+
throw new Error('generateCreateTestUsersSQL: roles is missing required properties. ' +
|
|
214
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}, administrator=${roles.administrator}.`);
|
|
215
|
+
}
|
|
216
|
+
if (!connections) {
|
|
217
|
+
throw new Error('generateCreateTestUsersSQL: connections parameter is undefined. ' +
|
|
218
|
+
'Ensure getConnEnvOptions().connections is defined.');
|
|
219
|
+
}
|
|
220
|
+
if (!connections.app?.user || !connections.app?.password || !connections.admin?.user || !connections.admin?.password) {
|
|
221
|
+
throw new Error('generateCreateTestUsersSQL: connections is missing required properties. ' +
|
|
222
|
+
'Ensure app.user, app.password, admin.user, and admin.password are defined.');
|
|
223
|
+
}
|
|
189
224
|
const r = {
|
|
190
225
|
anonymous: roles.anonymous,
|
|
191
226
|
authenticated: roles.authenticated,
|
|
@@ -363,6 +398,14 @@ $$;
|
|
|
363
398
|
* @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
|
|
364
399
|
*/
|
|
365
400
|
export function generateRemoveUserSQL(username, roles, useLocksForRoles = false) {
|
|
401
|
+
if (!roles) {
|
|
402
|
+
throw new Error('generateRemoveUserSQL: roles parameter is undefined. ' +
|
|
403
|
+
'Ensure getConnEnvOptions().roles is defined.');
|
|
404
|
+
}
|
|
405
|
+
if (!roles.anonymous || !roles.authenticated) {
|
|
406
|
+
throw new Error('generateRemoveUserSQL: roles is missing required properties. ' +
|
|
407
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}.`);
|
|
408
|
+
}
|
|
366
409
|
const r = {
|
|
367
410
|
anonymous: roles.anonymous,
|
|
368
411
|
authenticated: roles.authenticated
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"makage": "^0.1.9"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@pgpmjs/env": "^2.8.
|
|
50
|
+
"@pgpmjs/env": "^2.8.7",
|
|
51
51
|
"@pgpmjs/logger": "^1.3.5",
|
|
52
52
|
"@pgpmjs/server-utils": "^2.8.8",
|
|
53
53
|
"@pgpmjs/types": "^2.12.6",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"pgsql-parser": "^17.9.2",
|
|
64
64
|
"yanse": "^0.1.8"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "248d4056d3191b71bcab5892ef98b09164de9f7f"
|
|
67
67
|
}
|
package/roles/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { RoleMapping, TestUserCredentials } from '@pgpmjs/types';
|
|
|
3
3
|
* Generate SQL to create base roles (anonymous, authenticated, administrator).
|
|
4
4
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
|
5
5
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
6
|
+
* @throws Error if roles is undefined or missing required properties
|
|
6
7
|
*/
|
|
7
8
|
export declare function generateCreateBaseRolesSQL(roles: RoleMapping): string;
|
|
8
9
|
/**
|
package/roles/index.js
CHANGED
|
@@ -17,8 +17,19 @@ function sqlLiteral(value) {
|
|
|
17
17
|
* Generate SQL to create base roles (anonymous, authenticated, administrator).
|
|
18
18
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
|
19
19
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
20
|
+
* @throws Error if roles is undefined or missing required properties
|
|
20
21
|
*/
|
|
21
22
|
function generateCreateBaseRolesSQL(roles) {
|
|
23
|
+
if (!roles) {
|
|
24
|
+
throw new Error('generateCreateBaseRolesSQL: roles parameter is undefined. ' +
|
|
25
|
+
'Ensure getConnEnvOptions().roles is defined. ' +
|
|
26
|
+
'Check that pgpm.config.js or pgpm.json does not set db.roles to undefined.');
|
|
27
|
+
}
|
|
28
|
+
if (!roles.anonymous || !roles.authenticated || !roles.administrator) {
|
|
29
|
+
throw new Error('generateCreateBaseRolesSQL: roles is missing required properties. ' +
|
|
30
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}, administrator=${roles.administrator}. ` +
|
|
31
|
+
'Ensure all role names are defined in your configuration.');
|
|
32
|
+
}
|
|
22
33
|
const r = {
|
|
23
34
|
anonymous: roles.anonymous,
|
|
24
35
|
authenticated: roles.authenticated,
|
|
@@ -99,6 +110,14 @@ COMMIT;
|
|
|
99
110
|
* @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
|
|
100
111
|
*/
|
|
101
112
|
function generateCreateUserSQL(username, password, roles, useLocksForRoles = false) {
|
|
113
|
+
if (!roles) {
|
|
114
|
+
throw new Error('generateCreateUserSQL: roles parameter is undefined. ' +
|
|
115
|
+
'Ensure getConnEnvOptions().roles is defined.');
|
|
116
|
+
}
|
|
117
|
+
if (!roles.anonymous || !roles.authenticated) {
|
|
118
|
+
throw new Error('generateCreateUserSQL: roles is missing required properties. ' +
|
|
119
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}.`);
|
|
120
|
+
}
|
|
102
121
|
const r = {
|
|
103
122
|
anonymous: roles.anonymous,
|
|
104
123
|
authenticated: roles.authenticated
|
|
@@ -194,6 +213,22 @@ COMMIT;
|
|
|
194
213
|
* @param connections - Test user credentials from getConnEnvOptions().connections!
|
|
195
214
|
*/
|
|
196
215
|
function generateCreateTestUsersSQL(roles, connections) {
|
|
216
|
+
if (!roles) {
|
|
217
|
+
throw new Error('generateCreateTestUsersSQL: roles parameter is undefined. ' +
|
|
218
|
+
'Ensure getConnEnvOptions().roles is defined.');
|
|
219
|
+
}
|
|
220
|
+
if (!roles.anonymous || !roles.authenticated || !roles.administrator) {
|
|
221
|
+
throw new Error('generateCreateTestUsersSQL: roles is missing required properties. ' +
|
|
222
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}, administrator=${roles.administrator}.`);
|
|
223
|
+
}
|
|
224
|
+
if (!connections) {
|
|
225
|
+
throw new Error('generateCreateTestUsersSQL: connections parameter is undefined. ' +
|
|
226
|
+
'Ensure getConnEnvOptions().connections is defined.');
|
|
227
|
+
}
|
|
228
|
+
if (!connections.app?.user || !connections.app?.password || !connections.admin?.user || !connections.admin?.password) {
|
|
229
|
+
throw new Error('generateCreateTestUsersSQL: connections is missing required properties. ' +
|
|
230
|
+
'Ensure app.user, app.password, admin.user, and admin.password are defined.');
|
|
231
|
+
}
|
|
197
232
|
const r = {
|
|
198
233
|
anonymous: roles.anonymous,
|
|
199
234
|
authenticated: roles.authenticated,
|
|
@@ -371,6 +406,14 @@ $$;
|
|
|
371
406
|
* @param useLocksForRoles - Whether to use advisory locks (from getConnEnvOptions().useLocksForRoles)
|
|
372
407
|
*/
|
|
373
408
|
function generateRemoveUserSQL(username, roles, useLocksForRoles = false) {
|
|
409
|
+
if (!roles) {
|
|
410
|
+
throw new Error('generateRemoveUserSQL: roles parameter is undefined. ' +
|
|
411
|
+
'Ensure getConnEnvOptions().roles is defined.');
|
|
412
|
+
}
|
|
413
|
+
if (!roles.anonymous || !roles.authenticated) {
|
|
414
|
+
throw new Error('generateRemoveUserSQL: roles is missing required properties. ' +
|
|
415
|
+
`Got: anonymous=${roles.anonymous}, authenticated=${roles.authenticated}.`);
|
|
416
|
+
}
|
|
374
417
|
const r = {
|
|
375
418
|
anonymous: roles.anonymous,
|
|
376
419
|
authenticated: roles.authenticated
|