ember-data-resources 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [3.0.2](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.1...v3.0.2) (2022-01-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **findRecord:** allow string ids, and fix array thunk usage ([1eeafb4](https://github.com/NullVoxPopuli/ember-data-resources/commit/1eeafb4a73791f7a0dba9bc82787cabee82f604b)), closes [PR#227](https://github.com/PR/issues/227)
|
|
7
|
+
|
|
1
8
|
## [3.0.1](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.0...v3.0.1) (2022-01-15)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
export class IdRequiredError extends
|
|
1
|
+
export class IdRequiredError extends TypeError {
|
|
2
2
|
constructor(modelName: string) {
|
|
3
3
|
super(
|
|
4
4
|
`While trying to request a resource from ${modelName}, the ID was either null or undefined, and the ID is required for fetching resources`
|
|
5
5
|
);
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export class IdTypeError extends TypeError {
|
|
10
|
+
constructor(modelName: string, id: unknown) {
|
|
11
|
+
super(
|
|
12
|
+
`While trying to request a resource from ${modelName}, the ID was of invalid type ${typeof id}: only string and number are supported`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -2,7 +2,7 @@ import { tracked } from '@glimmer/tracking';
|
|
|
2
2
|
import { isDestroyed, isDestroying } from '@ember/destroyable';
|
|
3
3
|
import { action } from '@ember/object';
|
|
4
4
|
|
|
5
|
-
import { IdRequiredError } from './errors';
|
|
5
|
+
import { IdRequiredError, IdTypeError } from './errors';
|
|
6
6
|
import { Request } from './request';
|
|
7
7
|
|
|
8
8
|
import type { Id } from './types';
|
|
@@ -37,6 +37,8 @@ export class FindRecord<Model, LocalArgs extends Args = Args> extends Request<Lo
|
|
|
37
37
|
*/
|
|
38
38
|
if (id === null || id === undefined) {
|
|
39
39
|
throw new IdRequiredError(modelName);
|
|
40
|
+
} else if (typeof id !== 'string' && typeof id !== 'number') {
|
|
41
|
+
throw new IdTypeError(modelName, id);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
let record = await this.store.findRecord(modelName as never, id, options);
|
package/addon/js-helpers.ts
CHANGED
|
@@ -21,15 +21,15 @@ export function findRecord<Model = unknown>(
|
|
|
21
21
|
) {
|
|
22
22
|
return useResource<FindRecord<Model>>(destroyable, FindRecord, () => {
|
|
23
23
|
let reified = thunk();
|
|
24
|
-
let id: Id
|
|
24
|
+
let id: Id;
|
|
25
25
|
let options: FindRecordOptions;
|
|
26
26
|
|
|
27
|
-
if (
|
|
28
|
-
id = reified;
|
|
27
|
+
if (Array.isArray(reified)) {
|
|
28
|
+
id = reified[0];
|
|
29
|
+
options = reified[1] ?? {};
|
|
30
|
+
} else {
|
|
31
|
+
id = reified as Id;
|
|
29
32
|
options = {};
|
|
30
|
-
} else if (Array.isArray(options)) {
|
|
31
|
-
id = options[0];
|
|
32
|
-
options = options[1] || {};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
return {
|