@decocms/blocks 8.1.0-next.6 → 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/content.d.ts +24 -3
- package/dist/v8/cli/content.d.ts.map +1 -1
- package/dist/v8/cli/content.js +70 -5
- package/dist/v8/cli/content.js.map +1 -1
- 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 +18 -4
- 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.d.ts.map +1 -1
- package/dist/v8/cms.js +16 -19
- package/dist/v8/cms.js.map +1 -1
- package/dist/v8/content.d.ts +4 -5
- package/dist/v8/content.d.ts.map +1 -1
- package/dist/v8/content.js +46 -44
- package/dist/v8/content.js.map +1 -1
- package/dist/v8/draftChanges.d.ts +37 -14
- package/dist/v8/draftChanges.d.ts.map +1 -1
- package/dist/v8/draftChanges.js +66 -44
- package/dist/v8/draftChanges.js.map +1 -1
- package/dist/v8/identity.d.ts +0 -2
- package/dist/v8/identity.d.ts.map +1 -1
- package/dist/v8/identity.js +0 -10
- package/dist/v8/identity.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 +4 -4
- package/dist/v8/remoteLoader.d.ts.map +1 -1
- package/dist/v8/remoteLoader.js +106 -96
- 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/telemetry.d.ts +7 -7
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +24 -100
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/types.d.ts +59 -17
- 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/content.ts +85 -5
- package/src/v8/cli/log.ts +12 -0
- package/src/v8/cli/run.ts +19 -4
- 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 +17 -20
- package/src/v8/content.ts +54 -46
- package/src/v8/draftChanges.ts +79 -43
- package/src/v8/identity.ts +0 -10
- package/src/v8/matchRoute.ts +70 -106
- package/src/v8/remoteLoader.ts +112 -111
- package/src/v8/routeTrie.ts +103 -0
- package/src/v8/telemetry.ts +27 -108
- package/src/v8/types.ts +60 -15
package/dist/v8/remoteLoader.js
CHANGED
|
@@ -1,60 +1,75 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `remoteLoader`: hosted releases from
|
|
3
|
-
* content module, or any loader). See /next/hosted-releases-internals
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* `remoteLoader`: hosted releases from `delivery.decocms.com`, over a fallback
|
|
3
|
+
* (the content module, or any loader). See /next/hosted-releases-internals.
|
|
4
|
+
* Drafts aren't a loader's job: the CMS layers a draft's changes over what
|
|
5
|
+
* `load()` returns (see ./draftChanges.ts).
|
|
6
6
|
*
|
|
7
|
-
* - `load()` never touches the network: it returns the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* - `load()` never touches the network: it returns the release this process
|
|
8
|
+
* last swapped in, or the fallback's content until then. Nothing persists
|
|
9
|
+
* across restarts: every boot starts from the fallback.
|
|
10
|
+
* - `update()` (the CMS calls it in the background, on first use and then
|
|
11
|
+
* every interval) reads `sites/<site>/latest.json`,
|
|
12
|
+
* `{ revision, schemaHash, publishedAt }`. Whoever is newer wins: when it
|
|
13
|
+
* names a revision other than the one this process last swapped in, its
|
|
14
|
+
* `schemaHash` equals the fallback's, and its `publishedAt` is later than
|
|
15
|
+
* the fallback's `committedAt` (the commit time of the git HEAD
|
|
16
|
+
* `deco content` built it from), it downloads
|
|
17
|
+
* `sites/<site>/revisions/<revision>.json`, `{ revision, schemaHash, blocks }`,
|
|
18
|
+
* and swaps it in whole. Otherwise, and on any error, memory stays as it is.
|
|
19
|
+
* A fallback without a `schemaHash` never swaps; one without a `committedAt`
|
|
20
|
+
* (a custom loader, an older content module, a build outside git) counts as
|
|
21
|
+
* the oldest. Studio writes `publishedAt` on Publish, on "Make current" (a
|
|
22
|
+
* rollback) and on Resync, so a rollback wins over the bundles of earlier
|
|
23
|
+
* commits and a deploy of a later commit wins over the rollback. Commit
|
|
24
|
+
* time, not build time: a slow build of an older commit that finishes after
|
|
25
|
+
* a publish still loses to it.
|
|
26
|
+
* Pointers aren't ordered among themselves, and the fallback's content is
|
|
27
|
+
* never compared: only the two timestamps are.
|
|
28
|
+
* - With `dev: true` (`createCMS({ dev })`), it never swaps, so local files win.
|
|
29
|
+
* The SDK reads no environment variable to decide this: the site passes it
|
|
30
|
+
* (`import.meta.env.DEV`, `process.env.NODE_ENV === "development"`).
|
|
17
31
|
* - A release larger than `MAX_SNAPSHOT_BYTES` is refused while it downloads,
|
|
18
32
|
* before it's buffered whole (a Worker isolate has 128 MB).
|
|
19
|
-
* - Without `site`
|
|
33
|
+
* - Without `site` it's a plain loader over the fallback.
|
|
20
34
|
*
|
|
21
35
|
* Instances are process-wide singletons, like `createCMS`'s.
|
|
22
36
|
*/
|
|
23
37
|
import { readBoundedJson, timeoutSignal } from "./boundedJson.js";
|
|
24
|
-
import { computeContentRevision } from "./canonical.js";
|
|
25
38
|
import { isSnapshot, PEEK_RELEASE, peekRelease } from "./content.js";
|
|
26
|
-
import { clearGlobals, contentIdentity
|
|
39
|
+
import { clearGlobals, contentIdentity } from "./identity.js";
|
|
27
40
|
import { isPlainObject } from "./json.js";
|
|
28
|
-
/** The hosted delivery origin:
|
|
41
|
+
/** The hosted delivery origin: release pointers and revisions. */
|
|
29
42
|
const HOSTED_DELIVERY_ORIGIN = "https://delivery.decocms.com";
|
|
43
|
+
/** test-only: replaces the delivery origin in local end-to-end runs. Not documented, not exported. */
|
|
44
|
+
const TEST_DELIVERY_ORIGIN = Symbol.for("decocms.blocks.test.deliveryOrigin");
|
|
30
45
|
const INSTANCE_PREFIX = "decocms.blocks.remote:";
|
|
31
|
-
const MANIFEST_FORMAT = 1;
|
|
32
46
|
const FETCH_TIMEOUT_MS = 10_000;
|
|
33
47
|
/** The largest release accepted, in bytes of JSON. */
|
|
34
48
|
const MAX_SNAPSHOT_BYTES = 64 * 1024 * 1024;
|
|
49
|
+
// OPEN: a revision is the git commit SHA; only SHA-1 (40 hex) object names are accepted.
|
|
50
|
+
const REVISION = /^[0-9a-f]{40}$/;
|
|
51
|
+
const SCHEMA_HASH = /^[0-9a-f]{64}$/;
|
|
35
52
|
class RemoteLoader {
|
|
36
53
|
#site;
|
|
37
|
-
#token;
|
|
38
54
|
/** The `interval` this loader was created with; `createCMS` reads it. */
|
|
39
55
|
interval;
|
|
40
56
|
#fallback;
|
|
41
|
-
#fallbackRevision;
|
|
42
57
|
/** The fallback's content as last loaded, for a fallback that is itself a loader. */
|
|
43
58
|
#fallbackSnapshot;
|
|
59
|
+
/** The release this process last swapped in; `undefined` serves the fallback. */
|
|
44
60
|
#current;
|
|
45
|
-
#
|
|
61
|
+
#dev;
|
|
46
62
|
constructor(fallback, options) {
|
|
47
63
|
this.#fallback = fallback;
|
|
48
64
|
this.#site = options.site;
|
|
49
|
-
this.#token = options.token;
|
|
50
65
|
this.interval = options.interval;
|
|
66
|
+
this.#dev = options.dev === true;
|
|
51
67
|
}
|
|
52
68
|
/** A hot reload hands the same instance new fallback content. */
|
|
53
69
|
adopt(fallback) {
|
|
54
70
|
if (fallback === this.#fallback)
|
|
55
71
|
return;
|
|
56
72
|
this.#fallback = fallback;
|
|
57
|
-
this.#fallbackRevision = undefined;
|
|
58
73
|
this.#fallbackSnapshot = undefined;
|
|
59
74
|
}
|
|
60
75
|
/** What `load()` would return now, from memory only (see `peekRelease`). */
|
|
@@ -67,81 +82,72 @@ class RemoteLoader {
|
|
|
67
82
|
return this.#loadFallback();
|
|
68
83
|
}
|
|
69
84
|
async update() {
|
|
70
|
-
if (
|
|
85
|
+
if (this.#dev)
|
|
71
86
|
return { updated: false };
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
87
|
+
const fallback = this.#fallbackSnapshot ?? (await this.#loadFallback());
|
|
88
|
+
if (fallback.schemaHash === undefined)
|
|
74
89
|
return { updated: false };
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
let next;
|
|
87
|
-
if (fallbackRevision === undefined || manifest.revision !== fallbackRevision) {
|
|
88
|
-
next = await this.#release(manifest);
|
|
89
|
-
}
|
|
90
|
-
// A slower, earlier check must not undo a newer publish or rollback.
|
|
91
|
-
if (manifest.generation < this.#generation)
|
|
90
|
+
const site = encodeURIComponent(this.#site);
|
|
91
|
+
const latest = await this.#latest(site);
|
|
92
|
+
// Another schema: keep what this process serves (the fallback, or the last swap).
|
|
93
|
+
if (latest.schemaHash !== fallback.schemaHash)
|
|
94
|
+
return { updated: false };
|
|
95
|
+
// The bundle is newer: keep what this process serves.
|
|
96
|
+
// OPEN: a process that already swapped a release in keeps it (memory stays as it is).
|
|
97
|
+
if (!isNewer(latest.publishedAt, fallback.committedAt))
|
|
98
|
+
return { updated: false };
|
|
99
|
+
if (latest.revision === this.#current?.revision)
|
|
92
100
|
return { updated: false };
|
|
93
|
-
this.#
|
|
101
|
+
const blocks = await this.#revision(site, latest);
|
|
102
|
+
const next = { revision: latest.revision, blocks, schemaHash: latest.schemaHash };
|
|
103
|
+
if (fallback.aliases !== undefined)
|
|
104
|
+
next.aliases = fallback.aliases;
|
|
94
105
|
this.#current = next;
|
|
95
106
|
return { updated: true };
|
|
96
107
|
}
|
|
97
108
|
async #loadFallback() {
|
|
98
109
|
const fallback = this.#fallback;
|
|
99
110
|
const snapshot = isSnapshot(fallback) ? fallback : await fallback.load();
|
|
100
|
-
if (fallback === this.#fallback)
|
|
101
|
-
this.#fallbackRevision = snapshot.revision;
|
|
111
|
+
if (fallback === this.#fallback)
|
|
102
112
|
this.#fallbackSnapshot = snapshot;
|
|
103
|
-
}
|
|
104
113
|
return snapshot;
|
|
105
114
|
}
|
|
106
|
-
async #
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!response.ok)
|
|
113
|
-
throw new Error(`channel manifest: HTTP ${response.status}`);
|
|
115
|
+
async #latest(site) {
|
|
116
|
+
const response = await fetchWithTimeout(`${deliveryOrigin()}/sites/${site}/latest.json`);
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
await response.body?.cancel();
|
|
119
|
+
throw new Error(`latest.json: HTTP ${response.status}`);
|
|
120
|
+
}
|
|
114
121
|
const body = await response.json();
|
|
115
|
-
const prefix = `/sites/${site}/revisions/`;
|
|
116
122
|
if (!isPlainObject(body) ||
|
|
117
|
-
body.format !== MANIFEST_FORMAT ||
|
|
118
|
-
!Number.isSafeInteger(body.generation) ||
|
|
119
123
|
typeof body.revision !== "string" ||
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
body.
|
|
124
|
-
|
|
124
|
+
!REVISION.test(body.revision) ||
|
|
125
|
+
typeof body.schemaHash !== "string" ||
|
|
126
|
+
!SCHEMA_HASH.test(body.schemaHash) ||
|
|
127
|
+
typeof body.publishedAt !== "string" ||
|
|
128
|
+
Number.isNaN(Date.parse(body.publishedAt))) {
|
|
129
|
+
throw new Error("latest.json: unexpected format");
|
|
125
130
|
}
|
|
126
131
|
return body;
|
|
127
132
|
}
|
|
128
|
-
async #
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
snapshot.revision !== manifest.revision ||
|
|
135
|
-
(await computeContentRevision(snapshot.blocks)) !== manifest.revision) {
|
|
136
|
-
throw new Error(`release ${manifest.revision}: content doesn't match its revision`);
|
|
133
|
+
async #revision(site, latest) {
|
|
134
|
+
const label = `revision ${latest.revision}`;
|
|
135
|
+
const response = await fetchWithTimeout(`${deliveryOrigin()}/sites/${site}/revisions/${latest.revision}.json`);
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
await response.body?.cancel();
|
|
138
|
+
throw new Error(`${label}: HTTP ${response.status}`);
|
|
137
139
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
const body = await readBoundedJson(response, label, MAX_SNAPSHOT_BYTES);
|
|
141
|
+
if (!isPlainObject(body) ||
|
|
142
|
+
body.revision !== latest.revision ||
|
|
143
|
+
body.schemaHash !== latest.schemaHash ||
|
|
144
|
+
!isPlainObject(body.blocks)) {
|
|
145
|
+
throw new Error(`${label}: unexpected format, or not the revision latest.json names`);
|
|
146
|
+
}
|
|
147
|
+
return body.blocks;
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
|
-
/** A loader over the fallback alone: `remoteLoader` without `site
|
|
150
|
+
/** A loader over the fallback alone: `remoteLoader` without `site`. */
|
|
145
151
|
class LocalLoader {
|
|
146
152
|
#fallback;
|
|
147
153
|
constructor(fallback) {
|
|
@@ -159,15 +165,13 @@ class LocalLoader {
|
|
|
159
165
|
}
|
|
160
166
|
}
|
|
161
167
|
/**
|
|
162
|
-
* Hosted releases over a fallback. `createCMS` builds it for you
|
|
163
|
-
*
|
|
164
|
-
* environment without the variables), it's a loader over the fallback alone.
|
|
168
|
+
* Hosted releases over a fallback. `createCMS` builds it for you when `site`
|
|
169
|
+
* is set. Without `site`, it's a loader over the fallback alone.
|
|
165
170
|
*/
|
|
166
171
|
export function remoteLoader(fallback, options) {
|
|
167
|
-
const { site
|
|
168
|
-
const hosted = Boolean(site
|
|
169
|
-
const key = Symbol.for(`${INSTANCE_PREFIX}${contentIdentity(fallback)}`
|
|
170
|
-
(hosted ? `|site:${site}|token:${fnv1a(token)}` : "|local"));
|
|
172
|
+
const { site } = options ?? {};
|
|
173
|
+
const hosted = Boolean(site);
|
|
174
|
+
const key = Symbol.for(`${INSTANCE_PREFIX}${contentIdentity(fallback)}${hosted ? `|site:${site}` : "|local"}`);
|
|
171
175
|
const store = globalThis;
|
|
172
176
|
const existing = store[key];
|
|
173
177
|
if (existing instanceof Object && typeof existing.adopt === "function") {
|
|
@@ -179,7 +183,7 @@ export function remoteLoader(fallback, options) {
|
|
|
179
183
|
return existing;
|
|
180
184
|
}
|
|
181
185
|
const instance = hosted
|
|
182
|
-
? new RemoteLoader(fallback, { site: site,
|
|
186
|
+
? new RemoteLoader(fallback, { site: site, interval: options.interval, dev: options.dev })
|
|
183
187
|
: new LocalLoader(fallback);
|
|
184
188
|
store[key] = instance;
|
|
185
189
|
return instance;
|
|
@@ -187,16 +191,22 @@ export function remoteLoader(fallback, options) {
|
|
|
187
191
|
export function resetRemoteLoaders() {
|
|
188
192
|
clearGlobals(INSTANCE_PREFIX);
|
|
189
193
|
}
|
|
190
|
-
|
|
191
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Whether a release published at `publishedAt` is newer than content built
|
|
196
|
+
* from a commit made at `committedAt`. Content without a `committedAt` is the
|
|
197
|
+
* oldest.
|
|
198
|
+
* OPEN: a `committedAt` that doesn't parse as a date counts as missing.
|
|
199
|
+
*/
|
|
200
|
+
function isNewer(publishedAt, committedAt) {
|
|
201
|
+
const committed = committedAt === undefined ? Number.NaN : Date.parse(committedAt);
|
|
202
|
+
return Number.isNaN(committed) || Date.parse(publishedAt) > committed;
|
|
192
203
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
204
|
+
/** No credentials: delivery is public. */
|
|
205
|
+
function fetchWithTimeout(url) {
|
|
206
|
+
return fetch(url, { signal: timeoutSignal(FETCH_TIMEOUT_MS) });
|
|
207
|
+
}
|
|
208
|
+
function deliveryOrigin() {
|
|
209
|
+
const override = globalThis[TEST_DELIVERY_ORIGIN];
|
|
210
|
+
return typeof override === "string" ? override : HOSTED_DELIVERY_ORIGIN;
|
|
201
211
|
}
|
|
202
212
|
//# sourceMappingURL=remoteLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteLoader.js","sourceRoot":"","sources":["../../src/v8/remoteLoader.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remoteLoader.js","sourceRoot":"","sources":["../../src/v8/remoteLo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|
|
|
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
|
+
/** A leaf holds the entry and its parameter names, in path order; `splat` is a trailing `*`'s leaf. */
|
|
9
|
+
type Leaf<T> = {
|
|
10
|
+
value: T;
|
|
11
|
+
names: string[];
|
|
12
|
+
};
|
|
13
|
+
export type TrieNode<T> = {
|
|
14
|
+
literals: Map<string, TrieNode<T>>;
|
|
15
|
+
param?: TrieNode<T>;
|
|
16
|
+
leaf?: Leaf<T>;
|
|
17
|
+
splat?: Leaf<T>;
|
|
18
|
+
};
|
|
19
|
+
export type Hit<T> = {
|
|
20
|
+
value: T;
|
|
21
|
+
params: Record<string, string>;
|
|
22
|
+
rest: string[];
|
|
23
|
+
};
|
|
24
|
+
/** A trie holding `entries` (`[path, value]`); on a conflict the earlier keeps the leaf. */
|
|
25
|
+
export declare function buildTrie<T>(entries: Iterable<[string, T]>): TrieNode<T>;
|
|
26
|
+
/** Adds `path`; returns the value already holding its leaf (a conflict: the earlier keeps it). */
|
|
27
|
+
export declare function insert<T>(root: TrieNode<T>, path: string, value: T): T | undefined;
|
|
28
|
+
/** Walks the URL's segments: the literal child first, then the parameter child, then the splat. */
|
|
29
|
+
export declare function lookup<T>(node: TrieNode<T>, segs: string[], i?: number, vals?: string[]): Hit<T> | null;
|
|
30
|
+
/** `/a/b/`, `/a//b` and `/a/b?x` all name `["a", "b"]`; `/` names `[]`. */
|
|
31
|
+
export declare function splitPath(path: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* A path or URL split at its first `?` and `#`: everything before, the query
|
|
34
|
+
* (without its `?`, `""` when there's none) and the fragment (with its `#`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function splitRef(ref: string): {
|
|
37
|
+
path: string;
|
|
38
|
+
query: string;
|
|
39
|
+
hash: string;
|
|
40
|
+
};
|
|
41
|
+
export declare function safeDecode(segment: string): string;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=routeTrie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeTrie.d.ts","sourceRoot":"","sources":["../../src/v8/routeTrie.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uGAAuG;AACvG,KAAK,IAAI,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAC7C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACf,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAElF,4FAA4F;AAC5F,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAIxE;AAED,kGAAkG;AAClG,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAuBlF;AAED,mGAAmG;AACnG,wBAAgB,MAAM,CAAC,CAAC,EACtB,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,IAAI,EAAE,MAAM,EAAE,EACd,CAAC,SAAI,EACL,IAAI,GAAE,MAAM,EAAO,GAClB,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAUf;AAQD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAIhD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAQnF;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMlD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
/** A trie holding `entries` (`[path, value]`); on a conflict the earlier keeps the leaf. */
|
|
9
|
+
export function buildTrie(entries) {
|
|
10
|
+
const root = { literals: new Map() };
|
|
11
|
+
for (const [path, value] of entries)
|
|
12
|
+
insert(root, path, value);
|
|
13
|
+
return root;
|
|
14
|
+
}
|
|
15
|
+
/** Adds `path`; returns the value already holding its leaf (a conflict: the earlier keeps it). */
|
|
16
|
+
export function insert(root, path, value) {
|
|
17
|
+
const names = [];
|
|
18
|
+
const segments = splitPath(path);
|
|
19
|
+
let node = root;
|
|
20
|
+
for (const [i, segment] of segments.entries()) {
|
|
21
|
+
if (segment === "*" && i === segments.length - 1) {
|
|
22
|
+
if (node.splat)
|
|
23
|
+
return node.splat.value;
|
|
24
|
+
node.splat = { value, names };
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (segment.startsWith(":") && segment.length > 1) {
|
|
28
|
+
names.push(segment.slice(1));
|
|
29
|
+
node = node.param ??= { literals: new Map() };
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const literal = safeDecode(segment);
|
|
33
|
+
const child = node.literals.get(literal) ?? { literals: new Map() };
|
|
34
|
+
node.literals.set(literal, child);
|
|
35
|
+
node = child;
|
|
36
|
+
}
|
|
37
|
+
if (node.leaf)
|
|
38
|
+
return node.leaf.value;
|
|
39
|
+
node.leaf = { value, names };
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Walks the URL's segments: the literal child first, then the parameter child, then the splat. */
|
|
43
|
+
export function lookup(node, segs, i = 0, vals = []) {
|
|
44
|
+
if (i === segs.length)
|
|
45
|
+
return node.leaf ? hit(node.leaf, vals, []) : null;
|
|
46
|
+
const literal = node.literals.get(segs[i]);
|
|
47
|
+
let found = literal ? lookup(literal, segs, i + 1, vals) : null;
|
|
48
|
+
// A parameter is one segment and never contains a slash, even an encoded one.
|
|
49
|
+
if (!found && node.param && !segs[i].includes("/")) {
|
|
50
|
+
found = lookup(node.param, segs, i + 1, [...vals, segs[i]]);
|
|
51
|
+
}
|
|
52
|
+
// A splat takes the rest (at least one segment, as there is one here).
|
|
53
|
+
return found ?? (node.splat ? hit(node.splat, vals, segs.slice(i)) : null);
|
|
54
|
+
}
|
|
55
|
+
function hit({ value, names }, values, rest) {
|
|
56
|
+
const params = Object.fromEntries(names.map((n, i) => [n, values[i]]));
|
|
57
|
+
if (rest.length > 0)
|
|
58
|
+
params["*"] = rest.join("/");
|
|
59
|
+
return { value, params, rest };
|
|
60
|
+
}
|
|
61
|
+
/** `/a/b/`, `/a//b` and `/a/b?x` all name `["a", "b"]`; `/` names `[]`. */
|
|
62
|
+
export function splitPath(path) {
|
|
63
|
+
return splitRef(path)
|
|
64
|
+
.path.split("/")
|
|
65
|
+
.filter((segment) => segment.length > 0);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A path or URL split at its first `?` and `#`: everything before, the query
|
|
69
|
+
* (without its `?`, `""` when there's none) and the fragment (with its `#`).
|
|
70
|
+
*/
|
|
71
|
+
export function splitRef(ref) {
|
|
72
|
+
const hashAt = ref.indexOf("#") === -1 ? ref.length : ref.indexOf("#");
|
|
73
|
+
const queryAt = ref.indexOf("?") === -1 || ref.indexOf("?") > hashAt ? hashAt : ref.indexOf("?");
|
|
74
|
+
return {
|
|
75
|
+
path: ref.slice(0, queryAt),
|
|
76
|
+
query: ref.slice(queryAt + 1, hashAt),
|
|
77
|
+
hash: ref.slice(hashAt),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function safeDecode(segment) {
|
|
81
|
+
try {
|
|
82
|
+
return decodeURIComponent(segment);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return segment;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=routeTrie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeTrie.js","sourceRoot":"","sources":["../../src/v8/routeTrie.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,4FAA4F;AAC5F,MAAM,UAAU,SAAS,CAAI,OAA8B;IACzD,MAAM,IAAI,GAAgB,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO;QAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,MAAM,CAAI,IAAiB,EAAE,IAAY,EAAE,KAAQ;IACjE,MAAM,KAAK,GAAa,EAAE,C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;IACxC,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
|
package/dist/v8/telemetry.d.ts
CHANGED
|
@@ -5,14 +5,13 @@ export declare function telemetryLimits(config: false | TelemetryConfig | undefi
|
|
|
5
5
|
traceSampleRate: number;
|
|
6
6
|
};
|
|
7
7
|
type Attributes = Record<string, string | number | boolean | undefined>;
|
|
8
|
-
type Signal = "metrics" | "logs" | "traces";
|
|
9
8
|
interface Destination {
|
|
10
|
-
/** The base URL each signal's `/v1/<signal>` is appended to
|
|
9
|
+
/** The base URL each signal's `/v1/<signal>` is appended to. */
|
|
11
10
|
endpoint: string;
|
|
12
|
-
/** Full per-signal URLs, used as they are (the `OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT` form). */
|
|
13
|
-
signals?: Partial<Record<Signal, string>>;
|
|
14
11
|
headers: Record<string, string>;
|
|
15
12
|
site?: string;
|
|
13
|
+
/** `telemetry.resource`: merged over the default resource attributes. */
|
|
14
|
+
resource: Record<string, string>;
|
|
16
15
|
limits: {
|
|
17
16
|
errorSampleRate: number;
|
|
18
17
|
traceSampleRate: number;
|
|
@@ -35,10 +34,11 @@ export interface ClientTelemetry {
|
|
|
35
34
|
error(error: CMSError): void;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
|
-
* Where telemetry goes, or `null` for nowhere
|
|
39
|
-
* `
|
|
37
|
+
* Where telemetry goes, or `null` for nowhere: `false` is off; a non-empty
|
|
38
|
+
* `endpoint` is that collector, with `headers`; otherwise a `token` is the
|
|
39
|
+
* hosted Deco CMS collector, with the token as a Bearer credential.
|
|
40
40
|
*/
|
|
41
|
-
export declare function resolveDestination(config: false | TelemetryConfig | undefined, site?: string): Destination | null;
|
|
41
|
+
export declare function resolveDestination(config: false | TelemetryConfig | undefined, site?: string, token?: string): Destination | null;
|
|
42
42
|
export declare class TelemetryPipeline {
|
|
43
43
|
#private;
|
|
44
44
|
constructor(destination: Destination);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/v8/telemetry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/v8/telemetry.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAejF,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,GAAG,eAAe,GAAG,SAAS,GAAG;IAC5E,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAMA;AAED,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;AAIxE,UAAU,WAAW;IACnB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9D;AAED,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,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