@supalive/codegen 1.4.0 → 1.5.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as generateToDisk, r as readEntryConfig } from "./src-O2U-Keyx.js";
2
+ import { n as generateToDisk, r as readEntryConfig } from "./src-DM44BrYS.js";
3
3
  import path from "node:path";
4
4
  //#region src/cli.ts
5
5
  function parseArgs(argv) {
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-O2U-Keyx.js";
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-DM44BrYS.js";
2
2
  export { SchemaEnumRegistry, emit, extractClient, generate, generateToDisk, loadSchemaEnums, readEntryConfig, resolveConfig };
@@ -714,18 +714,18 @@ var Extractor = class {
714
714
  const propType = prop.getTypeAtLocation(this.locationNode);
715
715
  const declaredOptional = (prop.getFlags() & ts.SymbolFlags.Optional) !== 0;
716
716
  const { core, hasNull, hasUndefined } = splitNullish(propType);
717
- const dt = core.length === 0 ? { kind: "dynamic" } : core.length === 1 ? this.walkSingle(core[0], name + pascal(jsonKey)) : this.walkUnion(core, {
718
- hint: name + pascal(jsonKey),
719
- stem: cleanStem(name),
720
- field: jsonKey
721
- });
722
717
  const acc = fieldMap.get(jsonKey) ?? {
723
718
  types: [],
724
719
  present: 0,
725
720
  nullable: false,
726
721
  optional: false
727
722
  };
728
- acc.types.push(dt);
723
+ if (core.length === 1) acc.types.push(this.walkSingle(core[0], name + pascal(jsonKey)));
724
+ else if (core.length > 1) acc.types.push(this.walkUnion(core, {
725
+ hint: name + pascal(jsonKey),
726
+ stem: cleanStem(name),
727
+ field: jsonKey
728
+ }));
729
729
  acc.present++;
730
730
  if (hasNull) acc.nullable = true;
731
731
  if (declaredOptional || hasUndefined) acc.optional = true;
@@ -733,7 +733,7 @@ var Extractor = class {
733
733
  }
734
734
  const fields = [];
735
735
  for (const [jsonKey, acc] of fieldMap) {
736
- const consistent = acc.types.every((t) => JSON.stringify(t) === JSON.stringify(acc.types[0]));
736
+ const consistent = acc.types.length > 0 && acc.types.every((t) => JSON.stringify(t) === JSON.stringify(acc.types[0]));
737
737
  fields.push({
738
738
  name: camel(jsonKey),
739
739
  jsonKey,
@@ -808,6 +808,7 @@ function uniqueName(symName, registry, _type) {
808
808
  return pascal(symName);
809
809
  }
810
810
  function singular(hint) {
811
+ if (hint.endsWith("Result") && hint.length > 6) return hint.slice(0, -6) + "Item";
811
812
  if (hint.endsWith("ies")) return hint.slice(0, -3) + "y";
812
813
  if (hint.endsWith("s") && !hint.endsWith("ss")) return hint.slice(0, -1);
813
814
  return hint + "Item";
@@ -823,7 +824,8 @@ function cleanStem(modelName) {
823
824
  for (const suffix of [
824
825
  "ResultItem",
825
826
  "Result",
826
- "Args"
827
+ "Args",
828
+ "Item"
827
829
  ]) if (s.length > suffix.length && s.endsWith(suffix)) {
828
830
  s = s.slice(0, -suffix.length);
829
831
  break;
@@ -1044,6 +1046,7 @@ function emitModel(m) {
1044
1046
  return `(identical(other.${f.name}, ${f.name}) || ${cmp})`;
1045
1047
  }).join(" &&\n ");
1046
1048
  const hashParts = m.fields.map((f) => isDeep(f) ? `deepHashCode(${f.name})` : f.name).join(", ");
1049
+ const toStringFields = m.fields.map((f) => `${f.name}: $${f.name}`).join(", ");
1047
1050
  const hashBody = m.fields.length === 0 ? "runtimeType.hashCode" : m.fields.length <= 19 ? `Object.hash(runtimeType, ${hashParts})` : `Object.hashAll([runtimeType, ${hashParts}])`;
1048
1051
  return `${docComment(m.doc, "")}class ${m.name} implements SupaliveModel {
1049
1052
  const ${m.name}(${m.fields.length ? "{\n" + ctorParams + ",\n }" : ""});
@@ -1070,6 +1073,11 @@ ${toJson}
1070
1073
 
1071
1074
  @override
1072
1075
  int get hashCode => ${hashBody};
1076
+
1077
+ @override
1078
+ String toString() {
1079
+ return '${m.name}{${toStringFields}}';
1080
+ }
1073
1081
  }
1074
1082
  `;
1075
1083
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supalive/codegen",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Generate type-safe client code (Dart, and more) from a Supalive TypeScript router.",
5
5
  "author": "Rebaz Raouf",
6
6
  "license": "MIT",