Skip to content

Commit

Permalink
pico-engine now using latest pico-framework and leveldb
Browse files Browse the repository at this point in the history
  • Loading branch information
farskipper committed Nov 19, 2023
1 parent 8b63680 commit 854c775
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
9 changes: 2 additions & 7 deletions packages/pico-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,20 @@
"dependencies": {
"body-parser": "^1.18.3",
"charwise": "^3.0.1",
"classic-level": "^1.3.0",
"cross-fetch": "^3.0.5",
"cuid": "^2.1.8",
"encoding-down": "^6.0.2",
"express": "^4.16.4",
"helmet": "^3.16.0",
"home-dir": "^1.0.0",
"krl-compiler": "^1.3.0",
"krl-stdlib": "^1.3.0",
"level-json-coerce-null": "^1.0.1",
"leveldown": "^5.0.2",
"levelup": "^4.0.1",
"lodash": "^4.17.11",
"make-dir": "^3.0.0",
"memdown": "^5.1.0",
"minimist": "^1.2.5",
"pico-engine-core": "^1.3.0",
"pico-framework": "^0.6.0",
"pico-framework": "^0.7.0",
"rotating-file-stream": "^1.4.1",
"split": "^1.0.1",
"through2": "^3.0.1"
Expand All @@ -69,8 +66,6 @@
"@types/body-parser": "^1.17.0",
"@types/express": "^4.16.1",
"@types/helmet": "0.0.43",
"@types/leveldown": "^4.0.0",
"@types/levelup": "^3.1.0",
"@types/lodash": "^4.14.123",
"@types/node": "^20.8.10",
"ava": "^5.3.1",
Expand Down
16 changes: 6 additions & 10 deletions packages/pico-engine/src/RulesetRegistryLoaderFs.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import fetch from "cross-fetch";
import * as fs from "fs";
import leveldown from "leveldown";
import { default as level } from "levelup";
import { ClassicLevel } from "classic-level";
import * as makeDir from "make-dir";
import * as path from "path";
import { RulesetRegistryLoader } from "pico-engine-core";
import { Ruleset } from "pico-framework";
import { PicoDbKey, Ruleset } from "pico-framework";
import * as urlLib from "url";
const krlCompiler = require("krl-compiler");
const krlCompilerVersion = require("krl-compiler/package.json").version;
const charwise = require("charwise");
const encode = require("encoding-down");
const safeJsonCodec = require("level-json-coerce-null");

function getUrlFilename(url: string): string | null {
Expand Down Expand Up @@ -40,12 +38,10 @@ export function RulesetRegistryLoaderFs(
): RulesetRegistryLoader {
const rulesetDir = path.resolve(engineHomeDir, "rulesets");

const db = level(
encode(leveldown(path.resolve(engineHomeDir, "rulesets-db")), {
keyEncoding: charwise,
valueEncoding: safeJsonCodec,
})
);
const db = new ClassicLevel<PicoDbKey, any>(path.resolve(engineHomeDir, "rulesets-db"), {
keyEncoding: charwise,
valueEncoding: safeJsonCodec,
})

async function compileAndLoad(
url: string,
Expand Down
13 changes: 8 additions & 5 deletions packages/pico-engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { krl, KrlLogger, makeKrlLogger } from "krl-stdlib";
import leveldown from "leveldown";
import { ClassicLevel } from "classic-level";
import * as _ from "lodash";
import * as makeDir from "make-dir";
import * as path from "path";
import { PicoEngineCore, RulesetRegistry } from "pico-engine-core";
import { PicoFramework } from "pico-framework";
import { PicoDbKey, PicoFramework } from "pico-framework";
import { getPicoLogs, makeRotatingFileLogWriter } from "./logging";
import { RulesetRegistryLoaderFs } from "./RulesetRegistryLoaderFs";
import { server } from "./server";
import { toFileUrl } from "./utils/toFileUrl";
import * as fs from "fs";
import { reject } from "lodash";
const charwise = require("charwise");
const safeJsonCodec = require("level-json-coerce-null");

const homeDir = require("home-dir");
const version = require("../package.json").version;
Expand Down Expand Up @@ -85,7 +85,10 @@ export async function startEngine(
: makeKrlLogger(makeRotatingFileLogWriter(logFilePath));

const core = new PicoEngineCore({
leveldown: leveldown(path.resolve(home, "db")) as any,
db: new ClassicLevel<PicoDbKey, any>(path.resolve(home, "db"), {
keyEncoding: charwise,
valueEncoding: safeJsonCodec,
}),
rsRegLoader: RulesetRegistryLoaderFs(home),
log,
modules: configuration.modules,
Expand Down
21 changes: 9 additions & 12 deletions packages/pico-engine/test/test-rulesets/persistent.krl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,16 @@ test("persistent.krl", async t => {

/////////////////////////////////////////////////////////////////////////////
// clear vars
function dumpEnts(picoId: string) {
return new Promise((resolve, reject) => {
const list: any = [];
const s = pe.pf.db.createReadStream({
gte: ["entvar", picoId, "io.picolabs.persistent"],
lte: ["entvar", picoId, "io.picolabs.persistent", undefined]
});
s.on("error", err => reject(err));
s.on("end", () => resolve(list));
s.on("data", function(data) {
list.push([data.key.slice(3), data.value]);
});
async function dumpEnts(picoId: string) {
const list: any = [];
const iter = pe.pf.db.iterator({
gte: ["entvar", picoId, "io.picolabs.persistent"],
lte: ["entvar", picoId, "io.picolabs.persistent", undefined]
});
for await (const [key, value] of iter) {
list.push([key.slice(3), value]);
}
return list
}
t.deepEqual(await dumpEnts(picoIdA), [
[["name"], "Alf"],
Expand Down

0 comments on commit 854c775

Please sign in to comment.