forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.d.ts
80 lines (68 loc) · 3.19 KB
/
model.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import type EmberObject from '@ember/object';
import type { Errors } from '@ember-data/model/-private';
import type Store from '@ember-data/store';
import type { AttributeSchema, RelationshipSchema, RelationshipsSchema } from '@ember-data/types/q/record-data-schemas';
import type { JsonApiError } from '@ember-data/types/q/record-data-json-api';
import type HasManyReference from './references/has-many';
import type BelongsToReference from './references/belongs-to';
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
import type { LegacySupport } from './legacy-relationships-support';
import type { Cache } from '@ember-data/types/q/cache';
import type RecordState from './record-state';
export type ModelCreateArgs = {
_createProps: Record<string, unknown>;
// TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
_secretInit: {
identifier: StableRecordIdentifier;
cache: Cache;
store: Store;
cb: (record: Model, cache: Cache, identifier: StableRecordIdentifier, store: Store) => void;
};
};
class Model extends EmberObject {
store: Store;
errors: Errors;
currentState: RecordState;
adapterError?: Error;
toString(): string;
save(): Promise<this>;
hasMany(key: string): HasManyReference;
belongsTo(key: string): BelongsToReference
eachRelationship<T>(callback: (this: T, key: string, meta: RelationshipSchema) => void, binding?: T): void;
eachAttribute<T>(callback: (this: T, key: string, meta: AttributeSchema) => void, binding?: T): void;
invalidErrorsChanged(errors: JsonApiError[]): void;
rollbackAttributes(): void;
changedAttributes(): Record<string, [unknown, unknown]>;
[key: string]: unknown;
isDeleted: boolean;
deleteRecord(): void;
unloadRecord(): void;
serialize(): Record<string, unknown>;
_notifyProperties(keys: string[]): void;
static modelName: string;
static fields: Map<string, 'attribute' | 'belongsTo' | 'hasMany'>;
static attributes: Map<string, AttributeSchema>;
static relationshipsByName: Map<string, RelationshipSchema>;
static eachAttribute<T>(callback: (this: T, key: string, attribute: AttributeSchema) => void, binding?: T): void;
static eachRelationship<T>(callback: (this: T, key: string, relationship: RelationshipSchema) => void, binding?: T): void;
static eachTransformedAttribute<T>(callback: (this: T, key: string, type?: string) => void, binding?: T): void;
static toString(): string;
static isModel: true;
static relationshipsObject: RelationshipsSchema;
static extend(...mixins: unknown[]): typeof Model;
static reopenClass(...mixins: unknown[]): void;
static create(createArgs: ModelCreateArgs): Model;
static __isMixin?: true;
static __mixin?: unknown;
}
interface Model {
constructor: typeof Model;
}
export default Model;
export type StaticModel = typeof Model;
export const LEGACY_SUPPORT: Map<StableRecordIdentifier | Model, LegacySupport>;
export type ModelFactory = { class: StaticModel };
export type FactoryCache = Record<string, ModelFactory>;
// we put this on the store for interop because it's used by modelFor and
// instantiateRecord as well.
export type ModelStore = Store & { _modelFactoryCache: FactoryCache };