@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.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClientConstructor } from './contract-
|
|
2
|
-
export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-
|
|
1
|
+
import { C as ClientConstructor } from './contract-C9SubPBD.cjs';
|
|
2
|
+
export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-C9SubPBD.cjs';
|
|
3
3
|
import 'decimal.js';
|
|
4
4
|
import '@zenstackhq/sdk/schema';
|
|
5
5
|
import 'kysely';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClientConstructor } from './contract-
|
|
2
|
-
export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-
|
|
1
|
+
import { C as ClientConstructor } from './contract-C9SubPBD.js';
|
|
2
|
+
export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-C9SubPBD.js';
|
|
3
3
|
import 'decimal.js';
|
|
4
4
|
import '@zenstackhq/sdk/schema';
|
|
5
5
|
import 'kysely';
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/client/client-impl.ts
|
|
9
|
-
import { invariant as invariant12
|
|
9
|
+
import { invariant as invariant12 } from "@zenstackhq/common-helpers";
|
|
10
10
|
import { CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor as DefaultQueryExecutor2, Kysely, Log, sql as sql9 } from "kysely";
|
|
11
11
|
|
|
12
12
|
// src/client/crud/operations/aggregate.ts
|
|
@@ -5873,7 +5873,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends DefaultQueryExe
|
|
|
5873
5873
|
await this.callBeforeMutationHooks(queryNode, mutationInterceptionInfo);
|
|
5874
5874
|
}
|
|
5875
5875
|
const oldQueryNode = queryNode;
|
|
5876
|
-
if ((InsertQueryNode2.is(queryNode) || UpdateQueryNode2.is(queryNode)) && mutationInterceptionInfo?.
|
|
5876
|
+
if ((InsertQueryNode2.is(queryNode) || UpdateQueryNode2.is(queryNode)) && mutationInterceptionInfo?.loadAfterMutationEntities) {
|
|
5877
5877
|
queryNode = {
|
|
5878
5878
|
...queryNode,
|
|
5879
5879
|
returning: ReturningNode3.create([
|
|
@@ -5980,7 +5980,7 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
5980
5980
|
return newExecutor;
|
|
5981
5981
|
}
|
|
5982
5982
|
get hasMutationHooks() {
|
|
5983
|
-
return this.client.$options.plugins?.some((plugin) => plugin.
|
|
5983
|
+
return this.client.$options.plugins?.some((plugin) => !!plugin.onEntityMutation);
|
|
5984
5984
|
}
|
|
5985
5985
|
getMutationModel(queryNode) {
|
|
5986
5986
|
return match16(queryNode).when(InsertQueryNode2.is, (node) => node.into.table.identifier.name).when(UpdateQueryNode2.is, (node) => node.table.table.identifier.name).when(DeleteQueryNode2.is, (node) => {
|
|
@@ -6010,21 +6010,25 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6010
6010
|
where: node.where
|
|
6011
6011
|
})).exhaustive();
|
|
6012
6012
|
for (const plugin of plugins) {
|
|
6013
|
-
|
|
6013
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6014
|
+
if (!onEntityMutation) {
|
|
6015
|
+
continue;
|
|
6016
|
+
}
|
|
6017
|
+
if (!onEntityMutation.mutationInterceptionFilter) {
|
|
6014
6018
|
result.intercept = true;
|
|
6015
6019
|
} else {
|
|
6016
|
-
const filterResult = await
|
|
6020
|
+
const filterResult = await onEntityMutation.mutationInterceptionFilter({
|
|
6017
6021
|
model: mutationModel,
|
|
6018
6022
|
action,
|
|
6019
6023
|
queryNode
|
|
6020
6024
|
});
|
|
6021
6025
|
result.intercept ||= filterResult.intercept;
|
|
6022
|
-
result.
|
|
6023
|
-
result.
|
|
6026
|
+
result.loadBeforeMutationEntities ||= filterResult.loadBeforeMutationEntities;
|
|
6027
|
+
result.loadAfterMutationEntities ||= filterResult.loadAfterMutationEntities;
|
|
6024
6028
|
}
|
|
6025
6029
|
}
|
|
6026
6030
|
let beforeMutationEntities;
|
|
6027
|
-
if (result.
|
|
6031
|
+
if (result.loadBeforeMutationEntities && (UpdateQueryNode2.is(queryNode) || DeleteQueryNode2.is(queryNode))) {
|
|
6028
6032
|
beforeMutationEntities = await this.loadEntities(mutationModel, where);
|
|
6029
6033
|
}
|
|
6030
6034
|
return {
|
|
@@ -6045,8 +6049,9 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6045
6049
|
if (this.options.plugins) {
|
|
6046
6050
|
const mutationModel = this.getMutationModel(queryNode);
|
|
6047
6051
|
for (const plugin of this.options.plugins) {
|
|
6048
|
-
|
|
6049
|
-
|
|
6052
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6053
|
+
if (onEntityMutation?.beforeEntityMutation) {
|
|
6054
|
+
await onEntityMutation.beforeEntityMutation({
|
|
6050
6055
|
model: mutationModel,
|
|
6051
6056
|
action: mutationInterceptionInfo.action,
|
|
6052
6057
|
queryNode,
|
|
@@ -6062,8 +6067,9 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6062
6067
|
}
|
|
6063
6068
|
const hooks = [];
|
|
6064
6069
|
for (const plugin of this.options.plugins ?? []) {
|
|
6065
|
-
|
|
6066
|
-
|
|
6070
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6071
|
+
if (onEntityMutation?.afterEntityMutation) {
|
|
6072
|
+
hooks.push(onEntityMutation.afterEntityMutation.bind(plugin));
|
|
6067
6073
|
}
|
|
6068
6074
|
}
|
|
6069
6075
|
if (hooks.length === 0) {
|
|
@@ -6073,7 +6079,7 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6073
6079
|
const inTransaction = this.driver.isTransactionConnection(connection);
|
|
6074
6080
|
for (const hook of hooks) {
|
|
6075
6081
|
let afterMutationEntities = void 0;
|
|
6076
|
-
if (mutationInterceptionInfo.
|
|
6082
|
+
if (mutationInterceptionInfo.loadAfterMutationEntities) {
|
|
6077
6083
|
if (InsertQueryNode2.is(queryNode) || UpdateQueryNode2.is(queryNode)) {
|
|
6078
6084
|
afterMutationEntities = queryResult.rows;
|
|
6079
6085
|
}
|
|
@@ -6861,7 +6867,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6861
6867
|
return createZenStackPromise(async (txClient) => {
|
|
6862
6868
|
let proceed = /* @__PURE__ */ __name(async (_args) => {
|
|
6863
6869
|
const _handler = txClient ? handler.withClient(txClient) : handler;
|
|
6864
|
-
const r = await _handler.handle(operation, _args
|
|
6870
|
+
const r = await _handler.handle(operation, _args);
|
|
6865
6871
|
if (!r && throwIfNoResult) {
|
|
6866
6872
|
throw new NotFoundError(model);
|
|
6867
6873
|
}
|
|
@@ -6877,27 +6883,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6877
6883
|
...client.$options.plugins ?? []
|
|
6878
6884
|
];
|
|
6879
6885
|
for (const plugin of plugins) {
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
args,
|
|
6893
|
-
query: _proceed
|
|
6894
|
-
}), "proceed");
|
|
6895
|
-
}
|
|
6896
|
-
}
|
|
6897
|
-
}
|
|
6898
|
-
}
|
|
6899
|
-
}
|
|
6900
|
-
}
|
|
6886
|
+
const onQuery = plugin.onQuery;
|
|
6887
|
+
if (onQuery) {
|
|
6888
|
+
const _proceed = proceed;
|
|
6889
|
+
proceed = /* @__PURE__ */ __name((_args) => onQuery({
|
|
6890
|
+
client,
|
|
6891
|
+
model,
|
|
6892
|
+
operation,
|
|
6893
|
+
// reflect the latest override if provided
|
|
6894
|
+
args: _args,
|
|
6895
|
+
// ensure inner overrides are propagated to the previous proceed
|
|
6896
|
+
proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
|
|
6897
|
+
}), "proceed");
|
|
6901
6898
|
}
|
|
6902
6899
|
}
|
|
6903
6900
|
return proceed(args);
|