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