sofa-api 0.16.0 → 0.16.2
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/index.d.ts +1 -1
- package/index.js +23 -6
- package/index.mjs +23 -6
- package/open-api/utils.d.ts +1 -0
- package/package.json +9 -9
- package/router.d.ts +1 -2
- package/types.d.ts +1 -2
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SofaConfig } from './sofa';
|
|
2
2
|
export { OpenAPI } from './open-api';
|
|
3
|
-
export declare function useSofa(config: SofaConfig): import("@whatwg-node/router").Router<
|
|
3
|
+
export declare function useSofa(config: SofaConfig): import("@whatwg-node/router").Router<{}>;
|
package/index.js
CHANGED
|
@@ -330,11 +330,14 @@ function createRouter(sofa) {
|
|
|
330
330
|
router$1.post('/webhook', (request, serverContext) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
331
331
|
const { subscription, variables, url } = yield request.json();
|
|
332
332
|
try {
|
|
333
|
+
const sofaContext = Object.assign(serverContext, {
|
|
334
|
+
request,
|
|
335
|
+
});
|
|
333
336
|
const result = yield subscriptionManager.start({
|
|
334
337
|
subscription,
|
|
335
338
|
variables,
|
|
336
339
|
url,
|
|
337
|
-
},
|
|
340
|
+
}, sofaContext);
|
|
338
341
|
return new router.Response(JSON.stringify(result), {
|
|
339
342
|
status: 200,
|
|
340
343
|
statusText: 'OK',
|
|
@@ -356,8 +359,10 @@ function createRouter(sofa) {
|
|
|
356
359
|
const body = yield request.json();
|
|
357
360
|
const variables = body.variables;
|
|
358
361
|
try {
|
|
359
|
-
const
|
|
360
|
-
|
|
362
|
+
const sofaContext = Object.assign(serverContext, {
|
|
363
|
+
request,
|
|
364
|
+
});
|
|
365
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
361
366
|
const result = yield subscriptionManager.update({
|
|
362
367
|
id,
|
|
363
368
|
variables,
|
|
@@ -530,8 +535,10 @@ function useHandler(config) {
|
|
|
530
535
|
}
|
|
531
536
|
});
|
|
532
537
|
}
|
|
533
|
-
const
|
|
534
|
-
|
|
538
|
+
const sofaContext = Object.assign(serverContext, {
|
|
539
|
+
request,
|
|
540
|
+
});
|
|
541
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
535
542
|
const result = yield sofa.execute({
|
|
536
543
|
schema: sofa.schema,
|
|
537
544
|
document: operation,
|
|
@@ -678,6 +685,16 @@ function mapToPrimitive(type) {
|
|
|
678
685
|
}
|
|
679
686
|
function mapToRef(type) {
|
|
680
687
|
return `#/components/schemas/${type}`;
|
|
688
|
+
}
|
|
689
|
+
function normalizePathParamForOpenAPI(path) {
|
|
690
|
+
const pathParts = path.split('/');
|
|
691
|
+
const normalizedPathParts = pathParts.map((part) => {
|
|
692
|
+
if (part.startsWith(':')) {
|
|
693
|
+
return `{${part.slice(1)}}`;
|
|
694
|
+
}
|
|
695
|
+
return part;
|
|
696
|
+
});
|
|
697
|
+
return normalizedPathParts.join('/');
|
|
681
698
|
}
|
|
682
699
|
|
|
683
700
|
function buildSchemaObjectFromType(type, opts) {
|
|
@@ -912,7 +929,7 @@ function OpenAPI({ schema, info, servers, components, security, tags, customScal
|
|
|
912
929
|
addRoute(info, config) {
|
|
913
930
|
const basePath = (config === null || config === void 0 ? void 0 : config.basePath) || '';
|
|
914
931
|
const path = basePath +
|
|
915
|
-
info.path
|
|
932
|
+
normalizePathParamForOpenAPI(info.path);
|
|
916
933
|
if (!swagger.paths[path]) {
|
|
917
934
|
swagger.paths[path] = {};
|
|
918
935
|
}
|
package/index.mjs
CHANGED
|
@@ -324,11 +324,14 @@ function createRouter(sofa) {
|
|
|
324
324
|
router.post('/webhook', (request, serverContext) => __awaiter(this, void 0, void 0, function* () {
|
|
325
325
|
const { subscription, variables, url } = yield request.json();
|
|
326
326
|
try {
|
|
327
|
+
const sofaContext = Object.assign(serverContext, {
|
|
328
|
+
request,
|
|
329
|
+
});
|
|
327
330
|
const result = yield subscriptionManager.start({
|
|
328
331
|
subscription,
|
|
329
332
|
variables,
|
|
330
333
|
url,
|
|
331
|
-
},
|
|
334
|
+
}, sofaContext);
|
|
332
335
|
return new Response(JSON.stringify(result), {
|
|
333
336
|
status: 200,
|
|
334
337
|
statusText: 'OK',
|
|
@@ -350,8 +353,10 @@ function createRouter(sofa) {
|
|
|
350
353
|
const body = yield request.json();
|
|
351
354
|
const variables = body.variables;
|
|
352
355
|
try {
|
|
353
|
-
const
|
|
354
|
-
|
|
356
|
+
const sofaContext = Object.assign(serverContext, {
|
|
357
|
+
request,
|
|
358
|
+
});
|
|
359
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
355
360
|
const result = yield subscriptionManager.update({
|
|
356
361
|
id,
|
|
357
362
|
variables,
|
|
@@ -524,8 +529,10 @@ function useHandler(config) {
|
|
|
524
529
|
}
|
|
525
530
|
});
|
|
526
531
|
}
|
|
527
|
-
const
|
|
528
|
-
|
|
532
|
+
const sofaContext = Object.assign(serverContext, {
|
|
533
|
+
request,
|
|
534
|
+
});
|
|
535
|
+
const contextValue = yield sofa.contextFactory(sofaContext);
|
|
529
536
|
const result = yield sofa.execute({
|
|
530
537
|
schema: sofa.schema,
|
|
531
538
|
document: operation,
|
|
@@ -672,6 +679,16 @@ function mapToPrimitive(type) {
|
|
|
672
679
|
}
|
|
673
680
|
function mapToRef(type) {
|
|
674
681
|
return `#/components/schemas/${type}`;
|
|
682
|
+
}
|
|
683
|
+
function normalizePathParamForOpenAPI(path) {
|
|
684
|
+
const pathParts = path.split('/');
|
|
685
|
+
const normalizedPathParts = pathParts.map((part) => {
|
|
686
|
+
if (part.startsWith(':')) {
|
|
687
|
+
return `{${part.slice(1)}}`;
|
|
688
|
+
}
|
|
689
|
+
return part;
|
|
690
|
+
});
|
|
691
|
+
return normalizedPathParts.join('/');
|
|
675
692
|
}
|
|
676
693
|
|
|
677
694
|
function buildSchemaObjectFromType(type, opts) {
|
|
@@ -906,7 +923,7 @@ function OpenAPI({ schema, info, servers, components, security, tags, customScal
|
|
|
906
923
|
addRoute(info, config) {
|
|
907
924
|
const basePath = (config === null || config === void 0 ? void 0 : config.basePath) || '';
|
|
908
925
|
const path = basePath +
|
|
909
|
-
info.path
|
|
926
|
+
normalizePathParamForOpenAPI(info.path);
|
|
910
927
|
if (!swagger.paths[path]) {
|
|
911
928
|
swagger.paths[path] = {};
|
|
912
929
|
}
|
package/open-api/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sofa-api",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Create REST APIs with GraphQL",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "9.
|
|
11
|
-
"@whatwg-node/fetch": "^0.6.
|
|
12
|
-
"@whatwg-node/router": "^0.
|
|
13
|
-
"ansi-colors": "4.1.3",
|
|
14
|
-
"openapi-types": "12.1.0",
|
|
15
|
-
"param-case": "3.0.4",
|
|
16
|
-
"title-case": "3.0.3",
|
|
17
|
-
"tslib": "2.5.0"
|
|
10
|
+
"@graphql-tools/utils": "^9.2.0",
|
|
11
|
+
"@whatwg-node/fetch": "^0.6.6",
|
|
12
|
+
"@whatwg-node/router": "^0.2.0",
|
|
13
|
+
"ansi-colors": "^4.1.3",
|
|
14
|
+
"openapi-types": "^12.1.0",
|
|
15
|
+
"param-case": "^3.0.4",
|
|
16
|
+
"title-case": "^3.0.3",
|
|
17
|
+
"tslib": "^2.5.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/router.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Sofa } from './sofa';
|
|
2
|
-
import type { DefaultSofaServerContext } from './types';
|
|
3
2
|
import { Router } from '@whatwg-node/router';
|
|
4
3
|
export type ErrorHandler = (errors: ReadonlyArray<any>) => Response;
|
|
5
4
|
declare module 'graphql' {
|
|
@@ -11,4 +10,4 @@ declare module 'graphql' {
|
|
|
11
10
|
http?: GraphQLHTTPErrorExtensions;
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
|
-
export declare function createRouter(sofa: Sofa): Router<
|
|
13
|
+
export declare function createRouter(sofa: Sofa): Router<{}>;
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DefaultServerAdapterContext } from '@whatwg-node/router';
|
|
2
1
|
import { DocumentNode } from 'graphql';
|
|
3
2
|
export type ContextValue = Record<string, any>;
|
|
4
3
|
export type Ignore = string[];
|
|
@@ -12,6 +11,6 @@ export interface RouteInfo {
|
|
|
12
11
|
}
|
|
13
12
|
export type OnRoute = (info: RouteInfo) => void;
|
|
14
13
|
export type ContextFn = (serverContext: DefaultSofaServerContext) => Promise<ContextValue> | ContextValue;
|
|
15
|
-
export type DefaultSofaServerContext =
|
|
14
|
+
export type DefaultSofaServerContext = {
|
|
16
15
|
request: Request;
|
|
17
16
|
};
|