@harlan-zw/nuxt-cloudflare 0.0.15 → 0.0.16
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/d1.d.mts +39 -2
- package/dist/d1.mjs +5 -1
- package/dist/module.json +1 -1
- package/package.json +1 -1
package/dist/d1.d.mts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request-scoped D1 counters.
|
|
3
|
+
*
|
|
4
|
+
* D1 answers every remote query with a `meta` block naming the node that served
|
|
5
|
+
* it — `served_by_primary`, `served_by_region` — and the session layer here
|
|
6
|
+
* already knows when it had to recover from a reset. Neither fact survives the
|
|
7
|
+
* request unless something records it, and both are exactly what you want when
|
|
8
|
+
* a request is slow or an isolate dies: how many queries did this request make,
|
|
9
|
+
* how many of them crossed to the primary, and did the session have to restart.
|
|
10
|
+
*
|
|
11
|
+
* Kept separate from the session machinery so it stays optional. A caller that
|
|
12
|
+
* wants no telemetry passes no stats object and pays nothing.
|
|
13
|
+
*/
|
|
14
|
+
declare const REQUEST_D1_STATS: unique symbol;
|
|
1
15
|
interface D1RequestStats {
|
|
2
16
|
/** Terminal statement executions and batches. */
|
|
3
17
|
queries: number;
|
|
@@ -12,6 +26,29 @@ interface D1RequestStats {
|
|
|
12
26
|
/** Total SQL execution time D1 reported, in milliseconds. */
|
|
13
27
|
durationMs: number;
|
|
14
28
|
}
|
|
29
|
+
declare function createD1Stats(): D1RequestStats;
|
|
30
|
+
/**
|
|
31
|
+
* The stats object for this request, created on first use.
|
|
32
|
+
*
|
|
33
|
+
* Takes the request context rather than an `H3Event` so the same helper works
|
|
34
|
+
* in a queue consumer or a scheduled task, which have no event but do have a
|
|
35
|
+
* per-invocation object to hang state on.
|
|
36
|
+
*/
|
|
37
|
+
declare function useD1Stats(requestContext: Record<PropertyKey, unknown>): D1RequestStats;
|
|
38
|
+
/** The stats recorded so far, or `null` when this request never touched D1. */
|
|
39
|
+
declare function readD1Stats(requestContext: Record<PropertyKey, unknown> | undefined): D1RequestStats | null;
|
|
40
|
+
/**
|
|
41
|
+
* Fold one D1 result's `meta` into the request's counters.
|
|
42
|
+
*
|
|
43
|
+
* Every field is checked before use: `meta` is absent under `wrangler dev` and
|
|
44
|
+
* on a local D1, where these keys do not exist at all, and a telemetry helper
|
|
45
|
+
* that throws in development would be worse than one that records nothing.
|
|
46
|
+
*/
|
|
47
|
+
declare function recordD1Meta(stats: D1RequestStats, result: unknown): void;
|
|
48
|
+
/** Fold a recovery event into the request's counters. */
|
|
49
|
+
declare function recordD1Recovery(stats: D1RequestStats, event: {
|
|
50
|
+
_tag: 'retrying' | 'stopped';
|
|
51
|
+
}): void;
|
|
15
52
|
|
|
16
53
|
type D1WriteSafety = {
|
|
17
54
|
_tag: 'lock-only';
|
|
@@ -112,5 +149,5 @@ declare function getRequestD1Session<Session>(requestContext: Record<PropertyKey
|
|
|
112
149
|
declare function getRecoveringRequestD1Session<Session extends D1SessionLike>(requestContext: Record<PropertyKey, unknown>, binding: string, database: D1SessionSource<Session>, options?: D1ResetRecoveryOptions): Session;
|
|
113
150
|
declare function retryIdempotentD1Write<T>(options: RetryIdempotentD1WriteOptions<T>): Promise<T>;
|
|
114
151
|
|
|
115
|
-
export { D1_MAX_BOUND_PARAMETERS, assertD1BoundParameters, chunkD1Items, classifyD1RetryError, defineD1ParameterPlan, getRecoveringRequestD1Session, getRequestD1Session, isReplayableD1Sql, isTransientD1Error, retryIdempotentD1Write, withD1ResetRecovery };
|
|
116
|
-
export type { D1Consistency, D1ParameterPlan, D1ParameterPlanInput, D1RecoveryEvent, D1ResetRecoveryOptions, D1RetryErrorKind, D1SessionLike, D1SessionSource, D1StatementLike, D1WriteSafety, RetryIdempotentD1WriteOptions };
|
|
152
|
+
export { D1_MAX_BOUND_PARAMETERS, REQUEST_D1_STATS, assertD1BoundParameters, chunkD1Items, classifyD1RetryError, createD1Stats, defineD1ParameterPlan, getRecoveringRequestD1Session, getRequestD1Session, isReplayableD1Sql, isTransientD1Error, readD1Stats, recordD1Meta, recordD1Recovery, retryIdempotentD1Write, useD1Stats, withD1ResetRecovery };
|
|
153
|
+
export type { D1Consistency, D1ParameterPlan, D1ParameterPlanInput, D1RecoveryEvent, D1RequestStats, D1ResetRecoveryOptions, D1RetryErrorKind, D1SessionLike, D1SessionSource, D1StatementLike, D1WriteSafety, RetryIdempotentD1WriteOptions };
|
package/dist/d1.mjs
CHANGED
|
@@ -10,6 +10,10 @@ function useD1Stats(requestContext) {
|
|
|
10
10
|
requestContext[REQUEST_D1_STATS] = stats;
|
|
11
11
|
return stats;
|
|
12
12
|
}
|
|
13
|
+
function readD1Stats(requestContext) {
|
|
14
|
+
const stats = requestContext?.[REQUEST_D1_STATS];
|
|
15
|
+
return stats && typeof stats === "object" ? stats : null;
|
|
16
|
+
}
|
|
13
17
|
function recordD1Meta(stats, result) {
|
|
14
18
|
stats.queries++;
|
|
15
19
|
const meta = result?.meta;
|
|
@@ -412,4 +416,4 @@ async function retryIdempotentD1Write(options) {
|
|
|
412
416
|
throw lastError;
|
|
413
417
|
}
|
|
414
418
|
|
|
415
|
-
export { D1_MAX_BOUND_PARAMETERS, assertD1BoundParameters, chunkD1Items, classifyD1RetryError, defineD1ParameterPlan, getRecoveringRequestD1Session, getRequestD1Session, isReplayableD1Sql, isTransientD1Error, retryIdempotentD1Write, withD1ResetRecovery };
|
|
419
|
+
export { D1_MAX_BOUND_PARAMETERS, REQUEST_D1_STATS, assertD1BoundParameters, chunkD1Items, classifyD1RetryError, createD1Stats, defineD1ParameterPlan, getRecoveringRequestD1Session, getRequestD1Session, isReplayableD1Sql, isTransientD1Error, readD1Stats, recordD1Meta, recordD1Recovery, retryIdempotentD1Write, useD1Stats, withD1ResetRecovery };
|
package/dist/module.json
CHANGED
package/package.json
CHANGED