Exemplo n.º 1
0
export function sanitizeOutputFields(document: Object): Object {
  const doc = _.clone(document);
  _.unset(doc, '_id');
  _.unset(doc, '_key');
  _.unset(doc, '_rev');
  return doc;
}
Exemplo n.º 2
0
			sails.router.bind(route, function (req: any, res: any, next: Function) {

				let protocol: any = _.startsWith(swagger.host, 'http') ? '' : 'http://';
				let targetUrlTemplate: any = protocol + swagger.host + ( swagger.basePath || '' ) + path;
				let templateFn: any = _.template(targetUrlTemplate, {
					interpolate: /{([\s\S]+?)}/g
				});

				let params: any = req.allParams();

				let targetUrl: any = templateFn(params);

				let headers: any = req.headers;

				_.unset(headers, 'cookie');
				_.unset(headers, 'host');
				_.unset(headers, 'user-agent');
				_.unset(headers, 'referer');

				let reqOut: any = {
					url: targetUrl,
					method: vertex,
					body: ( req.body || null ),
					qs: req.transport != 'socket.io' ? req.query : req.body,
					json: true,
					headers: headers
				};

				let $request: any = sails.$request(req.session) || request;
				$request(reqOut, function (err: Error, message: any, body: any): void {

					console.log('*************************');
					console.log('' + vertex + ' ' + targetUrl);
					console.log('-------------------------');
					console.dir(headers);
					console.log('=========================');
					console.dir(body);

					if (params && body && !params.id && !_.isArray(body)) {
						body.id = body.id || uuid.v4();
						body = [body];
					}
					else if (_.isArray(body)) {
						_.each(body, function (item: any) {
							item.id = item.id || uuid.v4();
						});
					}

					if (!err) {
						res
							.status(message.statusCode)
							.send(body);
					}
					else {
						res.serverError(err);
					}
				})
			})
 it('should ignore ignoreProperties', () => {
     // set options (ignore Properties)
     eas.options = {
         ignoreProperties: ['data.ignored'], ignoreSubProperties: []
     };
     _.set(storage.testSnapObj, 'data.ignored', 'aVal');
     _.set(storage.testSnapObj2, 'data.ignored', 'aDifferentVal');
     // actual testing
     let result = eas.deepDiff(storage.testSnapObj, storage.testSnapObj2);
     expect(result).to.eql(storage.testDiffObj);
     // reset options to emtpy object
     eas.options = {};
     _.unset(storage.testSnapObj, 'data.ignored');
     _.unset(storage.testSnapObj2, 'data.ignored');
 });
Exemplo n.º 4
0
 let unsetIgnoredSubProperties = (obj: any) => {
     if (_.isPlainObject(obj)) {
         for (var prop of this.options.ignoreSubProperties) {
             _.unset(obj, prop);
         }
     }
 };
Exemplo n.º 5
0
 collections[collection].insert(doc, (err, newdoc) => {
   // docs
   if (err) {
     throw err;
   } else {
     _.unset(newdoc, '_id');
     return newdoc;
   }
 });
Exemplo n.º 6
0
export function makeActiveProject(projectDir: string, newActive: string): void {
  const activeProjects = configstore.get("activeProjects") || {};
  if (newActive) {
    activeProjects[projectDir] = newActive;
  } else {
    _.unset(activeProjects, projectDir);
  }
  configstore.set("activeProjects", activeProjects);
}
Exemplo n.º 7
0
 collections[collection].find(q).exec((err, docs) => {
   if (docs) {
     const l = docs.length;
     for (let i = 0; i < l; i += 1) {
       _.unset(docs[i], '_id');
     }
     resolve(docs);
   } else if (err) {
     reject(err);
   }
 });
Exemplo n.º 8
0
export function unsetConfigValue(ctx: ConfigContext & { property: string; }): void {
  const conf = getConfig(ctx);

  if (ctx.global) { // Global config is flattened
    conf.unset(ctx.property);
  } else {
    const { c } = conf;
    lodash.unset(c, ctx.property);
    conf.c = c;
  }
}
Exemplo n.º 9
0
 return (control: AbstractControl): { [key: string]: any } => {
   const ctrl1 = control.get(path1);
   const ctrl2 = control.get(path2);
   if (ctrl1.value !== ctrl2.value) {
     ctrl2.setErrors({ match: true });
   } else {
     const hasError = ctrl2.hasError('match');
     if (hasError) {
       // Remove the 'match' error. If no more errors exists, then set
       // the error value to 'null', otherwise the field is still marked
       // as invalid.
       const errors = ctrl2.errors;
       _.unset(errors, 'match');
       ctrl2.setErrors(_.isEmpty(_.keys(errors)) ? null : errors);
     }
   }
   return null;
 };
Exemplo n.º 10
0
  /**
   * 设置实例的 props 属性
   */
  @Action
  public setInstanceProps(instanceKey: string, key: string, value: any) {
    const instance = this.store.instances.get(instanceKey);
    const instanceClass = this.applicationStore.componentClasses.get(instance.gaeaKey);

    const defaultProps = this.applicationAction.getDefaultPropsByInstance(instance);

    // 如果和 defaultProps 相同,就把字段置空
    if (value === _.get(defaultProps, key)) {
      _.unset(instance.data.props, key);

      // 强制刷新组件
      this.eventAction.emit(`${this.eventStore.instanceUpdate}.${instanceKey}`);
      return;
    }

    _.set(instance.data, `props.${key}`, value);

    // 强制刷新组件
    this.eventAction.emit(`${this.eventStore.instanceUpdate}.${instanceKey}`);
  }