@everystack/model 0.4.1 → 0.4.2
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/package.json +1 -1
- package/src/model.ts +16 -0
package/package.json
CHANGED
package/src/model.ts
CHANGED
|
@@ -124,6 +124,22 @@ export function defineModel(table: string, def: ModelDefinition): ModelDescripto
|
|
|
124
124
|
throw new Error(`model '${table}': can('execute') is a function ability — declare it on the defineFunction it gates.`);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
// An array field's value default must be a JS array — `.default([])`, not the
|
|
129
|
+
// Postgres array literal `.default("{}")`. The literal is an implementation
|
|
130
|
+
// detail that leaks past the generator into drizzle's typed array `.default()`
|
|
131
|
+
// (which wants `string[] | SQL`) and fails tsc. Reject it at authoring time.
|
|
132
|
+
for (const [name, f] of Object.entries(def.fields)) {
|
|
133
|
+
const spec = f.spec;
|
|
134
|
+
if (spec.isArray && spec.defaultKind === 'value' && spec.default != null && !Array.isArray(spec.default)) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`model '${table}': field '${name}' is an array — its .default() takes a JS array, ` +
|
|
137
|
+
`e.g. .default([]), not ${JSON.stringify(spec.default)}. ` +
|
|
138
|
+
`For a SQL expression default use sql\`\` via .defaultSql().`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
127
143
|
validateTriggersFor('table', table, def.triggers ?? []);
|
|
128
144
|
|
|
129
145
|
return {
|