@stacksjs/actions 0.72.76 → 0.72.78

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/dist/dev/api.js CHANGED
@@ -1,4 +1,4 @@
1
- import{existsSync}from"node:fs";import process from"node:process";import{parseOptions}from"@stacksjs/cli";import{config,overridesReady}from"@stacksjs/config";import{path}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{autoImportsAreStale,generateAutoImportFiles,generateServerAutoImportTypes,injectGlobalAutoImports}from"@stacksjs/server";import{resolveApiHost}from"../helpers/api-host";import{exitWithParent}from"./exit-with-parent";const _options=parseOptions();exitWithParent();await generateServerAutoImportTypes();await overridesReady;const port=Number(process.env.PORT_API)||config.ports?.api||3008,hostname=resolveApiHost(),modelsIndex=path.storagePath("framework/auto-imports/models.ts");if(!existsSync(modelsIndex)||autoImportsAreStale())await generateAutoImportFiles();await injectGlobalAutoImports();try{const typesenseDev=path.appPath("Lib/typesense-dev.ts");if(existsSync(typesenseDev)){const mod=await import(typesenseDev);if(typeof mod.ensureTypesenseRunning==="function")await mod.ensureTypesenseRunning()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] search engine bootstrap skipped: ${err.message}`)}try{const listenerPath=path.appPath("Listener.ts");if(existsSync(listenerPath)){const listener=await import(listenerPath);if(typeof listener.handleEvents==="function")await listener.handleEvents()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] failed to bootstrap event listeners - dispatched events will be ignored: ${err.message}`)}try{const{startModelMigrationWatcher}=await import("./migrate-watcher");startModelMigrationWatcher()}catch(err){const{log}=await import("@stacksjs/cli");log.debug(`[api:dev] auto-migrate watcher not started: ${err.message}`)}function resolveDefaultsCorsPath(){const vendored=path.frameworkPath("defaults/app/Middleware/Cors.ts");if(existsSync(vendored))return vendored;try{return`${Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd()).replace(/package\.json$/,"")}app/Middleware/Cors.ts`}catch{return vendored}}const corsMod=await import(resolveDefaultsCorsPath()),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());const SAFE_REQUEST_ID=/^[a-zA-Z0-9._-]{8,128}$/;route.use(async(request,next)=>{const inbound=request?.headers?.get?.("x-request-id")||request?.headers?.get?.("X-Request-ID")||"",id=typeof inbound==="string"&&SAFE_REQUEST_ID.test(inbound)?inbound:crypto.randomUUID();request._requestId=id;request._startNs=process.hrtime.bigint();const response=await next();if(response&&response.status===404&&(response.headers.get("content-type")||"").includes("json"))try{const body=await response.clone().json();if(body&&(body.message==="Not Found"||body.error==="Not Found")){const url=new URL(request.url),enriched={...body,path:url.pathname,method:request.method,request_id:id},headers=new Headers(response.headers);headers.set("X-Request-ID",id);return new Response(JSON.stringify(enriched),{status:404,headers})}}catch{}return response});await route.importRoutes();disableViewRouting(route.bunRouter);try{await route.serve({port,hostname});console.log(`
1
+ import{existsSync}from"node:fs";import process from"node:process";import{parseOptions}from"@stacksjs/cli";import{config,overridesReady}from"@stacksjs/config";import{path}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{autoImportsAreStale,generateAutoImportFiles,generateServerAutoImportTypes,injectGlobalAutoImports}from"@stacksjs/server";import{resolveApiHost}from"../helpers/api-host";import{exitWithParent}from"./exit-with-parent";const _options=parseOptions();exitWithParent();await generateServerAutoImportTypes();await overridesReady;const port=Number(process.env.PORT_API)||config.ports?.api||3008,hostname=resolveApiHost(),modelsIndex=path.storagePath("framework/auto-imports/models.ts");if(!existsSync(modelsIndex)||autoImportsAreStale())await generateAutoImportFiles();await injectGlobalAutoImports();try{const typesenseDev=path.appPath("Lib/typesense-dev.ts");if(existsSync(typesenseDev)){const mod=await import(typesenseDev);if(typeof mod.ensureTypesenseRunning==="function")await mod.ensureTypesenseRunning()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] search engine bootstrap skipped: ${err.message}`)}try{const listenerPath=path.appPath("Listener.ts");if(existsSync(listenerPath)){const listener=await import(listenerPath);if(typeof listener.handleEvents==="function")await listener.handleEvents()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] failed to bootstrap event listeners - dispatched events will be ignored: ${err.message}`)}try{const{startModelMigrationWatcher}=await import("./migrate-watcher");startModelMigrationWatcher()}catch(err){const{log}=await import("@stacksjs/cli");log.debug(`[api:dev] auto-migrate watcher not started: ${err.message}`)}function resolveDefaultsCorsPath(){const published=path.appPath("Middleware/Cors.ts");if(existsSync(published))return published;const vendored=path.frameworkPath("defaults/app/Middleware/Cors.ts");if(existsSync(vendored))return vendored;try{return`${Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd()).replace(/package\.json$/,"")}app/Middleware/Cors.ts`}catch{return vendored}}const corsMod=await import(resolveDefaultsCorsPath()),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());const SAFE_REQUEST_ID=/^[a-zA-Z0-9._-]{8,128}$/;route.use(async(request,next)=>{const inbound=request?.headers?.get?.("x-request-id")||request?.headers?.get?.("X-Request-ID")||"",id=typeof inbound==="string"&&SAFE_REQUEST_ID.test(inbound)?inbound:crypto.randomUUID();request._requestId=id;request._startNs=process.hrtime.bigint();const response=await next();if(response&&response.status===404&&(response.headers.get("content-type")||"").includes("json"))try{const body=await response.clone().json();if(body&&(body.message==="Not Found"||body.error==="Not Found")){const url=new URL(request.url),enriched={...body,path:url.pathname,method:request.method,request_id:id},headers=new Headers(response.headers);headers.set("X-Request-ID",id);return new Response(JSON.stringify(enriched),{status:404,headers})}}catch{}return response});await route.importRoutes();disableViewRouting(route.bunRouter);try{await route.serve({port,hostname});console.log(`
2
2
  \u279C API server ready: http://${hostname}:${port}
3
3
  `)}catch(err){if((err?.code||err?.errno)==="EADDRINUSE"||String(err?.message||"").includes("EADDRINUSE")){console.error(`
4
4
  [dev/api] Port ${port} is already in use. Kill the other process and re-run \`./buddy dev\`, or set PORT_API to another port.
@@ -1,44 +1,35 @@
1
- import{log}from"@stacksjs/logging";import*as p from"@stacksjs/path";import{get,writeFile}from"@stacksjs/storage";export async function makeCommand(options){const name=options.name;if(!name){log.error("Command name is required");return!1}const commandName=toPascalCase(name),content=generateCommandContent(commandName,options),filePath=p.commandsPath(`${commandName}.ts`);try{await writeFile(filePath,content);log.success(`Created command: ${filePath}`);if(options.register!==!1)await registerCommand(commandName,options.signature||toKebabCase(name));return!0}catch(error){log.error(`Failed to create command: ${error.message}`);return!1}}function generateCommandContent(name,options){const signature=options.signature||toKebabCase(name),description=options.description||`The ${signature} command`;return`import type { CLI } from '@stacksjs/types'
2
- import { log } from '@stacksjs/cli'
1
+ import{log}from"@stacksjs/logging";import*as p from"@stacksjs/path";import{get,writeFile}from"@stacksjs/storage";export async function makeCommand(options){const name=options.name;if(!name){log.error("Command name is required");return!1}const commandName=toPascalCase(name),content=generateCommandContent(commandName,options),filePath=p.commandsPath(`${commandName}.ts`),signature=options.signature||toKebabCase(name);try{await writeFile(filePath,content);log.success(`Created command: ${filePath}`);if(options.register)await registerCommand(commandName,signature);else log.info(`Run it with: buddy ${signature}`);return!0}catch(error){log.error(`Failed to create command: ${error.message}`);return!1}}function generateCommandContent(name,options){const signature=options.signature||toKebabCase(name),description=options.description||`The ${signature} command`;return`import { defineCommand, log } from '@stacksjs/cli'
3
2
 
4
3
  /**
5
4
  * ${name} Command
6
5
  *
7
6
  * ${description}
7
+ *
8
+ * Registered automatically - every file in app/Commands is a command.
8
9
  */
10
+ export default defineCommand({
11
+ name: '${signature}',
12
+ description: '${description}',
13
+ options: {
14
+ '--verbose': { description: 'Enable verbose output', default: false },
15
+ // Add more options here. Their types flow into \`handle\`:
16
+ // '--name <name>': 'Who to greet',
17
+ },
18
+ async handle(options) {
19
+ try {
20
+ if (options.verbose)
21
+ log.info('Running ${signature} command...')
9
22
 
10
- interface ${name}Options {
11
- verbose: boolean
12
- // Add your command options here
13
- }
14
-
15
- export default function (cli: CLI) {
16
- cli
17
- .command('${signature}', '${description}')
18
- .option('--verbose', 'Enable verbose output', { default: false })
19
- // Add more options here
20
- // .option('-n, --name <name>', 'Your name')
21
- .action(async (options: ${name}Options) => {
22
- try {
23
- if (options.verbose) {
24
- log.info('Running ${signature} command...')
25
- }
26
-
27
- log.info('No command logic implemented yet. Update this command action to add behavior.')
28
-
29
- log.success('${signature} completed successfully!')
30
- }
31
- catch (error) {
32
- log.error('${signature} failed:', error)
33
- throw error
34
- }
35
- })
23
+ log.info('No command logic implemented yet. Update this command to add behavior.')
36
24
 
37
- // Handle unknown subcommands
38
- cli.on('${signature}:*', () => {
39
- log.error('Invalid command: %s\\nSee --help for a list of available commands.', cli.args.join(' '))
40
- })
41
- }
42
- `}async function registerCommand(name,signature){const commandsPath=p.appPath("Commands.ts");try{let content=await get(commandsPath);const exportMatch=content.match(/export default \{([\s\S]*)\} satisfies/);if(exportMatch){const existingCommands=exportMatch[1]??"";if(existingCommands.includes(`'${signature}'`)){log.info(`Command '${signature}' already registered in Commands.ts`);return}const newCommand=` '${signature}': '${name}',
43
- `,updatedCommands=`${existingCommands.trimEnd()}
44
- ${newCommand}`;content=content.replace(/export default \{[\s\S]*\} satisfies/,`export default {${updatedCommands}} satisfies`);await writeFile(commandsPath,content);log.success(`Registered command '${signature}' in Commands.ts`)}}catch(error){log.warn(`Could not register command in Commands.ts: ${error.message}`);log.info("You may need to manually add it to app/Commands.ts")}}function toPascalCase(str){return str.replace(/[-_](.)/g,(_,char)=>char.toUpperCase()).replace(/^(.)/,(_,char)=>char.toUpperCase())}function toKebabCase(str){return str.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}
25
+ log.success('${signature} completed successfully!')
26
+ }
27
+ catch (error) {
28
+ log.error('${signature} failed:', error)
29
+ throw error
30
+ }
31
+ },
32
+ })
33
+ `}async function registerCommand(name,signature){const commandsPath=p.appPath("Commands.ts"),patterns=[{match:/export default \{([\s\S]*)\} satisfies/,open:"export default {",close:"} satisfies"},{match:/export default defineCommands\(\{([\s\S]*)\}\)/,open:"export default defineCommands({",close:"})"}];try{const content=await get(commandsPath),pattern=patterns.find((candidate)=>candidate.match.test(content));if(!pattern){log.info(`Command '${signature}' is live without a registry entry.`);return}const existingCommands=content.match(pattern.match)?.[1]??"";if(existingCommands.includes(`'${signature}'`)){log.info(`Command '${signature}' already registered in Commands.ts`);return}const updatedCommands=`${existingCommands.trimEnd()}
34
+ '${signature}': '${name}',
35
+ `;await writeFile(commandsPath,content.replace(pattern.match,`${pattern.open}${updatedCommands}${pattern.close}`));log.success(`Registered command '${signature}' in Commands.ts`)}catch{log.info(`Command '${signature}' is live without a registry entry.`)}}function toPascalCase(str){return str.replace(/[-_](.)/g,(_,char)=>char.toUpperCase()).replace(/^(.)/,(_,char)=>char.toUpperCase())}function toKebabCase(str){return str.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}
package/dist/serve/api.js CHANGED
@@ -1 +1 @@
1
- import{existsSync}from"node:fs";import{dirname,join}from"node:path";import process from"node:process";import{config,overridesReady}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{frameworkPath}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{resolveApiHost}from"../helpers/api-host";function resolveDefaultsFile(rel){const vendored=frameworkPath(`defaults/${rel}`);if(existsSync(vendored))return vendored;try{const pkgJson=Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd());return join(dirname(pkgJson),rel)}catch{return vendored}}await overridesReady;const port=Number(process.env.PORT)||config.ports?.api||3008,hostname=resolveApiHost();log.info("[Stacks API] Starting server...");log.info(`[Stacks API] Environment: ${process.env.APP_ENV||"development"}`);const corsMod=await import(resolveDefaultsFile("app/Middleware/Cors.ts")),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());await route.importRoutes();disableViewRouting(route.bunRouter);const isDeployed=["production","staging","development"].includes((process.env.APP_ENV||"").toLowerCase()),server=await route.serve({port,hostname,reusePort:isDeployed});process.on("SIGTERM",()=>{const graceMs=Number(process.env.SHUTDOWN_GRACE_MS)||15000;setTimeout(()=>process.exit(0),graceMs).unref();Promise.resolve(server?.stop()).then(()=>process.exit(0))});log.info(`[Stacks API] Server running at http://${hostname}:${port}`);
1
+ import{existsSync}from"node:fs";import{dirname,join}from"node:path";import process from"node:process";import{config,overridesReady}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{appPath,frameworkPath}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{resolveApiHost}from"../helpers/api-host";function resolveDefaultsFile(rel){if(rel.startsWith("app/")){const published=appPath(rel.slice(4));if(existsSync(published))return published}const vendored=frameworkPath(`defaults/${rel}`);if(existsSync(vendored))return vendored;try{const pkgJson=Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd());return join(dirname(pkgJson),rel)}catch{return vendored}}await overridesReady;const port=Number(process.env.PORT)||config.ports?.api||3008,hostname=resolveApiHost();log.info("[Stacks API] Starting server...");log.info(`[Stacks API] Environment: ${process.env.APP_ENV||"development"}`);const corsMod=await import(resolveDefaultsFile("app/Middleware/Cors.ts")),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());await route.importRoutes();disableViewRouting(route.bunRouter);const isDeployed=["production","staging","development"].includes((process.env.APP_ENV||"").toLowerCase()),server=await route.serve({port,hostname,reusePort:isDeployed});process.on("SIGTERM",()=>{const graceMs=Number(process.env.SHUTDOWN_GRACE_MS)||15000;setTimeout(()=>process.exit(0),graceMs).unref();Promise.resolve(server?.stop()).then(()=>process.exit(0))});log.info(`[Stacks API] Server running at http://${hostname}:${port}`);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.72.76",
5
+ "version": "0.72.78",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,35 +60,35 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/config": "0.72.76",
63
+ "@stacksjs/config": "0.72.78",
64
64
  "@stacksjs/bumpx": "^0.2.6",
65
65
  "@stacksjs/bunpress": "^0.2.8",
66
66
  "@stacksjs/logsmith": "^0.2.3",
67
- "@stacksjs/registry": "0.72.76",
67
+ "@stacksjs/registry": "0.72.78",
68
68
  "@stacksjs/stx": "^0.2.230",
69
69
  "@stacksjs/ts-cloud": "^0.12.4",
70
70
  "@stacksjs/ts-md": "^0.1.1"
71
71
  },
72
72
  "devDependencies": {
73
- "@stacksjs/api": "0.72.76",
74
- "@stacksjs/cli": "0.72.76",
75
- "@stacksjs/database": "0.72.76",
73
+ "@stacksjs/api": "0.72.78",
74
+ "@stacksjs/cli": "0.72.78",
75
+ "@stacksjs/database": "0.72.78",
76
76
  "@stacksjs/tlsx": "^0.13.2",
77
77
  "better-dx": "^0.2.24",
78
- "@stacksjs/dns": "0.72.76",
79
- "@stacksjs/enums": "0.72.76",
80
- "@stacksjs/env": "0.72.76",
81
- "@stacksjs/error-handling": "0.72.76",
82
- "@stacksjs/image": "0.72.76",
83
- "@stacksjs/logging": "0.72.76",
84
- "@stacksjs/path": "0.72.76",
85
- "@stacksjs/security": "0.72.76",
86
- "@stacksjs/cms": "0.72.76",
87
- "@stacksjs/sites": "0.72.76",
88
- "@stacksjs/storage": "0.72.76",
89
- "@stacksjs/strings": "0.72.76",
90
- "@stacksjs/utils": "0.72.76",
91
- "@stacksjs/validation": "0.72.76"
78
+ "@stacksjs/dns": "0.72.78",
79
+ "@stacksjs/enums": "0.72.78",
80
+ "@stacksjs/env": "0.72.78",
81
+ "@stacksjs/error-handling": "0.72.78",
82
+ "@stacksjs/image": "0.72.78",
83
+ "@stacksjs/logging": "0.72.78",
84
+ "@stacksjs/path": "0.72.78",
85
+ "@stacksjs/security": "0.72.78",
86
+ "@stacksjs/cms": "0.72.78",
87
+ "@stacksjs/sites": "0.72.78",
88
+ "@stacksjs/storage": "0.72.78",
89
+ "@stacksjs/strings": "0.72.78",
90
+ "@stacksjs/utils": "0.72.78",
91
+ "@stacksjs/validation": "0.72.78"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "pickier": "^0.1.58",