utils.ts
This file
Path
src/adapter/cloudflare-workers/utils.ts
56 lines · 1.6 KiB · TypeScript
Last changed by
feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–4why, one step back1// __STATIC_CONTENT is KVNamespace2declare const __STATIC_CONTENT: unknown3declare const __STATIC_CONTENT_MANIFEST: string4feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827
lines 5–7why, one step back5/**6 * @deprecated `hono/cloudflare-workers` will be removed in v5. Install `@hono/cloudflare-workers` and import from there instead.7 */Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 8–13why, one step back8export type KVAssetOptions = {9 manifest?: object | string10 // namespace is KVNamespace11 namespace?: unknown12}13feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827
lines 14–16why, one step back14/**15 * @deprecated `hono/cloudflare-workers` will be removed in v5. Install `@hono/cloudflare-workers` and import from there instead.16 */Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 17–56why, one step back17export const getContentFromKVAsset = async (18 path: string,19 options?: KVAssetOptions20): Promise<ReadableStream | null> => {21 let ASSET_MANIFEST: Record<string, string>2223 if (options && options.manifest) {24 if (typeof options.manifest === 'string') {25 ASSET_MANIFEST = JSON.parse(options.manifest)26 } else {27 ASSET_MANIFEST = options.manifest as Record<string, string>28 }29 } else {30 if (typeof __STATIC_CONTENT_MANIFEST === 'string') {31 ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST)32 } else {33 ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST34 }35 }3637 // ASSET_NAMESPACE is KVNamespace38 let ASSET_NAMESPACE: unknown39 if (options && options.namespace) {40 ASSET_NAMESPACE = options.namespace41 } else {42 ASSET_NAMESPACE = __STATIC_CONTENT43 }4445 const key = ASSET_MANIFEST[path]46 if (!key) {47 return null48 }4950 // @ts-expect-error ASSET_NAMESPACE is not typed51 const content = await ASSET_NAMESPACE.get(key, { type: 'stream' })52 if (!content) {53 return null54 }55 return content as unknown as ReadableStream56}