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

deprecation: implement helper deprecations #8093

Merged
merged 9 commits into from
Jul 31, 2022
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
11 changes: 5 additions & 6 deletions ember-data-types/q/record-data-json-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CollectionResourceRelationship, SingleResourceRelationship } from './ember-data-json-api';
import type { CollectionResourceRelationship, Links, Meta, SingleResourceRelationship } from './ember-data-json-api';
import type { Dict } from './utils';

/**
Expand All @@ -10,12 +10,11 @@ export type AttributesHash = Dict<unknown>;
export interface JsonApiResource {
id?: string | null;
type?: string;
attributes?: AttributesHash;
relationships?: {
[key: string]: SingleResourceRelationship | CollectionResourceRelationship;
};
meta?: any;
lid?: string;
attributes?: AttributesHash;
relationships?: Dict<SingleResourceRelationship | CollectionResourceRelationship>;
meta?: Meta;
links?: Links;
}

export interface JsonApiValidationError {
Expand Down
7 changes: 1 addition & 6 deletions ember-data-types/q/record-data-record-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ export interface RecordDataRecordWrapper {
hasAttr(key: string): boolean;

// new
getErrors?(recordIdentifier: RecordIdentifier): JsonApiValidationError[];
/**
* @internal
* @deprecated
*/
getErrors?({}): JsonApiValidationError[]; // eslint-disable-line no-empty-pattern
getErrors(recordIdentifier: RecordIdentifier): JsonApiValidationError[];

isNew?(): boolean;
isDeleted?(): boolean;
Expand Down
7 changes: 1 addition & 6 deletions ember-data-types/q/record-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ export interface RecordData {
_initRecordCreateOptions(options: any): { [key: string]: unknown };

// new
getErrors?(recordIdentifier: RecordIdentifier): JsonApiValidationError[];
/**
* @deprecated
* @internal
*/
getErrors?({}): JsonApiValidationError[]; // eslint-disable-line no-empty-pattern
getErrors(recordIdentifier: RecordIdentifier): JsonApiValidationError[];

isNew?(): boolean;
isDeleted?(): boolean;
Expand Down
48 changes: 48 additions & 0 deletions packages/-ember-data/tests/deprecations/deprecate-helpers-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { module } from 'qunit';

import { setupTest } from 'ember-qunit';

import { errorsArrayToHash, errorsHashToArray } from '@ember-data/adapter/error';
import { normalizeModelName } from '@ember-data/store';
import { normalizeModelName as _privateNormalize } from '@ember-data/store/-private';
import { deprecatedTest } from '@ember-data/unpublished-test-infra/test-support/deprecated-test';

module('Deprecations', function (hooks) {
setupTest(hooks);

deprecatedTest(
`Calling normalizeModelName`,
{ id: 'ember-data:deprecate-normalize-modelname-helper', until: '5.0', count: 1 },
function (assert) {
normalizeModelName('user');
assert.ok(true);
}
);

deprecatedTest(
`Calling normalizeModelName imported from private`,
{ id: 'ember-data:deprecate-normalize-modelname-helper', until: '5.0', count: 1 },
function (assert) {
_privateNormalize('user');
assert.ok(true);
}
);

deprecatedTest(
`Calling errorsArrayToHash`,
{ id: 'ember-data:deprecate-errors-array-to-hash-helper', until: '5.0', count: 1 },
function (assert) {
errorsArrayToHash([]);
assert.ok(true);
}
);

deprecatedTest(
`Calling errorsHashToArray`,
{ id: 'ember-data:deprecate-errors-hash-to-array-helper', until: '5.0', count: 1 },
function (assert) {
errorsHashToArray({});
assert.ok(true);
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module('integration/adapter/store-adapter - client-side delete', function (hooks

test('client-side deleted records can be added back from an inverse', async function (assert) {
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

class Bookstore extends Model {
@attr name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function
let { owner } = this;

owner.register('model:person', Person);
owner.register('serializer:application', JSONAPISerializer.extend());
owner.register('serializer:application', class extends JSONAPISerializer {});

store = owner.lookup('service:store');
});
Expand Down
20 changes: 10 additions & 10 deletions packages/-ember-data/tests/integration/adapter/find-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

const store = this.owner.lookup('service:store');

Expand All @@ -40,7 +40,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let count = 0;

Expand All @@ -64,7 +64,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {
},
})
);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

const store = this.owner.lookup('service:store');

Expand All @@ -79,7 +79,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let resolveFindRecordPromise;
let findRecordPromise = new Promise((resolve) => (resolveFindRecordPromise = resolve));
Expand Down Expand Up @@ -125,7 +125,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register(
'adapter:person',
Adapter.extend({
Expand All @@ -152,7 +152,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register(
'adapter:person',
Adapter.extend({
Expand Down Expand Up @@ -180,7 +180,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register(
'adapter:person',
Adapter.extend({
Expand Down Expand Up @@ -208,7 +208,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register(
'adapter:person',
Adapter.extend({
Expand Down Expand Up @@ -237,7 +237,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register(
'adapter:person',
Adapter.extend({
Expand Down Expand Up @@ -269,7 +269,7 @@ module('integration/adapter/find - Finding Records', function (hooks) {

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register(
'serializer:application',
JSONAPISerializer.extend({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { module, test } from 'qunit';
import { resolve } from 'rsvp';

import DS from 'ember-data';
import { setupTest } from 'ember-qunit';

import JSONAPIAdapter from '@ember-data/adapter/json-api';
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug';

let store, adapter;
Expand Down Expand Up @@ -58,8 +59,8 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks)
@attr('number') hipsters;
}

this.owner.register('adapter:application', DS.JSONAPIAdapter.extend());
this.owner.register('serializer:application', DS.JSONAPISerializer.extend());
this.owner.register('adapter:application', class extends JSONAPIAdapter {});
this.owner.register('serializer:application', class extends JSONAPISerializer {});

this.owner.register('model:user', User);
this.owner.register('model:post', Post);
Expand Down Expand Up @@ -922,11 +923,11 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks)

this.owner.register(
'serializer:user',
DS.JSONAPISerializer.extend({
attrs: {
class extends JSONAPISerializer {
attrs = {
handles: { serialize: true },
},
})
};
}
);

let user = store.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module('integration/adapter/queries - Queries', function (hooks) {

hooks.beforeEach(function () {
this.owner.register('adapter:application', JSONAPIAdapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
});

testInDebug('It raises an assertion when no type is passed', function (assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down Expand Up @@ -70,7 +70,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down Expand Up @@ -106,7 +106,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down Expand Up @@ -140,7 +140,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down Expand Up @@ -186,7 +186,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down Expand Up @@ -283,7 +283,7 @@ module('integration/adapter/record_persistence - Persisting Records', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module('integration/adapter/serialize - DS.Adapter integration test', function (

this.owner.register('model:person', Person);
this.owner.register('adapter:application', Adapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});

let store = this.owner.lookup('service:store');
let adapter = store.adapterFor('application');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function moveRecordOutOfInFlight(record) {
let { store, _internalModel } = record;
// TODO this would be made nicer by a cancellation API
let pending = store.getRequestStateService().getPendingRequestsForRecord(_internalModel.identifier);
pending.splice(0, pending.length); // release the requests
_internalModel.adapterDidError(new Error());
pending.splice(0, pending.length);
}

module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test', function (hooks) {
Expand All @@ -39,7 +38,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration
}

this.owner.register('adapter:application', JSONAPIAdapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
this.owner.register('model:person', Person);
this.owner.register('model:dog', Dog);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module(

this.owner.register('model:post-note', PostNote);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
});

test('can lookup records using camelCase strings', function (assert) {
Expand Down Expand Up @@ -110,7 +110,7 @@ module(
this.owner.register('model:note-post', NotePost);
this.owner.register('model:post-note', PostNote);
this.owner.register('adapter:application', ApplicationAdapter);
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
});

test('looks up belongsTo using camelCase strings', function (assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module('integration - Client Id Generation', function (hooks) {
owner.register('model:post', Post);
owner.register('model:misc', Misc);
owner.register('adapter:application', JSONAPIAdapter.extend());
owner.register('serializer:application', JSONAPISerializer.extend());
owner.register('serializer:application', class extends JSONAPISerializer {});

store = owner.lookup('service:store');
adapter = store.adapterFor('application');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module('Integration | Identifiers - configuration', function (hooks) {
const { owner } = this;

owner.register('adapter:application', JSONAPIAdapter.extend());
owner.register('serializer:application', JSONAPISerializer.extend());
owner.register('serializer:application', class extends JSONAPISerializer {});
class User extends Model {
@attr()
declare firstName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module('unit/record-array - RecordArray', function (hooks) {
owner.register('model:tag', Tag);
owner.register('model:tool', Tool);
owner.register('adapter:application', JSONAPIAdapter.extend());
owner.register('serializer:application', JSONAPISerializer.extend());
owner.register('serializer:application', class extends JSONAPISerializer {});

store = owner.lookup('service:store');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula
hooks.beforeEach(function () {
this.owner.register('model:person', Person);
this.owner.register('adapter:application', JSONAPIAdapter.extend());
this.owner.register('serializer:application', JSONAPISerializer.extend());
this.owner.register('serializer:application', class extends JSONAPISerializer {});
});

test('when a record is deleted in an adapter populated record array, it should be removed', async function (assert) {
Expand Down
Loading