@ember-data-types/store 5.4.0-alpha.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +11 -0
- package/README.md +193 -0
- package/ember-data-logo-dark.svg +12 -0
- package/ember-data-logo-light.svg +12 -0
- package/package.json +20 -0
- package/unstable-preview-types/-private/cache-handler.d.ts +100 -0
- package/unstable-preview-types/-private/cache-handler.d.ts.map +1 -0
- package/unstable-preview-types/-private/caches/cache-utils.d.ts +11 -0
- package/unstable-preview-types/-private/caches/cache-utils.d.ts.map +1 -0
- package/unstable-preview-types/-private/caches/identifier-cache.d.ts +182 -0
- package/unstable-preview-types/-private/caches/identifier-cache.d.ts.map +1 -0
- package/unstable-preview-types/-private/caches/instance-cache.d.ts +63 -0
- package/unstable-preview-types/-private/caches/instance-cache.d.ts.map +1 -0
- package/unstable-preview-types/-private/caches/resource-utils.d.ts +12 -0
- package/unstable-preview-types/-private/caches/resource-utils.d.ts.map +1 -0
- package/unstable-preview-types/-private/document.d.ts +146 -0
- package/unstable-preview-types/-private/document.d.ts.map +1 -0
- package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts +179 -0
- package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts.map +1 -0
- package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts +19 -0
- package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts.map +1 -0
- package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +29 -0
- package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts.map +1 -0
- package/unstable-preview-types/-private/managers/cache-manager.d.ts +442 -0
- package/unstable-preview-types/-private/managers/cache-manager.d.ts.map +1 -0
- package/unstable-preview-types/-private/managers/notification-manager.d.ts +98 -0
- package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -0
- package/unstable-preview-types/-private/managers/record-array-manager.d.ts +97 -0
- package/unstable-preview-types/-private/managers/record-array-manager.d.ts.map +1 -0
- package/unstable-preview-types/-private/network/request-cache.d.ts +109 -0
- package/unstable-preview-types/-private/network/request-cache.d.ts.map +1 -0
- package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +133 -0
- package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -0
- package/unstable-preview-types/-private/record-arrays/native-proxy-type-fix.d.ts +118 -0
- package/unstable-preview-types/-private/record-arrays/native-proxy-type-fix.d.ts.map +1 -0
- package/unstable-preview-types/-private/store-service.d.ts +1554 -0
- package/unstable-preview-types/-private/store-service.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils/coerce-id.d.ts +10 -0
- package/unstable-preview-types/-private/utils/coerce-id.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils/construct-resource.d.ts +10 -0
- package/unstable-preview-types/-private/utils/construct-resource.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts +7 -0
- package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts +4 -0
- package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils/normalize-model-name.d.ts +4 -0
- package/unstable-preview-types/-private/utils/normalize-model-name.d.ts.map +1 -0
- package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts +4 -0
- package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts.map +1 -0
- package/unstable-preview-types/-private.d.ts +20 -0
- package/unstable-preview-types/-private.d.ts.map +1 -0
- package/unstable-preview-types/-types/overview.d.ts +21 -0
- package/unstable-preview-types/-types/overview.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts +107 -0
- package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/cache.d.ts +47 -0
- package/unstable-preview-types/-types/q/cache.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/ds-model.d.ts +15 -0
- package/unstable-preview-types/-types/q/ds-model.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/identifier.d.ts +171 -0
- package/unstable-preview-types/-types/q/identifier.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/promise-proxies.d.ts +4 -0
- package/unstable-preview-types/-types/q/promise-proxies.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/record-data-json-api.d.ts +36 -0
- package/unstable-preview-types/-types/q/record-data-json-api.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/record-instance.d.ts +29 -0
- package/unstable-preview-types/-types/q/record-instance.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/schema-service.d.ts +214 -0
- package/unstable-preview-types/-types/q/schema-service.d.ts.map +1 -0
- package/unstable-preview-types/-types/q/store.d.ts +17 -0
- package/unstable-preview-types/-types/q/store.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +220 -0
- package/unstable-preview-types/index.d.ts.map +1 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
declare module '@ember-data/store/-types/q/schema-service' {
|
|
2
|
+
/**
|
|
3
|
+
@module @ember-data/store
|
|
4
|
+
*/
|
|
5
|
+
import type { RecordIdentifier } from '@warp-drive/core-types/identifier';
|
|
6
|
+
import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema';
|
|
7
|
+
export interface FieldSchema {
|
|
8
|
+
type: string | null;
|
|
9
|
+
name: string;
|
|
10
|
+
kind: 'attribute' | 'hasMany' | 'belongsTo' | 'field' | 'resource' | 'collection' | 'derived' | 'object' | 'array' | '@id' | '@local';
|
|
11
|
+
options?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The SchemaService provides the ability to query for information about the structure
|
|
15
|
+
* of any resource type.
|
|
16
|
+
*
|
|
17
|
+
* Applications can provide any implementation of the SchemaService they please so long
|
|
18
|
+
* as it conforms to this interface.
|
|
19
|
+
*
|
|
20
|
+
* The design of the service means that schema information could be lazily populated,
|
|
21
|
+
* derived-on-demand, or progressively enhanced during the course of an application's runtime.
|
|
22
|
+
* The primary requirement is merely that any information the service needs to correctly
|
|
23
|
+
* respond to an inquest is available by the time it is asked.
|
|
24
|
+
*
|
|
25
|
+
* The `@ember-data/model` package provides an implementation of this service which
|
|
26
|
+
* makes use of your model classes as the source of information to respond to queries
|
|
27
|
+
* about resource schema. While this is useful, this may not be ideal for your application.
|
|
28
|
+
* For instance, Schema information could be sideloaded or pre-flighted for API calls,
|
|
29
|
+
* resulting in no need to bundle and ship potentially large and expensive JSON
|
|
30
|
+
* or large Javascript based Models to pull information from.
|
|
31
|
+
*
|
|
32
|
+
* To register a custom schema implementation, extend the store service or
|
|
33
|
+
* lookup and register the schema service first thing on app-boot. Example below
|
|
34
|
+
* shows extending the service.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import Store from '@ember-data/store';
|
|
38
|
+
* import CustomSchemas from './custom-schemas';
|
|
39
|
+
*
|
|
40
|
+
* export default class extends Store {
|
|
41
|
+
* constructor(...args) {
|
|
42
|
+
* super(...args);
|
|
43
|
+
* this.registerSchema(new CustomSchemas());
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* At runtime, both the `Store` and the `CacheCapabilitiesManager` provide
|
|
49
|
+
* access to this service via the `schema` property.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* export default class extends Component {
|
|
53
|
+
* @service store;
|
|
54
|
+
*
|
|
55
|
+
* get attributes() {
|
|
56
|
+
* return this.store
|
|
57
|
+
* .schema
|
|
58
|
+
* .attributesDefinitionFor(this.args.dataType);
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Note: there can only be one schema service registered at a time.
|
|
64
|
+
* If you register a new schema service, the old one will be replaced.
|
|
65
|
+
*
|
|
66
|
+
* If you would like to inherit from another schema service, you can do so by
|
|
67
|
+
* using typical class inheritance patterns OR by accessing the existing
|
|
68
|
+
* schema service at runtime before replacing it with your own, and then
|
|
69
|
+
* having your own delegate to it when needed.
|
|
70
|
+
*
|
|
71
|
+
* @class <Interface> SchemaService
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export interface SchemaService {
|
|
75
|
+
/**
|
|
76
|
+
* Queries whether the schema-definition-service recognizes `type` as a resource type
|
|
77
|
+
*
|
|
78
|
+
* @method doesTypeExist
|
|
79
|
+
* @public
|
|
80
|
+
* @param {string} type
|
|
81
|
+
* @return {boolean}
|
|
82
|
+
*/
|
|
83
|
+
doesTypeExist(type: string): boolean;
|
|
84
|
+
fields({ type }: {
|
|
85
|
+
type: string;
|
|
86
|
+
}): Map<string, FieldSchema>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns definitions for all properties of the specified resource
|
|
89
|
+
* that are considered "attributes". Generally these are properties
|
|
90
|
+
* that are not related to book-keeping state on the client and do
|
|
91
|
+
* not represent a linkage to another resource.
|
|
92
|
+
*
|
|
93
|
+
* The return value should be a dictionary of key:value pairs
|
|
94
|
+
* where the `key` is the attribute or property's name and `value`
|
|
95
|
+
* is an object with at least the property `name` which should also
|
|
96
|
+
* match `key`.
|
|
97
|
+
*
|
|
98
|
+
* Optionally, this object may also specify `type`, which should
|
|
99
|
+
* be a string reference to a `transform`, and `options` which
|
|
100
|
+
* should be dictionary in which any key:value pairs are permissable.
|
|
101
|
+
*
|
|
102
|
+
* For instance, when using `@ember-data/model`, the following attribute
|
|
103
|
+
* definition:
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* class extends Model {
|
|
107
|
+
* @attr('string', { defaultValue: 'hello' }) greeting;
|
|
108
|
+
* @attr('date') birthday;
|
|
109
|
+
* @attr firstName;
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* Would be returned as:
|
|
114
|
+
*
|
|
115
|
+
* ```js
|
|
116
|
+
* {
|
|
117
|
+
* greeting: { name: 'greeting', type: 'string', options: { defaultValue: 'hello' } },
|
|
118
|
+
* birthday: { name: 'birthday', type: 'date' },
|
|
119
|
+
* firstName: { name: 'firstName' }
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @method attributesDefinitionFor
|
|
124
|
+
* @public
|
|
125
|
+
* @param {RecordIdentifier|{ type: string }} identifier
|
|
126
|
+
* @return {AttributesSchema}
|
|
127
|
+
*/
|
|
128
|
+
attributesDefinitionFor(identifier: RecordIdentifier | {
|
|
129
|
+
type: string;
|
|
130
|
+
}): AttributesSchema;
|
|
131
|
+
/**
|
|
132
|
+
* Returns definitions for all properties of the specified resource
|
|
133
|
+
* that are considered "relationships". Generally these are properties
|
|
134
|
+
* that represent a linkage to another resource.
|
|
135
|
+
*
|
|
136
|
+
* The return value should be a dictionary of key:value pairs
|
|
137
|
+
* where the `key` is the relationship or property's name and `value`
|
|
138
|
+
* is an object with at least the following properties:
|
|
139
|
+
*
|
|
140
|
+
* - `name` which should also match the `key` used in the dictionary.
|
|
141
|
+
* - `kind` which should be either `belongsTo` or `hasMany`
|
|
142
|
+
* - `type` which should be the related resource's string "type"
|
|
143
|
+
* - `options` which should be a dictionary allowing any key but with
|
|
144
|
+
* at least the below keys present.
|
|
145
|
+
*
|
|
146
|
+
* - `options.async` a boolean representing whether data for this relationship is
|
|
147
|
+
* typically loaded on-demand.
|
|
148
|
+
* - `options.inverse` a string or null representing the field name / key of the
|
|
149
|
+
* corresponding relationship on the inverse resource.
|
|
150
|
+
*
|
|
151
|
+
* Additionally the following options properties are optional. See [Polymorphic Relationships](https://rfcs.emberjs.com/id/0793-polymporphic-relations-without-inheritance)
|
|
152
|
+
*
|
|
153
|
+
* - `options.polymorphic` a boolean representing whether multiple resource types
|
|
154
|
+
* can be used to satisfy this relationship.
|
|
155
|
+
* - `options.as` a string representing the abstract type that the concrete side of
|
|
156
|
+
* a relationship must specify when fulfilling a polymorphic inverse.
|
|
157
|
+
*
|
|
158
|
+
* For example, the following Model using @ember-data/model would generate this relationships
|
|
159
|
+
* definition by default:
|
|
160
|
+
*
|
|
161
|
+
* ```js
|
|
162
|
+
* class User extends Model {
|
|
163
|
+
* @belongsTo('user', { async: false, inverse: null }) bestFriend;
|
|
164
|
+
* @hasMany('user', { async: true, inverse: 'friends' }) friends;
|
|
165
|
+
* @hasMany('pet', { async: false, polymorphic: true, inverse: 'owner' }) pets;
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* Which would be returned as
|
|
170
|
+
*
|
|
171
|
+
* ```js
|
|
172
|
+
* {
|
|
173
|
+
* bestFriend: {
|
|
174
|
+
* name: 'bestFriend',
|
|
175
|
+
* kind: 'belongsTo',
|
|
176
|
+
* type: 'user',
|
|
177
|
+
* options: {
|
|
178
|
+
* async: false,
|
|
179
|
+
* inverse: null
|
|
180
|
+
* }
|
|
181
|
+
* },
|
|
182
|
+
* friends: {
|
|
183
|
+
* name: 'friends',
|
|
184
|
+
* kind: 'hasMany',
|
|
185
|
+
* type: 'user',
|
|
186
|
+
* options: {
|
|
187
|
+
* async: true,
|
|
188
|
+
* inverse: 'friends'
|
|
189
|
+
* }
|
|
190
|
+
* },
|
|
191
|
+
* pets: {
|
|
192
|
+
* name: 'pets',
|
|
193
|
+
* kind: 'hasMany',
|
|
194
|
+
* type: 'pet',
|
|
195
|
+
* options: {
|
|
196
|
+
* async: false,
|
|
197
|
+
* polymorphic: true,
|
|
198
|
+
* inverse: 'owner'
|
|
199
|
+
* }
|
|
200
|
+
* },
|
|
201
|
+
* }
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @method relationshipsDefinitionFor
|
|
205
|
+
* @public
|
|
206
|
+
* @param {RecordIdentifier|{ type: string }} identifier
|
|
207
|
+
* @return {RelationshipsSchema}
|
|
208
|
+
*/
|
|
209
|
+
relationshipsDefinitionFor(identifier: RecordIdentifier | {
|
|
210
|
+
type: string;
|
|
211
|
+
}): RelationshipsSchema;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=schema-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-service.d.ts","sourceRoot":"","sources":["../../../src/-types/q/schema-service.ts"],"names":[],"mappings":"AAAA;;EAEE;AAEF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAE3F,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EACA,WAAW,GACX,SAAS,GACT,WAAW,GACX,OAAO,GACP,UAAU,GACV,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,OAAO,GACP,KAAK,GACL,QAAQ,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;OAOG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAErC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,uBAAuB,CAAC,UAAU,EAAE,gBAAgB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,gBAAgB,CAAC;IAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6EG;IACH,0BAA0B,CAAC,UAAU,EAAE,gBAAgB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,mBAAmB,CAAC;CAClG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module '@ember-data/store/-types/q/store' {
|
|
2
|
+
import type { Value } from '@warp-drive/core-types/json/raw';
|
|
3
|
+
export interface BaseFinderOptions {
|
|
4
|
+
reload?: boolean;
|
|
5
|
+
backgroundReload?: boolean;
|
|
6
|
+
include?: string | string[];
|
|
7
|
+
adapterOptions?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface FindRecordOptions extends BaseFinderOptions {
|
|
10
|
+
preload?: Record<string, Value>;
|
|
11
|
+
}
|
|
12
|
+
export type QueryOptions = {
|
|
13
|
+
[K in string | 'adapterOptions']?: K extends 'adapterOptions' ? Record<string, unknown> : unknown;
|
|
14
|
+
};
|
|
15
|
+
export type FindAllOptions = BaseFinderOptions;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/-types/q/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AACD,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACjC;AAED,MAAM,MAAM,YAAY,GAAG;KACxB,CAAC,IAAI,MAAM,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;CAClG,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/// <reference path="./-private.d.ts" />
|
|
2
|
+
/// <reference path="./-types/overview.d.ts" />
|
|
3
|
+
/// <reference path="./-types/q/identifier.d.ts" />
|
|
4
|
+
/// <reference path="./-types/q/schema-service.d.ts" />
|
|
5
|
+
/// <reference path="./-types/q/ds-model.d.ts" />
|
|
6
|
+
/// <reference path="./-types/q/promise-proxies.d.ts" />
|
|
7
|
+
/// <reference path="./-types/q/record-data-json-api.d.ts" />
|
|
8
|
+
/// <reference path="./-types/q/cache-store-wrapper.d.ts" />
|
|
9
|
+
/// <reference path="./-types/q/record-instance.d.ts" />
|
|
10
|
+
/// <reference path="./-types/q/cache.d.ts" />
|
|
11
|
+
/// <reference path="./-types/q/store.d.ts" />
|
|
12
|
+
/// <reference path="./-private/document.d.ts" />
|
|
13
|
+
/// <reference path="./-private/cache-handler.d.ts" />
|
|
14
|
+
/// <reference path="./-private/store-service.d.ts" />
|
|
15
|
+
/// <reference path="./-private/legacy-model-support/record-reference.d.ts" />
|
|
16
|
+
/// <reference path="./-private/legacy-model-support/shim-model-class.d.ts" />
|
|
17
|
+
/// <reference path="./-private/caches/identifier-cache.d.ts" />
|
|
18
|
+
/// <reference path="./-private/caches/instance-cache.d.ts" />
|
|
19
|
+
/// <reference path="./-private/caches/cache-utils.d.ts" />
|
|
20
|
+
/// <reference path="./-private/caches/resource-utils.d.ts" />
|
|
21
|
+
/// <reference path="./-private/utils/coerce-id.d.ts" />
|
|
22
|
+
/// <reference path="./-private/utils/is-non-empty-string.d.ts" />
|
|
23
|
+
/// <reference path="./-private/utils/uuid-polyfill.d.ts" />
|
|
24
|
+
/// <reference path="./-private/utils/identifier-debug-consts.d.ts" />
|
|
25
|
+
/// <reference path="./-private/utils/construct-resource.d.ts" />
|
|
26
|
+
/// <reference path="./-private/utils/normalize-model-name.d.ts" />
|
|
27
|
+
/// <reference path="./-private/record-arrays/identifier-array.d.ts" />
|
|
28
|
+
/// <reference path="./-private/record-arrays/native-proxy-type-fix.d.ts" />
|
|
29
|
+
/// <reference path="./-private/managers/record-array-manager.d.ts" />
|
|
30
|
+
/// <reference path="./-private/managers/cache-manager.d.ts" />
|
|
31
|
+
/// <reference path="./-private/managers/cache-capabilities-manager.d.ts" />
|
|
32
|
+
/// <reference path="./-private/managers/notification-manager.d.ts" />
|
|
33
|
+
/// <reference path="./-private/network/request-cache.d.ts" />
|
|
34
|
+
declare module '@ember-data/store' {
|
|
35
|
+
/**
|
|
36
|
+
* <p align="center">
|
|
37
|
+
* <img
|
|
38
|
+
* class="project-logo"
|
|
39
|
+
* src="https://raw.githubusercontent.com/emberjs/data/4612c9354e4c54d53327ec2cf21955075ce21294/ember-data-logo-light.svg#gh-light-mode-only"
|
|
40
|
+
* alt="EmberData Store"
|
|
41
|
+
* width="240px"
|
|
42
|
+
* title="EmberData Store"
|
|
43
|
+
* />
|
|
44
|
+
* </p>
|
|
45
|
+
*
|
|
46
|
+
* This package provides [*Ember***Data**](https://github.com/emberjs/data/)'s `Store` class.
|
|
47
|
+
*
|
|
48
|
+
* A [Store](https://api.emberjs.com/ember-data/release/classes/Store) coordinates interaction between your application, a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache),
|
|
49
|
+
* and sources of data (such as your API or a local persistence layer) accessed via a [RequestManager](https://github.com/emberjs/data/tree/main/packages/request).
|
|
50
|
+
*
|
|
51
|
+
* Optionally, a Store can be configured to hydrate the response data into rich presentation classes.
|
|
52
|
+
*
|
|
53
|
+
* ## Installation
|
|
54
|
+
*
|
|
55
|
+
* If you have installed `ember-data` then you already have this package installed.
|
|
56
|
+
* Otherwise you can install it using your javascript package manager of choice.
|
|
57
|
+
* For instance with [pnpm](https://pnpm.io/)
|
|
58
|
+
*
|
|
59
|
+
* ```
|
|
60
|
+
* pnpm add @ember-data/store
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* After installing you will want to configure your first `Store`. Read more below
|
|
64
|
+
* for how to create and configure stores for your application.
|
|
65
|
+
*
|
|
66
|
+
*
|
|
67
|
+
* ## 🔨 Creating A Store
|
|
68
|
+
*
|
|
69
|
+
* To use a `Store` we will need to do few things: add a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache)
|
|
70
|
+
* to store data **in-memory**, add a [Handler](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache) to fetch data from a source,
|
|
71
|
+
* and implement `instantiateRecord` to tell the store how to display the data for individual resources.
|
|
72
|
+
*
|
|
73
|
+
* > **Note**
|
|
74
|
+
* > If you are using the package `ember-data` then a JSON:API cache, RequestManager, LegacyNetworkHandler,
|
|
75
|
+
* > and `instantiateRecord` are configured for you by default.
|
|
76
|
+
*
|
|
77
|
+
* ### Configuring A Cache
|
|
78
|
+
*
|
|
79
|
+
* To start, let's install a [JSON:API](https://jsonapi.org/) cache. If your app uses `GraphQL` or `REST` other
|
|
80
|
+
* caches may better fit your data. You can author your own cache by creating one that
|
|
81
|
+
* conforms to the [spec](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache).
|
|
82
|
+
*
|
|
83
|
+
* The package `@ember-data/json-api` provides a [JSON:API](https://jsonapi.org/) cache we can use.
|
|
84
|
+
* After installing it, we can configure the store to use this cache.
|
|
85
|
+
*
|
|
86
|
+
* ```js
|
|
87
|
+
* import Store from '@ember-data/store';
|
|
88
|
+
* import Cache from '@ember-data/json-api';
|
|
89
|
+
*
|
|
90
|
+
* class extends Store {
|
|
91
|
+
* createCache(storeWrapper) {
|
|
92
|
+
* return new Cache(storeWrapper);
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* Now that we have a `cache` let's setup something to handle fetching
|
|
98
|
+
* and saving data via our API.
|
|
99
|
+
*
|
|
100
|
+
* > **Note**
|
|
101
|
+
* > The `ember-data` package automatically includes and configures
|
|
102
|
+
* > the `@ember-data/json-api` cache for you.
|
|
103
|
+
*
|
|
104
|
+
* ### Handling Requests
|
|
105
|
+
*
|
|
106
|
+
* When *Ember***Data** needs to fetch or save data it will pass that request to your application's `RequestManager` for fulfillment. How this fulfillment occurs (in-memory, device storage, via single or multiple API requests, etc.) is then up to the registered request handlers.
|
|
107
|
+
*
|
|
108
|
+
* To start, let's install the `RequestManager` from `@ember-data/request` and the basic `Fetch` handler from ``@ember-data/request/fetch`.
|
|
109
|
+
*
|
|
110
|
+
* > **Note**
|
|
111
|
+
* > If your app uses `GraphQL`, `REST` or different conventions for `JSON:API` than your cache expects, other handlers may better fit your data. You can author your own handler by creating one that conforms to the [handler interface](https://github.com/emberjs/data/tree/main/packages/request#handling-requests).
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* import Store from '@ember-data/store';
|
|
115
|
+
* import RequestManager from '@ember-data/request';
|
|
116
|
+
* import Fetch from '@ember-data/request/fetch';
|
|
117
|
+
*
|
|
118
|
+
* export default class extends Store {
|
|
119
|
+
* constructor() {
|
|
120
|
+
* super(...arguments);
|
|
121
|
+
* this.requestManager = new RequestManager();
|
|
122
|
+
* this.requestManager.use([Fetch]);
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* **Using RequestManager as a Service**
|
|
128
|
+
*
|
|
129
|
+
* Alternatively if you have configured the `RequestManager` to be a service you may re-use it.
|
|
130
|
+
*
|
|
131
|
+
* *app/services/request.js*
|
|
132
|
+
* ```ts
|
|
133
|
+
* import RequestManager from '@ember-data/request';
|
|
134
|
+
* import Fetch from '@ember-data/request/fetch';
|
|
135
|
+
*
|
|
136
|
+
* export default class extends RequestManager {
|
|
137
|
+
* constructor(createArgs) {
|
|
138
|
+
* super(createArgs);
|
|
139
|
+
* this.use([Fetch]);
|
|
140
|
+
* }
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* *app/services/store.js*
|
|
145
|
+
* ```ts
|
|
146
|
+
* import Store from '@ember-data/store';
|
|
147
|
+
* import { service } from '@ember/service';
|
|
148
|
+
*
|
|
149
|
+
* export default class extends Store {
|
|
150
|
+
* @service('request') requestManager
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
*
|
|
155
|
+
* ### Presenting Data from the Cache
|
|
156
|
+
*
|
|
157
|
+
* Now that we have a source and a cach for our data, we need to configure how
|
|
158
|
+
* the Store delivers that data back to our application. We do this via the hook
|
|
159
|
+
* [instantiateRecord](https://api.emberjs.com/ember-data/release/classes/Store/methods/instantiateRecord%20(hook)?anchor=instantiateRecord%20(hook)),
|
|
160
|
+
* which allows us to transform the data for a resource before handing it to the application.
|
|
161
|
+
*
|
|
162
|
+
* A naive way to present the data would be to return it as JSON. Typically instead
|
|
163
|
+
* this hook will be used to add reactivity and make each unique resource a singleton,
|
|
164
|
+
* ensuring that if the cache updates our presented data will reflect the new state.
|
|
165
|
+
*
|
|
166
|
+
* Below is an example of using the hooks `instantiateRecord` and a `teardownRecord`
|
|
167
|
+
* to provide minimal read-only reactive state for simple resources.
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* import Store, { recordIdentifierFor } from '@ember-data/store';
|
|
171
|
+
* import { TrackedObject } from 'tracked-built-ins';
|
|
172
|
+
*
|
|
173
|
+
* class extends Store {
|
|
174
|
+
* instantiateRecord(identifier) {
|
|
175
|
+
* const { cache, notifications } = this;
|
|
176
|
+
*
|
|
177
|
+
* // create a TrackedObject with our attributes, id and type
|
|
178
|
+
* const record = new TrackedObject(Object.assign({}, cache.peek(identifier)));
|
|
179
|
+
* record.type = identifier.type;
|
|
180
|
+
* record.id = identifier.id;
|
|
181
|
+
*
|
|
182
|
+
* notifications.subscribe(identifier, (_, change) => {
|
|
183
|
+
* if (change === 'attributes') {
|
|
184
|
+
* Object.assign(record, cache.peek(identifier));
|
|
185
|
+
* }
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* return record;
|
|
189
|
+
* }
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* Because `instantiateRecord` is opaque to the nature of the record, an implementation
|
|
194
|
+
* can be anything from a fairly simple object to a robust proxy that intelligently links
|
|
195
|
+
* together associated records through relationships.
|
|
196
|
+
*
|
|
197
|
+
* This also enables creating a record that separates `edit` flows from `create` flows
|
|
198
|
+
* entirely. A record class might choose to implement a `checkout`method that gives access
|
|
199
|
+
* to an editable instance while the primary record continues to be read-only and reflect
|
|
200
|
+
* only persisted (non-mutated) state.
|
|
201
|
+
*
|
|
202
|
+
* Typically you will choose an existing record implementation such as `@ember-data/model`
|
|
203
|
+
* for your application.
|
|
204
|
+
*
|
|
205
|
+
* Because of the boundaries around instantiation and the cache, record implementations
|
|
206
|
+
* should be capable of interop both with each other and with any `Cache`. Due to this,
|
|
207
|
+
* if needed an application can utilize multiple record implementations and multiple cache
|
|
208
|
+
* implementations either to support enhanced features for only a subset of records or to
|
|
209
|
+
* be able to incrementally migrate from one record/cache to another record or cache.
|
|
210
|
+
*
|
|
211
|
+
* > **Note**
|
|
212
|
+
* > The `ember-data` package automatically includes the `@ember-data/model`
|
|
213
|
+
* > package and configures it for you.
|
|
214
|
+
*
|
|
215
|
+
* @module @ember-data/store
|
|
216
|
+
* @main @ember-data/store
|
|
217
|
+
*/
|
|
218
|
+
export { Store as default, CacheHandler, type LifetimesService, type StoreRequestInput, setIdentifierGenerationMethod, setIdentifierUpdateMethod, setIdentifierForgetMethod, setIdentifierResetMethod, recordIdentifierFor, storeFor, } from '@ember-data/store/-private';
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsLG;AAEH,OAAO,EACL,KAAK,IAAI,OAAO,EAChB,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,6BAA6B,EAC7B,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,mBAAmB,EACnB,QAAQ,GACT,MAAM,YAAY,CAAC"}
|