Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] rename Record to RecordInstance #6763

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-instance';
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-instance';
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-instance';
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-instance';
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
4 changes: 2 additions & 2 deletions packages/store/addon/-private/ts-interfaces/ds-model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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';
import { RecordInstance } from './record-instance';

// Placeholder until model.js is typed
export interface DSModel extends Record, EmberObject {
export interface DSModel extends RecordInstance, EmberObject {
toString(): string;
save(): RSVP.Promise<DSModel>;
eachRelationship(callback: (key: string, meta: RelationshipSchema) => void): void;
Expand Down
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;