@transai/connector-runner-file 0.1.0 → 0.2.0
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/index.cjs +58 -0
- package/index.cjs.map +7 -0
- package/index.js +58 -0
- package/index.js.map +7 -0
- package/libs/connector-runner-file/src/lib/actions-handler.d.ts +7 -0
- package/libs/connector-runner-file/src/lib/connector-runner-file.d.ts +8 -0
- package/libs/connector-runner-file/src/lib/processor.d.ts +9 -0
- package/libs/connector-runner-file/src/lib/types.d.ts +40 -0
- package/libs/connector-runtime-sdk/src/index.d.ts +3 -0
- package/libs/connector-runtime-sdk/src/lib/connector-runtime.d.ts +16 -0
- package/libs/connector-runtime-sdk/src/lib/connector-runtime.interface.d.ts +5 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/files.sdk.interface.d.ts +18 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/http-client.interface.d.ts +38 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/index.d.ts +10 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/logger.sdk.interface.d.ts +7 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/offset-store.sdk.interface.d.ts +12 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/processing.sdk.interface.d.ts +13 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/receiver.sdk.interface.d.ts +14 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/sdk.interface.d.ts +31 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/sender.sdk.interface.d.ts +22 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/telemetry.sdk.interface.d.ts +15 -0
- package/libs/connector-runtime-sdk/src/lib/sdk/templating.sdk.interface.d.ts +12 -0
- package/libs/file-handler/src/index.d.ts +2 -0
- package/libs/file-handler/src/lib/file-handler.d.ts +23 -0
- package/libs/file-handler/src/lib/types.d.ts +6 -0
- package/libs/logger/src/index.d.ts +1 -0
- package/libs/logger/src/lib/logger.d.ts +28 -0
- package/libs/types/src/index.d.ts +7 -0
- package/libs/types/src/lib/cube-query-config.types.d.ts +20 -0
- package/libs/types/src/lib/file-action.types.d.ts +5 -0
- package/libs/types/src/lib/http-status-codes.enum.d.ts +64 -0
- package/libs/types/src/lib/management-api/action-definition.interface.d.ts +12 -0
- package/libs/types/src/lib/management-api/chart.interface.d.ts +9 -0
- package/libs/types/src/lib/management-api/connector/connector.interface.d.ts +140 -0
- package/libs/types/src/lib/management-api/connector/connectors.interface.d.ts +126 -0
- package/libs/types/src/lib/management-api/connector-orchestrator-config.interface.d.ts +14 -0
- package/libs/types/src/lib/management-api/cube-dataset.interface.d.ts +93 -0
- package/libs/types/src/lib/management-api/dashboard.interface.d.ts +35 -0
- package/libs/types/src/lib/management-api/dataset/collection.interface.d.ts +16 -0
- package/libs/types/src/lib/management-api/dataset/dataset-record.interface.d.ts +5 -0
- package/libs/types/src/lib/management-api/dataset/dataset.interface.d.ts +730 -0
- package/libs/types/src/lib/management-api/dataset/datasets.interface.d.ts +710 -0
- package/libs/types/src/lib/management-api/dataset/dimension.interface.d.ts +205 -0
- package/libs/types/src/lib/management-api/dataset/dimensions.interface.d.ts +186 -0
- package/libs/types/src/lib/management-api/dataset/filter-group.interface.d.ts +8 -0
- package/libs/types/src/lib/management-api/dataset/filter.interface.d.ts +34 -0
- package/libs/types/src/lib/management-api/dataset/filters.interface.d.ts +7 -0
- package/libs/types/src/lib/management-api/dataset/measure.interface.d.ts +65 -0
- package/libs/types/src/lib/management-api/dataset/measures.interface.d.ts +56 -0
- package/libs/types/src/lib/management-api/dataset/meta.interface.d.ts +9 -0
- package/libs/types/src/lib/management-api/dataset/pre-aggregate.interface.d.ts +69 -0
- package/libs/types/src/lib/management-api/dataset/pre-aggregations.interface.d.ts +54 -0
- package/libs/types/src/lib/management-api/dataset/relation.interface.d.ts +40 -0
- package/libs/types/src/lib/management-api/dataset/relations.interface.d.ts +36 -0
- package/libs/types/src/lib/management-api/dataset/segment.interface.d.ts +45 -0
- package/libs/types/src/lib/management-api/dataset/segments.interface.d.ts +43 -0
- package/libs/types/src/lib/management-api/dataset/switch.interface.d.ts +70 -0
- package/libs/types/src/lib/management-api/dataset/when-item.interface.d.ts +41 -0
- package/libs/types/src/lib/management-api/dataset/when-items.interface.d.ts +40 -0
- package/libs/types/src/lib/management-api/event-origin.interface.d.ts +24 -0
- package/libs/types/src/lib/management-api/index.d.ts +39 -0
- package/libs/types/src/lib/management-api/semantic-trigger/custom-cron-trigger-record.interface.d.ts +6 -0
- package/libs/types/src/lib/management-api/semantic-trigger/index.d.ts +6 -0
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger-filter.interface.d.ts +20 -0
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger-filters.interface.d.ts +18 -0
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger-record.interface.d.ts +6 -0
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-trigger.interface.d.ts +75 -0
- package/libs/types/src/lib/management-api/semantic-trigger/semantic-triggers.interface.d.ts +62 -0
- package/libs/types/src/lib/management-api/template-implementation-overrides.interface.d.ts +1152 -0
- package/libs/types/src/lib/management-api/template-implementation.interface.d.ts +2860 -0
- package/libs/types/src/lib/management-api/template.interface.d.ts +1191 -0
- package/libs/types/src/lib/management-api/tenant.interface.d.ts +8 -0
- package/libs/types/src/lib/management-api/type-enums.d.ts +85 -0
- package/libs/types/src/lib/management-api/web/generic-filter.dto.d.ts +37 -0
- package/libs/types/src/lib/management-api/web/index.d.ts +2 -0
- package/libs/types/src/lib/management-api/web/paginated-response.interface.d.ts +17 -0
- package/libs/types/src/lib/management-api/workflow/action.interface.d.ts +85 -0
- package/libs/types/src/lib/management-api/workflow/index.d.ts +6 -0
- package/libs/types/src/lib/management-api/workflow/offset.interface.d.ts +14 -0
- package/libs/types/src/lib/management-api/workflow/trigger-types.interface.d.ts +14 -0
- package/libs/types/src/lib/management-api/workflow/workflow-definition.interface.d.ts +57 -0
- package/libs/types/src/lib/management-api/workflow/workflow-run.d.ts +70 -0
- package/libs/types/src/lib/management-api/workflow/workflow.drawing.d.ts +102 -0
- package/libs/types/src/lib/message.types.d.ts +59 -0
- package/libs/types/src/lib/response.types.d.ts +27 -0
- package/libs/types/src/lib/types.d.ts +116 -0
- package/package.json +1 -1
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -10
- package/project.json +0 -33
- package/src/lib/actions-handler.spec.ts +0 -121
- package/src/lib/actions-handler.ts +0 -82
- package/src/lib/connector-runner-file.spec.ts +0 -73
- package/src/lib/connector-runner-file.ts +0 -50
- package/src/lib/processor.spec.ts +0 -119
- package/src/lib/processor.ts +0 -186
- package/src/lib/types.ts +0 -51
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -14
- /package/{src/index.ts → libs/connector-runner-file/src/index.d.ts} +0 -0
package/src/lib/processor.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ConnectorSDKInterface,
|
|
5
|
-
FileHandleInterface,
|
|
6
|
-
FileInfo,
|
|
7
|
-
FilesSDKInterface,
|
|
8
|
-
IntervalHandler,
|
|
9
|
-
} from '@transai/connector-runtime-sdk';
|
|
10
|
-
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
11
|
-
import { FileHandler, ParsedFile } from '@xip-online-data/file-handler';
|
|
12
|
-
|
|
13
|
-
import { FileConfig, FileSelectorConfig } from './types';
|
|
14
|
-
|
|
15
|
-
export class Processor implements IntervalHandler {
|
|
16
|
-
static readonly DEFAULT_INTERVAL_SECONDS = 60;
|
|
17
|
-
|
|
18
|
-
readonly #connectorSDK: ConnectorSDKInterface<FileConfig>;
|
|
19
|
-
|
|
20
|
-
readonly #fileSelector: FileSelectorConfig;
|
|
21
|
-
|
|
22
|
-
readonly #fileHandler: FilesSDKInterface;
|
|
23
|
-
|
|
24
|
-
readonly #destinationFileHandler?: FilesSDKInterface;
|
|
25
|
-
|
|
26
|
-
readonly #fileReader: FileHandler;
|
|
27
|
-
|
|
28
|
-
readonly #fileSelectionRegex: RegExp;
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
connectorSDK: ConnectorSDKInterface<FileConfig>,
|
|
32
|
-
fileSelector: FileSelectorConfig,
|
|
33
|
-
fileHandler: FilesSDKInterface,
|
|
34
|
-
) {
|
|
35
|
-
this.#connectorSDK = connectorSDK;
|
|
36
|
-
this.#fileSelector = fileSelector;
|
|
37
|
-
this.#fileHandler = fileHandler;
|
|
38
|
-
this.#fileReader = new FileHandler(fileSelector.delimiter);
|
|
39
|
-
|
|
40
|
-
const { selector } = this.#fileSelector;
|
|
41
|
-
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
42
|
-
this.#fileSelectionRegex = new RegExp(
|
|
43
|
-
typeof selector !== 'string' ? selector.pattern : selector,
|
|
44
|
-
typeof selector !== 'string' && selector.flags ? selector.flags : 'i',
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
if (this.#fileSelector.destinationDsn) {
|
|
48
|
-
this.#destinationFileHandler = this.#connectorSDK.files(
|
|
49
|
-
this.#fileSelector.destinationDsn,
|
|
50
|
-
);
|
|
51
|
-
} else if (this.#fileSelector.action === 'move') {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Destination DSN must be provided for 'move' action in file selector: ${this.name}`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get name(): string {
|
|
59
|
-
const { selector } = this.#fileSelector;
|
|
60
|
-
return `file-processor-${typeof selector === 'string' ? selector : selector.pattern}`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async onRun(): Promise<void> {
|
|
64
|
-
const processedFiles = await this.#listDirectory();
|
|
65
|
-
this.#connectorSDK.telemetry.increment(
|
|
66
|
-
'files.processed.count',
|
|
67
|
-
processedFiles,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async #listDirectory(dirPath = '/'): Promise<number> {
|
|
72
|
-
const contents = await this.#fileHandler.list(dirPath);
|
|
73
|
-
const numberOfProcessedFilesList = await Promise.all(
|
|
74
|
-
contents.map(async (fileInfo): Promise<number> => {
|
|
75
|
-
if (fileInfo.type === 'FILE') {
|
|
76
|
-
const processed = await this.#processFile(fileInfo, dirPath);
|
|
77
|
-
return processed ? 1 : 0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (this.#fileSelector.recursive === true) {
|
|
81
|
-
return this.#listDirectory(path.join(dirPath, fileInfo.name));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return Promise.resolve(0);
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
return numberOfProcessedFilesList.reduce((acc, curr) => acc + curr, 0);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async #processFile(fileInfo: FileInfo, dirPath: string): Promise<boolean> {
|
|
92
|
-
const filePath = path.join(dirPath, fileInfo.name);
|
|
93
|
-
if (!this.#fileSelectionRegex.test(fileInfo.name)) {
|
|
94
|
-
this.#connectorSDK.logger.verbose(
|
|
95
|
-
`Skipping file at path: ${filePath} as it does not match selector regex`,
|
|
96
|
-
);
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this.#connectorSDK.logger.debug(`Processing file at path: ${filePath}`);
|
|
101
|
-
let fileContent: FileHandleInterface | undefined;
|
|
102
|
-
let parsedContent: ParsedFile | undefined;
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
fileContent = await this.#fileHandler.read(filePath);
|
|
106
|
-
|
|
107
|
-
// Parse file to JSON using FileHandler based on file type
|
|
108
|
-
parsedContent = await this.#fileReader.handleBuffer(
|
|
109
|
-
filePath,
|
|
110
|
-
fileContent.get(),
|
|
111
|
-
this.#fileSelector.optionalHeaders ?? [],
|
|
112
|
-
this.#fileSelector.optionalSettings,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
if (!parsedContent) {
|
|
116
|
-
this.#connectorSDK.logger.info(
|
|
117
|
-
`Failed to parse file at path: ${filePath}`,
|
|
118
|
-
);
|
|
119
|
-
fileContent.close();
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.#connectorSDK.logger.debug(
|
|
124
|
-
`Parsed file successfully at path: ${filePath}`,
|
|
125
|
-
);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
this.#connectorSDK.logger.error(
|
|
128
|
-
`Error parsing file at path: ${filePath}, error: ${error}`,
|
|
129
|
-
);
|
|
130
|
-
fileContent?.close();
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
const data = [
|
|
136
|
-
{
|
|
137
|
-
...parsedContent,
|
|
138
|
-
_filename: FileHandler.getFileName(filePath) ?? fileInfo.name,
|
|
139
|
-
} as object,
|
|
140
|
-
];
|
|
141
|
-
const metadata = {
|
|
142
|
-
keyField: '_filename',
|
|
143
|
-
collection: `${this.#connectorSDK.config.datasourceIdentifier ?? 'file'}_${this.#fileSelector.identifier ?? this.#fileSelectionRegex.source}`,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
if (this.#fileSelector.type === 'metric') {
|
|
147
|
-
await this.#connectorSDK.sender.metricsLegacy(
|
|
148
|
-
data as Array<never>,
|
|
149
|
-
metadata,
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
await this.#connectorSDK.sender.documents(data, metadata);
|
|
153
|
-
}
|
|
154
|
-
} catch (error) {
|
|
155
|
-
this.#connectorSDK.logger.error(
|
|
156
|
-
`Error sending parsed file from path: ${filePath}, error: ${error}`,
|
|
157
|
-
);
|
|
158
|
-
fileContent?.close();
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
// eslint-disable-next-line default-case
|
|
164
|
-
switch (this.#fileSelector.action) {
|
|
165
|
-
case 'move':
|
|
166
|
-
await this.#destinationFileHandler?.write(fileInfo.name, fileContent);
|
|
167
|
-
await this.#fileHandler.delete(filePath);
|
|
168
|
-
this.#connectorSDK.logger.debug(
|
|
169
|
-
`"Moved" file at path: ${filePath} to ${this.#destinationFileHandler?.pathAsDsn(fileInfo.name)} after processing`,
|
|
170
|
-
);
|
|
171
|
-
break;
|
|
172
|
-
|
|
173
|
-
case 'delete':
|
|
174
|
-
await this.#fileHandler.delete(filePath);
|
|
175
|
-
this.#connectorSDK.logger.debug(
|
|
176
|
-
`Deleted file at path: ${filePath} after processing`,
|
|
177
|
-
);
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
} finally {
|
|
181
|
-
fileContent?.close();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
}
|
package/src/lib/types.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { BaseConnectorConfig } from '@xip-online-data/types';
|
|
2
|
-
|
|
3
|
-
export interface FileSelectorConfig {
|
|
4
|
-
/**
|
|
5
|
-
* A regex pattern or string to select matching files. If the identifier is not
|
|
6
|
-
* provided, the selector string itself will be used as the identifier.
|
|
7
|
-
*/
|
|
8
|
-
selector:
|
|
9
|
-
| {
|
|
10
|
-
pattern: string;
|
|
11
|
-
flags?: string;
|
|
12
|
-
}
|
|
13
|
-
| string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The action to take on the file after processing. 'move' to move the file to
|
|
17
|
-
* a different DSN (requires destinationDsn), 'delete' to delete the file, or
|
|
18
|
-
* 'nothing' to leave the file as is (default).
|
|
19
|
-
*/
|
|
20
|
-
action?: 'move' | 'delete' | 'nothing';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* If the action is 'move', the destination DSN where the file should be moved.
|
|
24
|
-
*/
|
|
25
|
-
destinationDsn?: string;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* An optional identifier for the file selector, used for the collection.
|
|
29
|
-
*/
|
|
30
|
-
identifier?: string;
|
|
31
|
-
|
|
32
|
-
intervalSeconds?: number;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Look for files recursively in subdirectories.
|
|
36
|
-
*/
|
|
37
|
-
recursive?: boolean;
|
|
38
|
-
|
|
39
|
-
delimiter?: string;
|
|
40
|
-
optionalHeaders?: Array<string>;
|
|
41
|
-
optionalSettings?: {
|
|
42
|
-
[key: string]: unknown;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
type?: 'metric' | 'document';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface FileConfig extends BaseConnectorConfig {
|
|
49
|
-
dsn: string;
|
|
50
|
-
fileSelectors?: Array<FileSelectorConfig>;
|
|
51
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"forceConsistentCasingInFileNames": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"noImplicitOverride": true,
|
|
8
|
-
"noImplicitReturns": true,
|
|
9
|
-
"noFallthroughCasesInSwitch": true,
|
|
10
|
-
"noPropertyAccessFromIndexSignature": true
|
|
11
|
-
},
|
|
12
|
-
"files": [],
|
|
13
|
-
"include": [],
|
|
14
|
-
"references": [
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.lib.json"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "./tsconfig.spec.json"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
package/tsconfig.lib.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"types": ["jest", "node"]
|
|
7
|
-
},
|
|
8
|
-
"include": [
|
|
9
|
-
"jest.config.ts",
|
|
10
|
-
"src/**/*.test.ts",
|
|
11
|
-
"src/**/*.spec.ts",
|
|
12
|
-
"src/**/*.d.ts"
|
|
13
|
-
]
|
|
14
|
-
}
|
|
File without changes
|