{"version":3,"file":"PathParameter.mjs","names":[],"sources":["../src/PathParameter.ts"],"sourcesContent":["/**\n * The path parameters of a generated SDK function, as its URL carries them.\n *\n * @author Jeongho Nam - https://github.com/samchon\n * @evidence contracts/common.md#principled-implementation A path parameter is one URL path segment, so the value must be encoded as one segment and must never spell a dot segment, which the URL parser would resolve away.\n * @evidence contracts/common.md#clear-and-simple-design One namespace with one function, kept apart so both the SDK generator's output and hand-written callers use the same rule.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule applies to every value; no parameter name is special-cased.\n * @evidence contracts/common.md#meaningful-documentation The comment states the purpose of the namespace and the function documents the dot-segment refusal.\n */\nexport namespace PathParameter {\n  /**\n   * The parameter's value as one URL path segment: its text URI-encoded, or\n   * `\"null\"` when the value is nullish.\n   *\n   * `.` and `..` are refused. `encodeURIComponent` leaves them as they are, and\n   * the URL parser that `fetch` and `new URL()` share resolves them as dot\n   * segments, so the request would reach the parent path instead of the route,\n   * with the value gone. Their percent-encoded form is a dot segment by the\n   * same standard, so no spelling carries them.\n   *\n   * @param name Name of the parameter, for the error\n   * @param value Value of the parameter\n   * @returns The URI-encoded segment\n   * @throws Error when the value is `.` or `..`\n   * @evidence contracts/common.md#principled-implementation encodeURIComponent produces a single segment for well-formed Unicode text and throws URIError for unpaired surrogates; nullish input becomes the text null. The encoded text . or .. is refused because the WHATWG URL parser treats it and its percent-encoded spelling as a dot segment.\n   * @evidence contracts/common.md#clear-and-simple-design One conversion and one guard, with the reason for the guard stated in the comment.\n   * @evidence contracts/common.md#prohibited-implementation-shortcuts The guard prevents a request from silently reaching a different route, so it is a correctness check rather than a workaround for a test.\n   * @evidence contracts/common.md#meaningful-documentation The comment states the encoding, the nullish rule, the refused segments, their reason, and the thrown error.\n   */\n  export const encode = (name: string, value: unknown): string => {\n    const encoded: string = encodeURIComponent(\n      value === null || value === undefined ? \"null\" : String(value),\n    );\n    if (encoded === \".\" || encoded === \"..\")\n      throw new Error(\n        `Error on PathParameter.encode(): path parameter \"${name}\" is ${JSON.stringify(encoded)}, a dot segment the URL resolves away, which would send the request to another path.`,\n      );\n    return encoded;\n  };\n}\n"],"mappings":";AASO,IAAA;;0BAoBkB,MAAc,UAA2B;EAC9D,MAAM,UAAkB,mBACtB,UAAU,QAAQ,UAAU,KAAA,IAAY,SAAS,OAAO,KAAK,CAC/D;EACA,IAAI,YAAY,OAAO,YAAY,MACjC,MAAM,IAAI,MACR,oDAAoD,KAAK,OAAO,KAAK,UAAU,OAAO,EAAE,qFAC1F;EACF,OAAO;CACT;GACD,kBAAA,gBAAA,CAAA,EAAD"}