-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: promiser wrapper implementation in all find functions
- Loading branch information
Rajat Kaushik
committed
Jun 28, 2023
1 parent
e8b6f4e
commit d701952
Showing
5 changed files
with
95 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,66 @@ | ||
{ | ||
"name": "@cosmicjs/sdk", | ||
"version": "1.0.6", | ||
"description": "The official client module for Cosmic. This module helps you easily add dynamic content to your website or application using the Cosmic headless CMS.", | ||
"keywords": [ | ||
"headlesscms", | ||
"cms", | ||
"node", | ||
"content", | ||
"api", | ||
"react", | ||
"reactjs", | ||
"vue", | ||
"vuejs", | ||
"nextjs" | ||
], | ||
"homepage": "https://www.cosmicjs.com", | ||
"bugs": { | ||
"url": "https://github.com/cosmicjs/cosmic-sdk-js/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/cosmicjs/cosmic-sdk-js.git" | ||
}, | ||
"license": "MIT", | ||
"author": "Tony Spiro <[email protected]>", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup src/index.ts --format cjs,esm --dts --minify", | ||
"tsc:lint": "tsc", | ||
"lint": "eslint --fix 'src/**/*.{ts,js}'", | ||
"format": "prettier --write './src/**/*.{ts,js}'", | ||
"release": "npm run build && changeset publish", | ||
"prepare": "husky install", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.3.4", | ||
"form-data": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.1", | ||
"@semantic-release/changelog": "^6.0.2", | ||
"@types/node": "^18.15.5", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-import-resolver-typescript": "^3.5.3", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^13.2.0", | ||
"prettier": "^2.8.6", | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.0.2" | ||
}, | ||
"lint-staged": { | ||
"src/**/*.{ts,js}": [ | ||
"npx prettier --write", | ||
"npx eslint --fix" | ||
] | ||
} | ||
"name": "@cosmicjs/sdk", | ||
"version": "1.0.6", | ||
"description": "The official client module for Cosmic. This module helps you easily add dynamic content to your website or application using the Cosmic headless CMS.", | ||
"keywords": [ | ||
"headlesscms", | ||
"cms", | ||
"node", | ||
"content", | ||
"api", | ||
"react", | ||
"reactjs", | ||
"vue", | ||
"vuejs", | ||
"nextjs" | ||
], | ||
"homepage": "https://www.cosmicjs.com", | ||
"bugs": { | ||
"url": "https://github.com/cosmicjs/cosmic-sdk-js/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/cosmicjs/cosmic-sdk-js.git" | ||
}, | ||
"license": "MIT", | ||
"author": "Tony Spiro <[email protected]>", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup src/index.ts --format cjs,esm --dts --minify", | ||
"tsc:lint": "tsc", | ||
"lint": "eslint --fix 'src/**/*.{ts,js}'", | ||
"format": "prettier --write './src/**/*.{ts,js}'", | ||
"release": "npm run build && changeset publish", | ||
"prepare": "husky install", | ||
"prepublishOnly": "npm run build", | ||
"test": "tsc-watch --project . --outDir ./dist --onSuccess \"nodemon ./test.ts\"" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.3.4", | ||
"form-data": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.26.1", | ||
"@semantic-release/changelog": "^6.0.2", | ||
"@types/node": "^18.15.5", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-import-resolver-typescript": "^3.5.3", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^13.2.0", | ||
"prettier": "^2.8.6", | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.0.2" | ||
}, | ||
"lint-staged": { | ||
"src/**/*.{ts,js}": [ | ||
"npx prettier --write", | ||
"npx eslint --fix" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
import { PromiseFnType } from '../../../../types/promise.types'; | ||
import { promiser } from '../../../../utils/request.promiser'; | ||
import { promiserTryCatchWrapper } from '../../../../utils/request.promiser'; | ||
import Chaining from './chaining'; | ||
|
||
export default class FindOneChaining extends Chaining { | ||
async then<FulfilledResult = any, RejectedResult = never>( | ||
onFulfilled?: PromiseFnType<FulfilledResult>, | ||
onRejected?: PromiseFnType<RejectedResult> | ||
) { | ||
promiser(this.endpoint) | ||
.then((res: any) => | ||
onFulfilled?.({ | ||
object: res.objects && res.objects.length ? res.objects[0] : null, | ||
}) | ||
) | ||
.catch((err) => { | ||
if (typeof onRejected === 'function') { | ||
onRejected?.(err); | ||
} else { | ||
onFulfilled?.(null); | ||
} | ||
await promiserTryCatchWrapper(this.endpoint, onRejected, (res) => { | ||
onFulfilled?.({ | ||
object: res.objects && res.objects.length ? res.objects[0] : null, | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters