Best JavaScript code snippet using mountebank
dump-load.js
Source:dump-load.js
1import * as FT from "../extend/feature-tools.js";2// ÑкÑпоÑÑ ÑоÑÑоÑÐ½Ð¸Ñ Ð´ÐµÑева обÑекÑов nodesystem в json-пÑоÑÑой обÑекÑ3// а Ñакже Ñоздание деÑева по ÑÑÐ¾Ð¼Ñ ÑоÑÑоÑниÑ4// update: manualParamsMode полÑÑаеÑÑÑ ÑÑо Ð¸Ð´ÐµÑ Ð¿Ñизнак иÑÑоÑника воÑÑÑÐ°Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ Ð¸ ÑообÑазно Ñазное поведение5// manualParamsMode=true => вÑе паÑамеÑÑÑ ÑÑиÑаÑÑÑÑ Ð²ÑÑÑавленнÑе вÑÑÑнÑÑ, setParam( .... true )6// ÑÑо пÑÐ¸Ð²ÐµÐ´ÐµÑ Ð¿Ñи далÑнейÑем дампе к иÑ
ÑоÑ
ÑÐ°Ð½ÐµÐ½Ð¸Ñ Ð² дамп7// manualParamsMode=false => вÑе паÑамеÑÑÑ ÑÑиÑаÑÑÑÑ ÑÑÑанавливаемÑми пÑогÑаммно и ÑообÑазно поÑом в дамп не попадÑÑ8// и более Ñого, ÑÑо иÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð°Ð½Ð°Ð»Ð¸Ð·Ð° ÑÑиÑÐ°Ð½Ð¸Ñ Ð¾Ð±ÑекÑов коÑоÑÑе не ÑпоминаÑÑÑÑ Ð² дампе9// todo пеÑеÑазобÑаÑÑÑÑ Ñ manual и forcecreate(dumpyInserted) - ÑÑÑ Ð³Ð´Ðµ-Ñо ÑÑвÑÑвÑеÑÑÑ ÑÑо бÑÐ´ÐµÑ ÑÑноÑÑÑ Ð¿ÑиÑин.10export default function setup( m ) {11 // Ñоздание деÑева по json-опиÑаниÑ12 // Ñ Ð²Ð¾Ð·Ð¼Ð¾Ð¶Ð½Ð¾ÑÑÑÑ ÑинÑ
ÑонизаÑии в ÑÑÑеÑÑвÑÑÑее деÑево13 14 // вÑÑÑнилоÑÑ ÑÑо Ñаз Ð¼Ñ Ð½Ðµ деÑжим во вÑÑзавÑе коÑнÑ,15 // Ñо надо ÑмеÑÑ ÑоздаваÑÑ Ð¾Ð±ÑекÑÑ Ð¿Ð¾ дампÑ..16 // но - как нам ÑÑо Ð¿Ð¾Ð¼Ð¾Ð¶ÐµÑ Ð²ÑÑÑавлÑÑÑ Ð¿Ð°ÑамеÑÑÑ Ð½Ð° Ñозданной ÑÑене?17 // видимо ÑÑо вÑе-Ñаки ÑоздаÑÑе-ÑинÑ
ÑонизиÑÑÑÑÐ°Ñ ÑÑнкÑиÑ18 // и ее вÑоÑой аÑгÑÐ¼ÐµÐ½Ñ ÑÑо как Ñаз - ÑекÑÑий имеÑÑийÑÑ Ð¾Ð±ÑекÑ19 // коÑоÑе Ñ Ð²Ñе еÑе в ÑомнениÑÑ
- ÑÑÑ ÑмеÑано полÑÑаеÑÑÑ Ñоздание деÑева по опиÑаниÑ20 // и 2) ÑинÑ
ÑонизаÑÐ¸Ñ ÑÑого деÑева из опиÑаниÑ, и 21 // и еÑе ÑÑо ÑпиÑаеÑÑÑ Ð² ÑиÑÑаÑÐ¸Ñ Ð° ÑÑо еÑли коÑÐµÐ½Ñ Ð´ÐµÑева в памÑÑи не Ñого Ñипа ÑÑо в опиÑании?22 23 // returns promise24 25 m.createSyncFromDump = function( dump, _existingObj, parent, desiredName, manualParamsMode, $scopeFor )26 {27 // ÑÑо из ÑпиÑков.. пÑиÑобаÑиваÑÑ Ð¿Ð¾Ð²ÐµÑÑ
вÑего ÑÑо заÑ
оÑÑÑ Ð´Ð°Ð²Ð°ÑÑ..28 if (dump.$scopeFor) {29 // но еÑÑÑ ÑлÑÑай когда Ð¼Ñ ÑÑо Ñже ÑÑли, и Ñогда ÑÑого делаÑÑ Ð½Ðµ надо30 if (!$scopeFor?.skip_dump_scopes)31 $scopeFor = dump.$scopeFor;32 }33 //let scopeFor_param = $scopeFor;34 if (!$scopeFor) {35 //debugger;36 if (_existingObj)37 $scopeFor = _existingObj.$scopes.top();38 }39 // вÑоде как не положено емÑ. он ж ÑÑÑной, Ð¾Ñ Ð¿Ð¾Ð»ÑзоваÑелÑ.. (из дампа поди пÑиÑел ÑÑÑаниÑÑ)40 // но вÑÑÑнилоÑÑ ÑÑо пÑоÑивоÑеÑÐ¸Ñ ÑиÑÑаÑии когда Ð¼Ñ Ð¿ÑÑаемÑÑ Ð¸Ð·Ð¾Ð±ÑазиÑÑ Ð´ÐµÐ¹ÑÑÐ²Ð¸Ñ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ Ð° пÑи ÑÑом Ñаки опиÑаемÑÑ Ð½Ð° scope..41 // напÑÐ¸Ð¼ÐµÑ Ð² аÑгÑменÑаÑ
make={ |a b| some @a @b } и оно Ñам ÑоÑ
ÑÐ°Ð½Ð¸Ñ ÑÑи a b но пеÑедаÑÑ Ð¸Ñ
надо..42 // if (dump.manual) $scopeFor = null;43 // вÑÑÑнилоÑÑ ÑÑо Ñ Ð½Ð°Ñ Ð¼Ð¾Ð³ÑÑ Ð½Ð° пÑомиÑаÑ
ÑпаÑиÑÑ Ñоздание деÑей вовÑÑ, когда обÑÐµÐºÑ Ñже ÑеÑили ÑдалиÑÑ44 if (parent && parent.removed) {45 return Promise.resolve("parent_removed");46 }47 /*48 if (parent) {49 let root = parent.findRoot();50 if (root.getPath().split("/").length > 2)51 debugger;52 }53 */54 var obj = _existingObj;55 if (!obj || (dump.type && obj.historicalType != dump.type && dump.manual)) {56 if (!obj || obj.ns.parent) { // пÑÑÑÑ ÑÑо ÑабоÑÐ°ÐµÑ Ð¿Ð¾ÐºÐ° не Ð´Ð»Ñ ÐºÐ¾ÑÐ½Ñ Ð´ÐµÑева - Ñам непонÑÑно мне пока57 // var opts = { parent: parent, type: dump.type, name: dump.name }58 var opts = Object.assign( {}, dump, { parent: parent, name: desiredName } );59 obj = dump.type ? m.create_obj_by_type( opts ) : m.createObj( opts );60 if (!obj) {61 console.error("createSyncFromDump: failed to create object! opts=",opts);62 console.error("will create some obj to avoid js errors, but it is not the desired one");63 obj = m.createObj( { parent: parent, name: desiredName || "ehh" });64 }65 //obj.$vz_created_by_dump = dump; // поÑ
Ñаним...66 //obj.$vz_features_from_dump = dump.features;67 }68 }69 // в dump должно бÑÑÑ Ð¿Ð¾Ð»Ðµ type, оно нам вÑе и ÑоздаÑÑ ÑÑо надо70 71// if (!$scopeFor)72// $scopeFor = obj.$scopes.createScope("createSyncFromDump");73 // F-FEAT-PARAMS74 if (dump.feature_of_env) {75 obj.hosted = true;76 obj.host = dump.feature_of_env;77 } else {78 obj.hosted = false;79 obj.host = obj;80 }81 // F-LEXICAL-PARENT82 if (dump.lexicalParent)83 obj.lexicalParent = dump.lexicalParent;84 // неопиÑанное еÑе пÑиклÑÑение85 if (dump.$name) {86 obj.$env_extra_names ||= {};87 obj.$env_extra_names[ dump.$name ] = true;88 };89 // F-SCOPE90 let name_for_scope = desiredName || dump.$name;91 if ($scopeFor && !_existingObj) {92 obj.$scopes.addScopeRef( $scopeFor );93 if (dump.name_is_autogenerated)94 {95 // ниÑего не делаем, не заÑоÑÑем ÑÑедÑ96 dump.name_is_autogenerated;97 }98 else99 {100 if (name_for_scope == null || name_for_scope == "")101 console.error("scopes: name_for_scope is blank",name_for_scope,obj)102 if ($scopeFor[ name_for_scope ]) {103 console.error("scopes: duplicated name!",name_for_scope,'me=',obj,'existing=',$scopeFor[ name_for_scope ])104 if (dump.locinfo)105 console.log( dump.locinfo );106 }107 else108 $scopeFor.$add( name_for_scope, obj );109 };110 }111 if (dump.locinfo)112 obj.$locinfo = dump.locinfo;113 //let keepExistingParamsOrig = dump.keepExistingParams;114 // ÑÑеÑÐ¾Ð²Ð°Ñ Ð»Ð¾Ð³Ð¸ÐºÐ° но пока лÑÑÑе не пÑидÑмал115 // еÑли Ð¼Ñ Ð² Ñежиме ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð½Ð¾Ð²Ð¾Ð³Ð¾ обÑекÑа Ñо - надо вклÑÑаÑÑ Ð¸ Ð»Ð¾Ð³Ð¸ÐºÑ ÑоÑ
ÑÐ°Ð½ÐµÐ½Ð¸Ñ Ð¿Ð°ÑамеÑÑов116 // ÑÑÐ¾Ð±Ñ Ð²Ð½Ð¾Ð²Ñ Ð¿Ð¾ÑÑÑпаÑÑие ÑиÑи, паÑамеÑÑÑ, ÑÑÑлки, не заÑиÑали Ñо ÑÑо Ñже Ñоздано117 /*118 if (!_existingObj) {119 dump.keepExistingParams = true; 120 }121 */122/*123 if (dump.$scopeParent) {124 obj.$scopes.addScopeRef( dump.$scopeParent );125 // окей ÑоÑ
Ñанили на паÑенÑа. ÑепеÑÑ Ð½Ð°Ð´Ð¾ в него запиÑаÑÑÑÑ..126 if (dump.$scopeParent[ desiredName ]) {127 if (!dump.name_is_autogenerated)128 console.error("scopes: duplicated name!",desiredName,obj)129 }130 else131 dump.$scopeParent[ desiredName ] = obj;132 }133*/134 /// поÑ
Ð¾Ð´Ñ Ð½Ð°Ð´Ð¾ паÑамеÑÑÑ Ð´Ð¾ ÑÐ¸Ñ Ñаки.. но Ñогда непонÑÑно ÑÑо еÑÑÑ restorefromdump...135 //let p1 = m.restoreFeatures( dump, obj, manualParamsMode, $scopeFor );136 // Ñаким обÑазом ÑиÑи имеÑÑ Ð²Ð¾Ð·Ð¼Ð¾Ð¶Ð½Ð¾ÑÑÑ Ð·Ð°Ð¼ÐµÐ½Ð¸ÑÑ obj.restoreFromDump137 // и ÑÑаÑÑ ÑÑнкÑоÑами138 //if (obj.removed)139 //debugger;140 let res = obj.restoreFromDump( dump,manualParamsMode, $scopeFor )141 // оÑпÑавим ÑобÑÑие ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð¾Ð±ÑекÑа142 // Ñ
оÑÑ Ð²ÐµÑоÑÑно его ÑÑÐ¾Ð¸Ñ Ð·Ð°Ð¿Ð¸Ñ
аÑÑ Ð² ÑиÑи.. но вопÑÐ¾Ñ ÑÑо ÑÑо должно бÑÑÑ Ð¿Ð¾Ñледним143 res.then( (res2) => {144 // @exp - ÑÐ¿Ñ ÐºÐ¾Ð³Ð´Ð° ÑиÑи вÑе из опиÑÐ°Ð½Ð¸Ñ Ð¿ÑимененÑ, и паÑамеÑÑÑ, и деÑи145 if (!_existingObj) {146 obj.emit("cocreate");147 }; // idea и еÑе emit("synced");148 });149 return res;150 }151 152 // ÑеÑÑовое - полÑÑаеÑÑÑ ÑÐ¾Ð·Ð´Ð°ÐµÑ obj а наполнение поÑом Ñж153 m.createSyncFromDumpNow = function( dump, _existingObj, parent, desiredName )154 {155 debugger;156 var obj = _existingObj;157 if (!obj || (dump.type && obj.historicalType != dump.type && dump.manual)) {158 if (!obj || obj.ns.parent) { // пÑÑÑÑ ÑÑо ÑабоÑÐ°ÐµÑ Ð¿Ð¾ÐºÐ° не Ð´Ð»Ñ ÐºÐ¾ÑÐ½Ñ Ð´ÐµÑева - Ñам непонÑÑно мне пока159 // var opts = { parent: parent, type: dump.type, name: dump.name }160 var opts = Object.assign( {}, dump, { parent: parent, name: desiredName } );161 obj = dump.type ? m.create_obj_by_type( opts ) : m.createObj( opts );162 if (!obj) {163 console.error("createSyncFromDump: failed to create object! opts=",opts);164 console.error("will create some obj to avoid js errors, but it is not the desired one");165 obj = m.createObj( { parent: parent, name: desiredName || "ehh" });166 }167 }168 }169 // в dump должно бÑÑÑ Ð¿Ð¾Ð»Ðµ type, оно нам вÑе и ÑоздаÑÑ ÑÑо надо170 // F-FEAT-PARAMS171 if (dump.feature_of_env) {172 obj.hosted = true;173 obj.host = dump.feature_of_env;174 } else {175 obj.hosted = false;176 obj.host = obj;177 }178 debugger;179 // F-LEXICAL-PARENT180 if (dump.lexicalParent)181 obj.lexicalParent = dump.lexicalParent;182 // неопиÑанное еÑе пÑиклÑÑение183 if (dump.$name) {184 obj.$env_extra_names ||= {};185 obj.$env_extra_names[ dump.$name ] = true;186 } 187 m.restoreFeatures( dump, obj );188 // Ñаким обÑазом ÑиÑи имеÑÑ Ð²Ð¾Ð·Ð¼Ð¾Ð¶Ð½Ð¾ÑÑÑ Ð·Ð°Ð¼ÐµÐ½Ð¸ÑÑ obj.restoreFromDump189 // и ÑÑаÑÑ ÑÑнкÑоÑами190 obj.restoreFromDump( dump );191 return obj;192 }193 m.restoreParams = function ( dump, obj, manualParamsMode, $scopeFor) {194 if (dump.manual) manualParamsMode = true; // Ñакой Ð²Ð¾Ñ Ð¿Ñием.. а Ñо "ÑÑÑнÑе обÑекÑÑ" поÑом не ÑоÑ
ÑаниÑÑ Ð¿Ð¾Ð»ÑÑаеÑÑÑ..195 var h = dump.params || {};196 var keys = Object.keys(h);197 keys.forEach( function(name) {198 //console.log("setting param",name,h[name]);199 // if (name == "manual_features") return; // пÑовеÑка200 // F-KEEP-EXISTING-PARAMS201 if (dump.keepExistingParams && (obj.hasParam( name ) || obj.hasLinksToParam( name ))) return;202 let v = h[name];203 // ÑиÑка. v ÑÑо Ñ Ð½Ð°Ñ Ð¾Ð±Ñее опиÑание на ÑÑовне dump.204 // еÑли Ð¼Ñ ÑÑда пÑопиÑÑваем lexicalParent Ñо Ð¼Ñ Ð¿Ð¸Ñем в обÑÑÑ Ð·Ð°Ð¿Ð¸ÑÑ205 // ÑÑо надо ÑпеÑиалÑнÑм обÑазом как-Ñо заÑеÑаÑÑ206 // F-LEXICAL-PARENT207 // здеÑÑ Ð¿ÑоиÑÑ
Ð¾Ð´Ð¸Ñ Ð½Ð°Ð·Ð½Ð°Ñение "лекÑиÑеÑкого ÑодиÑелÑ" в dump-опиÑÐ°Ð½Ð¸Ñ Ð¾ÐºÑÑжений, Ñ
ÑанимÑÑ
в паÑамеÑÑаÑ
208 let bemanual = manualParamsMode;209 if (v?.needLexicalParent) {210 if (!$scopeFor)211 debugger;212 //v.lexicalParent = obj;213 if (Array.isArray(v)) // Ñам ÑпиÑок окÑÑжений - вÑем назнаÑим..214 {215 // ÑÑаÑое for (let q of v) q.lexicalParent = obj;216 // новое - Ñделаем ÑÑпо, поÑом можно опÑимизиÑоваÑÑ Ð½Ð°Ð¿ÑÐ¸Ð¼ÐµÑ ÑÐ¾Ð·Ð´Ð°Ð²Ð°Ñ ÑпеÑ-ÑÑÑÑкÑÑÑÑ217 // вида newrecord -> lexicalparent, array..218 219 let ea = v.env_args; // F-ENV-ARGS220 v = v.map(a => ({...a})); // Ñипо копиÑÑем.. Ð½Ñ Ð¾Ðº...221 if (ea) // F-ENV-ARGS222 v.env_args = ea;223 // updated224 // for (let q of v) q.lexicalParent = obj;225 for (let q of v) 226 q.$scopeFor = $scopeFor;227 //v.this_is_env_list_description = true; 228 bemanual=false;229 }230 }231 obj.setParam( name, v, bemanual ); // ÑÑавим true - в Ñом ÑмÑÑле ÑÑо ÑÑо ÑÑÑановка из232 // F-SCOPE-PARAMS233 /* пеÑенеÑено в ÑиÑÑ var234 if (obj.is_feature_applied("data"))235 {236 if (Number.isInteger(parseFloat(name)) || name == "args_count")237 {238 }239 else {240 if ($scopeFor[ name ]) {241 console.error("scopes: data param duplicated name!",name,'me=',obj,'cell ',name,'existing=',$scopeFor[ name ])242 if (dump.locinfo)243 console.log( dump.locinfo );244 }245 else246 {247 $scopeFor.$add( name, obj.get_cell(name) );248 console.log("data: added name to scope",name,$scopeFor)249 } 250 };251 };252 */253 // F-LINKS-OVERWRITE254 // ÑдалиÑÑ ÑÑÑлки пиÑÑÑие в ÑÑÐ¾Ñ Ð¿Ð°ÑамеÑÑ... Ñипа Ð¼Ñ ÑÑÑ Ñо знаÑением пÑиÑли...255 // и Ñ ÑÑеÑом ÑÑо Ñ Ð½Ð°Ñ Ð²Ñе ÑÐ½Ð¸Ð·Ñ Ð²Ð²ÐµÑÑ
ÑепеÑÑ ÑаÑкÑÑваеÑÑÑ - ÑÑо ÑÑабоÑаеÑ256 // и плÑÑ Ñже ÑÑÑено keepExistingParams257 if (obj.hasLinksToParam( name )) {258 let larr = obj.linksToParam( name );259 for (let l of larr)260 if (l.params.manual_mode)261 {262 // ладно ÑакÑÑ ÑÑÑÐ»ÐºÑ Ð¾ÑÑавим263 // ибо она ÑаÑÑÑ Ð¼ÐµÑ
аники поÑ
оже какой-Ñо264 }265 else266 {267 //console.log("p-removing link:", l.getPath(), "reason - setting param",name )268 // вÑеменнÑй Ñ
ак. он в Ñом ÑÑо еÑли вÑÑÑавлено manual_mode ÑÑо знаÑÐ¸Ñ ÑÑо ÑÑа ÑÑÑлка обеÑпеÑиваеÑ269 // запиÑÑ Ð² ÑÑÑном Ñежиме оÑкÑда-Ñо.. и ее ÑÑало бÑÑÑ Ð·Ð°ÑиÑаÑÑ Ð½Ðµ надобно..270 if (!l.params.manual_mode)271 {272 l.remove();273 }274 }275 }276 277 });278 ///// оÑобÑй ÑлÑÑай - паÑамеÑÑÑ Ð·Ð½Ð°Ñение коÑоÑÑÑ
ÑÑо ÑпиÑок окÑÑжений279 // им надо вÑÑÑавиÑÑ lexicalParent280/*281 var h = dump.env_list_params || {};282 var keys = Object.keys(h);283 keys.forEach( function(name) {284 //console.log("setting param",name,h[name]);285 // F-KEEP-EXISTING-PARAMS286 if (dump.keepExistingParams && obj.hasParam( name )) return;287 let v = h[name];288 v.lexicalParent = obj;289 obj.setParam( name, v, manualParamsMode ); // ÑÑавим true - в Ñом ÑмÑÑле ÑÑо ÑÑо ÑÑÑановка из290 });291*/292 293 }294 // ÑÐµÐ»Ñ - акÑивиÑоваÑÑ Ð² окÑÑжении новÑÑ ÑиÑÑ, опÑеделеннÑÑ Ð² dump295 // оÑлиÑие в Ñом, ÑÑо Ñам не пÑоÑÑо имÑ, а Ñелое новое под-окÑÑжение296 // и Ð¼Ñ Ð½Ðµ можем ÑоздаÑÑ ÑнаÑала под-окÑÑжение а поÑом его пÑиÑепиÑÑ297 // поÑÐ¾Ð¼Ñ ÑÑо пÑи Ñоздании пÑоиÑÑ
Ð¾Ð´Ð¸Ñ Ð°ÐºÑиваÑÐ¸Ñ ÑиÑ, и им Ñже надо знаÑÑ298 // ÑÑо они акÑивиÑÑÑÑÑÑ Ð² Ñежиме аÑÑаÑа к оÑÐ½Ð¾Ð²Ð½Ð¾Ð¼Ñ Ð½Ð¾Ð²Ð¾Ð¼Ñ Ð¾ÐºÑÑжениÑ..299 m.importAsParametrizedFeature = function( dump,obj, $scopeFor ) {300 // todo замениÑÑ ÑÑо вÑе на ÑабоÑÑ Ñ Ð´ÐµÑевом..301 dump.feature_of_env = obj;302 dump.keepExistingChildren = true; // без ÑÑой ÑÑÑки оно наÑÐ¸Ð½Ð°ÐµÑ ÑÑиÑаÑÑ ÑвоиÑ
ÑобÑÑвеннÑÑ
деÑей303 // не надо воÑÑÑанливаÑÑ ()-окÑÑжениÑ304 // F-LINKS-OVERWRITE305 306 if (dump.features.computer && dump.keepExistingParams) {307 let links = Object.values( dump.links );308 let link = links[0];309 if (links.length > 1)310 debugger;311 312 let output_param_name = link.to.split("->")[1];313 if (obj.hasParam(output_param_name) || obj.hasLinksToParam( output_param_name ))314 {315 // Ð²Ð¾Ñ Ð½Ð°Ð¼ знаÑÐ¸Ñ Ñже и не надо ÑÑÐ¾Ñ Ð¾Ð±ÑекÑ.316 //console.warn("shadowed computing env skipping", output_param_name, dump, obj )317 return null;318 }319 }320 //fr.keepExistingChildren = true; // ÑÑÑанно ÑÑо вÑе...321 let prom = m.createSyncFromDump( dump, null, null, dump.$name,false, $scopeFor );322 return new Promise( (resolve,reject) => {323 prom.then( (feature_obj) => {324 // еÑли ÑÑо Ñ Ð½Ð°Ñ ()-вÑÑиÑлиÑелнÑй обÑекÑ, и ÑдалÑÑÑ ÑÑÑÐ»ÐºÑ ÑезÑлÑÑаÑа325 // Ñо и ÑÑÐ¾Ñ Ð¾Ð±ÑÐµÐºÑ Ð½Ð°Ð´Ð¾ ÑдалиÑÑ.326 if (dump.features.computer) {327 //debugger;328 let output_link = feature_obj.ns.getChildByName("arg_link_to");329 if (output_link)330 {331 output_link.on("remove", () => {332 //console.warn("shadowed computing env removed due output link", output_link.params.to, dump, obj )333 if (!feature_obj)334 feature_obj.remove()335 } );336 }337 else {338 // коÑоÑе еÑли Ñам Ð½ÐµÑ Ñже ÑÑÑлки - знаÑÐ¸Ñ ÐµÐµ поÑеÑли339 // и знаÑим нам наÑе вÑÑиÑление Ñож надо поÑеÑеÑÑ340 // ппÑ.341 debugger;342 feature_obj.remove();343 reject();344 return;345 //debugger;346 }347 }348 // как вÑÑÑнилоÑÑ Ð¸ Ð²Ð¾Ñ Ñак бÑваеÑ349 if (obj.removed)350 {351 feature_obj.remove();352 reject();353 return;354 }355 //arr.push( feature_obj );356 //feature_obj.lexialParent = obj;357 //feature_obj.master_env = obj;358 //obj.feature_359 // todo надо Ð±Ñ Ð¸Ñ
в деÑево поÑадиÑÑ... Ñем более Ñам по именам поÑом заÑ
оÑеÑÑÑ Ñ
одиÑÑ..360 // Ð²Ð¾Ñ Ð·Ð´ÐµÑÑ Ð¿Ð¾Ð»ÑÑаеÑÑÑ ÑÑо Ð¼Ñ Ð²ÑÑÑбаем x-on "remove"... todo361 // мбÑÑÑ ÑделаÑÑ on_prepend = добавиÑÑ Ð² наÑало оÑеÑеди...362 //console.log("adding ",dump.$name,"and starting monitor remove of host",obj.$vz_unique_id)363 let forget_that = obj.on("remove",() => {364 forget_that = () => {};365 //console.log("calling feature_obj.remove",feature_obj.$vz_unique_id,"because obj is removing",obj.$vz_unique_id)366 feature_obj.remove();367 });368 // $feature_name заÑем иÑполÑзÑеÑÑÑ... вÑÑÑниÑÑ ÐºÐ°ÐºÑÑ ÑеманÑÐ¸ÐºÑ Ñ Ð² него вложил..369 feature_obj.$feature_name = dump.$name || "some_feature"; /// ......370 obj.$feature_list_envs ||= [];371 obj.$feature_list_envs.push( feature_obj );372 obj.$feature_list_envs_table ||= {};373 let kname = feature_obj.$feature_name;374 while (obj.$feature_list_envs_table[kname]) {375 // @todo ÑÑо меÑÑо Ð¿Ð¸Ð¿ÐµÑ ÐºÐ¾Ð½ÐµÑно.. надо под-окÑÑÐ¶ÐµÐ½Ð¸Ñ ÑникалÑнÑе ÑоздаваÑÑ Ð¸Ð»Ð¸ Ñипа Ñого..376 //console.warn("$feature_list_envs_table DUPLICATE DETECTED, $feature_name=",kname)377 kname = kname + "_x";378 //console.warn("renamed to",kname);379 }380 obj.$feature_list_envs_table[kname] = feature_obj;381 // надо Ð±Ñ Ð·Ð°Ð¿Ð¾Ð¼Ð½Ð¸ÑÑ, как Ð¼Ñ ÐµÐµ запомнили..382 feature_obj.$feature_name = kname;383 // пÑоÑокол F-NEW-MODIFIERS-FTREE384 385 let detach_code = feature_obj.emit("attach",obj)386 // вÑемÑнка некаÑ.. 387 /*388 let feature_obj_got_attached_signal = false;389 if (!(feature_obj.hasParam("input") || feature_obj.hasLinksToParam("input"))) {390 feature_obj.emit("attach",obj)391 feature_obj_got_attached_signal = true;392 }393 */394 // еÑли ÑиÑÑ Ð¿ÑоÑÑо Ñак ÑдалÑÑÑ Ð±ÑдÑÑ - надо оÑвободиÑÑ ÑодиÑелÑ395 feature_obj.on("remove",() => {396 forget_that()397 // пÑоÑокол F-NEW-MODIFIERS-FTREE398 feature_obj.emit("detach",obj);399 //if (feature_obj_got_attached_signal)400 // feature_obj.emit("detach",obj);401 // detach_code();402 if (!obj.removed) {403 // поÑиÑÑиÑÑ ÑаблиÑÑ ÐµÑе надо404 // по ÑÑÑи Ð¼Ñ ÑÑÑ children-ÑаблиÑÑ Ð·Ð°Ð½Ð¾Ð²Ð¾ пиÑем.. ÑÑ
405 delete obj.$feature_list_envs_table[kname];406 let myindex = obj.$feature_list_envs.indexOf( feature_obj );407 if (myindex >= 0) obj.$feature_list_envs.splice( myindex,1 );408 }409 });410 resolve( feature_obj );411 }); 412 413 //return feature_obj;414 });415 }416 /* todo417 m.restoreParamizedFeatures = function( dump, obj, $scopeFor, crit_fn ) {418 let feat_arr_0 = []419 // а ÑепеÑÑ ÑиÑе-лиÑÑÑ... F-FEAT-PARAMS420 // restoreFeatures вÑзÑваеÑÑÑ Ð¼Ð½Ð¾Ð³Ð¾ÐºÑаÑно, и еÑли Ð¾Ñ Ð¾Ð´Ð½Ð¾ÐºÑаÑнÑÑ
ÑÐ¸Ñ Ñ Ð½Ð°Ñ ÐµÑÑÑ Ð·Ð°ÑиÑа Ñо ÑÑÑ Ð½ÐµÑ421 obj.features_list_is_restored ||= new Set();422 423 //var arr = [];424 for (let fr of (dump.features_list || [])) 425 {426 if (obj.features_list_is_restored.has(fr)) continue;427 obj.features_list_is_restored.add( fr ) ;428 if (!crit_fn(fr)) continue;429 fr.keepExistingParams = dump.keepExistingParams;430 let r2 = m.importAsParametrizedFeature( fr, obj, $scopeFor );431 //console.log( "case3 fn=",fr,r2,obj.getPath())432 feat_arr_0.push( Promise.resolve( r2 ) );433 }434 435 //obj.$feature_list_envs = (obj.$feature_list_envs || []).concat( arr );436 // ÑÑÑ Ð±Ñ ÑпиÑоÑег...437 //obj.setParam("feature_list_envs",arr);438 439 return feat_arr_0;440 } 441 */442 m.restoreParamizedFeatures = function( dump, obj, $scopeFor, crit_fn ) {443 let feat_arr_0 = []444 // а ÑепеÑÑ ÑиÑе-лиÑÑÑ... F-FEAT-PARAMS445 // restoreFeatures вÑзÑваеÑÑÑ Ð¼Ð½Ð¾Ð³Ð¾ÐºÑаÑно, и еÑли Ð¾Ñ Ð¾Ð´Ð½Ð¾ÐºÑаÑнÑÑ
ÑÐ¸Ñ Ñ Ð½Ð°Ñ ÐµÑÑÑ Ð·Ð°ÑиÑа Ñо ÑÑÑ Ð½ÐµÑ446 obj.features_list_is_restored ||= new Set();447 if (!obj.features_list_is_restored.has(dump.features_list)) {448 //var arr = [];449 for (let fr of (dump.features_list || [])) 450 {451 if (!crit_fn(fr)) continue;452 fr.keepExistingParams = dump.keepExistingParams;453 let r2 = m.importAsParametrizedFeature( fr, obj, $scopeFor );454 //console.log( "case3 fn=",fr,r2,obj.getPath())455 feat_arr_0.push( Promise.resolve( r2 ) );456 }457 obj.features_list_is_restored.add( dump.features_list ) ;458 //obj.$feature_list_envs = (obj.$feature_list_envs || []).concat( arr );459 // ÑÑÑ Ð±Ñ ÑпиÑоÑег...460 //obj.setParam("feature_list_envs",arr);461 }462 return feat_arr_0;463 }464 m.restoreFeatures = function ( dump, obj, manualparamsmode, $scopeFor) {465 //let feat_arr_0 = m.restoreParamizedFeatures( dump, obj, $scopeFor, (d)=>d.features.computer);466 /*467 // мега-ÑÑеÑÐ¾Ð²Ð°Ñ Ð»Ð¾Ð³Ð¸ÐºÐ° но ÑÑо делаÑÑ.468 // еÑли Ð¼Ñ Ð½Ðµ в ÑÑÑном Ñежиме.. Ñо.. нÑжно вклÑÑаÑÑ Ñежим когда Ð¼Ñ 469 let keepExistingParamsOrig = dump.keepExistingParams;470 if (!manualparamsmode) 471 dump.keepExistingParams = true;472 */ 473 let feat_arr_0 = m.restoreParamizedFeatures( dump, obj, $scopeFor, (d)=>true);474 475 // полÑÑаеÑÑÑ ÑÑо здеÑÑ Ð¿ÑоиÑÑ
Ð¾Ð´Ð¸Ñ Ð¿Ð¾Ð²ÑоÑнÑй вÑзов obj.feature476 // (пеÑвÑй в конÑÑÑÑкÑоÑе обÑекÑа за ÑÑÐµÑ Ð¾Ð¿Ñий .features)477 // пока оÑменим ÑÑÑ 478 // Ð½ÐµÑ Ð½Ðµ оÑменим. пÑименение ÑÐ¸Ñ Ð½Ð° ÑÑапе конÑÑÑÑкÑии обÑекÑа оказалоÑÑ Ñем ÑÑÑанно, ÑÑо479 // ÑиÑи пÑименÑÑÑÑÑ Ð²Ð¿ÐµÑед, на Ñамом базовом createObj480 // Ñаки оÑменим.. пÑÑÑÑ Ð¾Ð½Ð¸ Ñам Ñж пÑименÑÑÑÑÑ481 //return;482 // Ð½ÐµÑ Ð½Ðµ оÑменим483 // поÑÐ¾Ð¼Ñ ÑÑо Ð¼Ñ Ð¿ÑименÑем здеÑÑ ÑиÑи из ÑÑнкÑоÑа воÑÑÑÐ°Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ Ð¸Ð· дампа (compalang)484 // еÑÑÑ Ð¸Ð´ÐµÑ - пÑименÑÑÑ ÑиÑи поÑле {{ }}- ÑиÑ485 // ÑÑо Ð¿Ð¾Ð·Ð²Ð¾Ð»Ð¸Ñ Ð½Ð°Ð²ÐµÑиÑÑ Ð²ÑÑкие on-обÑабоÑÑики до поÑÐ²Ð»ÐµÐ½Ð¸Ñ ÐºÐ°ÐºÐ¸Ñ
-либо ÑобÑÑий внÑÑÑи486 let res = new Promise( (resolve,reject) => {487 Promise.allSettled( feat_arr_0 ).then( () => {488 let feat_arr = [];489 // NHACK490 if (dump.features && dump.features['base_url_tracing'])491 obj.feature('base_url_tracing', dump.features['base_url_tracing'].params);492 for (let fn of Object.keys(dump.features || {})) 493 {494 // ÑÑÑ ÑÑиÑаеÑÑÑ ÑÑо feature-code ÑÐ¾Ð²Ð¿Ð°Ð´Ð°ÐµÑ Ñ feature-name495 // в Ñелом же навеÑнÑка ÑÑо можно ÑаÑÑиÑиÑÑ Ð´Ð¾ Ñого ÑÑо код неÑколÑкиÑ
ÑÐ¸Ñ Ð¼Ð¾Ð¶ÐµÑ ÑовпадаÑÑ.496 // но ÑÑо надо Ñогда бÑÐ´ÐµÑ ÑÑеÑÑÑ Ð¸ feature-tools (Ñам оÑÑекаеÑÑÑ Ð¿Ð¾Ð²ÑоÑное пÑименение ÑÐ¸Ñ Ñ Ð¾Ð´Ð¸Ð½Ð°ÐºÐ¾Ð²Ñм кодом)497 let r = obj.feature( fn, dump.features[fn].params );498 //console.log( "case1 fn=",fn,r,obj.getPath())499 feat_arr.push( Promise.resolve( r ));500 }501 // белковÑй пÑедÑÑавиÑÐµÐ»Ñ manual-features502 // важно ÑÑи ÑиÑи воÑÑÑанавливаÑÑ Ð½Ð° 1м пÑоÑ
оде, Ñ.к. далее Ð¸Ð´ÐµÑ Ð¿ÑиÑвоение manual_features503 // и ÑообÑазно ÑиÑи наÑинаÑÑ Ð¿ÑименÑÑÑÑÑ Ð±ÐµÐ· пÑомиÑов, а на 2м пÑоÑ
оде - они Ñже ÑÑиÑаÑÑÑÑ Ð¿ÑимененнÑми и пÑомиÑов не ÑобÑаÑÑ504 // поÑÑÐ¾Ð¼Ñ Ð¼Ñ ÑÑÑ Ñ
аком - влазим и пÑименÑем не дожидаÑÑÑ.505 // но вообÑе - надо по ÑÐ¼Ñ ÑÑо-Ñо дÑÑгое делаÑÑ Ñ manual-features-ами. возможно ÑÑо 506 // вÑÑÑнÑÑ Ð½Ð°Ð±ÑаннÑе модиÑикаÑоÑÑ (ÑкоÑее вÑего ÑÑо они)507 508 if (dump.params?.manual_features) {509 let mf = FT.feature_names_to_arr( dump.params.manual_features );510 //if (!Array.isArray(mf)) mf = [mf];511 for (let fn of mf)512 {513 // ÑÑÑ ÑÑиÑаеÑÑÑ ÑÑо feature-code ÑÐ¾Ð²Ð¿Ð°Ð´Ð°ÐµÑ Ñ feature-name514 // в Ñелом же навеÑнÑка ÑÑо можно ÑаÑÑиÑиÑÑ Ð´Ð¾ Ñого ÑÑо код неÑколÑкиÑ
ÑÐ¸Ñ Ð¼Ð¾Ð¶ÐµÑ ÑовпадаÑÑ.515 // но ÑÑо надо Ñогда бÑÐ´ÐµÑ ÑÑеÑÑÑ Ð¸ feature-tools (Ñам оÑÑекаеÑÑÑ Ð¿Ð¾Ð²ÑоÑное пÑименение ÑÐ¸Ñ Ñ Ð¾Ð´Ð¸Ð½Ð°ÐºÐ¾Ð²Ñм кодом)516 let r = obj.feature( fn );517 //console.log( "case2 fn=",fn,r,obj.getPath())518 feat_arr.push( Promise.resolve( r ));519 }520 }521 Promise.allSettled( feat_arr ).then( resolve );522 /*Promise.allSettled( feat_arr ).then( () => {523 let feat_arr_1 = m.restoreParamizedFeatures( dump, obj, $scopeFor, (d)=>!d.features.computer);524 Promise.allSettled(feat_arr_1).then( resolve );525 });526 */527 });528 });529 //console.log( feat_arr, obj.getPath())530 return res;531 }532 m.restoreLinks = function( dump, obj, manualparamsmode, $scopeFor ) {533 for (var lname of Object.keys(dump.links || {})) {534 535 var lrec = dump.links[lname];536 var arr = lrec.to.split("->");537 if (arr[0] == "." || arr[0] == "~") { // ÑÑÑлка на Ð¿Ð¾Ð»Ñ Ð¾Ð±ÑекÑа538 //console.log("cre-link-to",lrec, obj.getPath()) 539 //console.log("cre-link-to",arr[1], lrec,obj.getPath()) 540 //if (arr[1] == "input_kv")541 // debugger;542 if (dump.keepExistingParams) {543 // оÑобÑй Ñежим ÑоÑ
ÑÐ°Ð½ÐµÐ½Ð¸Ñ Ñже ÑÑÑеÑÑвÑÑÑиÑ
паÑамеÑÑов544 // пÑоблема ÑÑо hasLinksToParam заÑабоÑÐ°ÐµÑ ÑолÑко пÑи акÑиваÑии ÑÑÑлки, коÑоÑÐ°Ñ Ñ Ð½Ð°Ñ Ð¾ÑложеннаÑ...545 // F-LINKS-OVERWRITE546 if (obj.hasLinksToParam( arr[1] ) || obj.hasParam( arr[1] )) {547 //console.log("orig link is kept - keepExistingParams")548 continue;549 }550 }551 else552 {553 // F-LINKS-OVERWRITE554 // ÑдалиÑÑ ÑÑÑлки пиÑÑÑие в ÑÑÐ¾Ñ Ð¿Ð°ÑамеÑÑ... Ñипа Ð¼Ñ ÑÑÑ Ñо знаÑением пÑиÑли...555 // и Ñ ÑÑеÑом ÑÑо Ñ Ð½Ð°Ñ Ð²Ñе ÑÐ½Ð¸Ð·Ñ Ð²Ð²ÐµÑÑ
ÑепеÑÑ ÑаÑкÑÑваеÑÑÑ - ÑÑо ÑÑабоÑаеÑ556 // и плÑÑ Ñже ÑÑÑено keepExistingParams557 if (obj.hasLinksToParam( arr[1] )) {558 let larr = obj.linksToParam( arr[1] );559 for (let l of larr)560 if (l.params.manual_mode)561 {562 // ладно ÑакÑÑ ÑÑÑÐ»ÐºÑ Ð¾ÑÑавим563 // ибо она ÑаÑÑÑ Ð¼ÐµÑ
аники поÑ
оже какой-Ñо564 }565 else {566 // console.warn("link removed",l.params.to)567 l.remove();568 }569 };570 };571 // ÑазделÑем ÑиÑÑаÑÐ¸Ñ ÐºÑда же нам напÑавиÑÑ Ð¼ÐµÑÑнÑÑ ÑÑÑÐ»ÐºÑ - на ÑÐµÐ±Ñ (на ÑиÑÑ) или на главное окÑÑжение572 // заÑÑем паÑамеÑÑ Ñелевой... Ñиак надо... но ÑÑо-Ñо Ñ ÑÑим вÑе ломаеÑÑÑ573/*574 if (arr[0] == ".") {575 obj.host.setParam( arr[1], undefined );576 }577*/ 578 let lobj = obj.createLinkTo( {param: arr[1], 579 from: lrec.from,580 name: "arg_link_to", 581 target_host_env: (arr[0] == "."),582 soft_mode: lrec.soft_mode583 584 } );585 if ($scopeFor)586 lobj.$scopes.addScopeRef( $scopeFor );587 else debugger; // вÑоде ниÑего ÑÑÑаÑного ж.. или Ñаки мабÑÑÑ?588 if (lrec.locinfo) 589 lobj.$locinfo = lrec.locinfo;590 //lobj.setParam('locinfo',lrec.locinfo);591/*592 if (lrec.to == ".->crit")593 lobj.on("remove",() => {594 lobj;595 debugger;596 }) 597*/ 598 }599 else600 {601 //console.log("arg-link-to",lrec, obj.getPath())602 let lobj = m.createLink( {parent: obj, name: "arg_link" });603 if ($scopeFor) 604 lobj.$scopes.addScopeRef( $scopeFor );605 else debugger; 606 m.setParam("soft_mode",lrec.soft_mode);607 m.setParam("to",lrec.to);608 m.setParam("from",lrec.from);609 if (lrec.locinfo) 610 lobj.$locinfo = lrec.locinfo;611 // кÑайне важно даваÑÑ Ð¸Ð¼ÐµÐ½Ð° ÑÑÑ ÑÑÑлкам (Ñипа arg_...) поÑÐ¾Ð¼Ñ ÑÑо инаÑе они ÑмеÑиваÑÑÑÑ Ñо ÑÑÑлками612 // задаваемÑми ÑеÑез children и наÑинаÑÑ Ñ Ð½Ð¸Ð¼Ð¸ конÑликÑоваÑÑ Ð¿Ð¾ именам (пеÑезапиÑÑваÑÑ Ð¸Ñ
)613 }614 }615 }616 617 // this is made specially so obj.restoreFromDump may be overriden618 m.restoreObjFromDump = function( dump, obj, manualParamsMode, $scopeFor ) {619 //let k = dump.params.manual_features;620 //delete dump.params['manual_features'];621 m.restoreParams( dump, obj,manualParamsMode,$scopeFor );622 m.restoreLinks( dump, obj,manualParamsMode,$scopeFor );623 let feature_promise = m.restoreFeatures( dump, obj,manualParamsMode,$scopeFor );624 // ÑÑÑ Ð¸Ð´ÐµÑ Ð´ÑблиÑование restoreFeatures Ñ createSyncFromDump, но ниÑего, Ð¼Ñ Ð¿ÐµÑеживем.625 if (dump.manual) {626 manualParamsMode = true; // Ñакой Ð²Ð¾Ñ Ð¿Ñием.. а Ñо "ÑÑÑнÑе обÑекÑÑ" поÑом не ÑоÑ
ÑаниÑÑ Ð¿Ð¾Ð»ÑÑаеÑÑÑ..627 }; 628 if (manualParamsMode) { // деÑей Ñделали - ÑÑÑкнем обÑÐµÐºÑ ÑÑо воÑ, воÑÑÑановилиÑÑ629 // а пÑиÑем важно ÑÑо ÑделаÑÑ ÑÑÑ Ñак как - Ñам ÑÑеди деÑей Ð¼Ð¾Ð³ÐµÑ ÑоздаÑÑÑÑ Ð¼Ð¾Ð½ÐµÑоÑеÑ630 // ÑÑого ÑобÑÑиÑ631 //console.log("emitting manual-restore for",obj.getPath())632 //obj.emit("manual-restore");633 obj.setParam("manual_restore_performed",true);634 }635 return new Promise( (resolve,reject) => {636 feature_promise.then( () => {637 let rc = obj.restoreChildrenFromDump( dump, manualParamsMode,$scopeFor );638 rc.then( () => {639 resolve( obj );640 });641 })642 })643 //let rc = obj.restoreChildrenFromDump( dump, manualParamsMode );644 //return Promise.all( feature_promise,rc );645 }646 647 m.removeChildrenByDump = function( dump, obj, manualParamsMode )648 {649 var c = dump.children || {};650 var ckeys = Object.keys( c );651 ///////////////////////////////////////////////////////////652 // ÑдалÑем ÑеÑ
ÑÑо еÑÑÑ Ñ Ð½Ð°Ñ Ð½Ð¾ Ð½ÐµÑ Ð²Ð¾ вÑ
одÑÑем ÑпиÑке653 // важно на каждой иÑеÑаÑии Ñикла обÑаÑаÑÑÑÑ Ð² getChildren654 var cnames = obj.ns.getChildNames();655 for (var i=0; i<cnames.length; i++) {656 var cname = cnames[i];657 var lc = obj.ns.getChildByName( cname );658 if (lc.protected) continue;659 // ÑежимÑ:660 // обÑÐµÐºÑ Ð±Ñл добавлен вÑÑÑнÑÑ => вÑ
одÑÑÐ°Ñ Ð¸Ð½ÑоÑмаÑÐ¸Ñ Ð½ÐµÑÐµÑ Ð¿ÑиоÑиÑеÑ661 // обÑÐµÐºÑ Ð±Ñл добавлен пÑогÑаммно => вообÑе его не ÑÑогаем (поÑемÑ-Ñо)662 // обÑÐµÐºÑ Ð±Ñл добавлен пÑогÑаммно Ñ Ð¿Ð¾Ð¼ÐµÑкой dumpyInserted/forcecreate => вÑ
одÑÑÐ°Ñ Ð¸Ð½ÑоÑмаÑÐ¸Ñ Ð½ÐµÑÐµÑ Ð¿ÑиоÑиÑÐµÑ ÐµÑли Ñежим ввода пÑогÑаммнÑй663 if (lc.manuallyInserted || (lc.dumpyInserted && !manualParamsMode)) {664 if (!c[cname]) { // во вÑ
одÑÑиÑ
неÑ665 // console.log("removing local unnecessary child lc=",lc);666 lc.remove();667 }668 }669 }670 }671/*672 ÑоздаÑÑ ÑпиÑок обÑекÑов по дампÑ673 ÑÑебованиÑ: 674 * пÑи воÑÑÑановлении ÑоÑ
ÑаниÑÑ Ð¿Ð¾ÑÑдок675 * веÑнÑÑÑ Ð¿ÑомиÑÑ ÐºÐ¾ÑоÑÐ°Ñ ÑазÑезолвиÑÑÑ ÐºÐ¾Ð³Ð´Ð° ÑабоÑа бÑÐ´ÐµÑ Ð³Ð¾Ñова676 ÑазделÑнÑй поÑÑдок воÑÑÑановлениÑ: F-DEFINED677 * ÑнаÑала вÑе load и register_feature678 * а заÑем вÑе оÑÑалÑное679*/680 // F-ENV-ARGS681 m.createObjectsList = function (env_list, obj, manualParamsMode, $scopeFor)682 {683 var result_p = new Promise( (resolv, reject) => {684 restore( 0,0 );685 function restore( i, priority ) {686 if (i == env_list.length) {687 if (priority == 0)688 return restore( 0,1 ); // пеÑеÑ
одим на вÑоÑой ÑÑап689 else690 return resolv( obj );691 }692 let child_dump = env_list[i];693 let name = child_dump.$name;694 // без ÑÑого оно Ñам кидеаеÑÑÑ Ð²Ñе ÑдалÑÑÑ..695 child_dump.keepExistingChildren = true;696 // еÑли 697 698 let feats = child_dump.features || {};699 let item_priority = (feats.load || feats.when || feats.feature || feats.register_feature) ? 0 : 1700 if (priority != item_priority)701 return restore( i+1, priority );702 let cobj = null;703 var r = m.createSyncFromDump( child_dump, cobj, obj, name, manualParamsMode, $scopeFor );704 // todo веÑнÑÑÑ Ð¾Ð¿ÑимизаÑиÑ705 r.then( () => {706 restore( i+1, priority );707 });708 709 // the only way to catch errors is here, allSettled will ignore that error710 r.catch( (err) => {711 console.error("createChildrenByDump: error! parent=",obj.getPath(),"child_dump=",child_dump,"error=",err );712 // и Ñе.. по идее надо вÑе-Ñавно вÑзÑваÑÑ ÑледÑÑÑиÑ
... или вÑзовеÑÑÑ?713 }); 714 }; // ÑÑнкÑÐ¸Ñ restore715 });716 717 return result_p; 718 }719 720 // ÑÑо вÑнеÑено в оÑделÑнÑÑ ÑÑнкÑÐ¸Ñ Ð¿Ð¾ÑÐ¾Ð¼Ñ ÑÑо Ð¼Ñ ÐµÐµ заÑ
оÑим оввеÑÑайдиÑÑ Ð´Ð»Ñ Ð·Ð°Ð³ÑÑзки пакеÑов721/*722 воÑÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð´ÐµÑей обÑекÑÑ Ð¸Ð· дампа723 ÑÑебованиÑ: 724 * пÑи воÑÑÑановлении ÑоÑ
ÑаниÑÑ Ð¿Ð¾ÑÑдок деÑей725 * веÑнÑÑÑ Ð¿ÑомиÑÑ ÐºÐ¾ÑоÑÐ°Ñ ÑазÑезолвиÑÑÑ ÐºÐ¾Ð³Ð´Ð° ÑабоÑа бÑÐ´ÐµÑ Ð³Ð¾Ñова726 новое: ÑазделÑнÑй поÑÑдок воÑÑÑановлениÑ: F-DEFINED727 * ÑнаÑала вÑе load и register_feature728 * а заÑем вÑе оÑÑалÑное729 todo опÑимизиÑоваÑÑ - на ÑÐµÐ¼Ñ ÑÑÐ¾Ð±Ñ load неÑколÑко паÑаллелÑно загÑÑжалиÑÑ730*/ 731 // F-ENV-ARGS732 m.copyEnvArgsToScope = function( args, env_args, scope ) {733// позиÑионное копиÑование734 for (let i=0; i<env_args.length; i++) {735 /*736 let argname = env_args[i];737 scope.$add( argname, args[i] );738 */739 let argname = env_args[i];740 let argvalue = args[i];741 /*742 // пÑидеÑÑÑ Ð¿ÑикинÑÑÑÑÑ Ð¾ÐºÑÑженÑем743 let param_env = m.createObj();744 param_env.feature("is_positional_env");745 param_env.setParam( 0, argvalue );746 scope.$add( argname, param_env );747 */748 scope.$add( argname, argvalue );749 }750 }751 // F-ENV-ARGS752 // ÑÑо как createObjectsList ÑолÑко Ñ ÑоÑмиÑованием окÑÑжениÑ-scope753 // todo на бÑдÑÑее ÑеÑ
ниÑеÑки ÑÑо и Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ env (наÑим обÑекÑом, пÑоÑеÑÑом)754 // без scope-ов755 m.callEnvFunction = function( env_list, parent_object, manualParamsMode, scope, ...args)756 {757 if (env_list.env_args) {758 let newscope = parent_object.$scopes.createAbandonedScope("$vz_children_function");759 newscope.$lexicalParentScope = env_list[0].$scopeFor || scope;760 //newscope.$lexicalParentScope = env_list[0].$scopeFor || parent_object.$scopes.top();761 //let newscope = scope_env.$scopes.createScope("$vz_children_function");762 //let newscope = scope.createScope("$vz_children_function");763 m.copyEnvArgsToScope( args, env_list.env_args.attrs, newscope);764 // коÑоÑе иÑÑоÑÐ¸Ñ ÑÐ°ÐºÐ°Ñ ÑÑо Ñам scope пÑоÑÐ¸Ñ Ð² каждÑÑ ÑÐ»ÐµÐ¼ÐµÐ½Ñ env_list765 // в паÑамеÑÑаÑ
(Ñ.е. alfa={ some; envs} )766 // и поÑÑÐ¾Ð¼Ñ ÐµÐµ надо каждÑÑ Ð¿ÐµÑеÑибиÑÑ767 //debugger;768 if (env_list[0].$scopeFor)769 for (let e of env_list)770 e.$scopeFor = newscope;771 // Ñипа ÑÐºÐ¾Ð±Ñ - нам не надо копиÑоваÑÑ Ñ.к. еÑÑÑ Ð¸ пÑоÑÑо паÑамеÑÑ newscope Ñ createObjectsList772 return m.createObjectsList( env_list, parent_object, manualParamsMode, newscope );773 }774 return m.createObjectsList( env_list, parent_object, manualParamsMode, scope );775 }776 // по знаÑÐµÐ½Ð¸Ñ - либо вÑÐ·Ð¾Ð²ÐµÑ ÐºÐ°Ðº ÑÑнкÑÐ¸Ñ Ð»Ð¸Ð±Ð¾ поÑмоÑÑÐ¸Ñ ÐºÐ°Ðº777 // на Ð½Ð°Ð±Ð¾Ñ Ð¾ÐºÑÑжений возможно вÑзÑваемÑй Ñ Ð°ÑгÑменÑами778 // update - ÑÑо ÑÑÑ
нÑ. надо делаÑÑ Ñак ÑÑÐ¾Ð±Ñ Ð±Ñл возвÑÐ°Ñ ÑезÑлÑÑаÑа годнÑй Ð´Ð»Ñ insert-children779 // и пÑоÑиÑ
createObjectsList780 m.callParamFunction = function( param_value, parent_object, manualParamsMode, scope, ...args) {781 if (typeof(param_value) == "string") {782 let f = eval( param_value );783 param_value = f( ...args )784 }785 else if (param_value.bind) {786 param_value = param_value( ...args );787 }788 return m.callEnvFunction( param_value, parent_object, manualParamsMode, scope, ...args);789 }790 // пÑеобÑазÑÐµÑ Ð·Ð½Ð°Ñение в dump-маÑÑив, пÑигоднÑй Ð´Ð»Ñ Ð¿ÐµÑедаÑи в insert_children791 // еÑли records ÑÑо ÑÑнкÑÐ¸Ñ Ñо вÑзÑÐ²Ð°ÐµÑ ÐµÐµ Ñ Ð°ÑгÑменÑами792 // еÑли records ÑÑо { |args|... } Ñо ÑвÑзÑÐ²Ð°ÐµÑ args Ñ Ð°ÑгÑменÑами (пока вÑе позиÑионное)793 m.prepareEnvRecords = function( records, ...args) {794 if (typeof(records) == "string") { // код на js795 let f = eval( records );796 records = f( ...args );797 }798 else if (records.bind) { // Ñ-Ñ799 records = records( ...args );800 }801 else if (records.env_args) {802 let newscope = m.createAbandonedScope("prepareEnvRecords");803 if (records && records.length > 0)804 newscope.$lexicalParentScope = records[0].$scopeFor;805 m.copyEnvArgsToScope( args, records.env_args.attrs, newscope);806 // коÑоÑе иÑÑоÑÐ¸Ñ ÑÐ°ÐºÐ°Ñ ÑÑо Ñам scope пÑоÑÐ¸Ñ Ð² каждÑÑ ÑÐ»ÐµÐ¼ÐµÐ½Ñ env_list807 // в паÑамеÑÑаÑ
(Ñ.е. alfa={ some; envs} )808 // и поÑÑÐ¾Ð¼Ñ ÐµÐµ надо каждÑÑ Ð¿ÐµÑеÑибиÑÑ809 if (records[0].$scopeFor)810 for (let e of records)811 e.$scopeFor = newscope;812 } 813 return records;814 };815 m.createChildrenByDump = function( dump, obj, manualParamsMode,$scopeFor )816 {817 // // F-ENV-ARGS818 obj.$vz_children_function = (...args) => {819 let c = Object.values( dump.children );820 c.env_args = dump.children_env_args;821 m.callEnvFunction( c, obj, manualParamsMode, $scopeFor, ...args )822 };823 // F-ENV-ARGS824 if (dump.children_env_args || obj.$vz_children_autocreate_enabled == false) { 825 return Promise.resolve(obj);826 }827 var c = dump.children || {};828 var ckeys = Object.keys( c );829 var result_p = new Promise( (resolv, reject) => {830 restore( 0,0 );831 function restore( i, priority ) {832 if (i == ckeys.length) {833 if (priority == 0)834 return restore( 0,1 ); // пеÑеÑ
одим на вÑоÑой ÑÑап835 else836 return resolv( obj );837 }838 name = ckeys[i];839 var child_dump = c[name];840 // еÑли 841 842 let feats = child_dump.features || {};843 let item_priority = (feats.load || feats.when || feats.feature || feats.register_feature) ? 0 : 1844 if (priority != item_priority)845 return restore( i+1, priority );846 var cobj = obj.ns.getChildByName( name );847 if (!c[name].manual && !cobj && !c[name].forcecreate) {848 // ÑиÑÑаÑÐ¸Ñ ÐºÐ¾Ð³Ð´Ð° обÑÐµÐºÑ Ð´Ð¾Ð»Ð¶ÐµÐ½ бÑл бÑÑÑ Ñоздан авÑомаÑиÑеÑки - но его неÑ!849 console.error("load_from_dump: no child of name found! name=",name,"obj=",obj,"dump=",dump);850 //promises_arr.push( Promise.reject() );851 return restore( i+1, priority );852 }853 854 if (dump.keepExistingChildren)855 child_dump.keepExistingChildren = dump.keepExistingChildren;856 if (dump.keepExistingChildren) cobj = null; // R-NEW-CHILDREN857 var r = m.createSyncFromDump( child_dump, cobj, obj, name, manualParamsMode, $scopeFor );858 // todo веÑнÑÑÑ Ð¾Ð¿ÑимизаÑиÑ859 r.then( () => {860 restore( i+1, priority );861 });862 863 // the only way to catch errors is here, allSettled will ignore that error864 r.catch( (err) => {865 console.error("createChildrenByDump: error! parent=",obj.getPath(),"child_dump=",child_dump,"error=",err );866 // и Ñе.. по идее надо вÑе-Ñавно вÑзÑваÑÑ ÑледÑÑÑиÑ
... или вÑзовеÑÑÑ?867 }); 868 }; // ÑÑнкÑÐ¸Ñ restore869 });870 871 return result_p;872 }873 874 m.dumpObj = function( obj ) {875 876 //var res = Object.create( obj.params );877 var res = {};878 if (Object.keys( obj.params ).length > 0) {879 //res.params = Object.assign({},obj.params);880 // feature: do not copy some params to dump!881 res.params = {};882 Object.keys( obj.params ).forEach( function(name) {883 var v = obj.dumpParam( name );884 if (v == null) return;885 if (typeof(v) === "string" && v.length > 10000) {886 console.error("dumpObj: because value too long, dump will not save param ",name,"of obj",obj.getPath());887 return;888 }889 // ÑиÑа по оÑÐ»Ð¾Ð²Ñ ÑиÑÑаÑий890 // Ð½Ñ Ð¼Ð± можно бÑло Ð±Ñ ÑÑÑ Ð¸ ÑÑÑоÑÐºÑ ÑоÑ
ÑанÑÑÑ, не знаÑ891 // но поÑом Ñогда надо из дампа ее воÑÑÑанавливаÑÑ892 // ÑÑо Ñоже в пÑинÑипе ваÑÐ¸Ð°Ð½Ñ (ÑоÑ
ÑанÑÑÑ { ref: 'obj', path: ....})893 // кÑÑаÑи ÑÑо Ñдобно бÑло бÑ. Ð½Ñ Ð¼Ð±. smallidea.894 if (v.setParam) {895 console.error("dumpObj: vz object in param value! name=", name, "obj path=",obj.getPath(), obj)896 return;897 }898 res.params[name] = v;899 });900 }901 if (obj.ismanual && obj.ismanual()) {902 res.manual = true;903 res.type = obj.historicalType;904 }905 else if (obj.historicalType) {906 res.type = obj.historicalType;907 //res.type = opts.type; //tttt908 }909 if (obj.module_url) {910 res.module_url = obj.module_url;911 }912 var ch = obj.ns.getChildNames();913 if (ch.length > 0) {914 res.children={};915 ch.forEach( function(cname,index) {916 var c = obj.ns.getChildByName( cname );917 var r = c.dump();918 if (!r) return; // возможноÑÑÑ Ð¾Ð±ÑекÑÑ Ð¾ÑказаÑÑÑÑ Ð¾Ñ ÑоÑ
ÑанениÑ919 res.children[cname] = r;920 if (res.children[cname].manual)921 res.children[cname].order=index;922 } );923 }924 // ÑиÑа "еÑли не Ð·Ð°Ð´Ð°Ð½Ñ Ð¿Ð°ÑамеÑÑÑ Ð²Ð¾Ð²Ñе Ñо не надо делаÑÑ Ð·Ð°Ð¿Ð¸ÑÑ params"925 if (res.params && Object.keys(res.params).length == 0) delete res.params;926 // ÑиÑа "еÑли не Ð·Ð°Ð´Ð°Ð½Ñ Ð´ÐµÑи вовÑе Ñо не надо делаÑÑ Ð·Ð°Ð¿Ð¸ÑÑ children"927 if (res.children && Object.keys(res.children).length == 0) delete res.children;928 return res;929 }930m.chain("create_obj",function( obj, opts ) {931 // @compolang @todo @design - поÑÐµÐ¼Ñ Ð²Ð¾Ñ ÑÑо нелÑÐ·Ñ Ð±Ñло Ð±Ñ Ð² паÑамеÑÑÑ Ñо пеÑеÑаÑиÑÑ?932 obj.ismanual = function() {933 return obj.manuallyInserted ? true : false;934 }935 obj.setmanual = function(v) {936 return obj.manuallyInserted = v;937 }938 obj.dump = function() {939 return m.dumpObj( obj );940 }941 // manualParamsMode - consider incoming params as manual942 obj.restoreFromDump = function ( dump, manualParamsMode, $scopeFor ) {943 return m.restoreObjFromDump( dump, obj, manualParamsMode, $scopeFor );944 }945 946 // returns promise947 obj.clone = function( opts = {} ) {948 var dump = obj.dump();949 //debugger;950 if (!opts.parent) opts.parent = obj.ns.parent;951 return m.createSyncFromDump( dump, null, opts.parent, opts.name );952 }953 954 // created this method(tpu) to implement R-SETREF-OBJ955 obj.dumpParam = function ( name ) {956 if (obj.getParamOption( name,"internal" ) || name[0] == "@")957 {958 // console.log("skipped dump of name because internal",name);959 }960 else961 {962 return obj.params[name];963 }964 }965 // вÑделÑем воÑÑÑановление деÑей в оÑделÑнÑй меÑод в конÑекÑÑе obj966 // ÑÑÐ¾Ð±Ñ ÑиÑи обÑекÑа могли ÑÑпеÑÑ ÐµÐ³Ð¾ поменÑÑÑ (конкÑеÑно ÑÑо надо бÑло Ð´Ð»Ñ repeater)967 obj.restoreChildrenFromDump = (dump, ismanual, $scopeFor) => {968 if (!dump.keepExistingChildren)969 m.removeChildrenByDump( dump, obj, ismanual );970 return m.createChildrenByDump( dump, obj, ismanual, $scopeFor );971 }972 973 if (opts.manual) obj.manuallyInserted = true;974 if (opts.forcecreate) obj.dumpyInserted = true; // @todo ÑаÑкопаÑÑ ÑÑÑ ÑемÑ975 // ÑаÑÑкомменÑиÑовал dumpyInserted Ñак как ÑÑо пÑизнак пÑи оÑиÑÑке деÑей ÑÑо иÑ
можно оÑиÑаÑÑ..976 // (Ñам Ð¸Ð´ÐµÑ Ð¸Ð´ÐµÐ¹Ð½Ñй конÑÐ»Ð¸ÐºÑ - нам пÑиÑ
Ð¾Ð´Ð¸Ñ Ð´Ð°Ð¼Ð¿ и можно ли ÑдалиÑÑ Ð¾Ð±ÑекÑ?)977 // и Ð²Ð¾Ñ Ñ Ð½Ð° ÑлÑÑай ÑÑо Ð¼Ñ Ñделали xmlFromChildren.. и Ñ
оÑим повÑоÑиÑÑ... и знаÑÐ¸Ñ Ð½Ð°Ð´Ð¾ вÑеÑ
кого Ð¼Ñ Ð½Ðµ пеÑеÑиÑлили - ÑбÑаÑÑ..978 // но ÑÑо пÑÐ¸Ð²Ð¾Ð´Ð¸Ñ Ðº ÑÐ¾Ð¼Ñ ÑÑо когда пÑиÑ
Ð¾Ð´Ð¸Ñ Ð´Ð°Ð¼Ð¿ из пÑоекÑа (Ñ
ÐµÑ Ð±ÑаÑзеÑа) Ñо ÑÑо пÑÐ¸Ð²Ð¾Ð´Ð¸Ñ Ðº оÑиÑÑке вÑево..979 // знаÑÐ¸Ñ Ð½ÑÐ¶Ð½Ñ ÑежимÑ...980 this.orig( obj, opts );981 return obj;982} ); // create_obj...
imposter.js
Source:imposter.js
...42 domain = require('domain').create(),43 errorHandler = createErrorHandler(deferred, creationRequest.port),44 compatibility = require('./compatibility'),45 requests = [],46 logger = require('../util/scopedLogger').create(baseLogger, scopeFor(creationRequest.port)),47 helpers = require('../util/helpers'),48 imposterState = {};49 let stubs;50 let resolver;51 let numberOfRequests = 0;52 compatibility.upcast(creationRequest);53 // If the CLI --mock flag is passed, we record even if the imposter level recordRequests = false54 const recordRequests = config.recordRequests || creationRequest.recordRequests;55 function getResponseFor (request) {56 if (!isAllowedConnection(request.ip, logger)) {57 return Q({ blocked: true, code: 'unauthorized ip address' });58 }59 numberOfRequests += 1;60 if (recordRequests) {61 const recordedRequest = helpers.clone(request);62 recordedRequest.timestamp = new Date().toJSON();63 requests.push(recordedRequest);64 }65 const responseConfig = stubs.getResponseFor(request, logger, imposterState);66 return resolver.resolve(responseConfig, request, logger, imposterState).then(response => {67 if (config.recordMatches && !response.proxy) {68 if (response.response) {69 // Out of process responses wrap the result in an outer response object70 responseConfig.recordMatch(response.response);71 }72 else {73 // In process resolution74 responseConfig.recordMatch(response);75 }76 }77 return Q(response);78 });79 }80 function getProxyResponseFor (proxyResponse, proxyResolutionKey) {81 return resolver.resolveProxy(proxyResponse, proxyResolutionKey, logger).then(response => {82 if (config.recordMatches) {83 response.recordMatch();84 }85 return Q(response);86 });87 }88 domain.on('error', errorHandler);89 domain.run(() => {90 if (!helpers.defined(creationRequest.host) && helpers.defined(config.host)) {91 creationRequest.host = config.host;92 }93 Protocol.createServer(creationRequest, logger, getResponseFor).done(server => {94 if (creationRequest.port !== server.port) {95 logger.changeScope(scopeFor(server.port));96 }97 logger.info('Open for business...');98 stubs = server.stubs;99 resolver = server.resolver;100 if (creationRequest.stubs) {101 creationRequest.stubs.forEach(stubs.addStub);102 }103 function stop () {104 const stopDeferred = Q.defer();105 server.close(() => {106 logger.info('Ciao for now');107 return stopDeferred.resolve({});108 });109 return stopDeferred.promise;...
actions.js
Source:actions.js
...62 findScope($el).$broadcast(event, data);63 };64}65function findScope(el) {66 if (scopeFor(el)) {67 return scopeFor(el);68 }69 var children = el.children();70 for (var i = 0; i < children.length; i++) {71 var scope = scopeFor(children[i]);72 if (scope) {73 return scope;74 }75 }76 throw new Error('Cannot find scope on top level children of root element', el);77 function scopeFor(element) {78 return angular.element(element).scope();79 }80}81function wait(timeout) {82 return function () {83 return {84 then: function (callback) {85 setTimeout(callback, timeout || 0);86 }87 };88 };89}90function navigateTo(url) {91 return withAfter(function ($el) {...
Using AI Code Generation
1var mb = require('mountebank');2var imposter = {3 {4 {5 is: {6 headers: {7 },8 body: JSON.stringify({message: 'Hello world!'})9 }10 }11 }12};13mb.create(imposter, function () {14 scope.get('/').reply(200, {message: 'Hello world!'});15 });16});17### mountebank.create(imposter, callback)18* `port` - the port on which to create the imposter (required)19* `protocol` - the protocol to use for the imposter (required)20* `stubs` - an array of stubs to use for the imposter (optional)21* `name` - a name for the imposter (optional)22* `key` - a key to use for basic authentication (optional)23* `cert` - a certificate to use for SSL (optional)24* `recordRequests` - whether the imposter should record requests (optional, defaults to false)25* `defaultResponse` - the default response to use for the imposter (optional, defaults to `{is: {statusCode: 400}}`)26* `mode` - the mode to use for the imposter (optional, defaults to 'text')27* `defaultMode` - the default mode to use for the imposter (optional, defaults to 'text')28* `stubs` - an array of stubs to use for the imposter (optional)29* `predicates` - an array of predicates to use for the imposter (optional)30* `responses` - an array of responses to use for the imposter (optional)31* `behaviors` - an array of behaviors to use for the imposter (optional)32* `numberOfRequests` - the number of requests to use for the imposter (optional)
Using AI Code Generation
1const mb = require('mountebank');2const scopeFor = mb.scopeFor;3const port = 2525;4 {5 {6 {7 is: {8 }9 }10 }11 }12];13const scope = scopeFor(port);14scope.create(imposters)15 .then(() => {16 })17 .then(response => {18 console.log('Response from imposter:', response.body);19 })20 .then(() => {21 console.log('Imposter deleted');22 })23 .catch(error => {24 console.error(error);25 });26### scopeFor(port, options)27### scope.create(imposter)28### scope.get(path, options)
Using AI Code Generation
1var mb = require('mountebank');2var Q = require('q');3var request = require('request');4var deferred = Q.defer();5var imposter = {6 stubs: [{7 responses: [{8 is: {9 }10 }]11 }]12};13mb.create({port: 2525}, function (error, mbServer) {14 mbServer.post('/imposters', imposter, function (error, response) {15 mbServer.del('/imposters', function () {16 deferred.resolve();17 });18 });19 });20});21deferred.promise.then(function () {22 console.log('done');23});
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const imposterPort = 3000;4const imposterProtocol = 'http';5const imposterName = 'testImposter';6const imposterStub = {7 responses: [{8 is: {9 }10 }]11};12mb.create(port)13 .then(function (mbServer) {14 return mbServer.createImposter({15 });16 })17 .then(function (imposter) {18 })19 .then(function (scope) {20 return scope.get('/').then(function (response) {21 console.log(response.body);22 });23 })24 .catch(function (error) {25 console.error(error);26 });27[MIT](LICENSE)
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3mb.create(port, function (error, mbServer) {4 if (error) {5 console.error(error);6 } else {7 mbServer.post('/imposters', {8 {9 {10 equals: {11 }12 }13 {14 is: {15 headers: {16 },17 body: JSON.stringify({18 })19 }20 }21 }22 }, function (error, imposters) {23 if (error) {24 console.error(error);25 } else {26 const imposterPort = imposters[0].port;27 console.log(`Created imposter on port ${imposterPort}`);28 }29 });30 }31});32const mb = require('mountebank');33const port = 2525;34mb.create(port, function (error, mbServer) {35 if (error) {36 console.error(error);37 } else {38 mbServer.post('/imposters', {39 {40 {41 equals: {42 }43 }44 {45 is: {46 headers: {47 },48 body: JSON.stringify({49 })50 }51 }52 }53 }, function (error, imposters) {54 if (error) {55 console.error(error
Using AI Code Generation
1var mb = require('mountebank');2var Q = require('q');3var http = require('http');4var deferred = Q.defer();5var options = {6};7var request = http.request(options, function (response) {8 response.setEncoding('utf8');9 response.on('data', function (chunk) {10 deferred.resolve(chunk);11 });12});13var json = {14 {15 {16 "is": {17 }18 }19 }20};21request.write(JSON.stringify(json));22request.end();23deferred.promise.then(function (chunk) {24 var imposters = JSON.parse(chunk);25 var imposter = imposters[0];26 var imposterPort = imposter.port;27 var imposterProtocol = imposter.protocol;28 var scope = mb.scopeFor(imposterProtocol, imposterPort);29 scope.get('/', 200);30 scope.post('/', 200);31 scope.put('/', 200);32 scope.delete('/', 200);33 scope.head('/', 200);34 scope.options('/', 200);35 scope.patch('/', 200);36 scope.addStub({ responses: [{ is: { body: 'Hello world!' } }] });37 scope.removeStub(0);38 scope.removeStubs();39 scope.remove();40});41var mb = require('mountebank');42var Q = require('q');43var http = require('http');44var deferred = Q.defer();45var options = {46};47var request = http.request(options, function (response) {48 response.setEncoding('utf8');49 response.on('data', function (chunk) {50 deferred.resolve(chunk);51 });52});53var json = {54 {55 {56 "is": {57 }58 }59 }60};61request.write(JSON.stringify(json
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var imposterPort = 3000;4var imposterProtocol = 'http';5var imposterName = 'test';6var imposterStub = {7 {8 is: {9 }10 }11};12var imposterPredicate = {13 equals: {14 }15};16var imposterStub = {17 {18 is: {19 }20 }21};22var imposter = {23 {24 {25 is: {26 }27 }28 }29};30var imposterPredicate = {31 equals: {32 }33};34var imposterStub = {35 {36 is: {37 }38 }39};40mb.create({ port: port }, function (error, mbServer) {41 if (error) {42 console.error(error);43 }44 else {45 console.log('mbServer started at port: ' + port);46 mbServer.post('/imposters', imposter, function (error, response) {47 if (error) {48 console.error(error);49 }50 else {51 console.log('imposter created: ' + response.body.name);52 console.log(response.body);53 }54 });55 }56});57mb.create({ port: port }, function (error, mbServer) {58 if (error) {59 console.error(error);60 }61 else {62 console.log('mbServer started at port: ' + port);63 mbServer.post('/imposters', imposter, function (error, response) {64 if (error) {65 console.error(error);66 }67 else {68 console.log('imposter created: ' + response.body.name);69 console.log(response.body);70 }71 });72 }73});74mb.create({ port: port }, function (error
Using AI Code Generation
1var mb = require('mountebank');2var imposter = mb.create({port: 2525, name: 'test'});3imposter.post('/test', {key: 'value'});4imposter.get('/test', {key: 'value'});5imposter.scopeFor('test').get('/test', {key: 'value'});6imposter.scopeFor('test').post('/test', {key: 'value'});7imposter.scopeFor('test').put('/test', {key: 'value'});8imposter.scopeFor('test').delete('/test', {key: 'value'});9imposter.scopeFor('test').patch('/test', {key: 'value'});10imposter.scopeFor('test').head('/test', {key: 'value'});11imposter.scopeFor('test').options('/test', {key: 'value'});12imposter.scopeFor('test').any('/test', {key: 'value'});13imposter.scopeFor('test').predicate('/test', {key: 'value'});14imposter.scopeFor('test').response('/test', {key: 'value'});15imposter.scopeFor('test').response('/test', {key: 'value'}, 200);16imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'});17imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'}, 'text/plain');18imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'}, 'text/plain', 'utf-8');19imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'}, 'text/plain', 'utf-8', 'test');20imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'}, 'text/plain', 'utf-8', 'test', 'test');21imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'}, 'text/plain', 'utf-8', 'test', 'test', 'test');22imposter.scopeFor('test').response('/test', {key: 'value'}, 200, {key: 'value'}, 'text/plain', 'utf-8', 'test', 'test', 'test23 }24 else {25 console.log('imposter created: ' + response.body.name);26 console.log(response.body);27 }28 });29 }30});31mb.create({ port: port }, function (error
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!