better-auth
Version:
The most comprehensive authentication framework for TypeScript.
1 lines • 2.18 kB
Source Map (JSON)
{"version":3,"file":"get-schema.mjs","names":["schema: Record<\n\t\tstring,\n\t\t{\n\t\t\tfields: Record<string, DBFieldAttribute>;\n\t\t\torder: number;\n\t\t}\n\t>","actualFields: Record<string, DBFieldAttribute>","key"],"sources":["../../src/db/get-schema.ts"],"sourcesContent":["import type { BetterAuthOptions } from \"@better-auth/core\";\nimport type { DBFieldAttribute } from \"@better-auth/core/db\";\nimport { getAuthTables } from \".\";\n\nexport function getSchema(config: BetterAuthOptions) {\n\tconst tables = getAuthTables(config);\n\tlet schema: Record<\n\t\tstring,\n\t\t{\n\t\t\tfields: Record<string, DBFieldAttribute>;\n\t\t\torder: number;\n\t\t}\n\t> = {};\n\tfor (const key in tables) {\n\t\tconst table = tables[key]!;\n\t\tconst fields = table.fields;\n\t\tlet actualFields: Record<string, DBFieldAttribute> = {};\n\t\tObject.entries(fields).forEach(([key, field]) => {\n\t\t\tactualFields[field.fieldName || key] = field;\n\t\t\tif (field.references) {\n\t\t\t\tconst refTable = tables[field.references.model];\n\t\t\t\tif (refTable) {\n\t\t\t\t\tactualFields[field.fieldName || key]!.references = {\n\t\t\t\t\t\t...field.references,\n\t\t\t\t\t\tmodel: refTable.modelName,\n\t\t\t\t\t\tfield: field.references.field,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tif (schema[table.modelName]) {\n\t\t\tschema[table.modelName]!.fields = {\n\t\t\t\t...schema[table.modelName]!.fields,\n\t\t\t\t...actualFields,\n\t\t\t};\n\t\t\tcontinue;\n\t\t}\n\t\tschema[table.modelName] = {\n\t\t\tfields: actualFields,\n\t\t\torder: table.order || Infinity,\n\t\t};\n\t}\n\treturn schema;\n}\n"],"mappings":";;;AAIA,SAAgB,UAAU,QAA2B;CACpD,MAAM,uCAAuB,OAAO;CACpC,IAAIA,SAMA,EAAE;AACN,MAAK,MAAM,OAAO,QAAQ;EACzB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,MAAM;EACrB,IAAIC,eAAiD,EAAE;AACvD,SAAO,QAAQ,OAAO,CAAC,SAAS,CAACC,OAAK,WAAW;AAChD,gBAAa,MAAM,aAAaA,SAAO;AACvC,OAAI,MAAM,YAAY;IACrB,MAAM,WAAW,OAAO,MAAM,WAAW;AACzC,QAAI,SACH,cAAa,MAAM,aAAaA,OAAM,aAAa;KAClD,GAAG,MAAM;KACT,OAAO,SAAS;KAChB,OAAO,MAAM,WAAW;KACxB;;IAGF;AACF,MAAI,OAAO,MAAM,YAAY;AAC5B,UAAO,MAAM,WAAY,SAAS;IACjC,GAAG,OAAO,MAAM,WAAY;IAC5B,GAAG;IACH;AACD;;AAED,SAAO,MAAM,aAAa;GACzB,QAAQ;GACR,OAAO,MAAM,SAAS;GACtB;;AAEF,QAAO"}