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
Sometimes you may encounter data structures that are meant to be sorted based on their relation to each other. For example messages and their replies, folders and their sub folders, tasks and their subtasks, etc... However, sometimes the data sources might not return the data in an easily digestible structured format but as a flat array.
4
+
5
+
For these occasions you may use the AncestryCollection. The AncestryCollection is a subclass of the [ModelCollection](./model-collection.md), therefore all methods are inherited. Keep in mind that inherited methods will be operating on the top level items as one might expect.
6
+
7
+
## Properties
8
+
9
+
#### depthName
10
+
<Badgetext="static"type="warning"/>
11
+
12
+
This string determines the name of the attribute that is set on the models when constructing the collection using the [treeOf](#treeof) method.
13
+
14
+
## Methods
15
+
16
+
[[toc]]
17
+
18
+
#### treeOf
19
+
<Badgetext="static"type="warning"/>
20
+
21
+
The `treeOf` static method creates the AncestryCollection from the given [ModelCollection](./model-collection.md). This arranges the models to as the child of their respective models. Optionally the method takes 2 more arguments:
22
+
-`parentKey` (default: `'parentId'`) - the name of the attribute that contains the parent's identifier.
23
+
-`childrenRelation` (default: `'children'`): - the name of the relation the child models are nested under.
24
+
25
+
This will also assign the [depth](#depthname) value to the model based on its position on the tree.
The `leaves` method returns a [ModelCollection](./model-collection.md) containing all the models that does not have any children. With the analogy of a tree, it will not include roots, branches, only the models at the end of the bloodline.
The `isAncestryCollection` static method same as the [isModelCollection](./model-collection.md#ismodelcollection) method on the ModelCollection, is used to evaluate that the given value is an AncestryCollection.
Copy file name to clipboardExpand all lines: docs/calliope/attributes.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,9 @@ Casting transforms values when accessing or setting attributes on a model.
14
14
To define the casters on your model you should define a getter for the `casts` property.
15
15
16
16
<CodeGroup>
17
+
17
18
<CodeGroupItemtitle="Javascript">
19
+
18
20
```js
19
21
// User.js
20
22
import { Model } from'@upfrontjs/framework';
@@ -27,9 +29,11 @@ export default class User extends Model {
27
29
}
28
30
}
29
31
```
32
+
30
33
</CodeGroupItem>
31
34
32
35
<CodeGroupItemtitle="Typescript">
36
+
33
37
```ts
34
38
// User.ts
35
39
import { Model } from'@upfrontjs/framework';
@@ -44,7 +48,9 @@ export default class User extends Model {
44
48
}
45
49
}
46
50
```
51
+
47
52
</CodeGroupItem>
53
+
48
54
</CodeGroup>
49
55
50
56
**The following cast types are available:**
@@ -66,14 +72,17 @@ Casts the values to a [Collection](../helpers/collection.md) by calling the coll
66
72
67
73
#### `'datetime'`
68
74
69
-
Cast the values to the [given date time](../helpers/global-config.md#datetime) by calling the method or its constructor. If no date time defined in the config by default it will construct a new [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object with the value.
75
+
Cast the values to the [given date time](../helpers/global-config.md#datetime) by calling the method or its constructor.
76
+
Default: If no date time defined in the config by default it will construct a new [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object with the value. This when receives a `null` value it will return `null` instead of a `Date` set to unix epoch.
70
77
71
78
#### custom object
72
79
73
80
This is an object which implements the `AttributeCaster` type. Meaning it has a `get` and a `set` method both of which accepts a value, and an `Attributes` object (the equivalent of [getRawAttributes](#getrawattributes)) argument.
74
81
75
82
<CodeGroup>
83
+
76
84
<CodeGroupItemtitle="Javascript">
85
+
77
86
```js
78
87
// User.js
79
88
import { Model } from'@upfrontjs/framework';
@@ -96,6 +105,7 @@ export default class User extends Model {
96
105
</CodeGroupItem>
97
106
98
107
<CodeGroupItemtitle="Typescript">
108
+
99
109
```ts
100
110
// User.ts
101
111
import { Model } from'@upfrontjs/framework';
@@ -116,7 +126,9 @@ export default class User extends Model {
Copy file name to clipboardExpand all lines: docs/calliope/model-collection.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@ ModelCollection is a subclass of the [Collection](../helpers/collection.md), the
4
4
5
5
## Methods
6
6
7
+
[[toc]]
8
+
7
9
#### modelKeys
8
10
9
11
The `modelKeys` method returns the [primary key](./readme.md#getkey) of the models on a Collection.
@@ -29,6 +31,7 @@ modelCollection.findByKey(43, defaultModel); // Model
29
31
```
30
32
31
33
#### isModelCollection
34
+
<Badgetext="static"type="warning"/>
32
35
33
36
The `isModelCollection` static method same as the [isCollection](../helpers/collection.md#iscollection) method on the collection, is used to evaluate that the given value is a ModelCollection.
@@ -218,6 +221,85 @@ export default class Model extends BaseModel implements FormatsQueryParameters {
218
221
219
222
Now if our other models extend our own model they will have the option to set the `appends` field on the outgoing requests.
220
223
224
+
#### Using it with automated query builder packages
225
+
226
+
For even more convenience the package can be adjusted to be used with some sort of automated query parsing code on the backend.
227
+
Closely similar to [query builder extending](#extend-query-builder-functionality) you may create a more generalised approach to allow setting such query params.
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.
Copy file name to clipboardExpand all lines: docs/getting-started/installation.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,23 @@
1
1
# Installation
2
2
3
3
<CodeGroup>
4
+
4
5
<CodeGroupItemtitle="npm">
6
+
5
7
```shell
6
8
npm install @upfrontjs/framework
7
9
```
10
+
8
11
</CodeGroupItem>
9
12
10
13
<CodeGroupItemtitle="yarn">
14
+
11
15
```shell
12
16
yarn install @upfrontjs/framework
13
17
```
18
+
14
19
</CodeGroupItem>
20
+
15
21
</CodeGroup>
16
22
17
23
The library is transpiled to ES6 (currently the lowest supported version), but if you're using [Typescript](https://www.typescriptlang.org/), you could choose to use the source `.ts` files. To do so, import files from `/src` folder as opposed to the library root.
Copy file name to clipboardExpand all lines: docs/getting-started/readme.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,12 +14,11 @@ const excellentStudentNames = students
14
14
```
15
15
16
16
## What does it solve?
17
-
There are number of solutions out there for fetching data and working with the response. However not all of these might be as scalable as one would hope. With state management, you might have a getter for users, but those users include all users, meaning for a custom collection you would need a new getter method. An on-demand ajax request written specifically to solve a single issue, while it is simple to do, it quickly gets repetitive and hard to maintain. [Upfront](./installation.md) solves the above by creating abstraction over the data in a unified api. Just like the above examples it can be used to fetch data on demand or be complimentary to state management libraries.
17
+
There are number of solutions out there for fetching data and working with the response. However not all of these might be as maintainable as one would hope. With state management, you might have a getter for users, but those users include all users, meaning for a custom collection you would need a new getter method. An on-demand ajax request written specifically to solve a single issue, while it is simple to do, it quickly gets repetitive and laborious to maintain. [Upfront](./installation.md) solves the above by creating abstraction over the data in a unified api. Just like the above examples it can be used to fetch data on demand or be complimentary to state management libraries.
18
18
19
19
## Caveats
20
20
While using this package increases ease of access and cuts down development time, it can also have unintended consequences. By pushing more logic to the client side you may expose backend logic such as data relations. Furthermore, if you're incorrectly implementing the [backend requirements](./installation.md#backend-requirements) you may introduce vulnerabilities such as sql injection.
21
21
22
22
---
23
23
24
24
As always you're encouraged to explore the [source](https://github.com/upfrontjs/framework) yourself or look at the [api reference](https://upfrontjs.github.io/framework/) to gain insight on how the package works, and the [tests](https://github.com/upfrontjs/framework/tree/main/tests) to see how it's used.
0 commit comments