@emeryld/rrroutes-export 1.0.3 → 1.0.4
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/defaultViewerTemplate.d.ts +1 -0
- package/dist/exportFinalizedLeaves.cli.d.ts +14 -0
- package/dist/exportFinalizedLeaves.d.ts +61 -0
- package/dist/extractLeafSourceByAst.d.ts +38 -0
- package/dist/flattenSchema.d.ts +12 -0
- package/dist/index.d.ts +7 -0
- package/dist/schemaIntrospection.d.ts +47 -0
- package/dist/serializeLeafContract.d.ts +31 -0
- package/package.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_VIEWER_TEMPLATE = "<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Finalized Leaves Viewer</title>\n <style>\n :root {\n --bg: #212121;\n --surface: #2a2a2a;\n --border: #4a4a4a;\n --text: #fffafa;\n --muted: #c8c2c2;\n --accent: #a764d3;\n --schema-accent: #fbbd23;\n }\n body {\n margin: 0;\n font-family: 'Iosevka Web', 'SFMono-Regular', Menlo, Consolas, monospace;\n color: var(--text);\n background: var(--bg);\n }\n a { color: var(--schema-accent); }\n .wrap { max-width: 1100px; margin: 0 auto; padding: 20px; }\n .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }\n .meta { color: var(--muted); font-size: 12px; }\n #results { margin-top: 12px; display: grid; gap: 8px; }\n details { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }\n summary { cursor: pointer; font-weight: 700; color: var(--accent); }\n pre { margin: 10px 0 0; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: #303030; color: var(--text); }\n </style>\n </head>\n <body>\n <div class=\"wrap\">\n <h1>Finalized Leaves Viewer (Baked)</h1>\n <div class=\"card\">\n <div id=\"status\" class=\"meta\">Waiting for baked payload...</div>\n </div>\n <div id=\"results\"></div>\n </div>\n\n <!--__FINALIZED_LEAVES_BAKED_PAYLOAD__-->\n\n <script>\n const statusEl = document.getElementById('status')\n const resultsEl = document.getElementById('results')\n const payload = window.__FINALIZED_LEAVES_PAYLOAD\n\n if (!payload || !Array.isArray(payload.leaves)) {\n statusEl.textContent = 'No baked payload found in this HTML file.'\n } else {\n statusEl.textContent = 'Loaded baked payload with ' + payload.leaves.length + ' routes.'\n\n const toHref = (source) => {\n if (!source || !source.file) return null\n const normalizedPath = String(source.file).replace(/\\\\/g, '/')\n const platform =\n (navigator.userAgentData && navigator.userAgentData.platform) ||\n navigator.platform ||\n ''\n const isWindows = /win/i.test(platform)\n const vscodePath = isWindows\n ? normalizedPath.replace(/^\\/+/, '')\n : normalizedPath.startsWith('/')\n ? normalizedPath\n : '/' + normalizedPath\n const line = Number.isFinite(source.line) ? source.line : 1\n const column = Number.isFinite(source.column) ? source.column : 1\n return 'vscode://file/' + encodeURI(vscodePath) + ':' + line + ':' + column\n }\n\n const sourceDisplay = (source) => {\n return ''\n }\n\n payload.leaves.forEach((leaf) => {\n const details = document.createElement('details')\n const summary = document.createElement('summary')\n summary.textContent = String(leaf.method || '').toUpperCase() + ' ' + (leaf.path || '')\n\n const pre = document.createElement('pre')\n pre.textContent = JSON.stringify(leaf, null, 2)\n\n const source = payload.sourceByLeaf && payload.sourceByLeaf[leaf.key]\n let sourceWrap = null\n if (source) {\n sourceWrap = document.createElement('div')\n sourceWrap.className = 'meta'\n\n const definitionHref = toHref(source.definition)\n if (definitionHref) {\n const label = document.createElement('div')\n const link = document.createElement('a')\n link.href = definitionHref\n link.target = '_blank'\n link.rel = 'noopener noreferrer'\n link.textContent = 'definition'\n label.appendChild(link)\n sourceWrap.appendChild(label)\n }\n\n if (source.schemas && typeof source.schemas === 'object') {\n Object.entries(source.schemas).forEach(([name, schema]) => {\n if (!schema) return\n const href = toHref(schema)\n const row = document.createElement('div')\n if (href) {\n const link = document.createElement('a')\n link.href = href\n link.target = '_blank'\n link.rel = 'noopener noreferrer'\n link.textContent =\n name + ': ' + (schema.sourceName || schema.tag || '<anonymous>')\n row.appendChild(link)\n } else {\n row.textContent = name + ': ' + (schema.sourceName || schema.tag || '<anonymous>')\n }\n sourceWrap.appendChild(row)\n })\n }\n\n }\n\n details.appendChild(summary)\n if (sourceWrap) details.appendChild(sourceWrap)\n details.appendChild(pre)\n resultsEl.appendChild(details)\n })\n }\n </script>\n </body>\n</html>\n";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ExportFinalizedLeavesInput } from './exportFinalizedLeaves';
|
|
2
|
+
export type FinalizedLeavesCliArgs = {
|
|
3
|
+
modulePath: string;
|
|
4
|
+
exportName: string;
|
|
5
|
+
outFile: string;
|
|
6
|
+
withSource: boolean;
|
|
7
|
+
tsconfigPath?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function parseFinalizedLeavesCliArgs(argv: string[]): FinalizedLeavesCliArgs;
|
|
10
|
+
export declare function loadFinalizedLeavesInput({ modulePath, exportName, }: FinalizedLeavesCliArgs): Promise<ExportFinalizedLeavesInput>;
|
|
11
|
+
export declare function runExportFinalizedLeavesCli(argv: string[]): Promise<{
|
|
12
|
+
payload: import("./exportFinalizedLeaves").FinalizedLeavesExport;
|
|
13
|
+
outFile: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AnyLeafLowProfile, FinalizedRegistry } from '@emeryld/rrroutes-contract';
|
|
2
|
+
import { type FlatSchemaMap } from './flattenSchema';
|
|
3
|
+
import { type SerializeLeafContractOptions, type SerializedLeafContract } from './serializeLeafContract';
|
|
4
|
+
import { type LeafSourceByKey, type SourceExtractionReason } from './extractLeafSourceByAst';
|
|
5
|
+
export type ExportFinalizedLeavesInput = readonly AnyLeafLowProfile[] | FinalizedRegistry<readonly AnyLeafLowProfile[]>;
|
|
6
|
+
export type ExportFinalizedLeavesMeta = {
|
|
7
|
+
generatedAt: string;
|
|
8
|
+
description: string;
|
|
9
|
+
sourceExtraction?: {
|
|
10
|
+
mode: 'ast';
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
modulePath?: string;
|
|
13
|
+
exportName?: string;
|
|
14
|
+
tsconfigPath?: string;
|
|
15
|
+
resolvedLeafCount: number;
|
|
16
|
+
reason?: SourceExtractionReason;
|
|
17
|
+
stats?: {
|
|
18
|
+
visitedSymbols: number;
|
|
19
|
+
visitedFiles: number;
|
|
20
|
+
unresolvedReferences: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
fieldCatalog: {
|
|
24
|
+
leaf: string[];
|
|
25
|
+
cfg: string[];
|
|
26
|
+
schemaNode: string[];
|
|
27
|
+
flatSchemaEntry: string[];
|
|
28
|
+
};
|
|
29
|
+
flattening: {
|
|
30
|
+
notation: 'dot+[]';
|
|
31
|
+
unionBranchSuffix: '-N';
|
|
32
|
+
sections: readonly ['params', 'query', 'body', 'output'];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type FinalizedLeavesExport = {
|
|
36
|
+
_meta: ExportFinalizedLeavesMeta;
|
|
37
|
+
leaves: SerializedLeafContract[];
|
|
38
|
+
schemaFlatByLeaf: Record<string, FlatSchemaMap>;
|
|
39
|
+
sourceByLeaf?: LeafSourceByKey;
|
|
40
|
+
};
|
|
41
|
+
export type ExportFinalizedLeavesOptions = SerializeLeafContractOptions & {
|
|
42
|
+
outFile?: string;
|
|
43
|
+
htmlFile?: string;
|
|
44
|
+
viewerTemplateFile?: string;
|
|
45
|
+
openOnFinish?: boolean;
|
|
46
|
+
includeSource?: boolean;
|
|
47
|
+
tsconfigPath?: string;
|
|
48
|
+
sourceModulePath?: string;
|
|
49
|
+
sourceExportName?: string;
|
|
50
|
+
};
|
|
51
|
+
export type WriteFinalizedLeavesExportOptions = {
|
|
52
|
+
outFile?: string;
|
|
53
|
+
htmlFile?: string;
|
|
54
|
+
viewerTemplateFile?: string;
|
|
55
|
+
openOnFinish?: boolean;
|
|
56
|
+
};
|
|
57
|
+
export declare function writeFinalizedLeavesExport(payload: FinalizedLeavesExport, outFileOrOptions: string | WriteFinalizedLeavesExportOptions): Promise<{
|
|
58
|
+
outFile?: string;
|
|
59
|
+
htmlFile?: string;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function exportFinalizedLeaves(input: ExportFinalizedLeavesInput, options?: ExportFinalizedLeavesOptions): Promise<FinalizedLeavesExport>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
declare const SCHEMA_KEYS: readonly ["bodySchema", "querySchema", "paramsSchema", "outputSchema", "outputMetaSchema", "queryExtensionSchema"];
|
|
2
|
+
export type SourceExtractionReason = 'module_not_in_program' | 'export_not_found' | 'unsupported_expression_shape' | 'resolved_zero_leaves';
|
|
3
|
+
type SchemaKey = (typeof SCHEMA_KEYS)[number];
|
|
4
|
+
export type LeafSourceLocation = {
|
|
5
|
+
file: string;
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
};
|
|
9
|
+
export type SchemaSourceMetadata = LeafSourceLocation & {
|
|
10
|
+
sourceName?: string;
|
|
11
|
+
tag?: '<inline>' | '<anonymous>' | '<expression>';
|
|
12
|
+
};
|
|
13
|
+
export type LeafSourceMetadata = {
|
|
14
|
+
definition: LeafSourceLocation & {
|
|
15
|
+
symbolName?: string;
|
|
16
|
+
};
|
|
17
|
+
schemas: Partial<Record<SchemaKey, SchemaSourceMetadata>>;
|
|
18
|
+
};
|
|
19
|
+
export type LeafSourceByKey = Record<string, LeafSourceMetadata>;
|
|
20
|
+
export type ExtractLeafSourceByAstOptions = {
|
|
21
|
+
modulePath: string;
|
|
22
|
+
exportName: string;
|
|
23
|
+
tsconfigPath?: string;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
};
|
|
26
|
+
export type ExtractLeafSourceByAstStats = {
|
|
27
|
+
visitedSymbols: number;
|
|
28
|
+
visitedFiles: number;
|
|
29
|
+
unresolvedReferences: number;
|
|
30
|
+
};
|
|
31
|
+
export type ExtractLeafSourceByAstResult = {
|
|
32
|
+
sourceByLeaf: LeafSourceByKey;
|
|
33
|
+
tsconfigPath?: string;
|
|
34
|
+
reason?: SourceExtractionReason;
|
|
35
|
+
stats: ExtractLeafSourceByAstStats;
|
|
36
|
+
};
|
|
37
|
+
export declare function extractLeafSourceByAst({ modulePath, exportName, tsconfigPath, cwd, }: ExtractLeafSourceByAstOptions): ExtractLeafSourceByAstResult;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AnyLeafLowProfile } from '@emeryld/rrroutes-contract';
|
|
2
|
+
import { type SerializedLeafContract } from './serializeLeafContract';
|
|
3
|
+
import type { SerializableSchema } from './schemaIntrospection';
|
|
4
|
+
export type FlatSchemaEntry = {
|
|
5
|
+
type: string;
|
|
6
|
+
nullable: boolean;
|
|
7
|
+
optional: boolean;
|
|
8
|
+
literal?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type FlatSchemaMap = Record<string, FlatSchemaEntry>;
|
|
11
|
+
export declare function flattenSerializableSchema(schema: SerializableSchema | undefined, path: string): FlatSchemaMap;
|
|
12
|
+
export declare function flattenLeafSchemas(leaf: AnyLeafLowProfile | SerializedLeafContract): FlatSchemaMap;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './schemaIntrospection';
|
|
2
|
+
export * from './serializeLeafContract';
|
|
3
|
+
export * from './flattenSchema';
|
|
4
|
+
export * from './exportFinalizedLeaves';
|
|
5
|
+
export * from './exportFinalizedLeaves.cli';
|
|
6
|
+
export * from './defaultViewerTemplate';
|
|
7
|
+
export * from './extractLeafSourceByAst';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const serializableSchemaKinds: readonly ["object", "string", "number", "boolean", "bigint", "date", "array", "enum", "literal", "union", "record", "tuple", "unknown", "any"];
|
|
3
|
+
export type SerializableSchemaKind = (typeof serializableSchemaKinds)[number];
|
|
4
|
+
export type SerializableSchema = {
|
|
5
|
+
kind: SerializableSchemaKind;
|
|
6
|
+
optional?: boolean;
|
|
7
|
+
nullable?: boolean;
|
|
8
|
+
description?: string;
|
|
9
|
+
properties?: Record<string, SerializableSchema>;
|
|
10
|
+
element?: SerializableSchema;
|
|
11
|
+
union?: SerializableSchema[];
|
|
12
|
+
literal?: unknown;
|
|
13
|
+
enumValues?: string[];
|
|
14
|
+
};
|
|
15
|
+
type ZodAny = z.ZodTypeAny;
|
|
16
|
+
type InternalSchemaKind = SerializableSchemaKind | 'intersection';
|
|
17
|
+
type IntrospectionWalker = (schema: ZodAny | undefined) => SerializableSchema | undefined;
|
|
18
|
+
export type IntrospectionContext = {
|
|
19
|
+
zod: typeof z;
|
|
20
|
+
introspect: IntrospectionWalker;
|
|
21
|
+
getDef: (schema: unknown) => any | undefined;
|
|
22
|
+
unwrap: (schema: ZodAny) => {
|
|
23
|
+
base: ZodAny;
|
|
24
|
+
optional: boolean;
|
|
25
|
+
nullable: boolean;
|
|
26
|
+
};
|
|
27
|
+
getDescription: (schema: ZodAny) => string | undefined;
|
|
28
|
+
};
|
|
29
|
+
export type IntrospectionNode = {
|
|
30
|
+
schema: ZodAny;
|
|
31
|
+
base: ZodAny;
|
|
32
|
+
def: any;
|
|
33
|
+
kind: InternalSchemaKind;
|
|
34
|
+
optional: boolean;
|
|
35
|
+
nullable: boolean;
|
|
36
|
+
node: SerializableSchema;
|
|
37
|
+
};
|
|
38
|
+
export type SchemaIntrospectionHandler = (args: IntrospectionNode, ctx: IntrospectionContext) => SerializableSchema | undefined;
|
|
39
|
+
export type SchemaIntrospectionHandlerMap = Partial<Record<InternalSchemaKind, SchemaIntrospectionHandler>>;
|
|
40
|
+
export type IntrospectSchemaOptions = {
|
|
41
|
+
handlers?: SchemaIntrospectionHandlerMap;
|
|
42
|
+
};
|
|
43
|
+
export declare function registerSchemaIntrospectionHandler(kind: InternalSchemaKind, handler: SchemaIntrospectionHandler): void;
|
|
44
|
+
export declare function clearSchemaIntrospectionHandlers(): void;
|
|
45
|
+
export declare function createSchemaIntrospector(options?: IntrospectSchemaOptions): IntrospectionWalker;
|
|
46
|
+
export declare function introspectSchema(schema: ZodAny | undefined, options?: IntrospectSchemaOptions): SerializableSchema | undefined;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type AnyLeafLowProfile, type FileField } from '@emeryld/rrroutes-contract';
|
|
2
|
+
import { type IntrospectSchemaOptions, type SerializableSchema } from './schemaIntrospection';
|
|
3
|
+
export type ContractLeafSchemas = {
|
|
4
|
+
body?: SerializableSchema;
|
|
5
|
+
query?: SerializableSchema;
|
|
6
|
+
params?: SerializableSchema;
|
|
7
|
+
output?: SerializableSchema;
|
|
8
|
+
outputMeta?: SerializableSchema;
|
|
9
|
+
queryExtension?: SerializableSchema;
|
|
10
|
+
};
|
|
11
|
+
export type SerializedLeafContract = {
|
|
12
|
+
key: string;
|
|
13
|
+
method: AnyLeafLowProfile['method'];
|
|
14
|
+
path: string;
|
|
15
|
+
cfg: {
|
|
16
|
+
description?: string;
|
|
17
|
+
summary?: string;
|
|
18
|
+
docsGroup?: string;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
deprecated?: boolean;
|
|
21
|
+
stability?: 'experimental' | 'beta' | 'stable' | 'deprecated';
|
|
22
|
+
docsHidden?: boolean;
|
|
23
|
+
docsMeta?: Record<string, unknown>;
|
|
24
|
+
feed?: boolean;
|
|
25
|
+
bodyFiles?: FileField[];
|
|
26
|
+
schemas: ContractLeafSchemas;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type SerializeLeafContractOptions = IntrospectSchemaOptions;
|
|
30
|
+
export declare function serializeLeafContract(leaf: AnyLeafLowProfile, options?: SerializeLeafContractOptions): SerializedLeafContract;
|
|
31
|
+
export declare function serializeLeavesContract(leaves: readonly AnyLeafLowProfile[], options?: SerializeLeafContractOptions): SerializedLeafContract[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emeryld/rrroutes-export",
|
|
3
3
|
"description": "Finalized leaves export helpers and CLI for RRRoutes",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.cjs",
|
|
@@ -36,8 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"clean": "rimraf dist && rimraf node_modules",
|
|
39
|
-
"build": "pnpm run clean && pnpm install && pnpm run build:js",
|
|
39
|
+
"build": "pnpm run clean && pnpm install && pnpm run build:js && pnpm run build:types",
|
|
40
40
|
"build:js": "tsup --config tsup.config.ts",
|
|
41
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
41
42
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
43
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.base.config.js --watchman=false --runInBand",
|
|
43
44
|
"export:finalized-leaves": "TS_NODE_PROJECT=tsconfig.tools.json TS_NODE_TRANSPILE_ONLY=1 node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/export-finalized-leaves.ts"
|