opik 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Node18UniversalStreamWrapper-5PLK6H2I.js +216 -0
- package/dist/NodePre18StreamWrapper-PJE27LW2.js +88 -0
- package/dist/UndiciStreamWrapper-M2WUKUR4.js +204 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/index.cjs +10735 -0
- package/dist/index.d.cts +3653 -0
- package/dist/index.d.ts +3653 -0
- package/dist/index.js +10173 -0
- package/examples/manual-trace.js +16 -0
- package/package.json +56 -0
- package/src/opik/client/Client.ts +65 -0
- package/src/opik/config/Config.ts +35 -0
- package/src/opik/index.ts +2 -0
- package/src/opik/rest_api/Client.ts +247 -0
- package/src/opik/rest_api/api/errors/BadRequestError.ts +16 -0
- package/src/opik/rest_api/api/errors/ConflictError.ts +16 -0
- package/src/opik/rest_api/api/errors/ForbiddenError.ts +17 -0
- package/src/opik/rest_api/api/errors/NotFoundError.ts +16 -0
- package/src/opik/rest_api/api/errors/NotImplementedError.ts +16 -0
- package/src/opik/rest_api/api/errors/UnauthorizedError.ts +17 -0
- package/src/opik/rest_api/api/errors/UnprocessableEntityError.ts +16 -0
- package/src/opik/rest_api/api/errors/index.ts +7 -0
- package/src/opik/rest_api/api/index.ts +3 -0
- package/src/opik/rest_api/api/resources/chatCompletions/client/Client.ts +125 -0
- package/src/opik/rest_api/api/resources/chatCompletions/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/chatCompletions/client/requests/ChatCompletionRequest.ts +33 -0
- package/src/opik/rest_api/api/resources/chatCompletions/client/requests/index.ts +1 -0
- package/src/opik/rest_api/api/resources/chatCompletions/index.ts +1 -0
- package/src/opik/rest_api/api/resources/check/client/Client.ts +141 -0
- package/src/opik/rest_api/api/resources/check/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/check/index.ts +1 -0
- package/src/opik/rest_api/api/resources/datasets/client/Client.ts +1244 -0
- package/src/opik/rest_api/api/resources/datasets/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetIdentifier.ts +13 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetIdentifierPublic.ts +13 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetItemBatchWrite.ts +21 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetItemStreamRequest.ts +9 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetItemsDelete.ts +13 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetUpdate.ts +14 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/DatasetWrite.ts +15 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/FindDatasetItemsWithExperimentItemsRequest.ts +17 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/FindDatasetsRequest.ts +16 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/GetDatasetItemsOutputColumnsRequest.ts +11 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/GetDatasetItemsRequest.ts +13 -0
- package/src/opik/rest_api/api/resources/datasets/client/requests/index.ts +11 -0
- package/src/opik/rest_api/api/resources/datasets/index.ts +1 -0
- package/src/opik/rest_api/api/resources/experiments/client/Client.ts +858 -0
- package/src/opik/rest_api/api/resources/experiments/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/ExperimentItemStreamRequest.ts +9 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/ExperimentItemsBatch.ts +19 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/ExperimentItemsDelete.ts +13 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/ExperimentWrite.ts +19 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/ExperimentsDelete.ts +13 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/FindExperimentsRequest.ts +16 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/FindFeedbackScoreNamesRequest.ts +11 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.ts +13 -0
- package/src/opik/rest_api/api/resources/experiments/client/requests/index.ts +8 -0
- package/src/opik/rest_api/api/resources/experiments/index.ts +1 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/client/Client.ts +515 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/client/requests/FindFeedbackDefinitionsRequest.ts +16 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/client/requests/index.ts +1 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/index.ts +2 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/types/FindFeedbackDefinitionsRequestType.ts +10 -0
- package/src/opik/rest_api/api/resources/feedbackDefinitions/types/index.ts +1 -0
- package/src/opik/rest_api/api/resources/index.ts +23 -0
- package/src/opik/rest_api/api/resources/llmProviderKey/client/Client.ts +412 -0
- package/src/opik/rest_api/api/resources/llmProviderKey/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/llmProviderKey/client/requests/ProviderApiKeyUpdate.ts +13 -0
- package/src/opik/rest_api/api/resources/llmProviderKey/client/requests/ProviderApiKeyWrite.ts +13 -0
- package/src/opik/rest_api/api/resources/llmProviderKey/client/requests/index.ts +2 -0
- package/src/opik/rest_api/api/resources/llmProviderKey/index.ts +1 -0
- package/src/opik/rest_api/api/resources/projects/client/Client.ts +720 -0
- package/src/opik/rest_api/api/resources/projects/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/projects/client/requests/FindProjectsRequest.ts +14 -0
- package/src/opik/rest_api/api/resources/projects/client/requests/ProjectMetricRequestPublic.ts +16 -0
- package/src/opik/rest_api/api/resources/projects/client/requests/ProjectRetrievePublic.ts +13 -0
- package/src/opik/rest_api/api/resources/projects/client/requests/ProjectUpdate.ts +12 -0
- package/src/opik/rest_api/api/resources/projects/client/requests/ProjectWrite.ts +14 -0
- package/src/opik/rest_api/api/resources/projects/client/requests/index.ts +5 -0
- package/src/opik/rest_api/api/resources/projects/index.ts +2 -0
- package/src/opik/rest_api/api/resources/projects/types/ProjectMetricRequestPublicInterval.ts +11 -0
- package/src/opik/rest_api/api/resources/projects/types/ProjectMetricRequestPublicMetricType.ts +18 -0
- package/src/opik/rest_api/api/resources/projects/types/index.ts +2 -0
- package/src/opik/rest_api/api/resources/prompts/client/Client.ts +900 -0
- package/src/opik/rest_api/api/resources/prompts/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/CreatePromptVersionDetail.ts +19 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/GetPromptVersionsRequest.ts +12 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/GetPromptsRequest.ts +13 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/PromptUpdatable.ts +14 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/PromptVersionRetrieveDetail.ts +14 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/PromptWrite.ts +16 -0
- package/src/opik/rest_api/api/resources/prompts/client/requests/index.ts +6 -0
- package/src/opik/rest_api/api/resources/prompts/index.ts +1 -0
- package/src/opik/rest_api/api/resources/spans/client/Client.ts +957 -0
- package/src/opik/rest_api/api/resources/spans/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/spans/client/requests/FindFeedbackScoreNames1Request.ts +14 -0
- package/src/opik/rest_api/api/resources/spans/client/requests/GetSpanStatsRequest.ts +17 -0
- package/src/opik/rest_api/api/resources/spans/client/requests/GetSpansByProjectRequest.ts +20 -0
- package/src/opik/rest_api/api/resources/spans/client/requests/SpanBatchWrite.ts +20 -0
- package/src/opik/rest_api/api/resources/spans/client/requests/SpanUpdate.ts +29 -0
- package/src/opik/rest_api/api/resources/spans/client/requests/index.ts +5 -0
- package/src/opik/rest_api/api/resources/spans/index.ts +2 -0
- package/src/opik/rest_api/api/resources/spans/types/FindFeedbackScoreNames1RequestType.ts +11 -0
- package/src/opik/rest_api/api/resources/spans/types/GetSpanStatsRequestType.ts +11 -0
- package/src/opik/rest_api/api/resources/spans/types/GetSpansByProjectRequestType.ts +11 -0
- package/src/opik/rest_api/api/resources/spans/types/index.ts +3 -0
- package/src/opik/rest_api/api/resources/systemUsage/client/Client.ts +347 -0
- package/src/opik/rest_api/api/resources/systemUsage/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/systemUsage/index.ts +1 -0
- package/src/opik/rest_api/api/resources/traces/client/Client.ts +990 -0
- package/src/opik/rest_api/api/resources/traces/client/index.ts +1 -0
- package/src/opik/rest_api/api/resources/traces/client/requests/FindFeedbackScoreNames2Request.ts +11 -0
- package/src/opik/rest_api/api/resources/traces/client/requests/GetTraceStatsRequest.ts +13 -0
- package/src/opik/rest_api/api/resources/traces/client/requests/GetTracesByProjectRequest.ts +16 -0
- package/src/opik/rest_api/api/resources/traces/client/requests/TraceBatchWrite.ts +18 -0
- package/src/opik/rest_api/api/resources/traces/client/requests/TraceUpdate.ts +22 -0
- package/src/opik/rest_api/api/resources/traces/client/requests/index.ts +5 -0
- package/src/opik/rest_api/api/resources/traces/index.ts +1 -0
- package/src/opik/rest_api/api/types/AssistantMessage.ts +14 -0
- package/src/opik/rest_api/api/types/AssistantMessageRole.ts +13 -0
- package/src/opik/rest_api/api/types/AuthDetailsHolder.ts +5 -0
- package/src/opik/rest_api/api/types/AvgValueStatPublic.ts +7 -0
- package/src/opik/rest_api/api/types/BatchDelete.ts +7 -0
- package/src/opik/rest_api/api/types/BiInformation.ts +9 -0
- package/src/opik/rest_api/api/types/BiInformationResponse.ts +9 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDefinition.ts +13 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDefinitionCreate.ts +9 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDefinitionPublic.ts +13 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDefinitionUpdate.ts +9 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDetail.ts +7 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDetailCreate.ts +7 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDetailPublic.ts +7 -0
- package/src/opik/rest_api/api/types/CategoricalFeedbackDetailUpdate.ts +7 -0
- package/src/opik/rest_api/api/types/ChatCompletionChoice.ts +12 -0
- package/src/opik/rest_api/api/types/ChatCompletionResponse.ts +14 -0
- package/src/opik/rest_api/api/types/ChunkedOutputJsonNode.ts +10 -0
- package/src/opik/rest_api/api/types/ChunkedOutputJsonNodeType.ts +7 -0
- package/src/opik/rest_api/api/types/Column.ts +13 -0
- package/src/opik/rest_api/api/types/ColumnCompare.ts +13 -0
- package/src/opik/rest_api/api/types/ColumnCompareTypesItem.ts +14 -0
- package/src/opik/rest_api/api/types/ColumnPublic.ts +13 -0
- package/src/opik/rest_api/api/types/ColumnPublicTypesItem.ts +14 -0
- package/src/opik/rest_api/api/types/ColumnTypesItem.ts +14 -0
- package/src/opik/rest_api/api/types/CompletionTokensDetails.ts +7 -0
- package/src/opik/rest_api/api/types/CountValueStatPublic.ts +7 -0
- package/src/opik/rest_api/api/types/DataPointNumberPublic.ts +8 -0
- package/src/opik/rest_api/api/types/Dataset.ts +17 -0
- package/src/opik/rest_api/api/types/DatasetItem.ts +21 -0
- package/src/opik/rest_api/api/types/DatasetItemBatch.ts +13 -0
- package/src/opik/rest_api/api/types/DatasetItemCompare.ts +21 -0
- package/src/opik/rest_api/api/types/DatasetItemCompareSource.ts +12 -0
- package/src/opik/rest_api/api/types/DatasetItemPageCompare.ts +13 -0
- package/src/opik/rest_api/api/types/DatasetItemPagePublic.ts +13 -0
- package/src/opik/rest_api/api/types/DatasetItemPublic.ts +21 -0
- package/src/opik/rest_api/api/types/DatasetItemPublicSource.ts +12 -0
- package/src/opik/rest_api/api/types/DatasetItemSource.ts +12 -0
- package/src/opik/rest_api/api/types/DatasetItemWrite.ts +16 -0
- package/src/opik/rest_api/api/types/DatasetItemWriteSource.ts +12 -0
- package/src/opik/rest_api/api/types/DatasetPagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/DatasetPublic.ts +17 -0
- package/src/opik/rest_api/api/types/DeleteFeedbackScore.ts +7 -0
- package/src/opik/rest_api/api/types/Delta.ts +12 -0
- package/src/opik/rest_api/api/types/DeltaRole.ts +13 -0
- package/src/opik/rest_api/api/types/ErrorInfo.ts +9 -0
- package/src/opik/rest_api/api/types/ErrorInfoPublic.ts +9 -0
- package/src/opik/rest_api/api/types/ErrorInfoWrite.ts +9 -0
- package/src/opik/rest_api/api/types/ErrorMessage.ts +9 -0
- package/src/opik/rest_api/api/types/ErrorMessageDetail.ts +9 -0
- package/src/opik/rest_api/api/types/ErrorMessagePublic.ts +7 -0
- package/src/opik/rest_api/api/types/Experiment.ts +20 -0
- package/src/opik/rest_api/api/types/ExperimentItem.ts +19 -0
- package/src/opik/rest_api/api/types/ExperimentItemCompare.ts +19 -0
- package/src/opik/rest_api/api/types/ExperimentItemPublic.ts +14 -0
- package/src/opik/rest_api/api/types/ExperimentPagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/ExperimentPublic.ts +20 -0
- package/src/opik/rest_api/api/types/Feedback.ts +26 -0
- package/src/opik/rest_api/api/types/FeedbackCreate.ts +22 -0
- package/src/opik/rest_api/api/types/FeedbackDefinitionPagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/FeedbackObjectPublic.ts +26 -0
- package/src/opik/rest_api/api/types/FeedbackPublic.ts +26 -0
- package/src/opik/rest_api/api/types/FeedbackScore.ts +17 -0
- package/src/opik/rest_api/api/types/FeedbackScoreAverage.ts +8 -0
- package/src/opik/rest_api/api/types/FeedbackScoreAveragePublic.ts +8 -0
- package/src/opik/rest_api/api/types/FeedbackScoreBatch.ts +9 -0
- package/src/opik/rest_api/api/types/FeedbackScoreBatchItem.ts +16 -0
- package/src/opik/rest_api/api/types/FeedbackScoreBatchItemSource.ts +10 -0
- package/src/opik/rest_api/api/types/FeedbackScoreCompare.ts +17 -0
- package/src/opik/rest_api/api/types/FeedbackScoreCompareSource.ts +10 -0
- package/src/opik/rest_api/api/types/FeedbackScorePublic.ts +17 -0
- package/src/opik/rest_api/api/types/FeedbackScorePublicSource.ts +10 -0
- package/src/opik/rest_api/api/types/FeedbackScoreSource.ts +10 -0
- package/src/opik/rest_api/api/types/FeedbackUpdate.ts +22 -0
- package/src/opik/rest_api/api/types/Function.ts +12 -0
- package/src/opik/rest_api/api/types/FunctionCall.ts +8 -0
- package/src/opik/rest_api/api/types/JsonNode.ts +5 -0
- package/src/opik/rest_api/api/types/JsonNodeCompare.ts +5 -0
- package/src/opik/rest_api/api/types/JsonNodePublic.ts +5 -0
- package/src/opik/rest_api/api/types/JsonNodeWrite.ts +5 -0
- package/src/opik/rest_api/api/types/JsonObjectSchema.ts +14 -0
- package/src/opik/rest_api/api/types/JsonSchema.ts +11 -0
- package/src/opik/rest_api/api/types/JsonSchemaElement.ts +7 -0
- package/src/opik/rest_api/api/types/Message.ts +5 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDefinition.ts +13 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDefinitionCreate.ts +9 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDefinitionPublic.ts +13 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDefinitionUpdate.ts +9 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDetail.ts +8 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDetailCreate.ts +8 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDetailPublic.ts +8 -0
- package/src/opik/rest_api/api/types/NumericalFeedbackDetailUpdate.ts +8 -0
- package/src/opik/rest_api/api/types/PageColumns.ts +9 -0
- package/src/opik/rest_api/api/types/PercentageValueStatPublic.ts +9 -0
- package/src/opik/rest_api/api/types/PercentageValuesPublic.ts +9 -0
- package/src/opik/rest_api/api/types/Project.ts +14 -0
- package/src/opik/rest_api/api/types/ProjectMetricResponsePublic.ts +12 -0
- package/src/opik/rest_api/api/types/ProjectMetricResponsePublicInterval.ts +11 -0
- package/src/opik/rest_api/api/types/ProjectMetricResponsePublicMetricType.ts +18 -0
- package/src/opik/rest_api/api/types/ProjectPagePublic.ts +13 -0
- package/src/opik/rest_api/api/types/ProjectPublic.ts +14 -0
- package/src/opik/rest_api/api/types/ProjectStatItemObjectPublic.ts +28 -0
- package/src/opik/rest_api/api/types/ProjectStatsPublic.ts +9 -0
- package/src/opik/rest_api/api/types/Prompt.ts +18 -0
- package/src/opik/rest_api/api/types/PromptDetail.ts +17 -0
- package/src/opik/rest_api/api/types/PromptPagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/PromptPublic.ts +14 -0
- package/src/opik/rest_api/api/types/PromptVersion.ts +15 -0
- package/src/opik/rest_api/api/types/PromptVersionDetail.ts +15 -0
- package/src/opik/rest_api/api/types/PromptVersionLink.ts +9 -0
- package/src/opik/rest_api/api/types/PromptVersionLinkPublic.ts +9 -0
- package/src/opik/rest_api/api/types/PromptVersionLinkWrite.ts +7 -0
- package/src/opik/rest_api/api/types/PromptVersionPagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/PromptVersionPublic.ts +14 -0
- package/src/opik/rest_api/api/types/ProviderApiKey.ts +13 -0
- package/src/opik/rest_api/api/types/ProviderApiKeyPublic.ts +12 -0
- package/src/opik/rest_api/api/types/ResponseFormat.ts +10 -0
- package/src/opik/rest_api/api/types/ResponseFormatType.ts +11 -0
- package/src/opik/rest_api/api/types/ResultsNumberPublic.ts +10 -0
- package/src/opik/rest_api/api/types/Span.ts +32 -0
- package/src/opik/rest_api/api/types/SpanBatch.ts +9 -0
- package/src/opik/rest_api/api/types/SpanPagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/SpanPublic.ts +30 -0
- package/src/opik/rest_api/api/types/SpanPublicType.ts +11 -0
- package/src/opik/rest_api/api/types/SpanType.ts +11 -0
- package/src/opik/rest_api/api/types/SpanWrite.ts +25 -0
- package/src/opik/rest_api/api/types/SpanWriteType.ts +11 -0
- package/src/opik/rest_api/api/types/StreamOptions.ts +7 -0
- package/src/opik/rest_api/api/types/Tool.ts +10 -0
- package/src/opik/rest_api/api/types/ToolCall.ts +12 -0
- package/src/opik/rest_api/api/types/Trace.ts +27 -0
- package/src/opik/rest_api/api/types/TraceBatch.ts +9 -0
- package/src/opik/rest_api/api/types/TraceCountResponse.ts +9 -0
- package/src/opik/rest_api/api/types/TracePagePublic.ts +12 -0
- package/src/opik/rest_api/api/types/TracePublic.ts +25 -0
- package/src/opik/rest_api/api/types/TraceWrite.ts +19 -0
- package/src/opik/rest_api/api/types/Usage.ts +12 -0
- package/src/opik/rest_api/api/types/WorkspaceTraceCount.ts +8 -0
- package/src/opik/rest_api/api/types/index.ts +138 -0
- package/src/opik/rest_api/core/api-promise/APIPromise.ts +54 -0
- package/src/opik/rest_api/core/api-promise/index.ts +1 -0
- package/src/opik/rest_api/core/fetcher/APIResponse.ts +12 -0
- package/src/opik/rest_api/core/fetcher/Fetcher.ts +143 -0
- package/src/opik/rest_api/core/fetcher/Supplier.ts +11 -0
- package/src/opik/rest_api/core/fetcher/createRequestUrl.ts +10 -0
- package/src/opik/rest_api/core/fetcher/getFetchFn.ts +25 -0
- package/src/opik/rest_api/core/fetcher/getHeader.ts +8 -0
- package/src/opik/rest_api/core/fetcher/getRequestBody.ts +14 -0
- package/src/opik/rest_api/core/fetcher/getResponseBody.ts +34 -0
- package/src/opik/rest_api/core/fetcher/index.ts +5 -0
- package/src/opik/rest_api/core/fetcher/makeRequest.ts +44 -0
- package/src/opik/rest_api/core/fetcher/requestWithRetries.ts +33 -0
- package/src/opik/rest_api/core/fetcher/signals.ts +38 -0
- package/src/opik/rest_api/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts +256 -0
- package/src/opik/rest_api/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts +106 -0
- package/src/opik/rest_api/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts +243 -0
- package/src/opik/rest_api/core/fetcher/stream-wrappers/chooseStreamWrapper.ts +33 -0
- package/src/opik/rest_api/core/index.ts +4 -0
- package/src/opik/rest_api/core/runtime/index.ts +1 -0
- package/src/opik/rest_api/core/runtime/runtime.ts +126 -0
- package/src/opik/rest_api/core/schemas/Schema.ts +99 -0
- package/src/opik/rest_api/core/schemas/builders/bigint/bigint.ts +50 -0
- package/src/opik/rest_api/core/schemas/builders/bigint/index.ts +1 -0
- package/src/opik/rest_api/core/schemas/builders/date/date.ts +65 -0
- package/src/opik/rest_api/core/schemas/builders/date/index.ts +1 -0
- package/src/opik/rest_api/core/schemas/builders/enum/enum.ts +43 -0
- package/src/opik/rest_api/core/schemas/builders/enum/index.ts +1 -0
- package/src/opik/rest_api/core/schemas/builders/index.ts +14 -0
- package/src/opik/rest_api/core/schemas/builders/lazy/index.ts +3 -0
- package/src/opik/rest_api/core/schemas/builders/lazy/lazy.ts +32 -0
- package/src/opik/rest_api/core/schemas/builders/lazy/lazyObject.ts +20 -0
- package/src/opik/rest_api/core/schemas/builders/list/index.ts +1 -0
- package/src/opik/rest_api/core/schemas/builders/list/list.ts +73 -0
- package/src/opik/rest_api/core/schemas/builders/literals/booleanLiteral.ts +29 -0
- package/src/opik/rest_api/core/schemas/builders/literals/index.ts +2 -0
- package/src/opik/rest_api/core/schemas/builders/literals/stringLiteral.ts +29 -0
- package/src/opik/rest_api/core/schemas/builders/object/index.ts +22 -0
- package/src/opik/rest_api/core/schemas/builders/object/object.ts +324 -0
- package/src/opik/rest_api/core/schemas/builders/object/objectWithoutOptionalProperties.ts +18 -0
- package/src/opik/rest_api/core/schemas/builders/object/property.ts +23 -0
- package/src/opik/rest_api/core/schemas/builders/object/types.ts +72 -0
- package/src/opik/rest_api/core/schemas/builders/object-like/getObjectLikeUtils.ts +79 -0
- package/src/opik/rest_api/core/schemas/builders/object-like/index.ts +2 -0
- package/src/opik/rest_api/core/schemas/builders/object-like/types.ts +11 -0
- package/src/opik/rest_api/core/schemas/builders/primitives/any.ts +4 -0
- package/src/opik/rest_api/core/schemas/builders/primitives/boolean.ts +25 -0
- package/src/opik/rest_api/core/schemas/builders/primitives/index.ts +5 -0
- package/src/opik/rest_api/core/schemas/builders/primitives/number.ts +25 -0
- package/src/opik/rest_api/core/schemas/builders/primitives/string.ts +25 -0
- package/src/opik/rest_api/core/schemas/builders/primitives/unknown.ts +4 -0
- package/src/opik/rest_api/core/schemas/builders/record/index.ts +2 -0
- package/src/opik/rest_api/core/schemas/builders/record/record.ts +130 -0
- package/src/opik/rest_api/core/schemas/builders/record/types.ts +17 -0
- package/src/opik/rest_api/core/schemas/builders/schema-utils/JsonError.ts +9 -0
- package/src/opik/rest_api/core/schemas/builders/schema-utils/ParseError.ts +9 -0
- package/src/opik/rest_api/core/schemas/builders/schema-utils/getSchemaUtils.ts +105 -0
- package/src/opik/rest_api/core/schemas/builders/schema-utils/index.ts +4 -0
- package/src/opik/rest_api/core/schemas/builders/schema-utils/stringifyValidationErrors.ts +8 -0
- package/src/opik/rest_api/core/schemas/builders/set/index.ts +1 -0
- package/src/opik/rest_api/core/schemas/builders/set/set.ts +43 -0
- package/src/opik/rest_api/core/schemas/builders/undiscriminated-union/index.ts +6 -0
- package/src/opik/rest_api/core/schemas/builders/undiscriminated-union/types.ts +10 -0
- package/src/opik/rest_api/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.ts +60 -0
- package/src/opik/rest_api/core/schemas/builders/union/discriminant.ts +14 -0
- package/src/opik/rest_api/core/schemas/builders/union/index.ts +10 -0
- package/src/opik/rest_api/core/schemas/builders/union/types.ts +26 -0
- package/src/opik/rest_api/core/schemas/builders/union/union.ts +170 -0
- package/src/opik/rest_api/core/schemas/index.ts +2 -0
- package/src/opik/rest_api/core/schemas/utils/MaybePromise.ts +1 -0
- package/src/opik/rest_api/core/schemas/utils/addQuestionMarksToNullableProperties.ts +15 -0
- package/src/opik/rest_api/core/schemas/utils/createIdentitySchemaCreator.ts +21 -0
- package/src/opik/rest_api/core/schemas/utils/entries.ts +3 -0
- package/src/opik/rest_api/core/schemas/utils/filterObject.ts +10 -0
- package/src/opik/rest_api/core/schemas/utils/getErrorMessageForIncorrectType.ts +25 -0
- package/src/opik/rest_api/core/schemas/utils/isPlainObject.ts +17 -0
- package/src/opik/rest_api/core/schemas/utils/keys.ts +3 -0
- package/src/opik/rest_api/core/schemas/utils/maybeSkipValidation.ts +38 -0
- package/src/opik/rest_api/core/schemas/utils/partition.ts +12 -0
- package/src/opik/rest_api/environments.ts +9 -0
- package/src/opik/rest_api/errors/OpikApiError.ts +45 -0
- package/src/opik/rest_api/errors/OpikApiTimeoutError.ts +10 -0
- package/src/opik/rest_api/errors/index.ts +2 -0
- package/src/opik/rest_api/index.ts +4 -0
- package/src/opik/rest_api/serialization/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/chatCompletions/client/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/chatCompletions/client/requests/ChatCompletionRequest.ts +72 -0
- package/src/opik/rest_api/serialization/resources/chatCompletions/client/requests/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/chatCompletions/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetIdentifier.ts +20 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetIdentifierPublic.ts +20 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetItemBatchWrite.ts +25 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetItemStreamRequest.ts +24 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetItemsDelete.ts +20 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetUpdate.ts +20 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/DatasetWrite.ts +22 -0
- package/src/opik/rest_api/serialization/resources/datasets/client/requests/index.ts +7 -0
- package/src/opik/rest_api/serialization/resources/datasets/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/findFeedbackScoreNames.ts +15 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/ExperimentItemStreamRequest.ts +24 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/ExperimentItemsBatch.ts +21 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/ExperimentItemsDelete.ts +20 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/ExperimentWrite.ts +28 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/ExperimentsDelete.ts +20 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.ts +18 -0
- package/src/opik/rest_api/serialization/resources/experiments/client/requests/index.ts +6 -0
- package/src/opik/rest_api/serialization/resources/experiments/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/feedbackDefinitions/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/feedbackDefinitions/types/FindFeedbackDefinitionsRequestType.ts +16 -0
- package/src/opik/rest_api/serialization/resources/feedbackDefinitions/types/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/index.ts +20 -0
- package/src/opik/rest_api/serialization/resources/llmProviderKey/client/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/llmProviderKey/client/requests/ProviderApiKeyUpdate.ts +20 -0
- package/src/opik/rest_api/serialization/resources/llmProviderKey/client/requests/ProviderApiKeyWrite.ts +20 -0
- package/src/opik/rest_api/serialization/resources/llmProviderKey/client/requests/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/llmProviderKey/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/projects/client/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/projects/client/requests/ProjectMetricRequestPublic.ts +28 -0
- package/src/opik/rest_api/serialization/resources/projects/client/requests/ProjectRetrievePublic.ts +20 -0
- package/src/opik/rest_api/serialization/resources/projects/client/requests/ProjectUpdate.ts +20 -0
- package/src/opik/rest_api/serialization/resources/projects/client/requests/ProjectWrite.ts +20 -0
- package/src/opik/rest_api/serialization/resources/projects/client/requests/index.ts +4 -0
- package/src/opik/rest_api/serialization/resources/projects/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/projects/types/ProjectMetricRequestPublicInterval.ts +16 -0
- package/src/opik/rest_api/serialization/resources/projects/types/ProjectMetricRequestPublicMetricType.ts +16 -0
- package/src/opik/rest_api/serialization/resources/projects/types/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/prompts/client/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/prompts/client/requests/CreatePromptVersionDetail.ts +23 -0
- package/src/opik/rest_api/serialization/resources/prompts/client/requests/PromptUpdatable.ts +20 -0
- package/src/opik/rest_api/serialization/resources/prompts/client/requests/PromptVersionRetrieveDetail.ts +22 -0
- package/src/opik/rest_api/serialization/resources/prompts/client/requests/PromptWrite.ts +24 -0
- package/src/opik/rest_api/serialization/resources/prompts/client/requests/index.ts +4 -0
- package/src/opik/rest_api/serialization/resources/prompts/index.ts +1 -0
- package/src/opik/rest_api/serialization/resources/spans/client/findFeedbackScoreNames1.ts +13 -0
- package/src/opik/rest_api/serialization/resources/spans/client/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/spans/client/requests/SpanBatchWrite.ts +19 -0
- package/src/opik/rest_api/serialization/resources/spans/client/requests/SpanUpdate.ts +44 -0
- package/src/opik/rest_api/serialization/resources/spans/client/requests/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/spans/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/spans/types/FindFeedbackScoreNames1RequestType.ts +16 -0
- package/src/opik/rest_api/serialization/resources/spans/types/GetSpanStatsRequestType.ts +16 -0
- package/src/opik/rest_api/serialization/resources/spans/types/GetSpansByProjectRequestType.ts +16 -0
- package/src/opik/rest_api/serialization/resources/spans/types/index.ts +3 -0
- package/src/opik/rest_api/serialization/resources/traces/client/findFeedbackScoreNames2.ts +13 -0
- package/src/opik/rest_api/serialization/resources/traces/client/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/traces/client/requests/TraceBatchWrite.ts +19 -0
- package/src/opik/rest_api/serialization/resources/traces/client/requests/TraceUpdate.ts +34 -0
- package/src/opik/rest_api/serialization/resources/traces/client/requests/index.ts +2 -0
- package/src/opik/rest_api/serialization/resources/traces/index.ts +1 -0
- package/src/opik/rest_api/serialization/types/AssistantMessage.ts +33 -0
- package/src/opik/rest_api/serialization/types/AssistantMessageRole.ts +16 -0
- package/src/opik/rest_api/serialization/types/AuthDetailsHolder.ts +16 -0
- package/src/opik/rest_api/serialization/types/AvgValueStatPublic.ts +20 -0
- package/src/opik/rest_api/serialization/types/BatchDelete.ts +18 -0
- package/src/opik/rest_api/serialization/types/BiInformation.ts +22 -0
- package/src/opik/rest_api/serialization/types/BiInformationResponse.ts +21 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDefinition.ts +29 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDefinitionCreate.ts +21 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDefinitionPublic.ts +29 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDefinitionUpdate.ts +21 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDetail.ts +20 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDetailCreate.ts +20 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDetailPublic.ts +20 -0
- package/src/opik/rest_api/serialization/types/CategoricalFeedbackDetailUpdate.ts +20 -0
- package/src/opik/rest_api/serialization/types/ChatCompletionChoice.ts +28 -0
- package/src/opik/rest_api/serialization/types/ChatCompletionResponse.ts +32 -0
- package/src/opik/rest_api/serialization/types/ChunkedOutputJsonNode.ts +23 -0
- package/src/opik/rest_api/serialization/types/ChunkedOutputJsonNodeType.ts +20 -0
- package/src/opik/rest_api/serialization/types/Column.ts +25 -0
- package/src/opik/rest_api/serialization/types/ColumnCompare.ts +25 -0
- package/src/opik/rest_api/serialization/types/ColumnCompareTypesItem.ts +16 -0
- package/src/opik/rest_api/serialization/types/ColumnPublic.ts +25 -0
- package/src/opik/rest_api/serialization/types/ColumnPublicTypesItem.ts +16 -0
- package/src/opik/rest_api/serialization/types/ColumnTypesItem.ts +14 -0
- package/src/opik/rest_api/serialization/types/CompletionTokensDetails.ts +20 -0
- package/src/opik/rest_api/serialization/types/CountValueStatPublic.ts +20 -0
- package/src/opik/rest_api/serialization/types/DataPointNumberPublic.ts +22 -0
- package/src/opik/rest_api/serialization/types/Dataset.ts +44 -0
- package/src/opik/rest_api/serialization/types/DatasetItem.ts +48 -0
- package/src/opik/rest_api/serialization/types/DatasetItemBatch.ts +25 -0
- package/src/opik/rest_api/serialization/types/DatasetItemCompare.ts +51 -0
- package/src/opik/rest_api/serialization/types/DatasetItemCompareSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/DatasetItemPageCompare.ts +30 -0
- package/src/opik/rest_api/serialization/types/DatasetItemPagePublic.ts +30 -0
- package/src/opik/rest_api/serialization/types/DatasetItemPublic.ts +51 -0
- package/src/opik/rest_api/serialization/types/DatasetItemPublicSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/DatasetItemSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/DatasetItemWrite.ts +37 -0
- package/src/opik/rest_api/serialization/types/DatasetItemWriteSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/DatasetPagePublic.ts +27 -0
- package/src/opik/rest_api/serialization/types/DatasetPublic.ts +44 -0
- package/src/opik/rest_api/serialization/types/DeleteFeedbackScore.ts +20 -0
- package/src/opik/rest_api/serialization/types/Delta.ts +26 -0
- package/src/opik/rest_api/serialization/types/DeltaRole.ts +14 -0
- package/src/opik/rest_api/serialization/types/ErrorInfo.ts +22 -0
- package/src/opik/rest_api/serialization/types/ErrorInfoPublic.ts +24 -0
- package/src/opik/rest_api/serialization/types/ErrorInfoWrite.ts +22 -0
- package/src/opik/rest_api/serialization/types/ErrorMessage.ts +22 -0
- package/src/opik/rest_api/serialization/types/ErrorMessageDetail.ts +24 -0
- package/src/opik/rest_api/serialization/types/ErrorMessagePublic.ts +20 -0
- package/src/opik/rest_api/serialization/types/Experiment.ts +46 -0
- package/src/opik/rest_api/serialization/types/ExperimentItem.ts +43 -0
- package/src/opik/rest_api/serialization/types/ExperimentItemCompare.ts +45 -0
- package/src/opik/rest_api/serialization/types/ExperimentItemPublic.ts +34 -0
- package/src/opik/rest_api/serialization/types/ExperimentPagePublic.ts +27 -0
- package/src/opik/rest_api/serialization/types/ExperimentPublic.ts +48 -0
- package/src/opik/rest_api/serialization/types/Feedback.ts +48 -0
- package/src/opik/rest_api/serialization/types/FeedbackCreate.ts +41 -0
- package/src/opik/rest_api/serialization/types/FeedbackDefinitionPagePublic.ts +27 -0
- package/src/opik/rest_api/serialization/types/FeedbackObjectPublic.ts +51 -0
- package/src/opik/rest_api/serialization/types/FeedbackPublic.ts +49 -0
- package/src/opik/rest_api/serialization/types/FeedbackScore.ts +35 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreAverage.ts +22 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreAveragePublic.ts +22 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreBatch.ts +21 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreBatchItem.ts +33 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreBatchItemSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreCompare.ts +37 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreCompareSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/FeedbackScorePublic.ts +37 -0
- package/src/opik/rest_api/serialization/types/FeedbackScorePublicSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/FeedbackScoreSource.ts +16 -0
- package/src/opik/rest_api/serialization/types/FeedbackUpdate.ts +41 -0
- package/src/opik/rest_api/serialization/types/Function.ts +25 -0
- package/src/opik/rest_api/serialization/types/FunctionCall.ts +20 -0
- package/src/opik/rest_api/serialization/types/JsonNode.ts +14 -0
- package/src/opik/rest_api/serialization/types/JsonNodeCompare.ts +14 -0
- package/src/opik/rest_api/serialization/types/JsonNodePublic.ts +14 -0
- package/src/opik/rest_api/serialization/types/JsonNodeWrite.ts +14 -0
- package/src/opik/rest_api/serialization/types/JsonObjectSchema.ts +34 -0
- package/src/opik/rest_api/serialization/types/JsonSchema.ts +23 -0
- package/src/opik/rest_api/serialization/types/JsonSchemaElement.ts +20 -0
- package/src/opik/rest_api/serialization/types/Message.ts +16 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDefinition.ts +29 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDefinitionCreate.ts +21 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDefinitionPublic.ts +29 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDefinitionUpdate.ts +21 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDetail.ts +22 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDetailCreate.ts +22 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDetailPublic.ts +22 -0
- package/src/opik/rest_api/serialization/types/NumericalFeedbackDetailUpdate.ts +22 -0
- package/src/opik/rest_api/serialization/types/PageColumns.ts +19 -0
- package/src/opik/rest_api/serialization/types/PercentageValueStatPublic.ts +21 -0
- package/src/opik/rest_api/serialization/types/PercentageValuesPublic.ts +24 -0
- package/src/opik/rest_api/serialization/types/Project.ts +32 -0
- package/src/opik/rest_api/serialization/types/ProjectMetricResponsePublic.ts +29 -0
- package/src/opik/rest_api/serialization/types/ProjectMetricResponsePublicInterval.ts +16 -0
- package/src/opik/rest_api/serialization/types/ProjectMetricResponsePublicMetricType.ts +16 -0
- package/src/opik/rest_api/serialization/types/ProjectPagePublic.ts +29 -0
- package/src/opik/rest_api/serialization/types/ProjectPublic.ts +32 -0
- package/src/opik/rest_api/serialization/types/ProjectStatItemObjectPublic.ts +50 -0
- package/src/opik/rest_api/serialization/types/ProjectStatsPublic.ts +21 -0
- package/src/opik/rest_api/serialization/types/Prompt.ts +37 -0
- package/src/opik/rest_api/serialization/types/PromptDetail.ts +35 -0
- package/src/opik/rest_api/serialization/types/PromptPagePublic.ts +27 -0
- package/src/opik/rest_api/serialization/types/PromptPublic.ts +32 -0
- package/src/opik/rest_api/serialization/types/PromptVersion.ts +30 -0
- package/src/opik/rest_api/serialization/types/PromptVersionDetail.ts +32 -0
- package/src/opik/rest_api/serialization/types/PromptVersionLink.ts +24 -0
- package/src/opik/rest_api/serialization/types/PromptVersionLinkPublic.ts +24 -0
- package/src/opik/rest_api/serialization/types/PromptVersionLinkWrite.ts +20 -0
- package/src/opik/rest_api/serialization/types/PromptVersionPagePublic.ts +27 -0
- package/src/opik/rest_api/serialization/types/PromptVersionPublic.ts +30 -0
- package/src/opik/rest_api/serialization/types/ProviderApiKey.ts +30 -0
- package/src/opik/rest_api/serialization/types/ProviderApiKeyPublic.ts +30 -0
- package/src/opik/rest_api/serialization/types/ResponseFormat.ts +22 -0
- package/src/opik/rest_api/serialization/types/ResponseFormatType.ts +16 -0
- package/src/opik/rest_api/serialization/types/ResultsNumberPublic.ts +23 -0
- package/src/opik/rest_api/serialization/types/Span.ts +65 -0
- package/src/opik/rest_api/serialization/types/SpanBatch.ts +19 -0
- package/src/opik/rest_api/serialization/types/SpanPagePublic.ts +25 -0
- package/src/opik/rest_api/serialization/types/SpanPublic.ts +67 -0
- package/src/opik/rest_api/serialization/types/SpanPublicType.ts +14 -0
- package/src/opik/rest_api/serialization/types/SpanType.ts +15 -0
- package/src/opik/rest_api/serialization/types/SpanWrite.ts +51 -0
- package/src/opik/rest_api/serialization/types/SpanWriteType.ts +14 -0
- package/src/opik/rest_api/serialization/types/StreamOptions.ts +18 -0
- package/src/opik/rest_api/serialization/types/Tool.ts +20 -0
- package/src/opik/rest_api/serialization/types/ToolCall.ts +25 -0
- package/src/opik/rest_api/serialization/types/Trace.ts +54 -0
- package/src/opik/rest_api/serialization/types/TraceBatch.ts +19 -0
- package/src/opik/rest_api/serialization/types/TraceCountResponse.ts +24 -0
- package/src/opik/rest_api/serialization/types/TracePagePublic.ts +27 -0
- package/src/opik/rest_api/serialization/types/TracePublic.ts +56 -0
- package/src/opik/rest_api/serialization/types/TraceWrite.ts +38 -0
- package/src/opik/rest_api/serialization/types/Usage.ts +27 -0
- package/src/opik/rest_api/serialization/types/WorkspaceTraceCount.ts +22 -0
- package/src/opik/rest_api/serialization/types/index.ts +138 -0
- package/src/opik/tracer/Span.ts +34 -0
- package/src/opik/tracer/Trace.ts +61 -0
- package/tests/client.test.ts +25 -0
- package/tsconfig.json +25 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { MaybeValid, Schema, SchemaType, ValidationError } from "../../Schema";
|
|
2
|
+
import { entries } from "../../utils/entries";
|
|
3
|
+
import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType";
|
|
4
|
+
import { isPlainObject } from "../../utils/isPlainObject";
|
|
5
|
+
import { maybeSkipValidation } from "../../utils/maybeSkipValidation";
|
|
6
|
+
import { getSchemaUtils } from "../schema-utils";
|
|
7
|
+
import { BaseRecordSchema, RecordSchema } from "./types";
|
|
8
|
+
|
|
9
|
+
export function record<RawKey extends string | number, RawValue, ParsedValue, ParsedKey extends string | number>(
|
|
10
|
+
keySchema: Schema<RawKey, ParsedKey>,
|
|
11
|
+
valueSchema: Schema<RawValue, ParsedValue>
|
|
12
|
+
): RecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> {
|
|
13
|
+
const baseSchema: BaseRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> = {
|
|
14
|
+
parse: (raw, opts) => {
|
|
15
|
+
return validateAndTransformRecord({
|
|
16
|
+
value: raw,
|
|
17
|
+
isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
|
|
18
|
+
transformKey: (key) =>
|
|
19
|
+
keySchema.parse(key, {
|
|
20
|
+
...opts,
|
|
21
|
+
breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`],
|
|
22
|
+
}),
|
|
23
|
+
transformValue: (value, key) =>
|
|
24
|
+
valueSchema.parse(value, {
|
|
25
|
+
...opts,
|
|
26
|
+
breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`],
|
|
27
|
+
}),
|
|
28
|
+
breadcrumbsPrefix: opts?.breadcrumbsPrefix,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
json: (parsed, opts) => {
|
|
32
|
+
return validateAndTransformRecord({
|
|
33
|
+
value: parsed,
|
|
34
|
+
isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
|
|
35
|
+
transformKey: (key) =>
|
|
36
|
+
keySchema.json(key, {
|
|
37
|
+
...opts,
|
|
38
|
+
breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`],
|
|
39
|
+
}),
|
|
40
|
+
transformValue: (value, key) =>
|
|
41
|
+
valueSchema.json(value, {
|
|
42
|
+
...opts,
|
|
43
|
+
breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`],
|
|
44
|
+
}),
|
|
45
|
+
breadcrumbsPrefix: opts?.breadcrumbsPrefix,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
getType: () => SchemaType.RECORD,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...maybeSkipValidation(baseSchema),
|
|
53
|
+
...getSchemaUtils(baseSchema),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function validateAndTransformRecord<TransformedKey extends string | number, TransformedValue>({
|
|
58
|
+
value,
|
|
59
|
+
isKeyNumeric,
|
|
60
|
+
transformKey,
|
|
61
|
+
transformValue,
|
|
62
|
+
breadcrumbsPrefix = [],
|
|
63
|
+
}: {
|
|
64
|
+
value: unknown;
|
|
65
|
+
isKeyNumeric: boolean;
|
|
66
|
+
transformKey: (key: string | number) => MaybeValid<TransformedKey>;
|
|
67
|
+
transformValue: (value: unknown, key: string | number) => MaybeValid<TransformedValue>;
|
|
68
|
+
breadcrumbsPrefix: string[] | undefined;
|
|
69
|
+
}): MaybeValid<Record<TransformedKey, TransformedValue>> {
|
|
70
|
+
if (!isPlainObject(value)) {
|
|
71
|
+
return {
|
|
72
|
+
ok: false,
|
|
73
|
+
errors: [
|
|
74
|
+
{
|
|
75
|
+
path: breadcrumbsPrefix,
|
|
76
|
+
message: getErrorMessageForIncorrectType(value, "object"),
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return entries(value).reduce<MaybeValid<Record<TransformedKey, TransformedValue>>>(
|
|
83
|
+
(accPromise, [stringKey, value]) => {
|
|
84
|
+
// skip nullish keys
|
|
85
|
+
if (value == null) {
|
|
86
|
+
return accPromise;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const acc = accPromise;
|
|
90
|
+
|
|
91
|
+
let key: string | number = stringKey;
|
|
92
|
+
if (isKeyNumeric) {
|
|
93
|
+
const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
|
|
94
|
+
if (!isNaN(numberKey)) {
|
|
95
|
+
key = numberKey;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const transformedKey = transformKey(key);
|
|
99
|
+
|
|
100
|
+
const transformedValue = transformValue(value, key);
|
|
101
|
+
|
|
102
|
+
if (acc.ok && transformedKey.ok && transformedValue.ok) {
|
|
103
|
+
return {
|
|
104
|
+
ok: true,
|
|
105
|
+
value: {
|
|
106
|
+
...acc.value,
|
|
107
|
+
[transformedKey.value]: transformedValue.value,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const errors: ValidationError[] = [];
|
|
113
|
+
if (!acc.ok) {
|
|
114
|
+
errors.push(...acc.errors);
|
|
115
|
+
}
|
|
116
|
+
if (!transformedKey.ok) {
|
|
117
|
+
errors.push(...transformedKey.errors);
|
|
118
|
+
}
|
|
119
|
+
if (!transformedValue.ok) {
|
|
120
|
+
errors.push(...transformedValue.errors);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
ok: false,
|
|
125
|
+
errors,
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
{ ok: true, value: {} as Record<TransformedKey, TransformedValue> }
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseSchema } from "../../Schema";
|
|
2
|
+
import { SchemaUtils } from "../schema-utils";
|
|
3
|
+
|
|
4
|
+
export type RecordSchema<
|
|
5
|
+
RawKey extends string | number,
|
|
6
|
+
RawValue,
|
|
7
|
+
ParsedKey extends string | number,
|
|
8
|
+
ParsedValue
|
|
9
|
+
> = BaseRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> &
|
|
10
|
+
SchemaUtils<Record<RawKey, RawValue>, Record<ParsedKey, ParsedValue>>;
|
|
11
|
+
|
|
12
|
+
export type BaseRecordSchema<
|
|
13
|
+
RawKey extends string | number,
|
|
14
|
+
RawValue,
|
|
15
|
+
ParsedKey extends string | number,
|
|
16
|
+
ParsedValue
|
|
17
|
+
> = BaseSchema<Record<RawKey, RawValue>, Record<ParsedKey, ParsedValue>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidationError } from "../../Schema";
|
|
2
|
+
import { stringifyValidationError } from "./stringifyValidationErrors";
|
|
3
|
+
|
|
4
|
+
export class JsonError extends Error {
|
|
5
|
+
constructor(public readonly errors: ValidationError[]) {
|
|
6
|
+
super(errors.map(stringifyValidationError).join("; "));
|
|
7
|
+
Object.setPrototypeOf(this, JsonError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidationError } from "../../Schema";
|
|
2
|
+
import { stringifyValidationError } from "./stringifyValidationErrors";
|
|
3
|
+
|
|
4
|
+
export class ParseError extends Error {
|
|
5
|
+
constructor(public readonly errors: ValidationError[]) {
|
|
6
|
+
super(errors.map(stringifyValidationError).join("; "));
|
|
7
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { BaseSchema, Schema, SchemaOptions, SchemaType } from "../../Schema";
|
|
2
|
+
import { JsonError } from "./JsonError";
|
|
3
|
+
import { ParseError } from "./ParseError";
|
|
4
|
+
|
|
5
|
+
export interface SchemaUtils<Raw, Parsed> {
|
|
6
|
+
optional: () => Schema<Raw | null | undefined, Parsed | undefined>;
|
|
7
|
+
transform: <Transformed>(transformer: SchemaTransformer<Parsed, Transformed>) => Schema<Raw, Transformed>;
|
|
8
|
+
parseOrThrow: (raw: unknown, opts?: SchemaOptions) => Parsed;
|
|
9
|
+
jsonOrThrow: (raw: unknown, opts?: SchemaOptions) => Raw;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SchemaTransformer<Parsed, Transformed> {
|
|
13
|
+
transform: (parsed: Parsed) => Transformed;
|
|
14
|
+
untransform: (transformed: any) => Parsed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getSchemaUtils<Raw, Parsed>(schema: BaseSchema<Raw, Parsed>): SchemaUtils<Raw, Parsed> {
|
|
18
|
+
return {
|
|
19
|
+
optional: () => optional(schema),
|
|
20
|
+
transform: (transformer) => transform(schema, transformer),
|
|
21
|
+
parseOrThrow: (raw, opts) => {
|
|
22
|
+
const parsed = schema.parse(raw, opts);
|
|
23
|
+
if (parsed.ok) {
|
|
24
|
+
return parsed.value;
|
|
25
|
+
}
|
|
26
|
+
throw new ParseError(parsed.errors);
|
|
27
|
+
},
|
|
28
|
+
jsonOrThrow: (parsed, opts) => {
|
|
29
|
+
const raw = schema.json(parsed, opts);
|
|
30
|
+
if (raw.ok) {
|
|
31
|
+
return raw.value;
|
|
32
|
+
}
|
|
33
|
+
throw new JsonError(raw.errors);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* schema utils are defined in one file to resolve issues with circular imports
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export function optional<Raw, Parsed>(
|
|
43
|
+
schema: BaseSchema<Raw, Parsed>
|
|
44
|
+
): Schema<Raw | null | undefined, Parsed | undefined> {
|
|
45
|
+
const baseSchema: BaseSchema<Raw | null | undefined, Parsed | undefined> = {
|
|
46
|
+
parse: (raw, opts) => {
|
|
47
|
+
if (raw == null) {
|
|
48
|
+
return {
|
|
49
|
+
ok: true,
|
|
50
|
+
value: undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return schema.parse(raw, opts);
|
|
54
|
+
},
|
|
55
|
+
json: (parsed, opts) => {
|
|
56
|
+
if (opts?.omitUndefined && parsed === undefined) {
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
value: undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (parsed == null) {
|
|
63
|
+
return {
|
|
64
|
+
ok: true,
|
|
65
|
+
value: null,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return schema.json(parsed, opts);
|
|
69
|
+
},
|
|
70
|
+
getType: () => SchemaType.OPTIONAL,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...baseSchema,
|
|
75
|
+
...getSchemaUtils(baseSchema),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function transform<Raw, Parsed, Transformed>(
|
|
80
|
+
schema: BaseSchema<Raw, Parsed>,
|
|
81
|
+
transformer: SchemaTransformer<Parsed, Transformed>
|
|
82
|
+
): Schema<Raw, Transformed> {
|
|
83
|
+
const baseSchema: BaseSchema<Raw, Transformed> = {
|
|
84
|
+
parse: (raw, opts) => {
|
|
85
|
+
const parsed = schema.parse(raw, opts);
|
|
86
|
+
if (!parsed.ok) {
|
|
87
|
+
return parsed;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
ok: true,
|
|
91
|
+
value: transformer.transform(parsed.value),
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
json: (transformed, opts) => {
|
|
95
|
+
const parsed = transformer.untransform(transformed);
|
|
96
|
+
return schema.json(parsed, opts);
|
|
97
|
+
},
|
|
98
|
+
getType: () => schema.getType(),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...baseSchema,
|
|
103
|
+
...getSchemaUtils(baseSchema),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { set } from "./set";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BaseSchema, Schema, SchemaType } from "../../Schema";
|
|
2
|
+
import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType";
|
|
3
|
+
import { maybeSkipValidation } from "../../utils/maybeSkipValidation";
|
|
4
|
+
import { list } from "../list";
|
|
5
|
+
import { getSchemaUtils } from "../schema-utils";
|
|
6
|
+
|
|
7
|
+
export function set<Raw, Parsed>(schema: Schema<Raw, Parsed>): Schema<Raw[], Set<Parsed>> {
|
|
8
|
+
const listSchema = list(schema);
|
|
9
|
+
const baseSchema: BaseSchema<Raw[], Set<Parsed>> = {
|
|
10
|
+
parse: (raw, opts) => {
|
|
11
|
+
const parsedList = listSchema.parse(raw, opts);
|
|
12
|
+
if (parsedList.ok) {
|
|
13
|
+
return {
|
|
14
|
+
ok: true,
|
|
15
|
+
value: new Set(parsedList.value),
|
|
16
|
+
};
|
|
17
|
+
} else {
|
|
18
|
+
return parsedList;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
json: (parsed, opts) => {
|
|
22
|
+
if (!(parsed instanceof Set)) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
errors: [
|
|
26
|
+
{
|
|
27
|
+
path: opts?.breadcrumbsPrefix ?? [],
|
|
28
|
+
message: getErrorMessageForIncorrectType(parsed, "Set"),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const jsonList = listSchema.json([...parsed], opts);
|
|
34
|
+
return jsonList;
|
|
35
|
+
},
|
|
36
|
+
getType: () => SchemaType.SET,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...maybeSkipValidation(baseSchema),
|
|
41
|
+
...getSchemaUtils(baseSchema),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { inferParsed, inferRaw, Schema } from "../../Schema";
|
|
2
|
+
|
|
3
|
+
export type UndiscriminatedUnionSchema<Schemas extends [...Schema[]]> = Schema<
|
|
4
|
+
inferRawUnidiscriminatedUnionSchema<Schemas>,
|
|
5
|
+
inferParsedUnidiscriminatedUnionSchema<Schemas>
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
export type inferRawUnidiscriminatedUnionSchema<Schemas extends [...Schema[]]> = inferRaw<Schemas[number]>;
|
|
9
|
+
|
|
10
|
+
export type inferParsedUnidiscriminatedUnionSchema<Schemas extends [...Schema[]]> = inferParsed<Schemas[number]>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseSchema, MaybeValid, Schema, SchemaOptions, SchemaType, ValidationError } from "../../Schema";
|
|
2
|
+
import { maybeSkipValidation } from "../../utils/maybeSkipValidation";
|
|
3
|
+
import { getSchemaUtils } from "../schema-utils";
|
|
4
|
+
import { inferParsedUnidiscriminatedUnionSchema, inferRawUnidiscriminatedUnionSchema } from "./types";
|
|
5
|
+
|
|
6
|
+
export function undiscriminatedUnion<Schemas extends [Schema<any, any>, ...Schema<any, any>[]]>(
|
|
7
|
+
schemas: Schemas
|
|
8
|
+
): Schema<inferRawUnidiscriminatedUnionSchema<Schemas>, inferParsedUnidiscriminatedUnionSchema<Schemas>> {
|
|
9
|
+
const baseSchema: BaseSchema<
|
|
10
|
+
inferRawUnidiscriminatedUnionSchema<Schemas>,
|
|
11
|
+
inferParsedUnidiscriminatedUnionSchema<Schemas>
|
|
12
|
+
> = {
|
|
13
|
+
parse: (raw, opts) => {
|
|
14
|
+
return validateAndTransformUndiscriminatedUnion<inferParsedUnidiscriminatedUnionSchema<Schemas>>(
|
|
15
|
+
(schema, opts) => schema.parse(raw, opts),
|
|
16
|
+
schemas,
|
|
17
|
+
opts
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
json: (parsed, opts) => {
|
|
21
|
+
return validateAndTransformUndiscriminatedUnion<inferRawUnidiscriminatedUnionSchema<Schemas>>(
|
|
22
|
+
(schema, opts) => schema.json(parsed, opts),
|
|
23
|
+
schemas,
|
|
24
|
+
opts
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
getType: () => SchemaType.UNDISCRIMINATED_UNION,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
...maybeSkipValidation(baseSchema),
|
|
32
|
+
...getSchemaUtils(baseSchema),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function validateAndTransformUndiscriminatedUnion<Transformed>(
|
|
37
|
+
transform: (schema: Schema<any, any>, opts: SchemaOptions) => MaybeValid<Transformed>,
|
|
38
|
+
schemas: Schema<any, any>[],
|
|
39
|
+
opts: SchemaOptions | undefined
|
|
40
|
+
): MaybeValid<Transformed> {
|
|
41
|
+
const errors: ValidationError[] = [];
|
|
42
|
+
for (const [index, schema] of schemas.entries()) {
|
|
43
|
+
const transformed = transform(schema, { ...opts, skipValidation: false });
|
|
44
|
+
if (transformed.ok) {
|
|
45
|
+
return transformed;
|
|
46
|
+
} else {
|
|
47
|
+
for (const error of transformed.errors) {
|
|
48
|
+
errors.push({
|
|
49
|
+
path: error.path,
|
|
50
|
+
message: `[Variant ${index}] ${error.message}`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
ok: false,
|
|
58
|
+
errors,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function discriminant<RawDiscriminant extends string, ParsedDiscriminant extends string>(
|
|
2
|
+
parsedDiscriminant: ParsedDiscriminant,
|
|
3
|
+
rawDiscriminant: RawDiscriminant
|
|
4
|
+
): Discriminant<RawDiscriminant, ParsedDiscriminant> {
|
|
5
|
+
return {
|
|
6
|
+
parsedDiscriminant,
|
|
7
|
+
rawDiscriminant,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Discriminant<RawDiscriminant extends string, ParsedDiscriminant extends string> {
|
|
12
|
+
parsedDiscriminant: ParsedDiscriminant;
|
|
13
|
+
rawDiscriminant: RawDiscriminant;
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { discriminant } from "./discriminant";
|
|
2
|
+
export type { Discriminant } from "./discriminant";
|
|
3
|
+
export type {
|
|
4
|
+
inferParsedDiscriminant,
|
|
5
|
+
inferParsedUnion,
|
|
6
|
+
inferRawDiscriminant,
|
|
7
|
+
inferRawUnion,
|
|
8
|
+
UnionSubtypes,
|
|
9
|
+
} from "./types";
|
|
10
|
+
export { union } from "./union";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { inferParsedObject, inferRawObject, ObjectSchema } from "../object";
|
|
2
|
+
import { Discriminant } from "./discriminant";
|
|
3
|
+
|
|
4
|
+
export type UnionSubtypes<DiscriminantValues extends string | number | symbol> = {
|
|
5
|
+
[K in DiscriminantValues]: ObjectSchema<any, any>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type inferRawUnion<D extends string | Discriminant<any, any>, U extends UnionSubtypes<keyof U>> = {
|
|
9
|
+
[K in keyof U]: Record<inferRawDiscriminant<D>, K> & inferRawObject<U[K]>;
|
|
10
|
+
}[keyof U];
|
|
11
|
+
|
|
12
|
+
export type inferParsedUnion<D extends string | Discriminant<any, any>, U extends UnionSubtypes<keyof U>> = {
|
|
13
|
+
[K in keyof U]: Record<inferParsedDiscriminant<D>, K> & inferParsedObject<U[K]>;
|
|
14
|
+
}[keyof U];
|
|
15
|
+
|
|
16
|
+
export type inferRawDiscriminant<D extends string | Discriminant<any, any>> = D extends string
|
|
17
|
+
? D
|
|
18
|
+
: D extends Discriminant<infer Raw, any>
|
|
19
|
+
? Raw
|
|
20
|
+
: never;
|
|
21
|
+
|
|
22
|
+
export type inferParsedDiscriminant<D extends string | Discriminant<any, any>> = D extends string
|
|
23
|
+
? D
|
|
24
|
+
: D extends Discriminant<any, infer Parsed>
|
|
25
|
+
? Parsed
|
|
26
|
+
: never;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { BaseSchema, MaybeValid, SchemaType } from "../../Schema";
|
|
2
|
+
import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType";
|
|
3
|
+
import { isPlainObject } from "../../utils/isPlainObject";
|
|
4
|
+
import { keys } from "../../utils/keys";
|
|
5
|
+
import { maybeSkipValidation } from "../../utils/maybeSkipValidation";
|
|
6
|
+
import { enum_ } from "../enum";
|
|
7
|
+
import { ObjectSchema } from "../object";
|
|
8
|
+
import { getObjectLikeUtils, ObjectLikeSchema } from "../object-like";
|
|
9
|
+
import { getSchemaUtils } from "../schema-utils";
|
|
10
|
+
import { Discriminant } from "./discriminant";
|
|
11
|
+
import { inferParsedDiscriminant, inferParsedUnion, inferRawDiscriminant, inferRawUnion, UnionSubtypes } from "./types";
|
|
12
|
+
|
|
13
|
+
export function union<D extends string | Discriminant<any, any>, U extends UnionSubtypes<any>>(
|
|
14
|
+
discriminant: D,
|
|
15
|
+
union: U
|
|
16
|
+
): ObjectLikeSchema<inferRawUnion<D, U>, inferParsedUnion<D, U>> {
|
|
17
|
+
const rawDiscriminant =
|
|
18
|
+
typeof discriminant === "string" ? discriminant : (discriminant.rawDiscriminant as inferRawDiscriminant<D>);
|
|
19
|
+
const parsedDiscriminant =
|
|
20
|
+
typeof discriminant === "string"
|
|
21
|
+
? discriminant
|
|
22
|
+
: (discriminant.parsedDiscriminant as inferParsedDiscriminant<D>);
|
|
23
|
+
|
|
24
|
+
const discriminantValueSchema = enum_(keys(union) as string[]);
|
|
25
|
+
|
|
26
|
+
const baseSchema: BaseSchema<inferRawUnion<D, U>, inferParsedUnion<D, U>> = {
|
|
27
|
+
parse: (raw, opts) => {
|
|
28
|
+
return transformAndValidateUnion({
|
|
29
|
+
value: raw,
|
|
30
|
+
discriminant: rawDiscriminant,
|
|
31
|
+
transformedDiscriminant: parsedDiscriminant,
|
|
32
|
+
transformDiscriminantValue: (discriminantValue) =>
|
|
33
|
+
discriminantValueSchema.parse(discriminantValue, {
|
|
34
|
+
allowUnrecognizedEnumValues: opts?.allowUnrecognizedUnionMembers,
|
|
35
|
+
breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), rawDiscriminant],
|
|
36
|
+
}),
|
|
37
|
+
getAdditionalPropertiesSchema: (discriminantValue) => union[discriminantValue],
|
|
38
|
+
allowUnrecognizedUnionMembers: opts?.allowUnrecognizedUnionMembers,
|
|
39
|
+
transformAdditionalProperties: (additionalProperties, additionalPropertiesSchema) =>
|
|
40
|
+
additionalPropertiesSchema.parse(additionalProperties, opts),
|
|
41
|
+
breadcrumbsPrefix: opts?.breadcrumbsPrefix,
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
json: (parsed, opts) => {
|
|
45
|
+
return transformAndValidateUnion({
|
|
46
|
+
value: parsed,
|
|
47
|
+
discriminant: parsedDiscriminant,
|
|
48
|
+
transformedDiscriminant: rawDiscriminant,
|
|
49
|
+
transformDiscriminantValue: (discriminantValue) =>
|
|
50
|
+
discriminantValueSchema.json(discriminantValue, {
|
|
51
|
+
allowUnrecognizedEnumValues: opts?.allowUnrecognizedUnionMembers,
|
|
52
|
+
breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), parsedDiscriminant],
|
|
53
|
+
}),
|
|
54
|
+
getAdditionalPropertiesSchema: (discriminantValue) => union[discriminantValue],
|
|
55
|
+
allowUnrecognizedUnionMembers: opts?.allowUnrecognizedUnionMembers,
|
|
56
|
+
transformAdditionalProperties: (additionalProperties, additionalPropertiesSchema) =>
|
|
57
|
+
additionalPropertiesSchema.json(additionalProperties, opts),
|
|
58
|
+
breadcrumbsPrefix: opts?.breadcrumbsPrefix,
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
getType: () => SchemaType.UNION,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...maybeSkipValidation(baseSchema),
|
|
66
|
+
...getSchemaUtils(baseSchema),
|
|
67
|
+
...getObjectLikeUtils(baseSchema),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function transformAndValidateUnion<
|
|
72
|
+
TransformedDiscriminant extends string,
|
|
73
|
+
TransformedDiscriminantValue extends string,
|
|
74
|
+
TransformedAdditionalProperties
|
|
75
|
+
>({
|
|
76
|
+
value,
|
|
77
|
+
discriminant,
|
|
78
|
+
transformedDiscriminant,
|
|
79
|
+
transformDiscriminantValue,
|
|
80
|
+
getAdditionalPropertiesSchema,
|
|
81
|
+
allowUnrecognizedUnionMembers = false,
|
|
82
|
+
transformAdditionalProperties,
|
|
83
|
+
breadcrumbsPrefix = [],
|
|
84
|
+
}: {
|
|
85
|
+
value: unknown;
|
|
86
|
+
discriminant: string;
|
|
87
|
+
transformedDiscriminant: TransformedDiscriminant;
|
|
88
|
+
transformDiscriminantValue: (discriminantValue: unknown) => MaybeValid<TransformedDiscriminantValue>;
|
|
89
|
+
getAdditionalPropertiesSchema: (discriminantValue: string) => ObjectSchema<any, any> | undefined;
|
|
90
|
+
allowUnrecognizedUnionMembers: boolean | undefined;
|
|
91
|
+
transformAdditionalProperties: (
|
|
92
|
+
additionalProperties: unknown,
|
|
93
|
+
additionalPropertiesSchema: ObjectSchema<any, any>
|
|
94
|
+
) => MaybeValid<TransformedAdditionalProperties>;
|
|
95
|
+
breadcrumbsPrefix: string[] | undefined;
|
|
96
|
+
}): MaybeValid<Record<TransformedDiscriminant, TransformedDiscriminantValue> & TransformedAdditionalProperties> {
|
|
97
|
+
if (!isPlainObject(value)) {
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
errors: [
|
|
101
|
+
{
|
|
102
|
+
path: breadcrumbsPrefix,
|
|
103
|
+
message: getErrorMessageForIncorrectType(value, "object"),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const { [discriminant]: discriminantValue, ...additionalProperties } = value;
|
|
110
|
+
|
|
111
|
+
if (discriminantValue == null) {
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
errors: [
|
|
115
|
+
{
|
|
116
|
+
path: breadcrumbsPrefix,
|
|
117
|
+
message: `Missing discriminant ("${discriminant}")`,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const transformedDiscriminantValue = transformDiscriminantValue(discriminantValue);
|
|
124
|
+
if (!transformedDiscriminantValue.ok) {
|
|
125
|
+
return {
|
|
126
|
+
ok: false,
|
|
127
|
+
errors: transformedDiscriminantValue.errors,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const additionalPropertiesSchema = getAdditionalPropertiesSchema(transformedDiscriminantValue.value);
|
|
132
|
+
|
|
133
|
+
if (additionalPropertiesSchema == null) {
|
|
134
|
+
if (allowUnrecognizedUnionMembers) {
|
|
135
|
+
return {
|
|
136
|
+
ok: true,
|
|
137
|
+
value: {
|
|
138
|
+
[transformedDiscriminant]: transformedDiscriminantValue.value,
|
|
139
|
+
...additionalProperties,
|
|
140
|
+
} as Record<TransformedDiscriminant, TransformedDiscriminantValue> & TransformedAdditionalProperties,
|
|
141
|
+
};
|
|
142
|
+
} else {
|
|
143
|
+
return {
|
|
144
|
+
ok: false,
|
|
145
|
+
errors: [
|
|
146
|
+
{
|
|
147
|
+
path: [...breadcrumbsPrefix, discriminant],
|
|
148
|
+
message: "Unexpected discriminant value",
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const transformedAdditionalProperties = transformAdditionalProperties(
|
|
156
|
+
additionalProperties,
|
|
157
|
+
additionalPropertiesSchema
|
|
158
|
+
);
|
|
159
|
+
if (!transformedAdditionalProperties.ok) {
|
|
160
|
+
return transformedAdditionalProperties;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
ok: true,
|
|
165
|
+
value: {
|
|
166
|
+
[transformedDiscriminant]: discriminantValue,
|
|
167
|
+
...transformedAdditionalProperties.value,
|
|
168
|
+
} as Record<TransformedDiscriminant, TransformedDiscriminantValue> & TransformedAdditionalProperties,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type addQuestionMarksToNullableProperties<T> = {
|
|
2
|
+
[K in OptionalKeys<T>]?: T[K];
|
|
3
|
+
} & Pick<T, RequiredKeys<T>>;
|
|
4
|
+
|
|
5
|
+
export type OptionalKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: undefined extends T[K]
|
|
7
|
+
? K
|
|
8
|
+
: null extends T[K]
|
|
9
|
+
? K
|
|
10
|
+
: 1 extends (any extends T[K] ? 0 : 1)
|
|
11
|
+
? never
|
|
12
|
+
: K;
|
|
13
|
+
}[keyof T];
|
|
14
|
+
|
|
15
|
+
export type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;
|