@harlan-zw/nuxt-cloudflare 0.4.0 → 0.4.1

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.
@@ -0,0 +1,10 @@
1
+ import { Check } from '@harlan-zw/nuxt-checkin/server';
2
+
3
+ interface D1CheckOptions {
4
+ id: string;
5
+ binding: string;
6
+ }
7
+ declare function defineD1Check(options: D1CheckOptions): Check;
8
+
9
+ export { defineD1Check as default, defineD1Check };
10
+ export type { D1CheckOptions };
@@ -0,0 +1,26 @@
1
+ import { defineCheck, unavailable, pass } from '@harlan-zw/nuxt-checkin/server';
2
+ import { resolveCloudflareBindings } from './bindings.mjs';
3
+
4
+ function defineD1Check(options) {
5
+ if (!options.binding?.trim())
6
+ throw new TypeError("D1 check requires a binding name.");
7
+ return defineCheck({
8
+ id: options.id,
9
+ async run({ event, collect }) {
10
+ const env = event ? resolveCloudflareBindings(event) : void 0;
11
+ const db = env?.[options.binding];
12
+ if (typeof db?.prepare !== "function")
13
+ return unavailable("D1 binding is unavailable.");
14
+ const prepare = db.prepare.bind(db);
15
+ const row = await collect(db, "cloudflare.d1-read", async () => ({
16
+ value: await prepare("SELECT 1 AS checkin_ready").first(),
17
+ metrics: { requests: 1 }
18
+ }));
19
+ if (!row || typeof row !== "object" || !("checkin_ready" in row) || row.checkin_ready !== 1)
20
+ return unavailable("D1 read returned an invalid result.");
21
+ return pass({ binding: options.binding, readable: true });
22
+ }
23
+ });
24
+ }
25
+
26
+ export { defineD1Check as default, defineD1Check };
package/dist/module.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { WranglerDiagnosticCode, WorkersCachePolicy, WranglerConfigInput } from './wrangler.mjs';
2
2
  import { Nuxt } from '@nuxt/schema';
3
+ import { D1CheckOptions } from './checks.mjs';
4
+ import '@harlan-zw/nuxt-checkin/server';
3
5
 
4
6
  type WranglerDiagnosticPolicy = {
5
7
  _tag: 'advisory';
@@ -9,6 +11,8 @@ type WranglerDiagnosticPolicy = {
9
11
  };
10
12
 
11
13
  interface ModuleOptions {
14
+ /** Register checks through the public check-in API. */
15
+ checks?: D1CheckOptions[];
12
16
  bindingTypes?: boolean | {
13
17
  /** Shared cache directory. Set false to generate binding types every time. */
14
18
  cacheDir?: false | string;
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.5.0 <6.0.0"
6
6
  },
7
- "version": "0.4.0",
7
+ "version": "0.4.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import process from 'node:process';
2
- import { useLogger, defineNuxtModule, hasNuxtModule, addTypeTemplate } from '@nuxt/kit';
2
+ import { useLogger, defineNuxtModule, createResolver, hasNuxtModule, addTypeTemplate } from '@nuxt/kit';
3
3
  import { resolve } from 'pathe';
4
4
  import { a as diagnoseWranglerSourceConfigs, d as discoverWranglerSourceConfigs, b as diagnoseStaticAssetRules, c as readStaticAssetRuleFiles, f as resolveBuildStaticAssetDirectory, e as evaluateWranglerDiagnostics } from './shared/nuxt-cloudflare.Drgx8RDh.mjs';
5
5
  import { resolveHtmlCacheGuarantee, staleDirectivesAreDisabled } from '../dist/runtime/server/utils/workers-cache.js';
@@ -250,6 +250,13 @@ ${formatWranglerDiagnostics(outcome.blockingDiagnostics)}`);
250
250
  function setupCloudflareModule(options, nuxt) {
251
251
  if (!options.enabled)
252
252
  return;
253
+ if (options.checks?.length) {
254
+ const checkResolver = createResolver(import.meta.url);
255
+ nuxt.hook("checkin:register", (registry) => {
256
+ for (const check of options.checks ?? [])
257
+ registry.add({ id: check.id, handler: checkResolver.resolve("./checks"), options: { ...check } });
258
+ });
259
+ }
253
260
  const configure = () => configureNitroCloudflare(
254
261
  nuxt.options.nitro,
255
262
  options,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@harlan-zw/nuxt-cloudflare",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -51,6 +51,10 @@
51
51
  "./cache": {
52
52
  "types": "./dist/cache.d.mts",
53
53
  "import": "./dist/cache.mjs"
54
+ },
55
+ "./checks": {
56
+ "types": "./dist/checks.d.mts",
57
+ "import": "./dist/checks.mjs"
54
58
  }
55
59
  },
56
60
  "main": "./dist/module.mjs",
@@ -74,6 +78,9 @@
74
78
  ],
75
79
  "wrangler": [
76
80
  "dist/wrangler.d.mts"
81
+ ],
82
+ "checks": [
83
+ "dist/checks.d.mts"
77
84
  ]
78
85
  }
79
86
  },
@@ -87,9 +94,15 @@
87
94
  "node": ">=22.12.0"
88
95
  },
89
96
  "peerDependencies": {
97
+ "@harlan-zw/nuxt-checkin": "^0.1.0",
90
98
  "nuxt": ">=4.5.0 <6.0.0",
91
99
  "wrangler": ">=4.120.0 <5.0.0"
92
100
  },
101
+ "peerDependenciesMeta": {
102
+ "@harlan-zw/nuxt-checkin": {
103
+ "optional": true
104
+ }
105
+ },
93
106
  "dependencies": {
94
107
  "@nuxt/kit": "^4.5.2",
95
108
  "citty": "^0.2.2",
@@ -113,6 +126,7 @@
113
126
  "unbuild": "^3.6.1",
114
127
  "vitest": "^4.1.10",
115
128
  "wrangler": "^4.120.1",
129
+ "@harlan-zw/nuxt-checkin": "0.1.0",
116
130
  "@harlan-zw/nuxt-wide-events": "^0.1.4"
117
131
  },
118
132
  "scripts": {