@zenstackhq/orm 3.4.0-beta.2 → 3.4.0-beta.4
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 +28 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +32 -26
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -5062,6 +5062,9 @@ var InputValidator = class {
|
|
|
5062
5062
|
}
|
|
5063
5063
|
client;
|
|
5064
5064
|
schemaCache = /* @__PURE__ */ new Map();
|
|
5065
|
+
allFilterKinds = [
|
|
5066
|
+
...new Set(Object.values(FILTER_PROPERTY_TO_KIND))
|
|
5067
|
+
];
|
|
5065
5068
|
constructor(client) {
|
|
5066
5069
|
this.client = client;
|
|
5067
5070
|
}
|
|
@@ -5346,7 +5349,7 @@ var InputValidator = class {
|
|
|
5346
5349
|
continue;
|
|
5347
5350
|
}
|
|
5348
5351
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
5349
|
-
if (allowedFilterKinds && !allowedFilterKinds.
|
|
5352
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) {
|
|
5350
5353
|
fieldSchema = import_zod2.z.never();
|
|
5351
5354
|
} else {
|
|
5352
5355
|
fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
@@ -5568,7 +5571,7 @@ var InputValidator = class {
|
|
|
5568
5571
|
}
|
|
5569
5572
|
makeJsonFilterSchema(contextModel, field, optional) {
|
|
5570
5573
|
const allowedFilterKinds = this.getEffectiveFilterKinds(contextModel, field);
|
|
5571
|
-
if (allowedFilterKinds && !allowedFilterKinds.
|
|
5574
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) {
|
|
5572
5575
|
return import_zod2.z.never();
|
|
5573
5576
|
}
|
|
5574
5577
|
const valueSchema = this.makeJsonValueSchema(optional, true);
|
|
@@ -6429,7 +6432,7 @@ var InputValidator = class {
|
|
|
6429
6432
|
}
|
|
6430
6433
|
/**
|
|
6431
6434
|
* Gets the effective set of allowed FilterKind values for a specific model and field.
|
|
6432
|
-
* Respects the precedence: field
|
|
6435
|
+
* Respects the precedence: model[field] > model.$all > $all[field] > $all.$all.
|
|
6433
6436
|
*/
|
|
6434
6437
|
getEffectiveFilterKinds(model, field) {
|
|
6435
6438
|
if (!model) {
|
|
@@ -6439,21 +6442,27 @@ var InputValidator = class {
|
|
|
6439
6442
|
if (!slicing?.models) {
|
|
6440
6443
|
return void 0;
|
|
6441
6444
|
}
|
|
6442
|
-
const
|
|
6445
|
+
const modelsRecord = slicing.models;
|
|
6446
|
+
const modelConfig = modelsRecord[(0, import_common_helpers9.lowerCaseFirst)(model)];
|
|
6443
6447
|
if (modelConfig?.fields) {
|
|
6444
6448
|
const fieldConfig = modelConfig.fields[field];
|
|
6445
6449
|
if (fieldConfig) {
|
|
6446
6450
|
return this.computeFilterKinds(fieldConfig.includedFilterKinds, fieldConfig.excludedFilterKinds);
|
|
6447
6451
|
}
|
|
6448
|
-
const allFieldsConfig = modelConfig.fields
|
|
6452
|
+
const allFieldsConfig = modelConfig.fields["$all"];
|
|
6449
6453
|
if (allFieldsConfig) {
|
|
6450
6454
|
return this.computeFilterKinds(allFieldsConfig.includedFilterKinds, allFieldsConfig.excludedFilterKinds);
|
|
6451
6455
|
}
|
|
6452
6456
|
}
|
|
6453
|
-
const allModelsConfig =
|
|
6457
|
+
const allModelsConfig = modelsRecord["$all"];
|
|
6454
6458
|
if (allModelsConfig?.fields) {
|
|
6455
|
-
|
|
6456
|
-
|
|
6459
|
+
const allModelsFieldConfig = allModelsConfig.fields[field];
|
|
6460
|
+
if (allModelsFieldConfig) {
|
|
6461
|
+
return this.computeFilterKinds(allModelsFieldConfig.includedFilterKinds, allModelsFieldConfig.excludedFilterKinds);
|
|
6462
|
+
}
|
|
6463
|
+
const allModelsAllFieldsConfig = allModelsConfig.fields["$all"];
|
|
6464
|
+
if (allModelsAllFieldsConfig) {
|
|
6465
|
+
return this.computeFilterKinds(allModelsAllFieldsConfig.includedFilterKinds, allModelsAllFieldsConfig.excludedFilterKinds);
|
|
6457
6466
|
}
|
|
6458
6467
|
}
|
|
6459
6468
|
return void 0;
|
|
@@ -6464,21 +6473,18 @@ var InputValidator = class {
|
|
|
6464
6473
|
computeFilterKinds(included, excluded) {
|
|
6465
6474
|
let result;
|
|
6466
6475
|
if (included !== void 0) {
|
|
6467
|
-
result =
|
|
6476
|
+
result = [
|
|
6477
|
+
...included
|
|
6478
|
+
];
|
|
6468
6479
|
}
|
|
6469
6480
|
if (excluded !== void 0) {
|
|
6470
6481
|
if (!result) {
|
|
6471
|
-
result =
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
"Like",
|
|
6475
|
-
"Json",
|
|
6476
|
-
"List",
|
|
6477
|
-
"Relation"
|
|
6478
|
-
]);
|
|
6482
|
+
result = [
|
|
6483
|
+
...this.allFilterKinds
|
|
6484
|
+
];
|
|
6479
6485
|
}
|
|
6480
6486
|
for (const kind of excluded) {
|
|
6481
|
-
result.
|
|
6487
|
+
result = result.filter((k) => k !== kind);
|
|
6482
6488
|
}
|
|
6483
6489
|
}
|
|
6484
6490
|
return result;
|
|
@@ -6491,17 +6497,17 @@ var InputValidator = class {
|
|
|
6491
6497
|
return operators;
|
|
6492
6498
|
}
|
|
6493
6499
|
return Object.fromEntries(Object.entries(operators).filter(([key, _]) => {
|
|
6494
|
-
return !(key in FILTER_PROPERTY_TO_KIND) || allowedKinds.
|
|
6500
|
+
return !(key in FILTER_PROPERTY_TO_KIND) || allowedKinds.includes(FILTER_PROPERTY_TO_KIND[key]);
|
|
6495
6501
|
}));
|
|
6496
6502
|
}
|
|
6497
6503
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
6498
6504
|
if (Object.keys(components).length === 0) {
|
|
6499
|
-
if (!allowedFilterKinds || allowedFilterKinds.
|
|
6505
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) {
|
|
6500
6506
|
return this.nullableIf(valueSchema, optional);
|
|
6501
6507
|
}
|
|
6502
6508
|
return import_zod2.z.never();
|
|
6503
6509
|
}
|
|
6504
|
-
if (!allowedFilterKinds || allowedFilterKinds.
|
|
6510
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) {
|
|
6505
6511
|
return import_zod2.z.union([
|
|
6506
6512
|
this.nullableIf(valueSchema, optional),
|
|
6507
6513
|
import_zod2.z.strictObject(components)
|
|
@@ -9253,7 +9259,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
9253
9259
|
};
|
|
9254
9260
|
const slicing = client.$options.slicing;
|
|
9255
9261
|
if (slicing?.models) {
|
|
9256
|
-
const modelSlicing = slicing.models[model];
|
|
9262
|
+
const modelSlicing = slicing.models[(0, import_common_helpers14.lowerCaseFirst)(model)];
|
|
9257
9263
|
const allSlicing = slicing.models.$all;
|
|
9258
9264
|
const includedOperations = modelSlicing?.includedOperations ?? allSlicing?.includedOperations;
|
|
9259
9265
|
const excludedOperations = modelSlicing?.excludedOperations ?? allSlicing?.excludedOperations;
|