Sakib
Sakib
Explore posts from servers
HHono
Created by Sakib on 5/20/2024 in #help
Type 'Hono<App {...}>' does not satisfy the constraint 'Hono<any, any, any> Property '#private' in t
Hi, I'm trying to use hono RPC client on my frontend project. But the type not working properly. I'm using "hono": "^4.3.7", on server and client. // On /web-api/src/routes/index.ts [Server]
import { App } from "@/@types/app";
import { Hono } from "hono";
import UserRoutes from "@/routes/users";

const app = new Hono<App>().route("/users", UserRoutes);

export type AppType = typeof app;
export default app;
import { App } from "@/@types/app";
import { Hono } from "hono";
import UserRoutes from "@/routes/users";

const app = new Hono<App>().route("/users", UserRoutes);

export type AppType = typeof app;
export default app;
// On /web-api/src/routes/users/index.ts [Server]
import { App } from "@/@types/app";
import { Hono } from "hono";

const app = new Hono<App>()
.get("/", async (c) => {
return c.json({});
})
.get("/test", async (c) => {
return c.json({});
});

export default app;
import { App } from "@/@types/app";
import { Hono } from "hono";

const app = new Hono<App>()
.get("/", async (c) => {
return c.json({});
})
.get("/test", async (c) => {
return c.json({});
});

export default app;
// On /web-api/tsconfig.json [Server]
{
"compilerOptions": {
"composite": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"lib": ["ESNext"],
"types": ["@cloudflare/workers-types"],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
"paths": {
"@/*": ["./src/*"]
}
}
}
{
"compilerOptions": {
"composite": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"lib": ["ESNext"],
"types": ["@cloudflare/workers-types"],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
"paths": {
"@/*": ["./src/*"]
}
}
}
// On /web-ui/tsconfig.json [Client]
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Other */
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@api/*": ["../web-api/src/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }, { "path": "../web-api" }]
}
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Other */
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@api/*": ["../web-api/src/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }, { "path": "../web-api" }]
}
3 replies
DTDrizzle Team
Created by Sakib on 3/6/2024 in #help
TypeErr: BatchItem<sqlite>[] not assignable to readonly [BatchItem<sqlite>, ...BatchItem<sqlite>[]]
Hi, I'm trying to use drizzle/d1 (cloudflare worker) for batch. But I'm getting type error.
export const insert_logs_from_batch = async (
batch: MessageBatch<logSchema>,
env: Bindings
): Promise<InsertBatchLogsResponse> => {
const db = drizzle(env.DB);

const refine_batch = batch.messages.map((log) => {
return db.insert(logs).values({
...log.body
}) as BatchItem<"sqlite">; // <--casting as BatchItem cause original type doesn't match as batchItem
});

try {
const res = await db.batch([...refine_batch]); // --> Getting the type error here. it works on runtime

return { success: true, data: null };
} catch (err) {
return { success: false, error: err };
}
};
export const insert_logs_from_batch = async (
batch: MessageBatch<logSchema>,
env: Bindings
): Promise<InsertBatchLogsResponse> => {
const db = drizzle(env.DB);

const refine_batch = batch.messages.map((log) => {
return db.insert(logs).values({
...log.body
}) as BatchItem<"sqlite">; // <--casting as BatchItem cause original type doesn't match as batchItem
});

try {
const res = await db.batch([...refine_batch]); // --> Getting the type error here. it works on runtime

return { success: true, data: null };
} catch (err) {
return { success: false, error: err };
}
};
1 replies
CDCloudflare Developers
Created by Sakib on 2/19/2024 in #workers-help
Hyperdrive not working on local environment
Hi, I'm getting an error from hyperdrive.
✘ [ERROR] When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the 'WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE' variable or "HYPERDRIVE"'s "localConnectionString" to the Postgres connection string.
✘ [ERROR] When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the 'WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE' variable or "HYPERDRIVE"'s "localConnectionString" to the Postgres connection string.
I'm not sure what does that mean? I added a WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE variable on wrangler.toml file under [vars] but still not working
4 replies
DTDrizzle Team
Created by Sakib on 12/30/2023 in #help
Typescript not showing where field in query. Query working but ts throwing error
Hi, I have a query like below
const weight = await drizzle(c.env.DB, { schema }).query.weights.findFirst({
with: {
type: {
// @ts-expect-error where is not defined in the type
where: and(eq(types.type, parse.type), eq(types.id, parse.type_id)),
// Only showing columns, extras, with field
},
},
where: and(eq(weights.type_id, parse.type_id), eq(weights.weight, parse.weight)),
});
const weight = await drizzle(c.env.DB, { schema }).query.weights.findFirst({
with: {
type: {
// @ts-expect-error where is not defined in the type
where: and(eq(types.type, parse.type), eq(types.id, parse.type_id)),
// Only showing columns, extras, with field
},
},
where: and(eq(weights.type_id, parse.type_id), eq(weights.weight, parse.weight)),
});
// relations.ts
export const typesRelations = relations(types, ({ many }) => ({
weights: many(weights),
}));

export const weightsRelations = relations(weights, ({ one }) => ({
type: one(types, {
fields: [weights.type_id],
references: [types.id],
}),
}));
export const typesRelations = relations(types, ({ many }) => ({
weights: many(weights),
}));

export const weightsRelations = relations(weights, ({ one }) => ({
type: one(types, {
fields: [weights.type_id],
references: [types.id],
}),
}));
I'm using drizzle-orm: ^0.29.1
4 replies
CDCloudflare Developers
Created by Sakib on 10/11/2023 in #workers-help
If I called waitUntil(callback()) in a loop just say loop length is 100, so does that mean the...?
If I called waitUntil(callback()) in a loop just say loop length is 100, so does that mean the callback() function will run in a multiple thread or in a single thread? or waituntil will use a different instance for each time?
1 replies
DTDrizzle Team
Created by Sakib on 9/20/2023 in #help
Which typescript type should I use for select?
Hi, this question might be confusing. Let me explain the problem, I'm building a common function for drizzle().select() somethine like
const data = await selectQuery(ctx, tableName, {id:tableName.id, data:tableName.data}); // should return {id:number,data:string}

// select
export const selectQuery = async <T extends SQLiteTable<TableConfig>>(ctx: TRPContextUser, table: T, select: SelectedFields) => {
return await drizzle(ctx.c.env.DB).select(select).from(table).all(); // returning {[x:string]:never}
};
const data = await selectQuery(ctx, tableName, {id:tableName.id, data:tableName.data}); // should return {id:number,data:string}

// select
export const selectQuery = async <T extends SQLiteTable<TableConfig>>(ctx: TRPContextUser, table: T, select: SelectedFields) => {
return await drizzle(ctx.c.env.DB).select(select).from(table).all(); // returning {[x:string]:never}
};
you can see I'm getting {[x:string]:never} when I pass {id:number;data:string} on select param.
5 replies
CDCloudflare Developers
Created by Sakib on 8/26/2023 in #workers-help
How to use cloudflare saas custom hosts feature with worker?
Hi, I have a worker, which can show pages based on unique sub domain, like customer1.mydomain.com, customer2.mydomain.com etc. now my customer have their own domain which they can add from my site, which trigger the worker and the worker will add the custom hostname to my domain (saas) . customer will have to add a cname from their dns like cname => customerdomain.com => (customer1.mydomain.com), I want to do something like that, But I'm not sure I can do it with worker. Since I can't point worker (subdomain.worker.dev) address via cname on my domain (according to some article I read from cloudflare community post), that's mean I can't add a fallback domain on saas. to add a fallback domain I will need to use A/CNAME record, which not possible for workers, anyone can give me any suggestion? that would be great
3 replies
CDCloudflare Developers
Created by Sakib on 8/23/2023 in #workers-help
Can't add custom domain on a worker. stuck at initializing for 6 hours, seems edge advanced cert stu
1 replies
CDCloudflare Developers
Created by Sakib on 6/11/2023 in #pages-help
Trying to pass data from middleware context.data = {id:1} to a function, not working :(
Hi, I have a middleware inside functions/api/_middleware.ts now I'm trying to pass some data from that middleware to a function like I want to access that data on onRequest(data) like that. right now, it returning an empty object.
2 replies
CDCloudflare Developers
Created by Sakib on 6/10/2023 in #pages-help
Middleware not working as excepted
2 replies
CDCloudflare Developers
Created by Sakib on 6/5/2023 in #pages-help
Getting a warning message in the wrangler terminal "Your worker called response.clone() but didn..."
3 replies
CDCloudflare Developers
Created by Sakib on 5/17/2023 in #workers-help
I'm getting CORS policy issue with the pages function.
2 replies
CDCloudflare Developers
Created by Sakib on 5/7/2023 in #pages-help
wrangler pages dev --local . not loading the wrangler.toml file.
Hi, I'm trying to load wrangler.toml file in the pages functions, I'm running this cmd npx wrangler pages dev --local . but it saying in the terminal, No compatibility_date was specified. But I did add this in the wrangler.toml file. /root /root/functions/index.ts /wrangler.toml
2 replies
CDCloudflare Developers
Created by Sakib on 5/4/2023 in #workers-help
Horseman CMS not working
HI, I've setup 2 worker according to docs, But it's not working. plz check this https://github.com/AggressivelyMeows/Horseman/discussions/8
11 replies