sofa-api 0.18.3 → 0.18.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.
package/cjs/ast.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOperationInfo = void 0;
3
+ exports.getOperationInfo = getOperationInfo;
4
4
  const graphql_1 = require("graphql");
5
5
  function getOperationInfo(doc) {
6
6
  const op = (0, graphql_1.getOperationAST)(doc, null);
@@ -13,4 +13,3 @@ function getOperationInfo(doc) {
13
13
  variables: op.variableDefinitions || [],
14
14
  };
15
15
  }
16
- exports.getOperationInfo = getOperationInfo;
package/cjs/common.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNil = exports.convertName = void 0;
3
+ exports.convertName = convertName;
4
+ exports.isNil = isNil;
4
5
  const param_case_1 = require("param-case");
5
6
  function convertName(name) {
6
7
  return (0, param_case_1.paramCase)(name);
7
8
  }
8
- exports.convertName = convertName;
9
9
  function isNil(val) {
10
10
  return val == null;
11
11
  }
12
- exports.isNil = isNil;
package/cjs/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSofa = exports.OpenAPI = void 0;
4
- const router_1 = require("./router");
5
- const sofa_1 = require("./sofa");
3
+ exports.OpenAPI = void 0;
4
+ exports.useSofa = useSofa;
5
+ const router_js_1 = require("./router.js");
6
+ const sofa_js_1 = require("./sofa.js");
6
7
  var open_api_1 = require("./open-api");
7
8
  Object.defineProperty(exports, "OpenAPI", { enumerable: true, get: function () { return open_api_1.OpenAPI; } });
8
9
  function useSofa(config) {
9
- return (0, router_1.createRouter)((0, sofa_1.createSofa)(config));
10
+ return (0, router_js_1.createRouter)((0, sofa_js_1.createSofa)(config));
10
11
  }
11
- exports.useSofa = useSofa;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenAPI = void 0;
3
+ exports.OpenAPI = OpenAPI;
4
4
  const graphql_1 = require("graphql");
5
- const types_1 = require("./types");
6
- const operations_1 = require("./operations");
7
- const utils_1 = require("./utils");
5
+ const types_js_1 = require("./types.js");
6
+ const operations_js_1 = require("./operations.js");
7
+ const utils_js_1 = require("./utils.js");
8
8
  function OpenAPI({ schema, info, servers, components, security, tags, customScalars = {}, }) {
9
9
  const types = schema.getTypeMap();
10
10
  const swagger = {
@@ -21,7 +21,7 @@ function OpenAPI({ schema, info, servers, components, security, tags, customScal
21
21
  const type = types[typeName];
22
22
  if (((0, graphql_1.isObjectType)(type) || (0, graphql_1.isInputObjectType)(type)) &&
23
23
  !(0, graphql_1.isIntrospectionType)(type)) {
24
- swagger.components.schemas[typeName] = (0, types_1.buildSchemaObjectFromType)(type, {
24
+ swagger.components.schemas[typeName] = (0, types_js_1.buildSchemaObjectFromType)(type, {
25
25
  customScalars,
26
26
  });
27
27
  }
@@ -39,12 +39,12 @@ function OpenAPI({ schema, info, servers, components, security, tags, customScal
39
39
  addRoute(info, config) {
40
40
  const basePath = config?.basePath || '';
41
41
  const path = basePath +
42
- (0, utils_1.normalizePathParamForOpenAPI)(info.path);
42
+ (0, utils_js_1.normalizePathParamForOpenAPI)(info.path);
43
43
  if (!swagger.paths[path]) {
44
44
  swagger.paths[path] = {};
45
45
  }
46
46
  const pathsObj = swagger.paths[path];
47
- pathsObj[info.method.toLowerCase()] = (0, operations_1.buildPathFromOperation)({
47
+ pathsObj[info.method.toLowerCase()] = (0, operations_js_1.buildPathFromOperation)({
48
48
  url: path,
49
49
  operation: info.document,
50
50
  schema,
@@ -59,4 +59,3 @@ function OpenAPI({ schema, info, servers, components, security, tags, customScal
59
59
  },
60
60
  };
61
61
  }
62
- exports.OpenAPI = OpenAPI;
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVariableDescription = exports.isInPath = exports.resolveResponse = exports.resolveParamSchema = exports.resolveRequestBody = exports.buildPathFromOperation = void 0;
3
+ exports.buildPathFromOperation = buildPathFromOperation;
4
+ exports.resolveRequestBody = resolveRequestBody;
5
+ exports.resolveParamSchema = resolveParamSchema;
6
+ exports.resolveResponse = resolveResponse;
7
+ exports.isInPath = isInPath;
8
+ exports.resolveVariableDescription = resolveVariableDescription;
4
9
  const graphql_1 = require("graphql");
5
- const ast_1 = require("../ast");
6
- const utils_1 = require("./utils");
7
- const types_1 = require("./types");
10
+ const ast_js_1 = require("../ast.js");
11
+ const utils_js_1 = require("./utils.js");
12
+ const types_js_1 = require("./types.js");
8
13
  const title_case_1 = require("title-case");
9
14
  function buildPathFromOperation({ url, schema, operation, useRequestBody, tags, description, customScalars, }) {
10
- const info = (0, ast_1.getOperationInfo)(operation);
15
+ const info = (0, ast_js_1.getOperationInfo)(operation);
11
16
  const enumTypes = resolveEnumTypes(schema);
12
17
  const summary = resolveDescription(schema, info.operation);
13
18
  const variables = info.operation.variableDefinitions;
@@ -48,7 +53,6 @@ function buildPathFromOperation({ url, schema, operation, useRequestBody, tags,
48
53
  },
49
54
  };
50
55
  }
51
- exports.buildPathFromOperation = buildPathFromOperation;
52
56
  function resolveEnumTypes(schema) {
53
57
  const enumTypes = Object.values(schema.getTypeMap())
54
58
  .filter(graphql_1.isEnumType);
@@ -95,7 +99,6 @@ function resolveRequestBody(variables, schema, operation, opts) {
95
99
  ...(required.length ? { required } : {}),
96
100
  };
97
101
  }
98
- exports.resolveRequestBody = resolveRequestBody;
99
102
  // array -> [type]
100
103
  // type -> $ref
101
104
  // scalar -> swagger primitive
@@ -109,12 +112,11 @@ function resolveParamSchema(type, opts) {
109
112
  items: resolveParamSchema(type.type, opts),
110
113
  };
111
114
  }
112
- const primitive = (0, utils_1.mapToPrimitive)(type.name.value);
115
+ const primitive = (0, utils_js_1.mapToPrimitive)(type.name.value);
113
116
  return (primitive ||
114
117
  opts.customScalars[type.name.value] ||
115
- opts.enumTypes[type.name.value] || { $ref: (0, utils_1.mapToRef)(type.name.value) });
118
+ opts.enumTypes[type.name.value] || { $ref: (0, utils_js_1.mapToRef)(type.name.value) });
116
119
  }
117
- exports.resolveParamSchema = resolveParamSchema;
118
120
  function resolveResponse({ schema, operation, opts, }) {
119
121
  const operationType = operation.operation;
120
122
  const rootField = operation.selectionSet.selections[0];
@@ -122,20 +124,18 @@ function resolveResponse({ schema, operation, opts, }) {
122
124
  if (operationType === 'query') {
123
125
  const queryType = schema.getQueryType();
124
126
  const field = queryType.getFields()[rootField.name.value];
125
- return (0, types_1.resolveFieldType)(field.type, opts);
127
+ return (0, types_js_1.resolveFieldType)(field.type, opts);
126
128
  }
127
129
  if (operationType === 'mutation') {
128
130
  const mutationType = schema.getMutationType();
129
131
  const field = mutationType.getFields()[rootField.name.value];
130
- return (0, types_1.resolveFieldType)(field.type, opts);
132
+ return (0, types_js_1.resolveFieldType)(field.type, opts);
131
133
  }
132
134
  }
133
135
  }
134
- exports.resolveResponse = resolveResponse;
135
136
  function isInPath(url, param) {
136
137
  return url.includes(`:${param}`) || url.includes(`{${param}}`);
137
138
  }
138
- exports.isInPath = isInPath;
139
139
  function getOperationFieldNode(schema, operation) {
140
140
  const selection = operation.selectionSet.selections[0];
141
141
  const fieldName = selection.name.value;
@@ -158,7 +158,6 @@ function resolveVariableDescription(schema, operation, variable) {
158
158
  const argument = fieldNode?.arguments?.find((arg) => arg.name.value === variable.variable.name.value);
159
159
  return argument?.description?.value;
160
160
  }
161
- exports.resolveVariableDescription = resolveVariableDescription;
162
161
  function isObjectTypeDefinitionNode(node) {
163
162
  return node.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION;
164
163
  }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveFieldType = exports.buildSchemaObjectFromType = void 0;
3
+ exports.buildSchemaObjectFromType = buildSchemaObjectFromType;
4
+ exports.resolveFieldType = resolveFieldType;
4
5
  const graphql_1 = require("graphql");
5
- const utils_1 = require("./utils");
6
+ const utils_js_1 = require("./utils.js");
6
7
  function buildSchemaObjectFromType(type, opts) {
7
8
  const required = [];
8
9
  const properties = {};
@@ -24,7 +25,6 @@ function buildSchemaObjectFromType(type, opts) {
24
25
  ...(type.description ? { description: type.description } : {}),
25
26
  };
26
27
  }
27
- exports.buildSchemaObjectFromType = buildSchemaObjectFromType;
28
28
  function resolveField(field, opts) {
29
29
  return resolveFieldType(field.type, opts);
30
30
  }
@@ -43,11 +43,11 @@ function resolveFieldType(type, opts) {
43
43
  }
44
44
  if ((0, graphql_1.isObjectType)(type)) {
45
45
  return {
46
- $ref: (0, utils_1.mapToRef)(type.name),
46
+ $ref: (0, utils_js_1.mapToRef)(type.name),
47
47
  };
48
48
  }
49
49
  if ((0, graphql_1.isScalarType)(type)) {
50
- const resolved = (0, utils_1.mapToPrimitive)(type.name) ||
50
+ const resolved = (0, utils_js_1.mapToPrimitive)(type.name) ||
51
51
  opts.customScalars[type.name] ||
52
52
  type.extensions?.jsonSchema || {
53
53
  type: 'object',
@@ -69,4 +69,3 @@ function resolveFieldType(type, opts) {
69
69
  type: 'object',
70
70
  };
71
71
  }
72
- exports.resolveFieldType = resolveFieldType;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizePathParamForOpenAPI = exports.mapToRef = exports.mapToPrimitive = void 0;
3
+ exports.mapToPrimitive = mapToPrimitive;
4
+ exports.mapToRef = mapToRef;
5
+ exports.normalizePathParamForOpenAPI = normalizePathParamForOpenAPI;
4
6
  function mapToPrimitive(type) {
5
7
  const formatMap = {
6
8
  Int: {
@@ -25,11 +27,9 @@ function mapToPrimitive(type) {
25
27
  return formatMap[type];
26
28
  }
27
29
  }
28
- exports.mapToPrimitive = mapToPrimitive;
29
30
  function mapToRef(type) {
30
31
  return `#/components/schemas/${type}`;
31
32
  }
32
- exports.mapToRef = mapToRef;
33
33
  function normalizePathParamForOpenAPI(path) {
34
34
  const pathParts = path.split('/');
35
35
  const normalizedPathParts = pathParts.map((part) => {
@@ -40,4 +40,3 @@ function normalizePathParamForOpenAPI(path) {
40
40
  });
41
41
  return normalizedPathParts.join('/');
42
42
  }
43
- exports.normalizePathParamForOpenAPI = normalizePathParamForOpenAPI;
package/cjs/parse.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseVariable = void 0;
3
+ exports.parseVariable = parseVariable;
4
4
  const graphql_1 = require("graphql");
5
5
  const common_js_1 = require("./common.js");
6
6
  function parseVariable({ value, variable, schema, }) {
@@ -13,7 +13,6 @@ function parseVariable({ value, variable, schema, }) {
13
13
  schema,
14
14
  });
15
15
  }
16
- exports.parseVariable = parseVariable;
17
16
  function resolveVariable({ value, type, schema, }) {
18
17
  if (type.kind === graphql_1.Kind.NAMED_TYPE) {
19
18
  const namedType = schema.getType(type.name.value);
package/cjs/router.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRouter = void 0;
3
+ exports.createRouter = createRouter;
4
4
  const graphql_1 = require("graphql");
5
5
  const utils_1 = require("@graphql-tools/utils");
6
6
  const ast_js_1 = require("./ast.js");
7
- const common_1 = require("./common");
7
+ const common_js_1 = require("./common.js");
8
8
  const parse_js_1 = require("./parse.js");
9
9
  const subscriptions_js_1 = require("./subscriptions.js");
10
10
  const logger_js_1 = require("./logger.js");
@@ -157,7 +157,6 @@ function createRouter(sofa) {
157
157
  });
158
158
  return router;
159
159
  }
160
- exports.createRouter = createRouter;
161
160
  function createQueryRoute({ sofa, router, fieldName, }) {
162
161
  logger_js_1.logger.debug(`[Router] Creating ${fieldName} query`);
163
162
  const queryType = sofa.schema.getQueryType();
@@ -211,10 +210,12 @@ function createQueryRoute({ sofa, router, fieldName, }) {
211
210
  }
212
211
  function getRouteSchemas({ method, path, info, sofa, responseStatus, }) {
213
212
  const params = {
213
+ type: 'object',
214
214
  properties: {},
215
215
  required: [],
216
216
  };
217
217
  const query = {
218
+ type: 'object',
218
219
  properties: {},
219
220
  required: [],
220
221
  };
@@ -386,7 +387,7 @@ function useHandler(config) {
386
387
  };
387
388
  }
388
389
  function getPath(fieldName, hasId = false) {
389
- return `/${(0, common_1.convertName)(fieldName)}${hasId ? '/:id' : ''}`;
390
+ return `/${(0, common_js_1.convertName)(fieldName)}${hasId ? '/:id' : ''}`;
390
391
  }
391
392
  function pickParam({ name, url, params, body, }) {
392
393
  if (name in params) {
package/cjs/sofa.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isContextFn = exports.createSofa = void 0;
3
+ exports.createSofa = createSofa;
4
+ exports.isContextFn = isContextFn;
4
5
  const graphql_1 = require("graphql");
5
6
  const common_js_1 = require("./common.js");
6
7
  const logger_js_1 = require("./logger.js");
@@ -33,11 +34,9 @@ function createSofa(config) {
33
34
  ...config,
34
35
  };
35
36
  }
36
- exports.createSofa = createSofa;
37
37
  function isContextFn(context) {
38
38
  return typeof context === 'function';
39
39
  }
40
- exports.isContextFn = isContextFn;
41
40
  // Objects and Unions are the only things that are used to define return types
42
41
  // and both might contain an ID
43
42
  // We don't treat Unions as models because
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createRouter } from './router';
2
- import { createSofa } from './sofa';
1
+ import { createRouter } from './router.js';
2
+ import { createSofa } from './sofa.js';
3
3
  export { OpenAPI } from './open-api';
4
4
  export function useSofa(config) {
5
5
  return createRouter(createSofa(config));
@@ -1,7 +1,7 @@
1
1
  import { isObjectType, isInputObjectType, isIntrospectionType, } from 'graphql';
2
- import { buildSchemaObjectFromType } from './types';
3
- import { buildPathFromOperation } from './operations';
4
- import { normalizePathParamForOpenAPI } from './utils';
2
+ import { buildSchemaObjectFromType } from './types.js';
3
+ import { buildPathFromOperation } from './operations.js';
4
+ import { normalizePathParamForOpenAPI } from './utils.js';
5
5
  export function OpenAPI({ schema, info, servers, components, security, tags, customScalars = {}, }) {
6
6
  const types = schema.getTypeMap();
7
7
  const swagger = {
@@ -1,7 +1,7 @@
1
1
  import { isEnumType, Kind, parse, printType, } from 'graphql';
2
- import { getOperationInfo } from '../ast';
3
- import { mapToPrimitive, mapToRef } from './utils';
4
- import { resolveFieldType } from './types';
2
+ import { getOperationInfo } from '../ast.js';
3
+ import { mapToPrimitive, mapToRef } from './utils.js';
4
+ import { resolveFieldType } from './types.js';
5
5
  import { titleCase } from 'title-case';
6
6
  export function buildPathFromOperation({ url, schema, operation, useRequestBody, tags, description, customScalars, }) {
7
7
  const info = getOperationInfo(operation);
@@ -1,5 +1,5 @@
1
1
  import { isNonNullType, isListType, isObjectType, isScalarType, isEnumType, isUnionType, } from 'graphql';
2
- import { mapToPrimitive, mapToRef } from './utils';
2
+ import { mapToPrimitive, mapToRef } from './utils.js';
3
3
  export function buildSchemaObjectFromType(type, opts) {
4
4
  const required = [];
5
5
  const properties = {};
package/esm/router.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isObjectType, isNonNullType, Kind, isIntrospectionType, isInputObjectType, isEnumType, } from 'graphql';
2
2
  import { buildOperationNodeForField, createGraphQLError } from '@graphql-tools/utils';
3
3
  import { getOperationInfo } from './ast.js';
4
- import { convertName } from './common';
4
+ import { convertName } from './common.js';
5
5
  import { parseVariable } from './parse.js';
6
6
  import { SubscriptionManager } from './subscriptions.js';
7
7
  import { logger } from './logger.js';
@@ -207,10 +207,12 @@ function createQueryRoute({ sofa, router, fieldName, }) {
207
207
  }
208
208
  function getRouteSchemas({ method, path, info, sofa, responseStatus, }) {
209
209
  const params = {
210
+ type: 'object',
210
211
  properties: {},
211
212
  required: [],
212
213
  };
213
214
  const query = {
215
+ type: 'object',
214
216
  properties: {},
215
217
  required: [],
216
218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sofa-api",
3
- "version": "0.18.3",
3
+ "version": "0.18.6",
4
4
  "description": "Create REST APIs with GraphQL",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -9,7 +9,7 @@
9
9
  "dependencies": {
10
10
  "@graphql-tools/utils": "^10.0.0",
11
11
  "@whatwg-node/fetch": "^0.9.14",
12
- "fets": "^0.7.0",
12
+ "fets": "^0.8.0",
13
13
  "ansi-colors": "^4.1.3",
14
14
  "openapi-types": "^12.1.0",
15
15
  "param-case": "^3.0.4",
@@ -1,4 +1,4 @@
1
- import type { SofaConfig } from './sofa';
1
+ import type { SofaConfig } from './sofa.cjs';
2
2
  export { OpenAPI } from './open-api';
3
3
  export declare function useSofa(config: SofaConfig): import("fets").Router<any, {}, {
4
4
  [TKey: string]: never;
@@ -1,4 +1,4 @@
1
- import type { SofaConfig } from './sofa';
1
+ import type { SofaConfig } from './sofa.js';
2
2
  export { OpenAPI } from './open-api';
3
3
  export declare function useSofa(config: SofaConfig): import("fets").Router<any, {}, {
4
4
  [TKey: string]: never;
@@ -1,5 +1,5 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
- import { RouteInfo } from '../types';
2
+ import { RouteInfo } from '../types.cjs';
3
3
  import { OpenAPIV3 } from 'openapi-types';
4
4
  export declare function OpenAPI({ schema, info, servers, components, security, tags, customScalars, }: {
5
5
  schema: GraphQLSchema;
@@ -1,5 +1,5 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
- import { RouteInfo } from '../types';
2
+ import { RouteInfo } from '../types.js';
3
3
  import { OpenAPIV3 } from 'openapi-types';
4
4
  export declare function OpenAPI({ schema, info, servers, components, security, tags, customScalars, }: {
5
5
  schema: GraphQLSchema;
@@ -13,3 +13,8 @@ export type ContextFn = (serverContext: DefaultSofaServerContext) => Promise<Con
13
13
  export type DefaultSofaServerContext = {
14
14
  request: Request;
15
15
  };
16
+ export interface ObjectJSONSchema {
17
+ type: 'object';
18
+ properties: Record<string, any>;
19
+ required: string[];
20
+ }
@@ -13,3 +13,8 @@ export type ContextFn = (serverContext: DefaultSofaServerContext) => Promise<Con
13
13
  export type DefaultSofaServerContext = {
14
14
  request: Request;
15
15
  };
16
+ export interface ObjectJSONSchema {
17
+ type: 'object';
18
+ properties: Record<string, any>;
19
+ required: string[];
20
+ }