n8n-nodes-base 0.218.0 → 0.218.1
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/dist/build.tsbuildinfo +1 -1
- package/dist/nodes/SplitInBatches/SplitInBatches.node.d.ts +3 -4
- package/dist/nodes/SplitInBatches/SplitInBatches.node.js +10 -107
- package/dist/nodes/SplitInBatches/SplitInBatches.node.js.map +1 -1
- package/dist/nodes/SplitInBatches/test/SplitInBatches.combineData.json +1 -1
- package/dist/nodes/SplitInBatches/test/SplitInBatches.workflow_v2.json +178 -0
- package/dist/nodes/SplitInBatches/v1/SplitInBatchesV1.node.d.ts +5 -0
- package/dist/nodes/SplitInBatches/v1/SplitInBatchesV1.node.js +109 -0
- package/dist/nodes/SplitInBatches/v1/SplitInBatchesV1.node.js.map +1 -0
- package/dist/nodes/SplitInBatches/v2/SplitInBatchesV2.node.d.ts +5 -0
- package/dist/nodes/SplitInBatches/v2/SplitInBatchesV2.node.js +122 -0
- package/dist/nodes/SplitInBatches/v2/SplitInBatchesV2.node.js.map +1 -0
- package/dist/types/nodes.json +3 -2
- package/package.json +1 -1
- /package/dist/nodes/SplitInBatches/test/{SplitInBatches.workflow.json → SplitInBatches.workflow_v1.json} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare class SplitInBatches
|
|
3
|
-
|
|
4
|
-
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][] | null>;
|
|
1
|
+
import { VersionedNodeType } from 'n8n-workflow';
|
|
2
|
+
export declare class SplitInBatches extends VersionedNodeType {
|
|
3
|
+
constructor();
|
|
5
4
|
}
|
|
@@ -2,120 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SplitInBatches = void 0;
|
|
4
4
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
-
|
|
5
|
+
const SplitInBatchesV1_node_1 = require("./v1/SplitInBatchesV1.node");
|
|
6
|
+
const SplitInBatchesV2_node_1 = require("./v2/SplitInBatchesV2.node");
|
|
7
|
+
class SplitInBatches extends n8n_workflow_1.VersionedNodeType {
|
|
6
8
|
constructor() {
|
|
7
|
-
|
|
9
|
+
const baseDescription = {
|
|
8
10
|
displayName: 'Split In Batches',
|
|
9
11
|
name: 'splitInBatches',
|
|
10
12
|
icon: 'fa:th-large',
|
|
11
13
|
group: ['organization'],
|
|
12
|
-
version: 1,
|
|
13
14
|
description: 'Split data into batches and iterate over each batch',
|
|
14
|
-
|
|
15
|
-
name: 'Split In Batches',
|
|
16
|
-
color: '#007755',
|
|
17
|
-
},
|
|
18
|
-
inputs: ['main'],
|
|
19
|
-
outputs: ['main', 'main'],
|
|
20
|
-
outputNames: ['loop', 'done'],
|
|
21
|
-
properties: [
|
|
22
|
-
{
|
|
23
|
-
displayName: 'You may not need this node — n8n nodes automatically run once for each input item. <a href="https://docs.n8n.io/getting-started/key-concepts/looping.html#using-loops-in-n8n" target="_blank">More info</a>',
|
|
24
|
-
name: 'splitInBatchesNotice',
|
|
25
|
-
type: 'notice',
|
|
26
|
-
default: '',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
displayName: 'Batch Size',
|
|
30
|
-
name: 'batchSize',
|
|
31
|
-
type: 'number',
|
|
32
|
-
typeOptions: {
|
|
33
|
-
minValue: 1,
|
|
34
|
-
},
|
|
35
|
-
default: 10,
|
|
36
|
-
description: 'The number of items to return with each call',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
displayName: 'Options',
|
|
40
|
-
name: 'options',
|
|
41
|
-
type: 'collection',
|
|
42
|
-
placeholder: 'Add Option',
|
|
43
|
-
default: {},
|
|
44
|
-
options: [
|
|
45
|
-
{
|
|
46
|
-
displayName: 'Reset',
|
|
47
|
-
name: 'reset',
|
|
48
|
-
type: 'boolean',
|
|
49
|
-
default: false,
|
|
50
|
-
description: 'Whether the node will be reset and so with the current input-data newly initialized',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
],
|
|
15
|
+
defaultVersion: 2,
|
|
55
16
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const returnItems = [];
|
|
62
|
-
const options = this.getNodeParameter('options', 0, {});
|
|
63
|
-
if (nodeContext.items === undefined || options.reset === true) {
|
|
64
|
-
const sourceData = this.getInputSourceData();
|
|
65
|
-
nodeContext.currentRunIndex = 0;
|
|
66
|
-
nodeContext.maxRunIndex = Math.ceil(items.length / batchSize);
|
|
67
|
-
nodeContext.sourceData = (0, n8n_workflow_1.deepCopy)(sourceData);
|
|
68
|
-
returnItems.push.apply(returnItems, items.splice(0, batchSize));
|
|
69
|
-
nodeContext.items = [...items];
|
|
70
|
-
nodeContext.processedItems = [];
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
nodeContext.currentRunIndex += 1;
|
|
74
|
-
returnItems.push.apply(returnItems, nodeContext.items.splice(0, batchSize));
|
|
75
|
-
const addSourceOverwrite = (pairedItem) => {
|
|
76
|
-
if (typeof pairedItem === 'number') {
|
|
77
|
-
return {
|
|
78
|
-
item: pairedItem,
|
|
79
|
-
sourceOverwrite: nodeContext.sourceData,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
...pairedItem,
|
|
84
|
-
sourceOverwrite: nodeContext.sourceData,
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
function getPairedItemInformation(item) {
|
|
88
|
-
if (item.pairedItem === undefined) {
|
|
89
|
-
return {
|
|
90
|
-
item: 0,
|
|
91
|
-
sourceOverwrite: nodeContext.sourceData,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
if (Array.isArray(item.pairedItem)) {
|
|
95
|
-
return item.pairedItem.map(addSourceOverwrite);
|
|
96
|
-
}
|
|
97
|
-
return addSourceOverwrite(item.pairedItem);
|
|
98
|
-
}
|
|
99
|
-
const sourceOverwrite = this.getInputSourceData();
|
|
100
|
-
const newItems = items.map((item, index) => {
|
|
101
|
-
return {
|
|
102
|
-
...item,
|
|
103
|
-
pairedItem: {
|
|
104
|
-
sourceOverwrite,
|
|
105
|
-
item: index,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
nodeContext.processedItems = [...nodeContext.processedItems, ...newItems];
|
|
110
|
-
returnItems.map((item) => {
|
|
111
|
-
item.pairedItem = getPairedItemInformation(item);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
nodeContext.noItemsLeft = nodeContext.items.length === 0;
|
|
115
|
-
if (returnItems.length === 0) {
|
|
116
|
-
return [[], nodeContext.processedItems];
|
|
117
|
-
}
|
|
118
|
-
return [returnItems, []];
|
|
17
|
+
const nodeVersions = {
|
|
18
|
+
1: new SplitInBatchesV1_node_1.SplitInBatchesV1(),
|
|
19
|
+
2: new SplitInBatchesV2_node_1.SplitInBatchesV2(),
|
|
20
|
+
};
|
|
21
|
+
super(nodeVersions, baseDescription);
|
|
119
22
|
}
|
|
120
23
|
}
|
|
121
24
|
exports.SplitInBatches = SplitInBatches;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SplitInBatches.node.js","sourceRoot":"","sources":["../../../nodes/SplitInBatches/SplitInBatches.node.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SplitInBatches.node.js","sourceRoot":"","sources":["../../../nodes/SplitInBatches/SplitInBatches.node.ts"],"names":[],"mappings":";;;AACA,+CAAiD;AAEjD,sEAA8D;AAC9D,sEAA8D;AAE9D,MAAa,cAAe,SAAQ,gCAAiB;IACpD;QACC,MAAM,eAAe,GAA6B;YACjD,WAAW,EAAE,kBAAkB;YAC/B,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,CAAC,cAAc,CAAC;YACvB,WAAW,EAAE,qDAAqD;YAClE,cAAc,EAAE,CAAC;SACjB,CAAC;QAEF,MAAM,YAAY,GAAuC;YACxD,CAAC,EAAE,IAAI,wCAAgB,EAAE;YACzB,CAAC,EAAE,IAAI,wCAAgB,EAAE;SACzB,CAAC;QAEF,KAAK,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IACtC,CAAC;CACD;AAlBD,wCAkBC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Split in Batches Test",
|
|
3
|
+
"nodes": [
|
|
4
|
+
{
|
|
5
|
+
"parameters": {},
|
|
6
|
+
"id": "86b8149f-b0a0-489c-bb62-e59142988996",
|
|
7
|
+
"name": "When clicking \"Execute Workflow\"",
|
|
8
|
+
"type": "n8n-nodes-base.manualTrigger",
|
|
9
|
+
"typeVersion": 1,
|
|
10
|
+
"position": [400, 220]
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"parameters": {
|
|
14
|
+
"batchSize": 1,
|
|
15
|
+
"options": {}
|
|
16
|
+
},
|
|
17
|
+
"id": "30c5546e-bdcc-44ff-bfca-89c5fb97b678",
|
|
18
|
+
"name": "Split In Batches",
|
|
19
|
+
"type": "n8n-nodes-base.splitInBatches",
|
|
20
|
+
"typeVersion": 2,
|
|
21
|
+
"position": [1100, 220]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"parameters": {
|
|
25
|
+
"values": {
|
|
26
|
+
"string": [
|
|
27
|
+
{
|
|
28
|
+
"name": "data[0]",
|
|
29
|
+
"value": "n8n"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "data[1]",
|
|
33
|
+
"value": "test"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"options": {}
|
|
38
|
+
},
|
|
39
|
+
"id": "92d386b8-60be-4f8b-801c-b6459ec206f7",
|
|
40
|
+
"name": "Set",
|
|
41
|
+
"type": "n8n-nodes-base.set",
|
|
42
|
+
"typeVersion": 1,
|
|
43
|
+
"position": [640, 220]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"parameters": {
|
|
47
|
+
"fieldToSplitOut": "data",
|
|
48
|
+
"options": {}
|
|
49
|
+
},
|
|
50
|
+
"id": "74b7e63e-a9f8-4a82-9e1f-7b2429d9118d",
|
|
51
|
+
"name": "Item Lists",
|
|
52
|
+
"type": "n8n-nodes-base.itemLists",
|
|
53
|
+
"typeVersion": 1,
|
|
54
|
+
"position": [860, 220]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"parameters": {
|
|
58
|
+
"conditions": {
|
|
59
|
+
"boolean": [
|
|
60
|
+
{
|
|
61
|
+
"value1": "={{ $node[\"Split In Batches\"].context[\"noItemsLeft\"] }}",
|
|
62
|
+
"value2": true
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"id": "a5f68369-4e70-4f16-b260-3c8b74517993",
|
|
68
|
+
"name": "IF",
|
|
69
|
+
"type": "n8n-nodes-base.if",
|
|
70
|
+
"typeVersion": 1,
|
|
71
|
+
"position": [1280, 220]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"parameters": {
|
|
75
|
+
"values": {
|
|
76
|
+
"string": [
|
|
77
|
+
{
|
|
78
|
+
"name": "maxRunIndex",
|
|
79
|
+
"value": "={{ $node[\"Split In Batches\"].context[\"maxRunIndex\"] }}"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"value": "={{ $node[\"Split In Batches\"].context[\"currentRunIndex\"] }}"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
"options": {}
|
|
87
|
+
},
|
|
88
|
+
"id": "1f44eb0a-5fb7-43a7-8281-84a8a7ec8464",
|
|
89
|
+
"name": "Output",
|
|
90
|
+
"type": "n8n-nodes-base.set",
|
|
91
|
+
"typeVersion": 1,
|
|
92
|
+
"position": [1480, 200]
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"pinData": {
|
|
96
|
+
"Output": [
|
|
97
|
+
{
|
|
98
|
+
"json": {
|
|
99
|
+
"data": "test",
|
|
100
|
+
"maxRunIndex": 2,
|
|
101
|
+
"propertyName": 1
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
"connections": {
|
|
107
|
+
"When clicking \"Execute Workflow\"": {
|
|
108
|
+
"main": [
|
|
109
|
+
[
|
|
110
|
+
{
|
|
111
|
+
"node": "Set",
|
|
112
|
+
"type": "main",
|
|
113
|
+
"index": 0
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
"Split In Batches": {
|
|
119
|
+
"main": [
|
|
120
|
+
[
|
|
121
|
+
{
|
|
122
|
+
"node": "IF",
|
|
123
|
+
"type": "main",
|
|
124
|
+
"index": 0
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
"Set": {
|
|
130
|
+
"main": [
|
|
131
|
+
[
|
|
132
|
+
{
|
|
133
|
+
"node": "Item Lists",
|
|
134
|
+
"type": "main",
|
|
135
|
+
"index": 0
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"Item Lists": {
|
|
141
|
+
"main": [
|
|
142
|
+
[
|
|
143
|
+
{
|
|
144
|
+
"node": "Split In Batches",
|
|
145
|
+
"type": "main",
|
|
146
|
+
"index": 0
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
"IF": {
|
|
152
|
+
"main": [
|
|
153
|
+
[
|
|
154
|
+
{
|
|
155
|
+
"node": "Output",
|
|
156
|
+
"type": "main",
|
|
157
|
+
"index": 0
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
{
|
|
162
|
+
"node": "Split In Batches",
|
|
163
|
+
"type": "main",
|
|
164
|
+
"index": 0
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"active": false,
|
|
171
|
+
"settings": {},
|
|
172
|
+
"versionId": "de1a454e-43e9-4c2d-b786-18da5d97940f",
|
|
173
|
+
"id": "389",
|
|
174
|
+
"meta": {
|
|
175
|
+
"instanceId": "REMOVED"
|
|
176
|
+
},
|
|
177
|
+
"tags": []
|
|
178
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class SplitInBatchesV1 implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][] | null>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SplitInBatchesV1 = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
class SplitInBatchesV1 {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.description = {
|
|
8
|
+
displayName: 'Split In Batches',
|
|
9
|
+
name: 'splitInBatches',
|
|
10
|
+
icon: 'fa:th-large',
|
|
11
|
+
group: ['organization'],
|
|
12
|
+
version: 1,
|
|
13
|
+
description: 'Split data into batches and iterate over each batch',
|
|
14
|
+
defaults: {
|
|
15
|
+
name: 'Split In Batches',
|
|
16
|
+
color: '#007755',
|
|
17
|
+
},
|
|
18
|
+
inputs: ['main'],
|
|
19
|
+
outputs: ['main'],
|
|
20
|
+
properties: [
|
|
21
|
+
{
|
|
22
|
+
displayName: 'You may not need this node — n8n nodes automatically run once for each input item. <a href="https://docs.n8n.io/getting-started/key-concepts/looping.html#using-loops-in-n8n" target="_blank">More info</a>',
|
|
23
|
+
name: 'splitInBatchesNotice',
|
|
24
|
+
type: 'notice',
|
|
25
|
+
default: '',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
displayName: 'Batch Size',
|
|
29
|
+
name: 'batchSize',
|
|
30
|
+
type: 'number',
|
|
31
|
+
typeOptions: {
|
|
32
|
+
minValue: 1,
|
|
33
|
+
},
|
|
34
|
+
default: 10,
|
|
35
|
+
description: 'The number of items to return with each call',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
displayName: 'Options',
|
|
39
|
+
name: 'options',
|
|
40
|
+
type: 'collection',
|
|
41
|
+
placeholder: 'Add Option',
|
|
42
|
+
default: {},
|
|
43
|
+
options: [
|
|
44
|
+
{
|
|
45
|
+
displayName: 'Reset',
|
|
46
|
+
name: 'reset',
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
default: false,
|
|
49
|
+
description: 'Whether the node will be reset and so with the current input-data newly initialized',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async execute() {
|
|
57
|
+
const items = this.getInputData().slice();
|
|
58
|
+
const nodeContext = this.getContext('node');
|
|
59
|
+
const batchSize = this.getNodeParameter('batchSize', 0);
|
|
60
|
+
const returnItems = [];
|
|
61
|
+
const options = this.getNodeParameter('options', 0, {});
|
|
62
|
+
if (nodeContext.items === undefined || options.reset === true) {
|
|
63
|
+
const sourceData = this.getInputSourceData();
|
|
64
|
+
nodeContext.currentRunIndex = 0;
|
|
65
|
+
nodeContext.maxRunIndex = Math.ceil(items.length / batchSize);
|
|
66
|
+
nodeContext.sourceData = (0, n8n_workflow_1.deepCopy)(sourceData);
|
|
67
|
+
returnItems.push.apply(returnItems, items.splice(0, batchSize));
|
|
68
|
+
nodeContext.items = [...items];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
nodeContext.currentRunIndex += 1;
|
|
72
|
+
returnItems.push.apply(returnItems, nodeContext.items.splice(0, batchSize));
|
|
73
|
+
const addSourceOverwrite = (pairedItem) => {
|
|
74
|
+
if (typeof pairedItem === 'number') {
|
|
75
|
+
return {
|
|
76
|
+
item: pairedItem,
|
|
77
|
+
sourceOverwrite: nodeContext.sourceData,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
...pairedItem,
|
|
82
|
+
sourceOverwrite: nodeContext.sourceData,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
function getPairedItemInformation(item) {
|
|
86
|
+
if (item.pairedItem === undefined) {
|
|
87
|
+
return {
|
|
88
|
+
item: 0,
|
|
89
|
+
sourceOverwrite: nodeContext.sourceData,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(item.pairedItem)) {
|
|
93
|
+
return item.pairedItem.map(addSourceOverwrite);
|
|
94
|
+
}
|
|
95
|
+
return addSourceOverwrite(item.pairedItem);
|
|
96
|
+
}
|
|
97
|
+
returnItems.map((item) => {
|
|
98
|
+
item.pairedItem = getPairedItemInformation(item);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
nodeContext.noItemsLeft = nodeContext.items.length === 0;
|
|
102
|
+
if (returnItems.length === 0) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return [returnItems];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.SplitInBatchesV1 = SplitInBatchesV1;
|
|
109
|
+
//# sourceMappingURL=SplitInBatchesV1.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SplitInBatchesV1.node.js","sourceRoot":"","sources":["../../../../nodes/SplitInBatches/v1/SplitInBatchesV1.node.ts"],"names":[],"mappings":";;;AAQA,+CAAwC;AAExC,MAAa,gBAAgB;IAA7B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,kBAAkB;YAC/B,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,CAAC,cAAc,CAAC;YACvB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,qDAAqD;YAClE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BAAkB,CAAC,CAAC;iBAC/C;gBAED,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5C,CAAC;YAED,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACxB,IAAI,CAAC,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;SACH;QAED,WAAW,CAAC,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QAEzD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAE7B,OAAO,IAAI,CAAC;SACZ;QAED,OAAO,CAAC,WAAW,CAAC,CAAC;IACtB,CAAC;CACD;AApID,4CAoIC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class SplitInBatchesV2 implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][] | null>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SplitInBatchesV2 = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
class SplitInBatchesV2 {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.description = {
|
|
8
|
+
displayName: 'Split In Batches',
|
|
9
|
+
name: 'splitInBatches',
|
|
10
|
+
icon: 'fa:th-large',
|
|
11
|
+
group: ['organization'],
|
|
12
|
+
version: 2,
|
|
13
|
+
description: 'Split data into batches and iterate over each batch',
|
|
14
|
+
defaults: {
|
|
15
|
+
name: 'Split In Batches',
|
|
16
|
+
color: '#007755',
|
|
17
|
+
},
|
|
18
|
+
inputs: ['main'],
|
|
19
|
+
outputs: ['main', 'main'],
|
|
20
|
+
outputNames: ['loop', 'done'],
|
|
21
|
+
properties: [
|
|
22
|
+
{
|
|
23
|
+
displayName: 'You may not need this node — n8n nodes automatically run once for each input item. <a href="https://docs.n8n.io/getting-started/key-concepts/looping.html#using-loops-in-n8n" target="_blank">More info</a>',
|
|
24
|
+
name: 'splitInBatchesNotice',
|
|
25
|
+
type: 'notice',
|
|
26
|
+
default: '',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
displayName: 'Batch Size',
|
|
30
|
+
name: 'batchSize',
|
|
31
|
+
type: 'number',
|
|
32
|
+
typeOptions: {
|
|
33
|
+
minValue: 1,
|
|
34
|
+
},
|
|
35
|
+
default: 10,
|
|
36
|
+
description: 'The number of items to return with each call',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
displayName: 'Options',
|
|
40
|
+
name: 'options',
|
|
41
|
+
type: 'collection',
|
|
42
|
+
placeholder: 'Add Option',
|
|
43
|
+
default: {},
|
|
44
|
+
options: [
|
|
45
|
+
{
|
|
46
|
+
displayName: 'Reset',
|
|
47
|
+
name: 'reset',
|
|
48
|
+
type: 'boolean',
|
|
49
|
+
default: false,
|
|
50
|
+
description: 'Whether the node will be reset and so with the current input-data newly initialized',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async execute() {
|
|
58
|
+
const items = this.getInputData().slice();
|
|
59
|
+
const nodeContext = this.getContext('node');
|
|
60
|
+
const batchSize = this.getNodeParameter('batchSize', 0);
|
|
61
|
+
const returnItems = [];
|
|
62
|
+
const options = this.getNodeParameter('options', 0, {});
|
|
63
|
+
if (nodeContext.items === undefined || options.reset === true) {
|
|
64
|
+
const sourceData = this.getInputSourceData();
|
|
65
|
+
nodeContext.currentRunIndex = 0;
|
|
66
|
+
nodeContext.maxRunIndex = Math.ceil(items.length / batchSize);
|
|
67
|
+
nodeContext.sourceData = (0, n8n_workflow_1.deepCopy)(sourceData);
|
|
68
|
+
returnItems.push.apply(returnItems, items.splice(0, batchSize));
|
|
69
|
+
nodeContext.items = [...items];
|
|
70
|
+
nodeContext.processedItems = [];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
nodeContext.currentRunIndex += 1;
|
|
74
|
+
returnItems.push.apply(returnItems, nodeContext.items.splice(0, batchSize));
|
|
75
|
+
const addSourceOverwrite = (pairedItem) => {
|
|
76
|
+
if (typeof pairedItem === 'number') {
|
|
77
|
+
return {
|
|
78
|
+
item: pairedItem,
|
|
79
|
+
sourceOverwrite: nodeContext.sourceData,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...pairedItem,
|
|
84
|
+
sourceOverwrite: nodeContext.sourceData,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
function getPairedItemInformation(item) {
|
|
88
|
+
if (item.pairedItem === undefined) {
|
|
89
|
+
return {
|
|
90
|
+
item: 0,
|
|
91
|
+
sourceOverwrite: nodeContext.sourceData,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(item.pairedItem)) {
|
|
95
|
+
return item.pairedItem.map(addSourceOverwrite);
|
|
96
|
+
}
|
|
97
|
+
return addSourceOverwrite(item.pairedItem);
|
|
98
|
+
}
|
|
99
|
+
const sourceOverwrite = this.getInputSourceData();
|
|
100
|
+
const newItems = items.map((item, index) => {
|
|
101
|
+
return {
|
|
102
|
+
...item,
|
|
103
|
+
pairedItem: {
|
|
104
|
+
sourceOverwrite,
|
|
105
|
+
item: index,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
nodeContext.processedItems = [...nodeContext.processedItems, ...newItems];
|
|
110
|
+
returnItems.map((item) => {
|
|
111
|
+
item.pairedItem = getPairedItemInformation(item);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
nodeContext.noItemsLeft = nodeContext.items.length === 0;
|
|
115
|
+
if (returnItems.length === 0) {
|
|
116
|
+
return [[], nodeContext.processedItems];
|
|
117
|
+
}
|
|
118
|
+
return [returnItems, []];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.SplitInBatchesV2 = SplitInBatchesV2;
|
|
122
|
+
//# sourceMappingURL=SplitInBatchesV2.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SplitInBatchesV2.node.js","sourceRoot":"","sources":["../../../../nodes/SplitInBatches/v2/SplitInBatchesV2.node.ts"],"names":[],"mappings":";;;AAQA,+CAAwC;AAExC,MAAa,gBAAgB;IAA7B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,kBAAkB;YAC/B,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,CAAC,cAAc,CAAC;YACvB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,qDAAqD;YAClE,QAAQ,EAAE;gBACT,IAAI,EAAE,kBAAkB;gBACxB,KAAK,EAAE,SAAS;aAChB;YACD,MAAM,EAAE,CAAC,MAAM,CAAC;YAEhB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;YACzB,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;YAC7B,UAAU,EAAE;gBACX;oBACC,WAAW,EACV,6MAA6M;oBAC9M,IAAI,EAAE,sBAAsB;oBAC5B,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,EAAE;iBACX;gBACD;oBACC,WAAW,EAAE,YAAY;oBACzB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE;wBACZ,QAAQ,EAAE,CAAC;qBACX;oBACD,OAAO,EAAE,EAAE;oBACX,WAAW,EAAE,8CAA8C;iBAC3D;gBACD;oBACC,WAAW,EAAE,SAAS;oBACtB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,YAAY;oBAClB,WAAW,EAAE,YAAY;oBACzB,OAAO,EAAE,EAAE;oBACX,OAAO,E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