@zenstackhq/runtime 3.0.0-alpha.20 → 3.0.0-alpha.21
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-XFKcwhq7.d.cts → contract-D8U59Syb.d.cts} +1 -0
- package/dist/{contract-XFKcwhq7.d.ts → contract-D8U59Syb.d.ts} +1 -0
- package/dist/index.cjs +22 -20
- 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 +50 -48
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +14 -10
- 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 +17 -13
- package/dist/plugins/policy/index.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as kysely from 'kysely';
|
|
2
|
-
import { R as RuntimePlugin, V as OnKyselyQueryArgs } from '../../contract-
|
|
2
|
+
import { R as RuntimePlugin, V as OnKyselyQueryArgs } from '../../contract-D8U59Syb.cjs';
|
|
3
3
|
import { SchemaDef } from '@zenstackhq/sdk/schema';
|
|
4
4
|
import 'decimal.js';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as kysely from 'kysely';
|
|
2
|
-
import { R as RuntimePlugin, V as OnKyselyQueryArgs } from '../../contract-
|
|
2
|
+
import { R as RuntimePlugin, V as OnKyselyQueryArgs } from '../../contract-D8U59Syb.js';
|
|
3
3
|
import { SchemaDef } from '@zenstackhq/sdk/schema';
|
|
4
4
|
import 'decimal.js';
|
|
5
5
|
|
|
@@ -354,7 +354,7 @@ __name(aggregate, "aggregate");
|
|
|
354
354
|
|
|
355
355
|
// src/client/crud/dialects/base.ts
|
|
356
356
|
import { invariant, isPlainObject } from "@zenstackhq/common-helpers";
|
|
357
|
-
import { sql } from "kysely";
|
|
357
|
+
import { expressionBuilder, sql } from "kysely";
|
|
358
358
|
import { match as match2, P } from "ts-pattern";
|
|
359
359
|
|
|
360
360
|
// src/utils/enumerate.ts
|
|
@@ -420,7 +420,7 @@ var BaseCrudDialect = class {
|
|
|
420
420
|
if (fieldDef.relation) {
|
|
421
421
|
result = this.and(eb, result, this.buildRelationFilter(eb, model, modelAlias, key, fieldDef, payload));
|
|
422
422
|
} else {
|
|
423
|
-
const fieldRef =
|
|
423
|
+
const fieldRef = this.fieldRef(fieldDef.originModel ?? model, key, eb, fieldDef.originModel ?? modelAlias);
|
|
424
424
|
if (fieldDef.array) {
|
|
425
425
|
result = this.and(eb, result, this.buildArrayFilter(eb, fieldRef, fieldDef, payload));
|
|
426
426
|
} else {
|
|
@@ -743,7 +743,7 @@ var BaseCrudDialect = class {
|
|
|
743
743
|
invariant(value && typeof value === "object", `invalid orderBy value for field "${field}"`);
|
|
744
744
|
for (const [k, v] of Object.entries(value)) {
|
|
745
745
|
invariant(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
|
|
746
|
-
result = result.orderBy((eb) => aggregate(eb,
|
|
746
|
+
result = result.orderBy((eb) => aggregate(eb, this.fieldRef(model, k, eb, modelAlias), field), sql.raw(this.negateSort(v, negated)));
|
|
747
747
|
}
|
|
748
748
|
continue;
|
|
749
749
|
}
|
|
@@ -752,7 +752,7 @@ var BaseCrudDialect = class {
|
|
|
752
752
|
invariant(value && typeof value === "object", 'invalid orderBy value for field "_count"');
|
|
753
753
|
for (const [k, v] of Object.entries(value)) {
|
|
754
754
|
invariant(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
|
|
755
|
-
result = result.orderBy((eb) => eb.fn.count(
|
|
755
|
+
result = result.orderBy((eb) => eb.fn.count(this.fieldRef(model, k, eb, modelAlias)), sql.raw(this.negateSort(v, negated)));
|
|
756
756
|
}
|
|
757
757
|
continue;
|
|
758
758
|
}
|
|
@@ -761,10 +761,11 @@ var BaseCrudDialect = class {
|
|
|
761
761
|
}
|
|
762
762
|
const fieldDef = requireField(this.schema, model, field);
|
|
763
763
|
if (!fieldDef.relation) {
|
|
764
|
+
const fieldRef = this.fieldRef(model, field, expressionBuilder(), modelAlias);
|
|
764
765
|
if (value === "asc" || value === "desc") {
|
|
765
|
-
result = result.orderBy(
|
|
766
|
+
result = result.orderBy(fieldRef, this.negateSort(value, negated));
|
|
766
767
|
} else if (value && typeof value === "object" && "nulls" in value && "sort" in value && (value.sort === "asc" || value.sort === "desc") && (value.nulls === "first" || value.nulls === "last")) {
|
|
767
|
-
result = result.orderBy(
|
|
768
|
+
result = result.orderBy(fieldRef, sql.raw(`${this.negateSort(value.sort, negated)} nulls ${value.nulls}`));
|
|
768
769
|
}
|
|
769
770
|
} else {
|
|
770
771
|
const relationModel = fieldDef.type;
|
|
@@ -826,7 +827,7 @@ var BaseCrudDialect = class {
|
|
|
826
827
|
buildSelectField(query, model, modelAlias, field) {
|
|
827
828
|
const fieldDef = requireField(this.schema, model, field);
|
|
828
829
|
if (fieldDef.computed) {
|
|
829
|
-
return query.select((eb) =>
|
|
830
|
+
return query.select((eb) => this.fieldRef(model, field, eb, modelAlias).as(field));
|
|
830
831
|
} else if (!fieldDef.originModel) {
|
|
831
832
|
return query.select(sql.ref(`${modelAlias}.${field}`).as(field));
|
|
832
833
|
} else {
|
|
@@ -917,6 +918,9 @@ var BaseCrudDialect = class {
|
|
|
917
918
|
not(eb, ...args) {
|
|
918
919
|
return eb.not(this.and(eb, ...args));
|
|
919
920
|
}
|
|
921
|
+
fieldRef(model, field, eb, modelAlias) {
|
|
922
|
+
return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias);
|
|
923
|
+
}
|
|
920
924
|
};
|
|
921
925
|
|
|
922
926
|
// src/client/crud/dialects/postgresql.ts
|
|
@@ -1010,7 +1014,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1010
1014
|
if (payload === true || !payload.select) {
|
|
1011
1015
|
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !(typeof payload === "object" && payload.omit?.[name] === true)).map(([field]) => [
|
|
1012
1016
|
sql2.lit(field),
|
|
1013
|
-
|
|
1017
|
+
this.fieldRef(relationModel, field, eb)
|
|
1014
1018
|
]).flatMap((v) => v));
|
|
1015
1019
|
} else if (payload.select) {
|
|
1016
1020
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
@@ -1022,7 +1026,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1022
1026
|
];
|
|
1023
1027
|
} else {
|
|
1024
1028
|
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1025
|
-
const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) :
|
|
1029
|
+
const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : this.fieldRef(relationModel, field, eb);
|
|
1026
1030
|
return [
|
|
1027
1031
|
sql2.lit(field),
|
|
1028
1032
|
fieldValue
|
|
@@ -1173,7 +1177,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1173
1177
|
if (payload === true || !payload.select) {
|
|
1174
1178
|
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !(typeof payload === "object" && payload.omit?.[name] === true)).map(([field]) => [
|
|
1175
1179
|
sql3.lit(field),
|
|
1176
|
-
|
|
1180
|
+
this.fieldRef(relationModel, field, eb)
|
|
1177
1181
|
]).flatMap((v) => v));
|
|
1178
1182
|
} else if (payload.select) {
|
|
1179
1183
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
@@ -1194,7 +1198,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1194
1198
|
} else {
|
|
1195
1199
|
return [
|
|
1196
1200
|
sql3.lit(field),
|
|
1197
|
-
|
|
1201
|
+
this.fieldRef(relationModel, field, eb)
|
|
1198
1202
|
];
|
|
1199
1203
|
}
|
|
1200
1204
|
}
|
|
@@ -1583,7 +1587,7 @@ var ColumnCollector = class extends DefaultOperationNodeVisitor {
|
|
|
1583
1587
|
|
|
1584
1588
|
// src/plugins/policy/expression-transformer.ts
|
|
1585
1589
|
import { invariant as invariant5 } from "@zenstackhq/common-helpers";
|
|
1586
|
-
import { AliasNode as AliasNode2, BinaryOperationNode as BinaryOperationNode2, ColumnNode, expressionBuilder, FromNode, FunctionNode as FunctionNode2, IdentifierNode, OperatorNode as OperatorNode2, ReferenceNode as ReferenceNode2, SelectionNode, SelectQueryNode, TableNode as TableNode2, ValueListNode, ValueNode as ValueNode2, WhereNode } from "kysely";
|
|
1590
|
+
import { AliasNode as AliasNode2, BinaryOperationNode as BinaryOperationNode2, ColumnNode, expressionBuilder as expressionBuilder2, FromNode, FunctionNode as FunctionNode2, IdentifierNode, OperatorNode as OperatorNode2, ReferenceNode as ReferenceNode2, SelectionNode, SelectQueryNode, TableNode as TableNode2, ValueListNode, ValueNode as ValueNode2, WhereNode } from "kysely";
|
|
1587
1591
|
import { match as match7 } from "ts-pattern";
|
|
1588
1592
|
|
|
1589
1593
|
// src/plugins/policy/expression-evaluator.ts
|
|
@@ -1940,7 +1944,7 @@ var ExpressionTransformer = class {
|
|
|
1940
1944
|
if (!func) {
|
|
1941
1945
|
throw new QueryError(`Function not implemented: ${expr2.function}`);
|
|
1942
1946
|
}
|
|
1943
|
-
const eb =
|
|
1947
|
+
const eb = expressionBuilder2();
|
|
1944
1948
|
return func(eb, (expr2.args ?? []).map((arg) => this.transformCallArg(eb, arg, context)), {
|
|
1945
1949
|
dialect: this.dialect,
|
|
1946
1950
|
model: context.model,
|