@warp-drive/legacy 5.10.0-alpha.21 → 5.10.0-alpha.22

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 (94) hide show
  1. package/dist/adapter/-private.d.ts +1 -1
  2. package/dist/adapter/json-api.d.ts +6 -1
  3. package/dist/adapter/json-api.d.ts.map +1 -1
  4. package/dist/adapter/rest.d.ts +1 -1
  5. package/dist/adapter/rest.js +2 -2
  6. package/dist/adapter.d.ts +218 -0
  7. package/dist/compat/builders.d.ts +12 -0
  8. package/dist/compat/builders.d.ts.map +1 -1
  9. package/dist/compat/extensions.d.ts +5 -0
  10. package/dist/index.d.ts +6 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3 -3
  13. package/dist/model/migration-support.js +1 -1
  14. package/dist/{model-Be-e84FX.js → model-EM9IS3kJ.js} +2 -2
  15. package/dist/{model-Be-e84FX.js.map → model-EM9IS3kJ.js.map} +1 -1
  16. package/dist/{unpkg/dev/model-fragments-DCHMDr5f.js → model-fragments-bM9vucwt.js} +2 -2
  17. package/dist/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
  18. package/dist/model-fragments.d.ts +5 -0
  19. package/dist/model-fragments.d.ts.map +1 -1
  20. package/dist/model-fragments.js +1 -1
  21. package/dist/model.d.ts +68 -0
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/model.js +2 -2
  24. package/dist/{rest-CmFneLJH.d.ts → rest-CzVG2wcS.d.ts} +2 -2
  25. package/dist/{rest-CmFneLJH.d.ts.map → rest-CzVG2wcS.d.ts.map} +1 -1
  26. package/dist/{schema-provider-BAB8DyMr.js → schema-provider-BsP-TyJN.js} +3 -3
  27. package/dist/{schema-provider-BAB8DyMr.js.map → schema-provider-BsP-TyJN.js.map} +1 -1
  28. package/dist/serializer/transform.d.ts +5 -0
  29. package/dist/serializer/transform.d.ts.map +1 -1
  30. package/dist/serializer.d.ts +143 -0
  31. package/dist/serializer.d.ts.map +1 -1
  32. package/dist/{store-BLKEsJyw.js → store-09VISmB-.js} +2 -2
  33. package/dist/{store-BLKEsJyw.js.map → store-09VISmB-.js.map} +1 -1
  34. package/dist/store.d.ts +5 -0
  35. package/dist/store.d.ts.map +1 -1
  36. package/dist/store.js +1 -1
  37. package/dist/unpkg/dev/adapter/rest.js +2 -2
  38. package/dist/unpkg/dev/index.js +3 -3
  39. package/dist/unpkg/dev/model/migration-support.js +1 -1
  40. package/dist/unpkg/dev/{model-QCZr8eec.js → model-BRhfRvm7.js} +2 -2
  41. package/dist/unpkg/dev/{model-QCZr8eec.js.map → model-BRhfRvm7.js.map} +1 -1
  42. package/dist/{model-fragments-DCHMDr5f.js → unpkg/dev/model-fragments-bM9vucwt.js} +2 -2
  43. package/dist/unpkg/dev/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
  44. package/dist/unpkg/dev/model-fragments.js +1 -1
  45. package/dist/unpkg/dev/model.js +2 -2
  46. package/dist/unpkg/dev/{schema-provider-IMFO9Kgw.js → schema-provider-KpRvBrnz.js} +3 -3
  47. package/dist/unpkg/dev/{schema-provider-IMFO9Kgw.js.map → schema-provider-KpRvBrnz.js.map} +1 -1
  48. package/dist/unpkg/dev/{store-BiXsLLAu.js → store-DwneLtlP.js} +2 -2
  49. package/dist/unpkg/{dev-deprecated/store-Ci8k7Lh6.js.map → dev/store-DwneLtlP.js.map} +1 -1
  50. package/dist/unpkg/dev/store.js +1 -1
  51. package/dist/unpkg/dev-deprecated/adapter/rest.js +2 -2
  52. package/dist/unpkg/dev-deprecated/index.js +3 -3
  53. package/dist/unpkg/dev-deprecated/model/migration-support.js +1 -1
  54. package/dist/unpkg/dev-deprecated/{model-B0ZNLaHO.js → model-C5LZIABq.js} +2 -2
  55. package/dist/unpkg/dev-deprecated/{model-B0ZNLaHO.js.map → model-C5LZIABq.js.map} +1 -1
  56. package/dist/unpkg/dev-deprecated/{model-fragments-DCHMDr5f.js → model-fragments-bM9vucwt.js} +2 -2
  57. package/dist/unpkg/dev-deprecated/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
  58. package/dist/unpkg/dev-deprecated/model-fragments.js +1 -1
  59. package/dist/unpkg/dev-deprecated/model.js +2 -2
  60. package/dist/unpkg/dev-deprecated/{schema-provider-DGWYnFno.js → schema-provider-BHW1XG6Q.js} +3 -3
  61. package/dist/unpkg/dev-deprecated/{schema-provider-DGWYnFno.js.map → schema-provider-BHW1XG6Q.js.map} +1 -1
  62. package/dist/unpkg/dev-deprecated/{store-Ci8k7Lh6.js → store-CBtAELz5.js} +2 -2
  63. package/dist/unpkg/{dev/store-BiXsLLAu.js.map → dev-deprecated/store-CBtAELz5.js.map} +1 -1
  64. package/dist/unpkg/dev-deprecated/store.js +1 -1
  65. package/dist/unpkg/prod/adapter/rest.js +2 -2
  66. package/dist/unpkg/prod/index.js +3 -3
  67. package/dist/unpkg/prod/model/migration-support.js +1 -1
  68. package/dist/unpkg/prod/{model-QtC0IWbE.js → model-QIzJrhcV.js} +2 -2
  69. package/dist/unpkg/prod/{model-QtC0IWbE.js.map → model-QIzJrhcV.js.map} +1 -1
  70. package/dist/unpkg/prod/model-fragments-bM9vucwt.js +348 -0
  71. package/dist/unpkg/prod/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
  72. package/dist/unpkg/prod/model-fragments.js +1 -1
  73. package/dist/unpkg/prod/model.js +2 -2
  74. package/dist/unpkg/prod/{schema-provider-DPOzTa8e.js → schema-provider-D_H0kna2.js} +3 -3
  75. package/dist/unpkg/prod/{schema-provider-DPOzTa8e.js.map → schema-provider-D_H0kna2.js.map} +1 -1
  76. package/dist/unpkg/prod/{store-BsSkzWgk.js → store-BB1Ab-3t.js} +2 -2
  77. package/dist/unpkg/{prod-deprecated/store-Dsw2f4s-.js.map → prod/store-BB1Ab-3t.js.map} +1 -1
  78. package/dist/unpkg/prod/store.js +1 -1
  79. package/dist/unpkg/prod-deprecated/adapter/rest.js +2 -2
  80. package/dist/unpkg/prod-deprecated/index.js +3 -3
  81. package/dist/unpkg/prod-deprecated/model/migration-support.js +1 -1
  82. package/dist/unpkg/prod-deprecated/{model-B946S2pl.js → model-Dik7yYTm.js} +2 -2
  83. package/dist/unpkg/prod-deprecated/{model-B946S2pl.js.map → model-Dik7yYTm.js.map} +1 -1
  84. package/dist/unpkg/prod-deprecated/{model-fragments-DCHMDr5f.js → model-fragments-bM9vucwt.js} +2 -2
  85. package/dist/unpkg/prod-deprecated/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
  86. package/dist/unpkg/prod-deprecated/model-fragments.js +1 -1
  87. package/dist/unpkg/prod-deprecated/model.js +2 -2
  88. package/dist/unpkg/prod-deprecated/{schema-provider-xcaytn9y.js → schema-provider-BKBnIcPE.js} +3 -3
  89. package/dist/unpkg/prod-deprecated/{schema-provider-xcaytn9y.js.map → schema-provider-BKBnIcPE.js.map} +1 -1
  90. package/dist/unpkg/prod-deprecated/{store-Dsw2f4s-.js → store-Cp64p5ZC.js} +2 -2
  91. package/dist/unpkg/{prod/store-BsSkzWgk.js.map → prod-deprecated/store-Cp64p5ZC.js.map} +1 -1
  92. package/dist/unpkg/prod-deprecated/store.js +1 -1
  93. package/package.json +8 -8
  94. package/dist/unpkg/prod/model-fragments-DCHMDr5f.js +0 -348
@@ -1,5 +1,5 @@
1
+ import { a as RequestData } from "../rest-CzVG2wcS.js";
1
2
  import { m as Snapshot } from "../compat-DoWEarkU.js";
2
- import { a as RequestData } from "../rest-CmFneLJH.js";
3
3
  import { Store } from "@warp-drive/core";
4
4
  import { ModelSchema } from "@warp-drive/core/types";
5
5
  export declare function parseResponseHeaders(headersString: string): Record<string, string>;
@@ -1,5 +1,10 @@
1
+ /**
2
+ * @module
3
+ * @summary Legacy `JSONAPIAdapter`, which turns store requests into HTTP requests following JSON:API URL, verb and
4
+ * header conventions.
5
+ */
1
6
  import { _ as AdapterPayload, m as Snapshot, p as SnapshotRecordArray } from "../compat-DoWEarkU.js";
2
- import { i as RESTAdapter, n as JQueryRequestInit, r as QueryState, t as FetchRequestInit } from "../rest-CmFneLJH.js";
7
+ import { i as RESTAdapter, n as JQueryRequestInit, r as QueryState, t as FetchRequestInit } from "../rest-CzVG2wcS.js";
3
8
  import { Store } from "@warp-drive/core";
4
9
  import { HTTPMethod } from "@warp-drive/core/types/request";
5
10
  import { ModelSchema } from "@warp-drive/core/types";
@@ -1 +1 @@
1
- {"version":3,"file":"json-api.d.ts","names":[],"sources":["../../src/adapter/json-api.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmKM,uBAAuB;;;;;EAK3B;;;;;;;;EASA,YACE,aACA,MAAM,YACN,UAAS,qBAAqB,cAC7B,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAgEnB;MAQA,qBAAqB;EAIzB,SAAS,OAAO,OAAO,MAAM,aAAa,eAAe,WAAW,aAAa,QAAQ;;;;;;;;EAYzF,YAAY;EAKZ,aAAa,OAAO,OAAO,QAAQ,aAAa,UAAU,WAAW,QAAQ;;;;;;;;;;EAoB7E,WAAW,UAAU,WAAW,sBAAsB"}
1
+ {"version":3,"file":"json-api.d.ts","names":[],"sources":["../../src/adapter/json-api.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmKM,uBAAuB;;;;;EAK3B;;;;;;;;EASA,YACE,aACA,MAAM,YACN,UAAS,qBAAqB,cAC7B,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAgEnB;MAQA,qBAAqB;EAIzB,SAAS,OAAO,OAAO,MAAM,aAAa,eAAe,WAAW,aAAa,QAAQ;;;;;;;;EAYzF,YAAY;EAKZ,aAAa,OAAO,OAAO,QAAQ,aAAa,UAAU,WAAW,QAAQ;;;;;;;;;;EAoB7E,WAAW,UAAU,WAAW,sBAAsB"}
@@ -1,2 +1,2 @@
1
- import { a as RequestData, i as RESTAdapter, n as JQueryRequestInit, o as fetchOptions, r as QueryState, t as FetchRequestInit } from "../rest-CmFneLJH.js";
1
+ import { a as RequestData, i as RESTAdapter, n as JQueryRequestInit, o as fetchOptions, r as QueryState, t as FetchRequestInit } from "../rest-CzVG2wcS.js";
2
2
  export { FetchRequestInit, JQueryRequestInit, QueryState, RESTAdapter, RequestData, fetchOptions };
@@ -1,7 +1,7 @@
1
- import { n as decorateMethodV2 } from "../runtime--fcdnjmJ-5yaSpa-d.js";
2
1
  import { n as BuildURLMixin, t as Adapter } from "../adapter-AwGvdMSZ.js";
3
- import { AbortError, AdapterError, ConflictError, ForbiddenError, InvalidError, NotFoundError, ServerError, TimeoutError, UnauthorizedError } from "./error.js";
4
2
  import { a as determineBodyPromise, i as serializeQueryParams, n as getFetchFunction, o as parseResponseHeaders, t as serializeIntoHash } from "../-private-L2BtGGYa.js";
3
+ import { AbortError, AdapterError, ConflictError, ForbiddenError, InvalidError, NotFoundError, ServerError, TimeoutError, UnauthorizedError } from "./error.js";
4
+ import { n as decorateMethodV2 } from "../runtime--fcdnjmJ-5yaSpa-d.js";
5
5
  import { getOwner } from "@ember/application";
6
6
  import { warn } from "@ember/debug";
7
7
  import { getGlobalConfig, macroCondition } from "@embroider/macros";
package/dist/adapter.d.ts CHANGED
@@ -1,2 +1,220 @@
1
+ /**
2
+ * ## Overview
3
+ *
4
+ * :::danger
5
+ * ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
6
+ * If starting a new app or thinking of implementing a new adapter, consider writing a
7
+ * {@link Handler} instead to be used with the {@link RequestManager}
8
+ * ::::
9
+ *
10
+ * In order to properly fetch and update data, @warp-drive/legacy
11
+ * needs to understand how to connect to your API.
12
+ *
13
+ * `Adapters` accept various kinds of requests from the store
14
+ * and manage fulfillment of the request from your API.
15
+ *
16
+ * ### Why It's Legacy
17
+ *
18
+ * The Adapter pattern was designed for class-based architectures in which each resource type
19
+ * could have its own data-fetching logic:
20
+ *
21
+ * - `store.adapterFor` resolves an adapter by resource type at runtime, looking up
22
+ * `adapter:<type>` and then `adapter:application` through Ember's owner.
23
+ * - Each request is fulfilled by a single adapter, so sharing behavior across resource types
24
+ * means extending a common base class rather than composing request logic.
25
+ * - The provided adapter classes extend `EmberObject`, which, together with the owner lookup,
26
+ * ties the pattern to Ember.
27
+ * - Adapter methods resolve with an untyped `AdapterPayload`, so nothing ties the response's
28
+ * type to the request that produced it.
29
+ *
30
+ * ### Modern Alternative
31
+ *
32
+ * Use [Handlers](/api/@warp-drive/core/request/types/Handler) with the {@link RequestManager}.
33
+ * Each request passes through a chain of handlers, any of which can fulfill it, modify it or
34
+ * pass it along. Handlers support:
35
+ *
36
+ * - request builders, which return a request typed with its expected response, so
37
+ * `store.request` resolves with that type
38
+ * - composition: `RequestManager.use` takes a list of handlers, such as the built-in `Fetch`
39
+ * handler, and wrappers such as `Gate` from `@warp-drive/utilities/handlers` run another
40
+ * handler only for the requests it accepts
41
+ * - explicit imports rather than lookup by name at runtime
42
+ * - any framework ***Warp*Drive** supports, since `@warp-drive/core` has no runtime
43
+ * dependency on Ember (see [Installation](/guides/installation/))
44
+ *
45
+ * For an alternative modern pattern to Adapters, see the
46
+ * [Request Handlers Guide](/guides/the-manual/requests/handlers).
47
+ *
48
+ * ### Request Flow
49
+ *
50
+ * When the store decides it needs to issue a request it uses the following flow to manage the request and process the data.
51
+ *
52
+ * - find the appropriate adapter
53
+ * - issue the request to the adapter
54
+ * - await the adapter's response
55
+ * - if an error occurs reject with the error
56
+ * - if no error
57
+ * - if there is response data
58
+ * - pass the response data to the appropriate serializer
59
+ * - update the cache using the JSON:API formatted data from the serializer's response
60
+ * - return the primary record(s) associated with the request
61
+ *
62
+ * ### Request Errors
63
+ *
64
+ * When a request errors and your adapter does not have the ability to recover from the error,
65
+ * you may either reject the promise returned by your adapter method with the error or simply
66
+ * throw the error.
67
+ *
68
+ * If the request was for a `createRecord` `updateRecord` or `deleteRecord` special rules
69
+ * apply to how this error will affect the state of the store and additional properties on
70
+ * the `Error` class may be used. See the documentation for these methods in
71
+ * {@link MinimumAdapterInterface} for more information.
72
+ *
73
+ * ### Implementing an Adapter
74
+ *
75
+ * There are seven required adapter methods, one for each of
76
+ * the primary request types that @warp-drive/legacy issues.
77
+ *
78
+ * They are:
79
+ *
80
+ * - findRecord
81
+ * - findAll
82
+ * - queryRecord
83
+ * - query
84
+ * - createRecord
85
+ * - updateRecord
86
+ * - deleteRecord
87
+ *
88
+ * Each of these request types has a matching store method that triggers it
89
+ * and matching `requestType` that is passed to the serializer's
90
+ * `normalizeResponse` method.
91
+ *
92
+ * If your app only reads data but never writes data, it is not necessary
93
+ * to implement the methods for create, update, and delete. This extends to
94
+ * all of the store's find methods with the exception of `findRecord` (`findAll`,
95
+ * `query`, `queryRecord`): if you do not use the store method in your app then
96
+ * your Adapter does not need the method.
97
+ *
98
+ * ```ts
99
+ * async function fetchData(url, options = {}) {
100
+ * let response = await fetch(url, options);
101
+ * return response.toJSON();
102
+ * }
103
+ *
104
+ * export default class ApplicationAdapter {
105
+ * findRecord(_, { modelName }, id) {
106
+ * return fetchData(`./${modelName}s/${id}`);
107
+ * }
108
+ *
109
+ * static create() {
110
+ * return new this();
111
+ * }
112
+ * }
113
+ * ```
114
+ *
115
+ * ### Adapter Resolution
116
+ *
117
+ * `store.adapterFor(name)` will lookup adapters defined in `app/adapters/` and
118
+ * return an instance.
119
+ *
120
+ * `adapterFor` first attempts to find an adapter with an exact match on `name`,
121
+ then falls back to checking for the presence of an adapter named `application`.
122
+
123
+ If no adapter is found, an error will be thrown.
124
+
125
+ ```ts
126
+ store.adapterFor('author');
127
+
128
+ // lookup paths (in order) =>
129
+ // app/adapters/author.js
130
+ // app/adapters/application.js
131
+ ```
132
+
133
+ Most requests in @warp-drive/legacy are made with respect to a particular `type` (or `modelName`)
134
+ (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
135
+ refer to this as the **primary** resource `type`.
136
+
137
+ `adapterFor` is used by the store to find an adapter with a name matching that of the primary
138
+ resource `type` for the request, which then falls back to the `application` adapter.
139
+
140
+ It is recommended that applications define only a single `application` adapter and serializer
141
+ where possible, only implementing an adapter specific to the `type` when absolutely necessary.
142
+
143
+ If you need to support multiple API versions for the same type, the per-type strategy for
144
+ defining adapters might not be adequate.
145
+
146
+ If you have multiple APIs or multiple API versions and the single application adapter and per-type
147
+ strategy does not suite your needs, one strategy is to write an `application` adapter and serializer
148
+ that make use of `options` to specify the desired format when making a request, then forwards to the
149
+ request to the desired adapter or serializer as needed.
150
+
151
+ ```js [app/adapters/application.js]
152
+ export default class Adapter extends EmberObject {
153
+ findRecord(store, schema, id, snapshot) {
154
+ let { apiVersion } = snapshot.adapterOptions;
155
+ return this.adapterFor(`-api-${apiVersion}`).findRecord(store, schema, id, snapshot);
156
+ }
157
+ }
158
+ ```
159
+
160
+ ### Overriding `Store.adapterFor`
161
+
162
+ ```js
163
+ import Store from '@ember-data/store';
164
+ import Adapter from '@ember-data/adapter/json-api';
165
+
166
+ class extends Store {
167
+ #adapter = new Adapter();
168
+
169
+ adapterFor() {
170
+ return this.#adapter;
171
+ }
172
+ }
173
+ ```
174
+
175
+
176
+ Note: If you are using Ember and would like to make use of `service` injections in your adapter, you will want to additionally `setOwner` for the Adapter.
177
+
178
+ ```js
179
+ import Store from '@ember-data/store';
180
+ import Adapter from '@ember-data/adapter/json-api';
181
+ import { getOwner, setOwner } from '@ember/owner';
182
+
183
+ class extends Store {
184
+ #adapter = null;
185
+
186
+ adapterFor() {
187
+ let adapter = this.#adapter;
188
+ if (!adapter) {
189
+ const owner = getOwner(this);
190
+ adapter = new Adapter();
191
+ setOwner(adapter, owner);
192
+ this.#adapter = adapter;
193
+ }
194
+
195
+ return adapter;
196
+ }
197
+ }
198
+ ```
199
+
200
+ By default when using with Ember you only need to implement this hook if you want your adapter usage to be statically analyzeable. *Ember***Data** will attempt to resolve adapters using Ember's resolver. To provide a single Adapter for your application like the above you would provide it as the default export of the file `app/adapters/application.{js/ts}`
201
+
202
+ ### Using an Adapter
203
+
204
+ Any adapter in `app/adapters/` can be looked up by `name` using `store.adapterFor(name)`.
205
+
206
+ ### Default Adapters
207
+
208
+ Applications whose API's structure endpoint URLs *very close to* or *exactly* the **REST**
209
+ or **JSON:API** convention, the `@ember-data/adapter` package contains implementations
210
+ these applications can extend.
211
+
212
+ Many applications will find writing their own adapter to be allow greater flexibility,
213
+ customization, and maintenance than attempting to override methods in these adapters.
214
+
215
+ @summary Legacy adapter layer through which the store fetches and saves data from an API, superseded by
216
+ `RequestManager` handlers.
217
+ @module
218
+ */
1
219
  import { n as BuildURLMixin, t as Adapter } from "./adapter-DvDVeaCc.js";
2
220
  export { Adapter, BuildURLMixin };
@@ -1,3 +1,15 @@
1
+ /**
2
+ Builders for migrating from `store` methods to `store.request`.
3
+
4
+ These builders enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
5
+ This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
6
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
7
+
8
+ @summary Deprecated request builders that move `findRecord`, `query`, and `saveRecord` calls to `store.request`
9
+ while still using adapters and serializers.
10
+ @module
11
+ @deprecated
12
+ */
1
13
  import { StoreRequestInput } from "@warp-drive/core";
2
14
  import { RequestSignature } from "@warp-drive/core/types/symbols";
3
15
  import { FindAllOptions, FindRecordOptions, LegacyResourceQuery, QueryOptions, ResourceKey } from "@warp-drive/core/types";
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","names":[],"sources":["../../src/compat/builders/find-all.ts","../../src/compat/builders/find-record.ts","../../src/compat/builders/query.ts","../../src/compat/builders/save-record.ts"],"mappings":";;;;;KASK,oBAAoB,2BAA2B,kBAAkB;EACpE;EACA;IACE,MAAM;IACN,SAAS;;GAEV,oBAAoB;;KAGlB,wBAAwB;;;;;;;;;;;;;;;;;;iBAmBb,eAAe,UAAU,qBACvC,MAAM,iBAAiB,IACvB,UAAU,wBACT,oBAAoB,iBAAiB,IAAI;iBAC5B,eAAe,cAAc,UAAU,wBAAwB;KC9B1E,uBAAuB,2BAA2B,gBAAgB;EACrE;EACA;IACE,QAAQ,yBAAyB;IACjC,SAAS;;GAEV,oBAAoB;;KAGlB,2BAA2B,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsCrB,kBAAkB,UAAU,qBAC1C,MAAM,iBAAiB,IACvB,YACA,UAAU,2BACT,uBAAuB,iBAAiB,IAAI;iBAC/B,kBAAkB,cAAc,YAAY,UAAU,2BAA2B;iBACjF,kBAAkB,UAAU,qBAC1C,UAAU,yBAAyB,iBAAiB,KACpD,UAAU,2BACT,uBAAuB,iBAAiB,IAAI;iBAC/B,kBACd,UAAU,0BACV,UAAU,2BACT;KC9DE,kBAAkB,2BAA2B,kBAAkB;EAClE;EACA;IACE,MAAM;IACN,OAAO;IACP,SAAS;;GAEV,oBAAoB;;KAGlB,sBAAsB;;;;;;;;;;;;;;;;;;;iBAoBX,aAAa,UAAU,qBACrC,MAAM,iBAAiB,IACvB,OAAO,qBACP,UAAU,sBACT,kBAAkB,iBAAiB,IAAI;iBAC1B,aACd,cACA,OAAO,qBACP,UAAU,sBACT;KAwBE,wBAAwB,2BAA2B,gBAAgB;EACtE;EACA;IACE,MAAM;IACN,OAAO;IACP,SAAS;;GAEV,oBAAoB;;;;;;;;;;;;;;;;;;;;iBAqBP,mBAAmB,UAAU,qBAC3C,MAAM,iBAAiB,IACvB,OAAO,qBACP,UAAU,sBACT,wBAAwB,iBAAiB,IAAI;iBAChC,mBACd,cACA,OAAO,qBACP,UAAU,sBACT;KCpGE,uBAAuB,2BAA2B,gBAAgB;EACrE;EACA;IACE,QAAQ,YAAY;IACpB,SAAS;;EAEX,UAAU,YAAY;GACrB,oBAAoB;;KAGlB,2BAA2B;;;;;;;;;;;;;;;;;;iBA4BhB,kBAAkB,UAAU,qBAC1C,QAAQ,GACR,UAAS,0BACR,uBAAuB,iBAAiB,IAAI"}
1
+ {"version":3,"file":"builders.d.ts","names":[],"sources":["../../src/compat/builders/find-all.ts","../../src/compat/builders/find-record.ts","../../src/compat/builders/query.ts","../../src/compat/builders/save-record.ts"],"mappings":";;;;;;;;;;;;;;;;;KASK,oBAAoB,2BAA2B,kBAAkB;EACpE;EACA;IACE,MAAM;IACN,SAAS;;GAEV,oBAAoB;;KAGlB,wBAAwB;;;;;;;;;;;;;;;;;;iBAmBb,eAAe,UAAU,qBACvC,MAAM,iBAAiB,IACvB,UAAU,wBACT,oBAAoB,iBAAiB,IAAI;iBAC5B,eAAe,cAAc,UAAU,wBAAwB;KC9B1E,uBAAuB,2BAA2B,gBAAgB;EACrE;EACA;IACE,QAAQ,yBAAyB;IACjC,SAAS;;GAEV,oBAAoB;;KAGlB,2BAA2B,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsCrB,kBAAkB,UAAU,qBAC1C,MAAM,iBAAiB,IACvB,YACA,UAAU,2BACT,uBAAuB,iBAAiB,IAAI;iBAC/B,kBAAkB,cAAc,YAAY,UAAU,2BAA2B;iBACjF,kBAAkB,UAAU,qBAC1C,UAAU,yBAAyB,iBAAiB,KACpD,UAAU,2BACT,uBAAuB,iBAAiB,IAAI;iBAC/B,kBACd,UAAU,0BACV,UAAU,2BACT;KC9DE,kBAAkB,2BAA2B,kBAAkB;EAClE;EACA;IACE,MAAM;IACN,OAAO;IACP,SAAS;;GAEV,oBAAoB;;KAGlB,sBAAsB;;;;;;;;;;;;;;;;;;;iBAoBX,aAAa,UAAU,qBACrC,MAAM,iBAAiB,IACvB,OAAO,qBACP,UAAU,sBACT,kBAAkB,iBAAiB,IAAI;iBAC1B,aACd,cACA,OAAO,qBACP,UAAU,sBACT;KAwBE,wBAAwB,2BAA2B,gBAAgB;EACtE;EACA;IACE,MAAM;IACN,OAAO;IACP,SAAS;;GAEV,oBAAoB;;;;;;;;;;;;;;;;;;;;iBAqBP,mBAAmB,UAAU,qBAC3C,MAAM,iBAAiB,IACvB,OAAO,qBACP,UAAU,sBACT,wBAAwB,iBAAiB,IAAI;iBAChC,mBACd,cACA,OAAO,qBACP,UAAU,sBACT;KCpGE,uBAAuB,2BAA2B,gBAAgB;EACrE;EACA;IACE,QAAQ,YAAY;IACpB,SAAS;;EAEX,UAAU,YAAY;GACrB,oBAAoB;;KAGlB,2BAA2B;;;;;;;;;;;;;;;;;;iBA4BhB,kBAAkB,UAAU,qBAC1C,QAAQ,GACR,UAAS,0BACR,uBAAuB,iBAAiB,IAAI"}
@@ -1,2 +1,7 @@
1
+ /**
2
+ * @module
3
+ * @summary Legacy schema extensions that give reactive objects and arrays the classic `EmberObject` and Ember array
4
+ * APIs, such as `get`, `set` and `mapBy`, plus matching types.
5
+ */
1
6
  import { a as WithArrayLike, i as EmberObjectExtension, n as EmberArrayLikeExtension, o as WithEmberObject, r as EmberObjectArrayExtension, t as ArrayType } from "../extensions-DcEz1lKv.js";
2
7
  export { ArrayType, EmberArrayLikeExtension, EmberObjectArrayExtension, EmberObjectExtension, WithArrayLike, WithEmberObject };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @summary Legacy `Model`, adapter, and serializer support for WarpDrive, including `useLegacyStore` to configure a
3
+ * store that uses them.
4
+ * @module
5
+ * @mergeModuleWith <project>
6
+ */
1
7
  import { Store, StoreSetupOptions } from "@warp-drive/core";
2
8
  import { CacheCapabilitiesManager } from "@warp-drive/core/types";
3
9
  import { Cache } from "@warp-drive/core/types/cache";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UA6CU,yBAAyB,UAAU,eAAe,KAAK,kBAAkB;;;;;;;;;;;EAWjF,UAAU,MAAM,iBAAiB;;;;;;EAOjC;;;;;;;;;;iBAWe,6BAA6B,UAAU,eAAe,yBAAyB;;;;;;;;;EAS9F;;;;;;;;;EASA;;;;;;;;;;;iBAYe,uCAAuC,UAAU,eAAe,yBAAyB;;;;;;;EAOxG;;;;;;;;;EASA;;;;;;;;;;;iBAYe,iDAAiD,UAAU,eAAe,yBAAyB;;;;;;;EAOlH;;;;;;;;;EASA;;;;;;;;;;;;;YAgBU,wBAAwB,UAAU,QAAQ,SAClD,6BAA6B,KAC7B,uCAAuC,KACvC,iDAAiD;qBAEhC,gBACnB;;;;EAIE,OAAO;WAED;EAER,YAAY,cAAc,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4HvC,eAAe,UAAU,OACvC,SAAS,6BAA6B,IACtC,oBAAoB,eACZ;EAAkB,OAAO;;wBACnB,eAAe,UAAU,OACvC,SAAS,uCAAuC,IAChD,oBAAoB,eACZ;EAAkB,OAAO;;wBACnB,eAAe,UAAU,OACvC,SAAS,iDAAiD,IAC1D,oBAAoB,eACZ;EAAkB,OAAO"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;UA6CU,yBAAyB,UAAU,eAAe,KAAK,kBAAkB;;;;;;;;;;;EAWjF,UAAU,MAAM,iBAAiB;;;;;;EAOjC;;;;;;;;;;iBAWe,6BAA6B,UAAU,eAAe,yBAAyB;;;;;;;;;EAS9F;;;;;;;;;EASA;;;;;;;;;;;iBAYe,uCAAuC,UAAU,eAAe,yBAAyB;;;;;;;EAOxG;;;;;;;;;EASA;;;;;;;;;;;iBAYe,iDAAiD,UAAU,eAAe,yBAAyB;;;;;;;EAOlH;;;;;;;;;EASA;;;;;;;;;;;;;YAgBU,wBAAwB,UAAU,QAAQ,SAClD,6BAA6B,KAC7B,uCAAuC,KACvC,iDAAiD;qBAEhC,gBACnB;;;;EAIE,OAAO;WAED;EAER,YAAY,cAAc,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4HvC,eAAe,UAAU,OACvC,SAAS,6BAA6B,IACtC,oBAAoB,eACZ;EAAkB,OAAO;;wBACnB,eAAe,UAAU,OACvC,SAAS,uCAAuC,IAChD,oBAAoB,eACZ;EAAkB,OAAO;;wBACnB,eAAe,UAAU,OACvC,SAAS,iDAAiD,IAC1D,oBAAoB,eACZ;EAAkB,OAAO"}
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { a as serializeRecord, i as pushPayload, n as cleanup, o as serializerFor, r as normalize, s as LegacyNetworkHandler, t as adapterFor } from "./compat-C-yQnbkF.js";
2
2
  import { EmberArrayLikeExtension, EmberObjectArrayExtension, EmberObjectExtension } from "./compat/extensions.js";
3
- import { n as modelFor, r as teardownRecord$1, t as instantiateRecord$1 } from "./model-Be-e84FX.js";
3
+ import { n as modelFor, r as teardownRecord$1, t as instantiateRecord$1 } from "./model-EM9IS3kJ.js";
4
+ import { a as FragmentExtension, s as FragmentArrayExtension, t as fragmentsModelFor } from "./model-fragments-bM9vucwt.js";
4
5
  import { i as releaseLegacySupport } from "./errors-BEExAZtv.js";
5
- import { a as FragmentExtension, s as FragmentArrayExtension, t as fragmentsModelFor } from "./model-fragments-DCHMDr5f.js";
6
6
  import { DelegatingSchemaService, registerDerivations as registerDerivations$1 } from "./model/migration-support.js";
7
- import { t as restoreDeprecatedStoreBehaviors } from "./store-BLKEsJyw.js";
7
+ import { t as restoreDeprecatedStoreBehaviors } from "./store-09VISmB-.js";
8
8
  import { CacheHandler, Fetch, RequestManager, Store, recordIdentifierFor } from "@warp-drive/core";
9
9
  import { SchemaService, instantiateRecord, registerDerivations, teardownRecord } from "@warp-drive/core/reactive";
10
10
  import { DefaultCachePolicy } from "@warp-drive/core/store";
@@ -1,6 +1,6 @@
1
1
  import { r as lookupLegacySupport, t as Errors } from "../errors-BEExAZtv.js";
2
- import { _ as save, a as RecordState, c as _save, d as createSnapshot, f as deleteRecord, g as rollbackAttributes, h as reload, l as belongsTo, m as hasMany, o as _destroyRecord, p as destroyRecord, s as _reload, t as buildSchema, u as changedAttributes, v as serialize, y as unloadRecord } from "../schema-provider-BAB8DyMr.js";
3
2
  import "./-private.js";
3
+ import { _ as save, a as RecordState, c as _save, d as createSnapshot, f as deleteRecord, g as rollbackAttributes, h as reload, l as belongsTo, m as hasMany, o as _destroyRecord, p as destroyRecord, s as _reload, t as buildSchema, u as changedAttributes, v as serialize, y as unloadRecord } from "../schema-provider-BsP-TyJN.js";
4
4
  import { recordIdentifierFor } from "@warp-drive/core";
5
5
  import { assertPrivateStore } from "@warp-drive/core/store/-private";
6
6
  import { Context } from "@warp-drive/core/reactive/-private";
@@ -1,6 +1,6 @@
1
1
  import { n as normalizeModelName, t as isElementDescriptor } from "./util-fMuLguoj.js";
2
2
  import { r as lookupLegacySupport } from "./errors-BEExAZtv.js";
3
- import { n as getModelFactory } from "./schema-provider-BAB8DyMr.js";
3
+ import { n as getModelFactory } from "./schema-provider-BsP-TyJN.js";
4
4
  import { recordIdentifierFor } from "@warp-drive/core";
5
5
  import { getOwner, setOwner } from "@ember/application";
6
6
  import { StoreMap, assertPrivateStore, setRecordIdentifier } from "@warp-drive/core/store/-private";
@@ -687,4 +687,4 @@ function secretInit(record, identifier, store) {
687
687
  }
688
688
 
689
689
  export { belongsTo as a, hasMany as i, modelFor as n, attr as o, teardownRecord as r, instantiateRecord as t };
690
- //# sourceMappingURL=model-Be-e84FX.js.map
690
+ //# sourceMappingURL=model-EM9IS3kJ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-Be-e84FX.js","names":["computed","recordIdentifierFor","RecordStore","isElementDescriptor","getGlobalConfig","macroCondition","_attr","type","options","undefined","meta","kind","isAttribute","sourceKey","key","get","WarpDrive","env","DEBUG","includes","Error","constructor","toString","isDestroyed","isDestroying","cache","getAttr","set","value","identifier","test","id","lid","currentState","isDeleted","cacheKey","currentValue","setAttr","isValid","errors","remove","cleanErrorRequests","attr","desc","args","warn","computed","assertPrivateStore","RecordStore","lookupLegacySupport","isElementDescriptor","normalizeModelName","getGlobalConfig","macroCondition","_belongsTo","type","options","WarpDrive","env","DEBUG","test","Error","async","inverse","length","meta","kind","name","sourceKey","get","key","isDestroying","isDestroyed","support","includes","constructor","toString","Object","prototype","hasOwnProperty","call","identifier","id","getBelongsTo","set","value","_join","setDirtyBelongsTo","belongsTo","arguments","deprecate","computed","assertPrivateStore","RecordStore","dasherize","singularize","lookupLegacySupport","isElementDescriptor","getGlobalConfig","macroCondition","normalizeType","type","WarpDrive","deprecations","DEPRECATE_NON_STRICT_TYPES","result","id","until","for","since","available","enabled","_hasMany","options","env","DEBUG","test","Error","async","meta","kind","name","sourceKey","get","key","includes","constructor","toString","isDestroying","isDestroyed","getHasMany","set","records","support","manyArray","getManyArray","Array","isArray","_join","splice","length","hasMany","arguments","getOwner","setOwner","assertPrivateStore","setRecordIdentifier","StoreMap","getModelFactory","normalizeModelName","macroCondition","getGlobalConfig","recast","context","instantiateRecord","identifier","createRecordArgs","type","createOptions","_createProps","_secretInit","store","cb","secretInit","factory","WarpDrive","env","DEBUG","test","Error","class","create","teardownRecord","record","destroy","modelFor","modelName","isDestroyed","isDestroying","length","maybeFactory","klass","ignoreType","isModel","_forceShim","schema","hasResource","set"],"sources":["../src/model/-private/attr.ts","../src/model/-private/belongs-to.ts","../src/model/-private/has-many.ts","../src/model/-private/hooks.ts"],"sourcesContent":["import { computed } from '@ember/object';\n\nimport { recordIdentifierFor } from '@warp-drive/core';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ArrayValue, ObjectValue, PrimitiveValue, Value } from '@warp-drive/core/types/json/raw';\nimport { RecordStore, type TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { Transform } from '../../serializer/transform.ts';\nimport type { Model } from './model.ts';\nimport type { DecoratorPropertyDescriptor } from './util.ts';\nimport { isElementDescriptor } from './util.ts';\n/**\n * Options provided to the attr decorator are\n * supplied to the associated transform. Any\n * key-value pair is valid; however, it is highly\n * recommended to only use statically defined values\n * that could be serialized to JSON.\n *\n * If no transform is provided, the only valid\n * option is `defaultValue`.\n *\n * Examples:\n *\n * ```ts\n * class User extends Model {\n * @attr('string', { defaultValue: 'Anonymous' }) name;\n * @attr('date', { defaultValue: () => new Date() }) createdAt;\n * @attr({ defaultValue: () => ({}) }) preferences;\n * @attr('boolean') hasVerifiedEmail;\n * @attr address;\n * }\n *\n * @class NOTATHING\n */\nexport type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {\n /**\n * The default value for this attribute.\n *\n * Default values can be provided as a value or a function that will be\n * executed to generate the default value.\n *\n * Default values *should not* be stateful (object, arrays, etc.) as\n * they will be shared across all instances of the record.\n *\n */\n defaultValue?: DV extends PrimitiveValue ? DV : () => DV;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * attributes: {\n * 'first-name': 'Chris'\n * }\n * }\n * ```\n *\n * But the app desires to use `record.firstName; // 'Chris'`, then the\n * property should be named `firstName` and `sourceKey` should be set\n * to `'first-name'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\n};\n\nfunction _attr(type?: string | AttrOptions, options?: AttrOptions) {\n if (typeof type === 'object') {\n options = type;\n type = undefined;\n } else {\n options = options || {};\n }\n\n const meta = {\n type: type,\n kind: 'attribute',\n isAttribute: true,\n options: options,\n sourceKey: options.sourceKey,\n key: null,\n };\n\n return computed({\n get(this: Model, key: string) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n const cache = this[RecordStore].cache;\n return cache.getAttr(recordIdentifierFor(this), meta.sourceKey ?? key);\n },\n set(this: Model, key: string, value: Value) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n const identifier = recordIdentifierFor(this);\n assert(\n `Attempted to set '${key}' on the deleted record ${identifier.type}:${identifier.id} (${identifier.lid})`,\n !this.currentState.isDeleted\n );\n const cache = this[RecordStore].cache;\n const cacheKey = meta.sourceKey ?? key;\n\n const currentValue = cache.getAttr(identifier, cacheKey);\n if (currentValue !== value) {\n cache.setAttr(identifier, cacheKey, value);\n\n if (!this.isValid) {\n const { errors } = this;\n\n if (errors.get(key)) {\n errors.remove(key);\n this.currentState.cleanErrorRequests();\n }\n }\n }\n\n return value;\n },\n }).meta(meta);\n}\n\n// NOTE: Usage of Explicit ANY\n// -------------------------------------------------------------------\n// any is required here because we are the maximal not the minimal\n// subset of options allowed. If we used unknown, object, or\n// Record<string, unknown> we would get type errors when we try to\n// assert against a more specific implementation with precise options.\n// -------------------------------------------------------------------\n\ntype LooseTransformInstance<V, Raw, Name extends string> = {\n /**\n * value type must match the return type of the deserialize method\n *\n */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/no-explicit-any\n serialize: (value: V, options: any) => Raw;\n /**\n * defaultValue type must match the return type of the deserialize method\n *\n */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/no-explicit-any\n deserialize: (value: Raw, options: any) => V;\n\n [TransformName]: Name;\n};\nexport type TransformHasType = { [TransformName]: string };\n\nexport type TypedTransformInstance<V, T extends string> =\n | LooseTransformInstance<V, string, T>\n | LooseTransformInstance<V, number, T>\n | LooseTransformInstance<V, boolean, T>\n | LooseTransformInstance<V, null, T>\n | LooseTransformInstance<V, ObjectValue, T>\n | LooseTransformInstance<V, ArrayValue, T>\n | LooseTransformInstance<V, string | null, T>\n | LooseTransformInstance<V, number | null, T>\n | LooseTransformInstance<V, boolean | null, T>\n | LooseTransformInstance<V, ObjectValue | null, T>\n | LooseTransformInstance<V, ArrayValue | null, T>;\n\n// see note on Explicit ANY above\n// oxlint-disable-next-line typescript/no-explicit-any\nexport type GetMaybeDeserializeValue<T> = T extends { deserialize: (...args: any[]) => unknown }\n ? ReturnType<T['deserialize']>\n : never;\n\nexport type TypeFromInstance<T> = T extends TransformHasType ? T[typeof TransformName] : never;\nexport type ExtractOptions<T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>> =\n Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>;\nexport type OptionsFromInstance<T> =\n TypeFromInstance<T> extends never\n ? never\n : GetMaybeDeserializeValue<T> extends never\n ? never\n : T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>\n ? Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>\n : never;\n\n/**\n * The return type of `void` is a lie to appease TypeScript. The actual return type\n * is a descriptor, but typescript incorrectly insists that decorator functions return\n * `void` or `any`.\n *\n */\nexport type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;\n\n/**\n `attr` defines an attribute on a {@link Model}.\n By default, attributes are passed through as-is, however you can specify an\n optional type to have the value automatically transformed.\n WarpDrive ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n {@link Transform}.\n\n Note that you cannot use `attr` to define an attribute of `id`.\n\n `attr` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `defaultValue`: Pass a string or a function to be called to set the attribute\n to a default value if and only if the key is absent from the payload response.\n\n Example\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n @attr('boolean', { defaultValue: false }) verified;\n }\n ```\n\n Default value can also be a function. This is useful it you want to return\n a new object for each attribute.\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n\n @attr({\n defaultValue() {\n return {};\n }\n })\n settings;\n }\n ```\n\n The `options` hash is passed as second argument to a transforms'\n `serialize` and `deserialize` method. This allows to configure a\n transformation and adapt the corresponding value, based on the config:\n\n ```js [app/models/post.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```js [app/transforms/text.js]\n export default class TextTransform {\n serialize(value, options) {\n if (options.uppercase) {\n return value.toUpperCase();\n }\n\n return value;\n }\n\n deserialize(value) {\n return value;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @summary Legacy `Model` decorator that declares an attribute field, optionally converted by a named transform and\n given a `defaultValue`.\n @public\n @param type the attribute type\n @param options a hash of options\n*/\nexport function attr(): DataDecorator;\nexport function attr<T>(type: TypeFromInstance<T>): DataDecorator;\nexport function attr(type: string): DataDecorator;\nexport function attr(options: AttrOptions): DataDecorator;\nexport function attr<T>(type: TypeFromInstance<T>, options?: OptionsFromInstance<T>): DataDecorator;\nexport function attr(type: string, options?: AttrOptions & object): DataDecorator;\nexport function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void; // see note on DataDecorator for why void\nexport function attr(\n type?: string | AttrOptions | object,\n options?: (AttrOptions & object) | string | symbol,\n desc?: PropertyDescriptor\n): DataDecorator | void {\n const args = [type, options, desc];\n // see note on DataDecorator for why void\n return isElementDescriptor(args) ? (_attr()(...args) as void) : _attr(type, options as object);\n}\n","import { warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\n\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor, normalizeModelName } from './util.ts';\n\nexport type IsUnknown<T> = unknown extends T ? true : false;\n\nexport type RelationshipOptions<T, Async extends boolean> = {\n async: Async;\n inverse: null | (IsUnknown<T> extends true ? string : keyof NoNull<T> & string);\n polymorphic?: boolean;\n as?: string;\n linksMode?: true;\n resetOnRemoteUpdate?: boolean;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * relationships: {\n * 'best-friend': { data: { type: 'user', id: '1' } }\n * }\n * }\n * ```\n *\n * But the app desires to use `record.bestFriend`, then the property\n * should be named `bestFriend` and `sourceKey` should be set to\n * `'best-friend'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\n};\n\nexport type NoNull<T> = Exclude<T, null>;\n// type BelongsToDecoratorObject<getT> = {\n// get: () => getT;\n// // set: (value: Awaited<getT>) => void;\n// set: (value: getT) => void;\n// // init: () => getT;\n// };\n// oxlint-disable-next-line no-unused-vars\nexport type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void; // BelongsToDecoratorObject<getT>;\n\nfunction _belongsTo<T, Async extends boolean>(\n type: string,\n options: RelationshipOptions<T, Async>\n): RelationshipDecorator<T> {\n assert(\n `Expected options.async from @belongsTo('${type}', options) to be a boolean`,\n options && typeof options.async === 'boolean'\n );\n assert(\n `Expected options.inverse from @belongsTo('${type}', options) to be either null or the string type of the related resource.`,\n options.inverse === null || (typeof options.inverse === 'string' && options.inverse.length > 0)\n );\n\n const meta = {\n type: normalizeModelName(type),\n options: options,\n kind: 'belongsTo',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\n };\n\n return computed({\n get<R extends MinimalLegacyRecord>(this: R, key: string) {\n // this is a legacy behavior we may not carry into a new model setup\n // it's better to error on disconnected records so users find errors\n // in their logic.\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n if (Object.prototype.hasOwnProperty.call(options, 'serialize')) {\n warn(\n `You provided a serialize option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See Serializer and it's implementations https://api.emberjs.com/ember-data/release/classes/Serializer`,\n false,\n {\n id: 'ds.model.serialize-option-in-belongs-to',\n }\n );\n }\n\n if (Object.prototype.hasOwnProperty.call(options, 'embedded')) {\n warn(\n `You provided an embedded option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See EmbeddedRecordsMixin https://api.emberjs.com/ember-data/release/classes/EmbeddedRecordsMixin`,\n false,\n {\n id: 'ds.model.embedded-option-in-belongs-to',\n }\n );\n }\n }\n\n return support.getBelongsTo(key);\n },\n set<R extends MinimalLegacyRecord>(this: R, key: string, value: unknown) {\n assert(`Cannot set belongsTo relationship ${key} on a destroyed record`, !this.isDestroying && !this.isDestroyed);\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n }\n assertPrivateStore(this[RecordStore]);\n this[RecordStore]._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None\n relationships on a {@link Model}.\n\n `belongsTo` takes a configuration hash as a second parameter, currently\n supported options are:\n\n - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.\n - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.\n - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic\n - `as`: (*optional*) A string used to declare the abstract type \"this\" record satisfies for polymorphism.\n\n ### Examples\n\n To declare a **one-to-many** (or many-to-many) relationship, use\n `belongsTo` in combination with `hasMany`:\n\n ```js\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n ```\n\n To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:\n\n ```js\n // app/models/author.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Author extends Model {\n @belongsTo('address', { async: true, inverse: 'owner' }) address;\n }\n\n // app/models/address.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Address extends Model {\n @belongsTo('author', { async: true, inverse: 'address' }) owner;\n }\n ```\n\n To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides\n with `null` as the inverse:\n\n ```js\n // app/models/author.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Author extends Model {\n @belongsTo('address', { async: true, inverse: null }) address;\n }\n\n // app/models/address.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Address extends Model {\n @belongsTo('author', { async: true, inverse: null }) owner;\n }\n ```\n\n To declare a one-to-none relationship between two models, use\n `belongsTo` with inverse set to `null` on just one side::\n\n ```js\n // app/models/person.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Person extends Model {\n @belongsTo('person', { async: false, inverse: null }) bestFriend;\n }\n ```\n\n #### Sync vs Async Relationships\n\n WarpDrive fulfills relationships using resource data available in\n the cache.\n\n Sync relationships point directly to the known related resources.\n\n When a relationship is declared as async, if any of the known related\n resources have not been loaded, they will be fetched. The property\n on the record when accessed provides a promise that resolves once\n all resources are loaded.\n\n Async relationships may take advantage of links. On access, if the related\n link has not been loaded, or if any known resources are not available in\n the cache, the fresh state will be fetched using the link.\n\n In contrast to async relationship, accessing a sync relationship\n will error on access when any of the known related resources have\n not been loaded.\n\n If you are using `links` with sync relationships, you have to use\n the BelongsTo reference API to fetch or refresh related resources\n that aren't loaded. For instance, for a `bestFriend` relationship:\n\n ```js\n person.belongsTo('bestFriend').reload();\n ```\n\n #### Polymorphic Relationships\n\n To declare a polymorphic relationship, use `hasMany` with the `polymorphic`\n option set to `true`:\n\n ```js\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;\n }\n ```\n\n `'commentable'` here is referred to as the \"abstract type\" for the polymorphic\n relationship.\n\n Polymorphic relationships with `inverse: null` will accept any type of record as their content.\n Polymorphic relationships with `inverse` set to a string will only accept records with a matching\n inverse relationships declaring itself as satisfying the abstract type.\n\n Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'\n for this relationship.\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;\n }\n ```\n\n Note: every Model that declares an inverse to a polymorphic relationship must\n declare itself exactly the same. This is because polymorphism is based on structural\n traits.\n\n Polymorphic to polymorphic relationships are supported. Both sides of the relationship\n must be declared as polymorphic, and the `as` option must be used to declare the abstract\n type each record satisfies on both sides.\n\n @summary Legacy `Model` decorator that declares a to-one relationship to another resource type, configured with\n required `async` and `inverse` options.\n @public\n @param type the name of the related resource\n @param options a hash of options\n*/\n\nexport function belongsTo(): never;\nexport function belongsTo(type: string): never;\nexport function belongsTo<T>(\n type: TypeFromInstance<NoNull<T>>,\n options: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T>;\n// export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(\n// type: TypeFromInstance<NoNull<T>>,\n// options: RelationshipOptions<T, true>\n// ): RelationshipDecorator<K>;\nexport function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;\nexport function belongsTo<T>(\n type?: TypeFromInstance<NoNull<T>>,\n options?: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T> {\n if (DEBUG) {\n assert(\n `belongsTo must be invoked with a type and options. Did you mean \\`@belongsTo(${type}, { async: false, inverse: null })\\`?`,\n !isElementDescriptor(arguments as unknown as unknown[])\n );\n }\n return _belongsTo(type!, options!);\n}\n","import { deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\nimport { dasherize, singularize } from '@warp-drive/utilities/string';\n\nimport type { NoNull, RelationshipDecorator, RelationshipOptions } from './belongs-to.ts';\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor } from './util.ts';\n\nfunction normalizeType(type: string) {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = singularize(dasherize(type));\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n\nfunction _hasMany<T, Async extends boolean>(\n type: string,\n options: RelationshipOptions<T, Async>\n): RelationshipDecorator<T> {\n assert(`Expected hasMany options.async to be a boolean`, options && typeof options.async === 'boolean');\n\n // Metadata about relationships is stored on the meta of\n // the relationship. This is used for introspection and\n // serialization. Note that `key` is populated lazily\n // the first time the CP is called.\n const meta = {\n type: normalizeType(type),\n options,\n kind: 'hasMany',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\n };\n\n return computed({\n get<R extends MinimalLegacyRecord>(this: R, key: string) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroying || this.isDestroyed) {\n return [];\n }\n return lookupLegacySupport(this).getHasMany(key);\n },\n set<R extends MinimalLegacyRecord>(this: R, key: string, records: T[]) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n const support = lookupLegacySupport(this);\n const manyArray = support.getManyArray(key);\n assert(`You must pass an array of records to set a hasMany relationship`, Array.isArray(records));\n\n assertPrivateStore(this[RecordStore]);\n this[RecordStore]._join(() => {\n manyArray.splice(0, manyArray.length, ...records);\n });\n\n return support.getHasMany(key);\n },\n }).meta(meta);\n}\n\n/**\n `hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None\n relationships on a {@link Model}.\n\n `hasMany` takes a configuration hash as a second parameter, currently\n supported options are:\n\n - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.\n - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.\n - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic\n - `as`: (*optional*) A string used to declare the abstract type \"this\" record satisfies for polymorphism.\n\n ### Examples\n\n To declare a **many-to-one** (or one-to-many) relationship, use\n `belongsTo` in combination with `hasMany`:\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n\n\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n ```\n\n To declare a **many-to-many** relationship with managed inverses, use `hasMany` for both sides:\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('tag', { async: true, inverse: 'posts' }) tags;\n }\n\n // app/models/tag.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Tag extends Model {\n @hasMany('post', { async: true, inverse: 'tags' }) posts;\n }\n ```\n\n To declare a **many-to-many** relationship without managed inverses, use `hasMany` for both sides\n with `null` as the inverse:\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('tag', { async: true, inverse: null }) tags;\n }\n\n // app/models/tag.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Tag extends Model {\n @hasMany('post', { async: true, inverse: null }) posts;\n }\n ```\n\n To declare a many-to-none relationship between two models, use\n `hasMany` with inverse set to `null` on just one side::\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('category', { async: true, inverse: null }) categories;\n }\n ```\n\n #### Sync vs Async Relationships\n\n WarpDrive fulfills relationships using resource data available in\n the cache.\n\n Sync relationships point directly to the known related resources.\n\n When a relationship is declared as async, if any of the known related\n resources have not been loaded, they will be fetched. The property\n on the record when accessed provides a promise that resolves once\n all resources are loaded.\n\n Async relationships may take advantage of links. On access, if the related\n link has not been loaded, or if any known resources are not available in\n the cache, the fresh state will be fetched using the link.\n\n In contrast to async relationship, accessing a sync relationship\n will error on access when any of the known related resources have\n not been loaded.\n\n If you are using `links` with sync relationships, you have to use\n the HasMany reference API to fetch or refresh related resources\n that aren't loaded. For instance, for a `comments` relationship:\n\n ```js\n post.hasMany('comments').reload();\n ```\n\n #### Polymorphic Relationships\n\n To declare a polymorphic relationship, use `hasMany` with the `polymorphic`\n option set to `true`:\n\n ```js\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;\n }\n ```\n\n `'commentable'` here is referred to as the \"abstract type\" for the polymorphic\n relationship.\n\n Polymorphic relationships with `inverse: null` will accept any type of record as their content.\n Polymorphic relationships with `inverse` set to a string will only accept records with a matching\n inverse relationships declaring itself as satisfying the abstract type.\n\n Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'\n for this relationship.\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;\n }\n ```\n\n Note: every Model that declares an inverse to a polymorphic relationship must\n declare itself exactly the same. This is because polymorphism is based on structural\n traits.\n\n Polymorphic to polymorphic relationships are supported. Both sides of the relationship\n must be declared as polymorphic, and the `as` option must be used to declare the abstract\n type each record satisfies on both sides.\n\n @summary Legacy `Model` decorator that declares a to-many relationship to another resource type, configured with\n required `async` and `inverse` options.\n @public\n @param type the name of the related resource\n @param options a hash of options\n*/\nexport function hasMany(): never;\nexport function hasMany(type: string): never;\nexport function hasMany<T>(\n type: TypeFromInstance<NoNull<T>>,\n options: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T>;\n// export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(\n// type: TypeFromInstance<NoNull<T>>,\n// options: RelationshipOptions<T, true>\n// ): RelationshipDecorator<K>;\nexport function hasMany(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;\nexport function hasMany<T>(\n type?: TypeFromInstance<NoNull<T>>,\n options?: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T> {\n if (DEBUG) {\n assert(\n `hasMany must be invoked with a type and options. Did you mean \\`@hasMany(${type}, { async: false, inverse: null })\\`?`,\n !isElementDescriptor(arguments as unknown as unknown[])\n );\n }\n return _hasMany(type!, options!);\n}\n","import { getOwner, setOwner } from '@ember/application';\n\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore, setRecordIdentifier, type Store, StoreMap } from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core/types/record';\n\nimport type { Model, ModelStore } from './model.ts';\nimport { getModelFactory } from './schema-provider.ts';\nimport { normalizeModelName } from './util.ts';\n\nfunction recast(context: Store): asserts context is ModelStore {}\n\n/**\n * The `instantiateRecord` hook implementation for use with `Model`. Pass\n * this to your store's `instantiateRecord` method when configuring the\n * store to use `Model` for schema/record instantiation.\n *\n * @summary Legacy store hook that creates a `Model` instance for a resource key using the `Model` class registered\n * for its type.\n * @public\n */\nexport function instantiateRecord(\n this: Store,\n identifier: ResourceKey,\n createRecordArgs?: { [key: string]: unknown }\n): Model {\n const type = identifier.type;\n\n recast(this);\n\n // TODO deprecate allowing unknown args setting\n const createOptions = {\n _createProps: createRecordArgs ?? {},\n // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for\n _secretInit: {\n identifier,\n store: this,\n cb: secretInit,\n },\n };\n\n // ensure that `getOwner(this)` works inside a model instance\n setOwner(createOptions, getOwner(this)!);\n const factory = getModelFactory(this, type);\n\n assert(`No model was found for '${type}'`, factory);\n return factory.class.create(createOptions);\n}\n\n/**\n * The `teardownRecord` hook implementation for use with `Model`. Pass this\n * to your store's `teardownRecord` method when configuring the store to\n * use `Model` for schema/record instantiation.\n *\n * @summary Legacy store hook that destroys a `Model` instance when the store releases its record.\n * @public\n */\nexport function teardownRecord(record: Model): void {\n assert(\n `expected to receive an instance of Model from @warp-drive/legacy/model. If using a custom model make sure you implement teardownRecord`,\n 'destroy' in record\n );\n record.destroy();\n}\n\n/**\n * The `modelFor` implementation for use with `Model`, exposed on the store\n * as `store.modelFor(type)` when the store is configured to use `Model`.\n * Returns the `Model` subclass registered for the given type, if any.\n *\n * @summary Legacy `store.modelFor` implementation that returns the `Model` class registered for a resource type, if\n * there is one.\n * @public\n */\nexport function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;\n/**\n * Overload accepting a raw type string instead of a typed record instance.\n *\n * @public\n */\nexport function modelFor(type: string): typeof Model | void;\nexport function modelFor<T>(this: Store, modelName: TypeFromInstanceOrString<T>): typeof Model | void {\n assertPrivateStore(this);\n assert(\n `Attempted to call store.modelFor(), but the store instance has already been destroyed.`,\n !this.isDestroyed && !this.isDestroying\n );\n assert(`You need to pass a model name to the store's modelFor method`, modelName);\n assert(\n `Please pass a proper model name to the store's modelFor method`,\n typeof modelName === 'string' && modelName.length\n );\n recast(this);\n\n const type = normalizeModelName(modelName);\n const maybeFactory = getModelFactory(this, type);\n const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;\n\n const ignoreType = !klass || !klass.isModel || this._forceShim;\n if (!ignoreType) {\n return klass;\n }\n assert(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n}\n\nfunction secretInit(record: Model, identifier: ResourceKey, store: Store): void {\n setRecordIdentifier(record, identifier);\n StoreMap.set(record, store);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAASM,MAAMC,MAA6BC,SAAuB;CACjE,IAAI,OAAOD,SAAS,UAAU;EAC5BC,UAAUD;EACVA,OAAOE;CACT,OACED,UAAUA,WAAW,CAA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AAC,MAAO,8DAA8D;CAAA,EAAA,CAAEO,SAAS;CAChF1B,eAAAC,gBAAA,CAAA,CAAAc,UAAAC,IAAAC,KAAA,OAAAC,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MACE,gEAAgE;CAAA,EAAA,CAChE,OAAOO,cAAc,YAAYA,UAAUG,MAAM;CAInD,MAAMtB,OAAOR,mBAAmB2B,SAAS;CACzC,MAAMI,eAAehC,gBAAgB,MAAMS,IAAI;CAC/C,MAAMwB,QAAQD,gBAAgBA,aAAaV,QAAQU,aAAaV,QAAQ;CAGxE,IAAI,EADe,CAACW,SAAS,CAACA,MAAME,WAAW,KAAKC,aAElD,OAAOH;CAET/B,eAAAC,gBAAA,CAAA,CAAAc,UAAAC,IAAAC,KAAA,OAAAC,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MAAO,2BAA2BZ,KAAI,iCAAkC;CAAA,EAAA,CAAE,KAAK4B,OAAOC,YAAY,EAAE7B,KAAK,CAAC,CAAC;AAC7G;AAEA,SAASM,WAAWU,QAAelB,YAAyBM,OAAoB;CAC9Ef,oBAAoB2B,QAAQlB,UAAU;CACtCR,SAASwC,IAAId,QAAQZ,KAAK;AAC5B"}
1
+ {"version":3,"file":"model-EM9IS3kJ.js","names":["computed","recordIdentifierFor","RecordStore","isElementDescriptor","getGlobalConfig","macroCondition","_attr","type","options","undefined","meta","kind","isAttribute","sourceKey","key","get","WarpDrive","env","DEBUG","includes","Error","constructor","toString","isDestroyed","isDestroying","cache","getAttr","set","value","identifier","test","id","lid","currentState","isDeleted","cacheKey","currentValue","setAttr","isValid","errors","remove","cleanErrorRequests","attr","desc","args","warn","computed","assertPrivateStore","RecordStore","lookupLegacySupport","isElementDescriptor","normalizeModelName","getGlobalConfig","macroCondition","_belongsTo","type","options","WarpDrive","env","DEBUG","test","Error","async","inverse","length","meta","kind","name","sourceKey","get","key","isDestroying","isDestroyed","support","includes","constructor","toString","Object","prototype","hasOwnProperty","call","identifier","id","getBelongsTo","set","value","_join","setDirtyBelongsTo","belongsTo","arguments","deprecate","computed","assertPrivateStore","RecordStore","dasherize","singularize","lookupLegacySupport","isElementDescriptor","getGlobalConfig","macroCondition","normalizeType","type","WarpDrive","deprecations","DEPRECATE_NON_STRICT_TYPES","result","id","until","for","since","available","enabled","_hasMany","options","env","DEBUG","test","Error","async","meta","kind","name","sourceKey","get","key","includes","constructor","toString","isDestroying","isDestroyed","getHasMany","set","records","support","manyArray","getManyArray","Array","isArray","_join","splice","length","hasMany","arguments","getOwner","setOwner","assertPrivateStore","setRecordIdentifier","StoreMap","getModelFactory","normalizeModelName","macroCondition","getGlobalConfig","recast","context","instantiateRecord","identifier","createRecordArgs","type","createOptions","_createProps","_secretInit","store","cb","secretInit","factory","WarpDrive","env","DEBUG","test","Error","class","create","teardownRecord","record","destroy","modelFor","modelName","isDestroyed","isDestroying","length","maybeFactory","klass","ignoreType","isModel","_forceShim","schema","hasResource","set"],"sources":["../src/model/-private/attr.ts","../src/model/-private/belongs-to.ts","../src/model/-private/has-many.ts","../src/model/-private/hooks.ts"],"sourcesContent":["import { computed } from '@ember/object';\n\nimport { recordIdentifierFor } from '@warp-drive/core';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ArrayValue, ObjectValue, PrimitiveValue, Value } from '@warp-drive/core/types/json/raw';\nimport { RecordStore, type TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { Transform } from '../../serializer/transform.ts';\nimport type { Model } from './model.ts';\nimport type { DecoratorPropertyDescriptor } from './util.ts';\nimport { isElementDescriptor } from './util.ts';\n/**\n * Options provided to the attr decorator are\n * supplied to the associated transform. Any\n * key-value pair is valid; however, it is highly\n * recommended to only use statically defined values\n * that could be serialized to JSON.\n *\n * If no transform is provided, the only valid\n * option is `defaultValue`.\n *\n * Examples:\n *\n * ```ts\n * class User extends Model {\n * @attr('string', { defaultValue: 'Anonymous' }) name;\n * @attr('date', { defaultValue: () => new Date() }) createdAt;\n * @attr({ defaultValue: () => ({}) }) preferences;\n * @attr('boolean') hasVerifiedEmail;\n * @attr address;\n * }\n *\n * @class NOTATHING\n */\nexport type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {\n /**\n * The default value for this attribute.\n *\n * Default values can be provided as a value or a function that will be\n * executed to generate the default value.\n *\n * Default values *should not* be stateful (object, arrays, etc.) as\n * they will be shared across all instances of the record.\n *\n */\n defaultValue?: DV extends PrimitiveValue ? DV : () => DV;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * attributes: {\n * 'first-name': 'Chris'\n * }\n * }\n * ```\n *\n * But the app desires to use `record.firstName; // 'Chris'`, then the\n * property should be named `firstName` and `sourceKey` should be set\n * to `'first-name'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\n};\n\nfunction _attr(type?: string | AttrOptions, options?: AttrOptions) {\n if (typeof type === 'object') {\n options = type;\n type = undefined;\n } else {\n options = options || {};\n }\n\n const meta = {\n type: type,\n kind: 'attribute',\n isAttribute: true,\n options: options,\n sourceKey: options.sourceKey,\n key: null,\n };\n\n return computed({\n get(this: Model, key: string) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n const cache = this[RecordStore].cache;\n return cache.getAttr(recordIdentifierFor(this), meta.sourceKey ?? key);\n },\n set(this: Model, key: string, value: Value) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n const identifier = recordIdentifierFor(this);\n assert(\n `Attempted to set '${key}' on the deleted record ${identifier.type}:${identifier.id} (${identifier.lid})`,\n !this.currentState.isDeleted\n );\n const cache = this[RecordStore].cache;\n const cacheKey = meta.sourceKey ?? key;\n\n const currentValue = cache.getAttr(identifier, cacheKey);\n if (currentValue !== value) {\n cache.setAttr(identifier, cacheKey, value);\n\n if (!this.isValid) {\n const { errors } = this;\n\n if (errors.get(key)) {\n errors.remove(key);\n this.currentState.cleanErrorRequests();\n }\n }\n }\n\n return value;\n },\n }).meta(meta);\n}\n\n// NOTE: Usage of Explicit ANY\n// -------------------------------------------------------------------\n// any is required here because we are the maximal not the minimal\n// subset of options allowed. If we used unknown, object, or\n// Record<string, unknown> we would get type errors when we try to\n// assert against a more specific implementation with precise options.\n// -------------------------------------------------------------------\n\ntype LooseTransformInstance<V, Raw, Name extends string> = {\n /**\n * value type must match the return type of the deserialize method\n *\n */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/no-explicit-any\n serialize: (value: V, options: any) => Raw;\n /**\n * defaultValue type must match the return type of the deserialize method\n *\n */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/no-explicit-any\n deserialize: (value: Raw, options: any) => V;\n\n [TransformName]: Name;\n};\nexport type TransformHasType = { [TransformName]: string };\n\nexport type TypedTransformInstance<V, T extends string> =\n | LooseTransformInstance<V, string, T>\n | LooseTransformInstance<V, number, T>\n | LooseTransformInstance<V, boolean, T>\n | LooseTransformInstance<V, null, T>\n | LooseTransformInstance<V, ObjectValue, T>\n | LooseTransformInstance<V, ArrayValue, T>\n | LooseTransformInstance<V, string | null, T>\n | LooseTransformInstance<V, number | null, T>\n | LooseTransformInstance<V, boolean | null, T>\n | LooseTransformInstance<V, ObjectValue | null, T>\n | LooseTransformInstance<V, ArrayValue | null, T>;\n\n// see note on Explicit ANY above\n// oxlint-disable-next-line typescript/no-explicit-any\nexport type GetMaybeDeserializeValue<T> = T extends { deserialize: (...args: any[]) => unknown }\n ? ReturnType<T['deserialize']>\n : never;\n\nexport type TypeFromInstance<T> = T extends TransformHasType ? T[typeof TransformName] : never;\nexport type ExtractOptions<T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>> =\n Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>;\nexport type OptionsFromInstance<T> =\n TypeFromInstance<T> extends never\n ? never\n : GetMaybeDeserializeValue<T> extends never\n ? never\n : T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>\n ? Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>\n : never;\n\n/**\n * The return type of `void` is a lie to appease TypeScript. The actual return type\n * is a descriptor, but typescript incorrectly insists that decorator functions return\n * `void` or `any`.\n *\n */\nexport type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;\n\n/**\n `attr` defines an attribute on a {@link Model}.\n By default, attributes are passed through as-is, however you can specify an\n optional type to have the value automatically transformed.\n WarpDrive ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n {@link Transform}.\n\n Note that you cannot use `attr` to define an attribute of `id`.\n\n `attr` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `defaultValue`: Pass a string or a function to be called to set the attribute\n to a default value if and only if the key is absent from the payload response.\n\n Example\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n @attr('boolean', { defaultValue: false }) verified;\n }\n ```\n\n Default value can also be a function. This is useful it you want to return\n a new object for each attribute.\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n\n @attr({\n defaultValue() {\n return {};\n }\n })\n settings;\n }\n ```\n\n The `options` hash is passed as second argument to a transforms'\n `serialize` and `deserialize` method. This allows to configure a\n transformation and adapt the corresponding value, based on the config:\n\n ```js [app/models/post.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```js [app/transforms/text.js]\n export default class TextTransform {\n serialize(value, options) {\n if (options.uppercase) {\n return value.toUpperCase();\n }\n\n return value;\n }\n\n deserialize(value) {\n return value;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @summary Legacy `Model` decorator that declares an attribute field, optionally converted by a named transform and\n given a `defaultValue`.\n @public\n @param type the attribute type\n @param options a hash of options\n*/\nexport function attr(): DataDecorator;\nexport function attr<T>(type: TypeFromInstance<T>): DataDecorator;\nexport function attr(type: string): DataDecorator;\nexport function attr(options: AttrOptions): DataDecorator;\nexport function attr<T>(type: TypeFromInstance<T>, options?: OptionsFromInstance<T>): DataDecorator;\nexport function attr(type: string, options?: AttrOptions & object): DataDecorator;\nexport function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void; // see note on DataDecorator for why void\nexport function attr(\n type?: string | AttrOptions | object,\n options?: (AttrOptions & object) | string | symbol,\n desc?: PropertyDescriptor\n): DataDecorator | void {\n const args = [type, options, desc];\n // see note on DataDecorator for why void\n return isElementDescriptor(args) ? (_attr()(...args) as void) : _attr(type, options as object);\n}\n","import { warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\n\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor, normalizeModelName } from './util.ts';\n\nexport type IsUnknown<T> = unknown extends T ? true : false;\n\nexport type RelationshipOptions<T, Async extends boolean> = {\n async: Async;\n inverse: null | (IsUnknown<T> extends true ? string : keyof NoNull<T> & string);\n polymorphic?: boolean;\n as?: string;\n linksMode?: true;\n resetOnRemoteUpdate?: boolean;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * relationships: {\n * 'best-friend': { data: { type: 'user', id: '1' } }\n * }\n * }\n * ```\n *\n * But the app desires to use `record.bestFriend`, then the property\n * should be named `bestFriend` and `sourceKey` should be set to\n * `'best-friend'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\n};\n\nexport type NoNull<T> = Exclude<T, null>;\n// type BelongsToDecoratorObject<getT> = {\n// get: () => getT;\n// // set: (value: Awaited<getT>) => void;\n// set: (value: getT) => void;\n// // init: () => getT;\n// };\n// oxlint-disable-next-line no-unused-vars\nexport type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void; // BelongsToDecoratorObject<getT>;\n\nfunction _belongsTo<T, Async extends boolean>(\n type: string,\n options: RelationshipOptions<T, Async>\n): RelationshipDecorator<T> {\n assert(\n `Expected options.async from @belongsTo('${type}', options) to be a boolean`,\n options && typeof options.async === 'boolean'\n );\n assert(\n `Expected options.inverse from @belongsTo('${type}', options) to be either null or the string type of the related resource.`,\n options.inverse === null || (typeof options.inverse === 'string' && options.inverse.length > 0)\n );\n\n const meta = {\n type: normalizeModelName(type),\n options: options,\n kind: 'belongsTo',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\n };\n\n return computed({\n get<R extends MinimalLegacyRecord>(this: R, key: string) {\n // this is a legacy behavior we may not carry into a new model setup\n // it's better to error on disconnected records so users find errors\n // in their logic.\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n if (Object.prototype.hasOwnProperty.call(options, 'serialize')) {\n warn(\n `You provided a serialize option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See Serializer and it's implementations https://api.emberjs.com/ember-data/release/classes/Serializer`,\n false,\n {\n id: 'ds.model.serialize-option-in-belongs-to',\n }\n );\n }\n\n if (Object.prototype.hasOwnProperty.call(options, 'embedded')) {\n warn(\n `You provided an embedded option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See EmbeddedRecordsMixin https://api.emberjs.com/ember-data/release/classes/EmbeddedRecordsMixin`,\n false,\n {\n id: 'ds.model.embedded-option-in-belongs-to',\n }\n );\n }\n }\n\n return support.getBelongsTo(key);\n },\n set<R extends MinimalLegacyRecord>(this: R, key: string, value: unknown) {\n assert(`Cannot set belongsTo relationship ${key} on a destroyed record`, !this.isDestroying && !this.isDestroyed);\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n }\n assertPrivateStore(this[RecordStore]);\n this[RecordStore]._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None\n relationships on a {@link Model}.\n\n `belongsTo` takes a configuration hash as a second parameter, currently\n supported options are:\n\n - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.\n - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.\n - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic\n - `as`: (*optional*) A string used to declare the abstract type \"this\" record satisfies for polymorphism.\n\n ### Examples\n\n To declare a **one-to-many** (or many-to-many) relationship, use\n `belongsTo` in combination with `hasMany`:\n\n ```js\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n ```\n\n To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:\n\n ```js\n // app/models/author.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Author extends Model {\n @belongsTo('address', { async: true, inverse: 'owner' }) address;\n }\n\n // app/models/address.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Address extends Model {\n @belongsTo('author', { async: true, inverse: 'address' }) owner;\n }\n ```\n\n To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides\n with `null` as the inverse:\n\n ```js\n // app/models/author.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Author extends Model {\n @belongsTo('address', { async: true, inverse: null }) address;\n }\n\n // app/models/address.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Address extends Model {\n @belongsTo('author', { async: true, inverse: null }) owner;\n }\n ```\n\n To declare a one-to-none relationship between two models, use\n `belongsTo` with inverse set to `null` on just one side::\n\n ```js\n // app/models/person.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Person extends Model {\n @belongsTo('person', { async: false, inverse: null }) bestFriend;\n }\n ```\n\n #### Sync vs Async Relationships\n\n WarpDrive fulfills relationships using resource data available in\n the cache.\n\n Sync relationships point directly to the known related resources.\n\n When a relationship is declared as async, if any of the known related\n resources have not been loaded, they will be fetched. The property\n on the record when accessed provides a promise that resolves once\n all resources are loaded.\n\n Async relationships may take advantage of links. On access, if the related\n link has not been loaded, or if any known resources are not available in\n the cache, the fresh state will be fetched using the link.\n\n In contrast to async relationship, accessing a sync relationship\n will error on access when any of the known related resources have\n not been loaded.\n\n If you are using `links` with sync relationships, you have to use\n the BelongsTo reference API to fetch or refresh related resources\n that aren't loaded. For instance, for a `bestFriend` relationship:\n\n ```js\n person.belongsTo('bestFriend').reload();\n ```\n\n #### Polymorphic Relationships\n\n To declare a polymorphic relationship, use `hasMany` with the `polymorphic`\n option set to `true`:\n\n ```js\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;\n }\n ```\n\n `'commentable'` here is referred to as the \"abstract type\" for the polymorphic\n relationship.\n\n Polymorphic relationships with `inverse: null` will accept any type of record as their content.\n Polymorphic relationships with `inverse` set to a string will only accept records with a matching\n inverse relationships declaring itself as satisfying the abstract type.\n\n Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'\n for this relationship.\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;\n }\n ```\n\n Note: every Model that declares an inverse to a polymorphic relationship must\n declare itself exactly the same. This is because polymorphism is based on structural\n traits.\n\n Polymorphic to polymorphic relationships are supported. Both sides of the relationship\n must be declared as polymorphic, and the `as` option must be used to declare the abstract\n type each record satisfies on both sides.\n\n @summary Legacy `Model` decorator that declares a to-one relationship to another resource type, configured with\n required `async` and `inverse` options.\n @public\n @param type the name of the related resource\n @param options a hash of options\n*/\n\nexport function belongsTo(): never;\nexport function belongsTo(type: string): never;\nexport function belongsTo<T>(\n type: TypeFromInstance<NoNull<T>>,\n options: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T>;\n// export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(\n// type: TypeFromInstance<NoNull<T>>,\n// options: RelationshipOptions<T, true>\n// ): RelationshipDecorator<K>;\nexport function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;\nexport function belongsTo<T>(\n type?: TypeFromInstance<NoNull<T>>,\n options?: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T> {\n if (DEBUG) {\n assert(\n `belongsTo must be invoked with a type and options. Did you mean \\`@belongsTo(${type}, { async: false, inverse: null })\\`?`,\n !isElementDescriptor(arguments as unknown as unknown[])\n );\n }\n return _belongsTo(type!, options!);\n}\n","import { deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\nimport { dasherize, singularize } from '@warp-drive/utilities/string';\n\nimport type { NoNull, RelationshipDecorator, RelationshipOptions } from './belongs-to.ts';\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor } from './util.ts';\n\nfunction normalizeType(type: string) {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = singularize(dasherize(type));\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n\nfunction _hasMany<T, Async extends boolean>(\n type: string,\n options: RelationshipOptions<T, Async>\n): RelationshipDecorator<T> {\n assert(`Expected hasMany options.async to be a boolean`, options && typeof options.async === 'boolean');\n\n // Metadata about relationships is stored on the meta of\n // the relationship. This is used for introspection and\n // serialization. Note that `key` is populated lazily\n // the first time the CP is called.\n const meta = {\n type: normalizeType(type),\n options,\n kind: 'hasMany',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\n };\n\n return computed({\n get<R extends MinimalLegacyRecord>(this: R, key: string) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroying || this.isDestroyed) {\n return [];\n }\n return lookupLegacySupport(this).getHasMany(key);\n },\n set<R extends MinimalLegacyRecord>(this: R, key: string, records: T[]) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n const support = lookupLegacySupport(this);\n const manyArray = support.getManyArray(key);\n assert(`You must pass an array of records to set a hasMany relationship`, Array.isArray(records));\n\n assertPrivateStore(this[RecordStore]);\n this[RecordStore]._join(() => {\n manyArray.splice(0, manyArray.length, ...records);\n });\n\n return support.getHasMany(key);\n },\n }).meta(meta);\n}\n\n/**\n `hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None\n relationships on a {@link Model}.\n\n `hasMany` takes a configuration hash as a second parameter, currently\n supported options are:\n\n - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.\n - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.\n - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic\n - `as`: (*optional*) A string used to declare the abstract type \"this\" record satisfies for polymorphism.\n\n ### Examples\n\n To declare a **many-to-one** (or one-to-many) relationship, use\n `belongsTo` in combination with `hasMany`:\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n\n\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n ```\n\n To declare a **many-to-many** relationship with managed inverses, use `hasMany` for both sides:\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('tag', { async: true, inverse: 'posts' }) tags;\n }\n\n // app/models/tag.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Tag extends Model {\n @hasMany('post', { async: true, inverse: 'tags' }) posts;\n }\n ```\n\n To declare a **many-to-many** relationship without managed inverses, use `hasMany` for both sides\n with `null` as the inverse:\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('tag', { async: true, inverse: null }) tags;\n }\n\n // app/models/tag.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Tag extends Model {\n @hasMany('post', { async: true, inverse: null }) posts;\n }\n ```\n\n To declare a many-to-none relationship between two models, use\n `hasMany` with inverse set to `null` on just one side::\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('category', { async: true, inverse: null }) categories;\n }\n ```\n\n #### Sync vs Async Relationships\n\n WarpDrive fulfills relationships using resource data available in\n the cache.\n\n Sync relationships point directly to the known related resources.\n\n When a relationship is declared as async, if any of the known related\n resources have not been loaded, they will be fetched. The property\n on the record when accessed provides a promise that resolves once\n all resources are loaded.\n\n Async relationships may take advantage of links. On access, if the related\n link has not been loaded, or if any known resources are not available in\n the cache, the fresh state will be fetched using the link.\n\n In contrast to async relationship, accessing a sync relationship\n will error on access when any of the known related resources have\n not been loaded.\n\n If you are using `links` with sync relationships, you have to use\n the HasMany reference API to fetch or refresh related resources\n that aren't loaded. For instance, for a `comments` relationship:\n\n ```js\n post.hasMany('comments').reload();\n ```\n\n #### Polymorphic Relationships\n\n To declare a polymorphic relationship, use `hasMany` with the `polymorphic`\n option set to `true`:\n\n ```js\n // app/models/comment.js\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class Comment extends Model {\n @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;\n }\n ```\n\n `'commentable'` here is referred to as the \"abstract type\" for the polymorphic\n relationship.\n\n Polymorphic relationships with `inverse: null` will accept any type of record as their content.\n Polymorphic relationships with `inverse` set to a string will only accept records with a matching\n inverse relationships declaring itself as satisfying the abstract type.\n\n Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'\n for this relationship.\n\n ```js\n // app/models/post.js\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;\n }\n ```\n\n Note: every Model that declares an inverse to a polymorphic relationship must\n declare itself exactly the same. This is because polymorphism is based on structural\n traits.\n\n Polymorphic to polymorphic relationships are supported. Both sides of the relationship\n must be declared as polymorphic, and the `as` option must be used to declare the abstract\n type each record satisfies on both sides.\n\n @summary Legacy `Model` decorator that declares a to-many relationship to another resource type, configured with\n required `async` and `inverse` options.\n @public\n @param type the name of the related resource\n @param options a hash of options\n*/\nexport function hasMany(): never;\nexport function hasMany(type: string): never;\nexport function hasMany<T>(\n type: TypeFromInstance<NoNull<T>>,\n options: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T>;\n// export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(\n// type: TypeFromInstance<NoNull<T>>,\n// options: RelationshipOptions<T, true>\n// ): RelationshipDecorator<K>;\nexport function hasMany(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;\nexport function hasMany<T>(\n type?: TypeFromInstance<NoNull<T>>,\n options?: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T> {\n if (DEBUG) {\n assert(\n `hasMany must be invoked with a type and options. Did you mean \\`@hasMany(${type}, { async: false, inverse: null })\\`?`,\n !isElementDescriptor(arguments as unknown as unknown[])\n );\n }\n return _hasMany(type!, options!);\n}\n","import { getOwner, setOwner } from '@ember/application';\n\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore, setRecordIdentifier, type Store, StoreMap } from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core/types/record';\n\nimport type { Model, ModelStore } from './model.ts';\nimport { getModelFactory } from './schema-provider.ts';\nimport { normalizeModelName } from './util.ts';\n\nfunction recast(context: Store): asserts context is ModelStore {}\n\n/**\n * The `instantiateRecord` hook implementation for use with `Model`. Pass\n * this to your store's `instantiateRecord` method when configuring the\n * store to use `Model` for schema/record instantiation.\n *\n * @summary Legacy store hook that creates a `Model` instance for a resource key using the `Model` class registered\n * for its type.\n * @public\n */\nexport function instantiateRecord(\n this: Store,\n identifier: ResourceKey,\n createRecordArgs?: { [key: string]: unknown }\n): Model {\n const type = identifier.type;\n\n recast(this);\n\n // TODO deprecate allowing unknown args setting\n const createOptions = {\n _createProps: createRecordArgs ?? {},\n // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for\n _secretInit: {\n identifier,\n store: this,\n cb: secretInit,\n },\n };\n\n // ensure that `getOwner(this)` works inside a model instance\n setOwner(createOptions, getOwner(this)!);\n const factory = getModelFactory(this, type);\n\n assert(`No model was found for '${type}'`, factory);\n return factory.class.create(createOptions);\n}\n\n/**\n * The `teardownRecord` hook implementation for use with `Model`. Pass this\n * to your store's `teardownRecord` method when configuring the store to\n * use `Model` for schema/record instantiation.\n *\n * @summary Legacy store hook that destroys a `Model` instance when the store releases its record.\n * @public\n */\nexport function teardownRecord(record: Model): void {\n assert(\n `expected to receive an instance of Model from @warp-drive/legacy/model. If using a custom model make sure you implement teardownRecord`,\n 'destroy' in record\n );\n record.destroy();\n}\n\n/**\n * The `modelFor` implementation for use with `Model`, exposed on the store\n * as `store.modelFor(type)` when the store is configured to use `Model`.\n * Returns the `Model` subclass registered for the given type, if any.\n *\n * @summary Legacy `store.modelFor` implementation that returns the `Model` class registered for a resource type, if\n * there is one.\n * @public\n */\nexport function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;\n/**\n * Overload accepting a raw type string instead of a typed record instance.\n *\n * @public\n */\nexport function modelFor(type: string): typeof Model | void;\nexport function modelFor<T>(this: Store, modelName: TypeFromInstanceOrString<T>): typeof Model | void {\n assertPrivateStore(this);\n assert(\n `Attempted to call store.modelFor(), but the store instance has already been destroyed.`,\n !this.isDestroyed && !this.isDestroying\n );\n assert(`You need to pass a model name to the store's modelFor method`, modelName);\n assert(\n `Please pass a proper model name to the store's modelFor method`,\n typeof modelName === 'string' && modelName.length\n );\n recast(this);\n\n const type = normalizeModelName(modelName);\n const maybeFactory = getModelFactory(this, type);\n const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;\n\n const ignoreType = !klass || !klass.isModel || this._forceShim;\n if (!ignoreType) {\n return klass;\n }\n assert(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n}\n\nfunction secretInit(record: Model, identifier: ResourceKey, store: Store): void {\n setRecordIdentifier(record, identifier);\n StoreMap.set(record, store);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAASM,MAAMC,MAA6BC,SAAuB;CACjE,IAAI,OAAOD,SAAS,UAAU;EAC5BC,UAAUD;EACVA,OAAOE;CACT,OACED,UAAUA,WAAW,CAAC;CAGxB,MAAME,OAAO;EACLH;EACNI,MAAM;EACNC,aAAa;EACJJ;EACTK,WAAWL,QAAQK;EACnBC,KAAK;CACP;CAEA,OAAOd,SAAS;EACde,IAAiBD,KAAa;GAC5B,IAAAT,eAAAD,gBAAA,CAAA,CAAAY,UAAAC,IAAAC,KAAA,GACE;QAAI,CAAC,cAAc,CAAC,CAACC,SAASL,GAAG,GAC/B,MAAM,IAAIM,MACR,IAAIN,IAAG,kIAAmI,KAAKO,YAAYC,SAAS,GACtK;GACF;GAEF,IAAI,KAAKC,eAAe,KAAKC,cAC3B;GAGF,OADc,KAAKtB,YAAY,CAACuB,MACnBC,QAAQzB,oBAAoB,IAAI,GAAGS,KAAKG,aAAaC,GAAG;EACvE;EACAa,IAAiBb,KAAac,OAAc;GAC1C,IAAAvB,eAAAD,gBAAA,CAAA,CAAAY,UAAAC,IAAAC,KAAA,GACE;QAAI,CAAC,cAAc,C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AAA,CAAE,KAAK4B,OAAOC,YAAY,EAAE7B,KAAK,CAAC,CAAC;AAC7G;AAEA,SAASM,WAAWU,QAAelB,YAAyBM,OAAoB;CAC9Ef,oBAAoB2B,QAAQlB,UAAU;CACtCR,SAASwC,IAAId,QAAQZ,KAAK;AAC5B"}
@@ -1,5 +1,5 @@
1
- import { n as decorateMethodV2, r as initializeDeferredDecorator, t as decorateFieldV2 } from "./runtime--fcdnjmJ-5yaSpa-d.js";
2
1
  import { withDefaults } from "./model/migration-support.js";
2
+ import { n as decorateMethodV2, r as initializeDeferredDecorator, t as decorateFieldV2 } from "./runtime--fcdnjmJ-5yaSpa-d.js";
3
3
  import { Context } from "@warp-drive/core/reactive/-private";
4
4
  import { pluralize, singularize } from "@warp-drive/utilities/string";
5
5
  import { cached, tracked } from "@glimmer/tracking";
@@ -345,4 +345,4 @@ function fragmentsModelFor(modelName) {
345
345
  const modelFor = fragmentsModelFor;
346
346
 
347
347
  export { FragmentExtension as a, withLegacy as c, withArrayDefaults as d, Fragment as i, withFragmentArrayDefaults as l, modelFor as n, FragmentArray as o, registerFragmentExtensions as r, FragmentArrayExtension as s, fragmentsModelFor as t, withFragmentDefaults as u };
348
- //# sourceMappingURL=model-fragments-DCHMDr5f.js.map
348
+ //# sourceMappingURL=model-fragments-bM9vucwt.js.map