Skip to content

Commit 6e1879f

Browse files
committed
docs: autogenerate typescript definitions
1 parent 66d76ef commit 6e1879f

22 files changed

Lines changed: 608 additions & 382 deletions

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"build": "lerna exec yarn build",
2020
"docs": "lerna exec --parallel yarn docs:lint",
2121
"docs:build": "lerna exec --parallel yarn docs:build",
22+
"docs:typescript": "lerna exec --parallel yarn docs:typescript",
2223
"docs:release": "yarn docs && yarn docs:build",
2324
"fix": "eslint . --fix",
2425
"lint": "eslint .",
@@ -50,7 +51,8 @@
5051
"rollup": "~2.10.0",
5152
"rollup-plugin-local-resolve": "~1.0.7",
5253
"rollup-plugin-terser": "~5.3.0",
53-
"size-limit": "~4.5.0"
54+
"size-limit": "~4.5.0",
55+
"typescript": "~3.9.3"
5456
},
5557
"jest": {
5658
"testEnvironment": "node",

packages/kitsu-core/index.d.ts

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

packages/kitsu-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"module": "lib/index.mjs",
1616
"unpkg": "lib/index.browser.js",
1717
"jsdelivr": "lib/index.browser.js",
18-
"types": "index.d.ts",
18+
"types": "types/index.d.ts",
1919
"homepage": "https://github.com/wopian/kitsu/tree/master/packages/kitsu-core#readme",
2020
"repository": "https://github.com/wopian/kitsu/tree/master/packages/kitsu-core",
2121
"bugs": {
@@ -34,6 +34,7 @@
3434
"scripts": {
3535
"docs:lint": "documentation lint src/index.js",
3636
"docs:build": "documentation readme src/index.js --section=API -g true --sort-order source",
37+
"docs:typescript": "tsc src/index.js --declaration --emitDeclarationOnly --allowJs --outDir types",
3738
"rollup": "cross-env NODE_ENV=production rollup -c --environment BUILD:production",
3839
"build": "yarn rollup"
3940
},

packages/kitsu-core/src/filterIncludes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { error } from '../error'
77
* @param {Object} relationship
88
* @param {string} relationship.id The relationship ID
99
* @param {string} relationship.type The relationship type
10-
* @returns {Array} The matched includes
10+
* @returns {Array<Object>} The matched includes
1111
*
1212
* @example
1313
* const includes = [

packages/kitsu-core/src/serialise/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function hasID (node) {
106106
* Handles the Bulk Extension support. See `serialise` for examples.
107107
*
108108
* @param {string} type Resource type
109-
* @param {Array} payload The data
109+
* @param {Array<Object>} payload The data
110110
* @param {string} method Request type (PATCH, POST, DELETE)
111111
* @param {Object} options Optional configuration for camelCase and pluralisation handling
112112
* @param {Function} options.camelCaseTypes Convert library-entries and library_entries to libraryEntries (default no conversion). To use parameter, import camel from kitsu-core
@@ -127,7 +127,7 @@ function serialiseRootArray (type, payload, method, options) {
127127
* Serialises the root data object. See `serialise` for examples.
128128
*
129129
* @param {string} type Resource type
130-
* @param {Array} payload The data
130+
* @param {Object} payload The data
131131
* @param {string} method Request type (PATCH, POST, DELETE)
132132
* @param {Object} options Optional configuration for camelCase and pluralisation handling
133133
* @param {Function} options.camelCaseTypes Convert library-entries and library_entries to libraryEntries (default no conversion). To use parameter, import camel from kitsu-core
@@ -164,7 +164,7 @@ function serialiseRootObject (type, payload, method, options) {
164164
* Serialises an object into a JSON-API structure
165165
*
166166
* @param {string} type Resource type
167-
* @param {Object|Array} data The data
167+
* @param {Object|Array<Object>} data The data
168168
* @param {string} method Request type (PATCH, POST, DELETE)
169169
* @param {Object} options Optional configuration for camelCase and pluralisation handling
170170
* @param {Function} options.camelCaseTypes Convert library-entries and library_entries to libraryEntries (default no conversion). To use parameter, import camel from kitsu-core

packages/kitsu-core/src/splitModel/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @param {Object} options
88
* @param {Function} options.resourceCase Convert libraryEntries to library-entries or library_entries (default no conversion). To use parameter, import kebab or snake from kitsu-core
99
* @param {Function} options.pluralModel Pluralise models (default no pluralisation). To use parameter, import pluralize (or another pluralisation npm package)
10-
* @returns {Array} Array containing the model name and the resource URL with pluralisation applied
10+
* @returns {Array<string, string>} Array containing the model name and the resource URL with pluralisation applied
1111
*
1212
* @example
1313
* splitModel('posts/1/comments')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare function _default(s: string): string;
2+
export default _default;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Hoists attributes to be top-level
3+
*
4+
* @param {Object|Array} data Resource data
5+
* @returns {Object|Array} Deattributed resource data
6+
*
7+
* @example <caption>Deattribute an array of resources</caption>
8+
* // JSON:API 'data' field
9+
* const data = [
10+
* {
11+
* id: '1',
12+
* type: 'users',
13+
* attributes: { slug: 'wopian' }
14+
* }
15+
* ]
16+
*
17+
* const output = deattribute(data) // [ { id: '1', type: 'users', slug: 'wopian' } ]
18+
*
19+
* @example <caption>Deattribute a resource</caption>
20+
* // JSON:API 'data' field
21+
* const data = {
22+
* id: '1',
23+
* type: 'users',
24+
* attributes: { slug: 'wopian' }
25+
* }
26+
*
27+
* const output = deattribute(data) // { id: '1', type: 'users', slug: 'wopian' }
28+
*/
29+
export function deattribute(data: any | Array): any | Array;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Deserialises a JSON-API response
3+
*
4+
* @param {Object} response The raw JSON:API response object
5+
* @returns {Object} The deserialised response
6+
*
7+
* @example <caption>Deserialise with a basic data object</caption>
8+
* deserialise({
9+
* data: {
10+
* id: '1',
11+
* attributes: { liked: true }
12+
* },
13+
* meta: { hello: 'world' }
14+
* }) // { data: { id: '1', liked: true }, meta: { hello: 'world' } }
15+
*
16+
* @example <caption>Deserialise with relationships</caption>
17+
* deserialise({
18+
* data: {
19+
* id: '1',
20+
* relationships: {
21+
* user: {
22+
* data: {
23+
* type: 'users',
24+
* id: '2' }
25+
* }
26+
* }
27+
* },
28+
* included: [
29+
* {
30+
* type: 'users',
31+
* id: '2',
32+
* attributes: { slug: 'wopian' }
33+
* }
34+
* ]
35+
* }) // { data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } }
36+
*/
37+
export function deserialise(response: any): any;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Uniform error handling for Axios, JSON:API and internal package errors. Mutated Error object is rethrown to the caller.
3+
*
4+
* @param {Object} E The Error
5+
* @throws {Object} The mutated Error
6+
*
7+
* @example
8+
* error('Hello')
9+
*
10+
* @example
11+
* error({errors: [ { code: 400 } ]})
12+
*
13+
* @example
14+
* error({
15+
* response: {
16+
* data: {
17+
* errors: [ {
18+
* title: 'Filter is not allowed',
19+
* detail: 'x is not allowed',
20+
* code: '102',
21+
* status: '400'
22+
* } ]
23+
* }
24+
* }
25+
* })
26+
*/
27+
export function error(E: any): void;

0 commit comments

Comments
 (0)