routesync 1.0.3 → 1.0.5

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
@@ -8451,7 +8451,7 @@ if ($extractModels) {
8451
8451
  foreach ($columns as $col) {
8452
8452
  $parsedColumns[] = [
8453
8453
  'name' => $col['name'],
8454
- 'type' => $col['type_name'],
8454
+ 'type' => $col['type'], // Use 'type' which contains the raw type like enum('a','b') instead of 'type_name'
8455
8455
  'nullable' => $col['nullable']
8456
8456
  ];
8457
8457
  }
@@ -8459,7 +8459,10 @@ if ($extractModels) {
8459
8459
  $result['models'][] = [
8460
8460
  'name' => class_basename($class),
8461
8461
  'table' => $table,
8462
- 'columns' => $parsedColumns
8462
+ 'columns' => $parsedColumns,
8463
+ 'hidden' => $model->getHidden(),
8464
+ 'appends' => $model->getAppends(),
8465
+ 'casts' => $model->getCasts()
8463
8466
  ];
8464
8467
  } catch (\\Exception $e) {}
8465
8468
  }
@@ -8916,12 +8919,23 @@ var ModelGenerator = class {
8916
8919
  lines.push(``);
8917
8920
  for (const model of manifest.models) {
8918
8921
  lines.push(`export interface ${model.name} {`);
8922
+ const hidden = Array.isArray(model.hidden) ? model.hidden : [];
8923
+ const casts = model.casts || {};
8919
8924
  for (const col of model.columns) {
8920
- const tsType = this.mapSqlTypeToTs(col.type);
8925
+ const isHidden2 = hidden.includes(col.name);
8926
+ const isOptional = isHidden2 ? "?" : "";
8927
+ const castType = casts[col.name];
8928
+ let tsType = this.mapSqlTypeToTs(col.type);
8929
+ if (castType) {
8930
+ tsType = this.mapCastToTs(castType, tsType);
8931
+ }
8921
8932
  const nullable = col.nullable ? " | null" : "";
8922
- const isOptional = col.name === "password" || col.name === "remember_token" ? "?" : "";
8923
8933
  lines.push(` ${col.name}${isOptional}: ${tsType}${nullable}`);
8924
8934
  }
8935
+ const appends = Array.isArray(model.appends) ? model.appends : [];
8936
+ for (const append of appends) {
8937
+ lines.push(` ${append}: any // appended attribute`);
8938
+ }
8925
8939
  lines.push(`}`);
8926
8940
  lines.push(``);
8927
8941
  }
@@ -8938,8 +8952,29 @@ var ModelGenerator = class {
8938
8952
  if (type.includes("json")) {
8939
8953
  return "any";
8940
8954
  }
8955
+ const enumMatch = type.match(/^enum\((.*)\)$/);
8956
+ if (enumMatch && enumMatch[1]) {
8957
+ const values = enumMatch[1].split(",").map((v) => v.trim().replace(/^'|'$/g, ""));
8958
+ return values.map((v) => `'${v}'`).join(" | ");
8959
+ }
8941
8960
  return "string";
8942
8961
  }
8962
+ static mapCastToTs(castType, defaultType) {
8963
+ const type = castType.toLowerCase();
8964
+ if (type.includes("int") || type.includes("float") || type.includes("decimal") || type.includes("double")) {
8965
+ return "number";
8966
+ }
8967
+ if (type.includes("bool")) {
8968
+ return "boolean";
8969
+ }
8970
+ if (type.includes("array") || type.includes("json") || type.includes("collection") || type.includes("object")) {
8971
+ return "any";
8972
+ }
8973
+ if (type.includes("date") || type.includes("datetime") || type.includes("string")) {
8974
+ return "string";
8975
+ }
8976
+ return defaultType;
8977
+ }
8943
8978
  };
8944
8979
 
8945
8980
  // packages/cli/src/commands/generate.ts
package/dist/core.d.mts CHANGED
@@ -223,6 +223,9 @@ interface ParsedModel {
223
223
  name: string;
224
224
  table: string;
225
225
  columns: ParsedColumn[];
226
+ hidden?: string[];
227
+ appends?: string[];
228
+ casts?: Record<string, string>;
226
229
  }
227
230
 
228
231
  export { type ApiDefinition, ApiError, type ApiResponse, type AuthConfig, AuthMiddleware, ErrorHandler, HttpClient, type HttpMethod, Interceptor, type PaginationMeta, type ParsedChannel, type ParsedColumn, type ParsedModel, type ParsedRoute, PathResolver, QueryBuilder, Request, type RequestOptions, Response, type RetryConfig, type RouteDefinition, type RouteManifest, type RouteMapper, type RouteParserSchema, type RouteSchema, type RouteSchemaMap, type RouteSchemaValue, type RouteTransform, type RouteTransformMap, type ServiceConfig, TokenManager };
package/dist/core.d.ts CHANGED
@@ -223,6 +223,9 @@ interface ParsedModel {
223
223
  name: string;
224
224
  table: string;
225
225
  columns: ParsedColumn[];
226
+ hidden?: string[];
227
+ appends?: string[];
228
+ casts?: Record<string, string>;
226
229
  }
227
230
 
228
231
  export { type ApiDefinition, ApiError, type ApiResponse, type AuthConfig, AuthMiddleware, ErrorHandler, HttpClient, type HttpMethod, Interceptor, type PaginationMeta, type ParsedChannel, type ParsedColumn, type ParsedModel, type ParsedRoute, PathResolver, QueryBuilder, Request, type RequestOptions, Response, type RetryConfig, type RouteDefinition, type RouteManifest, type RouteMapper, type RouteParserSchema, type RouteSchema, type RouteSchemaMap, type RouteSchemaValue, type RouteTransform, type RouteTransformMap, type ServiceConfig, TokenManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routesync",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Laravel routes to typed frontend SDKs.",
5
5
  "main": "./dist/sdk.js",
6
6
  "module": "./dist/sdk.mjs",