@makano/rew 1.2.57 → 1.2.59
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/rew/cli/cli.js +33 -5
- package/lib/rew/cli/utils.js +29 -6
- package/lib/rew/const/default.js +2 -1
- package/lib/rew/const/opt.js +3 -1
- package/lib/rew/const/usage.js +3 -0
- package/lib/rew/functions/import.js +8 -3
- package/lib/rew/functions/stdout.js +4 -0
- package/lib/rew/modules/compiler.js +23 -6
- package/lib/rew/modules/runtime.js +30 -13
- package/package.json +5 -3
- package/runtime.d.ts +91 -55
package/lib/rew/cli/cli.js
CHANGED
@@ -5,7 +5,7 @@ const path = require('path');
|
|
5
5
|
const { hideBin } = require('yargs/helpers');
|
6
6
|
const { execSync } = require('child_process');
|
7
7
|
const utils = require('./utils');
|
8
|
-
const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } = require('fs');
|
8
|
+
const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync, unlinkSync } = require('fs');
|
9
9
|
const { log } = require('./log');
|
10
10
|
const os = require('os');
|
11
11
|
const crypto = require('crypto');
|
@@ -18,6 +18,7 @@ const colors = require('colors');
|
|
18
18
|
const { req } = require('../misc/req');
|
19
19
|
const { gen_key } = require('../misc/bin');
|
20
20
|
const { REW_FILE_TYPE } = require('../const/ext');
|
21
|
+
const { generateRandomID } = require('../functions/id');
|
21
22
|
|
22
23
|
if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH + '/repos.yaml')) {
|
23
24
|
mkdirSync(CONFIG_PATH, { recursive: true });
|
@@ -62,9 +63,36 @@ yargs(hideBin(process.argv))
|
|
62
63
|
log('File not found:'.red.bold, argv.file, ':end');
|
63
64
|
return;
|
64
65
|
}
|
65
|
-
utils.runFileWithArgv(filePath, { onlyCompile: argv.compile, watch: argv.watch });
|
66
|
+
utils.runFileWithArgv(filePath, { async: !process.stdin.isTTY, onlyCompile: argv.compile, watch: argv.watch });
|
66
67
|
},
|
67
68
|
)
|
69
|
+
.command(
|
70
|
+
'exec [code]',
|
71
|
+
'Executes in REPL',
|
72
|
+
(yargs) => {
|
73
|
+
yargs
|
74
|
+
.option('compile', {
|
75
|
+
alias: 'c',
|
76
|
+
describe: 'Compile and output the javascript',
|
77
|
+
type: 'boolean',
|
78
|
+
});
|
79
|
+
},
|
80
|
+
async (argv) => {
|
81
|
+
const replFile = '/tmp/rew-'+generateRandomID()+'-'+Date.now()+'.coffee';
|
82
|
+
let code = argv.code;
|
83
|
+
if(!process.stdin.isTTY) {
|
84
|
+
code = await utils.getAllPipeInput();
|
85
|
+
}
|
86
|
+
writeFileSync(replFile, code);
|
87
|
+
try{
|
88
|
+
utils.runFileWithArgv(replFile, { async: !process.stdin.isTTY, onlyCompile: argv.compile });
|
89
|
+
} catch(e){
|
90
|
+
console.error(e);
|
91
|
+
} finally {
|
92
|
+
unlinkSync(replFile);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
)
|
68
96
|
.command(
|
69
97
|
'conf <command> [path] [key] [value]',
|
70
98
|
'Configuration management',
|
@@ -128,7 +156,7 @@ yargs(hideBin(process.argv))
|
|
128
156
|
type: 'string',
|
129
157
|
})
|
130
158
|
.option('dev', {
|
131
|
-
describe: `If your entry file is a .qrew, then just use
|
159
|
+
describe: `If your entry file is a .qrew, then just use .coffe or ${REW_FILE_TYPE.EXTENSION} instead`,
|
132
160
|
type: 'boolean',
|
133
161
|
})
|
134
162
|
.option('entry', {
|
@@ -355,7 +383,7 @@ yargs(hideBin(process.argv))
|
|
355
383
|
})
|
356
384
|
.option('remove', {
|
357
385
|
alias: 'r',
|
358
|
-
describe: 'Remove all '+REW_FILE_TYPE.EXTENSION,
|
386
|
+
describe: 'Remove all .coffee and '+REW_FILE_TYPE.EXTENSION,
|
359
387
|
type: 'boolean',
|
360
388
|
});
|
361
389
|
},
|
@@ -363,4 +391,4 @@ yargs(hideBin(process.argv))
|
|
363
391
|
utils.build(argv);
|
364
392
|
},
|
365
393
|
)
|
366
|
-
.help(!isFileGiven).argv;
|
394
|
+
.help(!isFileGiven).argv;
|
package/lib/rew/cli/utils.js
CHANGED
@@ -36,7 +36,7 @@ module.exports = {
|
|
36
36
|
|
37
37
|
const runIt = () => {
|
38
38
|
if (options.watch) console.clear();
|
39
|
-
const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile });
|
39
|
+
const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile, async: options?.async });
|
40
40
|
if (options.watch) {
|
41
41
|
imports.forEach((file) => {
|
42
42
|
watchIt(file);
|
@@ -48,15 +48,21 @@ module.exports = {
|
|
48
48
|
runIt();
|
49
49
|
},
|
50
50
|
runFileWithArgv(filePath, options = {}, cargv) {
|
51
|
-
|
51
|
+
let argv = cargv || process.argv;
|
52
52
|
argv.shift();
|
53
|
-
if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION)) {
|
53
|
+
if (argv[0].endsWith(REW_FILE_TYPE.EXTENSION) || argv[0].endsWith('.coffee')) {
|
54
54
|
if (argv[1] == 'run') {
|
55
55
|
argv.splice(0, 3);
|
56
56
|
} else if(argv[1] == '-w' || argv[1] == '--watch'){
|
57
57
|
argv.splice(0, 3);
|
58
58
|
} else argv.splice(0, 2);
|
59
59
|
}
|
60
|
+
if (argv[1] == 'exec') {
|
61
|
+
argv.splice(0, 2);
|
62
|
+
}
|
63
|
+
if (argv.includes('--')) {
|
64
|
+
argv = argv.slice(argv.indexOf('--') + 1, argv.length);
|
65
|
+
}
|
60
66
|
this.runFile(filePath, options, argv)
|
61
67
|
},
|
62
68
|
conf(command, fullPath, key, value) {
|
@@ -154,7 +160,7 @@ module.exports = {
|
|
154
160
|
project.package = pkg.trim();
|
155
161
|
rl.question(logget(' Use intellisense declarations ? (y/N): '.magenta.bold), (inteli) => {
|
156
162
|
project.intellisense = inteli.toLowerCase() == 'y' || inteli.toLowerCase() == 'yes';
|
157
|
-
rl.question(logget(' Use Civet
|
163
|
+
rl.question(logget(' Use Civet For main ? (y/N): '.blue.bold), (civet) => {
|
158
164
|
project.civet = civet.toLowerCase() == 'y' || civet.toLowerCase() == 'yes';
|
159
165
|
rl.question(logget(' Use git ? (y/N): '.yellow.bold), (use_git) => {
|
160
166
|
project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
|
@@ -190,7 +196,7 @@ module.exports = {
|
|
190
196
|
});
|
191
197
|
r = path.resolve(root, c.exec.entry.replace(new RegExp(path.extname(c.exec.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
|
192
198
|
}
|
193
|
-
this.runFileWithArgv(r);
|
199
|
+
this.runFileWithArgv(r, { async: !process.stdin.isTTY });
|
194
200
|
}
|
195
201
|
};
|
196
202
|
|
@@ -368,6 +374,9 @@ module.exports = {
|
|
368
374
|
} else if (fs.existsSync(importedFilePath + REW_FILE_TYPE.EXTENSION)) {
|
369
375
|
importsArray.push(importStatement);
|
370
376
|
processFile(importedFilePath + REW_FILE_TYPE.EXTENSION, importsArray);
|
377
|
+
} else if (fs.existsSync(importedFilePath + '.coffee')) {
|
378
|
+
importsArray.push(importStatement);
|
379
|
+
processFile(importedFilePath + '.coffee', importsArray);
|
371
380
|
} else if (fs.existsSync(importedFilePath + '.js')) {
|
372
381
|
importsArray.push(importStatement);
|
373
382
|
processFile(importedFilePath + '.js', importsArray);
|
@@ -377,7 +386,7 @@ module.exports = {
|
|
377
386
|
|
378
387
|
const appPath = findAppInfo(filePath);
|
379
388
|
|
380
|
-
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content
|
389
|
+
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(`"initFile ${filePath}"\n${path.basename(content)}`, appPath?.config?.manifest?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
|
381
390
|
writeCompiledFile(filePath, compiled);
|
382
391
|
}
|
383
392
|
|
@@ -539,5 +548,19 @@ module.exports = {
|
|
539
548
|
fs.mkdirSync(binpath, { recursive: true });
|
540
549
|
fs.mkdirSync(cachepath, { recursive: true });
|
541
550
|
fs.mkdirSync(logspath, { recursive: true });
|
551
|
+
},
|
552
|
+
getAllPipeInput(){
|
553
|
+
return new Promise((resolve) => {
|
554
|
+
let data = '';
|
555
|
+
process.stdin.setEncoding('utf8');
|
556
|
+
|
557
|
+
process.stdin.on('data', (chunk) => {
|
558
|
+
data += chunk;
|
559
|
+
});
|
560
|
+
|
561
|
+
process.stdin.on('end', () => {
|
562
|
+
resolve(data);
|
563
|
+
});
|
564
|
+
});
|
542
565
|
}
|
543
566
|
};
|
package/lib/rew/const/default.js
CHANGED
@@ -7,7 +7,7 @@ const { match } = require('../functions/match');
|
|
7
7
|
const { map } = require('../functions/map');
|
8
8
|
const { typex, typeis, typedef, typei, int, float, num, str, bool } = require('../functions/types');
|
9
9
|
const { isEmpty, clone, deepClone, merge, uniqueId, compose, curry } = require('../functions/core');
|
10
|
-
const { print, input, clear } = require('../functions/stdout');
|
10
|
+
const { print, input, clear, printf } = require('../functions/stdout');
|
11
11
|
const { curl } = require('../functions/curl');
|
12
12
|
const { wait } = require('../functions/wait');
|
13
13
|
const { scheduleFrame } = require('../functions/misc');
|
@@ -55,5 +55,6 @@ module.exports = {
|
|
55
55
|
curl,
|
56
56
|
|
57
57
|
print,
|
58
|
+
printf,
|
58
59
|
input,
|
59
60
|
};
|
package/lib/rew/const/opt.js
CHANGED
package/lib/rew/const/usage.js
CHANGED
@@ -73,8 +73,8 @@ module.exports.imp = function (runPath, context) {
|
|
73
73
|
} else lookUp();
|
74
74
|
}
|
75
75
|
|
76
|
-
const exec = (coptions = {}) =>
|
77
|
-
runPath(
|
76
|
+
const exec = (coptions = {}) => {
|
77
|
+
const r = runPath(
|
78
78
|
filepath,
|
79
79
|
{
|
80
80
|
import: options,
|
@@ -87,7 +87,12 @@ module.exports.imp = function (runPath, context) {
|
|
87
87
|
package: context.app ? context.app.config.package : path.basename(filepath)
|
88
88
|
},
|
89
89
|
execOptions.sharedContext == false ? {} : options.context && options.context == 'new' ? {} : context,
|
90
|
-
)
|
90
|
+
);
|
91
|
+
if(r instanceof Promise){
|
92
|
+
return new Promise((resolve) => r.then(c => resolve(c.context.module.exports)));
|
93
|
+
}
|
94
|
+
return r.context.module.exports;
|
95
|
+
}
|
91
96
|
|
92
97
|
if (ispkg) {
|
93
98
|
const pkg = getPackage(filename)(context, options);
|
@@ -4,6 +4,10 @@ const print = (module.exports.print = function print(...args) {
|
|
4
4
|
return console.log(...args);
|
5
5
|
});
|
6
6
|
|
7
|
+
module.exports.printf = function printf(buffer, cb) {
|
8
|
+
return process.stdout.write(buffer, cb);
|
9
|
+
};
|
10
|
+
|
7
11
|
print.stdout = process.stdout;
|
8
12
|
print.stdin = process.stdin;
|
9
13
|
|
@@ -303,13 +303,22 @@ const cpl = (module.exports.compile = function (file, options = {}) {
|
|
303
303
|
compiledCode = result.compiled;
|
304
304
|
|
305
305
|
const babelify = (code, options) => babel.transformSync(code, {
|
306
|
-
presets: [
|
307
|
-
|
306
|
+
presets: [
|
307
|
+
...(doJSX ? [[babelReact, { pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
|
308
|
+
],
|
309
|
+
plugins: [
|
310
|
+
...(doDecorators ? [[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }], [require('@babel/plugin-proposal-class-properties'), { loose: true }], [require('@babel/plugin-transform-class-static-block'), {}]] : [])
|
311
|
+
],
|
308
312
|
}).code;
|
309
313
|
|
314
|
+
const doJSX = execOptions.jsx || options.jsx;
|
315
|
+
const doTypes = execOptions.typescript || options.typescript;
|
316
|
+
const doDecorators = execOptions.decorators || options.decorators;
|
317
|
+
const doBabel = doJSX || doTypes || doDecorators;
|
318
|
+
|
310
319
|
if(compiledCode instanceof Promise){
|
311
320
|
return compiledCode.then((compiledCode) => {
|
312
|
-
if (
|
321
|
+
if (doBabel) {
|
313
322
|
compiledCode = babelify(compiledCode, options);
|
314
323
|
}
|
315
324
|
return compiledCode;
|
@@ -317,7 +326,7 @@ const cpl = (module.exports.compile = function (file, options = {}) {
|
|
317
326
|
}
|
318
327
|
|
319
328
|
// console.log(c);
|
320
|
-
if (
|
329
|
+
if (doBabel) {
|
321
330
|
compiledCode = babelify(compiledCode, options);
|
322
331
|
}
|
323
332
|
return compiledCode;
|
@@ -331,13 +340,21 @@ module.exports.compileFile = function (filepath, options = {}) {
|
|
331
340
|
if(options.qrew || path.extname(filepath) == '.qrew') {
|
332
341
|
qrew = true
|
333
342
|
f.content = from_qrew(readFileSync(f.path), options.package || findAppInfo(filepath)?.config.manifest.package || path.basename(filepath).split('.').slice(0, -1).join('.')).toString();
|
343
|
+
options.type = f.content.split('\n')[0]?.match(/"initFile (.+)"/)?.[1]?.split('.').pop();
|
334
344
|
}
|
335
345
|
|
336
346
|
let compiled_code = cpl(f, { ...options });
|
337
347
|
|
338
348
|
if(options.onlyCompile && !qrew){
|
339
|
-
|
340
|
-
|
349
|
+
if(compiled_code instanceof Promise){
|
350
|
+
compiled_code.then((r) => {
|
351
|
+
console.log(r);
|
352
|
+
process.exit();
|
353
|
+
});
|
354
|
+
} else {
|
355
|
+
console.log(compiled_code);
|
356
|
+
process.exit();
|
357
|
+
}
|
341
358
|
}
|
342
359
|
|
343
360
|
return {
|
@@ -18,26 +18,43 @@ const exec = (module.exports.exec = function (code, context, original = '') {
|
|
18
18
|
module.exports.runPath = function runPath(filepath, options = {}, custom_context = {}) {
|
19
19
|
if(filepath.endsWith('.js')) options.type = 'js';
|
20
20
|
if(filepath.endsWith('.coffee')) options.type = 'coffee';
|
21
|
+
if(filepath.endsWith('.qrew')) options.type = 'qrew';
|
22
|
+
|
23
|
+
if(options.import?.async) options.async = true;
|
21
24
|
let { compiled_code, file } = compileFile(options.code ? { content: options.code, path: filepath } : filepath, options);
|
22
|
-
const context = options.import?.takeThisContext ? custom_context : prepareContext(custom_context, options, file.path, runPath);
|
23
25
|
// context.module.compiled = compiled_code;
|
24
26
|
// context.process.exit = (int) => process.exit(int);
|
25
27
|
|
26
|
-
|
27
|
-
const
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
const doCode = () => {
|
29
|
+
const context = options.import?.takeThisContext ? custom_context : prepareContext(custom_context, options, file.path, runPath);
|
30
|
+
|
31
|
+
if(context.app){
|
32
|
+
const p = path.join(CONFIG_PATH, context.app.config.manifest.package, 'app');
|
33
|
+
if(existsSync(p) && context.app.path !== p){
|
34
|
+
console.log("App with the same package name has been installed. Conflicts happened. \nTo fix this, change your app's package name or remove the app making the conflict.");
|
35
|
+
return {
|
36
|
+
context: { module: { exports: null } },
|
37
|
+
returns: null
|
38
|
+
}
|
33
39
|
}
|
34
40
|
}
|
41
|
+
|
42
|
+
compiled_code = preScript+'\n'+compiled_code;
|
43
|
+
|
44
|
+
return {
|
45
|
+
context,
|
46
|
+
returns: exec(compiled_code, context, file.content),
|
47
|
+
};
|
35
48
|
}
|
36
49
|
|
37
|
-
|
50
|
+
if(options.async){
|
51
|
+
return new Promise(async (r, re) => {
|
52
|
+
compiled_code.then((e) => {
|
53
|
+
compiled_code = e;
|
54
|
+
r(doCode());
|
55
|
+
});
|
56
|
+
});
|
57
|
+
}
|
38
58
|
|
39
|
-
return
|
40
|
-
context,
|
41
|
-
returns: exec(compiled_code, context, file.content),
|
42
|
-
};
|
59
|
+
return doCode();
|
43
60
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@makano/rew",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.59",
|
4
4
|
"description": "A simple coffescript runtime and app manager",
|
5
5
|
"main": "main.js",
|
6
6
|
"directories": {
|
@@ -32,6 +32,9 @@
|
|
32
32
|
"license": "ISC",
|
33
33
|
"dependencies": {
|
34
34
|
"@babel/core": "^7.24.6",
|
35
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
36
|
+
"@babel/plugin-proposal-decorators": "^7.24.7",
|
37
|
+
"@babel/plugin-transform-class-static-block": "^7.24.7",
|
35
38
|
"@babel/preset-env": "^7.24.7",
|
36
39
|
"@babel/preset-react": "^7.24.6",
|
37
40
|
"@babel/preset-typescript": "^7.24.7",
|
@@ -48,6 +51,5 @@
|
|
48
51
|
"vite": "^5.2.13",
|
49
52
|
"vm": "^0.1.0",
|
50
53
|
"yargs": "^17.7.2"
|
51
|
-
}
|
52
|
-
"devDependencies": {}
|
54
|
+
}
|
53
55
|
}
|
package/runtime.d.ts
CHANGED
@@ -64,6 +64,7 @@ interface ModuleConf extends ModuleConfOptionCenter {
|
|
64
64
|
defaults?: any
|
65
65
|
) => {
|
66
66
|
write: (value: any, ifExists?: boolean) => any;
|
67
|
+
// @ts-ignore
|
67
68
|
read: (to?: string | object) => string | object | Buffer;
|
68
69
|
fileRoot: string;
|
69
70
|
exists: boolean;
|
@@ -128,6 +129,34 @@ interface ModuleThreads {
|
|
128
129
|
};
|
129
130
|
}
|
130
131
|
|
132
|
+
|
133
|
+
type _Request = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Request;
|
134
|
+
type _Response = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Response;
|
135
|
+
type _FormData = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").FormData;
|
136
|
+
type _Headers = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Headers;
|
137
|
+
type _RequestInit = typeof globalThis extends { onmessage: any } ? {}
|
138
|
+
: import("undici-types").RequestInit;
|
139
|
+
type _ResponseInit = typeof globalThis extends { onmessage: any } ? {}
|
140
|
+
: import("undici-types").ResponseInit;
|
141
|
+
// @ts-ignore
|
142
|
+
type _File = typeof globalThis extends { onmessage: any } ? {} : import("node:buffer").File;
|
143
|
+
|
144
|
+
interface Request {}
|
145
|
+
declare var Request: typeof globalThis extends {
|
146
|
+
onmessage: any;
|
147
|
+
Request: infer T;
|
148
|
+
} ? T
|
149
|
+
: typeof import("undici-types").Request;
|
150
|
+
|
151
|
+
interface ResponseInit extends _ResponseInit {}
|
152
|
+
|
153
|
+
interface Response extends _Response {}
|
154
|
+
declare var Response: typeof globalThis extends {
|
155
|
+
onmessage: any;
|
156
|
+
Response: infer T;
|
157
|
+
} ? T
|
158
|
+
: typeof import("undici-types").Response;
|
159
|
+
|
131
160
|
type GenericTraps = Record<string, any>;
|
132
161
|
|
133
162
|
type IRequestStrict = {
|
@@ -159,7 +188,7 @@ type StatusErrorObject = {
|
|
159
188
|
[key: string]: any;
|
160
189
|
};
|
161
190
|
|
162
|
-
|
191
|
+
interface StatusError extends Error {
|
163
192
|
status: number;
|
164
193
|
[key: string]: any;
|
165
194
|
constructor(status?: number, body?: StatusErrorObject | string);
|
@@ -267,7 +296,7 @@ interface ErrorFormatter {
|
|
267
296
|
(statusCode?: number, body?: ErrorBody): Response;
|
268
297
|
}
|
269
298
|
|
270
|
-
|
299
|
+
type IttyRouter = <
|
271
300
|
RequestType extends IRequest = IRequest,
|
272
301
|
Args extends any[] = any[],
|
273
302
|
ResponseType = any
|
@@ -277,7 +306,7 @@ export const IttyRouter: <
|
|
277
306
|
...other
|
278
307
|
}?: IttyRouterOptions) => IttyRouterType<RequestType, Args, ResponseType>;
|
279
308
|
|
280
|
-
|
309
|
+
type Router = <
|
281
310
|
RequestType = IRequest,
|
282
311
|
Args extends any[] = any[],
|
283
312
|
ResponseType = any
|
@@ -291,7 +320,7 @@ export const Router: <
|
|
291
320
|
ResponseType
|
292
321
|
>;
|
293
322
|
|
294
|
-
|
323
|
+
type AutoRouter = <
|
295
324
|
RequestType extends IRequest = IRequest,
|
296
325
|
Args extends any[] = any[],
|
297
326
|
ResponseType = any
|
@@ -307,32 +336,18 @@ const AutoRouter: <
|
|
307
336
|
ResponseType
|
308
337
|
>;
|
309
338
|
|
310
|
-
|
339
|
+
type createResponse = (
|
311
340
|
format?: string,
|
312
341
|
transform?: ((body: any) => any) | undefined
|
313
342
|
) => ResponseFormatter;
|
314
343
|
|
315
|
-
|
316
|
-
|
317
|
-
const statusR: (status: number, options?: ResponseInit) => Response;
|
318
|
-
|
319
|
-
const textR: ResponseFormatter;
|
344
|
+
type statusR = (status: number, options?: ResponseInit) => Response;
|
320
345
|
|
321
|
-
|
346
|
+
type withContent = (request: IRequest) => Promise<void>;
|
322
347
|
|
323
|
-
|
348
|
+
type withCookies = (r: IRequest) => void;
|
324
349
|
|
325
|
-
|
326
|
-
|
327
|
-
const pngR: ResponseFormatter;
|
328
|
-
|
329
|
-
const webpR: ResponseFormatter;
|
330
|
-
|
331
|
-
const withContent: (request: IRequest) => Promise<void>;
|
332
|
-
|
333
|
-
const withCookies: (r: IRequest) => void;
|
334
|
-
|
335
|
-
const withParams: (request: IRequest) => void;
|
350
|
+
type withParams = (request: IRequest) => void;
|
336
351
|
|
337
352
|
type CorsOptions = {
|
338
353
|
credentials?: true;
|
@@ -353,7 +368,7 @@ type CorsPair = {
|
|
353
368
|
preflight: Preflight;
|
354
369
|
corsify: Corsify;
|
355
370
|
};
|
356
|
-
|
371
|
+
type cors = (options?: CorsOptions) => {
|
357
372
|
corsify: (response: Response, request?: Request) => Response;
|
358
373
|
preflight: (request: Request) => Response | undefined;
|
359
374
|
};
|
@@ -362,7 +377,9 @@ interface ModuleServeRouter extends RouterType {
|
|
362
377
|
to(server: ModuleServeServer): any;
|
363
378
|
}
|
364
379
|
|
365
|
-
interface
|
380
|
+
interface ResponseType{}
|
381
|
+
|
382
|
+
declare class ModuleServeServerOptions {
|
366
383
|
handler?: (req: RequestLike, res: ResponseType) => any;
|
367
384
|
routers?: ModuleServeRouter[];
|
368
385
|
fetch?: (req: RequestLike) => ResponseType | Promise<ResponseType>;
|
@@ -372,7 +389,7 @@ interface ModuleServeServer {
|
|
372
389
|
_server: any;
|
373
390
|
routers: Record<string, ModuleServeRouter>;
|
374
391
|
|
375
|
-
handleRequest: typeof ModuleServeServerOptions.handler;
|
392
|
+
handleRequest: typeof ModuleServeServerOptions.prototype.handler;
|
376
393
|
listen: this;
|
377
394
|
port: (port: number) => this;
|
378
395
|
log: (string: string) => this;
|
@@ -388,7 +405,7 @@ interface ModuleServeFileRouterOptions {
|
|
388
405
|
onError?: () => any;
|
389
406
|
}
|
390
407
|
|
391
|
-
class ModuleServe {
|
408
|
+
declare class ModuleServe {
|
392
409
|
router({
|
393
410
|
id,
|
394
411
|
type,
|
@@ -403,26 +420,29 @@ class ModuleServe {
|
|
403
420
|
o: ModuleServeFileRouterOptions
|
404
421
|
): (req: RequestLike) => ResponseType | Promise<ResponseType>;
|
405
422
|
|
406
|
-
cors
|
407
|
-
json
|
408
|
-
error
|
409
|
-
png
|
410
|
-
jpeg
|
411
|
-
webp
|
412
|
-
text
|
413
|
-
html
|
414
|
-
status
|
423
|
+
cors: cors;
|
424
|
+
json: ResponseFormatter;
|
425
|
+
error: ResponseFormatter;
|
426
|
+
png: ResponseFormatter;
|
427
|
+
jpeg: ResponseFormatter;
|
428
|
+
webp: ResponseFormatter;
|
429
|
+
text: ResponseFormatter;
|
430
|
+
html: ResponseFormatter;
|
431
|
+
status: statusR;
|
415
432
|
|
416
|
-
createResponse
|
433
|
+
createResponse: createResponse;
|
417
434
|
|
418
|
-
withContent
|
419
|
-
withCookies
|
420
|
-
withParams
|
435
|
+
withContent: withContent;
|
436
|
+
withCookies: withCookies;
|
437
|
+
withParams: withParams;
|
421
438
|
|
439
|
+
// @ts-ignore
|
422
440
|
Request = Request;
|
441
|
+
// @ts-ignore
|
423
442
|
Response = Response;
|
424
443
|
}
|
425
444
|
|
445
|
+
// @ts-ignore
|
426
446
|
type nodable = Element | Node | any;
|
427
447
|
interface Node {
|
428
448
|
type: string;
|
@@ -461,7 +481,7 @@ interface ModuleWebState {
|
|
461
481
|
subscribe(callback: CallableFunction): this;
|
462
482
|
}
|
463
483
|
|
464
|
-
class ModuleWeb {
|
484
|
+
declare class ModuleWeb {
|
465
485
|
create(options: ModuleWebPageOptions): ModuleWebPage;
|
466
486
|
isNode(node: any): boolean;
|
467
487
|
isTextNode(node: any): boolean;
|
@@ -471,12 +491,13 @@ class ModuleWeb {
|
|
471
491
|
createElement(...args: any[]): ElementNode;
|
472
492
|
|
473
493
|
state(value): ModuleWebState | any;
|
494
|
+
// @ts-ignore
|
474
495
|
useState(states: State[], callback: CallableFunction): any;
|
475
496
|
|
476
497
|
bundle(filePath: string, options?: Record<string, any>): string;
|
477
498
|
}
|
478
499
|
|
479
|
-
class Stack<T = any> {
|
500
|
+
declare class Stack<T = any> {
|
480
501
|
constructor();
|
481
502
|
push(item: T): void;
|
482
503
|
pop(): T | undefined;
|
@@ -485,7 +506,7 @@ class Stack<T = any> {
|
|
485
506
|
toArray(): T[];
|
486
507
|
}
|
487
508
|
|
488
|
-
class Queue<T = any> {
|
509
|
+
declare class Queue<T = any> {
|
489
510
|
constructor();
|
490
511
|
enqueue(item: T): void;
|
491
512
|
dequeue(): T | undefined;
|
@@ -494,7 +515,7 @@ class Queue<T = any> {
|
|
494
515
|
toArray(): T[];
|
495
516
|
}
|
496
517
|
|
497
|
-
class LinkedList<T = any> {
|
518
|
+
declare class LinkedList<T = any> {
|
498
519
|
constructor();
|
499
520
|
append(value: T): void;
|
500
521
|
prepend(value: T): void;
|
@@ -503,7 +524,7 @@ class LinkedList<T = any> {
|
|
503
524
|
toArray(): T[];
|
504
525
|
}
|
505
526
|
|
506
|
-
namespace LinkedList {
|
527
|
+
declare namespace LinkedList {
|
507
528
|
class Node<T = any> {
|
508
529
|
constructor(value: T);
|
509
530
|
value: T;
|
@@ -511,14 +532,14 @@ namespace LinkedList {
|
|
511
532
|
}
|
512
533
|
}
|
513
534
|
|
514
|
-
class BinaryTree<T = any> {
|
535
|
+
declare class BinaryTree<T = any> {
|
515
536
|
constructor();
|
516
537
|
insert(value: T): void;
|
517
538
|
find(value: T): BinaryTree.Node<T> | null;
|
518
539
|
toArray(): T[];
|
519
540
|
}
|
520
541
|
|
521
|
-
namespace BinaryTree {
|
542
|
+
declare namespace BinaryTree {
|
522
543
|
class Node<T = any> {
|
523
544
|
constructor(value: T);
|
524
545
|
value: T;
|
@@ -527,7 +548,7 @@ namespace BinaryTree {
|
|
527
548
|
}
|
528
549
|
}
|
529
550
|
|
530
|
-
class DoublyLinkedList<T = any> {
|
551
|
+
declare class DoublyLinkedList<T = any> {
|
531
552
|
constructor();
|
532
553
|
append(value: T): void;
|
533
554
|
prepend(value: T): void;
|
@@ -536,7 +557,7 @@ class DoublyLinkedList<T = any> {
|
|
536
557
|
toArray(): T[];
|
537
558
|
}
|
538
559
|
|
539
|
-
namespace DoublyLinkedList {
|
560
|
+
declare namespace DoublyLinkedList {
|
540
561
|
class Node<T = any> {
|
541
562
|
constructor(value: T);
|
542
563
|
value: T;
|
@@ -545,20 +566,26 @@ namespace DoublyLinkedList {
|
|
545
566
|
}
|
546
567
|
}
|
547
568
|
|
548
|
-
interface ModuleData {
|
569
|
+
declare interface ModuleData {
|
549
570
|
Stack: typeof Stack;
|
550
571
|
Queue: typeof Queue;
|
551
|
-
|
552
|
-
|
553
|
-
|
572
|
+
BinaryTree: typeof BinaryTree;
|
573
|
+
DoublyLinkedList: typeof DoublyLinkedList;
|
574
|
+
LinkedList: typeof LinkedList;
|
554
575
|
}
|
555
576
|
|
556
577
|
interface ModuleStream {
|
578
|
+
// @ts-ignore
|
557
579
|
Readable: Readable,
|
580
|
+
// @ts-ignore
|
558
581
|
Writable: Writable,
|
582
|
+
// @ts-ignore
|
559
583
|
Transform: Transform,
|
584
|
+
// @ts-ignore
|
560
585
|
Duplex: Duplex,
|
586
|
+
// @ts-ignore
|
561
587
|
pipeline: pipeline,
|
588
|
+
// @ts-ignore
|
562
589
|
finished: finished
|
563
590
|
}
|
564
591
|
|
@@ -575,8 +602,9 @@ declare function imp(path: "data", options?: ImportOptions): ModuleData;
|
|
575
602
|
declare function imp(path: "stream", options?: ImportOptions): ModuleStream;
|
576
603
|
declare function imp(path: string, options?: ImportOptions): any;
|
577
604
|
|
578
|
-
declare const inc
|
605
|
+
declare const inc: typeof imp;
|
579
606
|
|
607
|
+
// @ts-ignore
|
580
608
|
declare function require(moduleName: string): any;
|
581
609
|
|
582
610
|
interface Module {
|
@@ -587,10 +615,12 @@ interface Module {
|
|
587
615
|
compiled: string;
|
588
616
|
}
|
589
617
|
|
618
|
+
// @ts-ignore
|
590
619
|
declare const module: Module;
|
591
620
|
|
592
621
|
interface Imports {
|
593
622
|
meta: {
|
623
|
+
// @ts-ignore
|
594
624
|
url: URL,
|
595
625
|
main: boolean
|
596
626
|
};
|
@@ -599,6 +629,7 @@ interface Imports {
|
|
599
629
|
|
600
630
|
declare const imports: Imports;
|
601
631
|
|
632
|
+
// @ts-ignore
|
602
633
|
declare const process: {
|
603
634
|
argv: string[];
|
604
635
|
target: ReturnType<typeof emitter>;
|
@@ -842,6 +873,7 @@ declare function curl(
|
|
842
873
|
*/
|
843
874
|
o?: string;
|
844
875
|
}
|
876
|
+
// @ts-ignore
|
845
877
|
): Promise<Response>;
|
846
878
|
|
847
879
|
/**
|
@@ -874,7 +906,9 @@ declare function curl(
|
|
874
906
|
|
875
907
|
declare function print(...args: any[]): void;
|
876
908
|
declare namespace print {
|
909
|
+
// @ts-ignore
|
877
910
|
const stdout: WriteStream;
|
911
|
+
// @ts-ignore
|
878
912
|
const stdin: ReadStream;
|
879
913
|
}
|
880
914
|
|
@@ -886,6 +920,7 @@ declare const extname: (path: string) => string;
|
|
886
920
|
declare const pjoin: (...paths: string[]) => string;
|
887
921
|
declare const presolve: (...paths: string[]) => string;
|
888
922
|
|
923
|
+
// @ts-ignore
|
889
924
|
declare function exports(value: any): any;
|
890
925
|
|
891
926
|
|
@@ -901,7 +936,8 @@ declare const opt: {
|
|
901
936
|
|
902
937
|
declare const JSX: any;
|
903
938
|
declare const TYPES: any;
|
939
|
+
declare const DECORATORS: any;
|
904
940
|
declare function using(fn: any, ...args: any[]): any;
|
905
941
|
|
906
942
|
declare function wait(fn: CallableFunction, ...args: any[]): any;
|
907
|
-
declare function clear(): void;
|
943
|
+
declare function clear(): void;
|