@ember-data/legacy-compat 5.4.0-alpha.52 → 5.4.0-alpha.54

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.
@@ -0,0 +1,274 @@
1
+ import { deprecate, assert } from '@ember/debug';
2
+ import { SkipCache } from '@warp-drive/core-types/request';
3
+ import { dasherize } from '@ember/string';
4
+ import { macroCondition, getOwnConfig } from '@embroider/macros';
5
+ import { ensureStringId, constructResource } from '@ember-data/store/-private';
6
+ import { storeFor, recordIdentifierFor } from '@ember-data/store';
7
+ function isMaybeIdentifier(maybeIdentifier) {
8
+ return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
9
+ }
10
+ function normalizeModelName(type) {
11
+ if (macroCondition(getOwnConfig().deprecations.DEPRECATE_NON_STRICT_TYPES)) {
12
+ const result = dasherize(type);
13
+ deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
14
+ id: 'ember-data:deprecate-non-strict-types',
15
+ until: '6.0',
16
+ for: 'ember-data',
17
+ since: {
18
+ available: '5.3',
19
+ enabled: '5.3'
20
+ }
21
+ });
22
+ return result;
23
+ }
24
+ return type;
25
+ }
26
+
27
+ /**
28
+ * @module @ember-data/legacy-compat/builders
29
+ */
30
+
31
+ /**
32
+ This function builds a request config to perform a `findAll` request for the given type.
33
+ When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.
34
+ Additionally, it takes the same options as `store.findAll`.
35
+
36
+ All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
37
+ 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.
38
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
39
+
40
+ @method findAll
41
+ @deprecated
42
+ @public
43
+ @static
44
+ @for @ember-data/legacy-compat/builders
45
+ @param {string} type the name of the resource
46
+ @param {object} query a query to be used by the adapter
47
+ @param {FindAllBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.findAll
48
+ @return {FindAllRequestInput} request config
49
+ */
50
+
51
+ function findAllBuilder(type, options = {}) {
52
+ assert(`You need to pass a model name to the findAll builder`, type);
53
+ assert(`Model name passed to the findAll builder must be a dasherized string instead of ${type}`, typeof type === 'string');
54
+ return {
55
+ op: 'findAll',
56
+ data: {
57
+ type: normalizeModelName(type),
58
+ options: options || {}
59
+ },
60
+ cacheOptions: {
61
+ [SkipCache]: true
62
+ }
63
+ };
64
+ }
65
+
66
+ /**
67
+ * @module @ember-data/legacy-compat/builders
68
+ */
69
+
70
+ /**
71
+ This function builds a request config to find the record for a given identifier or type and id combination.
72
+ When passed to `store.request`, this config will result in the same behavior as a `store.findRecord` request.
73
+ Additionally, it takes the same options as `store.findRecord`, with the exception of `preload` (which is unsupported).
74
+
75
+ **Example 1**
76
+
77
+ ```ts
78
+ import { findRecord } from '@ember-data/legacy-compat/builders';
79
+ const { content: post } = await store.request<Post>(findRecord<Post>('post', '1'));
80
+ ```
81
+
82
+ **Example 2**
83
+
84
+ `findRecord` can be called with a single identifier argument instead of the combination
85
+ of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
86
+ the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
87
+
88
+ ```ts
89
+ import { findRecord } from '@ember-data/legacy-compat/builders';
90
+ const { content: post } = await store.request<Post>(findRecord<Post>({ type: 'post', id }));
91
+ ```
92
+
93
+ All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
94
+ 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.
95
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
96
+
97
+ @method findRecord
98
+ @deprecated
99
+ @public
100
+ @static
101
+ @for @ember-data/legacy-compat/builders
102
+ @param {string|object} type - either a string representing the name of the resource or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
103
+ @param {string|number|object} id - optional object with options for the request only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved
104
+ @param {FindRecordBuilderOptions} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.
105
+ @return {FindRecordRequestInput} request config
106
+ */
107
+
108
+ function findRecordBuilder(resource, idOrOptions, options) {
109
+ assert(`You need to pass a modelName or resource identifier as the first argument to the findRecord builder`, resource);
110
+ if (isMaybeIdentifier(resource)) {
111
+ options = idOrOptions;
112
+ } else {
113
+ assert(`You need to pass a modelName or resource identifier as the first argument to the findRecord builder (passed ${resource})`, typeof resource === 'string');
114
+ const type = normalizeModelName(resource);
115
+ const normalizedId = ensureStringId(idOrOptions);
116
+ resource = constructResource(type, normalizedId);
117
+ }
118
+ options = options || {};
119
+ assert('findRecord builder does not support options.preload', !options.preload);
120
+ return {
121
+ op: 'findRecord',
122
+ data: {
123
+ record: resource,
124
+ options
125
+ },
126
+ cacheOptions: {
127
+ [SkipCache]: true
128
+ }
129
+ };
130
+ }
131
+
132
+ /**
133
+ * @module @ember-data/legacy-compat/builders
134
+ */
135
+
136
+ /**
137
+ This function builds a request config for a given type and query object.
138
+ When passed to `store.request`, this config will result in the same behavior as a `store.query` request.
139
+ Additionally, it takes the same options as `store.query`.
140
+
141
+ All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
142
+ 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.
143
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
144
+
145
+ @method query
146
+ @deprecated
147
+ @public
148
+ @static
149
+ @for @ember-data/legacy-compat/builders
150
+ @param {string} type the name of the resource
151
+ @param {object} query a query to be used by the adapter
152
+ @param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
153
+ @return {QueryRequestInput} request config
154
+ */
155
+
156
+ function queryBuilder(type, query, options = {}) {
157
+ assert(`You need to pass a model name to the query builder`, type);
158
+ assert(`You need to pass a query hash to the query builder`, query);
159
+ assert(`Model name passed to the query builder must be a dasherized string instead of ${type}`, typeof type === 'string');
160
+ return {
161
+ op: 'query',
162
+ data: {
163
+ type: normalizeModelName(type),
164
+ query,
165
+ options: options
166
+ },
167
+ cacheOptions: {
168
+ [SkipCache]: true
169
+ }
170
+ };
171
+ }
172
+
173
+ /**
174
+ This function builds a request config for a given type and query object.
175
+ When passed to `store.request`, this config will result in the same behavior as a `store.queryRecord` request.
176
+ Additionally, it takes the same options as `store.queryRecord`.
177
+
178
+ All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
179
+ 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.
180
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
181
+
182
+ @method queryRecord
183
+ @deprecated
184
+ @public
185
+ @static
186
+ @for @ember-data/legacy-compat/builders
187
+ @param {string} type the name of the resource
188
+ @param {object} query a query to be used by the adapter
189
+ @param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
190
+ @return {QueryRecordRequestInput} request config
191
+ */
192
+
193
+ function queryRecordBuilder(type, query, options) {
194
+ assert(`You need to pass a model name to the queryRecord builder`, type);
195
+ assert(`You need to pass a query hash to the queryRecord builder`, query);
196
+ assert(`Model name passed to the queryRecord builder must be a dasherized string instead of ${type}`, typeof type === 'string');
197
+ return {
198
+ op: 'queryRecord',
199
+ data: {
200
+ type: normalizeModelName(type),
201
+ query,
202
+ options: options || {}
203
+ },
204
+ cacheOptions: {
205
+ [SkipCache]: true
206
+ }
207
+ };
208
+ }
209
+
210
+ /**
211
+ * @module @ember-data/legacy-compat/builders
212
+ */
213
+ function _resourceIsFullDeleted(identifier, cache) {
214
+ return cache.isDeletionCommitted(identifier) || cache.isNew(identifier) && cache.isDeleted(identifier);
215
+ }
216
+ function resourceIsFullyDeleted(instanceCache, identifier) {
217
+ const cache = instanceCache.cache;
218
+ return !cache || _resourceIsFullDeleted(identifier, cache);
219
+ }
220
+
221
+ /**
222
+ This function builds a request config for saving the given record (e.g. creating, updating, or deleting the record).
223
+ When passed to `store.request`, this config will result in the same behavior as a legacy `store.saveRecord` request.
224
+ Additionally, it takes the same options as `store.saveRecord`.
225
+
226
+ All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
227
+ 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.
228
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
229
+
230
+ @method saveRecord
231
+ @deprecated
232
+ @public
233
+ @static
234
+ @for @ember-data/legacy-compat/builders
235
+ @param {object} record a record to save
236
+ @param {SaveRecordBuilderOptions} options optional, may include `adapterOptions` hash which will be passed to adapter.saveRecord
237
+ @return {SaveRecordRequestInput} request config
238
+ */
239
+ function saveRecordBuilder(record, options = {}) {
240
+ const store = storeFor(record);
241
+ assert(`Unable to initiate save for a record in a disconnected state`, store);
242
+ const identifier = recordIdentifierFor(record);
243
+ if (!identifier) {
244
+ // this commonly means we're disconnected
245
+ // but just in case we throw here to prevent bad things.
246
+ throw new Error(`Record Is Disconnected`);
247
+ }
248
+ assert(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`, store._instanceCache.recordIsLoaded(identifier));
249
+ if (resourceIsFullyDeleted(store._instanceCache, identifier)) {
250
+ throw new Error('cannot build saveRecord request for deleted record');
251
+ }
252
+ if (!options) {
253
+ options = {};
254
+ }
255
+ let operation = 'updateRecord';
256
+ const cache = store.cache;
257
+ if (cache.isNew(identifier)) {
258
+ operation = 'createRecord';
259
+ } else if (cache.isDeleted(identifier)) {
260
+ operation = 'deleteRecord';
261
+ }
262
+ return {
263
+ op: operation,
264
+ data: {
265
+ options,
266
+ record: identifier
267
+ },
268
+ records: [identifier],
269
+ cacheOptions: {
270
+ [SkipCache]: true
271
+ }
272
+ };
273
+ }
274
+ export { findAllBuilder as findAll, findRecordBuilder as findRecord, queryBuilder as query, queryRecordBuilder as queryRecord, saveRecordBuilder as saveRecord };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.js","sources":["../src/builders/utils.ts","../src/builders/find-all.ts","../src/builders/find-record.ts","../src/builders/query.ts","../src/builders/save-record.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\nimport { dasherize } from '@ember/string';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@ember-data/deprecations';\nimport type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';\n\nexport function isMaybeIdentifier(\n maybeIdentifier: string | ResourceIdentifierObject\n): maybeIdentifier is ResourceIdentifierObject {\n return Boolean(\n maybeIdentifier !== null &&\n typeof maybeIdentifier === 'object' &&\n (('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type) ||\n maybeIdentifier.lid)\n );\n}\n\nexport function normalizeModelName(type: string): string {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = 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: '5.3',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n","/**\n * @module @ember-data/legacy-compat/builders\n */\nimport { assert } from '@ember/debug';\n\nimport type { StoreRequestInput } from '@ember-data/store';\nimport type { FindAllOptions } from '@ember-data/store/-types/q/store';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';\nimport { SkipCache } from '@warp-drive/core-types/request';\n\nimport { normalizeModelName } from './utils';\n\ntype FindAllRequestInput<T extends string> = StoreRequestInput & {\n op: 'findAll';\n data: {\n type: T;\n options: FindAllBuilderOptions;\n };\n};\n\ntype FindAllBuilderOptions = FindAllOptions;\n\n/**\n This function builds a request config to perform a `findAll` request for the given type.\n When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.\n Additionally, it takes the same options as `store.findAll`.\n\n All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.\n 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.\n To that end, these builders are deprecated and will be removed in a future version of Ember Data.\n\n @method findAll\n @deprecated\n @public\n @static\n @for @ember-data/legacy-compat/builders\n @param {string} type the name of the resource\n @param {object} query a query to be used by the adapter\n @param {FindAllBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.findAll\n @return {FindAllRequestInput} request config\n*/\nexport function findAllBuilder<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n options?: FindAllBuilderOptions\n): FindAllRequestInput<TypeFromInstance<T>>;\nexport function findAllBuilder(type: string, options?: FindAllBuilderOptions): FindAllRequestInput<string>;\nexport function findAllBuilder(type: string, options: FindAllBuilderOptions = {}): FindAllRequestInput<string> {\n assert(`You need to pass a model name to the findAll builder`, type);\n assert(\n `Model name passed to the findAll builder must be a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n return {\n op: 'findAll',\n data: {\n type: normalizeModelName(type),\n options: options || {},\n },\n cacheOptions: { [SkipCache as symbol]: true },\n };\n}\n","/**\n * @module @ember-data/legacy-compat/builders\n */\nimport { assert } from '@ember/debug';\n\nimport type { StoreRequestInput } from '@ember-data/store';\nimport { constructResource, ensureStringId } from '@ember-data/store/-private';\nimport type { BaseFinderOptions, FindRecordOptions } from '@ember-data/store/-types/q/store';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';\nimport { SkipCache } from '@warp-drive/core-types/request';\nimport type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';\n\nimport { isMaybeIdentifier, normalizeModelName } from './utils';\n\ntype FindRecordRequestInput<T extends string> = StoreRequestInput & {\n op: 'findRecord';\n data: {\n record: ResourceIdentifierObject<T>;\n options: FindRecordBuilderOptions;\n };\n};\n\ntype FindRecordBuilderOptions = Omit<FindRecordOptions, 'preload'>;\n\n/**\n This function builds a request config to find the record for a given identifier or type and id combination.\n When passed to `store.request`, this config will result in the same behavior as a `store.findRecord` request.\n Additionally, it takes the same options as `store.findRecord`, with the exception of `preload` (which is unsupported).\n\n **Example 1**\n\n ```ts\n import { findRecord } from '@ember-data/legacy-compat/builders';\n const { content: post } = await store.request<Post>(findRecord<Post>('post', '1'));\n ```\n\n **Example 2**\n\n `findRecord` can be called with a single identifier argument instead of the combination\n of `type` (modelName) and `id` as separate arguments. You may recognize this combo as\n the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)\n\n ```ts\n import { findRecord } from '@ember-data/legacy-compat/builders';\n const { content: post } = await store.request<Post>(findRecord<Post>({ type: 'post', id }));\n ```\n\n All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.\n 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.\n To that end, these builders are deprecated and will be removed in a future version of Ember Data.\n\n @method findRecord\n @deprecated\n @public\n @static\n @for @ember-data/legacy-compat/builders\n @param {string|object} type - either a string representing the name of the resource or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record\n @param {string|number|object} id - optional object with options for the request only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved\n @param {FindRecordBuilderOptions} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.\n @return {FindRecordRequestInput} request config\n*/\nexport function findRecordBuilder<T extends TypedRecordInstance>(\n resource: TypeFromInstance<T>,\n id: string,\n options?: FindRecordBuilderOptions\n): FindRecordRequestInput<TypeFromInstance<T>>;\nexport function findRecordBuilder(\n resource: string,\n id: string,\n options?: FindRecordBuilderOptions\n): FindRecordRequestInput<string>;\nexport function findRecordBuilder<T extends TypedRecordInstance>(\n resource: ResourceIdentifierObject<TypeFromInstance<T>>,\n options?: FindRecordBuilderOptions\n): FindRecordRequestInput<TypeFromInstance<T>>;\nexport function findRecordBuilder(\n resource: ResourceIdentifierObject,\n options?: FindRecordBuilderOptions\n): FindRecordRequestInput<string>;\nexport function findRecordBuilder(\n resource: string | ResourceIdentifierObject,\n idOrOptions?: string | FindRecordBuilderOptions,\n options?: FindRecordBuilderOptions\n): FindRecordRequestInput<string> {\n assert(\n `You need to pass a modelName or resource identifier as the first argument to the findRecord builder`,\n resource\n );\n if (isMaybeIdentifier(resource)) {\n options = idOrOptions as BaseFinderOptions | undefined;\n } else {\n assert(\n `You need to pass a modelName or resource identifier as the first argument to the findRecord builder (passed ${resource})`,\n typeof resource === 'string'\n );\n const type = normalizeModelName(resource);\n const normalizedId = ensureStringId(idOrOptions as string | number);\n resource = constructResource(type, normalizedId);\n }\n\n options = options || {};\n\n assert('findRecord builder does not support options.preload', !(options as FindRecordOptions).preload);\n\n return {\n op: 'findRecord' as const,\n data: {\n record: resource,\n options,\n },\n cacheOptions: { [SkipCache as symbol]: true },\n };\n}\n","/**\n * @module @ember-data/legacy-compat/builders\n */\nimport { assert } from '@ember/debug';\n\nimport type { StoreRequestInput } from '@ember-data/store';\nimport type { QueryOptions } from '@ember-data/store/-types/q/store';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';\nimport { SkipCache } from '@warp-drive/core-types/request';\n\nimport { normalizeModelName } from './utils';\n\ntype QueryRequestInput<T extends string> = StoreRequestInput & {\n op: 'query';\n data: {\n type: T;\n query: Record<string, unknown>;\n options: QueryBuilderOptions;\n };\n};\n\ntype QueryBuilderOptions = QueryOptions;\n\n/**\n This function builds a request config for a given type and query object.\n When passed to `store.request`, this config will result in the same behavior as a `store.query` request.\n Additionally, it takes the same options as `store.query`.\n\n All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.\n 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.\n To that end, these builders are deprecated and will be removed in a future version of Ember Data.\n\n @method query\n @deprecated\n @public\n @static\n @for @ember-data/legacy-compat/builders\n @param {string} type the name of the resource\n @param {object} query a query to be used by the adapter\n @param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query\n @return {QueryRequestInput} request config\n*/\nexport function queryBuilder<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n query: Record<string, unknown>,\n options?: QueryBuilderOptions\n): QueryRequestInput<TypeFromInstance<T>>;\nexport function queryBuilder(\n type: string,\n query: Record<string, unknown>,\n options?: QueryBuilderOptions\n): QueryRequestInput<string>;\nexport function queryBuilder(\n type: string,\n query: Record<string, unknown>,\n options: QueryBuilderOptions = {}\n): QueryRequestInput<string> {\n assert(`You need to pass a model name to the query builder`, type);\n assert(`You need to pass a query hash to the query builder`, query);\n assert(\n `Model name passed to the query builder must be a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n return {\n op: 'query' as const,\n data: {\n type: normalizeModelName(type),\n query,\n options: options,\n },\n cacheOptions: { [SkipCache as symbol]: true },\n };\n}\n\ntype QueryRecordRequestInput<T extends string> = StoreRequestInput & {\n op: 'queryRecord';\n data: {\n type: T;\n query: Record<string, unknown>;\n options: QueryBuilderOptions;\n };\n};\n\n/**\n This function builds a request config for a given type and query object.\n When passed to `store.request`, this config will result in the same behavior as a `store.queryRecord` request.\n Additionally, it takes the same options as `store.queryRecord`.\n\n All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.\n 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.\n To that end, these builders are deprecated and will be removed in a future version of Ember Data.\n\n @method queryRecord\n @deprecated\n @public\n @static\n @for @ember-data/legacy-compat/builders\n @param {string} type the name of the resource\n @param {object} query a query to be used by the adapter\n @param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query\n @return {QueryRecordRequestInput} request config\n*/\nexport function queryRecordBuilder<T extends TypedRecordInstance>(\n type: TypeFromInstance<T>,\n query: Record<string, unknown>,\n options?: QueryBuilderOptions\n): QueryRecordRequestInput<TypeFromInstance<T>>;\nexport function queryRecordBuilder(\n type: string,\n query: Record<string, unknown>,\n options?: QueryBuilderOptions\n): QueryRecordRequestInput<string>;\nexport function queryRecordBuilder(\n type: string,\n query: Record<string, unknown>,\n options?: QueryBuilderOptions\n): QueryRecordRequestInput<string> {\n assert(`You need to pass a model name to the queryRecord builder`, type);\n assert(`You need to pass a query hash to the queryRecord builder`, query);\n assert(\n `Model name passed to the queryRecord builder must be a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n return {\n op: 'queryRecord',\n data: {\n type: normalizeModelName(type),\n query,\n options: options || {},\n },\n cacheOptions: { [SkipCache as symbol]: true },\n };\n}\n","/**\n * @module @ember-data/legacy-compat/builders\n */\nimport { assert } from '@ember/debug';\n\nimport { recordIdentifierFor, storeFor, type StoreRequestInput } from '@ember-data/store';\nimport type { InstanceCache } from '@ember-data/store/-private/caches/instance-cache';\nimport type { StableRecordIdentifier } from '@warp-drive/core-types';\nimport type { Cache } from '@warp-drive/core-types/cache';\nimport type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';\nimport { SkipCache } from '@warp-drive/core-types/request';\n\ntype SaveRecordRequestInput<T extends string> = StoreRequestInput & {\n op: 'createRecord' | 'deleteRecord' | 'updateRecord';\n data: {\n record: StableRecordIdentifier<T>;\n options: SaveRecordBuilderOptions;\n };\n records: [StableRecordIdentifier<T>];\n};\n\ntype SaveRecordBuilderOptions = Record<string, unknown>;\n\nfunction _resourceIsFullDeleted(identifier: StableRecordIdentifier, cache: Cache): boolean {\n return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));\n}\n\nfunction resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean {\n const cache = instanceCache.cache;\n return !cache || _resourceIsFullDeleted(identifier, cache);\n}\n\n/**\n This function builds a request config for saving the given record (e.g. creating, updating, or deleting the record).\n When passed to `store.request`, this config will result in the same behavior as a legacy `store.saveRecord` request.\n Additionally, it takes the same options as `store.saveRecord`.\n\n All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.\n 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.\n To that end, these builders are deprecated and will be removed in a future version of Ember Data.\n\n @method saveRecord\n @deprecated\n @public\n @static\n @for @ember-data/legacy-compat/builders\n @param {object} record a record to save\n @param {SaveRecordBuilderOptions} options optional, may include `adapterOptions` hash which will be passed to adapter.saveRecord\n @return {SaveRecordRequestInput} request config\n*/\nexport function saveRecordBuilder<T extends TypedRecordInstance>(\n record: T,\n options: Record<string, unknown> = {}\n): SaveRecordRequestInput<TypeFromInstance<T>> {\n const store = storeFor(record);\n assert(`Unable to initiate save for a record in a disconnected state`, store);\n const identifier = recordIdentifierFor(record);\n\n if (!identifier) {\n // this commonly means we're disconnected\n // but just in case we throw here to prevent bad things.\n throw new Error(`Record Is Disconnected`);\n }\n assert(\n `Cannot initiate a save request for an unloaded record: ${identifier.lid}`,\n store._instanceCache.recordIsLoaded(identifier)\n );\n if (resourceIsFullyDeleted(store._instanceCache, identifier)) {\n throw new Error('cannot build saveRecord request for deleted record');\n }\n\n if (!options) {\n options = {};\n }\n let operation: 'createRecord' | 'deleteRecord' | 'updateRecord' = 'updateRecord';\n\n const cache = store.cache;\n if (cache.isNew(identifier)) {\n operation = 'createRecord';\n } else if (cache.isDeleted(identifier)) {\n operation = 'deleteRecord';\n }\n\n return {\n op: operation,\n data: {\n options,\n record: identifier,\n },\n records: [identifier],\n cacheOptions: { [SkipCache as symbol]: true },\n };\n}\n"],"names":["isMaybeIdentifier","maybeIdentifier","Boolean","id","type","lid","normalizeModelName","macroCondition","getOwnConfig","deprecations","DEPRECATE_NON_STRICT_TYPES","result","dasherize","deprecate","until","for","since","available","enabled","findAllBuilder","options","assert","op","data","cacheOptions","SkipCache","findRecordBuilder","resource","idOrOptions","normalizedId","ensureStringId","constructResource","preload","record","queryBuilder","query","queryRecordBuilder","_resourceIsFullDeleted","identifier","cache","isDeletionCommitted","isNew","isDeleted","resourceIsFullyDeleted","instanceCache","saveRecordBuilder","store","storeFor","recordIdentifierFor","Error","_instanceCache","recordIsLoaded","operation","records"],"mappings":";;;;;;;AAMO,SAASA,iBAAiBA,CAC/BC,eAAkD,EACL;AAC7C,EAAA,OAAOC,OAAO,CACZD,eAAe,KAAK,IAAI,IACtB,OAAOA,eAAe,KAAK,QAAQ,KACjC,IAAI,IAAIA,eAAe,IAAI,MAAM,IAAIA,eAAe,IAAIA,eAAe,CAACE,EAAE,IAAIF,eAAe,CAACG,IAAI,IAClGH,eAAe,CAACI,GAAG,CACzB,CAAC,CAAA;AACH,CAAA;AAEO,SAASC,kBAAkBA,CAACF,IAAY,EAAU;AACvD,EAAA,IAAAG,cAAA,CAAAC,YAAA,GAAAC,YAAA,CAAAC,0BAAA,CAAgC,EAAA;AAC9B,IAAA,MAAMC,MAAM,GAAGC,SAAS,CAACR,IAAI,CAAC,CAAA;AAE9BS,IAAAA,SAAS,CACN,CAAA,mBAAA,EAAqBT,IAAK,CAAA,0DAAA,EAA4DO,MAAO,CAAA,cAAA,EAAgBP,IAAK,CAAA,EAAA,CAAG,EACtHO,MAAM,KAAKP,IAAI,EACf;AACED,MAAAA,EAAE,EAAE,uCAAuC;AAC3CW,MAAAA,KAAK,EAAE,KAAK;AACZC,MAAAA,GAAG,EAAE,YAAY;AACjBC,MAAAA,KAAK,EAAE;AACLC,QAAAA,SAAS,EAAE,KAAK;AAChBC,QAAAA,OAAO,EAAE,KAAA;AACX,OAAA;AACF,KACF,CAAC,CAAA;AAED,IAAA,OAAOP,MAAM,CAAA;AACf,GAAA;AAEA,EAAA,OAAOP,IAAI,CAAA;AACb;;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,MAAA,CAACC,SAAS,GAAa,IAAA;AAAK,KAAA;GAC7C,CAAA;AACH;;;;"}
package/addon/index.js CHANGED
@@ -350,6 +350,7 @@ function saveRecord(context) {
350
350
  options,
351
351
  record: identifier
352
352
  } = data;
353
+ store.cache.willCommit(identifier, context);
353
354
  const saveOptions = Object.assign({
354
355
  [SaveOp]: operation
355
356
  }, options);