@supalive/codegen 1.22.0 → 1.22.1
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/cli.js +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/{src-DvV5kMq2.js → src-Ckf5xah9.js} +35 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,9 @@ interface SchemaEnumEntry {
|
|
|
130
130
|
field: string;
|
|
131
131
|
/** Canonical Dart enum name, e.g. "PosDeviceStatus". */
|
|
132
132
|
enumName: string;
|
|
133
|
+
/** True when {@link enumName} came from the column's own `.modelName("X")`
|
|
134
|
+
* rather than being derived from table + column. */
|
|
135
|
+
explicit: boolean;
|
|
133
136
|
/** Values in schema (canonical) order. */
|
|
134
137
|
values: string[];
|
|
135
138
|
/** Order-independent value-set signature, for matching. */
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as emit, c as loadSchemaEnums, i as resolveConfig, n as generateToDisk, o as extractClient, r as readEntryConfig, s as SchemaEnumRegistry, t as generate } from "./src-
|
|
1
|
+
import { a as emit, c as loadSchemaEnums, i as resolveConfig, n as generateToDisk, o as extractClient, r as readEntryConfig, s as SchemaEnumRegistry, t as generate } from "./src-Ckf5xah9.js";
|
|
2
2
|
export { SchemaEnumRegistry, emit, extractClient, generate, generateToDisk, loadSchemaEnums, readEntryConfig, resolveConfig };
|
|
@@ -532,6 +532,7 @@ var SchemaEnumRegistry = class SchemaEnumRegistry {
|
|
|
532
532
|
const matches = candidates.filter((c) => c.setSig === sig);
|
|
533
533
|
if (matches.length === 0) return void 0;
|
|
534
534
|
if (matches.length === 1) return matches[0];
|
|
535
|
+
if (matches.every((m) => m.enumName === matches[0].enumName)) return matches[0];
|
|
535
536
|
const pick = (test) => {
|
|
536
537
|
let best;
|
|
537
538
|
for (const m of matches) if (test(m.tableStem) && (!best || m.tableStem.length > best.tableStem.length)) best = m;
|
|
@@ -549,11 +550,13 @@ var SchemaEnumRegistry = class SchemaEnumRegistry {
|
|
|
549
550
|
for (const [fieldKey, zodType] of Object.entries(shape)) {
|
|
550
551
|
const values = readEnumValues(zodType);
|
|
551
552
|
if (!values || values.length === 0) continue;
|
|
553
|
+
const explicit = readGenType(zodType);
|
|
552
554
|
entries.push({
|
|
553
555
|
table,
|
|
554
556
|
tableStem,
|
|
555
557
|
field: camel(fieldKey),
|
|
556
|
-
enumName: tableStem + pascal(fieldKey),
|
|
558
|
+
enumName: explicit ?? tableStem + pascal(fieldKey),
|
|
559
|
+
explicit: explicit !== void 0,
|
|
557
560
|
values,
|
|
558
561
|
setSig: setSignature(values)
|
|
559
562
|
});
|
|
@@ -583,6 +586,32 @@ function readEnumValues(field) {
|
|
|
583
586
|
const entries = def?.entries ?? def?.values;
|
|
584
587
|
if (entries && typeof entries === "object") return Object.values(entries).map((v) => String(v));
|
|
585
588
|
}
|
|
589
|
+
/** Read an explicit `.modelName("X")` (i.e. `.meta({ __genType: "X" })`) off a
|
|
590
|
+
* column, looking through the same optional/nullable/default wrappers as
|
|
591
|
+
* {@link readEnumValues} and taking the outermost name so a wrapper can override
|
|
592
|
+
* the shared base type. Realm-independent: we invoke the schema's OWN `.meta()`,
|
|
593
|
+
* which reads the registry belonging to whichever Zod copy built it. */
|
|
594
|
+
function readGenType(field) {
|
|
595
|
+
let cur = field;
|
|
596
|
+
for (let guard = 0; cur && guard < 12; guard++) {
|
|
597
|
+
const name = genTypeOf(cur);
|
|
598
|
+
if (name) return name;
|
|
599
|
+
const def = zodDef(cur);
|
|
600
|
+
if (def?.type && WRAPPERS.has(def.type) && def.innerType) {
|
|
601
|
+
cur = def.innerType;
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function genTypeOf(node) {
|
|
608
|
+
try {
|
|
609
|
+
const name = (node.meta?.())?.__genType;
|
|
610
|
+
return typeof name === "string" && name.length > 0 ? name : void 0;
|
|
611
|
+
} catch {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
586
615
|
function zodDef(node) {
|
|
587
616
|
const n = node;
|
|
588
617
|
return n?._zod?.def ?? n?.def;
|
|
@@ -642,6 +671,8 @@ async function loadSchemaEnums(config) {
|
|
|
642
671
|
}
|
|
643
672
|
//#endregion
|
|
644
673
|
//#region src/extract.ts
|
|
674
|
+
/** Do two enums carry the same constants, order aside? */
|
|
675
|
+
const sameValueSet = (a, b) => a.length === b.length && [...a].sort().join("\0") === [...b].sort().join("\0");
|
|
645
676
|
/** Load the router from the entry file and extract a ClientIR. */
|
|
646
677
|
function extractClient(config, schemaEnums = SchemaEnumRegistry.empty()) {
|
|
647
678
|
const project = new Project({
|
|
@@ -976,6 +1007,7 @@ var Extractor = class {
|
|
|
976
1007
|
type,
|
|
977
1008
|
values: hit.values,
|
|
978
1009
|
schemaName: hit.enumName,
|
|
1010
|
+
customName: hit.explicit ? hit.enumName : void 0,
|
|
979
1011
|
stem: ctx.stem,
|
|
980
1012
|
field: ctx.field,
|
|
981
1013
|
hint: ctx.hint
|
|
@@ -1012,14 +1044,14 @@ var Extractor = class {
|
|
|
1012
1044
|
const namedOwners = /* @__PURE__ */ new Map();
|
|
1013
1045
|
const assignNamed = (g, name) => {
|
|
1014
1046
|
const owner = namedOwners.get(name);
|
|
1015
|
-
if (owner) {
|
|
1047
|
+
if (owner && sameValueSet(owner.values, g.values)) {
|
|
1016
1048
|
g.type.name = owner.type.name;
|
|
1017
1049
|
return;
|
|
1018
1050
|
}
|
|
1019
1051
|
const finalName = used.has(name) ? this.ensureUnique(name, used) : name;
|
|
1020
1052
|
used.add(finalName);
|
|
1021
1053
|
g.type.name = finalName;
|
|
1022
|
-
namedOwners.set(name, g);
|
|
1054
|
+
if (!owner) namedOwners.set(name, g);
|
|
1023
1055
|
this.pushEnumIR(finalName, g.values);
|
|
1024
1056
|
};
|
|
1025
1057
|
const customGroups = groups.filter((g) => g.customName).sort((a, b) => a.customName.localeCompare(b.customName));
|
|
@@ -1033,7 +1065,6 @@ var Extractor = class {
|
|
|
1033
1065
|
if (!arr.some((x) => x.type.name === g.type.name)) arr.push(g);
|
|
1034
1066
|
namedByField.set(g.field, arr);
|
|
1035
1067
|
}
|
|
1036
|
-
const sameValueSet = (a, b) => a.length === b.length && [...a].sort().join("\0") === [...b].sort().join("\0");
|
|
1037
1068
|
const fallbackGroups = groups.filter((g) => !g.schemaName && !g.customName).sort((a, b) => fallbackBase(a).localeCompare(fallbackBase(b)));
|
|
1038
1069
|
const baseCount = /* @__PURE__ */ new Map();
|
|
1039
1070
|
for (const g of fallbackGroups) {
|