UNPKG

beyond

Version:

The Full Stack Universal Typescript Framework

55 lines (43 loc) 1.67 kB
module.exports = class { #model; constructor(model) { this.#model = model; } async list(ids) { if (!(ids instanceof Array)) throw new Error('Invalid parameters'); if (!ids.length) return; const collection = new this.#model.Collection(this.#model.Processor, ids); await collection.ready; const output = {}; for (const processor of collection.values()) { if (processor.error) continue; const sources = await processor.overwrites(); if (!sources) continue; output[processor.id] = [...sources.values()].map(source => ({ id: source.id, version: source.version, code: source.content, file: source.file, filename: source.filename, dirname: source.dirname, basename: source.basename, extname: source.extname, relative: {file: source.relative?.file, dirname: source.relative?.dirname} }) ); } return output; } async get(ids) { if (!(ids instanceof Array)) throw new Error('Invalid parameters'); if (!ids.length) return; const collection = new this.#model.Collection(this.#model.Overwrite, ids); await collection.ready; const output = {}; for (const source of collection.values()) { if (source.error) continue; output[source.id] = source.toJSON(); } return output; } }