@sdkgen/node-runtime 1.6.1 → 2.0.1

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
  }
@@ -108,6 +108,11 @@ function typeToSchema(definitions, type) {
108
108
  type: "string",
109
109
  };
110
110
  }
111
+ else if (type instanceof parser_1.BigIntPrimitiveType) {
112
+ return {
113
+ type: "string",
114
+ };
115
+ }
111
116
  else if (type instanceof parser_1.OptionalType) {
112
117
  return {
113
118
  oneOf: [typeToSchema(definitions, type.base), { type: "null" }],
@@ -191,7 +196,7 @@ function setupSwagger(server) {
191
196
  `);
192
197
  res.end();
193
198
  });
194
- server.addHttpHandler("GET", /^\/swagger/u, (req, res) => {
199
+ server.addHttpHandler("GET", /^\/swagger.*/u, (req, res) => {
195
200
  if (!server.introspection) {
196
201
  res.statusCode = 404;
197
202
  res.end();
@@ -201,7 +206,7 @@ function setupSwagger(server) {
201
206
  req.url = req.url.replace(/\/swagger/u, "");
202
207
  }
203
208
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
204
- serve_handler_1.default(req, res, {
209
+ (0, serve_handler_1.default)(req, res, {
205
210
  cleanUrls: false,
206
211
  directoryListing: false,
207
212
  etag: true,
@@ -221,6 +226,7 @@ function setupSwagger(server) {
221
226
  }
222
227
  try {
223
228
  const definitions = {};
229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
224
230
  const paths = {};
225
231
  for (const op of server.apiConfig.ast.operations) {
226
232
  for (const ann of op.annotations) {
@@ -331,17 +337,22 @@ function setupSwagger(server) {
331
337
  content: {
332
338
  "application/json": {
333
339
  schema: {
334
- properties: {
335
- message: {
336
- type: "string",
337
- },
338
- type: {
339
- enum: server.apiConfig.ast.errors,
340
- type: "string",
341
- },
342
- },
343
- required: ["type", "message"],
344
- 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
+ ],
345
356
  },
346
357
  },
347
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
  };