@ember-data/store 4.10.0-alpha.2 → 4.10.0-alpha.21
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 -0
- package/addon/-private.js.map +1 -0
- package/addon/index-12e1fcb9.js +7660 -0
- package/addon/index-12e1fcb9.js.map +1 -0
- package/addon/index.js +1 -0
- package/addon/index.js.map +1 -0
- package/addon-main.js +90 -0
- package/package.json +44 -15
- package/addon/-private/caches/identifier-cache.ts +0 -686
- package/addon/-private/caches/instance-cache.ts +0 -695
- package/addon/-private/caches/record-data-for.ts +0 -34
- package/addon/-private/index.ts +0 -59
- package/addon/-private/legacy-model-support/record-reference.ts +0 -240
- package/addon/-private/legacy-model-support/schema-definition-service.ts +0 -148
- package/addon/-private/legacy-model-support/shim-model-class.ts +0 -97
- package/addon/-private/managers/record-array-manager.ts +0 -379
- package/addon/-private/managers/record-data-manager.ts +0 -845
- package/addon/-private/managers/record-data-store-wrapper.ts +0 -425
- package/addon/-private/managers/record-notification-manager.ts +0 -111
- package/addon/-private/network/fetch-manager.ts +0 -567
- package/addon/-private/network/finders.js +0 -104
- package/addon/-private/network/request-cache.ts +0 -132
- package/addon/-private/network/snapshot-record-array.ts +0 -209
- package/addon/-private/network/snapshot.ts +0 -563
- package/addon/-private/proxies/promise-proxies.ts +0 -228
- package/addon/-private/proxies/promise-proxy-base.js +0 -7
- package/addon/-private/record-arrays/identifier-array.ts +0 -929
- package/addon/-private/store-service.ts +0 -2896
- package/addon/-private/utils/coerce-id.ts +0 -41
- package/addon/-private/utils/common.js +0 -65
- package/addon/-private/utils/construct-resource.ts +0 -61
- package/addon/-private/utils/identifer-debug-consts.ts +0 -3
- package/addon/-private/utils/is-non-empty-string.ts +0 -3
- package/addon/-private/utils/normalize-model-name.ts +0 -21
- package/addon/-private/utils/promise-record.ts +0 -15
- package/addon/-private/utils/serializer-response.ts +0 -86
- package/addon/-private/utils/uuid-polyfill.ts +0 -73
- package/addon/index.ts +0 -14
- package/index.js +0 -49
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@module @ember-data/store
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Used by the store to normalize IDs entering the store. Despite the fact
|
|
6
|
-
// that developers may provide IDs as numbers (e.g., `store.findRecord('person', 1)`),
|
|
7
|
-
// it is important that internally we use strings, since IDs may be serialized
|
|
8
|
-
// and lose type information. For example, Ember's router may put a record's
|
|
9
|
-
// ID into the URL, and if we later try to deserialize that URL and find the
|
|
10
|
-
// corresponding record, we will not know if it is a string or a number.
|
|
11
|
-
type Coercable = string | number | boolean | null | undefined | symbol;
|
|
12
|
-
|
|
13
|
-
function coerceId(id: Coercable): string | null {
|
|
14
|
-
if (id === null || id === undefined || id === '') {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
if (typeof id === 'string') {
|
|
18
|
-
return id;
|
|
19
|
-
}
|
|
20
|
-
if (typeof id === 'symbol') {
|
|
21
|
-
return id.toString();
|
|
22
|
-
}
|
|
23
|
-
return '' + id;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function ensureStringId(id: Coercable): string {
|
|
27
|
-
let normalized: string | null = null;
|
|
28
|
-
if (typeof id === 'string') {
|
|
29
|
-
normalized = id.length > 0 ? id : null;
|
|
30
|
-
} else if (typeof id === 'number' && !isNaN(id)) {
|
|
31
|
-
normalized = '' + id;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (normalized === null) {
|
|
35
|
-
throw new Error(`Expected id to be a string or number, received ${String(id)}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return normalized;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default coerceId;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { deprecate } from '@ember/debug';
|
|
2
|
-
import { DEBUG } from '@glimmer/env';
|
|
3
|
-
|
|
4
|
-
import { resolve } from 'rsvp';
|
|
5
|
-
|
|
6
|
-
import { DEPRECATE_RSVP_PROMISE } from '@ember-data/private-build-infra/deprecations';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
@module @ember-data/store
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export function _bind(fn, ...args) {
|
|
13
|
-
return function () {
|
|
14
|
-
return fn.apply(undefined, args);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function _guard(promise, test) {
|
|
19
|
-
let guarded = promise.finally(() => {
|
|
20
|
-
if (!test()) {
|
|
21
|
-
guarded._subscribers.length = 0;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return guarded;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function _objectIsAlive(object) {
|
|
29
|
-
return !(object.isDestroyed || object.isDestroying);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function guardDestroyedStore(promise, store, label) {
|
|
33
|
-
let token;
|
|
34
|
-
if (DEBUG) {
|
|
35
|
-
token = store._trackAsyncRequestStart(label);
|
|
36
|
-
}
|
|
37
|
-
let wrapperPromise = resolve(promise, label).then((_v) => {
|
|
38
|
-
if (!_objectIsAlive(store)) {
|
|
39
|
-
if (DEPRECATE_RSVP_PROMISE) {
|
|
40
|
-
deprecate(
|
|
41
|
-
`A Promise did not resolve by the time the store was destroyed. This will error in a future release.`,
|
|
42
|
-
false,
|
|
43
|
-
{
|
|
44
|
-
id: 'ember-data:rsvp-unresolved-async',
|
|
45
|
-
until: '5.0',
|
|
46
|
-
for: '@ember-data/store',
|
|
47
|
-
since: {
|
|
48
|
-
available: '4.5',
|
|
49
|
-
enabled: '4.5',
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return promise;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
return _guard(wrapperPromise, () => {
|
|
60
|
-
if (DEBUG) {
|
|
61
|
-
store._trackAsyncRequestEnd(token);
|
|
62
|
-
}
|
|
63
|
-
return _objectIsAlive(store);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { assert } from '@ember/debug';
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
ExistingResourceIdentifierObject,
|
|
5
|
-
ResourceIdentifierObject,
|
|
6
|
-
} from '@ember-data/types/q/ember-data-json-api';
|
|
7
|
-
|
|
8
|
-
import { isStableIdentifier } from '../caches/identifier-cache';
|
|
9
|
-
import coerceId from './coerce-id';
|
|
10
|
-
import isNonEmptyString from './is-non-empty-string';
|
|
11
|
-
|
|
12
|
-
function constructResource(type: ResourceIdentifierObject): ResourceIdentifierObject;
|
|
13
|
-
function constructResource(type: string, id: string, lid: string): ExistingResourceIdentifierObject;
|
|
14
|
-
function constructResource(
|
|
15
|
-
type: string | undefined,
|
|
16
|
-
id: null | undefined,
|
|
17
|
-
lid: string
|
|
18
|
-
): ExistingResourceIdentifierObject;
|
|
19
|
-
function constructResource(type: string, id: string, lid?: string | null): ExistingResourceIdentifierObject;
|
|
20
|
-
function constructResource(type: string, id?: string | number | null, lid?: string | null): ResourceIdentifierObject;
|
|
21
|
-
function constructResource(
|
|
22
|
-
type: string | ResourceIdentifierObject | undefined,
|
|
23
|
-
id?: string | number | null,
|
|
24
|
-
lid?: string | null
|
|
25
|
-
): ResourceIdentifierObject | ExistingResourceIdentifierObject {
|
|
26
|
-
if (typeof type === 'object' && type !== null) {
|
|
27
|
-
let resource = type;
|
|
28
|
-
if (isStableIdentifier(resource)) {
|
|
29
|
-
return resource;
|
|
30
|
-
}
|
|
31
|
-
if ('id' in resource) {
|
|
32
|
-
resource.id = coerceId(resource.id);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
assert(
|
|
36
|
-
'Expected either id or lid to be a valid string',
|
|
37
|
-
('id' in resource && isNonEmptyString(resource.id)) || isNonEmptyString(resource.lid)
|
|
38
|
-
);
|
|
39
|
-
assert('if id is present, the type must be a string', !('id' in resource) || typeof resource.type === 'string');
|
|
40
|
-
|
|
41
|
-
return resource;
|
|
42
|
-
} else {
|
|
43
|
-
const trueId = coerceId(id);
|
|
44
|
-
if (!isNonEmptyString(trueId)) {
|
|
45
|
-
if (isNonEmptyString(lid)) {
|
|
46
|
-
return { lid };
|
|
47
|
-
}
|
|
48
|
-
throw new Error('Expected either id or lid to be a valid string');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
assert('type must be a string', typeof type === 'string');
|
|
52
|
-
|
|
53
|
-
if (isNonEmptyString(lid)) {
|
|
54
|
-
return { type, id: trueId, lid };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return { type, id: trueId };
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default constructResource;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { dasherize } from '@ember/string';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
@module @ember-data/store
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
This method normalizes a modelName into the format Ember Data uses
|
|
9
|
-
internally by dasherizing it.
|
|
10
|
-
|
|
11
|
-
@method normalizeModelName
|
|
12
|
-
@static
|
|
13
|
-
@public
|
|
14
|
-
@deprecated
|
|
15
|
-
@for @ember-data/store
|
|
16
|
-
@param {String} modelName
|
|
17
|
-
@return {String} normalizedModelName
|
|
18
|
-
*/
|
|
19
|
-
export default function normalizeModelName(modelName: string): string {
|
|
20
|
-
return dasherize(modelName);
|
|
21
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
2
|
-
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
3
|
-
|
|
4
|
-
import type { PromiseObject } from '../proxies/promise-proxies';
|
|
5
|
-
import { promiseObject } from '../proxies/promise-proxies';
|
|
6
|
-
import type Store from '../store-service';
|
|
7
|
-
|
|
8
|
-
export default function promiseRecord(
|
|
9
|
-
store: Store,
|
|
10
|
-
promise: Promise<StableRecordIdentifier>
|
|
11
|
-
): PromiseObject<RecordInstance> {
|
|
12
|
-
let toReturn = promise.then((identifier: StableRecordIdentifier) => store.peekRecord(identifier)!);
|
|
13
|
-
|
|
14
|
-
return promiseObject(toReturn);
|
|
15
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { assert } from '@ember/debug';
|
|
2
|
-
import { DEBUG } from '@glimmer/env';
|
|
3
|
-
|
|
4
|
-
import type { JsonApiDocument } from '@ember-data/types/q/ember-data-json-api';
|
|
5
|
-
import type { AdapterPayload } from '@ember-data/types/q/minimum-adapter-interface';
|
|
6
|
-
import type { MinimumSerializerInterface, RequestType } from '@ember-data/types/q/minimum-serializer-interface';
|
|
7
|
-
|
|
8
|
-
import type ShimModelClass from '../legacy-model-support/shim-model-class';
|
|
9
|
-
import type Store from '../store-service';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
This is a helper method that validates a JSON API top-level document
|
|
13
|
-
|
|
14
|
-
The format of a document is described here:
|
|
15
|
-
http://jsonapi.org/format/#document-top-level
|
|
16
|
-
|
|
17
|
-
@internal
|
|
18
|
-
*/
|
|
19
|
-
function validateDocumentStructure(doc?: AdapterPayload | JsonApiDocument): asserts doc is JsonApiDocument {
|
|
20
|
-
if (DEBUG) {
|
|
21
|
-
let errors: string[] = [];
|
|
22
|
-
if (!doc || typeof doc !== 'object') {
|
|
23
|
-
errors.push('Top level of a JSON API document must be an object');
|
|
24
|
-
} else {
|
|
25
|
-
if (!('data' in doc) && !('errors' in doc) && !('meta' in doc)) {
|
|
26
|
-
errors.push('One or more of the following keys must be present: "data", "errors", "meta".');
|
|
27
|
-
} else {
|
|
28
|
-
if ('data' in doc && 'errors' in doc) {
|
|
29
|
-
errors.push('Top level keys "errors" and "data" cannot both be present in a JSON API document');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if ('data' in doc) {
|
|
33
|
-
if (!(doc.data === null || Array.isArray(doc.data) || typeof doc.data === 'object')) {
|
|
34
|
-
errors.push('data must be null, an object, or an array');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if ('meta' in doc) {
|
|
38
|
-
if (typeof doc.meta !== 'object') {
|
|
39
|
-
errors.push('meta must be an object');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if ('errors' in doc) {
|
|
43
|
-
if (!Array.isArray(doc.errors)) {
|
|
44
|
-
errors.push('errors must be an array');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if ('links' in doc) {
|
|
48
|
-
if (typeof doc.links !== 'object') {
|
|
49
|
-
errors.push('links must be an object');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if ('jsonapi' in doc) {
|
|
53
|
-
if (typeof doc.jsonapi !== 'object') {
|
|
54
|
-
errors.push('jsonapi must be an object');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if ('included' in doc) {
|
|
58
|
-
if (typeof doc.included !== 'object') {
|
|
59
|
-
errors.push('included must be an array');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
assert(
|
|
65
|
-
`Response must be normalized to a valid JSON API document:\n\t* ${errors.join('\n\t* ')}`,
|
|
66
|
-
errors.length === 0
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function normalizeResponseHelper(
|
|
72
|
-
serializer: MinimumSerializerInterface | null,
|
|
73
|
-
store: Store,
|
|
74
|
-
modelClass: ShimModelClass,
|
|
75
|
-
payload: AdapterPayload,
|
|
76
|
-
id: string | null,
|
|
77
|
-
requestType: RequestType
|
|
78
|
-
): JsonApiDocument {
|
|
79
|
-
let normalizedResponse = serializer
|
|
80
|
-
? serializer.normalizeResponse(store, modelClass, payload, id, requestType)
|
|
81
|
-
: payload;
|
|
82
|
-
|
|
83
|
-
validateDocumentStructure(normalizedResponse);
|
|
84
|
-
|
|
85
|
-
return normalizedResponse;
|
|
86
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@module @ember-data/store
|
|
3
|
-
*/
|
|
4
|
-
interface FastbootCrypto {
|
|
5
|
-
randomFillSync(v: Uint8Array): Uint8Array;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default function installPolyfill() {
|
|
9
|
-
const isFastBoot = typeof FastBoot !== 'undefined';
|
|
10
|
-
const CRYPTO: Crypto = isFastBoot ? (FastBoot.require('crypto') as Crypto) : window.crypto;
|
|
11
|
-
|
|
12
|
-
if (!CRYPTO.randomUUID) {
|
|
13
|
-
// we might be able to optimize this by requesting more bytes than we need at a time
|
|
14
|
-
const rng = function (): Uint8Array {
|
|
15
|
-
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
16
|
-
let rnds8 = new Uint8Array(16);
|
|
17
|
-
|
|
18
|
-
if (!CRYPTO.getRandomValues && !isFastBoot) {
|
|
19
|
-
throw new Error(`Unable to generate bytes for UUID`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return CRYPTO.getRandomValues
|
|
23
|
-
? CRYPTO.getRandomValues(rnds8)
|
|
24
|
-
: (CRYPTO as unknown as FastbootCrypto).randomFillSync(rnds8);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/*
|
|
28
|
-
* Convert array of 16 byte values to UUID string format of the form:
|
|
29
|
-
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
30
|
-
*/
|
|
31
|
-
const byteToHex: string[] = [];
|
|
32
|
-
for (let i = 0; i < 256; ++i) {
|
|
33
|
-
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const bytesToUuid = function (buf: Uint8Array) {
|
|
37
|
-
let bth = byteToHex;
|
|
38
|
-
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
|
|
39
|
-
return [
|
|
40
|
-
bth[buf[0]],
|
|
41
|
-
bth[buf[1]],
|
|
42
|
-
bth[buf[2]],
|
|
43
|
-
bth[buf[3]],
|
|
44
|
-
'-',
|
|
45
|
-
bth[buf[4]],
|
|
46
|
-
bth[buf[5]],
|
|
47
|
-
'-',
|
|
48
|
-
bth[buf[6]],
|
|
49
|
-
bth[buf[7]],
|
|
50
|
-
'-',
|
|
51
|
-
bth[buf[8]],
|
|
52
|
-
bth[buf[9]],
|
|
53
|
-
'-',
|
|
54
|
-
bth[buf[10]],
|
|
55
|
-
bth[buf[11]],
|
|
56
|
-
bth[buf[12]],
|
|
57
|
-
bth[buf[13]],
|
|
58
|
-
bth[buf[14]],
|
|
59
|
-
bth[buf[15]],
|
|
60
|
-
].join('');
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
CRYPTO.randomUUID = function uuidv4(): string {
|
|
64
|
-
let rnds = rng();
|
|
65
|
-
|
|
66
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
67
|
-
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
68
|
-
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
69
|
-
|
|
70
|
-
return bytesToUuid(rnds);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
package/addon/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@module @ember-data/store
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
Store as default,
|
|
7
|
-
normalizeModelName,
|
|
8
|
-
setIdentifierGenerationMethod,
|
|
9
|
-
setIdentifierUpdateMethod,
|
|
10
|
-
setIdentifierForgetMethod,
|
|
11
|
-
setIdentifierResetMethod,
|
|
12
|
-
recordIdentifierFor,
|
|
13
|
-
storeFor,
|
|
14
|
-
} from './-private';
|
package/index.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const addonBuildConfigForDataPackage = require('@ember-data/private-build-infra/src/addon-build-config-for-data-package');
|
|
4
|
-
|
|
5
|
-
const name = require('./package').name;
|
|
6
|
-
|
|
7
|
-
const addonBaseConfig = addonBuildConfigForDataPackage(name);
|
|
8
|
-
|
|
9
|
-
module.exports = Object.assign({}, addonBaseConfig, {
|
|
10
|
-
shouldRollupPrivate: true,
|
|
11
|
-
externalDependenciesForPrivateModule() {
|
|
12
|
-
return [
|
|
13
|
-
'ember-cached-decorator-polyfill',
|
|
14
|
-
|
|
15
|
-
'@ember-data/canary-features',
|
|
16
|
-
'@ember-data/tracking/-private',
|
|
17
|
-
|
|
18
|
-
'@ember/application',
|
|
19
|
-
'@ember/array/proxy',
|
|
20
|
-
'@ember/array',
|
|
21
|
-
'@ember/debug',
|
|
22
|
-
'@ember/error',
|
|
23
|
-
'@ember/object',
|
|
24
|
-
'@ember/object/computed',
|
|
25
|
-
'@ember/object/evented',
|
|
26
|
-
'@ember/object/internals',
|
|
27
|
-
'@ember/object/mixin',
|
|
28
|
-
'@ember/object/compat',
|
|
29
|
-
'@ember/object/promise-proxy-mixin',
|
|
30
|
-
'@ember/object/proxy',
|
|
31
|
-
'@ember/polyfills',
|
|
32
|
-
'@ember/runloop',
|
|
33
|
-
'@ember/service',
|
|
34
|
-
'@ember/string',
|
|
35
|
-
'@ember/test',
|
|
36
|
-
'@ember/utils',
|
|
37
|
-
|
|
38
|
-
'@embroider/macros/es-compat',
|
|
39
|
-
'@embroider/macros/runtime',
|
|
40
|
-
|
|
41
|
-
'ember-inflector',
|
|
42
|
-
'ember',
|
|
43
|
-
'rsvp',
|
|
44
|
-
'require',
|
|
45
|
-
|
|
46
|
-
'@glimmer/tracking',
|
|
47
|
-
];
|
|
48
|
-
},
|
|
49
|
-
});
|