refactor: separate out data structures into hoppscotch-data
This commit is contained in:
356
packages/hoppscotch-data/package-lock.json
generated
Normal file
356
packages/hoppscotch-data/package-lock.json
generated
Normal file
@@ -0,0 +1,356 @@
|
||||
{
|
||||
"name": "@hoppscotch/data",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@hoppscotch/data",
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fp-ts": "^2.11.5",
|
||||
"io-ts": "^2.2.16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.13.15",
|
||||
"rollup": "^2.60.0",
|
||||
"rollup-plugin-dts": "^4.0.1",
|
||||
"rollup-plugin-esbuild": "^4.7.2"
|
||||
}
|
||||
},
|
||||
"../../node_modules/.pnpm/esbuild@0.13.15/node_modules/esbuild": {
|
||||
"version": "0.13.15",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"esbuild": "bin/esbuild"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"esbuild-android-arm64": "0.13.15",
|
||||
"esbuild-darwin-64": "0.13.15",
|
||||
"esbuild-darwin-arm64": "0.13.15",
|
||||
"esbuild-freebsd-64": "0.13.15",
|
||||
"esbuild-freebsd-arm64": "0.13.15",
|
||||
"esbuild-linux-32": "0.13.15",
|
||||
"esbuild-linux-64": "0.13.15",
|
||||
"esbuild-linux-arm": "0.13.15",
|
||||
"esbuild-linux-arm64": "0.13.15",
|
||||
"esbuild-linux-mips64le": "0.13.15",
|
||||
"esbuild-linux-ppc64le": "0.13.15",
|
||||
"esbuild-netbsd-64": "0.13.15",
|
||||
"esbuild-openbsd-64": "0.13.15",
|
||||
"esbuild-sunos-64": "0.13.15",
|
||||
"esbuild-windows-32": "0.13.15",
|
||||
"esbuild-windows-64": "0.13.15",
|
||||
"esbuild-windows-arm64": "0.13.15"
|
||||
}
|
||||
},
|
||||
"../../node_modules/.pnpm/rollup-plugin-dts@4.0.1_rollup@2.60.0/node_modules/rollup-plugin-dts": {
|
||||
"version": "4.0.1",
|
||||
"dev": true,
|
||||
"license": "LGPL-3.0",
|
||||
"dependencies": {
|
||||
"magic-string": "^0.25.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/babel__code-frame": "^7.0.3",
|
||||
"@types/d3-drag": "^3.0.1",
|
||||
"@types/estree": "0.0.50",
|
||||
"@types/fs-extra": "^9.0.12",
|
||||
"@types/node": "^16.7.5",
|
||||
"@types/react": "^17.0.20",
|
||||
"c8": "^7.8.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "2.56.3",
|
||||
"typescript": "4.4.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=v12.22.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/Swatinem"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@babel/code-frame": "^7.14.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"rollup": "^2.56.3",
|
||||
"typescript": "^4.4.2"
|
||||
}
|
||||
},
|
||||
"../../node_modules/.pnpm/rollup-plugin-esbuild@4.7.2_esbuild@0.13.15+rollup@2.60.0/node_modules/rollup-plugin-esbuild": {
|
||||
"version": "4.7.2",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rollup/pluginutils": "^4.1.1",
|
||||
"joycon": "^3.0.1",
|
||||
"jsonc-parser": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "14.14.37",
|
||||
"esbuild": "^0.13.13",
|
||||
"jest": "^27.3.1",
|
||||
"prettier": "^2.4.1",
|
||||
"rollup": "^2.59.0",
|
||||
"ts-jest": "^27.0.7",
|
||||
"tsup": "^5.7.2",
|
||||
"typescript": "^4.4.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"esbuild": ">=0.10.1",
|
||||
"rollup": "^1.20.0 || ^2.0.0"
|
||||
}
|
||||
},
|
||||
"../../node_modules/.pnpm/rollup@2.60.0/node_modules/rollup": {
|
||||
"version": "2.60.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-alias": "^3.1.5",
|
||||
"@rollup/plugin-buble": "^0.21.3",
|
||||
"@rollup/plugin-commonjs": "^20.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.0.5",
|
||||
"@rollup/plugin-replace": "^3.0.0",
|
||||
"@rollup/plugin-typescript": "^8.2.5",
|
||||
"@rollup/pluginutils": "^4.1.1",
|
||||
"@types/node": "^10.17.60",
|
||||
"@types/require-relative": "^0.8.0",
|
||||
"@types/signal-exit": "^3.0.1",
|
||||
"@types/yargs-parser": "^20.2.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.32.0",
|
||||
"@typescript-eslint/parser": "^4.32.0",
|
||||
"acorn": "^8.5.0",
|
||||
"acorn-jsx": "^5.3.2",
|
||||
"acorn-walk": "^8.2.0",
|
||||
"buble": "^0.20.0",
|
||||
"chokidar": "^3.5.2",
|
||||
"colorette": "^1.4.0",
|
||||
"core-js": "^3.18.0",
|
||||
"date-time": "^4.0.0",
|
||||
"es5-shim": "^4.6.2",
|
||||
"es6-shim": "^0.35.6",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.24.2",
|
||||
"eslint-plugin-prettier": "^3.4.1",
|
||||
"execa": "^5.1.1",
|
||||
"fixturify": "^2.1.1",
|
||||
"hash.js": "^1.1.7",
|
||||
"husky": "^6.0.0",
|
||||
"is-reference": "^3.0.0",
|
||||
"lint-staged": "^10.5.4",
|
||||
"locate-character": "^2.0.5",
|
||||
"magic-string": "^0.25.7",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "^15.1.0",
|
||||
"pinst": "^2.1.6",
|
||||
"prettier": "^2.4.1",
|
||||
"pretty-bytes": "^5.6.0",
|
||||
"pretty-ms": "^7.0.1",
|
||||
"require-relative": "^0.8.7",
|
||||
"requirejs": "^2.3.6",
|
||||
"rollup": "^2.57.0",
|
||||
"rollup-plugin-license": "^2.5.0",
|
||||
"rollup-plugin-string": "^3.0.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-thatworks": "^1.0.4",
|
||||
"sander": "^0.6.0",
|
||||
"shx": "^0.3.3",
|
||||
"signal-exit": "^3.0.5",
|
||||
"source-map": "^0.7.3",
|
||||
"source-map-support": "^0.5.20",
|
||||
"sourcemap-codec": "^1.4.8",
|
||||
"systemjs": "^6.10.3",
|
||||
"terser": "^5.9.0",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.4.3",
|
||||
"weak-napi": "^2.0.2",
|
||||
"yargs-parser": "^20.2.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "~2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"resolved": "../../node_modules/.pnpm/esbuild@0.13.15/node_modules/esbuild",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/fp-ts": {
|
||||
"version": "2.11.5",
|
||||
"resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-2.11.5.tgz",
|
||||
"integrity": "sha512-OqlwJq1BdpB83BZXTqI+dNcA6uYk6qk4u9Cgnt64Y+XS7dwdbp/mobx8S2KXf2AXH+scNmA/UVK3SEFHR3vHZA=="
|
||||
},
|
||||
"node_modules/io-ts": {
|
||||
"version": "2.2.16",
|
||||
"resolved": "https://registry.npmjs.org/io-ts/-/io-ts-2.2.16.tgz",
|
||||
"integrity": "sha512-y5TTSa6VP6le0hhmIyN0dqEXkrZeJLeC5KApJq6VLci3UEKF80lZ+KuoUs02RhBxNWlrqSNxzfI7otLX1Euv8Q==",
|
||||
"peerDependencies": {
|
||||
"fp-ts": "^2.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup": {
|
||||
"resolved": "../../node_modules/.pnpm/rollup@2.60.0/node_modules/rollup",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/rollup-plugin-dts": {
|
||||
"resolved": "../../node_modules/.pnpm/rollup-plugin-dts@4.0.1_rollup@2.60.0/node_modules/rollup-plugin-dts",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/rollup-plugin-esbuild": {
|
||||
"resolved": "../../node_modules/.pnpm/rollup-plugin-esbuild@4.7.2_esbuild@0.13.15+rollup@2.60.0/node_modules/rollup-plugin-esbuild",
|
||||
"link": true
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"esbuild": {
|
||||
"version": "file:../../node_modules/.pnpm/esbuild@0.13.15/node_modules/esbuild",
|
||||
"requires": {
|
||||
"esbuild-android-arm64": "0.13.15",
|
||||
"esbuild-darwin-64": "0.13.15",
|
||||
"esbuild-darwin-arm64": "0.13.15",
|
||||
"esbuild-freebsd-64": "0.13.15",
|
||||
"esbuild-freebsd-arm64": "0.13.15",
|
||||
"esbuild-linux-32": "0.13.15",
|
||||
"esbuild-linux-64": "0.13.15",
|
||||
"esbuild-linux-arm": "0.13.15",
|
||||
"esbuild-linux-arm64": "0.13.15",
|
||||
"esbuild-linux-mips64le": "0.13.15",
|
||||
"esbuild-linux-ppc64le": "0.13.15",
|
||||
"esbuild-netbsd-64": "0.13.15",
|
||||
"esbuild-openbsd-64": "0.13.15",
|
||||
"esbuild-sunos-64": "0.13.15",
|
||||
"esbuild-windows-32": "0.13.15",
|
||||
"esbuild-windows-64": "0.13.15",
|
||||
"esbuild-windows-arm64": "0.13.15"
|
||||
}
|
||||
},
|
||||
"fp-ts": {
|
||||
"version": "2.11.5",
|
||||
"resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-2.11.5.tgz",
|
||||
"integrity": "sha512-OqlwJq1BdpB83BZXTqI+dNcA6uYk6qk4u9Cgnt64Y+XS7dwdbp/mobx8S2KXf2AXH+scNmA/UVK3SEFHR3vHZA=="
|
||||
},
|
||||
"io-ts": {
|
||||
"version": "2.2.16",
|
||||
"resolved": "https://registry.npmjs.org/io-ts/-/io-ts-2.2.16.tgz",
|
||||
"integrity": "sha512-y5TTSa6VP6le0hhmIyN0dqEXkrZeJLeC5KApJq6VLci3UEKF80lZ+KuoUs02RhBxNWlrqSNxzfI7otLX1Euv8Q==",
|
||||
"requires": {}
|
||||
},
|
||||
"rollup": {
|
||||
"version": "file:../../node_modules/.pnpm/rollup@2.60.0/node_modules/rollup",
|
||||
"requires": {
|
||||
"@rollup/plugin-alias": "^3.1.5",
|
||||
"@rollup/plugin-buble": "^0.21.3",
|
||||
"@rollup/plugin-commonjs": "^20.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^13.0.5",
|
||||
"@rollup/plugin-replace": "^3.0.0",
|
||||
"@rollup/plugin-typescript": "^8.2.5",
|
||||
"@rollup/pluginutils": "^4.1.1",
|
||||
"@types/node": "^10.17.60",
|
||||
"@types/require-relative": "^0.8.0",
|
||||
"@types/signal-exit": "^3.0.1",
|
||||
"@types/yargs-parser": "^20.2.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.32.0",
|
||||
"@typescript-eslint/parser": "^4.32.0",
|
||||
"acorn": "^8.5.0",
|
||||
"acorn-jsx": "^5.3.2",
|
||||
"acorn-walk": "^8.2.0",
|
||||
"buble": "^0.20.0",
|
||||
"chokidar": "^3.5.2",
|
||||
"colorette": "^1.4.0",
|
||||
"core-js": "^3.18.0",
|
||||
"date-time": "^4.0.0",
|
||||
"es5-shim": "^4.6.2",
|
||||
"es6-shim": "^0.35.6",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.24.2",
|
||||
"eslint-plugin-prettier": "^3.4.1",
|
||||
"execa": "^5.1.1",
|
||||
"fixturify": "^2.1.1",
|
||||
"fsevents": "~2.3.2",
|
||||
"hash.js": "^1.1.7",
|
||||
"husky": "^6.0.0",
|
||||
"is-reference": "^3.0.0",
|
||||
"lint-staged": "^10.5.4",
|
||||
"locate-character": "^2.0.5",
|
||||
"magic-string": "^0.25.7",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "^15.1.0",
|
||||
"pinst": "^2.1.6",
|
||||
"prettier": "^2.4.1",
|
||||
"pretty-bytes": "^5.6.0",
|
||||
"pretty-ms": "^7.0.1",
|
||||
"require-relative": "^0.8.7",
|
||||
"requirejs": "^2.3.6",
|
||||
"rollup": "^2.57.0",
|
||||
"rollup-plugin-license": "^2.5.0",
|
||||
"rollup-plugin-string": "^3.0.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-thatworks": "^1.0.4",
|
||||
"sander": "^0.6.0",
|
||||
"shx": "^0.3.3",
|
||||
"signal-exit": "^3.0.5",
|
||||
"source-map": "^0.7.3",
|
||||
"source-map-support": "^0.5.20",
|
||||
"sourcemap-codec": "^1.4.8",
|
||||
"systemjs": "^6.10.3",
|
||||
"terser": "^5.9.0",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.4.3",
|
||||
"weak-napi": "^2.0.2",
|
||||
"yargs-parser": "^20.2.9"
|
||||
}
|
||||
},
|
||||
"rollup-plugin-dts": {
|
||||
"version": "file:../../node_modules/.pnpm/rollup-plugin-dts@4.0.1_rollup@2.60.0/node_modules/rollup-plugin-dts",
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.14.5",
|
||||
"@types/babel__code-frame": "^7.0.3",
|
||||
"@types/d3-drag": "^3.0.1",
|
||||
"@types/estree": "0.0.50",
|
||||
"@types/fs-extra": "^9.0.12",
|
||||
"@types/node": "^16.7.5",
|
||||
"@types/react": "^17.0.20",
|
||||
"c8": "^7.8.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"magic-string": "^0.25.7",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "2.56.3",
|
||||
"typescript": "4.4.2"
|
||||
}
|
||||
},
|
||||
"rollup-plugin-esbuild": {
|
||||
"version": "file:../../node_modules/.pnpm/rollup-plugin-esbuild@4.7.2_esbuild@0.13.15+rollup@2.60.0/node_modules/rollup-plugin-esbuild",
|
||||
"requires": {
|
||||
"@rollup/pluginutils": "^4.1.1",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "14.14.37",
|
||||
"esbuild": "^0.13.13",
|
||||
"jest": "^27.3.1",
|
||||
"joycon": "^3.0.1",
|
||||
"jsonc-parser": "^3.0.0",
|
||||
"prettier": "^2.4.1",
|
||||
"rollup": "^2.59.0",
|
||||
"ts-jest": "^27.0.7",
|
||||
"tsup": "^5.7.2",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
packages/hoppscotch-data/package.json
Normal file
32
packages/hoppscotch-data/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@hoppscotch/data",
|
||||
"version": "0.1.0",
|
||||
"description": "Data Types, Validations and Migrations for Hoppscotch Public Data Structures",
|
||||
"main": "dist/index.js",
|
||||
"module": "true",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup src --dts",
|
||||
"prepare": "tsup src --dts"
|
||||
},
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./graphql": "./dist/graphql/index.js",
|
||||
"./rest": "./dist/rest/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hoppscotch/hoppscotch.git"
|
||||
},
|
||||
"author": "The Hoppscotch Team <support@hoppscotch.io>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hoppscotch/hoppscotch/issues"
|
||||
},
|
||||
"homepage": "https://github.com/hoppscotch/hoppscotch#readme",
|
||||
"devDependencies": {
|
||||
"tsup": "^5.9.0"
|
||||
}
|
||||
}
|
||||
36
packages/hoppscotch-data/rollup.config.js
Normal file
36
packages/hoppscotch-data/rollup.config.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import dts from 'rollup-plugin-dts'
|
||||
import esbuild from 'rollup-plugin-esbuild'
|
||||
import multi from '@rollup/plugin-multi-entry'
|
||||
|
||||
const name = require('./package.json').main.replace(/\.js$/, '')
|
||||
|
||||
const bundle = config => ({
|
||||
...config,
|
||||
input: 'src/**/*.ts',
|
||||
external: id => !/^[./]/.test(id),
|
||||
})
|
||||
|
||||
export default [
|
||||
bundle({
|
||||
plugins: [multi(), esbuild()],
|
||||
output: [
|
||||
{
|
||||
file: `${name}.js`,
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
},
|
||||
{
|
||||
file: `${name}.mjs`,
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
bundle({
|
||||
plugins: [dts()],
|
||||
output: {
|
||||
file: `${name}.d.ts`,
|
||||
format: 'es',
|
||||
},
|
||||
}),
|
||||
]
|
||||
41
packages/hoppscotch-data/src/graphql/index.ts
Normal file
41
packages/hoppscotch-data/src/graphql/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
export type GQLHeader = {
|
||||
key: string
|
||||
value: string
|
||||
active: boolean
|
||||
}
|
||||
|
||||
export type HoppGQLRequest = {
|
||||
v: number
|
||||
name: string
|
||||
url: string
|
||||
headers: GQLHeader[]
|
||||
query: string
|
||||
variables: string
|
||||
}
|
||||
|
||||
export function translateToGQLRequest(x: any): HoppGQLRequest {
|
||||
if (x.v && x.v === 1) return x
|
||||
|
||||
// Old request
|
||||
const name = x.name ?? "Untitled"
|
||||
const url = x.url ?? ""
|
||||
const headers = x.headers ?? []
|
||||
const query = x.query ?? ""
|
||||
const variables = x.variables ?? []
|
||||
|
||||
return {
|
||||
v: 1,
|
||||
name,
|
||||
url,
|
||||
headers,
|
||||
query,
|
||||
variables,
|
||||
}
|
||||
}
|
||||
|
||||
export function makeGQLRequest(x: Omit<HoppGQLRequest, "v">) {
|
||||
return {
|
||||
v: 1,
|
||||
...x,
|
||||
}
|
||||
}
|
||||
2
packages/hoppscotch-data/src/index.ts
Normal file
2
packages/hoppscotch-data/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./rest"
|
||||
export * from "./graphql"
|
||||
34
packages/hoppscotch-data/src/rest/HoppRESTAuth.ts
Normal file
34
packages/hoppscotch-data/src/rest/HoppRESTAuth.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export type HoppRESTAuthNone = {
|
||||
authType: "none"
|
||||
}
|
||||
|
||||
export type HoppRESTAuthBasic = {
|
||||
authType: "basic"
|
||||
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export type HoppRESTAuthBearer = {
|
||||
authType: "bearer"
|
||||
|
||||
token: string
|
||||
}
|
||||
|
||||
export type HoppRESTAuthOAuth2 = {
|
||||
authType: "oauth-2"
|
||||
|
||||
token: string
|
||||
oidcDiscoveryURL: string
|
||||
authURL: string
|
||||
accessTokenURL: string
|
||||
clientID: string
|
||||
scope: string
|
||||
}
|
||||
|
||||
export type HoppRESTAuth = { authActive: boolean } & (
|
||||
| HoppRESTAuthNone
|
||||
| HoppRESTAuthBasic
|
||||
| HoppRESTAuthBearer
|
||||
| HoppRESTAuthOAuth2
|
||||
)
|
||||
13
packages/hoppscotch-data/src/rest/content-types.ts
Normal file
13
packages/hoppscotch-data/src/rest/content-types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const knownContentTypes = {
|
||||
"application/json": "json",
|
||||
"application/ld+json": "json",
|
||||
"application/hal+json": "json",
|
||||
"application/vnd.api+json": "json",
|
||||
"application/xml": "xml",
|
||||
"application/x-www-form-urlencoded": "multipart",
|
||||
"multipart/form-data": "multipart",
|
||||
"text/html": "html",
|
||||
"text/plain": "plain",
|
||||
}
|
||||
|
||||
export type ValidContentTypes = keyof typeof knownContentTypes
|
||||
164
packages/hoppscotch-data/src/rest/index.ts
Normal file
164
packages/hoppscotch-data/src/rest/index.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { ValidContentTypes } from "./content-types"
|
||||
import { HoppRESTAuth } from "./HoppRESTAuth"
|
||||
|
||||
export * from "./content-types"
|
||||
export * from "./HoppRESTAuth"
|
||||
|
||||
export const RESTReqSchemaVersion = "1"
|
||||
|
||||
export type HoppRESTParam = {
|
||||
key: string
|
||||
value: string
|
||||
active: boolean
|
||||
}
|
||||
|
||||
export type HoppRESTHeader = {
|
||||
key: string
|
||||
value: string
|
||||
active: boolean
|
||||
}
|
||||
|
||||
export type FormDataKeyValue = {
|
||||
key: string
|
||||
active: boolean
|
||||
} & ({ isFile: true; value: Blob[] } | { isFile: false; value: string })
|
||||
|
||||
export type HoppRESTReqBodyFormData = {
|
||||
contentType: "multipart/form-data"
|
||||
body: FormDataKeyValue[]
|
||||
}
|
||||
|
||||
export type HoppRESTReqBody =
|
||||
| {
|
||||
contentType: Exclude<ValidContentTypes, "multipart/form-data">
|
||||
body: string
|
||||
}
|
||||
| HoppRESTReqBodyFormData
|
||||
| {
|
||||
contentType: null
|
||||
body: null
|
||||
}
|
||||
|
||||
export interface HoppRESTRequest {
|
||||
v: string
|
||||
id?: string // Firebase Firestore ID
|
||||
|
||||
name: string
|
||||
method: string
|
||||
endpoint: string
|
||||
params: HoppRESTParam[]
|
||||
headers: HoppRESTHeader[]
|
||||
preRequestScript: string
|
||||
testScript: string
|
||||
|
||||
auth: HoppRESTAuth
|
||||
|
||||
body: HoppRESTReqBody
|
||||
}
|
||||
|
||||
export function makeRESTRequest(
|
||||
x: Omit<HoppRESTRequest, "v">
|
||||
): HoppRESTRequest {
|
||||
return {
|
||||
...x,
|
||||
v: RESTReqSchemaVersion,
|
||||
}
|
||||
}
|
||||
|
||||
export function isHoppRESTRequest(x: any): x is HoppRESTRequest {
|
||||
return x && typeof x === "object" && "v" in x
|
||||
}
|
||||
|
||||
function parseRequestBody(x: any): HoppRESTReqBody {
|
||||
if (x.contentType === "application/json") {
|
||||
return {
|
||||
contentType: "application/json",
|
||||
body: x.rawParams,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
contentType: "application/json",
|
||||
body: "",
|
||||
}
|
||||
}
|
||||
|
||||
export function translateToNewRequest(x: any): HoppRESTRequest {
|
||||
if (isHoppRESTRequest(x)) {
|
||||
return x
|
||||
} else {
|
||||
// Old format
|
||||
const endpoint: string = `${x.url}${x.path}`
|
||||
|
||||
const headers: HoppRESTHeader[] = x.headers ?? []
|
||||
|
||||
// Remove old keys from params
|
||||
const params: HoppRESTParam[] = (x.params ?? []).map(
|
||||
({
|
||||
key,
|
||||
value,
|
||||
active,
|
||||
}: {
|
||||
key: string
|
||||
value: string
|
||||
active: boolean
|
||||
}) => ({
|
||||
key,
|
||||
value,
|
||||
active,
|
||||
})
|
||||
)
|
||||
|
||||
const name = x.name
|
||||
const method = x.method
|
||||
|
||||
const preRequestScript = x.preRequestScript
|
||||
const testScript = x.testScript
|
||||
|
||||
const body = parseRequestBody(x)
|
||||
|
||||
const auth = parseOldAuth(x)
|
||||
|
||||
const result: HoppRESTRequest = {
|
||||
name,
|
||||
endpoint,
|
||||
headers,
|
||||
params,
|
||||
method,
|
||||
preRequestScript,
|
||||
testScript,
|
||||
body,
|
||||
auth,
|
||||
v: RESTReqSchemaVersion,
|
||||
}
|
||||
|
||||
if (x.id) result.id = x.id
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export function parseOldAuth(x: any): HoppRESTAuth {
|
||||
if (!x.auth || x.auth === "None")
|
||||
return {
|
||||
authType: "none",
|
||||
authActive: true,
|
||||
}
|
||||
|
||||
if (x.auth === "Basic Auth")
|
||||
return {
|
||||
authType: "basic",
|
||||
authActive: true,
|
||||
username: x.httpUser,
|
||||
password: x.httpPassword,
|
||||
}
|
||||
|
||||
if (x.auth === "Bearer Token")
|
||||
return {
|
||||
authType: "bearer",
|
||||
authActive: true,
|
||||
token: x.bearerToken,
|
||||
}
|
||||
|
||||
return { authType: "none", authActive: true }
|
||||
}
|
||||
12
packages/hoppscotch-data/tsconfig.json
Normal file
12
packages/hoppscotch-data/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"module": "esnext",
|
||||
"lib": ["esnext"],
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
}
|
||||
18
packages/hoppscotch-data/tsup.config.ts
Normal file
18
packages/hoppscotch-data/tsup.config.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Options } from 'tsup'
|
||||
|
||||
const options: Options = {
|
||||
format: [
|
||||
'cjs',
|
||||
// loading Babel in ESM is tricky, since Babel itself it CJS only
|
||||
// we decided to drop ESM support until Babel supports native ESM
|
||||
// 'esm',
|
||||
],
|
||||
clean: true,
|
||||
splitting: true,
|
||||
dts: true,
|
||||
entryPoints: [
|
||||
'src/**/*.ts',
|
||||
],
|
||||
}
|
||||
|
||||
export default options
|
||||
Reference in New Issue
Block a user