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]: TypeScript adapters #7358

Merged
merged 56 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
02ef2d7
[Chore]: ts adapters
snewcomer Oct 23, 2020
99747b7
interface should be on base class
snewcomer Oct 23, 2020
60496a2
add back extend
snewcomer Oct 30, 2020
4115108
mixin to ts
snewcomer Oct 30, 2020
fe3e1e4
finish up ts conversion
snewcomer Oct 31, 2020
74a1409
Revert "types/ember update"
snewcomer Oct 31, 2020
04ee267
some more casting
snewcomer Nov 2, 2020
b1f0cfd
whoops writable
snewcomer Nov 2, 2020
9618dc8
fix jquery in typescript
snewcomer Nov 2, 2020
551330c
just set useFetch instead of non ie11 compat version
snewcomer Nov 2, 2020
67a8327
textStatus(jquery) => statusText(Response)
snewcomer Nov 2, 2020
aa61154
create js util for jquery
snewcomer Nov 3, 2020
76a5483
Add global definition jQuery
snewcomer Nov 5, 2020
1973a25
add globals for jQuery. I thought this didnt work
snewcomer Nov 5, 2020
1e9d4d7
v0.0.0
snewcomer Nov 5, 2020
d9d74bd
get off window
snewcomer Nov 9, 2020
6d2d1e8
improvements
snewcomer Nov 9, 2020
870f16c
Lets try simplest route with ts first
snewcomer Nov 9, 2020
8f88b80
fix test error
snewcomer Nov 10, 2020
d4be51e
do not assign useFetch in constructor body
snewcomer Nov 10, 2020
55960a6
more as any to prevent assigning in body of constructor
snewcomer Nov 10, 2020
52eab28
moar types
snewcomer Nov 10, 2020
4993089
another constructor body issue
snewcomer Nov 10, 2020
454b515
remove fastboot off of constructor
snewcomer Nov 11, 2020
5d22295
add computed
snewcomer Nov 11, 2020
945f097
Address feedback
snewcomer Nov 24, 2020
2a0ac82
revert
snewcomer Dec 3, 2020
255dad7
declare useFetch
snewcomer Dec 3, 2020
4041fb4
declare _fastboot
snewcomer Dec 3, 2020
fcee91a
declare _najaxRequest
snewcomer Dec 3, 2020
b857533
declare headers
snewcomer Dec 3, 2020
60576f1
_najaxRequest is a Function
snewcomer Dec 3, 2020
16e6684
Perhaps we dont need these
snewcomer Dec 3, 2020
c1dc782
Minor refactors to najax and jQuery
snewcomer Dec 3, 2020
ba8facd
Slim down fastboot interface to only used known properties
snewcomer Dec 5, 2020
858fa3e
address feedback
snewcomer Dec 10, 2020
0c313c3
typo fix
snewcomer Dec 10, 2020
db04a0b
alias rsvp promise as RSVPPromise
snewcomer Dec 10, 2020
dec5296
ConfidentDict => Dict
snewcomer Dec 11, 2020
9ea712e
Add FetchRequestInit interface
snewcomer Dec 11, 2020
7ca81e3
no cast for Promise. error returns back to calleer
snewcomer Dec 11, 2020
76315d5
remove cast for payload and just add an if check. we do not want to J…
snewcomer Dec 11, 2020
4028ba7
Clearer typing delineation between fetch and ajax paths
snewcomer Dec 11, 2020
820bde5
Cleanup of payload
igorT Jan 20, 2021
c6e1515
request types but with cache problem
igorT Jan 20, 2021
d6c1496
cleanup fetchRequest by setting it to any
igorT Jan 20, 2021
4036fb7
Fix lint
snewcomer Jan 20, 2021
7d8fbc7
cleanup anys in build-url-mixin
igorT Jan 21, 2021
ecbc13a
ajax options temp cleanup
igorT Jan 21, 2021
ad3b199
cleanup ajax types
igorT Jan 28, 2021
1c61991
any clenaup
igorT Jan 28, 2021
3343cef
jquery type
igorT Jan 28, 2021
64f6959
lint
igorT Jan 28, 2021
8a2e21d
fix jquery type
igorT Feb 3, 2021
759c470
fix FetchRequestData type for determineBodyPromise
Feb 4, 2021
98784c5
ajax settings => jquery request init
Feb 4, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module('Integration | Identifiers - scenarios', function(hooks) {
module('Secondary Cache based on an attribute', function(hooks) {
let store;
let calls;
let isQuery = false;
let secondaryCache: {
id: ConfidentDict<string>;
username: ConfidentDict<string>;
Expand All @@ -44,10 +45,11 @@ module('Integration | Identifiers - scenarios', function(hooks) {
shouldBackgroundReloadRecord() {
return false;
}
findRecord(isQuery = false) {
findRecord() {
if (isQuery !== true) {
calls.findRecord++;
}
isQuery = false;
return resolve({
data: {
id: '1',
Expand All @@ -62,7 +64,8 @@ module('Integration | Identifiers - scenarios', function(hooks) {
}
queryRecord() {
calls.queryRecord++;
return this.findRecord(true);
isQuery = true;
return this.findRecord();
}
}

Expand Down Expand Up @@ -234,6 +237,7 @@ module('Integration | Identifiers - scenarios', function(hooks) {
module('Secondary Cache using an attribute as an alternate id', function(hooks) {
let store;
let calls;
let isQuery = false;
let secondaryCache: ConfidentDict<string>;
class TestSerializer extends Serializer {
normalizeResponse(_, __, payload) {
Expand All @@ -244,10 +248,11 @@ module('Integration | Identifiers - scenarios', function(hooks) {
shouldBackgroundReloadRecord() {
return false;
}
findRecord(isQuery = false) {
findRecord() {
if (isQuery !== true) {
calls.findRecord++;
}
isQuery = false;
return resolve({
data: {
id: '1',
Expand All @@ -262,7 +267,8 @@ module('Integration | Identifiers - scenarios', function(hooks) {
}
queryRecord() {
calls.queryRecord++;
return this.findRecord(true);
isQuery = true;
return this.findRecord();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { camelize } from '@ember/string';

import { pluralize } from 'ember-inflector';

type Dict<T> = import('@ember-data/store/-private/ts-interfaces/utils').Dict<T>;
type Snapshot = import('@ember-data/store/-private/system/snapshot').default;
type SnapshotRecordArray = import('@ember-data/store/-private/system/snapshot-record-array').default;

/**
@module @ember-data/adapter
*/
Expand Down Expand Up @@ -55,7 +59,13 @@ export default Mixin.create({
@param {Object} query object of query parameters to send for query requests.
@return {String} url
*/
buildURL(modelName, id, snapshot, requestType, query) {
buildURL(
modelName: string,
id: string | string[] | Dict<unknown> | null,
snapshot: Snapshot | Snapshot[] | SnapshotRecordArray | null,
requestType: string = '',
query = {}
): string {
switch (requestType) {
case 'findRecord':
return this.urlForFindRecord(id, modelName, snapshot);
Expand Down Expand Up @@ -89,9 +99,9 @@ export default Mixin.create({
@param {String} id
@return {String} url
*/
_buildURL(modelName, id) {
_buildURL(modelName: string | null | undefined, id: string | null | undefined): string {
let path;
let url = [];
let url: string[] = [];
let host = get(this, 'host');
let prefix = this.urlPrefix();

Expand All @@ -109,12 +119,12 @@ export default Mixin.create({
url.unshift(prefix);
}

url = url.join('/');
if (!host && url && url.charAt(0) !== '/') {
url = '/' + url;
let urlString = url.join('/');
if (!host && urlString && urlString.charAt(0) !== '/') {
urlString = '/' + urlString;
}

return url;
return urlString;
},

/**
Expand All @@ -140,7 +150,7 @@ export default Mixin.create({
@return {String} url

*/
urlForFindRecord(id, modelName, snapshot) {
urlForFindRecord(id: string, modelName: string, snapshot: Snapshot): string {
return this._buildURL(modelName, id);
},

Expand All @@ -165,7 +175,7 @@ export default Mixin.create({
@param {SnapshotRecordArray} snapshot
@return {String} url
*/
urlForFindAll(modelName, snapshot) {
urlForFindAll(modelName: string, snapshot: Snapshot): string {
return this._buildURL(modelName);
},

Expand Down Expand Up @@ -195,7 +205,7 @@ export default Mixin.create({
@param {String} modelName
@return {String} url
*/
urlForQuery(query, modelName) {
urlForQuery(query: Dict<unknown>, modelName: string): string {
return this._buildURL(modelName);
},

Expand All @@ -220,7 +230,7 @@ export default Mixin.create({
@param {String} modelName
@return {String} url
*/
urlForQueryRecord(query, modelName) {
urlForQueryRecord(query: Dict<unknown>, modelName: string): string {
return this._buildURL(modelName);
},

Expand Down Expand Up @@ -248,7 +258,7 @@ export default Mixin.create({
@param {Array} snapshots
@return {String} url
*/
urlForFindMany(ids, modelName, snapshots) {
urlForFindMany(ids: string[], modelName: string, snapshots: Snapshot[]) {
return this._buildURL(modelName);
},

Expand All @@ -275,7 +285,7 @@ export default Mixin.create({
@param {Snapshot} snapshot
@return {String} url
*/
urlForFindHasMany(id, modelName, snapshot) {
urlForFindHasMany(id: string, modelName: string, snapshot: Snapshot): string {
return this._buildURL(modelName, id);
},

Expand All @@ -302,7 +312,7 @@ export default Mixin.create({
@param {Snapshot} snapshot
@return {String} url
*/
urlForFindBelongsTo(id, modelName, snapshot) {
urlForFindBelongsTo(id: string, modelName: string, snapshot: Snapshot): string {
return this._buildURL(modelName, id);
},

Expand All @@ -327,7 +337,7 @@ export default Mixin.create({
@param {Snapshot} snapshot
@return {String} url
*/
urlForCreateRecord(modelName, snapshot) {
urlForCreateRecord(modelName: string, snapshot: Snapshot) {
return this._buildURL(modelName);
},

Expand All @@ -352,7 +362,7 @@ export default Mixin.create({
@param {Snapshot} snapshot
@return {String} url
*/
urlForUpdateRecord(id, modelName, snapshot) {
urlForUpdateRecord(id: string, modelName: string, snapshot: Snapshot): string {
return this._buildURL(modelName, id);
},

Expand All @@ -377,7 +387,7 @@ export default Mixin.create({
@param {Snapshot} snapshot
@return {String} url
*/
urlForDeleteRecord(id, modelName, snapshot) {
urlForDeleteRecord(id: string, modelName: string, snapshot: Snapshot): string {
return this._buildURL(modelName, id);
},

Expand All @@ -388,7 +398,7 @@ export default Mixin.create({
@param {String} parentURL
@return {String} urlPrefix
*/
urlPrefix(path, parentURL) {
urlPrefix(path: string | null | undefined, parentURL: string): string {
let host = get(this, 'host');
let namespace = get(this, 'namespace');

Expand All @@ -412,7 +422,7 @@ export default Mixin.create({
}

// No path provided
let url = [];
let url: string[] = [];
if (host) {
url.push(host);
}
Expand Down Expand Up @@ -450,7 +460,7 @@ export default Mixin.create({
@param {String} modelName
@return {String} path
**/
pathForType(modelName) {
pathForType(modelName: string): string {
let camelized = camelize(modelName);
return pluralize(camelized);
},
Expand Down
9 changes: 9 additions & 0 deletions packages/adapter/addon/-private/fastboot-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Request {
protocol: string;
host: string;
}

export interface FastBoot {
isFastBoot: boolean;
request: Request;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DEBUG } from '@glimmer/env';

import continueOnReject from './continue-on-reject';

type RequestData = import('../../rest').RequestData;
type Payload = object | string | undefined;

interface CustomSyntaxError extends SyntaxError {
Expand Down Expand Up @@ -62,7 +63,7 @@ function _determineContent(response: Response, requestData: JQueryAjaxSettings,
return ret;
}

export function determineBodyPromise(response: Response, requestData: JQueryAjaxSettings): Promise<Payload> {
export function determineBodyPromise(response: Response, requestData: RequestData): Promise<Payload> {
// response.text() may resolve or reject
// it is a native promise, may not have finally
return continueOnReject(response.text()).then(payload => _determineContent(response, requestData, payload));
Expand Down
Loading