mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
Merge pull request #63 from bknd-io/fix/api-and-adapter
fix/api-and-adapter
This commit is contained in:
@@ -27,10 +27,7 @@ describe("ModuleApi", () => {
|
|||||||
|
|
||||||
it("fetches endpoint", async () => {
|
it("fetches endpoint", async () => {
|
||||||
const app = new Hono().get("/endpoint", (c) => c.json({ foo: "bar" }));
|
const app = new Hono().get("/endpoint", (c) => c.json({ foo: "bar" }));
|
||||||
const api = new Api({ host });
|
const api = new Api({ host }, app.request as typeof fetch);
|
||||||
|
|
||||||
// @ts-expect-error it's protected
|
|
||||||
api.fetcher = app.request as typeof fetch;
|
|
||||||
|
|
||||||
const res = await api.get("/endpoint");
|
const res = await api.get("/endpoint");
|
||||||
expect(res.res.ok).toEqual(true);
|
expect(res.res.ok).toEqual(true);
|
||||||
@@ -41,10 +38,7 @@ describe("ModuleApi", () => {
|
|||||||
|
|
||||||
it("has accessible request", async () => {
|
it("has accessible request", async () => {
|
||||||
const app = new Hono().get("/endpoint", (c) => c.json({ foo: "bar" }));
|
const app = new Hono().get("/endpoint", (c) => c.json({ foo: "bar" }));
|
||||||
const api = new Api({ host });
|
const api = new Api({ host }, app.request as typeof fetch);
|
||||||
|
|
||||||
// @ts-expect-error it's protected
|
|
||||||
api.fetcher = app.request as typeof fetch;
|
|
||||||
|
|
||||||
const promise = api.get("/endpoint");
|
const promise = api.get("/endpoint");
|
||||||
expect(promise.request).toBeDefined();
|
expect(promise.request).toBeDefined();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export type ApiOptions = {
|
|||||||
headers?: Headers;
|
headers?: Headers;
|
||||||
key?: string;
|
key?: string;
|
||||||
localStorage?: boolean;
|
localStorage?: boolean;
|
||||||
|
fetcher?: typeof fetch;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AuthState = {
|
export type AuthState = {
|
||||||
@@ -163,14 +164,18 @@ export class Api {
|
|||||||
headers: this.options.headers,
|
headers: this.options.headers,
|
||||||
token_transport: this.token_transport
|
token_transport: this.token_transport
|
||||||
};
|
};
|
||||||
|
const fetcher = this.options.fetcher;
|
||||||
|
|
||||||
this.system = new SystemApi(baseParams);
|
this.system = new SystemApi(baseParams, fetcher);
|
||||||
this.data = new DataApi(baseParams);
|
this.data = new DataApi(baseParams, fetcher);
|
||||||
this.auth = new AuthApi({
|
this.auth = new AuthApi(
|
||||||
|
{
|
||||||
...baseParams,
|
...baseParams,
|
||||||
onTokenUpdate: (token) => this.updateToken(token, true)
|
onTokenUpdate: (token) => this.updateToken(token, true)
|
||||||
});
|
},
|
||||||
this.media = new MediaApi(baseParams);
|
fetcher
|
||||||
|
);
|
||||||
|
this.media = new MediaApi(baseParams, fetcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { CreateUserPayload } from "auth/AppAuth";
|
import type { CreateUserPayload } from "auth/AppAuth";
|
||||||
import { Event } from "core/events";
|
import { Event } from "core/events";
|
||||||
import { Connection, type LibSqlCredentials, LibsqlConnection } from "data";
|
import { Connection, type LibSqlCredentials, LibsqlConnection } from "data";
|
||||||
|
import type { Hono } from "hono";
|
||||||
import {
|
import {
|
||||||
type InitialModuleConfigs,
|
type InitialModuleConfigs,
|
||||||
ModuleManager,
|
ModuleManager,
|
||||||
@@ -132,7 +133,7 @@ export class App {
|
|||||||
return this.modules.ctx().em;
|
return this.modules.ctx().em;
|
||||||
}
|
}
|
||||||
|
|
||||||
get fetch(): any {
|
get fetch(): Hono["fetch"] {
|
||||||
return this.server.fetch;
|
return this.server.fetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +156,10 @@ export class App {
|
|||||||
return this.modules.version();
|
return this.modules.version();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBuilt(): boolean {
|
||||||
|
return this.modules.isBuilt();
|
||||||
|
}
|
||||||
|
|
||||||
registerAdminController(config?: AdminControllerOptions) {
|
registerAdminController(config?: AdminControllerOptions) {
|
||||||
// register admin
|
// register admin
|
||||||
this.adminController = new AdminController(this, config);
|
this.adminController = new AdminController(this, config);
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
export * from "./astro.adapter";
|
export * from "./astro.adapter";
|
||||||
export { registerLocalMediaAdapter } from "bknd/adapter/node";
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
export * from "./nextjs.adapter";
|
export * from "./nextjs.adapter";
|
||||||
export { registerLocalMediaAdapter } from "bknd/adapter/node";
|
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
export * from "./remix.adapter";
|
export * from "./remix.adapter";
|
||||||
export * from "./AdminPage";
|
export * from "./AdminPage";
|
||||||
export { registerLocalMediaAdapter } from "bknd/adapter/node";
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
export * from "./vite.adapter";
|
export * from "./vite.adapter";
|
||||||
export { registerLocalMediaAdapter } from "bknd/adapter/node";
|
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ export class Authenticator<Strategies extends Record<string, Strategy> = Record<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async requestCookieRefresh(c: Context) {
|
async requestCookieRefresh(c: Context) {
|
||||||
if (this.config.cookie.renew) {
|
if (this.config.cookie.renew && this.isUserLoggedIn()) {
|
||||||
const token = await this.getAuthCookie(c);
|
const token = await this.getAuthCookie(c);
|
||||||
if (token) {
|
if (token) {
|
||||||
await this.setAuthCookie(c, token);
|
await this.setAuthCookie(c, token);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export {
|
|||||||
export * as middlewares from "modules/middlewares";
|
export * as middlewares from "modules/middlewares";
|
||||||
export { registries } from "modules/registries";
|
export { registries } from "modules/registries";
|
||||||
|
|
||||||
export type * from "./adapter";
|
|
||||||
export { Api, type ApiOptions } from "./Api";
|
export { Api, type ApiOptions } from "./Api";
|
||||||
|
|
||||||
export type { MediaFieldSchema } from "media/AppMedia";
|
export type { MediaFieldSchema } from "media/AppMedia";
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ export type ApiResponse<Data = any> = {
|
|||||||
export type TInput = string | (string | number | PrimaryFieldType)[];
|
export type TInput = string | (string | number | PrimaryFieldType)[];
|
||||||
|
|
||||||
export abstract class ModuleApi<Options extends BaseModuleApiOptions = BaseModuleApiOptions> {
|
export abstract class ModuleApi<Options extends BaseModuleApiOptions = BaseModuleApiOptions> {
|
||||||
protected fetcher?: typeof fetch;
|
constructor(
|
||||||
|
protected readonly _options: Partial<Options> = {},
|
||||||
constructor(protected readonly _options: Partial<Options> = {}) {}
|
protected fetcher?: typeof fetch
|
||||||
|
) {}
|
||||||
|
|
||||||
protected getDefaultOptions(): Partial<Options> {
|
protected getDefaultOptions(): Partial<Options> {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -171,6 +171,10 @@ export class ModuleManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBuilt(): boolean {
|
||||||
|
return this._built;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is set through module's setListener
|
* This is set through module's setListener
|
||||||
* It's called everytime a module's config is updated in SchemaObject
|
* It's called everytime a module's config is updated in SchemaObject
|
||||||
|
|||||||
Reference in New Issue
Block a user