How to use the yup.lazy function in yup

To help you get started, we’ve selected a few yup 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 TheThingsNetwork / lorawan-stack / pkg / webui / console / components / device-data-form / validation-schema.js View on Github external
key: Yup.string()
                .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                .transform(toUndefined)
                .default(random16BytesString),
            }),
            s_nwk_s_int_key: Yup.lazy(() =>
              isNewVersion
                ? Yup.object().shape({
                    key: Yup.string()
                      .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                      .transform(toUndefined)
                      .default(random16BytesString),
                  })
                : Yup.object().strip(),
            ),
            nwk_s_enc_key: Yup.lazy(() =>
              isNewVersion
                ? Yup.object().shape({
                    key: Yup.string()
                      .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                      .transform(toUndefined)
                      .default(random16BytesString),
                  })
                : Yup.object().strip(),
            ),
            app_s_key: Yup.object().shape({
              key: Yup.string()
                .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                .transform(toUndefined)
                .default(random16BytesString),
            }),
          }),
github TheThingsNetwork / lorawan-stack / pkg / webui / console / components / device-data-form / validation-schema.js View on Github external
then: schema =>
        schema.shape({
          nwk_key: Yup.lazy(
            value =>
              value !== undefined
                ? Yup.object().shape({
                    key: Yup.string()
                      .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                      .transform(toUndefined)
                      .default(random16BytesString),
                  })
                : Yup.object().strip(), // Avoid generating when key is unexposed
          ),
          app_key: Yup.lazy(
            value =>
              value !== undefined
                ? Yup.object().shape({
                    key: Yup.string()
                      .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                      .transform(toUndefined)
                      .default(random16BytesString),
                  })
                : Yup.object().strip(), // Avoid generating when key is unexposed
          ),
        }),
      otherwise: schema =>
github TheThingsNetwork / lorawan-stack / pkg / webui / console / views / device-general-settings / network-server-form / validation-schema.js View on Github external
(externalJs, version, mode, schema) => {
        if (mode === ACTIVATION_MODES.OTAA) {
          const strippedSchema = Yup.object().strip()
          const keySchema = Yup.lazy(() => {
            return !externalJs
              ? Yup.object().shape({
                  key: Yup.string()
                    .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                    .transform(toUndefined)
                    .default(random16BytesString),
                })
              : strippedSchema
          })

          if (externalJs) {
            return schema.shape({
              nwk_key: strippedSchema,
              app_key: strippedSchema,
            })
          }
github TheThingsNetwork / lorawan-stack / pkg / webui / console / views / device-general-settings / join-server-form / validation-schema.js View on Github external
(externalJs, version, schema) => {
        const strippedSchema = Yup.object().strip()
        const keySchema = Yup.lazy(() => {
          return !externalJs
            ? Yup.object().shape({
                key: Yup.string()
                  .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                  .transform(toUndefined)
                  .default(random16BytesString),
              })
            : Yup.object().strip()
        })

        if (externalJs) {
          return schema.shape({
            nwk_key: strippedSchema,
            app_key: strippedSchema,
          })
        }
github TheThingsNetwork / lorawan-stack / pkg / webui / console / views / device-general-settings / identity-server-form / validation-schema.js View on Github external
(externalJs, version, schema) => {
        const strippedSchema = Yup.object().strip()
        const keySchema = Yup.lazy(() => {
          return !externalJs
            ? Yup.object().shape({
                key: Yup.string()
                  .emptyOrLength(16 * 2, m.validate32) // 16 Byte hex
                  .transform(toUndefined)
                  .default(random16BytesString),
              })
            : Yup.object().strip()
        })

        if (externalJs) {
          return schema.shape({
            nwk_key: strippedSchema,
            app_key: strippedSchema,
          })
        }
github strapi / strapi / packages / strapi-plugin-content-type-builder / admin / src / containers / FormModal / utils / forms.js View on Github external
}

          return yup.object().shape({
            ...commonShape,
            default: defaultType.nullable(),
            ...numberTypeShape,
          });
        }
        case 'relation':
          return yup.object().shape({
            name: yup
              .string()
              .matches(NAME_REGEX, errorsTrads.regex)
              .unique(errorsTrads.unique, alreadyTakenAttributes)
              .required(errorsTrads.required),
            targetAttribute: yup.lazy(() => {
              let schema = yup.string();

              if (!['oneWay', 'manyWay'].includes(dataToValidate.nature)) {
                schema = schema.matches(NAME_REGEX, errorsTrads.regex);
              }
              return schema
                .unique(errorsTrads.unique, targetAttributeAlreadyTakenValue)
                .required(errorsTrads.required);
            }),
            target: yup.string().required(errorsTrads.required),
            nature: yup.string().required(),
            dominant: yup.boolean().nullable(),
            unique: yup.boolean().nullable(),
          });
        default:
          return yup.object().shape({
github strapi / strapi / packages / strapi-plugin-content-manager / admin / src / containers / EditViewDataManagerProvider / utils / schema.js View on Github external
.of(componentFieldSchema)
                  .nullable();

          if (min) {
            componentSchema = componentSchema.min(min, errorsTrads.min);
          }

          if (max) {
            componentSchema = componentSchema.max(max, errorsTrads.max);
          }

          acc[current] = componentSchema;

          return acc;
        } else {
          const componentSchema = yup.lazy(obj => {
            if (obj !== undefined) {
              return attribute.required === true
                ? componentFieldSchema.defined()
                : componentFieldSchema.nullable();
            }

            return attribute.required === true
              ? yup.object().defined()
              : yup.object().nullable();
          });

          acc[current] = componentSchema;

          return acc;
        }
      }
github instamed / healthcare-payments-blockchain / packages / financial-cc / src / financial.model.ts View on Github external
@Validate(yup.lazy(() => Money.schema()))
   public unitPrice?: FlatConvectorModel;

   @Validate(yup.number())
   public factor?: number;

   @Validate(yup.lazy(() => Money.schema()))
   public net?: FlatConvectorModel;

   @Validate(yup.lazy(() => yup.array(Reference.schema())))
   public udi?: Array>; //Device

   @Validate(yup.array(yup.number()))
   public noteNumber?: Array;

   @Validate(yup.lazy(() => yup.array(ExplanationOfBenefitItemAdjudication.schema())))
   public adjudication?: Array>;

   @Validate(yup.lazy(() => yup.array(ExplanationOfBenefitItemDetailSubDetail.schema())))
   public subDetail?: Array>;

}

export class ExplanationOfBenefitItemDetailSubDetail extends BackboneElement {
   @Default('fhir.datatypes.ExplanationOfBenefit.ExplanationOfBenefitItemDetailSubDetail')
   @ReadOnly()
   public readonly type: string;

   @Required()
   @Validate(yup.number())
   public sequence: number;
github gojek / turing / ui / src / router / components / form / validation / schema.js View on Github external
type: yup
          .mixed()
          .required("Valid Experiment Engine should be selected")
          .when("$experimentEngineOptions", (options, schema) =>
            schema.oneOf(options, "Valid Experiment Engine should be selected")
          ),
        config: yup.mixed().when("type", {
          is: "nop",
          otherwise: experimentConfigSchema
        })
      })
    })
  }),
  yup.object().shape({
    config: yup.object().shape({
      enricher: yup.lazy(value => {
        switch (value.type) {
          case "docker":
            return enricherSchema.concat(dockerDeploymentSchema);
          default:
            return enricherSchema;
        }
      })
    })
  }),
  yup.object().shape({
    config: yup.object().shape({
      ensembler: yup.object().shape({
        type: yup
          .mixed()
          .required("Valid Ensembler type should be selected")
          .oneOf(