@zenstackhq/runtime 3.0.0-alpha.25 → 3.0.0-alpha.27
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/{contract-BOWN0dwS.d.cts → contract-c8GpEAl3.d.cts} +17 -14
- package/dist/{contract-BOWN0dwS.d.ts → contract-c8GpEAl3.d.ts} +17 -14
- package/dist/index.cjs +120 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +120 -152
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +59 -24
- package/dist/plugins/policy/index.cjs.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/dist/plugins/policy/index.js +59 -24
- package/dist/plugins/policy/index.js.map +1 -1
- package/package.json +8 -8
|
@@ -362,6 +362,16 @@ function flattenCompoundUniqueFilters(schema, model, filter) {
|
|
|
362
362
|
return result;
|
|
363
363
|
}
|
|
364
364
|
__name(flattenCompoundUniqueFilters, "flattenCompoundUniqueFilters");
|
|
365
|
+
function ensureArray(value) {
|
|
366
|
+
if (Array.isArray(value)) {
|
|
367
|
+
return value;
|
|
368
|
+
} else {
|
|
369
|
+
return [
|
|
370
|
+
value
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
__name(ensureArray, "ensureArray");
|
|
365
375
|
function getDelegateDescendantModels(schema, model, collected = /* @__PURE__ */ new Set()) {
|
|
366
376
|
const subModels = Object.values(schema.models).filter((m) => m.baseModel === model);
|
|
367
377
|
subModels.forEach((def) => {
|
|
@@ -424,6 +434,33 @@ var BaseCrudDialect = class {
|
|
|
424
434
|
}
|
|
425
435
|
return result;
|
|
426
436
|
}
|
|
437
|
+
buildFilterSortTake(model, args, query) {
|
|
438
|
+
let result = query;
|
|
439
|
+
if (args.where) {
|
|
440
|
+
result = result.where((eb) => this.buildFilter(eb, model, model, args?.where));
|
|
441
|
+
}
|
|
442
|
+
let negateOrderBy = false;
|
|
443
|
+
const skip = args.skip;
|
|
444
|
+
let take = args.take;
|
|
445
|
+
if (take !== void 0 && take < 0) {
|
|
446
|
+
negateOrderBy = true;
|
|
447
|
+
take = -take;
|
|
448
|
+
}
|
|
449
|
+
result = this.buildSkipTake(result, skip, take);
|
|
450
|
+
result = this.buildOrderBy(result, model, model, args.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
451
|
+
if ("distinct" in args && args.distinct) {
|
|
452
|
+
const distinct = ensureArray(args.distinct);
|
|
453
|
+
if (this.supportsDistinctOn) {
|
|
454
|
+
result = result.distinctOn(distinct.map((f) => import_kysely.sql.ref(`${model}.${f}`)));
|
|
455
|
+
} else {
|
|
456
|
+
throw new QueryError(`"distinct" is not supported by "${this.schema.provider.type}" provider`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (args.cursor) {
|
|
460
|
+
result = this.buildCursorFilter(model, result, args.cursor, args.orderBy, negateOrderBy);
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
427
464
|
buildFilter(eb, model, modelAlias, where) {
|
|
428
465
|
if (where === true || where === void 0) {
|
|
429
466
|
return this.true(eb);
|
|
@@ -461,6 +498,26 @@ var BaseCrudDialect = class {
|
|
|
461
498
|
}
|
|
462
499
|
return result;
|
|
463
500
|
}
|
|
501
|
+
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
|
|
502
|
+
const _orderBy = orderBy ?? makeDefaultOrderBy(this.schema, model);
|
|
503
|
+
const orderByItems = ensureArray(_orderBy).flatMap((obj) => Object.entries(obj));
|
|
504
|
+
const eb = (0, import_kysely.expressionBuilder)();
|
|
505
|
+
const cursorFilter = this.buildFilter(eb, model, model, cursor);
|
|
506
|
+
let result = query;
|
|
507
|
+
const filters = [];
|
|
508
|
+
for (let i = orderByItems.length - 1; i >= 0; i--) {
|
|
509
|
+
const andFilters = [];
|
|
510
|
+
for (let j = 0; j <= i; j++) {
|
|
511
|
+
const [field, order] = orderByItems[j];
|
|
512
|
+
const _order = negateOrderBy ? order === "asc" ? "desc" : "asc" : order;
|
|
513
|
+
const op = j === i ? _order === "asc" ? ">=" : "<=" : "=";
|
|
514
|
+
andFilters.push(eb(eb.ref(`${model}.${field}`), op, eb.selectFrom(model).select(`${model}.${field}`).where(cursorFilter)));
|
|
515
|
+
}
|
|
516
|
+
filters.push(eb.and(andFilters));
|
|
517
|
+
}
|
|
518
|
+
result = result.where((eb2) => eb2.or(filters));
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
464
521
|
isLogicalCombinator(key) {
|
|
465
522
|
return LOGICAL_COMBINATORS.includes(key);
|
|
466
523
|
}
|
|
@@ -987,18 +1044,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
987
1044
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
988
1045
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
989
1046
|
if (payload && typeof payload === "object") {
|
|
990
|
-
|
|
991
|
-
subQuery = subQuery.where((eb2) => this.buildFilter(eb2, relationModel, relationModel, payload.where));
|
|
992
|
-
}
|
|
993
|
-
const skip = payload.skip;
|
|
994
|
-
let take = payload.take;
|
|
995
|
-
let negateOrderBy = false;
|
|
996
|
-
if (take !== void 0 && take < 0) {
|
|
997
|
-
negateOrderBy = true;
|
|
998
|
-
take = -take;
|
|
999
|
-
}
|
|
1000
|
-
subQuery = this.buildSkipTake(subQuery, skip, take);
|
|
1001
|
-
subQuery = this.buildOrderBy(subQuery, relationModel, relationModel, payload.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
1047
|
+
subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
|
|
1002
1048
|
}
|
|
1003
1049
|
const m2m = getManyToManyRelation(this.schema, model, relationField);
|
|
1004
1050
|
if (m2m) {
|
|
@@ -1161,18 +1207,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1161
1207
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
1162
1208
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
1163
1209
|
if (payload && typeof payload === "object") {
|
|
1164
|
-
|
|
1165
|
-
subQuery = subQuery.where((eb2) => this.buildFilter(eb2, relationModel, relationModel, payload.where));
|
|
1166
|
-
}
|
|
1167
|
-
const skip = payload.skip;
|
|
1168
|
-
let take = payload.take;
|
|
1169
|
-
let negateOrderBy = false;
|
|
1170
|
-
if (take !== void 0 && take < 0) {
|
|
1171
|
-
negateOrderBy = true;
|
|
1172
|
-
take = -take;
|
|
1173
|
-
}
|
|
1174
|
-
subQuery = this.buildSkipTake(subQuery, skip, take);
|
|
1175
|
-
subQuery = this.buildOrderBy(subQuery, relationModel, relationModel, payload.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
1210
|
+
subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
|
|
1176
1211
|
}
|
|
1177
1212
|
const m2m = getManyToManyRelation(this.schema, model, relationField);
|
|
1178
1213
|
if (m2m) {
|