toilscript 0.1.29 → 0.1.30
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 +50 -1
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.30/dist/toilscript.js",
|
|
4
|
+
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.30/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.30";
|
|
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.30/dist/toilscript.js",
|
|
5
|
+
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.30/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
|
@@ -54,6 +54,13 @@ const TOIL_DECORATORS = new Set([
|
|
|
54
54
|
'patch',
|
|
55
55
|
'head',
|
|
56
56
|
'options',
|
|
57
|
+
'database',
|
|
58
|
+
'collection',
|
|
59
|
+
'query',
|
|
60
|
+
'action',
|
|
61
|
+
'job',
|
|
62
|
+
'derive',
|
|
63
|
+
'admin',
|
|
57
64
|
'main',
|
|
58
65
|
'user',
|
|
59
66
|
'auth',
|
|
@@ -198,6 +205,47 @@ function init(modules) {
|
|
|
198
205
|
return out;
|
|
199
206
|
}
|
|
200
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Ambient declarations so the editor types each `@database` class's STATIC
|
|
210
|
+
* collection handles. The compiler injects a lazy static getter per
|
|
211
|
+
* `@collection` field (`AuthDb.users`), but the source only declares an
|
|
212
|
+
* instance type-carrier field, so stock TS reports `AuthDb.users` as
|
|
213
|
+
* TS2339. Merge a `namespace` onto the class (the standard way to add typed
|
|
214
|
+
* statics) with one `const` per collection, typed as the field's handle type
|
|
215
|
+
* (`Record<User, UserId>`, `Capacity<DropId>`, ...). Returns "" when the file
|
|
216
|
+
* declares no `@database`.
|
|
217
|
+
*/
|
|
218
|
+
function databaseAugmentation(text) {
|
|
219
|
+
if (text.indexOf('@database') < 0) return '';
|
|
220
|
+
let sf;
|
|
221
|
+
try {
|
|
222
|
+
sf = ts.createSourceFile('__toil_db_aug__.ts', text, ts.ScriptTarget.Latest, true);
|
|
223
|
+
} catch {
|
|
224
|
+
return '';
|
|
225
|
+
}
|
|
226
|
+
let out = '';
|
|
227
|
+
sf.forEachChild((node) => {
|
|
228
|
+
if (!ts.isClassDeclaration(node) || !node.name) return;
|
|
229
|
+
if (!declHasDecorator(node, 'database')) return;
|
|
230
|
+
const dbName = node.name.text;
|
|
231
|
+
// Match export-ness so the class/namespace merge is all-exported or
|
|
232
|
+
// all-local (a mismatch trips TS2395).
|
|
233
|
+
const exp = hasExportModifier(node) ? 'export ' : '';
|
|
234
|
+
let consts = '';
|
|
235
|
+
node.members.forEach((m) => {
|
|
236
|
+
if (!ts.isPropertyDeclaration(m) || !declHasDecorator(m, 'collection')) return;
|
|
237
|
+
if (!m.type || !m.name || !ts.isIdentifier(m.name)) return;
|
|
238
|
+
consts += ` const ${m.name.text}: ${m.type.getText(sf)};\n`;
|
|
239
|
+
});
|
|
240
|
+
if (consts) {
|
|
241
|
+
out +=
|
|
242
|
+
`\n// toilscript: editor types for the @database ${dbName} static collection handles\n` +
|
|
243
|
+
`${exp}declare namespace ${dbName} {\n${consts}}\n`;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
|
|
201
249
|
return {
|
|
202
250
|
create(info) {
|
|
203
251
|
const ls = info.languageService;
|
|
@@ -215,7 +263,8 @@ function init(modules) {
|
|
|
215
263
|
if (!snap) return snap;
|
|
216
264
|
let aug = '';
|
|
217
265
|
try {
|
|
218
|
-
|
|
266
|
+
const t = snap.getText(0, snap.getLength());
|
|
267
|
+
aug = dataAugmentation(t) + databaseAugmentation(t);
|
|
219
268
|
} catch {
|
|
220
269
|
aug = '';
|
|
221
270
|
}
|