leanfran 0.0.0-stage → 0.6.0

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/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/cli.js ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ import { a as statusModels, d as statusPackage, f as syncPackage, l as leanTypescriptCli, n as csimpFiles, p as SyncError, t as checkPackage, u as readPackage } from "./check-DROT5twE.js";
3
+ import { spawnSync } from "node:child_process";
4
+ import { readFileSync } from "node:fs";
5
+ // src/cli.ts
6
+ const USAGE = `usage: leanfran [--version] <command> [parameters]
7
+
8
+ commands:
9
+ sync Check the Lean blocks of a package and generate their TypeScript modules
10
+ check Translate the model(...) functions and judge the proofs of their obligations
11
+ status List the blocks whose generated modules are stale (no Lean)
12
+ generate Emit a TypeScript module per Lean module of a lake project
13
+
14
+ leanfran sync
15
+ --package <dir> The package (the directory with package.json and src/) (required)
16
+ --leanfran-typescript <path> The Lean CLI (default: $LEANFRAN_TYPESCRIPT, then leanfran-typescript on PATH)
17
+
18
+ leanfran check
19
+ --package <dir> The package (required)
20
+ --leanfran-typescript <path> as for sync
21
+ --require proved Exit with 254 unless every obligation is proved
22
+ Writes <dir>/leanfran.lock and prints one line per obligation: <status> <module>:<function> <label>
23
+
24
+ leanfran status
25
+ --package <dir> The package (required); exits with 254 when a block or an obligation is stale
26
+
27
+ leanfran generate
28
+ --lake-dir <dir> Lake project to build (required)
29
+ --output-dir <dir> Directory of the TypeScript modules (required)
30
+ --modules <Name> ... Modules to emit (default: every module the project builds)
31
+ --leanfran-typescript <path> as for sync
32
+
33
+ exit codes: 0 success, 252 invalid parameters, 254 input that cannot be converted, 255 other errors
34
+ `;
35
+ function parseArgs(argv, allowed) {
36
+ const single = /* @__PURE__ */ new Map();
37
+ const modules = [];
38
+ for (let i = 0; i < argv.length; i++) {
39
+ const a = argv[i] ?? "";
40
+ if (a === "--modules" && allowed.includes(a)) {
41
+ while (i + 1 < argv.length && !(argv[i + 1] ?? "").startsWith("--")) modules.push(argv[++i] ?? "");
42
+ continue;
43
+ }
44
+ const v = argv[i + 1];
45
+ if (!allowed.includes(a) || v === void 0 || v.startsWith("--")) throw new SyncError(`unknown or incomplete parameter: ${a}`, 252);
46
+ single.set(a, v);
47
+ i++;
48
+ }
49
+ return {
50
+ single,
51
+ modules
52
+ };
53
+ }
54
+ function required(args, name) {
55
+ const v = args.single.get(name);
56
+ if (v === void 0) throw new SyncError(`${name} is required`, 252);
57
+ return v;
58
+ }
59
+ function log(line) {
60
+ process.stderr.write(line.endsWith("\n") ? line : `${line}\n`);
61
+ }
62
+ function version() {
63
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
64
+ const v = typeof pkg === "object" && pkg !== null ? Reflect.get(pkg, "version") : void 0;
65
+ if (typeof v !== "string") throw new SyncError("package.json has no version", 255);
66
+ return v;
67
+ }
68
+ async function main(argv) {
69
+ const [command, ...rest] = argv;
70
+ if (command === void 0 || command === "help" || command === "--help") {
71
+ process.stdout.write(USAGE);
72
+ return 0;
73
+ }
74
+ if (command === "--version") {
75
+ process.stdout.write(`${version()}\n`);
76
+ return 0;
77
+ }
78
+ if (command === "sync") {
79
+ const args = parseArgs(rest, ["--package", "--leanfran-typescript"]);
80
+ await syncPackage(required(args, "--package"), args.single.get("--leanfran-typescript"), log, csimpFiles);
81
+ return 0;
82
+ }
83
+ if (command === "check") {
84
+ const args = parseArgs(rest, [
85
+ "--package",
86
+ "--leanfran-typescript",
87
+ "--require"
88
+ ]);
89
+ const req = args.single.get("--require");
90
+ if (req !== void 0 && req !== "proved") throw new SyncError(`--require takes proved (got ${req})`, 252);
91
+ const { rows } = await checkPackage(required(args, "--package"), args.single.get("--leanfran-typescript"), log);
92
+ for (const r of rows) process.stdout.write(`${r.status.padEnd(12)}${r.fn} ${r.label}\n`);
93
+ return req === void 0 || rows.every((r) => r.status === "proved") ? 0 : 254;
94
+ }
95
+ if (command === "status") {
96
+ const dir = required(parseArgs(rest, ["--package"]), "--package");
97
+ const pkg = await readPackage(dir, false);
98
+ const rows = statusPackage(pkg);
99
+ for (const r of rows) process.stdout.write(`${r.state.padEnd(8)}${r.block}\n`);
100
+ const models = statusModels(pkg);
101
+ for (const r of models) process.stdout.write(`${r.status.padEnd(12)}${r.fn} ${r.label}\n`);
102
+ return rows.every((r) => r.state === "fresh") && models.every((r) => r.status !== "stale") ? 0 : 254;
103
+ }
104
+ if (command === "generate") {
105
+ const args = parseArgs(rest, [
106
+ "--lake-dir",
107
+ "--output-dir",
108
+ "--modules",
109
+ "--leanfran-typescript"
110
+ ]);
111
+ const cli = leanTypescriptCli(args.single.get("--leanfran-typescript"));
112
+ const modules = args.modules.length === 0 ? [] : ["--modules", ...args.modules];
113
+ const r = spawnSync(cli, [
114
+ "project",
115
+ "generate",
116
+ "--lake-dir",
117
+ required(args, "--lake-dir"),
118
+ "--output-dir",
119
+ required(args, "--output-dir"),
120
+ ...modules,
121
+ "--output",
122
+ "text"
123
+ ], { stdio: "inherit" });
124
+ if (r.error !== void 0) throw new SyncError(`cannot run ${cli}: ${r.error.message}`, 255);
125
+ return r.status ?? 255;
126
+ }
127
+ throw new SyncError(`unknown command ${command} (see \`leanfran help\`)`, 252);
128
+ }
129
+ try {
130
+ process.exitCode = await main(process.argv.slice(2));
131
+ } catch (e) {
132
+ log(`leanfran: ${e instanceof Error ? e.message : String(e)}`);
133
+ process.exitCode = e instanceof SyncError ? e.code : 255;
134
+ }
@@ -0,0 +1,200 @@
1
+ import { t as blockRegistry } from "./block-CU7YIXdj.js";
2
+ // src/key.ts
3
+ function isJsonObject(v) {
4
+ return typeof v === "object" && v !== null && !Array.isArray(v);
5
+ }
6
+ function toJson(v, where) {
7
+ if (v === null || typeof v === "boolean" || typeof v === "string") return v;
8
+ if (typeof v === "number") {
9
+ if (!Number.isFinite(v)) throw new TypeError(`${where}: ${v} is not a JSON number`);
10
+ return v;
11
+ }
12
+ if (Array.isArray(v)) return v.map((x, i) => toJson(x, `${where}[${i}]`));
13
+ if (isJsonObject(v)) {
14
+ const out = {};
15
+ for (const k of Object.keys(v).toSorted()) {
16
+ const x = v[k];
17
+ if (x !== void 0) out[k] = toJson(x, `${where}.${k}`);
18
+ }
19
+ return out;
20
+ }
21
+ throw new TypeError(`${where}: ${typeof v} is not a JSON value`);
22
+ }
23
+ function canonicalJson(v) {
24
+ return JSON.stringify(toJson(v, "value"));
25
+ }
26
+ const FNV_OFFSET = 14695981039346656037n;
27
+ const FNV_PRIME = 1099511628211n;
28
+ function fnv1a64(s) {
29
+ let h = FNV_OFFSET;
30
+ for (const b of new TextEncoder().encode(s)) h = BigInt.asUintN(64, (h ^ BigInt(b)) * FNV_PRIME);
31
+ return h.toString(16).padStart(16, "0");
32
+ }
33
+ // src/embed.ts
34
+ const GENERATOR_VERSION = "10";
35
+ var LeanBlockStale = class extends Error {
36
+ constructor(message) {
37
+ super(message);
38
+ this.name = "LeanBlockStale";
39
+ }
40
+ };
41
+ function stringList(v, where) {
42
+ if (v === void 0) return [];
43
+ if (!Array.isArray(v) || !v.every((x) => typeof x === "string")) throw new TypeError(`lean(): ${where} must be an array of strings`);
44
+ return v;
45
+ }
46
+ function isRecord(v) {
47
+ return typeof v === "object" && v !== null && !Array.isArray(v);
48
+ }
49
+ function modelSchema(name, model) {
50
+ const std = isRecord(model) ? model["~standard"] : void 0;
51
+ const converter = isRecord(std) ? std["jsonSchema"] : void 0;
52
+ const output = isRecord(converter) ? converter["output"] : void 0;
53
+ if (typeof output !== "function") throw new TypeError(`lean(): the model ${name} is not a Standard JSON Schema (no ~standard.jsonSchema.output)`);
54
+ return toJson(Reflect.apply(output, converter, [{ target: "draft-2020-12" }]), `the JSON Schema of the model ${name}`);
55
+ }
56
+ function outputOptions(v) {
57
+ if (v === void 0) return {};
58
+ if (!isRecord(v)) throw new TypeError("lean(): options.output must be an object");
59
+ const out = {};
60
+ const { tagKey, option } = v;
61
+ if (tagKey !== void 0) {
62
+ if (typeof tagKey !== "string") throw new TypeError("lean(): output.tagKey must be a string");
63
+ out.tagKey = tagKey;
64
+ }
65
+ if (option !== void 0) {
66
+ if (option !== "null" && option !== "undefined") throw new TypeError("lean(): output.option must be \"null\" or \"undefined\"");
67
+ out.option = option;
68
+ }
69
+ return out;
70
+ }
71
+ function blockInputs(name, source, options) {
72
+ if (typeof name !== "string") throw new TypeError("lean(): the block name must be a string");
73
+ if (typeof source !== "string") throw new TypeError("lean(): the Lean source must be a string");
74
+ if (options !== void 0 && !isRecord(options)) throw new TypeError("lean(): options must be an object");
75
+ const o = options ?? {};
76
+ const models = {};
77
+ if (o["models"] !== void 0) {
78
+ if (!isRecord(o["models"])) throw new TypeError("lean(): options.models must be an object");
79
+ for (const [k, m] of Object.entries(o["models"])) models[k] = modelSchema(k, m);
80
+ }
81
+ return {
82
+ name,
83
+ source,
84
+ imports: stringList(o["imports"], "options.imports"),
85
+ uses: stringList(o["uses"], "options.uses"),
86
+ models,
87
+ output: outputOptions(o["output"])
88
+ };
89
+ }
90
+ function blockContent(b) {
91
+ return toJson({
92
+ name: b.name,
93
+ source: b.source,
94
+ imports: b.imports,
95
+ uses: b.uses,
96
+ models: b.models,
97
+ output: b.output,
98
+ generator: "10"
99
+ }, "block");
100
+ }
101
+ function blockFnv(b) {
102
+ return fnv1a64(canonicalJson(blockContent(b)));
103
+ }
104
+ function nodeProcess() {
105
+ return typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process : void 0;
106
+ }
107
+ function packageRoot(proc, entries) {
108
+ const fs = proc.getBuiltinModule("node:fs");
109
+ const path = proc.getBuiltinModule("node:path");
110
+ const url = proc.getBuiltinModule("node:url");
111
+ const first = entries[0];
112
+ let dir = first === void 0 ? proc.cwd() : path.dirname(url.fileURLToPath(first.url));
113
+ for (;;) {
114
+ if (fs.existsSync(path.join(dir, "package.json"))) return dir;
115
+ const up = path.dirname(dir);
116
+ if (up === dir) throw new LeanBlockStale(`leanfran: no package.json above ${dir}`);
117
+ dir = up;
118
+ }
119
+ }
120
+ function autoSync(proc, name, entries) {
121
+ if (proc.env["LEANFRAN_TS_AUTO_SYNC"] !== "1") return false;
122
+ const root = packageRoot(proc, entries);
123
+ const cli = proc.getBuiltinModule("node:url").fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./cli.ts" : "./cli.js", import.meta.url));
124
+ const r = proc.getBuiltinModule("node:child_process").spawnSync(proc.execPath, [
125
+ cli,
126
+ "sync",
127
+ "--package",
128
+ root
129
+ ], {
130
+ stdio: "inherit",
131
+ env: {
132
+ ...proc.env,
133
+ LEANFRAN_TS_AUTO_SYNC: "0"
134
+ }
135
+ });
136
+ if (r.status !== 0) throw new LeanBlockStale(`leanfran: \`leanfran sync --package ${root}\` failed (exit ${r.status})`);
137
+ proc.stderr.write(`leanfran: regenerated the Lean block ${JSON.stringify(name)} of ${root}; the generated module takes effect when the program starts again\n`);
138
+ return true;
139
+ }
140
+ const packageSettingsCache = /* @__PURE__ */ new Map();
141
+ function packageSettings(proc, entry) {
142
+ const root = packageRoot(proc, [entry]);
143
+ const cached = packageSettingsCache.get(root);
144
+ if (cached !== void 0) return cached;
145
+ const file = proc.getBuiltinModule("node:path").join(root, "package.json");
146
+ const pkg = JSON.parse(proc.getBuiltinModule("node:fs").readFileSync(file, "utf8"));
147
+ const field = isRecord(pkg) ? pkg["leanfran"] : void 0;
148
+ const settings = isRecord(field) ? field : {};
149
+ packageSettingsCache.set(root, settings);
150
+ return settings;
151
+ }
152
+ function settingString(v) {
153
+ return typeof v === "string" ? v : void 0;
154
+ }
155
+ function currentSettings(proc, entry, output) {
156
+ const pkg = packageSettings(proc, entry);
157
+ return {
158
+ tagKey: output.tagKey ?? settingString(pkg["tagKey"]) ?? "ctor",
159
+ option: output.option ?? settingString(pkg["option"]) ?? "null"
160
+ };
161
+ }
162
+ function lean(name, source, options) {
163
+ const registry = blockRegistry();
164
+ const models = options?.models ?? {};
165
+ if (registry.recording !== null) {
166
+ registry.recording.push({
167
+ name,
168
+ source,
169
+ options
170
+ });
171
+ return {
172
+ name,
173
+ key: "",
174
+ models
175
+ };
176
+ }
177
+ const inputs = blockInputs(name, source, options);
178
+ const fnv = blockFnv(inputs);
179
+ for (const [k, m] of Object.entries(models)) registry.models.set(`${fnv}:${k}`, m);
180
+ const entries = registry.blocks.get(name) ?? [];
181
+ const same = entries.filter((e) => e.fnv === fnv);
182
+ const proc = nodeProcess();
183
+ if (same.filter((e) => {
184
+ if (proc === void 0) return true;
185
+ const s = currentSettings(proc, e, inputs.output);
186
+ return s.tagKey === e.settings.tagKey && s.option === e.settings.option;
187
+ }).length !== 0) return {
188
+ name,
189
+ key: fnv,
190
+ models
191
+ };
192
+ if (proc !== void 0 && autoSync(proc, name, entries)) return {
193
+ name,
194
+ key: fnv,
195
+ models
196
+ };
197
+ const where = entries.length === 0 ? "its generated module was not imported" : same.length !== 0 ? "the leanfran settings of its package.json changed since `leanfran sync` generated it" : "it has changed since `leanfran sync` generated it";
198
+ throw new LeanBlockStale(`the Lean block ${JSON.stringify(name)} is stale (${where}); run \`leanfran sync\` (or set LEANFRAN_TS_AUTO_SYNC=1)`);
199
+ }
200
+ export { blockInputs as a, canonicalJson as c, blockFnv as i, LeanBlockStale as n, lean as o, blockContent as r, modelSchema as s, GENERATOR_VERSION as t };
@@ -0,0 +1,210 @@
1
+ import { l as Obj } from "./object-G1zwZFrv.js";
2
+ import { StandardJSONSchemaV1, StandardSchemaV1, StandardTypedV1 } from "@standard-schema/spec";
3
+ import * as FastCheck from "fast-check";
4
+ type Slot = "obj" | "usize" | "u8" | "u16" | "u32" | "u64" | "f64" | "f32" | "none";
5
+ type SchemaBounds = Readonly<Record<string, number>>;
6
+ interface FieldDesc {
7
+ readonly key: string;
8
+ readonly desc: TypeDesc;
9
+ readonly slot: Slot;
10
+ readonly at: number;
11
+ readonly omitNone: boolean;
12
+ readonly flat: boolean;
13
+ readonly bounds: SchemaBounds;
14
+ }
15
+ interface InvariantDesc {
16
+ readonly field: string;
17
+ readonly prop: string;
18
+ readonly args: readonly number[];
19
+ readonly decide: (...args: Obj[]) => boolean;
20
+ }
21
+ interface VariantDesc {
22
+ readonly name: string;
23
+ readonly cidx: number;
24
+ readonly size: number;
25
+ readonly usize: number;
26
+ readonly ssize: number;
27
+ readonly positional: boolean;
28
+ readonly fields: readonly FieldDesc[];
29
+ readonly invariants: readonly InvariantDesc[];
30
+ }
31
+ type Absent = "null" | "undefined";
32
+ type DescNode = {
33
+ readonly kind: "nat" | "int" | "bool" | "char" | "string" | "float" | "float32" | "unit";
34
+ } | {
35
+ readonly kind: "uint" | "sint";
36
+ readonly bits: 8 | 16 | 32 | 64;
37
+ } | {
38
+ readonly kind: "usize" | "isize";
39
+ } | {
40
+ readonly kind: "list" | "array";
41
+ readonly item: TypeDesc;
42
+ } | {
43
+ readonly kind: "option";
44
+ readonly item: TypeDesc;
45
+ readonly absent: Absent;
46
+ } | {
47
+ readonly kind: "prod";
48
+ readonly fst: TypeDesc;
49
+ readonly snd: TypeDesc;
50
+ } | {
51
+ readonly kind: "except";
52
+ readonly error: TypeDesc;
53
+ readonly value: TypeDesc;
54
+ } | {
55
+ readonly kind: "fin";
56
+ readonly bound: bigint;
57
+ } | {
58
+ readonly kind: "struct";
59
+ readonly name: string;
60
+ readonly variant: VariantDesc;
61
+ readonly trivial: number | null;
62
+ } | {
63
+ readonly kind: "enum";
64
+ readonly name: string;
65
+ readonly ctors: readonly string[];
66
+ } | {
67
+ readonly kind: "inductive";
68
+ readonly name: string;
69
+ readonly tagKey: string;
70
+ readonly variants: readonly VariantDesc[];
71
+ } | {
72
+ readonly kind: "subtype";
73
+ readonly name: string;
74
+ readonly base: TypeDesc;
75
+ readonly invariant: InvariantDesc;
76
+ readonly bounds: SchemaBounds;
77
+ } | {
78
+ readonly kind: "model";
79
+ readonly name: string;
80
+ readonly key: string;
81
+ readonly struct: TypeDesc;
82
+ } | {
83
+ readonly kind: "ref";
84
+ readonly get: () => TypeDesc;
85
+ };
86
+ type TypeDesc<T = unknown> = DescNode & {
87
+ readonly output?: T;
88
+ };
89
+ type Except<E, A> = {
90
+ ok: true;
91
+ value: A;
92
+ } | {
93
+ ok: false;
94
+ error: E;
95
+ };
96
+ declare const natDesc: TypeDesc<bigint>;
97
+ declare const intDesc: TypeDesc<bigint>;
98
+ declare const boolDesc: TypeDesc<boolean>;
99
+ declare const charDesc: TypeDesc<string>;
100
+ declare const stringDesc: TypeDesc<string>;
101
+ declare const floatDesc: TypeDesc<number>;
102
+ declare const float32Desc: TypeDesc<number>;
103
+ declare const unitDesc: TypeDesc<undefined>;
104
+ declare const usizeDesc: TypeDesc<bigint>;
105
+ declare const isizeDesc: TypeDesc<bigint>;
106
+ declare function uintDesc(bits: 8 | 16 | 32): TypeDesc<number>;
107
+ declare function uintDesc(bits: 64): TypeDesc<bigint>;
108
+ declare function sintDesc(bits: 8 | 16 | 32): TypeDesc<number>;
109
+ declare function sintDesc(bits: 64): TypeDesc<bigint>;
110
+ declare function listDesc<T>(item: TypeDesc<T>): TypeDesc<T[]>;
111
+ declare function arrayDesc<T>(item: TypeDesc<T>): TypeDesc<T[]>;
112
+ declare function optionDesc<T>(item: TypeDesc<T>, absent: "null"): TypeDesc<T | null>;
113
+ declare function optionDesc<T>(item: TypeDesc<T>, absent: "undefined"): TypeDesc<T | undefined>;
114
+ declare function prodDesc<A, B>(fst: TypeDesc<A>, snd: TypeDesc<B>): TypeDesc<readonly [A, B]>;
115
+ declare function exceptDesc<E, A>(error: TypeDesc<E>, value: TypeDesc<A>): TypeDesc<Except<E, A>>;
116
+ declare function finDesc<T extends number | bigint>(bound: bigint): TypeDesc<T>;
117
+ declare function refDesc<T>(get: () => TypeDesc<T>): TypeDesc<T>;
118
+ declare function typeDesc<T>(node: DescNode): TypeDesc<T>;
119
+ declare function modelDesc<T>(key: string, name: string, struct: TypeDesc): TypeDesc<T>;
120
+ interface Issue {
121
+ readonly message: string;
122
+ readonly path: readonly PropertyKey[];
123
+ }
124
+ declare class LeanValidationError extends Error {
125
+ readonly issues: readonly Issue[];
126
+ constructor(issues: readonly Issue[]);
127
+ }
128
+ declare class LeanIOError extends Error {
129
+ readonly code: string;
130
+ constructor(error: Obj);
131
+ }
132
+ declare function resolve(d: TypeDesc): TypeDesc;
133
+ interface StandardResult {
134
+ readonly value: unknown;
135
+ readonly issues: readonly Issue[] | null;
136
+ }
137
+ declare function standardValidate(schema: unknown, value: unknown): StandardResult;
138
+ declare function jsonValue(d: TypeDesc, v: unknown, big: boolean): unknown;
139
+ type Checked<T> = {
140
+ readonly value: T;
141
+ } | {
142
+ readonly issues: readonly Issue[];
143
+ };
144
+ declare function checkValue<T>(d: TypeDesc<T>, v: unknown): Checked<T>;
145
+ declare function toLean(d: TypeDesc, v: unknown, name: string): Obj;
146
+ declare function toTs<T>(d: TypeDesc<T>, x: Obj): T;
147
+ declare function ioResult<T>(d: TypeDesc<T>, r: Obj): T;
148
+ declare function lazy(f: () => Obj): () => Obj;
149
+ type JsonSchemaTarget = "draft-2020-12" | "draft-07" | "openapi-3.0";
150
+ type Js = Record<string, unknown>;
151
+ declare function jsonSchemaOf(root: TypeDesc, target: string): Js;
152
+ type FC = typeof FastCheck;
153
+ declare function arbitrary<T>(schema: {
154
+ readonly desc: TypeDesc<T>;
155
+ } | TypeDesc<T>, fc: FC): FastCheck.Arbitrary<T>;
156
+ interface LeanSchema<Input, Output> {
157
+ readonly "~standard": StandardSchemaV1.Props<Input, Output> & StandardJSONSchemaV1.Props<Input, Output>;
158
+ readonly desc: TypeDesc<Output>;
159
+ }
160
+ type InferInput<S extends StandardTypedV1> = StandardTypedV1.InferInput<S>;
161
+ type InferOutput<S extends StandardTypedV1> = StandardTypedV1.InferOutput<S>;
162
+ type UnitInput = Readonly<Record<string, never>> | undefined;
163
+ type ExceptInput<E, A> = {
164
+ readonly ok: A;
165
+ } | {
166
+ readonly error: E;
167
+ };
168
+ declare function schema<Input, Output>(desc: TypeDesc<Output>): LeanSchema<Input, Output>;
169
+ declare function merge<S extends object, M extends object>(target: S, members: M): S & M;
170
+ declare function fromJSON<Output>(s: LeanSchema<unknown, Output>, json: unknown): Output;
171
+ declare function toJSON<Output>(s: LeanSchema<unknown, Output>, value: Output): unknown;
172
+ declare function stringify<Output>(s: LeanSchema<unknown, Output>, value: Output): string;
173
+ declare function parse<Output>(s: LeanSchema<unknown, Output>, text: string): Output;
174
+ type Big = bigint | number | string;
175
+ type Nat = bigint;
176
+ type Int = bigint;
177
+ type UInt8 = number;
178
+ type UInt16 = number;
179
+ type UInt32 = number;
180
+ type UInt64 = bigint;
181
+ type USize = bigint;
182
+ type Int8 = number;
183
+ type Int16 = number;
184
+ type Int32 = number;
185
+ type Int64 = bigint;
186
+ type ISize = bigint;
187
+ type Bool = boolean;
188
+ type Char = string;
189
+ type Float = number;
190
+ type Float32 = number;
191
+ type Unit = undefined;
192
+ declare const Nat: LeanSchema<Big, bigint>;
193
+ declare const Int: LeanSchema<Big, bigint>;
194
+ declare const UInt8: LeanSchema<number, number>;
195
+ declare const UInt16: LeanSchema<number, number>;
196
+ declare const UInt32: LeanSchema<number, number>;
197
+ declare const UInt64: LeanSchema<Big, bigint>;
198
+ declare const USize: LeanSchema<Big, bigint>;
199
+ declare const Int8: LeanSchema<number, number>;
200
+ declare const Int16: LeanSchema<number, number>;
201
+ declare const Int32: LeanSchema<number, number>;
202
+ declare const Int64: LeanSchema<Big, bigint>;
203
+ declare const ISize: LeanSchema<Big, bigint>;
204
+ declare const Bool: LeanSchema<boolean, boolean>;
205
+ declare const Char: LeanSchema<string, string>;
206
+ declare const StringSchema: LeanSchema<string, string>;
207
+ declare const Float: LeanSchema<number | string, number>;
208
+ declare const Float32: LeanSchema<number | string, number>;
209
+ declare const Unit: LeanSchema<UnitInput, undefined>;
210
+ export { float32Desc as $, FC as A, Issue as B, UnitInput as C, schema as D, parse as E, Checked as F, TypeDesc as G, LeanValidationError as H, DescNode as I, boolDesc as J, VariantDesc as K, Except as L, JsonSchemaTarget as M, jsonSchemaOf as N, stringify as O, Absent as P, finDesc as Q, FieldDesc as R, Unit as S, merge as T, SchemaBounds as U, LeanIOError as V, Slot as W, checkValue as X, charDesc as Y, exceptDesc as Z, UInt16 as _, toTs as _t, Float32 as a, lazy as at, UInt8 as b, unitDesc as bt, InferOutput as c, natDesc as ct, Int32 as d, refDesc as dt, floatDesc as et, Int64 as f, resolve as ft, StringSchema as g, toLean as gt, Nat as h, stringDesc as ht, Float as i, jsonValue as it, arbitrary as j, toJSON as k, Int as l, optionDesc as lt, LeanSchema as m, standardValidate as mt, Char as n, ioResult as nt, ISize as o, listDesc as ot, Int8 as p, sintDesc as pt, arrayDesc as q, ExceptInput as r, isizeDesc as rt, InferInput as s, modelDesc as st, Bool as t, intDesc as tt, Int16 as u, prodDesc as ut, UInt32 as v, typeDesc as vt, fromJSON as w, USize as x, usizeDesc as xt, UInt64 as y, uintDesc as yt, InvariantDesc as z };
@@ -0,0 +1,23 @@
1
+ import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
2
+ export declare const GENERATOR_VERSION: string;
3
+ type LeanModel = StandardSchemaV1 & StandardJSONSchemaV1;
4
+ interface OutputOptions {
5
+ readonly tagKey?: string;
6
+ readonly option?: "null" | "undefined";
7
+ }
8
+ interface LeanBlockOptions {
9
+ readonly imports?: readonly string[];
10
+ readonly uses?: readonly string[];
11
+ readonly models?: Readonly<Record<string, LeanModel>>;
12
+ readonly output?: OutputOptions;
13
+ }
14
+ interface LeanBlock {
15
+ readonly name: string;
16
+ readonly key: string;
17
+ readonly models: Readonly<Record<string, LeanModel>>;
18
+ }
19
+ export declare class LeanBlockStale extends Error {
20
+ constructor(message: string);
21
+ }
22
+ export declare function lean(name: string, source: string, options?: LeanBlockOptions): LeanBlock;
23
+ export type { LeanBlock, LeanBlockOptions, LeanModel, OutputOptions };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { t as GENERATOR_VERSION, n as LeanBlockStale, o as lean } from "./embed-BlX4FUDH.js";
@@ -0,0 +1,66 @@
1
+ import { a as Ctor, l as Obj, s as Fn } from "./object-G1zwZFrv.js";
2
+ interface Platform {
3
+ target: string;
4
+ writeStdout(data: string | Uint8Array): void;
5
+ writeStderr(data: string | Uint8Array): void;
6
+ readFd(fd: number, buf: Uint8Array): number;
7
+ writeFd(fd: number, data: Uint8Array): void;
8
+ openFile(path: string, flags: string): number;
9
+ isTty(fd: number): boolean;
10
+ getenv(name: string): string | undefined;
11
+ argv(): string[];
12
+ exit(code: number): never;
13
+ setExitCode(code: number): void;
14
+ }
15
+ declare const browserPlatform: Platform;
16
+ declare function setPlatform(p: Platform): void;
17
+ declare function getPlatform(): Platform;
18
+ declare function lean_set_panic_messages(b: number): void;
19
+ declare function lean_set_exit_on_panic(b: number): void;
20
+ declare function lean_panic_fn<T>(defaultVal: T, msg: Obj): T;
21
+ declare function lean_panic_fn_borrowed<T>(defaultVal: T, msg: Obj): T;
22
+ declare function lean_internal_panic(msg: string): never;
23
+ declare function lean_internal_panic_unreachable(): never;
24
+ declare function lean_io_result_mk_ok(a: Obj): Ctor;
25
+ declare function lean_io_result_mk_error(e: Obj): Ctor;
26
+ declare function lean_io_result_is_ok(r: Obj): boolean;
27
+ declare function lean_io_result_get_value(r: Obj): Obj;
28
+ declare function lean_io_result_get_error(r: Obj): Obj;
29
+ declare function lean_mk_io_user_error(msg: Obj): Ctor;
30
+ declare function lean_mk_io_error_unsupported_operation(details: string): Ctor;
31
+ declare function lean_io_error_to_string(e: Obj): string;
32
+ declare function lean_get_stdout(): Obj;
33
+ declare function lean_get_stderr(): Obj;
34
+ declare function lean_get_stdin(): Obj;
35
+ declare function lean_get_set_stdout(s: Obj): Obj;
36
+ declare function lean_get_set_stderr(s: Obj): Obj;
37
+ declare function lean_get_set_stdin(s: Obj): Obj;
38
+ declare function lean_io_eprint(s: Obj): Obj;
39
+ declare function lean_io_eprintln(s: Obj): Obj;
40
+ declare function lean_st_mk_ref(a: Obj): Obj;
41
+ declare function lean_st_ref_get(r: Obj): Obj;
42
+ declare function lean_st_ref_set(r: Obj, a: Obj): Obj;
43
+ declare function lean_st_ref_swap(r: Obj, a: Obj): Obj;
44
+ declare function lean_st_ref_take(r: Obj): Obj;
45
+ declare function lean_st_ref_put(r: Obj, a: Obj): Obj;
46
+ declare function lean_st_ref_ptr_eq(r1: Obj, r2: Obj): number;
47
+ declare function lean_io_getenv(name: Obj): Obj;
48
+ declare function lean_io_exit(code: number): never;
49
+ declare function lean_io_force_exit(code: number): never;
50
+ declare function lean_io_prim_handle_mk(path: Obj, mode: number): Obj;
51
+ declare function lean_io_prim_handle_put_str(h: Obj, s: Obj): Obj;
52
+ declare function lean_io_prim_handle_write(h: Obj, buf: Obj): Obj;
53
+ declare function lean_io_prim_handle_read(h: Obj, n: bigint): Obj;
54
+ declare function lean_io_prim_handle_flush(_h: Obj): Obj;
55
+ declare function lean_io_prim_handle_is_tty(h: Obj): number;
56
+ declare function lean_io_prim_handle_get_line(h: Obj): Obj;
57
+ declare function lean_io_result_show_error(res: Obj): void;
58
+ declare function lean_dbg_trace(s: Obj, fn: Obj): Obj;
59
+ declare function lean_dbg_trace_if_shared(s: Obj, a: Obj): Obj;
60
+ declare function lean_dbg_sleep(_ms: number, fn: Obj): Obj;
61
+ declare function lean_ptr_addr(_a: Obj): bigint;
62
+ declare function lean_is_exclusive_obj(a: Obj): number;
63
+ declare function lean_register_init(thunk: () => Obj): void;
64
+ declare function lean_run_init(): Obj;
65
+ declare function lean_run_main(mainFn: Fn, hasArgs: boolean, retIsU32: boolean): void;
66
+ export { lean_io_result_is_ok as A, lean_register_init as B, lean_io_prim_handle_is_tty as C, lean_io_prim_handle_write as D, lean_io_prim_handle_read as E, lean_mk_io_error_unsupported_operation as F, lean_st_mk_ref as G, lean_run_main as H, lean_mk_io_user_error as I, lean_st_ref_put as J, lean_st_ref_get as K, lean_panic_fn as L, lean_io_result_mk_ok as M, lean_io_result_show_error as N, lean_io_result_get_error as O, lean_is_exclusive_obj as P, setPlatform as Q, lean_panic_fn_borrowed as R, lean_io_prim_handle_get_line as S, lean_io_prim_handle_put_str as T, lean_set_exit_on_panic as U, lean_run_init as V, lean_set_panic_messages as W, lean_st_ref_swap as X, lean_st_ref_set as Y, lean_st_ref_take as Z, lean_io_error_to_string as _, lean_dbg_trace as a, lean_io_getenv as b, lean_get_set_stdin as c, lean_get_stdin as d, lean_get_stdout as f, lean_io_eprintln as g, lean_io_eprint as h, lean_dbg_sleep as i, lean_io_result_mk_error as j, lean_io_result_get_value as k, lean_get_set_stdout as l, lean_internal_panic_unreachable as m, browserPlatform as n, lean_dbg_trace_if_shared as o, lean_internal_panic as p, lean_st_ref_ptr_eq as q, getPlatform as r, lean_get_set_stderr as s, Platform as t, lean_get_stderr as u, lean_io_exit as v, lean_io_prim_handle_mk as w, lean_io_prim_handle_flush as x, lean_io_force_exit as y, lean_ptr_addr as z };