sofa-api 0.16.3 → 0.17.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/ast.d.ts +7 -7
- package/common.d.ts +2 -2
- package/index.d.ts +5 -3
- package/index.js +994 -918
- package/index.mjs +995 -919
- package/logger.d.ts +6 -6
- package/open-api/index.d.ts +26 -26
- package/open-api/operations.d.ts +29 -11
- package/open-api/types.d.ts +7 -7
- package/open-api/utils.d.ts +3 -3
- package/package.json +4 -4
- package/parse.d.ts +6 -6
- package/router.d.ts +16 -13
- package/sofa.d.ts +58 -50
- package/subscriptions.d.ts +33 -33
- package/types.d.ts +15 -16
package/logger.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const logger: {
|
|
2
|
-
error: (...args: any[]) => void;
|
|
3
|
-
warn: (...args: any[]) => void;
|
|
4
|
-
info: (...args: any[]) => void;
|
|
5
|
-
debug: (...args: any[]) => void;
|
|
6
|
-
};
|
|
1
|
+
export declare const logger: {
|
|
2
|
+
error: (...args: any[]) => void;
|
|
3
|
+
warn: (...args: any[]) => void;
|
|
4
|
+
info: (...args: any[]) => void;
|
|
5
|
+
debug: (...args: any[]) => void;
|
|
6
|
+
};
|
package/open-api/index.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { RouteInfo } from '../types';
|
|
3
|
-
import { OpenAPIV3 } from 'openapi-types';
|
|
4
|
-
export declare function OpenAPI({ schema, info, servers, components, security, tags, customScalars, }: {
|
|
5
|
-
schema: GraphQLSchema;
|
|
6
|
-
info: OpenAPIV3.InfoObject;
|
|
7
|
-
servers?: OpenAPIV3.ServerObject[];
|
|
8
|
-
components?: Record<string, any>;
|
|
9
|
-
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
10
|
-
tags?: OpenAPIV3.TagObject[];
|
|
11
|
-
/**
|
|
12
|
-
* Override mapping of custom scalars to OpenAPI
|
|
13
|
-
* @example
|
|
14
|
-
* ```js
|
|
15
|
-
* {
|
|
16
|
-
* Date: { type: "string", format: "date" }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
customScalars?: Record<string, any>;
|
|
21
|
-
}): {
|
|
22
|
-
addRoute(info: RouteInfo, config?: {
|
|
23
|
-
basePath?: string;
|
|
24
|
-
}): void;
|
|
25
|
-
get(): OpenAPIV3.Document<{}>;
|
|
26
|
-
};
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { RouteInfo } from '../types';
|
|
3
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
4
|
+
export declare function OpenAPI({ schema, info, servers, components, security, tags, customScalars, }: {
|
|
5
|
+
schema: GraphQLSchema;
|
|
6
|
+
info: OpenAPIV3.InfoObject;
|
|
7
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
8
|
+
components?: Record<string, any>;
|
|
9
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
10
|
+
tags?: OpenAPIV3.TagObject[];
|
|
11
|
+
/**
|
|
12
|
+
* Override mapping of custom scalars to OpenAPI
|
|
13
|
+
* @example
|
|
14
|
+
* ```js
|
|
15
|
+
* {
|
|
16
|
+
* Date: { type: "string", format: "date" }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
customScalars?: Record<string, any>;
|
|
21
|
+
}): {
|
|
22
|
+
addRoute(info: RouteInfo, config?: {
|
|
23
|
+
basePath?: string;
|
|
24
|
+
}): void;
|
|
25
|
+
get(): OpenAPIV3.Document<{}>;
|
|
26
|
+
};
|
package/open-api/operations.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
|
-
import { OpenAPIV3 } from 'openapi-types';
|
|
3
|
-
export declare function buildPathFromOperation({ url, schema, operation, useRequestBody, tags, description, customScalars, }: {
|
|
4
|
-
url: string;
|
|
5
|
-
schema: GraphQLSchema;
|
|
6
|
-
operation: DocumentNode;
|
|
7
|
-
useRequestBody: boolean;
|
|
8
|
-
tags?: string[];
|
|
9
|
-
description?: string;
|
|
10
|
-
customScalars: Record<string, any>;
|
|
11
|
-
}): OpenAPIV3.OperationObject;
|
|
1
|
+
import { DocumentNode, GraphQLSchema, OperationDefinitionNode, TypeNode, VariableDefinitionNode } from 'graphql';
|
|
2
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
3
|
+
export declare function buildPathFromOperation({ url, schema, operation, useRequestBody, tags, description, customScalars, }: {
|
|
4
|
+
url: string;
|
|
5
|
+
schema: GraphQLSchema;
|
|
6
|
+
operation: DocumentNode;
|
|
7
|
+
useRequestBody: boolean;
|
|
8
|
+
tags?: string[];
|
|
9
|
+
description?: string;
|
|
10
|
+
customScalars: Record<string, any>;
|
|
11
|
+
}): OpenAPIV3.OperationObject;
|
|
12
|
+
export declare function resolveRequestBody(variables: ReadonlyArray<VariableDefinitionNode> | undefined, schema: GraphQLSchema, operation: OperationDefinitionNode, opts: {
|
|
13
|
+
customScalars: Record<string, any>;
|
|
14
|
+
enumTypes: Record<string, any>;
|
|
15
|
+
}): {};
|
|
16
|
+
export declare function resolveParamSchema(type: TypeNode, opts: {
|
|
17
|
+
customScalars: Record<string, any>;
|
|
18
|
+
enumTypes: Record<string, any>;
|
|
19
|
+
}): any;
|
|
20
|
+
export declare function resolveResponse({ schema, operation, opts, }: {
|
|
21
|
+
schema: GraphQLSchema;
|
|
22
|
+
operation: OperationDefinitionNode;
|
|
23
|
+
opts: {
|
|
24
|
+
customScalars: Record<string, any>;
|
|
25
|
+
enumTypes: Record<string, any>;
|
|
26
|
+
};
|
|
27
|
+
}): any;
|
|
28
|
+
export declare function isInPath(url: string, param: string): boolean;
|
|
29
|
+
export declare function resolveVariableDescription(schema: GraphQLSchema, operation: OperationDefinitionNode, variable: VariableDefinitionNode): string | undefined;
|
package/open-api/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GraphQLObjectType, GraphQLInputObjectType, GraphQLType } from 'graphql';
|
|
2
|
-
export declare function buildSchemaObjectFromType(type: GraphQLObjectType | GraphQLInputObjectType, opts: {
|
|
3
|
-
customScalars: Record<string, any>;
|
|
4
|
-
}): any;
|
|
5
|
-
export declare function resolveFieldType(type: GraphQLType, opts: {
|
|
6
|
-
customScalars: Record<string, any>;
|
|
7
|
-
}): any;
|
|
1
|
+
import { GraphQLObjectType, GraphQLInputObjectType, GraphQLType } from 'graphql';
|
|
2
|
+
export declare function buildSchemaObjectFromType(type: GraphQLObjectType | GraphQLInputObjectType, opts: {
|
|
3
|
+
customScalars: Record<string, any>;
|
|
4
|
+
}): any;
|
|
5
|
+
export declare function resolveFieldType(type: GraphQLType, opts: {
|
|
6
|
+
customScalars: Record<string, any>;
|
|
7
|
+
}): any;
|
package/open-api/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function mapToPrimitive(type: string): any;
|
|
2
|
-
export declare function mapToRef(type: string): string;
|
|
3
|
-
export declare function normalizePathParamForOpenAPI(path: string): string;
|
|
1
|
+
export declare function mapToPrimitive(type: string): any;
|
|
2
|
+
export declare function mapToRef(type: string): string;
|
|
3
|
+
export declare function normalizePathParamForOpenAPI(path: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sofa-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Create REST APIs with GraphQL",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-tools/utils": "^9.2.0",
|
|
11
|
-
"@whatwg-node/fetch": "^0.
|
|
12
|
-
"@whatwg-node/router": "^0.2.0",
|
|
11
|
+
"@whatwg-node/fetch": "^0.8.0",
|
|
13
12
|
"ansi-colors": "^4.1.3",
|
|
13
|
+
"fets": "^0.1.4",
|
|
14
14
|
"openapi-types": "^12.1.0",
|
|
15
15
|
"param-case": "^3.0.4",
|
|
16
16
|
"title-case": "^3.0.3",
|
|
@@ -49,4 +49,4 @@
|
|
|
49
49
|
},
|
|
50
50
|
"./package.json": "./package.json"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|
package/parse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { VariableDefinitionNode, GraphQLSchema } from 'graphql';
|
|
2
|
-
export declare function parseVariable({ value, variable, schema, }: {
|
|
3
|
-
value: any;
|
|
4
|
-
variable: VariableDefinitionNode;
|
|
5
|
-
schema: GraphQLSchema;
|
|
6
|
-
}): any;
|
|
1
|
+
import { VariableDefinitionNode, GraphQLSchema } from 'graphql';
|
|
2
|
+
export declare function parseVariable({ value, variable, schema, }: {
|
|
3
|
+
value: any;
|
|
4
|
+
variable: VariableDefinitionNode;
|
|
5
|
+
schema: GraphQLSchema;
|
|
6
|
+
}): any;
|
package/router.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { Sofa } from './sofa';
|
|
2
|
-
import { Router } from '
|
|
3
|
-
export type ErrorHandler = (errors: ReadonlyArray<any>) => Response;
|
|
4
|
-
declare module 'graphql' {
|
|
5
|
-
interface GraphQLHTTPErrorExtensions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
import type { Sofa } from './sofa';
|
|
2
|
+
import { Response, Router } from 'fets';
|
|
3
|
+
export type ErrorHandler = (errors: ReadonlyArray<any>) => Response;
|
|
4
|
+
declare module 'graphql' {
|
|
5
|
+
interface GraphQLHTTPErrorExtensions {
|
|
6
|
+
spec?: boolean;
|
|
7
|
+
status?: number;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
interface GraphQLErrorExtensions {
|
|
11
|
+
http?: GraphQLHTTPErrorExtensions;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare function createRouter(sofa: Sofa): Router<any, {}, {
|
|
15
|
+
[TKey: string]: never;
|
|
16
|
+
}>;
|
package/sofa.d.ts
CHANGED
|
@@ -1,50 +1,58 @@
|
|
|
1
|
-
import { GraphQLSchema, subscribe, execute } from 'graphql';
|
|
2
|
-
import { Ignore,
|
|
3
|
-
import { ErrorHandler } from './router';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
depthLimit?: number;
|
|
28
|
-
errorHandler?: ErrorHandler;
|
|
29
|
-
/**
|
|
30
|
-
* Overwrites the default HTTP route.
|
|
31
|
-
*/
|
|
32
|
-
routes?: Record<string, RouteConfig>;
|
|
33
|
-
context?: ContextFn | ContextValue;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
import { GraphQLSchema, subscribe, execute } from 'graphql';
|
|
2
|
+
import { Ignore, ContextFn, ContextValue } from './types';
|
|
3
|
+
import { ErrorHandler } from './router';
|
|
4
|
+
import { HTTPMethod, StatusCode } from 'fets/typings/typed-fetch';
|
|
5
|
+
export interface RouteConfig {
|
|
6
|
+
method?: HTTPMethod;
|
|
7
|
+
path?: string;
|
|
8
|
+
responseStatus?: StatusCode;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Route {
|
|
13
|
+
method: HTTPMethod;
|
|
14
|
+
path: string;
|
|
15
|
+
responseStatus: StatusCode;
|
|
16
|
+
}
|
|
17
|
+
export interface SofaConfig {
|
|
18
|
+
basePath: string;
|
|
19
|
+
schema: GraphQLSchema;
|
|
20
|
+
execute?: typeof execute;
|
|
21
|
+
subscribe?: typeof subscribe;
|
|
22
|
+
/**
|
|
23
|
+
* Treats an Object with an ID as not a model.
|
|
24
|
+
* @example ["User", "Message.author"]
|
|
25
|
+
*/
|
|
26
|
+
ignore?: Ignore;
|
|
27
|
+
depthLimit?: number;
|
|
28
|
+
errorHandler?: ErrorHandler;
|
|
29
|
+
/**
|
|
30
|
+
* Overwrites the default HTTP route.
|
|
31
|
+
*/
|
|
32
|
+
routes?: Record<string, RouteConfig>;
|
|
33
|
+
context?: ContextFn | ContextValue;
|
|
34
|
+
customScalars?: Record<string, any>;
|
|
35
|
+
enumTypes?: Record<string, any>;
|
|
36
|
+
title?: string;
|
|
37
|
+
version?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface Sofa {
|
|
41
|
+
basePath: string;
|
|
42
|
+
schema: GraphQLSchema;
|
|
43
|
+
models: string[];
|
|
44
|
+
ignore: Ignore;
|
|
45
|
+
depthLimit: number;
|
|
46
|
+
routes?: Record<string, RouteConfig>;
|
|
47
|
+
execute: typeof execute;
|
|
48
|
+
subscribe: typeof subscribe;
|
|
49
|
+
errorHandler?: ErrorHandler;
|
|
50
|
+
contextFactory: ContextFn;
|
|
51
|
+
customScalars: Record<string, any>;
|
|
52
|
+
enumTypes: Record<string, any>;
|
|
53
|
+
title?: string;
|
|
54
|
+
version?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
}
|
|
57
|
+
export declare function createSofa(config: SofaConfig): Sofa;
|
|
58
|
+
export declare function isContextFn(context: any): context is ContextFn;
|
package/subscriptions.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { ExecutionResult } from 'graphql';
|
|
2
|
-
import type { ContextValue } from './types';
|
|
3
|
-
import type { Sofa } from './sofa';
|
|
4
|
-
export type ID = string;
|
|
5
|
-
export type SubscriptionFieldName = string;
|
|
6
|
-
export interface StartSubscriptionEvent {
|
|
7
|
-
subscription: SubscriptionFieldName;
|
|
8
|
-
variables: any;
|
|
9
|
-
url: string;
|
|
10
|
-
}
|
|
11
|
-
export interface UpdateSubscriptionEvent {
|
|
12
|
-
id: ID;
|
|
13
|
-
variables: any;
|
|
14
|
-
}
|
|
15
|
-
export interface StopSubscriptionResponse {
|
|
16
|
-
id: ID;
|
|
17
|
-
}
|
|
18
|
-
export declare class SubscriptionManager {
|
|
19
|
-
private sofa;
|
|
20
|
-
private operations;
|
|
21
|
-
private clients;
|
|
22
|
-
constructor(sofa: Sofa);
|
|
23
|
-
start(event: StartSubscriptionEvent, contextValue: ContextValue): Promise<ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | {
|
|
24
|
-
id: string
|
|
25
|
-
}>;
|
|
26
|
-
stop(id: ID): Promise<StopSubscriptionResponse>;
|
|
27
|
-
update(event: UpdateSubscriptionEvent, contextValue: ContextValue): Promise<ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | {
|
|
28
|
-
id: string
|
|
29
|
-
}>;
|
|
30
|
-
private execute;
|
|
31
|
-
private sendData;
|
|
32
|
-
private buildOperations;
|
|
33
|
-
}
|
|
1
|
+
import { ExecutionResult } from 'graphql';
|
|
2
|
+
import type { ContextValue } from './types';
|
|
3
|
+
import type { Sofa } from './sofa';
|
|
4
|
+
export type ID = string;
|
|
5
|
+
export type SubscriptionFieldName = string;
|
|
6
|
+
export interface StartSubscriptionEvent {
|
|
7
|
+
subscription: SubscriptionFieldName;
|
|
8
|
+
variables: any;
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
export interface UpdateSubscriptionEvent {
|
|
12
|
+
id: ID;
|
|
13
|
+
variables: any;
|
|
14
|
+
}
|
|
15
|
+
export interface StopSubscriptionResponse {
|
|
16
|
+
id: ID;
|
|
17
|
+
}
|
|
18
|
+
export declare class SubscriptionManager {
|
|
19
|
+
private sofa;
|
|
20
|
+
private operations;
|
|
21
|
+
private clients;
|
|
22
|
+
constructor(sofa: Sofa);
|
|
23
|
+
start(event: StartSubscriptionEvent, contextValue: ContextValue): Promise<ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | {
|
|
24
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
25
|
+
}>;
|
|
26
|
+
stop(id: ID): Promise<StopSubscriptionResponse>;
|
|
27
|
+
update(event: UpdateSubscriptionEvent, contextValue: ContextValue): Promise<ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>> | {
|
|
28
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
29
|
+
}>;
|
|
30
|
+
private execute;
|
|
31
|
+
private sendData;
|
|
32
|
+
private buildOperations;
|
|
33
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export interface RouteInfo {
|
|
6
|
-
document: DocumentNode;
|
|
7
|
-
path: string;
|
|
8
|
-
method:
|
|
9
|
-
tags?: string[];
|
|
10
|
-
description?: string;
|
|
11
|
-
}
|
|
12
|
-
export type
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
1
|
+
import { HTTPMethod } from 'fets/typings/typed-fetch';
|
|
2
|
+
import { DocumentNode } from 'graphql';
|
|
3
|
+
export type ContextValue = Record<string, any>;
|
|
4
|
+
export type Ignore = string[];
|
|
5
|
+
export interface RouteInfo {
|
|
6
|
+
document: DocumentNode;
|
|
7
|
+
path: string;
|
|
8
|
+
method: HTTPMethod;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
export type ContextFn = (serverContext: DefaultSofaServerContext) => Promise<ContextValue> | ContextValue;
|
|
13
|
+
export type DefaultSofaServerContext = {
|
|
14
|
+
request: Request;
|
|
15
|
+
};
|