getBuilder static method

UpdateVerbBuilder? getBuilder(
  1. String command
)

Implementation

static UpdateVerbBuilder? getBuilder(String command) {
  if (command != command.trim()) {
    throw IllegalArgumentException(
        'Commands may not have leading or trailing whitespace');
  }
  var builder = UpdateVerbBuilder();
  HashMap<String, String?>? verbParams;
  if (command.contains(AtConstants.updateMeta)) {
    verbParams = VerbUtil.getVerbParam(VerbSyntax.update_meta, command);
    builder.operation = AtConstants.updateMeta;
  } else {
    verbParams = VerbUtil.getVerbParam(VerbSyntax.update, command);
  }
  if (verbParams == null) {
    return null;
  }
  builder.atKey.metadata.isPublic =
      verbParams[AtConstants.publicScopeParam] == 'public';
  builder.atKey.sharedWith =
      VerbUtil.formatAtSign(verbParams[AtConstants.forAtSign]);
  builder.atKey.sharedBy =
      VerbUtil.formatAtSign(verbParams[AtConstants.atSign]);
  builder.atKey.key = verbParams[AtConstants.atKey]!;
  builder.value = verbParams[AtConstants.atValue];
  if (builder.value is String) {
    builder.value = VerbUtil.replaceNewline(builder.value);
  }
  if (verbParams[AtConstants.ttl] != null) {
    builder.atKey.metadata.ttl = int.parse(verbParams[AtConstants.ttl]!);
  }
  if (verbParams[AtConstants.ttb] != null) {
    builder.atKey.metadata.ttb = int.parse(verbParams[AtConstants.ttb]!);
  }
  if (verbParams[AtConstants.ttr] != null) {
    builder.atKey.metadata.ttr = int.parse(verbParams[AtConstants.ttr]!);
  }
  if (verbParams[AtConstants.ccd] != null) {
    builder.atKey.metadata.ccd =
        _getBoolVerbParams(verbParams[AtConstants.ccd]!);
  }

  builder.atKey.metadata.dataSignature =
      verbParams[AtConstants.publicDataSignature];

  if (verbParams[AtConstants.isBinary] != null) {
    builder.atKey.metadata.isBinary =
        _getBoolVerbParams(verbParams[AtConstants.isBinary]!);
  }
  if (verbParams[AtConstants.isEncrypted] != null) {
    builder.atKey.metadata.isEncrypted =
        _getBoolVerbParams(verbParams[AtConstants.isEncrypted]!);
  }

  builder.atKey.metadata.sharedKeyEnc =
      verbParams[AtConstants.sharedKeyEncrypted];
  // ignore: deprecated_member_use_from_same_package
  builder.atKey.metadata.pubKeyCS =
      verbParams[AtConstants.sharedWithPublicKeyCheckSum];
  builder.atKey.metadata.sharedKeyStatus =
      verbParams[AtConstants.sharedKeyStatus];
  builder.atKey.metadata.encoding = verbParams[AtConstants.encoding];
  builder.atKey.metadata.encKeyName =
      verbParams[AtConstants.encryptingKeyName];
  builder.atKey.metadata.encAlgo = verbParams[AtConstants.encryptingAlgo];
  builder.atKey.metadata.ivNonce = verbParams[AtConstants.ivOrNonce];
  builder.atKey.metadata.skeEncKeyName =
      verbParams[AtConstants.sharedKeyEncryptedEncryptingKeyName];
  builder.atKey.metadata.skeEncAlgo =
      verbParams[AtConstants.sharedKeyEncryptedEncryptingAlgo];

  builder.value = verbParams[AtConstants.value];

  return builder;
}