Skip to content

Commit

Permalink
rename Record to RecordInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Nov 19, 2019
1 parent 9048531 commit e5be474
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
20 changes: 10 additions & 10 deletions packages/store/addon/-private/system/core-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -3033,7 +3033,7 @@ abstract class CoreStore extends Service {
return internalModelFactoryFor(this).lookup(resource);
}

serializeRecord(record: Record, options?: Dict<unknown>): unknown {
serializeRecord(record: RecordInstance, options?: Dict<unknown>): unknown {
if (CUSTOM_MODEL_CLASS) {
let identifier = recordIdentifierFor(record);
let internalModel = internalModelFactoryFor(this).peek(identifier);
Expand All @@ -3044,7 +3044,7 @@ abstract class CoreStore extends Service {
}
}

saveRecord(record: Record, options?: Dict<unknown>): RSVP.Promise<Record> {
saveRecord(record: RecordInstance, options?: Dict<unknown>): RSVP.Promise<RecordInstance> {
if (CUSTOM_MODEL_CLASS) {
let identifier = recordIdentifierFor(record);
let internalModel = internalModelFactoryFor(this).peek(identifier);
Expand Down
4 changes: 2 additions & 2 deletions packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -799,7 +799,7 @@ export default class InternalModel {
key: string,
args: {
promise: RSVP.Promise<any>;
content?: Record | ManyArray | null;
content?: RecordInstance | ManyArray | null;
_belongsToState?: BelongsToMetaWrapper;
}
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/store/addon/-private/system/references/record.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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<SingleResourceDocument>): RSVP.Promise<Record> {
push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): RSVP.Promise<RecordInstance> {
return resolve(objectOrPromise).then(data => {
return this.store.push(data);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,13 +23,13 @@ import constructResource from '../../utils/construct-resource';
const FactoryCache = new WeakMap<CoreStore, InternalModelFactory>();
type NewResourceInfo = { type: string; id: string | null };

const RecordCache = new WeakMap<Record, StableRecordIdentifier>();
const RecordCache = new WeakMap<RecordInstance, StableRecordIdentifier>();

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) {
Expand All @@ -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`);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/store/addon/-private/ts-interfaces/ds-model.ts
Original file line number Diff line number Diff line change
@@ -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<DSModel>;
eachRelationship(callback: (key: string, meta: RelationshipSchema) => void): void;
Expand Down
5 changes: 2 additions & 3 deletions packages/store/addon/-private/ts-interfaces/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit e5be474

Please sign in to comment.