@owlmeans/context 0.1.18-rc.10 → 0.1.18-rc.12
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/README.md +2 -2
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/context/SKILL.md +12 -152
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ Three flat maps keyed by alias. Registering the same alias twice replaces the ea
|
|
|
85
85
|
```typescript
|
|
86
86
|
context.registerService(service) // context.service(alias), context.hasService(alias)
|
|
87
87
|
context.registerResource(resource) // context.resource(alias), context.hasResource(alias)
|
|
88
|
-
context.registerEntrypoints(entrypoints) // context.entrypoint(
|
|
88
|
+
context.registerEntrypoints(entrypoints) // context.entrypoint(protocol), context.entrypoints(), context.hasEntrypoint(alias)
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
### Enums
|
|
@@ -120,7 +120,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
120
120
|
your project's skill store (`.agents/skills/`):
|
|
121
121
|
|
|
122
122
|
```sh
|
|
123
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
123
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.16
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/context",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-09-
|
|
4
|
+
"version": "0.1.18-rc.12",
|
|
5
|
+
"generatedAt": "2026-09-12T12:33:32.499Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,163 +1,23 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: context
|
|
3
|
-
description:
|
|
4
|
-
user-invocable: false
|
|
3
|
+
description: Use OwlMeans context services, resources and typed entrypoint protocol references.
|
|
5
4
|
---
|
|
6
5
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
6
|
|
|
8
|
-
#
|
|
7
|
+
# Context lookups
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
Use a protocol declaration directly when obtaining an entrypoint. The declaration supplies the
|
|
10
|
+
registered entrypoint’s request and response types.
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|--------|-------------|
|
|
17
|
-
| `makeBasicContext(cfg)` | Low-level factory — extend a layer-specific factory instead |
|
|
18
|
-
| `BasicContext<C>` | The container interface, typed by its config |
|
|
19
|
-
| `BasicConfig` | `{ ready, service, alias?, type, services?, records?, debug? }` — what every config extends |
|
|
20
|
-
| `makeBasicConfig(type, service, cfg?)` | Build the base config object a layer factory then fills in |
|
|
21
|
-
| `createService(alias, impl, init?)` | Build a service initialized during `context.init()` |
|
|
22
|
-
| `createLazyService(alias, impl, init?)` | Build a service initialized on first `context.service()` |
|
|
23
|
-
| `appendContextual(alias, obj)` | Give any object `alias` / `registerContext` / `assertCtx` |
|
|
24
|
-
| `assertContext(ctx, location?)` | Return the context or throw `SyntaxError` when it is absent |
|
|
25
|
-
| `Service` / `InitializedService` / `LazyService` | The three service shapes |
|
|
26
|
-
| `BasicResource` / `BasicEntrypoint` / `Contextual` | The other registrable shapes |
|
|
27
|
-
| `Middleware`, `MiddlewareType`, `MiddlewareStage` | Hooks that run inside `configure()` / `init()` |
|
|
28
|
-
| `AppType` | `Backend` / `Frontend` |
|
|
29
|
-
| `ContextStage` | `Configuration` → `Loading` → `Ready` |
|
|
30
|
-
| `CONFIG_RECORD` (`'records'`), `ConfigRecord` | The config-record array key, and a record in it |
|
|
31
|
-
| `ROOT`, `HOME`, `GUEST`, `BASE`, `CRASH` | Route-alias idioms every layer reuses |
|
|
32
|
-
|
|
33
|
-
## One context per process
|
|
34
|
-
|
|
35
|
-
A context is created ONCE by ONE factory. Extend a layer-specific factory
|
|
36
|
-
(`@owlmeans/server-context`, `@owlmeans/web-panel`, …) rather than calling the basic factory
|
|
37
|
-
directly: your factory calls the factory below it, applies its own idempotent `append*(context)`
|
|
38
|
-
mixins and service registrations, and returns that same context. There are no layered or child
|
|
39
|
-
contexts and nothing is stored for re-creation — a service, a resource and an entrypoint each bind
|
|
40
|
-
to exactly one context, the first that registers them.
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { makeServerContext } from '@owlmeans/server-context'
|
|
44
|
-
|
|
45
|
-
export const makeContext = <C extends Config, T extends Context<C>>(cfg: C): T => {
|
|
46
|
-
const context = makeServerContext<C, T>(cfg)
|
|
47
|
-
context.registerService(makeMyService())
|
|
48
|
-
return context
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Registries
|
|
53
|
-
|
|
54
|
-
Three flat maps keyed by alias. Registering the same alias twice **replaces** the earlier entry —
|
|
55
|
-
entrypoint lists are routinely spread together and the later declaration is the one the app means.
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
context.registerService(service) // service(alias), hasService(alias)
|
|
59
|
-
context.registerResource(resource) // resource(alias), hasResource(alias)
|
|
60
|
-
context.registerEntrypoints(entrypoints) // entrypoint(alias), entrypoints(), hasEntrypoint(alias)
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Every lookup throws `SyntaxError` when the alias is unknown. Resolve a service and call another
|
|
64
|
-
service's entrypoint from a handler:
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
const someService = ctx.service<MyService>(MY_SERVICE_ALIAS)
|
|
68
|
-
|
|
69
|
-
const response = await ctx.entrypoint<ClientEntrypoint<ResponseType>>(
|
|
70
|
-
externalService.action.alias
|
|
71
|
-
).call({ body: { ... } }) // call() resolves to the value; invoke() gives { value, outcome }
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Lifecycle
|
|
75
|
-
|
|
76
|
-
`configure()` runs the `Config` + `Configuration` middlewares and moves the context to `Loading`;
|
|
77
|
-
`init()` awaits that, then initializes every service, then the resources, then flips to `Ready` and
|
|
78
|
-
sets `cfg.ready`. `waitForConfigured()` and `waitForInitialized()` resolve at those two points, and
|
|
79
|
-
`await ctx.config` yields the config once configuration is done. Both calls are safe to repeat — a
|
|
80
|
-
context already past the stage returns itself unchanged.
|
|
81
|
-
|
|
82
|
-
`configure()` is **not** async: it returns the context straight away and its middlewares run
|
|
83
|
-
detached, so the stage flips to `Loading` only when they settle. Anything that must see a configured
|
|
84
|
-
context awaits `waitForConfigured()` or `init()`, never the return of `configure()`.
|
|
85
|
-
|
|
86
|
-
## Services
|
|
87
|
-
|
|
88
|
-
`createService` and `createLazyService` differ only in **when** the init function runs.
|
|
89
|
-
|
|
90
|
-
- `createService` — `init()` is awaited during `context.init()`, in registration order. Asking for
|
|
91
|
-
an uninitialized one throws `SyntaxError`.
|
|
92
|
-
- `createLazyService` — `lazyInit()` fires on the first `context.service(alias)` and the service is
|
|
93
|
-
returned immediately, before that promise settles. Choose lazy when the service must be reachable
|
|
94
|
-
while the context is still `Loading` — from an app's `makeContext`, or from another package's
|
|
95
|
-
`append*` helper — **not** because it has no async work; most lazy services do plenty of it.
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
import { createService } from '@owlmeans/context'
|
|
99
|
-
|
|
100
|
-
export const makeMyService = (alias = MY_SERVICE) => createService<MyService>(alias, {
|
|
101
|
-
doWork: async () => { /* ... */ }
|
|
102
|
-
}, service => async () => {
|
|
103
|
-
await connect()
|
|
104
|
-
service.initialized = true
|
|
105
|
-
})
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
The init function is a factory: it receives the service and returns the actual initializer, which
|
|
109
|
-
must set `service.initialized = true`. Omit it and the service is simply marked initialized. Inside
|
|
110
|
-
any method use `service.assertCtx<Config, Context>()` to reach the context it was registered on.
|
|
111
|
-
|
|
112
|
-
### `ready()`
|
|
113
|
-
|
|
114
|
-
Both factories give the service a `ready(): Promise<boolean>` that resolves once its init function
|
|
115
|
-
has finished, and both `InitializedService` and `LazyService` declare it. It is how you wait for a
|
|
116
|
-
lazy service: the container hands the service back before `lazyInit()` settles, so anything the init
|
|
117
|
-
prepared — a database client, a loaded config, a socket — is only safe to touch after `ready()`.
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
const mongo = ctx.service<MongoService>(MONGO_ALIAS) // this call is what triggers lazyInit
|
|
121
|
-
await mongo.ready()
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
A lazy service's init runs only when someone resolves it through `context.service(alias)`, so
|
|
125
|
-
`ready()` on a reference obtained any other way never settles.
|
|
126
|
-
|
|
127
|
-
## Middlewares
|
|
128
|
-
|
|
129
|
-
A middleware declares a `type` (`Config` or `Context`) and a `stage` (`Configuration`, `Loading` or
|
|
130
|
-
`Ready`), and that pair — not the stage alone — decides where it runs. Exactly five pairs are ever
|
|
131
|
-
applied, in this order:
|
|
132
|
-
|
|
133
|
-
| Type + stage | Where it runs |
|
|
134
|
-
|--------------|---------------|
|
|
135
|
-
| `Config` + `Configuration` | inside `configure()`, before the stage becomes `Loading` — the only hook that sees `cfg` before anything else does |
|
|
136
|
-
| `Context` + `Configuration` | first thing inside `init()` |
|
|
137
|
-
| `Config` + `Loading` | inside `init()`, **after every service has been initialized** and before the resources |
|
|
138
|
-
| `Context` + `Loading` | inside `init()`, after the resources |
|
|
139
|
-
| `Context` + `Ready` | after the stage flips to `Ready`; started but **not awaited**, so `init()` resolves without waiting for it |
|
|
140
|
-
|
|
141
|
-
`Config` + `Ready` is never applied at all — a middleware registered under that pair silently never
|
|
142
|
-
runs. All middlewares sharing a pair are applied with `Promise.all`, so they run concurrently and
|
|
143
|
-
registration order does not sequence them.
|
|
144
|
-
|
|
145
|
-
Pick the pair by what the work needs. `Config` + `Configuration` is for config that stands on its
|
|
146
|
-
own — mounted secrets, hosts read from the environment. `Config` + `Loading` is for config that has
|
|
147
|
-
to be resolved *through a running service*, because services are already initialized by then; that
|
|
148
|
-
is the stage a cluster- or vault-backed value resolver registers at, and it can `await
|
|
149
|
-
service.ready()` on the service it depends on. `Context` middlewares register or adjust what the
|
|
150
|
-
container holds.
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
context.registerMiddleware({
|
|
154
|
-
type: MiddlewareType.Config,
|
|
155
|
-
stage: MiddlewareStage.Loading, // services are up — resolve cfg values through one of them
|
|
156
|
-
apply: async ctx => { /* mutate ctx.cfg */ }
|
|
12
|
+
```ts
|
|
13
|
+
const project = await context.entrypoint(projectEntrypoints.get).call({
|
|
14
|
+
params: { id },
|
|
157
15
|
})
|
|
158
16
|
```
|
|
159
17
|
|
|
160
|
-
|
|
18
|
+
Use `context.service(alias)` for registered services and context resource APIs for data access.
|
|
19
|
+
Protocol declarations are shared immutable values; context registration receives local server or
|
|
20
|
+
client entrypoints created with `bind()`, `bindAll()` or `bindScreen()`.
|
|
161
21
|
|
|
162
|
-
|
|
163
|
-
|
|
22
|
+
Keep organization entity addressing on the wire as `entitySlug`. Resolve the stable `entityId`
|
|
23
|
+
inside the context before persisting relations or calling third parties.
|