Skip to content

Commit

Permalink
feat: add slot, tag and deprecate version
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Sep 8, 2024
1 parent 8acebc4 commit bad1b04
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@subsquid/manifest",
"type": "commonjs",
"version": "1.0.0-beta.14",
"version": "2.0.0-beta.1",
"homepage": "https://www.subsquid.io",
"repository": "https://github.com/subsquid/manifest.git",
"license": "GPL-3.0-or-later",
Expand Down
70 changes: 68 additions & 2 deletions schemas/squid_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,62 @@
"$id": "https://cdn.subsquid.io/schemas/squid_manifest.json",
"$schema": "https://json-schema.org/draft-07/schema",
"additionalProperties": false,
"oneOf": [
{
"required": [
"slot"
]
},
{
"required": [
"version"
]
},
{
"required": [
"tag"
]
},
{
"not": {
"oneOf": [
{
"required": [
"slot"
]
},
{
"required": [
"version"
]
},
{
"required": [
"tag"
]
},
{
"required": [
"slot",
"version"
]
},
{
"required": [
"slot",
"tag"
]
},
{
"required": [
"version",
"tag"
]
}
]
}
}
],
"properties": {
"manifest_version": {
"const": "subsquid.io/v0.1"
Expand All @@ -17,6 +73,18 @@
"maximum": 1000000,
"exclusiveMinimum": 0
},
"slot": {
"type": "string",
"minLength": 2,
"maxLength": 6,
"pattern": "^[a-z0-9][a-z0-9\\-]*[a-z0-9]$"
},
"tag": {
"type": "string",
"minLength": 3,
"maxLength": 32,
"pattern": "^[a-z0-9][a-z0-9\\-]*[a-z0-9]$"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -655,8 +723,6 @@
}
},
"required": [
"name",
"version",
"deploy"
],
"type": "object"
Expand Down
4 changes: 2 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export class Manifest {
return this.name;
}

versionName() {
return `v${this.version}`;
slotName() {
return this.slot || (this.version ? `v${this.version}` : undefined);
}

values(): ManifestValue {
Expand Down
52 changes: 33 additions & 19 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ManifestProcessor, ManifestValue } from './types';

export const SECRET_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
export const SQUID_NAME_PATTERN = /^[a-z0-9][a-z0-9\-]*[a-z0-9]$/;
export const SQUID_SLOT_PATTERN = SQUID_NAME_PATTERN;
export const SQUID_TAG_PATTERN = SQUID_NAME_PATTERN;
export const DEFAULT_NODE_VERSION = '20';
export const DEFAULT_PACKAGE_MANAGER = 'auto';
export const ENV_NAME_PATTERN = SECRET_NAME_PATTERN;
Expand All @@ -19,21 +21,31 @@ export const JoiSquidName = Joi.string().min(3).max(30).pattern(SQUID_NAME_PATTE
'The squid name "{#value}" is invalid. Only lowercase latin letters, numbers and the dash symbol are allowed for the squid name. The squid name cannot start with a dash',
});

export const JoiSquidVersionName = Joi.number()
.integer()
.max(1000000)
.positive()
.required()
.messages({
'any.required': 'The squid version is required',
'number.unsafe': `The squid version "{#value}" is invalid. Must be a number from 1 to 1000000`,
});
export const JoiSquidVersion = Joi.number().integer().max(1000000).positive().messages({
'any.required': 'The squid version is required',
'number.unsafe': `The squid version "{#value}" is invalid. Must be a number from 1 to 1000000`,
});

export const JoiSquidSlot = Joi.string().min(2).max(6).pattern(SQUID_SLOT_PATTERN).messages({
'any.required': 'The squid slot is required',
'string.min': 'The squid slot must contain at least {#limit} symbol(s)',
'string.max': 'The squid slot must contain no more than {#limit} symbol(s)',
'string.pattern.base':
'The squid slot "{#value}" is invalid. Only lowercase latin letters, numbers and the dash symbol are allowed for the squid slot. The squid slot cannot start with a dash',
});

export const JoiSquidTag = Joi.string().min(3).max(32).pattern(SQUID_TAG_PATTERN).messages({
'any.required': 'The squid tag is required',
'string.min': 'The squid tag must contain at least {#limit} symbol(s)',
'string.max': 'The squid tag must contain no more than {#limit} symbol(s)',
'string.pattern.base':
'The squid tag "{#value}" is invalid. Only lowercase latin letters, numbers and the dash symbol are allowed for the squid tag. The squid tag cannot start with a dash',
});

const envSchema = Joi.object().pattern(ENV_NAME_PATTERN, Joi.envString().required());

const cmdSchema = Joi.string()
.regex(/^[:\-\/\w.]+$/)
.required()
.messages({
'string.pattern.base':
'{#label} with value "{#value}" is invalid. Only latin letters, numbers, ".", "-", "_", "/" and ":" symbols are allowed.',
Expand All @@ -54,14 +66,16 @@ export const processorSchema = (multi = true) => {
return Joi.object<ManifestProcessor>({
name: nameSchema,
env: envSchema,
cmd: Joi.array().items(cmdSchema).min(1).required(),
cmd: Joi.array().items(cmdSchema.required()).min(1).required(),
});
};

export const manifestSchema = Joi.object<ManifestValue>({
manifest_version: Joi.string().valid(...AVAILABLE_MANIFEST_VERSIONS),
name: JoiSquidName.required(),
version: JoiSquidVersionName,
name: JoiSquidName,
version: JoiSquidVersion,
slot: JoiSquidSlot,
tag: JoiSquidTag,
description: Joi.string().trim(),
queries: Joi.object(),
build: Joi.object({
Expand All @@ -72,9 +86,9 @@ export const manifestSchema = Joi.object<ManifestValue>({
.valid('auto', 'npm', 'pnpm', 'yarn')
.default(DEFAULT_PACKAGE_MANAGER),
install: Joi.object({
cmd: Joi.array().items(cmdSchema).min(1).required(),
cmd: Joi.array().items(cmdSchema.required()).min(1).required(),
}),
cmd: Joi.array().items(cmdSchema).min(1),
cmd: Joi.array().items(cmdSchema.required()).min(1),
}).allow(null),

deploy: Joi.object({
Expand Down Expand Up @@ -113,12 +127,12 @@ export const manifestSchema = Joi.object<ManifestValue>({

init: Joi.object({
env: envSchema,
cmd: Joi.array().items(cmdSchema).min(1).required(),
cmd: Joi.array().items(cmdSchema.required()).min(1).required(),
}).allow(false),

migrate: Joi.object({
env: envSchema,
cmd: Joi.array().items(cmdSchema).min(1).required(),
cmd: Joi.array().items(cmdSchema.required()).min(1).required(),
})
.description('[DEPRECATED] Please use "deploy.init" instead')
.allow(false),
Expand All @@ -138,7 +152,7 @@ export const manifestSchema = Joi.object<ManifestValue>({

api: Joi.object({
env: envSchema,
cmd: Joi.array().items(cmdSchema).min(1).required(),
cmd: Joi.array().items(cmdSchema.required()).min(1).required(),
}),

/** @deprecated **/
Expand Down Expand Up @@ -214,4 +228,4 @@ export const manifestSchema = Joi.object<ManifestValue>({
.description('[DEPRECATED] Please use "manifest_version" instead.')
.valid(...AVAILABLE_MANIFEST_VERSIONS)
.meta({ deprecated: true }),
});
}).oxor('slot', 'version', 'tag');
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,15 @@ export type ManifestValue = {
* @deprecated
*/
manifestVersion?: string;
/**
* @deprecated
*/
version?: number;

manifest_version: string;
name: string;
version: number;
name?: string;
slot?: string;
tag?: string;
description?: string;
queries?: Record<string, string>;

Expand Down

0 comments on commit bad1b04

Please sign in to comment.