diff options
| author | Frank <[email protected]> | 2025-11-23 15:21:47 -0500 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-11-23 15:21:47 -0500 |
| commit | bbc9142fc54fef532039f2a91c63ac2f2873af41 (patch) | |
| tree | 67b6d266cdab71cc094c92a6474fc4f44dd4ad7e /packages/console/resource/resource.node.ts | |
| parent | 7413c2715c208a92d1ca3c4f31988a4449b877a0 (diff) | |
| download | opencode-bbc9142fc54fef532039f2a91c63ac2f2873af41.tar.gz opencode-bbc9142fc54fef532039f2a91c63ac2f2873af41.zip | |
wip: zen
Diffstat (limited to 'packages/console/resource/resource.node.ts')
| -rw-r--r-- | packages/console/resource/resource.node.ts | 90 |
1 files changed, 51 insertions, 39 deletions
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<void>) => { + 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<KVNamespaceListResult<unknown, string>> => - 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<KVNamespaceListResult<unknown, string>> => + 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 |
