@nextera.one/anchor-routing-core 0.1.0
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 +3 -0
- package/dist/index.d.mts +131 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +826 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +773 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
declare const ANCHOR_ERROR_CODES: {
|
|
2
|
+
readonly ANCHOR_PARSE_EMPTY_INPUT: "ANCHOR_PARSE_EMPTY_INPUT";
|
|
3
|
+
readonly ANCHOR_PARSE_INVALID_FORMAT: "ANCHOR_PARSE_INVALID_FORMAT";
|
|
4
|
+
readonly ANCHOR_PARSE_EMPTY_PAGE: "ANCHOR_PARSE_EMPTY_PAGE";
|
|
5
|
+
readonly ANCHOR_PARSE_EMPTY_SECTION: "ANCHOR_PARSE_EMPTY_SECTION";
|
|
6
|
+
readonly ANCHOR_PARSE_EMPTY_KEY: "ANCHOR_PARSE_EMPTY_KEY";
|
|
7
|
+
readonly ANCHOR_PARSE_INVALID_DOT_KEY: "ANCHOR_PARSE_INVALID_DOT_KEY";
|
|
8
|
+
readonly ANCHOR_PARSE_INVALID_INTENT_PAIR: "ANCHOR_PARSE_INVALID_INTENT_PAIR";
|
|
9
|
+
readonly ANCHOR_PARSE_DUPLICATE_NAMED_ARG: "ANCHOR_PARSE_DUPLICATE_NAMED_ARG";
|
|
10
|
+
readonly ANCHOR_ESCAPE_INVALID_SEQUENCE: "ANCHOR_ESCAPE_INVALID_SEQUENCE";
|
|
11
|
+
readonly ANCHOR_VALIDATE_UNESCAPED_RESERVED_CHAR: "ANCHOR_VALIDATE_UNESCAPED_RESERVED_CHAR";
|
|
12
|
+
readonly ANCHOR_VALIDATE_TOO_MANY_ARGS: "ANCHOR_VALIDATE_TOO_MANY_ARGS";
|
|
13
|
+
readonly ANCHOR_RESOLVE_PAGE_NOT_FOUND: "ANCHOR_RESOLVE_PAGE_NOT_FOUND";
|
|
14
|
+
readonly ANCHOR_RESOLVE_SECTION_NOT_FOUND: "ANCHOR_RESOLVE_SECTION_NOT_FOUND";
|
|
15
|
+
readonly ANCHOR_RESOLVE_KEY_NOT_FOUND: "ANCHOR_RESOLVE_KEY_NOT_FOUND";
|
|
16
|
+
readonly ANCHOR_RESOLVE_BINDING_MISSING_ARG: "ANCHOR_RESOLVE_BINDING_MISSING_ARG";
|
|
17
|
+
readonly ANCHOR_RESOLVE_INVALID_NAMED_ARG: "ANCHOR_RESOLVE_INVALID_NAMED_ARG";
|
|
18
|
+
};
|
|
19
|
+
type AnchorErrorCode = (typeof ANCHOR_ERROR_CODES)[keyof typeof ANCHOR_ERROR_CODES];
|
|
20
|
+
interface AnchorDiagnostic {
|
|
21
|
+
code: AnchorErrorCode;
|
|
22
|
+
message: string;
|
|
23
|
+
raw: string;
|
|
24
|
+
mode?: string;
|
|
25
|
+
}
|
|
26
|
+
declare class AnchorRouteError extends Error {
|
|
27
|
+
readonly code: AnchorErrorCode;
|
|
28
|
+
readonly raw: string;
|
|
29
|
+
readonly mode?: string;
|
|
30
|
+
constructor(code: AnchorErrorCode, message: string, raw: string, mode?: string);
|
|
31
|
+
toDiagnostic(): AnchorDiagnostic;
|
|
32
|
+
}
|
|
33
|
+
declare function createDiagnostic(code: AnchorErrorCode, message: string, raw: string, mode?: string): AnchorDiagnostic;
|
|
34
|
+
declare function isAnchorRouteError(error: unknown): error is AnchorRouteError;
|
|
35
|
+
|
|
36
|
+
type AnchorRouteMode = 'page' | 'param' | 'dot' | 'intent';
|
|
37
|
+
type AnchorBindingTarget = 'params' | 'query';
|
|
38
|
+
type UnknownNamedArgsMode = 'reject' | 'ignore' | 'keep';
|
|
39
|
+
interface AnchorRouteInstruction {
|
|
40
|
+
mode: AnchorRouteMode;
|
|
41
|
+
raw: string;
|
|
42
|
+
page?: string;
|
|
43
|
+
section?: string;
|
|
44
|
+
key?: string;
|
|
45
|
+
pathTokens?: string[];
|
|
46
|
+
args?: string[];
|
|
47
|
+
namedArgs?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
interface AnchorResolvedRoute {
|
|
50
|
+
success: boolean;
|
|
51
|
+
mode: AnchorRouteMode | 'unknown';
|
|
52
|
+
raw: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
path?: string;
|
|
55
|
+
params?: Record<string, string>;
|
|
56
|
+
query?: Record<string, string>;
|
|
57
|
+
hash?: string;
|
|
58
|
+
title?: string;
|
|
59
|
+
permissions?: string[];
|
|
60
|
+
meta?: Record<string, unknown>;
|
|
61
|
+
errorCode?: AnchorErrorCode;
|
|
62
|
+
errorMessage?: string;
|
|
63
|
+
diagnostics?: AnchorDiagnostic[];
|
|
64
|
+
}
|
|
65
|
+
interface AnchorTargetDefinition {
|
|
66
|
+
key?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
path?: string;
|
|
69
|
+
defaultParams?: Record<string, string>;
|
|
70
|
+
defaultQuery?: Record<string, string>;
|
|
71
|
+
positionalBind?: Record<string, number>;
|
|
72
|
+
namedBind?: Record<string, string>;
|
|
73
|
+
bindingTargets?: Record<string, AnchorBindingTarget>;
|
|
74
|
+
permissions?: string[];
|
|
75
|
+
title?: string;
|
|
76
|
+
hash?: string;
|
|
77
|
+
meta?: Record<string, unknown>;
|
|
78
|
+
requiredNamedArgs?: string[];
|
|
79
|
+
requiredPositionalCount?: number;
|
|
80
|
+
}
|
|
81
|
+
type PageAnchorRegistry = Record<string, Record<string, AnchorTargetDefinition>>;
|
|
82
|
+
type GlobalAnchorRegistry = Record<string, AnchorTargetDefinition>;
|
|
83
|
+
interface AnchorRegistry {
|
|
84
|
+
pages?: PageAnchorRegistry;
|
|
85
|
+
global?: GlobalAnchorRegistry;
|
|
86
|
+
}
|
|
87
|
+
interface AnchorResolveOptions {
|
|
88
|
+
maxArgs?: number;
|
|
89
|
+
unknownNamedArgs?: UnknownNamedArgsMode;
|
|
90
|
+
}
|
|
91
|
+
interface AnchorValidationResult {
|
|
92
|
+
valid: boolean;
|
|
93
|
+
instruction?: AnchorRouteInstruction;
|
|
94
|
+
errors: AnchorDiagnostic[];
|
|
95
|
+
}
|
|
96
|
+
interface DecodedAnchorKey {
|
|
97
|
+
key: string;
|
|
98
|
+
pathTokens: string[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare function buildPageAnchor(page: string, section: string): string;
|
|
102
|
+
declare function buildParamAnchor(key: string, args?: string[]): string;
|
|
103
|
+
declare function buildDotAnchor(tokens: string[]): string;
|
|
104
|
+
declare function buildIntentAnchor(key: string, namedArgs: Record<string, string>): string;
|
|
105
|
+
declare function serializeAnchor(instruction: AnchorRouteInstruction): string;
|
|
106
|
+
|
|
107
|
+
declare const ANCHOR_PATH_PREFIX = "/~";
|
|
108
|
+
declare const ARG_SEPARATOR = ";";
|
|
109
|
+
declare const ANCHOR_SEPARATOR = "~";
|
|
110
|
+
declare const DOT_SEPARATOR = ".";
|
|
111
|
+
declare const RESERVED_ANCHOR_CHARACTERS: readonly ["/", "~", ";", ".", "=", "@", "#", "%"];
|
|
112
|
+
declare const SAFE_LITERAL_CHARACTER: RegExp;
|
|
113
|
+
declare function isReservedAnchorCharacter(character: string): boolean;
|
|
114
|
+
declare function isHexDigit(character: string): boolean;
|
|
115
|
+
|
|
116
|
+
declare function escapeAnchorValue(input: string): string;
|
|
117
|
+
declare function validateEncodedToken(rawToken: string, rawInput: string, mode?: string): void;
|
|
118
|
+
declare function decodeAnchorToken(rawToken: string, rawInput: string, mode?: string): string;
|
|
119
|
+
declare function decodeAnchorKey(rawKey: string, rawInput: string, mode?: string): DecodedAnchorKey;
|
|
120
|
+
declare function escapeAnchorKey(input: string): string;
|
|
121
|
+
|
|
122
|
+
declare function normalizeAnchor(input: string): string;
|
|
123
|
+
|
|
124
|
+
declare function parseAnchor(input: string): AnchorRouteInstruction;
|
|
125
|
+
declare function isAnchorRoute(input: string): boolean;
|
|
126
|
+
|
|
127
|
+
declare function resolveAnchor(input: string | AnchorRouteInstruction, registry?: AnchorRegistry, options?: AnchorResolveOptions): AnchorResolvedRoute;
|
|
128
|
+
|
|
129
|
+
declare function validateAnchor(input: string | AnchorRouteInstruction, registry?: AnchorRegistry, options?: AnchorResolveOptions): AnchorValidationResult;
|
|
130
|
+
|
|
131
|
+
export { ANCHOR_ERROR_CODES, ANCHOR_PATH_PREFIX, ANCHOR_SEPARATOR, ARG_SEPARATOR, type AnchorBindingTarget, type AnchorDiagnostic, type AnchorErrorCode, type AnchorRegistry, type AnchorResolveOptions, type AnchorResolvedRoute, AnchorRouteError, type AnchorRouteInstruction, type AnchorRouteMode, type AnchorTargetDefinition, type AnchorValidationResult, DOT_SEPARATOR, type DecodedAnchorKey, type GlobalAnchorRegistry, type PageAnchorRegistry, RESERVED_ANCHOR_CHARACTERS, SAFE_LITERAL_CHARACTER, type UnknownNamedArgsMode, buildDotAnchor, buildIntentAnchor, buildPageAnchor, buildParamAnchor, createDiagnostic, decodeAnchorKey, decodeAnchorToken, escapeAnchorKey, escapeAnchorValue, isAnchorRoute, isAnchorRouteError, isHexDigit, isReservedAnchorCharacter, normalizeAnchor, parseAnchor, resolveAnchor, serializeAnchor, validateAnchor, validateEncodedToken };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
declare const ANCHOR_ERROR_CODES: {
|
|
2
|
+
readonly ANCHOR_PARSE_EMPTY_INPUT: "ANCHOR_PARSE_EMPTY_INPUT";
|
|
3
|
+
readonly ANCHOR_PARSE_INVALID_FORMAT: "ANCHOR_PARSE_INVALID_FORMAT";
|
|
4
|
+
readonly ANCHOR_PARSE_EMPTY_PAGE: "ANCHOR_PARSE_EMPTY_PAGE";
|
|
5
|
+
readonly ANCHOR_PARSE_EMPTY_SECTION: "ANCHOR_PARSE_EMPTY_SECTION";
|
|
6
|
+
readonly ANCHOR_PARSE_EMPTY_KEY: "ANCHOR_PARSE_EMPTY_KEY";
|
|
7
|
+
readonly ANCHOR_PARSE_INVALID_DOT_KEY: "ANCHOR_PARSE_INVALID_DOT_KEY";
|
|
8
|
+
readonly ANCHOR_PARSE_INVALID_INTENT_PAIR: "ANCHOR_PARSE_INVALID_INTENT_PAIR";
|
|
9
|
+
readonly ANCHOR_PARSE_DUPLICATE_NAMED_ARG: "ANCHOR_PARSE_DUPLICATE_NAMED_ARG";
|
|
10
|
+
readonly ANCHOR_ESCAPE_INVALID_SEQUENCE: "ANCHOR_ESCAPE_INVALID_SEQUENCE";
|
|
11
|
+
readonly ANCHOR_VALIDATE_UNESCAPED_RESERVED_CHAR: "ANCHOR_VALIDATE_UNESCAPED_RESERVED_CHAR";
|
|
12
|
+
readonly ANCHOR_VALIDATE_TOO_MANY_ARGS: "ANCHOR_VALIDATE_TOO_MANY_ARGS";
|
|
13
|
+
readonly ANCHOR_RESOLVE_PAGE_NOT_FOUND: "ANCHOR_RESOLVE_PAGE_NOT_FOUND";
|
|
14
|
+
readonly ANCHOR_RESOLVE_SECTION_NOT_FOUND: "ANCHOR_RESOLVE_SECTION_NOT_FOUND";
|
|
15
|
+
readonly ANCHOR_RESOLVE_KEY_NOT_FOUND: "ANCHOR_RESOLVE_KEY_NOT_FOUND";
|
|
16
|
+
readonly ANCHOR_RESOLVE_BINDING_MISSING_ARG: "ANCHOR_RESOLVE_BINDING_MISSING_ARG";
|
|
17
|
+
readonly ANCHOR_RESOLVE_INVALID_NAMED_ARG: "ANCHOR_RESOLVE_INVALID_NAMED_ARG";
|
|
18
|
+
};
|
|
19
|
+
type AnchorErrorCode = (typeof ANCHOR_ERROR_CODES)[keyof typeof ANCHOR_ERROR_CODES];
|
|
20
|
+
interface AnchorDiagnostic {
|
|
21
|
+
code: AnchorErrorCode;
|
|
22
|
+
message: string;
|
|
23
|
+
raw: string;
|
|
24
|
+
mode?: string;
|
|
25
|
+
}
|
|
26
|
+
declare class AnchorRouteError extends Error {
|
|
27
|
+
readonly code: AnchorErrorCode;
|
|
28
|
+
readonly raw: string;
|
|
29
|
+
readonly mode?: string;
|
|
30
|
+
constructor(code: AnchorErrorCode, message: string, raw: string, mode?: string);
|
|
31
|
+
toDiagnostic(): AnchorDiagnostic;
|
|
32
|
+
}
|
|
33
|
+
declare function createDiagnostic(code: AnchorErrorCode, message: string, raw: string, mode?: string): AnchorDiagnostic;
|
|
34
|
+
declare function isAnchorRouteError(error: unknown): error is AnchorRouteError;
|
|
35
|
+
|
|
36
|
+
type AnchorRouteMode = 'page' | 'param' | 'dot' | 'intent';
|
|
37
|
+
type AnchorBindingTarget = 'params' | 'query';
|
|
38
|
+
type UnknownNamedArgsMode = 'reject' | 'ignore' | 'keep';
|
|
39
|
+
interface AnchorRouteInstruction {
|
|
40
|
+
mode: AnchorRouteMode;
|
|
41
|
+
raw: string;
|
|
42
|
+
page?: string;
|
|
43
|
+
section?: string;
|
|
44
|
+
key?: string;
|
|
45
|
+
pathTokens?: string[];
|
|
46
|
+
args?: string[];
|
|
47
|
+
namedArgs?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
interface AnchorResolvedRoute {
|
|
50
|
+
success: boolean;
|
|
51
|
+
mode: AnchorRouteMode | 'unknown';
|
|
52
|
+
raw: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
path?: string;
|
|
55
|
+
params?: Record<string, string>;
|
|
56
|
+
query?: Record<string, string>;
|
|
57
|
+
hash?: string;
|
|
58
|
+
title?: string;
|
|
59
|
+
permissions?: string[];
|
|
60
|
+
meta?: Record<string, unknown>;
|
|
61
|
+
errorCode?: AnchorErrorCode;
|
|
62
|
+
errorMessage?: string;
|
|
63
|
+
diagnostics?: AnchorDiagnostic[];
|
|
64
|
+
}
|
|
65
|
+
interface AnchorTargetDefinition {
|
|
66
|
+
key?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
path?: string;
|
|
69
|
+
defaultParams?: Record<string, string>;
|
|
70
|
+
defaultQuery?: Record<string, string>;
|
|
71
|
+
positionalBind?: Record<string, number>;
|
|
72
|
+
namedBind?: Record<string, string>;
|
|
73
|
+
bindingTargets?: Record<string, AnchorBindingTarget>;
|
|
74
|
+
permissions?: string[];
|
|
75
|
+
title?: string;
|
|
76
|
+
hash?: string;
|
|
77
|
+
meta?: Record<string, unknown>;
|
|
78
|
+
requiredNamedArgs?: string[];
|
|
79
|
+
requiredPositionalCount?: number;
|
|
80
|
+
}
|
|
81
|
+
type PageAnchorRegistry = Record<string, Record<string, AnchorTargetDefinition>>;
|
|
82
|
+
type GlobalAnchorRegistry = Record<string, AnchorTargetDefinition>;
|
|
83
|
+
interface AnchorRegistry {
|
|
84
|
+
pages?: PageAnchorRegistry;
|
|
85
|
+
global?: GlobalAnchorRegistry;
|
|
86
|
+
}
|
|
87
|
+
interface AnchorResolveOptions {
|
|
88
|
+
maxArgs?: number;
|
|
89
|
+
unknownNamedArgs?: UnknownNamedArgsMode;
|
|
90
|
+
}
|
|
91
|
+
interface AnchorValidationResult {
|
|
92
|
+
valid: boolean;
|
|
93
|
+
instruction?: AnchorRouteInstruction;
|
|
94
|
+
errors: AnchorDiagnostic[];
|
|
95
|
+
}
|
|
96
|
+
interface DecodedAnchorKey {
|
|
97
|
+
key: string;
|
|
98
|
+
pathTokens: string[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare function buildPageAnchor(page: string, section: string): string;
|
|
102
|
+
declare function buildParamAnchor(key: string, args?: string[]): string;
|
|
103
|
+
declare function buildDotAnchor(tokens: string[]): string;
|
|
104
|
+
declare function buildIntentAnchor(key: string, namedArgs: Record<string, string>): string;
|
|
105
|
+
declare function serializeAnchor(instruction: AnchorRouteInstruction): string;
|
|
106
|
+
|
|
107
|
+
declare const ANCHOR_PATH_PREFIX = "/~";
|
|
108
|
+
declare const ARG_SEPARATOR = ";";
|
|
109
|
+
declare const ANCHOR_SEPARATOR = "~";
|
|
110
|
+
declare const DOT_SEPARATOR = ".";
|
|
111
|
+
declare const RESERVED_ANCHOR_CHARACTERS: readonly ["/", "~", ";", ".", "=", "@", "#", "%"];
|
|
112
|
+
declare const SAFE_LITERAL_CHARACTER: RegExp;
|
|
113
|
+
declare function isReservedAnchorCharacter(character: string): boolean;
|
|
114
|
+
declare function isHexDigit(character: string): boolean;
|
|
115
|
+
|
|
116
|
+
declare function escapeAnchorValue(input: string): string;
|
|
117
|
+
declare function validateEncodedToken(rawToken: string, rawInput: string, mode?: string): void;
|
|
118
|
+
declare function decodeAnchorToken(rawToken: string, rawInput: string, mode?: string): string;
|
|
119
|
+
declare function decodeAnchorKey(rawKey: string, rawInput: string, mode?: string): DecodedAnchorKey;
|
|
120
|
+
declare function escapeAnchorKey(input: string): string;
|
|
121
|
+
|
|
122
|
+
declare function normalizeAnchor(input: string): string;
|
|
123
|
+
|
|
124
|
+
declare function parseAnchor(input: string): AnchorRouteInstruction;
|
|
125
|
+
declare function isAnchorRoute(input: string): boolean;
|
|
126
|
+
|
|
127
|
+
declare function resolveAnchor(input: string | AnchorRouteInstruction, registry?: AnchorRegistry, options?: AnchorResolveOptions): AnchorResolvedRoute;
|
|
128
|
+
|
|
129
|
+
declare function validateAnchor(input: string | AnchorRouteInstruction, registry?: AnchorRegistry, options?: AnchorResolveOptions): AnchorValidationResult;
|
|
130
|
+
|
|
131
|
+
export { ANCHOR_ERROR_CODES, ANCHOR_PATH_PREFIX, ANCHOR_SEPARATOR, ARG_SEPARATOR, type AnchorBindingTarget, type AnchorDiagnostic, type AnchorErrorCode, type AnchorRegistry, type AnchorResolveOptions, type AnchorResolvedRoute, AnchorRouteError, type AnchorRouteInstruction, type AnchorRouteMode, type AnchorTargetDefinition, type AnchorValidationResult, DOT_SEPARATOR, type DecodedAnchorKey, type GlobalAnchorRegistry, type PageAnchorRegistry, RESERVED_ANCHOR_CHARACTERS, SAFE_LITERAL_CHARACTER, type UnknownNamedArgsMode, buildDotAnchor, buildIntentAnchor, buildPageAnchor, buildParamAnchor, createDiagnostic, decodeAnchorKey, decodeAnchorToken, escapeAnchorKey, escapeAnchorValue, isAnchorRoute, isAnchorRouteError, isHexDigit, isReservedAnchorCharacter, normalizeAnchor, parseAnchor, resolveAnchor, serializeAnchor, validateAnchor, validateEncodedToken };
|