@zenstackhq/orm 3.2.0 → 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 +170 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +916 -879
- package/dist/index.d.ts +916 -879
- package/dist/index.js +165 -93
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -2070,6 +2070,54 @@ function getCrudDialect(schema, options) {
|
|
|
2070
2070
|
__name(getCrudDialect, "getCrudDialect");
|
|
2071
2071
|
|
|
2072
2072
|
// src/client/crud/operations/base.ts
|
|
2073
|
+
var CoreCrudOperations = [
|
|
2074
|
+
"findMany",
|
|
2075
|
+
"findUnique",
|
|
2076
|
+
"findFirst",
|
|
2077
|
+
"create",
|
|
2078
|
+
"createMany",
|
|
2079
|
+
"createManyAndReturn",
|
|
2080
|
+
"update",
|
|
2081
|
+
"updateMany",
|
|
2082
|
+
"updateManyAndReturn",
|
|
2083
|
+
"upsert",
|
|
2084
|
+
"delete",
|
|
2085
|
+
"deleteMany",
|
|
2086
|
+
"count",
|
|
2087
|
+
"aggregate",
|
|
2088
|
+
"groupBy",
|
|
2089
|
+
"exists"
|
|
2090
|
+
];
|
|
2091
|
+
var CoreReadOperations = [
|
|
2092
|
+
"findMany",
|
|
2093
|
+
"findUnique",
|
|
2094
|
+
"findFirst",
|
|
2095
|
+
"count",
|
|
2096
|
+
"aggregate",
|
|
2097
|
+
"groupBy",
|
|
2098
|
+
"exists"
|
|
2099
|
+
];
|
|
2100
|
+
var CoreWriteOperations = [
|
|
2101
|
+
"create",
|
|
2102
|
+
"createMany",
|
|
2103
|
+
"createManyAndReturn",
|
|
2104
|
+
"update",
|
|
2105
|
+
"updateMany",
|
|
2106
|
+
"updateManyAndReturn",
|
|
2107
|
+
"upsert",
|
|
2108
|
+
"delete",
|
|
2109
|
+
"deleteMany"
|
|
2110
|
+
];
|
|
2111
|
+
var AllCrudOperations = [
|
|
2112
|
+
...CoreCrudOperations,
|
|
2113
|
+
"findUniqueOrThrow",
|
|
2114
|
+
"findFirstOrThrow"
|
|
2115
|
+
];
|
|
2116
|
+
var AllReadOperations = [
|
|
2117
|
+
...CoreReadOperations,
|
|
2118
|
+
"findUniqueOrThrow",
|
|
2119
|
+
"findFirstOrThrow"
|
|
2120
|
+
];
|
|
2073
2121
|
var BaseOperationHandler = class {
|
|
2074
2122
|
static {
|
|
2075
2123
|
__name(this, "BaseOperationHandler");
|
|
@@ -3722,6 +3770,18 @@ var DeleteOperationHandler = class extends BaseOperationHandler {
|
|
|
3722
3770
|
}
|
|
3723
3771
|
};
|
|
3724
3772
|
|
|
3773
|
+
// src/client/crud/operations/exists.ts
|
|
3774
|
+
var ExistsOperationHandler = class extends BaseOperationHandler {
|
|
3775
|
+
static {
|
|
3776
|
+
__name(this, "ExistsOperationHandler");
|
|
3777
|
+
}
|
|
3778
|
+
async handle(_operation, args) {
|
|
3779
|
+
const normalizedArgs = this.normalizeArgs(args);
|
|
3780
|
+
const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
|
|
3781
|
+
return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
|
|
3782
|
+
}
|
|
3783
|
+
};
|
|
3784
|
+
|
|
3725
3785
|
// src/client/crud/operations/find.ts
|
|
3726
3786
|
var FindOperationHandler = class extends BaseOperationHandler {
|
|
3727
3787
|
static {
|
|
@@ -3730,10 +3790,7 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
3730
3790
|
async handle(operation, args, validateArgs = true) {
|
|
3731
3791
|
const normalizedArgs = this.normalizeArgs(args);
|
|
3732
3792
|
const findOne = operation === "findFirst" || operation === "findUnique";
|
|
3733
|
-
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs,
|
|
3734
|
-
unique: operation === "findUnique",
|
|
3735
|
-
findOne
|
|
3736
|
-
}) : normalizedArgs;
|
|
3793
|
+
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, operation) : normalizedArgs;
|
|
3737
3794
|
if (findOne) {
|
|
3738
3795
|
parsedArgs = parsedArgs ?? {};
|
|
3739
3796
|
parsedArgs.take = 1;
|
|
@@ -3744,18 +3801,6 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
3744
3801
|
}
|
|
3745
3802
|
};
|
|
3746
3803
|
|
|
3747
|
-
// src/client/crud/operations/exists.ts
|
|
3748
|
-
var ExistsOperationHandler = class extends BaseOperationHandler {
|
|
3749
|
-
static {
|
|
3750
|
-
__name(this, "ExistsOperationHandler");
|
|
3751
|
-
}
|
|
3752
|
-
async handle(_operation, args) {
|
|
3753
|
-
const normalizedArgs = this.normalizeArgs(args);
|
|
3754
|
-
const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
|
|
3755
|
-
return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
|
|
3756
|
-
}
|
|
3757
|
-
};
|
|
3758
|
-
|
|
3759
3804
|
// src/client/crud/operations/group-by.ts
|
|
3760
3805
|
import { match as match10 } from "ts-pattern";
|
|
3761
3806
|
var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
@@ -3874,7 +3919,7 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
3874
3919
|
const result = await this.safeTransaction(async (tx) => {
|
|
3875
3920
|
const updateResult = await this.update(tx, this.model, args.where, args.data, void 0, void 0, void 0, selectedFields);
|
|
3876
3921
|
if (needReadBack) {
|
|
3877
|
-
const readFilter = updateResult
|
|
3922
|
+
const readFilter = updateResult ? getIdValues(this.schema, this.model, updateResult) : args.where;
|
|
3878
3923
|
let readBackResult = void 0;
|
|
3879
3924
|
readBackResult = await this.readUnique(tx, this.model, {
|
|
3880
3925
|
select: args.select,
|
|
@@ -4354,12 +4399,12 @@ function evalCall(data, expr) {
|
|
|
4354
4399
|
__name(evalCall, "evalCall");
|
|
4355
4400
|
|
|
4356
4401
|
// src/client/crud/validator/index.ts
|
|
4357
|
-
var schemaCache = /* @__PURE__ */ new WeakMap();
|
|
4358
4402
|
var InputValidator = class {
|
|
4359
4403
|
static {
|
|
4360
4404
|
__name(this, "InputValidator");
|
|
4361
4405
|
}
|
|
4362
4406
|
client;
|
|
4407
|
+
schemaCache = /* @__PURE__ */ new Map();
|
|
4363
4408
|
constructor(client) {
|
|
4364
4409
|
this.client = client;
|
|
4365
4410
|
}
|
|
@@ -4456,75 +4501,64 @@ var InputValidator = class {
|
|
|
4456
4501
|
}
|
|
4457
4502
|
return schema;
|
|
4458
4503
|
}
|
|
4459
|
-
validateFindArgs(model, args,
|
|
4460
|
-
return this.validate(model,
|
|
4504
|
+
validateFindArgs(model, args, operation) {
|
|
4505
|
+
return this.validate(model, operation, (model2) => this.makeFindSchema(model2, operation), args);
|
|
4461
4506
|
}
|
|
4462
4507
|
validateExistsArgs(model, args) {
|
|
4463
|
-
return this.validate(model, "exists",
|
|
4508
|
+
return this.validate(model, "exists", (model2) => this.makeExistsSchema(model2), args);
|
|
4464
4509
|
}
|
|
4465
4510
|
validateCreateArgs(model, args) {
|
|
4466
|
-
return this.validate(model, "create",
|
|
4511
|
+
return this.validate(model, "create", (model2) => this.makeCreateSchema(model2), args);
|
|
4467
4512
|
}
|
|
4468
4513
|
validateCreateManyArgs(model, args) {
|
|
4469
|
-
return this.validate(model, "createMany",
|
|
4514
|
+
return this.validate(model, "createMany", (model2) => this.makeCreateManySchema(model2), args);
|
|
4470
4515
|
}
|
|
4471
4516
|
validateCreateManyAndReturnArgs(model, args) {
|
|
4472
|
-
return this.validate(model, "createManyAndReturn",
|
|
4517
|
+
return this.validate(model, "createManyAndReturn", (model2) => this.makeCreateManyAndReturnSchema(model2), args);
|
|
4473
4518
|
}
|
|
4474
4519
|
validateUpdateArgs(model, args) {
|
|
4475
|
-
return this.validate(model, "update",
|
|
4520
|
+
return this.validate(model, "update", (model2) => this.makeUpdateSchema(model2), args);
|
|
4476
4521
|
}
|
|
4477
4522
|
validateUpdateManyArgs(model, args) {
|
|
4478
|
-
return this.validate(model, "updateMany",
|
|
4523
|
+
return this.validate(model, "updateMany", (model2) => this.makeUpdateManySchema(model2), args);
|
|
4479
4524
|
}
|
|
4480
4525
|
validateUpdateManyAndReturnArgs(model, args) {
|
|
4481
|
-
return this.validate(model, "updateManyAndReturn",
|
|
4526
|
+
return this.validate(model, "updateManyAndReturn", (model2) => this.makeUpdateManyAndReturnSchema(model2), args);
|
|
4482
4527
|
}
|
|
4483
4528
|
validateUpsertArgs(model, args) {
|
|
4484
|
-
return this.validate(model, "upsert",
|
|
4529
|
+
return this.validate(model, "upsert", (model2) => this.makeUpsertSchema(model2), args);
|
|
4485
4530
|
}
|
|
4486
4531
|
validateDeleteArgs(model, args) {
|
|
4487
|
-
return this.validate(model, "delete",
|
|
4532
|
+
return this.validate(model, "delete", (model2) => this.makeDeleteSchema(model2), args);
|
|
4488
4533
|
}
|
|
4489
4534
|
validateDeleteManyArgs(model, args) {
|
|
4490
|
-
return this.validate(model, "deleteMany",
|
|
4535
|
+
return this.validate(model, "deleteMany", (model2) => this.makeDeleteManySchema(model2), args);
|
|
4491
4536
|
}
|
|
4492
4537
|
validateCountArgs(model, args) {
|
|
4493
|
-
return this.validate(model, "count",
|
|
4538
|
+
return this.validate(model, "count", (model2) => this.makeCountSchema(model2), args);
|
|
4494
4539
|
}
|
|
4495
4540
|
validateAggregateArgs(model, args) {
|
|
4496
|
-
return this.validate(model, "aggregate",
|
|
4541
|
+
return this.validate(model, "aggregate", (model2) => this.makeAggregateSchema(model2), args);
|
|
4497
4542
|
}
|
|
4498
4543
|
validateGroupByArgs(model, args) {
|
|
4499
|
-
return this.validate(model, "groupBy",
|
|
4544
|
+
return this.validate(model, "groupBy", (model2) => this.makeGroupBySchema(model2), args);
|
|
4500
4545
|
}
|
|
4501
4546
|
getSchemaCache(cacheKey) {
|
|
4502
|
-
|
|
4503
|
-
if (!thisCache) {
|
|
4504
|
-
thisCache = /* @__PURE__ */ new Map();
|
|
4505
|
-
schemaCache.set(this.schema, thisCache);
|
|
4506
|
-
}
|
|
4507
|
-
return thisCache.get(cacheKey);
|
|
4547
|
+
return this.schemaCache.get(cacheKey);
|
|
4508
4548
|
}
|
|
4509
4549
|
setSchemaCache(cacheKey, schema) {
|
|
4510
|
-
|
|
4511
|
-
if (!thisCache) {
|
|
4512
|
-
thisCache = /* @__PURE__ */ new Map();
|
|
4513
|
-
schemaCache.set(this.schema, thisCache);
|
|
4514
|
-
}
|
|
4515
|
-
return thisCache.set(cacheKey, schema);
|
|
4550
|
+
return this.schemaCache.set(cacheKey, schema);
|
|
4516
4551
|
}
|
|
4517
|
-
validate(model, operation,
|
|
4552
|
+
validate(model, operation, getSchema, args) {
|
|
4518
4553
|
const cacheKey = stableStringify({
|
|
4519
4554
|
type: "model",
|
|
4520
4555
|
model,
|
|
4521
4556
|
operation,
|
|
4522
|
-
options,
|
|
4523
4557
|
extraValidationsEnabled: this.extraValidationsEnabled
|
|
4524
4558
|
});
|
|
4525
4559
|
let schema = this.getSchemaCache(cacheKey);
|
|
4526
4560
|
if (!schema) {
|
|
4527
|
-
schema = getSchema(model
|
|
4561
|
+
schema = getSchema(model);
|
|
4528
4562
|
this.setSchemaCache(cacheKey, schema);
|
|
4529
4563
|
}
|
|
4530
4564
|
const { error, data } = schema.safeParse(args);
|
|
@@ -4535,11 +4569,25 @@ var InputValidator = class {
|
|
|
4535
4569
|
}
|
|
4536
4570
|
return data;
|
|
4537
4571
|
}
|
|
4572
|
+
mergePluginArgsSchema(schema, operation) {
|
|
4573
|
+
let result = schema;
|
|
4574
|
+
for (const plugin of this.options.plugins ?? []) {
|
|
4575
|
+
if (plugin.extQueryArgs) {
|
|
4576
|
+
const pluginSchema = plugin.extQueryArgs.getValidationSchema(operation);
|
|
4577
|
+
if (pluginSchema) {
|
|
4578
|
+
result = result.extend(pluginSchema.shape);
|
|
4579
|
+
}
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
return result.strict();
|
|
4583
|
+
}
|
|
4538
4584
|
// #region Find
|
|
4539
|
-
makeFindSchema(model,
|
|
4585
|
+
makeFindSchema(model, operation) {
|
|
4540
4586
|
const fields = {};
|
|
4541
|
-
const
|
|
4542
|
-
|
|
4587
|
+
const unique = operation === "findUnique";
|
|
4588
|
+
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
4589
|
+
const where = this.makeWhereSchema(model, unique);
|
|
4590
|
+
if (unique) {
|
|
4543
4591
|
fields["where"] = where;
|
|
4544
4592
|
} else {
|
|
4545
4593
|
fields["where"] = where.optional();
|
|
@@ -4547,9 +4595,9 @@ var InputValidator = class {
|
|
|
4547
4595
|
fields["select"] = this.makeSelectSchema(model).optional().nullable();
|
|
4548
4596
|
fields["include"] = this.makeIncludeSchema(model).optional().nullable();
|
|
4549
4597
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
4550
|
-
if (!
|
|
4598
|
+
if (!unique) {
|
|
4551
4599
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4552
|
-
if (
|
|
4600
|
+
if (findOne) {
|
|
4553
4601
|
fields["take"] = z3.literal(1).optional();
|
|
4554
4602
|
} else {
|
|
4555
4603
|
fields["take"] = this.makeTakeSchema().optional();
|
|
@@ -4558,18 +4606,20 @@ var InputValidator = class {
|
|
|
4558
4606
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4559
4607
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4560
4608
|
}
|
|
4561
|
-
|
|
4609
|
+
const baseSchema = z3.strictObject(fields);
|
|
4610
|
+
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
4562
4611
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4563
4612
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4564
|
-
if (!
|
|
4613
|
+
if (!unique) {
|
|
4565
4614
|
result = result.optional();
|
|
4566
4615
|
}
|
|
4567
4616
|
return result;
|
|
4568
4617
|
}
|
|
4569
4618
|
makeExistsSchema(model) {
|
|
4570
|
-
|
|
4619
|
+
const baseSchema = z3.strictObject({
|
|
4571
4620
|
where: this.makeWhereSchema(model, false).optional()
|
|
4572
|
-
})
|
|
4621
|
+
});
|
|
4622
|
+
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
4573
4623
|
}
|
|
4574
4624
|
makeScalarSchema(type, attributes) {
|
|
4575
4625
|
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
@@ -5137,25 +5187,27 @@ var InputValidator = class {
|
|
|
5137
5187
|
// #region Create
|
|
5138
5188
|
makeCreateSchema(model) {
|
|
5139
5189
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5140
|
-
|
|
5190
|
+
const baseSchema = z3.strictObject({
|
|
5141
5191
|
data: dataSchema,
|
|
5142
5192
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5143
5193
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5144
5194
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5145
5195
|
});
|
|
5196
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "create");
|
|
5146
5197
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5147
5198
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5148
5199
|
return schema;
|
|
5149
5200
|
}
|
|
5150
5201
|
makeCreateManySchema(model) {
|
|
5151
|
-
return this.makeCreateManyDataSchema(model, []).optional();
|
|
5202
|
+
return this.mergePluginArgsSchema(this.makeCreateManyDataSchema(model, []), "createMany").optional();
|
|
5152
5203
|
}
|
|
5153
5204
|
makeCreateManyAndReturnSchema(model) {
|
|
5154
5205
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
5155
|
-
|
|
5206
|
+
let result = base.extend({
|
|
5156
5207
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5157
5208
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5158
5209
|
});
|
|
5210
|
+
result = this.mergePluginArgsSchema(result, "createManyAndReturn");
|
|
5159
5211
|
return this.refineForSelectOmitMutuallyExclusive(result).optional();
|
|
5160
5212
|
}
|
|
5161
5213
|
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5348,27 +5400,28 @@ var InputValidator = class {
|
|
|
5348
5400
|
// #endregion
|
|
5349
5401
|
// #region Update
|
|
5350
5402
|
makeUpdateSchema(model) {
|
|
5351
|
-
|
|
5403
|
+
const baseSchema = z3.strictObject({
|
|
5352
5404
|
where: this.makeWhereSchema(model, true),
|
|
5353
5405
|
data: this.makeUpdateDataSchema(model),
|
|
5354
5406
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5355
5407
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5356
5408
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5357
5409
|
});
|
|
5410
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "update");
|
|
5358
5411
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5359
5412
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5360
5413
|
return schema;
|
|
5361
5414
|
}
|
|
5362
5415
|
makeUpdateManySchema(model) {
|
|
5363
|
-
return z3.strictObject({
|
|
5416
|
+
return this.mergePluginArgsSchema(z3.strictObject({
|
|
5364
5417
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5365
5418
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5366
5419
|
limit: z3.number().int().nonnegative().optional()
|
|
5367
|
-
});
|
|
5420
|
+
}), "updateMany");
|
|
5368
5421
|
}
|
|
5369
5422
|
makeUpdateManyAndReturnSchema(model) {
|
|
5370
|
-
const
|
|
5371
|
-
let schema =
|
|
5423
|
+
const baseSchema = this.makeUpdateManySchema(model);
|
|
5424
|
+
let schema = baseSchema.extend({
|
|
5372
5425
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5373
5426
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5374
5427
|
});
|
|
@@ -5376,7 +5429,7 @@ var InputValidator = class {
|
|
|
5376
5429
|
return schema;
|
|
5377
5430
|
}
|
|
5378
5431
|
makeUpsertSchema(model) {
|
|
5379
|
-
|
|
5432
|
+
const baseSchema = z3.strictObject({
|
|
5380
5433
|
where: this.makeWhereSchema(model, true),
|
|
5381
5434
|
create: this.makeCreateDataSchema(model, false),
|
|
5382
5435
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -5384,6 +5437,7 @@ var InputValidator = class {
|
|
|
5384
5437
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5385
5438
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5386
5439
|
});
|
|
5440
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "upsert");
|
|
5387
5441
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5388
5442
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5389
5443
|
return schema;
|
|
@@ -5477,32 +5531,33 @@ var InputValidator = class {
|
|
|
5477
5531
|
// #endregion
|
|
5478
5532
|
// #region Delete
|
|
5479
5533
|
makeDeleteSchema(model) {
|
|
5480
|
-
|
|
5534
|
+
const baseSchema = z3.strictObject({
|
|
5481
5535
|
where: this.makeWhereSchema(model, true),
|
|
5482
5536
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5483
5537
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5484
5538
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5485
5539
|
});
|
|
5540
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "delete");
|
|
5486
5541
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5487
5542
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5488
5543
|
return schema;
|
|
5489
5544
|
}
|
|
5490
5545
|
makeDeleteManySchema(model) {
|
|
5491
|
-
return z3.
|
|
5546
|
+
return this.mergePluginArgsSchema(z3.strictObject({
|
|
5492
5547
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5493
5548
|
limit: z3.number().int().nonnegative().optional()
|
|
5494
|
-
}).optional();
|
|
5549
|
+
}), "deleteMany").optional();
|
|
5495
5550
|
}
|
|
5496
5551
|
// #endregion
|
|
5497
5552
|
// #region Count
|
|
5498
5553
|
makeCountSchema(model) {
|
|
5499
|
-
return z3.
|
|
5554
|
+
return this.mergePluginArgsSchema(z3.strictObject({
|
|
5500
5555
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5501
5556
|
skip: this.makeSkipSchema().optional(),
|
|
5502
5557
|
take: this.makeTakeSchema().optional(),
|
|
5503
5558
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5504
5559
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
5505
|
-
}).optional();
|
|
5560
|
+
}), "count").optional();
|
|
5506
5561
|
}
|
|
5507
5562
|
makeCountAggregateInputSchema(model) {
|
|
5508
5563
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5520,7 +5575,7 @@ var InputValidator = class {
|
|
|
5520
5575
|
// #endregion
|
|
5521
5576
|
// #region Aggregate
|
|
5522
5577
|
makeAggregateSchema(model) {
|
|
5523
|
-
return z3.
|
|
5578
|
+
return this.mergePluginArgsSchema(z3.strictObject({
|
|
5524
5579
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5525
5580
|
skip: this.makeSkipSchema().optional(),
|
|
5526
5581
|
take: this.makeTakeSchema().optional(),
|
|
@@ -5530,7 +5585,7 @@ var InputValidator = class {
|
|
|
5530
5585
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5531
5586
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5532
5587
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5533
|
-
}).optional();
|
|
5588
|
+
}), "aggregate").optional();
|
|
5534
5589
|
}
|
|
5535
5590
|
makeSumAvgInputSchema(model) {
|
|
5536
5591
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5556,7 +5611,7 @@ var InputValidator = class {
|
|
|
5556
5611
|
const modelDef = requireModel(this.schema, model);
|
|
5557
5612
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5558
5613
|
const bySchema = nonRelationFields.length > 0 ? this.orArray(z3.enum(nonRelationFields), true) : z3.never();
|
|
5559
|
-
|
|
5614
|
+
const baseSchema = z3.strictObject({
|
|
5560
5615
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5561
5616
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5562
5617
|
by: bySchema,
|
|
@@ -5569,6 +5624,7 @@ var InputValidator = class {
|
|
|
5569
5624
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5570
5625
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5571
5626
|
});
|
|
5627
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
|
|
5572
5628
|
schema = schema.refine((value) => {
|
|
5573
5629
|
const bys = typeof value.by === "string" ? [
|
|
5574
5630
|
value.by
|
|
@@ -7259,6 +7315,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7259
7315
|
$schema;
|
|
7260
7316
|
kyselyProps;
|
|
7261
7317
|
auth;
|
|
7318
|
+
inputValidator;
|
|
7262
7319
|
constructor(schema, options, baseClient, executor) {
|
|
7263
7320
|
this.schema = schema;
|
|
7264
7321
|
this.options = options;
|
|
@@ -7295,6 +7352,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7295
7352
|
});
|
|
7296
7353
|
}
|
|
7297
7354
|
this.kysely = new Kysely(this.kyselyProps);
|
|
7355
|
+
this.inputValidator = baseClient?.inputValidator ?? new InputValidator(this);
|
|
7298
7356
|
return createClientProxy(this);
|
|
7299
7357
|
}
|
|
7300
7358
|
get $qb() {
|
|
@@ -7379,8 +7437,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7379
7437
|
if (!procOptions[name] || typeof procOptions[name] !== "function") {
|
|
7380
7438
|
throw createConfigError(`Procedure "${name}" does not have a handler configured.`);
|
|
7381
7439
|
}
|
|
7382
|
-
const
|
|
7383
|
-
const validatedInput = inputValidator.validateProcedureInput(name, input);
|
|
7440
|
+
const validatedInput = this.inputValidator.validateProcedureInput(name, input);
|
|
7384
7441
|
const handler = procOptions[name];
|
|
7385
7442
|
const invokeWithClient = /* @__PURE__ */ __name(async (client, _input) => {
|
|
7386
7443
|
let proceed = /* @__PURE__ */ __name(async (nextInput) => {
|
|
@@ -7430,7 +7487,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
7430
7487
|
...this.options,
|
|
7431
7488
|
plugins: newPlugins
|
|
7432
7489
|
};
|
|
7433
|
-
|
|
7490
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7491
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7492
|
+
return newClient;
|
|
7434
7493
|
}
|
|
7435
7494
|
$unuse(pluginId) {
|
|
7436
7495
|
const newPlugins = [];
|
|
@@ -7443,14 +7502,18 @@ var ClientImpl = class _ClientImpl {
|
|
|
7443
7502
|
...this.options,
|
|
7444
7503
|
plugins: newPlugins
|
|
7445
7504
|
};
|
|
7446
|
-
|
|
7505
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7506
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7507
|
+
return newClient;
|
|
7447
7508
|
}
|
|
7448
7509
|
$unuseAll() {
|
|
7449
7510
|
const newOptions = {
|
|
7450
7511
|
...this.options,
|
|
7451
7512
|
plugins: []
|
|
7452
7513
|
};
|
|
7453
|
-
|
|
7514
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7515
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7516
|
+
return newClient;
|
|
7454
7517
|
}
|
|
7455
7518
|
$setAuth(auth) {
|
|
7456
7519
|
if (auth !== void 0 && typeof auth !== "object") {
|
|
@@ -7464,14 +7527,16 @@ var ClientImpl = class _ClientImpl {
|
|
|
7464
7527
|
return this.auth;
|
|
7465
7528
|
}
|
|
7466
7529
|
$setOptions(options) {
|
|
7467
|
-
|
|
7530
|
+
const newClient = new _ClientImpl(this.schema, options, this);
|
|
7531
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7532
|
+
return newClient;
|
|
7468
7533
|
}
|
|
7469
7534
|
$setInputValidation(enable) {
|
|
7470
7535
|
const newOptions = {
|
|
7471
7536
|
...this.options,
|
|
7472
7537
|
validateInput: enable
|
|
7473
7538
|
};
|
|
7474
|
-
return
|
|
7539
|
+
return this.$setOptions(newOptions);
|
|
7475
7540
|
}
|
|
7476
7541
|
$executeRaw(query, ...values) {
|
|
7477
7542
|
return createZenStackPromise(async () => {
|
|
@@ -7508,7 +7573,6 @@ var ClientImpl = class _ClientImpl {
|
|
|
7508
7573
|
}
|
|
7509
7574
|
};
|
|
7510
7575
|
function createClientProxy(client) {
|
|
7511
|
-
const inputValidator = new InputValidator(client);
|
|
7512
7576
|
const resultProcessor = new ResultProcessor(client.$schema, client.$options);
|
|
7513
7577
|
return new Proxy(client, {
|
|
7514
7578
|
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
@@ -7518,7 +7582,7 @@ function createClientProxy(client) {
|
|
|
7518
7582
|
if (typeof prop === "string") {
|
|
7519
7583
|
const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
|
|
7520
7584
|
if (model) {
|
|
7521
|
-
return createModelCrudHandler(client, model, inputValidator, resultProcessor);
|
|
7585
|
+
return createModelCrudHandler(client, model, client.inputValidator, resultProcessor);
|
|
7522
7586
|
}
|
|
7523
7587
|
}
|
|
7524
7588
|
return Reflect.get(target, prop, receiver);
|
|
@@ -7550,15 +7614,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
7550
7614
|
const onQuery = plugin.onQuery;
|
|
7551
7615
|
if (onQuery) {
|
|
7552
7616
|
const _proceed = proceed;
|
|
7553
|
-
proceed = /* @__PURE__ */ __name((_args) =>
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7617
|
+
proceed = /* @__PURE__ */ __name((_args) => {
|
|
7618
|
+
const ctx = {
|
|
7619
|
+
client,
|
|
7620
|
+
model,
|
|
7621
|
+
operation: nominalOperation,
|
|
7622
|
+
// reflect the latest override if provided
|
|
7623
|
+
args: _args,
|
|
7624
|
+
// ensure inner overrides are propagated to the previous proceed
|
|
7625
|
+
proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
|
|
7626
|
+
};
|
|
7627
|
+
return onQuery(ctx);
|
|
7628
|
+
}, "proceed");
|
|
7562
7629
|
}
|
|
7563
7630
|
}
|
|
7564
7631
|
return proceed(args);
|
|
@@ -7578,7 +7645,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
7578
7645
|
return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
7579
7646
|
}, "findFirstOrThrow"),
|
|
7580
7647
|
findMany: /* @__PURE__ */ __name((args) => {
|
|
7581
|
-
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
7648
|
+
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true, false);
|
|
7582
7649
|
}, "findMany"),
|
|
7583
7650
|
create: /* @__PURE__ */ __name((args) => {
|
|
7584
7651
|
return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
@@ -8042,11 +8109,16 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
8042
8109
|
}
|
|
8043
8110
|
};
|
|
8044
8111
|
export {
|
|
8112
|
+
AllCrudOperations,
|
|
8113
|
+
AllReadOperations,
|
|
8045
8114
|
AnyNull,
|
|
8046
8115
|
AnyNullClass,
|
|
8047
8116
|
BaseCrudDialect,
|
|
8048
8117
|
CRUD,
|
|
8049
8118
|
CRUD_EXT,
|
|
8119
|
+
CoreCrudOperations,
|
|
8120
|
+
CoreReadOperations,
|
|
8121
|
+
CoreWriteOperations,
|
|
8050
8122
|
DbNull,
|
|
8051
8123
|
DbNullClass,
|
|
8052
8124
|
InputValidator,
|