@application-kit/graphql 0.5.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @application-kit/graphql
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - abb4a67: Реестр кодов сообщений `BusinessMessageCodeRegistryInterface` и тип `BusinessMessageCode`: приложение объявляет коды через `declare module '@application-kit/graphql'`.
8
+ **Ломающее:** параметр типа у `BusinessGraphQLError` и `BusinessErrorOptionsInterface` снят, `BusinessErrorTable` получил значение параметра по умолчанию. Потребителю — записать коды в реестр и удалить свои привязки параметра; без записи тип кода `never`, и `new BusinessGraphQLError` не компилируется.
9
+
3
10
  ## 0.5.0
4
11
 
5
12
  ### Minor Changes
package/README.md CHANGED
@@ -27,7 +27,7 @@ Peer-зависимости: `@nestjs/common`, `@nestjs/graphql`, `class-transfo
27
27
 
28
28
  ## Сервер
29
29
 
30
- - `BusinessGraphQLError<TMessageCode>` — бизнес-ошибка с транспортным кодом (`BAD_USER_INPUT`, `FORBIDDEN`,
30
+ - `BusinessGraphQLError` — бизнес-ошибка с транспортным кодом (`BAD_USER_INPUT`, `FORBIDDEN`,
31
31
  `NOT_FOUND`) и кодом показываемого текста `messageCode`.
32
32
  - `matchBusinessError(table, fallback)` — таблица «класс доменной ошибки → опции ответа», первая подходящая строка.
33
33
  - `formatGraphQLError(error, supportId)` — единая точка форматирования: `HttpException` → `extensions`,
@@ -37,14 +37,17 @@ Peer-зависимости: `@nestjs/common`, `@nestjs/graphql`, `class-transfo
37
37
 
38
38
  ### Словарь кодов сообщений — у приложения
39
39
 
40
- Пакет не знает кодов сообщений: тип кода — параметр без значения по умолчанию. Приложение один раз связывает его
41
- со своим объединением, и неизвестный код перестаёт компилироваться:
40
+ Пакет не знает кодов сообщений: реестр `BusinessMessageCodeRegistryInterface` пуст, и без записи приложения тип кода —
41
+ `never`. Приложение объявляет коды один раз, и неизвестный код перестаёт компилироваться в `BusinessGraphQLError`,
42
+ `BusinessErrorOptionsInterface` и `BusinessErrorTable`:
42
43
 
43
44
  ```ts
44
- type MessageCode = 'signIn.invalidCredentials' | 'profile.notFound'
45
-
46
- export class BusinessGraphQLError extends BaseBusinessGraphQLError<MessageCode> {}
47
- export type BusinessErrorOptions = BusinessErrorOptionsInterface<MessageCode>
45
+ declare module '@application-kit/graphql' {
46
+ interface BusinessMessageCodeRegistryInterface {
47
+ 'profile.notFound': true
48
+ 'signIn.invalidCredentials': true
49
+ }
50
+ }
48
51
  ```
49
52
 
50
53
  ## Клиент (`/client`)
@@ -0,0 +1,3 @@
1
+ export type BusinessMessageCode = keyof BusinessMessageCodeRegistryInterface;
2
+ export interface BusinessMessageCodeRegistryInterface {
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
+ export * from './business-message-code.js';
1
2
  export * from './graphql-error-contract.js';
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./business-message-code.js"), exports);
17
18
  __exportStar(require("./graphql-error-contract.js"), exports);
@@ -1,5 +1,6 @@
1
1
  import { GraphQLError } from 'graphql';
2
+ import type { BusinessMessageCode } from '../contract/business-message-code.js';
2
3
  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);
4
+ export declare class BusinessGraphQLError extends GraphQLError {
5
+ constructor(message: string, code: BusinessGraphQLErrorCode, messageCode: BusinessMessageCode, extensions?: GraphQLErrorWireExtensions);
5
6
  }
@@ -1,7 +1,8 @@
1
+ import type { BusinessMessageCode } from '../contract/business-message-code.js';
1
2
  import type { BusinessGraphQLErrorCode } from '../contract/graphql-error-contract.js';
2
- export interface BusinessErrorOptionsInterface<TMessageCode extends string> {
3
+ export interface BusinessErrorOptionsInterface {
3
4
  code: BusinessGraphQLErrorCode;
4
- messageCode: TMessageCode;
5
+ messageCode: BusinessMessageCode;
5
6
  }
6
- export type BusinessErrorTable<TOptions> = readonly [new (...arguments_: never[]) => Error, TOptions][];
7
+ export type BusinessErrorTable<TOptions = BusinessErrorOptionsInterface> = readonly [new (...arguments_: never[]) => Error, TOptions][];
7
8
  export declare const matchBusinessError: <TOptions>(table: BusinessErrorTable<TOptions>, fallback: TOptions) => (commandError: Error) => TOptions;
@@ -0,0 +1,3 @@
1
+ export type BusinessMessageCode = keyof BusinessMessageCodeRegistryInterface;
2
+ export interface BusinessMessageCodeRegistryInterface {
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1,2 @@
1
+ export * from './business-message-code.js';
1
2
  export * from './graphql-error-contract.js';
@@ -1 +1,2 @@
1
+ export * from './business-message-code.js';
1
2
  export * from './graphql-error-contract.js';
@@ -1,5 +1,6 @@
1
1
  import { GraphQLError } from 'graphql';
2
+ import type { BusinessMessageCode } from '../contract/business-message-code.js';
2
3
  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);
4
+ export declare class BusinessGraphQLError extends GraphQLError {
5
+ constructor(message: string, code: BusinessGraphQLErrorCode, messageCode: BusinessMessageCode, extensions?: GraphQLErrorWireExtensions);
5
6
  }
@@ -1,7 +1,8 @@
1
+ import type { BusinessMessageCode } from '../contract/business-message-code.js';
1
2
  import type { BusinessGraphQLErrorCode } from '../contract/graphql-error-contract.js';
2
- export interface BusinessErrorOptionsInterface<TMessageCode extends string> {
3
+ export interface BusinessErrorOptionsInterface {
3
4
  code: BusinessGraphQLErrorCode;
4
- messageCode: TMessageCode;
5
+ messageCode: BusinessMessageCode;
5
6
  }
6
- export type BusinessErrorTable<TOptions> = readonly [new (...arguments_: never[]) => Error, TOptions][];
7
+ export type BusinessErrorTable<TOptions = BusinessErrorOptionsInterface> = readonly [new (...arguments_: never[]) => Error, TOptions][];
7
8
  export declare const matchBusinessError: <TOptions>(table: BusinessErrorTable<TOptions>, fallback: TOptions) => (commandError: Error) => TOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@application-kit/graphql",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Контракт ошибок GraphQL (сервер и клиент) и типы курсорного листинга для NestJS",
5
5
  "keywords": [
6
6
  "apollo",