firestore-adapter
Advanced tools
Comparing version 1.0.4 to 1.0.5
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Adapter is a class to convert Firestore data into values without value types. | ||
* Converting Firestore data into values without value types. | ||
*/ | ||
var Adapter = /** @class */ (function () { | ||
function Adapter(input) { | ||
this.input = input; | ||
} | ||
Adapter.prototype.convert = function () { | ||
var _this = this; | ||
var output = this.input.map(function (obj) { return _this.extractObject(obj); }); | ||
return output; | ||
}; | ||
var convert = function (input) { | ||
/** | ||
* Check if object is `ArrayValue`, `MapValue` | ||
*/ | ||
var isArrayValue = function (object) { return object.hasOwnProperty('arrayValue'); }; | ||
var isMapValue = function (object) { return object.hasOwnProperty('mapValue'); }; | ||
/** | ||
* Extract an `Object`with types and values into pure values | ||
@@ -32,4 +29,3 @@ * Each field of Object has its type and value. | ||
*/ | ||
Adapter.prototype.extractObject = function (value) { | ||
var _this = this; | ||
var extractObject = function (value) { | ||
var output = {}; | ||
@@ -39,3 +35,3 @@ // Extract value of each field | ||
var valueField = value[k]; | ||
output[k] = _this.extractValueField(valueField); | ||
output[k] = extractValueField(valueField); | ||
}); | ||
@@ -54,4 +50,3 @@ return output; | ||
*/ | ||
Adapter.prototype.extractValueField = function (valueField) { | ||
var _this = this; | ||
var extractValueField = function (valueField) { | ||
/** | ||
@@ -61,4 +56,4 @@ * `ArrayValue` contains array of ValueField i.e. { values: [{stringValue: 'some value'}, ...] } | ||
*/ | ||
if (this.isArrayValue(valueField)) { | ||
return valueField.arrayValue.values.map(function (v) { return _this.extractValueField(v); }); | ||
if (isArrayValue(valueField)) { | ||
return valueField.arrayValue.values.map(function (v) { return extractValueField(v); }); | ||
} | ||
@@ -69,4 +64,4 @@ /** | ||
*/ | ||
if (this.isMapValue(valueField)) { | ||
return this.extractObject(valueField.mapValue.fields); | ||
if (isMapValue(valueField)) { | ||
return extractObject(valueField.mapValue.fields); | ||
} | ||
@@ -83,17 +78,4 @@ /** | ||
}; | ||
/** | ||
* Check if object is `ArrayValue` | ||
*/ | ||
Adapter.prototype.isArrayValue = function (object) { | ||
return object.hasOwnProperty('arrayValue'); | ||
}; | ||
/** | ||
* Check if object is `MapValue` | ||
*/ | ||
Adapter.prototype.isMapValue = function (object) { | ||
return object.hasOwnProperty('mapValue'); | ||
}; | ||
return Adapter; | ||
}()); | ||
exports.Adapter = Adapter; | ||
exports.default = Adapter; | ||
return (input instanceof Array) ? input.map(function (obj) { return extractObject(obj); }) : extractObject(input); | ||
}; | ||
exports.default = convert; |
"use strict"; | ||
// import Adapter from './adapter'; | ||
// import { convert } from './adapter'; | ||
// import { data } from './resource'; | ||
@@ -8,6 +8,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// const adapter = new Adapter(data); | ||
// console.log(JSON.stringify(adapter.convert())); | ||
// const output = convert(data); | ||
// console.log(JSON.stringify(output)); | ||
var adapter_1 = __importDefault(require("./adapter")); | ||
exports.Adapter = adapter_1.default; | ||
exports.convert = adapter_1.default; | ||
exports.default = adapter_1.default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.data = [{ | ||
string: { | ||
stringValue: 'WASHINGTON' | ||
}, | ||
boolean: { | ||
booleanValue: true | ||
}, | ||
null: { | ||
nullValue: null | ||
}, | ||
double: { | ||
doubleValue: 523.3892 | ||
}, | ||
integer: { | ||
integerValue: '3' | ||
}, | ||
geoPoint: { | ||
geoPointValue: { | ||
latitude: 123.456, | ||
longitude: 234.23 | ||
} | ||
}, | ||
reference: { | ||
referenceValue: 'Reference' | ||
}, | ||
array: { | ||
arrayValue: { | ||
values: [ | ||
{ stringValue: 'abc' }, | ||
{ timestampValue: Date.now() }, | ||
{ | ||
arrayValue: { | ||
values: [ | ||
{ stringValue: 'abc' }, | ||
{ integerValue: '234' } | ||
] | ||
} | ||
}, | ||
{ | ||
mapValue: { | ||
fields: { | ||
integer: { | ||
integerValue: '1526' | ||
}, | ||
geoPoint: { | ||
geoPointValue: { | ||
latitude: 23.4, | ||
longitude: 2.45 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
}, | ||
maps: { | ||
mapValue: { | ||
fields: { | ||
double: { | ||
doubleValue: 523.3892 | ||
}, | ||
geoPoint: { | ||
geoPointValue: { | ||
latitude: 123.456, | ||
longitude: 234.23 | ||
} | ||
}, | ||
array: { | ||
arrayValue: { | ||
values: [ | ||
{ stringValue: 'abc' }, | ||
{ integerValue: '234' }, | ||
{ | ||
geoPointValue: { | ||
latitude: 123.456, | ||
longitude: 234.23 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
id: '53-0196605' | ||
}]; | ||
// export const data = { | ||
// string: { | ||
// stringValue: 'WASHINGTON' | ||
// }, | ||
// boolean: { | ||
// booleanValue: true | ||
// }, | ||
// null: { | ||
// nullValue: null | ||
// }, | ||
// double: { | ||
// doubleValue: 523.3892 | ||
// }, | ||
// integer: { | ||
// integerValue: '3' | ||
// }, | ||
// geoPoint: { | ||
// geoPointValue: { | ||
// latitude: 123.456, | ||
// longitude: 234.23 | ||
// } | ||
// }, | ||
// reference: { | ||
// referenceValue: 'Reference' | ||
// }, | ||
// array: { | ||
// arrayValue: { | ||
// values: [ | ||
// { stringValue: 'abc' }, | ||
// { timestampValue: Date.now() }, | ||
// { | ||
// arrayValue: { | ||
// values: [ | ||
// { stringValue: 'abc' }, | ||
// { integerValue: '234' } | ||
// ] | ||
// } | ||
// }, | ||
// { | ||
// mapValue: { | ||
// fields: { | ||
// integer: { | ||
// integerValue: '1526' | ||
// }, | ||
// geoPoint: { | ||
// geoPointValue: { | ||
// latitude: 23.4, | ||
// longitude: 2.45 | ||
// } | ||
// } | ||
// } | ||
// } | ||
// } | ||
// ] | ||
// }, | ||
// }, | ||
// maps: { | ||
// mapValue: { | ||
// fields: { | ||
// double: { | ||
// doubleValue: 523.3892 | ||
// }, | ||
// geoPoint: { | ||
// geoPointValue: { | ||
// latitude: 123.456, | ||
// longitude: 234.23 | ||
// } | ||
// }, | ||
// array: { | ||
// arrayValue: { | ||
// values: [ | ||
// { stringValue: 'abc' }, | ||
// { integerValue: '234' }, | ||
// { | ||
// geoPointValue: { | ||
// latitude: 123.456, | ||
// longitude: 234.23 | ||
// } | ||
// } | ||
// ] | ||
// } | ||
// } | ||
// } | ||
// } | ||
// }, | ||
// id: '53-0196605' | ||
// }; | ||
exports.data = { | ||
strein: { stringValue: '53-0196605' }, | ||
state: { stringValue: 'DC' }, | ||
name: { stringValue: 'AMERICAN NATIONAL RED CROSS' }, | ||
score: { doubleValue: 523.3892 }, | ||
have_filings: { nullValue: null }, | ||
have_pdfs: { nullValue: null }, | ||
subseccd: { integerValue: '3' }, | ||
ein: { integerValue: '530196605' }, | ||
city: { stringValue: 'WASHINGTON' }, | ||
sub_name: { stringValue: 'AMERICAN NATIONAL RED CROSS ' }, | ||
has_subseccd: { booleanValue: true }, | ||
ntee_code: { stringValue: 'P210' }, | ||
have_extracts: { nullValue: null }, | ||
raw_ntee_code: { stringValue: 'P210' }, | ||
id: '53-0196605' | ||
}; |
{ | ||
"name": "firestore-adapter", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Adapter to convert typed Firestore data into a standard format.", | ||
@@ -14,5 +14,3 @@ "main": "lib/index.js", | ||
"license": "ISC", | ||
"dependencies": { | ||
"implement-js": "0.0.26" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -19,0 +17,0 @@ "@types/node": "^11.9.5", |
import { ValueField, ArrayValue, MapValue } from './models'; | ||
/** | ||
* Adapter is a class to convert Firestore data into values without value types. | ||
* Converting Firestore data into values without value types. | ||
*/ | ||
export class Adapter { | ||
const convert = (input: ValueField[] | ValueField) => { | ||
constructor(private input: ValueField[]) { } | ||
/** | ||
* Check if object is `ArrayValue`, `MapValue` | ||
*/ | ||
const isArrayValue = (object: any): object is ArrayValue => object.hasOwnProperty('arrayValue'); | ||
const isMapValue = (object: any): object is MapValue => object.hasOwnProperty('mapValue'); | ||
public convert() { | ||
const output = this.input.map(obj => this.extractObject(obj)); | ||
return output; | ||
} | ||
/** | ||
@@ -32,3 +31,3 @@ * Extract an `Object`with types and values into pure values | ||
*/ | ||
private extractObject(value: ValueField) { | ||
const extractObject = (value: ValueField) => { | ||
const output: any = {}; | ||
@@ -38,3 +37,3 @@ // Extract value of each field | ||
const valueField = value[k]; | ||
output[k] = this.extractValueField(valueField); | ||
output[k] = extractValueField(valueField); | ||
}); | ||
@@ -54,3 +53,3 @@ return output; | ||
*/ | ||
private extractValueField(valueField: any): any { | ||
const extractValueField = (valueField: any): any => { | ||
/** | ||
@@ -60,4 +59,4 @@ * `ArrayValue` contains array of ValueField i.e. { values: [{stringValue: 'some value'}, ...] } | ||
*/ | ||
if (this.isArrayValue(valueField)) { | ||
return valueField.arrayValue.values.map(v => this.extractValueField(v)); | ||
if (isArrayValue(valueField)) { | ||
return valueField.arrayValue.values.map(v => extractValueField(v)); | ||
} | ||
@@ -68,4 +67,4 @@ /** | ||
*/ | ||
if (this.isMapValue(valueField)) { | ||
return this.extractObject(valueField.mapValue.fields); | ||
if (isMapValue(valueField)) { | ||
return extractObject(valueField.mapValue.fields); | ||
} | ||
@@ -83,17 +82,5 @@ /** | ||
/** | ||
* Check if object is `ArrayValue` | ||
*/ | ||
private isArrayValue(object: any): object is ArrayValue { | ||
return object.hasOwnProperty('arrayValue'); | ||
} | ||
/** | ||
* Check if object is `MapValue` | ||
*/ | ||
private isMapValue(object: any): object is MapValue { | ||
return object.hasOwnProperty('mapValue'); | ||
} | ||
return (input instanceof Array) ? input.map(obj => extractObject(obj)) : extractObject(input); | ||
} | ||
export default Adapter | ||
export default convert |
@@ -1,13 +0,13 @@ | ||
// import Adapter from './adapter'; | ||
// import { convert } from './adapter'; | ||
// import { data } from './resource'; | ||
// const adapter = new Adapter(data); | ||
// console.log(JSON.stringify(adapter.convert())); | ||
// const output = convert(data); | ||
// console.log(JSON.stringify(output)); | ||
import Adapter from './adapter' | ||
import convert from './adapter'; | ||
export { | ||
Adapter | ||
convert | ||
} | ||
export default Adapter | ||
export default convert |
@@ -1,87 +0,104 @@ | ||
export const data = [{ | ||
string: { | ||
stringValue: 'WASHINGTON' | ||
}, | ||
boolean: { | ||
booleanValue: true | ||
}, | ||
null: { | ||
nullValue: null | ||
}, | ||
double: { | ||
doubleValue: 523.3892 | ||
}, | ||
integer: { | ||
integerValue: '3' | ||
}, | ||
geoPoint: { | ||
geoPointValue: { | ||
latitude: 123.456, | ||
longitude: 234.23 | ||
} | ||
}, | ||
reference: { | ||
referenceValue: 'Reference' | ||
}, | ||
array: { | ||
arrayValue: { | ||
values: [ | ||
{ stringValue: 'abc' }, | ||
{ timestampValue: Date.now() }, | ||
{ | ||
arrayValue: { | ||
values: [ | ||
{ stringValue: 'abc' }, | ||
{ integerValue: '234' } | ||
] | ||
} | ||
}, | ||
{ | ||
mapValue: { | ||
fields: { | ||
integer: { | ||
integerValue: '1526' | ||
}, | ||
geoPoint: { | ||
geoPointValue: { | ||
latitude: 23.4, | ||
longitude: 2.45 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
}, | ||
maps: { | ||
mapValue: { | ||
fields: { | ||
double: { | ||
doubleValue: 523.3892 | ||
}, | ||
geoPoint: { | ||
geoPointValue: { | ||
latitude: 123.456, | ||
longitude: 234.23 | ||
} | ||
}, | ||
array: { | ||
arrayValue: { | ||
values: [ | ||
{ stringValue: 'abc' }, | ||
{ integerValue: '234' }, | ||
{ | ||
geoPointValue: { | ||
latitude: 123.456, | ||
longitude: 234.23 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
// export const data = { | ||
// string: { | ||
// stringValue: 'WASHINGTON' | ||
// }, | ||
// boolean: { | ||
// booleanValue: true | ||
// }, | ||
// null: { | ||
// nullValue: null | ||
// }, | ||
// double: { | ||
// doubleValue: 523.3892 | ||
// }, | ||
// integer: { | ||
// integerValue: '3' | ||
// }, | ||
// geoPoint: { | ||
// geoPointValue: { | ||
// latitude: 123.456, | ||
// longitude: 234.23 | ||
// } | ||
// }, | ||
// reference: { | ||
// referenceValue: 'Reference' | ||
// }, | ||
// array: { | ||
// arrayValue: { | ||
// values: [ | ||
// { stringValue: 'abc' }, | ||
// { timestampValue: Date.now() }, | ||
// { | ||
// arrayValue: { | ||
// values: [ | ||
// { stringValue: 'abc' }, | ||
// { integerValue: '234' } | ||
// ] | ||
// } | ||
// }, | ||
// { | ||
// mapValue: { | ||
// fields: { | ||
// integer: { | ||
// integerValue: '1526' | ||
// }, | ||
// geoPoint: { | ||
// geoPointValue: { | ||
// latitude: 23.4, | ||
// longitude: 2.45 | ||
// } | ||
// } | ||
// } | ||
// } | ||
// } | ||
// ] | ||
// }, | ||
// }, | ||
// maps: { | ||
// mapValue: { | ||
// fields: { | ||
// double: { | ||
// doubleValue: 523.3892 | ||
// }, | ||
// geoPoint: { | ||
// geoPointValue: { | ||
// latitude: 123.456, | ||
// longitude: 234.23 | ||
// } | ||
// }, | ||
// array: { | ||
// arrayValue: { | ||
// values: [ | ||
// { stringValue: 'abc' }, | ||
// { integerValue: '234' }, | ||
// { | ||
// geoPointValue: { | ||
// latitude: 123.456, | ||
// longitude: 234.23 | ||
// } | ||
// } | ||
// ] | ||
// } | ||
// } | ||
// } | ||
// } | ||
// }, | ||
// id: '53-0196605' | ||
// }; | ||
export const data = { | ||
strein: { stringValue: '53-0196605' }, | ||
state: { stringValue: 'DC' }, | ||
name: { stringValue: 'AMERICAN NATIONAL RED CROSS' }, | ||
score: { doubleValue: 523.3892 }, | ||
have_filings: { nullValue: null }, | ||
have_pdfs: { nullValue: null }, | ||
subseccd: { integerValue: '3' }, | ||
ein: { integerValue: '530196605' }, | ||
city: { stringValue: 'WASHINGTON' }, | ||
sub_name: { stringValue: 'AMERICAN NATIONAL RED CROSS ' }, | ||
has_subseccd: { booleanValue: true }, | ||
ntee_code: { stringValue: 'P210' }, | ||
have_extracts: { nullValue: null }, | ||
raw_ntee_code: { stringValue: 'P210' }, | ||
id: '53-0196605' | ||
}]; | ||
}; |
22816
0
558
- Removedimplement-js@0.0.26
- Removedimplement-js@0.0.26(transitive)
- Removedinvariant@2.2.2(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removeduuid@3.1.0(transitive)
- Removedwarning@3.0.0(transitive)