@zenstackhq/orm 3.3.2 → 3.4.0-beta.1
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 +36 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -972,7 +972,7 @@ var BaseCrudDialect = class {
|
|
|
972
972
|
break;
|
|
973
973
|
}
|
|
974
974
|
case "has": {
|
|
975
|
-
clauses.push(this.buildArrayContains(receiver, this.eb.val(value)));
|
|
975
|
+
clauses.push(this.buildArrayContains(receiver, this.eb.val(value), fieldType));
|
|
976
976
|
break;
|
|
977
977
|
}
|
|
978
978
|
case "hasEvery": {
|
|
@@ -1819,7 +1819,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1819
1819
|
buildArrayValue(values, _elemType) {
|
|
1820
1820
|
return new import_kysely3.ExpressionWrapper(import_kysely3.ValueListNode.create(values.map((v) => v.toOperationNode())));
|
|
1821
1821
|
}
|
|
1822
|
-
buildArrayContains(_field, _value) {
|
|
1822
|
+
buildArrayContains(_field, _value, _elemType) {
|
|
1823
1823
|
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1824
1824
|
}
|
|
1825
1825
|
buildArrayHasEvery(_field, _values) {
|
|
@@ -2076,8 +2076,15 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2076
2076
|
const mappedType = this.getSqlType(elemType);
|
|
2077
2077
|
return this.eb.cast(arr, import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]`);
|
|
2078
2078
|
}
|
|
2079
|
-
buildArrayContains(field, value) {
|
|
2080
|
-
|
|
2079
|
+
buildArrayContains(field, value, elemType) {
|
|
2080
|
+
const arrayExpr = import_kysely4.sql`ARRAY[${value}]`;
|
|
2081
|
+
if (elemType) {
|
|
2082
|
+
const mappedType = this.getSqlType(elemType);
|
|
2083
|
+
const typedArray = this.eb.cast(arrayExpr, import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]`);
|
|
2084
|
+
return this.eb(field, "@>", typedArray);
|
|
2085
|
+
} else {
|
|
2086
|
+
return this.eb(field, "@>", arrayExpr);
|
|
2087
|
+
}
|
|
2081
2088
|
}
|
|
2082
2089
|
buildArrayHasEvery(field, values) {
|
|
2083
2090
|
return this.eb(field, "@>", values);
|
|
@@ -2413,7 +2420,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2413
2420
|
buildArrayValue(values, _elemType) {
|
|
2414
2421
|
return new import_kysely5.ExpressionWrapper(import_kysely5.ValueListNode.create(values.map((v) => v.toOperationNode())));
|
|
2415
2422
|
}
|
|
2416
|
-
buildArrayContains(_field, _value) {
|
|
2423
|
+
buildArrayContains(_field, _value, _elemType) {
|
|
2417
2424
|
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2418
2425
|
}
|
|
2419
2426
|
buildArrayHasEvery(_field, _values) {
|
|
@@ -8424,7 +8431,7 @@ var SchemaDbPusher = class {
|
|
|
8424
8431
|
return "integer";
|
|
8425
8432
|
}
|
|
8426
8433
|
get floatType() {
|
|
8427
|
-
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("mysql", () => import_kysely10.sql.raw("double")).otherwise(() => "real");
|
|
8434
|
+
return (0, import_ts_pattern17.match)(this.schema.provider.type).with("postgresql", () => "double precision").with("mysql", () => import_kysely10.sql.raw("double")).otherwise(() => "real");
|
|
8428
8435
|
}
|
|
8429
8436
|
get bigIntType() {
|
|
8430
8437
|
return "bigint";
|
|
@@ -8618,6 +8625,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
8618
8625
|
...functions_exports,
|
|
8619
8626
|
...this.$options.functions
|
|
8620
8627
|
};
|
|
8628
|
+
if (!baseClient) {
|
|
8629
|
+
this.validateComputedFieldsConfig();
|
|
8630
|
+
}
|
|
8621
8631
|
if (baseClient) {
|
|
8622
8632
|
this.kyselyProps = {
|
|
8623
8633
|
...baseClient.kyselyProps,
|
|
@@ -8663,6 +8673,26 @@ var ClientImpl = class _ClientImpl {
|
|
|
8663
8673
|
withExecutor(executor) {
|
|
8664
8674
|
return new _ClientImpl(this.schema, this.$options, this, executor);
|
|
8665
8675
|
}
|
|
8676
|
+
/**
|
|
8677
|
+
* Validates that all computed fields in the schema have corresponding configurations.
|
|
8678
|
+
*/
|
|
8679
|
+
validateComputedFieldsConfig() {
|
|
8680
|
+
const computedFieldsConfig = "computedFields" in this.$options ? this.$options.computedFields : void 0;
|
|
8681
|
+
for (const [modelName, modelDef] of Object.entries(this.$schema.models)) {
|
|
8682
|
+
if (modelDef.computedFields) {
|
|
8683
|
+
for (const fieldName of Object.keys(modelDef.computedFields)) {
|
|
8684
|
+
const modelConfig = computedFieldsConfig?.[modelName];
|
|
8685
|
+
const fieldConfig = modelConfig?.[fieldName];
|
|
8686
|
+
if (fieldConfig === null || fieldConfig === void 0) {
|
|
8687
|
+
throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" does not have a configuration. Please provide an implementation in the computedFields option.`);
|
|
8688
|
+
}
|
|
8689
|
+
if (typeof fieldConfig !== "function") {
|
|
8690
|
+
throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" has an invalid configuration: expected a function but received ${typeof fieldConfig}.`);
|
|
8691
|
+
}
|
|
8692
|
+
}
|
|
8693
|
+
}
|
|
8694
|
+
}
|
|
8695
|
+
}
|
|
8666
8696
|
// implementation
|
|
8667
8697
|
async $transaction(input, options) {
|
|
8668
8698
|
(0, import_common_helpers14.invariant)(typeof input === "function" || Array.isArray(input) && input.every((p) => p.then && p.cb), "Invalid transaction input, expected a function or an array of ZenStackPromise");
|