Skip to content

Commit

Permalink
update request typing, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberCookie committed Jul 16, 2024
1 parent 57de6d5 commit 34eef78
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 27 deletions.
2 changes: 1 addition & 1 deletion client_core/network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Content-type header values used in **request**.
- `isFullRes` - **Boolean** Default is **false**<br />
Returns full response with headers, status code etc

- `parseMethod` - **String**<br />
- `parseMethod` - **'json' | 'formData' | 'text' | 'arrayBuffer' | 'blob'**<br />
Method to be executed on response to extract its data<br />
By default **request** sets this prop regarding to response content type

Expand Down
8 changes: 6 additions & 2 deletions client_core/network/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function extractResponseData(req: RequestParams, res: Response): Promise<a
jsonParsePreprocess(await res.text())
)

: await res[parseMethod as 'json' | 'formData' | 'text']()
: await res[parseMethod]()
} catch (err) { throw new Error(
`${err}. Failed to parse contentType: ${contentType} using ${parseMethod}() method.`
)}
Expand Down Expand Up @@ -140,7 +140,11 @@ const createApi = (setupParams: SetupParams = {}) => {


return async <Res = any, Body = any>(req: RequestParams<Body, Res>) => {
req.json ||= json

if (!isExists(req.json)) {
req.json = json
}

req.jsonStringifyPostprocess ||= jsonStringifyPostprocess
req.jsonParsePreprocess ||= jsonParsePreprocess

Expand Down
2 changes: 1 addition & 1 deletion client_core/network/request/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type RequestParams<_Body = any, _Res = any> = {
isFullRes?: boolean

/** Method to be executed on response to extract its data */
parseMethod?: string
parseMethod?: 'json' | 'formData' | 'text' | 'arrayBuffer' | 'blob'

/** Request credentials */
credentials?: RequestInit['credentials']
Expand Down
2 changes: 1 addition & 1 deletion core/client_build/module_rules/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ConfigFinal } from '../../types'
type WorkerLoaderRegExp = '__worker\\.[tj]s$'
type ScriptsLoaderRegExp = '\\.[tj]sx?$'
type StylesLoaderRegExp = '\\.(c|sc|sa)ss$'
type FilesLoaderRegExp = '\\.(avif|webp|jpe?g|png|svg|woff2?)$'
// type FilesLoaderRegExp = '\\.(avif|webp|jpe?g|png|svg|woff2?)$'


type AnyDefaultLoader = Exclude<Loader, boolean | string>
Expand Down
15 changes: 0 additions & 15 deletions core/client_build/plugins/plugin_sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ type SwPluginClassCtor = {

const NAME = 'siegel-sw-plugin'

// function generateContentHash(str: string) {
// let hash = 0, i, chr

// if (str.length) {
// for (i = 0; i < str.length; i++) {
// chr = str.charCodeAt(i)
// hash = ((hash << 5) - hash) + chr
// hash |= 0 // Convert to 32bit integer
// }

// }

// return hash
// }

const serviceWorkerPlugin = function(this: WebpackPluginInstance, entry: SwPluginOptions) {
const filename = path.basename(entry)
const swContent = fs.readFileSync(entry, 'utf8')
Expand Down
1 change: 1 addition & 0 deletions core/client_build/plugins/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type UserPlugin<
> | boolean


//TODO typing: user plugin options
//TODO typing: required custom plugin and never predefined
type Plugins = {
compression?: UserPlugin<CompressionPlugin, null, null, DefaultPlugins['compression']['instances']>
Expand Down
122 changes: 121 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siegel",
"version": "0.14.94",
"version": "0.14.95",
"homepage": "https://siegel-qe3q.onrender.com",
"url": "https://github.com/CyberCookie/siegel",
"bugs": "https://github.com/CyberCookie/siegel/issues",
Expand Down Expand Up @@ -58,7 +58,7 @@
"build": "$npm_package_config_boot -b -p",
"build_serv": "$npm_package_config_boot -b -s -p",
"serv": "$npm_package_config_boot -s -p",
"deploy": "npm ci --no-audit --no-fund && npm run build && npm run serv",
"deploy": "npm ci --no-audit --no-fund && npm run build && npm run serv",
"validate": "npx eslint . && npx tsc -p ."
},
"dependencies": {
Expand All @@ -76,7 +76,7 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"react-refresh": "0.14.2",
"sass": "1.77.6",
"sass": "1.77.8",
"sass-loader": "14.2.1",
"sass-resources-loader": "2.2.5",
"style-loader": "4.0.0",
Expand All @@ -85,20 +85,20 @@
"ts-node": "10.9.2",
"ttf2woff": "3.0.0",
"ttf2woff2": "5.0.0",
"webpack": "^5.92.1",
"webpack": "^5.93.0",
"webpack-dev-middleware": "7.2.1",
"webpack-hot-middleware": "2.26.1",
"worker-loader": "3.0.8"
},
"devDependencies": {
"@types/jest": "29.5.12",
"jest": "29.7.0",
"ts-jest": "29.1.5"
"ts-jest": "29.2.2"
},
"peerDependencies": {
"@types/express": "4.17.21",
"@types/mime": "1.3.2",
"@types/node": "20.14.9",
"@types/node": "20.14.10",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@types/svg2ttf": "5.0.3",
Expand Down

0 comments on commit 34eef78

Please sign in to comment.