@heychunky/core 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/graph.d.ts +57 -0
- package/dist/admin/graph.d.ts.map +1 -0
- package/dist/admin/graph.js +90 -0
- package/dist/admin/graph.js.map +1 -0
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.d.ts.map +1 -1
- package/dist/admin/index.js +1 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/migrations.d.ts +5 -0
- package/dist/admin/migrations.d.ts.map +1 -1
- package/dist/admin/migrations.js +10 -2
- package/dist/admin/migrations.js.map +1 -1
- package/dist/http/errors.d.ts +14 -8
- package/dist/http/errors.d.ts.map +1 -1
- package/dist/http/errors.js +27 -20
- package/dist/http/errors.js.map +1 -1
- package/dist/services/db.d.ts.map +1 -1
- package/dist/services/db.js +5 -2
- package/dist/services/db.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an app is made of, and what a change to one part would reach.
|
|
3
|
+
*
|
|
4
|
+
* An app is chunks and chunks depend on each other, which is the shape that
|
|
5
|
+
* decides whether a change is small. Nothing showed it, and the chunk READMEs
|
|
6
|
+
* that describe it in prose go stale the first time somebody deletes an import
|
|
7
|
+
* and not a sentence.
|
|
8
|
+
*
|
|
9
|
+
* So the edges are read rather than restated. `@chunks/<name>` is the boundary
|
|
10
|
+
* the app itself declares in its manifest aliases, so a scan of the chunk
|
|
11
|
+
* sources is the whole graph — the same discipline as everything else here:
|
|
12
|
+
* derive the fact, never keep a second copy of it.
|
|
13
|
+
*
|
|
14
|
+
* Three callers want this. The console draws it, the CLI prints it, and a run
|
|
15
|
+
* reads it to know when it has left its chunk, so it lives where none of them
|
|
16
|
+
* owns it.
|
|
17
|
+
*/
|
|
18
|
+
/** One chunk, and what it reaches. */
|
|
19
|
+
export interface ChunkNode {
|
|
20
|
+
name: string;
|
|
21
|
+
/** Chunks this one imports from, sorted. */
|
|
22
|
+
dependsOn: string[];
|
|
23
|
+
/** Chunks that import this one, sorted. */
|
|
24
|
+
dependedOnBy: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Every chunk reachable by following dependents — what a change here could
|
|
27
|
+
* break. The number that answers "is this a small change".
|
|
28
|
+
*/
|
|
29
|
+
blastRadius: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface ChunkGraph {
|
|
32
|
+
chunks: ChunkNode[];
|
|
33
|
+
/**
|
|
34
|
+
* Pairs that import each other.
|
|
35
|
+
*
|
|
36
|
+
* Reported because they are the reason a blast radius is twelve rather than
|
|
37
|
+
* two: a cycle collapses everything it touches into one cluster, and an app
|
|
38
|
+
* whose graph has cycles has no clean layering to read.
|
|
39
|
+
*/
|
|
40
|
+
cycles: [string, string][];
|
|
41
|
+
}
|
|
42
|
+
/** A chunk's sources, as the scan needs them: its name and its file contents. */
|
|
43
|
+
export interface ChunkSource {
|
|
44
|
+
name: string;
|
|
45
|
+
/** Every text file in the chunk. Contents only; paths are not needed. */
|
|
46
|
+
files: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build the graph from a set of chunks and their sources.
|
|
50
|
+
*
|
|
51
|
+
* Pure, so it can be tested against a real app's shape without a network, and
|
|
52
|
+
* so the expensive half — fetching the sources — is somebody else's problem.
|
|
53
|
+
* An edge to a chunk that is not in the set is dropped: an app importing
|
|
54
|
+
* something it does not have is a broken app, not an extra node.
|
|
55
|
+
*/
|
|
56
|
+
export declare function chunkGraph(sources: readonly ChunkSource[]): ChunkGraph;
|
|
57
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/admin/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,sCAAsC;AACtC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB;;;;;;OAMG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CAC5B;AAED,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAWD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,UAAU,CAoCtE"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an app is made of, and what a change to one part would reach.
|
|
3
|
+
*
|
|
4
|
+
* An app is chunks and chunks depend on each other, which is the shape that
|
|
5
|
+
* decides whether a change is small. Nothing showed it, and the chunk READMEs
|
|
6
|
+
* that describe it in prose go stale the first time somebody deletes an import
|
|
7
|
+
* and not a sentence.
|
|
8
|
+
*
|
|
9
|
+
* So the edges are read rather than restated. `@chunks/<name>` is the boundary
|
|
10
|
+
* the app itself declares in its manifest aliases, so a scan of the chunk
|
|
11
|
+
* sources is the whole graph — the same discipline as everything else here:
|
|
12
|
+
* derive the fact, never keep a second copy of it.
|
|
13
|
+
*
|
|
14
|
+
* Three callers want this. The console draws it, the CLI prints it, and a run
|
|
15
|
+
* reads it to know when it has left its chunk, so it lives where none of them
|
|
16
|
+
* owns it.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* An import of another chunk, by the alias an app declares for its chunks root.
|
|
20
|
+
*
|
|
21
|
+
* Deliberately not a TypeScript parse. The alias is the boundary, so the name
|
|
22
|
+
* after it is the edge — and a scan that cannot be wrong about syntax it does
|
|
23
|
+
* not read is worth more here than one that understands every import form.
|
|
24
|
+
*/
|
|
25
|
+
const EDGE = /@chunks\/([a-z0-9][a-z0-9-]*)/gi;
|
|
26
|
+
/**
|
|
27
|
+
* Build the graph from a set of chunks and their sources.
|
|
28
|
+
*
|
|
29
|
+
* Pure, so it can be tested against a real app's shape without a network, and
|
|
30
|
+
* so the expensive half — fetching the sources — is somebody else's problem.
|
|
31
|
+
* An edge to a chunk that is not in the set is dropped: an app importing
|
|
32
|
+
* something it does not have is a broken app, not an extra node.
|
|
33
|
+
*/
|
|
34
|
+
export function chunkGraph(sources) {
|
|
35
|
+
const names = new Set(sources.map((s) => s.name));
|
|
36
|
+
const out = new Map();
|
|
37
|
+
for (const { name, files } of sources) {
|
|
38
|
+
const found = new Set();
|
|
39
|
+
for (const text of files) {
|
|
40
|
+
for (const [, to] of text.matchAll(EDGE)) {
|
|
41
|
+
const chunk = to.toLowerCase();
|
|
42
|
+
// A chunk importing itself is a file next door, not an edge.
|
|
43
|
+
if (chunk !== name && names.has(chunk))
|
|
44
|
+
found.add(chunk);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
out.set(name, found);
|
|
48
|
+
}
|
|
49
|
+
const into = new Map([...names].map((n) => [n, new Set()]));
|
|
50
|
+
for (const [from, tos] of out) {
|
|
51
|
+
for (const to of tos)
|
|
52
|
+
into.get(to).add(from);
|
|
53
|
+
}
|
|
54
|
+
const chunks = [...names].sort().map((name) => ({
|
|
55
|
+
name,
|
|
56
|
+
dependsOn: [...out.get(name)].sort(),
|
|
57
|
+
dependedOnBy: [...into.get(name)].sort(),
|
|
58
|
+
blastRadius: [...reach(name, into)].sort(),
|
|
59
|
+
}));
|
|
60
|
+
const cycles = [];
|
|
61
|
+
for (const [a, tos] of out) {
|
|
62
|
+
for (const b of tos) {
|
|
63
|
+
if (a < b && out.get(b)?.has(a))
|
|
64
|
+
cycles.push([a, b]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
cycles.sort(([a], [b]) => a.localeCompare(b));
|
|
68
|
+
return { chunks, cycles };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Everything reachable by following dependents, excluding the start.
|
|
72
|
+
*
|
|
73
|
+
* Iterative rather than recursive because the graphs that most need this are
|
|
74
|
+
* the ones with cycles, and a cycle is where a naive recursion does not come
|
|
75
|
+
* back.
|
|
76
|
+
*/
|
|
77
|
+
function reach(start, into) {
|
|
78
|
+
const seen = new Set();
|
|
79
|
+
const stack = [start];
|
|
80
|
+
while (stack.length) {
|
|
81
|
+
for (const up of into.get(stack.pop()) ?? []) {
|
|
82
|
+
if (up !== start && !seen.has(up)) {
|
|
83
|
+
seen.add(up);
|
|
84
|
+
stack.push(up);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return seen;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/admin/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAmCH;;;;;;GAMG;AACH,MAAM,IAAI,GAAG,iCAAiC,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAA+B;IACxD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC3C,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,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;QAC3B,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;YACpB,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,KAAK,CAAC,KAAa,EAAE,IAA8B;IAC1D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC;IACtB,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;gBAClC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACb,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/admin/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./appkeys.ts";
|
|
|
28
28
|
export * from "./runs.ts";
|
|
29
29
|
export * from "./entrypoints.ts";
|
|
30
30
|
export * from "./chunks.ts";
|
|
31
|
+
export * from "./graph.ts";
|
|
31
32
|
export * from "./services/github.ts";
|
|
32
33
|
export * from "./services/vercel.ts";
|
|
33
34
|
export * from "./services/neon.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAG3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
package/dist/admin/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./appkeys.js";
|
|
|
28
28
|
export * from "./runs.js";
|
|
29
29
|
export * from "./entrypoints.js";
|
|
30
30
|
export * from "./chunks.js";
|
|
31
|
+
export * from "./graph.js";
|
|
31
32
|
// One file per service, matching the registry.
|
|
32
33
|
export * from "./services/github.js";
|
|
33
34
|
export * from "./services/vercel.js";
|
package/dist/admin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAE3B,+CAA+C;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
|
@@ -71,6 +71,11 @@ export declare function ensureLedger(db: Ledger): Promise<void>;
|
|
|
71
71
|
* but it must not be answered by making the table, because this is the call an
|
|
72
72
|
* unconfirmed plan makes and a plan that wrote to the database would not be a
|
|
73
73
|
* plan. Any other error is real and is left alone.
|
|
74
|
+
*
|
|
75
|
+
* "No ledger table" is decided by Postgres's own code for an undefined table,
|
|
76
|
+
* `42P01`, never by message text — "does not exist" also appears in errors
|
|
77
|
+
* about columns, schemas and roles, and swallowing one of those would report
|
|
78
|
+
* a broken database as a fresh one.
|
|
74
79
|
*/
|
|
75
80
|
export declare function applied(db: Ledger): Promise<Set<string>>;
|
|
76
81
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/admin/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,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async function ensureLedger(db) {
|
|
|
43
43
|
* but it must not be answered by making the table, because this is the call an
|
|
44
44
|
* unconfirmed plan makes and a plan that wrote to the database would not be a
|
|
45
45
|
* plan. Any other error is real and is left alone.
|
|
46
|
+
*
|
|
47
|
+
* "No ledger table" is decided by Postgres's own code for an undefined table,
|
|
48
|
+
* `42P01`, never by message text — "does not exist" also appears in errors
|
|
49
|
+
* about columns, schemas and roles, and swallowing one of those would report
|
|
50
|
+
* a broken database as a fresh one.
|
|
46
51
|
*/
|
|
47
52
|
export async function applied(db) {
|
|
48
53
|
try {
|
|
@@ -50,8 +55,11 @@ export async function applied(db) {
|
|
|
50
55
|
return new Set(rows.map((r) => String(r.id)));
|
|
51
56
|
}
|
|
52
57
|
catch (err) {
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
// The caught value is whatever the client threw, so look before reading.
|
|
59
|
+
const code = typeof err === "object" && err !== null && "code" in err
|
|
60
|
+
? err.code
|
|
61
|
+
: undefined;
|
|
62
|
+
if (code === "42P01")
|
|
55
63
|
return new Set();
|
|
56
64
|
throw err;
|
|
57
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/admin/migrations.ts"],"names":[],"mappings":"AA6BA,kEAAkE;AAClE,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C,oEAAoE;AACpE,MAAM,CAAC,MAAM,MAAM,GAAG,uBAAuB,CAAC;AAe9C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,EAAQ,EAAE,IAAY,EAAE,KAAa;IACjE,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,OAAO,C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B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/http/errors.d.ts
CHANGED
|
@@ -9,23 +9,29 @@ export declare abstract class HttpError extends Error {
|
|
|
9
9
|
readonly status: number;
|
|
10
10
|
readonly url: string;
|
|
11
11
|
readonly body: string;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The provider's own error code, when it gave one — Postgres's SQLSTATE
|
|
14
|
+
* through Neon, for instance. A caller deciding "missing table" from the
|
|
15
|
+
* message text would also match a missing column; the code is exact.
|
|
16
|
+
*/
|
|
17
|
+
readonly code: string | undefined;
|
|
18
|
+
constructor(name: string, message: string, status: number, url: string, body: string, code?: string);
|
|
13
19
|
/** Whether trying the same request again could plausibly succeed. */
|
|
14
20
|
abstract get retryable(): boolean;
|
|
15
21
|
}
|
|
16
22
|
/** The credential is wrong, expired, or lacks the permission. Never retry. */
|
|
17
23
|
export declare class AuthError extends HttpError {
|
|
18
|
-
constructor(status: number, url: string, body: string);
|
|
24
|
+
constructor(status: number, url: string, body: string, code?: string);
|
|
19
25
|
get retryable(): boolean;
|
|
20
26
|
}
|
|
21
27
|
/** It does not exist. Often a normal state, not a failure. */
|
|
22
28
|
export declare class NotFoundError extends HttpError {
|
|
23
|
-
constructor(url: string, body: string);
|
|
29
|
+
constructor(url: string, body: string, code?: string);
|
|
24
30
|
get retryable(): boolean;
|
|
25
31
|
}
|
|
26
32
|
/** The request was malformed. Retrying sends the same bad request. */
|
|
27
33
|
export declare class ValidationError extends HttpError {
|
|
28
|
-
constructor(status: number, url: string, body: string);
|
|
34
|
+
constructor(status: number, url: string, body: string, code?: string);
|
|
29
35
|
get retryable(): boolean;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
@@ -36,21 +42,21 @@ export declare class ValidationError extends HttpError {
|
|
|
36
42
|
* a client error and is not one — the request is correct and merely early.
|
|
37
43
|
*/
|
|
38
44
|
export declare class BusyError extends HttpError {
|
|
39
|
-
constructor(status: number, url: string, body: string);
|
|
45
|
+
constructor(status: number, url: string, body: string, code?: string);
|
|
40
46
|
get retryable(): boolean;
|
|
41
47
|
}
|
|
42
48
|
/** Slow down. Carries the provider's own advice on how long to wait. */
|
|
43
49
|
export declare class RateLimitError extends HttpError {
|
|
44
50
|
/** Seconds to wait, when the provider said. */
|
|
45
51
|
readonly retryAfter: number | undefined;
|
|
46
|
-
constructor(url: string, body: string, retryAfter?: number);
|
|
52
|
+
constructor(url: string, body: string, retryAfter?: number, code?: string);
|
|
47
53
|
get retryable(): boolean;
|
|
48
54
|
}
|
|
49
55
|
/** The provider broke. Worth trying again. */
|
|
50
56
|
export declare class ServiceError extends HttpError {
|
|
51
|
-
constructor(status: number, url: string, body: string);
|
|
57
|
+
constructor(status: number, url: string, body: string, code?: string);
|
|
52
58
|
get retryable(): boolean;
|
|
53
59
|
}
|
|
54
60
|
/** Map a response onto the right error. */
|
|
55
|
-
export declare function errorFor(status: number, url: string, body: string, retryAfter?: number): HttpError;
|
|
61
|
+
export declare function errorFor(status: number, url: string, body: string, retryAfter?: number, code?: string): HttpError;
|
|
56
62
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8BAAsB,SAAU,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8BAAsB,SAAU,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAA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E,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAIzE,IAAI,SAAS,IAAI,OAAO,CAAiB;CAC1C;AAED,8CAA8C;AAC9C,qBAAa,YAAa,SAAQ,SAAS;gBAC7B,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAGpE,IAAI,SAAS,IAAI,OAAO,CAAiB;CAC1C;AAED,2CAA2C;AAC3C,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAOjH"}
|
package/dist/http/errors.js
CHANGED
|
@@ -9,32 +9,39 @@ export class HttpError extends Error {
|
|
|
9
9
|
status;
|
|
10
10
|
url;
|
|
11
11
|
body;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The provider's own error code, when it gave one — Postgres's SQLSTATE
|
|
14
|
+
* through Neon, for instance. A caller deciding "missing table" from the
|
|
15
|
+
* message text would also match a missing column; the code is exact.
|
|
16
|
+
*/
|
|
17
|
+
code;
|
|
18
|
+
constructor(name, message, status, url, body, code) {
|
|
13
19
|
super(message);
|
|
14
20
|
this.name = name;
|
|
15
21
|
this.status = status;
|
|
16
22
|
this.url = url;
|
|
17
23
|
this.body = body;
|
|
24
|
+
this.code = code;
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
/** The credential is wrong, expired, or lacks the permission. Never retry. */
|
|
21
28
|
export class AuthError extends HttpError {
|
|
22
|
-
constructor(status, url, body) {
|
|
23
|
-
super("AuthError", `Not authorised (${status}) — the key is wrong or lacks permission`, status, url, body);
|
|
29
|
+
constructor(status, url, body, code) {
|
|
30
|
+
super("AuthError", `Not authorised (${status}) — the key is wrong or lacks permission`, status, url, body, code);
|
|
24
31
|
}
|
|
25
32
|
get retryable() { return false; }
|
|
26
33
|
}
|
|
27
34
|
/** It does not exist. Often a normal state, not a failure. */
|
|
28
35
|
export class NotFoundError extends HttpError {
|
|
29
|
-
constructor(url, body) {
|
|
30
|
-
super("NotFoundError", "Not found", 404, url, body);
|
|
36
|
+
constructor(url, body, code) {
|
|
37
|
+
super("NotFoundError", "Not found", 404, url, body, code);
|
|
31
38
|
}
|
|
32
39
|
get retryable() { return false; }
|
|
33
40
|
}
|
|
34
41
|
/** The request was malformed. Retrying sends the same bad request. */
|
|
35
42
|
export class ValidationError extends HttpError {
|
|
36
|
-
constructor(status, url, body) {
|
|
37
|
-
super("ValidationError", `Rejected (${status}): ${body.slice(0, 200)}`, status, url, body);
|
|
43
|
+
constructor(status, url, body, code) {
|
|
44
|
+
super("ValidationError", `Rejected (${status}): ${body.slice(0, 200)}`, status, url, body, code);
|
|
38
45
|
}
|
|
39
46
|
get retryable() { return false; }
|
|
40
47
|
}
|
|
@@ -46,8 +53,8 @@ export class ValidationError extends HttpError {
|
|
|
46
53
|
* a client error and is not one — the request is correct and merely early.
|
|
47
54
|
*/
|
|
48
55
|
export class BusyError extends HttpError {
|
|
49
|
-
constructor(status, url, body) {
|
|
50
|
-
super("BusyError", `Busy (${status}) — the resource is mid-operation`, status, url, body);
|
|
56
|
+
constructor(status, url, body, code) {
|
|
57
|
+
super("BusyError", `Busy (${status}) — the resource is mid-operation`, status, url, body, code);
|
|
51
58
|
}
|
|
52
59
|
get retryable() { return true; }
|
|
53
60
|
}
|
|
@@ -55,31 +62,31 @@ export class BusyError extends HttpError {
|
|
|
55
62
|
export class RateLimitError extends HttpError {
|
|
56
63
|
/** Seconds to wait, when the provider said. */
|
|
57
64
|
retryAfter;
|
|
58
|
-
constructor(url, body, retryAfter) {
|
|
59
|
-
super("RateLimitError", `Rate limited${retryAfter ? ` — retry in ${retryAfter}s` : ""}`, 429, url, body);
|
|
65
|
+
constructor(url, body, retryAfter, code) {
|
|
66
|
+
super("RateLimitError", `Rate limited${retryAfter ? ` — retry in ${retryAfter}s` : ""}`, 429, url, body, code);
|
|
60
67
|
this.retryAfter = retryAfter;
|
|
61
68
|
}
|
|
62
69
|
get retryable() { return true; }
|
|
63
70
|
}
|
|
64
71
|
/** The provider broke. Worth trying again. */
|
|
65
72
|
export class ServiceError extends HttpError {
|
|
66
|
-
constructor(status, url, body) {
|
|
67
|
-
super("ServiceError", `Service error (${status})`, status, url, body);
|
|
73
|
+
constructor(status, url, body, code) {
|
|
74
|
+
super("ServiceError", `Service error (${status})`, status, url, body, code);
|
|
68
75
|
}
|
|
69
76
|
get retryable() { return true; }
|
|
70
77
|
}
|
|
71
78
|
/** Map a response onto the right error. */
|
|
72
|
-
export function errorFor(status, url, body, retryAfter) {
|
|
79
|
+
export function errorFor(status, url, body, retryAfter, code) {
|
|
73
80
|
if (status === 401 || status === 403)
|
|
74
|
-
return new AuthError(status, url, body);
|
|
81
|
+
return new AuthError(status, url, body, code);
|
|
75
82
|
if (status === 404)
|
|
76
|
-
return new NotFoundError(url, body);
|
|
83
|
+
return new NotFoundError(url, body, code);
|
|
77
84
|
if (status === 423)
|
|
78
|
-
return new BusyError(status, url, body);
|
|
85
|
+
return new BusyError(status, url, body, code);
|
|
79
86
|
if (status === 429)
|
|
80
|
-
return new RateLimitError(url, body, retryAfter);
|
|
87
|
+
return new RateLimitError(url, body, retryAfter, code);
|
|
81
88
|
if (status >= 500)
|
|
82
|
-
return new ServiceError(status, url, body);
|
|
83
|
-
return new ValidationError(status, url, body);
|
|
89
|
+
return new ServiceError(status, url, body, code);
|
|
90
|
+
return new ValidationError(status, url, body, code);
|
|
84
91
|
}
|
|
85
92
|
//# sourceMappingURL=errors.js.map
|
package/dist/http/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAgB,SAAU,SAAQ,KAAK;IAClC,MA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AG,EAAE,MAAM,GAAG,IAAI,CAahD;AAED,wBAAgB,EAAE,CAAC,gBAAgB,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/services/db.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAahD;AAED,wBAAgB,EAAE,CAAC,gBAAgB,EAAE,MAAM;iBA0Cf,MAAM,WAAU,OAAO,EAAE,KAAQ,OAAO,CAAC,IAAI,CAAC;iBAW9C,MAAM,WAAU,OAAO,EAAE,KAAQ,OAAO,CAAC,IAAI,CAAC;cAatD,OAAO,CAAC,MAAM,EAAE,CAAC;mBAOZ,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;EAelD"}
|
package/dist/services/db.js
CHANGED
|
@@ -68,8 +68,11 @@ export function db(connectionString) {
|
|
|
68
68
|
if (!res.ok) {
|
|
69
69
|
// Postgres's own message names the column or the constraint; a status
|
|
70
70
|
// code alone sends someone to the wrong place. errorFor classifies it,
|
|
71
|
-
// so a worker knows a syntax error will never succeed on retry.
|
|
72
|
-
|
|
71
|
+
// so a worker knows a syntax error will never succeed on retry. The
|
|
72
|
+
// SQLSTATE travels too, so a caller can compare exactly — "undefined
|
|
73
|
+
// table" is 42P01, not whatever the message happens to say.
|
|
74
|
+
const code = typeof parsed.code === "string" ? parsed.code : undefined;
|
|
75
|
+
throw errorFor(res.status, endpoint, parsed.message ?? JSON.stringify(parsed), undefined, code);
|
|
73
76
|
}
|
|
74
77
|
return parsed;
|
|
75
78
|
}
|
package/dist/services/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/services/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAa7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,QAAQ,GAAG,GAAG;SACjB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IACpC,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,sEAAsE;YACpE,kEAAkE,CACrE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,EAAE,CAAC,gBAAwB;IACzC,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;IAC/F,CAAC;IACD,MAAM,QAAQ,GAAG,WAAW,IAAI,MAAM,CAAC;IAEvC,KAAK,UAAU,IAAI,CACjB,IAAa,EACb,UAAkC,EAAE;QAEpC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YAChC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,wBAAwB,EAAE,gBAAgB;gBAC1C,GAAG,OAAO;aACX;YACD,IAAI,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