// src/store-contract.ts
function isRecord(value) {
  return typeof value === "object" && value !== null && !Array.isArray(value);
}
function assertString(value, field) {
  if (typeof value !== "string" || value.trim().length === 0) {
    throw new Error(`${field} must be a non-empty string`);
  }
  return value.trim();
}
function optionalString(value) {
  if (typeof value !== "string" || value.trim().length === 0) return void 0;
  return value.trim();
}
function assertSafePathSegment(value, field) {
  if (value === "." || value === ".." || value.includes("/") || value.includes("\\")) {
    throw new Error(`${field} must be a safe path segment`);
  }
  return value;
}
function assertIsoRecordedAt(value, field = "recordedAt") {
  if (!/^\d{4}-\d{2}-\d{2}T/.test(value)) {
    throw new Error(`${field} must be an ISO timestamp`);
  }
  return value;
}
function recordStoreDay(recordedAt) {
  const day = recordedAt.slice(0, 10);
  if (!/^\d{4}-\d{2}-\d{2}$/.test(day)) {
    throw new Error("recordedAt must start with a valid YYYY-MM-DD date");
  }
  return day;
}
function optionalStringArray(value, field) {
  if (value === void 0) return void 0;
  if (!Array.isArray(value)) throw new Error(`${field} must be an array of strings`);
  const items = value.map((item, index) => assertString(item, `${field}[${index}]`));
  return items.length > 0 ? items : void 0;
}
function validateStringRecord(raw, field = "metadata") {
  if (raw === void 0) return void 0;
  if (!isRecord(raw)) throw new Error(`${field} must be an object of strings`);
  const out = {};
  for (const [key, value] of Object.entries(raw)) {
    if (typeof value !== "string") throw new Error(`${field} must be an object of strings`);
    out[key] = value;
  }
  return Object.keys(out).length > 0 ? out : void 0;
}

export {
  isRecord,
  assertString,
  optionalString,
  assertSafePathSegment,
  assertIsoRecordedAt,
  recordStoreDay,
  optionalStringArray,
  validateStringRecord
};
//# sourceMappingURL=chunk-DGXUHMOV.js.map