UNPKG

better-auth

Version:

The most comprehensive authentication framework for TypeScript.

1 lines 2.06 kB
{"version":3,"file":"adapter-base.mjs","names":["adapter: DBAdapter<BetterAuthOptions>"],"sources":["../../src/db/adapter-base.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"@better-auth/core\";\nimport { getAuthTables } from \"@better-auth/core/db\";\nimport type { DBAdapter } from \"@better-auth/core/db/adapter\";\nimport { logger } from \"@better-auth/core/env\";\nimport type { MemoryDB } from \"../adapters/memory-adapter\";\n\nexport async function getBaseAdapter(\n\toptions: BetterAuthOptions,\n\thandleDirectDatabase: (\n\t\toptions: BetterAuthOptions,\n\t) => Promise<DBAdapter<BetterAuthOptions>>,\n): Promise<DBAdapter<BetterAuthOptions>> {\n\tlet adapter: DBAdapter<BetterAuthOptions>;\n\n\tif (!options.database) {\n\t\tconst tables = getAuthTables(options);\n\t\tconst memoryDB = Object.keys(tables).reduce<MemoryDB>((acc, key) => {\n\t\t\tacc[key] = [];\n\t\t\treturn acc;\n\t\t}, {});\n\t\tconst { memoryAdapter } = await import(\"../adapters/memory-adapter\");\n\t\tadapter = memoryAdapter(memoryDB)(options);\n\t} else if (typeof options.database === \"function\") {\n\t\tadapter = options.database(options);\n\t} else {\n\t\tadapter = await handleDirectDatabase(options);\n\t}\n\n\t// patch for 1.3.x to ensure we have a transaction function in the adapter\n\tif (!adapter.transaction) {\n\t\tlogger.warn(\n\t\t\t\"Adapter does not correctly implement transaction function, patching it automatically. Please update your adapter implementation.\",\n\t\t);\n\t\tadapter.transaction = async (cb) => {\n\t\t\treturn cb(adapter);\n\t\t};\n\t}\n\n\treturn adapter;\n}\n"],"mappings":";;;;AAMA,eAAsB,eACrB,SACA,sBAGwC;CACxC,IAAIA;AAEJ,KAAI,CAAC,QAAQ,UAAU;EACtB,MAAM,SAAS,cAAc,QAAQ;EACrC,MAAM,WAAW,OAAO,KAAK,OAAO,CAAC,QAAkB,KAAK,QAAQ;AACnE,OAAI,OAAO,EAAE;AACb,UAAO;KACL,EAAE,CAAC;EACN,MAAM,EAAE,kBAAkB,MAAM,OAAO;AACvC,YAAU,cAAc,SAAS,CAAC,QAAQ;YAChC,OAAO,QAAQ,aAAa,WACtC,WAAU,QAAQ,SAAS,QAAQ;KAEnC,WAAU,MAAM,qBAAqB,QAAQ;AAI9C,KAAI,CAAC,QAAQ,aAAa;AACzB,SAAO,KACN,mIACA;AACD,UAAQ,cAAc,OAAO,OAAO;AACnC,UAAO,GAAG,QAAQ;;;AAIpB,QAAO"}