@zenstackhq/runtime 3.0.0-alpha.23 → 3.0.0-alpha.25
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-Y3qWOegb.d.cts → contract-BOWN0dwS.d.cts} +90 -85
- package/dist/{contract-Y3qWOegb.d.ts → contract-BOWN0dwS.d.ts} +90 -85
- package/dist/index.cjs +38 -39
- 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 +39 -40
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +10 -7
- 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 +10 -7
- package/dist/plugins/policy/index.js.map +1 -1
- package/package.json +9 -9
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-BOWN0dwS.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-BOWN0dwS.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-BOWN0dwS.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-BOWN0dwS.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
|
|
@@ -270,11 +270,14 @@ function getIdValues(schema, model, data) {
|
|
|
270
270
|
}), {});
|
|
271
271
|
}
|
|
272
272
|
__name(getIdValues, "getIdValues");
|
|
273
|
-
function buildFieldRef(schema, model, field, options, eb, modelAlias) {
|
|
273
|
+
function buildFieldRef(schema, model, field, options, eb, modelAlias, inlineComputedField = true) {
|
|
274
274
|
const fieldDef = requireField(schema, model, field);
|
|
275
275
|
if (!fieldDef.computed) {
|
|
276
276
|
return eb.ref(modelAlias ? `${modelAlias}.${field}` : field);
|
|
277
277
|
} else {
|
|
278
|
+
if (!inlineComputedField) {
|
|
279
|
+
return eb.ref(modelAlias ? `${modelAlias}.${field}` : field);
|
|
280
|
+
}
|
|
278
281
|
let computer;
|
|
279
282
|
if ("computedFields" in options) {
|
|
280
283
|
const computedFields = options.computedFields;
|
|
@@ -458,7 +461,6 @@ import { sql as sql2 } from "kysely";
|
|
|
458
461
|
import { match as match3 } from "ts-pattern";
|
|
459
462
|
|
|
460
463
|
// src/client/constants.ts
|
|
461
|
-
var CONTEXT_COMMENT_PREFIX = "-- $$context:";
|
|
462
464
|
var NUMERIC_FIELD_TYPES = [
|
|
463
465
|
"Int",
|
|
464
466
|
"Float",
|
|
@@ -1045,8 +1047,8 @@ var BaseCrudDialect = class {
|
|
|
1045
1047
|
not(eb, ...args) {
|
|
1046
1048
|
return eb.not(this.and(eb, ...args));
|
|
1047
1049
|
}
|
|
1048
|
-
fieldRef(model, field, eb, modelAlias) {
|
|
1049
|
-
return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias);
|
|
1050
|
+
fieldRef(model, field, eb, modelAlias, inlineComputedField = true) {
|
|
1051
|
+
return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias, inlineComputedField);
|
|
1050
1052
|
}
|
|
1051
1053
|
};
|
|
1052
1054
|
|
|
@@ -1141,7 +1143,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1141
1143
|
if (payload === true || !payload.select) {
|
|
1142
1144
|
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !(typeof payload === "object" && payload.omit?.[name] === true)).map(([field]) => [
|
|
1143
1145
|
sql2.lit(field),
|
|
1144
|
-
this.fieldRef(relationModel, field, eb)
|
|
1146
|
+
this.fieldRef(relationModel, field, eb, void 0, false)
|
|
1145
1147
|
]).flatMap((v) => v));
|
|
1146
1148
|
} else if (payload.select) {
|
|
1147
1149
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
@@ -1153,7 +1155,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1153
1155
|
];
|
|
1154
1156
|
} else {
|
|
1155
1157
|
const fieldDef = requireField(this.schema, relationModel, field);
|
|
1156
|
-
const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : this.fieldRef(relationModel, field, eb);
|
|
1158
|
+
const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : this.fieldRef(relationModel, field, eb, void 0, false);
|
|
1157
1159
|
return [
|
|
1158
1160
|
sql2.lit(field),
|
|
1159
1161
|
fieldValue
|
|
@@ -1304,7 +1306,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1304
1306
|
if (payload === true || !payload.select) {
|
|
1305
1307
|
objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !(typeof payload === "object" && payload.omit?.[name] === true)).map(([field]) => [
|
|
1306
1308
|
sql3.lit(field),
|
|
1307
|
-
this.fieldRef(relationModel, field, eb)
|
|
1309
|
+
this.fieldRef(relationModel, field, eb, void 0, false)
|
|
1308
1310
|
]).flatMap((v) => v));
|
|
1309
1311
|
} else if (payload.select) {
|
|
1310
1312
|
objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
|
|
@@ -1325,7 +1327,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1325
1327
|
} else {
|
|
1326
1328
|
return [
|
|
1327
1329
|
sql3.lit(field),
|
|
1328
|
-
this.fieldRef(relationModel, field, eb)
|
|
1330
|
+
this.fieldRef(relationModel, field, eb, void 0, false)
|
|
1329
1331
|
];
|
|
1330
1332
|
}
|
|
1331
1333
|
}
|
|
@@ -3425,8 +3427,8 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
|
|
|
3425
3427
|
isNumericField(fieldDef) {
|
|
3426
3428
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
3427
3429
|
}
|
|
3428
|
-
makeContextComment(
|
|
3429
|
-
return sql4
|
|
3430
|
+
makeContextComment(_context) {
|
|
3431
|
+
return sql4``;
|
|
3430
3432
|
}
|
|
3431
3433
|
async updateMany(kysely, model, where, data, limit, returnData, filterModel) {
|
|
3432
3434
|
if (typeof data !== "object") {
|
|
@@ -5980,7 +5982,7 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
5980
5982
|
return newExecutor;
|
|
5981
5983
|
}
|
|
5982
5984
|
get hasMutationHooks() {
|
|
5983
|
-
return this.client.$options.plugins?.some((plugin) => plugin.
|
|
5985
|
+
return this.client.$options.plugins?.some((plugin) => !!plugin.onEntityMutation);
|
|
5984
5986
|
}
|
|
5985
5987
|
getMutationModel(queryNode) {
|
|
5986
5988
|
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,10 +6012,14 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6010
6012
|
where: node.where
|
|
6011
6013
|
})).exhaustive();
|
|
6012
6014
|
for (const plugin of plugins) {
|
|
6013
|
-
|
|
6015
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6016
|
+
if (!onEntityMutation) {
|
|
6017
|
+
continue;
|
|
6018
|
+
}
|
|
6019
|
+
if (!onEntityMutation.mutationInterceptionFilter) {
|
|
6014
6020
|
result.intercept = true;
|
|
6015
6021
|
} else {
|
|
6016
|
-
const filterResult = await
|
|
6022
|
+
const filterResult = await onEntityMutation.mutationInterceptionFilter({
|
|
6017
6023
|
model: mutationModel,
|
|
6018
6024
|
action,
|
|
6019
6025
|
queryNode
|
|
@@ -6045,8 +6051,9 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6045
6051
|
if (this.options.plugins) {
|
|
6046
6052
|
const mutationModel = this.getMutationModel(queryNode);
|
|
6047
6053
|
for (const plugin of this.options.plugins) {
|
|
6048
|
-
|
|
6049
|
-
|
|
6054
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6055
|
+
if (onEntityMutation?.beforeEntityMutation) {
|
|
6056
|
+
await onEntityMutation.beforeEntityMutation({
|
|
6050
6057
|
model: mutationModel,
|
|
6051
6058
|
action: mutationInterceptionInfo.action,
|
|
6052
6059
|
queryNode,
|
|
@@ -6062,8 +6069,9 @@ ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
|
|
|
6062
6069
|
}
|
|
6063
6070
|
const hooks = [];
|
|
6064
6071
|
for (const plugin of this.options.plugins ?? []) {
|
|
6065
|
-
|
|
6066
|
-
|
|
6072
|
+
const onEntityMutation = plugin.onEntityMutation;
|
|
6073
|
+
if (onEntityMutation?.afterEntityMutation) {
|
|
6074
|
+
hooks.push(onEntityMutation.afterEntityMutation.bind(plugin));
|
|
6067
6075
|
}
|
|
6068
6076
|
}
|
|
6069
6077
|
if (hooks.length === 0) {
|
|
@@ -6861,7 +6869,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6861
6869
|
return createZenStackPromise(async (txClient) => {
|
|
6862
6870
|
let proceed = /* @__PURE__ */ __name(async (_args) => {
|
|
6863
6871
|
const _handler = txClient ? handler.withClient(txClient) : handler;
|
|
6864
|
-
const r = await _handler.handle(operation, _args
|
|
6872
|
+
const r = await _handler.handle(operation, _args);
|
|
6865
6873
|
if (!r && throwIfNoResult) {
|
|
6866
6874
|
throw new NotFoundError(model);
|
|
6867
6875
|
}
|
|
@@ -6877,27 +6885,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6877
6885
|
...client.$options.plugins ?? []
|
|
6878
6886
|
];
|
|
6879
6887
|
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
|
-
}
|
|
6888
|
+
const onQuery = plugin.onQuery;
|
|
6889
|
+
if (onQuery) {
|
|
6890
|
+
const _proceed = proceed;
|
|
6891
|
+
proceed = /* @__PURE__ */ __name((_args) => onQuery({
|
|
6892
|
+
client,
|
|
6893
|
+
model,
|
|
6894
|
+
operation,
|
|
6895
|
+
// reflect the latest override if provided
|
|
6896
|
+
args: _args,
|
|
6897
|
+
// ensure inner overrides are propagated to the previous proceed
|
|
6898
|
+
proceed: /* @__PURE__ */ __name((nextArgs) => _proceed(nextArgs), "proceed")
|
|
6899
|
+
}), "proceed");
|
|
6901
6900
|
}
|
|
6902
6901
|
}
|
|
6903
6902
|
return proceed(args);
|