@rank-lang/provider-runtime
v0.3.1
Published
Shared provider runtime helpers for Rank host integrations
Readme
@rank-lang/provider-runtime
Shared JavaScript helpers for Rank provider processes.
Install
npm install @rank-lang/provider-runtimeEntry points
@rank-lang/provider-runtime: provider protocol helpers plus deterministic RNG helpers@rank-lang/provider-runtime/rand: deterministic RNG helpers only
API
Constants
STDLIB_RAND_ALGORITHM: stable identifier for the stdlib RNG algorithm (rank/rand/splitmix64@1)PROVIDER_PROTOCOL_VERSION: current line-oriented provider protocol version
RNG helpers
encodeStdlibRandState(state: bigint): stringdecodeStdlibRandState(stateText: string): bigint | undefinedstdlibRandSeedState(seed: number): bigintstdlibRandDeriveState(parentState: bigint, label: string): bigintstdlibRandNextUnitFloat(state: bigint): { value: number, state: bigint }stdlibRandNextInt(state: bigint, min: bigint, max: bigint): { value: bigint, state: bigint }stdlibRandChooseIndex(state: bigint, length: number): { index: number, state: bigint }
These helpers are the shared deterministic random source used by provider runtimes such as @rank-lang/plugin-faker.
Provider protocol helpers
initializeResult(namespace, error?)invokeSuccess(requestId, output)invokeError(requestId, code, message)runNodeProviderLoop({ namespace, invoke })
runNodeProviderLoop reads newline-delimited JSON messages from stdin, enforces initialization before invocation, and writes protocol results to stdout.
Example
import { runNodeProviderLoop } from "@rank-lang/provider-runtime";
await runNodeProviderLoop({
namespace: "demo",
invoke(exportName, input) {
if (exportName !== "Echo") {
return {
ok: false,
code: "UnknownExport",
message: `Unsupported export: ${String(exportName)}`,
};
}
return {
ok: true,
output: input,
};
},
});Development
npm run test -w @rank-lang/provider-runtimePublishing
No build step is required for this package.
From the workspace root:
npm publish -w @rank-lang/provider-runtime