@stonecrop/schema 0.7.0 → 0.7.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/dist/index.d.ts +74 -8
- package/dist/index.js +3 -3
- package/package.json +12 -7
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,10 @@ export declare const ActionDefinition: z.ZodObject<{
|
|
|
33
33
|
args?: Record<string, unknown> | undefined;
|
|
34
34
|
}>;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Action definition type inferred from Zod schema
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
36
40
|
export declare type ActionDefinition = z.infer<typeof ActionDefinition>;
|
|
37
41
|
|
|
38
42
|
/**
|
|
@@ -66,7 +70,9 @@ export declare function camelToSnake(camelCase: string): string;
|
|
|
66
70
|
* @public
|
|
67
71
|
*/
|
|
68
72
|
export declare interface ConversionFieldMeta extends FieldMeta {
|
|
73
|
+
/** Original PostgreSQL type (for debugging/reference) */
|
|
69
74
|
_pgType?: string;
|
|
75
|
+
/** Marks fields that couldn't be automatically mapped */
|
|
70
76
|
_unmapped?: boolean;
|
|
71
77
|
}
|
|
72
78
|
|
|
@@ -94,11 +100,14 @@ export declare interface ConversionOptions {
|
|
|
94
100
|
* @public
|
|
95
101
|
*/
|
|
96
102
|
export declare interface ConvertedDoctype extends Omit<DoctypeMeta, 'fields'> {
|
|
103
|
+
/** Field definitions with optional conversion metadata */
|
|
97
104
|
fields: ConversionFieldMeta[];
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
/**
|
|
101
108
|
* Convert PostgreSQL DDL to Stonecrop doctype schemas
|
|
109
|
+
* @param sql - PostgreSQL DDL statements to convert
|
|
110
|
+
* @param options - Conversion options for controlling output format
|
|
102
111
|
* @public
|
|
103
112
|
*/
|
|
104
113
|
export declare function convertSchema(sql: string, options?: ConversionOptions): ConvertedDoctype[];
|
|
@@ -347,6 +356,10 @@ declare const DoctypeMeta: z.ZodObject<{
|
|
|
347
356
|
parentDoctype?: string | undefined;
|
|
348
357
|
}>;
|
|
349
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Doctype metadata type inferred from Zod schema
|
|
361
|
+
* @public
|
|
362
|
+
*/
|
|
350
363
|
declare type DoctypeMeta = z.infer<typeof DoctypeMeta>;
|
|
351
364
|
export { DoctypeMeta }
|
|
352
365
|
export { DoctypeMeta as DoctypeMetaType }
|
|
@@ -389,8 +402,8 @@ declare const FieldMeta: z.ZodObject<{
|
|
|
389
402
|
* - Link: target doctype slug ("customer")
|
|
390
403
|
* - Doctype: child doctype slug ("sales-order-item")
|
|
391
404
|
* - Select: choices array (["Draft", "Submitted"])
|
|
392
|
-
* - Decimal: { precision, scale }
|
|
393
|
-
* - Code: { language }
|
|
405
|
+
* - Decimal: \{ precision, scale \}
|
|
406
|
+
* - Code: \{ language \}
|
|
394
407
|
*/
|
|
395
408
|
options: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
396
409
|
/** Input mask pattern (e.g., "##/##/####" for dates) */
|
|
@@ -446,6 +459,10 @@ declare const FieldMeta: z.ZodObject<{
|
|
|
446
459
|
mask?: string | undefined;
|
|
447
460
|
}>;
|
|
448
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Field metadata type inferred from Zod schema
|
|
464
|
+
* @public
|
|
465
|
+
*/
|
|
449
466
|
declare type FieldMeta = z.infer<typeof FieldMeta>;
|
|
450
467
|
export { FieldMeta }
|
|
451
468
|
export { FieldMeta as FieldMetaType }
|
|
@@ -456,22 +473,31 @@ export { FieldMeta as FieldMetaType }
|
|
|
456
473
|
* Usage by fieldtype:
|
|
457
474
|
* - Link/Doctype: target doctype slug as string ("customer", "sales-order-item")
|
|
458
475
|
* - Select: array of choices (["Draft", "Submitted", "Cancelled"])
|
|
459
|
-
* - Decimal: config object ({ precision: 10, scale: 2 })
|
|
460
|
-
* - Code: config object ({ language: "python" })
|
|
476
|
+
* - Decimal: config object (\{ precision: 10, scale: 2 \})
|
|
477
|
+
* - Code: config object (\{ language: "python" \})
|
|
461
478
|
*
|
|
462
479
|
* @public
|
|
463
480
|
*/
|
|
464
481
|
declare const FieldOptions: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
465
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Field options type inferred from Zod schema
|
|
485
|
+
* @public
|
|
486
|
+
*/
|
|
466
487
|
declare type FieldOptions = z.infer<typeof FieldOptions>;
|
|
467
488
|
export { FieldOptions }
|
|
468
489
|
export { FieldOptions as FieldOptionsType }
|
|
469
490
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
491
|
+
/**
|
|
492
|
+
* Field template for TYPE_MAP entries
|
|
493
|
+
* @public
|
|
494
|
+
*/
|
|
495
|
+
declare interface FieldTemplate {
|
|
473
496
|
component: string;
|
|
474
497
|
fieldtype: StonecropFieldType;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
declare interface FieldTemplate_2 extends FieldTemplate {
|
|
475
501
|
_unmapped?: boolean;
|
|
476
502
|
}
|
|
477
503
|
|
|
@@ -490,6 +516,10 @@ export declare const FieldValidation: z.ZodObject<{
|
|
|
490
516
|
errorMessage: z.ZodString;
|
|
491
517
|
}, z.ZodTypeAny, "passthrough">>;
|
|
492
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Field validation type inferred from Zod schema
|
|
521
|
+
* @public
|
|
522
|
+
*/
|
|
493
523
|
export declare type FieldValidation = z.infer<typeof FieldValidation>;
|
|
494
524
|
|
|
495
525
|
/**
|
|
@@ -513,6 +543,9 @@ export declare interface MapColumnOptions {
|
|
|
513
543
|
|
|
514
544
|
/**
|
|
515
545
|
* Map a parsed column to a Stonecrop field definition
|
|
546
|
+
* @param column - Parsed PostgreSQL column information
|
|
547
|
+
* @param _tableRegistry - Map of table names to parsed table definitions (for reference resolution)
|
|
548
|
+
* @param options - Mapping options for field naming and metadata
|
|
516
549
|
* @public
|
|
517
550
|
*/
|
|
518
551
|
export declare function mapColumnToField(column: ParsedColumn, _tableRegistry: Map<string, ParsedTable>, options?: MapColumnOptions): ConversionFieldMeta;
|
|
@@ -532,6 +565,7 @@ export declare interface NameConversion {
|
|
|
532
565
|
|
|
533
566
|
/**
|
|
534
567
|
* Normalize raw PostgreSQL type string to canonical PostgresType
|
|
568
|
+
* @param rawType - Raw PostgreSQL type string (e.g., 'character varying', 'int4')
|
|
535
569
|
* @public
|
|
536
570
|
*/
|
|
537
571
|
export declare function normalizeType(rawType: string): PostgresType;
|
|
@@ -541,26 +575,42 @@ export declare function normalizeType(rawType: string): PostgresType;
|
|
|
541
575
|
* @public
|
|
542
576
|
*/
|
|
543
577
|
export declare interface ParsedColumn {
|
|
578
|
+
/** Column name (from SQL definition) */
|
|
544
579
|
name: string;
|
|
580
|
+
/** Raw PostgreSQL data type string */
|
|
545
581
|
dataType: string;
|
|
582
|
+
/** Normalized PostgreSQL type (mapped to standard types) */
|
|
546
583
|
normalizedType: PostgresType;
|
|
584
|
+
/** Whether the column allows NULL values */
|
|
547
585
|
nullable: boolean;
|
|
586
|
+
/** Whether the column is auto-generated (GENERATED ALWAYS) */
|
|
548
587
|
isGenerated: boolean;
|
|
588
|
+
/** Default value expression (if specified) */
|
|
549
589
|
defaultValue?: string;
|
|
590
|
+
/** Number of array dimensions (0 for non-array types) */
|
|
550
591
|
arrayDimensions: number;
|
|
592
|
+
/** Foreign key reference information (if column references another table) */
|
|
551
593
|
reference?: {
|
|
594
|
+
/** Referenced schema name */
|
|
552
595
|
schema?: string;
|
|
596
|
+
/** Referenced table name */
|
|
553
597
|
table: string;
|
|
598
|
+
/** Referenced column name */
|
|
554
599
|
column: string;
|
|
600
|
+
/** Foreign key ON DELETE action */
|
|
555
601
|
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
556
602
|
};
|
|
603
|
+
/** Numeric precision (for NUMERIC/DECIMAL types) */
|
|
557
604
|
precision?: number;
|
|
605
|
+
/** Numeric scale (for NUMERIC/DECIMAL types) */
|
|
558
606
|
scale?: number;
|
|
607
|
+
/** Character/binary length constraint (for VARCHAR, CHAR, BIT types) */
|
|
559
608
|
length?: number;
|
|
560
609
|
}
|
|
561
610
|
|
|
562
611
|
/**
|
|
563
612
|
* Parse PostgreSQL DDL and extract table definitions
|
|
613
|
+
* @param sql - PostgreSQL DDL statements to parse
|
|
564
614
|
* @public
|
|
565
615
|
*/
|
|
566
616
|
export declare function parseDDL(sql: string): ParsedTable[];
|
|
@@ -579,13 +629,17 @@ export declare function parseDoctype(data: unknown): DoctypeMeta;
|
|
|
579
629
|
* @public
|
|
580
630
|
*/
|
|
581
631
|
export declare interface ParsedTable {
|
|
632
|
+
/** Table name (from CREATE TABLE statement) */
|
|
582
633
|
name: string;
|
|
634
|
+
/** Schema name (if specified, defaults to 'public') */
|
|
583
635
|
schema?: string;
|
|
636
|
+
/** Column definitions parsed from the table */
|
|
584
637
|
columns: ParsedColumn[];
|
|
638
|
+
/** Parent table names (for PostgreSQL table inheritance) */
|
|
585
639
|
inherits?: string[];
|
|
586
640
|
/** Table comment from COMMENT ON TABLE statement */
|
|
587
641
|
comment?: string;
|
|
588
|
-
/** Doctype name extracted from comment (if using
|
|
642
|
+
/** Doctype name extracted from comment (if using \@doctype convention) */
|
|
589
643
|
doctypeName?: string;
|
|
590
644
|
}
|
|
591
645
|
|
|
@@ -610,6 +664,10 @@ export declare const PG_TYPE_MAP: Record<PostgresType, FieldTemplate_2>;
|
|
|
610
664
|
*/
|
|
611
665
|
export declare const PostgresType: z.ZodEnum<["text", "varchar", "char", "citext", "smallint", "integer", "bigint", "serial", "bigserial", "smallserial", "numeric", "decimal", "real", "double precision", "money", "boolean", "date", "time", "timetz", "timestamp", "timestamptz", "interval", "int4range", "int8range", "numrange", "daterange", "tsrange", "tstzrange", "bytea", "uuid", "json", "jsonb", "bit", "varbit", "xml", "unit", "cube", "unknown"]>;
|
|
612
666
|
|
|
667
|
+
/**
|
|
668
|
+
* PostgreSQL type enum inferred from Zod schema
|
|
669
|
+
* @public
|
|
670
|
+
*/
|
|
613
671
|
export declare type PostgresType = z.infer<typeof PostgresType>;
|
|
614
672
|
|
|
615
673
|
/**
|
|
@@ -645,6 +703,10 @@ export declare function snakeToLabel(snakeCase: string): string;
|
|
|
645
703
|
*/
|
|
646
704
|
declare const StonecropFieldType: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
|
|
647
705
|
|
|
706
|
+
/**
|
|
707
|
+
* Stonecrop field type enum inferred from Zod schema
|
|
708
|
+
* @public
|
|
709
|
+
*/
|
|
648
710
|
declare type StonecropFieldType = z.infer<typeof StonecropFieldType>;
|
|
649
711
|
export { StonecropFieldType }
|
|
650
712
|
export { StonecropFieldType as StonecropFieldTypeValue }
|
|
@@ -774,6 +836,10 @@ declare const WorkflowMeta: z.ZodObject<{
|
|
|
774
836
|
}> | undefined;
|
|
775
837
|
}>;
|
|
776
838
|
|
|
839
|
+
/**
|
|
840
|
+
* Workflow metadata type inferred from Zod schema
|
|
841
|
+
* @public
|
|
842
|
+
*/
|
|
777
843
|
declare type WorkflowMeta = z.infer<typeof WorkflowMeta>;
|
|
778
844
|
export { WorkflowMeta }
|
|
779
845
|
export { WorkflowMeta as WorkflowMetaType }
|
package/dist/index.js
CHANGED
|
@@ -76,7 +76,7 @@ const he = U.union([
|
|
|
76
76
|
U.array(U.string()),
|
|
77
77
|
// Select choices: ["A", "B", "C"]
|
|
78
78
|
U.record(U.string(), U.unknown())
|
|
79
|
-
// Config: { precision: 10, scale: 2 }
|
|
79
|
+
// Config: \{ precision: 10, scale: 2 \}
|
|
80
80
|
]), xe = U.object({
|
|
81
81
|
/** Error message to display when validation fails */
|
|
82
82
|
errorMessage: U.string()
|
|
@@ -116,8 +116,8 @@ const he = U.union([
|
|
|
116
116
|
* - Link: target doctype slug ("customer")
|
|
117
117
|
* - Doctype: child doctype slug ("sales-order-item")
|
|
118
118
|
* - Select: choices array (["Draft", "Submitted"])
|
|
119
|
-
* - Decimal: { precision, scale }
|
|
120
|
-
* - Code: { language }
|
|
119
|
+
* - Decimal: \{ precision, scale \}
|
|
120
|
+
* - Code: \{ language \}
|
|
121
121
|
*/
|
|
122
122
|
options: he.optional(),
|
|
123
123
|
/** Input mask pattern (e.g., "##/##/####" for dates) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/schema",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,17 +20,22 @@
|
|
|
20
20
|
"zod": "^3.25.76"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
+
"@rushstack/heft": "^1.1.7",
|
|
23
24
|
"@types/node": "^22.19.5",
|
|
24
25
|
"typescript": "^5.9.3",
|
|
25
26
|
"vite": "^7.3.1",
|
|
26
27
|
"vite-plugin-dts": "^4.5.4",
|
|
27
|
-
"vitest": "^4.0.17"
|
|
28
|
+
"vitest": "^4.0.17",
|
|
29
|
+
"stonecrop-rig": "0.7.0"
|
|
28
30
|
},
|
|
29
31
|
"scripts": {
|
|
30
|
-
"_phase:build": "vite build",
|
|
31
|
-
"prepublish": "vite build",
|
|
32
|
-
"build": "vite build",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
32
|
+
"_phase:build": "heft build && vite build && rushx docs",
|
|
33
|
+
"prepublish": "heft build && vite build && rushx docs",
|
|
34
|
+
"build": "heft build && vite build && rushx docs",
|
|
35
|
+
"docs": "bash ../common/scripts/run-docs.sh schema",
|
|
36
|
+
"preview": "vite preview",
|
|
37
|
+
"test": "vitest run --coverage.enabled false",
|
|
38
|
+
"test:watch": "vitest watch",
|
|
39
|
+
"test:ui": "vitest --ui"
|
|
35
40
|
}
|
|
36
41
|
}
|