@apso/cli 0.47.6 → 0.48.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.
Files changed (74) hide show
  1. package/dist/commands/generate.js +6 -0
  2. package/dist/lib/ddl/change.js +2 -0
  3. package/dist/lib/ddl/index.d.ts +11 -1
  4. package/dist/lib/ddl/index.js +30 -16
  5. package/dist/lib/ddl/sync.d.ts +25 -0
  6. package/dist/lib/ddl/sync.js +78 -0
  7. package/dist/lib/generators/go.d.ts +12 -6
  8. package/dist/lib/generators/go.js +223 -97
  9. package/dist/lib/generators/python.d.ts +6 -0
  10. package/dist/lib/generators/python.js +234 -23
  11. package/dist/lib/templates/entities/entity-col-array.eta +1 -1
  12. package/dist/lib/templates/go/dto/dto-col-array.eta +2 -2
  13. package/dist/lib/templates/go/dto/dto-col-date.eta +1 -1
  14. package/dist/lib/templates/go/dto/dto-col-decimal.eta +1 -1
  15. package/dist/lib/templates/go/dto/dto-col-enum.eta +1 -1
  16. package/dist/lib/templates/go/dto/dto-col-float.eta +1 -1
  17. package/dist/lib/templates/go/dto/dto-col-integer.eta +3 -3
  18. package/dist/lib/templates/go/dto/dto-col-numeric.eta +1 -1
  19. package/dist/lib/templates/go/dto/dto-col-string.eta +1 -1
  20. package/dist/lib/templates/go/dto/dto-col-text.eta +1 -1
  21. package/dist/lib/templates/go/dto/dto-col-timestamp.eta +1 -1
  22. package/dist/lib/templates/go/dto/dto-col-timestamptz.eta +1 -1
  23. package/dist/lib/templates/go/dto/dto-col-uuid.eta +1 -1
  24. package/dist/lib/templates/go/dto/dto-col-varchar.eta +1 -1
  25. package/dist/lib/templates/go/dto/dto.eta +17 -18
  26. package/dist/lib/templates/go/handlers/handler.eta +2 -0
  27. package/dist/lib/templates/go/index-module.eta +3 -1
  28. package/dist/lib/templates/go/middleware/auth.eta +1 -1
  29. package/dist/lib/templates/go/models/model.eta +22 -19
  30. package/dist/lib/templates/go/models/schema.eta +72 -0
  31. package/dist/lib/templates/go/services/service.eta +49 -21
  32. package/dist/lib/templates/go/utils/query.eta +32 -6
  33. package/dist/lib/templates/python/models/init.eta +24 -0
  34. package/dist/lib/templates/python/models/model.eta +24 -56
  35. package/dist/lib/templates/python/schemas/schema-col-array.eta +1 -1
  36. package/dist/lib/templates/python/schemas/schema.eta +9 -9
  37. package/dist/lib/utils/field.d.ts +12 -0
  38. package/dist/lib/utils/field.js +18 -2
  39. package/npm-shrinkwrap.json +2 -2
  40. package/oclif.manifest.json +1 -1
  41. package/package.json +1 -1
  42. package/dist/lib/templates/go/models/model-col-array.eta +0 -1
  43. package/dist/lib/templates/go/models/model-col-boolean.eta +0 -1
  44. package/dist/lib/templates/go/models/model-col-date.eta +0 -1
  45. package/dist/lib/templates/go/models/model-col-decimal.eta +0 -1
  46. package/dist/lib/templates/go/models/model-col-enum.eta +0 -2
  47. package/dist/lib/templates/go/models/model-col-float.eta +0 -1
  48. package/dist/lib/templates/go/models/model-col-integer.eta +0 -1
  49. package/dist/lib/templates/go/models/model-col-json.eta +0 -1
  50. package/dist/lib/templates/go/models/model-col-jsonb.eta +0 -1
  51. package/dist/lib/templates/go/models/model-col-numeric.eta +0 -1
  52. package/dist/lib/templates/go/models/model-col-string.eta +0 -1
  53. package/dist/lib/templates/go/models/model-col-text.eta +0 -1
  54. package/dist/lib/templates/go/models/model-col-timestamp.eta +0 -1
  55. package/dist/lib/templates/go/models/model-col-timestamptz.eta +0 -1
  56. package/dist/lib/templates/go/models/model-col-uuid.eta +0 -1
  57. package/dist/lib/templates/go/models/model-col-varchar.eta +0 -1
  58. package/dist/lib/templates/python/models/model-col-array.eta +0 -4
  59. package/dist/lib/templates/python/models/model-col-boolean.eta +0 -6
  60. package/dist/lib/templates/python/models/model-col-date.eta +0 -4
  61. package/dist/lib/templates/python/models/model-col-datetime.eta +0 -5
  62. package/dist/lib/templates/python/models/model-col-decimal.eta +0 -4
  63. package/dist/lib/templates/python/models/model-col-enum.eta +0 -16
  64. package/dist/lib/templates/python/models/model-col-float.eta +0 -6
  65. package/dist/lib/templates/python/models/model-col-integer.eta +0 -6
  66. package/dist/lib/templates/python/models/model-col-json.eta +0 -4
  67. package/dist/lib/templates/python/models/model-col-jsonb.eta +0 -4
  68. package/dist/lib/templates/python/models/model-col-numeric.eta +0 -4
  69. package/dist/lib/templates/python/models/model-col-string.eta +0 -6
  70. package/dist/lib/templates/python/models/model-col-text.eta +0 -6
  71. package/dist/lib/templates/python/models/model-col-timestamp.eta +0 -11
  72. package/dist/lib/templates/python/models/model-col-timestamptz.eta +0 -11
  73. package/dist/lib/templates/python/models/model-col-uuid.eta +0 -5
  74. package/dist/lib/templates/python/models/model-col-varchar.eta +0 -6
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateDecimalField = exports.typeExistsInEntity = exports.fieldToEnumType = exports.getFieldForTemplate = exports.getDefaultValueForField = exports.getJsTypeFromFieldType = exports.normalizeFieldType = exports.fieldTypeToColumnType = void 0;
3
+ exports.validateDecimalField = exports.typeExistsInEntity = exports.fieldToEnumType = exports.getFieldForTemplate = exports.getDefaultValueForField = exports.arrayElementType = exports.getJsTypeFromFieldType = exports.normalizeFieldType = exports.fieldTypeToColumnType = void 0;
4
4
  const casing_1 = require("./casing");
5
5
  /**
6
6
  * Canonical mapping from .apsorc field types to Postgres column types.
@@ -83,6 +83,8 @@ const typeToJsType = {
83
83
  array: "string[]",
84
84
  boolean: "boolean",
85
85
  integer: "number",
86
+ int: "number",
87
+ float8: "number",
86
88
  float: "number",
87
89
  real: "number",
88
90
  double: "number",
@@ -128,6 +130,16 @@ const typeToJsType = {
128
130
  };
129
131
  const getJsTypeFromFieldType = (type) => { var _a; return (_a = typeToJsType[type]) !== null && _a !== void 0 ? _a : "string"; };
130
132
  exports.getJsTypeFromFieldType = getJsTypeFromFieldType;
133
+ /**
134
+ * Postgres element type of an "array" field, as the DDL writer reads it.
135
+ * Python read `arrayType` and Go `arrayItemType` before `elementType`; both
136
+ * still work so older schemas generate the same code.
137
+ *
138
+ * @param {Field} field - An "array" field from .apsorc.
139
+ * @returns {string} The element type, "text" when none is set.
140
+ */
141
+ const arrayElementType = (field) => field.elementType || field.arrayType || field.arrayItemType || "text";
142
+ exports.arrayElementType = arrayElementType;
131
143
  const getDefaultValueForField = (field) => {
132
144
  var _a, _b;
133
145
  switch (field.type) {
@@ -167,10 +179,14 @@ const getFieldForTemplate = (fields, entityName) => fields.map((field) => {
167
179
  ...field,
168
180
  // Use normalized type for template lookup
169
181
  type: normalizedType,
182
+ // Resolved here so every template and the DDL writer read one key.
183
+ ...(field.type === "array" && { elementType: (0, exports.arrayElementType)(field) }),
170
184
  default: (0, exports.getDefaultValueForField)(field),
171
185
  dataType: field.type === "enum"
172
186
  ? (0, exports.fieldToEnumType)(field.name, entityName)
173
- : (0, exports.getJsTypeFromFieldType)(field.type),
187
+ : field.type === "array"
188
+ ? `${(0, exports.getJsTypeFromFieldType)((0, exports.arrayElementType)(field))}[]`
189
+ : (0, exports.getJsTypeFromFieldType)(field.type),
174
190
  };
175
191
  });
176
192
  exports.getFieldForTemplate = getFieldForTemplate;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.47.6",
3
+ "version": "0.48.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@apso/cli",
9
- "version": "0.47.6",
9
+ "version": "0.48.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@apso/schema-tools": "^0.2.2",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.47.6",
2
+ "version": "0.48.0",
3
3
  "commands": {
4
4
  "config": {
5
5
  "id": "config",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.47.6",
3
+ "version": "0.48.0",
4
4
  "mcpName": "io.github.apsoai/apso",
5
5
  "description": "Apso CLI",
6
6
  "author": "Apso by Mavric - @mavric",
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> []<%= it.column.arrayItemType || 'string' %> `gorm:"type:<%= it.column.arrayItemType || 'text' %>[];serializer:json<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>bool `gorm:"type:boolean<% if (!it.column.required) { %>;default:null<% } else if (it.column.default !== undefined) { %>;default:<%= it.column.default %><% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `gorm:"type:date<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `gorm:"type:decimal(<%= it.column.precision || 10 %>,<%= it.column.scale || 2 %>)<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1,2 +0,0 @@
1
- <% const enumTypeName = it.column.enumType || (it.column.pascalName + 'Enum'); %>
2
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>enums.<%= enumTypeName %> `gorm:"type:varchar(50)<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `gorm:"type:float<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>int <% if (it.column.primary) { %>`gorm:"primaryKey;autoIncrement" json:"<%= it.column.name %>"`<% } else { %>`gorm:"type:integer<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`<% } %>
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>map[string]interface{} `gorm:"type:json<% if (!it.column.required) { %>;default:null<% } %>;serializer:json" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>map[string]interface{} `gorm:"type:jsonb<% if (!it.column.required) { %>;default:null<% } %>;serializer:json" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `gorm:"type:numeric(<%= it.column.precision || 10 %>,<%= it.column.scale || 2 %>)<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `gorm:"type:varchar(<%= it.column.length || 255 %>)<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `gorm:"type:text<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `gorm:"type:timestamp<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `gorm:"type:timestamptz<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string <% if (it.column.primary) { %>`gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"<%= it.column.name %>"`<% } else { %>`gorm:"type:uuid<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`<% } %>
@@ -1 +0,0 @@
1
- <%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `gorm:"type:varchar(<%= it.column.length || 255 %>)<% if (!it.column.required) { %>;default:null<% } %>" json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
@@ -1,4 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[list]<% } else { %>list<% } %>] = mapped_column(
2
- ARRAY(<%= it.field.arrayType === 'integer' ? 'Integer' : 'String' %>),
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
4
- )
@@ -1,6 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[bool]<% } else { %>bool<% } %>] = mapped_column(
2
- Boolean,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
5
- default=<%= (it.field.default === true || it.field.default === 'true') ? 'True' : 'False' %><% } %>
6
- )
@@ -1,4 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[date]<% } else { %>date<% } %>] = mapped_column(
2
- Date,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
4
- )
@@ -1,5 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[datetime]<% } else { %>datetime<% } %>] = mapped_column(
2
- DateTime,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
4
- default=<%= it.field.default === null ? 'None' : `"${it.field.default}"` %><% } %>
5
- )
@@ -1,4 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[Decimal]<% } else { %>Decimal<% } %>] = mapped_column(
2
- Numeric(precision=<%= it.field.precision || 10 %>, scale=<%= it.field.scale || 2 %>),
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
4
- )
@@ -1,16 +0,0 @@
1
- <%
2
- // Generate the enum type name: EntityName + FieldNamePascal + Enum
3
- const fieldNamePascal = it.field.name.charAt(0).toUpperCase() + it.field.name.slice(1);
4
- const enumTypeName = it.field.enumType || `${it.entityName}${fieldNamePascal}Enum`;
5
- // Generate the PostgreSQL enum type name (snake_case version)
6
- const pgEnumName = (it.entityName + '_' + it.field.name + '_enum').toLowerCase().replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
7
- -%>
8
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[enums.<%= enumTypeName %>]<% } else { %>enums.<%= enumTypeName %><% } %>] = mapped_column(
9
- SAEnum(
10
- enums.<%= enumTypeName %>,
11
- name="<%= pgEnumName %>",
12
- values_callable=lambda x: [e.value for e in x],
13
- create_type=True
14
- ),
15
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
16
- )
@@ -1,6 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[float]<% } else { %>float<% } %>] = mapped_column(
2
- Float,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
5
- default=<%= it.field.default %><% } %>
6
- )
@@ -1,6 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[int]<% } else { %>int<% } %>] = mapped_column(
2
- Integer,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
5
- default=<%= it.field.default %><% } %>
6
- )
@@ -1,4 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[dict]<% } else { %>dict<% } %>] = mapped_column(
2
- JSON,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
4
- )
@@ -1,4 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[dict]<% } else { %>dict<% } %>] = mapped_column(
2
- JSONB,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
4
- )
@@ -1,4 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[Decimal]<% } else { %>Decimal<% } %>] = mapped_column(
2
- Numeric(precision=<%= it.field.precision || 10 %>, scale=<%= it.field.scale || 2 %>),
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %>
4
- )
@@ -1,6 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[str]<% } else { %>str<% } %>] = mapped_column(
2
- String(<%= it.field.length || 255 %>),
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
5
- default="<%= it.field.default %>"<% } %>
6
- )
@@ -1,6 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[str]<% } else { %>str<% } %>] = mapped_column(
2
- Text,
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
5
- default="<%= it.field.default %>"<% } %>
6
- )
@@ -1,11 +0,0 @@
1
- <%
2
- const isCreatedAt = ['createdAt', 'created_at'].includes(it.field.name);
3
- const isUpdatedAt = ['updatedAt', 'updated_at'].includes(it.field.name);
4
- -%>
5
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[datetime]<% } else { %>datetime<% } %>] = mapped_column(
6
- DateTime,
7
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (isCreatedAt) { %>,
8
- server_default=func.now()<% } %><% if (isUpdatedAt) { %>,
9
- server_default=func.now(),
10
- onupdate=func.now()<% } %>
11
- )
@@ -1,11 +0,0 @@
1
- <%
2
- const isCreatedAt = ['createdAt', 'created_at'].includes(it.field.name);
3
- const isUpdatedAt = ['updatedAt', 'updated_at'].includes(it.field.name);
4
- -%>
5
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[datetime]<% } else { %>datetime<% } %>] = mapped_column(
6
- DateTime(timezone=True),
7
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (isCreatedAt) { %>,
8
- server_default=func.now()<% } %><% if (isUpdatedAt) { %>,
9
- server_default=func.now(),
10
- onupdate=func.now()<% } %>
11
- )
@@ -1,5 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[UUID]<% } else { %>UUID<% } %>] = mapped_column(
2
- PGUUID(as_uuid=True),
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %>
5
- )
@@ -1,6 +0,0 @@
1
- <%= it.field.name %>: Mapped[<% if (it.field.nullable !== false) { %>Optional[str]<% } else { %>str<% } %>] = mapped_column(
2
- String(<%= it.field.length || 255 %>),
3
- nullable=<%= it.field.nullable === false ? 'False' : 'True' %><% if (it.field.unique) { %>,
4
- unique=True<% } %><% if (it.field.default !== undefined && it.field.default !== null) { %>,
5
- default="<%= it.field.default %>"<% } %>
6
- )