hekireki 0.52.1 → 0.52.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/README.md +8 -0
- 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/docs.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 +5 -5
- package/dist/bin/kysely.js +1 -1
- package/dist/bin/openapi.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-openapi-hono.js +1 -1
- package/dist/bin/zod.js +1 -1
- package/dist/{bin-Ds90Ze0I.js → bin-i7iQQ-V-.js} +131 -27
- package/dist/{discover-HsZu2aJ7.js → discover-CLLycWcR.js} +2 -2
- package/dist/{emit-COI2F4Vx.js → emit-DsCT5gLu.js} +1 -1
- package/dist/{migrate-B_LmJjyl.js → migrate-1xVrRUlb.js} +3 -3
- package/dist/{native-engine-CiYCdB3Z.js → native-engine-DeQEnJxi.js} +1 -1
- package/dist/{plan-C4tSF0Di.js → plan-8rsBBJcs.js} +2 -2
- package/dist/{run-CVdbTDka.js → run-DbZYkHVI.js} +4 -4
- package/dist/{schema-TL20sYuM.js → schema-CyJTUCF1.js} +10 -1
- package/dist/{sql-Dul-J3wN.js → sql-LMMCiAlf.js} +1 -1
- package/dist/{start-DCy-nE2o.js → start-Ba8wQAD1.js} +5 -5
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -80,6 +80,14 @@ The `provider` of the generator block picks the output. Every option is optional
|
|
|
80
80
|
Every ORM generator stores a `DateTime` as Prisma Client stores it, so the ORM and Prisma read
|
|
81
81
|
each other's rows alike.
|
|
82
82
|
|
|
83
|
+
`hekireki-sqlalchemy` and `hekireki-django` give a `uuid()`, `cuid()`, `ulid()` or `nanoid()`
|
|
84
|
+
default the value Prisma Client would make, with a package from PyPI where Python's standard
|
|
85
|
+
library has none: `uuid6` for `uuid(7)`, `python-ulid` for `ulid()`, `cuid` for `cuid()`, `cuid2`
|
|
86
|
+
for `cuid(2)` (2.1 or later, for `create_id()`) and `nanoid` for `nanoid()` (and `types-nanoid`
|
|
87
|
+
for mypy). A module imports only the ones its schema uses. With such a default on a Django primary
|
|
88
|
+
key, `save()` on a new instance given an existing key inserts, as with `uuid()`: update with
|
|
89
|
+
`update_or_create()` or `save(force_update=True)`.
|
|
90
|
+
|
|
83
91
|
### Database and documents
|
|
84
92
|
|
|
85
93
|
| Provider | Writes | Options |
|
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/docs.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
|
@@ -6,7 +6,7 @@ import { Console, Data, Effect, Schema } from "effect";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { CliError, Command, Flag } from "effect/cli";
|
|
8
8
|
// package.json
|
|
9
|
-
var version = "0.52.
|
|
9
|
+
var version = "0.52.2";
|
|
10
10
|
// src/schema/path.ts
|
|
11
11
|
/** Where Prisma looks for a schema when neither the command nor prisma.config.ts names one. */
|
|
12
12
|
const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
|
|
@@ -149,7 +149,7 @@ const studioFlags = {
|
|
|
149
149
|
function runStudio(args) {
|
|
150
150
|
return Effect.gen(function* () {
|
|
151
151
|
const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
|
|
152
|
-
const { startStudioServer } = yield* Effect.promise(() => import("../start-
|
|
152
|
+
const { startStudioServer } = yield* Effect.promise(() => import("../start-Ba8wQAD1.js"));
|
|
153
153
|
const started = yield* startStudioServer({
|
|
154
154
|
schemaPath,
|
|
155
155
|
port: args.port,
|
|
@@ -201,7 +201,7 @@ const seedFlags = {
|
|
|
201
201
|
};
|
|
202
202
|
function runSeedCommand(args) {
|
|
203
203
|
return Effect.gen(function* () {
|
|
204
|
-
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-
|
|
204
|
+
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-DbZYkHVI.js"));
|
|
205
205
|
const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
206
206
|
yield* Console.log(seedBanner(report));
|
|
207
207
|
});
|
|
@@ -244,7 +244,7 @@ function runMigrateCheckCommand(args) {
|
|
|
244
244
|
"migrate",
|
|
245
245
|
"check"
|
|
246
246
|
]);
|
|
247
|
-
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-
|
|
247
|
+
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-1xVrRUlb.js"));
|
|
248
248
|
const report = yield* runMigrateCheck({
|
|
249
249
|
...args,
|
|
250
250
|
schemaPath,
|
|
@@ -291,7 +291,7 @@ function runMigratePlanCommand(args) {
|
|
|
291
291
|
"migrate",
|
|
292
292
|
"plan"
|
|
293
293
|
]);
|
|
294
|
-
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-
|
|
294
|
+
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-1xVrRUlb.js"));
|
|
295
295
|
const report = yield* runMigrateCheck({
|
|
296
296
|
...args,
|
|
297
297
|
schemaPath,
|
package/dist/bin/kysely.js
CHANGED
package/dist/bin/openapi.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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as removePath, o as readDirectory, s as readFile, t as exists, u as writeFile } from "./file-DOGnu_Q2.js";
|
|
2
|
-
import { A as
|
|
3
|
-
import { n as emitMany, r as emitRaw, t as emit } from "./emit-
|
|
4
|
-
import { _ as stripAnnotations, a as makeOfflineSchemaEngineAdapter, c as makeSchema, d as erRelations, f as inferredERRelations, g as makeValidationExtractor, h as isAnnotationLine, i as openSchemaEngine, l as annotatedERRelations, m as extractObjectType, n as openNativeSchemaEngine, p as docBlockLines, r as engineCommand, t as findSchemaEngineBinary, u as erKey } from "./native-engine-
|
|
2
|
+
import { A as primaryKeyFields$1, C as isJoinSideA, D as lengthArg, E as isUlidDefault, F as uuidDefaultVersion, L as isSameList, M as relationEnds, N as scalarFields, O as manyToManyRelations, P as tableName, R as fmt, S as isImplicitManyToMany, T as isNowDefault$1, _ as cuidDefaultVersion, a as schemaText, b as isAutoincrement, g as columnName, h as backRelation, i as readSchemaFiles, j as referentialActions, k as nanoidDefault, m as formatSql, t as dialectOf, v as fieldColumn, w as isListDefault, x as isFunctionDefault, y as implicitJoinTables, z as fmtMarkdown } from "./schema-CyJTUCF1.js";
|
|
3
|
+
import { n as emitMany, r as emitRaw, t as emit } from "./emit-DsCT5gLu.js";
|
|
4
|
+
import { _ as stripAnnotations, a as makeOfflineSchemaEngineAdapter, c as makeSchema, d as erRelations, f as inferredERRelations, g as makeValidationExtractor, h as isAnnotationLine, i as openSchemaEngine, l as annotatedERRelations, m as extractObjectType, n as openNativeSchemaEngine, p as docBlockLines, r as engineCommand, t as findSchemaEngineBinary, u as erKey } from "./native-engine-DeQEnJxi.js";
|
|
5
5
|
import { a as makeSnakeCase, i as makePascalCase, n as indexPrefix, r as lowerFirst, t as constraintName } from "./case-D3JCqTLI.js";
|
|
6
6
|
import { a as splitStatements, t as MigrateConfigError } from "./errors-CRIxtr-P.js";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
@@ -3410,9 +3410,14 @@ const MODULE_NAMES$1 = /* @__PURE__ */ new Set([
|
|
|
3410
3410
|
"time",
|
|
3411
3411
|
"utc_today",
|
|
3412
3412
|
"utc_time",
|
|
3413
|
+
"now_milliseconds",
|
|
3413
3414
|
"uuid4_str",
|
|
3414
3415
|
"uuid7_str",
|
|
3415
3416
|
"ulid_str",
|
|
3417
|
+
"cuid_str",
|
|
3418
|
+
"cuid2_str",
|
|
3419
|
+
"nanoid_str",
|
|
3420
|
+
"partial",
|
|
3416
3421
|
"list",
|
|
3417
3422
|
"dict"
|
|
3418
3423
|
]);
|
|
@@ -3428,7 +3433,11 @@ function modelAttrNames(model, m2mTables) {
|
|
|
3428
3433
|
};
|
|
3429
3434
|
const reads = model.fields.map((field) => {
|
|
3430
3435
|
if (field.kind === "object") return field.isList && isDeclaringM2MSide(model, field, m2mTables) ? ["models"] : [];
|
|
3431
|
-
return ["models", ...formatDefaultArgs(model, field, false, unresolved).
|
|
3436
|
+
return ["models", ...formatDefaultArgs(model, field, false, unresolved).flatMap((arg) => {
|
|
3437
|
+
const match = /^\w+=(partial\()?([a-z_]\w*)/u.exec(arg);
|
|
3438
|
+
if (match === null) return [];
|
|
3439
|
+
return match[1] === void 0 ? [match[2]] : ["partial", match[2]];
|
|
3440
|
+
})];
|
|
3432
3441
|
});
|
|
3433
3442
|
for (const [i, field] of model.fields.entries()) {
|
|
3434
3443
|
const readLater = new Set(reads.slice(i + 1).flat());
|
|
@@ -3458,6 +3467,9 @@ function resolveNames(models, m2mTables = []) {
|
|
|
3458
3467
|
"uuid4_str",
|
|
3459
3468
|
"uuid7_str",
|
|
3460
3469
|
"ulid_str",
|
|
3470
|
+
"cuid_str",
|
|
3471
|
+
"cuid2_str",
|
|
3472
|
+
"nanoid_str",
|
|
3461
3473
|
...attr.values()
|
|
3462
3474
|
]);
|
|
3463
3475
|
const helper = /* @__PURE__ */ new Map();
|
|
@@ -3510,16 +3522,32 @@ function jsonScalarReturnType(parsed) {
|
|
|
3510
3522
|
}
|
|
3511
3523
|
function collectDefaultHelpers(models, names, enums) {
|
|
3512
3524
|
const enumMap = new Map((enums ?? []).map((e) => [e.name, e]));
|
|
3513
|
-
const
|
|
3525
|
+
const idHelpers = [
|
|
3514
3526
|
models.some((m) => m.fields.some((f) => uuidDefaultVersion(f) === 4 && f.nativeType?.[0] !== "Uuid")) ? ["def uuid4_str() -> str:", " return str(uuid.uuid4())"].join("\n") : null,
|
|
3515
3527
|
models.some((m) => m.fields.some((f) => uuidDefaultVersion(f) === 7 && f.nativeType?.[0] !== "Uuid")) ? ["def uuid7_str() -> str:", " return str(uuid6.uuid7())"].join("\n") : null,
|
|
3516
|
-
models.some((m) => m.fields.some((f) => isUlidDefault(f))) ? ["def ulid_str() -> str:", " return str(ULID())"].join("\n") : null
|
|
3528
|
+
models.some((m) => m.fields.some((f) => isUlidDefault(f))) ? ["def ulid_str() -> str:", " return str(ULID())"].join("\n") : null,
|
|
3529
|
+
models.some((m) => m.fields.some((f) => cuidDefaultVersion(f) === 1)) ? ["def cuid_str() -> str:", " return str(cuid.cuid())"].join("\n") : null,
|
|
3530
|
+
models.some((m) => m.fields.some((f) => cuidDefaultVersion(f) === 2)) ? ["def cuid2_str() -> str:", " return cuid2.create_id()"].join("\n") : null
|
|
3517
3531
|
].filter((h) => h !== null);
|
|
3532
|
+
const nanoidHelpers = models.some((m) => m.fields.some((f) => nanoidDefault(f) !== null)) ? [["def nanoid_str(size: int = 21) -> str:", " return nanoid.generate(size=size)"].join("\n")] : [];
|
|
3518
3533
|
const nowKinds = new Set(models.flatMap((m) => m.fields.filter((f) => isNowDefault$1(f) || f.isUpdatedAt === true).map((f) => dateTimeKind(f))));
|
|
3519
|
-
const nowHelpers = [
|
|
3534
|
+
const nowHelpers = [
|
|
3535
|
+
nowKinds.has("datetime") ? [
|
|
3536
|
+
"def now_milliseconds() -> datetime:",
|
|
3537
|
+
" now = timezone.now()",
|
|
3538
|
+
" return now.replace(microsecond=now.microsecond // 1000 * 1000)"
|
|
3539
|
+
].join("\n") : null,
|
|
3540
|
+
nowKinds.has("date") ? ["def utc_today() -> date:", " return datetime.now(dt_timezone.utc).date()"].join("\n") : null,
|
|
3541
|
+
nowKinds.has("time") ? [
|
|
3542
|
+
"def utc_time() -> time:",
|
|
3543
|
+
" now = datetime.now(dt_timezone.utc)",
|
|
3544
|
+
" return now.replace(microsecond=now.microsecond // 1000 * 1000).time()"
|
|
3545
|
+
].join("\n") : null
|
|
3546
|
+
].filter((h) => h !== null);
|
|
3520
3547
|
const fieldHelpers = models.flatMap((model) => model.fields.filter((f) => f.kind !== "object").map((field) => fieldDefaultHelper(model, field, names, enumMap)).filter((h) => h !== null));
|
|
3521
3548
|
return [
|
|
3522
|
-
...
|
|
3549
|
+
...idHelpers,
|
|
3550
|
+
...nanoidHelpers,
|
|
3523
3551
|
...nowHelpers,
|
|
3524
3552
|
...fieldHelpers
|
|
3525
3553
|
];
|
|
@@ -3552,11 +3580,36 @@ class AutoNowQuerySet(models.QuerySet[_M]):
|
|
|
3552
3580
|
if getattr(field, "auto_now", False):
|
|
3553
3581
|
kwargs.setdefault(field.name, getattr(field, "stamp", timezone.now)())
|
|
3554
3582
|
return super().update(**kwargs)`;
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3583
|
+
const STAMPED_FIELDS = [
|
|
3584
|
+
{
|
|
3585
|
+
name: "UtcDateField",
|
|
3586
|
+
base: "models.DateField",
|
|
3587
|
+
type: "date",
|
|
3588
|
+
helper: "utc_today"
|
|
3589
|
+
},
|
|
3590
|
+
{
|
|
3591
|
+
name: "UtcTimeField",
|
|
3592
|
+
base: "models.TimeField",
|
|
3593
|
+
type: "time",
|
|
3594
|
+
helper: "utc_time"
|
|
3595
|
+
},
|
|
3596
|
+
{
|
|
3597
|
+
name: "UtcAutoNowDateTimeField",
|
|
3598
|
+
base: "UtcDateTimeField",
|
|
3599
|
+
type: "datetime",
|
|
3600
|
+
helper: "now_milliseconds"
|
|
3601
|
+
},
|
|
3602
|
+
{
|
|
3603
|
+
name: "AutoNowDateTimeField",
|
|
3604
|
+
base: "models.DateTimeField",
|
|
3605
|
+
type: "datetime",
|
|
3606
|
+
helper: "now_milliseconds"
|
|
3607
|
+
}
|
|
3608
|
+
];
|
|
3609
|
+
function stampedField({ name, base, type, helper }) {
|
|
3610
|
+
return `class ${name}(${base}):${base.startsWith("models.") ? " # type: ignore[type-arg]" : ""}
|
|
3611
|
+
def stamp(self) -> ${type}:
|
|
3612
|
+
return ${helper}()
|
|
3560
3613
|
|
|
3561
3614
|
def pre_save(self, model_instance: models.Model, add: bool) -> Any:
|
|
3562
3615
|
if not self.auto_now:
|
|
@@ -3565,19 +3618,19 @@ function utcStampedField(kind) {
|
|
|
3565
3618
|
setattr(model_instance, self.attname, value)
|
|
3566
3619
|
return value`;
|
|
3567
3620
|
}
|
|
3568
|
-
function stampedFieldClass(field) {
|
|
3621
|
+
function stampedFieldClass(field, provider) {
|
|
3569
3622
|
if (field.isUpdatedAt !== true) return null;
|
|
3570
3623
|
const kind = dateTimeKind(field);
|
|
3571
3624
|
if (kind === "date") return "UtcDateField";
|
|
3572
|
-
|
|
3625
|
+
if (kind === "time") return "UtcTimeField";
|
|
3626
|
+
return holdsUtc(field, provider) ? "UtcAutoNowDateTimeField" : "AutoNowDateTimeField";
|
|
3573
3627
|
}
|
|
3574
3628
|
function collectFieldClasses(models, provider) {
|
|
3575
3629
|
const scalarFields = models.flatMap((m) => m.fields.filter((f) => f.kind !== "object"));
|
|
3576
|
-
const stamped = new Set(scalarFields.map((f) => stampedFieldClass(f)));
|
|
3630
|
+
const stamped = new Set(scalarFields.map((f) => stampedFieldClass(f, provider)));
|
|
3577
3631
|
return [
|
|
3578
3632
|
scalarFields.some((f) => holdsUtc(f, provider)) ? UTC_DATETIME_FIELD : null,
|
|
3579
|
-
stamped.has(
|
|
3580
|
-
stamped.has("UtcTimeField") ? utcStampedField("time") : null,
|
|
3633
|
+
...STAMPED_FIELDS.filter((f) => stamped.has(f.name)).map((f) => stampedField(f)),
|
|
3581
3634
|
scalarFields.some((f) => f.isUpdatedAt === true) ? AUTO_NOW_QUERY_SET : null
|
|
3582
3635
|
].filter((c) => c !== null);
|
|
3583
3636
|
}
|
|
@@ -3588,8 +3641,11 @@ function isEmptyObject(value) {
|
|
|
3588
3641
|
const NOW_DEFAULTS = {
|
|
3589
3642
|
date: "default=utc_today",
|
|
3590
3643
|
time: "default=utc_time",
|
|
3591
|
-
datetime: "default=
|
|
3644
|
+
datetime: "default=now_milliseconds"
|
|
3592
3645
|
};
|
|
3646
|
+
function nanoidDefaultArg(length) {
|
|
3647
|
+
return length === null ? "default=nanoid_str" : `default=partial(nanoid_str, size=${length})`;
|
|
3648
|
+
}
|
|
3593
3649
|
function generatedDefaultArgs(field) {
|
|
3594
3650
|
if (field.isUpdatedAt === true) return ["auto_now=True"];
|
|
3595
3651
|
const generated = dbGeneratedExpr(field);
|
|
@@ -3601,6 +3657,10 @@ function generatedDefaultArgs(field) {
|
|
|
3601
3657
|
return [uuidVersion === 7 ? "default=uuid7_str" : "default=uuid4_str"];
|
|
3602
3658
|
}
|
|
3603
3659
|
if (isUlidDefault(field)) return ["default=ulid_str"];
|
|
3660
|
+
const cuidVersion = cuidDefaultVersion(field);
|
|
3661
|
+
if (cuidVersion !== null) return [cuidVersion === 2 ? "default=cuid2_str" : "default=cuid_str"];
|
|
3662
|
+
const nanoid = nanoidDefault(field);
|
|
3663
|
+
if (nanoid !== null) return [nanoidDefaultArg(nanoid.length)];
|
|
3604
3664
|
return null;
|
|
3605
3665
|
}
|
|
3606
3666
|
function stringDefaultArgs(model, field, def, names) {
|
|
@@ -3635,8 +3695,7 @@ function autoFieldCtor(field) {
|
|
|
3635
3695
|
return field.type === "BigInt" ? "BigAutoField" : "AutoField";
|
|
3636
3696
|
}
|
|
3637
3697
|
function scalarFieldClass(field, provider, ctor) {
|
|
3638
|
-
|
|
3639
|
-
return stampedFieldClass(field) ?? `models.${ctor}`;
|
|
3698
|
+
return stampedFieldClass(field, provider) ?? (holdsUtc(field, provider) ? "UtcDateTimeField" : `models.${ctor}`);
|
|
3640
3699
|
}
|
|
3641
3700
|
function generateScalarField(model, field, isPk, names, provider) {
|
|
3642
3701
|
const columnName = fieldColumnName(field);
|
|
@@ -3924,11 +3983,15 @@ function stdlibImports(needs) {
|
|
|
3924
3983
|
needs.fromDatetime.length > 0 ? `from datetime import ${needs.fromDatetime.join(", ")}` : null,
|
|
3925
3984
|
needs.utcField || needs.nowHelpers ? "from datetime import timezone as dt_timezone" : null,
|
|
3926
3985
|
needs.decimal ? "from decimal import Decimal" : null,
|
|
3986
|
+
needs.partial ? "from functools import partial" : null,
|
|
3927
3987
|
fromTyping.length > 0 ? `from typing import ${fromTyping.join(", ")}` : null
|
|
3928
3988
|
].filter((l) => l !== null);
|
|
3929
3989
|
}
|
|
3930
3990
|
function thirdPartyImports(needs) {
|
|
3931
3991
|
return [
|
|
3992
|
+
needs.cuid ? "import cuid # type: ignore[import-untyped, unused-ignore]" : null,
|
|
3993
|
+
needs.cuid2 ? "import cuid2" : null,
|
|
3994
|
+
needs.nanoid ? "import nanoid" : null,
|
|
3932
3995
|
needs.uuid6 ? "import uuid6" : null,
|
|
3933
3996
|
needs.utcField ? "from django.conf import settings" : null,
|
|
3934
3997
|
needs.array ? "from django.contrib.postgres.fields import ArrayField" : null,
|
|
@@ -3948,13 +4011,17 @@ function collectGlobalImports$1(models, indexes, provider) {
|
|
|
3948
4011
|
const nowHelperKinds = nowKinds.filter((kind) => kind !== "datetime");
|
|
3949
4012
|
const kinds = /* @__PURE__ */ new Set([
|
|
3950
4013
|
...literalKinds,
|
|
3951
|
-
...
|
|
4014
|
+
...nowKinds,
|
|
3952
4015
|
...needsUtcField || nowHelperKinds.length > 0 ? ["datetime"] : []
|
|
3953
4016
|
]);
|
|
3954
4017
|
const needs = {
|
|
3955
4018
|
uuid: scalarFields.some((f) => uuidDefaultVersion(f) === 4),
|
|
3956
4019
|
uuid6: scalarFields.some((f) => uuidDefaultVersion(f) === 7),
|
|
3957
4020
|
ulid: scalarFields.some((f) => isUlidDefault(f)),
|
|
4021
|
+
cuid: scalarFields.some((f) => cuidDefaultVersion(f) === 1),
|
|
4022
|
+
cuid2: scalarFields.some((f) => cuidDefaultVersion(f) === 2),
|
|
4023
|
+
nanoid: scalarFields.some((f) => nanoidDefault(f) !== null),
|
|
4024
|
+
partial: scalarFields.some((f) => (nanoidDefault(f)?.length ?? null) !== null),
|
|
3958
4025
|
array: scalarFields.some((f) => f.isList),
|
|
3959
4026
|
rawSql: scalarFields.some((f) => dbGeneratedExpr(f) !== null),
|
|
3960
4027
|
utcField: needsUtcField,
|
|
@@ -16502,7 +16569,7 @@ function collectManyToManyTables(allModels) {
|
|
|
16502
16569
|
info: {
|
|
16503
16570
|
relationName,
|
|
16504
16571
|
tableName: `_${relationName}`,
|
|
16505
|
-
varName:
|
|
16572
|
+
varName: associationVarName(relationName),
|
|
16506
16573
|
leftModel: leftName,
|
|
16507
16574
|
leftTable: leftModelObj?.dbName ?? leftName,
|
|
16508
16575
|
leftPkField: leftModelObj?.fields.find((f) => f.isId),
|
|
@@ -16519,6 +16586,22 @@ function collectManyToManyTables(allModels) {
|
|
|
16519
16586
|
return [info];
|
|
16520
16587
|
});
|
|
16521
16588
|
}
|
|
16589
|
+
const MODULE_LEVEL_NAMES = /* @__PURE__ */ new Set([
|
|
16590
|
+
"uuid",
|
|
16591
|
+
"uuid6",
|
|
16592
|
+
"cuid",
|
|
16593
|
+
"cuid2",
|
|
16594
|
+
"nanoid",
|
|
16595
|
+
"datetime",
|
|
16596
|
+
"date",
|
|
16597
|
+
"timezone",
|
|
16598
|
+
"text",
|
|
16599
|
+
"func"
|
|
16600
|
+
]);
|
|
16601
|
+
function associationVarName(relationName) {
|
|
16602
|
+
const name = makeSnakeCase(relationName);
|
|
16603
|
+
return MODULE_LEVEL_NAMES.has(name) ? `${name}_table` : name;
|
|
16604
|
+
}
|
|
16522
16605
|
function generateAssociationTable(info, provider) {
|
|
16523
16606
|
const plain = plainType("String", provider);
|
|
16524
16607
|
const leftSaType = info.leftPkField ? resolveNativeType(info.leftPkField, provider) : plain;
|
|
@@ -16733,6 +16816,13 @@ function uuidDefaultArg(field, uuidVersion) {
|
|
|
16733
16816
|
if (field.nativeType?.[0] === "Uuid") return uuidVersion === 7 ? "default=uuid6.uuid7" : "default=uuid_mod.uuid4";
|
|
16734
16817
|
return uuidVersion === 7 ? "default=lambda: str(uuid6.uuid7())" : "default=lambda: str(uuid_mod.uuid4())";
|
|
16735
16818
|
}
|
|
16819
|
+
function idDefaultArg(field) {
|
|
16820
|
+
const cuidVersion = cuidDefaultVersion(field);
|
|
16821
|
+
if (cuidVersion !== null) return cuidVersion === 2 ? "default=lambda: cuid2.create_id()" : "default=lambda: cuid.cuid()";
|
|
16822
|
+
const nanoid = nanoidDefault(field);
|
|
16823
|
+
if (nanoid === null) return null;
|
|
16824
|
+
return nanoid.length === null ? "default=lambda: nanoid.generate()" : `default=lambda: nanoid.generate(size=${nanoid.length})`;
|
|
16825
|
+
}
|
|
16736
16826
|
function literalDefaultArgs(field, isPk, enumMap, provider) {
|
|
16737
16827
|
const defaultVal = formatDefault(field, enumMap.get(field.type));
|
|
16738
16828
|
if (defaultVal === null || isPk) return [];
|
|
@@ -16749,6 +16839,8 @@ function defaultArgs(field, isPk, enumMap, provider) {
|
|
|
16749
16839
|
const uuidVersion = uuidDefaultVersion(field);
|
|
16750
16840
|
if (uuidVersion !== null) return [uuidDefaultArg(field, uuidVersion)];
|
|
16751
16841
|
if (isUlidDefault(field)) return ["default=lambda: str(ULID())"];
|
|
16842
|
+
const idArg = idDefaultArg(field);
|
|
16843
|
+
if (idArg !== null) return [idArg];
|
|
16752
16844
|
if (!isPk || isAutoincrement(field)) return literalDefaultArgs(field, isPk, enumMap, provider);
|
|
16753
16845
|
return [];
|
|
16754
16846
|
}
|
|
@@ -16868,7 +16960,7 @@ function generateManyToManyRelationships(associations, model, allModels, m2mTabl
|
|
|
16868
16960
|
return associations.manyToMany.map((assoc) => {
|
|
16869
16961
|
const snakeName = attributeName(model, assoc.name);
|
|
16870
16962
|
const backPop = findM2MBackPopulates(assoc.targetModel, model.name, assoc.name, assoc.relationName, allModels);
|
|
16871
|
-
const secondaryVar = tableByRelation.get(assoc.relationName)?.varName ??
|
|
16963
|
+
const secondaryVar = tableByRelation.get(assoc.relationName)?.varName ?? associationVarName(assoc.relationName);
|
|
16872
16964
|
const other = relationFieldsOf(model, assoc.relationName).find((f) => f.name !== assoc.name);
|
|
16873
16965
|
const [own, far] = other && other.name < assoc.name ? ["B", "A"] : ["A", "B"];
|
|
16874
16966
|
const pk = `${className(model.name)}.${attributeName(model, pkField?.name ?? "id")}`;
|
|
@@ -16978,6 +17070,9 @@ function importNeeds(models, provider) {
|
|
|
16978
17070
|
uuid: someField(models, isUuidField),
|
|
16979
17071
|
uuid7: someField(models, (f) => uuidDefaultVersion(f) === 7),
|
|
16980
17072
|
ulid: someField(models, (f) => isUlidDefault(f)),
|
|
17073
|
+
cuid: someField(models, (f) => cuidDefaultVersion(f) === 1),
|
|
17074
|
+
cuid2: someField(models, (f) => cuidDefaultVersion(f) === 2),
|
|
17075
|
+
nanoid: someField(models, (f) => nanoidDefault(f) !== null),
|
|
16981
17076
|
date: usesNativeType(models, ["Date"]),
|
|
16982
17077
|
time: usesNativeType(models, ["Time", "Timetz"])
|
|
16983
17078
|
};
|
|
@@ -17033,6 +17128,15 @@ function dialectImportLines(saImports, needs, provider) {
|
|
|
17033
17128
|
if (dialectTypes.length === 0) return [];
|
|
17034
17129
|
return [`from sqlalchemy.dialects.${provider === "mysql" ? "mysql" : "postgresql"} import ${dialectTypes.toSorted().join(", ")}`];
|
|
17035
17130
|
}
|
|
17131
|
+
function idPackageImportLines(needs) {
|
|
17132
|
+
return [
|
|
17133
|
+
...needs.uuid7 ? ["import uuid6"] : [],
|
|
17134
|
+
...needs.ulid ? ["from ulid import ULID"] : [],
|
|
17135
|
+
...needs.cuid ? ["import cuid # type: ignore[import-untyped, unused-ignore]"] : [],
|
|
17136
|
+
...needs.cuid2 ? ["import cuid2"] : [],
|
|
17137
|
+
...needs.nanoid ? ["import nanoid"] : []
|
|
17138
|
+
];
|
|
17139
|
+
}
|
|
17036
17140
|
function pythonImportLines(needs) {
|
|
17037
17141
|
const typingImports = [needs.any ? "Any" : null, needs.optional ? "Optional" : null].filter((i) => i !== null);
|
|
17038
17142
|
const dtParts = [
|
|
@@ -17046,8 +17150,7 @@ function pythonImportLines(needs) {
|
|
|
17046
17150
|
...needs.decimal ? ["from decimal import Decimal as DecimalType"] : [],
|
|
17047
17151
|
...dtParts.length > 0 ? [`from datetime import ${dtParts.join(", ")}`] : [],
|
|
17048
17152
|
...needs.uuid ? ["import uuid as uuid_mod"] : [],
|
|
17049
|
-
...needs
|
|
17050
|
-
...needs.ulid ? ["from ulid import ULID"] : []
|
|
17153
|
+
...idPackageImportLines(needs)
|
|
17051
17154
|
];
|
|
17052
17155
|
}
|
|
17053
17156
|
function collectGlobalImports(models, _enums, indexes, m2mTables, provider) {
|
|
@@ -17183,7 +17286,8 @@ function generateBase(models, provider) {
|
|
|
17183
17286
|
] : [];
|
|
17184
17287
|
const utcNow = models.some((m) => m.fields.some((f) => isNowDefault$1(f) || f.isUpdatedAt === true)) ? [
|
|
17185
17288
|
"def utc_now() -> datetime:",
|
|
17186
|
-
"
|
|
17289
|
+
" now = datetime.now(timezone.utc)",
|
|
17290
|
+
" return now.replace(microsecond=now.microsecond // 1000 * 1000)",
|
|
17187
17291
|
"",
|
|
17188
17292
|
""
|
|
17189
17293
|
] : [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as importFromProject, f as ADAPTERS, h as LIBSQL_ADAPTER } from "./file-DOGnu_Q2.js";
|
|
2
|
-
import { d as makePostgresSchema, l as isLibsqlUrl, p as makeSqliteFilePath } from "./schema-
|
|
3
|
-
import { l as SeedDatabaseError } from "./sql-
|
|
2
|
+
import { d as makePostgresSchema, l as isLibsqlUrl, p as makeSqliteFilePath } from "./schema-CyJTUCF1.js";
|
|
3
|
+
import { l as SeedDatabaseError } from "./sql-LMMCiAlf.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { s as readFile } from "./file-DOGnu_Q2.js";
|
|
2
|
-
import "./schema-
|
|
3
|
-
import { r as emitRaw } from "./emit-
|
|
2
|
+
import "./schema-CyJTUCF1.js";
|
|
3
|
+
import { r as emitRaw } from "./emit-DsCT5gLu.js";
|
|
4
4
|
import { a as splitStatements, t as MigrateConfigError } from "./errors-CRIxtr-P.js";
|
|
5
|
-
import { i as lostInRebuild, l as runMigrateCheck, n as isDestructiveStep, o as BLOCK_QUOTE, r as isLossyFix, s as rewriteMigration, t as batchedStatements } from "./plan-
|
|
5
|
+
import { i as lostInRebuild, l as runMigrateCheck, n as isDestructiveStep, o as BLOCK_QUOTE, r as isLossyFix, s as rewriteMigration, t as batchedStatements } from "./plan-8rsBBJcs.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
// src/migrate/adapter/plan-file.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as readBytes, o as readDirectory, t as exists } from "./file-DOGnu_Q2.js";
|
|
2
|
-
import { h as backRelation, s as environmentVariable } from "./schema-
|
|
2
|
+
import { h as backRelation, s as environmentVariable } from "./schema-CyJTUCF1.js";
|
|
3
3
|
import { a as splitStatements, c as sqliteAffinity, r as MigrateEngineError } from "./errors-CRIxtr-P.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { Effect, Semaphore, Stream } from "effect";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { _ as NO_SQLITE, c as removePath, d as importFromProject, i as makeDirectory, m as DISCONNECTED, r as isDirectory, s as readFile, t as exists, u as writeFile, v as READ_STATEMENT } from "./file-DOGnu_Q2.js";
|
|
2
2
|
import { d as DatabaseError, f as DatabaseUnavailableError } from "./bin/hekireki.js";
|
|
3
|
-
import {
|
|
3
|
+
import { C as isJoinSideA, a as schemaText, d as makePostgresSchema, f as makeRedactedUrl, h as backRelation, i as readSchemaFiles, l as isLibsqlUrl, n as parseSchema, p as makeSqliteFilePath, t as dialectOf, u as makeDialect } from "./schema-CyJTUCF1.js";
|
|
4
4
|
import { a as splitStatements, c as sqliteAffinity, n as MigrateDatabaseError, o as splitTopLevel, t as MigrateConfigError } from "./errors-CRIxtr-P.js";
|
|
5
|
-
import { d as resolveDatabaseUrl, f as placeholder, h as stringLiteral, i as withTypeScriptImports, m as quoteIdentifier, n as renderLiteral, o as readConfigUrl, p as qualifiedName } from "./sql-
|
|
5
|
+
import { d as resolveDatabaseUrl, f as placeholder, h as stringLiteral, i as withTypeScriptImports, m as quoteIdentifier, n as renderLiteral, o as readConfigUrl, p as qualifiedName } from "./sql-LMMCiAlf.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { layer } from "@effect/platform-node/NodeFileSystem";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as exists } from "./file-DOGnu_Q2.js";
|
|
2
2
|
import { v as DEFAULT_SCHEMA_PATHS, y as prismaSchemaPath } from "./bin/hekireki.js";
|
|
3
|
-
import {
|
|
4
|
-
import { r as emitRaw } from "./emit-
|
|
3
|
+
import { C as isJoinSideA, I as chunks, a as schemaText, h as backRelation, i as readSchemaFiles, n as parseSchema, t as dialectOf } from "./schema-CyJTUCF1.js";
|
|
4
|
+
import { r as emitRaw } from "./emit-DsCT5gLu.js";
|
|
5
5
|
import { r as lowerFirst } from "./case-D3JCqTLI.js";
|
|
6
|
-
import { a as loadSeedConfig, c as SeedConfigError, d as resolveDatabaseUrl, i as withTypeScriptImports, l as SeedDatabaseError, r as sequenceSql, s as resolveConfigPath, t as makeSeedSql, u as SeedGenerationError } from "./sql-
|
|
7
|
-
import { n as discoverClient, r as adapterOf } from "./discover-
|
|
6
|
+
import { a as loadSeedConfig, c as SeedConfigError, d as resolveDatabaseUrl, i as withTypeScriptImports, l as SeedDatabaseError, r as sequenceSql, s as resolveConfigPath, t as makeSeedSql, u as SeedGenerationError } from "./sql-LMMCiAlf.js";
|
|
7
|
+
import { n as discoverClient, r as adapterOf } from "./discover-CLLycWcR.js";
|
|
8
8
|
import { Effect } from "effect";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import * as z from "zod";
|
|
@@ -104,6 +104,15 @@ function uuidDefaultVersion(field) {
|
|
|
104
104
|
function isUlidDefault(field) {
|
|
105
105
|
return isFunctionDefault(field.default) && field.default.name === "ulid";
|
|
106
106
|
}
|
|
107
|
+
function cuidDefaultVersion(field) {
|
|
108
|
+
if (!(isFunctionDefault(field.default) && field.default.name === "cuid")) return null;
|
|
109
|
+
return field.default.args[0] === 2 ? 2 : 1;
|
|
110
|
+
}
|
|
111
|
+
function nanoidDefault(field) {
|
|
112
|
+
if (!(isFunctionDefault(field.default) && field.default.name === "nanoid")) return null;
|
|
113
|
+
const [length] = field.default.args;
|
|
114
|
+
return { length: typeof length === "number" ? length : null };
|
|
115
|
+
}
|
|
107
116
|
function backRelation(field, owner, models) {
|
|
108
117
|
const related = models.find((m) => m.name === field.type);
|
|
109
118
|
return related?.fields.find((f) => f.kind === "object" && f.relationName === field.relationName && f.type === owner.name && !(related.name === owner.name && f.name === field.name));
|
|
@@ -495,4 +504,4 @@ const DIALECTS = {
|
|
|
495
504
|
function dialectOf(provider) {
|
|
496
505
|
return provider === null ? null : DIALECTS[provider] ?? null;
|
|
497
506
|
}
|
|
498
|
-
export {
|
|
507
|
+
export { primaryKeyFields as A, isJoinSideA as C, lengthArg as D, isUlidDefault as E, uuidDefaultVersion as F, chunks as I, isSameList as L, relationEnds as M, scalarFields as N, manyToManyRelations as O, tableName as P, fmt as R, isImplicitManyToMany as S, isNowDefault as T, cuidDefaultVersion as _, schemaText as a, isAutoincrement as b, makeDatabaseUrl as c, makePostgresSchema as d, makeRedactedUrl as f, columnName as g, backRelation as h, readSchemaFiles as i, referentialActions as j, nanoidDefault as k, isLibsqlUrl as l, formatSql as m, parseSchema as n, DatabaseUrlNotFoundError as o, makeSqliteFilePath as p, readConfig as r, environmentVariable as s, dialectOf as t, makeDialect as u, fieldColumn as v, isListDefault as w, isFunctionDefault as x, implicitJoinTables as y, fmtMarkdown as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as readFile, t as exists, u as writeFile } from "./file-DOGnu_Q2.js";
|
|
2
2
|
import { b as readPrismaConfig } from "./bin/hekireki.js";
|
|
3
|
-
import {
|
|
3
|
+
import { I as chunks, c as makeDatabaseUrl, o as DatabaseUrlNotFoundError } from "./schema-CyJTUCF1.js";
|
|
4
4
|
import nodeModule from "node:module";
|
|
5
5
|
import { ConfigProvider, Data, Effect, FileSystem, Schema, SchemaIssue } from "effect";
|
|
6
6
|
import path from "node:path";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { c as removePath, i as makeDirectory, l as watch, n as fileStamp, o as readDirectory, r as isDirectory, s as readFile, t as exists, u as writeFile$1 } from "./file-DOGnu_Q2.js";
|
|
2
2
|
import { _ as STUDIO_HOSTNAME, a as InvalidInputError, b as readPrismaConfig, c as ServerListenError, d as DatabaseError, g as SSE_PING_MS, h as PRISMA_FILE_URI, i as FormatError, l as UnknownFileError, m as MIGRATIONS_POLL_MS, n as ClientUnavailableError, o as SchemaLoadError, p as FORBIDDEN_HOST_MESSAGE, r as FileWriteError, s as SchemaParseError, t as ClientQueryError, u as UnknownModelError } from "./bin/hekireki.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeSchema, i as openSchemaEngine, n as openNativeSchemaEngine, o as makeSchemaEngineAdapter, r as engineCommand, s as makeAnalysisSchema, t as findSchemaEngineBinary } from "./native-engine-
|
|
3
|
+
import { R as fmt, d as makePostgresSchema, i as readSchemaFiles$1, m as formatSql, n as parseSchema, r as readConfig } from "./schema-CyJTUCF1.js";
|
|
4
|
+
import { c as makeSchema, i as openSchemaEngine, n as openNativeSchemaEngine, o as makeSchemaEngineAdapter, r as engineCommand, s as makeAnalysisSchema, t as findSchemaEngineBinary } from "./native-engine-DeQEnJxi.js";
|
|
5
5
|
import { r as lowerFirst } from "./case-D3JCqTLI.js";
|
|
6
6
|
import { a as splitStatements, i as MigrationNotFoundError, l as toTsType, n as MigrateDatabaseError, s as literalDataType, t as MigrateConfigError } from "./errors-CRIxtr-P.js";
|
|
7
|
-
import { f as placeholder, h as stringLiteral, i as withTypeScriptImports, m as quoteIdentifier, o as readConfigUrl, p as qualifiedName } from "./sql-
|
|
8
|
-
import { _ as openSqliteCopy, a as makePlan$1, c as checkOpened, d as DECISIONS_FILE, f as readDecisions, g as openShadowDatabase, h as openMysqlCopy, m as connectDatabase, p as writeDecisions, u as introspectDatabase } from "./plan-
|
|
9
|
-
import { n as discoverClient, r as adapterOf, t as clientSource } from "./discover-
|
|
7
|
+
import { f as placeholder, h as stringLiteral, i as withTypeScriptImports, m as quoteIdentifier, o as readConfigUrl, p as qualifiedName } from "./sql-LMMCiAlf.js";
|
|
8
|
+
import { _ as openSqliteCopy, a as makePlan$1, c as checkOpened, d as DECISIONS_FILE, f as readDecisions, g as openShadowDatabase, h as openMysqlCopy, m as connectDatabase, p as writeDecisions, u as introspectDatabase } from "./plan-8rsBBJcs.js";
|
|
9
|
+
import { n as discoverClient, r as adapterOf, t as clientSource } from "./discover-CLLycWcR.js";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
11
|
import { Clock, Duration, Effect, Match, Option, Ref, Schedule, Semaphore, Stream } from "effect";
|
|
12
12
|
import path from "node:path";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hekireki",
|
|
3
|
-
"version": "0.52.
|
|
3
|
+
"version": "0.52.2",
|
|
4
4
|
"description": "Hekireki is a code generator from Prisma schema to validation schemas, ORM models, OpenAPI and ER diagrams, with a Studio for your schema and its data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"activerecord",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"django",
|
|
13
13
|
"docs",
|
|
14
14
|
"documentation",
|
|
15
|
+
"drizzle",
|
|
15
16
|
"ecto",
|
|
16
17
|
"efcore",
|
|
17
18
|
"effect",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"faker",
|
|
22
23
|
"go",
|
|
23
24
|
"gorm",
|
|
25
|
+
"hono",
|
|
24
26
|
"json-schema",
|
|
25
27
|
"kotlin",
|
|
26
28
|
"kysely",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"ruby",
|
|
36
38
|
"rust",
|
|
37
39
|
"sea-orm",
|
|
40
|
+
"sqlalchemy",
|
|
38
41
|
"typebox",
|
|
39
42
|
"valibot",
|
|
40
43
|
"zod"
|