toilscript 0.1.44 → 0.1.45

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "imports": {
3
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.44/dist/toilscript.js",
4
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.44/dist/cli.js",
3
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.45/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.45/dist/cli.js",
5
5
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@130.0.0-nightly.20260609/index.js",
6
6
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
7
7
  }
@@ -2972,6 +2972,8 @@ declare module "types:toilscript/src/parser" {
2972
2972
  dependees: Map<string, Dependee>;
2973
2973
  /** Normalized paths whose `@rest` runtime import has already been injected. */
2974
2974
  restImportedSources: Set<string>;
2975
+ /** Normalized paths whose `@service`/`@remote` RPC runtime import has already been injected. */
2976
+ rpcImportedSources: Set<string>;
2975
2977
  /** Normalized paths whose `@stream` module-level registry + the single
2976
2978
  * `stream_dispatch` export have already been emitted (a project may declare
2977
2979
  * several `@stream` classes, but the export is emitted exactly once). */
@@ -3105,6 +3107,41 @@ declare module "types:toilscript/src/parser" {
3105
3107
  * return; plus a module-level self-registration into the runtime `Rest` router.
3106
3108
  */
3107
3109
  private injectRestController;
3110
+ /**
3111
+ * Wire a `@service` class's `@remote` methods onto the global `Rpc` registry - the RPC mirror of
3112
+ * `injectRestController`. Each method becomes an id-matched arm of a synthesized
3113
+ * `__rpcDispatch(__id, __body)`: decode the positional args from the body, call the method on a FRESH
3114
+ * instance (stateless, exactly like a `@rest` controller), encode the result. The id is FNV-1a of
3115
+ * `"Class.method"` - the identical hash the generated client sends in the `toil-rpc` header, so the
3116
+ * wire matches without the two sides sharing state. `DataReader`/`DataWriter` are ambient (std).
3117
+ */
3118
+ private injectService;
3119
+ /** True if a return type node is `void` (no result is encoded). */
3120
+ private rpcIsVoid;
3121
+ /** AS statements decoding one RPC arg of `typeNode` from `__r` into a fresh const `dest` (mirrors the
3122
+ * per-field decode in `injectDataCodec`: length-prefixed array, raw bytes, or scalar/@data). */
3123
+ private rpcDecodeArg;
3124
+ /** AS statements encoding the result `src` of `typeNode` into `__w`; `void` -> "" (mirrors the
3125
+ * per-field encode in `injectDataCodec`). */
3126
+ private rpcEncodeResult;
3127
+ /**
3128
+ * Wire `@service` classes and free `@remote` functions onto the global `Rpc` registry. Runs ONCE
3129
+ * before element creation (via `weaveDataMigrations`). `@service` could be done at parse time, but
3130
+ * folding both here gives a SINGLE place to honor the `@stream` gating: a project using `@stream`
3131
+ * cannot declare `@service`/`@remote` (the 9003 diagnostic fires at element creation), so we must not
3132
+ * half-inject first or the build crashes instead of reporting it.
3133
+ */
3134
+ private weaveRpc;
3135
+ /** Reject duplicate client-facing `Server` keys (two @services lowercasing to the same key, a free
3136
+ * @remote shadowing a @service / the reserved REST / Stream) and FNV method-id collisions, before the
3137
+ * surface is emitted - else the generated `Server` object/type silently overwrites a key, or a collided
3138
+ * id routes to the wrong method at dispatch. */
3139
+ private checkRpcSurfaceCollisions;
3140
+ /** True if the program declares any `@stream` class (gates the RPC weave; see diagnostic 9003). */
3141
+ private projectHasStream;
3142
+ /** Inject the RPC dispatch fn + its registration for one free `@remote` function (id = FNV of the
3143
+ * bare function name, matching the generated client). */
3144
+ private injectRemote;
3108
3145
  /**
3109
3146
  * Synthesize the cold-artifact daemon entry for a `@daemon` class (spec 03
3110
3147
  * sections 5.2 / 5.6 / 5.7, Reconciliation Part 2 cold exports). Mirrors
@@ -3152,8 +3189,8 @@ declare module "types:toilscript/src/parser" {
3152
3189
  * order), switches on `event_kind` (1 connect / 2 message / 3 close /
3153
3190
  * 4 disconnect, the FIXED Part 2 ABI values), and returns the hook's
3154
3191
  * packed-i64 result (0 = no output / accept; a negative value is the
3155
- * Part 3 reject/error bridge, wired with the real ring/StreamOutbound
3156
- * runtime in a later increment).
3192
+ * Part 3 reject/error bridge `-(0x10000 + 0x02xx)`, lowered through the
3193
+ * real ring/StreamOutbound runtime via `__encode`).
3157
3194
  *
3158
3195
  * Each `@stream` class keeps its own MODULE-SINGLETON instance (a resident
3159
3196
  * per-connection box): the dispatch thunk constructs it on first use and REUSES
@@ -3181,13 +3218,14 @@ declare module "types:toilscript/src/parser" {
3181
3218
  *
3182
3219
  * Only hooks the class actually declares get a dispatch arm; an event for an
3183
3220
  * absent hook falls through to `return 0` (a no-op success per the contract,
3184
- * never a crash). A hook that declares parameters (the typed `@message`
3185
- * `@data` arg, or a `StreamInbound`/`StreamPacket` view) is given a no-op arm
3186
- * here too: the `StreamInbound`/`StreamPacket`/`StreamOutbound` runtime + the
3187
- * ingress-ring read are owned by toiljs (spec 5.4) and land in a later
3188
- * increment, so this self-contained shim cannot synthesize those argument
3189
- * values yet; calling a zero-arg hook directly is the part that compiles and
3190
- * runs today (every gating/catalog fixture uses the zero-arg/void hook form).
3221
+ * never a crash). Param'd hooks are fully wired through the injected ring
3222
+ * runtime (`streamRuntimeSource`): `@connect(StreamInbound)` reads the host's
3223
+ * connect-info block, `@message(StreamPacket)` drains the raw ingress frame, and
3224
+ * `@message(MessageType)` decodes the frame into the `@data` class declared by
3225
+ * `@stream({ message: MessageType })` (doc 03 2.5); each may reply with a
3226
+ * `StreamOutbound` (lowered via `__encode`) or return `void`. An unrecognized
3227
+ * `@message` / `@connect` signature is a hard error (9015 / 9014), never a
3228
+ * silent no-op.
3191
3229
  *
3192
3230
  * Fires the 9013 warning for a `@stream` class with zero lifecycle hooks (a
3193
3231
  * hookless stream can never receive traffic), mirroring the daemon 9008 warning
@@ -4564,6 +4602,21 @@ declare module "types:toilscript/src/dbcatalog" {
4564
4602
  * str route_pattern (same normalized pattern emitted into __toilMatch)
4565
4603
  */
4566
4604
  export function buildToilDbRouteKinds(program: Program): Uint8Array | null;
4605
+ /** Build the `toildb.rpc_kinds` section bytes, or `null` when no @remote needs the Action upgrade.
4606
+ * Unlike `route_kinds` (a DOWNGRADE list of explicit `@query` routes, with POST defaulting to Action),
4607
+ * an RPC method has no HTTP-method signal and defaults to READ-ONLY (Query). This section is therefore
4608
+ * the inverse - an UPGRADE list: the FNV ids of the `@action` `@remote`s the runtime must let WRITE.
4609
+ * Everything else (a plain `@remote` or an explicit `@query`) stays Query, so a read-only RPC can never
4610
+ * silently mutate the DB.
4611
+ *
4612
+ * Wire format (LE):
4613
+ * u16 format_version = 1
4614
+ * u16 n_methods
4615
+ * per method:
4616
+ * u32 method_id (FNV-1a of "ClassName.methodName" or "fnName", the `toil-rpc` header id)
4617
+ * u8 function_kind (1 = Action)
4618
+ */
4619
+ export function buildToilDbRpcKinds(program: Program): Uint8Array | null;
4567
4620
  /** Build the `toilstream.catalog` section bytes, or `null` if the program
4568
4621
  * declares no `@stream` class. Per Part 5 (LE):
4569
4622
  *