@solcreek/cli 0.4.2 → 0.4.3

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.
@@ -58,6 +58,45 @@ export const devCommand = defineCommand({
58
58
  await server.stop();
59
59
  process.exit(1);
60
60
  }
61
+ // Interactive trigger commands (only if cron/queue configured)
62
+ if (config.cron.length > 0 || config.queue) {
63
+ const { createInterface } = await import("node:readline");
64
+ const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: false });
65
+ rl.on("line", async (line) => {
66
+ const input = line.trim();
67
+ if (!input)
68
+ return;
69
+ if (input === "cron" && config.cron.length > 0) {
70
+ try {
71
+ await server.triggerScheduled();
72
+ consola.success("Triggered scheduled()");
73
+ }
74
+ catch (e) {
75
+ consola.error(`scheduled() error: ${e.message}`);
76
+ }
77
+ return;
78
+ }
79
+ if (input.startsWith("queue ") && config.queue) {
80
+ const payload = input.slice(6).trim();
81
+ let parsed = payload;
82
+ try {
83
+ parsed = JSON.parse(payload);
84
+ }
85
+ catch {
86
+ // Not JSON, send as string
87
+ }
88
+ try {
89
+ await server.sendQueueMessage(parsed);
90
+ consola.success(`Sent message to queue()`);
91
+ }
92
+ catch (e) {
93
+ consola.error(`queue() error: ${e.message}`);
94
+ }
95
+ return;
96
+ }
97
+ consola.warn(`Unknown command: ${input}`);
98
+ });
99
+ }
61
100
  },
62
101
  });
63
102
  //# sourceMappingURL=dev.js.map
@@ -0,0 +1,2 @@
1
+ export declare const queueCommand: import("citty").CommandDef<import("citty").ArgsDef>;
2
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1,92 @@
1
+ import { defineCommand } from "citty";
2
+ import consola from "consola";
3
+ import { CreekClient, parseConfig } from "@solcreek/sdk";
4
+ import { getToken, getApiUrl } from "../utils/config.js";
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { globalArgs, resolveJsonMode, jsonOutput } from "../utils/output.js";
8
+ function getProjectSlug() {
9
+ const configPath = join(process.cwd(), "creek.toml");
10
+ if (!existsSync(configPath)) {
11
+ consola.error("No creek.toml found. Run `creek init` first.");
12
+ process.exit(1);
13
+ }
14
+ return parseConfig(readFileSync(configPath, "utf-8")).project.name;
15
+ }
16
+ function getClient() {
17
+ const token = getToken();
18
+ if (!token) {
19
+ consola.error("Not authenticated. Run `creek login` first.");
20
+ process.exit(1);
21
+ }
22
+ return new CreekClient(getApiUrl(), token);
23
+ }
24
+ const queueSend = defineCommand({
25
+ meta: { name: "send", description: "Send a message to the project's queue" },
26
+ args: {
27
+ message: {
28
+ type: "positional",
29
+ description: "Message body (string, or use --json for JSON content)",
30
+ required: true,
31
+ },
32
+ parseJson: {
33
+ type: "boolean",
34
+ alias: "j",
35
+ description: "Parse message as JSON",
36
+ default: false,
37
+ },
38
+ project: {
39
+ type: "string",
40
+ description: "Project slug (defaults to current creek.toml)",
41
+ },
42
+ ...globalArgs,
43
+ },
44
+ async run({ args }) {
45
+ const jsonMode = resolveJsonMode(args);
46
+ const client = getClient();
47
+ const slug = args.project ?? getProjectSlug();
48
+ let payload = args.message;
49
+ if (args.parseJson) {
50
+ try {
51
+ payload = JSON.parse(args.message);
52
+ }
53
+ catch (err) {
54
+ if (jsonMode) {
55
+ jsonOutput({ ok: false, error: "invalid_json", message: err instanceof Error ? err.message : String(err) }, 1, []);
56
+ }
57
+ consola.error(`Invalid JSON: ${err instanceof Error ? err.message : err}`);
58
+ process.exit(1);
59
+ }
60
+ }
61
+ try {
62
+ const result = await client.sendQueueMessage(slug, payload);
63
+ if (jsonMode) {
64
+ jsonOutput({ ok: true, project: slug, queueId: result.queueId }, 0, [
65
+ { command: `creek deployments --project ${slug}`, description: "View deployment history" },
66
+ ]);
67
+ }
68
+ consola.success(`Sent message to ${slug} queue`);
69
+ }
70
+ catch (err) {
71
+ const msg = err instanceof Error ? err.message : String(err);
72
+ if (jsonMode) {
73
+ jsonOutput({ ok: false, error: "send_failed", message: msg }, 1, [
74
+ { command: `creek status --project ${slug}`, description: "Check project triggers" },
75
+ ]);
76
+ }
77
+ consola.error(`Failed to send: ${msg}`);
78
+ consola.info("Make sure your creek.toml has `queue = true` under [triggers] and the project is deployed.");
79
+ process.exit(1);
80
+ }
81
+ },
82
+ });
83
+ export const queueCommand = defineCommand({
84
+ meta: {
85
+ name: "queue",
86
+ description: "Send messages to the project's queue",
87
+ },
88
+ subCommands: {
89
+ send: queueSend,
90
+ },
91
+ });
92
+ //# sourceMappingURL=queue.js.map
@@ -13,6 +13,10 @@ export declare class DevServer {
13
13
  private proxy;
14
14
  constructor(options: DevServerOptions);
15
15
  start(): Promise<void>;
16
+ /** Trigger the worker's scheduled() handler. */
17
+ triggerScheduled(): Promise<void>;
18
+ /** Send a message to the worker's queue() handler. */
19
+ sendQueueMessage(message: unknown): Promise<void>;
16
20
  stop(): Promise<void>;
17
21
  }
18
22
  //# sourceMappingURL=server.d.ts.map
@@ -47,6 +47,8 @@ export class DevServer {
47
47
  realtimeUrl: `http://127.0.0.1:${this.realtimeServer.getPort()}`,
48
48
  projectSlug: config.projectName,
49
49
  vars: config.vars,
50
+ cron: config.cron,
51
+ queue: config.queue,
50
52
  onRebuild: (ms) => {
51
53
  consola.info(`Worker rebuilt in ${ms}ms`);
52
54
  },
@@ -117,8 +119,38 @@ export class DevServer {
117
119
  }
118
120
  consola.info(`Realtime: ws://localhost:${actualPort}`);
119
121
  consola.info(`Data: .creek/dev/`);
122
+ if (config.cron.length > 0 || config.queue) {
123
+ const triggers = [];
124
+ if (config.cron.length > 0)
125
+ triggers.push(`${config.cron.length} cron`);
126
+ if (config.queue)
127
+ triggers.push("queue");
128
+ consola.info(`Triggers: ${triggers.join(", ")}`);
129
+ }
120
130
  console.log("");
121
131
  consola.success(`Ready in ${elapsed}ms`);
132
+ if (config.cron.length > 0 || config.queue) {
133
+ console.log("");
134
+ consola.info("Trigger commands (type and press Enter):");
135
+ if (config.cron.length > 0) {
136
+ consola.info(" cron Trigger scheduled() handler");
137
+ }
138
+ if (config.queue) {
139
+ consola.info(' queue <message> Send a message to queue() handler');
140
+ }
141
+ }
142
+ }
143
+ /** Trigger the worker's scheduled() handler. */
144
+ async triggerScheduled() {
145
+ if (!this.workerRunner)
146
+ throw new Error("Worker not running");
147
+ await this.workerRunner.triggerScheduled();
148
+ }
149
+ /** Send a message to the worker's queue() handler. */
150
+ async sendQueueMessage(message) {
151
+ if (!this.workerRunner)
152
+ throw new Error("Worker not running");
153
+ await this.workerRunner.sendQueueMessage(message);
122
154
  }
123
155
  async stop() {
124
156
  // Stop in reverse order
@@ -16,6 +16,10 @@ export interface WorkerRunnerOptions {
16
16
  vars?: Record<string, string>;
17
17
  /** Whether the project has client assets (Worker + SPA hybrid). */
18
18
  hasClientAssets?: boolean;
19
+ /** Cron schedules from creek.toml [triggers].cron */
20
+ cron?: string[];
21
+ /** Whether project uses a queue (auto-provisions a local queue) */
22
+ queue?: boolean;
19
23
  /** Callback when worker is rebuilt. */
20
24
  onRebuild?: (durationMs: number) => void;
21
25
  /**
@@ -42,6 +46,10 @@ export declare class WorkerRunner {
42
46
  /** Dispatch a fetch request to the worker (via Miniflare). */
43
47
  dispatchFetch(input: string, init?: RequestInit): Promise<Response>;
44
48
  private buildMiniflareOptions;
49
+ /** Trigger the scheduled() handler manually (for local cron simulation). */
50
+ triggerScheduled(scheduledTime?: number, cron?: string): Promise<Response>;
51
+ /** Send a message to the local queue (consumed by the worker's queue() handler). */
52
+ sendQueueMessage(message: unknown): Promise<void>;
45
53
  private get esbuildOptions();
46
54
  private bundle;
47
55
  private startWatching;
@@ -124,8 +124,37 @@ export class WorkerRunner {
124
124
  opts.r2Buckets = { [r2BindingName]: "creek-dev-r2" };
125
125
  opts.r2Persist = persistDir ? join(persistDir, "r2") : false;
126
126
  }
127
+ // Queue (producer + consumer wired to the same worker)
128
+ if (this.options.queue) {
129
+ opts.queueProducers = { QUEUE: "creek-dev-queue" };
130
+ opts.queueConsumers = {
131
+ "creek-dev-queue": {
132
+ maxBatchSize: 10,
133
+ maxBatchTimeout: 1,
134
+ maxRetries: 3,
135
+ },
136
+ };
137
+ }
127
138
  return opts;
128
139
  }
140
+ /** Trigger the scheduled() handler manually (for local cron simulation). */
141
+ async triggerScheduled(scheduledTime = Date.now(), cron = "* * * * *") {
142
+ if (!this.mf)
143
+ throw new Error("WorkerRunner not started");
144
+ const worker = await this.mf.getWorker();
145
+ const url = `http://placeholder/cdn-cgi/handler/scheduled?time=${scheduledTime}&cron=${encodeURIComponent(cron)}`;
146
+ return worker.fetch(url);
147
+ }
148
+ /** Send a message to the local queue (consumed by the worker's queue() handler). */
149
+ async sendQueueMessage(message) {
150
+ if (!this.mf)
151
+ throw new Error("WorkerRunner not started");
152
+ if (!this.options.queue) {
153
+ throw new Error("Queue is not enabled. Add `queue = true` to [triggers] in creek.toml.");
154
+ }
155
+ const queue = await this.mf.getQueueProducer("QUEUE");
156
+ await queue.send(message);
157
+ }
129
158
  get esbuildOptions() {
130
159
  return {
131
160
  absWorkingDir: this.options.cwd,
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ import { statusCommand } from "./commands/status.js";
17
17
  import { devCommand } from "./commands/dev.js";
18
18
  import { rollbackCommand } from "./commands/rollback.js";
19
19
  import { opsCommand } from "./commands/ops.js";
20
+ import { queueCommand } from "./commands/queue.js";
20
21
  const __dirname = dirname(fileURLToPath(import.meta.url));
21
22
  const cliPkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
22
23
  // Read version from the "creek" facade package (what users install),
@@ -47,6 +48,7 @@ const main = defineCommand({
47
48
  init: initCommand,
48
49
  claim: claimCommand,
49
50
  env: envCommand,
51
+ queue: queueCommand,
50
52
  domains: domainsCommand,
51
53
  rollback: rollbackCommand,
52
54
  ops: opsCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solcreek/cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "CLI for the Creek deployment platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",