@formspec/build 0.1.0-alpha.52 → 0.1.0-alpha.53
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/analyzer/tsdoc-parser.d.ts.map +1 -1
- package/dist/browser.cjs +17 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +8 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +19 -0
- package/dist/browser.js.map +1 -1
- package/dist/build-alpha.d.ts +21 -0
- package/dist/build-beta.d.ts +21 -0
- package/dist/build-internal.d.ts +21 -0
- package/dist/build.d.ts +21 -0
- package/dist/cli/logger.d.ts +22 -0
- package/dist/cli/logger.d.ts.map +1 -0
- package/dist/cli.cjs +123 -21
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +119 -20
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +88 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -20
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +63 -17
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.js +63 -17
- package/dist/internals.js.map +1 -1
- package/dist/json-schema/generator.d.ts +6 -1
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +6 -1
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/package.json +11 -5
package/dist/build-alpha.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { ExtensionDefinition } from '@formspec/core';
|
|
|
40
40
|
import { FormElement } from '@formspec/core';
|
|
41
41
|
import { FormSpec } from '@formspec/core';
|
|
42
42
|
import { Group } from '@formspec/core';
|
|
43
|
+
import type { LoggerLike } from '@formspec/core';
|
|
43
44
|
import type { MetadataPolicyInput } from '@formspec/core';
|
|
44
45
|
import { NumberField } from '@formspec/core';
|
|
45
46
|
import { ObjectField } from '@formspec/core';
|
|
@@ -95,6 +96,11 @@ export declare function buildFormSchemas<E extends readonly FormElement[]>(form:
|
|
|
95
96
|
* @public
|
|
96
97
|
*/
|
|
97
98
|
export declare interface BuildFormSchemasOptions extends GenerateJsonSchemaOptions, GenerateUiSchemaOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
101
|
+
* existing callers produce no output.
|
|
102
|
+
*/
|
|
103
|
+
readonly logger?: LoggerLike | undefined;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
@@ -1008,6 +1014,11 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1008
1014
|
readonly enumSerialization?: "enum" | "oneOf";
|
|
1009
1015
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1010
1016
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
|
+
/**
|
|
1018
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1019
|
+
* existing callers produce no output.
|
|
1020
|
+
*/
|
|
1021
|
+
readonly logger?: LoggerLike | undefined;
|
|
1011
1022
|
}
|
|
1012
1023
|
|
|
1013
1024
|
/**
|
|
@@ -1390,6 +1401,11 @@ export declare function generateUiSchema<E extends readonly FormElement[]>(form:
|
|
|
1390
1401
|
export declare interface GenerateUiSchemaOptions {
|
|
1391
1402
|
/** Metadata resolution policy for chain DSL UI generation. */
|
|
1392
1403
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1404
|
+
/**
|
|
1405
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1406
|
+
* existing callers produce no output.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly logger?: LoggerLike | undefined;
|
|
1393
1409
|
}
|
|
1394
1410
|
|
|
1395
1411
|
export { Group }
|
|
@@ -2391,6 +2407,11 @@ export declare interface WriteSchemasOptions extends GenerateJsonSchemaOptions {
|
|
|
2391
2407
|
readonly name?: string;
|
|
2392
2408
|
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
2393
2409
|
readonly indent?: number;
|
|
2410
|
+
/**
|
|
2411
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
2412
|
+
* existing callers produce no output.
|
|
2413
|
+
*/
|
|
2414
|
+
readonly logger?: LoggerLike | undefined;
|
|
2394
2415
|
}
|
|
2395
2416
|
|
|
2396
2417
|
/**
|
package/dist/build-beta.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { ExtensionDefinition } from '@formspec/core';
|
|
|
40
40
|
import { FormElement } from '@formspec/core';
|
|
41
41
|
import { FormSpec } from '@formspec/core';
|
|
42
42
|
import { Group } from '@formspec/core';
|
|
43
|
+
import type { LoggerLike } from '@formspec/core';
|
|
43
44
|
import type { MetadataPolicyInput } from '@formspec/core';
|
|
44
45
|
import { NumberField } from '@formspec/core';
|
|
45
46
|
import { ObjectField } from '@formspec/core';
|
|
@@ -95,6 +96,11 @@ export declare function buildFormSchemas<E extends readonly FormElement[]>(form:
|
|
|
95
96
|
* @public
|
|
96
97
|
*/
|
|
97
98
|
export declare interface BuildFormSchemasOptions extends GenerateJsonSchemaOptions, GenerateUiSchemaOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
101
|
+
* existing callers produce no output.
|
|
102
|
+
*/
|
|
103
|
+
readonly logger?: LoggerLike | undefined;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
@@ -1008,6 +1014,11 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1008
1014
|
readonly enumSerialization?: "enum" | "oneOf";
|
|
1009
1015
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1010
1016
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
|
+
/**
|
|
1018
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1019
|
+
* existing callers produce no output.
|
|
1020
|
+
*/
|
|
1021
|
+
readonly logger?: LoggerLike | undefined;
|
|
1011
1022
|
}
|
|
1012
1023
|
|
|
1013
1024
|
/**
|
|
@@ -1390,6 +1401,11 @@ export declare function generateUiSchema<E extends readonly FormElement[]>(form:
|
|
|
1390
1401
|
export declare interface GenerateUiSchemaOptions {
|
|
1391
1402
|
/** Metadata resolution policy for chain DSL UI generation. */
|
|
1392
1403
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1404
|
+
/**
|
|
1405
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1406
|
+
* existing callers produce no output.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly logger?: LoggerLike | undefined;
|
|
1393
1409
|
}
|
|
1394
1410
|
|
|
1395
1411
|
export { Group }
|
|
@@ -2391,6 +2407,11 @@ export declare interface WriteSchemasOptions extends GenerateJsonSchemaOptions {
|
|
|
2391
2407
|
readonly name?: string;
|
|
2392
2408
|
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
2393
2409
|
readonly indent?: number;
|
|
2410
|
+
/**
|
|
2411
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
2412
|
+
* existing callers produce no output.
|
|
2413
|
+
*/
|
|
2414
|
+
readonly logger?: LoggerLike | undefined;
|
|
2394
2415
|
}
|
|
2395
2416
|
|
|
2396
2417
|
/**
|
package/dist/build-internal.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { ExtensionDefinition } from '@formspec/core';
|
|
|
40
40
|
import { FormElement } from '@formspec/core';
|
|
41
41
|
import { FormSpec } from '@formspec/core';
|
|
42
42
|
import { Group } from '@formspec/core';
|
|
43
|
+
import type { LoggerLike } from '@formspec/core';
|
|
43
44
|
import type { MetadataPolicyInput } from '@formspec/core';
|
|
44
45
|
import { NumberField } from '@formspec/core';
|
|
45
46
|
import { ObjectField } from '@formspec/core';
|
|
@@ -95,6 +96,11 @@ export declare function buildFormSchemas<E extends readonly FormElement[]>(form:
|
|
|
95
96
|
* @public
|
|
96
97
|
*/
|
|
97
98
|
export declare interface BuildFormSchemasOptions extends GenerateJsonSchemaOptions, GenerateUiSchemaOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
101
|
+
* existing callers produce no output.
|
|
102
|
+
*/
|
|
103
|
+
readonly logger?: LoggerLike | undefined;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
@@ -1008,6 +1014,11 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1008
1014
|
readonly enumSerialization?: "enum" | "oneOf";
|
|
1009
1015
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1010
1016
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
|
+
/**
|
|
1018
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1019
|
+
* existing callers produce no output.
|
|
1020
|
+
*/
|
|
1021
|
+
readonly logger?: LoggerLike | undefined;
|
|
1011
1022
|
}
|
|
1012
1023
|
|
|
1013
1024
|
/**
|
|
@@ -1390,6 +1401,11 @@ export declare function generateUiSchema<E extends readonly FormElement[]>(form:
|
|
|
1390
1401
|
export declare interface GenerateUiSchemaOptions {
|
|
1391
1402
|
/** Metadata resolution policy for chain DSL UI generation. */
|
|
1392
1403
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1404
|
+
/**
|
|
1405
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1406
|
+
* existing callers produce no output.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly logger?: LoggerLike | undefined;
|
|
1393
1409
|
}
|
|
1394
1410
|
|
|
1395
1411
|
export { Group }
|
|
@@ -2391,6 +2407,11 @@ export declare interface WriteSchemasOptions extends GenerateJsonSchemaOptions {
|
|
|
2391
2407
|
readonly name?: string;
|
|
2392
2408
|
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
2393
2409
|
readonly indent?: number;
|
|
2410
|
+
/**
|
|
2411
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
2412
|
+
* existing callers produce no output.
|
|
2413
|
+
*/
|
|
2414
|
+
readonly logger?: LoggerLike | undefined;
|
|
2394
2415
|
}
|
|
2395
2416
|
|
|
2396
2417
|
/**
|
package/dist/build.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { ExtensionDefinition } from '@formspec/core';
|
|
|
40
40
|
import { FormElement } from '@formspec/core';
|
|
41
41
|
import { FormSpec } from '@formspec/core';
|
|
42
42
|
import { Group } from '@formspec/core';
|
|
43
|
+
import type { LoggerLike } from '@formspec/core';
|
|
43
44
|
import type { MetadataPolicyInput } from '@formspec/core';
|
|
44
45
|
import { NumberField } from '@formspec/core';
|
|
45
46
|
import { ObjectField } from '@formspec/core';
|
|
@@ -95,6 +96,11 @@ export declare function buildFormSchemas<E extends readonly FormElement[]>(form:
|
|
|
95
96
|
* @public
|
|
96
97
|
*/
|
|
97
98
|
export declare interface BuildFormSchemasOptions extends GenerateJsonSchemaOptions, GenerateUiSchemaOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
101
|
+
* existing callers produce no output.
|
|
102
|
+
*/
|
|
103
|
+
readonly logger?: LoggerLike | undefined;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
@@ -1008,6 +1014,11 @@ export declare interface GenerateJsonSchemaOptions {
|
|
|
1008
1014
|
readonly enumSerialization?: "enum" | "oneOf";
|
|
1009
1015
|
/** Metadata resolution policy for chain DSL generation. */
|
|
1010
1016
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1017
|
+
/**
|
|
1018
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1019
|
+
* existing callers produce no output.
|
|
1020
|
+
*/
|
|
1021
|
+
readonly logger?: LoggerLike | undefined;
|
|
1011
1022
|
}
|
|
1012
1023
|
|
|
1013
1024
|
/**
|
|
@@ -1390,6 +1401,11 @@ export declare function generateUiSchema<E extends readonly FormElement[]>(form:
|
|
|
1390
1401
|
export declare interface GenerateUiSchemaOptions {
|
|
1391
1402
|
/** Metadata resolution policy for chain DSL UI generation. */
|
|
1392
1403
|
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1404
|
+
/**
|
|
1405
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
1406
|
+
* existing callers produce no output.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly logger?: LoggerLike | undefined;
|
|
1393
1409
|
}
|
|
1394
1410
|
|
|
1395
1411
|
export { Group }
|
|
@@ -2391,6 +2407,11 @@ export declare interface WriteSchemasOptions extends GenerateJsonSchemaOptions {
|
|
|
2391
2407
|
readonly name?: string;
|
|
2392
2408
|
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
2393
2409
|
readonly indent?: number;
|
|
2410
|
+
/**
|
|
2411
|
+
* Optional logger for diagnostic output. Defaults to a no-op logger so
|
|
2412
|
+
* existing callers produce no output.
|
|
2413
|
+
*/
|
|
2414
|
+
readonly logger?: LoggerLike | undefined;
|
|
2394
2415
|
}
|
|
2395
2416
|
|
|
2396
2417
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pino-based logger factory for the @formspec/build CLI.
|
|
3
|
+
*
|
|
4
|
+
* Reads `process.env.DEBUG` to determine which namespaces are enabled using
|
|
5
|
+
* the shared matcher in `@formspec/core` — same semantics as the `debug` npm
|
|
6
|
+
* package (comma-separated patterns, `*` wildcard, `-` prefix for negation,
|
|
7
|
+
* negations always win).
|
|
8
|
+
*/
|
|
9
|
+
import type { LoggerLike } from "@formspec/core";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a logger for the given namespace.
|
|
12
|
+
*
|
|
13
|
+
* When the namespace is enabled by `DEBUG`, writes structured JSON to stderr
|
|
14
|
+
* (with pino-pretty formatting when stderr is a TTY). Otherwise returns the
|
|
15
|
+
* silent `noopLogger` from `@formspec/core`.
|
|
16
|
+
*
|
|
17
|
+
* pino and pino-pretty are loaded lazily via `require()` so that the CLI
|
|
18
|
+
* pays no load-time cost when logging is disabled, and so the dependencies
|
|
19
|
+
* can be declared as `optionalDependencies` of `@formspec/build`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createLogger(namespace: string): LoggerLike;
|
|
22
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/cli/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAwB1D"}
|
package/dist/cli.cjs
CHANGED
|
@@ -1742,19 +1742,25 @@ var init_ir_generator = __esm({
|
|
|
1742
1742
|
|
|
1743
1743
|
// src/json-schema/generator.ts
|
|
1744
1744
|
function generateJsonSchema(form, options) {
|
|
1745
|
+
const logger = (options?.logger ?? import_core2.noopLogger).child({ stage: "ir" });
|
|
1745
1746
|
const metadata = options?.metadata;
|
|
1746
1747
|
const vendorPrefix = options?.vendorPrefix;
|
|
1747
1748
|
const enumSerialization = options?.enumSerialization;
|
|
1749
|
+
logger.debug("canonicalizing chain DSL to IR");
|
|
1748
1750
|
const ir = canonicalizeChainDSL(form, metadata !== void 0 ? { metadata } : void 0);
|
|
1751
|
+
const schemaLogger = (options?.logger ?? import_core2.noopLogger).child({ stage: "schema" });
|
|
1752
|
+
schemaLogger.debug("generating JSON Schema from IR");
|
|
1749
1753
|
const internalOptions = vendorPrefix === void 0 && enumSerialization === void 0 ? void 0 : {
|
|
1750
1754
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
1751
1755
|
...enumSerialization !== void 0 && { enumSerialization }
|
|
1752
1756
|
};
|
|
1753
1757
|
return generateJsonSchemaFromIR(ir, internalOptions);
|
|
1754
1758
|
}
|
|
1759
|
+
var import_core2;
|
|
1755
1760
|
var init_generator = __esm({
|
|
1756
1761
|
"src/json-schema/generator.ts"() {
|
|
1757
1762
|
"use strict";
|
|
1763
|
+
import_core2 = require("@formspec/core");
|
|
1758
1764
|
init_canonicalize();
|
|
1759
1765
|
init_ir_generator();
|
|
1760
1766
|
}
|
|
@@ -2034,15 +2040,21 @@ var init_ir_generator2 = __esm({
|
|
|
2034
2040
|
|
|
2035
2041
|
// src/ui-schema/generator.ts
|
|
2036
2042
|
function generateUiSchema(form, options) {
|
|
2043
|
+
const logger = (options?.logger ?? import_core3.noopLogger).child({ stage: "ir" });
|
|
2044
|
+
logger.debug("canonicalizing chain DSL to IR for UI Schema generation");
|
|
2037
2045
|
const ir = canonicalizeChainDSL(
|
|
2038
2046
|
form,
|
|
2039
2047
|
options?.metadata !== void 0 ? { metadata: options.metadata } : void 0
|
|
2040
2048
|
);
|
|
2049
|
+
const schemaLogger = (options?.logger ?? import_core3.noopLogger).child({ stage: "schema" });
|
|
2050
|
+
schemaLogger.debug("generating UI Schema from IR");
|
|
2041
2051
|
return generateUiSchemaFromIR(ir);
|
|
2042
2052
|
}
|
|
2053
|
+
var import_core3;
|
|
2043
2054
|
var init_generator2 = __esm({
|
|
2044
2055
|
"src/ui-schema/generator.ts"() {
|
|
2045
2056
|
"use strict";
|
|
2057
|
+
import_core3 = require("@formspec/core");
|
|
2046
2058
|
init_canonicalize();
|
|
2047
2059
|
init_ir_generator2();
|
|
2048
2060
|
}
|
|
@@ -2490,39 +2502,85 @@ function isNonReferenceIdentifier(node) {
|
|
|
2490
2502
|
}
|
|
2491
2503
|
return false;
|
|
2492
2504
|
}
|
|
2493
|
-
function
|
|
2505
|
+
function astReferencesImportedName(root, importedNames) {
|
|
2494
2506
|
if (importedNames.size === 0) {
|
|
2495
2507
|
return false;
|
|
2496
2508
|
}
|
|
2497
|
-
let
|
|
2509
|
+
let found = false;
|
|
2498
2510
|
const visit = (node) => {
|
|
2499
|
-
if (
|
|
2500
|
-
return;
|
|
2501
|
-
}
|
|
2511
|
+
if (found) return;
|
|
2502
2512
|
if (ts4.isIdentifier(node) && importedNames.has(node.text) && !isNonReferenceIdentifier(node)) {
|
|
2503
|
-
|
|
2513
|
+
found = true;
|
|
2504
2514
|
return;
|
|
2505
2515
|
}
|
|
2506
2516
|
ts4.forEachChild(node, visit);
|
|
2507
2517
|
};
|
|
2508
|
-
visit(
|
|
2509
|
-
return
|
|
2518
|
+
visit(root);
|
|
2519
|
+
return found;
|
|
2520
|
+
}
|
|
2521
|
+
function getObjectMembers(statement) {
|
|
2522
|
+
if (ts4.isInterfaceDeclaration(statement)) {
|
|
2523
|
+
return statement.members;
|
|
2524
|
+
}
|
|
2525
|
+
if (ts4.isTypeLiteralNode(statement.type)) {
|
|
2526
|
+
return statement.type.members;
|
|
2527
|
+
}
|
|
2528
|
+
return void 0;
|
|
2529
|
+
}
|
|
2530
|
+
function rewriteImportedMemberTypes(statement, sourceFile, importedNames) {
|
|
2531
|
+
const members = getObjectMembers(statement);
|
|
2532
|
+
if (members === void 0) {
|
|
2533
|
+
return null;
|
|
2534
|
+
}
|
|
2535
|
+
const replacements = [];
|
|
2536
|
+
for (const member of members) {
|
|
2537
|
+
if (!ts4.isPropertySignature(member)) {
|
|
2538
|
+
if (astReferencesImportedName(member, importedNames)) {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
continue;
|
|
2542
|
+
}
|
|
2543
|
+
const typeAnnotation = member.type;
|
|
2544
|
+
if (typeAnnotation === void 0) continue;
|
|
2545
|
+
if (astReferencesImportedName(typeAnnotation, importedNames)) {
|
|
2546
|
+
replacements.push({
|
|
2547
|
+
start: typeAnnotation.getStart(sourceFile),
|
|
2548
|
+
end: typeAnnotation.getEnd()
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
if (replacements.length === 0) {
|
|
2553
|
+
return statement.getText(sourceFile);
|
|
2554
|
+
}
|
|
2555
|
+
const stmtStart = statement.getStart(sourceFile);
|
|
2556
|
+
let result = statement.getText(sourceFile);
|
|
2557
|
+
for (const { start, end } of [...replacements].reverse()) {
|
|
2558
|
+
result = result.slice(0, start - stmtStart) + "unknown" + result.slice(end - stmtStart);
|
|
2559
|
+
}
|
|
2560
|
+
return result;
|
|
2510
2561
|
}
|
|
2511
2562
|
function buildSupportingDeclarations(sourceFile, extensionTypeNames) {
|
|
2512
2563
|
const importedNames = collectImportedNames(sourceFile);
|
|
2513
2564
|
const importedNamesToSkip = new Set(
|
|
2514
2565
|
[...importedNames].filter((name) => !extensionTypeNames.has(name))
|
|
2515
2566
|
);
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
if (ts4.
|
|
2519
|
-
if (ts4.
|
|
2520
|
-
|
|
2521
|
-
if (
|
|
2522
|
-
|
|
2567
|
+
const result = [];
|
|
2568
|
+
for (const statement of sourceFile.statements) {
|
|
2569
|
+
if (ts4.isImportDeclaration(statement)) continue;
|
|
2570
|
+
if (ts4.isImportEqualsDeclaration(statement)) continue;
|
|
2571
|
+
if (ts4.isExportDeclaration(statement) && statement.moduleSpecifier !== void 0) continue;
|
|
2572
|
+
if (!astReferencesImportedName(statement, importedNamesToSkip)) {
|
|
2573
|
+
result.push(statement.getText(sourceFile));
|
|
2574
|
+
continue;
|
|
2523
2575
|
}
|
|
2524
|
-
|
|
2525
|
-
|
|
2576
|
+
if (ts4.isInterfaceDeclaration(statement) || ts4.isTypeAliasDeclaration(statement)) {
|
|
2577
|
+
const rewritten = rewriteImportedMemberTypes(statement, sourceFile, importedNamesToSkip);
|
|
2578
|
+
if (rewritten !== null) {
|
|
2579
|
+
result.push(rewritten);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
return result;
|
|
2526
2584
|
}
|
|
2527
2585
|
function pushUniqueCompilerDiagnostics(target, additions) {
|
|
2528
2586
|
for (const diagnostic of additions) {
|
|
@@ -6933,6 +6991,8 @@ __export(index_exports, {
|
|
|
6933
6991
|
writeSchemas: () => writeSchemas
|
|
6934
6992
|
});
|
|
6935
6993
|
function buildFormSchemas(form, options) {
|
|
6994
|
+
const logger = options?.logger ?? import_core4.noopLogger;
|
|
6995
|
+
logger.debug("buildFormSchemas: starting schema generation");
|
|
6936
6996
|
return {
|
|
6937
6997
|
jsonSchema: generateJsonSchema(form, options),
|
|
6938
6998
|
uiSchema: generateUiSchema(form, options)
|
|
@@ -6945,12 +7005,15 @@ function writeSchemas(form, options) {
|
|
|
6945
7005
|
indent = 2,
|
|
6946
7006
|
vendorPrefix,
|
|
6947
7007
|
enumSerialization,
|
|
6948
|
-
metadata
|
|
7008
|
+
metadata,
|
|
7009
|
+
logger: rawLogger
|
|
6949
7010
|
} = options;
|
|
6950
|
-
const
|
|
7011
|
+
const logger = (rawLogger ?? import_core4.noopLogger).child({ stage: "write" });
|
|
7012
|
+
const buildOptions = vendorPrefix === void 0 && enumSerialization === void 0 && metadata === void 0 ? { logger: rawLogger } : {
|
|
6951
7013
|
...vendorPrefix !== void 0 && { vendorPrefix },
|
|
6952
7014
|
...enumSerialization !== void 0 && { enumSerialization },
|
|
6953
|
-
...metadata !== void 0 && { metadata }
|
|
7015
|
+
...metadata !== void 0 && { metadata },
|
|
7016
|
+
logger: rawLogger
|
|
6954
7017
|
};
|
|
6955
7018
|
const { jsonSchema, uiSchema: uiSchema2 } = buildFormSchemas(form, buildOptions);
|
|
6956
7019
|
if (!fs.existsSync(outDir)) {
|
|
@@ -6958,14 +7021,17 @@ function writeSchemas(form, options) {
|
|
|
6958
7021
|
}
|
|
6959
7022
|
const jsonSchemaPath = path3.join(outDir, `${name}-schema.json`);
|
|
6960
7023
|
const uiSchemaPath = path3.join(outDir, `${name}-uischema.json`);
|
|
7024
|
+
logger.debug("writing JSON Schema", { path: jsonSchemaPath });
|
|
6961
7025
|
fs.writeFileSync(jsonSchemaPath, JSON.stringify(jsonSchema, null, indent));
|
|
7026
|
+
logger.debug("writing UI Schema", { path: uiSchemaPath });
|
|
6962
7027
|
fs.writeFileSync(uiSchemaPath, JSON.stringify(uiSchema2, null, indent));
|
|
6963
7028
|
return { jsonSchemaPath, uiSchemaPath };
|
|
6964
7029
|
}
|
|
6965
|
-
var fs, path3;
|
|
7030
|
+
var import_core4, fs, path3;
|
|
6966
7031
|
var init_index = __esm({
|
|
6967
7032
|
"src/index.ts"() {
|
|
6968
7033
|
"use strict";
|
|
7034
|
+
import_core4 = require("@formspec/core");
|
|
6969
7035
|
init_generator();
|
|
6970
7036
|
init_generator2();
|
|
6971
7037
|
init_ir_generator();
|
|
@@ -6989,6 +7055,34 @@ var init_index = __esm({
|
|
|
6989
7055
|
// src/cli.ts
|
|
6990
7056
|
var path4 = __toESM(require("path"), 1);
|
|
6991
7057
|
var import_node_url = require("url");
|
|
7058
|
+
|
|
7059
|
+
// src/cli/logger.ts
|
|
7060
|
+
var import_node_module = require("module");
|
|
7061
|
+
var import_core = require("@formspec/core");
|
|
7062
|
+
var import_meta = {};
|
|
7063
|
+
var require2 = (0, import_node_module.createRequire)(import_meta.url);
|
|
7064
|
+
function createLogger(namespace) {
|
|
7065
|
+
const debugEnv = process.env["DEBUG"] ?? "";
|
|
7066
|
+
if (!(0, import_core.isNamespaceEnabled)(debugEnv, namespace)) {
|
|
7067
|
+
return import_core.noopLogger;
|
|
7068
|
+
}
|
|
7069
|
+
const pinoModule = require2("pino");
|
|
7070
|
+
const pino = typeof pinoModule === "function" ? pinoModule : pinoModule.default;
|
|
7071
|
+
const isTTY = process.stderr.isTTY;
|
|
7072
|
+
if (isTTY) {
|
|
7073
|
+
const pinoPretty = require2("pino-pretty");
|
|
7074
|
+
const prettyTransport = pinoPretty.default ?? pinoPretty;
|
|
7075
|
+
const stream = prettyTransport({ destination: 2, colorize: true, sync: true });
|
|
7076
|
+
return pino({ name: namespace, level: "debug" }, stream);
|
|
7077
|
+
}
|
|
7078
|
+
return pino(
|
|
7079
|
+
{ name: namespace, level: "debug" },
|
|
7080
|
+
pino.destination({ dest: 2, sync: true })
|
|
7081
|
+
);
|
|
7082
|
+
}
|
|
7083
|
+
|
|
7084
|
+
// src/cli.ts
|
|
7085
|
+
var log = createLogger("formspec:build");
|
|
6992
7086
|
function printHelp() {
|
|
6993
7087
|
console.log(`
|
|
6994
7088
|
FormSpec Build CLI - Generate JSON Schema and UI Schema
|
|
@@ -7078,6 +7172,7 @@ function parseArgs(args) {
|
|
|
7078
7172
|
if (!name) {
|
|
7079
7173
|
name = path4.basename(inputFile, path4.extname(inputFile));
|
|
7080
7174
|
}
|
|
7175
|
+
log.debug("Arguments parsed", { inputFile, outDir, name, enumSerialization });
|
|
7081
7176
|
return { inputFile, outDir, name, enumSerialization };
|
|
7082
7177
|
}
|
|
7083
7178
|
async function main() {
|
|
@@ -7088,11 +7183,14 @@ async function main() {
|
|
|
7088
7183
|
}
|
|
7089
7184
|
const { inputFile, outDir, name, enumSerialization } = options;
|
|
7090
7185
|
const absoluteInput = path4.resolve(process.cwd(), inputFile);
|
|
7186
|
+
log.debug("Resolved input file", { absoluteInput });
|
|
7091
7187
|
try {
|
|
7092
7188
|
const fileUrl = (0, import_node_url.pathToFileURL)(absoluteInput).href;
|
|
7189
|
+
log.debug("Loading form module", { fileUrl });
|
|
7093
7190
|
const module2 = await import(fileUrl);
|
|
7094
7191
|
const form = module2["default"] ?? module2["form"];
|
|
7095
7192
|
if (!form || typeof form !== "object" || !("elements" in form)) {
|
|
7193
|
+
log.error("Input file does not export a valid FormSpec", { fileUrl });
|
|
7096
7194
|
console.error("Error: Input file must export a FormSpec as default export or as 'form'");
|
|
7097
7195
|
console.error("Example:");
|
|
7098
7196
|
console.error(' export default formspec(field.text("name"));');
|
|
@@ -7100,18 +7198,22 @@ async function main() {
|
|
|
7100
7198
|
console.error(' export const form = formspec(field.text("name"));');
|
|
7101
7199
|
process.exit(1);
|
|
7102
7200
|
}
|
|
7201
|
+
log.debug("Form module loaded, generating schemas");
|
|
7103
7202
|
const { writeSchemas: writeSchemas2 } = await Promise.resolve().then(() => (init_index(), index_exports));
|
|
7104
7203
|
const { jsonSchemaPath, uiSchemaPath } = writeSchemas2(
|
|
7105
7204
|
form,
|
|
7106
7205
|
{ outDir, name, enumSerialization }
|
|
7107
7206
|
);
|
|
7207
|
+
log.debug("Schemas written", { jsonSchemaPath, uiSchemaPath });
|
|
7108
7208
|
console.log("Generated:");
|
|
7109
7209
|
console.log(` ${jsonSchemaPath}`);
|
|
7110
7210
|
console.log(` ${uiSchemaPath}`);
|
|
7111
7211
|
} catch (error) {
|
|
7112
7212
|
if (error instanceof Error) {
|
|
7213
|
+
log.child({ err: error.message }).error("Schema generation failed");
|
|
7113
7214
|
console.error(`Error: ${error.message}`);
|
|
7114
7215
|
} else {
|
|
7216
|
+
log.error("Schema generation failed with unknown error");
|
|
7115
7217
|
console.error("Error:", error);
|
|
7116
7218
|
}
|
|
7117
7219
|
process.exit(1);
|