swoop-common 1.0.28 → 1.0.30

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.
@@ -1,3 +1,5 @@
1
+ // DO NOT EDIT THIS FILE //
2
+ // THE IMPORTS WILL RESOLVE //
1
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,10 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
9
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
10
  });
9
11
  };
10
- /* generated using openapi-typescript-codegen -- do not edit */
11
- /* istanbul ignore file */
12
- /* tslint:disable */
13
- /* eslint-disable */
12
+ // This adds hydra unwrapping
13
+ //@ts-nocheck
14
14
  import { ApiError } from './ApiError';
15
15
  import { CancelablePromise } from './CancelablePromise';
16
16
  export const isDefined = (value) => {
@@ -235,6 +235,27 @@ export const catchErrorCodes = (options, result) => {
235
235
  throw new ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
236
236
  }
237
237
  };
238
+ const unwrapHydra = (json) => {
239
+ const context = json["@context"];
240
+ // Do nothing if not hydra
241
+ if (!context || typeof context !== "object")
242
+ return json;
243
+ // Get keys
244
+ const keys = Object.keys(context);
245
+ if (keys.length != 3) {
246
+ console.log("Unexpected number of keys within hydra context:", keys);
247
+ return json;
248
+ }
249
+ // Get the key that is not hydra
250
+ const main = keys.find(s => !["@vocab", "hydra"].includes(s));
251
+ // Main WILL exist, as there are 3 keys and filter max 2
252
+ const data = json[main];
253
+ if (!data) {
254
+ console.log("Hydra defined key did not exist within object:", Object.keys(json));
255
+ return json;
256
+ }
257
+ return data;
258
+ };
238
259
  /**
239
260
  * Request method
240
261
  * @param config The OpenAPI configuration object
@@ -251,7 +272,7 @@ export const request = (config, options) => {
251
272
  const headers = yield getHeaders(config, options);
252
273
  if (!onCancel.isCancelled) {
253
274
  const response = yield sendRequest(config, options, url, body, formData, headers, onCancel);
254
- const responseBody = yield getResponseBody(response);
275
+ const responseBody = unwrapHydra(yield getResponseBody(response));
255
276
  const responseHeader = getResponseHeader(response, options.responseHeader);
256
277
  const result = {
257
278
  url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swoop-common",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {
@@ -24,7 +24,7 @@
24
24
  "build-imports": "tsx ./src/rendering/prebuild/import.ts",
25
25
  "build-core-sdk": "npx openapi-typescript-codegen --input ./openapi/generated/core_bundled.yaml --output ./src/api/generated/core --client fetch",
26
26
  "build-itinerary-sdk": "npx openapi-typescript-codegen --input ./openapi/generated/itinerary_bundled.yaml --output ./src/api/generated/itinerary --client fetch",
27
- "build-swoop-sdk": "npx openapi-typescript-codegen --input ./openapi/swoop_service.yaml --output ./src/api/generated/swoop --client fetch --postfixModels Swoop",
27
+ "build-swoop-sdk": "npx openapi-typescript-codegen --input ./openapi/swoop_service.yaml --output ./src/api/generated/swoop --client fetch --postfixModels Swoop --request ./src/api/templates/request.ts",
28
28
  "prebuild": "npm run build-imports && npm run bundle && npm run build-sdk",
29
29
  "build-sdk-exports": "tsx ./src/api/gen.ts",
30
30
  "bundle": "",
package/dist/api/gen.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/api/gen.js DELETED
@@ -1,49 +0,0 @@
1
- import fs from "fs";
2
- import { capitalise } from "../rendering/util/string";
3
- // Really quick gen file dont judge
4
- // Considering making a fork of the codegen lib instead of this
5
- // Export into one file, so i can export entire file out of the swoop lib
6
- const buildExports = (sdk, excludeCoreTypes, excludeServiceTypes, exclude) => {
7
- const existing = fs.readFileSync(`./src/api/generated/${sdk}/index.ts`, "utf-8");
8
- const out = ["// GENERATED FILE DO NOT EDIT //", ""];
9
- const lines = existing.split("\n");
10
- lines.forEach(l => {
11
- if (!l.startsWith("export"))
12
- return;
13
- // Dont export service
14
- if (l.includes("Service }"))
15
- return;
16
- // Dont export openApi or openapi config
17
- if (l.includes("{ OpenAPI }"))
18
- return;
19
- if (l.includes("{ OpenAPIConfig }"))
20
- return;
21
- if (excludeCoreTypes && l.includes("{ ApiError }"))
22
- return;
23
- if (excludeCoreTypes && l.includes("{ CancelablePromise, CancelError }"))
24
- return;
25
- if (exclude === null || exclude === void 0 ? void 0 : exclude.some(e => l.includes(e)))
26
- return;
27
- if (sdk === "swoop" && l.includes(" as ")) {
28
- l = l.split(" as ")[0] + "Swoop } from './index;'";
29
- }
30
- if (excludeServiceTypes && !l.includes(`${sdk[0].toUpperCase()}${sdk.slice(1, sdk.length)}Service`))
31
- return;
32
- out.push(l.replace(/'(.*?)'/g, "'./index'"));
33
- });
34
- const file = out.join("\n");
35
- fs.writeFileSync(`./src/api/generated/${sdk}/exports.ts`, file);
36
- };
37
- // Edits the class to ensure all methods are not static (so it can be instanced)
38
- const makeNotStatic = (sdk) => {
39
- const existing = fs.readFileSync(`./src/api/generated/${sdk}/services/${capitalise(sdk)}Service.ts`, "utf-8");
40
- // Replace static with nothing
41
- const clean = existing.replace(/public static/g, "public");
42
- fs.writeFileSync(`./src/api/generated/${sdk}/services/${capitalise(sdk)}Service.ts`, clean);
43
- };
44
- buildExports("core", false, false, ["{ Traveller }"]);
45
- buildExports("itinerary", true, true);
46
- buildExports("swoop", true, false);
47
- makeNotStatic("core");
48
- makeNotStatic("itinerary");
49
- makeNotStatic("swoop");