{"version":3,"file":"wait-point-registry-B-ESkTZX.mjs","names":[],"sources":["../src/utils/wait-point-key-grammar.ts","../src/utils/wait-point-registry.ts"],"sourcesContent":["/**\n * The wait point key grammar shared by declaration-time validation\n * (parser) and runtime key composition (configure). Both sides must\n * accept exactly the same keys, so the rules live here once.\n */\nexport const WAIT_POINT_KEY_REGEX = /^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/;\nexport const WAIT_POINT_KEY_MAX_LENGTH = 63;\nexport const WAIT_POINT_KEY_GRAMMAR =\n  \"[a-z0-9-] (3-63 characters; must start and end with [a-z0-9])\";\n\n/**\n * Whether a `-`-separated key segment names a `$param`.\n * A bare \"$\" names nothing, so it is not a param on either side.\n * @param segment - One segment of a wait point key\n * @returns True when the segment is a `$param` reference\n */\nexport function isWaitPointParamSegment(segment: string): boolean {\n  return segment.startsWith(\"$\") && segment.length > 1;\n}\n","/**\n * How a wait point key reached the SDK. The declaration decides what the key\n * may contain: only `define` sees the key as a literal type, so only it can\n * type the `$params` a key carries.\n */\nexport type WaitPointDeclaration = \"createWaitPoint\" | \"define\" | \"property\";\n\n/** A wait point key as declared, before the deploy-time key rules run. */\nexport interface RegisteredWaitPoint {\n  key: string;\n  declaredBy: WaitPointDeclaration;\n}\n\nconst WAIT_POINT_REGISTRY_KEY: unique symbol = Symbol.for(\n  \"tailor-platform/sdk:wait-point-registry\",\n);\n\ninterface Registry {\n  entries: RegisteredWaitPoint[];\n  scopeStart: number;\n}\n\ntype GlobalWithRegistry = typeof globalThis & {\n  [WAIT_POINT_REGISTRY_KEY]?: Registry;\n};\n\nfunction registry(): Registry {\n  const g = globalThis as GlobalWithRegistry;\n  let state = g[WAIT_POINT_REGISTRY_KEY];\n  if (!state) {\n    state = { entries: [], scopeStart: 0 };\n    g[WAIT_POINT_REGISTRY_KEY] = state;\n  }\n  return state;\n}\n\n/**\n * Record a declared wait point key so the CLI can check it against the key\n * rules once the declaring module has loaded.\n * @param entry - The key and the declaration it came from\n */\nexport function registerWaitPoint(entry: RegisteredWaitPoint): void {\n  registry().entries.push(entry);\n}\n\n/**\n * Read every wait point declared by the modules loaded so far.\n * @returns The registered wait points, in declaration order\n */\nexport function getRegisteredWaitPoints(): readonly RegisteredWaitPoint[] {\n  return registry().entries;\n}\n\n/**\n * Start a scope here, so what a run declares can be told apart from what an\n * earlier one left behind.\n *\n * The registry is process-wide, and a run that fails partway still leaves its\n * keys in it. Without a scope, a second run in the same process would be judged\n * on the first run's keys as well as its own.\n */\nexport function beginWaitPointScope(): void {\n  const state = registry();\n  state.scopeStart = state.entries.length;\n}\n\n/**\n * Read the wait points declared since {@link beginWaitPointScope}, or every one\n * of them when no scope was started.\n * @returns The wait points registered in the current scope, in declaration order\n */\nexport function getScopedWaitPoints(): readonly RegisteredWaitPoint[] {\n  const state = registry();\n  return state.entries.slice(state.scopeStart);\n}\n\n/**\n * Drop everything registered after a mark, where the mark is the length\n * {@link getRegisteredWaitPoints} returned earlier.\n *\n * The registry is process-wide, so a test that declares a key `deploy` rejects\n * would otherwise leave it for the deploy-time check another test file runs.\n * Nothing outside a test needs this: a CLI run declares one project's keys and\n * checks all of them.\n * @param mark - The registry length to return to\n */\nexport function restoreWaitPointRegistry(mark: number): void {\n  const state = registry();\n  state.entries.length = mark;\n  if (state.scopeStart > mark) state.scopeStart = mark;\n}\n"],"mappings":"AAKA,MAAa,EAAuB,oCAEvB,EACX,gEAQF,SAAgB,wBAAwB,EAA0B,CAChE,OAAO,EAAQ,WAAW,GAAG,GAAK,EAAQ,OAAS,CACrD,CCLA,MAAM,EAAyC,OAAO,IACpD,yCACF,EAWA,SAAS,UAAqB,CAC5B,IAAM,EAAI,WACN,EAAQ,EAAE,GAKd,OAJK,IACH,EAAQ,CAAE,QAAS,CAAC,EAAG,WAAY,CAAE,EACrC,EAAE,GAA2B,GAExB,CACT,CAOA,SAAgB,kBAAkB,EAAkC,CAClE,SAAS,CAAC,CAAC,QAAQ,KAAK,CAAK,CAC/B,CAkBA,SAAgB,qBAA4B,CAC1C,IAAM,EAAQ,SAAS,EACvB,EAAM,WAAa,EAAM,QAAQ,MACnC,CAOA,SAAgB,qBAAsD,CACpE,IAAM,EAAQ,SAAS,EACvB,OAAO,EAAM,QAAQ,MAAM,EAAM,UAAU,CAC7C"}