@beignet/cli 0.0.37 → 0.0.38
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 +17 -0
- package/README.md +18 -5
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/inspect.js +15 -15
- package/dist/inspect.js.map +1 -1
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +27 -6
- package/dist/lint.js.map +1 -1
- package/dist/make/inbox.js +7 -7
- package/dist/make/inbox.js.map +1 -1
- package/dist/make/payments.d.ts +2 -1
- package/dist/make/payments.d.ts.map +1 -1
- package/dist/make/payments.js +15 -11
- package/dist/make/payments.js.map +1 -1
- package/dist/make/shared.d.ts +1 -1
- package/dist/make/shared.d.ts.map +1 -1
- package/dist/make/shared.js +49 -37
- package/dist/make/shared.js.map +1 -1
- package/dist/make/tenancy.js +8 -8
- package/dist/make/tenancy.js.map +1 -1
- package/dist/make.d.ts.map +1 -1
- package/dist/make.js +27 -16
- package/dist/make.js.map +1 -1
- package/dist/operational-error-reporting.d.ts +15 -0
- package/dist/operational-error-reporting.d.ts.map +1 -0
- package/dist/operational-error-reporting.js +42 -0
- package/dist/operational-error-reporting.js.map +1 -0
- package/dist/outbox.d.ts.map +1 -1
- package/dist/outbox.js +73 -0
- package/dist/outbox.js.map +1 -1
- package/dist/provider-add.js +17 -17
- package/dist/provider-add.js.map +1 -1
- package/dist/provider-audit.js +3 -3
- package/dist/provider-audit.js.map +1 -1
- package/dist/schedule.d.ts.map +1 -1
- package/dist/schedule.js +28 -1
- package/dist/schedule.js.map +1 -1
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +37 -4
- package/dist/task.js.map +1 -1
- package/dist/templates/index.js +2 -2
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/server.d.ts +1 -1
- package/dist/templates/server.d.ts.map +1 -1
- package/dist/templates/server.js +5 -5
- package/dist/templates/server.js.map +1 -1
- package/dist/templates/testing.js +1 -1
- package/dist/templates/todos.js +6 -6
- package/package.json +4 -4
- package/src/config.ts +2 -2
- package/src/inspect.ts +15 -17
- package/src/lint.ts +35 -4
- package/src/make/inbox.ts +7 -7
- package/src/make/payments.ts +23 -15
- package/src/make/shared.ts +56 -40
- package/src/make/tenancy.ts +8 -8
- package/src/make.ts +30 -16
- package/src/operational-error-reporting.ts +60 -0
- package/src/outbox.ts +77 -0
- package/src/provider-add.ts +21 -17
- package/src/provider-audit.ts +3 -3
- package/src/schedule.ts +32 -1
- package/src/task.ts +41 -4
- package/src/templates/index.ts +2 -2
- package/src/templates/server.ts +5 -5
- package/src/templates/testing.ts +1 -1
- package/src/templates/todos.ts +6 -6
package/src/task.ts
CHANGED
|
@@ -3,6 +3,11 @@ import path from "node:path";
|
|
|
3
3
|
import type { TaskDef, TaskRunContextArgs } from "@beignet/core/tasks";
|
|
4
4
|
import { createJiti } from "jiti";
|
|
5
5
|
import { loadBeignetConfig, normalizePath } from "./config.js";
|
|
6
|
+
import {
|
|
7
|
+
flushOperationalErrorReporter,
|
|
8
|
+
type OperationalErrorReportingContext,
|
|
9
|
+
reportOperationalFailure,
|
|
10
|
+
} from "./operational-error-reporting.js";
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Options for running an app-owned operational task.
|
|
@@ -63,10 +68,35 @@ export async function runAppTask(
|
|
|
63
68
|
: {};
|
|
64
69
|
|
|
65
70
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
let output: unknown;
|
|
72
|
+
try {
|
|
73
|
+
output = await runTask(task, {
|
|
74
|
+
input: parsedInput,
|
|
75
|
+
ctx,
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
await reportOperationalFailure({
|
|
79
|
+
ctx: toOperationalContext(ctx),
|
|
80
|
+
error,
|
|
81
|
+
reportOptions: {
|
|
82
|
+
level: "error",
|
|
83
|
+
mechanism: "beignet.task.cli",
|
|
84
|
+
handled: false,
|
|
85
|
+
tags: {
|
|
86
|
+
"beignet.kind": "task",
|
|
87
|
+
"beignet.task": task.name,
|
|
88
|
+
},
|
|
89
|
+
contexts: {
|
|
90
|
+
task: {
|
|
91
|
+
name: task.name,
|
|
92
|
+
tenant: options.tenant ?? null,
|
|
93
|
+
source: "beignet-cli",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
70
100
|
|
|
71
101
|
return {
|
|
72
102
|
schemaVersion: 1,
|
|
@@ -79,10 +109,17 @@ export async function runAppTask(
|
|
|
79
109
|
durationMs: Math.round(performance.now() - startedAt),
|
|
80
110
|
};
|
|
81
111
|
} finally {
|
|
112
|
+
await flushOperationalErrorReporter(toOperationalContext(ctx));
|
|
82
113
|
await taskModule.stopTaskContext?.(ctx, contextArgs);
|
|
83
114
|
}
|
|
84
115
|
}
|
|
85
116
|
|
|
117
|
+
function toOperationalContext(ctx: unknown): OperationalErrorReportingContext {
|
|
118
|
+
return typeof ctx === "object" && ctx !== null
|
|
119
|
+
? (ctx as OperationalErrorReportingContext)
|
|
120
|
+
: {};
|
|
121
|
+
}
|
|
122
|
+
|
|
86
123
|
function parseTaskInputFlag(input: RunAppTaskOptions["input"]): unknown {
|
|
87
124
|
if (input === undefined) return {};
|
|
88
125
|
if (typeof input !== "string") return input;
|
package/src/templates/index.ts
CHANGED
|
@@ -19,8 +19,8 @@ import { dbFiles } from "./db/index.js";
|
|
|
19
19
|
import {
|
|
20
20
|
betterAuth,
|
|
21
21
|
env,
|
|
22
|
-
infrastructurePorts,
|
|
23
22
|
ports,
|
|
23
|
+
portWiring,
|
|
24
24
|
server,
|
|
25
25
|
serverFiles,
|
|
26
26
|
serverProviders,
|
|
@@ -109,7 +109,7 @@ export function getTemplateFiles(ctx: TemplateContext): TemplateFile[] {
|
|
|
109
109
|
},
|
|
110
110
|
{ path: "ports/index.ts", content: ports(ctx) },
|
|
111
111
|
{ path: "ports/auth.ts", content: serverFiles.authPort },
|
|
112
|
-
{ path: "infra/
|
|
112
|
+
{ path: "infra/port-wiring.ts", content: portWiring(ctx) },
|
|
113
113
|
{ path: "infra/db/client.ts", content: db.dbClient },
|
|
114
114
|
{ path: "infra/db/database-ready.ts", content: db.databaseReady },
|
|
115
115
|
{ path: "infra/db/provider.ts", content: db.dbProvider },
|
package/src/templates/server.ts
CHANGED
|
@@ -101,7 +101,7 @@ ${usesResend ? "\tmailer: MailerPort;\n" : ""}${usesUpstash ? "\trateLimit: Rate
|
|
|
101
101
|
`;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export function
|
|
104
|
+
export function portWiring(ctx: TemplateContext): string {
|
|
105
105
|
const deferred = [
|
|
106
106
|
'\t\t"auth",',
|
|
107
107
|
'\t\t"idempotency",',
|
|
@@ -130,13 +130,13 @@ const gate = createGate({
|
|
|
130
130
|
});
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Initial port values the server boots with.
|
|
134
134
|
*
|
|
135
135
|
* Bound ports are app-owned. Every deferred key is contributed by a provider
|
|
136
136
|
* in server/providers.ts during startup; createNextServer(...) fails boot if
|
|
137
137
|
* any of them is still unbound after providers have started.
|
|
138
138
|
*/
|
|
139
|
-
export const
|
|
139
|
+
export const initialPorts = definePorts<AppPorts>()({
|
|
140
140
|
bound: {
|
|
141
141
|
errorReporter: createNoopErrorReporter(),
|
|
142
142
|
gate,
|
|
@@ -290,7 +290,7 @@ import {
|
|
|
290
290
|
createSecurityHeadersHooks,
|
|
291
291
|
} from "@beignet/core/server";
|
|
292
292
|
import type { AppContext } from "@/app-context";
|
|
293
|
-
import {
|
|
293
|
+
import { initialPorts } from "@/infra/port-wiring";
|
|
294
294
|
import { closeDatabaseClient } from "@/infra/db/client";
|
|
295
295
|
import { env } from "@/lib/env";
|
|
296
296
|
import { appContext } from "./context";
|
|
@@ -300,7 +300,7 @@ export const getServer = createNextServerLoader(async () => {
|
|
|
300
300
|
const { providers } = await import("./providers");
|
|
301
301
|
|
|
302
302
|
const server = await createNextServer({
|
|
303
|
-
ports:
|
|
303
|
+
ports: initialPorts,
|
|
304
304
|
providers,
|
|
305
305
|
hooks: [
|
|
306
306
|
createSecurityHeadersHooks<AppContext>(),
|
package/src/templates/testing.ts
CHANGED
|
@@ -536,7 +536,7 @@ async function configuredRoots(cwd: string): Promise<string[]> {
|
|
|
536
536
|
paths.features,
|
|
537
537
|
parentPath(paths.routes),
|
|
538
538
|
parentPath(paths.server),
|
|
539
|
-
parentPath(paths.
|
|
539
|
+
parentPath(paths.portWiring),
|
|
540
540
|
parentPath(paths.ports),
|
|
541
541
|
parentPath(paths.useCaseBuilder),
|
|
542
542
|
parentPath(paths.routesBuilder),
|
package/src/templates/todos.ts
CHANGED
|
@@ -368,7 +368,7 @@ import {
|
|
|
368
368
|
import { createInMemoryDevtools } from "@beignet/devtools";
|
|
369
369
|
import type { AppContext } from "@/app-context";
|
|
370
370
|
import type { TodoRepository } from "@/features/todos/ports";
|
|
371
|
-
import {
|
|
371
|
+
import { initialPorts } from "@/infra/port-wiring";
|
|
372
372
|
import type { AppTransactionPorts } from "@/ports";
|
|
373
373
|
import {
|
|
374
374
|
createTodoUseCase,
|
|
@@ -388,9 +388,9 @@ function createTester(userId: string, todos: TodoRepository) {
|
|
|
388
388
|
session: { id: \`session_\${userId}\` },
|
|
389
389
|
};
|
|
390
390
|
const testFixture = createTestPorts<AppContext["ports"], AppTransactionPorts>({
|
|
391
|
-
base:
|
|
391
|
+
base: initialPorts,
|
|
392
392
|
overrides: {
|
|
393
|
-
gate:
|
|
393
|
+
gate: initialPorts.gate,
|
|
394
394
|
todos,
|
|
395
395
|
devtools: createInMemoryDevtools(),
|
|
396
396
|
},
|
|
@@ -483,7 +483,7 @@ import { createInMemoryDevtools } from "@beignet/devtools";
|
|
|
483
483
|
import { createTestApp, createTestRequester } from "@beignet/web/testing";
|
|
484
484
|
import type { AppContext } from "@/app-context";
|
|
485
485
|
import type { TodoRepository } from "@/features/todos/ports";
|
|
486
|
-
import {
|
|
486
|
+
import { initialPorts } from "@/infra/port-wiring";
|
|
487
487
|
import type { AppPorts, AppTransactionPorts } from "@/ports";
|
|
488
488
|
import type { AuthRequest, AuthSessionMetadata, AuthUser } from "@/ports/auth";
|
|
489
489
|
import { type AppServiceContextInput, appContext } from "@/server/context";
|
|
@@ -507,9 +507,9 @@ async function createTodosTestApp(
|
|
|
507
507
|
) {
|
|
508
508
|
const todos = options.todos ?? createTestTodoRepository();
|
|
509
509
|
const fixture = createTestPorts<AppContext["ports"], AppTransactionPorts>({
|
|
510
|
-
base:
|
|
510
|
+
base: initialPorts,
|
|
511
511
|
overrides: {
|
|
512
|
-
gate:
|
|
512
|
+
gate: initialPorts.gate,
|
|
513
513
|
todos,
|
|
514
514
|
devtools: createInMemoryDevtools(),
|
|
515
515
|
auth: options.auth ?? createSignedOutAuth(),
|