@arifwidianto/rpc-agent
Version:
RPC Agent for both client and server, extends more methods easily
77 lines • 2.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateParamsToSchema = exports.validateSchema = void 0;
function validateSchema(schema) {
if (typeof schema !== "object" || schema === null)
return false;
for (const [, method] of Object.entries(schema)) {
if (typeof method !== "object" ||
method === null ||
!method.hasOwnProperty("input") ||
typeof method.input !== "object" ||
method.input === null ||
!method.hasOwnProperty("output") ||
typeof method.output !== "object" ||
method.output === null ||
!method.hasOwnProperty("example") ||
typeof method.example !== "object" ||
method.example === null) {
return false;
}
for (const [, property] of Object.entries(method.input)) {
if (typeof property !== "object" ||
property === null ||
!property.hasOwnProperty("type") ||
typeof property.type !== "string" ||
!property.hasOwnProperty("description") ||
typeof property.description !== "string") {
return false;
}
}
for (const [, property] of Object.entries(method.output)) {
if (typeof property !== "object" ||
property === null ||
!property.hasOwnProperty("type") ||
typeof property.type !== "string" ||
!property.hasOwnProperty("description") ||
typeof property.description !== "string") {
return false;
}
if (property.type === "array") {
if (!property.hasOwnProperty("items") ||
typeof property.items !== "object" ||
property.items === null) {
return false;
}
}
else if (property.type === "object") {
if (!property.hasOwnProperty("properties") ||
typeof property.properties !== "object" ||
property.properties === null) {
return false;
}
}
}
for (const [, exampleValue] of Object.entries(method.example)) {
if (typeof exampleValue !== "string") {
return false;
}
}
}
return true;
}
exports.validateSchema = validateSchema;
function validateParamsToSchema(params, schema) {
for (const [methodName, method] of Object.entries(schema)) {
if (method.hasOwnProperty("input")) {
for (const [, property] of Object.entries(schema[methodName]?.input)) {
if (params.hasOwnProperty(property.type)) {
return true;
}
}
}
}
return false;
}
exports.validateParamsToSchema = validateParamsToSchema;
//# sourceMappingURL=schema.js.map