How to use the fp-ts/lib/Either.isRight function in fp-ts

To help you get started, we’ve selected a few fp-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
return async (auth, _, userAttributes, fiscalCode) => {
    const errorOrMaybeProfile = await profileModel.findOneProfileByFiscalCode(
      fiscalCode
    );
    if (isRight(errorOrMaybeProfile)) {
      const maybeProfile = errorOrMaybeProfile.value;
      if (isSome(maybeProfile)) {
        const profile = maybeProfile.value;
        if (auth.groups.has(UserGroup.ApiFullProfileRead)) {
          // if the client is a trusted application we return the
          // extended profile
          return ResponseSuccessJson(toExtendedProfile(profile));
        } else {
          // or else, we return a limited profile
          return ResponseSuccessJson(
            toLimitedProfile(
              profile,
              isSenderAllowed(
                profile.blockedInboxOrChannels,
                userAttributes.service.serviceId
              )
github stoplightio / prism / packages / http / src / router / __tests__ / index.spec.ts View on Github external
test('should match even if no server defined', () => {
        const method = pickOneHttpMethod();
        const path = randomPath();

        return expect(
          isRight(
            route({
              resources: [createResource(method, path, [])],
              input: {
                method,
                url: {
                  baseUrl: '',
                  path,
                },
              },
            })
          )
        ).toBeTruthy();
      });
github eramdam / BetterTweetDeck / src / services / backgroundSettings.ts View on Github external
async function getValidatedSettings() {
  const currentSettings = await ExtensionSettings.get();
  const settingsWithDefault = RBetterTweetDeckSettings.decode(currentSettings);

  if (!isRight(settingsWithDefault)) {
    console.error('Had to use default settings');
    console.log(PathReporter.report(settingsWithDefault));
    return defaultSettings;
  }

  return settingsWithDefault.right;
}
github elastic / kibana / x-pack / legacy / plugins / ingest / server / libs / adapters / configurations / default.ts View on Github external
public async getBackup(id: string): Promise {
    const config = await this.so.get('backup_configurations', id);

    if (config.error) {
      throw new Error(config.error.message);
    }

    if (!config.attributes) {
      throw new Error(`No backup configuration found with ID of ${id}`);
    }
    if (isRight(RuntimeConfigurationFile.decode(config.attributes))) {
      return config.attributes as BackupConfigurationFile;
    } else {
      throw new Error(`Invalid BackupConfigurationFile data. == ${config.attributes}`);
    }
  }
github elastic / kibana / x-pack / legacy / plugins / ingest / server / libs / adapters / policy / default.ts View on Github external
const storedPolicies = policies.saved_objects.map(policySO => {
      const policy = {
        id: policySO.id,
        ...policySO.attributes,
      };
      const decoded = RuntimeStoredPolicy.decode(policy);

      if (isRight(decoded)) {
        return decoded.right;
      } else {
        throw new Error(
          `Invalid PolicyFile data. == ${JSON.stringify(policy)}  -- ${PathReporter.report(
            decoded
          )}`
        );
      }
    });
    return {
github marcellourbani / vscode_abap_remote_fs / client / src / views / abapgit.ts View on Github external
const getBranches = (x: RepoAccess) => async () =>
          (
            await this.git.getRemoteInfo(repoUrl, client, x.user, x.password)
          ).branches.map(b => b.name)
        const placeHolder = "select branch"
        const replaceBranch = dependFieldReplacer("branch", x =>
          quickPick(getBranches(x), { placeHolder })
        )

        const newAccess = await chainTaskTransformers(
          fieldReplacer("user", inputUser),
          fieldReplacer("password", inputPwd),
          replaceBranch
        )(access)()
        if (isRight(newAccess)) return newAccess.right
      } else access.branch = ri && ri.branches[0] && ri.branches[0].name
    } catch (e) {
      log(e.toString())
    }
    return access
  }
github mikearnaldi / matechs-effect / packages / effect / src / streameither / index.ts View on Github external
return S.stream.chain((str as any) as StreamEither, ea =>
    Ei.isRight(ea)
      ? S.stream.of>(ea)
      : (f(ea.left) as any)
  );
github elastic / kibana / x-pack / legacy / plugins / ingest / server / libs / adapters / configurations / default.ts View on Github external
return configs.map(config => {
      if (isRight(RuntimeConfigurationFile.decode(config.attributes))) {
        return config.attributes;
      } else {
        throw new Error(`Invalid ConfigurationFile data. == ${config.attributes}`);
      }
    });
  }
github elastic / kibana / x-pack / legacy / plugins / infra / public / containers / metrics / with_metrics_time.tsx View on Github external
const mapToTimeUrlState = (value: any) => {
  const result = MetricsTimeRT.decode(value);
  if (isRight(result)) {
    const resultValue = result.right;
    const to = isNumber(resultValue.to) ? moment(resultValue.to).toISOString() : resultValue.to;
    const from = isNumber(resultValue.from)
      ? moment(resultValue.from).toISOString()
      : resultValue.from;
    return { ...resultValue, from, to };
  }
  return undefined;
};
github teamdigitale / io-functions / lib / controllers / profiles.ts View on Github external
profileModelPayload: ExtendedProfile
): Promise | IResponseErrorQuery> {
  const profile: Profile = {
    acceptedTosVersion: profileModelPayload.accepted_tos_version,
    blockedInboxOrChannels: profileModelPayload.blocked_inbox_or_channels,
    email: profileModelPayload.email,
    fiscalCode,
    isInboxEnabled: profileModelPayload.is_inbox_enabled,
    isWebhookEnabled: profileModelPayload.is_webhook_enabled,
    preferredLanguages: profileModelPayload.preferred_languages
  };
  const errorOrProfile = await profileModel.create(profile, profile.fiscalCode);
  const errorOrProfileAsPublicExtendedProfile = errorOrProfile.map(
    toExtendedProfile
  );
  if (isRight(errorOrProfileAsPublicExtendedProfile)) {
    return ResponseSuccessJson(errorOrProfileAsPublicExtendedProfile.value);
  } else {
    return ResponseErrorQuery(
      "Error while creating a new profile",
      errorOrProfileAsPublicExtendedProfile.value
    );
  }
}