swoop-common 1.0.27 → 1.0.29
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/api/generated/swoop/core/request.js +25 -5
- package/package.json +2 -2
- package/dist/api/gen.d.ts +0 -1
- package/dist/api/gen.js +0 -49
|
@@ -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,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
9
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
10
|
});
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
/* istanbul ignore file */
|
|
12
|
-
/* tslint:disable */
|
|
13
|
-
/* eslint-disable */
|
|
12
|
+
//@ts-nocheck
|
|
14
13
|
import { ApiError } from './ApiError';
|
|
15
14
|
import { CancelablePromise } from './CancelablePromise';
|
|
16
15
|
export const isDefined = (value) => {
|
|
@@ -235,6 +234,27 @@ export const catchErrorCodes = (options, result) => {
|
|
|
235
234
|
throw new ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
|
|
236
235
|
}
|
|
237
236
|
};
|
|
237
|
+
const unwrapHydra = (json) => {
|
|
238
|
+
const context = json["@context"];
|
|
239
|
+
// Do nothing if not hydra
|
|
240
|
+
if (!context || typeof context !== "object")
|
|
241
|
+
return json;
|
|
242
|
+
// Get keys
|
|
243
|
+
const keys = Object.keys(context);
|
|
244
|
+
if (keys.length != 3) {
|
|
245
|
+
console.log("Unexpected number of keys within hydra context:", keys);
|
|
246
|
+
return json;
|
|
247
|
+
}
|
|
248
|
+
// Get the key that is not hydra
|
|
249
|
+
const main = keys.find(s => !["@context", "hydra"].includes(s));
|
|
250
|
+
// Main WILL exist, as there are 3 keys and filter max 2
|
|
251
|
+
const data = json[main];
|
|
252
|
+
if (!data) {
|
|
253
|
+
console.log("Hydra defined key did not exist within object:", Object.keys(json));
|
|
254
|
+
return json;
|
|
255
|
+
}
|
|
256
|
+
return data;
|
|
257
|
+
};
|
|
238
258
|
/**
|
|
239
259
|
* Request method
|
|
240
260
|
* @param config The OpenAPI configuration object
|
|
@@ -251,7 +271,7 @@ export const request = (config, options) => {
|
|
|
251
271
|
const headers = yield getHeaders(config, options);
|
|
252
272
|
if (!onCancel.isCancelled) {
|
|
253
273
|
const response = yield sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
254
|
-
const responseBody = yield getResponseBody(response);
|
|
274
|
+
const responseBody = unwrapHydra(yield getResponseBody(response));
|
|
255
275
|
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
256
276
|
const result = {
|
|
257
277
|
url,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swoop-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
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");
|