@decocms/blocks 8.1.0-next.7 → 8.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/dist/v8/cli/check/index.d.ts +6 -2
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +34 -7
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/color.d.ts +14 -0
- package/dist/v8/cli/color.d.ts.map +1 -0
- package/dist/v8/cli/color.js +14 -0
- package/dist/v8/cli/color.js.map +1 -0
- package/dist/v8/cli/log.d.ts +4 -0
- package/dist/v8/cli/log.d.ts.map +1 -1
- package/dist/v8/cli/log.js +9 -0
- package/dist/v8/cli/log.js.map +1 -1
- package/dist/v8/cli/run.d.ts +1 -0
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +17 -3
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/schema/index.d.ts.map +1 -1
- package/dist/v8/cli/schema/index.js +5 -3
- package/dist/v8/cli/schema/index.js.map +1 -1
- package/dist/v8/cli/schema/tsProgram.d.ts +1 -0
- package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -1
- package/dist/v8/cli/schema/tsProgram.js +1 -0
- package/dist/v8/cli/schema/tsProgram.js.map +1 -1
- package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -1
- package/dist/v8/cli/schema/typeToSchema.js +50 -7
- package/dist/v8/cli/schema/typeToSchema.js.map +1 -1
- package/dist/v8/cms.js +1 -1
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/matchRoute.d.ts +12 -10
- package/dist/v8/matchRoute.d.ts.map +1 -1
- package/dist/v8/matchRoute.js +60 -86
- package/dist/v8/matchRoute.js.map +1 -1
- package/dist/v8/remoteLoader.d.ts +2 -0
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +7 -16
- package/dist/v8/remoteLoader.js.map +1 -1
- package/dist/v8/routeTrie.d.ts +43 -0
- package/dist/v8/routeTrie.d.ts.map +1 -0
- package/dist/v8/routeTrie.js +88 -0
- package/dist/v8/routeTrie.js.map +1 -0
- package/dist/v8/types.d.ts +12 -1
- package/dist/v8/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/v8/cli/check/index.ts +32 -7
- package/src/v8/cli/color.ts +29 -0
- package/src/v8/cli/log.ts +12 -0
- package/src/v8/cli/run.ts +18 -3
- package/src/v8/cli/schema/index.ts +5 -3
- package/src/v8/cli/schema/tsProgram.ts +2 -1
- package/src/v8/cli/schema/typeToSchema.ts +47 -7
- package/src/v8/cms.ts +1 -1
- package/src/v8/matchRoute.ts +70 -106
- package/src/v8/remoteLoader.ts +13 -17
- package/src/v8/routeTrie.ts +103 -0
- package/src/v8/types.ts +12 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The segment trie behind `matchRoute` (see /next/router-internals): paths
|
|
3
|
+
* compile into nodes keyed by segment, and a lookup walks the URL's segments,
|
|
4
|
+
* trying the literal child, then the parameter child, then a trailing `*` (a
|
|
5
|
+
* splat: one or more remaining segments). A lookup costs the URL's depth, not
|
|
6
|
+
* the number of entries. No regex, no sorting.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** A leaf holds the entry and its parameter names, in path order; `splat` is a trailing `*`'s leaf. */
|
|
10
|
+
type Leaf<T> = { value: T; names: string[] };
|
|
11
|
+
export type TrieNode<T> = {
|
|
12
|
+
literals: Map<string, TrieNode<T>>;
|
|
13
|
+
param?: TrieNode<T>;
|
|
14
|
+
leaf?: Leaf<T>;
|
|
15
|
+
splat?: Leaf<T>;
|
|
16
|
+
};
|
|
17
|
+
export type Hit<T> = { value: T; params: Record<string, string>; rest: string[] };
|
|
18
|
+
|
|
19
|
+
/** A trie holding `entries` (`[path, value]`); on a conflict the earlier keeps the leaf. */
|
|
20
|
+
export function buildTrie<T>(entries: Iterable<[string, T]>): TrieNode<T> {
|
|
21
|
+
const root: TrieNode<T> = { literals: new Map() };
|
|
22
|
+
for (const [path, value] of entries) insert(root, path, value);
|
|
23
|
+
return root;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Adds `path`; returns the value already holding its leaf (a conflict: the earlier keeps it). */
|
|
27
|
+
export function insert<T>(root: TrieNode<T>, path: string, value: T): T | undefined {
|
|
28
|
+
const names: string[] = [];
|
|
29
|
+
const segments = splitPath(path);
|
|
30
|
+
let node = root;
|
|
31
|
+
for (const [i, segment] of segments.entries()) {
|
|
32
|
+
if (segment === "*" && i === segments.length - 1) {
|
|
33
|
+
if (node.splat) return node.splat.value;
|
|
34
|
+
node.splat = { value, names };
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
if (segment.startsWith(":") && segment.length > 1) {
|
|
38
|
+
names.push(segment.slice(1));
|
|
39
|
+
node = node.param ??= { literals: new Map() };
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const literal = safeDecode(segment);
|
|
43
|
+
const child = node.literals.get(literal) ?? { literals: new Map() };
|
|
44
|
+
node.literals.set(literal, child);
|
|
45
|
+
node = child;
|
|
46
|
+
}
|
|
47
|
+
if (node.leaf) return node.leaf.value;
|
|
48
|
+
node.leaf = { value, names };
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Walks the URL's segments: the literal child first, then the parameter child, then the splat. */
|
|
53
|
+
export function lookup<T>(
|
|
54
|
+
node: TrieNode<T>,
|
|
55
|
+
segs: string[],
|
|
56
|
+
i = 0,
|
|
57
|
+
vals: string[] = [],
|
|
58
|
+
): Hit<T> | null {
|
|
59
|
+
if (i === segs.length) return node.leaf ? hit(node.leaf, vals, []) : null;
|
|
60
|
+
const literal = node.literals.get(segs[i]!);
|
|
61
|
+
let found = literal ? lookup(literal, segs, i + 1, vals) : null;
|
|
62
|
+
// A parameter is one segment and never contains a slash, even an encoded one.
|
|
63
|
+
if (!found && node.param && !segs[i]!.includes("/")) {
|
|
64
|
+
found = lookup(node.param, segs, i + 1, [...vals, segs[i]!]);
|
|
65
|
+
}
|
|
66
|
+
// A splat takes the rest (at least one segment, as there is one here).
|
|
67
|
+
return found ?? (node.splat ? hit(node.splat, vals, segs.slice(i)) : null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function hit<T>({ value, names }: Leaf<T>, values: string[], rest: string[]): Hit<T> {
|
|
71
|
+
const params: Record<string, string> = Object.fromEntries(names.map((n, i) => [n, values[i]!]));
|
|
72
|
+
if (rest.length > 0) params["*"] = rest.join("/");
|
|
73
|
+
return { value, params, rest };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `/a/b/`, `/a//b` and `/a/b?x` all name `["a", "b"]`; `/` names `[]`. */
|
|
77
|
+
export function splitPath(path: string): string[] {
|
|
78
|
+
return splitRef(path)
|
|
79
|
+
.path.split("/")
|
|
80
|
+
.filter((segment) => segment.length > 0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A path or URL split at its first `?` and `#`: everything before, the query
|
|
85
|
+
* (without its `?`, `""` when there's none) and the fragment (with its `#`).
|
|
86
|
+
*/
|
|
87
|
+
export function splitRef(ref: string): { path: string; query: string; hash: string } {
|
|
88
|
+
const hashAt = ref.indexOf("#") === -1 ? ref.length : ref.indexOf("#");
|
|
89
|
+
const queryAt = ref.indexOf("?") === -1 || ref.indexOf("?") > hashAt ? hashAt : ref.indexOf("?");
|
|
90
|
+
return {
|
|
91
|
+
path: ref.slice(0, queryAt),
|
|
92
|
+
query: ref.slice(queryAt + 1, hashAt),
|
|
93
|
+
hash: ref.slice(hashAt),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function safeDecode(segment: string): string {
|
|
98
|
+
try {
|
|
99
|
+
return decodeURIComponent(segment);
|
|
100
|
+
} catch {
|
|
101
|
+
return segment;
|
|
102
|
+
}
|
|
103
|
+
}
|
package/src/v8/types.ts
CHANGED
|
@@ -107,7 +107,12 @@ export interface Page extends Route {
|
|
|
107
107
|
|
|
108
108
|
/** The built-in `redirect` block. */
|
|
109
109
|
export interface Redirect {
|
|
110
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Literal path or template (`:name` segments, an optional trailing `/*`),
|
|
112
|
+
* optionally scoped to a query (`/calcados?map=c,ft`): then it matches only
|
|
113
|
+
* a request whose query string is exactly that one, and wins over a
|
|
114
|
+
* path-only `from` for the same URL.
|
|
115
|
+
*/
|
|
111
116
|
from: string;
|
|
112
117
|
to: string;
|
|
113
118
|
/** `true` for a 301, `false` for a 302. */
|
|
@@ -250,6 +255,12 @@ export interface CMSConfig {
|
|
|
250
255
|
content: ContentModule | Loader;
|
|
251
256
|
/** ms between `update()` checks of a content source that has one; minimum 60 000. */
|
|
252
257
|
interval?: number;
|
|
258
|
+
/**
|
|
259
|
+
* Local development (`import.meta.env.DEV`, `process.env.NODE_ENV === "development"`):
|
|
260
|
+
* hosted releases are never swapped in, so local files win. Drafts still load.
|
|
261
|
+
* The SDK reads no environment variable for it; default `false`.
|
|
262
|
+
*/
|
|
263
|
+
dev?: boolean;
|
|
253
264
|
/** Where telemetry goes; see /next/telemetry. */
|
|
254
265
|
telemetry?: false | TelemetryConfig;
|
|
255
266
|
preview?: {
|