MCPcopy
hub / github.com/anomalyco/opencode / get

Function get

packages/console/resource/resource.node.ts:12–69  ·  view source on GitHub ↗
(_target, prop: keyof typeof ResourceBase)

Source from the content-addressed store, hash-verified

10 {},
11 {
12 get(_target, prop: keyof typeof ResourceBase) {
13 const value = ResourceBase[prop]
14 const secrets = ResourceBase as unknown as Record<string, { value: string }>
15 if ("type" in value) {
16 // @ts-ignore
17 if (value.type === "sst.cloudflare.Bucket") {
18 return {
19 put: async () => {},
20 }
21 }
22 // @ts-ignore
23 if (value.type === "sst.cloudflare.Kv") {
24 const client = new Cloudflare({
25 apiToken: secrets.CLOUDFLARE_API_TOKEN.value,
26 })
27 // @ts-ignore
28 const namespaceId = value.namespaceId
29 const accountId = secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID.value
30 return {
31 get: (k: string | string[]) => {
32 const isMulti = Array.isArray(k)
33 return client.kv.namespaces
34 .bulkGet(namespaceId, {
35 keys: Array.isArray(k) ? k : [k],
36 account_id: accountId,
37 })
38 .then((result) => (isMulti ? new Map(Object.entries(result?.values ?? {})) : result?.values?.[k]))
39 },
40 put: (k: string, v: string, opts?: KVNamespacePutOptions) =>
41 client.kv.namespaces.values.update(namespaceId, k, {
42 account_id: accountId,
43 value: v,
44 expiration: opts?.expiration,
45 expiration_ttl: opts?.expirationTtl,
46 metadata: opts?.metadata,
47 }),
48 delete: (k: string) =>
49 client.kv.namespaces.values.delete(namespaceId, k, {
50 account_id: accountId,
51 }),
52 list: (opts?: KVNamespaceListOptions): Promise<KVNamespaceListResult<unknown, string>> =>
53 client.kv.namespaces.keys
54 .list(namespaceId, {
55 account_id: accountId,
56 prefix: opts?.prefix ?? undefined,
57 })
58 .then((result) => {
59 return {
60 keys: result.result,
61 list_complete: true,
62 cacheStatus: null,
63 }
64 }),
65 }
66 }
67 }
68 return value
69 },

Callers

nothing calls this directly

Calls 3

updateMethod · 0.65
listMethod · 0.65
deleteMethod · 0.45

Tested by

no test coverage detected