build: update dist files with named tuple support
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
23ee60bc20
commit
9adce3d45e
|
|
@ -114,13 +114,13 @@ var Parser = class {
|
|||
this.consume();
|
||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||
}
|
||||
elements.push(this.parseSchema());
|
||||
elements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(";")) {
|
||||
const remainingElements = [];
|
||||
while (true) {
|
||||
this.skipWhitespace();
|
||||
remainingElements.push(this.parseSchema());
|
||||
remainingElements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(";")) {
|
||||
break;
|
||||
|
|
@ -137,13 +137,13 @@ var Parser = class {
|
|||
if (!this.consumeStr("]")) {
|
||||
throw new ParseError("Expected ]", this.pos);
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "array", element: { type: "tuple", elements } };
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "tuple", elements };
|
||||
}
|
||||
|
|
@ -163,6 +163,28 @@ var Parser = class {
|
|||
}
|
||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||
}
|
||||
parseNamedSchema() {
|
||||
this.skipWhitespace();
|
||||
const startpos = this.pos;
|
||||
let identifier = "";
|
||||
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||
identifier += this.consume();
|
||||
}
|
||||
if (identifier.length === 0) {
|
||||
throw new ParseError("Expected schema or named schema", this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(":")) {
|
||||
this.skipWhitespace();
|
||||
const name = identifier;
|
||||
const schema = this.parseSchema();
|
||||
return { name, schema };
|
||||
} else {
|
||||
this.pos = startpos;
|
||||
const schema = this.parseSchema();
|
||||
return { schema };
|
||||
}
|
||||
}
|
||||
};
|
||||
function parseSchema(schemaString) {
|
||||
const parser = new Parser(schemaString.trim());
|
||||
|
|
@ -270,7 +292,15 @@ var ValueParser = class {
|
|||
const result = [];
|
||||
for (let i = 0; i < schema.elements.length; i++) {
|
||||
this.skipWhitespace();
|
||||
result.push(this.parseValue(schema.elements[i], false));
|
||||
const elementSchema = schema.elements[i];
|
||||
if (elementSchema.name) {
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
}
|
||||
result.push(this.parseValue(elementSchema.schema, false));
|
||||
this.skipWhitespace();
|
||||
if (i < schema.elements.length - 1) {
|
||||
if (!this.consumeStr(";")) {
|
||||
|
|
@ -352,7 +382,7 @@ function createValidator(schema) {
|
|||
if (!Array.isArray(value)) return false;
|
||||
if (value.length !== schema.elements.length) return false;
|
||||
return schema.elements.every(
|
||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
||||
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||
);
|
||||
case "array":
|
||||
if (!Array.isArray(value)) return false;
|
||||
|
|
@ -376,12 +406,12 @@ function schemaToTypeString(schema) {
|
|||
return "boolean";
|
||||
case "array":
|
||||
if (schema.element.type === "tuple") {
|
||||
const tupleElements2 = schema.element.elements.map(schemaToTypeString);
|
||||
const tupleElements2 = schema.element.elements.map((el) => schemaToTypeString(el.schema));
|
||||
return `[${tupleElements2.join(", ")}]`;
|
||||
}
|
||||
return `${schemaToTypeString(schema.element)}[]`;
|
||||
case "tuple":
|
||||
const tupleElements = schema.elements.map(schemaToTypeString);
|
||||
const tupleElements = schema.elements.map((el) => schemaToTypeString(el.schema));
|
||||
return `[${tupleElements.join(", ")}]`;
|
||||
default:
|
||||
return "unknown";
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@ var Parser = class {
|
|||
this.consume();
|
||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||
}
|
||||
elements.push(this.parseSchema());
|
||||
elements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(";")) {
|
||||
const remainingElements = [];
|
||||
while (true) {
|
||||
this.skipWhitespace();
|
||||
remainingElements.push(this.parseSchema());
|
||||
remainingElements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(";")) {
|
||||
break;
|
||||
|
|
@ -103,13 +103,13 @@ var Parser = class {
|
|||
if (!this.consumeStr("]")) {
|
||||
throw new ParseError("Expected ]", this.pos);
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "array", element: { type: "tuple", elements } };
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "tuple", elements };
|
||||
}
|
||||
|
|
@ -129,6 +129,28 @@ var Parser = class {
|
|||
}
|
||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||
}
|
||||
parseNamedSchema() {
|
||||
this.skipWhitespace();
|
||||
const startpos = this.pos;
|
||||
let identifier = "";
|
||||
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||
identifier += this.consume();
|
||||
}
|
||||
if (identifier.length === 0) {
|
||||
throw new ParseError("Expected schema or named schema", this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(":")) {
|
||||
this.skipWhitespace();
|
||||
const name = identifier;
|
||||
const schema = this.parseSchema();
|
||||
return { name, schema };
|
||||
} else {
|
||||
this.pos = startpos;
|
||||
const schema = this.parseSchema();
|
||||
return { schema };
|
||||
}
|
||||
}
|
||||
};
|
||||
function parseSchema(schemaString) {
|
||||
const parser = new Parser(schemaString.trim());
|
||||
|
|
@ -236,7 +258,15 @@ var ValueParser = class {
|
|||
const result = [];
|
||||
for (let i = 0; i < schema.elements.length; i++) {
|
||||
this.skipWhitespace();
|
||||
result.push(this.parseValue(schema.elements[i], false));
|
||||
const elementSchema = schema.elements[i];
|
||||
if (elementSchema.name) {
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
}
|
||||
result.push(this.parseValue(elementSchema.schema, false));
|
||||
this.skipWhitespace();
|
||||
if (i < schema.elements.length - 1) {
|
||||
if (!this.consumeStr(";")) {
|
||||
|
|
@ -318,7 +348,7 @@ function createValidator(schema) {
|
|||
if (!Array.isArray(value)) return false;
|
||||
if (value.length !== schema.elements.length) return false;
|
||||
return schema.elements.every(
|
||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
||||
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||
);
|
||||
case "array":
|
||||
if (!Array.isArray(value)) return false;
|
||||
|
|
@ -342,12 +372,12 @@ function schemaToTypeString(schema) {
|
|||
return "boolean";
|
||||
case "array":
|
||||
if (schema.element.type === "tuple") {
|
||||
const tupleElements2 = schema.element.elements.map(schemaToTypeString);
|
||||
const tupleElements2 = schema.element.elements.map((el) => schemaToTypeString(el.schema));
|
||||
return `[${tupleElements2.join(", ")}]`;
|
||||
}
|
||||
return `${schemaToTypeString(schema.element)}[]`;
|
||||
case "tuple":
|
||||
const tupleElements = schema.elements.map(schemaToTypeString);
|
||||
const tupleElements = schema.elements.map((el) => schemaToTypeString(el.schema));
|
||||
return `[${tupleElements.join(", ")}]`;
|
||||
default:
|
||||
return "unknown";
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ type SchemaType = 'string' | 'number' | 'boolean';
|
|||
interface PrimitiveSchema {
|
||||
type: SchemaType;
|
||||
}
|
||||
interface NamedSchema {
|
||||
name?: string;
|
||||
schema: Schema;
|
||||
}
|
||||
interface TupleSchema {
|
||||
type: 'tuple';
|
||||
elements: Schema[];
|
||||
elements: NamedSchema[];
|
||||
}
|
||||
interface ArraySchema {
|
||||
type: 'array';
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ type SchemaType = 'string' | 'number' | 'boolean';
|
|||
interface PrimitiveSchema {
|
||||
type: SchemaType;
|
||||
}
|
||||
interface NamedSchema {
|
||||
name?: string;
|
||||
schema: Schema;
|
||||
}
|
||||
interface TupleSchema {
|
||||
type: 'tuple';
|
||||
elements: Schema[];
|
||||
elements: NamedSchema[];
|
||||
}
|
||||
interface ArraySchema {
|
||||
type: 'array';
|
||||
|
|
|
|||
|
|
@ -107,13 +107,13 @@ var Parser = class {
|
|||
this.consume();
|
||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||
}
|
||||
elements.push(this.parseSchema());
|
||||
elements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(";")) {
|
||||
const remainingElements = [];
|
||||
while (true) {
|
||||
this.skipWhitespace();
|
||||
remainingElements.push(this.parseSchema());
|
||||
remainingElements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(";")) {
|
||||
break;
|
||||
|
|
@ -130,13 +130,13 @@ var Parser = class {
|
|||
if (!this.consumeStr("]")) {
|
||||
throw new ParseError("Expected ]", this.pos);
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "array", element: { type: "tuple", elements } };
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "tuple", elements };
|
||||
}
|
||||
|
|
@ -156,6 +156,28 @@ var Parser = class {
|
|||
}
|
||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||
}
|
||||
parseNamedSchema() {
|
||||
this.skipWhitespace();
|
||||
const startpos = this.pos;
|
||||
let identifier = "";
|
||||
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||
identifier += this.consume();
|
||||
}
|
||||
if (identifier.length === 0) {
|
||||
throw new ParseError("Expected schema or named schema", this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(":")) {
|
||||
this.skipWhitespace();
|
||||
const name = identifier;
|
||||
const schema = this.parseSchema();
|
||||
return { name, schema };
|
||||
} else {
|
||||
this.pos = startpos;
|
||||
const schema = this.parseSchema();
|
||||
return { schema };
|
||||
}
|
||||
}
|
||||
};
|
||||
function parseSchema(schemaString) {
|
||||
const parser = new Parser(schemaString.trim());
|
||||
|
|
@ -263,7 +285,15 @@ var ValueParser = class {
|
|||
const result = [];
|
||||
for (let i = 0; i < schema.elements.length; i++) {
|
||||
this.skipWhitespace();
|
||||
result.push(this.parseValue(schema.elements[i], false));
|
||||
const elementSchema = schema.elements[i];
|
||||
if (elementSchema.name) {
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
}
|
||||
result.push(this.parseValue(elementSchema.schema, false));
|
||||
this.skipWhitespace();
|
||||
if (i < schema.elements.length - 1) {
|
||||
if (!this.consumeStr(";")) {
|
||||
|
|
@ -345,7 +375,7 @@ function createValidator(schema) {
|
|||
if (!Array.isArray(value)) return false;
|
||||
if (value.length !== schema.elements.length) return false;
|
||||
return schema.elements.every(
|
||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
||||
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||
);
|
||||
case "array":
|
||||
if (!Array.isArray(value)) return false;
|
||||
|
|
|
|||
|
|
@ -77,13 +77,13 @@ var Parser = class {
|
|||
this.consume();
|
||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||
}
|
||||
elements.push(this.parseSchema());
|
||||
elements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(";")) {
|
||||
const remainingElements = [];
|
||||
while (true) {
|
||||
this.skipWhitespace();
|
||||
remainingElements.push(this.parseSchema());
|
||||
remainingElements.push(this.parseNamedSchema());
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(";")) {
|
||||
break;
|
||||
|
|
@ -100,13 +100,13 @@ var Parser = class {
|
|||
if (!this.consumeStr("]")) {
|
||||
throw new ParseError("Expected ]", this.pos);
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "array", element: { type: "tuple", elements } };
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return { type: "array", element: elements[0] };
|
||||
if (elements.length === 1 && !elements[0].name) {
|
||||
return { type: "array", element: elements[0].schema };
|
||||
}
|
||||
return { type: "tuple", elements };
|
||||
}
|
||||
|
|
@ -126,6 +126,28 @@ var Parser = class {
|
|||
}
|
||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||
}
|
||||
parseNamedSchema() {
|
||||
this.skipWhitespace();
|
||||
const startpos = this.pos;
|
||||
let identifier = "";
|
||||
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||
identifier += this.consume();
|
||||
}
|
||||
if (identifier.length === 0) {
|
||||
throw new ParseError("Expected schema or named schema", this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
if (this.consumeStr(":")) {
|
||||
this.skipWhitespace();
|
||||
const name = identifier;
|
||||
const schema = this.parseSchema();
|
||||
return { name, schema };
|
||||
} else {
|
||||
this.pos = startpos;
|
||||
const schema = this.parseSchema();
|
||||
return { schema };
|
||||
}
|
||||
}
|
||||
};
|
||||
function parseSchema(schemaString) {
|
||||
const parser = new Parser(schemaString.trim());
|
||||
|
|
@ -233,7 +255,15 @@ var ValueParser = class {
|
|||
const result = [];
|
||||
for (let i = 0; i < schema.elements.length; i++) {
|
||||
this.skipWhitespace();
|
||||
result.push(this.parseValue(schema.elements[i], false));
|
||||
const elementSchema = schema.elements[i];
|
||||
if (elementSchema.name) {
|
||||
this.skipWhitespace();
|
||||
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||
}
|
||||
this.skipWhitespace();
|
||||
}
|
||||
result.push(this.parseValue(elementSchema.schema, false));
|
||||
this.skipWhitespace();
|
||||
if (i < schema.elements.length - 1) {
|
||||
if (!this.consumeStr(";")) {
|
||||
|
|
@ -315,7 +345,7 @@ function createValidator(schema) {
|
|||
if (!Array.isArray(value)) return false;
|
||||
if (value.length !== schema.elements.length) return false;
|
||||
return schema.elements.every(
|
||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
||||
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||
);
|
||||
case "array":
|
||||
if (!Array.isArray(value)) return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue