Skip to content

Commit 531befc

Browse files
committed
refactor: Removed type-check
1 parent 076eb91 commit 531befc

File tree

12 files changed

+77
-246
lines changed

12 files changed

+77
-246
lines changed

lib/contentful.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66

77
import createHttpClient from './create-http-client'
88
import createCdaApi from './create-cda-api'
9-
import {typeCheck} from './type-check'
10-
11-
const ClientParams = `{
12-
space: String,
13-
accessToken: String,
14-
insecure: Maybe Boolean,
15-
host: Maybe String,
16-
resolveLinks: Maybe Boolean,
17-
agent: Maybe Object,
18-
headers: Maybe Object
19-
}`
209

2110
/**
2211
* Create a client instance
@@ -46,8 +35,6 @@ export default function createClient (axios, params) {
4635
throw new TypeError('Expected parameter space')
4736
}
4837

49-
typeCheck(ClientParams, params)
50-
5138
// Use resolveLinks param if specified, otherwise default to true
5239
const resolveLinks = !!('resolveLinks' in params ? params.resolveLinks : true)
5340

lib/create-cda-api.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,78 @@ export default function createCdaApi (http, resolveLinksGlobalSetting) {
182182
sync: sync
183183
}
184184
}
185+
186+
/**
187+
* System metadata. See <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes">Common Resource Attributes</a> for more details.
188+
* @memberof Entities
189+
* @typedef Sys
190+
* @prop {string} type
191+
* @prop {string} id
192+
* @prop {Entities.Link} space
193+
* @prop {string} createdAt
194+
* @prop {string} updatedAt
195+
* @prop {number} revision
196+
*/
197+
198+
/**
199+
* Link to another entity. See <a href="https://www.contentful.com/developers/docs/concepts/links/">Links</a> for more details.
200+
* @memberof Entities
201+
* @typedef Link
202+
* @prop {string} type - type of this entity. Always link.
203+
* @prop {string} id
204+
* @prop {string} linkType - type of this link. If defined, either Entry or Asset
205+
*/
206+
207+
/**
208+
* @namespace EntryFields
209+
*/
210+
211+
/**
212+
* @memberof EntryFields
213+
* @typedef Symbol
214+
* @type string
215+
*/
216+
217+
/**
218+
* @memberof EntryFields
219+
* @typedef Text
220+
* @type string
221+
*/
222+
223+
/**
224+
* @memberof EntryFields
225+
* @typedef Integer
226+
* @type number
227+
*/
228+
229+
/**
230+
* @memberof EntryFields
231+
* @typedef Number
232+
* @type number
233+
*/
234+
235+
/**
236+
* @memberof EntryFields
237+
* @typedef Date
238+
* @type string
239+
*/
240+
241+
/**
242+
* @memberof EntryFields
243+
* @typedef Boolean
244+
* @type boolean
245+
*/
246+
247+
/**
248+
* @memberof EntryFields
249+
* @typedef Location
250+
* @prop {string} lat - latitude
251+
* @prop {string} lon - longitude
252+
*/
253+
254+
/**
255+
* A Field in an Entry can have one of the following types that can be defined in Contentful. See <a href="https://www.contentful.com/developers/docs/references/field-type/">Field Types</a> for more details.
256+
* @memberof Entities
257+
* @typedef Field
258+
* @type EntryFields.Symbol | EntryFields.Text | EntryFields.Integer | EntryFields.Number | EntryFields.Date | EntryFields.Boolean | EntryFields.Location | Entities.Link | Array<EntryFields.Symbol|Entities.Link> | Object
259+
*/

lib/entities/asset.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {typeCheck} from '../type-check'
21
import {cloneDeep} from 'lodash/lang'
3-
import {SysProps} from './sys'
4-
import Field from './field'
52
import mixinToPlainObject from '../mixins/to-plain-object'
63

74
/**
@@ -19,23 +16,13 @@ import mixinToPlainObject from '../mixins/to-plain-object'
1916
* @prop {Object} fields.file.details - Details for the file, depending on file type (example: image size in bytes, etc)
2017
* @prop {function(): Object} toPlainObject() - Returns this Asset as a plain JS object
2118
*/
22-
const Asset = `{
23-
sys: {
24-
${SysProps},
25-
locale: String
26-
},
27-
fields: Field
28-
}`
29-
30-
export default Asset
3119

3220
/**
3321
* @private
3422
* @param {Object} data - Raw asset data
3523
* @return {Asset} Wrapped asset data
3624
*/
3725
export function wrapAsset (data) {
38-
typeCheck(Asset, data, [Field])
3926
return Object.freeze(mixinToPlainObject(cloneDeep(data)))
4027
}
4128

@@ -48,19 +35,12 @@ export function wrapAsset (data) {
4835
* @prop {Array<Entities.Asset>} items
4936
* @prop {function(): Object} toPlainObject() - Returns this Asset collection as a plain JS object
5037
*/
51-
const AssetCollection = `{
52-
total: Number,
53-
skip: Number,
54-
limit: Number,
55-
items: [${Asset}]
56-
}`
5738

5839
/**
5940
* @private
6041
* @param {Object} data - Raw asset collection data
6142
* @return {AssetCollection} Wrapped asset collection data
6243
*/
6344
export function wrapAssetCollection (data) {
64-
typeCheck(AssetCollection, data, [Field])
6545
return Object.freeze(mixinToPlainObject(cloneDeep(data)))
6646
}

lib/entities/content-type.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {typeCheck} from '../type-check'
21
import {cloneDeep} from 'lodash/lang'
3-
import Sys from './sys'
42
import mixinToPlainObject from '../mixins/to-plain-object'
53

64
/**
@@ -13,29 +11,13 @@ import mixinToPlainObject from '../mixins/to-plain-object'
1311
* @prop {string} Array<Field> - All the fields contained in this Content Type
1412
* @prop {function(): Object} toPlainObject() - Returns this Content Type as a plain JS object
1513
*/
16-
const ContentType = `{
17-
sys: ${Sys},
18-
name: String,
19-
description: String,
20-
displayField: String,
21-
fields: [
22-
{
23-
id: String,
24-
name: String,
25-
type: String,
26-
localized: Boolean,
27-
required: Boolean
28-
}
29-
]
30-
}`
3114

3215
/**
3316
* @private
3417
* @param {Object} data - Raw content type data
3518
* @return {ContentType} Wrapped content type data
3619
*/
3720
export function wrapContentType (data) {
38-
typeCheck(ContentType, data)
3921
return Object.freeze(mixinToPlainObject(cloneDeep(data)))
4022
}
4123

@@ -48,19 +30,12 @@ export function wrapContentType (data) {
4830
* @prop {Array<Entities.ContentType>} items
4931
* @prop {function(): Object} toPlainObject() - Returns this Content Type collection as a plain JS object
5032
*/
51-
const ContentTypeCollection = `{
52-
total: Number,
53-
skip: Number,
54-
limit: Number,
55-
items: [${ContentType}]
56-
}`
5733

5834
/**
5935
* @private
6036
* @param {Object} data - Raw content type collection data
6137
* @return {ContentTypeCollection} Wrapped content type collection data
6238
*/
6339
export function wrapContentTypeCollection (data) {
64-
typeCheck(ContentTypeCollection, data)
6540
return Object.freeze(mixinToPlainObject(cloneDeep(data)))
6641
}

lib/entities/entry.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {typeCheck} from '../type-check'
21
import {cloneDeep} from 'lodash/lang'
3-
import {SysProps} from './sys'
4-
import Field from './field'
5-
import Link from './link'
6-
import Asset from './Asset'
72
import mixinToPlainObject from '../mixins/to-plain-object'
83
import mixinLinkGetters from '../mixins/link-getters'
94

@@ -16,24 +11,13 @@ import mixinLinkGetters from '../mixins/link-getters'
1611
* @prop {Object<EntryFields.Field>} fields - Object with content for each field
1712
* @prop {function(): Object} toPlainObject() - Returns this Entry as a plain JS object
1813
*/
19-
const Entry = `{
20-
sys: {
21-
${SysProps},
22-
locale: String,
23-
contentType: ${Link}
24-
},
25-
fields: Field
26-
}`
27-
28-
export default Entry
2914

3015
/**
3116
* @private
3217
* @param {Object} data - Raw entry data
3318
* @return {Entry} Wrapped entry data
3419
*/
3520
export function wrapEntry (data) {
36-
typeCheck(Entry, data, [Field])
3721
return Object.freeze(mixinToPlainObject(cloneDeep(data)))
3822
}
3923

@@ -46,18 +30,6 @@ export function wrapEntry (data) {
4630
* @prop {Array<Entities.Entry>} items
4731
* @prop {function(): Object} toPlainObject() - Returns this Entry collection as a plain JS object
4832
*/
49-
const EntryCollection = `{
50-
total: Number,
51-
skip: Number,
52-
limit: Number,
53-
items: [${Entry}],
54-
includes: Maybe {
55-
Entry: Maybe [${Entry}],
56-
Asset: Maybe [${Asset}],
57-
DeletedEntry: Maybe [${Entry}],
58-
DeletedAsset: Maybe [${Asset}]
59-
}
60-
}`
6133

6234
/**
6335
* Data is also mixed in with link getters if links exist and includes were requested
@@ -66,7 +38,6 @@ const EntryCollection = `{
6638
* @return {EntryCollection} Wrapped entry collection data
6739
*/
6840
export function wrapEntryCollection (data, resolveLinks) {
69-
typeCheck(EntryCollection, data, [Field])
7041
const wrappedData = mixinToPlainObject(cloneDeep(data))
7142
if (wrappedData.includes && resolveLinks) {
7243
mixinLinkGetters(wrappedData.items, wrappedData.includes)

lib/entities/field.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,11 @@
11
import {typeCheck} from '../type-check'
22
import Link from './link'
33

4-
/**
5-
* @namespace EntryFields
6-
*/
7-
8-
/**
9-
* @memberof EntryFields
10-
* @typedef Symbol
11-
* @type string
12-
*/
13-
14-
/**
15-
* @memberof EntryFields
16-
* @typedef Text
17-
* @type string
18-
*/
19-
20-
/**
21-
* @memberof EntryFields
22-
* @typedef Integer
23-
* @type number
24-
*/
25-
26-
/**
27-
* @memberof EntryFields
28-
* @typedef Number
29-
* @type number
30-
*/
31-
32-
/**
33-
* @memberof EntryFields
34-
* @typedef Date
35-
* @type string
36-
*/
37-
38-
/**
39-
* @memberof EntryFields
40-
* @typedef Boolean
41-
* @type boolean
42-
*/
43-
44-
/**
45-
* @memberof EntryFields
46-
* @typedef Location
47-
* @prop {string} lat - latitude
48-
* @prop {string} lon - longitude
49-
*/
504
const Location = `{
515
lat: String,
526
lon: String
537
}`
548

55-
/**
56-
* A Field in an Entry can have one of the following types that can be defined in Contentful. See <a href="https://www.contentful.com/developers/docs/references/field-type/">Field Types</a> for more details.
57-
* @memberof Entities
58-
* @typedef Field
59-
* @type EntryFields.Symbol | EntryFields.Text | EntryFields.Integer | EntryFields.Number | EntryFields.Date | EntryFields.Boolean | EntryFields.Location | Entities.Link | Array<EntryFields.Symbol|Entities.Link> | Object
60-
*/
619
export default {
6210
name: 'Field',
6311
type: {

lib/entities/link.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/entities/space.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {typeCheck} from '../type-check'
21
import mixinToPlainObject from '../mixins/to-plain-object'
32

43
/**
@@ -11,21 +10,12 @@ import mixinToPlainObject from '../mixins/to-plain-object'
1110
* @prop {Array<string>} locales - Array with locale codes
1211
* @prop {function(): Object} toPlainObject() - Returns this Space as a plain JS object
1312
*/
14-
const Space = `{
15-
sys: {
16-
id: String,
17-
type: String
18-
},
19-
name: String,
20-
locales: [String]
21-
}`
2213

2314
/**
2415
* @private
2516
* @param {Object} data - API response for a Space
2617
* @return {Space}
2718
*/
2819
export function wrapSpace (data) {
29-
typeCheck(Space, data)
3020
return Object.freeze(mixinToPlainObject(data))
3121
}

0 commit comments

Comments
 (0)