Skip to content

Commit c078528

Browse files
authored
feat: upstream release/0.x to main (#157)
## Docs * docs: fix incorrect info * docs: added recipe * Example on how to extend the model * docs(services): updated ApiResponseHandler signatures Changes missed in: 1e0b58f * docs: added remote pagination to recipes * docs: clarified back-end compatibility * docs: extended recipe with static method * docs: simplified examples * docs: added supporter section * docs: added clarifications * docs: added typescript tip for ApiResponse * Showed how to use module augmentation to extend the ApiResponse * docs: added reference to module augmentation docs * docs: added clarification * docs(attributes): added missing comma * docs: updated cookbook example to be more comprehensive ## Chore * chore: converted todo into an issue * chore: fixed .gitignore targeting * chore(deps-dev): updated dependencies * @semantic-release/git * @types/semantic-release * eslint-plugin-import * rollup * typedoc * chore: incremented version * chore: fixed incorrect bug report yml file * chore: added pull request template * chore: added search terms to the bug report template * chore: moved todo out into an issue * linked @upfrontjs/framework#151 * chore(deps-dev): updated non breaking dependencies * typescript * typedoc * rollup * semantic-release * @types/lodash * @types/uuid * chore(deps-dev): updated breaking dependencies * @typescript-eslint/eslint-plugin * @typescript-eslint/parser * eslint * eslint-plugin-jest * @commitlint/config-conventional * @commitlint/prompt-cli * @commitlint/types * lint-staged * chore(deps-dev): updated dependencies * @typescript-eslint/eslint-plugin * @typescript-eslint/parser * eslint * qs * rollup * commitlint * chore(deps-dev): lock typescript to 4.4.4 * Locking for the time being as 4.5.2 breaks the global config set typing. * The type is meant to be widened by the passed in value but, * on get it reckons it's an unknown value ## Feature * feat(query-builder): widened `formatQueryParameters` argument's type * added string indexing to allow arbitrary values to be assigned to `parameters` argument * feat(api-calls): added type argument to handle and call methods * feat(services)!: updated handling of non 200 responses * Throw response/error on client and server errors * Ignore informational, redirect and no content responses * feat(api-calls): added data unwrapping * feat(query-builder): added `page` method * feat(query-builder): hardened type handling of numeric query parameters * feat: added more utility types * Added KeysMatching and KeysNotMatching types * feat(global-config): updated type argument to accept arbitrary values * feat(attributes): added type support for keys defined on the model * feat(attributes): added missing type arguments * 7cf3ca6 * feat(api-calls)!: set _lastSyncedAt to cast to the set datetime value * feat: wip - worked on type inference of attributes * feat: added type arguments where applicable * feat!: updated `Jsonable` to return a json as opposed to string * The naming intended to return a json not a string. * Stringified version is only meant for saving or transferring data * feat(internal): added type arguments to methods in ModelCollection * feat(model): added toString method to the model * This will give a understandable format when juggling types * feat: added UnionToIntersection helper type * feat(query-builder): added type argument for static methods * feat(attributes): added `setServerStringCase` internal helper * feat(api-calls)!: moved data unwrapping into dedicated method * This way the user gets the the raw response exposed while utilising the model's call method * Furthermore as this is now public and all methods called them anyways, * moved the resetEndpoint and resetQueryParameters methods into the call method * feat(model): added `new` method * With this the user don't have to leave the model to construct a new instance. ## Test * test(internal): simplified test response customisation * test: increased test coverage * test(events): increased test coverage of EventEmitter * test: fixed type-hinting in test * test: fixed failing query building tests * test: fixed failing type in test #Refactor * refactor(internal): simplified getting the response model * refactor(attributes)!: from casting method removed attributes argument * Technically breaking change but it's is considered an internal method. * refactor(attributes): simplified date time casting * casting to date time logic has been moved into a single method * Furthermore, when using the built in Date, an error will be thrown on invalid values * refactor(helpers)!: renamed `isConstructableUserClass` function * `isUserLandClass` seems shorter while keeping the meaning * refactor(events): updated to use built-in Parameters type ## Fix * fix(services)!: removed data unwrapping from `ApiResponseHandler` * Response may include other keys such as `links`, `meta` and with the previous logic this would have been lost * fix(timestamps): access attribute name dynamically * Updated accessing timestamp names from class reference to constructor reference * fix(attributes): `set` on AttributeCaster have to return a value * This isn't a breaking change as `void` is assignable to `unknown` * fix(attributes)!: set index signature to `unknown` * Harden the user's type safety by updating from any to unknown * fix(attributes): resolved remaining typing issues * Fixed lingering issues missed in: * 66f5631 * fix!: fix `getName` returning wrong value after mangling for production * This isn't a breaking change but marking as such so people who do keep up with the release notes will not accidentally skim over it. * fix: removed unnecessary properties from ApiResponse type * This might be breaking typing for people using non-null assertion on Response properties * fix!: remove redundant ExtractArguments type * This is can be replaced by the built-in Parameters type * fix(query-builder)!: updated built-in column name casting * Fixed the column names to be in the expected serverAttributeCasing ## Continuous Integration * ci: adjust names and remove redundant cache actions * ci: ensure package is tested on the latest and LTS versions * ci: removed unnecessary argument * ci: run tests run on package updates too * ci: renamed action's name * ci: added api docs deployment action * ci: ensure both commit messages and PR titles are linted ## Performance * perf(model): improved `replicate` logic * with 1 warm up run, over 4 tries with 100,000 loops the average time: * with arguments: decreased by 177ms * without arguments: increased 20.75ms ## Style * style(attributes): removed unused code
1 parent da52e4e commit c078528

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4360
-3329
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ body:
1515
options:
1616
- label: I have searched the existing issues
1717
required: true
18+
- type: textarea
19+
id: search-terms
20+
attributes:
21+
label: Search terms
22+
description: The terms you searched for in the issues before opening a new issue.
23+
validations:
24+
required: true
1825
- type: textarea
1926
id: current-behaviour
2027
attributes:
@@ -55,7 +62,6 @@ body:
5562
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
5663
validations:
5764
required: false
58-
required: false
5965
- type: textarea
6066
id: reproduction
6167
attributes:

.github/pull_request_template.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!---
2+
☝️ PR title should follow conventional commits (https://conventionalcommits.org)
3+
4+
Please carefully read the contribution docs before creating a pull request
5+
👉 https://upfrontjs.com/prologue/contributing.html
6+
-->
7+
8+
### 🔗 Linked issue
9+
10+
<!-- Please ensure there is an open issue and mention its number as #123 -->
11+
12+
### ❓ Type of change
13+
14+
<!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. -->
15+
16+
- [ ] 📖 Documentation (updates to the documentation or readme)
17+
- [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
18+
- [ ] 👌 Enhancement (improving an existing functionality like performance)
19+
- [ ] ✨ New feature (a non-breaking change that adds functionality)
20+
- [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
21+
22+
### 📚 Description
23+
24+
<!-- Describe your changes in detail -->
25+
<!-- Why is this change required? What problem does it solve? -->
26+
<!-- If it resolves an open issue, please link to the issue here. For example "Resolves #1337" -->
27+
28+
### 📝 Checklist
29+
30+
<!-- Put an `x` in all the boxes that apply. -->
31+
<!-- If your change requires a documentation PR, please link it appropriately -->
32+
<!-- If you're unsure about any of these, don't hesitate to ask. -->
33+
34+
- [ ] I have linked an issue or discussion.
35+
- [ ] I have updated the documentation accordingly.
36+

.github/semantic.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://github.com/zeke/semantic-pull-requests#configuration
2+
3+
# Always validate the PR title AND all the commits
4+
titleAndCommits: true
5+
6+
# Allow use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns")
7+
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
8+
allowMergeCommits: true
9+
10+
# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"")
11+
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
12+
allowRevertCommits: true
13+
14+
# Scopes matching the ones defined in .commitlintrc.js file
15+
scopes:
16+
- 'attributes' # guarding and casting can also go under attributes
17+
- 'global-config'
18+
- 'exception'
19+
- 'events'
20+
- 'services'
21+
- 'helpers'
22+
- 'collection'
23+
- 'model'
24+
- 'model-collection'
25+
- 'paginator'
26+
- 'factory'
27+
- 'query-builder'
28+
- 'timestamps' # soft-deletes can also go under timestamps
29+
- 'relations'
30+
- 'api-calls'
31+
- 'deps'
32+
- 'deps-dev'
33+
- 'internal' # things that are not meant to be used outside of the package

.github/workflows/automerge.yml

-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ jobs:
1717
steps:
1818
- uses: tjenkinson/gh-action-auto-merge-dependency-updates@v1
1919
with:
20-
repo-token: ${{ secrets.GITHUB_TOKEN }}
2120
allowed-actors: dependabot-preview[bot], dependabot[bot]
2221
merge-method: squash

.github/workflows/build.yml

+2-9
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,15 @@ on:
1212
- 'release/*'
1313

1414
jobs:
15-
build:
15+
rollup:
1616
timeout-minutes: 10
1717
if: github.event.pull_request.draft == false
18-
name: Build
1918
runs-on: ubuntu-latest
2019
steps:
2120
- uses: actions/checkout@v2
2221
- uses: actions/setup-node@v2
23-
- uses: actions/cache@v2
2422
with:
25-
key: npm-${{ hashFiles('./package-lock.json') }}
26-
path: ~/.npm
27-
restore-keys: |
28-
npm-
29-
node-version: 15
30-
check-latest: true
23+
cache: 'npm'
3124
- run: npm ci
3225
- name: Rollup
3326
run: npm run build

.github/workflows/commitlint.yml

-18
This file was deleted.

.github/workflows/deploy-api-docs.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Deploy Api Docs
2+
3+
on:
4+
push:
5+
paths:
6+
- 'src/**/*.ts'
7+
branches:
8+
- main
9+
10+
jobs:
11+
deploy:
12+
timeout-minutes: 10
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v2
17+
- name: Install dependencies
18+
run: npm ci
19+
- name: Build api docs
20+
run: npm run docs:api
21+
- name: Update gh-pages branch
22+
run: |
23+
git config --global user.name "${{ github.actor }}"
24+
git add api-docs
25+
git commit -m "Updates from ${{ github.ref }}"
26+
git push -u origin gh-pages

.github/workflows/lint.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint
1+
name: Lint Code
22

33
on:
44
pull_request:
@@ -10,22 +10,15 @@ on:
1010
- 'release/*'
1111

1212
jobs:
13-
lint:
13+
eslint:
1414
timeout-minutes: 10
1515
if: github.event.pull_request.draft == false
16-
name: Lint
1716
runs-on: ubuntu-latest
1817
steps:
1918
- uses: actions/checkout@v2
2019
- uses: actions/setup-node@v2
21-
- uses: actions/cache@v2
2220
with:
23-
key: npm-${{ hashFiles('./package-lock.json') }}
24-
path: ~/.npm
25-
restore-keys: |
26-
npm-
27-
node-version: 15
28-
check-latest: true
21+
cache: 'npm'
2922
- run: npm ci
3023
- name: ESLint
3124
run: node node_modules/.bin/eslint . --ext .ts

.github/workflows/test.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ on:
88
- 'tests/**/*.ts'
99
- 'src/**/*.ts'
1010
- 'jest.config.js'
11+
- 'package-lock.json'
1112
branches:
1213
- main
1314
- 'release/*'
1415

1516
jobs:
16-
test:
17+
jest:
1718
timeout-minutes: 10
1819
if: github.event.pull_request.draft == false
19-
name: Test
2020
runs-on: ubuntu-latest
21+
strategy:
22+
matrix:
23+
node: [ 16, 17 ]
2124
steps:
2225
- uses: actions/checkout@v2
2326
- uses: actions/setup-node@v2
24-
- uses: actions/cache@v2
2527
with:
26-
key: npm-${{ hashFiles('./package-lock.json') }}
27-
path: ~/.npm
28-
restore-keys: |
29-
npm-
30-
node-version: 15
31-
check-latest: true
28+
cache: 'npm'
29+
node-version: ${{ matrix.node }}
3230
- run: npm ci
3331
- run: npm run test

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ index.*.js*
44
array.*.js*
55
string.*.js*
66
types
7-
.tgz
7+
*.tgz
88

99
# testing
1010
tests/cache/

TODO

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
Todos which are not concerning a single unit of code:
22

3-
todo - tinker with node support (take callsApi out)
4-
todo - arrange api-docs to be live
5-
todo - qs should not be a dependency if the user not using the API service
6-
todo - https://github.com/microsoft/TypeScript/issues/33079 figure out the package entries so user doesn't have to specify .es.min.js for string and array helpers and when using helpers in js the typings will be found
3+
todo - qs should not be a dependency if the user not using the API service (maybe interfaces and services should be separate packages?)

docs/calliope/api-calls.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ The `serverAttributeCasing` is a getter which similarly to [attributeCasing](./a
1818

1919
#### _lastSyncedAt
2020

21-
The `_lastSyncedAt` or `_last_synced_at` (naming subject to [attributeCasing](./attributes.md#attributecasing)) attribute is a getter attribute that is set only when the model data has been fetched, [saved](./readme.md#save) or [refreshed](./readme.md#refresh). It is a javascript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object indicating when was the last time the data has been loaded from the backend.
21+
The `_lastSyncedAt` or `_last_synced_at` (naming subject to [attributeCasing](./attributes.md#attributecasing)) attribute is a getter attribute that is set only when the model data has been fetched, [saved](./readme.md#save) or [refreshed](./readme.md#refresh). It is type subject to the [datetime](./attributes.md#datetime) setting, with the value of when was the last time the data has been loaded from the backend.
2222

2323
## Methods
2424

2525
::: tip
26-
All request methods on success will call the [resetEndpoint](#resetendpoint) and will reset the all the [query parameters](./query-building.md).
26+
All request methods on success will call the [resetEndpoint](#resetendpoint) and will reset all the [query parameters](./query-building.md).
2727
:::
2828

2929
#### get
@@ -118,7 +118,7 @@ import User from '@Models/User';
118118

119119
const user = new User;
120120
user.setEndpoint('/something').getEndpoint(); // '/something'
121-
user.resetEndpoint('/something').getEndpoint(); // 'users'
121+
user.resetEndpoint().getEndpoint(); // 'users'
122122
```
123123

124124
#### appendToEndpoint

docs/calliope/attributes.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ user.hasCast('test1'); // true
162162

163163
## Guarding
164164

165-
With models there are option to mass assign attributes to the model though the constructor or the [fill](#fill) method. However, when you're constructing your attributes dynamically, you may come across scenarios where you may not want every attribute assigned to the model on mass assignment. For these, there is an option to white and black list attribute keys.
165+
With models there are option to mass assign attributes to the model though the constructor or the [fill](#fill) methods. However, when you're constructing your attributes dynamically, you may come across scenarios where you may not want every attribute assigned to the model on mass assignment. For these, there is an option to white and black list attribute keys.
166166

167167
To define these rules, you create a `fillable` and/or `guarded` getter function which returns an array of strings.
168168
```js
@@ -300,7 +300,7 @@ export default class User extends Model {
300300
}
301301

302302
setFullNameAttribute(name) {
303-
return name.startsWith(this.title + ' ')
303+
this.attributes.fullName = name.startsWith(this.title + ' ')
304304
? name.slice(this.title.length + 1)
305305
: name;
306306
}

docs/calliope/query-building.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ User.skip(10);
390390
#### newQuery
391391
<Badge text="static only" type="warning"/>
392392

393-
The `newQuery` is a static method that returns the builder. You're not expected to use it as all methods are already available statically as well.
393+
The `newQuery` is a static method that returns the builder. You're not expected to use this as builder all methods are already available statically as well. However, if you still find that there are methods not available statically (like your own methods) you can use this.
394394

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

0 commit comments

Comments
 (0)