Skip to content

Commit

Permalink
feat: 0.11.0 (#214)
Browse files Browse the repository at this point in the history
## Continious Integration
* ci: updated setup node actions
* ci: added concurrency cancelling in workflows
* ci: removed redundant caching
  * release workflow is not something that is frequently ran

## Feature
* feat(api-calls): updated visibility modifier of `setLastSyncedAt`
  * In practice this has been reached for on enough occasions to warrant the change
* feat(collection): added `orderBy` method
* feat(helpers): added `transformKeys` utility
  * Extracted logic from model for use outside of models.

## Chore
* chore: turned on `noImplicitOverride` config
  * With the intention that this would help with maintainability of the codebase
* chore: incremented version
* chore(deps-dev): updated dependencies
* chore(deps-dev): updated eslint plugins
* chore: fixed eslint issues
* chore: bumped current node version

## Documentation
* docs(api-calls): documented `setLastSyncedAt`
* docs: added best practices section
* docs(services): corrected example output
* docs: organised testing section better
* docs: updated wording

## Fix
* fix(helpers): fixed `DeepPartial` logic
  • Loading branch information
nandi95 authored Jun 16, 2022
1 parent 10ec3b2 commit a969868
Show file tree
Hide file tree
Showing 54 changed files with 3,908 additions and 3,434 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ jobs:
timeout-minutes: 10
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
cache: 'npm'
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build api docs
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ jobs:
timeout-minutes: 10
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
cache: 'npm'
- name: Install dependencies
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - uses: actions/setup-node@v2
# - uses: actions/setup-node@v3
# with:
# node-version: 15
# check-latest: true
Expand All @@ -40,10 +40,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build library
Expand All @@ -52,7 +51,7 @@ jobs:
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
registry-url: https://npm.pkg.github.com/
- run: npm publish --access public
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ jobs:
strategy:
matrix:
# current and active LTS
node: [ 16, 17 ]
node: [ 16, 18 ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: ${{ matrix.node }}
Expand Down
21 changes: 21 additions & 0 deletions docs/calliope/api-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,24 @@ const user = new User;
user.getEndpoint(); // 'users'
user.appendToEndpoint('/something').getEndpoint(); // 'users/something'
```

### Miscellaneous

#### setLastSyncedAt
<Badge text="advanced" type="warning"/>

The `setLastSyncedAt` method sets the [_lastSyncedAt](#_lastsyncedat) attribute to the current [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). It optionally also accepts an argument for the value to be set as. The set value is subject to the [date-time casting](./attributes.md#datetime).

::: warning
This method should only really be used when mocking the model to look like it exists. Some possible use-cases are:
- Testing a model.
- Hydrating a model with known to existing record.
:::

```js
import User from '@Models/User';

const user = User.create({ id: 1 });
user.exists; // false
user.setLastSyncedAt().exists; // true
```
11 changes: 4 additions & 7 deletions docs/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,10 @@ async function paginatedModels<T extends Model>(
): Promise<PaginatedModels<T>> {
const instance = builder instanceof Model ? builder.clone() : new builder();

const response = (await instance.limit(limit).page(page).call<PaginatedApiResponse<Attributes<T>>>('GET'))!;
const modelCollection = new ModelCollection<T>(response.data.map(attributes => {
return instance
.new(attributes)
// @ts-expect-error - Protected internal method required for correct .exists detection
.setLastSyncedAt();
}));
const response = await instance.limit(limit).page(page).call<PaginatedApiResponse<Attributes<T>>>('GET');
const modelCollection = new ModelCollection<T>(
response!.data.map(attributes => instance.new(attributes).setLastSyncedAt())
);

return {
data: modelCollection,
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ Given UpfrontJS is back-end agnostic, there are 2-3 requirements that needs to b
- `DELETE users/{id}` - delete a single user.

::: tip
Note that if you expect to experience high traffic for some unique data, you should probably still write a dedicated endpoint for it, instead of parsing the query and letting an ORM figure it out.
Note that if you expect to experience high traffic for some unique data, you should probably still write a dedicated RPC endpoint for it, instead of parsing the query and letting an ORM figure it out.
:::
28 changes: 28 additions & 0 deletions docs/helpers/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,34 @@ collection.dump('test'); // logged: '10:37:05 (test) - All items: 1,2,3,4,5'
collection.dump().take(2); // Collection[1, 2]
```

#### orderBy

When all items in the collections are objects, then you may order them using the `orderBy` method. The method takes one or more objects describing how the collection should be ordered. The object has two properties:

- `property` - the name of the property you want to order by OR a method that accepts the collection item and returns the nested value.
- `direction` - possible values are `asc`, `desc` respective to weather it should be in ascending or descending order.

```js
const elements = [
{ id: 2, nestedObj: { name: '2' } },
{ id: 1, nestedObj: { name: '5' } },
{ id: 1, nestedObj: { name: '1' } },
{ id: 4, nestedObj: { name: '4' } },
{ id: 3, nestedObj: { name: '3' } }
];

const collection = new Collection(elements);

collection.orderBy(
{ property: 'id', directions: 'asc' },
{ property: element => element.nestedObj.name, direction: 'desc' }
).at(1)!.nestedObj.name === '1'; // true

collection.orderBy(
{ property: element => element.nestedObj.name, direction: 'asc' }
).at(0)!.nestedObj.name === '1'; // true
```

#### toArray

The `toArray` method creates an [array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) from the collection.
Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/event-emitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ emitter.has(undefined, num => console.log(num)); // true
```
#### listenerCount

The `listenerCount` determines how many listeners are currently registered. If an event name is given only the listeners for the given event is counted.
The `listenerCount` determines how many listeners are currently registered. If an event name is given only the listeners for the given event are counted.

```ts
import { EventEmitter } from '@upfrontjs/framework';
Expand Down
7 changes: 6 additions & 1 deletion docs/prologue/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ I'd also love PRs. If you're thinking of a large PR, I advise opening up an issu

~~**Major** new features should always be sent to the `main` branch, which contains the upcoming release.~~

Until reaching a stable version (v1), all pull requests should start from `main` and with your changes go into `release/0.x`. After that `release/0.x` will gets merged into the `main` branch.
Until reaching a stable version (v1), all pull requests should start from `main` and with your changes go into `main`. After that `main` will gets merged into the `release/0.x` branch.

## Best pracrices

- The code should be self documenting. If a piece of logic might not be easy to reason by for a new contributor, consider adding a comment or two explaining the logic.
- The code should be written defensively to reduce the possible errors in the consuming applications. However a balance should be struck to avoid overhead and developer relying too much on the library. Throwing errors are also accepted where the developer will likely make a fatal mistake.

## Submitting a pull request

Expand Down
2 changes: 1 addition & 1 deletion docs/services/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ With the default settings, your api has to be ready to parse the requests with t
A sample get request `User.whereKey(1).get()` will encode to the following:

```http request
GET https://test-api-endpoint.com/users?wheres[][column]=id&wheres[][operator]=%3D&wheres[][value]=1&wheres[][boolean]=and
GET https://test-api-endpoint.com/users?wheres[0][column]=id&wheres[0][operator]=%3D&wheres[0][value]=1&wheres[0][boolean]=and
Content-type: application/x-www-form-urlencoded, charset=utf-8
Accept: application/json
```
Expand Down
Loading

0 comments on commit a969868

Please sign in to comment.