chore: add pnpm monorepo skeleton with core contracts
Shared notebook model (types.ts), HTTP/WebSocket protocol (protocol.ts) and core function signatures (stubs) so core, server and web can be built in parallel. Minimal Fastify server with a health route and test.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Public API of @shellbook/core. Pure functions, no I/O.
|
||||
// Signatures are a CONTRACT used by server and web; implementations land in M0.
|
||||
|
||||
import type { Notebook, ParamValues, RenderedStep, Step } from "./types";
|
||||
|
||||
export type * from "./types";
|
||||
export type * from "./protocol";
|
||||
|
||||
const notImplemented = (fn: string): never => {
|
||||
throw new Error(`@shellbook/core: ${fn} is not implemented yet (M0)`);
|
||||
};
|
||||
|
||||
/** Parse notebook Markdown (frontmatter, steps, :::after sections). Never throws; problems go to diagnostics. */
|
||||
export function parseNotebook(source: string): Notebook {
|
||||
return notImplemented(`parseNotebook(${source.length} chars)`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quote a value for POSIX sh. Returns the value unchanged when it only contains
|
||||
* [A-Za-z0-9._/@:=+-] and is non-empty; otherwise single-quoted with ' escaped as '\''.
|
||||
* The ONLY place in the codebase that quotes shell values.
|
||||
*/
|
||||
export function shellQuote(value: string): string {
|
||||
return notImplemented(`shellQuote(${value.length} chars)`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve defaults ({{other}} references) and validate all params by type.
|
||||
* Returns effective values and an error message per invalid/missing-required param.
|
||||
* `hostNames` = names from hosts.yaml (for type "host").
|
||||
*/
|
||||
export function resolveParams(
|
||||
notebook: Notebook,
|
||||
values: ParamValues,
|
||||
hostNames: readonly string[],
|
||||
): { values: ParamValues; errors: Record<string, string> } {
|
||||
return notImplemented(`resolveParams(${notebook.params.length}, ${Object.keys(values).length}, ${hostNames.length})`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitute {{name}} in a step: script values are shell-quoted via shellQuote,
|
||||
* attribute values (host, artifacts, uploads) are substituted raw but validated.
|
||||
* Secret params must not be referenced with {{ }} (they are env vars) — reported in `invalid`.
|
||||
*/
|
||||
export function renderStep(
|
||||
notebook: Notebook,
|
||||
step: Step,
|
||||
values: ParamValues,
|
||||
runtime: ParamValues,
|
||||
hostNames: readonly string[],
|
||||
): RenderedStep {
|
||||
return notImplemented(`renderStep(${notebook.title}, ${step.attrs.id}, ${Object.keys(values).length}, ${Object.keys(runtime).length}, ${hostNames.length})`);
|
||||
}
|
||||
|
||||
/** Substitute {{name}} in prose/markdown for display (no quoting; secrets shown as ••••). */
|
||||
export function renderText(text: string, values: ParamValues, notebook: Notebook): string {
|
||||
return notImplemented(`renderText(${text.length}, ${Object.keys(values).length}, ${notebook.title})`);
|
||||
}
|
||||
|
||||
/** Env vars for a run: every `secret` param as NAME=value (exact param name). Server-side only. */
|
||||
export function secretEnv(notebook: Notebook, values: ParamValues): Record<string, string> {
|
||||
return notImplemented(`secretEnv(${notebook.params.length}, ${Object.keys(values).length})`);
|
||||
}
|
||||
Reference in New Issue
Block a user