You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Docs
* docs: updated pagination recipe
* docs: corrected pagination example
* The exists method has taken the `_lastSyncedAt` property into account and here it was not set before
* docs: adjust wording in doc blocks
* docs(services): noted `handleError` is now async
* docs(query-builder): added documentation for `resetQueryParameters`
* docs: fixed grammar mistakes
* docs(factory): updated examples to be in-line with mocks
* docs(api-calls): updated methods to preferred uppercase
* docs: updated recipe to use the new typing
* docs(timestamps): updated attribute name getter method names
* Linked: 114176e
* docs: fixed typo in test name
* docs: updated pagination recipe to handle model constructors
* docs(api-calls): updated to uppercase method names
* Updated all method argument to `call` to uppercase for consistency
* docs: fixed examples
* docs(api-calls): updated method name to uppercase
* change missed from 03486f1
## Perf
* perf(query-builder): simplified withs deduplication
## Feature
* feat(services): made handleError async on ApiResponseHandler
* feat(api-calls): added default type argument
* While this is invalid, from the outside TS still figures the current `this` correctly
* feat(query-builder): changed `resetQueryParameters` access to public
* feat(api-calls): export `Method` type
* feat(services): widened request type on ApiResponse
* feat(services): added HEAD request handling
* feat(services): improve typings of services call and handle method
* feat(attributes): improved `Attributes` type inference
* Resolves#154
* feat(attributes): improved `only` method's typing
* feat(attributes): improved `except` typing
* feat(attributes): improved typings on attribute management methods
* Following have been updated:
`getOriginal`
`getRawOriginal`
`getChanges`
`getDeletedAttributes`
`getNewAttributes`
* feat: updated static methods returning models to infer type from `this`
* feat: updated some static inference to not use error ignoring
* Updates related to: 63ed0be
* feat(model): added `create` method
* This allows to constructing a model more fluently
## Fix
* fix(model): updated missed distinctBy in the clone method
* fix(attributes): fixed casting methods typing to accept mixed values
* fix(api-calls): pass the response attributes to the constructor
* This also cleans up the code a little
* fix(services): normalised fetch methods
* `patch` could failed with lowercase method name
* fix(api-calls): updated typing to be inclusive of each other on `get`
* fix(relations): fixed `addRelation` typing to accept subclass of a model
* fix: fixed outstanding eslint and typing errors
* fix(model-collection): fixed wrong typing of `toJSON`
* Issue introduced in b4d6db4
* fix(**BREAKING CHANGE**): renamed timestamp name methods
* Renamed the following:
`getDeletedAtColumn` -> `getDeletedAtName`
`getCreatedAtColumn` -> `getCreatedAtName`
`getUpdatedAtColumn` -> `getUpdatedAtName`
## Test
* test(timestamps): tested `restore` accepting server deletedAt value
* test: added initial baseEndpoint in testing
* test(services): added missing test updates
* Updates missed from a07b22a
* test(attributes): fixed failing guarding tests
* test(services): added missing test updates
* Updates missed from a07b22a
* test(relations): updated testing to use the new typings
* test(model): updated to use new typings
* test(api-calls): added missing data unwrap test
* test(api-calls): added missing endpoint getter test
## Refactor
* refactor(services): simplified `handleError` in response handler
* refactor(attributes): simplified `getAttribute` override typing
* refactor(factory): update return types of mock factories
* refactor(model-collection): updated `toJSON` typing
* updated `toJSON` typing to track the model's `toJSON`
## Chore
* chore: incremented package version
* chore: added new eslint rule
* chore: moved todos into github
* chore(deps): updated non-breaking dependencies
* @commitlint/prompt-cli
* @types/uuid
* @typescript-eslint/eslint-plugin
* @typescript-eslint/parser
* commitlint
* eslint
* eslint-plugin-jest
* lint-staged
* qs
* rollup
* typedoc
* typescript
* chore(deps-dev): updated breaking change dependencies
* semantic-release
## Style
* style: fixed eslint issues
## Continuous Integration
* ci: added matrix values explanation
The `call` method is what powers the rest of the api calls on the model. It takes one argument and two optional arguments. The first argument is the method name which is one of `'delete' | 'get' | 'patch' | 'post' | 'put'`. The second is the data to send along with the request. and the third is any custom headers in an object format to be sent along. After the request the [resetEndpoint](#resetendpoint) will be called and all [query parameters](./query-building.md) will be reset.
94
+
The `call` method is what powers the rest of the api calls on the model. It takes one argument and two optional arguments. The first argument is the method name which is one of `'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT' | 'HEAD'`. The second is the data to send along with the request. and the third is any custom headers in an object format to be sent along. After the request the [resetEndpoint](#resetendpoint) will be called and all [query parameters](./query-building.md) will be reset.
95
95
96
96
```ts
97
97
importUserfrom'@Models/User';
98
98
99
99
const user =newUser();
100
100
101
-
awaituser.call('get', { query: 'value' }); // GET your-api.com/users?query=value
101
+
awaituser.call('GET', { query: 'value' }); // GET your-api.com/users?query=value
Copy file name to clipboardexpand all lines: docs/calliope/attributes.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ export default class User extends Model {
50
50
**The following cast types are available:**
51
51
52
52
::: warning
53
-
If the values cannot be casted, an error will be thrown.
53
+
If the values cannot be cast, an error will be thrown.
54
54
:::
55
55
#### `'boolean'`
56
56
Casts the values to boolean. It does not evaluate values as truthy or falsy, it expects the numeric `0, 1`, booleans or `'true', 'false'` in any casing. This is useful to parse the data from the back-end.
@@ -409,7 +409,7 @@ user.name; // 'Jane Doe'
409
409
410
410
When setting an attribute following priority will apply to value:
411
411
- If exists use the [mutator](#mutatorsaccessors) to set the attribute.
412
-
- If [cast](#casting) defined, use the casted value to set the attribute.
412
+
- If [cast](#casting) defined, use the cast value to set the attribute.
413
413
- If the `key` argument is a defined relation and the `value` argument is a valid relation value, set the relation value.
414
414
- Otherwise, just set the attribute on the model.
415
415
@@ -428,7 +428,7 @@ Optionally the method takes a second argument which is returned if the key canno
428
428
This method is internally used when accessing attributes on the model like in the above example. The model will resolve the value in the following order:
429
429
430
430
- If the attribute exists and has an [accessor](#mutatorsaccessors), return the accessor's value.
431
-
- If the attribute exists, and a cast has been defined, return the casted value.
431
+
- If the attribute exists, and a cast has been defined, return the cast value.
432
432
- If the given key is a relation's name, and the relation [has been loaded](./relationships.md#relationloaded), return the relation.
433
433
- If the key is a property of the model, and it's a function, return the default value.
434
434
- If the key is a property of the model, return its value.
Copy file name to clipboardexpand all lines: docs/calliope/query-building.md
+14-2
Original file line number
Diff line number
Diff line change
@@ -348,7 +348,7 @@ User.orderByDesc('column');
348
348
349
349
#### latest
350
350
351
-
The `latest` method is an alias of the [orderBy](#orderby) method using a descending order. You may optionally specify which column to order by with the default being the result of the [getCreatedAtColumn](./timestamps.md#getcreatedatcolumn) method.
351
+
The `latest` method is an alias of the [orderBy](#orderby) method using a descending order. You may optionally specify which column to order by with the default being the result of the [getCreatedAtName](./timestamps.md#getcreatedatname) method.
352
352
353
353
```js
354
354
importUserfrom'@Models/User';
@@ -359,7 +359,7 @@ User.latest('signed_up_at');
359
359
360
360
#### oldest
361
361
362
-
The `oldest` method is an alias of the [orderBy](#orderby) method using an ascending order. You may optionally specify which column to order by with the default being the result of the [getCreatedAtColumn](./timestamps.md#getcreatedatcolumn) method.
362
+
The `oldest` method is an alias of the [orderBy](#orderby) method using an ascending order. You may optionally specify which column to order by with the default being the result of the [getCreatedAtName](./timestamps.md#getcreatedatname) method.
363
363
364
364
```js
365
365
importUserfrom'@Models/User';
@@ -399,6 +399,18 @@ import User from '@Models/User';
399
399
User.newQuery(); // The query builder
400
400
```
401
401
402
+
#### resetQueryParameters
403
+
404
+
The `resetQueryParameters` is a method that clears all previously set query parameters.
405
+
406
+
```js
407
+
importUserfrom'@Models/User';
408
+
409
+
constuser=newUser();
410
+
voiduser.where('columns', 'value').get(); // would send the where query
411
+
voiduser.where('columns', 'value').resetQueryParameters().get(); // would NOT send any query
Copy file name to clipboardexpand all lines: docs/calliope/timestamps.md
+14-14
Original file line number
Diff line number
Diff line change
@@ -9,26 +9,26 @@ Timestamps are a feature of the model used for tracking changes on your entities
9
9
#### createdAt
10
10
11
11
The `createdAt` is a static property on the model. The default value is `'createdAt'`. You may over ride this if the expected timestamp attribute is named differently.
12
-
The letter casing is no concern here as [getCreatedAtColumn](#getcreatedatcolumn) will update it to the correct casing.
12
+
The letter casing is no concern here as [getCreatedAtName](#getcreatedatname) will update it to the correct casing.
13
13
14
14
#### updatedAt
15
15
16
16
The `updatedAt` is a static property on the model. The default value is `'updatedAt'`. You may over ride this if the expected timestamp attribute is named differently.
17
-
The letter casing is no concern here as [getUpdatedAtColumn](#getupdatedatcolumn) will update it to the correct casing.
17
+
The letter casing is no concern here as [getUpdatedAtName](#getupdatedatname) will update it to the correct casing.
18
18
19
19
#### timestamps
20
20
21
21
The `timestamps` is a read only attribute that signifies whether the model uses timestamps or not. The default value is `true`;
22
22
23
23
### Methods
24
24
25
-
#### getCreatedAtColumn
25
+
#### getCreatedAtName
26
26
27
-
The `getCreatedAtColumn` method returns the value of the static [createdAt](#createdat) value with the letter casing set to the given [attributeCasing](./attributes.md#attributecasing).
27
+
The `getCreatedAtName` method returns the value of the static [createdAt](#createdat) value with the letter casing set to the given [attributeCasing](./attributes.md#attributecasing).
28
28
29
-
#### getUpdatedAtColumn
29
+
#### getUpdatedAtName
30
30
31
-
The `getUpdatedAtColumn` method returns the value of the static [updatedAt](#updatedat) value with the letter casing set to the given [attributeCasing](./attributes.md#attributecasing).
31
+
The `getUpdatedAtName` method returns the value of the static [updatedAt](#updatedat) value with the letter casing set to the given [attributeCasing](./attributes.md#attributecasing).
32
32
33
33
#### usesTimestamps
34
34
@@ -37,7 +37,7 @@ The `usesTimestamps` method returns the value of the [timestamps](#timestamps-3)
37
37
#### touch
38
38
<Badgetext="async"type="warning"/>
39
39
40
-
The `touch` method sends a `PATCH` request with the new [updatedAt](#getupdatedatcolumn) attribute value. It updates the attribute from the response data.
40
+
The `touch` method sends a `PATCH` request with the new [updatedAt](#getupdatedatname) attribute value. It updates the attribute from the response data.
41
41
42
42
::: tip
43
43
Your backend should probably not trust this input, but generate its own timestamp.
@@ -46,7 +46,7 @@ Your backend should probably not trust this input, but generate its own timestam
46
46
#### freshTimestamps
47
47
<Badgetext="async"type="warning"/>
48
48
49
-
The `freshTimestamps` method sends `GET` request [selecting](./query-building.md#select) only the [createdAt](#getcreatedatcolumn) and [updatedAt](#getupdatedatcolumn) attributes, which are updated from the response on success.
49
+
The `freshTimestamps` method sends `GET` request [selecting](./query-building.md#select) only the [createdAt](#getcreatedatname) and [updatedAt](#getupdatedatname) attributes, which are updated from the response on success.
The `deletedAt` is a static property on the model. The default value is `'deletedAt'`. You may over ride this if the expected timestamp attribute is named differently.
58
-
The letter casing is no concern here as [getDeletedAtColumn](#getdeletedatcolumn) will update it to the correct casing.
58
+
The letter casing is no concern here as [getDeletedAtName](#getdeletedatname) will update it to the correct casing.
59
59
60
60
#### softDeletes
61
61
62
62
The `softDeletes` is a read only attribute that signifies whether the model uses soft deleting or not. The default value is `true`;
63
63
64
64
#### trashed
65
65
66
-
The `trashed` is a getter property that returns a boolean depending on whether the model has the [deletedAt](#getdeletedatcolumn) set to a truthy value.
66
+
The `trashed` is a getter property that returns a boolean depending on whether the model has the [deletedAt](#getdeletedatname) set to a truthy value.
67
67
68
68
### Methods
69
69
70
-
#### getDeletedAtColumn
70
+
#### getDeletedAtName
71
71
72
-
The `getDeletedAtColumn` method returns the value of the static [deletedAt](#deletedat) value with the letter casing set to the given [attributeCasing](./attributes.md#attributecasing).
72
+
The `getDeletedAtName` method returns the value of the static [deletedAt](#deletedat) value with the letter casing set to the given [attributeCasing](./attributes.md#attributecasing).
73
73
74
74
#### usesSoftDeletes
75
75
@@ -80,7 +80,7 @@ The `usesSoftDeletes` method returns the value of the [softDeletes](#softdeletes
80
80
81
81
The `delete` method is an extension of the api calling method [delete](./api-calls.md#delete). If the model is not [using softDeletes](#usessoftdeletes) the logic will fall back to the original [delete](./api-calls.md#delete) method's logic therefore, method accepts an optional object argument which will be sent along on the request in the body.
82
82
83
-
This method sends a `DELETE` request with the new [deletedAt](#getdeletedatcolumn) attribute value. It updates the attribute from the response data.
83
+
This method sends a `DELETE` request with the new [deletedAt](#getdeletedatname) attribute value. It updates the attribute from the response data.
84
84
85
85
::: tip
86
86
Your backend should probably not trust this input, but generate its own timestamp.
@@ -89,6 +89,6 @@ Your backend should probably not trust this input, but generate its own timestam
89
89
#### restore
90
90
<Badgetext="async"type="warning"/>
91
91
92
-
The `restore` methods sends a `PATCH` request with the nullified [deletedAt](#getdeletedatcolumn) attribute value. It updates the attribute to `null` on successful request.
92
+
The `restore` methods sends a `PATCH` request with the nullified [deletedAt](#getdeletedatname) attribute value. It updates the attribute to `null` on successful request.
Extending/overwriting the model should not be a daunting task. If we wanted we could add an extra method to send data to the server. In this example we add a new field on the sent data which is called `appends` and we're expecting the server to append additional information on the model response data.
@@ -217,50 +217,98 @@ Now if our other models extend our own model they will have the option to set th
217
217
While it's nice to be able to [paginate locally](./helpers/pagination.md) it might not be desired to get too much data upfront. In this case a pagination can be implemented that will only get the pages in question on an explicit request. Of course, you might change the typings and the implementation to fit your needs.
0 commit comments