From e5be474dbe8d27ee725d5134e61177d431a69ce0 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Tue, 19 Nov 2019 09:19:24 -0800 Subject: [PATCH] rename Record to RecordInstance --- .../store/addon/-private/system/core-store.ts | 20 +++++++++---------- .../-private/system/model/internal-model.ts | 4 ++-- .../-private/system/references/record.ts | 4 ++-- .../system/store/internal-model-factory.ts | 8 ++++---- .../addon/-private/ts-interfaces/ds-model.ts | 3 +-- .../addon/-private/ts-interfaces/record.ts | 5 ++--- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 8baa75796d8..ae60d7060c8 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -53,7 +53,7 @@ import { HAS_SERIALIZER_PACKAGE, } from '@ember-data/private-build-infra'; -import { Record } from '../ts-interfaces/record'; +import { RecordInstance } from '../ts-interfaces/record'; import { JsonApiRelationship } from '../ts-interfaces/record-data-json-api'; import { ResourceIdentifierObject } from '../ts-interfaces/ember-data-json-api'; @@ -472,9 +472,9 @@ abstract class CoreStore extends Service { createRecordArgs: { [key: string]: unknown }, // args passed in to store.createRecord() and processed by recordData to be set on creation recordDataFor: (identifier: RecordIdentifier) => RecordDataRecordWrapper, notificationManager: NotificationManager - ): Record; + ): RecordInstance; - abstract teardownRecord(record: Record): void; + abstract teardownRecord(record: RecordInstance): void; _internalDeleteRecord(internalModel: InternalModel) { internalModel.deleteRecord(); @@ -1449,7 +1449,7 @@ abstract class CoreStore extends Service { @param {String|Integer} id @return {Model|null} record */ - peekRecord(modelName: string, id: string | number): Record | null { + peekRecord(modelName: string, id: string | number): RecordInstance | null { if (DEBUG) { assertDestroyingStore(this, 'peekRecord'); } @@ -1550,7 +1550,7 @@ abstract class CoreStore extends Service { @param {(String|Integer)} id @return {Model} record */ - recordForId(modelName: string, id: string | number): Record { + recordForId(modelName: string, id: string | number): RecordInstance { if (DEBUG) { assertDestroyingStore(this, 'recordForId'); } @@ -2794,9 +2794,9 @@ abstract class CoreStore extends Service { updated. */ push(data: EmptyResourceDocument): null; - push(data: SingleResourceDocument): Record; - push(data: CollectionResourceDocument): Record[]; - push(data: JsonApiDocument): Record | Record[] | null { + push(data: SingleResourceDocument): RecordInstance; + push(data: CollectionResourceDocument): RecordInstance[]; + push(data: JsonApiDocument): RecordInstance | RecordInstance[] | null { if (DEBUG) { assertDestroyingStore(this, 'push'); } @@ -3033,7 +3033,7 @@ abstract class CoreStore extends Service { return internalModelFactoryFor(this).lookup(resource); } - serializeRecord(record: Record, options?: Dict): unknown { + serializeRecord(record: RecordInstance, options?: Dict): unknown { if (CUSTOM_MODEL_CLASS) { let identifier = recordIdentifierFor(record); let internalModel = internalModelFactoryFor(this).peek(identifier); @@ -3044,7 +3044,7 @@ abstract class CoreStore extends Service { } } - saveRecord(record: Record, options?: Dict): RSVP.Promise { + saveRecord(record: RecordInstance, options?: Dict): RSVP.Promise { if (CUSTOM_MODEL_CLASS) { let identifier = recordIdentifierFor(record); let internalModel = internalModelFactoryFor(this).peek(identifier); diff --git a/packages/store/addon/-private/system/model/internal-model.ts b/packages/store/addon/-private/system/model/internal-model.ts index b3fd72fc2c1..c598f5898b3 100644 --- a/packages/store/addon/-private/system/model/internal-model.ts +++ b/packages/store/addon/-private/system/model/internal-model.ts @@ -19,7 +19,7 @@ import RecordArray from '../record-arrays/record-array'; import { RecordReference, BelongsToReference, HasManyReference } from '../references'; import RecordData from '../../ts-interfaces/record-data'; import { JsonApiResource, JsonApiValidationError } from '../../ts-interfaces/record-data-json-api'; -import { Record } from '../../ts-interfaces/record'; +import { RecordInstance } from '../../ts-interfaces/record'; import { ConfidentDict } from '../../ts-interfaces/utils'; import { IDENTIFIERS, @@ -799,7 +799,7 @@ export default class InternalModel { key: string, args: { promise: RSVP.Promise; - content?: Record | ManyArray | null; + content?: RecordInstance | ManyArray | null; _belongsToState?: BelongsToMetaWrapper; } ) { diff --git a/packages/store/addon/-private/system/references/record.ts b/packages/store/addon/-private/system/references/record.ts index 8c8ea8ba35a..c9deb72eb65 100644 --- a/packages/store/addon/-private/system/references/record.ts +++ b/packages/store/addon/-private/system/references/record.ts @@ -1,6 +1,6 @@ import RSVP, { resolve } from 'rsvp'; import Reference from './reference'; -import { Record } from '../../ts-interfaces/record'; +import { RecordInstance } from '../../ts-interfaces/record'; import { SingleResourceDocument } from '../../ts-interfaces/ember-data-json-api'; /** @@ -99,7 +99,7 @@ export default class RecordReference extends Reference { @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one @return a promise for the value (record or relationship) */ - push(objectOrPromise: SingleResourceDocument | Promise): RSVP.Promise { + push(objectOrPromise: SingleResourceDocument | Promise): RSVP.Promise { return resolve(objectOrPromise).then(data => { return this.store.push(data); }); diff --git a/packages/store/addon/-private/system/store/internal-model-factory.ts b/packages/store/addon/-private/system/store/internal-model-factory.ts index 4bc9d16829b..d17a3186021 100644 --- a/packages/store/addon/-private/system/store/internal-model-factory.ts +++ b/packages/store/addon/-private/system/store/internal-model-factory.ts @@ -6,7 +6,7 @@ import { StableRecordIdentifier } from '../../ts-interfaces/identifier'; import InternalModelMap from '../internal-model-map'; import { isNone } from '@ember/utils'; import { IDENTIFIERS } from '@ember-data/canary-features'; -import { Record } from '../../ts-interfaces/record'; +import { RecordInstance } from '../../ts-interfaces/record'; import { ResourceIdentifierObject, ExistingResourceObject, @@ -23,13 +23,13 @@ import constructResource from '../../utils/construct-resource'; const FactoryCache = new WeakMap(); type NewResourceInfo = { type: string; id: string | null }; -const RecordCache = new WeakMap(); +const RecordCache = new WeakMap(); export function peekRecordIdentifier(record: any): StableRecordIdentifier | undefined { return RecordCache.get(record); } -export function recordIdentifierFor(record: Record): StableRecordIdentifier { +export function recordIdentifierFor(record: RecordInstance): StableRecordIdentifier { let identifier = RecordCache.get(record); if (DEBUG && identifier === undefined) { @@ -39,7 +39,7 @@ export function recordIdentifierFor(record: Record): StableRecordIdentifier { return identifier as StableRecordIdentifier; } -export function setRecordIdentifier(record: Record, identifier: StableRecordIdentifier): void { +export function setRecordIdentifier(record: RecordInstance, identifier: StableRecordIdentifier): void { if (DEBUG && RecordCache.has(record)) { throw new Error(`${record} was already assigned an identifier`); } diff --git a/packages/store/addon/-private/ts-interfaces/ds-model.ts b/packages/store/addon/-private/ts-interfaces/ds-model.ts index 9b3349ca293..c9ab98d728b 100644 --- a/packages/store/addon/-private/ts-interfaces/ds-model.ts +++ b/packages/store/addon/-private/ts-interfaces/ds-model.ts @@ -1,11 +1,10 @@ -import { Record } from './record'; import RSVP from 'rsvp'; import EmberObject from '@ember/object'; import { JsonApiValidationError } from './record-data-json-api'; import { RelationshipSchema } from './record-data-schemas'; // Placeholder until model.js is typed -export interface DSModel extends Record, EmberObject { +export interface DSModel extends EmberObject { toString(): string; save(): RSVP.Promise; eachRelationship(callback: (key: string, meta: RelationshipSchema) => void): void; diff --git a/packages/store/addon/-private/ts-interfaces/record.ts b/packages/store/addon/-private/ts-interfaces/record.ts index d40b3260ec1..25e38f15a10 100644 --- a/packages/store/addon/-private/ts-interfaces/record.ts +++ b/packages/store/addon/-private/ts-interfaces/record.ts @@ -10,8 +10,7 @@ model instances (aka `Records`) are completely user supplied and opaque to the internals, we need a type through which to communicate what is valid. - The type belows allows for either a class instance, or an object, but not primitive values or functions. + The type belows allows for anything extending object. */ -// TODO Rename to RecordInstance -export type Record = Object; +export type RecordInstance = object;