@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.d.cts
CHANGED
|
@@ -1332,7 +1332,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
1332
1332
|
/**
|
|
1333
1333
|
* Builds an expression that checks if an array contains a single value.
|
|
1334
1334
|
*/
|
|
1335
|
-
abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown
|
|
1335
|
+
abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown>, elemType?: string): AliasableExpression<SqlBool>;
|
|
1336
1336
|
/**
|
|
1337
1337
|
* Builds an expression that checks if an array contains all values from another array.
|
|
1338
1338
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1332,7 +1332,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
1332
1332
|
/**
|
|
1333
1333
|
* Builds an expression that checks if an array contains a single value.
|
|
1334
1334
|
*/
|
|
1335
|
-
abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown
|
|
1335
|
+
abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown>, elemType?: string): AliasableExpression<SqlBool>;
|
|
1336
1336
|
/**
|
|
1337
1337
|
* Builds an expression that checks if an array contains all values from another array.
|
|
1338
1338
|
*/
|
package/dist/index.js
CHANGED
|
@@ -927,7 +927,7 @@ var BaseCrudDialect = class {
|
|
|
927
927
|
break;
|
|
928
928
|
}
|
|
929
929
|
case "has": {
|
|
930
|
-
clauses.push(this.buildArrayContains(receiver, this.eb.val(value)));
|
|
930
|
+
clauses.push(this.buildArrayContains(receiver, this.eb.val(value), fieldType));
|
|
931
931
|
break;
|
|
932
932
|
}
|
|
933
933
|
case "hasEvery": {
|
|
@@ -1774,7 +1774,7 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1774
1774
|
buildArrayValue(values, _elemType) {
|
|
1775
1775
|
return new ExpressionWrapper(ValueListNode.create(values.map((v) => v.toOperationNode())));
|
|
1776
1776
|
}
|
|
1777
|
-
buildArrayContains(_field, _value) {
|
|
1777
|
+
buildArrayContains(_field, _value, _elemType) {
|
|
1778
1778
|
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1779
1779
|
}
|
|
1780
1780
|
buildArrayHasEvery(_field, _values) {
|
|
@@ -2031,8 +2031,15 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2031
2031
|
const mappedType = this.getSqlType(elemType);
|
|
2032
2032
|
return this.eb.cast(arr, sql3`${sql3.raw(mappedType)}[]`);
|
|
2033
2033
|
}
|
|
2034
|
-
buildArrayContains(field, value) {
|
|
2035
|
-
|
|
2034
|
+
buildArrayContains(field, value, elemType) {
|
|
2035
|
+
const arrayExpr = sql3`ARRAY[${value}]`;
|
|
2036
|
+
if (elemType) {
|
|
2037
|
+
const mappedType = this.getSqlType(elemType);
|
|
2038
|
+
const typedArray = this.eb.cast(arrayExpr, sql3`${sql3.raw(mappedType)}[]`);
|
|
2039
|
+
return this.eb(field, "@>", typedArray);
|
|
2040
|
+
} else {
|
|
2041
|
+
return this.eb(field, "@>", arrayExpr);
|
|
2042
|
+
}
|
|
2036
2043
|
}
|
|
2037
2044
|
buildArrayHasEvery(field, values) {
|
|
2038
2045
|
return this.eb(field, "@>", values);
|
|
@@ -2368,7 +2375,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2368
2375
|
buildArrayValue(values, _elemType) {
|
|
2369
2376
|
return new ExpressionWrapper2(ValueListNode2.create(values.map((v) => v.toOperationNode())));
|
|
2370
2377
|
}
|
|
2371
|
-
buildArrayContains(_field, _value) {
|
|
2378
|
+
buildArrayContains(_field, _value, _elemType) {
|
|
2372
2379
|
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2373
2380
|
}
|
|
2374
2381
|
buildArrayHasEvery(_field, _values) {
|
|
@@ -8379,7 +8386,7 @@ var SchemaDbPusher = class {
|
|
|
8379
8386
|
return "integer";
|
|
8380
8387
|
}
|
|
8381
8388
|
get floatType() {
|
|
8382
|
-
return match17(this.schema.provider.type).with("mysql", () => sql7.raw("double")).otherwise(() => "real");
|
|
8389
|
+
return match17(this.schema.provider.type).with("postgresql", () => "double precision").with("mysql", () => sql7.raw("double")).otherwise(() => "real");
|
|
8383
8390
|
}
|
|
8384
8391
|
get bigIntType() {
|
|
8385
8392
|
return "bigint";
|
|
@@ -8573,6 +8580,9 @@ var ClientImpl = class _ClientImpl {
|
|
|
8573
8580
|
...functions_exports,
|
|
8574
8581
|
...this.$options.functions
|
|
8575
8582
|
};
|
|
8583
|
+
if (!baseClient) {
|
|
8584
|
+
this.validateComputedFieldsConfig();
|
|
8585
|
+
}
|
|
8576
8586
|
if (baseClient) {
|
|
8577
8587
|
this.kyselyProps = {
|
|
8578
8588
|
...baseClient.kyselyProps,
|
|
@@ -8618,6 +8628,26 @@ var ClientImpl = class _ClientImpl {
|
|
|
8618
8628
|
withExecutor(executor) {
|
|
8619
8629
|
return new _ClientImpl(this.schema, this.$options, this, executor);
|
|
8620
8630
|
}
|
|
8631
|
+
/**
|
|
8632
|
+
* Validates that all computed fields in the schema have corresponding configurations.
|
|
8633
|
+
*/
|
|
8634
|
+
validateComputedFieldsConfig() {
|
|
8635
|
+
const computedFieldsConfig = "computedFields" in this.$options ? this.$options.computedFields : void 0;
|
|
8636
|
+
for (const [modelName, modelDef] of Object.entries(this.$schema.models)) {
|
|
8637
|
+
if (modelDef.computedFields) {
|
|
8638
|
+
for (const fieldName of Object.keys(modelDef.computedFields)) {
|
|
8639
|
+
const modelConfig = computedFieldsConfig?.[modelName];
|
|
8640
|
+
const fieldConfig = modelConfig?.[fieldName];
|
|
8641
|
+
if (fieldConfig === null || fieldConfig === void 0) {
|
|
8642
|
+
throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" does not have a configuration. Please provide an implementation in the computedFields option.`);
|
|
8643
|
+
}
|
|
8644
|
+
if (typeof fieldConfig !== "function") {
|
|
8645
|
+
throw createConfigError(`Computed field "${fieldName}" in model "${modelName}" has an invalid configuration: expected a function but received ${typeof fieldConfig}.`);
|
|
8646
|
+
}
|
|
8647
|
+
}
|
|
8648
|
+
}
|
|
8649
|
+
}
|
|
8650
|
+
}
|
|
8621
8651
|
// implementation
|
|
8622
8652
|
async $transaction(input, options) {
|
|
8623
8653
|
invariant14(typeof input === "function" || Array.isArray(input) && input.every((p) => p.then && p.cb), "Invalid transaction input, expected a function or an array of ZenStackPromise");
|