@sdkgen/node-runtime 1.5.5 → 2.0.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.
@@ -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,
@@ -331,17 +336,22 @@ function setupSwagger(server) {
331
336
  content: {
332
337
  "application/json": {
333
338
  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",
339
+ anyOf: [
340
+ server.apiConfig.ast.errors.map(error => ({
341
+ properties: Object.assign({ message: {
342
+ type: "string",
343
+ }, type: {
344
+ enum: [error.name],
345
+ type: "string",
346
+ } }, (error.dataType instanceof parser_1.VoidPrimitiveType
347
+ ? {}
348
+ : {
349
+ data: typeToSchema(definitions, error.dataType),
350
+ })),
351
+ required: ["type", "message"],
352
+ type: "object",
353
+ })),
354
+ ],
345
355
  },
346
356
  },
347
357
  },
@@ -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
  };