@zhin.js/middleware 1.1.10 → 1.1.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/lib/definition.d.ts +7 -1
- package/lib/middleware-index.d.ts +1 -0
- package/lib/middleware-index.js +10 -3
- package/package.json +3 -3
- package/src/definition.ts +13 -2
- package/src/middleware-index.ts +11 -2
package/lib/definition.d.ts
CHANGED
|
@@ -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> {
|
|
@@ -28,6 +29,8 @@ export type MiddlewareDefinition<TInput = unknown, TConfig = unknown, TAdapter e
|
|
|
28
29
|
handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: MiddlewareNext): unknown;
|
|
29
30
|
} | {
|
|
30
31
|
readonly target: 'outbound';
|
|
32
|
+
/** Opt in to cumulative prefixes. Previously published text, format and addressing must stay stable. */
|
|
33
|
+
readonly incremental?: true;
|
|
31
34
|
handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: OutboundMiddlewareNext): void | Promise<void>;
|
|
32
35
|
});
|
|
33
36
|
declare module '@zhin.js/plugin-runtime' {
|
|
@@ -49,6 +52,9 @@ type AuthoringForAdapter<TInput, TConfig, TAdapter extends string | undefined> =
|
|
|
49
52
|
handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: MiddlewareNext): unknown;
|
|
50
53
|
} | {
|
|
51
54
|
readonly target: 'outbound';
|
|
55
|
+
/** Opt in to cumulative prefixes. Previously published text, format and addressing must stay stable;
|
|
56
|
+
* do not repeat approvals, external sends or other side effects. */
|
|
57
|
+
readonly incremental?: true;
|
|
52
58
|
handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: OutboundMiddlewareNext): void | Promise<void>;
|
|
53
59
|
});
|
|
54
60
|
/** @internal Shape shared with the typed IM facade; not a separate authoring API. */
|
|
@@ -19,6 +19,7 @@ export interface MiddlewareDescriptor {
|
|
|
19
19
|
readonly target: MiddlewareTarget;
|
|
20
20
|
readonly order: number;
|
|
21
21
|
readonly adapter?: string;
|
|
22
|
+
readonly incremental?: true;
|
|
22
23
|
}
|
|
23
24
|
/** @internal Runtime middleware executor. */
|
|
24
25
|
export declare class MiddlewareIndex {
|
package/lib/middleware-index.js
CHANGED
|
@@ -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 {
|
|
@@ -16,6 +16,7 @@ export class MiddlewareIndex {
|
|
|
16
16
|
target: slot.definition.target,
|
|
17
17
|
order: slot.definition.order,
|
|
18
18
|
...(slot.definition.adapter ? { adapter: slot.definition.adapter } : {}),
|
|
19
|
+
...(slot.definition.target === 'outbound' && slot.definition.incremental === true ? { incremental: true } : {}),
|
|
19
20
|
slot,
|
|
20
21
|
})).sort((left, right) => compareMiddleware(left, right, topology)));
|
|
21
22
|
}
|
|
@@ -41,9 +42,12 @@ export class MiddlewareIndex {
|
|
|
41
42
|
return terminal();
|
|
42
43
|
const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
|
|
43
44
|
const context = {
|
|
44
|
-
...createCapabilityContext(operationSnapshot, record.owner),
|
|
45
|
+
...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal),
|
|
45
46
|
input: authorInput,
|
|
46
47
|
};
|
|
48
|
+
Object.defineProperty(context, 'session', {
|
|
49
|
+
enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
|
|
50
|
+
});
|
|
47
51
|
Object.defineProperty(context, '$client', {
|
|
48
52
|
enumerable: true,
|
|
49
53
|
get: () => readOperationClient(authorInput, record.adapter),
|
|
@@ -72,8 +76,11 @@ export class MiddlewareIndex {
|
|
|
72
76
|
throw new Error('Invalid inbound Middleware');
|
|
73
77
|
const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
|
|
74
78
|
const context = {
|
|
75
|
-
...createCapabilityContext(operationSnapshot, record.owner), input: authorInput,
|
|
79
|
+
...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal), input: authorInput,
|
|
76
80
|
};
|
|
81
|
+
Object.defineProperty(context, 'session', {
|
|
82
|
+
enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
|
|
83
|
+
});
|
|
77
84
|
Object.defineProperty(context, '$client', {
|
|
78
85
|
enumerable: true, get: () => readOperationClient(authorInput, record.adapter),
|
|
79
86
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/middleware",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
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.
|
|
20
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
19
|
+
"@zhin.js/feature-kit": "1.1.11",
|
|
20
|
+
"@zhin.js/plugin-runtime": "1.1.19"
|
|
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. */
|
|
@@ -45,7 +47,10 @@ export type MiddlewareDefinition<
|
|
|
45
47
|
TAdapter extends string | undefined = string | undefined,
|
|
46
48
|
> = MiddlewareDefinitionBase<TAdapter> & (
|
|
47
49
|
| { readonly target: 'inbound'; handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: MiddlewareNext): unknown }
|
|
48
|
-
| { readonly target: 'outbound';
|
|
50
|
+
| { readonly target: 'outbound';
|
|
51
|
+
/** Opt in to cumulative prefixes. Previously published text, format and addressing must stay stable. */
|
|
52
|
+
readonly incremental?: true;
|
|
53
|
+
handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: OutboundMiddlewareNext): void | Promise<void> }
|
|
49
54
|
);
|
|
50
55
|
|
|
51
56
|
declare module '@zhin.js/plugin-runtime' {
|
|
@@ -69,7 +74,13 @@ type AuthoringForAdapter<TInput, TConfig, TAdapter extends string | undefined> =
|
|
|
69
74
|
readonly order?: number;
|
|
70
75
|
} & (
|
|
71
76
|
| { readonly target?: 'inbound'; handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: MiddlewareNext): unknown }
|
|
72
|
-
| {
|
|
77
|
+
| {
|
|
78
|
+
readonly target: 'outbound';
|
|
79
|
+
/** Opt in to cumulative prefixes. Previously published text, format and addressing must stay stable;
|
|
80
|
+
* do not repeat approvals, external sends or other side effects. */
|
|
81
|
+
readonly incremental?: true;
|
|
82
|
+
handle(context: MiddlewareContext<TInput, TConfig, TAdapter>, next: OutboundMiddlewareNext): void | Promise<void>;
|
|
83
|
+
}
|
|
73
84
|
);
|
|
74
85
|
|
|
75
86
|
/** @internal Shape shared with the typed IM facade; not a separate authoring API. */
|
package/src/middleware-index.ts
CHANGED
|
@@ -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,
|
|
@@ -35,6 +36,7 @@ export interface MiddlewareDescriptor {
|
|
|
35
36
|
readonly target: MiddlewareTarget;
|
|
36
37
|
readonly order: number;
|
|
37
38
|
readonly adapter?: string;
|
|
39
|
+
readonly incremental?: true;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
interface MiddlewareRecord extends MiddlewareDescriptor {
|
|
@@ -59,6 +61,7 @@ export class MiddlewareIndex {
|
|
|
59
61
|
target: slot.definition.target,
|
|
60
62
|
order: slot.definition.order,
|
|
61
63
|
...(slot.definition.adapter ? { adapter: slot.definition.adapter } : {}),
|
|
64
|
+
...(slot.definition.target === 'outbound' && slot.definition.incremental === true ? { incremental: true as const } : {}),
|
|
62
65
|
slot,
|
|
63
66
|
})).sort((left, right) => compareMiddleware(left, right, topology)));
|
|
64
67
|
}
|
|
@@ -93,9 +96,12 @@ export class MiddlewareIndex {
|
|
|
93
96
|
if (!record) return terminal();
|
|
94
97
|
const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
|
|
95
98
|
const context = {
|
|
96
|
-
...createCapabilityContext(operationSnapshot, record.owner),
|
|
99
|
+
...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal),
|
|
97
100
|
input: authorInput,
|
|
98
101
|
} as MiddlewareContext<TInput>;
|
|
102
|
+
Object.defineProperty(context, 'session', {
|
|
103
|
+
enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
|
|
104
|
+
});
|
|
99
105
|
Object.defineProperty(context, '$client', {
|
|
100
106
|
enumerable: true,
|
|
101
107
|
get: () => readOperationClient(authorInput, record.adapter),
|
|
@@ -126,8 +132,11 @@ export class MiddlewareIndex {
|
|
|
126
132
|
if (definition.target !== 'inbound') throw new Error('Invalid inbound Middleware');
|
|
127
133
|
const authorInput = bindOperationInput(input, record.owner, operationSnapshot);
|
|
128
134
|
const context = {
|
|
129
|
-
...createCapabilityContext(operationSnapshot, record.owner), input: authorInput,
|
|
135
|
+
...createCapabilityContext(operationSnapshot, record.owner, undefined, readOperationSession(authorInput, record.adapter)?.signal), input: authorInput,
|
|
130
136
|
} as MiddlewareContext<TInput>;
|
|
137
|
+
Object.defineProperty(context, 'session', {
|
|
138
|
+
enumerable: true, get: () => readOperationSession(authorInput, record.adapter),
|
|
139
|
+
});
|
|
131
140
|
Object.defineProperty(context, '$client', {
|
|
132
141
|
enumerable: true, get: () => readOperationClient(authorInput, record.adapter),
|
|
133
142
|
});
|