// src/secret-backed-value.ts
import { Effect, Schema } from "effect";
var SecretBackedValue = Schema.Union([
  Schema.String,
  Schema.Struct({
    secretId: Schema.String,
    prefix: Schema.optional(Schema.String)
  })
]);
var SecretBackedMap = Schema.Record(Schema.String, SecretBackedValue);
var isSecretBackedRef = (value) => typeof value !== "string";
var resolveSecretBackedMap = ({
  values,
  getSecret,
  onMissing,
  onError,
  missing = "fail"
}) => {
  const entries = Object.entries(values ?? {});
  if (entries.length === 0) return Effect.succeed(void 0);
  return Effect.gen(function* () {
    const resolved = {};
    for (const [name, value] of entries) {
      if (typeof value === "string") {
        resolved[name] = value;
        continue;
      }
      const secret = yield* getSecret(value.secretId).pipe(
        Effect.mapError((error) => onError?.(error, name, value) ?? error)
      );
      if (secret === null) {
        if (missing === "drop") continue;
        return yield* Effect.fail(onMissing(name, value));
      }
      resolved[name] = value.prefix ? `${value.prefix}${secret}` : secret;
    }
    return Object.keys(resolved).length > 0 ? resolved : void 0;
  });
};

export {
  SecretBackedValue,
  SecretBackedMap,
  isSecretBackedRef,
  resolveSecretBackedMap
};
//# sourceMappingURL=chunk-MLNVNVRI.js.map