@zenstackhq/orm 3.8.0-beta.2 → 3.8.0
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 +20 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.mjs +206 -189
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1474,7 +1474,10 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1474
1474
|
return { [field]: fieldValue };
|
|
1475
1475
|
}
|
|
1476
1476
|
}));
|
|
1477
|
-
if (typeof payload === "object" && payload.include && typeof payload.include === "object") Object.assign(objArgs, ...Object.entries(payload.include).filter(([, value]) => value).map(([field]) =>
|
|
1477
|
+
if (typeof payload === "object" && payload.include && typeof payload.include === "object") Object.assign(objArgs, ...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
1478
|
+
if (field === "_count") return { [field]: this.buildCountJson(relationModel, eb, relationModelAlias, value) };
|
|
1479
|
+
return { [field]: eb.ref(`${parentResultName}$${field}.$data`) };
|
|
1480
|
+
}));
|
|
1478
1481
|
return objArgs;
|
|
1479
1482
|
}
|
|
1480
1483
|
buildRelationJoins(query, relationModel, relationModelAlias, payload, parentResultName) {
|
|
@@ -1869,7 +1872,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1869
1872
|
return this.eb.fn("trim", [expression, kysely.sql.lit("\"")]);
|
|
1870
1873
|
}
|
|
1871
1874
|
buildArrayLength(array) {
|
|
1872
|
-
return this.eb.fn("array_length", [array]);
|
|
1875
|
+
return this.eb.fn("array_length", [array, kysely.sql.lit(1)]);
|
|
1873
1876
|
}
|
|
1874
1877
|
buildArrayValue(values, elemType) {
|
|
1875
1878
|
const arr = kysely.sql`ARRAY[${kysely.sql.join(values, kysely.sql.raw(","))}]`;
|
|
@@ -2149,6 +2152,10 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2149
2152
|
} else return [kysely.sql.lit(field), this.fieldRef(relationModel, field, subQueryName, false)];
|
|
2150
2153
|
}).flatMap((v) => v));
|
|
2151
2154
|
if (typeof payload === "object" && payload.include && typeof payload.include === "object") objArgs.push(...Object.entries(payload.include).filter(([, value]) => value).map(([field, value]) => {
|
|
2155
|
+
if (field === "_count") {
|
|
2156
|
+
const subJson = this.buildCountJson(relationModel, eb, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2157
|
+
return [kysely.sql.lit(field), subJson];
|
|
2158
|
+
}
|
|
2152
2159
|
const subJson = this.buildRelationJSON(relationModel, eb, field, tmpAlias(`${parentAlias}$${relationField}`), value);
|
|
2153
2160
|
return [kysely.sql.lit(field), subJson];
|
|
2154
2161
|
}).flatMap((v) => v));
|
|
@@ -2874,7 +2881,8 @@ var ZodSchemaFactory = class {
|
|
|
2874
2881
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
2875
2882
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2876
2883
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2877
|
-
} else fields[field] = zod.z.
|
|
2884
|
+
} else if (this.options.allowQueryTimeOmitOverride === false && this.isFieldOmittedByConfig(model, field)) fields[field] = zod.z.literal(false).optional();
|
|
2885
|
+
else fields[field] = zod.z.boolean().optional();
|
|
2878
2886
|
if (this.shouldIncludeRelations(options)) {
|
|
2879
2887
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2880
2888
|
if (!(_countSchema instanceof zod.z.ZodNever)) fields["_count"] = _countSchema;
|
|
@@ -2920,6 +2928,15 @@ var ZodSchemaFactory = class {
|
|
|
2920
2928
|
this.registerSchema(`${model}${(0, _zenstackhq_common_helpers.upperCaseFirst)(field)}RelationInput`, result);
|
|
2921
2929
|
return result;
|
|
2922
2930
|
}
|
|
2931
|
+
/**
|
|
2932
|
+
* Determines whether a field is configured to be omitted at the schema or client-options level
|
|
2933
|
+
* (query-level omit is excluded as it's mutually exclusive with `select`).
|
|
2934
|
+
*/
|
|
2935
|
+
isFieldOmittedByConfig(model, field) {
|
|
2936
|
+
const omitConfig = this.options.omit?.[(0, _zenstackhq_common_helpers.lowerCaseFirst)(model)] ?? this.options.omit?.[model];
|
|
2937
|
+
if (omitConfig && typeof omitConfig[field] === "boolean") return omitConfig[field];
|
|
2938
|
+
return !!requireField(this.schema, model, field).omit;
|
|
2939
|
+
}
|
|
2923
2940
|
makeOmitSchema(model) {
|
|
2924
2941
|
const fields = {};
|
|
2925
2942
|
for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = zod.z.boolean().optional();
|