Feat: Multiplayer sessions added using CRUD database.
This commit is contained in:
83
node_modules/schema-utils/dist/keywords/absolutePath.js
generated
vendored
Normal file
83
node_modules/schema-utils/dist/keywords/absolutePath.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
/** @typedef {import("ajv").default} Ajv */
|
||||
/** @typedef {import("ajv").SchemaValidateFunction} SchemaValidateFunction */
|
||||
/** @typedef {import("ajv").AnySchemaObject} AnySchemaObject */
|
||||
/** @typedef {import("../validate").SchemaUtilErrorObject} SchemaUtilErrorObject */
|
||||
|
||||
/**
|
||||
* @param {string} message message
|
||||
* @param {object} schema schema
|
||||
* @param {string} data data
|
||||
* @returns {SchemaUtilErrorObject} error object
|
||||
*/
|
||||
function errorMessage(message, schema, data) {
|
||||
return {
|
||||
dataPath: undefined,
|
||||
// @ts-expect-error
|
||||
schemaPath: undefined,
|
||||
keyword: "absolutePath",
|
||||
params: {
|
||||
absolutePath: data
|
||||
},
|
||||
message,
|
||||
parentSchema: schema
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} shouldBeAbsolute true when should be absolute path, otherwise false
|
||||
* @param {object} schema schema
|
||||
* @param {string} data data
|
||||
* @returns {SchemaUtilErrorObject} error object
|
||||
*/
|
||||
function getErrorFor(shouldBeAbsolute, schema, data) {
|
||||
const message = shouldBeAbsolute ? `The provided value ${JSON.stringify(data)} is not an absolute path!` : `A relative path is expected. However, the provided value ${JSON.stringify(data)} is an absolute path!`;
|
||||
return errorMessage(message, schema, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Ajv} ajv ajv
|
||||
* @returns {Ajv} configured ajv
|
||||
*/
|
||||
function addAbsolutePathKeyword(ajv) {
|
||||
ajv.addKeyword({
|
||||
keyword: "absolutePath",
|
||||
type: "string",
|
||||
errors: true,
|
||||
/**
|
||||
* @param {boolean} schema schema
|
||||
* @param {AnySchemaObject} parentSchema parent schema
|
||||
* @returns {SchemaValidateFunction} validate function
|
||||
*/
|
||||
compile(schema, parentSchema) {
|
||||
/** @type {SchemaValidateFunction} */
|
||||
const callback = data => {
|
||||
let passes = true;
|
||||
const isExclamationMarkPresent = data.includes("!");
|
||||
if (isExclamationMarkPresent) {
|
||||
callback.errors = [errorMessage(`The provided value ${JSON.stringify(data)} contains exclamation mark (!) which is not allowed because it's reserved for loader syntax.`, parentSchema, data)];
|
||||
passes = false;
|
||||
}
|
||||
|
||||
// ?:[A-Za-z]:\\ - Windows absolute path
|
||||
// \\\\ - Windows network absolute path
|
||||
// \/ - Unix-like OS absolute path
|
||||
const isCorrectAbsolutePath = schema === /^(?:[A-Za-z]:(\\|\/)|\\\\|\/)/.test(data);
|
||||
if (!isCorrectAbsolutePath) {
|
||||
callback.errors = [getErrorFor(schema, parentSchema, data)];
|
||||
passes = false;
|
||||
}
|
||||
return passes;
|
||||
};
|
||||
callback.errors = [];
|
||||
return callback;
|
||||
}
|
||||
});
|
||||
return ajv;
|
||||
}
|
||||
var _default = exports.default = addAbsolutePathKeyword;
|
||||
167
node_modules/schema-utils/dist/keywords/limit.js
generated
vendored
Normal file
167
node_modules/schema-utils/dist/keywords/limit.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
/** @typedef {import("ajv").default} Ajv */
|
||||
/** @typedef {import("ajv").Code} Code */
|
||||
/** @typedef {import("ajv").Name} Name */
|
||||
/** @typedef {import("ajv").KeywordErrorDefinition} KeywordErrorDefinition */
|
||||
|
||||
/**
|
||||
* @param {Ajv} ajv ajv
|
||||
* @returns {Ajv} ajv with limit keyword
|
||||
*/
|
||||
function addLimitKeyword(ajv) {
|
||||
const {
|
||||
_,
|
||||
str,
|
||||
KeywordCxt,
|
||||
nil,
|
||||
Name
|
||||
} = require("ajv");
|
||||
|
||||
/**
|
||||
* @param {Code | Name} nameOrCode name or code
|
||||
* @returns {Code | Name} name or code
|
||||
*/
|
||||
function par(nameOrCode) {
|
||||
return nameOrCode instanceof Name ? nameOrCode : _`(${nameOrCode})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Code} op op
|
||||
* @returns {(xValue: Code, yValue: Code) => Code} code
|
||||
*/
|
||||
function mappend(op) {
|
||||
return (xValue, yValue) => xValue === nil ? yValue : yValue === nil ? xValue : _`${par(xValue)} ${op} ${par(yValue)}`;
|
||||
}
|
||||
const orCode = mappend(_`||`);
|
||||
|
||||
// boolean OR (||) expression with the passed arguments
|
||||
/**
|
||||
* @param {...Code} args args
|
||||
* @returns {Code} code
|
||||
*/
|
||||
function or(...args) {
|
||||
return args.reduce(orCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | number} key key
|
||||
* @returns {Code} property
|
||||
*/
|
||||
function getProperty(key) {
|
||||
return _`[${key}]`;
|
||||
}
|
||||
const keywords = {
|
||||
formatMaximum: {
|
||||
okStr: "<=",
|
||||
ok: _`<=`,
|
||||
fail: _`>`
|
||||
},
|
||||
formatMinimum: {
|
||||
okStr: ">=",
|
||||
ok: _`>=`,
|
||||
fail: _`<`
|
||||
},
|
||||
formatExclusiveMaximum: {
|
||||
okStr: "<",
|
||||
ok: _`<`,
|
||||
fail: _`>=`
|
||||
},
|
||||
formatExclusiveMinimum: {
|
||||
okStr: ">",
|
||||
ok: _`>`,
|
||||
fail: _`<=`
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {KeywordErrorDefinition} */
|
||||
const error = {
|
||||
message: ({
|
||||
keyword,
|
||||
schemaCode
|
||||
}) => str`should be ${keywords[(/** @type {keyof typeof keywords} */keyword)].okStr} ${schemaCode}`,
|
||||
params: ({
|
||||
keyword,
|
||||
schemaCode
|
||||
}) => _`{comparison: ${keywords[(/** @type {keyof typeof keywords} */keyword)].okStr}, limit: ${schemaCode}}`
|
||||
};
|
||||
for (const keyword of Object.keys(keywords)) {
|
||||
ajv.addKeyword({
|
||||
keyword,
|
||||
type: "string",
|
||||
schemaType: keyword.startsWith("formatExclusive") ? ["string", "boolean"] : ["string", "number"],
|
||||
$data: true,
|
||||
error,
|
||||
code(cxt) {
|
||||
const {
|
||||
gen,
|
||||
data,
|
||||
schemaCode,
|
||||
keyword,
|
||||
it
|
||||
} = cxt;
|
||||
const {
|
||||
opts,
|
||||
self
|
||||
} = it;
|
||||
if (!opts.validateFormats) return;
|
||||
const fCxt = new KeywordCxt(it,
|
||||
// eslint-disable-next-line jsdoc/no-restricted-syntax
|
||||
/** @type {any} */
|
||||
self.RULES.all.format.definition, "format");
|
||||
|
||||
/**
|
||||
* @param {Name} fmt fmt
|
||||
* @returns {Code} code
|
||||
*/
|
||||
function compareCode(fmt) {
|
||||
return _`${fmt}.compare(${data}, ${schemaCode}) ${keywords[(/** @type {keyof typeof keywords} */keyword)].fail} 0`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
function validate$DataFormat() {
|
||||
const fmts = gen.scopeValue("formats", {
|
||||
ref: self.formats,
|
||||
code: opts.code.formats
|
||||
});
|
||||
const fmt = gen.const("fmt", _`${fmts}[${fCxt.schemaCode}]`);
|
||||
cxt.fail$data(or(_`typeof ${fmt} != "object"`, _`${fmt} instanceof RegExp`, _`typeof ${fmt}.compare != "function"`, compareCode(fmt)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
function validateFormat() {
|
||||
const format = fCxt.schema;
|
||||
const fmtDef = self.formats[format];
|
||||
if (!fmtDef || fmtDef === true) {
|
||||
return;
|
||||
}
|
||||
if (typeof fmtDef !== "object" || fmtDef instanceof RegExp || typeof fmtDef.compare !== "function") {
|
||||
throw new Error(`"${keyword}": format "${format}" does not define "compare" function`);
|
||||
}
|
||||
const fmt = gen.scopeValue("formats", {
|
||||
key: format,
|
||||
ref: fmtDef,
|
||||
code: opts.code.formats ? _`${opts.code.formats}${getProperty(format)}` : undefined
|
||||
});
|
||||
cxt.fail$data(compareCode(fmt));
|
||||
}
|
||||
if (fCxt.$data) {
|
||||
validate$DataFormat();
|
||||
} else {
|
||||
validateFormat();
|
||||
}
|
||||
},
|
||||
dependencies: ["format"]
|
||||
});
|
||||
}
|
||||
return ajv;
|
||||
}
|
||||
var _default = exports.default = addLimitKeyword;
|
||||
34
node_modules/schema-utils/dist/keywords/undefinedAsNull.js
generated
vendored
Normal file
34
node_modules/schema-utils/dist/keywords/undefinedAsNull.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
/** @typedef {import("ajv").default} Ajv */
|
||||
/** @typedef {import("ajv").SchemaValidateFunction} SchemaValidateFunction */
|
||||
/** @typedef {import("ajv").AnySchemaObject} AnySchemaObject */
|
||||
/** @typedef {import("ajv").ValidateFunction} ValidateFunction */
|
||||
|
||||
/**
|
||||
* @param {Ajv} ajv ajv
|
||||
* @returns {Ajv} configured ajv
|
||||
*/
|
||||
function addUndefinedAsNullKeyword(ajv) {
|
||||
ajv.addKeyword({
|
||||
keyword: "undefinedAsNull",
|
||||
before: "enum",
|
||||
modifying: true,
|
||||
/** @type {SchemaValidateFunction} */
|
||||
validate(kwVal, data, metadata, dataCxt) {
|
||||
if (kwVal && dataCxt && metadata && typeof metadata.enum !== "undefined") {
|
||||
const idx = dataCxt.parentDataProperty;
|
||||
if (typeof dataCxt.parentData[idx] === "undefined") {
|
||||
dataCxt.parentData[dataCxt.parentDataProperty] = null;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return ajv;
|
||||
}
|
||||
var _default = exports.default = addUndefinedAsNullKeyword;
|
||||
Reference in New Issue
Block a user