@getstrata/cli 2.2.59 → 3.0.4
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 +28 -0
- package/package.json +3 -3
- package/src/bunChildResource.ts +281 -0
- package/src/openapi.ts +59 -48
- package/src/outboxWorker.ts +55 -53
- package/src/queueFailed.ts +60 -59
- package/src/queueWorker.ts +18 -34
- package/src/scaffold/makeFactory.ts +19 -17
- package/src/scaffold/makeListener.ts +30 -8
- package/src/scaffold/makeMigration.ts +4 -3
- package/src/scaffold/makeModel.ts +19 -20
- package/src/scaffold/makeModule.ts +1 -16
- package/src/scaffold/renderModule.ts +57 -64
- package/src/schedule.ts +15 -5
- package/src/spawnBun.ts +2 -26
|
@@ -44,15 +44,16 @@ export { ${moduleIdentifier}Table };
|
|
|
44
44
|
[
|
|
45
45
|
"repository.ts",
|
|
46
46
|
`import { BaseRepository } from "@getstrata/core/database/baseRepository";
|
|
47
|
+
import { defineRepository } from "@getstrata/core/database/definitions";
|
|
47
48
|
import { ${moduleIdentifier}Table } from "./table";
|
|
48
49
|
import type { ${moduleName}Record } from "./types";
|
|
49
50
|
|
|
50
|
-
class ${moduleName}Repository extends BaseRepository<${moduleName}Record, "id"> {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
51
|
+
class ${moduleName}Repository extends BaseRepository<${moduleName}Record, "id"> {}
|
|
52
|
+
const ${moduleIdentifier}Repository = defineRepository({
|
|
53
|
+
name: "${moduleSlug}.repository", table: ${moduleIdentifier}Table, dependencies: [] as const,
|
|
54
|
+
create: binding => new ${moduleName}Repository(binding),
|
|
55
|
+
});
|
|
56
|
+
export { ${moduleIdentifier}Repository };
|
|
56
57
|
export default ${moduleName}Repository;
|
|
57
58
|
`,
|
|
58
59
|
],
|
|
@@ -120,31 +121,20 @@ export default ${moduleName}Policy;
|
|
|
120
121
|
],
|
|
121
122
|
[
|
|
122
123
|
"provider.ts",
|
|
123
|
-
`import
|
|
124
|
+
`import { createServiceToken } from "@getstrata/core/contracts/token";
|
|
125
|
+
import type { ServiceProvider } from "@getstrata/core/contracts/di";
|
|
124
126
|
import { CORE_POLICY_GATE_TOKEN } from "@getstrata/bootstrap/config";
|
|
125
|
-
import ${moduleName}Repository from "./repository";
|
|
126
|
-
import ${moduleName}Service from "./service";
|
|
127
127
|
import ${moduleName}Policy from "./policy";
|
|
128
128
|
|
|
129
|
-
const ${moduleIdentifier}
|
|
130
|
-
const ${moduleIdentifier}ServiceToken = "${moduleSlug}.service";
|
|
131
|
-
const ${moduleIdentifier}PolicyToken = "${moduleSlug}.policy";
|
|
129
|
+
const ${moduleIdentifier}PolicyToken = createServiceToken<${moduleName}Policy>("${moduleSlug}.policy");
|
|
132
130
|
|
|
133
131
|
const ${moduleIdentifier}Provider: ServiceProvider = {
|
|
134
132
|
name: "${moduleSlug}.provider",
|
|
135
133
|
register({ container }) {
|
|
136
|
-
container.singleton(${moduleIdentifier}RepositoryToken, () => new ${moduleName}Repository());
|
|
137
134
|
container.singleton(${moduleIdentifier}PolicyToken, () => new ${moduleName}Policy());
|
|
138
135
|
},
|
|
139
136
|
boot({ container }) {
|
|
140
|
-
container.
|
|
141
|
-
const repository = container.resolve<${moduleName}Repository>(${moduleIdentifier}RepositoryToken);
|
|
142
|
-
return new ${moduleName}Service(repository);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const gate = container.resolve<{ register: (resource: string, policy: unknown) => void }>(
|
|
146
|
-
CORE_POLICY_GATE_TOKEN,
|
|
147
|
-
);
|
|
137
|
+
const gate = container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
148
138
|
gate.register("${moduleSlug}", container.resolve(${moduleIdentifier}PolicyToken));
|
|
149
139
|
},
|
|
150
140
|
};
|
|
@@ -152,8 +142,6 @@ const ${moduleIdentifier}Provider: ServiceProvider = {
|
|
|
152
142
|
export default ${moduleIdentifier}Provider;
|
|
153
143
|
export {
|
|
154
144
|
${moduleIdentifier}PolicyToken,
|
|
155
|
-
${moduleIdentifier}RepositoryToken,
|
|
156
|
-
${moduleIdentifier}ServiceToken,
|
|
157
145
|
};
|
|
158
146
|
`,
|
|
159
147
|
],
|
|
@@ -277,15 +265,15 @@ export type { ${moduleName}Resource };
|
|
|
277
265
|
],
|
|
278
266
|
[
|
|
279
267
|
"controller.ts",
|
|
280
|
-
`import type {
|
|
281
|
-
import {
|
|
268
|
+
`import type { BusinessRequestPorts } from "@getstrata/bootstrap/contracts";
|
|
269
|
+
import type { CachedJson } from "@getstrata/core/contracts/di";
|
|
282
270
|
import { bindRouteModel } from "@getstrata/core/http/routeModelBinding";
|
|
283
271
|
import { buildRequestCacheKey } from "@getstrata/core/http/validation";
|
|
284
|
-
import { securedBindRouteModel } from "@getstrata/core/http/securedRouteModelBinding";
|
|
272
|
+
import {type RouteModelBindingPorts, securedBindRouteModel } from "@getstrata/core/http/securedRouteModelBinding";
|
|
285
273
|
import type { RouteRequest } from "@getstrata/core/http/route";
|
|
286
|
-
import { createdResponse, jsonResponse, noContentResponse
|
|
274
|
+
import { createdResponse, jsonResponse, noContentResponse } from "@getstrata/core/http/response";
|
|
287
275
|
import ${moduleName}Service from "./service";
|
|
288
|
-
import { ${moduleIdentifier}
|
|
276
|
+
import { ${moduleIdentifier}Repository } from "./repository";
|
|
289
277
|
import {
|
|
290
278
|
parseCreate${moduleName}Body,
|
|
291
279
|
parse${moduleName}ListQuery,
|
|
@@ -301,15 +289,21 @@ const ${moduleIdentifier.toUpperCase()}_CACHE_TAG = "${pluralSlug}";
|
|
|
301
289
|
|
|
302
290
|
class ${moduleName}Controller {
|
|
303
291
|
constructor(
|
|
304
|
-
private readonly
|
|
292
|
+
private readonly database: BusinessRequestPorts["database"],
|
|
305
293
|
private readonly cachedJson: CachedJson,
|
|
306
|
-
|
|
294
|
+
binding: RouteModelBindingPorts,
|
|
295
|
+
) {
|
|
296
|
+
this.update=this.bindUpdate(binding);
|
|
297
|
+
this.destroy=this.bindDestroy(binding);
|
|
298
|
+
}
|
|
299
|
+
readonly update:(request:RouteRequest<${moduleName}IdParams>)=>Promise<Response>;
|
|
300
|
+
readonly destroy:(request:RouteRequest<${moduleName}IdParams>)=>Promise<Response>;
|
|
307
301
|
|
|
308
302
|
private get service(): ${moduleName}Service {
|
|
309
|
-
return
|
|
303
|
+
return new ${moduleName}Service(this.database.repository(${moduleIdentifier}Repository));
|
|
310
304
|
}
|
|
311
305
|
|
|
312
|
-
readonly index =
|
|
306
|
+
readonly index = (async (request?: Request) => {
|
|
313
307
|
const query = parse${moduleName}ListQuery(request);
|
|
314
308
|
const cacheKey = buildRequestCacheKey("/${pluralSlug}", request);
|
|
315
309
|
|
|
@@ -324,24 +318,23 @@ class ${moduleName}Controller {
|
|
|
324
318
|
);
|
|
325
319
|
});
|
|
326
320
|
|
|
327
|
-
readonly show =
|
|
321
|
+
readonly show = (
|
|
328
322
|
bindRouteModel(
|
|
329
323
|
"id",
|
|
330
324
|
(id) => this.service.findByIdOrThrow(id),
|
|
331
325
|
async (_request: RouteRequest<${moduleName}IdParams>, record) => {
|
|
332
326
|
return jsonResponse(to${moduleName}Resource(record));
|
|
333
327
|
},
|
|
334
|
-
)
|
|
328
|
+
)
|
|
335
329
|
);
|
|
336
330
|
|
|
337
|
-
readonly store =
|
|
331
|
+
readonly store = (async (request: Request) => {
|
|
338
332
|
const body = await parseCreate${moduleName}Body(request);
|
|
339
333
|
const record = await this.service.create(body);
|
|
340
334
|
return createdResponse(to${moduleName}Resource(record));
|
|
341
335
|
});
|
|
342
336
|
|
|
343
|
-
|
|
344
|
-
securedBindRouteModel(
|
|
337
|
+
private bindUpdate(binding:RouteModelBindingPorts) {return securedBindRouteModel(
|
|
345
338
|
"id",
|
|
346
339
|
(id) => this.service.findByIdOrThrow(id),
|
|
347
340
|
{ resource: "${moduleSlug}", action: "update" },
|
|
@@ -350,11 +343,11 @@ class ${moduleName}Controller {
|
|
|
350
343
|
const updated = await this.service.update(record.id, body);
|
|
351
344
|
return jsonResponse(to${moduleName}Resource(updated));
|
|
352
345
|
},
|
|
353
|
-
|
|
354
|
-
|
|
346
|
+
binding,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
355
349
|
|
|
356
|
-
|
|
357
|
-
securedBindRouteModel(
|
|
350
|
+
private bindDestroy(binding:RouteModelBindingPorts) {return securedBindRouteModel(
|
|
358
351
|
"id",
|
|
359
352
|
(id) => this.service.findByIdOrThrow(id),
|
|
360
353
|
{ resource: "${moduleSlug}", action: "delete" },
|
|
@@ -362,8 +355,9 @@ class ${moduleName}Controller {
|
|
|
362
355
|
await this.service.delete(record.id);
|
|
363
356
|
return noContentResponse();
|
|
364
357
|
},
|
|
365
|
-
|
|
366
|
-
|
|
358
|
+
binding,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
367
361
|
}
|
|
368
362
|
|
|
369
363
|
export default ${moduleName}Controller;
|
|
@@ -372,6 +366,9 @@ export default ${moduleName}Controller;
|
|
|
372
366
|
[
|
|
373
367
|
"routes.ts",
|
|
374
368
|
`import type { HttpKernel } from "@getstrata/bootstrap/httpKernel";
|
|
369
|
+
import type { BusinessRequestPorts } from "@getstrata/bootstrap/contracts";
|
|
370
|
+
import type { RouteRequest } from "@getstrata/core/http/route";
|
|
371
|
+
import type { ${moduleName}IdParams } from "./requests";
|
|
375
372
|
import type { AppDependencies, CachedJson } from "@getstrata/core/contracts/di";
|
|
376
373
|
${withWeb ? 'import { apiPrefix } from "@getstrata/core/runtime/appKeyPrefix";\n' : ""}import ${moduleName}Controller from "./controller";
|
|
377
374
|
|
|
@@ -380,26 +377,27 @@ function create${moduleName}Routes(
|
|
|
380
377
|
cachedJson: CachedJson,
|
|
381
378
|
kernel: HttpKernel,
|
|
382
379
|
) {
|
|
383
|
-
|
|
380
|
+
void dependencies;
|
|
381
|
+
const controller = (ports: BusinessRequestPorts) => new ${moduleName}Controller(ports.database, cachedJson, kernel.routeModelBindingPorts(ports.auth));
|
|
384
382
|
${withWeb ? ` const apiBase = \`\${apiPrefix()}/${pluralSlug}\`;\n` : ""}
|
|
385
383
|
|
|
386
384
|
return {
|
|
387
385
|
${withWeb ? "[apiBase]" : `"/${pluralSlug}"`}: {
|
|
388
|
-
GET: controller.index,
|
|
386
|
+
GET: kernel.wrapApi((request: Request, ports: BusinessRequestPorts) => controller(ports).index(request)),
|
|
389
387
|
POST: kernel.wrapAbility(
|
|
390
388
|
"${pluralSlug}:create",
|
|
391
|
-
controller.store,
|
|
389
|
+
(request: Request, ports: BusinessRequestPorts) => controller(ports).store(request),
|
|
392
390
|
),
|
|
393
391
|
},
|
|
394
392
|
${withWeb ? `[\`\${apiBase}/:id\`]` : `"/${pluralSlug}/:id"`}: {
|
|
395
|
-
GET: controller.show,
|
|
393
|
+
GET: kernel.wrapApi((request: RouteRequest<${moduleName}IdParams>, ports: BusinessRequestPorts) => controller(ports).show(request)),
|
|
396
394
|
PATCH: kernel.wrapAbility(
|
|
397
395
|
"${pluralSlug}:update",
|
|
398
|
-
controller.update,
|
|
396
|
+
(request: RouteRequest<${moduleName}IdParams>, ports: BusinessRequestPorts) => controller(ports).update(request),
|
|
399
397
|
),
|
|
400
398
|
DELETE: kernel.wrapAbility(
|
|
401
399
|
"${pluralSlug}:delete",
|
|
402
|
-
controller.destroy,
|
|
400
|
+
(request: RouteRequest<${moduleName}IdParams>, ports: BusinessRequestPorts) => controller(ports).destroy(request),
|
|
403
401
|
),
|
|
404
402
|
},
|
|
405
403
|
};
|
|
@@ -413,8 +411,6 @@ export { create${moduleName}Routes };
|
|
|
413
411
|
`import { type AppModule } from "@getstrata/bootstrap/contracts";
|
|
414
412
|
import ${moduleName}Controller from "./controller";
|
|
415
413
|
import ${moduleIdentifier}Provider, {
|
|
416
|
-
${moduleIdentifier}RepositoryToken,
|
|
417
|
-
${moduleIdentifier}ServiceToken,
|
|
418
414
|
} from "./provider";
|
|
419
415
|
import { create${moduleName}Routes } from "./routes";${
|
|
420
416
|
withWeb
|
|
@@ -445,8 +441,6 @@ const ${moduleVariable}: AppModule = {
|
|
|
445
441
|
export default ${moduleVariable};
|
|
446
442
|
export {
|
|
447
443
|
${moduleIdentifier}Provider,
|
|
448
|
-
${moduleIdentifier}RepositoryToken,
|
|
449
|
-
${moduleIdentifier}ServiceToken,
|
|
450
444
|
};
|
|
451
445
|
export { ${moduleName}Controller };
|
|
452
446
|
export { parse${moduleName}IdParams, parse${moduleName}ListQuery } from "./requests";
|
|
@@ -461,7 +455,7 @@ export { create${moduleName}Routes } from "./routes";${
|
|
|
461
455
|
export { create${moduleName}WebRoutes } from "./webRoutes";`
|
|
462
456
|
: ""
|
|
463
457
|
}
|
|
464
|
-
export { default as ${moduleName}Repository } from "./repository";
|
|
458
|
+
export { default as ${moduleName}Repository, ${moduleIdentifier}Repository } from "./repository";
|
|
465
459
|
export { default as ${moduleName}Service } from "./service";
|
|
466
460
|
export { ${moduleIdentifier}Table } from "./table";
|
|
467
461
|
export type { ${moduleName}Record } from "./types";
|
|
@@ -485,26 +479,26 @@ export type { ${moduleName}Record } from "./types";
|
|
|
485
479
|
|
|
486
480
|
webFiles.set(
|
|
487
481
|
"webController.ts",
|
|
488
|
-
`import type {
|
|
482
|
+
`import type { BusinessRequestPorts } from "@getstrata/bootstrap/contracts";
|
|
483
|
+
import type { AppDependencies } from "@getstrata/core/contracts/di";
|
|
489
484
|
import { resolveService } from "@getstrata/core/contracts/di";
|
|
490
|
-
import { withErrorHandling } from "@getstrata/core/http/response";
|
|
491
485
|
import { CORE_VIEW_RENDERER_TOKEN, type NamespacedViewRenderer } from "@getstrata/core/view";
|
|
492
|
-
import { ${moduleIdentifier}
|
|
486
|
+
import { ${moduleIdentifier}Repository } from "./repository";
|
|
493
487
|
import { parse${moduleName}ListQuery } from "./requests";
|
|
494
|
-
import
|
|
488
|
+
import ${moduleName}Service from "./service";
|
|
495
489
|
|
|
496
490
|
class ${moduleName}WebController {
|
|
497
|
-
constructor(private readonly dependencies: AppDependencies) {}
|
|
491
|
+
constructor(private readonly dependencies: AppDependencies, private readonly database: BusinessRequestPorts["database"]) {}
|
|
498
492
|
|
|
499
493
|
private get service(): ${moduleName}Service {
|
|
500
|
-
return
|
|
494
|
+
return new ${moduleName}Service(this.database.repository(${moduleIdentifier}Repository));
|
|
501
495
|
}
|
|
502
496
|
|
|
503
497
|
private get views(): NamespacedViewRenderer {
|
|
504
498
|
return resolveService(this.dependencies, CORE_VIEW_RENDERER_TOKEN).namespace("${pluralSlug}");
|
|
505
499
|
}
|
|
506
500
|
|
|
507
|
-
readonly index =
|
|
501
|
+
readonly index = (async (request?: Request) => {
|
|
508
502
|
const query = parse${moduleName}ListQuery(request);
|
|
509
503
|
const result = await this.service.paginate(query);
|
|
510
504
|
|
|
@@ -525,14 +519,13 @@ export default ${moduleName}WebController;
|
|
|
525
519
|
"webRoutes.ts",
|
|
526
520
|
`import type { AppDependencies } from "@getstrata/core/contracts/di";
|
|
527
521
|
import type { HttpKernel } from "@getstrata/bootstrap/httpKernel";
|
|
522
|
+
import type { BusinessRequestPorts } from "@getstrata/bootstrap/contracts";
|
|
528
523
|
import ${moduleName}WebController from "./webController";
|
|
529
524
|
|
|
530
525
|
function create${moduleName}WebRoutes(dependencies: AppDependencies, kernel: HttpKernel) {
|
|
531
|
-
const controller = new ${moduleName}WebController(dependencies);
|
|
532
|
-
|
|
533
526
|
return {
|
|
534
527
|
"/${pluralSlug}": {
|
|
535
|
-
GET: kernel.wrapWebPublicRead(
|
|
528
|
+
GET: kernel.wrapWebPublicRead((request: Request, ports: BusinessRequestPorts) => new ${moduleName}WebController(dependencies, ports.database).index(request)),
|
|
536
529
|
},
|
|
537
530
|
};
|
|
538
531
|
}
|
package/src/schedule.ts
CHANGED
|
@@ -2,9 +2,13 @@ import {
|
|
|
2
2
|
installGracefulShutdownSignals,
|
|
3
3
|
LifecycleCoordinator,
|
|
4
4
|
} from "@getstrata/core/lifecycle/gracefulShutdown";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
runDueScheduledTasks,
|
|
7
|
+
type Schedule,
|
|
8
|
+
type SchedulerRunOptions,
|
|
9
|
+
} from "@getstrata/core/scheduler/schedule";
|
|
6
10
|
|
|
7
|
-
type LoadAppSchedule = () =>
|
|
11
|
+
type LoadAppSchedule = () => Schedule | Promise<Schedule>;
|
|
8
12
|
type CloseScheduledApp = () => void | Promise<void>;
|
|
9
13
|
|
|
10
14
|
function createScheduleRunCommand(
|
|
@@ -12,6 +16,7 @@ function createScheduleRunCommand(
|
|
|
12
16
|
close?: CloseScheduledApp,
|
|
13
17
|
options: {
|
|
14
18
|
lifecycle?: LifecycleCoordinator;
|
|
19
|
+
scheduler?: SchedulerRunOptions;
|
|
15
20
|
flush?: CloseScheduledApp;
|
|
16
21
|
drain?: CloseScheduledApp;
|
|
17
22
|
} = {},
|
|
@@ -58,13 +63,18 @@ function createScheduleRunCommand(
|
|
|
58
63
|
let failure: unknown;
|
|
59
64
|
try {
|
|
60
65
|
execution = (async () => {
|
|
61
|
-
await loadSchedule();
|
|
66
|
+
const schedule = await loadSchedule();
|
|
67
|
+
if (!schedule || typeof schedule.dueTasks !== "function")
|
|
68
|
+
throw new TypeError("Schedule boot must return its application-owned Schedule.");
|
|
62
69
|
if (stopping) return;
|
|
63
|
-
const due =
|
|
70
|
+
const due = schedule.dueTasks();
|
|
64
71
|
if (due.length === 0) console.log("No scheduled tasks due.");
|
|
65
72
|
else {
|
|
66
73
|
for (const task of due) console.log(`Running scheduled task: ${task.name}`);
|
|
67
|
-
await runDueScheduledTasks(
|
|
74
|
+
await runDueScheduledTasks(schedule, new Date(), {
|
|
75
|
+
...options.scheduler,
|
|
76
|
+
signal: admission.signal,
|
|
77
|
+
});
|
|
68
78
|
}
|
|
69
79
|
})();
|
|
70
80
|
await execution;
|
package/src/spawnBun.ts
CHANGED
|
@@ -1,32 +1,8 @@
|
|
|
1
|
+
import { bunExecutable, createBunChildSupervisor } from "./bunChildResource.ts";
|
|
1
2
|
import type { StrataAppConfig } from "./types.ts";
|
|
2
3
|
|
|
3
|
-
function bunExecutable(): string {
|
|
4
|
-
return process.execPath.includes("bun") ? process.execPath : "bun";
|
|
5
|
-
}
|
|
6
|
-
|
|
7
4
|
async function spawnBun(app: StrataAppConfig, bunArgs: string[]): Promise<number> {
|
|
8
|
-
|
|
9
|
-
cwd: app.root,
|
|
10
|
-
stdout: "inherit",
|
|
11
|
-
stderr: "inherit",
|
|
12
|
-
stdin: "inherit",
|
|
13
|
-
env: process.env,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// The CLI owns this child. A container signals its supervisor, not the server.
|
|
17
|
-
const signals = ["SIGINT", "SIGTERM"] as const;
|
|
18
|
-
const relays = signals.map((signal) => {
|
|
19
|
-
const relay = () => {
|
|
20
|
-
if (proc.exitCode === null) proc.kill(signal);
|
|
21
|
-
};
|
|
22
|
-
process.on(signal, relay);
|
|
23
|
-
return () => process.off(signal, relay);
|
|
24
|
-
});
|
|
25
|
-
try {
|
|
26
|
-
return await proc.exited;
|
|
27
|
-
} finally {
|
|
28
|
-
for (const remove of relays) remove();
|
|
29
|
-
}
|
|
5
|
+
return await createBunChildSupervisor(app, bunArgs).run();
|
|
30
6
|
}
|
|
31
7
|
|
|
32
8
|
export { bunExecutable, spawnBun };
|