@warp-drive/legacy 5.6.0-alpha.15 → 5.6.0-alpha.18
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/declarations/adapter/-private/build-url-mixin.d.ts +41 -29
- package/declarations/adapter/-private/fastboot-interface.d.ts +4 -5
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +5 -6
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts +1 -2
- package/declarations/adapter/-private/utils/fetch.d.ts +2 -3
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +5 -6
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -2
- package/declarations/adapter/-private.d.ts +5 -6
- package/declarations/adapter/error.d.ts +206 -178
- package/declarations/adapter/json-api.d.ts +206 -207
- package/declarations/adapter/rest.d.ts +805 -808
- package/declarations/adapter.d.ts +742 -766
- package/declarations/compat/-private.d.ts +10 -11
- package/declarations/compat/builders/find-all.d.ts +26 -24
- package/declarations/compat/builders/find-record.d.ts +41 -39
- package/declarations/compat/builders/query.d.ts +50 -45
- package/declarations/compat/builders/save-record.d.ts +26 -24
- package/declarations/compat/builders/utils.d.ts +1 -2
- package/declarations/compat/builders.d.ts +10 -11
- package/declarations/compat/extensions.d.ts +52 -106
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +39 -38
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +9 -10
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +521 -517
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +214 -215
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts +5 -6
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +83 -84
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +228 -229
- package/declarations/compat/utils.d.ts +118 -119
- package/declarations/compat.d.ts +106 -104
- package/declarations/model/-private/attr.d.ts +164 -145
- package/declarations/model/-private/belongs-to.d.ts +135 -122
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +15 -4
- package/declarations/model/-private/errors.d.ts +272 -267
- package/declarations/model/-private/has-many.d.ts +119 -116
- package/declarations/model/-private/hooks.d.ts +5 -6
- package/declarations/model/-private/legacy-relationships-support.d.ts +51 -52
- package/declarations/model/-private/model-for-mixin.d.ts +18 -3
- package/declarations/model/-private/model-methods.d.ts +29 -24
- package/declarations/model/-private/model.d.ts +1306 -1254
- package/declarations/model/-private/notify-changes.d.ts +3 -4
- package/declarations/model/-private/promise-belongs-to.d.ts +33 -27
- package/declarations/model/-private/promise-many-array.d.ts +125 -116
- package/declarations/model/-private/record-state.d.ts +63 -60
- package/declarations/model/-private/references/belongs-to.d.ts +491 -487
- package/declarations/model/-private/references/has-many.d.ts +495 -492
- package/declarations/model/-private/schema-provider.d.ts +53 -56
- package/declarations/model/-private/type-utils.d.ts +41 -41
- package/declarations/model/-private/util.d.ts +1 -2
- package/declarations/model/-private.d.ts +8 -8
- package/declarations/model/migration-support.d.ts +281 -279
- package/declarations/model.d.ts +48 -49
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +70 -71
- package/declarations/serializer/-private/transforms/boolean.d.ts +37 -37
- package/declarations/serializer/-private/transforms/date.d.ts +22 -22
- package/declarations/serializer/-private/transforms/number.d.ts +22 -22
- package/declarations/serializer/-private/transforms/string.d.ts +22 -22
- package/declarations/serializer/-private/transforms/transform.d.ts +109 -110
- package/declarations/serializer/-private/utils.d.ts +0 -1
- package/declarations/serializer/json-api.d.ts +124 -494
- package/declarations/serializer/json.d.ts +62 -1031
- package/declarations/serializer/rest.d.ts +52 -552
- package/declarations/serializer/transform.d.ts +5 -6
- package/declarations/serializer.d.ts +217 -218
- package/dist/{-private-DFfBszo5.js → -private-CKrP0ogQ.js} +1 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +17 -0
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +5 -7
- package/dist/adapter.js +6 -35
- package/dist/compat/-private.js +1 -1
- package/dist/compat/extensions.js +0 -2
- package/dist/compat.js +3 -4
- package/dist/{errors-_QQ7xpSn.js → errors-BX5wowuz.js} +11 -10
- package/dist/{json-DSOlH9A8.js → json-Et4mt_LM.js} +84 -157
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +3 -4
- package/dist/model.js +3 -3
- package/dist/{schema-provider-D_P8ReX6.js → schema-provider-BdQhkT-Q.js} +20 -13
- package/dist/{serialize-into-hash-BxfqWC8u.js → serialize-into-hash-Bp58npke.js} +1 -1
- package/dist/serializer/json-api.js +42 -2
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +46 -41
- package/dist/serializer/transform.js +0 -44
- package/package.json +7 -7
- package/declarations/adapter/-private/build-url-mixin.d.ts.map +0 -1
- package/declarations/adapter/-private/fastboot-interface.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/fetch.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +0 -1
- package/declarations/adapter/-private.d.ts.map +0 -1
- package/declarations/adapter/error.d.ts.map +0 -1
- package/declarations/adapter/json-api.d.ts.map +0 -1
- package/declarations/adapter/rest.d.ts.map +0 -1
- package/declarations/adapter.d.ts.map +0 -1
- package/declarations/compat/-private.d.ts.map +0 -1
- package/declarations/compat/builders/find-all.d.ts.map +0 -1
- package/declarations/compat/builders/find-record.d.ts.map +0 -1
- package/declarations/compat/builders/query.d.ts.map +0 -1
- package/declarations/compat/builders/save-record.d.ts.map +0 -1
- package/declarations/compat/builders/utils.d.ts.map +0 -1
- package/declarations/compat/builders.d.ts.map +0 -1
- package/declarations/compat/extensions.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +0 -1
- package/declarations/compat/utils.d.ts.map +0 -1
- package/declarations/compat.d.ts.map +0 -1
- package/declarations/model/-private/attr.d.ts.map +0 -1
- package/declarations/model/-private/attr.type-test.d.ts +0 -2
- package/declarations/model/-private/attr.type-test.d.ts.map +0 -1
- package/declarations/model/-private/belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/belongs-to.type-test.d.ts +0 -2
- package/declarations/model/-private/belongs-to.type-test.d.ts.map +0 -1
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
- package/declarations/model/-private/errors.d.ts.map +0 -1
- package/declarations/model/-private/has-many.d.ts.map +0 -1
- package/declarations/model/-private/has-many.type-test.d.ts +0 -2
- package/declarations/model/-private/has-many.type-test.d.ts.map +0 -1
- package/declarations/model/-private/hooks.d.ts.map +0 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts.map +0 -1
- package/declarations/model/-private/model-for-mixin.d.ts.map +0 -1
- package/declarations/model/-private/model-methods.d.ts.map +0 -1
- package/declarations/model/-private/model.d.ts.map +0 -1
- package/declarations/model/-private/model.type-test.d.ts +0 -2
- package/declarations/model/-private/model.type-test.d.ts.map +0 -1
- package/declarations/model/-private/notify-changes.d.ts.map +0 -1
- package/declarations/model/-private/promise-belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/promise-many-array.d.ts.map +0 -1
- package/declarations/model/-private/promise-proxy-base.d.ts +0 -3
- package/declarations/model/-private/promise-proxy-base.d.ts.map +0 -1
- package/declarations/model/-private/record-state.d.ts.map +0 -1
- package/declarations/model/-private/references/belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/references/has-many.d.ts.map +0 -1
- package/declarations/model/-private/schema-provider.d.ts.map +0 -1
- package/declarations/model/-private/type-utils.d.ts.map +0 -1
- package/declarations/model/-private/util.d.ts.map +0 -1
- package/declarations/model/-private.d.ts.map +0 -1
- package/declarations/model/migration-support.d.ts.map +0 -1
- package/declarations/model/migration-support.type-test.d.ts +0 -2
- package/declarations/model/migration-support.type-test.d.ts.map +0 -1
- package/declarations/model.d.ts.map +0 -1
- package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/boolean.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +0 -2
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/date.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/number.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/string.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/transform.d.ts.map +0 -1
- package/declarations/serializer/-private/utils.d.ts.map +0 -1
- package/declarations/serializer/json-api.d.ts.map +0 -1
- package/declarations/serializer/json.d.ts.map +0 -1
- package/declarations/serializer/rest.d.ts.map +0 -1
- package/declarations/serializer/transform.d.ts.map +0 -1
- package/declarations/serializer.d.ts.map +0 -1
- package/dist/-private-DFfBszo5.js.map +0 -1
- package/dist/adapter/-private.js.map +0 -1
- package/dist/adapter/error.js.map +0 -1
- package/dist/adapter/json-api.js.map +0 -1
- package/dist/adapter/rest.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/compat/-private.js.map +0 -1
- package/dist/compat/builders.js.map +0 -1
- package/dist/compat/extensions.js.map +0 -1
- package/dist/compat/utils.js.map +0 -1
- package/dist/compat.js.map +0 -1
- package/dist/errors-_QQ7xpSn.js.map +0 -1
- package/dist/json-DSOlH9A8.js.map +0 -1
- package/dist/model/-private.js.map +0 -1
- package/dist/model/migration-support.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +0 -1
- package/dist/schema-provider-D_P8ReX6.js.map +0 -1
- package/dist/serialize-into-hash-BxfqWC8u.js.map +0 -1
- package/dist/serializer/json-api.js.map +0 -1
- package/dist/serializer/json.js.map +0 -1
- package/dist/serializer/rest.js.map +0 -1
- package/dist/serializer/transform.js.map +0 -1
- package/dist/serializer.js.map +0 -1
|
@@ -1,164 +1,167 @@
|
|
|
1
|
-
import type { TypeFromInstance } from
|
|
2
|
-
import type { NoNull, RelationshipDecorator, RelationshipOptions } from
|
|
1
|
+
import type { TypeFromInstance } from "@warp-drive/core/types/record";
|
|
2
|
+
import type { NoNull, RelationshipDecorator, RelationshipOptions } from "./belongs-to.js";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
`hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None
|
|
5
|
+
relationships on a [Model](/ember-data/release/classes/Model).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
`hasMany` takes a configuration hash as a second parameter, currently
|
|
8
|
+
supported options are:
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
- `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.
|
|
11
|
+
- `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.
|
|
12
|
+
- `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic
|
|
13
|
+
- `as`: (*optional*) A string used to declare the abstract type "this" record satisfies for polymorphism.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### Examples
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
To declare a **many-to-one** (or one-to-many) relationship, use
|
|
18
|
+
`belongsTo` in combination with `hasMany`:
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
```js
|
|
21
|
+
// app/models/post.js
|
|
22
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
export default class Post extends Model {
|
|
25
|
+
@hasMany('comment', { async: false, inverse: 'post' }) comments;
|
|
26
|
+
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// app/models/comment.js
|
|
30
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
export default class Comment extends Model {
|
|
33
|
+
@belongsTo('post', { async: false, inverse: 'comments' }) post;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
To declare a **many-to-many** relationship with managed inverses, use `hasMany` for both sides:
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
```js
|
|
40
|
+
// app/models/post.js
|
|
41
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
export default class Post extends Model {
|
|
44
|
+
@hasMany('tag', { async: true, inverse: 'posts' }) tags;
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// app/models/tag.js
|
|
48
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
export default class Tag extends Model {
|
|
51
|
+
@hasMany('post', { async: true, inverse: 'tags' }) posts;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
To declare a **many-to-many** relationship without managed inverses, use `hasMany` for both sides
|
|
56
|
+
with `null` as the inverse:
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
```js
|
|
59
|
+
// app/models/post.js
|
|
60
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
export default class Post extends Model {
|
|
63
|
+
@hasMany('tag', { async: true, inverse: null }) tags;
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// app/models/tag.js
|
|
67
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
export default class Tag extends Model {
|
|
70
|
+
@hasMany('post', { async: true, inverse: null }) posts;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
To declare a many-to-none relationship between two models, use
|
|
75
|
+
`hasMany` with inverse set to `null` on just one side::
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
```js
|
|
78
|
+
// app/models/post.js
|
|
79
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
export default class Post extends Model {
|
|
82
|
+
@hasMany('category', { async: true, inverse: null }) categories;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
#### Sync vs Async Relationships
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
EmberData fulfills relationships using resource data available in
|
|
89
|
+
the cache.
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
Sync relationships point directly to the known related resources.
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
When a relationship is declared as async, if any of the known related
|
|
94
|
+
resources have not been loaded, they will be fetched. The property
|
|
95
|
+
on the record when accessed provides a promise that resolves once
|
|
96
|
+
all resources are loaded.
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
Async relationships may take advantage of links. On access, if the related
|
|
99
|
+
link has not been loaded, or if any known resources are not available in
|
|
100
|
+
the cache, the fresh state will be fetched using the link.
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
In contrast to async relationship, accessing a sync relationship
|
|
103
|
+
will error on access when any of the known related resources have
|
|
104
|
+
not been loaded.
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
If you are using `links` with sync relationships, you have to use
|
|
107
|
+
the HasMany reference API to fetch or refresh related resources
|
|
108
|
+
that aren't loaded. For instance, for a `comments` relationship:
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
```js
|
|
111
|
+
post.hasMany('comments').reload();
|
|
112
|
+
```
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
#### Polymorphic Relationships
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
To declare a polymorphic relationship, use `hasMany` with the `polymorphic`
|
|
117
|
+
option set to `true`:
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
```js
|
|
120
|
+
// app/models/comment.js
|
|
121
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
export default class Comment extends Model {
|
|
124
|
+
@belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
`'commentable'` here is referred to as the "abstract type" for the polymorphic
|
|
129
|
+
relationship.
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
Polymorphic relationships with `inverse: null` will accept any type of record as their content.
|
|
132
|
+
Polymorphic relationships with `inverse` set to a string will only accept records with a matching
|
|
133
|
+
inverse relationships declaring itself as satisfying the abstract type.
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'
|
|
136
|
+
for this relationship.
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
```js
|
|
139
|
+
// app/models/post.js
|
|
140
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
export default class Post extends Model {
|
|
143
|
+
@hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
Note: every Model that declares an inverse to a polymorphic relationship must
|
|
148
|
+
declare itself exactly the same. This is because polymorphism is based on structural
|
|
149
|
+
traits.
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
Polymorphic to polymorphic relationships are supported. Both sides of the relationship
|
|
152
|
+
must be declared as polymorphic, and the `as` option must be used to declare the abstract
|
|
153
|
+
type each record satisfies on both sides.
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
@public
|
|
156
|
+
@param {String} type (optional) the name of the related resource
|
|
157
|
+
@param {Object} options (optional) a hash of options
|
|
158
|
+
@return {PropertyDescriptor} relationship
|
|
159
159
|
*/
|
|
160
160
|
export declare function hasMany(): never;
|
|
161
161
|
export declare function hasMany(type: string): never;
|
|
162
162
|
export declare function hasMany<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, boolean>): RelationshipDecorator<T>;
|
|
163
|
+
// export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
|
|
164
|
+
// type: TypeFromInstance<NoNull<T>>,
|
|
165
|
+
// options: RelationshipOptions<T, true>
|
|
166
|
+
// ): RelationshipDecorator<K>;
|
|
163
167
|
export declare function hasMany(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
|
|
164
|
-
//# sourceMappingURL=has-many.d.ts.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { type Store } from
|
|
2
|
-
import type { StableRecordIdentifier } from
|
|
3
|
-
import type { TypeFromInstance } from
|
|
4
|
-
import type { Model } from
|
|
1
|
+
import { type Store } from "@warp-drive/core/store/-private";
|
|
2
|
+
import type { StableRecordIdentifier } from "@warp-drive/core/types/identifier";
|
|
3
|
+
import type { TypeFromInstance } from "@warp-drive/core/types/record";
|
|
4
|
+
import type { Model } from "./model.js";
|
|
5
5
|
export declare function instantiateRecord(this: Store, identifier: StableRecordIdentifier, createRecordArgs: {
|
|
6
|
-
|
|
6
|
+
[key: string]: unknown;
|
|
7
7
|
}): Model;
|
|
8
8
|
export declare function teardownRecord(record: Model): void;
|
|
9
9
|
export declare function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;
|
|
10
10
|
export declare function modelFor(type: string): typeof Model | void;
|
|
11
|
-
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1,57 +1,56 @@
|
|
|
1
|
-
import type { Store } from
|
|
2
|
-
import type { CollectionEdge, Graph, ResourceEdge, UpgradedMeta } from
|
|
3
|
-
import type { LiveArray } from
|
|
4
|
-
import { RelatedCollection as ManyArray } from
|
|
5
|
-
import type { BaseFinderOptions, StableRecordIdentifier } from
|
|
6
|
-
import type { Cache } from
|
|
7
|
-
import type { CollectionRelationship } from
|
|
8
|
-
import type { LocalRelationshipOperation } from
|
|
9
|
-
import type { OpaqueRecordInstance, TypeFromInstanceOrString } from
|
|
10
|
-
import type { CollectionResourceRelationship, InnerRelationshipDocument, SingleResourceRelationship } from
|
|
11
|
-
import type { MinimalLegacyRecord } from
|
|
12
|
-
import type { BelongsToProxyCreateArgs } from
|
|
13
|
-
import { PromiseBelongsTo } from
|
|
14
|
-
import type { HasManyProxyCreateArgs } from
|
|
15
|
-
import { PromiseManyArray } from
|
|
16
|
-
import BelongsToReference from
|
|
17
|
-
import HasManyReference from
|
|
1
|
+
import type { Store } from "@warp-drive/core";
|
|
2
|
+
import type { CollectionEdge, Graph, ResourceEdge, UpgradedMeta } from "@warp-drive/core/graph/-private";
|
|
3
|
+
import type { LiveArray } from "@warp-drive/core/store/-private";
|
|
4
|
+
import { RelatedCollection as ManyArray } from "@warp-drive/core/store/-private";
|
|
5
|
+
import type { BaseFinderOptions, StableRecordIdentifier } from "@warp-drive/core/types";
|
|
6
|
+
import type { Cache } from "@warp-drive/core/types/cache";
|
|
7
|
+
import type { CollectionRelationship } from "@warp-drive/core/types/cache/relationship";
|
|
8
|
+
import type { LocalRelationshipOperation } from "@warp-drive/core/types/graph";
|
|
9
|
+
import type { OpaqueRecordInstance, TypeFromInstanceOrString } from "@warp-drive/core/types/record";
|
|
10
|
+
import type { CollectionResourceRelationship, InnerRelationshipDocument, SingleResourceRelationship } from "@warp-drive/core/types/spec/json-api-raw";
|
|
11
|
+
import type { MinimalLegacyRecord } from "./model-methods.js";
|
|
12
|
+
import type { BelongsToProxyCreateArgs } from "./promise-belongs-to.js";
|
|
13
|
+
import { PromiseBelongsTo } from "./promise-belongs-to.js";
|
|
14
|
+
import type { HasManyProxyCreateArgs } from "./promise-many-array.js";
|
|
15
|
+
import { PromiseManyArray } from "./promise-many-array.js";
|
|
16
|
+
import BelongsToReference from "./references/belongs-to.js";
|
|
17
|
+
import HasManyReference from "./references/has-many.js";
|
|
18
18
|
export declare const LEGACY_SUPPORT: Map<StableRecordIdentifier | MinimalLegacyRecord, LegacySupport>;
|
|
19
19
|
export declare function lookupLegacySupport(record: MinimalLegacyRecord): LegacySupport;
|
|
20
20
|
export declare class LegacySupport {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
21
|
+
record: MinimalLegacyRecord;
|
|
22
|
+
store: Store;
|
|
23
|
+
graph: Graph;
|
|
24
|
+
cache: Cache;
|
|
25
|
+
references: Record<string, BelongsToReference | HasManyReference>;
|
|
26
|
+
identifier: StableRecordIdentifier;
|
|
27
|
+
_manyArrayCache: Record<string, ManyArray>;
|
|
28
|
+
_relationshipPromisesCache: Record<string, Promise<ManyArray | OpaqueRecordInstance>>;
|
|
29
|
+
_relationshipProxyCache: Record<string, PromiseManyArray | PromiseBelongsTo | undefined>;
|
|
30
|
+
_pending: Record<string, Promise<StableRecordIdentifier | null> | undefined>;
|
|
31
|
+
isDestroying: boolean;
|
|
32
|
+
isDestroyed: boolean;
|
|
33
|
+
constructor(record: MinimalLegacyRecord);
|
|
34
|
+
_syncArray(array: LiveArray): void;
|
|
35
|
+
mutate(mutation: LocalRelationshipOperation): void;
|
|
36
|
+
_findBelongsTo(key: string, resource: SingleResourceRelationship, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
|
|
37
|
+
reloadBelongsTo(key: string, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
|
|
38
|
+
getBelongsTo(key: string, options?: BaseFinderOptions): PromiseBelongsTo | OpaqueRecordInstance | null;
|
|
39
|
+
setDirtyBelongsTo(key: string, value: OpaqueRecordInstance | null): void;
|
|
40
|
+
_getCurrentState<T>(identifier: StableRecordIdentifier, field: string): [StableRecordIdentifier<TypeFromInstanceOrString<T>>[], CollectionRelationship];
|
|
41
|
+
getManyArray<T>(key: string, definition?: UpgradedMeta): ManyArray<T>;
|
|
42
|
+
fetchAsyncHasMany(key: string, relationship: CollectionEdge, manyArray: ManyArray, options?: BaseFinderOptions): Promise<ManyArray>;
|
|
43
|
+
reloadHasMany<T>(key: string, options?: BaseFinderOptions): Promise<ManyArray<T>> | PromiseManyArray<T>;
|
|
44
|
+
getHasMany(key: string, options?: BaseFinderOptions): PromiseManyArray | ManyArray;
|
|
45
|
+
_updatePromiseProxyFor(kind: "hasMany", key: string, args: HasManyProxyCreateArgs): PromiseManyArray;
|
|
46
|
+
_updatePromiseProxyFor(kind: "belongsTo", key: string, args: BelongsToProxyCreateArgs): PromiseBelongsTo;
|
|
47
|
+
_updatePromiseProxyFor(kind: "belongsTo", key: string, args: {
|
|
48
|
+
promise: Promise<OpaqueRecordInstance | null>;
|
|
49
|
+
}): PromiseBelongsTo;
|
|
50
|
+
referenceFor(kind: "belongsTo", name: string): BelongsToReference;
|
|
51
|
+
referenceFor(kind: "hasMany", name: string): HasManyReference;
|
|
52
|
+
_findHasManyByJsonApiResource(resource: CollectionResourceRelationship, parentIdentifier: StableRecordIdentifier, relationship: CollectionEdge, options?: BaseFinderOptions): Promise<void | unknown[]> | void;
|
|
53
|
+
_findBelongsToByJsonApiResource(resource: SingleResourceRelationship, parentIdentifier: StableRecordIdentifier, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<StableRecordIdentifier | null>;
|
|
54
|
+
destroy(): void;
|
|
55
55
|
}
|
|
56
56
|
export declare function areAllInverseRecordsLoaded(store: Store, resource: InnerRelationshipDocument): boolean;
|
|
57
|
-
//# sourceMappingURL=legacy-relationships-support.d.ts.map
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import type { Store } from
|
|
2
|
-
import { type ModelFactory } from
|
|
1
|
+
import type { Store } from "@warp-drive/core";
|
|
2
|
+
import { type ModelFactory } from "./model.js";
|
|
3
|
+
/*
|
|
4
|
+
In case someone defined a relationship to a mixin, for example:
|
|
5
|
+
```ts
|
|
6
|
+
class CommentModel extends Model {
|
|
7
|
+
@belongsTo('commentable', { polymorphic: true }) owner;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let Commentable = Mixin.create({
|
|
11
|
+
@hasMany('comment') comments;
|
|
12
|
+
});
|
|
13
|
+
```
|
|
14
|
+
we want to look up a Commentable class which has all the necessary
|
|
15
|
+
relationship meta data. Thus, we look up the mixin and create a mock
|
|
16
|
+
Model, so we can access the relationship CPs of the mixin (`comments`)
|
|
17
|
+
in this case
|
|
18
|
+
*/
|
|
3
19
|
export default function modelForMixin(store: Store, normalizedModelName: string): ModelFactory | undefined;
|
|
4
|
-
//# sourceMappingURL=model-for-mixin.d.ts.map
|
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import type { Store } from
|
|
2
|
-
import type { ChangedAttributesHash } from
|
|
3
|
-
import { RecordStore } from
|
|
4
|
-
import type { Snapshot } from
|
|
5
|
-
import type { Errors } from
|
|
6
|
-
import type RecordState from
|
|
7
|
-
import type BelongsToReference from
|
|
8
|
-
import type HasManyReference from
|
|
9
|
-
import type { MaybeBelongsToFields, MaybeHasManyFields } from
|
|
1
|
+
import type { Store } from "@warp-drive/core";
|
|
2
|
+
import type { ChangedAttributesHash } from "@warp-drive/core/types/cache";
|
|
3
|
+
import { RecordStore } from "@warp-drive/core/types/symbols";
|
|
4
|
+
import type { Snapshot } from "../../compat/-private.js";
|
|
5
|
+
import type { Errors } from "./errors.js";
|
|
6
|
+
import type RecordState from "./record-state.js";
|
|
7
|
+
import type BelongsToReference from "./references/belongs-to.js";
|
|
8
|
+
import type HasManyReference from "./references/has-many.js";
|
|
9
|
+
import type { MaybeBelongsToFields, MaybeHasManyFields } from "./type-utils.js";
|
|
10
10
|
export interface MinimalLegacyRecord {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
errors: Errors;
|
|
12
|
+
___recordState: RecordState;
|
|
13
|
+
currentState: RecordState;
|
|
14
|
+
isDestroyed: boolean;
|
|
15
|
+
isDestroying: boolean;
|
|
16
|
+
isReloading: boolean;
|
|
17
|
+
isValid: boolean;
|
|
18
|
+
[RecordStore]: Store;
|
|
19
|
+
deleteRecord(): void;
|
|
20
|
+
unloadRecord(): void;
|
|
21
|
+
save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;
|
|
22
|
+
destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;
|
|
23
23
|
}
|
|
24
24
|
export declare function rollbackAttributes<T extends MinimalLegacyRecord>(this: T): void;
|
|
25
25
|
export declare function unloadRecord<T extends MinimalLegacyRecord>(this: T): void;
|
|
26
|
-
export declare function belongsTo<
|
|
27
|
-
|
|
26
|
+
export declare function belongsTo<
|
|
27
|
+
T extends MinimalLegacyRecord,
|
|
28
|
+
K extends MaybeBelongsToFields<T>
|
|
29
|
+
>(this: T, prop: K): BelongsToReference<T, K>;
|
|
30
|
+
export declare function hasMany<
|
|
31
|
+
T extends MinimalLegacyRecord,
|
|
32
|
+
K extends MaybeHasManyFields<T>
|
|
33
|
+
>(this: T, prop: K): HasManyReference<T, K>;
|
|
28
34
|
export declare function reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
29
35
|
export declare function changedAttributes<T extends MinimalLegacyRecord>(this: T): ChangedAttributesHash;
|
|
30
36
|
export declare function serialize<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): unknown;
|
|
@@ -32,4 +38,3 @@ export declare function deleteRecord<T extends MinimalLegacyRecord>(this: T): vo
|
|
|
32
38
|
export declare function save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
33
39
|
export declare function destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
|
|
34
40
|
export declare function createSnapshot<T extends MinimalLegacyRecord>(this: T): Snapshot<T>;
|
|
35
|
-
//# sourceMappingURL=model-methods.d.ts.map
|