@sdkgen/node-runtime 1.6.2 → 2.0.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/dist/src/index.js CHANGED
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./api-config"), exports);
14
- __exportStar(require("./context"), exports);
15
- __exportStar(require("./encode-decode"), exports);
16
- __exportStar(require("./error"), exports);
17
- __exportStar(require("./http-client"), exports);
18
- __exportStar(require("./http-server"), exports);
19
- __exportStar(require("./test-wrapper"), exports);
3
+ exports.apiTestWrapper = exports.SdkgenHttpServer = exports.SdkgenHttpClient = exports.SdkgenErrorWithData = exports.SdkgenError = exports.Fatal = exports.encode = exports.decode = exports.BaseApiConfig = void 0;
4
+ var api_config_1 = require("./api-config");
5
+ Object.defineProperty(exports, "BaseApiConfig", { enumerable: true, get: function () { return api_config_1.BaseApiConfig; } });
6
+ var encode_decode_1 = require("./encode-decode");
7
+ Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return encode_decode_1.decode; } });
8
+ Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return encode_decode_1.encode; } });
9
+ var error_1 = require("./error");
10
+ Object.defineProperty(exports, "Fatal", { enumerable: true, get: function () { return error_1.Fatal; } });
11
+ Object.defineProperty(exports, "SdkgenError", { enumerable: true, get: function () { return error_1.SdkgenError; } });
12
+ Object.defineProperty(exports, "SdkgenErrorWithData", { enumerable: true, get: function () { return error_1.SdkgenErrorWithData; } });
13
+ var http_client_1 = require("./http-client");
14
+ Object.defineProperty(exports, "SdkgenHttpClient", { enumerable: true, get: function () { return http_client_1.SdkgenHttpClient; } });
15
+ var http_server_1 = require("./http-server");
16
+ Object.defineProperty(exports, "SdkgenHttpServer", { enumerable: true, get: function () { return http_server_1.SdkgenHttpServer; } });
17
+ var test_wrapper_1 = require("./test-wrapper");
18
+ Object.defineProperty(exports, "apiTestWrapper", { enumerable: true, get: function () { return test_wrapper_1.apiTestWrapper; } });
@@ -7,7 +7,7 @@ exports.setupSwagger = void 0;
7
7
  const parser_1 = require("@sdkgen/parser");
8
8
  const serve_handler_1 = __importDefault(require("serve-handler"));
9
9
  const swagger_ui_dist_1 = require("swagger-ui-dist");
10
- const swaggerUiAssetPath = swagger_ui_dist_1.getAbsoluteFSPath();
10
+ const swaggerUiAssetPath = (0, swagger_ui_dist_1.getAbsoluteFSPath)();
11
11
  function objectFromEntries(entries) {
12
12
  return Object.assign({}, ...Array.from(entries, ([k, v]) => ({ [k]: v })));
13
13
  }
@@ -206,7 +206,7 @@ function setupSwagger(server) {
206
206
  req.url = req.url.replace(/\/swagger/u, "");
207
207
  }
208
208
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
209
- serve_handler_1.default(req, res, {
209
+ (0, serve_handler_1.default)(req, res, {
210
210
  cleanUrls: false,
211
211
  directoryListing: false,
212
212
  etag: true,
@@ -226,6 +226,7 @@ function setupSwagger(server) {
226
226
  }
227
227
  try {
228
228
  const definitions = {};
229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
230
  const paths = {};
230
231
  for (const op of server.apiConfig.ast.operations) {
231
232
  for (const ann of op.annotations) {
@@ -336,17 +337,22 @@ function setupSwagger(server) {
336
337
  content: {
337
338
  "application/json": {
338
339
  schema: {
339
- properties: {
340
- message: {
341
- type: "string",
342
- },
343
- type: {
344
- enum: server.apiConfig.ast.errors,
345
- type: "string",
346
- },
347
- },
348
- required: ["type", "message"],
349
- type: "object",
340
+ anyOf: [
341
+ server.apiConfig.ast.errors.map(error => ({
342
+ properties: Object.assign({ message: {
343
+ type: "string",
344
+ }, type: {
345
+ enum: [error.name],
346
+ type: "string",
347
+ } }, (error.dataType instanceof parser_1.VoidPrimitiveType
348
+ ? {}
349
+ : {
350
+ data: typeToSchema(definitions, error.dataType),
351
+ })),
352
+ required: ["type", "message"],
353
+ type: "object",
354
+ })),
355
+ ],
350
356
  },
351
357
  },
352
358
  },
@@ -15,12 +15,12 @@ function apiTestWrapper(api) {
15
15
  for (const functionName of Object.keys(api.astJson.functionTable)) {
16
16
  wrappedApi.fn[functionName] = async (ctx, args) => {
17
17
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
18
- const encodedArgs = encode_decode_1.encode(api.astJson.typeTable, `fn.${functionName}.args`, api.astJson.functionTable[functionName].args, args);
18
+ const encodedArgs = (0, encode_decode_1.encode)(api.astJson.typeTable, `fn.${functionName}.args`, api.astJson.functionTable[functionName].args, args);
19
19
  ctx.request = {
20
20
  args: encodedArgs,
21
21
  deviceInfo: (_b = (_a = ctx.request) === null || _a === void 0 ? void 0 : _a.deviceInfo) !== null && _b !== void 0 ? _b : {
22
22
  fingerprint: null,
23
- id: crypto_1.randomBytes(16).toString("hex"),
23
+ id: (0, crypto_1.randomBytes)(16).toString("hex"),
24
24
  language: null,
25
25
  platform: null,
26
26
  timezone: null,
@@ -30,17 +30,17 @@ function apiTestWrapper(api) {
30
30
  extra: (_d = (_c = ctx.request) === null || _c === void 0 ? void 0 : _c.extra) !== null && _d !== void 0 ? _d : {},
31
31
  files: (_f = (_e = ctx.request) === null || _e === void 0 ? void 0 : _e.files) !== null && _f !== void 0 ? _f : [],
32
32
  headers: (_h = (_g = ctx.request) === null || _g === void 0 ? void 0 : _g.headers) !== null && _h !== void 0 ? _h : {},
33
- id: (_k = (_j = ctx.request) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : crypto_1.randomBytes(16).toString("hex"),
33
+ id: (_k = (_j = ctx.request) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : (0, crypto_1.randomBytes)(16).toString("hex"),
34
34
  ip: (_m = (_l = ctx.request) === null || _l === void 0 ? void 0 : _l.ip) !== null && _m !== void 0 ? _m : "0.0.0.0",
35
35
  name: functionName,
36
36
  version: 3,
37
37
  };
38
- const reply = await execute_1.executeRequest(ctx, api);
38
+ const reply = await (0, execute_1.executeRequest)(ctx, api);
39
39
  if (reply.error) {
40
40
  throw reply.error;
41
41
  }
42
42
  else {
43
- const decodedRet = encode_decode_1.decode(api.astJson.typeTable, `fn.${functionName}.ret`, api.astJson.functionTable[functionName].ret, JSON.parse(JSON.stringify(reply.result)));
43
+ const decodedRet = (0, encode_decode_1.decode)(api.astJson.typeTable, `fn.${functionName}.ret`, api.astJson.functionTable[functionName].ret, JSON.parse(JSON.stringify(reply.result)));
44
44
  return decodedRet;
45
45
  }
46
46
  };