@owlmeans/context 0.1.18-rc.3 → 0.1.18-rc.31
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 +255 -50
- package/agent-meta/manifest.json +5 -5
- package/agent-meta/skills/owlmeans-context/SKILL.md +25 -0
- package/build/config.d.ts.map +1 -1
- package/build/config.js +0 -2
- package/build/config.js.map +1 -1
- package/build/consts.d.ts +1 -9
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +0 -9
- package/build/consts.js.map +1 -1
- package/build/context.d.ts.map +1 -1
- package/build/context.js +26 -109
- package/build/context.js.map +1 -1
- package/build/helper.d.ts +0 -1
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +4 -13
- package/build/helper.js.map +1 -1
- package/build/types.d.ts +21 -23
- package/build/types.d.ts.map +1 -1
- package/build/utils/context.d.ts +2 -7
- package/build/utils/context.d.ts.map +1 -1
- package/build/utils/context.js +0 -11
- package/build/utils/context.js.map +1 -1
- package/build/utils/index.d.ts +0 -1
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +0 -1
- package/build/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -2
- package/src/consts.ts +1 -10
- package/src/context.ts +32 -134
- package/src/helper.ts +4 -18
- package/src/types.ts +22 -26
- package/src/utils/context.ts +2 -20
- package/src/utils/index.ts +0 -1
- package/tests/context.ts +1 -2
- package/tests/service.spec.ts +1 -1
- package/agent-meta/skills/context/SKILL.md +0 -53
- package/build/.gitkeep +0 -0
- package/build/utils/layer.d.ts +0 -6
- package/build/utils/layer.d.ts.map +0 -1
- package/build/utils/layer.js +0 -12
- package/build/utils/layer.js.map +0 -1
- package/src/utils/layer.ts +0 -17
package/README.md
CHANGED
|
@@ -1,95 +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
|
|
15
|
+
bun add @owlmeans/context@^0.1.18-rc.31
|
|
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:
|
|
37
70
|
|
|
38
|
-
```
|
|
39
|
-
const
|
|
40
|
-
|
|
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
|
+
}
|
|
41
103
|
|
|
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
|
+
}
|
|
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'
|
|
145
|
+
|
|
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
|
+
})
|
|
154
|
+
|
|
155
|
+
return service
|
|
156
|
+
}
|
|
157
|
+
```
|
|
64
158
|
|
|
65
|
-
|
|
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
|
+
})
|
|
66
184
|
|
|
67
|
-
|
|
185
|
+
return context
|
|
186
|
+
}
|
|
187
|
+
```
|
|
68
188
|
|
|
69
|
-
|
|
189
|
+
Work that needs the whole context ready without blocking the factory hangs off
|
|
190
|
+
`waitForInitialized()`:
|
|
70
191
|
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
192
|
+
```ts
|
|
193
|
+
context.waitForInitialized().then(async () => {
|
|
194
|
+
context.service<DevService>(DEV_SERVICE).setMetadataFactory(metadataFactory)
|
|
195
|
+
})
|
|
75
196
|
```
|
|
76
197
|
|
|
77
|
-
###
|
|
198
|
+
### 5. A plain contextual object
|
|
78
199
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
200
|
+
`appendContextual` turns any object into something a context can register — the basis of custom
|
|
201
|
+
resources and entrypoints:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { appendContextual } from '@owlmeans/context'
|
|
205
|
+
import type { BasicResource } from '@owlmeans/context'
|
|
206
|
+
|
|
207
|
+
const resource = appendContextual<BasicResource>('project-cache', {
|
|
208
|
+
init: async () => { /* warm up */ },
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
context.registerResource(resource)
|
|
85
212
|
```
|
|
86
213
|
|
|
87
|
-
##
|
|
214
|
+
## API
|
|
88
215
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
92
296
|
- [`@owlmeans/server-app`](../server-app) — top-level server context factory
|
|
297
|
+
- [`@owlmeans/web-panel`](../web-panel) — top-level browser context factory
|
|
93
298
|
|
|
94
299
|
<!-- owlmeans:agent-guidance:start -->
|
|
95
300
|
## Agent guidance
|
|
@@ -99,7 +304,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
99
304
|
your project's skill store (`.agents/skills/`):
|
|
100
305
|
|
|
101
306
|
```sh
|
|
102
|
-
npx @owlmeans/agent-skills
|
|
307
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.35
|
|
103
308
|
```
|
|
104
309
|
|
|
105
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
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/context",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.31",
|
|
5
|
+
"generatedAt": "2026-09-22T21:58:46.790Z",
|
|
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-rc.31`
|
|
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.
|
package/build/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,QAAQ,OAAO,WAAW,MAAM,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAG,CAYzG,CAAA"}
|
package/build/config.js
CHANGED
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAwB,IAAa,EAAE,OAAe,EAAE,GAAgB,EAAK,EAAE;IAC5G,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,KAAK;QACZ,OAAO;QACP,IAAI;QACJ,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,EAAE;QACX,GAAG,GAAG;KACF,CAAA;IAEN,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/build/consts.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export declare enum Layer {
|
|
2
|
-
System = "system",
|
|
3
|
-
Global = "global",
|
|
4
|
-
Service = "service",
|
|
5
|
-
Entity = "entity",
|
|
6
|
-
User = "user"
|
|
7
|
-
}
|
|
8
1
|
export declare enum AppType {
|
|
9
2
|
Backend = "backend",
|
|
10
3
|
Frontend = "frontend"
|
|
@@ -21,8 +14,7 @@ export declare enum ContextStage {
|
|
|
21
14
|
export declare enum MiddlewareStage {
|
|
22
15
|
Configuration = "configuration",
|
|
23
16
|
Loading = "loading",
|
|
24
|
-
Ready = "ready"
|
|
25
|
-
Switching = "switching"
|
|
17
|
+
Ready = "ready"
|
|
26
18
|
}
|
|
27
19
|
export declare const CONFIG_RECORD = "records";
|
|
28
20
|
export declare const EMPTY_ENTITY = "[UNDEFINED_ENTITY]";
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,OAAO;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,oBAAY,cAAc;IACxB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,oBAAY,YAAY;IACtB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,oBAAY,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,eAAO,MAAM,aAAa,YAAY,CAAA;AAEtC,eAAO,MAAM,YAAY,uBAAuB,CAAA;AAChD,eAAO,MAAM,aAAa,wBAAwB,CAAA;AAGlD;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,KAAK,UAAU,CAAA;AAC5B;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,KAAK,UAAU,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export var Layer;
|
|
2
|
-
(function (Layer) {
|
|
3
|
-
Layer["System"] = "system";
|
|
4
|
-
Layer["Global"] = "global";
|
|
5
|
-
Layer["Service"] = "service";
|
|
6
|
-
Layer["Entity"] = "entity";
|
|
7
|
-
Layer["User"] = "user";
|
|
8
|
-
})(Layer || (Layer = {}));
|
|
9
1
|
export var AppType;
|
|
10
2
|
(function (AppType) {
|
|
11
3
|
AppType["Backend"] = "backend";
|
|
@@ -27,7 +19,6 @@ export var MiddlewareStage;
|
|
|
27
19
|
MiddlewareStage["Configuration"] = "configuration";
|
|
28
20
|
MiddlewareStage["Loading"] = "loading";
|
|
29
21
|
MiddlewareStage["Ready"] = "ready";
|
|
30
|
-
MiddlewareStage["Switching"] = "switching";
|
|
31
22
|
})(MiddlewareStage || (MiddlewareStage = {}));
|
|
32
23
|
export const CONFIG_RECORD = 'records';
|
|
33
24
|
export const EMPTY_ENTITY = '[UNDEFINED_ENTITY]';
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;AACvB,CAAC,EAHW,OAAO,KAAP,OAAO,QAGlB;AAED,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;AACrB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,+CAA+B,CAAA;IAC/B,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACjB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,kDAA+B,CAAA;IAC/B,sCAAmB,CAAA;IACnB,kCAAe,CAAA;AACjB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAA;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,CAAA;AAElD,wBAAwB;AACxB;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA;AAC1B;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA;AAC1B;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAA;AAC5B;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA;AAC1B;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAA"}
|
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,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EAAE,YAAY,EAC1B,MAAM,YAAY,CAAA;AAKnB,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,OAAO,CAAC,KAAG,YAAY,CAAC,CAAC,CAuK9E,CAAA"}
|