Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema for Tact configuration #194

Merged
merged 22 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions grammar/configSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "http://json-schema.org/schema#",
"$id": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json",
"title": "Tact configuration schema",
"description": "JSON Schema for Tact configuration file",
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
"type": "object",
"required": ["projects"],
"properties": {
"projects": {
"type": "array",
"description": "The list of all projects with compiler parameters",
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
"items": {
"type": "object",
"required": ["name", "path", "output"],
"properties": {
"name": {
"type": "string",
"description": "The name of a project. All generated files are prefixed with this name"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
},
"path": {
"type": "string",
"description": "The path to the root Tact file"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
},
"output": {
"type": "string",
"description": "The path to a directory where all generated files will be placed"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
},
"options": {
"type": "object",
"description": "Additional project properties",
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
"properties": {
"debug": {
"type": "boolean",
"description": "Enables debug output of a contract. It is useful for debugging purposes. Enabling this contract would report that it was compiled in debug mode using the supported_interfaces method"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
},
"masterchain": {
"type": "boolean",
"description": "Enables masterchain support in the contract"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
},
"external": {
"type": "boolean",
"description": "Allows the contract to call external functions"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
},
"experimental": {
"type": "object",
"description": "Experimental project properties. Might be removed in the future",
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
"properties": {
"inline": {
"type": "boolean",
"description": "Enables inlining of all functions in contracts. Could reduce gas usage at the cost of a bigger contract"
VanishMax marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"ajv": "^8.12.0",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"glob": "^8.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/config/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const projectSchema = z.object({
}).strict();

const configSchema = z.object({
$schema: z.string().optional(),
projects: z.array(projectSchema)
}).strict();

Expand All @@ -31,4 +32,4 @@ export function parseConfig(src: string) {

export function verifyConfig(config: Config) {
return configSchema.parse(config);
}
}
31 changes: 31 additions & 0 deletions src/test/schema.spec.ts
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs';
import path from 'path';
import Ajv from 'ajv';
import { __DANGER_resetNodeId } from '../grammar/ast';

describe('configuration schema', () => {
const ajv = new Ajv();
const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'grammar', 'configSchema.json'), 'utf8'));

beforeEach(() => {
__DANGER_resetNodeId();
});

it('should validate Tact config', () => {
const tactConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'tact.config.json'), 'utf8'));

const validate = ajv.compile(schema);
validate(tactConfig);

expect(validate.errors).toBeNull();
});

it('should validate test config', () => {
const testConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'test-tact.config.json'), 'utf8'));

const validate = ajv.compile(schema);
validate(testConfig);

expect(validate.errors).toBeNull();
});
});
21 changes: 11 additions & 10 deletions src/test/test-tact.config.json
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"projects": [
{
"name": "implicit-init-2",
"path": "./features/implicit-init-2.tact",
"output": "./features/output",
"options": {
"debug": true
}
"$schema": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json",
"projects": [
{
"name": "implicit-init-2",
"path": "./features/implicit-init-2.tact",
"output": "./features/output",
"options": {
"debug": true
}
]
}
}
]
}
3 changes: 2 additions & 1 deletion tact.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://raw.githubusercontent.com/tact-lang/tact/main/grammar/configSchema.json",
"projects": [
{
"name": "echo",
Expand Down Expand Up @@ -269,4 +270,4 @@
}
}
]
}
}
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,16 @@ ajv@^6.12.4:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^8.12.0:
version "8.12.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
dependencies:
fast-deep-equal "^3.1.1"
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"
uri-js "^4.2.2"

ansi-align@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59"
Expand Down Expand Up @@ -4139,6 +4149,11 @@ json-schema-traverse@^0.4.1:
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
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.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
Expand Down Expand Up @@ -5095,6 +5110,11 @@ require-directory@^2.1.1:
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
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.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.2.1.tgz#b7adbdac3546aaaec20b45e7d8265927072726f9"
Expand Down
Loading