@noego/trust 0.5.1-dev.2 → 0.5.1-dev.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/README.md +155 -0
- package/dist/{baseline-D0Ok-NGU.d.ts → baseline-DMNO7IAl.d.ts} +20 -2
- package/dist/{chunk-V4FYZG5Q.js → chunk-2MSSO67W.js} +2 -2
- package/dist/{chunk-P4VFMA2A.js → chunk-3IIEQHH2.js} +382 -12
- package/dist/chunk-3IIEQHH2.js.map +1 -0
- package/dist/{chunk-RVTPDLEW.js → chunk-VJGGEY4G.js} +3481 -3456
- package/dist/chunk-VJGGEY4G.js.map +1 -0
- package/dist/cli/index.js +6 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/eslint/index.d.ts +5 -2
- package/dist/eslint/index.js +49 -12
- package/dist/eslint/index.js.map +1 -1
- package/dist/index.cjs +33 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -5
- package/dist/index.d.ts +66 -5
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/dist/native/trust_native_wasm.wasm +0 -0
- package/package.json +4 -4
- package/dist/chunk-P4VFMA2A.js.map +0 -1
- package/dist/chunk-RVTPDLEW.js.map +0 -1
- /package/dist/{chunk-V4FYZG5Q.js.map → chunk-2MSSO67W.js.map} +0 -0
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TypeScript, a as TsconfigMapping, Z as ZoneGroup, F as Finding } from '../baseline-
|
|
2
|
-
export { B as BaselineCounts, b as BaselineDelta, c as BaselineFinding, d as BaselineScope, e as LineDirective, W as WHOLE_BASELINE, f as Zone, g as Zones, h as compareToBaseline, i as countFindings, j as describeBaselineDelta, k as directiveDirectlyAbove, l as directiveReason, m as groupMatches, n as isNamedDirective, o as lineDirectivesIn, p as loadTypeScript, q as matchesPatterns, r as nearestPackageName, s as nodeBelow, t as normalizePattern, u as parseBaseline, v as readBaseline, w as realpathOrSelf, x as relativeInside, y as serializeBaseline, z as toPosix, A as updateBaseline } from '../baseline-
|
|
1
|
+
import { T as TypeScript, a as TsconfigMapping, Z as ZoneGroup, F as Finding } from '../baseline-DMNO7IAl.js';
|
|
2
|
+
export { B as BaselineCounts, b as BaselineDelta, c as BaselineFinding, d as BaselineScope, e as LineDirective, W as WHOLE_BASELINE, f as Zone, g as Zones, h as compareToBaseline, i as countFindings, j as describeBaselineDelta, k as directiveDirectlyAbove, l as directiveReason, m as groupMatches, n as isNamedDirective, o as lineDirectivesIn, p as loadTypeScript, q as matchesPatterns, r as nearestPackageName, s as nodeBelow, t as normalizePattern, u as parseBaseline, v as readBaseline, w as realpathOrSelf, x as relativeInside, y as serializeBaseline, z as toPosix, A as updateBaseline } from '../baseline-DMNO7IAl.js';
|
|
3
3
|
import * as TS from 'typescript';
|
|
4
4
|
|
|
5
5
|
/** Absolute paths, sorted and deduplicated: named files as-is, directories walked for .ts/.tsx. */
|
package/dist/core/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
formatWalkFailure,
|
|
6
6
|
relativeTo,
|
|
7
7
|
resolveFiles
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-2MSSO67W.js";
|
|
9
9
|
import {
|
|
10
10
|
WHOLE_BASELINE,
|
|
11
11
|
Zones,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
sourceFileOf,
|
|
35
35
|
toPosix,
|
|
36
36
|
updateBaseline
|
|
37
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-VJGGEY4G.js";
|
|
38
38
|
|
|
39
39
|
// src/core/tool-config.ts
|
|
40
40
|
import { existsSync, readFileSync } from "fs";
|
package/dist/eslint/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as eslint from 'eslint';
|
|
2
2
|
import { Linter, ESLint } from 'eslint';
|
|
3
|
-
import { g as Zones, O as OriginResolver, C as TrustRuleSettings, T as TypeScript, D as TrustConfig, E as OriginInfo, G as CatchProblem } from '../baseline-
|
|
4
|
-
export { H as ACCEPT_DIRECTIVE, I as ACCEPT_DIRECTIVE_MESSAGES, J as BOUNDARY_MESSAGES, K as BOUNDARY_RULE, B as BaselineCounts, b as BaselineDelta, d as BaselineScope, L as BoundaryGroup, M as BoundaryOrigin, N as CATCH_ORIGIN, P as DEFAULT_RULE_SETTINGS, Q as DIRECTIVE_ORIGIN, R as DROPPED_RESULT_MESSAGES, S as DROPPED_RESULT_RULE, U as DroppedResultOrigin, F as Finding, V as LoadTrustConfigOptions, X as OptInRule, Y as REDUNDANT_GUARD_MESSAGES, _ as REDUNDANT_GUARD_ORIGIN, $ as REDUNDANT_GUARD_RULE, a0 as RuleSwitch, a1 as THROW_MESSAGES, a2 as THROW_RULE, a3 as
|
|
3
|
+
import { g as Zones, O as OriginResolver, C as TrustRuleSettings, T as TypeScript, D as TrustConfig, E as OriginInfo, G as CatchProblem } from '../baseline-DMNO7IAl.js';
|
|
4
|
+
export { H as ACCEPT_DIRECTIVE, I as ACCEPT_DIRECTIVE_MESSAGES, J as BOUNDARY_MESSAGES, K as BOUNDARY_RULE, B as BaselineCounts, b as BaselineDelta, d as BaselineScope, L as BoundaryGroup, M as BoundaryOrigin, N as CATCH_ORIGIN, P as DEFAULT_RULE_SETTINGS, Q as DIRECTIVE_ORIGIN, R as DROPPED_RESULT_MESSAGES, S as DROPPED_RESULT_RULE, U as DroppedResultOrigin, F as Finding, V as LoadTrustConfigOptions, X as OptInRule, Y as REDUNDANT_GUARD_MESSAGES, _ as REDUNDANT_GUARD_ORIGIN, $ as REDUNDANT_GUARD_RULE, a0 as RuleSwitch, a1 as THROW_MESSAGES, a2 as THROW_RULE, a3 as TRUSTED_STATE_MESSAGES, a4 as TRUSTED_STATE_RULE, a5 as TYPE_CLAIM_KINDS, a6 as TYPE_CLAIM_MESSAGES, a7 as TYPE_CLAIM_RULE, a8 as TrustConfigError, a9 as TrustEntry, aa as TrustLevel, ab as TrustedStateOrigin, a as TsconfigMapping, ac as TypeClaimOrigin, ad as UNANALYZABLE_ORIGIN, ae as UNTRUSTED_CALL_MESSAGES, af as UNTRUSTED_CALL_RULE, ag as UNTRUSTED_VALUE_MESSAGES, ah as UNTRUSTED_VALUE_RULE, ai as UntrustedCallbacks, aj as UntrustedEntry, ak as VALIDATOR_DIRECTIVE, W as WHOLE_BASELINE, f as Zone, Z as ZoneGroup, h as compareToBaseline, i as countFindings, al as effectiveTrustList, am as effectiveTypeTrustList, an as isInsideValidator, ao as isMarkedValidator, ap as isRuleEnabled, aq as loadTrustConfig, ar as normalizeOrigin, u as parseBaseline, y as serializeBaseline, A as updateBaseline } from '../baseline-DMNO7IAl.js';
|
|
5
5
|
import * as TS from 'typescript';
|
|
6
6
|
|
|
7
7
|
interface PresetDefinition {
|
|
@@ -115,6 +115,8 @@ declare class TrustPolicy {
|
|
|
115
115
|
isErrType(type: TS.Type): boolean;
|
|
116
116
|
/** 'ok' | 'err' when the type is @noego/trust's Ok/Err (by the declaration of its `ok` property). */
|
|
117
117
|
resultVariant(type: TS.Type): 'ok' | 'err' | null;
|
|
118
|
+
/** null: stateless (or not Ok); undefined: non-literal state; array: literal states. */
|
|
119
|
+
okStates(type: TS.Type): readonly string[] | null | undefined;
|
|
118
120
|
/** Name of the @noego/trust function a call resolves to (`err`, `tryResult`, …), else null. */
|
|
119
121
|
trustFunctionName(node: TS.CallExpression): string | null;
|
|
120
122
|
}
|
|
@@ -157,6 +159,7 @@ declare const rules: {
|
|
|
157
159
|
'type-claim': eslint.Rule.RuleModule;
|
|
158
160
|
'untrusted-value': eslint.Rule.RuleModule;
|
|
159
161
|
'dropped-result': eslint.Rule.RuleModule;
|
|
162
|
+
'trusted-state': eslint.Rule.RuleModule;
|
|
160
163
|
'redundant-guard': eslint.Rule.RuleModule;
|
|
161
164
|
'boundary-result': eslint.Rule.RuleModule;
|
|
162
165
|
};
|
package/dist/eslint/index.js
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
redundantGuardData,
|
|
20
20
|
redundantGuardsIn,
|
|
21
21
|
throwProblem,
|
|
22
|
+
trustedStateContext,
|
|
23
|
+
trustedStatesIn,
|
|
22
24
|
typeClaimContext,
|
|
23
25
|
typeClaimsIn,
|
|
24
26
|
typedGuardContext,
|
|
@@ -29,7 +31,7 @@ import {
|
|
|
29
31
|
untrustedValueData,
|
|
30
32
|
untrustedValueMessageId,
|
|
31
33
|
untrustedValuesIn
|
|
32
|
-
} from "../chunk-
|
|
34
|
+
} from "../chunk-3IIEQHH2.js";
|
|
33
35
|
import {
|
|
34
36
|
ACCEPT_DIRECTIVE,
|
|
35
37
|
ACCEPT_DIRECTIVE_MESSAGES,
|
|
@@ -47,6 +49,8 @@ import {
|
|
|
47
49
|
REDUNDANT_GUARD_RULE,
|
|
48
50
|
THROW_MESSAGES,
|
|
49
51
|
THROW_RULE,
|
|
52
|
+
TRUSTED_STATE_MESSAGES,
|
|
53
|
+
TRUSTED_STATE_RULE,
|
|
50
54
|
TYPE_CLAIM_KINDS,
|
|
51
55
|
TYPE_CLAIM_MESSAGES,
|
|
52
56
|
TYPE_CLAIM_RULE,
|
|
@@ -73,7 +77,7 @@ import {
|
|
|
73
77
|
parseBaseline,
|
|
74
78
|
serializeBaseline,
|
|
75
79
|
updateBaseline
|
|
76
|
-
} from "../chunk-
|
|
80
|
+
} from "../chunk-VJGGEY4G.js";
|
|
77
81
|
|
|
78
82
|
// src/eslint/rule-setup.ts
|
|
79
83
|
import { resolve } from "path";
|
|
@@ -200,8 +204,37 @@ var rule2 = {
|
|
|
200
204
|
};
|
|
201
205
|
var dropped_result_default = rule2;
|
|
202
206
|
|
|
203
|
-
// src/eslint/rules/
|
|
207
|
+
// src/eslint/rules/trusted-state.ts
|
|
204
208
|
var rule3 = {
|
|
209
|
+
meta: {
|
|
210
|
+
type: "problem",
|
|
211
|
+
docs: { description: "Require distinct success outcomes to use literal states." },
|
|
212
|
+
schema: OPTIONS_SCHEMA,
|
|
213
|
+
messages: TRUSTED_STATE_MESSAGES
|
|
214
|
+
},
|
|
215
|
+
create(context) {
|
|
216
|
+
const setup = setupRule(context);
|
|
217
|
+
if (!isRuleEnabled(setup, TRUSTED_STATE_RULE)) return {};
|
|
218
|
+
if (!setup.policy || !setup.checker) {
|
|
219
|
+
throw new Error("trusted-state requires typed linting (parserOptions.projectService or project).");
|
|
220
|
+
}
|
|
221
|
+
if (setup.zone !== "checked") return {};
|
|
222
|
+
const { ts, tsNode, checker, policy } = setup;
|
|
223
|
+
const { sourceCode } = context;
|
|
224
|
+
return {
|
|
225
|
+
Program(node) {
|
|
226
|
+
const sourceFile = tsNode(node, ts.isSourceFile);
|
|
227
|
+
for (const dropped of trustedStatesIn(sourceFile, trustedStateContext(ts, checker, policy))) {
|
|
228
|
+
context.report({ loc: sourceCode.getLocFromIndex(dropped.start), messageId: dropped.origin, data: dropped.data });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var trusted_state_default = rule3;
|
|
235
|
+
|
|
236
|
+
// src/eslint/rules/redundant-guard.ts
|
|
237
|
+
var rule4 = {
|
|
205
238
|
meta: {
|
|
206
239
|
type: "problem",
|
|
207
240
|
docs: { description: "Report every guard (Trust.try / Trust.tryAsync / try-catch) around code that cannot fail." },
|
|
@@ -228,10 +261,10 @@ var rule3 = {
|
|
|
228
261
|
};
|
|
229
262
|
}
|
|
230
263
|
};
|
|
231
|
-
var redundant_guard_default =
|
|
264
|
+
var redundant_guard_default = rule4;
|
|
232
265
|
|
|
233
266
|
// src/eslint/rules/throw-must-return-result.ts
|
|
234
|
-
var
|
|
267
|
+
var rule5 = {
|
|
235
268
|
meta: {
|
|
236
269
|
type: "problem",
|
|
237
270
|
docs: { description: "Require every throw to be caught locally and returned as Result.err." },
|
|
@@ -260,10 +293,10 @@ var rule4 = {
|
|
|
260
293
|
};
|
|
261
294
|
}
|
|
262
295
|
};
|
|
263
|
-
var throw_must_return_result_default =
|
|
296
|
+
var throw_must_return_result_default = rule5;
|
|
264
297
|
|
|
265
298
|
// src/eslint/rules/type-claim.ts
|
|
266
|
-
var
|
|
299
|
+
var rule6 = {
|
|
267
300
|
meta: {
|
|
268
301
|
type: "problem",
|
|
269
302
|
docs: { description: "Report every place a type is claimed instead of proven." },
|
|
@@ -291,10 +324,10 @@ var rule5 = {
|
|
|
291
324
|
};
|
|
292
325
|
}
|
|
293
326
|
};
|
|
294
|
-
var type_claim_default =
|
|
327
|
+
var type_claim_default = rule6;
|
|
295
328
|
|
|
296
329
|
// src/eslint/rules/untrusted-call-must-return-result.ts
|
|
297
|
-
var
|
|
330
|
+
var rule7 = {
|
|
298
331
|
meta: {
|
|
299
332
|
type: "problem",
|
|
300
333
|
docs: { description: "Require calls into untrusted code to be handled locally and returned as Result.err." },
|
|
@@ -317,10 +350,10 @@ var rule6 = {
|
|
|
317
350
|
return { CallExpression: check, NewExpression: check };
|
|
318
351
|
}
|
|
319
352
|
};
|
|
320
|
-
var untrusted_call_must_return_result_default =
|
|
353
|
+
var untrusted_call_must_return_result_default = rule7;
|
|
321
354
|
|
|
322
355
|
// src/eslint/rules/untrusted-value.ts
|
|
323
|
-
var
|
|
356
|
+
var rule8 = {
|
|
324
357
|
meta: {
|
|
325
358
|
type: "problem",
|
|
326
359
|
docs: { description: "Report every use of a value whose type was declared by an origin that is not type-trusted." },
|
|
@@ -352,7 +385,7 @@ var rule7 = {
|
|
|
352
385
|
};
|
|
353
386
|
}
|
|
354
387
|
};
|
|
355
|
-
var untrusted_value_default =
|
|
388
|
+
var untrusted_value_default = rule8;
|
|
356
389
|
|
|
357
390
|
// src/eslint/index.ts
|
|
358
391
|
var rules = {
|
|
@@ -361,6 +394,7 @@ var rules = {
|
|
|
361
394
|
"type-claim": type_claim_default,
|
|
362
395
|
"untrusted-value": untrusted_value_default,
|
|
363
396
|
"dropped-result": dropped_result_default,
|
|
397
|
+
"trusted-state": trusted_state_default,
|
|
364
398
|
"redundant-guard": redundant_guard_default,
|
|
365
399
|
"boundary-result": boundary_result_default
|
|
366
400
|
};
|
|
@@ -384,6 +418,7 @@ function typedConfig(options) {
|
|
|
384
418
|
"trust/type-claim": [severity, ruleOptions],
|
|
385
419
|
"trust/untrusted-value": [severity, ruleOptions],
|
|
386
420
|
"trust/dropped-result": [severity, ruleOptions],
|
|
421
|
+
"trust/trusted-state": [severity, ruleOptions],
|
|
387
422
|
"trust/redundant-guard": [severity, ruleOptions],
|
|
388
423
|
"trust/boundary-result": [severity, ruleOptions]
|
|
389
424
|
}
|
|
@@ -407,6 +442,8 @@ export {
|
|
|
407
442
|
REDUNDANT_GUARD_RULE,
|
|
408
443
|
THROW_MESSAGES,
|
|
409
444
|
THROW_RULE,
|
|
445
|
+
TRUSTED_STATE_MESSAGES,
|
|
446
|
+
TRUSTED_STATE_RULE,
|
|
410
447
|
TYPE_CLAIM_KINDS,
|
|
411
448
|
TYPE_CLAIM_MESSAGES,
|
|
412
449
|
TYPE_CLAIM_RULE,
|
package/dist/eslint/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/eslint/rule-setup.ts","../../src/eslint/rules/boundary-result.ts","../../src/eslint/rules/dropped-result.ts","../../src/eslint/rules/redundant-guard.ts","../../src/eslint/rules/throw-must-return-result.ts","../../src/eslint/rules/type-claim.ts","../../src/eslint/rules/untrusted-call-must-return-result.ts","../../src/eslint/rules/untrusted-value.ts","../../src/eslint/index.ts"],"sourcesContent":["// Shared per-file setup for both rules: trust config, file zone, guard context, and the mapping from\n// ESLint's ESTree nodes to the TypeScript nodes the shared rule logic (../core/rules.ts) works on.\nimport { resolve } from 'node:path';\nimport type { Rule } from 'eslint';\nimport type * as TS from 'typescript';\nimport { emptyTrustConfig, policyFor } from '../core/check-file.js';\nimport type { GuardContext } from '../core/guard.js';\nimport { nameBasedGuardContext, typedGuardContext } from '../core/rules.js';\nimport { loadTrustConfigCached, normalizeOrigin, type TrustConfig, type TrustRuleSettings } from './config.js';\nimport type { TrustPolicy } from './policy.js';\nimport { loadTypeScript, type TypeScript } from './typescript.js';\nimport { Zones, type Zone } from './zones.js';\n\nexport interface TrustRuleOptions {\n /** trust.config.json path, relative to the ESLint cwd. */\n readonly configFile?: string;\n /** Extra trusted origins (applied before the config chain). */\n readonly trust?: readonly string[];\n}\n\nexport const OPTIONS_SCHEMA = [\n {\n type: 'object',\n properties: {\n configFile: { type: 'string' },\n trust: { type: 'array', items: { type: 'string' } },\n },\n additionalProperties: false,\n },\n] as const;\n\ninterface ParserServices {\n readonly program?: TS.Program | null;\n readonly esTreeNodeToTSNodeMap?: { get(node: unknown): TS.Node };\n}\n\n/** ESTree node as ESLint hands it to a rule (ranges are always present). */\ntype EsNode = Rule.Node | { readonly range?: [number, number] };\n\nexport interface RuleSetup {\n readonly ts: TypeScript;\n readonly zone: Zone;\n readonly policy: TrustPolicy | null;\n readonly guardContext: GuardContext;\n /** Maps an ESTree node to its TypeScript node of the given kind. */\n readonly tsNode: <T extends TS.Node>(node: EsNode, is: (node: TS.Node) => node is T) => T;\n readonly checker: TS.TypeChecker | null;\n /** The program of typed linting (null without parser services). */\n readonly program: TS.Program | null;\n /** The loaded trust config (`boundaries`, `strict` globs, …). */\n readonly config: TrustConfig;\n /** The trust config's per-rule settings: an opt-in rule that is not on reports nothing. */\n readonly rules: TrustRuleSettings;\n /** The TypeScript source file of the linted file (its comments are read from it). */\n readonly sourceFile: () => TS.SourceFile;\n}\n\n/**\n * Without parser services (e.g. ESLint's default parser) the file is parsed once with TypeScript and\n * nodes are found by their source range, which ESTree and TypeScript agree on.\n */\nfunction rangeLocator(ts: TypeScript, context: Rule.RuleContext): Pick<RuleSetup, 'tsNode' | 'sourceFile'> {\n let parsed: TS.SourceFile | undefined;\n const sourceFile = (): TS.SourceFile => (parsed ??= ts.createSourceFile(context.filename, context.sourceCode.text, ts.ScriptTarget.Latest, true));\n return { tsNode: locate, sourceFile };\n function locate<T extends TS.Node>(node: EsNode, is: (node: TS.Node) => node is T): T {\n const file = sourceFile();\n const [start, end] = (node as { range: [number, number] }).range;\n let found: T | undefined;\n const visit = (candidate: TS.Node): void => {\n if (found || candidate.pos > start || candidate.end < end) return;\n if (candidate.end === end && candidate.getStart(file) === start && is(candidate)) found = candidate;\n else ts.forEachChild(candidate, visit);\n };\n visit(file);\n if (!found) throw new Error(`@noego/trust: no TypeScript node at ${context.filename}:${start}-${end}`);\n return found;\n }\n}\n\nfunction mapLocator(ts: TypeScript, context: Rule.RuleContext, map: NonNullable<ParserServices['esTreeNodeToTSNodeMap']>): Pick<RuleSetup, 'tsNode' | 'sourceFile'> {\n const tsNode = function mapped<T extends TS.Node>(node: EsNode, is: (node: TS.Node) => node is T): T {\n const target = map.get(node);\n if (!target || !is(target)) throw new Error(`@noego/trust: unexpected TypeScript node in ${context.filename}`);\n return target;\n };\n return { tsNode, sourceFile: () => tsNode(context.sourceCode.ast, ts.isSourceFile) };\n}\n\nexport function setupRule(context: Rule.RuleContext): RuleSetup {\n const options = (context.options[0] ?? {}) as TrustRuleOptions;\n const ts = loadTypeScript(context.cwd);\n const config = options.configFile ? loadTrustConfigCached(resolve(context.cwd, options.configFile)) : emptyTrustConfig(context.cwd);\n const services = context.sourceCode.parserServices as ParserServices | undefined;\n const program = services?.program ?? null;\n const map = services?.esTreeNodeToTSNodeMap;\n const { tsNode, sourceFile } = map ? mapLocator(ts, context, map) : rangeLocator(ts, context);\n if (!program || !map) {\n const zones = new Zones(config.rootDir, config.passthrough, config.ignore);\n return { ts, zone: zones.zoneOf(context.filename), policy: null, guardContext: nameBasedGuardContext(ts), tsNode, checker: null, program: null, config, rules: config.rules, sourceFile };\n }\n const checker = program.getTypeChecker();\n const policy = policyFor(ts, checker, config, (options.trust ?? []).map(normalizeOrigin));\n return {\n ts,\n zone: policy.zones.zoneOf(context.filename),\n policy,\n guardContext: typedGuardContext(ts, checker, policy),\n tsNode,\n checker,\n program,\n config,\n rules: config.rules,\n sourceFile,\n };\n}\n","// ESLint adapter for boundary-result: in a file the trust config names as a boundary (`boundaries`), every\n// exported function and public member whose return value can fail is reported, with the origin as messageId\n// (`returns-result`, `unproven-return`, `stale-exclude`, `overlapping-items`).\n// The decisions are the shared core rule (../../core/boundaries.ts), run once over the file's TypeScript\n// source; this file only reports them at their source positions. A stale-exclude finding belongs to the config\n// file, which ESLint cannot report into: it is reported at the start of the file the core attributes it to.\n// ESLint has no per-finding severity, so an unproven return is reported like the rest (`trust check` warns).\n// Off unless the trust config has `boundaries`, the same setting `trust check` honours. When on, it requires\n// typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { boundaryContext, boundaryFindingsIn } from '../../core/boundaries.js';\nimport { isStrictByConfig } from '../../core/check-file.js';\nimport { BOUNDARY_MESSAGES } from '../../core/messages.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { BOUNDARY_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every boundary (exported function or public member of a configured boundary file) whose return value can fail.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: BOUNDARY_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (setup.config.boundaries.length === 0) return {};\n if (!setup.policy || !setup.checker || !setup.program) {\n throw new Error('boundary-result requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy, program, config } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n const strict = isStrictByConfig(config, sourceFile.fileName);\n for (const found of boundaryFindingsIn(sourceFile, boundaryContext(ts, checker, program, policy, config), strict)) {\n context.report({ loc: sourceCode.getLocFromIndex(found.start), messageId: found.origin, data: { ...found.data } });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for dropped-result: a Result that can still fail must be passed up (returned) or handled\n// (Trust.decide / Trust.translate, a branch naming its kind); every place a failure is dropped instead is\n// reported, with the origin as messageId (`discarded`, `argument`, `stored`, `callback`, `return`, `end`,\n// `overwritten`).\n// The decisions are the shared core rule (../../core/dropped-results.ts), run once over the file's\n// TypeScript source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"dropped-result\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { droppedResultContext, droppedResultData, droppedResultsIn } from '../../core/dropped-results.js';\nimport { DROPPED_RESULT_MESSAGES, DROPPED_RESULT_RULE } from '../../core/messages.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { DROPPED_RESULT_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every place a Result that can still fail is dropped instead of returned or handled.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: DROPPED_RESULT_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, DROPPED_RESULT_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('dropped-result requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n for (const dropped of droppedResultsIn(sourceFile, droppedResultContext(ts, checker, policy))) {\n context.report({ loc: sourceCode.getLocFromIndex(dropped.start), messageId: dropped.origin, data: droppedResultData(dropped) });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for redundant-guard: a Trust.try / Trust.tryAsync (or a `try` whose `catch` returns\n// Result.err) around code that cannot fail — every call inside is trusted, first-party, or declared to return\n// a Result — invents a failure path; it is reported at the guard (messageId `redundant`).\n// The decisions are the shared core rule (../../core/redundant-guards.ts), run once over the file's TypeScript\n// source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"redundant-guard\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { REDUNDANT_GUARD_MESSAGES, REDUNDANT_GUARD_RULE } from '../../core/messages.js';\nimport { redundantGuardData, redundantGuardsIn } from '../../core/redundant-guards.js';\nimport { typedGuardContext } from '../../core/rules.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { REDUNDANT_GUARD_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every guard (Trust.try / Trust.tryAsync / try-catch) around code that cannot fail.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: REDUNDANT_GUARD_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, REDUNDANT_GUARD_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('redundant-guard requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n const guardContext = typedGuardContext(ts, checker, policy);\n for (const guard of redundantGuardsIn(sourceFile, { ts, checker, policy, guardContext })) {\n context.report({ loc: sourceCode.getLocFromIndex(guard.start), messageId: 'redundant', data: redundantGuardData(guard) });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for throw-must-return-result: every `throw` in checked code must be guarded —\n// inside a `try` (same function) whose `catch` returns Result.err(...) on every path, or inside a\n// Trust.try / Trust.tryAsync callback. The decision is the shared core rule (../../core/rules.ts);\n// this file only maps ESTree nodes to TypeScript nodes and reports.\n// Works with or without type information; with it, Result.err is recognised by declaration.\n// A `throw` in a statement marked `//trust:accept <reason>` is accepted, and every `//trust:accept` that\n// accepts nothing is reported here, at the comment (`directive`, ../../core/accept.ts). Without type\n// information an accept above a statement with nothing to accept (stale) cannot be told, so it is not reported.\nimport type { Rule } from 'eslint';\nimport { acceptanceOf, acceptDirectiveFindings } from '../../core/accept.js';\nimport { ACCEPT_DIRECTIVE_MESSAGES, THROW_MESSAGES } from '../../core/messages.js';\nimport { throwProblem } from '../../core/rules.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { THROW_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Require every throw to be caught locally and returned as Result.err.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: { ...THROW_MESSAGES, ...ACCEPT_DIRECTIVE_MESSAGES },\n },\n create(context) {\n const setup = setupRule(context);\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, guardContext, policy, checker } = setup;\n const { sourceCode } = context;\n return {\n Program() {\n const failureContext = policy && checker ? { ts, checker, policy, guardContext } : null;\n const sourceFile = setup.sourceFile();\n for (const found of acceptDirectiveFindings(ts, sourceFile, failureContext)) {\n const loc = { start: sourceCode.getLocFromIndex(found.directive.pos), end: sourceCode.getLocFromIndex(found.directive.end) };\n context.report({ loc, messageId: found.messageId, data: found.data });\n }\n },\n ThrowStatement(node) {\n const statement = tsNode(node, ts.isThrowStatement);\n const messageId = throwProblem(statement, guardContext);\n if (messageId && !acceptanceOf(ts, statement)) context.report({ node, messageId });\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for type-claim: every place a type is claimed instead of proven — a narrowing\n// `as`, `x!`, `any` in a typed position, a written type predicate, a caller-chosen generic return —\n// is reported, with the claim kind as messageId (`claim:as`, `claim:non-null`, `claim:any`,\n// `claim:predicate`, `claim:generic-return`; `unanalyzable` for a node whose type does not resolve;\n// `directive` for a `//trust:` comment that marks nothing). Claims inside a validator (a function marked\n// `//trust:validator_function`) are not reported.\n// The decisions are the shared core rule (../../core/type-claims.ts), run once over the file's\n// TypeScript source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"type-claim\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { TYPE_CLAIM_MESSAGES, TYPE_CLAIM_RULE } from '../../core/messages.js';\nimport { claimSpan, typeClaimContext, typeClaimsIn } from '../../core/type-claims.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { TYPE_CLAIM_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every place a type is claimed instead of proven.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: TYPE_CLAIM_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, TYPE_CLAIM_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('type-claim requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n for (const claim of typeClaimsIn(sourceFile, typeClaimContext(ts, checker, undefined, policy))) {\n const span = claimSpan(claim, sourceFile);\n const loc = { start: sourceCode.getLocFromIndex(span.start), end: sourceCode.getLocFromIndex(span.end) };\n context.report({ loc, messageId: claim.origin, data: claim.data });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for untrusted-call-must-return-result: every call or `new` whose callee is\n// untrusted must be guarded — inside a `try` (same function) whose `catch` returns Result.err(...)\n// on every path, or inside a Trust.try / Trust.tryAsync callback. Trust comes from\n// trust.config.json (see ../config.ts), from first-party checked code, or from a declared return\n// type of Result / Promise<Result> from @noego/trust. The decision is the shared core rule\n// (../../core/rules.ts); this file only maps ESTree nodes to TypeScript nodes and reports.\n// Requires typed linting (parserOptions.projectService or project). A call in a statement marked\n// `//trust:accept <reason>` is accepted (../../core/accept.ts).\nimport type { Rule } from 'eslint';\nimport type * as TS from 'typescript';\nimport { acceptanceOf } from '../../core/accept.js';\nimport { UNTRUSTED_CALL_MESSAGES } from '../../core/messages.js';\nimport { untrustedCallProblem } from '../../core/rules.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { UNTRUSTED_CALL_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Require calls into untrusted code to be handled locally and returned as Result.err.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: UNTRUSTED_CALL_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!setup.policy || !setup.checker) {\n throw new Error('untrusted-call-must-return-result requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, policy, tsNode, checker, guardContext } = setup;\n const isCallOrNew = (node: TS.Node): node is TS.CallExpression | TS.NewExpression => ts.isCallExpression(node) || ts.isNewExpression(node);\n\n function check(node: Rule.Node): void {\n const call = tsNode(node, isCallOrNew);\n const problem = untrustedCallProblem(call, policy, checker, guardContext);\n if (problem && !acceptanceOf(ts, call)) context.report({ node, messageId: problem.messageId, data: { origin: problem.origin } });\n }\n\n return { CallExpression: check, NewExpression: check };\n },\n};\n\nexport default rule;\n","// ESLint adapter for untrusted-value: type trust is opt-in. A value whose type was declared by an origin\n// that is not on the type-trust list (`trust_type` in trust.config.json) — a call's return, a parameter of\n// a callback the outside calls, a property or global it declares — may only be passed to a validator, kept\n// as `unknown`, or tested by a built-in check; any other use is reported with the origin named.\n// The decisions are the shared core rule (../../core/untrusted-values.ts), run once over the file's\n// TypeScript source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"untrusted-value\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport type * as TS from 'typescript';\nimport { UNTRUSTED_VALUE_MESSAGES, UNTRUSTED_VALUE_RULE } from '../../core/messages.js';\nimport {\n untrustedHandoffData,\n untrustedHandoffsIn,\n untrustedValueContext,\n untrustedValueData,\n untrustedValueMessageId,\n untrustedValuesIn,\n} from '../../core/untrusted-values.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { UNTRUSTED_VALUE_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every use of a value whose type was declared by an origin that is not type-trusted.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: UNTRUSTED_VALUE_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, UNTRUSTED_VALUE_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('untrusted-value requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n const valueContext = untrustedValueContext(ts, checker, policy);\n const locOf = (at: TS.Node) => ({ start: sourceCode.getLocFromIndex(at.getStart(sourceFile)), end: sourceCode.getLocFromIndex(at.getEnd()) });\n for (const value of untrustedValuesIn(sourceFile, valueContext)) {\n if (value.outcome !== 'finding') continue;\n context.report({ loc: locOf(value.node), messageId: untrustedValueMessageId(value), data: untrustedValueData(value) });\n }\n // `untrustedCallbacks: \"all\"`: functions handed to an origin that is not type-trusted, at the hand-off.\n for (const handoff of untrustedHandoffsIn(sourceFile, valueContext)) {\n context.report({ loc: locOf(handoff.node), messageId: 'handoff', data: untrustedHandoffData(handoff) });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// @noego/trust/eslint — ESLint plugin, trust config loader, and policy.\n//\n// import { typedConfig } from '@noego/trust/eslint';\n// export default [\n// ...typedConfig({ files: ['server/**/*.ts'], configFile: 'trust.config.json' }),\n// ];\nimport type { ESLint, Linter } from 'eslint';\nimport boundaryResult from './rules/boundary-result.js';\nimport droppedResult from './rules/dropped-result.js';\nimport redundantGuard from './rules/redundant-guard.js';\nimport throwMustReturnResult from './rules/throw-must-return-result.js';\nimport typeClaim from './rules/type-claim.js';\nimport untrustedCallMustReturnResult from './rules/untrusted-call-must-return-result.js';\nimport untrustedValue from './rules/untrusted-value.js';\n\nexport const rules = {\n 'untrusted-call-must-return-result': untrustedCallMustReturnResult,\n 'throw-must-return-result': throwMustReturnResult,\n 'type-claim': typeClaim,\n 'untrusted-value': untrustedValue,\n 'dropped-result': droppedResult,\n 'redundant-guard': redundantGuard,\n 'boundary-result': boundaryResult,\n};\n\nexport interface TypedConfigOptions {\n /** Files to check (flat-config globs). They must be in a tsconfig the project service can find. */\n readonly files: readonly string[];\n readonly ignores?: readonly string[];\n /** trust.config.json path relative to the ESLint cwd (default \"trust.config.json\"). */\n readonly configFile?: string;\n readonly severity?: Linter.RuleSeverity;\n}\n\nconst plugin: ESLint.Plugin = {\n meta: { name: '@noego/trust' },\n rules,\n};\n\nexport default plugin;\n\n/**\n * Flat config that registers the plugin as `trust` and enables its rules (the two trust rules, `type-claim`,\n * `untrusted-value` and `dropped-result`) for `files`. Needs typed linting. `type-claim`, `untrusted-value` and\n * `dropped-result` are opt-in: they report only when the trust config turns them on\n * (`\"rules\": { \"type-claim\": \"on\", \"untrusted-value\": \"on\", \"dropped-result\": \"on\" }`), the same settings\n * `trust check` / `trust baseline` honour, so ESLint and the CLI always agree.\n */\nexport function typedConfig(options: TypedConfigOptions): Linter.Config[] {\n const severity = options.severity ?? 'warn';\n const ruleOptions = { configFile: options.configFile ?? 'trust.config.json' };\n return [\n {\n name: '@noego/trust/typed',\n files: [...options.files],\n ignores: [...(options.ignores ?? [])],\n plugins: { trust: plugin },\n rules: {\n 'trust/untrusted-call-must-return-result': [severity, ruleOptions],\n 'trust/throw-must-return-result': [severity, ruleOptions],\n 'trust/type-claim': [severity, ruleOptions],\n 'trust/untrusted-value': [severity, ruleOptions],\n 'trust/dropped-result': [severity, ruleOptions],\n 'trust/redundant-guard': [severity, ruleOptions],\n 'trust/boundary-result': [severity, ruleOptions],\n },\n },\n ];\n}\n\nexport {\n DEFAULT_RULE_SETTINGS,\n effectiveTrustList,\n effectiveTypeTrustList,\n isRuleEnabled,\n loadTrustConfig,\n normalizeOrigin,\n TrustConfigError,\n type BoundaryGroup,\n type LoadTrustConfigOptions,\n type OptInRule,\n type RuleSwitch,\n type TrustConfig,\n type TrustEntry,\n type TrustLevel,\n type TrustRuleSettings,\n type TsconfigMapping,\n type UntrustedCallbacks,\n} from './config.js';\nexport { PRESETS, type PresetDefinition } from './presets.js';\nexport { entryMatches, TrustPolicy, type MatchedEntry, type TypeVerdict, type Verdict } from './policy.js';\nexport { OriginResolver, type OriginInfo } from './origin.js';\nexport { Zones, type Zone, type ZoneGroup } from './zones.js';\nexport { alwaysExits, catchProblem, guardOf, type Guard, type GuardContext } from '../core/guard.js';\nexport type { CatchProblem } from '../core/messages.js';\nexport {\n compareToBaseline,\n countFindings,\n parseBaseline,\n serializeBaseline,\n THROW_RULE,\n UNTRUSTED_CALL_RULE,\n updateBaseline,\n WHOLE_BASELINE,\n type BaselineCounts,\n type BaselineDelta,\n type BaselineScope,\n type Finding,\n} from '../core/baseline.js';\nexport { DIRECTIVE_ORIGIN, TYPE_CLAIM_KINDS, TYPE_CLAIM_RULE, UNANALYZABLE_ORIGIN, type TypeClaimOrigin } from '../core/messages.js';\nexport { CATCH_ORIGIN, UNTRUSTED_VALUE_RULE, type UntrustedEntry } from '../core/messages.js';\nexport { DROPPED_RESULT_RULE, type DroppedResultOrigin } from '../core/messages.js';\nexport { DROPPED_RESULT_MESSAGES } from './rules/dropped-result.js';\nexport { REDUNDANT_GUARD_ORIGIN, REDUNDANT_GUARD_RULE } from '../core/messages.js';\nexport { REDUNDANT_GUARD_MESSAGES } from './rules/redundant-guard.js';\nexport { BOUNDARY_RULE, type BoundaryOrigin } from '../core/messages.js';\nexport { BOUNDARY_MESSAGES } from './rules/boundary-result.js';\nexport { ACCEPT_DIRECTIVE, isInsideValidator, isMarkedValidator, VALIDATOR_DIRECTIVE } from '../core/validator.js';\nexport { ACCEPT_DIRECTIVE_MESSAGES } from '../core/messages.js';\nexport { THROW_MESSAGES } from './rules/throw-must-return-result.js';\nexport { TYPE_CLAIM_MESSAGES } from './rules/type-claim.js';\nexport { UNTRUSTED_CALL_MESSAGES } from './rules/untrusted-call-must-return-result.js';\nexport { UNTRUSTED_VALUE_MESSAGES } from './rules/untrusted-value.js';\nexport type { TrustRuleOptions } from './rule-setup.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,eAAe;AAkBjB,IAAM,iBAAiB;AAAA,EAC5B;AAAA,IACE,MAAM;AAAA,IACN,YAAY;AAAA,MACV,YAAY,EAAE,MAAM,SAAS;AAAA,MAC7B,OAAO,EAAE,MAAM,SAAS,OAAO,EAAE,MAAM,SAAS,EAAE;AAAA,IACpD;AAAA,IACA,sBAAsB;AAAA,EACxB;AACF;AAgCA,SAAS,aAAa,IAAgB,SAAqE;AACzG,MAAI;AACJ,QAAM,aAAa,MAAsB,WAAW,GAAG,iBAAiB,QAAQ,UAAU,QAAQ,WAAW,MAAM,GAAG,aAAa,QAAQ,IAAI;AAC/I,SAAO,EAAE,QAAQ,QAAQ,WAAW;AACpC,WAAS,OAA0B,MAAc,IAAqC;AACpF,UAAM,OAAO,WAAW;AACxB,UAAM,CAAC,OAAO,GAAG,IAAK,KAAqC;AAC3D,QAAI;AACJ,UAAM,QAAQ,CAAC,cAA6B;AAC1C,UAAI,SAAS,UAAU,MAAM,SAAS,UAAU,MAAM,IAAK;AAC3D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E,OAAO,OAAO;AAAA,MACzB,OAAO;AAAA,QACL,2CAA2C,CAAC,UAAU,WAAW;AAAA,QACjE,kCAAkC,CAAC,UAAU,WAAW;AAAA,QACxD,oBAAoB,CAAC,UAAU,WAAW;AAAA,QAC1C,yBAAyB,CAAC,UAAU,WAAW;AAAA,QAC/C,wBAAwB,CAAC,UAAU,WAAW;AAAA,QAC9C,yBAAyB,CAAC,UAAU,WAAW;AAAA,QAC/C,yBAAyB,CAAC,UAAU,WAAW;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AACF;","names":["rule","rule","rule","rule","rule","rule"]}
|
|
1
|
+
{"version":3,"sources":["../../src/eslint/rule-setup.ts","../../src/eslint/rules/boundary-result.ts","../../src/eslint/rules/dropped-result.ts","../../src/eslint/rules/trusted-state.ts","../../src/eslint/rules/redundant-guard.ts","../../src/eslint/rules/throw-must-return-result.ts","../../src/eslint/rules/type-claim.ts","../../src/eslint/rules/untrusted-call-must-return-result.ts","../../src/eslint/rules/untrusted-value.ts","../../src/eslint/index.ts"],"sourcesContent":["// Shared per-file setup for both rules: trust config, file zone, guard context, and the mapping from\n// ESLint's ESTree nodes to the TypeScript nodes the shared rule logic (../core/rules.ts) works on.\nimport { resolve } from 'node:path';\nimport type { Rule } from 'eslint';\nimport type * as TS from 'typescript';\nimport { emptyTrustConfig, policyFor } from '../core/check-file.js';\nimport type { GuardContext } from '../core/guard.js';\nimport { nameBasedGuardContext, typedGuardContext } from '../core/rules.js';\nimport { loadTrustConfigCached, normalizeOrigin, type TrustConfig, type TrustRuleSettings } from './config.js';\nimport type { TrustPolicy } from './policy.js';\nimport { loadTypeScript, type TypeScript } from './typescript.js';\nimport { Zones, type Zone } from './zones.js';\n\nexport interface TrustRuleOptions {\n /** trust.config.json path, relative to the ESLint cwd. */\n readonly configFile?: string;\n /** Extra trusted origins (applied before the config chain). */\n readonly trust?: readonly string[];\n}\n\nexport const OPTIONS_SCHEMA = [\n {\n type: 'object',\n properties: {\n configFile: { type: 'string' },\n trust: { type: 'array', items: { type: 'string' } },\n },\n additionalProperties: false,\n },\n] as const;\n\ninterface ParserServices {\n readonly program?: TS.Program | null;\n readonly esTreeNodeToTSNodeMap?: { get(node: unknown): TS.Node };\n}\n\n/** ESTree node as ESLint hands it to a rule (ranges are always present). */\ntype EsNode = Rule.Node | { readonly range?: [number, number] };\n\nexport interface RuleSetup {\n readonly ts: TypeScript;\n readonly zone: Zone;\n readonly policy: TrustPolicy | null;\n readonly guardContext: GuardContext;\n /** Maps an ESTree node to its TypeScript node of the given kind. */\n readonly tsNode: <T extends TS.Node>(node: EsNode, is: (node: TS.Node) => node is T) => T;\n readonly checker: TS.TypeChecker | null;\n /** The program of typed linting (null without parser services). */\n readonly program: TS.Program | null;\n /** The loaded trust config (`boundaries`, `strict` globs, …). */\n readonly config: TrustConfig;\n /** The trust config's per-rule settings: an opt-in rule that is not on reports nothing. */\n readonly rules: TrustRuleSettings;\n /** The TypeScript source file of the linted file (its comments are read from it). */\n readonly sourceFile: () => TS.SourceFile;\n}\n\n/**\n * Without parser services (e.g. ESLint's default parser) the file is parsed once with TypeScript and\n * nodes are found by their source range, which ESTree and TypeScript agree on.\n */\nfunction rangeLocator(ts: TypeScript, context: Rule.RuleContext): Pick<RuleSetup, 'tsNode' | 'sourceFile'> {\n let parsed: TS.SourceFile | undefined;\n const sourceFile = (): TS.SourceFile => (parsed ??= ts.createSourceFile(context.filename, context.sourceCode.text, ts.ScriptTarget.Latest, true));\n return { tsNode: locate, sourceFile };\n function locate<T extends TS.Node>(node: EsNode, is: (node: TS.Node) => node is T): T {\n const file = sourceFile();\n const [start, end] = (node as { range: [number, number] }).range;\n let found: T | undefined;\n const visit = (candidate: TS.Node): void => {\n if (found || candidate.pos > start || candidate.end < end) return;\n if (candidate.end === end && candidate.getStart(file) === start && is(candidate)) found = candidate;\n else ts.forEachChild(candidate, visit);\n };\n visit(file);\n if (!found) throw new Error(`@noego/trust: no TypeScript node at ${context.filename}:${start}-${end}`);\n return found;\n }\n}\n\nfunction mapLocator(ts: TypeScript, context: Rule.RuleContext, map: NonNullable<ParserServices['esTreeNodeToTSNodeMap']>): Pick<RuleSetup, 'tsNode' | 'sourceFile'> {\n const tsNode = function mapped<T extends TS.Node>(node: EsNode, is: (node: TS.Node) => node is T): T {\n const target = map.get(node);\n if (!target || !is(target)) throw new Error(`@noego/trust: unexpected TypeScript node in ${context.filename}`);\n return target;\n };\n return { tsNode, sourceFile: () => tsNode(context.sourceCode.ast, ts.isSourceFile) };\n}\n\nexport function setupRule(context: Rule.RuleContext): RuleSetup {\n const options = (context.options[0] ?? {}) as TrustRuleOptions;\n const ts = loadTypeScript(context.cwd);\n const config = options.configFile ? loadTrustConfigCached(resolve(context.cwd, options.configFile)) : emptyTrustConfig(context.cwd);\n const services = context.sourceCode.parserServices as ParserServices | undefined;\n const program = services?.program ?? null;\n const map = services?.esTreeNodeToTSNodeMap;\n const { tsNode, sourceFile } = map ? mapLocator(ts, context, map) : rangeLocator(ts, context);\n if (!program || !map) {\n const zones = new Zones(config.rootDir, config.passthrough, config.ignore);\n return { ts, zone: zones.zoneOf(context.filename), policy: null, guardContext: nameBasedGuardContext(ts), tsNode, checker: null, program: null, config, rules: config.rules, sourceFile };\n }\n const checker = program.getTypeChecker();\n const policy = policyFor(ts, checker, config, (options.trust ?? []).map(normalizeOrigin));\n return {\n ts,\n zone: policy.zones.zoneOf(context.filename),\n policy,\n guardContext: typedGuardContext(ts, checker, policy),\n tsNode,\n checker,\n program,\n config,\n rules: config.rules,\n sourceFile,\n };\n}\n","// ESLint adapter for boundary-result: in a file the trust config names as a boundary (`boundaries`), every\n// exported function and public member whose return value can fail is reported, with the origin as messageId\n// (`returns-result`, `unproven-return`, `stale-exclude`, `overlapping-items`).\n// The decisions are the shared core rule (../../core/boundaries.ts), run once over the file's TypeScript\n// source; this file only reports them at their source positions. A stale-exclude finding belongs to the config\n// file, which ESLint cannot report into: it is reported at the start of the file the core attributes it to.\n// ESLint has no per-finding severity, so an unproven return is reported like the rest (`trust check` warns).\n// Off unless the trust config has `boundaries`, the same setting `trust check` honours. When on, it requires\n// typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { boundaryContext, boundaryFindingsIn } from '../../core/boundaries.js';\nimport { isStrictByConfig } from '../../core/check-file.js';\nimport { BOUNDARY_MESSAGES } from '../../core/messages.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { BOUNDARY_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every boundary (exported function or public member of a configured boundary file) whose return value can fail.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: BOUNDARY_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (setup.config.boundaries.length === 0) return {};\n if (!setup.policy || !setup.checker || !setup.program) {\n throw new Error('boundary-result requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy, program, config } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n const strict = isStrictByConfig(config, sourceFile.fileName);\n for (const found of boundaryFindingsIn(sourceFile, boundaryContext(ts, checker, program, policy, config), strict)) {\n context.report({ loc: sourceCode.getLocFromIndex(found.start), messageId: found.origin, data: { ...found.data } });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for dropped-result: a Result that can still fail must be passed up (returned) or handled\n// (Trust.decide / Trust.translate, a branch naming its kind); every place a failure is dropped instead is\n// reported, with the origin as messageId (`discarded`, `argument`, `stored`, `callback`, `return`, `end`,\n// `overwritten`).\n// The decisions are the shared core rule (../../core/dropped-results.ts), run once over the file's\n// TypeScript source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"dropped-result\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { droppedResultContext, droppedResultData, droppedResultsIn } from '../../core/dropped-results.js';\nimport { DROPPED_RESULT_MESSAGES, DROPPED_RESULT_RULE } from '../../core/messages.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { DROPPED_RESULT_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every place a Result that can still fail is dropped instead of returned or handled.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: DROPPED_RESULT_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, DROPPED_RESULT_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('dropped-result requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n for (const dropped of droppedResultsIn(sourceFile, droppedResultContext(ts, checker, policy))) {\n context.report({ loc: sourceCode.getLocFromIndex(dropped.start), messageId: dropped.origin, data: droppedResultData(dropped) });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint controls severity per rule, not per finding; the core marks single-state as a warning.\nimport type { Rule } from 'eslint';\nimport { trustedStateContext, trustedStatesIn } from '../../core/trusted-state.js';\nimport { TRUSTED_STATE_MESSAGES, TRUSTED_STATE_RULE } from '../../core/messages.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { TRUSTED_STATE_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Require distinct success outcomes to use literal states.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: TRUSTED_STATE_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, TRUSTED_STATE_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('trusted-state requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n for (const dropped of trustedStatesIn(sourceFile, trustedStateContext(ts, checker, policy))) {\n context.report({ loc: sourceCode.getLocFromIndex(dropped.start), messageId: dropped.origin, data: dropped.data });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for redundant-guard: a Trust.try / Trust.tryAsync (or a `try` whose `catch` returns\n// Result.err) around code that cannot fail — every call inside is trusted, first-party, or declared to return\n// a Result — invents a failure path; it is reported at the guard (messageId `redundant`).\n// The decisions are the shared core rule (../../core/redundant-guards.ts), run once over the file's TypeScript\n// source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"redundant-guard\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { REDUNDANT_GUARD_MESSAGES, REDUNDANT_GUARD_RULE } from '../../core/messages.js';\nimport { redundantGuardData, redundantGuardsIn } from '../../core/redundant-guards.js';\nimport { typedGuardContext } from '../../core/rules.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { REDUNDANT_GUARD_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every guard (Trust.try / Trust.tryAsync / try-catch) around code that cannot fail.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: REDUNDANT_GUARD_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, REDUNDANT_GUARD_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('redundant-guard requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n const guardContext = typedGuardContext(ts, checker, policy);\n for (const guard of redundantGuardsIn(sourceFile, { ts, checker, policy, guardContext })) {\n context.report({ loc: sourceCode.getLocFromIndex(guard.start), messageId: 'redundant', data: redundantGuardData(guard) });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for throw-must-return-result: every `throw` in checked code must be guarded —\n// inside a `try` (same function) whose `catch` returns Result.err(...) on every path, or inside a\n// Trust.try / Trust.tryAsync callback. The decision is the shared core rule (../../core/rules.ts);\n// this file only maps ESTree nodes to TypeScript nodes and reports.\n// Works with or without type information; with it, Result.err is recognised by declaration.\n// A `throw` in a statement marked `//trust:accept <reason>` is accepted, and every `//trust:accept` that\n// accepts nothing is reported here, at the comment (`directive`, ../../core/accept.ts). Without type\n// information an accept above a statement with nothing to accept (stale) cannot be told, so it is not reported.\nimport type { Rule } from 'eslint';\nimport { acceptanceOf, acceptDirectiveFindings } from '../../core/accept.js';\nimport { ACCEPT_DIRECTIVE_MESSAGES, THROW_MESSAGES } from '../../core/messages.js';\nimport { throwProblem } from '../../core/rules.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { THROW_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Require every throw to be caught locally and returned as Result.err.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: { ...THROW_MESSAGES, ...ACCEPT_DIRECTIVE_MESSAGES },\n },\n create(context) {\n const setup = setupRule(context);\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, guardContext, policy, checker } = setup;\n const { sourceCode } = context;\n return {\n Program() {\n const failureContext = policy && checker ? { ts, checker, policy, guardContext } : null;\n const sourceFile = setup.sourceFile();\n for (const found of acceptDirectiveFindings(ts, sourceFile, failureContext)) {\n const loc = { start: sourceCode.getLocFromIndex(found.directive.pos), end: sourceCode.getLocFromIndex(found.directive.end) };\n context.report({ loc, messageId: found.messageId, data: found.data });\n }\n },\n ThrowStatement(node) {\n const statement = tsNode(node, ts.isThrowStatement);\n const messageId = throwProblem(statement, guardContext);\n if (messageId && !acceptanceOf(ts, statement)) context.report({ node, messageId });\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for type-claim: every place a type is claimed instead of proven — a narrowing\n// `as`, `x!`, `any` in a typed position, a written type predicate, a caller-chosen generic return —\n// is reported, with the claim kind as messageId (`claim:as`, `claim:non-null`, `claim:any`,\n// `claim:predicate`, `claim:generic-return`; `unanalyzable` for a node whose type does not resolve;\n// `directive` for a `//trust:` comment that marks nothing). Claims inside a validator (a function marked\n// `//trust:validator_function`) are not reported.\n// The decisions are the shared core rule (../../core/type-claims.ts), run once over the file's\n// TypeScript source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"type-claim\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport { TYPE_CLAIM_MESSAGES, TYPE_CLAIM_RULE } from '../../core/messages.js';\nimport { claimSpan, typeClaimContext, typeClaimsIn } from '../../core/type-claims.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { TYPE_CLAIM_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every place a type is claimed instead of proven.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: TYPE_CLAIM_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, TYPE_CLAIM_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('type-claim requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n for (const claim of typeClaimsIn(sourceFile, typeClaimContext(ts, checker, undefined, policy))) {\n const span = claimSpan(claim, sourceFile);\n const loc = { start: sourceCode.getLocFromIndex(span.start), end: sourceCode.getLocFromIndex(span.end) };\n context.report({ loc, messageId: claim.origin, data: claim.data });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// ESLint adapter for untrusted-call-must-return-result: every call or `new` whose callee is\n// untrusted must be guarded — inside a `try` (same function) whose `catch` returns Result.err(...)\n// on every path, or inside a Trust.try / Trust.tryAsync callback. Trust comes from\n// trust.config.json (see ../config.ts), from first-party checked code, or from a declared return\n// type of Result / Promise<Result> from @noego/trust. The decision is the shared core rule\n// (../../core/rules.ts); this file only maps ESTree nodes to TypeScript nodes and reports.\n// Requires typed linting (parserOptions.projectService or project). A call in a statement marked\n// `//trust:accept <reason>` is accepted (../../core/accept.ts).\nimport type { Rule } from 'eslint';\nimport type * as TS from 'typescript';\nimport { acceptanceOf } from '../../core/accept.js';\nimport { UNTRUSTED_CALL_MESSAGES } from '../../core/messages.js';\nimport { untrustedCallProblem } from '../../core/rules.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { UNTRUSTED_CALL_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Require calls into untrusted code to be handled locally and returned as Result.err.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: UNTRUSTED_CALL_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!setup.policy || !setup.checker) {\n throw new Error('untrusted-call-must-return-result requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, policy, tsNode, checker, guardContext } = setup;\n const isCallOrNew = (node: TS.Node): node is TS.CallExpression | TS.NewExpression => ts.isCallExpression(node) || ts.isNewExpression(node);\n\n function check(node: Rule.Node): void {\n const call = tsNode(node, isCallOrNew);\n const problem = untrustedCallProblem(call, policy, checker, guardContext);\n if (problem && !acceptanceOf(ts, call)) context.report({ node, messageId: problem.messageId, data: { origin: problem.origin } });\n }\n\n return { CallExpression: check, NewExpression: check };\n },\n};\n\nexport default rule;\n","// ESLint adapter for untrusted-value: type trust is opt-in. A value whose type was declared by an origin\n// that is not on the type-trust list (`trust_type` in trust.config.json) — a call's return, a parameter of\n// a callback the outside calls, a property or global it declares — may only be passed to a validator, kept\n// as `unknown`, or tested by a built-in check; any other use is reported with the origin named.\n// The decisions are the shared core rule (../../core/untrusted-values.ts), run once over the file's\n// TypeScript source; this file only reports them at their source positions.\n// Opt-in: it reports nothing unless the trust config turns it on (`\"rules\": { \"untrusted-value\": \"on\" }`), the\n// same setting `trust check` honours. When on, it requires typed linting (parserOptions.projectService or project).\nimport type { Rule } from 'eslint';\nimport type * as TS from 'typescript';\nimport { UNTRUSTED_VALUE_MESSAGES, UNTRUSTED_VALUE_RULE } from '../../core/messages.js';\nimport {\n untrustedHandoffData,\n untrustedHandoffsIn,\n untrustedValueContext,\n untrustedValueData,\n untrustedValueMessageId,\n untrustedValuesIn,\n} from '../../core/untrusted-values.js';\nimport { isRuleEnabled } from '../config.js';\nimport { OPTIONS_SCHEMA, setupRule } from '../rule-setup.js';\n\nexport { UNTRUSTED_VALUE_MESSAGES };\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: { description: 'Report every use of a value whose type was declared by an origin that is not type-trusted.' },\n schema: OPTIONS_SCHEMA as unknown as Rule.RuleMetaData['schema'],\n messages: UNTRUSTED_VALUE_MESSAGES,\n },\n create(context) {\n const setup = setupRule(context);\n if (!isRuleEnabled(setup, UNTRUSTED_VALUE_RULE)) return {};\n if (!setup.policy || !setup.checker) {\n throw new Error('untrusted-value requires typed linting (parserOptions.projectService or project).');\n }\n if (setup.zone !== 'checked') return {};\n const { ts, tsNode, checker, policy } = setup;\n const { sourceCode } = context;\n\n return {\n Program(node) {\n const sourceFile = tsNode(node, ts.isSourceFile);\n const valueContext = untrustedValueContext(ts, checker, policy);\n const locOf = (at: TS.Node) => ({ start: sourceCode.getLocFromIndex(at.getStart(sourceFile)), end: sourceCode.getLocFromIndex(at.getEnd()) });\n for (const value of untrustedValuesIn(sourceFile, valueContext)) {\n if (value.outcome !== 'finding') continue;\n context.report({ loc: locOf(value.node), messageId: untrustedValueMessageId(value), data: untrustedValueData(value) });\n }\n // `untrustedCallbacks: \"all\"`: functions handed to an origin that is not type-trusted, at the hand-off.\n for (const handoff of untrustedHandoffsIn(sourceFile, valueContext)) {\n context.report({ loc: locOf(handoff.node), messageId: 'handoff', data: untrustedHandoffData(handoff) });\n }\n },\n };\n },\n};\n\nexport default rule;\n","// @noego/trust/eslint — ESLint plugin, trust config loader, and policy.\n//\n// import { typedConfig } from '@noego/trust/eslint';\n// export default [\n// ...typedConfig({ files: ['server/**/*.ts'], configFile: 'trust.config.json' }),\n// ];\nimport type { ESLint, Linter } from 'eslint';\nimport boundaryResult from './rules/boundary-result.js';\nimport droppedResult from './rules/dropped-result.js';\nimport trustedState from './rules/trusted-state.js';\nimport redundantGuard from './rules/redundant-guard.js';\nimport throwMustReturnResult from './rules/throw-must-return-result.js';\nimport typeClaim from './rules/type-claim.js';\nimport untrustedCallMustReturnResult from './rules/untrusted-call-must-return-result.js';\nimport untrustedValue from './rules/untrusted-value.js';\n\nexport const rules = {\n 'untrusted-call-must-return-result': untrustedCallMustReturnResult,\n 'throw-must-return-result': throwMustReturnResult,\n 'type-claim': typeClaim,\n 'untrusted-value': untrustedValue,\n 'dropped-result': droppedResult,\n 'trusted-state': trustedState,\n 'redundant-guard': redundantGuard,\n 'boundary-result': boundaryResult,\n};\n\nexport interface TypedConfigOptions {\n /** Files to check (flat-config globs). They must be in a tsconfig the project service can find. */\n readonly files: readonly string[];\n readonly ignores?: readonly string[];\n /** trust.config.json path relative to the ESLint cwd (default \"trust.config.json\"). */\n readonly configFile?: string;\n readonly severity?: Linter.RuleSeverity;\n}\n\nconst plugin: ESLint.Plugin = {\n meta: { name: '@noego/trust' },\n rules,\n};\n\nexport default plugin;\n\n/**\n * Flat config that registers the plugin as `trust` and enables its rules (the two trust rules, `type-claim`,\n * `untrusted-value` and `dropped-result`) for `files`. Needs typed linting. `type-claim`, `untrusted-value` and\n * `dropped-result` are opt-in: they report only when the trust config turns them on\n * (`\"rules\": { \"type-claim\": \"on\", \"untrusted-value\": \"on\", \"dropped-result\": \"on\" }`), the same settings\n * `trust check` / `trust baseline` honour, so ESLint and the CLI always agree.\n */\nexport function typedConfig(options: TypedConfigOptions): Linter.Config[] {\n const severity = options.severity ?? 'warn';\n const ruleOptions = { configFile: options.configFile ?? 'trust.config.json' };\n return [\n {\n name: '@noego/trust/typed',\n files: [...options.files],\n ignores: [...(options.ignores ?? [])],\n plugins: { trust: plugin },\n rules: {\n 'trust/untrusted-call-must-return-result': [severity, ruleOptions],\n 'trust/throw-must-return-result': [severity, ruleOptions],\n 'trust/type-claim': [severity, ruleOptions],\n 'trust/untrusted-value': [severity, ruleOptions],\n 'trust/dropped-result': [severity, ruleOptions],\n 'trust/trusted-state': [severity, ruleOptions],\n 'trust/redundant-guard': [severity, ruleOptions],\n 'trust/boundary-result': [severity, ruleOptions],\n },\n },\n ];\n}\n\nexport {\n DEFAULT_RULE_SETTINGS,\n effectiveTrustList,\n effectiveTypeTrustList,\n isRuleEnabled,\n loadTrustConfig,\n normalizeOrigin,\n TrustConfigError,\n type BoundaryGroup,\n type LoadTrustConfigOptions,\n type OptInRule,\n type RuleSwitch,\n type TrustConfig,\n type TrustEntry,\n type TrustLevel,\n type TrustRuleSettings,\n type TsconfigMapping,\n type UntrustedCallbacks,\n} from './config.js';\nexport { PRESETS, type PresetDefinition } from './presets.js';\nexport { entryMatches, TrustPolicy, type MatchedEntry, type TypeVerdict, type Verdict } from './policy.js';\nexport { OriginResolver, type OriginInfo } from './origin.js';\nexport { Zones, type Zone, type ZoneGroup } from './zones.js';\nexport { alwaysExits, catchProblem, guardOf, type Guard, type GuardContext } from '../core/guard.js';\nexport type { CatchProblem } from '../core/messages.js';\nexport {\n compareToBaseline,\n countFindings,\n parseBaseline,\n serializeBaseline,\n THROW_RULE,\n UNTRUSTED_CALL_RULE,\n updateBaseline,\n WHOLE_BASELINE,\n type BaselineCounts,\n type BaselineDelta,\n type BaselineScope,\n type Finding,\n} from '../core/baseline.js';\nexport { DIRECTIVE_ORIGIN, TYPE_CLAIM_KINDS, TYPE_CLAIM_RULE, UNANALYZABLE_ORIGIN, type TypeClaimOrigin } from '../core/messages.js';\nexport { CATCH_ORIGIN, UNTRUSTED_VALUE_RULE, type UntrustedEntry } from '../core/messages.js';\nexport { DROPPED_RESULT_RULE, type DroppedResultOrigin } from '../core/messages.js';\nexport { DROPPED_RESULT_MESSAGES } from './rules/dropped-result.js';\nexport { REDUNDANT_GUARD_ORIGIN, REDUNDANT_GUARD_RULE } from '../core/messages.js';\nexport { REDUNDANT_GUARD_MESSAGES } from './rules/redundant-guard.js';\nexport { BOUNDARY_RULE, type BoundaryOrigin } from '../core/messages.js';\nexport { BOUNDARY_MESSAGES } from './rules/boundary-result.js';\nexport { ACCEPT_DIRECTIVE, isInsideValidator, isMarkedValidator, VALIDATOR_DIRECTIVE } from '../core/validator.js';\nexport { ACCEPT_DIRECTIVE_MESSAGES } from '../core/messages.js';\nexport { THROW_MESSAGES } from './rules/throw-must-return-result.js';\nexport { TYPE_CLAIM_MESSAGES } from './rules/type-claim.js';\nexport { UNTRUSTED_CALL_MESSAGES } from './rules/untrusted-call-must-return-result.js';\nexport { UNTRUSTED_VALUE_MESSAGES } from './rules/untrusted-value.js';\nexport type { TrustRuleOptions } from './rule-setup.js';\n\nexport { TRUSTED_STATE_RULE, TRUSTED_STATE_MESSAGES, type TrustedStateOrigin } from '../core/messages.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAW,QAAQ,YAAY;AACrC,QAAM,cAAc,EAAE,YAAY,QAAQ,cAAc,oBAAoB;AAC5E,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,OAAO,CAAC,GAAG,QAAQ,KAAK;AAAA,MACxB,SAAS,CAAC,GAAI,QAAQ,WAAW,CAAC,CAAE;AAAA,MACpC,SAAS,EAAE,OAAO,OAAO;AAAA,MACzB,OAAO;AAAA,QACL,2CAA2C,CAAC,UAAU,WAAW;AAAA,QACjE,kCAAkC,CAAC,UAAU,WAAW;AAAA,QACxD,oBAAoB,CAAC,UAAU,WAAW;AAAA,QAC1C,yBAAyB,CAAC,UAAU,WAAW;AAAA,QAC/C,wBAAwB,CAAC,UAAU,WAAW;AAAA,QAC9C,uBAAuB,CAAC,UAAU,WAAW;AAAA,QAC7C,yBAAyB,CAAC,UAAU,WAAW;AAAA,QAC/C,yBAAyB,CAAC,UAAU,WAAW;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AACF;","names":["rule","rule","rule","rule","rule","rule","rule"]}
|
package/dist/index.cjs
CHANGED
|
@@ -24,17 +24,34 @@ __export(src_exports, {
|
|
|
24
24
|
Trust: () => Trust,
|
|
25
25
|
decide: () => decide,
|
|
26
26
|
err: () => err,
|
|
27
|
+
match: () => match,
|
|
27
28
|
ok: () => ok,
|
|
29
|
+
state: () => state,
|
|
28
30
|
translate: () => translate,
|
|
29
31
|
tryResult: () => tryResult,
|
|
30
32
|
tryResultAsync: () => tryResultAsync
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var resultBrand = /* @__PURE__ */ Symbol.for("@noego/trust/result");
|
|
36
|
+
function brand(value) {
|
|
37
|
+
return Object.defineProperty(value, resultBrand, { value: true });
|
|
38
|
+
}
|
|
39
|
+
function isResult(value) {
|
|
40
|
+
return (typeof value === "object" && value !== null || typeof value === "function") && resultBrand in value;
|
|
41
|
+
}
|
|
42
|
+
function state(state2, value) {
|
|
43
|
+
if (arguments.length === 1) return brand({ ok: true, state: state2, value: void 0 });
|
|
44
|
+
if (isResult(value)) {
|
|
45
|
+
if (value.ok === false) return value;
|
|
46
|
+
return brand({ ok: true, state: state2, value: value.value });
|
|
47
|
+
}
|
|
48
|
+
return brand({ ok: true, state: state2, value });
|
|
49
|
+
}
|
|
33
50
|
function ok(value) {
|
|
34
|
-
return { ok: true, value };
|
|
51
|
+
return brand({ ok: true, value });
|
|
35
52
|
}
|
|
36
53
|
function err(error) {
|
|
37
|
-
return { ok: false, error };
|
|
54
|
+
return brand({ ok: false, error });
|
|
38
55
|
}
|
|
39
56
|
function tryResult(fn, onError) {
|
|
40
57
|
try {
|
|
@@ -57,22 +74,33 @@ function pick(table, kind) {
|
|
|
57
74
|
function decide(result, handlers) {
|
|
58
75
|
if (result.ok) return result;
|
|
59
76
|
const handler = pick(handlers, result.error?.kind);
|
|
60
|
-
|
|
77
|
+
if (handler === void 0) return result;
|
|
78
|
+
const value = handler(result.error);
|
|
79
|
+
return isResult(value) ? value : ok(value);
|
|
61
80
|
}
|
|
62
81
|
function translate(result, mappers) {
|
|
63
82
|
if (result.ok) return result;
|
|
64
83
|
const mapper = pick(mappers, result.error?.kind);
|
|
65
84
|
return mapper === void 0 ? result : err(mapper(result.error));
|
|
66
85
|
}
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
function match(result, handlers) {
|
|
87
|
+
if (!result.ok) return result;
|
|
88
|
+
const handler = pick(handlers, result.state);
|
|
89
|
+
if (handler === void 0) return result;
|
|
90
|
+
const value = handler(result.value);
|
|
91
|
+
return isResult(value) ? value : ok(value);
|
|
92
|
+
}
|
|
93
|
+
var Result = { ok, err, state };
|
|
94
|
+
var Trust = { try: tryResult, tryAsync: tryResultAsync, decide, translate, match };
|
|
69
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
96
|
0 && (module.exports = {
|
|
71
97
|
Result,
|
|
72
98
|
Trust,
|
|
73
99
|
decide,
|
|
74
100
|
err,
|
|
101
|
+
match,
|
|
75
102
|
ok,
|
|
103
|
+
state,
|
|
76
104
|
translate,
|
|
77
105
|
tryResult,
|
|
78
106
|
tryResultAsync
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Closed result primitive: expected failures are values, not exceptions.\n *\n * `Result<T, E>` is `Ok<T> | Err<E>`, discriminated by `ok`. This module has no\n * imports so it is safe in any bundle (Node, Electron main, renderer, browser).\n *\n * Public surface is two namespaces:\n *\n * Result.ok / Result.err — make a result\n * Trust.try / Trust.tryAsync — the only boundary that may catch a throw\n * Trust.decide / Trust.translate — the only places a failure may stop or change\n *\n * The underlying functions are exported as well because the `@noego/trust/eslint`\n * rules recognise calls by their declaration (not by name): `Trust.try(...)` resolves\n * to `tryResult`, `Result.err(...)` to `err`. Write the namespace form in application code.\n */\nexport type Ok<T> = { readonly ok: true; readonly value: T };\nexport type Err<E> = { readonly ok: false; readonly error: E };\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/** A failure is an object with a literal `kind` plus any fields. */\nexport type Failure<K extends string = string, Fields extends object = {}> = { readonly kind: K } & Readonly<Fields>;\n\n/** Wraps a success value. */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value };\n}\n\n/**\n * Wraps a failure value. Pass a typed error, not a raw caught value.\n *\n * The first overload keeps a literal `kind` for inline failures (`err({ kind: 'X' })`\n * gives `Err<{ kind: 'X' }>`) through the `K` hint in the intersection, so no `as const`\n * is needed. `E` itself is still a plain type parameter, so a declared `Result` return\n * type sets it and other literal fields keep their declared union types. The second\n * overload covers arguments that cannot meet the intersection (generic, unknown, null).\n */\nexport function err<E, K extends string = string>(error: E & { readonly kind?: K }): Err<E>;\nexport function err<E>(error: E): Err<E>;\nexport function err<E>(error: E): Err<E> {\n return { ok: false, error };\n}\n\n/**\n * Runs `fn` and converts anything it throws into `Err` via `onError`.\n * Calls made directly inside `fn` count as guarded for the trust lint rules.\n */\nexport function tryResult<T, E, K extends string = string>(\n fn: () => T,\n onError: (cause: unknown) => E & { readonly kind?: K },\n): Result<T, E>;\nexport function tryResult<T, E>(fn: () => T, onError: (cause: unknown) => E): Result<T, E>;\nexport function tryResult<T, E>(fn: () => T, onError: (cause: unknown) => E): Result<T, E> {\n try {\n return ok(fn());\n } catch (cause) {\n return err(onError(cause));\n }\n}\n\n/**\n * Awaits `fn` and converts a throw or rejection into `Err` via `onError`.\n * Calls made directly inside `fn` count as guarded for the trust lint rules.\n */\nexport function tryResultAsync<T, E, K extends string = string>(\n fn: () => T | PromiseLike<T>,\n onError: (cause: unknown) => E & { readonly kind?: K },\n): Promise<Result<T, E>>;\nexport function tryResultAsync<T, E>(\n fn: () => T | PromiseLike<T>,\n onError: (cause: unknown) => E,\n): Promise<Result<T, E>>;\nexport async function tryResultAsync<T, E>(\n fn: () => T | PromiseLike<T>,\n onError: (cause: unknown) => E,\n): Promise<Result<T, E>> {\n try {\n return ok(await fn());\n } catch (cause) {\n return err(onError(cause));\n }\n}\n\ntype IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;\n/**\n * One failure per kind. A single declared failure whose `kind` is a union\n * (`{ kind: 'a' | 'b'; op: string }`) is split into `{...; kind: 'a'} | {...; kind: 'b'}`\n * so that handlers narrow to one kind each; failures that already have one\n * literal kind are left as they are.\n */\ntype SplitByKind<E> = E extends { readonly kind: infer K extends string }\n ? IsUnion<K> extends true\n ? K extends unknown\n ? E & { readonly kind: K }\n : never\n : E\n : never;\n\ntype KindsOf<E> = E extends { readonly kind: infer K extends string } ? K : never;\ntype ErrorOf<R> = R extends Err<infer E> ? SplitByKind<E> : never;\ntype OkOf<R> = R extends Ok<infer T> ? T : never;\ntype CannotFail = { readonly __trust: 'decide needs a result that can fail (it has no Err member)' };\ntype BadFailure = { readonly __trust: 'every failure needs a string `kind` (string and Error are not failures)' };\ntype NeedsLiteralKind = { readonly __trust: 'a translate mapper must return an object with a literal string kind' };\n\ntype RawErrorOf<R> = R extends Err<infer E> ? E : never;\ntype FailureGuard<R> = [RawErrorOf<R>] extends [never]\n ? CannotFail\n : [RawErrorOf<R>] extends [{ readonly kind: string }]\n ? unknown\n : BadFailure;\n\ntype HandlerBase<E, H> = { [K in keyof H]: K extends KindsOf<E> ? {} | null : never };\ntype HandlerFns<E, H> = {\n [K in keyof H]-?: (failure: Extract<E, { readonly kind: K }>) => H[K];\n};\ntype LiteralKind = '' | (string & {});\ntype MapperBase<E, M> = { [K in keyof M]: K extends KindsOf<E> ? { readonly kind: LiteralKind } : never };\ntype MapperFns<E, M> = {\n [K in keyof M]-?: (failure: Extract<E, { readonly kind: K }>) => M[K];\n};\ntype KindCheck<M> = [\n { [K in keyof M]-?: M[K] extends { readonly kind: infer Kd } ? (string extends Kd ? 1 : never) : 1 }[keyof M],\n] extends [never]\n ? []\n : [problem: NeedsLiteralKind];\n\ntype Remaining<E, H> = Exclude<E, { readonly kind: keyof H & string }>;\ntype Decided<R, H> = [Remaining<ErrorOf<R>, H>] extends [never]\n ? Ok<OkOf<R> | H[keyof H]>\n : Ok<OkOf<R> | H[keyof H]> | Err<Remaining<ErrorOf<R>, H>>;\ntype Translated<R, M> = Ok<OkOf<R>> | Err<M[keyof M] | Remaining<ErrorOf<R>, M>>;\n\nfunction pick(table: object, kind: unknown): ((failure: unknown) => unknown) | undefined {\n if (typeof kind !== 'string' || !Object.prototype.hasOwnProperty.call(table, kind)) return undefined;\n return (table as Record<string, (failure: unknown) => unknown>)[kind];\n}\n\n/**\n * The only place a failure may stop: a failure whose kind has a handler becomes\n * `ok(handler(failure))`; anything else is returned untouched. Handlers are synchronous\n * and must return a value (never `undefined`/`void`).\n */\nexport function decide<R extends Result<unknown, unknown>, H extends HandlerBase<ErrorOf<R>, H>>(\n result: R & FailureGuard<R>,\n handlers: HandlerFns<ErrorOf<R>, H>,\n): Decided<R, H>;\nexport function decide(result: Result<unknown, unknown>, handlers: object): unknown {\n if (result.ok) return result;\n const handler = pick(handlers, (result.error as { kind?: unknown } | null)?.kind);\n return handler === undefined ? result : ok(handler(result.error));\n}\n\n/** Turns failures into different failures; unmapped failures and successes pass through untouched. */\nexport function translate<R extends Result<unknown, unknown>, M extends MapperBase<ErrorOf<R>, M>>(\n result: R & FailureGuard<R>,\n mappers: MapperFns<ErrorOf<R>, M>,\n ...check: KindCheck<M>\n): Translated<R, M>;\nexport function translate(result: Result<unknown, unknown>, mappers: object): unknown {\n if (result.ok) return result;\n const mapper = pick(mappers, (result.error as { kind?: unknown } | null)?.kind);\n return mapper === undefined ? result : err(mapper(result.error));\n}\n\n/** Make a result: `Result.ok(value)`, `Result.err({ kind: 'x', ... })`. */\nexport const Result: {\n readonly ok: typeof ok;\n readonly err: typeof err;\n} = { ok, err };\n\n/**\n * Apply the discipline:\n * `Trust.try` / `Trust.tryAsync` are the only boundary that may catch a throw;\n * `Trust.decide` is the only place a failure may stop; `Trust.translate` the only place it may change kind.\n */\nexport const Trust: {\n readonly try: typeof tryResult;\n readonly tryAsync: typeof tryResultAsync;\n readonly decide: typeof decide;\n readonly translate: typeof translate;\n} = { try: tryResult, tryAsync: tryResultAsync, decide, translate };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,SAAS,GAAM,OAAiB;AACrC,SAAO,EAAE,IAAI,MAAM,MAAM;AAC3B;AAaO,SAAS,IAAO,OAAkB;AACvC,SAAO,EAAE,IAAI,OAAO,MAAM;AAC5B;AAWO,SAAS,UAAgB,IAAa,SAA8C;AACzF,MAAI;AACF,WAAO,GAAG,GAAG,CAAC;AAAA,EAChB,SAAS,OAAO;AACd,WAAO,IAAI,QAAQ,KAAK,CAAC;AAAA,EAC3B;AACF;AAcA,eAAsB,eACpB,IACA,SACuB;AACvB,MAAI;AACF,WAAO,GAAG,MAAM,GAAG,CAAC;AAAA,EACtB,SAAS,OAAO;AACd,WAAO,IAAI,QAAQ,KAAK,CAAC;AAAA,EAC3B;AACF;AAoDA,SAAS,KAAK,OAAe,MAA4D;AACvF,MAAI,OAAO,SAAS,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,OAAO,IAAI,EAAG,QAAO;AAC3F,SAAQ,MAAwD,IAAI;AACtE;AAWO,SAAS,OAAO,QAAkC,UAA2B;AAClF,MAAI,OAAO,GAAI,QAAO;AACtB,QAAM,UAAU,KAAK,UAAW,OAAO,OAAqC,IAAI;AAChF,SAAO,YAAY,SAAY,SAAS,GAAG,QAAQ,OAAO,KAAK,CAAC;AAClE;AAQO,SAAS,UAAU,QAAkC,SAA0B;AACpF,MAAI,OAAO,GAAI,QAAO;AACtB,QAAM,SAAS,KAAK,SAAU,OAAO,OAAqC,IAAI;AAC9E,SAAO,WAAW,SAAY,SAAS,IAAI,OAAO,OAAO,KAAK,CAAC;AACjE;AAGO,IAAM,SAGT,EAAE,IAAI,IAAI;AAOP,IAAM,QAKT,EAAE,KAAK,WAAW,UAAU,gBAAgB,QAAQ,UAAU;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Closed result primitive: expected failures are values, not exceptions.\n *\n * `Result<T, E>` is `Ok<T> | Err<E>`, discriminated by `ok`. This module has no\n * imports so it is safe in any bundle (Node, Electron main, renderer, browser).\n *\n * Public surface is two namespaces:\n *\n * Result.ok / Result.err — make a result\n * Trust.try / Trust.tryAsync — the only boundary that may catch a throw\n * Trust.decide / Trust.translate — the only places a failure may stop or change\n *\n * The underlying functions are exported as well because the `@noego/trust/eslint`\n * rules recognise calls by their declaration (not by name): `Trust.try(...)` resolves\n * to `tryResult`, `Result.err(...)` to `err`. Write the namespace form in application code.\n */\nexport type Ok<T> = { readonly ok: true; readonly value: T };\nexport type Err<E> = { readonly ok: false; readonly error: E };\nexport type Result<T, E> = Ok<T> | Err<E>;\n\nexport type StatedOk<T, S extends string> = { [K in S]: { readonly ok: true; readonly state: K; readonly value: T } }[S];\nexport type StatedResult<T, E, S extends string> = StatedOk<T, S> | Err<E>;\n\ntype LiteralState<S extends string> = string extends S ? never : S;\ntype Stateless<R> = Extract<R, { readonly state: unknown }> extends never ? R : never;\ntype NotResult<T> = unknown extends T ? never : Extract<T, Ok<unknown> | Err<unknown>> extends never ? T : never;\n\nconst resultBrand = Symbol.for('@noego/trust/result');\nfunction brand<T extends object>(value: T): T {\n return Object.defineProperty(value, resultBrand, { value: true });\n}\nfunction isResult(value: unknown): value is Result<unknown, unknown> {\n return ((typeof value === 'object' && value !== null) || typeof value === 'function')\n && resultBrand in value;\n}\n\nexport function state<const S extends string>(state: LiteralState<S>): StatedOk<void, S>;\nexport function state<const S extends string, R extends Result<unknown, unknown>>(\n state: LiteralState<S>, result: R & Stateless<R> & (0 extends (1 & R) ? never : unknown),\n): StatedOk<OkOf<R>, S> | Extract<R, { readonly ok: false }>;\nexport function state<const S extends string, T>(\n state: LiteralState<S>, value: T,\n ...check: [T] extends [NotResult<T>] ? unknown extends T ? [problem: never] : [] : [problem: never]\n): StatedOk<T, S>;\nexport function state(state: string, value?: unknown): Result<unknown, unknown> {\n if (arguments.length === 1) return brand({ ok: true, state, value: undefined });\n if (isResult(value)) {\n if (value.ok === false) return value;\n return brand({ ok: true, state, value: value.value });\n }\n return brand({ ok: true, state, value });\n}\n\n/** A failure is an object with a literal `kind` plus any fields. */\nexport type Failure<K extends string = string, Fields extends object = {}> = { readonly kind: K } & Readonly<Fields>;\n\n/** Wraps a success value. */\nexport function ok<T>(value: T): Ok<T> {\n return brand({ ok: true, value });\n}\n\n/**\n * Wraps a failure value. Pass a typed error, not a raw caught value.\n *\n * The first overload keeps a literal `kind` for inline failures (`err({ kind: 'X' })`\n * gives `Err<{ kind: 'X' }>`) through the `K` hint in the intersection, so no `as const`\n * is needed. `E` itself is still a plain type parameter, so a declared `Result` return\n * type sets it and other literal fields keep their declared union types. The second\n * overload covers arguments that cannot meet the intersection (generic, unknown, null).\n */\nexport function err<E, K extends string = string>(error: E & { readonly kind?: K }): Err<E>;\nexport function err<E>(error: E): Err<E>;\nexport function err<E>(error: E): Err<E> {\n return brand({ ok: false, error });\n}\n\n/**\n * Runs `fn` and converts anything it throws into `Err` via `onError`.\n * Calls made directly inside `fn` count as guarded for the trust lint rules.\n */\nexport function tryResult<T, E, K extends string = string>(\n fn: () => T,\n onError: (cause: unknown) => E & { readonly kind?: K },\n): Result<T, E>;\nexport function tryResult<T, E>(fn: () => T, onError: (cause: unknown) => E): Result<T, E>;\nexport function tryResult<T, E>(fn: () => T, onError: (cause: unknown) => E): Result<T, E> {\n try {\n return ok(fn());\n } catch (cause) {\n return err(onError(cause));\n }\n}\n\n/**\n * Awaits `fn` and converts a throw or rejection into `Err` via `onError`.\n * Calls made directly inside `fn` count as guarded for the trust lint rules.\n */\nexport function tryResultAsync<T, E, K extends string = string>(\n fn: () => T | PromiseLike<T>,\n onError: (cause: unknown) => E & { readonly kind?: K },\n): Promise<Result<T, E>>;\nexport function tryResultAsync<T, E>(\n fn: () => T | PromiseLike<T>,\n onError: (cause: unknown) => E,\n): Promise<Result<T, E>>;\nexport async function tryResultAsync<T, E>(\n fn: () => T | PromiseLike<T>,\n onError: (cause: unknown) => E,\n): Promise<Result<T, E>> {\n try {\n return ok(await fn());\n } catch (cause) {\n return err(onError(cause));\n }\n}\n\ntype IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;\n/**\n * One failure per kind. A single declared failure whose `kind` is a union\n * (`{ kind: 'a' | 'b'; op: string }`) is split into `{...; kind: 'a'} | {...; kind: 'b'}`\n * so that handlers narrow to one kind each; failures that already have one\n * literal kind are left as they are.\n */\ntype SplitByKind<E> = E extends { readonly kind: infer K extends string }\n ? IsUnion<K> extends true\n ? K extends unknown\n ? E & { readonly kind: K }\n : never\n : E\n : never;\n\ntype KindsOf<E> = E extends { readonly kind: infer K extends string } ? K : never;\ntype ErrorOf<R> = R extends Err<infer E> ? SplitByKind<E> : never;\ntype OkOf<R> = R extends Ok<infer T> ? T : never;\ntype CannotFail = { readonly __trust: 'decide needs a result that can fail (it has no Err member)' };\ntype BadFailure = { readonly __trust: 'every failure needs a string `kind` (string and Error are not failures)' };\ntype NeedsLiteralKind = { readonly __trust: 'a translate mapper must return an object with a literal string kind' };\n\ntype RawErrorOf<R> = R extends Err<infer E> ? E : never;\ntype FailureGuard<R> = [RawErrorOf<R>] extends [never]\n ? CannotFail\n : [RawErrorOf<R>] extends [{ readonly kind: string }]\n ? unknown\n : BadFailure;\n\ntype HandlerBase<E, H> = { [K in keyof H]: K extends KindsOf<E> ? {} | null : never };\ntype HandlerFns<E, H> = {\n [K in keyof H]-?: (failure: Extract<E, { readonly kind: K }>) => H[K];\n};\ntype LiteralKind = '' | (string & {});\ntype MapperBase<E, M> = { [K in keyof M]: K extends KindsOf<E> ? { readonly kind: LiteralKind } : never };\ntype MapperFns<E, M> = {\n [K in keyof M]-?: (failure: Extract<E, { readonly kind: K }>) => M[K];\n};\ntype KindCheck<M> = [\n { [K in keyof M]-?: M[K] extends { readonly kind: infer Kd } ? (string extends Kd ? 1 : never) : 1 }[keyof M],\n] extends [never]\n ? []\n : [problem: NeedsLiteralKind];\n\ntype Remaining<E, H> = Exclude<E, { readonly kind: keyof H & string }>;\ntype StatedMembersOf<R> = Extract<R, { readonly ok: true; readonly state: string }>;\ntype HasStates<R> = [StatedMembersOf<R>] extends [never] ? false : true;\ntype StateGuard<R> = HasStates<R> extends true\n ? Exclude<Extract<R, Ok<unknown>>, StatedMembersOf<R>> extends never ? unknown\n : { readonly __trust: 'mixed stated and stateless successes are not supported' }\n : unknown;\ntype SuccessOf<R, H> = HasStates<R> extends true ? StatedMembersOf<R> | H[keyof H] : Ok<OkOf<R> | H[keyof H]>;\ntype RecoveryCheck<R, H> = {\n [K in keyof H]: HasStates<R> extends true\n ? H[K] extends StatedOk<unknown, infer S extends string> ? string extends S ? 1 : never : 1\n : Extract<H[K], { readonly state: unknown }> extends never ? never : 1\n}[keyof H] extends never ? [] : [problem: { readonly __trust: 'recovery must preserve the success state discipline' }];\ntype Decided<R, H> = [Remaining<ErrorOf<R>, H>] extends [never]\n ? SuccessOf<R, H>\n : SuccessOf<R, H> | Err<Remaining<ErrorOf<R>, H>>;\ntype Translated<R, M> = (HasStates<R> extends true ? StatedMembersOf<R> : Ok<OkOf<R>>) | Err<M[keyof M] | Remaining<ErrorOf<R>, M>>;\n\nfunction pick(table: object, kind: unknown): ((failure: unknown) => unknown) | undefined {\n if (typeof kind !== 'string' || !Object.prototype.hasOwnProperty.call(table, kind)) return undefined;\n return (table as Record<string, (failure: unknown) => unknown>)[kind];\n}\n\n/**\n * The only place a failure may stop: a failure whose kind has a handler becomes\n * `ok(handler(failure))`; anything else is returned untouched. Handlers are synchronous\n * and must return a value (never `undefined`/`void`).\n */\nexport function decide<R extends Result<unknown, unknown>, H extends HandlerBase<ErrorOf<R>, H>>(\n result: R & FailureGuard<R> & StateGuard<R>,\n handlers: HandlerFns<ErrorOf<R>, H>,\n ...check: RecoveryCheck<R, H>\n): Decided<R, H>;\nexport function decide(result: Result<unknown, unknown>, handlers: object): unknown {\n if (result.ok) return result;\n const handler = pick(handlers, (result.error as { kind?: unknown } | null)?.kind);\n if (handler === undefined) return result;\n const value = handler(result.error);\n return isResult(value) ? value : ok(value);\n}\n\n/** Turns failures into different failures; unmapped failures and successes pass through untouched. */\nexport function translate<R extends Result<unknown, unknown>, M extends MapperBase<ErrorOf<R>, M>>(\n result: R & FailureGuard<R> & StateGuard<R>,\n mappers: MapperFns<ErrorOf<R>, M>,\n ...check: KindCheck<M>\n): Translated<R, M>;\nexport function translate(result: Result<unknown, unknown>, mappers: object): unknown {\n if (result.ok) return result;\n const mapper = pick(mappers, (result.error as { kind?: unknown } | null)?.kind);\n return mapper === undefined ? result : err(mapper(result.error));\n}\n\ntype MatchGuard<R> = [RawErrorOf<R>] extends [never]\n ? HasStates<R> extends true ? StateGuard<R> : { readonly __trust: 'match needs stated successes' }\n : { readonly __trust: 'match requires all failures to be handled first' };\ntype StatesOf<R> = StatedMembersOf<R>['state'];\ntype MatchFns<R, H> = {\n [K in keyof H]-?: (value: OkOf<Extract<R, { readonly state: K }>>) => H[K];\n};\ntype MatchBase<R, H> = { [K in StatesOf<R>]: {} | null } & {\n [K in keyof H]: K extends StatesOf<R> ? {} | null : never;\n};\ntype Matched<H> = [H[keyof H]] extends [StatedOk<unknown, string>] ? H[keyof H] : Ok<H[keyof H]>;\ntype MatchCheck<H> = [Extract<H[keyof H], { readonly state: unknown }>] extends [never]\n ? [] : [H[keyof H]] extends [StatedOk<unknown, infer S extends string>]\n ? string extends S ? [problem: { readonly __trust: 'match needs literal output states' }] : []\n : [problem: { readonly __trust: 'match cannot mix stated and bare returns' }];\n\nexport function match<R extends Result<unknown, unknown>, H extends MatchBase<R, H>>(\n result: R & MatchGuard<R>, handlers: MatchFns<R, H>, ...check: MatchCheck<H>\n): Matched<H>;\nexport function match(result: Result<unknown, unknown>, handlers: object): unknown {\n if (!result.ok) return result;\n const handler = pick(handlers, (result as { state?: unknown }).state);\n if (handler === undefined) return result;\n const value = handler(result.value);\n return isResult(value) ? value : ok(value);\n}\n\n/** Make a result: `Result.ok(value)`, `Result.err({ kind: 'x', ... })`. */\nexport const Result: {\n readonly ok: typeof ok;\n readonly err: typeof err;\n readonly state: typeof state;\n} = { ok, err, state };\n\n/**\n * Apply the discipline:\n * `Trust.try` / `Trust.tryAsync` are the only boundary that may catch a throw;\n * `Trust.decide` is the only place a failure may stop; `Trust.translate` the only place it may change kind.\n */\nexport const Trust: {\n readonly try: typeof tryResult;\n readonly tryAsync: typeof tryResultAsync;\n readonly decide: typeof decide;\n readonly translate: typeof translate;\n readonly match: typeof match;\n} = { try: tryResult, tryAsync: tryResultAsync, decide, translate, match };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,IAAM,cAAc,uBAAO,IAAI,qBAAqB;AACpD,SAAS,MAAw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