toilscript 0.1.25 → 0.1.27

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.25/dist/toilscript.js",
4
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.25/dist/cli.js",
3
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.27/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.27/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
  }
package/dist/web.js CHANGED
@@ -1,8 +1,8 @@
1
- var ASSEMBLYSCRIPT_VERSION = "0.1.25";
1
+ var ASSEMBLYSCRIPT_VERSION = "0.1.27";
2
2
  var ASSEMBLYSCRIPT_IMPORTMAP = {
3
3
  "imports": {
4
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.25/dist/toilscript.js",
5
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.25/dist/cli.js",
4
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.27/dist/toilscript.js",
5
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.27/dist/cli.js",
6
6
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@129.0.0-nightly.20260428/index.js",
7
7
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
8
8
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "toilscript",
9
9
  "wasm"
10
10
  ],
11
- "version": "0.1.25",
11
+ "version": "0.1.27",
12
12
  "author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
13
13
  "license": "Apache-2.0",
14
14
  "homepage": "https://github.com/dacely-cloud/toilscript",
@@ -72,8 +72,11 @@ declare function options(path: string): ToilRouteDecorator;
72
72
  /** Cache a route's response: `@cache(edgeMinutes, browserSeconds?, privateScope?, allowAuth?)`. */
73
73
  declare function cache(edgeMinutes: i32, browserSeconds?: i32, privateScope?: bool, allowAuth?: bool): ToilRouteDecorator;
74
74
 
75
- /** Rate-limit a route: `@ratelimit(strategy, limit, window)` (strategy = a `RateLimit` member). */
76
- declare function ratelimit(strategy: i32, limit: i32, window: i32): ToilRouteDecorator;
75
+ /** Rate-limiting strategy for `@ratelimit`. Values match the runtime `RateLimit` enum. */
76
+ declare enum RateLimit { FixedWindow, SlidingWindow, TokenBucket }
77
+
78
+ /** Rate-limit a route: `@ratelimit(strategy, limit, window)`. */
79
+ declare function ratelimit(strategy: RateLimit, limit: i32, window: i32): ToilRouteDecorator;
77
80
 
78
81
  /** Require a valid session for a `@rest` class or route method (`@auth`). 401 otherwise. */
79
82
  declare function auth(target: Function): void;
package/std/ts-plugin.cjs CHANGED
@@ -125,6 +125,18 @@ function init(modules) {
125
125
  );
126
126
  }
127
127
 
128
+ /** True when a declaration carries an `export` modifier. The appended codec
129
+ * augmentation must match the class's export-ness, else merging the class with
130
+ * the synthesized `interface`/`namespace` trips TS2395 ("must be all exported
131
+ * or all local"). */
132
+ function hasExportModifier(node) {
133
+ const mods =
134
+ (ts.getModifiers && ts.canHaveModifiers && ts.canHaveModifiers(node)
135
+ ? ts.getModifiers(node)
136
+ : node.modifiers) || [];
137
+ return mods.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
138
+ }
139
+
128
140
  /** True when the parsed file is an ES module (has a top-level import/export), so
129
141
  * a global augmentation must be wrapped in `declare global { ... }`. */
130
142
  function isModuleFile(sf) {
@@ -164,11 +176,14 @@ function init(modules) {
164
176
  const isUser = declHasDecorator(node, 'user');
165
177
  if (!declHasDecorator(node, 'data') && !isUser) return;
166
178
  const n = node.name.text;
179
+ // Match the class's export-ness so the class/interface/namespace merge is all
180
+ // exported or all local (an exported class + local augmentation -> TS2395).
181
+ const exp = hasExportModifier(node) ? 'export ' : '';
167
182
  // Both `@data` and `@user` classes get the compiler-injected binary codec.
168
183
  out +=
169
184
  `\n// toilscript: editor types for the compiler-injected ${isUser ? '@user' : '@data'} ${n} codec\n` +
170
- `interface ${n} { encode(): Uint8Array; toJSON(): JSON; }\n` +
171
- `declare namespace ${n} { function decode(buf: Uint8Array): ${n}; function fromJSON(v: JSON): ${n}; function dataId(): u32; }\n`;
185
+ `${exp}interface ${n} { encode(): Uint8Array; toJSON(): JSON; }\n` +
186
+ `${exp}declare namespace ${n} { function decode(buf: Uint8Array): ${n}; function fromJSON(v: JSON): ${n}; function dataId(): u32; }\n`;
172
187
  // The single `@user` class is also the type of `AuthService.getUser()`
173
188
  // everywhere: merge it into the global `__ToilAuthUser` interface that the
174
189
  // generated env d.ts returns from `getUser()`. `declare global` when the