@owlmeans/postgres-resource 0.1.15
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/LICENSE +21 -0
- package/README.md +219 -0
- package/agent-meta/instructions/postgres-resource.instructions.md +60 -0
- package/agent-meta/manifest.json +23 -0
- package/agent-meta/skills/postgres-resource/SKILL.md +186 -0
- package/build/consts.d.ts +81 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +86 -0
- package/build/consts.js.map +1 -0
- package/build/declarations.d.ts +12 -0
- package/build/declarations.d.ts.map +1 -0
- package/build/declarations.js +28 -0
- package/build/declarations.js.map +1 -0
- package/build/errors.d.ts +70 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +201 -0
- package/build/errors.js.map +1 -0
- package/build/helper.d.ts +4 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +5 -0
- package/build/helper.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -0
- package/build/resource.d.ts +4 -0
- package/build/resource.d.ts.map +1 -0
- package/build/resource.js +395 -0
- package/build/resource.js.map +1 -0
- package/build/types.d.ts +273 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/utils/criteria.d.ts +24 -0
- package/build/utils/criteria.d.ts.map +1 -0
- package/build/utils/criteria.js +209 -0
- package/build/utils/criteria.js.map +1 -0
- package/build/utils/diff.d.ts +24 -0
- package/build/utils/diff.d.ts.map +1 -0
- package/build/utils/diff.js +330 -0
- package/build/utils/diff.js.map +1 -0
- package/build/utils/index.d.ts +12 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +12 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/introspect.d.ts +7 -0
- package/build/utils/introspect.d.ts.map +1 -0
- package/build/utils/introspect.js +70 -0
- package/build/utils/introspect.js.map +1 -0
- package/build/utils/life-cycle.d.ts +39 -0
- package/build/utils/life-cycle.d.ts.map +1 -0
- package/build/utils/life-cycle.js +119 -0
- package/build/utils/life-cycle.js.map +1 -0
- package/build/utils/marshal.d.ts +36 -0
- package/build/utils/marshal.d.ts.map +1 -0
- package/build/utils/marshal.js +152 -0
- package/build/utils/marshal.js.map +1 -0
- package/build/utils/migrations.d.ts +16 -0
- package/build/utils/migrations.d.ts.map +1 -0
- package/build/utils/migrations.js +108 -0
- package/build/utils/migrations.js.map +1 -0
- package/build/utils/name.d.ts +39 -0
- package/build/utils/name.d.ts.map +1 -0
- package/build/utils/name.js +63 -0
- package/build/utils/name.js.map +1 -0
- package/build/utils/schema.d.ts +28 -0
- package/build/utils/schema.d.ts.map +1 -0
- package/build/utils/schema.js +356 -0
- package/build/utils/schema.js.map +1 -0
- package/build/utils/sql.d.ts +22 -0
- package/build/utils/sql.d.ts.map +1 -0
- package/build/utils/sql.js +0 -0
- package/build/utils/sql.js.map +1 -0
- package/build/utils/sync.d.ts +21 -0
- package/build/utils/sync.d.ts.map +1 -0
- package/build/utils/sync.js +93 -0
- package/build/utils/sync.js.map +1 -0
- package/build/utils/table.d.ts +8 -0
- package/build/utils/table.d.ts.map +1 -0
- package/build/utils/table.js +68 -0
- package/build/utils/table.js.map +1 -0
- package/package.json +50 -0
- package/src/consts.ts +95 -0
- package/src/declarations.ts +41 -0
- package/src/errors.ts +242 -0
- package/src/helper.ts +7 -0
- package/src/index.ts +7 -0
- package/src/resource.ts +524 -0
- package/src/types.ts +310 -0
- package/src/utils/criteria.ts +246 -0
- package/src/utils/diff.ts +363 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/introspect.ts +87 -0
- package/src/utils/life-cycle.ts +155 -0
- package/src/utils/marshal.ts +175 -0
- package/src/utils/migrations.ts +135 -0
- package/src/utils/name.ts +79 -0
- package/src/utils/schema.ts +426 -0
- package/src/utils/sql.ts +0 -0
- package/src/utils/sync.ts +106 -0
- package/src/utils/table.ts +76 -0
- package/tests/errors.spec.ts +121 -0
- package/tests/name.spec.ts +75 -0
- package/tests/schema.spec.ts +258 -0
- package/tests/sql.spec.ts +104 -0
- package/tsconfig.json +16 -0
package/build/consts.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export const DEFAULT_DB_ALIAS = 'postgres';
|
|
2
|
+
export const DEFAULT_PAGE_SIZE = 10;
|
|
3
|
+
/**
|
|
4
|
+
* Table that records which code-registered migrations have already been applied.
|
|
5
|
+
* Lives in the same Postgres schema as the resources it tracks, so dropping the
|
|
6
|
+
* schema drops the ledger with it.
|
|
7
|
+
*/
|
|
8
|
+
export const DEF_MIGRATIONS_TABLE = '_owlmeans_migrations';
|
|
9
|
+
/** JSON Schema keyword carrying the Postgres specific overrides. */
|
|
10
|
+
export const PG_KEYWORD = 'pg';
|
|
11
|
+
/** Postgres `NAMEDATALEN - 1`. Identifiers past this are silently truncated by the server. */
|
|
12
|
+
export const PG_MAX_IDENTIFIER = 63;
|
|
13
|
+
/** Property name that carries the record identity across every OwlMeans resource. */
|
|
14
|
+
export const ID_FIELD = 'id';
|
|
15
|
+
/** Fallback when a scalar property can't be mapped to anything more specific. */
|
|
16
|
+
export const DEF_SQL_TYPE = 'text';
|
|
17
|
+
export const DEF_JSON_TYPE = 'jsonb';
|
|
18
|
+
/** Server side identity default for the implicit `id` primary key. */
|
|
19
|
+
export const DEF_ID_DEFAULT = 'gen_random_uuid()::text';
|
|
20
|
+
/**
|
|
21
|
+
* How far structure reconciliation is allowed to go.
|
|
22
|
+
*
|
|
23
|
+
* `additive` is the adoption path for a table this package didn't create: it adds what's
|
|
24
|
+
* missing but never retypes and never drops, so a first boot against an existing schema
|
|
25
|
+
* converges without touching data. Flip to `full` once the plan comes out empty.
|
|
26
|
+
*/
|
|
27
|
+
export var PgAutoSync;
|
|
28
|
+
(function (PgAutoSync) {
|
|
29
|
+
PgAutoSync["Full"] = "full";
|
|
30
|
+
PgAutoSync["Additive"] = "additive";
|
|
31
|
+
PgAutoSync["Off"] = "off";
|
|
32
|
+
})(PgAutoSync || (PgAutoSync = {}));
|
|
33
|
+
export var PgIndexMethod;
|
|
34
|
+
(function (PgIndexMethod) {
|
|
35
|
+
PgIndexMethod["BTree"] = "btree";
|
|
36
|
+
PgIndexMethod["Hash"] = "hash";
|
|
37
|
+
PgIndexMethod["Gin"] = "gin";
|
|
38
|
+
PgIndexMethod["Gist"] = "gist";
|
|
39
|
+
PgIndexMethod["Brin"] = "brin";
|
|
40
|
+
PgIndexMethod["SpGist"] = "spgist";
|
|
41
|
+
})(PgIndexMethod || (PgIndexMethod = {}));
|
|
42
|
+
export var PgReferentialAction;
|
|
43
|
+
(function (PgReferentialAction) {
|
|
44
|
+
PgReferentialAction["NoAction"] = "no action";
|
|
45
|
+
PgReferentialAction["Restrict"] = "restrict";
|
|
46
|
+
PgReferentialAction["Cascade"] = "cascade";
|
|
47
|
+
PgReferentialAction["SetNull"] = "set null";
|
|
48
|
+
PgReferentialAction["SetDefault"] = "set default";
|
|
49
|
+
})(PgReferentialAction || (PgReferentialAction = {}));
|
|
50
|
+
/**
|
|
51
|
+
* Postgres error codes the resource layer translates into framework errors. Sourced
|
|
52
|
+
* from the `pg` driver's `DatabaseError.code`.
|
|
53
|
+
*/
|
|
54
|
+
export var PgErrorCode;
|
|
55
|
+
(function (PgErrorCode) {
|
|
56
|
+
PgErrorCode["UniqueViolation"] = "23505";
|
|
57
|
+
PgErrorCode["ForeignKeyViolation"] = "23503";
|
|
58
|
+
PgErrorCode["NotNullViolation"] = "23502";
|
|
59
|
+
PgErrorCode["CheckViolation"] = "23514";
|
|
60
|
+
PgErrorCode["UndefinedTable"] = "42P01";
|
|
61
|
+
PgErrorCode["UndefinedColumn"] = "42703";
|
|
62
|
+
PgErrorCode["DuplicateTable"] = "42P07";
|
|
63
|
+
PgErrorCode["DuplicateColumn"] = "42701";
|
|
64
|
+
PgErrorCode["DuplicateObject"] = "42710";
|
|
65
|
+
PgErrorCode["CannotCoerce"] = "42846";
|
|
66
|
+
PgErrorCode["DatatypeMismatch"] = "42804";
|
|
67
|
+
PgErrorCode["InvalidTextRepresentation"] = "22P02";
|
|
68
|
+
PgErrorCode["StringDataRightTruncation"] = "22001";
|
|
69
|
+
PgErrorCode["NumericValueOutOfRange"] = "22003";
|
|
70
|
+
PgErrorCode["SerializationFailure"] = "40001";
|
|
71
|
+
PgErrorCode["DeadlockDetected"] = "40P01";
|
|
72
|
+
PgErrorCode["NoActiveTransaction"] = "25001";
|
|
73
|
+
})(PgErrorCode || (PgErrorCode = {}));
|
|
74
|
+
/**
|
|
75
|
+
* Postgres reports scalar values of these types as strings to avoid precision loss.
|
|
76
|
+
* The marshaller converts them back using the resource's schema.
|
|
77
|
+
*/
|
|
78
|
+
export const STRING_RETURNING_TYPES = ['numeric', 'bigint', 'int8', 'decimal', 'money'];
|
|
79
|
+
/** Built-in type OIDs the marshaller has to name to reach the driver's own parsers. */
|
|
80
|
+
export var PgTypeOid;
|
|
81
|
+
(function (PgTypeOid) {
|
|
82
|
+
PgTypeOid[PgTypeOid["Date"] = 1082] = "Date";
|
|
83
|
+
PgTypeOid[PgTypeOid["Timestamp"] = 1114] = "Timestamp";
|
|
84
|
+
PgTypeOid[PgTypeOid["TimestampTz"] = 1184] = "TimestampTz";
|
|
85
|
+
})(PgTypeOid || (PgTypeOid = {}));
|
|
86
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAA;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAA;AAE1D,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAA;AAE9B,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,E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,CAAA;AAC/B,CAAC,EAlBW,WAAW,KAAX,WAAW,QAkBtB;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA;AAEhG,uFAAuF;AACvF,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,4CAAW,CAAA;IACX,sDAAgB,CAAA;IAChB,0DAAkB,CAAA;AACpB,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MigrationRegistry } from '@owlmeans/resource';
|
|
2
|
+
import type { AnySchema } from 'ajv';
|
|
3
|
+
import type { PgIndexSpec, PostgresTx } from './types.js';
|
|
4
|
+
export interface PostgresDeclaration {
|
|
5
|
+
schema?: AnySchema;
|
|
6
|
+
indexes: PgIndexSpec[];
|
|
7
|
+
migrations: MigrationRegistry<PostgresTx>;
|
|
8
|
+
}
|
|
9
|
+
export declare const getDeclaration: (alias: string) => PostgresDeclaration;
|
|
10
|
+
/** Testing seam — drops every declaration so a spec can redeclare a resource from scratch. */
|
|
11
|
+
export declare const resetDeclarations: (alias?: string) => void;
|
|
12
|
+
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEzD,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,UAAU,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAA;CAC1C;AAaD,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,mBAQ9C,CAAA;AAED,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,IAMlD,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createMigrationRegistry } from '@owlmeans/resource';
|
|
2
|
+
/**
|
|
3
|
+
* Per-alias declaration store, held at module scope rather than on the resource object.
|
|
4
|
+
*
|
|
5
|
+
* `reinitializeContext` rebuilds every resource, which drops anything a caller attached
|
|
6
|
+
* by chaining. Mongo lives with that by requiring the app to pass `makeCustomResource`
|
|
7
|
+
* and re-run the whole maker; migrations can't depend on that discipline, because losing
|
|
8
|
+
* one silently means a data transformation never runs. Keying the declarations by alias
|
|
9
|
+
* makes them survive any number of context switches.
|
|
10
|
+
*/
|
|
11
|
+
const declarations = new Map();
|
|
12
|
+
export const getDeclaration = (alias) => {
|
|
13
|
+
let declaration = declarations.get(alias);
|
|
14
|
+
if (declaration == null) {
|
|
15
|
+
declaration = { indexes: [], migrations: createMigrationRegistry() };
|
|
16
|
+
declarations.set(alias, declaration);
|
|
17
|
+
}
|
|
18
|
+
return declaration;
|
|
19
|
+
};
|
|
20
|
+
/** Testing seam — drops every declaration so a spec can redeclare a resource from scratch. */
|
|
21
|
+
export const resetDeclarations = (alias) => {
|
|
22
|
+
if (alias == null) {
|
|
23
|
+
declarations.clear();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
declarations.delete(alias);
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAY5D;;;;;;;;GAQG;AACH,MAAM,YAAY,GAAqC,IAAI,GAAG,EAAE,CAAA;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAuB,EAAE;IACnE,IAAI,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,WAAW,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,uBAAuB,EAAc,EAAE,CAAA;QAChF,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAED,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAQ,EAAE;IACxD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,YAAY,CAAC,KAAK,EAAE,CAAA;QACpB,OAAM;IACR,CAAC;IACD,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ResourceError } from '@owlmeans/resource';
|
|
2
|
+
export declare class PostgresError extends ResourceError {
|
|
3
|
+
static typeName: string;
|
|
4
|
+
constructor(message?: string);
|
|
5
|
+
}
|
|
6
|
+
/** Structure reconciliation failed. The message carries the offending statement. */
|
|
7
|
+
export declare class PostgresSyncError extends PostgresError {
|
|
8
|
+
static typeName: string;
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Postgres refused to cast a column to its new type. Fix it with `pg: { using: '<expr>' }`
|
|
13
|
+
* on the property, or with a `pre` migration that performs the ALTER by hand — after
|
|
14
|
+
* which reconciliation sees no drift and emits nothing.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PostgresCastRequired extends PostgresSyncError {
|
|
17
|
+
static typeName: string;
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class PostgresConstraintError extends PostgresError {
|
|
21
|
+
static typeName: string;
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class PostgresForeignKeyError extends PostgresConstraintError {
|
|
25
|
+
static typeName: string;
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class PostgresCheckError extends PostgresConstraintError {
|
|
29
|
+
static typeName: string;
|
|
30
|
+
constructor(message: string);
|
|
31
|
+
}
|
|
32
|
+
/** Serialization failure or deadlock — the caller may retry the whole transaction. */
|
|
33
|
+
export declare class PostgresDeadlockError extends PostgresError {
|
|
34
|
+
static typeName: string;
|
|
35
|
+
readonly retryable: boolean;
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
38
|
+
/** A `{{alias}}` placeholder in custom SQL couldn't be resolved. */
|
|
39
|
+
export declare class PostgresPlaceholderError extends PostgresError {
|
|
40
|
+
static typeName: string;
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
export declare class PostgresConnectionError extends PostgresError {
|
|
44
|
+
static typeName: string;
|
|
45
|
+
constructor(message: string);
|
|
46
|
+
}
|
|
47
|
+
/** The least-privilege admin path failed. */
|
|
48
|
+
export declare class PostgresBootstrapError extends PostgresError {
|
|
49
|
+
static typeName: string;
|
|
50
|
+
constructor(message: string);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The framework's error marshalling preserves only type, message and stack, so the
|
|
54
|
+
* Postgres diagnostics have to travel inside the message. Downstream tooling — notably
|
|
55
|
+
* the viable-agent fixer, which retries on `42P01` / `42703` — classifies on exactly
|
|
56
|
+
* this text, so the code always leads.
|
|
57
|
+
*
|
|
58
|
+
* `where` is deliberately never included: it can echo bound parameter values.
|
|
59
|
+
*
|
|
60
|
+
* Exported so a wrapper can quote the diagnostics without also quoting the translated error's
|
|
61
|
+
* own type prefix, which would nest one error vocabulary inside another's message.
|
|
62
|
+
*/
|
|
63
|
+
export declare const describePgError: (error: unknown) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Translate a raw `pg` driver error into the framework's error vocabulary, so a driver
|
|
66
|
+
* type never escapes the package. Errors that already are `ResilientError`s pass through
|
|
67
|
+
* untouched — the reconciler and the migration runner raise their own.
|
|
68
|
+
*/
|
|
69
|
+
export declare const pgErrorToResourceError: (error: unknown) => Error;
|
|
70
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAC0B,aAAa,EAC7C,MAAM,oBAAoB,CAAA;AAI3B,qBAAa,aAAc,SAAQ,aAAa;IAC9C,OAAuB,QAAQ,SAA2C;gBAE9D,OAAO,GAAE,MAAgB;CAItC;AAED,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAuB,QAAQ,SAAuC;gBAE1D,OAAO,EAAE,MAAM;CAI5B;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;IACzD,OAAuB,QAAQ,SAA8C;gBAEjE,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,OAAuB,QAAQ,SAA6C;gBAEhE,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,uBAAuB;IAClE,OAAuB,QAAQ,SAAkD;gBAErE,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,uBAAuB;IAC7D,OAAuB,QAAQ,SAA6C;gBAEhE,OAAO,EAAE,MAAM;CAI5B;AAED,sFAAsF;AACtF,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,OAAuB,QAAQ,SAA2C;IAE1E,SAAgB,SAAS,EAAE,OAAO,CAAO;gBAE7B,OAAO,EAAE,MAAM;CAI5B;AAED,oEAAoE;AACpE,qBAAa,wBAAyB,SAAQ,aAAa;IACzD,OAAuB,QAAQ,SAA8C;gBAEjE,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,OAAuB,QAAQ,SAA6C;gBAEhE,OAAO,EAAE,MAAM;CAI5B;AAED,6CAA6C;AAC7C,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,OAAuB,QAAQ,SAA4C;gBAE/D,OAAO,EAAE,MAAM;CAI5B;AA0CD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAOhD,CAAA;AAeD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,OAAO,KAAG,KA4CvD,CAAA"}
|
package/build/errors.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { ResilientError } from '@owlmeans/error';
|
|
2
|
+
import { MisshapedRecord, RecordExists, ResourceError } from '@owlmeans/resource';
|
|
3
|
+
import { PgErrorCode } from './consts.js';
|
|
4
|
+
export class PostgresError extends ResourceError {
|
|
5
|
+
static typeName = `${ResourceError.typeName}PostgresError`;
|
|
6
|
+
constructor(message = 'error') {
|
|
7
|
+
super(`postgres:${message}`);
|
|
8
|
+
this.type = PostgresError.typeName;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Structure reconciliation failed. The message carries the offending statement. */
|
|
12
|
+
export class PostgresSyncError extends PostgresError {
|
|
13
|
+
static typeName = `${PostgresError.typeName}SyncError`;
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(`sync:${message}`);
|
|
16
|
+
this.type = PostgresSyncError.typeName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Postgres refused to cast a column to its new type. Fix it with `pg: { using: '<expr>' }`
|
|
21
|
+
* on the property, or with a `pre` migration that performs the ALTER by hand — after
|
|
22
|
+
* which reconciliation sees no drift and emits nothing.
|
|
23
|
+
*/
|
|
24
|
+
export class PostgresCastRequired extends PostgresSyncError {
|
|
25
|
+
static typeName = `${PostgresSyncError.typeName}CastRequired`;
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(`cast-required:${message}`);
|
|
28
|
+
this.type = PostgresCastRequired.typeName;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class PostgresConstraintError extends PostgresError {
|
|
32
|
+
static typeName = `${PostgresError.typeName}ConstraintError`;
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super(`constraint:${message}`);
|
|
35
|
+
this.type = PostgresConstraintError.typeName;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class PostgresForeignKeyError extends PostgresConstraintError {
|
|
39
|
+
static typeName = `${PostgresConstraintError.typeName}ForeignKey`;
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(`foreign-key:${message}`);
|
|
42
|
+
this.type = PostgresForeignKeyError.typeName;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class PostgresCheckError extends PostgresConstraintError {
|
|
46
|
+
static typeName = `${PostgresConstraintError.typeName}Check`;
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(`check:${message}`);
|
|
49
|
+
this.type = PostgresCheckError.typeName;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Serialization failure or deadlock — the caller may retry the whole transaction. */
|
|
53
|
+
export class PostgresDeadlockError extends PostgresError {
|
|
54
|
+
static typeName = `${PostgresError.typeName}DeadlockError`;
|
|
55
|
+
retryable = true;
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(`deadlock:${message}`);
|
|
58
|
+
this.type = PostgresDeadlockError.typeName;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** A `{{alias}}` placeholder in custom SQL couldn't be resolved. */
|
|
62
|
+
export class PostgresPlaceholderError extends PostgresError {
|
|
63
|
+
static typeName = `${PostgresError.typeName}PlaceholderError`;
|
|
64
|
+
constructor(message) {
|
|
65
|
+
super(`placeholder:${message}`);
|
|
66
|
+
this.type = PostgresPlaceholderError.typeName;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class PostgresConnectionError extends PostgresError {
|
|
70
|
+
static typeName = `${PostgresError.typeName}ConnectionError`;
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super(`connection:${message}`);
|
|
73
|
+
this.type = PostgresConnectionError.typeName;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The least-privilege admin path failed. */
|
|
77
|
+
export class PostgresBootstrapError extends PostgresError {
|
|
78
|
+
static typeName = `${PostgresError.typeName}BootstrapError`;
|
|
79
|
+
constructor(message) {
|
|
80
|
+
super(`bootstrap:${message}`);
|
|
81
|
+
this.type = PostgresBootstrapError.typeName;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const isDriverError = (error) => error != null && typeof error === 'object' && 'code' in error;
|
|
85
|
+
/**
|
|
86
|
+
* Reach the `pg` error inside whatever wrapped it.
|
|
87
|
+
*
|
|
88
|
+
* Drizzle raises `DrizzleQueryError` and hangs the driver error off `cause`, so a unique
|
|
89
|
+
* violation arriving through the query builder carries no `code` at the top level. Reading
|
|
90
|
+
* only the outer error is what makes the whole vocabulary below collapse to one opaque
|
|
91
|
+
* class on every CRUD path — and it is exactly the paths that go through Drizzle.
|
|
92
|
+
*
|
|
93
|
+
* The walk is bounded because `cause` chains can be circular.
|
|
94
|
+
*/
|
|
95
|
+
const unwrap = (error) => {
|
|
96
|
+
let current = error;
|
|
97
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
98
|
+
if (isDriverError(current)) {
|
|
99
|
+
return current;
|
|
100
|
+
}
|
|
101
|
+
const cause = current?.cause;
|
|
102
|
+
if (cause == null || cause === current) {
|
|
103
|
+
return error;
|
|
104
|
+
}
|
|
105
|
+
current = cause;
|
|
106
|
+
}
|
|
107
|
+
return error;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* The framework's error marshalling preserves only type, message and stack, so the
|
|
111
|
+
* Postgres diagnostics have to travel inside the message. Downstream tooling — notably
|
|
112
|
+
* the viable-agent fixer, which retries on `42P01` / `42703` — classifies on exactly
|
|
113
|
+
* this text, so the code always leads.
|
|
114
|
+
*
|
|
115
|
+
* `where` is deliberately never included: it can echo bound parameter values.
|
|
116
|
+
*
|
|
117
|
+
* Exported so a wrapper can quote the diagnostics without also quoting the translated error's
|
|
118
|
+
* own type prefix, which would nest one error vocabulary inside another's message.
|
|
119
|
+
*/
|
|
120
|
+
export const describePgError = (error) => {
|
|
121
|
+
const driver = unwrap(error);
|
|
122
|
+
if (!isDriverError(driver)) {
|
|
123
|
+
return error instanceof Error ? error.message : `${error}`;
|
|
124
|
+
}
|
|
125
|
+
return describe(driver);
|
|
126
|
+
};
|
|
127
|
+
const describe = (error) => {
|
|
128
|
+
const parts = [error.code ?? 'unknown'];
|
|
129
|
+
if (error.message != null)
|
|
130
|
+
parts.push(error.message);
|
|
131
|
+
if (error.constraint != null)
|
|
132
|
+
parts.push(`constraint=${error.constraint}`);
|
|
133
|
+
if (error.table != null)
|
|
134
|
+
parts.push(`table=${error.table}`);
|
|
135
|
+
if (error.column != null)
|
|
136
|
+
parts.push(`column=${error.column}`);
|
|
137
|
+
if (error.detail != null)
|
|
138
|
+
parts.push(`detail=${error.detail}`);
|
|
139
|
+
if (error.hint != null)
|
|
140
|
+
parts.push(`hint=${error.hint}`);
|
|
141
|
+
if (error.severity != null)
|
|
142
|
+
parts.push(`severity=${error.severity}`);
|
|
143
|
+
return parts.join(' ');
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Translate a raw `pg` driver error into the framework's error vocabulary, so a driver
|
|
147
|
+
* type never escapes the package. Errors that already are `ResilientError`s pass through
|
|
148
|
+
* untouched — the reconciler and the migration runner raise their own.
|
|
149
|
+
*/
|
|
150
|
+
export const pgErrorToResourceError = (error) => {
|
|
151
|
+
if (error instanceof ResilientError) {
|
|
152
|
+
return error;
|
|
153
|
+
}
|
|
154
|
+
const driver = unwrap(error);
|
|
155
|
+
if (!isDriverError(driver)) {
|
|
156
|
+
return error instanceof Error ? error : new PostgresError(`${error}`);
|
|
157
|
+
}
|
|
158
|
+
const message = describe(driver);
|
|
159
|
+
const produce = () => {
|
|
160
|
+
switch (driver.code) {
|
|
161
|
+
case PgErrorCode.UniqueViolation:
|
|
162
|
+
return new RecordExists(message);
|
|
163
|
+
case PgErrorCode.NotNullViolation:
|
|
164
|
+
return new MisshapedRecord(message);
|
|
165
|
+
case PgErrorCode.ForeignKeyViolation:
|
|
166
|
+
return new PostgresForeignKeyError(message);
|
|
167
|
+
case PgErrorCode.CheckViolation:
|
|
168
|
+
return new PostgresCheckError(message);
|
|
169
|
+
case PgErrorCode.DatatypeMismatch:
|
|
170
|
+
case PgErrorCode.CannotCoerce:
|
|
171
|
+
return new PostgresCastRequired(message);
|
|
172
|
+
case PgErrorCode.SerializationFailure:
|
|
173
|
+
case PgErrorCode.DeadlockDetected:
|
|
174
|
+
return new PostgresDeadlockError(message);
|
|
175
|
+
default:
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
if (driver.code != null && driver.code.startsWith('08')) {
|
|
179
|
+
return new PostgresConnectionError(message);
|
|
180
|
+
}
|
|
181
|
+
if (driver.code != null && driver.code.startsWith('23')) {
|
|
182
|
+
return new PostgresConstraintError(message);
|
|
183
|
+
}
|
|
184
|
+
return new PostgresError(message);
|
|
185
|
+
};
|
|
186
|
+
const produced = produce();
|
|
187
|
+
/** The *original* error, wrapper and all — unwrapping is for classification, not for loss. */
|
|
188
|
+
produced.cause = error;
|
|
189
|
+
return produced;
|
|
190
|
+
};
|
|
191
|
+
ResilientError.registerErrorClass(PostgresError);
|
|
192
|
+
ResilientError.registerErrorClass(PostgresSyncError);
|
|
193
|
+
ResilientError.registerErrorClass(PostgresCastRequired);
|
|
194
|
+
ResilientError.registerErrorClass(PostgresConstraintError);
|
|
195
|
+
ResilientError.registerErrorClass(PostgresForeignKeyError);
|
|
196
|
+
ResilientError.registerErrorClass(PostgresCheckError);
|
|
197
|
+
ResilientError.registerErrorClass(PostgresDeadlockError);
|
|
198
|
+
ResilientError.registerErrorClass(PostgresPlaceholderError);
|
|
199
|
+
ResilientError.registerErrorClass(PostgresConnectionError);
|
|
200
|
+
ResilientError.registerErrorClass(PostgresBootstrapError);
|
|
201
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EACL,eAAe,EAAE,YAAY,EAAE,aAAa,EAC7C,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,OAAO,aAAc,SAAQ,aAAa;IACvC,MAAM,CAAU,QAAQ,GAAG,GAAG,aAAa,CAAC,QAAQ,eAAe,CAAA;IAE1E,YAAY,UAAkB,OAAO;QACnC,KAAK,CAAC,YAAY,OAAO,EAAE,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAA;IACpC,CAAC;;AAGH,oFAAoF;AACpF,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAC3C,MAAM,CAAU,QAAQ,GAAG,GAAG,aAAa,CAAC,QAAQ,WAAW,CAAA;IAEtE,YAAY,OAAe;QACzB,KAAK,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,QAAQ,CAAA;IACxC,CAAC;;AAGH;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IAClD,MAAM,CAAU,QAAQ,GAAG,GAAG,iBAAiB,CAAC,QAAQ,cAAc,CAAA;IAE7E,YAAY,OAAe;QACzB,KAAK,CAAC,iBAAiB,OAAO,EAAE,CAAC,CAAA;QACjC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC,QAAQ,CAAA;IAC3C,CAAC;;AAGH,MAAM,OAAO,uBAAwB,SAAQ,aAAa;IACjD,MAAM,CAAU,QAAQ,GAAG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,CAAA;AAEpD,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,KAAG,MAAM,EAGxC,CAAA"}
|
package/build/helper.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Properties marked `secure: true` — the fields `lock()`/`unlock()` operate on by default. */
|
|
2
|
+
export const getSchemaSecureFeilds = (schema) => Object.entries(schema?.properties ?? {})
|
|
3
|
+
.filter(([, property]) => property.secure === true)
|
|
4
|
+
.map(([key]) => key);
|
|
5
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAiB,EAAY,EAAE,CACnE,MAAM,CAAC,OAAO,CAAE,MAA8B,EAAE,UAAU,IAAI,EAAE,CAAC;KAC9D,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAE,QAAiC,CAAC,MAAM,KAAK,IAAI,CAAC;KAC5E,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type * from './types.js';
|
|
2
|
+
export * from './consts.js';
|
|
3
|
+
export * from './declarations.js';
|
|
4
|
+
export * from './errors.js';
|
|
5
|
+
export * from './helper.js';
|
|
6
|
+
export * from './resource.js';
|
|
7
|
+
export * from './utils/index.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResourceMaker, ResourceRecord } from '@owlmeans/resource';
|
|
2
|
+
import type { PostgresResource } from './types.js';
|
|
3
|
+
export declare const makePostgresResource: <R extends ResourceRecord, T extends PostgresResource<R> = PostgresResource<R>>(alias: string, dbAlias?: string, serviceAlias?: string, makeCustomResource?: ResourceMaker<R, T>, tableName?: string) => T;
|
|
4
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACiB,aAAa,EAAE,cAAc,EACzD,MAAM,oBAAoB,CAAA;AAY3B,OAAO,KAAK,EAC8D,gBAAgB,EAEzF,MAAM,YAAY,CAAA;AA4BnB,eAAO,MAAM,oBAAoB,GAC/B,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAE7E,OAAO,MAAM,EAAE,UAAS,MAAyB,EAAE,eAAc,MAAyB,EAC1F,qBAAqB,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,MAAM,KAC3D,CAmdF,CAAA"}
|