UNPKG

open-epsilon

Version:

empty-epsilon / open-sound-control bidirectional proxy

56 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processApiSchema = void 0; const naming = require("naming"); const ee_schema_1 = require("./ee-schema"); function initContextNode(ctxName, generatedGameSchema, processedGameSchema) { const existingContext = processedGameSchema[ctxName]; if (existingContext) { return existingContext; } else { const ctx = generatedGameSchema[ctxName]; let superCtx = {}; if (typeof ctx.$inherits === 'string') { superCtx = initContextNode(ctx.$inherits, generatedGameSchema, processedGameSchema); } return processedGameSchema[ctxName] = Object.create(superCtx); } } function processApiSchema(generatedGameSchema) { const processedGameSchema = {}; for (let ctxName of Object.keys(generatedGameSchema)) { initContextNode(ctxName, generatedGameSchema, processedGameSchema); } for (let ctxName of Object.keys(generatedGameSchema)) { const ctx = generatedGameSchema[ctxName]; const methodContext = processedGameSchema[ctxName]; for (let methodName of Object.keys(ctx).filter(k => !k.startsWith('$'))) { const generatedMethodMeta = ctx[methodName]; if (ee_schema_1.isGameMethod(generatedMethodMeta)) { const parsedMethodName = naming.disperse(methodName); const propertyName = parsedMethodName.slice(1).join('-'); const methodVerb = parsedMethodName[0].toLowerCase(); if (methodVerb === 'get') { methodContext[propertyName] = methodContext[propertyName] || {}; const type = (ee_schema_1.isPrimitiveOrArrayOfPrimitiveType(generatedMethodMeta.type)) ? generatedMethodMeta.type : processedGameSchema[generatedMethodMeta.type[0]]; methodContext[propertyName].get = { methodName: methodName, arguments: generatedMethodMeta.arguments, type: type, }; } else if (methodVerb === 'set') { methodContext[propertyName] = methodContext[propertyName] || {}; methodContext[propertyName].set = { methodName: methodName, arguments: generatedMethodMeta.arguments, }; } } } } return processedGameSchema; } exports.processApiSchema = processApiSchema; //# sourceMappingURL=process-schema.js.map