toilscript 0.1.24 → 0.1.25
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/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/importmap.json +2 -2
- package/dist/web.js +3 -3
- package/package.json +1 -1
- package/std/ts-plugin.cjs +51 -9
package/dist/importmap.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"imports": {
|
|
3
|
-
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
4
|
-
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
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",
|
|
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.
|
|
1
|
+
var ASSEMBLYSCRIPT_VERSION = "0.1.25";
|
|
2
2
|
var ASSEMBLYSCRIPT_IMPORTMAP = {
|
|
3
3
|
"imports": {
|
|
4
|
-
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
5
|
-
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
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",
|
|
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
package/std/ts-plugin.cjs
CHANGED
|
@@ -33,6 +33,13 @@ const DATA_MEMBERS = new Set([
|
|
|
33
33
|
'dataId',
|
|
34
34
|
]);
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Decorators whose class carries the compiler-injected `@data` binary codec.
|
|
38
|
+
* `@user` is `@data` plus the auth-user registration (it also types
|
|
39
|
+
* `AuthService.getUser()`); both get the same codec members.
|
|
40
|
+
*/
|
|
41
|
+
const CODEC_DECORATORS = new Set(['data', 'user']);
|
|
42
|
+
|
|
36
43
|
/** Toil-native decorators whose presence means the compiler uses the declaration. */
|
|
37
44
|
const TOIL_DECORATORS = new Set([
|
|
38
45
|
'data',
|
|
@@ -48,6 +55,10 @@ const TOIL_DECORATORS = new Set([
|
|
|
48
55
|
'head',
|
|
49
56
|
'options',
|
|
50
57
|
'main',
|
|
58
|
+
'user',
|
|
59
|
+
'auth',
|
|
60
|
+
'cache',
|
|
61
|
+
'ratelimit',
|
|
51
62
|
'global',
|
|
52
63
|
'inline',
|
|
53
64
|
'external',
|
|
@@ -90,7 +101,7 @@ function init(modules) {
|
|
|
90
101
|
function declsAreDataClass(declarations) {
|
|
91
102
|
return (
|
|
92
103
|
!!declarations &&
|
|
93
|
-
declarations.some((d) => ts.isClassDeclaration(d) && declHasDecorator(d,
|
|
104
|
+
declarations.some((d) => ts.isClassDeclaration(d) && declHasDecorator(d, CODEC_DECORATORS))
|
|
94
105
|
);
|
|
95
106
|
}
|
|
96
107
|
|
|
@@ -114,28 +125,59 @@ function init(modules) {
|
|
|
114
125
|
);
|
|
115
126
|
}
|
|
116
127
|
|
|
128
|
+
/** True when the parsed file is an ES module (has a top-level import/export), so
|
|
129
|
+
* a global augmentation must be wrapped in `declare global { ... }`. */
|
|
130
|
+
function isModuleFile(sf) {
|
|
131
|
+
const modsOf = (n) =>
|
|
132
|
+
(ts.getModifiers && ts.canHaveModifiers && ts.canHaveModifiers(n)
|
|
133
|
+
? ts.getModifiers(n)
|
|
134
|
+
: n.modifiers) || [];
|
|
135
|
+
return sf.statements.some(
|
|
136
|
+
(s) =>
|
|
137
|
+
ts.isImportDeclaration(s) ||
|
|
138
|
+
ts.isImportEqualsDeclaration(s) ||
|
|
139
|
+
ts.isExportDeclaration(s) ||
|
|
140
|
+
ts.isExportAssignment(s) ||
|
|
141
|
+
modsOf(s).some((m) => m.kind === ts.SyntaxKind.ExportKeyword),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
117
145
|
/**
|
|
118
|
-
* Ambient declarations to append so the editor types each `@data` class's
|
|
119
|
-
* codec members
|
|
146
|
+
* Ambient declarations to append so the editor types each `@data`/`@user` class's
|
|
147
|
+
* injected codec members, plus the project-wide type of `AuthService.getUser()`
|
|
148
|
+
* (the single `@user` class). Returns "" when the file declares neither. Uses only
|
|
120
149
|
* editor-visible globals (`Uint8Array`, `JSON`, `u32`), so the appended block is
|
|
121
150
|
* itself error-free; any diagnostics there are filtered anyway.
|
|
122
151
|
*/
|
|
123
152
|
function dataAugmentation(text) {
|
|
124
|
-
if (text.indexOf('@data') < 0) return '';
|
|
153
|
+
if (text.indexOf('@data') < 0 && text.indexOf('@user') < 0) return '';
|
|
125
154
|
let sf;
|
|
126
155
|
try {
|
|
127
156
|
sf = ts.createSourceFile('__toil_aug__.ts', text, ts.ScriptTarget.Latest, true);
|
|
128
157
|
} catch {
|
|
129
158
|
return '';
|
|
130
159
|
}
|
|
160
|
+
const moduleScoped = isModuleFile(sf);
|
|
131
161
|
let out = '';
|
|
132
162
|
sf.forEachChild((node) => {
|
|
133
|
-
if (ts.isClassDeclaration(node)
|
|
134
|
-
|
|
163
|
+
if (!ts.isClassDeclaration(node) || !node.name) return;
|
|
164
|
+
const isUser = declHasDecorator(node, 'user');
|
|
165
|
+
if (!declHasDecorator(node, 'data') && !isUser) return;
|
|
166
|
+
const n = node.name.text;
|
|
167
|
+
// Both `@data` and `@user` classes get the compiler-injected binary codec.
|
|
168
|
+
out +=
|
|
169
|
+
`\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`;
|
|
172
|
+
// The single `@user` class is also the type of `AuthService.getUser()`
|
|
173
|
+
// everywhere: merge it into the global `__ToilAuthUser` interface that the
|
|
174
|
+
// generated env d.ts returns from `getUser()`. `declare global` when the
|
|
175
|
+
// file is a module (else a bare interface, already global in a script).
|
|
176
|
+
if (isUser) {
|
|
177
|
+
const merge = `interface __ToilAuthUser extends ${n} {}`;
|
|
135
178
|
out +=
|
|
136
|
-
|
|
137
|
-
`
|
|
138
|
-
`declare namespace ${n} { function decode(buf: Uint8Array): ${n}; function fromJSON(v: JSON): ${n}; function dataId(): u32; }\n`;
|
|
179
|
+
`// toilscript: editor type for AuthService.getUser() (the @user ${n})\n` +
|
|
180
|
+
(moduleScoped ? `declare global { ${merge} }\n` : `${merge}\n`);
|
|
139
181
|
}
|
|
140
182
|
});
|
|
141
183
|
return out;
|