@objectstack/cli 4.0.4 → 4.1.0
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 +44 -25
- package/dist/commands/build.d.ts +5 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +6 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/cloud/login.d.ts +16 -0
- package/dist/commands/cloud/login.d.ts.map +1 -0
- package/dist/commands/cloud/login.js +166 -0
- package/dist/commands/cloud/login.js.map +1 -0
- package/dist/commands/cloud/logout.d.ts +15 -0
- package/dist/commands/cloud/logout.d.ts.map +1 -0
- package/dist/commands/cloud/logout.js +51 -0
- package/dist/commands/cloud/logout.js.map +1 -0
- package/dist/commands/cloud/whoami.d.ts +15 -0
- package/dist/commands/cloud/whoami.d.ts.map +1 -0
- package/dist/commands/cloud/whoami.js +81 -0
- package/dist/commands/cloud/whoami.js.map +1 -0
- package/dist/commands/compile.d.ts +3 -0
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +128 -6
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/create.js +1 -1
- package/dist/commands/data/create.js +2 -2
- package/dist/commands/data/create.js.map +1 -1
- package/dist/commands/data/delete.js +2 -2
- package/dist/commands/data/delete.js.map +1 -1
- package/dist/commands/data/get.js +2 -2
- package/dist/commands/data/get.js.map +1 -1
- package/dist/commands/data/query.js +2 -2
- package/dist/commands/data/query.js.map +1 -1
- package/dist/commands/data/update.js +2 -2
- package/dist/commands/data/update.js.map +1 -1
- package/dist/commands/dev.d.ts +9 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +116 -22
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/generate.js +9 -9
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/i18n/check.d.ts +18 -0
- package/dist/commands/i18n/check.d.ts.map +1 -0
- package/dist/commands/i18n/check.js +153 -0
- package/dist/commands/i18n/check.js.map +1 -0
- package/dist/commands/init.js +2 -2
- package/dist/commands/lint.d.ts +3 -0
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +24 -0
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/login.d.ts +17 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +313 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/{auth/logout.js → logout.js} +14 -2
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/meta/delete.js +2 -2
- package/dist/commands/meta/delete.js.map +1 -1
- package/dist/commands/meta/get.js +2 -2
- package/dist/commands/meta/get.js.map +1 -1
- package/dist/commands/meta/list.js +2 -2
- package/dist/commands/meta/list.js.map +1 -1
- package/dist/commands/meta/register.js +2 -2
- package/dist/commands/meta/register.js.map +1 -1
- package/dist/commands/package/publish.d.ts +32 -0
- package/dist/commands/package/publish.d.ts.map +1 -0
- package/dist/commands/package/publish.js +324 -0
- package/dist/commands/package/publish.js.map +1 -0
- package/dist/commands/projects/bind.d.ts +30 -0
- package/dist/commands/projects/bind.d.ts.map +1 -0
- package/dist/commands/projects/bind.js +132 -0
- package/dist/commands/projects/bind.js.map +1 -0
- package/dist/commands/projects/create.d.ts +28 -0
- package/dist/commands/projects/create.d.ts.map +1 -0
- package/dist/commands/projects/create.js +120 -0
- package/dist/commands/projects/create.js.map +1 -0
- package/dist/commands/projects/list.d.ts +21 -0
- package/dist/commands/projects/list.d.ts.map +1 -0
- package/dist/commands/projects/list.js +79 -0
- package/dist/commands/projects/list.js.map +1 -0
- package/dist/commands/projects/projects.test.d.ts +2 -0
- package/dist/commands/projects/projects.test.d.ts.map +1 -0
- package/dist/commands/projects/projects.test.js +56 -0
- package/dist/commands/projects/projects.test.js.map +1 -0
- package/dist/commands/projects/show.d.ts +21 -0
- package/dist/commands/projects/show.d.ts.map +1 -0
- package/dist/commands/projects/show.js +72 -0
- package/dist/commands/projects/show.js.map +1 -0
- package/dist/commands/projects/switch.d.ts +24 -0
- package/dist/commands/projects/switch.d.ts.map +1 -0
- package/dist/commands/projects/switch.js +64 -0
- package/dist/commands/projects/switch.js.map +1 -0
- package/dist/commands/publish.d.ts +17 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +135 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/{auth/login.d.ts → register.d.ts} +3 -2
- package/dist/commands/register.d.ts.map +1 -0
- package/dist/commands/{auth/login.js → register.js} +44 -61
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/rollback.d.ts +13 -0
- package/dist/commands/rollback.d.ts.map +1 -0
- package/dist/commands/rollback.js +77 -0
- package/dist/commands/rollback.js.map +1 -0
- package/dist/commands/serve.d.ts +22 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +1173 -58
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/start.d.ts +18 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +112 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/{auth/whoami.js → whoami.js} +5 -5
- package/dist/commands/whoami.js.map +1 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/account.d.ts +31 -0
- package/dist/utils/account.d.ts.map +1 -0
- package/dist/utils/account.js +154 -0
- package/dist/utils/account.js.map +1 -0
- package/dist/utils/api-client.d.ts +10 -4
- package/dist/utils/api-client.d.ts.map +1 -1
- package/dist/utils/api-client.js +13 -7
- package/dist/utils/api-client.js.map +1 -1
- package/dist/utils/auth-config.d.ts +6 -0
- package/dist/utils/auth-config.d.ts.map +1 -1
- package/dist/utils/auth-config.js.map +1 -1
- package/dist/utils/auth-flows.d.ts +31 -0
- package/dist/utils/auth-flows.d.ts.map +1 -0
- package/dist/utils/auth-flows.js +151 -0
- package/dist/utils/auth-flows.js.map +1 -0
- package/dist/utils/build-runtime.d.ts +45 -0
- package/dist/utils/build-runtime.d.ts.map +1 -0
- package/dist/utils/build-runtime.js +154 -0
- package/dist/utils/build-runtime.js.map +1 -0
- package/dist/utils/cloud-config.d.ts +24 -0
- package/dist/utils/cloud-config.d.ts.map +1 -0
- package/dist/utils/cloud-config.js +75 -0
- package/dist/utils/cloud-config.js.map +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +17 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/console.d.ts +33 -0
- package/dist/utils/console.d.ts.map +1 -0
- package/dist/utils/console.js +172 -0
- package/dist/utils/console.js.map +1 -0
- package/dist/utils/extract-hook-body.d.ts +13 -0
- package/dist/utils/extract-hook-body.d.ts.map +1 -0
- package/dist/utils/extract-hook-body.js +175 -0
- package/dist/utils/extract-hook-body.js.map +1 -0
- package/dist/utils/format.d.ts +8 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +15 -2
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/i18n-coverage.d.ts +61 -0
- package/dist/utils/i18n-coverage.d.ts.map +1 -0
- package/dist/utils/i18n-coverage.js +176 -0
- package/dist/utils/i18n-coverage.js.map +1 -0
- package/dist/utils/lower-callables.d.ts +17 -0
- package/dist/utils/lower-callables.d.ts.map +1 -0
- package/dist/utils/lower-callables.js +181 -0
- package/dist/utils/lower-callables.js.map +1 -0
- package/dist/utils/plugin-detection.d.ts +1 -0
- package/dist/utils/plugin-detection.d.ts.map +1 -1
- package/dist/utils/plugin-detection.js +41 -0
- package/dist/utils/plugin-detection.js.map +1 -1
- package/dist/utils/studio.d.ts +1 -0
- package/dist/utils/studio.d.ts.map +1 -1
- package/dist/utils/studio.js +24 -9
- package/dist/utils/studio.js.map +1 -1
- package/package.json +60 -22
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -821
- package/bin/run-dev.js +0 -5
- package/dist/commands/auth/login.d.ts.map +0 -1
- package/dist/commands/auth/login.js.map +0 -1
- package/dist/commands/auth/logout.d.ts.map +0 -1
- package/dist/commands/auth/logout.js.map +0 -1
- package/dist/commands/auth/whoami.d.ts.map +0 -1
- package/dist/commands/auth/whoami.js.map +0 -1
- package/dist/commands/codemod/v2-to-v3.d.ts +0 -10
- package/dist/commands/codemod/v2-to-v3.d.ts.map +0 -1
- package/dist/commands/codemod/v2-to-v3.js +0 -145
- package/dist/commands/codemod/v2-to-v3.js.map +0 -1
- package/dist/commands/plugin/add.d.ts +0 -22
- package/dist/commands/plugin/add.d.ts.map +0 -1
- package/dist/commands/plugin/add.js +0 -93
- package/dist/commands/plugin/add.js.map +0 -1
- package/dist/commands/plugin/build.d.ts +0 -29
- package/dist/commands/plugin/build.d.ts.map +0 -1
- package/dist/commands/plugin/build.js +0 -170
- package/dist/commands/plugin/build.js.map +0 -1
- package/dist/commands/plugin/info.d.ts +0 -10
- package/dist/commands/plugin/info.d.ts.map +0 -1
- package/dist/commands/plugin/info.js +0 -65
- package/dist/commands/plugin/info.js.map +0 -1
- package/dist/commands/plugin/list.d.ts +0 -13
- package/dist/commands/plugin/list.d.ts.map +0 -1
- package/dist/commands/plugin/list.js +0 -78
- package/dist/commands/plugin/list.js.map +0 -1
- package/dist/commands/plugin/publish.d.ts +0 -27
- package/dist/commands/plugin/publish.d.ts.map +0 -1
- package/dist/commands/plugin/publish.js +0 -152
- package/dist/commands/plugin/publish.js.map +0 -1
- package/dist/commands/plugin/remove.d.ts +0 -20
- package/dist/commands/plugin/remove.d.ts.map +0 -1
- package/dist/commands/plugin/remove.js +0 -79
- package/dist/commands/plugin/remove.js.map +0 -1
- package/dist/commands/plugin/validate.d.ts +0 -23
- package/dist/commands/plugin/validate.d.ts.map +0 -1
- package/dist/commands/plugin/validate.js +0 -251
- package/dist/commands/plugin/validate.js.map +0 -1
- package/src/bin.ts +0 -13
- package/src/commands/auth/login.ts +0 -188
- package/src/commands/auth/logout.ts +0 -51
- package/src/commands/auth/whoami.ts +0 -85
- package/src/commands/codemod/v2-to-v3.ts +0 -171
- package/src/commands/compile.ts +0 -114
- package/src/commands/create.ts +0 -281
- package/src/commands/data/create.ts +0 -110
- package/src/commands/data/delete.ts +0 -84
- package/src/commands/data/get.ts +0 -84
- package/src/commands/data/query.ts +0 -127
- package/src/commands/data/update.ts +0 -114
- package/src/commands/dev.ts +0 -83
- package/src/commands/diff.ts +0 -294
- package/src/commands/doctor.ts +0 -572
- package/src/commands/explain.ts +0 -412
- package/src/commands/generate.ts +0 -924
- package/src/commands/info.ts +0 -124
- package/src/commands/init.ts +0 -327
- package/src/commands/lint.ts +0 -315
- package/src/commands/meta/delete.ts +0 -79
- package/src/commands/meta/get.ts +0 -73
- package/src/commands/meta/list.ts +0 -105
- package/src/commands/meta/register.ts +0 -97
- package/src/commands/plugin/add.ts +0 -112
- package/src/commands/plugin/build.ts +0 -193
- package/src/commands/plugin/info.ts +0 -79
- package/src/commands/plugin/list.ts +0 -93
- package/src/commands/plugin/publish.ts +0 -176
- package/src/commands/plugin/remove.ts +0 -97
- package/src/commands/plugin/validate.ts +0 -268
- package/src/commands/serve.ts +0 -411
- package/src/commands/studio.ts +0 -52
- package/src/commands/test.ts +0 -135
- package/src/commands/validate.ts +0 -143
- package/src/index.ts +0 -22
- package/src/utils/api-client.ts +0 -88
- package/src/utils/auth-config.ts +0 -107
- package/src/utils/config.ts +0 -80
- package/src/utils/format.ts +0 -267
- package/src/utils/output-formatter.ts +0 -91
- package/src/utils/plugin-detection.ts +0 -16
- package/src/utils/plugin-helpers.ts +0 -37
- package/src/utils/studio.ts +0 -350
- package/test/commands.test.ts +0 -128
- package/test/create.test.ts +0 -25
- package/test/plugin-commands.test.ts +0 -44
- package/test/plugin.test.ts +0 -169
- package/test/remote-api-commands.test.ts +0 -188
- package/test/remote-api-utils.test.ts +0 -196
- package/test/serve-host-config.test.ts +0 -77
- package/tsconfig.build.json +0 -20
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -23
- /package/dist/commands/{auth/logout.d.ts → logout.d.ts} +0 -0
- /package/dist/commands/{auth/whoami.d.ts → whoami.d.ts} +0 -0
package/src/commands/serve.ts
DELETED
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { Args, Command, Flags } from '@oclif/core';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import net from 'net';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import { bundleRequire } from 'bundle-require';
|
|
9
|
-
import { loadConfig } from '../utils/config.js';
|
|
10
|
-
import { isHostConfig } from '../utils/plugin-detection.js';
|
|
11
|
-
import {
|
|
12
|
-
printHeader,
|
|
13
|
-
printKV,
|
|
14
|
-
printSuccess,
|
|
15
|
-
printError,
|
|
16
|
-
printStep,
|
|
17
|
-
printInfo,
|
|
18
|
-
printServerReady,
|
|
19
|
-
} from '../utils/format.js';
|
|
20
|
-
import {
|
|
21
|
-
STUDIO_PATH,
|
|
22
|
-
resolveStudioPath,
|
|
23
|
-
hasStudioDist,
|
|
24
|
-
createStudioStaticPlugin,
|
|
25
|
-
} from '../utils/studio.js';
|
|
26
|
-
import dotenvFlow from 'dotenv-flow';
|
|
27
|
-
|
|
28
|
-
// Helper to find available port
|
|
29
|
-
const getAvailablePort = async (startPort: number): Promise<number> => {
|
|
30
|
-
const isPortAvailable = (port: number): Promise<boolean> => {
|
|
31
|
-
return new Promise((resolve) => {
|
|
32
|
-
const server = net.createServer();
|
|
33
|
-
server.once('error', (err: any) => {
|
|
34
|
-
resolve(false);
|
|
35
|
-
});
|
|
36
|
-
server.once('listening', () => {
|
|
37
|
-
server.close(() => resolve(true));
|
|
38
|
-
});
|
|
39
|
-
server.listen(port);
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
let port = startPort;
|
|
44
|
-
while (!(await isPortAvailable(port))) {
|
|
45
|
-
port++;
|
|
46
|
-
if (port > startPort + 100) {
|
|
47
|
-
throw new Error(`Could not find an available port starting from ${startPort}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return port;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default class Serve extends Command {
|
|
54
|
-
static override description = 'Start ObjectStack server with plugins from configuration';
|
|
55
|
-
|
|
56
|
-
static override args = {
|
|
57
|
-
config: Args.string({ description: 'Configuration file path', required: false, default: 'objectstack.config.ts' }),
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
static override flags = {
|
|
61
|
-
port: Flags.string({ char: 'p', description: 'Server port', default: '3000' }),
|
|
62
|
-
dev: Flags.boolean({ description: 'Run in development mode (load devPlugins)' }),
|
|
63
|
-
ui: Flags.boolean({ description: 'Enable Studio UI at /_studio/ (default: true in dev mode)' }),
|
|
64
|
-
server: Flags.boolean({ description: 'Start HTTP server plugin', default: true, allowNo: true }),
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
async run(): Promise<void> {
|
|
68
|
-
const { args, flags } = await this.parse(Serve);
|
|
69
|
-
|
|
70
|
-
let port = parseInt(flags.port);
|
|
71
|
-
try {
|
|
72
|
-
const availablePort = await getAvailablePort(port);
|
|
73
|
-
if (availablePort !== port) {
|
|
74
|
-
port = availablePort;
|
|
75
|
-
}
|
|
76
|
-
} catch (e) {
|
|
77
|
-
// Ignore error and try with original port
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Load .env files following Vite/Next.js convention
|
|
81
|
-
const mode = flags.dev ? 'development'
|
|
82
|
-
: (process.env.NODE_ENV === 'test' ? 'test'
|
|
83
|
-
: (process.env.NODE_ENV || 'production'));
|
|
84
|
-
dotenvFlow.config({ node_env: mode, silent: true });
|
|
85
|
-
|
|
86
|
-
const isDev = flags.dev || process.env.NODE_ENV === 'development';
|
|
87
|
-
|
|
88
|
-
const absolutePath = path.resolve(process.cwd(), args.config!);
|
|
89
|
-
const relativeConfig = path.relative(process.cwd(), absolutePath);
|
|
90
|
-
|
|
91
|
-
if (!fs.existsSync(absolutePath)) {
|
|
92
|
-
printError(`Configuration file not found: ${absolutePath}`);
|
|
93
|
-
console.log(chalk.dim(' Hint: Run `objectstack init` to create a new project'));
|
|
94
|
-
this.exit(1);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Quiet loading — only show a single spinner line
|
|
98
|
-
console.log('');
|
|
99
|
-
console.log(chalk.dim(` Loading ${relativeConfig}...`));
|
|
100
|
-
|
|
101
|
-
// Track loaded plugins for summary
|
|
102
|
-
const loadedPlugins: string[] = [];
|
|
103
|
-
const shortPluginName = (raw: string) => {
|
|
104
|
-
// Map verbose internal IDs to short display names
|
|
105
|
-
if (raw.includes('objectql')) return 'ObjectQL';
|
|
106
|
-
if (raw.includes('driver') && raw.includes('memory')) return 'MemoryDriver';
|
|
107
|
-
if (raw.startsWith('plugin.app.')) return raw.replace('plugin.app.', '').split('.').pop() || raw;
|
|
108
|
-
if (raw.includes('hono')) return 'HonoServer';
|
|
109
|
-
return raw;
|
|
110
|
-
};
|
|
111
|
-
const trackPlugin = (name: string) => { loadedPlugins.push(shortPluginName(name)); };
|
|
112
|
-
|
|
113
|
-
// Save original console/stdout methods — we'll suppress noise during boot
|
|
114
|
-
const originalConsoleLog = console.log;
|
|
115
|
-
const originalConsoleDebug = console.debug;
|
|
116
|
-
const origStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
117
|
-
let bootQuiet = false;
|
|
118
|
-
|
|
119
|
-
const restoreOutput = () => {
|
|
120
|
-
bootQuiet = false;
|
|
121
|
-
process.stdout.write = origStdoutWrite;
|
|
122
|
-
console.log = originalConsoleLog;
|
|
123
|
-
console.debug = originalConsoleDebug;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const portShifted = parseInt(flags.port) !== port;
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
// ── Suppress ALL runtime noise during boot ────────────────────
|
|
130
|
-
// Multiple sources write to stdout during startup:
|
|
131
|
-
// • Pino-pretty (direct process.stdout.write)
|
|
132
|
-
// • ObjectLogger browser fallback (console.log)
|
|
133
|
-
// • SchemaRegistry (console.log)
|
|
134
|
-
// We capture stdout entirely, then restore after runtime.start().
|
|
135
|
-
bootQuiet = true;
|
|
136
|
-
process.stdout.write = (chunk: any, ...rest: any[]) => {
|
|
137
|
-
if (bootQuiet) return true; // swallow
|
|
138
|
-
return (origStdoutWrite as any)(chunk, ...rest);
|
|
139
|
-
};
|
|
140
|
-
console.log = (...args: any[]) => { if (!bootQuiet) originalConsoleLog(...args); };
|
|
141
|
-
console.debug = (...args: any[]) => { if (!bootQuiet) originalConsoleDebug(...args); };
|
|
142
|
-
|
|
143
|
-
// Load configuration
|
|
144
|
-
const { mod } = await bundleRequire({
|
|
145
|
-
filepath: absolutePath,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const config = mod.default || mod;
|
|
149
|
-
|
|
150
|
-
if (!config) {
|
|
151
|
-
throw new Error(`No default export found in ${args.config}`);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Import ObjectStack runtime
|
|
155
|
-
const { Runtime } = await import('@objectstack/runtime');
|
|
156
|
-
|
|
157
|
-
// Set kernel logger to 'silent' — the CLI manages its own output
|
|
158
|
-
const loggerConfig = { level: 'silent' as const };
|
|
159
|
-
|
|
160
|
-
const runtime = new Runtime({
|
|
161
|
-
kernel: {
|
|
162
|
-
logger: loggerConfig
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const kernel = runtime.getKernel();
|
|
166
|
-
|
|
167
|
-
// Load plugins from configuration
|
|
168
|
-
let plugins = config.plugins || [];
|
|
169
|
-
|
|
170
|
-
// Merge devPlugins if in dev mode
|
|
171
|
-
if (flags.dev && config.devPlugins) {
|
|
172
|
-
plugins = [...plugins, ...config.devPlugins];
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// 1. Auto-register ObjectQL Plugin if objects define but plugins missing
|
|
176
|
-
const hasObjectQL = plugins.some((p: any) => p.name?.includes('objectql') || p.constructor?.name?.includes('ObjectQL'));
|
|
177
|
-
if (config.objects && !hasObjectQL) {
|
|
178
|
-
try {
|
|
179
|
-
const { ObjectQLPlugin } = await import('@objectstack/objectql');
|
|
180
|
-
await kernel.use(new ObjectQLPlugin());
|
|
181
|
-
trackPlugin('ObjectQL');
|
|
182
|
-
} catch (e: any) {
|
|
183
|
-
// silent
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 2. Auto-register Memory Driver if in Dev and no driver configured
|
|
188
|
-
const hasDriver = plugins.some((p: any) => p.name?.includes('driver') || p.constructor?.name?.includes('Driver'));
|
|
189
|
-
if (isDev && !hasDriver && config.objects) {
|
|
190
|
-
try {
|
|
191
|
-
const { DriverPlugin } = await import('@objectstack/runtime');
|
|
192
|
-
const { InMemoryDriver } = await import('@objectstack/driver-memory');
|
|
193
|
-
await kernel.use(new DriverPlugin(new InMemoryDriver()));
|
|
194
|
-
trackPlugin('MemoryDriver');
|
|
195
|
-
} catch (e: any) {
|
|
196
|
-
// silent
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// 3. Auto-register AppPlugin if config contains app definitions
|
|
201
|
-
// Skip if config is a host/aggregator config that already contains
|
|
202
|
-
// instantiated plugins — wrapping it would cause duplicate registration
|
|
203
|
-
// and startup failures (e.g. plugin.app.dev-workspace).
|
|
204
|
-
if (!isHostConfig(config) && (config.objects || config.manifest || config.apps)) {
|
|
205
|
-
try {
|
|
206
|
-
const { AppPlugin } = await import('@objectstack/runtime');
|
|
207
|
-
await kernel.use(new AppPlugin(config));
|
|
208
|
-
trackPlugin('App');
|
|
209
|
-
} catch (e: any) {
|
|
210
|
-
// silent
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// 3b. Auto-register I18nServicePlugin if config contains translations/i18n
|
|
215
|
-
// This ensures i18n REST routes work out of the box without manual plugin registration.
|
|
216
|
-
const hasI18nPlugin = plugins.some(
|
|
217
|
-
(p: any) => p.name === 'com.objectstack.service.i18n'
|
|
218
|
-
|| p.constructor?.name === 'I18nServicePlugin'
|
|
219
|
-
);
|
|
220
|
-
const configHasTranslations = (
|
|
221
|
-
(Array.isArray(config.translations) && config.translations.length > 0)
|
|
222
|
-
|| config.i18n
|
|
223
|
-
|| (config.manifest && (
|
|
224
|
-
(Array.isArray(config.manifest.translations) && config.manifest.translations.length > 0)
|
|
225
|
-
|| config.manifest.i18n
|
|
226
|
-
))
|
|
227
|
-
);
|
|
228
|
-
if (!hasI18nPlugin && configHasTranslations) {
|
|
229
|
-
try {
|
|
230
|
-
// Dynamic import with variable to prevent tsc from resolving the optional package
|
|
231
|
-
const i18nPkg = '@objectstack/service-i18n';
|
|
232
|
-
const { I18nServicePlugin } = await import(/* webpackIgnore: true */ i18nPkg);
|
|
233
|
-
const i18nCfg = config.i18n || config.manifest?.i18n || {};
|
|
234
|
-
await kernel.use(new I18nServicePlugin({
|
|
235
|
-
defaultLocale: i18nCfg.defaultLocale,
|
|
236
|
-
fallbackLocale: i18nCfg.fallbackLocale || i18nCfg.defaultLocale || 'en',
|
|
237
|
-
}));
|
|
238
|
-
trackPlugin('I18nService');
|
|
239
|
-
} catch {
|
|
240
|
-
// @objectstack/service-i18n not installed — kernel memory fallback will handle i18n
|
|
241
|
-
}
|
|
242
|
-
} else if (!hasI18nPlugin && !configHasTranslations) {
|
|
243
|
-
// No translations and no explicit i18n plugin — this is fine, kernel fallback works
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Add HTTP server plugin BEFORE config plugins so that the
|
|
247
|
-
// http-server service is available for any plugin that needs it
|
|
248
|
-
// during init/start (e.g. AuthPlugin).
|
|
249
|
-
// Skip if config already contains a HonoServerPlugin to avoid
|
|
250
|
-
// duplicate registration.
|
|
251
|
-
const configHasHonoServer = plugins.some(
|
|
252
|
-
(p: any) => p.name === 'com.objectstack.server.hono' || p.constructor?.name === 'HonoServerPlugin'
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
if (flags.server && !configHasHonoServer) {
|
|
256
|
-
try {
|
|
257
|
-
const { HonoServerPlugin } = await import('@objectstack/plugin-hono-server');
|
|
258
|
-
const serverPlugin = new HonoServerPlugin({ port });
|
|
259
|
-
await kernel.use(serverPlugin);
|
|
260
|
-
trackPlugin('HonoServer');
|
|
261
|
-
} catch (e: any) {
|
|
262
|
-
console.warn(chalk.yellow(` ⚠ HTTP server plugin not available: ${e.message}`));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// 5. Auto-register SetupPlugin BEFORE config plugins so that other
|
|
267
|
-
// plugins (e.g. AuthPlugin) can call setupNav.contribute() during init.
|
|
268
|
-
const hasSetupPlugin = plugins.some(
|
|
269
|
-
(p: any) => p.name === 'com.objectstack.setup' || p.constructor?.name === 'SetupPlugin'
|
|
270
|
-
);
|
|
271
|
-
if (!hasSetupPlugin) {
|
|
272
|
-
try {
|
|
273
|
-
const setupPkg = '@objectstack/plugin-setup';
|
|
274
|
-
const { SetupPlugin } = await import(/* webpackIgnore: true */ setupPkg);
|
|
275
|
-
await kernel.use(new SetupPlugin());
|
|
276
|
-
trackPlugin('Setup');
|
|
277
|
-
} catch {
|
|
278
|
-
// @objectstack/plugin-setup not installed — setup app unavailable
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (plugins.length > 0) {
|
|
283
|
-
for (const plugin of plugins) {
|
|
284
|
-
try {
|
|
285
|
-
let pluginToLoad = plugin;
|
|
286
|
-
|
|
287
|
-
// Resolve string references (package names)
|
|
288
|
-
if (typeof plugin === 'string') {
|
|
289
|
-
try {
|
|
290
|
-
const imported = await import(plugin);
|
|
291
|
-
pluginToLoad = imported.default || imported;
|
|
292
|
-
} catch (importError: any) {
|
|
293
|
-
throw new Error(`Failed to import plugin '${plugin}': ${importError.message}`);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Wrap raw config objects (no init/start) into AppPlugin
|
|
298
|
-
// This handles plugins defined as plain { name, objects, ... } bundles
|
|
299
|
-
if (pluginToLoad && typeof pluginToLoad === 'object' && !pluginToLoad.init) {
|
|
300
|
-
try {
|
|
301
|
-
const { AppPlugin } = await import('@objectstack/runtime');
|
|
302
|
-
pluginToLoad = new AppPlugin(pluginToLoad);
|
|
303
|
-
} catch (e: any) {
|
|
304
|
-
// Fall through to kernel.use which will report the error
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
await kernel.use(pluginToLoad);
|
|
309
|
-
const pluginName = plugin.name || plugin.constructor?.name || 'unnamed';
|
|
310
|
-
trackPlugin(pluginName);
|
|
311
|
-
} catch (e: any) {
|
|
312
|
-
console.error(chalk.red(` ✗ Failed to load plugin: ${e.message}`));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Register REST API and Dispatcher plugins (consume http.server + protocol services)
|
|
318
|
-
if (flags.server) {
|
|
319
|
-
try {
|
|
320
|
-
const { createRestApiPlugin } = await import('@objectstack/rest');
|
|
321
|
-
await kernel.use(createRestApiPlugin());
|
|
322
|
-
trackPlugin('RestAPI');
|
|
323
|
-
} catch (e: any) {
|
|
324
|
-
// @objectstack/rest is optional
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Register Dispatcher plugin (auth, graphql, analytics, packages, hub, storage, automation)
|
|
328
|
-
try {
|
|
329
|
-
const { createDispatcherPlugin } = await import('@objectstack/runtime');
|
|
330
|
-
await kernel.use(createDispatcherPlugin());
|
|
331
|
-
trackPlugin('Dispatcher');
|
|
332
|
-
} catch (e: any) {
|
|
333
|
-
// optional
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// 4. Auto-register AIServicePlugin if not already loaded by config plugins.
|
|
338
|
-
// Registered AFTER Dispatcher so that the ai:routes hook listener is
|
|
339
|
-
// already in place when AIServicePlugin.start() fires the hook.
|
|
340
|
-
const hasAIPlugin = plugins.some(
|
|
341
|
-
(p: any) => p.name === 'com.objectstack.service-ai'
|
|
342
|
-
|| p.constructor?.name === 'AIServicePlugin'
|
|
343
|
-
);
|
|
344
|
-
if (!hasAIPlugin) {
|
|
345
|
-
try {
|
|
346
|
-
const aiPkg = '@objectstack/service-ai';
|
|
347
|
-
const { AIServicePlugin } = await import(/* webpackIgnore: true */ aiPkg);
|
|
348
|
-
|
|
349
|
-
// AIServicePlugin will auto-detect LLM provider from environment variables
|
|
350
|
-
// (AI_GATEWAY_MODEL, OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY)
|
|
351
|
-
// No need to manually construct the adapter here.
|
|
352
|
-
await kernel.use(new AIServicePlugin());
|
|
353
|
-
trackPlugin('AIService');
|
|
354
|
-
} catch {
|
|
355
|
-
// @objectstack/service-ai not installed — AI features unavailable
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// ── Studio UI ─────────────────────────────────────────────────
|
|
360
|
-
// In dev mode, Studio UI is enabled by default (use --no-ui to disable).
|
|
361
|
-
// Always serves the pre-built dist/ — no Vite dev server, no extra port.
|
|
362
|
-
const enableUI = flags.ui || isDev;
|
|
363
|
-
|
|
364
|
-
if (enableUI) {
|
|
365
|
-
const studioPath = resolveStudioPath();
|
|
366
|
-
if (!studioPath) {
|
|
367
|
-
console.warn(chalk.yellow(` ⚠ @objectstack/studio not found — skipping UI`));
|
|
368
|
-
} else if (hasStudioDist(studioPath)) {
|
|
369
|
-
const distPath = path.join(studioPath, 'dist');
|
|
370
|
-
await kernel.use(createStudioStaticPlugin(distPath, { isDev }));
|
|
371
|
-
trackPlugin('StudioUI');
|
|
372
|
-
} else {
|
|
373
|
-
console.warn(chalk.yellow(` ⚠ Studio dist not found — run "pnpm --filter @objectstack/studio build" first`));
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// Boot the runtime
|
|
378
|
-
await runtime.start();
|
|
379
|
-
|
|
380
|
-
// Wait briefly for pino worker thread buffers to flush, then restore
|
|
381
|
-
await new Promise(r => setTimeout(r, 100));
|
|
382
|
-
restoreOutput();
|
|
383
|
-
|
|
384
|
-
// ── Clean startup summary ──────────────────────────────────────
|
|
385
|
-
printServerReady({
|
|
386
|
-
port,
|
|
387
|
-
configFile: relativeConfig,
|
|
388
|
-
isDev,
|
|
389
|
-
pluginCount: loadedPlugins.length,
|
|
390
|
-
pluginNames: loadedPlugins,
|
|
391
|
-
uiEnabled: enableUI,
|
|
392
|
-
studioPath: STUDIO_PATH,
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
// Keep process alive
|
|
396
|
-
process.on('SIGINT', async () => {
|
|
397
|
-
console.warn(chalk.yellow(`\n\n⏹ Stopping server...`));
|
|
398
|
-
await runtime.getKernel().shutdown();
|
|
399
|
-
console.log(chalk.green(`✅ Server stopped`));
|
|
400
|
-
process.exit(0);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
} catch (error: any) {
|
|
404
|
-
restoreOutput();
|
|
405
|
-
console.log('');
|
|
406
|
-
printError(error.message || String(error));
|
|
407
|
-
if (process.env.DEBUG) console.error(chalk.dim(error.stack));
|
|
408
|
-
this.exit(1);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
package/src/commands/studio.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { Args, Command, Flags } from '@oclif/core';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { spawn } from 'child_process';
|
|
6
|
-
import { printHeader, printKV, printStep } from '../utils/format.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `objectstack studio` — Launch the ObjectStack Studio UI.
|
|
10
|
-
*
|
|
11
|
-
* Alias for `objectstack serve --dev --ui`.
|
|
12
|
-
* Starts the ObjectStack server in development mode with the Studio
|
|
13
|
-
* UI available at http://localhost:<port>/_studio/
|
|
14
|
-
*/
|
|
15
|
-
export default class Studio extends Command {
|
|
16
|
-
static override description = 'Launch Studio UI with development server';
|
|
17
|
-
|
|
18
|
-
static override args = {
|
|
19
|
-
config: Args.string({ description: 'Configuration file path', required: false, default: 'objectstack.config.ts' }),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
static override flags = {
|
|
23
|
-
port: Flags.string({ char: 'p', description: 'Server port', default: '3000' }),
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
async run(): Promise<void> {
|
|
27
|
-
const { args, flags } = await this.parse(Studio);
|
|
28
|
-
|
|
29
|
-
printHeader('Studio');
|
|
30
|
-
printKV('Mode', 'dev + ui', '🎨');
|
|
31
|
-
printStep('Delegating to serve --dev --ui …');
|
|
32
|
-
console.log('');
|
|
33
|
-
|
|
34
|
-
// Delegate to the serve command with --dev --ui flags
|
|
35
|
-
const binPath = process.argv[1];
|
|
36
|
-
const spawnArgs = [
|
|
37
|
-
binPath,
|
|
38
|
-
'serve',
|
|
39
|
-
args.config!,
|
|
40
|
-
'--dev',
|
|
41
|
-
'--ui',
|
|
42
|
-
'--port', flags.port,
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
const child = spawn(process.execPath, spawnArgs, {
|
|
46
|
-
stdio: 'inherit',
|
|
47
|
-
env: { ...process.env, NODE_ENV: 'development' },
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
child.on('exit', (code) => process.exit(code ?? 0));
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/commands/test.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { Args, Command, Flags } from '@oclif/core';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import { QA as CoreQA } from '@objectstack/core';
|
|
8
|
-
import { QA } from '@objectstack/spec';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Resolve a glob-like pattern to matching file paths.
|
|
12
|
-
* Supports `*` (single segment wildcard) and `**` (recursive wildcard).
|
|
13
|
-
* Falls back to direct file path if no glob characters are present.
|
|
14
|
-
*/
|
|
15
|
-
function resolveGlob(pattern: string): string[] {
|
|
16
|
-
// Direct file path — no wildcards
|
|
17
|
-
if (!pattern.includes('*')) {
|
|
18
|
-
return fs.existsSync(pattern) ? [pattern] : [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Split pattern into the static base directory and the glob portion
|
|
22
|
-
const parts = pattern.split(path.sep.replace('\\', '/'));
|
|
23
|
-
// Also handle forward-slash on Windows
|
|
24
|
-
const segments = pattern.includes('/') ? pattern.split('/') : parts;
|
|
25
|
-
|
|
26
|
-
let baseDir = '.';
|
|
27
|
-
let globStart = 0;
|
|
28
|
-
for (let i = 0; i < segments.length; i++) {
|
|
29
|
-
if (segments[i].includes('*')) {
|
|
30
|
-
globStart = i;
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
baseDir = i === 0 ? segments[i] : path.join(baseDir, segments[i]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!fs.existsSync(baseDir)) return [];
|
|
37
|
-
|
|
38
|
-
// Convert the glob portion into a RegExp
|
|
39
|
-
const globPortion = segments.slice(globStart).join('/');
|
|
40
|
-
const regexStr = globPortion
|
|
41
|
-
.replace(/\./g, '\\.') // escape dots
|
|
42
|
-
.replace(/\*\*\//g, '(.+/)?') // ** matches any directory depth
|
|
43
|
-
.replace(/\*\*/g, '.*') // trailing ** without slash
|
|
44
|
-
.replace(/\*/g, '[^/]*'); // * matches within a single segment
|
|
45
|
-
const regex = new RegExp(`^${regexStr}$`);
|
|
46
|
-
|
|
47
|
-
// Recursively read all files under baseDir
|
|
48
|
-
const entries = fs.readdirSync(baseDir, { recursive: true, encoding: 'utf-8' }) as string[];
|
|
49
|
-
return entries
|
|
50
|
-
.filter(entry => regex.test(entry.replace(/\\/g, '/')))
|
|
51
|
-
.map(entry => path.join(baseDir, entry))
|
|
52
|
-
.filter(fullPath => fs.statSync(fullPath).isFile());
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default class Test extends Command {
|
|
56
|
-
static override description = 'Run Quality Protocol test scenarios against a running server';
|
|
57
|
-
|
|
58
|
-
static override args = {
|
|
59
|
-
files: Args.string({ description: 'Glob pattern for test files (e.g. "qa/*.test.json")', required: false, default: 'qa/*.test.json' }),
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
static override flags = {
|
|
63
|
-
url: Flags.string({ description: 'Target base URL', default: 'http://localhost:3000' }),
|
|
64
|
-
token: Flags.string({ description: 'Authentication token' }),
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
async run(): Promise<void> {
|
|
68
|
-
const { args, flags } = await this.parse(Test);
|
|
69
|
-
const filesPattern = args.files;
|
|
70
|
-
|
|
71
|
-
console.log(chalk.bold(`\n🧪 ObjectStack Quality Protocol Runner`));
|
|
72
|
-
console.log(chalk.dim(`-------------------------------------`));
|
|
73
|
-
console.log(`Target: ${chalk.blue(flags.url)}`);
|
|
74
|
-
|
|
75
|
-
// 1. Setup Runner
|
|
76
|
-
const adapter = new CoreQA.HttpTestAdapter(flags.url, flags.token);
|
|
77
|
-
const runner = new CoreQA.TestRunner(adapter);
|
|
78
|
-
|
|
79
|
-
// 2. Find test files using glob-style pattern matching
|
|
80
|
-
const testFiles: string[] = resolveGlob(filesPattern);
|
|
81
|
-
|
|
82
|
-
if (testFiles.length === 0) {
|
|
83
|
-
console.warn(chalk.yellow(`No test files found matching: ${filesPattern}`));
|
|
84
|
-
// Create a demo test file if none exist?
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
console.log(`Found ${testFiles.length} test suites.`);
|
|
89
|
-
|
|
90
|
-
// 3. Run Tests
|
|
91
|
-
let totalPassed = 0;
|
|
92
|
-
let totalFailed = 0;
|
|
93
|
-
|
|
94
|
-
for (const file of testFiles) {
|
|
95
|
-
console.log(`\n📄 Running suite: ${chalk.bold(path.basename(file))}`);
|
|
96
|
-
try {
|
|
97
|
-
const content = fs.readFileSync(file, 'utf-8');
|
|
98
|
-
const suite = JSON.parse(content) as QA.TestSuite; // Should validate with Zod
|
|
99
|
-
|
|
100
|
-
const results = await runner.runSuite(suite);
|
|
101
|
-
|
|
102
|
-
for (const result of results) {
|
|
103
|
-
const icon = result.passed ? '✅' : '❌';
|
|
104
|
-
console.log(` ${icon} Scenario: ${result.scenarioId} (${result.duration}ms)`);
|
|
105
|
-
if (!result.passed) {
|
|
106
|
-
console.error(chalk.red(` Error: ${result.error}`));
|
|
107
|
-
result.steps.forEach(step => {
|
|
108
|
-
if (!step.passed) {
|
|
109
|
-
console.error(chalk.red(` Step Failed: ${step.stepName}`));
|
|
110
|
-
if (step.output) console.error(` Output:`, step.output);
|
|
111
|
-
if (step.error) console.error(` Error:`, step.error);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
totalFailed++;
|
|
115
|
-
} else {
|
|
116
|
-
totalPassed++;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
} catch (e) {
|
|
120
|
-
console.error(chalk.red(`Failed to load or run suite ${file}: ${e}`));
|
|
121
|
-
totalFailed++; // Count suite failure
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// 4. Summary
|
|
126
|
-
console.log(chalk.dim(`\n-------------------------------------`));
|
|
127
|
-
if (totalFailed > 0) {
|
|
128
|
-
console.log(chalk.red(`FAILED: ${totalFailed} scenarios failed. ${totalPassed} passed.`));
|
|
129
|
-
process.exit(1);
|
|
130
|
-
} else {
|
|
131
|
-
console.log(chalk.green(`SUCCESS: All ${totalPassed} scenarios passed.`));
|
|
132
|
-
process.exit(0);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|