@polygonlabs/servercore 1.0.0-dev.5 → 1.0.0-dev.6

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.
@@ -4,4 +4,5 @@ import '../errors/api_errors.js';
4
4
  import '../errors/base_error.js';
5
5
  import '../errors/database_errors.js';
6
6
  import '../errors/external_dependency_error.js';
7
+ import '../types/response_context.js';
7
8
  import 'zod';
@@ -1,12 +1,9 @@
1
1
  import { ApiError } from '../errors/api_errors.js';
2
2
  import { DatabaseError } from '../errors/database_errors.js';
3
3
  import { ExternalDependencyError } from '../errors/external_dependency_error.js';
4
+ import { ResponseContext } from '../types/response_context.js';
4
5
  import '../errors/base_error.js';
5
6
 
6
- type ResponseContext = {
7
- status: (statusCode: number) => ResponseContext;
8
- json: (body: any) => any;
9
- };
10
7
  declare const handleResponse: (c: ResponseContext, data: any) => any;
11
8
  declare const handleError: (c: ResponseContext, error: ApiError | ExternalDependencyError | DatabaseError) => any;
12
9
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/response_handler.ts"],"sourcesContent":["import { ApiError, DatabaseError, ExternalDependencyError } from \"../errors\"; // Define your error types\nimport { httpResposneCodes, errorCodes } from \"../constants\"; // Define your success codes\n\ntype ResponseContext = {\n // Here we allow the user of this utility to pass the response methods depending on the API framework.\n // For example, in Express, this would be `res` (response) object.\n status: (statusCode: number) => ResponseContext;\n json: (body: any) => any; // Define how to send JSON responses\n};\n\nexport const handleResponse = (c: ResponseContext, data: any) => {\n // This method returns a success response with the status and data.\n return c\n .status(httpResposneCodes.OK_RESPONSE) // Use success code from httpResposneCodes\n .json({\n status: \"success\",\n data: data,\n });\n};\n\nexport const handleError = (\n c: ResponseContext,\n error: ApiError | ExternalDependencyError | DatabaseError\n) => {\n // This method returns an error response with the error details.\n return c\n .status(error.code ?? errorCodes.api.INTERNAL_SERVER_ERROR) // Use error code or default to internal server error\n .json({\n status: \"error\",\n message: error.message,\n name: error.name,\n code: error.code,\n details: error.context,\n });\n};\n"],"mappings":"AAAA,SAAS,UAAU,eAAe,+BAA+B;AACjE,SAAS,mBAAmB,kBAAkB;AASvC,MAAM,iBAAiB,CAAC,GAAoB,SAAc;AAE7D,SAAO,EACF,OAAO,kBAAkB,WAAW,EACpC,KAAK;AAAA,IACF,QAAQ;AAAA,IACR;AAAA,EACJ,CAAC;AACT;AAEO,MAAM,cAAc,CACvB,GACA,UACC;AAED,SAAO,EACF,OAAO,MAAM,QAAQ,WAAW,IAAI,qBAAqB,EACzD,KAAK;AAAA,IACF,QAAQ;AAAA,IACR,SAAS,MAAM;AAAA,IACf,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,SAAS,MAAM;AAAA,EACnB,CAAC;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/api/response_handler.ts"],"sourcesContent":["import { ApiError, DatabaseError, ExternalDependencyError } from \"../errors\"; // Define your error types\nimport { httpResposneCodes, errorCodes } from \"../constants\"; // Define your success codes\nimport type { ResponseContext } from \"../types\";\n\nexport const handleResponse = (c: ResponseContext, data: any) => {\n // This method returns a success response with the status and data.\n return c\n .status(httpResposneCodes.OK_RESPONSE) // Use success code from httpResposneCodes\n .json({\n status: \"success\",\n data: data,\n });\n};\n\nexport const handleError = (\n c: ResponseContext,\n error: ApiError | ExternalDependencyError | DatabaseError\n) => {\n // This method returns an error response with the error details.\n return c\n .status(error.code ?? errorCodes.api.INTERNAL_SERVER_ERROR) // Use error code or default to internal server error\n .json({\n status: \"error\",\n message: error.message,\n name: error.name,\n code: error.code,\n details: error.context,\n });\n};\n"],"mappings":"AAAA,SAAS,UAAU,eAAe,+BAA+B;AACjE,SAAS,mBAAmB,kBAAkB;AAGvC,MAAM,iBAAiB,CAAC,GAAoB,SAAc;AAE7D,SAAO,EACF,OAAO,kBAAkB,WAAW,EACpC,KAAK;AAAA,IACF,QAAQ;AAAA,IACR;AAAA,EACJ,CAAC;AACT;AAEO,MAAM,cAAc,CACvB,GACA,UACC;AAED,SAAO,EACF,OAAO,MAAM,QAAQ,WAAW,IAAI,qBAAqB,EACzD,KAAK;AAAA,IACF,QAAQ;AAAA,IACR,SAAS,MAAM;AAAA,IACf,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,SAAS,MAAM;AAAA,EACnB,CAAC;AACT;","names":[]}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { ILoggerConfig } from './types/logger_config.js';
7
7
  export { IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrderOperationParams, OrderByDirection, WhereFilterOp } from './types/database.js';
8
8
  export { IObserver } from './types/observer.js';
9
9
  export { ChainNativeCurrency, IEventConsumerConfig } from './types/event_consumer_config.js';
10
+ export { ResponseContext } from './types/response_context.js';
10
11
  export { ApiError, BadRequestError, ForbiddenError, NotFoundError, RateLimitError, TimeoutError, UnauthorizedError } from './errors/api_errors.js';
11
12
  export { DatabaseError } from './errors/database_errors.js';
12
13
  export { ExternalDependencyError } from './errors/external_dependency_error.js';
@@ -2,5 +2,6 @@ export { ILoggerConfig } from './logger_config.js';
2
2
  export { IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrderOperationParams, OrderByDirection, WhereFilterOp } from './database.js';
3
3
  export { IObserver } from './observer.js';
4
4
  export { ChainNativeCurrency, IEventConsumerConfig } from './event_consumer_config.js';
5
+ export { ResponseContext } from './response_context.js';
5
6
  import 'winston';
6
7
  import 'viem';
@@ -2,4 +2,5 @@ export * from "./logger_config";
2
2
  export * from "./database";
3
3
  export * from "./observer";
4
4
  export * from "./event_consumer_config";
5
+ export * from "./response_context";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./logger_config\";\nexport * from \"./database\";\nexport * from \"./observer\";\nexport * from \"./event_consumer_config\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./logger_config\";\nexport * from \"./database\";\nexport * from \"./observer\";\nexport * from \"./event_consumer_config\";\nexport * from \"./response_context\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,6 @@
1
+ type ResponseContext = {
2
+ status: (statusCode: number) => ResponseContext;
3
+ json: (body: any) => any;
4
+ };
5
+
6
+ export type { ResponseContext };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=response_context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polygonlabs/servercore",
3
- "version": "1.0.0-dev.5",
3
+ "version": "1.0.0-dev.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },