@forinda/kickjs 2.0.0 → 2.1.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/README.md +85 -584
- package/dist/adapter-BqGjZCSm.d.mts +122 -0
- package/dist/adapter-BqGjZCSm.d.mts.map +1 -0
- package/dist/app-module-CcEbAVtB.d.mts +33 -0
- package/dist/app-module-CcEbAVtB.d.mts.map +1 -0
- package/dist/application-DNHj-_UL.mjs +449 -0
- package/dist/application-DNHj-_UL.mjs.map +1 -0
- package/dist/bootstrap-DLEZaJ3b.mjs +205 -0
- package/dist/bootstrap-DLEZaJ3b.mjs.map +1 -0
- package/dist/{core/cache.d.ts → cache-DJeMaGqb.d.mts} +33 -31
- package/dist/cache-DJeMaGqb.d.mts.map +1 -0
- package/dist/chunk-C5Qp-JxE.mjs +15 -0
- package/dist/container-nBSIhyqV.d.mts +141 -0
- package/dist/container-nBSIhyqV.d.mts.map +1 -0
- package/dist/core/adapter.d.mts +3 -0
- package/dist/core/adapter.mjs +11 -0
- package/dist/core/app-module.d.mts +3 -0
- package/dist/core/app-module.mjs +11 -0
- package/dist/core/cache.d.mts +3 -0
- package/dist/core/cache.mjs +113 -0
- package/dist/core/cache.mjs.map +1 -0
- package/dist/core/container.d.mts +3 -0
- package/dist/core/container.mjs +426 -0
- package/dist/core/container.mjs.map +1 -0
- package/dist/core/cron.d.mts +3 -0
- package/dist/core/cron.mjs +42 -0
- package/dist/core/cron.mjs.map +1 -0
- package/dist/core/decorators.d.mts +3 -0
- package/dist/core/decorators.mjs +213 -0
- package/dist/core/decorators.mjs.map +1 -0
- package/dist/core/errors.d.mts +3 -0
- package/dist/core/errors.mjs +97 -0
- package/dist/core/errors.mjs.map +1 -0
- package/dist/core/interfaces.d.mts +3 -0
- package/dist/core/interfaces.mjs +44 -0
- package/dist/core/interfaces.mjs.map +1 -0
- package/dist/core/logger.d.mts +3 -0
- package/dist/core/logger.mjs +217 -0
- package/dist/core/logger.mjs.map +1 -0
- package/dist/core/path.d.mts +3 -0
- package/dist/core/path.mjs +45 -0
- package/dist/core/path.mjs.map +1 -0
- package/dist/core/plugin.d.mts +3 -0
- package/dist/core/plugin.mjs +11 -0
- package/dist/core/reactivity.d.mts +3 -0
- package/dist/core/reactivity.mjs +189 -0
- package/dist/core/reactivity.mjs.map +1 -0
- package/dist/core-BL_H8fEZ.mjs +121 -0
- package/dist/core-BL_H8fEZ.mjs.map +1 -0
- package/dist/{core/cron.d.ts → cron-RKhH5TOd.d.mts} +16 -14
- package/dist/cron-RKhH5TOd.d.mts.map +1 -0
- package/dist/decorators-CQ93ak6Z.d.mts +154 -0
- package/dist/decorators-CQ93ak6Z.d.mts.map +1 -0
- package/dist/errors-te5Km00o.d.mts +68 -0
- package/dist/errors-te5Km00o.d.mts.map +1 -0
- package/dist/http/application.d.mts +220 -0
- package/dist/http/application.d.mts.map +1 -0
- package/dist/http/application.mjs +12 -0
- package/dist/http/bootstrap.d.mts +43 -0
- package/dist/http/bootstrap.d.mts.map +1 -0
- package/dist/http/bootstrap.mjs +12 -0
- package/dist/http/context.d.mts +131 -0
- package/dist/http/context.d.mts.map +1 -0
- package/dist/http/context.mjs +220 -0
- package/dist/http/context.mjs.map +1 -0
- package/dist/http/middleware/cors.d.mts +48 -0
- package/dist/http/middleware/cors.d.mts.map +1 -0
- package/dist/http/middleware/cors.mjs +83 -0
- package/dist/http/middleware/cors.mjs.map +1 -0
- package/dist/http/middleware/csrf.d.mts +52 -0
- package/dist/http/middleware/csrf.d.mts.map +1 -0
- package/dist/http/middleware/csrf.mjs +72 -0
- package/dist/http/middleware/csrf.mjs.map +1 -0
- package/dist/http/middleware/error-handler.d.mts +11 -0
- package/dist/http/middleware/error-handler.d.mts.map +1 -0
- package/dist/http/middleware/error-handler.mjs +52 -0
- package/dist/http/middleware/error-handler.mjs.map +1 -0
- package/dist/http/middleware/helmet.d.mts +41 -0
- package/dist/http/middleware/helmet.d.mts.map +1 -0
- package/dist/http/middleware/helmet.mjs +51 -0
- package/dist/http/middleware/helmet.mjs.map +1 -0
- package/dist/http/middleware/rate-limit.d.mts +56 -0
- package/dist/http/middleware/rate-limit.d.mts.map +1 -0
- package/dist/http/middleware/rate-limit.mjs +101 -0
- package/dist/http/middleware/rate-limit.mjs.map +1 -0
- package/dist/http/middleware/request-id.d.mts +10 -0
- package/dist/http/middleware/request-id.d.mts.map +1 -0
- package/dist/http/middleware/request-id.mjs +26 -0
- package/dist/http/middleware/request-id.mjs.map +1 -0
- package/dist/http/middleware/request-logger.d.mts +32 -0
- package/dist/http/middleware/request-logger.d.mts.map +1 -0
- package/dist/http/middleware/request-logger.mjs +49 -0
- package/dist/http/middleware/request-logger.mjs.map +1 -0
- package/dist/http/middleware/session.d.mts +67 -0
- package/dist/http/middleware/session.d.mts.map +1 -0
- package/dist/http/middleware/session.mjs +152 -0
- package/dist/http/middleware/session.mjs.map +1 -0
- package/dist/http/middleware/spa.d.mts +101 -0
- package/dist/http/middleware/spa.d.mts.map +1 -0
- package/dist/http/middleware/spa.mjs +108 -0
- package/dist/http/middleware/spa.mjs.map +1 -0
- package/dist/http/middleware/{upload.d.ts → upload.d.mts} +21 -17
- package/dist/http/middleware/upload.d.mts.map +1 -0
- package/dist/http/middleware/upload.mjs +191 -0
- package/dist/http/middleware/upload.mjs.map +1 -0
- package/dist/http/middleware/validate.d.mts +18 -0
- package/dist/http/middleware/validate.d.mts.map +1 -0
- package/dist/http/middleware/validate.mjs +62 -0
- package/dist/http/middleware/validate.mjs.map +1 -0
- package/dist/http/middleware/views.d.mts +62 -0
- package/dist/http/middleware/views.d.mts.map +1 -0
- package/dist/http/middleware/views.mjs +65 -0
- package/dist/http/middleware/views.mjs.map +1 -0
- package/dist/http/query/index.d.mts +3 -0
- package/dist/http/query/index.mjs +12 -0
- package/dist/http/{router-builder.d.ts → router-builder.d.mts} +9 -5
- package/dist/http/router-builder.d.mts.map +1 -0
- package/dist/http/router-builder.mjs +67 -0
- package/dist/http/router-builder.mjs.map +1 -0
- package/dist/index-C0gbnpSg.d.mts +107 -0
- package/dist/index-C0gbnpSg.d.mts.map +1 -0
- package/dist/index-Cls52etj.d.mts +148 -0
- package/dist/index-Cls52etj.d.mts.map +1 -0
- package/dist/index.d.mts +133 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +126 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces-D-48zotH.d.mts +52 -0
- package/dist/interfaces-D-48zotH.d.mts.map +1 -0
- package/dist/logger-Dzj-TF0t.d.mts +119 -0
- package/dist/logger-Dzj-TF0t.d.mts.map +1 -0
- package/dist/metadata-fmvikBA0.mjs +76 -0
- package/dist/metadata-fmvikBA0.mjs.map +1 -0
- package/dist/{core/path.d.ts → path-LmwfhfyH.d.mts} +7 -3
- package/dist/path-LmwfhfyH.d.mts.map +1 -0
- package/dist/plugin-DIoPIpSm.d.mts +95 -0
- package/dist/plugin-DIoPIpSm.d.mts.map +1 -0
- package/dist/query-7cdHF6ry.mjs +164 -0
- package/dist/query-7cdHF6ry.mjs.map +1 -0
- package/dist/{core/reactivity.d.ts → reactivity-BbS-99ow.d.mts} +21 -20
- package/dist/reactivity-BbS-99ow.d.mts.map +1 -0
- package/package.json +73 -43
- package/dist/chunk-DVVP7zzD.js +0 -7
- package/dist/core/adapter.d.ts +0 -109
- package/dist/core/adapter.d.ts.map +0 -1
- package/dist/core/adapter.js +0 -0
- package/dist/core/app-module.d.ts +0 -28
- package/dist/core/app-module.d.ts.map +0 -1
- package/dist/core/app-module.js +0 -0
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/cache.js +0 -57
- package/dist/core/container.d.ts +0 -63
- package/dist/core/container.d.ts.map +0 -1
- package/dist/core/container.js +0 -117
- package/dist/core/cron.d.ts.map +0 -1
- package/dist/core/cron.js +0 -22
- package/dist/core/decorators.d.ts +0 -153
- package/dist/core/decorators.d.ts.map +0 -1
- package/dist/core/decorators.js +0 -141
- package/dist/core/errors.d.ts +0 -64
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/errors.js +0 -67
- package/dist/core/index.d.ts +0 -14
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/interfaces.d.ts +0 -44
- package/dist/core/interfaces.d.ts.map +0 -1
- package/dist/core/interfaces.js +0 -25
- package/dist/core/logger.d.ts +0 -43
- package/dist/core/logger.d.ts.map +0 -1
- package/dist/core/logger.js +0 -54
- package/dist/core/path.d.ts.map +0 -1
- package/dist/core/path.js +0 -12
- package/dist/core/plugin.d.ts +0 -90
- package/dist/core/plugin.d.ts.map +0 -1
- package/dist/core/plugin.js +0 -0
- package/dist/core/reactivity.d.ts.map +0 -1
- package/dist/core/reactivity.js +0 -101
- package/dist/core-B6Okew3W.js +0 -7
- package/dist/http/application.d.ts +0 -103
- package/dist/http/application.d.ts.map +0 -1
- package/dist/http/application.js +0 -167
- package/dist/http/bootstrap.d.ts +0 -22
- package/dist/http/bootstrap.d.ts.map +0 -1
- package/dist/http/bootstrap.js +0 -40
- package/dist/http/context.d.ts +0 -129
- package/dist/http/context.d.ts.map +0 -1
- package/dist/http/context.js +0 -115
- package/dist/http/index.d.ts +0 -16
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/middleware/cors.d.ts +0 -43
- package/dist/http/middleware/cors.d.ts.map +0 -1
- package/dist/http/middleware/cors.js +0 -31
- package/dist/http/middleware/csrf.d.ts +0 -47
- package/dist/http/middleware/csrf.d.ts.map +0 -1
- package/dist/http/middleware/csrf.js +0 -25
- package/dist/http/middleware/error-handler.d.ts +0 -6
- package/dist/http/middleware/error-handler.d.ts.map +0 -1
- package/dist/http/middleware/error-handler.js +0 -37
- package/dist/http/middleware/helmet.d.ts +0 -36
- package/dist/http/middleware/helmet.d.ts.map +0 -1
- package/dist/http/middleware/helmet.js +0 -20
- package/dist/http/middleware/rate-limit.d.ts +0 -51
- package/dist/http/middleware/rate-limit.d.ts.map +0 -1
- package/dist/http/middleware/rate-limit.js +0 -46
- package/dist/http/middleware/request-id.d.ts +0 -5
- package/dist/http/middleware/request-id.d.ts.map +0 -1
- package/dist/http/middleware/request-id.js +0 -12
- package/dist/http/middleware/request-logger.d.ts +0 -27
- package/dist/http/middleware/request-logger.d.ts.map +0 -1
- package/dist/http/middleware/request-logger.js +0 -16
- package/dist/http/middleware/session.d.ts +0 -62
- package/dist/http/middleware/session.d.ts.map +0 -1
- package/dist/http/middleware/session.js +0 -76
- package/dist/http/middleware/spa.d.ts +0 -93
- package/dist/http/middleware/spa.d.ts.map +0 -1
- package/dist/http/middleware/spa.js +0 -52
- package/dist/http/middleware/upload.d.ts.map +0 -1
- package/dist/http/middleware/upload.js +0 -119
- package/dist/http/middleware/validate.d.ts +0 -13
- package/dist/http/middleware/validate.d.ts.map +0 -1
- package/dist/http/middleware/validate.js +0 -45
- package/dist/http/middleware/views.d.ts +0 -56
- package/dist/http/middleware/views.d.ts.map +0 -1
- package/dist/http/middleware/views.js +0 -18
- package/dist/http/query/index.d.ts +0 -4
- package/dist/http/query/index.d.ts.map +0 -1
- package/dist/http/query/index.js +0 -10
- package/dist/http/query/parse-query.d.ts +0 -44
- package/dist/http/query/parse-query.d.ts.map +0 -1
- package/dist/http/query/types.d.ts +0 -100
- package/dist/http/query/types.d.ts.map +0 -1
- package/dist/http/router-builder.d.ts.map +0 -1
- package/dist/http/router-builder.js +0 -37
- package/dist/index.d.ts +0 -25
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -103
- package/dist/query-Bym31XRp.js +0 -88
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { createHmac as v, randomUUID as x, timingSafeEqual as I } from "node:crypto";
|
|
2
|
-
var O = class {
|
|
3
|
-
sessions = /* @__PURE__ */ new Map();
|
|
4
|
-
cleanupInterval;
|
|
5
|
-
constructor() {
|
|
6
|
-
this.cleanupInterval = setInterval(() => this.purge(), 6e4), this.cleanupInterval.unref();
|
|
7
|
-
}
|
|
8
|
-
async get(e) {
|
|
9
|
-
const t = this.sessions.get(e);
|
|
10
|
-
return t ? Date.now() > t.expires ? (this.sessions.delete(e), null) : t.data : null;
|
|
11
|
-
}
|
|
12
|
-
async set(e, t, s) {
|
|
13
|
-
this.sessions.set(e, {
|
|
14
|
-
data: t,
|
|
15
|
-
expires: Date.now() + s
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
async destroy(e) {
|
|
19
|
-
this.sessions.delete(e);
|
|
20
|
-
}
|
|
21
|
-
async touch(e, t) {
|
|
22
|
-
const s = this.sessions.get(e);
|
|
23
|
-
s && (s.expires = Date.now() + t);
|
|
24
|
-
}
|
|
25
|
-
purge() {
|
|
26
|
-
const e = Date.now();
|
|
27
|
-
for (const [t, s] of this.sessions) e > s.expires && this.sessions.delete(t);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
function w(e, t) {
|
|
31
|
-
return `s:${e}.${v("sha256", t).update(e).digest("base64url")}`;
|
|
32
|
-
}
|
|
33
|
-
function S(e, t) {
|
|
34
|
-
if (!e.startsWith("s:")) return !1;
|
|
35
|
-
const s = e.slice(2), a = s.lastIndexOf(".");
|
|
36
|
-
if (a === -1) return !1;
|
|
37
|
-
const u = s.slice(0, a), p = s.slice(a + 1), i = v("sha256", t).update(u).digest("base64url"), o = Buffer.from(p), c = Buffer.from(i);
|
|
38
|
-
return o.length !== c.length || !I(o, c) ? !1 : u;
|
|
39
|
-
}
|
|
40
|
-
function N(e) {
|
|
41
|
-
const { secret: t, cookieName: s = "kick.sid", maxAge: a = 864e5, rolling: u = !1, saveUninitialized: p = !0, store: i = new O(), cookie: o = {} } = e, c = {
|
|
42
|
-
httpOnly: o.httpOnly ?? !0,
|
|
43
|
-
secure: o.secure ?? process.env.NODE_ENV === "production",
|
|
44
|
-
sameSite: o.sameSite ?? "lax",
|
|
45
|
-
path: o.path ?? "/",
|
|
46
|
-
...o.domain ? { domain: o.domain } : {},
|
|
47
|
-
maxAge: a
|
|
48
|
-
};
|
|
49
|
-
return async (m, f, D) => {
|
|
50
|
-
const k = (m.cookies || {})[s];
|
|
51
|
-
let l = !1, h = null, d = !1;
|
|
52
|
-
k && (l = S(k, t), l && (h = await i.get(l))), (!l || !h) && (l = x(), h = {}, d = !0);
|
|
53
|
-
let n = l, r = { ...h }, y = !1;
|
|
54
|
-
const g = {
|
|
55
|
-
get id() {
|
|
56
|
-
return n;
|
|
57
|
-
},
|
|
58
|
-
data: r,
|
|
59
|
-
async regenerate() {
|
|
60
|
-
await i.destroy(n), n = x(), r = {}, g.data = r, await i.set(n, r, a), f.cookie(s, w(n, t), c);
|
|
61
|
-
},
|
|
62
|
-
async destroy() {
|
|
63
|
-
await i.destroy(n), y = !0, r = {}, g.data = r, f.clearCookie(s, { path: c.path });
|
|
64
|
-
},
|
|
65
|
-
async save() {
|
|
66
|
-
y || await i.set(n, r, a);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
m.session = g, d && f.cookie(s, w(n, t), c), f.on("finish", async () => {
|
|
70
|
-
y || d && !p && Object.keys(r).length === 0 || (await i.set(n, r, a), u && !d && i.touch && await i.touch(n, a));
|
|
71
|
-
}), u && !d && f.cookie(s, w(n, t), c), D();
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
N as session
|
|
76
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { type AppAdapter, type AdapterContext } from '../../core';
|
|
2
|
-
export interface SpaAdapterOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Directory containing the built SPA files (index.html, assets, etc.)
|
|
5
|
-
* Default: 'dist/client'
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* // Vue: 'dist'
|
|
10
|
-
* // React (Vite): 'dist'
|
|
11
|
-
* // React (CRA): 'build'
|
|
12
|
-
* // Svelte: 'build'
|
|
13
|
-
* // Angular: 'dist/my-app/browser'
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
clientDir?: string;
|
|
17
|
-
/**
|
|
18
|
-
* URL prefix for API routes. SPA fallback only applies to
|
|
19
|
-
* non-API routes (routes NOT starting with this prefix).
|
|
20
|
-
* Default: '/api'
|
|
21
|
-
*
|
|
22
|
-
* Set to an array for multiple prefixes:
|
|
23
|
-
* ```ts
|
|
24
|
-
* apiPrefix: ['/api', '/graphql', '/_debug']
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
apiPrefix?: string | string[];
|
|
28
|
-
/**
|
|
29
|
-
* Additional paths to exclude from SPA fallback.
|
|
30
|
-
* These paths will NOT serve index.html.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* exclude: ['/health', '/metrics', '/ws']
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
exclude?: string[];
|
|
38
|
-
/**
|
|
39
|
-
* Cache-Control header for static assets (default: 'public, max-age=31536000, immutable')
|
|
40
|
-
* Set to false to disable caching headers.
|
|
41
|
-
*/
|
|
42
|
-
cacheControl?: string | false;
|
|
43
|
-
/**
|
|
44
|
-
* Cache-Control for index.html (default: 'no-cache')
|
|
45
|
-
* index.html should not be cached to ensure clients get fresh builds.
|
|
46
|
-
*/
|
|
47
|
-
indexCacheControl?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* SPA adapter — serve a Vue, React, Svelte, or Angular build alongside
|
|
51
|
-
* your KickJS API. API routes are handled by controllers; everything else
|
|
52
|
-
* falls back to index.html for client-side routing.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* import { SpaAdapter } from '@forinda/kickjs-http/spa'
|
|
57
|
-
*
|
|
58
|
-
* bootstrap({
|
|
59
|
-
* modules,
|
|
60
|
-
* adapters: [
|
|
61
|
-
* new SpaAdapter({
|
|
62
|
-
* clientDir: 'dist/client', // or 'build', 'dist', etc.
|
|
63
|
-
* apiPrefix: '/api',
|
|
64
|
-
* }),
|
|
65
|
-
* ],
|
|
66
|
-
* })
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* File structure:
|
|
70
|
-
* ```
|
|
71
|
-
* dist/
|
|
72
|
-
* client/ ← SPA build output
|
|
73
|
-
* index.html
|
|
74
|
-
* assets/
|
|
75
|
-
* app.js
|
|
76
|
-
* style.css
|
|
77
|
-
* server/ ← KickJS server
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export declare class SpaAdapter implements AppAdapter {
|
|
81
|
-
private options;
|
|
82
|
-
name: string;
|
|
83
|
-
private clientDir;
|
|
84
|
-
private apiPrefixes;
|
|
85
|
-
private excludePaths;
|
|
86
|
-
private cacheControl;
|
|
87
|
-
private indexCacheControl;
|
|
88
|
-
private indexHtml;
|
|
89
|
-
constructor(options?: SpaAdapterOptions);
|
|
90
|
-
beforeMount({ app }: AdapterContext): void;
|
|
91
|
-
beforeStart({ app }: AdapterContext): void;
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=spa.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spa.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/spa.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAIzE,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAE7B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAE7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,UAAW,YAAW,UAAU;IAS/B,OAAO,CAAC,OAAO;IAR3B,IAAI,SAAe;IACnB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,SAAS,CAAsB;gBAEnB,OAAO,GAAE,iBAAsB;IAUnD,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,GAAG,IAAI;IAyC1C,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,GAAG,IAAI;CA2B3C"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { t as c } from "../../chunk-DVVP7zzD.js";
|
|
2
|
-
import { Logger as h } from "../../core/logger.js";
|
|
3
|
-
import "../../core-B6Okew3W.js";
|
|
4
|
-
import { join as l, resolve as d } from "node:path";
|
|
5
|
-
import { existsSync as a, readFileSync as f } from "node:fs";
|
|
6
|
-
var s = h.for("SpaAdapter"), P = class {
|
|
7
|
-
name = "SpaAdapter";
|
|
8
|
-
clientDir;
|
|
9
|
-
apiPrefixes;
|
|
10
|
-
excludePaths;
|
|
11
|
-
cacheControl;
|
|
12
|
-
indexCacheControl;
|
|
13
|
-
indexHtml = null;
|
|
14
|
-
constructor(e = {}) {
|
|
15
|
-
this.options = e, this.clientDir = d(e.clientDir ?? "dist/client"), this.excludePaths = e.exclude ?? [], this.cacheControl = e.cacheControl ?? "public, max-age=31536000, immutable", this.indexCacheControl = e.indexCacheControl ?? "no-cache";
|
|
16
|
-
const t = e.apiPrefix ?? "/api";
|
|
17
|
-
this.apiPrefixes = Array.isArray(t) ? t : [t];
|
|
18
|
-
}
|
|
19
|
-
beforeMount({ app: e }) {
|
|
20
|
-
if (!a(this.clientDir)) {
|
|
21
|
-
s.warn(`SPA client directory not found: ${this.clientDir}`), s.warn("Build your frontend first, or set clientDir to the correct path.");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const t = l(this.clientDir, "index.html");
|
|
25
|
-
if (a(t)) this.indexHtml = f(t, "utf-8");
|
|
26
|
-
else {
|
|
27
|
-
s.warn(`index.html not found in ${this.clientDir}`);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const n = c("express"), i = {};
|
|
32
|
-
this.cacheControl && (i.setHeaders = (r, o) => {
|
|
33
|
-
o.endsWith(".html") ? r.setHeader("Cache-Control", this.indexCacheControl) : r.setHeader("Cache-Control", this.cacheControl);
|
|
34
|
-
}), e.use(n.static(this.clientDir, i));
|
|
35
|
-
} catch {
|
|
36
|
-
s.error("express.static not available — SPA static file serving disabled");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
s.info(`Serving SPA from ${this.clientDir}`);
|
|
40
|
-
}
|
|
41
|
-
beforeStart({ app: e }) {
|
|
42
|
-
this.indexHtml && e.use((t, n, i) => {
|
|
43
|
-
for (const r of this.apiPrefixes) if (t.path.startsWith(r)) return i();
|
|
44
|
-
for (const r of this.excludePaths) if (t.path.startsWith(r)) return i();
|
|
45
|
-
if (t.path.includes(".") || t.method !== "GET") return i();
|
|
46
|
-
n.setHeader("Content-Type", "text/html"), n.setHeader("Cache-Control", this.indexCacheControl), n.send(this.indexHtml);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
export {
|
|
51
|
-
P as SpaAdapter
|
|
52
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/upload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC9E,OAAe,EAAE,KAAK,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAyDrE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAK1D;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,sDAAsD;IACtD,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;IAClC,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAoDD;;;;;;;;;;;GAWG;AACH,iBAAS,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,cAAc,CAG9E;AAED;;GAEG;AACH,iBAAS,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,SAAK,EAAE,OAAO,GAAE,aAAkB,GAAG,cAAc,CAG5F;AAED;;GAEG;AACH,iBAAS,IAAI,CAAC,OAAO,GAAE,aAAkB,GAAG,cAAc,CAGzD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,KAClB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,UAwBxD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAgB9E;AAED,gFAAgF;AAChF,eAAO,MAAM,MAAM;;;;CAA0B,CAAA"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { unlink as u } from "node:fs/promises";
|
|
2
|
-
import v from "multer";
|
|
3
|
-
var m = {
|
|
4
|
-
jpg: "image/jpeg",
|
|
5
|
-
jpeg: "image/jpeg",
|
|
6
|
-
png: "image/png",
|
|
7
|
-
gif: "image/gif",
|
|
8
|
-
webp: "image/webp",
|
|
9
|
-
svg: "image/svg+xml",
|
|
10
|
-
bmp: "image/bmp",
|
|
11
|
-
ico: "image/x-icon",
|
|
12
|
-
tiff: "image/tiff",
|
|
13
|
-
tif: "image/tiff",
|
|
14
|
-
avif: "image/avif",
|
|
15
|
-
pdf: "application/pdf",
|
|
16
|
-
doc: "application/msword",
|
|
17
|
-
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
18
|
-
xls: "application/vnd.ms-excel",
|
|
19
|
-
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
20
|
-
ppt: "application/vnd.ms-powerpoint",
|
|
21
|
-
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
22
|
-
odt: "application/vnd.oasis.opendocument.text",
|
|
23
|
-
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
|
24
|
-
odp: "application/vnd.oasis.opendocument.presentation",
|
|
25
|
-
rtf: "application/rtf",
|
|
26
|
-
txt: "text/plain",
|
|
27
|
-
csv: "text/csv",
|
|
28
|
-
zip: "application/zip",
|
|
29
|
-
gz: "application/gzip",
|
|
30
|
-
tar: "application/x-tar",
|
|
31
|
-
rar: "application/vnd.rar",
|
|
32
|
-
"7z": "application/x-7z-compressed",
|
|
33
|
-
mp3: "audio/mpeg",
|
|
34
|
-
wav: "audio/wav",
|
|
35
|
-
ogg: "audio/ogg",
|
|
36
|
-
flac: "audio/flac",
|
|
37
|
-
aac: "audio/aac",
|
|
38
|
-
mp4: "video/mp4",
|
|
39
|
-
webm: "video/webm",
|
|
40
|
-
avi: "video/x-msvideo",
|
|
41
|
-
mov: "video/quicktime",
|
|
42
|
-
mkv: "video/x-matroska",
|
|
43
|
-
json: "application/json",
|
|
44
|
-
xml: "application/xml",
|
|
45
|
-
html: "text/html"
|
|
46
|
-
};
|
|
47
|
-
function w(e) {
|
|
48
|
-
return e.map((a) => m[a.toLowerCase().replace(/^\./, "")] ?? a);
|
|
49
|
-
}
|
|
50
|
-
function s(e) {
|
|
51
|
-
const a = e.customMimeMap ? {
|
|
52
|
-
...m,
|
|
53
|
-
...e.customMimeMap
|
|
54
|
-
} : m, i = { fileSize: e.maxSize ?? 5 * 1024 * 1024 };
|
|
55
|
-
let t;
|
|
56
|
-
if (typeof e.allowedTypes == "function") {
|
|
57
|
-
const o = e.allowedTypes;
|
|
58
|
-
t = (r, p, n) => {
|
|
59
|
-
o(p.mimetype, p.originalname) ? n(null, !0) : n(/* @__PURE__ */ new Error(`File type ${p.mimetype} is not allowed`));
|
|
60
|
-
};
|
|
61
|
-
} else if (Array.isArray(e.allowedTypes)) {
|
|
62
|
-
const o = e.allowedTypes.map((r) => a[r.toLowerCase().replace(/^\./, "")] ?? r);
|
|
63
|
-
t = (r, p, n) => {
|
|
64
|
-
o.some((l) => l.endsWith("/*") ? p.mimetype.startsWith(l.replace("/*", "/")) : p.mimetype === l) ? n(null, !0) : n(/* @__PURE__ */ new Error(`File type ${p.mimetype} is not allowed`));
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return v({
|
|
68
|
-
limits: i,
|
|
69
|
-
...t ? { fileFilter: t } : {},
|
|
70
|
-
...e.storage ? { storage: e.storage } : {},
|
|
71
|
-
...e.dest ? { dest: e.dest } : {}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function c(e, a = {}) {
|
|
75
|
-
return s(a).single(e);
|
|
76
|
-
}
|
|
77
|
-
function d(e, a = 10, i = {}) {
|
|
78
|
-
return s(i).array(e, a);
|
|
79
|
-
}
|
|
80
|
-
function f(e = {}) {
|
|
81
|
-
return s(e).none();
|
|
82
|
-
}
|
|
83
|
-
function y() {
|
|
84
|
-
return (e, a, i) => {
|
|
85
|
-
a.on("finish", async () => {
|
|
86
|
-
const t = [];
|
|
87
|
-
if (e.file?.path && t.push(e.file), Array.isArray(e.files))
|
|
88
|
-
for (const o of e.files) o?.path && t.push(o);
|
|
89
|
-
for (const o of t) try {
|
|
90
|
-
await u(o.path);
|
|
91
|
-
} catch {
|
|
92
|
-
}
|
|
93
|
-
}), i();
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function M(e) {
|
|
97
|
-
const a = {};
|
|
98
|
-
e.maxSize && (a.maxSize = e.maxSize), e.allowedTypes && (a.allowedTypes = e.allowedTypes), e.customMimeMap && (a.customMimeMap = e.customMimeMap);
|
|
99
|
-
const i = e.fieldName ?? "file";
|
|
100
|
-
switch (e.mode) {
|
|
101
|
-
case "single":
|
|
102
|
-
return c(i, a);
|
|
103
|
-
case "array":
|
|
104
|
-
return d(i, e.maxCount ?? 10, a);
|
|
105
|
-
case "none":
|
|
106
|
-
return f(a);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
var h = {
|
|
110
|
-
single: c,
|
|
111
|
-
array: d,
|
|
112
|
-
none: f
|
|
113
|
-
};
|
|
114
|
-
export {
|
|
115
|
-
M as buildUploadMiddleware,
|
|
116
|
-
y as cleanupFiles,
|
|
117
|
-
w as resolveMimeTypes,
|
|
118
|
-
h as upload
|
|
119
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Request, Response, NextFunction } from 'express';
|
|
2
|
-
export interface ValidationSchema {
|
|
3
|
-
body?: any;
|
|
4
|
-
query?: any;
|
|
5
|
-
params?: any;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Express middleware that validates request body/query/params against schemas.
|
|
9
|
-
* Works with any validation library that exposes `.safeParse(data)` returning
|
|
10
|
-
* `{ success: true, data }` or `{ success: false, error: { issues } }`.
|
|
11
|
-
*/
|
|
12
|
-
export declare function validate(schema: ValidationSchema): (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
|
|
13
|
-
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,MAAM,CAAC,EAAE,GAAG,CAAA;CACb;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,IACvC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,oDAiDxD"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
function u(a) {
|
|
2
|
-
return (r, t, o) => {
|
|
3
|
-
try {
|
|
4
|
-
if (a.body) {
|
|
5
|
-
const s = a.body.safeParse(r.body);
|
|
6
|
-
if (!s.success) return t.status(422).json({
|
|
7
|
-
message: s.error.issues[0]?.message || "Validation failed",
|
|
8
|
-
errors: s.error.issues.map((e) => ({
|
|
9
|
-
field: e.path.join("."),
|
|
10
|
-
message: e.message
|
|
11
|
-
}))
|
|
12
|
-
});
|
|
13
|
-
r.body = s.data;
|
|
14
|
-
}
|
|
15
|
-
if (a.query) {
|
|
16
|
-
const s = a.query.safeParse(r.query);
|
|
17
|
-
if (!s.success) return t.status(422).json({
|
|
18
|
-
message: "Invalid query parameters",
|
|
19
|
-
errors: s.error.issues.map((e) => ({
|
|
20
|
-
field: e.path.join("."),
|
|
21
|
-
message: e.message
|
|
22
|
-
}))
|
|
23
|
-
});
|
|
24
|
-
r.query = s.data;
|
|
25
|
-
}
|
|
26
|
-
if (a.params) {
|
|
27
|
-
const s = a.params.safeParse(r.params);
|
|
28
|
-
if (!s.success) return t.status(422).json({
|
|
29
|
-
message: "Invalid path parameters",
|
|
30
|
-
errors: s.error.issues.map((e) => ({
|
|
31
|
-
field: e.path.join("."),
|
|
32
|
-
message: e.message
|
|
33
|
-
}))
|
|
34
|
-
});
|
|
35
|
-
r.params = s.data;
|
|
36
|
-
}
|
|
37
|
-
o();
|
|
38
|
-
} catch (s) {
|
|
39
|
-
o(s);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
u as validate
|
|
45
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { type AppAdapter, type AdapterContext } from '../../core';
|
|
2
|
-
export interface ViewAdapterOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Template engine — pass the engine module or a render function.
|
|
5
|
-
* Supported engines: ejs, pug, handlebars, nunjucks, or any
|
|
6
|
-
* Express-compatible engine with a __express property.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import ejs from 'ejs'
|
|
11
|
-
* new ViewAdapter({ engine: ejs, ext: 'ejs' })
|
|
12
|
-
*
|
|
13
|
-
* import pug from 'pug'
|
|
14
|
-
* new ViewAdapter({ engine: pug, ext: 'pug' })
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
engine: any;
|
|
18
|
-
/** File extension for templates (e.g., 'ejs', 'pug', 'hbs') */
|
|
19
|
-
ext: string;
|
|
20
|
-
/** Directory containing template files (default: 'src/views') */
|
|
21
|
-
viewsDir?: string;
|
|
22
|
-
/** Default layout template (optional — depends on engine) */
|
|
23
|
-
layout?: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* View/template adapter — pluggable template engine support for KickJS.
|
|
27
|
-
*
|
|
28
|
-
* Registers an Express view engine and sets the views directory.
|
|
29
|
-
* Use `ctx.render()` in controllers to render templates.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* import ejs from 'ejs'
|
|
34
|
-
* import { ViewAdapter } from '@forinda/kickjs-http/views'
|
|
35
|
-
*
|
|
36
|
-
* bootstrap({
|
|
37
|
-
* modules,
|
|
38
|
-
* adapters: [
|
|
39
|
-
* new ViewAdapter({ engine: ejs, ext: 'ejs', viewsDir: 'src/views' }),
|
|
40
|
-
* ],
|
|
41
|
-
* })
|
|
42
|
-
*
|
|
43
|
-
* // In a controller:
|
|
44
|
-
* @Get('/dashboard')
|
|
45
|
-
* async dashboard(ctx: RequestContext) {
|
|
46
|
-
* ctx.render('dashboard', { user: currentUser, title: 'Dashboard' })
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare class ViewAdapter implements AppAdapter {
|
|
51
|
-
private options;
|
|
52
|
-
name: string;
|
|
53
|
-
constructor(options: ViewAdapterOptions);
|
|
54
|
-
beforeMount({ app }: AdapterContext): void;
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=views.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../../src/http/middleware/views.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAIzE,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;;;;;OAaG;IACH,MAAM,EAAE,GAAG,CAAA;IAEX,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAA;IAEX,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,WAAY,YAAW,UAAU;IAGhC,OAAO,CAAC,OAAO;IAF3B,IAAI,SAAgB;gBAEA,OAAO,EAAE,kBAAkB;IAE/C,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,GAAG,IAAI;CAyB3C"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Logger as l } from "../../core/logger.js";
|
|
2
|
-
import "../../core-B6Okew3W.js";
|
|
3
|
-
import { resolve as o } from "node:path";
|
|
4
|
-
var s = l.for("ViewEngine"), d = class {
|
|
5
|
-
name = "ViewAdapter";
|
|
6
|
-
constructor(e) {
|
|
7
|
-
this.options = e;
|
|
8
|
-
}
|
|
9
|
-
beforeMount({ app: e }) {
|
|
10
|
-
const { engine: i, ext: n, viewsDir: r = "src/views" } = this.options;
|
|
11
|
-
i.__express ? e.engine(n, i.__express) : typeof i.renderFile == "function" ? e.engine(n, (t, f, g) => {
|
|
12
|
-
i.renderFile(t, f, g);
|
|
13
|
-
}) : (typeof i == "function" || s.warn(`Engine for .${n} does not have __express or renderFile. Trying as-is.`), e.engine(n, i)), e.set("view engine", n), e.set("views", o(r)), s.info(`View engine: ${n} (${o(r)})`);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
export {
|
|
17
|
-
d as ViewAdapter
|
|
18
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { parseQuery, parseFilters, parseSort, parsePagination, parseSearchQuery, buildQueryParams, } from './parse-query';
|
|
2
|
-
export type { FilterOperator, FilterItem, SortItem, PaginationParams, ParsedQuery, QueryFieldConfig, StringQueryFieldConfig, ColumnQueryFieldConfig, QueryBuilderAdapter, PaginatedResponse, } from './types';
|
|
3
|
-
export { FILTER_OPERATORS } from './types';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,eAAe,CAAA;AAEtB,YAAY,EACV,cAAc,EACd,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/http/query/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { a as r, i as s, n as e, o as p, r as i, s as o, t } from "../../query-Bym31XRp.js";
|
|
2
|
-
export {
|
|
3
|
-
o as FILTER_OPERATORS,
|
|
4
|
-
t as buildQueryParams,
|
|
5
|
-
e as parseFilters,
|
|
6
|
-
i as parsePagination,
|
|
7
|
-
s as parseQuery,
|
|
8
|
-
r as parseSearchQuery,
|
|
9
|
-
p as parseSort
|
|
10
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type FilterItem, type SortItem, type PaginationParams, type ParsedQuery, type QueryFieldConfig } from './types';
|
|
2
|
-
/** Parse filter strings like "status:eq:active" into structured objects */
|
|
3
|
-
export declare function parseFilters(filterParam: string | string[] | undefined, allowedFields?: string[]): FilterItem[];
|
|
4
|
-
/** Parse sort strings like "firstName:asc" into structured objects */
|
|
5
|
-
export declare function parseSort(sortParam: string | string[] | undefined, allowedFields?: string[]): SortItem[];
|
|
6
|
-
/** Parse page/limit into pagination with computed offset */
|
|
7
|
-
export declare function parsePagination(params: {
|
|
8
|
-
page?: string | number;
|
|
9
|
-
limit?: string | number;
|
|
10
|
-
}): PaginationParams;
|
|
11
|
-
/** Sanitize and truncate search query */
|
|
12
|
-
export declare function parseSearchQuery(q: string | undefined): string;
|
|
13
|
-
/**
|
|
14
|
-
* Parse a raw Express query object into a structured, ORM-agnostic ParsedQuery.
|
|
15
|
-
*
|
|
16
|
-
* @param query - Raw query string object from `req.query` or Zod-validated object
|
|
17
|
-
* @param fieldConfig - Optional field restrictions (whitelist filterable/sortable/searchable).
|
|
18
|
-
* Accepts both string-based configs (`{ filterable, sortable, searchable }`) and
|
|
19
|
-
* column-object configs (`{ columns, sortable, searchColumns }`).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // String-based config
|
|
24
|
-
* const parsed = parseQuery(ctx.query, {
|
|
25
|
-
* filterable: ['status', 'priority'],
|
|
26
|
-
* sortable: ['createdAt', 'title'],
|
|
27
|
-
* })
|
|
28
|
-
*
|
|
29
|
-
* // Column-object config (DrizzleQueryParamsConfig)
|
|
30
|
-
* const parsed = parseQuery(ctx.query, TASK_QUERY_CONFIG)
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* Query string format:
|
|
34
|
-
* - Filters: `?filter=field:operator:value` (repeatable)
|
|
35
|
-
* - Sort: `?sort=field:asc|desc` (repeatable)
|
|
36
|
-
* - Pagination: `?page=1&limit=20`
|
|
37
|
-
* - Search: `?q=search+term`
|
|
38
|
-
*
|
|
39
|
-
* Filter operators: eq, neq, gt, gte, lt, lte, between, in, contains, starts, ends
|
|
40
|
-
*/
|
|
41
|
-
export declare function parseQuery(query: Record<string, any>, fieldConfig?: QueryFieldConfig): ParsedQuery;
|
|
42
|
-
/** Convert ParsedQuery back into query string parameters */
|
|
43
|
-
export declare function buildQueryParams(parsed: Partial<ParsedQuery>): Record<string, string | string[] | number>;
|
|
44
|
-
//# sourceMappingURL=parse-query.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-query.d.ts","sourceRoot":"","sources":["../../../src/http/query/parse-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAEf,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAEtB,MAAM,SAAS,CAAA;AAShB,2EAA2E;AAC3E,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EAC1C,aAAa,CAAC,EAAE,MAAM,EAAE,GACvB,UAAU,EAAE,CA2Bd;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CACvB,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACxC,aAAa,CAAC,EAAE,MAAM,EAAE,GACvB,QAAQ,EAAE,CAuBZ;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACxB,GAAG,gBAAgB,CAWnB;AAED,yCAAyC;AACzC,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAG9D;AA2BD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,WAAW,CAAC,EAAE,gBAAgB,GAC7B,WAAW,CAQb;AAID,4DAA4D;AAC5D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,CAqB5C"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/** Supported filter operators for query string parsing */
|
|
2
|
-
export type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'in' | 'contains' | 'starts' | 'ends';
|
|
3
|
-
export declare const FILTER_OPERATORS: Set<string>;
|
|
4
|
-
export interface FilterItem {
|
|
5
|
-
field: string;
|
|
6
|
-
operator: FilterOperator;
|
|
7
|
-
value: string;
|
|
8
|
-
}
|
|
9
|
-
export interface SortItem {
|
|
10
|
-
field: string;
|
|
11
|
-
direction: 'asc' | 'desc';
|
|
12
|
-
}
|
|
13
|
-
export interface PaginationParams {
|
|
14
|
-
page: number;
|
|
15
|
-
limit: number;
|
|
16
|
-
offset: number;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The result of parsing a query string. ORM-agnostic — pass this to
|
|
20
|
-
* a query builder adapter (Drizzle, Prisma, Sequelize, etc.) to produce
|
|
21
|
-
* database-specific query objects.
|
|
22
|
-
*/
|
|
23
|
-
export interface ParsedQuery {
|
|
24
|
-
filters: FilterItem[];
|
|
25
|
-
sort: SortItem[];
|
|
26
|
-
pagination: PaginationParams;
|
|
27
|
-
search: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Restrict which fields can be filtered, sorted, or searched.
|
|
31
|
-
* Fields not in the allow-list are silently ignored.
|
|
32
|
-
*
|
|
33
|
-
* Accepts two forms:
|
|
34
|
-
* 1. **String arrays** (standard): `{ filterable: ['name', 'status'], sortable: ['createdAt'] }`
|
|
35
|
-
* 2. **Column-object maps** (Drizzle-style): `{ columns: { name: col, status: col }, sortable: { createdAt: col } }`
|
|
36
|
-
*
|
|
37
|
-
* When column-object maps are provided, `Object.keys()` is used to derive the field names.
|
|
38
|
-
*/
|
|
39
|
-
export type QueryFieldConfig = StringQueryFieldConfig | ColumnQueryFieldConfig;
|
|
40
|
-
export interface StringQueryFieldConfig {
|
|
41
|
-
filterable?: string[];
|
|
42
|
-
sortable?: string[];
|
|
43
|
-
searchable?: string[];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Column-object-based field config (e.g., from DrizzleQueryParamsConfig).
|
|
47
|
-
* Keys are the field names used in query strings; values are ORM column references.
|
|
48
|
-
*/
|
|
49
|
-
export interface ColumnQueryFieldConfig {
|
|
50
|
-
columns: Record<string, any>;
|
|
51
|
-
sortable?: Record<string, any>;
|
|
52
|
-
searchColumns?: any[];
|
|
53
|
-
[key: string]: any;
|
|
54
|
-
}
|
|
55
|
-
/** Standardized paginated response shape */
|
|
56
|
-
export interface PaginatedResponse<T = any> {
|
|
57
|
-
data: T[];
|
|
58
|
-
meta: {
|
|
59
|
-
page: number;
|
|
60
|
-
limit: number;
|
|
61
|
-
total: number;
|
|
62
|
-
totalPages: number;
|
|
63
|
-
hasNext: boolean;
|
|
64
|
-
hasPrev: boolean;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Interface for ORM-specific query builder adapters.
|
|
69
|
-
* Implement this to translate a `ParsedQuery` into your ORM's query format.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* // Drizzle adapter
|
|
74
|
-
* class DrizzleQueryAdapter implements QueryBuilderAdapter<DrizzleQueryResult> {
|
|
75
|
-
* build(parsed: ParsedQuery, config: DrizzleConfig): DrizzleQueryResult {
|
|
76
|
-
* // Convert filters → Drizzle SQL conditions
|
|
77
|
-
* // Convert sort → Drizzle orderBy
|
|
78
|
-
* return { where, orderBy, limit, offset }
|
|
79
|
-
* }
|
|
80
|
-
* }
|
|
81
|
-
*
|
|
82
|
-
* // Prisma adapter
|
|
83
|
-
* class PrismaQueryAdapter implements QueryBuilderAdapter<PrismaQueryResult> {
|
|
84
|
-
* build(parsed: ParsedQuery, config: PrismaConfig): PrismaQueryResult {
|
|
85
|
-
* return { where, orderBy, skip, take }
|
|
86
|
-
* }
|
|
87
|
-
* }
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export interface QueryBuilderAdapter<TResult = any, TConfig = any> {
|
|
91
|
-
/** Human-readable name for debugging */
|
|
92
|
-
readonly name: string;
|
|
93
|
-
/**
|
|
94
|
-
* Convert a ParsedQuery into an ORM-specific query object.
|
|
95
|
-
* @param parsed - The ORM-agnostic parsed query
|
|
96
|
-
* @param config - ORM-specific configuration (column maps, search columns, etc.)
|
|
97
|
-
*/
|
|
98
|
-
build(parsed: ParsedQuery, config: TConfig): TResult;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/http/query/types.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,MAAM,cAAc,GACtB,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,SAAS,GACT,IAAI,GACJ,UAAU,GACV,QAAQ,GACR,MAAM,CAAA;AAEV,eAAO,MAAM,gBAAgB,aAY3B,CAAA;AAEF,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,cAAc,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,KAAK,GAAG,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,UAAU,EAAE,CAAA;IACrB,IAAI,EAAE,QAAQ,EAAE,CAAA;IAChB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,sBAAsB,CAAA;AAE9E,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,aAAa,CAAC,EAAE,GAAG,EAAE,CAAA;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,4CAA4C;AAC5C,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,GAAG;IACxC,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;QACb,KAAK,EAAE,MAAM,CAAA;QACb,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,OAAO,CAAA;QAChB,OAAO,EAAE,OAAO,CAAA;KACjB,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,mBAAmB,CAAC,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG;IAC/D,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAA;CACrD"}
|