@apso/cli 0.47.2 → 0.47.3

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.
@@ -99,6 +99,7 @@ const nullableSql = (c) => `${(0, _1.q)(c.name)} ${c.type}${c.default === undefi
99
99
  const changed = (x, y) => !y || x.name !== y.name || x.body !== y.body || x.unique !== y.unique;
100
100
  /** The enum type name in a column type like "public"."contact_status_enum". */
101
101
  const typeOf = (t) => { var _a; return ((_a = t.match(/^"public"\."(.+)"$/)) !== null && _a !== void 0 ? _a : [])[1]; };
102
+ const isArray = (t) => t.endsWith("[]");
102
103
  function changeDdl(before, after, plan) {
103
104
  const renamed = applyRenames(before, after, plan);
104
105
  const was = (0, _1.schemaModel)((0, apsorc_parser_1.parseApsorcV2)(before));
@@ -190,6 +191,9 @@ function changeDdl(before, after, plan) {
190
191
  using = `${(0, _1.q)(c.name)}::text::${c.type}`;
191
192
  else if ((cast === null || cast === void 0 ? void 0 : cast.answer) === "sql")
192
193
  using = `(${cast.sql})`;
194
+ else if (isArray(o.type) !== isArray(c.type))
195
+ // A plain cast between a value and an array fails or garbles the data.
196
+ throw new Error(`${t.name}.${c.name} changes between ${o.type} and ${c.type}; a plain cast can't convert it. Answer "sql" with an expression that builds the new value.`);
193
197
  if (o.default !== undefined)
194
198
  up.push(`${at} DROP DEFAULT`);
195
199
  up.push(`${at} TYPE ${c.type} USING ${using}`);
@@ -107,6 +107,14 @@ function columnSpec(table, f) {
107
107
  case "json-plain":
108
108
  type = "json";
109
109
  break;
110
+ case "array": {
111
+ // entity-col-array.eta: { type: elementType || "text", array: true }, no default.
112
+ const element = f.elementType || "text";
113
+ if (!/^[a-z][\w ]*$/i.test(element))
114
+ throw new Error(`Field ${table}.${f.name} has an invalid elementType "${element}".`);
115
+ type = `${element}[]`;
116
+ break;
117
+ }
110
118
  default:
111
119
  // ponytail: spatial, range and other special templates; add each with a parity case.
112
120
  throw new Error(`The DDL writer does not support field type "${f.type}" yet (${table}.${f.name}).`);
@@ -4,6 +4,7 @@ interface PlanField {
4
4
  values?: string[];
5
5
  nullable?: boolean;
6
6
  default?: string | null;
7
+ elementType?: string;
7
8
  }
8
9
  interface PlanEntity {
9
10
  name: string;
@@ -28,6 +28,8 @@ const STRING_TYPES = new Set(["text", "varchar", "char", "string"]);
28
28
  const sameType = (a, b) => {
29
29
  const ta = (0, field_1.normalizeFieldType)(a.type);
30
30
  const tb = (0, field_1.normalizeFieldType)(b.type);
31
+ if (ta === "array" && tb === "array")
32
+ return (a.elementType || "text") === (b.elementType || "text");
31
33
  return ta === tb || (STRING_TYPES.has(ta) && STRING_TYPES.has(tb));
32
34
  };
33
35
  const fieldsOf = (e) => { var _a; return (_a = e === null || e === void 0 ? void 0 : e.fields) !== null && _a !== void 0 ? _a : []; };
@@ -150,7 +152,10 @@ function planMigration(before, after, previous) {
150
152
  id: `cast:${now.name}.${old.name}`,
151
153
  kind: "cast",
152
154
  subject: `Field ${now.name}.${old.name} changes type from ${old.type} to ${cur.type}`,
153
- options: ["cast", "sql"],
155
+ // No plain cast turns a value into an array or back.
156
+ options: (cur.type === "array") === (old.type === "array")
157
+ ? ["cast", "sql"]
158
+ : ["sql"],
154
159
  });
155
160
  }
156
161
  else if (old.values && cur.values) {
@@ -11,6 +11,8 @@ export interface Field {
11
11
  length?: number;
12
12
  precision?: number;
13
13
  scale?: number;
14
+ /** Postgres element type of an "array" field; text when unset. */
15
+ elementType?: string;
14
16
  is_email?: boolean;
15
17
  }
16
18
  export interface ComputedField extends Field {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.47.2",
3
+ "version": "0.47.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@apso/cli",
9
- "version": "0.47.2",
9
+ "version": "0.47.3",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@apso/schema-tools": "^0.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.47.2",
2
+ "version": "0.47.3",
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.2",
3
+ "version": "0.47.3",
4
4
  "mcpName": "io.github.apsoai/apso",
5
5
  "description": "Apso CLI",
6
6
  "author": "Apso by Mavric - @mavric",