@salesforce/plugin-custom-metadata 2.1.12 → 2.1.13
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/lib/commands/cmdt/generate/records.js +16 -13
- package/lib/commands/cmdt/generate/records.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +4 -5
- package/csvtojson/CSVError.d.ts +0 -18
- package/csvtojson/CSVError.js +0 -46
- package/csvtojson/CSVError.js.map +0 -1
- package/csvtojson/Converter.d.ts +0 -43
- package/csvtojson/Converter.js +0 -197
- package/csvtojson/Converter.js.map +0 -1
- package/csvtojson/Parameters.d.ts +0 -97
- package/csvtojson/Parameters.js +0 -47
- package/csvtojson/Parameters.js.map +0 -1
- package/csvtojson/ParseRuntime.d.ts +0 -63
- package/csvtojson/ParseRuntime.js +0 -36
- package/csvtojson/ParseRuntime.js.map +0 -1
- package/csvtojson/ProcessFork.d.ts +0 -37
- package/csvtojson/ProcessFork.js +0 -158
- package/csvtojson/ProcessFork.js.map +0 -1
- package/csvtojson/Processor.d.ts +0 -21
- package/csvtojson/Processor.js +0 -16
- package/csvtojson/Processor.js.map +0 -1
- package/csvtojson/ProcessorLocal.d.ts +0 -26
- package/csvtojson/ProcessorLocal.js +0 -314
- package/csvtojson/ProcessorLocal.js.map +0 -1
- package/csvtojson/README.md +0 -1
- package/csvtojson/Result.d.ts +0 -22
- package/csvtojson/Result.js +0 -168
- package/csvtojson/Result.js.map +0 -1
- package/csvtojson/dataClean.d.ts +0 -13
- package/csvtojson/dataClean.js +0 -76
- package/csvtojson/dataClean.js.map +0 -1
- package/csvtojson/fileline.d.ts +0 -20
- package/csvtojson/fileline.js +0 -26
- package/csvtojson/fileline.js.map +0 -1
- package/csvtojson/getEol.d.ts +0 -6
- package/csvtojson/getEol.js +0 -31
- package/csvtojson/getEol.js.map +0 -1
- package/csvtojson/index.d.ts +0 -10
- package/csvtojson/index.js +0 -13
- package/csvtojson/index.js.map +0 -1
- package/csvtojson/lineToJson.d.ts +0 -9
- package/csvtojson/lineToJson.js +0 -216
- package/csvtojson/lineToJson.js.map +0 -1
- package/csvtojson/rowSplit.d.ts +0 -38
- package/csvtojson/rowSplit.js +0 -234
- package/csvtojson/rowSplit.js.map +0 -1
- package/csvtojson/util.d.ts +0 -10
- package/csvtojson/util.js +0 -43
- package/csvtojson/util.js.map +0 -1
- package/csvtojson/worker.d.ts +0 -3
- package/csvtojson/worker.js +0 -76
- package/csvtojson/worker.js.map +0 -1
|
@@ -10,7 +10,7 @@ const fs = require("fs");
|
|
|
10
10
|
const path = require("path");
|
|
11
11
|
const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
|
|
12
12
|
const core_1 = require("@salesforce/core");
|
|
13
|
-
const
|
|
13
|
+
const sync_1 = require("csv-parse/sync");
|
|
14
14
|
const createUtil_1 = require("../../../shared/helpers/createUtil");
|
|
15
15
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
16
16
|
const messages = core_1.Messages.loadMessages('@salesforce/plugin-custom-metadata', 'records');
|
|
@@ -23,19 +23,11 @@ class Insert extends sf_plugins_core_1.SfCommand {
|
|
|
23
23
|
// if customMetadata folder does not exist, create it
|
|
24
24
|
await fs.promises.mkdir(flags['output-directory'], { recursive: true });
|
|
25
25
|
const fileData = await (0, createUtil_1.getFileData)(fieldDirPath, fileNames);
|
|
26
|
-
const csvDataAry = (await csv().fromFile(flags.csv));
|
|
27
26
|
const metadataTypeFields = (0, createUtil_1.getFieldNames)(fileData, flags['name-column']);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw new core_1.SfError(messages.getMessage('fieldNotFoundError', [key, flags['type-name']]));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// find the cmdt in the inputdir.
|
|
37
|
-
// loop through files and create records that match fields
|
|
38
|
-
const recordConfigs = csvDataAry.map((record) => ({
|
|
27
|
+
const parsedRecords = (0, sync_1.parse)(await fs.promises.readFile(flags.csv), {
|
|
28
|
+
columns: (header) => columnValidation(metadataTypeFields, header, flags['type-name']),
|
|
29
|
+
});
|
|
30
|
+
const recordConfigs = parsedRecords.map((record) => ({
|
|
39
31
|
typename: flags['type-name'],
|
|
40
32
|
recordname: record[flags['name-column']].replace(' ', '_'),
|
|
41
33
|
label: record[flags['name-column']],
|
|
@@ -55,6 +47,8 @@ class Insert extends sf_plugins_core_1.SfCommand {
|
|
|
55
47
|
})),
|
|
56
48
|
fileData,
|
|
57
49
|
}));
|
|
50
|
+
// find the cmdt in the inputdir.
|
|
51
|
+
// loop through files and create records that match fields
|
|
58
52
|
await Promise.all(recordConfigs.map((r) => (0, createUtil_1.createRecord)(r)));
|
|
59
53
|
this.log(messages.getMessage('successResponse', [flags.csv, flags['output-directory']]));
|
|
60
54
|
return recordConfigs;
|
|
@@ -102,4 +96,13 @@ Insert.flags = {
|
|
|
102
96
|
aliases: ['namecolumn'],
|
|
103
97
|
}),
|
|
104
98
|
};
|
|
99
|
+
/** Validate that every column in the CSV has known metadata */
|
|
100
|
+
const columnValidation = (requiredFields, columnList, typeNameFlag) => {
|
|
101
|
+
columnList.forEach((column) => {
|
|
102
|
+
if (!requiredFields.includes(column)) {
|
|
103
|
+
throw new core_1.SfError(messages.getMessage('fieldNotFoundError', [column, typeNameFlag]));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return columnList;
|
|
107
|
+
};
|
|
105
108
|
//# sourceMappingURL=records.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../../../src/commands/cmdt/generate/records.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6B;AAC7B,iEAAyE;AACzE,2CAAqD;AAErD,
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../../../src/commands/cmdt/generate/records.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,yBAAyB;AACzB,6BAA6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;QACvC,MAAM,EAAE,IAAI;KACb,CAAC;IACF,kBAAkB,EAAE,uBAAK,CAAC,SAAS,CAAC;QAClC,IAAI,EAAE,GAAG;QACT,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,gCAAgC,CAAC;QAC9D,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,CAAC;QACpE,OAAO,EAAE,CAAC,WAAW,EAAE,iBAAiB,CAAC;KAC1C,CAAC;IACF,aAAa,EAAE,uBAAK,CAAC,MAAM,CAAC;QAC1B,IAAI,EAAE,GAAG;QACT,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,2BAA2B,CAAC;QACzD,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,CAAC,YAAY,CAAC;KACxB,CAAC;CACH,CAAC;AAiDJ,+DAA+D;AAC/D,MAAM,gBAAgB,GAAG,CAAC,cAAwB,EAAE,UAAoB,EAAE,YAAoB,EAAY,EAAE;IAC1G,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,MAAM,IAAI,cAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;SACtF;IACH,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/plugin-custom-metadata",
|
|
3
3
|
"description": "Tools for working with custom metadata types and their records.",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.13",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Carolyn Grabill",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@salesforce/core": "^3.34.6",
|
|
47
47
|
"@salesforce/sf-plugins-core": "^2.2.5",
|
|
48
48
|
"@salesforce/ts-types": "^1.7.3",
|
|
49
|
+
"csv-parse": "^5.3.6",
|
|
49
50
|
"fast-xml-parser": "^4.1.3",
|
|
50
51
|
"tslib": "^2"
|
|
51
52
|
},
|
|
@@ -60,7 +61,6 @@
|
|
|
60
61
|
"@swc/core": "^1.3.37",
|
|
61
62
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
62
63
|
"@typescript-eslint/parser": "^5.57.1",
|
|
63
|
-
"bluebird": "3.7.2",
|
|
64
64
|
"chai": "^4.3.7",
|
|
65
65
|
"eslint": "^8.36.0",
|
|
66
66
|
"eslint-config-prettier": "^8.8.0",
|
|
@@ -88,7 +88,6 @@
|
|
|
88
88
|
"node": ">=14.0.0"
|
|
89
89
|
},
|
|
90
90
|
"files": [
|
|
91
|
-
"/csvtojson",
|
|
92
91
|
"/lib",
|
|
93
92
|
"/messages",
|
|
94
93
|
"/oclif.manifest.json",
|
|
@@ -246,7 +245,7 @@
|
|
|
246
245
|
}
|
|
247
246
|
},
|
|
248
247
|
"sfdx": {
|
|
249
|
-
"publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-custom-metadata/2.1.
|
|
250
|
-
"signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-custom-metadata/2.1.
|
|
248
|
+
"publicKeyUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-custom-metadata/2.1.13.crt",
|
|
249
|
+
"signatureUrl": "https://developer.salesforce.com/media/salesforce-cli/security/@salesforce/plugin-custom-metadata/2.1.13.sig"
|
|
251
250
|
}
|
|
252
251
|
}
|
package/csvtojson/CSVError.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
export default class CSVError extends Error {
|
|
6
|
-
err: string;
|
|
7
|
-
line: number;
|
|
8
|
-
extra: string | undefined;
|
|
9
|
-
static column_mismatched(index: number, extra?: string): CSVError;
|
|
10
|
-
static unclosed_quote(index: number, extra?: string): CSVError;
|
|
11
|
-
static fromJSON(obj: any): CSVError;
|
|
12
|
-
constructor(err: string, line: number, extra?: string | undefined);
|
|
13
|
-
toJSON(): {
|
|
14
|
-
err: string;
|
|
15
|
-
line: number;
|
|
16
|
-
extra: string | undefined;
|
|
17
|
-
};
|
|
18
|
-
}
|
package/csvtojson/CSVError.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
var __extends = (this && this.__extends) || (function () {
|
|
7
|
-
var extendStatics = Object.setPrototypeOf ||
|
|
8
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
9
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
10
|
-
return function (d, b) {
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var CSVError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(CSVError, _super);
|
|
19
|
-
function CSVError(err, line, extra) {
|
|
20
|
-
var _this = _super.call(this, "Error: " + err + ". JSON Line number: " + line + (extra ? " near: " + extra : "")) || this;
|
|
21
|
-
_this.err = err;
|
|
22
|
-
_this.line = line;
|
|
23
|
-
_this.extra = extra;
|
|
24
|
-
_this.name = "CSV Parse Error";
|
|
25
|
-
return _this;
|
|
26
|
-
}
|
|
27
|
-
CSVError.column_mismatched = function (index, extra) {
|
|
28
|
-
return new CSVError("column_mismatched", index, extra);
|
|
29
|
-
};
|
|
30
|
-
CSVError.unclosed_quote = function (index, extra) {
|
|
31
|
-
return new CSVError("unclosed_quote", index, extra);
|
|
32
|
-
};
|
|
33
|
-
CSVError.fromJSON = function (obj) {
|
|
34
|
-
return new CSVError(obj.err, obj.line, obj.extra);
|
|
35
|
-
};
|
|
36
|
-
CSVError.prototype.toJSON = function () {
|
|
37
|
-
return {
|
|
38
|
-
err: this.err,
|
|
39
|
-
line: this.line,
|
|
40
|
-
extra: this.extra
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
return CSVError;
|
|
44
|
-
}(Error));
|
|
45
|
-
exports.default = CSVError;
|
|
46
|
-
//# sourceMappingURL=CSVError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CSVError.js","sourceRoot":"","sources":["../src/CSVError.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;IAAsC,4BAAK;IAUzC,kBACS,GAAW,EACX,IAAY,EACZ,KAAc;QAHvB,YAKE,kBAAM,SAAS,GAAG,GAAG,GAAG,sBAAsB,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAE1F;QANQ,SAAG,GAAH,GAAG,CAAQ;QACX,UAAI,GAAJ,IAAI,CAAQ;QACZ,WAAK,GAAL,KAAK,CAAS;QAGrB,KAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;;IAChC,CAAC;IAhBM,0BAAiB,GAAxB,UAAyB,KAAa,EAAE,KAAc;QACpD,OAAO,IAAI,QAAQ,CAAC,mBAAmB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IACM,uBAAc,GAArB,UAAsB,KAAa,EAAE,KAAc;QACjD,OAAO,IAAI,QAAQ,CAAC,gBAAgB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IACM,iBAAQ,GAAf,UAAgB,GAAG;QACjB,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IASD,yBAAM,GAAN;QACE,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAA;IACH,CAAC;IAEH,eAAC;AAAD,CAAC,AA1BD,CAAsC,KAAK,GA0B1C"}
|
package/csvtojson/Converter.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
import { Transform, TransformOptions, Readable } from "stream";
|
|
7
|
-
import { CSVParseParam } from "./Parameters";
|
|
8
|
-
import { ParseRuntime } from "./ParseRuntime";
|
|
9
|
-
import CSVError from "./CSVError";
|
|
10
|
-
export declare class Converter extends Transform implements PromiseLike<any[]> {
|
|
11
|
-
options: TransformOptions;
|
|
12
|
-
preRawData(onRawData: PreRawDataCallback): Converter;
|
|
13
|
-
preFileLine(onFileLine: PreFileLineCallback): Converter;
|
|
14
|
-
subscribe(onNext?: (data: any, lineNumber: number) => void | PromiseLike<void>, onError?: (err: CSVError) => void, onCompleted?: () => void): Converter;
|
|
15
|
-
fromFile(filePath: string, options?: string | CreateReadStreamOption | undefined): Converter;
|
|
16
|
-
fromStream(readStream: Readable): Converter;
|
|
17
|
-
fromString(csvString: string): Converter;
|
|
18
|
-
then<TResult1 = any[], TResult2 = never>(onfulfilled?: (value: any[]) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
|
|
19
|
-
readonly parseParam: CSVParseParam;
|
|
20
|
-
readonly parseRuntime: ParseRuntime;
|
|
21
|
-
private params;
|
|
22
|
-
private runtime;
|
|
23
|
-
private processor;
|
|
24
|
-
private result;
|
|
25
|
-
constructor(param?: Partial<CSVParseParam>, options?: TransformOptions);
|
|
26
|
-
_transform(chunk: any, encoding: string, cb: Function): void;
|
|
27
|
-
_flush(cb: Function): void;
|
|
28
|
-
private processEnd(cb);
|
|
29
|
-
readonly parsedLineNumber: number;
|
|
30
|
-
}
|
|
31
|
-
export interface CreateReadStreamOption {
|
|
32
|
-
flags?: string;
|
|
33
|
-
encoding?: string;
|
|
34
|
-
fd?: number;
|
|
35
|
-
mode?: number;
|
|
36
|
-
autoClose?: boolean;
|
|
37
|
-
start?: number;
|
|
38
|
-
end?: number;
|
|
39
|
-
highWaterMark?: number;
|
|
40
|
-
}
|
|
41
|
-
export declare type CallBack = (err: Error, data: Array<any>) => void;
|
|
42
|
-
export declare type PreFileLineCallback = (line: string, lineNumber: number) => string | PromiseLike<string>;
|
|
43
|
-
export declare type PreRawDataCallback = (csvString: string) => string | PromiseLike<string>;
|
package/csvtojson/Converter.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
var __extends = (this && this.__extends) || (function () {
|
|
7
|
-
var extendStatics = Object.setPrototypeOf ||
|
|
8
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
9
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
10
|
-
return function (d, b) {
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
var stream_1 = require("stream");
|
|
21
|
-
var Parameters_1 = require("./Parameters");
|
|
22
|
-
var ParseRuntime_1 = require("./ParseRuntime");
|
|
23
|
-
var bluebird_1 = __importDefault(require("bluebird"));
|
|
24
|
-
// import { ProcessorFork } from "./ProcessFork";
|
|
25
|
-
var ProcessorLocal_1 = require("./ProcessorLocal");
|
|
26
|
-
var Result_1 = require("./Result");
|
|
27
|
-
var Converter = /** @class */ (function (_super) {
|
|
28
|
-
__extends(Converter, _super);
|
|
29
|
-
function Converter(param, options) {
|
|
30
|
-
if (options === void 0) { options = {}; }
|
|
31
|
-
var _this = _super.call(this, options) || this;
|
|
32
|
-
_this.options = options;
|
|
33
|
-
_this.params = Parameters_1.mergeParams(param);
|
|
34
|
-
_this.runtime = ParseRuntime_1.initParseRuntime(_this);
|
|
35
|
-
_this.result = new Result_1.Result(_this);
|
|
36
|
-
// if (this.params.fork) {
|
|
37
|
-
// this.processor = new ProcessorFork(this);
|
|
38
|
-
// } else {
|
|
39
|
-
_this.processor = new ProcessorLocal_1.ProcessorLocal(_this);
|
|
40
|
-
// }
|
|
41
|
-
_this.once("error", function (err) {
|
|
42
|
-
// console.log("BBB");
|
|
43
|
-
//wait for next cycle to emit the errors.
|
|
44
|
-
setImmediate(function () {
|
|
45
|
-
_this.result.processError(err);
|
|
46
|
-
_this.emit("done", err);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
_this.once("done", function () {
|
|
50
|
-
_this.processor.destroy();
|
|
51
|
-
});
|
|
52
|
-
return _this;
|
|
53
|
-
}
|
|
54
|
-
Converter.prototype.preRawData = function (onRawData) {
|
|
55
|
-
this.runtime.preRawDataHook = onRawData;
|
|
56
|
-
return this;
|
|
57
|
-
};
|
|
58
|
-
Converter.prototype.preFileLine = function (onFileLine) {
|
|
59
|
-
this.runtime.preFileLineHook = onFileLine;
|
|
60
|
-
return this;
|
|
61
|
-
};
|
|
62
|
-
Converter.prototype.subscribe = function (onNext, onError, onCompleted) {
|
|
63
|
-
this.parseRuntime.subscribe = {
|
|
64
|
-
onNext: onNext,
|
|
65
|
-
onError: onError,
|
|
66
|
-
onCompleted: onCompleted
|
|
67
|
-
};
|
|
68
|
-
return this;
|
|
69
|
-
};
|
|
70
|
-
Converter.prototype.fromFile = function (filePath, options) {
|
|
71
|
-
var _this = this;
|
|
72
|
-
var fs = require("fs");
|
|
73
|
-
// var rs = null;
|
|
74
|
-
// this.wrapCallback(cb, function () {
|
|
75
|
-
// if (rs && rs.destroy) {
|
|
76
|
-
// rs.destroy();
|
|
77
|
-
// }
|
|
78
|
-
// });
|
|
79
|
-
fs.exists(filePath, function (exist) {
|
|
80
|
-
if (exist) {
|
|
81
|
-
var rs = fs.createReadStream(filePath, options);
|
|
82
|
-
rs.pipe(_this);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
_this.emit('error', new Error("File does not exist. Check to make sure the file path to your csv is correct."));
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return this;
|
|
89
|
-
};
|
|
90
|
-
Converter.prototype.fromStream = function (readStream) {
|
|
91
|
-
readStream.pipe(this);
|
|
92
|
-
return this;
|
|
93
|
-
};
|
|
94
|
-
Converter.prototype.fromString = function (csvString) {
|
|
95
|
-
var csv = csvString.toString();
|
|
96
|
-
var read = new stream_1.Readable();
|
|
97
|
-
var idx = 0;
|
|
98
|
-
read._read = function (size) {
|
|
99
|
-
if (idx >= csvString.length) {
|
|
100
|
-
this.push(null);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
var str = csvString.substr(idx, size);
|
|
104
|
-
this.push(str);
|
|
105
|
-
idx += size;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
return this.fromStream(read);
|
|
109
|
-
};
|
|
110
|
-
Converter.prototype.then = function (onfulfilled, onrejected) {
|
|
111
|
-
var _this = this;
|
|
112
|
-
return new bluebird_1.default(function (resolve, reject) {
|
|
113
|
-
_this.parseRuntime.then = {
|
|
114
|
-
onfulfilled: function (value) {
|
|
115
|
-
if (onfulfilled) {
|
|
116
|
-
resolve(onfulfilled(value));
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
resolve(value);
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
onrejected: function (err) {
|
|
123
|
-
if (onrejected) {
|
|
124
|
-
resolve(onrejected(err));
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
reject(err);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
Object.defineProperty(Converter.prototype, "parseParam", {
|
|
134
|
-
get: function () {
|
|
135
|
-
return this.params;
|
|
136
|
-
},
|
|
137
|
-
enumerable: true,
|
|
138
|
-
configurable: true
|
|
139
|
-
});
|
|
140
|
-
Object.defineProperty(Converter.prototype, "parseRuntime", {
|
|
141
|
-
get: function () {
|
|
142
|
-
return this.runtime;
|
|
143
|
-
},
|
|
144
|
-
enumerable: true,
|
|
145
|
-
configurable: true
|
|
146
|
-
});
|
|
147
|
-
Converter.prototype._transform = function (chunk, encoding, cb) {
|
|
148
|
-
var _this = this;
|
|
149
|
-
this.processor.process(chunk)
|
|
150
|
-
.then(function (result) {
|
|
151
|
-
// console.log(result);
|
|
152
|
-
if (result.length > 0) {
|
|
153
|
-
_this.runtime.started = true;
|
|
154
|
-
return _this.result.processResult(result);
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
.then(function () {
|
|
158
|
-
_this.emit("drained");
|
|
159
|
-
cb();
|
|
160
|
-
}, function (error) {
|
|
161
|
-
_this.runtime.hasError = true;
|
|
162
|
-
_this.runtime.error = error;
|
|
163
|
-
_this.emit("error", error);
|
|
164
|
-
cb();
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
Converter.prototype._flush = function (cb) {
|
|
168
|
-
var _this = this;
|
|
169
|
-
this.processor.flush()
|
|
170
|
-
.then(function (data) {
|
|
171
|
-
if (data.length > 0) {
|
|
172
|
-
return _this.result.processResult(data);
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
.then(function () {
|
|
176
|
-
_this.processEnd(cb);
|
|
177
|
-
}, function (err) {
|
|
178
|
-
_this.emit("error", err);
|
|
179
|
-
cb();
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
Converter.prototype.processEnd = function (cb) {
|
|
183
|
-
this.result.endProcess();
|
|
184
|
-
this.emit("done");
|
|
185
|
-
cb();
|
|
186
|
-
};
|
|
187
|
-
Object.defineProperty(Converter.prototype, "parsedLineNumber", {
|
|
188
|
-
get: function () {
|
|
189
|
-
return this.runtime.parsedLineNumber;
|
|
190
|
-
},
|
|
191
|
-
enumerable: true,
|
|
192
|
-
configurable: true
|
|
193
|
-
});
|
|
194
|
-
return Converter;
|
|
195
|
-
}(stream_1.Transform));
|
|
196
|
-
exports.Converter = Converter;
|
|
197
|
-
//# sourceMappingURL=Converter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Converter.js","sourceRoot":"","sources":["../src/Converter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iCAA+D;AAC/D,2CAA0D;AAC1D,+CAAgE;AAChE,sDAAyB;AAOzB,iDAAiD;AACjD,mDAAkD;AAClD,mCAAkC;AAMlC;IAA+B,6BAAS;IAuFtC,mBAAY,KAA8B,EAAS,OAA8B;QAA9B,wBAAA,EAAA,YAA8B;QAAjF,YACE,kBAAM,OAAO,CAAC,SAuBf;QAxBkD,aAAO,GAAP,OAAO,CAAuB;QAE/E,KAAI,CAAC,MAAM,GAAG,wBAAW,CAAC,KAAK,CAAC,CAAC;QACjC,KAAI,CAAC,OAAO,GAAG,+BAAgB,CAAC,KAAI,CAAC,CAAC;QACtC,KAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,KAAI,CAAC,CAAC;QAC/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BAAM,GAAN,UAAO,EAAY;QAAnB,iBAcC;QAbC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;aACnB,IAAI,CAAC,UAAC,IAAI;YACT,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBAEnB,OAAO,KAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;aACxC;QACH,CAAC,CAAC;aACD,IAAI,CAAC;YACJ,KAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACtB,CAAC,EAAE,UAAC,GAAG;YACL,KAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACxB,EAAE,EAAE,CAAC;QACP,CAAC,CAAC,CAAA;IACN,CAAC;IACO,8BAAU,GAAlB,UAAmB,EAAE;QACnB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,EAAE,EAAE,CAAC;IACP,CAAC;IACD,sBAAI,uCAAgB;aAApB;YACE,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACvC,CAAC;;;OAAA;IACH,gBAAC;AAAD,CAAC,AA3JD,CAA+B,kBAAS,GA2JvC;AA3JY,8BAAS"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
export interface CSVParseParam {
|
|
6
|
-
/**
|
|
7
|
-
* delimiter used for seperating columns. Use "auto" if delimiter is unknown in advance, in this case, delimiter will be auto-detected (by best attempt). Use an array to give a list of potential delimiters e.g. [",","|","$"]. default: ","
|
|
8
|
-
*/
|
|
9
|
-
delimiter: string | string[];
|
|
10
|
-
/**
|
|
11
|
-
* This parameter instructs the parser to ignore columns as specified by the regular expression. Example: /(name|age)/ will ignore columns whose header contains "name" or "age"
|
|
12
|
-
*/
|
|
13
|
-
ignoreColumns?: RegExp;
|
|
14
|
-
/**
|
|
15
|
-
* This parameter instructs the parser to include only those columns as specified by the regular expression. Example: /(name|age)/ will parse and include columns whose header contains "name" or "age"
|
|
16
|
-
*/
|
|
17
|
-
includeColumns?: RegExp;
|
|
18
|
-
/**
|
|
19
|
-
* If a column contains delimiter, it is able to use quote character to surround the column content. e.g. "hello, world" wont be split into two columns while parsing. Set to "off" will ignore all quotes. default: " (double quote)
|
|
20
|
-
*/
|
|
21
|
-
quote: string;
|
|
22
|
-
/**
|
|
23
|
-
* Indicate if parser trim off spaces surrounding column content. e.g. " content " will be trimmed to "content". Default: true
|
|
24
|
-
*/
|
|
25
|
-
trim: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* This parameter turns on and off whether check field type. Default is false.
|
|
28
|
-
*/
|
|
29
|
-
checkType: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Ignore the empty value in CSV columns. If a column value is not given, set this to true to skip them. Default: false.
|
|
32
|
-
*/
|
|
33
|
-
ignoreEmpty: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Delegate parsing work to another process.
|
|
36
|
-
*/
|
|
37
|
-
/**
|
|
38
|
-
* Indicating csv data has no header row and first row is data row. Default is false.
|
|
39
|
-
*/
|
|
40
|
-
noheader: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* An array to specify the headers of CSV data. If --noheader is false, this value will override CSV header row. Default: null. Example: ["my field","name"].
|
|
43
|
-
*/
|
|
44
|
-
headers?: string[];
|
|
45
|
-
/**
|
|
46
|
-
* Don't interpret dots (.) and square brackets in header fields as nested object or array identifiers at all (treat them like regular characters for JSON field identifiers). Default: false.
|
|
47
|
-
*/
|
|
48
|
-
flatKeys: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* the max character a csv row could have. 0 means infinite. If max number exceeded, parser will emit "error" of "row_exceed". if a possibly corrupted csv data provided, give it a number like 65535 so the parser wont consume memory. default: 0
|
|
51
|
-
*/
|
|
52
|
-
maxRowLength: number;
|
|
53
|
-
/**
|
|
54
|
-
* whether check column number of a row is the same as headers. If column number mismatched headers number, an error of "mismatched_column" will be emitted.. default: false
|
|
55
|
-
*/
|
|
56
|
-
checkColumn: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* escape character used in quoted column. Default is double quote (") according to RFC4108. Change to back slash (\) or other chars for your own case.
|
|
59
|
-
*/
|
|
60
|
-
escape: string;
|
|
61
|
-
/**
|
|
62
|
-
* Allows override parsing logic for a specific column. It accepts a JSON object with fields like: headName: <String | Function> . e.g. {field1:'number'} will use built-in number parser to convert value of the field1 column to number. Another example {"name":nameProcessFunc} will use specified function to parse the value.
|
|
63
|
-
*/
|
|
64
|
-
colParser: {
|
|
65
|
-
[key: string]: string | CellParser | ColumnParam;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* End of line character. If omitted, parser will attempt to retrieve it from the first chunks of CSV data
|
|
69
|
-
*/
|
|
70
|
-
eol?: string;
|
|
71
|
-
/**
|
|
72
|
-
* Always interpret each line (as defined by eol) as a row. This will prevent eol characters from being used within a row (even inside a quoted field). Default is false. Change to true if you are confident no inline line breaks (like line break in a cell which has multi line text)
|
|
73
|
-
*/
|
|
74
|
-
alwaysSplitAtEOL: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* The format to be converted to. "json" (default) -- convert csv to json. "csv" -- convert csv to csv row array. "line" -- convert csv to csv line string
|
|
77
|
-
*/
|
|
78
|
-
output: "json" | "csv" | "line";
|
|
79
|
-
/**
|
|
80
|
-
* Convert string "null" to null object in JSON outputs. Default is false.
|
|
81
|
-
*/
|
|
82
|
-
nullObject: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Define the format required by downstream (this parameter does not work if objectMode is on). `line` -- json is emitted in a single line separated by a line breake like "json1\njson2" . `array` -- downstream requires array format like "[json1,json2]". Default is line.
|
|
85
|
-
*/
|
|
86
|
-
downstreamFormat: "line" | "array";
|
|
87
|
-
/**
|
|
88
|
-
* Define whether .then(callback) returns all JSON data in its callback. Default is true. Change to false to save memory if subscribing json lines.
|
|
89
|
-
*/
|
|
90
|
-
needEmitAll: boolean;
|
|
91
|
-
}
|
|
92
|
-
export declare type CellParser = (item: string, head: string, resultRow: any, row: string[], columnIndex: number) => any;
|
|
93
|
-
export interface ColumnParam {
|
|
94
|
-
flat?: boolean;
|
|
95
|
-
cellParser?: string | CellParser;
|
|
96
|
-
}
|
|
97
|
-
export declare function mergeParams(params?: Partial<CSVParseParam>): CSVParseParam;
|
package/csvtojson/Parameters.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
function mergeParams(params) {
|
|
8
|
-
var defaultParam = {
|
|
9
|
-
delimiter: ',',
|
|
10
|
-
ignoreColumns: undefined,
|
|
11
|
-
includeColumns: undefined,
|
|
12
|
-
quote: '"',
|
|
13
|
-
trim: true,
|
|
14
|
-
checkType: false,
|
|
15
|
-
ignoreEmpty: false,
|
|
16
|
-
// fork: false,
|
|
17
|
-
noheader: false,
|
|
18
|
-
headers: undefined,
|
|
19
|
-
flatKeys: false,
|
|
20
|
-
maxRowLength: 0,
|
|
21
|
-
checkColumn: false,
|
|
22
|
-
escape: '"',
|
|
23
|
-
colParser: {},
|
|
24
|
-
eol: undefined,
|
|
25
|
-
alwaysSplitAtEOL: false,
|
|
26
|
-
output: "json",
|
|
27
|
-
nullObject: false,
|
|
28
|
-
downstreamFormat: "line",
|
|
29
|
-
needEmitAll: true
|
|
30
|
-
};
|
|
31
|
-
if (!params) {
|
|
32
|
-
params = {};
|
|
33
|
-
}
|
|
34
|
-
for (var key in params) {
|
|
35
|
-
if (params.hasOwnProperty(key)) {
|
|
36
|
-
if (Array.isArray(params[key])) {
|
|
37
|
-
defaultParam[key] = [].concat(params[key]);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
defaultParam[key] = params[key];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return defaultParam;
|
|
45
|
-
}
|
|
46
|
-
exports.mergeParams = mergeParams;
|
|
47
|
-
//# sourceMappingURL=Parameters.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Parameters.js","sourceRoot":"","sources":["../src/Parameters.ts"],"names":[],"mappings":";;AAiGA,qBAA4B,MAA+B;IACzD,IAAM,YAAY,GAAkB;QAClC,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,SAAS;QACxB,cAAc,EAAE,SAAS;QACzB,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,KAAK;QAClB,eAAe;QACf,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,SAAS;QAClB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,KAAK;QAClB,MAAM,EAAE,GAAG;QACX,SAAS,EAAE,EAAE;QACb,GAAG,EAAE,SAAS;QACd,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,KAAK;QACjB,gBAAgB,EAAC,MAAM;QACvB,WAAW,EAAC,IAAI;KACjB,CAAA;IACD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,EAAE,CAAC;KACb;IACD,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;QACtB,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC9B,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5C;iBAAM;gBACL,YAAY,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;aACjC;SACF;KACF;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AArCD,kCAqCC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT license brought in by https://github.com/Keyang/node-csvtojson
|
|
3
|
-
* */
|
|
4
|
-
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
import { CellParser } from "./Parameters";
|
|
7
|
-
import { Converter, PreRawDataCallback, PreFileLineCallback } from "./Converter";
|
|
8
|
-
import CSVError from "./CSVError";
|
|
9
|
-
export interface ParseRuntime {
|
|
10
|
-
/**
|
|
11
|
-
* If need convert ignoreColumn from column name(string) to column index (number). Parser needs column index.
|
|
12
|
-
*/
|
|
13
|
-
needProcessIgnoreColumn: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* If need convert includeColumn from column name(string) to column index (number). Parser needs column index.
|
|
16
|
-
*/
|
|
17
|
-
needProcessIncludeColumn: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* the indexes of columns to reserve, undefined means reserve all, [] means hide all
|
|
20
|
-
*/
|
|
21
|
-
selectedColumns?: number[];
|
|
22
|
-
ended: boolean;
|
|
23
|
-
hasError: boolean;
|
|
24
|
-
error?: Error;
|
|
25
|
-
/**
|
|
26
|
-
* Inferred delimiter
|
|
27
|
-
*/
|
|
28
|
-
delimiter: string | string[];
|
|
29
|
-
/**
|
|
30
|
-
* Inferred eol
|
|
31
|
-
*/
|
|
32
|
-
eol?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Converter function for a column. Populated at runtime.
|
|
35
|
-
*/
|
|
36
|
-
columnConv: (CellParser | null)[];
|
|
37
|
-
headerType: any[];
|
|
38
|
-
headerTitle: string[];
|
|
39
|
-
headerFlag: any[];
|
|
40
|
-
/**
|
|
41
|
-
* Inferred headers
|
|
42
|
-
*/
|
|
43
|
-
headers?: any[];
|
|
44
|
-
csvLineBuffer?: Buffer;
|
|
45
|
-
/**
|
|
46
|
-
* after first chunk of data being processed and emitted, started will become true.
|
|
47
|
-
*/
|
|
48
|
-
started: boolean;
|
|
49
|
-
preRawDataHook?: PreRawDataCallback;
|
|
50
|
-
preFileLineHook?: PreFileLineCallback;
|
|
51
|
-
parsedLineNumber: number;
|
|
52
|
-
columnValueSetter: Function[];
|
|
53
|
-
subscribe?: {
|
|
54
|
-
onNext?: (data: any, lineNumber: number) => void | PromiseLike<void>;
|
|
55
|
-
onError?: (err: CSVError) => void;
|
|
56
|
-
onCompleted?: () => void;
|
|
57
|
-
};
|
|
58
|
-
then?: {
|
|
59
|
-
onfulfilled: (value: any[]) => any;
|
|
60
|
-
onrejected: (err: Error) => any;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export declare function initParseRuntime(converter: Converter): ParseRuntime;
|