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] redivide assets to move record-data into package #6513

Merged
merged 7 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions packages/-ember-data/addon/-private/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ export {
InternalModel,
ManyArray,
PromiseArray,
Relationship,
PromiseManyArray,
PromiseObject,
RecordData,
RecordArray,
RecordArrayManager,
RootState,
SnapshotRecordArray,
recordDataFor,
relationshipStateFor,
relationshipsFor,
normalizeModelName,
coerceId,
} from '@ember-data/store/-private';
export { RecordData, Relationship } from '@ember-data/record-data/-private';
3 changes: 2 additions & 1 deletion packages/-ember-data/addon/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VERSION } from '@ember/version';
import EmberError from '@ember/error';
import Store from './store';

if (VERSION.match(/^1\.([0-9]|1[0-2])\./)) {
throw new EmberError(
Expand All @@ -9,7 +10,7 @@ if (VERSION.match(/^1\.([0-9]|1[0-2])\./)) {
);
}

import Store, { normalizeModelName } from '@ember-data/store';
import { normalizeModelName } from '@ember-data/store';
import DebugAdapter from '@ember-data/debug';

import {
Expand Down
22 changes: 21 additions & 1 deletion packages/-ember-data/addon/store.ts
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
export { default } from '@ember-data/store';
import Store from '@ember-data/store';
import { RecordData } from '@ember-data/record-data/-private';
import { identifierCacheFor } from '@ember-data/store/-private';
import { IDENTIFIERS } from '@ember-data/canary-features';
runspired marked this conversation as resolved.
Show resolved Hide resolved

type RecordDataStoreWrapper = import('@ember-data/store/-private/ts-interfaces/record-data-store-wrapper').RecordDataStoreWrapper;
runspired marked this conversation as resolved.
Show resolved Hide resolved

export default class DefaultStore extends Store {
createRecordDataFor(modelName: string, id: string | null, clientId: string, storeWrapper: RecordDataStoreWrapper) {
if (IDENTIFIERS) {
let identifier = identifierCacheFor(this).getOrCreateRecordIdentifier({
type: modelName,
id,
lid: clientId,
});
return new RecordData(identifier, storeWrapper);
} else {
return new RecordData(modelName, id, clientId, storeWrapper);
}
}
}
1 change: 1 addition & 0 deletions packages/-ember-data/app/services/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-data/store';
8 changes: 7 additions & 1 deletion packages/-ember-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ const merge = require('broccoli-merge-trees');
module.exports = Object.assign({}, addonBaseConfig, {
shouldRollupPrivate: true,
externalDependenciesForPrivateModule() {
return ['ember-data/version', '@ember-data/store/-private', '@ember-data/store', '@ember-data/model'];
return [
'@ember-data/record-data/-private',
'ember-data/version',
'@ember-data/store/-private',
'@ember-data/store',
'@ember-data/model',
];
},
treeForAddon(tree) {
tree = merge([tree, version()]);
Expand Down
1 change: 1 addition & 0 deletions packages/-ember-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@ember-data/adapter": "3.15.0-alpha.0",
"@ember-data/debug": "3.15.0-alpha.0",
"@ember-data/model": "3.15.0-alpha.0",
"@ember-data/record-data": "3.15.0-alpha.0",
"@ember-data/serializer": "3.15.0-alpha.0",
"@ember-data/store": "3.15.0-alpha.0",
"@ember/ordered-set": "^2.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ if (IDENTIFIERS) {
name: 'callback-hell',
},
relationships: {
retainer: { type: 'retainer', id: '1' },
retainer: { data: { type: 'retainer', id: '1' } },
runspired marked this conversation as resolved.
Show resolved Hide resolved
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { run } from '@ember/runloop';
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { get } from '@ember/object';
import Store from '@ember-data/store';
// we intentionally test against the ember-data version here
runspired marked this conversation as resolved.
Show resolved Hide resolved
import Store from 'ember-data/store';
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import RESTSerializer, { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
import RESTAdapter from '@ember-data/adapter/rest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { setupTest } from 'ember-qunit';
import Model from '@ember-data/model';
import { run } from '@ember/runloop';
import { assign } from '@ember/polyfills';
import { RecordData, recordDataFor } from 'ember-data/-private';
import { recordDataFor } from '@ember-data/store/-private';
import { RecordData } from '@ember-data/record-data/-private';
import { resolve } from 'rsvp';
import { attr, hasMany, belongsTo } from '@ember-data/model';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import DS from 'ember-data';
import { setupTest } from 'ember-qunit';
import { recordDataFor } from 'ember-data/-private';
import { recordDataFor } from '@ember-data/store/-private';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import JSONAPISerializer from '@ember-data/serializer/json-api';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Store from '@ember-data/store';
import Model from '@ember-data/model';
import testInDebug from 'dummy/tests/helpers/test-in-debug';
import DS from 'ember-data';
import { RecordData, recordDataFor, relationshipsFor, relationshipStateFor } from '@ember-data/store/-private';
import { identifierCacheFor } from '@ember-data/store/-private';
import { RecordData, relationshipsFor, relationshipStateFor } from '@ember-data/record-data/-private';
import { identifierCacheFor, recordDataFor } from '@ember-data/store/-private';
import { IDENTIFIERS } from '@ember-data/canary-features';
import { setupContext, teardownContext } from '@ember/test-helpers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { setupTest } from 'ember-qunit';
import testInDebug from 'dummy/tests/helpers/test-in-debug';
import { deprecatedTest } from 'dummy/tests/helpers/deprecated-test';
import { module, test } from 'qunit';
import { relationshipStateFor, relationshipsFor } from 'ember-data/-private';
import { relationshipStateFor, relationshipsFor } from '@ember-data/record-data/-private';

import Adapter from '@ember-data/adapter';
import JSONAPISerializer from '@ember-data/serializer/json-api';
Expand Down
2 changes: 1 addition & 1 deletion packages/-ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import JSONAPIAdapter from '@ember-data/adapter/json-api';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import JSONSerializer from '@ember-data/serializer/json';
import { attr as DSattr } from '@ember-data/model';
import { recordDataFor } from 'ember-data/-private';
import { recordDataFor } from '@ember-data/store/-private';
import { attr, hasMany, belongsTo } from '@ember-data/model';
import { gte } from 'ember-compatibility-helpers';

Expand Down
5 changes: 3 additions & 2 deletions packages/-ember-data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"@ember-data/model/*": ["../model/addon/*"],
"@ember-data/adapter": ["../adapter/addon"],
"@ember-data/adapter/*": ["../adapter/addon/*"],
"@ember-data/adapter/error": ["../adapter/addon/error"],
runspired marked this conversation as resolved.
Show resolved Hide resolved
"@ember-data/serializer": ["../serializer/addon"],
"@ember-data/serializer/*": ["../serializer/addon/*"],
"ember-data/test-support": ["addon-test-support"],
"ember-data/test-support/*": ["addon-test-support/*"],
"@ember-data/adapter/error": ["../adapter/addon/error"],
"@ember-data/record-data/*": ["../record-data/addon/*"],
"@ember-data/canary-features": ["../canary-features/addon"],
"*": ["../store/types/*"]
"*": ["../store/types/*", "../record-data/types/*"]
}
},
"include": ["app/**/*", "addon/**/*", "tests/**/*", "types/**/*", "test-support/**/*", "addon-test-support/**/*"],
Expand Down
1 change: 1 addition & 0 deletions packages/-record-data-encapsulation-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@ember-data/serializer": "3.15.0-alpha.0",
"@ember-data/model": "3.15.0-alpha.0",
"@ember-data/store": "3.15.0-alpha.0",
"@ember-data/debug": "3.15.0-alpha.0",
"ember-inflector": "^3.0.1"
},
"devDependencies": {
Expand Down
19 changes: 19 additions & 0 deletions packages/-serializer-encapsulation-test-app/app/services/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Store from '@ember-data/store';
runspired marked this conversation as resolved.
Show resolved Hide resolved
import { RecordData } from '@ember-data/record-data/-private';
import { identifierCacheFor } from '@ember-data/store/-private';
import { IDENTIFIERS } from '@ember-data/canary-features';

export default class DefaultStore extends Store {
createRecordDataFor(modelName, id, clientId, storeWrapper) {
if (IDENTIFIERS) {
let identifier = identifierCacheFor(this).getOrCreateRecordIdentifier({
type: modelName,
id,
lid: clientId,
});
return new RecordData(identifier, storeWrapper);
} else {
return new RecordData(modelName, id, clientId, storeWrapper);
}
}
}
1 change: 1 addition & 0 deletions packages/-serializer-encapsulation-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@ember-data/adapter": "3.15.0-alpha.0",
"@ember-data/model": "3.15.0-alpha.0",
"@ember-data/store": "3.15.0-alpha.0",
"@ember-data/record-data": "3.15.0-alpha.0",
"ember-inflector": "^3.0.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Model, { attr } from '@ember-data/model';
import Store from '@ember-data/store';
import Store from 'serializer-encapsulation-test-app/services/store';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import EmberObject from '@ember/object';
import { setupTest } from 'ember-qunit';
Expand Down Expand Up @@ -27,7 +27,7 @@ class Person extends Model {
}
}

module('inteegration/create-record - running createRecord with minimum serializer', function(hooks) {
module('integration/create-record - running createRecord with minimum serializer', function(hooks) {
setupTest(hooks);

hooks.beforeEach(function(assert) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Model, { attr } from '@ember-data/model';
import Store from '@ember-data/store';
import Store from 'serializer-encapsulation-test-app/services/store';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import EmberObject from '@ember/object';
import { setupTest } from 'ember-qunit';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { resolve } from 'rsvp';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import Store from '@ember-data/store';
import Store from 'serializer-encapsulation-test-app/services/store';
import Model, { attr, hasMany, belongsTo } from '@ember-data/model';
import EmberObject from '@ember/object';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Model, { attr } from '@ember-data/model';
import Store from '@ember-data/store';
import Store from 'serializer-encapsulation-test-app/services/store';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import EmberObject from '@ember/object';
import { setupTest } from 'ember-qunit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Model, { attr } from '@ember-data/model';
import Store from '@ember-data/store';
import Store from 'serializer-encapsulation-test-app/services/store';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import EmberObject from '@ember/object';
import { setupTest } from 'ember-qunit';
Expand Down Expand Up @@ -27,7 +27,7 @@ class Person extends Model {
}
}

module('inteegration/create-record - running createRecord with minimum serializer', function(hooks) {
module('integration/create-record - running createRecord with minimum serializer', function(hooks) {
setupTest(hooks);

hooks.beforeEach(function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion packages/debug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Provides developer ergonomics and dev-mode enhancements for apps built with Embe
## Installation

```
ember install @ember-data/record-data
ember install @ember-data/debug
```

## Usage
Expand Down
4 changes: 2 additions & 2 deletions packages/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"test:all": "ember try:each"
},
"dependencies": {
"@ember-data/-build-infra": "3.14.0-alpha.4",
"@ember-data/-build-infra": "3.15.0-alpha.0",
"@ember/edition-utils": "^1.1.1",
"ember-cli-babel": "^7.12.0",
"ember-cli-test-info": "^1.0.0",
"ember-cli-typescript": "^3.0.0"
},
"devDependencies": {
"@ember-data/-test-infra": "3.14.0-alpha.4",
"@ember-data/-test-infra": "3.15.0-alpha.0",
"@ember/optional-features": "^0.7.0",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "^3.13.1",
Expand Down
39 changes: 39 additions & 0 deletions packages/record-data/addon/-private/coerce-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { DEBUG } from '@glimmer/env';

// Used by the store to normalize IDs entering the store. Despite the fact
// that developers may provide IDs as numbers (e.g., `store.findRecord('person', 1)`),
// it is important that internally we use strings, since IDs may be serialized
// and lose type information. For example, Ember's router may put a record's
// ID into the URL, and if we later try to deserialize that URL and find the
// corresponding record, we will not know if it is a string or a number.
type Coercable = string | number | boolean | null | undefined | symbol;

function coerceId(id: Coercable): string | null {
if (id === null || id === undefined || id === '') {
return null;
}
if (typeof id === 'string') {
return id;
}
if (typeof id === 'symbol') {
return id.toString();
}
return '' + id;
}

export function ensureStringId(id: Coercable): string {
let normalized: string | null = null;
if (typeof id === 'string') {
normalized = id.length > 0 ? id : null;
} else if (typeof id === 'number' && !isNaN(id)) {
normalized = '' + id;
}

if (DEBUG && normalized === null) {
runspired marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`Expected id to be a string or number, recieved ${String(id)}`);
}

return normalized!;
}

export default coerceId;
5 changes: 5 additions & 0 deletions packages/record-data/addon/-private/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { default as RecordData } from './record-data';
export { default as Relationship } from './relationships/state/relationship';
export { default as BelongsToRelationship } from './relationships/state/belongs-to';
export { default as ManyRelationship } from './relationships/state/has-many';
export { relationshipStateFor, relationshipsFor } from './record-data-for';
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/**
@module @ember-data/store
*/

/*
This method normalizes a link to an "links object". If the passed link is
already an object it's returned without any modifications.

See http://jsonapi.org/format/#document-links for more information.

@method _normalizeLink
@private
@internal
runspired marked this conversation as resolved.
Show resolved Hide resolved
@param {String} link
@return {Object|null}
*/
export default function _normalizeLink(link) {
type Link = import('@ember-data/store/-private/ts-interfaces/ember-data-json-api').Link;
runspired marked this conversation as resolved.
Show resolved Hide resolved
type LinkObject = import('@ember-data/store/-private/ts-interfaces/ember-data-json-api').LinkObject;

export default function _normalizeLink(link: Link): LinkObject | null {
switch (typeof link) {
case 'object':
return link;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import EmberOrderedSet from '@ember/ordered-set';
import { guidFor } from '@ember/object/internals';

/**
@module @ember-data/store
*/

export default class EmberDataOrderedSet<T> extends EmberOrderedSet<T> {
static create() {
return new this();
Expand Down
21 changes: 21 additions & 0 deletions packages/record-data/addon/-private/record-data-for.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { recordDataFor } from '@ember-data/store/-private';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my overall comment on recordDataFor – we should be able to use the types defined in that approach to strengthen these and thereby eliminate the use of any here, which will make these functions much more reliable.


export function relationshipsFor(instance: any) {
let recordData = recordDataFor(instance) || instance;

return recordData._relationships;
}

export function relationshipStateFor(instance: any, propertyName: string) {
return relationshipsFor(instance).get(propertyName);
}

export function implicitRelationshipsFor(instance: any) {
let recordData = recordDataFor(instance) || instance;

return recordData.__implicitRelationships;
}

export function implicitRelationshipStateFor(instance: any, propertyName: string) {
return implicitRelationshipsFor(instance)[propertyName];
}
Loading