toilscript 0.1.44 → 0.1.46

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.46/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.46/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
  }
@@ -609,7 +609,9 @@ declare module "types:toilscript/src/diagnosticMessages.generated" {
609
609
  Scheduled_handler_0_must_take_no_arguments_and_return_void = 9012,
610
610
  Stream_scope_must_be_a_StreamScope_enum_member = 9013,
611
611
  Stream_connect_handler_0_has_an_invalid_signature = 9014,
612
- Stream_message_handler_0_has_an_invalid_signature = 9015
612
+ Stream_message_handler_0_has_an_invalid_signature = 9015,
613
+ Stream_close_handler_0_has_an_invalid_signature = 9016,
614
+ Stream_disconnect_handler_0_has_an_invalid_signature = 9017
613
615
  }
614
616
  /** Translates a diagnostic code to its respective string. */
615
617
  export function diagnosticCodeToString(code: DiagnosticCode): string;
@@ -2972,6 +2974,8 @@ declare module "types:toilscript/src/parser" {
2972
2974
  dependees: Map<string, Dependee>;
2973
2975
  /** Normalized paths whose `@rest` runtime import has already been injected. */
2974
2976
  restImportedSources: Set<string>;
2977
+ /** Normalized paths whose `@service`/`@remote` RPC runtime import has already been injected. */
2978
+ rpcImportedSources: Set<string>;
2975
2979
  /** Normalized paths whose `@stream` module-level registry + the single
2976
2980
  * `stream_dispatch` export have already been emitted (a project may declare
2977
2981
  * several `@stream` classes, but the export is emitted exactly once). */
@@ -3105,6 +3109,41 @@ declare module "types:toilscript/src/parser" {
3105
3109
  * return; plus a module-level self-registration into the runtime `Rest` router.
3106
3110
  */
3107
3111
  private injectRestController;
3112
+ /**
3113
+ * Wire a `@service` class's `@remote` methods onto the global `Rpc` registry - the RPC mirror of
3114
+ * `injectRestController`. Each method becomes an id-matched arm of a synthesized
3115
+ * `__rpcDispatch(__id, __body)`: decode the positional args from the body, call the method on a FRESH
3116
+ * instance (stateless, exactly like a `@rest` controller), encode the result. The id is FNV-1a of
3117
+ * `"Class.method"` - the identical hash the generated client sends in the `toil-rpc` header, so the
3118
+ * wire matches without the two sides sharing state. `DataReader`/`DataWriter` are ambient (std).
3119
+ */
3120
+ private injectService;
3121
+ /** True if a return type node is `void` (no result is encoded). */
3122
+ private rpcIsVoid;
3123
+ /** AS statements decoding one RPC arg of `typeNode` from `__r` into a fresh const `dest` (mirrors the
3124
+ * per-field decode in `injectDataCodec`: length-prefixed array, raw bytes, or scalar/@data). */
3125
+ private rpcDecodeArg;
3126
+ /** AS statements encoding the result `src` of `typeNode` into `__w`; `void` -> "" (mirrors the
3127
+ * per-field encode in `injectDataCodec`). */
3128
+ private rpcEncodeResult;
3129
+ /**
3130
+ * Wire `@service` classes and free `@remote` functions onto the global `Rpc` registry. Runs ONCE
3131
+ * before element creation (via `weaveDataMigrations`). `@service` could be done at parse time, but
3132
+ * folding both here gives a SINGLE place to honor the `@stream` gating: a project using `@stream`
3133
+ * cannot declare `@service`/`@remote` (the 9003 diagnostic fires at element creation), so we must not
3134
+ * half-inject first or the build crashes instead of reporting it.
3135
+ */
3136
+ private weaveRpc;
3137
+ /** Reject duplicate client-facing `Server` keys (two @services lowercasing to the same key, a free
3138
+ * @remote shadowing a @service / the reserved REST / Stream) and FNV method-id collisions, before the
3139
+ * surface is emitted - else the generated `Server` object/type silently overwrites a key, or a collided
3140
+ * id routes to the wrong method at dispatch. */
3141
+ private checkRpcSurfaceCollisions;
3142
+ /** True if the program declares any `@stream` class (gates the RPC weave; see diagnostic 9003). */
3143
+ private projectHasStream;
3144
+ /** Inject the RPC dispatch fn + its registration for one free `@remote` function (id = FNV of the
3145
+ * bare function name, matching the generated client). */
3146
+ private injectRemote;
3108
3147
  /**
3109
3148
  * Synthesize the cold-artifact daemon entry for a `@daemon` class (spec 03
3110
3149
  * sections 5.2 / 5.6 / 5.7, Reconciliation Part 2 cold exports). Mirrors
@@ -3152,8 +3191,8 @@ declare module "types:toilscript/src/parser" {
3152
3191
  * order), switches on `event_kind` (1 connect / 2 message / 3 close /
3153
3192
  * 4 disconnect, the FIXED Part 2 ABI values), and returns the hook's
3154
3193
  * 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).
3194
+ * Part 3 reject/error bridge `-(0x10000 + 0x02xx)`, lowered through the
3195
+ * real ring/StreamOutbound runtime via `__encode`).
3157
3196
  *
3158
3197
  * Each `@stream` class keeps its own MODULE-SINGLETON instance (a resident
3159
3198
  * per-connection box): the dispatch thunk constructs it on first use and REUSES
@@ -3181,13 +3220,14 @@ declare module "types:toilscript/src/parser" {
3181
3220
  *
3182
3221
  * Only hooks the class actually declares get a dispatch arm; an event for an
3183
3222
  * 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).
3223
+ * never a crash). Param'd hooks are fully wired through the injected ring
3224
+ * runtime (`streamRuntimeSource`): `@connect(StreamInbound)` reads the host's
3225
+ * connect-info block, `@message(StreamPacket)` drains the raw ingress frame, and
3226
+ * `@message(MessageType)` decodes the frame into the `@data` class declared by
3227
+ * `@stream({ message: MessageType })` (doc 03 2.5); each may reply with a
3228
+ * `StreamOutbound` (lowered via `__encode`) or return `void`. An unrecognized
3229
+ * `@message` / `@connect` signature is a hard error (9015 / 9014), never a
3230
+ * silent no-op.
3191
3231
  *
3192
3232
  * Fires the 9013 warning for a `@stream` class with zero lifecycle hooks (a
3193
3233
  * hookless stream can never receive traffic), mirroring the daemon 9008 warning
@@ -4564,6 +4604,21 @@ declare module "types:toilscript/src/dbcatalog" {
4564
4604
  * str route_pattern (same normalized pattern emitted into __toilMatch)
4565
4605
  */
4566
4606
  export function buildToilDbRouteKinds(program: Program): Uint8Array | null;
4607
+ /** Build the `toildb.rpc_kinds` section bytes, or `null` when no @remote needs the Action upgrade.
4608
+ * Unlike `route_kinds` (a DOWNGRADE list of explicit `@query` routes, with POST defaulting to Action),
4609
+ * an RPC method has no HTTP-method signal and defaults to READ-ONLY (Query). This section is therefore
4610
+ * the inverse - an UPGRADE list: the FNV ids of the `@action` `@remote`s the runtime must let WRITE.
4611
+ * Everything else (a plain `@remote` or an explicit `@query`) stays Query, so a read-only RPC can never
4612
+ * silently mutate the DB.
4613
+ *
4614
+ * Wire format (LE):
4615
+ * u16 format_version = 1
4616
+ * u16 n_methods
4617
+ * per method:
4618
+ * u32 method_id (FNV-1a of "ClassName.methodName" or "fnName", the `toil-rpc` header id)
4619
+ * u8 function_kind (1 = Action)
4620
+ */
4621
+ export function buildToilDbRpcKinds(program: Program): Uint8Array | null;
4567
4622
  /** Build the `toilstream.catalog` section bytes, or `null` if the program
4568
4623
  * declares no `@stream` class. Per Part 5 (LE):
4569
4624
  *
@@ -4575,8 +4630,8 @@ declare module "types:toilscript/src/dbcatalog" {
4575
4630
  * u8 hook_presence_bitmask (bit0 connect..bit3 disconnect)
4576
4631
  * u8 declared_scope (0 regional/L2, 1 continental/L3)
4577
4632
  * u8 message_mode (0 raw, 1 @data-typed)
4578
- * u32 max_frame_bytes (0 = use plan default)
4579
- * u32 ingress_ring_bytes (0 = host chooses)
4633
+ * u32 max_frame_bytes (RESERVED: parsed, not yet consumed; the runtime ignores it)
4634
+ * u32 ingress_ring_bytes (RESERVED: parsed, not yet consumed; the runtime ignores it)
4580
4635
  * u32 message_value_data_id (fnv1a(typeName); 0 when raw)
4581
4636
  * u32 message_schema_version (recursive layoutHash; 0 when raw)
4582
4637
  * u16 stream_index (0-based position in this array)