@econ-v1/app-sdk 7.0.78 → 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,5 @@
|
|
|
1
|
+
export declare function initAppTelemetry(_appName: string): Promise<void>;
|
|
2
|
+
export declare function telemetryActive(): boolean;
|
|
3
|
+
export declare function incrementCounter(_name: string, _value?: number, _attributes?: Record<string, string | number | boolean>): void;
|
|
4
|
+
export declare function injectTraceContext(carrier: Record<string, string>): Record<string, string>;
|
|
5
|
+
export declare function traceIncomingCapability<T>(_capability: string, _carrier: Record<string, string> | undefined, fn: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun (and Node-compatible) platform for the SDK core. Selected by
|
|
3
|
+
* `#platform` for every export condition except `burger`. The bodies here
|
|
4
|
+
* were moved verbatim from `src/index.ts`; behaviour is unchanged.
|
|
5
|
+
*/
|
|
6
|
+
import type { AppMemorySample, HostConnection, HostConnectionHandlers, InvocationContextStore, NodeAppCtx } from "./types.js";
|
|
7
|
+
export declare const platformName: "bun" | "burger";
|
|
8
|
+
export declare const isMainThread: boolean;
|
|
9
|
+
export declare const DEFAULT_SQLITE_CACHE_SIZE_KB: number;
|
|
10
|
+
/** @internal exported for unit tests; not part of the public SDK surface. */
|
|
11
|
+
export declare function _resolveCtx(): NodeAppCtx;
|
|
12
|
+
/** Context captured once at SDK import time. */
|
|
13
|
+
export declare const appCtx: NodeAppCtx;
|
|
14
|
+
/** @internal test-only export */
|
|
15
|
+
export declare function _testRunNodeAppPath(): string | undefined;
|
|
16
|
+
/** @internal test-only export; also the production exit pathway. */
|
|
17
|
+
export declare function _testExitWorker(code: number, mainThread: boolean, exit?: (code: number) => never): void;
|
|
18
|
+
/** Exit this app: the process on the main thread, the worker otherwise. */
|
|
19
|
+
export declare function exitApp(code: number): void;
|
|
20
|
+
/** Exit with an error when the host did not provide `NODE_APP_SOCKET`. */
|
|
21
|
+
export declare function assertHostEndpoint(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Connect to the host over the per-app Unix socket and speak the
|
|
24
|
+
* newline-delimited JSON protocol. Frames that arrive in one chunk are
|
|
25
|
+
* handled in order; a frame's handler finishing is awaited before the next
|
|
26
|
+
* frame of the same chunk is dispatched.
|
|
27
|
+
*/
|
|
28
|
+
export declare function connectToHost(handlers: HostConnectionHandlers): HostConnection;
|
|
29
|
+
export declare function createInvocationContextStore<T>(): InvocationContextStore<T>;
|
|
30
|
+
/** @internal Exact isolate sample used by the IPC timer and unit tests. */
|
|
31
|
+
export declare function _sampleMemory(): AppMemorySample;
|
|
32
|
+
export declare function _captureHeapSnapshotTo(path: string, generate?: () => ArrayBuffer, write?: (path: string, bytes: ArrayBuffer) => Promise<number>): Promise<{
|
|
33
|
+
size_bytes: number;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Burger platform for the SDK core. Selected by `#platform` under the
|
|
3
|
+
* `burger` export condition (Burger apps are bundled by `burger-build`,
|
|
4
|
+
* which sets it).
|
|
5
|
+
*
|
|
6
|
+
* The per-app channel is opened by the Burger runtime from its load_app
|
|
7
|
+
* message (Contract C3); framing and JSON (de)serialisation happen in Rust
|
|
8
|
+
* (Contract C4), so this module never splits lines or calls `JSON.parse`.
|
|
9
|
+
*/
|
|
10
|
+
import type { AppMemorySample, HostConnection, HostConnectionHandlers, InvocationContextStore, NodeAppCtx } from "./types.js";
|
|
11
|
+
export declare const platformName: "bun" | "burger";
|
|
12
|
+
/** Burger runs each app on its own runtime; there are no worker threads. */
|
|
13
|
+
export declare const isMainThread: boolean;
|
|
14
|
+
/** Burger applies `PRAGMA cache_size = -256` to every database it opens; the SDK must not widen it. */
|
|
15
|
+
export declare const DEFAULT_SQLITE_CACHE_SIZE_KB: number;
|
|
16
|
+
/** @internal exported for unit tests; not part of the public SDK surface. */
|
|
17
|
+
export declare function _resolveCtx(): NodeAppCtx;
|
|
18
|
+
/** Context captured once at SDK import time. */
|
|
19
|
+
export declare const appCtx: NodeAppCtx;
|
|
20
|
+
/** @internal test-only export */
|
|
21
|
+
export declare function _testRunNodeAppPath(): string | undefined;
|
|
22
|
+
/** @internal test-only export; also the production exit pathway. */
|
|
23
|
+
export declare function _testExitWorker(code: number, _mainThread: boolean, exitFn?: (code: number) => never): void;
|
|
24
|
+
/** Exit this app through the runtime (runs shutdown handlers, tears down the runtime). */
|
|
25
|
+
export declare function exitApp(code: number): void;
|
|
26
|
+
/** The runtime always binds the app channel, so there is nothing to check. */
|
|
27
|
+
export declare function assertHostEndpoint(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Open the runtime-owned app channel. Each inbound frame is dispatched as
|
|
30
|
+
* soon as the runtime delivers it: handlers for different frames may
|
|
31
|
+
* interleave at `await` points, which is what lets a capability handler
|
|
32
|
+
* await an `invoke_capability_result` frame that arrives later.
|
|
33
|
+
*/
|
|
34
|
+
export declare function connectToHost(handlers: HostConnectionHandlers): HostConnection;
|
|
35
|
+
/**
|
|
36
|
+
* Burger Phase 1 has no `AsyncLocalStorage` (C6). The store is visible only
|
|
37
|
+
* during the synchronous part of `fn`: a nested `invokeCapability` made
|
|
38
|
+
* before the handler's first `await` carries `invocation_context_id`, later
|
|
39
|
+
* ones carry none and the host classifies them as
|
|
40
|
+
* `Background(AutonomousApp)` — never a wrong or elevated origin.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createInvocationContextStore<T>(): InvocationContextStore<T>;
|
|
43
|
+
/** @internal Exact QuickJS runtime sample used by the IPC timer and unit tests. */
|
|
44
|
+
export declare function _sampleMemory(): AppMemorySample;
|
|
45
|
+
export declare function _captureHeapSnapshotTo(path: string, generate?: () => ArrayBuffer, write?: (path: string, bytes: ArrayBuffer) => Promise<number>): Promise<{
|
|
46
|
+
size_bytes: number;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time guard: the Bun and Burger platforms export the same names
|
|
3
|
+
* with compatible types. `tsc --noEmit` (the SDK's `typecheck` script and
|
|
4
|
+
* the publish gate) fails when they drift apart.
|
|
5
|
+
*/
|
|
6
|
+
import type * as BunPlatform from "./bun.js";
|
|
7
|
+
import type * as BurgerPlatform from "./burger.js";
|
|
8
|
+
type Bun = typeof BunPlatform;
|
|
9
|
+
type Burger = typeof BurgerPlatform;
|
|
10
|
+
type SameExportNames = [Exclude<keyof Bun, keyof Burger>, Exclude<keyof Burger, keyof Bun>] extends [never, never] ? true : false;
|
|
11
|
+
type BurgerAssignableToBun = Burger extends Bun ? true : false;
|
|
12
|
+
type BunAssignableToBurger = Bun extends Burger ? true : false;
|
|
13
|
+
export declare const platformsExportTheSameNames: SameExportNames;
|
|
14
|
+
export declare const burgerPlatformMatchesBun: BurgerAssignableToBun;
|
|
15
|
+
export declare const bunPlatformMatchesBurger: BunAssignableToBurger;
|
|
16
|
+
import type * as OtelDefault from "../otel.js";
|
|
17
|
+
import type * as OtelBurger from "../otel-burger.js";
|
|
18
|
+
type OtelSameExportNames = [
|
|
19
|
+
Exclude<keyof typeof OtelDefault, keyof typeof OtelBurger>,
|
|
20
|
+
Exclude<keyof typeof OtelBurger, keyof typeof OtelDefault>
|
|
21
|
+
] extends [never, never] ? true : false;
|
|
22
|
+
type OtelBurgerAssignable = typeof OtelBurger extends typeof OtelDefault ? true : false;
|
|
23
|
+
export declare const otelModulesExportTheSameNames: OtelSameExportNames;
|
|
24
|
+
export declare const burgerOtelMatchesDefault: OtelBurgerAssignable;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam between the platform-neutral SDK core (`src/index.ts`) and the
|
|
3
|
+
* runtime it runs on. `src/platform/bun.ts` and `src/platform/burger.ts`
|
|
4
|
+
* export exactly the same names with these types; `package.json#imports`
|
|
5
|
+
* selects one through the `#platform` specifier (`burger` export condition
|
|
6
|
+
* → Burger, everything else → Bun). `src/platform/conformance.ts` fails
|
|
7
|
+
* `tsc` if the two drift apart.
|
|
8
|
+
*/
|
|
9
|
+
export interface NodeAppCtx {
|
|
10
|
+
socket: string | undefined;
|
|
11
|
+
logDir: string | undefined;
|
|
12
|
+
dataDir: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface AppMemorySample {
|
|
15
|
+
heap_used_kb: number;
|
|
16
|
+
heap_total_kb: number;
|
|
17
|
+
external_kb?: number;
|
|
18
|
+
heap_capacity_kb?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Callbacks the SDK core registers on the host connection. */
|
|
21
|
+
export interface HostConnectionHandlers {
|
|
22
|
+
/** The connection is open; `endpoint` is a human-readable description for logs. */
|
|
23
|
+
onConnected(endpoint: string): void;
|
|
24
|
+
/** One inbound IPC frame, already parsed into a plain object. */
|
|
25
|
+
onFrame(frame: unknown): Promise<void>;
|
|
26
|
+
/** A frame could not be parsed, or its handler threw. */
|
|
27
|
+
onFrameError(error: unknown): void;
|
|
28
|
+
/** The connection failed. */
|
|
29
|
+
onError(error: Error): void;
|
|
30
|
+
/** The connection closed normally. */
|
|
31
|
+
onClose(): void;
|
|
32
|
+
}
|
|
33
|
+
export interface HostConnection {
|
|
34
|
+
/** Write one frame. */
|
|
35
|
+
send(frame: object): void;
|
|
36
|
+
/** Write one frame and resolve once the runtime has accepted the bytes. */
|
|
37
|
+
sendAndFlush(frame: object): Promise<void>;
|
|
38
|
+
/** Stop delivering inbound frames that have not been delivered yet (lease drain). */
|
|
39
|
+
stopAccepting(): void;
|
|
40
|
+
/** Close the connection. */
|
|
41
|
+
end(): void;
|
|
42
|
+
}
|
|
43
|
+
/** The subset of `AsyncLocalStorage` the SDK core uses. */
|
|
44
|
+
export interface InvocationContextStore<T> {
|
|
45
|
+
run<R>(store: T, fn: () => R): R;
|
|
46
|
+
getStore(): T | undefined;
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@econ-v1/app-sdk",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.79",
|
|
4
4
|
"description": "TypeScript SDK for building Node mini-app plugins (Bun runtime) on the Lightning-powered marketplace daemon",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "Node contributors",
|
|
@@ -27,11 +27,44 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
|
+
"burger": "./dist/burger/index.js",
|
|
30
31
|
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./burger-build": {
|
|
34
|
+
"types": "./dist/burger-build/index.d.ts",
|
|
35
|
+
"default": "./dist/burger-build/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./burger-types": {
|
|
38
|
+
"types": "./dist/burger-types/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./burger-types/modules": {
|
|
41
|
+
"types": "./dist/burger-types/modules.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"./burger-types/aliases": {
|
|
44
|
+
"types": "./dist/burger-types/aliases.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./burger-types/globals": {
|
|
47
|
+
"types": "./dist/burger-types/globals.d.ts"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"bin": {
|
|
51
|
+
"burger-build": "dist/burger-build/cli.js"
|
|
52
|
+
},
|
|
53
|
+
"imports": {
|
|
54
|
+
"#platform": {
|
|
55
|
+
"burger": "./src/platform/burger.ts",
|
|
56
|
+
"default": "./src/platform/bun.ts"
|
|
57
|
+
},
|
|
58
|
+
"#otel": {
|
|
59
|
+
"burger": "./src/otel-burger.ts",
|
|
60
|
+
"default": "./src/otel.ts"
|
|
31
61
|
}
|
|
32
62
|
},
|
|
33
63
|
"files": [
|
|
34
64
|
"dist",
|
|
65
|
+
"!dist/__burger__",
|
|
66
|
+
"!dist/__tests__",
|
|
67
|
+
"!dist/**/*.test.d.ts",
|
|
35
68
|
"README.md"
|
|
36
69
|
],
|
|
37
70
|
"engines": {
|
|
@@ -39,11 +72,16 @@
|
|
|
39
72
|
"bun": ">=1.0"
|
|
40
73
|
},
|
|
41
74
|
"scripts": {
|
|
42
|
-
"build": "rm -rf dist && bun build src/index.ts --outdir dist --target=bun --minify && tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
75
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --target=bun --minify && bun run build:burger && tsc --emitDeclarationOnly --declaration --outDir dist && bun run build:toolchain",
|
|
76
|
+
"build:burger": "bun ../burger-build/src/cli.ts build src/index.ts --outdir dist/burger",
|
|
77
|
+
"build:toolchain": "bun scripts/build-burger-toolchain.ts",
|
|
43
78
|
"prepublishOnly": "npm run build",
|
|
44
79
|
"test": "bun test",
|
|
80
|
+
"test:burger": "bun test --conditions=burger --preload ./src/__burger__/preload.ts ./src/__burger__/run-node-app.burger-test.ts",
|
|
81
|
+
"test:toolchain": "cd ../burger-types && bun install && bun test && cd ../burger-build && bun install && bun run typecheck && bun test",
|
|
45
82
|
"typecheck": "tsc --noEmit",
|
|
46
|
-
"pack:dry": "npm pack --dry-run"
|
|
83
|
+
"pack:dry": "npm pack --dry-run",
|
|
84
|
+
"verify:pack": "bun scripts/verify-pack.ts"
|
|
47
85
|
},
|
|
48
86
|
"publishConfig": {
|
|
49
87
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/memory.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|