Adding doctests

This commit is contained in:
Paul Copplestone committed 2019-11-08 04:30:56 +00:00
1 parent ed46049ee9
commit dc3662e6fa
6 files changed
+671 -38

No files matched your search

+2 -1
View File
@@ -21,7 +21,8 @@
"deploy:web": "yarn workspace @supabase/web deploy",
"deploy:realtime-js": "yarn workspace @supabase/realtime-js deploy",
"dev": "concurrently --kill-others-on-fail \"yarn dev:web\" ",
"dev:web": "yarn workspace @supabase/web dev"
"dev:web": "yarn workspace @supabase/web dev",
"test:realtime-js": "yarn workspace @supabase/realtime-js test"
},
"dependencies": {
"concurrently": "^5.0.0"
+8 -4
View File
@@ -5,18 +5,22 @@
"repository": "https://github.com/supabase/monorepo",
"main": "src/index.js",
"scripts": {
"test": "mocha \"test/**/*_spec.js\"",
"deploy": "npm version patch; npm publish --access=public"
"deploy": "npm version patch; npm publish --access=public",
"test": "mocha --require esm \"test/**/*_spec.js\""
},
"keywords": [
"supabase",
"realtime"
],
"author": "@kiwicopple",
"license": "Apache 2.0",
"devDependencies": {},
"license": "Apache-2.0",
"dependencies": {
"@types/node": "^12.6.8",
"phoenix-channels": "^1.0.0"
},
"devDependencies": {
"esm": "3.2.25",
"jsdoc-test": "0.0.10",
"mocha": "6.2.2"
}
}
+29 -3
View File
@@ -41,11 +41,15 @@
* @param {Object} records
* @param {Object} options The map of various options that can be applied to the mapper
* @param {Array} options.skipTypes The array of types that should not be converted
*
* @example
* convertChangeData([{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {'Paul', '33'}, {})
* //=>
* { first_name: 'Paul', age: 33 }
*/
export const dataConverter = (columns, records, options = {}) => {
export const convertChangeData = (columns, records, options = {}) => {
let result = {}
let skipTypes = typeof options.skipTypes !== 'undefined' ? options.skipTypes : []
Object.entries(records).map(([key, value]) => {
result[key] = convertColumn(key, columns, records, skipTypes)
})
@@ -58,9 +62,19 @@ export const dataConverter = (columns, records, options = {}) => {
* @param {{name: String, type: String}[]} columns All of the columns
* @param {Object} records The map of string values
* @param {Array} skipTypes An array of types that should not be converted
* @return {object} Useless information
*
* @example
* convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], ['Paul', '33'], [])
* //=>
* 33
*
* @example
* convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], ['Paul', '33'], ['int4'])
* //=>
* "33"
*/
export const convertColumn = (columnName, columns, records, skipTypes) => {
let column = columns.find(x => x.name == columnName)
if(skipTypes.includes(column.type)) return noop(records[columnName])
else return convertCell(column.type, records[columnName])
@@ -69,6 +83,18 @@ export const convertColumn = (columnName, columns, records, skipTypes) => {
/**
* If the value of the cell is `null`, returns null.
* Otherwise converts the string value to the correct type.
* @param {String} type A postgres column type
* @param {String} stringValue The cell value
*
* @example
* convertCell('bool', 'true')
* //=>
* true
*
* @example
* convertCell('int8', '10')
* //=>
* 10
*/
export const convertCell = (type, stringValue) => {
try {
@@ -0,0 +1,5 @@
import doctest from 'jsdoc-test'
describe('Ru', () => {
doctest('src/mapper.js')
})
-1
View File
@@ -1 +0,0 @@
// Coming soon
+627 -29
View File
File diff suppressed because it is too large. Load diff