@@ -4,6 +4,14 @@ var sdk = require('postman-collection'),
4
4
5
5
DEFAULT_LOOKUP_STRATEGY = 'idOrName' ,
6
6
INVALID_LOOKUP_STRATEGY_ERROR = 'runtime~extractRunnableItems: Invalid entrypoint lookupStrategy' ,
7
+
8
+ DEFAULT_IGNORE_STRATEGY = 'itemOrGroup' ,
9
+ INVALID_IGNORE_STRATEGY_ERROR = 'runtime~extractRunnableItems: Invalid exclude ignoreStrategy' ,
10
+
11
+ ignoreStrategyMap = {
12
+ itemOrGroup : findItemOrGroup ,
13
+ itemsOrGroups : findItemsOrGroups
14
+ } ,
7
15
8
16
/**
9
17
* Accumulate all items in order if entry point is a collection/folder.
@@ -106,6 +114,10 @@ var sdk = require('postman-collection'),
106
114
return _accumulatedItems ;
107
115
} ,
108
116
117
+ findItemsOrGroupsToExclude = function ( options , itemGroup , excludeSubset = { } , _continueAccumulation = false ) {
118
+
119
+ }
120
+
109
121
/**
110
122
* Finds an item or group from a path. The path should be an array of ids from the parent chain.
111
123
*
@@ -115,12 +127,14 @@ var sdk = require('postman-collection'),
115
127
* @param {?Array<String> } [options.path]
116
128
* @param {Function } callback
117
129
*/
118
- lookupByPath = function ( collection , options , callback ) {
130
+ lookupByPath = function ( collection , options , exclude = { } , callback ) {
119
131
var lookupPath ,
120
132
lastMatch = collection ,
121
133
lookupOptions = options || { } ,
122
134
i ,
123
135
ii ;
136
+
137
+ console . log ( 'entrypoint4:' , JSON . stringify ( options ) )
124
138
125
139
// path can be empty, if item/group is at the top level
126
140
lookupPath = lookupOptions . path || [ ] ;
@@ -144,15 +158,25 @@ var sdk = require('postman-collection'),
144
158
* @param {String } [options.execute]
145
159
* @param {Function } callback
146
160
*/
147
- lookupByIdOrName = function ( collection , options , callback ) {
161
+ lookupByIdOrName = function ( collection , options , exclude , callback ) {
148
162
var match = options . execute ,
149
- matched ;
163
+ matched , itemToIgnore ;
164
+
165
+ console . log ( 'entrypoint3:' , JSON . stringify ( options ) )
150
166
151
167
if ( ! match ) { return callback ( null , [ ] ) ; }
152
168
153
169
// do a recursive lookup
154
170
matched = findItemOrGroup ( collection , match ) ;
155
171
172
+ if ( ! exclude . ignore ) {
173
+ itemToIgnore = findItemsOrGroupsToExclude ( exclude , collection , exclude . ignore ) ;
174
+
175
+ if ( matched . id === itemToIgnore . id || matched . name === itemToIgnore . name ) {
176
+ return callback ( null , [ ] ) ;
177
+ }
178
+ }
179
+
156
180
callback ( null , flattenNode ( matched ) , matched ) ;
157
181
} ,
158
182
@@ -166,14 +190,18 @@ var sdk = require('postman-collection'),
166
190
* @param {Array<String> } [options.execute]
167
191
* @param {Function } callback
168
192
*/
169
- lookupByMultipleIdOrName = function ( collection , options , callback ) {
193
+ lookupByMultipleIdOrName = function ( collection , options , exclude , callback ) {
170
194
var entrypoints = options . execute ,
171
195
entrypointLookup = { } ,
196
+ excludeItemsLookup = { } ,
172
197
runnableItems = [ ] ,
173
198
items ,
199
+ itemsToIgnore ,
174
200
i ,
175
201
ii ;
176
202
203
+ console . log ( 'entrypoint2:' , JSON . stringify ( options ) )
204
+
177
205
if ( ! ( Array . isArray ( entrypoints ) && entrypoints . length ) ) {
178
206
return callback ( null , [ ] ) ;
179
207
}
@@ -194,6 +222,13 @@ var sdk = require('postman-collection'),
194
222
return callback ( null , [ ] ) ;
195
223
}
196
224
225
+ if ( exlude . ignore ) {
226
+ // for (j = 0, jj = itemsToIgnore.length; j < jj; j++) {
227
+ // excludeItemsLookup[itemsToIgnore[j]] = true;
228
+ // }
229
+ itemsToIgnore = findItemsOrGroupsToExclude ( exclude , collection , excludeItemsLookup , true ) ;
230
+ }
231
+
197
232
// extract runnable items from the searched items.
198
233
for ( i = 0 , ii = items . members . length ; i < ii ; i ++ ) {
199
234
runnableItems = runnableItems . concat ( flattenNode ( items . members [ i ] ) ) ;
@@ -212,13 +247,15 @@ var sdk = require('postman-collection'),
212
247
* @param {Array<String> } [options.execute]
213
248
* @param {Function } callback
214
249
*/
215
- lookupByOrder = function ( collection , options , callback ) {
250
+ lookupByOrder = function ( collection , options , exclude = { } , callback ) {
216
251
var entrypoints = options . execute ,
217
252
entrypointLookup = { } ,
218
253
runnableItems = [ ] ,
219
254
items ,
220
255
i ,
221
256
ii ;
257
+
258
+ console . log ( 'entrypoint1:' , JSON . stringify ( options ) )
222
259
223
260
if ( ! ( Array . isArray ( entrypoints ) && entrypoints . length ) ) {
224
261
return callback ( null , [ ] ) ;
@@ -265,19 +302,29 @@ var sdk = require('postman-collection'),
265
302
* @param {String } [entrypoint.lookupStrategy=idOrName] strategy to use for entrypoint lookup [idOrName, path]
266
303
* @param {Function } callback
267
304
*/
268
- extractRunnableItems = function ( collection , entrypoint , callback ) {
305
+ extractRunnableItems = function ( collection , entrypoint , exclude , callback ) {
269
306
var lookupFunction ,
270
- lookupStrategy ;
307
+ ignoreFunction ,
308
+ lookupStrategy ,
309
+ ignoreStrategy ;
310
+
311
+ console . log ( 'entrypoint:' , JSON . stringify ( entrypoint ) )
271
312
272
313
// if no entrypoint is specified, flatten the entire collection
273
- if ( ! entrypoint ) { return callback ( null , flattenNode ( collection ) , collection ) ; }
314
+ if ( ! entrypoint && ! exclude ) { return callback ( null , flattenNode ( collection ) , collection ) ; }
274
315
275
316
lookupStrategy = entrypoint . lookupStrategy || DEFAULT_LOOKUP_STRATEGY ;
317
+ ignoreStrategy = exclude . ignoreStrategy || DEFAULT_IGNORE_STRATEGY ;
318
+
319
+ // lookup exclude pool using given strategy
320
+ // eslint-disable-next-line no-cond-assign
321
+ ( ignoreFunction = ignoreStrategyMap [ ignoreStrategy ] ) ?
322
+ ignoreStrategyMap [ ignoreStrategy ] : callback ( new Error ( INVALID_IGNORE_STRATEGY_ERROR ) ) ; // eslint-disable-line callback-return
276
323
277
324
// lookup entry using given strategy
278
325
// eslint-disable-next-line no-cond-assign
279
326
( lookupFunction = lookupStrategyMap [ lookupStrategy ] ) ?
280
- lookupFunction ( collection , entrypoint , callback ) :
327
+ lookupFunction ( collection , entrypoint , exclude , callback ) :
281
328
callback ( new Error ( INVALID_LOOKUP_STRATEGY_ERROR ) ) ; // eslint-disable-line callback-return
282
329
} ;
283
330
0 commit comments