@adhd/apigen-base-logical 0.1.0 → 0.1.2
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/CHANGELOG.md +49 -0
- package/README.md +36 -0
- package/index.d.ts +2 -0
- package/index.js +1 -1
- package/index.mjs +590 -310
- package/lib/contracts.d.ts +19 -0
- package/lib/example.d.ts +35 -0
- package/lib/hints.d.ts +11 -7
- package/package.json +20 -2
package/lib/contracts.d.ts
CHANGED
|
@@ -28,6 +28,25 @@ export interface LogicalTypeCodec<Host = unknown> {
|
|
|
28
28
|
readonly schema: SchemaNode;
|
|
29
29
|
/** Structural, cheap test: does this codec own `node`? (format match, or x-apigen-codec===id). */
|
|
30
30
|
matches(node: SchemaNode): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Value-side claim test, used ONLY on the schemaless path (a `{}` / `any`
|
|
33
|
+
* schema node, where `matches(node)` cannot decide anything).
|
|
34
|
+
*
|
|
35
|
+
* Implement this on — and only on — codecs whose HOST type is not
|
|
36
|
+
* JSON-native (`Date`, `bigint`, `Uint8Array`, non-finite `number`). Those
|
|
37
|
+
* are the values that genuinely need the `{$apigen,v}` envelope to survive
|
|
38
|
+
* a JSON round-trip. A codec whose host type IS JSON-native (`uuid` and
|
|
39
|
+
* `decimal` are both branded strings) must NOT implement it: a plain string
|
|
40
|
+
* already round-trips, and claiming it would rewrite a consumer's payload
|
|
41
|
+
* for no gain.
|
|
42
|
+
*
|
|
43
|
+
* A codec that omits `ownsValue` is never eligible for schemaless claiming.
|
|
44
|
+
* That is the safe default — passthrough loses nothing, whereas a wrong
|
|
45
|
+
* claim silently destroys data.
|
|
46
|
+
*
|
|
47
|
+
* MUST be pure and side-effect free.
|
|
48
|
+
*/
|
|
49
|
+
ownsValue?(value: unknown): boolean;
|
|
31
50
|
/** Host -> wire. MUST NOT mutate `value`; MUST be deterministic. */
|
|
32
51
|
encode(value: Host, node: SchemaNode, ctx: TranscodeCtx): Wire;
|
|
33
52
|
/** Wire -> host. MUST validate-then-construct; MUST be the inverse of `encode` across the vectors. */
|
package/lib/example.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The minimal JSON-Schema-shaped structure this module reads. */
|
|
2
|
+
export interface JsonSchemaLike {
|
|
3
|
+
type?: string | string[];
|
|
4
|
+
properties?: Record<string, JsonSchemaLike>;
|
|
5
|
+
required?: string[];
|
|
6
|
+
items?: JsonSchemaLike | JsonSchemaLike[];
|
|
7
|
+
enum?: unknown[];
|
|
8
|
+
const?: unknown;
|
|
9
|
+
format?: string;
|
|
10
|
+
oneOf?: JsonSchemaLike[];
|
|
11
|
+
anyOf?: JsonSchemaLike[];
|
|
12
|
+
allOf?: JsonSchemaLike[];
|
|
13
|
+
$ref?: string;
|
|
14
|
+
definitions?: Record<string, JsonSchemaLike>;
|
|
15
|
+
$defs?: Record<string, JsonSchemaLike>;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Synthesize a minimal, AJV-plausible example value for `schema`.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - The schema fragment to synthesize a value for.
|
|
22
|
+
* @param root - The document root `$ref`s in `schema` (and its descendants)
|
|
23
|
+
* resolve against. Defaults to `schema` itself — correct for the common
|
|
24
|
+
* case where `schema` IS the whole self-contained document (apigen always
|
|
25
|
+
* composes schemas this way; see module doc).
|
|
26
|
+
* @param depth - Internal recursion guard; callers never need to pass this.
|
|
27
|
+
*/
|
|
28
|
+
export declare function synthesizeExample(schema: JsonSchemaLike | undefined, root?: JsonSchemaLike, depth?: number): unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Render `schema`'s synthesized example as a compact `Example: {...}` note,
|
|
31
|
+
* or `undefined` if there's nothing meaningful to show (schema absent).
|
|
32
|
+
* Shared rendering so every call site (tool descriptions, validation error
|
|
33
|
+
* messages) produces byte-identical example text for the same schema.
|
|
34
|
+
*/
|
|
35
|
+
export declare function renderExampleNote(schema: JsonSchemaLike | undefined): string | undefined;
|
package/lib/hints.d.ts
CHANGED
|
@@ -15,18 +15,22 @@ export type CanonicalLogicalTypeId = (typeof CANONICAL_LOGICAL_TYPE_IDS)[number]
|
|
|
15
15
|
export type LanguageTable = Record<CanonicalLogicalTypeId, TemplateCell>;
|
|
16
16
|
/**
|
|
17
17
|
* @stable The host languages for which a template column exists in
|
|
18
|
-
* {@link TEMPLATE_CELLS}. `'typescript'` and `'
|
|
19
|
-
* (§13.2 values verbatim
|
|
20
|
-
*
|
|
21
|
-
* `
|
|
18
|
+
* {@link TEMPLATE_CELLS}. `'typescript'`, `'python'`, and `'java'` (FEAT-APIGEN-001
|
|
19
|
+
* slice 1/3, 2026-08-06) are fully filled (§13.2 values verbatim / real
|
|
20
|
+
* Jackson expressions — see the `JAVA_COLUMN` doc comments below).
|
|
21
|
+
* `'rust'` and `'go'` remain scaffolded — structure complete, expressions
|
|
22
|
+
* use stable placeholders pending the `lt-host-*` states.
|
|
22
23
|
*/
|
|
23
24
|
export type HostLanguage = 'typescript' | 'python' | 'rust' | 'go' | 'java';
|
|
24
25
|
/**
|
|
25
26
|
* @stable The template-cell registry: `[language][logicalTypeId] → TemplateCell`.
|
|
26
27
|
*
|
|
27
|
-
* TypeScript and
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* TypeScript, Python, and Java columns are fully filled (TypeScript/Python
|
|
29
|
+
* per DESIGN §13.2 verbatim expressions; Java per FEAT-APIGEN-001 slice 1/3 —
|
|
30
|
+
* real Jackson annotation/expression glue, no `__SCAFFOLD_*__` left — see
|
|
31
|
+
* `JAVA_COLUMN` above). Rust and Go columns remain scaffolded — structure
|
|
32
|
+
* complete, expressions use `__SCAFFOLD_*__` placeholders pending `lt-host-*`
|
|
33
|
+
* states.
|
|
30
34
|
*
|
|
31
35
|
* Keyed by {@link HostLanguage}, then by the canonical {@link CanonicalLogicalTypeId}.
|
|
32
36
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhd/apigen-base-logical",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"module": "./index.mjs",
|
|
6
|
-
"typings": "./index.d.ts"
|
|
6
|
+
"typings": "./index.d.ts",
|
|
7
|
+
"description": "Logical-type transcoding contracts for apigen",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"api",
|
|
10
|
+
"codegen",
|
|
11
|
+
"logical-types",
|
|
12
|
+
"schema",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/PseudoSky/adhd.git",
|
|
19
|
+
"directory": "packages/apigen/apigen-base-logical"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/PseudoSky/adhd/tree/main/packages/apigen/apigen-base-logical#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/PseudoSky/adhd/issues"
|
|
24
|
+
}
|
|
7
25
|
}
|