@lunora/platform-node 1.0.0-alpha.16 → 1.0.0-alpha.18
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/conformance/index.mjs +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{createNodePlatform-CfKfpghn.mjs → createNodePlatform-Dxux41uK.mjs} +1 -1
- package/dist/packem_shared/createNodeShardHost-C0j8nvSU.mjs +1 -0
- package/dist/packem_shared/{createNodeShardRegistry-Zy8eZoF9.mjs → createNodeShardRegistry-Dku0Og-w.mjs} +1 -1
- package/dist/packem_shared/createNodeSocketHost-DcWtdVDs.mjs +2 -0
- package/package.json +5 -5
- package/dist/packem_shared/createNodeShardHost-ByDrsNFb.mjs +0 -1
- package/dist/packem_shared/createNodeSocketHost-Ce4aH2Kq.mjs +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createNodeShardKvStore as
|
|
1
|
+
import{createNodeShardKvStore as N}from"../packem_shared/createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeSchedulerHost as D}from"../packem_shared/createNodeSchedulerHost-vZgv1CEo.mjs";import{createNodeShardHost as g}from"../packem_shared/createNodeShardHost-C0j8nvSU.mjs";import{createNodeShardRegistry as k}from"../packem_shared/createNodeShardRegistry-Dku0Og-w.mjs";import{createNodeSocketHost as H}from"../packem_shared/createNodeSocketHost-DcWtdVDs.mjs";const b=()=>{const{database:o,dispose:n,host:m}=g(),h=N(o),r=k(),{directory:p}=r,{readFrames:l,restoreSocket:u,simulateRecycle:w,socket:S}=H(o),i=new Set,{dispose:f,scheduler:d,simulateDeadLetter:y}=D(o,{onDispatch:(e,s,t)=>{i.add(t.id)}}),c=()=>{f(),n(),r.close()};return{awaitAlarmFired:async e=>{await new Promise(s=>{setTimeout(s,Math.max(0,e-Date.now())+30)})},awaitJobDispatched:async e=>{const t=(await d.list?.())?.find(a=>a.id===e);return t!==void 0&&await new Promise(a=>{setTimeout(a,Math.max(0,t.scheduledFor-Date.now())+30)}),i.has(e)},cleanup:c,directory:p,disposeTerminally:c,kv:h,readFrames:l,restoreSocket:u,scheduler:d,shard:m,simulateDeadLetter:y,simulateRecycle:w,socket:S}};export{b as createNodeConformanceHost};
|
package/dist/index.d.mts
CHANGED
|
@@ -335,8 +335,10 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
335
335
|
* benign); `shard.alarms.set()`/`delete()` throw before mutating any
|
|
336
336
|
* in-memory state (checked against the connection's own open/closed state,
|
|
337
337
|
* the single source of truth); `shard.alarms.get()` keeps answering
|
|
338
|
-
* whatever it last held.
|
|
339
|
-
*
|
|
338
|
+
* whatever it last held; `sockets.accept()`/`setTag()`/`removeTag()` throw
|
|
339
|
+
* the same way, checked against the same connection state, before touching
|
|
340
|
+
* any runtime socket map or durable row. A no-op instead of a throw would
|
|
341
|
+
* be indistinguishable from a working call — exactly the silent-vanishing
|
|
340
342
|
* this lifecycle exists to end.
|
|
341
343
|
*/
|
|
342
344
|
close: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -335,8 +335,10 @@ interface NodePlatform<Queues extends Record<string, {
|
|
|
335
335
|
* benign); `shard.alarms.set()`/`delete()` throw before mutating any
|
|
336
336
|
* in-memory state (checked against the connection's own open/closed state,
|
|
337
337
|
* the single source of truth); `shard.alarms.get()` keeps answering
|
|
338
|
-
* whatever it last held.
|
|
339
|
-
*
|
|
338
|
+
* whatever it last held; `sockets.accept()`/`setTag()`/`removeTag()` throw
|
|
339
|
+
* the same way, checked against the same connection state, before touching
|
|
340
|
+
* any runtime socket map or durable row. A no-op instead of a throw would
|
|
341
|
+
* be indistinguishable from a working call — exactly the silent-vanishing
|
|
340
342
|
* this lifecycle exists to end.
|
|
341
343
|
*/
|
|
342
344
|
close: () => void;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createNodeGlobalStore as r,createNodeSqlExec as t}from"./packem_shared/createNodeGlobalStore-Cwi33XOk.mjs";import{createNodeShardKvStore as d}from"./packem_shared/createNodeShardKvStore-DVi1OsvH.mjs";import{createNodePlatform as f}from"./packem_shared/createNodePlatform-
|
|
1
|
+
import{createNodeGlobalStore as r,createNodeSqlExec as t}from"./packem_shared/createNodeGlobalStore-Cwi33XOk.mjs";import{createNodeShardKvStore as d}from"./packem_shared/createNodeShardKvStore-DVi1OsvH.mjs";import{createNodePlatform as f}from"./packem_shared/createNodePlatform-Dxux41uK.mjs";import{createNodeQueueHost as x}from"./packem_shared/createNodeQueueHost--mBLGSxF.mjs";import{createNodeR2Bucket as p}from"./packem_shared/createNodeR2Bucket-CmHYlIni.mjs";import{createNodeSchedulerHost as l}from"./packem_shared/createNodeSchedulerHost-vZgv1CEo.mjs";import{createNodeShardHost as h}from"./packem_shared/createNodeShardHost-C0j8nvSU.mjs";import{createNodeShardRegistry as k}from"./packem_shared/createNodeShardRegistry-Dku0Og-w.mjs";import{createNodeShardState as w}from"./packem_shared/createNodeShardState-CpUzvWwd.mjs";import{createNodeSocketHost as W}from"./packem_shared/createNodeSocketHost-DcWtdVDs.mjs";import{createNodeWorkflowHost as g}from"./packem_shared/createNodeWorkflowHost-CTVBYiuj.mjs";import{createNodeWorkflowStore as q}from"./packem_shared/createNodeWorkflowStore-CL7RYP6H.mjs";export{r as createNodeGlobalStore,f as createNodePlatform,x as createNodeQueueHost,p as createNodeR2Bucket,l as createNodeSchedulerHost,h as createNodeShardHost,d as createNodeShardKvStore,k as createNodeShardRegistry,w as createNodeShardState,W as createNodeSocketHost,t as createNodeSqlExec,g as createNodeWorkflowHost,q as createNodeWorkflowStore};
|
package/dist/packem_shared/{createNodePlatform-CfKfpghn.mjs → createNodePlatform-Dxux41uK.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{NODE_CAPABILITIES as p}from"@lunora/platform";import{createNodeShardKvStore as f}from"./createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeQueueHost as N}from"./createNodeQueueHost--mBLGSxF.mjs";import{createNodeSchedulerHost as S}from"./createNodeSchedulerHost-vZgv1CEo.mjs";import{createNodeShardHost as q}from"./createNodeShardHost-
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";import{NODE_CAPABILITIES as p}from"@lunora/platform";import{createNodeShardKvStore as f}from"./createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeQueueHost as N}from"./createNodeQueueHost--mBLGSxF.mjs";import{createNodeSchedulerHost as S}from"./createNodeSchedulerHost-vZgv1CEo.mjs";import{createNodeShardHost as q}from"./createNodeShardHost-C0j8nvSU.mjs";import{createNodeShardRegistry as v}from"./createNodeShardRegistry-Dku0Og-w.mjs";import{createNodeSocketHost as w}from"./createNodeSocketHost-DcWtdVDs.mjs";const H=(e={})=>{const{database:o,dispose:s,drain:a,host:c}=q(e),d=f(o),r=v(e),{directory:u}=r,{socket:i}=w(o),{dispose:m,scheduler:h}=S(o,e),n=e.queues===void 0?void 0:N(o,{onBatch:e.onQueueBatch??(()=>{throw new l("VALIDATION_ERROR","@lunora/platform-node: createNodePlatform was given `queues` without `onQueueBatch`, so a delivered batch has nowhere to go — pass dispatchQueueBatch from @lunora/queue")}),queues:e.queues}),t=()=>{m(),s(),r.close()};return{capabilities:p,close:t,directory:u,drain:a,kv:d,queues:n,scheduler:h,shard:c,sockets:i,[Symbol.dispose]:t}};export{H as createNodePlatform};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import h from"better-sqlite3";const p=2147483647,T=e=>e===void 0?null:e,f=e=>({get databaseSize(){const r=e.pragma("page_count",{simple:!0}),s=e.pragma("page_size",{simple:!0});return r*s},exec:(r,...s)=>{const t=e.prepare(r),c=s.map(i=>T(i)),o=t.reader?t.all(...c):(t.run(...c),[]);return{[Symbol.iterator]:()=>o[Symbol.iterator](),one:()=>{if(o.length!==1)throw new Error(`expected exactly one row, got ${String(o.length)}`);return o[0]},toArray:()=>[...o]}}}),_=(e,r)=>{let s,t;e.exec("CREATE TABLE IF NOT EXISTS _lunora_alarm (id INTEGER PRIMARY KEY CHECK (id = 0), scheduled_for INTEGER NOT NULL)");const c=n=>{n===void 0?e.prepare("DELETE FROM _lunora_alarm WHERE id = 0").run():e.prepare("INSERT INTO _lunora_alarm (id, scheduled_for) VALUES (0, ?) ON CONFLICT (id) DO UPDATE SET scheduled_for = excluded.scheduled_for").run(n)},o=()=>{t!==void 0&&(clearTimeout(t),t=void 0)},i=n=>{o();const d=Math.max(0,n-Date.now());if(d>p){t=setTimeout(()=>{i(n)},p);return}t=setTimeout(()=>{s=void 0,t=void 0,e.open&&(c(void 0),(async()=>{await r?.()})().catch(()=>{}))},d)},m={delete:()=>{if(!e.open)throw new Error("platform closed: cannot delete an alarm");s=void 0,o(),c(void 0)},get:()=>s??null,set:n=>{if(!e.open)throw new Error("platform closed: cannot set an alarm");const d=typeof n=="number"?n:n.getTime();s=d,c(d),i(d)}},u=e.prepare("SELECT scheduled_for FROM _lunora_alarm WHERE id = 0").get();return u!==void 0&&(s=u.scheduled_for,i(u.scheduled_for)),{alarms:m,dispose:o}},v=(e={})=>{const r=new h(e.path??":memory:");r.pragma("journal_mode = WAL");const s=f(r),{alarms:t,dispose:c}=_(r,e.onAlarm),o=new Set;let i=Promise.resolve();const m=l=>{const a=i.then(l,l);return i=a.then(()=>{},()=>{}),a};let u=Promise.resolve();const n=async l=>{r.exec("BEGIN");try{const a=await l();return r.exec("COMMIT"),a}catch(a){throw r.exec("ROLLBACK"),a}},d=l=>{const a=u.then(()=>n(l),()=>n(l));return u=a.then(()=>{},()=>{}),a},E={alarms:t,runSerialized:m,shardKey:e.shardKey,sql:s,transaction:d,waitUntil:l=>{const a=l.catch(()=>{}).finally(()=>{o.delete(a)});o.add(a)}};return{database:r,dispose:()=>{c(),r.open&&r.close()},drain:async()=>{for(;o.size>0;)await Promise.all(o)},host:E}};export{v as createNodeShardHost};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mkdirSync as S,readdirSync as l}from"node:fs";import{join as u}from"node:path";import{createNodeShardKvStore as p}from"./createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeShardHost as y}from"./createNodeShardHost-
|
|
1
|
+
import{mkdirSync as S,readdirSync as l}from"node:fs";import{join as u}from"node:path";import{createNodeShardKvStore as p}from"./createNodeShardKvStore-DVi1OsvH.mjs";import{createNodeShardHost as y}from"./createNodeShardHost-C0j8nvSU.mjs";import{createNodeSocketHost as v}from"./createNodeSocketHost-DcWtdVDs.mjs";const n=".sqlite3",g=r=>r.replaceAll(/[^\w.-]/gu,t=>[...Buffer.from(t,"utf8")].map(o=>`%${o.toString(16).padStart(2,"0").toUpperCase()}`).join("")),F=r=>decodeURIComponent(r),R=(r={})=>{const t=new Map,o=new Set;if(r.directory!==void 0){S(r.directory,{recursive:!0});for(const e of l(r.directory))e.endsWith(n)&&o.add(F(e.slice(0,-n.length)))}const a=e=>{const d=t.get(e);if(d!==void 0)return d.shard;const c=r.directory===void 0?void 0:u(r.directory,`${g(e)}${n}`);let s;const{database:h,dispose:f,host:m}=y({onAlarm:()=>r.onAlarm?.(s),path:c,shardKey:e});return s={kv:p(h),shard:m,shardKey:e,sockets:v(h).socket},t.set(e,{dispose:f,shard:s}),o.add(e),s},i=e=>({fetch:async d=>{const c=a(e);return r.onFetch===void 0?new Response(e):r.onFetch(d,c)}});return{close:()=>{for(const e of t.values())e.dispose();t.clear()},directory:{get:e=>i(String(e)),getByName:e=>i(e),idForName:e=>e},listShardKeys:()=>[...o],shardFor:a}};export{R as createNodeShardRegistry};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{deserialize as T,serialize as u}from"node:v8";import{t as v}from"./to-array-buffer-DVyXU4Ep.mjs";const k=n=>{n.exec("CREATE TABLE IF NOT EXISTS _lunora_sockets (id TEXT PRIMARY KEY, attachment BLOB, tags TEXT NOT NULL DEFAULT '[]')");const p=n.prepare(`INSERT INTO _lunora_sockets (id, attachment, tags) VALUES (?, ?, ?)
|
|
2
|
+
ON CONFLICT (id) DO UPDATE SET attachment = excluded.attachment, tags = excluded.tags`),f=n.prepare("UPDATE _lunora_sockets SET attachment = ? WHERE id = ?"),g=n.prepare("UPDATE _lunora_sockets SET tags = ? WHERE id = ?"),E=n.prepare("SELECT attachment, tags FROM _lunora_sockets WHERE id = ?"),m=n.prepare("DELETE FROM _lunora_sockets WHERE id = ?"),s=new Map,i=new WeakMap,h=(t,e)=>{n.open&&f.run(e===void 0?null:u(e),t)},a=(t,e)=>{n.open&&g.run(JSON.stringify([...e]),t)},d=t=>{const e=t,o={bufferedAmount:e.bufferedAmount,close:(r,c)=>{e.closed=!0,s.delete(e.id),n.open&&m.run(e.id)},deserializeAttachment:()=>e.attachment,send:r=>{e.received.push(typeof r=="string"?r:v(r))},serializeAttachment:r=>{e.attachment=r,h(e.id,r)}};return e.handle=o,i.set(o,e.id),o};return{readFrames:t=>(s.get(i.get(t)??"")?.received??[]).filter(e=>typeof e=="string"),restoreSocket:(t,e)=>{const o=n.open?E.get(t):void 0,r=o?.attachment===null?void 0:o?.attachment,c={attachment:r===void 0?e:T(r),bufferedAmount:0,closed:!1,handle:void 0,id:t,raw:void 0,received:[],tags:new Set(o===void 0?[]:JSON.parse(o.tags))};return s.set(t,c),d(c)},simulateRecycle:()=>{s.clear()},socket:{accept:(t,e,o)=>{if(!n.open)throw new Error("platform closed: cannot accept a socket");const r=crypto.randomUUID(),c=new Set(o),l={attachment:e,bufferedAmount:0,closed:!1,handle:void 0,id:r,raw:t,received:[],tags:c};return s.set(r,l),p.run(r,e===void 0?null:u(e),JSON.stringify([...c])),d(l)},getSockets:t=>{const e=[...s.values()];return(t===void 0?e:e.filter(r=>r.tags.has(t))).map(r=>r.handle)},handleFor:t=>[...s.values()].find(e=>e.raw===t)?.handle,idFor:t=>{const e=i.get(t);if(e===void 0)throw new Error("@lunora/platform-node: idFor called with a handle this host never issued");return e},removeTag:(t,e)=>{if(!n.open)throw new Error("platform closed: cannot remove a tag");const o=s.get(i.get(t)??"");o!==void 0&&(e===void 0?o.tags.clear():o.tags.delete(e),a(o.id,o.tags))},setTag:(t,e)=>{if(!n.open)throw new Error("platform closed: cannot set a tag");const o=s.get(i.get(t)??"");o!==void 0&&(o.tags.add(e),a(o.id,o.tags))}}}};export{k as createNodeSocketHost};
|
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.18",
|
|
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",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/d1": "1.0.0-alpha.
|
|
49
|
+
"@lunora/d1": "1.0.0-alpha.82",
|
|
50
50
|
"@lunora/errors": "1.0.0-alpha.22",
|
|
51
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
52
|
-
"@lunora/queue": "1.0.0-alpha.
|
|
53
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
51
|
+
"@lunora/platform": "1.0.0-alpha.14",
|
|
52
|
+
"@lunora/queue": "1.0.0-alpha.30",
|
|
53
|
+
"@lunora/sql-store": "1.0.0-alpha.84",
|
|
54
54
|
"@lunora/workflow": "1.0.0-alpha.30",
|
|
55
55
|
"@visulima/workflow": "3.0.0",
|
|
56
56
|
"better-sqlite3": "^13.0.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import f from"better-sqlite3";const h=2147483647,p=e=>e===void 0?null:e,g=e=>({get databaseSize(){const r=e.pragma("page_count",{simple:!0}),t=e.pragma("page_size",{simple:!0});return r*t},exec:(r,...t)=>{const o=e.prepare(r),c=t.map(l=>p(l)),n=o.reader?o.all(...c):(o.run(...c),[]);return{[Symbol.iterator]:()=>n[Symbol.iterator](),one:()=>{if(n.length!==1)throw new Error(`expected exactly one row, got ${String(n.length)}`);return n[0]},toArray:()=>[...n]}}}),w=e=>({all:async(r,t)=>e.prepare(r).all(...t.map(c=>p(c))),run:async(r,t)=>({rowsAffected:e.prepare(r).run(...t.map(n=>p(n))).changes})}),y=(e,r)=>{let t,o;e.exec("CREATE TABLE IF NOT EXISTS _lunora_alarm (id INTEGER PRIMARY KEY CHECK (id = 0), scheduled_for INTEGER NOT NULL)");const c=a=>{a===void 0?e.prepare("DELETE FROM _lunora_alarm WHERE id = 0").run():e.prepare("INSERT INTO _lunora_alarm (id, scheduled_for) VALUES (0, ?) ON CONFLICT (id) DO UPDATE SET scheduled_for = excluded.scheduled_for").run(a)},n=()=>{o!==void 0&&(clearTimeout(o),o=void 0)},l=a=>{n();const i=Math.max(0,a-Date.now());if(i>h){o=setTimeout(()=>{l(a)},h);return}o=setTimeout(()=>{t=void 0,o=void 0,e.open&&(c(void 0),(async()=>{await r?.()})().catch(()=>{}))},i)},m={delete:()=>{if(!e.open)throw new Error("platform closed: cannot delete an alarm");t=void 0,n(),c(void 0)},get:()=>t??null,set:a=>{if(!e.open)throw new Error("platform closed: cannot set an alarm");const i=typeof a=="number"?a:a.getTime();t=i,c(i),l(i)}},u=e.prepare("SELECT scheduled_for FROM _lunora_alarm WHERE id = 0").get();return u!==void 0&&(t=u.scheduled_for,l(u.scheduled_for)),{alarms:m,dispose:n}},v=(e={})=>{const r=new f(e.path??":memory:");r.pragma("journal_mode = WAL");const t=g(r),o=w(r),{alarms:c,dispose:n}=y(r,e.onAlarm),l=new Set;let m=Promise.resolve();const u=d=>{const s=m.then(d,d);return m=s.then(()=>{},()=>{}),s};let a=Promise.resolve();const i=async d=>{r.exec("BEGIN");try{const s=await d();return r.exec("COMMIT"),s}catch(s){throw r.exec("ROLLBACK"),s}},E=d=>{const s=a.then(()=>i(d),()=>i(d));return a=s.then(()=>{},()=>{}),s},T={alarms:c,asyncSql:o,runSerialized:u,shardKey:e.shardKey,sql:t,transaction:E,waitUntil:d=>{const s=d.catch(()=>{}).finally(()=>{l.delete(s)});l.add(s)}};return{database:r,dispose:()=>{n(),r.open&&r.close()},drain:async()=>{for(;l.size>0;)await Promise.all(l)},host:T}};export{v as createNodeShardHost};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{deserialize as T,serialize as u}from"node:v8";import{t as v}from"./to-array-buffer-DVyXU4Ep.mjs";const R=r=>{r.exec("CREATE TABLE IF NOT EXISTS _lunora_sockets (id TEXT PRIMARY KEY, attachment BLOB, tags TEXT NOT NULL DEFAULT '[]')");const p=r.prepare(`INSERT INTO _lunora_sockets (id, attachment, tags) VALUES (?, ?, ?)
|
|
2
|
-
ON CONFLICT (id) DO UPDATE SET attachment = excluded.attachment, tags = excluded.tags`),f=r.prepare("UPDATE _lunora_sockets SET attachment = ? WHERE id = ?"),g=r.prepare("UPDATE _lunora_sockets SET tags = ? WHERE id = ?"),E=r.prepare("SELECT attachment, tags FROM _lunora_sockets WHERE id = ?"),h=r.prepare("DELETE FROM _lunora_sockets WHERE id = ?"),n=new Map,i=new WeakMap,m=(t,e)=>{r.open&&f.run(e===void 0?null:u(e),t)},a=(t,e)=>{r.open&&g.run(JSON.stringify([...e]),t)},d=t=>{const e=t,o={bufferedAmount:e.bufferedAmount,close:(s,c)=>{e.closed=!0,n.delete(e.id),r.open&&h.run(e.id)},deserializeAttachment:()=>e.attachment,send:s=>{e.received.push(typeof s=="string"?s:v(s))},serializeAttachment:s=>{e.attachment=s,m(e.id,s)}};return e.handle=o,i.set(o,e.id),o};return{readFrames:t=>(n.get(i.get(t)??"")?.received??[]).filter(e=>typeof e=="string"),restoreSocket:(t,e)=>{const o=r.open?E.get(t):void 0,s=o?.attachment===null?void 0:o?.attachment,c={attachment:s===void 0?e:T(s),bufferedAmount:0,closed:!1,handle:void 0,id:t,raw:void 0,received:[],tags:new Set(o===void 0?[]:JSON.parse(o.tags))};return n.set(t,c),d(c)},simulateRecycle:()=>{n.clear()},socket:{accept:(t,e,o)=>{const s=crypto.randomUUID(),c=new Set(o),l={attachment:e,bufferedAmount:0,closed:!1,handle:void 0,id:s,raw:t,received:[],tags:c};return n.set(s,l),r.open&&p.run(s,e===void 0?null:u(e),JSON.stringify([...c])),d(l)},getSockets:t=>{const e=[...n.values()];return(t===void 0?e:e.filter(s=>s.tags.has(t))).map(s=>s.handle)},handleFor:t=>[...n.values()].find(e=>e.raw===t)?.handle,idFor:t=>{const e=i.get(t);if(e===void 0)throw new Error("@lunora/platform-node: idFor called with a handle this host never issued");return e},removeTag:(t,e)=>{const o=n.get(i.get(t)??"");o!==void 0&&(e===void 0?o.tags.clear():o.tags.delete(e),a(o.id,o.tags))},setTag:(t,e)=>{const o=n.get(i.get(t)??"");o!==void 0&&(o.tags.add(e),a(o.id,o.tags))}}}};export{R as createNodeSocketHost};
|