inlaycms 0.2.0 → 0.4.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 +334 -1
- package/assets/admin/admin.css +1 -1
- package/assets/admin/admin.js +1 -1
- package/assets/admin/editor.js +59 -44
- package/dist/adapters/admin/screens/redirects.js +12 -3
- package/dist/adapters/admin/views/layout.js +27 -7
- package/dist/adapters/cli/remote.js +9 -1
- package/dist/adapters/mcp/tools/redirects.js +16 -2
- package/dist/adapters/site/assets.d.ts +11 -0
- package/dist/adapters/site/assets.js +71 -0
- package/dist/adapters/site/cache.d.ts +2 -1
- package/dist/adapters/site/cache.js +6 -1
- package/dist/adapters/site/context.d.ts +6 -0
- package/dist/adapters/site/context.js +38 -13
- package/dist/adapters/site/head.d.ts +30 -7
- package/dist/adapters/site/head.js +145 -20
- package/dist/adapters/site/headers.d.ts +5 -0
- package/dist/adapters/site/headers.js +31 -0
- package/dist/adapters/site/plugin.d.ts +2 -0
- package/dist/adapters/site/plugin.js +32 -9
- package/dist/adapters/site/public.js +7 -24
- package/dist/adapters/site/render.d.ts +5 -0
- package/dist/adapters/site/render.js +23 -8
- package/dist/adapters/site/routes.d.ts +6 -0
- package/dist/adapters/site/routes.js +8 -3
- package/dist/adapters/site/seo.d.ts +20 -0
- package/dist/adapters/site/seo.js +45 -0
- package/dist/adapters/site/sitemap.d.ts +1 -1
- package/dist/adapters/site/sitemap.js +1 -1
- package/dist/config.js +3 -2
- package/dist/core/agent/format.js +1 -1
- package/dist/core/agent/schema.js +3 -0
- package/dist/core/boot.js +7 -0
- package/dist/core/check.js +6 -1
- package/dist/core/content/dry-run.d.ts +7 -6
- package/dist/core/content/dry-run.js +8 -8
- package/dist/core/content/publish.d.ts +1 -1
- package/dist/core/content/publish.js +5 -3
- package/dist/core/content/read.d.ts +3 -0
- package/dist/core/content/reader.js +3 -2
- package/dist/core/content/refs.js +1 -1
- package/dist/core/content/search.js +2 -2
- package/dist/core/content/shipped-images.d.ts +32 -0
- package/dist/core/content/shipped-images.js +62 -0
- package/dist/core/content/shipped-input.d.ts +9 -3
- package/dist/core/content/shipped-input.js +165 -28
- package/dist/core/content/shipped.js +8 -3
- package/dist/core/content/validate.js +7 -1
- package/dist/core/core.d.ts +5 -1
- package/dist/core/core.js +5 -4
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +13 -1
- package/dist/core/db/migrate.js +2 -0
- package/dist/core/db/migrations/0007_published_at.d.ts +3 -0
- package/dist/core/db/migrations/0007_published_at.js +16 -0
- package/dist/core/db/schema.d.ts +1 -0
- package/dist/core/export/export.js +3 -1
- package/dist/core/export/format.d.ts +8 -1
- package/dist/core/export/format.js +3 -2
- package/dist/core/export/read.js +7 -0
- package/dist/core/export/stage.d.ts +1 -1
- package/dist/core/export/stage.js +24 -1
- package/dist/core/fields/builtins.d.ts +28 -0
- package/dist/core/fields/builtins.js +103 -11
- package/dist/core/fields/define.d.ts +6 -0
- package/dist/core/fields/widgets.d.ts +7 -0
- package/dist/core/fields/widgets.js +77 -28
- package/dist/core/media/library.js +2 -2
- package/dist/core/messages/en.d.ts +72 -6
- package/dist/core/messages/en.js +72 -6
- package/dist/core/redirects/collapse.d.ts +17 -1
- package/dist/core/redirects/collapse.js +19 -3
- package/dist/core/redirects/redirects.d.ts +13 -12
- package/dist/core/redirects/redirects.js +141 -53
- package/dist/core/redirects/rule.d.ts +25 -0
- package/dist/core/redirects/rule.js +55 -0
- package/dist/core/registry/define.d.ts +40 -0
- package/dist/core/registry/define.js +3 -0
- package/dist/core/registry/registry.d.ts +21 -0
- package/dist/core/registry/registry.js +114 -6
- package/dist/core/registry/render.d.ts +37 -1
- package/dist/core/registry/route.d.ts +4 -0
- package/dist/core/release/bundle.js +30 -5
- package/dist/core/release/manifest.d.ts +14 -0
- package/dist/core/release/manifest.js +42 -17
- package/dist/core/release/markdown-file.d.ts +21 -0
- package/dist/core/release/markdown-file.js +172 -0
- package/dist/core/release/pack.js +2 -2
- package/dist/core/release/read.js +4 -1
- package/dist/core/release/site-dir.d.ts +4 -0
- package/dist/core/release/site-dir.js +8 -0
- package/dist/core/report.d.ts +8 -2
- package/dist/core/richtext/html.d.ts +3 -1
- package/dist/core/richtext/html.js +18 -4
- package/dist/core/richtext/inline.d.ts +22 -0
- package/dist/core/richtext/inline.js +33 -0
- package/dist/core/richtext/markdown.d.ts +19 -1
- package/dist/core/richtext/markdown.js +187 -22
- package/dist/core/richtext/schema.d.ts +22 -5
- package/dist/core/richtext/schema.js +81 -4
- package/dist/core/site/live.d.ts +1 -0
- package/dist/core/site/live.js +1 -0
- package/dist/core/site/paths.d.ts +6 -0
- package/dist/core/site/paths.js +13 -0
- package/dist/core/site/resolve.d.ts +1 -1
- package/dist/core/site/resolve.js +119 -30
- package/dist/core/site/sitemap.d.ts +1 -1
- package/dist/core/site/sitemap.js +4 -0
- package/dist/core/types.d.ts +28 -3
- package/dist/host/app.d.ts +5 -0
- package/dist/host/app.js +10 -1
- package/dist/host/dev.js +3 -7
- package/dist/host/diff.d.ts +19 -1
- package/dist/host/diff.js +32 -2
- package/dist/index.d.ts +2 -2
- package/dist/markdown-modules.d.ts +8 -0
- package/dist/markdown-modules.js +1 -0
- package/dist/site.d.ts +8 -3
- package/dist/site.js +6 -0
- package/dist/testing.d.ts +22 -0
- package/dist/testing.js +155 -0
- package/package.json +7 -1
package/dist/testing.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { loadConfig } from './config.js';
|
|
7
|
+
import { checkBundle } from './core/check.js';
|
|
8
|
+
import { InlayError } from './core/errors.js';
|
|
9
|
+
import { formatReport } from './core/report.js';
|
|
10
|
+
import { createSiteApp, sourceFromConfig } from './host/app.js';
|
|
11
|
+
import { ensureDataDir, readHostConfig } from './host/config.js';
|
|
12
|
+
function configFile(config) {
|
|
13
|
+
if (typeof config === 'string' && !config.startsWith('file:'))
|
|
14
|
+
return resolve(process.cwd(), config);
|
|
15
|
+
const url = typeof config === 'string' ? new URL(config) : config;
|
|
16
|
+
if (url.protocol !== 'file:')
|
|
17
|
+
throw new InlayError('not_found', 'error.configMissing', { path: url.href });
|
|
18
|
+
return fileURLToPath(url);
|
|
19
|
+
}
|
|
20
|
+
/** Refuses a site that `inlaycms pack` refuses, so its tests can't pass where a release would fail. */
|
|
21
|
+
async function checkPackBoundary(file) {
|
|
22
|
+
const problems = await checkBundle(file);
|
|
23
|
+
if (problems.length === 0)
|
|
24
|
+
return;
|
|
25
|
+
const list = formatReport({
|
|
26
|
+
ok: false,
|
|
27
|
+
systemMigrations: [],
|
|
28
|
+
shipped: { created: [], replaced: [], skipped: [], deletedRefs: [], warnings: [] },
|
|
29
|
+
problems,
|
|
30
|
+
warnings: [],
|
|
31
|
+
}).join('\n');
|
|
32
|
+
throw new InlayError('check_failed', 'error.checkFailed', { count: problems.length, list }, { problems });
|
|
33
|
+
}
|
|
34
|
+
/** Statuses a Response can't carry a body with. */
|
|
35
|
+
const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
36
|
+
/**
|
|
37
|
+
* Boots the site of an `inlay.config.ts` the way `inlaycms dev` does, in a temporary data folder, and answers its
|
|
38
|
+
* requests in process (Fastify `inject`): no port, no child process. `close()` stops it and removes the folder.
|
|
39
|
+
*/
|
|
40
|
+
export async function createTestSite(opts) {
|
|
41
|
+
const file = configFile(opts.config);
|
|
42
|
+
const loaded = await loadConfig(file);
|
|
43
|
+
await checkPackBoundary(file);
|
|
44
|
+
const dataDir = await mkdtemp(join(tmpdir(), 'inlay-test-site-'));
|
|
45
|
+
let host;
|
|
46
|
+
let booted;
|
|
47
|
+
try {
|
|
48
|
+
const read = readHostConfig({
|
|
49
|
+
INLAY_DATA_DIR: dataDir,
|
|
50
|
+
INLAY_BASE_URL: opts.baseUrl ?? 'http://localhost',
|
|
51
|
+
INLAY_SECRET: randomBytes(32).toString('hex'),
|
|
52
|
+
INLAY_RATE_LIMIT: 'off',
|
|
53
|
+
});
|
|
54
|
+
const given = opts.secrets ?? {};
|
|
55
|
+
host = {
|
|
56
|
+
...read,
|
|
57
|
+
secrets: (names) => Object.fromEntries(Object.entries(given).filter(([name]) => names.includes(name))),
|
|
58
|
+
};
|
|
59
|
+
await ensureDataDir(host);
|
|
60
|
+
booted = await createSiteApp(host, sourceFromConfig(loaded), {
|
|
61
|
+
content: 'apply',
|
|
62
|
+
backupSchedule: false,
|
|
63
|
+
...(opts.now && { now: opts.now }),
|
|
64
|
+
...(opts.fetch && { fetch: opts.fetch }),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
await rm(dataDir, { recursive: true, force: true });
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
const { app, core } = booted;
|
|
72
|
+
const hostHeader = new URL(host.baseUrl).host;
|
|
73
|
+
let closed = null;
|
|
74
|
+
const inFlight = new Set();
|
|
75
|
+
const track = (p) => {
|
|
76
|
+
inFlight.add(p);
|
|
77
|
+
const done = () => void inFlight.delete(p);
|
|
78
|
+
p.then(done, done);
|
|
79
|
+
return p;
|
|
80
|
+
};
|
|
81
|
+
const ensureOpen = () => {
|
|
82
|
+
if (closed)
|
|
83
|
+
throw new InlayError('invalid_operation', 'error.testSiteClosed');
|
|
84
|
+
};
|
|
85
|
+
const send = async (path, init = {}) => {
|
|
86
|
+
ensureOpen();
|
|
87
|
+
if (typeof path !== 'string' || !path.startsWith('/') || path.startsWith('//')) {
|
|
88
|
+
throw new InlayError('invalid_operation', 'error.testSitePath', { path: String(path) });
|
|
89
|
+
}
|
|
90
|
+
const method = (init.method ?? 'GET').toUpperCase();
|
|
91
|
+
const headers = Object.fromEntries(new Headers(init.headers));
|
|
92
|
+
if (headers.host === undefined)
|
|
93
|
+
headers.host = hostHeader;
|
|
94
|
+
const body = init.body;
|
|
95
|
+
let payload;
|
|
96
|
+
if (typeof body === 'string') {
|
|
97
|
+
payload = body;
|
|
98
|
+
if (headers['content-type'] === undefined)
|
|
99
|
+
headers['content-type'] = 'text/plain;charset=UTF-8';
|
|
100
|
+
}
|
|
101
|
+
else if (body instanceof URLSearchParams) {
|
|
102
|
+
payload = body.toString();
|
|
103
|
+
if (headers['content-type'] === undefined) {
|
|
104
|
+
headers['content-type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (body !== undefined && body !== null) {
|
|
108
|
+
throw new InlayError('invalid_operation', 'error.testSiteBody');
|
|
109
|
+
}
|
|
110
|
+
const res = await app.inject({
|
|
111
|
+
method: method,
|
|
112
|
+
url: path,
|
|
113
|
+
headers,
|
|
114
|
+
...(payload !== undefined && { payload }),
|
|
115
|
+
});
|
|
116
|
+
const out = new Headers();
|
|
117
|
+
for (const [name, value] of Object.entries(res.headers)) {
|
|
118
|
+
if (value === undefined)
|
|
119
|
+
continue;
|
|
120
|
+
if (Array.isArray(value))
|
|
121
|
+
for (const v of value)
|
|
122
|
+
out.append(name, v);
|
|
123
|
+
else
|
|
124
|
+
out.append(name, String(value));
|
|
125
|
+
}
|
|
126
|
+
const bodiless = method === 'HEAD' || NULL_BODY_STATUSES.has(res.statusCode);
|
|
127
|
+
return new Response(bodiless ? null : new Uint8Array(res.rawPayload), {
|
|
128
|
+
status: res.statusCode,
|
|
129
|
+
statusText: res.statusMessage,
|
|
130
|
+
headers: out,
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
async fetch(path, init) {
|
|
135
|
+
ensureOpen();
|
|
136
|
+
return track(send(path, init));
|
|
137
|
+
},
|
|
138
|
+
async paths() {
|
|
139
|
+
ensureOpen();
|
|
140
|
+
return track(core.sitemapEntries().then((entries) => entries.map((e) => e.path)));
|
|
141
|
+
},
|
|
142
|
+
close() {
|
|
143
|
+
closed ??= (async () => {
|
|
144
|
+
try {
|
|
145
|
+
await Promise.allSettled([...inFlight]);
|
|
146
|
+
await app.close();
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
await rm(dataDir, { recursive: true, force: true });
|
|
150
|
+
}
|
|
151
|
+
})();
|
|
152
|
+
return closed;
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inlaycms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A code-first CMS for content sites: templates, schemas and content in code, one SQLite file, signed releases.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"types": "./dist/site.d.ts",
|
|
35
35
|
"default": "./dist/site.js"
|
|
36
36
|
},
|
|
37
|
+
"./testing": {
|
|
38
|
+
"types": "./dist/testing.d.ts",
|
|
39
|
+
"default": "./dist/testing.js"
|
|
40
|
+
},
|
|
37
41
|
"./jsx-runtime": {
|
|
38
42
|
"types": "./dist/jsx/jsx-runtime.d.ts",
|
|
39
43
|
"default": "./dist/jsx/jsx-runtime.js"
|
|
@@ -79,12 +83,14 @@
|
|
|
79
83
|
"@tiptap/core": "^3.32.2",
|
|
80
84
|
"@tiptap/extension-blockquote": "^3.32.2",
|
|
81
85
|
"@tiptap/extension-bold": "^3.32.2",
|
|
86
|
+
"@tiptap/extension-code": "^3.32.2",
|
|
82
87
|
"@tiptap/extension-document": "^3.32.2",
|
|
83
88
|
"@tiptap/extension-hard-break": "^3.32.2",
|
|
84
89
|
"@tiptap/extension-heading": "^3.32.2",
|
|
85
90
|
"@tiptap/extension-italic": "^3.32.2",
|
|
86
91
|
"@tiptap/extension-list": "^3.32.2",
|
|
87
92
|
"@tiptap/extension-paragraph": "^3.32.2",
|
|
93
|
+
"@tiptap/extension-table": "^3.32.2",
|
|
88
94
|
"@tiptap/extension-text": "^3.32.2",
|
|
89
95
|
"@tiptap/extensions": "^3.32.2",
|
|
90
96
|
"@tiptap/pm": "^3.32.2",
|