bearminion 1.14.0 → 1.16.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/content.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ContentModel, d as SectionOf, t as Page } from "./page-CwbIDegI.js";
1
+ import { d as SectionOf, g as ContentModel, t as Page } from "./page-D1pdneYm.js";
2
2
  import { z } from "zod";
3
3
  //#region src/content.d.ts
4
4
  export interface ContentCollectionsOptions {
package/dist/content.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as createPageSchema, r as createTolerantPageSchema } from "./page-wlcQJAA-.js";
2
2
  import { n as createMigrator } from "./migrate-b408EaLp.js";
3
- import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-BIIa7pej.js";
3
+ import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-BzVw721A.js";
4
4
  import { z } from "zod";
5
5
  import path from "node:path";
6
6
  import { pathToFileURL } from "node:url";
@@ -55,6 +55,15 @@ function draftImageUsages(src, drafts, labels) {
55
55
  }
56
56
  return usages;
57
57
  }
58
+ /** One validation issue per image path in `document` whose file does not exist. */
59
+ async function missingAssetIssues(document, exists) {
60
+ const refs = assetRefs(document);
61
+ const present = await Promise.all(refs.map((ref) => exists(ref.src)));
62
+ return refs.flatMap((ref, index) => present[index] ? [] : [{
63
+ path: ref.path,
64
+ message: `Image file not found: ${ref.src}. Choose another image or upload it again.`
65
+ }]);
66
+ }
58
67
  const PREFIX = "bearminion:draft:";
59
68
  /** Stable id so two projects served from localhost do not share drafts. */
60
69
  function projectId(root, siteName) {
@@ -233,4 +242,4 @@ function reloadDecision(input) {
233
242
  return "reload";
234
243
  }
235
244
  //#endregion
236
- export { isAssetPath as S, writeSaveNotice as _, localDraftStorage as a, describeSiteRef as b, projectId as c, removeDraft as d, savedNoticeFor as f, writeDraftRecord as g, sweepExpiredDrafts as h, isForeignSave as i, readDraftRecord as l, siteSavedKey as m, draftBannerText as n, pageDraftKey as o, siteDraftKey as p, hashText as r, pageSavedKey as s, assessStoredDraft as t, reloadDecision as u, assetRefs as v, draftImageUsages as x, describePageRef as y };
245
+ export { missingAssetIssues as C, isAssetPath as S, writeSaveNotice as _, localDraftStorage as a, describeSiteRef as b, projectId as c, removeDraft as d, savedNoticeFor as f, writeDraftRecord as g, sweepExpiredDrafts as h, isForeignSave as i, readDraftRecord as l, siteSavedKey as m, draftBannerText as n, pageDraftKey as o, siteDraftKey as p, hashText as r, pageSavedKey as s, assessStoredDraft as t, reloadDecision as u, assetRefs as v, draftImageUsages as x, describePageRef as y };
@@ -0,0 +1,310 @@
1
+ import { _ as SectionRegistry, ht as SiteDefinition, n as PageRules, w as ContentMigrator, y as ThemeDefinition } from "./page-D1pdneYm.js";
2
+ import { ZodType, z } from "zod";
3
+ //#region src/upload-names.d.ts
4
+ type ImageKind = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
5
+ //#endregion
6
+ //#region src/image-sniff.d.ts
7
+ interface SavedImage {
8
+ filename: string;
9
+ path: string;
10
+ bytes: number;
11
+ }
12
+ interface ListedImage {
13
+ filename: string;
14
+ path: string;
15
+ }
16
+ //#endregion
17
+ //#region src/video-sniff.d.ts
18
+ type VideoKind = 'mp4' | 'mov' | 'webm' | 'ogv';
19
+ interface SavedVideo {
20
+ filename: string;
21
+ /** Project-relative path of the file. */
22
+ path: string;
23
+ /** What a Media section's `video` field holds: the file's address on the site, such as `/videos/demo-1a2b.mp4`. */
24
+ url: string;
25
+ bytes: number;
26
+ }
27
+ type ListedVideo = Omit<SavedVideo, 'bytes'> & {
28
+ bytes?: number;
29
+ };
30
+ //#endregion
31
+ //#region src/store-core.d.ts
32
+ /**
33
+ * Where the editor reads and writes content. The editor API talks only to this interface, so the
34
+ * place the files live is a choice: {@link createFileStore} uses the local project, and another
35
+ * implementation (a Git host's API, say) can stand in without touching the API handlers.
36
+ *
37
+ * Keys are `/`-separated paths relative to the content directory: `site.json`, `pages/about.json`. A key with a
38
+ * leading slash is relative to the project root instead (`/src/content/blog/en/post.md`), for files that live outside
39
+ * the content directory, such as Markdown collections. See {@link repoKey}.
40
+ * Values are text. Parsing, validation and the JSON layout belong to the caller.
41
+ *
42
+ * Not part of the store: undo history (local editor state in `.editor/`), `Commit changes`
43
+ * (needs a local git work tree), and the loaders that run at build time.
44
+ */
45
+ interface ContentStore {
46
+ /** The text at `key`, or `undefined` when there is none. */
47
+ read(key: string): Promise<string | undefined>;
48
+ exists(key: string): Promise<boolean>;
49
+ /** Names of the files directly inside the directory `dir`, sorted, or `undefined` when it does not exist. */
50
+ list(dir: string): Promise<string[] | undefined>;
51
+ /**
52
+ * Apply changes that belong together, such as a rename (write the new file, remove the old one).
53
+ * Writes run before removals, so a failure never leaves the content with a page missing. An
54
+ * implementation that can make the whole batch atomic (one commit) should.
55
+ */
56
+ apply(operations: readonly StoreOperation[]): Promise<void>;
57
+ /** Uploaded images. */
58
+ readonly uploads: UploadStore;
59
+ /** Uploaded videos, served from `public/`. Absent in stores that only hold images. */
60
+ readonly videos?: VideoStore;
61
+ /**
62
+ * Whether the image file an image field points at (`src/assets/...`) exists. Saves that point at a missing file
63
+ * fail validation. A store without it skips that check.
64
+ */
65
+ assetExists?(src: string): Promise<boolean>;
66
+ /**
67
+ * A view of the store for editing one entry (`page:about`, `site`), for stores that keep each entry's pending edits
68
+ * apart, such as `githubStore` in `pr` mode, where every scope is a branch and a pull request. Reads see the entry's
69
+ * pending edits, writes go to them. Absent when every write goes to the same place.
70
+ */
71
+ scoped?(scope: string): ContentStore;
72
+ }
73
+ type StoreOperation = {
74
+ type: 'write';
75
+ key: string;
76
+ text: string;
77
+ } | {
78
+ type: 'remove';
79
+ key: string;
80
+ };
81
+ interface UploadStore {
82
+ list(): Promise<ListedImage[]>;
83
+ /** Store the bytes under a unique, sanitised name and return where it went. `path` is what image fields hold. */
84
+ save(input: {
85
+ originalName: string;
86
+ bytes: Uint8Array;
87
+ kind: ImageKind;
88
+ }): Promise<SavedImage>;
89
+ /** Delete one upload by file name. False when there is no such upload. */
90
+ remove(filename: string): Promise<boolean>;
91
+ }
92
+ interface VideoStore {
93
+ list(): Promise<ListedVideo[]>;
94
+ save(input: {
95
+ originalName: string;
96
+ bytes: Uint8Array;
97
+ kind: VideoKind;
98
+ }): Promise<SavedVideo>;
99
+ remove(filename: string): Promise<boolean>;
100
+ }
101
+ //#endregion
102
+ //#region src/collections.d.ts
103
+ /** What a collection's `schema` may be: a Zod schema, or Astro's factory form `({ image }) => schema`. */
104
+ type CollectionSchema = ZodType | ((helpers: {
105
+ image: () => ZodType;
106
+ }) => ZodType);
107
+ interface CollectionOptions {
108
+ /**
109
+ * The same schema the site's `content.config.ts` uses, imported from a plain module (no `astro:content`). A site that
110
+ * uses Astro's `image()` writes the factory form `({ image }) => z.object({ cover: image().optional() })`.
111
+ */
112
+ schema: CollectionSchema;
113
+ /** Where the files are, from the project root, with `{slug}` as the file name: `src/content/blog/en/{slug}.md`. */
114
+ path: string;
115
+ /** Shown in the editor. Default: the collection's id. */
116
+ label?: string;
117
+ /** Allow changing an entry's slug, which changes its address. Default false. */
118
+ rename?: boolean;
119
+ /** Allow deleting entries. Default false. */
120
+ delete?: boolean;
121
+ }
122
+ interface Collection {
123
+ id: string;
124
+ label: string;
125
+ /** The folder of the files, from the project root, without a trailing slash. */
126
+ dir: string;
127
+ ext: '.md' | '.mdx';
128
+ schema: ZodType;
129
+ rename: boolean;
130
+ delete: boolean;
131
+ }
132
+ /** Declares a collection. Checks the options now, so a typo fails when the config loads, not on the first save. */
133
+ declare function collection(options: CollectionOptions): CollectionOptions;
134
+ //#endregion
135
+ //#region src/git-types.d.ts
136
+ type ChangeStatus = 'added' | 'modified' | 'deleted' | 'renamed' | 'untracked';
137
+ interface ChangedFile {
138
+ /** Path relative to the project root, with `/` separators. */
139
+ path: string;
140
+ status: ChangeStatus;
141
+ }
142
+ interface GitInfo {
143
+ /** The `git` option is on. */
144
+ enabled: boolean;
145
+ /** The project is inside a git work tree. */
146
+ repo: boolean;
147
+ branch?: string;
148
+ files: ChangedFile[];
149
+ }
150
+ /** What the editor needs from a version-control backend. Absent on the context means Commit changes is off. */
151
+ interface GitPort {
152
+ info(): Promise<GitInfo>;
153
+ commit(message: string, paths?: readonly string[]): Promise<{
154
+ commit: string;
155
+ files: number;
156
+ }>;
157
+ }
158
+ //#endregion
159
+ //#region src/api-types.d.ts
160
+ /**
161
+ * Request and response bodies of the dev editor API (`/__bearminion/api`). The server handlers and the
162
+ * overlay's client both use these, so a changed shape is a type error on both sides.
163
+ */
164
+ /** Every error response. `issues` is present on schema validation failures. */
165
+ interface ApiProblem {
166
+ error: string;
167
+ message: string;
168
+ issues?: ApiIssue[];
169
+ }
170
+ /** One validation failure: a dotted path into the document and a message. */
171
+ interface ApiIssue {
172
+ path: string;
173
+ message: string;
174
+ /** Present on `POST /save`, which validates the page and the site together. */
175
+ file?: 'page' | 'site';
176
+ }
177
+ /** `GET /pages`. */
178
+ interface PageListItem {
179
+ slug: string;
180
+ title: string;
181
+ /** File name inside the pages directory. */
182
+ file: string;
183
+ system?: boolean;
184
+ anchors?: string[];
185
+ }
186
+ /** `GET /images` entries and the body of a successful `POST /images`. */
187
+ interface UploadedImage {
188
+ filename: string;
189
+ /** Project-relative path, the value image fields store. */
190
+ path: string;
191
+ bytes?: number;
192
+ }
193
+ /** `GET /videos` entries and the body of a successful `POST /videos`. */
194
+ interface UploadedVideo {
195
+ filename: string;
196
+ /** Project-relative path of the file. */
197
+ path: string;
198
+ /** What a Media section's `video` field holds, such as `/videos/demo-1a2b3c4d.mp4`. */
199
+ url: string;
200
+ bytes?: number;
201
+ }
202
+ /** `GET /history/site` and `GET /history/pages/:slug` entries. */
203
+ interface HistoryEntry {
204
+ id: string;
205
+ at: string;
206
+ }
207
+ /** `POST /save`. At least one of `page` and `site`. */
208
+ interface SaveRequest<TPage = unknown, TSite = unknown> {
209
+ page?: {
210
+ /** Slug the page is stored under now. When `document.slug` differs, the page is renamed (or made home). */
211
+ from: string;
212
+ document: TPage;
213
+ /** Where the current home page moves when this page becomes `index`. Required when a home page exists. */
214
+ previousHomeSlug?: string;
215
+ };
216
+ site?: TSite;
217
+ }
218
+ /** `POST /save` response: the documents as stored. */
219
+ interface SaveResponse<TPage = unknown, TSite = unknown> {
220
+ page?: TPage;
221
+ site?: TSite;
222
+ }
223
+ /** `POST /pages`. `template` is a section type or the slug of a page to copy. */
224
+ interface CreatePageRequest {
225
+ slug: string;
226
+ title: string;
227
+ template?: string;
228
+ }
229
+ /** `POST /git/commit`. */
230
+ interface CommitRequest {
231
+ message: string;
232
+ paths?: string[];
233
+ }
234
+ interface CommitResult {
235
+ commit: string;
236
+ files: number;
237
+ }
238
+ /** `POST /preview/site`. */
239
+ interface SitePreview {
240
+ header: string;
241
+ footer: string;
242
+ }
243
+ //#endregion
244
+ //#region src/history-types.d.ts
245
+ type HistoryScope = 'page' | 'site';
246
+ /** Local copies of what was saved, so an earlier version can be loaded back into the draft. */
247
+ interface HistoryPort {
248
+ /** Newest first. */
249
+ list(scope: HistoryScope, slug?: string): Promise<HistoryEntry[]>;
250
+ read(scope: HistoryScope, slug: string, id: string): Promise<unknown | null>;
251
+ /** Never throws: history must not block a save. */
252
+ write(scope: HistoryScope, slug: string, value: unknown): Promise<void>;
253
+ /** Before the first save of a page or the site, keep the file as it was so even that first save can be undone. */
254
+ ensureBaseline(scope: HistoryScope, slug: string, current: unknown): Promise<void>;
255
+ }
256
+ //#endregion
257
+ //#region src/upload-rules.d.ts
258
+ /** Re-encode uploads in the browser before they are sent. */
259
+ interface ImageConvertOptions {
260
+ to: 'webp';
261
+ /** Wider images are scaled down to this width, never up. Default: no width cap. */
262
+ maxWidth?: number;
263
+ /** WebP quality, 0.1 to 1. Default 0.82. */
264
+ quality?: number;
265
+ }
266
+ /** What the browser needs to know before it sends a file. */
267
+ interface UploadRules {
268
+ maxBytes: number;
269
+ convert: {
270
+ to: 'webp';
271
+ maxWidth: number | null;
272
+ quality: number;
273
+ } | null;
274
+ }
275
+ //#endregion
276
+ //#region src/editor-context.d.ts
277
+ interface EditorContext {
278
+ root: string;
279
+ contentDir: string;
280
+ uploadsDir: string;
281
+ videosDir: string;
282
+ maxVideoBytes: number;
283
+ maxImageBytes: number;
284
+ pageRules: PageRules;
285
+ /** `imageConvert`, validated and with its defaults filled in. `null` when conversion is off. */
286
+ imageConvert: UploadRules['convert'];
287
+ sections: SectionRegistry;
288
+ site: SiteDefinition;
289
+ theme: ThemeDefinition;
290
+ store: ContentStore;
291
+ /** Upgrades files written under an older `schemaVersion` and stamps the current one on write. */
292
+ migrator: ContentMigrator;
293
+ /** Commit changes is enabled. */
294
+ git: boolean;
295
+ /** Markdown collections the editor can edit, by id. Absent when the site has none. */
296
+ collections?: Record<string, Collection>;
297
+ /** The folder with the site's form handlers, or `null` when the `forms` option turns them off. */
298
+ formsDir?: string | null;
299
+ /**
300
+ * Undo history. The local editor keeps copies of what was saved in `.editor/history/`; a hosted editor has none,
301
+ * because the repository is the history.
302
+ */
303
+ history?: HistoryPort;
304
+ /** Commit changes, when `git` is on and the project is a local git work tree. */
305
+ commits?: GitPort;
306
+ /** The file of the form handler `name` in the site, or `null` when there is none. Local projects only. */
307
+ formFile?: (name: string) => string | null;
308
+ }
309
+ //#endregion
310
+ export { CollectionOptions as _, CommitRequest as a, StoreOperation as b, HistoryEntry as c, SaveResponse as d, SitePreview as f, GitInfo as g, ChangedFile as h, ApiProblem as i, PageListItem as l, UploadedVideo as m, ImageConvertOptions as n, CommitResult as o, UploadedImage as p, ApiIssue as r, CreatePageRequest as s, EditorContext as t, SaveRequest as u, collection as v, UploadStore as x, ContentStore as y };
@@ -1,4 +1,4 @@
1
- import { s as resolveDir } from "./security-FLvgc2jD.js";
1
+ import { r as resolveDir } from "./security-CBiOYdVE.js";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { parseEnv } from "node:util";
@@ -0,0 +1,64 @@
1
+ import { y as ContentStore } from "./editor-context-BBsL5NFx.js";
2
+ //#region src/store-error.d.ts
3
+ /** A key that is empty, has an empty or dot segment, or leaves its base directory. */
4
+ declare class StoreKeyError extends Error {
5
+ constructor(key: string);
6
+ }
7
+ /**
8
+ * A store that could not do what was asked, for a reason the person editing can act on (a refused token, a protected
9
+ * branch, a branch that moved). The editor API answers it with `status` and `code`, so the message reaches the page
10
+ * instead of becoming a bare 500.
11
+ */
12
+ declare class StoreError extends Error {
13
+ readonly status: number;
14
+ readonly code: string;
15
+ constructor(status: number, code: string, message: string);
16
+ }
17
+ //#endregion
18
+ //#region src/github-store.d.ts
19
+ interface GithubStoreOptions {
20
+ /** `owner/name`. */
21
+ repo: string;
22
+ /**
23
+ * A token that may write to the repository: a fine-grained personal access token with "Contents: Read and write" on
24
+ * this one repository. Keep it in the environment, never in a file the repository tracks.
25
+ */
26
+ token: string;
27
+ /** The branch edits are committed to. Default: the repository's default branch. */
28
+ branch?: string;
29
+ /** The folder of the site inside the repository. Default: the repository root. */
30
+ rootDir?: string;
31
+ /** The content folder, relative to `rootDir`. Default `content`. */
32
+ contentDir?: string;
33
+ /** The folder uploaded images go to, relative to `rootDir`. Default `src/assets/uploads`. */
34
+ uploadsDir?: string;
35
+ /** The commit message for a change. Default: `Update pages/about.json`, `Update 3 files`, `Upload photo-1a2b3c4d.jpg`. */
36
+ message?: (change: {
37
+ written: readonly string[];
38
+ removed: readonly string[];
39
+ }) => string;
40
+ /**
41
+ * `direct` (default): a save is a commit on `branch`. `pr`: a save is a commit on a branch of its own for the entry
42
+ * being edited, with a pull request opened on the first save. Nothing here ever merges. Needs "Pull requests: Read
43
+ * and write" besides "Contents: Read and write".
44
+ */
45
+ mode?: 'direct' | 'pr';
46
+ /** `pr` mode: the title and body of the pull request opened for an entry. */
47
+ pullRequest?: (change: {
48
+ scope: string;
49
+ written: readonly string[];
50
+ removed: readonly string[];
51
+ }) => {
52
+ title: string;
53
+ body: string;
54
+ };
55
+ /** `pr` mode: the label put on the pull requests. Default `bearminion`; `false` for none. */
56
+ label?: string | false;
57
+ /** The GitHub API. Default `https://api.github.com`. Set it for GitHub Enterprise. */
58
+ apiUrl?: string;
59
+ /** Default: the global `fetch`. */
60
+ fetch?: typeof fetch;
61
+ }
62
+ declare function githubStore(options: GithubStoreOptions): ContentStore;
63
+ //#endregion
64
+ export { StoreKeyError as i, githubStore as n, StoreError as r, GithubStoreOptions as t };