sails-js-parser
Version:
Sails-IDL parser for TypeScript
64 lines (61 loc) • 1.72 kB
JavaScript
import { WithDef, EnumVariant } from './types.js';
import { getName, getBool, getDocs } from './util.js';
import { Base } from './visitor.js';
class Service extends Base {
funcs;
events;
name;
constructor(ptr, memory) {
super(ptr, memory);
const [name, nameOffset] = getName(ptr, this.offset, memory);
this.name = name || 'Service';
this.offset += nameOffset;
this.funcs = [];
this.events = [];
}
addFunc(func) {
this.funcs.push(func);
}
addEvent(event) {
this.events.push(event);
}
}
class ServiceEvent extends EnumVariant {
}
class ServiceFunc extends WithDef {
name;
isQuery;
docs;
_params;
constructor(ptr, memory) {
super(ptr, memory);
const [name, nameOffset] = getName(ptr, this.offset, memory);
this.name = name;
this.offset += nameOffset;
const [isQuery, isQueryOffset] = getBool(ptr, this.offset, memory);
this.isQuery = isQuery;
this.offset += isQueryOffset;
const [docs, docsOffset] = getDocs(ptr, this.offset, memory);
this.docs = docs;
this.offset += docsOffset;
this._params = new Map();
}
addFuncParam(ptr, param) {
this._params.set(ptr, param);
}
get params() {
if (this._params.size === 0)
return [];
return [...this._params.values()];
}
}
class FuncParam extends WithDef {
name;
constructor(ptr, memory) {
super(ptr, memory);
const [name, nameOffset] = getName(ptr, this.offset, memory);
this.name = name;
this.offset += nameOffset;
}
}
export { FuncParam, Service, ServiceEvent, ServiceFunc };