@plexspaces/sdk 0.1.5 → 0.1.8

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/host.d.ts CHANGED
@@ -119,12 +119,110 @@ export declare class Registry {
119
119
  heartbeat(objectId: string, objectType?: number, tenantId?: string, namespace?: string): void;
120
120
  }
121
121
  export { RegistryObjectType };
122
+ /**
123
+ * KVStore provides namespaced KV operations.
124
+ * Equivalent to Cloudflare DO's this.state.storage API.
125
+ * Access via host.kv.get(), host.kv.put() etc.
126
+ */
127
+ export declare class KVStore {
128
+ get(key: string): string | null;
129
+ put(key: string, value: string): void;
130
+ delete(key: string): void;
131
+ list(prefix: string): string[];
132
+ putWithTtl(key: string, value: string, ttlSeconds: number): void;
133
+ getTtl(key: string): number;
134
+ cas(key: string, expected: string | null, newValue: string): boolean;
135
+ increment(key: string, delta: number): number;
136
+ multiGet(keys: string[]): (string | null)[];
137
+ multiPut(entries: Record<string, string>): void;
138
+ getJson<T = unknown>(key: string): T | null;
139
+ putJson(key: string, value: unknown): void;
140
+ }
141
+ /**
142
+ * AlarmClient provides durable alarm scheduling.
143
+ * Equivalent to Cloudflare DO's setAlarm/getAlarm/deleteAlarm.
144
+ * Access via host.alarm.set(), host.alarm.get(), host.alarm.delete() etc.
145
+ */
146
+ export declare class AlarmClient {
147
+ set(timestampMs: number): void;
148
+ setIn(delayMs: number): void;
149
+ get(): number;
150
+ delete(): void;
151
+ }
152
+ /**
153
+ * LockClient provides distributed lock operations.
154
+ * Access via host.locks.acquire(), host.locks.release() etc.
155
+ */
156
+ export declare class LockClient {
157
+ acquire(holderId: string, lockName: string, leaseDurationSecs: number, timeoutMs: bigint): Uint8Array;
158
+ release(lockId: string, holderId: string, lockVersion: string): void;
159
+ renew(lockId: string, holderId: string, lockVersion: string, leaseDurationSecs: number): Uint8Array;
160
+ }
161
+ /**
162
+ * BlobClient provides blob storage operations.
163
+ * Access via host.blob.upload(), host.blob.download() etc.
164
+ */
165
+ export declare class BlobClient {
166
+ upload(name: string, data: Uint8Array, contentType: string): string;
167
+ download(blobId: string): Uint8Array;
168
+ delete(blobId: string): void;
169
+ list(prefix: string): string[];
170
+ }
171
+ /**
172
+ * ActorRef is a lightweight handle to a named virtual actor.
173
+ * Equivalent to Cloudflare DO's env.BINDING.get(id).
174
+ * Use getActorRef() to obtain one.
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const room = getActorRef("ChatRoomActor", roomId, "default");
179
+ * const result = room.ask("send_message", payload, BigInt(5000));
180
+ * ```
181
+ */
182
+ export declare class ActorRef {
183
+ readonly actorId: string;
184
+ constructor(actorType: string, name: string, namespace: string);
185
+ id(): string;
186
+ tell(msgType: string, payload: Uint8Array): void;
187
+ ask(msgType: string, payload: Uint8Array, timeoutMs: bigint): Uint8Array;
188
+ }
189
+ /**
190
+ * getActorRef constructs an ActorRef for a named virtual actor.
191
+ * The actor is created automatically on first contact (virtual actor pattern).
192
+ * Equivalent to Cloudflare: `const room = env.CHAT_ROOM.get(roomId)`
193
+ */
194
+ export declare function getActorRef(actorType: string, name: string, namespace: string): ActorRef;
122
195
  export declare class Host {
123
196
  readonly processGroups: ProcessGroups;
124
197
  /** Tuple space: list-in, list-out. Use null in patterns for wildcards. */
125
198
  readonly ts: TupleSpace;
126
199
  /** Object registry: register, discover, and look up actors and services. */
127
200
  readonly registry: Registry;
201
+ /** Namespaced KV store: host.kv.get(), host.kv.put() etc. */
202
+ readonly kv: KVStore;
203
+ /** Durable alarm client: host.alarm.set(), host.alarm.get() etc. */
204
+ readonly alarm: AlarmClient;
205
+ /** Distributed lock client: host.locks.acquire(), host.locks.release() etc. */
206
+ readonly locks: LockClient;
207
+ /** Blob storage client: host.blob.upload(), host.blob.download() etc. */
208
+ readonly blob: BlobClient;
209
+ /**
210
+ * Create an ergonomic HTTP client for a named service link.
211
+ *
212
+ * The link must be pre-configured in RuntimeConfig.service_links.
213
+ * The host handles retries, circuit breaking, and auth injection.
214
+ *
215
+ * @param linkName - Service link name (e.g. "payments-api")
216
+ * @returns A {@link ServiceHttpClient} bound to that link
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const http = host.httpClient("payments-api");
221
+ * const balance = http.get("/v1/balance?account=123");
222
+ * const result = http.post("/v1/transfer", { amount: 100 });
223
+ * ```
224
+ */
225
+ httpClient(linkName: string): ServiceHttpClient;
128
226
  /** Send message to another actor (fire-and-forget) */
129
227
  send(to: string, msgType: string, payload?: unknown): string;
130
228
  /** Send request and wait for response (request-reply) */
@@ -133,12 +231,19 @@ export declare class Host {
133
231
  selfId(): string;
134
232
  /**
135
233
  * Spawn a new actor through the framework-owned actor spawn path exposed by the host.
234
+ * Returns the canonical actor ID assigned by the framework — use this ID (not actorName)
235
+ * for all subsequent ask/send/stop calls.
236
+ *
136
237
  * @param moduleRef - Actor type/module reference (must be deployed)
137
- * @param actorId - Unique ID for the new actor (empty = auto-generated ULID)
138
- * @param initConfig - Optional config passed to the new actor's init()
139
- * @returns Spawned actor ID string (may be auto-generated if actorId was empty)
238
+ * @param actorName - Requested name for the new actor. The framework forms the full canonical
239
+ * ID from this name, moduleRef, namespace and node. Pass empty string to
240
+ * let the framework auto-generate a ULID name.
241
+ * @param role - Disambiguation key used ONLY when multiple actors in the same supervisor share
242
+ * the same actor_type (moduleRef). Pass empty string when moduleRef is unique.
243
+ * @param args - Key-value init arguments forwarded to the new actor's init()
244
+ * @returns Canonical actor ID string assigned by the framework
140
245
  */
141
- spawn(moduleRef: string, actorId?: string, initConfig?: unknown): string;
246
+ spawn(moduleRef: string, actorName?: string, role?: string, args?: Record<string, string>): string;
142
247
  /** Stop an actor gracefully */
143
248
  stop(actorId: string): void;
144
249
  /** Bidirectional link */
@@ -165,14 +270,6 @@ export declare class Host {
165
270
  error(message: string): void;
166
271
  /** Get current timestamp in milliseconds */
167
272
  nowMs(): number;
168
- kvGet(key: string): string;
169
- kvPut(key: string, value: string): string;
170
- kvDelete(key: string): string;
171
- kvList(prefix: string): string;
172
- /** Retrieve a JSON value by key. Returns parsed object or null if not found. */
173
- kvGetJson<T = unknown>(key: string): T | null;
174
- /** Serialize value to JSON and store under key. Throws on write failure. */
175
- kvPutJson(key: string, value: unknown): void;
176
273
  /** Increment a single named application metric counter by 1. Errors are swallowed. */
177
274
  incrCounter(applicationId: string, name: string): void;
178
275
  /** Increment one or more named application metric counters. Errors are swallowed. */
@@ -185,13 +282,6 @@ export declare class Host {
185
282
  tsTakePayload(data: Uint8Array): Uint8Array;
186
283
  /** @internal */
187
284
  tsReadAllPayload(data: Uint8Array): Uint8Array;
188
- lockAcquire(tenantId: string, namespace: string, holderId: string, lockName: string, leaseDurationSecs?: number, timeoutMs?: number): string;
189
- lockRelease(lockId: string, tenantId: string, namespace: string, holderId: string, lockVersion: string): string;
190
- lockRenew(lockId: string, tenantId: string, namespace: string, holderId: string, lockVersion: string, leaseDurationSecs?: number): string;
191
- blobUpload(blobId: string, data: string, contentType?: string): string;
192
- blobDownload(blobId: string): string;
193
- blobDelete(blobId: string): string;
194
- blobList(prefix: string): string;
195
285
  /**
196
286
  * Checkout an actor from a named pool. Returns handle { actor_id, pool_name, checkout_id } or null on failure.
197
287
  */
@@ -269,9 +359,13 @@ export declare class EventLog {
269
359
  * The link must be pre-configured in RuntimeConfig.service_links.
270
360
  * The host handles retries, circuit breaking, and auth injection.
271
361
  *
362
+ * Prefer creating instances via {@link Host.httpClient} rather than calling
363
+ * the constructor directly:
364
+ *
272
365
  * @example
273
366
  * ```typescript
274
- * const http = new ServiceHttpClient("payments-api");
367
+ * // Preferred: use the factory method
368
+ * const http = host.httpClient("payments-api");
275
369
  * const balance = http.get("/v1/balance?account=123");
276
370
  * const result = http.post("/v1/transfer", { amount: 100 });
277
371
  * ```