Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/resources/beta/index.d.ts +5 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.js.map +1 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/resources/beta/messages/index.js.map +1 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/_vendor/partial-json-parser/README.md +3 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/builtin-types.ts +93 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/decoders/jsonl.ts +48 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/types.ts +92 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/utils.ts +8 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/utils/bytes.ts +32 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/utils/path.ts +65 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/batches.ts +502 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/messages.ts +3 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/messages/batches.ts +396 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/models.ts +103 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.github/dependabot.yml +13 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.github/tests_checker.yml +8 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.github/workflows/ci.yml +26 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.taprc +2 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/lib/default-ajv-options.js +14 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/lib/validator-compiler.js +58 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/test/index.test.js +307 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/test/plugins.test.js +264 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/test/serialization.test.js +279 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/types/index.test-d.ts +226 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/.editorconfig +8 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/.gitattributes +5 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/.github/stale.yml +21 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/bench.js +17 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/benchmark/package.json +15 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/benchmark/vary.js +34 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/test/cors.test.js +1052 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/test/vary.test.js +237 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/types/index.d.ts +126 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/.github/dependabot.yml +13 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/.github/workflows/ci.yml +28 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/create.js +9 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/instantiate.js +18 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/no-stack.js +13 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/toString.js +11 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/test/instanceof.test.js +263 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/types/index.d.ts +49 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/types/index.test-d.ts +92 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc +1 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.gitattributes +2 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml +28 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/index.js +8 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/package.json +71 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/standalone.test.js +230 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.d.ts +41 -0
- platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.test-d.ts +142 -0
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/resources/beta/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export { Beta, type AnthropicBeta, type BetaAPIError, type BetaAuthenticationError, type BetaBillingError, type BetaError, type BetaErrorResponse, type BetaGatewayTimeoutError, type BetaInvalidRequestError, type BetaNotFoundError, type BetaOverloadedError, type BetaPermissionError, type BetaRateLimitError, } from "./beta.js";
|
| 2 |
+
export { Files, type DeletedFile, type FileMetadata, type FileListParams, type FileDeleteParams, type FileDownloadParams, type FileRetrieveMetadataParams, type FileUploadParams, type FileMetadataPage, } from "./files.js";
|
| 3 |
+
export { Messages, type BetaBase64ImageSource, type BetaBase64PDFSource, type BetaCacheControlEphemeral, type BetaCacheCreation, type BetaCitationCharLocation, type BetaCitationCharLocationParam, type BetaCitationContentBlockLocation, type BetaCitationContentBlockLocationParam, type BetaCitationPageLocation, type BetaCitationPageLocationParam, type BetaCitationWebSearchResultLocationParam, type BetaCitationsConfigParam, type BetaCitationsDelta, type BetaCitationsWebSearchResultLocation, type BetaCodeExecutionOutputBlock, type BetaCodeExecutionOutputBlockParam, type BetaCodeExecutionResultBlock, type BetaCodeExecutionResultBlockParam, type BetaCodeExecutionTool20250522, type BetaCodeExecutionToolResultBlock, type BetaCodeExecutionToolResultBlockContent, type BetaCodeExecutionToolResultBlockParam, type BetaCodeExecutionToolResultBlockParamContent, type BetaCodeExecutionToolResultError, type BetaCodeExecutionToolResultErrorCode, type BetaCodeExecutionToolResultErrorParam, type BetaContainer, type BetaContainerUploadBlock, type BetaContainerUploadBlockParam, type BetaContentBlock, type BetaContentBlockParam, type BetaContentBlockSource, type BetaContentBlockSourceContent, type BetaFileDocumentSource, type BetaFileImageSource, type BetaImageBlockParam, type BetaInputJSONDelta, type BetaMCPToolResultBlock, type BetaMCPToolUseBlock, type BetaMCPToolUseBlockParam, type BetaMessage, type BetaMessageDeltaUsage, type BetaMessageParam, type BetaMessageTokensCount, type BetaMetadata, type BetaPlainTextSource, type BetaRawContentBlockDelta, type BetaRawContentBlockDeltaEvent, type BetaRawContentBlockStartEvent, type BetaRawContentBlockStopEvent, type BetaRawMessageDeltaEvent, type BetaRawMessageStartEvent, type BetaRawMessageStopEvent, type BetaRawMessageStreamEvent, type BetaRedactedThinkingBlock, type BetaRedactedThinkingBlockParam, type BetaRequestDocumentBlock, type BetaRequestMCPServerToolConfiguration, type BetaRequestMCPServerURLDefinition, type BetaRequestMCPToolResultBlockParam, type BetaServerToolUsage, type BetaServerToolUseBlock, type BetaServerToolUseBlockParam, type BetaSignatureDelta, type BetaStopReason, type BetaTextBlock, type BetaTextBlockParam, type BetaTextCitation, type BetaTextCitationParam, type BetaTextDelta, type BetaThinkingBlock, type BetaThinkingBlockParam, type BetaThinkingConfigDisabled, type BetaThinkingConfigEnabled, type BetaThinkingConfigParam, type BetaThinkingDelta, type BetaTool, type BetaToolBash20241022, type BetaToolBash20250124, type BetaToolChoice, type BetaToolChoiceAny, type BetaToolChoiceAuto, type BetaToolChoiceNone, type BetaToolChoiceTool, type BetaToolComputerUse20241022, type BetaToolComputerUse20250124, type BetaToolResultBlockParam, type BetaToolTextEditor20241022, type BetaToolTextEditor20250124, type BetaToolTextEditor20250429, type BetaToolUnion, type BetaToolUseBlock, type BetaToolUseBlockParam, type BetaURLImageSource, type BetaURLPDFSource, type BetaUsage, type BetaWebSearchResultBlock, type BetaWebSearchResultBlockParam, type BetaWebSearchTool20250305, type BetaWebSearchToolRequestError, type BetaWebSearchToolResultBlock, type BetaWebSearchToolResultBlockContent, type BetaWebSearchToolResultBlockParam, type BetaWebSearchToolResultBlockParamContent, type BetaWebSearchToolResultError, type BetaWebSearchToolResultErrorCode, type BetaBase64PDFBlock, type MessageCreateParams, type MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming, type MessageCountTokensParams, } from "./messages/index.js";
|
| 4 |
+
export { Models, type BetaModelInfo, type ModelRetrieveParams, type ModelListParams, type BetaModelInfosPage, } from "./models.js";
|
| 5 |
+
//# sourceMappingURL=index.d.ts.map
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"batches.js","sourceRoot":"","sources":["../../../src/resources/beta/messages/batches.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,wDAAqD;AAIrD,4DAA8E;AAC9E,0DAAyD;AAEzD,+DAAgE;AAChE,6CAAgD;AAChD,0DAAoD;AAEpD,MAAa,OAAQ,SAAQ,sBAAW;IACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,MAAM,CAAC,MAAyB,EAAE,OAAwB;QACxD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gCAAgC,EAAE;YACzD,IAAI;YACJ,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjF,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CACN,cAAsB,EACtB,SAAiD,EAAE,EACnD,OAAwB;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAA,WAAI,EAAA,wBAAwB,cAAc,YAAY,EAAE;YAC9E,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjF,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAI,CACF,SAA6C,EAAE,EAC/C,OAAwB;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,gCAAgC,EAAE,CAAA,iBAAsB,CAAA,EAAE;YACvF,KAAK;YACL,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjF,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CACJ,cAAsB,EACtB,SAA+C,EAAE,EACjD,OAAwB;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAA,WAAI,EAAA,wBAAwB,cAAc,YAAY,EAAE;YACjF,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjF,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CACJ,cAAsB,EACtB,SAA+C,EAAE,EACjD,OAAwB;QAExB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAA,WAAI,EAAA,wBAAwB,cAAc,mBAAmB,EAAE;YACtF,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjF,OAAO,EAAE,OAAO;aACjB,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,OAAO,CACX,cAAsB,EACtB,SAAyC,EAAE,EAC3C,OAAwB;QAExB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YACvB,MAAM,IAAI,sBAAc,CACtB,yDAAyD,KAAK,CAAC,iBAAiB,MAAM,KAAK,CAAC,EAAE,EAAE,CACjG,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,OAAO;aAChB,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;YACtB,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC;gBACpB;oBACE,gBAAgB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,4BAA4B,CAAC,CAAC,QAAQ,EAAE;oBAC7E,MAAM,EAAE,oBAAoB;iBAC7B;gBACD,OAAO,EAAE,OAAO;aACjB,CAAC;YACF,MAAM,EAAE,IAAI;YACZ,gBAAgB,EAAE,IAAI;SACvB,CAAC;aACD,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,oBAAY,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAEvF,CAAC;IACJ,CAAC;CACF;AA5ND,0BA4NC"}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/resources/beta/messages/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/resources/beta/messages/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,wCAkBmB;AAjBjB,kGAAA,OAAO,OAAA;AAkBT,0CAkHoB;AAjHlB,oGAAA,QAAQ,OAAA"}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/_vendor/partial-json-parser/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Partial JSON Parser
|
| 2 |
+
|
| 3 |
+
Vendored from https://www.npmjs.com/package/partial-json-parser and updated to use TypeScript.
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/builtin-types.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* An alias to the builtin `RequestInit` type so we can
|
| 7 |
+
* easily alias it in import statements if there are name clashes.
|
| 8 |
+
*
|
| 9 |
+
* https://developer.mozilla.org/docs/Web/API/RequestInit
|
| 10 |
+
*/
|
| 11 |
+
type _RequestInit = RequestInit;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* An alias to the builtin `Response` type so we can
|
| 15 |
+
* easily alias it in import statements if there are name clashes.
|
| 16 |
+
*
|
| 17 |
+
* https://developer.mozilla.org/docs/Web/API/Response
|
| 18 |
+
*/
|
| 19 |
+
type _Response = Response;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* The type for the first argument to `fetch`.
|
| 23 |
+
*
|
| 24 |
+
* https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
|
| 25 |
+
*/
|
| 26 |
+
type _RequestInfo = Request | URL | string;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* The type for constructing `RequestInit` Headers.
|
| 30 |
+
*
|
| 31 |
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
|
| 32 |
+
*/
|
| 33 |
+
type _HeadersInit = RequestInit['headers'];
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* The type for constructing `RequestInit` body.
|
| 37 |
+
*
|
| 38 |
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#body
|
| 39 |
+
*/
|
| 40 |
+
type _BodyInit = RequestInit['body'];
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* An alias to the builtin `Array<T>` type so we can
|
| 44 |
+
* easily alias it in import statements if there are name clashes.
|
| 45 |
+
*/
|
| 46 |
+
type _Array<T> = Array<T>;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* An alias to the builtin `Record<K, T>` type so we can
|
| 50 |
+
* easily alias it in import statements if there are name clashes.
|
| 51 |
+
*/
|
| 52 |
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
| 53 |
+
|
| 54 |
+
export type {
|
| 55 |
+
_Array as Array,
|
| 56 |
+
_BodyInit as BodyInit,
|
| 57 |
+
_HeadersInit as HeadersInit,
|
| 58 |
+
_Record as Record,
|
| 59 |
+
_RequestInfo as RequestInfo,
|
| 60 |
+
_RequestInit as RequestInit,
|
| 61 |
+
_Response as Response,
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* A copy of the builtin `EndingType` type as it isn't fully supported in certain
|
| 66 |
+
* environments and attempting to reference the global version will error.
|
| 67 |
+
*
|
| 68 |
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
|
| 69 |
+
*/
|
| 70 |
+
type EndingType = 'native' | 'transparent';
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
|
| 74 |
+
* environments and attempting to reference the global version will error.
|
| 75 |
+
*
|
| 76 |
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
|
| 77 |
+
* https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
|
| 78 |
+
*/
|
| 79 |
+
export interface BlobPropertyBag {
|
| 80 |
+
endings?: EndingType;
|
| 81 |
+
type?: string;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
|
| 86 |
+
* environments and attempting to reference the global version will error.
|
| 87 |
+
*
|
| 88 |
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
|
| 89 |
+
* https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
|
| 90 |
+
*/
|
| 91 |
+
export interface FilePropertyBag extends BlobPropertyBag {
|
| 92 |
+
lastModified?: number;
|
| 93 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/decoders/jsonl.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AnthropicError } from '../../core/error';
|
| 2 |
+
import { ReadableStreamToAsyncIterable } from '../shims';
|
| 3 |
+
import { LineDecoder, type Bytes } from './line';
|
| 4 |
+
|
| 5 |
+
export class JSONLDecoder<T> {
|
| 6 |
+
controller: AbortController;
|
| 7 |
+
|
| 8 |
+
constructor(
|
| 9 |
+
private iterator: AsyncIterableIterator<Bytes>,
|
| 10 |
+
controller: AbortController,
|
| 11 |
+
) {
|
| 12 |
+
this.controller = controller;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
private async *decoder(): AsyncIterator<T, any, undefined> {
|
| 16 |
+
const lineDecoder = new LineDecoder();
|
| 17 |
+
for await (const chunk of this.iterator) {
|
| 18 |
+
for (const line of lineDecoder.decode(chunk)) {
|
| 19 |
+
yield JSON.parse(line);
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
for (const line of lineDecoder.flush()) {
|
| 24 |
+
yield JSON.parse(line);
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
[Symbol.asyncIterator](): AsyncIterator<T> {
|
| 29 |
+
return this.decoder();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
static fromResponse<T>(response: Response, controller: AbortController): JSONLDecoder<T> {
|
| 33 |
+
if (!response.body) {
|
| 34 |
+
controller.abort();
|
| 35 |
+
if (
|
| 36 |
+
typeof (globalThis as any).navigator !== 'undefined' &&
|
| 37 |
+
(globalThis as any).navigator.product === 'ReactNative'
|
| 38 |
+
) {
|
| 39 |
+
throw new AnthropicError(
|
| 40 |
+
`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`,
|
| 41 |
+
);
|
| 42 |
+
}
|
| 43 |
+
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return new JSONLDecoder(ReadableStreamToAsyncIterable<Bytes>(response.body), controller);
|
| 47 |
+
}
|
| 48 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/types.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export type PromiseOrValue<T> = T | Promise<T>;
|
| 4 |
+
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
| 5 |
+
|
| 6 |
+
export type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
| 7 |
+
|
| 8 |
+
export type FinalizedRequestInit = RequestInit & { headers: Headers };
|
| 9 |
+
|
| 10 |
+
type NotAny<T> = [unknown] extends [T] ? never : T;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
| 14 |
+
*/
|
| 15 |
+
type OverloadedParameters<T> =
|
| 16 |
+
T extends (
|
| 17 |
+
{
|
| 18 |
+
(...args: infer A): unknown;
|
| 19 |
+
(...args: infer B): unknown;
|
| 20 |
+
(...args: infer C): unknown;
|
| 21 |
+
(...args: infer D): unknown;
|
| 22 |
+
}
|
| 23 |
+
) ?
|
| 24 |
+
A | B | C | D
|
| 25 |
+
: T extends (
|
| 26 |
+
{
|
| 27 |
+
(...args: infer A): unknown;
|
| 28 |
+
(...args: infer B): unknown;
|
| 29 |
+
(...args: infer C): unknown;
|
| 30 |
+
}
|
| 31 |
+
) ?
|
| 32 |
+
A | B | C
|
| 33 |
+
: T extends (
|
| 34 |
+
{
|
| 35 |
+
(...args: infer A): unknown;
|
| 36 |
+
(...args: infer B): unknown;
|
| 37 |
+
}
|
| 38 |
+
) ?
|
| 39 |
+
A | B
|
| 40 |
+
: T extends (...args: infer A) => unknown ? A
|
| 41 |
+
: never;
|
| 42 |
+
|
| 43 |
+
/* eslint-disable */
|
| 44 |
+
/**
|
| 45 |
+
* These imports attempt to get types from a parent package's dependencies.
|
| 46 |
+
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
| 47 |
+
* would cause typescript to show types not present at runtime. To avoid this, we import
|
| 48 |
+
* directly from parent node_modules folders.
|
| 49 |
+
*
|
| 50 |
+
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
| 51 |
+
* For example, pnpm generates directories like this:
|
| 52 |
+
* ```
|
| 53 |
+
* node_modules
|
| 54 |
+
* ├── .pnpm
|
| 55 |
+
* │ └── pkg@1.0.0
|
| 56 |
+
* │ └── node_modules
|
| 57 |
+
* │ └── pkg
|
| 58 |
+
* │ └── internal
|
| 59 |
+
* │ └── types.d.ts
|
| 60 |
+
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
| 61 |
+
* └── undici
|
| 62 |
+
* ```
|
| 63 |
+
*
|
| 64 |
+
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
| 65 |
+
*/
|
| 66 |
+
/** @ts-ignore For users with \@types/node */
|
| 67 |
+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types').RequestInit> | NotAny<import('../../node_modules/undici-types').RequestInit> | NotAny<import('../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types').RequestInit>;
|
| 68 |
+
/** @ts-ignore For users with undici */
|
| 69 |
+
type UndiciRequestInit = NotAny<import('../node_modules/undici').RequestInit> | NotAny<import('../../node_modules/undici').RequestInit> | NotAny<import('../../../node_modules/undici').RequestInit> | NotAny<import('../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici').RequestInit>;
|
| 70 |
+
/** @ts-ignore For users with \@types/bun */
|
| 71 |
+
type BunRequestInit = globalThis.FetchRequestInit;
|
| 72 |
+
/** @ts-ignore For users with node-fetch */
|
| 73 |
+
type NodeFetchRequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
| 74 |
+
/** @ts-ignore For users who use Deno */
|
| 75 |
+
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
| 76 |
+
/* eslint-enable */
|
| 77 |
+
|
| 78 |
+
type RequestInits =
|
| 79 |
+
| NotAny<UndiciTypesRequestInit>
|
| 80 |
+
| NotAny<UndiciRequestInit>
|
| 81 |
+
| NotAny<BunRequestInit>
|
| 82 |
+
| NotAny<NodeFetchRequestInit>
|
| 83 |
+
| NotAny<RequestInit>
|
| 84 |
+
| NotAny<FetchRequestInit>;
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* This type contains `RequestInit` options that may be available on the current runtime,
|
| 88 |
+
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
| 89 |
+
*/
|
| 90 |
+
export type MergedRequestInit = RequestInits &
|
| 91 |
+
/** We don't include these in the types as they'll be overridden for every request. */
|
| 92 |
+
Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/utils.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './utils/values';
|
| 4 |
+
export * from './utils/base64';
|
| 5 |
+
export * from './utils/env';
|
| 6 |
+
export * from './utils/log';
|
| 7 |
+
export * from './utils/uuid';
|
| 8 |
+
export * from './utils/sleep';
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/utils/bytes.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function concatBytes(buffers: Uint8Array[]): Uint8Array {
|
| 2 |
+
let length = 0;
|
| 3 |
+
for (const buffer of buffers) {
|
| 4 |
+
length += buffer.length;
|
| 5 |
+
}
|
| 6 |
+
const output = new Uint8Array(length);
|
| 7 |
+
let index = 0;
|
| 8 |
+
for (const buffer of buffers) {
|
| 9 |
+
output.set(buffer, index);
|
| 10 |
+
index += buffer.length;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
return output;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
let encodeUTF8_: (str: string) => Uint8Array;
|
| 17 |
+
export function encodeUTF8(str: string) {
|
| 18 |
+
let encoder;
|
| 19 |
+
return (
|
| 20 |
+
encodeUTF8_ ??
|
| 21 |
+
((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))
|
| 22 |
+
)(str);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
let decodeUTF8_: (bytes: Uint8Array) => string;
|
| 26 |
+
export function decodeUTF8(bytes: Uint8Array) {
|
| 27 |
+
let decoder;
|
| 28 |
+
return (
|
| 29 |
+
decodeUTF8_ ??
|
| 30 |
+
((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))
|
| 31 |
+
)(bytes);
|
| 32 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/internal/utils/path.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AnthropicError } from '../../core/error';
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
| 5 |
+
*
|
| 6 |
+
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
| 7 |
+
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
| 8 |
+
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
| 9 |
+
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
| 10 |
+
*/
|
| 11 |
+
export function encodeURIPath(str: string) {
|
| 12 |
+
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
| 16 |
+
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
| 17 |
+
// If there are no params, no processing is needed.
|
| 18 |
+
if (statics.length === 1) return statics[0]!;
|
| 19 |
+
|
| 20 |
+
let postPath = false;
|
| 21 |
+
const path = statics.reduce((previousValue, currentValue, index) => {
|
| 22 |
+
if (/[?#]/.test(currentValue)) {
|
| 23 |
+
postPath = true;
|
| 24 |
+
}
|
| 25 |
+
return (
|
| 26 |
+
previousValue +
|
| 27 |
+
currentValue +
|
| 28 |
+
(index === params.length ? '' : (postPath ? encodeURIComponent : pathEncoder)(String(params[index])))
|
| 29 |
+
);
|
| 30 |
+
}, '');
|
| 31 |
+
|
| 32 |
+
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
| 33 |
+
const invalidSegments = [];
|
| 34 |
+
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
| 35 |
+
let match;
|
| 36 |
+
|
| 37 |
+
// Find all invalid segments
|
| 38 |
+
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
| 39 |
+
invalidSegments.push({
|
| 40 |
+
start: match.index,
|
| 41 |
+
length: match[0].length,
|
| 42 |
+
});
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if (invalidSegments.length > 0) {
|
| 46 |
+
let lastEnd = 0;
|
| 47 |
+
const underline = invalidSegments.reduce((acc, segment) => {
|
| 48 |
+
const spaces = ' '.repeat(segment.start - lastEnd);
|
| 49 |
+
const arrows = '^'.repeat(segment.length);
|
| 50 |
+
lastEnd = segment.start + segment.length;
|
| 51 |
+
return acc + spaces + arrows;
|
| 52 |
+
}, '');
|
| 53 |
+
|
| 54 |
+
throw new AnthropicError(
|
| 55 |
+
`Path parameters result in path with invalid segments:\n${path}\n${underline}`,
|
| 56 |
+
);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
return path;
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
| 64 |
+
*/
|
| 65 |
+
export const path = createPathTagFunction(encodeURIPath);
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/batches.ts
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../../core/resource';
|
| 4 |
+
import * as BetaAPI from '../beta';
|
| 5 |
+
import { APIPromise } from '../../../core/api-promise';
|
| 6 |
+
import * as BetaMessagesAPI from './messages';
|
| 7 |
+
import { Page, type PageParams, PagePromise } from '../../../core/pagination';
|
| 8 |
+
import { buildHeaders } from '../../../internal/headers';
|
| 9 |
+
import { RequestOptions } from '../../../internal/request-options';
|
| 10 |
+
import { JSONLDecoder } from '../../../internal/decoders/jsonl';
|
| 11 |
+
import { AnthropicError } from '../../../error';
|
| 12 |
+
import { path } from '../../../internal/utils/path';
|
| 13 |
+
|
| 14 |
+
export class Batches extends APIResource {
|
| 15 |
+
/**
|
| 16 |
+
* Send a batch of Message creation requests.
|
| 17 |
+
*
|
| 18 |
+
* The Message Batches API can be used to process multiple Messages API requests at
|
| 19 |
+
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
| 20 |
+
* can take up to 24 hours to complete.
|
| 21 |
+
*
|
| 22 |
+
* Learn more about the Message Batches API in our
|
| 23 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* ```ts
|
| 27 |
+
* const betaMessageBatch =
|
| 28 |
+
* await client.beta.messages.batches.create({
|
| 29 |
+
* requests: [
|
| 30 |
+
* {
|
| 31 |
+
* custom_id: 'my-custom-id-1',
|
| 32 |
+
* params: {
|
| 33 |
+
* max_tokens: 1024,
|
| 34 |
+
* messages: [
|
| 35 |
+
* { content: 'Hello, world', role: 'user' },
|
| 36 |
+
* ],
|
| 37 |
+
* model: 'claude-3-7-sonnet-20250219',
|
| 38 |
+
* },
|
| 39 |
+
* },
|
| 40 |
+
* ],
|
| 41 |
+
* });
|
| 42 |
+
* ```
|
| 43 |
+
*/
|
| 44 |
+
create(params: BatchCreateParams, options?: RequestOptions): APIPromise<BetaMessageBatch> {
|
| 45 |
+
const { betas, ...body } = params;
|
| 46 |
+
return this._client.post('/v1/messages/batches?beta=true', {
|
| 47 |
+
body,
|
| 48 |
+
...options,
|
| 49 |
+
headers: buildHeaders([
|
| 50 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 51 |
+
options?.headers,
|
| 52 |
+
]),
|
| 53 |
+
});
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* This endpoint is idempotent and can be used to poll for Message Batch
|
| 58 |
+
* completion. To access the results of a Message Batch, make a request to the
|
| 59 |
+
* `results_url` field in the response.
|
| 60 |
+
*
|
| 61 |
+
* Learn more about the Message Batches API in our
|
| 62 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 63 |
+
*
|
| 64 |
+
* @example
|
| 65 |
+
* ```ts
|
| 66 |
+
* const betaMessageBatch =
|
| 67 |
+
* await client.beta.messages.batches.retrieve(
|
| 68 |
+
* 'message_batch_id',
|
| 69 |
+
* );
|
| 70 |
+
* ```
|
| 71 |
+
*/
|
| 72 |
+
retrieve(
|
| 73 |
+
messageBatchID: string,
|
| 74 |
+
params: BatchRetrieveParams | null | undefined = {},
|
| 75 |
+
options?: RequestOptions,
|
| 76 |
+
): APIPromise<BetaMessageBatch> {
|
| 77 |
+
const { betas } = params ?? {};
|
| 78 |
+
return this._client.get(path`/v1/messages/batches/${messageBatchID}?beta=true`, {
|
| 79 |
+
...options,
|
| 80 |
+
headers: buildHeaders([
|
| 81 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 82 |
+
options?.headers,
|
| 83 |
+
]),
|
| 84 |
+
});
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* List all Message Batches within a Workspace. Most recently created batches are
|
| 89 |
+
* returned first.
|
| 90 |
+
*
|
| 91 |
+
* Learn more about the Message Batches API in our
|
| 92 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 93 |
+
*
|
| 94 |
+
* @example
|
| 95 |
+
* ```ts
|
| 96 |
+
* // Automatically fetches more pages as needed.
|
| 97 |
+
* for await (const betaMessageBatch of client.beta.messages.batches.list()) {
|
| 98 |
+
* // ...
|
| 99 |
+
* }
|
| 100 |
+
* ```
|
| 101 |
+
*/
|
| 102 |
+
list(
|
| 103 |
+
params: BatchListParams | null | undefined = {},
|
| 104 |
+
options?: RequestOptions,
|
| 105 |
+
): PagePromise<BetaMessageBatchesPage, BetaMessageBatch> {
|
| 106 |
+
const { betas, ...query } = params ?? {};
|
| 107 |
+
return this._client.getAPIList('/v1/messages/batches?beta=true', Page<BetaMessageBatch>, {
|
| 108 |
+
query,
|
| 109 |
+
...options,
|
| 110 |
+
headers: buildHeaders([
|
| 111 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 112 |
+
options?.headers,
|
| 113 |
+
]),
|
| 114 |
+
});
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Delete a Message Batch.
|
| 119 |
+
*
|
| 120 |
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
| 121 |
+
* like to delete an in-progress batch, you must first cancel it.
|
| 122 |
+
*
|
| 123 |
+
* Learn more about the Message Batches API in our
|
| 124 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 125 |
+
*
|
| 126 |
+
* @example
|
| 127 |
+
* ```ts
|
| 128 |
+
* const betaDeletedMessageBatch =
|
| 129 |
+
* await client.beta.messages.batches.delete(
|
| 130 |
+
* 'message_batch_id',
|
| 131 |
+
* );
|
| 132 |
+
* ```
|
| 133 |
+
*/
|
| 134 |
+
delete(
|
| 135 |
+
messageBatchID: string,
|
| 136 |
+
params: BatchDeleteParams | null | undefined = {},
|
| 137 |
+
options?: RequestOptions,
|
| 138 |
+
): APIPromise<BetaDeletedMessageBatch> {
|
| 139 |
+
const { betas } = params ?? {};
|
| 140 |
+
return this._client.delete(path`/v1/messages/batches/${messageBatchID}?beta=true`, {
|
| 141 |
+
...options,
|
| 142 |
+
headers: buildHeaders([
|
| 143 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 144 |
+
options?.headers,
|
| 145 |
+
]),
|
| 146 |
+
});
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Batches may be canceled any time before processing ends. Once cancellation is
|
| 151 |
+
* initiated, the batch enters a `canceling` state, at which time the system may
|
| 152 |
+
* complete any in-progress, non-interruptible requests before finalizing
|
| 153 |
+
* cancellation.
|
| 154 |
+
*
|
| 155 |
+
* The number of canceled requests is specified in `request_counts`. To determine
|
| 156 |
+
* which requests were canceled, check the individual results within the batch.
|
| 157 |
+
* Note that cancellation may not result in any canceled requests if they were
|
| 158 |
+
* non-interruptible.
|
| 159 |
+
*
|
| 160 |
+
* Learn more about the Message Batches API in our
|
| 161 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 162 |
+
*
|
| 163 |
+
* @example
|
| 164 |
+
* ```ts
|
| 165 |
+
* const betaMessageBatch =
|
| 166 |
+
* await client.beta.messages.batches.cancel(
|
| 167 |
+
* 'message_batch_id',
|
| 168 |
+
* );
|
| 169 |
+
* ```
|
| 170 |
+
*/
|
| 171 |
+
cancel(
|
| 172 |
+
messageBatchID: string,
|
| 173 |
+
params: BatchCancelParams | null | undefined = {},
|
| 174 |
+
options?: RequestOptions,
|
| 175 |
+
): APIPromise<BetaMessageBatch> {
|
| 176 |
+
const { betas } = params ?? {};
|
| 177 |
+
return this._client.post(path`/v1/messages/batches/${messageBatchID}/cancel?beta=true`, {
|
| 178 |
+
...options,
|
| 179 |
+
headers: buildHeaders([
|
| 180 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 181 |
+
options?.headers,
|
| 182 |
+
]),
|
| 183 |
+
});
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Streams the results of a Message Batch as a `.jsonl` file.
|
| 188 |
+
*
|
| 189 |
+
* Each line in the file is a JSON object containing the result of a single request
|
| 190 |
+
* in the Message Batch. Results are not guaranteed to be in the same order as
|
| 191 |
+
* requests. Use the `custom_id` field to match results to requests.
|
| 192 |
+
*
|
| 193 |
+
* Learn more about the Message Batches API in our
|
| 194 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 195 |
+
*
|
| 196 |
+
* @example
|
| 197 |
+
* ```ts
|
| 198 |
+
* const betaMessageBatchIndividualResponse =
|
| 199 |
+
* await client.beta.messages.batches.results(
|
| 200 |
+
* 'message_batch_id',
|
| 201 |
+
* );
|
| 202 |
+
* ```
|
| 203 |
+
*/
|
| 204 |
+
async results(
|
| 205 |
+
messageBatchID: string,
|
| 206 |
+
params: BatchResultsParams | undefined = {},
|
| 207 |
+
options?: RequestOptions,
|
| 208 |
+
): Promise<JSONLDecoder<BetaMessageBatchIndividualResponse>> {
|
| 209 |
+
const batch = await this.retrieve(messageBatchID);
|
| 210 |
+
if (!batch.results_url) {
|
| 211 |
+
throw new AnthropicError(
|
| 212 |
+
`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`,
|
| 213 |
+
);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
const { betas } = params ?? {};
|
| 217 |
+
return this._client
|
| 218 |
+
.get(batch.results_url, {
|
| 219 |
+
...options,
|
| 220 |
+
headers: buildHeaders([
|
| 221 |
+
{
|
| 222 |
+
'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
|
| 223 |
+
Accept: 'application/binary',
|
| 224 |
+
},
|
| 225 |
+
options?.headers,
|
| 226 |
+
]),
|
| 227 |
+
stream: true,
|
| 228 |
+
__binaryResponse: true,
|
| 229 |
+
})
|
| 230 |
+
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller)) as APIPromise<
|
| 231 |
+
JSONLDecoder<BetaMessageBatchIndividualResponse>
|
| 232 |
+
>;
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
export type BetaMessageBatchesPage = Page<BetaMessageBatch>;
|
| 237 |
+
|
| 238 |
+
export interface BetaDeletedMessageBatch {
|
| 239 |
+
/**
|
| 240 |
+
* ID of the Message Batch.
|
| 241 |
+
*/
|
| 242 |
+
id: string;
|
| 243 |
+
|
| 244 |
+
/**
|
| 245 |
+
* Deleted object type.
|
| 246 |
+
*
|
| 247 |
+
* For Message Batches, this is always `"message_batch_deleted"`.
|
| 248 |
+
*/
|
| 249 |
+
type: 'message_batch_deleted';
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
export interface BetaMessageBatch {
|
| 253 |
+
/**
|
| 254 |
+
* Unique object identifier.
|
| 255 |
+
*
|
| 256 |
+
* The format and length of IDs may change over time.
|
| 257 |
+
*/
|
| 258 |
+
id: string;
|
| 259 |
+
|
| 260 |
+
/**
|
| 261 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 262 |
+
* archived and its results became unavailable.
|
| 263 |
+
*/
|
| 264 |
+
archived_at: string | null;
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
* RFC 3339 datetime string representing the time at which cancellation was
|
| 268 |
+
* initiated for the Message Batch. Specified only if cancellation was initiated.
|
| 269 |
+
*/
|
| 270 |
+
cancel_initiated_at: string | null;
|
| 271 |
+
|
| 272 |
+
/**
|
| 273 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 274 |
+
* created.
|
| 275 |
+
*/
|
| 276 |
+
created_at: string;
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* RFC 3339 datetime string representing the time at which processing for the
|
| 280 |
+
* Message Batch ended. Specified only once processing ends.
|
| 281 |
+
*
|
| 282 |
+
* Processing ends when every request in a Message Batch has either succeeded,
|
| 283 |
+
* errored, canceled, or expired.
|
| 284 |
+
*/
|
| 285 |
+
ended_at: string | null;
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* RFC 3339 datetime string representing the time at which the Message Batch will
|
| 289 |
+
* expire and end processing, which is 24 hours after creation.
|
| 290 |
+
*/
|
| 291 |
+
expires_at: string;
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Processing status of the Message Batch.
|
| 295 |
+
*/
|
| 296 |
+
processing_status: 'in_progress' | 'canceling' | 'ended';
|
| 297 |
+
|
| 298 |
+
/**
|
| 299 |
+
* Tallies requests within the Message Batch, categorized by their status.
|
| 300 |
+
*
|
| 301 |
+
* Requests start as `processing` and move to one of the other statuses only once
|
| 302 |
+
* processing of the entire batch ends. The sum of all values always matches the
|
| 303 |
+
* total number of requests in the batch.
|
| 304 |
+
*/
|
| 305 |
+
request_counts: BetaMessageBatchRequestCounts;
|
| 306 |
+
|
| 307 |
+
/**
|
| 308 |
+
* URL to a `.jsonl` file containing the results of the Message Batch requests.
|
| 309 |
+
* Specified only once processing ends.
|
| 310 |
+
*
|
| 311 |
+
* Results in the file are not guaranteed to be in the same order as requests. Use
|
| 312 |
+
* the `custom_id` field to match results to requests.
|
| 313 |
+
*/
|
| 314 |
+
results_url: string | null;
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Object type.
|
| 318 |
+
*
|
| 319 |
+
* For Message Batches, this is always `"message_batch"`.
|
| 320 |
+
*/
|
| 321 |
+
type: 'message_batch';
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
export interface BetaMessageBatchCanceledResult {
|
| 325 |
+
type: 'canceled';
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
export interface BetaMessageBatchErroredResult {
|
| 329 |
+
error: BetaAPI.BetaErrorResponse;
|
| 330 |
+
|
| 331 |
+
type: 'errored';
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
export interface BetaMessageBatchExpiredResult {
|
| 335 |
+
type: 'expired';
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
/**
|
| 339 |
+
* This is a single line in the response `.jsonl` file and does not represent the
|
| 340 |
+
* response as a whole.
|
| 341 |
+
*/
|
| 342 |
+
export interface BetaMessageBatchIndividualResponse {
|
| 343 |
+
/**
|
| 344 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 345 |
+
* matching results to requests, as results may be given out of request order.
|
| 346 |
+
*
|
| 347 |
+
* Must be unique for each request within the Message Batch.
|
| 348 |
+
*/
|
| 349 |
+
custom_id: string;
|
| 350 |
+
|
| 351 |
+
/**
|
| 352 |
+
* Processing result for this request.
|
| 353 |
+
*
|
| 354 |
+
* Contains a Message output if processing was successful, an error response if
|
| 355 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 356 |
+
* cancellation or expiration.
|
| 357 |
+
*/
|
| 358 |
+
result: BetaMessageBatchResult;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
export interface BetaMessageBatchRequestCounts {
|
| 362 |
+
/**
|
| 363 |
+
* Number of requests in the Message Batch that have been canceled.
|
| 364 |
+
*
|
| 365 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 366 |
+
*/
|
| 367 |
+
canceled: number;
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* Number of requests in the Message Batch that encountered an error.
|
| 371 |
+
*
|
| 372 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 373 |
+
*/
|
| 374 |
+
errored: number;
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* Number of requests in the Message Batch that have expired.
|
| 378 |
+
*
|
| 379 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 380 |
+
*/
|
| 381 |
+
expired: number;
|
| 382 |
+
|
| 383 |
+
/**
|
| 384 |
+
* Number of requests in the Message Batch that are processing.
|
| 385 |
+
*/
|
| 386 |
+
processing: number;
|
| 387 |
+
|
| 388 |
+
/**
|
| 389 |
+
* Number of requests in the Message Batch that have completed successfully.
|
| 390 |
+
*
|
| 391 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 392 |
+
*/
|
| 393 |
+
succeeded: number;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
/**
|
| 397 |
+
* Processing result for this request.
|
| 398 |
+
*
|
| 399 |
+
* Contains a Message output if processing was successful, an error response if
|
| 400 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 401 |
+
* cancellation or expiration.
|
| 402 |
+
*/
|
| 403 |
+
export type BetaMessageBatchResult =
|
| 404 |
+
| BetaMessageBatchSucceededResult
|
| 405 |
+
| BetaMessageBatchErroredResult
|
| 406 |
+
| BetaMessageBatchCanceledResult
|
| 407 |
+
| BetaMessageBatchExpiredResult;
|
| 408 |
+
|
| 409 |
+
export interface BetaMessageBatchSucceededResult {
|
| 410 |
+
message: BetaMessagesAPI.BetaMessage;
|
| 411 |
+
|
| 412 |
+
type: 'succeeded';
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
export interface BatchCreateParams {
|
| 416 |
+
/**
|
| 417 |
+
* Body param: List of requests for prompt completion. Each is an individual
|
| 418 |
+
* request to create a Message.
|
| 419 |
+
*/
|
| 420 |
+
requests: Array<BatchCreateParams.Request>;
|
| 421 |
+
|
| 422 |
+
/**
|
| 423 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 424 |
+
*/
|
| 425 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
export namespace BatchCreateParams {
|
| 429 |
+
export interface Request {
|
| 430 |
+
/**
|
| 431 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 432 |
+
* matching results to requests, as results may be given out of request order.
|
| 433 |
+
*
|
| 434 |
+
* Must be unique for each request within the Message Batch.
|
| 435 |
+
*/
|
| 436 |
+
custom_id: string;
|
| 437 |
+
|
| 438 |
+
/**
|
| 439 |
+
* Messages API creation parameters for the individual request.
|
| 440 |
+
*
|
| 441 |
+
* See the [Messages API reference](/en/api/messages) for full documentation on
|
| 442 |
+
* available parameters.
|
| 443 |
+
*/
|
| 444 |
+
params: Omit<BetaMessagesAPI.MessageCreateParamsNonStreaming, 'betas'>;
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
export interface BatchRetrieveParams {
|
| 449 |
+
/**
|
| 450 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 451 |
+
*/
|
| 452 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
export interface BatchListParams extends PageParams {
|
| 456 |
+
/**
|
| 457 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 458 |
+
*/
|
| 459 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
export interface BatchDeleteParams {
|
| 463 |
+
/**
|
| 464 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 465 |
+
*/
|
| 466 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
export interface BatchCancelParams {
|
| 470 |
+
/**
|
| 471 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 472 |
+
*/
|
| 473 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
export interface BatchResultsParams {
|
| 477 |
+
/**
|
| 478 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 479 |
+
*/
|
| 480 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
export declare namespace Batches {
|
| 484 |
+
export {
|
| 485 |
+
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
|
| 486 |
+
type BetaMessageBatch as BetaMessageBatch,
|
| 487 |
+
type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
|
| 488 |
+
type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
|
| 489 |
+
type BetaMessageBatchExpiredResult as BetaMessageBatchExpiredResult,
|
| 490 |
+
type BetaMessageBatchIndividualResponse as BetaMessageBatchIndividualResponse,
|
| 491 |
+
type BetaMessageBatchRequestCounts as BetaMessageBatchRequestCounts,
|
| 492 |
+
type BetaMessageBatchResult as BetaMessageBatchResult,
|
| 493 |
+
type BetaMessageBatchSucceededResult as BetaMessageBatchSucceededResult,
|
| 494 |
+
type BetaMessageBatchesPage as BetaMessageBatchesPage,
|
| 495 |
+
type BatchCreateParams as BatchCreateParams,
|
| 496 |
+
type BatchRetrieveParams as BatchRetrieveParams,
|
| 497 |
+
type BatchListParams as BatchListParams,
|
| 498 |
+
type BatchDeleteParams as BatchDeleteParams,
|
| 499 |
+
type BatchCancelParams as BatchCancelParams,
|
| 500 |
+
type BatchResultsParams as BatchResultsParams,
|
| 501 |
+
};
|
| 502 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/messages.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './messages/index';
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/messages/batches.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../core/resource';
|
| 4 |
+
import * as Shared from '../shared';
|
| 5 |
+
import * as MessagesAPI from './messages';
|
| 6 |
+
import { APIPromise } from '../../core/api-promise';
|
| 7 |
+
import { Page, type PageParams, PagePromise } from '../../core/pagination';
|
| 8 |
+
import { buildHeaders } from '../../internal/headers';
|
| 9 |
+
import { RequestOptions } from '../../internal/request-options';
|
| 10 |
+
import { JSONLDecoder } from '../../internal/decoders/jsonl';
|
| 11 |
+
import { AnthropicError } from '../../error';
|
| 12 |
+
import { path } from '../../internal/utils/path';
|
| 13 |
+
|
| 14 |
+
export class Batches extends APIResource {
|
| 15 |
+
/**
|
| 16 |
+
* Send a batch of Message creation requests.
|
| 17 |
+
*
|
| 18 |
+
* The Message Batches API can be used to process multiple Messages API requests at
|
| 19 |
+
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
| 20 |
+
* can take up to 24 hours to complete.
|
| 21 |
+
*
|
| 22 |
+
* Learn more about the Message Batches API in our
|
| 23 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* ```ts
|
| 27 |
+
* const messageBatch = await client.messages.batches.create({
|
| 28 |
+
* requests: [
|
| 29 |
+
* {
|
| 30 |
+
* custom_id: 'my-custom-id-1',
|
| 31 |
+
* params: {
|
| 32 |
+
* max_tokens: 1024,
|
| 33 |
+
* messages: [
|
| 34 |
+
* { content: 'Hello, world', role: 'user' },
|
| 35 |
+
* ],
|
| 36 |
+
* model: 'claude-3-7-sonnet-20250219',
|
| 37 |
+
* },
|
| 38 |
+
* },
|
| 39 |
+
* ],
|
| 40 |
+
* });
|
| 41 |
+
* ```
|
| 42 |
+
*/
|
| 43 |
+
create(body: BatchCreateParams, options?: RequestOptions): APIPromise<MessageBatch> {
|
| 44 |
+
return this._client.post('/v1/messages/batches', { body, ...options });
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* This endpoint is idempotent and can be used to poll for Message Batch
|
| 49 |
+
* completion. To access the results of a Message Batch, make a request to the
|
| 50 |
+
* `results_url` field in the response.
|
| 51 |
+
*
|
| 52 |
+
* Learn more about the Message Batches API in our
|
| 53 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 54 |
+
*
|
| 55 |
+
* @example
|
| 56 |
+
* ```ts
|
| 57 |
+
* const messageBatch = await client.messages.batches.retrieve(
|
| 58 |
+
* 'message_batch_id',
|
| 59 |
+
* );
|
| 60 |
+
* ```
|
| 61 |
+
*/
|
| 62 |
+
retrieve(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch> {
|
| 63 |
+
return this._client.get(path`/v1/messages/batches/${messageBatchID}`, options);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* List all Message Batches within a Workspace. Most recently created batches are
|
| 68 |
+
* returned first.
|
| 69 |
+
*
|
| 70 |
+
* Learn more about the Message Batches API in our
|
| 71 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 72 |
+
*
|
| 73 |
+
* @example
|
| 74 |
+
* ```ts
|
| 75 |
+
* // Automatically fetches more pages as needed.
|
| 76 |
+
* for await (const messageBatch of client.messages.batches.list()) {
|
| 77 |
+
* // ...
|
| 78 |
+
* }
|
| 79 |
+
* ```
|
| 80 |
+
*/
|
| 81 |
+
list(
|
| 82 |
+
query: BatchListParams | null | undefined = {},
|
| 83 |
+
options?: RequestOptions,
|
| 84 |
+
): PagePromise<MessageBatchesPage, MessageBatch> {
|
| 85 |
+
return this._client.getAPIList('/v1/messages/batches', Page<MessageBatch>, { query, ...options });
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Delete a Message Batch.
|
| 90 |
+
*
|
| 91 |
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
| 92 |
+
* like to delete an in-progress batch, you must first cancel it.
|
| 93 |
+
*
|
| 94 |
+
* Learn more about the Message Batches API in our
|
| 95 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 96 |
+
*
|
| 97 |
+
* @example
|
| 98 |
+
* ```ts
|
| 99 |
+
* const deletedMessageBatch =
|
| 100 |
+
* await client.messages.batches.delete('message_batch_id');
|
| 101 |
+
* ```
|
| 102 |
+
*/
|
| 103 |
+
delete(messageBatchID: string, options?: RequestOptions): APIPromise<DeletedMessageBatch> {
|
| 104 |
+
return this._client.delete(path`/v1/messages/batches/${messageBatchID}`, options);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Batches may be canceled any time before processing ends. Once cancellation is
|
| 109 |
+
* initiated, the batch enters a `canceling` state, at which time the system may
|
| 110 |
+
* complete any in-progress, non-interruptible requests before finalizing
|
| 111 |
+
* cancellation.
|
| 112 |
+
*
|
| 113 |
+
* The number of canceled requests is specified in `request_counts`. To determine
|
| 114 |
+
* which requests were canceled, check the individual results within the batch.
|
| 115 |
+
* Note that cancellation may not result in any canceled requests if they were
|
| 116 |
+
* non-interruptible.
|
| 117 |
+
*
|
| 118 |
+
* Learn more about the Message Batches API in our
|
| 119 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 120 |
+
*
|
| 121 |
+
* @example
|
| 122 |
+
* ```ts
|
| 123 |
+
* const messageBatch = await client.messages.batches.cancel(
|
| 124 |
+
* 'message_batch_id',
|
| 125 |
+
* );
|
| 126 |
+
* ```
|
| 127 |
+
*/
|
| 128 |
+
cancel(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch> {
|
| 129 |
+
return this._client.post(path`/v1/messages/batches/${messageBatchID}/cancel`, options);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* Streams the results of a Message Batch as a `.jsonl` file.
|
| 134 |
+
*
|
| 135 |
+
* Each line in the file is a JSON object containing the result of a single request
|
| 136 |
+
* in the Message Batch. Results are not guaranteed to be in the same order as
|
| 137 |
+
* requests. Use the `custom_id` field to match results to requests.
|
| 138 |
+
*
|
| 139 |
+
* Learn more about the Message Batches API in our
|
| 140 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 141 |
+
*
|
| 142 |
+
* @example
|
| 143 |
+
* ```ts
|
| 144 |
+
* const messageBatchIndividualResponse =
|
| 145 |
+
* await client.messages.batches.results('message_batch_id');
|
| 146 |
+
* ```
|
| 147 |
+
*/
|
| 148 |
+
async results(
|
| 149 |
+
messageBatchID: string,
|
| 150 |
+
options?: RequestOptions,
|
| 151 |
+
): Promise<JSONLDecoder<MessageBatchIndividualResponse>> {
|
| 152 |
+
const batch = await this.retrieve(messageBatchID);
|
| 153 |
+
if (!batch.results_url) {
|
| 154 |
+
throw new AnthropicError(
|
| 155 |
+
`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`,
|
| 156 |
+
);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return this._client
|
| 160 |
+
.get(batch.results_url, {
|
| 161 |
+
...options,
|
| 162 |
+
headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
|
| 163 |
+
stream: true,
|
| 164 |
+
__binaryResponse: true,
|
| 165 |
+
})
|
| 166 |
+
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller)) as APIPromise<
|
| 167 |
+
JSONLDecoder<MessageBatchIndividualResponse>
|
| 168 |
+
>;
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
export type MessageBatchesPage = Page<MessageBatch>;
|
| 173 |
+
|
| 174 |
+
export interface DeletedMessageBatch {
|
| 175 |
+
/**
|
| 176 |
+
* ID of the Message Batch.
|
| 177 |
+
*/
|
| 178 |
+
id: string;
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Deleted object type.
|
| 182 |
+
*
|
| 183 |
+
* For Message Batches, this is always `"message_batch_deleted"`.
|
| 184 |
+
*/
|
| 185 |
+
type: 'message_batch_deleted';
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
export interface MessageBatch {
|
| 189 |
+
/**
|
| 190 |
+
* Unique object identifier.
|
| 191 |
+
*
|
| 192 |
+
* The format and length of IDs may change over time.
|
| 193 |
+
*/
|
| 194 |
+
id: string;
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 198 |
+
* archived and its results became unavailable.
|
| 199 |
+
*/
|
| 200 |
+
archived_at: string | null;
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* RFC 3339 datetime string representing the time at which cancellation was
|
| 204 |
+
* initiated for the Message Batch. Specified only if cancellation was initiated.
|
| 205 |
+
*/
|
| 206 |
+
cancel_initiated_at: string | null;
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 210 |
+
* created.
|
| 211 |
+
*/
|
| 212 |
+
created_at: string;
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* RFC 3339 datetime string representing the time at which processing for the
|
| 216 |
+
* Message Batch ended. Specified only once processing ends.
|
| 217 |
+
*
|
| 218 |
+
* Processing ends when every request in a Message Batch has either succeeded,
|
| 219 |
+
* errored, canceled, or expired.
|
| 220 |
+
*/
|
| 221 |
+
ended_at: string | null;
|
| 222 |
+
|
| 223 |
+
/**
|
| 224 |
+
* RFC 3339 datetime string representing the time at which the Message Batch will
|
| 225 |
+
* expire and end processing, which is 24 hours after creation.
|
| 226 |
+
*/
|
| 227 |
+
expires_at: string;
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* Processing status of the Message Batch.
|
| 231 |
+
*/
|
| 232 |
+
processing_status: 'in_progress' | 'canceling' | 'ended';
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Tallies requests within the Message Batch, categorized by their status.
|
| 236 |
+
*
|
| 237 |
+
* Requests start as `processing` and move to one of the other statuses only once
|
| 238 |
+
* processing of the entire batch ends. The sum of all values always matches the
|
| 239 |
+
* total number of requests in the batch.
|
| 240 |
+
*/
|
| 241 |
+
request_counts: MessageBatchRequestCounts;
|
| 242 |
+
|
| 243 |
+
/**
|
| 244 |
+
* URL to a `.jsonl` file containing the results of the Message Batch requests.
|
| 245 |
+
* Specified only once processing ends.
|
| 246 |
+
*
|
| 247 |
+
* Results in the file are not guaranteed to be in the same order as requests. Use
|
| 248 |
+
* the `custom_id` field to match results to requests.
|
| 249 |
+
*/
|
| 250 |
+
results_url: string | null;
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Object type.
|
| 254 |
+
*
|
| 255 |
+
* For Message Batches, this is always `"message_batch"`.
|
| 256 |
+
*/
|
| 257 |
+
type: 'message_batch';
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
export interface MessageBatchCanceledResult {
|
| 261 |
+
type: 'canceled';
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
export interface MessageBatchErroredResult {
|
| 265 |
+
error: Shared.ErrorResponse;
|
| 266 |
+
|
| 267 |
+
type: 'errored';
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
export interface MessageBatchExpiredResult {
|
| 271 |
+
type: 'expired';
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* This is a single line in the response `.jsonl` file and does not represent the
|
| 276 |
+
* response as a whole.
|
| 277 |
+
*/
|
| 278 |
+
export interface MessageBatchIndividualResponse {
|
| 279 |
+
/**
|
| 280 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 281 |
+
* matching results to requests, as results may be given out of request order.
|
| 282 |
+
*
|
| 283 |
+
* Must be unique for each request within the Message Batch.
|
| 284 |
+
*/
|
| 285 |
+
custom_id: string;
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* Processing result for this request.
|
| 289 |
+
*
|
| 290 |
+
* Contains a Message output if processing was successful, an error response if
|
| 291 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 292 |
+
* cancellation or expiration.
|
| 293 |
+
*/
|
| 294 |
+
result: MessageBatchResult;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
export interface MessageBatchRequestCounts {
|
| 298 |
+
/**
|
| 299 |
+
* Number of requests in the Message Batch that have been canceled.
|
| 300 |
+
*
|
| 301 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 302 |
+
*/
|
| 303 |
+
canceled: number;
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* Number of requests in the Message Batch that encountered an error.
|
| 307 |
+
*
|
| 308 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 309 |
+
*/
|
| 310 |
+
errored: number;
|
| 311 |
+
|
| 312 |
+
/**
|
| 313 |
+
* Number of requests in the Message Batch that have expired.
|
| 314 |
+
*
|
| 315 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 316 |
+
*/
|
| 317 |
+
expired: number;
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* Number of requests in the Message Batch that are processing.
|
| 321 |
+
*/
|
| 322 |
+
processing: number;
|
| 323 |
+
|
| 324 |
+
/**
|
| 325 |
+
* Number of requests in the Message Batch that have completed successfully.
|
| 326 |
+
*
|
| 327 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 328 |
+
*/
|
| 329 |
+
succeeded: number;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
/**
|
| 333 |
+
* Processing result for this request.
|
| 334 |
+
*
|
| 335 |
+
* Contains a Message output if processing was successful, an error response if
|
| 336 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 337 |
+
* cancellation or expiration.
|
| 338 |
+
*/
|
| 339 |
+
export type MessageBatchResult =
|
| 340 |
+
| MessageBatchSucceededResult
|
| 341 |
+
| MessageBatchErroredResult
|
| 342 |
+
| MessageBatchCanceledResult
|
| 343 |
+
| MessageBatchExpiredResult;
|
| 344 |
+
|
| 345 |
+
export interface MessageBatchSucceededResult {
|
| 346 |
+
message: MessagesAPI.Message;
|
| 347 |
+
|
| 348 |
+
type: 'succeeded';
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
export interface BatchCreateParams {
|
| 352 |
+
/**
|
| 353 |
+
* List of requests for prompt completion. Each is an individual request to create
|
| 354 |
+
* a Message.
|
| 355 |
+
*/
|
| 356 |
+
requests: Array<BatchCreateParams.Request>;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
export namespace BatchCreateParams {
|
| 360 |
+
export interface Request {
|
| 361 |
+
/**
|
| 362 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 363 |
+
* matching results to requests, as results may be given out of request order.
|
| 364 |
+
*
|
| 365 |
+
* Must be unique for each request within the Message Batch.
|
| 366 |
+
*/
|
| 367 |
+
custom_id: string;
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* Messages API creation parameters for the individual request.
|
| 371 |
+
*
|
| 372 |
+
* See the [Messages API reference](/en/api/messages) for full documentation on
|
| 373 |
+
* available parameters.
|
| 374 |
+
*/
|
| 375 |
+
params: MessagesAPI.MessageCreateParamsNonStreaming;
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
export interface BatchListParams extends PageParams {}
|
| 380 |
+
|
| 381 |
+
export declare namespace Batches {
|
| 382 |
+
export {
|
| 383 |
+
type DeletedMessageBatch as DeletedMessageBatch,
|
| 384 |
+
type MessageBatch as MessageBatch,
|
| 385 |
+
type MessageBatchCanceledResult as MessageBatchCanceledResult,
|
| 386 |
+
type MessageBatchErroredResult as MessageBatchErroredResult,
|
| 387 |
+
type MessageBatchExpiredResult as MessageBatchExpiredResult,
|
| 388 |
+
type MessageBatchIndividualResponse as MessageBatchIndividualResponse,
|
| 389 |
+
type MessageBatchRequestCounts as MessageBatchRequestCounts,
|
| 390 |
+
type MessageBatchResult as MessageBatchResult,
|
| 391 |
+
type MessageBatchSucceededResult as MessageBatchSucceededResult,
|
| 392 |
+
type MessageBatchesPage as MessageBatchesPage,
|
| 393 |
+
type BatchCreateParams as BatchCreateParams,
|
| 394 |
+
type BatchListParams as BatchListParams,
|
| 395 |
+
};
|
| 396 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@anthropic-ai/sdk/src/resources/models.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../core/resource';
|
| 4 |
+
import * as BetaAPI from './beta/beta';
|
| 5 |
+
import { APIPromise } from '../core/api-promise';
|
| 6 |
+
import { Page, type PageParams, PagePromise } from '../core/pagination';
|
| 7 |
+
import { buildHeaders } from '../internal/headers';
|
| 8 |
+
import { RequestOptions } from '../internal/request-options';
|
| 9 |
+
import { path } from '../internal/utils/path';
|
| 10 |
+
|
| 11 |
+
export class Models extends APIResource {
|
| 12 |
+
/**
|
| 13 |
+
* Get a specific model.
|
| 14 |
+
*
|
| 15 |
+
* The Models API response can be used to determine information about a specific
|
| 16 |
+
* model or resolve a model alias to a model ID.
|
| 17 |
+
*/
|
| 18 |
+
retrieve(
|
| 19 |
+
modelID: string,
|
| 20 |
+
params: ModelRetrieveParams | null | undefined = {},
|
| 21 |
+
options?: RequestOptions,
|
| 22 |
+
): APIPromise<ModelInfo> {
|
| 23 |
+
const { betas } = params ?? {};
|
| 24 |
+
return this._client.get(path`/v1/models/${modelID}`, {
|
| 25 |
+
...options,
|
| 26 |
+
headers: buildHeaders([
|
| 27 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 28 |
+
options?.headers,
|
| 29 |
+
]),
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* List available models.
|
| 35 |
+
*
|
| 36 |
+
* The Models API response can be used to determine which models are available for
|
| 37 |
+
* use in the API. More recently released models are listed first.
|
| 38 |
+
*/
|
| 39 |
+
list(
|
| 40 |
+
params: ModelListParams | null | undefined = {},
|
| 41 |
+
options?: RequestOptions,
|
| 42 |
+
): PagePromise<ModelInfosPage, ModelInfo> {
|
| 43 |
+
const { betas, ...query } = params ?? {};
|
| 44 |
+
return this._client.getAPIList('/v1/models', Page<ModelInfo>, {
|
| 45 |
+
query,
|
| 46 |
+
...options,
|
| 47 |
+
headers: buildHeaders([
|
| 48 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 49 |
+
options?.headers,
|
| 50 |
+
]),
|
| 51 |
+
});
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export type ModelInfosPage = Page<ModelInfo>;
|
| 56 |
+
|
| 57 |
+
export interface ModelInfo {
|
| 58 |
+
/**
|
| 59 |
+
* Unique model identifier.
|
| 60 |
+
*/
|
| 61 |
+
id: string;
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* RFC 3339 datetime string representing the time at which the model was released.
|
| 65 |
+
* May be set to an epoch value if the release date is unknown.
|
| 66 |
+
*/
|
| 67 |
+
created_at: string;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* A human-readable name for the model.
|
| 71 |
+
*/
|
| 72 |
+
display_name: string;
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Object type.
|
| 76 |
+
*
|
| 77 |
+
* For Models, this is always `"model"`.
|
| 78 |
+
*/
|
| 79 |
+
type: 'model';
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
export interface ModelRetrieveParams {
|
| 83 |
+
/**
|
| 84 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 85 |
+
*/
|
| 86 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
export interface ModelListParams extends PageParams {
|
| 90 |
+
/**
|
| 91 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 92 |
+
*/
|
| 93 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
export declare namespace Models {
|
| 97 |
+
export {
|
| 98 |
+
type ModelInfo as ModelInfo,
|
| 99 |
+
type ModelInfosPage as ModelInfosPage,
|
| 100 |
+
type ModelRetrieveParams as ModelRetrieveParams,
|
| 101 |
+
type ModelListParams as ModelListParams,
|
| 102 |
+
};
|
| 103 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.github/dependabot.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 2
|
| 2 |
+
updates:
|
| 3 |
+
- package-ecosystem: "github-actions"
|
| 4 |
+
directory: "/"
|
| 5 |
+
schedule:
|
| 6 |
+
interval: "monthly"
|
| 7 |
+
open-pull-requests-limit: 10
|
| 8 |
+
|
| 9 |
+
- package-ecosystem: "npm"
|
| 10 |
+
directory: "/"
|
| 11 |
+
schedule:
|
| 12 |
+
interval: "weekly"
|
| 13 |
+
open-pull-requests-limit: 10
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.github/tests_checker.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
comment: |
|
| 2 |
+
Hello! Thank you for contributing!
|
| 3 |
+
It appears that you have changed the code, but the tests that verify your change are missing. Could you please add them?
|
| 4 |
+
fileExtensions:
|
| 5 |
+
- '.ts'
|
| 6 |
+
- '.js'
|
| 7 |
+
|
| 8 |
+
testDir: 'test'
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.github/workflows/ci.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: CI
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
- master
|
| 8 |
+
- next
|
| 9 |
+
- 'v*'
|
| 10 |
+
paths-ignore:
|
| 11 |
+
- 'docs/**'
|
| 12 |
+
- '*.md'
|
| 13 |
+
pull_request:
|
| 14 |
+
paths-ignore:
|
| 15 |
+
- 'docs/**'
|
| 16 |
+
- '*.md'
|
| 17 |
+
|
| 18 |
+
env:
|
| 19 |
+
TZ: 'UTC'
|
| 20 |
+
|
| 21 |
+
jobs:
|
| 22 |
+
test:
|
| 23 |
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
|
| 24 |
+
with:
|
| 25 |
+
lint: true
|
| 26 |
+
license-check: true
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/.taprc
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
files:
|
| 2 |
+
- test/**/*.test.js
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/lib/default-ajv-options.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const fastUri = require('fast-uri')
|
| 4 |
+
|
| 5 |
+
module.exports = Object.freeze({
|
| 6 |
+
coerceTypes: 'array',
|
| 7 |
+
useDefaults: true,
|
| 8 |
+
removeAdditional: true,
|
| 9 |
+
uriResolver: fastUri,
|
| 10 |
+
addUsedSchema: false,
|
| 11 |
+
// Explicitly set allErrors to `false`.
|
| 12 |
+
// When set to `true`, a DoS attack is possible.
|
| 13 |
+
allErrors: false
|
| 14 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/lib/validator-compiler.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const Ajv = require('ajv').default
|
| 4 |
+
const AjvJTD = require('ajv/dist/jtd')
|
| 5 |
+
|
| 6 |
+
const defaultAjvOptions = require('./default-ajv-options')
|
| 7 |
+
|
| 8 |
+
class ValidatorCompiler {
|
| 9 |
+
constructor (externalSchemas, options) {
|
| 10 |
+
// This instance of Ajv is private
|
| 11 |
+
// it should not be customized or used
|
| 12 |
+
if (options.mode === 'JTD') {
|
| 13 |
+
this.ajv = new AjvJTD(Object.assign({}, defaultAjvOptions, options.customOptions))
|
| 14 |
+
} else {
|
| 15 |
+
this.ajv = new Ajv(Object.assign({}, defaultAjvOptions, options.customOptions))
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
let addFormatPlugin = true
|
| 19 |
+
if (options.plugins && options.plugins.length > 0) {
|
| 20 |
+
for (const plugin of options.plugins) {
|
| 21 |
+
if (Array.isArray(plugin)) {
|
| 22 |
+
addFormatPlugin = addFormatPlugin && plugin[0].name !== 'formatsPlugin'
|
| 23 |
+
plugin[0](this.ajv, plugin[1])
|
| 24 |
+
} else {
|
| 25 |
+
addFormatPlugin = addFormatPlugin && plugin.name !== 'formatsPlugin'
|
| 26 |
+
plugin(this.ajv)
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
if (addFormatPlugin) {
|
| 32 |
+
require('ajv-formats')(this.ajv)
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
options.onCreate?.(this.ajv)
|
| 36 |
+
|
| 37 |
+
const sourceSchemas = Object.values(externalSchemas)
|
| 38 |
+
for (const extSchema of sourceSchemas) {
|
| 39 |
+
this.ajv.addSchema(extSchema)
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
buildValidatorFunction ({ schema/*, method, url, httpPart */ }) {
|
| 44 |
+
// Ajv does not support compiling two schemas with the same
|
| 45 |
+
// id inside the same instance. Therefore if we have already
|
| 46 |
+
// compiled the schema with the given id, we just return it.
|
| 47 |
+
if (schema.$id) {
|
| 48 |
+
const stored = this.ajv.getSchema(schema.$id)
|
| 49 |
+
if (stored) {
|
| 50 |
+
return stored
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
return this.ajv.compile(schema)
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
module.exports = ValidatorCompiler
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/test/index.test.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const t = require('tap')
|
| 4 |
+
const fastify = require('fastify')
|
| 5 |
+
const AjvCompiler = require('../index')
|
| 6 |
+
|
| 7 |
+
const sym = Symbol.for('fastify.ajv-compiler.reference')
|
| 8 |
+
|
| 9 |
+
const sampleSchema = Object.freeze({
|
| 10 |
+
$id: 'example1',
|
| 11 |
+
type: 'object',
|
| 12 |
+
properties: {
|
| 13 |
+
name: { type: 'string' }
|
| 14 |
+
}
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
const externalSchemas1 = Object.freeze({})
|
| 18 |
+
const externalSchemas2 = Object.freeze({
|
| 19 |
+
foo: {
|
| 20 |
+
$id: 'foo',
|
| 21 |
+
type: 'object',
|
| 22 |
+
properties: {
|
| 23 |
+
name: { type: 'string' }
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
const fastifyAjvOptionsDefault = Object.freeze({
|
| 29 |
+
customOptions: {}
|
| 30 |
+
})
|
| 31 |
+
|
| 32 |
+
const fastifyJtdDefault = Object.freeze({
|
| 33 |
+
customOptions: { },
|
| 34 |
+
mode: 'JTD'
|
| 35 |
+
})
|
| 36 |
+
|
| 37 |
+
const fastifyAjvOptionsCustom = Object.freeze({
|
| 38 |
+
customOptions: {
|
| 39 |
+
allErrors: true,
|
| 40 |
+
removeAdditional: false
|
| 41 |
+
},
|
| 42 |
+
plugins: [
|
| 43 |
+
require('ajv-formats'),
|
| 44 |
+
[require('ajv-errors'), { singleError: false }]
|
| 45 |
+
]
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
t.test('basic usage', t => {
|
| 49 |
+
t.plan(1)
|
| 50 |
+
const factory = AjvCompiler()
|
| 51 |
+
const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault)
|
| 52 |
+
const validatorFunc = compiler({ schema: sampleSchema })
|
| 53 |
+
const result = validatorFunc({ name: 'hello' })
|
| 54 |
+
t.equal(result, true)
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
t.test('array coercion', t => {
|
| 58 |
+
t.plan(2)
|
| 59 |
+
const factory = AjvCompiler()
|
| 60 |
+
const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault)
|
| 61 |
+
|
| 62 |
+
const arraySchema = {
|
| 63 |
+
$id: 'example1',
|
| 64 |
+
type: 'object',
|
| 65 |
+
properties: {
|
| 66 |
+
name: { type: 'array', items: { type: 'string' } }
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const validatorFunc = compiler({ schema: arraySchema })
|
| 71 |
+
|
| 72 |
+
const inputObj = { name: 'hello' }
|
| 73 |
+
t.equal(validatorFunc(inputObj), true)
|
| 74 |
+
t.same(inputObj, { name: ['hello'] }, 'the name property should be coerced to an array')
|
| 75 |
+
})
|
| 76 |
+
|
| 77 |
+
t.test('nullable default', t => {
|
| 78 |
+
t.plan(2)
|
| 79 |
+
const factory = AjvCompiler()
|
| 80 |
+
const compiler = factory({}, fastifyAjvOptionsDefault)
|
| 81 |
+
const validatorFunc = compiler({
|
| 82 |
+
schema: {
|
| 83 |
+
type: 'object',
|
| 84 |
+
properties: {
|
| 85 |
+
nullable: { type: 'string', nullable: true },
|
| 86 |
+
notNullable: { type: 'string' }
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
})
|
| 90 |
+
const input = { nullable: null, notNullable: null }
|
| 91 |
+
const result = validatorFunc(input)
|
| 92 |
+
t.equal(result, true)
|
| 93 |
+
t.same(input, { nullable: null, notNullable: '' }, 'the notNullable field has been coerced')
|
| 94 |
+
})
|
| 95 |
+
|
| 96 |
+
t.test('plugin loading', t => {
|
| 97 |
+
t.plan(3)
|
| 98 |
+
const factory = AjvCompiler()
|
| 99 |
+
const compiler = factory(externalSchemas1, fastifyAjvOptionsCustom)
|
| 100 |
+
const validatorFunc = compiler({
|
| 101 |
+
schema: {
|
| 102 |
+
type: 'object',
|
| 103 |
+
properties: {
|
| 104 |
+
q: {
|
| 105 |
+
type: 'string',
|
| 106 |
+
format: 'date',
|
| 107 |
+
formatMinimum: '2016-02-06',
|
| 108 |
+
formatExclusiveMaximum: '2016-12-27'
|
| 109 |
+
}
|
| 110 |
+
},
|
| 111 |
+
required: ['q'],
|
| 112 |
+
errorMessage: 'hello world'
|
| 113 |
+
}
|
| 114 |
+
})
|
| 115 |
+
const result = validatorFunc({ q: '2016-10-02' })
|
| 116 |
+
t.equal(result, true)
|
| 117 |
+
|
| 118 |
+
const resultFail = validatorFunc({})
|
| 119 |
+
t.equal(resultFail, false)
|
| 120 |
+
t.equal(validatorFunc.errors[0].message, 'hello world')
|
| 121 |
+
})
|
| 122 |
+
|
| 123 |
+
t.test('optimization - cache ajv instance', t => {
|
| 124 |
+
t.plan(5)
|
| 125 |
+
const factory = AjvCompiler()
|
| 126 |
+
const compiler1 = factory(externalSchemas1, fastifyAjvOptionsDefault)
|
| 127 |
+
const compiler2 = factory(externalSchemas1, fastifyAjvOptionsDefault)
|
| 128 |
+
t.equal(compiler1, compiler2, 'same instance')
|
| 129 |
+
t.same(compiler1, compiler2, 'same instance')
|
| 130 |
+
|
| 131 |
+
const compiler3 = factory(externalSchemas2, fastifyAjvOptionsDefault)
|
| 132 |
+
t.not(compiler3, compiler1, 'new ajv instance when externa schema change')
|
| 133 |
+
|
| 134 |
+
const compiler4 = factory(externalSchemas1, fastifyAjvOptionsCustom)
|
| 135 |
+
t.not(compiler4, compiler1, 'new ajv instance when externa schema change')
|
| 136 |
+
t.not(compiler4, compiler3, 'new ajv instance when externa schema change')
|
| 137 |
+
})
|
| 138 |
+
|
| 139 |
+
t.test('the onCreate callback can enhance the ajv instance', t => {
|
| 140 |
+
t.plan(2)
|
| 141 |
+
const factory = AjvCompiler()
|
| 142 |
+
|
| 143 |
+
const fastifyAjvCustomOptionsFormats = Object.freeze({
|
| 144 |
+
onCreate (ajv) {
|
| 145 |
+
for (const [formatName, format] of Object.entries(this.customOptions.formats)) {
|
| 146 |
+
ajv.addFormat(formatName, format)
|
| 147 |
+
}
|
| 148 |
+
},
|
| 149 |
+
customOptions: {
|
| 150 |
+
formats: {
|
| 151 |
+
date: /foo/
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
})
|
| 155 |
+
|
| 156 |
+
const compiler1 = factory(externalSchemas1, fastifyAjvCustomOptionsFormats)
|
| 157 |
+
const validatorFunc = compiler1({
|
| 158 |
+
schema: {
|
| 159 |
+
type: 'string',
|
| 160 |
+
format: 'date'
|
| 161 |
+
}
|
| 162 |
+
})
|
| 163 |
+
const result = validatorFunc('foo')
|
| 164 |
+
t.equal(result, true)
|
| 165 |
+
|
| 166 |
+
const resultFail = validatorFunc('2016-10-02')
|
| 167 |
+
t.equal(resultFail, false)
|
| 168 |
+
})
|
| 169 |
+
|
| 170 |
+
// https://github.com/fastify/fastify/pull/2969
|
| 171 |
+
t.test('compile same $id when in external schema', t => {
|
| 172 |
+
t.plan(3)
|
| 173 |
+
const factory = AjvCompiler()
|
| 174 |
+
|
| 175 |
+
const base = {
|
| 176 |
+
$id: 'urn:schema:base',
|
| 177 |
+
definitions: {
|
| 178 |
+
hello: { type: 'string' }
|
| 179 |
+
},
|
| 180 |
+
type: 'object',
|
| 181 |
+
properties: {
|
| 182 |
+
hello: { $ref: '#/definitions/hello' }
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
const refSchema = {
|
| 187 |
+
$id: 'urn:schema:ref',
|
| 188 |
+
type: 'object',
|
| 189 |
+
properties: {
|
| 190 |
+
hello: { $ref: 'urn:schema:base#/definitions/hello' }
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
const compiler = factory({
|
| 195 |
+
[base.$id]: base,
|
| 196 |
+
[refSchema.$id]: refSchema
|
| 197 |
+
|
| 198 |
+
}, fastifyAjvOptionsDefault)
|
| 199 |
+
|
| 200 |
+
t.notOk(compiler[sym], 'the ajv reference do not exists if code is not activated')
|
| 201 |
+
|
| 202 |
+
const validatorFunc1 = compiler({
|
| 203 |
+
schema: {
|
| 204 |
+
$id: 'urn:schema:ref'
|
| 205 |
+
}
|
| 206 |
+
})
|
| 207 |
+
|
| 208 |
+
const validatorFunc2 = compiler({
|
| 209 |
+
schema: {
|
| 210 |
+
$id: 'urn:schema:ref'
|
| 211 |
+
}
|
| 212 |
+
})
|
| 213 |
+
|
| 214 |
+
t.pass('the compile does not fail if the schema compiled is already in the external schemas')
|
| 215 |
+
t.equal(validatorFunc1, validatorFunc2, 'the returned function is the same')
|
| 216 |
+
})
|
| 217 |
+
|
| 218 |
+
t.test('JTD MODE', t => {
|
| 219 |
+
t.plan(2)
|
| 220 |
+
|
| 221 |
+
t.test('compile jtd schema', t => {
|
| 222 |
+
t.plan(4)
|
| 223 |
+
const factory = AjvCompiler()
|
| 224 |
+
|
| 225 |
+
const jtdSchema = {
|
| 226 |
+
discriminator: 'version',
|
| 227 |
+
mapping: {
|
| 228 |
+
1: {
|
| 229 |
+
properties: {
|
| 230 |
+
foo: { type: 'uint8' }
|
| 231 |
+
}
|
| 232 |
+
},
|
| 233 |
+
2: {
|
| 234 |
+
properties: {
|
| 235 |
+
foo: { type: 'string' }
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
const compiler = factory({}, fastifyJtdDefault)
|
| 242 |
+
const validatorFunc = compiler({ schema: jtdSchema })
|
| 243 |
+
t.pass('generated validation function for JTD SCHEMA')
|
| 244 |
+
|
| 245 |
+
const result = validatorFunc({
|
| 246 |
+
version: '2',
|
| 247 |
+
foo: []
|
| 248 |
+
})
|
| 249 |
+
t.notOk(result, 'failed validation')
|
| 250 |
+
t.type(validatorFunc.errors, 'Array')
|
| 251 |
+
|
| 252 |
+
const success = validatorFunc({
|
| 253 |
+
version: '1',
|
| 254 |
+
foo: 42
|
| 255 |
+
})
|
| 256 |
+
t.ok(success)
|
| 257 |
+
})
|
| 258 |
+
|
| 259 |
+
t.test('fastify integration', async t => {
|
| 260 |
+
const factory = AjvCompiler()
|
| 261 |
+
|
| 262 |
+
const app = fastify({
|
| 263 |
+
jsonShorthand: false,
|
| 264 |
+
ajv: {
|
| 265 |
+
customOptions: { },
|
| 266 |
+
mode: 'JTD'
|
| 267 |
+
},
|
| 268 |
+
schemaController: {
|
| 269 |
+
compilersFactory: {
|
| 270 |
+
buildValidator: factory
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
})
|
| 274 |
+
|
| 275 |
+
app.post('/', {
|
| 276 |
+
schema: {
|
| 277 |
+
body: {
|
| 278 |
+
discriminator: 'version',
|
| 279 |
+
mapping: {
|
| 280 |
+
1: {
|
| 281 |
+
properties: {
|
| 282 |
+
foo: { type: 'uint8' }
|
| 283 |
+
}
|
| 284 |
+
},
|
| 285 |
+
2: {
|
| 286 |
+
properties: {
|
| 287 |
+
foo: { type: 'string' }
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
}, () => {})
|
| 294 |
+
|
| 295 |
+
const res = await app.inject({
|
| 296 |
+
url: '/',
|
| 297 |
+
method: 'POST',
|
| 298 |
+
payload: {
|
| 299 |
+
version: '1',
|
| 300 |
+
foo: 'this is not a number'
|
| 301 |
+
}
|
| 302 |
+
})
|
| 303 |
+
|
| 304 |
+
t.equal(res.statusCode, 400)
|
| 305 |
+
t.equal(res.json().message, 'body/foo must be uint8')
|
| 306 |
+
})
|
| 307 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/test/plugins.test.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const t = require('tap')
|
| 4 |
+
const fastify = require('fastify')
|
| 5 |
+
const AjvCompiler = require('../index')
|
| 6 |
+
|
| 7 |
+
const ajvFormats = require('ajv-formats')
|
| 8 |
+
const ajvErrors = require('ajv-errors')
|
| 9 |
+
const localize = require('ajv-i18n')
|
| 10 |
+
|
| 11 |
+
t.test('Format Baseline test', async (t) => {
|
| 12 |
+
const app = buildApplication({
|
| 13 |
+
customOptions: {
|
| 14 |
+
validateFormats: false
|
| 15 |
+
}
|
| 16 |
+
})
|
| 17 |
+
|
| 18 |
+
const res = await app.inject({
|
| 19 |
+
url: '/hello',
|
| 20 |
+
headers: {
|
| 21 |
+
'x-foo': 'hello',
|
| 22 |
+
'x-date': 'not a date',
|
| 23 |
+
'x-email': 'not an email'
|
| 24 |
+
},
|
| 25 |
+
query: {
|
| 26 |
+
foo: 'hello',
|
| 27 |
+
date: 'not a date',
|
| 28 |
+
email: 'not an email'
|
| 29 |
+
}
|
| 30 |
+
})
|
| 31 |
+
t.equal(res.statusCode, 200, 'format validation does not apply as configured')
|
| 32 |
+
t.equal(res.payload, 'hello')
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
t.test('Custom Format plugin loading test', (t) => {
|
| 36 |
+
t.plan(6)
|
| 37 |
+
const app = buildApplication({
|
| 38 |
+
customOptions: {
|
| 39 |
+
validateFormats: true
|
| 40 |
+
},
|
| 41 |
+
plugins: [[ajvFormats, { mode: 'fast' }]]
|
| 42 |
+
})
|
| 43 |
+
|
| 44 |
+
app.inject('/hello', (err, res) => {
|
| 45 |
+
t.error(err)
|
| 46 |
+
t.equal(res.statusCode, 400, 'format validation applies')
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
app.inject('/2ad0612c-7578-4b18-9a6f-579863f40e0b', (err, res) => {
|
| 50 |
+
t.error(err)
|
| 51 |
+
t.equal(res.statusCode, 400, 'format validation applies')
|
| 52 |
+
})
|
| 53 |
+
|
| 54 |
+
app.inject({
|
| 55 |
+
url: '/2ad0612c-7578-4b18-9a6f-579863f40e0b',
|
| 56 |
+
headers: {
|
| 57 |
+
'x-foo': 'hello',
|
| 58 |
+
'x-date': new Date().toISOString(),
|
| 59 |
+
'x-email': 'foo@bar.baz'
|
| 60 |
+
},
|
| 61 |
+
query: {
|
| 62 |
+
foo: 'hello',
|
| 63 |
+
date: new Date().toISOString(),
|
| 64 |
+
email: 'foo@bar.baz'
|
| 65 |
+
}
|
| 66 |
+
}, (err, res) => {
|
| 67 |
+
t.error(err)
|
| 68 |
+
t.equal(res.statusCode, 200)
|
| 69 |
+
})
|
| 70 |
+
})
|
| 71 |
+
|
| 72 |
+
t.test('Format plugin set by default test', (t) => {
|
| 73 |
+
t.plan(6)
|
| 74 |
+
const app = buildApplication({})
|
| 75 |
+
|
| 76 |
+
app.inject('/hello', (err, res) => {
|
| 77 |
+
t.error(err)
|
| 78 |
+
t.equal(res.statusCode, 400, 'format validation applies')
|
| 79 |
+
})
|
| 80 |
+
|
| 81 |
+
app.inject('/2ad0612c-7578-4b18-9a6f-579863f40e0b', (err, res) => {
|
| 82 |
+
t.error(err)
|
| 83 |
+
t.equal(res.statusCode, 400, 'format validation applies')
|
| 84 |
+
})
|
| 85 |
+
|
| 86 |
+
app.inject({
|
| 87 |
+
url: '/2ad0612c-7578-4b18-9a6f-579863f40e0b',
|
| 88 |
+
headers: {
|
| 89 |
+
'x-foo': 'hello',
|
| 90 |
+
'x-date': new Date().toISOString(),
|
| 91 |
+
'x-email': 'foo@bar.baz'
|
| 92 |
+
},
|
| 93 |
+
query: {
|
| 94 |
+
foo: 'hello',
|
| 95 |
+
date: new Date().toISOString(),
|
| 96 |
+
email: 'foo@bar.baz'
|
| 97 |
+
}
|
| 98 |
+
}, (err, res) => {
|
| 99 |
+
t.error(err)
|
| 100 |
+
t.equal(res.statusCode, 200)
|
| 101 |
+
})
|
| 102 |
+
})
|
| 103 |
+
|
| 104 |
+
t.test('Custom error messages', (t) => {
|
| 105 |
+
t.plan(9)
|
| 106 |
+
|
| 107 |
+
const app = buildApplication({
|
| 108 |
+
customOptions: {
|
| 109 |
+
removeAdditional: false,
|
| 110 |
+
allErrors: true
|
| 111 |
+
},
|
| 112 |
+
plugins: [ajvFormats, ajvErrors]
|
| 113 |
+
})
|
| 114 |
+
|
| 115 |
+
const errorMessage = {
|
| 116 |
+
required: 'custom miss',
|
| 117 |
+
type: 'custom type', // will not replace internal "type" error for the property "foo"
|
| 118 |
+
_: 'custom type', // this prop will do it
|
| 119 |
+
additionalProperties: 'custom too many params'
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
app.post('/', {
|
| 123 |
+
handler: () => { t.fail('dont call me') },
|
| 124 |
+
schema: {
|
| 125 |
+
body: {
|
| 126 |
+
type: 'object',
|
| 127 |
+
required: ['foo'],
|
| 128 |
+
properties: {
|
| 129 |
+
foo: { type: 'integer' }
|
| 130 |
+
},
|
| 131 |
+
additionalProperties: false,
|
| 132 |
+
errorMessage
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
})
|
| 136 |
+
|
| 137 |
+
app.inject({
|
| 138 |
+
url: '/',
|
| 139 |
+
method: 'post',
|
| 140 |
+
payload: {}
|
| 141 |
+
}, (err, res) => {
|
| 142 |
+
t.error(err)
|
| 143 |
+
t.equal(res.statusCode, 400)
|
| 144 |
+
t.match(res.json().message, errorMessage.required)
|
| 145 |
+
})
|
| 146 |
+
|
| 147 |
+
app.inject({
|
| 148 |
+
url: '/',
|
| 149 |
+
method: 'post',
|
| 150 |
+
payload: { foo: 'not a number' }
|
| 151 |
+
}, (err, res) => {
|
| 152 |
+
t.error(err)
|
| 153 |
+
t.equal(res.statusCode, 400)
|
| 154 |
+
t.match(res.json().message, errorMessage.type)
|
| 155 |
+
})
|
| 156 |
+
|
| 157 |
+
app.inject({
|
| 158 |
+
url: '/',
|
| 159 |
+
method: 'post',
|
| 160 |
+
payload: { foo: 3, bar: 'ops' }
|
| 161 |
+
}, (err, res) => {
|
| 162 |
+
t.error(err)
|
| 163 |
+
t.equal(res.statusCode, 400)
|
| 164 |
+
t.match(res.json().message, errorMessage.additionalProperties)
|
| 165 |
+
})
|
| 166 |
+
})
|
| 167 |
+
|
| 168 |
+
t.test('Custom i18n error messages', (t) => {
|
| 169 |
+
t.plan(3)
|
| 170 |
+
|
| 171 |
+
const app = buildApplication({
|
| 172 |
+
customOptions: {
|
| 173 |
+
allErrors: true,
|
| 174 |
+
messages: false
|
| 175 |
+
},
|
| 176 |
+
plugins: [ajvFormats]
|
| 177 |
+
})
|
| 178 |
+
|
| 179 |
+
app.post('/', {
|
| 180 |
+
handler: () => { t.fail('dont call me') },
|
| 181 |
+
schema: {
|
| 182 |
+
body: {
|
| 183 |
+
type: 'object',
|
| 184 |
+
required: ['foo'],
|
| 185 |
+
properties: {
|
| 186 |
+
foo: { type: 'integer' }
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
})
|
| 191 |
+
|
| 192 |
+
app.setErrorHandler((error, request, reply) => {
|
| 193 |
+
t.pass('Error handler executed')
|
| 194 |
+
if (error.validation) {
|
| 195 |
+
localize.ru(error.validation)
|
| 196 |
+
reply.status(400).send(error.validation)
|
| 197 |
+
return
|
| 198 |
+
}
|
| 199 |
+
t.fail('not other errors')
|
| 200 |
+
})
|
| 201 |
+
|
| 202 |
+
app.inject({
|
| 203 |
+
method: 'POST',
|
| 204 |
+
url: '/',
|
| 205 |
+
payload: {
|
| 206 |
+
foo: 'string'
|
| 207 |
+
}
|
| 208 |
+
}, (err, res) => {
|
| 209 |
+
t.error(err)
|
| 210 |
+
t.equal(res.json()[0].message, 'должно быть integer')
|
| 211 |
+
})
|
| 212 |
+
})
|
| 213 |
+
|
| 214 |
+
function buildApplication (ajvOptions) {
|
| 215 |
+
const factory = AjvCompiler()
|
| 216 |
+
|
| 217 |
+
const app = fastify({
|
| 218 |
+
ajv: ajvOptions,
|
| 219 |
+
schemaController: {
|
| 220 |
+
compilersFactory: {
|
| 221 |
+
buildValidator: factory
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
})
|
| 225 |
+
|
| 226 |
+
app.get('/:id', {
|
| 227 |
+
schema: {
|
| 228 |
+
headers: {
|
| 229 |
+
type: 'object',
|
| 230 |
+
required: [
|
| 231 |
+
'x-foo',
|
| 232 |
+
'x-date',
|
| 233 |
+
'x-email'
|
| 234 |
+
],
|
| 235 |
+
properties: {
|
| 236 |
+
'x-foo': { type: 'string' },
|
| 237 |
+
'x-date': { type: 'string', format: 'date-time' },
|
| 238 |
+
'x-email': { type: 'string', format: 'email' }
|
| 239 |
+
}
|
| 240 |
+
},
|
| 241 |
+
query: {
|
| 242 |
+
type: 'object',
|
| 243 |
+
required: [
|
| 244 |
+
'foo',
|
| 245 |
+
'date',
|
| 246 |
+
'email'
|
| 247 |
+
],
|
| 248 |
+
properties: {
|
| 249 |
+
foo: { type: 'string' },
|
| 250 |
+
date: { type: 'string', format: 'date-time' },
|
| 251 |
+
email: { type: 'string', format: 'email' }
|
| 252 |
+
}
|
| 253 |
+
},
|
| 254 |
+
params: {
|
| 255 |
+
type: 'object',
|
| 256 |
+
properties: {
|
| 257 |
+
id: { type: 'string', format: 'uuid' }
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
}, async () => 'hello')
|
| 262 |
+
|
| 263 |
+
return app
|
| 264 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/test/serialization.test.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const t = require('tap')
|
| 4 |
+
const fastify = require('fastify')
|
| 5 |
+
const AjvCompiler = require('../index')
|
| 6 |
+
|
| 7 |
+
const jtdSchema = {
|
| 8 |
+
discriminator: 'version',
|
| 9 |
+
mapping: {
|
| 10 |
+
1: {
|
| 11 |
+
properties: {
|
| 12 |
+
foo: { type: 'uint8' }
|
| 13 |
+
}
|
| 14 |
+
},
|
| 15 |
+
2: {
|
| 16 |
+
properties: {
|
| 17 |
+
foo: { type: 'string' }
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const externalSchemas1 = Object.freeze({})
|
| 24 |
+
const externalSchemas2 = Object.freeze({
|
| 25 |
+
foo: {
|
| 26 |
+
definitions: {
|
| 27 |
+
coordinates: {
|
| 28 |
+
properties: {
|
| 29 |
+
lat: { type: 'float32' },
|
| 30 |
+
lng: { type: 'float32' }
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
})
|
| 36 |
+
|
| 37 |
+
const fastifyAjvOptionsDefault = Object.freeze({
|
| 38 |
+
customOptions: {}
|
| 39 |
+
})
|
| 40 |
+
|
| 41 |
+
t.test('basic serializer usage', t => {
|
| 42 |
+
t.plan(4)
|
| 43 |
+
const factory = AjvCompiler({ jtdSerializer: true })
|
| 44 |
+
const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault)
|
| 45 |
+
const serializeFunc = compiler({ schema: jtdSchema })
|
| 46 |
+
t.equal(serializeFunc({ version: '1', foo: 42 }), '{"version":"1","foo":42}')
|
| 47 |
+
t.equal(serializeFunc({ version: '2', foo: 'hello' }), '{"version":"2","foo":"hello"}')
|
| 48 |
+
t.equal(serializeFunc({ version: '3', foo: 'hello' }), '{"version":"3"}')
|
| 49 |
+
t.equal(serializeFunc({ version: '2', foo: ['not', 1, { string: 'string' }] }), '{"version":"2","foo":"not,1,[object Object]"}')
|
| 50 |
+
})
|
| 51 |
+
|
| 52 |
+
t.test('external schemas are ignored', t => {
|
| 53 |
+
t.plan(1)
|
| 54 |
+
const factory = AjvCompiler({ jtdSerializer: true })
|
| 55 |
+
const compiler = factory(externalSchemas2, fastifyAjvOptionsDefault)
|
| 56 |
+
const serializeFunc = compiler({
|
| 57 |
+
schema: {
|
| 58 |
+
definitions: {
|
| 59 |
+
coordinates: {
|
| 60 |
+
properties: {
|
| 61 |
+
lat: { type: 'float32' },
|
| 62 |
+
lng: { type: 'float32' }
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
properties: {
|
| 67 |
+
userLoc: { ref: 'coordinates' },
|
| 68 |
+
serverLoc: { ref: 'coordinates' }
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
})
|
| 72 |
+
t.equal(serializeFunc(
|
| 73 |
+
{ userLoc: { lat: 50, lng: -90 }, serverLoc: { lat: -15, lng: 50 } }),
|
| 74 |
+
'{"userLoc":{"lat":50,"lng":-90},"serverLoc":{"lat":-15,"lng":50}}'
|
| 75 |
+
)
|
| 76 |
+
})
|
| 77 |
+
|
| 78 |
+
t.test('fastify integration within JTD serializer', async t => {
|
| 79 |
+
const factoryValidator = AjvCompiler()
|
| 80 |
+
const factorySerializer = AjvCompiler({ jtdSerializer: true })
|
| 81 |
+
|
| 82 |
+
const app = fastify({
|
| 83 |
+
jsonShorthand: false,
|
| 84 |
+
ajv: {
|
| 85 |
+
customOptions: { },
|
| 86 |
+
mode: 'JTD'
|
| 87 |
+
},
|
| 88 |
+
schemaController: {
|
| 89 |
+
compilersFactory: {
|
| 90 |
+
buildValidator: factoryValidator,
|
| 91 |
+
buildSerializer: factorySerializer
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
})
|
| 95 |
+
|
| 96 |
+
app.post('/', {
|
| 97 |
+
schema: {
|
| 98 |
+
body: jtdSchema,
|
| 99 |
+
response: {
|
| 100 |
+
200: {
|
| 101 |
+
properties: {
|
| 102 |
+
id: { type: 'string' },
|
| 103 |
+
createdAt: { type: 'timestamp' },
|
| 104 |
+
karma: { type: 'int32' },
|
| 105 |
+
isAdmin: { type: 'boolean' }
|
| 106 |
+
}
|
| 107 |
+
},
|
| 108 |
+
400: jtdSchema
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}, async () => {
|
| 112 |
+
return {
|
| 113 |
+
id: '123',
|
| 114 |
+
createdAt: new Date('1999-01-31T23:00:00.000Z'),
|
| 115 |
+
karma: 42,
|
| 116 |
+
isAdmin: true,
|
| 117 |
+
remove: 'me'
|
| 118 |
+
}
|
| 119 |
+
})
|
| 120 |
+
|
| 121 |
+
{
|
| 122 |
+
const res = await app.inject({
|
| 123 |
+
url: '/',
|
| 124 |
+
method: 'POST',
|
| 125 |
+
payload: {
|
| 126 |
+
version: '1',
|
| 127 |
+
foo: 'not a number'
|
| 128 |
+
}
|
| 129 |
+
})
|
| 130 |
+
|
| 131 |
+
t.equal(res.statusCode, 400)
|
| 132 |
+
t.same(res.json(), { version: 'undefined' })
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
{
|
| 136 |
+
const res = await app.inject({
|
| 137 |
+
url: '/',
|
| 138 |
+
method: 'POST',
|
| 139 |
+
payload: {
|
| 140 |
+
version: '1',
|
| 141 |
+
foo: 32
|
| 142 |
+
}
|
| 143 |
+
})
|
| 144 |
+
|
| 145 |
+
t.equal(res.statusCode, 200)
|
| 146 |
+
t.same(res.json(), {
|
| 147 |
+
id: '123',
|
| 148 |
+
createdAt: '1999-01-31T23:00:00.000Z',
|
| 149 |
+
karma: 42,
|
| 150 |
+
isAdmin: true
|
| 151 |
+
})
|
| 152 |
+
}
|
| 153 |
+
})
|
| 154 |
+
|
| 155 |
+
t.test('fastify integration and cached serializer', async t => {
|
| 156 |
+
const factoryValidator = AjvCompiler()
|
| 157 |
+
const factorySerializer = AjvCompiler({ jtdSerializer: true })
|
| 158 |
+
|
| 159 |
+
const app = fastify({
|
| 160 |
+
jsonShorthand: false,
|
| 161 |
+
ajv: {
|
| 162 |
+
customOptions: { },
|
| 163 |
+
mode: 'JTD'
|
| 164 |
+
},
|
| 165 |
+
schemaController: {
|
| 166 |
+
compilersFactory: {
|
| 167 |
+
buildValidator: factoryValidator,
|
| 168 |
+
buildSerializer: factorySerializer
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
})
|
| 172 |
+
|
| 173 |
+
app.register(async function plugin (app, opts) {
|
| 174 |
+
app.post('/', {
|
| 175 |
+
schema: {
|
| 176 |
+
body: jtdSchema,
|
| 177 |
+
response: {
|
| 178 |
+
200: {
|
| 179 |
+
properties: {
|
| 180 |
+
id: { type: 'string' },
|
| 181 |
+
createdAt: { type: 'timestamp' },
|
| 182 |
+
karma: { type: 'int32' },
|
| 183 |
+
isAdmin: { type: 'boolean' }
|
| 184 |
+
}
|
| 185 |
+
},
|
| 186 |
+
400: jtdSchema
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
}, async () => {
|
| 190 |
+
return {
|
| 191 |
+
id: '123',
|
| 192 |
+
createdAt: new Date('1999-01-31T23:00:00.000Z'),
|
| 193 |
+
karma: 42,
|
| 194 |
+
isAdmin: true,
|
| 195 |
+
remove: 'me'
|
| 196 |
+
}
|
| 197 |
+
})
|
| 198 |
+
})
|
| 199 |
+
|
| 200 |
+
app.register(async function plugin (app, opts) {
|
| 201 |
+
app.post('/two', {
|
| 202 |
+
schema: {
|
| 203 |
+
body: jtdSchema,
|
| 204 |
+
response: {
|
| 205 |
+
400: jtdSchema
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}, () => {})
|
| 209 |
+
})
|
| 210 |
+
|
| 211 |
+
{
|
| 212 |
+
const res = await app.inject({
|
| 213 |
+
url: '/',
|
| 214 |
+
method: 'POST',
|
| 215 |
+
payload: {
|
| 216 |
+
version: '1',
|
| 217 |
+
foo: 'not a number'
|
| 218 |
+
}
|
| 219 |
+
})
|
| 220 |
+
|
| 221 |
+
t.equal(res.statusCode, 400)
|
| 222 |
+
t.same(res.json(), { version: 'undefined' })
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
{
|
| 226 |
+
const res = await app.inject({
|
| 227 |
+
url: '/',
|
| 228 |
+
method: 'POST',
|
| 229 |
+
payload: {
|
| 230 |
+
version: '1',
|
| 231 |
+
foo: 32
|
| 232 |
+
}
|
| 233 |
+
})
|
| 234 |
+
|
| 235 |
+
t.equal(res.statusCode, 200)
|
| 236 |
+
t.same(res.json(), {
|
| 237 |
+
id: '123',
|
| 238 |
+
createdAt: '1999-01-31T23:00:00.000Z',
|
| 239 |
+
karma: 42,
|
| 240 |
+
isAdmin: true
|
| 241 |
+
})
|
| 242 |
+
}
|
| 243 |
+
})
|
| 244 |
+
|
| 245 |
+
t.test('fastify integration within JTD serializer and custom options', async t => {
|
| 246 |
+
const factorySerializer = AjvCompiler({ jtdSerializer: true })
|
| 247 |
+
|
| 248 |
+
const app = fastify({
|
| 249 |
+
jsonShorthand: false,
|
| 250 |
+
serializerOpts: {
|
| 251 |
+
allErrors: true,
|
| 252 |
+
logger: 'wrong-value'
|
| 253 |
+
},
|
| 254 |
+
schemaController: {
|
| 255 |
+
compilersFactory: {
|
| 256 |
+
buildSerializer: factorySerializer
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
})
|
| 260 |
+
|
| 261 |
+
app.post('/', {
|
| 262 |
+
schema: {
|
| 263 |
+
response: {
|
| 264 |
+
200: {
|
| 265 |
+
properties: {
|
| 266 |
+
test: { type: 'boolean' }
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
}, async () => { })
|
| 272 |
+
|
| 273 |
+
try {
|
| 274 |
+
await app.ready()
|
| 275 |
+
t.fail('should throw')
|
| 276 |
+
} catch (error) {
|
| 277 |
+
t.equal(error.message, 'logger must implement log, warn and error methods', 'the wrong setting is forwarded to ajv/jtd')
|
| 278 |
+
}
|
| 279 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/ajv-compiler/types/index.test-d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AnySchemaObject, ValidateFunction } from 'ajv'
|
| 2 |
+
import { AnyValidateFunction } from 'ajv/dist/core'
|
| 3 |
+
import { expectAssignable, expectType } from 'tsd'
|
| 4 |
+
import AjvCompiler, { AjvReference, ValidatorFactory, StandaloneValidator, RouteDefinition, ErrorObject, BuildCompilerFromPool, BuildSerializerFromPool, ValidatorCompiler } from '..'
|
| 5 |
+
|
| 6 |
+
{
|
| 7 |
+
const compiler = AjvCompiler({})
|
| 8 |
+
expectType<BuildCompilerFromPool>(compiler)
|
| 9 |
+
}
|
| 10 |
+
{
|
| 11 |
+
const compiler = AjvCompiler()
|
| 12 |
+
expectType<BuildCompilerFromPool>(compiler)
|
| 13 |
+
}
|
| 14 |
+
{
|
| 15 |
+
const compiler = AjvCompiler({ jtdSerializer: false })
|
| 16 |
+
expectType<BuildCompilerFromPool>(compiler)
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
{
|
| 20 |
+
const factory = AjvCompiler({ jtdSerializer: false })
|
| 21 |
+
expectType<BuildCompilerFromPool>(factory)
|
| 22 |
+
factory({}, {
|
| 23 |
+
onCreate (ajv) {
|
| 24 |
+
expectType<import('ajv').default>(ajv)
|
| 25 |
+
}
|
| 26 |
+
})
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
{
|
| 30 |
+
const compiler = AjvCompiler({ jtdSerializer: true })
|
| 31 |
+
expectType<BuildSerializerFromPool>(compiler)
|
| 32 |
+
}
|
| 33 |
+
const reader = StandaloneValidator({
|
| 34 |
+
readMode: true,
|
| 35 |
+
restoreFunction: (route: RouteDefinition) => {
|
| 36 |
+
expectAssignable<RouteDefinition>(route)
|
| 37 |
+
return {} as ValidateFunction
|
| 38 |
+
},
|
| 39 |
+
})
|
| 40 |
+
expectAssignable<ValidatorFactory>(reader)
|
| 41 |
+
|
| 42 |
+
const writer = StandaloneValidator({
|
| 43 |
+
readMode: false,
|
| 44 |
+
storeFunction: (route: RouteDefinition, code: string) => {
|
| 45 |
+
expectAssignable<RouteDefinition>(route)
|
| 46 |
+
expectAssignable<string>(code)
|
| 47 |
+
},
|
| 48 |
+
})
|
| 49 |
+
expectAssignable<ValidatorFactory>(writer)
|
| 50 |
+
|
| 51 |
+
expectType<unknown>(({} as ErrorObject).data)
|
| 52 |
+
expectType<string>(({} as ErrorObject).instancePath)
|
| 53 |
+
expectType<string>(({} as ErrorObject).keyword)
|
| 54 |
+
expectType<string | undefined>(({} as ErrorObject).message)
|
| 55 |
+
expectType<Record<string, any>>(({} as ErrorObject).params)
|
| 56 |
+
expectType<AnySchemaObject | undefined>(({} as ErrorObject).parentSchema)
|
| 57 |
+
expectType<string | undefined>(({} as ErrorObject).propertyName)
|
| 58 |
+
expectType<unknown>(({} as ErrorObject).schema)
|
| 59 |
+
expectType<string>(({} as ErrorObject).schemaPath)
|
| 60 |
+
|
| 61 |
+
expectType<Symbol>(AjvReference)
|
| 62 |
+
|
| 63 |
+
{
|
| 64 |
+
const jtdSchema = {
|
| 65 |
+
discriminator: 'version',
|
| 66 |
+
mapping: {
|
| 67 |
+
1: {
|
| 68 |
+
properties: {
|
| 69 |
+
foo: { type: 'uint8' }
|
| 70 |
+
}
|
| 71 |
+
},
|
| 72 |
+
2: {
|
| 73 |
+
properties: {
|
| 74 |
+
foo: { type: 'string' }
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
const externalSchemas1 = {
|
| 81 |
+
foo: {
|
| 82 |
+
definitions: {
|
| 83 |
+
coordinates: {
|
| 84 |
+
properties: {
|
| 85 |
+
lat: { type: 'float32' },
|
| 86 |
+
lng: { type: 'float32' }
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
const factory = AjvCompiler({ jtdSerializer: true })
|
| 94 |
+
expectType<BuildSerializerFromPool>(factory)
|
| 95 |
+
const compiler = factory(externalSchemas1, {})
|
| 96 |
+
expectAssignable<Function>(compiler)
|
| 97 |
+
const serializeFunc = compiler({ schema: jtdSchema })
|
| 98 |
+
expectType<(data: unknown) => string>(serializeFunc)
|
| 99 |
+
expectType<string>(serializeFunc({ version: '1', foo: 42 }))
|
| 100 |
+
}
|
| 101 |
+
// JTD
|
| 102 |
+
{
|
| 103 |
+
const factory = AjvCompiler()
|
| 104 |
+
expectType<BuildCompilerFromPool>(factory)
|
| 105 |
+
|
| 106 |
+
const jtdSchema = {
|
| 107 |
+
discriminator: 'version',
|
| 108 |
+
mapping: {
|
| 109 |
+
1: {
|
| 110 |
+
properties: {
|
| 111 |
+
foo: { type: 'uint8' }
|
| 112 |
+
}
|
| 113 |
+
},
|
| 114 |
+
2: {
|
| 115 |
+
properties: {
|
| 116 |
+
foo: { type: 'string' }
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
const compiler = factory({}, {
|
| 123 |
+
customOptions: {},
|
| 124 |
+
mode: 'JTD'
|
| 125 |
+
})
|
| 126 |
+
expectAssignable<ValidatorCompiler>(compiler)
|
| 127 |
+
const validatorFunc = compiler({ schema: jtdSchema })
|
| 128 |
+
expectAssignable<ValidateFunction>(validatorFunc)
|
| 129 |
+
|
| 130 |
+
expectType<boolean | Promise<any>>(validatorFunc({
|
| 131 |
+
version: '2',
|
| 132 |
+
foo: []
|
| 133 |
+
}))
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// generate standalone code
|
| 137 |
+
{
|
| 138 |
+
const base = {
|
| 139 |
+
$id: 'urn:schema:base',
|
| 140 |
+
definitions: {
|
| 141 |
+
hello: { type: 'string' }
|
| 142 |
+
},
|
| 143 |
+
type: 'object',
|
| 144 |
+
properties: {
|
| 145 |
+
hello: { $ref: '#/definitions/hello' }
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
const refSchema = {
|
| 150 |
+
$id: 'urn:schema:ref',
|
| 151 |
+
type: 'object',
|
| 152 |
+
properties: {
|
| 153 |
+
hello: { $ref: 'urn:schema:base#/definitions/hello' }
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
const endpointSchema = {
|
| 158 |
+
schema: {
|
| 159 |
+
$id: 'urn:schema:endpoint',
|
| 160 |
+
$ref: 'urn:schema:ref'
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
const schemaMap = {
|
| 165 |
+
[base.$id]: base,
|
| 166 |
+
[refSchema.$id]: refSchema
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
const factory = StandaloneValidator({
|
| 170 |
+
readMode: false,
|
| 171 |
+
storeFunction (routeOpts, schemaValidationCode) {
|
| 172 |
+
expectType<RouteDefinition>(routeOpts)
|
| 173 |
+
expectType<string>(schemaValidationCode)
|
| 174 |
+
}
|
| 175 |
+
})
|
| 176 |
+
expectAssignable<ValidatorFactory>(factory)
|
| 177 |
+
|
| 178 |
+
const compiler = factory(schemaMap)
|
| 179 |
+
expectAssignable<ValidatorCompiler>(compiler)
|
| 180 |
+
expectAssignable<Function>(compiler(endpointSchema))
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
{
|
| 184 |
+
const base = {
|
| 185 |
+
$id: 'urn:schema:base',
|
| 186 |
+
definitions: {
|
| 187 |
+
hello: { type: 'string' }
|
| 188 |
+
},
|
| 189 |
+
type: 'object',
|
| 190 |
+
properties: {
|
| 191 |
+
hello: { $ref: '#/definitions/hello' }
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
const refSchema = {
|
| 196 |
+
$id: 'urn:schema:ref',
|
| 197 |
+
type: 'object',
|
| 198 |
+
properties: {
|
| 199 |
+
hello: { $ref: 'urn:schema:base#/definitions/hello' }
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
const endpointSchema = {
|
| 204 |
+
schema: {
|
| 205 |
+
$id: 'urn:schema:endpoint',
|
| 206 |
+
$ref: 'urn:schema:ref'
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
const schemaMap = {
|
| 211 |
+
[base.$id]: base,
|
| 212 |
+
[refSchema.$id]: refSchema
|
| 213 |
+
}
|
| 214 |
+
const factory = StandaloneValidator({
|
| 215 |
+
readMode: true,
|
| 216 |
+
restoreFunction (routeOpts) {
|
| 217 |
+
expectType<RouteDefinition>(routeOpts)
|
| 218 |
+
return {} as ValidateFunction
|
| 219 |
+
}
|
| 220 |
+
})
|
| 221 |
+
expectAssignable<ValidatorFactory>(factory)
|
| 222 |
+
|
| 223 |
+
const compiler = factory(schemaMap)
|
| 224 |
+
expectAssignable<ValidatorCompiler>(compiler)
|
| 225 |
+
expectType<AnyValidateFunction<any>>(compiler(endpointSchema))
|
| 226 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/.editorconfig
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root = true
|
| 2 |
+
|
| 3 |
+
[*]
|
| 4 |
+
indent_style = space
|
| 5 |
+
indent_size = 2
|
| 6 |
+
charset = utf-8
|
| 7 |
+
trim_trailing_whitespace = false
|
| 8 |
+
insert_final_newline = false
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/.gitattributes
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Set the default behavior, in case people don't have core.autocrlf set
|
| 2 |
+
* text=auto
|
| 3 |
+
|
| 4 |
+
# Require Unix line endings
|
| 5 |
+
* text eol=lf
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/.github/stale.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Number of days of inactivity before an issue becomes stale
|
| 2 |
+
daysUntilStale: 15
|
| 3 |
+
# Number of days of inactivity before a stale issue is closed
|
| 4 |
+
daysUntilClose: 7
|
| 5 |
+
# Issues with these labels will never be considered stale
|
| 6 |
+
exemptLabels:
|
| 7 |
+
- "discussion"
|
| 8 |
+
- "feature request"
|
| 9 |
+
- "bug"
|
| 10 |
+
- "help wanted"
|
| 11 |
+
- "plugin suggestion"
|
| 12 |
+
- "good first issue"
|
| 13 |
+
# Label to use when marking an issue as stale
|
| 14 |
+
staleLabel: stale
|
| 15 |
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
| 16 |
+
markComment: >
|
| 17 |
+
This issue has been automatically marked as stale because it has not had
|
| 18 |
+
recent activity. It will be closed if no further activity occurs. Thank you
|
| 19 |
+
for your contributions.
|
| 20 |
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
| 21 |
+
closeComment: false
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/bench.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const fastify = require('fastify')()
|
| 4 |
+
|
| 5 |
+
fastify.register((instance, _opts, next) => {
|
| 6 |
+
instance.register(require('./index'))
|
| 7 |
+
instance.get('/fastify', (_req, reply) => reply.send('ok'))
|
| 8 |
+
next()
|
| 9 |
+
})
|
| 10 |
+
|
| 11 |
+
fastify.register((instance, _opts, next) => {
|
| 12 |
+
instance.use(require('cors')())
|
| 13 |
+
instance.get('/express', (_req, reply) => reply.send('ok'))
|
| 14 |
+
next()
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
fastify.listen({ port: 3000 })
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/benchmark/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "benchmark",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "",
|
| 5 |
+
"main": "vary.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"test": "echo \"Error: no test specified\" && exit 1"
|
| 8 |
+
},
|
| 9 |
+
"author": "",
|
| 10 |
+
"license": "ISC",
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"benchmark": "^2.1.4",
|
| 13 |
+
"vary": "^1.1.2"
|
| 14 |
+
}
|
| 15 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/benchmark/vary.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const benchmark = require('benchmark')
|
| 4 |
+
const vary = require('vary')
|
| 5 |
+
const createAddFieldnameToVary = require('../vary').createAddFieldnameToVary
|
| 6 |
+
|
| 7 |
+
const replyMock = (header) => ({
|
| 8 |
+
getHeader () { return header },
|
| 9 |
+
setHeader () { },
|
| 10 |
+
header () { }
|
| 11 |
+
})
|
| 12 |
+
|
| 13 |
+
const addAcceptToVary = createAddFieldnameToVary('Accept')
|
| 14 |
+
const addWildcardToVary = createAddFieldnameToVary('*')
|
| 15 |
+
const addAcceptEncodingToVary = createAddFieldnameToVary('Accept-Encoding')
|
| 16 |
+
const addXFooToVary = createAddFieldnameToVary('X-Foo')
|
| 17 |
+
|
| 18 |
+
new benchmark.Suite()
|
| 19 |
+
.add('vary - field to undefined', function () { vary(replyMock(undefined), 'Accept-Encoding') }, { minSamples: 100 })
|
| 20 |
+
.add('vary - field to *', function () { vary(replyMock('*'), 'Accept-Encoding') }, { minSamples: 100 })
|
| 21 |
+
.add('vary - * to field', function () { vary(replyMock('Accept-Encoding'), '*') }, { minSamples: 100 })
|
| 22 |
+
.add('vary - field to empty', function () { vary(replyMock(''), 'Accept-Encoding') }, { minSamples: 100 })
|
| 23 |
+
.add('vary - fields string to empty', function () { vary(replyMock(''), 'Accept') }, { minSamples: 100 })
|
| 24 |
+
.add('vary - field to fields', function () { vary(replyMock('Accept, Accept-Encoding, Accept-Language'), 'X-Foo') }, { minSamples: 100 })
|
| 25 |
+
|
| 26 |
+
.add('cors - field to undefined', function () { addAcceptEncodingToVary(replyMock(undefined)) }, { minSamples: 100 })
|
| 27 |
+
.add('cors - field to *', function () { addAcceptEncodingToVary(replyMock('*')) }, { minSamples: 100 })
|
| 28 |
+
.add('cors - * to field', function () { addWildcardToVary(replyMock('Accept-Encoding')) }, { minSamples: 100 })
|
| 29 |
+
.add('cors - field to empty', function () { addAcceptEncodingToVary(replyMock('')) }, { minSamples: 100 })
|
| 30 |
+
.add('cors - fields string to empty', function () { addAcceptToVary(replyMock('')) }, { minSamples: 100 })
|
| 31 |
+
.add('cors - field to fields', function () { addXFooToVary(replyMock('Accept, Accept-Encoding, Accept-Language')) }, { minSamples: 100 })
|
| 32 |
+
|
| 33 |
+
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
|
| 34 |
+
.run({ async: false })
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/test/cors.test.js
ADDED
|
@@ -0,0 +1,1052 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { test } = require('node:test')
|
| 4 |
+
const { createReadStream, statSync, readFileSync } = require('node:fs')
|
| 5 |
+
const Fastify = require('fastify')
|
| 6 |
+
const cors = require('../')
|
| 7 |
+
const { resolve } = require('node:path')
|
| 8 |
+
const { setTimeout: sleep } = require('node:timers/promises')
|
| 9 |
+
|
| 10 |
+
test('Should add cors headers', async t => {
|
| 11 |
+
t.plan(4)
|
| 12 |
+
|
| 13 |
+
const fastify = Fastify()
|
| 14 |
+
fastify.register(cors)
|
| 15 |
+
|
| 16 |
+
fastify.get('/', (_req, reply) => {
|
| 17 |
+
reply.send('ok')
|
| 18 |
+
})
|
| 19 |
+
|
| 20 |
+
const res = await fastify.inject({
|
| 21 |
+
method: 'GET',
|
| 22 |
+
url: '/'
|
| 23 |
+
})
|
| 24 |
+
|
| 25 |
+
t.assert.ok(res)
|
| 26 |
+
delete res.headers.date
|
| 27 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 28 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 29 |
+
t.assert.deepStrictEqual(res.headers['access-control-allow-origin'],
|
| 30 |
+
'*'
|
| 31 |
+
)
|
| 32 |
+
})
|
| 33 |
+
|
| 34 |
+
test('Should add cors headers when payload is a stream', async t => {
|
| 35 |
+
t.plan(4)
|
| 36 |
+
|
| 37 |
+
const fastify = Fastify()
|
| 38 |
+
fastify.register(cors)
|
| 39 |
+
const filePath = resolve(__dirname, __filename)
|
| 40 |
+
|
| 41 |
+
fastify.get('/', (_req, reply) => {
|
| 42 |
+
const stream = createReadStream(filePath)
|
| 43 |
+
reply
|
| 44 |
+
.type('application/json')
|
| 45 |
+
.header('Content-Length', statSync(filePath).size)
|
| 46 |
+
.send(stream)
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
const fileContent = readFileSync(filePath, 'utf-8')
|
| 50 |
+
|
| 51 |
+
const res = await fastify.inject({
|
| 52 |
+
method: 'GET',
|
| 53 |
+
url: '/'
|
| 54 |
+
})
|
| 55 |
+
t.assert.ok(res)
|
| 56 |
+
delete res.headers.date
|
| 57 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 58 |
+
t.assert.strictEqual(res.payload, fileContent)
|
| 59 |
+
const actualHeaders = {
|
| 60 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 61 |
+
'content-length': res.headers['content-length']
|
| 62 |
+
|
| 63 |
+
}
|
| 64 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 65 |
+
'access-control-allow-origin': '*',
|
| 66 |
+
'content-length': statSync(filePath).size.toString()
|
| 67 |
+
})
|
| 68 |
+
})
|
| 69 |
+
|
| 70 |
+
test('Should add cors headers (custom values)', async t => {
|
| 71 |
+
t.plan(10)
|
| 72 |
+
|
| 73 |
+
const fastify = Fastify()
|
| 74 |
+
fastify.register(cors, {
|
| 75 |
+
origin: 'example.com',
|
| 76 |
+
methods: 'GET',
|
| 77 |
+
credentials: true,
|
| 78 |
+
exposedHeaders: ['foo', 'bar'],
|
| 79 |
+
allowedHeaders: ['baz', 'woo'],
|
| 80 |
+
maxAge: 123,
|
| 81 |
+
cacheControl: 321
|
| 82 |
+
})
|
| 83 |
+
|
| 84 |
+
fastify.get('/', (_req, reply) => {
|
| 85 |
+
reply.send('ok')
|
| 86 |
+
})
|
| 87 |
+
|
| 88 |
+
let res = await fastify.inject({
|
| 89 |
+
method: 'OPTIONS',
|
| 90 |
+
url: '/',
|
| 91 |
+
headers: {
|
| 92 |
+
'access-control-request-method': 'GET',
|
| 93 |
+
origin: 'example.com'
|
| 94 |
+
}
|
| 95 |
+
})
|
| 96 |
+
t.assert.ok(res)
|
| 97 |
+
delete res.headers.date
|
| 98 |
+
t.assert.strictEqual(res.statusCode, 204)
|
| 99 |
+
t.assert.strictEqual(res.payload, '')
|
| 100 |
+
const actualHeaders = {
|
| 101 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 102 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 103 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 104 |
+
'access-control-allow-methods': res.headers['access-control-allow-methods'],
|
| 105 |
+
'access-control-allow-headers': res.headers['access-control-allow-headers'],
|
| 106 |
+
'access-control-max-age': res.headers['access-control-max-age'],
|
| 107 |
+
'cache-control': res.headers['cache-control'],
|
| 108 |
+
'content-length': res.headers['content-length']
|
| 109 |
+
}
|
| 110 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 111 |
+
'access-control-allow-origin': 'example.com',
|
| 112 |
+
'access-control-allow-credentials': 'true',
|
| 113 |
+
'access-control-expose-headers': 'foo, bar',
|
| 114 |
+
'access-control-allow-methods': 'GET',
|
| 115 |
+
'access-control-allow-headers': 'baz, woo',
|
| 116 |
+
'access-control-max-age': '123',
|
| 117 |
+
'cache-control': 'max-age=321',
|
| 118 |
+
'content-length': '0'
|
| 119 |
+
})
|
| 120 |
+
t.assert.notDeepEqual(res.headers, { vary: 'Origin' })
|
| 121 |
+
|
| 122 |
+
res = await fastify.inject({
|
| 123 |
+
method: 'GET',
|
| 124 |
+
url: '/'
|
| 125 |
+
})
|
| 126 |
+
t.assert.ok(res)
|
| 127 |
+
delete res.headers.date
|
| 128 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 129 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 130 |
+
const actualHeaders2 = {
|
| 131 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 132 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 133 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 134 |
+
'content-length': res.headers['content-length']
|
| 135 |
+
}
|
| 136 |
+
t.assert.deepStrictEqual(actualHeaders2, {
|
| 137 |
+
'access-control-allow-origin': 'example.com',
|
| 138 |
+
'access-control-allow-credentials': 'true',
|
| 139 |
+
'access-control-expose-headers': 'foo, bar',
|
| 140 |
+
'content-length': '2'
|
| 141 |
+
})
|
| 142 |
+
t.assert.notDeepEqual(res.headers, { vary: 'Origin' })
|
| 143 |
+
})
|
| 144 |
+
|
| 145 |
+
test('Should support dynamic config (callback)', async t => {
|
| 146 |
+
t.plan(16)
|
| 147 |
+
|
| 148 |
+
const configs = [{
|
| 149 |
+
origin: 'example.com',
|
| 150 |
+
methods: 'GET',
|
| 151 |
+
credentials: true,
|
| 152 |
+
exposedHeaders: ['foo', 'bar'],
|
| 153 |
+
allowedHeaders: ['baz', 'woo'],
|
| 154 |
+
maxAge: 123,
|
| 155 |
+
cacheControl: 456
|
| 156 |
+
}, {
|
| 157 |
+
origin: 'sample.com',
|
| 158 |
+
methods: 'GET',
|
| 159 |
+
credentials: true,
|
| 160 |
+
exposedHeaders: ['zoo', 'bar'],
|
| 161 |
+
allowedHeaders: ['baz', 'foo'],
|
| 162 |
+
maxAge: 321,
|
| 163 |
+
cacheControl: '456'
|
| 164 |
+
}]
|
| 165 |
+
|
| 166 |
+
const fastify = Fastify()
|
| 167 |
+
let requestId = 0
|
| 168 |
+
const configDelegation = async function (req, cb) {
|
| 169 |
+
// request should have id
|
| 170 |
+
t.assert.ok(req.id)
|
| 171 |
+
// request should not have send
|
| 172 |
+
t.assert.ifError(req.send)
|
| 173 |
+
|
| 174 |
+
const config = configs[requestId]
|
| 175 |
+
requestId++
|
| 176 |
+
if (config) {
|
| 177 |
+
cb(null, config)
|
| 178 |
+
} else {
|
| 179 |
+
cb(new Error('ouch'))
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
await fastify.register(cors, () => configDelegation)
|
| 183 |
+
|
| 184 |
+
fastify.get('/', (_req, reply) => {
|
| 185 |
+
reply.send('ok')
|
| 186 |
+
})
|
| 187 |
+
|
| 188 |
+
let res = await fastify.inject({
|
| 189 |
+
method: 'GET',
|
| 190 |
+
url: '/'
|
| 191 |
+
})
|
| 192 |
+
t.assert.ok(res)
|
| 193 |
+
delete res.headers.date
|
| 194 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 195 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 196 |
+
const actualHeaders = {
|
| 197 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 198 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 199 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 200 |
+
'content-length': res.headers['content-length'],
|
| 201 |
+
vary: res.headers.vary
|
| 202 |
+
}
|
| 203 |
+
// Sleep to wait for callback
|
| 204 |
+
sleep()
|
| 205 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 206 |
+
'access-control-allow-origin': 'example.com',
|
| 207 |
+
'access-control-allow-credentials': 'true',
|
| 208 |
+
'access-control-expose-headers': 'foo, bar',
|
| 209 |
+
'content-length': '2',
|
| 210 |
+
vary: 'Origin'
|
| 211 |
+
})
|
| 212 |
+
|
| 213 |
+
res = await fastify.inject({
|
| 214 |
+
method: 'OPTIONS',
|
| 215 |
+
url: '/',
|
| 216 |
+
headers: {
|
| 217 |
+
'access-control-request-method': 'GET',
|
| 218 |
+
origin: 'example.com'
|
| 219 |
+
}
|
| 220 |
+
})
|
| 221 |
+
t.assert.ok(res)
|
| 222 |
+
delete res.headers.date
|
| 223 |
+
t.assert.strictEqual(res.statusCode, 204)
|
| 224 |
+
t.assert.strictEqual(res.payload, '')
|
| 225 |
+
const actualHeaders2 = {
|
| 226 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 227 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 228 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 229 |
+
'access-control-allow-methods': res.headers['access-control-allow-methods'],
|
| 230 |
+
'access-control-allow-headers': res.headers['access-control-allow-headers'],
|
| 231 |
+
'access-control-max-age': res.headers['access-control-max-age'],
|
| 232 |
+
'cache-control': res.headers['cache-control'],
|
| 233 |
+
'content-length': res.headers['content-length'],
|
| 234 |
+
vary: res.headers.vary
|
| 235 |
+
}
|
| 236 |
+
// Sleep to wait for callback
|
| 237 |
+
sleep()
|
| 238 |
+
t.assert.deepStrictEqual(actualHeaders2, {
|
| 239 |
+
'access-control-allow-origin': 'sample.com',
|
| 240 |
+
'access-control-allow-credentials': 'true',
|
| 241 |
+
'access-control-expose-headers': 'zoo, bar',
|
| 242 |
+
'access-control-allow-methods': 'GET',
|
| 243 |
+
'access-control-allow-headers': 'baz, foo',
|
| 244 |
+
'access-control-max-age': '321',
|
| 245 |
+
'cache-control': '456',
|
| 246 |
+
'content-length': '0',
|
| 247 |
+
vary: 'Origin'
|
| 248 |
+
})
|
| 249 |
+
|
| 250 |
+
res = await fastify.inject({
|
| 251 |
+
method: 'GET',
|
| 252 |
+
url: '/',
|
| 253 |
+
headers: {
|
| 254 |
+
'access-control-request-method': 'GET',
|
| 255 |
+
origin: 'example.com'
|
| 256 |
+
}
|
| 257 |
+
})
|
| 258 |
+
t.assert.ok(res)
|
| 259 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 260 |
+
})
|
| 261 |
+
|
| 262 |
+
test('Should support dynamic config (Promise)', async t => {
|
| 263 |
+
t.plan(23)
|
| 264 |
+
|
| 265 |
+
const configs = [{
|
| 266 |
+
origin: 'example.com',
|
| 267 |
+
methods: 'GET',
|
| 268 |
+
credentials: true,
|
| 269 |
+
exposedHeaders: ['foo', 'bar'],
|
| 270 |
+
allowedHeaders: ['baz', 'woo'],
|
| 271 |
+
maxAge: 123,
|
| 272 |
+
cacheControl: 456
|
| 273 |
+
}, {
|
| 274 |
+
origin: 'sample.com',
|
| 275 |
+
methods: 'GET',
|
| 276 |
+
credentials: true,
|
| 277 |
+
exposedHeaders: ['zoo', 'bar'],
|
| 278 |
+
allowedHeaders: ['baz', 'foo'],
|
| 279 |
+
maxAge: 321,
|
| 280 |
+
cacheControl: true // Invalid value should be ignored
|
| 281 |
+
}, {
|
| 282 |
+
origin: 'sample.com',
|
| 283 |
+
methods: 'GET',
|
| 284 |
+
credentials: true,
|
| 285 |
+
exposedHeaders: ['zoo', 'bar'],
|
| 286 |
+
allowedHeaders: ['baz', 'foo'],
|
| 287 |
+
maxAge: 321,
|
| 288 |
+
cacheControl: 'public, max-age=456'
|
| 289 |
+
}]
|
| 290 |
+
|
| 291 |
+
const fastify = Fastify()
|
| 292 |
+
let requestId = 0
|
| 293 |
+
const configDelegation = async function (req) {
|
| 294 |
+
// request should have id
|
| 295 |
+
t.assert.ok(req.id)
|
| 296 |
+
// request should not have send
|
| 297 |
+
t.assert.ifError(req.send)
|
| 298 |
+
const config = configs[requestId]
|
| 299 |
+
requestId++
|
| 300 |
+
if (config) {
|
| 301 |
+
return Promise.resolve(config)
|
| 302 |
+
} else {
|
| 303 |
+
return Promise.reject(new Error('ouch'))
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
await fastify.register(cors, () => configDelegation)
|
| 307 |
+
|
| 308 |
+
fastify.get('/', (_req, reply) => {
|
| 309 |
+
reply.send('ok')
|
| 310 |
+
})
|
| 311 |
+
|
| 312 |
+
let res = await fastify.inject({
|
| 313 |
+
method: 'GET',
|
| 314 |
+
url: '/'
|
| 315 |
+
})
|
| 316 |
+
t.assert.ok(res)
|
| 317 |
+
delete res.headers.date
|
| 318 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 319 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 320 |
+
const actualHeaders = {
|
| 321 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 322 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 323 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 324 |
+
'content-length': res.headers['content-length'],
|
| 325 |
+
vary: res.headers.vary
|
| 326 |
+
}
|
| 327 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 328 |
+
'access-control-allow-origin': 'example.com',
|
| 329 |
+
'access-control-allow-credentials': 'true',
|
| 330 |
+
'access-control-expose-headers': 'foo, bar',
|
| 331 |
+
'content-length': '2',
|
| 332 |
+
vary: 'Origin'
|
| 333 |
+
})
|
| 334 |
+
|
| 335 |
+
res = await fastify.inject({
|
| 336 |
+
method: 'OPTIONS',
|
| 337 |
+
url: '/',
|
| 338 |
+
headers: {
|
| 339 |
+
'access-control-request-method': 'GET',
|
| 340 |
+
origin: 'sample.com'
|
| 341 |
+
}
|
| 342 |
+
})
|
| 343 |
+
t.assert.ok(res)
|
| 344 |
+
delete res.headers.date
|
| 345 |
+
t.assert.strictEqual(res.statusCode, 204)
|
| 346 |
+
t.assert.strictEqual(res.payload, '')
|
| 347 |
+
const acutalHeaders2 = {
|
| 348 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 349 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 350 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 351 |
+
'access-control-allow-methods': res.headers['access-control-allow-methods'],
|
| 352 |
+
'access-control-allow-headers': res.headers['access-control-allow-headers'],
|
| 353 |
+
'access-control-max-age': res.headers['access-control-max-age'],
|
| 354 |
+
'content-length': res.headers['content-length'],
|
| 355 |
+
vary: res.headers.vary
|
| 356 |
+
}
|
| 357 |
+
t.assert.deepStrictEqual(acutalHeaders2, {
|
| 358 |
+
'access-control-allow-origin': 'sample.com',
|
| 359 |
+
'access-control-allow-credentials': 'true',
|
| 360 |
+
'access-control-expose-headers': 'zoo, bar',
|
| 361 |
+
'access-control-allow-methods': 'GET',
|
| 362 |
+
'access-control-allow-headers': 'baz, foo',
|
| 363 |
+
'access-control-max-age': '321',
|
| 364 |
+
'content-length': '0',
|
| 365 |
+
vary: 'Origin'
|
| 366 |
+
})
|
| 367 |
+
t.assert.strictEqual(res.headers['cache-control'], undefined, 'cache-control omitted (invalid value)')
|
| 368 |
+
|
| 369 |
+
res = await fastify.inject({
|
| 370 |
+
method: 'OPTIONS',
|
| 371 |
+
url: '/',
|
| 372 |
+
headers: {
|
| 373 |
+
'access-control-request-method': 'GET',
|
| 374 |
+
origin: 'example.com'
|
| 375 |
+
}
|
| 376 |
+
})
|
| 377 |
+
t.assert.ok(res)
|
| 378 |
+
delete res.headers.date
|
| 379 |
+
t.assert.strictEqual(res.statusCode, 204)
|
| 380 |
+
t.assert.strictEqual(res.payload, '')
|
| 381 |
+
const actualHeaders3 = {
|
| 382 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 383 |
+
'access-control-allow-credentials': res.headers['access-control-allow-credentials'],
|
| 384 |
+
'access-control-expose-headers': res.headers['access-control-expose-headers'],
|
| 385 |
+
'access-control-allow-methods': res.headers['access-control-allow-methods'],
|
| 386 |
+
'access-control-allow-headers': res.headers['access-control-allow-headers'],
|
| 387 |
+
'access-control-max-age': res.headers['access-control-max-age'],
|
| 388 |
+
'cache-control': res.headers['cache-control'],
|
| 389 |
+
'content-length': res.headers['content-length'],
|
| 390 |
+
vary: res.headers.vary
|
| 391 |
+
}
|
| 392 |
+
t.assert.deepStrictEqual(actualHeaders3, {
|
| 393 |
+
'access-control-allow-origin': 'sample.com',
|
| 394 |
+
'access-control-allow-credentials': 'true',
|
| 395 |
+
'access-control-expose-headers': 'zoo, bar',
|
| 396 |
+
'access-control-allow-methods': 'GET',
|
| 397 |
+
'access-control-allow-headers': 'baz, foo',
|
| 398 |
+
'access-control-max-age': '321',
|
| 399 |
+
'cache-control': 'public, max-age=456', // cache-control included (custom string)
|
| 400 |
+
'content-length': '0',
|
| 401 |
+
vary: 'Origin'
|
| 402 |
+
})
|
| 403 |
+
|
| 404 |
+
res = await fastify.inject({
|
| 405 |
+
method: 'GET',
|
| 406 |
+
url: '/',
|
| 407 |
+
headers: {
|
| 408 |
+
'access-control-request-method': 'GET',
|
| 409 |
+
origin: 'example.com'
|
| 410 |
+
}
|
| 411 |
+
})
|
| 412 |
+
t.assert.ok(res)
|
| 413 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 414 |
+
})
|
| 415 |
+
|
| 416 |
+
test('Should support dynamic config. (Invalid function)', async t => {
|
| 417 |
+
t.plan(2)
|
| 418 |
+
|
| 419 |
+
const fastify = Fastify()
|
| 420 |
+
fastify.register(cors, () => () => {})
|
| 421 |
+
|
| 422 |
+
fastify.get('/', (_req, reply) => {
|
| 423 |
+
reply.send('ok')
|
| 424 |
+
})
|
| 425 |
+
|
| 426 |
+
const res = await fastify.inject({
|
| 427 |
+
method: 'GET',
|
| 428 |
+
url: '/',
|
| 429 |
+
headers: {
|
| 430 |
+
'access-control-request-method': 'GET',
|
| 431 |
+
origin: 'example.com'
|
| 432 |
+
}
|
| 433 |
+
})
|
| 434 |
+
t.assert.ok(res)
|
| 435 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 436 |
+
})
|
| 437 |
+
|
| 438 |
+
test('Dynamic origin resolution (valid origin)', async t => {
|
| 439 |
+
t.plan(6)
|
| 440 |
+
|
| 441 |
+
const fastify = Fastify()
|
| 442 |
+
const origin = function (header, cb) {
|
| 443 |
+
t.assert.strictEqual(header, 'example.com')
|
| 444 |
+
t.assert.equal(this, fastify)
|
| 445 |
+
cb(null, true)
|
| 446 |
+
}
|
| 447 |
+
fastify.register(cors, { origin })
|
| 448 |
+
|
| 449 |
+
fastify.get('/', (_req, reply) => {
|
| 450 |
+
reply.send('ok')
|
| 451 |
+
})
|
| 452 |
+
|
| 453 |
+
const res = await fastify.inject({
|
| 454 |
+
method: 'GET',
|
| 455 |
+
url: '/',
|
| 456 |
+
headers: { origin: 'example.com' }
|
| 457 |
+
})
|
| 458 |
+
t.assert.ok(res)
|
| 459 |
+
delete res.headers.date
|
| 460 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 461 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 462 |
+
const actualHeaders = {
|
| 463 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 464 |
+
vary: res.headers.vary
|
| 465 |
+
}
|
| 466 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 467 |
+
'access-control-allow-origin': 'example.com',
|
| 468 |
+
vary: 'Origin'
|
| 469 |
+
})
|
| 470 |
+
})
|
| 471 |
+
|
| 472 |
+
test('Dynamic origin resolution (not valid origin)', async t => {
|
| 473 |
+
t.plan(5)
|
| 474 |
+
|
| 475 |
+
const fastify = Fastify()
|
| 476 |
+
const origin = (header, cb) => {
|
| 477 |
+
t.assert.strictEqual(header, 'example.com')
|
| 478 |
+
cb(null, false)
|
| 479 |
+
}
|
| 480 |
+
fastify.register(cors, { origin })
|
| 481 |
+
|
| 482 |
+
fastify.get('/', (_req, reply) => {
|
| 483 |
+
reply.send('ok')
|
| 484 |
+
})
|
| 485 |
+
|
| 486 |
+
const res = await fastify.inject({
|
| 487 |
+
method: 'GET',
|
| 488 |
+
url: '/',
|
| 489 |
+
headers: { origin: 'example.com' }
|
| 490 |
+
})
|
| 491 |
+
t.assert.ok(res)
|
| 492 |
+
delete res.headers.date
|
| 493 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 494 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 495 |
+
const actualHeaders = {
|
| 496 |
+
'content-length': res.headers['content-length'],
|
| 497 |
+
'content-type': res.headers['content-type'],
|
| 498 |
+
connection: res.headers.connection,
|
| 499 |
+
vary: res.headers.vary
|
| 500 |
+
}
|
| 501 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 502 |
+
'content-length': '2',
|
| 503 |
+
'content-type': 'text/plain; charset=utf-8',
|
| 504 |
+
connection: 'keep-alive',
|
| 505 |
+
vary: 'Origin'
|
| 506 |
+
})
|
| 507 |
+
})
|
| 508 |
+
|
| 509 |
+
test('Dynamic origin resolution (errored)', async t => {
|
| 510 |
+
t.plan(3)
|
| 511 |
+
|
| 512 |
+
const fastify = Fastify()
|
| 513 |
+
const origin = (header, cb) => {
|
| 514 |
+
t.assert.strictEqual(header, 'example.com')
|
| 515 |
+
cb(new Error('ouch'))
|
| 516 |
+
}
|
| 517 |
+
fastify.register(cors, { origin })
|
| 518 |
+
|
| 519 |
+
const res = await fastify.inject({
|
| 520 |
+
method: 'GET',
|
| 521 |
+
url: '/',
|
| 522 |
+
headers: { origin: 'example.com' }
|
| 523 |
+
})
|
| 524 |
+
t.assert.ok(res)
|
| 525 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 526 |
+
})
|
| 527 |
+
|
| 528 |
+
test('Dynamic origin resolution (invalid result)', async t => {
|
| 529 |
+
t.plan(3)
|
| 530 |
+
|
| 531 |
+
const fastify = Fastify()
|
| 532 |
+
const origin = (header, cb) => {
|
| 533 |
+
t.assert.strictEqual(header, 'example.com')
|
| 534 |
+
cb(null, undefined)
|
| 535 |
+
}
|
| 536 |
+
fastify.register(cors, { origin })
|
| 537 |
+
|
| 538 |
+
const res = await fastify.inject({
|
| 539 |
+
method: 'GET',
|
| 540 |
+
url: '/',
|
| 541 |
+
headers: { origin: 'example.com' }
|
| 542 |
+
})
|
| 543 |
+
t.assert.ok(res)
|
| 544 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 545 |
+
})
|
| 546 |
+
|
| 547 |
+
test('Dynamic origin resolution (valid origin - promises)', async t => {
|
| 548 |
+
t.plan(5)
|
| 549 |
+
|
| 550 |
+
const fastify = Fastify()
|
| 551 |
+
const origin = (header) => {
|
| 552 |
+
return new Promise((resolve) => {
|
| 553 |
+
t.assert.strictEqual(header, 'example.com')
|
| 554 |
+
resolve(true)
|
| 555 |
+
})
|
| 556 |
+
}
|
| 557 |
+
fastify.register(cors, { origin })
|
| 558 |
+
|
| 559 |
+
fastify.get('/', (_req, reply) => {
|
| 560 |
+
reply.send('ok')
|
| 561 |
+
})
|
| 562 |
+
|
| 563 |
+
const res = await fastify.inject({
|
| 564 |
+
method: 'GET',
|
| 565 |
+
url: '/',
|
| 566 |
+
headers: { origin: 'example.com' }
|
| 567 |
+
})
|
| 568 |
+
t.assert.ok(res)
|
| 569 |
+
delete res.headers.date
|
| 570 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 571 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 572 |
+
const actualHeaders = {
|
| 573 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 574 |
+
vary: res.headers.vary
|
| 575 |
+
}
|
| 576 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 577 |
+
'access-control-allow-origin': 'example.com',
|
| 578 |
+
vary: 'Origin'
|
| 579 |
+
})
|
| 580 |
+
})
|
| 581 |
+
|
| 582 |
+
test('Dynamic origin resolution (not valid origin - promises)', async t => {
|
| 583 |
+
t.plan(5)
|
| 584 |
+
|
| 585 |
+
const fastify = Fastify()
|
| 586 |
+
const origin = (header) => {
|
| 587 |
+
return new Promise((resolve) => {
|
| 588 |
+
t.assert.strictEqual(header, 'example.com')
|
| 589 |
+
resolve(false)
|
| 590 |
+
})
|
| 591 |
+
}
|
| 592 |
+
fastify.register(cors, { origin })
|
| 593 |
+
|
| 594 |
+
fastify.get('/', (_req, reply) => {
|
| 595 |
+
reply.send('ok')
|
| 596 |
+
})
|
| 597 |
+
|
| 598 |
+
const res = await fastify.inject({
|
| 599 |
+
method: 'GET',
|
| 600 |
+
url: '/',
|
| 601 |
+
headers: { origin: 'example.com' }
|
| 602 |
+
})
|
| 603 |
+
t.assert.ok(res)
|
| 604 |
+
delete res.headers.date
|
| 605 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 606 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 607 |
+
const actualHeaders = {
|
| 608 |
+
'content-length': res.headers['content-length'],
|
| 609 |
+
'content-type': res.headers['content-type'],
|
| 610 |
+
connection: res.headers.connection,
|
| 611 |
+
vary: res.headers.vary
|
| 612 |
+
}
|
| 613 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 614 |
+
'content-length': '2',
|
| 615 |
+
'content-type': 'text/plain; charset=utf-8',
|
| 616 |
+
connection: 'keep-alive',
|
| 617 |
+
vary: 'Origin'
|
| 618 |
+
})
|
| 619 |
+
})
|
| 620 |
+
|
| 621 |
+
test('Dynamic origin resolution (errored - promises)', async t => {
|
| 622 |
+
t.plan(3)
|
| 623 |
+
|
| 624 |
+
const fastify = Fastify()
|
| 625 |
+
const origin = (header) => {
|
| 626 |
+
return new Promise((_resolve, reject) => {
|
| 627 |
+
t.assert.strictEqual(header, 'example.com')
|
| 628 |
+
reject(new Error('ouch'))
|
| 629 |
+
})
|
| 630 |
+
}
|
| 631 |
+
fastify.register(cors, { origin })
|
| 632 |
+
|
| 633 |
+
const res = await fastify.inject({
|
| 634 |
+
method: 'GET',
|
| 635 |
+
url: '/',
|
| 636 |
+
headers: { origin: 'example.com' }
|
| 637 |
+
})
|
| 638 |
+
t.assert.ok(res)
|
| 639 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 640 |
+
})
|
| 641 |
+
|
| 642 |
+
test('Should reply 404 without cors headers when origin is false', async t => {
|
| 643 |
+
t.plan(8)
|
| 644 |
+
|
| 645 |
+
const fastify = Fastify()
|
| 646 |
+
fastify.register(cors, {
|
| 647 |
+
origin: false,
|
| 648 |
+
methods: 'GET',
|
| 649 |
+
credentials: true,
|
| 650 |
+
exposedHeaders: ['foo', 'bar'],
|
| 651 |
+
allowedHeaders: ['baz', 'woo'],
|
| 652 |
+
maxAge: 123
|
| 653 |
+
})
|
| 654 |
+
|
| 655 |
+
fastify.get('/', (_req, reply) => {
|
| 656 |
+
reply.send('ok')
|
| 657 |
+
})
|
| 658 |
+
|
| 659 |
+
let res = await fastify.inject({
|
| 660 |
+
method: 'OPTIONS',
|
| 661 |
+
url: '/'
|
| 662 |
+
})
|
| 663 |
+
t.assert.ok(res)
|
| 664 |
+
delete res.headers.date
|
| 665 |
+
t.assert.strictEqual(res.statusCode, 404)
|
| 666 |
+
t.assert.strictEqual(res.payload, '{"message":"Route OPTIONS:/ not found","error":"Not Found","statusCode":404}')
|
| 667 |
+
const actualHeaders = {
|
| 668 |
+
'content-length': res.headers['content-length'],
|
| 669 |
+
'content-type': res.headers['content-type'],
|
| 670 |
+
connection: res.headers.connection
|
| 671 |
+
}
|
| 672 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 673 |
+
'content-length': '76',
|
| 674 |
+
'content-type': 'application/json; charset=utf-8',
|
| 675 |
+
connection: 'keep-alive'
|
| 676 |
+
})
|
| 677 |
+
|
| 678 |
+
res = await fastify.inject({
|
| 679 |
+
method: 'GET',
|
| 680 |
+
url: '/'
|
| 681 |
+
})
|
| 682 |
+
t.assert.ok(res)
|
| 683 |
+
delete res.headers.date
|
| 684 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 685 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 686 |
+
t.assert.deepStrictEqual(res.headers, {
|
| 687 |
+
'content-length': '2',
|
| 688 |
+
'content-type': 'text/plain; charset=utf-8',
|
| 689 |
+
connection: 'keep-alive'
|
| 690 |
+
})
|
| 691 |
+
})
|
| 692 |
+
|
| 693 |
+
test('Server error if origin option is falsy but not false', async t => {
|
| 694 |
+
t.plan(4)
|
| 695 |
+
|
| 696 |
+
const fastify = Fastify()
|
| 697 |
+
fastify.register(cors, { origin: '' })
|
| 698 |
+
|
| 699 |
+
const res = await fastify.inject({
|
| 700 |
+
method: 'GET',
|
| 701 |
+
url: '/',
|
| 702 |
+
headers: { origin: 'example.com' }
|
| 703 |
+
})
|
| 704 |
+
t.assert.ok(res)
|
| 705 |
+
delete res.headers.date
|
| 706 |
+
t.assert.strictEqual(res.statusCode, 500)
|
| 707 |
+
t.assert.deepStrictEqual(res.json(), { statusCode: 500, error: 'Internal Server Error', message: 'Invalid CORS origin option' })
|
| 708 |
+
const actualHeaders = {
|
| 709 |
+
'content-length': res.headers['content-length'],
|
| 710 |
+
'content-type': res.headers['content-type'],
|
| 711 |
+
connection: res.headers.connection
|
| 712 |
+
}
|
| 713 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 714 |
+
'content-length': '89',
|
| 715 |
+
'content-type': 'application/json; charset=utf-8',
|
| 716 |
+
connection: 'keep-alive'
|
| 717 |
+
})
|
| 718 |
+
})
|
| 719 |
+
|
| 720 |
+
test('Allow only request from a specific origin', async t => {
|
| 721 |
+
t.plan(5)
|
| 722 |
+
|
| 723 |
+
const fastify = Fastify()
|
| 724 |
+
fastify.register(cors, { origin: 'other.io' })
|
| 725 |
+
|
| 726 |
+
fastify.get('/', (_req, reply) => {
|
| 727 |
+
reply.send('ok')
|
| 728 |
+
})
|
| 729 |
+
|
| 730 |
+
const res = await fastify.inject({
|
| 731 |
+
method: 'GET',
|
| 732 |
+
url: '/',
|
| 733 |
+
headers: { origin: 'example.com' }
|
| 734 |
+
})
|
| 735 |
+
t.assert.ok(res)
|
| 736 |
+
delete res.headers.date
|
| 737 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 738 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 739 |
+
t.assert.deepStrictEqual(res.headers['access-control-allow-origin'],
|
| 740 |
+
'other.io'
|
| 741 |
+
)
|
| 742 |
+
t.assert.notDeepEqual(res.headers, { vary: 'Origin' })
|
| 743 |
+
})
|
| 744 |
+
|
| 745 |
+
test('Allow only request from multiple specific origin', async t => {
|
| 746 |
+
t.plan(9)
|
| 747 |
+
|
| 748 |
+
const fastify = Fastify()
|
| 749 |
+
fastify.register(cors, { origin: ['other.io', 'example.com'] })
|
| 750 |
+
|
| 751 |
+
fastify.get('/', (_req, reply) => {
|
| 752 |
+
reply.send('ok')
|
| 753 |
+
})
|
| 754 |
+
|
| 755 |
+
let res = await fastify.inject({
|
| 756 |
+
method: 'GET',
|
| 757 |
+
url: '/',
|
| 758 |
+
headers: { origin: 'other.io' }
|
| 759 |
+
})
|
| 760 |
+
t.assert.ok(res)
|
| 761 |
+
delete res.headers.date
|
| 762 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 763 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 764 |
+
const actualHeaders = {
|
| 765 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 766 |
+
vary: res.headers.vary
|
| 767 |
+
}
|
| 768 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 769 |
+
'access-control-allow-origin': 'other.io',
|
| 770 |
+
vary: 'Origin'
|
| 771 |
+
})
|
| 772 |
+
|
| 773 |
+
res = await fastify.inject({
|
| 774 |
+
method: 'GET',
|
| 775 |
+
url: '/',
|
| 776 |
+
headers: { origin: 'foo.com' }
|
| 777 |
+
})
|
| 778 |
+
t.assert.ok(res)
|
| 779 |
+
delete res.headers.date
|
| 780 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 781 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 782 |
+
t.assert.deepStrictEqual(res.headers.vary,
|
| 783 |
+
'Origin'
|
| 784 |
+
)
|
| 785 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'], undefined)
|
| 786 |
+
})
|
| 787 |
+
|
| 788 |
+
test('Allow only request from a specific origin using regex', async t => {
|
| 789 |
+
t.plan(8)
|
| 790 |
+
|
| 791 |
+
const fastify = Fastify()
|
| 792 |
+
fastify.register(cors, { origin: /(?:example|other)\.com\/?$/giu })
|
| 793 |
+
|
| 794 |
+
fastify.get('/', (_req, reply) => {
|
| 795 |
+
reply.send('ok')
|
| 796 |
+
})
|
| 797 |
+
|
| 798 |
+
// .test was previously used, which caused 2 consecutive requests to return
|
| 799 |
+
// different results with global (e.g. /g) regexes. Therefore, check this
|
| 800 |
+
// twice to check consistency
|
| 801 |
+
for (let i = 0; i < 2; i++) {
|
| 802 |
+
const res = await fastify.inject({
|
| 803 |
+
method: 'GET',
|
| 804 |
+
url: '/',
|
| 805 |
+
headers: { origin: 'https://www.example.com/' }
|
| 806 |
+
})
|
| 807 |
+
t.assert.ok(res)
|
| 808 |
+
delete res.headers.date
|
| 809 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 810 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 811 |
+
const actualHeaders = {
|
| 812 |
+
'access-control-allow-origin': res.headers['access-control-allow-origin'],
|
| 813 |
+
vary: res.headers.vary
|
| 814 |
+
}
|
| 815 |
+
t.assert.deepStrictEqual(actualHeaders, {
|
| 816 |
+
'access-control-allow-origin': 'https://www.example.com/',
|
| 817 |
+
vary: 'Origin'
|
| 818 |
+
})
|
| 819 |
+
}
|
| 820 |
+
})
|
| 821 |
+
|
| 822 |
+
test('Disable preflight', async t => {
|
| 823 |
+
t.plan(7)
|
| 824 |
+
|
| 825 |
+
const fastify = Fastify()
|
| 826 |
+
fastify.register(cors, { preflight: false })
|
| 827 |
+
|
| 828 |
+
fastify.get('/', (_req, reply) => {
|
| 829 |
+
reply.send('ok')
|
| 830 |
+
})
|
| 831 |
+
|
| 832 |
+
let res = await fastify.inject({
|
| 833 |
+
method: 'OPTIONS',
|
| 834 |
+
url: '/hello'
|
| 835 |
+
})
|
| 836 |
+
t.assert.ok(res)
|
| 837 |
+
delete res.headers.date
|
| 838 |
+
t.assert.strictEqual(res.statusCode, 404)
|
| 839 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'],
|
| 840 |
+
'*'
|
| 841 |
+
)
|
| 842 |
+
|
| 843 |
+
res = await fastify.inject({
|
| 844 |
+
method: 'GET',
|
| 845 |
+
url: '/'
|
| 846 |
+
})
|
| 847 |
+
t.assert.ok(res)
|
| 848 |
+
delete res.headers.date
|
| 849 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 850 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 851 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'],
|
| 852 |
+
'*'
|
| 853 |
+
)
|
| 854 |
+
})
|
| 855 |
+
|
| 856 |
+
test('Should always add vary header to `Origin` for reflected origin', async t => {
|
| 857 |
+
t.plan(12)
|
| 858 |
+
|
| 859 |
+
const fastify = Fastify()
|
| 860 |
+
fastify.register(cors, { origin: true })
|
| 861 |
+
|
| 862 |
+
fastify.get('/', (_req, reply) => {
|
| 863 |
+
reply.send('ok')
|
| 864 |
+
})
|
| 865 |
+
|
| 866 |
+
// Invalid Preflight
|
| 867 |
+
let res = await fastify.inject({
|
| 868 |
+
method: 'OPTIONS',
|
| 869 |
+
url: '/'
|
| 870 |
+
})
|
| 871 |
+
t.assert.ok(res)
|
| 872 |
+
delete res.headers.date
|
| 873 |
+
t.assert.strictEqual(res.statusCode, 400)
|
| 874 |
+
t.assert.strictEqual(res.payload, 'Invalid Preflight Request')
|
| 875 |
+
t.assert.strictEqual(res.headers.vary,
|
| 876 |
+
'Origin'
|
| 877 |
+
)
|
| 878 |
+
|
| 879 |
+
// Valid Preflight
|
| 880 |
+
res = await fastify.inject({
|
| 881 |
+
method: 'OPTIONS',
|
| 882 |
+
url: '/',
|
| 883 |
+
headers: {
|
| 884 |
+
'access-control-request-method': 'GET',
|
| 885 |
+
origin: 'example.com'
|
| 886 |
+
}
|
| 887 |
+
})
|
| 888 |
+
t.assert.ok(res)
|
| 889 |
+
delete res.headers.date
|
| 890 |
+
t.assert.strictEqual(res.statusCode, 204)
|
| 891 |
+
t.assert.strictEqual(res.payload, '')
|
| 892 |
+
t.assert.strictEqual(res.headers.vary,
|
| 893 |
+
'Origin, Access-Control-Request-Headers'
|
| 894 |
+
)
|
| 895 |
+
|
| 896 |
+
// Other Route
|
| 897 |
+
res = await fastify.inject({
|
| 898 |
+
method: 'GET',
|
| 899 |
+
url: '/'
|
| 900 |
+
})
|
| 901 |
+
t.assert.ok(res)
|
| 902 |
+
delete res.headers.date
|
| 903 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 904 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 905 |
+
t.assert.strictEqual(res.headers.vary,
|
| 906 |
+
'Origin'
|
| 907 |
+
)
|
| 908 |
+
})
|
| 909 |
+
|
| 910 |
+
test('Should always add vary header to `Origin` for reflected origin (vary is array)', async t => {
|
| 911 |
+
t.plan(4)
|
| 912 |
+
|
| 913 |
+
const fastify = Fastify()
|
| 914 |
+
|
| 915 |
+
// Mock getHeader function
|
| 916 |
+
fastify.decorateReply('getHeader', () => ['foo', 'bar'])
|
| 917 |
+
|
| 918 |
+
fastify.register(cors, { origin: true })
|
| 919 |
+
|
| 920 |
+
fastify.get('/', (_req, reply) => {
|
| 921 |
+
reply.send('ok')
|
| 922 |
+
})
|
| 923 |
+
|
| 924 |
+
const res = await fastify.inject({
|
| 925 |
+
method: 'GET',
|
| 926 |
+
url: '/'
|
| 927 |
+
})
|
| 928 |
+
t.assert.ok(res)
|
| 929 |
+
delete res.headers.date
|
| 930 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 931 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 932 |
+
t.assert.strictEqual(res.headers.vary,
|
| 933 |
+
'foo, bar, Origin'
|
| 934 |
+
)
|
| 935 |
+
})
|
| 936 |
+
|
| 937 |
+
test('Allow only request from with specific headers', async t => {
|
| 938 |
+
t.plan(8)
|
| 939 |
+
|
| 940 |
+
const fastify = Fastify()
|
| 941 |
+
fastify.register(cors, {
|
| 942 |
+
allowedHeaders: 'foo',
|
| 943 |
+
exposedHeaders: 'bar'
|
| 944 |
+
})
|
| 945 |
+
|
| 946 |
+
fastify.get('/', (_req, reply) => {
|
| 947 |
+
reply.send('ok')
|
| 948 |
+
})
|
| 949 |
+
|
| 950 |
+
let res = await fastify.inject({
|
| 951 |
+
method: 'OPTIONS',
|
| 952 |
+
url: '/',
|
| 953 |
+
headers: {
|
| 954 |
+
'access-control-request-method': 'GET',
|
| 955 |
+
origin: 'example.com'
|
| 956 |
+
}
|
| 957 |
+
})
|
| 958 |
+
t.assert.ok(res)
|
| 959 |
+
delete res.headers.date
|
| 960 |
+
t.assert.strictEqual(res.statusCode, 204)
|
| 961 |
+
t.assert.deepStrictEqual(res.headers['access-control-allow-headers'],
|
| 962 |
+
'foo'
|
| 963 |
+
)
|
| 964 |
+
t.assert.notDeepEqual(res.headers.vary, 'Origin')
|
| 965 |
+
|
| 966 |
+
res = await fastify.inject({
|
| 967 |
+
method: 'GET',
|
| 968 |
+
url: '/'
|
| 969 |
+
})
|
| 970 |
+
t.assert.ok(res)
|
| 971 |
+
delete res.headers.date
|
| 972 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 973 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 974 |
+
t.assert.strictEqual(res.headers['access-control-expose-headers'],
|
| 975 |
+
'bar'
|
| 976 |
+
)
|
| 977 |
+
})
|
| 978 |
+
|
| 979 |
+
test('Should support wildcard config /1', async t => {
|
| 980 |
+
t.plan(4)
|
| 981 |
+
|
| 982 |
+
const fastify = Fastify()
|
| 983 |
+
fastify.register(cors, { origin: '*' })
|
| 984 |
+
|
| 985 |
+
fastify.get('/', (_req, reply) => {
|
| 986 |
+
reply.send('ok')
|
| 987 |
+
})
|
| 988 |
+
|
| 989 |
+
const res = await fastify.inject({
|
| 990 |
+
method: 'GET',
|
| 991 |
+
url: '/'
|
| 992 |
+
})
|
| 993 |
+
t.assert.ok(res)
|
| 994 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 995 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 996 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'], '*')
|
| 997 |
+
})
|
| 998 |
+
|
| 999 |
+
test('Should support wildcard config /2', async t => {
|
| 1000 |
+
t.plan(4)
|
| 1001 |
+
|
| 1002 |
+
const fastify = Fastify()
|
| 1003 |
+
fastify.register(cors, { origin: ['*'] })
|
| 1004 |
+
|
| 1005 |
+
fastify.get('/', (_req, reply) => {
|
| 1006 |
+
reply.send('ok')
|
| 1007 |
+
})
|
| 1008 |
+
|
| 1009 |
+
const res = await fastify.inject({
|
| 1010 |
+
method: 'GET',
|
| 1011 |
+
url: '/'
|
| 1012 |
+
})
|
| 1013 |
+
t.assert.ok(res)
|
| 1014 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 1015 |
+
t.assert.strictEqual(res.payload, 'ok')
|
| 1016 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'], '*')
|
| 1017 |
+
})
|
| 1018 |
+
|
| 1019 |
+
test('Should allow routes to disable CORS individually', async t => {
|
| 1020 |
+
t.plan(6)
|
| 1021 |
+
|
| 1022 |
+
const fastify = Fastify()
|
| 1023 |
+
fastify.register(cors, { origin: '*' })
|
| 1024 |
+
|
| 1025 |
+
fastify.get('/cors-enabled', (_req, reply) => {
|
| 1026 |
+
reply.send('ok')
|
| 1027 |
+
})
|
| 1028 |
+
|
| 1029 |
+
fastify.get('/cors-disabled', { config: { cors: false } }, (_req, reply) => {
|
| 1030 |
+
reply.send('ok')
|
| 1031 |
+
})
|
| 1032 |
+
|
| 1033 |
+
// Test CORS enabled route
|
| 1034 |
+
let res = await fastify.inject({
|
| 1035 |
+
method: 'GET',
|
| 1036 |
+
url: '/cors-enabled',
|
| 1037 |
+
headers: { origin: 'example.com' }
|
| 1038 |
+
})
|
| 1039 |
+
t.assert.ok(res)
|
| 1040 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 1041 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'], '*')
|
| 1042 |
+
|
| 1043 |
+
// Test CORS disabled route
|
| 1044 |
+
res = await fastify.inject({
|
| 1045 |
+
method: 'GET',
|
| 1046 |
+
url: '/cors-disabled',
|
| 1047 |
+
headers: { origin: 'example.com' }
|
| 1048 |
+
})
|
| 1049 |
+
t.assert.ok(res)
|
| 1050 |
+
t.assert.strictEqual(res.statusCode, 200)
|
| 1051 |
+
t.assert.strictEqual(res.headers['access-control-allow-origin'], undefined)
|
| 1052 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/test/vary.test.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { test } = require('node:test')
|
| 4 |
+
const { createAddFieldnameToVary } = require('../vary')
|
| 5 |
+
const { parse } = require('../vary')
|
| 6 |
+
|
| 7 |
+
test('Should set * even if we set a specific field', async t => {
|
| 8 |
+
t.plan(1)
|
| 9 |
+
|
| 10 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 11 |
+
const replyMock = {
|
| 12 |
+
getHeader () {
|
| 13 |
+
return '*'
|
| 14 |
+
},
|
| 15 |
+
header () {
|
| 16 |
+
t.fail('Should not be here')
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
addOriginToVary(replyMock)
|
| 21 |
+
t.assert.ok(true) // equalivant to tap t.pass()
|
| 22 |
+
})
|
| 23 |
+
|
| 24 |
+
test('Should set * even if we set a specific field', t => {
|
| 25 |
+
t.plan(2)
|
| 26 |
+
|
| 27 |
+
const addWildcardToVary = createAddFieldnameToVary('*')
|
| 28 |
+
const replyMock = {
|
| 29 |
+
getHeader () {
|
| 30 |
+
return 'Origin'
|
| 31 |
+
},
|
| 32 |
+
header (name, value) {
|
| 33 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 34 |
+
t.assert.deepStrictEqual(value, '*')
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
addWildcardToVary(replyMock)
|
| 39 |
+
})
|
| 40 |
+
|
| 41 |
+
test('Should set * when field contains a *', t => {
|
| 42 |
+
t.plan(3)
|
| 43 |
+
|
| 44 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 45 |
+
const replyMock = {
|
| 46 |
+
getHeader () {
|
| 47 |
+
return ['Origin', '*', 'Access-Control-Request-Headers']
|
| 48 |
+
},
|
| 49 |
+
header (name, value) {
|
| 50 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 51 |
+
t.assert.deepStrictEqual(value, '*')
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
addOriginToVary(replyMock)
|
| 56 |
+
t.assert.ok(true) // equalivant to tap t.pass()
|
| 57 |
+
})
|
| 58 |
+
|
| 59 |
+
test('Should concat vary values', t => {
|
| 60 |
+
t.plan(3)
|
| 61 |
+
|
| 62 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 63 |
+
const replyMock = {
|
| 64 |
+
getHeader () {
|
| 65 |
+
return 'Access-Control-Request-Headers'
|
| 66 |
+
},
|
| 67 |
+
header (name, value) {
|
| 68 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 69 |
+
t.assert.deepStrictEqual(value, 'Access-Control-Request-Headers, Origin')
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
addOriginToVary(replyMock)
|
| 74 |
+
t.assert.ok(true) // equalivant to tap t.pass()
|
| 75 |
+
})
|
| 76 |
+
|
| 77 |
+
test('Should concat vary values ignoring consecutive commas', t => {
|
| 78 |
+
t.plan(3)
|
| 79 |
+
|
| 80 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 81 |
+
const replyMock = {
|
| 82 |
+
getHeader () {
|
| 83 |
+
return ' Access-Control-Request-Headers,Access-Control-Request-Method'
|
| 84 |
+
},
|
| 85 |
+
header (name, value) {
|
| 86 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 87 |
+
t.assert.deepStrictEqual(value, ' Access-Control-Request-Headers,Access-Control-Request-Method, Origin')
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
addOriginToVary(replyMock)
|
| 92 |
+
t.assert.ok(true) // equalivant to tap t.pass()
|
| 93 |
+
})
|
| 94 |
+
|
| 95 |
+
test('Should concat vary values ignoring whitespace', t => {
|
| 96 |
+
t.plan(3)
|
| 97 |
+
|
| 98 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 99 |
+
const replyMock = {
|
| 100 |
+
getHeader () {
|
| 101 |
+
return ' Access-Control-Request-Headers ,Access-Control-Request-Method'
|
| 102 |
+
},
|
| 103 |
+
header (name, value) {
|
| 104 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 105 |
+
t.assert.deepStrictEqual(value, ' Access-Control-Request-Headers ,Access-Control-Request-Method, Origin')
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
addOriginToVary(replyMock)
|
| 110 |
+
t.assert.ok(true) // equalivant to tap t.pass()
|
| 111 |
+
})
|
| 112 |
+
|
| 113 |
+
test('Should set the field as value for vary if no vary is defined', t => {
|
| 114 |
+
t.plan(2)
|
| 115 |
+
|
| 116 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 117 |
+
const replyMock = {
|
| 118 |
+
getHeader () {
|
| 119 |
+
return undefined
|
| 120 |
+
},
|
| 121 |
+
header (name, value) {
|
| 122 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 123 |
+
t.assert.deepStrictEqual(value, 'Origin')
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
addOriginToVary(replyMock)
|
| 128 |
+
})
|
| 129 |
+
|
| 130 |
+
test('Should set * as value for vary if vary contains *', t => {
|
| 131 |
+
t.plan(2)
|
| 132 |
+
|
| 133 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 134 |
+
const replyMock = {
|
| 135 |
+
getHeader () {
|
| 136 |
+
return 'Accept,*'
|
| 137 |
+
},
|
| 138 |
+
header (name, value) {
|
| 139 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 140 |
+
t.assert.deepStrictEqual(value, '*')
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
addOriginToVary(replyMock)
|
| 145 |
+
})
|
| 146 |
+
|
| 147 |
+
test('Should set Accept-Encoding as value for vary if vary is empty string', t => {
|
| 148 |
+
t.plan(2)
|
| 149 |
+
|
| 150 |
+
const addAcceptEncodingToVary = createAddFieldnameToVary('Accept-Encoding')
|
| 151 |
+
const replyMock = {
|
| 152 |
+
getHeader () {
|
| 153 |
+
return ''
|
| 154 |
+
},
|
| 155 |
+
header (name, value) {
|
| 156 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 157 |
+
t.assert.deepStrictEqual(value, 'Accept-Encoding')
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
addAcceptEncodingToVary(replyMock)
|
| 162 |
+
})
|
| 163 |
+
|
| 164 |
+
test('Should have no issues with values containing dashes', t => {
|
| 165 |
+
t.plan(2)
|
| 166 |
+
|
| 167 |
+
const addXFooToVary = createAddFieldnameToVary('X-Foo')
|
| 168 |
+
const replyMock = {
|
| 169 |
+
value: 'Accept-Encoding',
|
| 170 |
+
getHeader () {
|
| 171 |
+
return this.value
|
| 172 |
+
},
|
| 173 |
+
header (name, value) {
|
| 174 |
+
t.assert.deepStrictEqual(name, 'Vary')
|
| 175 |
+
t.assert.deepStrictEqual(value, 'Accept-Encoding, X-Foo')
|
| 176 |
+
this.value = value
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
addXFooToVary(replyMock)
|
| 181 |
+
addXFooToVary(replyMock)
|
| 182 |
+
})
|
| 183 |
+
|
| 184 |
+
test('Should ignore the header as value for vary if it is already in vary', t => {
|
| 185 |
+
t.plan(1)
|
| 186 |
+
|
| 187 |
+
const addOriginToVary = createAddFieldnameToVary('Origin')
|
| 188 |
+
const replyMock = {
|
| 189 |
+
getHeader () {
|
| 190 |
+
return 'Origin'
|
| 191 |
+
},
|
| 192 |
+
header () {
|
| 193 |
+
t.fail('Should not be here')
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
addOriginToVary(replyMock)
|
| 197 |
+
addOriginToVary(replyMock)
|
| 198 |
+
|
| 199 |
+
t.assert.ok(true) // equalivant to tap t.pass()
|
| 200 |
+
})
|
| 201 |
+
|
| 202 |
+
test('parse', t => {
|
| 203 |
+
t.plan(18)
|
| 204 |
+
t.assert.deepStrictEqual(parse(''), [])
|
| 205 |
+
t.assert.deepStrictEqual(parse('a'), ['a'])
|
| 206 |
+
t.assert.deepStrictEqual(parse('a,b'), ['a', 'b'])
|
| 207 |
+
t.assert.deepStrictEqual(parse(' a,b'), ['a', 'b'])
|
| 208 |
+
t.assert.deepStrictEqual(parse('a,b '), ['a', 'b'])
|
| 209 |
+
t.assert.deepStrictEqual(parse('a,b,c'), ['a', 'b', 'c'])
|
| 210 |
+
t.assert.deepStrictEqual(parse('A,b,c'), ['a', 'b', 'c'])
|
| 211 |
+
t.assert.deepStrictEqual(parse('a,b,c,'), ['a', 'b', 'c'])
|
| 212 |
+
t.assert.deepStrictEqual(parse('a,b,c, '), ['a', 'b', 'c'])
|
| 213 |
+
t.assert.deepStrictEqual(parse(',a,b,c'), ['a', 'b', 'c'])
|
| 214 |
+
t.assert.deepStrictEqual(parse(' ,a,b,c'), ['a', 'b', 'c'])
|
| 215 |
+
t.assert.deepStrictEqual(parse('a,,b,c'), ['a', 'b', 'c'])
|
| 216 |
+
t.assert.deepStrictEqual(parse('a,,,b,,c'), ['a', 'b', 'c'])
|
| 217 |
+
t.assert.deepStrictEqual(parse('a, b,c'), ['a', 'b', 'c'])
|
| 218 |
+
t.assert.deepStrictEqual(parse('a, b,c'), ['a', 'b', 'c'])
|
| 219 |
+
t.assert.deepStrictEqual(parse('a, , b,c'), ['a', 'b', 'c'])
|
| 220 |
+
t.assert.deepStrictEqual(parse('a, , b,c'), ['a', 'b', 'c'])
|
| 221 |
+
|
| 222 |
+
// one for the cache
|
| 223 |
+
t.assert.deepStrictEqual(parse('A,b,c'), ['a', 'b', 'c'])
|
| 224 |
+
})
|
| 225 |
+
|
| 226 |
+
test('createAddFieldnameToVary', async t => {
|
| 227 |
+
t.plan(4)
|
| 228 |
+
t.assert.strictEqual(typeof createAddFieldnameToVary('valid-header'), 'function')
|
| 229 |
+
await t.assert.rejects(
|
| 230 |
+
async () => createAddFieldnameToVary('invalid:header'),
|
| 231 |
+
(err) => {
|
| 232 |
+
t.assert.strictEqual(err.name, 'TypeError')
|
| 233 |
+
t.assert.strictEqual(err.message, 'Fieldname contains invalid characters.')
|
| 234 |
+
return true
|
| 235 |
+
}
|
| 236 |
+
)
|
| 237 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/cors/types/index.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// <reference types="node" />
|
| 2 |
+
|
| 3 |
+
import { FastifyInstance, FastifyPluginCallback, FastifyRequest, LogLevel } from 'fastify'
|
| 4 |
+
|
| 5 |
+
type OriginCallback = (err: Error | null, origin: ValueOrArray<OriginType>) => void
|
| 6 |
+
type OriginType = string | boolean | RegExp
|
| 7 |
+
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>
|
| 8 |
+
|
| 9 |
+
interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
type FastifyCorsPlugin = FastifyPluginCallback<
|
| 13 |
+
NonNullable<fastifyCors.FastifyCorsOptions> | fastifyCors.FastifyCorsOptionsDelegate
|
| 14 |
+
>
|
| 15 |
+
|
| 16 |
+
type FastifyCorsHook =
|
| 17 |
+
| 'onRequest'
|
| 18 |
+
| 'preParsing'
|
| 19 |
+
| 'preValidation'
|
| 20 |
+
| 'preHandler'
|
| 21 |
+
| 'preSerialization'
|
| 22 |
+
| 'onSend'
|
| 23 |
+
|
| 24 |
+
declare namespace fastifyCors {
|
| 25 |
+
export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void
|
| 26 |
+
export type AsyncOriginFunction = (origin: string | undefined) => Promise<ValueOrArray<OriginType>>
|
| 27 |
+
|
| 28 |
+
export interface FastifyCorsOptions {
|
| 29 |
+
/**
|
| 30 |
+
* Configures the Lifecycle Hook.
|
| 31 |
+
*/
|
| 32 |
+
hook?: FastifyCorsHook;
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Configures the delegate function.
|
| 36 |
+
*/
|
| 37 |
+
delegator?: FastifyCorsOptionsDelegate;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Configures the Access-Control-Allow-Origin CORS header.
|
| 41 |
+
*/
|
| 42 |
+
origin?: ValueOrArray<OriginType> | fastifyCors.AsyncOriginFunction | fastifyCors.OriginFunction;
|
| 43 |
+
/**
|
| 44 |
+
* Configures the Access-Control-Allow-Credentials CORS header.
|
| 45 |
+
* Set to true to pass the header, otherwise it is omitted.
|
| 46 |
+
*/
|
| 47 |
+
credentials?: boolean;
|
| 48 |
+
/**
|
| 49 |
+
* Configures the Access-Control-Expose-Headers CORS header.
|
| 50 |
+
* Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
|
| 51 |
+
* or an array (ex: ['Content-Range', 'X-Content-Range']).
|
| 52 |
+
* If not specified, no custom headers are exposed.
|
| 53 |
+
*/
|
| 54 |
+
exposedHeaders?: string | string[];
|
| 55 |
+
/**
|
| 56 |
+
* Configures the Access-Control-Allow-Headers CORS header.
|
| 57 |
+
* Expects a comma-delimited string (ex: 'Content-Type,Authorization')
|
| 58 |
+
* or an array (ex: ['Content-Type', 'Authorization']). If not
|
| 59 |
+
* specified, defaults to reflecting the headers specified in the
|
| 60 |
+
* request's Access-Control-Request-Headers header.
|
| 61 |
+
*/
|
| 62 |
+
allowedHeaders?: string | string[];
|
| 63 |
+
/**
|
| 64 |
+
* Configures the Access-Control-Allow-Methods CORS header.
|
| 65 |
+
* Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
|
| 66 |
+
*/
|
| 67 |
+
methods?: string | string[];
|
| 68 |
+
/**
|
| 69 |
+
* Configures the Access-Control-Max-Age CORS header.
|
| 70 |
+
* Set to an integer to pass the header, otherwise it is omitted.
|
| 71 |
+
*/
|
| 72 |
+
maxAge?: number;
|
| 73 |
+
/**
|
| 74 |
+
* Configures the Cache-Control header for CORS preflight responses.
|
| 75 |
+
* Set to an integer to pass the header as `Cache-Control: max-age=${cacheControl}`,
|
| 76 |
+
* or set to a string to pass the header as `Cache-Control: ${cacheControl}` (fully define
|
| 77 |
+
* the header value), otherwise the header is omitted.
|
| 78 |
+
*/
|
| 79 |
+
cacheControl?: number | string;
|
| 80 |
+
/**
|
| 81 |
+
* Pass the CORS preflight response to the route handler (default: false).
|
| 82 |
+
*/
|
| 83 |
+
preflightContinue?: boolean;
|
| 84 |
+
/**
|
| 85 |
+
* Provides a status code to use for successful OPTIONS requests,
|
| 86 |
+
* since some legacy browsers (IE11, various SmartTVs) choke on 204.
|
| 87 |
+
*/
|
| 88 |
+
optionsSuccessStatus?: number;
|
| 89 |
+
/**
|
| 90 |
+
* Pass the CORS preflight response to the route handler (default: true).
|
| 91 |
+
*/
|
| 92 |
+
preflight?: boolean;
|
| 93 |
+
/**
|
| 94 |
+
* Enforces strict requirement of the CORS preflight request headers (Access-Control-Request-Method and Origin).
|
| 95 |
+
* Preflight requests without the required headers will result in 400 errors when set to `true` (default: `true`).
|
| 96 |
+
*/
|
| 97 |
+
strictPreflight?: boolean;
|
| 98 |
+
/**
|
| 99 |
+
* Hide options route from the documentation built using fastify-swagger (default: true).
|
| 100 |
+
*/
|
| 101 |
+
hideOptionsRoute?: boolean;
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* Sets the Fastify log level specifically for the internal OPTIONS route
|
| 105 |
+
* used to handle CORS preflight requests. For example, setting this to `'silent'`
|
| 106 |
+
* will prevent these requests from being logged.
|
| 107 |
+
* Useful for reducing noise in application logs.
|
| 108 |
+
* Default: inherits Fastify's global log level.
|
| 109 |
+
*/
|
| 110 |
+
logLevel?: LogLevel;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
export interface FastifyCorsOptionsDelegateCallback { (req: FastifyRequest, cb: (error: Error | null, corsOptions?: FastifyCorsOptions) => void): void }
|
| 114 |
+
export interface FastifyCorsOptionsDelegatePromise { (req: FastifyRequest): Promise<FastifyCorsOptions> }
|
| 115 |
+
export type FastifyCorsOptionsDelegate = FastifyCorsOptionsDelegateCallback | FastifyCorsOptionsDelegatePromise
|
| 116 |
+
export type FastifyPluginOptionsDelegate<T = FastifyCorsOptionsDelegate> = (instance: FastifyInstance) => T
|
| 117 |
+
|
| 118 |
+
export const fastifyCors: FastifyCorsPlugin
|
| 119 |
+
export { fastifyCors as default }
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
declare function fastifyCors (
|
| 123 |
+
...params: Parameters<FastifyCorsPlugin>
|
| 124 |
+
): ReturnType<FastifyCorsPlugin>
|
| 125 |
+
|
| 126 |
+
export = fastifyCors
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/.github/dependabot.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 2
|
| 2 |
+
updates:
|
| 3 |
+
- package-ecosystem: "github-actions"
|
| 4 |
+
directory: "/"
|
| 5 |
+
schedule:
|
| 6 |
+
interval: "monthly"
|
| 7 |
+
open-pull-requests-limit: 10
|
| 8 |
+
|
| 9 |
+
- package-ecosystem: "npm"
|
| 10 |
+
directory: "/"
|
| 11 |
+
schedule:
|
| 12 |
+
interval: "monthly"
|
| 13 |
+
open-pull-requests-limit: 10
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/.github/workflows/ci.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: CI
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
- next
|
| 8 |
+
- 'v*'
|
| 9 |
+
paths-ignore:
|
| 10 |
+
- 'docs/**'
|
| 11 |
+
- '*.md'
|
| 12 |
+
pull_request:
|
| 13 |
+
paths-ignore:
|
| 14 |
+
- 'docs/**'
|
| 15 |
+
- '*.md'
|
| 16 |
+
|
| 17 |
+
permissions:
|
| 18 |
+
contents: read
|
| 19 |
+
|
| 20 |
+
jobs:
|
| 21 |
+
test:
|
| 22 |
+
permissions:
|
| 23 |
+
contents: write
|
| 24 |
+
pull-requests: write
|
| 25 |
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
|
| 26 |
+
with:
|
| 27 |
+
license-check: true
|
| 28 |
+
lint: true
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/create.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const benchmark = require('benchmark')
|
| 4 |
+
const createError = require('..')
|
| 5 |
+
|
| 6 |
+
new benchmark.Suite()
|
| 7 |
+
.add('create FastifyError', function () { createError('CODE', 'Not available') }, { minSamples: 100 })
|
| 8 |
+
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
|
| 9 |
+
.run({ async: false })
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/instantiate.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const benchmark = require('benchmark')
|
| 4 |
+
const createError = require('..')
|
| 5 |
+
|
| 6 |
+
const FastifyError = createError('CODE', 'Not available')
|
| 7 |
+
const FastifyError1 = createError('CODE', 'Not %s available')
|
| 8 |
+
const FastifyError2 = createError('CODE', 'Not %s available %s')
|
| 9 |
+
|
| 10 |
+
const cause = new Error('cause')
|
| 11 |
+
new benchmark.Suite()
|
| 12 |
+
.add('instantiate Error', function () { new Error() }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 13 |
+
.add('instantiate FastifyError', function () { new FastifyError() }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 14 |
+
.add('instantiate FastifyError arg 1', function () { new FastifyError1('q') }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 15 |
+
.add('instantiate FastifyError arg 2', function () { new FastifyError2('qq', 'ss') }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 16 |
+
.add('instantiate FastifyError cause', function () { new FastifyError2({ cause }) }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 17 |
+
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
|
| 18 |
+
.run({ async: false })
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/no-stack.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const benchmark = require('benchmark')
|
| 4 |
+
const createError = require('..')
|
| 5 |
+
|
| 6 |
+
const FastifyError = createError('CODE', 'Not available')
|
| 7 |
+
Error.stackTraceLimit = 0
|
| 8 |
+
|
| 9 |
+
new benchmark.Suite()
|
| 10 |
+
.add('no-stack instantiate Error', function () { new Error() }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 11 |
+
.add('no-stack instantiate FastifyError', function () { new FastifyError() }, { minSamples: 100 }) // eslint-disable-line no-new
|
| 12 |
+
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
|
| 13 |
+
.run({ async: false })
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/benchmarks/toString.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const benchmark = require('benchmark')
|
| 4 |
+
const createError = require('..')
|
| 5 |
+
|
| 6 |
+
const FastifyError = createError('CODE', 'Not available')
|
| 7 |
+
|
| 8 |
+
new benchmark.Suite()
|
| 9 |
+
.add('FastifyError toString', function () { new FastifyError().toString() }, { minSamples: 100 })
|
| 10 |
+
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
|
| 11 |
+
.run({ async: false })
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/test/instanceof.test.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const cp = require('node:child_process')
|
| 4 |
+
const fs = require('node:fs')
|
| 5 |
+
const path = require('node:path')
|
| 6 |
+
const os = require('node:os')
|
| 7 |
+
const test = require('node:test')
|
| 8 |
+
const { createError, FastifyError } = require('..')
|
| 9 |
+
|
| 10 |
+
test('Readme: All errors created with `createError` will be instances of the base error constructor you provided, or `Error` if none was provided.', (t) => {
|
| 11 |
+
t.plan(3)
|
| 12 |
+
|
| 13 |
+
const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
|
| 14 |
+
const customError = new CustomError('world')
|
| 15 |
+
|
| 16 |
+
t.assert.ok(customError instanceof CustomError)
|
| 17 |
+
t.assert.ok(customError instanceof TypeError)
|
| 18 |
+
t.assert.ok(customError instanceof Error)
|
| 19 |
+
})
|
| 20 |
+
|
| 21 |
+
test('Readme: All instantiated errors will be instances of the `FastifyError` class. The `FastifyError` class can be required from the module directly.', (t) => {
|
| 22 |
+
t.plan(1)
|
| 23 |
+
|
| 24 |
+
const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
|
| 25 |
+
const customError = new CustomError('world')
|
| 26 |
+
|
| 27 |
+
t.assert.ok(customError instanceof FastifyError)
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
test('Readme: It is possible to create a `FastifyError` that extends another `FastifyError`, created by `createError`, while instanceof working correctly.', (t) => {
|
| 31 |
+
t.plan(5)
|
| 32 |
+
|
| 33 |
+
const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
|
| 34 |
+
const ChildCustomError = createError('CHILD_ERROR_CODE', 'Hello %s', 500, CustomError)
|
| 35 |
+
|
| 36 |
+
const customError = new ChildCustomError('world')
|
| 37 |
+
|
| 38 |
+
t.assert.ok(customError instanceof ChildCustomError)
|
| 39 |
+
t.assert.ok(customError instanceof CustomError)
|
| 40 |
+
t.assert.ok(customError instanceof FastifyError)
|
| 41 |
+
t.assert.ok(customError instanceof TypeError)
|
| 42 |
+
t.assert.ok(customError instanceof Error)
|
| 43 |
+
})
|
| 44 |
+
|
| 45 |
+
test('Readme: Changing the code of an instantiated Error will not change the result of the `instanceof` operator.', (t) => {
|
| 46 |
+
t.plan(3)
|
| 47 |
+
|
| 48 |
+
const CustomError = createError('ERROR_CODE', 'Hello %s', 500, TypeError)
|
| 49 |
+
const AnotherCustomError = createError('ANOTHER_ERROR_CODE', 'Hello %s', 500, CustomError)
|
| 50 |
+
|
| 51 |
+
const customError = new CustomError('world')
|
| 52 |
+
customError.code = 'ANOTHER_ERROR_CODE'
|
| 53 |
+
|
| 54 |
+
t.assert.ok(customError instanceof CustomError)
|
| 55 |
+
t.assert.ok(customError instanceof AnotherCustomError === false)
|
| 56 |
+
t.assert.ok(customError instanceof FastifyError)
|
| 57 |
+
})
|
| 58 |
+
|
| 59 |
+
test('check if createError creates an Error which is instanceof Error', (t) => {
|
| 60 |
+
t.plan(3)
|
| 61 |
+
|
| 62 |
+
const CustomFastifyError = createError('CODE', 'Not available')
|
| 63 |
+
const err = CustomFastifyError()
|
| 64 |
+
|
| 65 |
+
t.assert.ok(err instanceof Error)
|
| 66 |
+
t.assert.ok(err instanceof SyntaxError === false)
|
| 67 |
+
t.assert.ok(err instanceof TypeError === false)
|
| 68 |
+
})
|
| 69 |
+
|
| 70 |
+
test('check if createError creates an Error which is instanceof FastifyError', (t) => {
|
| 71 |
+
t.plan(4)
|
| 72 |
+
|
| 73 |
+
const CustomFastifyError = createError('CODE', 'Not available')
|
| 74 |
+
const err = CustomFastifyError()
|
| 75 |
+
|
| 76 |
+
t.assert.ok(err instanceof Error)
|
| 77 |
+
t.assert.ok(err instanceof FastifyError)
|
| 78 |
+
t.assert.ok(err instanceof SyntaxError === false)
|
| 79 |
+
t.assert.ok(err instanceof TypeError === false)
|
| 80 |
+
})
|
| 81 |
+
|
| 82 |
+
test('check if createError creates an Error with the right BaseConstructor', (t) => {
|
| 83 |
+
t.plan(2)
|
| 84 |
+
|
| 85 |
+
const CustomFastifyError = createError('CODE', 'Not available', 500, TypeError)
|
| 86 |
+
const err = CustomFastifyError()
|
| 87 |
+
|
| 88 |
+
t.assert.ok(err instanceof Error)
|
| 89 |
+
t.assert.ok(err instanceof TypeError)
|
| 90 |
+
})
|
| 91 |
+
|
| 92 |
+
test('check if createError creates an Error with the right BaseConstructor, which is a FastifyError', (t) => {
|
| 93 |
+
t.plan(6)
|
| 94 |
+
|
| 95 |
+
const BaseFastifyError = createError('CODE', 'Not available', 500, TypeError)
|
| 96 |
+
const CustomFastifyError = createError('CODE', 'Not available', 500, BaseFastifyError)
|
| 97 |
+
const err = CustomFastifyError()
|
| 98 |
+
|
| 99 |
+
t.assert.ok(err instanceof Error)
|
| 100 |
+
t.assert.ok(err instanceof TypeError)
|
| 101 |
+
t.assert.ok(err instanceof FastifyError)
|
| 102 |
+
t.assert.ok(err instanceof BaseFastifyError)
|
| 103 |
+
t.assert.ok(err instanceof CustomFastifyError)
|
| 104 |
+
t.assert.ok(err instanceof SyntaxError === false)
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
// for more information see https://github.com/fastify/fastify-error/pull/86#issuecomment-1301466407
|
| 108 |
+
test('ensure that instanceof works accross different installations of the fastify-error module', async (t) => {
|
| 109 |
+
const assertsPlanned = 5
|
| 110 |
+
t.plan(assertsPlanned)
|
| 111 |
+
|
| 112 |
+
// We need to create a test environment where fastify-error is installed in two different locations
|
| 113 |
+
// and then we will check if the error created in one location is instanceof the error created in the other location
|
| 114 |
+
// This is done by creating a test directory with the following structure:
|
| 115 |
+
|
| 116 |
+
// /
|
| 117 |
+
// ├── index.js
|
| 118 |
+
// └── node_modules/
|
| 119 |
+
// ├── fastify-error/
|
| 120 |
+
// │ └── index.js
|
| 121 |
+
// └── dep/
|
| 122 |
+
// ├── index.js
|
| 123 |
+
// └── node_modules/
|
| 124 |
+
// └── fastify-error/
|
| 125 |
+
// └── index.js
|
| 126 |
+
|
| 127 |
+
const testDirectoryPrefix = 'fastify-error-instanceof-test-'
|
| 128 |
+
|
| 129 |
+
const testCwd = path.resolve(os.tmpdir(), `${testDirectoryPrefix}${Math.random().toString(36).substring(2, 15)}`)
|
| 130 |
+
fs.mkdirSync(testCwd, { recursive: true })
|
| 131 |
+
|
| 132 |
+
// Create the index.js. It will be executed as a forked process, so we need to
|
| 133 |
+
// use process.send to send messages back to the parent process.
|
| 134 |
+
fs.writeFileSync(path.resolve(testCwd, 'index.js'), `
|
| 135 |
+
'use strict'
|
| 136 |
+
|
| 137 |
+
const path = require('node:path')
|
| 138 |
+
const { createError, FastifyError } = require('fastify-error')
|
| 139 |
+
const { foo } = require('dep')
|
| 140 |
+
|
| 141 |
+
const actualPathOfFastifyError = require.resolve('fastify-error')
|
| 142 |
+
const expectedPathOfFastifyError = path.resolve('node_modules', 'fastify-error', 'index.js')
|
| 143 |
+
|
| 144 |
+
// Ensure that fastify-error is required from the node_modules directory of the test-project
|
| 145 |
+
if (actualPathOfFastifyError !== expectedPathOfFastifyError) {
|
| 146 |
+
console.error('actualPathOfFastifyError', actualPathOfFastifyError)
|
| 147 |
+
console.error('expectedPathOfFastifyError', expectedPathOfFastifyError)
|
| 148 |
+
throw new Error('fastify-error should be required from the node_modules directory of the test-project')
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
const Boom = createError('Boom', 'Boom', 500)
|
| 152 |
+
const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
|
| 153 |
+
const NotChildBoom = createError('NotChildBoom', 'NotChildBoom', 500, Boom)
|
| 154 |
+
|
| 155 |
+
try {
|
| 156 |
+
foo()
|
| 157 |
+
} catch (err) {
|
| 158 |
+
process.send(err instanceof Error)
|
| 159 |
+
process.send(err instanceof FastifyError)
|
| 160 |
+
process.send(err instanceof NotChildBoom)
|
| 161 |
+
process.send(err instanceof Boom)
|
| 162 |
+
process.send(err instanceof ChildBoom)
|
| 163 |
+
}
|
| 164 |
+
`)
|
| 165 |
+
|
| 166 |
+
// Create /node_modules/fastify-error directory
|
| 167 |
+
// Copy the index.js file to the fastify-error directory
|
| 168 |
+
fs.mkdirSync(path.resolve(testCwd, 'node_modules', 'fastify-error'), { recursive: true })
|
| 169 |
+
fs.copyFileSync(path.resolve(process.cwd(), 'index.js'), path.resolve(testCwd, 'node_modules', 'fastify-error', 'index.js'))
|
| 170 |
+
|
| 171 |
+
// Create /node_modules/dep/node_modules/fastify-error directory
|
| 172 |
+
// Copy the index.js to the fastify-error directory
|
| 173 |
+
fs.mkdirSync(path.resolve(testCwd, 'node_modules', 'dep', 'node_modules', 'fastify-error'), { recursive: true })
|
| 174 |
+
fs.copyFileSync(path.resolve(process.cwd(), 'index.js'), path.resolve(testCwd, 'node_modules', 'dep', 'node_modules', 'fastify-error', 'index.js'))
|
| 175 |
+
|
| 176 |
+
// Create /node_modules/dep/index.js. It will export a function foo which will
|
| 177 |
+
// throw an error when called. The error will be an instance of ChildBoom, created
|
| 178 |
+
// by the fastify-error module in the node_modules directory of dep.
|
| 179 |
+
fs.writeFileSync(path.resolve(testCwd, 'node_modules', 'dep', 'index.js'), `
|
| 180 |
+
'use strict'
|
| 181 |
+
|
| 182 |
+
const path = require('node:path')
|
| 183 |
+
const { createError } = require('fastify-error')
|
| 184 |
+
|
| 185 |
+
const actualPathOfFastifyError = require.resolve('fastify-error')
|
| 186 |
+
const expectedPathOfFastifyError = path.resolve('node_modules', 'dep', 'node_modules', 'fastify-error', 'index.js')
|
| 187 |
+
|
| 188 |
+
// Ensure that fastify-error is required from the node_modules directory of the test-project
|
| 189 |
+
if (actualPathOfFastifyError !== expectedPathOfFastifyError) {
|
| 190 |
+
console.error('actualPathOfFastifyError', actualPathOfFastifyError)
|
| 191 |
+
console.error('expectedPathOfFastifyError', expectedPathOfFastifyError)
|
| 192 |
+
throw new Error('fastify-error should be required from the node_modules directory of dep')
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
const Boom = createError('Boom', 'Boom', 500)
|
| 196 |
+
const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
|
| 197 |
+
|
| 198 |
+
module.exports.foo = function foo () {
|
| 199 |
+
throw new ChildBoom('foo go Boom')
|
| 200 |
+
}
|
| 201 |
+
`)
|
| 202 |
+
|
| 203 |
+
const finishedPromise = {
|
| 204 |
+
promise: undefined,
|
| 205 |
+
reject: undefined,
|
| 206 |
+
resolve: undefined,
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
finishedPromise.promise = new Promise((resolve, reject) => {
|
| 210 |
+
finishedPromise.resolve = resolve
|
| 211 |
+
finishedPromise.reject = reject
|
| 212 |
+
})
|
| 213 |
+
|
| 214 |
+
const child = cp.fork(path.resolve(testCwd, 'index.js'), {
|
| 215 |
+
cwd: testCwd,
|
| 216 |
+
stdio: 'inherit',
|
| 217 |
+
env: {
|
| 218 |
+
...process.env,
|
| 219 |
+
NODE_OPTIONS: '--no-warnings'
|
| 220 |
+
},
|
| 221 |
+
})
|
| 222 |
+
|
| 223 |
+
let messageCount = 0
|
| 224 |
+
child.on('message', message => {
|
| 225 |
+
try {
|
| 226 |
+
switch (messageCount) {
|
| 227 |
+
case 0:
|
| 228 |
+
t.assert.strictEqual(message, true, 'instanceof Error')
|
| 229 |
+
break
|
| 230 |
+
case 1:
|
| 231 |
+
t.assert.strictEqual(message, true, 'instanceof FastifyError')
|
| 232 |
+
break
|
| 233 |
+
case 2:
|
| 234 |
+
t.assert.strictEqual(message, false, 'instanceof NotChildBoom')
|
| 235 |
+
break
|
| 236 |
+
case 3:
|
| 237 |
+
t.assert.strictEqual(message, true, 'instanceof Boom')
|
| 238 |
+
break
|
| 239 |
+
case 4:
|
| 240 |
+
t.assert.strictEqual(message, true, 'instanceof ChildBoom')
|
| 241 |
+
break
|
| 242 |
+
}
|
| 243 |
+
if (++messageCount === assertsPlanned) {
|
| 244 |
+
finishedPromise.resolve()
|
| 245 |
+
}
|
| 246 |
+
} catch (err) {
|
| 247 |
+
finishedPromise.reject(err)
|
| 248 |
+
}
|
| 249 |
+
})
|
| 250 |
+
|
| 251 |
+
child.on('error', err => {
|
| 252 |
+
finishedPromise.reject(err)
|
| 253 |
+
})
|
| 254 |
+
|
| 255 |
+
await finishedPromise.promise
|
| 256 |
+
|
| 257 |
+
// Cleanup
|
| 258 |
+
// As we are creating the test-setup on the fly in the /tmp directory, we can remove it
|
| 259 |
+
// safely when we are done. It is not relevant for the test if the deletion fails.
|
| 260 |
+
try {
|
| 261 |
+
fs.rmSync(testCwd, { recursive: true, force: true })
|
| 262 |
+
} catch {}
|
| 263 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/types/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?]> (
|
| 2 |
+
code: C,
|
| 3 |
+
message: string,
|
| 4 |
+
statusCode: SC,
|
| 5 |
+
Base?: ErrorConstructor,
|
| 6 |
+
captureStackTrace?: boolean
|
| 7 |
+
): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }, Arg>
|
| 8 |
+
|
| 9 |
+
declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?]> (
|
| 10 |
+
code: C,
|
| 11 |
+
message: string,
|
| 12 |
+
statusCode?: number,
|
| 13 |
+
Base?: ErrorConstructor,
|
| 14 |
+
captureStackTrace?: boolean
|
| 15 |
+
): createError.FastifyErrorConstructor<{ code: C }, Arg>
|
| 16 |
+
|
| 17 |
+
declare function createError<Arg extends unknown[] = [any?, any?, any?]> (
|
| 18 |
+
code: string,
|
| 19 |
+
message: string,
|
| 20 |
+
statusCode?: number,
|
| 21 |
+
Base?: ErrorConstructor,
|
| 22 |
+
captureStackTrace?: boolean
|
| 23 |
+
): createError.FastifyErrorConstructor<{ code: string }, Arg>
|
| 24 |
+
|
| 25 |
+
type CreateError = typeof createError
|
| 26 |
+
|
| 27 |
+
declare namespace createError {
|
| 28 |
+
export interface FastifyError extends Error {
|
| 29 |
+
code: string
|
| 30 |
+
name: string
|
| 31 |
+
statusCode?: number
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
export interface FastifyErrorConstructor<
|
| 35 |
+
E extends { code: string, statusCode?: number } = { code: string, statusCode?: number },
|
| 36 |
+
T extends unknown[] = [any?, any?, any?]
|
| 37 |
+
> {
|
| 38 |
+
new(...arg: T): FastifyError & E
|
| 39 |
+
(...arg: T): FastifyError & E
|
| 40 |
+
readonly prototype: FastifyError & E
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export const FastifyError: FastifyErrorConstructor
|
| 44 |
+
|
| 45 |
+
export const createError: CreateError
|
| 46 |
+
export { createError as default }
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export = createError
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/error/types/index.test-d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import createError, { FastifyError, FastifyErrorConstructor } from '..'
|
| 2 |
+
import { expectType, expectError } from 'tsd'
|
| 3 |
+
|
| 4 |
+
const CustomError = createError('ERROR_CODE', 'message')
|
| 5 |
+
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomError)
|
| 6 |
+
const err = new CustomError()
|
| 7 |
+
expectType<FastifyError & { code: 'ERROR_CODE' }>(err)
|
| 8 |
+
expectType<'ERROR_CODE'>(err.code)
|
| 9 |
+
expectType<string>(err.message)
|
| 10 |
+
expectType<number | undefined>(err.statusCode)
|
| 11 |
+
|
| 12 |
+
const CustomErrorNoStackTrace = createError('ERROR_CODE', 'message', undefined, undefined, false)
|
| 13 |
+
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomErrorNoStackTrace)
|
| 14 |
+
const errNoStackTrace = new CustomErrorNoStackTrace()
|
| 15 |
+
expectType<FastifyError & { code: 'ERROR_CODE' }>(errNoStackTrace)
|
| 16 |
+
expectType<'ERROR_CODE'>(errNoStackTrace.code)
|
| 17 |
+
expectType<string>(errNoStackTrace.message)
|
| 18 |
+
expectType<number | undefined>(errNoStackTrace.statusCode)
|
| 19 |
+
|
| 20 |
+
const CustomTypedError = createError('OTHER_CODE', 'message', 400)
|
| 21 |
+
expectType<FastifyErrorConstructor<{ code: 'OTHER_CODE', statusCode: 400 }>>(CustomTypedError)
|
| 22 |
+
const typed = new CustomTypedError()
|
| 23 |
+
expectType<FastifyError & { code: 'OTHER_CODE', statusCode: 400 }>(typed)
|
| 24 |
+
expectType<'OTHER_CODE'>(typed.code)
|
| 25 |
+
expectType<string>(typed.message)
|
| 26 |
+
expectType<400>(typed.statusCode)
|
| 27 |
+
|
| 28 |
+
/* eslint-disable no-new */
|
| 29 |
+
const CustomTypedArgError = createError<[string]>('OTHER_CODE', 'expect %s message', 400)
|
| 30 |
+
CustomTypedArgError('a')
|
| 31 |
+
expectError(CustomTypedArgError('a', 'b'))
|
| 32 |
+
expectError(new CustomTypedArgError('a', 'b'))
|
| 33 |
+
expectError(CustomTypedArgError(1))
|
| 34 |
+
expectError(new CustomTypedArgError(1))
|
| 35 |
+
|
| 36 |
+
const CustomTypedArgError2 = createError<string, number, [string]>('OTHER_CODE', 'expect %s message', 400)
|
| 37 |
+
CustomTypedArgError2('a')
|
| 38 |
+
expectError(CustomTypedArgError2('a', 'b'))
|
| 39 |
+
expectError(new CustomTypedArgError2('a', 'b'))
|
| 40 |
+
expectError(CustomTypedArgError2(1))
|
| 41 |
+
expectError(new CustomTypedArgError2(1))
|
| 42 |
+
|
| 43 |
+
const CustomTypedArgError3 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
|
| 44 |
+
expectError(CustomTypedArgError3('a'))
|
| 45 |
+
CustomTypedArgError3('a', 'b')
|
| 46 |
+
new CustomTypedArgError3('a', 'b')
|
| 47 |
+
expectError(CustomTypedArgError3(1))
|
| 48 |
+
expectError(new CustomTypedArgError3(1))
|
| 49 |
+
expectError(new CustomTypedArgError3(1, 2))
|
| 50 |
+
expectError(new CustomTypedArgError3('1', 2))
|
| 51 |
+
expectError(new CustomTypedArgError3(1, '2'))
|
| 52 |
+
|
| 53 |
+
const CustomTypedArgError4 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
|
| 54 |
+
expectError(CustomTypedArgError4('a'))
|
| 55 |
+
CustomTypedArgError4('a', 'b')
|
| 56 |
+
new CustomTypedArgError4('a', 'b')
|
| 57 |
+
expectError(CustomTypedArgError4(1))
|
| 58 |
+
expectError(new CustomTypedArgError4(1))
|
| 59 |
+
expectError(new CustomTypedArgError4(1, 2))
|
| 60 |
+
expectError(new CustomTypedArgError4('1', 2))
|
| 61 |
+
expectError(new CustomTypedArgError4(1, '2'))
|
| 62 |
+
|
| 63 |
+
const CustomTypedArgError5 = createError<[string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
|
| 64 |
+
expectError(CustomTypedArgError5('a'))
|
| 65 |
+
expectError(new CustomTypedArgError5('a', 'b'))
|
| 66 |
+
expectError(new CustomTypedArgError5('a', 'b', 'c'))
|
| 67 |
+
CustomTypedArgError5('a', 'b', 'c', 'd')
|
| 68 |
+
expectError(new CustomTypedArgError5('a', 'b', 'c', 'd', 'e'))
|
| 69 |
+
|
| 70 |
+
const CustomTypedArgError6 = createError<string, number, [string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
|
| 71 |
+
expectError(CustomTypedArgError6('a'))
|
| 72 |
+
expectError(new CustomTypedArgError6('a', 'b'))
|
| 73 |
+
expectError(new CustomTypedArgError6('a', 'b', 'c'))
|
| 74 |
+
CustomTypedArgError6('a', 'b', 'c', 'd')
|
| 75 |
+
expectError(new CustomTypedArgError6('a', 'b', 'c', 'd', 'e'))
|
| 76 |
+
|
| 77 |
+
const CustomErrorWithErrorConstructor = createError('ERROR_CODE', 'message', 500, TypeError)
|
| 78 |
+
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE', statusCode: 500 }>>(CustomErrorWithErrorConstructor)
|
| 79 |
+
CustomErrorWithErrorConstructor({ cause: new Error('Error') })
|
| 80 |
+
const customErrorWithErrorConstructor = CustomErrorWithErrorConstructor()
|
| 81 |
+
if (customErrorWithErrorConstructor instanceof FastifyError) {
|
| 82 |
+
expectType<'ERROR_CODE'>(customErrorWithErrorConstructor.code)
|
| 83 |
+
expectType<string>(customErrorWithErrorConstructor.message)
|
| 84 |
+
expectType<500>(customErrorWithErrorConstructor.statusCode)
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
const error = new FastifyError('ERROR_CODE', 'message', 500)
|
| 88 |
+
if (error instanceof FastifyError) {
|
| 89 |
+
expectType<string>(error.code)
|
| 90 |
+
expectType<string>(error.message)
|
| 91 |
+
expectType<number | undefined>(error.statusCode)
|
| 92 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"extends": "standard"}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Set default behavior to automatically convert line endings
|
| 2 |
+
* text=auto eol=lf
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: CI
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
- next
|
| 8 |
+
- 'v*'
|
| 9 |
+
paths-ignore:
|
| 10 |
+
- 'docs/**'
|
| 11 |
+
- '*.md'
|
| 12 |
+
pull_request:
|
| 13 |
+
paths-ignore:
|
| 14 |
+
- 'docs/**'
|
| 15 |
+
- '*.md'
|
| 16 |
+
|
| 17 |
+
permissions:
|
| 18 |
+
contents: read
|
| 19 |
+
|
| 20 |
+
jobs:
|
| 21 |
+
test:
|
| 22 |
+
permissions:
|
| 23 |
+
contents: write
|
| 24 |
+
pull-requests: write
|
| 25 |
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
|
| 26 |
+
with:
|
| 27 |
+
license-check: true
|
| 28 |
+
lint: true
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const { SerializerSelector, StandaloneSerializer } = require('./standalone')
|
| 4 |
+
|
| 5 |
+
module.exports = SerializerSelector
|
| 6 |
+
module.exports.default = SerializerSelector
|
| 7 |
+
module.exports.SerializerSelector = SerializerSelector
|
| 8 |
+
module.exports.StandaloneSerializer = StandaloneSerializer
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@fastify/fast-json-stringify-compiler",
|
| 3 |
+
"description": "Build and manage the fast-json-stringify instances for the fastify framework",
|
| 4 |
+
"version": "5.0.3",
|
| 5 |
+
"main": "index.js",
|
| 6 |
+
"type": "commonjs",
|
| 7 |
+
"types": "types/index.d.ts",
|
| 8 |
+
"scripts": {
|
| 9 |
+
"lint": "eslint",
|
| 10 |
+
"lint:fix": "eslint --fix",
|
| 11 |
+
"unit": "c8 --100 node --test",
|
| 12 |
+
"test": "npm run unit && npm run test:typescript",
|
| 13 |
+
"test:typescript": "tsd"
|
| 14 |
+
},
|
| 15 |
+
"repository": {
|
| 16 |
+
"type": "git",
|
| 17 |
+
"url": "git+https://github.com/fastify/fast-json-stringify-compiler.git"
|
| 18 |
+
},
|
| 19 |
+
"keywords": [],
|
| 20 |
+
"author": "Manuel Spigolon <manuel.spigolon@nearform.com> (https://github.com/Eomm)",
|
| 21 |
+
"contributors": [
|
| 22 |
+
{
|
| 23 |
+
"name": "Matteo Collina",
|
| 24 |
+
"email": "hello@matteocollina.com"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "Aras Abbasi",
|
| 28 |
+
"email": "aras.abbasi@gmail.com"
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"name": "James Sumners",
|
| 32 |
+
"url": "https://james.sumners.info"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"name": "Frazer Smith",
|
| 36 |
+
"email": "frazer.dev@icloud.com",
|
| 37 |
+
"url": "https://github.com/fdawgs"
|
| 38 |
+
}
|
| 39 |
+
],
|
| 40 |
+
"license": "MIT",
|
| 41 |
+
"bugs": {
|
| 42 |
+
"url": "https://github.com/fastify/fast-json-stringify-compiler/issues"
|
| 43 |
+
},
|
| 44 |
+
"homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme",
|
| 45 |
+
"funding": [
|
| 46 |
+
{
|
| 47 |
+
"type": "github",
|
| 48 |
+
"url": "https://github.com/sponsors/fastify"
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"type": "opencollective",
|
| 52 |
+
"url": "https://opencollective.com/fastify"
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"devDependencies": {
|
| 56 |
+
"@fastify/pre-commit": "^2.1.0",
|
| 57 |
+
"c8": "^10.1.3",
|
| 58 |
+
"eslint": "^9.17.0",
|
| 59 |
+
"fastify": "^5.0.0",
|
| 60 |
+
"neostandard": "^0.12.0",
|
| 61 |
+
"sanitize-filename": "^1.6.3",
|
| 62 |
+
"tsd": "^0.31.0"
|
| 63 |
+
},
|
| 64 |
+
"pre-commit": [
|
| 65 |
+
"lint",
|
| 66 |
+
"test"
|
| 67 |
+
],
|
| 68 |
+
"dependencies": {
|
| 69 |
+
"fast-json-stringify": "^6.0.0"
|
| 70 |
+
}
|
| 71 |
+
}
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/test/standalone.test.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict'
|
| 2 |
+
|
| 3 |
+
const fs = require('node:fs')
|
| 4 |
+
const path = require('node:path')
|
| 5 |
+
const { test } = require('node:test')
|
| 6 |
+
const fastify = require('fastify')
|
| 7 |
+
const sanitize = require('sanitize-filename')
|
| 8 |
+
|
| 9 |
+
const { StandaloneSerializer: FjsStandaloneCompiler } = require('../')
|
| 10 |
+
|
| 11 |
+
const generatedFileNames = []
|
| 12 |
+
|
| 13 |
+
function generateFileName (routeOpts) {
|
| 14 |
+
const fileName = `/fjs-generated-${sanitize(routeOpts.schema.$id)}-${routeOpts.method}-${routeOpts.httpPart}-${sanitize(routeOpts.url)}.js`
|
| 15 |
+
generatedFileNames.push(fileName)
|
| 16 |
+
return fileName
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
test('standalone', async t => {
|
| 20 |
+
t.plan(5)
|
| 21 |
+
|
| 22 |
+
t.after(async () => {
|
| 23 |
+
for (const fileName of generatedFileNames) {
|
| 24 |
+
try {
|
| 25 |
+
await fs.promises.unlink(path.join(__dirname, fileName))
|
| 26 |
+
} catch {}
|
| 27 |
+
}
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
t.test('errors', t => {
|
| 31 |
+
t.plan(2)
|
| 32 |
+
t.assert.throws(() => {
|
| 33 |
+
FjsStandaloneCompiler()
|
| 34 |
+
}, 'missing restoreFunction')
|
| 35 |
+
t.assert.throws(() => {
|
| 36 |
+
FjsStandaloneCompiler({ readMode: false })
|
| 37 |
+
}, 'missing storeFunction')
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
t.test('generate standalone code', t => {
|
| 41 |
+
t.plan(5)
|
| 42 |
+
|
| 43 |
+
const base = {
|
| 44 |
+
$id: 'urn:schema:base',
|
| 45 |
+
definitions: {
|
| 46 |
+
hello: { type: 'string' }
|
| 47 |
+
},
|
| 48 |
+
type: 'object',
|
| 49 |
+
properties: {
|
| 50 |
+
hello: { $ref: '#/definitions/hello' }
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const refSchema = {
|
| 55 |
+
$id: 'urn:schema:ref',
|
| 56 |
+
type: 'object',
|
| 57 |
+
properties: {
|
| 58 |
+
hello: { $ref: 'urn:schema:base#/definitions/hello' }
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
const endpointSchema = {
|
| 63 |
+
schema: {
|
| 64 |
+
$id: 'urn:schema:endpoint',
|
| 65 |
+
$ref: 'urn:schema:ref'
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
const schemaMap = {
|
| 70 |
+
[base.$id]: base,
|
| 71 |
+
[refSchema.$id]: refSchema
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
const factory = FjsStandaloneCompiler({
|
| 75 |
+
readMode: false,
|
| 76 |
+
storeFunction (routeOpts, schemaSerializerCode) {
|
| 77 |
+
t.assert.deepStrictEqual(routeOpts, endpointSchema)
|
| 78 |
+
t.assert.ok(typeof schemaSerializerCode === 'string')
|
| 79 |
+
fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode)
|
| 80 |
+
generatedFileNames.push('/fjs-generated.js')
|
| 81 |
+
t.assert.ok('stored the serializer function')
|
| 82 |
+
}
|
| 83 |
+
})
|
| 84 |
+
|
| 85 |
+
const compiler = factory(schemaMap)
|
| 86 |
+
compiler(endpointSchema)
|
| 87 |
+
t.assert.ok('compiled the endpoint schema')
|
| 88 |
+
|
| 89 |
+
t.test('usage standalone code', t => {
|
| 90 |
+
t.plan(3)
|
| 91 |
+
const standaloneSerializer = require('./fjs-generated')
|
| 92 |
+
t.assert.ok(standaloneSerializer)
|
| 93 |
+
|
| 94 |
+
const valid = standaloneSerializer({ hello: 'world' })
|
| 95 |
+
t.assert.deepStrictEqual(valid, JSON.stringify({ hello: 'world' }))
|
| 96 |
+
|
| 97 |
+
const invalid = standaloneSerializer({ hello: [] })
|
| 98 |
+
t.assert.deepStrictEqual(invalid, '{"hello":""}')
|
| 99 |
+
})
|
| 100 |
+
})
|
| 101 |
+
|
| 102 |
+
t.test('fastify integration - writeMode', async t => {
|
| 103 |
+
t.plan(4)
|
| 104 |
+
|
| 105 |
+
const factory = FjsStandaloneCompiler({
|
| 106 |
+
readMode: false,
|
| 107 |
+
storeFunction (routeOpts, schemaSerializationCode) {
|
| 108 |
+
const fileName = generateFileName(routeOpts)
|
| 109 |
+
t.assert.ok(routeOpts)
|
| 110 |
+
fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
|
| 111 |
+
t.assert.ok(`stored the serializer function ${fileName}`)
|
| 112 |
+
},
|
| 113 |
+
restoreFunction () {
|
| 114 |
+
t.fail('write mode ON')
|
| 115 |
+
}
|
| 116 |
+
})
|
| 117 |
+
|
| 118 |
+
const app = buildApp(factory)
|
| 119 |
+
await app.ready()
|
| 120 |
+
})
|
| 121 |
+
|
| 122 |
+
await t.test('fastify integration - writeMode forces standalone', async t => {
|
| 123 |
+
t.plan(4)
|
| 124 |
+
|
| 125 |
+
const factory = FjsStandaloneCompiler({
|
| 126 |
+
readMode: false,
|
| 127 |
+
storeFunction (routeOpts, schemaSerializationCode) {
|
| 128 |
+
const fileName = generateFileName(routeOpts)
|
| 129 |
+
t.assert.ok(routeOpts)
|
| 130 |
+
fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
|
| 131 |
+
t.assert.ok(`stored the serializer function ${fileName}`)
|
| 132 |
+
},
|
| 133 |
+
restoreFunction () {
|
| 134 |
+
t.fail('write mode ON')
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
|
| 138 |
+
const app = buildApp(factory, {
|
| 139 |
+
mode: 'not-standalone',
|
| 140 |
+
rounding: 'ceil'
|
| 141 |
+
})
|
| 142 |
+
|
| 143 |
+
await app.ready()
|
| 144 |
+
})
|
| 145 |
+
|
| 146 |
+
await t.test('fastify integration - readMode', async t => {
|
| 147 |
+
t.plan(6)
|
| 148 |
+
|
| 149 |
+
const factory = FjsStandaloneCompiler({
|
| 150 |
+
readMode: true,
|
| 151 |
+
storeFunction () {
|
| 152 |
+
t.fail('read mode ON')
|
| 153 |
+
},
|
| 154 |
+
restoreFunction (routeOpts) {
|
| 155 |
+
const fileName = generateFileName(routeOpts)
|
| 156 |
+
t.assert.ok(`restore the serializer function ${fileName}}`)
|
| 157 |
+
return require(path.join(__dirname, fileName))
|
| 158 |
+
}
|
| 159 |
+
})
|
| 160 |
+
|
| 161 |
+
const app = buildApp(factory)
|
| 162 |
+
await app.ready()
|
| 163 |
+
|
| 164 |
+
let res = await app.inject({
|
| 165 |
+
url: '/foo',
|
| 166 |
+
method: 'POST'
|
| 167 |
+
})
|
| 168 |
+
t.assert.equal(res.statusCode, 200)
|
| 169 |
+
t.assert.equal(res.payload, JSON.stringify({ hello: 'world' }))
|
| 170 |
+
|
| 171 |
+
res = await app.inject({
|
| 172 |
+
url: '/bar?lang=it',
|
| 173 |
+
method: 'GET'
|
| 174 |
+
})
|
| 175 |
+
t.assert.equal(res.statusCode, 200)
|
| 176 |
+
t.assert.equal(res.payload, JSON.stringify({ lang: 'en' }))
|
| 177 |
+
})
|
| 178 |
+
|
| 179 |
+
function buildApp (factory, serializerOpts) {
|
| 180 |
+
const app = fastify({
|
| 181 |
+
exposeHeadRoutes: false,
|
| 182 |
+
jsonShorthand: false,
|
| 183 |
+
schemaController: {
|
| 184 |
+
compilersFactory: {
|
| 185 |
+
buildSerializer: factory
|
| 186 |
+
}
|
| 187 |
+
},
|
| 188 |
+
serializerOpts
|
| 189 |
+
})
|
| 190 |
+
|
| 191 |
+
app.addSchema({
|
| 192 |
+
$id: 'urn:schema:foo',
|
| 193 |
+
type: 'object',
|
| 194 |
+
properties: {
|
| 195 |
+
name: { type: 'string' },
|
| 196 |
+
id: { type: 'integer' }
|
| 197 |
+
}
|
| 198 |
+
})
|
| 199 |
+
|
| 200 |
+
app.post('/foo', {
|
| 201 |
+
schema: {
|
| 202 |
+
response: {
|
| 203 |
+
200: {
|
| 204 |
+
$id: 'urn:schema:response',
|
| 205 |
+
type: 'object',
|
| 206 |
+
properties: {
|
| 207 |
+
hello: { $ref: 'urn:schema:foo#/properties/name' }
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
}, () => { return { hello: 'world' } })
|
| 213 |
+
|
| 214 |
+
app.get('/bar', {
|
| 215 |
+
schema: {
|
| 216 |
+
response: {
|
| 217 |
+
200: {
|
| 218 |
+
$id: 'urn:schema:response:bar',
|
| 219 |
+
type: 'object',
|
| 220 |
+
properties: {
|
| 221 |
+
lang: { type: 'string', enum: ['it', 'en'] }
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
}, () => { return { lang: 'en' } })
|
| 227 |
+
|
| 228 |
+
return app
|
| 229 |
+
}
|
| 230 |
+
})
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Options } from 'fast-json-stringify'
|
| 2 |
+
|
| 3 |
+
type FastJsonStringifyFactory = () => SerializerSelector.SerializerFactory
|
| 4 |
+
|
| 5 |
+
declare namespace SerializerSelector {
|
| 6 |
+
export type SerializerFactory = (
|
| 7 |
+
externalSchemas?: unknown,
|
| 8 |
+
options?: Options
|
| 9 |
+
) => SerializerCompiler
|
| 10 |
+
|
| 11 |
+
export type SerializerCompiler = (routeDef: RouteDefinition) => Serializer
|
| 12 |
+
export type Serializer = (doc: any) => string
|
| 13 |
+
|
| 14 |
+
export type RouteDefinition = {
|
| 15 |
+
method: string;
|
| 16 |
+
url: string;
|
| 17 |
+
httpStatus: string;
|
| 18 |
+
schema?: unknown;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export type StandaloneOptions = StandaloneOptionsReadModeOn | StandaloneOptionsReadModeOff
|
| 22 |
+
|
| 23 |
+
export type StandaloneOptionsReadModeOn = {
|
| 24 |
+
readMode: true;
|
| 25 |
+
restoreFunction?(opts: RouteDefinition): Serializer;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
export type StandaloneOptionsReadModeOff = {
|
| 29 |
+
readMode?: false | undefined;
|
| 30 |
+
storeFunction?(opts: RouteDefinition, schemaSerializationCode: string): void;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export type { Options }
|
| 34 |
+
export const SerializerSelector: FastJsonStringifyFactory
|
| 35 |
+
export function StandaloneSerializer (options: StandaloneOptions): SerializerFactory
|
| 36 |
+
|
| 37 |
+
export { SerializerSelector as default }
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
declare function SerializerSelector (...params: Parameters<FastJsonStringifyFactory>): ReturnType<FastJsonStringifyFactory>
|
| 41 |
+
export = SerializerSelector
|
platform/dbops/archive/databases_old/data/home/x/india-h200-1-workspace/claude-code-router/node_modules/@fastify/fast-json-stringify-compiler/types/index.test-d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { expectAssignable, expectError, expectType } from 'tsd'
|
| 2 |
+
import SerializerSelector, {
|
| 3 |
+
RouteDefinition,
|
| 4 |
+
Serializer,
|
| 5 |
+
SerializerCompiler,
|
| 6 |
+
SerializerFactory,
|
| 7 |
+
SerializerSelector as SerializerSelectorNamed,
|
| 8 |
+
StandaloneSerializer,
|
| 9 |
+
} from '..'
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* SerializerSelector
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
{
|
| 16 |
+
const compiler = SerializerSelector()
|
| 17 |
+
expectType<SerializerFactory>(compiler)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
{
|
| 21 |
+
const compiler = SerializerSelectorNamed()
|
| 22 |
+
expectType<SerializerFactory>(compiler)
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
{
|
| 26 |
+
const sampleSchema = {
|
| 27 |
+
$id: 'example1',
|
| 28 |
+
type: 'object',
|
| 29 |
+
properties: {
|
| 30 |
+
name: { type: 'string' }
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const externalSchemas1 = {}
|
| 35 |
+
|
| 36 |
+
const factory = SerializerSelector()
|
| 37 |
+
expectType<SerializerFactory>(factory)
|
| 38 |
+
const compiler = factory(externalSchemas1, {})
|
| 39 |
+
expectType<SerializerCompiler>(compiler)
|
| 40 |
+
const serializeFunc = compiler({ schema: sampleSchema, method: '', url: '', httpStatus: '' })
|
| 41 |
+
expectType<Serializer>(serializeFunc)
|
| 42 |
+
|
| 43 |
+
expectType<string>(serializeFunc({ name: 'hello' }))
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* StandaloneSerializer
|
| 48 |
+
*/
|
| 49 |
+
|
| 50 |
+
const reader = StandaloneSerializer({
|
| 51 |
+
readMode: true,
|
| 52 |
+
restoreFunction: (route: RouteDefinition) => {
|
| 53 |
+
expectAssignable<RouteDefinition>(route)
|
| 54 |
+
return {} as Serializer
|
| 55 |
+
},
|
| 56 |
+
})
|
| 57 |
+
expectType<SerializerFactory>(reader)
|
| 58 |
+
|
| 59 |
+
const writer = StandaloneSerializer({
|
| 60 |
+
readMode: false,
|
| 61 |
+
storeFunction: (route: RouteDefinition, code: string) => {
|
| 62 |
+
expectAssignable<RouteDefinition>(route)
|
| 63 |
+
expectAssignable<string>(code)
|
| 64 |
+
},
|
| 65 |
+
})
|
| 66 |
+
expectType<SerializerFactory>(writer)
|
| 67 |
+
|
| 68 |
+
{
|
| 69 |
+
const base = {
|
| 70 |
+
$id: 'urn:schema:base',
|
| 71 |
+
definitions: {
|
| 72 |
+
hello: { type: 'string' }
|
| 73 |
+
},
|
| 74 |
+
type: 'object',
|
| 75 |
+
properties: {
|
| 76 |
+
hello: { $ref: '#/definitions/hello' }
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
const refSchema = {
|
| 81 |
+
$id: 'urn:schema:ref',
|
| 82 |
+
type: 'object',
|
| 83 |
+
properties: {
|
| 84 |
+
hello: { $ref: 'urn:schema:base#/definitions/hello' }
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
const endpointSchema = {
|
| 89 |
+
method: '',
|
| 90 |
+
url: '',
|
| 91 |
+
httpStatus: '',
|
| 92 |
+
schema: {
|
| 93 |
+
$id: 'urn:schema:endpoint',
|
| 94 |
+
$ref: 'urn:schema:ref'
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
const schemaMap = {
|
| 99 |
+
[base.$id]: base,
|
| 100 |
+
[refSchema.$id]: refSchema
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
expectError(StandaloneSerializer({
|
| 104 |
+
readMode: true,
|
| 105 |
+
storeFunction () { }
|
| 106 |
+
}))
|
| 107 |
+
expectError(StandaloneSerializer({
|
| 108 |
+
readMode: false,
|
| 109 |
+
restoreFunction () {}
|
| 110 |
+
}))
|
| 111 |
+
expectError(StandaloneSerializer({
|
| 112 |
+
restoreFunction () {}
|
| 113 |
+
}))
|
| 114 |
+
|
| 115 |
+
expectType<SerializerFactory>(StandaloneSerializer({
|
| 116 |
+
storeFunction (routeOpts, schemaSerializerCode) {
|
| 117 |
+
expectType<RouteDefinition>(routeOpts)
|
| 118 |
+
expectType<string>(schemaSerializerCode)
|
| 119 |
+
}
|
| 120 |
+
}))
|
| 121 |
+
|
| 122 |
+
expectType<SerializerFactory>(StandaloneSerializer({
|
| 123 |
+
readMode: true,
|
| 124 |
+
restoreFunction (routeOpts) {
|
| 125 |
+
expectType<RouteDefinition>(routeOpts)
|
| 126 |
+
return {} as Serializer
|
| 127 |
+
}
|
| 128 |
+
}))
|
| 129 |
+
|
| 130 |
+
const factory = StandaloneSerializer({
|
| 131 |
+
readMode: false,
|
| 132 |
+
storeFunction (routeOpts, schemaSerializerCode) {
|
| 133 |
+
expectType<RouteDefinition>(routeOpts)
|
| 134 |
+
expectType<string>(schemaSerializerCode)
|
| 135 |
+
}
|
| 136 |
+
})
|
| 137 |
+
expectType<SerializerFactory>(factory)
|
| 138 |
+
|
| 139 |
+
const compiler = factory(schemaMap)
|
| 140 |
+
expectType<SerializerCompiler>(compiler)
|
| 141 |
+
expectType<Serializer>(compiler(endpointSchema))
|
| 142 |
+
}
|