@geekmidas/db 9.0.2 → 10.0.0-alpha.0
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/dist/errors-CfFCan-X.mjs +69 -0
- package/dist/errors-CfFCan-X.mjs.map +1 -0
- package/dist/errors-Cs5jlAv-.cjs +93 -0
- package/dist/errors-Cs5jlAv-.cjs.map +1 -0
- package/dist/errors.cjs +6 -0
- package/dist/errors.d.cts +53 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +53 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +3 -0
- package/dist/kysely/pagination.cjs +1 -1
- package/dist/kysely/pagination.d.mts +1 -1
- package/dist/kysely/pagination.mjs +1 -1
- package/dist/{kysely-Dm1w5gAY.d.mts → kysely-BAedYsvn.d.mts} +1 -1
- package/dist/{kysely-Dm1w5gAY.d.mts.map → kysely-BAedYsvn.d.mts.map} +1 -1
- package/dist/{kysely-DmfA94RY.mjs → kysely-Bo_Zg-D3.mjs} +1 -1
- package/dist/{kysely-DmfA94RY.mjs.map → kysely-Bo_Zg-D3.mjs.map} +1 -1
- package/dist/{kysely-8WPSKCZG.cjs → kysely-LWvS2ekY.cjs} +1 -1
- package/dist/{kysely-8WPSKCZG.cjs.map → kysely-LWvS2ekY.cjs.map} +1 -1
- package/dist/kysely.cjs +1 -1
- package/dist/kysely.d.mts +1 -1
- package/dist/kysely.mjs +1 -1
- package/dist/objection/pagination.cjs +1 -1
- package/dist/objection/pagination.d.mts +1 -1
- package/dist/objection/pagination.mjs +1 -1
- package/dist/{pagination-Bdoa4PVj.cjs → pagination-Bu1dqOy0.cjs} +1 -1
- package/dist/{pagination-Bdoa4PVj.cjs.map → pagination-Bu1dqOy0.cjs.map} +1 -1
- package/dist/{pagination-BDLa7Yb_.mjs → pagination-CQ8QHXaL.mjs} +1 -1
- package/dist/{pagination-BDLa7Yb_.mjs.map → pagination-CQ8QHXaL.mjs.map} +1 -1
- package/dist/{pagination-BziGl-B8.d.mts → pagination-kv-KWS-7.d.mts} +1 -1
- package/dist/{pagination-BziGl-B8.d.mts.map → pagination-kv-KWS-7.d.mts.map} +1 -1
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.mts +1 -1
- package/dist/pagination.mjs +1 -1
- package/dist/pg/roles.cjs +154 -0
- package/dist/pg/roles.cjs.map +1 -0
- package/dist/pg/roles.d.cts +82 -0
- package/dist/pg/roles.d.cts.map +1 -0
- package/dist/pg/roles.d.mts +82 -0
- package/dist/pg/roles.d.mts.map +1 -0
- package/dist/pg/roles.mjs +150 -0
- package/dist/pg/roles.mjs.map +1 -0
- package/dist/pg/url.cjs +33 -0
- package/dist/pg/url.cjs.map +1 -0
- package/dist/pg/url.d.cts +47 -0
- package/dist/pg/url.d.cts.map +1 -0
- package/dist/pg/url.d.mts +47 -0
- package/dist/pg/url.d.mts.map +1 -0
- package/dist/pg/url.mjs +33 -0
- package/dist/pg/url.mjs.map +1 -0
- package/dist/rls.cjs +1 -1
- package/dist/rls.d.mts +1 -1
- package/dist/rls.mjs +1 -1
- package/package.json +34 -1
- package/CHANGELOG.md +0 -65
- package/src/__tests__/kysely.integration.spec.ts +0 -741
- package/src/__tests__/kysely.spec.ts +0 -394
- package/src/__tests__/rls.spec.ts +0 -716
- package/src/kysely/__tests__/pagination.integration.spec.ts +0 -341
- package/src/kysely/pagination.ts +0 -113
- package/src/kysely.ts +0 -33
- package/src/objection/__tests__/pagination.integration.spec.ts +0 -291
- package/src/objection/pagination.ts +0 -98
- package/src/pagination.ts +0 -49
- package/src/rls.ts +0 -90
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Database URL errors and redaction — engine-neutral.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here is Postgres-specific: every engine addresses itself as a URL
|
|
6
|
+
* carrying a password, and "must name a host" holds for all of them. The parts
|
|
7
|
+
* that differ — libpq's `options=-c search_path=…`, which no other engine
|
|
8
|
+
* accepts — live under the driver they belong to.
|
|
9
|
+
*
|
|
10
|
+
* Messages state the rule, which is constant; the offending value is a field.
|
|
11
|
+
* An interpolated message cannot be matched on and carries user input into
|
|
12
|
+
* every log line that touches it.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Replace the password in a connection string with `***`.
|
|
16
|
+
*
|
|
17
|
+
* A connection string is a secret, and the places it is most likely to be
|
|
18
|
+
* written down — a log line, an error, a crash report shipped to a third party
|
|
19
|
+
* — are the places nobody is reading carefully. This exists so that redacting
|
|
20
|
+
* is the easy thing to do at each of them.
|
|
21
|
+
*
|
|
22
|
+
* Safe on input that is not a URL: it returns a constant rather than throwing,
|
|
23
|
+
* because this runs on paths that must not fail. Anything unparseable is
|
|
24
|
+
* treated as potentially secret and withheld entirely rather than echoed.
|
|
25
|
+
*/
|
|
26
|
+
function redactDatabaseUrl(url) {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = new URL(url);
|
|
29
|
+
if (!parsed.password) return url;
|
|
30
|
+
parsed.password = "***";
|
|
31
|
+
return parsed.toString();
|
|
32
|
+
} catch {
|
|
33
|
+
return "<unparseable url>";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Base for an address that cannot become a connection string.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately carries no URL field: these are thrown while *composing* one, so
|
|
40
|
+
* there is no URL yet — only the parts, which include the password.
|
|
41
|
+
*/
|
|
42
|
+
var DatabaseAddressError = class extends Error {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = new.target.name;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/** An address with no host to connect to. */
|
|
49
|
+
var MissingDatabaseHost = class extends DatabaseAddressError {
|
|
50
|
+
constructor() {
|
|
51
|
+
super("A database address must name a host");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* An address with no database name.
|
|
56
|
+
*
|
|
57
|
+
* Postgres silently falls back to the connecting role's name, so the app
|
|
58
|
+
* connects successfully to the wrong database and fails later with confusing
|
|
59
|
+
* "relation does not exist" errors. Rejecting it here is much cheaper.
|
|
60
|
+
*/
|
|
61
|
+
var MissingDatabaseName = class extends DatabaseAddressError {
|
|
62
|
+
constructor() {
|
|
63
|
+
super("A database address must name a database");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { DatabaseAddressError, MissingDatabaseHost, MissingDatabaseName, redactDatabaseUrl };
|
|
69
|
+
//# sourceMappingURL=errors-CfFCan-X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CfFCan-X.mjs","names":["url: string","message: string"],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Database URL errors and redaction — engine-neutral.\n *\n * Nothing here is Postgres-specific: every engine addresses itself as a URL\n * carrying a password, and \"must name a host\" holds for all of them. The parts\n * that differ — libpq's `options=-c search_path=…`, which no other engine\n * accepts — live under the driver they belong to.\n *\n * Messages state the rule, which is constant; the offending value is a field.\n * An interpolated message cannot be matched on and carries user input into\n * every log line that touches it.\n */\n\n/**\n * Replace the password in a connection string with `***`.\n *\n * A connection string is a secret, and the places it is most likely to be\n * written down — a log line, an error, a crash report shipped to a third party\n * — are the places nobody is reading carefully. This exists so that redacting\n * is the easy thing to do at each of them.\n *\n * Safe on input that is not a URL: it returns a constant rather than throwing,\n * because this runs on paths that must not fail. Anything unparseable is\n * treated as potentially secret and withheld entirely rather than echoed.\n */\nexport function redactDatabaseUrl(url: string): string {\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tif (!parsed.password) return url;\n\t\tparsed.password = '***';\n\t\treturn parsed.toString();\n\t} catch {\n\t\treturn '<unparseable url>';\n\t}\n}\n\n/**\n * Base for an address that cannot become a connection string.\n *\n * Deliberately carries no URL field: these are thrown while *composing* one, so\n * there is no URL yet — only the parts, which include the password.\n */\nexport abstract class DatabaseAddressError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t}\n}\n\n/** An address with no host to connect to. */\nexport class MissingDatabaseHost extends DatabaseAddressError {\n\tconstructor() {\n\t\tsuper('A database address must name a host');\n\t}\n}\n\n/**\n * An address with no database name.\n *\n * Postgres silently falls back to the connecting role's name, so the app\n * connects successfully to the wrong database and fails later with confusing\n * \"relation does not exist\" errors. Rejecting it here is much cheaper.\n */\nexport class MissingDatabaseName extends DatabaseAddressError {\n\tconstructor() {\n\t\tsuper('A database address must name a database');\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,kBAAkBA,KAAqB;AACtD,KAAI;EACH,MAAM,SAAS,IAAI,IAAI;AACvB,OAAK,OAAO,SAAU,QAAO;AAC7B,SAAO,WAAW;AAClB,SAAO,OAAO,UAAU;CACxB,QAAO;AACP,SAAO;CACP;AACD;;;;;;;AAQD,IAAsB,uBAAtB,cAAmD,MAAM;CACxD,YAAYC,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO,IAAI,OAAO;CACvB;AACD;;AAGD,IAAa,sBAAb,cAAyC,qBAAqB;CAC7D,cAAc;AACb,QAAM,sCAAsC;CAC5C;AACD;;;;;;;;AASD,IAAa,sBAAb,cAAyC,qBAAqB;CAC7D,cAAc;AACb,QAAM,0CAA0C;CAChD;AACD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/errors.ts
|
|
3
|
+
/**
|
|
4
|
+
* Database URL errors and redaction — engine-neutral.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here is Postgres-specific: every engine addresses itself as a URL
|
|
7
|
+
* carrying a password, and "must name a host" holds for all of them. The parts
|
|
8
|
+
* that differ — libpq's `options=-c search_path=…`, which no other engine
|
|
9
|
+
* accepts — live under the driver they belong to.
|
|
10
|
+
*
|
|
11
|
+
* Messages state the rule, which is constant; the offending value is a field.
|
|
12
|
+
* An interpolated message cannot be matched on and carries user input into
|
|
13
|
+
* every log line that touches it.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Replace the password in a connection string with `***`.
|
|
17
|
+
*
|
|
18
|
+
* A connection string is a secret, and the places it is most likely to be
|
|
19
|
+
* written down — a log line, an error, a crash report shipped to a third party
|
|
20
|
+
* — are the places nobody is reading carefully. This exists so that redacting
|
|
21
|
+
* is the easy thing to do at each of them.
|
|
22
|
+
*
|
|
23
|
+
* Safe on input that is not a URL: it returns a constant rather than throwing,
|
|
24
|
+
* because this runs on paths that must not fail. Anything unparseable is
|
|
25
|
+
* treated as potentially secret and withheld entirely rather than echoed.
|
|
26
|
+
*/
|
|
27
|
+
function redactDatabaseUrl(url) {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = new URL(url);
|
|
30
|
+
if (!parsed.password) return url;
|
|
31
|
+
parsed.password = "***";
|
|
32
|
+
return parsed.toString();
|
|
33
|
+
} catch {
|
|
34
|
+
return "<unparseable url>";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Base for an address that cannot become a connection string.
|
|
39
|
+
*
|
|
40
|
+
* Deliberately carries no URL field: these are thrown while *composing* one, so
|
|
41
|
+
* there is no URL yet — only the parts, which include the password.
|
|
42
|
+
*/
|
|
43
|
+
var DatabaseAddressError = class extends Error {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = new.target.name;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** An address with no host to connect to. */
|
|
50
|
+
var MissingDatabaseHost = class extends DatabaseAddressError {
|
|
51
|
+
constructor() {
|
|
52
|
+
super("A database address must name a host");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* An address with no database name.
|
|
57
|
+
*
|
|
58
|
+
* Postgres silently falls back to the connecting role's name, so the app
|
|
59
|
+
* connects successfully to the wrong database and fails later with confusing
|
|
60
|
+
* "relation does not exist" errors. Rejecting it here is much cheaper.
|
|
61
|
+
*/
|
|
62
|
+
var MissingDatabaseName = class extends DatabaseAddressError {
|
|
63
|
+
constructor() {
|
|
64
|
+
super("A database address must name a database");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
Object.defineProperty(exports, 'DatabaseAddressError', {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () {
|
|
72
|
+
return DatabaseAddressError;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, 'MissingDatabaseHost', {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return MissingDatabaseHost;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, 'MissingDatabaseName', {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () {
|
|
84
|
+
return MissingDatabaseName;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, 'redactDatabaseUrl', {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return redactDatabaseUrl;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=errors-Cs5jlAv-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-Cs5jlAv-.cjs","names":["url: string","message: string"],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Database URL errors and redaction — engine-neutral.\n *\n * Nothing here is Postgres-specific: every engine addresses itself as a URL\n * carrying a password, and \"must name a host\" holds for all of them. The parts\n * that differ — libpq's `options=-c search_path=…`, which no other engine\n * accepts — live under the driver they belong to.\n *\n * Messages state the rule, which is constant; the offending value is a field.\n * An interpolated message cannot be matched on and carries user input into\n * every log line that touches it.\n */\n\n/**\n * Replace the password in a connection string with `***`.\n *\n * A connection string is a secret, and the places it is most likely to be\n * written down — a log line, an error, a crash report shipped to a third party\n * — are the places nobody is reading carefully. This exists so that redacting\n * is the easy thing to do at each of them.\n *\n * Safe on input that is not a URL: it returns a constant rather than throwing,\n * because this runs on paths that must not fail. Anything unparseable is\n * treated as potentially secret and withheld entirely rather than echoed.\n */\nexport function redactDatabaseUrl(url: string): string {\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tif (!parsed.password) return url;\n\t\tparsed.password = '***';\n\t\treturn parsed.toString();\n\t} catch {\n\t\treturn '<unparseable url>';\n\t}\n}\n\n/**\n * Base for an address that cannot become a connection string.\n *\n * Deliberately carries no URL field: these are thrown while *composing* one, so\n * there is no URL yet — only the parts, which include the password.\n */\nexport abstract class DatabaseAddressError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t}\n}\n\n/** An address with no host to connect to. */\nexport class MissingDatabaseHost extends DatabaseAddressError {\n\tconstructor() {\n\t\tsuper('A database address must name a host');\n\t}\n}\n\n/**\n * An address with no database name.\n *\n * Postgres silently falls back to the connecting role's name, so the app\n * connects successfully to the wrong database and fails later with confusing\n * \"relation does not exist\" errors. Rejecting it here is much cheaper.\n */\nexport class MissingDatabaseName extends DatabaseAddressError {\n\tconstructor() {\n\t\tsuper('A database address must name a database');\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,kBAAkBA,KAAqB;AACtD,KAAI;EACH,MAAM,SAAS,IAAI,IAAI;AACvB,OAAK,OAAO,SAAU,QAAO;AAC7B,SAAO,WAAW;AAClB,SAAO,OAAO,UAAU;CACxB,QAAO;AACP,SAAO;CACP;AACD;;;;;;;AAQD,IAAsB,uBAAtB,cAAmD,MAAM;CACxD,YAAYC,SAAiB;AAC5B,QAAM,QAAQ;AACd,OAAK,OAAO,IAAI,OAAO;CACvB;AACD;;AAGD,IAAa,sBAAb,cAAyC,qBAAqB;CAC7D,cAAc;AACb,QAAM,sCAAsC;CAC5C;AACD;;;;;;;;AASD,IAAa,sBAAb,cAAyC,qBAAqB;CAC7D,cAAc;AACb,QAAM,0CAA0C;CAChD;AACD"}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const require_errors = require('./errors-Cs5jlAv-.cjs');
|
|
2
|
+
|
|
3
|
+
exports.DatabaseAddressError = require_errors.DatabaseAddressError;
|
|
4
|
+
exports.MissingDatabaseHost = require_errors.MissingDatabaseHost;
|
|
5
|
+
exports.MissingDatabaseName = require_errors.MissingDatabaseName;
|
|
6
|
+
exports.redactDatabaseUrl = require_errors.redactDatabaseUrl;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Database URL errors and redaction — engine-neutral.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here is Postgres-specific: every engine addresses itself as a URL
|
|
6
|
+
* carrying a password, and "must name a host" holds for all of them. The parts
|
|
7
|
+
* that differ — libpq's `options=-c search_path=…`, which no other engine
|
|
8
|
+
* accepts — live under the driver they belong to.
|
|
9
|
+
*
|
|
10
|
+
* Messages state the rule, which is constant; the offending value is a field.
|
|
11
|
+
* An interpolated message cannot be matched on and carries user input into
|
|
12
|
+
* every log line that touches it.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Replace the password in a connection string with `***`.
|
|
16
|
+
*
|
|
17
|
+
* A connection string is a secret, and the places it is most likely to be
|
|
18
|
+
* written down — a log line, an error, a crash report shipped to a third party
|
|
19
|
+
* — are the places nobody is reading carefully. This exists so that redacting
|
|
20
|
+
* is the easy thing to do at each of them.
|
|
21
|
+
*
|
|
22
|
+
* Safe on input that is not a URL: it returns a constant rather than throwing,
|
|
23
|
+
* because this runs on paths that must not fail. Anything unparseable is
|
|
24
|
+
* treated as potentially secret and withheld entirely rather than echoed.
|
|
25
|
+
*/
|
|
26
|
+
declare function redactDatabaseUrl(url: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Base for an address that cannot become a connection string.
|
|
29
|
+
*
|
|
30
|
+
* Deliberately carries no URL field: these are thrown while *composing* one, so
|
|
31
|
+
* there is no URL yet — only the parts, which include the password.
|
|
32
|
+
*/
|
|
33
|
+
declare abstract class DatabaseAddressError extends Error {
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
/** An address with no host to connect to. */
|
|
37
|
+
declare class MissingDatabaseHost extends DatabaseAddressError {
|
|
38
|
+
constructor();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* An address with no database name.
|
|
42
|
+
*
|
|
43
|
+
* Postgres silently falls back to the connecting role's name, so the app
|
|
44
|
+
* connects successfully to the wrong database and fails later with confusing
|
|
45
|
+
* "relation does not exist" errors. Rejecting it here is much cheaper.
|
|
46
|
+
*/
|
|
47
|
+
declare class MissingDatabaseName extends DatabaseAddressError {
|
|
48
|
+
constructor();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
51
|
+
//#endregion
|
|
52
|
+
export { DatabaseAddressError, MissingDatabaseHost, MissingDatabaseName, redactDatabaseUrl };
|
|
53
|
+
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;AAyBA;AAiBA;AAQA;AAaA;;;;;;;;;;;;;;;;;;;;iBAtCgB,iBAAA;;;;;;;uBAiBM,oBAAA,SAA6B,KAAK;;;;cAQ3C,mBAAA,SAA4B,oBAAoB;;;;;;;;;;cAahD,mBAAA,SAA4B,oBAAoB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Database URL errors and redaction — engine-neutral.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here is Postgres-specific: every engine addresses itself as a URL
|
|
6
|
+
* carrying a password, and "must name a host" holds for all of them. The parts
|
|
7
|
+
* that differ — libpq's `options=-c search_path=…`, which no other engine
|
|
8
|
+
* accepts — live under the driver they belong to.
|
|
9
|
+
*
|
|
10
|
+
* Messages state the rule, which is constant; the offending value is a field.
|
|
11
|
+
* An interpolated message cannot be matched on and carries user input into
|
|
12
|
+
* every log line that touches it.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Replace the password in a connection string with `***`.
|
|
16
|
+
*
|
|
17
|
+
* A connection string is a secret, and the places it is most likely to be
|
|
18
|
+
* written down — a log line, an error, a crash report shipped to a third party
|
|
19
|
+
* — are the places nobody is reading carefully. This exists so that redacting
|
|
20
|
+
* is the easy thing to do at each of them.
|
|
21
|
+
*
|
|
22
|
+
* Safe on input that is not a URL: it returns a constant rather than throwing,
|
|
23
|
+
* because this runs on paths that must not fail. Anything unparseable is
|
|
24
|
+
* treated as potentially secret and withheld entirely rather than echoed.
|
|
25
|
+
*/
|
|
26
|
+
declare function redactDatabaseUrl(url: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Base for an address that cannot become a connection string.
|
|
29
|
+
*
|
|
30
|
+
* Deliberately carries no URL field: these are thrown while *composing* one, so
|
|
31
|
+
* there is no URL yet — only the parts, which include the password.
|
|
32
|
+
*/
|
|
33
|
+
declare abstract class DatabaseAddressError extends Error {
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
/** An address with no host to connect to. */
|
|
37
|
+
declare class MissingDatabaseHost extends DatabaseAddressError {
|
|
38
|
+
constructor();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* An address with no database name.
|
|
42
|
+
*
|
|
43
|
+
* Postgres silently falls back to the connecting role's name, so the app
|
|
44
|
+
* connects successfully to the wrong database and fails later with confusing
|
|
45
|
+
* "relation does not exist" errors. Rejecting it here is much cheaper.
|
|
46
|
+
*/
|
|
47
|
+
declare class MissingDatabaseName extends DatabaseAddressError {
|
|
48
|
+
constructor();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
51
|
+
//#endregion
|
|
52
|
+
export { DatabaseAddressError, MissingDatabaseHost, MissingDatabaseName, redactDatabaseUrl };
|
|
53
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;AAyBA;AAiBA;AAQA;AAaA;;;;;;;;;;;;;;;;;;;;iBAtCgB,iBAAA;;;;;;;uBAiBM,oBAAA,SAA6B,KAAK;;;;cAQ3C,mBAAA,SAA4B,oBAAoB;;;;;;;;;;cAahD,mBAAA,SAA4B,oBAAoB"}
|
package/dist/errors.mjs
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-kv-KWS-7.mjs";
|
|
2
2
|
import { SelectQueryBuilder } from "kysely";
|
|
3
3
|
|
|
4
4
|
//#region src/kysely/pagination.d.ts
|
|
@@ -10,4 +10,4 @@ type DatabaseConnection<T> = ControlledTransaction<T> | Kysely<T> | Transaction<
|
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
export { DatabaseConnection, TransactionSettings, withTransaction };
|
|
13
|
-
//# sourceMappingURL=kysely-
|
|
13
|
+
//# sourceMappingURL=kysely-BAedYsvn.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-
|
|
1
|
+
{"version":3,"file":"kysely-BAedYsvn.d.mts","names":[],"sources":["../src/kysely.ts"],"sourcesContent":[],"mappings":";;;UAOiB,mBAAA;mBACC;AADlB;AAIgB,iBAAA,eAAe,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAA,EAC1B,kBAD0B,CACP,EADO,CAAA,EAAA,EAAA,EAAA,CAAA,GAAA,EAEpB,WAFoB,CAER,EAFQ,CAAA,EAAA,GAEA,OAFA,CAEQ,CAFR,CAAA,EAAA,QAAA,CAAA,EAGnB,mBAHmB,CAAA,EAI5B,OAJ4B,CAIpB,CAJoB,CAAA;AAAA,KAkBnB,kBAlBmB,CAAA,CAAA,CAAA,GAmB5B,qBAnB4B,CAmBN,CAnBM,CAAA,GAoB5B,MApB4B,CAoBrB,CApBqB,CAAA,GAqB5B,WArB4B,CAqBhB,CArBgB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-
|
|
1
|
+
{"version":3,"file":"kysely-Bo_Zg-D3.mjs","names":["db: DatabaseConnection<DB>","cb: (trx: Transaction<DB>) => Promise<T>","settings?: TransactionSettings"],"sources":["../src/kysely.ts"],"sourcesContent":["import type {\n\tControlledTransaction,\n\tIsolationLevel,\n\tKysely,\n\tTransaction,\n} from 'kysely';\n\nexport interface TransactionSettings {\n\tisolationLevel?: IsolationLevel;\n}\n\nexport function withTransaction<DB, T>(\n\tdb: DatabaseConnection<DB>,\n\tcb: (trx: Transaction<DB>) => Promise<T>,\n\tsettings?: TransactionSettings,\n): Promise<T> {\n\tif (db.isTransaction) {\n\t\treturn cb(db as Transaction<DB>);\n\t}\n\n\tconst builder = db.transaction();\n\n\tif (settings?.isolationLevel) {\n\t\treturn builder.setIsolationLevel(settings.isolationLevel).execute(cb);\n\t}\n\n\treturn builder.execute(cb);\n}\n\nexport type DatabaseConnection<T> =\n\t| ControlledTransaction<T>\n\t| Kysely<T>\n\t| Transaction<T>;\n"],"mappings":";AAWA,SAAgB,gBACfA,IACAC,IACAC,UACa;AACb,KAAI,GAAG,cACN,QAAO,GAAG,GAAsB;CAGjC,MAAM,UAAU,GAAG,aAAa;AAEhC,KAAI,UAAU,eACb,QAAO,QAAQ,kBAAkB,SAAS,eAAe,CAAC,QAAQ,GAAG;AAGtE,QAAO,QAAQ,QAAQ,GAAG;AAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-
|
|
1
|
+
{"version":3,"file":"kysely-LWvS2ekY.cjs","names":["db: DatabaseConnection<DB>","cb: (trx: Transaction<DB>) => Promise<T>","settings?: TransactionSettings"],"sources":["../src/kysely.ts"],"sourcesContent":["import type {\n\tControlledTransaction,\n\tIsolationLevel,\n\tKysely,\n\tTransaction,\n} from 'kysely';\n\nexport interface TransactionSettings {\n\tisolationLevel?: IsolationLevel;\n}\n\nexport function withTransaction<DB, T>(\n\tdb: DatabaseConnection<DB>,\n\tcb: (trx: Transaction<DB>) => Promise<T>,\n\tsettings?: TransactionSettings,\n): Promise<T> {\n\tif (db.isTransaction) {\n\t\treturn cb(db as Transaction<DB>);\n\t}\n\n\tconst builder = db.transaction();\n\n\tif (settings?.isolationLevel) {\n\t\treturn builder.setIsolationLevel(settings.isolationLevel).execute(cb);\n\t}\n\n\treturn builder.execute(cb);\n}\n\nexport type DatabaseConnection<T> =\n\t| ControlledTransaction<T>\n\t| Kysely<T>\n\t| Transaction<T>;\n"],"mappings":";;AAWA,SAAgB,gBACfA,IACAC,IACAC,UACa;AACb,KAAI,GAAG,cACN,QAAO,GAAG,GAAsB;CAGjC,MAAM,UAAU,GAAG,aAAa;AAEhC,KAAI,UAAU,eACb,QAAO,QAAQ,kBAAkB,SAAS,eAAe,CAAC,QAAQ,GAAG;AAGtE,QAAO,QAAQ,QAAQ,GAAG;AAC1B"}
|
package/dist/kysely.cjs
CHANGED
package/dist/kysely.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DatabaseConnection, TransactionSettings, withTransaction } from "./kysely-
|
|
1
|
+
import { DatabaseConnection, TransactionSettings, withTransaction } from "./kysely-BAedYsvn.mjs";
|
|
2
2
|
export { DatabaseConnection, TransactionSettings, withTransaction };
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "../pagination-kv-KWS-7.mjs";
|
|
2
2
|
import { Model, QueryBuilder } from "objection";
|
|
3
3
|
|
|
4
4
|
//#region src/objection/pagination.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination-
|
|
1
|
+
{"version":3,"file":"pagination-Bu1dqOy0.cjs","names":["value: unknown","cursor: string"],"sources":["../src/pagination.ts"],"sourcesContent":["/**\n * Sort direction for cursor-based pagination.\n */\nexport enum Direction {\n\tAsc = 'asc',\n\tDesc = 'desc',\n}\n\n/**\n * Result of a paginated query.\n */\nexport interface PaginationResult<TItem> {\n\titems: TItem[];\n\tpagination: {\n\t\ttotal: number;\n\t\thasMore: boolean;\n\t\tcursor?: string;\n\t};\n}\n\n/**\n * Encode a cursor value for safe URL transmission.\n * Supports various types: string, number, Date, etc.\n */\nexport function encodeCursor(value: unknown): string {\n\tconst payload = {\n\t\tv: value instanceof Date ? value.toISOString() : value,\n\t\tt: value instanceof Date ? 'date' : typeof value,\n\t};\n\treturn Buffer.from(JSON.stringify(payload)).toString('base64url');\n}\n\n/**\n * Decode a cursor string back to its original value.\n */\nexport function decodeCursor(cursor: string): unknown {\n\ttry {\n\t\tconst json = Buffer.from(cursor, 'base64url').toString('utf-8');\n\t\tconst payload = JSON.parse(json);\n\n\t\tif (payload.t === 'date') {\n\t\t\treturn new Date(payload.v);\n\t\t}\n\n\t\treturn payload.v;\n\t} catch {\n\t\tthrow new Error('Invalid cursor format');\n\t}\n}\n"],"mappings":";;;;;AAGA,IAAY,kDAAL;AACN;AACA;;AACA;;;;;AAkBD,SAAgB,aAAaA,OAAwB;CACpD,MAAM,UAAU;EACf,GAAG,iBAAiB,OAAO,MAAM,aAAa,GAAG;EACjD,GAAG,iBAAiB,OAAO,gBAAgB;CAC3C;AACD,QAAO,OAAO,KAAK,KAAK,UAAU,QAAQ,CAAC,CAAC,SAAS,YAAY;AACjE;;;;AAKD,SAAgB,aAAaC,QAAyB;AACrD,KAAI;EACH,MAAM,OAAO,OAAO,KAAK,QAAQ,YAAY,CAAC,SAAS,QAAQ;EAC/D,MAAM,UAAU,KAAK,MAAM,KAAK;AAEhC,MAAI,QAAQ,MAAM,OACjB,QAAO,IAAI,KAAK,QAAQ;AAGzB,SAAO,QAAQ;CACf,QAAO;AACP,QAAM,IAAI,MAAM;CAChB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination-
|
|
1
|
+
{"version":3,"file":"pagination-CQ8QHXaL.mjs","names":["value: unknown","cursor: string"],"sources":["../src/pagination.ts"],"sourcesContent":["/**\n * Sort direction for cursor-based pagination.\n */\nexport enum Direction {\n\tAsc = 'asc',\n\tDesc = 'desc',\n}\n\n/**\n * Result of a paginated query.\n */\nexport interface PaginationResult<TItem> {\n\titems: TItem[];\n\tpagination: {\n\t\ttotal: number;\n\t\thasMore: boolean;\n\t\tcursor?: string;\n\t};\n}\n\n/**\n * Encode a cursor value for safe URL transmission.\n * Supports various types: string, number, Date, etc.\n */\nexport function encodeCursor(value: unknown): string {\n\tconst payload = {\n\t\tv: value instanceof Date ? value.toISOString() : value,\n\t\tt: value instanceof Date ? 'date' : typeof value,\n\t};\n\treturn Buffer.from(JSON.stringify(payload)).toString('base64url');\n}\n\n/**\n * Decode a cursor string back to its original value.\n */\nexport function decodeCursor(cursor: string): unknown {\n\ttry {\n\t\tconst json = Buffer.from(cursor, 'base64url').toString('utf-8');\n\t\tconst payload = JSON.parse(json);\n\n\t\tif (payload.t === 'date') {\n\t\t\treturn new Date(payload.v);\n\t\t}\n\n\t\treturn payload.v;\n\t} catch {\n\t\tthrow new Error('Invalid cursor format');\n\t}\n}\n"],"mappings":";;;;AAGA,IAAY,kDAAL;AACN;AACA;;AACA;;;;;AAkBD,SAAgB,aAAaA,OAAwB;CACpD,MAAM,UAAU;EACf,GAAG,iBAAiB,OAAO,MAAM,aAAa,GAAG;EACjD,GAAG,iBAAiB,OAAO,gBAAgB;CAC3C;AACD,QAAO,OAAO,KAAK,KAAK,UAAU,QAAQ,CAAC,CAAC,SAAS,YAAY;AACjE;;;;AAKD,SAAgB,aAAaC,QAAyB;AACrD,KAAI;EACH,MAAM,OAAO,OAAO,KAAK,QAAQ,YAAY,CAAC,SAAS,QAAQ;EAC/D,MAAM,UAAU,KAAK,MAAM,KAAK;AAEhC,MAAI,QAAQ,MAAM,OACjB,QAAO,IAAI,KAAK,QAAQ;AAGzB,SAAO,QAAQ;CACf,QAAO;AACP,QAAM,IAAI,MAAM;CAChB;AACD"}
|
|
@@ -29,4 +29,4 @@ declare function decodeCursor(cursor: string): unknown;
|
|
|
29
29
|
//# sourceMappingURL=pagination.d.ts.map
|
|
30
30
|
//#endregion
|
|
31
31
|
export { Direction, PaginationResult, decodeCursor, encodeCursor };
|
|
32
|
-
//# sourceMappingURL=pagination-
|
|
32
|
+
//# sourceMappingURL=pagination-kv-KWS-7.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination-
|
|
1
|
+
{"version":3,"file":"pagination-kv-KWS-7.d.mts","names":[],"sources":["../src/pagination.ts"],"sourcesContent":[],"mappings":";;AAGA;AAQA;AAagB,aArBJ,SAAA;EAgCI,GAAA,GAAA,KAAA;;;;;;UAxBC;SACT;;;;;;;;;;;iBAYQ,YAAA;;;;iBAWA,YAAA"}
|
package/dist/pagination.cjs
CHANGED
package/dist/pagination.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "./pagination-
|
|
1
|
+
import { Direction, PaginationResult, decodeCursor, encodeCursor } from "./pagination-kv-KWS-7.mjs";
|
|
2
2
|
export { Direction, PaginationResult, decodeCursor, encodeCursor };
|
package/dist/pagination.mjs
CHANGED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/pg/roles.ts
|
|
3
|
+
/**
|
|
4
|
+
* Everything one tenant's roles need, in dependency order.
|
|
5
|
+
*
|
|
6
|
+
* The owner before the schema it owns, the schema before the grants on it. A
|
|
7
|
+
* caller applies them in sequence and may stop at the first failure without
|
|
8
|
+
* leaving a half-granted role that looks complete.
|
|
9
|
+
*/
|
|
10
|
+
function roleStatements(spec) {
|
|
11
|
+
const { runtime, owner, schema, passwords } = spec;
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
describe: `role ${owner}`,
|
|
15
|
+
exists: roleExists(owner),
|
|
16
|
+
sql: `CREATE ROLE ${ident(owner)} LOGIN PASSWORD ${literal(passwords.owner)}`
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
describe: `role ${runtime}`,
|
|
20
|
+
exists: roleExists(runtime),
|
|
21
|
+
sql: `CREATE ROLE ${ident(runtime)} LOGIN PASSWORD ${literal(passwords.runtime)}`
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
describe: `${owner} granted to the connecting role`,
|
|
25
|
+
sql: `GRANT ${ident(owner)} TO CURRENT_USER`
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
describe: `schema ${schema}`,
|
|
29
|
+
exists: {
|
|
30
|
+
sql: "SELECT 1 FROM information_schema.schemata WHERE schema_name = $1",
|
|
31
|
+
values: [schema]
|
|
32
|
+
},
|
|
33
|
+
sql: `CREATE SCHEMA ${ident(schema)} AUTHORIZATION ${ident(owner)}`
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
describe: `${schema} is owned by ${owner}`,
|
|
37
|
+
sql: `ALTER SCHEMA ${ident(schema)} OWNER TO ${ident(owner)}`
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
describe: `${runtime} may use ${schema}`,
|
|
41
|
+
sql: `GRANT USAGE ON SCHEMA ${ident(schema)} TO ${ident(runtime)}`
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
describe: `${runtime} may read and write future tables in ${schema}`,
|
|
45
|
+
sql: `ALTER DEFAULT PRIVILEGES FOR ROLE ${ident(owner)} IN SCHEMA ${ident(schema)} GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO ${ident(runtime)}`
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
describe: `${runtime} may use future sequences in ${schema}`,
|
|
49
|
+
sql: `ALTER DEFAULT PRIVILEGES FOR ROLE ${ident(owner)} IN SCHEMA ${ident(schema)} GRANT USAGE, SELECT ON SEQUENCES TO ${ident(runtime)}`
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
describe: `${runtime} may read and write existing tables in ${schema}`,
|
|
53
|
+
sql: `GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA ${ident(schema)} TO ${ident(runtime)}`
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
describe: `${runtime} may use existing sequences in ${schema}`,
|
|
57
|
+
sql: `GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA ${ident(schema)} TO ${ident(runtime)}`
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
describe: `${runtime} resolves names in ${schema}`,
|
|
61
|
+
sql: `ALTER ROLE ${ident(runtime)} SET search_path TO ${ident(schema)}`
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
describe: `${owner} resolves names in ${schema}`,
|
|
65
|
+
sql: `ALTER ROLE ${ident(owner)} SET search_path TO ${ident(schema)}`
|
|
66
|
+
},
|
|
67
|
+
...spec.reader ? readerStatements(spec, spec.reader) : []
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A role that may read and nothing else.
|
|
72
|
+
*
|
|
73
|
+
* `SELECT` and no more, on what exists and on what the owner creates later. No
|
|
74
|
+
* `INSERT`, no `UPDATE`, no `DELETE`, and no sequence `USAGE` — a reader that
|
|
75
|
+
* could take a sequence value could not write the row it was for, so granting
|
|
76
|
+
* it would be surface with no use.
|
|
77
|
+
*/
|
|
78
|
+
function readerStatements(spec, reader) {
|
|
79
|
+
const { owner, schema, passwords } = spec;
|
|
80
|
+
const password = passwords.reader;
|
|
81
|
+
if (!password) throw new ReaderNeedsPassword(reader);
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
describe: `role ${reader}`,
|
|
85
|
+
exists: roleExists(reader),
|
|
86
|
+
sql: `CREATE ROLE ${ident(reader)} LOGIN PASSWORD ${literal(password)}`
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
describe: `${reader} may use ${schema}`,
|
|
90
|
+
sql: `GRANT USAGE ON SCHEMA ${ident(schema)} TO ${ident(reader)}`
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
describe: `${reader} may read future tables in ${schema}`,
|
|
94
|
+
sql: `ALTER DEFAULT PRIVILEGES FOR ROLE ${ident(owner)} IN SCHEMA ${ident(schema)} GRANT SELECT ON TABLES TO ${ident(reader)}`
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
describe: `${reader} may read existing tables in ${schema}`,
|
|
98
|
+
sql: `GRANT SELECT ON ALL TABLES IN SCHEMA ${ident(schema)} TO ${ident(reader)}`
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
describe: `${reader} resolves names in ${schema}`,
|
|
102
|
+
sql: `ALTER ROLE ${ident(reader)} SET search_path TO ${ident(schema)}`
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
/** A reader role was named and no password was supplied for it. */
|
|
107
|
+
var ReaderNeedsPassword = class extends Error {
|
|
108
|
+
constructor(role) {
|
|
109
|
+
super(`'${role}' is a reader role and no password was supplied for it. This module composes DDL and invents no secrets: pass passwords.reader alongside the role name.`);
|
|
110
|
+
this.role = role;
|
|
111
|
+
this.name = "ReaderNeedsPassword";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/** The read-only role's name for a given runtime role. */
|
|
115
|
+
function readerRole(runtime) {
|
|
116
|
+
return `${runtime}_reader`;
|
|
117
|
+
}
|
|
118
|
+
/** The owner role's name for a given runtime role. */
|
|
119
|
+
function ownerRole(runtime) {
|
|
120
|
+
return `${runtime}_owner`;
|
|
121
|
+
}
|
|
122
|
+
function roleExists(role) {
|
|
123
|
+
return {
|
|
124
|
+
sql: "SELECT 1 FROM pg_roles WHERE rolname = $1",
|
|
125
|
+
values: [role]
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Quote an identifier for use in DDL.
|
|
130
|
+
*
|
|
131
|
+
* Names reaching here are already canonical, so this is defence rather than
|
|
132
|
+
* sanitisation — but DDL cannot be parameterised, and an unquoted identifier is
|
|
133
|
+
* the one place a name could ever be more than a name.
|
|
134
|
+
*/
|
|
135
|
+
function ident(name) {
|
|
136
|
+
return `"${name.replace(/"/g, "\"\"")}"`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Quote a string literal.
|
|
140
|
+
*
|
|
141
|
+
* A password cannot be a bind parameter in `CREATE ROLE`, which is the one
|
|
142
|
+
* place in this module where a value rather than a name is interpolated — so it
|
|
143
|
+
* is escaped rather than trusted, whatever the caller believes it derived.
|
|
144
|
+
*/
|
|
145
|
+
function literal(value) {
|
|
146
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
exports.ReaderNeedsPassword = ReaderNeedsPassword;
|
|
151
|
+
exports.ownerRole = ownerRole;
|
|
152
|
+
exports.readerRole = readerRole;
|
|
153
|
+
exports.roleStatements = roleStatements;
|
|
154
|
+
//# sourceMappingURL=roles.cjs.map
|