{"version":3,"file":"get-single.mjs","names":["documentServices.client.getSingle"],"sources":["../../../../src/libs/toolkit/documents/get-single.ts"],"sourcesContent":["import { documentServices } from \"../../../services/index.js\";\nimport type {\n\tCollectionDocument,\n\tCollectionDocumentKey,\n\tCollectionDocumentSingleQuery,\n} from \"../../../types.js\";\nimport type {\n\tServiceContext,\n\tServiceResponse,\n} from \"../../../utils/services/types.js\";\nimport type { ToolkitTenantOptions } from \"../types.js\";\nimport {\n\tnormalizeDocumentQuery,\n\trunToolkitService,\n\twithToolkitTenant,\n} from \"../utils.js\";\nimport type { ToolkitDocumentVersion } from \"./index.js\";\n\nexport type ToolkitDocumentsGetSingleQuery<\n\tTCollectionKey extends CollectionDocumentKey = CollectionDocumentKey,\n> = Omit<CollectionDocumentSingleQuery<TCollectionKey>, never>;\n\nexport type ToolkitDocumentsGetSingleInput<\n\tTCollectionKey extends CollectionDocumentKey = CollectionDocumentKey,\n> = ToolkitTenantOptions & {\n\tcollectionKey: TCollectionKey;\n\tversion: ToolkitDocumentVersion<TCollectionKey>;\n\t/** Optional preview context that may override the requested version. */\n\tpreview?: string | null;\n\tquery?: ToolkitDocumentsGetSingleQuery<TCollectionKey>;\n};\n\nconst getSingle = async <TCollectionKey extends CollectionDocumentKey>(\n\tcontext: ServiceContext,\n\tinput: ToolkitDocumentsGetSingleInput<TCollectionKey>,\n): ServiceResponse<CollectionDocument<TCollectionKey>> => {\n\tconst serviceContext = withToolkitTenant(context, input);\n\n\treturn runToolkitService(\n\t\t() =>\n\t\t\tdocumentServices.client.getSingle(serviceContext, {\n\t\t\t\tcollectionKey: input.collectionKey,\n\t\t\t\tversionType: input.version,\n\t\t\t\tpreview: input.preview ?? undefined,\n\t\t\t\tquery: normalizeDocumentQuery(input.query),\n\t\t\t}),\n\t\t{\n\t\t\tname: {\n\t\t\t\tkey: \"core.toolkit.documents.get.single.error.name\",\n\t\t\t\tdefaultMessage: \"Documents Toolkit Error\",\n\t\t\t},\n\t\t\tmessage: {\n\t\t\t\tkey: \"core.toolkit.documents.get.single.error.message\",\n\t\t\t\tdefaultMessage: \"Lucid toolkit could not fetch a document.\",\n\t\t\t},\n\t\t},\n\t);\n};\n\nexport default getSingle;\n"],"mappings":"qKAgCA,MAAM,EAAY,MACjB,EACA,IACyD,CACzD,IAAM,EAAiB,EAAkB,EAAS,CAAK,EAEvD,OAAO,MAELA,EAAkC,EAAgB,CACjD,cAAe,EAAM,cACrB,YAAa,EAAM,QACnB,QAAS,EAAM,SAAW,IAAA,GAC1B,MAAO,EAAuB,EAAM,KAAK,CAC1C,CAAC,EACF,CACC,KAAM,CACL,IAAK,+CACL,eAAgB,yBACjB,EACA,QAAS,CACR,IAAK,kDACL,eAAgB,2CACjB,CACD,CACD,CACD"}