@lunora/do 1.0.0-alpha.194 → 1.0.0-alpha.195

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
@@ -3,6 +3,57 @@ export { type AdvisorProcedure, type AdvisoryFinding, type AggregateIndexDefinit
3
3
  import { DatabaseInstrumentation, MetricHistoryOptions, LogEventInput, TraceAnchor, ContextLogLevel, ContextTracer, SqlClientLike, ContextFetch, ContextMetrics } from '@lunora/observability';
4
4
  import { DrizzleSqliteDODatabase } from 'drizzle-orm/durable-sqlite';
5
5
  export { type ShardPlatform, type WorkerPlatform, type WorkerPlatformOptions, createShardAlarms, createShardDirectory, createShardHost, createShardKvStore, createShardPlatform, createSocketHost, createWorkerPlatform } from '@lunora/platform-cloudflare';
6
+ /** The framework roles that can share the shard class, named after their generated `_generated/` modules. */
7
+ declare const MERGED_ROLES: readonly ["scheduler", "shardRegistry"];
8
+ /** One of {@link MERGED_ROLES}. */
9
+ type MergedRole = (typeof MERGED_ROLES)[number];
10
+ /** The lifecycle handlers the Workers runtime invokes on a Durable Object. */
11
+ interface DurableObjectHandlers {
12
+ alarm?: (alarmInfo?: AlarmInvocationInfo) => Promise<void> | void;
13
+ fetch?: (request: Request) => Promise<Response> | Response;
14
+ webSocketClose?: (ws: WebSocket, code: number, reason: string, wasClean: boolean) => Promise<void> | void;
15
+ webSocketError?: (ws: WebSocket, error: unknown) => Promise<void> | void;
16
+ webSocketMessage?: (ws: WebSocket, message: ArrayBuffer | string) => Promise<void> | void;
17
+ }
18
+ /**
19
+ * A Durable Object class one role is implemented by. Its parameters are typed
20
+ * `never` so any role class fits — each framework class declares the structural
21
+ * slice of `DurableObjectState` / env it reads, and those slices differ.
22
+ */
23
+ type RoleClass = new (state: never, env: never) => DurableObjectHandlers;
24
+ /** The classes {@link mergeDurableObjects} folds into one; `scheduler` and `shardRegistry` only when the app has them. */
25
+ type MergedRoles = Partial<Record<MergedRole, RoleClass>> & {
26
+ shard: RoleClass;
27
+ };
28
+ /** The merged class: every lifecycle handler is defined, delegating to the instance's role. */
29
+ type MergedDurableObject<Env> = new (state: DurableObjectState, env: Env) => Required<DurableObjectHandlers>;
30
+ /** The one namespace member every selector shape shares — what {@link roleNamespace} needs to be handed. */
31
+ interface RoleNamespaceTarget {
32
+ idFromName: (name: string) => unknown;
33
+ }
34
+ /**
35
+ * One Durable Object class that hosts the shard, the scheduler and the shard
36
+ * registry, so an app spends one account class on the framework instead of
37
+ * three (plan 462). The role is read from `ctx.id.name` once, in the
38
+ * constructor — {@link roleNamespace} names carry `__lunora_do__:<role>:`,
39
+ * every other name is a shard — and each instance keeps that role, with its own
40
+ * storage, alarm and WebSockets, for life.
41
+ */
42
+ declare const mergeDurableObjects: <Env = unknown>(roles: MergedRoles) => MergedDurableObject<Env>;
43
+ /**
44
+ * `namespace` seen as one role of a {@link mergeDurableObjects} class: every name
45
+ * it resolves is prefixed with `__lunora_do__:<role>:`, so the scheduler's
46
+ * `"default"` and a shard called `"default"` stay different instances. Pass it
47
+ * where the builder takes the role's namespace:
48
+ * `.scheduler({ namespace: (env) => roleNamespace(env.SHARD, "scheduler") })`.
49
+ *
50
+ * A `Proxy`, so the result keeps the namespace's own type — whichever selector
51
+ * shape the caller has — and every member the framework does not name by
52
+ * (`get`, `idFromString`, …) passes through untouched. Methods are bound to the
53
+ * namespace: workerd rejects a native method called on another receiver
54
+ * ("Illegal invocation").
55
+ */
56
+ declare const roleNamespace: <Namespace extends RoleNamespaceTarget>(namespace: Namespace, role: MergedRole) => Namespace;
6
57
  /**
7
58
  * Serve a reserved `__lunora_relation__:read` / `:count` fan-out read for reverse
8
59
  * cross-backend relations — a `.global()` (D1) parent loading a shard-local child
@@ -5832,4 +5883,4 @@ declare class ShardRegistryDO {
5832
5883
  /** The in-memory map as a JSON-safe `table → [keys]` object, for `/snapshot`. */
5833
5884
  private serializeTables;
5834
5885
  }
5835
- export { type DispatchBookmark, type HibernatableWebSocket, type QueryReadScope, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkRowArgs, type RunShardBulkRowResult, type RunShardExportArgs, type RunShardFindRelatedArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, SessionDO, type SessionRecord, ShardDO, type ShardDOOptions, type ShardDOState, ShardRegistryDO, type SubscriptionOutcome, type TelemetrySink, type TraceRefLike, serveRelationFanout };
5886
+ export { type DispatchBookmark, type DurableObjectHandlers, type HibernatableWebSocket, MERGED_ROLES, type MergedDurableObject, type MergedRole, type MergedRoles, type QueryReadScope, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RoleClass, type RoleNamespaceTarget, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkRowArgs, type RunShardBulkRowResult, type RunShardExportArgs, type RunShardFindRelatedArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, SessionDO, type SessionRecord, ShardDO, type ShardDOOptions, type ShardDOState, ShardRegistryDO, type SubscriptionOutcome, type TelemetrySink, type TraceRefLike, mergeDurableObjects, roleNamespace, serveRelationFanout };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,57 @@ export { type AdvisorProcedure, type AdvisoryFinding, type AggregateIndexDefinit
3
3
  import { DatabaseInstrumentation, MetricHistoryOptions, LogEventInput, TraceAnchor, ContextLogLevel, ContextTracer, SqlClientLike, ContextFetch, ContextMetrics } from '@lunora/observability';
4
4
  import { DrizzleSqliteDODatabase } from 'drizzle-orm/durable-sqlite';
5
5
  export { type ShardPlatform, type WorkerPlatform, type WorkerPlatformOptions, createShardAlarms, createShardDirectory, createShardHost, createShardKvStore, createShardPlatform, createSocketHost, createWorkerPlatform } from '@lunora/platform-cloudflare';
6
+ /** The framework roles that can share the shard class, named after their generated `_generated/` modules. */
7
+ declare const MERGED_ROLES: readonly ["scheduler", "shardRegistry"];
8
+ /** One of {@link MERGED_ROLES}. */
9
+ type MergedRole = (typeof MERGED_ROLES)[number];
10
+ /** The lifecycle handlers the Workers runtime invokes on a Durable Object. */
11
+ interface DurableObjectHandlers {
12
+ alarm?: (alarmInfo?: AlarmInvocationInfo) => Promise<void> | void;
13
+ fetch?: (request: Request) => Promise<Response> | Response;
14
+ webSocketClose?: (ws: WebSocket, code: number, reason: string, wasClean: boolean) => Promise<void> | void;
15
+ webSocketError?: (ws: WebSocket, error: unknown) => Promise<void> | void;
16
+ webSocketMessage?: (ws: WebSocket, message: ArrayBuffer | string) => Promise<void> | void;
17
+ }
18
+ /**
19
+ * A Durable Object class one role is implemented by. Its parameters are typed
20
+ * `never` so any role class fits — each framework class declares the structural
21
+ * slice of `DurableObjectState` / env it reads, and those slices differ.
22
+ */
23
+ type RoleClass = new (state: never, env: never) => DurableObjectHandlers;
24
+ /** The classes {@link mergeDurableObjects} folds into one; `scheduler` and `shardRegistry` only when the app has them. */
25
+ type MergedRoles = Partial<Record<MergedRole, RoleClass>> & {
26
+ shard: RoleClass;
27
+ };
28
+ /** The merged class: every lifecycle handler is defined, delegating to the instance's role. */
29
+ type MergedDurableObject<Env> = new (state: DurableObjectState, env: Env) => Required<DurableObjectHandlers>;
30
+ /** The one namespace member every selector shape shares — what {@link roleNamespace} needs to be handed. */
31
+ interface RoleNamespaceTarget {
32
+ idFromName: (name: string) => unknown;
33
+ }
34
+ /**
35
+ * One Durable Object class that hosts the shard, the scheduler and the shard
36
+ * registry, so an app spends one account class on the framework instead of
37
+ * three (plan 462). The role is read from `ctx.id.name` once, in the
38
+ * constructor — {@link roleNamespace} names carry `__lunora_do__:<role>:`,
39
+ * every other name is a shard — and each instance keeps that role, with its own
40
+ * storage, alarm and WebSockets, for life.
41
+ */
42
+ declare const mergeDurableObjects: <Env = unknown>(roles: MergedRoles) => MergedDurableObject<Env>;
43
+ /**
44
+ * `namespace` seen as one role of a {@link mergeDurableObjects} class: every name
45
+ * it resolves is prefixed with `__lunora_do__:<role>:`, so the scheduler's
46
+ * `"default"` and a shard called `"default"` stay different instances. Pass it
47
+ * where the builder takes the role's namespace:
48
+ * `.scheduler({ namespace: (env) => roleNamespace(env.SHARD, "scheduler") })`.
49
+ *
50
+ * A `Proxy`, so the result keeps the namespace's own type — whichever selector
51
+ * shape the caller has — and every member the framework does not name by
52
+ * (`get`, `idFromString`, …) passes through untouched. Methods are bound to the
53
+ * namespace: workerd rejects a native method called on another receiver
54
+ * ("Illegal invocation").
55
+ */
56
+ declare const roleNamespace: <Namespace extends RoleNamespaceTarget>(namespace: Namespace, role: MergedRole) => Namespace;
6
57
  /**
7
58
  * Serve a reserved `__lunora_relation__:read` / `:count` fan-out read for reverse
8
59
  * cross-backend relations — a `.global()` (D1) parent loading a shard-local child
@@ -5832,4 +5883,4 @@ declare class ShardRegistryDO {
5832
5883
  /** The in-memory map as a JSON-safe `table → [keys]` object, for `/snapshot`. */
5833
5884
  private serializeTables;
5834
5885
  }
5835
- export { type DispatchBookmark, type HibernatableWebSocket, type QueryReadScope, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkRowArgs, type RunShardBulkRowResult, type RunShardExportArgs, type RunShardFindRelatedArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, SessionDO, type SessionRecord, ShardDO, type ShardDOOptions, type ShardDOState, ShardRegistryDO, type SubscriptionOutcome, type TelemetrySink, type TraceRefLike, serveRelationFanout };
5886
+ export { type DispatchBookmark, type DurableObjectHandlers, type HibernatableWebSocket, MERGED_ROLES, type MergedDurableObject, type MergedRole, type MergedRoles, type QueryReadScope, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RoleClass, type RoleNamespaceTarget, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkRowArgs, type RunShardBulkRowResult, type RunShardExportArgs, type RunShardFindRelatedArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, SessionDO, type SessionRecord, ShardDO, type ShardDOOptions, type ShardDOState, ShardRegistryDO, type SubscriptionOutcome, type TelemetrySink, type TraceRefLike, mergeDurableObjects, roleNamespace, serveRelationFanout };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{serveRelationFanout as a}from"./packem_shared/serveRelationFanout-DcSjzAZv.mjs";import{SESSION_DO_TTL_DEFAULT as t,SessionDO as c}from"./packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs";import{ROOT_DO_SIZE_WARN_BYTES as i,ROOT_SHARD_NAME as s,ShardDO as l}from"./packem_shared/ROOT_DO_SIZE_WARN_BYTES-kzU0A8n5.mjs";import{SHARD_REGISTRY_DO_NAME as d,ShardRegistryDO as R}from"./packem_shared/SHARD_REGISTRY_DO_NAME-DRIFt2FK.mjs";import{createShardAlarms as h,createShardDirectory as D,createShardHost as O,createShardKvStore as _,createShardPlatform as E,createSocketHost as m,createWorkerPlatform as u}from"@lunora/platform-cloudflare";import{REPROJECTION_MIGRATION_PREFIX as x,UNVOUCHABLE_DEP as I,applyCdcChanges as f,assertShapeShardable as b,backfillSearchIndexes as A,backfillVectorIndexes as M,buildReprojectionMigration as g,clearMemoryTables as k,countLegacyRows as N,createReadFootprint as y,createShardCtxDb as C,exportShardRows as H,importShardRows as L,isSourceDue as P,markUnvouchableReads as F,pullExternalSourceIncrementalTick as U,pullExternalSourceTick as j,reprojectionMigrationId as v,reprojectionTables as w,runDataMigration as B,runShardMigrations as G,subscriptionListDeltas as V}from"@lunora/shard-engine";export{x as REPROJECTION_MIGRATION_PREFIX,i as ROOT_DO_SIZE_WARN_BYTES,s as ROOT_SHARD_NAME,t as SESSION_DO_TTL_DEFAULT,d as SHARD_REGISTRY_DO_NAME,c as SessionDO,l as ShardDO,R as ShardRegistryDO,I as UNVOUCHABLE_DEP,f as applyCdcChanges,b as assertShapeShardable,A as backfillSearchIndexes,M as backfillVectorIndexes,g as buildReprojectionMigration,k as clearMemoryTables,N as countLegacyRows,y as createReadFootprint,h as createShardAlarms,C as createShardCtxDb,D as createShardDirectory,O as createShardHost,_ as createShardKvStore,E as createShardPlatform,m as createSocketHost,u as createWorkerPlatform,H as exportShardRows,L as importShardRows,P as isSourceDue,F as markUnvouchableReads,U as pullExternalSourceIncrementalTick,j as pullExternalSourceTick,v as reprojectionMigrationId,w as reprojectionTables,B as runDataMigration,G as runShardMigrations,a as serveRelationFanout,V as subscriptionListDeltas};
1
+ import{MERGED_ROLES as a,mergeDurableObjects as o,roleNamespace as t}from"./packem_shared/MERGED_ROLES-C4RToZ16.mjs";import{serveRelationFanout as S}from"./packem_shared/serveRelationFanout-DcSjzAZv.mjs";import{SESSION_DO_TTL_DEFAULT as s,SessionDO as l}from"./packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs";import{ROOT_DO_SIZE_WARN_BYTES as R,ROOT_SHARD_NAME as p,ShardDO as d}from"./packem_shared/ROOT_DO_SIZE_WARN_BYTES-kzU0A8n5.mjs";import{SHARD_REGISTRY_DO_NAME as E,ShardRegistryDO as O}from"./packem_shared/SHARD_REGISTRY_DO_NAME-DRIFt2FK.mjs";import{createShardAlarms as m,createShardDirectory as _,createShardHost as u,createShardKvStore as x,createShardPlatform as T,createSocketHost as b,createWorkerPlatform as f}from"@lunora/platform-cloudflare";import{REPROJECTION_MIGRATION_PREFIX as A,UNVOUCHABLE_DEP as M,applyCdcChanges as g,assertShapeShardable as N,backfillSearchIndexes as k,backfillVectorIndexes as L,buildReprojectionMigration as y,clearMemoryTables as C,countLegacyRows as H,createReadFootprint as P,createShardCtxDb as j,exportShardRows as F,importShardRows as U,isSourceDue as v,markUnvouchableReads as w,pullExternalSourceIncrementalTick as G,pullExternalSourceTick as B,reprojectionMigrationId as V,reprojectionTables as W,runDataMigration as Y,runShardMigrations as J,subscriptionListDeltas as K}from"@lunora/shard-engine";export{a as MERGED_ROLES,A as REPROJECTION_MIGRATION_PREFIX,R as ROOT_DO_SIZE_WARN_BYTES,p as ROOT_SHARD_NAME,s as SESSION_DO_TTL_DEFAULT,E as SHARD_REGISTRY_DO_NAME,l as SessionDO,d as ShardDO,O as ShardRegistryDO,M as UNVOUCHABLE_DEP,g as applyCdcChanges,N as assertShapeShardable,k as backfillSearchIndexes,L as backfillVectorIndexes,y as buildReprojectionMigration,C as clearMemoryTables,H as countLegacyRows,P as createReadFootprint,m as createShardAlarms,j as createShardCtxDb,_ as createShardDirectory,u as createShardHost,x as createShardKvStore,T as createShardPlatform,b as createSocketHost,f as createWorkerPlatform,F as exportShardRows,U as importShardRows,v as isSourceDue,w as markUnvouchableReads,o as mergeDurableObjects,G as pullExternalSourceIncrementalTick,B as pullExternalSourceTick,V as reprojectionMigrationId,W as reprojectionTables,t as roleNamespace,Y as runDataMigration,J as runShardMigrations,S as serveRelationFanout,K as subscriptionListDeltas};
@@ -0,0 +1 @@
1
+ import{LunoraError as l}from"@lunora/errors";import{LUNORA_ROLE_PREFIX as c}from"@lunora/platform";const m=["scheduler","shardRegistry"],h=t=>typeof t=="function",f=t=>typeof t=="object"&&t!==null&&"idFromName"in t&&h(t.idFromName),d=t=>{if(!t?.startsWith(c))return"shard";const s=t.slice(c.length,t.indexOf(":",c.length));return m.find(e=>e===s)},N=t=>class{#e;constructor(e,r){const n=d(e.id.name),o=n===void 0?void 0:t[n];if(o===void 0)throw new l("INTERNAL",`instance "${String(e.id.name)}" names no role merged into this Durable Object class`);this.#e=new o(e,r)}async alarm(e){await this.#e.alarm?.(e)}async fetch(e){if(this.#e.fetch===void 0)throw new l("INTERNAL","the merged Durable Object role has no fetch handler");return await this.#e.fetch(e)}async webSocketClose(e,r,n,o){await this.#e.webSocketClose?.(e,r,n,o)}async webSocketError(e,r){await this.#e.webSocketError?.(e,r)}async webSocketMessage(e,r){await this.#e.webSocketMessage?.(e,r)}},w=(t,s)=>{const e=`${c}${s}:`;return new Proxy(t,{get:(r,n)=>{const o=Reflect.get(r,n);return h(o)?n==="idFromName"||n==="getByName"?(a,...i)=>o.call(r,`${e}${a}`,...i):n==="jurisdiction"?(...a)=>{const i=o.apply(r,a);return f(i)?w(i,s):i}:o.bind(r):o}})};export{m as MERGED_ROLES,N as mergeDurableObjects,w as roleNamespace};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/do",
3
- "version": "1.0.0-alpha.194",
3
+ "version": "1.0.0-alpha.195",
4
4
  "description": "Lunora Durable Objects: ShardDO (SQLite, OCC, hibernated WebSocket subscriptions) and SessionDO",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -47,9 +47,10 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@lunora/errors": "1.0.0-alpha.50",
50
- "@lunora/observability": "1.0.0-alpha.121",
51
- "@lunora/platform-cloudflare": "1.0.0-alpha.74",
52
- "@lunora/shard-engine": "1.0.0-alpha.112",
50
+ "@lunora/observability": "1.0.0-alpha.122",
51
+ "@lunora/platform": "1.0.0-alpha.56",
52
+ "@lunora/platform-cloudflare": "1.0.0-alpha.75",
53
+ "@lunora/shard-engine": "1.0.0-alpha.113",
53
54
  "drizzle-orm": "^0.45.3"
54
55
  },
55
56
  "engines": {