Reduce lint errors
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { buf } from "https://deno.land/x/sqlite3@0.6.1/src/util.ts";
|
||||
|
||||
export function base64Decode(s: string): Uint8Array {
|
||||
const binString = atob(s);
|
||||
const len = binString.length;
|
||||
|
||||
@@ -36,8 +36,8 @@ export class ConsoleLogger {
|
||||
}
|
||||
|
||||
logMessage(values: any[]): string {
|
||||
let pieces: string[] = [];
|
||||
for (let val of values) {
|
||||
const pieces: string[] = [];
|
||||
for (const val of values) {
|
||||
switch (typeof val) {
|
||||
case "string":
|
||||
case "number":
|
||||
|
||||
@@ -86,7 +86,7 @@ self.addEventListener("message", (event: { data: WorkerMessage }) => {
|
||||
switch (data.type) {
|
||||
case "load":
|
||||
{
|
||||
let fn2 = new Function(wrapScript(data.code!));
|
||||
const fn2 = new Function(wrapScript(data.code!));
|
||||
loadedFunctions.set(data.name!, fn2());
|
||||
workerPostMessage({
|
||||
type: "inited",
|
||||
@@ -98,8 +98,8 @@ self.addEventListener("message", (event: { data: WorkerMessage }) => {
|
||||
case "load-dependency":
|
||||
{
|
||||
// console.log("Received dep", data.name);
|
||||
let fn3 = new Function(`return ${data.code!}`);
|
||||
let v = fn3();
|
||||
const fn3 = new Function(`return ${data.code!}`);
|
||||
const v = fn3();
|
||||
loadedModules.set(data.name!, v);
|
||||
// console.log("Dep val", v);
|
||||
workerPostMessage({
|
||||
@@ -110,12 +110,12 @@ self.addEventListener("message", (event: { data: WorkerMessage }) => {
|
||||
break;
|
||||
case "invoke":
|
||||
{
|
||||
let fn = loadedFunctions.get(data.name!);
|
||||
const fn = loadedFunctions.get(data.name!);
|
||||
if (!fn) {
|
||||
throw new Error(`Function not loaded: ${data.name}`);
|
||||
}
|
||||
try {
|
||||
let result = await Promise.resolve(fn(...(data.args || [])));
|
||||
const result = await Promise.resolve(fn(...(data.args || [])));
|
||||
workerPostMessage({
|
||||
type: "result",
|
||||
id: data.id,
|
||||
@@ -136,7 +136,7 @@ self.addEventListener("message", (event: { data: WorkerMessage }) => {
|
||||
break;
|
||||
case "syscall-response":
|
||||
{
|
||||
let syscallId = data.id!;
|
||||
const syscallId = data.id!;
|
||||
const lookup = pendingRequests.get(syscallId);
|
||||
if (!lookup) {
|
||||
console.log(
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
import { load as nativeLoad } from "./src/native_loader.ts";
|
||||
import { load as portableLoad } from "./src/portable_loader.ts";
|
||||
import { ModuleEntry } from "./src/deno.ts";
|
||||
import { resolve } from "https://deno.land/std@0.122.0/path/win32.ts";
|
||||
|
||||
export interface DenoPluginOptions {
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ export class DenoCronHook implements Hook<CronHookT> {
|
||||
function reloadCrons() {
|
||||
tasks.forEach((task) => task.stop());
|
||||
tasks = [];
|
||||
for (let plug of system.loadedPlugs.values()) {
|
||||
for (const plug of system.loadedPlugs.values()) {
|
||||
if (!plug.manifest) {
|
||||
continue;
|
||||
}
|
||||
@@ -59,15 +59,15 @@ export class DenoCronHook implements Hook<CronHookT> {
|
||||
}
|
||||
|
||||
validateManifest(manifest: Manifest<CronHookT>): string[] {
|
||||
let errors: string[] = [];
|
||||
for (const [name, functionDef] of Object.entries(manifest.functions)) {
|
||||
const errors: string[] = [];
|
||||
for (const functionDef of Object.values(manifest.functions)) {
|
||||
if (!functionDef.cron) {
|
||||
continue;
|
||||
}
|
||||
const crons = Array.isArray(functionDef.cron)
|
||||
? functionDef.cron
|
||||
: [functionDef.cron];
|
||||
for (let cronDef of crons) {
|
||||
for (const _cronDef of crons) {
|
||||
// if (!cron.validate(cronDef)) {
|
||||
// errors.push(`Invalid cron expression ${cronDef}`);
|
||||
// }
|
||||
|
||||
@@ -50,7 +50,7 @@ export class EndpointHook implements Hook<EndpointHookT> {
|
||||
}
|
||||
const functions = manifest.functions;
|
||||
console.log("Checking plug", plugName);
|
||||
let prefix = `${this.prefix}/${plugName}`;
|
||||
const prefix = `${this.prefix}/${plugName}`;
|
||||
if (!requestPath.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
@@ -58,12 +58,12 @@ export class EndpointHook implements Hook<EndpointHookT> {
|
||||
if (!functionDef.http) {
|
||||
continue;
|
||||
}
|
||||
let endpoints = Array.isArray(functionDef.http)
|
||||
const endpoints = Array.isArray(functionDef.http)
|
||||
? functionDef.http
|
||||
: [functionDef.http];
|
||||
console.log(endpoints);
|
||||
for (const { path, method } of endpoints) {
|
||||
let prefixedPath = `${prefix}${path}`;
|
||||
const prefixedPath = `${prefix}${path}`;
|
||||
if (
|
||||
prefixedPath === requestPath &&
|
||||
((method || "GET") === req.method || method === "ANY")
|
||||
@@ -109,15 +109,15 @@ export class EndpointHook implements Hook<EndpointHookT> {
|
||||
}
|
||||
|
||||
validateManifest(manifest: Manifest<EndpointHookT>): string[] {
|
||||
let errors = [];
|
||||
for (const [name, functionDef] of Object.entries(manifest.functions)) {
|
||||
const errors = [];
|
||||
for (const functionDef of Object.values(manifest.functions)) {
|
||||
if (!functionDef.http) {
|
||||
continue;
|
||||
}
|
||||
let endpoints = Array.isArray(functionDef.http)
|
||||
const endpoints = Array.isArray(functionDef.http)
|
||||
? functionDef.http
|
||||
: [functionDef.http];
|
||||
for (let { path, method } of endpoints) {
|
||||
for (const { path, method } of endpoints) {
|
||||
if (!path) {
|
||||
errors.push("Path not defined for endpoint");
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ export class Plug<HookT> {
|
||||
return await this.sandbox.invoke(name, args);
|
||||
}
|
||||
|
||||
async stop() {
|
||||
stop() {
|
||||
this.sandbox.stop();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-10
@@ -40,7 +40,7 @@ export class Sandbox {
|
||||
|
||||
async load(name: string, code: string): Promise<void> {
|
||||
await this.worker.ready;
|
||||
let outstandingInit = this.outstandingInits.get(name);
|
||||
const outstandingInit = this.outstandingInits.get(name);
|
||||
if (outstandingInit) {
|
||||
// Load already in progress, let's wait for it...
|
||||
return new Promise((resolve) => {
|
||||
@@ -82,19 +82,21 @@ export class Sandbox {
|
||||
|
||||
async onMessage(data: ControllerMessage) {
|
||||
switch (data.type) {
|
||||
case "inited":
|
||||
let initCb = this.outstandingInits.get(data.name!);
|
||||
case "inited": {
|
||||
const initCb = this.outstandingInits.get(data.name!);
|
||||
initCb && initCb();
|
||||
this.outstandingInits.delete(data.name!);
|
||||
break;
|
||||
case "dependency-inited":
|
||||
let depInitCb = this.outstandingDependencyInits.get(data.name!);
|
||||
}
|
||||
case "dependency-inited": {
|
||||
const depInitCb = this.outstandingDependencyInits.get(data.name!);
|
||||
depInitCb && depInitCb();
|
||||
this.outstandingDependencyInits.delete(data.name!);
|
||||
break;
|
||||
}
|
||||
case "syscall":
|
||||
try {
|
||||
let result = await this.plug.syscall(data.name!, data.args!);
|
||||
const result = await this.plug.syscall(data.name!, data.args!);
|
||||
|
||||
this.worker.postMessage({
|
||||
type: "syscall-response",
|
||||
@@ -110,8 +112,8 @@ export class Sandbox {
|
||||
} as WorkerMessage);
|
||||
}
|
||||
break;
|
||||
case "result":
|
||||
let resultCbs = this.outstandingInvocations.get(data.id!);
|
||||
case "result": {
|
||||
const resultCbs = this.outstandingInvocations.get(data.id!);
|
||||
this.outstandingInvocations.delete(data.id!);
|
||||
if (data.error) {
|
||||
resultCbs &&
|
||||
@@ -122,7 +124,8 @@ export class Sandbox {
|
||||
resultCbs && resultCbs.resolve(data.result);
|
||||
}
|
||||
break;
|
||||
case "log":
|
||||
}
|
||||
case "log": {
|
||||
this.logBuffer.push({
|
||||
level: data.level!,
|
||||
message: data.message!,
|
||||
@@ -133,12 +136,13 @@ export class Sandbox {
|
||||
}
|
||||
console.log(`[Sandbox ${data.level}]`, data.message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.error("Unknown message type", data);
|
||||
}
|
||||
}
|
||||
|
||||
async invoke(name: string, args: any[]): Promise<any> {
|
||||
invoke(name: string, args: any[]): Promise<any> {
|
||||
this.reqId++;
|
||||
this.worker.postMessage({
|
||||
type: "invoke",
|
||||
|
||||
Reference in New Issue
Block a user