faire-auth 1.0.0

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.
Files changed (221) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +34 -0
  3. package/dist/access-B5bBI4uT.mjs +39 -0
  4. package/dist/access-Crt-IJ2P.cjs +51 -0
  5. package/dist/adapter-factory-BXei1QRX.mjs +881 -0
  6. package/dist/adapter-factory-DT-_2aHJ.cjs +893 -0
  7. package/dist/adapters/drizzle-adapter/index.cjs +208 -0
  8. package/dist/adapters/drizzle-adapter/index.d.cts +48 -0
  9. package/dist/adapters/drizzle-adapter/index.d.mts +48 -0
  10. package/dist/adapters/drizzle-adapter/index.mjs +207 -0
  11. package/dist/adapters/index.cjs +23 -0
  12. package/dist/adapters/index.d.cts +157 -0
  13. package/dist/adapters/index.d.mts +157 -0
  14. package/dist/adapters/index.mjs +17 -0
  15. package/dist/adapters/kysely-adapter/index.cjs +11 -0
  16. package/dist/adapters/kysely-adapter/index.d.cts +52 -0
  17. package/dist/adapters/kysely-adapter/index.d.mts +52 -0
  18. package/dist/adapters/kysely-adapter/index.mjs +9 -0
  19. package/dist/adapters/memory-adapter/index.cjs +9 -0
  20. package/dist/adapters/memory-adapter/index.d.cts +15 -0
  21. package/dist/adapters/memory-adapter/index.d.mts +15 -0
  22. package/dist/adapters/memory-adapter/index.mjs +9 -0
  23. package/dist/adapters/mongodb-adapter/index.cjs +9 -0
  24. package/dist/adapters/mongodb-adapter/index.d.cts +4 -0
  25. package/dist/adapters/mongodb-adapter/index.d.mts +4 -0
  26. package/dist/adapters/mongodb-adapter/index.mjs +9 -0
  27. package/dist/adapters/prisma-adapter/index.cjs +156 -0
  28. package/dist/adapters/prisma-adapter/index.d.cts +35 -0
  29. package/dist/adapters/prisma-adapter/index.d.mts +35 -0
  30. package/dist/adapters/prisma-adapter/index.mjs +155 -0
  31. package/dist/adapters/test.cjs +797 -0
  32. package/dist/adapters/test.d.cts +82 -0
  33. package/dist/adapters/test.d.mts +82 -0
  34. package/dist/adapters/test.mjs +793 -0
  35. package/dist/api/index.cjs +20 -0
  36. package/dist/api/index.d.cts +3 -0
  37. package/dist/api/index.d.mts +3 -0
  38. package/dist/api/index.mjs +20 -0
  39. package/dist/api/middleware/index.cjs +16 -0
  40. package/dist/api/middleware/index.d.cts +16 -0
  41. package/dist/api/middleware/index.d.mts +16 -0
  42. package/dist/api/middleware/index.mjs +11 -0
  43. package/dist/api-Bm89BLgN.cjs +1899 -0
  44. package/dist/api-_B7qO28y.mjs +1892 -0
  45. package/dist/auth-Bo9PDt5j.cjs +739 -0
  46. package/dist/auth-Ds4AG4h4.mjs +709 -0
  47. package/dist/bearer-0SeEmaS4.mjs +54 -0
  48. package/dist/bearer-CHeREcGT.cjs +60 -0
  49. package/dist/bun-sqlite-dialect-CfkBo2v5.mjs +155 -0
  50. package/dist/bun-sqlite-dialect-wuaC2-gh.cjs +156 -0
  51. package/dist/chunk-Ceigfy4P.mjs +39 -0
  52. package/dist/chunk-oakRccI5.cjs +60 -0
  53. package/dist/client/index.cjs +22 -0
  54. package/dist/client/index.d.cts +8 -0
  55. package/dist/client/index.d.mts +8 -0
  56. package/dist/client/index.mjs +19 -0
  57. package/dist/client/lynx/index.cjs +79 -0
  58. package/dist/client/lynx/index.d.cts +156 -0
  59. package/dist/client/lynx/index.d.mts +156 -0
  60. package/dist/client/lynx/index.mjs +76 -0
  61. package/dist/client/plugins/index.cjs +11 -0
  62. package/dist/client/plugins/index.d.cts +17 -0
  63. package/dist/client/plugins/index.d.mts +17 -0
  64. package/dist/client/plugins/index.mjs +10 -0
  65. package/dist/client/react/index.cjs +79 -0
  66. package/dist/client/react/index.d.cts +156 -0
  67. package/dist/client/react/index.d.mts +156 -0
  68. package/dist/client/react/index.mjs +76 -0
  69. package/dist/client/solid/index.cjs +51 -0
  70. package/dist/client/solid/index.d.cts +90 -0
  71. package/dist/client/solid/index.d.mts +90 -0
  72. package/dist/client/solid/index.mjs +50 -0
  73. package/dist/client/svelte/index.cjs +28 -0
  74. package/dist/client/svelte/index.d.cts +110 -0
  75. package/dist/client/svelte/index.d.mts +110 -0
  76. package/dist/client/svelte/index.mjs +28 -0
  77. package/dist/client/vue/index.cjs +68 -0
  78. package/dist/client/vue/index.d.cts +123 -0
  79. package/dist/client/vue/index.d.mts +123 -0
  80. package/dist/client/vue/index.mjs +67 -0
  81. package/dist/cookies-B5xeA6i8.cjs +456 -0
  82. package/dist/cookies-Ch1JfQIz.mjs +367 -0
  83. package/dist/crypto/index.cjs +11 -0
  84. package/dist/crypto/index.d.cts +22 -0
  85. package/dist/crypto/index.d.mts +22 -0
  86. package/dist/crypto/index.mjs +5 -0
  87. package/dist/crypto-CcTxYH82.cjs +57 -0
  88. package/dist/crypto-CyQRFtkq.mjs +41 -0
  89. package/dist/db/index.cjs +40 -0
  90. package/dist/db/index.d.cts +4 -0
  91. package/dist/db/index.d.mts +4 -0
  92. package/dist/db/index.mjs +16 -0
  93. package/dist/db-BTKyYu-_.cjs +1180 -0
  94. package/dist/db-xiJtoDgz.mjs +1119 -0
  95. package/dist/defu-B0Svx_x4.cjs +34 -0
  96. package/dist/defu-SZkpHhbR.mjs +28 -0
  97. package/dist/email-verification-C-AsfJsb.cjs +247 -0
  98. package/dist/email-verification-CWhj2qfb.mjs +228 -0
  99. package/dist/hono-BEq1NYVX.cjs +526 -0
  100. package/dist/hono-Cdukwu5K.cjs +13 -0
  101. package/dist/hono-CoKYWnXA.mjs +7 -0
  102. package/dist/hono-Covz10jU.mjs +508 -0
  103. package/dist/hono-DOM31WQz.d.cts +18 -0
  104. package/dist/hono-DuE14mmj.d.mts +18 -0
  105. package/dist/index-B-WeOMzg.d.cts +13350 -0
  106. package/dist/index-B09P9p5_.d.cts +33 -0
  107. package/dist/index-B5_0QTLg.d.mts +3 -0
  108. package/dist/index-B7SKyR_a.d.cts +3 -0
  109. package/dist/index-BVHscLQl.d.cts +992 -0
  110. package/dist/index-C2-2QDyS.d.cts +35 -0
  111. package/dist/index-CTwrVluH.d.mts +41 -0
  112. package/dist/index-CWAqWfoZ.d.cts +27 -0
  113. package/dist/index-CYSShrFx.d.mts +27 -0
  114. package/dist/index-Qu-iJGNr.d.mts +992 -0
  115. package/dist/index-cs4Sh0En.d.cts +41 -0
  116. package/dist/index-jlessPI0.d.mts +13350 -0
  117. package/dist/index-ppgcFe12.d.mts +33 -0
  118. package/dist/index-to0RO38U.d.mts +35 -0
  119. package/dist/index.cjs +85 -0
  120. package/dist/index.d.cts +5 -0
  121. package/dist/index.d.mts +5 -0
  122. package/dist/index.mjs +27 -0
  123. package/dist/integrations/next-js.cjs +50 -0
  124. package/dist/integrations/next-js.d.cts +23 -0
  125. package/dist/integrations/next-js.d.mts +23 -0
  126. package/dist/integrations/next-js.mjs +49 -0
  127. package/dist/integrations/node.cjs +139 -0
  128. package/dist/integrations/node.d.cts +22 -0
  129. package/dist/integrations/node.d.mts +22 -0
  130. package/dist/integrations/node.mjs +134 -0
  131. package/dist/integrations/react-start.cjs +37 -0
  132. package/dist/integrations/react-start.d.cts +17 -0
  133. package/dist/integrations/react-start.d.mts +17 -0
  134. package/dist/integrations/react-start.mjs +37 -0
  135. package/dist/integrations/solid-start.cjs +14 -0
  136. package/dist/integrations/solid-start.d.cts +13 -0
  137. package/dist/integrations/solid-start.d.mts +13 -0
  138. package/dist/integrations/solid-start.mjs +13 -0
  139. package/dist/integrations/svelte-kit.cjs +52 -0
  140. package/dist/integrations/svelte-kit.d.cts +42 -0
  141. package/dist/integrations/svelte-kit.d.mts +42 -0
  142. package/dist/integrations/svelte-kit.mjs +49 -0
  143. package/dist/ip-B5SwXaMB.cjs +54 -0
  144. package/dist/ip-BjNYspCH.mjs +36 -0
  145. package/dist/json-B1v2qRTQ.mjs +24 -0
  146. package/dist/json-CcJ2HjGo.cjs +30 -0
  147. package/dist/kysely-adapter-Bxi7sPdG.cjs +288 -0
  148. package/dist/kysely-adapter-DRuoT_X8.mjs +270 -0
  149. package/dist/logged-CyGfp8_H.mjs +187 -0
  150. package/dist/logged-DQK3C64b.cjs +193 -0
  151. package/dist/memory-adapter-BlnDIAAX.cjs +154 -0
  152. package/dist/memory-adapter-Db3tsJTn.mjs +148 -0
  153. package/dist/middleware-CE6OhDkq.mjs +29 -0
  154. package/dist/middleware-CWvRH4EW.cjs +47 -0
  155. package/dist/mongodb-adapter-C_qGQED5.mjs +291 -0
  156. package/dist/mongodb-adapter-C_qfK87x.cjs +297 -0
  157. package/dist/node-sqlite-dialect-BfBzyOAg.mjs +155 -0
  158. package/dist/node-sqlite-dialect-mJWC8LWQ.cjs +156 -0
  159. package/dist/oauth2/index.cjs +25 -0
  160. package/dist/oauth2/index.d.cts +42 -0
  161. package/dist/oauth2/index.d.mts +42 -0
  162. package/dist/oauth2/index.mjs +16 -0
  163. package/dist/oauth2-B8M0lW9l.mjs +159 -0
  164. package/dist/oauth2-BLeOEi7Y.cjs +177 -0
  165. package/dist/origin-check-8Gajklvh.mjs +228 -0
  166. package/dist/origin-check-id9lTnqZ.cjs +246 -0
  167. package/dist/parser-CdncAl9i.cjs +83 -0
  168. package/dist/parser-CeAer-RM.mjs +71 -0
  169. package/dist/passkey-B6N20LSS.cjs +512 -0
  170. package/dist/passkey-DJsR_GX3.mjs +505 -0
  171. package/dist/plugins/access/index.cjs +4 -0
  172. package/dist/plugins/access/index.d.cts +2 -0
  173. package/dist/plugins/access/index.d.mts +2 -0
  174. package/dist/plugins/access/index.mjs +3 -0
  175. package/dist/plugins/bearer/index.cjs +7 -0
  176. package/dist/plugins/bearer/index.d.cts +4 -0
  177. package/dist/plugins/bearer/index.d.mts +4 -0
  178. package/dist/plugins/bearer/index.mjs +7 -0
  179. package/dist/plugins/index.cjs +49 -0
  180. package/dist/plugins/index.d.cts +9326 -0
  181. package/dist/plugins/index.d.mts +9326 -0
  182. package/dist/plugins/index.mjs +26 -0
  183. package/dist/plugins/passkey/index.cjs +15 -0
  184. package/dist/plugins/passkey/index.d.cts +4 -0
  185. package/dist/plugins/passkey/index.d.mts +4 -0
  186. package/dist/plugins/passkey/index.mjs +15 -0
  187. package/dist/plugins-C1lm2Wj3.cjs +5254 -0
  188. package/dist/plugins-Dai1QkRU.mjs +5199 -0
  189. package/dist/request-1NL_1lyJ.mjs +58 -0
  190. package/dist/request-CPNlp-DK.cjs +100 -0
  191. package/dist/schema-D-qjygfE.cjs +179 -0
  192. package/dist/schema-DTIwLLmf.mjs +125 -0
  193. package/dist/session-De9POJTW.cjs +641 -0
  194. package/dist/session-rH8ougDl.mjs +538 -0
  195. package/dist/social-providers/index.cjs +10 -0
  196. package/dist/social-providers/index.d.cts +2 -0
  197. package/dist/social-providers/index.d.mts +2 -0
  198. package/dist/social-providers/index.mjs +5 -0
  199. package/dist/social-providers-DcFNUT0S.cjs +13 -0
  200. package/dist/social-providers-DoYJhBe3.mjs +9 -0
  201. package/dist/state--f7fwIGh.cjs +99 -0
  202. package/dist/state-CqJfCIl9.mjs +86 -0
  203. package/dist/test-utils/index.cjs +27492 -0
  204. package/dist/test-utils/index.d.cts +4584 -0
  205. package/dist/test-utils/index.d.mts +4584 -0
  206. package/dist/test-utils/index.mjs +27490 -0
  207. package/dist/types/index.cjs +0 -0
  208. package/dist/types/index.d.cts +3 -0
  209. package/dist/types/index.d.mts +3 -0
  210. package/dist/types/index.mjs +1 -0
  211. package/dist/url-BoUuoIwZ.mjs +88 -0
  212. package/dist/url-D2yvKaM7.cjs +118 -0
  213. package/dist/utils/cookies.cjs +51 -0
  214. package/dist/utils/cookies.d.cts +179 -0
  215. package/dist/utils/cookies.d.mts +179 -0
  216. package/dist/utils/cookies.mjs +7 -0
  217. package/dist/utils-44aDDP8f.cjs +2 -0
  218. package/dist/utils-D4vZd1-9.mjs +4 -0
  219. package/dist/vanilla-Bu2PmFzE.cjs +30 -0
  220. package/dist/vanilla-TfHqeiC7.mjs +25 -0
  221. package/package.json +470 -0
@@ -0,0 +1,58 @@
1
+ //#region src/utils/request.ts
2
+ const isPromise = (value) => value != null && typeof value.then === "function";
3
+ const normaliseHeaders = (source) => {
4
+ if (source == null) return new Headers();
5
+ let result;
6
+ result = typeof source === "function" ? source() : source;
7
+ if (isPromise(result)) return result.then((h) => new Headers(h));
8
+ return new Headers(result);
9
+ };
10
+ const mergeHeaders = (...sources) => {
11
+ const resolved = sources.filter((v) => v !== void 0).map((src) => src == null ? {} : typeof src === "function" ? src() : src);
12
+ if (!resolved.some((r) => isPromise(r))) {
13
+ const out = new Headers();
14
+ resolved.forEach((h) => new Headers(h).forEach((v, k) => out.set(k, v)));
15
+ return out;
16
+ }
17
+ return async () => {
18
+ const out = new Headers();
19
+ for (const r of resolved) new Headers(isPromise(r) ? await r : r).forEach((v, k) => out.set(k, v));
20
+ return out;
21
+ };
22
+ };
23
+ const buildSearchParams = (query) => {
24
+ const searchParams = new URLSearchParams();
25
+ for (const [k, v] of Object.entries(query)) {
26
+ if (v === void 0) continue;
27
+ if (Array.isArray(v)) for (const v2 of v) searchParams.append(k, v2);
28
+ else searchParams.set(k, v);
29
+ }
30
+ return searchParams;
31
+ };
32
+ const removeIndexString = (urlString) => {
33
+ if (/^https?:\/\/[^\/]+?\/index$/.test(urlString)) return urlString.replace(/\/index$/, "/");
34
+ return urlString.replace(/\/index$/, "");
35
+ };
36
+ const replaceUrlParam = (urlString, params) => {
37
+ for (const [k, v] of Object.entries(params)) {
38
+ const reg = /* @__PURE__ */ new RegExp("/?:" + k + "(?:{[^/]+})?\\??");
39
+ urlString = urlString.replace(reg, (substring) => v ? `${substring[0] === "/" ? "/" : ""}${v}` : "");
40
+ }
41
+ return urlString.replace(/^\/\//, "/");
42
+ };
43
+ const mergePath = (base, path) => {
44
+ if (base == null) return path;
45
+ base = base.replace(/\/+$/, "");
46
+ base = base + "/";
47
+ path = path.replace(/^\/+/, "");
48
+ return base + path;
49
+ };
50
+ const replaceUrlProtocol = (urlString, protocol) => {
51
+ switch (protocol) {
52
+ case "ws": return urlString.replace(/^https?/i, (match) => match.toLowerCase() === "https" ? "wss" : "ws");
53
+ case "http": return urlString.replace(/^wss?/i, (match) => match.toLowerCase() === "wss" ? "https" : "http");
54
+ }
55
+ };
56
+
57
+ //#endregion
58
+ export { removeIndexString as a, normaliseHeaders as i, mergeHeaders as n, replaceUrlParam as o, mergePath as r, replaceUrlProtocol as s, buildSearchParams as t };
@@ -0,0 +1,100 @@
1
+
2
+ //#region src/utils/request.ts
3
+ const isPromise = (value) => value != null && typeof value.then === "function";
4
+ const normaliseHeaders = (source) => {
5
+ if (source == null) return new Headers();
6
+ let result;
7
+ result = typeof source === "function" ? source() : source;
8
+ if (isPromise(result)) return result.then((h) => new Headers(h));
9
+ return new Headers(result);
10
+ };
11
+ const mergeHeaders = (...sources) => {
12
+ const resolved = sources.filter((v) => v !== void 0).map((src) => src == null ? {} : typeof src === "function" ? src() : src);
13
+ if (!resolved.some((r) => isPromise(r))) {
14
+ const out = new Headers();
15
+ resolved.forEach((h) => new Headers(h).forEach((v, k) => out.set(k, v)));
16
+ return out;
17
+ }
18
+ return async () => {
19
+ const out = new Headers();
20
+ for (const r of resolved) new Headers(isPromise(r) ? await r : r).forEach((v, k) => out.set(k, v));
21
+ return out;
22
+ };
23
+ };
24
+ const buildSearchParams = (query) => {
25
+ const searchParams = new URLSearchParams();
26
+ for (const [k, v] of Object.entries(query)) {
27
+ if (v === void 0) continue;
28
+ if (Array.isArray(v)) for (const v2 of v) searchParams.append(k, v2);
29
+ else searchParams.set(k, v);
30
+ }
31
+ return searchParams;
32
+ };
33
+ const removeIndexString = (urlString) => {
34
+ if (/^https?:\/\/[^\/]+?\/index$/.test(urlString)) return urlString.replace(/\/index$/, "/");
35
+ return urlString.replace(/\/index$/, "");
36
+ };
37
+ const replaceUrlParam = (urlString, params) => {
38
+ for (const [k, v] of Object.entries(params)) {
39
+ const reg = /* @__PURE__ */ new RegExp("/?:" + k + "(?:{[^/]+})?\\??");
40
+ urlString = urlString.replace(reg, (substring) => v ? `${substring[0] === "/" ? "/" : ""}${v}` : "");
41
+ }
42
+ return urlString.replace(/^\/\//, "/");
43
+ };
44
+ const mergePath = (base, path) => {
45
+ if (base == null) return path;
46
+ base = base.replace(/\/+$/, "");
47
+ base = base + "/";
48
+ path = path.replace(/^\/+/, "");
49
+ return base + path;
50
+ };
51
+ const replaceUrlProtocol = (urlString, protocol) => {
52
+ switch (protocol) {
53
+ case "ws": return urlString.replace(/^https?/i, (match) => match.toLowerCase() === "https" ? "wss" : "ws");
54
+ case "http": return urlString.replace(/^wss?/i, (match) => match.toLowerCase() === "wss" ? "https" : "http");
55
+ }
56
+ };
57
+
58
+ //#endregion
59
+ Object.defineProperty(exports, 'buildSearchParams', {
60
+ enumerable: true,
61
+ get: function () {
62
+ return buildSearchParams;
63
+ }
64
+ });
65
+ Object.defineProperty(exports, 'mergeHeaders', {
66
+ enumerable: true,
67
+ get: function () {
68
+ return mergeHeaders;
69
+ }
70
+ });
71
+ Object.defineProperty(exports, 'mergePath', {
72
+ enumerable: true,
73
+ get: function () {
74
+ return mergePath;
75
+ }
76
+ });
77
+ Object.defineProperty(exports, 'normaliseHeaders', {
78
+ enumerable: true,
79
+ get: function () {
80
+ return normaliseHeaders;
81
+ }
82
+ });
83
+ Object.defineProperty(exports, 'removeIndexString', {
84
+ enumerable: true,
85
+ get: function () {
86
+ return removeIndexString;
87
+ }
88
+ });
89
+ Object.defineProperty(exports, 'replaceUrlParam', {
90
+ enumerable: true,
91
+ get: function () {
92
+ return replaceUrlParam;
93
+ }
94
+ });
95
+ Object.defineProperty(exports, 'replaceUrlProtocol', {
96
+ enumerable: true,
97
+ get: function () {
98
+ return replaceUrlProtocol;
99
+ }
100
+ });
@@ -0,0 +1,179 @@
1
+ const require_chunk = require('./chunk-oakRccI5.cjs');
2
+ const require_hono = require('./hono-Cdukwu5K.cjs');
3
+ let __faire_auth_core_static = require("@faire-auth/core/static");
4
+
5
+ //#region src/db/schema.ts
6
+ const cache = /* @__PURE__ */ new WeakMap();
7
+ function parseOutputData(data, schema) {
8
+ const fields = schema.fields;
9
+ const parsedData = {};
10
+ for (const key in data) {
11
+ const field = fields[key];
12
+ if (!field) {
13
+ parsedData[key] = data[key];
14
+ continue;
15
+ }
16
+ if (field.returned === false) continue;
17
+ parsedData[key] = data[key];
18
+ }
19
+ return parsedData;
20
+ }
21
+ function getAllFields(options, table) {
22
+ if (!cache.has(options)) cache.set(options, /* @__PURE__ */ new Map());
23
+ const tableCache = cache.get(options);
24
+ if (tableCache.has(table)) return tableCache.get(table);
25
+ let schema = {
26
+ ...table === "user" ? options.user?.additionalFields : {},
27
+ ...table === "session" ? options.session?.additionalFields : {}
28
+ };
29
+ for (const plugin of options.plugins ?? []) if (plugin.schema && plugin.schema[table]) schema = {
30
+ ...schema,
31
+ ...plugin.schema[table].fields
32
+ };
33
+ cache.get(options).set(table, schema);
34
+ return schema;
35
+ }
36
+ function parseUserOutput(options, user) {
37
+ return parseOutputData(user, { fields: getAllFields(options, "user") });
38
+ }
39
+ function parseAccountOutput(options, account) {
40
+ return parseOutputData(account, { fields: getAllFields(options, "account") });
41
+ }
42
+ function parseSessionOutput(options, session) {
43
+ return parseOutputData(session, { fields: getAllFields(options, "session") });
44
+ }
45
+ function parseInputData(data, schema) {
46
+ const ctx = require_hono.getContext();
47
+ const action = schema.action || "create";
48
+ const fields = schema.fields;
49
+ const parsedData = Object.assign(Object.create(null), null);
50
+ let fieldError;
51
+ for (const key in fields) {
52
+ if (key in data) {
53
+ if (fields[key].input === false) {
54
+ if (fields[key].defaultValue !== void 0) {
55
+ if (action !== "update") {
56
+ parsedData[key] = fields[key].defaultValue;
57
+ continue;
58
+ }
59
+ }
60
+ if (data[key]) {
61
+ fieldError = ctx.render({
62
+ success: __faire_auth_core_static.False,
63
+ message: `${key} is not allowed to be set`
64
+ }, 400);
65
+ break;
66
+ }
67
+ continue;
68
+ }
69
+ if (fields[key].validator?.input && data[key] !== void 0) {
70
+ parsedData[key] = fields[key].validator.input["~standard"].validate(data[key]);
71
+ continue;
72
+ }
73
+ if (fields[key].transform?.input && data[key] !== void 0) {
74
+ parsedData[key] = fields[key].transform?.input(data[key]);
75
+ continue;
76
+ }
77
+ parsedData[key] = data[key];
78
+ continue;
79
+ }
80
+ if (fields[key].defaultValue !== void 0 && action === "create") {
81
+ parsedData[key] = fields[key].defaultValue;
82
+ continue;
83
+ }
84
+ if (fields[key].required && action === "create") {
85
+ fieldError = ctx.render({
86
+ success: __faire_auth_core_static.False,
87
+ message: `${key} is required`
88
+ }, 400);
89
+ break;
90
+ }
91
+ }
92
+ if (fieldError) return fieldError;
93
+ return parsedData;
94
+ }
95
+ function parseUserInput(options, user = {}, action) {
96
+ return parseInputData(user, {
97
+ fields: getAllFields(options, "user"),
98
+ action
99
+ });
100
+ }
101
+ function parseAdditionalUserInput(options, user) {
102
+ const schema = getAllFields(options, "user");
103
+ return parseInputData(user || {}, { fields: schema });
104
+ }
105
+ function parseAccountInput(options, account) {
106
+ return parseInputData(account, { fields: getAllFields(options, "account") });
107
+ }
108
+ function parseSessionInput(options, session) {
109
+ return parseInputData(session, { fields: getAllFields(options, "session") });
110
+ }
111
+ function mergeSchema(schema, newSchema) {
112
+ if (!newSchema) return schema;
113
+ for (const table in newSchema) {
114
+ const newModelName = newSchema[table]?.modelName;
115
+ if (newModelName) schema[table].modelName = newModelName;
116
+ for (const field in schema[table].fields) {
117
+ const newField = newSchema[table]?.fields?.[field];
118
+ if (!newField) continue;
119
+ schema[table].fields[field].fieldName = newField;
120
+ }
121
+ }
122
+ return schema;
123
+ }
124
+
125
+ //#endregion
126
+ Object.defineProperty(exports, 'mergeSchema', {
127
+ enumerable: true,
128
+ get: function () {
129
+ return mergeSchema;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, 'parseAccountInput', {
133
+ enumerable: true,
134
+ get: function () {
135
+ return parseAccountInput;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, 'parseAccountOutput', {
139
+ enumerable: true,
140
+ get: function () {
141
+ return parseAccountOutput;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, 'parseAdditionalUserInput', {
145
+ enumerable: true,
146
+ get: function () {
147
+ return parseAdditionalUserInput;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, 'parseInputData', {
151
+ enumerable: true,
152
+ get: function () {
153
+ return parseInputData;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, 'parseSessionInput', {
157
+ enumerable: true,
158
+ get: function () {
159
+ return parseSessionInput;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, 'parseSessionOutput', {
163
+ enumerable: true,
164
+ get: function () {
165
+ return parseSessionOutput;
166
+ }
167
+ });
168
+ Object.defineProperty(exports, 'parseUserInput', {
169
+ enumerable: true,
170
+ get: function () {
171
+ return parseUserInput;
172
+ }
173
+ });
174
+ Object.defineProperty(exports, 'parseUserOutput', {
175
+ enumerable: true,
176
+ get: function () {
177
+ return parseUserOutput;
178
+ }
179
+ });
@@ -0,0 +1,125 @@
1
+ import { n as getContext } from "./hono-CoKYWnXA.mjs";
2
+ import { False } from "@faire-auth/core/static";
3
+
4
+ //#region src/db/schema.ts
5
+ const cache = /* @__PURE__ */ new WeakMap();
6
+ function parseOutputData(data, schema) {
7
+ const fields = schema.fields;
8
+ const parsedData = {};
9
+ for (const key in data) {
10
+ const field = fields[key];
11
+ if (!field) {
12
+ parsedData[key] = data[key];
13
+ continue;
14
+ }
15
+ if (field.returned === false) continue;
16
+ parsedData[key] = data[key];
17
+ }
18
+ return parsedData;
19
+ }
20
+ function getAllFields(options, table) {
21
+ if (!cache.has(options)) cache.set(options, /* @__PURE__ */ new Map());
22
+ const tableCache = cache.get(options);
23
+ if (tableCache.has(table)) return tableCache.get(table);
24
+ let schema = {
25
+ ...table === "user" ? options.user?.additionalFields : {},
26
+ ...table === "session" ? options.session?.additionalFields : {}
27
+ };
28
+ for (const plugin of options.plugins ?? []) if (plugin.schema && plugin.schema[table]) schema = {
29
+ ...schema,
30
+ ...plugin.schema[table].fields
31
+ };
32
+ cache.get(options).set(table, schema);
33
+ return schema;
34
+ }
35
+ function parseUserOutput(options, user) {
36
+ return parseOutputData(user, { fields: getAllFields(options, "user") });
37
+ }
38
+ function parseAccountOutput(options, account) {
39
+ return parseOutputData(account, { fields: getAllFields(options, "account") });
40
+ }
41
+ function parseSessionOutput(options, session) {
42
+ return parseOutputData(session, { fields: getAllFields(options, "session") });
43
+ }
44
+ function parseInputData(data, schema) {
45
+ const ctx = getContext();
46
+ const action = schema.action || "create";
47
+ const fields = schema.fields;
48
+ const parsedData = Object.assign(Object.create(null), null);
49
+ let fieldError;
50
+ for (const key in fields) {
51
+ if (key in data) {
52
+ if (fields[key].input === false) {
53
+ if (fields[key].defaultValue !== void 0) {
54
+ if (action !== "update") {
55
+ parsedData[key] = fields[key].defaultValue;
56
+ continue;
57
+ }
58
+ }
59
+ if (data[key]) {
60
+ fieldError = ctx.render({
61
+ success: False,
62
+ message: `${key} is not allowed to be set`
63
+ }, 400);
64
+ break;
65
+ }
66
+ continue;
67
+ }
68
+ if (fields[key].validator?.input && data[key] !== void 0) {
69
+ parsedData[key] = fields[key].validator.input["~standard"].validate(data[key]);
70
+ continue;
71
+ }
72
+ if (fields[key].transform?.input && data[key] !== void 0) {
73
+ parsedData[key] = fields[key].transform?.input(data[key]);
74
+ continue;
75
+ }
76
+ parsedData[key] = data[key];
77
+ continue;
78
+ }
79
+ if (fields[key].defaultValue !== void 0 && action === "create") {
80
+ parsedData[key] = fields[key].defaultValue;
81
+ continue;
82
+ }
83
+ if (fields[key].required && action === "create") {
84
+ fieldError = ctx.render({
85
+ success: False,
86
+ message: `${key} is required`
87
+ }, 400);
88
+ break;
89
+ }
90
+ }
91
+ if (fieldError) return fieldError;
92
+ return parsedData;
93
+ }
94
+ function parseUserInput(options, user = {}, action) {
95
+ return parseInputData(user, {
96
+ fields: getAllFields(options, "user"),
97
+ action
98
+ });
99
+ }
100
+ function parseAdditionalUserInput(options, user) {
101
+ const schema = getAllFields(options, "user");
102
+ return parseInputData(user || {}, { fields: schema });
103
+ }
104
+ function parseAccountInput(options, account) {
105
+ return parseInputData(account, { fields: getAllFields(options, "account") });
106
+ }
107
+ function parseSessionInput(options, session) {
108
+ return parseInputData(session, { fields: getAllFields(options, "session") });
109
+ }
110
+ function mergeSchema(schema, newSchema) {
111
+ if (!newSchema) return schema;
112
+ for (const table in newSchema) {
113
+ const newModelName = newSchema[table]?.modelName;
114
+ if (newModelName) schema[table].modelName = newModelName;
115
+ for (const field in schema[table].fields) {
116
+ const newField = newSchema[table]?.fields?.[field];
117
+ if (!newField) continue;
118
+ schema[table].fields[field].fieldName = newField;
119
+ }
120
+ }
121
+ return schema;
122
+ }
123
+
124
+ //#endregion
125
+ export { parseInputData as a, parseUserInput as c, parseAdditionalUserInput as i, parseUserOutput as l, parseAccountInput as n, parseSessionInput as o, parseAccountOutput as r, parseSessionOutput as s, mergeSchema as t };