Skip to content

Commit 5353625

Browse files
BlairJBlairJ
authored andcommitted
Tidy up code, comment out unused code
1 parent 48bd89b commit 5353625

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

scripts/typings/js-data/DSUtil.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
reject(error: any): Promise<any>;
3636
}
3737

38+
// See: https://github.com/js-data/js-data/blob/master/src/utils.js
3839
interface DSUtil {
3940
Promise: PromiseLib; //{ <R>(callback: (resolve: (value?: R | Thenable<R>) => void, reject: (error?: any) => void) => void) };
4041
deepMixIn: (dest: any, source: any) => any;

src/JsonApi.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,7 @@ export class JsonApiError {
183183
}
184184
}
185185

186-
//class Source {
187-
// pointer: string;
188-
// parameterDecorator: string;
189-
//}
190-
191186
export class JsonApiVersion {
192187
version: string;
193188
meta: Meta;
194-
}
195-
189+
}

src/JsonApiAdapter.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,14 @@ import JSDataHttp = require('js-data-http');
1212
import Helper = require('./JsonApiSerializer');
1313
export import JsonApi = require('./JsonApi');
1414

15-
//class Headers {
16-
// common: { [name: string]: string };
17-
18-
// constructor() {
19-
// this.common = {};
20-
// }
21-
//}
22-
2315
const HttpNoContent: Number = 204;
2416

2517
export class JsonApiAdapter implements JSData.IDSAdapter {
2618

27-
//TODO Add typings, see: https://github.com/js-data/js-data/blob/master/src/utils.js
2819
private DSUtils: JSData.DSUtil;
2920
private adapter: JSData.DSHttpAdapterExtended;
3021
private adapterGetPath: Function;
3122
adapterHTTP: Function;
32-
// adapterPOST: Function;
3323

3424
get defaults(): JsonApiAdapter.DSJsonApiAdapterOptions {
3525
return this.adapter.defaults;
@@ -42,7 +32,7 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
4232
var httpAdapter: typeof DSHttpAdapter = JSDataHttp;
4333
this.DSUtils = JSDataLib['DSUtils'];
4434

45-
//TODO : Set defaults on options
35+
//No longer use options
4636
this.serialize = this.SerializeJsonResponse;
4737
this.deserialize = this.DeSerializeJsonResponse;
4838

@@ -54,23 +44,23 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
5444
// defaults.error = (a, b) => console[typeof console.error === 'function' ? 'error' : 'log'](a, b)
5545
//}
5646

57-
//options = options || {};
58-
//this.DSUtils.deepMixIn(options, defaults);
47+
// Create base adapter
5948
this.adapter = <JSData.DSHttpAdapterExtended> (new httpAdapter(options));
6049

6150
// Override default get path implementation
6251
this.adapterGetPath = this.adapter.getPath;
6352
this.adapterHTTP = this.adapter.HTTP;
64-
//this.adapterPOST = this.adapterPOST;
6553

6654

55+
// Override Get Path
6756
this.adapter.getPath = (method: string, resourceConfig: JSData.DSResourceDefinition<any>, id: Object, options: JSData.DSConfiguration): string => {
6857
return this.getPath(method, resourceConfig, id, options);
6958
};
59+
60+
// Override HTTP
7061
this.adapter.HTTP = (options: Object): JSData.JSDataPromise<JSData.DSHttpAdapterPromiseResolveType> => {
7162
return this.HTTP(options);
7263
};
73-
//this.adapter.POST = this.POST;
7464
}
7565

7666
SerializeJsonResponse(resourceConfig: JSData.DSResourceDefinition<any>, attrs: Object): any {
@@ -81,7 +71,7 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
8171
DeSerializeJsonResponse(resourceConfig: JSData.DSResourceDefinition<any>, response: JSData.DSHttpAdapterPromiseResolveType): any {
8272
//Only process JSON Api responses!!
8373
if (Helper.JsonApiHelper.ContainsJsonApiContentTypeHeader(response.headers)) {
84-
// TODO : Decode Json API Error response
74+
// Decode Json API Error response
8575
if (response.data.errors) {
8676
response.data = Helper.JsonApiHelper.FromJsonApiError(response.data);
8777
} else {
@@ -203,18 +193,18 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
203193
* @desc Configure serialization and deserialization for the request using
204194
* either axios or $http configuration options
205195
* @param {object} options axios or $http config options
206-
* @returns {object} options copy of options with serializers configured
196+
* @returns {object} options copy of options with serializers configured for jsonapi
207197
* @memberOf JsonApiAdapter
208198
*/
209199
configureSerializers(options: JSData.DSConfiguration): any {
210200
options = this.DSUtils.copy(options) || {};
211201
options['headers'] = options['headers'] || {};
212202

213-
//Jsoin Api requires accept header
203+
//Json Api requires accept header
214204
Helper.JsonApiHelper.AddJsonApiAcceptHeader(options['headers']);
215205
Helper.JsonApiHelper.AddJsonApiContentTypeHeader(options['headers']);
216206

217-
// Ensure that we always call the JsonApi serializer first then any other serializers
207+
// Ensure that we always call the JsonApi serializer first then any other serializers
218208
var serialize = options['serialize'] || this.defaults.serialize;
219209
if (serialize) {
220210
options['serialize'] = (resourceConfig: JSData.DSResourceDefinition<any>, attrs: Object) => {
@@ -226,7 +216,7 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
226216
};
227217
}
228218

229-
// Ensure that we always call the JsonApi deserializer first then any other deserializers
219+
// Ensure that we always call the JsonApi deserializer first then any other deserializers
230220
var deserialize = options['deserialize'] || this.defaults.deserialize;
231221
if (deserialize) {
232222
options['deserialize'] = (resourceConfig: JSData.DSResourceDefinition<any>, data: JSData.DSHttpAdapterPromiseResolveType) => {
@@ -242,6 +232,13 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
242232
}
243233

244234
// DSHttpAdapter uses axios or $http, so options are axios config objects or $http config options.
235+
236+
/**
237+
* @name HTTP
238+
* @desc Performs an HTTP request and receives resposne
239+
* @param options
240+
* @memberOf JsonApiAdapter
241+
*/
245242
public HTTP(options?: Object): JSData.JSDataPromise<JSData.DSHttpAdapterPromiseResolveType> {
246243
return this.adapterHTTP.apply(this.adapter, [options])
247244
.then((response: JSData.DSHttpAdapterPromiseResolveType) => {
@@ -282,7 +279,7 @@ export class JsonApiAdapter implements JSData.IDSAdapter {
282279
//}
283280

284281

285-
//IDSAdapter
282+
// IDSAdapter
286283
public create(config: JSData.DSResourceDefinition<any>, attrs: Object, options?: JSData.DSConfiguration): JSData.JSDataPromise<any> {
287284
let localOptions = this.configureSerializers(options);
288285

src/JsonApiSerializer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,7 @@ export class JsonApiHelper {
426426
}
427427

428428
public static AddJsonApiContentTypeHeader(headers: { [name: string]: string }): void {
429-
//if (!headers['Content-Type'])
430429
headers['Content-Type'] = jsonApiContentType;
431-
//else {}
432430
}
433431

434432
public static AddJsonApiAcceptHeader(headers: { [name: string]: string }): void {
@@ -790,7 +788,8 @@ export class JsonApiHelper {
790788
}
791789
}
792790

793-
791+
// Obsolete to be removed
792+
/*
794793
private static ReplaceModelPlaceHolderRelations(included: any, options: SerializationOptions) {
795794
//Store data included as type,id key pairs
796795
if (included) {
@@ -866,8 +865,10 @@ export class JsonApiHelper {
866865
}
867866
}
868867
}
868+
*/
869869

870870
/**
871+
* @Obsolete
871872
* @name NormaliseDataObjectGraph
872873
* @desc Convert all data relationshipts to real objects taken from 1 Included data, then data or joiningdata
873874
* @param {any} data Json data
@@ -877,6 +878,7 @@ export class JsonApiHelper {
877878
* @returns {string} JsonApi rest service Url
878879
* @memberOf JsonApiAdapter
879880
*/
881+
/*
880882
private static NormaliseDataObjectGraph(data: any, included: any, jsDataJoiningTables: any, options: SerializationOptions) : Array<any> {
881883
882884
// This is an array of top level objects with child, object references and included objects
@@ -987,7 +989,7 @@ export class JsonApiHelper {
987989
}
988990
return jsDataArray;
989991
}
990-
992+
*/
991993

992994
private static CreateErrorResponse(title: string, detail: string): JsonApi.JsonApiRequest {
993995
var response = new JsonApi.JsonApiRequest();

0 commit comments

Comments
 (0)