editlet 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +113 -2
- package/dist/admin/config.d.ts +22 -0
- package/dist/admin/config.js +75 -0
- package/dist/admin/dist/assets/RichEditor-BlaCRrEX.css +1 -0
- package/dist/admin/dist/assets/RichEditor-IZKdt6MK.js +42 -0
- package/dist/admin/dist/assets/blank-line-CbGzlqBI.js +1 -0
- package/dist/admin/dist/assets/channel-CljeMIwA.js +1 -0
- package/dist/admin/dist/assets/db-CCMyPgQa.js +1 -0
- package/dist/admin/dist/assets/index-CWoJh4H8.js +257 -0
- package/dist/admin/dist/assets/index-DkRMnD_M.css +1 -0
- package/dist/admin/dist/assets/mdast-util-from-markdown-C79q1_d8.js +3 -0
- package/dist/admin/dist/assets/mdast-util-gfm-cM-_xFJE.js +19 -0
- package/dist/admin/dist/assets/micromark-extension-gfm-Wz6-oszS.js +1 -0
- package/dist/admin/dist/assets/micromark-util-classify-character-BgXaGAja.js +1 -0
- package/dist/admin/dist/assets/micromark-util-html-tag-name-B61T18yC.js +1 -0
- package/dist/admin/dist/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/admin/dist/index.html +16 -0
- package/dist/admin/dist/preview.js +1 -0
- package/dist/admin/dist/window.js +1 -0
- package/dist/astro/content.d.ts +21 -0
- package/dist/astro/content.js +235 -0
- package/dist/astro/devServer.js +89 -0
- package/dist/astro/index.d.ts +15 -0
- package/dist/astro/index.js +98 -0
- package/dist/astro/nodeBridge.js +36 -0
- package/dist/astro/shared.js +10 -0
- package/dist/astro/stub/index.html +71 -0
- package/dist/auth/client.d.ts +24 -0
- package/dist/auth/client.js +120 -0
- package/dist/auth/handler.d.ts +16 -0
- package/dist/auth/handler.js +281 -0
- package/dist/auth/protocol.d.ts +25 -0
- package/dist/auth/protocol.js +3 -0
- package/dist/core/assets.d.ts +73 -0
- package/dist/core/assets.js +405 -0
- package/dist/core/devApi.d.ts +28 -0
- package/dist/core/devApi.js +3 -0
- package/dist/core/entryFile.d.ts +13 -0
- package/dist/core/entryFile.js +81 -0
- package/dist/core/fields.js +147 -0
- package/dist/core/generate.d.ts +3 -0
- package/dist/core/generate.js +70 -0
- package/dist/core/gitStyle.d.ts +92 -0
- package/dist/core/gitStyle.js +206 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +16 -0
- package/dist/core/issues.d.ts +10 -0
- package/dist/core/issues.js +10 -0
- package/dist/core/paths.d.ts +31 -0
- package/dist/core/paths.js +114 -0
- package/dist/core/project.js +56 -0
- package/dist/core/references.d.ts +68 -0
- package/dist/core/references.js +103 -0
- package/dist/core/rename.d.ts +60 -0
- package/dist/core/rename.js +133 -0
- package/dist/core/schema.d.ts +117 -0
- package/dist/core/schema.js +299 -0
- package/dist/core/sha.d.ts +2 -0
- package/dist/core/sha.js +13 -0
- package/dist/core/source.d.ts +48 -0
- package/dist/core/source.js +57 -0
- package/dist/core/validate.d.ts +22 -0
- package/dist/core/validate.js +148 -0
- package/dist/core/walk.d.ts +23 -0
- package/dist/core/walk.js +94 -0
- package/dist/core/writes.d.ts +37 -0
- package/dist/core/writes.js +166 -0
- package/dist/github/base64.js +16 -0
- package/dist/github/cache.d.ts +34 -0
- package/dist/github/cache.js +126 -0
- package/dist/github/client.d.ts +38 -0
- package/dist/github/client.js +228 -0
- package/dist/github/codeowners.d.ts +23 -0
- package/dist/github/codeowners.js +96 -0
- package/dist/github/commitReader.d.ts +25 -0
- package/dist/github/commitReader.js +38 -0
- package/dist/github/deploy.d.ts +15 -0
- package/dist/github/deploy.js +33 -0
- package/dist/github/index.d.ts +9 -0
- package/dist/github/index.js +8 -0
- package/dist/github/repo.d.ts +95 -0
- package/dist/github/repo.js +375 -0
- package/dist/github/source.d.ts +115 -0
- package/dist/github/source.js +558 -0
- package/dist/loader/index.d.ts +27 -0
- package/dist/loader/index.js +151 -0
- package/dist/loader/protocol.d.ts +95 -0
- package/dist/loader/protocol.js +120 -0
- package/dist/loader/window/geometry.js +9 -0
- package/dist/next/EditletLoader.d.ts +5 -0
- package/dist/next/EditletLoader.js +33 -0
- package/dist/next/assetUrl.d.ts +9 -0
- package/dist/next/assetUrl.js +13 -0
- package/dist/next/buildGuard.js +26 -0
- package/dist/next/config.d.ts +18 -0
- package/dist/next/config.js +255 -0
- package/dist/next/devServer.js +70 -0
- package/dist/next/editletField.d.ts +7 -0
- package/dist/next/editletField.js +7 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.js +6 -0
- package/dist/next/preview.d.ts +18 -0
- package/dist/next/preview.js +100 -0
- package/dist/next/previewCookie.d.ts +5 -0
- package/dist/next/previewCookie.js +72 -0
- package/dist/next/previewEnv.js +25 -0
- package/dist/next/previewRef.d.ts +8 -0
- package/dist/next/previewRef.js +17 -0
- package/dist/next/publicDir.js +65 -0
- package/dist/next/reader.d.ts +49 -0
- package/dist/next/reader.js +161 -0
- package/dist/next/stub/index.html +56 -0
- package/dist/node/devHandler.d.ts +6 -0
- package/dist/node/devHandler.js +430 -0
- package/dist/node/fs.js +37 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +3 -0
- package/dist/node/project.d.ts +12 -0
- package/dist/node/project.js +43 -0
- package/package.json +187 -4
- package/skills/README.md +84 -0
- package/skills/editlet/SKILL.md +119 -0
- package/skills/editlet/references/content-format.md +191 -0
- package/skills/editlet/references/preview.md +75 -0
- package/skills/editlet/references/publishing.md +137 -0
- package/skills/editlet/references/schema-changes.md +127 -0
- package/skills/editlet/scripts/guard.mjs +1061 -0
- package/skills/editlet/scripts/link.mjs +193 -0
- package/skills/editlet/scripts/refs.mjs +1480 -0
- package/skills/editlet/scripts/schema.mjs +1340 -0
- package/skills/editlet/scripts/style.mjs +657 -0
- package/skills/editlet/scripts/types.mjs +525 -0
- package/skills/editlet/scripts/validate.mjs +724 -0
- package/skills/editlet-migrate/SKILL.md +92 -0
- package/skills/editlet-migrate/references/mapping.md +73 -0
- package/skills/editlet-migrate/references/sources.md +70 -0
- package/skills/editlet-setup/SKILL.md +108 -0
- package/skills/editlet-setup/references/astro.md +83 -0
- package/skills/editlet-setup/references/doctor.md +89 -0
- package/skills/editlet-setup/references/next.md +140 -0
- package/skills/editlet-setup/references/preview.md +54 -0
- package/skills/editlet-setup/references/production.md +153 -0
- package/skills/editlet-setup/references/roles.md +238 -0
- package/skills/editlet-setup/references/skills.md +99 -0
- package/skills/editlet-setup/scripts/doctor.mjs +1378 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { BLOCK_KEY } from "./schema.js";
|
|
2
|
+
// core/walk.ts
|
|
3
|
+
/**
|
|
4
|
+
* Walking entry data together with its fields, into `object` fields, their lists and `blocks` items. Leaf values (every
|
|
5
|
+
* other field type) are what callers see; containers are handled here. Data that does not match the schema (a list
|
|
6
|
+
* that is not an array, an item that is not an object, an unknown block kind) is skipped, never thrown on.
|
|
7
|
+
*/
|
|
8
|
+
const isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9
|
+
/** The fields of one `blocks` item (by its `block` key), or `undefined` for an unknown kind. */
|
|
10
|
+
function blockFields(field, item) {
|
|
11
|
+
if (!isPlainObject(item)) return void 0;
|
|
12
|
+
const kind = item[BLOCK_KEY];
|
|
13
|
+
return typeof kind === "string" && Object.hasOwn(field.blocks, kind) ? field.blocks[kind].fields : void 0;
|
|
14
|
+
}
|
|
15
|
+
/** Each container's child data with its fields and path: one object, or every item of a list. */
|
|
16
|
+
function children(field, value, path) {
|
|
17
|
+
if (field.type === "object") {
|
|
18
|
+
if (!field.list) return isPlainObject(value) ? [[
|
|
19
|
+
field.fields,
|
|
20
|
+
value,
|
|
21
|
+
path
|
|
22
|
+
]] : [];
|
|
23
|
+
if (!Array.isArray(value)) return [];
|
|
24
|
+
return value.flatMap((item, i) => isPlainObject(item) ? [[
|
|
25
|
+
field.fields,
|
|
26
|
+
item,
|
|
27
|
+
[...path, i]
|
|
28
|
+
]] : []);
|
|
29
|
+
}
|
|
30
|
+
if (field.type === "blocks") {
|
|
31
|
+
if (!Array.isArray(value)) return [];
|
|
32
|
+
return value.flatMap((item, i) => {
|
|
33
|
+
const fields = blockFields(field, item);
|
|
34
|
+
return fields ? [[
|
|
35
|
+
fields,
|
|
36
|
+
item,
|
|
37
|
+
[...path, i]
|
|
38
|
+
]] : [];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const isContainer = (field) => field.type === "object" || field.type === "blocks";
|
|
44
|
+
/**
|
|
45
|
+
* Calls `visit` for every leaf value present in `data` (keys of `fields` that `data` has), depth first in field order:
|
|
46
|
+
* `path` is the dot path parts from the entry's data (`['content', 2, 'image']`).
|
|
47
|
+
*/
|
|
48
|
+
function visitFields(fields, data, visit, at = []) {
|
|
49
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
50
|
+
if (!Object.hasOwn(data, key)) continue;
|
|
51
|
+
const path = [...at, key];
|
|
52
|
+
if (!isContainer(field)) {
|
|
53
|
+
visit(field, data[key], path);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
for (const [childFields, child, childPath] of children(field, data[key], path)) visitFields(childFields, child, visit, childPath);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A copy of `data` with every leaf value replaced by `map(field, value, path)`; `undefined` drops the key. Containers
|
|
61
|
+
* are copied (objects, lists, block items keep their `block` key); keys outside `fields` are kept as they are.
|
|
62
|
+
*/
|
|
63
|
+
function mapFields(fields, data, map, at = []) {
|
|
64
|
+
const out = { ...data };
|
|
65
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
66
|
+
if (!Object.hasOwn(data, key)) continue;
|
|
67
|
+
const path = [...at, key];
|
|
68
|
+
const value = data[key];
|
|
69
|
+
let next;
|
|
70
|
+
if (field.type === "object" && !field.list) next = isPlainObject(value) ? mapFields(field.fields, value, map, path) : value;
|
|
71
|
+
else if (field.type === "object" && Array.isArray(value)) next = value.map((item, i) => isPlainObject(item) ? mapFields(field.fields, item, map, [...path, i]) : item);
|
|
72
|
+
else if (field.type === "blocks" && Array.isArray(value)) next = value.map((item, i) => {
|
|
73
|
+
const child = blockFields(field, item);
|
|
74
|
+
return child ? mapFields(child, item, map, [...path, i]) : item;
|
|
75
|
+
});
|
|
76
|
+
else if (isContainer(field)) next = value;
|
|
77
|
+
else next = map(field, value, path);
|
|
78
|
+
if (next === void 0) delete out[key];
|
|
79
|
+
else out[key] = next;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/** Every field, nested ones too, with its path in the schema's field tree (`['content', 'hero', 'title']`). */
|
|
84
|
+
function allFields(fields, at = []) {
|
|
85
|
+
const out = [];
|
|
86
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
87
|
+
const path = [...at, key];
|
|
88
|
+
out.push([path, field]);
|
|
89
|
+
if (field.type === "object") out.push(...allFields(field.fields, path));
|
|
90
|
+
if (field.type === "blocks") for (const [kind, block] of Object.entries(field.blocks)) out.push(...allFields(block.fields, [...path, kind]));
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
export { allFields, blockFields, mapFields, visitFields };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Issue } from "./issues.js";
|
|
2
|
+
import { Schema } from "./schema.js";
|
|
3
|
+
import { FileChange } from "./source.js";
|
|
4
|
+
/**
|
|
5
|
+
* True for the schema file itself, `.md` paths that `parseEntryPath` accepts and image paths inside `contentDir`.
|
|
6
|
+
* Rejects non-canonical paths (absolute, `..` / `.` / empty segments, backslashes, NUL, `:`), hidden paths
|
|
7
|
+
* (a segment below `contentDir` starting with `.`) and anything else.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isWritablePath(schema: Schema, schemaPath: string, path: string): boolean;
|
|
10
|
+
/** The repository state a batch of changes is validated against (before the changes). */
|
|
11
|
+
export interface ChangeContext {
|
|
12
|
+
/** Parsed schema on disk; `null` when it is broken. */
|
|
13
|
+
schema: Schema | null;
|
|
14
|
+
schemaPath: string;
|
|
15
|
+
exists: (path: string) => boolean;
|
|
16
|
+
/** UTF-8 text of an existing file; `undefined` when it is missing or not valid UTF-8. Use together with `list`. */
|
|
17
|
+
read?: (path: string) => string | undefined;
|
|
18
|
+
/** Every existing file path (any order). Use together with `read`. */
|
|
19
|
+
list?: () => Iterable<string>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validates a set of writes against the state AFTER the changes. A schema change in the batch is parsed and used
|
|
23
|
+
* for the entries of the same batch; if it fails to parse only its issues are returned. `current.schema === null`
|
|
24
|
+
* means the schema on disk is broken: then only a change to the schema file is accepted.
|
|
25
|
+
*
|
|
26
|
+
* Changed entries are always validated. When `current.read` and `current.list` are given and the batch deletes a
|
|
27
|
+
* file or changes the schema, every other non-hidden `.md` file under the old or new `contentDir` is validated too,
|
|
28
|
+
* with the post-change schema and file set, and only issues it did not already have before the batch (same
|
|
29
|
+
* `path` + `message` under the pre-change schema and file set) are reported: deleting a referenced entry or image,
|
|
30
|
+
* or a schema change that breaks existing entries (or turns entries into non-entries), returns issues, while stray
|
|
31
|
+
* or already-broken files do not block unrelated changes. Without `read` / `list` unchanged entries are not
|
|
32
|
+
* re-validated, so a caller (e.g. the GitHub source) must pass both, or validate the whole project, for the same
|
|
33
|
+
* guarantee.
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateChanges(current: ChangeContext, changes: FileChange[]): Issue[];
|
|
36
|
+
/** `validateChanges` plus the commit-message rule shared by every `ContentSource.commit`. */
|
|
37
|
+
export declare function validateCommit(current: ChangeContext, changes: FileChange[], message: string): Issue[];
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { decodeUtf8, parseEntryFile } from "./entryFile.js";
|
|
2
|
+
import { EditletError } from "./issues.js";
|
|
3
|
+
import { entryFilePath, isCanonicalPath, isHiddenContentPath, isImagePath, parseEntryPath, parseRefKey } from "./paths.js";
|
|
4
|
+
import { parseSchemaText } from "./schema.js";
|
|
5
|
+
import { validateEntry } from "./validate.js";
|
|
6
|
+
// core/writes.ts
|
|
7
|
+
/**
|
|
8
|
+
* True for the schema file itself, `.md` paths that `parseEntryPath` accepts and image paths inside `contentDir`.
|
|
9
|
+
* Rejects non-canonical paths (absolute, `..` / `.` / empty segments, backslashes, NUL, `:`), hidden paths
|
|
10
|
+
* (a segment below `contentDir` starting with `.`) and anything else.
|
|
11
|
+
*/
|
|
12
|
+
function isWritablePath(schema, schemaPath, path) {
|
|
13
|
+
if (!isCanonicalPath(path)) return false;
|
|
14
|
+
if (path === schemaPath) return true;
|
|
15
|
+
if (!path.startsWith(`${schema.contentDir}/`) || isHiddenContentPath(schema, path)) return false;
|
|
16
|
+
if (path.endsWith(".md")) return parseEntryPath(schema, path) !== null;
|
|
17
|
+
return isImagePath(path);
|
|
18
|
+
}
|
|
19
|
+
function issuesOf(error, file) {
|
|
20
|
+
if (!(error instanceof EditletError)) throw error;
|
|
21
|
+
return error.issues.map((issue) => ({
|
|
22
|
+
...issue,
|
|
23
|
+
file: issue.file ?? file
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
const issueKey = (i) => `${i.file}|${i.path}|${i.message}`;
|
|
27
|
+
function refExists(schema, fileExists) {
|
|
28
|
+
return (ref) => {
|
|
29
|
+
const parsed = parseRefKey(ref);
|
|
30
|
+
if (!parsed || !Object.hasOwn(schema.collections, parsed.collection)) return false;
|
|
31
|
+
const { collection, slug } = parsed;
|
|
32
|
+
if (schema.collections[collection].singleton && slug !== "index") return false;
|
|
33
|
+
const path = entryFilePath(schema, collection, slug);
|
|
34
|
+
return parseEntryPath(schema, path) !== null && fileExists(path);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function checkEntry(state, path, entry, content) {
|
|
38
|
+
const decoded = decodeUtf8(content, path);
|
|
39
|
+
if ("issue" in decoded) return [decoded.issue];
|
|
40
|
+
let file;
|
|
41
|
+
try {
|
|
42
|
+
file = parseEntryFile(decoded.text);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return issuesOf(error, path);
|
|
45
|
+
}
|
|
46
|
+
const { schema, ...ctx } = state;
|
|
47
|
+
return validateEntry(schema, {
|
|
48
|
+
...entry,
|
|
49
|
+
data: file.data,
|
|
50
|
+
body: file.body
|
|
51
|
+
}, ctx);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates a set of writes against the state AFTER the changes. A schema change in the batch is parsed and used
|
|
55
|
+
* for the entries of the same batch; if it fails to parse only its issues are returned. `current.schema === null`
|
|
56
|
+
* means the schema on disk is broken: then only a change to the schema file is accepted.
|
|
57
|
+
*
|
|
58
|
+
* Changed entries are always validated. When `current.read` and `current.list` are given and the batch deletes a
|
|
59
|
+
* file or changes the schema, every other non-hidden `.md` file under the old or new `contentDir` is validated too,
|
|
60
|
+
* with the post-change schema and file set, and only issues it did not already have before the batch (same
|
|
61
|
+
* `path` + `message` under the pre-change schema and file set) are reported: deleting a referenced entry or image,
|
|
62
|
+
* or a schema change that breaks existing entries (or turns entries into non-entries), returns issues, while stray
|
|
63
|
+
* or already-broken files do not block unrelated changes. Without `read` / `list` unchanged entries are not
|
|
64
|
+
* re-validated, so a caller (e.g. the GitHub source) must pass both, or validate the whole project, for the same
|
|
65
|
+
* guarantee.
|
|
66
|
+
*/
|
|
67
|
+
function validateChanges(current, changes) {
|
|
68
|
+
const { schemaPath } = current;
|
|
69
|
+
const latest = /* @__PURE__ */ new Map();
|
|
70
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const change of changes) {
|
|
72
|
+
if (latest.has(change.path)) duplicates.add(change.path);
|
|
73
|
+
latest.set(change.path, change.content);
|
|
74
|
+
}
|
|
75
|
+
if (duplicates.size > 0) return [...duplicates].map((file) => ({
|
|
76
|
+
file,
|
|
77
|
+
path: "",
|
|
78
|
+
message: "Duplicate path in changes"
|
|
79
|
+
}));
|
|
80
|
+
let schema = current.schema;
|
|
81
|
+
if (latest.has(schemaPath)) {
|
|
82
|
+
const content = latest.get(schemaPath) ?? null;
|
|
83
|
+
if (content === null) return [{
|
|
84
|
+
file: schemaPath,
|
|
85
|
+
path: "",
|
|
86
|
+
message: "The schema file cannot be deleted"
|
|
87
|
+
}];
|
|
88
|
+
const decoded = decodeUtf8(content, schemaPath);
|
|
89
|
+
if ("issue" in decoded) return [decoded.issue];
|
|
90
|
+
try {
|
|
91
|
+
schema = parseSchemaText(decoded.text, schemaPath);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return issuesOf(error, schemaPath);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const issues = [];
|
|
97
|
+
if (current.schema === null) {
|
|
98
|
+
for (const path of latest.keys()) {
|
|
99
|
+
if (path === schemaPath) continue;
|
|
100
|
+
issues.push({
|
|
101
|
+
file: path,
|
|
102
|
+
path: "",
|
|
103
|
+
message: `The schema (${schemaPath}) is invalid; fix it first`
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return issues;
|
|
107
|
+
}
|
|
108
|
+
const prev = current.schema;
|
|
109
|
+
const effective = schema ?? prev;
|
|
110
|
+
const fileExists = (path) => latest.has(path) ? latest.get(path) !== null : current.exists(path);
|
|
111
|
+
const after = {
|
|
112
|
+
schema: effective,
|
|
113
|
+
fileExists,
|
|
114
|
+
entryExists: refExists(effective, fileExists)
|
|
115
|
+
};
|
|
116
|
+
for (const [path, content] of latest) {
|
|
117
|
+
if (path === schemaPath) continue;
|
|
118
|
+
if (!isWritablePath(effective, schemaPath, path)) {
|
|
119
|
+
issues.push({
|
|
120
|
+
file: path,
|
|
121
|
+
path: "",
|
|
122
|
+
message: "Path not writable"
|
|
123
|
+
});
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const parsed = content === null ? null : parseEntryPath(effective, path);
|
|
127
|
+
if (content !== null && parsed !== null) issues.push(...checkEntry(after, path, parsed, content));
|
|
128
|
+
}
|
|
129
|
+
const { read, list } = current;
|
|
130
|
+
if (!(latest.has(schemaPath) || [...latest.values()].includes(null)) || read === void 0 || list === void 0) return issues;
|
|
131
|
+
const before = {
|
|
132
|
+
schema: prev,
|
|
133
|
+
fileExists: current.exists,
|
|
134
|
+
entryExists: refExists(prev, current.exists)
|
|
135
|
+
};
|
|
136
|
+
for (const path of list()) {
|
|
137
|
+
if (latest.has(path) || path === schemaPath || !path.endsWith(".md")) continue;
|
|
138
|
+
const owner = [effective, prev].find((s) => path.startsWith(`${s.contentDir}/`));
|
|
139
|
+
if (owner === void 0 || isHiddenContentPath(owner, path)) continue;
|
|
140
|
+
const wasEntry = parseEntryPath(prev, path);
|
|
141
|
+
const isEntry = parseEntryPath(effective, path);
|
|
142
|
+
if (isEntry === null) {
|
|
143
|
+
if (wasEntry !== null) issues.push({
|
|
144
|
+
file: path,
|
|
145
|
+
path: "",
|
|
146
|
+
message: "Not an entry file"
|
|
147
|
+
});
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const text = read(path);
|
|
151
|
+
if (text === void 0) continue;
|
|
152
|
+
const known = new Set(wasEntry === null ? [] : checkEntry(before, path, wasEntry, text).map(issueKey));
|
|
153
|
+
issues.push(...checkEntry(after, path, isEntry, text).filter((i) => !known.has(issueKey(i))));
|
|
154
|
+
}
|
|
155
|
+
return issues;
|
|
156
|
+
}
|
|
157
|
+
/** `validateChanges` plus the commit-message rule shared by every `ContentSource.commit`. */
|
|
158
|
+
function validateCommit(current, changes, message) {
|
|
159
|
+
const issues = validateChanges(current, changes);
|
|
160
|
+
if (message.trim() === "") issues.push({
|
|
161
|
+
path: "",
|
|
162
|
+
message: "Commit message is required"
|
|
163
|
+
});
|
|
164
|
+
return issues;
|
|
165
|
+
}
|
|
166
|
+
export { isWritablePath, validateChanges, validateCommit };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// github/base64.ts
|
|
2
|
+
const CHUNK = 24576;
|
|
3
|
+
/** Standard base64 (with padding). Does not rely on `Uint8Array.prototype.toBase64`. */
|
|
4
|
+
function toBase64(bytes) {
|
|
5
|
+
let out = "";
|
|
6
|
+
for (let i = 0; i < bytes.length; i += CHUNK) out += btoa(String.fromCharCode(...bytes.subarray(i, i + CHUNK)));
|
|
7
|
+
return out;
|
|
8
|
+
}
|
|
9
|
+
/** Decodes standard base64; whitespace (GitHub wraps base64 at 60 columns) is ignored. */
|
|
10
|
+
function fromBase64(text) {
|
|
11
|
+
const binary = atob(text.replace(/\s+/g, ""));
|
|
12
|
+
const bytes = new Uint8Array(binary.length);
|
|
13
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
14
|
+
return bytes;
|
|
15
|
+
}
|
|
16
|
+
export { fromBase64, toBase64 };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface PendingChange {
|
|
2
|
+
path: string;
|
|
3
|
+
content: Uint8Array | string | null;
|
|
4
|
+
sha: string | null;
|
|
5
|
+
updatedAt: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PendingQueue {
|
|
8
|
+
list(): Promise<PendingChange[]>;
|
|
9
|
+
get(path: string): Promise<PendingChange | undefined>;
|
|
10
|
+
put(change: {
|
|
11
|
+
path: string;
|
|
12
|
+
content: Uint8Array | string | null;
|
|
13
|
+
sha: string | null;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
remove(paths: string[]): Promise<void>;
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface GitHubCache {
|
|
19
|
+
getBlobs(shas: string[]): Promise<Map<string, Uint8Array>>;
|
|
20
|
+
putBlobs(blobs: {
|
|
21
|
+
sha: string;
|
|
22
|
+
bytes: Uint8Array;
|
|
23
|
+
}[]): Promise<void>;
|
|
24
|
+
pending(scope: string): PendingQueue;
|
|
25
|
+
clear(): Promise<void>;
|
|
26
|
+
/** Releases the underlying database connection (no-op for the memory cache). */
|
|
27
|
+
close?(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function openGitHubCache(options?: {
|
|
30
|
+
name?: string;
|
|
31
|
+
indexedDB?: IDBFactory;
|
|
32
|
+
IDBKeyRange?: typeof IDBKeyRange;
|
|
33
|
+
}): GitHubCache;
|
|
34
|
+
export declare function createMemoryCache(): GitHubCache;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import Dexie from "dexie";
|
|
2
|
+
// github/cache.ts
|
|
3
|
+
const copyContent = (c) => c === null || typeof c === "string" ? c : new Uint8Array(c);
|
|
4
|
+
const toChange = (r) => ({
|
|
5
|
+
path: r.path,
|
|
6
|
+
content: copyContent(r.content),
|
|
7
|
+
sha: r.sha,
|
|
8
|
+
updatedAt: r.updatedAt
|
|
9
|
+
});
|
|
10
|
+
const byPath = (a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
11
|
+
function openGitHubCache(options = {}) {
|
|
12
|
+
if (!options.indexedDB && globalThis.indexedDB === void 0) return createMemoryCache();
|
|
13
|
+
const deps = options.indexedDB ? {
|
|
14
|
+
indexedDB: options.indexedDB,
|
|
15
|
+
IDBKeyRange: options.IDBKeyRange
|
|
16
|
+
} : {};
|
|
17
|
+
const db = new Dexie(options.name ?? "editlet-github", deps);
|
|
18
|
+
db.version(1).stores({
|
|
19
|
+
blobs: "sha",
|
|
20
|
+
pending: "[scope+path], scope"
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
async getBlobs(shas) {
|
|
24
|
+
const out = /* @__PURE__ */ new Map();
|
|
25
|
+
try {
|
|
26
|
+
const rows = await db.blobs.bulkGet(shas);
|
|
27
|
+
for (const row of rows) if (row) out.set(row.sha, new Uint8Array(row.bytes));
|
|
28
|
+
} catch {}
|
|
29
|
+
return out;
|
|
30
|
+
},
|
|
31
|
+
async putBlobs(blobs) {
|
|
32
|
+
try {
|
|
33
|
+
await db.blobs.bulkPut(blobs.map((b) => ({
|
|
34
|
+
sha: b.sha,
|
|
35
|
+
bytes: new Uint8Array(b.bytes)
|
|
36
|
+
})));
|
|
37
|
+
} catch {}
|
|
38
|
+
},
|
|
39
|
+
pending(scope) {
|
|
40
|
+
return {
|
|
41
|
+
async list() {
|
|
42
|
+
return (await db.pending.where("scope").equals(scope).toArray()).map(toChange).toSorted(byPath);
|
|
43
|
+
},
|
|
44
|
+
async get(path) {
|
|
45
|
+
const row = await db.pending.get([scope, path]);
|
|
46
|
+
return row ? toChange(row) : void 0;
|
|
47
|
+
},
|
|
48
|
+
async put(change) {
|
|
49
|
+
await db.pending.put({
|
|
50
|
+
scope,
|
|
51
|
+
path: change.path,
|
|
52
|
+
content: copyContent(change.content),
|
|
53
|
+
sha: change.sha,
|
|
54
|
+
updatedAt: Date.now()
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
async remove(paths) {
|
|
58
|
+
await db.pending.bulkDelete(paths.map((p) => [scope, p]));
|
|
59
|
+
},
|
|
60
|
+
async clear() {
|
|
61
|
+
await db.pending.where("scope").equals(scope).delete();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
async clear() {
|
|
66
|
+
await Promise.all([db.blobs.clear(), db.pending.clear()]);
|
|
67
|
+
},
|
|
68
|
+
async close() {
|
|
69
|
+
db.close();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function createMemoryCache() {
|
|
74
|
+
const blobs = /* @__PURE__ */ new Map();
|
|
75
|
+
const pending = /* @__PURE__ */ new Map();
|
|
76
|
+
const scopeMap = (scope) => {
|
|
77
|
+
let m = pending.get(scope);
|
|
78
|
+
if (!m) pending.set(scope, m = /* @__PURE__ */ new Map());
|
|
79
|
+
return m;
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
async getBlobs(shas) {
|
|
83
|
+
const out = /* @__PURE__ */ new Map();
|
|
84
|
+
for (const sha of shas) {
|
|
85
|
+
const b = blobs.get(sha);
|
|
86
|
+
if (b) out.set(sha, new Uint8Array(b));
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
},
|
|
90
|
+
async putBlobs(list) {
|
|
91
|
+
for (const b of list) blobs.set(b.sha, new Uint8Array(b.bytes));
|
|
92
|
+
},
|
|
93
|
+
pending(scope) {
|
|
94
|
+
return {
|
|
95
|
+
async list() {
|
|
96
|
+
return [...scopeMap(scope).values()].map(toChange).toSorted(byPath);
|
|
97
|
+
},
|
|
98
|
+
async get(path) {
|
|
99
|
+
const row = scopeMap(scope).get(path);
|
|
100
|
+
return row ? toChange(row) : void 0;
|
|
101
|
+
},
|
|
102
|
+
async put(change) {
|
|
103
|
+
scopeMap(scope).set(change.path, {
|
|
104
|
+
scope,
|
|
105
|
+
path: change.path,
|
|
106
|
+
content: copyContent(change.content),
|
|
107
|
+
sha: change.sha,
|
|
108
|
+
updatedAt: Date.now()
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
async remove(paths) {
|
|
112
|
+
const m = scopeMap(scope);
|
|
113
|
+
for (const p of paths) m.delete(p);
|
|
114
|
+
},
|
|
115
|
+
async clear() {
|
|
116
|
+
scopeMap(scope).clear();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
async clear() {
|
|
121
|
+
blobs.clear();
|
|
122
|
+
pending.clear();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export { createMemoryCache, openGitHubCache };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface GitHubClientOptions {
|
|
2
|
+
/** Token or getter (called per request, so a refreshed token is picked up). */
|
|
3
|
+
token: string | (() => string | Promise<string>);
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
sleep?: (ms: number) => Promise<void>;
|
|
6
|
+
now?: () => number;
|
|
7
|
+
}
|
|
8
|
+
export interface RestInit {
|
|
9
|
+
body?: unknown;
|
|
10
|
+
query?: Record<string, string | number | undefined>;
|
|
11
|
+
accept?: string;
|
|
12
|
+
raw?: boolean;
|
|
13
|
+
fresh?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface GitHubClient {
|
|
16
|
+
rest<T>(method: string, path: string, init?: RestInit): Promise<T>;
|
|
17
|
+
graphql<T>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
18
|
+
readonly sleep: (ms: number) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export type GitHubErrorCode = 'not_found' | 'rate_limited' | 'network_error' | 'branch_exists' | 'no_changes' | 'invalid_branch' | 'graphql_error' | 'http_error';
|
|
21
|
+
export interface GraphQLErrorItem {
|
|
22
|
+
type?: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class GitHubError extends Error {
|
|
26
|
+
code: GitHubErrorCode;
|
|
27
|
+
status?: number;
|
|
28
|
+
retryAt?: number;
|
|
29
|
+
graphqlErrors?: GraphQLErrorItem[];
|
|
30
|
+
constructor(code: GitHubErrorCode, message: string, extra?: {
|
|
31
|
+
status?: number;
|
|
32
|
+
retryAt?: number;
|
|
33
|
+
graphqlErrors?: GraphQLErrorItem[];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Encodes each segment of a ref/branch name, keeping `/`. */
|
|
37
|
+
export declare function encodeRef(name: string): string;
|
|
38
|
+
export declare function createGitHubClient(options: GitHubClientOptions): GitHubClient;
|