@zenstackhq/orm 3.2.1 → 3.3.0-beta.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/dist/index.cjs +245 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1149 -1077
- package/dist/index.d.ts +1149 -1077
- package/dist/index.js +237 -93
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -32,11 +32,19 @@ 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
|
+
CoreCreateOperations: () => CoreCreateOperations,
|
|
43
|
+
CoreCrudOperations: () => CoreCrudOperations,
|
|
44
|
+
CoreDeleteOperations: () => CoreDeleteOperations,
|
|
45
|
+
CoreReadOperations: () => CoreReadOperations,
|
|
46
|
+
CoreUpdateOperations: () => CoreUpdateOperations,
|
|
47
|
+
CoreWriteOperations: () => CoreWriteOperations,
|
|
40
48
|
DbNull: () => DbNull,
|
|
41
49
|
DbNullClass: () => DbNullClass,
|
|
42
50
|
InputValidator: () => InputValidator,
|
|
@@ -1159,7 +1167,15 @@ var BaseCrudDialect = class {
|
|
|
1159
1167
|
} else {
|
|
1160
1168
|
return this.eb.not(this.eb(lhs, "in", rhs));
|
|
1161
1169
|
}
|
|
1162
|
-
}).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("
|
|
1170
|
+
}).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("between", () => {
|
|
1171
|
+
(0, import_common_helpers2.invariant)(Array.isArray(rhs), "right hand side must be an array");
|
|
1172
|
+
(0, import_common_helpers2.invariant)(rhs.length === 2, "right hand side must have a length of 2");
|
|
1173
|
+
const [start, end] = rhs;
|
|
1174
|
+
return this.eb.and([
|
|
1175
|
+
this.eb(lhs, ">=", start),
|
|
1176
|
+
this.eb(lhs, "<=", end)
|
|
1177
|
+
]);
|
|
1178
|
+
}).with("not", () => this.eb.not(recurse(value))).with(import_ts_pattern2.P.union(...AGGREGATE_OPERATORS), (op2) => {
|
|
1163
1179
|
const innerResult = this.buildStandardFilter(type, value, aggregate(this.eb, lhs, op2), getRhs, recurse, throwIfInvalid);
|
|
1164
1180
|
consumedKeys.push(...innerResult.consumedKeys);
|
|
1165
1181
|
return this.and(...innerResult.conditions);
|
|
@@ -2107,6 +2123,70 @@ function getCrudDialect(schema, options) {
|
|
|
2107
2123
|
__name(getCrudDialect, "getCrudDialect");
|
|
2108
2124
|
|
|
2109
2125
|
// src/client/crud/operations/base.ts
|
|
2126
|
+
var CoreCrudOperations = [
|
|
2127
|
+
"findMany",
|
|
2128
|
+
"findUnique",
|
|
2129
|
+
"findFirst",
|
|
2130
|
+
"create",
|
|
2131
|
+
"createMany",
|
|
2132
|
+
"createManyAndReturn",
|
|
2133
|
+
"update",
|
|
2134
|
+
"updateMany",
|
|
2135
|
+
"updateManyAndReturn",
|
|
2136
|
+
"upsert",
|
|
2137
|
+
"delete",
|
|
2138
|
+
"deleteMany",
|
|
2139
|
+
"count",
|
|
2140
|
+
"aggregate",
|
|
2141
|
+
"groupBy",
|
|
2142
|
+
"exists"
|
|
2143
|
+
];
|
|
2144
|
+
var CoreReadOperations = [
|
|
2145
|
+
"findMany",
|
|
2146
|
+
"findUnique",
|
|
2147
|
+
"findFirst",
|
|
2148
|
+
"count",
|
|
2149
|
+
"aggregate",
|
|
2150
|
+
"groupBy",
|
|
2151
|
+
"exists"
|
|
2152
|
+
];
|
|
2153
|
+
var CoreWriteOperations = [
|
|
2154
|
+
"create",
|
|
2155
|
+
"createMany",
|
|
2156
|
+
"createManyAndReturn",
|
|
2157
|
+
"update",
|
|
2158
|
+
"updateMany",
|
|
2159
|
+
"updateManyAndReturn",
|
|
2160
|
+
"upsert",
|
|
2161
|
+
"delete",
|
|
2162
|
+
"deleteMany"
|
|
2163
|
+
];
|
|
2164
|
+
var CoreCreateOperations = [
|
|
2165
|
+
"create",
|
|
2166
|
+
"createMany",
|
|
2167
|
+
"createManyAndReturn",
|
|
2168
|
+
"upsert"
|
|
2169
|
+
];
|
|
2170
|
+
var CoreUpdateOperations = [
|
|
2171
|
+
"update",
|
|
2172
|
+
"updateMany",
|
|
2173
|
+
"updateManyAndReturn",
|
|
2174
|
+
"upsert"
|
|
2175
|
+
];
|
|
2176
|
+
var CoreDeleteOperations = [
|
|
2177
|
+
"delete",
|
|
2178
|
+
"deleteMany"
|
|
2179
|
+
];
|
|
2180
|
+
var AllCrudOperations = [
|
|
2181
|
+
...CoreCrudOperations,
|
|
2182
|
+
"findUniqueOrThrow",
|
|
2183
|
+
"findFirstOrThrow"
|
|
2184
|
+
];
|
|
2185
|
+
var AllReadOperations = [
|
|
2186
|
+
...CoreReadOperations,
|
|
2187
|
+
"findUniqueOrThrow",
|
|
2188
|
+
"findFirstOrThrow"
|
|
2189
|
+
];
|
|
2110
2190
|
var BaseOperationHandler = class {
|
|
2111
2191
|
static {
|
|
2112
2192
|
__name(this, "BaseOperationHandler");
|
|
@@ -3759,6 +3839,18 @@ var DeleteOperationHandler = class extends BaseOperationHandler {
|
|
|
3759
3839
|
}
|
|
3760
3840
|
};
|
|
3761
3841
|
|
|
3842
|
+
// src/client/crud/operations/exists.ts
|
|
3843
|
+
var ExistsOperationHandler = class extends BaseOperationHandler {
|
|
3844
|
+
static {
|
|
3845
|
+
__name(this, "ExistsOperationHandler");
|
|
3846
|
+
}
|
|
3847
|
+
async handle(_operation, args) {
|
|
3848
|
+
const normalizedArgs = this.normalizeArgs(args);
|
|
3849
|
+
const parsedArgs = this.inputValidator.validateExistsArgs(this.model, normalizedArgs);
|
|
3850
|
+
return await this.existsNonUnique(this.client.$qb, this.model, parsedArgs?.where);
|
|
3851
|
+
}
|
|
3852
|
+
};
|
|
3853
|
+
|
|
3762
3854
|
// src/client/crud/operations/find.ts
|
|
3763
3855
|
var FindOperationHandler = class extends BaseOperationHandler {
|
|
3764
3856
|
static {
|
|
@@ -3767,10 +3859,7 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
3767
3859
|
async handle(operation, args, validateArgs = true) {
|
|
3768
3860
|
const normalizedArgs = this.normalizeArgs(args);
|
|
3769
3861
|
const findOne = operation === "findFirst" || operation === "findUnique";
|
|
3770
|
-
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs,
|
|
3771
|
-
unique: operation === "findUnique",
|
|
3772
|
-
findOne
|
|
3773
|
-
}) : normalizedArgs;
|
|
3862
|
+
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, operation) : normalizedArgs;
|
|
3774
3863
|
if (findOne) {
|
|
3775
3864
|
parsedArgs = parsedArgs ?? {};
|
|
3776
3865
|
parsedArgs.take = 1;
|
|
@@ -3781,18 +3870,6 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
3781
3870
|
}
|
|
3782
3871
|
};
|
|
3783
3872
|
|
|
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
3873
|
// src/client/crud/operations/group-by.ts
|
|
3797
3874
|
var import_ts_pattern10 = require("ts-pattern");
|
|
3798
3875
|
var GroupByOperationHandler = class extends BaseOperationHandler {
|
|
@@ -4391,12 +4468,12 @@ function evalCall(data, expr) {
|
|
|
4391
4468
|
__name(evalCall, "evalCall");
|
|
4392
4469
|
|
|
4393
4470
|
// src/client/crud/validator/index.ts
|
|
4394
|
-
var schemaCache = /* @__PURE__ */ new WeakMap();
|
|
4395
4471
|
var InputValidator = class {
|
|
4396
4472
|
static {
|
|
4397
4473
|
__name(this, "InputValidator");
|
|
4398
4474
|
}
|
|
4399
4475
|
client;
|
|
4476
|
+
schemaCache = /* @__PURE__ */ new Map();
|
|
4400
4477
|
constructor(client) {
|
|
4401
4478
|
this.client = client;
|
|
4402
4479
|
}
|
|
@@ -4493,75 +4570,64 @@ var InputValidator = class {
|
|
|
4493
4570
|
}
|
|
4494
4571
|
return schema;
|
|
4495
4572
|
}
|
|
4496
|
-
validateFindArgs(model, args,
|
|
4497
|
-
return this.validate(model,
|
|
4573
|
+
validateFindArgs(model, args, operation) {
|
|
4574
|
+
return this.validate(model, operation, (model2) => this.makeFindSchema(model2, operation), args);
|
|
4498
4575
|
}
|
|
4499
4576
|
validateExistsArgs(model, args) {
|
|
4500
|
-
return this.validate(model, "exists",
|
|
4577
|
+
return this.validate(model, "exists", (model2) => this.makeExistsSchema(model2), args);
|
|
4501
4578
|
}
|
|
4502
4579
|
validateCreateArgs(model, args) {
|
|
4503
|
-
return this.validate(model, "create",
|
|
4580
|
+
return this.validate(model, "create", (model2) => this.makeCreateSchema(model2), args);
|
|
4504
4581
|
}
|
|
4505
4582
|
validateCreateManyArgs(model, args) {
|
|
4506
|
-
return this.validate(model, "createMany",
|
|
4583
|
+
return this.validate(model, "createMany", (model2) => this.makeCreateManySchema(model2), args);
|
|
4507
4584
|
}
|
|
4508
4585
|
validateCreateManyAndReturnArgs(model, args) {
|
|
4509
|
-
return this.validate(model, "createManyAndReturn",
|
|
4586
|
+
return this.validate(model, "createManyAndReturn", (model2) => this.makeCreateManyAndReturnSchema(model2), args);
|
|
4510
4587
|
}
|
|
4511
4588
|
validateUpdateArgs(model, args) {
|
|
4512
|
-
return this.validate(model, "update",
|
|
4589
|
+
return this.validate(model, "update", (model2) => this.makeUpdateSchema(model2), args);
|
|
4513
4590
|
}
|
|
4514
4591
|
validateUpdateManyArgs(model, args) {
|
|
4515
|
-
return this.validate(model, "updateMany",
|
|
4592
|
+
return this.validate(model, "updateMany", (model2) => this.makeUpdateManySchema(model2), args);
|
|
4516
4593
|
}
|
|
4517
4594
|
validateUpdateManyAndReturnArgs(model, args) {
|
|
4518
|
-
return this.validate(model, "updateManyAndReturn",
|
|
4595
|
+
return this.validate(model, "updateManyAndReturn", (model2) => this.makeUpdateManyAndReturnSchema(model2), args);
|
|
4519
4596
|
}
|
|
4520
4597
|
validateUpsertArgs(model, args) {
|
|
4521
|
-
return this.validate(model, "upsert",
|
|
4598
|
+
return this.validate(model, "upsert", (model2) => this.makeUpsertSchema(model2), args);
|
|
4522
4599
|
}
|
|
4523
4600
|
validateDeleteArgs(model, args) {
|
|
4524
|
-
return this.validate(model, "delete",
|
|
4601
|
+
return this.validate(model, "delete", (model2) => this.makeDeleteSchema(model2), args);
|
|
4525
4602
|
}
|
|
4526
4603
|
validateDeleteManyArgs(model, args) {
|
|
4527
|
-
return this.validate(model, "deleteMany",
|
|
4604
|
+
return this.validate(model, "deleteMany", (model2) => this.makeDeleteManySchema(model2), args);
|
|
4528
4605
|
}
|
|
4529
4606
|
validateCountArgs(model, args) {
|
|
4530
|
-
return this.validate(model, "count",
|
|
4607
|
+
return this.validate(model, "count", (model2) => this.makeCountSchema(model2), args);
|
|
4531
4608
|
}
|
|
4532
4609
|
validateAggregateArgs(model, args) {
|
|
4533
|
-
return this.validate(model, "aggregate",
|
|
4610
|
+
return this.validate(model, "aggregate", (model2) => this.makeAggregateSchema(model2), args);
|
|
4534
4611
|
}
|
|
4535
4612
|
validateGroupByArgs(model, args) {
|
|
4536
|
-
return this.validate(model, "groupBy",
|
|
4613
|
+
return this.validate(model, "groupBy", (model2) => this.makeGroupBySchema(model2), args);
|
|
4537
4614
|
}
|
|
4538
4615
|
getSchemaCache(cacheKey) {
|
|
4539
|
-
|
|
4540
|
-
if (!thisCache) {
|
|
4541
|
-
thisCache = /* @__PURE__ */ new Map();
|
|
4542
|
-
schemaCache.set(this.schema, thisCache);
|
|
4543
|
-
}
|
|
4544
|
-
return thisCache.get(cacheKey);
|
|
4616
|
+
return this.schemaCache.get(cacheKey);
|
|
4545
4617
|
}
|
|
4546
4618
|
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);
|
|
4619
|
+
return this.schemaCache.set(cacheKey, schema);
|
|
4553
4620
|
}
|
|
4554
|
-
validate(model, operation,
|
|
4621
|
+
validate(model, operation, getSchema, args) {
|
|
4555
4622
|
const cacheKey = (0, import_json_stable_stringify.default)({
|
|
4556
4623
|
type: "model",
|
|
4557
4624
|
model,
|
|
4558
4625
|
operation,
|
|
4559
|
-
options,
|
|
4560
4626
|
extraValidationsEnabled: this.extraValidationsEnabled
|
|
4561
4627
|
});
|
|
4562
4628
|
let schema = this.getSchemaCache(cacheKey);
|
|
4563
4629
|
if (!schema) {
|
|
4564
|
-
schema = getSchema(model
|
|
4630
|
+
schema = getSchema(model);
|
|
4565
4631
|
this.setSchemaCache(cacheKey, schema);
|
|
4566
4632
|
}
|
|
4567
4633
|
const { error, data } = schema.safeParse(args);
|
|
@@ -4572,11 +4638,61 @@ var InputValidator = class {
|
|
|
4572
4638
|
}
|
|
4573
4639
|
return data;
|
|
4574
4640
|
}
|
|
4641
|
+
mergePluginArgsSchema(schema, operation) {
|
|
4642
|
+
let result = schema;
|
|
4643
|
+
for (const plugin of this.options.plugins ?? []) {
|
|
4644
|
+
if (plugin.queryArgs) {
|
|
4645
|
+
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
4646
|
+
if (pluginSchema) {
|
|
4647
|
+
result = result.extend(pluginSchema.shape);
|
|
4648
|
+
}
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
return result.strict();
|
|
4652
|
+
}
|
|
4653
|
+
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
4654
|
+
if (!plugin.queryArgs) {
|
|
4655
|
+
return void 0;
|
|
4656
|
+
}
|
|
4657
|
+
let result;
|
|
4658
|
+
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
4659
|
+
result = plugin.queryArgs[operation];
|
|
4660
|
+
} else if (operation === "upsert") {
|
|
4661
|
+
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
4662
|
+
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
4663
|
+
if (createSchema && updateSchema) {
|
|
4664
|
+
(0, import_common_helpers7.invariant)(createSchema instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4665
|
+
(0, import_common_helpers7.invariant)(updateSchema instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4666
|
+
result = createSchema.extend(updateSchema.shape);
|
|
4667
|
+
} else if (createSchema) {
|
|
4668
|
+
result = createSchema;
|
|
4669
|
+
} else if (updateSchema) {
|
|
4670
|
+
result = updateSchema;
|
|
4671
|
+
}
|
|
4672
|
+
} else if (
|
|
4673
|
+
// then comes grouped operations: $create, $read, $update, $delete
|
|
4674
|
+
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
4675
|
+
) {
|
|
4676
|
+
result = plugin.queryArgs["$create"];
|
|
4677
|
+
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
4678
|
+
result = plugin.queryArgs["$read"];
|
|
4679
|
+
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
4680
|
+
result = plugin.queryArgs["$update"];
|
|
4681
|
+
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
4682
|
+
result = plugin.queryArgs["$delete"];
|
|
4683
|
+
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
4684
|
+
result = plugin.queryArgs["$all"];
|
|
4685
|
+
}
|
|
4686
|
+
(0, import_common_helpers7.invariant)(result === void 0 || result instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4687
|
+
return result;
|
|
4688
|
+
}
|
|
4575
4689
|
// #region Find
|
|
4576
|
-
makeFindSchema(model,
|
|
4690
|
+
makeFindSchema(model, operation) {
|
|
4577
4691
|
const fields = {};
|
|
4578
|
-
const
|
|
4579
|
-
|
|
4692
|
+
const unique = operation === "findUnique";
|
|
4693
|
+
const findOne = operation === "findUnique" || operation === "findFirst";
|
|
4694
|
+
const where = this.makeWhereSchema(model, unique);
|
|
4695
|
+
if (unique) {
|
|
4580
4696
|
fields["where"] = where;
|
|
4581
4697
|
} else {
|
|
4582
4698
|
fields["where"] = where.optional();
|
|
@@ -4584,9 +4700,9 @@ var InputValidator = class {
|
|
|
4584
4700
|
fields["select"] = this.makeSelectSchema(model).optional().nullable();
|
|
4585
4701
|
fields["include"] = this.makeIncludeSchema(model).optional().nullable();
|
|
4586
4702
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
4587
|
-
if (!
|
|
4703
|
+
if (!unique) {
|
|
4588
4704
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4589
|
-
if (
|
|
4705
|
+
if (findOne) {
|
|
4590
4706
|
fields["take"] = import_zod3.z.literal(1).optional();
|
|
4591
4707
|
} else {
|
|
4592
4708
|
fields["take"] = this.makeTakeSchema().optional();
|
|
@@ -4595,18 +4711,20 @@ var InputValidator = class {
|
|
|
4595
4711
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4596
4712
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4597
4713
|
}
|
|
4598
|
-
|
|
4714
|
+
const baseSchema = import_zod3.z.strictObject(fields);
|
|
4715
|
+
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
4599
4716
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4600
4717
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4601
|
-
if (!
|
|
4718
|
+
if (!unique) {
|
|
4602
4719
|
result = result.optional();
|
|
4603
4720
|
}
|
|
4604
4721
|
return result;
|
|
4605
4722
|
}
|
|
4606
4723
|
makeExistsSchema(model) {
|
|
4607
|
-
|
|
4724
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
4608
4725
|
where: this.makeWhereSchema(model, false).optional()
|
|
4609
|
-
})
|
|
4726
|
+
});
|
|
4727
|
+
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
4610
4728
|
}
|
|
4611
4729
|
makeScalarSchema(type, attributes) {
|
|
4612
4730
|
if (this.schema.typeDefs && type in this.schema.typeDefs) {
|
|
@@ -4952,6 +5070,7 @@ var InputValidator = class {
|
|
|
4952
5070
|
lte: baseSchema.optional(),
|
|
4953
5071
|
gt: baseSchema.optional(),
|
|
4954
5072
|
gte: baseSchema.optional(),
|
|
5073
|
+
between: baseSchema.array().length(2).optional(),
|
|
4955
5074
|
not: makeThis().optional(),
|
|
4956
5075
|
...withAggregations?.includes("_count") ? {
|
|
4957
5076
|
_count: this.makeNumberFilterSchema(import_zod3.z.number().int(), false, false).optional()
|
|
@@ -5174,25 +5293,27 @@ var InputValidator = class {
|
|
|
5174
5293
|
// #region Create
|
|
5175
5294
|
makeCreateSchema(model) {
|
|
5176
5295
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5177
|
-
|
|
5296
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5178
5297
|
data: dataSchema,
|
|
5179
5298
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5180
5299
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5181
5300
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5182
5301
|
});
|
|
5302
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "create");
|
|
5183
5303
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5184
5304
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5185
5305
|
return schema;
|
|
5186
5306
|
}
|
|
5187
5307
|
makeCreateManySchema(model) {
|
|
5188
|
-
return this.makeCreateManyDataSchema(model, []).optional();
|
|
5308
|
+
return this.mergePluginArgsSchema(this.makeCreateManyDataSchema(model, []), "createMany").optional();
|
|
5189
5309
|
}
|
|
5190
5310
|
makeCreateManyAndReturnSchema(model) {
|
|
5191
5311
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
5192
|
-
|
|
5312
|
+
let result = base.extend({
|
|
5193
5313
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5194
5314
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5195
5315
|
});
|
|
5316
|
+
result = this.mergePluginArgsSchema(result, "createManyAndReturn");
|
|
5196
5317
|
return this.refineForSelectOmitMutuallyExclusive(result).optional();
|
|
5197
5318
|
}
|
|
5198
5319
|
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5385,27 +5506,28 @@ var InputValidator = class {
|
|
|
5385
5506
|
// #endregion
|
|
5386
5507
|
// #region Update
|
|
5387
5508
|
makeUpdateSchema(model) {
|
|
5388
|
-
|
|
5509
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5389
5510
|
where: this.makeWhereSchema(model, true),
|
|
5390
5511
|
data: this.makeUpdateDataSchema(model),
|
|
5391
5512
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5392
5513
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5393
5514
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5394
5515
|
});
|
|
5516
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "update");
|
|
5395
5517
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5396
5518
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5397
5519
|
return schema;
|
|
5398
5520
|
}
|
|
5399
5521
|
makeUpdateManySchema(model) {
|
|
5400
|
-
return import_zod3.z.strictObject({
|
|
5522
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5401
5523
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5402
5524
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5403
5525
|
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
5404
|
-
});
|
|
5526
|
+
}), "updateMany");
|
|
5405
5527
|
}
|
|
5406
5528
|
makeUpdateManyAndReturnSchema(model) {
|
|
5407
|
-
const
|
|
5408
|
-
let schema =
|
|
5529
|
+
const baseSchema = this.makeUpdateManySchema(model);
|
|
5530
|
+
let schema = baseSchema.extend({
|
|
5409
5531
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5410
5532
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5411
5533
|
});
|
|
@@ -5413,7 +5535,7 @@ var InputValidator = class {
|
|
|
5413
5535
|
return schema;
|
|
5414
5536
|
}
|
|
5415
5537
|
makeUpsertSchema(model) {
|
|
5416
|
-
|
|
5538
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5417
5539
|
where: this.makeWhereSchema(model, true),
|
|
5418
5540
|
create: this.makeCreateDataSchema(model, false),
|
|
5419
5541
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -5421,6 +5543,7 @@ var InputValidator = class {
|
|
|
5421
5543
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5422
5544
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5423
5545
|
});
|
|
5546
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "upsert");
|
|
5424
5547
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5425
5548
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5426
5549
|
return schema;
|
|
@@ -5514,32 +5637,33 @@ var InputValidator = class {
|
|
|
5514
5637
|
// #endregion
|
|
5515
5638
|
// #region Delete
|
|
5516
5639
|
makeDeleteSchema(model) {
|
|
5517
|
-
|
|
5640
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5518
5641
|
where: this.makeWhereSchema(model, true),
|
|
5519
5642
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5520
5643
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
5521
5644
|
omit: this.makeOmitSchema(model).optional().nullable()
|
|
5522
5645
|
});
|
|
5646
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "delete");
|
|
5523
5647
|
schema = this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5524
5648
|
schema = this.refineForSelectOmitMutuallyExclusive(schema);
|
|
5525
5649
|
return schema;
|
|
5526
5650
|
}
|
|
5527
5651
|
makeDeleteManySchema(model) {
|
|
5528
|
-
return import_zod3.z.
|
|
5652
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5529
5653
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5530
5654
|
limit: import_zod3.z.number().int().nonnegative().optional()
|
|
5531
|
-
}).optional();
|
|
5655
|
+
}), "deleteMany").optional();
|
|
5532
5656
|
}
|
|
5533
5657
|
// #endregion
|
|
5534
5658
|
// #region Count
|
|
5535
5659
|
makeCountSchema(model) {
|
|
5536
|
-
return import_zod3.z.
|
|
5660
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5537
5661
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5538
5662
|
skip: this.makeSkipSchema().optional(),
|
|
5539
5663
|
take: this.makeTakeSchema().optional(),
|
|
5540
5664
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
5541
5665
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
5542
|
-
}).optional();
|
|
5666
|
+
}), "count").optional();
|
|
5543
5667
|
}
|
|
5544
5668
|
makeCountAggregateInputSchema(model) {
|
|
5545
5669
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5557,7 +5681,7 @@ var InputValidator = class {
|
|
|
5557
5681
|
// #endregion
|
|
5558
5682
|
// #region Aggregate
|
|
5559
5683
|
makeAggregateSchema(model) {
|
|
5560
|
-
return import_zod3.z.
|
|
5684
|
+
return this.mergePluginArgsSchema(import_zod3.z.strictObject({
|
|
5561
5685
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5562
5686
|
skip: this.makeSkipSchema().optional(),
|
|
5563
5687
|
take: this.makeTakeSchema().optional(),
|
|
@@ -5567,7 +5691,7 @@ var InputValidator = class {
|
|
|
5567
5691
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
5568
5692
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5569
5693
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5570
|
-
}).optional();
|
|
5694
|
+
}), "aggregate").optional();
|
|
5571
5695
|
}
|
|
5572
5696
|
makeSumAvgInputSchema(model) {
|
|
5573
5697
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5593,7 +5717,7 @@ var InputValidator = class {
|
|
|
5593
5717
|
const modelDef = requireModel(this.schema, model);
|
|
5594
5718
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5595
5719
|
const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod3.z.enum(nonRelationFields), true) : import_zod3.z.never();
|
|
5596
|
-
|
|
5720
|
+
const baseSchema = import_zod3.z.strictObject({
|
|
5597
5721
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5598
5722
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5599
5723
|
by: bySchema,
|
|
@@ -5606,6 +5730,7 @@ var InputValidator = class {
|
|
|
5606
5730
|
_min: this.makeMinMaxInputSchema(model).optional(),
|
|
5607
5731
|
_max: this.makeMinMaxInputSchema(model).optional()
|
|
5608
5732
|
});
|
|
5733
|
+
let schema = this.mergePluginArgsSchema(baseSchema, "groupBy");
|
|
5609
5734
|
schema = schema.refine((value) => {
|
|
5610
5735
|
const bys = typeof value.by === "string" ? [
|
|
5611
5736
|
value.by
|
|
@@ -7296,6 +7421,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7296
7421
|
$schema;
|
|
7297
7422
|
kyselyProps;
|
|
7298
7423
|
auth;
|
|
7424
|
+
inputValidator;
|
|
7299
7425
|
constructor(schema, options, baseClient, executor) {
|
|
7300
7426
|
this.schema = schema;
|
|
7301
7427
|
this.options = options;
|
|
@@ -7332,6 +7458,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7332
7458
|
});
|
|
7333
7459
|
}
|
|
7334
7460
|
this.kysely = new import_kysely10.Kysely(this.kyselyProps);
|
|
7461
|
+
this.inputValidator = baseClient?.inputValidator ?? new InputValidator(this);
|
|
7335
7462
|
return createClientProxy(this);
|
|
7336
7463
|
}
|
|
7337
7464
|
get $qb() {
|
|
@@ -7416,8 +7543,7 @@ var ClientImpl = class _ClientImpl {
|
|
|
7416
7543
|
if (!procOptions[name] || typeof procOptions[name] !== "function") {
|
|
7417
7544
|
throw createConfigError(`Procedure "${name}" does not have a handler configured.`);
|
|
7418
7545
|
}
|
|
7419
|
-
const
|
|
7420
|
-
const validatedInput = inputValidator.validateProcedureInput(name, input);
|
|
7546
|
+
const validatedInput = this.inputValidator.validateProcedureInput(name, input);
|
|
7421
7547
|
const handler = procOptions[name];
|
|
7422
7548
|
const invokeWithClient = /* @__PURE__ */ __name(async (client, _input) => {
|
|
7423
7549
|
let proceed = /* @__PURE__ */ __name(async (nextInput) => {
|
|
@@ -7467,7 +7593,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
7467
7593
|
...this.options,
|
|
7468
7594
|
plugins: newPlugins
|
|
7469
7595
|
};
|
|
7470
|
-
|
|
7596
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7597
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7598
|
+
return newClient;
|
|
7471
7599
|
}
|
|
7472
7600
|
$unuse(pluginId) {
|
|
7473
7601
|
const newPlugins = [];
|
|
@@ -7480,14 +7608,18 @@ var ClientImpl = class _ClientImpl {
|
|
|
7480
7608
|
...this.options,
|
|
7481
7609
|
plugins: newPlugins
|
|
7482
7610
|
};
|
|
7483
|
-
|
|
7611
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7612
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7613
|
+
return newClient;
|
|
7484
7614
|
}
|
|
7485
7615
|
$unuseAll() {
|
|
7486
7616
|
const newOptions = {
|
|
7487
7617
|
...this.options,
|
|
7488
7618
|
plugins: []
|
|
7489
7619
|
};
|
|
7490
|
-
|
|
7620
|
+
const newClient = new _ClientImpl(this.schema, newOptions, this);
|
|
7621
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7622
|
+
return newClient;
|
|
7491
7623
|
}
|
|
7492
7624
|
$setAuth(auth) {
|
|
7493
7625
|
if (auth !== void 0 && typeof auth !== "object") {
|
|
@@ -7501,14 +7633,16 @@ var ClientImpl = class _ClientImpl {
|
|
|
7501
7633
|
return this.auth;
|
|
7502
7634
|
}
|
|
7503
7635
|
$setOptions(options) {
|
|
7504
|
-
|
|
7636
|
+
const newClient = new _ClientImpl(this.schema, options, this);
|
|
7637
|
+
newClient.inputValidator = new InputValidator(newClient);
|
|
7638
|
+
return newClient;
|
|
7505
7639
|
}
|
|
7506
7640
|
$setInputValidation(enable) {
|
|
7507
7641
|
const newOptions = {
|
|
7508
7642
|
...this.options,
|
|
7509
7643
|
validateInput: enable
|
|
7510
7644
|
};
|
|
7511
|
-
return
|
|
7645
|
+
return this.$setOptions(newOptions);
|
|
7512
7646
|
}
|
|
7513
7647
|
$executeRaw(query, ...values) {
|
|
7514
7648
|
return createZenStackPromise(async () => {
|
|
@@ -7545,17 +7679,24 @@ var ClientImpl = class _ClientImpl {
|
|
|
7545
7679
|
}
|
|
7546
7680
|
};
|
|
7547
7681
|
function createClientProxy(client) {
|
|
7548
|
-
const inputValidator = new InputValidator(client);
|
|
7549
7682
|
const resultProcessor = new ResultProcessor(client.$schema, client.$options);
|
|
7550
7683
|
return new Proxy(client, {
|
|
7551
7684
|
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
7552
7685
|
if (typeof prop === "string" && prop.startsWith("$")) {
|
|
7686
|
+
const plugins = target.$options.plugins ?? [];
|
|
7687
|
+
for (let i = plugins.length - 1; i >= 0; i--) {
|
|
7688
|
+
const plugin = plugins[i];
|
|
7689
|
+
const clientMembers = plugin?.client;
|
|
7690
|
+
if (clientMembers && prop in clientMembers) {
|
|
7691
|
+
return clientMembers[prop];
|
|
7692
|
+
}
|
|
7693
|
+
}
|
|
7553
7694
|
return Reflect.get(target, prop, receiver);
|
|
7554
7695
|
}
|
|
7555
7696
|
if (typeof prop === "string") {
|
|
7556
7697
|
const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
|
|
7557
7698
|
if (model) {
|
|
7558
|
-
return createModelCrudHandler(client, model, inputValidator, resultProcessor);
|
|
7699
|
+
return createModelCrudHandler(client, model, client.inputValidator, resultProcessor);
|
|
7559
7700
|
}
|
|
7560
7701
|
}
|
|
7561
7702
|
return Reflect.get(target, prop, receiver);
|
|
@@ -7587,15 +7728,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
7587
7728
|
const onQuery = plugin.onQuery;
|
|
7588
7729
|
if (onQuery) {
|
|
7589
7730
|
const _proceed = proceed;
|
|
7590
|
-
proceed = /* @__PURE__ */ __name((_args) =>
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7731
|
+
proceed = /* @__PURE__ */ __name((_args) => {
|
|
7732
|
+
const ctx = {
|
|
7733
|
+
client,
|
|
7734
|
+
model,
|
|
7735
|
+
operation: nominalOperation,
|
|
7736
|
+
// reflect the latest override if provided
|
|
7737
|
+
args: _args,
|
|
7738
|
+
// ensure inner overrides are propagated to the previous proceed
|
|
7739
|
+
proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
|
|
7740
|
+
};
|
|
7741
|
+
return onQuery(ctx);
|
|
7742
|
+
}, "proceed");
|
|
7599
7743
|
}
|
|
7600
7744
|
}
|
|
7601
7745
|
return proceed(args);
|
|
@@ -7615,7 +7759,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
7615
7759
|
return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
7616
7760
|
}, "findFirstOrThrow"),
|
|
7617
7761
|
findMany: /* @__PURE__ */ __name((args) => {
|
|
7618
|
-
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
7762
|
+
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true, false);
|
|
7619
7763
|
}, "findMany"),
|
|
7620
7764
|
create: /* @__PURE__ */ __name((args) => {
|
|
7621
7765
|
return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
@@ -8080,11 +8224,19 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
8080
8224
|
};
|
|
8081
8225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8082
8226
|
0 && (module.exports = {
|
|
8227
|
+
AllCrudOperations,
|
|
8228
|
+
AllReadOperations,
|
|
8083
8229
|
AnyNull,
|
|
8084
8230
|
AnyNullClass,
|
|
8085
8231
|
BaseCrudDialect,
|
|
8086
8232
|
CRUD,
|
|
8087
8233
|
CRUD_EXT,
|
|
8234
|
+
CoreCreateOperations,
|
|
8235
|
+
CoreCrudOperations,
|
|
8236
|
+
CoreDeleteOperations,
|
|
8237
|
+
CoreReadOperations,
|
|
8238
|
+
CoreUpdateOperations,
|
|
8239
|
+
CoreWriteOperations,
|
|
8088
8240
|
DbNull,
|
|
8089
8241
|
DbNullClass,
|
|
8090
8242
|
InputValidator,
|