@lunora/platform-cloudflare 1.0.0-alpha.10 → 1.0.0-alpha.100

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.d.mts CHANGED
@@ -36,14 +36,6 @@ interface KvStorageLike {
36
36
  * `list` the underlying storage does not provide.
37
37
  */
38
38
  declare const createShardKvStore: (storage: KvStorageLike) => ShardKvStore;
39
- /**
40
- * Build the socket host for a DO.
41
- *
42
- * Note what is deliberately absent: `setTag` / `removeTag`. Cloudflare freezes
43
- * a socket's tags at `acceptWebSocket`, so declaring mutable tagging would be a
44
- * lie the engine could route on. Per the `SocketHost` contract, omitting both
45
- * tells callers to re-accept instead.
46
- */
47
39
  declare const createSocketHost: (state: DurableObjectState) => SocketHost;
48
40
  /**
49
41
  * Turn a Durable Object namespace binding into a {@link ShardDirectory}.
@@ -124,4 +116,114 @@ declare const createShardPlatform: (state: unknown) => ShardPlatform;
124
116
  * threaded through it.
125
117
  */
126
118
  declare const createWorkerPlatform: (env: unknown, options?: WorkerPlatformOptions) => WorkerPlatform;
127
- export { type ShardPlatform, type WorkerPlatform, type WorkerPlatformOptions, createShardAlarms, createShardDirectory, createShardHost, createShardKvStore, createShardPlatform, createSocketHost, createWorkerPlatform };
119
+ export { type ShardPlatform, type WorkerPlatform, type WorkerPlatformOptions,
120
+ /**
121
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
122
+ * `@lunora/platform` contracts.
123
+ *
124
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
125
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
126
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
127
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
128
+ * refactor of `@lunora/do`.
129
+ *
130
+ * # Why this depends on nothing but the contracts
131
+ *
132
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
133
+ * adapters that lived there, and so depended on the very package it was meant
134
+ * to make replaceable. That inverts the end-state, and with one host it also
135
+ * had zero consumers, so it was dissolved. This version is the other way up:
136
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
137
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
138
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
139
+ * provider API except through a contract.
140
+ */
141
+ createShardAlarms,
142
+ /**
143
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
144
+ * `@lunora/platform` contracts.
145
+ *
146
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
147
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
148
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
149
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
150
+ * refactor of `@lunora/do`.
151
+ *
152
+ * # Why this depends on nothing but the contracts
153
+ *
154
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
155
+ * adapters that lived there, and so depended on the very package it was meant
156
+ * to make replaceable. That inverts the end-state, and with one host it also
157
+ * had zero consumers, so it was dissolved. This version is the other way up:
158
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
159
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
160
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
161
+ * provider API except through a contract.
162
+ */
163
+ createShardDirectory,
164
+ /**
165
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
166
+ * `@lunora/platform` contracts.
167
+ *
168
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
169
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
170
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
171
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
172
+ * refactor of `@lunora/do`.
173
+ *
174
+ * # Why this depends on nothing but the contracts
175
+ *
176
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
177
+ * adapters that lived there, and so depended on the very package it was meant
178
+ * to make replaceable. That inverts the end-state, and with one host it also
179
+ * had zero consumers, so it was dissolved. This version is the other way up:
180
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
181
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
182
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
183
+ * provider API except through a contract.
184
+ */
185
+ createShardHost,
186
+ /**
187
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
188
+ * `@lunora/platform` contracts.
189
+ *
190
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
191
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
192
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
193
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
194
+ * refactor of `@lunora/do`.
195
+ *
196
+ * # Why this depends on nothing but the contracts
197
+ *
198
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
199
+ * adapters that lived there, and so depended on the very package it was meant
200
+ * to make replaceable. That inverts the end-state, and with one host it also
201
+ * had zero consumers, so it was dissolved. This version is the other way up:
202
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
203
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
204
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
205
+ * provider API except through a contract.
206
+ */
207
+ createShardKvStore, createShardPlatform,
208
+ /**
209
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
210
+ * `@lunora/platform` contracts.
211
+ *
212
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
213
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
214
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
215
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
216
+ * refactor of `@lunora/do`.
217
+ *
218
+ * # Why this depends on nothing but the contracts
219
+ *
220
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
221
+ * adapters that lived there, and so depended on the very package it was meant
222
+ * to make replaceable. That inverts the end-state, and with one host it also
223
+ * had zero consumers, so it was dissolved. This version is the other way up:
224
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
225
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
226
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
227
+ * provider API except through a contract.
228
+ */
229
+ createSocketHost, createWorkerPlatform };
package/dist/index.d.ts CHANGED
@@ -36,14 +36,6 @@ interface KvStorageLike {
36
36
  * `list` the underlying storage does not provide.
37
37
  */
38
38
  declare const createShardKvStore: (storage: KvStorageLike) => ShardKvStore;
39
- /**
40
- * Build the socket host for a DO.
41
- *
42
- * Note what is deliberately absent: `setTag` / `removeTag`. Cloudflare freezes
43
- * a socket's tags at `acceptWebSocket`, so declaring mutable tagging would be a
44
- * lie the engine could route on. Per the `SocketHost` contract, omitting both
45
- * tells callers to re-accept instead.
46
- */
47
39
  declare const createSocketHost: (state: DurableObjectState) => SocketHost;
48
40
  /**
49
41
  * Turn a Durable Object namespace binding into a {@link ShardDirectory}.
@@ -124,4 +116,114 @@ declare const createShardPlatform: (state: unknown) => ShardPlatform;
124
116
  * threaded through it.
125
117
  */
126
118
  declare const createWorkerPlatform: (env: unknown, options?: WorkerPlatformOptions) => WorkerPlatform;
127
- export { type ShardPlatform, type WorkerPlatform, type WorkerPlatformOptions, createShardAlarms, createShardDirectory, createShardHost, createShardKvStore, createShardPlatform, createSocketHost, createWorkerPlatform };
119
+ export { type ShardPlatform, type WorkerPlatform, type WorkerPlatformOptions,
120
+ /**
121
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
122
+ * `@lunora/platform` contracts.
123
+ *
124
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
125
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
126
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
127
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
128
+ * refactor of `@lunora/do`.
129
+ *
130
+ * # Why this depends on nothing but the contracts
131
+ *
132
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
133
+ * adapters that lived there, and so depended on the very package it was meant
134
+ * to make replaceable. That inverts the end-state, and with one host it also
135
+ * had zero consumers, so it was dissolved. This version is the other way up:
136
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
137
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
138
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
139
+ * provider API except through a contract.
140
+ */
141
+ createShardAlarms,
142
+ /**
143
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
144
+ * `@lunora/platform` contracts.
145
+ *
146
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
147
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
148
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
149
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
150
+ * refactor of `@lunora/do`.
151
+ *
152
+ * # Why this depends on nothing but the contracts
153
+ *
154
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
155
+ * adapters that lived there, and so depended on the very package it was meant
156
+ * to make replaceable. That inverts the end-state, and with one host it also
157
+ * had zero consumers, so it was dissolved. This version is the other way up:
158
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
159
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
160
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
161
+ * provider API except through a contract.
162
+ */
163
+ createShardDirectory,
164
+ /**
165
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
166
+ * `@lunora/platform` contracts.
167
+ *
168
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
169
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
170
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
171
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
172
+ * refactor of `@lunora/do`.
173
+ *
174
+ * # Why this depends on nothing but the contracts
175
+ *
176
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
177
+ * adapters that lived there, and so depended on the very package it was meant
178
+ * to make replaceable. That inverts the end-state, and with one host it also
179
+ * had zero consumers, so it was dissolved. This version is the other way up:
180
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
181
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
182
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
183
+ * provider API except through a contract.
184
+ */
185
+ createShardHost,
186
+ /**
187
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
188
+ * `@lunora/platform` contracts.
189
+ *
190
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
191
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
192
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
193
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
194
+ * refactor of `@lunora/do`.
195
+ *
196
+ * # Why this depends on nothing but the contracts
197
+ *
198
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
199
+ * adapters that lived there, and so depended on the very package it was meant
200
+ * to make replaceable. That inverts the end-state, and with one host it also
201
+ * had zero consumers, so it was dissolved. This version is the other way up:
202
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
203
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
204
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
205
+ * provider API except through a contract.
206
+ */
207
+ createShardKvStore, createShardPlatform,
208
+ /**
209
+ * `@lunora/platform-cloudflare` — the Cloudflare implementation of the
210
+ * `@lunora/platform` contracts.
211
+ *
212
+ * `@lunora/platform` says what a host must provide; this says how Cloudflare
213
+ * provides it, over `DurableObjectState`, hibernatable WebSockets, and a
214
+ * `DurableObjectNamespace`. A second target ships the same surface from its own
215
+ * `@lunora/platform-<target>` package, so adding one is a sibling rather than a
216
+ * refactor of `@lunora/do`.
217
+ *
218
+ * # Why this depends on nothing but the contracts
219
+ *
220
+ * An earlier version of this package sat *above* `@lunora/do` — it composed
221
+ * adapters that lived there, and so depended on the very package it was meant
222
+ * to make replaceable. That inverts the end-state, and with one host it also
223
+ * had zero consumers, so it was dissolved. This version is the other way up:
224
+ * the adapters live here, `@lunora/do` depends on this, and the only imports
225
+ * are `@lunora/platform` plus Cloudflare's own types. That is what makes the
226
+ * seam real rather than aspirational — `@lunora/do` can no longer reach a
227
+ * provider API except through a contract.
228
+ */
229
+ createSocketHost, createWorkerPlatform };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createShardAlarms as t,createShardDirectory as a,createShardHost as o,createShardKvStore as c,createSocketHost as S}from"./packem_shared/createShardAlarms-e3S0N0av.mjs";import{createShardPlatform as h,createWorkerPlatform as m}from"./packem_shared/createShardPlatform-AsnItVNl.mjs";export{t as createShardAlarms,a as createShardDirectory,o as createShardHost,c as createShardKvStore,h as createShardPlatform,S as createSocketHost,m as createWorkerPlatform};
1
+ import{createShardAlarms as t,createShardDirectory as a,createShardHost as o,createShardKvStore as c,createSocketHost as S}from"./packem_shared/createShardAlarms-Cm9SOaSc.mjs";import{createShardPlatform as h,createWorkerPlatform as m}from"./packem_shared/createShardPlatform-lSOGSs8s.mjs";export{t as createShardAlarms,a as createShardDirectory,o as createShardHost,c as createShardKvStore,h as createShardPlatform,S as createSocketHost,m as createWorkerPlatform};
@@ -0,0 +1 @@
1
+ import{LunoraError as h}from"@lunora/errors";const w=(e,t,o)=>{const c=e.storage.sql;if(typeof c?.exec!="function")throw new TypeError("storage.sql.exec is not available on this DurableObjectState");return c.exec(t,...o)},k=e=>({delete:()=>typeof e.deleteAlarm=="function"?e.deleteAlarm():Promise.resolve(),get:()=>typeof e.getAlarm=="function"?e.getAlarm():null,set:t=>typeof e.setAlarm=="function"?e.setAlarm(t):Promise.resolve()}),b=(e,t)=>{if(!(!(e instanceof Error)||e===t||e.cause!==void 0))try{Object.defineProperty(e,"cause",{configurable:!0,value:t,writable:!0})}catch{}},D=e=>{const{storage:t}=e,o={get databaseSize(){return e.storage.sql?.databaseSize},exec:(r,...i)=>w(e,r,i)},c=k(t),n=async r=>{if(typeof e.blockConcurrencyWhile=="function"){const i=await e.blockConcurrencyWhile(async()=>{try{return{ok:!0,value:await r()}}catch(l){return{error:l,ok:!1}}});if(!i.ok)throw i.error;return i.value}return r()},a=async r=>{const i=t;if(typeof i?.transaction=="function"){let l;try{return await i.transaction(async()=>{try{return await r()}catch(s){throw l={value:s},s}})}catch(s){throw l?(b(l.value,s),l.value):s}}return r()};return{alarms:c,runSerialized:n,shardKey:e.id?.name,sql:o,transaction:a,waitUntil:typeof e.waitUntil=="function"?r=>{e.waitUntil(r)}:void 0}},_=e=>({delete:async t=>!!await e.delete(t),get:t=>e.get(t),list:t=>{if(typeof e.list!="function")throw new TypeError("storage.list is not available on this DurableObjectStorage");return e.list(t)},put:(t,o)=>e.put(t,o)}),d="lunora-socket:",u=new WeakMap,g=new WeakMap;let S=0;const v=(e,t)=>{const{getTags:o}=e;if(typeof o=="function")try{return o.call(e,t).find(c=>c.startsWith(d))}catch{return}},E=(e,t)=>{const o=v(e,t);if(o!==void 0)return o.slice(d.length);const c=u.get(t);if(c!==void 0)return c;const n=g.get(t);if(n!==void 0)return n;S+=1;const a=`cf-socket-${String(S)}`;return g.set(t,a),a},p=10,y=256,m=1,T=e=>{if(!e||e.length===0)return;const t=p-m;if(e.length>t)throw new h("SOCKET_TAG_BUDGET_EXCEEDED",`${String(e.length)} tags supplied; Cloudflare allows ${String(p)} per socket and 1 is reserved for the host's identity tag — pass at most ${String(t)}.`);const o=e.find(c=>c.length>y);if(o!==void 0)throw new h("SOCKET_TAG_BUDGET_EXCEEDED",`Tag ${JSON.stringify(o)} is ${String(o.length)} characters; Cloudflare allows at most ${String(y)} characters per tag.`)},W=e=>{const t=e,o=new WeakSet;let c=0,n;const a=()=>{const r=e.getWebSockets();return(n?.generation!==c||n.length!==r.length)&&(n={generation:c,length:r.length,set:new WeakSet(r)}),n.set};return{newPair:()=>{if(t.openSocketPair!==void 0)return t.openSocketPair();const r=new WebSocketPair;return{client:r[0],server:r[1]}},upgradeResponse:r=>t.upgradeResponse!==void 0?t.upgradeResponse(r):new Response(null,{status:101,webSocket:r}),accept:(r,i,l)=>{T(l);const s=r,f=crypto.randomUUID();return e.acceptWebSocket(s,[`${d}${f}`,...l??[]]),u.set(s,f),c+=1,i!==void 0&&s.serializeAttachment?.(i),s},getSockets:r=>e.getWebSockets(r),handleFor:r=>{const i=r;if(u.has(i)||v(e,i)!==void 0)return i;if(!o.has(i)){if(a().has(i))return i;o.add(i)}},idFor:r=>E(e,r)}},A=e=>{const t=n=>({fetch:a=>n.fetch(a)}),o=n=>n===void 0?void 0:{locationHint:n};return{get:(n,a)=>t(e.get(n,o(a))),getByName:(n,a)=>t(e.get(e.idFromName(n),o(a))),idForName:n=>e.idFromName(n),jurisdiction:n=>A(e.jurisdiction(n))}};export{k as createShardAlarms,A as createShardDirectory,D as createShardHost,_ as createShardKvStore,W as createSocketHost};
@@ -0,0 +1 @@
1
+ import{createSocketHost as n,createShardHost as d,createShardKvStore as l,createShardDirectory as i}from"./createShardAlarms-Cm9SOaSc.mjs";import{CLOUDFLARE_CAPABILITIES as c}from"@lunora/platform";const h=e=>{const r=e;return{kv:l(r.storage),shard:d(r),sockets:n(r)}},m=(e,r={})=>{const s=e??{},a=o=>{const t=s[o];if(t==null)throw new Error(`@lunora/platform-cloudflare: no Durable Object namespace bound as "${o}" — add it to wrangler.jsonc's durable_objects.bindings`);return i(t)};return r.scheduler===void 0?{capabilities:c,directory:a}:{capabilities:c,directory:a,scheduler:r.scheduler}};export{h as createShardPlatform,m as createWorkerPlatform};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/platform-cloudflare",
3
- "version": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.100",
4
4
  "description": "Cloudflare implementation of the Lunora platform contracts: ShardHost, SocketHost, ShardDirectory, ShardKvStore over Durable Objects",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -43,8 +43,11 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@lunora/errors": "1.0.0-alpha.16",
47
- "@lunora/platform": "1.0.0-alpha.7"
46
+ "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
47
+ "@lunora/platform": "1.0.0-alpha.70"
48
+ },
49
+ "peerDependencies": {
50
+ "@cloudflare/workers-types": ">=4.0.0"
48
51
  },
49
52
  "engines": {
50
53
  "node": "^22.15.0 || >=24.11.0"
@@ -1 +0,0 @@
1
- import{LunoraError as g}from"@lunora/errors";const S=(t,e,r)=>{const a=t.storage.sql;if(typeof a?.exec!="function")throw new TypeError("storage.sql.exec is not available on this DurableObjectState");return a.exec(e,...r)},m=t=>({delete:()=>typeof t.deleteAlarm=="function"?t.deleteAlarm():Promise.resolve(),get:()=>typeof t.getAlarm=="function"?t.getAlarm():null,set:e=>typeof t.setAlarm=="function"?t.setAlarm(e):Promise.resolve()}),v=(t,e)=>{if(!(!(t instanceof Error)||t===e||t.cause!==void 0))try{Object.defineProperty(t,"cause",{configurable:!0,value:e,writable:!0})}catch{}},T=t=>{const{storage:e}=t,r={get databaseSize(){return t.storage.sql?.databaseSize},exec:(n,...s)=>S(t,n,s)},a=m(e),l=async n=>{if(typeof t.blockConcurrencyWhile=="function"){const s=await t.blockConcurrencyWhile(async()=>{try{return{ok:!0,value:await n()}}catch(i){return{error:i,ok:!1}}});if(!s.ok)throw s.error;return s.value}return n()},o=async n=>{const s=e;if(typeof s?.transaction=="function"){let i;try{return await s.transaction(async()=>{try{return await n()}catch(c){throw i={value:c},c}})}catch(c){throw i?(v(i.value,c),i.value):c}}return n()};return{alarms:a,runSerialized:l,shardKey:t.id?.name,sql:r,transaction:o,waitUntil:typeof t.waitUntil=="function"?n=>{t.waitUntil(n)}:void 0}},W=t=>({delete:async e=>!!await t.delete(e),get:e=>t.get(e),list:e=>{if(typeof t.list!="function")throw new TypeError("storage.list is not available on this DurableObjectStorage");return t.list(e)},put:(e,r)=>t.put(e,r)}),f="lunora-socket:",u=new WeakMap,h=new WeakMap;let d=0;const w=(t,e)=>{const{getTags:r}=t;if(typeof r=="function")try{return r.call(t,e).find(a=>a.startsWith(f))}catch{return}},k=(t,e)=>{const r=w(t,e);if(r!==void 0)return r.slice(f.length);const a=u.get(e);if(a!==void 0)return a;const l=h.get(e);if(l!==void 0)return l;d+=1;const o=`cf-socket-${String(d)}`;return h.set(e,o),o},y=10,p=256,b=1,E=t=>{if(!t||t.length===0)return;const e=y-b;if(t.length>e)throw new g("SOCKET_TAG_BUDGET_EXCEEDED",`${String(t.length)} tags supplied; Cloudflare allows ${String(y)} per socket and 1 is reserved for the host's identity tag — pass at most ${String(e)}.`);const r=t.find(a=>a.length>p);if(r!==void 0)throw new g("SOCKET_TAG_BUDGET_EXCEEDED",`Tag ${JSON.stringify(r)} is ${String(r.length)} characters; Cloudflare allows at most ${String(p)} characters per tag.`)},$=t=>{const e=new WeakSet;let r=0,a;const l=()=>{const o=t.getWebSockets();return(a?.generation!==r||a.length!==o.length)&&(a={generation:r,length:o.length,set:new WeakSet(o)}),a.set};return{accept:(o,n,s)=>{E(s);const i=o,c=crypto.randomUUID();return t.acceptWebSocket(i,[`${f}${c}`,...s??[]]),u.set(i,c),r+=1,n!==void 0&&i.serializeAttachment?.(n),i},getSockets:o=>t.getWebSockets(o),handleFor:o=>{const n=o;if(u.has(n)||w(t,n)!==void 0)return n;if(!e.has(n)){if(l().has(n))return n;e.add(n)}},idFor:o=>k(t,o)}},A=t=>{const e=r=>({fetch:a=>r.fetch(a)});return{get:r=>e(t.get(r)),getByName:r=>e(t.get(t.idFromName(r))),idForName:r=>t.idFromName(r),jurisdiction:r=>A(t.jurisdiction(r))}};export{m as createShardAlarms,A as createShardDirectory,T as createShardHost,W as createShardKvStore,$ as createSocketHost};
@@ -1 +0,0 @@
1
- import{CLOUDFLARE_CAPABILITIES as c}from"@lunora/platform";import{createSocketHost as d,createShardHost as n,createShardKvStore as i,createShardDirectory as l}from"./createShardAlarms-e3S0N0av.mjs";const b=e=>{const r=e;return{kv:i(r.storage),shard:n(r),sockets:d(r)}},m=(e,r={})=>{const s=e??{},t=o=>{const a=s[o];if(a==null)throw new Error(`@lunora/platform-cloudflare: no Durable Object namespace bound as "${o}" — add it to wrangler.jsonc's durable_objects.bindings`);return l(a)};return r.scheduler===void 0?{capabilities:c,directory:t}:{capabilities:c,directory:t,scheduler:r.scheduler}};export{b as createShardPlatform,m as createWorkerPlatform};