@bitblit/ratchet-graphql
Version:
Ratchet tools to simplify use of graphql
35 lines • 1.48 kB
JavaScript
import { Logger } from '@bitblit/ratchet-common/logger/logger';
import { StringRatchet } from '@bitblit/ratchet-common/lang/string-ratchet';
export class StringRecordQueryProvider {
autoPrefix;
autoSuffix;
caseSensitive;
files = {};
constructor(inFiles, autoPrefix = '', autoSuffix = '', caseSensitive) {
this.autoPrefix = autoPrefix;
this.autoSuffix = autoSuffix;
this.caseSensitive = caseSensitive;
if (inFiles) {
if (caseSensitive) {
this.files = Object.assign({}, inFiles);
}
else {
Object.keys(inFiles).forEach((k) => {
this.files[k.toLowerCase()] = inFiles[k];
});
}
}
}
async fetchQueryText(qry) {
let lookupKey = '';
lookupKey += this.caseSensitive ? StringRatchet.trimToEmpty(this.autoPrefix) : StringRatchet.trimToEmpty(this.autoPrefix).toLowerCase();
lookupKey += this.caseSensitive ? StringRatchet.trimToEmpty(qry) : StringRatchet.trimToEmpty(qry).toLowerCase();
lookupKey += this.caseSensitive ? StringRatchet.trimToEmpty(this.autoSuffix) : StringRatchet.trimToEmpty(this.autoSuffix).toLowerCase();
const rval = this.files[lookupKey];
if (!rval) {
Logger.warn('Could not find %s in %j', lookupKey, Object.keys(this.files));
}
return rval;
}
}
//# sourceMappingURL=string-record-query-provider.js.map