From bbc9142fc54fef532039f2a91c63ac2f2873af41 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 23 Nov 2025 15:21:47 -0500 Subject: wip: zen --- packages/console/resource/resource.node.ts | 90 +++++++++++++++++------------- 1 file changed, 51 insertions(+), 39 deletions(-) (limited to 'packages/console/resource/resource.node.ts') diff --git a/packages/console/resource/resource.node.ts b/packages/console/resource/resource.node.ts index f63d7bada..46b9629ed 100644 --- a/packages/console/resource/resource.node.ts +++ b/packages/console/resource/resource.node.ts @@ -2,54 +2,66 @@ import type { KVNamespaceListOptions, KVNamespaceListResult, KVNamespacePutOptio import { Resource as ResourceBase } from "sst" import Cloudflare from "cloudflare" +export const waitUntil = async (fn: () => Promise) => { + await fn() +} + export const Resource = new Proxy( {}, { get(_target, prop: keyof typeof ResourceBase) { const value = ResourceBase[prop] - // @ts-ignore - if ("type" in value && value.type === "sst.cloudflare.Kv") { - const client = new Cloudflare({ - apiToken: ResourceBase.CLOUDFLARE_API_TOKEN.value, - }) + if ("type" in value) { + // @ts-ignore + if (value.type === "sst.cloudflare.Bucket") { + return { + put: async () => {}, + } + } // @ts-ignore - const namespaceId = value.namespaceId - const accountId = ResourceBase.CLOUDFLARE_DEFAULT_ACCOUNT_ID.value - return { - get: (k: string | string[]) => { - const isMulti = Array.isArray(k) - return client.kv.namespaces - .bulkGet(namespaceId, { - keys: Array.isArray(k) ? k : [k], + if (value.type === "sst.cloudflare.Kv") { + const client = new Cloudflare({ + apiToken: ResourceBase.CLOUDFLARE_API_TOKEN.value, + }) + // @ts-ignore + const namespaceId = value.namespaceId + const accountId = ResourceBase.CLOUDFLARE_DEFAULT_ACCOUNT_ID.value + return { + get: (k: string | string[]) => { + const isMulti = Array.isArray(k) + return client.kv.namespaces + .bulkGet(namespaceId, { + keys: Array.isArray(k) ? k : [k], + account_id: accountId, + }) + .then((result) => (isMulti ? new Map(Object.entries(result?.values ?? {})) : result?.values?.[k])) + }, + put: (k: string, v: string, opts?: KVNamespacePutOptions) => + client.kv.namespaces.values.update(namespaceId, k, { account_id: accountId, - }) - .then((result) => (isMulti ? new Map(Object.entries(result?.values ?? {})) : result?.values?.[k])) - }, - put: (k: string, v: string, opts?: KVNamespacePutOptions) => - client.kv.namespaces.values.update(namespaceId, k, { - account_id: accountId, - value: v, - expiration: opts?.expiration, - expiration_ttl: opts?.expirationTtl, - metadata: opts?.metadata, - }), - delete: (k: string) => - client.kv.namespaces.values.delete(namespaceId, k, { - account_id: accountId, - }), - list: (opts?: KVNamespaceListOptions): Promise> => - client.kv.namespaces.keys - .list(namespaceId, { + value: v, + expiration: opts?.expiration, + expiration_ttl: opts?.expirationTtl, + metadata: opts?.metadata, + }), + delete: (k: string) => + client.kv.namespaces.values.delete(namespaceId, k, { account_id: accountId, - prefix: opts?.prefix ?? undefined, - }) - .then((result) => { - return { - keys: result.result, - list_complete: true, - cacheStatus: null, - } }), + list: (opts?: KVNamespaceListOptions): Promise> => + client.kv.namespaces.keys + .list(namespaceId, { + account_id: accountId, + prefix: opts?.prefix ?? undefined, + }) + .then((result) => { + return { + keys: result.result, + list_complete: true, + cacheStatus: null, + } + }), + } } } return value -- cgit v1.2.3