@ember-data/legacy-compat 4.12.0-alpha.9 → 4.12.0-beta.4
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/addon/-private.js +1 -1
- package/addon/fetch-manager-1067c70f.js +1128 -0
- package/addon/fetch-manager-1067c70f.js.map +1 -0
- package/addon/index.js +518 -1637
- package/addon/index.js.map +1 -1
- package/addon-main.js +18 -15
- package/package.json +17 -6
- package/addon/snapshot-record-array-a4efeb60.js +0 -169
- package/addon/snapshot-record-array-a4efeb60.js.map +0 -1
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { macroCondition, getOwnConfig } from '@embroider/macros';
|
|
2
|
-
import { deprecate } from '@ember/debug';
|
|
3
|
-
import { SOURCE } from '@ember-data/store/-private';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
SnapshotRecordArray is not directly instantiable.
|
|
7
|
-
Instances are provided to consuming application's
|
|
8
|
-
adapters for certain requests.
|
|
9
|
-
|
|
10
|
-
@class SnapshotRecordArray
|
|
11
|
-
@public
|
|
12
|
-
*/
|
|
13
|
-
class SnapshotRecordArray {
|
|
14
|
-
/**
|
|
15
|
-
SnapshotRecordArray is not directly instantiable.
|
|
16
|
-
Instances are provided to consuming application's
|
|
17
|
-
adapters and serializers for certain requests.
|
|
18
|
-
@method constructor
|
|
19
|
-
@private
|
|
20
|
-
@constructor
|
|
21
|
-
@param {Store} store
|
|
22
|
-
@param {string} type
|
|
23
|
-
@param options
|
|
24
|
-
*/
|
|
25
|
-
constructor(store, type, options = {}) {
|
|
26
|
-
this.__store = store;
|
|
27
|
-
/**
|
|
28
|
-
An array of snapshots
|
|
29
|
-
@private
|
|
30
|
-
@property _snapshots
|
|
31
|
-
@type {Array}
|
|
32
|
-
*/
|
|
33
|
-
this._snapshots = null;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
The modelName of the underlying records for the snapshots in the array, as a Model
|
|
37
|
-
@property modelName
|
|
38
|
-
@public
|
|
39
|
-
@type {Model}
|
|
40
|
-
*/
|
|
41
|
-
this.modelName = type;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
A hash of adapter options passed into the store method for this request.
|
|
45
|
-
Example
|
|
46
|
-
```app/adapters/post.js
|
|
47
|
-
import MyCustomAdapter from './custom-adapter';
|
|
48
|
-
export default class PostAdapter extends MyCustomAdapter {
|
|
49
|
-
findAll(store, type, sinceToken, snapshotRecordArray) {
|
|
50
|
-
if (snapshotRecordArray.adapterOptions.subscribe) {
|
|
51
|
-
// ...
|
|
52
|
-
}
|
|
53
|
-
// ...
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
@property adapterOptions
|
|
58
|
-
@public
|
|
59
|
-
@type {Object}
|
|
60
|
-
*/
|
|
61
|
-
this.adapterOptions = options.adapterOptions;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
The relationships to include for this request.
|
|
65
|
-
Example
|
|
66
|
-
```app/adapters/application.js
|
|
67
|
-
import Adapter from '@ember-data/adapter';
|
|
68
|
-
export default class ApplicationAdapter extends Adapter {
|
|
69
|
-
findAll(store, type, snapshotRecordArray) {
|
|
70
|
-
let url = `/${type.modelName}?include=${encodeURIComponent(snapshotRecordArray.include)}`;
|
|
71
|
-
return fetch(url).then((response) => response.json())
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
@property include
|
|
76
|
-
@public
|
|
77
|
-
@type {String|Array}
|
|
78
|
-
*/
|
|
79
|
-
this.include = options.include;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
An array of records
|
|
84
|
-
@property _recordArray
|
|
85
|
-
@private
|
|
86
|
-
@type {Array}
|
|
87
|
-
*/
|
|
88
|
-
get _recordArray() {
|
|
89
|
-
return this.__store.peekAll(this.modelName);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
Number of records in the array
|
|
94
|
-
Example
|
|
95
|
-
```app/adapters/post.js
|
|
96
|
-
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
97
|
-
export default class PostAdapter extends JSONAPIAdapter {
|
|
98
|
-
shouldReloadAll(store, snapshotRecordArray) {
|
|
99
|
-
return !snapshotRecordArray.length;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
@property length
|
|
104
|
-
@public
|
|
105
|
-
@type {Number}
|
|
106
|
-
*/
|
|
107
|
-
get length() {
|
|
108
|
-
return this._recordArray.length;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
Get snapshots of the underlying record array
|
|
113
|
-
Example
|
|
114
|
-
```app/adapters/post.js
|
|
115
|
-
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
116
|
-
export default class PostAdapter extends JSONAPIAdapter {
|
|
117
|
-
shouldReloadAll(store, snapshotArray) {
|
|
118
|
-
let snapshots = snapshotArray.snapshots();
|
|
119
|
-
return snapshots.any(function(ticketSnapshot) {
|
|
120
|
-
let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
|
|
121
|
-
if (timeDiff > 20) {
|
|
122
|
-
return true;
|
|
123
|
-
} else {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
@method snapshots
|
|
131
|
-
@public
|
|
132
|
-
@return {Array} Array of snapshots
|
|
133
|
-
*/
|
|
134
|
-
snapshots() {
|
|
135
|
-
if (this._snapshots !== null) {
|
|
136
|
-
return this._snapshots;
|
|
137
|
-
}
|
|
138
|
-
const {
|
|
139
|
-
_instanceCache
|
|
140
|
-
} = this.__store;
|
|
141
|
-
this._snapshots = this._recordArray[SOURCE].map(identifier => _instanceCache.createSnapshot(identifier));
|
|
142
|
-
return this._snapshots;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (macroCondition(getOwnConfig().deprecations.DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS)) {
|
|
146
|
-
/**
|
|
147
|
-
The type of the underlying records for the snapshots in the array, as a Model
|
|
148
|
-
@deprecated
|
|
149
|
-
@property type
|
|
150
|
-
@public
|
|
151
|
-
@type {Model}
|
|
152
|
-
*/
|
|
153
|
-
Object.defineProperty(SnapshotRecordArray.prototype, 'type', {
|
|
154
|
-
get() {
|
|
155
|
-
deprecate(`Using SnapshotRecordArray.type to access the ModelClass for a record is deprecated. Use store.modelFor(<modelName>) instead.`, false, {
|
|
156
|
-
id: 'ember-data:deprecate-snapshot-model-class-access',
|
|
157
|
-
until: '5.0',
|
|
158
|
-
for: 'ember-data',
|
|
159
|
-
since: {
|
|
160
|
-
available: '4.5.0',
|
|
161
|
-
enabled: '4.5.0'
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
// @ts-expect-error
|
|
165
|
-
return this._recordArray.type;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
export { SnapshotRecordArray as S };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-record-array-a4efeb60.js","sources":["../src/legacy-network-handler/snapshot-record-array.ts"],"sourcesContent":["/**\n @module @ember-data/legacy-compat\n*/\n\nimport { deprecate } from '@ember/debug';\n\nimport { DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS } from '@ember-data/private-build-infra/deprecations';\nimport Store from '@ember-data/store';\nimport { SOURCE } from '@ember-data/store/-private';\nimport type Snapshot from '@ember-data/store/-private/network/snapshot';\nimport type IdentifierArray from '@ember-data/store/-private/record-arrays/identifier-array';\nimport type { DSModelSchema, ModelSchema } from '@ember-data/types/q/ds-model';\nimport { StableRecordIdentifier } from '@ember-data/types/q/identifier';\nimport type { FindOptions } from '@ember-data/types/q/store';\nimport type { Dict } from '@ember-data/types/q/utils';\n/**\n SnapshotRecordArray is not directly instantiable.\n Instances are provided to consuming application's\n adapters for certain requests.\n\n @class SnapshotRecordArray\n @public\n*/\nexport default class SnapshotRecordArray {\n declare _snapshots: Snapshot[] | null;\n declare _type: ModelSchema | null;\n declare modelName: string;\n declare __store: Store;\n\n declare adapterOptions?: Dict<unknown>;\n declare include?: string;\n\n /**\n SnapshotRecordArray is not directly instantiable.\n Instances are provided to consuming application's\n adapters and serializers for certain requests.\n\n @method constructor\n @private\n @constructor\n @param {Store} store\n @param {string} type\n @param options\n */\n constructor(store: Store, type: string, options: FindOptions = {}) {\n this.__store = store;\n /**\n An array of snapshots\n @private\n @property _snapshots\n @type {Array}\n */\n this._snapshots = null;\n\n /**\n The modelName of the underlying records for the snapshots in the array, as a Model\n @property modelName\n @public\n @type {Model}\n */\n this.modelName = type;\n\n /**\n A hash of adapter options passed into the store method for this request.\n\n Example\n\n ```app/adapters/post.js\n import MyCustomAdapter from './custom-adapter';\n\n export default class PostAdapter extends MyCustomAdapter {\n findAll(store, type, sinceToken, snapshotRecordArray) {\n if (snapshotRecordArray.adapterOptions.subscribe) {\n // ...\n }\n // ...\n }\n }\n ```\n\n @property adapterOptions\n @public\n @type {Object}\n */\n this.adapterOptions = options.adapterOptions;\n\n /**\n The relationships to include for this request.\n\n Example\n\n ```app/adapters/application.js\n import Adapter from '@ember-data/adapter';\n\n export default class ApplicationAdapter extends Adapter {\n findAll(store, type, snapshotRecordArray) {\n let url = `/${type.modelName}?include=${encodeURIComponent(snapshotRecordArray.include)}`;\n\n return fetch(url).then((response) => response.json())\n }\n }\n ```\n\n @property include\n @public\n @type {String|Array}\n */\n this.include = options.include;\n }\n\n /**\n An array of records\n\n @property _recordArray\n @private\n @type {Array}\n */\n get _recordArray(): IdentifierArray {\n return this.__store.peekAll(this.modelName);\n }\n\n /**\n Number of records in the array\n\n Example\n\n ```app/adapters/post.js\n import JSONAPIAdapter from '@ember-data/adapter/json-api';\n\n export default class PostAdapter extends JSONAPIAdapter {\n shouldReloadAll(store, snapshotRecordArray) {\n return !snapshotRecordArray.length;\n }\n });\n ```\n\n @property length\n @public\n @type {Number}\n */\n get length(): number {\n return this._recordArray.length;\n }\n\n /**\n Get snapshots of the underlying record array\n\n Example\n\n ```app/adapters/post.js\n import JSONAPIAdapter from '@ember-data/adapter/json-api';\n\n export default class PostAdapter extends JSONAPIAdapter {\n shouldReloadAll(store, snapshotArray) {\n let snapshots = snapshotArray.snapshots();\n\n return snapshots.any(function(ticketSnapshot) {\n let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');\n if (timeDiff > 20) {\n return true;\n } else {\n return false;\n }\n });\n }\n }\n ```\n\n @method snapshots\n @public\n @return {Array} Array of snapshots\n */\n snapshots() {\n if (this._snapshots !== null) {\n return this._snapshots;\n }\n\n const { _instanceCache } = this.__store;\n this._snapshots = this._recordArray[SOURCE].map((identifier: StableRecordIdentifier) =>\n _instanceCache.createSnapshot(identifier)\n );\n\n return this._snapshots;\n }\n}\n\nif (DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS) {\n /**\n The type of the underlying records for the snapshots in the array, as a Model\n\n @deprecated\n @property type\n @public\n @type {Model}\n */\n Object.defineProperty(SnapshotRecordArray.prototype, 'type', {\n get() {\n deprecate(\n `Using SnapshotRecordArray.type to access the ModelClass for a record is deprecated. Use store.modelFor(<modelName>) instead.`,\n false,\n {\n id: 'ember-data:deprecate-snapshot-model-class-access',\n until: '5.0',\n for: 'ember-data',\n since: { available: '4.5.0', enabled: '4.5.0' },\n }\n );\n // @ts-expect-error\n return (this as SnapshotRecordArray)._recordArray.type as DSModelSchema;\n },\n });\n}\n"],"names":["SnapshotRecordArray","constructor","store","type","options","__store","_snapshots","modelName","adapterOptions","include","_recordArray","peekAll","length","snapshots","_instanceCache","SOURCE","map","identifier","createSnapshot","macroCondition","getOwnConfig","deprecations","DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS","Object","defineProperty","prototype","get","deprecate","id","until","for","since","available","enabled"],"mappings":";;;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMA,mBAAmB,CAAC;AASvC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EAEEC,WAAWA,CAACC,KAAY,EAAEC,IAAY,EAAEC,OAAoB,GAAG,EAAE,EAAE;IACjE,IAAI,CAACC,OAAO,GAAGH,KAAK,CAAA;AACpB;AACJ;AACA;AACA;AACA;AACA;IACI,IAAI,CAACI,UAAU,GAAG,IAAI,CAAA;;AAEtB;AACJ;AACA;AACA;AACA;AACA;IACI,IAAI,CAACC,SAAS,GAAGJ,IAAI,CAAA;;AAErB;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKI,IAAA,IAAI,CAACK,cAAc,GAAGJ,OAAO,CAACI,cAAc,CAAA;;AAE5C;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMI,IAAA,IAAI,CAACC,OAAO,GAAGL,OAAO,CAACK,OAAO,CAAA;AAChC,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;EAEE,IAAIC,YAAYA,GAAoB;IAClC,OAAO,IAAI,CAACL,OAAO,CAACM,OAAO,CAAC,IAAI,CAACJ,SAAS,CAAC,CAAA;AAC7C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EAKE,IAAIK,MAAMA,GAAW;AACnB,IAAA,OAAO,IAAI,CAACF,YAAY,CAACE,MAAM,CAAA;AACjC,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMEC,EAAAA,SAASA,GAAG;AACV,IAAA,IAAI,IAAI,CAACP,UAAU,KAAK,IAAI,EAAE;MAC5B,OAAO,IAAI,CAACA,UAAU,CAAA;AACxB,KAAA;IAEA,MAAM;AAAEQ,MAAAA,cAAAA;KAAgB,GAAG,IAAI,CAACT,OAAO,CAAA;IACvC,IAAI,CAACC,UAAU,GAAG,IAAI,CAACI,YAAY,CAACK,MAAM,CAAC,CAACC,GAAG,CAAEC,UAAkC,IACjFH,cAAc,CAACI,cAAc,CAACD,UAAU,CAAC,CAC1C,CAAA;IAED,OAAO,IAAI,CAACX,UAAU,CAAA;AACxB,GAAA;AACF,CAAA;AAEA,IAAAa,cAAA,CAAAC,YAAA,GAAAC,YAAA,CAAAC,qCAAA,CAA2C,EAAA;AACzC;AACF;AACA;AACA;AACA;AACA;AACA;EAEEC,MAAM,CAACC,cAAc,CAACxB,mBAAmB,CAACyB,SAAS,EAAE,MAAM,EAAE;AAC3DC,IAAAA,GAAGA,GAAG;AACJC,MAAAA,SAAS,CACN,CAAA,4HAAA,CAA6H,EAC9H,KAAK,EACL;AACEC,QAAAA,EAAE,EAAE,kDAAkD;AACtDC,QAAAA,KAAK,EAAE,KAAK;AACZC,QAAAA,GAAG,EAAE,YAAY;AACjBC,QAAAA,KAAK,EAAE;AAAEC,UAAAA,SAAS,EAAE,OAAO;AAAEC,UAAAA,OAAO,EAAE,OAAA;AAAQ,SAAA;AAChD,OAAC,CACF,CAAA;AACD;AACA,MAAA,OAAQ,IAAI,CAAyBvB,YAAY,CAACP,IAAI,CAAA;AACxD,KAAA;AACF,GAAC,CAAC,CAAA;AACJ;;;;"}
|