zyket 1.2.7 → 1.2.9

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/bin/cli.js CHANGED
@@ -70,7 +70,10 @@ const templateManager = new TemplateManager();
70
70
  const backendFiles = defaultTemplate.filter(file => {
71
71
  const route = file.route;
72
72
  // Only install src and config files, not frontend
73
- return route.startsWith('default/src/') || route.startsWith('default/config/');
73
+ // Skip guards and handlers folders since socket is disabled by default
74
+ return (route.startsWith('default/src/') || route.startsWith('default/config/'))
75
+ && !route.startsWith('default/src/guards/')
76
+ && !route.startsWith('default/src/handlers/');
74
77
  });
75
78
 
76
79
  for (const file of backendFiles) {
@@ -131,67 +134,40 @@ kernel.boot().then(() => {
131
134
 
132
135
  console.log('\n[ZYKET] ✅ Project initialized successfully!');
133
136
 
134
- // Ask if user wants to install dependencies
135
- const installDeps = await prompts({
136
- type: 'confirm',
137
- name: 'value',
138
- message: '[ZYKET] Install dependencies now?',
139
- initial: true
140
- });
137
+ // Install dependencies automatically
138
+ console.log('\n[ZYKET] Installing dependencies...');
139
+ await new Promise((resolve, reject) => {
140
+ const npmInstall = spawn('npm', ['install'], {
141
+ cwd: process.cwd(),
142
+ stdio: 'inherit',
143
+ shell: true
144
+ });
141
145
 
142
- if (installDeps.value) {
143
- console.log('\n[ZYKET] Installing dependencies...');
144
- await new Promise((resolve, reject) => {
145
- const npmInstall = spawn('npm', ['install'], {
146
- cwd: process.cwd(),
147
- stdio: 'inherit',
148
- shell: true
149
- });
150
-
151
- npmInstall.on('close', (code) => {
152
- if (code === 0) {
153
- console.log('[ZYKET] ✅ Dependencies installed successfully!');
154
- resolve();
155
- } else {
156
- reject(new Error(`npm install exited with code ${code}`));
157
- }
158
- });
159
-
160
- npmInstall.on('error', (error) => {
161
- reject(error);
162
- });
146
+ npmInstall.on('close', (code) => {
147
+ if (code === 0) {
148
+ console.log('\n[ZYKET] Dependencies installed successfully!');
149
+ resolve();
150
+ } else {
151
+ reject(new Error(`npm install exited with code ${code}`));
152
+ }
163
153
  });
164
154
 
165
- // Ask if user wants to start the project
166
- const startProject = await prompts({
167
- type: 'confirm',
168
- name: 'value',
169
- message: '[ZYKET] Start the project now?',
170
- initial: true
155
+ npmInstall.on('error', (error) => {
156
+ reject(error);
171
157
  });
158
+ });
172
159
 
173
- if (startProject.value) {
174
- console.log('\n[ZYKET] Starting project...\n');
175
- const nodeStart = spawn('node', ['index.js'], {
176
- cwd: process.cwd(),
177
- stdio: 'inherit',
178
- shell: true
179
- });
180
-
181
- nodeStart.on('error', (error) => {
182
- console.error('[ZYKET] Error starting project:', error);
183
- });
184
- } else {
185
- console.log('\n[ZYKET] Run "npm run dev" to start your application.');
186
- console.log('\n[ZYKET] Happy coding! 🚀\n');
187
- }
188
- } else {
189
- console.log('\n[ZYKET] Next steps:');
190
- console.log(' 1. Run: npm install');
191
- console.log(' 2. Review and update your .env file');
192
- console.log(' 3. Run: npm run dev');
193
- console.log('\n[ZYKET] Happy coding! 🚀\n');
194
- }
160
+ // Start the project automatically
161
+ console.log('\n[ZYKET] Starting project...\n');
162
+ const nodeStart = spawn('node', ['index.js'], {
163
+ cwd: process.cwd(),
164
+ stdio: 'inherit',
165
+ shell: true
166
+ });
167
+
168
+ nodeStart.on('error', (error) => {
169
+ console.error('[ZYKET] Error starting project:', error);
170
+ });
195
171
  },
196
172
  'install-template': async () => {
197
173
  const templates = templateManager.getTemplates();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyket",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -3,36 +3,95 @@ const { createClient } = require("redis");
3
3
 
4
4
  module.exports = class Cache extends Service {
5
5
  #container;
6
- client;
6
+ #client;
7
+ #useRedis;
8
+ #memoryCache;
9
+ #expirations;
7
10
 
8
11
  constructor(container, url) {
9
12
  super("cache");
10
13
  this.#container = container;
11
- this.client = createClient({ url });
14
+ // Check if URL is a valid Redis URL (starts with redis://)
15
+ // Empty string, 'memory', or 'in-memory' will use in-memory cache
16
+ this.#useRedis = !!url && url.startsWith('redis://');
17
+
18
+ if (this.#useRedis) {
19
+ this.#client = createClient({ url });
20
+ } else {
21
+ // Use in-memory cache
22
+ this.#memoryCache = new Map();
23
+ this.#expirations = new Map();
24
+ }
12
25
  }
13
26
 
14
27
  async boot() {
15
- await this.client.connect();
28
+ if (this.#useRedis) {
29
+ await this.#client.connect();
30
+ this.#container.get('logger').info('Cache service using Redis');
31
+ } else {
32
+ this.#container.get('logger').info('Cache service using in-memory cache');
33
+ }
16
34
  }
17
35
 
18
36
  async set(key, value) {
19
- return await this.client.set(key, value);
20
-
37
+ if (this.#useRedis) {
38
+ return await this.#client.set(key, value);
39
+ } else {
40
+ this.#memoryCache.set(key, value);
41
+ return 'OK';
42
+ }
21
43
  }
22
44
 
23
45
  async get(key) {
24
- return await this.client.get(key);
46
+ if (this.#useRedis) {
47
+ return await this.#client.get(key);
48
+ } else {
49
+ // Check if the key has expired
50
+ if (this.#expirations.has(key)) {
51
+ const expireTime = this.#expirations.get(key);
52
+ if (Date.now() > expireTime) {
53
+ this.#memoryCache.delete(key);
54
+ this.#expirations.delete(key);
55
+ return null;
56
+ }
57
+ }
58
+ return this.#memoryCache.get(key) || null;
59
+ }
25
60
  }
26
61
 
27
62
  async del(key) {
28
- return await this.client.del(key);
63
+ if (this.#useRedis) {
64
+ return await this.#client.del(key);
65
+ } else {
66
+ this.#expirations.delete(key);
67
+ return this.#memoryCache.delete(key) ? 1 : 0;
68
+ }
29
69
  }
30
70
 
31
71
  async keys(pattern) {
32
- return await this.client.keys(pattern);
72
+ if (this.#useRedis) {
73
+ return await this.#client.keys(pattern);
74
+ } else {
75
+ // Simple pattern matching for memory cache
76
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
77
+ return Array.from(this.#memoryCache.keys()).filter(key => regex.test(key));
78
+ }
33
79
  }
34
80
 
35
81
  async expire(key, seconds) {
36
- return await this.client.expire(key, seconds);
82
+ if (this.#useRedis) {
83
+ return await this.#client.expire(key, seconds);
84
+ } else {
85
+ if (this.#memoryCache.has(key)) {
86
+ const expireTime = Date.now() + (seconds * 1000);
87
+ this.#expirations.set(key, expireTime);
88
+ return 1;
89
+ }
90
+ return 0;
91
+ }
92
+ }
93
+
94
+ get client() {
95
+ return this.#useRedis ? this.#client : null;
37
96
  }
38
97
  }
@@ -8,8 +8,7 @@ const EventService = require("./events");
8
8
 
9
9
  const eventsActivated = process.env.DISABLE_EVENTS !== 'true';
10
10
  const databaseActivated = !!process.env.DATABASE_URL;
11
- const cacheActivated = !!process.env.CACHE_URL;
12
- const bullmqActivated = !!process.env.CACHE_URL && process.env.DISABLE_BULLMQ !== 'true';
11
+ const bullmqActivated = process.env.DISABLE_BULLMQ !== 'true';
13
12
  const s3Activated = process.env.S3_ENDPOINT && process.env.S3_ACCESS_KEY && process.env.S3_SECRET_KEY;
14
13
  const schedulerActivated = process.env.DISABLE_SCHEDULER !== 'true';
15
14
  const socketActivated = process.env.DISABLE_SOCKET !== 'true';
@@ -21,7 +20,7 @@ module.exports = [
21
20
  ["template-manager", require("./template-manager"), []],
22
21
  eventsActivated ? ["events", EventService, ["@service_container"]] : null,
23
22
  databaseActivated ? ["database", Database, ["@service_container", process.env.DATABASE_URL]] : null,
24
- cacheActivated ? ["cache", Cache, ["@service_container", process.env.CACHE_URL]] : null,
23
+ ["cache", Cache, ["@service_container", process.env.CACHE_URL || '']],
25
24
  s3Activated ? ["s3", S3, ["@service_container", process.env.S3_ENDPOINT, process.env.S3_PORT, process.env.S3_USE_SSL === "true", process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY]] : null,
26
25
  schedulerActivated ? ["scheduler", Scheduler, ["@service_container"]] : null,
27
26
  bullmqActivated ? ["bullmq", require("./bullmq"), ["@service_container"]] : null,
@@ -12,6 +12,9 @@ module.exports = class EnvManager {
12
12
  }
13
13
 
14
14
  static getDefaultSecrets() {
15
+ const header = `# Zyket Environment Configuration
16
+ # CACHE_URL: Leave empty or set to 'memory' for in-memory cache, or 'redis://localhost:6379' for Redis
17
+ `;
15
18
  const envsToCreate = {
16
19
  DEBUG: true,
17
20
  PORT: 3000,
@@ -35,7 +38,7 @@ module.exports = class EnvManager {
35
38
  DISABLE_VITE: true,
36
39
  }
37
40
 
38
- return Object.entries(envsToCreate).reduce((acc, [key, value]) => {
41
+ return header + Object.entries(envsToCreate).reduce((acc, [key, value]) => {
39
42
  return `${acc}${key}=${value}\n`;
40
43
  }, "");
41
44
  }