hekireki 0.31.0 → 0.32.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.
- package/README.md +37 -97
- package/dist/bin/activerecord.js +1 -1
- package/dist/bin/ajv.js +1 -1
- package/dist/bin/arktype.js +1 -1
- package/dist/bin/atlas.js +1 -1
- package/dist/bin/django.js +1 -1
- package/dist/bin/drizzle.js +1 -1
- package/dist/bin/ecto.js +1 -1
- package/dist/bin/efcore.js +1 -1
- package/dist/bin/effect.js +1 -1
- package/dist/bin/eloquent.js +1 -1
- package/dist/bin/er.js +1 -1
- package/dist/bin/exposed.js +1 -1
- package/dist/bin/gorm.js +1 -1
- package/dist/bin/hekireki.js +2 -2
- package/dist/bin/kysely.js +1 -1
- package/dist/bin/pydantic.js +1 -1
- package/dist/bin/sea-orm.js +1 -1
- package/dist/bin/seed.js +1 -1
- package/dist/bin/sqlalchemy.js +1 -1
- package/dist/bin/typebox.js +1 -1
- package/dist/bin/valibot.js +1 -1
- package/dist/bin/zod.js +1 -1
- package/dist/{bin-CiVKUVYM.js → bin-CmwdzyIR.js} +45 -19
- package/dist/{run-BMAnuiJ1.js → run-DhCGgShc.js} +13 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,60 +56,18 @@ model User {
|
|
|
56
56
|
|
|
57
57
|
### Rails
|
|
58
58
|
|
|
59
|
-
`hekireki-activerecord` writes `app/models`
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
What the model does carry: an `attribute` default for each literal `@default`, for `uuid()`,
|
|
72
|
-
`ulid()`, `cuid()`, `cuid(2)` and `nanoid()` (the `ulid`, `cuid`, `cuid2` and `nanoid` gems) and an
|
|
73
|
-
empty array for a list without one, as the Prisma client reads it; `implicit_order_column` on the
|
|
74
|
-
created timestamp when the primary key is random (`uuid()`, `cuid()`, `nanoid()`); `alias_attribute`
|
|
75
|
-
for a `createdAt` or `@updatedAt` column so Rails fills and bumps it as the Prisma client would;
|
|
76
|
-
`enum` with snake_case keys (`PENDING_REVIEW` gives `record.pending_review?` and the
|
|
77
|
-
`pending_review` scope, the stored value stays the database's), its `default:`, `prefix: true` when a
|
|
78
|
-
key is a method Ruby or Active Record already has, and `validate: true` so a value outside the enum
|
|
79
|
-
is a validation error rather than an `ArgumentError`; `dependent:` on every `has_many` and `has_one`
|
|
80
|
-
as the foreign key's `onDelete` acts (`Cascade` destroys, `SetNull` nullifies, `Restrict` and
|
|
81
|
-
`NoAction` refuse with an error); and validations from the columns: a required column without a
|
|
82
|
-
default is `presence` (`inclusion` in `[ true, false ]` for a `Boolean`, `exclusion` of `nil` for
|
|
83
|
-
`Json` and `Bytes`), `@unique` and `@@unique` are `uniqueness`, `@db.VarChar(n)` is `length`.
|
|
84
|
-
|
|
85
|
-
Validation stays in the model, as Active Record has it. A `/// @ar.` call on a field is one
|
|
86
|
-
validator on one `///` line, written as Rails spells it (`presence`, `length(maximum: 255)`), and
|
|
87
|
-
becomes an option of that field's `validates`, replacing the one the schema implied when it names
|
|
88
|
-
the same validator; a `/// @ar.` line on the model is written into the class as it is. A message
|
|
89
|
-
given per locale, `message: { ja: "...", en: "..." }` or `too_long: { ja: "...", en: "..." }`, is
|
|
90
|
-
not written into the model: it goes to `config/locales/models/todo/<locale>.yml` under the key the
|
|
91
|
-
[Rails i18n guide](https://guides.rubyonrails.org/i18n.html#error-message-scopes) lists for that
|
|
92
|
-
validator (`activerecord.errors.models.todo.attributes.title.blank`). `too_long` is a key already;
|
|
93
|
-
`message` stands for every key the validator can raise: `blank` for `presence`, all three of
|
|
94
|
-
`length`, and for `numericality` and `comparison` the keys of the options given
|
|
95
|
-
(`greater_than: 0` raises `greater_than`), so the one translation covers whichever fails. A locale's
|
|
96
|
-
value may be plural forms, `{ one: "...", other: "%{count} ..." }`, which I18n picks by `count`, and
|
|
97
|
-
`%{count}`, `%{value}`, `%{model}` and `%{attribute}` interpolate as Rails' own messages do.
|
|
98
|
-
`@ar.name(ja: "...", en: "...")` on a field or a model translates its name the same way
|
|
99
|
-
(`activerecord.attributes.todo.title`, `activerecord.models.todo`), plural forms included.
|
|
100
|
-
The files are laid out as the guide's
|
|
101
|
-
[organization of locale files](https://guides.rubyonrails.org/i18n.html#organization-of-locale-files)
|
|
102
|
-
has them, `models/<model>/<locale>.yml`, one directory per model and one file per locale it names,
|
|
103
|
-
so model and attribute names stay apart from the text of the views and from the defaults; Rails
|
|
104
|
-
loads `config/locales` through its subdirectories. `locales` names that directory; from
|
|
105
|
-
`app/models` it is `config/locales`. The comment has one shape: the description first, then the
|
|
106
|
-
`@ar.` calls, one to a `///` line. On a field each is `name` or `name(arguments)` with its
|
|
107
|
-
parentheses closed on that line; on the model each is a Ruby line as the class body would have it
|
|
108
|
-
(`validates :a, :b, presence: true`, `normalizes :title, with: ->(title) { title.strip }`), not
|
|
109
|
-
ending in a comma. A description line after a call, a call that runs on to the next `///` or a
|
|
110
|
-
call of another shape stops `prisma generate` with the model and field it is on. Rails joins attribute and message with a space (`errors.format`), which Japanese does not want: the
|
|
111
|
-
`rails-i18n` gem's `ja.yml` sets it to `%{attribute}%{message}`, and the generated files sit beside
|
|
112
|
-
it. Point `output` at `app/models`, and `todo.rb` is the model, nothing left to edit by hand:
|
|
59
|
+
`hekireki-activerecord` writes `app/models` from the schema: `application_record.rb` and one model
|
|
60
|
+
per Prisma model, as a Rails developer would write them. What Rails works out on its own
|
|
61
|
+
(`table_name`, `class_name`, `foreign_key`, `inverse_of` where the names follow its conventions)
|
|
62
|
+
is left unsaid; what the schema promises is written: `attribute` defaults, `enum`, timestamps,
|
|
63
|
+
associations with `dependent:` from `onDelete`, and validations from the columns (`presence`,
|
|
64
|
+
`uniqueness`, `length`).
|
|
65
|
+
|
|
66
|
+
A `/// @ar.` line on a field is a validator (`presence`, `length(maximum: 255)`) added to that
|
|
67
|
+
field's `validates`; on a model it is a Ruby line written into the class as it is
|
|
68
|
+
(`has_secure_password`, `has_many :tags, through: :post_tags`, `scope ...`). A message or name
|
|
69
|
+
given per locale, `message: { ja: "...", en: "..." }` or `@ar.name(ja: "...")`, goes to
|
|
70
|
+
`config/locales/models/<model>/<locale>.yml` under the key Rails reads.
|
|
113
71
|
|
|
114
72
|
```prisma
|
|
115
73
|
generator Hekireki-ActiveRecord {
|
|
@@ -133,11 +91,6 @@ model Todo {
|
|
|
133
91
|
```
|
|
134
92
|
|
|
135
93
|
```ruby
|
|
136
|
-
# app/models/application_record.rb
|
|
137
|
-
class ApplicationRecord < ActiveRecord::Base
|
|
138
|
-
primary_abstract_class
|
|
139
|
-
end
|
|
140
|
-
|
|
141
94
|
# app/models/todo.rb
|
|
142
95
|
class Todo < ApplicationRecord
|
|
143
96
|
attribute :completed, default: false
|
|
@@ -164,53 +117,40 @@ ja:
|
|
|
164
117
|
too_long: '%{count}文字以内で入力してください'
|
|
165
118
|
```
|
|
166
119
|
|
|
167
|
-
|
|
168
|
-
/
|
|
169
|
-
|
|
170
|
-
|
|
120
|
+
The tables stay Prisma's to create, so set `config.active_record.migration_error = false` and
|
|
121
|
+
create the test database with `prisma migrate deploy`. `examples/active-record` in the repository
|
|
122
|
+
runs a fuller schema against Active Record on SQLite, and is the place to read what each thing
|
|
123
|
+
becomes.
|
|
171
124
|
|
|
172
|
-
|
|
173
|
-
[managing the locale across requests](https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests)
|
|
174
|
-
sets it once per request with `I18n.with_locale`, which puts it back when the action ends rather
|
|
175
|
-
than leaving it on the thread for the next request, and names the locales the application serves:
|
|
125
|
+
## Studio
|
|
176
126
|
|
|
177
|
-
```
|
|
178
|
-
#
|
|
179
|
-
|
|
180
|
-
config.i18n.default_locale = :ja
|
|
181
|
-
|
|
182
|
-
# app/controllers/application_controller.rb
|
|
183
|
-
class ApplicationController < ActionController::Base
|
|
184
|
-
around_action :switch_locale
|
|
185
|
-
|
|
186
|
-
private
|
|
187
|
-
def switch_locale(&action)
|
|
188
|
-
locale = params[:locale] || I18n.default_locale
|
|
189
|
-
I18n.with_locale(locale, &action)
|
|
190
|
-
end
|
|
191
|
-
end
|
|
127
|
+
```bash
|
|
128
|
+
npx hekireki studio # ./prisma/schema.prisma or ./schema.prisma, port 5555
|
|
129
|
+
npx hekireki studio --url file:./dev.db
|
|
192
130
|
```
|
|
193
131
|
|
|
194
|
-
|
|
132
|
+
Your schema and database in the browser, on SQLite, PostgreSQL and MySQL.
|
|
195
133
|
|
|
196
|
-
|
|
197
|
-
# config/application.rb
|
|
198
|
-
config.active_record.migration_error = false
|
|
199
|
-
config.active_record.maintain_test_schema = false
|
|
200
|
-
```
|
|
134
|
+
**Browse the rows** of each model: search, add, edit and export them.
|
|
201
135
|
|
|
202
|
-
|
|
203
|
-
run) rather than `db:test:prepare`.
|
|
136
|
+

|
|
204
137
|
|
|
205
|
-
|
|
138
|
+
**Run SQL** with completion from the schema. The ER diagram marks the tables a statement reads,
|
|
139
|
+
and the result comes with the TypeScript types of its rows.
|
|
206
140
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
141
|
+

|
|
142
|
+
|
|
143
|
+
**Try Prisma Client calls** and see the SQL each one sends.
|
|
144
|
+
|
|
145
|
+

|
|
146
|
+
|
|
147
|
+
**Edit the schema** beside its ER diagram, which follows the file as it changes.
|
|
148
|
+
|
|
149
|
+

|
|
150
|
+
|
|
151
|
+
**Read the docs** of every model: its fields, and an example of each operation.
|
|
211
152
|
|
|
212
|
-
The
|
|
213
|
-
playground, in the browser. SQLite, PostgreSQL and MySQL.
|
|
153
|
+

|
|
214
154
|
|
|
215
155
|
## Seed
|
|
216
156
|
|
package/dist/bin/activerecord.js
CHANGED
package/dist/bin/ajv.js
CHANGED
package/dist/bin/arktype.js
CHANGED
package/dist/bin/atlas.js
CHANGED
package/dist/bin/django.js
CHANGED
package/dist/bin/drizzle.js
CHANGED
package/dist/bin/ecto.js
CHANGED
package/dist/bin/efcore.js
CHANGED
package/dist/bin/effect.js
CHANGED
package/dist/bin/eloquent.js
CHANGED
package/dist/bin/er.js
CHANGED
package/dist/bin/exposed.js
CHANGED
package/dist/bin/gorm.js
CHANGED
package/dist/bin/hekireki.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Console, Data, Effect, Option, Schema, Stdio } from "effect";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { CliError, Command, Flag } from "effect/unstable/cli";
|
|
7
7
|
//#region package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.32.0";
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/studio/server/constants/index.ts
|
|
11
11
|
/** Studio only listens on loopback: the API serves the raw schema and runs SQL without authentication. */
|
|
@@ -128,7 +128,7 @@ const seedFlags = {
|
|
|
128
128
|
};
|
|
129
129
|
function runSeedCommand(args) {
|
|
130
130
|
return Effect.gen(function* () {
|
|
131
|
-
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-
|
|
131
|
+
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-DhCGgShc.js"));
|
|
132
132
|
const report = yield* runSeed({
|
|
133
133
|
config: Option.getOrNull(args.config),
|
|
134
134
|
schema: Option.getOrNull(args.schema),
|
package/dist/bin/kysely.js
CHANGED
package/dist/bin/pydantic.js
CHANGED
package/dist/bin/sea-orm.js
CHANGED
package/dist/bin/seed.js
CHANGED
package/dist/bin/sqlalchemy.js
CHANGED
package/dist/bin/typebox.js
CHANGED
package/dist/bin/valibot.js
CHANGED
package/dist/bin/zod.js
CHANGED
|
@@ -993,7 +993,14 @@ function arCalls(documentation, on) {
|
|
|
993
993
|
* validator. Each names the model or field it is on.
|
|
994
994
|
*/
|
|
995
995
|
function activeRecordProblems(models) {
|
|
996
|
-
return models.flatMap((model) => [...arCalls(model.documentation, "model").problems.map((problem) => `model ${model.name}: ${problem}`), ...model.fields.flatMap((field) =>
|
|
996
|
+
return models.flatMap((model) => [...arCalls(model.documentation, "model").problems.map((problem) => `model ${model.name}: ${problem}`), ...model.fields.flatMap((field) => {
|
|
997
|
+
const { calls, problems } = arCalls(field.documentation, "field");
|
|
998
|
+
const notNames = field.kind === "object" ? calls.filter((call) => {
|
|
999
|
+
const { validator } = validatorCall(call);
|
|
1000
|
+
return validator !== null && validator !== "name";
|
|
1001
|
+
}).map((call) => `the @ar. call "${call}" is on a relation field, which takes only @ar.name; validate the association with an @ar. line on the model`) : [];
|
|
1002
|
+
return [...problems, ...notNames].map((problem) => `field ${model.name}.${field.name}: ${problem}`);
|
|
1003
|
+
})]);
|
|
997
1004
|
}
|
|
998
1005
|
function splitArguments(text) {
|
|
999
1006
|
const parts = [];
|
|
@@ -1119,6 +1126,11 @@ function validatorCall(call) {
|
|
|
1119
1126
|
messages
|
|
1120
1127
|
};
|
|
1121
1128
|
}
|
|
1129
|
+
if (args.trim() === "false") return {
|
|
1130
|
+
validator,
|
|
1131
|
+
option: null,
|
|
1132
|
+
messages
|
|
1133
|
+
};
|
|
1122
1134
|
const kept = [];
|
|
1123
1135
|
const translated = [];
|
|
1124
1136
|
for (const argument of splitArguments(args)) {
|
|
@@ -1192,10 +1204,10 @@ function activeRecordLocaleFiles(models) {
|
|
|
1192
1204
|
], m.text);
|
|
1193
1205
|
}
|
|
1194
1206
|
for (const field of model.fields) {
|
|
1195
|
-
|
|
1196
|
-
const attribute = field.dbName ?? field.name;
|
|
1207
|
+
const attribute = field.kind === "object" ? makeSnakeCase(field.name) : field.dbName ?? field.name;
|
|
1197
1208
|
for (const call of arCalls(field.documentation, "field").calls) {
|
|
1198
1209
|
const { validator, messages } = validatorCall(call);
|
|
1210
|
+
if (field.kind === "object" && validator !== "name") continue;
|
|
1199
1211
|
for (const m of messages) setPath(tree(m.locale), validator === "name" ? [
|
|
1200
1212
|
"activerecord",
|
|
1201
1213
|
"attributes",
|
|
@@ -1395,30 +1407,43 @@ function activeRecordModels(models, allModels, enums) {
|
|
|
1395
1407
|
}).lines;
|
|
1396
1408
|
const foreignKeyFields = new Set(model.fields.flatMap((f) => f.kind === "object" ? f.relationFromFields ?? [] : []));
|
|
1397
1409
|
const compositeKeyFields = new Set(model.primaryKey?.fields);
|
|
1398
|
-
const
|
|
1399
|
-
const
|
|
1410
|
+
const scalarColumns = new Set(model.fields.filter((f) => f.kind === "scalar" && !f.isList).map((f) => f.name));
|
|
1411
|
+
const taken = new Set(model.fields.filter((f) => f.isUnique && !f.isId).map((f) => f.name));
|
|
1412
|
+
const uniqueSets = [...model.fields.filter((f) => f.isUnique && !f.isId).map((f) => [f.name]), ...model.uniqueFields.map((set) => {
|
|
1413
|
+
const columns = set.filter((name) => scalarColumns.has(name));
|
|
1414
|
+
const own = columns.find((name) => !foreignKeyFields.has(name) && !taken.has(name)) ?? columns.find((name) => !foreignKeyFields.has(name)) ?? columns[0] ?? set[0] ?? "";
|
|
1415
|
+
taken.add(own);
|
|
1416
|
+
return [own, ...set.filter((name) => name !== own)];
|
|
1417
|
+
})];
|
|
1418
|
+
const modelLines = arCalls(model.documentation, "model").calls.filter((call) => validatorCall(call).validator !== "name");
|
|
1419
|
+
const digestColumns = new Set(modelLines.flatMap((line) => {
|
|
1420
|
+
const m = line.match(/^has_secure_password(?:\s*\(?\s*:([a-z_][a-z0-9_]*))?/u);
|
|
1421
|
+
return m && !/validations:\s*false/u.test(line) ? [`${m[1] ?? "password"}_digest`] : [];
|
|
1422
|
+
}));
|
|
1423
|
+
const validationLines = model.fields.flatMap((f) => {
|
|
1400
1424
|
if (!(f.kind === "scalar" || f.kind === "enum")) return [];
|
|
1401
1425
|
const column = f.kind === "scalar" && !f.isList;
|
|
1402
|
-
const
|
|
1426
|
+
const own = arCalls(f.documentation, "field").calls.map((call) => validatorCall(call));
|
|
1427
|
+
const presence = !(column && !own.some(({ validator, option }) => validator === "presence" && option === null) && f.isRequired && !f.hasDefaultValue && !f.isId && !f.isUpdatedAt && !foreignKeyFields.has(f.name) && !compositeKeyFields.has(f.name) && !digestColumns.has(f.dbName ?? f.name) && f !== createdField && f !== updatedField) ? [] : f.type === "Boolean" ? ["inclusion: { in: [ true, false ] }"] : f.type === "Json" || f.type === "Bytes" ? ["exclusion: { in: [ nil ] }"] : ["presence: true"];
|
|
1403
1428
|
const length = column && f.type === "String" ? nativeLength(f) : null;
|
|
1404
1429
|
const lengthOpt = length === null ? [] : [`length: { maximum: ${length} }`];
|
|
1405
|
-
const
|
|
1406
|
-
|
|
1407
|
-
const
|
|
1408
|
-
const opts = [
|
|
1430
|
+
const uniqueness = (column ? uniqueSets.filter((set) => set[0] === f.name) : []).map((set) => {
|
|
1431
|
+
const scope = set.slice(1).map((name) => `:${fieldColumn$1(model, name)}`);
|
|
1432
|
+
const nullable = set.slice(1).filter((name) => model.fields.some((g) => g.name === name && !g.isRequired)).map((name) => `where.not(${fieldColumn$1(model, name)}: nil)`);
|
|
1433
|
+
const opts = [
|
|
1434
|
+
...scope.length === 0 ? [] : [`scope: ${scope.length === 1 ? scope[0] : rubyArray(scope)}`],
|
|
1435
|
+
...nullable.length === 0 ? [] : [`conditions: -> { ${nullable.join(".")} }`],
|
|
1436
|
+
...f.isRequired ? [] : ["allow_nil: true"]
|
|
1437
|
+
];
|
|
1409
1438
|
return opts.length === 0 ? "uniqueness: true" : `uniqueness: { ${opts.join(", ")} }`;
|
|
1410
|
-
})()];
|
|
1411
|
-
const own = arCalls(f.documentation, "field").calls.flatMap((call) => {
|
|
1412
|
-
const { option } = validatorCall(call);
|
|
1413
|
-
return option === null ? [] : [option];
|
|
1414
1439
|
});
|
|
1415
1440
|
const rules = [...[
|
|
1416
1441
|
...presence,
|
|
1417
1442
|
...lengthOpt,
|
|
1418
|
-
...uniqueness
|
|
1419
|
-
].filter((rule) => !own.some((
|
|
1420
|
-
return rules.length === 0 ? [] : [rubyCall("validates", [`:${f.dbName ?? f.name}`], rules)];
|
|
1421
|
-
})
|
|
1443
|
+
...uniqueness.slice(0, 1)
|
|
1444
|
+
].filter((rule) => !own.some(({ validator }) => validator === rule.split(":")[0])), ...own.flatMap(({ option }) => option === null ? [] : [option])];
|
|
1445
|
+
return [...rules.length === 0 ? [] : [rubyCall("validates", [`:${f.dbName ?? f.name}`], rules)], ...uniqueness.slice(1).map((rule) => rubyCall("validates", [`:${f.dbName ?? f.name}`], [rule]))];
|
|
1446
|
+
});
|
|
1422
1447
|
const modelSnake = makeSnakeCase(model.name);
|
|
1423
1448
|
const belongsToLines = associations.belongsTo.map((a) => {
|
|
1424
1449
|
const name = makeSnakeCase(a.name);
|
|
@@ -1472,7 +1497,8 @@ function activeRecordModels(models, allModels, enums) {
|
|
|
1472
1497
|
[...attributeLines, ...timestampLines],
|
|
1473
1498
|
enumLines,
|
|
1474
1499
|
validationLines,
|
|
1475
|
-
associationLines
|
|
1500
|
+
associationLines,
|
|
1501
|
+
modelLines
|
|
1476
1502
|
].filter((group) => group.length > 0).map((group) => group.join("\n")).join("\n\n").split("\n");
|
|
1477
1503
|
return [
|
|
1478
1504
|
`class ${className} < ApplicationRecord`,
|
|
@@ -382,14 +382,14 @@ function makeText(faker, name) {
|
|
|
382
382
|
max: 3
|
|
383
383
|
}) : match[1](faker);
|
|
384
384
|
}
|
|
385
|
-
function maxLength(field, rule) {
|
|
385
|
+
function maxLength(field, rule, stringLength) {
|
|
386
386
|
const native = nativeTypeOf(field);
|
|
387
|
-
const bounds = [native.name
|
|
387
|
+
const bounds = [native.name === null ? stringLength ?? void 0 : /^(Var|N|NVar)?Char$/u.test(native.name) ? native.args[0] : void 0, typeof rule.length === "number" ? rule.length : rule.length?.max].filter((n) => n !== void 0 && n > 0);
|
|
388
388
|
return bounds.length === 0 ? null : Math.min(...bounds);
|
|
389
389
|
}
|
|
390
|
-
function makeString(faker, field, rule) {
|
|
390
|
+
function makeString(faker, field, rule, bounds) {
|
|
391
391
|
const text = nativeTypeOf(field).name === "Uuid" ? faker.string.uuid() : makeText(faker, normalizedName(field.name));
|
|
392
|
-
const limit = maxLength(field, rule);
|
|
392
|
+
const limit = maxLength(field, rule, bounds.stringLength ?? null);
|
|
393
393
|
return limit === null ? text : text.slice(0, limit);
|
|
394
394
|
}
|
|
395
395
|
function intRange(field, rule) {
|
|
@@ -482,7 +482,7 @@ function makeJson(faker) {
|
|
|
482
482
|
function makeScalar(faker, field, enumValues, rule, bounds, index) {
|
|
483
483
|
if (field.kind === "enum") return enumValues === null || enumValues.length === 0 ? null : faker.helpers.arrayElement(enumValues).name;
|
|
484
484
|
switch (field.type) {
|
|
485
|
-
case "String": return makeString(faker, field, rule);
|
|
485
|
+
case "String": return makeString(faker, field, rule, bounds);
|
|
486
486
|
case "Int": return field.isId && rule.min === void 0 && rule.max === void 0 ? index + 1 : faker.number.int(intRange(field, rule));
|
|
487
487
|
case "BigInt": {
|
|
488
488
|
const range = intRange(field, rule);
|
|
@@ -504,7 +504,7 @@ function makeScalar(faker, field, enumValues, rule, bounds, index) {
|
|
|
504
504
|
prefix: "",
|
|
505
505
|
casing: "lower"
|
|
506
506
|
}), "hex"));
|
|
507
|
-
default: return makeString(faker, field, rule);
|
|
507
|
+
default: return makeString(faker, field, rule, bounds);
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
510
|
function listLength(faker, rule) {
|
|
@@ -1053,7 +1053,8 @@ function defaultValue(input, field) {
|
|
|
1053
1053
|
const { context, table, index } = input;
|
|
1054
1054
|
const bounds = {
|
|
1055
1055
|
nullRate: 0,
|
|
1056
|
-
dates: context.config.dates
|
|
1056
|
+
dates: context.config.dates,
|
|
1057
|
+
stringLength: context.stringLength
|
|
1057
1058
|
};
|
|
1058
1059
|
const generated = fieldDefault(field);
|
|
1059
1060
|
if (generated?.name === "autoincrement") return field.type === "BigInt" ? BigInt(index + 1) : index + 1;
|
|
@@ -1083,7 +1084,8 @@ function fillScalars(input, columns, skip, row) {
|
|
|
1083
1084
|
rule: input.context.config.models[input.table.name]?.fields?.[column.field],
|
|
1084
1085
|
bounds: {
|
|
1085
1086
|
nullRate: input.context.config.nullRate,
|
|
1086
|
-
dates: input.context.config.dates
|
|
1087
|
+
dates: input.context.config.dates,
|
|
1088
|
+
stringLength: input.context.stringLength
|
|
1087
1089
|
},
|
|
1088
1090
|
index: input.index,
|
|
1089
1091
|
row
|
|
@@ -1324,6 +1326,7 @@ function generateSeedRows(input) {
|
|
|
1324
1326
|
const context = {
|
|
1325
1327
|
faker: input.faker,
|
|
1326
1328
|
config: input.config,
|
|
1329
|
+
stringLength: input.dialect === "mysql" ? 191 : null,
|
|
1327
1330
|
tables: input.tables,
|
|
1328
1331
|
rowsByModel,
|
|
1329
1332
|
pending: /* @__PURE__ */ new Map(),
|
|
@@ -1489,7 +1492,8 @@ function seedProgram(overrides, cwd) {
|
|
|
1489
1492
|
const entries = yield* generateSeedRows({
|
|
1490
1493
|
tables: yield* makeSeedPlan(schema.datamodel),
|
|
1491
1494
|
config,
|
|
1492
|
-
faker: yield* makeFaker(config.seed, config.locale)
|
|
1495
|
+
faker: yield* makeFaker(config.seed, config.locale),
|
|
1496
|
+
dialect: dialectOf(schema.provider)
|
|
1493
1497
|
});
|
|
1494
1498
|
const report = {
|
|
1495
1499
|
seed: config.seed,
|
package/package.json
CHANGED