@zhin.js/middleware 1.1.9 → 1.1.11

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.
@@ -2,7 +2,7 @@
2
2
  * Middleware authoring API consumed from `zhin.js/middleware`.
3
3
  * @module zhin.js/middleware
4
4
  */
5
- import type { AdapterClient, CapabilityContext, RegisteredAdapterName } from '@zhin.js/feature-kit';
5
+ import type { AdapterClient, OperationSession, CapabilityContext, RegisteredAdapterName } from '@zhin.js/feature-kit';
6
6
  import type { MiddlewareContinuation } from './continuation.js';
7
7
  export type { MiddlewareContinuation } from './continuation.js';
8
8
  declare const middlewareBrand: "zhin.middleware/1";
@@ -14,6 +14,7 @@ export interface MiddlewareContext<TInput = unknown, TConfig = unknown, TAdapter
14
14
  readonly input: TInput;
15
15
  /** Lazily resolved native Client. Without `adapter`, its static type is `unknown`. */
16
16
  readonly $client: AdapterClient<TAdapter>;
17
+ readonly session: OperationSession<TAdapter> | undefined;
17
18
  }
18
19
  /** Shared metadata for the public inbound and outbound definition contracts. */
19
20
  export interface MiddlewareDefinitionBase<TAdapter extends string | undefined = string | undefined> {
@@ -1,4 +1,4 @@
1
- import { createCapabilityContext, bindOperationInput, operationClientAdapter, readOperationClient, } from '@zhin.js/feature-kit';
1
+ import { createCapabilityContext, bindOperationInput, operationClientAdapter, readOperationClient, readOperationSession, } from '@zhin.js/feature-kit';
2
2
  import { continuationBrand } from './continuation.js';
3
3
  /** @internal Runtime middleware executor. */
4
4
  export class MiddlewareIndex {
@@ -41,9 +41,12 @@ export class MiddlewareIndex {
41
41
  return terminal();
42
42
  const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
43
43
  const context = {
44
- ...createCapabilityContext(operationSnapshot, record.owner),
44
+ ...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal),
45
45
  input: authorInput,
46
46
  };
47
+ Object.defineProperty(context, 'session', {
48
+ enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
49
+ });
47
50
  Object.defineProperty(context, '$client', {
48
51
  enumerable: true,
49
52
  get: () => readOperationClient(authorInput, record.adapter),
@@ -72,8 +75,11 @@ export class MiddlewareIndex {
72
75
  throw new Error('Invalid inbound Middleware');
73
76
  const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
74
77
  const context = {
75
- ...createCapabilityContext(operationSnapshot, record.owner), input: authorInput,
78
+ ...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal), input: authorInput,
76
79
  };
80
+ Object.defineProperty(context, 'session', {
81
+ enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
82
+ });
77
83
  Object.defineProperty(context, '$client', {
78
84
  enumerable: true, get: () => readOperationClient(authorInput, record.adapter),
79
85
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/middleware",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "Convention-based Middleware Feature for Zhin Plugin Runtime",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -16,8 +16,8 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@zhin.js/feature-kit": "1.1.8",
20
- "@zhin.js/plugin-runtime": "1.1.16"
19
+ "@zhin.js/plugin-runtime": "1.1.18",
20
+ "@zhin.js/feature-kit": "1.1.10"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^26.1.2",
package/src/definition.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import type {
6
6
  AdapterClient,
7
+ OperationSession,
7
8
  CapabilityContext,
8
9
  RegisteredAdapterName,
9
10
  } from '@zhin.js/feature-kit';
@@ -26,6 +27,7 @@ export interface MiddlewareContext<
26
27
  readonly input: TInput;
27
28
  /** Lazily resolved native Client. Without `adapter`, its static type is `unknown`. */
28
29
  readonly $client: AdapterClient<TAdapter>;
30
+ readonly session: OperationSession<TAdapter> | undefined;
29
31
  }
30
32
 
31
33
  /** Shared metadata for the public inbound and outbound definition contracts. */
@@ -4,6 +4,7 @@ import {
4
4
  bindOperationInput,
5
5
  operationClientAdapter,
6
6
  readOperationClient,
7
+ readOperationSession,
7
8
  } from '@zhin.js/feature-kit';
8
9
  import type {
9
10
  MiddlewareContext,
@@ -93,9 +94,12 @@ export class MiddlewareIndex {
93
94
  if (!record) return terminal();
94
95
  const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
95
96
  const context = {
96
- ...createCapabilityContext(operationSnapshot, record.owner),
97
+ ...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal),
97
98
  input: authorInput,
98
99
  } as MiddlewareContext<TInput>;
100
+ Object.defineProperty(context, 'session', {
101
+ enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
102
+ });
99
103
  Object.defineProperty(context, '$client', {
100
104
  enumerable: true,
101
105
  get: () => readOperationClient(authorInput, record.adapter),
@@ -126,8 +130,11 @@ export class MiddlewareIndex {
126
130
  if (definition.target !== 'inbound') throw new Error('Invalid inbound Middleware');
127
131
  const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
128
132
  const context = {
129
- ...createCapabilityContext(operationSnapshot, record.owner), input: authorInput,
133
+ ...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal), input: authorInput,
130
134
  } as MiddlewareContext<TInput>;
135
+ Object.defineProperty(context, 'session', {
136
+ enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
137
+ });
131
138
  Object.defineProperty(context, '$client', {
132
139
  enumerable: true, get: () => readOperationClient(authorInput, record.adapter),
133
140
  });