ember-data-resources 4.0.4 → 5.1.0

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.
Files changed (109) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +11 -9
  3. package/addon-main.cjs +5 -0
  4. package/dist/-private/find.js +2 -0
  5. package/dist/-private/find.js.map +1 -0
  6. package/dist/-private/query.js +2 -0
  7. package/dist/-private/query.js.map +1 -0
  8. package/dist/-private/resources/errors.js +13 -0
  9. package/dist/-private/resources/errors.js.map +1 -0
  10. package/dist/-private/resources/find-all.js +30 -0
  11. package/dist/-private/resources/find-all.js.map +1 -0
  12. package/dist/-private/resources/find-record.js +44 -0
  13. package/dist/-private/resources/find-record.js.map +1 -0
  14. package/dist/-private/resources/query-record.js +30 -0
  15. package/dist/-private/resources/query-record.js.map +1 -0
  16. package/dist/-private/resources/query.js +30 -0
  17. package/dist/-private/resources/query.js.map +1 -0
  18. package/dist/-private/resources/request.js +9 -0
  19. package/dist/-private/resources/request.js.map +1 -0
  20. package/dist/-private/resources/types.js +2 -0
  21. package/dist/-private/resources/types.js.map +1 -0
  22. package/dist/_app_/helpers/find-all.js +1 -0
  23. package/dist/_app_/helpers/find-record.js +1 -0
  24. package/dist/_app_/helpers/query-record.js +1 -0
  25. package/dist/_app_/helpers/query.js +1 -0
  26. package/dist/index.js +6 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/js-helpers.js +88 -0
  29. package/dist/js-helpers.js.map +1 -0
  30. package/dist/loose-mode-compat/helpers/find-all.js +9 -0
  31. package/dist/loose-mode-compat/helpers/find-all.js.map +1 -0
  32. package/dist/loose-mode-compat/helpers/find-record.js +9 -0
  33. package/dist/loose-mode-compat/helpers/find-record.js.map +1 -0
  34. package/dist/loose-mode-compat/helpers/query-record.js +9 -0
  35. package/dist/loose-mode-compat/helpers/query-record.js.map +1 -0
  36. package/dist/loose-mode-compat/helpers/query.js +9 -0
  37. package/dist/loose-mode-compat/helpers/query.js.map +1 -0
  38. package/dist/request-rVKgKutp.js +141 -0
  39. package/dist/request-rVKgKutp.js.map +1 -0
  40. package/dist-types/-private/find.d.ts +2 -0
  41. package/dist-types/-private/find.d.ts.map +1 -0
  42. package/dist-types/-private/query.d.ts +1 -0
  43. package/dist-types/-private/query.d.ts.map +1 -0
  44. package/dist-types/-private/resources/errors.d.ts +7 -0
  45. package/dist-types/-private/resources/errors.d.ts.map +1 -0
  46. package/dist-types/-private/resources/find-all.d.ts +18 -0
  47. package/dist-types/-private/resources/find-all.d.ts.map +1 -0
  48. package/dist-types/-private/resources/find-record.d.ts +18 -0
  49. package/dist-types/-private/resources/find-record.d.ts.map +1 -0
  50. package/dist-types/-private/resources/query-record.d.ts +19 -0
  51. package/dist-types/-private/resources/query-record.d.ts.map +1 -0
  52. package/dist-types/-private/resources/query.d.ts +20 -0
  53. package/dist-types/-private/resources/query.d.ts.map +1 -0
  54. package/dist-types/-private/resources/request.d.ts.map +1 -0
  55. package/dist-types/-private/resources/types.d.ts +2 -0
  56. package/dist-types/-private/resources/types.d.ts.map +1 -0
  57. package/dist-types/defineProperty-796354a6.d.ts +2 -0
  58. package/dist-types/index.d.ts +5 -0
  59. package/dist-types/index.d.ts.map +1 -0
  60. package/dist-types/js-helpers.d.ts +16 -0
  61. package/dist-types/js-helpers.d.ts.map +1 -0
  62. package/dist-types/loose-mode-compat/helpers/find-all.d.ts +2 -0
  63. package/dist-types/loose-mode-compat/helpers/find-all.d.ts.map +1 -0
  64. package/dist-types/loose-mode-compat/helpers/find-record.d.ts +2 -0
  65. package/dist-types/loose-mode-compat/helpers/find-record.d.ts.map +1 -0
  66. package/dist-types/loose-mode-compat/helpers/query-record.d.ts +2 -0
  67. package/dist-types/loose-mode-compat/helpers/query-record.d.ts.map +1 -0
  68. package/dist-types/loose-mode-compat/helpers/query.d.ts +2 -0
  69. package/dist-types/loose-mode-compat/helpers/query.d.ts.map +1 -0
  70. package/{-private/resources/request.d.ts → dist-types/request-rVKgKutp.d.ts} +13 -6
  71. package/dist-types/toPropertyKey-796354a6.d.ts +4 -0
  72. package/package.json +116 -127
  73. package/-private/find.d.ts +0 -1
  74. package/-private/query.d.ts +0 -1
  75. package/-private/resources/errors.d.ts +0 -7
  76. package/-private/resources/find-all.d.ts +0 -19
  77. package/-private/resources/find-record.d.ts +0 -19
  78. package/-private/resources/query-record.d.ts +0 -20
  79. package/-private/resources/query.d.ts +0 -21
  80. package/-private/resources/types.d.ts +0 -2
  81. package/.github/renovate.json5 +0 -93
  82. package/.github/workflows/ci.yml +0 -104
  83. package/.github/workflows/lint.yml +0 -101
  84. package/.github/workflows/types.yml +0 -46
  85. package/CHANGELOG.md +0 -257
  86. package/addon/-private/query.ts +0 -0
  87. package/addon/-private/resources/errors.ts +0 -15
  88. package/addon/-private/resources/find-all.ts +0 -37
  89. package/addon/-private/resources/find-record.ts +0 -53
  90. package/addon/-private/resources/query-record.ts +0 -38
  91. package/addon/-private/resources/query.ts +0 -39
  92. package/addon/-private/resources/request.ts +0 -113
  93. package/addon/-private/resources/types.ts +0 -1
  94. package/addon/index.ts +0 -10
  95. package/addon/js-helpers.ts +0 -127
  96. package/app/helpers/find-all.js +0 -1
  97. package/app/helpers/find-record.js +0 -1
  98. package/app/helpers/query-record.js +0 -1
  99. package/app/helpers/query.js +0 -1
  100. package/commitlint.config.js +0 -18
  101. package/config/environment.js +0 -5
  102. package/index.d.ts +0 -6
  103. package/index.js +0 -11
  104. package/js-helpers.d.ts +0 -21
  105. package/tsconfig.json +0 -101
  106. package/types/dummy/index.d.ts +0 -1
  107. package/types/ember-data/types/registries/model.d.ts +0 -6
  108. package/types/global.d.ts +0 -6
  109. /package/{addon/-private/find.ts → dist-types/-private/resources/request.d.ts} +0 -0
@@ -1,113 +0,0 @@
1
- import { tracked } from '@glimmer/tracking';
2
- import { assert } from '@ember/debug';
3
- import { isDestroyed, isDestroying } from '@ember/destroyable';
4
- import { action } from '@ember/object';
5
- import { inject as service } from '@ember/service';
6
- import { waitFor, waitForPromise } from '@ember/test-waiters';
7
-
8
- import { Resource } from 'ember-resources';
9
-
10
- import type Store from '@ember-data/store';
11
- import type { ExpandArgs } from 'ember-resources';
12
-
13
- export type FindRecordOptions = Parameters<Store['findRecord']>[2];
14
-
15
- export class Request<Args> extends Resource<Args> {
16
- @service declare store: Store;
17
-
18
- @tracked error: Error | undefined;
19
- @tracked isLoading = false;
20
- @tracked hasRan = false;
21
-
22
- /**
23
- * Args saved, untracked, for retrying
24
- */
25
- declare positional: ExpandArgs<Args>['Positional'];
26
- declare named: ExpandArgs<Args>['Named'];
27
-
28
- modify(positional: ExpandArgs<Args>['Positional'], named: ExpandArgs<Args>['Named']) {
29
- this.positional = positional;
30
- this.named = named;
31
-
32
- /**
33
- * We need to consume all arguments here so that we correctly respond to updates to
34
- * dirtied source data.
35
- *
36
- * e.g.: when an id changes that is passed to findRecord, we re-fetch.
37
- */
38
- this.__REQUEST_FUNCTION__([...(positional as unknown[])] as ExpandArgs<Args>['Positional'], {
39
- ...named,
40
- });
41
- }
42
-
43
- async __WRAPPED_FUNCTION__(
44
- _positional: ExpandArgs<Args>['Positional'],
45
- _named: ExpandArgs<Args>['Named']
46
- ) {
47
- throw new Error('Not Implemented');
48
- }
49
-
50
- get isSuccess() {
51
- return !this.error;
52
- }
53
-
54
- get isError() {
55
- return Boolean(this.error);
56
- }
57
-
58
- get records(): unknown | undefined {
59
- return assert(
60
- `The resource for ${this.constructor.name} does not have a records property. ` +
61
- `You might be looking for .record instead.`
62
- );
63
- }
64
-
65
- get record(): unknown | undefined {
66
- return assert(
67
- `The resource for ${this.constructor.name} does not have a record property. ` +
68
- `You might be looking for .records instead.`
69
- );
70
- }
71
-
72
- @action async retry() {
73
- return waitForPromise(this.__WRAPPED_FUNCTION__(this.positional, this.named));
74
- }
75
-
76
- @action
77
- @waitFor
78
- async __REQUEST_FUNCTION__(
79
- _positional: ExpandArgs<Args>['Positional'],
80
- _named: ExpandArgs<Args>['Named']
81
- ) {
82
- /**
83
- * Args are already consumed, but let's delay doing anything
84
- * until we can get out of a tracking frame.
85
- */
86
- await Promise.resolve();
87
-
88
- if (isDestroyed(this) || isDestroying(this)) return;
89
-
90
- this.error = undefined;
91
- this.isLoading = true;
92
-
93
- try {
94
- await this.retry();
95
- } catch (e) {
96
- if (isDestroyed(this) || isDestroying(this)) return;
97
-
98
- if (e instanceof Error) {
99
- this.error = e;
100
- } else {
101
- // How likely is this to happen?
102
- throw e;
103
- }
104
- }
105
-
106
- if (isDestroyed(this) || isDestroying(this)) {
107
- return;
108
- }
109
-
110
- this.isLoading = false;
111
- this.hasRan = true;
112
- }
113
- }
@@ -1 +0,0 @@
1
- export type Id = string | number | null | undefined;
package/addon/index.ts DELETED
@@ -1,10 +0,0 @@
1
- // For direct use in templates' strict Mode
2
- // for loose mode, these don't need to be imported, and are resolveable via
3
- // the lower-kebab-case variant of each of these names
4
- export { FindAll } from './-private/resources/find-all';
5
- export { FindRecord } from './-private/resources/find-record';
6
- export { Query } from './-private/resources/query';
7
- export { QueryRecord } from './-private/resources/query-record';
8
-
9
- // Resource wrappers in JS/TS classes
10
- export { findAll, findRecord, query, queryRecord } from './js-helpers';
@@ -1,127 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
- import { FindAll } from './-private/resources/find-all';
3
- import { FindRecord } from './-private/resources/find-record';
4
- import { Query } from './-private/resources/query';
5
- import { QueryRecord } from './-private/resources/query-record';
6
-
7
- import type { FindAllOptions } from './-private/resources/find-all';
8
- import type { FindRecordOptions } from './-private/resources/find-record';
9
- import type { QueryOptions, QueryQuery } from './-private/resources/query';
10
- import type { QueryRecordOptions, QueryRecordQuery } from './-private/resources/query-record';
11
- import type { Id } from './-private/resources/types';
12
-
13
- type FindRecordThunkResult = Id | [Id] | [Id, FindRecordOptions];
14
-
15
- export function findRecord<Model = unknown>(
16
- destroyable: object,
17
- modelName: string,
18
- thunk: () => FindRecordThunkResult
19
- ) {
20
- return FindRecord.from(destroyable, () => {
21
- let reified = thunk();
22
- let id: Id;
23
- let options: FindRecordOptions;
24
-
25
- if (Array.isArray(reified)) {
26
- id = reified[0];
27
- options = reified[1] ?? {};
28
- } else {
29
- id = reified as Id;
30
- options = {};
31
- }
32
-
33
- return {
34
- positional: [modelName, id],
35
- named: {
36
- options,
37
- },
38
- };
39
- // Cast needed Until min-supported TS is 4.7
40
- }) as FindRecord<Model>;
41
- }
42
-
43
- type FindAllThunkResult = { options: FindAllOptions } | FindAllOptions | void;
44
-
45
- export function findAll<Model = unknown>(
46
- destroyable: object,
47
- modelName: string,
48
- thunk?: () => FindAllThunkResult
49
- ) {
50
- return FindAll.from(destroyable, () => {
51
- let reified = thunk?.() || {};
52
- let options = 'options' in reified ? reified.options : reified;
53
-
54
- return {
55
- positional: [modelName],
56
- named: {
57
- options,
58
- },
59
- };
60
- // Cast needed Until min-supported TS is 4.7
61
- }) as FindAll<Model>;
62
- }
63
-
64
- type QueryThunkResult = QueryQuery | [QueryQuery] | [QueryQuery, QueryOptions];
65
-
66
- export function query<Model = unknown>(
67
- destroyable: object,
68
- modelName: string,
69
- thunk: () => QueryThunkResult
70
- ) {
71
- return Query.from(destroyable, () => {
72
- let reified = thunk();
73
-
74
- if (Array.isArray(reified)) {
75
- let [query, options] = reified;
76
-
77
- return {
78
- positional: [modelName, query],
79
- named: {
80
- options: options || {},
81
- },
82
- };
83
- }
84
-
85
- return {
86
- positional: [modelName, reified],
87
- named: {
88
- options: {},
89
- },
90
- };
91
- // Cast needed Until min-supported TS is 4.7
92
- }) as Query<Model>;
93
- }
94
-
95
- type QueryRecordThunkResult =
96
- | QueryRecordQuery
97
- | [QueryRecordQuery]
98
- | [QueryRecordQuery, QueryRecordOptions];
99
-
100
- export function queryRecord<Model = unknown>(
101
- destroyable: object,
102
- modelName: string,
103
- thunk: () => QueryRecordThunkResult
104
- ) {
105
- return QueryRecord.from(destroyable, () => {
106
- let reified = thunk();
107
-
108
- if (Array.isArray(reified)) {
109
- let [query, options] = reified;
110
-
111
- return {
112
- positional: [modelName, query],
113
- named: {
114
- options: options || {},
115
- },
116
- };
117
- }
118
-
119
- return {
120
- positional: [modelName, reified],
121
- named: {
122
- options: {},
123
- },
124
- };
125
- // Cast needed Until min-supported TS is 4.7
126
- }) as QueryRecord<Model>;
127
- }
@@ -1 +0,0 @@
1
- export { FindAll as default } from 'ember-data-resources/-private/resources/find-all';
@@ -1 +0,0 @@
1
- export { FindRecord as default } from 'ember-data-resources/-private/resources/find-record';
@@ -1 +0,0 @@
1
- export { QueryRecord as default } from 'ember-data-resources/-private/resources/query-record';
@@ -1 +0,0 @@
1
- export { Query as default } from 'ember-data-resources/-private/resources/query';
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- extends: ['@commitlint/config-conventional'],
5
- // https://commitlint.js.org/#/reference-rules
6
- // Level [0..2]: 0 disables the rule. For 1 it will be considered a warning for 2 an error.
7
- // Applicable always|never: never inverts the rule.
8
- // Value: value to use for this rule.
9
- rules: {
10
- // 72, the default, is a little short
11
- 'header-max-length': [1, 'always', 100],
12
- // Let people use caps
13
- 'header-case': [0],
14
- // Let people write sentences
15
- 'header-full-stop': [0],
16
- 'subject-case': [0],
17
- },
18
- };
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (/* environment, appConfig */) {
4
- return {};
5
- };
package/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export { FindAll } from './-private/resources/find-all';
2
- export { FindRecord } from './-private/resources/find-record';
3
- export { Query } from './-private/resources/query';
4
- export { QueryRecord } from './-private/resources/query-record';
5
- export { findAll, findRecord, query, queryRecord } from './js-helpers';
6
- //# sourceMappingURL=index.d.ts.map
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- name: require('./package').name,
5
-
6
- options: {
7
- 'ember-cli-babel': {
8
- enableTypeScriptTransform: true,
9
- },
10
- },
11
- };
package/js-helpers.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { FindAll } from './-private/resources/find-all';
2
- import { FindRecord } from './-private/resources/find-record';
3
- import { Query } from './-private/resources/query';
4
- import { QueryRecord } from './-private/resources/query-record';
5
- import type { FindAllOptions } from './-private/resources/find-all';
6
- import type { FindRecordOptions } from './-private/resources/find-record';
7
- import type { QueryOptions, QueryQuery } from './-private/resources/query';
8
- import type { QueryRecordOptions, QueryRecordQuery } from './-private/resources/query-record';
9
- import type { Id } from './-private/resources/types';
10
- declare type FindRecordThunkResult = Id | [Id] | [Id, FindRecordOptions];
11
- export declare function findRecord<Model = unknown>(destroyable: object, modelName: string, thunk: () => FindRecordThunkResult): FindRecord<Model, import("./-private/resources/find-record").Args>;
12
- declare type FindAllThunkResult = {
13
- options: FindAllOptions;
14
- } | FindAllOptions | void;
15
- export declare function findAll<Model = unknown>(destroyable: object, modelName: string, thunk?: () => FindAllThunkResult): FindAll<Model, import("./-private/resources/find-all").Args>;
16
- declare type QueryThunkResult = QueryQuery | [QueryQuery] | [QueryQuery, QueryOptions];
17
- export declare function query<Model = unknown>(destroyable: object, modelName: string, thunk: () => QueryThunkResult): Query<Model, import("./-private/resources/query").Args>;
18
- declare type QueryRecordThunkResult = QueryRecordQuery | [QueryRecordQuery] | [QueryRecordQuery, QueryRecordOptions];
19
- export declare function queryRecord<Model = unknown>(destroyable: object, modelName: string, thunk: () => QueryRecordThunkResult): QueryRecord<Model, import("./-private/resources/query-record").Args>;
20
- export {};
21
- //# sourceMappingURL=js-helpers.d.ts.map
package/tsconfig.json DELETED
@@ -1,101 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2021",
4
- "module": "ES2020",
5
- "moduleResolution": "node",
6
-
7
- // Trying to check Ember apps and addons with `allowJs: true` is a recipe
8
- // for many unresolveable type errors, because with *considerable* extra
9
- // configuration it ends up including many files which are *not* valid and
10
- // cannot be: they *appear* to be resolve-able to TS, but are in fact not in
11
- // valid Node-resolveable locations and may not have TS-ready types. This
12
- // will likely improve over time
13
- "allowJs": false,
14
-
15
- // --- TS for SemVer Types compatibility
16
- // Strictness settings -- you should *not* change these: Ember code is not
17
- // guaranteed to type check with these set to looser values.
18
- "strict": true,
19
- "noUncheckedIndexedAccess": true,
20
-
21
- // Interop: these are viral and will require anyone downstream of your
22
- // package to *also* set them to true. If you *must* enable them to consume
23
- // an upstream package, you should document that for downstream consumers to
24
- // be aware of.
25
- //
26
- // These *are* safe for apps to enable, since they do not *have* downstream
27
- // consumers; but leaving them off is still preferred when possible, since
28
- // it makes it easier to switch between apps and addons and have the same
29
- // rules for what can be imported and how.
30
- "allowSyntheticDefaultImports": false,
31
- "esModuleInterop": false,
32
-
33
- // --- Lint-style rules
34
-
35
- // TypeScript also supplies some lint-style checks; nearly all of them are
36
- // better handled by ESLint with the `@typescript-eslint`. This one is more
37
- // like a safety check, though, so we leave it on.
38
- "noPropertyAccessFromIndexSignature": true,
39
-
40
- // --- Compilation/integration settings
41
- // Setting `noEmitOnError` here allows ember-cli-typescript to catch errors
42
- // and inject them into Ember CLI's build error reporting, which provides
43
- // nice feedback for when
44
- "noEmitOnError": false,
45
-
46
- // We use Babel for emitting runtime code, because it's very important that
47
- // we always and only use the same transpiler for non-stable features, in
48
- // particular decorators. If you were to change this to `true`, it could
49
- // lead to accidentally generating code with `tsc` instead of Babel, and
50
- // could thereby result in broken code at runtime.
51
- "noEmit": true,
52
-
53
- // Ember makes heavy use of decorators; TS does not support them at all
54
- // without this flag.
55
- "experimentalDecorators": true,
56
-
57
- // Support generation of source maps. Note: you must *also* enable source
58
- // maps in your `ember-cli-babel` config and/or `babel.config.js`.
59
- "declaration": true,
60
- "declarationMap": true,
61
- "inlineSourceMap": true,
62
- "inlineSources": true,
63
-
64
- // The combination of `baseUrl` with `paths` allows Ember's classic package
65
- // layout, which is not resolveable with the Node resolution algorithm, to
66
- // work with TypeScript.
67
- "baseUrl": ".",
68
- "paths": {
69
- "dummy/tests/*": [
70
- "tests/*"
71
- ],
72
- "dummy/*": [
73
- "tests/dummy/app/*",
74
- "app/*"
75
- ],
76
- "ember-data-resources": [
77
- "addon"
78
- ],
79
- "ember-data-resources/*": [
80
- "addon/*"
81
- ],
82
- "ember-data-resources/test-support": [
83
- "addon-test-support"
84
- ],
85
- "ember-data-resources/test-support/*": [
86
- "addon-test-support/*"
87
- ],
88
- "*": [
89
- "types/*"
90
- ]
91
- }
92
- },
93
- "include": [
94
- "app/**/*",
95
- "addon/**/*",
96
- "tests/**/*",
97
- "types/**/*",
98
- "test-support/**/*",
99
- "addon-test-support/**/*"
100
- ]
101
- }
@@ -1 +0,0 @@
1
-
@@ -1,6 +0,0 @@
1
- /**
2
- * Catch-all for ember-data.
3
- */
4
- export default interface ModelRegistry {
5
- [key: string]: any;
6
- }
package/types/global.d.ts DELETED
@@ -1,6 +0,0 @@
1
- // Types for compiled templates
2
- declare module 'ember-data-resources/templates/*' {
3
- import { TemplateFactory } from 'htmlbars-inline-precompile';
4
- const tmpl: TemplateFactory;
5
- export default tmpl;
6
- }