lib/model/instance/form-partial.js
// which is a Form property and so a plain object is returned.
which is a Form property and so a plain object is returned.
which is a Form property and so a plain object is returned .
static fromXml(xml) {
    const dataNode = findOne(root('html'), node('head'), node('model'), node('instance'), node());
    const parse = (input) => traverseXml(input, [
      dataNode(attr('id')),
      dataNode(attr('version')),
      findOne(root('html'), node('head'), node('title'))(text()),
      findOne(root('html'), node('head'), node('model'), node('submission'))(attr('base64RsaPublicKey'))
    ]).then(([ idText, versionText, nameText, pubKey ]) => {
      const xmlFormId = idText.map(blankStringToNull)
        .orThrow(Problem.user.missingParameter({ field: 'formId' }));
      if (/\.(xlsx?|xml)$/.test(xmlFormId))
        throw Problem.user.unexpectedValue({
          field: 'formId',
          value: xmlFormId,
          reason: 'The Form ID cannot end in .xls, .xlsx, or .xml. Please either specify an allowed ID in the form itself, or rename the file (eg change form.xls.xls to form.xls).'
        });
      const version = versionText.orElse('');
      const name = nameText.orNull();
      const key = pubKey.map((k) => new Key({ public: k }));
      return new FormPartial({ xmlFormId, name, version, key });
    });
    return (typeof xml === 'string')
      ? parse(xml).then((partial) =>
        partial.with({ hash: md5sum(xml), sha: shasum(xml), sha256: sha256sum(xml), xml }))
      : pipethrough(xml, digestWith('md5'), digestWith('sha1'), digestWith('sha256'),
        consumerToPiper((stream) => consumeAndBuffer(stream, parse)))
        .then(([ hash, sha, sha256, [ partial, buffer ] ]) =>
          partial.with({ hash, sha, sha256, xml: buffer.toString('utf8') }));
  }
static fromXml ( xml ) { const dataNode = findOne ( root ( 'html' ) , node ( 'head' ) , node ( 'model' ) , node ( 'instance' ) , node ( ) ) ; const parse = ( input ) => traverseXml ( input , [ dataNode ( attr ( 'id' ) ) , dataNode ( attr ( 'version' ) ) , findOne ( root ( 'html' ) , node ( 'head' ) , node ( 'title' ) ) ( text ( ) ) , findOne ( root ( 'html' ) , node ( 'head' ) , node ( 'model' ) , node ( 'submission' ) ) ( attr ( 'base64RsaPublicKey' ) ) ] ) . then ( ( [ idText , versionText , nameText , pubKey ] ) => { const xmlFormId = idText . map ( blankStringToNull ) . orThrow ( Problem . user . missingParameter ( { field : 'formId' } ) ) ; if ( / \.(xlsx?|xml)$ / . test ( xmlFormId ) ) throw Problem . user . unexpectedValue ( { field : 'formId' , value : xmlFormId , reason : 'The Form ID cannot end in .xls, .xlsx, or .xml. Please either specify an allowed ID in the form itself, or rename the file (eg change form.xls.xls to form.xls).' } ) ; const version = versionText . orElse ( '' ) ; const name = nameText . orNull ( ) ; const key = pubKey . map ( ( k ) => new Key ( { public : k } ) ) ; return new FormPartial ( { xmlFormId , name , version , key } ) ; } ) ; return ( typeof xml === 'string' ) ? parse ( xml ) . then ( ( partial ) => partial . with ( { hash : md5sum ( xml ) , sha : shasum ( xml ) , sha256 : sha256sum ( xml ) , xml } ) ) : pipethrough ( xml , digestWith ( 'md5' ) , digestWith ( 'sha1' ) , digestWith ( 'sha256' ) , consumerToPiper ( ( stream ) => consumeAndBuffer ( stream , parse ) ) ) . then ( ( [ hash , sha , sha256 , [ partial , buffer ] ] ) => partial . with ( { hash , sha , sha256 , xml : buffer . toString ( 'utf8' ) } ) ) ; }
which is a Form property and so a plain object is returned.
which is a Form property and so a plain object is returned .