@leemour/cli-core 0.6.1 → 0.8.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/README.md +31 -0
- package/dist/codegen/index.d.ts +12 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +11 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/manifest.d.ts +41 -0
- package/dist/codegen/manifest.d.ts.map +1 -0
- package/dist/codegen/manifest.js +59 -0
- package/dist/codegen/manifest.js.map +1 -0
- package/dist/codegen/model.d.ts +139 -0
- package/dist/codegen/model.d.ts.map +1 -0
- package/dist/codegen/model.js +7 -0
- package/dist/codegen/model.js.map +1 -0
- package/dist/codegen/names.d.ts +4 -0
- package/dist/codegen/names.d.ts.map +1 -0
- package/dist/codegen/names.js +46 -0
- package/dist/codegen/names.js.map +1 -0
- package/dist/codegen/pipeline.d.ts +24 -0
- package/dist/codegen/pipeline.d.ts.map +1 -0
- package/dist/codegen/pipeline.js +134 -0
- package/dist/codegen/pipeline.js.map +1 -0
- package/dist/codegen/runtime.d.ts +24 -0
- package/dist/codegen/runtime.d.ts.map +1 -0
- package/dist/codegen/runtime.js +38 -0
- package/dist/codegen/runtime.js.map +1 -0
- package/dist/codegen/tree.d.ts +29 -0
- package/dist/codegen/tree.d.ts.map +1 -0
- package/dist/codegen/tree.js +87 -0
- package/dist/codegen/tree.js.map +1 -0
- package/dist/codegen/typescript.d.ts +6 -0
- package/dist/codegen/typescript.d.ts.map +1 -0
- package/dist/codegen/typescript.js +76 -0
- package/dist/codegen/typescript.js.map +1 -0
- package/dist/codegen/valibot.d.ts +10 -0
- package/dist/codegen/valibot.d.ts.map +1 -0
- package/dist/codegen/valibot.js +121 -0
- package/dist/codegen/valibot.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -5
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sanitize.d.ts +12 -0
- package/dist/sanitize.d.ts.map +1 -1
- package/dist/sanitize.js +21 -4
- package/dist/sanitize.js.map +1 -1
- package/package.json +21 -16
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ streams.stderr // []
|
|
|
46
46
|
| `/commands` | the command registry: `describeProgram`, `annotate`, `flatten` — see below |
|
|
47
47
|
| `/completion` | shell completion over the registry: `suggest`, `formatSuggestions` — see below |
|
|
48
48
|
| `/update` | keeping an install current: `installerOf`, `updateCommand`, `latestVersion`, `mayNotify`, `updateNotice`, `runUpdate` — see below |
|
|
49
|
+
| `/codegen` | build time: an official API description → types, Valibot schemas, an operation manifest and a coverage page — see below |
|
|
49
50
|
|
|
50
51
|
**Nothing in the root export is HTTP.** Status classification, `Retry-After` parsing and the fetch
|
|
51
52
|
seam live in `@leemour/cli-core/http`, so a CLI that speaks a socket never depends on a stack it
|
|
@@ -99,6 +100,36 @@ second line of defence, not the first.
|
|
|
99
100
|
no ambient clock. That is what makes a timeout test finish instantly and a keyring test incapable
|
|
100
101
|
of reaching a real keychain.
|
|
101
102
|
|
|
103
|
+
**Generating an API catalog is `@leemour/cli-core/codegen`**, a build-time tool. It reads a
|
|
104
|
+
format-neutral `ApiModel` — operations with a transport binding (`http` method and path, or `rpc`
|
|
105
|
+
name), an `effect` (`read`, `write`, `destructive`) and how far the source can be trusted
|
|
106
|
+
(`contract`, `example`, `inferred`, `override`) — and writes committed files. It parses no file
|
|
107
|
+
format: the adapter from OpenAPI, Postman or anything else lives in the CLI that has that source,
|
|
108
|
+
so this adds no dependency. Generation stops, naming the problem, when two operations collide, an
|
|
109
|
+
operation is not classified as a read or a write, an override matches nothing, a reference points
|
|
110
|
+
nowhere or a construct cannot be expressed; it never drops an operation or falls back to `any`.
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { generate, manifestGenerator, typesGenerator, valibotGenerator, writeArtifacts } from "@leemour/cli-core/codegen"
|
|
114
|
+
|
|
115
|
+
const artifacts = generate(model, [typesGenerator({ path }), valibotGenerator({ path, typesImport }), manifestGenerator({ path })], {
|
|
116
|
+
overrides: { answerOnCallback: { effect: "write", reason: "a POST that edits a message" } },
|
|
117
|
+
banner: ["Source: spec/bot/schema.yaml", "Run: pnpm bot:generate"],
|
|
118
|
+
})
|
|
119
|
+
const stale = writeArtifacts(artifacts, { root, check: process.argv.includes("--check") })
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The generated schemas import `@leemour/cli-core/codegen/runtime` at run time — a few number
|
|
123
|
+
helpers, not the generator. Numbers are expected from a lossless JSON parser (`lossless-json`): a
|
|
124
|
+
64-bit integer comes out as its exact decimal string, and any other integer that does not fit a JS
|
|
125
|
+
number fails instead of rounding. Objects are loose, so a field the API added later passes through.
|
|
126
|
+
Enums and discriminated unions are **strict**: a value or subtype the snapshot does not know fails,
|
|
127
|
+
so decode a live stream (updates, webhooks) only where that is what you want.
|
|
128
|
+
|
|
129
|
+
**The schemas decode; they do not encode.** Their output carries an `int64` as a string, so sending
|
|
130
|
+
it back would put a string where the API expects a number. Validate a request with the schema, then
|
|
131
|
+
send the original lossless value.
|
|
132
|
+
|
|
102
133
|
**Keeping an install current is `@leemour/cli-core/update`.** `installerOf(realpath(script))` says
|
|
103
134
|
which package manager put the CLI there — pnpm, npm or bun, measured on real installs — and
|
|
104
135
|
`updateCommand` gives the argv that updates it; a checkout or `npx` gets none. `latestVersion` asks
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an official API description into committed code: types, Valibot schemas, an operation
|
|
3
|
+
* manifest and a coverage page. Build-time only, and format-neutral: it parses no file format and
|
|
4
|
+
* adds no dependency. The adapter from OpenAPI, Postman or anything else lives in the consumer.
|
|
5
|
+
*/
|
|
6
|
+
export { type CoverageOptions, coverageGenerator, type ManifestOperation, manifestGenerator } from "./manifest.js";
|
|
7
|
+
export type { ApiBody, ApiModel, ApiOperation, ApiParameter, ApiSchema, Binding, CodeGenerator, Confidence, Discriminator, Effect, GeneratedArtifact, HttpBinding, HttpMethod, Override, RpcBinding, SchemaNode, SourceInfo, SourceReference, } from "./model.js";
|
|
8
|
+
export { identifier, kebab } from "./names.js";
|
|
9
|
+
export { applyOverrides, CodegenError, type GenerateOptions, generate, validateModel, type WriteOptions, writeArtifacts, } from "./pipeline.js";
|
|
10
|
+
export { typesGenerator } from "./typescript.js";
|
|
11
|
+
export { type ValibotOptions, valibotGenerator } from "./valibot.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,eAAe,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAClH,YAAY,EACV,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,OAAO,EACP,aAAa,EACb,UAAU,EACV,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,GAChB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EACL,cAAc,EACd,YAAY,EACZ,KAAK,eAAe,EACpB,QAAQ,EACR,aAAa,EACb,KAAK,YAAY,EACjB,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,KAAK,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an official API description into committed code: types, Valibot schemas, an operation
|
|
3
|
+
* manifest and a coverage page. Build-time only, and format-neutral: it parses no file format and
|
|
4
|
+
* adds no dependency. The adapter from OpenAPI, Postman or anything else lives in the consumer.
|
|
5
|
+
*/
|
|
6
|
+
export { coverageGenerator, manifestGenerator } from "./manifest.js";
|
|
7
|
+
export { identifier, kebab } from "./names.js";
|
|
8
|
+
export { applyOverrides, CodegenError, generate, validateModel, writeArtifacts, } from "./pipeline.js";
|
|
9
|
+
export { typesGenerator } from "./typescript.js";
|
|
10
|
+
export { valibotGenerator } from "./valibot.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAwB,iBAAiB,EAA0B,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAqBlH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EACL,cAAc,EACd,YAAY,EAEZ,QAAQ,EACR,aAAa,EAEb,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAuB,gBAAgB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Binding, CodeGenerator, Confidence, Effect, SchemaNode } from "./model.js";
|
|
2
|
+
/** One operation as a CLI reads it at run time: enough to build a command, validate input and guard a write. */
|
|
3
|
+
export interface ManifestOperation {
|
|
4
|
+
id: string;
|
|
5
|
+
command: string;
|
|
6
|
+
binding: Binding;
|
|
7
|
+
effect: Effect;
|
|
8
|
+
summary?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
tags: readonly string[];
|
|
11
|
+
deprecated?: boolean;
|
|
12
|
+
parameters: readonly {
|
|
13
|
+
name: string;
|
|
14
|
+
in: "path" | "query" | "header";
|
|
15
|
+
required: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
schema: SchemaNode;
|
|
18
|
+
}[];
|
|
19
|
+
request?: {
|
|
20
|
+
required: boolean;
|
|
21
|
+
confidence: Confidence;
|
|
22
|
+
schema?: string;
|
|
23
|
+
};
|
|
24
|
+
response?: {
|
|
25
|
+
confidence: Confidence;
|
|
26
|
+
schema?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare const manifestGenerator: (options: {
|
|
30
|
+
path: string;
|
|
31
|
+
coreImport?: string;
|
|
32
|
+
}) => CodeGenerator;
|
|
33
|
+
export interface CoverageOptions {
|
|
34
|
+
path: string;
|
|
35
|
+
title: string;
|
|
36
|
+
/** How a user reaches the operation, e.g. `max bot api get-my-info`. */
|
|
37
|
+
command: (operation: ManifestOperation) => string;
|
|
38
|
+
}
|
|
39
|
+
/** Every operation the source has, and how it is reached — the page a reviewer diffs after a sync. */
|
|
40
|
+
export declare const coverageGenerator: (options: CoverageOptions) => CodeGenerator;
|
|
41
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/codegen/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAIhH,gHAAgH;AAChH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IACvB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,EAAE,SAAS;QACnB,IAAI,EAAE,MAAM,CAAA;QACZ,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;QAC/B,QAAQ,EAAE,OAAO,CAAA;QACjB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,MAAM,EAAE,UAAU,CAAA;KACnB,EAAE,CAAA;IACH,OAAO,CAAC,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACxE,QAAQ,CAAC,EAAE;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACvD;AA4BD,eAAO,MAAM,iBAAiB,YAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,aAWjD,CAAA;AAIH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,wEAAwE;IACxE,OAAO,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,MAAM,CAAA;CAClD;AAED,sGAAsG;AACtG,eAAO,MAAM,iBAAiB,YAClB,eAAe,KAAG,aAwB3B,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { kebab } from "./names.js";
|
|
2
|
+
import { SchemaTree } from "./tree.js";
|
|
3
|
+
const withoutUndefined = (value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
|
|
4
|
+
const toManifest = (operation, tree) => withoutUndefined({
|
|
5
|
+
id: operation.id,
|
|
6
|
+
command: kebab(operation.id),
|
|
7
|
+
binding: operation.binding,
|
|
8
|
+
effect: operation.effect,
|
|
9
|
+
summary: operation.summary,
|
|
10
|
+
description: operation.description,
|
|
11
|
+
tags: operation.tags,
|
|
12
|
+
deprecated: operation.deprecated,
|
|
13
|
+
parameters: operation.parameters.map((parameter) => withoutUndefined({ ...parameter })),
|
|
14
|
+
request: operation.requestBody
|
|
15
|
+
? withoutUndefined({
|
|
16
|
+
required: operation.requestBody.required,
|
|
17
|
+
confidence: operation.requestBody.confidence,
|
|
18
|
+
schema: tree.requestName(operation.id),
|
|
19
|
+
})
|
|
20
|
+
: undefined,
|
|
21
|
+
response: operation.response
|
|
22
|
+
? withoutUndefined({ confidence: operation.response.confidence, schema: tree.responseName(operation.id) })
|
|
23
|
+
: undefined,
|
|
24
|
+
});
|
|
25
|
+
export const manifestGenerator = (options) => (model) => {
|
|
26
|
+
const tree = new SchemaTree(model);
|
|
27
|
+
const operations = model.operations.map((operation) => toManifest(operation, tree));
|
|
28
|
+
const content = [
|
|
29
|
+
`import type { ManifestOperation } from "${options.coreImport ?? "@leemour/cli-core/codegen"}"`,
|
|
30
|
+
"",
|
|
31
|
+
`export const operations: readonly ManifestOperation[] = ${JSON.stringify(operations, null, 2)}`,
|
|
32
|
+
"",
|
|
33
|
+
].join("\n");
|
|
34
|
+
return [{ path: options.path, content }];
|
|
35
|
+
};
|
|
36
|
+
const cell = (text) => (text ?? "").replace(/\s+/g, " ").replace(/\|/g, "\\|").trim();
|
|
37
|
+
/** Every operation the source has, and how it is reached — the page a reviewer diffs after a sync. */
|
|
38
|
+
export const coverageGenerator = (options) => (model) => {
|
|
39
|
+
const tree = new SchemaTree(model);
|
|
40
|
+
const rows = model.operations.map((operation) => {
|
|
41
|
+
const entry = toManifest(operation, tree);
|
|
42
|
+
const binding = entry.binding.kind === "http" ? `${entry.binding.method} ${entry.binding.path}` : entry.binding.name;
|
|
43
|
+
const status = entry.deprecated ? "deprecated" : "generated";
|
|
44
|
+
return `| \`${entry.id}\` | \`${binding}\` | \`${options.command(entry)}\` | ${entry.effect} | ${entry.request?.confidence ?? "—"} | ${status} | ${cell(entry.summary)} |`;
|
|
45
|
+
});
|
|
46
|
+
const version = model.source.version ? ` ${model.source.version}` : "";
|
|
47
|
+
const content = [
|
|
48
|
+
`# ${options.title}`,
|
|
49
|
+
"",
|
|
50
|
+
`${model.operations.length} operations from ${model.source.kind}${version}.`,
|
|
51
|
+
"",
|
|
52
|
+
"| Operation | Call | Command | Effect | Request source | Status | Summary |",
|
|
53
|
+
"|---|---|---|---|---|---|---|",
|
|
54
|
+
...rows,
|
|
55
|
+
"",
|
|
56
|
+
].join("\n");
|
|
57
|
+
return [{ path: options.path, content }];
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/codegen/manifest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAuBtC,MAAM,gBAAgB,GAAG,CAAmB,KAAQ,EAAK,EAAE,CACzD,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAM,CAAA;AAE3F,MAAM,UAAU,GAAG,CAAC,SAAuB,EAAE,IAAgB,EAAqB,EAAE,CAClF,gBAAgB,CAAC;IACf,EAAE,EAAE,SAAS,CAAC,EAAE;IAChB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;IAC5B,OAAO,EAAE,SAAS,CAAC,OAAO;IAC1B,MAAM,EAAE,SAAS,CAAC,MAAgB;IAClC,OAAO,EAAE,SAAS,CAAC,OAAO;IAC1B,WAAW,EAAE,SAAS,CAAC,WAAW;IAClC,IAAI,EAAE,SAAS,CAAC,IAAI;IACpB,UAAU,EAAE,SAAS,CAAC,UAAU;IAChC,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;IACvF,OAAO,EAAE,SAAS,CAAC,WAAW;QA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AC,IAAI,GAAG,OAAO,GAAG;QAC5E,EAAE;QACF,6EAA6E;QAC7E,+BAA+B;QAC/B,GAAG,IAAI;QACP,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACZ,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;AAC1C,CAAC,CAAA"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model every generator reads, whatever the source was: an OpenAPI file, a Postman collection,
|
|
3
|
+
* a scraped reference page. A source adapter lives in the consumer and produces this; nothing here
|
|
4
|
+
* parses a file format.
|
|
5
|
+
*/
|
|
6
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
7
|
+
/** How much the source promises. A Postman example is not a contract and must never become one. */
|
|
8
|
+
export type Confidence = "contract" | "example" | "inferred" | "override";
|
|
9
|
+
/**
|
|
10
|
+
* `undefined` in an adapter's output means "the source did not say". Generation refuses to run
|
|
11
|
+
* until an override classifies it — a write mistaken for a read is the expensive mistake.
|
|
12
|
+
*/
|
|
13
|
+
export type Effect = "read" | "write" | "destructive";
|
|
14
|
+
export interface HttpBinding {
|
|
15
|
+
kind: "http";
|
|
16
|
+
method: HttpMethod;
|
|
17
|
+
path: string;
|
|
18
|
+
}
|
|
19
|
+
/** Every call is the same HTTP shape and only the name differs, as in the Telegram Bot API. */
|
|
20
|
+
export interface RpcBinding {
|
|
21
|
+
kind: "rpc";
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
export type Binding = HttpBinding | RpcBinding;
|
|
25
|
+
interface SchemaCommon {
|
|
26
|
+
description?: string;
|
|
27
|
+
nullable?: boolean;
|
|
28
|
+
deprecated?: boolean;
|
|
29
|
+
default?: unknown;
|
|
30
|
+
}
|
|
31
|
+
export type SchemaNode = SchemaCommon & ({
|
|
32
|
+
type: "ref";
|
|
33
|
+
ref: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "string";
|
|
36
|
+
enum?: readonly string[];
|
|
37
|
+
minLength?: number;
|
|
38
|
+
maxLength?: number;
|
|
39
|
+
pattern?: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "integer";
|
|
42
|
+
format?: "int32" | "int64";
|
|
43
|
+
minimum?: number;
|
|
44
|
+
maximum?: number;
|
|
45
|
+
enum?: readonly number[];
|
|
46
|
+
} | {
|
|
47
|
+
type: "number";
|
|
48
|
+
minimum?: number;
|
|
49
|
+
maximum?: number;
|
|
50
|
+
} | {
|
|
51
|
+
type: "boolean";
|
|
52
|
+
} | {
|
|
53
|
+
type: "array";
|
|
54
|
+
items: SchemaNode;
|
|
55
|
+
minItems?: number;
|
|
56
|
+
maxItems?: number;
|
|
57
|
+
uniqueItems?: boolean;
|
|
58
|
+
} | {
|
|
59
|
+
type: "object";
|
|
60
|
+
properties: Readonly<Record<string, SchemaNode>>;
|
|
61
|
+
required: readonly string[];
|
|
62
|
+
additionalProperties?: SchemaNode;
|
|
63
|
+
}
|
|
64
|
+
/** Inheritance: every member must resolve to an object, and the fields are merged. */
|
|
65
|
+
| {
|
|
66
|
+
type: "allOf";
|
|
67
|
+
of: readonly SchemaNode[];
|
|
68
|
+
}
|
|
69
|
+
/** Only where the source itself says "anything". An adapter never falls back to this. */
|
|
70
|
+
| {
|
|
71
|
+
type: "unknown";
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* A base type with subtypes chosen by one property, OpenAPI's `discriminator`. Referenced from
|
|
75
|
+
* inside an `allOf` it means the base's own fields; referenced anywhere else, one of the subtypes.
|
|
76
|
+
*/
|
|
77
|
+
export interface Discriminator {
|
|
78
|
+
property: string;
|
|
79
|
+
mapping: Readonly<Record<string, string>>;
|
|
80
|
+
}
|
|
81
|
+
export interface ApiSchema {
|
|
82
|
+
id: string;
|
|
83
|
+
schema: SchemaNode;
|
|
84
|
+
discriminator?: Discriminator;
|
|
85
|
+
}
|
|
86
|
+
export interface ApiParameter {
|
|
87
|
+
name: string;
|
|
88
|
+
in: "path" | "query" | "header";
|
|
89
|
+
required: boolean;
|
|
90
|
+
description?: string;
|
|
91
|
+
schema: SchemaNode;
|
|
92
|
+
}
|
|
93
|
+
export interface ApiBody {
|
|
94
|
+
confidence: Confidence;
|
|
95
|
+
required: boolean;
|
|
96
|
+
schema?: SchemaNode;
|
|
97
|
+
example?: unknown;
|
|
98
|
+
}
|
|
99
|
+
export interface SourceReference {
|
|
100
|
+
/** Where in the source this came from, for a reviewer: a JSON pointer, a folder path. */
|
|
101
|
+
location: string;
|
|
102
|
+
}
|
|
103
|
+
export interface ApiOperation {
|
|
104
|
+
/** The source's own id where it has one. Never re-derived when it does. */
|
|
105
|
+
id: string;
|
|
106
|
+
binding: Binding;
|
|
107
|
+
summary?: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
tags: readonly string[];
|
|
110
|
+
parameters: readonly ApiParameter[];
|
|
111
|
+
requestBody?: ApiBody;
|
|
112
|
+
response?: ApiBody;
|
|
113
|
+
effect?: Effect;
|
|
114
|
+
deprecated?: boolean;
|
|
115
|
+
source: SourceReference;
|
|
116
|
+
}
|
|
117
|
+
export interface SourceInfo {
|
|
118
|
+
kind: "openapi" | "postman" | "other";
|
|
119
|
+
version?: string;
|
|
120
|
+
sourceUrl?: string;
|
|
121
|
+
sourceRevision?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface ApiModel {
|
|
124
|
+
source: SourceInfo;
|
|
125
|
+
operations: readonly ApiOperation[];
|
|
126
|
+
schemas: readonly ApiSchema[];
|
|
127
|
+
}
|
|
128
|
+
export interface Override {
|
|
129
|
+
effect?: Effect;
|
|
130
|
+
/** Required: an override nobody can explain is one nobody dares remove. */
|
|
131
|
+
reason: string;
|
|
132
|
+
}
|
|
133
|
+
export interface GeneratedArtifact {
|
|
134
|
+
path: string;
|
|
135
|
+
content: string;
|
|
136
|
+
}
|
|
137
|
+
export type CodeGenerator = (model: ApiModel) => GeneratedArtifact[];
|
|
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,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model every generator reads, whatever the source was: an OpenAPI file, a Postman collection,
|
|
3
|
+
* a scraped reference page. A source adapter lives in the consumer and produces this; nothing here
|
|
4
|
+
* parses a file format.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/codegen/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/codegen/names.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,UAAU,OAAQ,MAAM,KAAG,MAIvC,CAAA;AAED,mCAAmC;AACnC,eAAO,MAAM,KAAK,OAAQ,MAAM,KAAG,MAKjB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const pascal = (text) => text
|
|
2
|
+
.split(/[^A-Za-z0-9]+/)
|
|
3
|
+
.filter(Boolean)
|
|
4
|
+
.map((word) => word[0]?.toUpperCase() + word.slice(1))
|
|
5
|
+
.join("");
|
|
6
|
+
// A generated `export const Error` compiles, and then every `new Error()` in that module builds a schema.
|
|
7
|
+
const GLOBALS = new Set([
|
|
8
|
+
"Array",
|
|
9
|
+
"BigInt",
|
|
10
|
+
"Boolean",
|
|
11
|
+
"Date",
|
|
12
|
+
"Error",
|
|
13
|
+
"Function",
|
|
14
|
+
"Intl",
|
|
15
|
+
"JSON",
|
|
16
|
+
"Map",
|
|
17
|
+
"Math",
|
|
18
|
+
"Number",
|
|
19
|
+
"Object",
|
|
20
|
+
"Partial",
|
|
21
|
+
"Promise",
|
|
22
|
+
"Proxy",
|
|
23
|
+
"Record",
|
|
24
|
+
"Reflect",
|
|
25
|
+
"RegExp",
|
|
26
|
+
"Required",
|
|
27
|
+
"Set",
|
|
28
|
+
"String",
|
|
29
|
+
"Symbol",
|
|
30
|
+
"URL",
|
|
31
|
+
"WeakMap",
|
|
32
|
+
"WeakSet",
|
|
33
|
+
]);
|
|
34
|
+
export const identifier = (id) => {
|
|
35
|
+
const name = pascal(id);
|
|
36
|
+
if (!/^[A-Za-z]/.test(name))
|
|
37
|
+
return `Schema${name}`;
|
|
38
|
+
return GLOBALS.has(name) ? `Api${name}` : name;
|
|
39
|
+
};
|
|
40
|
+
/** `getMyInfo` → `get-my-info`. */
|
|
41
|
+
export const kebab = (id) => id
|
|
42
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
43
|
+
.replace(/[^A-Za-z0-9]+/g, "-")
|
|
44
|
+
.replace(/^-|-$/g, "")
|
|
45
|
+
.toLowerCase();
|
|
46
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../src/codegen/names.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CACtC,IAAI;KACD,KAAK,CAAC,eAAe,CAAC;KACtB,MAAM,CAAC,OAAO,CAAC;KACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACrD,IAAI,CAAC,EAAE,CAAC,CAAA;AAEb,0GAA0G;AAC1G,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,OAAO;IACP,QAAQ;IACR,SAAS;IACT,MAAM;IACN,OAAO;IACP,UAAU;IACV,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,OAAO;IACP,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,UAAU;IACV,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,SAAS;IACT,SAAS;CACV,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAU,EAAE;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAA;IACvB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,IAAI,EAAE,CAAA;IACnD,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAChD,CAAC,CAAA;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAU,EAAE,CAC1C,EAAE;KACC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;KACtC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;KAC9B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;KACrB,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ApiModel, CodeGenerator, GeneratedArtifact, Override } from "./model.js";
|
|
2
|
+
export declare class CodegenError extends Error {
|
|
3
|
+
readonly problems: readonly string[];
|
|
4
|
+
constructor(problems: readonly string[]);
|
|
5
|
+
}
|
|
6
|
+
export declare const applyOverrides: (model: ApiModel, overrides: Readonly<Record<string, Override>>) => ApiModel;
|
|
7
|
+
/** Everything that would otherwise make an operation vanish or turn into a guess. */
|
|
8
|
+
export declare const validateModel: (model: ApiModel) => void;
|
|
9
|
+
export interface GenerateOptions {
|
|
10
|
+
overrides?: Readonly<Record<string, Override>>;
|
|
11
|
+
/** Lines under "GENERATED. DO NOT EDIT." — the source and the command. Nothing that changes by itself. */
|
|
12
|
+
banner: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export declare const generate: (model: ApiModel, generators: readonly CodeGenerator[], options: GenerateOptions) => GeneratedArtifact[];
|
|
15
|
+
export interface WriteOptions {
|
|
16
|
+
root: string;
|
|
17
|
+
/** Compare only: report what is out of date and write nothing. */
|
|
18
|
+
check?: boolean;
|
|
19
|
+
/** The consumer's formatter, so a check compares what would actually be committed. */
|
|
20
|
+
format?: (path: string, content: string) => string;
|
|
21
|
+
}
|
|
22
|
+
/** Paths whose committed content differs from what was generated — written, or with `check`, only reported. */
|
|
23
|
+
export declare const writeArtifacts: (artifacts: readonly GeneratedArtifact[], options: WriteOptions) => string[];
|
|
24
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/codegen/pipeline.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAgB,aAAa,EAAE,iBAAiB,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAA;AAGhH,qBAAa,YAAa,SAAQ,KAAK;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE;IAAhD,YAAqB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAG/C;CACF;AAED,eAAO,MAAM,cAAc,UAAW,QAAQ,aAAa,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAG,QAc/F,CAAA;AA6BD,qFAAqF;AACrF,eAAO,MAAM,aAAa,UAAW,QAAQ,KAAG,IAyC/C,CAAA;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;IAC9C,0GAA0G;IAC1G,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAC1B;AAOD,eAAO,MAAM,QAAQ,UACZ,QAAQ,cACH,SAAS,aAAa,EAAE,WAC3B,eAAe,KACvB,iBAAiB,EAQnB,CAAA;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,kEAAkE;IAClE,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,sFAAsF;IACtF,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACnD;AAED,+GAA+G;AAC/G,eAAO,MAAM,cAAc,cAAe,SAAS,iBAAiB,EAAE,WAAW,YAAY,KAAG,MAAM,EAarG,CAAA"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, extname, join } from "node:path";
|
|
3
|
+
import { identifier, kebab } from "./names.js";
|
|
4
|
+
export class CodegenError extends Error {
|
|
5
|
+
problems;
|
|
6
|
+
constructor(problems) {
|
|
7
|
+
super(`generation stopped:\n${problems.map((problem) => ` - ${problem}`).join("\n")}`);
|
|
8
|
+
this.problems = problems;
|
|
9
|
+
this.name = "CodegenError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const applyOverrides = (model, overrides) => {
|
|
13
|
+
const known = new Set(model.operations.map((operation) => operation.id));
|
|
14
|
+
const stale = Object.keys(overrides).filter((id) => !known.has(id));
|
|
15
|
+
if (stale.length > 0) {
|
|
16
|
+
// A correction that matches nothing any more has silently stopped being applied.
|
|
17
|
+
throw new CodegenError(stale.map((id) => `override "${id}" matches no operation — stale, or the id changed`));
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
...model,
|
|
21
|
+
operations: model.operations.map((operation) => {
|
|
22
|
+
const override = overrides[operation.id];
|
|
23
|
+
return override?.effect ? { ...operation, effect: override.effect } : operation;
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const bindingKey = (operation) => operation.binding.kind === "http"
|
|
28
|
+
? `${operation.binding.method} ${operation.binding.path}`
|
|
29
|
+
: `rpc ${operation.binding.name}`;
|
|
30
|
+
const duplicates = (values) => [...new Set(values.filter((value, index) => values.indexOf(value) !== index))].sort();
|
|
31
|
+
const refsIn = (node, found = []) => {
|
|
32
|
+
switch (node.type) {
|
|
33
|
+
case "ref":
|
|
34
|
+
found.push(node.ref);
|
|
35
|
+
break;
|
|
36
|
+
case "array":
|
|
37
|
+
refsIn(node.items, found);
|
|
38
|
+
break;
|
|
39
|
+
case "object":
|
|
40
|
+
for (const property of Object.values(node.properties))
|
|
41
|
+
refsIn(property, found);
|
|
42
|
+
if (node.additionalProperties)
|
|
43
|
+
refsIn(node.additionalProperties, found);
|
|
44
|
+
break;
|
|
45
|
+
case "allOf":
|
|
46
|
+
for (const member of node.of)
|
|
47
|
+
refsIn(member, found);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
};
|
|
52
|
+
/** Everything that would otherwise make an operation vanish or turn into a guess. */
|
|
53
|
+
export const validateModel = (model) => {
|
|
54
|
+
const problems = [];
|
|
55
|
+
for (const id of duplicates(model.operations.map((operation) => operation.id))) {
|
|
56
|
+
problems.push(`two operations share the id "${id}"`);
|
|
57
|
+
}
|
|
58
|
+
for (const key of duplicates(model.operations.map(bindingKey)))
|
|
59
|
+
problems.push(`two operations are both ${key}`);
|
|
60
|
+
for (const id of duplicates(model.schemas.map((schema) => schema.id))) {
|
|
61
|
+
problems.push(`two schemas share the id "${id}"`);
|
|
62
|
+
}
|
|
63
|
+
for (const command of duplicates(model.operations.map((operation) => kebab(operation.id)))) {
|
|
64
|
+
problems.push(`two operations both become the command "${command}"`);
|
|
65
|
+
}
|
|
66
|
+
for (const name of duplicates(model.schemas.map((schema) => identifier(schema.id)))) {
|
|
67
|
+
problems.push(`two schemas both become the name "${name}"`);
|
|
68
|
+
}
|
|
69
|
+
for (const operation of model.operations) {
|
|
70
|
+
for (const name of duplicates(operation.parameters.map((parameter) => parameter.name))) {
|
|
71
|
+
problems.push(`operation "${operation.id}" has two parameters named "${name}"`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const operation of model.operations) {
|
|
75
|
+
if (!operation.effect)
|
|
76
|
+
problems.push(`operation "${operation.id}" is not classified as read, write or destructive`);
|
|
77
|
+
}
|
|
78
|
+
const schemaIds = new Set(model.schemas.map((schema) => schema.id));
|
|
79
|
+
const unresolved = (where, node) => {
|
|
80
|
+
if (!node)
|
|
81
|
+
return;
|
|
82
|
+
for (const ref of refsIn(node))
|
|
83
|
+
if (!schemaIds.has(ref))
|
|
84
|
+
problems.push(`${where} refers to unknown schema "${ref}"`);
|
|
85
|
+
};
|
|
86
|
+
for (const schema of model.schemas) {
|
|
87
|
+
unresolved(`schema "${schema.id}"`, schema.schema);
|
|
88
|
+
for (const [value, target] of Object.entries(schema.discriminator?.mapping ?? {})) {
|
|
89
|
+
if (!schemaIds.has(target))
|
|
90
|
+
problems.push(`schema "${schema.id}" maps "${value}" to unknown schema "${target}"`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const operation of model.operations) {
|
|
94
|
+
for (const parameter of operation.parameters)
|
|
95
|
+
unresolved(`operation "${operation.id}"`, parameter.schema);
|
|
96
|
+
unresolved(`operation "${operation.id}" request`, operation.requestBody?.schema);
|
|
97
|
+
unresolved(`operation "${operation.id}" response`, operation.response?.schema);
|
|
98
|
+
}
|
|
99
|
+
if (problems.length > 0)
|
|
100
|
+
throw new CodegenError(problems);
|
|
101
|
+
};
|
|
102
|
+
const commentFor = (path, lines) => {
|
|
103
|
+
if (extname(path) === ".md")
|
|
104
|
+
return `<!--\n${lines.join("\n")}\n-->\n\n`;
|
|
105
|
+
return `${lines.map((line) => `// ${line}`).join("\n")}\n\n`;
|
|
106
|
+
};
|
|
107
|
+
export const generate = (model, generators, options) => {
|
|
108
|
+
const prepared = applyOverrides(model, options.overrides ?? {});
|
|
109
|
+
validateModel(prepared);
|
|
110
|
+
const artifacts = generators.flatMap((generator) => generator(prepared));
|
|
111
|
+
const clashing = duplicates(artifacts.map((artifact) => artifact.path));
|
|
112
|
+
if (clashing.length > 0)
|
|
113
|
+
throw new CodegenError(clashing.map((path) => `two generators both write ${path}`));
|
|
114
|
+
const banner = ["GENERATED. DO NOT EDIT.", ...options.banner];
|
|
115
|
+
return artifacts.map((artifact) => ({ ...artifact, content: commentFor(artifact.path, banner) + artifact.content }));
|
|
116
|
+
};
|
|
117
|
+
/** Paths whose committed content differs from what was generated — written, or with `check`, only reported. */
|
|
118
|
+
export const writeArtifacts = (artifacts, options) => {
|
|
119
|
+
const stale = [];
|
|
120
|
+
for (const artifact of artifacts) {
|
|
121
|
+
const target = join(options.root, artifact.path);
|
|
122
|
+
const content = options.format ? options.format(artifact.path, artifact.content) : artifact.content;
|
|
123
|
+
const current = existsSync(target) ? readFileSync(target, "utf8") : undefined;
|
|
124
|
+
if (current === content)
|
|
125
|
+
continue;
|
|
126
|
+
stale.push(artifact.path);
|
|
127
|
+
if (options.check)
|
|
128
|
+
continue;
|
|
129
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
130
|
+
writeFileSync(target, content);
|
|
131
|
+
}
|
|
132
|
+
return stale;
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/codegen/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,OAAO,YAAa,SAAQ,KAAK;IAChB,QAAQ;IAA7B,YAAqB,QAA2B;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I,OAAO,KAAK,OAAO;YAAE,SAAQ;QACjC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACzB,IAAI,OAAO,CAAC,KAAK;YAAE,SAAQ;QAC3B,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC/C,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What generated Valibot schemas call at run time. Kept apart from the generator so a CLI loads
|
|
3
|
+
* these few functions, not the code that writes code.
|
|
4
|
+
*
|
|
5
|
+
* Numbers arrive from a lossless JSON parser (`lossless-json` or anything shaped like its
|
|
6
|
+
* `LosslessNumber`), because a 64-bit id read as a JS number is silently a different id.
|
|
7
|
+
*/
|
|
8
|
+
import * as v from "valibot";
|
|
9
|
+
interface LosslessLike {
|
|
10
|
+
isLosslessNumber: true;
|
|
11
|
+
value: string;
|
|
12
|
+
}
|
|
13
|
+
interface Range {
|
|
14
|
+
minimum?: number;
|
|
15
|
+
maximum?: number;
|
|
16
|
+
}
|
|
17
|
+
/** A 64-bit integer, handed on as its exact decimal string. */
|
|
18
|
+
export declare const int64: (range?: Range) => v.SchemaWithPipe<readonly [v.CustomSchema<number | bigint | LosslessLike, v.ErrorMessage<v.CustomIssue> | undefined>, v.TransformAction<number | bigint | LosslessLike, string>, v.CheckAction<string, "integer out of range">]>;
|
|
19
|
+
/** An integer that must fit a JS number exactly; one that does not fails instead of rounding. */
|
|
20
|
+
export declare const integer: (range?: Range) => v.SchemaWithPipe<readonly [v.CustomSchema<number | bigint | LosslessLike, v.ErrorMessage<v.CustomIssue> | undefined>, v.TransformAction<number | bigint | LosslessLike, number>, v.CheckAction<number, "integer out of range">]>;
|
|
21
|
+
export declare const number: (range?: Range) => v.SchemaWithPipe<readonly [v.CustomSchema<number | LosslessLike, v.ErrorMessage<v.CustomIssue> | undefined>, v.TransformAction<number | LosslessLike, number>, v.CheckAction<number, "number out of range">]>;
|
|
22
|
+
export declare const unique: (items: readonly unknown[]) => boolean;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/codegen/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,UAAU,YAAY;IACpB,gBAAgB,EAAE,IAAI,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;CACd;AAmBD,UAAU,KAAK;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAKD,+DAA+D;AAC/D,eAAO,MAAM,KAAK,WAAW,KAAK,qOAQ/B,CAAA;AAEH,iGAAiG;AACjG,eAAO,MAAM,OAAO,WAAW,KAAK,qOAQjC,CAAA;AAEH,eAAO,MAAM,MAAM,WAAW,KAAK,kNAQhC,CAAA;AAEH,eAAO,MAAM,MAAM,UAAW,SAAS,OAAO,EAAE,KAAG,OACuB,CAAA"}
|