@hazae41/bobine 0.1.4 → 0.1.5
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/README.md +1 -1
- package/out/mods/bobine/runner/mod.d.ts +1 -1
- package/out/mods/bobine/runner/mod.js +7 -13
- package/package.json +2 -2
- package/out/libs/packed/mod.d.ts +0 -13
- package/out/libs/packed/mod.js +0 -114
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ WebAssembly-based metered chain of compute
|
|
|
6
6
|
npm install @hazae41/bobine
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/bobine)
|
|
9
|
+
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/bobine)
|
|
10
10
|
|
|
11
11
|
## Ecosystem
|
|
12
12
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Nullable } from "../../../libs/nullable/mod.ts";
|
|
2
|
-
import { type Packable } from "
|
|
2
|
+
import { type Packable } from "@hazae41/webpack";
|
|
3
3
|
import { Database } from "@tursodatabase/database";
|
|
4
4
|
export interface Run {
|
|
5
5
|
readonly module: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// deno-lint-ignore-file no-unused-vars no-explicit-any
|
|
2
2
|
import { meter } from "../../../libs/metering/mod.js";
|
|
3
|
-
import { Packed } from "../../../libs/packed/mod.js";
|
|
4
3
|
import { runAsImmediate } from "../../../libs/sql/mod.js";
|
|
5
4
|
import { RpcPaymentError } from "../errors/mod.js";
|
|
6
5
|
import { Readable, Writable } from "@hazae41/binary";
|
|
7
6
|
import * as Wasm from "@hazae41/wasm";
|
|
7
|
+
import { Packed } from "@hazae41/webpack";
|
|
8
8
|
import { connect } from "@tursodatabase/database";
|
|
9
9
|
import { Buffer } from "node:buffer";
|
|
10
10
|
import { existsSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
|
|
@@ -72,12 +72,6 @@ export class Runner {
|
|
|
72
72
|
const caches = new Map();
|
|
73
73
|
const reads = new Array();
|
|
74
74
|
const writes = new Array();
|
|
75
|
-
const encode = (value) => {
|
|
76
|
-
return Writable.writeToBytes(new Packed(value));
|
|
77
|
-
};
|
|
78
|
-
const decode = (bytes) => {
|
|
79
|
-
return Readable.readFromBytes(Packed, bytes);
|
|
80
|
-
};
|
|
81
75
|
const consume = (amount) => {
|
|
82
76
|
sparks += BigInt(amount);
|
|
83
77
|
if (process.env.NODE_ENV === "development")
|
|
@@ -158,10 +152,10 @@ export class Runner {
|
|
|
158
152
|
return blob.toBase64();
|
|
159
153
|
},
|
|
160
154
|
encode: (value) => {
|
|
161
|
-
return encode(value);
|
|
155
|
+
return Packed.encode(value);
|
|
162
156
|
},
|
|
163
157
|
decode: (blob) => {
|
|
164
|
-
return decode(blob);
|
|
158
|
+
return Packed.decode(blob);
|
|
165
159
|
}
|
|
166
160
|
};
|
|
167
161
|
imports["texts"] = {
|
|
@@ -337,8 +331,8 @@ export class Runner {
|
|
|
337
331
|
set: (key, fresh) => {
|
|
338
332
|
const cache = caches.get(module);
|
|
339
333
|
cache.set(key, fresh);
|
|
340
|
-
const keyAsRaw = encode(key);
|
|
341
|
-
const valueAsRaw = encode(fresh);
|
|
334
|
+
const keyAsRaw = Packed.encode(key);
|
|
335
|
+
const valueAsRaw = Packed.encode(fresh);
|
|
342
336
|
writes.push([module, keyAsRaw, valueAsRaw]);
|
|
343
337
|
return;
|
|
344
338
|
},
|
|
@@ -347,13 +341,13 @@ export class Runner {
|
|
|
347
341
|
const stale = cache.get(key);
|
|
348
342
|
if (stale != null)
|
|
349
343
|
return [stale];
|
|
350
|
-
const keyAsRaw = encode(key);
|
|
344
|
+
const keyAsRaw = Packed.encode(key);
|
|
351
345
|
const row = await this.data.get(`SELECT value FROM events event WHERE event.module = ? AND event.key = ? ORDER BY event.nonce DESC LIMIT 1;`, module, keyAsRaw);
|
|
352
346
|
if (row == null)
|
|
353
347
|
return null;
|
|
354
348
|
const valueAsRaw = new Uint8Array(row.value);
|
|
355
349
|
reads.push([module, keyAsRaw, valueAsRaw]);
|
|
356
|
-
const fresh = decode(valueAsRaw);
|
|
350
|
+
const fresh = Packed.decode(valueAsRaw);
|
|
357
351
|
cache.set(key, fresh);
|
|
358
352
|
return [fresh];
|
|
359
353
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@hazae41/bobine",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"description": "WebAssembly-based metered chain of compute",
|
|
6
6
|
"repository": "github:hazae41/bobine",
|
|
7
7
|
"author": "hazae41",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@hazae41/binary": "^2.1.1",
|
|
24
|
-
"@hazae41/cursor": "^2.2.0",
|
|
25
24
|
"@hazae41/jsonrpc": "^1.2.1",
|
|
26
25
|
"@hazae41/wasm": "^1.0.2",
|
|
26
|
+
"@hazae41/webpack": "^1.0.0",
|
|
27
27
|
"@tursodatabase/database": "^0.8.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
package/out/libs/packed/mod.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Cursor } from "@hazae41/cursor";
|
|
2
|
-
export type Packable = null | number | Uint8Array | string | bigint | Array<Packable>;
|
|
3
|
-
export declare class Packed {
|
|
4
|
-
readonly value: Packable;
|
|
5
|
-
constructor(value: Packable);
|
|
6
|
-
size(): number;
|
|
7
|
-
write(cursor: Cursor): void;
|
|
8
|
-
}
|
|
9
|
-
export declare namespace Packed {
|
|
10
|
-
function read(cursor: Cursor): Packable;
|
|
11
|
-
function size(value: Packable): number;
|
|
12
|
-
function write(value: Packable, cursor: Cursor): void;
|
|
13
|
-
}
|
package/out/libs/packed/mod.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// deno-lint-ignore-file no-namespace
|
|
2
|
-
export class Packed {
|
|
3
|
-
value;
|
|
4
|
-
constructor(value) {
|
|
5
|
-
this.value = value;
|
|
6
|
-
}
|
|
7
|
-
size() {
|
|
8
|
-
return Packed.size(this.value);
|
|
9
|
-
}
|
|
10
|
-
write(cursor) {
|
|
11
|
-
Packed.write(this.value, cursor);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
(function (Packed) {
|
|
15
|
-
function read(cursor) {
|
|
16
|
-
const type = cursor.readUint8();
|
|
17
|
-
if (type === 0)
|
|
18
|
-
return null;
|
|
19
|
-
if (type === 1)
|
|
20
|
-
return cursor.readFloat64(true);
|
|
21
|
-
if (type === 2)
|
|
22
|
-
return cursor.read(cursor.readUint32(true));
|
|
23
|
-
if (type === 3) {
|
|
24
|
-
const size = cursor.readUint32(true);
|
|
25
|
-
const data = cursor.read(size);
|
|
26
|
-
return new TextDecoder().decode(data);
|
|
27
|
-
}
|
|
28
|
-
if (type === 4) {
|
|
29
|
-
const negative = cursor.readUint8();
|
|
30
|
-
const size = cursor.readUint32(true);
|
|
31
|
-
const data = cursor.read(size);
|
|
32
|
-
const absolute = BigInt("0x" + data.toHex());
|
|
33
|
-
return negative ? -absolute : absolute;
|
|
34
|
-
}
|
|
35
|
-
if (type === 5) {
|
|
36
|
-
const length = cursor.readUint32(true);
|
|
37
|
-
const values = new Array(length);
|
|
38
|
-
for (let i = 0; i < length; i++)
|
|
39
|
-
values[i] = read(cursor);
|
|
40
|
-
return values;
|
|
41
|
-
}
|
|
42
|
-
throw new Error("Unknown pack type");
|
|
43
|
-
}
|
|
44
|
-
Packed.read = read;
|
|
45
|
-
function size(value) {
|
|
46
|
-
if (value == null)
|
|
47
|
-
return 1;
|
|
48
|
-
if (typeof value === "number")
|
|
49
|
-
return 1 + 8;
|
|
50
|
-
if (value instanceof Uint8Array)
|
|
51
|
-
return 1 + 4 + value.length;
|
|
52
|
-
if (typeof value === "string")
|
|
53
|
-
return 1 + 4 + new TextEncoder().encode(value).length;
|
|
54
|
-
if (typeof value === "bigint") {
|
|
55
|
-
const absolute = value < 0n ? -value : value;
|
|
56
|
-
const text = absolute.toString(16);
|
|
57
|
-
const data = Uint8Array.fromHex(text.length % 2 === 1 ? "0" + text : text);
|
|
58
|
-
return 1 + 1 + 4 + data.length;
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(value)) {
|
|
61
|
-
let total = 0;
|
|
62
|
-
total += 1;
|
|
63
|
-
total += 4;
|
|
64
|
-
for (const subvalue of value)
|
|
65
|
-
total += size(subvalue);
|
|
66
|
-
return total;
|
|
67
|
-
}
|
|
68
|
-
throw new Error("Unknown pack value");
|
|
69
|
-
}
|
|
70
|
-
Packed.size = size;
|
|
71
|
-
function write(value, cursor) {
|
|
72
|
-
if (value == null) {
|
|
73
|
-
cursor.writeUint8(0);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (typeof value === "number") {
|
|
77
|
-
cursor.writeUint8(1);
|
|
78
|
-
cursor.writeFloat64(value, true);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (value instanceof Uint8Array) {
|
|
82
|
-
cursor.writeUint8(2);
|
|
83
|
-
cursor.writeUint32(value.length, true);
|
|
84
|
-
cursor.write(value);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (typeof value === "string") {
|
|
88
|
-
cursor.writeUint8(3);
|
|
89
|
-
const data = new TextEncoder().encode(value);
|
|
90
|
-
cursor.writeUint32(data.length, true);
|
|
91
|
-
cursor.write(data);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (typeof value === "bigint") {
|
|
95
|
-
cursor.writeUint8(4);
|
|
96
|
-
const [negative, absolute] = value < 0n ? [1, -value] : [0, value];
|
|
97
|
-
const text = absolute.toString(16);
|
|
98
|
-
const data = Uint8Array.fromHex(text.length % 2 === 1 ? "0" + text : text);
|
|
99
|
-
cursor.writeUint8(negative);
|
|
100
|
-
cursor.writeUint32(data.length, true);
|
|
101
|
-
cursor.write(data);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (Array.isArray(value)) {
|
|
105
|
-
cursor.writeUint8(5);
|
|
106
|
-
cursor.writeUint32(value.length, true);
|
|
107
|
-
for (const subvalue of value)
|
|
108
|
-
write(subvalue, cursor);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
throw new Error("Unknown pack value");
|
|
112
|
-
}
|
|
113
|
-
Packed.write = write;
|
|
114
|
-
})(Packed || (Packed = {}));
|