Skip to content

Commit

Permalink
feat: 0.17.0 (#354) (#355)
Browse files Browse the repository at this point in the history
## Feature:
* feat(helpers): add '*' as an accepted key to `dataGet`
  * Added collection as argument type
  * Added option to pass keys in as array or collection
  * Added a default value
* feat(helpers): added error check argument to the `retry` function
* feat(helpers): add typing to `ucFirst` function
* feat(helpers): add typing to `finish` function
* feat(helpers): add typing to `after` function
* feat(helpers): add typing to `afterLast` function
* feat(helpers): add typing to `before` function
* feat(helpers): add typing to `beforeLast` function
* feat(helpers): accept array of timeouts in `retry` function as shorthand
* feat(ancestry-collection): improved generic type of collection
* feat(helpers): add typing to `finish` function

## Testing:
* test(helpers): add `dataGet` tests
* test(collection): added partition test
  * ensure that partition returns the current collection type
* test(helpers): add `limit` test for not showing limiter after length
* test(ancestry-collection): remove folder properties now known

## Fix:
* fix(helpers): only include limiter when necessary with `words`
* fix(helpers): only include limiter when necessary with `limit`

## Refactor:
* refactor(helpers): rename argument in `dataGet`

## Chore:
* chore(internal): update jest config
* chore: increment version
* chore(deps-dev): updated dependencies
* chore: adjust lines-around-comment eslint rule
* chore: fix eslint issue

## Documentation:
* docs(helpers): update `dataGet` documentation
  • Loading branch information
nandi95 authored Mar 25, 2023
1 parent c0c0d68 commit 2fc2146
Show file tree
Hide file tree
Showing 27 changed files with 2,377 additions and 1,448 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
"eqeqeq": "error",
"no-restricted-imports": "off",
"lines-between-class-members": "off",
"lines-around-comment": "off",

// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules
'@typescript-eslint/object-curly-spacing': ['warn', 'always'],
Expand Down Expand Up @@ -90,5 +91,13 @@ module.exports = {
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/no-restricted-imports": "off",
"@typescript-eslint/lines-between-class-members": ["error"],
"@typescript-eslint/lines-around-comment": ["warn", {
"allowInterfaceStart": true,
"allowBlockStart": true,
"allowModuleStart": true,
"allowTypeStart": true,
"allowObjectStart": true,
"allowClassStart": true,
}]
}
}
21 changes: 17 additions & 4 deletions docs/helpers/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ transformKeys(obj); // { nestedObjects: [{ myKey: 1 }], myKey: 2 };

The `retry` method is a helper to retry a promise function a number of times if the promise rejects. The function takes 3 arguments:
- `fn` - The function to retry
- `maxRetries` (default: 3) - The number of times to retry.
- `delay` (default: 0) - The delay in milliseconds between retries. If the delay has been set to `0`, the function will run again as soon as the promise rejects. This could also be a function that accepts the current retry count and returns the delay.
- `maxRetries` (default: 3) - The number of times to retry. You may specify an array of timeouts as a shorthand for specifying the `maxRetries` and `timeout` arguments. If it is an array, the `timeout` argument will be ignored.
- `timeout` (default: 0) - The delay in milliseconds between retries. If the delay has been set to `0`, the function will run again as soon as the promise rejects. This could also be a function that accepts the current retry count and returns the delay.
- `errorCheck` - An optional function that accepts the error and returns a boolean to determine whether to retry or not.

```js
import { retry } from '@upfrontjs/framework';
Expand All @@ -400,11 +401,16 @@ const user = retry(async () => User.find(1), 3, 1000)

// Retry the function with progressively longer delays.
const user2 = retry(User.all, 3, attemptNumber => attemptNumber * 1000);
// Retry the request 3 times only if the error is of the expected error.
retry(fetch('https://example.com'), 3, 1000, error => error instanceof Error && error.code === 429);
// Retry 3 times with a delay of 1 second, 2 seconds and 3 seconds.
retry(fetch('https://example.com'), [1000, 2000, 3000]);
```
```
#### dataGet
The `dataGet` is a helper method to safely access any path within an object or array. If the path does not exist, it will return an `undefined`.
The `dataGet` is a helper method to safely access any path within an object or array. If the path does not exist, it will return the default value (default: `undefined`). Optionally the path may include a wildcard `*` to match array elements.
```js
import { dataGet } from '@upfrontjs/framework';
Expand All @@ -414,9 +420,16 @@ import Shift from '~/Models/Shift';
const complexStructure = Team.factory().with(
User.factory().with(Shift.factory().attributes({ id: 1 }))
).makeMany();
).createMany();
dataGet(complexStructure, '0.users.0.shifts.0.id') === 1; // true
const objectMatrix = [
[{ id: 1 }, { id: 2 }],
[{ id: 3 }, { id: 4 }]
]
dataGet(objectMatrix, '*.*.id'); // [1, 2, 3, 4]
dataGet(objectMatrix, '*.*.name', []); // []
```

#### value
Expand Down
4 changes: 0 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ module.exports = {
setupFilesAfterEnv: ['<rootDir>/tests/setupTests.ts'],
errorOnDeprecated: true,
bail: true,
globals: {
window: {},
global: {}
},
sandboxInjectedGlobals: [
'Function',
'Array',
Expand Down
Loading

0 comments on commit 2fc2146

Please sign in to comment.