From 48eee0238e9a745ef01a4bfd6441fd2bb7e519fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:00:56 -0300 Subject: [PATCH 01/10] chore: bump semantic-release from 17.2.2 to 17.2.3 (#152) Bumps [semantic-release](https://github.com/semantic-release/semantic-release) from 17.2.2 to 17.2.3. - [Release notes](https://github.com/semantic-release/semantic-release/releases) - [Commits](https://github.com/semantic-release/semantic-release/compare/v17.2.2...v17.2.3) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/yarn.lock b/yarn.lock index c132f94b..e69b6de4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2409,12 +2409,12 @@ debug@3.1.0, debug@=3.1.0: dependencies: ms "2.0.0" -debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" - integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== +debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1: + version "4.2.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1" + integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg== dependencies: - ms "^2.1.1" + ms "2.1.2" debug@^2.2.0, debug@^2.3.3: version "2.6.9" @@ -2430,13 +2430,6 @@ debug@^3.1.0: dependencies: ms "^2.1.1" -debug@^4.0.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1" - integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg== - dependencies: - ms "2.1.2" - debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" @@ -4966,12 +4959,7 @@ lodash.without@~4.4.0: resolved "https://registry.yarnpkg.com/lodash.without/-/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac" integrity sha1-PNRXSgC2e643OpS3SHcmQFB7eqw= -lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15: - version "4.17.19" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" - integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== - -lodash@^4.17.4: +lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== @@ -6815,9 +6803,9 @@ sax@^1.2.4: integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== semantic-release@^17.2.2: - version "17.2.2" - resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-17.2.2.tgz#520dae9cd188c7cdcc5216a7aad131548fc5cec7" - integrity sha512-LNU68ud3a3oU46H11OThXaKAK430jGGGTIF4VsiP843kRmS6s8kVCceLRdi7yWWz/sCCMD0zygPTQV2Jw79J5g== + version "17.2.3" + resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-17.2.3.tgz#11f10b851d4e75b1015b17515c433049b3df994c" + integrity sha512-MY1MlowGQrkOR7+leOD8ICkVOC6i1szbwDODdbJ0UdshtMx8Ms0bhpRQmEEliqYKEb5PLv/dqs6zKKuHT7UxTg== dependencies: "@semantic-release/commit-analyzer" "^8.0.0" "@semantic-release/error" "^2.2.0" From 02a88f5e1e79b82fcde98536d319658bfb5324cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:01:14 -0300 Subject: [PATCH 02/10] chore: bump ini from 1.3.5 to 1.3.7 (#160) Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.7) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index e69b6de4..f01d98e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3708,9 +3708,9 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1, integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== ini@^1.3.4, ini@^1.3.5, ini@~1.3.0: - version "1.3.5" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" - integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== + version "1.3.7" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.7.tgz#a09363e1911972ea16d7a8851005d84cf09a9a84" + integrity sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ== init-package-json@^1.10.3: version "1.10.3" From 648261d634853c9a24188113fb426496345819b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Dec 2020 14:01:23 -0300 Subject: [PATCH 03/10] chore: bump ini from 1.3.5 to 1.3.8 in /docs (#161) Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/yarn.lock b/docs/yarn.lock index 5ecc884a..7c179bfd 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -5094,9 +5094,9 @@ inherits@2.0.3: integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= ini@^1.3.5: - version "1.3.5" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" - integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== + version "1.3.8" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" + integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== inline-style-parser@0.1.1: version "0.1.1" From 7b67bf577fdbc2c603ea2622e01aa48d8c84a73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Sat, 16 Jan 2021 21:21:57 -0300 Subject: [PATCH 04/10] docs(api): fix docs of `parameterNames` and `get` (#169) * docs(api): fix options of `parameterNames` * docs(api): update description of `get` --- docs/content/en/api/model-options.md | 36 ++++++++++---------- docs/content/en/api/query-builder-methods.md | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/content/en/api/model-options.md b/docs/content/en/api/model-options.md index 989d97e5..0510ff65 100644 --- a/docs/content/en/api/model-options.md +++ b/docs/content/en/api/model-options.md @@ -65,24 +65,6 @@ parameterNames() { } ``` -### `formData` -- Returns: `object` - -This method can be overridden in the model to configure `object-to-formdata`. - -See [object-to-formdata](https://github.com/therealparmesh/object-to-formdata#usage) - -```js -formData() { - return { - indices: false, - nullsAsUndefineds: false, - booleansAsIntegers: false, - allowEmptyArrays: false, - } -} -``` - #### `include` - Default: `include` - Returns: `string` @@ -111,6 +93,24 @@ formData() { - Default: `limit` - Returns: `string` +### `formData` +- Returns: `object` + +This method can be overridden in the model to configure `object-to-formdata`. + +See [object-to-formdata](https://github.com/therealparmesh/object-to-formdata#usage) + +```js +formData() { + return { + indices: false, + nullsAsUndefineds: false, + booleansAsIntegers: false, + allowEmptyArrays: false, + } +} +``` + ## Model Options These are model-related options. diff --git a/docs/content/en/api/query-builder-methods.md b/docs/content/en/api/query-builder-methods.md index 93bc51ab..d57743a0 100644 --- a/docs/content/en/api/query-builder-methods.md +++ b/docs/content/en/api/query-builder-methods.md @@ -221,7 +221,7 @@ await Model.config({ ## `get` - Returns: `Collection | { data: Collection }` -Execute the query as a "select" statement. +Execute the query and get all results. ```js await Model.get() @@ -251,7 +251,7 @@ await Model.find(1) ## `$get` - Returns: `Collection` -Execute the query as a "select" statement. +Execute the query and get all results. ```js await Model.$get() From 727ded646b8c9a909bdedab8cde9a1060c323846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Sat, 16 Jan 2021 21:38:29 -0300 Subject: [PATCH 05/10] docs: fix router base (#170) Temporary workaround to solve router base issue. --- docs/nuxt.config.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/nuxt.config.js b/docs/nuxt.config.js index 45015050..921af97e 100644 --- a/docs/nuxt.config.js +++ b/docs/nuxt.config.js @@ -3,5 +3,16 @@ import theme from "@nuxt/content-theme-docs"; export default theme({ router: { base: '/vue-api-query/' + }, + /** + * Workaround to fix router base issue. + * + * See https://github.com/robsontenorio/vue-api-query/issues/165 + * See https://github.com/nuxt/content/issues/376#issuecomment-702193217 + */ + hooks: { + 'vue-renderer:ssr:templateParams': function(params) { + params.HEAD = params.HEAD.replace('', '') + } } }) From b733e45926a12cec6bad9d9a2b77631b8d6cba25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Sat, 16 Jan 2021 21:38:53 -0300 Subject: [PATCH 06/10] fix: add missing `config` static method (#167) --- src/StaticModel.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/StaticModel.js b/src/StaticModel.js index 0c9cc180..5a98fdb3 100644 --- a/src/StaticModel.js +++ b/src/StaticModel.js @@ -11,6 +11,13 @@ export default class StaticModel { return new this } + static config(config) { + let self = this.instance() + self.config(config) + + return self + } + static include(...args) { let self = this.instance() self.include(...args) From 1d8122fa57b52504efcb8e7d7f021fc6e23e33e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Sat, 16 Jan 2021 21:48:17 -0300 Subject: [PATCH 07/10] feat: add typescript support (#168) Based on #104 by @alvaro-canepa --- index.d.ts | 707 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 708 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..f9abe904 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,707 @@ +type Method = + | 'get' + | 'GET' + | 'delete' + | 'DELETE' + | 'head' + | 'HEAD' + | 'options' + | 'OPTIONS' + | 'post' + | 'POST' + | 'put' + | 'PUT' + | 'patch' + | 'PATCH' + | 'purge' + | 'PURGE' + | 'link' + | 'LINK' + | 'unlink' + | 'UNLINK' + +export interface HTTPRequestConfig { + method?: Method + url?: string + data?: Record | any + headers?: any + [key: string]: any +} + +export interface HTTPResponse { + data: T + [key: string]: any +} + +export type HTTPPromise = Promise> + +export interface WrappedResponse { + data: T, + [key: string]: any +} + +export type QueryPromise = Promise> + +declare class StaticModel { + /** + * Create an instance of itself. + */ + static instance (this: M): InstanceType + + /** + * Query + */ + + /** + * Configuration of HTTP Instance. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#config|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#configuring-the-request|Building the Query} + */ + static config (this: M, config: HTTPRequestConfig): InstanceType + + /** + * Eager load relationships. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + static include (this: M, ...relationships: string[]): InstanceType + + /** + * Eager load relationships. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + static include (this: M, relationships: string[]): InstanceType + + /** + * Eager load relationships. + * + * Alias for the [include()]{@link include} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + static with (this: M, ...relationships: string[]): InstanceType + + /** + * Eager load relationships. + * + * Alias for the [include()]{@link include} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + static with (this: M, relationships: string[]): InstanceType + + /** + * Append attributes. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#append|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#appending-attributes|Building the Query} + */ + static append (this: M, ...attributes: string[]): InstanceType + + /** + * Append attributes. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#append|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#appending-attributes|Building the Query} + */ + static append (this: M, attributes: string[]): InstanceType + + /** + * Set the columns to be selected. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#select|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#selecting-fields|Building the Query} + */ + static select (this: M, ...columns: string[]): InstanceType + + /** + * Set the columns to be selected. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#select|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#selecting-fields|Building the Query} + */ + static select (this: M, columns: string[]): InstanceType + + /** + * Set the columns to be selected. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#select|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#selecting-fields|Building the Query} + */ + static select (this: M, columns: { + [related: string]: string[] + }): InstanceType + + /** + * Add a basic where clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#where|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#evaluating-a-single-value|Building the Query} + */ + static where ( + this: M, + field: string | string[], + value: string | number | boolean + ): InstanceType + + /** + * Add a "where in" clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#wherein|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#evaluating-multiple-values|Building the Query} + */ + static whereIn ( + this: M, + field: string | string[], + values: (string | number | boolean)[] + ): InstanceType + + /** + * Add an "order by" clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#orderby|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#sorting|Building the Query} + */ + static orderBy (this: M, ...columns: string[]): InstanceType + + /** + * Add an "order by" clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#orderby|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#sorting|Building the Query} + */ + static orderBy (this: M, columns: string[]): InstanceType + + /** + * Set the current page. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#page|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#paginating|Building the Query} + */ + static page (this: M, number: number): InstanceType + + /** + * Set the page limit. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#limit|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#paginating|Building the Query} + */ + static limit (this: M, number: number): InstanceType + + /** + * Add custom parameters to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#params|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#applying-custom-parameters|Building the Query} + */ + static params (this: M, payload: Record): InstanceType + + /** + * Build custom endpoints. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#custom|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#calling-a-custom-resource|Building the Query} + */ + static custom (this: M, ...endpoint: (Model | string)[]): InstanceType + + /** + * Results + */ + + /** + * Execute the query and get the first result. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#first|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#getting-the-first-record|Building the Query} + */ + static first (this: M): QueryPromise> + + /** + * Execute the query and get the first result. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#first-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#getting-the-first-record|Building the Query} + */ + static $first (this: M): Promise> + + /** + * Find a model by its primary key. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#find|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#finding-a-specific-record|Building the Query} + */ + static find (this: M, id: number | string): QueryPromise> + + /** + * Find a model by its primary key. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#find-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#finding-a-specific-record|Building the Query} + */ + static $find (this: M, id: number | string): Promise> + + /** + * Execute the query and get all results. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + static get (this: M): QueryPromise[]> + + /** + * Execute the query and get all results. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + static $get (this: M): Promise[]> + + /** + * Execute the query and get all results. + * + * Alias for the [get()]{@link get} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + static all (this: M): QueryPromise[]> + + /** + * Execute the query and get all results. + * + * Alias for the [$get()]{@link $get} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + static $all (this: M): Promise[]> +} + +export class Model extends StaticModel { + /** + * Instance of the HTTP client which is used to make requests. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#http|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/installation|Installation} + */ + static $http: any + + constructor (...args: any[]) + + /** + * Settings + */ + + /** + * Instance of the HTTP client which is used to make requests. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#http|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/installation|Installation} + */ + get $http (): any + + /** + * This method can be overridden in the model to configure + * [object-to-formdata]{@link https://github.com/therealparmesh/object-to-formdata#usage|object-to-formdata}. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#http|API Reference} + * @see {@link https://github.com/therealparmesh/object-to-formdata#usage|object-to-formdata} + */ + formData (): { + indices: boolean, + nullsAsUndefineds: boolean, + booleansAsIntegers: boolean, + allowEmptyArrays: boolean, + } + + /** + * Resource route of the model which is used to build the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#resource|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#creating-the-domain-models|Configuration} + */ + resource (): string + + /** + * Primary key of the model which is used to build the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#primarykey|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#changing-the-primary-key|Configuration} + */ + primaryKey (): string + + /** + * This method can be used to lazy load relationships of a model and apply model instances to them. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#hasmany|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#lazy-loading-relationships|Configuration} + */ + hasMany (model: T): InstanceType + + /** + * This method can be implemented in the model to apply model instances to eager loaded relationships. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#relations|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#eager-loaded-relationships|Configuration} + */ + relations (): Record + + /** + * Base URL which is used and prepended to make requests. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#baseurl|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#creating-a-base-model|Configuration} + */ + baseURL (): string + + /** + * Request method which is used to make requests. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#request|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#creating-a-base-model|Configuration} + */ + request (config: HTTPRequestConfig): HTTPPromise + + /** + * From resource. + */ + private _from (url: string): void + + /** + * Helpers + */ + + /** + * Get the primary key of the model. + */ + private getPrimaryKey (): string | number + + /** + * Determines whether the model has an ID. + */ + private hasId (): boolean + + /** + * Determines whether the ID is valid. + */ + private isValidId (id: string | number): boolean + + /** + * The model's endpoint. + */ + private endpoint (): string + + /** + * This method can be overridden in the model to customize the name of the query parameters. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/model-options#parameternames|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/configuration#customizing-query-parameters|Configuration} + */ + protected parameterNames (): { + include: string, + filter: string, + sort: string, + fields: string, + append: string, + page: string, + limit: string + } + + /** + * Query + */ + + /** + * Configuration of HTTP Instance. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#config|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#configuring-the-request|Building the Query} + */ + config (config: HTTPRequestConfig): this + + /** + * Eager load relationships. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + include (...relationships: string[]): this + + /** + * Eager load relationships. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + include (relationships: string[]): this + + /** + * Eager load relationships. + * + * Alias for the [include()]{@link include} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + with (...relationships: string[]): this + + /** + * Eager load relationships. + * + * Alias for the [include()]{@link include} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#include|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#including-relationships|Building the Query} + */ + with (relationships: string[]): this + + /** + * Append attributes. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#append|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#appending-attributes|Building the Query} + */ + append (...attributes: string[]): this + + /** + * Append attributes. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#append|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#appending-attributes|Building the Query} + */ + append (attributes: string[]): this + + /** + * Set the columns to be selected. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#select|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#selecting-fields|Building the Query} + */ + select (...columns: string[]): this + + /** + * Set the columns to be selected. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#select|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#selecting-fields|Building the Query} + */ + select (columns: string[]): this + + /** + * Set the columns to be selected. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#select|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#selecting-fields|Building the Query} + */ + select (columns: { + [related: string]: string[] + }): this + + /** + * Add a basic where clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#where|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#evaluating-a-single-value|Building the Query} + */ + where (field: string | string[], value: string | number | boolean): this + + /** + * Add a "where in" clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#wherein|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#evaluating-multiple-values|Building the Query} + */ + whereIn (field: string | string[], array: (string | number | boolean)[]): this + + /** + * Add an "order by" clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#orderby|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#sorting|Building the Query} + */ + orderBy (...columns: string[]): this + + /** + * Add an "order by" clause to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#orderby|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#sorting|Building the Query} + */ + orderBy (columns: string[]): this + + /** + * Set the current page. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#page|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#paginating|Building the Query} + */ + page (number: number): this + + /** + * Set the page limit. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#limit|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#paginating|Building the Query} + */ + limit (number: number): this + + /** + * Add custom parameters to the query. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#params|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#applying-custom-parameters|Building the Query} + */ + params (payload: Record): this + + /** + * Build custom endpoints. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#custom|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#calling-a-custom-resource|Building the Query} + */ + custom (...endpoint: (Model | string)[]): this + + /** + * Results + */ + + /** + * Execute the query and get the first result. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#first|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#getting-the-first-record|Building the Query} + */ + first (): QueryPromise + + /** + * Execute the query and get the first result. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#first-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#getting-the-first-record|Building the Query} + */ + $first (): Promise + + /** + * Find a model by its primary key. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#find|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#finding-a-specific-record|Building the Query} + */ + find (identifier: number | string): QueryPromise + + /** + * Find a model by its primary key. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#find-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#finding-a-specific-record|Building the Query} + */ + $find (identifier: number | string): Promise + + /** + * Execute the query and get all results. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + get (): QueryPromise + + /** + * Execute the query and get all results. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + $get (): Promise + + /** + * Execute the query and get all results. + * + * Alias for the [get()]{@link get} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + all (): QueryPromise + + /** + * Execute the query and get all results. + * + * Alias for the [$get()]{@link $get} method. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#get-1|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query} + */ + $all (): Promise + + /** + * Common CRUD operations + */ + + /** + * Delete the model from the database. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/crud-operations#delete|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/performing-operations#deleting-a-model|Performing Operations} + */ + delete (): Promise + + /** + * Save or update a model in the database, then return the instance. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/crud-operations#save|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/performing-operations#saving-a-model|Performing Operations} + */ + save (): Promise + + /** + * Save a model in the database, then return the instance. + */ + private _create (): Promise + + /** + * Update a model in the database, then return the instance. + */ + private _update (): Promise + + /** + * Make a `PATCH` request to update a model in the database, then return the instance. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/crud-operations#patch|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/performing-operations#saving-a-model|Performing Operations} + */ + patch (): Promise + + /** + * Relationship operations + */ + + /** + * Create a new related model. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/relationship-operations#for|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/performing-operations#creating-related-models|Performing Operations} + */ + for (...models: Model[]): this + + /** + * Create a new related model. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/relationship-operations#attach|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/performing-operations#attaching-a-model|Performing Operations} + */ + attach (params: Record): Promise + + /** + * Update a related model. + * + * @see {@link https://robsontenorio.github.io/vue-api-query/api/relationship-operations#sync|API Reference} + * @see {@link https://robsontenorio.github.io/vue-api-query/performing-operations#syncing-a-model|Performing Operations} + */ + sync (params: Record): Promise +} diff --git a/package.json b/package.json index 237e28da..49c282c8 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0-development", "description": "💎 Elegant and simple way to build requests for REST API", "main": "build/index.js", + "types": "./index.d.ts", "scripts": { "build": "babel src -d build", "lint": "eslint --ext .js .", From a2a8787e22012c07a33c876442a0df00608f4bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robson=20Ten=C3=B3rio?= Date: Sat, 16 Jan 2021 22:04:46 -0300 Subject: [PATCH 08/10] chore: create pull_request_template.md --- .github/pull_request_template.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..aeb096fb --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,5 @@ +## Checklist + +- [ ] Tests +- [ ] Docs +- [ ] Type definitions From a2fa4a881ab50284c27e8ef176c6ec98c0fd492f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Jan 2021 22:10:32 -0300 Subject: [PATCH 09/10] chore: bump axios from 0.19.2 to 0.21.1 (#166) Bumps [axios](https://github.com/axios/axios) from 0.19.2 to 0.21.1. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v0.21.1/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v0.19.2...v0.21.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 49c282c8..d48629da 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@babel/plugin-transform-runtime": "^7.9.0", "@babel/preset-env": "^7.9.5", "@babel/runtime": "^7.9.2", - "axios": "^0.19.2", + "axios": "^0.21.1", "axios-mock-adapter": "^1.18.1", "babel-eslint": "^10.1.0", "codecov": "^3.6.5", diff --git a/yarn.lock b/yarn.lock index f01d98e3..85502682 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1595,12 +1595,12 @@ axios-mock-adapter@^1.18.1: fast-deep-equal "^3.1.1" is-buffer "^2.0.3" -axios@^0.19.2: - version "0.19.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" - integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== +axios@^0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== dependencies: - follow-redirects "1.5.10" + follow-redirects "^1.10.0" babel-eslint@^10.1.0: version "10.1.0" @@ -2402,7 +2402,7 @@ dateformat@^3.0.0: resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae" integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q== -debug@3.1.0, debug@=3.1.0: +debug@3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== @@ -3127,12 +3127,10 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@1.5.10: - version "1.5.10" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" - integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== - dependencies: - debug "=3.1.0" +follow-redirects@^1.10.0: + version "1.13.1" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7" + integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg== for-in@^1.0.2: version "1.0.2" From c4644c29150fc4271f758a046d4ed8945b489a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Antunes=20Silva?= Date: Sat, 16 Jan 2021 22:45:33 -0300 Subject: [PATCH 10/10] chore: only publish necessary files --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index d48629da..fdb6b5d1 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,10 @@ "description": "💎 Elegant and simple way to build requests for REST API", "main": "build/index.js", "types": "./index.d.ts", + "files": [ + "build", + "index.d.ts" + ], "scripts": { "build": "babel src -d build", "lint": "eslint --ext .js .",