@bomb.sh/router 0.7.0 → 0.8.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.
Files changed (45) hide show
  1. package/README.md +50 -24
  2. package/esm/lib/checkpoint.js +26 -1
  3. package/esm/lib/command.d.ts +3 -2
  4. package/esm/lib/command.js +2 -1
  5. package/esm/lib/dynamic.d.ts +3 -3
  6. package/esm/lib/dynamic.js +20 -3
  7. package/esm/lib/extend.d.ts +3 -2
  8. package/esm/lib/extend.js +3 -1
  9. package/esm/lib/parse.js +6 -5
  10. package/esm/lib/pipeline.d.ts +1 -1
  11. package/esm/lib/route.d.ts +16 -3
  12. package/esm/lib/route.js +5 -2
  13. package/esm/lib/types.d.ts +4 -4
  14. package/esm/mod.d.ts +2 -1
  15. package/esm/mod.js +2 -1
  16. package/package.json +1 -1
  17. package/src/_dnt.polyfills.ts +0 -27
  18. package/src/lib/argument.ts +0 -100
  19. package/src/lib/bind.ts +0 -421
  20. package/src/lib/checkpoint.ts +0 -10
  21. package/src/lib/command.ts +0 -36
  22. package/src/lib/dasherize.ts +0 -7
  23. package/src/lib/decode.ts +0 -55
  24. package/src/lib/definition.ts +0 -17
  25. package/src/lib/dynamic.ts +0 -39
  26. package/src/lib/env.ts +0 -142
  27. package/src/lib/extend.ts +0 -12
  28. package/src/lib/maybe.ts +0 -22
  29. package/src/lib/multiple.ts +0 -23
  30. package/src/lib/option.ts +0 -57
  31. package/src/lib/param.ts +0 -96
  32. package/src/lib/parse.ts +0 -478
  33. package/src/lib/pipeline.ts +0 -549
  34. package/src/lib/print.ts +0 -216
  35. package/src/lib/read.ts +0 -133
  36. package/src/lib/rest.ts +0 -10
  37. package/src/lib/result.ts +0 -10
  38. package/src/lib/route.ts +0 -77
  39. package/src/lib/toggle.ts +0 -132
  40. package/src/lib/tokenize.ts +0 -74
  41. package/src/lib/tokenizer.ts +0 -191
  42. package/src/lib/transform.ts +0 -49
  43. package/src/lib/types.ts +0 -460
  44. package/src/lib/values.ts +0 -131
  45. package/src/mod.ts +0 -74
package/src/lib/values.ts DELETED
@@ -1,131 +0,0 @@
1
- import type { Maybe } from "./maybe.js";
2
- import { brand, type IdentityElement } from "./pipeline.js";
3
- import type { AnyRoute, RoutePath } from "./types.js";
4
-
5
- export type ValueSource = {
6
- name: string;
7
- value: unknown;
8
- };
9
-
10
- export function withValues(
11
- values: readonly ValueSource[],
12
- ): IdentityElement<AnyRoute> {
13
- return brand<IdentityElement<AnyRoute>>(
14
- (route: AnyRoute) => {
15
- let phases = [...route.phases];
16
- let phase = phases.pop()!;
17
- phases.push({
18
- ...phase,
19
- values: phase.values.concat(values),
20
- });
21
- return {
22
- ...route,
23
- phases,
24
- };
25
- },
26
- );
27
- }
28
-
29
- export type ValueClaim = {
30
- result: Maybe<{
31
- source: string;
32
- address: readonly string[];
33
- value: unknown;
34
- }>;
35
- rest: Values;
36
- };
37
-
38
- export class Values {
39
- mounts: Map<RoutePath, ValueSource[]>;
40
- claims: Set<ClaimId>;
41
-
42
- constructor(
43
- mounts: Map<RoutePath, ValueSource[]> = new Map(),
44
- claims: Set<ClaimId> = new Set(),
45
- ) {
46
- this.mounts = mounts;
47
- this.claims = claims;
48
- }
49
-
50
- mount(path: readonly string[], sources: readonly ValueSource[]): Values {
51
- if (sources.length === 0) {
52
- return this;
53
- }
54
- const id = routeId(path);
55
-
56
- return new Values(
57
- new Map([...this.mounts.entries(), [
58
- id,
59
- (this.mounts.get(id) ?? []).concat(sources),
60
- ]]),
61
- this.claims,
62
- );
63
- }
64
-
65
- claim({ route, address }: ClaimOptions): ValueClaim {
66
- let id = claimId([...route, ...address]);
67
- const nope: ValueClaim = { result: { exists: false }, rest: this };
68
- if (this.claims.has(id)) {
69
- return nope;
70
- }
71
-
72
- for (let end = route.length; end >= 0; end--) {
73
- let mountId = routeId(route.slice(0, end));
74
- let sources = this.mounts.get(mountId) ?? [];
75
- for (let { name, value } of sources) {
76
- let result = find(value, [...route.slice(end), ...address]);
77
- if (result.exists) {
78
- let rest = new Values(this.mounts, new Set([...this.claims, id]));
79
- return {
80
- result: {
81
- exists: true,
82
- value: {
83
- source: name,
84
- address,
85
- value: result.value,
86
- },
87
- },
88
- rest,
89
- };
90
- }
91
- }
92
- }
93
- return nope;
94
- }
95
- }
96
-
97
- export interface ClaimOptions {
98
- route: readonly string[];
99
- address: readonly string[];
100
- }
101
-
102
- type ClaimId = string;
103
-
104
- function routeId(address: readonly string[]): RoutePath {
105
- return `/${address.join("/")}`;
106
- }
107
-
108
- function claimId(address: readonly string[]): ClaimId {
109
- return JSON.stringify(address);
110
- }
111
-
112
- function find(value: unknown, path: readonly string[]): Maybe<unknown> {
113
- let current: unknown = value;
114
-
115
- for (let key of path) {
116
- if (
117
- current === null ||
118
- (typeof current !== "object" && typeof current !== "function") ||
119
- !Object.hasOwn(current, key)
120
- ) {
121
- return { exists: false };
122
- }
123
-
124
- current = (current as Record<string, unknown>)[key];
125
- }
126
-
127
- return {
128
- exists: true,
129
- value: current,
130
- };
131
- }
package/src/mod.ts DELETED
@@ -1,74 +0,0 @@
1
- import "./_dnt.polyfills.js";
2
- export { argument } from "./lib/argument.js";
3
-
4
- export { extend } from "./lib/extend.js";
5
- export { command } from "./lib/command.js";
6
- export type { CommandZero } from "./lib/command.js";
7
-
8
- export { checkpoint } from "./lib/checkpoint.js";
9
-
10
- export { description, name } from "./lib/definition.js";
11
-
12
- export { env, withEnvs } from "./lib/env.js";
13
- export type { Environment, EnvSource } from "./lib/env.js";
14
-
15
- export { option } from "./lib/option.js";
16
- export { multiple } from "./lib/multiple.js";
17
-
18
- export { param, schema } from "./lib/param.js";
19
- export type { Param } from "./lib/param.js";
20
-
21
- export { parse } from "./lib/parse.js";
22
-
23
- export { mark } from "./lib/pipeline.js";
24
- export type { Transform, TransformElement } from "./lib/pipeline.js";
25
-
26
- export { printErrors, printHelp, printVersion } from "./lib/print.js";
27
-
28
- export type { Rest } from "./lib/rest.js";
29
-
30
- export { cli } from "./lib/read.js";
31
- export type {
32
- CLIOptions,
33
- CLIRead,
34
- ReadCLI,
35
- Symbol as CLISymbol,
36
- } from "./lib/read.js";
37
-
38
- export { executable, route, routes, version } from "./lib/route.js";
39
- export type { RouteZero } from "./lib/route.js";
40
-
41
- export { toggle } from "./lib/toggle.js";
42
-
43
- export { transform } from "./lib/transform.js";
44
-
45
- export { withValues } from "./lib/values.js";
46
- export type { ValueSource } from "./lib/values.js";
47
-
48
- export type { Literal } from "./lib/tokenize.js";
49
- export type { Result } from "./lib/result.js";
50
-
51
- export type {
52
- AnyIntent,
53
- AnyRoute,
54
- Definition,
55
- Execute,
56
- Help,
57
- Input,
58
- Intent,
59
- IntentsOf,
60
- Issue,
61
- Method,
62
- MethodNotAllowed,
63
- MethodsOf,
64
- ModelOf,
65
- ModelsByRoute,
66
- Outcome,
67
- Path,
68
- PathOf,
69
- Route,
70
- RoutePath,
71
- Schema,
72
- UnprocessableContent,
73
- Version,
74
- } from "./lib/types.js";