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

port more types work over from #7585 #7954

Merged
merged 7 commits into from
Apr 16, 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
21 changes: 21 additions & 0 deletions packages/-ember-data/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ module.exports = function (defaults) {

const terserSettings = {
exclude: ['assets/dummy.js', 'assets/tests.js', 'assets/test-support.js', 'dist/docs/*', 'docs/*'],
terser: {
compress: {
ecma: 2016, // probably can be higher
passes: 6, // slow, but worth it
negate_iife: false,
sequences: 30,
defaults: true,
arguments: true,
keep_fargs: false,
toplevel: true,
unsafe: true,
unsafe_comps: true,
unsafe_math: true,
unsafe_symbols: true,
unsafe_proto: true,
unsafe_undefined: true,
},
toplevel: true,
sourceMap: false,
ecma: 2016,
},
};

if (isTest && isProd) {
Expand Down
33 changes: 17 additions & 16 deletions packages/-ember-data/node-tests/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ module.exports = {
'(private) @ember-data/serializer/rest RESTSerializer#_normalizeArray',
'(private) @ember-data/serializer/rest RESTSerializer#_normalizeResponse',
'(private) @ember-data/store AdapterPopulatedRecordArray#_setIdentifiers',
'(private) @ember-data/store Errors#_add',
'(private) @ember-data/store Errors#_clear',
'(private) @ember-data/store Errors#_findOrCreateMessages',
'(private) @ember-data/store Errors#_registerHandlers',
'(private) @ember-data/store Errors#_remove',
'(private) @ember-data/store Errors#content',
'(private) @ember-data/store Errors#errorsByAttributeName',
'(private) @ember-data/store Errors#unknownProperty',
'(private) @ember-data/model Errors#_add',
'(private) @ember-data/model Errors#_clear',
'(private) @ember-data/model Errors#_findOrCreateMessages',
'(private) @ember-data/model Errors#_registerHandlers',
'(private) @ember-data/model Errors#_remove',
'(private) @ember-data/model Errors#content',
'(private) @ember-data/model Errors#errorsByAttributeName',
'(private) @ember-data/model Errors#unknownProperty',
'(private) @ember-data/store IdentifierCache#__configureMerge',
'(private) @ember-data/store IdentifierCache#_getRecordIdentifier',
'(private) @ember-data/store IdentifierCache#_mergeRecordIdentifiers',
Expand Down Expand Up @@ -228,6 +228,7 @@ module.exports = {
'(public) @ember-data/serializer MinimumSerializerInterface#pushPayload [OPTIONAL]',
'(public) @ember-data/serializer MinimumSerializerInterface#serialize',
'(public) @ember-data/serializer MinimumSerializerInterface#serializeIntoHash [OPTIONAL]',
'(public) @ember-data/serializer MinimumSerializerInterface#destroy [OPTIONAL]',
'(public) @ember-data/serializer Serializer#normalize',
'(public) @ember-data/serializer Serializer#normalizeResponse',
'(public) @ember-data/serializer Serializer#serialize',
Expand Down Expand Up @@ -301,14 +302,14 @@ module.exports = {
'(public) @ember-data/store BelongsToReference#push',
'(public) @ember-data/store BelongsToReference#reload',
'(public) @ember-data/store BelongsToReference#value',
'(public) @ember-data/store Errors#add',
'(public) @ember-data/store Errors#clear',
'(public) @ember-data/store Errors#errorsFor',
'(public) @ember-data/store Errors#has',
'(public) @ember-data/store Errors#isEmpty',
'(public) @ember-data/store Errors#length',
'(public) @ember-data/store Errors#messages',
'(public) @ember-data/store Errors#remove',
'(public) @ember-data/model Errors#add',
'(public) @ember-data/model Errors#clear',
'(public) @ember-data/model Errors#errorsFor',
'(public) @ember-data/model Errors#has',
'(public) @ember-data/model Errors#isEmpty',
'(public) @ember-data/model Errors#length',
'(public) @ember-data/model Errors#messages',
'(public) @ember-data/model Errors#remove',
'(public) @ember-data/store HasManyReference#ids',
'(public) @ember-data/store HasManyReference#load',
'(public) @ember-data/store HasManyReference#push',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class TestRecordData implements RecordData {
// Use correct interface once imports have been fix
_storeWrapper: any;

pushData(data, calculateChange?: boolean) {}
pushData(data: object, calculateChange: true): string[];
pushData(data: object, calculateChange?: false): void;
pushData(data: object, calculateChange?: boolean): string[] | void {}

clientDidCreate() {}

willCommit() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class TestRecordData implements RecordData {
// Use correct interface once imports have been fix
_storeWrapper: any;

pushData(data, calculateChange?: boolean) {}
pushData(data: object, calculateChange: true): string[];
pushData(data: object, calculateChange?: false): void;
pushData(data: object, calculateChange?: boolean): string[] | void {}

clientDidCreate() {}

willCommit() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class TestRecordData {
// Use correct interface once imports have been fix
_storeWrapper: any;

pushData(data, calculateChange?: boolean) {}
pushData(data: object, calculateChange: true): string[];
pushData(data: object, calculateChange?: false): void;
pushData(data: object, calculateChange?: boolean): string[] | void {}

clientDidCreate() {}

willCommit() {}
Expand Down Expand Up @@ -208,7 +211,9 @@ module('integration/record-data - Custom RecordData Implementations', function (
let isNew = false;

class LifecycleRecordData extends TestRecordData {
pushData(data, calculateChange?: boolean) {
pushData(data: object, calculateChange: true): string[];
pushData(data: object, calculateChange?: false): void;
pushData(data: object, calculateChange?: boolean): string[] | void {
calledPush++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { setupTest } from 'ember-qunit';
import Model, { attr } from '@ember-data/model';
import JSONSerializer from '@ember-data/serializer/json';
import type Store from '@ember-data/store';
import { DSModel } from '@ember-data/store/-private/ts-interfaces/ds-model';
import type { RequestStateEnum } from '@ember-data/store/-private/ts-interfaces/fetch-manager';

class Person extends Model {
Expand Down Expand Up @@ -93,7 +94,7 @@ module('integration/request-state-service - Request State Service', function (ho
};
assert.deepEqual(request.request.data[0], requestOp, 'request op is correct');

let person = await promise;
let person = (await promise) as DSModel;
let lastRequest = requestService.getLastRequestForRecord(identifier);
let requestStateResult = {
type: 'query' as const,
Expand Down Expand Up @@ -216,7 +217,7 @@ module('integration/request-state-service - Request State Service', function (ho
count++;
});

let person = await store.findRecord('person', '1');
let person = (await store.findRecord('person', '1')) as DSModel;
await person.save();
assert.strictEqual(count, 4, 'callback called four times');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
AttributesSchema,
RelationshipsSchema,
} from '@ember-data/store/-private/ts-interfaces/record-data-schemas';
import { RecordInstance } from '@ember-data/store/-private/ts-interfaces/record-instance';
import type { SchemaDefinitionService } from '@ember-data/store/-private/ts-interfaces/schema-definition-service';

module('unit/model - Custom Class Model', function (hooks) {
Expand All @@ -25,8 +26,10 @@ module('unit/model - Custom Class Model', function (hooks) {
constructor(public store: Store) {
this.store = store;
}
save() {
return this.store.saveRecord(this);
// these types aren't correct but we don't have a registry to help
// make them correct yet
save(): Promise<RecordInstance> {
return this.store.saveRecord(this as unknown as RecordInstance);
}
}

Expand Down Expand Up @@ -287,7 +290,7 @@ module('unit/model - Custom Class Model', function (hooks) {
};
store.registerSchemaDefinitionService(schema);
let person = store.createRecord('person', { name: 'chris' });
await person.save();
await (person as unknown as Person).save();
});

test('hasModelFor with custom schema definition', async function (assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
setupTest(hooks);

test('default initial state', async function (assert) {
let recordArray = AdapterPopulatedRecordArray.create({ modelName: 'recordType' });
let recordArray = AdapterPopulatedRecordArray.create({
modelName: 'recordType',
isLoaded: false,
content: A(),
store: null,
});

assert.false(recordArray.get('isLoaded'), 'expected isLoaded to be false');
assert.strictEqual(recordArray.get('modelName'), 'recordType', 'has modelName');
Expand All @@ -38,7 +43,6 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
let recordArray = AdapterPopulatedRecordArray.create({
modelName: 'apple',
isLoaded: true,
isUpdating: true,
content,
store,
query: 'some-query',
Expand Down Expand Up @@ -83,6 +87,8 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
let recordArray = AdapterPopulatedRecordArray.create({
modelName: 'recordType',
store,
content: A(),
isLoaded: true,
query: 'some-query',
});

Expand All @@ -93,15 +99,14 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
let updateResult = recordArray.update();

assert.strictEqual(queryCalled, 1);

deferred.resolve('return value');
const expectedResult = A();
deferred.resolve(expectedResult);

assert.true(recordArray.get('isUpdating'), 'should be updating');

return updateResult.then((result) => {
assert.strictEqual(result, 'return value');
assert.false(recordArray.get('isUpdating'), 'should no longer be updating');
});
const result = await updateResult;
assert.strictEqual(result, expectedResult);
assert.false(recordArray.get('isUpdating'), 'should no longer be updating');
});

// TODO: is this method required, i suspect store._query should be refactor so this is not needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) {
setupTest(hooks);

test('default initial state', async function (assert) {
let recordArray = RecordArray.create({ modelName: 'recordType' });
let recordArray = RecordArray.create({ modelName: 'recordType', isLoaded: false, store: null });

assert.false(get(recordArray, 'isLoaded'), 'record is not loaded');
assert.false(get(recordArray, 'isUpdating'), 'record is not updating');
Expand All @@ -37,7 +37,6 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) {
let recordArray = RecordArray.create({
modelName: 'apple',
isLoaded: true,
isUpdating: true,
content,
store,
});
Expand Down
24 changes: 16 additions & 8 deletions packages/adapter/addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ import type { Snapshot } from '@ember-data/store/-private';
import type Store from '@ember-data/store/-private/system/core-store';
import type ShimModelClass from '@ember-data/store/-private/system/model/shim-model-class';
import type SnapshotRecordArray from '@ember-data/store/-private/system/snapshot-record-array';
import type MinimumAdapterInterface from '@ember-data/store/-private/ts-interfaces/minimum-adapter-interface';
import type {
AdapterPayload,
MinimumAdapterInterface,
} from '@ember-data/store/-private/ts-interfaces/minimum-adapter-interface';
import type { Dict } from '@ember-data/store/-private/ts-interfaces/utils';

/**
Expand Down Expand Up @@ -240,7 +243,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
findRecord(store: Store, type: ShimModelClass, id: string, snapshot: Snapshot): Promise<unknown> {
findRecord(store: Store, type: ShimModelClass, id: string, snapshot: Snapshot): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a findRecord override');
}
Expand Down Expand Up @@ -279,7 +282,12 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
findAll(store: Store, type: ShimModelClass, neverSet, snapshotRecordArray: SnapshotRecordArray): Promise<unknown> {
findAll(
store: Store,
type: ShimModelClass,
neverSet,
snapshotRecordArray: SnapshotRecordArray
): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a findAll override');
}
Expand Down Expand Up @@ -319,7 +327,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
query(store: Store, type: ShimModelClass, query): Promise<unknown> {
query(store: Store, type: ShimModelClass, query): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a query override');
}
Expand Down Expand Up @@ -365,7 +373,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
queryRecord(store: Store, type: ShimModelClass, query, adapterOptions): Promise<unknown> {
queryRecord(store: Store, type: ShimModelClass, query, adapterOptions): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a queryRecord override');
}
Expand Down Expand Up @@ -477,7 +485,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
createRecord(store: Store, type: ShimModelClass, snapshot: Snapshot): Promise<unknown> {
createRecord(store: Store, type: ShimModelClass, snapshot: Snapshot): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a createRecord override');
}
Expand Down Expand Up @@ -536,7 +544,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
updateRecord(store: Store, type: ShimModelClass, snapshot: Snapshot): Promise<unknown> {
updateRecord(store: Store, type: ShimModelClass, snapshot: Snapshot): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a updateRecord override');
}
Expand Down Expand Up @@ -587,7 +595,7 @@ export default class Adapter extends EmberObject implements MinimumAdapterInterf
@return {Promise} promise
@public
*/
deleteRecord(store: Store, type: ShimModelClass, snapshot: Snapshot): Promise<unknown> {
deleteRecord(store: Store, type: ShimModelClass, snapshot: Snapshot): Promise<AdapterPayload> {
if (DEBUG) {
throw new Error('You subclassed the Adapter class but missing a deleteRecord override');
}
Expand Down
5 changes: 3 additions & 2 deletions packages/adapter/addon/json-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { pluralize } from 'ember-inflector';
import type Store from '@ember-data/store';
import type ShimModelClass from '@ember-data/store/-private/system/model/shim-model-class';
import type Snapshot from '@ember-data/store/-private/system/snapshot';
import { AdapterPayload } from '@ember-data/store/-private/ts-interfaces/minimum-adapter-interface';

import { serializeIntoHash } from './-private';
import type { FetchRequestInit, JQueryRequestInit } from './rest';
Expand Down Expand Up @@ -242,7 +243,7 @@ class JSONAPIAdapter extends RESTAdapter {
this._coalesceFindRequests = value;
}

findMany(store: Store, type: ShimModelClass, ids: string[], snapshots: Snapshot[]): Promise<unknown> {
findMany(store: Store, type: ShimModelClass, ids: string[], snapshots: Snapshot[]): Promise<AdapterPayload> {
let url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } });
}
Expand All @@ -252,7 +253,7 @@ class JSONAPIAdapter extends RESTAdapter {
return pluralize(dasherized);
}

updateRecord(store: Store, schema: ShimModelClass, snapshot: Snapshot): Promise<unknown> {
updateRecord(store: Store, schema: ShimModelClass, snapshot: Snapshot): Promise<AdapterPayload> {
const data = serializeIntoHash(store, schema, snapshot);
const type = snapshot.modelName;
const id = snapshot.id;
Expand Down
Loading