UNPKG

87.6 kBTypeScriptView Raw
1// Type definitions for ember-data 4.4
2// Project: https://github.com/emberjs/data
3// Definitions by: Derek Wickern <https://github.com/dwickern>
4// Mike North <https://github.com/mike-north>
5// Chris Krycho <https://github.com/chriskrycho>
6// James C. Davis <https://github.com/jamescdavis>
7// Chris Thoburn <https://github.com/runspired>
8// Peter Wagenet <https://github.com/wagenet>
9// Dan Freeman <https://github.com/dfreeman>
10// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
11// Minimum TypeScript Version: 4.4
12
13import Ember from 'ember';
14import Evented from '@ember/object/evented';
15import ObjectProxy from '@ember/object/proxy';
16import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
17import RSVP from 'rsvp';
18import TransformRegistry from 'ember-data/types/registries/transform';
19import ModelRegistry from 'ember-data/types/registries/model';
20import SerializerRegistry from 'ember-data/types/registries/serializer';
21import AdapterRegistry from 'ember-data/types/registries/adapter';
22import EmberError from '@ember/error';
23
24/**
25 The keys from the actual Model class, removing all the keys which come from
26 the base class.
27 */
28type ModelKeys<Model extends DS.Model> = Exclude<keyof Model, keyof DS.Model>;
29
30type AttributesFor<Model extends DS.Model> = ModelKeys<Model>; // TODO: filter to attr properties only (TS 2.8)
31type RelationshipsFor<Model extends DS.Model> = ModelKeys<Model>; // TODO: filter to hasMany/belongsTo properties only (TS 2.8)
32
33export interface ChangedAttributes {
34 [key: string]: [any, any] | undefined;
35}
36interface AttributeMeta<Model extends DS.Model> {
37 type: keyof TransformRegistry;
38 options: object;
39 name: AttributesFor<Model>;
40 parentType: Model;
41 isAttribute: true;
42}
43
44interface RelationshipMetaOptions {
45 async?: boolean | undefined;
46 inverse?: string | undefined;
47 polymorphic?: boolean | undefined;
48 [k: string]: any;
49}
50interface RelationshipMeta<Model extends DS.Model> {
51 key: RelationshipsFor<Model>;
52 kind: 'belongsTo' | 'hasMany';
53 type: keyof ModelRegistry;
54 options: RelationshipMetaOptions;
55 name: string;
56 parentType: Model;
57 isRelationship: true;
58}
59
60export interface ModelSchema<ModelName extends keyof ModelRegistry = keyof ModelRegistry> {
61 modelName: ModelName;
62 fields: Map<string, 'attribute' | 'belongsTo' | 'hasMany'>;
63 attributes: Map<string, AttributeSchema>;
64 relationshipsByName: Map<string, RelationshipSchema>;
65 eachAttribute<T>(callback: (this: T, key: string, attribute: AttributeSchema) => void, binding?: T): void;
66 eachRelationship<T>(callback: (this: T, key: string, relationship: RelationshipSchema) => void, binding?: T): void;
67 eachTransformedAttribute<T>(
68 callback: (this: T, key: string, relationship: RelationshipSchema) => void,
69 binding?: T,
70 ): void;
71}
72export interface RelationshipSchema {
73 name: string; // property key for this relationship
74 kind: 'belongsTo' | 'hasMany';
75 type: string; // related type
76 options: {
77 async: boolean;
78 polymorphic?: boolean;
79 as?: string;
80 inverse: string | null; // property key on the related type (if any)
81 [key: string]: unknown;
82 };
83}
84export interface AttributeSchema {
85 name: string;
86 kind?: 'attribute';
87 options?: Record<string, unknown>;
88 type?: string;
89}
90
91export namespace DS {
92 /**
93 * Convert an hash of errors into an array with errors in JSON-API format.
94 */
95 function errorsHashToArray(errors: {}): any[];
96 /**
97 * Convert an array of errors in JSON-API format into an object.
98 */
99 function errorsArrayToHash(errors: any[]): {};
100
101 interface RelationshipOptions<M extends Model> {
102 async?: boolean | undefined;
103 inverse?: RelationshipsFor<M> | null | undefined;
104 polymorphic?: boolean | undefined;
105 }
106
107 interface Sync {
108 async: false;
109 }
110 interface Async {
111 async?: true | undefined;
112 }
113
114 type AsyncBelongsTo<T extends Model | null> = PromiseObject<T>;
115 /**
116 * `DS.belongsTo` is used to define One-To-One and One-To-Many
117 * relationships on a [DS.Model](/api/data/classes/DS.Model.html).
118 */
119 function belongsTo<K extends keyof ModelRegistry>(
120 modelName: K,
121 options: RelationshipOptions<ModelRegistry[K]> & Sync
122 ): Ember.ComputedProperty<
123 ModelRegistry[K] | null,
124 ModelRegistry[K] | PromiseObject<ModelRegistry[K] | null> | null
125 >;
126 function belongsTo<K extends keyof ModelRegistry>(
127 modelName: K,
128 options?: RelationshipOptions<ModelRegistry[K]> & Async
129 ): Ember.ComputedProperty<
130 AsyncBelongsTo<ModelRegistry[K] | null>,
131 ModelRegistry[K] | PromiseObject<ModelRegistry[K] | null> | null
132 >;
133 type AsyncHasMany<T extends Model> = PromiseManyArray<T>;
134 type SyncHasMany<T extends Model> = ManyArray<T>;
135 /**
136 * `DS.hasMany` is used to define One-To-Many and Many-To-Many
137 * relationships on a [DS.Model](/api/data/classes/DS.Model.html).
138 */
139 function hasMany<K extends keyof ModelRegistry>(
140 type: K,
141 options: RelationshipOptions<ModelRegistry[K]> & Sync
142 ): Ember.ComputedProperty<SyncHasMany<ModelRegistry[K]>>;
143 function hasMany<K extends keyof ModelRegistry>(
144 type: K,
145 options?: RelationshipOptions<ModelRegistry[K]> & Async
146 ): Ember.ComputedProperty<
147 AsyncHasMany<ModelRegistry[K]>,
148 Ember.Array<ModelRegistry[K]>
149 >;
150 /**
151 * This method normalizes a modelName into the format Ember Data uses
152 * internally.
153 */
154 function normalizeModelName<K extends keyof ModelRegistry>(
155 modelName: K
156 ): string;
157 const VERSION: string;
158
159 interface AttrOptions<T> {
160 defaultValue?: T extends Exclude<object, null> ? (() => T) : T | (() => T) | undefined;
161 allowNull?: boolean | undefined; // TODO: restrict to boolean transform (TS 2.8)
162 [key: string]: unknown;
163 }
164
165 // The TransformRegistry should really only contain transforms, but historically people have just put the return type directly in.
166 type TransformType<K extends keyof TransformRegistry> = TransformRegistry[K] extends Transform ? ReturnType<TransformRegistry[K]['deserialize']> : TransformRegistry[K];
167
168 /**
169 * `DS.attr` defines an attribute on a [DS.Model](/api/data/classes/DS.Model.html).
170 * By default, attributes are passed through as-is, however you can specify an
171 * optional type to have the value automatically transformed.
172 * Ember Data ships with four basic transform types: `string`, `number`,
173 * `boolean` and `date`. You can define your own transforms by subclassing
174 * [DS.Transform](/api/data/classes/DS.Transform.html).
175 */
176 function attr<K extends keyof TransformRegistry>(
177 type: K,
178 options?: AttrOptions<TransformType<K>>
179 ): Ember.ComputedProperty<TransformType<K>>;
180 function attr(options?: AttrOptions<any>): Ember.ComputedProperty<any>;
181 function attr(target: any, propertyKey: string): void;
182
183 /**
184 * WARNING: This interface is likely to change in order to accomodate https://github.com/emberjs/rfcs/pull/4
185 * ## Using BuildURLMixin
186 * To use url building, include the mixin when extending an adapter, and call `buildURL` where needed.
187 * The default behaviour is designed for RESTAdapter.
188 * ### Example
189 * ```javascript
190 * export default DS.Adapter.extend(BuildURLMixin, {
191 * findRecord: function(store, type, id, snapshot) {
192 * var url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
193 * return this.ajax(url, 'GET');
194 * }
195 * });
196 * ```
197 * ### Attributes
198 * The `host` and `namespace` attributes will be used if defined, and are optional.
199 */
200 class BuildURLMixin {
201 /**
202 * Builds a URL for a given type and optional ID.
203 */
204 buildURL<K extends keyof ModelRegistry>(
205 modelName?: K,
206 id?: string | any[] | {} | null,
207 snapshot?: Snapshot<K> | any[] | null,
208 requestType?: string,
209 query?: {}
210 ): string;
211 /**
212 * Used by `findAll` and `findRecord` to build the query's `data` hash supplied to the ajax method.
213 */
214 buildQuery<K extends keyof ModelRegistry>(
215 snapshot: Snapshot<K>
216 ): Record<string, unknown>;
217 /**
218 * Builds a URL for a `store.findRecord(type, id)` call.
219 */
220 urlForFindRecord<K extends keyof ModelRegistry>(
221 id: string,
222 modelName: K,
223 snapshot: Snapshot<K>
224 ): string;
225 /**
226 * Builds a URL for a `store.findAll(type)` call.
227 */
228 urlForFindAll<K extends keyof ModelRegistry>(
229 modelName: K,
230 snapshot: SnapshotRecordArray<K>
231 ): string;
232 /**
233 * Builds a URL for a `store.query(type, query)` call.
234 */
235 urlForQuery<K extends keyof ModelRegistry>(
236 query: {},
237 modelName: K
238 ): string;
239 /**
240 * Builds a URL for a `store.queryRecord(type, query)` call.
241 */
242 urlForQueryRecord<K extends keyof ModelRegistry>(
243 query: {},
244 modelName: K
245 ): string;
246 /**
247 * Builds a URL for coalesceing multiple `store.findRecord(type, id)`
248 * records into 1 request when the adapter's `coalesceFindRequests`
249 * property is true.
250 */
251 urlForFindMany<K extends keyof ModelRegistry>(
252 ids: any[],
253 modelName: K,
254 snapshots: any[]
255 ): string;
256 /**
257 * Builds a URL for fetching a async hasMany relationship when a url
258 * is not provided by the server.
259 */
260 urlForFindHasMany<K extends keyof ModelRegistry>(
261 id: string,
262 modelName: K,
263 snapshot: Snapshot<K>
264 ): string;
265 /**
266 * Builds a URL for fetching a async belongsTo relationship when a url
267 * is not provided by the server.
268 */
269 urlForFindBelongsTo<K extends keyof ModelRegistry>(
270 id: string,
271 modelName: K,
272 snapshot: Snapshot<K>
273 ): string;
274 /**
275 * Builds a URL for a `record.save()` call when the record was created
276 * locally using `store.createRecord()`.
277 */
278 urlForCreateRecord<K extends keyof ModelRegistry>(
279 modelName: K,
280 snapshot: Snapshot<K>
281 ): string;
282 /**
283 * Builds a URL for a `record.save()` call when the record has been update locally.
284 */
285 urlForUpdateRecord<K extends keyof ModelRegistry>(
286 id: string,
287 modelName: K,
288 snapshot: Snapshot<K>
289 ): string;
290 /**
291 * Builds a URL for a `record.save()` call when the record has been deleted locally.
292 */
293 urlForDeleteRecord<K extends keyof ModelRegistry>(
294 id: string,
295 modelName: K,
296 snapshot: Snapshot<K>
297 ): string;
298 /**
299 * Determines the pathname for a given type.
300 */
301 pathForType<K extends keyof ModelRegistry>(modelName: K): string;
302 }
303 /**
304 * A `DS.AdapterError` is used by an adapter to signal that an error occurred
305 * during a request to an external API. It indicates a generic error, and
306 * subclasses are used to indicate specific error states. The following
307 * subclasses are provided:
308 */
309 class AdapterError extends EmberError {
310 static extend(options?: { message?: string }): typeof AdapterError;
311 }
312 /**
313 * A `DS.InvalidError` is used by an adapter to signal the external API
314 * was unable to process a request because the content was not
315 * semantically correct or meaningful per the API. Usually this means a
316 * record failed some form of server side validation. When a promise
317 * from an adapter is rejected with a `DS.InvalidError` the record will
318 * transition to the `invalid` state and the errors will be set to the
319 * `errors` property on the record.
320 */
321 class InvalidError extends AdapterError {
322 constructor(errors: any[]);
323 }
324 /**
325 * A `DS.TimeoutError` is used by an adapter to signal that a request
326 * to the external API has timed out. I.e. no response was received from
327 * the external API within an allowed time period.
328 */
329 class TimeoutError extends AdapterError {}
330 /**
331 * A `DS.AbortError` is used by an adapter to signal that a request to
332 * the external API was aborted. For example, this can occur if the user
333 * navigates away from the current page after a request to the external API
334 * has been initiated but before a response has been received.
335 */
336 class AbortError extends AdapterError {}
337 /**
338 * A `DS.UnauthorizedError` equates to a HTTP `401 Unauthorized` response
339 * status. It is used by an adapter to signal that a request to the external
340 * API was rejected because authorization is required and has failed or has not
341 * yet been provided.
342 */
343 class UnauthorizedError extends AdapterError {}
344 /**
345 * A `DS.ForbiddenError` equates to a HTTP `403 Forbidden` response status.
346 * It is used by an adapter to signal that a request to the external API was
347 * valid but the server is refusing to respond to it. If authorization was
348 * provided and is valid, then the authenticated user does not have the
349 * necessary permissions for the request.
350 */
351 class ForbiddenError extends AdapterError {}
352 /**
353 * A `DS.NotFoundError` equates to a HTTP `404 Not Found` response status.
354 * It is used by an adapter to signal that a request to the external API
355 * was rejected because the resource could not be found on the API.
356 */
357 class NotFoundError extends AdapterError {}
358 /**
359 * A `DS.ConflictError` equates to a HTTP `409 Conflict` response status.
360 * It is used by an adapter to indicate that the request could not be processed
361 * because of a conflict in the request. An example scenario would be when
362 * creating a record with a client generated id but that id is already known
363 * to the external API.
364 */
365 class ConflictError extends AdapterError {}
366 /**
367 * A `DS.ServerError` equates to a HTTP `500 Internal Server Error` response
368 * status. It is used by the adapter to indicate that a request has failed
369 * because of an error in the external API.
370 */
371 class ServerError extends AdapterError {}
372 /**
373 * Holds validation errors for a given record, organized by attribute names.
374 */
375 interface Errors extends Ember.Enumerable<any>, Evented {}
376 class Errors extends Ember.ArrayProxy<any> {
377 /**
378 * DEPRECATED:
379 * Register with target handler
380 */
381 registerHandlers(
382 target: {},
383 becameInvalid: Function,
384 becameValid: Function
385 ): any;
386 /**
387 * Returns errors for a given attribute
388 */
389 errorsFor(attribute: string): any[];
390 /**
391 * An array containing all of the error messages for this
392 * record. This is useful for displaying all errors to the user.
393 */
394 messages: Ember.ComputedProperty<any[]>;
395 /**
396 * Total number of errors.
397 */
398 length: Ember.ComputedProperty<number>;
399 isEmpty: Ember.ComputedProperty<boolean>;
400 /**
401 * DEPRECATED:
402 * Adds error messages to a given attribute and sends
403 * `becameInvalid` event to the record.
404 */
405 add(attribute: string, messages: any[] | string): any;
406 /**
407 * DEPRECATED:
408 * Removes all error messages from the given attribute and sends
409 * `becameValid` event to the record if there no more errors left.
410 */
411 remove(attribute: string): any;
412 /**
413 * DEPRECATED:
414 * Removes all error messages and sends `becameValid` event
415 * to the record.
416 */
417 clear(): any;
418 /**
419 * Checks if there is error messages for the given attribute.
420 */
421 has(attribute: string): boolean;
422 }
423 /**
424 * The model class that all Ember Data records descend from.
425 * This is the public API of Ember Data models. If you are using Ember Data
426 * in your application, this is the class you should use.
427 * If you are working on Ember Data internals, you most likely want to be dealing
428 * with `InternalModel`
429 */
430 class Model extends Ember.Object {
431 /**
432 * If this property is `true` the record is in the `empty`
433 * state. Empty is the first state all records enter after they have
434 * been created. Most records created by the store will quickly
435 * transition to the `loading` state if data needs to be fetched from
436 * the server or the `created` state if the record is created on the
437 * client. A record can also enter the empty state if the adapter is
438 * unable to locate the record.
439 */
440 isEmpty: Ember.ComputedProperty<boolean>;
441 /**
442 * If this property is `true` the record is in the `loading` state. A
443 * record enters this state when the store asks the adapter for its
444 * data. It remains in this state until the adapter provides the
445 * requested data.
446 */
447 isLoading: Ember.ComputedProperty<boolean>;
448 /**
449 * If this property is `true` the record is in the `loaded` state. A
450 * record enters this state when its data is populated. Most of a
451 * record's lifecycle is spent inside substates of the `loaded`
452 * state.
453 */
454 isLoaded: Ember.ComputedProperty<boolean>;
455 /**
456 * If this property is `true` the record is in the `dirty` state. The
457 * record has local changes that have not yet been saved by the
458 * adapter. This includes records that have been created (but not yet
459 * saved) or deleted.
460 */
461 hasDirtyAttributes: Ember.ComputedProperty<boolean>;
462 /**
463 * If this property is `true` the record is in the `saving` state. A
464 * record enters the saving state when `save` is called, but the
465 * adapter has not yet acknowledged that the changes have been
466 * persisted to the backend.
467 */
468 isSaving: Ember.ComputedProperty<boolean>;
469 /**
470 * If this property is `true` the record is in the `deleted` state
471 * and has been marked for deletion. When `isDeleted` is true and
472 * `hasDirtyAttributes` is true, the record is deleted locally but the deletion
473 * was not yet persisted. When `isSaving` is true, the change is
474 * in-flight. When both `hasDirtyAttributes` and `isSaving` are false, the
475 * change has persisted.
476 */
477 isDeleted: Ember.ComputedProperty<boolean>;
478 /**
479 * If this property is `true` the record is in the `new` state. A
480 * record will be in the `new` state when it has been created on the
481 * client and the adapter has not yet report that it was successfully
482 * saved.
483 */
484 isNew: Ember.ComputedProperty<boolean>;
485 /**
486 * If this property is `true` the record is in the `valid` state.
487 */
488 isValid: Ember.ComputedProperty<boolean>;
489 /**
490 * If the record is in the dirty state this property will report what
491 * kind of change has caused it to move into the dirty
492 * state. Possible values are:
493 */
494 dirtyType: Ember.ComputedProperty<string>;
495 /**
496 * If `true` the adapter reported that it was unable to save local
497 * changes to the backend for any reason other than a server-side
498 * validation error.
499 */
500 isError: boolean;
501 /**
502 * If `true` the store is attempting to reload the record from the adapter.
503 */
504 isReloading: boolean;
505 /**
506 * All ember models have an id property. This is an identifier
507 * managed by an external source. These are always coerced to be
508 * strings before being used internally. Note when declaring the
509 * attributes for a model it is an error to declare an id
510 * attribute.
511 */
512 id: string;
513 /**
514 * A reference to DS.Store service instance.
515 */
516 store: Store;
517 /**
518 * When the record is in the `invalid` state this object will contain
519 * any errors returned by the adapter. When present the errors hash
520 * contains keys corresponding to the invalid property names
521 * and values which are arrays of Javascript objects with two keys:
522 */
523 errors: Errors;
524 /**
525 * This property holds the `DS.AdapterError` object with which
526 * last adapter operation was rejected.
527 */
528 adapterError: AdapterError;
529 /**
530 * Create a JSON representation of the record, using the serialization
531 * strategy of the store's adapter.
532 */
533 serialize(options?: { includeId?: boolean | undefined }): object;
534 /**
535 * Use [DS.JSONSerializer](DS.JSONSerializer.html) to
536 * get the JSON representation of a record.
537 */
538 toJSON(options?: { includeId?: boolean | undefined }): object;
539 /**
540 * Fired when the record is ready to be interacted with,
541 * that is either loaded from the server or created locally.
542 */
543 ready(): void;
544 /**
545 * Fired when the record is loaded from the server.
546 */
547 didLoad(): void;
548 /**
549 * Fired when the record is updated.
550 */
551 didUpdate(): void;
552 /**
553 * Fired when a new record is commited to the server.
554 */
555 didCreate(): void;
556 /**
557 * Fired when the record is deleted.
558 */
559 didDelete(): void;
560 /**
561 * Fired when the record becomes invalid.
562 */
563 becameInvalid(): void;
564 /**
565 * Fired when the record enters the error state.
566 */
567 becameError(): void;
568 /**
569 * Fired when the record is rolled back.
570 */
571 rolledBack(): void;
572 /**
573 * Marks the record as deleted but does not save it. You must call
574 * `save` afterwards if you want to persist it. You might use this
575 * method if you want to allow the user to still `rollbackAttributes()`
576 * after a delete was made.
577 */
578 deleteRecord(): void;
579 /**
580 * Same as `deleteRecord`, but saves the record immediately.
581 */
582 destroyRecord(options?: { adapterOptions?: object | undefined }): RSVP.Promise<this>;
583 /**
584 * Unloads the record from the store. This will cause the record to be destroyed and freed up for garbage collection.
585 */
586 unloadRecord(): void;
587 /**
588 * Returns an object, whose keys are changed properties, and value is
589 * an [oldProp, newProp] array.
590 */
591 changedAttributes(): ChangedAttributes;
592 /**
593 * If the model `hasDirtyAttributes` this function will discard any unsaved
594 * changes. If the model `isNew` it will be removed from the store.
595 */
596 rollbackAttributes(): void;
597 /**
598 * Save the record and persist any changes to the record to an
599 * external source via the adapter.
600 */
601 save(options?: { adapterOptions?: object | undefined }): RSVP.Promise<this>;
602 /**
603 * Reload the record from the adapter.
604 */
605 reload(options?: { adapterOptions?: object | undefined }): RSVP.Promise<this>;
606 /**
607 * Get the reference for the specified belongsTo relationship.
608 */
609 belongsTo(name: RelationshipsFor<this>): BelongsToReference;
610 /**
611 * Get the reference for the specified hasMany relationship.
612 */
613 hasMany(name: RelationshipsFor<this>): HasManyReference<any>;
614 /**
615 * Given a callback, iterates over each of the relationships in the model,
616 * invoking the callback with the name of each relationship and its relationship
617 * descriptor.
618 */
619 eachRelationship<T extends Model>(
620 this: T,
621 callback: (name: ModelKeys<T>, details: RelationshipMeta<T>) => void,
622 binding?: any
623 ): void;
624 /**
625 * Represents the model's class name as a string. This can be used to look up the model's class name through
626 * `DS.Store`'s modelFor method.
627 */
628 static modelName: keyof ModelRegistry;
629 /**
630 * For a given relationship name, returns the model type of the relationship.
631 */
632 static typeForRelationship<K extends keyof ModelRegistry>(
633 name: K,
634 store: Store
635 ): ModelRegistry[K];
636 /**
637 * Find the relationship which is the inverse of the one asked for.
638 */
639 static inverseFor<K extends keyof ModelRegistry>(
640 name: K,
641 store: Store
642 ): {};
643 /**
644 * The model's relationships as a map, keyed on the type of the
645 * relationship. The value of each entry is an array containing a descriptor
646 * for each relationship with that type, describing the name of the relationship
647 * as well as the type.
648 */
649 static relationships: Ember.ComputedProperty<Map<string, unknown>>;
650 /**
651 * A hash containing lists of the model's relationships, grouped
652 * by the relationship kind. For example, given a model with this
653 * definition:
654 */
655 static relationshipNames: Ember.ComputedProperty<{}>;
656 /**
657 * An array of types directly related to a model. Each type will be
658 * included once, regardless of the number of relationships it has with
659 * the model.
660 */
661 static relatedTypes: Ember.ComputedProperty<Ember.NativeArray<string>>;
662 /**
663 * A map whose keys are the relationships of a model and whose values are
664 * relationship descriptors.
665 */
666 static relationshipsByName: Ember.ComputedProperty<Map<string, unknown>>;
667 /**
668 * A map whose keys are the fields of the model and whose values are strings
669 * describing the kind of the field. A model's fields are the union of all of its
670 * attributes and relationships.
671 */
672 static fields: Ember.ComputedProperty<Map<string, unknown>>;
673 /**
674 * Given a callback, iterates over each of the relationships in the model,
675 * invoking the callback with the name of each relationship and its relationship
676 * descriptor.
677 */
678 static eachRelationship<M extends Model = Model>(
679 callback: (name: ModelKeys<M>, details: RelationshipMeta<M>) => void,
680 binding?: any
681 ): void;
682 /**
683 * Given a callback, iterates over each of the types related to a model,
684 * invoking the callback with the related type's class. Each type will be
685 * returned just once, regardless of how many different relationships it has
686 * with a model.
687 */
688 static eachRelatedType(callback: (name: string) => void, binding?: any): void;
689 /**
690 * A map whose keys are the attributes of the model (properties
691 * described by DS.attr) and whose values are the meta object for the
692 * property.
693 */
694 static attributes: Ember.ComputedProperty<Map<string, unknown>>;
695 /**
696 * A map whose keys are the attributes of the model (properties
697 * described by DS.attr) and whose values are type of transformation
698 * applied to each attribute. This map does not include any
699 * attributes that do not have an transformation type.
700 */
701 static transformedAttributes: Ember.ComputedProperty<Map<string, unknown>>;
702 /**
703 * Iterates through the attributes of the model, calling the passed function on each
704 * attribute.
705 */
706 static eachAttribute<Class extends typeof Model, M extends InstanceType<Class>>(
707 this: Class,
708 callback: (
709 name: ModelKeys<M>,
710 meta: AttributeMeta<M>
711 ) => void,
712 binding?: any
713 ): void;
714 /**
715 * Iterates through the transformedAttributes of the model, calling
716 * the passed function on each attribute. Note the callback will not be
717 * called for any attributes that do not have an transformation type.
718 */
719 static eachTransformedAttribute<Class extends typeof Model>(
720 this: Class,
721 callback: (
722 name: ModelKeys<InstanceType<Class>>,
723 type: keyof TransformRegistry
724 ) => void,
725 binding?: any
726 ): void;
727 }
728 /**
729 * ### State
730 */
731 class RootState {}
732 /**
733 * Represents an ordered list of records whose order and membership is
734 * determined by the adapter. For example, a query sent to the adapter
735 * may trigger a search on the server, whose results would be loaded
736 * into an instance of the `AdapterPopulatedRecordArray`.
737 */
738 class AdapterPopulatedRecordArray<T> extends RecordArray<T> {}
739 /**
740 * Represents a list of records whose membership is determined by the
741 * store. As records are created, loaded, or modified, the store
742 * evaluates them to determine if they should be part of the record
743 * array.
744 */
745 class FilteredRecordArray<T> extends RecordArray<T> {
746 /**
747 * The filterFunction is a function used to test records from the store to
748 * determine if they should be part of the record array.
749 */
750 filterFunction(record: Model): boolean;
751 }
752 /**
753 * A record array is an array that contains records of a certain modelName. The record
754 * array materializes records as needed when they are retrieved for the first
755 * time. You should not create record arrays yourself. Instead, an instance of
756 * `DS.RecordArray` or its subclasses will be returned by your application's store
757 * in response to queries.
758 */
759 interface RecordArray<T> extends Ember.ArrayProxy<T>, Evented {}
760 class RecordArray<T> {
761 /**
762 * The flag to signal a `RecordArray` is finished loading data.
763 */
764 isLoaded: boolean;
765 /**
766 * The flag to signal a `RecordArray` is currently loading data.
767 */
768 isUpdating: boolean;
769 /**
770 * The modelClass represented by this record array.
771 */
772 type: Ember.ComputedProperty<Model>;
773 /**
774 * Used to get the latest version of all of the records in this array
775 * from the adapter.
776 */
777 update(): PromiseArray<T>;
778 /**
779 * Saves all of the records in the `RecordArray`.
780 */
781 save(): PromiseArray<T>;
782 }
783 /**
784 * A BelongsToReference is a low level API that allows users and
785 * addon author to perform meta-operations on a belongs-to
786 * relationship.
787 */
788 class BelongsToReference {
789 /**
790 * This returns a string that represents how the reference will be
791 * looked up when it is loaded. If the relationship has a link it will
792 * use the "link" otherwise it defaults to "id".
793 */
794 remoteType(): string;
795 /**
796 * The `id` of the record that this reference refers to. Together, the
797 * `type()` and `id()` methods form a composite key for the identity
798 * map. This can be used to access the id of an async relationship
799 * without triggering a fetch that would normally happen if you
800 * attempted to use `record.get('relationship.id')`.
801 */
802 id(): string;
803 /**
804 * The link Ember Data will use to fetch or reload this belongs-to
805 * relationship.
806 */
807 link(): string;
808 /**
809 * The meta data for the belongs-to relationship.
810 */
811 meta(): {};
812 /**
813 * `push` can be used to update the data in the relationship and Ember
814 * Data will treat the new data as the conanical value of this
815 * relationship on the backend.
816 */
817 push(objectOrPromise: {} | RSVP.Promise<any>): RSVP.Promise<any>;
818 /**
819 * `value()` synchronously returns the current value of the belongs-to
820 * relationship. Unlike `record.get('relationshipName')`, calling
821 * `value()` on a reference does not trigger a fetch if the async
822 * relationship is not yet loaded. If the relationship is not loaded
823 * it will always return `null`.
824 */
825 value(): Model | null;
826 /**
827 * Loads a record in a belongs to relationship if it is not already
828 * loaded. If the relationship is already loaded this method does not
829 * trigger a new load.
830 */
831 load(): RSVP.Promise<any>;
832 /**
833 * Triggers a reload of the value in this relationship. If the
834 * remoteType is `"link"` Ember Data will use the relationship link to
835 * reload the relationship. Otherwise it will reload the record by its
836 * id.
837 */
838 reload(): RSVP.Promise<any>;
839 }
840 /**
841 * A HasManyReference is a low level API that allows users and addon
842 * author to perform meta-operations on a has-many relationship.
843 */
844 class HasManyReference<T> {
845 /**
846 * This returns a string that represents how the reference will be
847 * looked up when it is loaded. If the relationship has a link it will
848 * use the "link" otherwise it defaults to "id".
849 */
850 remoteType(): string;
851 /**
852 * The link Ember Data will use to fetch or reload this has-many
853 * relationship.
854 */
855 link(): string;
856 /**
857 * `ids()` returns an array of the record ids in this relationship.
858 */
859 ids(): string[];
860 /**
861 * The meta data for the has-many relationship.
862 */
863 meta(): {};
864 /**
865 * `push` can be used to update the data in the relationship and Ember
866 * Data will treat the new data as the canonical value of this
867 * relationship on the backend.
868 */
869 push(objectOrPromise: T[] | RSVP.Promise<T[]>): ManyArray<T>;
870 /**
871 * `value()` synchronously returns the current value of the has-many
872 * relationship. Unlike `record.get('relationshipName')`, calling
873 * `value()` on a reference does not trigger a fetch if the async
874 * relationship is not yet loaded. If the relationship is not loaded
875 * it will always return `null`.
876 */
877 value(): ManyArray<T> | null;
878 /**
879 * Loads the relationship if it is not already loaded. If the
880 * relationship is already loaded this method does not trigger a new
881 * load.
882 */
883 load(): RSVP.Promise<any>;
884 /**
885 * Reloads this has-many relationship.
886 */
887 reload(): RSVP.Promise<any>;
888 }
889 /**
890 * An RecordReference is a low level API that allows users and
891 * addon author to perform meta-operations on a record.
892 */
893 class RecordReference<T extends Model> {
894 /**
895 * The `id` of the record that this reference refers to.
896 */
897 id(): string;
898 /**
899 * How the reference will be looked up when it is loaded: Currently
900 * this always return `identity` to signifying that a record will be
901 * loaded by the `type` and `id`.
902 */
903 remoteType(): string;
904 /**
905 * This API allows you to provide a reference with new data. The
906 * simplest usage of this API is similar to `store.push`: you provide a
907 * normalized hash of data and the object represented by the reference
908 * will update.
909 */
910 push(payload: RSVP.Promise<any> | {}): PromiseObject<T>;
911 /**
912 * If the entity referred to by the reference is already loaded, it is
913 * present as `reference.value`. Otherwise the value returned by this function
914 * is `null`.
915 */
916 value(): T | null;
917 /**
918 * Triggers a fetch for the backing entity based on its `remoteType`
919 * (see `remoteType` definitions per reference type).
920 */
921 load(): PromiseObject<T>;
922 /**
923 * Reloads the record if it is already loaded. If the record is not
924 * loaded it will load the record via `store.findRecord`
925 */
926 reload(): PromiseObject<T>;
927 }
928 /**
929 * A `ManyArray` is a `MutableArray` that represents the contents of a has-many
930 * relationship.
931 */
932 // tslint:disable-next-line:no-empty-interface -- used for declaration merge
933 interface ManyArray<T> extends Ember.MutableArray<T>, Evented {}
934 class ManyArray<T> extends Ember.Object {
935 /**
936 * The loading state of this array
937 */
938 isLoaded: boolean;
939 /**
940 * Metadata associated with the request for async hasMany relationships.
941 */
942 meta: {};
943 /**
944 * Reloads all of the records in the manyArray. If the manyArray
945 * holds a relationship that was originally fetched using a links url
946 * Ember Data will revisit the original links url to repopulate the
947 * relationship.
948 */
949 reload(): PromiseArray<T>;
950 /**
951 * Saves all of the records in the `ManyArray`.
952 */
953 save(): PromiseArray<T>;
954 /**
955 * Create a child record within the owner
956 */
957 createRecord(inputProperties?: {}): T;
958 }
959 /**
960 * A `PromiseArray` is an object that acts like both an `Ember.Array`
961 * and a promise. When the promise is resolved the resulting value
962 * will be set to the `PromiseArray`'s `content` property. This makes
963 * it easy to create data bindings with the `PromiseArray` that will be
964 * updated when the promise resolves.
965 */
966 interface PromiseArray<T, ArrayType extends Ember.ArrayProxy<T>['content'] = Ember.Array<T>>
967 extends Ember.ArrayProxy<T>,
968 PromiseProxyMixin<ArrayType> {}
969 class PromiseArray<T> extends Ember.ArrayProxy<T> {}
970 /**
971 * A `PromiseObject` is an object that acts like both an `Ember.Object`
972 * and a promise. When the promise is resolved, then the resulting value
973 * will be set to the `PromiseObject`'s `content` property. This makes
974 * it easy to create data bindings with the `PromiseObject` that will
975 * be updated when the promise resolves.
976 */
977 interface PromiseObject<T extends object | null>
978 extends PromiseProxyMixin<T> {}
979 class PromiseObject<T> extends ObjectProxy<NonNullable<T>> {}
980 /**
981 * A PromiseManyArray is a PromiseArray that also proxies certain method calls
982 * to the underlying manyArray.
983 * Right now we proxy:
984 */
985 class PromiseManyArray<T extends Model> extends PromiseArray<T, Ember.ArrayProxy<T>> {
986 /**
987 * Reloads all of the records in the manyArray. If the manyArray
988 * holds a relationship that was originally fetched using a links url
989 * Ember Data will revisit the original links url to repopulate the
990 * relationship.
991 */
992 reload(): PromiseManyArray<T>;
993 /**
994 * Create a child record within the owner
995 */
996 createRecord(inputProperties?: {}): T;
997 }
998 class SnapshotRecordArray<K extends keyof ModelRegistry> {
999 /**
1000 * Number of records in the array
1001 */
1002 length: number;
1003 /**
1004 * Meta objects for the record array.
1005 */
1006 meta: {};
1007 /**
1008 * A hash of adapter options passed into the store method for this request.
1009 */
1010 adapterOptions: {};
1011 /**
1012 * The relationships to include for this request.
1013 */
1014 include: string | any[];
1015 /**
1016 * The type of the underlying records for the snapshots in the array, as a DS.Model
1017 */
1018 type: ModelRegistry[K];
1019 /**
1020 * Get snapshots of the underlying record array
1021 */
1022 snapshots(): Snapshot[];
1023 }
1024 class Snapshot<K extends keyof ModelRegistry = keyof ModelRegistry> {
1025 /**
1026 * The underlying record for this snapshot. Can be used to access methods and
1027 * properties defined on the record.
1028 */
1029 record: ModelRegistry[K];
1030 /**
1031 * The id of the snapshot's underlying record
1032 */
1033 id: string;
1034 /**
1035 * A hash of adapter options
1036 */
1037 adapterOptions: Record<string, unknown>;
1038 /**
1039 * The name of the type of the underlying record for this snapshot, as a string.
1040 */
1041 modelName: K;
1042 /**
1043 * The type of the underlying record for this snapshot, as a DS.Model.
1044 */
1045 type: ModelRegistry[K];
1046 /**
1047 * Returns the value of an attribute.
1048 */
1049 attr<L extends AttributesFor<ModelRegistry[K]>>(
1050 keyName: L
1051 ): ModelRegistry[K][L];
1052 /**
1053 * Returns all attributes and their corresponding values.
1054 */
1055 attributes(): { [L in keyof ModelRegistry[K]]: ModelRegistry[K][L] };
1056 /**
1057 * Returns all changed attributes and their old and new values.
1058 */
1059 changedAttributes(): Partial<
1060 { [L in keyof ModelRegistry[K]]: ModelRegistry[K][L] }
1061 >;
1062 /**
1063 * Returns the current value of a belongsTo relationship.
1064 */
1065 belongsTo<L extends RelationshipsFor<ModelRegistry[K]>>(
1066 keyName: L,
1067 options?: {}
1068 ): Snapshot | null | undefined;
1069 belongsTo<L extends RelationshipsFor<ModelRegistry[K]>>(
1070 keyName: L,
1071 options: { id: true }
1072 ): string | null | undefined;
1073
1074 /**
1075 * Returns the current value of a hasMany relationship.
1076 */
1077 hasMany<L extends RelationshipsFor<ModelRegistry[K]>>(
1078 keyName: L,
1079 options?: { ids: false }
1080 ): Snapshot[] | undefined;
1081 hasMany<L extends RelationshipsFor<ModelRegistry[K]>>(
1082 keyName: L,
1083 options: { ids: true }
1084 ): string[] | undefined;
1085 /**
1086 * Iterates through all the attributes of the model, calling the passed
1087 * function on each attribute.
1088 */
1089 eachAttribute<M extends ModelRegistry[K]>(
1090 callback: (key: ModelKeys<M>, meta: AttributeMeta<M>) => void,
1091 binding?: {}
1092 ): void;
1093 /**
1094 * Iterates through all the relationships of the model, calling the passed
1095 * function on each relationship.
1096 */
1097 eachRelationship<M extends ModelRegistry[K]>(
1098 callback: (key: ModelKeys<M>, meta: RelationshipMeta<M>) => void,
1099 binding?: {}
1100 ): void;
1101 /**
1102 * Serializes the snapshot using the serializer for the model.
1103 */
1104 serialize<O extends object>(options: O): object;
1105 }
1106
1107 /**
1108 * The store contains all of the data for records loaded from the server.
1109 * It is also responsible for creating instances of `DS.Model` that wrap
1110 * the individual data for a record, so that they can be bound to in your
1111 * Handlebars templates.
1112 */
1113 class Store extends Ember.Service {
1114 /**
1115 * The default adapter to use to communicate to a backend server or
1116 * other persistence layer. This will be overridden by an application
1117 * adapter if present.
1118 */
1119 adapter: string;
1120 /**
1121 * Create a new record in the current store. The properties passed
1122 * to this method are set on the newly created record.
1123 */
1124 createRecord<K extends keyof ModelRegistry>(
1125 modelName: K,
1126 inputProperties?: {}
1127 ): ModelRegistry[K];
1128 /**
1129 * For symmetry, a record can be deleted via the store.
1130 */
1131 deleteRecord(record: Model): void;
1132 /**
1133 * For symmetry, a record can be unloaded via the store.
1134 * This will cause the record to be destroyed and freed up for garbage collection.
1135 */
1136 unloadRecord(record: Model): void;
1137 /**
1138 * This method returns a record for a given type and id combination.
1139 */
1140 findRecord<K extends keyof ModelRegistry>(
1141 modelName: K,
1142 id: string | number,
1143 options?: {}
1144 ): PromiseObject<ModelRegistry[K]>;
1145 /**
1146 * Get the reference for the specified record.
1147 */
1148 getReference<K extends keyof ModelRegistry>(
1149 modelName: K,
1150 id: string | number
1151 ): RecordReference<ModelRegistry[K]>;
1152 /**
1153 * Get a record by a given type and ID without triggering a fetch.
1154 */
1155 peekRecord<K extends keyof ModelRegistry>(
1156 modelName: K,
1157 id: string | number
1158 ): ModelRegistry[K] | null;
1159 /**
1160 * This method returns true if a record for a given modelName and id is already
1161 * loaded in the store. Use this function to know beforehand if a findRecord()
1162 * will result in a request or that it will be a cache hit.
1163 */
1164 hasRecordForId<K extends keyof ModelRegistry>(
1165 modelName: K,
1166 id: string | number
1167 ): boolean;
1168 /**
1169 * This method delegates a query to the adapter. This is the one place where
1170 * adapter-level semantics are exposed to the application.
1171 */
1172 query<K extends keyof ModelRegistry>(
1173 modelName: K,
1174 query: object,
1175 options?: { adapterOptions?: object | undefined }
1176 ): PromiseArray<ModelRegistry[K], AdapterPopulatedRecordArray<ModelRegistry[K]>>;
1177 /**
1178 * This method makes a request for one record, where the `id` is not known
1179 * beforehand (if the `id` is known, use [`findRecord`](#method_findRecord)
1180 * instead).
1181 */
1182 queryRecord<K extends keyof ModelRegistry>(
1183 modelName: K,
1184 query: object,
1185 options?: { adapterOptions?: object | undefined }
1186 ): RSVP.Promise<ModelRegistry[K]>;
1187 /**
1188 * `findAll` asks the adapter's `findAll` method to find the records for the
1189 * given type, and returns a promise which will resolve with all records of
1190 * this type present in the store, even if the adapter only returns a subset
1191 * of them.
1192 */
1193 findAll<K extends keyof ModelRegistry>(
1194 modelName: K,
1195 options?: {
1196 reload?: boolean | undefined;
1197 backgroundReload?: boolean | undefined;
1198 include?: string | undefined;
1199 adapterOptions?: any;
1200 }
1201 ): PromiseArray<ModelRegistry[K], Ember.ArrayProxy<ModelRegistry[K]>>;
1202 /**
1203 * This method returns a filtered array that contains all of the
1204 * known records for a given type in the store.
1205 */
1206 peekAll<K extends keyof ModelRegistry>(
1207 modelName: K
1208 ): RecordArray<ModelRegistry[K]>;
1209 /**
1210 * This method unloads all records in the store.
1211 * It schedules unloading to happen during the next run loop.
1212 */
1213 unloadAll<K extends keyof ModelRegistry>(modelName?: K): void;
1214 /**
1215 * DEPRECATED:
1216 * This method has been deprecated and is an alias for store.hasRecordForId, which should
1217 * be used instead.
1218 */
1219 recordIsLoaded<K extends keyof ModelRegistry>(
1220 modelName: K,
1221 id: string
1222 ): boolean;
1223 /**
1224 * Returns the model class for the particular `modelName`.
1225 */
1226 modelFor<K extends keyof ModelRegistry>(modelName: K): ModelRegistry[K];
1227 /**
1228 * Push some data for a given type into the store.
1229 */
1230 push(data: {}): Model | any[];
1231 /**
1232 * Push some raw data into the store.
1233 */
1234 pushPayload<K extends keyof ModelRegistry>(
1235 modelName: K,
1236 inputPayload: {}
1237 ): any;
1238 pushPayload(inputPayload: {}): any;
1239 /**
1240 * `normalize` converts a json payload into the normalized form that
1241 * [push](#method_push) expects.
1242 */
1243 normalize<K extends keyof ModelRegistry>(modelName: K, payload: {}): {};
1244 /**
1245 * Returns an instance of the adapter for a given type. For
1246 * example, `adapterFor('person')` will return an instance of
1247 * `App.PersonAdapter`.
1248 */
1249 adapterFor<K extends keyof AdapterRegistry>(
1250 modelName: K
1251 ): AdapterRegistry[K];
1252 /**
1253 * Returns an instance of the serializer for a given type. For
1254 * example, `serializerFor('person')` will return an instance of
1255 * `App.PersonSerializer`.
1256 */
1257 serializerFor<K extends keyof SerializerRegistry>(
1258 modelName: K
1259 ): SerializerRegistry[K];
1260 }
1261 /**
1262 * The `JSONAPIAdapter` is the default adapter used by Ember Data. It
1263 * is responsible for transforming the store's requests into HTTP
1264 * requests that follow the [JSON API](http://jsonapi.org/format/)
1265 * format.
1266 */
1267 class JSONAPIAdapter extends RESTAdapter {}
1268 /**
1269 * The REST adapter allows your store to communicate with an HTTP server by
1270 * transmitting JSON via XHR. Most Ember.js apps that consume a JSON API
1271 * should use the REST adapter.
1272 */
1273 class RESTAdapter extends Adapter implements BuildURLMixin {
1274 /**
1275 * Takes a URL, an HTTP method and a hash of data, and makes an HTTP request.
1276 */
1277 ajax(url: string, type: string, options?: object): RSVP.Promise<any>;
1278 /**
1279 * Generate ajax options
1280 */
1281 ajaxOptions(url: string, type: string, options?: object): object;
1282 /**
1283 * By default, the RESTAdapter will send the query params sorted alphabetically to the
1284 * server.
1285 */
1286 sortQueryParams(obj: {}): {};
1287 /**
1288 * Called by the store in order to fetch the JSON for a given
1289 * type and ID.
1290 */
1291 findRecord<K extends keyof ModelRegistry>(
1292 store: Store,
1293 type: ModelSchema<K>,
1294 id: string,
1295 snapshot: Snapshot<K>
1296 ): RSVP.Promise<any>;
1297 /**
1298 * Called by the store in order to fetch a JSON array for all
1299 * of the records for a given type.
1300 */
1301 findAll<K extends keyof ModelRegistry>(
1302 store: Store,
1303 type: ModelSchema<K>,
1304 sinceToken: string,
1305 snapshotRecordArray: SnapshotRecordArray<K>
1306 ): RSVP.Promise<any>;
1307 /**
1308 * Called by the store in order to fetch a JSON array for
1309 * the records that match a particular query.
1310 */
1311 query<K extends keyof ModelRegistry>(
1312 store: Store,
1313 type: ModelSchema<K>,
1314 query: {}
1315 ): RSVP.Promise<any>;
1316 /**
1317 * Called by the store in order to fetch a JSON object for
1318 * the record that matches a particular query.
1319 */
1320 queryRecord<K extends keyof ModelRegistry>(
1321 store: Store,
1322 type: ModelSchema<K>,
1323 query: {}
1324 ): RSVP.Promise<any>;
1325 /**
1326 * Called by the store in order to fetch several records together if `coalesceFindRequests` is true
1327 */
1328 findMany<K extends keyof ModelRegistry>(
1329 store: Store,
1330 type: ModelSchema<K>,
1331 ids: any[],
1332 snapshots: any[]
1333 ): RSVP.Promise<any>;
1334 /**
1335 * Called by the store in order to fetch a JSON array for
1336 * the unloaded records in a has-many relationship that were originally
1337 * specified as a URL (inside of `links`).
1338 */
1339 findHasMany<K extends keyof ModelRegistry>(
1340 store: Store,
1341 snapshot: Snapshot<K>,
1342 url: string,
1343 relationship: {}
1344 ): RSVP.Promise<any>;
1345 /**
1346 * Called by the store in order to fetch the JSON for the unloaded record in a
1347 * belongs-to relationship that was originally specified as a URL (inside of
1348 * `links`).
1349 */
1350 findBelongsTo<K extends keyof ModelRegistry>(
1351 store: Store,
1352 snapshot: Snapshot<K>,
1353 url: string
1354 ): RSVP.Promise<any>;
1355 /**
1356 * Called by the store when a newly created record is
1357 * saved via the `save` method on a model record instance.
1358 */
1359 createRecord<K extends keyof ModelRegistry>(
1360 store: Store,
1361 type: ModelSchema<K>,
1362 snapshot: Snapshot<K>
1363 ): RSVP.Promise<any>;
1364 /**
1365 * Called by the store when an existing record is saved
1366 * via the `save` method on a model record instance.
1367 */
1368 updateRecord<K extends keyof ModelRegistry>(
1369 store: Store,
1370 type: ModelSchema<K>,
1371 snapshot: Snapshot<K>
1372 ): RSVP.Promise<any>;
1373 /**
1374 * Called by the store when a record is deleted.
1375 */
1376 deleteRecord<K extends keyof ModelRegistry>(
1377 store: Store,
1378 type: ModelSchema<K>,
1379 snapshot: Snapshot<K>
1380 ): RSVP.Promise<any>;
1381 /**
1382 * Organize records into groups, each of which is to be passed to separate
1383 * calls to `findMany`.
1384 */
1385 groupRecordsForFindMany(store: Store, snapshots: any[]): any[];
1386 /**
1387 * Takes an ajax response, and returns the json payload or an error.
1388 */
1389 handleResponse(
1390 status: number,
1391 headers: {},
1392 payload: {},
1393 requestData: {}
1394 ): {};
1395 /**
1396 * Default `handleResponse` implementation uses this hook to decide if the
1397 * response is a success.
1398 */
1399 isSuccess(status: number, headers: {}, payload: {}): boolean;
1400 /**
1401 * Default `handleResponse` implementation uses this hook to decide if the
1402 * response is an invalid error.
1403 */
1404 isInvalid(status: number, headers: {}, payload: {}): boolean;
1405 /**
1406 * Get the data (body or query params) for a request.
1407 */
1408 dataForRequest(params: {}): {};
1409 /**
1410 * Get the HTTP method for a request.
1411 */
1412 methodForRequest(params: {}): string;
1413 /**
1414 * Get the URL for a request.
1415 */
1416 urlForRequest(params: {}): string;
1417 /**
1418 * Get the headers for a request.
1419 */
1420 headersForRequest(params: {}): {};
1421 /**
1422 * Builds a URL for a given type and optional ID.
1423 */
1424 buildURL<K extends keyof ModelRegistry>(
1425 modelName?: K,
1426 id?: string | any[] | {} | null,
1427 snapshot?: Snapshot<K> | any[] | null,
1428 requestType?: string,
1429 query?: {}
1430 ): string;
1431 /**
1432 * Used by `findAll` and `findRecord` to build the query's `data` hash supplied to the ajax method.
1433 */
1434 buildQuery<K extends keyof ModelRegistry>(
1435 snapshot: Snapshot<K>
1436 ): Record<string, unknown>;
1437 /**
1438 * Builds a URL for a `store.findRecord(type, id)` call.
1439 */
1440 urlForFindRecord<K extends keyof ModelRegistry>(
1441 id: string,
1442 modelName: K,
1443 snapshot: Snapshot<K>
1444 ): string;
1445 /**
1446 * Builds a URL for a `store.findAll(type)` call.
1447 */
1448 urlForFindAll<K extends keyof ModelRegistry>(
1449 modelName: K,
1450 snapshot: SnapshotRecordArray<K>
1451 ): string;
1452 /**
1453 * Builds a URL for a `store.query(type, query)` call.
1454 */
1455 urlForQuery<K extends keyof ModelRegistry>(
1456 query: {},
1457 modelName: K
1458 ): string;
1459 /**
1460 * Builds a URL for a `store.queryRecord(type, query)` call.
1461 */
1462 urlForQueryRecord<K extends keyof ModelRegistry>(
1463 query: {},
1464 modelName: K
1465 ): string;
1466 /**
1467 * Builds a URL for coalesceing multiple `store.findRecord(type, id)`
1468 * records into 1 request when the adapter's `coalesceFindRequests`
1469 * property is true.
1470 */
1471 urlForFindMany<K extends keyof ModelRegistry>(
1472 ids: any[],
1473 modelName: K,
1474 snapshots: any[]
1475 ): string;
1476 /**
1477 * Builds a URL for fetching a async hasMany relationship when a url
1478 * is not provided by the server.
1479 */
1480 urlForFindHasMany<K extends keyof ModelRegistry>(
1481 id: string,
1482 modelName: K,
1483 snapshot: Snapshot<K>
1484 ): string;
1485 /**
1486 * Builds a URL for fetching a async belongsTo relationship when a url
1487 * is not provided by the server.
1488 */
1489 urlForFindBelongsTo<K extends keyof ModelRegistry>(
1490 id: string,
1491 modelName: K,
1492 snapshot: Snapshot<K>
1493 ): string;
1494 /**
1495 * Builds a URL for a `record.save()` call when the record was created
1496 * locally using `store.createRecord()`.
1497 */
1498 urlForCreateRecord<K extends keyof ModelRegistry>(
1499 modelName: K,
1500 snapshot: Snapshot<K>
1501 ): string;
1502 /**
1503 * Builds a URL for a `record.save()` call when the record has been update locally.
1504 */
1505 urlForUpdateRecord<K extends keyof ModelRegistry>(
1506 id: string,
1507 modelName: K,
1508 snapshot: Snapshot<K>
1509 ): string;
1510 /**
1511 * Builds a URL for a `record.save()` call when the record has been deleted locally.
1512 */
1513 urlForDeleteRecord<K extends keyof ModelRegistry>(
1514 id: string,
1515 modelName: K,
1516 snapshot: Snapshot<K>
1517 ): string;
1518 /**
1519 * Determines the pathname for a given type.
1520 */
1521 pathForType<K extends keyof ModelRegistry>(modelName: K): string;
1522 }
1523
1524 // Instead of declaring `namespace`, `host`, and `headers` as a property we now declare it in an
1525 // interface. This works around the issue noted here with TypeScript 4:
1526 // https://github.com/microsoft/TypeScript/issues/40220
1527 interface RESTAdapter {
1528 /**
1529 * Endpoint paths can be prefixed with a `namespace` by setting the namespace
1530 * property on the adapter:
1531 */
1532 namespace: string;
1533 /**
1534 * An adapter can target other hosts by setting the `host` property.
1535 */
1536 host: string;
1537 /**
1538 * Some APIs require HTTP headers, e.g. to provide an API
1539 * key. Arbitrary headers can be set as key/value pairs on the
1540 * `RESTAdapter`'s `headers` object and Ember Data will send them
1541 * along with each ajax request. For dynamic headers see [headers
1542 * customization](/api/data/classes/DS.RESTAdapter.html#toc_headers-customization).
1543 */
1544 headers: {};
1545 }
1546 /**
1547 * ## Using Embedded Records
1548 */
1549 class EmbeddedRecordsMixin {
1550 /**
1551 * Normalize the record and recursively normalize/extract all the embedded records
1552 * while pushing them into the store as they are encountered
1553 */
1554 normalize(typeClass: ModelSchema, hash: {}, prop: string): {};
1555 /**
1556 * Serialize `belongsTo` relationship when it is configured as an embedded object.
1557 */
1558 serializeBelongsTo<K extends keyof ModelRegistry>(
1559 snapshot: Snapshot<K>,
1560 json: {},
1561 relationship: {}
1562 ): any;
1563 /**
1564 * Serializes `hasMany` relationships when it is configured as embedded objects.
1565 */
1566 serializeHasMany<K extends keyof ModelRegistry>(
1567 snapshot: Snapshot<K>,
1568 json: {},
1569 relationship: {}
1570 ): any;
1571 /**
1572 * When serializing an embedded record, modify the property (in the json payload)
1573 * that refers to the parent record (foreign key for relationship).
1574 */
1575 removeEmbeddedForeignKey<K extends keyof ModelRegistry>(
1576 snapshot: Snapshot<K>,
1577 embeddedSnapshot: Snapshot<K>,
1578 relationship: {},
1579 json: {}
1580 ): any;
1581 }
1582 /**
1583 * Ember Data 2.0 Serializer:
1584 */
1585 class JSONAPISerializer extends JSONSerializer {
1586 pushPayload(store: Store, payload: {}): any;
1587 /**
1588 * Dasherizes and singularizes the model name in the payload to match
1589 * the format Ember Data uses internally for the model name.
1590 */
1591 modelNameFromPayloadKey(key: string): string;
1592 /**
1593 * Converts the model name to a pluralized version of the model name.
1594 */
1595 payloadKeyFromModelName<K extends keyof ModelRegistry>(
1596 modelName: K
1597 ): string;
1598 /**
1599 * `keyForAttribute` can be used to define rules for how to convert an
1600 * attribute name in your model to a key in your JSON.
1601 * By default `JSONAPISerializer` follows the format used on the examples of
1602 * http://jsonapi.org/format and uses dashes as the word separator in the JSON
1603 * attribute keys.
1604 */
1605 keyForAttribute(key: string, method: string): string;
1606 /**
1607 * `keyForRelationship` can be used to define a custom key when
1608 * serializing and deserializing relationship properties.
1609 * By default `JSONAPISerializer` follows the format used on the examples of
1610 * http://jsonapi.org/format and uses dashes as word separators in
1611 * relationship properties.
1612 */
1613 keyForRelationship(
1614 key: string,
1615 typeClass: string,
1616 method: string
1617 ): string;
1618 /**
1619 * `modelNameFromPayloadType` can be used to change the mapping for a DS model
1620 * name, taken from the value in the payload.
1621 */
1622 modelNameFromPayloadType(payloadType: string): string;
1623 /**
1624 * `payloadTypeFromModelName` can be used to change the mapping for the type in
1625 * the payload, taken from the model name.
1626 */
1627 payloadTypeFromModelName<K extends keyof ModelRegistry>(
1628 modelName: K
1629 ): string;
1630 }
1631 /**
1632 * Ember Data 2.0 Serializer:
1633 */
1634 class JSONSerializer extends Serializer {
1635 /**
1636 * The `primaryKey` is used when serializing and deserializing
1637 * data. Ember Data always uses the `id` property to store the id of
1638 * the record. The external source may not always follow this
1639 * convention. In these cases it is useful to override the
1640 * `primaryKey` property to match the `primaryKey` of your external
1641 * store.
1642 */
1643 primaryKey: string;
1644 /**
1645 * The `attrs` object can be used to declare a simple mapping between
1646 * property names on `DS.Model` records and payload keys in the
1647 * serialized JSON object representing the record. An object with the
1648 * property `key` can also be used to designate the attribute's key on
1649 * the response payload.
1650 */
1651 attrs: {};
1652 /**
1653 * The `normalizeResponse` method is used to normalize a payload from the
1654 * server to a JSON-API Document.
1655 */
1656 normalizeResponse(
1657 store: Store,
1658 primaryModelClass: ModelSchema,
1659 payload: {},
1660 id: string | number,
1661 requestType: string
1662 ): {};
1663 normalizeFindRecordResponse(
1664 store: Store,
1665 primaryModelClass: ModelSchema,
1666 payload: {},
1667 id: string | number,
1668 requestType: string
1669 ): {};
1670 normalizeQueryRecordResponse(
1671 store: Store,
1672 primaryModelClass: ModelSchema,
1673 payload: {},
1674 id: string | number,
1675 requestType: string
1676 ): {};
1677 normalizeFindAllResponse(
1678 store: Store,
1679 primaryModelClass: ModelSchema,
1680 payload: {},
1681 id: string | number,
1682 requestType: string
1683 ): {};
1684 normalizeFindBelongsToResponse(
1685 store: Store,
1686 primaryModelClass: ModelSchema,
1687 payload: {},
1688 id: string | number,
1689 requestType: string
1690 ): {};
1691 normalizeFindHasManyResponse(
1692 store: Store,
1693 primaryModelClass: ModelSchema,
1694 payload: {},
1695 id: string | number,
1696 requestType: string
1697 ): {};
1698 normalizeFindManyResponse(
1699 store: Store,
1700 primaryModelClass: ModelSchema,
1701 payload: {},
1702 id: string | number,
1703 requestType: string
1704 ): {};
1705 normalizeQueryResponse(
1706 store: Store,
1707 primaryModelClass: ModelSchema,
1708 payload: {},
1709 id: string | number,
1710 requestType: string
1711 ): {};
1712 normalizeCreateRecordResponse(
1713 store: Store,
1714 primaryModelClass: ModelSchema,
1715 payload: {},
1716 id: string | number,
1717 requestType: string
1718 ): {};
1719 normalizeDeleteRecordResponse(
1720 store: Store,
1721 primaryModelClass: ModelSchema,
1722 payload: {},
1723 id: string | number,
1724 requestType: string
1725 ): {};
1726 normalizeUpdateRecordResponse(
1727 store: Store,
1728 primaryModelClass: ModelSchema,
1729 payload: {},
1730 id: string | number,
1731 requestType: string
1732 ): {};
1733 normalizeSaveResponse(
1734 store: Store,
1735 primaryModelClass: ModelSchema,
1736 payload: {},
1737 id: string | number,
1738 requestType: string
1739 ): {};
1740 normalizeSingleResponse(
1741 store: Store,
1742 primaryModelClass: ModelSchema,
1743 payload: {},
1744 id: string | number,
1745 requestType: string
1746 ): {};
1747 normalizeArrayResponse(
1748 store: Store,
1749 primaryModelClass: ModelSchema,
1750 payload: {},
1751 id: string | number,
1752 requestType: string
1753 ): {};
1754 /**
1755 * Normalizes a part of the JSON payload returned by
1756 * the server. You should override this method, munge the hash
1757 * and call super if you have generic normalization to do.
1758 */
1759 normalize(typeClass: ModelSchema, hash: {}): {};
1760 /**
1761 * Returns the resource's ID.
1762 */
1763 extractId(modelClass: {}, resourceHash: {}): string;
1764 /**
1765 * Returns the resource's attributes formatted as a JSON-API "attributes object".
1766 */
1767 extractAttributes(modelClass: ModelSchema, resourceHash: {}): {};
1768 /**
1769 * Returns a relationship formatted as a JSON-API "relationship object".
1770 */
1771 extractRelationship(
1772 relationshipModelName: {},
1773 relationshipHash: {}
1774 ): {};
1775 /**
1776 * Returns a polymorphic relationship formatted as a JSON-API "relationship object".
1777 */
1778 extractPolymorphicRelationship(
1779 relationshipModelName: {},
1780 relationshipHash: {},
1781 relationshipOptions: {}
1782 ): {};
1783 /**
1784 * Returns the resource's relationships formatted as a JSON-API "relationships object".
1785 */
1786 extractRelationships(modelClass: ModelSchema, resourceHash: {}): {};
1787 modelNameFromPayloadKey(key: string): string;
1788 /**
1789 * Check if the given hasMany relationship should be serialized
1790 */
1791 shouldSerializeHasMany<K extends keyof ModelRegistry>(
1792 snapshot: Snapshot<K>,
1793 key: string,
1794 relationshipType: string
1795 ): boolean;
1796 /**
1797 * Called when a record is saved in order to convert the
1798 * record into JSON.
1799 */
1800 serialize<K extends keyof ModelRegistry>(
1801 snapshot: Snapshot<K>,
1802 options: {}
1803 ): {};
1804 /**
1805 * You can use this method to customize how a serialized record is added to the complete
1806 * JSON hash to be sent to the server. By default the JSON Serializer does not namespace
1807 * the payload and just sends the raw serialized JSON object.
1808 * If your server expects namespaced keys, you should consider using the RESTSerializer.
1809 * Otherwise you can override this method to customize how the record is added to the hash.
1810 * The hash property should be modified by reference.
1811 */
1812 serializeIntoHash<K extends keyof ModelRegistry>(
1813 hash: {},
1814 typeClass: ModelSchema<K>,
1815 snapshot: Snapshot<K>,
1816 options?: {}
1817 ): any;
1818 /**
1819 * `serializeAttribute` can be used to customize how `DS.attr`
1820 * properties are serialized
1821 */
1822 serializeAttribute<K extends keyof ModelRegistry>(
1823 snapshot: Snapshot<K>,
1824 json: {},
1825 key: string,
1826 attribute: {}
1827 ): any;
1828 /**
1829 * `serializeBelongsTo` can be used to customize how `DS.belongsTo`
1830 * properties are serialized.
1831 */
1832 serializeBelongsTo<K extends keyof ModelRegistry>(
1833 snapshot: Snapshot<K>,
1834 json: {},
1835 relationship: {}
1836 ): any;
1837 /**
1838 * `serializeHasMany` can be used to customize how `DS.hasMany`
1839 * properties are serialized.
1840 */
1841 serializeHasMany<K extends keyof ModelRegistry>(
1842 snapshot: Snapshot<K>,
1843 json: {},
1844 relationship: {}
1845 ): any;
1846 /**
1847 * You can use this method to customize how polymorphic objects are
1848 * serialized. Objects are considered to be polymorphic if
1849 * `{ polymorphic: true }` is pass as the second argument to the
1850 * `DS.belongsTo` function.
1851 */
1852 serializePolymorphicType<K extends keyof ModelRegistry>(
1853 snapshot: Snapshot<K>,
1854 json: {},
1855 relationship: {}
1856 ): any;
1857 /**
1858 * `extractMeta` is used to deserialize any meta information in the
1859 * adapter payload. By default Ember Data expects meta information to
1860 * be located on the `meta` property of the payload object.
1861 */
1862 extractMeta(store: Store, modelClass: ModelSchema, payload: {}): any;
1863 /**
1864 * `extractErrors` is used to extract model errors when a call
1865 * to `DS.Model#save` fails with an `InvalidError`. By default
1866 * Ember Data expects error information to be located on the `errors`
1867 * property of the payload object.
1868 */
1869 extractErrors(
1870 store: Store,
1871 typeClass: ModelSchema,
1872 payload: {},
1873 id: string | number
1874 ): {};
1875 /**
1876 * `keyForAttribute` can be used to define rules for how to convert an
1877 * attribute name in your model to a key in your JSON.
1878 */
1879 keyForAttribute(key: string, method: string): string;
1880 /**
1881 * `keyForRelationship` can be used to define a custom key when
1882 * serializing and deserializing relationship properties. By default
1883 * `JSONSerializer` does not provide an implementation of this method.
1884 */
1885 keyForRelationship(
1886 key: string,
1887 typeClass: string,
1888 method: string
1889 ): string;
1890 /**
1891 * `keyForLink` can be used to define a custom key when deserializing link
1892 * properties.
1893 */
1894 keyForLink(key: string, kind: string): string;
1895 modelNameFromPayloadType(type: string): string;
1896 /**
1897 * serializeId can be used to customize how id is serialized
1898 * For example, your server may expect integer datatype of id
1899 */
1900 serializeId<K extends keyof ModelRegistry>(
1901 snapshot: Snapshot<K>,
1902 json: {},
1903 primaryKey: string
1904 ): any;
1905 }
1906 /**
1907 * Normally, applications will use the `RESTSerializer` by implementing
1908 * the `normalize` method.
1909 */
1910 class RESTSerializer extends JSONSerializer {
1911 /**
1912 * `keyForPolymorphicType` can be used to define a custom key when
1913 * serializing and deserializing a polymorphic type. By default, the
1914 * returned key is `${key}Type`.
1915 */
1916 keyForPolymorphicType(
1917 key: string,
1918 typeClass: string,
1919 method: string
1920 ): string;
1921 /**
1922 * Normalizes a part of the JSON payload returned by
1923 * the server. You should override this method, munge the hash
1924 * and call super if you have generic normalization to do.
1925 */
1926 normalize(modelClass: ModelSchema, resourceHash: {}, prop?: string): {};
1927 /**
1928 * This method allows you to push a payload containing top-level
1929 * collections of records organized per type.
1930 */
1931 pushPayload(store: Store, payload: {}): any;
1932 /**
1933 * This method is used to convert each JSON root key in the payload
1934 * into a modelName that it can use to look up the appropriate model for
1935 * that part of the payload.
1936 */
1937 modelNameFromPayloadKey(key: string): string;
1938 /**
1939 * Called when a record is saved in order to convert the
1940 * record into JSON.
1941 */
1942 serialize<K extends keyof ModelRegistry>(
1943 snapshot: Snapshot<K>,
1944 options: {}
1945 ): {};
1946 /**
1947 * You can use this method to customize the root keys serialized into the JSON.
1948 * The hash property should be modified by reference (possibly using something like _.extend)
1949 * By default the REST Serializer sends the modelName of a model, which is a camelized
1950 * version of the name.
1951 */
1952 serializeIntoHash<K extends keyof ModelRegistry>(
1953 hash: {},
1954 typeClass: ModelSchema<K>,
1955 snapshot: Snapshot<K>,
1956 options?: {}
1957 ): any;
1958 /**
1959 * You can use `payloadKeyFromModelName` to override the root key for an outgoing
1960 * request. By default, the RESTSerializer returns a camelized version of the
1961 * model's name.
1962 */
1963 payloadKeyFromModelName<K extends keyof ModelRegistry>(
1964 modelName: K
1965 ): string;
1966 /**
1967 * You can use this method to customize how polymorphic objects are serialized.
1968 * By default the REST Serializer creates the key by appending `Type` to
1969 * the attribute and value from the model's camelcased model name.
1970 */
1971 serializePolymorphicType<K extends keyof ModelRegistry>(
1972 snapshot: Snapshot<K>,
1973 json: {},
1974 relationship: {}
1975 ): any;
1976 /**
1977 * You can use this method to customize how a polymorphic relationship should
1978 * be extracted.
1979 */
1980 extractPolymorphicRelationship(
1981 relationshipType: {},
1982 relationshipHash: {},
1983 relationshipOptions: {}
1984 ): {};
1985 /**
1986 * `modelNameFromPayloadType` can be used to change the mapping for a DS model
1987 * name, taken from the value in the payload.
1988 */
1989 modelNameFromPayloadType(payloadType: string): string;
1990 /**
1991 * `payloadTypeFromModelName` can be used to change the mapping for the type in
1992 * the payload, taken from the model name.
1993 */
1994 payloadTypeFromModelName<K extends keyof ModelRegistry>(
1995 modelName: K
1996 ): string;
1997 }
1998 /**
1999 * The `DS.BooleanTransform` class is used to serialize and deserialize
2000 * boolean attributes on Ember Data record objects. This transform is
2001 * used when `boolean` is passed as the type parameter to the
2002 * [DS.attr](../../data#method_attr) function.
2003 */
2004 class BooleanTransform extends Transform<boolean> {}
2005 /**
2006 * The `DS.DateTransform` class is used to serialize and deserialize
2007 * date attributes on Ember Data record objects. This transform is used
2008 * when `date` is passed as the type parameter to the
2009 * [DS.attr](../../data#method_attr) function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601)
2010 * standard.
2011 */
2012 class DateTransform extends Transform<Date> {}
2013 /**
2014 * The `DS.NumberTransform` class is used to serialize and deserialize
2015 * numeric attributes on Ember Data record objects. This transform is
2016 * used when `number` is passed as the type parameter to the
2017 * [DS.attr](../../data#method_attr) function.
2018 */
2019 class NumberTransform extends Transform<number> {}
2020 /**
2021 * The `DS.StringTransform` class is used to serialize and deserialize
2022 * string attributes on Ember Data record objects. This transform is
2023 * used when `string` is passed as the type parameter to the
2024 * [DS.attr](../../data#method_attr) function.
2025 */
2026 class StringTransform extends Transform<string> {}
2027 /**
2028 * The `DS.Transform` class is used to serialize and deserialize model
2029 * attributes when they are saved or loaded from an
2030 * adapter. Subclassing `DS.Transform` is useful for creating custom
2031 * attributes. All subclasses of `DS.Transform` must implement a
2032 * `serialize` and a `deserialize` method.
2033 */
2034 class Transform<Deserialized = any, Serialized = any> extends Ember.Object {
2035 /**
2036 * When given a deserialized value from a record attribute this
2037 * method must return the serialized value.
2038 */
2039 serialize(deserialized: Deserialized, options: AttrOptions<Deserialized>): Serialized;
2040 /**
2041 * When given a serialize value from a JSON object this method must
2042 * return the deserialized value for the record attribute.
2043 */
2044 deserialize(serialized: Serialized, options: AttrOptions<Deserialized>): Deserialized;
2045 }
2046 /**
2047 * An adapter is an object that receives requests from a store and
2048 * translates them into the appropriate action to take against your
2049 * persistence layer. The persistence layer is usually an HTTP API, but
2050 * may be anything, such as the browser's local storage. Typically the
2051 * adapter is not invoked directly instead its functionality is accessed
2052 * through the `store`.
2053 */
2054 class Adapter extends Ember.Object {
2055 /**
2056 * If you would like your adapter to use a custom serializer you can
2057 * set the `defaultSerializer` property to be the name of the custom
2058 * serializer.
2059 */
2060 defaultSerializer: string;
2061 /**
2062 * The `findRecord()` method is invoked when the store is asked for a record that
2063 * has not previously been loaded. In response to `findRecord()` being called, you
2064 * should query your persistence layer for a record with the given ID. The `findRecord`
2065 * method should return a promise that will resolve to a JavaScript object that will be
2066 * normalized by the serializer.
2067 */
2068 findRecord<K extends keyof ModelRegistry>(
2069 store: Store,
2070 type: ModelSchema<K>,
2071 id: string,
2072 snapshot: Snapshot<K>
2073 ): RSVP.Promise<any>;
2074 /**
2075 * The `findAll()` method is used to retrieve all records for a given type.
2076 */
2077 findAll<K extends keyof ModelRegistry>(
2078 store: Store,
2079 type: ModelSchema<K>,
2080 sinceToken: string,
2081 snapshotRecordArray: SnapshotRecordArray<K>
2082 ): RSVP.Promise<any>;
2083 /**
2084 * This method is called when you call `query` on the store.
2085 */
2086 query<K extends keyof ModelRegistry>(
2087 store: Store,
2088 type: ModelSchema<K>,
2089 query: {},
2090 recordArray: AdapterPopulatedRecordArray<any>
2091 ): RSVP.Promise<any>;
2092 /**
2093 * The `queryRecord()` method is invoked when the store is asked for a single
2094 * record through a query object.
2095 */
2096 queryRecord<K extends keyof ModelRegistry>(
2097 store: Store,
2098 type: ModelSchema<K>,
2099 query: {}
2100 ): RSVP.Promise<any>;
2101 /**
2102 * If the globally unique IDs for your records should be generated on the client,
2103 * implement the `generateIdForRecord()` method. This method will be invoked
2104 * each time you create a new record, and the value returned from it will be
2105 * assigned to the record's `primaryKey`.
2106 */
2107 generateIdForRecord<K extends keyof ModelRegistry>(
2108 store: Store,
2109 type: ModelSchema<K>,
2110 inputProperties: {}
2111 ): string | number;
2112 /**
2113 * Proxies to the serializer's `serialize` method.
2114 */
2115 serialize<K extends keyof ModelRegistry>(
2116 snapshot: Snapshot<K>,
2117 options: {}
2118 ): {};
2119 /**
2120 * Implement this method in a subclass to handle the creation of
2121 * new records.
2122 */
2123 createRecord<K extends keyof ModelRegistry>(
2124 store: Store,
2125 type: ModelSchema<K>,
2126 snapshot: Snapshot<K>
2127 ): RSVP.Promise<any>;
2128 /**
2129 * Implement this method in a subclass to handle the updating of
2130 * a record.
2131 */
2132 updateRecord<K extends keyof ModelRegistry>(
2133 store: Store,
2134 type: ModelSchema<K>,
2135 snapshot: Snapshot<K>
2136 ): RSVP.Promise<any>;
2137 /**
2138 * Implement this method in a subclass to handle the deletion of
2139 * a record.
2140 */
2141 deleteRecord<K extends keyof ModelRegistry>(
2142 store: Store,
2143 type: ModelSchema<K>,
2144 snapshot: Snapshot<K>
2145 ): RSVP.Promise<any>;
2146 /**
2147 * The store will call `findMany` instead of multiple `findRecord`
2148 * requests to find multiple records at once if coalesceFindRequests
2149 * is true.
2150 */
2151 findMany<K extends keyof ModelRegistry>(
2152 store: Store,
2153 type: ModelSchema<K>,
2154 ids: any[],
2155 snapshots: any[]
2156 ): RSVP.Promise<any>;
2157 /**
2158 * Organize records into groups, each of which is to be passed to separate
2159 * calls to `findMany`.
2160 */
2161 groupRecordsForFindMany(store: Store, snapshots: any[]): any[];
2162 /**
2163 * This method is used by the store to determine if the store should
2164 * reload a record from the adapter when a record is requested by
2165 * `store.findRecord`.
2166 */
2167 shouldReloadRecord<K extends keyof ModelRegistry>(
2168 store: Store,
2169 snapshot: Snapshot<K>
2170 ): boolean;
2171 /**
2172 * This method is used by the store to determine if the store should
2173 * reload all records from the adapter when records are requested by
2174 * `store.findAll`.
2175 */
2176 shouldReloadAll<K extends keyof ModelRegistry>(
2177 store: Store,
2178 snapshotRecordArray: SnapshotRecordArray<K>
2179 ): boolean;
2180 /**
2181 * This method is used by the store to determine if the store should
2182 * reload a record after the `store.findRecord` method resolves a
2183 * cached record.
2184 */
2185 shouldBackgroundReloadRecord<K extends keyof ModelRegistry>(
2186 store: Store,
2187 snapshot: Snapshot<K>
2188 ): boolean;
2189 /**
2190 * This method is used by the store to determine if the store should
2191 * reload a record array after the `store.findAll` method resolves
2192 * with a cached record array.
2193 */
2194 shouldBackgroundReloadAll<K extends keyof ModelRegistry>(
2195 store: Store,
2196 snapshotRecordArray: SnapshotRecordArray<K>
2197 ): boolean;
2198 }
2199 // Instead of declaring `coalesceFindRequests` as a property we now declare it in an
2200 // interface. This works around the issue noted here with TypeScript 4:
2201 // https://github.com/microsoft/TypeScript/issues/40220
2202 interface Adapter {
2203 /**
2204 * By default the store will try to coalesce all `fetchRecord` calls within the same runloop
2205 * into as few requests as possible by calling groupRecordsForFindMany and passing it into a findMany call.
2206 * You can opt out of this behaviour by either not implementing the findMany hook or by setting
2207 * coalesceFindRequests to false.
2208 */
2209 coalesceFindRequests: boolean;
2210 }
2211 /**
2212 * `DS.Serializer` is an abstract base class that you should override in your
2213 * application to customize it for your backend. The minimum set of methods
2214 * that you should implement is:
2215 */
2216 class Serializer extends Ember.Object {
2217 /**
2218 * The `store` property is the application's `store` that contains
2219 * all records. It can be used to look up serializers for other model
2220 * types that may be nested inside the payload response.
2221 */
2222 store: Store;
2223 /**
2224 * The `normalizeResponse` method is used to normalize a payload from the
2225 * server to a JSON-API Document.
2226 */
2227 normalizeResponse(
2228 store: Store,
2229 primaryModelClass: ModelSchema,
2230 payload: {},
2231 id: string | number,
2232 requestType: string
2233 ): {};
2234 /**
2235 * The `serialize` method is used when a record is saved in order to convert
2236 * the record into the form that your external data source expects.
2237 */
2238 serialize<K extends keyof ModelRegistry>(
2239 snapshot: Snapshot<K>,
2240 options: {}
2241 ): {};
2242 /**
2243 * The `normalize` method is used to convert a payload received from your
2244 * external data source into the normalized form `store.push()` expects. You
2245 * should override this method, munge the hash and return the normalized
2246 * payload.
2247 */
2248 normalize(typeClass: ModelSchema, hash: {}): {};
2249 }
2250}
2251
2252export default DS;
2253
2254declare module '@ember/service' {
2255 interface Registry {
2256 store: DS.Store;
2257 }
2258}
2259
2260declare module 'ember-test-helpers' {
2261 interface TestContext {
2262 store: DS.Store;
2263 }
2264}
2265
\No newline at end of file