@cslug/core 0.3.0 → 0.4.1
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/docs/api.md +4 -1
- package/package.json +2 -2
- package/src/application.ts +5 -0
- package/src/command.ts +6 -0
- package/src/index.ts +2 -0
- package/src/provider.ts +9 -1
package/docs/api.md
CHANGED
|
@@ -55,12 +55,15 @@ export class XProvider extends ServiceProvider /* implements ProviderHooks */ {
|
|
|
55
55
|
The hooks and `dependsOn` are not declared on the base class, so apps using `noImplicitOverride` don't need
|
|
56
56
|
`override`. `ProviderHooks` gives the hook signatures for `implements`.
|
|
57
57
|
|
|
58
|
+
In `register()`, `this.commands([...])` contributes `cslug` commands (tag `COMMANDS`) and
|
|
59
|
+
`this.describe('routes', () => data)` a `cslug describe` section (tag `DESCRIBE`, `DescribeSection`).
|
|
60
|
+
|
|
58
61
|
## `Application` (extends `Container`)
|
|
59
62
|
|
|
60
63
|
| | |
|
|
61
64
|
|---|---|
|
|
62
65
|
| `new Application({ root?, configs? })` | `rootDir`, `configs`; the app is bound to itself (`@inject(Application)`) |
|
|
63
|
-
| `useProviders(list)` | Before `start()` |
|
|
66
|
+
| `useProviders(list)` | Before `start()`; `providers` returns the list |
|
|
64
67
|
| `start({ signals? })` | `register()` all, then `boot()` in order. On a failed boot: shuts down the booted ones in reverse, then throws `ProviderError` with the original error as `cause`. `signals: true` installs SIGTERM/SIGINT → `shutdown()` → exit |
|
|
65
68
|
| `shutdown()` | Reverse order; idempotent; collects errors into an `AggregateError` |
|
|
66
69
|
| `isRunning` | |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cslug/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Application, container and @inject, providers, config, events, logger, errors, context, Clock, Money, i18n, contracts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"bun": ">=1.3.14"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@cslug/validation": "0.
|
|
31
|
+
"@cslug/validation": "0.4.1"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/application.ts
CHANGED
|
@@ -85,6 +85,11 @@ export class Application extends Container {
|
|
|
85
85
|
return this.state === 'running'
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/** The providers given to `useProviders()`, in that order. */
|
|
89
|
+
get providers(): readonly ProviderClass[] {
|
|
90
|
+
return this.providerClasses
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
/** The providers to run, from `bootstrap/providers.ts`. Order matters only where `dependsOn` doesn't decide. */
|
|
89
94
|
useProviders(providers: readonly ProviderClass[]): this {
|
|
90
95
|
if (this.state !== 'created') throw new ProviderError('useProviders() must be called before start().')
|
package/src/command.ts
CHANGED
|
@@ -334,3 +334,9 @@ const toPascal = (s: string) =>
|
|
|
334
334
|
|
|
335
335
|
/** Tag of the command classes contributed by providers (`this.commands([...])`). */
|
|
336
336
|
export const COMMANDS = 'cslug.commands'
|
|
337
|
+
|
|
338
|
+
/** Tag of the `cslug describe` sections contributed by providers (`this.describe('routes', () => …)`). */
|
|
339
|
+
export const DESCRIBE = 'cslug.describe'
|
|
340
|
+
|
|
341
|
+
/** One section of `cslug describe`: JSON-ready data about the app (routes, tables, jobs…). */
|
|
342
|
+
export type DescribeSection = { name: string; collect: () => unknown }
|
package/src/index.ts
CHANGED
package/src/provider.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Application } from './application'
|
|
2
|
-
import { COMMANDS, type CommandClass } from './command'
|
|
2
|
+
import { COMMANDS, type CommandClass, DESCRIBE, type DescribeSection } from './command'
|
|
3
|
+
import { token } from './token'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The one place a subsystem is wired. `register()` binds, `boot()` connects and listens, `shutdown()` closes.
|
|
@@ -21,6 +22,13 @@ export abstract class ServiceProvider {
|
|
|
21
22
|
protected commands(commands: readonly CommandClass[]): void {
|
|
22
23
|
this.app.tag([...commands] as never[], COMMANDS)
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
/** Contribute a `cslug describe` section (call in `register()`); `collect` runs when it is asked for. */
|
|
27
|
+
protected describe(name: string, collect: () => unknown): void {
|
|
28
|
+
const section = token<DescribeSection>(`cslug.describe.${name}`)
|
|
29
|
+
this.app.instance(section, { name, collect })
|
|
30
|
+
this.app.tag([section], DESCRIBE)
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/** The optional lifecycle hooks of a provider. */
|