@application-kit/graphql 0.0.0-stage → 0.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +55 -2
  4. package/dist/cjs/client/index.d.ts +4 -0
  5. package/dist/cjs/client/index.js +20 -0
  6. package/dist/cjs/client/message-code-from-error.d.ts +1 -0
  7. package/dist/cjs/client/message-code-from-error.js +12 -0
  8. package/dist/cjs/client/rejected-characters-from-error.d.ts +1 -0
  9. package/dist/cjs/client/rejected-characters-from-error.js +19 -0
  10. package/dist/cjs/client/request-error.d.ts +8 -0
  11. package/dist/cjs/client/request-error.js +19 -0
  12. package/dist/cjs/client/support-id-from-error.d.ts +1 -0
  13. package/dist/cjs/client/support-id-from-error.js +13 -0
  14. package/dist/cjs/contract/graphql-error-contract.d.ts +17 -0
  15. package/dist/cjs/contract/graphql-error-contract.js +5 -0
  16. package/dist/cjs/contract/index.d.ts +1 -0
  17. package/dist/cjs/contract/index.js +17 -0
  18. package/dist/cjs/errors/add-support-id-to-graphql-error.d.ts +2 -0
  19. package/dist/cjs/errors/add-support-id-to-graphql-error.js +21 -0
  20. package/dist/cjs/errors/business-graphql-error.d.ts +5 -0
  21. package/dist/cjs/errors/business-graphql-error.js +11 -0
  22. package/dist/cjs/errors/format-graphql-error.d.ts +2 -0
  23. package/dist/cjs/errors/format-graphql-error.js +17 -0
  24. package/dist/cjs/errors/index.d.ts +6 -0
  25. package/dist/cjs/errors/index.js +22 -0
  26. package/dist/cjs/errors/is-business-graphql-error.d.ts +2 -0
  27. package/dist/cjs/errors/is-business-graphql-error.js +14 -0
  28. package/dist/cjs/errors/map-http-exception-to-graphql-error.d.ts +3 -0
  29. package/dist/cjs/errors/map-http-exception-to-graphql-error.js +29 -0
  30. package/dist/cjs/errors/match-business-error.d.ts +7 -0
  31. package/dist/cjs/errors/match-business-error.js +8 -0
  32. package/dist/cjs/index.d.ts +3 -0
  33. package/dist/cjs/index.js +19 -0
  34. package/dist/cjs/listing/cursor-output.type.d.ts +5 -0
  35. package/dist/cjs/listing/cursor-output.type.js +29 -0
  36. package/dist/cjs/listing/cursor-type.interface.d.ts +2 -0
  37. package/dist/cjs/listing/cursor-type.interface.js +2 -0
  38. package/dist/cjs/listing/filter-input.type.d.ts +6 -0
  39. package/dist/cjs/listing/filter-input.type.js +36 -0
  40. package/dist/cjs/listing/index.d.ts +7 -0
  41. package/dist/cjs/listing/index.js +23 -0
  42. package/dist/cjs/listing/listing-payload.d.ts +8 -0
  43. package/dist/cjs/listing/listing-payload.js +41 -0
  44. package/dist/cjs/listing/listing-response.interface.d.ts +6 -0
  45. package/dist/cjs/listing/listing-response.interface.js +2 -0
  46. package/dist/cjs/listing/paginator-input.type.d.ts +4 -0
  47. package/dist/cjs/listing/paginator-input.type.js +34 -0
  48. package/dist/cjs/listing/sorting-input.type.d.ts +5 -0
  49. package/dist/cjs/listing/sorting-input.type.js +31 -0
  50. package/dist/cjs/package.json +3 -0
  51. package/dist/esm/client/index.d.ts +4 -0
  52. package/dist/esm/client/index.js +4 -0
  53. package/dist/esm/client/message-code-from-error.d.ts +1 -0
  54. package/dist/esm/client/message-code-from-error.js +8 -0
  55. package/dist/esm/client/rejected-characters-from-error.d.ts +1 -0
  56. package/dist/esm/client/rejected-characters-from-error.js +15 -0
  57. package/dist/esm/client/request-error.d.ts +8 -0
  58. package/dist/esm/client/request-error.js +13 -0
  59. package/dist/esm/client/support-id-from-error.d.ts +1 -0
  60. package/dist/esm/client/support-id-from-error.js +9 -0
  61. package/dist/esm/contract/graphql-error-contract.d.ts +17 -0
  62. package/dist/esm/contract/graphql-error-contract.js +2 -0
  63. package/dist/esm/contract/index.d.ts +1 -0
  64. package/dist/esm/contract/index.js +1 -0
  65. package/dist/esm/errors/add-support-id-to-graphql-error.d.ts +2 -0
  66. package/dist/esm/errors/add-support-id-to-graphql-error.js +17 -0
  67. package/dist/esm/errors/business-graphql-error.d.ts +5 -0
  68. package/dist/esm/errors/business-graphql-error.js +7 -0
  69. package/dist/esm/errors/format-graphql-error.d.ts +2 -0
  70. package/dist/esm/errors/format-graphql-error.js +13 -0
  71. package/dist/esm/errors/index.d.ts +6 -0
  72. package/dist/esm/errors/index.js +6 -0
  73. package/dist/esm/errors/is-business-graphql-error.d.ts +2 -0
  74. package/dist/esm/errors/is-business-graphql-error.js +10 -0
  75. package/dist/esm/errors/map-http-exception-to-graphql-error.d.ts +3 -0
  76. package/dist/esm/errors/map-http-exception-to-graphql-error.js +25 -0
  77. package/dist/esm/errors/match-business-error.d.ts +7 -0
  78. package/dist/esm/errors/match-business-error.js +4 -0
  79. package/dist/esm/index.d.ts +3 -0
  80. package/dist/esm/index.js +3 -0
  81. package/dist/esm/listing/cursor-output.type.d.ts +5 -0
  82. package/dist/esm/listing/cursor-output.type.js +26 -0
  83. package/dist/esm/listing/cursor-type.interface.d.ts +2 -0
  84. package/dist/esm/listing/cursor-type.interface.js +1 -0
  85. package/dist/esm/listing/filter-input.type.d.ts +6 -0
  86. package/dist/esm/listing/filter-input.type.js +33 -0
  87. package/dist/esm/listing/index.d.ts +7 -0
  88. package/dist/esm/listing/index.js +7 -0
  89. package/dist/esm/listing/listing-payload.d.ts +8 -0
  90. package/dist/esm/listing/listing-payload.js +38 -0
  91. package/dist/esm/listing/listing-response.interface.d.ts +6 -0
  92. package/dist/esm/listing/listing-response.interface.js +1 -0
  93. package/dist/esm/listing/paginator-input.type.d.ts +4 -0
  94. package/dist/esm/listing/paginator-input.type.js +31 -0
  95. package/dist/esm/listing/sorting-input.type.d.ts +5 -0
  96. package/dist/esm/listing/sorting-input.type.js +28 -0
  97. package/package.json +91 -3
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Payload = void 0;
13
+ const graphql_1 = require("@nestjs/graphql");
14
+ const class_transformer_1 = require("class-transformer");
15
+ const class_validator_1 = require("class-validator");
16
+ const filter_input_type_js_1 = require("./filter-input.type.js");
17
+ const paginator_input_type_js_1 = require("./paginator-input.type.js");
18
+ const sorting_input_type_js_1 = require("./sorting-input.type.js");
19
+ let Payload = class Payload {
20
+ filters = [];
21
+ paginator = new paginator_input_type_js_1.PaginatorInputType();
22
+ sorting = [];
23
+ };
24
+ exports.Payload = Payload;
25
+ __decorate([
26
+ (0, graphql_1.Field)(() => [filter_input_type_js_1.FilterInputType], { nullable: true }),
27
+ __metadata("design:type", Array)
28
+ ], Payload.prototype, "filters", void 0);
29
+ __decorate([
30
+ (0, graphql_1.Field)(() => paginator_input_type_js_1.PaginatorInputType, { nullable: true }),
31
+ (0, class_transformer_1.Type)(() => paginator_input_type_js_1.PaginatorInputType),
32
+ (0, class_validator_1.ValidateNested)(),
33
+ __metadata("design:type", paginator_input_type_js_1.PaginatorInputType)
34
+ ], Payload.prototype, "paginator", void 0);
35
+ __decorate([
36
+ (0, graphql_1.Field)(() => [sorting_input_type_js_1.SortingInputType], { nullable: true }),
37
+ __metadata("design:type", Array)
38
+ ], Payload.prototype, "sorting", void 0);
39
+ exports.Payload = Payload = __decorate([
40
+ (0, graphql_1.ArgsType)()
41
+ ], Payload);
@@ -0,0 +1,6 @@
1
+ import type { CursorTypeInterface } from './cursor-type.interface.js';
2
+ export interface ListingResponseInterface<T> {
3
+ cursor: CursorTypeInterface;
4
+ data: T[];
5
+ totalRecords: number;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare class PaginatorInputType {
2
+ limit: number;
3
+ pageCursor: null | string;
4
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PaginatorInputType = void 0;
13
+ const graphql_1 = require("@nestjs/graphql");
14
+ const class_validator_1 = require("class-validator");
15
+ const MAX_PAGE_SIZE = 200;
16
+ let PaginatorInputType = class PaginatorInputType {
17
+ limit;
18
+ pageCursor;
19
+ };
20
+ exports.PaginatorInputType = PaginatorInputType;
21
+ __decorate([
22
+ (0, graphql_1.Field)(() => Number),
23
+ (0, class_validator_1.IsInt)(),
24
+ (0, class_validator_1.Max)(MAX_PAGE_SIZE),
25
+ (0, class_validator_1.Min)(1),
26
+ __metadata("design:type", Number)
27
+ ], PaginatorInputType.prototype, "limit", void 0);
28
+ __decorate([
29
+ (0, graphql_1.Field)(() => String, { nullable: true }),
30
+ __metadata("design:type", Object)
31
+ ], PaginatorInputType.prototype, "pageCursor", void 0);
32
+ exports.PaginatorInputType = PaginatorInputType = __decorate([
33
+ (0, graphql_1.InputType)()
34
+ ], PaginatorInputType);
@@ -0,0 +1,5 @@
1
+ import { SortOrder } from '@application-kit/typeorm/listing';
2
+ export declare class SortingInputType {
3
+ field: string;
4
+ order: SortOrder;
5
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SortingInputType = void 0;
13
+ const listing_1 = require("@application-kit/typeorm/listing");
14
+ const graphql_1 = require("@nestjs/graphql");
15
+ (0, graphql_1.registerEnumType)(listing_1.SortOrder, { name: 'SortOrder' });
16
+ let SortingInputType = class SortingInputType {
17
+ field;
18
+ order;
19
+ };
20
+ exports.SortingInputType = SortingInputType;
21
+ __decorate([
22
+ (0, graphql_1.Field)(() => String),
23
+ __metadata("design:type", String)
24
+ ], SortingInputType.prototype, "field", void 0);
25
+ __decorate([
26
+ (0, graphql_1.Field)(() => listing_1.SortOrder),
27
+ __metadata("design:type", String)
28
+ ], SortingInputType.prototype, "order", void 0);
29
+ exports.SortingInputType = SortingInputType = __decorate([
30
+ (0, graphql_1.InputType)()
31
+ ], SortingInputType);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,4 @@
1
+ export * from './message-code-from-error.js';
2
+ export * from './rejected-characters-from-error.js';
3
+ export * from './request-error.js';
4
+ export * from './support-id-from-error.js';
@@ -0,0 +1,4 @@
1
+ export * from './message-code-from-error.js';
2
+ export * from './rejected-characters-from-error.js';
3
+ export * from './request-error.js';
4
+ export * from './support-id-from-error.js';
@@ -0,0 +1 @@
1
+ export declare const messageCodeFromError: (error: unknown) => null | string;
@@ -0,0 +1,8 @@
1
+ import { CombinedGraphQLErrors } from '@apollo/client/errors';
2
+ const messageCodeOf = (graphqlError) => {
3
+ const extensions = graphqlError.extensions ?? {};
4
+ return extensions.messageCode;
5
+ };
6
+ export const messageCodeFromError = (error) => (CombinedGraphQLErrors.is(error)
7
+ ? error.errors.map((graphqlError) => messageCodeOf(graphqlError)).find((code) => code !== undefined) ?? null
8
+ : null);
@@ -0,0 +1 @@
1
+ export declare const rejectedCharactersFromError: (error: unknown) => string[];
@@ -0,0 +1,15 @@
1
+ import { CombinedGraphQLErrors } from '@apollo/client/errors';
2
+ const rejectedCharactersOf = (graphqlError) => {
3
+ const extensions = graphqlError.extensions ?? {};
4
+ return extensions.rejectedCharacters;
5
+ };
6
+ const isString = (item) => typeof item === 'string';
7
+ const isCharacterList = (value) => {
8
+ const isNonEmptyArray = Array.isArray(value) && value.length > 0;
9
+ return isNonEmptyArray && value.every(isString);
10
+ };
11
+ const firstCharacterList = (error) => {
12
+ const lists = error.errors.map((graphqlError) => rejectedCharactersOf(graphqlError));
13
+ return lists.find(isCharacterList) ?? [];
14
+ };
15
+ export const rejectedCharactersFromError = (error) => (CombinedGraphQLErrors.is(error) ? firstCharacterList(error) : []);
@@ -0,0 +1,8 @@
1
+ export declare const SKIP_GLOBAL_ERROR_TOAST = "skipGlobalErrorToast";
2
+ export declare const shouldSkipGlobalErrorToast: (context: Record<string, unknown>) => boolean;
3
+ export type TranslateFunction = (key: string, named?: Record<string, unknown>) => string;
4
+ export declare const SUPPORT_ID_LINE_KEY = "error.supportIdLine";
5
+ export declare const withSupportId: (message: string, supportId: string, translate: TranslateFunction) => string;
6
+ export type DescribeRequestError = (error: unknown, fallbackMessage: string, translate: TranslateFunction) => string;
7
+ export type MessageKeyFromError = (error: unknown) => null | string;
8
+ export declare const createDescribeRequestError: (messageKeyFromError: MessageKeyFromError) => DescribeRequestError;
@@ -0,0 +1,13 @@
1
+ import { supportIdFromError } from './support-id-from-error.js';
2
+ export const SKIP_GLOBAL_ERROR_TOAST = 'skipGlobalErrorToast';
3
+ export const shouldSkipGlobalErrorToast = (context) => {
4
+ const skipFlag = context[SKIP_GLOBAL_ERROR_TOAST];
5
+ return skipFlag === true;
6
+ };
7
+ export const SUPPORT_ID_LINE_KEY = 'error.supportIdLine';
8
+ export const withSupportId = (message, supportId, translate) => (supportId === '' ? message : `${message}\n${translate(SUPPORT_ID_LINE_KEY, { id: supportId })}`);
9
+ export const createDescribeRequestError = (messageKeyFromError) => (error, fallbackMessage, translate) => {
10
+ const messageKey = messageKeyFromError(error);
11
+ const message = messageKey === null ? fallbackMessage : translate(messageKey);
12
+ return withSupportId(message, supportIdFromError(error), translate);
13
+ };
@@ -0,0 +1 @@
1
+ export declare const supportIdFromError: (error: unknown) => string;
@@ -0,0 +1,9 @@
1
+ import { CombinedGraphQLErrors } from '@apollo/client/errors';
2
+ const supportIdOf = (graphqlError) => {
3
+ const extensions = graphqlError.extensions ?? {};
4
+ return extensions.supportId;
5
+ };
6
+ const isNonEmptyString = (value) => typeof value === 'string' && value !== '';
7
+ export const supportIdFromError = (error) => (CombinedGraphQLErrors.is(error)
8
+ ? error.errors.map((graphqlError) => supportIdOf(graphqlError)).find(isNonEmptyString) ?? ''
9
+ : '');
@@ -0,0 +1,17 @@
1
+ import type { GraphQLErrorExtensions } from 'graphql';
2
+ export declare const BUSINESS_GRAPHQL_ERROR_CODES: readonly ["BAD_USER_INPUT", "FORBIDDEN", "NOT_FOUND"];
3
+ export type BusinessGraphQLErrorCode = (typeof BUSINESS_GRAPHQL_ERROR_CODES)[number];
4
+ export declare const INTERNAL_SERVER_ERROR_CODE = "INTERNAL_SERVER_ERROR";
5
+ export type GraphQLErrorWireExtensions = {
6
+ code?: string;
7
+ messageCode?: string;
8
+ rejectedCharacters?: string[];
9
+ statusCode?: number;
10
+ supportId?: string;
11
+ validationErrors?: GraphQLValidationFieldErrorInterface[];
12
+ } & GraphQLErrorExtensions;
13
+ interface GraphQLValidationFieldErrorInterface {
14
+ constraints: string[];
15
+ property: string;
16
+ }
17
+ export {};
@@ -0,0 +1,2 @@
1
+ export const BUSINESS_GRAPHQL_ERROR_CODES = ['BAD_USER_INPUT', 'FORBIDDEN', 'NOT_FOUND'];
2
+ export const INTERNAL_SERVER_ERROR_CODE = 'INTERNAL_SERVER_ERROR';
@@ -0,0 +1 @@
1
+ export * from './graphql-error-contract.js';
@@ -0,0 +1 @@
1
+ export * from './graphql-error-contract.js';
@@ -0,0 +1,2 @@
1
+ import { GraphQLError } from 'graphql';
2
+ export declare const addSupportIdToGraphQLError: (gqlError: GraphQLError, supportId: string) => GraphQLError;
@@ -0,0 +1,17 @@
1
+ import { GraphQLError } from 'graphql';
2
+ const nullable = (value) => value ?? null;
3
+ export const addSupportIdToGraphQLError = (gqlError, supportId) => {
4
+ if (supportId === '') {
5
+ return gqlError;
6
+ }
7
+ const { extensions, message, nodes, originalError, path, positions, source } = gqlError;
8
+ const extensionsWithSupportId = { ...extensions, supportId };
9
+ return new GraphQLError(message, {
10
+ extensions: extensionsWithSupportId,
11
+ nodes: nullable(nodes),
12
+ originalError: nullable(originalError),
13
+ path: nullable(path),
14
+ positions: nullable(positions),
15
+ source: nullable(source),
16
+ });
17
+ };
@@ -0,0 +1,5 @@
1
+ import { GraphQLError } from 'graphql';
2
+ import type { BusinessGraphQLErrorCode, GraphQLErrorWireExtensions } from '../contract/graphql-error-contract.js';
3
+ export declare class BusinessGraphQLError<TMessageCode extends string> extends GraphQLError {
4
+ constructor(message: string, code: BusinessGraphQLErrorCode, messageCode: TMessageCode, extensions?: GraphQLErrorWireExtensions);
5
+ }
@@ -0,0 +1,7 @@
1
+ import { GraphQLError } from 'graphql';
2
+ export class BusinessGraphQLError extends GraphQLError {
3
+ constructor(message, code, messageCode, extensions) {
4
+ super(message, { extensions: { ...extensions, code, messageCode } });
5
+ this.name = 'BusinessGraphQLError';
6
+ }
7
+ }
@@ -0,0 +1,2 @@
1
+ import type { GraphQLError } from 'graphql';
2
+ export declare const formatGraphQLError: (gqlError: GraphQLError, supportId: string) => GraphQLError;
@@ -0,0 +1,13 @@
1
+ import { HttpException } from '@nestjs/common';
2
+ import { addSupportIdToGraphQLError } from './add-support-id-to-graphql-error.js';
3
+ import { isBusinessGraphQLError } from './is-business-graphql-error.js';
4
+ import { mapHttpExceptionToGraphQLError } from './map-http-exception-to-graphql-error.js';
5
+ export const formatGraphQLError = (gqlError, supportId) => {
6
+ const { originalError } = gqlError;
7
+ const mappedError = originalError instanceof HttpException
8
+ ? mapHttpExceptionToGraphQLError(gqlError, originalError)
9
+ : gqlError;
10
+ return isBusinessGraphQLError(mappedError)
11
+ ? mappedError
12
+ : addSupportIdToGraphQLError(mappedError, supportId);
13
+ };
@@ -0,0 +1,6 @@
1
+ export * from './add-support-id-to-graphql-error.js';
2
+ export * from './business-graphql-error.js';
3
+ export * from './format-graphql-error.js';
4
+ export * from './is-business-graphql-error.js';
5
+ export * from './map-http-exception-to-graphql-error.js';
6
+ export * from './match-business-error.js';
@@ -0,0 +1,6 @@
1
+ export * from './add-support-id-to-graphql-error.js';
2
+ export * from './business-graphql-error.js';
3
+ export * from './format-graphql-error.js';
4
+ export * from './is-business-graphql-error.js';
5
+ export * from './map-http-exception-to-graphql-error.js';
6
+ export * from './match-business-error.js';
@@ -0,0 +1,2 @@
1
+ import type { GraphQLError } from 'graphql';
2
+ export declare const isBusinessGraphQLError: (error: GraphQLError) => boolean;
@@ -0,0 +1,10 @@
1
+ import { BUSINESS_GRAPHQL_ERROR_CODES } from '../contract/graphql-error-contract.js';
2
+ const CLIENT_ERROR_MIN_STATUS = 400;
3
+ const SERVER_ERROR_MIN_STATUS = 500;
4
+ const BUSINESS_ERROR_CODES = new Set(BUSINESS_GRAPHQL_ERROR_CODES);
5
+ export const isBusinessGraphQLError = (error) => {
6
+ const { code, statusCode } = error.extensions;
7
+ return typeof statusCode === 'number'
8
+ ? statusCode >= CLIENT_ERROR_MIN_STATUS && statusCode < SERVER_ERROR_MIN_STATUS
9
+ : typeof code === 'string' && BUSINESS_ERROR_CODES.has(code);
10
+ };
@@ -0,0 +1,3 @@
1
+ import { HttpException } from '@nestjs/common';
2
+ import { GraphQLError } from 'graphql';
3
+ export declare const mapHttpExceptionToGraphQLError: (gqlError: GraphQLError, originalError: HttpException) => GraphQLError;
@@ -0,0 +1,25 @@
1
+ import { HttpException, UnprocessableEntityException } from '@nestjs/common';
2
+ import { GraphQLError } from 'graphql';
3
+ const isRecord = (value) => typeof value === 'object' && value !== null;
4
+ const nullable = (value) => value ?? null;
5
+ export const mapHttpExceptionToGraphQLError = (gqlError, originalError) => {
6
+ const { extensions, nodes, path, positions, source } = gqlError;
7
+ const response = originalError.getResponse();
8
+ const payload = isRecord(response) ? response : { message: response };
9
+ const message = typeof payload.message === 'string' ? payload.message : gqlError.message;
10
+ const code = Array.isArray(payload.validationErrors) ? UnprocessableEntityException.name : HttpException.name;
11
+ const extensionsOnWire = {
12
+ ...extensions,
13
+ ...payload,
14
+ code,
15
+ statusCode: originalError.getStatus(),
16
+ };
17
+ return new GraphQLError(message, {
18
+ extensions: extensionsOnWire,
19
+ nodes: nullable(nodes),
20
+ originalError,
21
+ path: nullable(path),
22
+ positions: nullable(positions),
23
+ source: nullable(source),
24
+ });
25
+ };
@@ -0,0 +1,7 @@
1
+ import type { BusinessGraphQLErrorCode } from '../contract/graphql-error-contract.js';
2
+ export interface BusinessErrorOptionsInterface<TMessageCode extends string> {
3
+ code: BusinessGraphQLErrorCode;
4
+ messageCode: TMessageCode;
5
+ }
6
+ export type BusinessErrorTable<TOptions> = readonly [new (...arguments_: never[]) => Error, TOptions][];
7
+ export declare const matchBusinessError: <TOptions>(table: BusinessErrorTable<TOptions>, fallback: TOptions) => (commandError: Error) => TOptions;
@@ -0,0 +1,4 @@
1
+ export const matchBusinessError = (table, fallback) => (commandError) => {
2
+ const matched = table.find(([errorClass]) => commandError instanceof errorClass);
3
+ return matched?.[1] ?? fallback;
4
+ };
@@ -0,0 +1,3 @@
1
+ export * from './contract/index.js';
2
+ export * from './errors/index.js';
3
+ export * from './listing/index.js';
@@ -0,0 +1,3 @@
1
+ export * from './contract/index.js';
2
+ export * from './errors/index.js';
3
+ export * from './listing/index.js';
@@ -0,0 +1,5 @@
1
+ import { CursorTypeInterface } from './cursor-type.interface.js';
2
+ export declare class CursorOutputType implements CursorTypeInterface {
3
+ next: null | string;
4
+ prev: null | string;
5
+ }
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Field, ObjectType } from '@nestjs/graphql';
11
+ let CursorOutputType = class CursorOutputType {
12
+ next;
13
+ prev;
14
+ };
15
+ __decorate([
16
+ Field(() => String, { nullable: true }),
17
+ __metadata("design:type", Object)
18
+ ], CursorOutputType.prototype, "next", void 0);
19
+ __decorate([
20
+ Field(() => String, { nullable: true }),
21
+ __metadata("design:type", Object)
22
+ ], CursorOutputType.prototype, "prev", void 0);
23
+ CursorOutputType = __decorate([
24
+ ObjectType()
25
+ ], CursorOutputType);
26
+ export { CursorOutputType };
@@ -0,0 +1,2 @@
1
+ import type { CursorInterface } from '@application-kit/typeorm/listing';
2
+ export type CursorTypeInterface = CursorInterface;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { FiltersMatchMode } from '@application-kit/typeorm/listing';
2
+ export declare class FilterInputType {
3
+ field: string;
4
+ matchMode: FiltersMatchMode;
5
+ value: string;
6
+ }
@@ -0,0 +1,33 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { FiltersMatchMode } from '@application-kit/typeorm/listing';
11
+ import { Field, InputType, registerEnumType } from '@nestjs/graphql';
12
+ registerEnumType(FiltersMatchMode, { name: 'FiltersMatchMode' });
13
+ let FilterInputType = class FilterInputType {
14
+ field;
15
+ matchMode;
16
+ value;
17
+ };
18
+ __decorate([
19
+ Field(() => String),
20
+ __metadata("design:type", String)
21
+ ], FilterInputType.prototype, "field", void 0);
22
+ __decorate([
23
+ Field(() => FiltersMatchMode),
24
+ __metadata("design:type", String)
25
+ ], FilterInputType.prototype, "matchMode", void 0);
26
+ __decorate([
27
+ Field(() => String),
28
+ __metadata("design:type", String)
29
+ ], FilterInputType.prototype, "value", void 0);
30
+ FilterInputType = __decorate([
31
+ InputType()
32
+ ], FilterInputType);
33
+ export { FilterInputType };
@@ -0,0 +1,7 @@
1
+ export * from './cursor-output.type.js';
2
+ export * from './cursor-type.interface.js';
3
+ export * from './filter-input.type.js';
4
+ export * from './listing-payload.js';
5
+ export * from './listing-response.interface.js';
6
+ export * from './paginator-input.type.js';
7
+ export * from './sorting-input.type.js';
@@ -0,0 +1,7 @@
1
+ export * from './cursor-output.type.js';
2
+ export * from './cursor-type.interface.js';
3
+ export * from './filter-input.type.js';
4
+ export * from './listing-payload.js';
5
+ export * from './listing-response.interface.js';
6
+ export * from './paginator-input.type.js';
7
+ export * from './sorting-input.type.js';
@@ -0,0 +1,8 @@
1
+ import { FilterInputType } from './filter-input.type.js';
2
+ import { PaginatorInputType } from './paginator-input.type.js';
3
+ import { SortingInputType } from './sorting-input.type.js';
4
+ export declare class Payload {
5
+ filters?: FilterInputType[];
6
+ paginator: PaginatorInputType;
7
+ sorting?: SortingInputType[];
8
+ }
@@ -0,0 +1,38 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { ArgsType, Field } from '@nestjs/graphql';
11
+ import { Type } from 'class-transformer';
12
+ import { ValidateNested } from 'class-validator';
13
+ import { FilterInputType } from './filter-input.type.js';
14
+ import { PaginatorInputType } from './paginator-input.type.js';
15
+ import { SortingInputType } from './sorting-input.type.js';
16
+ let Payload = class Payload {
17
+ filters = [];
18
+ paginator = new PaginatorInputType();
19
+ sorting = [];
20
+ };
21
+ __decorate([
22
+ Field(() => [FilterInputType], { nullable: true }),
23
+ __metadata("design:type", Array)
24
+ ], Payload.prototype, "filters", void 0);
25
+ __decorate([
26
+ Field(() => PaginatorInputType, { nullable: true }),
27
+ Type(() => PaginatorInputType),
28
+ ValidateNested(),
29
+ __metadata("design:type", PaginatorInputType)
30
+ ], Payload.prototype, "paginator", void 0);
31
+ __decorate([
32
+ Field(() => [SortingInputType], { nullable: true }),
33
+ __metadata("design:type", Array)
34
+ ], Payload.prototype, "sorting", void 0);
35
+ Payload = __decorate([
36
+ ArgsType()
37
+ ], Payload);
38
+ export { Payload };
@@ -0,0 +1,6 @@
1
+ import type { CursorTypeInterface } from './cursor-type.interface.js';
2
+ export interface ListingResponseInterface<T> {
3
+ cursor: CursorTypeInterface;
4
+ data: T[];
5
+ totalRecords: number;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare class PaginatorInputType {
2
+ limit: number;
3
+ pageCursor: null | string;
4
+ }
@@ -0,0 +1,31 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Field, InputType } from '@nestjs/graphql';
11
+ import { IsInt, Max, Min } from 'class-validator';
12
+ const MAX_PAGE_SIZE = 200;
13
+ let PaginatorInputType = class PaginatorInputType {
14
+ limit;
15
+ pageCursor;
16
+ };
17
+ __decorate([
18
+ Field(() => Number),
19
+ IsInt(),
20
+ Max(MAX_PAGE_SIZE),
21
+ Min(1),
22
+ __metadata("design:type", Number)
23
+ ], PaginatorInputType.prototype, "limit", void 0);
24
+ __decorate([
25
+ Field(() => String, { nullable: true }),
26
+ __metadata("design:type", Object)
27
+ ], PaginatorInputType.prototype, "pageCursor", void 0);
28
+ PaginatorInputType = __decorate([
29
+ InputType()
30
+ ], PaginatorInputType);
31
+ export { PaginatorInputType };
@@ -0,0 +1,5 @@
1
+ import { SortOrder } from '@application-kit/typeorm/listing';
2
+ export declare class SortingInputType {
3
+ field: string;
4
+ order: SortOrder;
5
+ }