@lunora/platform-node 1.0.0-alpha.212 → 1.0.0-alpha.214
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/index.mjs +1 -1
- package/dist/packem_shared/NODE_SCHEDULER_DISPATCH_PATH-CxOQHkZs.mjs +1 -0
- package/dist/packem_shared/createNodePlatform-BndSFuJZ.mjs +1 -0
- package/dist/packem_shared/node-dispatch-route-Dycdolqs.mjs +1 -0
- package/package.json +5 -5
- package/dist/packem_shared/NODE_SCHEDULER_DISPATCH_PATH-RI9fOO8d.mjs +0 -1
- package/dist/packem_shared/createNodePlatform-DJZCR46S.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{N as r,c as t}from"./packem_shared/node-dispatch-route-Dycdolqs.mjs";import{createNodeGlobalStore as d,createNodeSqlExec as c}from"./packem_shared/createNodeGlobalStore-CD4DiqeS.mjs";import{createNodeHttpServer as N}from"./packem_shared/createNodeHttpServer-D4YVdhJn.mjs";import{createNodeShardKvStore as m}from"./packem_shared/createNodeShardKvStore-DVi1OsvH.mjs";import{createNodePlatform as S}from"./packem_shared/createNodePlatform-BndSFuJZ.mjs";import{createNodeProfileHandler as H}from"./packem_shared/createNodeProfileHandler-MX5xKPg0.mjs";import{createNodeQueueHost as h}from"./packem_shared/createNodeQueueHost-CttDb5sY.mjs";import{createNodeR2Bucket as u}from"./packem_shared/createNodeR2Bucket-D_jsnenX.mjs";import{createNodeSchedulerHost as D}from"./packem_shared/createNodeSchedulerHost-CjgGhVoQ.mjs";import{createNodeShardHost as P}from"./packem_shared/createNodeShardHost-Bhbm4txQ.mjs";import{createNodeShardNamespace as _}from"./packem_shared/createNodeShardNamespace-BgQjDv7V.mjs";import{createNodeShardRegistry as n}from"./packem_shared/createNodeShardRegistry-BKl1QXiv.mjs";import{bindShardSockets as w,createNodeShardState as A}from"./packem_shared/bindShardSockets-9GvSocBW.mjs";import{createNodeSocketHost as T}from"./packem_shared/createNodeSocketHost-ByOmEGFe.mjs";import{createNodeWorkflowHost as g}from"./packem_shared/createNodeWorkflowHost-B76TKiw_.mjs";import{createNodeWorkflowStore as y}from"./packem_shared/createNodeWorkflowStore-CL7RYP6H.mjs";export{r as NODE_SCHEDULER_DISPATCH_PATH,w as bindShardSockets,t as createNodeDispatchRoute,d as createNodeGlobalStore,N as createNodeHttpServer,S as createNodePlatform,H as createNodeProfileHandler,h as createNodeQueueHost,u as createNodeR2Bucket,D as createNodeSchedulerHost,P as createNodeShardHost,m as createNodeShardKvStore,_ as createNodeShardNamespace,n as createNodeShardRegistry,A as createNodeShardState,T as createNodeSocketHost,c as createNodeSqlExec,g as createNodeWorkflowHost,y as createNodeWorkflowStore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{N as o,c as r,a as t}from"./node-dispatch-route-Dycdolqs.mjs";export{o as NODE_SCHEDULER_DISPATCH_PATH,r as createNodeDispatchRoute,t as createShardInvoke};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as u}from"@lunora/errors";import{NODE_CAPABILITIES as b}from"@lunora/platform";import{a as A,c as E,i as D,A as R}from"./node-dispatch-route-Dycdolqs.mjs";import{createNodeGlobalStore as y}from"./createNodeGlobalStore-CD4DiqeS.mjs";import{createNodeShardKvStore as g}from"./createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeQueueHost as T}from"./createNodeQueueHost-CttDb5sY.mjs";import{createNodeR2Bucket as F}from"./createNodeR2Bucket-D_jsnenX.mjs";import{createNodeSchedulerHost as I}from"./createNodeSchedulerHost-CjgGhVoQ.mjs";import{createNodeShardHost as B}from"./createNodeShardHost-Bhbm4txQ.mjs";import{createNodeShardRegistry as H}from"./createNodeShardRegistry-BKl1QXiv.mjs";import{createNodeSocketHost as L}from"./createNodeSocketHost-ByOmEGFe.mjs";import{createNodeWorkflowHost as q}from"./createNodeWorkflowHost-B76TKiw_.mjs";import{createNodeWorkflowStore as O}from"./createNodeWorkflowStore-CL7RYP6H.mjs";const U="__root__",Q=(e,o)=>async(r,c,t)=>{if(D(r,o,U))throw new u("BAD_REQUEST",R);const s=await e({args:c,functionPath:r,id:t.id,identity:void 0,scheduledFor:t.scheduledFor,shardKey:o,traceparent:void 0});if(!s.ok)throw new u("SERVICE_UNAVAILABLE",`@lunora/platform-node: scheduled job ${r} was refused with status ${String(s.status)}`)},X=(e={})=>{const o=[],{database:r,dispose:c,drain:t,host:s}=B(e);o.push(c);try{const d=g(r),a=H(e);o.push(()=>{a.close()});const{directory:l}=a,n=A(l,e.onFetch!==void 0),m=E({adminToken:e.dispatch?.adminToken,defaultShardKey:"__root__",invoke:n,schedulerSecret:e.dispatch?.schedulerSecret}),S=e.onFetch===void 0?void 0:Q(n,e.shardKey??"__root__"),{dispose:w,scheduler:v}=I(r,{...e,onDispatch:e.onDispatch??S}),{socket:_}=L(r);o.push(w);const p=e.queues===void 0?void 0:T(r,{onBatch:e.onQueueBatch??(()=>{throw new u("VALIDATION_ERROR","@lunora/platform-node: createNodePlatform was given `queues` without `onQueueBatch`, so a delivered batch has nowhere to go — pass the worker's queue export from createWorker")}),queues:e.queues}),k=e.objectStorageDirectory===void 0?void 0:F({directory:e.objectStorageDirectory}),i=e.globalTablesPath===void 0?void 0:y({path:e.globalTablesPath});i!==void 0&&o.push(()=>{i.dispose()});const N=e.workflows===void 0?void 0:q({store:O(r),workflows:e.workflows}),f=()=>{for(const h of o.toReversed())h()};return{capabilities:b,close:f,directory:l,dispatch:h=>m(h),drain:t,globalTables:i,kv:d,objectStorage:k,queues:p,scheduler:v,shard:s,sockets:_,workflows:N,[Symbol.dispose]:f}}catch(d){for(const a of o.toReversed())try{a()}catch{}throw d}};export{Q as createJobDelivery,X as createNodePlatform};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as s}from"@lunora/errors";import{toErrorResponse as u,resolveShard as l}from"@lunora/runtime";import{s as f}from"./hmac-url-Bogwm7I6.mjs";const g=async(t,e)=>{if(!t.body)return"";const n=t.body.getReader(),o=new TextDecoder;let r=0,a="";for(;;){const{done:i,value:d}=await n.read();if(i)break;if(d){if(r+=d.byteLength,r>e)return await n.cancel().catch(()=>{}),null;a+=o.decode(d,{stream:!0})}}return a+=o.decode(),a},h=(t,e)=>{const n=Math.max(t.length,e.length);let o=t.length^e.length;for(let r=0;r<n;r+=1){const a=r<t.length?t.charCodeAt(r):0,i=r<e.length?e.charCodeAt(r):0;o|=a^i}return o===0},y="/_lunora/scheduler/dispatch",_="__lunora_relation__:",A=t=>t.startsWith(_),c="agents:agentRun",E=(t,e,n)=>t===c&&e!==n,S=`\`${c}\` runs on the default shard only, where agent threads live; to run an agent's tools on another shard, start it from a mutation on that shard with \`ctx.agents.<name>.run\``,w=(t,e)=>{if(!e||e.length===0)return!1;const n=t.headers.get("authorization");if(!n)return!1;const[o,...r]=n.split(" ");return o?.toLowerCase()!=="bearer"?!1:h(e,r.join(" ").trim())},p=async(t,e,n)=>{const o=t.headers.get("x-lunora-scheduler-signature"),{schedulerSecret:r}=n;return o!==null&&o.length>0&&r!==void 0&&r.length>0?h(await f(r,e),o):w(t,n.adminToken)},T="x-lunora-paywall",D="1",R="x-lunora-scheduled-for",m=({forwardedIdentity:t,mutationId:e,scheduledFor:n,traceparent:o})=>{const r={"content-type":"application/json",[T]:D,"x-lunora-system":"1"};return t?.userId!==void 0&&t.userId.length>0&&(r["x-lunora-userid"]=t.userId),t?.identity!==void 0&&t.identity.length>0&&(r["x-lunora-identity"]=t.identity),e!==void 0&&e.length>0&&(r["x-lunora-mutation-id"]=e),o!==void 0&&o.length>0&&(r.traceparent=o),n!==void 0&&Number.isFinite(n)&&(r[R]=String(Math.trunc(n))),r},P=t=>{const e=t.headers.get("x-lunora-userid"),n=t.headers.get("x-lunora-identity");if(!(e===null&&n===null))return{...n===null?{}:{identity:n},...e===null?{}:{userId:e}}},N=1048576,O=async t=>{const e=await g(t,N);if(e===null)throw new s("PAYLOAD_TOO_LARGE","Scheduler dispatch body is too large");return e},v=async(t,e)=>{if(t.method!=="POST")throw new s("METHOD_NOT_ALLOWED","Scheduler dispatch endpoint requires POST",{status:405});const n=await O(t);if(!await p(t,n,{adminToken:e.adminToken,schedulerSecret:e.schedulerSecret}))throw new s("DISPATCH_UNAUTHENTICATED","Scheduler dispatch requires a valid signature or admin bearer");let r;try{r=JSON.parse(n)}catch{throw new s("BAD_REQUEST","Scheduler dispatch body must be valid JSON")}const a=r??{};if(typeof a.workflow=="string"||a.pool!==void 0)throw new s("SERVICE_UNAVAILABLE","Scheduler dispatch for a workflow or pool target is not served by the Node dispatch route");if(typeof a.functionPath!="string"||a.functionPath.length===0)throw new s("BAD_REQUEST","Scheduler dispatch is missing `functionPath`");if(A(a.functionPath))throw new s("FORBIDDEN","`__lunora_relation__:*` is a fan-out-only reserved RPC and cannot be dispatched to a single shard");const i=typeof a.shardKey=="string"&&a.shardKey.length>0?a.shardKey:e.defaultShardKey;if(E(a.functionPath,i,e.defaultShardKey))throw new s("BAD_REQUEST",S);return e.invoke({args:a.args??{},functionPath:a.functionPath,id:typeof a.id=="string"&&a.id.length>0?a.id:void 0,identity:P(t),scheduledFor:typeof a.scheduledFor=="number"?a.scheduledFor:void 0,shardKey:i,traceparent:t.headers.get("traceparent")??void 0})},x=(t,e)=>n=>{if(!e)throw new s("SERVICE_UNAVAILABLE","@lunora/platform-node: the dispatch route needs `onFetch` to run a function; without it a shard only echoes its key");const o=new Request("https://shard.internal/rpc",{body:JSON.stringify({args:n.args,functionPath:n.functionPath}),headers:m({forwardedIdentity:n.identity,mutationId:n.id,scheduledFor:n.scheduledFor,traceparent:n.traceparent}),method:"POST"});return l(t,n.shardKey).fetch(o)},H=t=>async e=>{try{return await v(e,t)}catch(n){return u(n)}},U=y;export{S as A,U as N,x as a,H as c,E as i};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/platform-node",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.214",
|
|
4
4
|
"description": "Node implementation of the Lunora platform contracts: ShardHost, SocketHost, ShardDirectory, ShardKvStore, SchedulerHost over better-sqlite3 and an in-process socket registry (dev/test target)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"better-sqlite3",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@lunora/d1": "1.0.0-alpha.230",
|
|
50
50
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
51
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
52
|
-
"@lunora/queue": "1.0.0-alpha.
|
|
53
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
51
|
+
"@lunora/platform": "1.0.0-alpha.79",
|
|
52
|
+
"@lunora/queue": "1.0.0-alpha.142",
|
|
53
|
+
"@lunora/runtime": "1.0.0-alpha.273",
|
|
54
54
|
"@lunora/sql-store": "1.0.0-alpha.231",
|
|
55
|
-
"@lunora/workflow": "1.0.0-alpha.
|
|
55
|
+
"@lunora/workflow": "1.0.0-alpha.110",
|
|
56
56
|
"@visulima/cron-parser": "2.0.0",
|
|
57
57
|
"@visulima/workflow": "4.0.0",
|
|
58
58
|
"better-sqlite3": "^13.0.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";import{toErrorResponse as h,resolveShard as u}from"@lunora/runtime";import{s as l}from"./hmac-url-Bogwm7I6.mjs";const f=async(e,t)=>{if(!e.body)return"";const n=e.body.getReader(),a=new TextDecoder;let r=0,o="";for(;;){const{done:s,value:d}=await n.read();if(s)break;if(d){if(r+=d.byteLength,r>t)return await n.cancel().catch(()=>{}),null;o+=a.decode(d,{stream:!0})}}return o+=a.decode(),o},c=(e,t)=>{const n=Math.max(e.length,t.length);let a=e.length^t.length;for(let r=0;r<n;r+=1){const o=r<e.length?e.charCodeAt(r):0,s=r<t.length?t.charCodeAt(r):0;a|=o^s}return a===0},y="/_lunora/scheduler/dispatch",g="__lunora_relation__:",p=e=>e.startsWith(g),_=(e,t)=>{if(!t||t.length===0)return!1;const n=e.headers.get("authorization");if(!n)return!1;const[a,...r]=n.split(" ");return a?.toLowerCase()!=="bearer"?!1:c(t,r.join(" ").trim())},w=async(e,t,n)=>{const a=e.headers.get("x-lunora-scheduler-signature"),{schedulerSecret:r}=n;return a!==null&&a.length>0&&r!==void 0&&r.length>0?c(await l(r,t),a):_(e,n.adminToken)},E="x-lunora-paywall",S="1",A="x-lunora-scheduled-for",T=({forwardedIdentity:e,mutationId:t,scheduledFor:n,traceparent:a})=>{const r={"content-type":"application/json",[E]:S,"x-lunora-system":"1"};return e?.userId!==void 0&&e.userId.length>0&&(r["x-lunora-userid"]=e.userId),e?.identity!==void 0&&e.identity.length>0&&(r["x-lunora-identity"]=e.identity),t!==void 0&&t.length>0&&(r["x-lunora-mutation-id"]=t),a!==void 0&&a.length>0&&(r.traceparent=a),n!==void 0&&Number.isFinite(n)&&(r[A]=String(Math.trunc(n))),r},D=e=>{const t=e.headers.get("x-lunora-userid"),n=e.headers.get("x-lunora-identity");if(!(t===null&&n===null))return{...n===null?{}:{identity:n},...t===null?{}:{userId:t}}},m=1048576,P=async e=>{const t=await f(e,m);if(t===null)throw new i("PAYLOAD_TOO_LARGE","Scheduler dispatch body is too large");return t},R=async(e,t)=>{if(e.method!=="POST")throw new i("METHOD_NOT_ALLOWED","Scheduler dispatch endpoint requires POST",{status:405});const n=await P(e);if(!await w(e,n,{adminToken:t.adminToken,schedulerSecret:t.schedulerSecret}))throw new i("DISPATCH_UNAUTHENTICATED","Scheduler dispatch requires a valid signature or admin bearer");let r;try{r=JSON.parse(n)}catch{throw new i("BAD_REQUEST","Scheduler dispatch body must be valid JSON")}const o=r??{};if(typeof o.workflow=="string"||o.pool!==void 0)throw new i("SERVICE_UNAVAILABLE","Scheduler dispatch for a workflow or pool target is not served by the Node dispatch route");if(typeof o.functionPath!="string"||o.functionPath.length===0)throw new i("BAD_REQUEST","Scheduler dispatch is missing `functionPath`");if(p(o.functionPath))throw new i("FORBIDDEN","`__lunora_relation__:*` is a fan-out-only reserved RPC and cannot be dispatched to a single shard");const s=typeof o.shardKey=="string"&&o.shardKey.length>0?o.shardKey:t.defaultShardKey;return t.invoke({args:o.args??{},functionPath:o.functionPath,id:typeof o.id=="string"&&o.id.length>0?o.id:void 0,identity:D(e),scheduledFor:typeof o.scheduledFor=="number"?o.scheduledFor:void 0,shardKey:s,traceparent:e.headers.get("traceparent")??void 0})},O=(e,t)=>n=>{if(!t)throw new i("SERVICE_UNAVAILABLE","@lunora/platform-node: the dispatch route needs `onFetch` to run a function; without it a shard only echoes its key");const a=new Request("https://shard.internal/rpc",{body:JSON.stringify({args:n.args,functionPath:n.functionPath}),headers:T({forwardedIdentity:n.identity,mutationId:n.id,scheduledFor:n.scheduledFor,traceparent:n.traceparent}),method:"POST"});return u(e,n.shardKey).fetch(a)},N=e=>async t=>{try{return await R(t,e)}catch(n){return h(n)}},C=y;export{C as NODE_SCHEDULER_DISPATCH_PATH,N as createNodeDispatchRoute,O as createShardInvoke};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as n}from"@lunora/errors";import{NODE_CAPABILITIES as y}from"@lunora/platform";import{createShardInvoke as g,createNodeDispatchRoute as _}from"./NODE_SCHEDULER_DISPATCH_PATH-RI9fOO8d.mjs";import{createNodeGlobalStore as R}from"./createNodeGlobalStore-CD4DiqeS.mjs";import{createNodeShardKvStore as D}from"./createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeQueueHost as I}from"./createNodeQueueHost-CttDb5sY.mjs";import{createNodeR2Bucket as A}from"./createNodeR2Bucket-D_jsnenX.mjs";import{createNodeSchedulerHost as E}from"./createNodeSchedulerHost-CjgGhVoQ.mjs";import{createNodeShardHost as T}from"./createNodeShardHost-Bhbm4txQ.mjs";import{createNodeShardRegistry as q}from"./createNodeShardRegistry-BKl1QXiv.mjs";import{createNodeSocketHost as B}from"./createNodeSocketHost-ByOmEGFe.mjs";import{createNodeWorkflowHost as H}from"./createNodeWorkflowHost-B76TKiw_.mjs";import{createNodeWorkflowStore as L}from"./createNodeWorkflowStore-CL7RYP6H.mjs";const F=(e,o)=>async(r,c,t)=>{const s=await e({args:c,functionPath:r,id:t.id,identity:void 0,scheduledFor:t.scheduledFor,shardKey:o,traceparent:void 0});if(!s.ok)throw new n("SERVICE_UNAVAILABLE",`@lunora/platform-node: scheduled job ${r} was refused with status ${String(s.status)}`)},z=(e={})=>{const o=[],{database:r,dispose:c,drain:t,host:s}=T(e);o.push(c);try{const d=D(r),a=q(e);o.push(()=>{a.close()});const{directory:u}=a,l=g(u,e.onFetch!==void 0),f=_({adminToken:e.dispatch?.adminToken,defaultShardKey:"__root__",invoke:l,schedulerSecret:e.dispatch?.schedulerSecret}),v=e.onFetch===void 0?void 0:F(l,e.shardKey??"__root__"),{dispose:w,scheduler:p}=E(r,{...e,onDispatch:e.onDispatch??v}),{socket:S}=B(r);o.push(w);const k=e.queues===void 0?void 0:I(r,{onBatch:e.onQueueBatch??(()=>{throw new n("VALIDATION_ERROR","@lunora/platform-node: createNodePlatform was given `queues` without `onQueueBatch`, so a delivered batch has nowhere to go — pass the worker's queue export from createWorker")}),queues:e.queues}),b=e.objectStorageDirectory===void 0?void 0:A({directory:e.objectStorageDirectory}),i=e.globalTablesPath===void 0?void 0:R({path:e.globalTablesPath});i!==void 0&&o.push(()=>{i.dispose()});const N=e.workflows===void 0?void 0:H({store:L(r),workflows:e.workflows}),m=()=>{for(const h of o.toReversed())h()};return{capabilities:y,close:m,directory:u,dispatch:h=>f(h),drain:t,globalTables:i,kv:d,objectStorage:b,queues:k,scheduler:p,shard:s,sockets:S,workflows:N,[Symbol.dispose]:m}}catch(d){for(const a of o.toReversed())try{a()}catch{}throw d}};export{z as createNodePlatform};
|