@objectstack/cli 0.7.2 → 0.8.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @objectstack/cli
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 254f290: fix: serve command now detects available ports to avoid conflicts
8
+ refactor: update to use Core v0.8.0 API (kernel.use/bootstrap)
9
+ - @objectstack/spec@0.8.1
10
+ - @objectstack/core@0.8.1
11
+ - @objectstack/plugin-hono-server@0.8.1
12
+
13
+ ## 1.0.0
14
+
15
+ ### Minor Changes
16
+
17
+ - # Upgrade to Zod v4 and Protocol Improvements
18
+
19
+ This release includes a major upgrade to the core validation engine (Zod v4) and aligns all protocol definitions with stricter type safety.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+ - @objectstack/spec@1.0.0
25
+ - @objectstack/core@1.0.0
26
+ - @objectstack/plugin-hono-server@1.0.0
27
+
3
28
  ## 0.7.2
4
29
 
5
30
  ### Patch Changes
package/dist/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  compileCommand
4
- } from "./chunk-RQRAZ23Z.js";
4
+ } from "./chunk-2YXVEYO7.js";
5
5
 
6
6
  // src/bin.ts
7
7
  import { Command as Command5 } from "commander";
@@ -416,14 +416,49 @@ var createCommand = new Command3("create").description("Create a new package, pl
416
416
  import { Command as Command4 } from "commander";
417
417
  import path3 from "path";
418
418
  import fs3 from "fs";
419
+ import net from "net";
419
420
  import chalk4 from "chalk";
420
421
  import { bundleRequire } from "bundle-require";
422
+ var getAvailablePort = async (startPort) => {
423
+ const isPortAvailable = (port2) => {
424
+ return new Promise((resolve) => {
425
+ const server = net.createServer();
426
+ server.once("error", (err) => {
427
+ resolve(false);
428
+ });
429
+ server.once("listening", () => {
430
+ server.close(() => resolve(true));
431
+ });
432
+ server.listen(port2);
433
+ });
434
+ };
435
+ let port = startPort;
436
+ while (!await isPortAvailable(port)) {
437
+ port++;
438
+ if (port > startPort + 100) {
439
+ throw new Error(`Could not find an available port starting from ${startPort}`);
440
+ }
441
+ }
442
+ return port;
443
+ };
421
444
  var serveCommand = new Command4("serve").description("Start ObjectStack server with plugins from configuration").argument("[config]", "Configuration file path", "objectstack.config.ts").option("-p, --port <port>", "Server port", "3000").option("--no-server", "Skip starting HTTP server plugin").action(async (configPath, options) => {
445
+ let port = parseInt(options.port);
446
+ try {
447
+ const availablePort = await getAvailablePort(port);
448
+ if (availablePort !== port) {
449
+ port = availablePort;
450
+ }
451
+ } catch (e) {
452
+ }
422
453
  console.log(chalk4.bold(`
423
454
  \u{1F680} ObjectStack Server`));
424
455
  console.log(chalk4.dim(`------------------------`));
425
456
  console.log(`\u{1F4C2} Config: ${chalk4.blue(configPath)}`);
426
- console.log(`\u{1F310} Port: ${chalk4.blue(options.port)}`);
457
+ if (parseInt(options.port) !== port) {
458
+ console.log(`\u{1F310} Port: ${chalk4.blue(port)} ${chalk4.yellow(`(requested: ${options.port} in use)`)}`);
459
+ } else {
460
+ console.log(`\u{1F310} Port: ${chalk4.blue(port)}`);
461
+ }
427
462
  console.log("");
428
463
  const absolutePath = path3.resolve(process.cwd(), configPath);
429
464
  if (!fs3.existsSync(absolutePath)) {
@@ -441,9 +476,9 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
441
476
  throw new Error(`Default export not found in ${configPath}`);
442
477
  }
443
478
  console.log(chalk4.green(`\u2713 Configuration loaded`));
444
- const { ObjectStackKernel } = await import("@objectstack/core");
479
+ const { ObjectKernel } = await import("@objectstack/core");
445
480
  console.log(chalk4.yellow(`\u{1F527} Initializing ObjectStack kernel...`));
446
- const kernel = new ObjectStackKernel({
481
+ const kernel = new ObjectKernel({
447
482
  metadata: config.metadata || {},
448
483
  objects: config.objects || {}
449
484
  });
@@ -452,7 +487,7 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
452
487
  console.log(chalk4.yellow(`\u{1F4E6} Loading ${plugins.length} plugin(s)...`));
453
488
  for (const plugin of plugins) {
454
489
  try {
455
- kernel.registerPlugin(plugin);
490
+ kernel.use(plugin);
456
491
  const pluginName = plugin.name || plugin.constructor?.name || "unnamed";
457
492
  console.log(chalk4.green(` \u2713 Registered plugin: ${pluginName}`));
458
493
  } catch (e) {
@@ -463,16 +498,16 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
463
498
  if (options.server !== false) {
464
499
  try {
465
500
  const { HonoServerPlugin } = await import("@objectstack/plugin-hono-server");
466
- const serverPlugin = new HonoServerPlugin({ port: parseInt(options.port) });
467
- kernel.registerPlugin(serverPlugin);
468
- console.log(chalk4.green(` \u2713 Registered HTTP server plugin (port: ${options.port})`));
501
+ const serverPlugin = new HonoServerPlugin({ port });
502
+ kernel.use(serverPlugin);
503
+ console.log(chalk4.green(` \u2713 Registered HTTP server plugin (port: ${port})`));
469
504
  } catch (e) {
470
505
  console.warn(chalk4.yellow(` \u26A0 HTTP server plugin not available: ${e.message}`));
471
506
  }
472
507
  }
473
508
  console.log(chalk4.yellow(`
474
509
  \u{1F680} Starting ObjectStack...`));
475
- await kernel.boot();
510
+ await kernel.bootstrap();
476
511
  console.log(chalk4.green(`
477
512
  \u2705 ObjectStack server is running!`));
478
513
  console.log(chalk4.dim(` Press Ctrl+C to stop
@@ -496,7 +531,7 @@ var serveCommand = new Command4("serve").description("Start ObjectStack server w
496
531
 
497
532
  // src/bin.ts
498
533
  var program = new Command5();
499
- program.name("objectstack").description("CLI for ObjectStack Protocol - Development Tools for Microkernel Architecture").version("0.7.1");
534
+ program.name("objectstack").description("CLI for ObjectStack Protocol - Development Tools for Microkernel Architecture").version("0.8.0");
500
535
  program.addCommand(compileCommand);
501
536
  program.addCommand(serveCommand);
502
537
  program.addCommand(devCommand);
@@ -33,7 +33,8 @@ var compileCommand = new Command("compile").description("Compile ObjectStack con
33
33
  if (!result.success) {
34
34
  console.error(chalk.red(`
35
35
  \u274C Validation Failed!`));
36
- result.error.errors.forEach((e) => {
36
+ const error = result.error;
37
+ error.issues.forEach((e) => {
37
38
  console.error(chalk.red(` - [${e.path.join(".")}] ${e.message}`));
38
39
  });
39
40
  process.exit(1);
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  compileCommand
4
- } from "./chunk-RQRAZ23Z.js";
4
+ } from "./chunk-2YXVEYO7.js";
5
5
  export {
6
6
  compileCommand
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/cli",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "description": "Command Line Interface for ObjectStack Protocol",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -21,13 +21,16 @@
21
21
  "chalk": "^5.3.0",
22
22
  "commander": "^11.1.0",
23
23
  "tsx": "^4.7.1",
24
- "zod": "^3.22.4",
25
- "@objectstack/spec": "0.7.2",
26
- "@objectstack/core": "0.7.2",
27
- "@objectstack/plugin-hono-server": "0.7.2"
24
+ "zod": "^4.3.6",
25
+ "@objectstack/spec": "0.8.1",
26
+ "@objectstack/core": "0.8.1",
27
+ "@objectstack/plugin-hono-server": "0.8.1"
28
+ },
29
+ "peerDependencies": {
30
+ "@objectstack/core": "^0.8.1"
28
31
  },
29
32
  "devDependencies": {
30
- "@types/node": "^20.11.19",
33
+ "@types/node": "^25.1.0",
31
34
  "tsup": "^8.0.2",
32
35
  "typescript": "^5.3.3"
33
36
  },
package/src/bin.ts CHANGED
@@ -10,7 +10,7 @@ const program = new Command();
10
10
  program
11
11
  .name('objectstack')
12
12
  .description('CLI for ObjectStack Protocol - Development Tools for Microkernel Architecture')
13
- .version('0.7.1');
13
+ .version('0.8.0');
14
14
 
15
15
  // Add all commands
16
16
  program.addCommand(compileCommand);
@@ -4,6 +4,7 @@ import fs from 'fs';
4
4
  import { pathToFileURL } from 'url';
5
5
  import chalk from 'chalk';
6
6
  import { bundleRequire } from 'bundle-require';
7
+ import { ZodError } from 'zod';
7
8
  import { ObjectStackDefinitionSchema } from '@objectstack/spec';
8
9
 
9
10
  export const compileCommand = new Command('compile')
@@ -42,7 +43,8 @@ export const compileCommand = new Command('compile')
42
43
  if (!result.success) {
43
44
  console.error(chalk.red(`\n❌ Validation Failed!`));
44
45
 
45
- result.error.errors.forEach(e => {
46
+ const error = result.error as ZodError;
47
+ error.issues.forEach((e: any) => {
46
48
  console.error(chalk.red(` - [${e.path.join('.')}] ${e.message}`));
47
49
  });
48
50
 
@@ -1,21 +1,62 @@
1
1
  import { Command } from 'commander';
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
+ import net from 'net';
4
5
  import chalk from 'chalk';
5
6
  import { bundleRequire } from 'bundle-require';
6
7
 
8
+ // Helper to find available port
9
+ const getAvailablePort = async (startPort: number): Promise<number> => {
10
+ const isPortAvailable = (port: number): Promise<boolean> => {
11
+ return new Promise((resolve) => {
12
+ const server = net.createServer();
13
+ server.once('error', (err: any) => {
14
+ resolve(false);
15
+ });
16
+ server.once('listening', () => {
17
+ server.close(() => resolve(true));
18
+ });
19
+ server.listen(port);
20
+ });
21
+ };
22
+
23
+ let port = startPort;
24
+ while (!(await isPortAvailable(port))) {
25
+ port++;
26
+ if (port > startPort + 100) {
27
+ throw new Error(`Could not find an available port starting from ${startPort}`);
28
+ }
29
+ }
30
+ return port;
31
+ };
32
+
7
33
  export const serveCommand = new Command('serve')
8
34
  .description('Start ObjectStack server with plugins from configuration')
9
35
  .argument('[config]', 'Configuration file path', 'objectstack.config.ts')
10
36
  .option('-p, --port <port>', 'Server port', '3000')
11
37
  .option('--no-server', 'Skip starting HTTP server plugin')
12
38
  .action(async (configPath, options) => {
39
+ let port = parseInt(options.port);
40
+ try {
41
+ const availablePort = await getAvailablePort(port);
42
+ if (availablePort !== port) {
43
+ port = availablePort;
44
+ }
45
+ } catch (e) {
46
+ // Ignore error and try with original port, or let it fail later
47
+ }
48
+
13
49
  console.log(chalk.bold(`\n🚀 ObjectStack Server`));
14
50
  console.log(chalk.dim(`------------------------`));
15
51
  console.log(`📂 Config: ${chalk.blue(configPath)}`);
16
- console.log(`🌐 Port: ${chalk.blue(options.port)}`);
52
+ if (parseInt(options.port) !== port) {
53
+ console.log(`🌐 Port: ${chalk.blue(port)} ${chalk.yellow(`(requested: ${options.port} in use)`)}`);
54
+ } else {
55
+ console.log(`🌐 Port: ${chalk.blue(port)}`);
56
+ }
17
57
  console.log('');
18
58
 
59
+
19
60
  const absolutePath = path.resolve(process.cwd(), configPath);
20
61
 
21
62
  if (!fs.existsSync(absolutePath)) {
@@ -39,11 +80,11 @@ export const serveCommand = new Command('serve')
39
80
  console.log(chalk.green(`✓ Configuration loaded`));
40
81
 
41
82
  // Import ObjectStack runtime
42
- const { ObjectStackKernel } = await import('@objectstack/core');
83
+ const { ObjectKernel } = await import('@objectstack/core');
43
84
 
44
85
  // Create kernel instance
45
86
  console.log(chalk.yellow(`🔧 Initializing ObjectStack kernel...`));
46
- const kernel = new ObjectStackKernel({
87
+ const kernel = new ObjectKernel({
47
88
  metadata: config.metadata || {},
48
89
  objects: config.objects || {},
49
90
  });
@@ -56,7 +97,7 @@ export const serveCommand = new Command('serve')
56
97
 
57
98
  for (const plugin of plugins) {
58
99
  try {
59
- kernel.registerPlugin(plugin);
100
+ kernel.use(plugin);
60
101
  const pluginName = plugin.name || plugin.constructor?.name || 'unnamed';
61
102
  console.log(chalk.green(` ✓ Registered plugin: ${pluginName}`));
62
103
  } catch (e: any) {
@@ -69,9 +110,9 @@ export const serveCommand = new Command('serve')
69
110
  if (options.server !== false) {
70
111
  try {
71
112
  const { HonoServerPlugin } = await import('@objectstack/plugin-hono-server');
72
- const serverPlugin = new HonoServerPlugin({ port: parseInt(options.port) });
73
- kernel.registerPlugin(serverPlugin);
74
- console.log(chalk.green(` ✓ Registered HTTP server plugin (port: ${options.port})`));
113
+ const serverPlugin = new HonoServerPlugin({ port });
114
+ kernel.use(serverPlugin);
115
+ console.log(chalk.green(` ✓ Registered HTTP server plugin (port: ${port})`));
75
116
  } catch (e: any) {
76
117
  console.warn(chalk.yellow(` ⚠ HTTP server plugin not available: ${e.message}`));
77
118
  }
@@ -79,7 +120,7 @@ export const serveCommand = new Command('serve')
79
120
 
80
121
  // Boot the kernel
81
122
  console.log(chalk.yellow(`\n🚀 Starting ObjectStack...`));
82
- await kernel.boot();
123
+ await kernel.bootstrap();
83
124
 
84
125
  console.log(chalk.green(`\n✅ ObjectStack server is running!`));
85
126
  console.log(chalk.dim(` Press Ctrl+C to stop\n`));