@owlmeans/context 0.1.18-rc.8 → 0.1.18
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 +248 -64
- package/agent-meta/manifest.json +6 -6
- package/agent-meta/skills/owlmeans-context/SKILL.md +25 -0
- package/build/consts.local.d.ts +5 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +6 -0
- package/build/consts.local.js.map +1 -0
- package/build/context.d.ts.map +1 -1
- package/build/context.js +9 -8
- package/build/context.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/memo/types.d.ts +14 -0
- package/build/memo/types.d.ts.map +1 -0
- package/build/memo/types.js +2 -0
- package/build/memo/types.js.map +1 -0
- package/build/memo.d.ts +4 -0
- package/build/memo.d.ts.map +1 -0
- package/build/memo.js +25 -0
- package/build/memo.js.map +1 -0
- package/build/service.d.ts +1 -4
- package/build/service.d.ts.map +1 -1
- package/build/service.js +1 -5
- package/build/service.js.map +1 -1
- package/build/types.d.ts +18 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +6 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/utils/context.d.ts +7 -2
- package/build/utils/context.d.ts.map +1 -1
- package/build/utils/context.js +11 -0
- package/build/utils/context.js.map +1 -1
- package/build/utils/index.d.ts +2 -1
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -1
- package/build/utils/index.js.map +1 -1
- package/build/utils/layer.d.ts +6 -0
- package/build/utils/layer.d.ts.map +1 -0
- package/build/utils/layer.js +12 -0
- package/build/utils/layer.js.map +1 -0
- package/build/utils/middleware/types.d.ts +12 -0
- package/build/utils/middleware/types.d.ts.map +1 -0
- package/build/utils/middleware/types.js +2 -0
- package/build/utils/middleware/types.js.map +1 -0
- package/build/utils/middleware.d.ts +4 -0
- package/build/utils/middleware.d.ts.map +1 -0
- package/build/utils/middleware.js +8 -0
- package/build/utils/middleware.js.map +1 -0
- package/package.json +2 -2
- package/src/consts.local.ts +4 -0
- package/src/context.ts +11 -11
- package/src/index.ts +2 -0
- package/src/memo/types.ts +13 -0
- package/src/memo.ts +33 -0
- package/src/service.ts +3 -14
- package/src/types.local.ts +7 -0
- package/src/types.ts +20 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/middleware/types.ts +18 -0
- package/src/utils/middleware.ts +23 -0
- package/tests/memo.spec.ts +27 -0
- package/agent-meta/skills/context/SKILL.md +0 -163
- package/src/utils/context.ts +0 -16
package/README.md
CHANGED
|
@@ -1,116 +1,300 @@
|
|
|
1
1
|
# @owlmeans/context
|
|
2
2
|
|
|
3
|
-
Lightweight dependency injection and service lifecycle
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
Lightweight dependency injection and service lifecycle for fullstack OwlMeans applications. An app
|
|
4
|
+
uses it to author its own services (`createService`, `createLazyService`), to type its context and
|
|
5
|
+
config, and to look up services, resources and entrypoints at runtime. An app almost never calls
|
|
6
|
+
`makeBasicContext` or `makeBasicConfig` itself — it builds its context with the layer factory
|
|
7
|
+
(`makeContext` from `@owlmeans/server-app` or `@owlmeans/web-panel`, `makeClientContext` from
|
|
8
|
+
`@owlmeans/client-context`) and its config with `config()` from `@owlmeans/config` or the layer
|
|
9
|
+
config package. Protocol declarations live in `@owlmeans/entrypoint`; data access contracts live in
|
|
10
|
+
`@owlmeans/resource`.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
bun add @owlmeans/context@^0.1.18
|
|
15
|
+
bun add @owlmeans/context@^0.1.18
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Concepts
|
|
19
|
+
|
|
20
|
+
- **Context** — the DI container: three flat registries (services, resources, entrypoints) keyed
|
|
21
|
+
by alias, plus a middleware table. One context is built per process by one factory; there is no
|
|
22
|
+
child context and nothing is stored for re-creation.
|
|
23
|
+
- **Contextual** — any object carrying `alias`, `registerContext` and `assertCtx`. It binds to
|
|
24
|
+
exactly one context, the first one that registers it.
|
|
25
|
+
- **Service** — a contextual with an initialization state. `createService` gets an eager `init()`
|
|
26
|
+
run during `context.init()`; `createLazyService` gets `lazyInit()` started on first lookup.
|
|
27
|
+
Both expose `ready()`.
|
|
28
|
+
- **Stage** — `ContextStage.Configuration` → `Loading` (after `configure()`) → `Ready` (after
|
|
29
|
+
`init()` resolves). `waitForConfigured()` / `waitForInitialized()` resolve at those points.
|
|
30
|
+
- **Middleware** — a hook keyed by `MiddlewareType` (`Config` / `Context`) and `MiddlewareStage`,
|
|
31
|
+
applied at fixed points of the lifecycle (see Usage 4).
|
|
32
|
+
- **`append*` mixin** — an idempotent function that registers a service, resource or middleware on
|
|
33
|
+
a context, optionally adds a typed accessor, and returns the same context. Layer factories are
|
|
34
|
+
compositions of these.
|
|
35
|
+
|
|
18
36
|
## Usage
|
|
19
37
|
|
|
20
|
-
|
|
38
|
+
### 1. Author a service
|
|
21
39
|
|
|
22
|
-
|
|
40
|
+
`createService` wraps a partial implementation with `alias`, `initialized`, `init`, `ready` and the
|
|
41
|
+
contextual helpers. Inside methods, `service.assertCtx()` returns the context it was registered in.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
23
44
|
import { createService } from '@owlmeans/context'
|
|
45
|
+
import type { InitializedService } from '@owlmeans/context'
|
|
46
|
+
import type { AppConfig, AppContext } from '../types.js'
|
|
47
|
+
|
|
48
|
+
export const INVOICE_SERVICE = 'invoice'
|
|
24
49
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
export interface InvoiceService extends InitializedService {
|
|
51
|
+
total: (projectId: string) => Promise<number>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const makeInvoiceService = (alias: string = INVOICE_SERVICE): InvoiceService => {
|
|
55
|
+
const service: InvoiceService = createService<InvoiceService>(alias, {
|
|
56
|
+
total: async projectId => {
|
|
57
|
+
const ctx = service.assertCtx<AppConfig, AppContext>()
|
|
58
|
+
const { items } = await ctx.invoices().list({ projectId })
|
|
59
|
+
|
|
60
|
+
return items.reduce((sum, invoice) => sum + invoice.amount, 0)
|
|
61
|
+
},
|
|
31
62
|
})
|
|
63
|
+
|
|
32
64
|
return service
|
|
33
65
|
}
|
|
34
66
|
```
|
|
35
67
|
|
|
36
|
-
|
|
68
|
+
A custom initializer is the third argument. It receives the service and returns the async function
|
|
69
|
+
`context.init()` runs — and it must set `initialized` itself:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
export const makeReminderService = (alias: string = 'reminder'): ReminderService =>
|
|
73
|
+
createService<ReminderService>(alias, { staleAfter: () => STALE_AFTER_MS }, service => async () => {
|
|
74
|
+
// open connections, start timers, read config — then mark the service usable
|
|
75
|
+
service.initialized = true
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 2. Register it through an `append*` mixin
|
|
80
|
+
|
|
81
|
+
The mixin registers the service, adds a typed accessor and returns the same context. The app's
|
|
82
|
+
factory calls the factory of the layer below and then its own mixins.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context'
|
|
86
|
+
import { makeContext as makeServerContext } from '@owlmeans/server-app'
|
|
87
|
+
|
|
88
|
+
export interface WithInvoiceService {
|
|
89
|
+
invoice: () => InvoiceService
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const appendInvoiceService = <C extends BasicConfig, T extends BasicContext<C>>(
|
|
93
|
+
ctx: T, alias: string = INVOICE_SERVICE
|
|
94
|
+
): T & WithInvoiceService => {
|
|
95
|
+
const context = ctx as T & WithInvoiceService
|
|
96
|
+
if (!context.hasService(alias)) {
|
|
97
|
+
context.registerService(makeInvoiceService(alias))
|
|
98
|
+
}
|
|
99
|
+
context.invoice = () => context.service(alias)
|
|
100
|
+
|
|
101
|
+
return context
|
|
102
|
+
}
|
|
37
103
|
|
|
38
|
-
|
|
39
|
-
const context =
|
|
40
|
-
context
|
|
104
|
+
export const makeContext = <C extends AppConfig, T extends AppContext<C>>(cfg: C): T => {
|
|
105
|
+
const context = makeServerContext<C, T>(cfg)
|
|
106
|
+
appendInvoiceService<C, T>(context)
|
|
107
|
+
|
|
108
|
+
return context
|
|
109
|
+
}
|
|
41
110
|
|
|
111
|
+
const context = makeContext(config)
|
|
42
112
|
await context.configure().init()
|
|
43
113
|
|
|
44
|
-
|
|
114
|
+
await context.invoice().total(projectId)
|
|
45
115
|
```
|
|
46
116
|
|
|
47
|
-
|
|
117
|
+
### 3. Look things up
|
|
48
118
|
|
|
49
|
-
|
|
119
|
+
`service`, `resource` and `entrypoint` throw a `SyntaxError` when the alias is not registered; use
|
|
120
|
+
the `has*` predicates for optional collaborators. Entrypoints are looked up by the shared protocol
|
|
121
|
+
declaration, which also supplies request and response types.
|
|
50
122
|
|
|
51
|
-
|
|
123
|
+
```ts
|
|
124
|
+
import { projectProtocols } from 'my-app-common'
|
|
52
125
|
|
|
53
|
-
|
|
126
|
+
const project = await context.entrypoint(projectProtocols.get).call({
|
|
127
|
+
params: { id },
|
|
128
|
+
})
|
|
54
129
|
|
|
55
|
-
|
|
130
|
+
const policy = context.hasService(RELEASE_POLICY)
|
|
131
|
+
? context.service<ReleasePolicy>(RELEASE_POLICY)
|
|
132
|
+
: null
|
|
56
133
|
|
|
57
|
-
|
|
134
|
+
const cache = context.resource<Resource<ProjectRecord>>(PROJECT_CACHE)
|
|
135
|
+
```
|
|
58
136
|
|
|
59
|
-
|
|
137
|
+
### 4. Lazy services and lifecycle hooks
|
|
60
138
|
|
|
61
|
-
|
|
139
|
+
A lazy service starts `lazyInit()` the first time `context.service(alias)` returns it and does not
|
|
140
|
+
wait for it, so its methods await `ready()` first:
|
|
62
141
|
|
|
63
|
-
|
|
142
|
+
```ts
|
|
143
|
+
import { createLazyService } from '@owlmeans/context'
|
|
144
|
+
import type { GateService } from '@owlmeans/entrypoint'
|
|
64
145
|
|
|
65
|
-
|
|
146
|
+
export const makeProjectGate = (alias: string = PROJECT_GATE): GateService => {
|
|
147
|
+
const service: GateService = createLazyService<GateService>(alias, {
|
|
148
|
+
assert: async (req, _res, params) => {
|
|
149
|
+
await service.ready()
|
|
150
|
+
const ctx = service.assertCtx<AppConfig, AppContext>()
|
|
151
|
+
// ... check req.auth against params using ctx resources
|
|
152
|
+
},
|
|
153
|
+
})
|
|
66
154
|
|
|
67
|
-
|
|
155
|
+
return service
|
|
156
|
+
}
|
|
157
|
+
```
|
|
68
158
|
|
|
69
|
-
|
|
159
|
+
Middlewares run at fixed points:
|
|
160
|
+
|
|
161
|
+
| When | Type / stage |
|
|
162
|
+
|------|--------------|
|
|
163
|
+
| `configure()` | `Config` / `Configuration` |
|
|
164
|
+
| `init()`, before services | `Context` / `Configuration` |
|
|
165
|
+
| after every eager `service.init()` | `Config` / `Loading` |
|
|
166
|
+
| after every `resource.init()` | `Context` / `Loading` |
|
|
167
|
+
| after the stage becomes `Ready` (not awaited) | `Context` / `Ready` |
|
|
168
|
+
|
|
169
|
+
`Context` / `Loading` is the moment services are initialized but nothing has started listening yet —
|
|
170
|
+
the place to mount a raw server route:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { MiddlewareStage, MiddlewareType } from '@owlmeans/context'
|
|
174
|
+
|
|
175
|
+
export const appendHealthEndpoint = <C extends AppConfig, T extends AppContext<C>>(context: T): T => {
|
|
176
|
+
context.registerMiddleware({
|
|
177
|
+
type: MiddlewareType.Context,
|
|
178
|
+
stage: MiddlewareStage.Loading,
|
|
179
|
+
apply: async ctx => {
|
|
180
|
+
const server = (ctx as unknown as T).getApiServer().server
|
|
181
|
+
server.route({ method: 'GET', url: '/healthz', handler: async () => ({ ok: true }) })
|
|
182
|
+
},
|
|
183
|
+
})
|
|
70
184
|
|
|
71
|
-
```typescript
|
|
72
|
-
export const makeContext = <C extends Config, T extends Context<C>>(cfg: C): T => {
|
|
73
|
-
const context = makeServerContext<C, T>(cfg)
|
|
74
|
-
appendMyService<C, T>(context)
|
|
75
185
|
return context
|
|
76
186
|
}
|
|
77
187
|
```
|
|
78
188
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
### Registries
|
|
189
|
+
Work that needs the whole context ready without blocking the factory hangs off
|
|
190
|
+
`waitForInitialized()`:
|
|
82
191
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
context.registerResource(resource) // context.resource(alias), context.hasResource(alias)
|
|
88
|
-
context.registerEntrypoints(entrypoints) // context.entrypoint(alias), context.entrypoints(), context.hasEntrypoint(alias)
|
|
192
|
+
```ts
|
|
193
|
+
context.waitForInitialized().then(async () => {
|
|
194
|
+
context.service<DevService>(DEV_SERVICE).setMetadataFactory(metadataFactory)
|
|
195
|
+
})
|
|
89
196
|
```
|
|
90
197
|
|
|
91
|
-
###
|
|
198
|
+
### 5. A plain contextual object
|
|
92
199
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
enum ContextStage { Configuration, Loading, Ready }
|
|
96
|
-
```
|
|
200
|
+
`appendContextual` turns any object into something a context can register — the basis of custom
|
|
201
|
+
resources and entrypoints:
|
|
97
202
|
|
|
98
|
-
|
|
203
|
+
```ts
|
|
204
|
+
import { appendContextual } from '@owlmeans/context'
|
|
205
|
+
import type { BasicResource } from '@owlmeans/context'
|
|
99
206
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
CRASH // error fallback screen
|
|
207
|
+
const resource = appendContextual<BasicResource>('project-cache', {
|
|
208
|
+
init: async () => { /* warm up */ },
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
context.registerResource(resource)
|
|
106
212
|
```
|
|
107
213
|
|
|
108
|
-
##
|
|
214
|
+
## API
|
|
109
215
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
216
|
+
### Functions
|
|
217
|
+
|
|
218
|
+
| Symbol | Kind | Purpose |
|
|
219
|
+
|--------|------|---------|
|
|
220
|
+
| `makeBasicContext<C>(cfg)` | function | Build the bare container; wrapped by every layer factory |
|
|
221
|
+
| `makeBasicConfig<C>(type, service, cfg?)` | function | Build a `BasicConfig` with `ready: false`, empty `services`, `records`, `debug` |
|
|
222
|
+
| `createService<S>(alias, service, init?)` | function | Service initialized eagerly by `context.init()` |
|
|
223
|
+
| `createLazyService<S>(alias, service, init?)` | function | Service initialized on first `context.service(alias)` |
|
|
224
|
+
| `appendContextual<T>(alias, obj)` | function | Add `alias`, `registerContext`, `assertCtx` to an object |
|
|
225
|
+
| `assertContext(ctx, location?)` | function | Return `ctx` or throw `SyntaxError` naming `location` |
|
|
226
|
+
|
|
227
|
+
### `BasicContext<C>` members
|
|
228
|
+
|
|
229
|
+
| Member | Purpose |
|
|
230
|
+
|--------|---------|
|
|
231
|
+
| `cfg`, `config` | Config object; `config` is a promise resolving after configuration |
|
|
232
|
+
| `stage` | Current `ContextStage` |
|
|
233
|
+
| `configure()`, `init()` | Run the lifecycle; `init()` resolves once the context is `Ready` |
|
|
234
|
+
| `waitForConfigured()`, `waitForInitialized()` | Promises for those two points |
|
|
235
|
+
| `registerService`, `registerResource`, `registerEntrypoint`, `registerEntrypoints`, `registerMiddleware` | Registration; a repeated alias replaces the earlier entry |
|
|
236
|
+
| `service(alias)`, `resource(alias)`, `entrypoint(protocol \| alias)` | Lookup; throws `SyntaxError` when missing or (eager service) not initialized |
|
|
237
|
+
| `hasService`, `hasResource`, `hasEntrypoint` | Presence checks by alias |
|
|
238
|
+
| `entrypoints()` | Every registered entrypoint |
|
|
239
|
+
|
|
240
|
+
### Constants and enums
|
|
241
|
+
|
|
242
|
+
| Symbol | Kind | Purpose |
|
|
243
|
+
|--------|------|---------|
|
|
244
|
+
| `AppType` | enum | `Backend`, `Frontend` |
|
|
245
|
+
| `ContextStage` | enum | `Configuration`, `Loading`, `Ready` |
|
|
246
|
+
| `MiddlewareType` | enum | `Config`, `Context` |
|
|
247
|
+
| `MiddlewareStage` | enum | `Configuration`, `Loading`, `Ready` |
|
|
248
|
+
| `CONFIG_RECORD` | const | Config key holding `ConfigRecord[]` (`'records'`) |
|
|
249
|
+
| `EMPTY_ENTITY`, `EMPTY_PROFILE` | const | Placeholders for an unset organization entity or profile |
|
|
250
|
+
| `ROOT` | const | Intermediate base route alias |
|
|
251
|
+
| `HOME` | const | Default final route alias |
|
|
252
|
+
| `GUEST` | const | Intermediate area without authentication |
|
|
253
|
+
| `BASE` | const | Intermediate area requiring authentication |
|
|
254
|
+
| `CRASH` | const | Fallback error screen alias |
|
|
255
|
+
|
|
256
|
+
### Types
|
|
257
|
+
|
|
258
|
+
| Symbol | Kind | Purpose |
|
|
259
|
+
|--------|------|---------|
|
|
260
|
+
| `BasicConfig` | interface | `ready`, `service`, `alias?`, `type`, `services?`, `records?`, `debug?` |
|
|
261
|
+
| `ConfigRecord` | interface | Free-form config record with `id` and optional `recordType` |
|
|
262
|
+
| `BasicContext<C>` | interface | The container (members above) |
|
|
263
|
+
| `Contextual` | interface | `ctx?`, `alias`, `registerContext`, `assertCtx` |
|
|
264
|
+
| `Service` | interface | Contextual with `initialized`, `init?`, `lazyInit?`, `ready?` |
|
|
265
|
+
| `InitializedService` | interface | Service with required `init` and `ready` |
|
|
266
|
+
| `LazyService` | interface | Service with required `lazyInit` and `ready` |
|
|
267
|
+
| `InitMethod<S>` | interface | `(service) => () => Promise<void>` custom initializer |
|
|
268
|
+
| `BasicResource` | interface | Contextual with optional `init` |
|
|
269
|
+
| `BasicEntrypoint` | interface | Contextual marked `_entrypoint: true` |
|
|
270
|
+
| `EntrypointReference<T>` | interface | `{ alias, entrypointType? }` — what a protocol declaration satisfies for typed lookup |
|
|
271
|
+
| `Middleware` | interface | `type`, `stage`, `apply(context, args?)` |
|
|
272
|
+
|
|
273
|
+
## Common pitfalls
|
|
274
|
+
|
|
275
|
+
- Pass protocol declarations to `context.entrypoint(...)`, never alias strings — the declaration
|
|
276
|
+
carries the request and response types.
|
|
277
|
+
- Build one context per process with one factory; do not create child contexts or reuse a service
|
|
278
|
+
object in a second context — it stays bound to the first one.
|
|
279
|
+
- A custom `init` passed to `createService` must set `service.initialized = true`, or
|
|
280
|
+
`context.service(alias)` throws "is not initialized".
|
|
281
|
+
- `context.service(alias)` on a lazy service does not wait for `lazyInit()`; methods await
|
|
282
|
+
`service.ready()` before touching state.
|
|
283
|
+
- Registering an alias twice silently replaces the earlier entry — guard `append*` mixins with
|
|
284
|
+
`has*` so they stay idempotent.
|
|
285
|
+
- `Context` / `Ready` middlewares are not awaited by `init()`; do not rely on them having finished.
|
|
286
|
+
- Keep the organization `entitySlug` on the wire; resolve the stable `entityId` inside the context
|
|
287
|
+
before persisting relations or calling third parties.
|
|
288
|
+
|
|
289
|
+
## Related packages
|
|
290
|
+
|
|
291
|
+
- [`@owlmeans/config`](../config) — the application config built on `BasicConfig`
|
|
292
|
+
- [`@owlmeans/entrypoint`](../entrypoint) — protocol declarations looked up through `context.entrypoint`
|
|
293
|
+
- [`@owlmeans/resource`](../resource) — the resource contract registered through `registerResource`
|
|
294
|
+
- [`@owlmeans/server-context`](../server-context) — server-side context layer
|
|
295
|
+
- [`@owlmeans/client-context`](../client-context) — client-side context layer
|
|
113
296
|
- [`@owlmeans/server-app`](../server-app) — top-level server context factory
|
|
297
|
+
- [`@owlmeans/web-panel`](../web-panel) — top-level browser context factory
|
|
114
298
|
|
|
115
299
|
<!-- owlmeans:agent-guidance:start -->
|
|
116
300
|
## Agent guidance
|
|
@@ -120,7 +304,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
120
304
|
your project's skill store (`.agents/skills/`):
|
|
121
305
|
|
|
122
306
|
```sh
|
|
123
|
-
npx @owlmeans/agent-skills@^0.1.18
|
|
307
|
+
npx @owlmeans/agent-skills@^0.1.18
|
|
124
308
|
```
|
|
125
309
|
|
|
126
310
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schemaVersion":
|
|
2
|
+
"schemaVersion": 3,
|
|
3
3
|
"package": "@owlmeans/context",
|
|
4
|
-
"version": "0.1.18
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18",
|
|
5
|
+
"generatedAt": "2026-10-28T00:31:34.773Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"kind": "skill",
|
|
10
|
-
"name": "context",
|
|
10
|
+
"name": "owlmeans-context",
|
|
11
11
|
"category": "package-specific",
|
|
12
|
-
"file": "skills/context/SKILL.md",
|
|
13
|
-
"canonicalPath": ".agents/skills/context/SKILL.md"
|
|
12
|
+
"file": "skills/owlmeans-context/SKILL.md",
|
|
13
|
+
"canonicalPath": ".agents/skills/owlmeans-context/SKILL.md"
|
|
14
14
|
}
|
|
15
15
|
]
|
|
16
16
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: owlmeans-context
|
|
3
|
+
description: How to use @owlmeans/context — the context every OwlMeans app looks things up on, context.service() and resource lookups, typed entrypoint protocol references, and entitySlug vs entityId addressing. Auto-invoked when importing from @owlmeans/context or obtaining a service, resource or entrypoint from a context.
|
|
4
|
+
---
|
|
5
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
|
+
|
|
7
|
+
# Context lookups
|
|
8
|
+
|
|
9
|
+
**Install:** `bun add @owlmeans/context@^0.1.18`
|
|
10
|
+
|
|
11
|
+
Use a protocol declaration directly when obtaining an entrypoint. The declaration supplies the
|
|
12
|
+
registered entrypoint’s request and response types.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const project = await context.entrypoint(projectProtocols.get).call({
|
|
16
|
+
params: { id },
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Use `context.service(alias)` for registered services and context resource APIs for data access.
|
|
21
|
+
Protocol declarations are shared immutable values; context registration receives local server or
|
|
22
|
+
client entrypoints created with `bind()`, `bindAll()` or `bindScreen()`.
|
|
23
|
+
|
|
24
|
+
Keep organization entity addressing on the wire as `entitySlug`. Resolve the stable `entityId`
|
|
25
|
+
inside the context before persisting relations or calling third parties.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.d.ts","sourceRoot":"","sources":["../src/consts.local.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,IAAI,aAAa;IACjB,WAAW,SAAS;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.local.js","sourceRoot":"","sources":["../src/consts.local.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,oCAAoB,CAAA;AACtB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB"}
|
package/build/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAA2D,MAAM,YAAY,CAAA;AAIpH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,OAAO,CAAC,KAAG,YAAY,CAAC,CAAC,CAuK9E,CAAA"}
|
package/build/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContextStage, MiddlewareStage, MiddlewareType } from './consts.js';
|
|
2
|
-
import {
|
|
2
|
+
import { middlewareUtils } from './utils/middleware.js';
|
|
3
3
|
export const makeBasicContext = (cfg) => {
|
|
4
4
|
/**
|
|
5
5
|
* One flat registry per kind, keyed by alias. Registering an alias twice replaces the
|
|
@@ -26,7 +26,7 @@ export const makeBasicContext = (cfg) => {
|
|
|
26
26
|
return context;
|
|
27
27
|
}
|
|
28
28
|
void (async () => {
|
|
29
|
-
await applyMiddlewares(context, middlewares, MiddlewareType.Config, MiddlewareStage.Configuration);
|
|
29
|
+
await middlewareUtils.applyMiddlewares(context, middlewares, MiddlewareType.Config, MiddlewareStage.Configuration);
|
|
30
30
|
context.stage = ContextStage.Loading;
|
|
31
31
|
configure(true);
|
|
32
32
|
})();
|
|
@@ -37,7 +37,7 @@ export const makeBasicContext = (cfg) => {
|
|
|
37
37
|
if (context.stage !== ContextStage.Loading) {
|
|
38
38
|
return context;
|
|
39
39
|
}
|
|
40
|
-
await applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration);
|
|
40
|
+
await middlewareUtils.applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration);
|
|
41
41
|
await Object.values(services).reduce(async (previous, service) => {
|
|
42
42
|
await previous;
|
|
43
43
|
if (!service.initialized) {
|
|
@@ -49,16 +49,16 @@ export const makeBasicContext = (cfg) => {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}, Promise.resolve());
|
|
52
|
-
await applyMiddlewares(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading);
|
|
52
|
+
await middlewareUtils.applyMiddlewares(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading);
|
|
53
53
|
await Object.values(resources).reduce(async (previous, resource) => {
|
|
54
54
|
await previous;
|
|
55
55
|
await resource.init?.();
|
|
56
56
|
}, Promise.resolve());
|
|
57
|
-
await applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading);
|
|
57
|
+
await middlewareUtils.applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading);
|
|
58
58
|
context.stage = ContextStage.Ready;
|
|
59
59
|
context.cfg.ready = true;
|
|
60
60
|
initialize(true);
|
|
61
|
-
void applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Ready);
|
|
61
|
+
void middlewareUtils.applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Ready);
|
|
62
62
|
return context;
|
|
63
63
|
},
|
|
64
64
|
registerService: (service) => {
|
|
@@ -78,7 +78,7 @@ export const makeBasicContext = (cfg) => {
|
|
|
78
78
|
return context;
|
|
79
79
|
},
|
|
80
80
|
registerMiddleware: (middleware) => {
|
|
81
|
-
const key = getMiddlerwareKey(middleware);
|
|
81
|
+
const key = middlewareUtils.getMiddlerwareKey(middleware);
|
|
82
82
|
if (!(key in middlewares)) {
|
|
83
83
|
middlewares[key] = [];
|
|
84
84
|
}
|
|
@@ -108,7 +108,8 @@ export const makeBasicContext = (cfg) => {
|
|
|
108
108
|
}
|
|
109
109
|
return _service;
|
|
110
110
|
},
|
|
111
|
-
entrypoint: (
|
|
111
|
+
entrypoint: (reference) => {
|
|
112
|
+
const alias = typeof reference === 'string' ? reference : reference.alias;
|
|
112
113
|
if (entrypoints[alias] != null) {
|
|
113
114
|
return entrypoints[alias];
|
|
114
115
|
}
|
package/build/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAGvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,C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AC/B,OAAO,WAAW,CAAC,KAAK,CAAM,CAAA;YAChC,CAAC;YACD,MAAM,IAAI,WAAW,CAAC,cAAc,KAAK,YAAY,CAAC,CAAA;QACxD,CAAC;QAED,QAAQ,EAAE,CAA0B,KAAa,EAAE,EAAE;YACnD,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAC,KAAK,CAAM,CAAA;YAC9B,CAAC;YACD,MAAM,IAAI,WAAW,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;QACtD,CAAC;QAED,WAAW,EAAE,GAAyB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAQ;QAE1E,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,IAAI;QAE9C,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI;QAE5C,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,IAAI;KACnD,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type * from './types.js';
|
|
2
|
+
export type * from './memo/types.js';
|
|
2
3
|
export * from './consts.js';
|
|
3
4
|
export * from './context.js';
|
|
4
5
|
export * from './service.js';
|
|
5
6
|
export * from './helper.js';
|
|
6
7
|
export * from './config.js';
|
|
8
|
+
export * from './memo.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,iBAAiB,CAAA;AACpC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Lazy, memoized construction — the seam bound objects are reached through. */
|
|
2
|
+
export interface MemoHelper {
|
|
3
|
+
/**
|
|
4
|
+
* A thunk that builds its value on the first call and answers the same value after. A flag, not
|
|
5
|
+
* `undefined`, marks it built, so a builder that returns `undefined` still runs once.
|
|
6
|
+
*/
|
|
7
|
+
once: <T>(build: () => T) => () => T;
|
|
8
|
+
/**
|
|
9
|
+
* One `make(target)` per target object: built on first use for that target and released with it
|
|
10
|
+
* (a WeakMap), so a context, a request or a collaborator gets exactly one bound object.
|
|
11
|
+
*/
|
|
12
|
+
oncePer: <K extends object, T>(make: (target: K) => T) => (target: K) => T;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memo/types.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,CAAA;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAA;CAC3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/memo/types.ts"],"names":[],"mappings":""}
|
package/build/memo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,eAAO,MAAM,gBAAgB,QAAO,UA4BnC,CAAA;AAED,eAAO,MAAM,UAAU,YAAqB,CAAA"}
|
package/build/memo.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const createMemoHelper = () => {
|
|
2
|
+
const once = (build) => {
|
|
3
|
+
let built = false;
|
|
4
|
+
let value;
|
|
5
|
+
return () => {
|
|
6
|
+
if (!built) {
|
|
7
|
+
value = build();
|
|
8
|
+
built = true;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const oncePer = (make) => {
|
|
14
|
+
const made = new WeakMap();
|
|
15
|
+
return target => {
|
|
16
|
+
if (!made.has(target)) {
|
|
17
|
+
made.set(target, make(target));
|
|
18
|
+
}
|
|
19
|
+
return made.get(target);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
return { once, oncePer };
|
|
23
|
+
};
|
|
24
|
+
export const memoHelper = createMemoHelper();
|
|
25
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.js","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAe,EAAE;IAC/C,MAAM,IAAI,GAAG,CAAI,KAAc,EAAa,EAAE;QAC5C,IAAI,KAAK,GAAG,KAAK,CAAA;QACjB,IAAI,KAAoB,CAAA;QAExB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,KAAK,GAAG,KAAK,EAAE,CAAA;gBACf,KAAK,GAAG,IAAI,CAAA;YACd,CAAC;YAED,OAAO,KAAU,CAAA;QACnB,CAAC,CAAA;IACH,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,CAAsB,IAAsB,EAAsB,EAAE;QAClF,MAAM,IAAI,GAAG,IAAI,OAAO,EAAQ,CAAA;QAEhC,OAAO,MAAM,CAAC,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBACtB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;YAChC,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAM,CAAA;QAC9B,CAAC,CAAA;IACH,CAAC,CAAA;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC1B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAA"}
|