@zenstackhq/runtime 3.0.0-alpha.22 → 3.0.0-alpha.24
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-D8U59Syb.d.cts → contract-C9SubPBD.d.cts} +92 -87
- package/dist/{contract-D8U59Syb.d.ts → contract-C9SubPBD.d.ts} +92 -87
- package/dist/index.cjs +31 -34
- 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 +32 -35
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -5908,7 +5908,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely13
|
|
|
5908
5908
|
await this.callBeforeMutationHooks(queryNode, mutationInterceptionInfo);
|
|
5909
5909
|
}
|
|
5910
5910
|
const oldQueryNode = queryNode;
|
|
5911
|
-
if ((import_kysely13.InsertQueryNode.is(queryNode) || import_kysely13.UpdateQueryNode.is(queryNode)) && mutationInterceptionInfo?.
|
|
5911
|
+
if ((import_kysely13.InsertQueryNode.is(queryNode) || import_kysely13.UpdateQueryNode.is(queryNode)) && mutationInterceptionInfo?.loadAfterMutationEntities) {
|
|
5912
5912
|
queryNode = {
|
|
5913
5913
|
...queryNode,
|
|
5914
5914
|
returning: import_kysely13.ReturningNode.create([
|
|
@@ -6015,7 +6015,7 @@ ${compiled.parameters.map((p) => (0, import_node_util2.inspect)(p)).join("\n")}`
|
|
|
6015
6015
|
return newExecutor;
|
|
6016
6016
|
}
|
|
6017
6017
|
get hasMutationHooks() {
|
|
6018
|
-
return this.client.$options.plugins?.some((plugin) => plugin.
|
|
6018
|
+
return this.client.$options.plugins?.some((plugin) => !!plugin.onEntityMutation);
|
|
6019
6019
|
}
|
|
6020
6020
|
getMutationModel(queryNode) {
|
|
6021
6021
|
return (0, import_ts_pattern16.match)(queryNode).when(import_kysely13.InsertQueryNode.is, (node) => node.into.table.identifier.name).when(import_kysely13.UpdateQueryNode.is, (node) => node.table.table.identifier.name).when(import_kysely13.DeleteQueryNode.is, (node) => {
|
|
@@ -6045,21 +6045,25 @@ ${compiled.parameters.map((p) => (0, import_node_util2.inspect)(p)).join("\n")}`
|
|
|
6045
6045
|
where: node.where
|
|
6046
6046
|
})).exhaustive();
|
|
6047
6047
|
for (const plugin of plugins) {
|
|
6048
|
-
|
|
6048
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6049
|
+
if (!onEntityMutation) {
|
|
6050
|
+
continue;
|
|
6051
|
+
}
|
|
6052
|
+
if (!onEntityMutation.mutationInterceptionFilter) {
|
|
6049
6053
|
result.intercept = true;
|
|
6050
6054
|
} else {
|
|
6051
|
-
const filterResult = await
|
|
6055
|
+
const filterResult = await onEntityMutation.mutationInterceptionFilter({
|
|
6052
6056
|
model: mutationModel,
|
|
6053
6057
|
action,
|
|
6054
6058
|
queryNode
|
|
6055
6059
|
});
|
|
6056
6060
|
result.intercept ||= filterResult.intercept;
|
|
6057
|
-
result.
|
|
6058
|
-
result.
|
|
6061
|
+
result.loadBeforeMutationEntities ||= filterResult.loadBeforeMutationEntities;
|
|
6062
|
+
result.loadAfterMutationEntities ||= filterResult.loadAfterMutationEntities;
|
|
6059
6063
|
}
|
|
6060
6064
|
}
|
|
6061
6065
|
let beforeMutationEntities;
|
|
6062
|
-
if (result.
|
|
6066
|
+
if (result.loadBeforeMutationEntities && (import_kysely13.UpdateQueryNode.is(queryNode) || import_kysely13.DeleteQueryNode.is(queryNode))) {
|
|
6063
6067
|
beforeMutationEntities = await this.loadEntities(mutationModel, where);
|
|
6064
6068
|
}
|
|
6065
6069
|
return {
|
|
@@ -6080,8 +6084,9 @@ ${compiled.parameters.map((p) => (0, import_node_util2.inspect)(p)).join("\n")}`
|
|
|
6080
6084
|
if (this.options.plugins) {
|
|
6081
6085
|
const mutationModel = this.getMutationModel(queryNode);
|
|
6082
6086
|
for (const plugin of this.options.plugins) {
|
|
6083
|
-
|
|
6084
|
-
|
|
6087
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6088
|
+
if (onEntityMutation?.beforeEntityMutation) {
|
|
6089
|
+
await onEntityMutation.beforeEntityMutation({
|
|
6085
6090
|
model: mutationModel,
|
|
6086
6091
|
action: mutationInterceptionInfo.action,
|
|
6087
6092
|
queryNode,
|
|
@@ -6097,8 +6102,9 @@ ${compiled.parameters.map((p) => (0, import_node_util2.inspect)(p)).join("\n")}`
|
|
|
6097
6102
|
}
|
|
6098
6103
|
const hooks = [];
|
|
6099
6104
|
for (const plugin of this.options.plugins ?? []) {
|
|
6100
|
-
|
|
6101
|
-
|
|
6105
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6106
|
+
if (onEntityMutation?.afterEntityMutation) {
|
|
6107
|
+
hooks.push(onEntityMutation.afterEntityMutation.bind(plugin));
|
|
6102
6108
|
}
|
|
6103
6109
|
}
|
|
6104
6110
|
if (hooks.length === 0) {
|
|
@@ -6108,7 +6114,7 @@ ${compiled.parameters.map((p) => (0, import_node_util2.inspect)(p)).join("\n")}`
|
|
|
6108
6114
|
const inTransaction = this.driver.isTransactionConnection(connection);
|
|
6109
6115
|
for (const hook of hooks) {
|
|
6110
6116
|
let afterMutationEntities = void 0;
|
|
6111
|
-
if (mutationInterceptionInfo.
|
|
6117
|
+
if (mutationInterceptionInfo.loadAfterMutationEntities) {
|
|
6112
6118
|
if (import_kysely13.InsertQueryNode.is(queryNode) || import_kysely13.UpdateQueryNode.is(queryNode)) {
|
|
6113
6119
|
afterMutationEntities = queryResult.rows;
|
|
6114
6120
|
}
|
|
@@ -6896,7 +6902,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6896
6902
|
return createZenStackPromise(async (txClient) => {
|
|
6897
6903
|
let proceed = /* @__PURE__ */ __name(async (_args) => {
|
|
6898
6904
|
const _handler = txClient ? handler.withClient(txClient) : handler;
|
|
6899
|
-
const r = await _handler.handle(operation, _args
|
|
6905
|
+
const r = await _handler.handle(operation, _args);
|
|
6900
6906
|
if (!r && throwIfNoResult) {
|
|
6901
6907
|
throw new NotFoundError(model);
|
|
6902
6908
|
}
|
|
@@ -6912,27 +6918,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6912
6918
|
...client.$options.plugins ?? []
|
|
6913
6919
|
];
|
|
6914
6920
|
for (const plugin of plugins) {
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
args,
|
|
6928
|
-
query: _proceed
|
|
6929
|
-
}), "proceed");
|
|
6930
|
-
}
|
|
6931
|
-
}
|
|
6932
|
-
}
|
|
6933
|
-
}
|
|
6934
|
-
}
|
|
6935
|
-
}
|
|
6921
|
+
const onQuery = plugin.onQuery;
|
|
6922
|
+
if (onQuery) {
|
|
6923
|
+
const _proceed = proceed;
|
|
6924
|
+
proceed = /* @__PURE__ */ __name((_args) => onQuery({
|
|
6925
|
+
client,
|
|
6926
|
+
model,
|
|
6927
|
+
operation,
|
|
6928
|
+
// reflect the latest override if provided
|
|
6929
|
+
args: _args,
|
|
6930
|
+
// ensure inner overrides are propagated to the previous proceed
|
|
6931
|
+
proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
|
|
6932
|
+
}), "proceed");
|
|
6936
6933
|
}
|
|
6937
6934
|
}
|
|
6938
6935
|
return proceed(args);
|