@constructive-io/errors 0.3.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/LICENSE +23 -0
- package/README.md +139 -0
- package/classify.d.ts +10 -0
- package/classify.js +20 -0
- package/define.d.ts +16 -0
- package/define.js +11 -0
- package/error.d.ts +32 -0
- package/error.js +47 -0
- package/esm/classify.d.ts +10 -0
- package/esm/classify.js +16 -0
- package/esm/define.d.ts +16 -0
- package/esm/define.js +8 -0
- package/esm/error.d.ts +32 -0
- package/esm/error.js +43 -0
- package/esm/factory.d.ts +35 -0
- package/esm/factory.js +49 -0
- package/esm/format.d.ts +24 -0
- package/esm/format.js +54 -0
- package/esm/generated/registry.generated.d.ts +27 -0
- package/esm/generated/registry.generated.js +601 -0
- package/esm/index.d.ts +9 -0
- package/esm/index.js +9 -0
- package/esm/interpolate.d.ts +6 -0
- package/esm/interpolate.js +11 -0
- package/esm/parse.d.ts +30 -0
- package/esm/parse.js +199 -0
- package/esm/pg.d.ts +14 -0
- package/esm/pg.js +49 -0
- package/esm/registry.d.ts +147 -0
- package/esm/registry.js +468 -0
- package/esm/types.d.ts +81 -0
- package/esm/types.js +10 -0
- package/factory.d.ts +35 -0
- package/factory.js +55 -0
- package/format.d.ts +24 -0
- package/format.js +59 -0
- package/generated/registry.generated.d.ts +27 -0
- package/generated/registry.generated.js +604 -0
- package/index.d.ts +9 -0
- package/index.js +25 -0
- package/interpolate.d.ts +6 -0
- package/interpolate.js +14 -0
- package/package.json +45 -0
- package/parse.d.ts +30 -0
- package/parse.js +203 -0
- package/pg.d.ts +14 -0
- package/pg.js +53 -0
- package/registry.d.ts +147 -0
- package/registry.js +474 -0
- package/types.d.ts +81 -0
- package/types.js +11 -0
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./classify"), exports);
|
|
18
|
+
__exportStar(require("./error"), exports);
|
|
19
|
+
__exportStar(require("./factory"), exports);
|
|
20
|
+
__exportStar(require("./format"), exports);
|
|
21
|
+
__exportStar(require("./interpolate"), exports);
|
|
22
|
+
__exportStar(require("./parse"), exports);
|
|
23
|
+
__exportStar(require("./pg"), exports);
|
|
24
|
+
__exportStar(require("./registry"), exports);
|
|
25
|
+
__exportStar(require("./types"), exports);
|
package/interpolate.d.ts
ADDED
package/interpolate.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolate = interpolate;
|
|
4
|
+
const PLACEHOLDER = /\{\{\s*(\w+)\s*\}\}/g;
|
|
5
|
+
/**
|
|
6
|
+
* Replace `{{key}}` placeholders in a template with values from `context`.
|
|
7
|
+
* Missing keys render as an empty string.
|
|
8
|
+
*/
|
|
9
|
+
function interpolate(template, context = {}) {
|
|
10
|
+
return template.replace(PLACEHOLDER, (_match, key) => {
|
|
11
|
+
const value = context[key];
|
|
12
|
+
return value === undefined || value === null ? '' : String(value);
|
|
13
|
+
});
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@constructive-io/errors",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"author": "Constructive <developers@constructive.io>",
|
|
5
|
+
"description": "Canonical Constructive error system: registry, codes, i18n messages, and cross-source (PostgreSQL/GraphQL/client) parsing. Zero runtime dependencies.",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/constructive-io/constructive",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/constructive-io/constructive"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/constructive-io/constructive/issues"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "makage clean",
|
|
24
|
+
"prepack": "npm run build",
|
|
25
|
+
"build": "makage build",
|
|
26
|
+
"build:dev": "makage build --dev",
|
|
27
|
+
"lint": "eslint . --fix",
|
|
28
|
+
"test": "jest --passWithNoTests",
|
|
29
|
+
"test:watch": "jest --watch"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"errors",
|
|
33
|
+
"error-codes",
|
|
34
|
+
"i18n",
|
|
35
|
+
"constructive",
|
|
36
|
+
"postgresql",
|
|
37
|
+
"graphql"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.19.11",
|
|
41
|
+
"makage": "^0.3.0",
|
|
42
|
+
"ts-node": "^10.9.2"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "bb3269d48cdf2bc8f361bdd79b4833c921c13ec3"
|
|
45
|
+
}
|
package/parse.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ConstructiveError } from './error';
|
|
2
|
+
import type { ParsedError } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Normalize an error from any source (a {@link ConstructiveError}, a node-postgres
|
|
5
|
+
* `DatabaseError`, a GraphQL error or `{ errors: [...] }` wrapper, a plain
|
|
6
|
+
* `Error`, or a string) into a canonical {@link ParsedError}.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order for the code:
|
|
9
|
+
* 1. structured `DETAIL` JSON (`{ code, context }`) — Constructive's DB transport
|
|
10
|
+
* 2. GraphQL `extensions.code`
|
|
11
|
+
* 3. a leading ALL_CAPS token in the message (legacy DB `RAISE`), with any
|
|
12
|
+
* `(arg, arg)` positional args mapped onto named context via the registry
|
|
13
|
+
* 4. native SQLSTATE constraint mapping (23505 → `UNIQUE_VIOLATION`, …)
|
|
14
|
+
*
|
|
15
|
+
* Classification trusts an explicit `class` provided by the producer — the
|
|
16
|
+
* database transport's `DETAIL.class` or the server's `extensions.class` — when
|
|
17
|
+
* present, since that source is authoritative for the raise site (and correctly
|
|
18
|
+
* classifies codes not yet in the registry). It falls back to `classify(code)`
|
|
19
|
+
* (registry lookup, unknown ⇒ `internal`) only when no explicit class is given.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parse(error: unknown): ParsedError;
|
|
22
|
+
/**
|
|
23
|
+
* Normalize any error into a throwable {@link ConstructiveError}.
|
|
24
|
+
*
|
|
25
|
+
* Delegates to {@link parse} for code/context/class recovery, then resolves a
|
|
26
|
+
* localized message from the registry catalogs (falling back to the source
|
|
27
|
+
* error's raw message when the code is unknown) and the registry's HTTP hint.
|
|
28
|
+
* Codes that could not be resolved become `UNKNOWN_ERROR` (internal).
|
|
29
|
+
*/
|
|
30
|
+
export declare function toError(error: unknown, locale?: string): ConstructiveError;
|
package/parse.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = parse;
|
|
4
|
+
exports.toError = toError;
|
|
5
|
+
const classify_1 = require("./classify");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
const format_1 = require("./format");
|
|
8
|
+
const pg_1 = require("./pg");
|
|
9
|
+
const registry_1 = require("./registry");
|
|
10
|
+
/** Leading ALL_CAPS token, optionally followed by `(arg, arg)` positional args. */
|
|
11
|
+
const CODE_TOKEN = /^([A-Z][A-Z0-9_]+)(?:\s*\((.*)\))?\s*$/;
|
|
12
|
+
/** Narrow an arbitrary value to a valid {@link ErrorClass}, else `null`. */
|
|
13
|
+
function toErrorClass(value) {
|
|
14
|
+
return value === 'public' || value === 'internal' ? value : null;
|
|
15
|
+
}
|
|
16
|
+
function getMessage(error) {
|
|
17
|
+
if (typeof error === 'string')
|
|
18
|
+
return error;
|
|
19
|
+
if (error instanceof Error)
|
|
20
|
+
return error.message;
|
|
21
|
+
if (error && typeof error === 'object' && typeof error.message === 'string') {
|
|
22
|
+
return error.message;
|
|
23
|
+
}
|
|
24
|
+
return String(error);
|
|
25
|
+
}
|
|
26
|
+
/** Pull GraphQL-shaped fields, including the `{ errors: [...] }` request wrapper. */
|
|
27
|
+
function extractGraphqlLike(error) {
|
|
28
|
+
if (!error || typeof error !== 'object')
|
|
29
|
+
return null;
|
|
30
|
+
const e = error;
|
|
31
|
+
const fromNode = (node) => {
|
|
32
|
+
if (!node)
|
|
33
|
+
return null;
|
|
34
|
+
const extensions = node.extensions;
|
|
35
|
+
const out = {};
|
|
36
|
+
if (typeof node.message === 'string')
|
|
37
|
+
out.message = node.message;
|
|
38
|
+
if (extensions && typeof extensions.code === 'string')
|
|
39
|
+
out.extensionsCode = extensions.code;
|
|
40
|
+
if (extensions && extensions.context && typeof extensions.context === 'object') {
|
|
41
|
+
out.extensionsContext = extensions.context;
|
|
42
|
+
}
|
|
43
|
+
if (extensions) {
|
|
44
|
+
const cls = toErrorClass(extensions.class);
|
|
45
|
+
if (cls)
|
|
46
|
+
out.extensionsClass = cls;
|
|
47
|
+
}
|
|
48
|
+
return out.message || out.extensionsCode ? out : null;
|
|
49
|
+
};
|
|
50
|
+
if (Array.isArray(e.errors) && e.errors.length > 0) {
|
|
51
|
+
const first = fromNode(e.errors[0]);
|
|
52
|
+
if (first)
|
|
53
|
+
return first;
|
|
54
|
+
}
|
|
55
|
+
return fromNode(e);
|
|
56
|
+
}
|
|
57
|
+
function parseDetailJson(detail) {
|
|
58
|
+
if (!detail)
|
|
59
|
+
return null;
|
|
60
|
+
const trimmed = detail.trim();
|
|
61
|
+
if (!trimmed.startsWith('{'))
|
|
62
|
+
return null;
|
|
63
|
+
try {
|
|
64
|
+
const obj = JSON.parse(trimmed);
|
|
65
|
+
if (obj && typeof obj.code === 'string') {
|
|
66
|
+
const context = obj.context && typeof obj.context === 'object' ? obj.context : {};
|
|
67
|
+
return { code: obj.code, context, class: toErrorClass(obj.class) };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// not structured json — fall through
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function coerce(value) {
|
|
76
|
+
if (value === '')
|
|
77
|
+
return value;
|
|
78
|
+
const num = Number(value);
|
|
79
|
+
return Number.isNaN(num) ? value : num;
|
|
80
|
+
}
|
|
81
|
+
/** Map legacy positional args (`CODE (a, b)`) onto named context keys. */
|
|
82
|
+
function mapPositional(code, args) {
|
|
83
|
+
if (args.length === 0)
|
|
84
|
+
return {};
|
|
85
|
+
const positional = (0, registry_1.getDefinition)(code)?.positional;
|
|
86
|
+
if (!positional || positional.length === 0) {
|
|
87
|
+
return { args: args.join(', ') };
|
|
88
|
+
}
|
|
89
|
+
const context = {};
|
|
90
|
+
positional.forEach((key, i) => {
|
|
91
|
+
if (i < args.length)
|
|
92
|
+
context[key] = coerce(args[i]);
|
|
93
|
+
});
|
|
94
|
+
return context;
|
|
95
|
+
}
|
|
96
|
+
function parseMessageCode(message) {
|
|
97
|
+
const m = message.trim().match(CODE_TOKEN);
|
|
98
|
+
if (!m)
|
|
99
|
+
return null;
|
|
100
|
+
return { code: m[1], args: m[2] !== undefined ? m[2].split(',').map((s) => s.trim()).filter(Boolean) : [] };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Normalize an error from any source (a {@link ConstructiveError}, a node-postgres
|
|
104
|
+
* `DatabaseError`, a GraphQL error or `{ errors: [...] }` wrapper, a plain
|
|
105
|
+
* `Error`, or a string) into a canonical {@link ParsedError}.
|
|
106
|
+
*
|
|
107
|
+
* Resolution order for the code:
|
|
108
|
+
* 1. structured `DETAIL` JSON (`{ code, context }`) — Constructive's DB transport
|
|
109
|
+
* 2. GraphQL `extensions.code`
|
|
110
|
+
* 3. a leading ALL_CAPS token in the message (legacy DB `RAISE`), with any
|
|
111
|
+
* `(arg, arg)` positional args mapped onto named context via the registry
|
|
112
|
+
* 4. native SQLSTATE constraint mapping (23505 → `UNIQUE_VIOLATION`, …)
|
|
113
|
+
*
|
|
114
|
+
* Classification trusts an explicit `class` provided by the producer — the
|
|
115
|
+
* database transport's `DETAIL.class` or the server's `extensions.class` — when
|
|
116
|
+
* present, since that source is authoritative for the raise site (and correctly
|
|
117
|
+
* classifies codes not yet in the registry). It falls back to `classify(code)`
|
|
118
|
+
* (registry lookup, unknown ⇒ `internal`) only when no explicit class is given.
|
|
119
|
+
*/
|
|
120
|
+
function parse(error) {
|
|
121
|
+
if (error instanceof error_1.ConstructiveError) {
|
|
122
|
+
return {
|
|
123
|
+
code: error.code,
|
|
124
|
+
context: error.context ?? {},
|
|
125
|
+
class: error.errorClass,
|
|
126
|
+
known: Boolean((0, registry_1.getDefinition)(error.code)),
|
|
127
|
+
rawMessage: error.message,
|
|
128
|
+
originalError: error
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const pg = (0, pg_1.extractPgErrorFields)(error);
|
|
132
|
+
const gql = extractGraphqlLike(error);
|
|
133
|
+
const rawMessage = gql?.message ?? getMessage(error);
|
|
134
|
+
const sqlState = pg?.code;
|
|
135
|
+
let code = null;
|
|
136
|
+
let context = {};
|
|
137
|
+
let explicitClass = null;
|
|
138
|
+
const detail = parseDetailJson(pg?.detail);
|
|
139
|
+
if (detail) {
|
|
140
|
+
code = detail.code;
|
|
141
|
+
context = { ...detail.context };
|
|
142
|
+
explicitClass = detail.class;
|
|
143
|
+
}
|
|
144
|
+
if (!code && gql?.extensionsCode) {
|
|
145
|
+
code = gql.extensionsCode;
|
|
146
|
+
if (gql.extensionsContext)
|
|
147
|
+
context = { ...gql.extensionsContext };
|
|
148
|
+
if (gql.extensionsClass)
|
|
149
|
+
explicitClass = gql.extensionsClass;
|
|
150
|
+
}
|
|
151
|
+
if (!code) {
|
|
152
|
+
const parsedMsg = parseMessageCode(gql?.message ?? rawMessage);
|
|
153
|
+
if (parsedMsg && parsedMsg.code !== pg_1.RAISE_EXCEPTION_SQLSTATE) {
|
|
154
|
+
code = parsedMsg.code;
|
|
155
|
+
context = mapPositional(parsedMsg.code, parsedMsg.args);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if ((!code || code === pg_1.RAISE_EXCEPTION_SQLSTATE) && sqlState && pg_1.SQLSTATE_TO_CODE[sqlState]) {
|
|
159
|
+
code = pg_1.SQLSTATE_TO_CODE[sqlState];
|
|
160
|
+
if (pg?.constraint)
|
|
161
|
+
context.constraint = pg.constraint;
|
|
162
|
+
if (pg?.table)
|
|
163
|
+
context.table = pg.table;
|
|
164
|
+
if (pg?.column)
|
|
165
|
+
context.column = pg.column;
|
|
166
|
+
}
|
|
167
|
+
if (code === pg_1.RAISE_EXCEPTION_SQLSTATE)
|
|
168
|
+
code = null;
|
|
169
|
+
return {
|
|
170
|
+
code,
|
|
171
|
+
context,
|
|
172
|
+
class: explicitClass ?? (0, classify_1.classify)(code),
|
|
173
|
+
known: Boolean(code && (0, registry_1.getDefinition)(code)),
|
|
174
|
+
rawMessage,
|
|
175
|
+
sqlState,
|
|
176
|
+
originalError: error
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Normalize any error into a throwable {@link ConstructiveError}.
|
|
181
|
+
*
|
|
182
|
+
* Delegates to {@link parse} for code/context/class recovery, then resolves a
|
|
183
|
+
* localized message from the registry catalogs (falling back to the source
|
|
184
|
+
* error's raw message when the code is unknown) and the registry's HTTP hint.
|
|
185
|
+
* Codes that could not be resolved become `UNKNOWN_ERROR` (internal).
|
|
186
|
+
*/
|
|
187
|
+
function toError(error, locale) {
|
|
188
|
+
if (error instanceof error_1.ConstructiveError)
|
|
189
|
+
return error;
|
|
190
|
+
const parsed = parse(error);
|
|
191
|
+
const code = parsed.code ?? 'UNKNOWN_ERROR';
|
|
192
|
+
const def = (0, registry_1.getDefinition)(code);
|
|
193
|
+
const message = parsed.known
|
|
194
|
+
? (0, format_1.format)(code, parsed.context, locale)
|
|
195
|
+
: parsed.rawMessage || (0, format_1.format)(code, parsed.context, locale);
|
|
196
|
+
return new error_1.ConstructiveError({
|
|
197
|
+
code,
|
|
198
|
+
message,
|
|
199
|
+
errorClass: parsed.class,
|
|
200
|
+
http: def?.http ?? 500,
|
|
201
|
+
context: parsed.context
|
|
202
|
+
});
|
|
203
|
+
}
|
package/pg.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PgErrorFields } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* PostgreSQL SQLSTATE codes for the native constraint violations we surface as
|
|
4
|
+
* public Constructive codes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SQLSTATE_TO_CODE: Record<string, string>;
|
|
7
|
+
/** SQLSTATE for a user-raised `RAISE EXCEPTION` without an explicit ERRCODE. */
|
|
8
|
+
export declare const RAISE_EXCEPTION_SQLSTATE = "P0001";
|
|
9
|
+
/**
|
|
10
|
+
* Extract extended PostgreSQL error fields from an error-like object. Returns
|
|
11
|
+
* `null` when the value does not look like a pg error (no `code`/`detail`/
|
|
12
|
+
* `where`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractPgErrorFields(err: unknown): PgErrorFields | null;
|
package/pg.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RAISE_EXCEPTION_SQLSTATE = exports.SQLSTATE_TO_CODE = void 0;
|
|
4
|
+
exports.extractPgErrorFields = extractPgErrorFields;
|
|
5
|
+
/**
|
|
6
|
+
* PostgreSQL SQLSTATE codes for the native constraint violations we surface as
|
|
7
|
+
* public Constructive codes.
|
|
8
|
+
*/
|
|
9
|
+
exports.SQLSTATE_TO_CODE = {
|
|
10
|
+
23505: 'UNIQUE_VIOLATION',
|
|
11
|
+
23503: 'FOREIGN_KEY_VIOLATION',
|
|
12
|
+
23502: 'NOT_NULL_VIOLATION',
|
|
13
|
+
23514: 'CHECK_VIOLATION',
|
|
14
|
+
'23P01': 'EXCLUSION_VIOLATION'
|
|
15
|
+
};
|
|
16
|
+
/** SQLSTATE for a user-raised `RAISE EXCEPTION` without an explicit ERRCODE. */
|
|
17
|
+
exports.RAISE_EXCEPTION_SQLSTATE = 'P0001';
|
|
18
|
+
/**
|
|
19
|
+
* Extract extended PostgreSQL error fields from an error-like object. Returns
|
|
20
|
+
* `null` when the value does not look like a pg error (no `code`/`detail`/
|
|
21
|
+
* `where`).
|
|
22
|
+
*/
|
|
23
|
+
function extractPgErrorFields(err) {
|
|
24
|
+
if (!err || typeof err !== 'object')
|
|
25
|
+
return null;
|
|
26
|
+
const e = err;
|
|
27
|
+
if (!e.code && !e.detail && !e.where)
|
|
28
|
+
return null;
|
|
29
|
+
const fields = {};
|
|
30
|
+
const assign = (key) => {
|
|
31
|
+
const value = e[key];
|
|
32
|
+
if (typeof value === 'string')
|
|
33
|
+
fields[key] = value;
|
|
34
|
+
};
|
|
35
|
+
[
|
|
36
|
+
'code',
|
|
37
|
+
'detail',
|
|
38
|
+
'hint',
|
|
39
|
+
'where',
|
|
40
|
+
'position',
|
|
41
|
+
'internalPosition',
|
|
42
|
+
'internalQuery',
|
|
43
|
+
'schema',
|
|
44
|
+
'table',
|
|
45
|
+
'column',
|
|
46
|
+
'dataType',
|
|
47
|
+
'constraint',
|
|
48
|
+
'file',
|
|
49
|
+
'line',
|
|
50
|
+
'routine'
|
|
51
|
+
].forEach(assign);
|
|
52
|
+
return fields;
|
|
53
|
+
}
|
package/registry.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ErrorContext, ErrorDefinition } from './types';
|
|
2
|
+
export { type DefinedError, defineError } from './define';
|
|
3
|
+
/**
|
|
4
|
+
* The curated Constructive error registry.
|
|
5
|
+
*
|
|
6
|
+
* These entries carry refined, typed context and hand-written copy for the
|
|
7
|
+
* codes that matter most (public auth/limit codes with real dashboard copy,
|
|
8
|
+
* native PostgreSQL constraint codes, and the pgpm CLI codes). They OVERRIDE
|
|
9
|
+
* the generated entries in {@link generatedRegistry} — every constructive-db
|
|
10
|
+
* code is present via generation; these just refine a subset.
|
|
11
|
+
*/
|
|
12
|
+
export declare const registry: {
|
|
13
|
+
readonly ACCOUNT_EXISTS: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
14
|
+
readonly ACCOUNT_NOT_FOUND: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
15
|
+
readonly NO_ACCOUNT_EXISTS: import("./define").DefinedError<{
|
|
16
|
+
userId?: string;
|
|
17
|
+
}>;
|
|
18
|
+
readonly INVALID_CREDENTIALS: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
19
|
+
readonly INCORRECT_PASSWORD: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
20
|
+
readonly ACCOUNT_LOCKED_EXCEED_ATTEMPTS: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
21
|
+
readonly ACCOUNT_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
22
|
+
readonly PASSWORD_INSECURE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
23
|
+
readonly PASSWORD_LEN: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
24
|
+
readonly EMAIL_NOT_VERIFIED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
25
|
+
readonly SIGN_UP_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
26
|
+
readonly USER_NOT_AUTHENTICATED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
27
|
+
readonly ACCOUNT_LOCKED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
28
|
+
readonly USER_NOT_FOUND: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
29
|
+
readonly NO_PRIMARY_EMAIL: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
30
|
+
readonly NO_CREDENTIALS: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
31
|
+
readonly BAD_SIGNIN: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
32
|
+
readonly SSO_SIGN_IN_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
33
|
+
readonly SSO_SIGN_UP_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
34
|
+
readonly SSO_ACCOUNT_NOT_FOUND: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
35
|
+
readonly MAGIC_LINK_SIGN_IN_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
36
|
+
readonly MAGIC_LINK_SIGN_UP_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
37
|
+
readonly EMAIL_OTP_SIGN_IN_DISABLED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
38
|
+
readonly INVALID_PUBLIC_KEY: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
39
|
+
readonly INVALID_MESSAGE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
40
|
+
readonly INVALID_SIGNATURE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
41
|
+
readonly UPLOAD_MIMETYPE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
42
|
+
readonly SINGLETON_TABLE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
43
|
+
readonly INVITE_NOT_FOUND: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
44
|
+
readonly INVITE_LIMIT: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
45
|
+
readonly INVITE_EMAIL_NOT_FOUND: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
46
|
+
readonly UNAUTHENTICATED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
47
|
+
readonly FORBIDDEN: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
48
|
+
readonly STEP_UP_REQUIRED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
49
|
+
readonly MFA_REQUIRED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
50
|
+
readonly INVALID_TOKEN: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
51
|
+
readonly LIMIT_REACHED: import("./define").DefinedError<{
|
|
52
|
+
resource?: string;
|
|
53
|
+
limit?: number;
|
|
54
|
+
}>;
|
|
55
|
+
readonly RATE_LIMITED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
56
|
+
readonly NETWORK_ERROR: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
57
|
+
readonly TIMEOUT_ERROR: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
58
|
+
readonly BAD_USER_INPUT: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
59
|
+
readonly VALIDATION_FAILED: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
60
|
+
readonly UNKNOWN_ERROR: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
61
|
+
readonly UNIQUE_VIOLATION: import("./define").DefinedError<{
|
|
62
|
+
constraint?: string;
|
|
63
|
+
table?: string;
|
|
64
|
+
}>;
|
|
65
|
+
readonly FOREIGN_KEY_VIOLATION: import("./define").DefinedError<{
|
|
66
|
+
constraint?: string;
|
|
67
|
+
table?: string;
|
|
68
|
+
}>;
|
|
69
|
+
readonly NOT_NULL_VIOLATION: import("./define").DefinedError<{
|
|
70
|
+
column?: string;
|
|
71
|
+
table?: string;
|
|
72
|
+
}>;
|
|
73
|
+
readonly CHECK_VIOLATION: import("./define").DefinedError<{
|
|
74
|
+
constraint?: string;
|
|
75
|
+
table?: string;
|
|
76
|
+
}>;
|
|
77
|
+
readonly EXCLUSION_VIOLATION: import("./define").DefinedError<{
|
|
78
|
+
constraint?: string;
|
|
79
|
+
table?: string;
|
|
80
|
+
}>;
|
|
81
|
+
readonly NOT_FOUND: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
82
|
+
readonly MODULE_NOT_FOUND: import("./define").DefinedError<{
|
|
83
|
+
name: string;
|
|
84
|
+
}>;
|
|
85
|
+
readonly INTERNAL_FAILURE: import("./define").DefinedError<{
|
|
86
|
+
details: string;
|
|
87
|
+
}>;
|
|
88
|
+
readonly CONTEXT_MISSING: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
89
|
+
readonly NOT_IN_WORKSPACE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
90
|
+
readonly NOT_IN_WORKSPACE_MODULE: import("./define").DefinedError<import("./types").EmptyContext>;
|
|
91
|
+
readonly DEPLOYMENT_FAILED: import("./define").DefinedError<{
|
|
92
|
+
type: "Deployment" | "Revert" | "Verify";
|
|
93
|
+
module: string;
|
|
94
|
+
}>;
|
|
95
|
+
readonly UNSUPPORTED_TYPE_HINT: import("./define").DefinedError<{
|
|
96
|
+
typeHint: string;
|
|
97
|
+
}>;
|
|
98
|
+
readonly BAD_FILE_NAME: import("./define").DefinedError<{
|
|
99
|
+
name: string;
|
|
100
|
+
}>;
|
|
101
|
+
readonly UNKNOWN_COMMAND: import("./define").DefinedError<{
|
|
102
|
+
cmd: string;
|
|
103
|
+
}>;
|
|
104
|
+
readonly CHANGE_NOT_FOUND: import("./define").DefinedError<{
|
|
105
|
+
change: string;
|
|
106
|
+
plan?: string;
|
|
107
|
+
}>;
|
|
108
|
+
readonly TAG_NOT_FOUND: import("./define").DefinedError<{
|
|
109
|
+
tag: string;
|
|
110
|
+
project?: string;
|
|
111
|
+
}>;
|
|
112
|
+
readonly PATH_NOT_FOUND: import("./define").DefinedError<{
|
|
113
|
+
path: string;
|
|
114
|
+
type: "module" | "workspace" | "file";
|
|
115
|
+
}>;
|
|
116
|
+
readonly OPERATION_FAILED: import("./define").DefinedError<{
|
|
117
|
+
operation: string;
|
|
118
|
+
target?: string;
|
|
119
|
+
reason?: string;
|
|
120
|
+
}>;
|
|
121
|
+
readonly PLAN_PARSE_ERROR: import("./define").DefinedError<{
|
|
122
|
+
planPath: string;
|
|
123
|
+
errors: string;
|
|
124
|
+
}>;
|
|
125
|
+
readonly CIRCULAR_DEPENDENCY: import("./define").DefinedError<{
|
|
126
|
+
module: string;
|
|
127
|
+
dependency: string;
|
|
128
|
+
}>;
|
|
129
|
+
readonly INVALID_NAME: import("./define").DefinedError<{
|
|
130
|
+
name: string;
|
|
131
|
+
type: "tag" | "change" | "module";
|
|
132
|
+
rules?: string;
|
|
133
|
+
}>;
|
|
134
|
+
readonly WORKSPACE_OPERATION_ERROR: import("./define").DefinedError<{
|
|
135
|
+
operation: string;
|
|
136
|
+
}>;
|
|
137
|
+
readonly FILE_NOT_FOUND: import("./define").DefinedError<{
|
|
138
|
+
filePath: string;
|
|
139
|
+
type?: string;
|
|
140
|
+
}>;
|
|
141
|
+
};
|
|
142
|
+
export type Registry = typeof registry;
|
|
143
|
+
export type RegistryCode = keyof Registry;
|
|
144
|
+
/** Look up a definition by code (from anywhere, not just typed keys). */
|
|
145
|
+
export declare function getDefinition(code: string): ErrorDefinition<ErrorContext> | undefined;
|
|
146
|
+
/** Every registered code (curated + generated). */
|
|
147
|
+
export declare function allCodes(): string[];
|