bulkyard 1.0.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/LICENSE +28 -0
- package/README.md +136 -0
- package/lib/commands/bulkyard/extract.d.ts +18 -0
- package/lib/commands/bulkyard/extract.js +84 -0
- package/lib/commands/bulkyard/extract.js.map +1 -0
- package/lib/commands/bulkyard/load.d.ts +19 -0
- package/lib/commands/bulkyard/load.js +98 -0
- package/lib/commands/bulkyard/load.js.map +1 -0
- package/lib/core/config.d.ts +23 -0
- package/lib/core/config.js +52 -0
- package/lib/core/config.js.map +1 -0
- package/lib/core/database.d.ts +15 -0
- package/lib/core/database.js +67 -0
- package/lib/core/database.js.map +1 -0
- package/lib/core/extractor.d.ts +11 -0
- package/lib/core/extractor.js +33 -0
- package/lib/core/extractor.js.map +1 -0
- package/lib/core/loader.d.ts +13 -0
- package/lib/core/loader.js +59 -0
- package/lib/core/loader.js.map +1 -0
- package/lib/core/type-map.d.ts +1 -0
- package/lib/core/type-map.js +32 -0
- package/lib/core/type-map.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/messages/bulkyard.extract.md +55 -0
- package/messages/bulkyard.load.md +59 -0
- package/oclif.lock +7821 -0
- package/oclif.manifest.json +252 -0
- package/package.json +191 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Jesse Wheeler
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# bulkyard
|
|
2
|
+
|
|
3
|
+
A Salesforce CLI plugin for bulk data extraction and loading via local SQLite3 databases.
|
|
4
|
+
|
|
5
|
+
Uses the Bulk API 2.0 to move data between a Salesforce org and a local SQLite database. A YAML config file drives which objects to process, enabling repeatable multi-object operations.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
sf plugins install bulkyard@x.y.z
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Config File
|
|
14
|
+
|
|
15
|
+
Create a `bulkyard.config.yml` file to define your database path and the objects to extract or load:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
database: ./bulkyard.db
|
|
19
|
+
|
|
20
|
+
objects:
|
|
21
|
+
- object: Account
|
|
22
|
+
query: 'SELECT Id, Name, Industry FROM Account WHERE Industry != null'
|
|
23
|
+
operation: upsert
|
|
24
|
+
externalIdField: Id
|
|
25
|
+
|
|
26
|
+
- object: Contact
|
|
27
|
+
query: 'SELECT Id, FirstName, LastName, Email FROM Contact'
|
|
28
|
+
operation: insert
|
|
29
|
+
table: Contact_Staging
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
| Field | Used By | Description |
|
|
33
|
+
| ----------------- | ------- | ---------------------------------------------------------- |
|
|
34
|
+
| `object` | both | Salesforce object API name |
|
|
35
|
+
| `query` | extract | SOQL query to execute |
|
|
36
|
+
| `operation` | load | Bulk API operation: `insert`, `update`, `upsert`, `delete` |
|
|
37
|
+
| `externalIdField` | load | Required when operation is `upsert` |
|
|
38
|
+
| `table` | both | Optional SQLite table name override (defaults to `object`) |
|
|
39
|
+
|
|
40
|
+
## Commands
|
|
41
|
+
|
|
42
|
+
### `sf bulkyard extract`
|
|
43
|
+
|
|
44
|
+
Extract data from a Salesforce org into a local SQLite database using Bulk API 2.0.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
USAGE
|
|
48
|
+
$ sf bulkyard extract -o <value> (-c <value> | -s <value>) [--json] [--api-version <value>]
|
|
49
|
+
[-q <value>] [-d <value>] [-t <value>]
|
|
50
|
+
|
|
51
|
+
FLAGS
|
|
52
|
+
-c, --config-file=<value> Path to the YAML config file.
|
|
53
|
+
-s, --sobject=<value> Salesforce object API name (e.g. Account, Contact).
|
|
54
|
+
-q, --query=<value> SOQL query to execute for extraction.
|
|
55
|
+
-d, --database=<value> [default: bulkyard.db] Path to the SQLite database file.
|
|
56
|
+
-t, --table=<value> SQLite table name override (defaults to the object name).
|
|
57
|
+
-o, --target-org=<value> (required) Username or alias of the target org.
|
|
58
|
+
--api-version=<value> Override the API version used for requests.
|
|
59
|
+
|
|
60
|
+
EXAMPLES
|
|
61
|
+
Multi-object mode (config file):
|
|
62
|
+
$ sf bulkyard extract --target-org myOrg --config-file bulkyard.config.yml
|
|
63
|
+
|
|
64
|
+
Single-object mode (inline flags):
|
|
65
|
+
$ sf bulkyard extract --target-org myOrg --sobject Account --query "SELECT Id, Name FROM Account"
|
|
66
|
+
|
|
67
|
+
Inline with custom database and table:
|
|
68
|
+
$ sf bulkyard extract -o myOrg -s Account -q "SELECT Id, Name FROM Account" -d my.db -t Account_Backup
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
For each object in the config, this command:
|
|
72
|
+
|
|
73
|
+
1. Runs the SOQL query via Bulk API 2.0
|
|
74
|
+
2. Describes the object to map Salesforce field types to SQLite column types
|
|
75
|
+
3. Creates (or replaces) a SQLite table with typed columns
|
|
76
|
+
4. Inserts all records in transactional batches of 1,000 rows
|
|
77
|
+
|
|
78
|
+
### `sf bulkyard load`
|
|
79
|
+
|
|
80
|
+
Load data from a local SQLite database into a Salesforce org using Bulk API 2.0.
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
USAGE
|
|
84
|
+
$ sf bulkyard load -o <value> (-c <value> | -s <value>) [--json] [--api-version <value>]
|
|
85
|
+
[-p <value>] [-e <value>] [-d <value>] [-t <value>]
|
|
86
|
+
|
|
87
|
+
FLAGS
|
|
88
|
+
-c, --config-file=<value> Path to the YAML config file.
|
|
89
|
+
-s, --sobject=<value> Salesforce object API name (e.g. Account, Contact).
|
|
90
|
+
-p, --operation=<value> Bulk API operation: insert, update, upsert, or delete.
|
|
91
|
+
-e, --external-id-field=<value> External ID field for upsert operations.
|
|
92
|
+
-d, --database=<value> [default: bulkyard.db] Path to the SQLite database file.
|
|
93
|
+
-t, --table=<value> SQLite table name override (defaults to the object name).
|
|
94
|
+
-o, --target-org=<value> (required) Username or alias of the target org.
|
|
95
|
+
--api-version=<value> Override the API version used for requests.
|
|
96
|
+
|
|
97
|
+
EXAMPLES
|
|
98
|
+
Multi-object mode (config file):
|
|
99
|
+
$ sf bulkyard load --target-org myOrg --config-file bulkyard.config.yml
|
|
100
|
+
|
|
101
|
+
Single-object mode (inline flags):
|
|
102
|
+
$ sf bulkyard load --target-org myOrg --sobject Account --operation upsert --external-id-field Id
|
|
103
|
+
|
|
104
|
+
Inline with custom database and table:
|
|
105
|
+
$ sf bulkyard load -o myOrg -s Account -p insert -d my.db -t Account_Staging
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
For each object in the config, this command:
|
|
109
|
+
|
|
110
|
+
1. Reads all rows from the corresponding SQLite table
|
|
111
|
+
2. Submits them to the Salesforce Bulk API 2.0 using the configured operation
|
|
112
|
+
3. Reports success/failure counts per object
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
BSD-3-Clause. See [LICENSE](LICENSE).
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Install dependencies
|
|
122
|
+
yarn
|
|
123
|
+
|
|
124
|
+
# Build
|
|
125
|
+
yarn build
|
|
126
|
+
|
|
127
|
+
# Run locally
|
|
128
|
+
./bin/dev.js bulkyard extract --help
|
|
129
|
+
./bin/dev.js bulkyard load --help
|
|
130
|
+
|
|
131
|
+
# Run tests
|
|
132
|
+
yarn test:only
|
|
133
|
+
|
|
134
|
+
# Lint
|
|
135
|
+
yarn lint
|
|
136
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { ExtractResult } from '../../core/extractor.js';
|
|
3
|
+
export type ExtractCommandResult = ExtractResult[];
|
|
4
|
+
export default class Extract extends SfCommand<ExtractCommandResult> {
|
|
5
|
+
static readonly summary: string;
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly examples: string[];
|
|
8
|
+
static readonly flags: {
|
|
9
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'config-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
sobject: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
query: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
database: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
table: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<ExtractCommandResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Messages } from '@salesforce/core';
|
|
3
|
+
import { loadConfig, buildConfigFromFlags, validateForExtract } from '../../core/config.js';
|
|
4
|
+
import { BulkyardDatabase } from '../../core/database.js';
|
|
5
|
+
import { extractObject } from '../../core/extractor.js';
|
|
6
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
7
|
+
const messages = Messages.loadMessages('bulkyard', 'bulkyard.extract');
|
|
8
|
+
export default class Extract extends SfCommand {
|
|
9
|
+
static summary = messages.getMessage('summary');
|
|
10
|
+
static description = messages.getMessage('description');
|
|
11
|
+
static examples = messages.getMessages('examples');
|
|
12
|
+
static flags = {
|
|
13
|
+
'target-org': Flags.requiredOrg(),
|
|
14
|
+
'api-version': Flags.orgApiVersion(),
|
|
15
|
+
'config-file': Flags.file({
|
|
16
|
+
char: 'c',
|
|
17
|
+
summary: messages.getMessage('flags.config-file.summary'),
|
|
18
|
+
exists: true,
|
|
19
|
+
exactlyOne: ['config-file', 'sobject'],
|
|
20
|
+
}),
|
|
21
|
+
sobject: Flags.string({
|
|
22
|
+
char: 's',
|
|
23
|
+
summary: messages.getMessage('flags.sobject.summary'),
|
|
24
|
+
exactlyOne: ['config-file', 'sobject'],
|
|
25
|
+
}),
|
|
26
|
+
query: Flags.string({
|
|
27
|
+
char: 'q',
|
|
28
|
+
summary: messages.getMessage('flags.query.summary'),
|
|
29
|
+
dependsOn: ['sobject'],
|
|
30
|
+
}),
|
|
31
|
+
database: Flags.string({
|
|
32
|
+
char: 'd',
|
|
33
|
+
summary: messages.getMessage('flags.database.summary'),
|
|
34
|
+
default: 'bulkyard.db',
|
|
35
|
+
exclusive: ['config-file'],
|
|
36
|
+
}),
|
|
37
|
+
table: Flags.string({
|
|
38
|
+
char: 't',
|
|
39
|
+
summary: messages.getMessage('flags.table.summary'),
|
|
40
|
+
dependsOn: ['sobject'],
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
async run() {
|
|
44
|
+
const { flags } = await this.parse(Extract);
|
|
45
|
+
const config = flags['config-file']
|
|
46
|
+
? loadConfig(flags['config-file'])
|
|
47
|
+
: buildConfigFromFlags({
|
|
48
|
+
sobject: flags.sobject,
|
|
49
|
+
database: flags.database,
|
|
50
|
+
query: flags.query,
|
|
51
|
+
table: flags.table,
|
|
52
|
+
});
|
|
53
|
+
validateForExtract(config);
|
|
54
|
+
const conn = flags['target-org'].getConnection(flags['api-version']);
|
|
55
|
+
const db = new BulkyardDatabase(config.database);
|
|
56
|
+
const results = [];
|
|
57
|
+
try {
|
|
58
|
+
for (const objConfig of config.objects) {
|
|
59
|
+
this.spinner.start(messages.getMessage('info.extracting', [objConfig.object]));
|
|
60
|
+
// eslint-disable-next-line no-await-in-loop
|
|
61
|
+
const result = await extractObject(conn, db, objConfig);
|
|
62
|
+
this.spinner.stop();
|
|
63
|
+
if (result.success) {
|
|
64
|
+
this.log(` ${result.object} -> ${result.table}: ${result.recordCount} records`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.warn(messages.getMessage('error.objectFailed', [result.object, result.error ?? 'unknown']));
|
|
68
|
+
}
|
|
69
|
+
results.push(result);
|
|
70
|
+
}
|
|
71
|
+
this.log(messages.getMessage('info.complete'));
|
|
72
|
+
this.styledHeader('Extract Results');
|
|
73
|
+
this.table({
|
|
74
|
+
data: results,
|
|
75
|
+
columns: ['object', 'table', { key: 'recordCount', name: 'Records' }, 'success'],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
db.close();
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../src/commands/bulkyard/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAiB,MAAM,yBAAyB,CAAC;AAEvE,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AAIvE,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,SAA+B;IAC3D,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAA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CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;gBACnG,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;YAC/C,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;YACrC,IAAI,CAAC,KAAK,CAAC;gBACT,IAAI,EAAE,OAAoD;gBAC1D,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC;aACjF,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { LoadResult } from '../../core/loader.js';
|
|
3
|
+
export type LoadCommandResult = LoadResult[];
|
|
4
|
+
export default class Load extends SfCommand<LoadCommandResult> {
|
|
5
|
+
static readonly summary: string;
|
|
6
|
+
static readonly description: string;
|
|
7
|
+
static readonly examples: string[];
|
|
8
|
+
static readonly flags: {
|
|
9
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'config-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
sobject: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
operation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
'external-id-field': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
database: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
table: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<LoadCommandResult>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Messages } from '@salesforce/core';
|
|
3
|
+
import { loadConfig, buildConfigFromFlags, validateForLoad } from '../../core/config.js';
|
|
4
|
+
import { BulkyardDatabase } from '../../core/database.js';
|
|
5
|
+
import { loadObject } from '../../core/loader.js';
|
|
6
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
7
|
+
const messages = Messages.loadMessages('bulkyard', 'bulkyard.load');
|
|
8
|
+
export default class Load extends SfCommand {
|
|
9
|
+
static summary = messages.getMessage('summary');
|
|
10
|
+
static description = messages.getMessage('description');
|
|
11
|
+
static examples = messages.getMessages('examples');
|
|
12
|
+
static flags = {
|
|
13
|
+
'target-org': Flags.requiredOrg(),
|
|
14
|
+
'api-version': Flags.orgApiVersion(),
|
|
15
|
+
'config-file': Flags.file({
|
|
16
|
+
char: 'c',
|
|
17
|
+
summary: messages.getMessage('flags.config-file.summary'),
|
|
18
|
+
exists: true,
|
|
19
|
+
exactlyOne: ['config-file', 'sobject'],
|
|
20
|
+
}),
|
|
21
|
+
sobject: Flags.string({
|
|
22
|
+
char: 's',
|
|
23
|
+
summary: messages.getMessage('flags.sobject.summary'),
|
|
24
|
+
exactlyOne: ['config-file', 'sobject'],
|
|
25
|
+
}),
|
|
26
|
+
operation: Flags.string({
|
|
27
|
+
char: 'p',
|
|
28
|
+
summary: messages.getMessage('flags.operation.summary'),
|
|
29
|
+
options: ['insert', 'update', 'upsert', 'delete'],
|
|
30
|
+
dependsOn: ['sobject'],
|
|
31
|
+
}),
|
|
32
|
+
'external-id-field': Flags.string({
|
|
33
|
+
char: 'e',
|
|
34
|
+
summary: messages.getMessage('flags.external-id-field.summary'),
|
|
35
|
+
dependsOn: ['sobject'],
|
|
36
|
+
}),
|
|
37
|
+
database: Flags.string({
|
|
38
|
+
char: 'd',
|
|
39
|
+
summary: messages.getMessage('flags.database.summary'),
|
|
40
|
+
default: 'bulkyard.db',
|
|
41
|
+
exclusive: ['config-file'],
|
|
42
|
+
}),
|
|
43
|
+
table: Flags.string({
|
|
44
|
+
char: 't',
|
|
45
|
+
summary: messages.getMessage('flags.table.summary'),
|
|
46
|
+
dependsOn: ['sobject'],
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
async run() {
|
|
50
|
+
const { flags } = await this.parse(Load);
|
|
51
|
+
const config = flags['config-file']
|
|
52
|
+
? loadConfig(flags['config-file'])
|
|
53
|
+
: buildConfigFromFlags({
|
|
54
|
+
sobject: flags.sobject,
|
|
55
|
+
database: flags.database,
|
|
56
|
+
operation: flags.operation,
|
|
57
|
+
externalIdField: flags['external-id-field'],
|
|
58
|
+
table: flags.table,
|
|
59
|
+
});
|
|
60
|
+
validateForLoad(config);
|
|
61
|
+
const conn = flags['target-org'].getConnection(flags['api-version']);
|
|
62
|
+
const db = new BulkyardDatabase(config.database);
|
|
63
|
+
const results = [];
|
|
64
|
+
try {
|
|
65
|
+
for (const objConfig of config.objects) {
|
|
66
|
+
this.spinner.start(messages.getMessage('info.loading', [objConfig.object]));
|
|
67
|
+
// eslint-disable-next-line no-await-in-loop
|
|
68
|
+
const result = await loadObject(conn, db, objConfig);
|
|
69
|
+
this.spinner.stop();
|
|
70
|
+
if (result.success) {
|
|
71
|
+
this.log(` ${result.object}: ${result.successCount}/${result.totalRecords} succeeded`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.warn(messages.getMessage('error.objectFailed', [result.object, result.errors.join('; ')]));
|
|
75
|
+
}
|
|
76
|
+
results.push(result);
|
|
77
|
+
}
|
|
78
|
+
this.log(messages.getMessage('info.complete'));
|
|
79
|
+
this.styledHeader('Load Results');
|
|
80
|
+
this.table({
|
|
81
|
+
data: results,
|
|
82
|
+
columns: [
|
|
83
|
+
'object',
|
|
84
|
+
'table',
|
|
85
|
+
{ key: 'totalRecords', name: 'Total' },
|
|
86
|
+
{ key: 'successCount', name: 'Success' },
|
|
87
|
+
{ key: 'failureCount', name: 'Failures' },
|
|
88
|
+
'success',
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
db.close();
|
|
94
|
+
}
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/commands/bulkyard/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAc,MAAM,sBAAsB,CAAC;AAE9D,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;AAIpE,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,SAA4B;IACrD,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;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|
8
|
+
export type BulkyardConfig = {
|
|
9
|
+
database: string;
|
|
10
|
+
objects: BulkyardObjectConfig[];
|
|
11
|
+
};
|
|
12
|
+
export declare function loadConfig(filePath: string): BulkyardConfig;
|
|
13
|
+
export type InlineFlagConfig = {
|
|
14
|
+
sobject: string;
|
|
15
|
+
database: string;
|
|
16
|
+
query?: string;
|
|
17
|
+
operation?: string;
|
|
18
|
+
externalIdField?: string;
|
|
19
|
+
table?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function buildConfigFromFlags(flags: InlineFlagConfig): BulkyardConfig;
|
|
22
|
+
export declare function validateForExtract(config: BulkyardConfig): void;
|
|
23
|
+
export declare function validateForLoad(config: BulkyardConfig): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { SfError } from '@salesforce/core';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
export function loadConfig(filePath) {
|
|
5
|
+
const raw = readFileSync(filePath, 'utf8');
|
|
6
|
+
const parsed = yaml.load(raw);
|
|
7
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
8
|
+
throw new SfError(`Invalid config file: ${filePath}`);
|
|
9
|
+
}
|
|
10
|
+
if (typeof parsed.database !== 'string' || parsed.database.length === 0) {
|
|
11
|
+
throw new SfError('Config must include a "database" path string.');
|
|
12
|
+
}
|
|
13
|
+
if (!Array.isArray(parsed.objects) || parsed.objects.length === 0) {
|
|
14
|
+
throw new SfError('Config must include a non-empty "objects" array.');
|
|
15
|
+
}
|
|
16
|
+
for (const obj of parsed.objects) {
|
|
17
|
+
if (typeof obj.object !== 'string' || obj.object.length === 0) {
|
|
18
|
+
throw new SfError('Each object entry must have an "object" field.');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return parsed;
|
|
22
|
+
}
|
|
23
|
+
export function buildConfigFromFlags(flags) {
|
|
24
|
+
const obj = { object: flags.sobject };
|
|
25
|
+
if (flags.query)
|
|
26
|
+
obj.query = flags.query;
|
|
27
|
+
if (flags.operation)
|
|
28
|
+
obj.operation = flags.operation;
|
|
29
|
+
if (flags.externalIdField)
|
|
30
|
+
obj.externalIdField = flags.externalIdField;
|
|
31
|
+
if (flags.table)
|
|
32
|
+
obj.table = flags.table;
|
|
33
|
+
return { database: flags.database, objects: [obj] };
|
|
34
|
+
}
|
|
35
|
+
export function validateForExtract(config) {
|
|
36
|
+
for (const obj of config.objects) {
|
|
37
|
+
if (!obj.query) {
|
|
38
|
+
throw new SfError(`Object "${obj.object}" is missing a "query" for extract.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function validateForLoad(config) {
|
|
43
|
+
for (const obj of config.objects) {
|
|
44
|
+
if (!obj.operation) {
|
|
45
|
+
throw new SfError(`Object "${obj.object}" is missing an "operation" for load.`);
|
|
46
|
+
}
|
|
47
|
+
if (obj.operation === 'upsert' && !obj.externalIdField) {
|
|
48
|
+
throw new SfError(`Object "${obj.object}" uses upsert but is missing "externalIdField".`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,IAAI,MAAM,SAAS,CAAC;AAe3B,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,MAAM,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAA4B,CAAC;IAEzD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,MAAM,IAAI,OAAO,CAAC,wBAAwB,QAAQ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,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAsB;IACvD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC,MAAM,qCAAqC,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAsB;IACpD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC,MAAM,uCAAuC,CAAC,CAAC;QAClF,CAAC;QACD,IAAI,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;YACvD,MAAM,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC,MAAM,iDAAiD,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ColumnDef = {
|
|
2
|
+
name: string;
|
|
3
|
+
sfType: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class BulkyardDatabase {
|
|
6
|
+
private db;
|
|
7
|
+
constructor(dbPath: string);
|
|
8
|
+
createTable(tableName: string, columns: ColumnDef[]): void;
|
|
9
|
+
insertRecords(tableName: string, columns: string[], records: Array<Record<string, unknown>>): void;
|
|
10
|
+
readAllRows(tableName: string): Array<Record<string, unknown>>;
|
|
11
|
+
tableExists(tableName: string): boolean;
|
|
12
|
+
getTableColumns(tableName: string): string[];
|
|
13
|
+
getRowCount(tableName: string): number;
|
|
14
|
+
close(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { sfTypeToSqlite } from './type-map.js';
|
|
3
|
+
function quoteId(identifier) {
|
|
4
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
5
|
+
}
|
|
6
|
+
function convertValue(val) {
|
|
7
|
+
if (val === null || val === undefined)
|
|
8
|
+
return null;
|
|
9
|
+
if (typeof val === 'boolean')
|
|
10
|
+
return val ? 1 : 0;
|
|
11
|
+
if (typeof val === 'object')
|
|
12
|
+
return JSON.stringify(val);
|
|
13
|
+
return val;
|
|
14
|
+
}
|
|
15
|
+
export class BulkyardDatabase {
|
|
16
|
+
db;
|
|
17
|
+
constructor(dbPath) {
|
|
18
|
+
this.db = new Database(dbPath);
|
|
19
|
+
this.db.pragma('journal_mode = WAL');
|
|
20
|
+
this.db.pragma('foreign_keys = OFF');
|
|
21
|
+
}
|
|
22
|
+
createTable(tableName, columns) {
|
|
23
|
+
const quoted = quoteId(tableName);
|
|
24
|
+
this.db.exec(`DROP TABLE IF EXISTS ${quoted}`);
|
|
25
|
+
const colDefs = columns.map((c) => `${quoteId(c.name)} ${sfTypeToSqlite(c.sfType)}`).join(', ');
|
|
26
|
+
this.db.exec(`CREATE TABLE ${quoted} (${colDefs})`);
|
|
27
|
+
}
|
|
28
|
+
insertRecords(tableName, columns, records) {
|
|
29
|
+
const quoted = quoteId(tableName);
|
|
30
|
+
const colList = columns.map((c) => quoteId(c)).join(', ');
|
|
31
|
+
const placeholders = columns.map(() => '?').join(', ');
|
|
32
|
+
const stmt = this.db.prepare(`INSERT INTO ${quoted} (${colList}) VALUES (${placeholders})`);
|
|
33
|
+
const batchSize = 1000;
|
|
34
|
+
for (let i = 0; i < records.length; i += batchSize) {
|
|
35
|
+
const batch = records.slice(i, i + batchSize);
|
|
36
|
+
const insertBatch = this.db.transaction((rows) => {
|
|
37
|
+
for (const row of rows) {
|
|
38
|
+
const values = columns.map((col) => convertValue(row[col]));
|
|
39
|
+
stmt.run(...values);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
insertBatch(batch);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
readAllRows(tableName) {
|
|
46
|
+
const quoted = quoteId(tableName);
|
|
47
|
+
return this.db.prepare(`SELECT * FROM ${quoted}`).all();
|
|
48
|
+
}
|
|
49
|
+
tableExists(tableName) {
|
|
50
|
+
const row = this.db
|
|
51
|
+
.prepare("SELECT count(*) as cnt FROM sqlite_master WHERE type='table' AND name = ?")
|
|
52
|
+
.get(tableName);
|
|
53
|
+
return row.cnt > 0;
|
|
54
|
+
}
|
|
55
|
+
getTableColumns(tableName) {
|
|
56
|
+
const rows = this.db.prepare(`PRAGMA table_info(${quoteId(tableName)})`).all();
|
|
57
|
+
return rows.map((r) => r.name);
|
|
58
|
+
}
|
|
59
|
+
getRowCount(tableName) {
|
|
60
|
+
const row = this.db.prepare(`SELECT count(*) as cnt FROM ${quoteId(tableName)}`).get();
|
|
61
|
+
return row.cnt;
|
|
62
|
+
}
|
|
63
|
+
close() {
|
|
64
|
+
this.db.close();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,SAAS,OAAO,CAAC,UAAkB;IACjC,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/C,CAAC;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,OAAO,GAAG,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,C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GAAG,CAAC,CAAC,GAAG,EAA6B,CAAC;QAC1G,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAEM,WAAW,CAAC,SAAiB;QAClC,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,+BAA+B,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,EAAqB,CAAC;QAC1G,OAAO,GAAG,CAAC,GAAG,CAAC;IACjB,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { BulkyardDatabase } from './database.js';
|
|
3
|
+
import { BulkyardObjectConfig } from './config.js';
|
|
4
|
+
export type ExtractResult = {
|
|
5
|
+
object: string;
|
|
6
|
+
table: string;
|
|
7
|
+
recordCount: number;
|
|
8
|
+
success: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function extractObject(conn: Connection, db: BulkyardDatabase, objConfig: BulkyardObjectConfig): Promise<ExtractResult>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export async function extractObject(conn, db, objConfig) {
|
|
2
|
+
const tableName = objConfig.table ?? objConfig.object;
|
|
3
|
+
try {
|
|
4
|
+
const queryResult = await conn.bulk2.query(objConfig.query);
|
|
5
|
+
const records = await queryResult.toArray();
|
|
6
|
+
if (records.length === 0) {
|
|
7
|
+
return { object: objConfig.object, table: tableName, recordCount: 0, success: true };
|
|
8
|
+
}
|
|
9
|
+
const firstRecord = records[0];
|
|
10
|
+
const recordKeys = Object.keys(firstRecord).filter((k) => k !== 'attributes');
|
|
11
|
+
const describeResult = await conn.describe(objConfig.object);
|
|
12
|
+
const fieldMap = new Map(describeResult.fields.map((f) => [f.name, f.type]));
|
|
13
|
+
const columns = recordKeys.map((key) => ({
|
|
14
|
+
name: key,
|
|
15
|
+
sfType: fieldMap.get(key) ?? 'string',
|
|
16
|
+
}));
|
|
17
|
+
db.createTable(tableName, columns);
|
|
18
|
+
const cleanRecords = records.map((rec) => {
|
|
19
|
+
const cleaned = {};
|
|
20
|
+
for (const key of recordKeys) {
|
|
21
|
+
cleaned[key] = rec[key];
|
|
22
|
+
}
|
|
23
|
+
return cleaned;
|
|
24
|
+
});
|
|
25
|
+
db.insertRecords(tableName, recordKeys, cleanRecords);
|
|
26
|
+
return { object: objConfig.object, table: tableName, recordCount: records.length, success: true };
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
30
|
+
return { object: objConfig.object, table: tableName, recordCount: 0, success: false, error: message };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../src/core/extractor.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAgB,EAChB,EAAoB,EACpB,SAA+B;IAE/B,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,MAAM,CAAC;IACtD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,KAAM,CAAC,CAAC;QAC7D,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAE5C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACvF,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC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AE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACxG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { BulkyardDatabase } from './database.js';
|
|
3
|
+
import { BulkyardObjectConfig } from './config.js';
|
|
4
|
+
export type LoadResult = {
|
|
5
|
+
object: string;
|
|
6
|
+
table: string;
|
|
7
|
+
totalRecords: number;
|
|
8
|
+
successCount: number;
|
|
9
|
+
failureCount: number;
|
|
10
|
+
success: boolean;
|
|
11
|
+
errors: string[];
|
|
12
|
+
};
|
|
13
|
+
export declare function loadObject(conn: Connection, db: BulkyardDatabase, objConfig: BulkyardObjectConfig): Promise<LoadResult>;
|