@econ-v1/app-sdk 7.0.77 → 7.0.79
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 +35 -0
- package/dist/burger/index.js +2 -0
- package/dist/burger-build/aliases.d.ts +28 -0
- package/dist/burger-build/build.d.ts +19 -0
- package/dist/burger-build/bun-version.d.ts +8 -0
- package/dist/burger-build/cli.js +844 -0
- package/dist/burger-build/gate.d.ts +28 -0
- package/dist/burger-build/index.d.ts +9 -0
- package/dist/burger-build/index.js +785 -0
- package/dist/burger-build/plugin.d.ts +25 -0
- package/dist/burger-build/test-prepare.d.ts +68 -0
- package/dist/burger-types/aliases.d.ts +20 -0
- package/dist/burger-types/globals.d.ts +66 -0
- package/dist/burger-types/index.d.ts +3 -0
- package/dist/burger-types/modules.d.ts +436 -0
- package/dist/index.d.ts +11 -18
- package/dist/index.js +11 -11
- package/dist/otel-burger.d.ts +5 -0
- package/dist/platform/bun.d.ts +34 -0
- package/dist/platform/burger.d.ts +47 -0
- package/dist/platform/conformance.d.ts +25 -0
- package/dist/platform/types.d.ts +47 -0
- package/package.json +41 -3
- package/dist/__tests__/lease-drain-socket.integration.test.d.ts +0 -1
- package/dist/__tests__/lease-drain.fixture.d.ts +0 -1
- package/dist/__tests__/otel.test.d.ts +0 -1
- package/dist/__tests__/worker-context.test.d.ts +0 -1
- package/dist/__tests__/worker-exit.fixture.d.ts +0 -1
- package/dist/__tests__/worker-exit.integration.test.d.ts +0 -1
- package/dist/index.test.d.ts +0 -1
- package/dist/managed-v1.test.d.ts +0 -1
- package/dist/memory.test.d.ts +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BunPlugin } from "bun";
|
|
2
|
+
import { type BurgerModule } from "./aliases.ts";
|
|
3
|
+
export interface ImportViolation {
|
|
4
|
+
specifier: string;
|
|
5
|
+
/** Absolute path of the importing file. */
|
|
6
|
+
importer: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
}
|
|
9
|
+
export interface GateState {
|
|
10
|
+
violations: ImportViolation[];
|
|
11
|
+
}
|
|
12
|
+
export declare const BRIDGE_NAMESPACE = "burger-require";
|
|
13
|
+
/**
|
|
14
|
+
* CommonJS `require("fs")` cannot be left external: the output would call
|
|
15
|
+
* a `__require` shim that does not exist in QuickJS. Instead it resolves to
|
|
16
|
+
* this ESM module, which the bundler links into the CommonJS wrapper.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bridgeSource(target: BurgerModule): string;
|
|
19
|
+
/**
|
|
20
|
+
* Resolves every `burger:*` and C6-aliased specifier to an external
|
|
21
|
+
* `burger:*` import, and records (and externalises, so the build can finish
|
|
22
|
+
* and report every problem at once) every other `node:*`, `bun:*`, Node
|
|
23
|
+
* built-in and native addon import.
|
|
24
|
+
*/
|
|
25
|
+
export declare function burgerResolvePlugin(state: GateState): BunPlugin;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Problem } from "./gate.ts";
|
|
2
|
+
export interface TestPrepareOptions {
|
|
3
|
+
/** App source directory (colocated `*.test.ts` files are tests too). */
|
|
4
|
+
src: string;
|
|
5
|
+
/** Separate test directory, when the app has one. */
|
|
6
|
+
tests?: string;
|
|
7
|
+
/** Output directory; deleted and recreated. */
|
|
8
|
+
out: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TestPlanEntry {
|
|
11
|
+
/** Absolute path of the test file as written. */
|
|
12
|
+
source: string;
|
|
13
|
+
/** Absolute path of the prepared ES module that `node-app-burger test` runs. */
|
|
14
|
+
output: string;
|
|
15
|
+
}
|
|
16
|
+
/** `<out>/test-plan.json`, read by `node-app test`. */
|
|
17
|
+
export interface TestPlan {
|
|
18
|
+
importMap: string;
|
|
19
|
+
tests: TestPlanEntry[];
|
|
20
|
+
}
|
|
21
|
+
/** `<out>/importmap.json` (Contract C8). */
|
|
22
|
+
export interface ImportMap {
|
|
23
|
+
imports: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
export type TestPrepareOutcome = {
|
|
26
|
+
ok: true;
|
|
27
|
+
plan: TestPlan;
|
|
28
|
+
importMap: ImportMap;
|
|
29
|
+
} | {
|
|
30
|
+
ok: false;
|
|
31
|
+
report: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function commonAncestor(dirs: readonly string[]): string;
|
|
34
|
+
/** `tests/db.test.ts` → `tests/db.test.js`. */
|
|
35
|
+
export declare function preparedPath(relativePath: string): string;
|
|
36
|
+
/** `@econ-v1/app-sdk` → `econ-v1__app-sdk.js`. */
|
|
37
|
+
export declare function dependencyFileName(specifier: string): string;
|
|
38
|
+
interface Workspace {
|
|
39
|
+
root: string;
|
|
40
|
+
sources: ReadonlySet<string>;
|
|
41
|
+
jsonFiles: Set<string>;
|
|
42
|
+
dependencies: Set<string>;
|
|
43
|
+
problems: Problem[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* What a prepared module imports instead of `specifier` (written in
|
|
47
|
+
* `importer`). Returns undefined — with a recorded problem — when the import
|
|
48
|
+
* cannot work under Burger.
|
|
49
|
+
*/
|
|
50
|
+
export declare function rewriteSpecifier(ws: Workspace, importer: string, specifier: string): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Problems for a module that statically imports a module it also replaces
|
|
53
|
+
* with `mock.module`. Bun patches the already-linked bindings, so the test
|
|
54
|
+
* passes there; Burger links static imports before any code runs, so the
|
|
55
|
+
* test would silently exercise the real module.
|
|
56
|
+
*/
|
|
57
|
+
export declare function staticallyImportedMocks(file: string, code: string, imports: readonly {
|
|
58
|
+
kind: string;
|
|
59
|
+
path: string;
|
|
60
|
+
}[]): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Turn an app's sources and tests into files `node-app-burger test` can run:
|
|
63
|
+
* one transpiled ES module per source file (module boundaries preserved so
|
|
64
|
+
* `mock.module` can replace them), one pre-bundled file per bare
|
|
65
|
+
* dependency specifier, and `importmap.json` (Contract C8).
|
|
66
|
+
*/
|
|
67
|
+
export declare function prepareTests(options: TestPrepareOptions): Promise<TestPrepareOutcome>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Specifiers the burger-build bundler rewrites to burger:* (Contracts C5, C6).
|
|
2
|
+
// Typing them here keeps existing `node:`/`bun:` imports compiling with the
|
|
3
|
+
// exact Phase 1 subset — anything outside it is a type error.
|
|
4
|
+
|
|
5
|
+
declare module "node:fs" { export * from "burger:fs"; export { default } from "burger:fs"; }
|
|
6
|
+
declare module "fs" { export * from "burger:fs"; export { default } from "burger:fs"; }
|
|
7
|
+
declare module "node:fs/promises" { export * from "burger:fs/promises"; export { default } from "burger:fs/promises"; }
|
|
8
|
+
declare module "fs/promises" { export * from "burger:fs/promises"; export { default } from "burger:fs/promises"; }
|
|
9
|
+
declare module "node:path" { export * from "burger:path"; export { default } from "burger:path"; }
|
|
10
|
+
declare module "path" { export * from "burger:path"; export { default } from "burger:path"; }
|
|
11
|
+
declare module "node:os" { export * from "burger:os"; export { default } from "burger:os"; }
|
|
12
|
+
declare module "os" { export * from "burger:os"; export { default } from "burger:os"; }
|
|
13
|
+
declare module "node:worker_threads" { export * from "burger:worker_threads"; export { default } from "burger:worker_threads"; }
|
|
14
|
+
declare module "worker_threads" { export * from "burger:worker_threads"; export { default } from "burger:worker_threads"; }
|
|
15
|
+
declare module "node:crypto" { export * from "burger:crypto"; export { default } from "burger:crypto"; }
|
|
16
|
+
declare module "crypto" { export * from "burger:crypto"; export { default } from "burger:crypto"; }
|
|
17
|
+
declare module "node:buffer" { export * from "burger:buffer"; export { default } from "burger:buffer"; }
|
|
18
|
+
declare module "buffer" { export * from "burger:buffer"; export { default } from "burger:buffer"; }
|
|
19
|
+
declare module "bun:sqlite" { export * from "burger:sqlite"; export { default } from "burger:sqlite"; }
|
|
20
|
+
declare module "bun:test" { export * from "burger:test"; }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Globals present in every Burger runtime in Phase 1 (Contract C5).
|
|
2
|
+
// Pair with `"lib": ["ES2023"]` and no DOM lib: fetch, URL, streams, etc. are
|
|
3
|
+
// deliberately absent until Phase 2.
|
|
4
|
+
|
|
5
|
+
interface BurgerConsole {
|
|
6
|
+
log(...data: unknown[]): void;
|
|
7
|
+
info(...data: unknown[]): void;
|
|
8
|
+
warn(...data: unknown[]): void;
|
|
9
|
+
error(...data: unknown[]): void;
|
|
10
|
+
debug(...data: unknown[]): void;
|
|
11
|
+
}
|
|
12
|
+
declare var console: BurgerConsole;
|
|
13
|
+
|
|
14
|
+
declare function setTimeout(handler: (...args: any[]) => void, timeoutMs?: number, ...args: any[]): number;
|
|
15
|
+
declare function clearTimeout(id: number | undefined): void;
|
|
16
|
+
declare function setInterval(handler: (...args: any[]) => void, timeoutMs?: number, ...args: any[]): number;
|
|
17
|
+
declare function clearInterval(id: number | undefined): void;
|
|
18
|
+
declare function queueMicrotask(callback: () => void): void;
|
|
19
|
+
|
|
20
|
+
declare class TextEncoder {
|
|
21
|
+
constructor();
|
|
22
|
+
readonly encoding: "utf-8";
|
|
23
|
+
encode(input?: string): Uint8Array;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare class TextDecoder {
|
|
27
|
+
constructor(label?: "utf-8" | "utf8", options?: { fatal?: boolean; ignoreBOM?: boolean });
|
|
28
|
+
readonly encoding: "utf-8";
|
|
29
|
+
decode(input?: Uint8Array | ArrayBuffer): string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare var performance: { now(): number };
|
|
33
|
+
|
|
34
|
+
interface BurgerCrypto {
|
|
35
|
+
randomUUID(): string;
|
|
36
|
+
getRandomValues<T extends Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array>(array: T): T;
|
|
37
|
+
}
|
|
38
|
+
declare var crypto: BurgerCrypto;
|
|
39
|
+
|
|
40
|
+
declare var Buffer: import("burger:buffer").BufferConstructor;
|
|
41
|
+
type Buffer = import("burger:buffer").Buffer;
|
|
42
|
+
|
|
43
|
+
declare function structuredClone<T>(value: T): T;
|
|
44
|
+
|
|
45
|
+
interface BurgerProcessMemoryUsage {
|
|
46
|
+
heapUsed: number;
|
|
47
|
+
heapTotal: number;
|
|
48
|
+
external: number;
|
|
49
|
+
rss: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BurgerProcess {
|
|
53
|
+
/** Per-app and mutable: writes and deletes never reach the OS environment. */
|
|
54
|
+
env: Record<string, string | undefined>;
|
|
55
|
+
readonly argv: string[];
|
|
56
|
+
readonly platform: "linux" | "darwin";
|
|
57
|
+
readonly arch: "arm64" | "x64";
|
|
58
|
+
exit(code: number): never;
|
|
59
|
+
on(event: "uncaughtException", listener: (error: unknown) => void): void;
|
|
60
|
+
on(event: "unhandledRejection", listener: (reason: unknown) => void): void;
|
|
61
|
+
on(event: string, listener: (...args: unknown[]) => void): void;
|
|
62
|
+
off(event: string, listener: (...args: any[]) => void): void;
|
|
63
|
+
nextTick(callback: (...args: any[]) => void, ...args: any[]): void;
|
|
64
|
+
memoryUsage(): BurgerProcessMemoryUsage;
|
|
65
|
+
}
|
|
66
|
+
declare var process: BurgerProcess;
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
// burger:* module declarations — Contract C4 (burger:host) and C6 (Phase 1 modules).
|
|
2
|
+
// Anything not declared here is not provided by Burger Phase 1.
|
|
3
|
+
// Modules provided under a Node or Bun name also have a `default` export: an
|
|
4
|
+
// object containing all their named exports (C6).
|
|
5
|
+
|
|
6
|
+
declare module "burger:host" {
|
|
7
|
+
/** Per-app identity and paths, fixed at runtime creation. */
|
|
8
|
+
export const appId: string;
|
|
9
|
+
export const dataDir: string;
|
|
10
|
+
export const logDir: string;
|
|
11
|
+
export const entryPoint: string;
|
|
12
|
+
export const config: unknown;
|
|
13
|
+
|
|
14
|
+
export interface HostChannel {
|
|
15
|
+
/** Serialise `frame` with serde_json, append "\n", write. Throws TypeError if not JSON-serialisable. */
|
|
16
|
+
send(frame: object): void;
|
|
17
|
+
/** Register the frame handler. Replaces any previous handler. */
|
|
18
|
+
onFrame(handler: (frame: any) => void): void;
|
|
19
|
+
/** Called once when the connection closes; `error` is set when it closed abnormally. */
|
|
20
|
+
onClose(handler: (error?: Error) => void): void;
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Open the app channel. Calling it twice returns the same channel. */
|
|
25
|
+
export function connect(): HostChannel;
|
|
26
|
+
|
|
27
|
+
/** QuickJS runtime memory for THIS app, in KiB. */
|
|
28
|
+
export function memoryUsage(): {
|
|
29
|
+
heap_used_kb: number;
|
|
30
|
+
heap_total_kb: number;
|
|
31
|
+
external_kb: number;
|
|
32
|
+
heap_capacity_kb: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Stop this app. Never returns. */
|
|
36
|
+
export function exit(code: number): never;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module "burger:fs" {
|
|
40
|
+
export type PathLike = string;
|
|
41
|
+
export type Utf8Encoding = "utf8" | "utf-8";
|
|
42
|
+
|
|
43
|
+
export interface Stats {
|
|
44
|
+
isFile(): boolean;
|
|
45
|
+
isDirectory(): boolean;
|
|
46
|
+
readonly size: number;
|
|
47
|
+
readonly mtimeMs: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function existsSync(path: PathLike): boolean;
|
|
51
|
+
export function readFileSync(path: PathLike): Uint8Array;
|
|
52
|
+
export function readFileSync(path: PathLike, encoding: Utf8Encoding | { encoding: Utf8Encoding }): string;
|
|
53
|
+
export function writeFileSync(path: PathLike, data: string | Uint8Array): void;
|
|
54
|
+
export function appendFileSync(path: PathLike, data: string | Uint8Array): void;
|
|
55
|
+
export function mkdirSync(path: PathLike, options?: { recursive?: boolean }): void;
|
|
56
|
+
export function readdirSync(path: PathLike): string[];
|
|
57
|
+
export function statSync(path: PathLike): Stats;
|
|
58
|
+
export function rmSync(path: PathLike, options?: { recursive?: boolean; force?: boolean }): void;
|
|
59
|
+
export function renameSync(oldPath: PathLike, newPath: PathLike): void;
|
|
60
|
+
export function chmodSync(path: PathLike, mode: number): void;
|
|
61
|
+
export function unlinkSync(path: PathLike): void;
|
|
62
|
+
/** Create a unique directory whose name starts with `prefix`; returns its path. */
|
|
63
|
+
export function mkdtempSync(prefix: string): string;
|
|
64
|
+
|
|
65
|
+
export interface FsPromises {
|
|
66
|
+
exists(path: PathLike): Promise<boolean>;
|
|
67
|
+
readFile(path: PathLike): Promise<Uint8Array>;
|
|
68
|
+
readFile(path: PathLike, encoding: Utf8Encoding | { encoding: Utf8Encoding }): Promise<string>;
|
|
69
|
+
writeFile(path: PathLike, data: string | Uint8Array): Promise<void>;
|
|
70
|
+
appendFile(path: PathLike, data: string | Uint8Array): Promise<void>;
|
|
71
|
+
mkdir(path: PathLike, options?: { recursive?: boolean }): Promise<void>;
|
|
72
|
+
readdir(path: PathLike): Promise<string[]>;
|
|
73
|
+
stat(path: PathLike): Promise<Stats>;
|
|
74
|
+
rm(path: PathLike, options?: { recursive?: boolean; force?: boolean }): Promise<void>;
|
|
75
|
+
rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
76
|
+
chmod(path: PathLike, mode: number): Promise<void>;
|
|
77
|
+
unlink(path: PathLike): Promise<void>;
|
|
78
|
+
mkdtemp(prefix: string): Promise<string>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const promises: FsPromises;
|
|
82
|
+
|
|
83
|
+
const fs: {
|
|
84
|
+
existsSync: typeof existsSync;
|
|
85
|
+
readFileSync: typeof readFileSync;
|
|
86
|
+
writeFileSync: typeof writeFileSync;
|
|
87
|
+
appendFileSync: typeof appendFileSync;
|
|
88
|
+
mkdirSync: typeof mkdirSync;
|
|
89
|
+
readdirSync: typeof readdirSync;
|
|
90
|
+
statSync: typeof statSync;
|
|
91
|
+
rmSync: typeof rmSync;
|
|
92
|
+
renameSync: typeof renameSync;
|
|
93
|
+
chmodSync: typeof chmodSync;
|
|
94
|
+
unlinkSync: typeof unlinkSync;
|
|
95
|
+
mkdtempSync: typeof mkdtempSync;
|
|
96
|
+
promises: FsPromises;
|
|
97
|
+
};
|
|
98
|
+
export default fs;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare module "burger:fs/promises" {
|
|
102
|
+
import type { FsPromises } from "burger:fs";
|
|
103
|
+
export const exists: FsPromises["exists"];
|
|
104
|
+
export const readFile: FsPromises["readFile"];
|
|
105
|
+
export const writeFile: FsPromises["writeFile"];
|
|
106
|
+
export const appendFile: FsPromises["appendFile"];
|
|
107
|
+
export const mkdir: FsPromises["mkdir"];
|
|
108
|
+
export const readdir: FsPromises["readdir"];
|
|
109
|
+
export const stat: FsPromises["stat"];
|
|
110
|
+
export const rm: FsPromises["rm"];
|
|
111
|
+
export const rename: FsPromises["rename"];
|
|
112
|
+
export const chmod: FsPromises["chmod"];
|
|
113
|
+
export const unlink: FsPromises["unlink"];
|
|
114
|
+
export const mkdtemp: FsPromises["mkdtemp"];
|
|
115
|
+
const fsPromises: FsPromises;
|
|
116
|
+
export default fsPromises;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare module "burger:path" {
|
|
120
|
+
export interface ParsedPath {
|
|
121
|
+
root: string;
|
|
122
|
+
dir: string;
|
|
123
|
+
base: string;
|
|
124
|
+
ext: string;
|
|
125
|
+
name: string;
|
|
126
|
+
}
|
|
127
|
+
export interface PathModule {
|
|
128
|
+
join(...paths: string[]): string;
|
|
129
|
+
resolve(...paths: string[]): string;
|
|
130
|
+
dirname(path: string): string;
|
|
131
|
+
basename(path: string, suffix?: string): string;
|
|
132
|
+
extname(path: string): string;
|
|
133
|
+
relative(from: string, to: string): string;
|
|
134
|
+
normalize(path: string): string;
|
|
135
|
+
isAbsolute(path: string): boolean;
|
|
136
|
+
readonly sep: "/";
|
|
137
|
+
readonly delimiter: ":";
|
|
138
|
+
parse(path: string): ParsedPath;
|
|
139
|
+
format(pathObject: Partial<ParsedPath>): string;
|
|
140
|
+
}
|
|
141
|
+
export const join: PathModule["join"];
|
|
142
|
+
export const resolve: PathModule["resolve"];
|
|
143
|
+
export const dirname: PathModule["dirname"];
|
|
144
|
+
export const basename: PathModule["basename"];
|
|
145
|
+
export const extname: PathModule["extname"];
|
|
146
|
+
export const relative: PathModule["relative"];
|
|
147
|
+
export const normalize: PathModule["normalize"];
|
|
148
|
+
export const isAbsolute: PathModule["isAbsolute"];
|
|
149
|
+
export const sep: PathModule["sep"];
|
|
150
|
+
export const delimiter: PathModule["delimiter"];
|
|
151
|
+
export const parse: PathModule["parse"];
|
|
152
|
+
export const format: PathModule["format"];
|
|
153
|
+
const path: PathModule;
|
|
154
|
+
export default path;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
declare module "burger:os" {
|
|
158
|
+
export interface CpuInfo {
|
|
159
|
+
model: string;
|
|
160
|
+
speed: number;
|
|
161
|
+
}
|
|
162
|
+
export interface OsModule {
|
|
163
|
+
platform(): "linux" | "darwin";
|
|
164
|
+
arch(): "arm64" | "x64";
|
|
165
|
+
cpus(): CpuInfo[];
|
|
166
|
+
totalmem(): number;
|
|
167
|
+
freemem(): number;
|
|
168
|
+
hostname(): string;
|
|
169
|
+
tmpdir(): string;
|
|
170
|
+
homedir(): string;
|
|
171
|
+
readonly EOL: string;
|
|
172
|
+
}
|
|
173
|
+
export const platform: OsModule["platform"];
|
|
174
|
+
export const arch: OsModule["arch"];
|
|
175
|
+
export const cpus: OsModule["cpus"];
|
|
176
|
+
export const totalmem: OsModule["totalmem"];
|
|
177
|
+
export const freemem: OsModule["freemem"];
|
|
178
|
+
export const hostname: OsModule["hostname"];
|
|
179
|
+
export const tmpdir: OsModule["tmpdir"];
|
|
180
|
+
export const homedir: OsModule["homedir"];
|
|
181
|
+
export const EOL: OsModule["EOL"];
|
|
182
|
+
const os: OsModule;
|
|
183
|
+
export default os;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare module "burger:worker_threads" {
|
|
187
|
+
export const isMainThread: true;
|
|
188
|
+
export const workerData: undefined;
|
|
189
|
+
export const parentPort: null;
|
|
190
|
+
export const threadId: 0;
|
|
191
|
+
const workerThreads: {
|
|
192
|
+
isMainThread: true;
|
|
193
|
+
workerData: undefined;
|
|
194
|
+
parentPort: null;
|
|
195
|
+
threadId: 0;
|
|
196
|
+
};
|
|
197
|
+
export default workerThreads;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare module "burger:crypto" {
|
|
201
|
+
export type HashAlgorithm = "sha256" | "sha512" | "sha1";
|
|
202
|
+
export type DigestEncoding = "hex" | "base64";
|
|
203
|
+
export interface Hash {
|
|
204
|
+
update(data: string | Uint8Array): Hash;
|
|
205
|
+
digest(): Uint8Array;
|
|
206
|
+
digest(encoding: DigestEncoding): string;
|
|
207
|
+
}
|
|
208
|
+
export type Hmac = Hash;
|
|
209
|
+
export function randomUUID(): string;
|
|
210
|
+
export function randomBytes(size: number): Uint8Array;
|
|
211
|
+
export function createHash(algorithm: HashAlgorithm): Hash;
|
|
212
|
+
export function createHmac(algorithm: HashAlgorithm, key: string | Uint8Array): Hmac;
|
|
213
|
+
export function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
214
|
+
const crypto: {
|
|
215
|
+
randomUUID: typeof randomUUID;
|
|
216
|
+
randomBytes: typeof randomBytes;
|
|
217
|
+
createHash: typeof createHash;
|
|
218
|
+
createHmac: typeof createHmac;
|
|
219
|
+
timingSafeEqual: typeof timingSafeEqual;
|
|
220
|
+
};
|
|
221
|
+
export default crypto;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare module "burger:buffer" {
|
|
225
|
+
export type BufferEncoding = "utf8" | "utf-8" | "hex" | "base64" | "base64url";
|
|
226
|
+
|
|
227
|
+
/** C5 subset of Node's Buffer. Instances are `Uint8Array`s. */
|
|
228
|
+
export interface Buffer extends Uint8Array<ArrayBuffer> {
|
|
229
|
+
toString(encoding?: BufferEncoding): string;
|
|
230
|
+
equals(other: Uint8Array): boolean;
|
|
231
|
+
subarray(start?: number, end?: number): Buffer;
|
|
232
|
+
slice(start?: number, end?: number): Buffer;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface BufferConstructor {
|
|
236
|
+
readonly prototype: Buffer;
|
|
237
|
+
from(value: string, encoding?: BufferEncoding): Buffer;
|
|
238
|
+
from(value: Uint8Array | ArrayBuffer | readonly number[]): Buffer;
|
|
239
|
+
alloc(size: number): Buffer;
|
|
240
|
+
concat(list: readonly Uint8Array[]): Buffer;
|
|
241
|
+
isBuffer(value: unknown): value is Buffer;
|
|
242
|
+
byteLength(value: string): number;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const Buffer: BufferConstructor;
|
|
246
|
+
const buffer: { Buffer: BufferConstructor };
|
|
247
|
+
export default buffer;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
declare module "burger:sqlite" {
|
|
251
|
+
export type SQLValue = null | number | bigint | string | Uint8Array;
|
|
252
|
+
export type SQLBinding = SQLValue | boolean | undefined;
|
|
253
|
+
export type SQLParams =
|
|
254
|
+
| SQLBinding[]
|
|
255
|
+
| [SQLBinding[]]
|
|
256
|
+
| [Record<string, SQLBinding>];
|
|
257
|
+
|
|
258
|
+
export interface Changes {
|
|
259
|
+
changes: number;
|
|
260
|
+
lastInsertRowid: number | bigint;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface Statement<Row = unknown> {
|
|
264
|
+
all(...params: SQLParams): Row[];
|
|
265
|
+
get(...params: SQLParams): Row | null;
|
|
266
|
+
run(...params: SQLParams): Changes;
|
|
267
|
+
values(...params: SQLParams): SQLValue[][];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface DatabaseOptions {
|
|
271
|
+
create?: boolean;
|
|
272
|
+
readonly?: boolean;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export class Database {
|
|
276
|
+
constructor(filename?: string, options?: DatabaseOptions);
|
|
277
|
+
query<Row = unknown>(sql: string): Statement<Row>;
|
|
278
|
+
prepare<Row = unknown>(sql: string): Statement<Row>;
|
|
279
|
+
exec(sql: string, ...params: SQLParams): Changes;
|
|
280
|
+
run(sql: string, ...params: SQLParams): Changes;
|
|
281
|
+
transaction<Args extends unknown[], Result>(fn: (...args: Args) => Result): (...args: Args) => Result;
|
|
282
|
+
close(): void;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Default export is the Database class itself, which also carries `.Database` (C6). */
|
|
286
|
+
const sqlite: typeof Database & { Database: typeof Database };
|
|
287
|
+
export default sqlite;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
declare module "burger:test" {
|
|
291
|
+
export type TestBody = () => void | Promise<unknown>;
|
|
292
|
+
/** A per-test timeout in milliseconds, or `{ timeout }` (as bun:test accepts). */
|
|
293
|
+
export type TestOptions = number | { timeout?: number };
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* `test.each(table)(title, fn)`: one test per row. A row that is an array is
|
|
297
|
+
* spread into `fn`'s arguments; `title` takes `%s %d %i %f %j %o %p %#`.
|
|
298
|
+
*/
|
|
299
|
+
export interface EachFunction {
|
|
300
|
+
<Row extends readonly unknown[]>(table: readonly Row[]): (
|
|
301
|
+
title: string,
|
|
302
|
+
fn: (...args: Row) => void | Promise<unknown>,
|
|
303
|
+
options?: TestOptions,
|
|
304
|
+
) => void;
|
|
305
|
+
<Row>(table: readonly Row[]): (title: string, fn: (arg: Row) => void | Promise<unknown>, options?: TestOptions) => void;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export interface DescribeEachFunction {
|
|
309
|
+
<Row extends readonly unknown[]>(table: readonly Row[]): (title: string, fn: (...args: Row) => void) => void;
|
|
310
|
+
<Row>(table: readonly Row[]): (title: string, fn: (arg: Row) => void) => void;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface TestFunction {
|
|
314
|
+
(name: string, fn: TestBody, options?: TestOptions): void;
|
|
315
|
+
skip(name: string, fn?: TestBody, options?: TestOptions): void;
|
|
316
|
+
only(name: string, fn: TestBody, options?: TestOptions): void;
|
|
317
|
+
todo(name: string, fn?: TestBody): void;
|
|
318
|
+
each: EachFunction;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface DescribeFunction {
|
|
322
|
+
(name: string, fn: () => void): void;
|
|
323
|
+
skip(name: string, fn: () => void): void;
|
|
324
|
+
only(name: string, fn: () => void): void;
|
|
325
|
+
todo(name: string, fn?: () => void): void;
|
|
326
|
+
each: DescribeEachFunction;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export const describe: DescribeFunction;
|
|
330
|
+
export const test: TestFunction;
|
|
331
|
+
export const it: TestFunction;
|
|
332
|
+
|
|
333
|
+
export function beforeEach(fn: TestBody): void;
|
|
334
|
+
export function afterEach(fn: TestBody): void;
|
|
335
|
+
export function beforeAll(fn: TestBody): void;
|
|
336
|
+
export function afterAll(fn: TestBody): void;
|
|
337
|
+
export function setDefaultTimeout(ms: number): void;
|
|
338
|
+
|
|
339
|
+
export interface Matchers<R> {
|
|
340
|
+
toBe(expected: unknown): R;
|
|
341
|
+
toContain(expected: unknown): R;
|
|
342
|
+
toEqual(expected: unknown): R;
|
|
343
|
+
toStrictEqual(expected: unknown): R;
|
|
344
|
+
toHaveLength(length: number): R;
|
|
345
|
+
toBeDefined(): R;
|
|
346
|
+
toBeUndefined(): R;
|
|
347
|
+
toBeNull(): R;
|
|
348
|
+
toBeTruthy(): R;
|
|
349
|
+
toBeFalsy(): R;
|
|
350
|
+
toHaveProperty(keyPath: string | string[], value?: unknown): R;
|
|
351
|
+
toMatchObject(expected: object): R;
|
|
352
|
+
toMatch(expected: string | RegExp): R;
|
|
353
|
+
toBeGreaterThan(expected: number | bigint): R;
|
|
354
|
+
toBeGreaterThanOrEqual(expected: number | bigint): R;
|
|
355
|
+
toBeLessThan(expected: number | bigint): R;
|
|
356
|
+
toBeLessThanOrEqual(expected: number | bigint): R;
|
|
357
|
+
/** `|expected - actual| < 10^-digits / 2`; `digits` defaults to 2. */
|
|
358
|
+
toBeCloseTo(expected: number, digits?: number): R;
|
|
359
|
+
toStartWith(prefix: string): R;
|
|
360
|
+
toThrow(expected?: string | RegExp | Error | AsymmetricMatcher | (new (...args: any[]) => Error)): R;
|
|
361
|
+
toBeInstanceOf(expected: abstract new (...args: any[]) => unknown): R;
|
|
362
|
+
toContainEqual(expected: unknown): R;
|
|
363
|
+
/** The subject is a `mock()` function. */
|
|
364
|
+
toHaveBeenCalled(): R;
|
|
365
|
+
toHaveBeenCalledTimes(count: number): R;
|
|
366
|
+
toHaveBeenCalledWith(...args: unknown[]): R;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface Expect extends Matchers<void> {
|
|
370
|
+
readonly not: Matchers<void>;
|
|
371
|
+
readonly resolves: Matchers<Promise<void>> & { readonly not: Matchers<Promise<void>> };
|
|
372
|
+
readonly rejects: Matchers<Promise<void>> & { readonly not: Matchers<Promise<void>> };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Placeholder accepted wherever an expected value is (`toEqual`, `toContainEqual`, `toHaveBeenCalledWith`, …). */
|
|
376
|
+
export interface AsymmetricMatcher {
|
|
377
|
+
asymmetricMatch(other: unknown): boolean;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface ExpectFunction {
|
|
381
|
+
(actual: unknown): Expect;
|
|
382
|
+
/** Matches any value created by `constructor` (or of that primitive type for `Number`, `String`, …). */
|
|
383
|
+
any(constructor: abstract new (...args: any[]) => unknown): AsymmetricMatcher;
|
|
384
|
+
/** Matches anything but `null` and `undefined`. */
|
|
385
|
+
anything(): AsymmetricMatcher;
|
|
386
|
+
/** Matches any object that has at least `sample`'s properties with equal values. */
|
|
387
|
+
objectContaining(sample: object): AsymmetricMatcher;
|
|
388
|
+
/** Matches any array that contains an element equal to each of `items`. */
|
|
389
|
+
arrayContaining(items: readonly unknown[]): AsymmetricMatcher;
|
|
390
|
+
stringContaining(text: string): AsymmetricMatcher;
|
|
391
|
+
stringMatching(pattern: string | RegExp): AsymmetricMatcher;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export const expect: ExpectFunction;
|
|
395
|
+
|
|
396
|
+
export type AnyFunction = (...args: any[]) => any;
|
|
397
|
+
|
|
398
|
+
export type MockResult<T> = { readonly type: "return"; readonly value: T } | { readonly type: "throw"; readonly value: unknown };
|
|
399
|
+
|
|
400
|
+
export interface MockState<F extends AnyFunction> {
|
|
401
|
+
readonly calls: Parameters<F>[];
|
|
402
|
+
readonly results: MockResult<ReturnType<F>>[];
|
|
403
|
+
/** `this` of each call. */
|
|
404
|
+
readonly instances: unknown[];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export interface Mock<F extends AnyFunction> {
|
|
408
|
+
(...args: Parameters<F>): ReturnType<F>;
|
|
409
|
+
readonly mock: MockState<F>;
|
|
410
|
+
mockImplementation(fn: F): Mock<F>;
|
|
411
|
+
mockImplementationOnce(fn: F): Mock<F>;
|
|
412
|
+
mockReturnValue(value: ReturnType<F>): Mock<F>;
|
|
413
|
+
mockReturnValueOnce(value: ReturnType<F>): Mock<F>;
|
|
414
|
+
mockResolvedValue(value: Awaited<ReturnType<F>>): Mock<F>;
|
|
415
|
+
mockResolvedValueOnce(value: Awaited<ReturnType<F>>): Mock<F>;
|
|
416
|
+
mockRejectedValue(error: unknown): Mock<F>;
|
|
417
|
+
mockRejectedValueOnce(error: unknown): Mock<F>;
|
|
418
|
+
/** Forget recorded calls, results and instances; keep the implementation. */
|
|
419
|
+
mockClear(): Mock<F>;
|
|
420
|
+
/** `mockClear()`, and drop every implementation (calls then return `undefined`). */
|
|
421
|
+
mockReset(): Mock<F>;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export interface MockFactory {
|
|
425
|
+
<F extends AnyFunction = AnyFunction>(fn?: F): Mock<F>;
|
|
426
|
+
/**
|
|
427
|
+
* Replace the module `specifier` (resolved as an import from the calling
|
|
428
|
+
* file) with `factory()`'s result. Factories are synchronous (C8). Call it
|
|
429
|
+
* before the module is loaded, then load it with `await import()`: static
|
|
430
|
+
* imports are linked before any test code runs.
|
|
431
|
+
*/
|
|
432
|
+
module(specifier: string, factory: () => Record<string, unknown>): void;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export const mock: MockFactory;
|
|
436
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,11 @@
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
import { Database } from "bun:sqlite";
|
|
33
|
-
|
|
33
|
+
import type { AppMemorySample, NodeAppCtx } from "./platform/types.js";
|
|
34
|
+
export type { AppMemorySample } from "./platform/types.js";
|
|
35
|
+
export declare const initAppTelemetry: (appName: string) => Promise<void>;
|
|
36
|
+
export declare const telemetryActive: () => boolean;
|
|
37
|
+
export declare const incrementCounter: (name: string, value?: number, attributes?: Record<string, string | number | boolean>) => void;
|
|
34
38
|
/**
|
|
35
39
|
* Open an app-owned SQLite database with a bounded page cache.
|
|
36
40
|
*
|
|
@@ -40,17 +44,12 @@ export { initAppTelemetry, telemetryActive, incrementCounter } from "./otel.js";
|
|
|
40
44
|
export declare function openDatabase(path: string, options?: {
|
|
41
45
|
cacheSizeKb?: number;
|
|
42
46
|
}): Database;
|
|
43
|
-
interface NodeAppCtx {
|
|
44
|
-
socket: string | undefined;
|
|
45
|
-
logDir: string | undefined;
|
|
46
|
-
dataDir: string | undefined;
|
|
47
|
-
}
|
|
48
47
|
/** @internal exported for unit tests; not part of the public SDK surface. */
|
|
49
|
-
export declare
|
|
48
|
+
export declare const _resolveCtx: () => NodeAppCtx;
|
|
50
49
|
/** @internal test-only export */
|
|
51
|
-
export declare
|
|
50
|
+
export declare const _testRunNodeAppPath: () => string | undefined;
|
|
52
51
|
/** @internal test-only export; also the production exit pathway. */
|
|
53
|
-
export declare
|
|
52
|
+
export declare const _testExitWorker: (code: number, mainThread: boolean, exit?: (code: number) => never) => void;
|
|
54
53
|
export interface AppMetadata {
|
|
55
54
|
name: string;
|
|
56
55
|
version: string;
|
|
@@ -192,15 +191,9 @@ export declare function _testLeaseState(): {
|
|
|
192
191
|
timerArmed: boolean;
|
|
193
192
|
draining: boolean;
|
|
194
193
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
external_kb?: number;
|
|
199
|
-
heap_capacity_kb?: number;
|
|
200
|
-
}
|
|
201
|
-
/** @internal Exact isolate sample used by the IPC timer and unit tests. */
|
|
202
|
-
export declare function _sampleMemory(): AppMemorySample;
|
|
203
|
-
export declare function _captureHeapSnapshotTo(path: string, generate?: () => ArrayBuffer, write?: (path: string, bytes: ArrayBuffer) => Promise<number>): Promise<{
|
|
194
|
+
/** @internal Exact runtime heap sample used by the IPC timer and unit tests. */
|
|
195
|
+
export declare const _sampleMemory: () => AppMemorySample;
|
|
196
|
+
export declare const _captureHeapSnapshotTo: (path: string, generate?: () => ArrayBuffer, write?: (path: string, bytes: ArrayBuffer) => Promise<number>) => Promise<{
|
|
204
197
|
size_bytes: number;
|
|
205
198
|
}>;
|
|
206
199
|
export declare function _handleHeapSnapshotRequest(request: HeapSnapshotRequest, send: (message: HeapSnapshotResponse) => void, capture?: (path: string) => Promise<{
|