toilscript 0.1.9 → 0.1.11

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.9/dist/toilscript.js",
4
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.9/dist/cli.js",
3
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.11/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.11/dist/cli.js",
5
5
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@129.0.0-nightly.20260428/index.js",
6
6
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
7
7
  }
@@ -2952,6 +2952,8 @@ declare module "types:toilscript/src/parser" {
2952
2952
  currentSource: Source | null;
2953
2953
  /** Map of dependees being depended upon by a source, by path. */
2954
2954
  dependees: Map<string, Dependee>;
2955
+ /** Normalized paths whose `@rest` runtime import has already been injected. */
2956
+ restImportedSources: Set<string>;
2955
2957
  /** An array of parsed sources. */
2956
2958
  sources: Source[];
2957
2959
  /** Current overridden module name. */
@@ -3002,6 +3004,39 @@ declare module "types:toilscript/src/parser" {
3002
3004
  private injectDataCodec;
3003
3005
  /** Parse a synthesized member from source text and append it to the class. */
3004
3006
  private injectClassMember;
3007
+ /** Parse synthesized top-level statements and append them to the class's source. */
3008
+ private injectTopLevelStatements;
3009
+ /**
3010
+ * Synthesize the HTTP dispatcher for a `@rest` controller: a `__tryRoute`
3011
+ * method that, per `@route`/`@get`/... method, matches the HTTP method + the
3012
+ * prefix-joined path (capturing `:params`), decodes the `@data` body for the
3013
+ * route's stream, invokes the handler, and encodes the `@data` (or `Response`)
3014
+ * return; plus a module-level self-registration into the runtime `Rest` router.
3015
+ */
3016
+ private injectRestController;
3017
+ /** The mount prefix from `@rest("api")` -> "/api"; "" for the bare/object form (root). */
3018
+ private restPrefixOf;
3019
+ /** The class-default stream from `@rest({ stream: DataStream.Binary })`, else "JSON". */
3020
+ private restStreamOf;
3021
+ /** The `@route`/`@get`/... decorator on a method, or null if it isn't a route. */
3022
+ private routeDecoratorOf;
3023
+ /** Generate one `if (method && path-match) { decode; call; encode }` route block. */
3024
+ private buildRouteBlock;
3025
+ /** Find an object-literal field value by name, or null. */
3026
+ private objectField;
3027
+ /** The member of an enum access expression (`Methods.GET` -> "GET"), or null. */
3028
+ private enumMember;
3029
+ /** The HTTP method name carried by a verb decorator kind. */
3030
+ private verbName;
3031
+ /** The runtime `Method` enum value for an HTTP method name, or -1 if unknown. */
3032
+ private methodEnumValue;
3033
+ /** Join a mount prefix and a route path into the matcher pattern. */
3034
+ private joinPath;
3035
+ /**
3036
+ * The module specifier to import the REST runtime from: reuse whatever path
3037
+ * this controller already imports a runtime symbol from, else the default.
3038
+ */
3039
+ private restRuntimePath;
3005
3040
  parseClassExpression(tn: Tokenizer): ClassExpression | null;
3006
3041
  parseClassMember(tn: Tokenizer, parent: ClassDeclaration): Node | null;
3007
3042
  parseIndexSignature(tn: Tokenizer, flags: CommonFlags, decorators: DecoratorNode[] | null): IndexSignatureNode | null;
@@ -3501,7 +3536,11 @@ declare module "types:toilscript/src/program" {
3501
3536
  /** Is a `@remote` client-callable function (RPC endpoint). */
3502
3537
  Remote = 16384,
3503
3538
  /** Is a `@service` class that namespaces `@remote` methods. */
3504
- Service = 32768
3539
+ Service = 32768,
3540
+ /** Is a `@rest` HTTP controller class. */
3541
+ Rest = 65536,
3542
+ /** Is a `@route`/`@get`/`@post`/... HTTP route method. */
3543
+ Route = 131072
3505
3544
  }
3506
3545
  export namespace DecoratorFlags {
3507
3546
  /** Translates a decorator kind to the respective decorator flag. */
@@ -7219,6 +7258,7 @@ declare module "types:toilscript/src/module" {
7219
7258
  createRelooper(): number;
7220
7259
  /** Makes a copy of a trivial expression (doesn't contain subexpressions). Returns `0` if non-trivial. */
7221
7260
  tryCopyTrivialExpression(expr: ExpressionRef): ExpressionRef;
7261
+ isTrivialExpression(expr: ExpressionRef): boolean;
7222
7262
  /** Makes a copy of any expression including all subexpressions. */
7223
7263
  copyExpression(expr: ExpressionRef): ExpressionRef;
7224
7264
  runExpression(expr: ExpressionRef, flags: ExpressionRunnerFlags, maxDepth?: number, maxLoopIterations?: number): ExpressionRef;
@@ -7720,7 +7760,16 @@ declare module "types:toilscript/src/ast" {
7720
7760
  Main = 14,
7721
7761
  Data = 15,
7722
7762
  Remote = 16,
7723
- Service = 17
7763
+ Service = 17,
7764
+ Rest = 18,
7765
+ Route = 19,
7766
+ Get = 20,
7767
+ Post = 21,
7768
+ Put = 22,
7769
+ Delete = 23,
7770
+ Patch = 24,
7771
+ Head = 25,
7772
+ Options = 26
7724
7773
  }
7725
7774
  export namespace DecoratorKind {
7726
7775
  /** Returns the kind of the specified decorator name node. Defaults to {@link DecoratorKind.CUSTOM}. */