inlaycms 0.5.0 → 0.7.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/assets/admin/admin.css +1 -1
- package/assets/admin/admin.js +1 -1
- package/dist/adapters/admin/publish.js +2 -2
- package/dist/adapters/admin/screens/editor.js +4 -2
- package/dist/adapters/admin/screens/media.d.ts +4 -1
- package/dist/adapters/admin/screens/media.js +22 -2
- package/dist/adapters/admin/screens/redirects.js +3 -1
- package/dist/adapters/admin/screens/releases.js +8 -3
- package/dist/adapters/admin/views/data-table.js +1 -1
- package/dist/adapters/admin/views/layout.d.ts +1 -1
- package/dist/adapters/admin/views/layout.js +12 -2
- package/dist/adapters/cli/main.js +21 -3
- package/dist/adapters/mcp/agent-refs.d.ts +2 -1
- package/dist/adapters/mcp/agent-refs.js +4 -4
- package/dist/adapters/mcp/tools/publish.js +1 -1
- package/dist/adapters/mcp/tools/read.d.ts +1 -1
- package/dist/adapters/mcp/tools/read.js +46 -3
- package/dist/adapters/mcp/tools/write.js +77 -6
- package/dist/adapters/site/context.d.ts +4 -1
- package/dist/adapters/site/context.js +9 -7
- package/dist/adapters/site/head.d.ts +2 -0
- package/dist/adapters/site/head.js +6 -6
- package/dist/adapters/site/plugin.d.ts +2 -0
- package/dist/adapters/site/plugin.js +25 -8
- package/dist/adapters/site/preview.d.ts +2 -0
- package/dist/adapters/site/preview.js +10 -5
- package/dist/adapters/site/public.d.ts +9 -1
- package/dist/adapters/site/public.js +48 -30
- package/dist/adapters/site/render.js +7 -2
- package/dist/adapters/site/routes.js +4 -3
- package/dist/adapters/site/sitemap.d.ts +2 -1
- package/dist/adapters/site/sitemap.js +3 -3
- package/dist/core/content/find-text.d.ts +31 -0
- package/dist/core/content/find-text.js +124 -0
- package/dist/core/content/search.js +1 -14
- package/dist/core/content/text-match.d.ts +14 -0
- package/dist/core/content/text-match.js +99 -0
- package/dist/core/content/text-replace.d.ts +14 -0
- package/dist/core/content/text-replace.js +100 -0
- package/dist/core/core.d.ts +7 -0
- package/dist/core/core.js +2 -0
- package/dist/core/messages/en.d.ts +43 -4
- package/dist/core/messages/en.js +43 -4
- package/dist/core/registry/define.d.ts +5 -0
- package/dist/core/registry/define.js +1 -0
- package/dist/core/registry/render.d.ts +6 -1
- package/dist/core/release/manifest.d.ts +0 -5
- package/dist/core/release/manifest.js +0 -24
- package/dist/core/release/pack.js +4 -0
- package/dist/core/release/public-files.d.ts +14 -0
- package/dist/core/release/public-files.js +43 -0
- package/dist/core/release/read.d.ts +2 -2
- package/dist/core/release/read.js +11 -12
- package/dist/core/release/window.d.ts +13 -0
- package/dist/core/release/window.js +40 -0
- package/dist/core/report.d.ts +1 -1
- package/dist/core/richtext/runs.d.ts +12 -0
- package/dist/core/richtext/runs.js +31 -0
- package/dist/core/site/paths.d.ts +5 -0
- package/dist/core/site/paths.js +32 -0
- package/dist/core/site/resolve.js +17 -6
- package/dist/core/version.d.ts +6 -0
- package/dist/core/version.js +6 -0
- package/dist/host/activate.js +2 -1
- package/dist/host/app.d.ts +6 -0
- package/dist/host/app.js +3 -0
- package/dist/host/push.d.ts +5 -1
- package/dist/host/push.js +17 -5
- package/dist/host/worker.js +9 -3
- package/dist/site.d.ts +1 -1
- package/package.json +1 -1
|
@@ -40,7 +40,7 @@ export interface Entry<F = Record<string, unknown>> {
|
|
|
40
40
|
/** The locale whose content is shown. */
|
|
41
41
|
locale: string;
|
|
42
42
|
fallback: boolean;
|
|
43
|
-
/** The encoded site
|
|
43
|
+
/** The encoded page URL, with the trailing slash when the site asks for it, or `null` for data entries. */
|
|
44
44
|
url: string | null;
|
|
45
45
|
title: string;
|
|
46
46
|
slug: string | null;
|
|
@@ -75,6 +75,8 @@ export interface PageInfo {
|
|
|
75
75
|
fallback: boolean;
|
|
76
76
|
/** The decoded site path; `''` for a page without one. */
|
|
77
77
|
path: string;
|
|
78
|
+
/** The encoded page URL, with the trailing slash when the site asks for it; `''` for a page without one. */
|
|
79
|
+
url: string;
|
|
78
80
|
/** When Inlay first published the page's document; `null` for a route or a never-published draft. */
|
|
79
81
|
publishedAt: string | null;
|
|
80
82
|
page: number;
|
|
@@ -129,7 +131,10 @@ export interface RenderContext {
|
|
|
129
131
|
script: ScriptApi;
|
|
130
132
|
alternates: Array<{
|
|
131
133
|
locale: string;
|
|
134
|
+
/** The decoded site path. */
|
|
132
135
|
path: string;
|
|
136
|
+
/** The encoded page URL, with the trailing slash when the site asks for it. */
|
|
137
|
+
url: string;
|
|
133
138
|
fallback: boolean;
|
|
134
139
|
}>;
|
|
135
140
|
/**
|
|
@@ -122,11 +122,6 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
122
122
|
slots: z.ZodArray<z.ZodString>;
|
|
123
123
|
}, z.core.$strict>>;
|
|
124
124
|
}, z.core.$strict>;
|
|
125
|
-
/**
|
|
126
|
-
* Whether `version` falls in `range`, which is `^MAJOR.MINOR.PATCH`: for major 0, the same minor and a patch at
|
|
127
|
-
* least as high; otherwise the same major and a minor and patch at least as high.
|
|
128
|
-
*/
|
|
129
|
-
export declare function satisfies(version: string, range: string): boolean;
|
|
130
125
|
export declare function sha256Hex(bytes: Uint8Array): string;
|
|
131
126
|
/** Where a release keeps a shipped file: named by its sha256, keeping its extension. */
|
|
132
127
|
export declare function contentPath(file: string, bytes: Uint8Array): string;
|
|
@@ -43,30 +43,6 @@ export const manifestSchema = z.strictObject({
|
|
|
43
43
|
locales: z.array(z.string()),
|
|
44
44
|
types: z.record(z.string(), z.strictObject({ kind: z.enum(['singleton', 'collection', 'global']), slots: z.array(z.string()) })),
|
|
45
45
|
});
|
|
46
|
-
const VERSION = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/;
|
|
47
|
-
function parts(version) {
|
|
48
|
-
const m = VERSION.exec(version);
|
|
49
|
-
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Whether `version` falls in `range`, which is `^MAJOR.MINOR.PATCH`: for major 0, the same minor and a patch at
|
|
53
|
-
* least as high; otherwise the same major and a minor and patch at least as high.
|
|
54
|
-
*/
|
|
55
|
-
export function satisfies(version, range) {
|
|
56
|
-
if (!range.startsWith('^'))
|
|
57
|
-
return false;
|
|
58
|
-
const want = parts(range.slice(1));
|
|
59
|
-
const have = parts(version);
|
|
60
|
-
if (!want || !have)
|
|
61
|
-
return false;
|
|
62
|
-
const [major, minor, patch] = want;
|
|
63
|
-
const [hMajor, hMinor, hPatch] = have;
|
|
64
|
-
if (hMajor !== major)
|
|
65
|
-
return false;
|
|
66
|
-
if (major === 0)
|
|
67
|
-
return hMinor === minor && hPatch >= patch;
|
|
68
|
-
return hMinor > minor || (hMinor === minor && hPatch >= patch);
|
|
69
|
-
}
|
|
70
46
|
export function sha256Hex(bytes) {
|
|
71
47
|
return createHash('sha256').update(bytes).digest('hex');
|
|
72
48
|
}
|
|
@@ -12,6 +12,7 @@ import { realInsideSync } from '../content/shipped-images.js';
|
|
|
12
12
|
import { InlayError } from '../errors.js';
|
|
13
13
|
import { buildRegistry } from '../registry/registry.js';
|
|
14
14
|
import { bundleSite } from './bundle.js';
|
|
15
|
+
import { publicClashes, publicClashError } from './public-files.js';
|
|
15
16
|
import { sign } from './keys.js';
|
|
16
17
|
import { contentPath, manifestOfRegistry, sha256Hex } from './manifest.js';
|
|
17
18
|
/** Every regular file under `dir`, as `/`-separated paths relative to it. Dotfiles and symlinks are left out. */
|
|
@@ -82,6 +83,9 @@ export async function packRelease(opts) {
|
|
|
82
83
|
}
|
|
83
84
|
const publicDir = join(dir, 'public');
|
|
84
85
|
if (existsSync(publicDir)) {
|
|
86
|
+
const [clash] = await publicClashes(publicDir, registry);
|
|
87
|
+
if (clash)
|
|
88
|
+
throw publicClashError(clash);
|
|
85
89
|
for (const path of await listFiles(publicDir, true)) {
|
|
86
90
|
await mkdir(dirname(join(tmp, 'public', path)), { recursive: true });
|
|
87
91
|
await copyFile(join(publicDir, path), join(tmp, 'public', path));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Registry } from '../registry/registry.js';
|
|
2
|
+
import { InlayError } from '../errors.js';
|
|
3
|
+
/** A `public/` file whose root address is taken. `file` is relative to `public/`; `path` is `'/' + file`. */
|
|
4
|
+
export interface PublicClash {
|
|
5
|
+
file: string;
|
|
6
|
+
path: string;
|
|
7
|
+
kind: 'reserved' | 'route' | 'redirect' | 'page';
|
|
8
|
+
}
|
|
9
|
+
/** The `public/` files that would be served at a root address Inlay or the site already uses. */
|
|
10
|
+
export declare function publicClashes(publicDir: string, registry: Pick<Registry, 'getRoutePaths' | 'redirects' | 'locales' | 'defaultLocale'> & {
|
|
11
|
+
site: Pick<Registry['site'], 'singletons'>;
|
|
12
|
+
}): Promise<PublicClash[]>;
|
|
13
|
+
export declare function publicClashMessage(clash: PublicClash): string;
|
|
14
|
+
export declare function publicClashError(clash: PublicClash): InlayError;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { InlayError } from '../errors.js';
|
|
2
|
+
import { t } from '../messages/index.js';
|
|
3
|
+
import { isReserved, singletonPath } from '../site/paths.js';
|
|
4
|
+
import { listFiles } from './pack.js';
|
|
5
|
+
const MESSAGES = {
|
|
6
|
+
reserved: 'error.publicReserved',
|
|
7
|
+
route: 'error.publicRoute',
|
|
8
|
+
redirect: 'error.publicRedirect',
|
|
9
|
+
page: 'error.publicPage',
|
|
10
|
+
};
|
|
11
|
+
/** The `public/` files that would be served at a root address Inlay or the site already uses. */
|
|
12
|
+
export async function publicClashes(publicDir, registry) {
|
|
13
|
+
const pages = new Set();
|
|
14
|
+
for (const def of registry.site.singletons) {
|
|
15
|
+
for (const locale of registry.locales) {
|
|
16
|
+
const p = singletonPath(def, locale, registry.defaultLocale);
|
|
17
|
+
if (p !== null)
|
|
18
|
+
pages.add(p);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const redirects = new Set(registry.redirects.map((r) => r.from));
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const file of await listFiles(publicDir, true)) {
|
|
24
|
+
if (!(file.split('/').at(-1) ?? '').includes('.'))
|
|
25
|
+
continue;
|
|
26
|
+
const path = `/${file}`;
|
|
27
|
+
if (isReserved(path))
|
|
28
|
+
out.push({ file, path, kind: 'reserved' });
|
|
29
|
+
else if (registry.getRoutePaths.has(path))
|
|
30
|
+
out.push({ file, path, kind: 'route' });
|
|
31
|
+
else if (redirects.has(path))
|
|
32
|
+
out.push({ file, path, kind: 'redirect' });
|
|
33
|
+
else if (pages.has(path))
|
|
34
|
+
out.push({ file, path, kind: 'page' });
|
|
35
|
+
}
|
|
36
|
+
return out.sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
|
|
37
|
+
}
|
|
38
|
+
export function publicClashMessage(clash) {
|
|
39
|
+
return t(MESSAGES[clash.kind], { file: clash.file, path: clash.path });
|
|
40
|
+
}
|
|
41
|
+
export function publicClashError(clash) {
|
|
42
|
+
return new InlayError('release', MESSAGES[clash.kind], { file: clash.file, path: clash.path });
|
|
43
|
+
}
|
|
@@ -15,8 +15,8 @@ export interface LoadedRelease {
|
|
|
15
15
|
* package (from `src/` the package's own `exports` name `dist/`): field definitions are checked by identity.
|
|
16
16
|
*/
|
|
17
17
|
export declare const INLAY_ENTRIES: Readonly<Record<string, string>>;
|
|
18
|
-
/** Throws `error.
|
|
19
|
-
export declare function checkInlayVersion(
|
|
18
|
+
/** Throws `error.releaseTooOld` or `error.releaseTooNew` when a release packed with Inlay `packed` doesn't run on Inlay `version` (default: the running one). */
|
|
19
|
+
export declare function checkInlayVersion(packed: string, version?: string): void;
|
|
20
20
|
/**
|
|
21
21
|
* Opens the release file at `file` into the empty folder `opts.dir` without running any of it. The signature is
|
|
22
22
|
* checked against `opts.trustedKeys` before anything but the manifest is read, the Inlay version range next, and
|
|
@@ -9,8 +9,9 @@ import { InlayError } from '../errors.js';
|
|
|
9
9
|
import { buildRegistry } from '../registry/registry.js';
|
|
10
10
|
import { inlayVersion as currentVersion } from '../version.js';
|
|
11
11
|
import { fingerprint, verify } from './keys.js';
|
|
12
|
-
import { manifestSchema,
|
|
12
|
+
import { manifestSchema, sha256Hex } from './manifest.js';
|
|
13
13
|
import { SITE_DIR_EXPORT } from './site-dir.js';
|
|
14
|
+
import { releaseFit, runningWindow } from './window.js';
|
|
14
15
|
const SIGNED = new Set(['manifest.json', 'manifest.sig']);
|
|
15
16
|
/** `.ts` when running from `src/` (tsx, vitest), `.js` from `dist/`. */
|
|
16
17
|
const EXT = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
|
|
@@ -84,16 +85,14 @@ function invalid() {
|
|
|
84
85
|
function releasePath(path) {
|
|
85
86
|
return path === 'site.js' || path.startsWith('content/') || path.startsWith('public/');
|
|
86
87
|
}
|
|
87
|
-
/** `
|
|
88
|
-
function
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!satisfies(version, range))
|
|
96
|
-
throw new InlayError('release', 'error.releaseVersion', { range, version, ...series(range) });
|
|
88
|
+
/** Throws `error.releaseTooOld` or `error.releaseTooNew` when a release packed with Inlay `packed` doesn't run on Inlay `version` (default: the running one). */
|
|
89
|
+
export function checkInlayVersion(packed, version = currentVersion()) {
|
|
90
|
+
const window = { ...runningWindow(), version };
|
|
91
|
+
const fit = releaseFit(packed, window);
|
|
92
|
+
if (fit === 'tooOld')
|
|
93
|
+
throw new InlayError('release', 'error.releaseTooOld', { packed, version, oldest: window.oldest });
|
|
94
|
+
if (fit === 'tooNew')
|
|
95
|
+
throw new InlayError('release', 'error.releaseTooNew', { packed, version });
|
|
97
96
|
}
|
|
98
97
|
/** The manifest and signature are small; anything bigger is refused before the signature is checked. */
|
|
99
98
|
const SIGNED_MAX_BYTES = 1024 ** 2;
|
|
@@ -183,7 +182,7 @@ async function checkRelease(file, dir, opts) {
|
|
|
183
182
|
catch {
|
|
184
183
|
throw invalid();
|
|
185
184
|
}
|
|
186
|
-
checkInlayVersion(manifest.inlay.
|
|
185
|
+
checkInlayVersion(manifest.inlay.version, opts.inlayVersion);
|
|
187
186
|
const listed = Object.keys(manifest.files);
|
|
188
187
|
if (!Object.hasOwn(manifest.files, 'site.js') || !listed.every(releasePath))
|
|
189
188
|
throw invalid();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ReleaseWindow {
|
|
2
|
+
version: string;
|
|
3
|
+
oldest: string;
|
|
4
|
+
nextOldest: string | null;
|
|
5
|
+
}
|
|
6
|
+
export type ReleaseFit = 'ok' | 'warn' | 'tooOld' | 'tooNew';
|
|
7
|
+
export declare function runningWindow(): ReleaseWindow;
|
|
8
|
+
/** Whether a release packed with `packed` runs in `window`: packed with the oldest version or later, and not a newer minor than the host. */
|
|
9
|
+
export declare function releaseFit(packed: string, window?: ReleaseWindow): ReleaseFit;
|
|
10
|
+
/** Whether `version` is `min` or later, ignoring a prerelease suffix. False when `version` doesn't parse. */
|
|
11
|
+
export declare function atLeastVersion(version: string, min: string): boolean;
|
|
12
|
+
/** A stored release's `inlay_range` without its leading caret. */
|
|
13
|
+
export declare function packedVersion(range: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { inlayVersion, NEXT_OLDEST_RELEASE, OLDEST_RELEASE } from '../version.js';
|
|
2
|
+
const VERSION = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/;
|
|
3
|
+
function parts(version) {
|
|
4
|
+
const m = VERSION.exec(version);
|
|
5
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
6
|
+
}
|
|
7
|
+
function compare(a, b) {
|
|
8
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
9
|
+
}
|
|
10
|
+
export function runningWindow() {
|
|
11
|
+
return { version: inlayVersion(), oldest: OLDEST_RELEASE, nextOldest: NEXT_OLDEST_RELEASE };
|
|
12
|
+
}
|
|
13
|
+
/** Whether a release packed with `packed` runs in `window`: packed with the oldest version or later, and not a newer minor than the host. */
|
|
14
|
+
export function releaseFit(packed, window = runningWindow()) {
|
|
15
|
+
const have = parts(packed);
|
|
16
|
+
if (!have)
|
|
17
|
+
return 'tooOld';
|
|
18
|
+
const host = parts(window.version);
|
|
19
|
+
const oldest = parts(window.oldest);
|
|
20
|
+
if (!host || !oldest)
|
|
21
|
+
return 'tooOld';
|
|
22
|
+
if (have[0] > host[0] || (have[0] === host[0] && have[1] > host[1]))
|
|
23
|
+
return 'tooNew';
|
|
24
|
+
if (compare(have, oldest) < 0)
|
|
25
|
+
return 'tooOld';
|
|
26
|
+
const next = window.nextOldest === null ? null : parts(window.nextOldest);
|
|
27
|
+
if (next && compare(have, next) < 0)
|
|
28
|
+
return 'warn';
|
|
29
|
+
return 'ok';
|
|
30
|
+
}
|
|
31
|
+
/** Whether `version` is `min` or later, ignoring a prerelease suffix. False when `version` doesn't parse. */
|
|
32
|
+
export function atLeastVersion(version, min) {
|
|
33
|
+
const have = parts(version);
|
|
34
|
+
const want = parts(min);
|
|
35
|
+
return have !== null && want !== null && compare(have, want) >= 0;
|
|
36
|
+
}
|
|
37
|
+
/** A stored release's `inlay_range` without its leading caret. */
|
|
38
|
+
export function packedVersion(range) {
|
|
39
|
+
return range.startsWith('^') ? range.slice(1) : range;
|
|
40
|
+
}
|
package/dist/core/report.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ShippedReport } from './content/shipped.js';
|
|
2
2
|
import type { ContentIssue } from './types.js';
|
|
3
|
-
export type ProblemCode = 'shipped_content' | 'release_import' | 'release_forbidden';
|
|
3
|
+
export type ProblemCode = 'shipped_content' | 'release_import' | 'release_forbidden' | 'public_clash';
|
|
4
4
|
/** One thing that stops the database from being brought up to date. `message` is written for the developer. */
|
|
5
5
|
export interface CheckProblem {
|
|
6
6
|
code: ProblemCode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RichTextDoc, RichTextText } from './schema.js';
|
|
2
|
+
export interface TextPiece {
|
|
3
|
+
node: RichTextText;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
7
|
+
export interface TextRun {
|
|
8
|
+
text: string;
|
|
9
|
+
pieces: TextPiece[];
|
|
10
|
+
}
|
|
11
|
+
/** The text of a document in runs: one per block, split again at each hard break and image. Runs with no text are left out. */
|
|
12
|
+
export declare function textRuns(doc: RichTextDoc): TextRun[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The text of a document in runs: one per block, split again at each hard break and image. Runs with no text are left out. */
|
|
2
|
+
export function textRuns(doc) {
|
|
3
|
+
const runs = [];
|
|
4
|
+
let current = { text: '', pieces: [] };
|
|
5
|
+
const flush = () => {
|
|
6
|
+
if (current.pieces.length > 0)
|
|
7
|
+
runs.push(current);
|
|
8
|
+
current = { text: '', pieces: [] };
|
|
9
|
+
};
|
|
10
|
+
const walk = (node) => {
|
|
11
|
+
if (node.type === 'text') {
|
|
12
|
+
if (node.text === '')
|
|
13
|
+
return;
|
|
14
|
+
current.pieces.push({ node, start: current.text.length, end: current.text.length + node.text.length });
|
|
15
|
+
current.text += node.text;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (node.type === 'hardBreak' || node.type === 'image') {
|
|
19
|
+
flush();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
flush();
|
|
23
|
+
for (const child of (node.content ?? []))
|
|
24
|
+
walk(child);
|
|
25
|
+
flush();
|
|
26
|
+
};
|
|
27
|
+
for (const node of doc.content)
|
|
28
|
+
walk(node);
|
|
29
|
+
flush();
|
|
30
|
+
return runs;
|
|
31
|
+
}
|
|
@@ -19,3 +19,8 @@ export declare function withLocale(registry: Registry, locale: string, path: str
|
|
|
19
19
|
export declare function singletonPath(def: SingletonDef, locale: string, defaultLocale: string): string | null;
|
|
20
20
|
export declare function routeRegExp(route: string): RegExp;
|
|
21
21
|
export declare function routePath(route: string, slug: string): string;
|
|
22
|
+
export type TrailingSlash = 'always' | 'never';
|
|
23
|
+
/** A decoded, normalized path (optionally with a `?query`) in the form the site presents. */
|
|
24
|
+
export declare function presentPath(path: string, mode: TrailingSlash): string;
|
|
25
|
+
/** The same for an encoded site-relative href; other hrefs come back unchanged. */
|
|
26
|
+
export declare function presentHref(href: string, mode: TrailingSlash): string;
|
package/dist/core/site/paths.js
CHANGED
|
@@ -75,3 +75,35 @@ export function routeRegExp(route) {
|
|
|
75
75
|
export function routePath(route, slug) {
|
|
76
76
|
return route.replace(':slug', slug);
|
|
77
77
|
}
|
|
78
|
+
function slashable(path) {
|
|
79
|
+
if (path === '/' || path.endsWith('/') || isReserved(path))
|
|
80
|
+
return false;
|
|
81
|
+
return !(path.split('/').at(-1) ?? '').includes('.');
|
|
82
|
+
}
|
|
83
|
+
/** A decoded, normalized path (optionally with a `?query`) in the form the site presents. */
|
|
84
|
+
export function presentPath(path, mode) {
|
|
85
|
+
if (mode !== 'always')
|
|
86
|
+
return path;
|
|
87
|
+
const q = path.indexOf('?');
|
|
88
|
+
const bare = q === -1 ? path : path.slice(0, q);
|
|
89
|
+
if (!slashable(bare))
|
|
90
|
+
return path;
|
|
91
|
+
return `${bare}/${q === -1 ? '' : path.slice(q)}`;
|
|
92
|
+
}
|
|
93
|
+
/** The same for an encoded site-relative href; other hrefs come back unchanged. */
|
|
94
|
+
export function presentHref(href, mode) {
|
|
95
|
+
if (mode !== 'always' || !href.startsWith('/') || href.startsWith('//'))
|
|
96
|
+
return href;
|
|
97
|
+
const q = href.indexOf('?');
|
|
98
|
+
const bare = q === -1 ? href : href.slice(0, q);
|
|
99
|
+
let decoded;
|
|
100
|
+
try {
|
|
101
|
+
decoded = decodeURIComponent(bare);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return href;
|
|
105
|
+
}
|
|
106
|
+
if (!slashable(decoded))
|
|
107
|
+
return href;
|
|
108
|
+
return `${bare}/${q === -1 ? '' : href.slice(q)}`;
|
|
109
|
+
}
|
|
@@ -158,14 +158,14 @@ function lookupLocales(deps, locale) {
|
|
|
158
158
|
export async function resolvePath(deps, rawPath, opts = {}) {
|
|
159
159
|
const res = await resolveSite(deps, rawPath, opts);
|
|
160
160
|
if (res.kind === 'canonical') {
|
|
161
|
-
// A mixed-case path that would 404 once canonical goes where the lowercase fallback lands, in one 301.
|
|
162
161
|
const { canonical } = res;
|
|
162
|
+
const at = await atCanonical(deps, canonical, opts);
|
|
163
|
+
if (at?.kind === 'redirect')
|
|
164
|
+
return at;
|
|
165
|
+
// A mixed-case path that would 404 once canonical goes where the lowercase fallback lands, in one 301.
|
|
163
166
|
const lower = lowercaseFallback(canonical);
|
|
164
|
-
if (lower !== null &&
|
|
165
|
-
!deps.registry.getRoutePaths.has(canonical) &&
|
|
166
|
-
(await resolveRules(deps, encodePath(canonical), opts)).kind === 'not_found') {
|
|
167
|
+
if (lower !== null && at?.kind === 'not_found')
|
|
167
168
|
return (await landing(deps, lower, opts)) ?? redirect(canonical);
|
|
168
|
-
}
|
|
169
169
|
return redirect(canonical);
|
|
170
170
|
}
|
|
171
171
|
if (res.kind !== 'rules')
|
|
@@ -191,6 +191,13 @@ async function resolveRules(deps, rawPath, opts) {
|
|
|
191
191
|
return res;
|
|
192
192
|
return (await matchRedirect(deps, res, opts)) ?? notFound(res.locale);
|
|
193
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* What steps 1–7b answer at the target of a step 2–3 redirect, so a rule there is reached in the
|
|
196
|
+
* same 301; `null` at a GET code route, which no rule can shadow.
|
|
197
|
+
*/
|
|
198
|
+
async function atCanonical(deps, canonical, opts) {
|
|
199
|
+
return deps.registry.getRoutePaths.has(canonical) ? null : resolveRules(deps, encodePath(canonical), opts);
|
|
200
|
+
}
|
|
194
201
|
/**
|
|
195
202
|
* Where the lowercase fallback for a request lands, given its lowercase form `lower`: a GET code
|
|
196
203
|
* route or a page there, a redirect that steps 2–6 or a rule would give, or `null` when nothing
|
|
@@ -202,8 +209,12 @@ async function landing(deps, lower, opts) {
|
|
|
202
209
|
const res = await resolveSite(deps, encodePath(lower), opts);
|
|
203
210
|
if (res.kind === 'page')
|
|
204
211
|
return redirect(lower);
|
|
205
|
-
if (res.kind === 'canonical')
|
|
212
|
+
if (res.kind === 'canonical') {
|
|
213
|
+
const at = await atCanonical(deps, res.canonical, opts);
|
|
214
|
+
if (at?.kind === 'redirect')
|
|
215
|
+
return at;
|
|
206
216
|
return (await answers(deps, res.canonical, opts)) ? redirect(res.canonical) : null;
|
|
217
|
+
}
|
|
207
218
|
if (res.kind === 'redirect')
|
|
208
219
|
return res;
|
|
209
220
|
if (res.kind !== 'rules')
|
package/dist/core/version.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function inlayVersion(): string;
|
|
2
|
+
/** The oldest Inlay version whose releases this one still runs. See the upgrades spec and CLAUDE.md. */
|
|
3
|
+
export declare const OLDEST_RELEASE = "0.5.0";
|
|
4
|
+
/** The oldest version the next window will keep, when already decided: older releases get a "pack again" warning. */
|
|
5
|
+
export declare const NEXT_OLDEST_RELEASE: string | null;
|
|
6
|
+
/** The first Inlay version whose releases serve their `public/` files at the site root too. */
|
|
7
|
+
export declare const ROOT_PUBLIC_FILES_SINCE = "0.7.0";
|
package/dist/core/version.js
CHANGED
|
@@ -3,3 +3,9 @@ export function inlayVersion() {
|
|
|
3
3
|
const url = new URL('../../package.json', import.meta.url);
|
|
4
4
|
return JSON.parse(readFileSync(url, 'utf8')).version;
|
|
5
5
|
}
|
|
6
|
+
/** The oldest Inlay version whose releases this one still runs. See the upgrades spec and CLAUDE.md. */
|
|
7
|
+
export const OLDEST_RELEASE = '0.5.0';
|
|
8
|
+
/** The oldest version the next window will keep, when already decided: older releases get a "pack again" warning. */
|
|
9
|
+
export const NEXT_OLDEST_RELEASE = null;
|
|
10
|
+
/** The first Inlay version whose releases serve their `public/` files at the site root too. */
|
|
11
|
+
export const ROOT_PUBLIC_FILES_SINCE = '0.7.0';
|
package/dist/host/activate.js
CHANGED
|
@@ -8,6 +8,7 @@ import { DEFAULT_MAX_BYTES, DEFAULT_UPLOAD_TYPES } from '../core/media/detect.js
|
|
|
8
8
|
import { fileMediaStore } from '../core/media/store.js';
|
|
9
9
|
import { buildRegistry } from '../core/registry/registry.js';
|
|
10
10
|
import { checkInlayVersion } from '../core/release/read.js';
|
|
11
|
+
import { packedVersion } from '../core/release/window.js';
|
|
11
12
|
import { currentRelease, getRelease, readCurrentPointer, writeCurrentPointer } from './store.js';
|
|
12
13
|
const noShipped = () => ({ created: [], replaced: [], skipped: [], deletedRefs: [], warnings: [] });
|
|
13
14
|
/** An activation's result as counts, for the worker that asked for it. */
|
|
@@ -105,7 +106,7 @@ export async function activateRelease(deps, releaseId) {
|
|
|
105
106
|
throw new InlayError('not_found', 'error.releaseUnknown', { id: releaseId });
|
|
106
107
|
if (row.state === 'deleted')
|
|
107
108
|
throw new InlayError('release', 'error.releaseDeleted', { name: row.name });
|
|
108
|
-
checkInlayVersion(row.inlay_range);
|
|
109
|
+
checkInlayVersion(packedVersion(row.inlay_range));
|
|
109
110
|
if (row.state === 'current') {
|
|
110
111
|
// A retry after a commit whose pointer write was lost: the database already says it's current.
|
|
111
112
|
const pointer = await readCurrentPointer(deps.releasesDir).catch(() => null);
|
package/dist/host/app.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export interface SiteSource {
|
|
|
15
15
|
shippedFiles?: ReadonlyMap<string, string>;
|
|
16
16
|
/** As `shippedFiles`, only the images `.md` files the site imports name. */
|
|
17
17
|
codeFiles?: ReadonlyMap<string, string>;
|
|
18
|
+
/** The release manifest; absent for a site run from its code, which always serves public files at the root. */
|
|
19
|
+
manifest?: {
|
|
20
|
+
inlay: {
|
|
21
|
+
version: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
25
|
/** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
|
|
20
26
|
export declare function sourceFromConfig(loaded: LoadedConfig): SiteSource;
|
package/dist/host/app.js
CHANGED
|
@@ -7,6 +7,8 @@ import { openDatabase } from '../core/db/connection.js';
|
|
|
7
7
|
import { InlayError } from '../core/errors.js';
|
|
8
8
|
import { t } from '../core/messages/index.js';
|
|
9
9
|
import { defineSite } from '../core/registry/define.js';
|
|
10
|
+
import { atLeastVersion } from '../core/release/window.js';
|
|
11
|
+
import { ROOT_PUBLIC_FILES_SINCE } from '../core/version.js';
|
|
10
12
|
import { PREVIEW_RELEASE_HEADER, registerPreviewProxy } from './preview-proxy.js';
|
|
11
13
|
import { adminHostHooks } from './hooks.js';
|
|
12
14
|
import { registerPushRoutes } from './push.js';
|
|
@@ -94,6 +96,7 @@ export async function createSiteApp(config, source, opts) {
|
|
|
94
96
|
cdn: config.cdn,
|
|
95
97
|
publicMaxAge: config.publicMaxAge,
|
|
96
98
|
...(source?.publicDir != null && { publicDir: source.publicDir }),
|
|
99
|
+
rootPublicFiles: source?.manifest === undefined || atLeastVersion(source.manifest.inlay.version, ROOT_PUBLIC_FILES_SINCE),
|
|
97
100
|
secrets: config.secrets(source?.site.secrets ?? []),
|
|
98
101
|
...(opts.fetch && { fetch: opts.fetch }),
|
|
99
102
|
content: opts.content,
|
package/dist/host/push.d.ts
CHANGED
|
@@ -62,7 +62,11 @@ export declare const RELEASE_NAME_MAX = 100;
|
|
|
62
62
|
/** With `activate`, how long the content half of the diff may take in all (preview start and answer): the activation waits. */
|
|
63
63
|
export declare const ACTIVATE_DIFF_TIMEOUT_MS = 10000;
|
|
64
64
|
/** A release row as the push API sends it: without the schema JSON, which is only kept for the record. */
|
|
65
|
-
export type ReleaseInfo = Omit<ReleaseRow, 'schema'
|
|
65
|
+
export type ReleaseInfo = Omit<ReleaseRow, 'schema'> & {
|
|
66
|
+
warning?: string;
|
|
67
|
+
};
|
|
68
|
+
/** The advance "pack again" warning for a release packed with the version in `row.inlay_range`, or null. */
|
|
69
|
+
export declare function packAgainWarning(row: Pick<ReleaseRow, 'inlay_range' | 'state'>): string | null;
|
|
66
70
|
export declare function releaseInfo(row: ReleaseRow): ReleaseInfo;
|
|
67
71
|
/**
|
|
68
72
|
* The manifest of what the site runs now: the current release's, or, for a site run from source with no current
|
package/dist/host/push.js
CHANGED
|
@@ -9,6 +9,7 @@ import { openDatabase } from '../core/db/connection.js';
|
|
|
9
9
|
import { InlayError } from '../core/errors.js';
|
|
10
10
|
import { t } from '../core/messages/index.js';
|
|
11
11
|
import { manifestOfRegistry, manifestSchema } from '../core/release/manifest.js';
|
|
12
|
+
import { packedVersion, releaseFit } from '../core/release/window.js';
|
|
12
13
|
import { structuralDiff } from './diff.js';
|
|
13
14
|
import { currentRelease, deleteRelease, getRelease, listReleases, releaseDir, storeRelease } from './store.js';
|
|
14
15
|
/** The largest release file a push may send. */
|
|
@@ -23,9 +24,17 @@ const RELEASE_TYPES = new Set(['application/gzip', 'application/x-gzip', 'applic
|
|
|
23
24
|
const DIFF_PATH = '/_inlay/internal/diff';
|
|
24
25
|
const DIFF_TIMEOUT_MS = 60_000;
|
|
25
26
|
const problemOf = (e) => (e instanceof Error ? e.message : String(e));
|
|
27
|
+
/** The advance "pack again" warning for a release packed with the version in `row.inlay_range`, or null. */
|
|
28
|
+
export function packAgainWarning(row) {
|
|
29
|
+
if (row.state === 'deleted')
|
|
30
|
+
return null;
|
|
31
|
+
const packed = packedVersion(row.inlay_range);
|
|
32
|
+
return releaseFit(packed) === 'warn' ? t('release.packAgain', { packed }) : null;
|
|
33
|
+
}
|
|
26
34
|
export function releaseInfo(row) {
|
|
27
35
|
const { schema: _schema, ...info } = row;
|
|
28
|
-
|
|
36
|
+
const warning = packAgainWarning(row);
|
|
37
|
+
return warning === null ? info : { ...info, warning };
|
|
29
38
|
}
|
|
30
39
|
async function readManifest(file) {
|
|
31
40
|
return manifestSchema.parse(JSON.parse(await readFile(file, 'utf8')));
|
|
@@ -161,12 +170,14 @@ export async function pushRelease(opts, file, push) {
|
|
|
161
170
|
throw new InlayError('release', 'error.releaseSecretsMissing', { names: missing.join(', ') });
|
|
162
171
|
const staged = await readManifest(join(releaseDir(work, row.id), 'manifest.json'));
|
|
163
172
|
const structural = structuralDiff(await currentManifest(opts), staged);
|
|
173
|
+
const packed = staged.inlay.version;
|
|
174
|
+
const packAgain = releaseFit(packed) === 'warn' ? [t('push.packAgain', { packed })] : [];
|
|
164
175
|
if (push.dryRun) {
|
|
165
176
|
if (opts.host?.startPreview === undefined)
|
|
166
|
-
return { release: null, diff: { structural, content: null }, warnings:
|
|
177
|
+
return { release: null, diff: { structural, content: null }, warnings: packAgain };
|
|
167
178
|
try {
|
|
168
179
|
const { content, warnings } = await contentDiff(opts, row.id, { dir: work });
|
|
169
|
-
return { release: null, diff: { structural, content }, warnings };
|
|
180
|
+
return { release: null, diff: { structural, content }, warnings: [...warnings, ...packAgain] };
|
|
170
181
|
}
|
|
171
182
|
finally {
|
|
172
183
|
await opts.host.stopPreview?.(row.id).catch(() => { });
|
|
@@ -190,7 +201,7 @@ export async function pushRelease(opts, file, push) {
|
|
|
190
201
|
}
|
|
191
202
|
structural.migrations = await pendingMigrations(opts.db, row.id, structural.migrations);
|
|
192
203
|
const { content, warnings } = await contentDiff(opts, row.id, push.activate ? { deadlineMs: opts.activateDiffTimeoutMs ?? ACTIVATE_DIFF_TIMEOUT_MS } : {});
|
|
193
|
-
return { release: row, diff: { structural, content }, warnings };
|
|
204
|
+
return { release: row, diff: { structural, content }, warnings: [...warnings, ...packAgain] };
|
|
194
205
|
}
|
|
195
206
|
finally {
|
|
196
207
|
await scratch.destroy();
|
|
@@ -249,7 +260,8 @@ function statusOf(e) {
|
|
|
249
260
|
switch (e.messageId) {
|
|
250
261
|
case 'error.releaseSignature':
|
|
251
262
|
return 403;
|
|
252
|
-
case 'error.
|
|
263
|
+
case 'error.releaseTooOld':
|
|
264
|
+
case 'error.releaseTooNew':
|
|
253
265
|
case 'error.releaseSecretsMissing':
|
|
254
266
|
case 'error.releaseCurrent':
|
|
255
267
|
case 'error.releaseDeleted':
|
package/dist/host/worker.js
CHANGED
|
@@ -5,6 +5,7 @@ import { openDatabase } from '../core/db/connection.js';
|
|
|
5
5
|
import { InlayError } from '../core/errors.js';
|
|
6
6
|
import { t } from '../core/messages/index.js';
|
|
7
7
|
import { checkInlayVersion, loadRelease } from '../core/release/read.js';
|
|
8
|
+
import { packedVersion, releaseFit } from '../core/release/window.js';
|
|
8
9
|
import { activateRelease, summarize } from './activate.js';
|
|
9
10
|
import { createSiteApp } from './app.js';
|
|
10
11
|
import { drainable } from './drain.js';
|
|
@@ -82,12 +83,14 @@ async function chooseRelease(config, log) {
|
|
|
82
83
|
log('host.pointerRepaired', { name: row.name });
|
|
83
84
|
}
|
|
84
85
|
try {
|
|
85
|
-
checkInlayVersion(row.inlay_range);
|
|
86
|
+
checkInlayVersion(packedVersion(row.inlay_range));
|
|
86
87
|
}
|
|
87
88
|
catch (e) {
|
|
88
|
-
if (!(e instanceof InlayError)
|
|
89
|
+
if (!(e instanceof InlayError))
|
|
89
90
|
throw e;
|
|
90
|
-
|
|
91
|
+
if (e.messageId !== 'error.releaseTooOld' && e.messageId !== 'error.releaseTooNew')
|
|
92
|
+
throw e;
|
|
93
|
+
log(e.messageId === 'error.releaseTooOld' ? 'host.releaseTooOld' : 'host.releaseTooNew', { ...e.params, name: row.name });
|
|
91
94
|
return { page: 'unavailable', id: row.id };
|
|
92
95
|
}
|
|
93
96
|
const opened = await openCurrentRelease({ releasesDir: config.paths.releases });
|
|
@@ -95,6 +98,9 @@ async function chooseRelease(config, log) {
|
|
|
95
98
|
log('host.releaseMissing', { name: row.name });
|
|
96
99
|
return { page: 'unavailable', id: row.id };
|
|
97
100
|
}
|
|
101
|
+
const packed = packedVersion(row.inlay_range);
|
|
102
|
+
if (releaseFit(packed) === 'warn')
|
|
103
|
+
log('host.releasePackAgain', { name: row.name, packed });
|
|
98
104
|
return { loaded: opened.loaded, id: row.id, name: row.name };
|
|
99
105
|
}
|
|
100
106
|
/**
|
package/dist/site.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { defineConfig, type InlayConfig } from './config.js';
|
|
|
12
12
|
export { escapeHtml, raw, SafeHtml, type Html, type Renderable } from './jsx/html.js';
|
|
13
13
|
export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps } from './core/fields/define.js';
|
|
14
14
|
export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.js';
|
|
15
|
-
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type OgType, type RedirectDef, type SeoSettings, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
|
|
15
|
+
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type OgType, type RedirectDef, type SeoSettings, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TrailingSlash, type TypeDef, } from './core/registry/define.js';
|
|
16
16
|
export { defineIntegration, type ConsentCategory, type CspDirective, type CspSources, type IntegrationDef, type IntegrationPage, type IntegrationRender, } from './core/registry/integration.js';
|
|
17
17
|
export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
|
|
18
18
|
export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
|