@m1kapp/kit 0.0.1 → 0.0.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/dist/server.d.mts CHANGED
@@ -22,29 +22,48 @@ declare function conflict(message?: string): never;
22
22
  /** 500 Internal Server Error — throw inside handler() */
23
23
  declare function serverError(message?: string): never;
24
24
 
25
- type NextRequest = Request;
26
- type RouteContext = {
27
- params?: Record<string, string | string[]>;
28
- };
25
+ /**
26
+ * Route context — `any` so the wrapper compiles against all Next.js versions:
27
+ * - Next.js 14: `{ params: Record<string, string | string[]> }`
28
+ * - Next.js 15/16: `{ params: Promise<Record<string, string | string[]>> }`
29
+ *
30
+ * Callers narrow the type themselves inside their handler function.
31
+ */
32
+ type RouteContext = any;
29
33
  /**
30
34
  * Wraps a Next.js route handler with automatic error handling.
35
+ * Compatible with Next.js 14, 15, and 16.
31
36
  *
32
37
  * - HttpError (thrown by unauthorized/notFound/etc.) → proper HTTP response
33
38
  * - Any other thrown error → 500
34
39
  * - No try/catch needed in your route
35
40
  *
36
41
  * @example
42
+ * // No params
37
43
  * export const GET = handler(async (req) => {
38
- * const user = await currentUser();
39
- * if (!user) unauthorized(); // throws → 401
44
+ * if (!auth) unauthorized();
45
+ * return ok(await db.findAll());
46
+ * });
40
47
  *
41
- * const site = await db.sites.find(id);
42
- * if (!site) notFound("사이트 없음"); // throws → 404
48
+ * // Next.js 15/16 — async params
49
+ * export const GET = handler(async (_req, ctx) => {
50
+ * const { id } = await ctx.params;
51
+ * return ok(await db.find(id));
52
+ * });
43
53
  *
44
- * return ok(site);
54
+ * // Next.js 14 — sync params
55
+ * export const GET = handler(async (_req, ctx) => {
56
+ * const { id } = ctx.params;
57
+ * return ok(await db.find(id));
45
58
  * });
46
59
  */
47
- declare function handler(fn: (req: NextRequest, ctx?: RouteContext) => Promise<Response>): (req: NextRequest, ctx?: RouteContext) => Promise<Response>;
60
+ declare function handler(fn: (req: Request) => Promise<Response>): (req: Request, ctx?: RouteContext) => Promise<Response>;
61
+ declare function handler<P extends Record<string, string | string[]>>(fn: (req: Request, ctx: {
62
+ params: Promise<P>;
63
+ }) => Promise<Response>): (req: Request, ctx?: RouteContext) => Promise<Response>;
64
+ declare function handler<P extends Record<string, string | string[]>>(fn: (req: Request, ctx: {
65
+ params: P;
66
+ }) => Promise<Response>): (req: Request, ctx?: RouteContext) => Promise<Response>;
48
67
 
49
68
  type SafeOk<T> = {
50
69
  ok: true;
package/dist/server.d.ts CHANGED
@@ -22,29 +22,48 @@ declare function conflict(message?: string): never;
22
22
  /** 500 Internal Server Error — throw inside handler() */
23
23
  declare function serverError(message?: string): never;
24
24
 
25
- type NextRequest = Request;
26
- type RouteContext = {
27
- params?: Record<string, string | string[]>;
28
- };
25
+ /**
26
+ * Route context — `any` so the wrapper compiles against all Next.js versions:
27
+ * - Next.js 14: `{ params: Record<string, string | string[]> }`
28
+ * - Next.js 15/16: `{ params: Promise<Record<string, string | string[]>> }`
29
+ *
30
+ * Callers narrow the type themselves inside their handler function.
31
+ */
32
+ type RouteContext = any;
29
33
  /**
30
34
  * Wraps a Next.js route handler with automatic error handling.
35
+ * Compatible with Next.js 14, 15, and 16.
31
36
  *
32
37
  * - HttpError (thrown by unauthorized/notFound/etc.) → proper HTTP response
33
38
  * - Any other thrown error → 500
34
39
  * - No try/catch needed in your route
35
40
  *
36
41
  * @example
42
+ * // No params
37
43
  * export const GET = handler(async (req) => {
38
- * const user = await currentUser();
39
- * if (!user) unauthorized(); // throws → 401
44
+ * if (!auth) unauthorized();
45
+ * return ok(await db.findAll());
46
+ * });
40
47
  *
41
- * const site = await db.sites.find(id);
42
- * if (!site) notFound("사이트 없음"); // throws → 404
48
+ * // Next.js 15/16 — async params
49
+ * export const GET = handler(async (_req, ctx) => {
50
+ * const { id } = await ctx.params;
51
+ * return ok(await db.find(id));
52
+ * });
43
53
  *
44
- * return ok(site);
54
+ * // Next.js 14 — sync params
55
+ * export const GET = handler(async (_req, ctx) => {
56
+ * const { id } = ctx.params;
57
+ * return ok(await db.find(id));
45
58
  * });
46
59
  */
47
- declare function handler(fn: (req: NextRequest, ctx?: RouteContext) => Promise<Response>): (req: NextRequest, ctx?: RouteContext) => Promise<Response>;
60
+ declare function handler(fn: (req: Request) => Promise<Response>): (req: Request, ctx?: RouteContext) => Promise<Response>;
61
+ declare function handler<P extends Record<string, string | string[]>>(fn: (req: Request, ctx: {
62
+ params: Promise<P>;
63
+ }) => Promise<Response>): (req: Request, ctx?: RouteContext) => Promise<Response>;
64
+ declare function handler<P extends Record<string, string | string[]>>(fn: (req: Request, ctx: {
65
+ params: P;
66
+ }) => Promise<Response>): (req: Request, ctx?: RouteContext) => Promise<Response>;
48
67
 
49
68
  type SafeOk<T> = {
50
69
  ok: true;
package/dist/server.js CHANGED
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var E=(e,r)=>{for(var o in r)u(e,o,{get:r[o],enumerable:!0})},b=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of T(r))!m.call(e,s)&&s!==o&&u(e,s,{get:()=>r[s],enumerable:!(n=y(r,s))||n.enumerable});return e};var k=e=>b(u({},"__esModule",{value:!0}),e);var v={};E(v,{HttpError:()=>t,badRequest:()=>c,conflict:()=>x,created:()=>i,forbidden:()=>f,handler:()=>w,noContent:()=>p,notFound:()=>l,ok:()=>a,safely:()=>h,serverError:()=>R,unauthorized:()=>d});module.exports=k(v);var t=class extends Error{constructor(o,n){super(`HTTP ${o}`);this.status=o;this.body=n;this.name="HttpError"}};function a(e,r=200){return Response.json(e,{status:r})}function i(e){return Response.json(e,{status:201})}function p(){return new Response(null,{status:204})}function c(e="Bad Request",r){throw new t(400,{error:e,...r?{errors:r}:{}})}function d(e="Unauthorized"){throw new t(401,{error:e})}function f(e="Forbidden"){throw new t(403,{error:e})}function l(e="Not Found"){throw new t(404,{error:e})}function x(e="Conflict"){throw new t(409,{error:e})}function R(e="Internal Server Error"){throw new t(500,{error:e})}function w(e){return async(r,o)=>{try{return await e(r,o)}catch(n){return n instanceof t?Response.json(n.body,{status:n.status}):(console.error("[handler] Unhandled error:",n),Response.json({error:"Internal Server Error"},{status:500}))}}}async function h(e){try{return{ok:!0,data:await e(),error:null}}catch(r){return{ok:!1,data:null,error:r instanceof Error?r:new Error(String(r))}}}0&&(module.exports={HttpError,badRequest,conflict,created,forbidden,handler,noContent,notFound,ok,safely,serverError,unauthorized});
1
+ "use strict";var u=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var y=(e,r)=>{for(var o in r)u(e,o,{get:r[o],enumerable:!0})},T=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of w(r))!P.call(e,s)&&s!==o&&u(e,s,{get:()=>r[s],enumerable:!(n=q(r,s))||n.enumerable});return e};var E=e=>T(u({},"__esModule",{value:!0}),e);var b={};y(b,{HttpError:()=>t,badRequest:()=>c,conflict:()=>x,created:()=>i,forbidden:()=>f,handler:()=>m,noContent:()=>p,notFound:()=>R,ok:()=>a,safely:()=>h,serverError:()=>l,unauthorized:()=>d});module.exports=E(b);var t=class extends Error{constructor(o,n){super(`HTTP ${o}`);this.status=o;this.body=n;this.name="HttpError"}};function a(e,r=200){return Response.json(e,{status:r})}function i(e){return Response.json(e,{status:201})}function p(){return new Response(null,{status:204})}function c(e="Bad Request",r){throw new t(400,{error:e,...r?{errors:r}:{}})}function d(e="Unauthorized"){throw new t(401,{error:e})}function f(e="Forbidden"){throw new t(403,{error:e})}function R(e="Not Found"){throw new t(404,{error:e})}function x(e="Conflict"){throw new t(409,{error:e})}function l(e="Internal Server Error"){throw new t(500,{error:e})}function m(e){return async(r,o)=>{try{return await e(r,o)}catch(n){return n instanceof t?Response.json(n.body,{status:n.status}):(console.error("[handler] Unhandled error:",n),Response.json({error:"Internal Server Error"},{status:500}))}}}async function h(e){try{return{ok:!0,data:await e(),error:null}}catch(r){return{ok:!1,data:null,error:r instanceof Error?r:new Error(String(r))}}}0&&(module.exports={HttpError,badRequest,conflict,created,forbidden,handler,noContent,notFound,ok,safely,serverError,unauthorized});
package/dist/server.mjs CHANGED
@@ -1 +1 @@
1
- var t=class extends Error{constructor(n,o){super(`HTTP ${n}`);this.status=n;this.body=o;this.name="HttpError"}};function s(e,r=200){return Response.json(e,{status:r})}function u(e){return Response.json(e,{status:201})}function a(){return new Response(null,{status:204})}function i(e="Bad Request",r){throw new t(400,{error:e,...r?{errors:r}:{}})}function p(e="Unauthorized"){throw new t(401,{error:e})}function c(e="Forbidden"){throw new t(403,{error:e})}function d(e="Not Found"){throw new t(404,{error:e})}function f(e="Conflict"){throw new t(409,{error:e})}function l(e="Internal Server Error"){throw new t(500,{error:e})}function x(e){return async(r,n)=>{try{return await e(r,n)}catch(o){return o instanceof t?Response.json(o.body,{status:o.status}):(console.error("[handler] Unhandled error:",o),Response.json({error:"Internal Server Error"},{status:500}))}}}async function R(e){try{return{ok:!0,data:await e(),error:null}}catch(r){return{ok:!1,data:null,error:r instanceof Error?r:new Error(String(r))}}}export{t as HttpError,i as badRequest,f as conflict,u as created,c as forbidden,x as handler,a as noContent,d as notFound,s as ok,R as safely,l as serverError,p as unauthorized};
1
+ var t=class extends Error{constructor(n,o){super(`HTTP ${n}`);this.status=n;this.body=o;this.name="HttpError"}};function s(e,r=200){return Response.json(e,{status:r})}function u(e){return Response.json(e,{status:201})}function a(){return new Response(null,{status:204})}function i(e="Bad Request",r){throw new t(400,{error:e,...r?{errors:r}:{}})}function p(e="Unauthorized"){throw new t(401,{error:e})}function c(e="Forbidden"){throw new t(403,{error:e})}function d(e="Not Found"){throw new t(404,{error:e})}function f(e="Conflict"){throw new t(409,{error:e})}function R(e="Internal Server Error"){throw new t(500,{error:e})}function x(e){return async(r,n)=>{try{return await e(r,n)}catch(o){return o instanceof t?Response.json(o.body,{status:o.status}):(console.error("[handler] Unhandled error:",o),Response.json({error:"Internal Server Error"},{status:500}))}}}async function l(e){try{return{ok:!0,data:await e(),error:null}}catch(r){return{ok:!1,data:null,error:r instanceof Error?r:new Error(String(r))}}}export{t as HttpError,i as badRequest,f as conflict,u as created,c as forbidden,x as handler,a as noContent,d as notFound,s as ok,l as safely,R as serverError,p as unauthorized};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m1kapp/kit",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "UI, SEO, and PWA utilities for side projects",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",