@paralect/hive 0.1.50-alpha.0 → 0.1.50-alpha.2
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/cli/helpers/docker.js +4 -4
- package/cli/helpers/envCheck.js +14 -10
- package/cli/helpers/findPort.js +3 -3
- package/cli/hive.js +17 -15
- package/package.json +1 -1
- package/starter/loader.mjs +40 -0
- package/starter/package-lock.json +3512 -262
- package/starter/package.json +7 -2
- package/starter/register.mjs +6 -0
- package/starter/src/app-config/index.js +3 -0
- package/starter/src/app.js +10 -14
- package/starter/src/autoMap/addHandlers.js +3 -3
- package/starter/src/autoMap/getDependentFields.js +1 -1
- package/starter/src/autoMap/mapSchema.js +2 -2
- package/starter/src/bullMqBus.js +1 -1
- package/starter/src/bullMqWrapper.js +1 -1
- package/starter/src/db.js +12 -11
- package/starter/src/helpers/esm.js +56 -0
- package/starter/src/helpers/getMiddlewares.js +3 -0
- package/starter/src/helpers/getResourceEndpoints.js +3 -0
- package/starter/src/helpers/getResources.js +3 -0
- package/starter/src/helpers/getSchemas.js +3 -0
- package/starter/src/helpers/importHandlers.js +11 -20
- package/starter/src/ioEmitter.js +1 -1
- package/starter/src/logger.js +1 -1
- package/starter/src/middlewares/attachUser.js +2 -2
- package/starter/src/middlewares/global/tryToAttachUser.js +1 -1
- package/starter/src/middlewares/shouldExist.js +1 -1
- package/starter/src/middlewares/shouldNotExist.js +1 -1
- package/starter/src/migrations/migration.service.js +4 -1
- package/starter/src/migrations/migrations-log/migration-log.schema.js +1 -1
- package/starter/src/migrations/migrations-log/migration-log.service.js +1 -1
- package/starter/src/migrations/migrations.schema.js +1 -1
- package/starter/src/migrations/migrator.js +1 -1
- package/starter/src/migrator.js +2 -3
- package/starter/src/resources/schemaMappings/schemaMappings.schema.js +1 -1
- package/starter/src/resources/tokens/methods/setToken.js +1 -1
- package/starter/src/resources/tokens/methods/storeToken.js +2 -2
- package/starter/src/resources/tokens/tokens.schema.js +1 -1
- package/starter/src/resources/users/endpoints/getCurrentUser.js +1 -1
- package/starter/src/resources/users/endpoints/getUserProfile.js +1 -1
- package/starter/src/resources/users/methods/ensureUserCreated.js +1 -1
- package/starter/src/resources/users/users.schema.js +1 -1
- package/starter/src/routes/index.js +8 -8
- package/starter/src/routes/middlewares/routeErrorHandler.js +1 -1
- package/starter/src/scheduler.js +10 -7
- package/starter/src/services/emailService.js +1 -1
- package/starter/src/services/setCookie.js +2 -2
- package/starter/src/socketIo.js +3 -3
- package/test-app/package-lock.json +321 -8543
- package/test-app/package.json +1 -1
package/cli/helpers/docker.js
CHANGED
|
@@ -21,7 +21,7 @@ const getContainerStatus = (name) => {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const startContainer = async (name, image,
|
|
24
|
+
const startContainer = async (name, image, hostPort, containerPort, extraArgs = '') => {
|
|
25
25
|
const status = getContainerStatus(name);
|
|
26
26
|
|
|
27
27
|
if (status === 'running') {
|
|
@@ -37,17 +37,17 @@ const startContainer = async (name, image, port, extraArgs = '') => {
|
|
|
37
37
|
|
|
38
38
|
// Container doesn't exist, create it
|
|
39
39
|
console.log(` Creating ${name}...`);
|
|
40
|
-
const cmd = `docker run -d --name ${name} -p ${
|
|
40
|
+
const cmd = `docker run -d --name ${name} -p ${hostPort}:${containerPort} ${extraArgs} ${image}`;
|
|
41
41
|
execSync(cmd, { stdio: 'inherit' });
|
|
42
42
|
return true;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const startMongo = async () => {
|
|
46
|
-
return startContainer('hive-mongo', 'mongo:7', 27017);
|
|
46
|
+
return startContainer('hive-mongo', 'mongo:7', 27027, 27017, '-e MONGO_INITDB_DATABASE=hive');
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
const startRedis = async () => {
|
|
50
|
-
return startContainer('hive-redis', 'redis:7-alpine', 6379);
|
|
50
|
+
return startContainer('hive-redis', 'redis:7-alpine', 6389, 6379);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
module.exports = {
|
package/cli/helpers/envCheck.js
CHANGED
|
@@ -47,10 +47,14 @@ const updateEnvFile = (envPath, updates) => {
|
|
|
47
47
|
writeEnvFile(envPath, env);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const ensureEnvConfig = async (
|
|
51
|
-
const
|
|
50
|
+
const ensureEnvConfig = async (hiveSrc) => {
|
|
51
|
+
const appConfigDir = path.join(hiveSrc, 'app-config');
|
|
52
|
+
if (!fs.existsSync(appConfigDir)) {
|
|
53
|
+
fs.mkdirSync(appConfigDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
const envPath = path.join(appConfigDir, '.env');
|
|
52
56
|
const env = readEnvFile(envPath);
|
|
53
|
-
const projectName = path.basename(
|
|
57
|
+
const projectName = path.basename(path.dirname(hiveSrc));
|
|
54
58
|
const updates = {};
|
|
55
59
|
|
|
56
60
|
// Check MONGODB_URI
|
|
@@ -60,19 +64,19 @@ const ensureEnvConfig = async (projectDir) => {
|
|
|
60
64
|
name: 'mongoChoice',
|
|
61
65
|
message: 'MONGODB_URI not set. How would you like to configure MongoDB?',
|
|
62
66
|
choices: [
|
|
63
|
-
{ name: 'Use local Docker (localhost:
|
|
67
|
+
{ name: 'Use local Docker (localhost:27027)', value: 'local' },
|
|
64
68
|
{ name: 'Enter custom URI', value: 'custom' },
|
|
65
69
|
]
|
|
66
70
|
}]);
|
|
67
71
|
|
|
68
72
|
if (mongoChoice === 'local') {
|
|
69
|
-
updates.MONGODB_URI = `mongodb://localhost:
|
|
73
|
+
updates.MONGODB_URI = `mongodb://localhost:27027/${projectName}`;
|
|
70
74
|
} else {
|
|
71
75
|
const { mongoUri } = await inquirer.prompt([{
|
|
72
76
|
type: 'input',
|
|
73
77
|
name: 'mongoUri',
|
|
74
78
|
message: 'Enter MongoDB URI:',
|
|
75
|
-
default: `mongodb://localhost:
|
|
79
|
+
default: `mongodb://localhost:27027/${projectName}`
|
|
76
80
|
}]);
|
|
77
81
|
updates.MONGODB_URI = mongoUri;
|
|
78
82
|
}
|
|
@@ -85,7 +89,7 @@ const ensureEnvConfig = async (projectDir) => {
|
|
|
85
89
|
name: 'redisChoice',
|
|
86
90
|
message: 'REDIS_URI not set. How would you like to configure Redis?',
|
|
87
91
|
choices: [
|
|
88
|
-
{ name: 'Use local Docker (localhost:
|
|
92
|
+
{ name: 'Use local Docker (localhost:6389)', value: 'local' },
|
|
89
93
|
{ name: 'Enter custom URI', value: 'custom' },
|
|
90
94
|
{ name: 'Skip (Redis optional)', value: 'skip' },
|
|
91
95
|
]
|
|
@@ -93,13 +97,13 @@ const ensureEnvConfig = async (projectDir) => {
|
|
|
93
97
|
|
|
94
98
|
if (redisChoice === 'local') {
|
|
95
99
|
const redisDb = hashCode(projectName) % 16;
|
|
96
|
-
updates.REDIS_URI = `redis://localhost:
|
|
100
|
+
updates.REDIS_URI = `redis://localhost:6389/${redisDb}`;
|
|
97
101
|
} else if (redisChoice === 'custom') {
|
|
98
102
|
const { redisUri } = await inquirer.prompt([{
|
|
99
103
|
type: 'input',
|
|
100
104
|
name: 'redisUri',
|
|
101
105
|
message: 'Enter Redis URI:',
|
|
102
|
-
default: `redis://localhost:
|
|
106
|
+
default: `redis://localhost:6389/0`
|
|
103
107
|
}]);
|
|
104
108
|
updates.REDIS_URI = redisUri;
|
|
105
109
|
}
|
|
@@ -108,7 +112,7 @@ const ensureEnvConfig = async (projectDir) => {
|
|
|
108
112
|
// Write updates if any
|
|
109
113
|
if (Object.keys(updates).length > 0) {
|
|
110
114
|
updateEnvFile(envPath, updates);
|
|
111
|
-
console.log(`\n Updated
|
|
115
|
+
console.log(`\n Updated app-config/.env with: ${Object.keys(updates).join(', ')}\n`);
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
return { ...env, ...updates };
|
package/cli/helpers/findPort.js
CHANGED
|
@@ -3,16 +3,16 @@ const net = require('net');
|
|
|
3
3
|
const isPortAvailable = (port) => {
|
|
4
4
|
return new Promise((resolve) => {
|
|
5
5
|
const server = net.createServer();
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
server.once('error', () => {
|
|
8
8
|
resolve(false);
|
|
9
9
|
});
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
server.once('listening', () => {
|
|
12
12
|
server.close();
|
|
13
13
|
resolve(true);
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
server.listen(port, '127.0.0.1');
|
|
17
17
|
});
|
|
18
18
|
};
|
package/cli/hive.js
CHANGED
|
@@ -76,14 +76,16 @@ program
|
|
|
76
76
|
);
|
|
77
77
|
|
|
78
78
|
const redisDb = hashCode(name) % 16;
|
|
79
|
+
const appConfigDir = path.join(projectDir, 'src', 'app-config');
|
|
80
|
+
await execCommand(`mkdir -p ${appConfigDir}`);
|
|
79
81
|
fs.writeFileSync(
|
|
80
|
-
path.join(
|
|
81
|
-
`MONGODB_URI=mongodb://localhost:
|
|
82
|
+
path.join(appConfigDir, '.env'),
|
|
83
|
+
`MONGODB_URI=mongodb://localhost:27027/${name}\nREDIS_URI=redis://localhost:6389/${redisDb}\nPORT=3001\nNODE_ENV=development\n`
|
|
82
84
|
);
|
|
83
85
|
|
|
84
86
|
fs.writeFileSync(
|
|
85
87
|
path.join(projectDir, '.gitignore'),
|
|
86
|
-
`node_modules\n.hive\n.env\n`
|
|
88
|
+
`node_modules\n.hive\n.env\nsrc/app-config/.env\n`
|
|
87
89
|
);
|
|
88
90
|
|
|
89
91
|
await execCommand(`cp -r ${path.resolve(__dirname, '..')}/starter/.cursor ${projectDir}/`);
|
|
@@ -111,14 +113,14 @@ program
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
console.log('\nStarting Hive infrastructure...\n');
|
|
114
|
-
|
|
116
|
+
|
|
115
117
|
await startMongo();
|
|
116
118
|
await startRedis();
|
|
117
119
|
|
|
118
120
|
console.log('\n✅ Infrastructure ready!\n');
|
|
119
121
|
console.log('Connection URIs:');
|
|
120
|
-
console.log(' MongoDB: mongodb://localhost:
|
|
121
|
-
console.log(' Redis: redis://localhost:
|
|
122
|
+
console.log(' MongoDB: mongodb://localhost:27027/<your-db-name>');
|
|
123
|
+
console.log(' Redis: redis://localhost:6389/<db-number>\n');
|
|
122
124
|
console.log('These containers are shared across all Hive projects.');
|
|
123
125
|
console.log('Each project uses a unique database name for isolation.\n');
|
|
124
126
|
} catch (error) {
|
|
@@ -135,8 +137,8 @@ program
|
|
|
135
137
|
const projectDir = path.resolve(hiveSrc, '..');
|
|
136
138
|
const hiveProjectDir = path.resolve(projectDir, '.hive');
|
|
137
139
|
|
|
138
|
-
// Ensure env config exists
|
|
139
|
-
await ensureEnvConfig(
|
|
140
|
+
// Ensure env config exists in hive_src/app-config/.env
|
|
141
|
+
await ensureEnvConfig(hiveSrc);
|
|
140
142
|
|
|
141
143
|
// Find available port
|
|
142
144
|
const defaultPort = parseInt(process.env.PORT) || 3001;
|
|
@@ -146,9 +148,9 @@ program
|
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
await execCommand(`mkdir -p ${hiveProjectDir}`);
|
|
149
|
-
await execCommand(`
|
|
151
|
+
await execCommand(`rsync -a --exclude node_modules ${path.resolve(__dirname, '..')}/starter/ ${hiveProjectDir}/`);
|
|
150
152
|
|
|
151
|
-
const child = spawn('npx', ['tsx', '--watch', 'src/app.js'], {
|
|
153
|
+
const child = spawn('npx', ['tsx', '--watch', '--import', './register.mjs', 'src/app.js'], {
|
|
152
154
|
cwd: hiveProjectDir,
|
|
153
155
|
stdio: 'inherit',
|
|
154
156
|
env: { ...process.env, HIVE_SRC: hiveSrc, PORT: String(port) }
|
|
@@ -166,15 +168,15 @@ program
|
|
|
166
168
|
.description('Prepare Hive server')
|
|
167
169
|
.action(async (dirPath = '.') => {
|
|
168
170
|
try {
|
|
169
|
-
|
|
170
|
-
const projectDir = path.resolve(
|
|
171
|
+
const hiveSrc = path.resolve(process.cwd(), dirPath);
|
|
172
|
+
const projectDir = path.resolve(hiveSrc, '..');
|
|
171
173
|
const hiveProjectDir = path.resolve(projectDir, '.hive');
|
|
172
174
|
|
|
173
|
-
// Ensure env config exists
|
|
174
|
-
await ensureEnvConfig(
|
|
175
|
+
// Ensure env config exists in hive_src/app-config/.env
|
|
176
|
+
await ensureEnvConfig(hiveSrc);
|
|
175
177
|
|
|
176
178
|
await execCommand(`mkdir -p ${hiveProjectDir}`);
|
|
177
|
-
await execCommand(`
|
|
179
|
+
await execCommand(`rsync -a --exclude node_modules ${path.resolve(__dirname, '..')}/starter/ ${hiveProjectDir}/`);
|
|
178
180
|
} catch (error) {
|
|
179
181
|
console.error('An error occurred:', error.message);
|
|
180
182
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { resolve as resolvePath } from 'path';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { existsSync, statSync } from 'fs';
|
|
4
|
+
|
|
5
|
+
function resolveFilePath(basePath) {
|
|
6
|
+
// If path exists as-is and is a file, use it
|
|
7
|
+
if (existsSync(basePath) && statSync(basePath).isFile()) {
|
|
8
|
+
return basePath;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// If path is a directory, try index.js
|
|
12
|
+
if (existsSync(basePath) && statSync(basePath).isDirectory()) {
|
|
13
|
+
const indexPath = resolvePath(basePath, 'index.js');
|
|
14
|
+
if (existsSync(indexPath)) {
|
|
15
|
+
return indexPath;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Try adding .js extension
|
|
20
|
+
const withJs = basePath + '.js';
|
|
21
|
+
if (existsSync(withJs)) {
|
|
22
|
+
return withJs;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Fallback to original path (will error if not found)
|
|
26
|
+
return basePath;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function resolve(specifier, context, nextResolve) {
|
|
30
|
+
// #root/... → HIVE_SRC/... (user code)
|
|
31
|
+
// Note: #hive/... is handled by package.json imports field
|
|
32
|
+
if (specifier.startsWith('#root/')) {
|
|
33
|
+
const relativePath = specifier.slice(6); // remove '#root/'
|
|
34
|
+
const basePath = resolvePath(process.env.HIVE_SRC, relativePath);
|
|
35
|
+
const absolutePath = resolveFilePath(basePath);
|
|
36
|
+
return { url: pathToFileURL(absolutePath).href, shortCircuit: true };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return nextResolve(specifier, context);
|
|
40
|
+
}
|