quasar-app-extension-api-wrapper
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,11 +10,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const api_client_wrapper_1 = __importDefault(require("api-client-wrapper")); | ||
exports.default = ({ Vue, store }) => __awaiter(void 0, void 0, void 0, function* () { | ||
api_client_wrapper_1.default.setStore(store); | ||
Vue.prototype.$api = api_client_wrapper_1.default; | ||
import api from 'api-client-wrapper'; | ||
export default ({ Vue, store }) => __awaiter(void 0, void 0, void 0, function* () { | ||
api.setStore(store); | ||
Vue.prototype.$api = api; | ||
}); | ||
//# sourceMappingURL=api-wrapper-bootfile.js.map |
{ | ||
"name": "quasar-app-extension-api-wrapper", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A Quasar App Extension designed to wrap up the most common features of an api client implementation", | ||
@@ -11,2 +11,3 @@ "author": "Roberto <roberto.langarica@gmail.com>", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"No test specified\" && exit 0" | ||
@@ -26,5 +27,7 @@ }, | ||
"dependencies": { | ||
"api-client-wrapper": "^0.2.1" | ||
"api-client-wrapper": "^0.2.3" | ||
}, | ||
"devDependencies": {} | ||
"devDependencies": { | ||
"typescript": "^3.9.7" | ||
} | ||
} |
@@ -12,3 +12,3 @@ ### Quasar App Extension | ||
The present features in the extension are: | ||
1. **Easy global access:** The extension came with a boot script that put an _**$api**_ object available at global scope for any component: `this.$api` | ||
1. **Easy global access:** The extension came with a [Quasar boot script](https://quasar.dev/quasar-cli/boot-files#Anatomy-of-a-boot-file) that put an _**$api**_ object available at global scope for any Vue component as: `this.$api`. You can access the `$api` object from inside any Vue component. | ||
@@ -25,3 +25,3 @@ 1. **Base API url:** The url that will be used as a root for any call that contains a relative path `this.$api.baseURL`. **Note:** If a call contains a full path (one with http or https protocol) it will be called as is without _baseURL_ concatenation. | ||
1. **Vuex integration:** The extension came with Vuex store integration for state monitoring. During boot phase a module is registered to Vuex with the next information: | ||
1. **Vuex integration:** The extension came with Vuex store integration for state monitoring. During Quasar boot phase a module is registered to Vuex with the next information: | ||
1. Working: Indicating that is at least one request executing `this.$store.state.APIwrapper.working` | ||
@@ -52,2 +52,3 @@ 1. Uploading: Indicating that is at least one request executing with a method different from `GET` `this.$store.state.APIwrapper.uploading` | ||
```javascript | ||
// Inside any Vue componente | ||
let result = await this.$api.get('path'); | ||
@@ -61,2 +62,3 @@ //or | ||
```javascript | ||
// Inside any Vue componente | ||
let result = await this.$api.post('path', {data}); | ||
@@ -69,13 +71,30 @@ //or | ||
```javascript | ||
get(path='', conf = {}) | ||
post(path='', data = {}, conf = {}) | ||
patch(path='', data = {}, conf = {}) | ||
put(path='', data = {}, conf = {}) | ||
delete(path='', conf = {}) | ||
// Inside any Vue componente | ||
this.$api.get(path='', conf = {}) | ||
this.$api.post(path='', data = {}, conf = {}) | ||
this.$api.patch(path='', data = {}, conf = {}) | ||
this.$api.put(path='', data = {}, conf = {}) | ||
this.$api.delete(path='', conf = {}) | ||
//Or the global method that receive a request Configuration | ||
call({request configuration}) | ||
//Or the global method that receive a request Configuration (in most of the cases you will never need this method) | ||
this.$api.call({request configuration}) | ||
``` | ||
Note that each method has a final argument that is a custom configuration for the request, this configuration takes precedence over the global configuration. For the supported properties please refer to the _Request Configuration_ section. | ||
### Use outside a Vue component | ||
You can use APIWrapper from outside a Vue component, this is common if you want to use it in a store module or inside any other js file Eg. A Quasar bootfile. | ||
```javascript | ||
// import the object | ||
import api from "api-client-wrapper" | ||
// Use any of the available methods | ||
api.get(path='', conf = {}) | ||
api.post(path='', data = {}, conf = {}) | ||
api.patch(path='', data = {}, conf = {}) | ||
api.put(path='', data = {}, conf = {}) | ||
api.delete(path='', conf = {}) | ||
``` | ||
**Important Note:** You are still referencing the same object that you use inside any Vue component, so if you make any configuration it will affect any other place where you were using it, and the same goes in viceversa, any previous configuration made will take effect. | ||
### Bulk calls | ||
@@ -85,2 +104,3 @@ Each method has a bulk counterpart that allows for bulk calls | ||
```javascript | ||
// Inside any Vue componente | ||
let result = await this.$api.bulkGet(['paths' or {configs}], continueWithFailure:Boolean, onProgress) | ||
@@ -101,3 +121,3 @@ let result = await this.$api.bulkPost(['paths' or {configs}], continueWithFailure:Boolean, onProgress) | ||
### Request Configuration | ||
A configuration object for each request (with precedence over any global configuration) with the next scheme: | ||
A configuration object for each request, which have precedence over any global configuration (so it is a way to override any global configuration for special scenarios) It has the next scheme: | ||
```javascript | ||
@@ -179,26 +199,30 @@ { | ||
Configuration of the overall behaviour for the extension | ||
Configuration of the overall behaviour for the extension. | ||
*Note:* The configuration could be made outside of a Vue component: See the: [Use outside a Vue component](#use-outside-a-vue-component) | ||
```javascript | ||
// Inside any Vue componente | ||
// `baseURL` will be prepended to any path provided unless the provided path is absolute. | ||
this.$api.baseURL = ''; | ||
this.$api.baseURL = ''; // Empty string is the default | ||
// The amount of attempts a request will make in the case of a timeout before failing completely | ||
this.$api.maxAttemptsPerCall = 1; | ||
this.$api.maxAttemptsPerCall = 1; // 1 is the default | ||
// The amount of concurrent requests that could be executed (when the requests number exceed this amount the requests are enqueue in a waiting mode) | ||
this.$api.simultaneousCalls = 5; | ||
this.$api.simultaneousCalls = 5; // 5 is the default | ||
// Specifies the number of milliseconds before a request times out | ||
this.$api.timeout = 10000; | ||
this.$api.timeout = 10000; // 10000 is the default | ||
// Sets the default headers for 'Content-Type' for each request | ||
this.$api.setContentType(type = 'application/json') | ||
this.$api.setContentType('application/json') // 'application/json' is the default | ||
// Sets the default authorization header: 'Authorization' for each request | ||
this.$api.setAuthorization(token, type = 'Bearer') | ||
this.$api.setAuthorization('token', 'Bearer') // The default is not to have any Authorization header | ||
// If the store where not provided in the boot phase then it could be passed to the extension using this function | ||
// If the store where not provided in the Quasar boot phase then it could be assigned to the extension using the next function | ||
// This will bring the module 'APIwrapper' available and the extension will start updating its state | ||
this.$api.setStore(vuex_instance) | ||
this.$api.setStore(vuex_instance) // vuex_instance should be a valid Vuex instance | ||
``` |
{ | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||
/* Basic Options */ | ||
"incremental": true, /* Enable incremental compilation */ | ||
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
"allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "checkJs": true, /* Report errors in .js files. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
"sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
"outDir": "dist", /* Redirect output structure to the directory. */ | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
// "composite": true, /* Enable project compilation */ | ||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ | ||
// "removeComments": true, /* Do not emit comments to output. */ | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
// "strictNullChecks": true, /* Enable strict null checks. */ | ||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ | ||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ | ||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
/* Additional Checks */ | ||
// "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
/* Module Resolution Options */ | ||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
// "typeRoots": [], /* List of folders to include type definitions from. */ | ||
// "types": [], /* Type declaration files to be included in compilation. */ | ||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ | ||
/* Source Map Options */ | ||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
/* Experimental Options */ | ||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
/* Advanced Options */ | ||
"skipLibCheck": true, /* Skip type checking of declaration files. */ | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
"incremental": true, | ||
"target": "ES2015", | ||
"module": "commonjs", | ||
"allowJs": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"baseUrl": ".", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
"dist", | ||
"ignore" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
221
17222
1
90
Updatedapi-client-wrapper@^0.2.3