serverless-spy 2.3.9 → 2.3.11
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/.jsii +2 -2
- package/dist/releasetag.txt +1 -1
- package/lib/_virtual/rolldown_runtime.js +25 -0
- package/lib/_virtual/rolldown_runtime.mjs +11 -0
- package/lib/cli/cli.d.mts +1 -0
- package/lib/cli/cli.d.ts +1 -2
- package/lib/cli/cli.js +151 -208
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/cli.mjs +144 -205
- package/lib/cli/cli.mjs.map +1 -0
- package/lib/cli/sampleData.d.mts +896 -0
- package/lib/cli/sampleData.d.ts +860 -856
- package/lib/cli/sampleData.js +496 -480
- package/lib/cli/sampleData.js.map +1 -0
- package/lib/cli/sampleData.mjs +495 -477
- package/lib/cli/sampleData.mjs.map +1 -0
- package/lib/common/SpyEventSender.d.mts +26 -0
- package/lib/common/SpyEventSender.d.ts +23 -18
- package/lib/common/SpyEventSender.js +180 -230
- package/lib/common/SpyEventSender.js.map +1 -0
- package/lib/common/SpyEventSender.mjs +180 -227
- package/lib/common/SpyEventSender.mjs.map +1 -0
- package/lib/common/getWebSocketUrl.d.mts +7 -0
- package/lib/common/getWebSocketUrl.d.ts +7 -2
- package/lib/common/getWebSocketUrl.js +51 -62
- package/lib/common/getWebSocketUrl.js.map +1 -0
- package/lib/common/getWebSocketUrl.mjs +49 -60
- package/lib/common/getWebSocketUrl.mjs.map +1 -0
- package/lib/common/spyEvents/DynamoDBSpyEvent.d.mts +15 -0
- package/lib/common/spyEvents/DynamoDBSpyEvent.d.ts +14 -9
- package/lib/common/spyEvents/DynamoDBSpyEvent.js +0 -3
- package/lib/common/spyEvents/DynamoDBSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/EventBridgeBaseSpyEvent.d.mts +14 -0
- package/lib/common/spyEvents/EventBridgeBaseSpyEvent.d.ts +13 -8
- package/lib/common/spyEvents/EventBridgeBaseSpyEvent.js +0 -3
- package/lib/common/spyEvents/EventBridgeBaseSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/EventBridgeRuleSpyEvent.d.mts +9 -0
- package/lib/common/spyEvents/EventBridgeRuleSpyEvent.d.ts +8 -3
- package/lib/common/spyEvents/EventBridgeRuleSpyEvent.js +0 -3
- package/lib/common/spyEvents/EventBridgeRuleSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/EventBridgeSpyEvent.d.mts +9 -0
- package/lib/common/spyEvents/EventBridgeSpyEvent.d.ts +8 -3
- package/lib/common/spyEvents/EventBridgeSpyEvent.js +0 -3
- package/lib/common/spyEvents/EventBridgeSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/FunctionBaseSpyEvent.d.mts +11 -0
- package/lib/common/spyEvents/FunctionBaseSpyEvent.d.ts +10 -5
- package/lib/common/spyEvents/FunctionBaseSpyEvent.js +0 -3
- package/lib/common/spyEvents/FunctionBaseSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/FunctionConsole.d.mts +10 -0
- package/lib/common/spyEvents/FunctionConsole.d.ts +9 -5
- package/lib/common/spyEvents/FunctionConsole.js +0 -3
- package/lib/common/spyEvents/FunctionConsole.mjs +1 -2
- package/lib/common/spyEvents/FunctionConsoleSpyEvent.d.mts +11 -0
- package/lib/common/spyEvents/FunctionConsoleSpyEvent.d.ts +10 -5
- package/lib/common/spyEvents/FunctionConsoleSpyEvent.js +0 -3
- package/lib/common/spyEvents/FunctionConsoleSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/FunctionContext.d.mts +12 -0
- package/lib/common/spyEvents/FunctionContext.d.ts +11 -6
- package/lib/common/spyEvents/FunctionContext.js +0 -3
- package/lib/common/spyEvents/FunctionContext.mjs +1 -2
- package/lib/common/spyEvents/FunctionErrorSpyEvent.d.mts +13 -0
- package/lib/common/spyEvents/FunctionErrorSpyEvent.d.ts +12 -7
- package/lib/common/spyEvents/FunctionErrorSpyEvent.js +0 -3
- package/lib/common/spyEvents/FunctionErrorSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/FunctionRequestSpyEvent.d.mts +12 -0
- package/lib/common/spyEvents/FunctionRequestSpyEvent.d.ts +11 -6
- package/lib/common/spyEvents/FunctionRequestSpyEvent.js +0 -3
- package/lib/common/spyEvents/FunctionRequestSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/FunctionResponseSpyEvent.d.mts +10 -0
- package/lib/common/spyEvents/FunctionResponseSpyEvent.d.ts +9 -4
- package/lib/common/spyEvents/FunctionResponseSpyEvent.js +0 -3
- package/lib/common/spyEvents/FunctionResponseSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/S3SpyEvent.d.mts +13 -0
- package/lib/common/spyEvents/S3SpyEvent.d.ts +12 -7
- package/lib/common/spyEvents/S3SpyEvent.js +0 -3
- package/lib/common/spyEvents/S3SpyEvent.mjs +1 -2
- package/lib/common/spyEvents/SnsSpyEventBase.d.mts +15 -0
- package/lib/common/spyEvents/SnsSpyEventBase.d.ts +14 -9
- package/lib/common/spyEvents/SnsSpyEventBase.js +0 -3
- package/lib/common/spyEvents/SnsSpyEventBase.mjs +1 -2
- package/lib/common/spyEvents/SnsSubscriptionSpyEvent.d.mts +9 -0
- package/lib/common/spyEvents/SnsSubscriptionSpyEvent.d.ts +8 -3
- package/lib/common/spyEvents/SnsSubscriptionSpyEvent.js +0 -3
- package/lib/common/spyEvents/SnsSubscriptionSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/SnsTopicSpyEvent.d.mts +9 -0
- package/lib/common/spyEvents/SnsTopicSpyEvent.d.ts +8 -3
- package/lib/common/spyEvents/SnsTopicSpyEvent.js +0 -3
- package/lib/common/spyEvents/SnsTopicSpyEvent.mjs +1 -2
- package/lib/common/spyEvents/SpyEvent.d.mts +7 -0
- package/lib/common/spyEvents/SpyEvent.d.ts +6 -2
- package/lib/common/spyEvents/SpyEvent.js +0 -3
- package/lib/common/spyEvents/SpyEvent.mjs +1 -2
- package/lib/common/spyEvents/SpyMessage.d.mts +11 -0
- package/lib/common/spyEvents/SpyMessage.d.ts +10 -5
- package/lib/common/spyEvents/SpyMessage.js +0 -3
- package/lib/common/spyEvents/SpyMessage.mjs +1 -2
- package/lib/common/spyEvents/SqsSpyEvent.d.mts +12 -0
- package/lib/common/spyEvents/SqsSpyEvent.d.ts +11 -6
- package/lib/common/spyEvents/SqsSpyEvent.js +0 -3
- package/lib/common/spyEvents/SqsSpyEvent.mjs +1 -2
- package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js +2 -2
- package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js.map +2 -2
- package/lib/functions/onConnect.d.mts +1 -0
- package/lib/functions/onConnect.d.ts +1 -1
- package/lib/functions/onConnect.js +28 -26
- package/lib/functions/onConnect.js.map +1 -0
- package/lib/functions/onConnect.mjs +35 -26
- package/lib/functions/onConnect.mjs.map +1 -0
- package/lib/functions/onDisconnect.d.mts +10 -0
- package/lib/functions/onDisconnect.d.ts +9 -4
- package/lib/functions/onDisconnect.js +28 -27
- package/lib/functions/onDisconnect.js.map +1 -0
- package/lib/functions/onDisconnect.mjs +29 -25
- package/lib/functions/onDisconnect.mjs.map +1 -0
- package/lib/functions/sendMessage.d.mts +8 -0
- package/lib/functions/sendMessage.d.ts +7 -3
- package/lib/functions/sendMessage.js +26 -21
- package/lib/functions/sendMessage.js.map +1 -0
- package/lib/functions/sendMessage.mjs +28 -19
- package/lib/functions/sendMessage.mjs.map +1 -0
- package/lib/functions/sqsSubscriptionAndDropAllMessages.d.mts +5 -0
- package/lib/functions/sqsSubscriptionAndDropAllMessages.d.ts +5 -1
- package/lib/functions/sqsSubscriptionAndDropAllMessages.js +6 -5
- package/lib/functions/sqsSubscriptionAndDropAllMessages.js.map +1 -0
- package/lib/functions/sqsSubscriptionAndDropAllMessages.mjs +7 -3
- package/lib/functions/sqsSubscriptionAndDropAllMessages.mjs.map +1 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +6 -19
- package/lib/index.mjs +5 -3
- package/lib/listener/PrettifyForDisplay.d.mts +5 -0
- package/lib/listener/PrettifyForDisplay.d.ts +5 -3
- package/lib/listener/PrettifyForDisplay.js +0 -3
- package/lib/listener/PrettifyForDisplay.mjs +1 -2
- package/lib/listener/RecursivePartial.d.mts +7 -0
- package/lib/listener/RecursivePartial.d.ts +7 -4
- package/lib/listener/RecursivePartial.js +0 -3
- package/lib/listener/RecursivePartial.mjs +1 -2
- package/lib/listener/ServerlessSpyListener.d.mts +23 -0
- package/lib/listener/ServerlessSpyListener.d.ts +22 -42
- package/lib/listener/ServerlessSpyListener.js +0 -3
- package/lib/listener/ServerlessSpyListener.mjs +1 -2
- package/lib/listener/ServerlessSpyListenerParams.d.mts +14 -0
- package/lib/listener/ServerlessSpyListenerParams.d.ts +13 -8
- package/lib/listener/ServerlessSpyListenerParams.js +0 -3
- package/lib/listener/ServerlessSpyListenerParams.mjs +1 -2
- package/lib/listener/SpyHandlers.ts.d.mts +158 -0
- package/lib/listener/SpyHandlers.ts.d.ts +144 -144
- package/lib/listener/SpyHandlers.ts.js +0 -3
- package/lib/listener/SpyHandlers.ts.mjs +1 -2
- package/lib/listener/WaitForParams.d.mts +10 -0
- package/lib/listener/WaitForParams.d.ts +9 -4
- package/lib/listener/WaitForParams.js +0 -3
- package/lib/listener/WaitForParams.mjs +1 -2
- package/lib/listener/WsListener.d.mts +27 -0
- package/lib/listener/WsListener.d.ts +26 -21
- package/lib/listener/WsListener.js +173 -231
- package/lib/listener/WsListener.js.map +1 -0
- package/lib/listener/WsListener.mjs +174 -228
- package/lib/listener/WsListener.mjs.map +1 -0
- package/lib/listener/createServerlessSpyListener.d.mts +8 -0
- package/lib/listener/createServerlessSpyListener.d.ts +8 -2
- package/lib/listener/createServerlessSpyListener.js +25 -25
- package/lib/listener/createServerlessSpyListener.js.map +1 -0
- package/lib/listener/createServerlessSpyListener.mjs +26 -23
- package/lib/listener/createServerlessSpyListener.mjs.map +1 -0
- package/lib/listener/index.d.mts +3 -0
- package/lib/listener/index.d.ts +3 -2
- package/lib/listener/index.js +3 -19
- package/lib/listener/index.mjs +3 -3
- package/lib/listener/iot-connection.d.mts +13 -0
- package/lib/listener/iot-connection.d.ts +12 -7
- package/lib/listener/iot-connection.js +48 -46
- package/lib/listener/iot-connection.js.map +1 -0
- package/lib/listener/iot-connection.mjs +46 -44
- package/lib/listener/iot-connection.mjs.map +1 -0
- package/lib/listener/matchers.d.mts +1 -0
- package/lib/listener/matchers.d.ts +1 -0
- package/lib/listener/matchers.js +0 -55
- package/lib/listener/matchers.mjs +1 -55
- package/lib/listener/setup.d.mts +1 -0
- package/lib/listener/setup.d.ts +1 -0
- package/lib/listener/setup.js +0 -21
- package/lib/listener/setup.mjs +1 -21
- package/lib/listener/topic.d.mts +6 -0
- package/lib/listener/topic.d.ts +6 -2
- package/lib/listener/topic.js +9 -7
- package/lib/listener/topic.js.map +1 -0
- package/lib/listener/topic.mjs +8 -4
- package/lib/listener/topic.mjs.map +1 -0
- package/lib/node_modules/tsdown/esm-shims.mjs +11 -0
- package/lib/node_modules/tsdown/esm-shims.mjs.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/native.js +10 -0
- package/lib/node_modules/uuid/dist/esm-node/native.js.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/native.mjs +8 -0
- package/lib/node_modules/uuid/dist/esm-node/native.mjs.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/rng.js +18 -0
- package/lib/node_modules/uuid/dist/esm-node/rng.js.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/rng.mjs +16 -0
- package/lib/node_modules/uuid/dist/esm-node/rng.mjs.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/stringify.js +15 -0
- package/lib/node_modules/uuid/dist/esm-node/stringify.js.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/stringify.mjs +14 -0
- package/lib/node_modules/uuid/dist/esm-node/stringify.mjs.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/v4.js +23 -0
- package/lib/node_modules/uuid/dist/esm-node/v4.js.map +1 -0
- package/lib/node_modules/uuid/dist/esm-node/v4.mjs +23 -0
- package/lib/node_modules/uuid/dist/esm-node/v4.mjs.map +1 -0
- package/lib/src/ServerlessSpy.d.mts +77 -0
- package/lib/src/ServerlessSpy.js +1 -1
- package/lib/src/ServerlessSpy.js.map +1 -0
- package/lib/src/ServerlessSpy.mjs +441 -618
- package/lib/src/ServerlessSpy.mjs.map +1 -0
- package/lib/src/common/envVariableNames.d.mts +35 -0
- package/lib/src/common/envVariableNames.js.map +1 -0
- package/lib/src/common/envVariableNames.mjs +43 -35
- package/lib/src/common/envVariableNames.mjs.map +1 -0
- package/lib/src/index.d.mts +2 -0
- package/lib/src/index.mjs +3 -2
- package/node_modules/debug/package.json +2 -3
- package/node_modules/debug/src/browser.js +1 -1
- package/node_modules/debug/src/common.js +1 -1
- package/package.json +3 -1
- package/tsdown.config.ts +16 -0
- package/node_modules/micromist/yarn.lock +0 -75
- package/node_modules/tmp/lib/tmp.js.orig +0 -471
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Tmp
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2011-2015 KARASZI Istvan <github@spam.raszi.hu>
|
|
5
|
-
*
|
|
6
|
-
* MIT Licensed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Module dependencies.
|
|
11
|
-
*/
|
|
12
|
-
var
|
|
13
|
-
fs = require('fs'),
|
|
14
|
-
path = require('path'),
|
|
15
|
-
os = require('os'),
|
|
16
|
-
crypto = require('crypto'),
|
|
17
|
-
exists = fs.exists || path.exists,
|
|
18
|
-
existsSync = fs.existsSync || path.existsSync,
|
|
19
|
-
tmpDir = require('os-tmpdir'),
|
|
20
|
-
_c = require('constants');
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The working inner variables.
|
|
25
|
-
*/
|
|
26
|
-
var
|
|
27
|
-
// store the actual TMP directory
|
|
28
|
-
_TMP = tmpDir(),
|
|
29
|
-
|
|
30
|
-
// the random characters to choose from
|
|
31
|
-
RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
32
|
-
|
|
33
|
-
TEMPLATE_PATTERN = /XXXXXX/,
|
|
34
|
-
|
|
35
|
-
DEFAULT_TRIES = 3,
|
|
36
|
-
|
|
37
|
-
CREATE_FLAGS = _c.O_CREAT | _c.O_EXCL | _c.O_RDWR,
|
|
38
|
-
|
|
39
|
-
DIR_MODE = 448 /* 0700 */,
|
|
40
|
-
FILE_MODE = 384 /* 0600 */,
|
|
41
|
-
|
|
42
|
-
// this will hold the objects need to be removed on exit
|
|
43
|
-
_removeObjects = [],
|
|
44
|
-
|
|
45
|
-
_gracefulCleanup = false,
|
|
46
|
-
_uncaughtException = false;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Random name generator based on crypto.
|
|
50
|
-
* Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
|
|
51
|
-
*
|
|
52
|
-
* @param {Number} howMany
|
|
53
|
-
* @return {String}
|
|
54
|
-
* @api private
|
|
55
|
-
*/
|
|
56
|
-
function _randomChars(howMany) {
|
|
57
|
-
var
|
|
58
|
-
value = [],
|
|
59
|
-
rnd = null;
|
|
60
|
-
|
|
61
|
-
// make sure that we do not fail because we ran out of entropy
|
|
62
|
-
try {
|
|
63
|
-
rnd = crypto.randomBytes(howMany);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
rnd = crypto.pseudoRandomBytes(howMany);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (var i = 0; i < howMany; i++) {
|
|
69
|
-
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return value.join('');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Checks whether the `obj` parameter is defined or not.
|
|
77
|
-
*
|
|
78
|
-
* @param {Object} obj
|
|
79
|
-
* @return {Boolean}
|
|
80
|
-
* @api private
|
|
81
|
-
*/
|
|
82
|
-
function _isUndefined(obj) {
|
|
83
|
-
return typeof obj === 'undefined';
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Parses the function arguments.
|
|
88
|
-
*
|
|
89
|
-
* This function helps to have optional arguments.
|
|
90
|
-
*
|
|
91
|
-
* @param {Object} options
|
|
92
|
-
* @param {Function} callback
|
|
93
|
-
* @api private
|
|
94
|
-
*/
|
|
95
|
-
function _parseArguments(options, callback) {
|
|
96
|
-
if (typeof options == 'function') {
|
|
97
|
-
var
|
|
98
|
-
tmp = options;
|
|
99
|
-
options = callback || {};
|
|
100
|
-
callback = tmp;
|
|
101
|
-
} else if (typeof options == 'undefined') {
|
|
102
|
-
options = {};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return [options, callback];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Generates a new temporary name.
|
|
110
|
-
*
|
|
111
|
-
* @param {Object} opts
|
|
112
|
-
* @returns {String}
|
|
113
|
-
* @api private
|
|
114
|
-
*/
|
|
115
|
-
function _generateTmpName(opts) {
|
|
116
|
-
if (opts.name) {
|
|
117
|
-
return path.join(opts.dir || _TMP, opts.name);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// mkstemps like template
|
|
121
|
-
if (opts.template) {
|
|
122
|
-
return opts.template.replace(TEMPLATE_PATTERN, _randomChars(6));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// prefix and postfix
|
|
126
|
-
var name = [
|
|
127
|
-
opts.prefix || 'tmp-',
|
|
128
|
-
process.pid,
|
|
129
|
-
_randomChars(12),
|
|
130
|
-
opts.postfix || ''
|
|
131
|
-
].join('');
|
|
132
|
-
|
|
133
|
-
return path.join(opts.dir || _TMP, name);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Gets a temporary file name.
|
|
138
|
-
*
|
|
139
|
-
* @param {Object} options
|
|
140
|
-
* @param {Function} callback
|
|
141
|
-
* @api private
|
|
142
|
-
*/
|
|
143
|
-
function _getTmpName(options, callback) {
|
|
144
|
-
var
|
|
145
|
-
args = _parseArguments(options, callback),
|
|
146
|
-
opts = args[0],
|
|
147
|
-
cb = args[1],
|
|
148
|
-
tries = opts.tries || DEFAULT_TRIES;
|
|
149
|
-
|
|
150
|
-
if (isNaN(tries) || tries < 0)
|
|
151
|
-
return cb(new Error('Invalid tries'));
|
|
152
|
-
|
|
153
|
-
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
|
|
154
|
-
return cb(new Error('Invalid template provided'));
|
|
155
|
-
|
|
156
|
-
(function _getUniqueName() {
|
|
157
|
-
var name = _generateTmpName(opts);
|
|
158
|
-
|
|
159
|
-
// check whether the path exists then retry if needed
|
|
160
|
-
exists(name, function _pathExists(pathExists) {
|
|
161
|
-
if (pathExists) {
|
|
162
|
-
if (tries-- > 0) return _getUniqueName();
|
|
163
|
-
|
|
164
|
-
return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
cb(null, name);
|
|
168
|
-
});
|
|
169
|
-
}());
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Synchronous version of _getTmpName.
|
|
174
|
-
*
|
|
175
|
-
* @param {Object} options
|
|
176
|
-
* @returns {String}
|
|
177
|
-
* @api private
|
|
178
|
-
*/
|
|
179
|
-
function _getTmpNameSync(options) {
|
|
180
|
-
var
|
|
181
|
-
args = _parseArguments(options),
|
|
182
|
-
opts = args[0],
|
|
183
|
-
tries = opts.tries || DEFAULT_TRIES;
|
|
184
|
-
|
|
185
|
-
if (isNaN(tries) || tries < 0)
|
|
186
|
-
throw new Error('Invalid tries');
|
|
187
|
-
|
|
188
|
-
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
|
|
189
|
-
throw new Error('Invalid template provided');
|
|
190
|
-
|
|
191
|
-
do {
|
|
192
|
-
var name = _generateTmpName(opts);
|
|
193
|
-
if (!existsSync(name)) {
|
|
194
|
-
return name;
|
|
195
|
-
}
|
|
196
|
-
} while (tries-- > 0);
|
|
197
|
-
|
|
198
|
-
throw new Error('Could not get a unique tmp filename, max tries reached');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Creates and opens a temporary file.
|
|
203
|
-
*
|
|
204
|
-
* @param {Object} options
|
|
205
|
-
* @param {Function} callback
|
|
206
|
-
* @api public
|
|
207
|
-
*/
|
|
208
|
-
function _createTmpFile(options, callback) {
|
|
209
|
-
var
|
|
210
|
-
args = _parseArguments(options, callback),
|
|
211
|
-
opts = args[0],
|
|
212
|
-
cb = args[1];
|
|
213
|
-
|
|
214
|
-
opts.postfix = (_isUndefined(opts.postfix)) ? '.tmp' : opts.postfix;
|
|
215
|
-
|
|
216
|
-
// gets a temporary filename
|
|
217
|
-
_getTmpName(opts, function _tmpNameCreated(err, name) {
|
|
218
|
-
if (err) return cb(err);
|
|
219
|
-
|
|
220
|
-
// create and open the file
|
|
221
|
-
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
|
|
222
|
-
if (err) return cb(err);
|
|
223
|
-
|
|
224
|
-
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Synchronous version of _createTmpFile.
|
|
231
|
-
*
|
|
232
|
-
* @param {Object} options
|
|
233
|
-
* @returns {Object} object consists of name, fd and removeCallback
|
|
234
|
-
* @api private
|
|
235
|
-
*/
|
|
236
|
-
function _createTmpFileSync(options) {
|
|
237
|
-
var
|
|
238
|
-
args = _parseArguments(options),
|
|
239
|
-
opts = args[0];
|
|
240
|
-
|
|
241
|
-
opts.postfix = opts.postfix || '.tmp';
|
|
242
|
-
|
|
243
|
-
var name = _getTmpNameSync(opts);
|
|
244
|
-
var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
name : name,
|
|
248
|
-
fd : fd,
|
|
249
|
-
removeCallback : _prepareTmpFileRemoveCallback(name, fd, opts)
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Removes files and folders in a directory recursively.
|
|
255
|
-
*
|
|
256
|
-
* @param {String} root
|
|
257
|
-
* @api private
|
|
258
|
-
*/
|
|
259
|
-
function _rmdirRecursiveSync(root) {
|
|
260
|
-
var dirs = [root];
|
|
261
|
-
|
|
262
|
-
do {
|
|
263
|
-
var
|
|
264
|
-
dir = dirs.pop(),
|
|
265
|
-
deferred = false,
|
|
266
|
-
files = fs.readdirSync(dir);
|
|
267
|
-
|
|
268
|
-
for (var i = 0, length = files.length; i < length; i++) {
|
|
269
|
-
var
|
|
270
|
-
file = path.join(dir, files[i]),
|
|
271
|
-
stat = fs.lstatSync(file); // lstat so we don't recurse into symlinked directories
|
|
272
|
-
|
|
273
|
-
if (stat.isDirectory()) {
|
|
274
|
-
if (!deferred) {
|
|
275
|
-
deferred = true;
|
|
276
|
-
dirs.push(dir);
|
|
277
|
-
}
|
|
278
|
-
dirs.push(file);
|
|
279
|
-
} else {
|
|
280
|
-
fs.unlinkSync(file);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (!deferred) {
|
|
285
|
-
fs.rmdirSync(dir);
|
|
286
|
-
}
|
|
287
|
-
} while (dirs.length !== 0);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Creates a temporary directory.
|
|
292
|
-
*
|
|
293
|
-
* @param {Object} options
|
|
294
|
-
* @param {Function} callback
|
|
295
|
-
* @api public
|
|
296
|
-
*/
|
|
297
|
-
function _createTmpDir(options, callback) {
|
|
298
|
-
var
|
|
299
|
-
args = _parseArguments(options, callback),
|
|
300
|
-
opts = args[0],
|
|
301
|
-
cb = args[1];
|
|
302
|
-
|
|
303
|
-
// gets a temporary filename
|
|
304
|
-
_getTmpName(opts, function _tmpNameCreated(err, name) {
|
|
305
|
-
if (err) return cb(err);
|
|
306
|
-
|
|
307
|
-
// create the directory
|
|
308
|
-
fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err) {
|
|
309
|
-
if (err) return cb(err);
|
|
310
|
-
|
|
311
|
-
cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Synchronous version of _createTmpDir.
|
|
318
|
-
*
|
|
319
|
-
* @param {Object} options
|
|
320
|
-
* @returns {Object} object consists of name and removeCallback
|
|
321
|
-
* @api private
|
|
322
|
-
*/
|
|
323
|
-
function _createTmpDirSync(options) {
|
|
324
|
-
var
|
|
325
|
-
args = _parseArguments(options),
|
|
326
|
-
opts = args[0];
|
|
327
|
-
|
|
328
|
-
var name = _getTmpNameSync(opts);
|
|
329
|
-
fs.mkdirSync(name, opts.mode || DIR_MODE);
|
|
330
|
-
|
|
331
|
-
return {
|
|
332
|
-
name : name,
|
|
333
|
-
removeCallback : _prepareTmpDirRemoveCallback(name, opts)
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Prepares the callback for removal of the temporary file.
|
|
339
|
-
*
|
|
340
|
-
* @param {String} name
|
|
341
|
-
* @param {int} fd
|
|
342
|
-
* @param {Object} opts
|
|
343
|
-
* @api private
|
|
344
|
-
* @returns {Function} the callback
|
|
345
|
-
*/
|
|
346
|
-
function _prepareTmpFileRemoveCallback(name, fd, opts) {
|
|
347
|
-
var removeCallback = _prepareRemoveCallback(function _removeCallback(fdPath) {
|
|
348
|
-
<<<<<<< HEAD
|
|
349
|
-
fs.close(fdPath[0], function _closeCallback(err) {
|
|
350
|
-
if (err.errno !== -1 * _c.EBADF || err.code != 'EBADF') throw err;
|
|
351
|
-
fs.unlink(fdPath[1], function _unlinkCallback(err) {
|
|
352
|
-
if (err.errno !== -1 * _c.ENOENT || err.code != 'ENOENT') throw err;
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
=======
|
|
356
|
-
try {
|
|
357
|
-
fs.closeSync(fdPath[0]);
|
|
358
|
-
}
|
|
359
|
-
catch (e) {
|
|
360
|
-
// under some node/windows related circumstances, a temporary file
|
|
361
|
-
// may have not be created as expected or the file was already closed
|
|
362
|
-
// by the user, in which case we will simply ignore the error
|
|
363
|
-
if (e.errno != -_c.EBADF && e.errno != -c.ENOENT) {
|
|
364
|
-
// reraise any unanticipated error
|
|
365
|
-
throw e;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
fs.unlinkSync(fdPath[1]);
|
|
369
|
-
>>>>>>> master
|
|
370
|
-
}, [fd, name]);
|
|
371
|
-
|
|
372
|
-
if (!opts.keep) {
|
|
373
|
-
_removeObjects.unshift(removeCallback);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return removeCallback;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Prepares the callback for removal of the temporary directory.
|
|
381
|
-
*
|
|
382
|
-
* @param {String} name
|
|
383
|
-
* @param {Object} opts
|
|
384
|
-
* @returns {Function} the callback
|
|
385
|
-
* @api private
|
|
386
|
-
*/
|
|
387
|
-
function _prepareTmpDirRemoveCallback(name, opts) {
|
|
388
|
-
var removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs.rmdirSync.bind(fs);
|
|
389
|
-
var removeCallback = _prepareRemoveCallback(removeFunction, name);
|
|
390
|
-
|
|
391
|
-
if (!opts.keep) {
|
|
392
|
-
_removeObjects.unshift(removeCallback);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return removeCallback;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Creates a guarded function wrapping the removeFunction call.
|
|
400
|
-
*
|
|
401
|
-
* @param {Function} removeFunction
|
|
402
|
-
* @param {Object} arg
|
|
403
|
-
* @returns {Function}
|
|
404
|
-
* @api private
|
|
405
|
-
*/
|
|
406
|
-
function _prepareRemoveCallback(removeFunction, arg) {
|
|
407
|
-
var called = false;
|
|
408
|
-
|
|
409
|
-
return function _cleanupCallback() {
|
|
410
|
-
if (called) return;
|
|
411
|
-
|
|
412
|
-
var index = _removeObjects.indexOf(removeFunction);
|
|
413
|
-
if (index >= 0) {
|
|
414
|
-
_removeObjects.splice(index, 1);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
called = true;
|
|
418
|
-
removeFunction(arg);
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* The garbage collector.
|
|
424
|
-
*
|
|
425
|
-
* @api private
|
|
426
|
-
*/
|
|
427
|
-
function _garbageCollector() {
|
|
428
|
-
if (_uncaughtException && !_gracefulCleanup) {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
for (var i = 0, length = _removeObjects.length; i < length; i++) {
|
|
433
|
-
try {
|
|
434
|
-
_removeObjects[i].call(null);
|
|
435
|
-
} catch (e) {
|
|
436
|
-
// already removed?
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function _setGracefulCleanup() {
|
|
442
|
-
_gracefulCleanup = true;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
var version = process.versions.node.split('.').map(function (value) {
|
|
446
|
-
return parseInt(value, 10);
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
if (version[0] === 0 && (version[1] < 9 || version[1] === 9 && version[2] < 5)) {
|
|
450
|
-
process.addListener('uncaughtException', function _uncaughtExceptionThrown(err) {
|
|
451
|
-
_uncaughtException = true;
|
|
452
|
-
_garbageCollector();
|
|
453
|
-
|
|
454
|
-
throw err;
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
process.addListener('exit', function _exit(code) {
|
|
459
|
-
if (code) _uncaughtException = true;
|
|
460
|
-
_garbageCollector();
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
// exporting all the needed methods
|
|
464
|
-
module.exports.tmpdir = _TMP;
|
|
465
|
-
module.exports.dir = _createTmpDir;
|
|
466
|
-
module.exports.dirSync = _createTmpDirSync;
|
|
467
|
-
module.exports.file = _createTmpFile;
|
|
468
|
-
module.exports.fileSync = _createTmpFileSync;
|
|
469
|
-
module.exports.tmpName = _getTmpName;
|
|
470
|
-
module.exports.tmpNameSync = _getTmpNameSync;
|
|
471
|
-
module.exports.setGracefulCleanup = _setGracefulCleanup;
|