Skip to content

Commit

Permalink
refactor: [M3-8945] - Update yup from 0.32.9 to 1.4.0 (#11324)
Browse files Browse the repository at this point in the history
* initial update

* fix cloudpulse schemas

* fix incorrect `stackscript_data` schema

* add changesets

---------

Co-authored-by: Banks Nussman <banks@nussman.us>
  • Loading branch information
bnussman-akamai and bnussman authored Dec 2, 2024
1 parent 8611b57 commit 8c11b28
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 293 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Tech Stories
---

Update yup from `0.32.9` to `1.4.0` ([#11324](https://github.com/linode/manager/pull/11324))
3 changes: 1 addition & 2 deletions packages/api-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@linode/validation": "*",
"axios": "~1.7.4",
"ipaddr.js": "^2.0.0",
"yup": "^0.32.9"
"yup": "^1.4.0"
},
"scripts": {
"start": "concurrently --raw \"tsc -w --preserveWatchOutput\" \"tsup --watch\"",
Expand All @@ -57,7 +57,6 @@
"lib"
],
"devDependencies": {
"@types/yup": "^0.29.13",
"axios-mock-adapter": "^1.22.0",
"concurrently": "^9.0.1",
"eslint": "^6.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Update yup from `0.32.9` to `1.4.0` ([#11324](https://github.com/linode/manager/pull/11324))
10 changes: 6 additions & 4 deletions packages/manager/cypress/support/plugins/generate-weights.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { CypressPlugin } from './plugin';
import { DateTime } from 'luxon';
import { writeFileSync } from 'fs';
import { DateTime } from 'luxon';
import { resolve } from 'path';
import { object, string, array, number, SchemaOf } from 'yup';
import { array, number, object, string } from 'yup';

import type { CypressPlugin } from './plugin';
import type { ObjectSchema } from 'yup';

// The name of the environment variable to read to check if generation is enabled.
// The value should be a path to the weights file.
Expand Down Expand Up @@ -50,7 +52,7 @@ export interface SpecWeight extends SpecResult {
/**
* Spec weights schema for JSON parsing, etc.
*/
export const specWeightsSchema: SchemaOf<SpecWeights> = object({
export const specWeightsSchema: ObjectSchema<SpecWeights> = object({
meta: object({
datetime: string().required(),
totalWeight: number().required(),
Expand Down
3 changes: 1 addition & 2 deletions packages/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"tss-react": "^4.8.2",
"typescript-fsa": "^3.0.0",
"typescript-fsa-reducers": "^1.2.0",
"yup": "^0.32.9",
"yup": "^1.4.0",
"zxcvbn": "^4.4.2"
},
"scripts": {
Expand Down Expand Up @@ -166,7 +166,6 @@
"@types/redux-mock-store": "^1.0.1",
"@types/throttle-debounce": "^1.0.0",
"@types/uuid": "^3.4.3",
"@types/yup": "^0.29.13",
"@types/zxcvbn": "^4.4.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { object, string } from 'yup';

const engineOptionValidation = string().when('service_type', {
is: 'dbaas',
otherwise: string().notRequired().nullable(),
then: string().required('Engine type is required.').nullable(),
otherwise: (schema) => schema.notRequired().nullable(),
then: (schema) => schema.required('Engine type is required.').nullable(),
});

export const CreateAlertDefinitionFormSchema = createAlertDefinitionSchema.concat(
object({
engineType: engineOptionValidation,
region: string().required('Region is required.'),
serviceType: string().required('Service is required.').nullable(),
serviceType: string().required('Service is required.'),
})
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/validation": Tech Stories
---

Update yup from `0.32.9` to `1.4.0` ([#11324](https://github.com/linode/manager/pull/11324))
3 changes: 1 addition & 2 deletions packages/validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
"url": "https://github.com/linode/manager/tree/develop/packages/validation"
},
"dependencies": {
"@types/yup": "^0.29.13",
"ipaddr.js": "^2.0.0",
"libphonenumber-js": "^1.10.6",
"yup": "^0.32.9"
"yup": "^1.4.0"
},
"devDependencies": {
"concurrently": "^9.0.1",
Expand Down
19 changes: 11 additions & 8 deletions packages/validation/src/account.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export const PaymentMethodSchema = object({
),
data: object().when('type', {
is: 'credit_card',
then: CreditCardSchema,
otherwise: object({
nonce: string().required('Payment nonce is required.'),
}),
then: () => CreditCardSchema,
otherwise: () =>
object({
nonce: string().required('Payment nonce is required.'),
}),
}),
is_default: boolean().required(
'You must indicate if this should be your default method of payment.'
Expand Down Expand Up @@ -100,10 +101,12 @@ export const UpdateUserSchema = object({

const GrantSchema = object({
id: number().required('ID is required.'),
permissions: mixed().oneOf(
[null, 'read_only', 'read_write'],
'Permissions must be null, read_only, or read_write.'
),
permissions: string()
.oneOf(
['read_only', 'read_write'],
'Permissions must be null, read_only, or read_write.'
)
.nullable('Permissions must be null, read_only, or read_write.'),
});

export const UpdateGrantSchema = object({
Expand Down
4 changes: 2 additions & 2 deletions packages/validation/src/buckets.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const CreateBucketSchema = object()
),
cluster: string().when('region', {
is: (region: string) => !region || region.length === 0,
then: string().required('Cluster is required.'),
then: (schema) => schema.required('Cluster is required.'),
}),
region: string().when('cluster', {
is: (cluster: string) => !cluster || cluster.length === 0,
then: string().required('Region is required.'),
then: (schema) => schema.required('Region is required.'),
}),
endpoint_type: string()
.oneOf([...ENDPOINT_TYPES])
Expand Down
2 changes: 1 addition & 1 deletion packages/validation/src/cloudpulse.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const triggerCondition = object({
export const createAlertDefinitionSchema = object({
label: string().required('Name is required.'),
description: string().optional(),
severity: string().required('Severity is required.'),
entity_ids: array().of(string()).min(1, 'At least one resource is needed.'),
severity: string().required('Severity is required.').nullable(),
criteria: array()
.of(metricCriteria)
.min(1, 'At least one metric criteria is needed.'),
Expand Down
8 changes: 4 additions & 4 deletions packages/validation/src/databases.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const createDatabaseSchema = object({
cluster_size: number()
.oneOf([1, 2, 3], 'Nodes are required')
.required('Nodes are required'),
replication_type: string().notRequired().nullable(true), // TODO (UIE-8214) remove POST GA
replication_commit_type: string().notRequired().nullable(true), // TODO (UIE-8214) remove POST GA
replication_type: string().notRequired().nullable(), // TODO (UIE-8214) remove POST GA
replication_commit_type: string().notRequired().nullable(), // TODO (UIE-8214) remove POST GA
});

export const updateDatabaseSchema = object({
Expand All @@ -28,8 +28,8 @@ export const updateDatabaseSchema = object({
duration: number(),
hour_of_day: number(),
day_of_week: number(),
week_of_month: number().nullable(true),
week_of_month: number().nullable(),
})
.nullable(true),
.nullable(),
type: string().notRequired(),
});
16 changes: 7 additions & 9 deletions packages/validation/src/domains.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,20 @@ export const createDomainSchema = domainSchemaBase.shape({
soa_email: string()
.when('type', {
is: 'master',
then: string().required('SOA Email is required.'),
otherwise: string(),
then: (schema) => schema.required('SOA Email is required.'),
})
.email('SOA Email is not valid.')
.trim(),
master_ips: array()
.of(string())
.when('type', {
is: 'slave',
then: array()
.of(string())
.compact()
.ensure()
.required('At least one primary IP address is required.')
.min(1, 'At least one primary IP address is required.'),
otherwise: array().of(string()),
then: (schema) =>
schema
.compact()
.ensure()
.required('At least one primary IP address is required.')
.min(1, 'At least one primary IP address is required.'),
}),
});

Expand Down
23 changes: 12 additions & 11 deletions packages/validation/src/firewalls.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,27 @@ export const FirewallRuleTypeSchema = object().shape({
.required('Protocol is required.'),
ports: string().when('protocol', {
is: (val: any) => val !== 'ICMP' && val !== 'IPENCAP',
then: validateFirewallPorts,
then: () => validateFirewallPorts,
// Workaround to get the test to fail if ports is defined when protocol === ICMP or IPENCAP
otherwise: string().test({
name: 'protocol',
message: 'Ports are not allowed for ICMP and IPENCAP protocols.',
test: (value) => typeof value === 'undefined',
}),
otherwise: (schema) =>
schema.test({
name: 'protocol',
message: 'Ports are not allowed for ICMP and IPENCAP protocols.',
test: (value) => typeof value === 'undefined',
}),
}),
addresses: object()
.shape({
ipv4: array().of(ipAddress).nullable(true),
ipv6: array().of(ipAddress).nullable(true),
ipv4: array().of(ipAddress).nullable(),
ipv6: array().of(ipAddress).nullable(),
})
.strict(true)
.nullable(true),
.nullable(),
});

export const FirewallRuleSchema = object().shape({
inbound: array(FirewallRuleTypeSchema).nullable(true),
outbound: array(FirewallRuleTypeSchema).nullable(true),
inbound: array(FirewallRuleTypeSchema).nullable(),
outbound: array(FirewallRuleTypeSchema).nullable(),
inbound_policy: mixed()
.oneOf(['ACCEPT', 'DROP'])
.required('Inbound policy is required.'),
Expand Down
48 changes: 25 additions & 23 deletions packages/validation/src/kubernetes.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,33 @@ export const AutoscaleNodePoolSchema = object({
enabled: boolean(),
min: number().when('enabled', {
is: true,
then: number()
.required()
.test(
'min',
'Minimum must be between 1 and 99 nodes and cannot be greater than Maximum.',
function (min) {
if (!min) {
return false;
then: (schema) =>
schema
.required()
.test(
'min',
'Minimum must be between 1 and 99 nodes and cannot be greater than Maximum.',
function (min) {
if (!min) {
return false;
}
if (min < 1 || min > 99) {
return false;
}
if (min > this.parent['max']) {
return false;
}
return true;
}
if (min < 1 || min > 99) {
return false;
}
if (min > this.parent['max']) {
return false;
}
return true;
}
),
),
}),
max: number().when('enabled', {
is: true,
then: number()
.required()
.min(1, 'Maximum must be between 1 and 100 nodes.')
.max(100, 'Maximum must be between 1 and 100 nodes.'),
then: (schema) =>
schema
.required()
.min(1, 'Maximum must be between 1 and 100 nodes.')
.max(100, 'Maximum must be between 1 and 100 nodes.'),
}),
});

Expand Down Expand Up @@ -76,8 +78,8 @@ const controlPlaneACLOptionsSchema = object().shape({
enabled: boolean(),
'revision-id': string(),
addresses: object().shape({
ipv4: array().of(ipv4Address).nullable(true),
ipv6: array().of(ipv6Address).nullable(true),
ipv4: array().of(ipv4Address).nullable(),
ipv6: array().of(ipv6Address).nullable(),
}),
});

Expand Down
Loading

0 comments on commit 8c11b28

Please sign in to comment.