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.
- package/LICENSE +661 -0
- package/README.md +34 -0
- package/dist/access-B5bBI4uT.mjs +39 -0
- package/dist/access-Crt-IJ2P.cjs +51 -0
- package/dist/adapter-factory-BXei1QRX.mjs +881 -0
- package/dist/adapter-factory-DT-_2aHJ.cjs +893 -0
- package/dist/adapters/drizzle-adapter/index.cjs +208 -0
- package/dist/adapters/drizzle-adapter/index.d.cts +48 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +48 -0
- package/dist/adapters/drizzle-adapter/index.mjs +207 -0
- package/dist/adapters/index.cjs +23 -0
- package/dist/adapters/index.d.cts +157 -0
- package/dist/adapters/index.d.mts +157 -0
- package/dist/adapters/index.mjs +17 -0
- package/dist/adapters/kysely-adapter/index.cjs +11 -0
- package/dist/adapters/kysely-adapter/index.d.cts +52 -0
- package/dist/adapters/kysely-adapter/index.d.mts +52 -0
- package/dist/adapters/kysely-adapter/index.mjs +9 -0
- package/dist/adapters/memory-adapter/index.cjs +9 -0
- package/dist/adapters/memory-adapter/index.d.cts +15 -0
- package/dist/adapters/memory-adapter/index.d.mts +15 -0
- package/dist/adapters/memory-adapter/index.mjs +9 -0
- package/dist/adapters/mongodb-adapter/index.cjs +9 -0
- package/dist/adapters/mongodb-adapter/index.d.cts +4 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -0
- package/dist/adapters/mongodb-adapter/index.mjs +9 -0
- package/dist/adapters/prisma-adapter/index.cjs +156 -0
- package/dist/adapters/prisma-adapter/index.d.cts +35 -0
- package/dist/adapters/prisma-adapter/index.d.mts +35 -0
- package/dist/adapters/prisma-adapter/index.mjs +155 -0
- package/dist/adapters/test.cjs +797 -0
- package/dist/adapters/test.d.cts +82 -0
- package/dist/adapters/test.d.mts +82 -0
- package/dist/adapters/test.mjs +793 -0
- package/dist/api/index.cjs +20 -0
- package/dist/api/index.d.cts +3 -0
- package/dist/api/index.d.mts +3 -0
- package/dist/api/index.mjs +20 -0
- package/dist/api/middleware/index.cjs +16 -0
- package/dist/api/middleware/index.d.cts +16 -0
- package/dist/api/middleware/index.d.mts +16 -0
- package/dist/api/middleware/index.mjs +11 -0
- package/dist/api-Bm89BLgN.cjs +1899 -0
- package/dist/api-_B7qO28y.mjs +1892 -0
- package/dist/auth-Bo9PDt5j.cjs +739 -0
- package/dist/auth-Ds4AG4h4.mjs +709 -0
- package/dist/bearer-0SeEmaS4.mjs +54 -0
- package/dist/bearer-CHeREcGT.cjs +60 -0
- package/dist/bun-sqlite-dialect-CfkBo2v5.mjs +155 -0
- package/dist/bun-sqlite-dialect-wuaC2-gh.cjs +156 -0
- package/dist/chunk-Ceigfy4P.mjs +39 -0
- package/dist/chunk-oakRccI5.cjs +60 -0
- package/dist/client/index.cjs +22 -0
- package/dist/client/index.d.cts +8 -0
- package/dist/client/index.d.mts +8 -0
- package/dist/client/index.mjs +19 -0
- package/dist/client/lynx/index.cjs +79 -0
- package/dist/client/lynx/index.d.cts +156 -0
- package/dist/client/lynx/index.d.mts +156 -0
- package/dist/client/lynx/index.mjs +76 -0
- package/dist/client/plugins/index.cjs +11 -0
- package/dist/client/plugins/index.d.cts +17 -0
- package/dist/client/plugins/index.d.mts +17 -0
- package/dist/client/plugins/index.mjs +10 -0
- package/dist/client/react/index.cjs +79 -0
- package/dist/client/react/index.d.cts +156 -0
- package/dist/client/react/index.d.mts +156 -0
- package/dist/client/react/index.mjs +76 -0
- package/dist/client/solid/index.cjs +51 -0
- package/dist/client/solid/index.d.cts +90 -0
- package/dist/client/solid/index.d.mts +90 -0
- package/dist/client/solid/index.mjs +50 -0
- package/dist/client/svelte/index.cjs +28 -0
- package/dist/client/svelte/index.d.cts +110 -0
- package/dist/client/svelte/index.d.mts +110 -0
- package/dist/client/svelte/index.mjs +28 -0
- package/dist/client/vue/index.cjs +68 -0
- package/dist/client/vue/index.d.cts +123 -0
- package/dist/client/vue/index.d.mts +123 -0
- package/dist/client/vue/index.mjs +67 -0
- package/dist/cookies-B5xeA6i8.cjs +456 -0
- package/dist/cookies-Ch1JfQIz.mjs +367 -0
- package/dist/crypto/index.cjs +11 -0
- package/dist/crypto/index.d.cts +22 -0
- package/dist/crypto/index.d.mts +22 -0
- package/dist/crypto/index.mjs +5 -0
- package/dist/crypto-CcTxYH82.cjs +57 -0
- package/dist/crypto-CyQRFtkq.mjs +41 -0
- package/dist/db/index.cjs +40 -0
- package/dist/db/index.d.cts +4 -0
- package/dist/db/index.d.mts +4 -0
- package/dist/db/index.mjs +16 -0
- package/dist/db-BTKyYu-_.cjs +1180 -0
- package/dist/db-xiJtoDgz.mjs +1119 -0
- package/dist/defu-B0Svx_x4.cjs +34 -0
- package/dist/defu-SZkpHhbR.mjs +28 -0
- package/dist/email-verification-C-AsfJsb.cjs +247 -0
- package/dist/email-verification-CWhj2qfb.mjs +228 -0
- package/dist/hono-BEq1NYVX.cjs +526 -0
- package/dist/hono-Cdukwu5K.cjs +13 -0
- package/dist/hono-CoKYWnXA.mjs +7 -0
- package/dist/hono-Covz10jU.mjs +508 -0
- package/dist/hono-DOM31WQz.d.cts +18 -0
- package/dist/hono-DuE14mmj.d.mts +18 -0
- package/dist/index-B-WeOMzg.d.cts +13350 -0
- package/dist/index-B09P9p5_.d.cts +33 -0
- package/dist/index-B5_0QTLg.d.mts +3 -0
- package/dist/index-B7SKyR_a.d.cts +3 -0
- package/dist/index-BVHscLQl.d.cts +992 -0
- package/dist/index-C2-2QDyS.d.cts +35 -0
- package/dist/index-CTwrVluH.d.mts +41 -0
- package/dist/index-CWAqWfoZ.d.cts +27 -0
- package/dist/index-CYSShrFx.d.mts +27 -0
- package/dist/index-Qu-iJGNr.d.mts +992 -0
- package/dist/index-cs4Sh0En.d.cts +41 -0
- package/dist/index-jlessPI0.d.mts +13350 -0
- package/dist/index-ppgcFe12.d.mts +33 -0
- package/dist/index-to0RO38U.d.mts +35 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +27 -0
- package/dist/integrations/next-js.cjs +50 -0
- package/dist/integrations/next-js.d.cts +23 -0
- package/dist/integrations/next-js.d.mts +23 -0
- package/dist/integrations/next-js.mjs +49 -0
- package/dist/integrations/node.cjs +139 -0
- package/dist/integrations/node.d.cts +22 -0
- package/dist/integrations/node.d.mts +22 -0
- package/dist/integrations/node.mjs +134 -0
- package/dist/integrations/react-start.cjs +37 -0
- package/dist/integrations/react-start.d.cts +17 -0
- package/dist/integrations/react-start.d.mts +17 -0
- package/dist/integrations/react-start.mjs +37 -0
- package/dist/integrations/solid-start.cjs +14 -0
- package/dist/integrations/solid-start.d.cts +13 -0
- package/dist/integrations/solid-start.d.mts +13 -0
- package/dist/integrations/solid-start.mjs +13 -0
- package/dist/integrations/svelte-kit.cjs +52 -0
- package/dist/integrations/svelte-kit.d.cts +42 -0
- package/dist/integrations/svelte-kit.d.mts +42 -0
- package/dist/integrations/svelte-kit.mjs +49 -0
- package/dist/ip-B5SwXaMB.cjs +54 -0
- package/dist/ip-BjNYspCH.mjs +36 -0
- package/dist/json-B1v2qRTQ.mjs +24 -0
- package/dist/json-CcJ2HjGo.cjs +30 -0
- package/dist/kysely-adapter-Bxi7sPdG.cjs +288 -0
- package/dist/kysely-adapter-DRuoT_X8.mjs +270 -0
- package/dist/logged-CyGfp8_H.mjs +187 -0
- package/dist/logged-DQK3C64b.cjs +193 -0
- package/dist/memory-adapter-BlnDIAAX.cjs +154 -0
- package/dist/memory-adapter-Db3tsJTn.mjs +148 -0
- package/dist/middleware-CE6OhDkq.mjs +29 -0
- package/dist/middleware-CWvRH4EW.cjs +47 -0
- package/dist/mongodb-adapter-C_qGQED5.mjs +291 -0
- package/dist/mongodb-adapter-C_qfK87x.cjs +297 -0
- package/dist/node-sqlite-dialect-BfBzyOAg.mjs +155 -0
- package/dist/node-sqlite-dialect-mJWC8LWQ.cjs +156 -0
- package/dist/oauth2/index.cjs +25 -0
- package/dist/oauth2/index.d.cts +42 -0
- package/dist/oauth2/index.d.mts +42 -0
- package/dist/oauth2/index.mjs +16 -0
- package/dist/oauth2-B8M0lW9l.mjs +159 -0
- package/dist/oauth2-BLeOEi7Y.cjs +177 -0
- package/dist/origin-check-8Gajklvh.mjs +228 -0
- package/dist/origin-check-id9lTnqZ.cjs +246 -0
- package/dist/parser-CdncAl9i.cjs +83 -0
- package/dist/parser-CeAer-RM.mjs +71 -0
- package/dist/passkey-B6N20LSS.cjs +512 -0
- package/dist/passkey-DJsR_GX3.mjs +505 -0
- package/dist/plugins/access/index.cjs +4 -0
- package/dist/plugins/access/index.d.cts +2 -0
- package/dist/plugins/access/index.d.mts +2 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/bearer/index.cjs +7 -0
- package/dist/plugins/bearer/index.d.cts +4 -0
- package/dist/plugins/bearer/index.d.mts +4 -0
- package/dist/plugins/bearer/index.mjs +7 -0
- package/dist/plugins/index.cjs +49 -0
- package/dist/plugins/index.d.cts +9326 -0
- package/dist/plugins/index.d.mts +9326 -0
- package/dist/plugins/index.mjs +26 -0
- package/dist/plugins/passkey/index.cjs +15 -0
- package/dist/plugins/passkey/index.d.cts +4 -0
- package/dist/plugins/passkey/index.d.mts +4 -0
- package/dist/plugins/passkey/index.mjs +15 -0
- package/dist/plugins-C1lm2Wj3.cjs +5254 -0
- package/dist/plugins-Dai1QkRU.mjs +5199 -0
- package/dist/request-1NL_1lyJ.mjs +58 -0
- package/dist/request-CPNlp-DK.cjs +100 -0
- package/dist/schema-D-qjygfE.cjs +179 -0
- package/dist/schema-DTIwLLmf.mjs +125 -0
- package/dist/session-De9POJTW.cjs +641 -0
- package/dist/session-rH8ougDl.mjs +538 -0
- package/dist/social-providers/index.cjs +10 -0
- package/dist/social-providers/index.d.cts +2 -0
- package/dist/social-providers/index.d.mts +2 -0
- package/dist/social-providers/index.mjs +5 -0
- package/dist/social-providers-DcFNUT0S.cjs +13 -0
- package/dist/social-providers-DoYJhBe3.mjs +9 -0
- package/dist/state--f7fwIGh.cjs +99 -0
- package/dist/state-CqJfCIl9.mjs +86 -0
- package/dist/test-utils/index.cjs +27492 -0
- package/dist/test-utils/index.d.cts +4584 -0
- package/dist/test-utils/index.d.mts +4584 -0
- package/dist/test-utils/index.mjs +27490 -0
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.mjs +1 -0
- package/dist/url-BoUuoIwZ.mjs +88 -0
- package/dist/url-D2yvKaM7.cjs +118 -0
- package/dist/utils/cookies.cjs +51 -0
- package/dist/utils/cookies.d.cts +179 -0
- package/dist/utils/cookies.d.mts +179 -0
- package/dist/utils/cookies.mjs +7 -0
- package/dist/utils-44aDDP8f.cjs +2 -0
- package/dist/utils-D4vZd1-9.mjs +4 -0
- package/dist/vanilla-Bu2PmFzE.cjs +30 -0
- package/dist/vanilla-TfHqeiC7.mjs +25 -0
- package/package.json +470 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { _ as serializeSignedCookie, p as parseSetCookieHeader } from "./cookies-Ch1JfQIz.mjs";
|
|
2
|
+
import { n as createHook } from "./middleware-CE6OhDkq.mjs";
|
|
3
|
+
import { createHMAC } from "@faire-auth/core/datatypes";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/bearer/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Converts bearer token to session cookie
|
|
8
|
+
*/
|
|
9
|
+
const bearer = (options) => ({
|
|
10
|
+
id: "bearer",
|
|
11
|
+
hooks: {
|
|
12
|
+
before: [{
|
|
13
|
+
matcher: (ctx) => Boolean(ctx.req.header("Authorization")),
|
|
14
|
+
handler: (_opts) => createHook()(async (ctx) => {
|
|
15
|
+
const token = ctx.req.header("Authorization")?.replace("Bearer ", "");
|
|
16
|
+
if (token == null) return;
|
|
17
|
+
let signedToken = "";
|
|
18
|
+
if (token.includes(".")) signedToken = token.replace("=", "");
|
|
19
|
+
else {
|
|
20
|
+
if (options?.requireSignature === true) return;
|
|
21
|
+
signedToken = (await serializeSignedCookie("", token, ctx.get("context").secret)).replace("=", "");
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const [first, second] = decodeURIComponent(signedToken).split(".");
|
|
25
|
+
if (first == null || second == null) return;
|
|
26
|
+
if (!await createHMAC("SHA-256", "base64urlnopad").verify(ctx.get("context").secret, first, second)) return;
|
|
27
|
+
} catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
ctx.req.raw.headers.append("cookie", `${ctx.get("context").authCookies.sessionToken.name}=${signedToken}`);
|
|
31
|
+
})
|
|
32
|
+
}],
|
|
33
|
+
after: [{
|
|
34
|
+
matcher: (_ctx) => true,
|
|
35
|
+
handler: (_opts) => createHook()(async (ctx) => {
|
|
36
|
+
const setCookie = ctx.res.headers.getSetCookie();
|
|
37
|
+
if (!setCookie.length) return;
|
|
38
|
+
const parsedCookies = parseSetCookieHeader(setCookie);
|
|
39
|
+
const cookieName = ctx.get("context").authCookies.sessionToken.name;
|
|
40
|
+
const sessionCookie = parsedCookies.get(cookieName);
|
|
41
|
+
if (sessionCookie?.value == null || sessionCookie["max-age"] === 0) return;
|
|
42
|
+
const token = sessionCookie.value;
|
|
43
|
+
const exposedHeaders = ctx.res.headers.get("access-control-expose-headers") ?? "";
|
|
44
|
+
const headersSet = new Set(exposedHeaders.split(",").map((header) => header.trim()).filter(Boolean));
|
|
45
|
+
headersSet.add("set-auth-token");
|
|
46
|
+
ctx.res.headers.set("set-auth-token", token);
|
|
47
|
+
ctx.res.headers.set("Access-Control-Expose-Headers", Array.from(headersSet).join(", "));
|
|
48
|
+
})
|
|
49
|
+
}]
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { bearer as t };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-oakRccI5.cjs');
|
|
2
|
+
const require_cookies = require('./cookies-B5xeA6i8.cjs');
|
|
3
|
+
const require_middleware = require('./middleware-CWvRH4EW.cjs');
|
|
4
|
+
let __faire_auth_core_datatypes = require("@faire-auth/core/datatypes");
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/bearer/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Converts bearer token to session cookie
|
|
9
|
+
*/
|
|
10
|
+
const bearer = (options) => ({
|
|
11
|
+
id: "bearer",
|
|
12
|
+
hooks: {
|
|
13
|
+
before: [{
|
|
14
|
+
matcher: (ctx) => Boolean(ctx.req.header("Authorization")),
|
|
15
|
+
handler: (_opts) => require_middleware.createHook()(async (ctx) => {
|
|
16
|
+
const token = ctx.req.header("Authorization")?.replace("Bearer ", "");
|
|
17
|
+
if (token == null) return;
|
|
18
|
+
let signedToken = "";
|
|
19
|
+
if (token.includes(".")) signedToken = token.replace("=", "");
|
|
20
|
+
else {
|
|
21
|
+
if (options?.requireSignature === true) return;
|
|
22
|
+
signedToken = (await require_cookies.serializeSignedCookie("", token, ctx.get("context").secret)).replace("=", "");
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const [first, second] = decodeURIComponent(signedToken).split(".");
|
|
26
|
+
if (first == null || second == null) return;
|
|
27
|
+
if (!await (0, __faire_auth_core_datatypes.createHMAC)("SHA-256", "base64urlnopad").verify(ctx.get("context").secret, first, second)) return;
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
ctx.req.raw.headers.append("cookie", `${ctx.get("context").authCookies.sessionToken.name}=${signedToken}`);
|
|
32
|
+
})
|
|
33
|
+
}],
|
|
34
|
+
after: [{
|
|
35
|
+
matcher: (_ctx) => true,
|
|
36
|
+
handler: (_opts) => require_middleware.createHook()(async (ctx) => {
|
|
37
|
+
const setCookie = ctx.res.headers.getSetCookie();
|
|
38
|
+
if (!setCookie.length) return;
|
|
39
|
+
const parsedCookies = require_cookies.parseSetCookieHeader(setCookie);
|
|
40
|
+
const cookieName = ctx.get("context").authCookies.sessionToken.name;
|
|
41
|
+
const sessionCookie = parsedCookies.get(cookieName);
|
|
42
|
+
if (sessionCookie?.value == null || sessionCookie["max-age"] === 0) return;
|
|
43
|
+
const token = sessionCookie.value;
|
|
44
|
+
const exposedHeaders = ctx.res.headers.get("access-control-expose-headers") ?? "";
|
|
45
|
+
const headersSet = new Set(exposedHeaders.split(",").map((header) => header.trim()).filter(Boolean));
|
|
46
|
+
headersSet.add("set-auth-token");
|
|
47
|
+
ctx.res.headers.set("set-auth-token", token);
|
|
48
|
+
ctx.res.headers.set("Access-Control-Expose-Headers", Array.from(headersSet).join(", "));
|
|
49
|
+
})
|
|
50
|
+
}]
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
Object.defineProperty(exports, 'bearer', {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return bearer;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { CompiledQuery, DEFAULT_MIGRATION_LOCK_TABLE, DEFAULT_MIGRATION_TABLE, DefaultQueryCompiler, Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/kysely-adapter/bun-sqlite-dialect.ts
|
|
4
|
+
var BunSqliteAdapter = class {
|
|
5
|
+
get supportsCreateIfNotExists() {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
get supportsTransactionalDdl() {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
get supportsReturning() {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
async acquireMigrationLock() {}
|
|
15
|
+
async releaseMigrationLock() {}
|
|
16
|
+
get supportsOutput() {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var BunSqliteDriver = class {
|
|
21
|
+
#config;
|
|
22
|
+
#connectionMutex = new ConnectionMutex();
|
|
23
|
+
#db;
|
|
24
|
+
#connection;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.#config = { ...config };
|
|
27
|
+
}
|
|
28
|
+
async init() {
|
|
29
|
+
this.#db = this.#config.database;
|
|
30
|
+
this.#connection = new BunSqliteConnection(this.#db);
|
|
31
|
+
if (this.#config.onCreateConnection) await this.#config.onCreateConnection(this.#connection);
|
|
32
|
+
}
|
|
33
|
+
async acquireConnection() {
|
|
34
|
+
await this.#connectionMutex.lock();
|
|
35
|
+
return this.#connection;
|
|
36
|
+
}
|
|
37
|
+
async beginTransaction(connection) {
|
|
38
|
+
await connection.executeQuery(CompiledQuery.raw("begin"));
|
|
39
|
+
}
|
|
40
|
+
async commitTransaction(connection) {
|
|
41
|
+
await connection.executeQuery(CompiledQuery.raw("commit"));
|
|
42
|
+
}
|
|
43
|
+
async rollbackTransaction(connection) {
|
|
44
|
+
await connection.executeQuery(CompiledQuery.raw("rollback"));
|
|
45
|
+
}
|
|
46
|
+
async releaseConnection() {
|
|
47
|
+
this.#connectionMutex.unlock();
|
|
48
|
+
}
|
|
49
|
+
async destroy() {
|
|
50
|
+
this.#db?.close();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var BunSqliteConnection = class {
|
|
54
|
+
#db;
|
|
55
|
+
constructor(db) {
|
|
56
|
+
this.#db = db;
|
|
57
|
+
}
|
|
58
|
+
executeQuery(compiledQuery) {
|
|
59
|
+
const { sql: sql$1, parameters } = compiledQuery;
|
|
60
|
+
const stmt = this.#db.prepare(sql$1);
|
|
61
|
+
return Promise.resolve({ rows: stmt.all(parameters) });
|
|
62
|
+
}
|
|
63
|
+
async *streamQuery() {
|
|
64
|
+
throw new Error("Streaming query is not supported by SQLite driver.");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var ConnectionMutex = class {
|
|
68
|
+
#promise;
|
|
69
|
+
#resolve;
|
|
70
|
+
async lock() {
|
|
71
|
+
while (this.#promise) await this.#promise;
|
|
72
|
+
this.#promise = new Promise((resolve) => {
|
|
73
|
+
this.#resolve = resolve;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
unlock() {
|
|
77
|
+
const resolve = this.#resolve;
|
|
78
|
+
this.#promise = void 0;
|
|
79
|
+
this.#resolve = void 0;
|
|
80
|
+
resolve?.();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var BunSqliteIntrospector = class {
|
|
84
|
+
#db;
|
|
85
|
+
constructor(db) {
|
|
86
|
+
this.#db = db;
|
|
87
|
+
}
|
|
88
|
+
async getSchemas() {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
async getTables(options = { withInternalKyselyTables: false }) {
|
|
92
|
+
let query = this.#db.selectFrom("sqlite_schema").where("type", "=", "table").where("name", "not like", "sqlite_%").select("name").$castTo();
|
|
93
|
+
if (!options.withInternalKyselyTables) query = query.where("name", "!=", DEFAULT_MIGRATION_TABLE).where("name", "!=", DEFAULT_MIGRATION_LOCK_TABLE);
|
|
94
|
+
const tables = await query.execute();
|
|
95
|
+
return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name)));
|
|
96
|
+
}
|
|
97
|
+
async getMetadata(options) {
|
|
98
|
+
return { tables: await this.getTables(options) };
|
|
99
|
+
}
|
|
100
|
+
async #getTableMetadata(table) {
|
|
101
|
+
const db = this.#db;
|
|
102
|
+
const autoIncrementCol = (await db.selectFrom("sqlite_master").where("name", "=", table).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((it) => it.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g, "");
|
|
103
|
+
return {
|
|
104
|
+
name: table,
|
|
105
|
+
columns: (await db.selectFrom(sql`pragma_table_info(${table})`.as("table_info")).select([
|
|
106
|
+
"name",
|
|
107
|
+
"type",
|
|
108
|
+
"notnull",
|
|
109
|
+
"dflt_value"
|
|
110
|
+
]).execute()).map((col) => ({
|
|
111
|
+
name: col.name,
|
|
112
|
+
dataType: col.type,
|
|
113
|
+
isNullable: !col.notnull,
|
|
114
|
+
isAutoIncrementing: col.name === autoIncrementCol,
|
|
115
|
+
hasDefaultValue: col.dflt_value != null
|
|
116
|
+
})),
|
|
117
|
+
isView: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var BunSqliteQueryCompiler = class extends DefaultQueryCompiler {
|
|
122
|
+
getCurrentParameterPlaceholder() {
|
|
123
|
+
return "?";
|
|
124
|
+
}
|
|
125
|
+
getLeftIdentifierWrapper() {
|
|
126
|
+
return "\"";
|
|
127
|
+
}
|
|
128
|
+
getRightIdentifierWrapper() {
|
|
129
|
+
return "\"";
|
|
130
|
+
}
|
|
131
|
+
getAutoIncrement() {
|
|
132
|
+
return "autoincrement";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var BunSqliteDialect = class {
|
|
136
|
+
#config;
|
|
137
|
+
constructor(config) {
|
|
138
|
+
this.#config = { ...config };
|
|
139
|
+
}
|
|
140
|
+
createDriver() {
|
|
141
|
+
return new BunSqliteDriver(this.#config);
|
|
142
|
+
}
|
|
143
|
+
createQueryCompiler() {
|
|
144
|
+
return new BunSqliteQueryCompiler();
|
|
145
|
+
}
|
|
146
|
+
createAdapter() {
|
|
147
|
+
return new BunSqliteAdapter();
|
|
148
|
+
}
|
|
149
|
+
createIntrospector(db) {
|
|
150
|
+
return new BunSqliteIntrospector(db);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
export { BunSqliteAdapter, BunSqliteDialect, BunSqliteDriver, BunSqliteIntrospector, BunSqliteQueryCompiler };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-oakRccI5.cjs');
|
|
2
|
+
let kysely = require("kysely");
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/kysely-adapter/bun-sqlite-dialect.ts
|
|
5
|
+
var BunSqliteAdapter = class {
|
|
6
|
+
get supportsCreateIfNotExists() {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
get supportsTransactionalDdl() {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
get supportsReturning() {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
async acquireMigrationLock() {}
|
|
16
|
+
async releaseMigrationLock() {}
|
|
17
|
+
get supportsOutput() {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var BunSqliteDriver = class {
|
|
22
|
+
#config;
|
|
23
|
+
#connectionMutex = new ConnectionMutex();
|
|
24
|
+
#db;
|
|
25
|
+
#connection;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.#config = { ...config };
|
|
28
|
+
}
|
|
29
|
+
async init() {
|
|
30
|
+
this.#db = this.#config.database;
|
|
31
|
+
this.#connection = new BunSqliteConnection(this.#db);
|
|
32
|
+
if (this.#config.onCreateConnection) await this.#config.onCreateConnection(this.#connection);
|
|
33
|
+
}
|
|
34
|
+
async acquireConnection() {
|
|
35
|
+
await this.#connectionMutex.lock();
|
|
36
|
+
return this.#connection;
|
|
37
|
+
}
|
|
38
|
+
async beginTransaction(connection) {
|
|
39
|
+
await connection.executeQuery(kysely.CompiledQuery.raw("begin"));
|
|
40
|
+
}
|
|
41
|
+
async commitTransaction(connection) {
|
|
42
|
+
await connection.executeQuery(kysely.CompiledQuery.raw("commit"));
|
|
43
|
+
}
|
|
44
|
+
async rollbackTransaction(connection) {
|
|
45
|
+
await connection.executeQuery(kysely.CompiledQuery.raw("rollback"));
|
|
46
|
+
}
|
|
47
|
+
async releaseConnection() {
|
|
48
|
+
this.#connectionMutex.unlock();
|
|
49
|
+
}
|
|
50
|
+
async destroy() {
|
|
51
|
+
this.#db?.close();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var BunSqliteConnection = class {
|
|
55
|
+
#db;
|
|
56
|
+
constructor(db) {
|
|
57
|
+
this.#db = db;
|
|
58
|
+
}
|
|
59
|
+
executeQuery(compiledQuery) {
|
|
60
|
+
const { sql: sql$1, parameters } = compiledQuery;
|
|
61
|
+
const stmt = this.#db.prepare(sql$1);
|
|
62
|
+
return Promise.resolve({ rows: stmt.all(parameters) });
|
|
63
|
+
}
|
|
64
|
+
async *streamQuery() {
|
|
65
|
+
throw new Error("Streaming query is not supported by SQLite driver.");
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var ConnectionMutex = class {
|
|
69
|
+
#promise;
|
|
70
|
+
#resolve;
|
|
71
|
+
async lock() {
|
|
72
|
+
while (this.#promise) await this.#promise;
|
|
73
|
+
this.#promise = new Promise((resolve) => {
|
|
74
|
+
this.#resolve = resolve;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
unlock() {
|
|
78
|
+
const resolve = this.#resolve;
|
|
79
|
+
this.#promise = void 0;
|
|
80
|
+
this.#resolve = void 0;
|
|
81
|
+
resolve?.();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var BunSqliteIntrospector = class {
|
|
85
|
+
#db;
|
|
86
|
+
constructor(db) {
|
|
87
|
+
this.#db = db;
|
|
88
|
+
}
|
|
89
|
+
async getSchemas() {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
async getTables(options = { withInternalKyselyTables: false }) {
|
|
93
|
+
let query = this.#db.selectFrom("sqlite_schema").where("type", "=", "table").where("name", "not like", "sqlite_%").select("name").$castTo();
|
|
94
|
+
if (!options.withInternalKyselyTables) query = query.where("name", "!=", kysely.DEFAULT_MIGRATION_TABLE).where("name", "!=", kysely.DEFAULT_MIGRATION_LOCK_TABLE);
|
|
95
|
+
const tables = await query.execute();
|
|
96
|
+
return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name)));
|
|
97
|
+
}
|
|
98
|
+
async getMetadata(options) {
|
|
99
|
+
return { tables: await this.getTables(options) };
|
|
100
|
+
}
|
|
101
|
+
async #getTableMetadata(table) {
|
|
102
|
+
const db = this.#db;
|
|
103
|
+
const autoIncrementCol = (await db.selectFrom("sqlite_master").where("name", "=", table).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((it) => it.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g, "");
|
|
104
|
+
return {
|
|
105
|
+
name: table,
|
|
106
|
+
columns: (await db.selectFrom(kysely.sql`pragma_table_info(${table})`.as("table_info")).select([
|
|
107
|
+
"name",
|
|
108
|
+
"type",
|
|
109
|
+
"notnull",
|
|
110
|
+
"dflt_value"
|
|
111
|
+
]).execute()).map((col) => ({
|
|
112
|
+
name: col.name,
|
|
113
|
+
dataType: col.type,
|
|
114
|
+
isNullable: !col.notnull,
|
|
115
|
+
isAutoIncrementing: col.name === autoIncrementCol,
|
|
116
|
+
hasDefaultValue: col.dflt_value != null
|
|
117
|
+
})),
|
|
118
|
+
isView: true
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var BunSqliteQueryCompiler = class extends kysely.DefaultQueryCompiler {
|
|
123
|
+
getCurrentParameterPlaceholder() {
|
|
124
|
+
return "?";
|
|
125
|
+
}
|
|
126
|
+
getLeftIdentifierWrapper() {
|
|
127
|
+
return "\"";
|
|
128
|
+
}
|
|
129
|
+
getRightIdentifierWrapper() {
|
|
130
|
+
return "\"";
|
|
131
|
+
}
|
|
132
|
+
getAutoIncrement() {
|
|
133
|
+
return "autoincrement";
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var BunSqliteDialect = class {
|
|
137
|
+
#config;
|
|
138
|
+
constructor(config) {
|
|
139
|
+
this.#config = { ...config };
|
|
140
|
+
}
|
|
141
|
+
createDriver() {
|
|
142
|
+
return new BunSqliteDriver(this.#config);
|
|
143
|
+
}
|
|
144
|
+
createQueryCompiler() {
|
|
145
|
+
return new BunSqliteQueryCompiler();
|
|
146
|
+
}
|
|
147
|
+
createAdapter() {
|
|
148
|
+
return new BunSqliteAdapter();
|
|
149
|
+
}
|
|
150
|
+
createIntrospector(db) {
|
|
151
|
+
return new BunSqliteIntrospector(db);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
exports.BunSqliteDialect = BunSqliteDialect;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJS = (cb, mod) => function() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __export = (all) => {
|
|
14
|
+
let target = {};
|
|
15
|
+
for (var name in all) __defProp(target, name, {
|
|
16
|
+
get: all[name],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
23
|
+
key = keys[i];
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
25
|
+
get: ((k) => from[k]).bind(null, key),
|
|
26
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
33
|
+
value: mod,
|
|
34
|
+
enumerable: true
|
|
35
|
+
}) : target, mod));
|
|
36
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { __toESM as a, __require as i, __export as n, __reExport as r, __commonJS as t };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (all) => {
|
|
12
|
+
let target = {};
|
|
13
|
+
for (var name in all) __defProp(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
21
|
+
key = keys[i];
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
+
get: ((k) => from[k]).bind(null, key),
|
|
24
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
+
value: mod,
|
|
32
|
+
enumerable: true
|
|
33
|
+
}) : target, mod));
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(exports, '__commonJS', {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return __commonJS;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, '__export', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return __export;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, '__reExport', {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return __reExport;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, '__toESM', {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return __toESM;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require('../logged-DQK3C64b.cjs');
|
|
2
|
+
require('../url-D2yvKaM7.cjs');
|
|
3
|
+
require('../request-CPNlp-DK.cjs');
|
|
4
|
+
require('../defu-B0Svx_x4.cjs');
|
|
5
|
+
const require_hono = require('../hono-BEq1NYVX.cjs');
|
|
6
|
+
require('../parser-CdncAl9i.cjs');
|
|
7
|
+
const require_vanilla = require('../vanilla-Bu2PmFzE.cjs');
|
|
8
|
+
|
|
9
|
+
//#region src/client/index.ts
|
|
10
|
+
const InferPlugin = () => ({
|
|
11
|
+
id: "infer-server-plugin",
|
|
12
|
+
$InferServerPlugin: {}
|
|
13
|
+
});
|
|
14
|
+
function InferAuth() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.InferAuth = InferAuth;
|
|
20
|
+
exports.InferPlugin = InferPlugin;
|
|
21
|
+
exports.createAuthClient = require_vanilla.createAuthClient;
|
|
22
|
+
exports.useAuthQuery = require_hono.useAuthQuery;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { $ as Client, Q as CamelCase, X as createAuthClient, Y as InferResolvedHooks, Z as AtomListener, at as InferAdditionalAsClient, ct as InferPluginsFromClient, dt as IsSignal, et as ClientOptions, ft as RevalidateOptions, ht as FetchOptions, it as InferActions, lt as InferSessionFromClient, mt as Store, nt as FaireAuthClientPlugin, ot as InferAdditionalFromClient, pt as SessionQueryParams, rt as Inc, st as InferErrorCodes, tt as CreateSchemaType, ut as InferUserFromClient } from "../index-B-WeOMzg.cjs";
|
|
2
|
+
import "../hono-DOM31WQz.cjs";
|
|
3
|
+
import { n as InferPlugin, r as useAuthQuery, t as InferAuth } from "../index-CWAqWfoZ.cjs";
|
|
4
|
+
import { t as index_d_exports } from "../index-B7SKyR_a.cjs";
|
|
5
|
+
export * from "@better-fetch/fetch";
|
|
6
|
+
export * from "nanostores";
|
|
7
|
+
type SocialProvider = index_d_exports.SocialProvider;
|
|
8
|
+
export { AtomListener, CamelCase, Client, ClientOptions, CreateSchemaType, FaireAuthClientPlugin, FetchOptions, Inc, InferActions, InferAdditionalAsClient, InferAdditionalFromClient, InferAuth, InferErrorCodes, InferPlugin, InferPluginsFromClient, InferResolvedHooks, InferSessionFromClient, InferUserFromClient, IsSignal, RevalidateOptions, SessionQueryParams, SocialProvider, Store, createAuthClient, useAuthQuery };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { $ as Client, Q as CamelCase, X as createAuthClient, Y as InferResolvedHooks, Z as AtomListener, at as InferAdditionalAsClient, ct as InferPluginsFromClient, dt as IsSignal, et as ClientOptions, ft as RevalidateOptions, ht as FetchOptions, it as InferActions, lt as InferSessionFromClient, mt as Store, nt as FaireAuthClientPlugin, ot as InferAdditionalFromClient, pt as SessionQueryParams, rt as Inc, st as InferErrorCodes, tt as CreateSchemaType, ut as InferUserFromClient } from "../index-jlessPI0.mjs";
|
|
2
|
+
import "../hono-DuE14mmj.mjs";
|
|
3
|
+
import { n as InferPlugin, r as useAuthQuery, t as InferAuth } from "../index-CYSShrFx.mjs";
|
|
4
|
+
import { t as index_d_exports } from "../index-B5_0QTLg.mjs";
|
|
5
|
+
export * from "@better-fetch/fetch";
|
|
6
|
+
export * from "nanostores";
|
|
7
|
+
type SocialProvider = index_d_exports.SocialProvider;
|
|
8
|
+
export { AtomListener, CamelCase, Client, ClientOptions, CreateSchemaType, FaireAuthClientPlugin, FetchOptions, Inc, InferActions, InferAdditionalAsClient, InferAdditionalFromClient, InferAuth, InferErrorCodes, InferPlugin, InferPluginsFromClient, InferResolvedHooks, InferSessionFromClient, InferUserFromClient, IsSignal, RevalidateOptions, SessionQueryParams, SocialProvider, Store, createAuthClient, useAuthQuery };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "../logged-CyGfp8_H.mjs";
|
|
2
|
+
import "../url-BoUuoIwZ.mjs";
|
|
3
|
+
import "../request-1NL_1lyJ.mjs";
|
|
4
|
+
import "../defu-SZkpHhbR.mjs";
|
|
5
|
+
import { r as useAuthQuery } from "../hono-Covz10jU.mjs";
|
|
6
|
+
import "../parser-CeAer-RM.mjs";
|
|
7
|
+
import { t as createAuthClient } from "../vanilla-TfHqeiC7.mjs";
|
|
8
|
+
|
|
9
|
+
//#region src/client/index.ts
|
|
10
|
+
const InferPlugin = () => ({
|
|
11
|
+
id: "infer-server-plugin",
|
|
12
|
+
$InferServerPlugin: {}
|
|
13
|
+
});
|
|
14
|
+
function InferAuth() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { InferAuth, InferPlugin, createAuthClient, useAuthQuery };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const require_chunk = require('../../chunk-oakRccI5.cjs');
|
|
2
|
+
const require_url = require('../../url-D2yvKaM7.cjs');
|
|
3
|
+
require('../../request-CPNlp-DK.cjs');
|
|
4
|
+
require('../../defu-B0Svx_x4.cjs');
|
|
5
|
+
const require_hono = require('../../hono-BEq1NYVX.cjs');
|
|
6
|
+
require('../../parser-CdncAl9i.cjs');
|
|
7
|
+
let nanostores = require("nanostores");
|
|
8
|
+
let __lynx_js_react = require("@lynx-js/react");
|
|
9
|
+
|
|
10
|
+
//#region src/client/lynx/lynx-store.ts
|
|
11
|
+
/**
|
|
12
|
+
* Subscribe to store changes and get store's value.
|
|
13
|
+
*
|
|
14
|
+
* Can be used with store builder too.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* import { useStore } from 'nanostores/react'
|
|
18
|
+
*
|
|
19
|
+
* import { router } from '../store/router'
|
|
20
|
+
*
|
|
21
|
+
* export const Layout = () => {
|
|
22
|
+
* let page = useStore(router)
|
|
23
|
+
* if (page.route === 'home') {
|
|
24
|
+
* return <HomePage />
|
|
25
|
+
* } else {
|
|
26
|
+
* return <Error404 />
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param store Store instance.
|
|
32
|
+
* @returns Store value.
|
|
33
|
+
*/
|
|
34
|
+
function useStore(store, options = {}) {
|
|
35
|
+
let snapshotRef = (0, __lynx_js_react.useRef)(store.get());
|
|
36
|
+
const { keys, deps = [store, keys] } = options;
|
|
37
|
+
let subscribe = (0, __lynx_js_react.useCallback)((onChange) => {
|
|
38
|
+
const emitChange = (value) => {
|
|
39
|
+
if (snapshotRef.current === value) return;
|
|
40
|
+
snapshotRef.current = value;
|
|
41
|
+
onChange();
|
|
42
|
+
};
|
|
43
|
+
emitChange(store.value);
|
|
44
|
+
if (keys?.length) return (0, nanostores.listenKeys)(store, keys, emitChange);
|
|
45
|
+
return store.listen(emitChange);
|
|
46
|
+
}, deps);
|
|
47
|
+
let get = () => snapshotRef.current;
|
|
48
|
+
return (0, __lynx_js_react.useSyncExternalStore)(subscribe, get, get);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/client/lynx/index.ts
|
|
53
|
+
function getAtomKey(str) {
|
|
54
|
+
return `use${capitalizeFirstLetter(str)}`;
|
|
55
|
+
}
|
|
56
|
+
function capitalizeFirstLetter(str) {
|
|
57
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
58
|
+
}
|
|
59
|
+
const createAuthClient = () => (options) => {
|
|
60
|
+
const baseURL = require_url.getBaseURL(options.baseURL, options.basePath);
|
|
61
|
+
const { pluginPathMethods, pluginsActions, pluginsAtoms, $fetch, $store, atomListeners } = require_hono.getClientConfig(options);
|
|
62
|
+
let resolvedHooks = {};
|
|
63
|
+
for (const [key, value] of Object.entries(pluginsAtoms)) resolvedHooks[getAtomKey(key)] = () => useStore(value);
|
|
64
|
+
const routes = {
|
|
65
|
+
...pluginsActions,
|
|
66
|
+
...resolvedHooks,
|
|
67
|
+
$fetch,
|
|
68
|
+
$store
|
|
69
|
+
};
|
|
70
|
+
return require_hono.createHonoClient({
|
|
71
|
+
baseURL,
|
|
72
|
+
createFetchOptions: options.fetchOptions
|
|
73
|
+
}, routes, $fetch, pluginsAtoms, atomListeners);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
78
|
+
exports.createAuthClient = createAuthClient;
|
|
79
|
+
exports.useStore = useStore;
|