bootstrap-parse-rest.ts 1.4 KB

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