ember-data-resources 3.0.1 → 3.0.5

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.
@@ -1,3 +1,6 @@
1
- export declare class IdRequiredError extends Error {
1
+ export declare class IdRequiredError extends TypeError {
2
2
  constructor(modelName: string);
3
3
  }
4
+ export declare class IdTypeError extends TypeError {
5
+ constructor(modelName: string, id: unknown);
6
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [3.0.5](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.4...v3.0.5) (2022-02-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency ember-resources to ^4.3.0 ([7fda73e](https://github.com/NullVoxPopuli/ember-data-resources/commit/7fda73e4a94abefe225e0041846a662ce4ea9a5f))
7
+
8
+ ## [3.0.4](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.3...v3.0.4) (2022-01-31)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency ember-resources to ^4.2.0 ([7d202b8](https://github.com/NullVoxPopuli/ember-data-resources/commit/7d202b8ad378e47af8bfb08c21eb0909935ee80e))
14
+
15
+ ## [3.0.3](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.2...v3.0.3) (2022-01-21)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **deps:** update dependency ember-auto-import to ^2.4.0 ([b867f76](https://github.com/NullVoxPopuli/ember-data-resources/commit/b867f7669c79aff6eeb92e12dfde2614420b921a))
21
+
22
+ ## [3.0.2](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.1...v3.0.2) (2022-01-17)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **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)
28
+
1
29
  ## [3.0.1](https://github.com/NullVoxPopuli/ember-data-resources/compare/v3.0.0...v3.0.1) (2022-01-15)
2
30
 
3
31
 
@@ -1,7 +1,15 @@
1
- export class IdRequiredError extends Error {
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);
@@ -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 | undefined = undefined;
24
+ let id: Id;
25
25
  let options: FindRecordOptions;
26
26
 
27
- if (typeof reified === 'number') {
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-data-resources",
3
- "version": "3.0.1",
3
+ "version": "3.0.5",
4
4
  "description": "Resource helpers for reactively (re)fetching data with ember-data",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -30,20 +30,20 @@
30
30
  "dependencies": {
31
31
  "@ember/test-waiters": "^3.0.1",
32
32
  "@glimmer/tracking": "^1.0.4",
33
- "ember-auto-import": "^2.3.0",
33
+ "ember-auto-import": "^2.4.0",
34
34
  "ember-cli-babel": "^7.26.11",
35
35
  "ember-cli-htmlbars": "^6.0.1",
36
36
  "ember-cli-typescript": "^4.2.1",
37
- "ember-resources": "^4.1.3"
37
+ "ember-resources": "^4.3.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@commitlint/cli": "^16.0.2",
40
+ "@commitlint/cli": "^16.1.0",
41
41
  "@commitlint/config-conventional": "^16.0.0",
42
42
  "@ember/optional-features": "^2.0.0",
43
43
  "@ember/test-helpers": "^2.6.0",
44
- "@embroider/test-setup": "^0.50.2",
44
+ "@embroider/test-setup": "^1.0.0",
45
45
  "@glimmer/component": "^1.0.4",
46
- "@nullvoxpopuli/eslint-configs": "^2.1.17",
46
+ "@nullvoxpopuli/eslint-configs": "^2.1.18",
47
47
  "@semantic-release/changelog": "^6.0.1",
48
48
  "@semantic-release/git": "^10.0.1",
49
49
  "@types/ember-data__model": "^3.16.2",
@@ -70,11 +70,11 @@
70
70
  "@types/htmlbars-inline-precompile": "^1.0.1",
71
71
  "@types/qunit": "^2.11.3",
72
72
  "@types/rsvp": "^4.0.4",
73
- "@typescript-eslint/eslint-plugin": "^5.9.1",
74
- "@typescript-eslint/parser": "^5.9.1",
73
+ "@typescript-eslint/eslint-plugin": "^5.10.1",
74
+ "@typescript-eslint/parser": "^5.10.1",
75
75
  "babel-eslint": "^10.1.0",
76
76
  "broccoli-asset-rev": "^3.0.0",
77
- "ember-cli": "~4.1.0",
77
+ "ember-cli": "~4.1.1",
78
78
  "ember-cli-dependency-checker": "^3.2.0",
79
79
  "ember-cli-inject-live-reload": "^2.1.0",
80
80
  "ember-cli-sri": "^2.1.1",
@@ -102,14 +102,14 @@
102
102
  "eslint-plugin-qunit": "^7.2.0",
103
103
  "eslint-plugin-simple-import-sort": "^7.0.0",
104
104
  "loader.js": "^4.7.0",
105
- "msw": "^0.36.4",
105
+ "msw": "^0.36.8",
106
106
  "npm-run-all": "^4.1.5",
107
107
  "prettier": "^2.5.1",
108
108
  "qunit": "^2.17.2",
109
109
  "qunit-dom": "^2.0.0",
110
- "semantic-release": "^18.0.1",
111
- "typescript": "^4.5.4",
112
- "webpack": "^5.66.0"
110
+ "semantic-release": "^19.0.2",
111
+ "typescript": "^4.5.5",
112
+ "webpack": "^5.68.0"
113
113
  },
114
114
  "peerDependencies": {
115
115
  "ember-data": "^3.25.0"