From 9bcfb441ff533d44e76b486883282a30931d3a23 Mon Sep 17 00:00:00 2001 From: Jason Caldwell Date: Tue, 5 Mar 2024 14:10:04 -0500 Subject: [PATCH] Project update. [p][robotic] --- .browserslistrc | 2 +- .dockerignore | 2 +- .env.vault | 8 ++++---- .gitattributes | 2 +- .gitignore | 2 +- .npmignore | 2 +- .prettierignore | 2 +- .vscode/settings.json | 2 +- .vscodeignore | 2 +- package-lock.json | 18 +++++++++--------- package.json | 2 +- src/cfw.ts | 2 +- src/root.ts | 19 +++++++++++++++++++ tsconfig.json | 2 +- wrangler.toml | 2 +- 15 files changed, 44 insertions(+), 25 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 291b6b3..f597acb 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -17,7 +17,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. [production] node >= 20.9.0 diff --git a/.dockerignore b/.dockerignore index eb22db8..50267c5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,7 +17,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. # Locals diff --git a/.env.vault b/.env.vault index c94c226..b62e472 100644 --- a/.env.vault +++ b/.env.vault @@ -8,12 +8,12 @@ DOTENV_VAULT_MAIN="3rfi+ClkONvfHPiU9FTBcC1+Um/L8QeM9dRw1jFzEqzZXw==" DOTENV_VAULT_MAIN_VERSION=1 # dev -DOTENV_VAULT_DEV="a3bVmJ+WUFOs+Dy+D7eelQDQ9VtkM/idZ2GhuKuaSF+hzZf3LBRzr1LepbP95LkIpPrGa4FGcTV+o8ExXk1ksymZVPbY83ceAodas0Stsh5ADg22AMcj/YF+tC0Jlns6ahiLUMf3badW5jwR0nqPcYWI4/FwI67XcwLROHwP1dKviPpSigEYBkN4AiAi6dFai2t1y9bgddfxmwz2tDQ8IdzuBWvZutIqRMIDDtw97H3T9WhAp+Y6zoeRhq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nkplA/hME/0/JO7yrJB6dtJX78U8K/rhs7JKOEN3p6zP3vl5Vw3m3Q4AuxJ6FA+pBJfdZX0c40sO7ZUFpmLj/Z0niSFcvZ+doukVt5cg9NRljehLZ374XhMXO5kt5s3uwymuzo5nsLqZRiSsrHWfkCaCDPSYLHiqjmWn9S143e4yahfmZafex4NA/IDVKy2rFRqM" +DOTENV_VAULT_CI_VERSION=237 # stage DOTENV_VAULT_STAGE="bfqZYD8oVLWMZ0JR5LICV+sB/btaXavszxZLxTfwSH8U5fg=" diff --git a/.gitattributes b/.gitattributes index 1a1f2aa..aae5fe4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,7 +17,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. # Default diff --git a/.gitignore b/.gitignore index ac75b0f..dff38e8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. # Locals diff --git a/.npmignore b/.npmignore index ff66777..87cc05a 100644 --- a/.npmignore +++ b/.npmignore @@ -25,7 +25,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. # Locals diff --git a/.prettierignore b/.prettierignore index 1183bb4..f5613da 100644 --- a/.prettierignore +++ b/.prettierignore @@ -17,7 +17,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. # Packages diff --git a/.vscode/settings.json b/.vscode/settings.json index 5d7e531..ff58d5d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ * @note This entire file will be updated automatically. * @note Instead of editing here, please review `./settings.mjs`. * - * Last generated using `./settings.mjs` Mar 5, 2024 6:33 PM UTC. + * Last generated using `./settings.mjs` Mar 5, 2024 7:09 PM UTC. */ { "editor.formatOnType": false, diff --git a/.vscodeignore b/.vscodeignore index 5540f6e..3686a7e 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -17,7 +17,7 @@ # Generated data. # -# Last generated Mar 5, 2024 6:33 PM UTC. +# Last generated Mar 5, 2024 7:09 PM UTC. # Locals diff --git a/package-lock.json b/package-lock.json index c9d4964..592ac36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@clevercanyon/utilities.cfw", - "version": "1.0.270", + "version": "1.0.271", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@clevercanyon/utilities.cfw", - "version": "1.0.270", + "version": "1.0.271", "cpu": [ "x64", "arm64" @@ -1103,9 +1103,9 @@ } }, "node_modules/@clevercanyon/utilities.cfw": { - "version": "1.0.270", - "resolved": "https://registry.npmjs.org/@clevercanyon/utilities.cfw/-/utilities.cfw-1.0.270.tgz", - "integrity": "sha512-d/XkLia3P+aR5YBiyko4mhrlrbg0EY08fua9XAsTCOMgg4oenwGzUR0fuwGXBMDfXFF9iKGZ6cOP6Dji8fDVKg==", + "version": "1.0.271", + "resolved": "https://registry.npmjs.org/@clevercanyon/utilities.cfw/-/utilities.cfw-1.0.271.tgz", + "integrity": "sha512-TPYg1eBTSZ1PU4cI0dbK/gr+1hywczNyyL2e4fnx+LHdJb9BVxIaSZxmyPtbH8SMaFLj81Etr/jT8ACDK8IccQ==", "cpu": [ "x64", "arm64" @@ -1124,7 +1124,7 @@ "url": "https://github.com/sponsors/clevercanyon" }, "peerDependencies": { - "@clevercanyon/utilities": "^1.0.882", + "@clevercanyon/utilities": "^1.0.884", "@cloudflare/ai": "1.0.53", "@upstash/ratelimit": "1.0.0", "@upstash/redis": "1.28.0" @@ -9518,9 +9518,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.692", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.692.tgz", - "integrity": "sha512-d5rZRka9n2Y3MkWRN74IoAsxR0HK3yaAt7T50e3iT9VZmCCQDT3geXUO5ZRMhDToa1pkCeQXuNo+0g+NfDOVPA==", + "version": "1.4.693", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.693.tgz", + "integrity": "sha512-/if4Ueg0GUQlhCrW2ZlXwDAm40ipuKo+OgeHInlL8sbjt+hzISxZK949fZeJaVsheamrzANXvw1zQTvbxTvSHw==", "dev": true }, "node_modules/emittery": { diff --git a/package.json b/package.json index 68fcccb..e8dae04 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publishConfig": { "access": "public" }, - "version": "1.0.271", + "version": "1.0.272", "license": "GPL-3.0-or-later", "name": "@clevercanyon/utilities.cfw", "description": "Utilities for JavaScript apps running in a Cloudflare Worker environment.", diff --git a/src/cfw.ts b/src/cfw.ts index 28bd0e2..c7ec920 100644 --- a/src/cfw.ts +++ b/src/cfw.ts @@ -50,6 +50,7 @@ export type StdExecutionContext = Readonly< >; export type StdEnvironment = Readonly<{ RT: $type.cfw.Fetcher; + RT_AI: $type.cfw.Fetcher; RT_D1: $type.cfw.D1Database; RT_R2: $type.cfw.R2Bucket; RT_KV: $type.cfw.KVNamespace; @@ -58,7 +59,6 @@ export type StdEnvironment = Readonly<{ D1: $type.cfw.D1Database; R2: $type.cfw.R2Bucket; KV: $type.cfw.KVNamespace; - DO: $type.cfw.DurableObjectNamespace; }>; export type StdRequestContextData = Readonly<{ ctx: StdExecutionContext; diff --git a/src/root.ts b/src/root.ts index de4a3a9..a7f6e15 100644 --- a/src/root.ts +++ b/src/root.ts @@ -36,6 +36,25 @@ fetch.isAvailable = (rcData: $cfw.StdRequestContextData): boolean => { return rcData.env.RT ? true : false; }; +/** + * Gets root AI binding. + * + * @param rcData Request context data; {@see $cfw.StdRequestContextData}. + * + * @returns Root AI binding. + */ +export const ai = (rcData: $cfw.StdRequestContextData): $type.cfw.Fetcher => { + const { env } = rcData, + ai = env.RT_AI || (rootPkgName === $app.pkgName() && env.AI); + + if (!ai) throw Error('Root AI binding unavailable.'); + + return ai; +}; +ai.isAvailable = (rcData: $cfw.StdRequestContextData): boolean => { + return rcData.env.RT_AI || (rootPkgName === $app.pkgName() && rcData.env.AI) ? true : false; +}; + /** * Gets root D1 binding. * diff --git a/tsconfig.json b/tsconfig.json index df429cf..1fd02a6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ * @note This entire file will be updated automatically. * @note Instead of editing here, please review `./tsconfig.mjs`. * - * Last generated using `./tsconfig.mjs` Mar 5, 2024 6:33 PM UTC. + * Last generated using `./tsconfig.mjs` Mar 5, 2024 7:09 PM UTC. */ { "include": ["./src/**/*", "./dev-types.d.ts"], diff --git a/wrangler.toml b/wrangler.toml index 2a3c68a..3cdd051 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -7,7 +7,7 @@ # @note This entire file will be updated automatically. # @note Instead of editing here, please review `./wrangler.mjs`. # -# Last generated using `./wrangler.mjs` Mar 5, 2024 6:33 PM UTC. +# Last generated using `./wrangler.mjs` Mar 5, 2024 7:09 PM UTC. ## send_metrics = false