@supalive/codegen 1.7.1 → 1.8.0
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.js +1 -1
- package/dist/{src-BTC1k7HX.js → src-BRGy8CeY.js} +67 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
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-BRGy8CeY.js";
|
|
2
2
|
export { SchemaEnumRegistry, emit, extractClient, generate, generateToDisk, loadSchemaEnums, readEntryConfig, resolveConfig };
|
|
@@ -512,6 +512,31 @@ var Extractor = class {
|
|
|
512
512
|
return;
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* Read an `@type` JSDoc tag from a property and parse it into a DartType.
|
|
517
|
+
*
|
|
518
|
+
* Supported formats:
|
|
519
|
+
* - `/** @type StoreCardItem */` → model with that name
|
|
520
|
+
* - `/** @type List<StoreCardItem> */` → list with model element
|
|
521
|
+
* - `/** @type String */`, `/** @type int */`, etc. → primitive
|
|
522
|
+
*/
|
|
523
|
+
readTypeOverride(prop) {
|
|
524
|
+
try {
|
|
525
|
+
const decls = prop.getDeclarations();
|
|
526
|
+
if (!decls || decls.length === 0) return null;
|
|
527
|
+
const node = decls[0];
|
|
528
|
+
if (!Node.isJSDocable(node)) return null;
|
|
529
|
+
const jsDocs = node.getJsDocs();
|
|
530
|
+
if (jsDocs.length === 0) return null;
|
|
531
|
+
const typeTag = jsDocs[jsDocs.length - 1].getTags().find((t) => t.getTagName() === "type");
|
|
532
|
+
if (!typeTag) return null;
|
|
533
|
+
const raw = typeTag.compilerNode.typeExpression?.getText?.()?.trim();
|
|
534
|
+
if (!raw) return null;
|
|
535
|
+
return parseTypeOverride(raw);
|
|
536
|
+
} catch {
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
515
540
|
models() {
|
|
516
541
|
this.finalizeEnums();
|
|
517
542
|
return [...this.modelRegistry.values()];
|
|
@@ -628,11 +653,15 @@ var Extractor = class {
|
|
|
628
653
|
const { core, hasNull, hasUndefined } = splitNullish(propType);
|
|
629
654
|
const optional = declaredOptional || hasUndefined;
|
|
630
655
|
const nullable = hasNull;
|
|
656
|
+
const typeOverride = this.readTypeOverride(prop);
|
|
631
657
|
let dartType;
|
|
632
|
-
if (
|
|
633
|
-
else if (core.length ===
|
|
634
|
-
else
|
|
635
|
-
|
|
658
|
+
if (typeOverride) dartType = typeOverride;
|
|
659
|
+
else if (core.length === 0) dartType = { kind: "dynamic" };
|
|
660
|
+
else if (core.length === 1) {
|
|
661
|
+
const fieldHint = name.replace(/Result$/, "") + pascal(jsonKey);
|
|
662
|
+
dartType = this.walkSingle(core[0], fieldHint);
|
|
663
|
+
} else dartType = this.walkUnion(core, {
|
|
664
|
+
hint: name.replace(/Result$/, "") + pascal(jsonKey),
|
|
636
665
|
stem: cleanStem(name),
|
|
637
666
|
field: jsonKey
|
|
638
667
|
});
|
|
@@ -916,6 +945,40 @@ function cleanStem(modelName) {
|
|
|
916
945
|
}
|
|
917
946
|
return singularizeWord(s);
|
|
918
947
|
}
|
|
948
|
+
const PRIMITIVE_MAP = {
|
|
949
|
+
string: "string",
|
|
950
|
+
int: "int",
|
|
951
|
+
double: "double",
|
|
952
|
+
bool: "bool",
|
|
953
|
+
bigint: "bigint",
|
|
954
|
+
bytes: "bytes",
|
|
955
|
+
datetime: "datetime",
|
|
956
|
+
dynamic: "dynamic"
|
|
957
|
+
};
|
|
958
|
+
/**
|
|
959
|
+
* Parse an `@type` override value into a DartType.
|
|
960
|
+
*
|
|
961
|
+
* - `"StoreCardItem"` → `{ kind: "model", name: "StoreCardItem" }`
|
|
962
|
+
* - `"List<StoreCardItem>"` → `{ kind: "list", element: { kind: "model", name: "StoreCardItem" } }`
|
|
963
|
+
* - `"String"` → `{ kind: "string" }`
|
|
964
|
+
* - `"int"` → `{ kind: "int" }`
|
|
965
|
+
*/
|
|
966
|
+
function parseTypeOverride(raw) {
|
|
967
|
+
const listMatch = raw.match(/^List<(.+)>$/);
|
|
968
|
+
if (listMatch) {
|
|
969
|
+
const innerType = parseTypeOverride(listMatch[1].trim());
|
|
970
|
+
return innerType ? {
|
|
971
|
+
kind: "list",
|
|
972
|
+
element: innerType
|
|
973
|
+
} : null;
|
|
974
|
+
}
|
|
975
|
+
const prim = PRIMITIVE_MAP[raw.toLowerCase()];
|
|
976
|
+
if (prim) return { kind: prim };
|
|
977
|
+
return {
|
|
978
|
+
kind: "model",
|
|
979
|
+
name: raw
|
|
980
|
+
};
|
|
981
|
+
}
|
|
919
982
|
/** The bare candidate name for a structural (non-schema) enum group. */
|
|
920
983
|
function fallbackBase(g) {
|
|
921
984
|
return pascal(g.field ?? g.hint);
|