@gugananuvem/aws-local-simulator 1.0.9 → 1.0.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/README.md +204 -192
- package/bin/aws-local-simulator.js +62 -62
- package/package.json +2 -2
- package/src/config/config-loader.js +112 -112
- package/src/config/default-config.js +65 -65
- package/src/config/env-loader.js +68 -66
- package/src/index.js +130 -130
- package/src/index.mjs +123 -123
- package/src/server.js +221 -219
- package/src/services/apigateway/index.js +66 -66
- package/src/services/apigateway/server.js +434 -434
- package/src/services/apigateway/simulator.js +1251 -1251
- package/src/services/cognito/index.js +65 -65
- package/src/services/cognito/server.js +228 -228
- package/src/services/cognito/simulator.js +847 -847
- package/src/services/dynamodb/index.js +70 -70
- package/src/services/dynamodb/server.js +121 -121
- package/src/services/dynamodb/simulator.js +620 -614
- package/src/services/ecs/index.js +66 -0
- package/src/services/ecs/server.js +234 -0
- package/src/services/ecs/simulator.js +845 -0
- package/src/services/eventbridge/index.js +84 -84
- package/src/services/index.js +18 -18
- package/src/services/lambda/handler-loader.js +172 -172
- package/src/services/lambda/index.js +72 -72
- package/src/services/lambda/route-registry.js +274 -274
- package/src/services/lambda/server.js +152 -152
- package/src/services/lambda/simulator.js +284 -277
- package/src/services/s3/index.js +69 -69
- package/src/services/s3/server.js +238 -238
- package/src/services/s3/simulator.js +740 -740
- package/src/services/sns/index.js +75 -75
- package/src/services/sqs/index.js +95 -95
- package/src/services/sqs/server.js +273 -273
- package/src/services/sqs/simulator.js +659 -659
- package/src/template/aws-config-template.js +87 -87
- package/src/template/aws-config-template.mjs +90 -90
- package/src/template/config-template.json +203 -165
- package/src/utils/aws-config.js +91 -91
- package/src/utils/local-store.js +67 -67
- package/src/utils/logger.js +59 -59
package/src/utils/local-store.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local Store - Persistência em arquivos JSON
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const mkdirp = require('mkdirp');
|
|
8
|
-
|
|
9
|
-
class LocalStore {
|
|
10
|
-
constructor(dataDir) {
|
|
11
|
-
this.dataDir = dataDir;
|
|
12
|
-
this.ensureDir();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
ensureDir() {
|
|
16
|
-
if (!fs.existsSync(this.dataDir)) {
|
|
17
|
-
mkdirp.sync(this.dataDir);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getFilePath(entity) {
|
|
22
|
-
return path.join(this.dataDir, `${entity}.json`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
read(entity) {
|
|
26
|
-
const filePath = this.getFilePath(entity);
|
|
27
|
-
if (!fs.existsSync(filePath)) return [];
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
31
|
-
return JSON.parse(content);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error(`Erro ao ler ${entity}:`, error);
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
write(entity, data) {
|
|
39
|
-
const filePath = this.getFilePath(entity);
|
|
40
|
-
try {
|
|
41
|
-
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error(`Erro ao escrever ${entity}:`, error);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
delete(entity) {
|
|
49
|
-
const filePath = this.getFilePath(entity);
|
|
50
|
-
if (fs.existsSync(filePath)) {
|
|
51
|
-
fs.unlinkSync(filePath);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exists(entity) {
|
|
56
|
-
const filePath = this.getFilePath(entity);
|
|
57
|
-
return fs.existsSync(filePath);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
list() {
|
|
61
|
-
if (!fs.existsSync(this.dataDir)) return [];
|
|
62
|
-
return fs.readdirSync(this.dataDir)
|
|
63
|
-
.filter(f => f.endsWith('.json'))
|
|
64
|
-
.map(f => f.replace('.json', ''));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Local Store - Persistência em arquivos JSON
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
|
|
9
|
+
class LocalStore {
|
|
10
|
+
constructor(dataDir) {
|
|
11
|
+
this.dataDir = dataDir;
|
|
12
|
+
this.ensureDir();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ensureDir() {
|
|
16
|
+
if (!fs.existsSync(this.dataDir)) {
|
|
17
|
+
mkdirp.sync(this.dataDir);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getFilePath(entity) {
|
|
22
|
+
return path.join(this.dataDir, `${entity}.json`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
read(entity) {
|
|
26
|
+
const filePath = this.getFilePath(entity);
|
|
27
|
+
if (!fs.existsSync(filePath)) return [];
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
31
|
+
return JSON.parse(content);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`Erro ao ler ${entity}:`, error);
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
write(entity, data) {
|
|
39
|
+
const filePath = this.getFilePath(entity);
|
|
40
|
+
try {
|
|
41
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error(`Erro ao escrever ${entity}:`, error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
delete(entity) {
|
|
49
|
+
const filePath = this.getFilePath(entity);
|
|
50
|
+
if (fs.existsSync(filePath)) {
|
|
51
|
+
fs.unlinkSync(filePath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exists(entity) {
|
|
56
|
+
const filePath = this.getFilePath(entity);
|
|
57
|
+
return fs.existsSync(filePath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
list() {
|
|
61
|
+
if (!fs.existsSync(this.dataDir)) return [];
|
|
62
|
+
return fs.readdirSync(this.dataDir)
|
|
63
|
+
.filter(f => f.endsWith('.json'))
|
|
64
|
+
.map(f => f.replace('.json', ''));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
68
|
module.exports = LocalStore;
|
package/src/utils/logger.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger configurável
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
let currentLogLevel = 'info';
|
|
6
|
-
|
|
7
|
-
const LOG_LEVELS = {
|
|
8
|
-
silent: 0,
|
|
9
|
-
error: 1,
|
|
10
|
-
warn: 2,
|
|
11
|
-
info: 3,
|
|
12
|
-
debug: 4,
|
|
13
|
-
verboso: 5
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
class Logger {
|
|
17
|
-
static setLevel(level) {
|
|
18
|
-
if (LOG_LEVELS[level] !== undefined) {
|
|
19
|
-
currentLogLevel = level;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static error(...args) {
|
|
24
|
-
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.error) {
|
|
25
|
-
console.error('\x1b[31m%s\x1b[0m', '❌', ...args);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static warn(...args) {
|
|
30
|
-
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.warn) {
|
|
31
|
-
console.warn('\x1b[33m%s\x1b[0m', '⚠️', ...args);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static info(...args) {
|
|
36
|
-
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
|
|
37
|
-
console.log('\x1b[36m%s\x1b[0m', 'ℹ️', ...args);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static debug(...args) {
|
|
42
|
-
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.debug) {
|
|
43
|
-
console.debug('\x1b[90m%s\x1b[0m', '🔍', ...args);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static verboso(...args) {
|
|
48
|
-
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.verboso) {
|
|
49
|
-
console.log('\x1b[35m%s\x1b[0m', '📝', ...args);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static success(...args) {
|
|
54
|
-
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
|
|
55
|
-
console.log('\x1b[32m%s\x1b[0m', '✅', ...args);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Logger configurável
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
let currentLogLevel = 'info';
|
|
6
|
+
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
silent: 0,
|
|
9
|
+
error: 1,
|
|
10
|
+
warn: 2,
|
|
11
|
+
info: 3,
|
|
12
|
+
debug: 4,
|
|
13
|
+
verboso: 5
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class Logger {
|
|
17
|
+
static setLevel(level) {
|
|
18
|
+
if (LOG_LEVELS[level] !== undefined) {
|
|
19
|
+
currentLogLevel = level;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static error(...args) {
|
|
24
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.error) {
|
|
25
|
+
console.error('\x1b[31m%s\x1b[0m', '❌', ...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static warn(...args) {
|
|
30
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.warn) {
|
|
31
|
+
console.warn('\x1b[33m%s\x1b[0m', '⚠️', ...args);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static info(...args) {
|
|
36
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
|
|
37
|
+
console.log('\x1b[36m%s\x1b[0m', 'ℹ️', ...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static debug(...args) {
|
|
42
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.debug) {
|
|
43
|
+
console.debug('\x1b[90m%s\x1b[0m', '🔍', ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static verboso(...args) {
|
|
48
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.verboso) {
|
|
49
|
+
console.log('\x1b[35m%s\x1b[0m', '📝', ...args);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static success(...args) {
|
|
54
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
|
|
55
|
+
console.log('\x1b[32m%s\x1b[0m', '✅', ...args);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
60
|
module.exports = Logger;
|