@forzalabs/remora 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Constants.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const CONSTANTS = {
4
- cliVersion: '0.0.15',
4
+ cliVersion: '0.0.17',
5
5
  lambdaVersion: 1,
6
6
  port: 5069
7
7
  };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.create_consumer = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const path_1 = __importDefault(require("path"));
19
+ const create_consumer = (name, producerName) => __awaiter(void 0, void 0, void 0, function* () {
20
+ try {
21
+ if (!fs_1.default.existsSync('./remora/consumers')) {
22
+ throw new Error(chalk_1.default.red('Missing directory: ') + chalk_1.default.yellow('./remora/consumers'));
23
+ }
24
+ // Read the default consumer template
25
+ const defaultConsumerTemplate = fs_1.default.readFileSync(path_1.default.join(__dirname, '../documentation/default_resources/consumer.json'), 'utf-8');
26
+ const defaultConsumer = JSON.parse(defaultConsumerTemplate);
27
+ defaultConsumer.name = name;
28
+ // If a producer is specified, set up a one-to-one mapping
29
+ if (producerName) {
30
+ const producerPath = path_1.default.join('remora/producers', `${producerName}.json`);
31
+ if (!fs_1.default.existsSync(producerPath)) {
32
+ throw new Error(chalk_1.default.red('Producer not found: ') + chalk_1.default.yellow(producerPath));
33
+ }
34
+ const producerConfig = JSON.parse(fs_1.default.readFileSync(producerPath, 'utf-8'));
35
+ // Set up producer reference
36
+ defaultConsumer.producers = [{ name: producerName }];
37
+ // Set up fields to include all producer fields
38
+ defaultConsumer.fields = producerConfig.dimensions.map(dim => ({
39
+ key: dim.name,
40
+ from: producerName
41
+ }));
42
+ // If there are measures, include those too
43
+ if (producerConfig.measures && producerConfig.measures.length > 0) {
44
+ defaultConsumer.fields.push(...producerConfig.measures.map(measure => ({
45
+ key: measure.name,
46
+ from: producerName
47
+ })));
48
+ }
49
+ defaultConsumer.description = `Consumer for ${producerName} data`;
50
+ defaultConsumer.schema = undefined;
51
+ defaultConsumer.filters = undefined;
52
+ defaultConsumer.metadata = undefined;
53
+ }
54
+ const consumerPath = path_1.default.join('remora/consumers', `${name}.json`);
55
+ fs_1.default.writeFileSync(consumerPath, JSON.stringify(defaultConsumer, null, 4));
56
+ console.log(chalk_1.default.green(`✅ Created consumer config at ${consumerPath}`));
57
+ if (!producerName) {
58
+ console.log(chalk_1.default.blue('Remember to:'));
59
+ console.log(chalk_1.default.blue('1. Set the correct producer name'));
60
+ console.log(chalk_1.default.blue('2. Configure the fields you want to include'));
61
+ console.log(chalk_1.default.blue('3. Set up the desired output formats'));
62
+ }
63
+ else {
64
+ console.log(chalk_1.default.blue('Consumer is configured to match all fields from producer:'), chalk_1.default.yellow(producerName));
65
+ console.log(chalk_1.default.blue('Remember to:'));
66
+ console.log(chalk_1.default.blue('1. Review the included fields'));
67
+ console.log(chalk_1.default.blue('2. Set up the desired output formats'));
68
+ }
69
+ }
70
+ catch (error) {
71
+ console.error(chalk_1.default.red('❌ Error creating consumer:'), error instanceof Error ? error.message : String(error));
72
+ process.exit(1);
73
+ }
74
+ });
75
+ exports.create_consumer = create_consumer;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.create_producer = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const path_1 = __importDefault(require("path"));
19
+ const create_producer = (name) => __awaiter(void 0, void 0, void 0, function* () {
20
+ try {
21
+ if (!fs_1.default.existsSync('./remora/producers')) {
22
+ throw new Error(chalk_1.default.red('Missing directory: ') + chalk_1.default.yellow('./remora/producers'));
23
+ }
24
+ // Read the default producer template
25
+ const defaultProducerTemplate = fs_1.default.readFileSync(path_1.default.join(__dirname, '../documentation/default_resources/producer.json'), 'utf-8');
26
+ const defaultProducer = JSON.parse(defaultProducerTemplate);
27
+ defaultProducer.name = name;
28
+ const producerPath = path_1.default.join('remora/producers', `${name}.json`);
29
+ fs_1.default.writeFileSync(producerPath, JSON.stringify(defaultProducer, null, 4));
30
+ console.log(chalk_1.default.green(`✅ Created producer config at ${producerPath}`));
31
+ console.log(chalk_1.default.blue('Remember to:'));
32
+ console.log(chalk_1.default.blue('1. Set the correct source name'));
33
+ console.log(chalk_1.default.blue('2. Configure the dimensions and measures (or use the "discover" command)'));
34
+ console.log(chalk_1.default.blue('3. Update the settings as needed'));
35
+ }
36
+ catch (error) {
37
+ console.error(chalk_1.default.red('❌ Error creating producer:'), error instanceof Error ? error.message : String(error));
38
+ process.exit(1);
39
+ }
40
+ });
41
+ exports.create_producer = create_producer;
package/actions/run.js CHANGED
@@ -19,12 +19,14 @@ const Environment_1 = __importDefault(require("../engines/Environment"));
19
19
  const UserManager_1 = __importDefault(require("../engines/UserManager"));
20
20
  const ConsumerEngine_1 = __importDefault(require("../engines/consumer/ConsumerEngine"));
21
21
  const compile_1 = require("./compile");
22
- const run = (options, consumersName) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const run = (consumerName) => __awaiter(void 0, void 0, void 0, function* () {
23
23
  try {
24
24
  (0, compile_1.compile)();
25
- const spinner = (0, ora_1.default)(chalk_1.default.blue('Run Consumers...\n')).start();
26
- const consumersToExecute = (consumersName && consumersName.length > 0) ? [Environment_1.default.getConsumer(consumersName)] : Environment_1.default._env.consumers;
25
+ const spinner = (0, ora_1.default)(chalk_1.default.blue('Running consumer(s)...\n')).start();
27
26
  const user = UserManager_1.default.getUser();
27
+ const consumersToExecute = (consumerName && consumerName.length > 0)
28
+ ? [Environment_1.default.getConsumer(consumerName)]
29
+ : Environment_1.default._env.consumers;
28
30
  const results = [];
29
31
  for (let i = 0; i < consumersToExecute.length; i++) {
30
32
  const consumer = consumersToExecute[i];
@@ -101,6 +101,8 @@ class ProducerEngineClass {
101
101
  }
102
102
  case 'JSONL':
103
103
  case 'JSON': {
104
+ if (lines.length === 1)
105
+ lines = lines[0].split('\n');
104
106
  const json = lines.map(x => JSON.parse(x));
105
107
  return { data: json, dataType: 'array-of-json' };
106
108
  }
@@ -132,7 +134,11 @@ class ProducerEngineClass {
132
134
  sampleData = ParseManager_1.default.csvLinesToJson(fileData.data, producer);
133
135
  }
134
136
  else if (((_b = producer.settings.fileType) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'JSON' || ((_c = producer.settings.fileType) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === 'JSONL') {
135
- sampleData = fileData.data.map(line => JSON.parse(line));
137
+ // With JSON or JSONL the readFile function already parses the strings
138
+ if (typeof fileData.data[0] === 'object')
139
+ sampleData = fileData.data;
140
+ else
141
+ sampleData = fileData.data.map(line => JSON.parse(line));
136
142
  }
137
143
  else {
138
144
  sampleData = fileData.data;
@@ -58,7 +58,7 @@ class PostProcessorClass {
58
58
  const { key, alias } = field.cField;
59
59
  const fieldKey = alias !== null && alias !== void 0 ? alias : key;
60
60
  const maskType = (_a = field.dimension) === null || _a === void 0 ? void 0 : _a.mask;
61
- projected[fieldKey] = CryptoEngine_1.default.hashValue(maskType, x[fieldKey]);
61
+ projected[fieldKey] = CryptoEngine_1.default.hashValue(maskType, x[key]);
62
62
  }
63
63
  return projected;
64
64
  });
@@ -99,14 +99,15 @@ class FileExporterClass {
99
99
  const folder = source.authentication.path;
100
100
  if (!fs.existsSync(folder))
101
101
  fs.mkdirSync(folder);
102
- const path = `${folder}/${consumer.name}_${Algo_1.default.replaceAll(DSTE_1.default.now().toJSON(), ':', '-')}.${extension}`;
102
+ const date = DSTE_1.default.now().toISOString().split('.')[0];
103
+ const path = `${folder}/${consumer.name}_${Algo_1.default.replaceAll(date, ':', '-')}.${extension}`;
103
104
  fs.writeFileSync(path, exportData);
104
105
  return path;
105
106
  }
106
107
  case 'aws-s3': {
107
108
  const driver = yield DriverFactory_1.default.instantiateDestination(source);
108
109
  const date = DSTE_1.default.now().toISOString().split('.')[0];
109
- const res = yield driver.uploadFile({ content: exportData, name: `${consumer.name}_${date}.${extension}` });
110
+ const res = yield driver.uploadFile({ content: exportData, name: `${consumer.name}_${Algo_1.default.replaceAll(date, ':', '-')}.${extension}` });
110
111
  return res.key;
111
112
  }
112
113
  }
package/index.js CHANGED
@@ -14,6 +14,8 @@ const run_1 = require("./actions/run");
14
14
  const Constants_1 = __importDefault(require("./Constants"));
15
15
  const discover_1 = require("./actions/discover");
16
16
  const automap_1 = require("./actions/automap");
17
+ const create_producer_1 = require("./actions/create_producer");
18
+ const create_consumer_1 = require("./actions/create_consumer");
17
19
  dotenv_1.default.configDotenv();
18
20
  const program = new commander_1.Command();
19
21
  program
@@ -46,7 +48,7 @@ program
46
48
  .option('--build-only', 'Build without deploying')
47
49
  .action(deploy_1.deploy);
48
50
  program
49
- .command('run [consumersName]')
51
+ .command('run [name]')
50
52
  .description('Execute consumers. Optionally specify a single consumers name to run.')
51
53
  .action(run_1.run);
52
54
  program
@@ -60,4 +62,13 @@ program
60
62
  .argument('<producer>', 'The producer to analyze')
61
63
  .argument('<schemas...>', 'One or more schema names to map against')
62
64
  .action(automap_1.automap);
65
+ program
66
+ .command('create-producer <name>')
67
+ .description('Create a new producer configuration with default settings')
68
+ .action(create_producer_1.create_producer);
69
+ program
70
+ .command('create-consumer <name>')
71
+ .description('Create a new consumer configuration with default settings')
72
+ .option('-p, --producer <name>', 'Producer to create a one-to-one mapping from')
73
+ .action((name, options) => (0, create_consumer_1.create_consumer)(name, options.producer));
63
74
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forzalabs/remora",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "A powerful CLI tool for seamless data translation.",
5
5
  "main": "index.js",
6
6
  "private": false,