longcelot-sheet-db
Version:
Google Sheets-backed staging database adapter for Node.js with schema-first design
41 lines • 1.77 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadSchemasWithPaths = loadSchemasWithPaths;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const actorConfig_1 = require("../../utils/actorConfig");
/**
* Like the ad-hoc `loadSchemas`/`loadSchemasForActor` helpers duplicated across sync.ts,
* export.ts, export-data.ts, status.ts, and validate.ts — but also keeps each schema's
* originating file path, needed by drop-table/drop-column/rename-column to edit or delete
* the file the schema came from.
*/
function loadSchemasWithPaths(config) {
const results = [];
const schemasRoot = config.schemasDir
? path_1.default.resolve(process.cwd(), config.schemasDir)
: path_1.default.join(process.cwd(), 'schemas');
for (const actorEntry of config.actors) {
const actor = (0, actorConfig_1.resolveActorName)(actorEntry);
const actorDir = path_1.default.join(schemasRoot, actor);
if (!fs_1.default.existsSync(actorDir))
continue;
const files = fs_1.default.readdirSync(actorDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
for (const file of files) {
const filePath = path_1.default.join(actorDir, file);
try {
const schema = require(filePath).default;
if (schema?.columns)
results.push({ schema, filePath, actor });
}
catch {
// skip unloadable files
}
}
}
return results;
}
//# sourceMappingURL=schemaLoader.js.map