MCPcopy Create free account
hub / github.com/cryptii/cryptii / extract

Method extract

src/Pipe.js:1055–1174  ·  view source on GitHub ↗

* Extracts pipe from structured data. * @param {mixed} data Structured data * @param {Factory} brickFactory Brick factory used for brick creation * @throws {Error} Throws an error if structured data is malformed. * @return {Pipe} Extracted pipe

(data, brickFactory)

Source from the content-addressed store, hash-verified

1053 * @return {Pipe} Extracted pipe
1054 */
1055 static extract (data, brickFactory) {
1056 // Verify items
1057 if (!Array.isArray(data.items) || data.items.length === 0) {
1058 throw new Error(
1059 'Pipe property \'items\' is expected to be of type \'array\' ' +
1060 'and must not be empty')
1061 }
1062
1063 // Create pipe instance
1064 const pipe = new Pipe()
1065 pipe.setBrickFactory(brickFactory)
1066 pipe.addBricks(data.items)
1067
1068 // Handle id property
1069 if (data.id !== undefined && data.id !== null) {
1070 if (typeof data.id !== 'number') {
1071 throw new Error(
1072 'Optional pipe property \'id\' is expected to be of type \'number\'')
1073 }
1074 pipe.setId(data.id)
1075 }
1076
1077 // Handle url property
1078 if (data.url !== undefined && data.url !== null) {
1079 if (typeof data.url !== 'string') {
1080 throw new Error(
1081 'Optional pipe property \'url\' is expected to be of type \'string\'')
1082 }
1083 pipe.setUrl(data.url)
1084 }
1085
1086 // Handle title property
1087 if (data.title !== undefined && data.title !== null) {
1088 if (typeof data.title !== 'string') {
1089 throw new Error(
1090 'Optional pipe property \'title\' is expected to be of ' +
1091 'type \'string\'')
1092 }
1093 pipe.setTitle(data.title)
1094 }
1095
1096 // Handle description property
1097 if (data.description !== undefined && data.description !== null) {
1098 if (typeof data.description !== 'string') {
1099 throw new Error(
1100 'Optional pipe property \'description\' is expected to be of ' +
1101 'type \'string\'')
1102 }
1103 pipe.setDescription(data.description)
1104 }
1105
1106 // Handle content property
1107 let content = ''
1108 let bucket = 0
1109
1110 if (data.content !== undefined && data.content !== null) {
1111 if (typeof data.content !== 'object') {
1112 throw new Error(

Callers 3

Pipe.jsFile · 0.45
spliceBricksMethod · 0.45
runMethod · 0.45

Calls 12

setBrickFactoryMethod · 0.95
addBricksMethod · 0.95
setIdMethod · 0.95
setUrlMethod · 0.95
setTitleMethod · 0.95
setDescriptionMethod · 0.95
getLengthMethod · 0.95
getBucketLengthMethod · 0.95
getBrickMethod · 0.95
setContentMethod · 0.95
bytesFromBase64StringMethod · 0.80

Tested by

no test coverage detected