@owlmeans/postgres-resource 0.1.18-rc.42 → 0.1.18-rc.43
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 +13 -13
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/postgres-resource/SKILL.md +1 -1
- package/build/consts.d.ts +9 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +6 -0
- package/build/consts.js.map +1 -1
- package/build/declarations/types.d.ts +12 -0
- package/build/declarations/types.d.ts.map +1 -0
- package/build/declarations/types.js +2 -0
- package/build/declarations/types.js.map +1 -0
- package/build/declarations.d.ts +5 -1
- package/build/declarations.d.ts.map +1 -1
- package/build/declarations.js +25 -15
- package/build/declarations.js.map +1 -1
- package/build/errors.d.ts +0 -20
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js +1 -111
- package/build/errors.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/pg-error/types.d.ts +24 -0
- package/build/pg-error/types.d.ts.map +1 -0
- package/build/pg-error/types.js +2 -0
- package/build/pg-error/types.js.map +1 -0
- package/build/pg-error.d.ts +4 -0
- package/build/pg-error.d.ts.map +1 -0
- package/build/pg-error.js +100 -0
- package/build/pg-error.js.map +1 -0
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +15 -11
- package/build/resource.js.map +1 -1
- package/build/types.d.ts.map +1 -1
- package/build/utils/consts.local.d.ts +2 -0
- package/build/utils/consts.local.d.ts.map +1 -1
- package/build/utils/consts.local.js +2 -0
- package/build/utils/consts.local.js.map +1 -1
- package/build/utils/criteria/types.d.ts +31 -0
- package/build/utils/criteria/types.d.ts.map +1 -0
- package/build/utils/criteria/types.js +2 -0
- package/build/utils/criteria/types.js.map +1 -0
- package/build/utils/criteria.d.ts +3 -27
- package/build/utils/criteria.d.ts.map +1 -1
- package/build/utils/criteria.js +86 -104
- package/build/utils/criteria.js.map +1 -1
- package/build/utils/diff/types.d.ts +40 -0
- package/build/utils/diff/types.d.ts.map +1 -0
- package/build/utils/diff/types.js +2 -0
- package/build/utils/diff/types.js.map +1 -0
- package/build/utils/diff.d.ts +5 -35
- package/build/utils/diff.d.ts.map +1 -1
- package/build/utils/diff.js +320 -344
- package/build/utils/diff.js.map +1 -1
- package/build/utils/index.d.ts +9 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js.map +1 -1
- package/build/utils/introspect/types.d.ts +9 -0
- package/build/utils/introspect/types.d.ts.map +1 -0
- package/build/utils/introspect/types.js +2 -0
- package/build/utils/introspect/types.js.map +1 -0
- package/build/utils/introspect.d.ts +3 -3
- package/build/utils/introspect.d.ts.map +1 -1
- package/build/utils/introspect.js +41 -38
- package/build/utils/introspect.js.map +1 -1
- package/build/utils/life-cycle/types.d.ts +37 -0
- package/build/utils/life-cycle/types.d.ts.map +1 -0
- package/build/utils/life-cycle/types.js +2 -0
- package/build/utils/life-cycle/types.js.map +1 -0
- package/build/utils/life-cycle.d.ts +3 -33
- package/build/utils/life-cycle.d.ts.map +1 -1
- package/build/utils/life-cycle.js +88 -108
- package/build/utils/life-cycle.js.map +1 -1
- package/build/utils/marshal/types.d.ts +39 -0
- package/build/utils/marshal/types.d.ts.map +1 -0
- package/build/utils/marshal/types.js +2 -0
- package/build/utils/marshal/types.js.map +1 -0
- package/build/utils/marshal.d.ts +4 -32
- package/build/utils/marshal.d.ts.map +1 -1
- package/build/utils/marshal.js +121 -144
- package/build/utils/marshal.js.map +1 -1
- package/build/utils/migrations.d.ts.map +1 -1
- package/build/utils/migrations.js +41 -36
- package/build/utils/migrations.js.map +1 -1
- package/build/utils/name/types.d.ts +43 -0
- package/build/utils/name/types.d.ts.map +1 -0
- package/build/utils/name/types.js +2 -0
- package/build/utils/name/types.js.map +1 -0
- package/build/utils/name.d.ts +6 -35
- package/build/utils/name.d.ts.map +1 -1
- package/build/utils/name.js +38 -57
- package/build/utils/name.js.map +1 -1
- package/build/utils/schema/types.d.ts +22 -0
- package/build/utils/schema/types.d.ts.map +1 -0
- package/build/utils/schema/types.js +2 -0
- package/build/utils/schema/types.js.map +1 -0
- package/build/utils/schema.d.ts +4 -24
- package/build/utils/schema.d.ts.map +1 -1
- package/build/utils/schema.js +339 -352
- package/build/utils/schema.js.map +1 -1
- package/build/utils/sql/types.d.ts +25 -0
- package/build/utils/sql/types.d.ts.map +1 -0
- package/build/utils/sql/types.js +2 -0
- package/build/utils/sql/types.js.map +1 -0
- package/build/utils/sql.d.ts +4 -18
- package/build/utils/sql.d.ts.map +1 -1
- package/build/utils/sql.js +0 -0
- package/build/utils/sql.js.map +1 -1
- package/build/utils/sync/types.d.ts +25 -0
- package/build/utils/sync/types.d.ts.map +1 -0
- package/build/utils/sync/types.js +2 -0
- package/build/utils/sync/types.js.map +1 -0
- package/build/utils/sync.d.ts +2 -19
- package/build/utils/sync.d.ts.map +1 -1
- package/build/utils/sync.js +64 -71
- package/build/utils/sync.js.map +1 -1
- package/package.json +7 -7
- package/src/consts.ts +7 -0
- package/src/declarations/types.ts +12 -0
- package/src/declarations.ts +29 -14
- package/src/errors.ts +1 -121
- package/src/index.ts +3 -0
- package/src/pg-error/types.ts +23 -0
- package/src/pg-error.ts +114 -0
- package/src/resource.ts +17 -13
- package/src/types.ts +1 -0
- package/src/utils/consts.local.ts +3 -0
- package/src/utils/criteria/types.ts +32 -0
- package/src/utils/criteria.ts +95 -110
- package/src/utils/diff/types.ts +41 -0
- package/src/utils/diff.ts +330 -348
- package/src/utils/index.ts +9 -0
- package/src/utils/introspect/types.ts +9 -0
- package/src/utils/introspect.ts +51 -45
- package/src/utils/life-cycle/types.ts +41 -0
- package/src/utils/life-cycle.ts +102 -121
- package/src/utils/marshal/types.ts +40 -0
- package/src/utils/marshal.ts +129 -147
- package/src/utils/migrations.ts +39 -33
- package/src/utils/name/types.ts +44 -0
- package/src/utils/name.ts +47 -60
- package/src/utils/schema/types.ts +26 -0
- package/src/utils/schema.ts +359 -366
- package/src/utils/sql/types.ts +25 -0
- package/src/utils/sql.ts +0 -0
- package/src/utils/sync/types.ts +25 -0
- package/src/utils/sync.ts +62 -68
- package/tests/criteria.spec.ts +4 -1
- package/tests/diff.spec.ts +4 -1
- package/tests/errors.spec.ts +4 -3
- package/tests/name.spec.ts +5 -3
- package/tests/schema.spec.ts +3 -1
- package/tests/sql.spec.ts +20 -22
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ResourceRecord } from '@owlmeans/resource';
|
|
2
|
+
import type { TableSpec } from '../../types.js';
|
|
3
|
+
/** Records to driver values and back, driven by a compiled table spec. */
|
|
4
|
+
export interface PgMarshalHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Turn a driver row into a record: physical column names back to schema property names,
|
|
7
|
+
* plus the coercions node-postgres leaves to the caller.
|
|
8
|
+
*
|
|
9
|
+
* Columns the spec doesn't know about — computed expressions, joined columns from custom
|
|
10
|
+
* SQL — are kept verbatim. A join result is more useful than a lossy projection.
|
|
11
|
+
*/
|
|
12
|
+
rowToRecord: <T extends ResourceRecord>(row: Record<string, unknown>, spec: TableSpec) => T;
|
|
13
|
+
/**
|
|
14
|
+
* Same coercion as {@link PgMarshalHelper.rowToRecord}, for rows Drizzle produced.
|
|
15
|
+
*
|
|
16
|
+
* Drizzle keys its results by the table object's JS property names — which are the schema
|
|
17
|
+
* property names — where raw SQL returns physical column names. Two functions rather than
|
|
18
|
+
* one lookup that tries both, because a schema that renames `a` to column `b` while another
|
|
19
|
+
* property is itself named `b` would make the combined lookup pick the wrong spec.
|
|
20
|
+
*/
|
|
21
|
+
resultToRecord: <T extends ResourceRecord>(row: Record<string, unknown>, spec: TableSpec) => T;
|
|
22
|
+
/**
|
|
23
|
+
* Turn a record into the values Drizzle inserts, keyed by property name (Drizzle owns the
|
|
24
|
+
* property to column mapping).
|
|
25
|
+
*
|
|
26
|
+
* `undefined` properties are dropped so a partial write touches only what was supplied;
|
|
27
|
+
* an explicit `null` is kept, because nulling a column is a real intent.
|
|
28
|
+
*/
|
|
29
|
+
recordToValues: (record: Record<string, unknown>, spec: TableSpec) => Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Every managed column, with anything the record omits explicitly nulled.
|
|
32
|
+
*
|
|
33
|
+
* This is what makes `update()` a replace rather than a merge — the semantics mongo's
|
|
34
|
+
* `replaceOne` gives, kept identical so a resource behaves the same on either backend.
|
|
35
|
+
* The primary key and unmanaged columns are never nulled.
|
|
36
|
+
*/
|
|
37
|
+
recordToFullValues: (record: Record<string, unknown>, spec: TableSpec) => Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/marshal/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,WAAW,EAAE,CAAC,CAAC,SAAS,cAAc,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,KAAK,CAAC,CAAA;IAC3F;;;;;;;OAOG;IACH,cAAc,EAAE,CAAC,CAAC,SAAS,cAAc,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,KAAK,CAAC,CAAA;IAC9F;;;;;;OAMG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7F;;;;;;OAMG;IACH,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/marshal/types.ts"],"names":[],"mappings":""}
|
package/build/utils/marshal.d.ts
CHANGED
|
@@ -1,36 +1,8 @@
|
|
|
1
1
|
import type { ResourceRecord } from '@owlmeans/resource';
|
|
2
2
|
import type { TableSpec } from '../types.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Columns the spec doesn't know about — computed expressions, joined columns from custom
|
|
8
|
-
* SQL — are kept verbatim. A join result is more useful than a lossy projection.
|
|
9
|
-
*/
|
|
3
|
+
import type { PgMarshalHelper } from './marshal/types.js';
|
|
4
|
+
export declare const createPgMarshalHelper: () => PgMarshalHelper;
|
|
5
|
+
export declare const pgMarshalHelper: PgMarshalHelper;
|
|
6
|
+
/** @deprecated compat:factory-refactor — use `pgMarshalHelper.rowToRecord(…)` */
|
|
10
7
|
export declare const rowToRecord: <T extends ResourceRecord>(row: Record<string, unknown>, spec: TableSpec) => T;
|
|
11
|
-
/**
|
|
12
|
-
* Same coercion as {@link rowToRecord}, for rows Drizzle produced.
|
|
13
|
-
*
|
|
14
|
-
* Drizzle keys its results by the table object's JS property names — which are the schema
|
|
15
|
-
* property names — where raw SQL returns physical column names. Two functions rather than
|
|
16
|
-
* one lookup that tries both, because a schema that renames `a` to column `b` while another
|
|
17
|
-
* property is itself named `b` would make the combined lookup pick the wrong spec.
|
|
18
|
-
*/
|
|
19
|
-
export declare const resultToRecord: <T extends ResourceRecord>(row: Record<string, unknown>, spec: TableSpec) => T;
|
|
20
|
-
/**
|
|
21
|
-
* Turn a record into the values Drizzle inserts, keyed by property name (Drizzle owns the
|
|
22
|
-
* property to column mapping).
|
|
23
|
-
*
|
|
24
|
-
* `undefined` properties are dropped so a partial write touches only what was supplied;
|
|
25
|
-
* an explicit `null` is kept, because nulling a column is a real intent.
|
|
26
|
-
*/
|
|
27
|
-
export declare const recordToValues: (record: Record<string, unknown>, spec: TableSpec) => Record<string, unknown>;
|
|
28
|
-
/**
|
|
29
|
-
* Every managed column, with anything the record omits explicitly nulled.
|
|
30
|
-
*
|
|
31
|
-
* This is what makes `update()` a replace rather than a merge — the semantics mongo's
|
|
32
|
-
* `replaceOne` gives, kept identical so a resource behaves the same on either backend.
|
|
33
|
-
* The primary key and unmanaged columns are never nulled.
|
|
34
|
-
*/
|
|
35
|
-
export declare const recordToFullValues: (record: Record<string, unknown>, spec: TableSpec) => Record<string, unknown>;
|
|
36
8
|
//# sourceMappingURL=marshal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["../../src/utils/marshal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAKxD,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["../../src/utils/marshal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAKxD,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAIzD,eAAO,MAAM,qBAAqB,QAAO,eAiJxC,CAAA;AAED,eAAO,MAAM,eAAe,iBAA0B,CAAA;AAEtD,iFAAiF;AACjF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,cAAc,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,SAAS,KAAG,CAC3D,CAAA"}
|
package/build/utils/marshal.js
CHANGED
|
@@ -2,157 +2,134 @@ import { logThrottle, logger } from '@owlmeans/log';
|
|
|
2
2
|
import { types as pgTypes } from 'pg';
|
|
3
3
|
import { ID_FIELD, PgTypeOid } from '../consts.js';
|
|
4
4
|
const log = logger('postgres-resource');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
5
|
+
export const createPgMarshalHelper = () => {
|
|
6
|
+
/**
|
|
7
|
+
* Parse a temporal value the way the driver would have.
|
|
8
|
+
*
|
|
9
|
+
* Drizzle's node-postgres session installs its own `getTypeParser` that hands date and
|
|
10
|
+
* timestamp columns back as raw text, because its own statically declared column types do
|
|
11
|
+
* the conversion. Ours are compiled at runtime and can't, so the driver's parser is called
|
|
12
|
+
* directly — the same function, just later. Raw SQL never comes through here, since that
|
|
13
|
+
* path keeps the driver's default parsers.
|
|
14
|
+
*/
|
|
15
|
+
const toDate = (value, column) => {
|
|
16
|
+
const oid = column.sqlType.startsWith('timestamp with time zone')
|
|
17
|
+
? PgTypeOid.TimestampTz
|
|
18
|
+
: column.sqlType.startsWith('timestamp')
|
|
19
|
+
? PgTypeOid.Timestamp
|
|
20
|
+
: PgTypeOid.Date;
|
|
21
|
+
return pgTypes.getTypeParser(oid)(value);
|
|
22
|
+
};
|
|
23
|
+
const fromDriver = (value, column, table) => {
|
|
24
|
+
if (value == null) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/** Ciphertext is opaque — coercing it would corrupt it. */
|
|
28
|
+
if (column.secure) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
switch (column.jsonType) {
|
|
32
|
+
case 'number':
|
|
33
|
+
/** Postgres returns `numeric` as a string to protect precision the JS number can't hold. */
|
|
34
|
+
return typeof value === 'string' ? parseFloat(value) : value;
|
|
35
|
+
case 'integer':
|
|
36
|
+
return typeof value === 'string' ? parseInt(value, 10) : value;
|
|
37
|
+
case 'bigint': {
|
|
38
|
+
if (typeof value !== 'string' && typeof value !== 'bigint') {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
const parsed = Number(value);
|
|
42
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
43
|
+
// Fires per row read: one line per window per column is enough.
|
|
44
|
+
if (logThrottle(`postgres-resource:${table ?? ''}:${column.column}:unsafe-bigint`, 300_000)) {
|
|
45
|
+
log.warn('Bigint column value exceeds the safe integer range; the value read back is imprecise', {
|
|
46
|
+
table, column: column.column,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
47
49
|
}
|
|
50
|
+
return parsed;
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
case 'binary':
|
|
53
|
+
return Buffer.isBuffer(value) ? value.toString('base64') : value;
|
|
54
|
+
case 'date':
|
|
55
|
+
return typeof value === 'string' ? toDate(value, column) : value;
|
|
56
|
+
default:
|
|
57
|
+
return value;
|
|
50
58
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return typeof value === 'string' ? toDate(value, column) : value;
|
|
55
|
-
default:
|
|
59
|
+
};
|
|
60
|
+
const toDriver = (value, column) => {
|
|
61
|
+
if (value == null) {
|
|
56
62
|
return value;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
}
|
|
64
|
+
if (column.secure) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (column.jsonb) {
|
|
68
|
+
/**
|
|
69
|
+
* node-postgres stringifies plain objects on its own but turns arrays into Postgres
|
|
70
|
+
* array literals, which a jsonb column rejects. Stringifying here covers both.
|
|
71
|
+
*/
|
|
72
|
+
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
73
|
+
}
|
|
74
|
+
if (column.jsonType === 'date' && !(value instanceof Date)) {
|
|
75
|
+
return new Date(value);
|
|
76
|
+
}
|
|
77
|
+
if (column.jsonType === 'binary' && typeof value === 'string') {
|
|
78
|
+
return Buffer.from(value, 'base64');
|
|
79
|
+
}
|
|
64
80
|
return value;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
if (column.jsonType === 'binary' && typeof value === 'string') {
|
|
77
|
-
return Buffer.from(value, 'base64');
|
|
78
|
-
}
|
|
79
|
-
return value;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Turn a driver row into a record: physical column names back to schema property names,
|
|
83
|
-
* plus the coercions node-postgres leaves to the caller.
|
|
84
|
-
*
|
|
85
|
-
* Columns the spec doesn't know about — computed expressions, joined columns from custom
|
|
86
|
-
* SQL — are kept verbatim. A join result is more useful than a lossy projection.
|
|
87
|
-
*/
|
|
88
|
-
export const rowToRecord = (row, spec) => {
|
|
89
|
-
const record = {};
|
|
90
|
-
for (const [key, value] of Object.entries(row)) {
|
|
91
|
-
const column = spec.byColumn[key];
|
|
92
|
-
if (column == null) {
|
|
93
|
-
record[key] = value;
|
|
94
|
-
continue;
|
|
81
|
+
};
|
|
82
|
+
const rowToRecord = (row, spec) => {
|
|
83
|
+
const record = {};
|
|
84
|
+
for (const [key, value] of Object.entries(row)) {
|
|
85
|
+
const column = spec.byColumn[key];
|
|
86
|
+
if (column == null) {
|
|
87
|
+
record[key] = value;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
record[column.property] = fromDriver(value, column, spec.qualified);
|
|
95
91
|
}
|
|
96
|
-
record[
|
|
97
|
-
|
|
98
|
-
if (record[ID_FIELD] != null) {
|
|
99
|
-
record[ID_FIELD] = `${record[ID_FIELD]}`;
|
|
100
|
-
}
|
|
101
|
-
return record;
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Same coercion as {@link rowToRecord}, for rows Drizzle produced.
|
|
105
|
-
*
|
|
106
|
-
* Drizzle keys its results by the table object's JS property names — which are the schema
|
|
107
|
-
* property names — where raw SQL returns physical column names. Two functions rather than
|
|
108
|
-
* one lookup that tries both, because a schema that renames `a` to column `b` while another
|
|
109
|
-
* property is itself named `b` would make the combined lookup pick the wrong spec.
|
|
110
|
-
*/
|
|
111
|
-
export const resultToRecord = (row, spec) => {
|
|
112
|
-
const record = {};
|
|
113
|
-
for (const [key, value] of Object.entries(row)) {
|
|
114
|
-
const column = spec.byProperty[key];
|
|
115
|
-
record[key] = column == null ? value : fromDriver(value, column, spec.qualified);
|
|
116
|
-
}
|
|
117
|
-
if (record[ID_FIELD] != null) {
|
|
118
|
-
record[ID_FIELD] = `${record[ID_FIELD]}`;
|
|
119
|
-
}
|
|
120
|
-
return record;
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Turn a record into the values Drizzle inserts, keyed by property name (Drizzle owns the
|
|
124
|
-
* property to column mapping).
|
|
125
|
-
*
|
|
126
|
-
* `undefined` properties are dropped so a partial write touches only what was supplied;
|
|
127
|
-
* an explicit `null` is kept, because nulling a column is a real intent.
|
|
128
|
-
*/
|
|
129
|
-
export const recordToValues = (record, spec) => {
|
|
130
|
-
const values = {};
|
|
131
|
-
for (const [key, value] of Object.entries(record)) {
|
|
132
|
-
const column = spec.byProperty[key];
|
|
133
|
-
if (column == null || value === undefined) {
|
|
134
|
-
continue;
|
|
92
|
+
if (record[ID_FIELD] != null) {
|
|
93
|
+
record[ID_FIELD] = `${record[ID_FIELD]}`;
|
|
135
94
|
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
95
|
+
return record;
|
|
96
|
+
};
|
|
97
|
+
const resultToRecord = (row, spec) => {
|
|
98
|
+
const record = {};
|
|
99
|
+
for (const [key, value] of Object.entries(row)) {
|
|
100
|
+
const column = spec.byProperty[key];
|
|
101
|
+
record[key] = column == null ? value : fromDriver(value, column, spec.qualified);
|
|
102
|
+
}
|
|
103
|
+
if (record[ID_FIELD] != null) {
|
|
104
|
+
record[ID_FIELD] = `${record[ID_FIELD]}`;
|
|
105
|
+
}
|
|
106
|
+
return record;
|
|
107
|
+
};
|
|
108
|
+
const recordToValues = (record, spec) => {
|
|
109
|
+
const values = {};
|
|
110
|
+
for (const [key, value] of Object.entries(record)) {
|
|
111
|
+
const column = spec.byProperty[key];
|
|
112
|
+
if (column == null || value === undefined) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
values[column.property] = toDriver(value, column);
|
|
116
|
+
}
|
|
117
|
+
return values;
|
|
118
|
+
};
|
|
119
|
+
const recordToFullValues = (record, spec) => {
|
|
120
|
+
const values = {};
|
|
121
|
+
for (const column of spec.columns) {
|
|
122
|
+
if (spec.primaryKey.includes(column.column) || spec.unmanaged.includes(column.column)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const value = record[column.property];
|
|
126
|
+
values[column.property] = value === undefined ? null : toDriver(value, column);
|
|
152
127
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
return values;
|
|
128
|
+
return values;
|
|
129
|
+
};
|
|
130
|
+
return { rowToRecord, resultToRecord, recordToValues, recordToFullValues };
|
|
157
131
|
};
|
|
132
|
+
export const pgMarshalHelper = createPgMarshalHelper();
|
|
133
|
+
/** @deprecated compat:factory-refactor — use `pgMarshalHelper.rowToRecord(…)` */
|
|
134
|
+
export const rowToRecord = (row, spec) => pgMarshalHelper.rowToRecord(row, spec);
|
|
158
135
|
//# sourceMappingURL=marshal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marshal.js","sourceRoot":"","sources":["../../src/utils/marshal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,IAAI,CAAA;AAErC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"marshal.js","sourceRoot":"","sources":["../../src/utils/marshal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,IAAI,CAAA;AAErC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAIlD,MAAM,GAAG,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAEvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAoB,EAAE;IACzD;;;;;;;;OAQG;IACH,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,MAAkB,EAAW,EAAE;QAC5D,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,0BAA0B,CAAC;YAC/D,CAAC,CAAC,SAAS,CAAC,WAAW;YACvB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC;gBACtC,CAAC,CAAC,SAAS,CAAC,SAAS;gBACrB,CAAC,CAAC,SAAS,CAAC,IAAI,CAAA;QAEpB,OAAQ,OAAO,CAAC,aAAa,CAAC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AqB,EAAE,CAAA;AAEtD,iFAAiF;AACjF,MAAM,CAAC,MAAM,WAAW,GAAG,CAA2B,GAA4B,EAAE,IAAe,EAAK,EAAE,CACxG,eAAe,CAAC,WAAW,CAAI,GAAG,EAAE,IAAI,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,IAAI,CAAA;AAGpD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGxD;;;GAGG;AACH,eAAO,MAAM,MAAM,WACT,UAAU,WAAW,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,KACrF,
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,IAAI,CAAA;AAGpD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGxD;;;GAGG;AACH,eAAO,MAAM,MAAM,WACT,UAAU,WAAW,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,KACrF,UAsCF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,WACrB,UAAU,QACZ,SAAS,SACR,MAAM,WACJ,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,OAC5B,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,KAC9B,cAAc,CAAC,UAAU,CA8E3B,CAAA"}
|
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { pgErrorHelper } from '../pg-error.js';
|
|
2
|
+
import { pgNameHelper } from './name.js';
|
|
3
3
|
/**
|
|
4
4
|
* A transaction façade over a checked out client. `{{alias}}` resolution is injected so
|
|
5
5
|
* migrations can address other resources by alias without importing the context.
|
|
6
6
|
*/
|
|
7
|
-
export const makeTx = (client, resolve, ref) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
7
|
+
export const makeTx = (client, resolve, ref) => {
|
|
8
|
+
const { pgErrorToResourceError } = pgErrorHelper;
|
|
9
|
+
return {
|
|
10
|
+
client,
|
|
11
|
+
query: async (text, params) => {
|
|
12
|
+
const query = resolve(text);
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.query(query, params);
|
|
15
|
+
return result.rows;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw pgErrorToResourceError(error, query);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
queryOne: async (text, params) => {
|
|
22
|
+
const query = resolve(text);
|
|
23
|
+
try {
|
|
24
|
+
const result = await client.query(query, params);
|
|
25
|
+
return result.rows[0] ?? null;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw pgErrorToResourceError(error, query);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
execute: async (text, params) => {
|
|
32
|
+
const query = resolve(text);
|
|
33
|
+
try {
|
|
34
|
+
const result = await client.query(query, params);
|
|
35
|
+
return result.rowCount ?? 0;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw pgErrorToResourceError(error, query);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
ref
|
|
42
|
+
};
|
|
43
|
+
};
|
|
41
44
|
/**
|
|
42
45
|
* Migration ledger, one table per Postgres schema.
|
|
43
46
|
*
|
|
@@ -45,6 +48,8 @@ export const makeTx = (client, resolve, ref) => ({
|
|
|
45
48
|
* tables it holds — correct, because those tables are what the migrations changed.
|
|
46
49
|
*/
|
|
47
50
|
export const makeMigrationStore = (client, spec, table, resolve, ref) => {
|
|
51
|
+
const { pgErrorToResourceError } = pgErrorHelper;
|
|
52
|
+
const { qualify, quoteIdent } = pgNameHelper;
|
|
48
53
|
const ledger = qualify(spec.schema, table);
|
|
49
54
|
return {
|
|
50
55
|
ensure: async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/utils/migrations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,MAAkB,EAAE,OAAiC,EAAE,GAA+B,EAC1E,EAAE;IACd,MAAM,EAAE,sBAAsB,EAAE,GAAG,aAAa,CAAA;IAEhD,OAAO;QACL,MAAM;QAEN,KAAK,EAAE,KAAK,EAA+C,IAAY,EAAE,MAAkB,EAAE,EAAE;YAC7F,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;YAC3B,IAAI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1B,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAC3B,IAAI,CAAC;gBACH,MAAM,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;gBACnD;;;mBAGG;gBACH,MAAM,MAAM,CAAC,KAAK,CAChB,eAAe,MAAM,KAAK,UAAU,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,OAAO,CAAC,GAAG;sBAC7F,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC,aAAa,CAAC,+BAA+B,EACzF,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAY,CAC9F,CAAA;gBACD,MAAM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YAC9B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;gBACrD,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DbConfig, ResourceRecord } from '@owlmeans/resource';
|
|
2
|
+
import type { PostgresResource } from '../../types.js';
|
|
3
|
+
/** Postgres identifiers and literals: sanitizing, asserting, quoting and naming. */
|
|
4
|
+
export interface PgNameHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Coerce an arbitrary name into a legal Postgres identifier of at most 63 bytes.
|
|
7
|
+
*
|
|
8
|
+
* Postgres cuts anything past `NAMEDATALEN - 1` off server side and says nothing about
|
|
9
|
+
* it, so two names that differ only beyond byte 63 would collapse into one identifier.
|
|
10
|
+
* Clamping here instead leaves room for a hash suffix that keeps them apart.
|
|
11
|
+
*/
|
|
12
|
+
pgIdentifier: (name: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Assert a value is safe to interpolate as an identifier. Postgres can't bind identifiers
|
|
15
|
+
* as parameters, so every one of them reaches the server as text — which makes this the
|
|
16
|
+
* only thing standing between a config value and injection.
|
|
17
|
+
*
|
|
18
|
+
* @throws {SyntaxError}
|
|
19
|
+
*/
|
|
20
|
+
assertSqlIdentifier: (value: string, what?: string) => string;
|
|
21
|
+
/** Quote an identifier for emission, doubling any interior quote. */
|
|
22
|
+
quoteIdent: (value: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Quote a string literal. Only ever used for values Postgres refuses to bind — notably
|
|
25
|
+
* the password in `CREATE ROLE`.
|
|
26
|
+
*
|
|
27
|
+
* @throws {SyntaxError} on a NUL byte, which no escaping makes safe.
|
|
28
|
+
*/
|
|
29
|
+
quoteLiteral: (value: string) => string;
|
|
30
|
+
/** `"schema"."table"`, each part quoted. */
|
|
31
|
+
qualify: (schema: string, table: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Physical table name of a resource: the explicit `name`, else the resource alias,
|
|
34
|
+
* prefixed per `DbConfig.resourcePrefix` and sanitized.
|
|
35
|
+
*/
|
|
36
|
+
pgTableName: (config: DbConfig, resource: PostgresResource<ResourceRecord>) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Derive a pair of int32s for `pg_advisory_lock` from a qualified table name, so every
|
|
39
|
+
* replica booting against the same table serializes on the same key.
|
|
40
|
+
*/
|
|
41
|
+
advisoryKey: (qualified: string) => [number, number];
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/name/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAElE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACtC;;;;;;OAMG;IACH,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IAC7D,qEAAqE;IACrE,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACrC;;;;;OAKG;IACH,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACvC,4CAA4C;IAC5C,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IAClD;;;OAGG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,KAAK,MAAM,CAAA;IACrF;;;OAGG;IACH,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/name/types.ts"],"names":[],"mappings":""}
|