@bbki.ng/backend 0.3.1 → 0.3.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # backend
2
2
 
3
+ ## 0.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - f12873e: update config
8
+ - 152ba35: update config
9
+ - 04c87c5: update config
10
+ - 74bdf37: update config
11
+ - 9142b64: update mono repo config
12
+
13
+ ## 0.3.2
14
+
3
15
  ## 0.3.1
4
16
 
5
17
  ## 0.3.0
@@ -0,0 +1,12 @@
1
+ import cloudflareConfig from '@bbki.ng/config/eslint/cloudflare';
2
+ import { includeIgnoreFile } from '@eslint/compat';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ export default [
10
+ includeIgnoreFile(path.resolve(__dirname, '.gitignore')),
11
+ ...cloudflareConfig,
12
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/backend",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@simplewebauthn/server": "13.2.2",
@@ -8,9 +8,21 @@
8
8
  },
9
9
  "devDependencies": {
10
10
  "@cloudflare/workers-types": "4.20251128.0",
11
+ "@eslint/compat": "^1.0.0",
12
+ "@eslint/js": "^8.57.0",
11
13
  "@types/node": "25.0.3",
12
- "wrangler": "^4.58.0"
14
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
15
+ "@typescript-eslint/parser": "^7.0.0",
16
+ "eslint": "^8.57.0",
17
+ "eslint-plugin-import": "^2.29.0",
18
+ "eslint-plugin-unicorn": "^51.0.0",
19
+ "globals": "^14.0.0",
20
+ "prettier": "^3.2.0",
21
+ "typescript": "^5.3.0",
22
+ "wrangler": "^4.58.0",
23
+ "@bbki.ng/config": "1.0.1"
13
24
  },
25
+ "prettier": "@bbki.ng/config/prettier",
14
26
  "scripts": {
15
27
  "dev": "wrangler dev",
16
28
  "deploy": "wrangler deploy --minify",
@@ -2,9 +2,47 @@ import { Context } from "hono";
2
2
 
3
3
  export const listStreaming = async (c: Context) => {
4
4
  try {
5
- const { results } = await c.env.DB.prepare(
6
- "SELECT id, author, content, type, created_at as createdAt FROM streaming ORDER BY created_at DESC LIMIT 100"
7
- ).all();
5
+ // Parse query parameters
6
+ // 'before' - fetch records older than this ID (for pagination / next page)
7
+ // 'after' - fetch records newer than this ID (for polling / new messages)
8
+ // 'offset' - number of records to fetch (default: 8, max: 100)
9
+ const before = c.req.query("before");
10
+ const after = c.req.query("after");
11
+ const offset = Math.min(parseInt(c.req.query("offset") || "8", 10), 100);
12
+
13
+ let results;
14
+
15
+ if (before) {
16
+ // Fetch records older than the specified id (pagination - next page)
17
+ const { results: cursorResults } = await c.env.DB.prepare(
18
+ `SELECT id, author, content, type, created_at as createdAt
19
+ FROM streaming
20
+ WHERE created_at < (SELECT created_at FROM streaming WHERE id = ?)
21
+ ORDER BY created_at DESC
22
+ LIMIT ?`
23
+ ).bind(before, offset).all();
24
+ results = cursorResults;
25
+ } else if (after) {
26
+ // Fetch records newer than the specified id (polling - new messages)
27
+ // Return in ascending order so client can unshift them in order
28
+ const { results: cursorResults } = await c.env.DB.prepare(
29
+ `SELECT id, author, content, type, created_at as createdAt
30
+ FROM streaming
31
+ WHERE created_at > (SELECT created_at FROM streaming WHERE id = ?)
32
+ ORDER BY created_at ASC
33
+ LIMIT ?`
34
+ ).bind(after, offset).all();
35
+ results = cursorResults;
36
+ } else {
37
+ // Fetch the most recent records
38
+ const { results: recentResults } = await c.env.DB.prepare(
39
+ `SELECT id, author, content, type, created_at as createdAt
40
+ FROM streaming
41
+ ORDER BY created_at DESC
42
+ LIMIT ?`
43
+ ).bind(offset).all();
44
+ results = recentResults;
45
+ }
8
46
 
9
47
  return c.json({
10
48
  status: "success",
package/src/index.ts CHANGED
@@ -1,15 +1,13 @@
1
- import app from "./config/app.config";
1
+ import app from './config/app.config';
2
2
 
3
- import { commentRouter } from "./routes/comment.routes";
4
- import { authRoutes } from "./routes/authn.routes";
5
- import { streamingRouter } from "./routes/streaming.routes";
3
+ import { commentRouter } from './routes/comment.routes';
4
+ import { streamingRouter } from './routes/streaming.routes';
6
5
 
7
- app.route("comment", commentRouter);
8
- app.route("auth", authRoutes);
9
- app.route("streaming", streamingRouter);
6
+ app.route('comment', commentRouter);
7
+ app.route('streaming', streamingRouter);
10
8
 
11
- app.get("/", (c) => {
12
- return c.text("Hello Hono!");
9
+ app.get('/', c => {
10
+ return c.text('Hello Hono!');
13
11
  });
14
12
 
15
13
  export default app;
package/tsconfig.json CHANGED
@@ -1,14 +1,9 @@
1
1
  {
2
+ "extends": "../../tsconfig.base.json",
2
3
  "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "strict": true,
7
- "skipLibCheck": true,
8
- "lib": [
9
- "ESNext"
10
- ],
4
+ "moduleResolution": "bundler",
11
5
  "jsx": "react-jsx",
12
- "jsxImportSource": "hono/jsx"
6
+ "jsxImportSource": "hono/jsx",
7
+ "types": ["@cloudflare/workers-types", "node"],
13
8
  },
14
- }
9
+ }