Skip to content

Commit

Permalink
change to zod schema
Browse files Browse the repository at this point in the history
  • Loading branch information
danielva-monday committed Sep 25, 2024
1 parent 3cc38e4 commit 2e7ab48
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 136 deletions.
3 changes: 0 additions & 3 deletions build.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
],
"commands-base/*": [
"./src/commands-base/*"
],
"assets/*": [
"./src/assets/*"
]
}
},
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@oclif/core": "^3.18.1",
"@oclif/plugin-autocomplete": "^3.0.5",
"@oclif/plugin-help": "^6.0.12",
"ajv": "^8.17.1",
"archiver": "^5.3.1",
"args-parser": "^1.3.0",
"axios": "^1.6.5",
Expand Down
95 changes: 0 additions & 95 deletions src/assets/mondaycodercSchema.json

This file was deleted.

10 changes: 2 additions & 8 deletions src/services/files-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

import Ajv from 'ajv';
import archiver from 'archiver';
import glob from 'glob';

Check warning on line 6 in src/services/files-service.ts

View workflow job for this annotation

GitHub Actions / Run validations

Using exported name 'glob' as identifier for default export
import parseGitIgnore from 'parse-gitignore';

import rcFileSchema from 'assets/mondaycodercSchema.json';
import { CONFIG_NAME } from 'services/config-service';
import { mondaycodercSchema } from 'services/schemas/mondaycoderc-schema';

import logger from '../utils/logger.js';

Expand Down Expand Up @@ -133,12 +132,7 @@ export const validateIfCanBuild = (directoryPath: string): void => {
RUNTIME: string;
RUNTIME_VERSION: string;
};
const ajv = new Ajv();
const validate = ajv.compile(rcFileSchema);
const isValid = validate(rcFileContent);
if (!isValid) {
throw new Error('Invalid .mondaycoderc file');
}
mondaycodercSchema.parse(rcFileContent);
}
};

Expand Down
45 changes: 45 additions & 0 deletions src/services/schemas/mondaycoderc-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { z } from 'zod';

export const mondaycodercSchema = z
.object({
RUNTIME: z.enum(['Python', 'Java', 'Go', 'PHP', 'Ruby', 'Nodejs', 'NETCore']).optional(),
RUNTIME_VERSION: z.string().optional(),
})
.refine(
data => {
if (data.RUNTIME) {
if (data.RUNTIME === 'Python') {
return /^3\.(10|11|12)\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Java') {
return ['11', '17', '18'].includes(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Go') {
return /^1\.\d+\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'PHP') {
return /^8\.(1|2)\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Ruby') {
return /^3\.(1|2)\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Nodejs') {
return /^(12|14|16|18|20)\.\d+\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'NETCore') {
return /^(6|7)\.\d+$/.test(data.RUNTIME_VERSION || '');
}
}

return true;
},
{
message: 'Invalid RUNTIME_VERSION for the specified RUNTIME',
},
);
4 changes: 0 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"baseUrl": ".",
"strict": true,
"target": "ESNext",
"resolveJsonModule": true,
"lib": [
"ES2022",
"DOM"
Expand Down Expand Up @@ -47,9 +46,6 @@
],
"commands-base/*": [
"./src/commands-base/*"
],
"assets/*": [
"./src/assets/*"
]
}
},
Expand Down
25 changes: 0 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2983,16 +2983,6 @@ ajv@^6.12.4:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^8.17.1:
version "8.17.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.17.1.tgz#37d9a5c776af6bc92d7f4f9510eba4c0a60d11a6"
integrity sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==
dependencies:
fast-deep-equal "^3.1.3"
fast-uri "^3.0.1"
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"

ansi-align@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz"
Expand Down Expand Up @@ -4988,11 +4978,6 @@ fast-safe-stringify@^2.1.1:
resolved "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz"
integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==

fast-uri@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.0.1.tgz#cddd2eecfc83a71c1be2cc2ef2061331be8a7134"
integrity sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==

[email protected]:
version "4.2.5"
resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz#a6747a09296a6cb34f2ae634019bf1738f3b421f"
Expand Down Expand Up @@ -6605,11 +6590,6 @@ json-schema-traverse@^0.4.1:
resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz"
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==

json-schema-traverse@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2"
integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==

json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz"
Expand Down Expand Up @@ -8426,11 +8406,6 @@ require-directory@^2.1.1:
resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz"
integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==

require-from-string@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==

resolve-alpn@^1.0.0, resolve-alpn@^1.2.0:
version "1.2.1"
resolved "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz"
Expand Down

0 comments on commit 2e7ab48

Please sign in to comment.