@neon/sdk 0.0.0 → 0.1.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.md +178 -0
- package/README.md +349 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/client/client/client.gen.d.ts +7 -0
- package/dist/client/client/client.gen.d.ts.map +1 -0
- package/dist/client/client/client.gen.js +176 -0
- package/dist/client/client/client.gen.js.map +1 -0
- package/dist/client/client/index.d.ts +10 -0
- package/dist/client/client/index.js +6 -0
- package/dist/client/client/types.gen.d.ts +124 -0
- package/dist/client/client/types.gen.d.ts.map +1 -0
- package/dist/client/client/types.gen.js +1 -0
- package/dist/client/client/utils.gen.d.ts +42 -0
- package/dist/client/client/utils.gen.d.ts.map +1 -0
- package/dist/client/client/utils.gen.js +179 -0
- package/dist/client/client/utils.gen.js.map +1 -0
- package/dist/client/client.gen.d.ts +18 -0
- package/dist/client/client.gen.d.ts.map +1 -0
- package/dist/client/client.gen.js +8 -0
- package/dist/client/client.gen.js.map +1 -0
- package/dist/client/core/auth.gen.d.ts +29 -0
- package/dist/client/core/auth.gen.d.ts.map +1 -0
- package/dist/client/core/auth.gen.js +12 -0
- package/dist/client/core/auth.gen.js.map +1 -0
- package/dist/client/core/bodySerializer.gen.d.ts +29 -0
- package/dist/client/core/bodySerializer.gen.d.ts.map +1 -0
- package/dist/client/core/bodySerializer.gen.js +33 -0
- package/dist/client/core/bodySerializer.gen.js.map +1 -0
- package/dist/client/core/params.gen.d.ts +46 -0
- package/dist/client/core/params.gen.d.ts.map +1 -0
- package/dist/client/core/params.gen.js +65 -0
- package/dist/client/core/params.gen.js.map +1 -0
- package/dist/client/core/pathSerializer.gen.d.ts +52 -0
- package/dist/client/core/pathSerializer.gen.d.ts.map +1 -0
- package/dist/client/core/pathSerializer.gen.js +82 -0
- package/dist/client/core/pathSerializer.gen.js.map +1 -0
- package/dist/client/core/queryKeySerializer.gen.d.ts +22 -0
- package/dist/client/core/queryKeySerializer.gen.d.ts.map +1 -0
- package/dist/client/core/queryKeySerializer.gen.js +64 -0
- package/dist/client/core/queryKeySerializer.gen.js.map +1 -0
- package/dist/client/core/serverSentEvents.gen.d.ts +88 -0
- package/dist/client/core/serverSentEvents.gen.d.ts.map +1 -0
- package/dist/client/core/serverSentEvents.gen.js +95 -0
- package/dist/client/core/serverSentEvents.gen.js.map +1 -0
- package/dist/client/core/types.gen.d.ts +80 -0
- package/dist/client/core/types.gen.d.ts.map +1 -0
- package/dist/client/core/types.gen.js +1 -0
- package/dist/client/core/utils.gen.d.ts +33 -0
- package/dist/client/core/utils.gen.d.ts.map +1 -0
- package/dist/client/core/utils.gen.js +78 -0
- package/dist/client/core/utils.gen.js.map +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +2 -0
- package/dist/client/sdk.gen.d.ts +1362 -0
- package/dist/client/sdk.gen.d.ts.map +1 -0
- package/dist/client/sdk.gen.js +4315 -0
- package/dist/client/sdk.gen.js.map +1 -0
- package/dist/client/types.gen.d.ts +9938 -0
- package/dist/client/types.gen.d.ts.map +1 -0
- package/dist/client/types.gen.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +4 -0
- package/dist/neon/client.d.ts +52 -0
- package/dist/neon/client.d.ts.map +1 -0
- package/dist/neon/client.js +40 -0
- package/dist/neon/client.js.map +1 -0
- package/dist/neon/config.d.ts +40 -0
- package/dist/neon/config.d.ts.map +1 -0
- package/dist/neon/config.js +23 -0
- package/dist/neon/config.js.map +1 -0
- package/dist/neon/connection.d.ts +22 -0
- package/dist/neon/connection.d.ts.map +1 -0
- package/dist/neon/connection.js +33 -0
- package/dist/neon/connection.js.map +1 -0
- package/dist/neon/context.d.ts +50 -0
- package/dist/neon/context.d.ts.map +1 -0
- package/dist/neon/context.js +59 -0
- package/dist/neon/context.js.map +1 -0
- package/dist/neon/coverage.d.ts +26 -0
- package/dist/neon/coverage.d.ts.map +1 -0
- package/dist/neon/coverage.js +229 -0
- package/dist/neon/coverage.js.map +1 -0
- package/dist/neon/errors.d.ts +78 -0
- package/dist/neon/errors.d.ts.map +1 -0
- package/dist/neon/errors.js +116 -0
- package/dist/neon/errors.js.map +1 -0
- package/dist/neon/paginate.d.ts +34 -0
- package/dist/neon/paginate.d.ts.map +1 -0
- package/dist/neon/paginate.js +51 -0
- package/dist/neon/paginate.js.map +1 -0
- package/dist/neon/resources/account.d.ts +45 -0
- package/dist/neon/resources/account.d.ts.map +1 -0
- package/dist/neon/resources/account.js +65 -0
- package/dist/neon/resources/account.js.map +1 -0
- package/dist/neon/resources/branches.d.ts +84 -0
- package/dist/neon/resources/branches.d.ts.map +1 -0
- package/dist/neon/resources/branches.js +132 -0
- package/dist/neon/resources/branches.js.map +1 -0
- package/dist/neon/resources/consumption.d.ts +22 -0
- package/dist/neon/resources/consumption.d.ts.map +1 -0
- package/dist/neon/resources/consumption.js +59 -0
- package/dist/neon/resources/consumption.js.map +1 -0
- package/dist/neon/resources/dataapi.d.ts +25 -0
- package/dist/neon/resources/dataapi.d.ts.map +1 -0
- package/dist/neon/resources/dataapi.js +59 -0
- package/dist/neon/resources/dataapi.js.map +1 -0
- package/dist/neon/resources/databases.d.ts +30 -0
- package/dist/neon/resources/databases.d.ts.map +1 -0
- package/dist/neon/resources/databases.js +68 -0
- package/dist/neon/resources/databases.js.map +1 -0
- package/dist/neon/resources/endpoints.d.ts +39 -0
- package/dist/neon/resources/endpoints.d.ts.map +1 -0
- package/dist/neon/resources/endpoints.js +89 -0
- package/dist/neon/resources/endpoints.js.map +1 -0
- package/dist/neon/resources/operations.d.ts +27 -0
- package/dist/neon/resources/operations.d.ts.map +1 -0
- package/dist/neon/resources/operations.js +50 -0
- package/dist/neon/resources/operations.js.map +1 -0
- package/dist/neon/resources/postgres.d.ts +45 -0
- package/dist/neon/resources/postgres.d.ts.map +1 -0
- package/dist/neon/resources/postgres.js +104 -0
- package/dist/neon/resources/postgres.js.map +1 -0
- package/dist/neon/resources/projects.d.ts +84 -0
- package/dist/neon/resources/projects.d.ts.map +1 -0
- package/dist/neon/resources/projects.js +111 -0
- package/dist/neon/resources/projects.js.map +1 -0
- package/dist/neon/resources/roles.d.ts +40 -0
- package/dist/neon/resources/roles.d.ts.map +1 -0
- package/dist/neon/resources/roles.js +78 -0
- package/dist/neon/resources/roles.js.map +1 -0
- package/dist/neon/resources/snapshots.d.ts +86 -0
- package/dist/neon/resources/snapshots.d.ts.map +1 -0
- package/dist/neon/resources/snapshots.js +125 -0
- package/dist/neon/resources/snapshots.js.map +1 -0
- package/dist/neon/result.d.ts +32 -0
- package/dist/neon/result.d.ts.map +1 -0
- package/dist/neon/result.js +26 -0
- package/dist/neon/result.js.map +1 -0
- package/dist/neon/retry.d.ts +17 -0
- package/dist/neon/retry.d.ts.map +1 -0
- package/dist/neon/retry.js +42 -0
- package/dist/neon/retry.js.map +1 -0
- package/dist/neon/wait.d.ts +27 -0
- package/dist/neon/wait.d.ts.map +1 -0
- package/dist/neon/wait.js +70 -0
- package/dist/neon/wait.js.map +1 -0
- package/dist/raw.d.ts +13 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/raw.js +159 -0
- package/dist/raw.js.map +1 -0
- package/package.json +57 -16
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { toNeonError } from "./errors.js";
|
|
2
|
+
import { err, finalize, ok } from "./result.js";
|
|
3
|
+
import { withRetries } from "./retry.js";
|
|
4
|
+
import { hasOperations, waitForOperations } from "./wait.js";
|
|
5
|
+
//#region src/neon/context.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared execution core: runs a raw client call with retries, maps its envelope to the
|
|
8
|
+
* ergonomic resource shape, optionally waits for provisioning operations, and applies the
|
|
9
|
+
* resolved `throwOnError` policy. Returns the bare value (throwing) or a {@link NeonResult}.
|
|
10
|
+
*/
|
|
11
|
+
var RequestContext = class {
|
|
12
|
+
#config;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.#config = config;
|
|
15
|
+
}
|
|
16
|
+
get client() {
|
|
17
|
+
return this.#config.client;
|
|
18
|
+
}
|
|
19
|
+
get defaults() {
|
|
20
|
+
return this.#config;
|
|
21
|
+
}
|
|
22
|
+
/** Run a raw call and map its body; applies the resolved `throwOnError` policy. */
|
|
23
|
+
async run(opts, exec, map) {
|
|
24
|
+
const shouldThrow = opts?.throwOnError ?? this.#config.throwOnError;
|
|
25
|
+
return finalize(await this.execute(opts, exec, map), shouldThrow);
|
|
26
|
+
}
|
|
27
|
+
/** Like {@link run} but for endpoints that may return an empty (204) body. */
|
|
28
|
+
async runVoid(opts, exec) {
|
|
29
|
+
const shouldThrow = opts?.throwOnError ?? this.#config.throwOnError;
|
|
30
|
+
const raw = await withRetries(() => exec(this.#config.client), this.#config.retries, opts?.signal);
|
|
31
|
+
if (raw.error !== void 0) return finalize(err(toNeonError(raw.error, raw.response)), shouldThrow);
|
|
32
|
+
const readiness = await this.#maybeWait(opts, raw.data);
|
|
33
|
+
if (readiness?.error) return finalize(err(readiness.error), shouldThrow);
|
|
34
|
+
return finalize(ok(void 0), shouldThrow);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Run a raw call and map its body, returning the {@link NeonResult} envelope (no
|
|
38
|
+
* throw). Used by `run` and by workflows that post-process the result.
|
|
39
|
+
*/
|
|
40
|
+
async execute(opts, exec, map) {
|
|
41
|
+
const raw = await withRetries(() => exec(this.#config.client), this.#config.retries, opts?.signal);
|
|
42
|
+
if (raw.error || raw.data === void 0) return err(toNeonError(raw.error, raw.response));
|
|
43
|
+
const readiness = await this.#maybeWait(opts, raw.data);
|
|
44
|
+
if (readiness?.error) return err(readiness.error);
|
|
45
|
+
return ok(map(raw.data));
|
|
46
|
+
}
|
|
47
|
+
/** Poll provisioning operations when `waitForReadiness` is on and the body has any. */
|
|
48
|
+
async #maybeWait(opts, data) {
|
|
49
|
+
if (!(opts?.waitForReadiness ?? this.#config.waitForReadiness) || !hasOperations(data)) return void 0;
|
|
50
|
+
return waitForOperations(this.#config.client, data.operations, {
|
|
51
|
+
...this.#config.waitOptions,
|
|
52
|
+
signal: opts?.signal ?? this.#config.waitOptions.signal
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { RequestContext };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":["#config","#maybeWait"],"sources":["../../src/neon/context.ts"],"sourcesContent":["import type { Client } from \"../client/client/index.js\";\nimport { toNeonError } from \"./errors.js\";\nimport { err, finalize, type NeonResult, ok } from \"./result.js\";\nimport { withRetries } from \"./retry.js\";\nimport {\n\thasOperations,\n\ttype WaitForOptions,\n\twaitForOperations,\n} from \"./wait.js\";\n\n/** Fully-resolved runtime configuration shared by every resource namespace. */\nexport interface ResolvedConfig {\n\tclient: Client;\n\tthrowOnError: boolean;\n\tretries: number;\n\twaitForReadiness: boolean;\n\twaitOptions: WaitForOptions;\n\torgId?: string;\n}\n\n/** Per-call overrides accepted by every ergonomic method. */\nexport interface CallOptions<Throw extends boolean = boolean> {\n\t/** Override the client's `throwOnError` for this call. */\n\tthrowOnError?: Throw;\n\t/** Override the client's `waitForReadiness` for this call (mutations only). */\n\twaitForReadiness?: boolean;\n\tsignal?: AbortSignal;\n}\n\ninterface RawResult<D> {\n\tdata?: D | undefined;\n\terror?: unknown;\n\tresponse?: Response | undefined;\n}\n\n/**\n * Shared execution core: runs a raw client call with retries, maps its envelope to the\n * ergonomic resource shape, optionally waits for provisioning operations, and applies the\n * resolved `throwOnError` policy. Returns the bare value (throwing) or a {@link NeonResult}.\n */\nexport class RequestContext {\n\treadonly #config: ResolvedConfig;\n\n\tconstructor(config: ResolvedConfig) {\n\t\tthis.#config = config;\n\t}\n\n\tget client(): Client {\n\t\treturn this.#config.client;\n\t}\n\n\tget defaults(): ResolvedConfig {\n\t\treturn this.#config;\n\t}\n\n\t/** Run a raw call and map its body; applies the resolved `throwOnError` policy. */\n\tasync run<D, T>(\n\t\topts: CallOptions | undefined,\n\t\texec: (client: Client) => Promise<RawResult<D>>,\n\t\tmap: (data: D) => T,\n\t): Promise<T | NeonResult<T>> {\n\t\tconst shouldThrow = opts?.throwOnError ?? this.#config.throwOnError;\n\t\treturn finalize(await this.execute(opts, exec, map), shouldThrow);\n\t}\n\n\t/** Like {@link run} but for endpoints that may return an empty (204) body. */\n\tasync runVoid<D>(\n\t\topts: CallOptions | undefined,\n\t\texec: (client: Client) => Promise<RawResult<D>>,\n\t): Promise<void | NeonResult<void>> {\n\t\tconst shouldThrow = opts?.throwOnError ?? this.#config.throwOnError;\n\t\tconst raw = await withRetries(\n\t\t\t() => exec(this.#config.client),\n\t\t\tthis.#config.retries,\n\t\t\topts?.signal,\n\t\t);\n\t\tif (raw.error !== undefined) {\n\t\t\treturn finalize(\n\t\t\t\terr<void>(toNeonError(raw.error, raw.response)),\n\t\t\t\tshouldThrow,\n\t\t\t);\n\t\t}\n\t\tconst readiness = await this.#maybeWait(opts, raw.data);\n\t\tif (readiness?.error)\n\t\t\treturn finalize(err<void>(readiness.error), shouldThrow);\n\t\treturn finalize(ok(undefined), shouldThrow);\n\t}\n\n\t/**\n\t * Run a raw call and map its body, returning the {@link NeonResult} envelope (no\n\t * throw). Used by `run` and by workflows that post-process the result.\n\t */\n\tasync execute<D, T>(\n\t\topts: CallOptions | undefined,\n\t\texec: (client: Client) => Promise<RawResult<D>>,\n\t\tmap: (data: D) => T,\n\t): Promise<NeonResult<T>> {\n\t\tconst raw = await withRetries(\n\t\t\t() => exec(this.#config.client),\n\t\t\tthis.#config.retries,\n\t\t\topts?.signal,\n\t\t);\n\t\tif (raw.error || raw.data === undefined) {\n\t\t\treturn err(toNeonError(raw.error, raw.response));\n\t\t}\n\t\tconst readiness = await this.#maybeWait(opts, raw.data);\n\t\tif (readiness?.error) return err(readiness.error);\n\t\treturn ok(map(raw.data));\n\t}\n\n\t/** Poll provisioning operations when `waitForReadiness` is on and the body has any. */\n\tasync #maybeWait(\n\t\topts: CallOptions | undefined,\n\t\tdata: unknown,\n\t): Promise<NeonResult<void> | undefined> {\n\t\tconst wait = opts?.waitForReadiness ?? this.#config.waitForReadiness;\n\t\tif (!wait || !hasOperations(data)) return undefined;\n\t\treturn waitForOperations(this.#config.client, data.operations, {\n\t\t\t...this.#config.waitOptions,\n\t\t\tsignal: opts?.signal ?? this.#config.waitOptions.signal,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;AAwCA,IAAa,iBAAb,MAA4B;CAC3B;CAEA,YAAY,QAAwB;EACnC,KAAKA,UAAU;CAChB;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAKA,QAAQ;CACrB;CAEA,IAAI,WAA2B;EAC9B,OAAO,KAAKA;CACb;;CAGA,MAAM,IACL,MACA,MACA,KAC6B;EAC7B,MAAM,cAAc,MAAM,gBAAgB,KAAKA,QAAQ;EACvD,OAAO,SAAS,MAAM,KAAK,QAAQ,MAAM,MAAM,GAAG,GAAG,WAAW;CACjE;;CAGA,MAAM,QACL,MACA,MACmC;EACnC,MAAM,cAAc,MAAM,gBAAgB,KAAKA,QAAQ;EACvD,MAAM,MAAM,MAAM,kBACX,KAAK,KAAKA,QAAQ,MAAM,GAC9B,KAAKA,QAAQ,SACb,MAAM,MACP;EACA,IAAI,IAAI,UAAU,KAAA,GACjB,OAAO,SACN,IAAU,YAAY,IAAI,OAAO,IAAI,QAAQ,CAAC,GAC9C,WACD;EAED,MAAM,YAAY,MAAM,KAAKC,WAAW,MAAM,IAAI,IAAI;EACtD,IAAI,WAAW,OACd,OAAO,SAAS,IAAU,UAAU,KAAK,GAAG,WAAW;EACxD,OAAO,SAAS,GAAG,KAAA,CAAS,GAAG,WAAW;CAC3C;;;;;CAMA,MAAM,QACL,MACA,MACA,KACyB;EACzB,MAAM,MAAM,MAAM,kBACX,KAAK,KAAKD,QAAQ,MAAM,GAC9B,KAAKA,QAAQ,SACb,MAAM,MACP;EACA,IAAI,IAAI,SAAS,IAAI,SAAS,KAAA,GAC7B,OAAO,IAAI,YAAY,IAAI,OAAO,IAAI,QAAQ,CAAC;EAEhD,MAAM,YAAY,MAAM,KAAKC,WAAW,MAAM,IAAI,IAAI;EACtD,IAAI,WAAW,OAAO,OAAO,IAAI,UAAU,KAAK;EAChD,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC;CACxB;;CAGA,MAAMA,WACL,MACA,MACwC;EAExC,IAAI,EADS,MAAM,oBAAoB,KAAKD,QAAQ,qBACvC,CAAC,cAAc,IAAI,GAAG,OAAO,KAAA;EAC1C,OAAO,kBAAkB,KAAKA,QAAQ,QAAQ,KAAK,YAAY;GAC9D,GAAG,KAAKA,QAAQ;GAChB,QAAQ,MAAM,UAAU,KAAKA,QAAQ,YAAY;EAClD,CAAC;CACF;AACD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/neon/coverage.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Drift guard for the ergonomic layer.
|
|
4
|
+
*
|
|
5
|
+
* The raw layer is regenerated from the OpenAPI spec, so it auto-tracks new endpoints.
|
|
6
|
+
* The ergonomic resource namespaces are hand-authored, so they can silently fall behind.
|
|
7
|
+
* `coverage.test.ts` compares the generated operation set against {@link EXPECTED_OPERATIONS}
|
|
8
|
+
* and fails CI when they differ — forcing a conscious decision on every spec change:
|
|
9
|
+
* either wrap the new operation in a resource (and add it to {@link WRAPPED}) or accept
|
|
10
|
+
* that it stays raw-only (and add it to the snapshot below).
|
|
11
|
+
*
|
|
12
|
+
* Workflow when the test fails after a `pnpm generate`:
|
|
13
|
+
* 1. Review the `added` / `removed` operations the test reports.
|
|
14
|
+
* 2. Wrap the ones worth ergonomic treatment (and list them in {@link WRAPPED}).
|
|
15
|
+
* 3. Update {@link EXPECTED_OPERATIONS} to match the new generated set.
|
|
16
|
+
*/
|
|
17
|
+
/** Operations surfaced by the ergonomic `createNeonClient` namespaces. */
|
|
18
|
+
declare const WRAPPED: ReadonlySet<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Committed snapshot of every operation the generated client exposes. Update this
|
|
21
|
+
* deliberately whenever the spec (and thus the generated client) changes.
|
|
22
|
+
*/
|
|
23
|
+
declare const EXPECTED_OPERATIONS: ReadonlySet<string>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { EXPECTED_OPERATIONS, WRAPPED };
|
|
26
|
+
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","names":[],"sources":["../../src/neon/coverage.ts"],"mappings":";;AAiBA;AA0EA;;;;;;;;;;;;;;cA1Ea,SAAS;;;;;cA0ET,qBAAqB"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//#region src/neon/coverage.ts
|
|
2
|
+
/**
|
|
3
|
+
* Drift guard for the ergonomic layer.
|
|
4
|
+
*
|
|
5
|
+
* The raw layer is regenerated from the OpenAPI spec, so it auto-tracks new endpoints.
|
|
6
|
+
* The ergonomic resource namespaces are hand-authored, so they can silently fall behind.
|
|
7
|
+
* `coverage.test.ts` compares the generated operation set against {@link EXPECTED_OPERATIONS}
|
|
8
|
+
* and fails CI when they differ — forcing a conscious decision on every spec change:
|
|
9
|
+
* either wrap the new operation in a resource (and add it to {@link WRAPPED}) or accept
|
|
10
|
+
* that it stays raw-only (and add it to the snapshot below).
|
|
11
|
+
*
|
|
12
|
+
* Workflow when the test fails after a `pnpm generate`:
|
|
13
|
+
* 1. Review the `added` / `removed` operations the test reports.
|
|
14
|
+
* 2. Wrap the ones worth ergonomic treatment (and list them in {@link WRAPPED}).
|
|
15
|
+
* 3. Update {@link EXPECTED_OPERATIONS} to match the new generated set.
|
|
16
|
+
*/
|
|
17
|
+
/** Operations surfaced by the ergonomic `createNeonClient` namespaces. */
|
|
18
|
+
const WRAPPED = /* @__PURE__ */ new Set([
|
|
19
|
+
"listProjects",
|
|
20
|
+
"getProject",
|
|
21
|
+
"createProject",
|
|
22
|
+
"updateProject",
|
|
23
|
+
"deleteProject",
|
|
24
|
+
"transferProjectsFromOrgToOrg",
|
|
25
|
+
"transferProjectsFromUserToOrg",
|
|
26
|
+
"listProjectBranches",
|
|
27
|
+
"getProjectBranch",
|
|
28
|
+
"createProjectBranch",
|
|
29
|
+
"updateProjectBranch",
|
|
30
|
+
"deleteProjectBranch",
|
|
31
|
+
"setDefaultProjectBranch",
|
|
32
|
+
"finalizeRestoreBranch",
|
|
33
|
+
"getProjectOperation",
|
|
34
|
+
"listProjectOperations",
|
|
35
|
+
"listProjectEndpoints",
|
|
36
|
+
"getProjectEndpoint",
|
|
37
|
+
"createProjectEndpoint",
|
|
38
|
+
"updateProjectEndpoint",
|
|
39
|
+
"deleteProjectEndpoint",
|
|
40
|
+
"startProjectEndpoint",
|
|
41
|
+
"suspendProjectEndpoint",
|
|
42
|
+
"restartProjectEndpoint",
|
|
43
|
+
"listProjectBranchDatabases",
|
|
44
|
+
"getProjectBranchDatabase",
|
|
45
|
+
"createProjectBranchDatabase",
|
|
46
|
+
"updateProjectBranchDatabase",
|
|
47
|
+
"deleteProjectBranchDatabase",
|
|
48
|
+
"listProjectBranchRoles",
|
|
49
|
+
"getProjectBranchRole",
|
|
50
|
+
"createProjectBranchRole",
|
|
51
|
+
"deleteProjectBranchRole",
|
|
52
|
+
"getProjectBranchRolePassword",
|
|
53
|
+
"resetProjectBranchRolePassword",
|
|
54
|
+
"getConnectionUri",
|
|
55
|
+
"getProjectBranchDataApi",
|
|
56
|
+
"createProjectBranchDataApi",
|
|
57
|
+
"updateProjectBranchDataApi",
|
|
58
|
+
"deleteProjectBranchDataApi",
|
|
59
|
+
"listSnapshots",
|
|
60
|
+
"createSnapshot",
|
|
61
|
+
"updateSnapshot",
|
|
62
|
+
"deleteSnapshot",
|
|
63
|
+
"restoreSnapshot",
|
|
64
|
+
"getSnapshotSchedule",
|
|
65
|
+
"setSnapshotSchedule",
|
|
66
|
+
"getConsumptionHistoryPerProject",
|
|
67
|
+
"getConsumptionHistoryPerProjectV2",
|
|
68
|
+
"getConsumptionHistoryPerBranchV2",
|
|
69
|
+
"getCurrentUserInfo",
|
|
70
|
+
"getCurrentUserOrganizations",
|
|
71
|
+
"getActiveRegions",
|
|
72
|
+
"listApiKeys",
|
|
73
|
+
"createApiKey",
|
|
74
|
+
"revokeApiKey"
|
|
75
|
+
]);
|
|
76
|
+
/**
|
|
77
|
+
* Committed snapshot of every operation the generated client exposes. Update this
|
|
78
|
+
* deliberately whenever the spec (and thus the generated client) changes.
|
|
79
|
+
*/
|
|
80
|
+
const EXPECTED_OPERATIONS = /* @__PURE__ */ new Set([
|
|
81
|
+
"acceptProjectTransferRequest",
|
|
82
|
+
"addBranchNeonAuthOauthProvider",
|
|
83
|
+
"addBranchNeonAuthTrustedDomain",
|
|
84
|
+
"addNeonAuthDomainToRedirectUriWhitelist",
|
|
85
|
+
"addNeonAuthOauthProvider",
|
|
86
|
+
"addProjectJwks",
|
|
87
|
+
"assignOrganizationVpcEndpoint",
|
|
88
|
+
"assignProjectVpcEndpoint",
|
|
89
|
+
"countProjectBranches",
|
|
90
|
+
"createApiKey",
|
|
91
|
+
"createBranchNeonAuthNewUser",
|
|
92
|
+
"createNeonAuth",
|
|
93
|
+
"createNeonAuthIntegration",
|
|
94
|
+
"createNeonAuthNewUser",
|
|
95
|
+
"createNeonAuthProviderSdkKeys",
|
|
96
|
+
"createOrgApiKey",
|
|
97
|
+
"createOrganizationInvitations",
|
|
98
|
+
"createProject",
|
|
99
|
+
"createProjectBranch",
|
|
100
|
+
"createProjectBranchAnonymized",
|
|
101
|
+
"createProjectBranchDataApi",
|
|
102
|
+
"createProjectBranchDatabase",
|
|
103
|
+
"createProjectBranchRole",
|
|
104
|
+
"createProjectEndpoint",
|
|
105
|
+
"createProjectTransferRequest",
|
|
106
|
+
"createSnapshot",
|
|
107
|
+
"deleteBranchNeonAuthOauthProvider",
|
|
108
|
+
"deleteBranchNeonAuthTrustedDomain",
|
|
109
|
+
"deleteBranchNeonAuthUser",
|
|
110
|
+
"deleteNeonAuthDomainFromRedirectUriWhitelist",
|
|
111
|
+
"deleteNeonAuthIntegration",
|
|
112
|
+
"deleteNeonAuthOauthProvider",
|
|
113
|
+
"deleteNeonAuthUser",
|
|
114
|
+
"deleteOrganizationSpendingLimit",
|
|
115
|
+
"deleteOrganizationVpcEndpoint",
|
|
116
|
+
"deleteProject",
|
|
117
|
+
"deleteProjectBranch",
|
|
118
|
+
"deleteProjectBranchDataApi",
|
|
119
|
+
"deleteProjectBranchDatabase",
|
|
120
|
+
"deleteProjectBranchRole",
|
|
121
|
+
"deleteProjectEndpoint",
|
|
122
|
+
"deleteProjectJwks",
|
|
123
|
+
"deleteProjectVpcEndpoint",
|
|
124
|
+
"deleteSnapshot",
|
|
125
|
+
"disableNeonAuth",
|
|
126
|
+
"finalizeRestoreBranch",
|
|
127
|
+
"getActiveRegions",
|
|
128
|
+
"getAnonymizedBranchStatus",
|
|
129
|
+
"getAuthDetails",
|
|
130
|
+
"getAvailablePreloadLibraries",
|
|
131
|
+
"getConnectionUri",
|
|
132
|
+
"getConsumptionHistoryPerBranchV2",
|
|
133
|
+
"getConsumptionHistoryPerProject",
|
|
134
|
+
"getConsumptionHistoryPerProjectV2",
|
|
135
|
+
"getCurrentUserInfo",
|
|
136
|
+
"getCurrentUserOrganizations",
|
|
137
|
+
"getMaskingRules",
|
|
138
|
+
"getNeonAuth",
|
|
139
|
+
"getNeonAuthAllowLocalhost",
|
|
140
|
+
"getNeonAuthEmailAndPasswordConfig",
|
|
141
|
+
"getNeonAuthEmailProvider",
|
|
142
|
+
"getNeonAuthEmailServer",
|
|
143
|
+
"getNeonAuthPhoneNumberPlugin",
|
|
144
|
+
"getNeonAuthPluginConfigs",
|
|
145
|
+
"getNeonAuthWebhookConfig",
|
|
146
|
+
"getOrganization",
|
|
147
|
+
"getOrganizationInvitations",
|
|
148
|
+
"getOrganizationMember",
|
|
149
|
+
"getOrganizationMembers",
|
|
150
|
+
"getOrganizationSpendingLimit",
|
|
151
|
+
"getOrganizationVpcEndpointDetails",
|
|
152
|
+
"getProject",
|
|
153
|
+
"getProjectAdvisorSecurityIssues",
|
|
154
|
+
"getProjectBranch",
|
|
155
|
+
"getProjectBranchDataApi",
|
|
156
|
+
"getProjectBranchDatabase",
|
|
157
|
+
"getProjectBranchRole",
|
|
158
|
+
"getProjectBranchRolePassword",
|
|
159
|
+
"getProjectBranchSchema",
|
|
160
|
+
"getProjectBranchSchemaComparison",
|
|
161
|
+
"getProjectEndpoint",
|
|
162
|
+
"getProjectJwks",
|
|
163
|
+
"getProjectOperation",
|
|
164
|
+
"getSnapshotSchedule",
|
|
165
|
+
"grantPermissionToProject",
|
|
166
|
+
"listApiKeys",
|
|
167
|
+
"listBranchNeonAuthOauthProviders",
|
|
168
|
+
"listBranchNeonAuthTrustedDomains",
|
|
169
|
+
"listNeonAuthIntegrations",
|
|
170
|
+
"listNeonAuthOauthProviders",
|
|
171
|
+
"listNeonAuthRedirectUriWhitelistDomains",
|
|
172
|
+
"listOrgApiKeys",
|
|
173
|
+
"listOrganizationVpcEndpoints",
|
|
174
|
+
"listOrganizationVpcEndpointsAllRegions",
|
|
175
|
+
"listProjectBranchDatabases",
|
|
176
|
+
"listProjectBranchEndpoints",
|
|
177
|
+
"listProjectBranchRoles",
|
|
178
|
+
"listProjectBranches",
|
|
179
|
+
"listProjectEndpoints",
|
|
180
|
+
"listProjectOperations",
|
|
181
|
+
"listProjectPermissions",
|
|
182
|
+
"listProjectVpcEndpoints",
|
|
183
|
+
"listProjects",
|
|
184
|
+
"listSharedProjects",
|
|
185
|
+
"listSnapshots",
|
|
186
|
+
"recoverProject",
|
|
187
|
+
"removeOrganizationMember",
|
|
188
|
+
"resetProjectBranchRolePassword",
|
|
189
|
+
"restartProjectEndpoint",
|
|
190
|
+
"restoreProjectBranch",
|
|
191
|
+
"restoreSnapshot",
|
|
192
|
+
"revokeApiKey",
|
|
193
|
+
"revokeOrgApiKey",
|
|
194
|
+
"revokePermissionFromProject",
|
|
195
|
+
"sendNeonAuthTestEmail",
|
|
196
|
+
"setDefaultProjectBranch",
|
|
197
|
+
"setOrganizationSpendingLimit",
|
|
198
|
+
"setSnapshotSchedule",
|
|
199
|
+
"startAnonymization",
|
|
200
|
+
"startProjectEndpoint",
|
|
201
|
+
"suspendProjectEndpoint",
|
|
202
|
+
"transferNeonAuthProviderProject",
|
|
203
|
+
"transferProjectsFromOrgToOrg",
|
|
204
|
+
"transferProjectsFromUserToOrg",
|
|
205
|
+
"updateBranchNeonAuthOauthProvider",
|
|
206
|
+
"updateMaskingRules",
|
|
207
|
+
"updateNeonAuthAllowLocalhost",
|
|
208
|
+
"updateNeonAuthConfig",
|
|
209
|
+
"updateNeonAuthEmailAndPasswordConfig",
|
|
210
|
+
"updateNeonAuthEmailProvider",
|
|
211
|
+
"updateNeonAuthEmailServer",
|
|
212
|
+
"updateNeonAuthMagicLinkPlugin",
|
|
213
|
+
"updateNeonAuthOauthProvider",
|
|
214
|
+
"updateNeonAuthOrganizationPlugin",
|
|
215
|
+
"updateNeonAuthPhoneNumberPlugin",
|
|
216
|
+
"updateNeonAuthUserRole",
|
|
217
|
+
"updateNeonAuthWebhookConfig",
|
|
218
|
+
"updateOrganizationMember",
|
|
219
|
+
"updateProject",
|
|
220
|
+
"updateProjectBranch",
|
|
221
|
+
"updateProjectBranchDataApi",
|
|
222
|
+
"updateProjectBranchDatabase",
|
|
223
|
+
"updateProjectEndpoint",
|
|
224
|
+
"updateSnapshot"
|
|
225
|
+
]);
|
|
226
|
+
//#endregion
|
|
227
|
+
export { EXPECTED_OPERATIONS, WRAPPED };
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.js","names":[],"sources":["../../src/neon/coverage.ts"],"sourcesContent":["/**\n * Drift guard for the ergonomic layer.\n *\n * The raw layer is regenerated from the OpenAPI spec, so it auto-tracks new endpoints.\n * The ergonomic resource namespaces are hand-authored, so they can silently fall behind.\n * `coverage.test.ts` compares the generated operation set against {@link EXPECTED_OPERATIONS}\n * and fails CI when they differ — forcing a conscious decision on every spec change:\n * either wrap the new operation in a resource (and add it to {@link WRAPPED}) or accept\n * that it stays raw-only (and add it to the snapshot below).\n *\n * Workflow when the test fails after a `pnpm generate`:\n * 1. Review the `added` / `removed` operations the test reports.\n * 2. Wrap the ones worth ergonomic treatment (and list them in {@link WRAPPED}).\n * 3. Update {@link EXPECTED_OPERATIONS} to match the new generated set.\n */\n\n/** Operations surfaced by the ergonomic `createNeonClient` namespaces. */\nexport const WRAPPED: ReadonlySet<string> = new Set([\n\t// projects\n\t\"listProjects\",\n\t\"getProject\",\n\t\"createProject\",\n\t\"updateProject\",\n\t\"deleteProject\",\n\t// projects: transfer\n\t\"transferProjectsFromOrgToOrg\",\n\t\"transferProjectsFromUserToOrg\",\n\t// branches\n\t\"listProjectBranches\",\n\t\"getProjectBranch\",\n\t\"createProjectBranch\",\n\t\"updateProjectBranch\",\n\t\"deleteProjectBranch\",\n\t\"setDefaultProjectBranch\",\n\t\"finalizeRestoreBranch\",\n\t// operations\n\t\"getProjectOperation\",\n\t\"listProjectOperations\",\n\t// postgres: endpoints\n\t\"listProjectEndpoints\",\n\t\"getProjectEndpoint\",\n\t\"createProjectEndpoint\",\n\t\"updateProjectEndpoint\",\n\t\"deleteProjectEndpoint\",\n\t\"startProjectEndpoint\",\n\t\"suspendProjectEndpoint\",\n\t\"restartProjectEndpoint\",\n\t// postgres: databases\n\t\"listProjectBranchDatabases\",\n\t\"getProjectBranchDatabase\",\n\t\"createProjectBranchDatabase\",\n\t\"updateProjectBranchDatabase\",\n\t\"deleteProjectBranchDatabase\",\n\t// postgres: roles\n\t\"listProjectBranchRoles\",\n\t\"getProjectBranchRole\",\n\t\"createProjectBranchRole\",\n\t\"deleteProjectBranchRole\",\n\t\"getProjectBranchRolePassword\",\n\t\"resetProjectBranchRolePassword\",\n\t// postgres: connection string + data api\n\t\"getConnectionUri\",\n\t\"getProjectBranchDataApi\",\n\t\"createProjectBranchDataApi\",\n\t\"updateProjectBranchDataApi\",\n\t\"deleteProjectBranchDataApi\",\n\t// snapshots\n\t\"listSnapshots\",\n\t\"createSnapshot\",\n\t\"updateSnapshot\",\n\t\"deleteSnapshot\",\n\t\"restoreSnapshot\",\n\t\"getSnapshotSchedule\",\n\t\"setSnapshotSchedule\",\n\t// consumption\n\t\"getConsumptionHistoryPerProject\",\n\t\"getConsumptionHistoryPerProjectV2\",\n\t\"getConsumptionHistoryPerBranchV2\",\n\t// account\n\t\"getCurrentUserInfo\",\n\t\"getCurrentUserOrganizations\",\n\t\"getActiveRegions\",\n\t\"listApiKeys\",\n\t\"createApiKey\",\n\t\"revokeApiKey\",\n]);\n\n/**\n * Committed snapshot of every operation the generated client exposes. Update this\n * deliberately whenever the spec (and thus the generated client) changes.\n */\nexport const EXPECTED_OPERATIONS: ReadonlySet<string> = new Set([\n\t\"acceptProjectTransferRequest\",\n\t\"addBranchNeonAuthOauthProvider\",\n\t\"addBranchNeonAuthTrustedDomain\",\n\t\"addNeonAuthDomainToRedirectUriWhitelist\",\n\t\"addNeonAuthOauthProvider\",\n\t\"addProjectJwks\",\n\t\"assignOrganizationVpcEndpoint\",\n\t\"assignProjectVpcEndpoint\",\n\t\"countProjectBranches\",\n\t\"createApiKey\",\n\t\"createBranchNeonAuthNewUser\",\n\t\"createNeonAuth\",\n\t\"createNeonAuthIntegration\",\n\t\"createNeonAuthNewUser\",\n\t\"createNeonAuthProviderSdkKeys\",\n\t\"createOrgApiKey\",\n\t\"createOrganizationInvitations\",\n\t\"createProject\",\n\t\"createProjectBranch\",\n\t\"createProjectBranchAnonymized\",\n\t\"createProjectBranchDataApi\",\n\t\"createProjectBranchDatabase\",\n\t\"createProjectBranchRole\",\n\t\"createProjectEndpoint\",\n\t\"createProjectTransferRequest\",\n\t\"createSnapshot\",\n\t\"deleteBranchNeonAuthOauthProvider\",\n\t\"deleteBranchNeonAuthTrustedDomain\",\n\t\"deleteBranchNeonAuthUser\",\n\t\"deleteNeonAuthDomainFromRedirectUriWhitelist\",\n\t\"deleteNeonAuthIntegration\",\n\t\"deleteNeonAuthOauthProvider\",\n\t\"deleteNeonAuthUser\",\n\t\"deleteOrganizationSpendingLimit\",\n\t\"deleteOrganizationVpcEndpoint\",\n\t\"deleteProject\",\n\t\"deleteProjectBranch\",\n\t\"deleteProjectBranchDataApi\",\n\t\"deleteProjectBranchDatabase\",\n\t\"deleteProjectBranchRole\",\n\t\"deleteProjectEndpoint\",\n\t\"deleteProjectJwks\",\n\t\"deleteProjectVpcEndpoint\",\n\t\"deleteSnapshot\",\n\t\"disableNeonAuth\",\n\t\"finalizeRestoreBranch\",\n\t\"getActiveRegions\",\n\t\"getAnonymizedBranchStatus\",\n\t\"getAuthDetails\",\n\t\"getAvailablePreloadLibraries\",\n\t\"getConnectionUri\",\n\t\"getConsumptionHistoryPerBranchV2\",\n\t\"getConsumptionHistoryPerProject\",\n\t\"getConsumptionHistoryPerProjectV2\",\n\t\"getCurrentUserInfo\",\n\t\"getCurrentUserOrganizations\",\n\t\"getMaskingRules\",\n\t\"getNeonAuth\",\n\t\"getNeonAuthAllowLocalhost\",\n\t\"getNeonAuthEmailAndPasswordConfig\",\n\t\"getNeonAuthEmailProvider\",\n\t\"getNeonAuthEmailServer\",\n\t\"getNeonAuthPhoneNumberPlugin\",\n\t\"getNeonAuthPluginConfigs\",\n\t\"getNeonAuthWebhookConfig\",\n\t\"getOrganization\",\n\t\"getOrganizationInvitations\",\n\t\"getOrganizationMember\",\n\t\"getOrganizationMembers\",\n\t\"getOrganizationSpendingLimit\",\n\t\"getOrganizationVpcEndpointDetails\",\n\t\"getProject\",\n\t\"getProjectAdvisorSecurityIssues\",\n\t\"getProjectBranch\",\n\t\"getProjectBranchDataApi\",\n\t\"getProjectBranchDatabase\",\n\t\"getProjectBranchRole\",\n\t\"getProjectBranchRolePassword\",\n\t\"getProjectBranchSchema\",\n\t\"getProjectBranchSchemaComparison\",\n\t\"getProjectEndpoint\",\n\t\"getProjectJwks\",\n\t\"getProjectOperation\",\n\t\"getSnapshotSchedule\",\n\t\"grantPermissionToProject\",\n\t\"listApiKeys\",\n\t\"listBranchNeonAuthOauthProviders\",\n\t\"listBranchNeonAuthTrustedDomains\",\n\t\"listNeonAuthIntegrations\",\n\t\"listNeonAuthOauthProviders\",\n\t\"listNeonAuthRedirectUriWhitelistDomains\",\n\t\"listOrgApiKeys\",\n\t\"listOrganizationVpcEndpoints\",\n\t\"listOrganizationVpcEndpointsAllRegions\",\n\t\"listProjectBranchDatabases\",\n\t\"listProjectBranchEndpoints\",\n\t\"listProjectBranchRoles\",\n\t\"listProjectBranches\",\n\t\"listProjectEndpoints\",\n\t\"listProjectOperations\",\n\t\"listProjectPermissions\",\n\t\"listProjectVpcEndpoints\",\n\t\"listProjects\",\n\t\"listSharedProjects\",\n\t\"listSnapshots\",\n\t\"recoverProject\",\n\t\"removeOrganizationMember\",\n\t\"resetProjectBranchRolePassword\",\n\t\"restartProjectEndpoint\",\n\t\"restoreProjectBranch\",\n\t\"restoreSnapshot\",\n\t\"revokeApiKey\",\n\t\"revokeOrgApiKey\",\n\t\"revokePermissionFromProject\",\n\t\"sendNeonAuthTestEmail\",\n\t\"setDefaultProjectBranch\",\n\t\"setOrganizationSpendingLimit\",\n\t\"setSnapshotSchedule\",\n\t\"startAnonymization\",\n\t\"startProjectEndpoint\",\n\t\"suspendProjectEndpoint\",\n\t\"transferNeonAuthProviderProject\",\n\t\"transferProjectsFromOrgToOrg\",\n\t\"transferProjectsFromUserToOrg\",\n\t\"updateBranchNeonAuthOauthProvider\",\n\t\"updateMaskingRules\",\n\t\"updateNeonAuthAllowLocalhost\",\n\t\"updateNeonAuthConfig\",\n\t\"updateNeonAuthEmailAndPasswordConfig\",\n\t\"updateNeonAuthEmailProvider\",\n\t\"updateNeonAuthEmailServer\",\n\t\"updateNeonAuthMagicLinkPlugin\",\n\t\"updateNeonAuthOauthProvider\",\n\t\"updateNeonAuthOrganizationPlugin\",\n\t\"updateNeonAuthPhoneNumberPlugin\",\n\t\"updateNeonAuthUserRole\",\n\t\"updateNeonAuthWebhookConfig\",\n\t\"updateOrganizationMember\",\n\t\"updateProject\",\n\t\"updateProjectBranch\",\n\t\"updateProjectBranchDataApi\",\n\t\"updateProjectBranchDatabase\",\n\t\"updateProjectEndpoint\",\n\t\"updateSnapshot\",\n]);\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,0BAA+B,IAAI,IAAI;CAEnD;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;AAMD,MAAa,sCAA2C,IAAI,IAAI;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/neon/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Typed error hierarchy surfaced on the `error` channel of every ergonomic call (and
|
|
4
|
+
* thrown when `throwOnError` is set). All are `Error` subclasses with a `kind`
|
|
5
|
+
* discriminant, so the same value works whether you read it from `{ error }` or `catch`
|
|
6
|
+
* it.
|
|
7
|
+
*/
|
|
8
|
+
type NeonErrorKind = "api" | "not_found" | "auth" | "rate_limit" | "operation" | "timeout" | "network" | "client";
|
|
9
|
+
/** Base class for every error the ergonomic layer produces. */
|
|
10
|
+
declare class NeonError extends Error {
|
|
11
|
+
readonly kind: NeonErrorKind;
|
|
12
|
+
constructor(message: string, kind: NeonErrorKind, options?: {
|
|
13
|
+
cause?: unknown;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** A non-2xx HTTP response from the Neon API. */
|
|
17
|
+
declare class NeonApiError extends NeonError {
|
|
18
|
+
/** HTTP status code. */
|
|
19
|
+
readonly status: number;
|
|
20
|
+
/** Machine-readable Neon error code (`GeneralError.code`), when present. */
|
|
21
|
+
readonly code?: string;
|
|
22
|
+
/** Neon request id (`X-Request-Id` / `GeneralError.request_id`), when present. */
|
|
23
|
+
readonly requestId?: string;
|
|
24
|
+
/** The raw response, when one was received. */
|
|
25
|
+
readonly response?: Response;
|
|
26
|
+
/** The parsed error body, as returned by the API. */
|
|
27
|
+
readonly body: unknown;
|
|
28
|
+
constructor(message: string, init: {
|
|
29
|
+
kind?: NeonErrorKind;
|
|
30
|
+
status: number;
|
|
31
|
+
code?: string;
|
|
32
|
+
requestId?: string;
|
|
33
|
+
response?: Response;
|
|
34
|
+
body?: unknown;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** 404 — the resource does not exist. */
|
|
38
|
+
declare class NeonNotFoundError extends NeonApiError {
|
|
39
|
+
constructor(message: string, init: ConstructorParameters<typeof NeonApiError>[1]);
|
|
40
|
+
}
|
|
41
|
+
/** 401/403 — the API key is missing, invalid, or lacks permission. */
|
|
42
|
+
declare class NeonAuthError extends NeonApiError {
|
|
43
|
+
constructor(message: string, init: ConstructorParameters<typeof NeonApiError>[1]);
|
|
44
|
+
}
|
|
45
|
+
/** 429 — rate limited (after retries, if enabled, were exhausted). */
|
|
46
|
+
declare class NeonRateLimitError extends NeonApiError {
|
|
47
|
+
constructor(message: string, init: ConstructorParameters<typeof NeonApiError>[1]);
|
|
48
|
+
}
|
|
49
|
+
/** An awaited Neon operation ended in a non-success terminal state. */
|
|
50
|
+
declare class NeonOperationError extends NeonError {
|
|
51
|
+
/** The id of the operation that failed. */
|
|
52
|
+
readonly operationId: string;
|
|
53
|
+
/** The terminal status reported by the API (`failed` / `error` / `cancelled`). */
|
|
54
|
+
readonly status: string;
|
|
55
|
+
constructor(message: string, init: {
|
|
56
|
+
operationId: string;
|
|
57
|
+
status: string;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Waiting for operations to finish exceeded the configured timeout. */
|
|
61
|
+
declare class NeonTimeoutError extends NeonError {
|
|
62
|
+
constructor(message: string);
|
|
63
|
+
}
|
|
64
|
+
/** A transport-level failure (DNS, connection, abort) — no HTTP response received. */
|
|
65
|
+
declare class NeonNetworkError extends NeonError {
|
|
66
|
+
constructor(message: string, options?: {
|
|
67
|
+
cause?: unknown;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build the right {@link NeonError} subclass from a raw client result. `error` is the
|
|
72
|
+
* decoded error body (Neon `GeneralError`); `response` is present unless the failure was
|
|
73
|
+
* transport-level.
|
|
74
|
+
*/
|
|
75
|
+
declare function toNeonError(error: unknown, response: Response | undefined): NeonError;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { NeonApiError, NeonAuthError, NeonError, NeonErrorKind, NeonNetworkError, NeonNotFoundError, NeonOperationError, NeonRateLimitError, NeonTimeoutError, toNeonError };
|
|
78
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../src/neon/errors.ts"],"mappings":";;AAOA;AAWA;;;;AAA+B,KAXnB,aAAA,GAWmB,KAAA,GAAA,WAAA,GAAA,MAAA,GAAA,YAAA,GAAA,WAAA,GAAA,SAAA,GAAA,SAAA,GAAA,QAAA;AAAK;AAevB,cAfA,SAAA,SAAkB,KAAA,CAeL;EAAA,SAAA,IAAA,EAdV,aAcU;aAQL,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EAlBb,aAkBa,EAAA,QAAA,EAAA;IAOX,KAAA,CAAA,EAAA,OAAA;;;AAfiC;AAiC9B,cAjCA,YAAA,SAAqB,SAAA,CAiCH;EAAA;WAGM,MAAA,EAAA,MAAA;;WAHE,IAAA,CAAA,EAAA,MAAA;EAAY;EAUtC,SAAA,SAAc,CAAA,EAAA,MAAA;EAAA;WAGU,QAAA,CAAA,EAtChB,QAsCgB;;WAHF,IAAA,EAAA,OAAA;EAAY,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EAAA;IAUlC,IAAA,CAAA,EAtCH,aAsCsB;IAAA,MAAA,EAAA,MAAA;IAGK,IAAA,CAAA,EAAA,MAAA;IAA7B,SAAA,CAAA,EAAA,MAAA;IAHgC,QAAA,CAAA,EAlC1B,QAkC0B;IAAY,IAAA,CAAA,EAAA,OAAA;EAUvC,CAAA;AAiBb;AAOA;AA6BgB,cAnFH,iBAAA,SAA0B,YAAA,CAmFZ;EAAA,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,IAAA,EAhFnB,qBAgFmB,CAAA,OAhFU,YAgFV,CAAA,CAAA,CAAA,CAAA;;;AAGf,cA5EC,aAAA,SAAsB,YAAA,CA4EvB;qCAzEJ,6BAA6B;;;cAOxB,kBAAA,SAA2B,YAAA;qCAGhC,6BAA6B;;;cAOxB,kBAAA,SAA2B,SAAS;;;;;;;;;;;cAiBpC,gBAAA,SAAyB,SAAS;;;;cAOlC,gBAAA,SAAyB,SAAS;;;;;;;;;;iBA6B/B,WAAA,2BAEL,uBACR"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//#region src/neon/errors.ts
|
|
2
|
+
/** Base class for every error the ergonomic layer produces. */
|
|
3
|
+
var NeonError = class extends Error {
|
|
4
|
+
kind;
|
|
5
|
+
constructor(message, kind, options) {
|
|
6
|
+
super(message, options);
|
|
7
|
+
this.name = new.target.name;
|
|
8
|
+
this.kind = kind;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
/** A non-2xx HTTP response from the Neon API. */
|
|
12
|
+
var NeonApiError = class extends NeonError {
|
|
13
|
+
/** HTTP status code. */
|
|
14
|
+
status;
|
|
15
|
+
/** Machine-readable Neon error code (`GeneralError.code`), when present. */
|
|
16
|
+
code;
|
|
17
|
+
/** Neon request id (`X-Request-Id` / `GeneralError.request_id`), when present. */
|
|
18
|
+
requestId;
|
|
19
|
+
/** The raw response, when one was received. */
|
|
20
|
+
response;
|
|
21
|
+
/** The parsed error body, as returned by the API. */
|
|
22
|
+
body;
|
|
23
|
+
constructor(message, init) {
|
|
24
|
+
super(message, init.kind ?? "api");
|
|
25
|
+
this.status = init.status;
|
|
26
|
+
this.code = init.code;
|
|
27
|
+
this.requestId = init.requestId;
|
|
28
|
+
this.response = init.response;
|
|
29
|
+
this.body = init.body;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** 404 — the resource does not exist. */
|
|
33
|
+
var NeonNotFoundError = class extends NeonApiError {
|
|
34
|
+
constructor(message, init) {
|
|
35
|
+
super(message, {
|
|
36
|
+
...init,
|
|
37
|
+
kind: "not_found"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/** 401/403 — the API key is missing, invalid, or lacks permission. */
|
|
42
|
+
var NeonAuthError = class extends NeonApiError {
|
|
43
|
+
constructor(message, init) {
|
|
44
|
+
super(message, {
|
|
45
|
+
...init,
|
|
46
|
+
kind: "auth"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/** 429 — rate limited (after retries, if enabled, were exhausted). */
|
|
51
|
+
var NeonRateLimitError = class extends NeonApiError {
|
|
52
|
+
constructor(message, init) {
|
|
53
|
+
super(message, {
|
|
54
|
+
...init,
|
|
55
|
+
kind: "rate_limit"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/** An awaited Neon operation ended in a non-success terminal state. */
|
|
60
|
+
var NeonOperationError = class extends NeonError {
|
|
61
|
+
/** The id of the operation that failed. */
|
|
62
|
+
operationId;
|
|
63
|
+
/** The terminal status reported by the API (`failed` / `error` / `cancelled`). */
|
|
64
|
+
status;
|
|
65
|
+
constructor(message, init) {
|
|
66
|
+
super(message, "operation");
|
|
67
|
+
this.operationId = init.operationId;
|
|
68
|
+
this.status = init.status;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/** Waiting for operations to finish exceeded the configured timeout. */
|
|
72
|
+
var NeonTimeoutError = class extends NeonError {
|
|
73
|
+
constructor(message) {
|
|
74
|
+
super(message, "timeout");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/** A transport-level failure (DNS, connection, abort) — no HTTP response received. */
|
|
78
|
+
var NeonNetworkError = class extends NeonError {
|
|
79
|
+
constructor(message, options) {
|
|
80
|
+
super(message, "network", options);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function readApiErrorBody(body) {
|
|
84
|
+
if (typeof body !== "object" || body === null) return {};
|
|
85
|
+
const out = {};
|
|
86
|
+
if ("message" in body && typeof body.message === "string") out.message = body.message;
|
|
87
|
+
if ("code" in body && typeof body.code === "string") out.code = body.code;
|
|
88
|
+
if ("request_id" in body && typeof body.request_id === "string") out.request_id = body.request_id;
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Build the right {@link NeonError} subclass from a raw client result. `error` is the
|
|
93
|
+
* decoded error body (Neon `GeneralError`); `response` is present unless the failure was
|
|
94
|
+
* transport-level.
|
|
95
|
+
*/
|
|
96
|
+
function toNeonError(error, response) {
|
|
97
|
+
if (!response) return new NeonNetworkError("Network error: no response received from the Neon API.", { cause: error });
|
|
98
|
+
const parsed = readApiErrorBody(error);
|
|
99
|
+
const status = response.status;
|
|
100
|
+
const message = parsed.message ?? `Neon API request failed with status ${status}.`;
|
|
101
|
+
const init = {
|
|
102
|
+
status,
|
|
103
|
+
code: parsed.code,
|
|
104
|
+
requestId: parsed.request_id ?? response.headers.get("x-request-id") ?? void 0,
|
|
105
|
+
response,
|
|
106
|
+
body: error
|
|
107
|
+
};
|
|
108
|
+
if (status === 404) return new NeonNotFoundError(message, init);
|
|
109
|
+
if (status === 401 || status === 403) return new NeonAuthError(message, init);
|
|
110
|
+
if (status === 429) return new NeonRateLimitError(message, init);
|
|
111
|
+
return new NeonApiError(message, init);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { NeonApiError, NeonAuthError, NeonError, NeonNetworkError, NeonNotFoundError, NeonOperationError, NeonRateLimitError, NeonTimeoutError, toNeonError };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/neon/errors.ts"],"sourcesContent":["/**\n * Typed error hierarchy surfaced on the `error` channel of every ergonomic call (and\n * thrown when `throwOnError` is set). All are `Error` subclasses with a `kind`\n * discriminant, so the same value works whether you read it from `{ error }` or `catch`\n * it.\n */\n\nexport type NeonErrorKind =\n\t| \"api\"\n\t| \"not_found\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"operation\"\n\t| \"timeout\"\n\t| \"network\"\n\t| \"client\";\n\n/** Base class for every error the ergonomic layer produces. */\nexport class NeonError extends Error {\n\treadonly kind: NeonErrorKind;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tkind: NeonErrorKind,\n\t\toptions?: { cause?: unknown },\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = new.target.name;\n\t\tthis.kind = kind;\n\t}\n}\n\n/** A non-2xx HTTP response from the Neon API. */\nexport class NeonApiError extends NeonError {\n\t/** HTTP status code. */\n\treadonly status: number;\n\t/** Machine-readable Neon error code (`GeneralError.code`), when present. */\n\treadonly code?: string;\n\t/** Neon request id (`X-Request-Id` / `GeneralError.request_id`), when present. */\n\treadonly requestId?: string;\n\t/** The raw response, when one was received. */\n\treadonly response?: Response;\n\t/** The parsed error body, as returned by the API. */\n\treadonly body: unknown;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tinit: {\n\t\t\tkind?: NeonErrorKind;\n\t\t\tstatus: number;\n\t\t\tcode?: string;\n\t\t\trequestId?: string;\n\t\t\tresponse?: Response;\n\t\t\tbody?: unknown;\n\t\t},\n\t) {\n\t\tsuper(message, init.kind ?? \"api\");\n\t\tthis.status = init.status;\n\t\tthis.code = init.code;\n\t\tthis.requestId = init.requestId;\n\t\tthis.response = init.response;\n\t\tthis.body = init.body;\n\t}\n}\n\n/** 404 — the resource does not exist. */\nexport class NeonNotFoundError extends NeonApiError {\n\tconstructor(\n\t\tmessage: string,\n\t\tinit: ConstructorParameters<typeof NeonApiError>[1],\n\t) {\n\t\tsuper(message, { ...init, kind: \"not_found\" });\n\t}\n}\n\n/** 401/403 — the API key is missing, invalid, or lacks permission. */\nexport class NeonAuthError extends NeonApiError {\n\tconstructor(\n\t\tmessage: string,\n\t\tinit: ConstructorParameters<typeof NeonApiError>[1],\n\t) {\n\t\tsuper(message, { ...init, kind: \"auth\" });\n\t}\n}\n\n/** 429 — rate limited (after retries, if enabled, were exhausted). */\nexport class NeonRateLimitError extends NeonApiError {\n\tconstructor(\n\t\tmessage: string,\n\t\tinit: ConstructorParameters<typeof NeonApiError>[1],\n\t) {\n\t\tsuper(message, { ...init, kind: \"rate_limit\" });\n\t}\n}\n\n/** An awaited Neon operation ended in a non-success terminal state. */\nexport class NeonOperationError extends NeonError {\n\t/** The id of the operation that failed. */\n\treadonly operationId: string;\n\t/** The terminal status reported by the API (`failed` / `error` / `cancelled`). */\n\treadonly status: string;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tinit: { operationId: string; status: string },\n\t) {\n\t\tsuper(message, \"operation\");\n\t\tthis.operationId = init.operationId;\n\t\tthis.status = init.status;\n\t}\n}\n\n/** Waiting for operations to finish exceeded the configured timeout. */\nexport class NeonTimeoutError extends NeonError {\n\tconstructor(message: string) {\n\t\tsuper(message, \"timeout\");\n\t}\n}\n\n/** A transport-level failure (DNS, connection, abort) — no HTTP response received. */\nexport class NeonNetworkError extends NeonError {\n\tconstructor(message: string, options?: { cause?: unknown }) {\n\t\tsuper(message, \"network\", options);\n\t}\n}\n\ninterface ApiErrorBody {\n\tmessage?: string;\n\tcode?: string;\n\trequest_id?: string;\n}\n\nfunction readApiErrorBody(body: unknown): ApiErrorBody {\n\tif (typeof body !== \"object\" || body === null) return {};\n\tconst out: ApiErrorBody = {};\n\tif (\"message\" in body && typeof body.message === \"string\")\n\t\tout.message = body.message;\n\tif (\"code\" in body && typeof body.code === \"string\") out.code = body.code;\n\tif (\"request_id\" in body && typeof body.request_id === \"string\") {\n\t\tout.request_id = body.request_id;\n\t}\n\treturn out;\n}\n\n/**\n * Build the right {@link NeonError} subclass from a raw client result. `error` is the\n * decoded error body (Neon `GeneralError`); `response` is present unless the failure was\n * transport-level.\n */\nexport function toNeonError(\n\terror: unknown,\n\tresponse: Response | undefined,\n): NeonError {\n\tif (!response) {\n\t\treturn new NeonNetworkError(\n\t\t\t\"Network error: no response received from the Neon API.\",\n\t\t\t{ cause: error },\n\t\t);\n\t}\n\n\tconst parsed = readApiErrorBody(error);\n\tconst status = response.status;\n\tconst message =\n\t\tparsed.message ?? `Neon API request failed with status ${status}.`;\n\tconst init = {\n\t\tstatus,\n\t\tcode: parsed.code,\n\t\trequestId:\n\t\t\tparsed.request_id ??\n\t\t\tresponse.headers.get(\"x-request-id\") ??\n\t\t\tundefined,\n\t\tresponse,\n\t\tbody: error,\n\t};\n\n\tif (status === 404) return new NeonNotFoundError(message, init);\n\tif (status === 401 || status === 403)\n\t\treturn new NeonAuthError(message, init);\n\tif (status === 429) return new NeonRateLimitError(message, init);\n\treturn new NeonApiError(message, init);\n}\n"],"mappings":";;AAkBA,IAAa,YAAb,cAA+B,MAAM;CACpC;CAEA,YACC,SACA,MACA,SACC;EACD,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO,IAAI,OAAO;EACvB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,eAAb,cAAkC,UAAU;;CAE3C;;CAEA;;CAEA;;CAEA;;CAEA;CAEA,YACC,SACA,MAQC;EACD,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,KAAK,SAAS,KAAK;EACnB,KAAK,OAAO,KAAK;EACjB,KAAK,YAAY,KAAK;EACtB,KAAK,WAAW,KAAK;EACrB,KAAK,OAAO,KAAK;CAClB;AACD;;AAGA,IAAa,oBAAb,cAAuC,aAAa;CACnD,YACC,SACA,MACC;EACD,MAAM,SAAS;GAAE,GAAG;GAAM,MAAM;EAAY,CAAC;CAC9C;AACD;;AAGA,IAAa,gBAAb,cAAmC,aAAa;CAC/C,YACC,SACA,MACC;EACD,MAAM,SAAS;GAAE,GAAG;GAAM,MAAM;EAAO,CAAC;CACzC;AACD;;AAGA,IAAa,qBAAb,cAAwC,aAAa;CACpD,YACC,SACA,MACC;EACD,MAAM,SAAS;GAAE,GAAG;GAAM,MAAM;EAAa,CAAC;CAC/C;AACD;;AAGA,IAAa,qBAAb,cAAwC,UAAU;;CAEjD;;CAEA;CAEA,YACC,SACA,MACC;EACD,MAAM,SAAS,WAAW;EAC1B,KAAK,cAAc,KAAK;EACxB,KAAK,SAAS,KAAK;CACpB;AACD;;AAGA,IAAa,mBAAb,cAAsC,UAAU;CAC/C,YAAY,SAAiB;EAC5B,MAAM,SAAS,SAAS;CACzB;AACD;;AAGA,IAAa,mBAAb,cAAsC,UAAU;CAC/C,YAAY,SAAiB,SAA+B;EAC3D,MAAM,SAAS,WAAW,OAAO;CAClC;AACD;AAQA,SAAS,iBAAiB,MAA6B;CACtD,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO,CAAC;CACvD,MAAM,MAAoB,CAAC;CAC3B,IAAI,aAAa,QAAQ,OAAO,KAAK,YAAY,UAChD,IAAI,UAAU,KAAK;CACpB,IAAI,UAAU,QAAQ,OAAO,KAAK,SAAS,UAAU,IAAI,OAAO,KAAK;CACrE,IAAI,gBAAgB,QAAQ,OAAO,KAAK,eAAe,UACtD,IAAI,aAAa,KAAK;CAEvB,OAAO;AACR;;;;;;AAOA,SAAgB,YACf,OACA,UACY;CACZ,IAAI,CAAC,UACJ,OAAO,IAAI,iBACV,0DACA,EAAE,OAAO,MAAM,CAChB;CAGD,MAAM,SAAS,iBAAiB,KAAK;CACrC,MAAM,SAAS,SAAS;CACxB,MAAM,UACL,OAAO,WAAW,uCAAuC,OAAO;CACjE,MAAM,OAAO;EACZ;EACA,MAAM,OAAO;EACb,WACC,OAAO,cACP,SAAS,QAAQ,IAAI,cAAc,KACnC,KAAA;EACD;EACA,MAAM;CACP;CAEA,IAAI,WAAW,KAAK,OAAO,IAAI,kBAAkB,SAAS,IAAI;CAC9D,IAAI,WAAW,OAAO,WAAW,KAChC,OAAO,IAAI,cAAc,SAAS,IAAI;CACvC,IAAI,WAAW,KAAK,OAAO,IAAI,mBAAmB,SAAS,IAAI;CAC/D,OAAO,IAAI,aAAa,SAAS,IAAI;AACtC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NeonResult } from "./result.js";
|
|
2
|
+
|
|
3
|
+
//#region src/neon/paginate.d.ts
|
|
4
|
+
interface Page<T> {
|
|
5
|
+
items: T[];
|
|
6
|
+
/** Cursor for the next page, when more results exist. */
|
|
7
|
+
cursor?: string;
|
|
8
|
+
}
|
|
9
|
+
interface RawResult<D> {
|
|
10
|
+
data?: D | undefined;
|
|
11
|
+
error?: unknown;
|
|
12
|
+
response?: Response | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A lazy, cursor-paginated list. `all()` / `page()` return the `{ data, error }` envelope;
|
|
16
|
+
* the async iterator streams items lazily and throws on a page-fetch error.
|
|
17
|
+
*
|
|
18
|
+
* Note: pagination helpers always use the result envelope (the iterator is the throwing
|
|
19
|
+
* form) regardless of the client's `throwOnError` setting.
|
|
20
|
+
*/
|
|
21
|
+
interface Paginated<T> extends AsyncIterable<T> {
|
|
22
|
+
/** Fetch a single page (optionally from a cursor). */
|
|
23
|
+
page(cursor?: string): Promise<NeonResult<Page<T>>>;
|
|
24
|
+
/** Fetch and concatenate every page. */
|
|
25
|
+
all(): Promise<NeonResult<T[]>>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build a {@link Paginated} list from a page fetcher and a page mapper. The response-body
|
|
29
|
+
* type `D` is inferred and erased from the public `Paginated<T>` return.
|
|
30
|
+
*/
|
|
31
|
+
declare function paginate<T, D>(fetchPage: (cursor: string | undefined, signal?: AbortSignal) => Promise<RawResult<D>>, mapPage: (data: D) => Page<T>, signal?: AbortSignal): Paginated<T>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Page, Paginated, paginate };
|
|
34
|
+
//# sourceMappingURL=paginate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","names":[],"sources":["../../src/neon/paginate.ts"],"mappings":";;;UAGiB;SACT;EADS;EAMP,MAAA,CAAA,EAAA,MAAS;;UAAT,SACF,CAAA,CAAA,CAAA,CAAA;MAEI,CAAA,EAFJ,CAEI,GAAA,SAAA;EAAQ,KAAA,CAAA,EAAA,OAAA;EAUH,QAAA,CAAA,EAVL,QAUc,GAAA,SAAA;;;;;;;;;AAIlB,UAJS,SAIT,CAAA,CAAA,CAAA,SAJ8B,aAI9B,CAJ4C,CAI5C,CAAA,CAAA;;EAJ2C,IAAA,CAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAE3B,OAF2B,CAEnB,UAFmB,CAER,IAFQ,CAEH,CAFG,CAAA,CAAA,CAAA;EAiEnC;EAAQ,GAAA,EAAA,EA7DhB,OA6DgB,CA7DR,UA6DQ,CA7DG,CA6DH,EAAA,CAAA,CAAA;;;;;;AAKI,iBALZ,QAKY,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,SAAA,EAAA,CAAA,MAAA,EAAA,MAAA,GAAA,SAAA,EAAA,MAAA,CAAA,EAFjB,WAEiB,EAAA,GADtB,OACsB,CADd,SACc,CADJ,CACI,CAAA,CAAA,EAAA,OAAA,EAAA,CAAA,IAAA,EAAX,CAAW,EAAA,GAAL,IAAK,CAAA,CAAA,CAAA,EAAA,MAAA,CAAA,EAClB,WADkB,CAAA,EAEzB,SAFyB,CAEf,CAFe,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { toNeonError } from "./errors.js";
|
|
2
|
+
import { err, ok } from "./result.js";
|
|
3
|
+
//#region src/neon/paginate.ts
|
|
4
|
+
var PaginatedList = class {
|
|
5
|
+
#fetchPage;
|
|
6
|
+
#mapPage;
|
|
7
|
+
#signal;
|
|
8
|
+
constructor(fetchPage, mapPage, signal) {
|
|
9
|
+
this.#fetchPage = fetchPage;
|
|
10
|
+
this.#mapPage = mapPage;
|
|
11
|
+
this.#signal = signal;
|
|
12
|
+
}
|
|
13
|
+
async page(cursor) {
|
|
14
|
+
const raw = await this.#fetchPage(cursor, this.#signal);
|
|
15
|
+
if (raw.error || raw.data === void 0) return err(toNeonError(raw.error, raw.response));
|
|
16
|
+
return ok(this.#mapPage(raw.data));
|
|
17
|
+
}
|
|
18
|
+
async all() {
|
|
19
|
+
const items = [];
|
|
20
|
+
let cursor;
|
|
21
|
+
while (true) {
|
|
22
|
+
const result = await this.page(cursor);
|
|
23
|
+
if (result.error) return err(result.error);
|
|
24
|
+
items.push(...result.data.items);
|
|
25
|
+
if (!result.data.cursor || result.data.items.length === 0) break;
|
|
26
|
+
cursor = result.data.cursor;
|
|
27
|
+
}
|
|
28
|
+
return ok(items);
|
|
29
|
+
}
|
|
30
|
+
async *[Symbol.asyncIterator]() {
|
|
31
|
+
let cursor;
|
|
32
|
+
while (true) {
|
|
33
|
+
const result = await this.page(cursor);
|
|
34
|
+
if (result.error) throw result.error;
|
|
35
|
+
yield* result.data.items;
|
|
36
|
+
if (!result.data.cursor || result.data.items.length === 0) break;
|
|
37
|
+
cursor = result.data.cursor;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Build a {@link Paginated} list from a page fetcher and a page mapper. The response-body
|
|
43
|
+
* type `D` is inferred and erased from the public `Paginated<T>` return.
|
|
44
|
+
*/
|
|
45
|
+
function paginate(fetchPage, mapPage, signal) {
|
|
46
|
+
return new PaginatedList(fetchPage, mapPage, signal);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { paginate };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=paginate.js.map
|