@nara-web/core 0.1.0 → 0.1.1

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.
Files changed (47) hide show
  1. package/dist/App.d.ts +11 -29
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/App.js +24 -237
  4. package/dist/App.js.map +1 -1
  5. package/dist/BaseController.d.ts +5 -26
  6. package/dist/BaseController.d.ts.map +1 -1
  7. package/dist/BaseController.js +6 -56
  8. package/dist/BaseController.js.map +1 -1
  9. package/dist/adapters.d.ts +7 -0
  10. package/dist/adapters.d.ts.map +1 -0
  11. package/dist/{adapters/types.js → adapters.js} +1 -1
  12. package/dist/adapters.js.map +1 -0
  13. package/dist/errors.d.ts +7 -23
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/errors.js +21 -73
  16. package/dist/errors.js.map +1 -1
  17. package/dist/index.d.ts +7 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +20 -16
  20. package/dist/index.js.map +1 -1
  21. package/dist/response.d.ts +6 -27
  22. package/dist/response.d.ts.map +1 -1
  23. package/dist/response.js +11 -54
  24. package/dist/response.js.map +1 -1
  25. package/dist/types.d.ts +9 -20
  26. package/dist/types.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/App.ts +67 -0
  29. package/src/BaseController.ts +15 -0
  30. package/src/adapters.ts +7 -0
  31. package/src/errors.ts +41 -0
  32. package/src/index.ts +38 -2
  33. package/src/response.ts +25 -0
  34. package/src/types.ts +9 -55
  35. package/tsconfig.tsbuildinfo +1 -1
  36. package/dist/Router.d.ts +0 -32
  37. package/dist/Router.d.ts.map +0 -1
  38. package/dist/Router.js +0 -100
  39. package/dist/Router.js.map +0 -1
  40. package/dist/adapters/svelte.d.ts +0 -3
  41. package/dist/adapters/svelte.d.ts.map +0 -1
  42. package/dist/adapters/svelte.js +0 -18
  43. package/dist/adapters/svelte.js.map +0 -1
  44. package/dist/adapters/types.d.ts +0 -9
  45. package/dist/adapters/types.d.ts.map +0 -1
  46. package/dist/adapters/types.js.map +0 -1
  47. package/src/adapters/types.ts +0 -31
package/dist/errors.js CHANGED
@@ -1,100 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternalError = exports.TooManyRequestsError = exports.ConflictError = exports.BadRequestError = exports.ForbiddenError = exports.NotFoundError = exports.AuthError = exports.ValidationError = exports.HttpError = void 0;
4
- exports.isHttpError = isHttpError;
5
- exports.isValidationError = isValidationError;
3
+ exports.ValidationError = exports.BadRequestError = exports.ForbiddenError = exports.UnauthorizedError = exports.NotFoundError = exports.HttpError = void 0;
6
4
  class HttpError extends Error {
7
- constructor(message, statusCode = 500, code = 'HTTP_ERROR') {
5
+ constructor(statusCode, message) {
8
6
  super(message);
9
- this.name = 'HttpError';
10
7
  this.statusCode = statusCode;
11
- this.code = code;
12
- Error.captureStackTrace(this, this.constructor);
13
- }
14
- toJSON() {
15
- return {
16
- name: this.name,
17
- message: this.message,
18
- statusCode: this.statusCode,
19
- code: this.code,
20
- };
8
+ this.name = 'HttpError';
21
9
  }
22
10
  }
23
11
  exports.HttpError = HttpError;
24
- class ValidationError extends HttpError {
25
- constructor(message = 'Validation failed', errors = {}) {
26
- super(message, 422, 'VALIDATION_ERROR');
27
- this.name = 'ValidationError';
28
- this.errors = errors;
29
- }
30
- toJSON() {
31
- return {
32
- ...super.toJSON(),
33
- errors: this.errors,
34
- };
35
- }
36
- }
37
- exports.ValidationError = ValidationError;
38
- class AuthError extends HttpError {
39
- constructor(message = 'Unauthorized') {
40
- super(message, 401, 'AUTH_ERROR');
41
- this.name = 'AuthError';
42
- }
43
- }
44
- exports.AuthError = AuthError;
45
12
  class NotFoundError extends HttpError {
46
- constructor(message = 'Not Found') {
47
- super(message, 404, 'NOT_FOUND');
13
+ constructor(message = 'Not found') {
14
+ super(404, message);
48
15
  this.name = 'NotFoundError';
49
16
  }
50
17
  }
51
18
  exports.NotFoundError = NotFoundError;
19
+ class UnauthorizedError extends HttpError {
20
+ constructor(message = 'Unauthorized') {
21
+ super(401, message);
22
+ this.name = 'UnauthorizedError';
23
+ }
24
+ }
25
+ exports.UnauthorizedError = UnauthorizedError;
52
26
  class ForbiddenError extends HttpError {
53
27
  constructor(message = 'Forbidden') {
54
- super(message, 403, 'FORBIDDEN');
28
+ super(403, message);
55
29
  this.name = 'ForbiddenError';
56
30
  }
57
31
  }
58
32
  exports.ForbiddenError = ForbiddenError;
59
33
  class BadRequestError extends HttpError {
60
- constructor(message = 'Bad Request') {
61
- super(message, 400, 'BAD_REQUEST');
34
+ constructor(message = 'Bad request') {
35
+ super(400, message);
62
36
  this.name = 'BadRequestError';
63
37
  }
64
38
  }
65
39
  exports.BadRequestError = BadRequestError;
66
- class ConflictError extends HttpError {
67
- constructor(message = 'Conflict') {
68
- super(message, 409, 'CONFLICT');
69
- this.name = 'ConflictError';
70
- }
71
- }
72
- exports.ConflictError = ConflictError;
73
- class TooManyRequestsError extends HttpError {
74
- constructor(message = 'Too Many Requests', retryAfter) {
75
- super(message, 429, 'TOO_MANY_REQUESTS');
76
- this.name = 'TooManyRequestsError';
77
- this.retryAfter = retryAfter;
78
- }
79
- toJSON() {
80
- return {
81
- ...super.toJSON(),
82
- ...(this.retryAfter && { retryAfter: this.retryAfter }),
83
- };
84
- }
85
- }
86
- exports.TooManyRequestsError = TooManyRequestsError;
87
- class InternalError extends HttpError {
88
- constructor(message = 'Internal Server Error') {
89
- super(message, 500, 'INTERNAL_ERROR');
90
- this.name = 'InternalError';
40
+ class ValidationError extends HttpError {
41
+ constructor(errors, message = 'Validation failed') {
42
+ super(422, message);
43
+ this.errors = errors;
44
+ this.name = 'ValidationError';
91
45
  }
92
46
  }
93
- exports.InternalError = InternalError;
94
- function isHttpError(error) {
95
- return error instanceof HttpError;
96
- }
97
- function isValidationError(error) {
98
- return error instanceof ValidationError;
99
- }
47
+ exports.ValidationError = ValidationError;
100
48
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @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CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED,MAAa,eAAgB,SAAQ,SAAS;IAC5C,YAAmB,MAAgC,EAAE,OAAO,GAAG,mBAAmB;QAChF,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QADH,WAAM,GAAN,MAAM,CAA0B;QAEjD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
- export * from './types';
2
- export * from './adapters/types';
1
+ export { NaraApp, createApp } from './App';
2
+ export type { AppOptions } from './App';
3
+ export { BaseController } from './BaseController';
4
+ export type { User, NaraRequest, NaraResponse, NaraHandler, NaraMiddleware } from './types';
5
+ export type { FrontendAdapter } from './adapters';
6
+ export { jsonSuccess, jsonError, jsonNotFound, jsonUnauthorized, jsonForbidden, jsonValidationError, } from './response';
7
+ export { HttpError, NotFoundError, UnauthorizedError, ForbiddenError, BadRequestError, ValidationError, } from './errors';
3
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,YAAY,EACV,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EACL,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,GAChB,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./adapters/types"), exports);
3
+ exports.ValidationError = exports.BadRequestError = exports.ForbiddenError = exports.UnauthorizedError = exports.NotFoundError = exports.HttpError = exports.jsonValidationError = exports.jsonForbidden = exports.jsonUnauthorized = exports.jsonNotFound = exports.jsonError = exports.jsonSuccess = exports.BaseController = exports.createApp = exports.NaraApp = void 0;
4
+ var App_1 = require("./App");
5
+ Object.defineProperty(exports, "NaraApp", { enumerable: true, get: function () { return App_1.NaraApp; } });
6
+ Object.defineProperty(exports, "createApp", { enumerable: true, get: function () { return App_1.createApp; } });
7
+ var BaseController_1 = require("./BaseController");
8
+ Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return BaseController_1.BaseController; } });
9
+ var response_1 = require("./response");
10
+ Object.defineProperty(exports, "jsonSuccess", { enumerable: true, get: function () { return response_1.jsonSuccess; } });
11
+ Object.defineProperty(exports, "jsonError", { enumerable: true, get: function () { return response_1.jsonError; } });
12
+ Object.defineProperty(exports, "jsonNotFound", { enumerable: true, get: function () { return response_1.jsonNotFound; } });
13
+ Object.defineProperty(exports, "jsonUnauthorized", { enumerable: true, get: function () { return response_1.jsonUnauthorized; } });
14
+ Object.defineProperty(exports, "jsonForbidden", { enumerable: true, get: function () { return response_1.jsonForbidden; } });
15
+ Object.defineProperty(exports, "jsonValidationError", { enumerable: true, get: function () { return response_1.jsonValidationError; } });
16
+ var errors_1 = require("./errors");
17
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return errors_1.HttpError; } });
18
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_1.NotFoundError; } });
19
+ Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return errors_1.UnauthorizedError; } });
20
+ Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return errors_1.ForbiddenError; } });
21
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_1.BadRequestError; } });
22
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
19
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,mDAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,6BAA2C;AAAlC,8FAAA,OAAO,OAAA;AAAE,gGAAA,SAAS,OAAA;AAI3B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAevB,uCAOoB;AANlB,uGAAA,WAAW,OAAA;AACX,qGAAA,SAAS,OAAA;AACT,wGAAA,YAAY,OAAA;AACZ,4GAAA,gBAAgB,OAAA;AAChB,yGAAA,aAAa,OAAA;AACb,+GAAA,mBAAmB,OAAA;AAIrB,mCAOkB;AANhB,mGAAA,SAAS,OAAA;AACT,uGAAA,aAAa,OAAA;AACb,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AACd,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA"}
@@ -1,29 +1,8 @@
1
1
  import type { NaraResponse } from './types';
2
- import { PaginatedMeta } from '@services/Paginator';
3
- export type PaginationMeta = PaginatedMeta;
4
- export type { PaginatedMeta };
5
- export type ResponseMeta = PaginationMeta | Record<string, unknown>;
6
- export interface ApiSuccessResponse<T = unknown> {
7
- success: true;
8
- message: string;
9
- data?: T;
10
- meta?: ResponseMeta;
11
- }
12
- export interface ApiErrorResponse {
13
- success: false;
14
- message: string;
15
- code?: string;
16
- errors?: Record<string, string[]>;
17
- }
18
- export type ApiResponse<T = unknown> = ApiSuccessResponse<T> | ApiErrorResponse;
19
- export declare function jsonSuccess<T = unknown>(res: NaraResponse, message: string, data?: T, meta?: ResponseMeta, statusCode?: number): NaraResponse;
20
- export declare function jsonError(res: NaraResponse, message: string, statusCode?: number, code?: string, errors?: Record<string, string[]>): NaraResponse;
21
- export declare function jsonPaginated<T = unknown>(res: NaraResponse, message: string, data: T[], meta: PaginatedMeta): NaraResponse;
22
- export declare function jsonCreated<T = unknown>(res: NaraResponse, message: string, data?: T): NaraResponse;
23
- export declare function jsonNoContent(res: NaraResponse): NaraResponse;
24
- export declare function jsonUnauthorized(res: NaraResponse, message?: string): NaraResponse;
25
- export declare function jsonForbidden(res: NaraResponse, message?: string): NaraResponse;
26
- export declare function jsonNotFound(res: NaraResponse, message?: string): NaraResponse;
27
- export declare function jsonValidationError(res: NaraResponse, message?: string, errors?: Record<string, string[]>): NaraResponse;
28
- export declare function jsonServerError(res: NaraResponse, message?: string): NaraResponse;
2
+ export declare function jsonSuccess(res: NaraResponse, data: any, message?: string): boolean;
3
+ export declare function jsonError(res: NaraResponse, message: string, status?: number): boolean;
4
+ export declare function jsonNotFound(res: NaraResponse, message?: string): boolean;
5
+ export declare function jsonUnauthorized(res: NaraResponse, message?: string): boolean;
6
+ export declare function jsonForbidden(res: NaraResponse, message?: string): boolean;
7
+ export declare function jsonValidationError(res: NaraResponse, errors: Record<string, string[]>): boolean;
29
8
  //# sourceMappingURL=response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpD,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,CAAC;AAK9B,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAKpE,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAKD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACnC;AAKD,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;AAyBhF,wBAAgB,WAAW,CAAC,CAAC,GAAG,OAAO,EACrC,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,CAAC,EACR,IAAI,CAAC,EAAE,YAAY,EACnB,UAAU,GAAE,MAAY,GACvB,YAAY,CAgBd;AAyBD,wBAAgB,SAAS,CAC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Y,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,SAAY,WAE5E;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAM,WAEzE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,SAAc,WAEpE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,SAAiB,WAE3E;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,SAAc,WAErE;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,WAEtF"}
package/dist/response.js CHANGED
@@ -2,69 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonSuccess = jsonSuccess;
4
4
  exports.jsonError = jsonError;
5
- exports.jsonPaginated = jsonPaginated;
6
- exports.jsonCreated = jsonCreated;
7
- exports.jsonNoContent = jsonNoContent;
5
+ exports.jsonNotFound = jsonNotFound;
8
6
  exports.jsonUnauthorized = jsonUnauthorized;
9
7
  exports.jsonForbidden = jsonForbidden;
10
- exports.jsonNotFound = jsonNotFound;
11
8
  exports.jsonValidationError = jsonValidationError;
12
- exports.jsonServerError = jsonServerError;
13
- function jsonSuccess(res, message, data, meta, statusCode = 200) {
14
- const response = {
15
- success: true,
16
- message,
17
- };
18
- if (data !== undefined) {
19
- response.data = data;
20
- }
21
- if (meta !== undefined) {
22
- response.meta = meta;
23
- }
24
- res.status(statusCode).json(response);
25
- return res;
26
- }
27
- function jsonError(res, message, statusCode = 400, code, errors) {
28
- const response = {
29
- success: false,
30
- message,
31
- };
32
- if (code !== undefined) {
33
- response.code = code;
34
- }
35
- if (errors !== undefined) {
36
- response.errors = errors;
37
- }
38
- res.status(statusCode).json(response);
39
- return res;
9
+ function jsonSuccess(res, data, message = 'Success') {
10
+ return res.json({ success: true, message, data });
40
11
  }
41
- function jsonPaginated(res, message, data, meta) {
42
- const paginationMeta = {
43
- ...meta,
44
- totalPages: meta.totalPages ?? Math.ceil(meta.total / meta.limit),
45
- };
46
- return jsonSuccess(res, message, data, paginationMeta);
12
+ function jsonError(res, message, status = 400) {
13
+ return res.status(status).json({ success: false, message });
47
14
  }
48
- function jsonCreated(res, message, data) {
49
- return jsonSuccess(res, message, data, undefined, 201);
50
- }
51
- function jsonNoContent(res) {
52
- res.status(204).send('');
53
- return res;
15
+ function jsonNotFound(res, message = 'Not found') {
16
+ return res.status(404).json({ success: false, message });
54
17
  }
55
18
  function jsonUnauthorized(res, message = 'Unauthorized') {
56
- return jsonError(res, message, 401, 'UNAUTHORIZED');
19
+ return res.status(401).json({ success: false, message });
57
20
  }
58
21
  function jsonForbidden(res, message = 'Forbidden') {
59
- return jsonError(res, message, 403, 'FORBIDDEN');
60
- }
61
- function jsonNotFound(res, message = 'Not Found') {
62
- return jsonError(res, message, 404, 'NOT_FOUND');
63
- }
64
- function jsonValidationError(res, message = 'Validation failed', errors) {
65
- return jsonError(res, message, 422, 'VALIDATION_ERROR', errors);
22
+ return res.status(403).json({ success: false, message });
66
23
  }
67
- function jsonServerError(res, message = 'Internal Server Error') {
68
- return jsonError(res, message, 500, 'INTERNAL_ERROR');
24
+ function jsonValidationError(res, errors) {
25
+ return res.status(422).json({ success: false, message: 'Validation failed', errors });
69
26
  }
70
27
  //# sourceMappingURL=response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":";;AAqFA,kCAsBC;AAyBD,8BAsBC;AAwBD,sCAaC;AAUD,kCAMC;AAYD,sCAGC;AAQD,4CAKC;AAQD,sCAKC;AAQD,oCAKC;AAWD,kDAMC;AAQD,0CAKC;AA9MD,SAAgB,WAAW,CACzB,GAAiB,EACjB,OAAe,EACf,IAAQ,EACR,IAAmB,EACnB,aAAqB,GAAG;IAExB,MAAM,Q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AAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,SAAgB,SAAS,CAAC,GAAiB,EAAE,OAAe,EAAE,MAAM,GAAG,GAAG;IACxE,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,SAAgB,YAAY,CAAC,GAAiB,EAAE,OAAO,GAAG,WAAW;IACnE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,gBAAgB,CAAC,GAAiB,EAAE,OAAO,GAAG,cAAc;IAC1E,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,aAAa,CAAC,GAAiB,EAAE,OAAO,GAAG,WAAW;IACpE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAiB,EAAE,MAAgC;IACrF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,CAAC,CAAC;AACxF,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,27 +1,16 @@
1
- import type { Request as HyperRequest, Response as HyperResponse, MiddlewareNext } from "hyper-express";
1
+ import type { Request, Response, MiddlewareHandler } from 'hyper-express';
2
2
  export interface User {
3
- id: string;
4
- name: string | null;
3
+ id: number;
4
+ name: string;
5
5
  email: string;
6
- phone: string | null;
7
- avatar: string | null;
8
- is_admin: boolean;
9
- is_verified: boolean;
10
- created_at?: number;
11
- updated_at?: number;
6
+ role?: string;
12
7
  }
13
- export interface NaraRequest extends HyperRequest {
8
+ export interface NaraRequest extends Request {
14
9
  user?: User;
15
- share?: Record<string, unknown>;
16
10
  }
17
- export interface NaraResponse extends HyperResponse {
18
- view(template: string, data?: Record<string, unknown>): Promise<unknown>;
19
- inertia?(component: string, props?: Record<string, unknown>, viewProps?: Record<string, unknown>): Promise<unknown>;
20
- flash(key: string, value: unknown): NaraResponse;
11
+ export interface NaraResponse extends Response {
12
+ inertia?: (component: string, props?: Record<string, any>) => void;
21
13
  }
22
- export interface NaraResponseWithInertia extends NaraResponse {
23
- inertia(component: string, props?: Record<string, unknown>, viewProps?: Record<string, unknown>): Promise<unknown>;
24
- }
25
- export type NaraMiddleware = (req: NaraRequest, res: NaraResponse, next: MiddlewareNext) => unknown | Promise<unknown>;
26
- export type NaraHandler = (req: NaraRequest, res: NaraResponse) => unknown | Promise<unknown>;
14
+ export type NaraHandler = (req: NaraRequest, res: NaraResponse) => void | Promise<void>;
15
+ export type NaraMiddleware = MiddlewareHandler;
27
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,YAAY,EAAE,QAAQ,IAAI,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKxG,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EA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.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1E,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAY,SAAQ,OAAO;IAC1C,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,YAAa,SAAQ,QAAQ;IAC5C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;CACpE;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACxF,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nara-web/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "NARA Framework Core - HyperExpress-based Node.js framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/App.ts ADDED
@@ -0,0 +1,67 @@
1
+ import HyperExpress from 'hyper-express';
2
+ import type { NaraRequest, NaraResponse, NaraHandler, NaraMiddleware } from './types';
3
+ import type { FrontendAdapter } from './adapters';
4
+
5
+ export interface AppOptions {
6
+ port?: number;
7
+ adapter?: FrontendAdapter;
8
+ }
9
+
10
+ export class NaraApp {
11
+ private server: HyperExpress.Server;
12
+ private port: number;
13
+ private adapter?: FrontendAdapter;
14
+
15
+ constructor(options: AppOptions = {}) {
16
+ this.server = new HyperExpress.Server();
17
+ this.port = options.port || 3000;
18
+ this.adapter = options.adapter;
19
+
20
+ if (this.adapter) {
21
+ this.server.use(this.adapter.middleware());
22
+ }
23
+ }
24
+
25
+ use(middleware: NaraMiddleware) {
26
+ this.server.use(middleware);
27
+ return this;
28
+ }
29
+
30
+ get(path: string, ...handlers: NaraHandler[]) {
31
+ this.server.get(path, ...handlers as any);
32
+ return this;
33
+ }
34
+
35
+ post(path: string, ...handlers: NaraHandler[]) {
36
+ this.server.post(path, ...handlers as any);
37
+ return this;
38
+ }
39
+
40
+ put(path: string, ...handlers: NaraHandler[]) {
41
+ this.server.put(path, ...handlers as any);
42
+ return this;
43
+ }
44
+
45
+ patch(path: string, ...handlers: NaraHandler[]) {
46
+ this.server.patch(path, ...handlers as any);
47
+ return this;
48
+ }
49
+
50
+ delete(path: string, ...handlers: NaraHandler[]) {
51
+ this.server.delete(path, ...handlers as any);
52
+ return this;
53
+ }
54
+
55
+ async start() {
56
+ await this.server.listen(this.port);
57
+ console.log(`🚀 Server running on http://localhost:${this.port}`);
58
+ }
59
+
60
+ getServer() {
61
+ return this.server;
62
+ }
63
+ }
64
+
65
+ export function createApp(options?: AppOptions): NaraApp {
66
+ return new NaraApp(options);
67
+ }
@@ -0,0 +1,15 @@
1
+ import type { NaraRequest, NaraResponse } from './types';
2
+
3
+ export class BaseController {
4
+ protected json(res: NaraResponse, data: any, status = 200) {
5
+ return res.status(status).json(data);
6
+ }
7
+
8
+ protected success(res: NaraResponse, data: any, message = 'Success') {
9
+ return res.json({ success: true, message, data });
10
+ }
11
+
12
+ protected error(res: NaraResponse, message: string, status = 400) {
13
+ return res.status(status).json({ success: false, message });
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ import type { NaraMiddleware, NaraResponse } from './types';
2
+
3
+ export interface FrontendAdapter {
4
+ name: string;
5
+ middleware: () => NaraMiddleware;
6
+ extendResponse?: (res: NaraResponse) => void;
7
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,41 @@
1
+ export class HttpError extends Error {
2
+ constructor(public statusCode: number, message: string) {
3
+ super(message);
4
+ this.name = 'HttpError';
5
+ }
6
+ }
7
+
8
+ export class NotFoundError extends HttpError {
9
+ constructor(message = 'Not found') {
10
+ super(404, message);
11
+ this.name = 'NotFoundError';
12
+ }
13
+ }
14
+
15
+ export class UnauthorizedError extends HttpError {
16
+ constructor(message = 'Unauthorized') {
17
+ super(401, message);
18
+ this.name = 'UnauthorizedError';
19
+ }
20
+ }
21
+
22
+ export class ForbiddenError extends HttpError {
23
+ constructor(message = 'Forbidden') {
24
+ super(403, message);
25
+ this.name = 'ForbiddenError';
26
+ }
27
+ }
28
+
29
+ export class BadRequestError extends HttpError {
30
+ constructor(message = 'Bad request') {
31
+ super(400, message);
32
+ this.name = 'BadRequestError';
33
+ }
34
+ }
35
+
36
+ export class ValidationError extends HttpError {
37
+ constructor(public errors: Record<string, string[]>, message = 'Validation failed') {
38
+ super(422, message);
39
+ this.name = 'ValidationError';
40
+ }
41
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,38 @@
1
- export * from './types';
2
- export * from './adapters/types';
1
+ // App
2
+ export { NaraApp, createApp } from './App';
3
+ export type { AppOptions } from './App';
4
+
5
+ // Base Controller
6
+ export { BaseController } from './BaseController';
7
+
8
+ // Types
9
+ export type {
10
+ User,
11
+ NaraRequest,
12
+ NaraResponse,
13
+ NaraHandler,
14
+ NaraMiddleware
15
+ } from './types';
16
+
17
+ // Adapters
18
+ export type { FrontendAdapter } from './adapters';
19
+
20
+ // Response helpers
21
+ export {
22
+ jsonSuccess,
23
+ jsonError,
24
+ jsonNotFound,
25
+ jsonUnauthorized,
26
+ jsonForbidden,
27
+ jsonValidationError,
28
+ } from './response';
29
+
30
+ // Errors
31
+ export {
32
+ HttpError,
33
+ NotFoundError,
34
+ UnauthorizedError,
35
+ ForbiddenError,
36
+ BadRequestError,
37
+ ValidationError,
38
+ } from './errors';
@@ -0,0 +1,25 @@
1
+ import type { NaraResponse } from './types';
2
+
3
+ export function jsonSuccess(res: NaraResponse, data: any, message = 'Success') {
4
+ return res.json({ success: true, message, data });
5
+ }
6
+
7
+ export function jsonError(res: NaraResponse, message: string, status = 400) {
8
+ return res.status(status).json({ success: false, message });
9
+ }
10
+
11
+ export function jsonNotFound(res: NaraResponse, message = 'Not found') {
12
+ return res.status(404).json({ success: false, message });
13
+ }
14
+
15
+ export function jsonUnauthorized(res: NaraResponse, message = 'Unauthorized') {
16
+ return res.status(401).json({ success: false, message });
17
+ }
18
+
19
+ export function jsonForbidden(res: NaraResponse, message = 'Forbidden') {
20
+ return res.status(403).json({ success: false, message });
21
+ }
22
+
23
+ export function jsonValidationError(res: NaraResponse, errors: Record<string, string[]>) {
24
+ return res.status(422).json({ success: false, message: 'Validation failed', errors });
25
+ }