@zenstackhq/runtime 3.0.0-beta.1 → 3.0.0-beta.3
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 +17 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -4331,9 +4331,17 @@ var FindOperationHandler = class extends BaseOperationHandler {
|
|
|
4331
4331
|
}
|
|
4332
4332
|
async handle(operation, args, validateArgs = true) {
|
|
4333
4333
|
const normalizedArgs = this.normalizeArgs(args);
|
|
4334
|
-
const
|
|
4334
|
+
const findOne = operation === "findFirst" || operation === "findUnique";
|
|
4335
|
+
let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, {
|
|
4336
|
+
unique: operation === "findUnique",
|
|
4337
|
+
findOne
|
|
4338
|
+
}) : normalizedArgs;
|
|
4339
|
+
if (findOne) {
|
|
4340
|
+
parsedArgs = parsedArgs ?? {};
|
|
4341
|
+
parsedArgs.take = 1;
|
|
4342
|
+
}
|
|
4335
4343
|
const result = await this.read(this.client.$qb, this.model, parsedArgs);
|
|
4336
|
-
const finalResult =
|
|
4344
|
+
const finalResult = findOne ? result[0] ?? null : result;
|
|
4337
4345
|
return finalResult;
|
|
4338
4346
|
}
|
|
4339
4347
|
};
|
|
@@ -4539,10 +4547,8 @@ var InputValidator = class {
|
|
|
4539
4547
|
constructor(schema) {
|
|
4540
4548
|
this.schema = schema;
|
|
4541
4549
|
}
|
|
4542
|
-
validateFindArgs(model,
|
|
4543
|
-
return this.validate(model, "find",
|
|
4544
|
-
unique
|
|
4545
|
-
}, (model2, options) => this.makeFindSchema(model2, options), args);
|
|
4550
|
+
validateFindArgs(model, args, options) {
|
|
4551
|
+
return this.validate(model, "find", options, (model2, options2) => this.makeFindSchema(model2, options2), args);
|
|
4546
4552
|
}
|
|
4547
4553
|
validateCreateArgs(model, args) {
|
|
4548
4554
|
return this.validate(model, "create", void 0, (model2) => this.makeCreateSchema(model2), args);
|
|
@@ -4611,7 +4617,11 @@ var InputValidator = class {
|
|
|
4611
4617
|
fields["omit"] = this.makeOmitSchema(model).optional();
|
|
4612
4618
|
if (!options.unique) {
|
|
4613
4619
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4614
|
-
|
|
4620
|
+
if (options.findOne) {
|
|
4621
|
+
fields["take"] = import_zod.z.literal(1).optional();
|
|
4622
|
+
} else {
|
|
4623
|
+
fields["take"] = this.makeTakeSchema().optional();
|
|
4624
|
+
}
|
|
4615
4625
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4616
4626
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4617
4627
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|