import-workbook-parse-rest.ts 1.4 KB

123456789101112131415161718192021222324252627
  1. import 'dotenv/config';
  2. import { resolve } from 'node:path';
  3. import { loadConfig } from '../src/config/env.js';
  4. import { ParseRestClient } from '../src/db/parse-rest.client.js';
  5. import { ensureVocParseSchemas } from '../src/db/parse-rest.schema.js';
  6. import { normalizeDemashiWorkbook } from '../src/modules/domestic-voc/importers/demashi-workbook.js';
  7. import { ParseRestDatasetImportService } from '../src/modules/domestic-voc/services/parse-rest-dataset-import.service.js';
  8. const inputPath = process.argv[2];
  9. if (!inputPath) throw new Error('Usage: npm run import:workbook:parse-rest -- <workbook.xlsx> [workspaceId]');
  10. const config = loadConfig();
  11. if (config.storageDriver !== 'parse_rest') throw new Error('STORAGE_DRIVER must be parse_rest');
  12. const workspaceId = process.argv[3] || config.auth.defaultWorkspaceId;
  13. const client = new ParseRestClient({
  14. serverUrl: config.parse.serverUrl,
  15. appId: config.parse.appId,
  16. masterKey: config.parse.masterKey,
  17. timeoutMs: config.parse.timeoutMs,
  18. });
  19. const dataset = await normalizeDemashiWorkbook(resolve(inputPath));
  20. await ensureVocParseSchemas(client);
  21. const imported = await new ParseRestDatasetImportService(client).import(dataset, workspaceId, {
  22. userId: config.auth.localUserId,
  23. email: config.auth.localUserEmail,
  24. displayName: config.auth.localUserName,
  25. });
  26. console.log(JSON.stringify({ source: dataset.source, summary: dataset.summary, imported }, null, 2));