@cleocode/lafs 2026.3.74 → 2026.4.3
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/LICENSE +0 -0
- package/README.md +97 -68
- package/dist/schemas/v1/agent-card.schema.json +230 -0
- package/dist/schemas/v1/conformance-profiles.json +0 -0
- package/dist/schemas/v1/context-ledger.schema.json +70 -0
- package/dist/schemas/v1/discovery.schema.json +132 -0
- package/dist/schemas/v1/envelope.schema.json +0 -0
- package/dist/schemas/v1/error-registry.json +0 -0
- package/dist/src/a2a/bindings/grpc.d.ts +118 -11
- package/dist/src/a2a/bindings/grpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/grpc.js +80 -8
- package/dist/src/a2a/bindings/grpc.js.map +1 -0
- package/dist/src/a2a/bindings/http.d.ts +131 -15
- package/dist/src/a2a/bindings/http.d.ts.map +1 -0
- package/dist/src/a2a/bindings/http.js +101 -14
- package/dist/src/a2a/bindings/http.js.map +1 -0
- package/dist/src/a2a/bindings/index.d.ts +83 -9
- package/dist/src/a2a/bindings/index.d.ts.map +1 -0
- package/dist/src/a2a/bindings/index.js +74 -6
- package/dist/src/a2a/bindings/index.js.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.d.ts +194 -9
- package/dist/src/a2a/bindings/jsonrpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.js +155 -10
- package/dist/src/a2a/bindings/jsonrpc.js.map +1 -0
- package/dist/src/a2a/bridge.d.ts +237 -44
- package/dist/src/a2a/bridge.d.ts.map +1 -0
- package/dist/src/a2a/bridge.js +187 -48
- package/dist/src/a2a/bridge.js.map +1 -0
- package/dist/src/a2a/extensions.d.ts +222 -12
- package/dist/src/a2a/extensions.d.ts.map +1 -0
- package/dist/src/a2a/extensions.js +178 -13
- package/dist/src/a2a/extensions.js.map +1 -0
- package/dist/src/a2a/index.d.ts +10 -7
- package/dist/src/a2a/index.d.ts.map +1 -0
- package/dist/src/a2a/index.js +24 -27
- package/dist/src/a2a/index.js.map +1 -0
- package/dist/src/a2a/streaming.d.ts +276 -3
- package/dist/src/a2a/streaming.d.ts.map +1 -0
- package/dist/src/a2a/streaming.js +255 -11
- package/dist/src/a2a/streaming.js.map +1 -0
- package/dist/src/a2a/task-lifecycle.d.ts +341 -20
- package/dist/src/a2a/task-lifecycle.d.ts.map +1 -0
- package/dist/src/a2a/task-lifecycle.js +327 -26
- package/dist/src/a2a/task-lifecycle.js.map +1 -0
- package/dist/src/budgetEnforcement.d.ts +93 -20
- package/dist/src/budgetEnforcement.d.ts.map +1 -0
- package/dist/src/budgetEnforcement.js +146 -31
- package/dist/src/budgetEnforcement.js.map +1 -0
- package/dist/src/circuit-breaker/index.d.ts +260 -10
- package/dist/src/circuit-breaker/index.d.ts.map +1 -0
- package/dist/src/circuit-breaker/index.js +226 -14
- package/dist/src/circuit-breaker/index.js.map +1 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +12 -11
- package/dist/src/cli.js.map +1 -0
- package/dist/src/compliance.d.ts +180 -3
- package/dist/src/compliance.d.ts.map +1 -0
- package/dist/src/compliance.js +114 -13
- package/dist/src/compliance.js.map +1 -0
- package/dist/src/conformance.d.ts +55 -2
- package/dist/src/conformance.d.ts.map +1 -0
- package/dist/src/conformance.js +124 -76
- package/dist/src/conformance.js.map +1 -0
- package/dist/src/conformanceProfiles.d.ts +68 -1
- package/dist/src/conformanceProfiles.d.ts.map +1 -0
- package/dist/src/conformanceProfiles.js +53 -1
- package/dist/src/conformanceProfiles.js.map +1 -0
- package/dist/src/deprecationRegistry.d.ts +82 -1
- package/dist/src/deprecationRegistry.d.ts.map +1 -0
- package/dist/src/deprecationRegistry.js +58 -7
- package/dist/src/deprecationRegistry.js.map +1 -0
- package/dist/src/discovery.d.ts +347 -65
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +130 -72
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/envelope.d.ts +262 -9
- package/dist/src/envelope.d.ts.map +1 -0
- package/dist/src/envelope.js +179 -15
- package/dist/src/envelope.js.map +1 -0
- package/dist/src/errorRegistry.d.ts +163 -3
- package/dist/src/errorRegistry.d.ts.map +1 -0
- package/dist/src/errorRegistry.js +119 -3
- package/dist/src/errorRegistry.js.map +1 -0
- package/dist/src/fieldExtraction.d.ts +128 -27
- package/dist/src/fieldExtraction.d.ts.map +1 -0
- package/dist/src/fieldExtraction.js +100 -27
- package/dist/src/fieldExtraction.js.map +1 -0
- package/dist/src/flagResolver.d.ts +77 -10
- package/dist/src/flagResolver.d.ts.map +1 -0
- package/dist/src/flagResolver.js +22 -5
- package/dist/src/flagResolver.js.map +1 -0
- package/dist/src/flagSemantics.d.ts +80 -4
- package/dist/src/flagSemantics.d.ts.map +1 -0
- package/dist/src/flagSemantics.js +78 -11
- package/dist/src/flagSemantics.js.map +1 -0
- package/dist/src/health/index.d.ts +103 -9
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +75 -26
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/index.d.ts +34 -23
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -28
- package/dist/src/index.js.map +1 -0
- package/dist/src/mviProjection.d.ts +43 -6
- package/dist/src/mviProjection.d.ts.map +1 -0
- package/dist/src/mviProjection.js +32 -5
- package/dist/src/mviProjection.js.map +1 -0
- package/dist/src/native-loader.d.ts +49 -0
- package/dist/src/native-loader.d.ts.map +1 -0
- package/dist/src/native-loader.js +56 -0
- package/dist/src/native-loader.js.map +1 -0
- package/dist/src/problemDetails.d.ts +71 -4
- package/dist/src/problemDetails.d.ts.map +1 -0
- package/dist/src/problemDetails.js +27 -3
- package/dist/src/problemDetails.js.map +1 -0
- package/dist/src/shutdown/index.d.ts +103 -9
- package/dist/src/shutdown/index.d.ts.map +1 -0
- package/dist/src/shutdown/index.js +78 -12
- package/dist/src/shutdown/index.js.map +1 -0
- package/dist/src/tokenEstimator.d.ts +98 -11
- package/dist/src/tokenEstimator.d.ts.map +1 -0
- package/dist/src/tokenEstimator.js +91 -13
- package/dist/src/tokenEstimator.js.map +1 -0
- package/dist/src/types.d.ts +477 -11
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +76 -2
- package/dist/src/types.js.map +1 -0
- package/dist/src/validateEnvelope.d.ts +61 -2
- package/dist/src/validateEnvelope.d.ts.map +1 -0
- package/dist/src/validateEnvelope.js +81 -14
- package/dist/src/validateEnvelope.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/lafs.md +3 -4
- package/package.json +14 -12
- package/schemas/v1/agent-card.schema.json +0 -0
- package/schemas/v1/conformance-profiles.json +0 -0
- package/schemas/v1/context-ledger.schema.json +0 -0
- package/schemas/v1/discovery.schema.json +0 -0
- package/schemas/v1/envelope.schema.json +0 -0
- package/schemas/v1/error-registry.json +0 -0
- package/dist/src/mcpAdapter.d.ts +0 -28
- package/dist/src/mcpAdapter.js +0 -281
|
@@ -1,28 +1,188 @@
|
|
|
1
|
-
import type { LAFSAgentAction } from
|
|
1
|
+
import type { LAFSAgentAction } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A single entry in the LAFS error-code registry.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Each entry defines the canonical error code, its category, human-readable
|
|
7
|
+
* description, retry semantics, and transport-specific status mappings.
|
|
8
|
+
*/
|
|
2
9
|
export interface RegistryCode {
|
|
10
|
+
/** The canonical LAFS error code (e.g., `"E_FORMAT_CONFLICT"`). */
|
|
3
11
|
code: string;
|
|
12
|
+
/** Broad error category (e.g., `"client"`, `"server"`, `"auth"`). */
|
|
4
13
|
category: string;
|
|
14
|
+
/** Human-readable description of when this error occurs. */
|
|
5
15
|
description: string;
|
|
16
|
+
/** Whether the operation that produced this error is safe to retry. */
|
|
6
17
|
retryable: boolean;
|
|
18
|
+
/** HTTP status code mapped to this error. */
|
|
7
19
|
httpStatus: number;
|
|
20
|
+
/** gRPC status string mapped to this error. */
|
|
8
21
|
grpcStatus: string;
|
|
22
|
+
/** CLI exit code mapped to this error. */
|
|
9
23
|
cliExit: number;
|
|
24
|
+
/**
|
|
25
|
+
* Suggested agent action from the registry (e.g., `"retry"`, `"abort"`).
|
|
26
|
+
* @defaultValue undefined
|
|
27
|
+
*/
|
|
10
28
|
agentAction?: string;
|
|
29
|
+
/**
|
|
30
|
+
* RFC 9457 type URI for this error, used in Problem Details responses.
|
|
31
|
+
* @defaultValue undefined
|
|
32
|
+
*/
|
|
11
33
|
typeUri?: string;
|
|
34
|
+
/**
|
|
35
|
+
* URL pointing to human-readable documentation for this error.
|
|
36
|
+
* @defaultValue undefined
|
|
37
|
+
*/
|
|
12
38
|
docUrl?: string;
|
|
13
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Top-level shape of the LAFS error-registry JSON file.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Contains a version string for schema evolution and the complete list
|
|
45
|
+
* of registered error codes.
|
|
46
|
+
*/
|
|
14
47
|
export interface ErrorRegistry {
|
|
48
|
+
/** Semantic version of the error-registry schema. */
|
|
15
49
|
version: string;
|
|
50
|
+
/** All registered LAFS error codes. */
|
|
16
51
|
codes: RegistryCode[];
|
|
17
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* A transport-specific status value resolved from the error registry.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* For HTTP and CLI, `value` is a number (status code / exit code).
|
|
58
|
+
* For gRPC, `value` is a string (status name).
|
|
59
|
+
*/
|
|
18
60
|
export type TransportMapping = {
|
|
19
|
-
transport
|
|
61
|
+
/** The transport protocol this mapping applies to. */
|
|
62
|
+
transport: 'http' | 'grpc' | 'cli';
|
|
63
|
+
/** The transport-specific status value (numeric for HTTP/CLI, string for gRPC). */
|
|
20
64
|
value: number | string;
|
|
21
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Loads the full LAFS error registry from the bundled JSON.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Returns the parsed `error-registry.json` as a typed {@link ErrorRegistry}.
|
|
71
|
+
*
|
|
72
|
+
* @returns The complete error registry with version and all registered codes.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const registry = getErrorRegistry();
|
|
77
|
+
* console.log(registry.version, registry.codes.length);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
22
80
|
export declare function getErrorRegistry(): ErrorRegistry;
|
|
81
|
+
/**
|
|
82
|
+
* Checks whether a given error code exists in the LAFS error registry.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Performs a linear scan of the registry codes array. Suitable for
|
|
86
|
+
* validation-time lookups; not optimized for hot-path usage.
|
|
87
|
+
*
|
|
88
|
+
* @param code - The error code string to look up (e.g., `"E_FORMAT_CONFLICT"`).
|
|
89
|
+
* @returns `true` if the code is registered, `false` otherwise.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* isRegisteredErrorCode('E_FORMAT_CONFLICT'); // true
|
|
94
|
+
* isRegisteredErrorCode('E_UNKNOWN'); // false
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
23
97
|
export declare function isRegisteredErrorCode(code: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves the full registry entry for a given error code.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* Returns `undefined` when the code is not found, allowing callers to
|
|
103
|
+
* distinguish between "code exists" and "code absent" without exceptions.
|
|
104
|
+
*
|
|
105
|
+
* @param code - The error code string to look up.
|
|
106
|
+
* @returns The matching {@link RegistryCode} or `undefined` if not found.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const entry = getRegistryCode('E_FORMAT_CONFLICT');
|
|
111
|
+
* if (entry) {
|
|
112
|
+
* console.log(entry.httpStatus); // 409
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
24
116
|
export declare function getRegistryCode(code: string): RegistryCode | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Returns the default agent action for a given error code.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* Delegates to {@link getRegistryCode} and extracts the `agentAction`
|
|
122
|
+
* field. Returns `undefined` when the code is unregistered or has no
|
|
123
|
+
* default action.
|
|
124
|
+
*
|
|
125
|
+
* @param code - The error code string to look up.
|
|
126
|
+
* @returns The {@link LAFSAgentAction} or `undefined` if unavailable.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const action = getAgentAction('E_RATE_LIMIT');
|
|
131
|
+
* console.log(action); // "retry"
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
25
134
|
export declare function getAgentAction(code: string): LAFSAgentAction | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the RFC 9457 type URI for a given error code.
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* Useful for constructing Problem Details responses. Returns `undefined`
|
|
140
|
+
* when the code is unregistered or has no type URI.
|
|
141
|
+
*
|
|
142
|
+
* @param code - The error code string to look up.
|
|
143
|
+
* @returns The type URI string or `undefined` if unavailable.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const uri = getTypeUri('E_VALIDATION');
|
|
148
|
+
* // "https://lafs.dev/errors/E_VALIDATION"
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
26
151
|
export declare function getTypeUri(code: string): string | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Returns the documentation URL for a given error code.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* Provides a link to human-readable docs for the error. Returns
|
|
157
|
+
* `undefined` when the code is unregistered or has no doc URL.
|
|
158
|
+
*
|
|
159
|
+
* @param code - The error code string to look up.
|
|
160
|
+
* @returns The documentation URL string or `undefined` if unavailable.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* const url = getDocUrl('E_VALIDATION');
|
|
165
|
+
* // "https://lafs.dev/docs/errors/E_VALIDATION"
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
27
168
|
export declare function getDocUrl(code: string): string | undefined;
|
|
28
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Resolves the transport-specific status value for a given error code and transport.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* Looks up the registry entry and extracts `httpStatus`, `grpcStatus`, or
|
|
174
|
+
* `cliExit` depending on the requested transport. Returns `null` when the
|
|
175
|
+
* error code is not registered.
|
|
176
|
+
*
|
|
177
|
+
* @param code - The error code string to look up.
|
|
178
|
+
* @param transport - The transport protocol to resolve a mapping for.
|
|
179
|
+
* @returns A {@link TransportMapping} or `null` if the code is unregistered.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const mapping = getTransportMapping('E_NOT_FOUND', 'http');
|
|
184
|
+
* console.log(mapping); // { transport: 'http', value: 404 }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare function getTransportMapping(code: string, transport: 'http' | 'grpc' | 'cli'): TransportMapping | null;
|
|
188
|
+
//# sourceMappingURL=errorRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorRegistry.d.ts","sourceRoot":"","sources":["../../src/errorRegistry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,SAAS,EAAE,OAAO,CAAC;IACnB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,KAAK,EAAE,YAAY,EAAE,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sDAAsD;IACtD,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IACnC,mFAAmF;IACnF,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG3D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEtE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAGxE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG1D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,GACjC,gBAAgB,GAAG,IAAI,CAazB"}
|
|
@@ -1,36 +1,152 @@
|
|
|
1
|
-
import errorRegistry from
|
|
1
|
+
import errorRegistry from '../schemas/v1/error-registry.json' with { type: 'json' };
|
|
2
|
+
/**
|
|
3
|
+
* Loads the full LAFS error registry from the bundled JSON.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Returns the parsed `error-registry.json` as a typed {@link ErrorRegistry}.
|
|
7
|
+
*
|
|
8
|
+
* @returns The complete error registry with version and all registered codes.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const registry = getErrorRegistry();
|
|
13
|
+
* console.log(registry.version, registry.codes.length);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
2
16
|
export function getErrorRegistry() {
|
|
3
17
|
return errorRegistry;
|
|
4
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether a given error code exists in the LAFS error registry.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* Performs a linear scan of the registry codes array. Suitable for
|
|
24
|
+
* validation-time lookups; not optimized for hot-path usage.
|
|
25
|
+
*
|
|
26
|
+
* @param code - The error code string to look up (e.g., `"E_FORMAT_CONFLICT"`).
|
|
27
|
+
* @returns `true` if the code is registered, `false` otherwise.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* isRegisteredErrorCode('E_FORMAT_CONFLICT'); // true
|
|
32
|
+
* isRegisteredErrorCode('E_UNKNOWN'); // false
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
5
35
|
export function isRegisteredErrorCode(code) {
|
|
6
36
|
const registry = getErrorRegistry();
|
|
7
37
|
return registry.codes.some((item) => item.code === code);
|
|
8
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the full registry entry for a given error code.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Returns `undefined` when the code is not found, allowing callers to
|
|
44
|
+
* distinguish between "code exists" and "code absent" without exceptions.
|
|
45
|
+
*
|
|
46
|
+
* @param code - The error code string to look up.
|
|
47
|
+
* @returns The matching {@link RegistryCode} or `undefined` if not found.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const entry = getRegistryCode('E_FORMAT_CONFLICT');
|
|
52
|
+
* if (entry) {
|
|
53
|
+
* console.log(entry.httpStatus); // 409
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
9
57
|
export function getRegistryCode(code) {
|
|
10
58
|
return getErrorRegistry().codes.find((item) => item.code === code);
|
|
11
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the default agent action for a given error code.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Delegates to {@link getRegistryCode} and extracts the `agentAction`
|
|
65
|
+
* field. Returns `undefined` when the code is unregistered or has no
|
|
66
|
+
* default action.
|
|
67
|
+
*
|
|
68
|
+
* @param code - The error code string to look up.
|
|
69
|
+
* @returns The {@link LAFSAgentAction} or `undefined` if unavailable.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const action = getAgentAction('E_RATE_LIMIT');
|
|
74
|
+
* console.log(action); // "retry"
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
12
77
|
export function getAgentAction(code) {
|
|
13
78
|
const entry = getRegistryCode(code);
|
|
14
79
|
return entry?.agentAction;
|
|
15
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the RFC 9457 type URI for a given error code.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Useful for constructing Problem Details responses. Returns `undefined`
|
|
86
|
+
* when the code is unregistered or has no type URI.
|
|
87
|
+
*
|
|
88
|
+
* @param code - The error code string to look up.
|
|
89
|
+
* @returns The type URI string or `undefined` if unavailable.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const uri = getTypeUri('E_VALIDATION');
|
|
94
|
+
* // "https://lafs.dev/errors/E_VALIDATION"
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
16
97
|
export function getTypeUri(code) {
|
|
17
98
|
const entry = getRegistryCode(code);
|
|
18
99
|
return entry?.typeUri;
|
|
19
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the documentation URL for a given error code.
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* Provides a link to human-readable docs for the error. Returns
|
|
106
|
+
* `undefined` when the code is unregistered or has no doc URL.
|
|
107
|
+
*
|
|
108
|
+
* @param code - The error code string to look up.
|
|
109
|
+
* @returns The documentation URL string or `undefined` if unavailable.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const url = getDocUrl('E_VALIDATION');
|
|
114
|
+
* // "https://lafs.dev/docs/errors/E_VALIDATION"
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
20
117
|
export function getDocUrl(code) {
|
|
21
118
|
const entry = getRegistryCode(code);
|
|
22
119
|
return entry?.docUrl;
|
|
23
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Resolves the transport-specific status value for a given error code and transport.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* Looks up the registry entry and extracts `httpStatus`, `grpcStatus`, or
|
|
126
|
+
* `cliExit` depending on the requested transport. Returns `null` when the
|
|
127
|
+
* error code is not registered.
|
|
128
|
+
*
|
|
129
|
+
* @param code - The error code string to look up.
|
|
130
|
+
* @param transport - The transport protocol to resolve a mapping for.
|
|
131
|
+
* @returns A {@link TransportMapping} or `null` if the code is unregistered.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const mapping = getTransportMapping('E_NOT_FOUND', 'http');
|
|
136
|
+
* console.log(mapping); // { transport: 'http', value: 404 }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
24
139
|
export function getTransportMapping(code, transport) {
|
|
25
140
|
const registryCode = getRegistryCode(code);
|
|
26
141
|
if (!registryCode) {
|
|
27
142
|
return null;
|
|
28
143
|
}
|
|
29
|
-
if (transport ===
|
|
144
|
+
if (transport === 'http') {
|
|
30
145
|
return { transport, value: registryCode.httpStatus };
|
|
31
146
|
}
|
|
32
|
-
if (transport ===
|
|
147
|
+
if (transport === 'grpc') {
|
|
33
148
|
return { transport, value: registryCode.grpcStatus };
|
|
34
149
|
}
|
|
35
150
|
return { transport, value: registryCode.cliExit };
|
|
36
151
|
}
|
|
152
|
+
//# sourceMappingURL=errorRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorRegistry.js","sourceRoot":"","sources":["../../src/errorRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,mCAAmC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAsEpF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAA8B,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;IACpC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,gBAAgB,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,KAAK,EAAE,WAA0C,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,KAAK,EAAE,OAAO,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,KAAK,EAAE,MAAM,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,SAAkC;IAElC,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,CAAC,UAAU,EAAE,CAAC;IACvD,CAAC;IACD,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,CAAC,UAAU,EAAE,CAAC;IACvD,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -1,67 +1,168 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Field extraction resolution for LAFS envelopes.
|
|
3
|
+
*
|
|
4
|
+
* Implements section 9.2 of the LAFS spec: `--field` extracts a single value
|
|
5
|
+
* as plain text (no envelope), `--fields` filters the JSON envelope to a subset,
|
|
6
|
+
* and `--mvi` controls envelope verbosity.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This module provides both resolution (flag parsing) and runtime extraction/filtering
|
|
10
|
+
* functions. The resolution layer is consumed by the unified resolver in `flagResolver.ts`.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.5.0
|
|
13
|
+
*/
|
|
14
|
+
import type { LAFSEnvelope, MVILevel } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Input flags for the field extraction layer.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Mutually exclusive: `fieldFlag` and `fieldsFlag` cannot both be set.
|
|
20
|
+
* Providing both causes an `E_FIELD_CONFLICT` error during resolution.
|
|
21
|
+
*/
|
|
2
22
|
export interface FieldExtractionInput {
|
|
3
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* `--field <name>`: extract a single field as plain text, discarding the envelope.
|
|
25
|
+
* @defaultValue undefined
|
|
26
|
+
*/
|
|
4
27
|
fieldFlag?: string;
|
|
5
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* `--fields <a,b,c>`: filter result to these fields while preserving the envelope.
|
|
30
|
+
* Accepts a comma-separated string or an array of field names.
|
|
31
|
+
* @defaultValue undefined
|
|
32
|
+
*/
|
|
6
33
|
fieldsFlag?: string | string[];
|
|
7
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* `--mvi <level>`: requested envelope verbosity level (client-requestable levels only).
|
|
36
|
+
* The `'custom'` level is server-set and not valid here.
|
|
37
|
+
* @defaultValue undefined
|
|
38
|
+
*/
|
|
8
39
|
mviFlag?: MVILevel | string;
|
|
9
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolved field extraction configuration.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Produced by {@link resolveFieldExtraction}. Contains the parsed and validated
|
|
46
|
+
* field extraction settings ready for use by extraction and filtering functions.
|
|
47
|
+
*/
|
|
10
48
|
export interface FieldExtractionResolution {
|
|
11
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* When set, extract this field as plain text, discarding the envelope.
|
|
51
|
+
* @defaultValue undefined
|
|
52
|
+
*/
|
|
12
53
|
field?: string;
|
|
13
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* When set, filter the result to these fields (envelope is preserved).
|
|
56
|
+
* @defaultValue undefined
|
|
57
|
+
*/
|
|
14
58
|
fields?: string[];
|
|
15
|
-
/** Resolved MVI level.
|
|
59
|
+
/** Resolved MVI level. Falls back to `'minimal'` when no valid flag is provided. */
|
|
16
60
|
mvi: MVILevel;
|
|
17
|
-
/** Which input determined the mvi value: 'flag' when mviFlag was valid, 'default' otherwise. */
|
|
18
|
-
mviSource:
|
|
61
|
+
/** Which input determined the mvi value: `'flag'` when mviFlag was valid, `'default'` otherwise. */
|
|
62
|
+
mviSource: 'flag' | 'default';
|
|
19
63
|
/**
|
|
20
|
-
* True when
|
|
21
|
-
* _meta.mvi = 'custom' in the response per
|
|
64
|
+
* True when `fields` are requested, indicating the server SHOULD set
|
|
65
|
+
* `_meta.mvi = 'custom'` in the response per section 9.1.
|
|
22
66
|
* Separate from the client-resolved mvi level.
|
|
23
67
|
*/
|
|
24
68
|
expectsCustomMvi: boolean;
|
|
25
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolve field extraction flags into a validated configuration.
|
|
72
|
+
*
|
|
73
|
+
* @param input - The field extraction flag inputs
|
|
74
|
+
* @returns The resolved extraction configuration with mvi level and source
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Parses and validates the `--field`, `--fields`, and `--mvi` flags. Throws
|
|
78
|
+
* `E_FIELD_CONFLICT` if both `--field` and `--fields` are provided. The `'custom'`
|
|
79
|
+
* MVI level is server-set per section 9.1 and is rejected as a client-requested value;
|
|
80
|
+
* invalid or absent `--mvi` falls back to `'minimal'`.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const resolution = resolveFieldExtraction({ fieldsFlag: 'id,title' });
|
|
85
|
+
* // => { fields: ['id', 'title'], mvi: 'minimal', mviSource: 'default', expectsCustomMvi: true }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @throws {@link LAFSFlagError} When both `fieldFlag` and `fieldsFlag` are set.
|
|
89
|
+
*/
|
|
26
90
|
export declare function resolveFieldExtraction(input: FieldExtractionInput): FieldExtractionResolution;
|
|
27
91
|
/**
|
|
28
92
|
* Extract a named field from a LAFS result object.
|
|
29
93
|
*
|
|
94
|
+
* @param result - The envelope result value (object, array, or null)
|
|
95
|
+
* @param field - The field name to extract
|
|
96
|
+
* @returns The extracted value, or `undefined` if not found at any level
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
30
99
|
* Handles four result shapes:
|
|
31
|
-
* 1. Direct array: result[0][field]
|
|
32
|
-
* 2. Direct:
|
|
33
|
-
* 3. Nested:
|
|
34
|
-
* 4. Array value:
|
|
100
|
+
* 1. Direct array: `result[0][field]` (list operations where result IS an array)
|
|
101
|
+
* 2. Direct: `result[field]` (flat result object)
|
|
102
|
+
* 3. Nested: `result.<key>[field]` (wrapper-entity, e.g. `result.task.title`)
|
|
103
|
+
* 4. Array value: `result.<key>[0][field]` (wrapper-array, e.g. `result.items[0].title`)
|
|
35
104
|
*
|
|
36
105
|
* Returns the value from the first match only. For array results (shapes 1
|
|
37
106
|
* and 4), returns the first element's field value only. To extract from all
|
|
38
|
-
* elements, iterate the array or use applyFieldFilter
|
|
107
|
+
* elements, iterate the array or use {@link applyFieldFilter}.
|
|
39
108
|
*
|
|
40
109
|
* When multiple wrapper keys contain the requested field (shapes 3 and 4),
|
|
41
110
|
* the first key in property insertion order wins.
|
|
42
111
|
*
|
|
43
|
-
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const result = { task: { id: 'T1', title: 'Fix bug' } };
|
|
115
|
+
* extractFieldFromResult(result, 'title'); // => 'Fix bug'
|
|
116
|
+
* ```
|
|
44
117
|
*/
|
|
45
118
|
export declare function extractFieldFromResult(result: LAFSEnvelope['result'], field: string): unknown;
|
|
46
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Extract a named field from an envelope's result.
|
|
121
|
+
*
|
|
122
|
+
* @param envelope - The LAFS envelope to extract from
|
|
123
|
+
* @param field - The field name to extract
|
|
124
|
+
* @returns The extracted value, or `undefined` if not found
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* Convenience wrapper around {@link extractFieldFromResult} that accepts
|
|
128
|
+
* the full envelope and delegates to the result extraction logic.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const value = extractFieldFromEnvelope(envelope, 'title');
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
47
135
|
export declare function extractFieldFromEnvelope(envelope: LAFSEnvelope, field: string): unknown;
|
|
48
136
|
/**
|
|
49
137
|
* Filter result fields in a LAFS envelope to the requested subset.
|
|
50
138
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* 3. Wrapper-entity: project nested entity's keys, preserve wrapper
|
|
55
|
-
* 4. Wrapper-array: project each element's keys, preserve wrapper
|
|
139
|
+
* @param envelope - The LAFS envelope whose result will be filtered
|
|
140
|
+
* @param fields - Array of field names to retain in the result
|
|
141
|
+
* @returns A new envelope with the filtered result and `_meta.mvi` set to `'custom'`
|
|
56
142
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Handles the same four result shapes as {@link extractFieldFromResult}:
|
|
145
|
+
* 1. Direct array: project each element
|
|
146
|
+
* 2. Flat result: project top-level keys
|
|
147
|
+
* 3. Wrapper-entity: project nested entity's keys, preserve wrapper
|
|
148
|
+
* 4. Wrapper-array: project each element's keys, preserve wrapper
|
|
149
|
+
*
|
|
150
|
+
* Sets `_meta.mvi = 'custom'` per section 9.1.
|
|
151
|
+
* Returns a new envelope with a new `_meta` object. Result values are not
|
|
59
152
|
* deep-cloned; nested object references are shared with the original.
|
|
60
|
-
* Unknown field names are silently omitted per
|
|
153
|
+
* Unknown field names are silently omitted per section 9.2.
|
|
61
154
|
*
|
|
62
155
|
* When result is a wrapper (shapes 3/4) with multiple keys, each key is
|
|
63
156
|
* projected independently. Primitive values at the wrapper level (numbers,
|
|
64
|
-
* strings, booleans) are preserved as-is
|
|
157
|
+
* strings, booleans) are preserved as-is; field filtering is applied to nested
|
|
65
158
|
* entity or array keys only, not to the wrapper's own primitive keys.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const filtered = applyFieldFilter(envelope, ['id', 'title']);
|
|
163
|
+
* // filtered.result contains only 'id' and 'title' fields
|
|
164
|
+
* // filtered._meta.mvi === 'custom'
|
|
165
|
+
* ```
|
|
66
166
|
*/
|
|
67
167
|
export declare function applyFieldFilter(envelope: LAFSEnvelope, fields: string[]): LAFSEnvelope;
|
|
168
|
+
//# sourceMappingURL=fieldExtraction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldExtraction.d.ts","sourceRoot":"","sources":["../../src/fieldExtraction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGzD;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,oFAAoF;IACpF,GAAG,EAAE,QAAQ,CAAC;IACd,oGAAoG;IACpG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,oBAAoB,GAAG,yBAAyB,CAmC7F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CA4B7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,CAuCvF"}
|