@zenstackhq/orm 3.2.1 → 3.3.0-beta.1
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/dist/index.cjs +169 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +913 -878
- package/dist/index.d.ts +913 -878
- package/dist/index.js +164 -92
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -32,11 +32,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
// src/index.ts
|
|
33
33
|
var src_exports = {};
|
|
34
34
|
__export(src_exports, {
|
|
35
|
+
AllCrudOperations: () => AllCrudOperations,
|
|
36
|
+
AllReadOperations: () => AllReadOperations,
|
|
35
37
|
AnyNull: () => AnyNull,
|
|
36
38
|
AnyNullClass: () => AnyNullClass,
|
|
37
39
|
BaseCrudDialect: () => BaseCrudDialect,
|
|
38
40
|
CRUD: () => CRUD,
|
|
39
41
|
CRUD_EXT: () => CRUD_EXT,
|
|
42
|
+
CoreCrudOperations: () => CoreCrudOperations,
|
|
43
|
+
CoreReadOperations: () => CoreReadOperations,
|
|
44
|
+
CoreWriteOperations: () => CoreWriteOperations,
|
|
40
45
|
DbNull: () => DbNull,
|
|
41
46
|
DbNullClass: () => DbNullClass,
|
|
42
47
|
InputValidator: () => InputValidator,
|
|
@@ -2107,6 +2112,54 @@ function getCrudDialect(schema, options) {
|
|
|
2107
2112
|
__name(getCrudDialect, "getCrudDialect");
|
|
2108
2113
|
|
|
2109
2114
|
// src/client/crud/operations/base.ts
|
|
2115
|
+
var CoreCrudOperations = [
|
|
2116
|
+
"findMany",
|
|
2117
|
+
"findUnique",
|
|
2118
|
+
"findFirst",
|
|
2119
|
+
"create",
|
|
2120
|
+
"createMany",
|
|
2121
|
+
"createManyAndReturn",
|
|
2122
|
+
"update",
|
|
2123
|
+
"updateMany",
|
|
2124
|
+
"updateManyAndReturn",
|
|
2125
|
+
"upsert",
|
|
2126
|
+
"delete",
|
|
2127
|
+
"deleteMany",
|
|
2128
|
+
"count",
|
|
2129
|
+
"aggregate",
|
|
2130
|
+
"groupBy",
|
|
2131
|
+
"exists"
|
|
2132
|
+
];
|
|
2133
|
+
var CoreReadOperations = [
|
|
2134
|
+
"findMany",
|
|
2135
|
+
"findUnique",
|
|
2136
|
+
"findFirst",
|
|
2137
|
+
"count",
|
|
2138
|
+
"aggregate",
|
|
2139
|
+
"groupBy",
|
|
2140
|
+
"exists"
|
|
2141
|
+
];
|
|
2142
|
+
var CoreWriteOperations = [
|
|
2143
|
+
"create",
|
|
2144
|
+
"createMany",
|
|
2145
|
+
"createManyAndReturn",
|
|
2146
|
+
"update",
|
|
2147
|
+
"updateMany",
|
|
2148
|
+
"updateManyAndReturn",
|
|
2149
|
+
"upsert",
|
|
2150
|
+
"delete",
|
|
2151
|
+
"deleteMany"
|
|
2152
|
+
];
|
|
2153
|
+
var AllCrudOperations = [
|
|
2154
|
+
...CoreCrudOperations,
|
|
2155
|
+
"findUniqueOrThrow",
|
|
2156
|
+
"findFirstOrThrow"
|
|
2157
|
+
];
|
|
2158
|
+
var AllReadOperations = [
|
|
2159
|
+
...CoreReadOperations,
|
|
2160
|
+
"findUniqueOrThrow",
|
|
2161
|
+
"findFirstOrThrow"
|
|
2162
|
+
];
|
|
2110
2163
|
var BaseOperationHandler = class {
|
|
2111
2164
|
static {
|
|
2112
2165
|
__name(this, "BaseOperationHandler");
|
|
@@ -3759,6 +3812,18 @@ var DeleteOperationHandler = class extends BaseOperationHandler {
|
|
|
3759
3812
|
}
|
|
3760
3813
|
};
|
|
3761
3814
|
|
|
3815
|
+
// src/client/crud/operations/exists.ts
|
|
3816
|
+
var ExistsOperationHandler = class extends BaseOperationHandler {
|
|
3817
|
+
static {
|
|
3818
|
+
__name(this, "ExistsOperationHandler");
|
|
3819
|
+
}
|
|
3820
|
+
async handle(_operation, args) {
|
|
3821
|
+
const normalizedArgs = this.normalizeArgs(args);
|
|
3822
|
+
const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
|
|
3823
|
+
return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
|
|
3824
|
+
}
|
|
3825
|
+
};
|
|
3826
|
+
|
|
3762
3827
|
// src/client/crud/operations/find.ts
|
|
3763
3828
|
var FindOperationHandler = class extends BaseOperationHandler {
|
|
3764
3829
|
static {
|
|
@@ -3767,10 +3832,7 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
3767
3832
|
async handle(operation, args, validateArgs = true) {
|
|
3768
3833
|
const normalizedArgs = this.normalizeArgs(args);
|
|
3769
3834
|
const findOne = operation === "findFirst" || operation === "findUnique";
|
|
3770
|
-
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs,
|
|
3771
|
-
unique: operation === "findUnique",
|
|
3772
|
-
findOne
|
|
3773
|
-
}) : normalizedArgs;
|
|
3835
|
+
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, operation) : normalizedArgs;
|
|
3774
3836
|
if (findOne) {
|
|
3775
3837
|
parsedArgs = parsedArgs ?? {};
|
|
3776
3838
|
parsedArgs.take = 1;
|
|
@@ -3781,18 +3843,6 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
3781
3843
|
}
|
|
3782
3844
|
};
|
|
3783
3845
|
|
|
3784
|
-
// src/client/crud/operations/exists.ts
|
|
3785
|
-
var ExistsOperationHandler = class extends BaseOperationHandler {
|
|
3786
|
-
static {
|
|
3787
|
-
__name(this, "ExistsOperationHandler");
|
|
3788
|
-
}
|
|
3789
|
-
async handle(_operation, args) {
|
|
3790
|
-
const normalizedArgs = this.normalizeArgs(args);
|
|
3791
|
-
const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
|
|
3792
|
-
return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
|
|
3793
|
-
}
|
|
3794
|
-
};
|
|
3795
|
-
|
|
3796
3846
|
// src/client/crud/operations/group-by.ts
|
|
3797
3847
|
var import_ts_pattern10 = require("ts-pattern");
|
|
3798
3848
|
var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
@@ -4391,12 +4441,12 @@ function evalCall(data, expr) {
|
|
|
4391
4441
|
__name(evalCall, "evalCall");
|
|
4392
4442
|
|
|
4393
4443
|
// src/client/crud/validator/index.ts
|
|
4394
|
-
var schemaCache = /* @__PURE__ */ new WeakMap();
|
|
4395
4444
|
var InputValidator = class {
|
|
4396
4445
|
static {
|
|
4397
4446
|
__name(this, "InputValidator");
|
|
4398
4447
|
}
|
|
4399
4448
|
client;
|
|
4449
|
+
schemaCache = /* @__PURE__ */ new Map();
|
|
4400
4450
|
constructor(client) {
|
|
4401
4451
|
this.client = client;
|
|
4402
4452
|
}
|
|
@@ -4493,75 +4543,64 @@ var InputValidator = class {
|
|
|
4493
4543
|
}
|
|
4494
4544
|
return schema;
|
|
4495
4545
|
}
|
|
4496
|
-
validateFindArgs(model, args,
|
|
4497
|
-
return this.validate(model,
|
|
4546
|
+
validateFindArgs(model, args, operation) {
|
|
4547
|
+
return this.validate(model, operation, (model2) => this.makeFindSchema(model2, operation), args);
|
|
4498
4548
|
}
|
|
4499
4549
|
validateExistsArgs(model, args) {
|
|
4500
|
-
return this.validate(model, "exists",
|
|
4550
|
+
return this.validate(model, "exists", (model2) => this.makeExistsSchema(model2), args);
|
|
4501
4551
|
}
|
|
4502
4552
|
validateCreateArgs(model, args) {
|
|
4503
|
-
return this.validate(model, "create",
|
|
4553
|
+
return this.validate(model, "create", (model2) => this.makeCreateSchema(model2), args);
|
|
4504
4554
|
}
|
|
4505
4555
|
validateCreateManyArgs(model, args) {
|
|
4506
|
-
return this.validate(model, "createMany",
|
|
4556
|
+
return this.validate(model, "createMany", (model2) => this.makeCreateManySchema(model2), args);
|
|
4507
4557
|
}
|
|
4508
4558
|
validateCreateManyAndReturnArgs(model, args) {
|
|
4509
|
-
return this.validate(model, "createManyAndReturn",
|
|
4559
|
+
return this.validate(model, "createManyAndReturn", (model2) => this.makeCreateManyAndReturnSchema(model2), args);
|
|
4510
4560
|
}
|
|
4511
4561
|
validateUpdateArgs(model, args) {
|
|
4512
|
-
return this.validate(model, "update",
|
|
4562
|
+
return this.validate(model, "update", (model2) => this.makeUpdateSchema(model2), args);
|
|
4513
4563
|
}
|
|
4514
4564
|
validateUpdateManyArgs(model, args) {
|
|
4515
|
-
return this.validate(model, "updateMany",
|
|
4565
|
+
return this.validate(model, "updateMany", (model2) => this.makeUpdateManySchema(model2), args);
|
|
4516
4566
|
}
|
|
4517
4567
|
validateUpdateManyAndReturnArgs(model, args) {
|
|
4518
|
-
return this.validate(model, "updateManyAndReturn",
|
|
4568
|
+
return this.validate(model, "updateManyAndReturn", (model2) => this.makeUpdateManyAndReturnSchema(model2), args);
|
|
4519
4569
|
}
|
|
4520
4570
|
validateUpsertArgs(model, args) {
|
|
4521
|
-
return this.validate(model, "upsert",
|
|
4571
|
+
return this.validate(model, "upsert", (model2) => this.makeUpsertSchema(model2), args);
|
|
4522
4572
|
}
|
|
4523
4573
|
validateDeleteArgs(model, args) {
|
|
4524
|
-
return this.validate(model, "delete",
|
|
4574
|
+
return this.validate(model, "delete", (model2) => this.makeDeleteSchema(model2), args);
|
|
4525
4575
|
}
|
|
4526
4576
|
validateDeleteManyArgs(model, args) {
|
|
4527
|
-
return this.validate(model, "deleteMany",
|
|
4577
|
+
return this.validate(model, "deleteMany", (model2) => this.makeDeleteManySchema(model2), args);
|
|
4528
4578
|
}
|
|
4529
4579
|
validateCountArgs(model, args) {
|
|
4530
|
-
return this.validate(model, "count",
|
|
4580
|
+
return this.validate(model, "count", (model2) => this.makeCountSchema(model2), args);
|
|
4531
4581
|
}
|
|
4532
4582
|
validateAggregateArgs(model, args) {
|
|
4533
|
-
return this.validate(model, "aggregate",
|
|
4583
|
+
return this.validate(model, "aggregate", (model2) => this.makeAggregateSchema(model2), args);
|
|
4534
4584
|
}
|
|
4535
4585
|
validateGroupByArgs(model, args) {
|
|
4536
|
-
return this.validate(model, "groupBy",
|
|
4586
|
+
return this.validate(model, "groupBy", (model2) => this.makeGroupBySchema(model2), args);
|
|
4537
4587
|
}
|
|
4538
4588
|
getSchemaCache(cacheKey) {
|
|
4539
|
-
|
|
4540
|
-
if (!thisCache) {
|
|
4541
|
-
thisCache = /* @__PURE__ */ new Map();
|
|
4542
|
-
schemaCache.set(this.schema, thisCache);
|
|
4543
|
-
}
|
|
4544
|
-
return thisCache.get(cacheKey);
|
|
4589
|
+
return this.schemaCache.get(cacheKey);
|
|
4545
4590
|
}
|
|
4546
4591
|
setSchemaCache(cacheKey, schema) {
|
|
4547
|
-
|
|
4548
|
-
if (!thisCache) {
|
|
4549
|
-
thisCache = /* @__PURE__ */ new Map();
|
|
4550
|
-
schemaCache.set(this.schema, thisCache);
|
|
4551
|
-
}
|
|
4552
|
-
return thisCache.set(cacheKey, schema);
|
|
4592
|
+
return this.schemaCache.set(cacheKey, schema);
|
|
4553
4593
|
}
|
|
4554
|
-
validate(model, operation,
|
|
4594
|
+
validate(model, operation, getSchema, args) {
|
|
4555
4595
|
const cacheKey = (0, import_json_stable_stringify.default)({
|
|
4556
4596
|
type: "model",
|
|
4557
4597
|
model,
|
|
4558
4598
|
operation,
|
|
4559
|
-
options,
|
|
4560
4599
|
extraValidationsEnabled: this.extraValidationsEnabled
|
|
4561
4600
|
});
|
|
4562
4601
|
let schema = this.getSchemaCache(cacheKey);
|
|
4563
4602
|
if (!schema) {
|
|
4564
|
-
schema = getSchema(model
|
|
4603
|
+
schema = getSchema(model);
|
|
4565
4604
|
this.setSchemaCache(cacheKey, schema);
|
|
4566
4605
|
}
|
|
4567
4606
|
const { error, data } = schema.safeParse(args);
|
|
@@ -4572,11 +4611,25 @@ var InputValidator = class {
|
|
|
4572
4611
|
}
|
|
4573
4612
|
return data;
|
|
4574
4613
|
}
|
|
4614
|
+
mergePluginArgsSchema(schema, operation) {
|
|
4615
|
+
let result = schema;
|
|
4616
|
+
for (const plugin of this.options.plugins ?? []) {
|
|
4617
|
+
if (plugin.extQueryArgs) {
|
|
4618
|
+
const pluginSchema = plugin.extQueryArgs.getValidationSchema(operation);
|
|
4619
|
+
if (pluginSchema) {
|
|
4620
|
+
result = result.extend(pluginSchema.shape);
|
|
4621
|
+
}
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
return result.strict();
|
|
4625
|
+
}
|
|
4575
4626
|
// #region Find
|
|
4576
|
-
makeFindSchema(model,
|
|
4627
|
+
makeFindSchema(model, operation) {
|
|
4577
4628
|
const fields = {};
|
|
4578
|
-
const
|
|
4579
|
-
|
|
4629
|
+
const unique = operation === "findUnique";
|
|
4630
|
+
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
4631
|
+
const where = this.makeWhereSchema(model, unique);
|
|
4632
|
+
if (unique) {
|
|
4580
4633
|
fields["where"] = where;
|
|
4581
4634
|
} else {
|
|
4582
4635
|
fields["where"] = where.optional();
|
|
@@ -4584,9 +4637,9 @@ var InputValidator = class {
|
|
|
4584
4637
|
fields["select"] = this.makeSelectSchema(model).optional().nullable();
|
|
4585
4638
|
fields["include"] = this.makeIncludeSchema(model).optional().nullable();
|
|
4586
4639
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
4587
|
-
if (!
|
|
4640
|
+
if (!unique) {
|
|
4588
4641
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4589
|
-
if (
|
|
4642
|
+
if (findOne) {
|
|
4590
4643
|
fields["take"] = import_zod3.z.literal(1).optional();
|
|
4591
4644
|
} else {
|
|
4592
4645
|
fields["take"] = this.makeTakeSchema().optional();
|
|
@@ -4595,18 +4648,20 @@ var InputValidator = class {
|
|
|
4595
4648
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4596
4649
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4597
4650
|
}
|
|
4598
|
-
|
|
4651
|
+
const baseSchema = import_zod3.z.strictObject(fields);
|
|
4652
|
+
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
4599
4653
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4600
4654
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4601
|
-
if (!
|
|
4655
|
+
if (!unique) {
|
|
4602
4656
|
result = result.optional();
|
|
4603
4657
|
}
|
|
4604
4658
|
return result;
|
|
4605
4659
|
}
|
|
4606
4660
|
makeExistsSchema(model) {
|
|
4607
|
-
|
|
4661
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
4608
4662
|
where: this.makeWhereSchema(model, false).optional()
|
|
4609
|
-
})
|
|
4663
|
+
});
|
|
4664
|
+
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
4610
4665
|
}
|
|
4611
4666
|
makeScalarSchema(type, attributes) {
|
|
4612
4667
|
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
@@ -5174,25 +5229,27 @@ var InputValidator = class {
|
|
|
5174
5229
|
// #region Create
|
|
5175
5230
|
makeCreateSchema(model) {
|
|
5176
5231
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5177
|
-
|
|
5232
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5178
5233
|
data: dataSchema,
|
|
5179
5234
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5180
5235
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5181
5236
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5182
5237
|
});
|
|
5238
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "create");
|
|
5183
5239
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5184
5240
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5185
5241
|
return schema;
|
|
5186
5242
|
}
|
|
5187
5243
|
makeCreateManySchema(model) {
|
|
5188
|
-
return this.makeCreateManyDataSchema(model, []).optional();
|
|
5244
|
+
return this.mergePluginArgsSchema(this.makeCreateManyDataSchema(model, []), "createMany").optional();
|
|
5189
5245
|
}
|
|
5190
5246
|
makeCreateManyAndReturnSchema(model) {
|
|
5191
5247
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
5192
|
-
|
|
5248
|
+
let result = base.extend({
|
|
5193
5249
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5194
5250
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5195
5251
|
});
|
|
5252
|
+
result = this.mergePluginArgsSchema(result, "createManyAndReturn");
|
|
5196
5253
|
return this.refineForSelectOmitMutuallyExclusive(result).optional();
|
|
5197
5254
|
}
|
|
5198
5255
|
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5385,27 +5442,28 @@ var InputValidator = class {
|
|
|
5385
5442
|
// #endregion
|
|
5386
5443
|
// #region Update
|
|
5387
5444
|
makeUpdateSchema(model) {
|
|
5388
|
-
|
|
5445
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5389
5446
|
where: this.makeWhereSchema(model, true),
|
|
5390
5447
|
data: this.makeUpdateDataSchema(model),
|
|
5391
5448
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5392
5449
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5393
5450
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5394
5451
|
});
|
|
5452
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "update");
|
|
5395
5453
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5396
5454
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5397
5455
|
return schema;
|
|
5398
5456
|
}
|
|
5399
5457
|
makeUpdateManySchema(model) {
|
|
5400
|
-
return import_zod3.z.strictObject({
|
|
5458
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5401
5459
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5402
5460
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5403
5461
|
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
5404
|
-
});
|
|
5462
|
+
}), "updateMany");
|
|
5405
5463
|
}
|
|
5406
5464
|
makeUpdateManyAndReturnSchema(model) {
|
|
5407
|
-
const
|
|
5408
|
-
let schema =
|
|
5465
|
+
const baseSchema = this.makeUpdateManySchema(model);
|
|
5466
|
+
let schema = baseSchema.extend({
|
|
5409
5467
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5410
5468
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5411
5469
|
});
|
|
@@ -5413,7 +5471,7 @@ var InputValidator = class {
|
|
|
5413
5471
|
return schema;
|
|
5414
5472
|
}
|
|
5415
5473
|
makeUpsertSchema(model) {
|
|
5416
|
-
|
|
5474
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5417
5475
|
where: this.makeWhereSchema(model, true),
|
|
5418
5476
|
create: this.makeCreateDataSchema(model, false),
|
|
5419
5477
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -5421,6 +5479,7 @@ var InputValidator = class {
|
|
|
5421
5479
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5422
5480
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5423
5481
|
});
|
|
5482
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "upsert");
|
|
5424
5483
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5425
5484
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5426
5485
|
return schema;
|
|
@@ -5514,32 +5573,33 @@ var InputValidator = class {
|
|
|
5514
5573
|
// #endregion
|
|
5515
5574
|
// #region Delete
|
|
5516
5575
|
makeDeleteSchema(model) {
|
|
5517
|
-
|
|
5576
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5518
5577
|
where: this.makeWhereSchema(model, true),
|
|
5519
5578
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5520
5579
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5521
5580
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5522
5581
|
});
|
|
5582
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "delete");
|
|
5523
5583
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5524
5584
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5525
5585
|
return schema;
|
|
5526
5586
|
}
|
|
5527
5587
|
makeDeleteManySchema(model) {
|
|
5528
|
-
return import_zod3.z.
|
|
5588
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5529
5589
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5530
5590
|
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
5531
|
-
}).optional();
|
|
5591
|
+
}), "deleteMany").optional();
|
|
5532
5592
|
}
|
|
5533
5593
|
// #endregion
|
|
5534
5594
|
// #region Count
|
|
5535
5595
|
makeCountSchema(model) {
|
|
5536
|
-
return import_zod3.z.
|
|
5596
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5537
5597
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5538
5598
|
skip: this.makeSkipSchema().optional(),
|
|
5539
5599
|
take: this.makeTakeSchema().optional(),
|
|
5540
5600
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5541
5601
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
5542
|
-
}).optional();
|
|
5602
|
+
}), "count").optional();
|
|
5543
5603
|
}
|
|
5544
5604
|
makeCountAggregateInputSchema(model) {
|
|
5545
5605
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5557,7 +5617,7 @@ var InputValidator = class {
|
|
|
5557
5617
|
// #endregion
|
|
5558
5618
|
// #region Aggregate
|
|
5559
5619
|
makeAggregateSchema(model) {
|
|
5560
|
-
return import_zod3.z.
|
|
5620
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5561
5621
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5562
5622
|
skip: this.makeSkipSchema().optional(),
|
|
5563
5623
|
take: this.makeTakeSchema().optional(),
|
|
@@ -5567,7 +5627,7 @@ var InputValidator = class {
|
|
|
5567
5627
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5568
5628
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5569
5629
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5570
|
-
}).optional();
|
|
5630
|
+
}), "aggregate").optional();
|
|
5571
5631
|
}
|
|
5572
5632
|
makeSumAvgInputSchema(model) {
|
|
5573
5633
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5593,7 +5653,7 @@ var InputValidator = class {
|
|
|
5593
5653
|
const modelDef = requireModel(this.schema, model);
|
|
5594
5654
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5595
5655
|
const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod3.z.enum(nonRelationFields), true) : import_zod3.z.never();
|
|
5596
|
-
|
|
5656
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5597
5657
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5598
5658
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5599
5659
|
by: bySchema,
|
|
@@ -5606,6 +5666,7 @@ var InputValidator = class {
|
|
|
5606
5666
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5607
5667
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5608
5668
|
});
|
|
5669
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
|
|
5609
5670
|
schema = schema.refine((value) => {
|
|
5610
5671
|
const bys = typeof value.by === "string" ? [
|
|
5611
5672
|
value.by
|
|
@@ -7296,6 +7357,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7296
7357
|
$schema;
|
|
7297
7358
|
kyselyProps;
|
|
7298
7359
|
auth;
|
|
7360
|
+
inputValidator;
|
|
7299
7361
|
constructor(schema, options, baseClient, executor) {
|
|
7300
7362
|
this.schema = schema;
|
|
7301
7363
|
this.options = options;
|
|
@@ -7332,6 +7394,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7332
7394
|
});
|
|
7333
7395
|
}
|
|
7334
7396
|
this.kysely = new import_kysely10.Kysely(this.kyselyProps);
|
|
7397
|
+
this.inputValidator = baseClient?.inputValidator ?? new InputValidator(this);
|
|
7335
7398
|
return createClientProxy(this);
|
|
7336
7399
|
}
|
|
7337
7400
|
get $qb() {
|
|
@@ -7416,8 +7479,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7416
7479
|
if (!procOptions[name] || typeof procOptions[name] !== "function") {
|
|
7417
7480
|
throw createConfigError(`Procedure "${name}" does not have a handler configured.`);
|
|
7418
7481
|
}
|
|
7419
|
-
const
|
|
7420
|
-
const validatedInput = inputValidator.validateProcedureInput(name, input);
|
|
7482
|
+
const validatedInput = this.inputValidator.validateProcedureInput(name, input);
|
|
7421
7483
|
const handler = procOptions[name];
|
|
7422
7484
|
const invokeWithClient = /* @__PURE__ */ __name(async (client, _input) => {
|
|
7423
7485
|
let proceed = /* @__PURE__ */ __name(async (nextInput) => {
|
|
@@ -7467,7 +7529,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
7467
7529
|
...this.options,
|
|
7468
7530
|
plugins: newPlugins
|
|
7469
7531
|
};
|
|
7470
|
-
|
|
7532
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7533
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7534
|
+
return newClient;
|
|
7471
7535
|
}
|
|
7472
7536
|
$unuse(pluginId) {
|
|
7473
7537
|
const newPlugins = [];
|
|
@@ -7480,14 +7544,18 @@ var ClientImpl = class _ClientImpl {
|
|
|
7480
7544
|
...this.options,
|
|
7481
7545
|
plugins: newPlugins
|
|
7482
7546
|
};
|
|
7483
|
-
|
|
7547
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7548
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7549
|
+
return newClient;
|
|
7484
7550
|
}
|
|
7485
7551
|
$unuseAll() {
|
|
7486
7552
|
const newOptions = {
|
|
7487
7553
|
...this.options,
|
|
7488
7554
|
plugins: []
|
|
7489
7555
|
};
|
|
7490
|
-
|
|
7556
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7557
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7558
|
+
return newClient;
|
|
7491
7559
|
}
|
|
7492
7560
|
$setAuth(auth) {
|
|
7493
7561
|
if (auth !== void 0 && typeof auth !== "object") {
|
|
@@ -7501,14 +7569,16 @@ var ClientImpl = class _ClientImpl {
|
|
|
7501
7569
|
return this.auth;
|
|
7502
7570
|
}
|
|
7503
7571
|
$setOptions(options) {
|
|
7504
|
-
|
|
7572
|
+
const newClient = new _ClientImpl(this.schema, options, this);
|
|
7573
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7574
|
+
return newClient;
|
|
7505
7575
|
}
|
|
7506
7576
|
$setInputValidation(enable) {
|
|
7507
7577
|
const newOptions = {
|
|
7508
7578
|
...this.options,
|
|
7509
7579
|
validateInput: enable
|
|
7510
7580
|
};
|
|
7511
|
-
return
|
|
7581
|
+
return this.$setOptions(newOptions);
|
|
7512
7582
|
}
|
|
7513
7583
|
$executeRaw(query, ...values) {
|
|
7514
7584
|
return createZenStackPromise(async () => {
|
|
@@ -7545,7 +7615,6 @@ var ClientImpl = class _ClientImpl {
|
|
|
7545
7615
|
}
|
|
7546
7616
|
};
|
|
7547
7617
|
function createClientProxy(client) {
|
|
7548
|
-
const inputValidator = new InputValidator(client);
|
|
7549
7618
|
const resultProcessor = new ResultProcessor(client.$schema, client.$options);
|
|
7550
7619
|
return new Proxy(client, {
|
|
7551
7620
|
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
@@ -7555,7 +7624,7 @@ function createClientProxy(client) {
|
|
|
7555
7624
|
if (typeof prop === "string") {
|
|
7556
7625
|
const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
|
|
7557
7626
|
if (model) {
|
|
7558
|
-
return createModelCrudHandler(client, model, inputValidator, resultProcessor);
|
|
7627
|
+
return createModelCrudHandler(client, model, client.inputValidator, resultProcessor);
|
|
7559
7628
|
}
|
|
7560
7629
|
}
|
|
7561
7630
|
return Reflect.get(target, prop, receiver);
|
|
@@ -7587,15 +7656,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
7587
7656
|
const onQuery = plugin.onQuery;
|
|
7588
7657
|
if (onQuery) {
|
|
7589
7658
|
const _proceed = proceed;
|
|
7590
|
-
proceed = /* @__PURE__ */ __name((_args) =>
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7659
|
+
proceed = /* @__PURE__ */ __name((_args) => {
|
|
7660
|
+
const ctx = {
|
|
7661
|
+
client,
|
|
7662
|
+
model,
|
|
7663
|
+
operation: nominalOperation,
|
|
7664
|
+
// reflect the latest override if provided
|
|
7665
|
+
args: _args,
|
|
7666
|
+
// ensure inner overrides are propagated to the previous proceed
|
|
7667
|
+
proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
|
|
7668
|
+
};
|
|
7669
|
+
return onQuery(ctx);
|
|
7670
|
+
}, "proceed");
|
|
7599
7671
|
}
|
|
7600
7672
|
}
|
|
7601
7673
|
return proceed(args);
|
|
@@ -7615,7 +7687,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
7615
7687
|
return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
7616
7688
|
}, "findFirstOrThrow"),
|
|
7617
7689
|
findMany: /* @__PURE__ */ __name((args) => {
|
|
7618
|
-
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
7690
|
+
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true, false);
|
|
7619
7691
|
}, "findMany"),
|
|
7620
7692
|
create: /* @__PURE__ */ __name((args) => {
|
|
7621
7693
|
return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
@@ -8080,11 +8152,16 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
8080
8152
|
};
|
|
8081
8153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8082
8154
|
0 && (module.exports = {
|
|
8155
|
+
AllCrudOperations,
|
|
8156
|
+
AllReadOperations,
|
|
8083
8157
|
AnyNull,
|
|
8084
8158
|
AnyNullClass,
|
|
8085
8159
|
BaseCrudDialect,
|
|
8086
8160
|
CRUD,
|
|
8087
8161
|
CRUD_EXT,
|
|
8162
|
+
CoreCrudOperations,
|
|
8163
|
+
CoreReadOperations,
|
|
8164
|
+
CoreWriteOperations,
|
|
8088
8165
|
DbNull,
|
|
8089
8166
|
DbNullClass,
|
|
8090
8167
|
InputValidator,
|