@zenstackhq/orm 3.3.3 → 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 CHANGED
@@ -8625,6 +8625,9 @@ var ClientImpl = class _ClientImpl {
8625
8625
  ...functions_exports,
8626
8626
  ...this.$options.functions
8627
8627
  };
8628
+ if (!baseClient) {
8629
+ this.validateComputedFieldsConfig();
8630
+ }
8628
8631
  if (baseClient) {
8629
8632
  this.kyselyProps = {
8630
8633
  ...baseClient.kyselyProps,
@@ -8670,6 +8673,26 @@ var ClientImpl = class _ClientImpl {
8670
8673
  withExecutor(executor) {
8671
8674
  return new _ClientImpl(this.schema, this.$options, this, executor);
8672
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
+ }
8673
8696
  // implementation
8674
8697
  async $transaction(input, options) {
8675
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");