@zenstackhq/orm 3.3.0-beta.1 → 3.3.0-beta.2
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/index.cjs +78 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -21
- package/dist/index.d.ts +58 -21
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -39,8 +39,11 @@ __export(src_exports, {
|
|
|
39
39
|
BaseCrudDialect: () => BaseCrudDialect,
|
|
40
40
|
CRUD: () => CRUD,
|
|
41
41
|
CRUD_EXT: () => CRUD_EXT,
|
|
42
|
+
CoreCreateOperations: () => CoreCreateOperations,
|
|
42
43
|
CoreCrudOperations: () => CoreCrudOperations,
|
|
44
|
+
CoreDeleteOperations: () => CoreDeleteOperations,
|
|
43
45
|
CoreReadOperations: () => CoreReadOperations,
|
|
46
|
+
CoreUpdateOperations: () => CoreUpdateOperations,
|
|
44
47
|
CoreWriteOperations: () => CoreWriteOperations,
|
|
45
48
|
DbNull: () => DbNull,
|
|
46
49
|
DbNullClass: () => DbNullClass,
|
|
@@ -1164,7 +1167,15 @@ var BaseCrudDialect = class {
|
|
|
1164
1167
|
} else {
|
|
1165
1168
|
return this.eb.not(this.eb(lhs, "in", rhs));
|
|
1166
1169
|
}
|
|
1167
|
-
}).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("
|
|
1170
|
+
}).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("between", () => {
|
|
1171
|
+
(0, import_common_helpers2.invariant)(Array.isArray(rhs), "right hand side must be an array");
|
|
1172
|
+
(0, import_common_helpers2.invariant)(rhs.length === 2, "right hand side must have a length of 2");
|
|
1173
|
+
const [start, end] = rhs;
|
|
1174
|
+
return this.eb.and([
|
|
1175
|
+
this.eb(lhs, ">=", start),
|
|
1176
|
+
this.eb(lhs, "<=", end)
|
|
1177
|
+
]);
|
|
1178
|
+
}).with("not", () => this.eb.not(recurse(value))).with(import_ts_pattern2.P.union(...AGGREGATE_OPERATORS), (op2) => {
|
|
1168
1179
|
const innerResult = this.buildStandardFilter(type, value, aggregate(this.eb, lhs, op2), getRhs, recurse, throwIfInvalid);
|
|
1169
1180
|
consumedKeys.push(...innerResult.consumedKeys);
|
|
1170
1181
|
return this.and(...innerResult.conditions);
|
|
@@ -2150,6 +2161,22 @@ var CoreWriteOperations = [
|
|
|
2150
2161
|
"delete",
|
|
2151
2162
|
"deleteMany"
|
|
2152
2163
|
];
|
|
2164
|
+
var CoreCreateOperations = [
|
|
2165
|
+
"create",
|
|
2166
|
+
"createMany",
|
|
2167
|
+
"createManyAndReturn",
|
|
2168
|
+
"upsert"
|
|
2169
|
+
];
|
|
2170
|
+
var CoreUpdateOperations = [
|
|
2171
|
+
"update",
|
|
2172
|
+
"updateMany",
|
|
2173
|
+
"updateManyAndReturn",
|
|
2174
|
+
"upsert"
|
|
2175
|
+
];
|
|
2176
|
+
var CoreDeleteOperations = [
|
|
2177
|
+
"delete",
|
|
2178
|
+
"deleteMany"
|
|
2179
|
+
];
|
|
2153
2180
|
var AllCrudOperations = [
|
|
2154
2181
|
...CoreCrudOperations,
|
|
2155
2182
|
"findUniqueOrThrow",
|
|
@@ -4614,8 +4641,8 @@ var InputValidator = class {
|
|
|
4614
4641
|
mergePluginArgsSchema(schema, operation) {
|
|
4615
4642
|
let result = schema;
|
|
4616
4643
|
for (const plugin of this.options.plugins ?? []) {
|
|
4617
|
-
if (plugin.
|
|
4618
|
-
const pluginSchema =
|
|
4644
|
+
if (plugin.queryArgs) {
|
|
4645
|
+
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
4619
4646
|
if (pluginSchema) {
|
|
4620
4647
|
result = result.extend(pluginSchema.shape);
|
|
4621
4648
|
}
|
|
@@ -4623,6 +4650,42 @@ var InputValidator = class {
|
|
|
4623
4650
|
}
|
|
4624
4651
|
return result.strict();
|
|
4625
4652
|
}
|
|
4653
|
+
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
4654
|
+
if (!plugin.queryArgs) {
|
|
4655
|
+
return void 0;
|
|
4656
|
+
}
|
|
4657
|
+
let result;
|
|
4658
|
+
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
4659
|
+
result = plugin.queryArgs[operation];
|
|
4660
|
+
} else if (operation === "upsert") {
|
|
4661
|
+
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
4662
|
+
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
4663
|
+
if (createSchema && updateSchema) {
|
|
4664
|
+
(0, import_common_helpers7.invariant)(createSchema instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4665
|
+
(0, import_common_helpers7.invariant)(updateSchema instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4666
|
+
result = createSchema.extend(updateSchema.shape);
|
|
4667
|
+
} else if (createSchema) {
|
|
4668
|
+
result = createSchema;
|
|
4669
|
+
} else if (updateSchema) {
|
|
4670
|
+
result = updateSchema;
|
|
4671
|
+
}
|
|
4672
|
+
} else if (
|
|
4673
|
+
// then comes grouped operations: $create, $read, $update, $delete
|
|
4674
|
+
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
4675
|
+
) {
|
|
4676
|
+
result = plugin.queryArgs["$create"];
|
|
4677
|
+
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
4678
|
+
result = plugin.queryArgs["$read"];
|
|
4679
|
+
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
4680
|
+
result = plugin.queryArgs["$update"];
|
|
4681
|
+
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
4682
|
+
result = plugin.queryArgs["$delete"];
|
|
4683
|
+
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
4684
|
+
result = plugin.queryArgs["$all"];
|
|
4685
|
+
}
|
|
4686
|
+
(0, import_common_helpers7.invariant)(result === void 0 || result instanceof import_zod3.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4687
|
+
return result;
|
|
4688
|
+
}
|
|
4626
4689
|
// #region Find
|
|
4627
4690
|
makeFindSchema(model, operation) {
|
|
4628
4691
|
const fields = {};
|
|
@@ -5007,6 +5070,7 @@ var InputValidator = class {
|
|
|
5007
5070
|
lte: baseSchema.optional(),
|
|
5008
5071
|
gt: baseSchema.optional(),
|
|
5009
5072
|
gte: baseSchema.optional(),
|
|
5073
|
+
between: baseSchema.array().length(2).optional(),
|
|
5010
5074
|
not: makeThis().optional(),
|
|
5011
5075
|
...withAggregations?.includes("_count") ? {
|
|
5012
5076
|
_count: this.makeNumberFilterSchema(import_zod3.z.number().int(), false, false).optional()
|
|
@@ -7619,6 +7683,14 @@ function createClientProxy(client) {
|
|
|
7619
7683
|
return new Proxy(client, {
|
|
7620
7684
|
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
7621
7685
|
if (typeof prop === "string" && prop.startsWith("$")) {
|
|
7686
|
+
const plugins = target.$options.plugins ?? [];
|
|
7687
|
+
for (let i = plugins.length - 1; i >= 0; i--) {
|
|
7688
|
+
const plugin = plugins[i];
|
|
7689
|
+
const clientMembers = plugin?.client;
|
|
7690
|
+
if (clientMembers && prop in clientMembers) {
|
|
7691
|
+
return clientMembers[prop];
|
|
7692
|
+
}
|
|
7693
|
+
}
|
|
7622
7694
|
return Reflect.get(target, prop, receiver);
|
|
7623
7695
|
}
|
|
7624
7696
|
if (typeof prop === "string") {
|
|
@@ -8159,8 +8231,11 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
8159
8231
|
BaseCrudDialect,
|
|
8160
8232
|
CRUD,
|
|
8161
8233
|
CRUD_EXT,
|
|
8234
|
+
CoreCreateOperations,
|
|
8162
8235
|
CoreCrudOperations,
|
|
8236
|
+
CoreDeleteOperations,
|
|
8163
8237
|
CoreReadOperations,
|
|
8238
|
+
CoreUpdateOperations,
|
|
8164
8239
|
CoreWriteOperations,
|
|
8165
8240
|
DbNull,
|
|
8166
8241
|
DbNullClass,
|