Skip to content

Commit eeea079

Browse files
committed
pico-engine updates
1 parent 35c157a commit eeea079

File tree

7 files changed

+101
-83
lines changed

7 files changed

+101
-83
lines changed

packages/pico-engine/package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,29 @@
4545
"body-parser": "^1.18.3",
4646
"charwise": "^3.0.1",
4747
"classic-level": "^1.3.0",
48-
"cross-fetch": "^3.0.5",
48+
"cross-fetch": "^4.0.0",
4949
"cuid": "^2.1.8",
5050
"express": "^4.16.4",
51-
"helmet": "^3.16.0",
51+
"helmet": "^7.1.0",
5252
"home-dir": "^1.0.0",
5353
"krl-compiler": "^1.3.0",
5454
"krl-stdlib": "^1.3.0",
5555
"level-json-coerce-null": "^1.0.1",
5656
"lodash": "^4.17.11",
57-
"make-dir": "^3.0.0",
57+
"make-dir": "^4.0.0",
5858
"minimist": "^1.2.5",
5959
"pico-engine-core": "^1.3.0",
6060
"pico-framework": "^0.7.0",
61-
"rotating-file-stream": "^1.4.1",
62-
"split": "^1.0.1",
63-
"through2": "^3.0.1"
61+
"rotating-file-stream": "^1.4.1"
6462
},
6563
"devDependencies": {
6664
"@types/body-parser": "^1.17.0",
6765
"@types/express": "^4.16.1",
68-
"@types/helmet": "0.0.43",
6966
"@types/lodash": "^4.14.123",
7067
"@types/node": "^20.8.10",
7168
"ava": "^5.3.1",
72-
"onchange": "^6.0.0",
69+
"onchange": "^7.1.0",
7370
"scriptsp": "^1.1.1",
74-
"temp-dir": "^2.0.0",
7571
"ts-node": "^10.4.0",
7672
"typescript": "^5.2.2"
7773
},

packages/pico-engine/public/pico-engine-ui.css

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pico-engine/public/pico-engine-ui.js

Lines changed: 49 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pico-engine/src/logging.ts

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as fs from "fs";
2+
import * as readline from "readline";
23
import { krlLogLevelCodeToHuman, PicoLogEntry } from "krl-stdlib";
34
import * as path from "path";
4-
const split = require("split");
5-
const through2 = require("through2");
65

76
const rfs = require("rotating-file-stream");
87

@@ -21,14 +20,14 @@ function getRotatingFileStream(filePath: string): NodeJS.WritableStream {
2120

2221
size: "100M", // rotate every 10 MegaBytes written
2322
maxFiles: 12,
24-
}
23+
},
2524
) as NodeJS.WritableStream;
2625
}
2726
return logStreams[filePath];
2827
}
2928

3029
export function makeRotatingFileLogWriter(
31-
filePath: string
30+
filePath: string,
3231
): (line: string) => void {
3332
const fileStream = getRotatingFileStream(filePath);
3433
const isTest = process.env.NODE_ENV === "test";
@@ -45,50 +44,40 @@ export function makeRotatingFileLogWriter(
4544

4645
export async function getPicoLogs(
4746
filePath: string,
48-
picoId: string
47+
picoId: string,
4948
): Promise<PicoLogEntry[]> {
50-
return new Promise((resolve, reject) => {
51-
const output: PicoLogEntry[] = [];
52-
fs.createReadStream(filePath)
53-
.pipe(split())
54-
.pipe(
55-
through2((chunk: any, enc: any, next: any) => {
56-
const line = chunk.toString();
57-
if (line.indexOf(picoId) < 0) {
58-
// not my pico
59-
return next();
60-
}
61-
let entry;
62-
try {
63-
entry = JSON.parse(line);
64-
} catch (err) {}
65-
if (!entry || entry.picoId !== picoId) {
66-
// not my pico
67-
return next();
68-
}
69-
const time = new Date(entry.time);
70-
if (Date.now() - time.getTime() > 1000 * 60 * 60 * 12) {
71-
// too old
72-
return next();
73-
}
74-
75-
const out: PicoLogEntry = {
76-
...entry,
77-
level: krlLogLevelCodeToHuman[entry.level] || `${entry.level}`,
78-
time: entry.time,
79-
txnId: entry.txnId,
80-
};
81-
delete (out as any).picoId;
82-
output.push(out);
49+
const output: PicoLogEntry[] = [];
8350

84-
next();
85-
})
86-
)
87-
.on("finish", () => {
88-
resolve(output);
89-
})
90-
.on("error", (err: any) => {
91-
reject(err);
92-
});
51+
const rl = readline.createInterface({
52+
input: fs.createReadStream(filePath),
9353
});
54+
55+
for await (const line of rl) {
56+
// Each line in the readline input will be successively available here as
57+
// `line`.
58+
if (line.indexOf(picoId) < 0) {
59+
continue; // not my pico
60+
}
61+
let entry;
62+
try {
63+
entry = JSON.parse(line);
64+
} catch (err) {}
65+
if (!entry || entry.picoId !== picoId) {
66+
continue; // not my pico
67+
}
68+
const time = new Date(entry.time);
69+
if (Date.now() - time.getTime() > 1000 * 60 * 60 * 12) {
70+
continue; // too old
71+
}
72+
73+
const out: PicoLogEntry = {
74+
...entry,
75+
level: krlLogLevelCodeToHuman[entry.level] || `${entry.level}`,
76+
time: entry.time,
77+
txnId: entry.txnId,
78+
};
79+
delete (out as any).picoId;
80+
output.push(out);
81+
}
82+
return output;
9483
}

packages/pico-engine/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as bodyParser from "body-parser";
22
import * as express from "express";
33
import { Express, Request } from "express";
4-
import * as helmet from "helmet";
4+
import helmet from "helmet";
55
import * as _ from "lodash";
66
import * as path from "path";
77
import { PicoEngineCore } from "pico-engine-core";

packages/pico-engine/test/RulesetRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import * as cuid from "cuid";
33
import * as fs from "fs";
44
import * as makeDir from "make-dir";
55
import * as path from "path";
6-
import * as tempDir from "temp-dir";
6+
import * as os from "os";
77
import { RulesetRegistry } from "pico-engine-core";
88
import { RulesetRegistryLoaderFs } from "../src/RulesetRegistryLoaderFs";
99
import { toFileUrl } from "../src/utils/toFileUrl";
1010

1111
test("RulesetRegistry", async (t) => {
12-
const dir = path.resolve(tempDir, "pico-engine", cuid());
12+
const dir = path.resolve(os.tmpdir(), "pico-engine", cuid());
1313
await makeDir(dir);
1414

1515
await fs.promises.writeFile(

packages/pico-engine/test/helpers/startTestEngine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as cuid from "cuid";
22
import * as path from "path";
33
import { ChannelConfig, Pico, PicoFramework } from "pico-framework";
4-
import * as tempDir from "temp-dir";
4+
import * as os from "os";
55
import { PicoEngineConfiguration, startEngine } from "../../src/index";
66
import { cleanDirectives } from "./cleanDirectives";
77
import { toTestKrlURL } from "./toTestKrlURL";
@@ -44,7 +44,7 @@ export async function startTestEngine(
4444
) {
4545
const pe = await startEngine({
4646
...conf,
47-
home: conf.home || path.resolve(tempDir, "pico-engine", cuid()),
47+
home: conf.home || path.resolve(os.tmpdir(), "pico-engine", cuid()),
4848
port: 0,
4949
});
5050

0 commit comments

Comments
 (0)