@ember-data/store 4.5.0-beta.0 → 4.5.0
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/{system/backburner.js → backburner.js} +0 -0
- package/addon/-private/{system/coerce-id.ts → coerce-id.ts} +0 -0
- package/addon/-private/{system/store/common.js → common.js} +0 -0
- package/addon/-private/{system/core-store.ts → core-store.ts} +467 -1253
- package/addon/-private/{system/errors-utils.js → errors-utils.js} +7 -6
- package/addon/-private/{system/fetch-manager.ts → fetch-manager.ts} +72 -42
- package/addon/-private/finders.js +107 -0
- package/addon/-private/identifer-debug-consts.ts +3 -0
- package/addon/-private/{identifiers/cache.ts → identifier-cache.ts} +26 -14
- package/addon/-private/{system/identity-map.ts → identity-map.ts} +2 -1
- package/addon/-private/index.ts +17 -17
- package/addon/-private/instance-cache.ts +387 -0
- package/addon/-private/{system/store/internal-model-factory.ts → internal-model-factory.ts} +25 -19
- package/addon/-private/{system/internal-model-map.ts → internal-model-map.ts} +9 -5
- package/addon/-private/model/internal-model.ts +602 -0
- package/addon/-private/{system/references/record.ts → model/record-reference.ts} +23 -36
- package/addon/-private/{system/model → model}/shim-model-class.ts +19 -14
- package/addon/-private/{system/normalize-model-name.ts → normalize-model-name.ts} +0 -0
- package/addon/-private/{system/promise-proxies.ts → promise-proxies.ts} +12 -5
- package/addon/-private/{system/promise-proxy-base.js → promise-proxy-base.js} +0 -0
- package/addon/-private/{system/record-array-manager.ts → record-array-manager.ts} +19 -18
- package/addon/-private/{system/record-arrays → record-arrays}/adapter-populated-record-array.ts +11 -10
- package/addon/-private/{system/record-arrays → record-arrays}/record-array.ts +37 -19
- package/addon/-private/record-data-for.ts +39 -0
- package/addon/-private/{system/store/record-data-store-wrapper.ts → record-data-store-wrapper.ts} +21 -26
- package/addon/-private/{system/record-notification-manager.ts → record-notification-manager.ts} +8 -3
- package/addon/-private/{system/request-cache.ts → request-cache.ts} +5 -6
- package/addon/-private/{system/schema-definition-service.ts → schema-definition-service.ts} +30 -14
- package/addon/-private/{system/store/serializer-response.ts → serializer-response.ts} +7 -6
- package/addon/-private/{system/snapshot-record-array.ts → snapshot-record-array.ts} +27 -8
- package/addon/-private/{system/snapshot.ts → snapshot.ts} +54 -39
- package/addon/-private/utils/construct-resource.ts +7 -3
- package/addon/-private/utils/promise-record.ts +9 -18
- package/addon/-private/{system/weak-cache.ts → weak-cache.ts} +2 -2
- package/addon/index.ts +1 -0
- package/package.json +21 -20
- package/addon/-private/identifiers/is-stable-identifier.ts +0 -18
- package/addon/-private/identifiers/utils/uuid-v4.ts +0 -80
- package/addon/-private/system/ds-model-store.ts +0 -136
- package/addon/-private/system/model/internal-model.ts +0 -1303
- package/addon/-private/system/model/states.js +0 -736
- package/addon/-private/system/record-arrays.ts +0 -8
- package/addon/-private/system/record-data-for.ts +0 -54
- package/addon/-private/system/references/belongs-to.ts +0 -406
- package/addon/-private/system/references/has-many.ts +0 -487
- package/addon/-private/system/references/reference.ts +0 -205
- package/addon/-private/system/references.js +0 -9
- package/addon/-private/system/store/finders.js +0 -412
- package/addon/-private/ts-interfaces/ds-model.ts +0 -50
- package/addon/-private/ts-interfaces/ember-data-json-api.ts +0 -145
- package/addon/-private/ts-interfaces/fetch-manager.ts +0 -44
- package/addon/-private/ts-interfaces/identifier.ts +0 -246
- package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +0 -584
- package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +0 -257
- package/addon/-private/ts-interfaces/promise-proxies.ts +0 -3
- package/addon/-private/ts-interfaces/record-data-json-api.ts +0 -29
- package/addon/-private/ts-interfaces/record-data-record-wrapper.ts +0 -46
- package/addon/-private/ts-interfaces/record-data-schemas.ts +0 -45
- package/addon/-private/ts-interfaces/record-data-store-wrapper.ts +0 -56
- package/addon/-private/ts-interfaces/record-data.ts +0 -72
- package/addon/-private/ts-interfaces/record-instance.ts +0 -18
- package/addon/-private/ts-interfaces/schema-definition-service.ts +0 -12
- package/addon/-private/ts-interfaces/store.ts +0 -10
- package/addon/-private/ts-interfaces/utils.ts +0 -6
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
2
|
-
/**
|
|
3
|
-
@module @ember-data/store
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const IDENTIFIERS = new WeakSet();
|
|
7
|
-
|
|
8
|
-
export default function isStableIdentifier(identifier: Object): identifier is StableRecordIdentifier {
|
|
9
|
-
return IDENTIFIERS.has(identifier);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function markStableIdentifier(identifier: Object) {
|
|
13
|
-
IDENTIFIERS.add(identifier);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function unmarkStableIdentifier(identifier: Object) {
|
|
17
|
-
IDENTIFIERS.delete(identifier);
|
|
18
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@module @ember-data/store
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const CRYPTO = (() => {
|
|
6
|
-
const hasWindow = typeof window !== 'undefined';
|
|
7
|
-
const isFastBoot = typeof FastBoot !== 'undefined';
|
|
8
|
-
|
|
9
|
-
if (isFastBoot) {
|
|
10
|
-
return {
|
|
11
|
-
getRandomValues(buffer: Uint8Array) {
|
|
12
|
-
try {
|
|
13
|
-
return (FastBoot as FastBoot).require('crypto').randomFillSync(buffer);
|
|
14
|
-
} catch (err) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
'Using createRecord in Fastboot requires you to add the "crypto" package to "fastbootDependencies" in your package.json'
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
} else if (hasWindow && typeof window.crypto !== 'undefined') {
|
|
22
|
-
return window.crypto;
|
|
23
|
-
} else {
|
|
24
|
-
throw new Error('ember-data: Cannot find a valid way to generate local identifiers');
|
|
25
|
-
}
|
|
26
|
-
})();
|
|
27
|
-
|
|
28
|
-
// we might be able to optimize this by requesting more bytes than we need at a time
|
|
29
|
-
function rng() {
|
|
30
|
-
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
31
|
-
let rnds8 = new Uint8Array(16);
|
|
32
|
-
|
|
33
|
-
return CRYPTO.getRandomValues(rnds8);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/*
|
|
37
|
-
* Convert array of 16 byte values to UUID string format of the form:
|
|
38
|
-
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
39
|
-
*/
|
|
40
|
-
const byteToHex: string[] = [];
|
|
41
|
-
for (let i = 0; i < 256; ++i) {
|
|
42
|
-
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function bytesToUuid(buf) {
|
|
46
|
-
let bth = byteToHex;
|
|
47
|
-
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
|
|
48
|
-
return [
|
|
49
|
-
bth[buf[0]],
|
|
50
|
-
bth[buf[1]],
|
|
51
|
-
bth[buf[2]],
|
|
52
|
-
bth[buf[3]],
|
|
53
|
-
'-',
|
|
54
|
-
bth[buf[4]],
|
|
55
|
-
bth[buf[5]],
|
|
56
|
-
'-',
|
|
57
|
-
bth[buf[6]],
|
|
58
|
-
bth[buf[7]],
|
|
59
|
-
'-',
|
|
60
|
-
bth[buf[8]],
|
|
61
|
-
bth[buf[9]],
|
|
62
|
-
'-',
|
|
63
|
-
bth[buf[10]],
|
|
64
|
-
bth[buf[11]],
|
|
65
|
-
bth[buf[12]],
|
|
66
|
-
bth[buf[13]],
|
|
67
|
-
bth[buf[14]],
|
|
68
|
-
bth[buf[15]],
|
|
69
|
-
].join('');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export default function uuidv4(): string {
|
|
73
|
-
let rnds = rng();
|
|
74
|
-
|
|
75
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
76
|
-
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
77
|
-
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
78
|
-
|
|
79
|
-
return bytesToUuid(rnds);
|
|
80
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { getOwner, setOwner } from '@ember/application';
|
|
2
|
-
import { assert } from '@ember/debug';
|
|
3
|
-
import EmberError from '@ember/error';
|
|
4
|
-
import { isPresent } from '@ember/utils';
|
|
5
|
-
import { DEBUG } from '@glimmer/env';
|
|
6
|
-
|
|
7
|
-
import type DSModelClass from '@ember-data/model';
|
|
8
|
-
|
|
9
|
-
import type { DSModel } from '../ts-interfaces/ds-model';
|
|
10
|
-
import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
11
|
-
import type { RecordDataRecordWrapper } from '../ts-interfaces/record-data-record-wrapper';
|
|
12
|
-
import type { SchemaDefinitionService } from '../ts-interfaces/schema-definition-service';
|
|
13
|
-
import CoreStore from './core-store';
|
|
14
|
-
import type ShimModelClass from './model/shim-model-class';
|
|
15
|
-
import { getShimClass } from './model/shim-model-class';
|
|
16
|
-
import normalizeModelName from './normalize-model-name';
|
|
17
|
-
import type NotificationManager from './record-notification-manager';
|
|
18
|
-
import { DSModelSchemaDefinitionService, getModelFactory } from './schema-definition-service';
|
|
19
|
-
|
|
20
|
-
class Store extends CoreStore {
|
|
21
|
-
public _modelFactoryCache = Object.create(null);
|
|
22
|
-
private _relationshipsDefCache = Object.create(null);
|
|
23
|
-
private _attributesDefCache = Object.create(null);
|
|
24
|
-
|
|
25
|
-
instantiateRecord(
|
|
26
|
-
identifier: StableRecordIdentifier,
|
|
27
|
-
createRecordArgs: { [key: string]: any },
|
|
28
|
-
recordDataFor: (identifier: StableRecordIdentifier) => RecordDataRecordWrapper,
|
|
29
|
-
notificationManager: NotificationManager
|
|
30
|
-
): DSModel {
|
|
31
|
-
let modelName = identifier.type;
|
|
32
|
-
|
|
33
|
-
let internalModel = this._internalModelForResource(identifier);
|
|
34
|
-
let createOptions: any = {
|
|
35
|
-
store: this,
|
|
36
|
-
_internalModel: internalModel,
|
|
37
|
-
// TODO deprecate allowing unknown args setting
|
|
38
|
-
_createProps: createRecordArgs,
|
|
39
|
-
container: null,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// ensure that `getOwner(this)` works inside a model instance
|
|
43
|
-
setOwner(createOptions, getOwner(this));
|
|
44
|
-
|
|
45
|
-
delete createOptions.container;
|
|
46
|
-
let record = this._modelFactoryFor(modelName).create(createOptions);
|
|
47
|
-
return record;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
teardownRecord(record: DSModel) {
|
|
51
|
-
record.destroy();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
modelFor(modelName: string): ShimModelClass | DSModelClass {
|
|
55
|
-
if (DEBUG) {
|
|
56
|
-
assertDestroyedStoreOnly(this, 'modelFor');
|
|
57
|
-
}
|
|
58
|
-
assert(`You need to pass a model name to the store's modelFor method`, isPresent(modelName));
|
|
59
|
-
assert(
|
|
60
|
-
`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`,
|
|
61
|
-
typeof modelName === 'string'
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
let maybeFactory = this._modelFactoryFor(modelName);
|
|
65
|
-
|
|
66
|
-
// for factorFor factory/class split
|
|
67
|
-
let klass = maybeFactory && maybeFactory.class ? maybeFactory.class : maybeFactory;
|
|
68
|
-
if (!klass || !klass.isModel) {
|
|
69
|
-
if (!this.getSchemaDefinitionService().doesTypeExist(modelName)) {
|
|
70
|
-
throw new EmberError(`No model was found for '${modelName}' and no schema handles the type`);
|
|
71
|
-
}
|
|
72
|
-
return getShimClass(this, modelName);
|
|
73
|
-
} else {
|
|
74
|
-
return klass;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
_modelFactoryFor(modelName: string): DSModelClass {
|
|
79
|
-
if (DEBUG) {
|
|
80
|
-
assertDestroyedStoreOnly(this, '_modelFactoryFor');
|
|
81
|
-
}
|
|
82
|
-
assert(`You need to pass a model name to the store's _modelFactoryFor method`, isPresent(modelName));
|
|
83
|
-
assert(
|
|
84
|
-
`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`,
|
|
85
|
-
typeof modelName === 'string'
|
|
86
|
-
);
|
|
87
|
-
let normalizedModelName = normalizeModelName(modelName);
|
|
88
|
-
let factory = getModelFactory(this, this._modelFactoryCache, normalizedModelName);
|
|
89
|
-
|
|
90
|
-
return factory;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_hasModelFor(modelName) {
|
|
94
|
-
if (DEBUG) {
|
|
95
|
-
assertDestroyingStore(this, '_hasModelFor');
|
|
96
|
-
}
|
|
97
|
-
assert(`You need to pass a model name to the store's hasModelFor method`, isPresent(modelName));
|
|
98
|
-
assert(
|
|
99
|
-
`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`,
|
|
100
|
-
typeof modelName === 'string'
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return this.getSchemaDefinitionService().doesTypeExist(modelName);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
_relationshipMetaFor(modelName: string, id: string | null, key: string) {
|
|
107
|
-
return this._relationshipsDefinitionFor({ type: modelName })[key];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
getSchemaDefinitionService(): SchemaDefinitionService {
|
|
111
|
-
if (!this._schemaDefinitionService) {
|
|
112
|
-
this._schemaDefinitionService = new DSModelSchemaDefinitionService(this);
|
|
113
|
-
}
|
|
114
|
-
return this._schemaDefinitionService;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let assertDestroyingStore: Function;
|
|
119
|
-
let assertDestroyedStoreOnly: Function;
|
|
120
|
-
|
|
121
|
-
if (DEBUG) {
|
|
122
|
-
assertDestroyingStore = function assertDestroyedStore(store, method) {
|
|
123
|
-
assert(
|
|
124
|
-
`Attempted to call store.${method}(), but the store instance has already been destroyed.`,
|
|
125
|
-
!(store.isDestroying || store.isDestroyed)
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
assertDestroyedStoreOnly = function assertDestroyedStoreOnly(store, method) {
|
|
129
|
-
assert(
|
|
130
|
-
`Attempted to call store.${method}(), but the store instance has already been destroyed.`,
|
|
131
|
-
!store.isDestroyed
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export default Store;
|