import { assert } from "../../../shared/src/asserts.js";
function getShardID({
  app,
  shard
}) {
  return {
    appID: app.id,
    shardNum: shard.num
  };
}
function getShardConfig({
  app,
  shard
}) {
  return {
    appID: app.id,
    shardNum: shard.num,
    publications: app.publications
  };
}
const ALLOWED_APP_ID_CHARACTERS = /^[a-z0-9_]+$/;
const INVALID_APP_ID_MESSAGE = "The App ID may only consist of lower-case letters, numbers, and the underscore character";
function check(shard) {
  const { appID, shardNum } = shard;
  if (!ALLOWED_APP_ID_CHARACTERS.test(appID)) {
    throw new Error(INVALID_APP_ID_MESSAGE);
  }
  assert(typeof shardNum === "number", "shardNum must be a number");
  return { appID, shardNum };
}
function appSchema({ appID }) {
  check({ appID, shardNum: 0 });
  return appID;
}
function upstreamSchema(shard) {
  const { appID, shardNum } = check(shard);
  return `${appID}_${shardNum}`;
}
function cdcSchema(shard) {
  const { appID, shardNum } = check(shard);
  return `${appID}_${shardNum}/cdc`;
}
function cvrSchema(shard) {
  const { appID, shardNum } = check(shard);
  return `${appID}_${shardNum}/cvr`;
}
export {
  ALLOWED_APP_ID_CHARACTERS,
  INVALID_APP_ID_MESSAGE,
  appSchema,
  cdcSchema,
  check,
  cvrSchema,
  getShardConfig,
  getShardID,
  upstreamSchema
};
//# sourceMappingURL=shards.js.map
