@zenstackhq/orm 3.3.3 → 3.4.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 +381 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1593 -1373
- package/dist/index.d.ts +1593 -1373
- package/dist/index.js +381 -111
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -599,13 +599,50 @@ var LOGICAL_COMBINATORS = [
|
|
|
599
599
|
"OR",
|
|
600
600
|
"NOT"
|
|
601
601
|
];
|
|
602
|
-
var
|
|
602
|
+
var AggregateOperators = [
|
|
603
603
|
"_count",
|
|
604
604
|
"_sum",
|
|
605
605
|
"_avg",
|
|
606
606
|
"_min",
|
|
607
607
|
"_max"
|
|
608
608
|
];
|
|
609
|
+
var FILTER_PROPERTY_TO_KIND = {
|
|
610
|
+
// Equality operators
|
|
611
|
+
equals: "Equality",
|
|
612
|
+
not: "Equality",
|
|
613
|
+
in: "Equality",
|
|
614
|
+
notIn: "Equality",
|
|
615
|
+
// Range operators
|
|
616
|
+
lt: "Range",
|
|
617
|
+
lte: "Range",
|
|
618
|
+
gt: "Range",
|
|
619
|
+
gte: "Range",
|
|
620
|
+
between: "Range",
|
|
621
|
+
// Like operators
|
|
622
|
+
contains: "Like",
|
|
623
|
+
startsWith: "Like",
|
|
624
|
+
endsWith: "Like",
|
|
625
|
+
mode: "Like",
|
|
626
|
+
// Relation operators
|
|
627
|
+
is: "Relation",
|
|
628
|
+
isNot: "Relation",
|
|
629
|
+
some: "Relation",
|
|
630
|
+
every: "Relation",
|
|
631
|
+
none: "Relation",
|
|
632
|
+
// Json operators
|
|
633
|
+
path: "Json",
|
|
634
|
+
string_contains: "Json",
|
|
635
|
+
string_starts_with: "Json",
|
|
636
|
+
string_ends_with: "Json",
|
|
637
|
+
array_contains: "Json",
|
|
638
|
+
array_starts_with: "Json",
|
|
639
|
+
array_ends_with: "Json",
|
|
640
|
+
// List operators
|
|
641
|
+
has: "List",
|
|
642
|
+
hasEvery: "List",
|
|
643
|
+
hasSome: "List",
|
|
644
|
+
isEmpty: "List"
|
|
645
|
+
};
|
|
609
646
|
|
|
610
647
|
// src/client/contract.ts
|
|
611
648
|
var TransactionIsolationLevel = /* @__PURE__ */ function(TransactionIsolationLevel2) {
|
|
@@ -1168,7 +1205,7 @@ var BaseCrudDialect = class {
|
|
|
1168
1205
|
this.eb(lhs, ">=", start),
|
|
1169
1206
|
this.eb(lhs, "<=", end)
|
|
1170
1207
|
]);
|
|
1171
|
-
}).with("not", () => this.eb.not(recurse(value))).with(P.union(...
|
|
1208
|
+
}).with("not", () => this.eb.not(recurse(value))).with(P.union(...AggregateOperators), (op2) => {
|
|
1172
1209
|
const innerResult = this.buildStandardFilter(type, value, aggregate(this.eb, lhs, op2), getRhs, recurse, throwIfInvalid);
|
|
1173
1210
|
consumedKeys.push(...innerResult.consumedKeys);
|
|
1174
1211
|
return this.and(...innerResult.conditions);
|
|
@@ -5251,6 +5288,10 @@ var InputValidator = class {
|
|
|
5251
5288
|
}
|
|
5252
5289
|
makeWhereSchema(model, unique, withoutRelationFields = false, withAggregations = false) {
|
|
5253
5290
|
const modelDef = requireModel(this.schema, model);
|
|
5291
|
+
const uniqueFieldNames = unique ? getUniqueFields(this.schema, model).filter((uf) => (
|
|
5292
|
+
// single-field unique
|
|
5293
|
+
"def" in uf
|
|
5294
|
+
)).map((uf) => uf.name) : void 0;
|
|
5254
5295
|
const fields = {};
|
|
5255
5296
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5256
5297
|
const fieldDef = requireField(this.schema, model, field);
|
|
@@ -5259,38 +5300,44 @@ var InputValidator = class {
|
|
|
5259
5300
|
if (withoutRelationFields) {
|
|
5260
5301
|
continue;
|
|
5261
5302
|
}
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
fieldSchema = z2.union([
|
|
5266
|
-
fieldSchema,
|
|
5267
|
-
z2.strictObject({
|
|
5268
|
-
some: fieldSchema.optional(),
|
|
5269
|
-
every: fieldSchema.optional(),
|
|
5270
|
-
none: fieldSchema.optional()
|
|
5271
|
-
})
|
|
5272
|
-
]);
|
|
5303
|
+
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
5304
|
+
if (allowedFilterKinds && !allowedFilterKinds.has("Relation")) {
|
|
5305
|
+
fieldSchema = z2.never();
|
|
5273
5306
|
} else {
|
|
5274
|
-
fieldSchema = z2.
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5307
|
+
fieldSchema = z2.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
5308
|
+
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
5309
|
+
if (fieldDef.array) {
|
|
5310
|
+
fieldSchema = z2.union([
|
|
5311
|
+
fieldSchema,
|
|
5312
|
+
z2.strictObject({
|
|
5313
|
+
some: fieldSchema.optional(),
|
|
5314
|
+
every: fieldSchema.optional(),
|
|
5315
|
+
none: fieldSchema.optional()
|
|
5316
|
+
})
|
|
5317
|
+
]);
|
|
5318
|
+
} else {
|
|
5319
|
+
fieldSchema = z2.union([
|
|
5320
|
+
fieldSchema,
|
|
5321
|
+
z2.strictObject({
|
|
5322
|
+
is: fieldSchema.optional(),
|
|
5323
|
+
isNot: fieldSchema.optional()
|
|
5324
|
+
})
|
|
5325
|
+
]);
|
|
5326
|
+
}
|
|
5281
5327
|
}
|
|
5282
5328
|
} else {
|
|
5329
|
+
const ignoreSlicing = !!uniqueFieldNames?.includes(field);
|
|
5283
5330
|
const enumDef = getEnum(this.schema, fieldDef.type);
|
|
5284
5331
|
if (enumDef) {
|
|
5285
5332
|
if (Object.keys(enumDef.values).length > 0) {
|
|
5286
|
-
fieldSchema = this.makeEnumFilterSchema(
|
|
5333
|
+
fieldSchema = this.makeEnumFilterSchema(model, fieldDef, withAggregations, ignoreSlicing);
|
|
5287
5334
|
}
|
|
5288
5335
|
} else if (fieldDef.array) {
|
|
5289
|
-
fieldSchema = this.makeArrayFilterSchema(fieldDef
|
|
5336
|
+
fieldSchema = this.makeArrayFilterSchema(model, fieldDef);
|
|
5290
5337
|
} else if (this.isTypeDefType(fieldDef.type)) {
|
|
5291
|
-
fieldSchema = this.makeTypedJsonFilterSchema(
|
|
5338
|
+
fieldSchema = this.makeTypedJsonFilterSchema(model, fieldDef);
|
|
5292
5339
|
} else {
|
|
5293
|
-
fieldSchema = this.makePrimitiveFilterSchema(
|
|
5340
|
+
fieldSchema = this.makePrimitiveFilterSchema(model, fieldDef, withAggregations, ignoreSlicing);
|
|
5294
5341
|
}
|
|
5295
5342
|
}
|
|
5296
5343
|
if (fieldSchema) {
|
|
@@ -5307,12 +5354,12 @@ var InputValidator = class {
|
|
|
5307
5354
|
const enumDef = getEnum(this.schema, def.type);
|
|
5308
5355
|
if (enumDef) {
|
|
5309
5356
|
if (Object.keys(enumDef.values).length > 0) {
|
|
5310
|
-
fieldSchema = this.makeEnumFilterSchema(
|
|
5357
|
+
fieldSchema = this.makeEnumFilterSchema(model, def, false, true);
|
|
5311
5358
|
} else {
|
|
5312
5359
|
fieldSchema = z2.never();
|
|
5313
5360
|
}
|
|
5314
5361
|
} else {
|
|
5315
|
-
fieldSchema = this.makePrimitiveFilterSchema(
|
|
5362
|
+
fieldSchema = this.makePrimitiveFilterSchema(model, def, false, true);
|
|
5316
5363
|
}
|
|
5317
5364
|
return [
|
|
5318
5365
|
key,
|
|
@@ -5347,7 +5394,11 @@ var InputValidator = class {
|
|
|
5347
5394
|
}
|
|
5348
5395
|
return result;
|
|
5349
5396
|
}
|
|
5350
|
-
makeTypedJsonFilterSchema(
|
|
5397
|
+
makeTypedJsonFilterSchema(contextModel, fieldInfo) {
|
|
5398
|
+
const field = fieldInfo.name;
|
|
5399
|
+
const type = fieldInfo.type;
|
|
5400
|
+
const optional = !!fieldInfo.optional;
|
|
5401
|
+
const array = !!fieldInfo.array;
|
|
5351
5402
|
const typeDef = getTypeDef(this.schema, type);
|
|
5352
5403
|
invariant9(typeDef, `Type definition "${type}" not found in schema`);
|
|
5353
5404
|
const candidates = [];
|
|
@@ -5355,21 +5406,26 @@ var InputValidator = class {
|
|
|
5355
5406
|
const fieldSchemas = {};
|
|
5356
5407
|
for (const [fieldName, fieldDef] of Object.entries(typeDef.fields)) {
|
|
5357
5408
|
if (this.isTypeDefType(fieldDef.type)) {
|
|
5358
|
-
fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(
|
|
5409
|
+
fieldSchemas[fieldName] = this.makeTypedJsonFilterSchema(contextModel, fieldDef).optional();
|
|
5359
5410
|
} else {
|
|
5360
5411
|
const enumDef = getEnum(this.schema, fieldDef.type);
|
|
5361
5412
|
if (enumDef) {
|
|
5362
|
-
fieldSchemas[fieldName] = this.makeEnumFilterSchema(
|
|
5413
|
+
fieldSchemas[fieldName] = this.makeEnumFilterSchema(contextModel, fieldDef, false).optional();
|
|
5363
5414
|
} else if (fieldDef.array) {
|
|
5364
|
-
fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef
|
|
5415
|
+
fieldSchemas[fieldName] = this.makeArrayFilterSchema(contextModel, fieldDef).optional();
|
|
5365
5416
|
} else {
|
|
5366
|
-
fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(
|
|
5417
|
+
fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(contextModel, fieldDef, false).optional();
|
|
5367
5418
|
}
|
|
5368
5419
|
}
|
|
5369
5420
|
}
|
|
5370
5421
|
candidates.push(z2.strictObject(fieldSchemas));
|
|
5371
5422
|
}
|
|
5372
|
-
const recursiveSchema = z2.lazy(() => this.makeTypedJsonFilterSchema(
|
|
5423
|
+
const recursiveSchema = z2.lazy(() => this.makeTypedJsonFilterSchema(contextModel, {
|
|
5424
|
+
name: field,
|
|
5425
|
+
type,
|
|
5426
|
+
optional,
|
|
5427
|
+
array: false
|
|
5428
|
+
})).optional();
|
|
5373
5429
|
if (array) {
|
|
5374
5430
|
candidates.push(z2.strictObject({
|
|
5375
5431
|
some: recursiveSchema,
|
|
@@ -5382,7 +5438,7 @@ var InputValidator = class {
|
|
|
5382
5438
|
isNot: recursiveSchema
|
|
5383
5439
|
}));
|
|
5384
5440
|
}
|
|
5385
|
-
candidates.push(this.makeJsonFilterSchema(optional));
|
|
5441
|
+
candidates.push(this.makeJsonFilterSchema(contextModel, field, optional));
|
|
5386
5442
|
if (optional) {
|
|
5387
5443
|
candidates.push(z2.null());
|
|
5388
5444
|
}
|
|
@@ -5391,14 +5447,18 @@ var InputValidator = class {
|
|
|
5391
5447
|
isTypeDefType(type) {
|
|
5392
5448
|
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
5393
5449
|
}
|
|
5394
|
-
makeEnumFilterSchema(
|
|
5450
|
+
makeEnumFilterSchema(model, fieldInfo, withAggregations, ignoreSlicing = false) {
|
|
5451
|
+
const enumName = fieldInfo.type;
|
|
5452
|
+
const optional = !!fieldInfo.optional;
|
|
5453
|
+
const array = !!fieldInfo.array;
|
|
5395
5454
|
const enumDef = getEnum(this.schema, enumName);
|
|
5396
5455
|
invariant9(enumDef, `Enum "${enumName}" not found in schema`);
|
|
5397
5456
|
const baseSchema = z2.enum(Object.keys(enumDef.values));
|
|
5398
5457
|
if (array) {
|
|
5399
|
-
return this.internalMakeArrayFilterSchema(baseSchema);
|
|
5458
|
+
return this.internalMakeArrayFilterSchema(model, fieldInfo.name, baseSchema);
|
|
5400
5459
|
}
|
|
5401
|
-
const
|
|
5460
|
+
const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(model, fieldInfo.name);
|
|
5461
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z2.lazy(() => this.makeEnumFilterSchema(model, fieldInfo, withAggregations)), [
|
|
5402
5462
|
"equals",
|
|
5403
5463
|
"in",
|
|
5404
5464
|
"notIn",
|
|
@@ -5407,26 +5467,29 @@ var InputValidator = class {
|
|
|
5407
5467
|
"_count",
|
|
5408
5468
|
"_min",
|
|
5409
5469
|
"_max"
|
|
5410
|
-
] : void 0);
|
|
5411
|
-
return
|
|
5412
|
-
this.nullableIf(baseSchema, optional),
|
|
5413
|
-
z2.strictObject(components)
|
|
5414
|
-
]);
|
|
5470
|
+
] : void 0, allowedFilterKinds);
|
|
5471
|
+
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
5415
5472
|
}
|
|
5416
|
-
makeArrayFilterSchema(
|
|
5417
|
-
return this.internalMakeArrayFilterSchema(this.makeScalarSchema(type));
|
|
5473
|
+
makeArrayFilterSchema(model, fieldInfo) {
|
|
5474
|
+
return this.internalMakeArrayFilterSchema(model, fieldInfo.name, this.makeScalarSchema(fieldInfo.type));
|
|
5418
5475
|
}
|
|
5419
|
-
internalMakeArrayFilterSchema(elementSchema) {
|
|
5420
|
-
|
|
5476
|
+
internalMakeArrayFilterSchema(contextModel, field, elementSchema) {
|
|
5477
|
+
const allowedFilterKinds = this.getEffectiveFilterKinds(contextModel, field);
|
|
5478
|
+
const operators = {
|
|
5421
5479
|
equals: elementSchema.array().optional(),
|
|
5422
5480
|
has: elementSchema.optional(),
|
|
5423
5481
|
hasEvery: elementSchema.array().optional(),
|
|
5424
5482
|
hasSome: elementSchema.array().optional(),
|
|
5425
5483
|
isEmpty: z2.boolean().optional()
|
|
5426
|
-
}
|
|
5484
|
+
};
|
|
5485
|
+
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
5486
|
+
return z2.strictObject(filteredOperators);
|
|
5427
5487
|
}
|
|
5428
|
-
makePrimitiveFilterSchema(
|
|
5429
|
-
|
|
5488
|
+
makePrimitiveFilterSchema(contextModel, fieldInfo, withAggregations, ignoreSlicing = false) {
|
|
5489
|
+
const allowedFilterKinds = ignoreSlicing ? void 0 : this.getEffectiveFilterKinds(contextModel, fieldInfo.name);
|
|
5490
|
+
const type = fieldInfo.type;
|
|
5491
|
+
const optional = !!fieldInfo.optional;
|
|
5492
|
+
return match14(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(P3.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(contextModel, fieldInfo.name, optional)).with("Unsupported", () => z2.never()).exhaustive();
|
|
5430
5493
|
}
|
|
5431
5494
|
makeJsonValueSchema(nullable, forFilter) {
|
|
5432
5495
|
const options = [
|
|
@@ -5458,7 +5521,11 @@ var InputValidator = class {
|
|
|
5458
5521
|
]);
|
|
5459
5522
|
return this.nullableIf(schema, nullable);
|
|
5460
5523
|
}
|
|
5461
|
-
makeJsonFilterSchema(optional) {
|
|
5524
|
+
makeJsonFilterSchema(contextModel, field, optional) {
|
|
5525
|
+
const allowedFilterKinds = this.getEffectiveFilterKinds(contextModel, field);
|
|
5526
|
+
if (allowedFilterKinds && !allowedFilterKinds.has("Json")) {
|
|
5527
|
+
return z2.never();
|
|
5528
|
+
}
|
|
5462
5529
|
const valueSchema = this.makeJsonValueSchema(optional, true);
|
|
5463
5530
|
return z2.strictObject({
|
|
5464
5531
|
path: z2.string().optional(),
|
|
@@ -5473,31 +5540,28 @@ var InputValidator = class {
|
|
|
5473
5540
|
array_ends_with: valueSchema.optional()
|
|
5474
5541
|
});
|
|
5475
5542
|
}
|
|
5476
|
-
makeDateTimeFilterSchema(optional, withAggregations) {
|
|
5543
|
+
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5477
5544
|
return this.makeCommonPrimitiveFilterSchema(z2.union([
|
|
5478
5545
|
z2.iso.datetime(),
|
|
5479
5546
|
z2.date()
|
|
5480
|
-
]), optional, () => z2.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
|
|
5547
|
+
]), optional, () => z2.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
5481
5548
|
"_count",
|
|
5482
5549
|
"_min",
|
|
5483
5550
|
"_max"
|
|
5484
|
-
] : void 0);
|
|
5551
|
+
] : void 0, allowedFilterKinds);
|
|
5485
5552
|
}
|
|
5486
|
-
makeBooleanFilterSchema(optional, withAggregations) {
|
|
5487
|
-
const components = this.makeCommonPrimitiveFilterComponents(z2.boolean(), optional, () => z2.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
|
|
5553
|
+
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5554
|
+
const components = this.makeCommonPrimitiveFilterComponents(z2.boolean(), optional, () => z2.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), [
|
|
5488
5555
|
"equals",
|
|
5489
5556
|
"not"
|
|
5490
5557
|
], withAggregations ? [
|
|
5491
5558
|
"_count",
|
|
5492
5559
|
"_min",
|
|
5493
5560
|
"_max"
|
|
5494
|
-
] : void 0);
|
|
5495
|
-
return z2.
|
|
5496
|
-
this.nullableIf(z2.boolean(), optional),
|
|
5497
|
-
z2.strictObject(components)
|
|
5498
|
-
]);
|
|
5561
|
+
] : void 0, allowedFilterKinds);
|
|
5562
|
+
return this.createUnionFilterSchema(z2.boolean(), optional, components, allowedFilterKinds);
|
|
5499
5563
|
}
|
|
5500
|
-
makeBytesFilterSchema(optional, withAggregations) {
|
|
5564
|
+
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5501
5565
|
const baseSchema = z2.instanceof(Uint8Array);
|
|
5502
5566
|
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z2.instanceof(Uint8Array), [
|
|
5503
5567
|
"equals",
|
|
@@ -5508,17 +5572,13 @@ var InputValidator = class {
|
|
|
5508
5572
|
"_count",
|
|
5509
5573
|
"_min",
|
|
5510
5574
|
"_max"
|
|
5511
|
-
] : void 0);
|
|
5512
|
-
return
|
|
5513
|
-
this.nullableIf(baseSchema, optional),
|
|
5514
|
-
z2.strictObject(components)
|
|
5515
|
-
]);
|
|
5575
|
+
] : void 0, allowedFilterKinds);
|
|
5576
|
+
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
5516
5577
|
}
|
|
5517
|
-
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
|
|
5518
|
-
const commonAggSchema = /* @__PURE__ */ __name(() => this.makeCommonPrimitiveFilterSchema(baseSchema, false, makeThis, void 0).optional(), "commonAggSchema");
|
|
5578
|
+
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0, allowedFilterKinds = void 0) {
|
|
5579
|
+
const commonAggSchema = /* @__PURE__ */ __name(() => this.makeCommonPrimitiveFilterSchema(baseSchema, false, makeThis, void 0, allowedFilterKinds).optional(), "commonAggSchema");
|
|
5519
5580
|
let result = {
|
|
5520
5581
|
equals: this.nullableIf(baseSchema.optional(), optional),
|
|
5521
|
-
notEquals: this.nullableIf(baseSchema.optional(), optional),
|
|
5522
5582
|
in: baseSchema.array().optional(),
|
|
5523
5583
|
notIn: baseSchema.array().optional(),
|
|
5524
5584
|
lt: baseSchema.optional(),
|
|
@@ -5528,7 +5588,7 @@ var InputValidator = class {
|
|
|
5528
5588
|
between: baseSchema.array().length(2).optional(),
|
|
5529
5589
|
not: makeThis().optional(),
|
|
5530
5590
|
...withAggregations?.includes("_count") ? {
|
|
5531
|
-
_count: this.makeNumberFilterSchema(z2.number().int(), false, false).optional()
|
|
5591
|
+
_count: this.makeNumberFilterSchema(z2.number().int(), false, false, void 0).optional()
|
|
5532
5592
|
} : {},
|
|
5533
5593
|
...withAggregations?.includes("_avg") ? {
|
|
5534
5594
|
_avg: commonAggSchema()
|
|
@@ -5550,40 +5610,42 @@ var InputValidator = class {
|
|
|
5550
5610
|
];
|
|
5551
5611
|
result = extractFields(result, keys);
|
|
5552
5612
|
}
|
|
5613
|
+
result = this.trimFilterOperators(result, allowedFilterKinds);
|
|
5553
5614
|
return result;
|
|
5554
5615
|
}
|
|
5555
|
-
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
z2.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
|
|
5559
|
-
]);
|
|
5616
|
+
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0, allowedFilterKinds = void 0) {
|
|
5617
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations, allowedFilterKinds);
|
|
5618
|
+
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
5560
5619
|
}
|
|
5561
|
-
makeNumberFilterSchema(baseSchema, optional, withAggregations) {
|
|
5562
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => z2.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
|
|
5620
|
+
makeNumberFilterSchema(baseSchema, optional, withAggregations, allowedFilterKinds) {
|
|
5621
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => z2.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
5563
5622
|
"_count",
|
|
5564
5623
|
"_avg",
|
|
5565
5624
|
"_sum",
|
|
5566
5625
|
"_min",
|
|
5567
5626
|
"_max"
|
|
5568
|
-
] : void 0);
|
|
5627
|
+
] : void 0, allowedFilterKinds);
|
|
5569
5628
|
}
|
|
5570
|
-
makeStringFilterSchema(optional, withAggregations) {
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5629
|
+
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
5630
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z2.string(), optional, () => z2.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)), void 0, withAggregations ? [
|
|
5631
|
+
"_count",
|
|
5632
|
+
"_min",
|
|
5633
|
+
"_max"
|
|
5634
|
+
] : void 0, allowedFilterKinds);
|
|
5635
|
+
const stringSpecificOperators = {
|
|
5636
|
+
startsWith: z2.string().optional(),
|
|
5637
|
+
endsWith: z2.string().optional(),
|
|
5638
|
+
contains: z2.string().optional(),
|
|
5639
|
+
...this.providerSupportsCaseSensitivity ? {
|
|
5640
|
+
mode: this.makeStringModeSchema().optional()
|
|
5641
|
+
} : {}
|
|
5642
|
+
};
|
|
5643
|
+
const filteredStringOperators = this.trimFilterOperators(stringSpecificOperators, allowedFilterKinds);
|
|
5644
|
+
const allComponents = {
|
|
5645
|
+
...baseComponents,
|
|
5646
|
+
...filteredStringOperators
|
|
5647
|
+
};
|
|
5648
|
+
return this.createUnionFilterSchema(z2.string(), optional, allComponents, allowedFilterKinds);
|
|
5587
5649
|
}
|
|
5588
5650
|
makeStringModeSchema() {
|
|
5589
5651
|
return z2.union([
|
|
@@ -5597,7 +5659,9 @@ var InputValidator = class {
|
|
|
5597
5659
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5598
5660
|
const fieldDef = requireField(this.schema, model, field);
|
|
5599
5661
|
if (fieldDef.relation) {
|
|
5600
|
-
|
|
5662
|
+
if (this.isModelAllowed(fieldDef.type)) {
|
|
5663
|
+
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5664
|
+
}
|
|
5601
5665
|
} else {
|
|
5602
5666
|
fields[field] = z2.boolean().optional();
|
|
5603
5667
|
}
|
|
@@ -5677,7 +5741,9 @@ var InputValidator = class {
|
|
|
5677
5741
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5678
5742
|
const fieldDef = requireField(this.schema, model, field);
|
|
5679
5743
|
if (fieldDef.relation) {
|
|
5680
|
-
|
|
5744
|
+
if (this.isModelAllowed(fieldDef.type)) {
|
|
5745
|
+
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5746
|
+
}
|
|
5681
5747
|
}
|
|
5682
5748
|
}
|
|
5683
5749
|
const _countSchema = this.makeCountSelectionSchema(model);
|
|
@@ -5793,6 +5859,9 @@ var InputValidator = class {
|
|
|
5793
5859
|
if (withoutRelationFields) {
|
|
5794
5860
|
return;
|
|
5795
5861
|
}
|
|
5862
|
+
if (!this.isModelAllowed(fieldDef.type)) {
|
|
5863
|
+
return;
|
|
5864
|
+
}
|
|
5796
5865
|
const excludeFields = [];
|
|
5797
5866
|
const oppositeField = fieldDef.relation.opposite;
|
|
5798
5867
|
if (oppositeField) {
|
|
@@ -6020,6 +6089,9 @@ var InputValidator = class {
|
|
|
6020
6089
|
if (withoutRelationFields) {
|
|
6021
6090
|
return;
|
|
6022
6091
|
}
|
|
6092
|
+
if (!this.isModelAllowed(fieldDef.type)) {
|
|
6093
|
+
return;
|
|
6094
|
+
}
|
|
6023
6095
|
const excludeFields = [];
|
|
6024
6096
|
const oppositeField = fieldDef.relation.opposite;
|
|
6025
6097
|
if (oppositeField) {
|
|
@@ -6195,7 +6267,7 @@ var InputValidator = class {
|
|
|
6195
6267
|
] : value.by;
|
|
6196
6268
|
if (value.having && typeof value.having === "object") {
|
|
6197
6269
|
for (const [key, val] of Object.entries(value.having)) {
|
|
6198
|
-
if (
|
|
6270
|
+
if (AggregateOperators.includes(key)) {
|
|
6199
6271
|
continue;
|
|
6200
6272
|
}
|
|
6201
6273
|
if (bys.includes(key)) {
|
|
@@ -6215,7 +6287,7 @@ var InputValidator = class {
|
|
|
6215
6287
|
const bys = typeof value.by === "string" ? [
|
|
6216
6288
|
value.by
|
|
6217
6289
|
] : value.by;
|
|
6218
|
-
if (value.orderBy && Object.keys(value.orderBy).filter((f) => !
|
|
6290
|
+
if (value.orderBy && Object.keys(value.orderBy).filter((f) => !AggregateOperators.includes(f)).some((key) => !bys.includes(key))) {
|
|
6219
6291
|
return false;
|
|
6220
6292
|
} else {
|
|
6221
6293
|
return true;
|
|
@@ -6225,7 +6297,7 @@ var InputValidator = class {
|
|
|
6225
6297
|
}
|
|
6226
6298
|
onlyAggregationFields(val) {
|
|
6227
6299
|
for (const [key, value] of Object.entries(val)) {
|
|
6228
|
-
if (
|
|
6300
|
+
if (AggregateOperators.includes(key)) {
|
|
6229
6301
|
continue;
|
|
6230
6302
|
}
|
|
6231
6303
|
if (LOGICAL_COMBINATORS.includes(key)) {
|
|
@@ -6310,6 +6382,111 @@ var InputValidator = class {
|
|
|
6310
6382
|
get providerSupportsCaseSensitivity() {
|
|
6311
6383
|
return this.schema.provider.type === "postgresql";
|
|
6312
6384
|
}
|
|
6385
|
+
/**
|
|
6386
|
+
* Gets the effective set of allowed FilterKind values for a specific model and field.
|
|
6387
|
+
* Respects the precedence: field-level > model-level $all > global $all.
|
|
6388
|
+
*/
|
|
6389
|
+
getEffectiveFilterKinds(model, field) {
|
|
6390
|
+
if (!model) {
|
|
6391
|
+
return void 0;
|
|
6392
|
+
}
|
|
6393
|
+
const slicing = this.options.slicing;
|
|
6394
|
+
if (!slicing?.models) {
|
|
6395
|
+
return void 0;
|
|
6396
|
+
}
|
|
6397
|
+
const modelConfig = slicing.models[model];
|
|
6398
|
+
if (modelConfig?.fields) {
|
|
6399
|
+
const fieldConfig = modelConfig.fields[field];
|
|
6400
|
+
if (fieldConfig) {
|
|
6401
|
+
return this.computeFilterKinds(fieldConfig.includedFilterKinds, fieldConfig.excludedFilterKinds);
|
|
6402
|
+
}
|
|
6403
|
+
const allFieldsConfig = modelConfig.fields.$all;
|
|
6404
|
+
if (allFieldsConfig) {
|
|
6405
|
+
return this.computeFilterKinds(allFieldsConfig.includedFilterKinds, allFieldsConfig.excludedFilterKinds);
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
const allModelsConfig = slicing.models.$all;
|
|
6409
|
+
if (allModelsConfig?.fields) {
|
|
6410
|
+
if (allModelsConfig.fields.$all) {
|
|
6411
|
+
return this.computeFilterKinds(allModelsConfig.fields.$all.includedFilterKinds, allModelsConfig.fields.$all.excludedFilterKinds);
|
|
6412
|
+
}
|
|
6413
|
+
}
|
|
6414
|
+
return void 0;
|
|
6415
|
+
}
|
|
6416
|
+
/**
|
|
6417
|
+
* Computes the effective set of filter kinds based on inclusion and exclusion lists.
|
|
6418
|
+
*/
|
|
6419
|
+
computeFilterKinds(included, excluded) {
|
|
6420
|
+
let result;
|
|
6421
|
+
if (included !== void 0) {
|
|
6422
|
+
result = new Set(included);
|
|
6423
|
+
}
|
|
6424
|
+
if (excluded !== void 0) {
|
|
6425
|
+
if (!result) {
|
|
6426
|
+
result = /* @__PURE__ */ new Set([
|
|
6427
|
+
"Equality",
|
|
6428
|
+
"Range",
|
|
6429
|
+
"Like",
|
|
6430
|
+
"Json",
|
|
6431
|
+
"List",
|
|
6432
|
+
"Relation"
|
|
6433
|
+
]);
|
|
6434
|
+
}
|
|
6435
|
+
for (const kind of excluded) {
|
|
6436
|
+
result.delete(kind);
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
return result;
|
|
6440
|
+
}
|
|
6441
|
+
/**
|
|
6442
|
+
* Filters operators based on allowed filter kinds.
|
|
6443
|
+
*/
|
|
6444
|
+
trimFilterOperators(operators, allowedKinds) {
|
|
6445
|
+
if (!allowedKinds) {
|
|
6446
|
+
return operators;
|
|
6447
|
+
}
|
|
6448
|
+
return Object.fromEntries(Object.entries(operators).filter(([key, _]) => {
|
|
6449
|
+
return !(key in FILTER_PROPERTY_TO_KIND) || allowedKinds.has(FILTER_PROPERTY_TO_KIND[key]);
|
|
6450
|
+
}));
|
|
6451
|
+
}
|
|
6452
|
+
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
6453
|
+
if (Object.keys(components).length === 0) {
|
|
6454
|
+
if (!allowedFilterKinds || allowedFilterKinds.has("Equality")) {
|
|
6455
|
+
return this.nullableIf(valueSchema, optional);
|
|
6456
|
+
}
|
|
6457
|
+
return z2.never();
|
|
6458
|
+
}
|
|
6459
|
+
if (!allowedFilterKinds || allowedFilterKinds.has("Equality")) {
|
|
6460
|
+
return z2.union([
|
|
6461
|
+
this.nullableIf(valueSchema, optional),
|
|
6462
|
+
z2.strictObject(components)
|
|
6463
|
+
]);
|
|
6464
|
+
} else {
|
|
6465
|
+
return z2.strictObject(components);
|
|
6466
|
+
}
|
|
6467
|
+
}
|
|
6468
|
+
/**
|
|
6469
|
+
* Checks if a model is included in the slicing configuration.
|
|
6470
|
+
* Returns true if the model is allowed, false if it's excluded.
|
|
6471
|
+
*/
|
|
6472
|
+
isModelAllowed(targetModel) {
|
|
6473
|
+
const slicing = this.options.slicing;
|
|
6474
|
+
if (!slicing) {
|
|
6475
|
+
return true;
|
|
6476
|
+
}
|
|
6477
|
+
const { includedModels, excludedModels } = slicing;
|
|
6478
|
+
if (includedModels !== void 0) {
|
|
6479
|
+
if (!includedModels.includes(targetModel)) {
|
|
6480
|
+
return false;
|
|
6481
|
+
}
|
|
6482
|
+
}
|
|
6483
|
+
if (excludedModels !== void 0) {
|
|
6484
|
+
if (excludedModels.includes(targetModel)) {
|
|
6485
|
+
return false;
|
|
6486
|
+
}
|
|
6487
|
+
}
|
|
6488
|
+
return true;
|
|
6489
|
+
}
|
|
6313
6490
|
};
|
|
6314
6491
|
_ts_decorate([
|
|
6315
6492
|
cache(),
|
|
@@ -6359,9 +6536,8 @@ _ts_decorate([
|
|
|
6359
6536
|
cache(),
|
|
6360
6537
|
_ts_metadata("design:type", Function),
|
|
6361
6538
|
_ts_metadata("design:paramtypes", [
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
Boolean
|
|
6539
|
+
Object,
|
|
6540
|
+
typeof FieldInfo === "undefined" ? Object : FieldInfo
|
|
6365
6541
|
]),
|
|
6366
6542
|
_ts_metadata("design:returntype", void 0)
|
|
6367
6543
|
], InputValidator.prototype, "makeTypedJsonFilterSchema", null);
|
|
@@ -6369,8 +6545,8 @@ _ts_decorate([
|
|
|
6369
6545
|
cache(),
|
|
6370
6546
|
_ts_metadata("design:type", Function),
|
|
6371
6547
|
_ts_metadata("design:paramtypes", [
|
|
6372
|
-
|
|
6373
|
-
|
|
6548
|
+
Object,
|
|
6549
|
+
typeof FieldInfo === "undefined" ? Object : FieldInfo,
|
|
6374
6550
|
Boolean,
|
|
6375
6551
|
Boolean
|
|
6376
6552
|
]),
|
|
@@ -6380,7 +6556,8 @@ _ts_decorate([
|
|
|
6380
6556
|
cache(),
|
|
6381
6557
|
_ts_metadata("design:type", Function),
|
|
6382
6558
|
_ts_metadata("design:paramtypes", [
|
|
6383
|
-
|
|
6559
|
+
Object,
|
|
6560
|
+
typeof FieldInfo === "undefined" ? Object : FieldInfo
|
|
6384
6561
|
]),
|
|
6385
6562
|
_ts_metadata("design:returntype", void 0)
|
|
6386
6563
|
], InputValidator.prototype, "makeArrayFilterSchema", null);
|
|
@@ -6388,9 +6565,10 @@ _ts_decorate([
|
|
|
6388
6565
|
cache(),
|
|
6389
6566
|
_ts_metadata("design:type", Function),
|
|
6390
6567
|
_ts_metadata("design:paramtypes", [
|
|
6391
|
-
|
|
6568
|
+
Object,
|
|
6569
|
+
typeof FieldInfo === "undefined" ? Object : FieldInfo,
|
|
6392
6570
|
Boolean,
|
|
6393
|
-
|
|
6571
|
+
void 0
|
|
6394
6572
|
]),
|
|
6395
6573
|
_ts_metadata("design:returntype", void 0)
|
|
6396
6574
|
], InputValidator.prototype, "makePrimitiveFilterSchema", null);
|
|
@@ -6398,6 +6576,8 @@ _ts_decorate([
|
|
|
6398
6576
|
cache(),
|
|
6399
6577
|
_ts_metadata("design:type", Function),
|
|
6400
6578
|
_ts_metadata("design:paramtypes", [
|
|
6579
|
+
Object,
|
|
6580
|
+
String,
|
|
6401
6581
|
Boolean
|
|
6402
6582
|
]),
|
|
6403
6583
|
_ts_metadata("design:returntype", void 0)
|
|
@@ -6407,7 +6587,8 @@ _ts_decorate([
|
|
|
6407
6587
|
_ts_metadata("design:type", Function),
|
|
6408
6588
|
_ts_metadata("design:paramtypes", [
|
|
6409
6589
|
Boolean,
|
|
6410
|
-
Boolean
|
|
6590
|
+
Boolean,
|
|
6591
|
+
Object
|
|
6411
6592
|
]),
|
|
6412
6593
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6413
6594
|
], InputValidator.prototype, "makeDateTimeFilterSchema", null);
|
|
@@ -6416,7 +6597,8 @@ _ts_decorate([
|
|
|
6416
6597
|
_ts_metadata("design:type", Function),
|
|
6417
6598
|
_ts_metadata("design:paramtypes", [
|
|
6418
6599
|
Boolean,
|
|
6419
|
-
Boolean
|
|
6600
|
+
Boolean,
|
|
6601
|
+
Object
|
|
6420
6602
|
]),
|
|
6421
6603
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6422
6604
|
], InputValidator.prototype, "makeBooleanFilterSchema", null);
|
|
@@ -6425,7 +6607,8 @@ _ts_decorate([
|
|
|
6425
6607
|
_ts_metadata("design:type", Function),
|
|
6426
6608
|
_ts_metadata("design:paramtypes", [
|
|
6427
6609
|
Boolean,
|
|
6428
|
-
Boolean
|
|
6610
|
+
Boolean,
|
|
6611
|
+
Object
|
|
6429
6612
|
]),
|
|
6430
6613
|
_ts_metadata("design:returntype", typeof ZodType === "undefined" ? Object : ZodType)
|
|
6431
6614
|
], InputValidator.prototype, "makeBytesFilterSchema", null);
|
|
@@ -8580,6 +8763,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
8580
8763
|
...functions_exports,
|
|
8581
8764
|
...this.$options.functions
|
|
8582
8765
|
};
|
|
8766
|
+
if (!baseClient) {
|
|
8767
|
+
this.validateComputedFieldsConfig();
|
|
8768
|
+
}
|
|
8583
8769
|
if (baseClient) {
|
|
8584
8770
|
this.kyselyProps = {
|
|
8585
8771
|
...baseClient.kyselyProps,
|
|
@@ -8625,6 +8811,26 @@ var ClientImpl = class _ClientImpl {
|
|
|
8625
8811
|
withExecutor(executor) {
|
|
8626
8812
|
return new _ClientImpl(this.schema, this.$options, this, executor);
|
|
8627
8813
|
}
|
|
8814
|
+
/**
|
|
8815
|
+
* Validates that all computed fields in the schema have corresponding configurations.
|
|
8816
|
+
*/
|
|
8817
|
+
validateComputedFieldsConfig() {
|
|
8818
|
+
const computedFieldsConfig = "computedFields" in this.$options ? this.$options.computedFields : void 0;
|
|
8819
|
+
for (const [modelName, modelDef] of Object.entries(this.$schema.models)) {
|
|
8820
|
+
if (modelDef.computedFields) {
|
|
8821
|
+
for (const fieldName of Object.keys(modelDef.computedFields)) {
|
|
8822
|
+
const modelConfig = computedFieldsConfig?.[modelName];
|
|
8823
|
+
const fieldConfig = modelConfig?.[fieldName];
|
|
8824
|
+
if (fieldConfig === null || fieldConfig === void 0) {
|
|
8825
|
+
throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" does not have a configuration. Please provide an implementation in the computedFields option.`);
|
|
8826
|
+
}
|
|
8827
|
+
if (typeof fieldConfig !== "function") {
|
|
8828
|
+
throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" has an invalid configuration: expected a function but received ${typeof fieldConfig}.`);
|
|
8829
|
+
}
|
|
8830
|
+
}
|
|
8831
|
+
}
|
|
8832
|
+
}
|
|
8833
|
+
}
|
|
8628
8834
|
// implementation
|
|
8629
8835
|
async $transaction(input, options) {
|
|
8630
8836
|
invariant14(typeof input === "function" || Array.isArray(input) && input.every((p) => p.then && p.cb), "Invalid transaction input, expected a function or an array of ZenStackPromise");
|
|
@@ -8676,6 +8882,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
8676
8882
|
}
|
|
8677
8883
|
get $procs() {
|
|
8678
8884
|
return Object.keys(this.$schema.procedures ?? {}).reduce((acc, name) => {
|
|
8885
|
+
if (!isProcedureIncluded(this.$options, name)) {
|
|
8886
|
+
return acc;
|
|
8887
|
+
}
|
|
8679
8888
|
acc[name] = (input) => this.handleProc(name, input);
|
|
8680
8889
|
return acc;
|
|
8681
8890
|
}, {});
|
|
@@ -8845,6 +9054,9 @@ function createClientProxy(client) {
|
|
|
8845
9054
|
if (typeof prop === "string") {
|
|
8846
9055
|
const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
|
|
8847
9056
|
if (model) {
|
|
9057
|
+
if (!isModelIncluded(client.$options, model)) {
|
|
9058
|
+
return void 0;
|
|
9059
|
+
}
|
|
8848
9060
|
return createModelCrudHandler(client, model, client.inputValidator, resultProcessor);
|
|
8849
9061
|
}
|
|
8850
9062
|
}
|
|
@@ -8853,6 +9065,44 @@ function createClientProxy(client) {
|
|
|
8853
9065
|
});
|
|
8854
9066
|
}
|
|
8855
9067
|
__name(createClientProxy, "createClientProxy");
|
|
9068
|
+
function isModelIncluded(options, model) {
|
|
9069
|
+
const slicing = options.slicing;
|
|
9070
|
+
if (!slicing) {
|
|
9071
|
+
return true;
|
|
9072
|
+
}
|
|
9073
|
+
const { includedModels, excludedModels } = slicing;
|
|
9074
|
+
if (includedModels !== void 0) {
|
|
9075
|
+
if (!includedModels.includes(model)) {
|
|
9076
|
+
return false;
|
|
9077
|
+
}
|
|
9078
|
+
}
|
|
9079
|
+
if (excludedModels && excludedModels.length > 0) {
|
|
9080
|
+
if (excludedModels.includes(model)) {
|
|
9081
|
+
return false;
|
|
9082
|
+
}
|
|
9083
|
+
}
|
|
9084
|
+
return true;
|
|
9085
|
+
}
|
|
9086
|
+
__name(isModelIncluded, "isModelIncluded");
|
|
9087
|
+
function isProcedureIncluded(options, procedureName) {
|
|
9088
|
+
const slicing = options.slicing;
|
|
9089
|
+
if (!slicing) {
|
|
9090
|
+
return true;
|
|
9091
|
+
}
|
|
9092
|
+
const { includedProcedures, excludedProcedures } = slicing;
|
|
9093
|
+
if (includedProcedures !== void 0) {
|
|
9094
|
+
if (!includedProcedures.includes(procedureName)) {
|
|
9095
|
+
return false;
|
|
9096
|
+
}
|
|
9097
|
+
}
|
|
9098
|
+
if (excludedProcedures && excludedProcedures.length > 0) {
|
|
9099
|
+
if (excludedProcedures.includes(procedureName)) {
|
|
9100
|
+
return false;
|
|
9101
|
+
}
|
|
9102
|
+
}
|
|
9103
|
+
return true;
|
|
9104
|
+
}
|
|
9105
|
+
__name(isProcedureIncluded, "isProcedureIncluded");
|
|
8856
9106
|
function createModelCrudHandler(client, model, inputValidator, resultProcessor) {
|
|
8857
9107
|
const createPromise = /* @__PURE__ */ __name((operation, nominalOperation, args, handler, postProcess = false, throwIfNoResult = false) => {
|
|
8858
9108
|
return createZenStackPromise(async (txClient) => {
|
|
@@ -8894,7 +9144,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
8894
9144
|
return proceed(args);
|
|
8895
9145
|
});
|
|
8896
9146
|
}, "createPromise");
|
|
8897
|
-
|
|
9147
|
+
const operations = {
|
|
8898
9148
|
findUnique: /* @__PURE__ */ __name((args) => {
|
|
8899
9149
|
return createPromise("findUnique", "findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
8900
9150
|
}, "findUnique"),
|
|
@@ -8956,6 +9206,26 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
8956
9206
|
return createPromise("exists", "exists", args, new ExistsOperationHandler(client, model, inputValidator), false);
|
|
8957
9207
|
}, "exists")
|
|
8958
9208
|
};
|
|
9209
|
+
const slicing = client.$options.slicing;
|
|
9210
|
+
if (slicing?.models) {
|
|
9211
|
+
const modelSlicing = slicing.models[model];
|
|
9212
|
+
const allSlicing = slicing.models.$all;
|
|
9213
|
+
const includedOperations = modelSlicing?.includedOperations ?? allSlicing?.includedOperations;
|
|
9214
|
+
const excludedOperations = modelSlicing?.excludedOperations ?? allSlicing?.excludedOperations;
|
|
9215
|
+
if (includedOperations !== void 0) {
|
|
9216
|
+
for (const key of Object.keys(operations)) {
|
|
9217
|
+
if (!includedOperations.includes(key)) {
|
|
9218
|
+
delete operations[key];
|
|
9219
|
+
}
|
|
9220
|
+
}
|
|
9221
|
+
}
|
|
9222
|
+
if (excludedOperations && excludedOperations.length > 0) {
|
|
9223
|
+
for (const operation of excludedOperations) {
|
|
9224
|
+
delete operations[operation];
|
|
9225
|
+
}
|
|
9226
|
+
}
|
|
9227
|
+
}
|
|
9228
|
+
return operations;
|
|
8959
9229
|
}
|
|
8960
9230
|
__name(createModelCrudHandler, "createModelCrudHandler");
|
|
8961
9231
|
|