@lunora/server 1.0.0-alpha.195 → 1.0.0-alpha.197
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/in-process.mjs +1 -1
- package/dist/index.d.mts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/beginDeferredSchedules-n_pHHjPE.mjs +1 -0
- package/dist/packem_shared/serveStorageObject-DNN3r8x3.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/beginDeferredSchedules-CmmdpWRS.mjs +0 -1
- package/dist/packem_shared/serveStorageObject-SPHQyLa4.mjs +0 -1
package/dist/in-process.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as I}from"@lunora/errors";import{runShardMigrations as R,TransactionHeadroomTracker as h,createShardCtxDb as T,RLS_UNWRAP_SYMBOL as g}from"@lunora/shard-engine";import{beginDeferredSchedules as p}from"./packem_shared/beginDeferredSchedules-
|
|
1
|
+
import{LunoraError as I}from"@lunora/errors";import{runShardMigrations as R,TransactionHeadroomTracker as h,createShardCtxDb as T,RLS_UNWRAP_SYMBOL as g}from"@lunora/shard-engine";import{beginDeferredSchedules as p}from"./packem_shared/beginDeferredSchedules-n_pHHjPE.mjs";import{bindTableFacade as y}from"./packem_shared/bindOrm-BHq_oUP2.mjs";const k=e=>{if(e===null||typeof e.userId!="string"||e.userId.length===0)return{claims:null,userId:null};const{userId:r,...s}=e;return{claims:Object.keys(s).length>0?s:null,userId:r}};class S extends h{current=new h;reset(){this.current=new h}headroom(){return this.current.headroom()}recordRead(r){this.current.recordRead(r)}recordWrite(r){this.current.recordWrite(r)}}const x=(e,r)=>{const{scheduler:s,sql:a}=r,i=e;R(a,i);const c=new S,m=t=>{const n=t;for(const o of Object.keys(i.tables))n[o]=y(t,o);return t};let u=!1;const w=t=>{const n=T({auth:{identity:t.claims,userId:t.userId},enforceRls:r.enforceRls??!0,headroom:c,inTransaction:()=>u,schema:i,sql:a}),o=n[g]??n;return{database:m(n),rawDatabase:m(o)}},l=t=>{a.exec.call(a,t)};let f=Promise.resolve();return{createWriters:w,resetHeadroom:()=>{c.reset()},runInTransaction:t=>{const n=async()=>{const b=p({scheduler:s});c.reset(),l("BEGIN"),u=!0;try{const d=await t();return l("COMMIT"),u=!1,await b(!0),d}catch(d){u=!1;try{l("ROLLBACK")}catch{}throw await b(!1),d}},o=f.then(n);return f=o.then(()=>{},()=>{}),o}}},v=e=>{if(typeof e!="object"||e===null)return;const{kind:r}=e;if(r==="query"||r==="mutation"||r==="action")return r},A=(e,r,s,a,i)=>{const c=v(r);if(c!==e)throw new I("INTERNAL",`expected a registered ${e}, received a ${c??"non-function"} reference`);if(!i&&r.visibility==="internal")throw new I("INTERNAL",`This ${e} is an internal function — it is unreachable from the external RPC boundary in production. Call it through ctx.run${e.charAt(0).toUpperCase()}${e.slice(1)} from another function instead.`);return Promise.resolve(r.handler(s,a??{}))};export{x as createInProcessRuntime,v as registeredFunctionKind,k as resolveInProcessIdentity,A as runRegisteredFunction};
|
package/dist/index.d.mts
CHANGED
|
@@ -1333,6 +1333,12 @@ declare const flushDeferredDeletes: (context: unknown) => Promise<DeferredDelete
|
|
|
1333
1333
|
* store) keeps the previous best-effort behaviour rather than failing to build.
|
|
1334
1334
|
*/
|
|
1335
1335
|
interface ScheduleOutbox {
|
|
1336
|
+
/**
|
|
1337
|
+
* The schedule-rate budget for `target`, asked once per target per dispatch. Returns the
|
|
1338
|
+
* instant a schedule to `target` may not fire before, or `undefined` when within budget.
|
|
1339
|
+
* Never throws: a deferral only ever moves a job later.
|
|
1340
|
+
*/
|
|
1341
|
+
admit: (target: string) => number | undefined;
|
|
1336
1342
|
/** Release custody — the scheduler has the job, or the window that owned it was dropped. */
|
|
1337
1343
|
forget: (id: string) => void;
|
|
1338
1344
|
/**
|
|
@@ -2170,8 +2176,15 @@ type StorageServeAuthorizer = (context: StorageServeAuthzContext) => boolean | P
|
|
|
2170
2176
|
* derived from `authorize` because a stub returning `true` during development
|
|
2171
2177
|
* would then silently publish a cache. An app fronting a genuinely public
|
|
2172
2178
|
* bucket passes its own value; `content-disposition` and `nosniff` stay
|
|
2173
|
-
* unconditional either way.
|
|
2174
|
-
*
|
|
2179
|
+
* unconditional either way.
|
|
2180
|
+
*
|
|
2181
|
+
* A request whose `If-None-Match` names the current `etag` (or `*`, or any
|
|
2182
|
+
* weak form of it in a list) is answered `304 Not Modified` with no body, after
|
|
2183
|
+
* `authorize` has run and a body-free `head()`. A 304 costs one R2 HEAD and no
|
|
2184
|
+
* body transfer. A changed object costs that HEAD plus the full read, one extra
|
|
2185
|
+
* Class B operation on top of a request that sent no validator. `head()` is used
|
|
2186
|
+
* rather than an `onlyIf` precondition on `get()`, because `get()` takes only a
|
|
2187
|
+
* range here. `If-Modified-Since` is ignored.
|
|
2175
2188
|
*/
|
|
2176
2189
|
declare const serveStorageObject: (context: ContextWithStorage, key: string, request: Request, authorize: StorageServeAuthorizer, cacheControl?: string) => Promise<Response>;
|
|
2177
2190
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1333,6 +1333,12 @@ declare const flushDeferredDeletes: (context: unknown) => Promise<DeferredDelete
|
|
|
1333
1333
|
* store) keeps the previous best-effort behaviour rather than failing to build.
|
|
1334
1334
|
*/
|
|
1335
1335
|
interface ScheduleOutbox {
|
|
1336
|
+
/**
|
|
1337
|
+
* The schedule-rate budget for `target`, asked once per target per dispatch. Returns the
|
|
1338
|
+
* instant a schedule to `target` may not fire before, or `undefined` when within budget.
|
|
1339
|
+
* Never throws: a deferral only ever moves a job later.
|
|
1340
|
+
*/
|
|
1341
|
+
admit: (target: string) => number | undefined;
|
|
1336
1342
|
/** Release custody — the scheduler has the job, or the window that owned it was dropped. */
|
|
1337
1343
|
forget: (id: string) => void;
|
|
1338
1344
|
/**
|
|
@@ -2170,8 +2176,15 @@ type StorageServeAuthorizer = (context: StorageServeAuthzContext) => boolean | P
|
|
|
2170
2176
|
* derived from `authorize` because a stub returning `true` during development
|
|
2171
2177
|
* would then silently publish a cache. An app fronting a genuinely public
|
|
2172
2178
|
* bucket passes its own value; `content-disposition` and `nosniff` stay
|
|
2173
|
-
* unconditional either way.
|
|
2174
|
-
*
|
|
2179
|
+
* unconditional either way.
|
|
2180
|
+
*
|
|
2181
|
+
* A request whose `If-None-Match` names the current `etag` (or `*`, or any
|
|
2182
|
+
* weak form of it in a list) is answered `304 Not Modified` with no body, after
|
|
2183
|
+
* `authorize` has run and a body-free `head()`. A 304 costs one R2 HEAD and no
|
|
2184
|
+
* body transfer. A changed object costs that HEAD plus the full read, one extra
|
|
2185
|
+
* Class B operation on top of a request that sent no validator. `head()` is used
|
|
2186
|
+
* rather than an `onlyIf` precondition on `get()`, because `get()` takes only a
|
|
2187
|
+
* range here. `If-Modified-Since` is ignored.
|
|
2175
2188
|
*/
|
|
2176
2189
|
declare const serveStorageObject: (context: ContextWithStorage, key: string, request: Request, authorize: StorageServeAuthorizer, cacheControl?: string) => Promise<Response>;
|
|
2177
2190
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as i,actionCacheExtension as n,cacheKeyFor as a,defineActionCache as f}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-BFmhdKJG.mjs";import{initLunora as d}from"./packem_shared/initLunora-B-7Xs3Qq.mjs";import{isPerDispatchMiddleware as p,tagPerDispatchMiddleware as x}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as l}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as u,flushDeferredDeletes as h,withDeferredDeletes as S}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as T,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-
|
|
1
|
+
import{ACTION_CACHE_DEFAULT_TTL_MS as t,ACTION_CACHE_TABLE as i,actionCacheExtension as n,cacheKeyFor as a,defineActionCache as f}from"./packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-BFmhdKJG.mjs";import{initLunora as d}from"./packem_shared/initLunora-B-7Xs3Qq.mjs";import{isPerDispatchMiddleware as p,tagPerDispatchMiddleware as x}from"./packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs";import{createSecrets as l}from"./packem_shared/createSecrets-D6rLB42U.mjs";import{beginDeferredDeletes as u,flushDeferredDeletes as h,withDeferredDeletes as S}from"./packem_shared/beginDeferredDeletes-DhwFBbvs.mjs";import{beginDeferredSchedules as T,withDeferredSchedules as g}from"./packem_shared/beginDeferredSchedules-n_pHHjPE.mjs";import{DOCUMENT_HISTORY_REDACTED_FIELDS as R,DOCUMENT_HISTORY_TABLE as _,defineDocumentHistory as I,documentHistoryExtension as L}from"./packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-BeS7G0yM.mjs";import{LunoraEnvError as M,defineEnv as P,redactSecrets as b}from"./packem_shared/LunoraEnvError-bkdMu_-N.mjs";import{bindOrm as F,bindTableFacade as O}from"./packem_shared/bindOrm-BHq_oUP2.mjs";import{httpAction as N,httpRoute as w,httpRouter as U,isSafeHeaderValue as k}from"./packem_shared/httpAction-CsKNC6op.mjs";import{serveStorageObject as B}from"./packem_shared/serveStorageObject-DNN3r8x3.mjs";import{defineIdentity as W}from"./packem_shared/defineIdentity-DwkNKwYa.mjs";import{default as Y}from"./packem_shared/defineIdentityGuard-Bt8N65Zs.mjs";import{onConnect as J,onDisconnect as K,onShardInit as Q}from"./packem_shared/onConnect-BLRoOpv2.mjs";import{DEFAULT_LIMIT as q,DEFAULT_MAX_LIMIT as z,clampLimit as Z,defineListArgs as $}from"./packem_shared/DEFAULT_LIMIT-pT_tV8R0.mjs";import{defineMigration as re}from"./packem_shared/defineMigration-CXOS0Bvq.mjs";import{defineModule as te}from"./packem_shared/defineModule-OecXWM3U.mjs";import{defineMutator as ne}from"./packem_shared/defineMutator-B4ipDtDR.mjs";import{platformAdmin as fe}from"./packem_shared/platformAdmin-kczXQme8.mjs";import{c as de,d as me,a as pe,b as xe,e as ce,f as le,g as Ee,h as ue,i as he,j as Se,k as De,m as Te}from"./packem_shared/plugin-Bm9wIpiI.mjs";import{PRESENCE_DEFAULT_TTL_MS as Ae,PRESENCE_TABLE as Re,definePresence as _e,presenceExtension as Ie}from"./packem_shared/PRESENCE_DEFAULT_TTL_MS-DFpy5J8G.mjs";import{protectPublic as Ce}from"./packem_shared/protectPublic-Bi5_95aP.mjs";import{onQueryChange as Pe}from"./packem_shared/onQueryChange-CatdYnH5.mjs";import{createServices as ye}from"./packem_shared/createServices-IJvoqi0e.mjs";import{defineShape as Oe}from"./packem_shared/defineShape-CX9Xs8AY.mjs";import{onWhisper as Ne}from"./packem_shared/onWhisper-CfDbFLQh.mjs";import{LunoraError as Ue}from"@lunora/errors";import{cronJobs as ve}from"@lunora/scheduler";import{ValidationError as Ve,v as We}from"@lunora/values";import{allowAll as Ye,deny as Ge,isDeny as Je,toWhereInput as Ke}from"./packem_shared/allowAll-DkRAgItV.mjs";import{asBucketStorage as Xe}from"./packem_shared/asBucketStorage-DoGYOjq3.mjs";import{assertShapesDeclareReadPolicies as ze,buildRlsReadRegistry as Ze,composeShapeReadWhere as $e}from"./packem_shared/assertShapesDeclareReadPolicies-isd_Yupt.mjs";import{buildMaskRegistry as rr}from"./packem_shared/buildMaskRegistry-DpWMtalG.mjs";import{createPolicyDsl as tr,definePermission as ir,definePolicies as nr,definePolicy as ar,defineRole as fr}from"./packem_shared/createPolicyDsl-BZa6SqLJ.mjs";import{defineStorageRule as dr,defineStorageRules as mr}from"./packem_shared/defineStorageRule-Dv4nJE0H.mjs";import{mask as xr}from"./packem_shared/mask-BdULkLAu.mjs";import{r as lr}from"./packem_shared/middleware-DbhB1jRk.mjs";import{storageRules as ur}from"./packem_shared/storageRules-CMfQu8yY.mjs";const e="0.0.0";export{t as ACTION_CACHE_DEFAULT_TTL_MS,i as ACTION_CACHE_TABLE,q as DEFAULT_LIMIT,z as DEFAULT_MAX_LIMIT,R as DOCUMENT_HISTORY_REDACTED_FIELDS,_ as DOCUMENT_HISTORY_TABLE,M as LunoraEnvError,Ue as LunoraError,Ae as PRESENCE_DEFAULT_TTL_MS,Re as PRESENCE_TABLE,e as VERSION,Ve as ValidationError,n as actionCacheExtension,Ye as allowAll,Xe as asBucketStorage,ze as assertShapesDeclareReadPolicies,u as beginDeferredDeletes,T as beginDeferredSchedules,F as bindOrm,O as bindTableFacade,rr as buildMaskRegistry,Ze as buildRlsReadRegistry,a as cacheKeyFor,Z as clampLimit,de as composePluginMiddleware,$e as composeShapeReadWhere,tr as createPolicyDsl,l as createSecrets,ye as createServices,ve as cronJobs,f as defineActionCache,me as defineAggregateIndex,pe as defineComponent,I as defineDocumentHistory,P as defineEnv,W as defineIdentity,Y as defineIdentityGuard,$ as defineListArgs,re as defineMigration,te as defineModule,ne as defineMutator,ir as definePermission,xe as definePlugin,nr as definePolicies,ar as definePolicy,_e as definePresence,ce as defineRankIndex,fr as defineRole,le as defineSchema,Ee as defineSchemaExtension,Oe as defineShape,dr as defineStorageRule,mr as defineStorageRules,ue as defineTable,he as defineVectorIndex,Ge as deny,L as documentHistoryExtension,h as flushDeferredDeletes,N as httpAction,w as httpRoute,U as httpRouter,Se as indexFieldsFromSchema,d as initLunora,De as installPlugins,Je as isDeny,p as isPerDispatchMiddleware,k as isSafeHeaderValue,xr as mask,Te as mergeSchemaExtension,J as onConnect,K as onDisconnect,Pe as onQueryChange,Q as onShardInit,Ne as onWhisper,fe as platformAdmin,Ie as presenceExtension,Ce as protectPublic,b as redactSecrets,lr as rls,B as serveStorageObject,ur as storageRules,x as tagPerDispatchMiddleware,Ke as toWhereInput,We as v,S as withDeferredDeletes,g as withDeferredSchedules};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{assertScheduleInstant as A,assertScheduleDelay as v,resolveScheduleId as y}from"@lunora/scheduler";import{a as S}from"./wire-codec-CZ4obM6q.mjs";const m=new WeakMap,w=c=>{if(typeof c=="string")return c;const r=c??{},e=r.__lunoraRef??r.binding;return typeof e=="string"?e:"<unknown>"},x=c=>{let r=c;for(;r!==void 0&&!r.open;)r=r.parent;return r},D=(c,r,e)=>c==="runAfter"?Math.max(r,e-Date.now()):Math.max(r,e),k=(c,r)=>{const e=c,t={decisions:new Map,innermost:void 0,outbox:r},l=(n,i,o,s,d)=>e[n].call(e,i,o,s,d),u=(n,i,o,s,d)=>{const a=w(o);t.decisions.has(a)||t.decisions.set(a,t.outbox?.admit(a));const g=t.decisions.get(a),h=g===void 0?i:D(n,i,g),b=t.innermost;if(b===void 0)return l(n,h,o,s,d);const p=y(d?.id);return t.outbox?.record(p,{args:S(`ctx.scheduler.${n}`,w(o),s),options:d,target:o,when:Math.ceil(n==="runAfter"?Date.now()+h:h)}),b.pending.push({id:p,run:async()=>l(n,h,o,s,{...d,id:p})}),Promise.resolve(p)},f={...e,runAfter:(n,i,o,s)=>(v(n,"ctx.scheduler.runAfter"),u("runAfter",n,i,o,s)),runAt:(n,i,o,s)=>(A(n,Date.now(),"ctx.scheduler.runAt"),u("runAt",n,i,o,s))};return Object.setPrototypeOf(f,Object.getPrototypeOf(e)),m.set(f,t),f},q=c=>{const{scheduler:r}=c,e=typeof r=="object"&&r!==null?m.get(r):void 0;if(!e)return async()=>{};const t={open:!0,parent:e.innermost,pending:[]};return e.innermost=t,async l=>{if(!t.open)return;t.open=!1,e.innermost===t&&(e.innermost=x(t.parent));const u=t.pending.splice(0);if(u.length===0)return;if(!l){for(const{id:s}of u)e.outbox?.forget(s);return}const f=x(t.parent);if(f!==void 0){f.pending.push(...u);return}const n=[];for(const{id:s,run:d}of u)try{await d(),e.outbox?.forget(s)}catch(a){n.push(a)}const[i,...o]=n;if(i!==void 0)throw e.outbox?.wake(),o.length===0?i:new AggregateError(n,`ctx.scheduler: ${String(n.length)} of ${String(u.length)} deferred jobs failed to reach the scheduler after the commit`)}};export{q as beginDeferredSchedules,k as withDeferredSchedules};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isSafeHeaderValue as b}from"./httpAction-CsKNC6op.mjs";const N=/^bytes=(\d*)-(\d*)$/,g=t=>t.startsWith('"')||t.startsWith('W/"')?t:`"${t}"`,R=/(?:W\/)?"[^"]*"/g,p=t=>t.startsWith("W/")?t.slice(2):t,S=(t,e)=>{if(t.trim()==="*")return!0;const n=p(g(e));return(t.match(R)??[]).some(s=>p(s)===n)},m=(t,e)=>{if(t===null)return{kind:"full"};const n=N.exec(t.trim());if(!n)return{kind:"full"};const s=n[1]??"",a=n[2]??"";if(s===""&&a==="")return{kind:"full"};let r,o;if(s===""){const u=Number(a);if(u===0)return{kind:"unsatisfiable"};r=Math.max(0,e-u),o=e-1}else r=Number(s),o=a===""?e-1:Math.min(Number(a),e-1);return r>o||r>=e?{kind:"unsatisfiable"}:{end:o,kind:"partial",start:r}},v=new Set(["audio/mpeg","audio/ogg","audio/wav","image/apng","image/avif","image/gif","image/jpeg","image/png","image/webp","video/mp4","video/webm"]),w=(t,e)=>{const n=t.httpMetadata?.contentType,s=n!==void 0&&b(n)?n:"application/octet-stream",a={"accept-ranges":"bytes","cache-control":e,"content-type":s,etag:g(t.etag),"x-content-type-options":"nosniff"};return v.has(s.split(";")[0]?.trim().toLowerCase()??"")||(a["content-disposition"]="attachment"),t.sha256Base64!==void 0&&(a["repr-digest"]=`sha-256=:${t.sha256Base64}:`),a},y=t=>m(t,0).kind==="full",h=async(t,e,n)=>{const s=await t.storage.download(e);return s?new Response(s.body,{headers:{...w(s,n),"content-length":String(s.size)},status:200}):new Response("Not Found",{status:404})},T=async(t,e,n)=>{try{return await t({key:e,request:n})===!0}catch{return!1}},W=async(t,e,n,s,a="no-store")=>{if(!await T(s,e,n))return new Response("Forbidden",{status:403});const r=n.headers.get("if-none-match");let o;if(r!==null){const d=await t.storage.head(e);if(!d)return new Response("Not Found",{status:404});if(S(r,d.etag))return new Response(void 0,{headers:{"cache-control":a,etag:g(d.etag)},status:304});o=d}const u=n.headers.get("range");if(y(u))return h(t,e,a);const c=o??await t.storage.head(e);if(!c)return new Response("Not Found",{status:404});const i=m(u,c.size);if(i.kind==="unsatisfiable")return new Response("Range Not Satisfiable",{headers:{"accept-ranges":"bytes","content-range":`bytes */${String(c.size)}`,"content-type":"text/plain; charset=utf-8",etag:g(c.etag)},status:416});if(i.kind==="full")return h(t,e,a);const f=i.end-i.start+1,l=await t.storage.download(e,{range:{length:f,offset:i.start}});return l?new Response(l.body,{headers:{...w(c,a),"content-length":String(f),"content-range":`bytes ${String(i.start)}-${String(i.end)}/${String(c.size)}`},status:206}):new Response("Not Found",{status:404})};export{W as serveStorageObject};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/server",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.197",
|
|
4
4
|
"description": "Server primitives for Lunora: defineSchema, defineTable, query, mutation, and action",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"backend",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
74
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
75
|
-
"@lunora/shard-engine": "1.0.0-alpha.
|
|
74
|
+
"@lunora/scheduler": "1.0.0-alpha.123",
|
|
75
|
+
"@lunora/shard-engine": "1.0.0-alpha.126",
|
|
76
76
|
"@lunora/values": "1.0.0-alpha.64",
|
|
77
77
|
"drizzle-orm": "^0.45.3",
|
|
78
78
|
"hono": "^4.13.13"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{assertScheduleInstant as b,assertScheduleDelay as w,resolveScheduleId as m}from"@lunora/scheduler";import{a as x}from"./wire-codec-CZ4obM6q.mjs";const g=new WeakMap,y=u=>{if(typeof u=="string")return u;const r=u??{},n=r.__lunoraRef??r.binding;return typeof n=="string"?n:"<unknown>"},p=u=>{let r=u;for(;r!==void 0&&!r.open;)r=r.parent;return r},S=(u,r)=>{const n=u,s={innermost:void 0,outbox:r},l=(e,t,c,o,d)=>n[e].call(n,t,c,o,d),i=(e,t,c,o,d)=>{const a=s.innermost;if(a===void 0)return l(e,t,c,o,d);const h=m(d?.id);return s.outbox?.record(h,{args:x(`ctx.scheduler.${e}`,y(c),o),options:d,target:c,when:Math.ceil(e==="runAfter"?Date.now()+t:t)}),a.pending.push({id:h,run:async()=>l(e,t,c,o,{...d,id:h})}),Promise.resolve(h)},f={...n,runAfter:(e,t,c,o)=>(w(e,"ctx.scheduler.runAfter"),i("runAfter",e,t,c,o)),runAt:(e,t,c,o)=>(b(e,Date.now(),"ctx.scheduler.runAt"),i("runAt",e,t,c,o))};return Object.setPrototypeOf(f,Object.getPrototypeOf(n)),g.set(f,s),f},D=u=>{const{scheduler:r}=u,n=typeof r=="object"&&r!==null?g.get(r):void 0;if(!n)return async()=>{};const s={open:!0,parent:n.innermost,pending:[]};return n.innermost=s,async l=>{if(!s.open)return;s.open=!1,n.innermost===s&&(n.innermost=p(s.parent));const i=s.pending.splice(0);if(i.length===0)return;if(!l){for(const{id:o}of i)n.outbox?.forget(o);return}const f=p(s.parent);if(f!==void 0){f.pending.push(...i);return}const e=[];for(const{id:o,run:d}of i)try{await d(),n.outbox?.forget(o)}catch(a){e.push(a)}const[t,...c]=e;if(t!==void 0)throw n.outbox?.wake(),c.length===0?t:new AggregateError(e,`ctx.scheduler: ${String(e.length)} of ${String(i.length)} deferred jobs failed to reach the scheduler after the commit`)}};export{D as beginDeferredSchedules,S as withDeferredSchedules};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isSafeHeaderValue as l}from"./httpAction-CsKNC6op.mjs";const h=/^bytes=(\d*)-(\d*)$/,g=t=>t.startsWith('"')||t.startsWith('W/"')?t:`"${t}"`,f=(t,e)=>{if(t===null)return{kind:"full"};const n=h.exec(t.trim());if(!n)return{kind:"full"};const s=n[1]??"",a=n[2]??"";if(s===""&&a==="")return{kind:"full"};let o,r;if(s===""){const i=Number(a);if(i===0)return{kind:"unsatisfiable"};o=Math.max(0,e-i),r=e-1}else o=Number(s),r=a===""?e-1:Math.min(Number(a),e-1);return o>r||o>=e?{kind:"unsatisfiable"}:{end:r,kind:"partial",start:o}},m=new Set(["audio/mpeg","audio/ogg","audio/wav","image/apng","image/avif","image/gif","image/jpeg","image/png","image/webp","video/mp4","video/webm"]),p=(t,e)=>{const n=t.httpMetadata?.contentType,s=n!==void 0&&l(n)?n:"application/octet-stream",a={"accept-ranges":"bytes","cache-control":e,"content-type":s,etag:g(t.etag),"x-content-type-options":"nosniff"};return m.has(s.split(";")[0]?.trim().toLowerCase()??"")||(a["content-disposition"]="attachment"),t.sha256Base64!==void 0&&(a["repr-digest"]=`sha-256=:${t.sha256Base64}:`),a},w=t=>f(t,0).kind==="full",u=async(t,e,n)=>{const s=await t.storage.download(e);return s?new Response(s.body,{headers:{...p(s,n),"content-length":String(s.size)},status:200}):new Response("Not Found",{status:404})},b=async(t,e,n)=>{try{return await t({key:e,request:n})===!0}catch{return!1}},y=async(t,e,n,s,a="no-store")=>{if(!await b(s,e,n))return new Response("Forbidden",{status:403});const o=n.headers.get("range");if(w(o))return u(t,e,a);const r=await t.storage.head(e);if(!r)return new Response("Not Found",{status:404});const i=f(o,r.size);if(i.kind==="unsatisfiable")return new Response("Range Not Satisfiable",{headers:{"accept-ranges":"bytes","content-range":`bytes */${String(r.size)}`,"content-type":"text/plain; charset=utf-8",etag:g(r.etag)},status:416});if(i.kind==="full")return u(t,e,a);const c=i.end-i.start+1,d=await t.storage.download(e,{range:{length:c,offset:i.start}});return d?new Response(d.body,{headers:{...p(r,a),"content-length":String(c),"content-range":`bytes ${String(i.start)}-${String(i.end)}/${String(r.size)}`},status:206}):new Response("Not Found",{status:404})};export{y as serveStorageObject};
|