@s2script/sdk 0.27.0 → 0.27.1

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/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** @s2script/config — typed access to the plugin's materialized config. NO runtime code. */
2
2
  /** A materialized config value: a scalar, or a nested section object of further values. */
3
3
  export type ConfigValue = string | number | boolean | { [k: string]: ConfigValue };
4
- /** The whole materialized config: top-level keys to {@link ConfigValue}s. Passed to `ctx.config.onChange`. */
4
+ /** The whole materialized config: top-level keys to {@link ConfigValue}s. Passed to `config.onChange` handlers. */
5
5
  export type Config = Record<string, ConfigValue>;
6
6
  /**
7
7
  * Typed access to this plugin's materialized config values (declared under `s2script.config` in the manifest).
@@ -25,7 +25,7 @@ export declare const config: {
25
25
  writeFile(name: string, content: string): void;
26
26
  /**
27
27
  * Fires when this plugin's config file is re-materialized on disk. Ledgered per plugin.
28
- * Not load-window-gated (safe from `OnPluginStart` or from `ctx.config.onChange`).
28
+ * Not load-window-gated (safe from `OnPluginStart` or from a `config.onChange` handler).
29
29
  */
30
30
  onChange(handler: (cfg: Config) => void): void;
31
31
  };
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * @example
12
12
  * import type { WorkshopService } from "@s2script/sdk/contracts/workshop";
13
- * const ws = ctx.tryUse<WorkshopService>("workshop");
13
+ * const ws = tryUse<WorkshopService>("workshop"); // in OnPluginStart
14
14
  * if (ws) {
15
15
  * const map = await ws.currentMap();
16
16
  * console.log(map ? `${map.title} (${map.id})` : "not a workshop map");
package/db.d.ts CHANGED
@@ -15,9 +15,16 @@ export interface ExecuteResult {
15
15
 
16
16
  /** A driver-owned connection — what a {@link Driver} hands back from {@link Driver.connect}. */
17
17
  export interface DriverConnection {
18
- /** Run a SELECT and resolve every result {@link Row}; `params` bind `?` placeholders. */
18
+ /**
19
+ * Run a SELECT and resolve every result {@link Row}; `params` bind `?` placeholders. Rejects
20
+ * with `AsyncQueueFull` or `AsyncPayloadTooLarge` before acceptance; `DatabaseResultTooLarge`
21
+ * when rows or retained bytes exceed the configured limit.
22
+ */
19
23
  query(sql: string, params?: SqlValue[]): Promise<Row[]>;
20
- /** Run a non-SELECT statement and resolve its {@link ExecuteResult}; `params` bind `?` placeholders. */
24
+ /**
25
+ * Run a non-SELECT statement and resolve its {@link ExecuteResult}; `params` bind `?`
26
+ * placeholders. Rejects with `AsyncQueueFull` or `AsyncPayloadTooLarge` before acceptance.
27
+ */
21
28
  execute(sql: string, params?: SqlValue[]): Promise<ExecuteResult>;
22
29
  /** Close the underlying connection. */
23
30
  close(): Promise<void>;
@@ -40,9 +47,16 @@ export interface Driver {
40
47
  }
41
48
  /** A live database connection (delegates to its driver). */
42
49
  export interface Database {
43
- /** Run a SELECT and resolve every result {@link Row}; `params` bind `?` placeholders. */
50
+ /**
51
+ * Run a SELECT and resolve every result {@link Row}; `params` bind `?` placeholders. Rejects
52
+ * with `AsyncQueueFull` or `AsyncPayloadTooLarge` before acceptance; `DatabaseResultTooLarge`
53
+ * when rows or retained bytes exceed the configured limit.
54
+ */
44
55
  query(sql: string, params?: SqlValue[]): Promise<Row[]>;
45
- /** Run a non-SELECT statement and resolve its {@link ExecuteResult}; `params` bind `?` placeholders. */
56
+ /**
57
+ * Run a non-SELECT statement and resolve its {@link ExecuteResult}; `params` bind `?`
58
+ * placeholders. Rejects with `AsyncQueueFull` or `AsyncPayloadTooLarge` before acceptance.
59
+ */
46
60
  execute(sql: string, params?: SqlValue[]): Promise<ExecuteResult>;
47
61
  /** Close the connection. */
48
62
  close(): Promise<void>;
package/events.d.ts CHANGED
@@ -67,7 +67,7 @@ export declare const Events: {
67
67
  * re-firing a rebuilt copy per viewer does not.
68
68
  *
69
69
  * @example
70
- * ctx.events.onPre("player_death", () => {
70
+ * hook.onPre("player_death", () => {
71
71
  * Events.setRecipients(traitorSlots); // only Traitors see the kill
72
72
  * return HookResult.Handled;
73
73
  * });
package/http.d.ts CHANGED
@@ -34,7 +34,9 @@ export interface Response {
34
34
  * @param url - Absolute `http(s)://` URL.
35
35
  * @param options - Method, headers, body, and timeout (see {@link FetchOptions}).
36
36
  * @returns Resolves for ANY HTTP response — a 4xx/5xx resolves with `ok=false`, it does not reject.
37
- * @throws Rejects only on a network error or timeout.
37
+ * @throws Rejects on a network error or timeout, or with `AsyncQueueFull` / `AsyncPayloadTooLarge`
38
+ * before acceptance. `HttpResponseTooLarge` when the retained UTF-8 body plus headers exceed the
39
+ * configured limit.
38
40
  * @example
39
41
  * import { fetch } from "@s2script/sdk/http";
40
42
  * const r = await fetch("https://httpbin.org/get", { timeoutMs: 15000 });
package/interfaces.d.ts CHANGED
@@ -5,7 +5,7 @@ import type { HookResultValue } from "./events";
5
5
  */
6
6
 
7
7
  /**
8
- * Handle returned by `ctx.publish(name, impl)`: lets the producer emit forwarded
8
+ * Handle returned by `publish(name, impl)`: lets the producer emit forwarded
9
9
  * events to every plugin subscribed to this interface via its `on(event, …)`.
10
10
  */
11
11
  export interface PublishHandle {
@@ -133,8 +133,10 @@ export type TypedInterfaceHandle<C> = ContractMethods<C> & {
133
133
  };
134
134
 
135
135
  /** A consumer-owned registration. Repeated disposal is a no-op. */
136
- export interface Subscription { dispose(): void; }
136
+ export interface Subscription { /** Remove this exact registration. Idempotent. */
137
+ dispose(): void; }
137
138
  /** Resources owned by one synchronous optional-provider attachment. */
138
139
  export interface AttachmentScope {
140
+ /** Return the resource and retain its disposer for this attachment. */
139
141
  own<T extends { dispose(): void }>(resource: T): T;
140
142
  }
package/menu.d.ts CHANGED
@@ -51,7 +51,6 @@ export interface MenuCancelEvent {
51
51
  * import { Menu, MenuStyle } from "@s2script/sdk/menu";
52
52
  * const m = new Menu("s2script Menu Demo");
53
53
  * m.style = MenuStyle.Center;
54
- * m.freezePlayer = true; // freeze movement while the HUD menu is open
55
54
  * m.addItem("hp", "Heal to 100");
56
55
  * m.addItem("noclip", "Toggle Noclip");
57
56
  * m.onSelect(e => { console.log(`picked ${e.info} (slot ${e.slot})`); });
@@ -65,8 +64,12 @@ export declare class Menu {
65
64
  style: MenuStyle;
66
65
  /** Append an auto Exit control (default true). */
67
66
  exitButton: boolean;
68
- /** When true, a renderer that supports it (the CS2 HUD renderer) freezes the player's movement
69
- * while the menu is open and restores it on close. Default false. */
67
+ /**
68
+ * When true, a renderer that supports it may freeze the player's movement while the menu is open
69
+ * and restore it on close. Default false. The CS2 center renderer currently ignores this and
70
+ * does not freeze movement — freezing is disabled until the menu surface can guarantee it is
71
+ * interactive. The chat renderer also ignores it.
72
+ */
70
73
  freezePlayer: boolean;
71
74
  /** `"immediate"` (default) arms cursor on open. `"tab"` paints first and waits for Tab. */
72
75
  activation: MenuActivation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s2script/sdk",
3
- "version": "0.27.0",
3
+ "version": "0.27.1",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "description": "s2script SDK — the builtin capability types (imported as @s2script/sdk/entity, …) plus the `s2s` CLI for building Source 2 / CS2 plugins.",
6
6
  "type": "module",
package/plugin.d.ts CHANGED
@@ -32,7 +32,7 @@ export interface CtxEvents {
32
32
  * Subscribe to a fired game event (post-phase). The {@link GameEvent} is valid only synchronously.
33
33
  * @example
34
34
  * // plugins/disabled/nextmap/src/plugin.ts:133
35
- * ctx.events.on("round_end", () => console.log("round ended"));
35
+ * hook.on("round_end", () => console.log("round ended"));
36
36
  */
37
37
  on(name: string, handler: (ev: GameEvent) => void): void;
38
38
  /** Pre-hook a game event: return a {@link HookResultValue} (`Handled`/`Stop` suppress the client broadcast). */
@@ -158,7 +158,7 @@ export interface CtxTranslations {
158
158
  * client's language, then English), so list your own set before any shared one if you want to be
159
159
  * able to override a shared phrase.
160
160
  *
161
- * @example ctx.translations.load("basecomm", "common");
161
+ * @example translations.load("basecomm", "common");
162
162
  */
163
163
  load(...names: string[]): void;
164
164
  }
@@ -250,7 +250,11 @@ export interface PluginContext {
250
250
  use<T extends object>(
251
251
  name: keyof InterfaceContracts extends never ? string : never
252
252
  ): InterfaceHandle<T>;
253
- /** Resolve an OPTIONAL dep (must be in `optionalPluginDependencies`); null while unpublished. */
253
+ /**
254
+ * Resolve an OPTIONAL dep (must be in `optionalPluginDependencies`); null while unpublished.
255
+ * One-shot lookup — does not track later availability. Prefer watchOptional to follow a provider
256
+ * across load and reload.
257
+ */
254
258
  tryUse<N extends keyof InterfaceContracts>(
255
259
  name: N
256
260
  ): TypedInterfaceHandle<InterfaceContracts[N]> | null;
@@ -305,10 +309,10 @@ export interface PluginHooks {
305
309
  * The {@link GameEvent} is valid only synchronously.
306
310
  */
307
311
  export declare const hook: {
308
- /** Post-phase (`ctx.events.on`). */
312
+ /** Post-phase game-event subscribe. The GameEvent is valid only synchronously. */
309
313
  on(name: string, handler: (ev: GameEvent) => void): void;
310
314
  /**
311
- * Pre-phase (`ctx.events.onPre`). Return {@link HookResultValue} `Handled`/`Stop` to suppress
315
+ * Pre-phase game-event subscribe. Return {@link HookResultValue} `Handled`/`Stop` to suppress
312
316
  * the client broadcast.
313
317
  */
314
318
  onPre(name: string, handler: (ev: GameEvent) => HookResultValue | void): void;
@@ -365,7 +369,8 @@ export declare function use<T extends object>(
365
369
  ): InterfaceHandle<T>;
366
370
  /**
367
371
  * Resolve an OPTIONAL dep (must be in `optionalPluginDependencies`); null while unpublished.
368
- * Load-window only. Same contract as {@link PluginContext.tryUse}.
372
+ * Load-window only. One-shot lookup — does not track later availability. Same contract as
373
+ * {@link PluginContext.tryUse}.
369
374
  */
370
375
  export declare function tryUse<N extends keyof InterfaceContracts>(
371
376
  name: N
@@ -383,7 +388,7 @@ export declare const topmenu: CtxTopMenu;
383
388
  /**
384
389
  * Load-window phrase-file declaration. Same contract as {@link PluginContext.translations}.
385
390
  * Throws after settle. `s2s build` / `sync-phrase-types.mjs` collect `translations.load(...)`
386
- * the same way they collect `ctx.translations.load(...)`.
391
+ * the same way they collect `translations.load(...)`.
387
392
  */
388
393
  export declare const translations: CtxTranslations;
389
394
 
package/topmenu.d.ts CHANGED
@@ -37,7 +37,7 @@ export interface TopMenuSnapshot {
37
37
  }
38
38
  /**
39
39
  * The shared admin/top-menu registry — renderers read {@link TopMenu.snapshot} and dispatch picks
40
- * through {@link TopMenu.select}; items are contributed by plugins via their own ctx.topmenu.
40
+ * through {@link TopMenu.select}; items are contributed by plugins via `topmenu`.
41
41
  * @example
42
42
  * import { TopMenu } from "@s2script/sdk/topmenu";
43
43
  * const snap = TopMenu.snapshot();
package/unsafe.d.ts CHANGED
@@ -74,7 +74,7 @@ export declare const Engine: {
74
74
  * gate (same class of reasons as {@link Engine.call}, plus a missing `validate` or an unknown
75
75
  * thunk shape). Guard once at load; the returned function records the handler and lazily
76
76
  * installs the detour. The owner is always the calling plugin — you cannot subscribe to
77
- * another plugin's hook through this factory (game-package hooks hang off `ctx.*`).
77
+ * another plugin's hook through this factory (game-package hooks are the `@s2script/cs2` exports such as `players` and `gameRules`).
78
78
  */
79
79
  hook<K extends keyof EngineHooks>(name: K): EngineHooks[K] | null;
80
80
  /** Why a hook descriptor is unavailable; `"available"` when it resolved. */
package/usercmd.d.ts CHANGED
@@ -7,16 +7,16 @@
7
7
  import type { QAngle } from "./math";
8
8
 
9
9
  /**
10
- * A block-scoped view of the CURRENT tick's usercmd (valid only during a `ctx.clients.onRunCmd`
10
+ * A block-scoped view of the CURRENT tick's usercmd (valid only during an `OnPlayerRunCmd`
11
11
  * handler — a stashed `UserCmdView` used after the handler returns, or across an `await`,
12
12
  * reads/writes nothing). There is exactly ONE `UserCmdView` instance for the whole process; every
13
13
  * handler call operates on it.
14
14
  * @example
15
15
  * import type { UserCmdView } from "@s2script/sdk/usercmd";
16
- * // examples/cookbook/src/recipes/usercmd.ts:27 — read this tick's input
17
- * ctx.clients.onRunCmd((cmd: UserCmdView, info: { slot: number }) => {
16
+ * // read this tick's input
17
+ * export function OnPlayerRunCmd(cmd: UserCmdView, info: { slot: number }): void {
18
18
  * console.log(`slot=${info.slot} fwd=${cmd.forwardMove} btn=${cmd.buttons}`);
19
- * });
19
+ * }
20
20
  */
21
21
  export interface UserCmdView {
22
22
  /** +forward / -back. Normalized to roughly [-1, 1] (not the legacy ±450 units). */
package/ws.d.ts CHANGED
@@ -9,7 +9,10 @@ export interface WebSocket {
9
9
  /** Register a handler for a transport error; `err` is the error text. */
10
10
  onError(handler: (err: string) => void): void;
11
11
  /** Send a text frame. */
12
- /** Returns false if closed, oversized, or the connection/global outbound budget is full. */
12
+ /**
13
+ * Send a text frame. Returns false if closed, oversized, or the connection/global outbound
14
+ * budget is full.
15
+ */
13
16
  send(data: string): boolean;
14
17
  /** Close the connection. */
15
18
  close(): void;