Skip to content

Commit 2fc2146

Browse files
authored
feat: 0.17.0 (#354) (#355)
## 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
1 parent c0c0d68 commit 2fc2146

27 files changed

Lines changed: 2377 additions & 1448 deletions

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = {
4141
"eqeqeq": "error",
4242
"no-restricted-imports": "off",
4343
"lines-between-class-members": "off",
44+
"lines-around-comment": "off",
4445

4546
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules
4647
'@typescript-eslint/object-curly-spacing': ['warn', 'always'],
@@ -90,5 +91,13 @@ module.exports = {
9091
"@typescript-eslint/prefer-for-of": "off",
9192
"@typescript-eslint/no-restricted-imports": "off",
9293
"@typescript-eslint/lines-between-class-members": ["error"],
94+
"@typescript-eslint/lines-around-comment": ["warn", {
95+
"allowInterfaceStart": true,
96+
"allowBlockStart": true,
97+
"allowModuleStart": true,
98+
"allowTypeStart": true,
99+
"allowObjectStart": true,
100+
"allowClassStart": true,
101+
}]
93102
}
94103
}

docs/helpers/readme.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ transformKeys(obj); // { nestedObjects: [{ myKey: 1 }], myKey: 2 };
385385

386386
The `retry` method is a helper to retry a promise function a number of times if the promise rejects. The function takes 3 arguments:
387387
- `fn` - The function to retry
388-
- `maxRetries` (default: 3) - The number of times to retry.
389-
- `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.
388+
- `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.
389+
- `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.
390+
- `errorCheck` - An optional function that accepts the error and returns a boolean to determine whether to retry or not.
390391

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

401402
// Retry the function with progressively longer delays.
402403
const user2 = retry(User.all, 3, attemptNumber => attemptNumber * 1000);
404+
// Retry the request 3 times only if the error is of the expected error.
405+
retry(fetch('https://example.com'), 3, 1000, error => error instanceof Error && error.code === 429);
406+
// Retry 3 times with a delay of 1 second, 2 seconds and 3 seconds.
407+
retry(fetch('https://example.com'), [1000, 2000, 3000]);
408+
```
403409
```
404410
405411
#### dataGet
406412
407-
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`.
413+
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.
408414
409415
```js
410416
import { dataGet } from '@upfrontjs/framework';
@@ -414,9 +420,16 @@ import Shift from '~/Models/Shift';
414420
415421
const complexStructure = Team.factory().with(
416422
User.factory().with(Shift.factory().attributes({ id: 1 }))
417-
).makeMany();
423+
).createMany();
418424
419425
dataGet(complexStructure, '0.users.0.shifts.0.id') === 1; // true
426+
427+
const objectMatrix = [
428+
[{ id: 1 }, { id: 2 }],
429+
[{ id: 3 }, { id: 4 }]
430+
]
431+
dataGet(objectMatrix, '*.*.id'); // [1, 2, 3, 4]
432+
dataGet(objectMatrix, '*.*.name', []); // []
420433
```
421434

422435
#### value

jest.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ module.exports = {
2020
setupFilesAfterEnv: ['<rootDir>/tests/setupTests.ts'],
2121
errorOnDeprecated: true,
2222
bail: true,
23-
globals: {
24-
window: {},
25-
global: {}
26-
},
2723
sandboxInjectedGlobals: [
2824
'Function',
2925
'Array',

0 commit comments

Comments
 (0)