astronaut-cms 0.0.1 → 1.0.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 +84 -3
- package/dist/admin/THIRD_PARTY_LICENSES.md +7598 -0
- package/dist/admin/assets/assistant-DkS355co.js +201 -0
- package/dist/admin/assets/badge-BXsOvOPX.js +1 -0
- package/dist/admin/assets/changes-Ba0G_GN1.js +1 -0
- package/dist/admin/assets/client-VKp75fDU.js +5 -0
- package/dist/admin/assets/clsx-DB0hHKMi.js +1 -0
- package/dist/admin/assets/collapsible-B6P_J0Bg.js +1 -0
- package/dist/admin/assets/collapsible-item-UaoJaaPw.js +1 -0
- package/dist/admin/assets/collections._collection-BE1enDCq.js +1 -0
- package/dist/admin/assets/collections._collection._entry-D3UksnCo.js +52 -0
- package/dist/admin/assets/collections._collection.index-BN5d8UIY.js +1 -0
- package/dist/admin/assets/component-lookup-CUCiK8Xh.js +4 -0
- package/dist/admin/assets/config-Pm_BHLNT.js +1 -0
- package/dist/admin/assets/copy-DezZzPMV.js +1 -0
- package/dist/admin/assets/css-BGIxQoYs.js +1 -0
- package/dist/admin/assets/css-DgaLhXQH.js +1 -0
- package/dist/admin/assets/diff-woXpYk--.js +1 -0
- package/dist/admin/assets/dist-DzkcSBZl.js +1 -0
- package/dist/admin/assets/dist-UbA1s2kM.js +1 -0
- package/dist/admin/assets/docx-BctAmX91.js +56 -0
- package/dist/admin/assets/editor-FGqMznBK.js +2 -0
- package/dist/admin/assets/empty-DSBYiI_7.js +1 -0
- package/dist/admin/assets/entry-link-CQLN2Zpf.js +158 -0
- package/dist/admin/assets/error-banner-yskeRXe8.js +159 -0
- package/dist/admin/assets/errors-DkJ5E_ak.js +1 -0
- package/dist/admin/assets/field-BDK5tt3J.js +41 -0
- package/dist/admin/assets/field-schema-CacrjSYw.js +1 -0
- package/dist/admin/assets/file-text-BzBif8ui.js +1 -0
- package/dist/admin/assets/github-dark-C-LZuMrd.js +1 -0
- package/dist/admin/assets/github-light-EUqPIrTm.js +1 -0
- package/dist/admin/assets/highlighted-body-JLMTFACH-CIQujGv2.js +1 -0
- package/dist/admin/assets/html-CvFb5cGI.js +1 -0
- package/dist/admin/assets/javascript-BzbQS41l.js +1 -0
- package/dist/admin/assets/javascript-CpIGwZ_Y.js +1 -0
- package/dist/admin/assets/json-qhed-kSA.js +1 -0
- package/dist/admin/assets/jsx-Bz0zcwM4.js +1 -0
- package/dist/admin/assets/lib-CMURo-7A.js +21 -0
- package/dist/admin/assets/library-Cr3f75Es.js +1 -0
- package/dist/admin/assets/list-skeleton-BdTNfVXs.js +1 -0
- package/dist/admin/assets/markdown-BYOwaDjH.js +1 -0
- package/dist/admin/assets/matchContext-Bq5Es9aD.js +2 -0
- package/dist/admin/assets/media-browser-9-CPTCks.js +1 -0
- package/dist/admin/assets/media._library-BfFaEZLR.js +1 -0
- package/dist/admin/assets/mermaid-WFAXDIZX-CJ3hhA0i.js +1 -0
- package/dist/admin/assets/page-header-B4nvAsVA.js +1 -0
- package/dist/admin/assets/pdf-DgessaF0.js +106 -0
- package/dist/admin/assets/python-gzcpVVnB.js +1 -0
- package/dist/admin/assets/react-kbcsfQYH.js +1 -0
- package/dist/admin/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
- package/dist/admin/assets/routes-CBt04sNR.js +1 -0
- package/dist/admin/assets/routes-D7tEdYGV.js +1 -0
- package/dist/admin/assets/save-actions-Cz0TkpcP.js +32 -0
- package/dist/admin/assets/select-Bv2EoLhN.js +1 -0
- package/dist/admin/assets/separator-DlYj_PoQ.js +3 -0
- package/dist/admin/assets/shell-DBEiq06l.js +1 -0
- package/dist/admin/assets/shellscript-CLZ0U2zV.js +1 -0
- package/dist/admin/assets/skeleton-CKiqTaRh.js +1 -0
- package/dist/admin/assets/sql-CEbI0hMM.js +1 -0
- package/dist/admin/assets/syntax-BAXqRKRO.js +8 -0
- package/dist/admin/assets/toggle-Y2UpJZyU.js +1 -0
- package/dist/admin/assets/toml-BPTmHmyx.js +1 -0
- package/dist/admin/assets/tsx-udAQXfEw.js +1 -0
- package/dist/admin/assets/typescript-bsJCZSQ-.js +1 -0
- package/dist/admin/assets/ui.module.css-WaO_77ml.js +56 -0
- package/dist/admin/assets/use-entries-B2lsaiK9.js +1 -0
- package/dist/admin/assets/useSelector-CWr3iU9K.js +1 -0
- package/dist/admin/assets/yaml-rwi0_p6S.js +1 -0
- package/dist/admin/assets/zwitch-Wwuax-dJ.js +1 -0
- package/dist/admin/bootstrap.d.ts +1 -0
- package/dist/admin/bootstrap.js +1 -0
- package/dist/admin/editor.d.ts +57 -0
- package/dist/admin/editor.js +1 -0
- package/dist/server/assets.d.ts +2 -0
- package/dist/server/assets.js +30 -0
- package/dist/server/chunks/anchors-DuZ1fokt.js +86 -0
- package/dist/server/chunks/auth-DJP9ryVd.js +44 -0
- package/dist/server/chunks/cms-markers-CUqrOnfA.js +78 -0
- package/dist/server/chunks/component-lookup-DAFg_Qg8.js +128 -0
- package/dist/server/chunks/config-WQqG4mNH.d.ts +193 -0
- package/dist/server/chunks/digest-BYzWNJea.js +753 -0
- package/dist/server/chunks/entry-checks-CKMag1G4.js +608 -0
- package/dist/server/chunks/field-schema-CfdN75jT.js +48 -0
- package/dist/server/chunks/http-BnsNh57m.d.ts +35 -0
- package/dist/server/chunks/i18n-BPmx7ESy.d.ts +15 -0
- package/dist/server/chunks/index-CYbkNvu5.d.ts +22 -0
- package/dist/server/chunks/media-BhqUVVYY.js +223 -0
- package/dist/server/chunks/paths-CEW9fvg8.js +17 -0
- package/dist/server/chunks/paths-Dztx2eUw.js +13 -0
- package/dist/server/chunks/types-DOR5XaJO.js +397 -0
- package/dist/server/chunks/types-Dkx4Xovf.d.ts +359 -0
- package/dist/server/chunks/types-DwA-C6Br.d.ts +266 -0
- package/dist/server/chunks/user-config-DoypbpQf.js +283 -0
- package/dist/server/chunks/xml-D8qPILJU.js +81 -0
- package/dist/server/config.d.ts +3 -0
- package/dist/server/config.js +18 -0
- package/dist/server/content.d.ts +48 -0
- package/dist/server/content.js +89 -0
- package/dist/server/endpoint.d.ts +11 -0
- package/dist/server/endpoint.js +2712 -0
- package/dist/server/integration.d.ts +7 -0
- package/dist/server/integration.js +1174 -0
- package/dist/server/internal.d.ts +65 -0
- package/dist/server/internal.js +30 -0
- package/dist/server/server-local.d.ts +453 -0
- package/dist/server/server-local.js +336 -0
- package/dist/styles/THIRD_PARTY_LICENSES.md +193 -0
- package/dist/styles/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/styles/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/styles/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/styles/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/styles/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/styles/styles.css +3 -0
- package/package.json +151 -5
- package/src/astro/Image.astro +28 -0
- package/src/astro/Video.astro +44 -0
- package/src/astro/admin.astro +137 -0
- package/src/astro/licenses.ts +5 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { m as DescribedComponent, t as AssertNever } from "./chunks/types-DwA-C6Br.js";
|
|
2
|
+
import { _ as EditorExports, a as ComponentDefinition, g as referenceMarker, o as ComponentIcon, r as CollectionOptions, u as ImageResolver, v as JsxEditor } from "./chunks/config-WQqG4mNH.js";
|
|
3
|
+
import { t as ContentI18n } from "./chunks/i18n-BPmx7ESy.js";
|
|
4
|
+
import { n as HARDENING_HEADERS } from "./chunks/http-BnsNh57m.js";
|
|
5
|
+
import { z, z as z$1 } from "zod";
|
|
6
|
+
import * as AstroContentConfig from "astro/content/config";
|
|
7
|
+
import * as AstroLoaders from "astro/loaders";
|
|
8
|
+
type AstroGlobOptions = Parameters<typeof AstroLoaders.glob>[0];
|
|
9
|
+
/**
|
|
10
|
+
* Shape captured by the `glob`/`file` loader stubs. `load-config.ts` reads
|
|
11
|
+
* these fields back to recover the loader's pattern/base/file name.
|
|
12
|
+
*/
|
|
13
|
+
export interface LoaderMarker {
|
|
14
|
+
__cmsPattern?: string | string[] | null;
|
|
15
|
+
__cmsBase?: string | URL | null;
|
|
16
|
+
__cmsFileName?: string | null;
|
|
17
|
+
__cmsCustomParser?: true;
|
|
18
|
+
__cmsCustomId?: true;
|
|
19
|
+
}
|
|
20
|
+
export declare function defineCollection<T>(config: T): T;
|
|
21
|
+
export declare function glob(options: Pick<AstroGlobOptions, "pattern" | "base" | "generateId">): LoaderMarker;
|
|
22
|
+
export declare function file(fileName: Parameters<typeof AstroLoaders.file>[0], options?: Parameters<typeof AstroLoaders.file>[1]): LoaderMarker;
|
|
23
|
+
export type AllLoadersStubbed = AssertNever<Exclude<keyof typeof AstroLoaders, "glob" | "file">>;
|
|
24
|
+
export type AllContentHelpersStubbed = AssertNever<Exclude<keyof typeof AstroContentConfig, "defineCollection" | "defineLiveCollection">>;
|
|
25
|
+
export declare const NestedLexicalEditor: EditorExports["NestedLexicalEditor"];
|
|
26
|
+
export declare const useMdastNodeUpdater: EditorExports["useMdastNodeUpdater"];
|
|
27
|
+
export declare const useLexicalNodeRemove: EditorExports["useLexicalNodeRemove"];
|
|
28
|
+
export interface ClientComponentDef extends DescribedComponent {
|
|
29
|
+
icon: ComponentIcon | null;
|
|
30
|
+
editor: JsxEditor | null;
|
|
31
|
+
}
|
|
32
|
+
export type ComponentManifest = Record<string, ClientComponentDef>;
|
|
33
|
+
/**
|
|
34
|
+
* An MDX body refers to a component by its name alone, so one name may stand
|
|
35
|
+
* for one definition only. A child set may reuse a definition under the same name.
|
|
36
|
+
* `i18n` lays out the `localized()` props, see {@link zodToFieldSchema}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function processUserConfig(components: Record<string, ComponentDefinition> | undefined, i18n: ContentI18n | null): ComponentManifest;
|
|
39
|
+
/** The collections' icons by name, the one option the manifest cannot carry, being live components. */
|
|
40
|
+
export declare function processCollectionIcons(collections: Record<string, CollectionOptions> | undefined): Record<string, ComponentIcon>;
|
|
41
|
+
/**
|
|
42
|
+
* Parses a component's attributes by its name, so every `.default()` and
|
|
43
|
+
* transform applies, and keeps any attribute the schema does not declare, such
|
|
44
|
+
* as `class`. Every `image()` prop is resolved with `resolveImage` on the way,
|
|
45
|
+
* so a component receives its images as a collection's `image()` field arrives:
|
|
46
|
+
* as `ImageMetadata`, or an object-store URL. MDX hands a component its
|
|
47
|
+
* attributes verbatim, which is why the generated wrappers run this before
|
|
48
|
+
* rendering it. Every schema is built once.
|
|
49
|
+
*/
|
|
50
|
+
export declare function propsResolver(components: Record<string, ComponentDefinition>, resolveImage: ImageResolver): (name: string, props: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
51
|
+
type UnionToIntersection<U> = [U] extends [never] ? unknown : (U extends unknown ? (union: U) => void : never) extends ((intersection: infer I) => void) ? I : never;
|
|
52
|
+
/** Which side of the schema to read: as MDX writes the props, or as the component renders them. */
|
|
53
|
+
type PropsSide = "input" | "output";
|
|
54
|
+
type ChildProps<Definition, Side extends PropsSide> = Definition extends ComponentDefinition<z$1.ZodType<object>, infer C> ? [C] extends [never] ? never : [C] extends [Record<string, ComponentDefinition>] ? InferComponentProps<C, Side> : never : never;
|
|
55
|
+
type SideOf<T extends z$1.ZodType, Side extends PropsSide> = Side extends "input" ? z$1.input<T> : z$1.output<T>;
|
|
56
|
+
type SchemaProps<T extends z$1.ZodType<object>, Side extends PropsSide> = T extends z$1.ZodObject<infer Shape> ? [keyof Shape] extends [never] ? Record<never, never> : SideOf<T, Side> : SideOf<T, Side>;
|
|
57
|
+
/**
|
|
58
|
+
* The props of every component by name, the children of each included. The
|
|
59
|
+
* output is what a component renders with, every default applied, and the
|
|
60
|
+
* input what MDX writes, where a prop with a `.default()` is optional.
|
|
61
|
+
*/
|
|
62
|
+
type InferComponentProps<Components extends Record<string, ComponentDefinition>, Side extends PropsSide = "output"> = { [Name in string & keyof Components]: Components[Name] extends ComponentDefinition<infer T> ? SchemaProps<T, Side> : never; } & UnionToIntersection<{ [Name in keyof Components]: ChildProps<Components[Name], Side>; }[keyof Components]>;
|
|
63
|
+
/** The element the shell renders and the admin mounts into, carrying the site's routing. */
|
|
64
|
+
export declare const ADMIN_ROOT_ID = "astronaut-cms-root";
|
|
65
|
+
export { HARDENING_HEADERS, type InferComponentProps, referenceMarker as reference, z };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { o as referenceMarker } from "./chunks/cms-markers-CUqrOnfA.js";
|
|
2
|
+
import { n as processUserConfig, r as propsResolver, t as processCollectionIcons } from "./chunks/user-config-DoypbpQf.js";
|
|
3
|
+
import { a as HARDENING_HEADERS } from "./chunks/component-lookup-DAFg_Qg8.js";
|
|
4
|
+
import { t as ADMIN_ROOT_ID } from "./chunks/auth-DJP9ryVd.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/internal/loader-stubs.ts
|
|
7
|
+
function defineCollection(config) {
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
function glob(options) {
|
|
11
|
+
return {
|
|
12
|
+
__cmsPattern: options.pattern,
|
|
13
|
+
__cmsBase: options.base ?? ".",
|
|
14
|
+
...options.generateId && { __cmsCustomId: true }
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function file(fileName, options) {
|
|
18
|
+
return {
|
|
19
|
+
__cmsFileName: fileName ?? null,
|
|
20
|
+
...options?.parser && { __cmsCustomParser: true }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// src/internal/editor-stubs.ts
|
|
24
|
+
var adminOnly = () => {
|
|
25
|
+
throw new Error("astronaut-cms/editor only runs in the admin.");
|
|
26
|
+
};
|
|
27
|
+
var NestedLexicalEditor = adminOnly;
|
|
28
|
+
var useMdastNodeUpdater = adminOnly;
|
|
29
|
+
var useLexicalNodeRemove = adminOnly;
|
|
30
|
+
export { ADMIN_ROOT_ID, HARDENING_HEADERS, NestedLexicalEditor, defineCollection, file, glob, processCollectionIcons, processUserConfig, propsResolver, referenceMarker as reference, useLexicalNodeRemove, useMdastNodeUpdater, z };
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { a as EntryContent, c as FileChange, d as SaveEntryRequest, f as TrashedFile, l as FileCollectionInfo, n as CollectionManifest, o as EntryFormat, p as ComponentSchemaMap, r as CollectionManifestEntry, s as EntryMeta, u as MediaFile } from "./chunks/types-DwA-C6Br.js";
|
|
2
|
+
import { r as PartialContent, t as ByteRange } from "./chunks/http-BnsNh57m.js";
|
|
3
|
+
import { a as ResolvedImageOptimization } from "./chunks/types-Dkx4Xovf.js";
|
|
4
|
+
import "yaml";
|
|
5
|
+
type MediaLibraryId = "repo" | "s3";
|
|
6
|
+
/** Bounds on a file's size in bytes, null where there is none. */
|
|
7
|
+
interface SizeLimits {
|
|
8
|
+
minFileSize: number | null;
|
|
9
|
+
maxFileSize: number | null;
|
|
10
|
+
}
|
|
11
|
+
/** What decides which files a library takes, and how an image is reshaped on the way in. */
|
|
12
|
+
interface ClientLibrary extends SizeLimits {
|
|
13
|
+
/** Overrides the admin's translated name for the library. */
|
|
14
|
+
label: string | null;
|
|
15
|
+
/** Extensions the library lists and accepts, already lower-cased, or null for any file. */
|
|
16
|
+
extensions: string[] | null;
|
|
17
|
+
/** How to reshape an image before uploading it here, or null when uploads go untouched. */
|
|
18
|
+
imageOptimization: ResolvedImageOptimization | null;
|
|
19
|
+
/**
|
|
20
|
+
* Project-relative directory holding the library's bytes in the working tree
|
|
21
|
+
* or repository, absent where they live in a store instead.
|
|
22
|
+
*/
|
|
23
|
+
directory?: string;
|
|
24
|
+
}
|
|
25
|
+
/** A library whose bytes are files of the project, as the storage backends serve one. */
|
|
26
|
+
type WorkingTreeLibrary = ClientLibrary & {
|
|
27
|
+
directory: string;
|
|
28
|
+
};
|
|
29
|
+
/** What the admin bundle may know of the object store: never an endpoint, a bucket or a credential. */
|
|
30
|
+
interface ClientS3Library extends ClientLibrary {
|
|
31
|
+
/** The base the library's keys are publicly served under. */
|
|
32
|
+
publicUrl: string;
|
|
33
|
+
/**
|
|
34
|
+
* Origin of the store's own S3 API, where presigned uploads go.
|
|
35
|
+
*
|
|
36
|
+
* The admin's CSP needs it to allow the upload the browser PUTs there. It
|
|
37
|
+
* says only where the store lives, which is what a signed URL reveals
|
|
38
|
+
* anyway.
|
|
39
|
+
*/
|
|
40
|
+
storeOrigin: string;
|
|
41
|
+
/**
|
|
42
|
+
* `astro dev` only: the directory holding the bytes instead of the store,
|
|
43
|
+
* while references keep the store's URL format. That split is the point, dev
|
|
44
|
+
* touches no bucket, and an entry edited here is spelled exactly as the build
|
|
45
|
+
* expects it.
|
|
46
|
+
*/
|
|
47
|
+
directory?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Both libraries as the admin, the site and the server read them. */
|
|
50
|
+
interface ClientMediaConfig {
|
|
51
|
+
repo: WorkingTreeLibrary;
|
|
52
|
+
/** Null when no object store is configured. */
|
|
53
|
+
s3: ClientS3Library | null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A delegated upload: where the browser may PUT, and the headers it has to send
|
|
57
|
+
* because they are signed into that URL. The browser reproduces them verbatim
|
|
58
|
+
* or the store rejects the signature, which is what makes them terms rather
|
|
59
|
+
* than suggestions.
|
|
60
|
+
*/
|
|
61
|
+
interface PresignedUpload {
|
|
62
|
+
url: string;
|
|
63
|
+
headers: Record<string, string>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The draft branch's standing relative to the default branch. What is *on* the
|
|
67
|
+
* branch is the changeset (see `getChanges`); this only covers what the
|
|
68
|
+
* changeset cannot say: where it lives, whether the default branch has moved on,
|
|
69
|
+
* and where to review it.
|
|
70
|
+
*/
|
|
71
|
+
interface BranchStatus {
|
|
72
|
+
/** Draft branch name, empty for a backend without one. */
|
|
73
|
+
branch: string;
|
|
74
|
+
/** Commits the default branch is ahead of the draft, i.e. what `update` would merge in. */
|
|
75
|
+
behind: number;
|
|
76
|
+
changeRequestUrl?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A file as it was read, with whatever the backend calls that state.
|
|
80
|
+
*
|
|
81
|
+
* The token a write hands back to say which state it was based on: a commit id
|
|
82
|
+
* on GitLab, a blob hash on GitHub, a content digest against the working tree.
|
|
83
|
+
* Opaque, and compared only against itself. A backend with nothing to name a
|
|
84
|
+
* state by returns none, and the write then takes the last word as it always
|
|
85
|
+
* did. ({@link MediaFile.version} serves the other purpose a version can, naming
|
|
86
|
+
* bytes so a URL can address them; the two are read from the same listings but
|
|
87
|
+
* are not interchangeable.)
|
|
88
|
+
*/
|
|
89
|
+
interface VersionedContent {
|
|
90
|
+
content: string;
|
|
91
|
+
version?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* What a write requires of the path it is claiming, as one value: the state it
|
|
95
|
+
* was based on, or that there was no state at all. Two separate parameters could
|
|
96
|
+
* say both at once, which means nothing and left each backend to invent its own
|
|
97
|
+
* precedence for the pair.
|
|
98
|
+
*/
|
|
99
|
+
type Precondition = {
|
|
100
|
+
version: string;
|
|
101
|
+
} | {
|
|
102
|
+
absent: true;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Where the bytes of one library file come from. A backend that can hand out a
|
|
106
|
+
* URL the browser may load itself does; the rest return a body and let the route
|
|
107
|
+
* serve it.
|
|
108
|
+
*/
|
|
109
|
+
type MediaContent = {
|
|
110
|
+
/**
|
|
111
|
+
* What this file's contents are, where the backend knows it without asking for
|
|
112
|
+
* it. The route serves an immutable cache only when the URL's version matches
|
|
113
|
+
* this one, so the policy comes from the file rather than from whatever a
|
|
114
|
+
* caller appended, and a backend that cannot say degrades to the short cache
|
|
115
|
+
* rather than to a wrong one. It is also the answer's entity tag, which is
|
|
116
|
+
* what makes that short cache end in a 304 rather than in the bytes again.
|
|
117
|
+
*/
|
|
118
|
+
version?: string;
|
|
119
|
+
} & ({
|
|
120
|
+
redirect: string;
|
|
121
|
+
} | {
|
|
122
|
+
body: BodyInit | null;
|
|
123
|
+
/** How the range the backend was asked for was answered, absent without one. */
|
|
124
|
+
partial?: PartialContent;
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Content storage, as the operation registry addresses it. The media library is
|
|
128
|
+
* part of it for a repository backend and configured separately for an object
|
|
129
|
+
* store (see `server/media.ts`), which is why the two halves are declared apart.
|
|
130
|
+
*/
|
|
131
|
+
interface StorageBackend {
|
|
132
|
+
listEntries(collection: string): Promise<EntryMeta[]>;
|
|
133
|
+
getEntry(collection: string, id: string): Promise<EntryContent>;
|
|
134
|
+
/** The entry a listing reported, read without looking it up in the listing again. */
|
|
135
|
+
readEntry(meta: EntryMeta): Promise<EntryContent>;
|
|
136
|
+
/**
|
|
137
|
+
* Answers with the version the entry now has, so the editor that saved can
|
|
138
|
+
* keep editing without its next write looking stale. Absent for a backend that
|
|
139
|
+
* names no versions.
|
|
140
|
+
*/
|
|
141
|
+
saveEntry(collection: string, id: string, data: SaveEntryRequest): Promise<string | undefined>;
|
|
142
|
+
/**
|
|
143
|
+
* Each takes the {@link VersionedContent} version its caller read, so a write
|
|
144
|
+
* cannot silently discard one that landed in between. Absent means "whatever
|
|
145
|
+
* is there now", which is what a caller with nothing to compare against can
|
|
146
|
+
* honestly claim.
|
|
147
|
+
*/
|
|
148
|
+
deleteEntry(collection: string, id: string, expectedVersion?: string): Promise<void>;
|
|
149
|
+
renameEntry(collection: string, oldId: string, newId: string, expectedVersion?: string): Promise<void>;
|
|
150
|
+
duplicateEntry(collection: string, sourceId: string, targetId: string): Promise<void>;
|
|
151
|
+
reorderEntries(collection: string, ids: string[], expectedVersion?: string): Promise<void>;
|
|
152
|
+
getFileLayout(collection: string): Promise<FileCollectionInfo>;
|
|
153
|
+
publish(): Promise<void>;
|
|
154
|
+
update(): Promise<void>;
|
|
155
|
+
discard(): Promise<void>;
|
|
156
|
+
getStatus(): Promise<BranchStatus>;
|
|
157
|
+
/** Everything pending since the last publish, as one reviewable unit. */
|
|
158
|
+
getChanges(): Promise<FileChange[]>;
|
|
159
|
+
}
|
|
160
|
+
/** Where an upload's bytes go: straight to an object store, or through the route into a repository. */
|
|
161
|
+
type UploadTicket = ({
|
|
162
|
+
direct: true;
|
|
163
|
+
} & PresignedUpload) | {
|
|
164
|
+
direct: false;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The media library, whether it is the repository itself or an object store.
|
|
168
|
+
* One contract for both, so nothing above this layer branches on which it is.
|
|
169
|
+
*/
|
|
170
|
+
interface MediaBackend {
|
|
171
|
+
listMedia(): Promise<MediaFile[]>;
|
|
172
|
+
/** The paths alone, for a check that has no use for sizes a backend would have to look up. */
|
|
173
|
+
listPaths(): Promise<{
|
|
174
|
+
path: string;
|
|
175
|
+
}[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Where to put the bytes for `path`, decided before any of them exist. Nothing
|
|
178
|
+
* is reserved by this call: a ticket says only that the request is allowed in
|
|
179
|
+
* principle, and the destination is claimed on arrival.
|
|
180
|
+
*/
|
|
181
|
+
beginUpload(path: string, size: number, overwrite: boolean): Promise<UploadTicket>;
|
|
182
|
+
/** Takes the bytes through this server, present only for a repository library, which hands out no URL. */
|
|
183
|
+
uploadMedia?(path: string, bytes: Uint8Array<ArrayBuffer>, overwrite: boolean): Promise<void>;
|
|
184
|
+
renameMedia(from: string, to: string): Promise<void>;
|
|
185
|
+
deleteMedia(path: string): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* A backend handing over bytes honours `range` and says so with `partial`, so
|
|
188
|
+
* a seek in a large video never reads the whole file. A redirect leaves the
|
|
189
|
+
* range to whoever serves it.
|
|
190
|
+
*/
|
|
191
|
+
readMedia(path: string, range?: ByteRange): Promise<MediaContent>;
|
|
192
|
+
/**
|
|
193
|
+
* Deletions that can still be undone. Empty for a library whose deletions are
|
|
194
|
+
* a commit, since git keeps those whether or not the CMS offers a trash.
|
|
195
|
+
*/
|
|
196
|
+
listTrash(): Promise<TrashedFile[]>;
|
|
197
|
+
restoreMedia(id: string): Promise<void>;
|
|
198
|
+
purgeTrash(id: string): Promise<void>;
|
|
199
|
+
}
|
|
200
|
+
/** The entries of a file collection, keyed by id in the order the file holds them. */
|
|
201
|
+
type FileEntries = Map<string, Record<string, unknown>>;
|
|
202
|
+
/**
|
|
203
|
+
* What the checks need to look things up. The storage backend is passed in
|
|
204
|
+
* rather than taken from `getStorage()` so that the backend itself can validate
|
|
205
|
+
* its own writes without depending on the module that constructs it.
|
|
206
|
+
*/
|
|
207
|
+
interface MediaSource {
|
|
208
|
+
/** The library's paths, which is all a check needs, so a backend may skip what the listing adds. */
|
|
209
|
+
listPaths(): Promise<{
|
|
210
|
+
path: string;
|
|
211
|
+
}[]>;
|
|
212
|
+
}
|
|
213
|
+
interface ContentSource {
|
|
214
|
+
listMedia(library: MediaLibraryId): Promise<{
|
|
215
|
+
path: string;
|
|
216
|
+
}[]>;
|
|
217
|
+
listEntries(collection: string): Promise<{
|
|
218
|
+
id: string;
|
|
219
|
+
}[]>;
|
|
220
|
+
/** How an asset value addresses the libraries. */
|
|
221
|
+
media: ClientMediaConfig;
|
|
222
|
+
/** The components a body may use, with the prop schemas their values follow. */
|
|
223
|
+
components: ComponentSchemaMap;
|
|
224
|
+
}
|
|
225
|
+
/** Everything a backend needs that is not the provider credential itself. */
|
|
226
|
+
interface StorageOptions {
|
|
227
|
+
collections: CollectionManifest;
|
|
228
|
+
/** Both libraries, which decide how an entry spells an asset. */
|
|
229
|
+
media: ClientMediaConfig;
|
|
230
|
+
/**
|
|
231
|
+
* The library this instance serves: the repository library, or, in a dev
|
|
232
|
+
* run, the working-tree stand-in for the object store.
|
|
233
|
+
*/
|
|
234
|
+
library: WorkingTreeLibrary;
|
|
235
|
+
components: ComponentSchemaMap;
|
|
236
|
+
/** The signed-in editor, which is what the draft branch is named after. */
|
|
237
|
+
login: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* A Git storage backend is also the repository media library: media there is
|
|
241
|
+
* committed to the same draft branch as content. Entry validation checks assets
|
|
242
|
+
* against whichever library a reference names, which {@link useMediaLibraries}
|
|
243
|
+
* hands it.
|
|
244
|
+
*
|
|
245
|
+
* One instance serves one request. Nothing here is cached across requests, which
|
|
246
|
+
* is what makes it correct on a serverless runtime where an instance may be
|
|
247
|
+
* shared between editors or discarded between clicks.
|
|
248
|
+
*/
|
|
249
|
+
declare abstract class StorageBase implements StorageBackend, MediaBackend {
|
|
250
|
+
protected readonly options: StorageOptions;
|
|
251
|
+
protected readonly schemas: CollectionManifest;
|
|
252
|
+
protected readonly mediaDirectory: string;
|
|
253
|
+
private libraryOf;
|
|
254
|
+
/**
|
|
255
|
+
* The container file of each file collection, read at most once per request.
|
|
256
|
+
* Every entry of one lives in the same file, so a reference scan over an
|
|
257
|
+
* N-entry collection would otherwise fetch and re-parse it N times.
|
|
258
|
+
*/
|
|
259
|
+
private readonly containers;
|
|
260
|
+
/**
|
|
261
|
+
* Each collection's listing, made at most once between writes. Every entry
|
|
262
|
+
* read and write looks its entry up in it, so a rename would otherwise list
|
|
263
|
+
* the collection three times.
|
|
264
|
+
*/
|
|
265
|
+
private readonly listings;
|
|
266
|
+
constructor(options: StorageOptions);
|
|
267
|
+
/** Only the listings are needed, so this never grants writes to a library it does not own. */
|
|
268
|
+
useMediaLibraries(libraryOf: (library: MediaLibraryId) => MediaSource): void;
|
|
269
|
+
listEntries(collection: string): Promise<EntryMeta[]>;
|
|
270
|
+
/**
|
|
271
|
+
* Repository paths at or below a glob collection's `globRoots`, of which the
|
|
272
|
+
* listing keeps the files its loader loads.
|
|
273
|
+
*/
|
|
274
|
+
protected abstract globPaths(col: CollectionManifestEntry): Promise<Iterable<string>>;
|
|
275
|
+
abstract listMedia(): Promise<MediaFile[]>;
|
|
276
|
+
/**
|
|
277
|
+
* All three take repository paths, lowered by the funnels below, and persist a
|
|
278
|
+
* write the library's limits have already been checked against.
|
|
279
|
+
*/
|
|
280
|
+
protected abstract writeMedia(repoPath: string, bytes: Uint8Array<ArrayBuffer>, overwrite: boolean): Promise<void>;
|
|
281
|
+
protected abstract moveMedia(from: string, to: string): Promise<void>;
|
|
282
|
+
protected abstract removeMedia(repoPath: string): Promise<void>;
|
|
283
|
+
/** A content write, after which what this request read is stale. */
|
|
284
|
+
private persist;
|
|
285
|
+
/** Drops the listings and containers this request read, which a write has made stale. */
|
|
286
|
+
protected invalidate(): void;
|
|
287
|
+
private tomlEntryData;
|
|
288
|
+
/**
|
|
289
|
+
* The two file primitives every content write comes down to. Which file and
|
|
290
|
+
* what goes in it is decided here, uniformly, so a backend only has to know
|
|
291
|
+
* how to persist one.
|
|
292
|
+
*
|
|
293
|
+
* The `precondition` is what the write requires of the path at the instant it
|
|
294
|
+
* is claimed. A backend that can make the provider enforce it does; one that
|
|
295
|
+
* cannot ignores it, and the write takes the last word as it always did.
|
|
296
|
+
*/
|
|
297
|
+
protected abstract commitFile(path: string, content: string, message: string, precondition?: Precondition): Promise<string | undefined>;
|
|
298
|
+
protected abstract removeFile(path: string, message: string, expectedVersion?: string): Promise<void>;
|
|
299
|
+
abstract publish(): Promise<void>;
|
|
300
|
+
abstract update(): Promise<void>;
|
|
301
|
+
abstract discard(): Promise<void>;
|
|
302
|
+
abstract getStatus(): Promise<BranchStatus>;
|
|
303
|
+
abstract getChanges(): Promise<FileChange[]>;
|
|
304
|
+
/**
|
|
305
|
+
* The single funnel for content writes, and therefore where content validity is
|
|
306
|
+
* enforced: an entry that does not satisfy its collection's schema (or points
|
|
307
|
+
* at an asset or reference that does not exist) breaks the site's content sync,
|
|
308
|
+
* so it never reaches storage. Every other write composes this one.
|
|
309
|
+
*/
|
|
310
|
+
saveEntry(collection: string, id: string, data: SaveEntryRequest): Promise<string | undefined>;
|
|
311
|
+
deleteEntry(collection: string, id: string, expectedVersion?: string): Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Only a collection sorted by file order has an order to change, which only a
|
|
314
|
+
* file collection can be: a glob collection's entries are separate files. Any
|
|
315
|
+
* other order is the site's, so a rewrite would change nothing it renders.
|
|
316
|
+
*/
|
|
317
|
+
reorderEntries(collection: string, ids: string[], expectedVersion?: string): Promise<void>;
|
|
318
|
+
getEntry(collection: string, id: string): Promise<EntryContent>;
|
|
319
|
+
readEntry({ collection, id, path, format }: EntryMeta): Promise<EntryContent>;
|
|
320
|
+
/** A copy under a new id, which works uniformly because saveEntry branches on layout. */
|
|
321
|
+
duplicateEntry(collection: string, sourceId: string, targetId: string): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* In a glob collection two writes, a copy and the removal of the original, and
|
|
324
|
+
* the version describes the removal. In a file collection both entries share
|
|
325
|
+
* one container, so it is one rewrite that keeps the entry where it was, since
|
|
326
|
+
* its position may be the collection's order.
|
|
327
|
+
*/
|
|
328
|
+
renameEntry(collection: string, oldId: string, newId: string, expectedVersion?: string): Promise<void>;
|
|
329
|
+
/** The entry as the memoized listing reports it, or undefined when there is none. */
|
|
330
|
+
private storedEntry;
|
|
331
|
+
/** The raw content of a repository file, by project-relative path. */
|
|
332
|
+
protected fetchFileContent(_path: string): Promise<VersionedContent>;
|
|
333
|
+
/** What entry validation resolves references and assets against. */
|
|
334
|
+
protected get contentSource(): ContentSource;
|
|
335
|
+
/** The repository path of a library file. */
|
|
336
|
+
protected mediaRepoPath(path: string): string;
|
|
337
|
+
/**
|
|
338
|
+
* A repository library has no URL to hand out: its bytes become a commit, so
|
|
339
|
+
* they have to arrive here. The checks still run now rather than on arrival,
|
|
340
|
+
* so an oversized or occupied upload is refused before it is sent.
|
|
341
|
+
*/
|
|
342
|
+
beginUpload(path: string, size: number, overwrite: boolean): Promise<UploadTicket>;
|
|
343
|
+
private assertUploadable;
|
|
344
|
+
/**
|
|
345
|
+
* Where a repository library's own writes are checked before bytes reach a backend.
|
|
346
|
+
* Every backend claims a new path atomically, so no listing is needed here.
|
|
347
|
+
*/
|
|
348
|
+
uploadMedia(path: string, bytes: Uint8Array<ArrayBuffer>, overwrite: boolean): Promise<void>;
|
|
349
|
+
renameMedia(oldPath: string, newPath: string): Promise<void>;
|
|
350
|
+
deleteMedia(path: string): Promise<void>;
|
|
351
|
+
abstract readMedia(path: string): Promise<MediaContent>;
|
|
352
|
+
listPaths(): Promise<{
|
|
353
|
+
path: string;
|
|
354
|
+
}[]>;
|
|
355
|
+
/**
|
|
356
|
+
* A repository library has no trash, and needs none: a deletion here is a
|
|
357
|
+
* commit on the draft branch, so the file is still in git, recoverable by
|
|
358
|
+
* discarding the changeset before it publishes, and in history for good
|
|
359
|
+
* afterwards. An object store keeps no history, which is the whole reason the
|
|
360
|
+
* other library has a trash at all.
|
|
361
|
+
*/
|
|
362
|
+
listTrash(): Promise<TrashedFile[]>;
|
|
363
|
+
restoreMedia(): Promise<never>;
|
|
364
|
+
purgeTrash(): Promise<never>;
|
|
365
|
+
/**
|
|
366
|
+
* Lowers repository paths into library files, dropping strays in the media
|
|
367
|
+
* directory. Takes the backend's own listing shape rather than `MediaFile`s, so
|
|
368
|
+
* a whole-repository tree costs no allocation for the paths it discards.
|
|
369
|
+
*/
|
|
370
|
+
protected mediaFiles(files: Iterable<{
|
|
371
|
+
path: string;
|
|
372
|
+
size?: number;
|
|
373
|
+
version?: string;
|
|
374
|
+
}>): MediaFile[];
|
|
375
|
+
private schema;
|
|
376
|
+
protected isFileCollection(collection: string): boolean;
|
|
377
|
+
protected getFileLoaderPath(collection: string): string | null;
|
|
378
|
+
/**
|
|
379
|
+
* The format of a file collection's container. It is the loader's own file
|
|
380
|
+
* name, so an unknown extension means the loader is one the CMS cannot read
|
|
381
|
+
* rather than a caller mistake; JSON is the reading that parses most of them.
|
|
382
|
+
*/
|
|
383
|
+
protected containerFormat(loaderFileName: string): EntryFormat;
|
|
384
|
+
/**
|
|
385
|
+
* The container file as it stands, or an empty one when it does not exist yet
|
|
386
|
+
* (or is not a file collection at all). Every read of one goes through here,
|
|
387
|
+
* so the listing, the layout and a write all see the same parse.
|
|
388
|
+
*/
|
|
389
|
+
private readFileCollection;
|
|
390
|
+
private loadFileCollection;
|
|
391
|
+
/**
|
|
392
|
+
* How a file collection stores its entries, which decides whether they can be
|
|
393
|
+
* reordered, and the version a reorder has to be based on.
|
|
394
|
+
*/
|
|
395
|
+
getFileLayout(collection: string): Promise<FileCollectionInfo>;
|
|
396
|
+
private listFileCollectionEntries;
|
|
397
|
+
/**
|
|
398
|
+
* A file collection rewritten by `mutate`, as the path and content to write.
|
|
399
|
+
* All three ways to change one (upsert, remove, reorder) are the same
|
|
400
|
+
* read-modify-serialize, so they differ only in the mutation.
|
|
401
|
+
*/
|
|
402
|
+
protected editFileCollection(collection: string, mutate: (entries: FileEntries, format: EntryFormat) => FileEntries | void): Promise<{
|
|
403
|
+
path: string;
|
|
404
|
+
content: string;
|
|
405
|
+
version?: string;
|
|
406
|
+
}>;
|
|
407
|
+
}
|
|
408
|
+
export interface LocalConfig {
|
|
409
|
+
/** Absolute project root. Every managed path is resolved against it. */
|
|
410
|
+
rootDir: string;
|
|
411
|
+
}
|
|
412
|
+
export declare class LocalStorage extends StorageBase {
|
|
413
|
+
private readonly rootDir;
|
|
414
|
+
private readonly managed;
|
|
415
|
+
/** The roots as the filesystem actually names them. Fixed, so resolved once. */
|
|
416
|
+
private canonicalRoots?;
|
|
417
|
+
constructor(config: LocalConfig, options: StorageOptions);
|
|
418
|
+
private roots;
|
|
419
|
+
/**
|
|
420
|
+
* A project-relative path lowered to an absolute one the CMS is allowed to
|
|
421
|
+
* touch. Joining first means a crafted `..` cannot smuggle a path out of the
|
|
422
|
+
* project, and the allowlist then bounds it to the content model.
|
|
423
|
+
*/
|
|
424
|
+
private resolve;
|
|
425
|
+
/** Every file below a managed directory, or the managed file itself, project-relative. */
|
|
426
|
+
private filesAt;
|
|
427
|
+
private fileAt;
|
|
428
|
+
private writeFileAt;
|
|
429
|
+
protected globPaths(col: CollectionManifestEntry): Promise<string[]>;
|
|
430
|
+
protected fetchFileContent(path: string): Promise<VersionedContent>;
|
|
431
|
+
/**
|
|
432
|
+
* The working tree has nothing that names a file's state, so the state is
|
|
433
|
+
* named by its contents. A dev run is one editor, but the assistant writes
|
|
434
|
+
* here too, and the check being exercised in development is how it is known to
|
|
435
|
+
* work in production.
|
|
436
|
+
*/
|
|
437
|
+
protected commitFile(path: string, content: string, _message?: string, precondition?: Precondition): Promise<string>;
|
|
438
|
+
protected removeFile(path: string, _message?: string, expectedVersion?: string): Promise<void>;
|
|
439
|
+
/** The working tree names a file's state by its contents, so this reads them back. */
|
|
440
|
+
private assertVersion;
|
|
441
|
+
listMedia(): Promise<MediaFile[]>;
|
|
442
|
+
protected writeMedia(repoPath: string, bytes: Uint8Array<ArrayBuffer>, overwrite: boolean): Promise<void>;
|
|
443
|
+
protected moveMedia(from: string, to: string): Promise<void>;
|
|
444
|
+
protected removeMedia(repoPath: string): Promise<void>;
|
|
445
|
+
/** Streamed from disk, and only the range asked for, so no read costs the whole file. */
|
|
446
|
+
readMedia(path: string, range?: ByteRange): Promise<MediaContent>;
|
|
447
|
+
publish(): Promise<void>;
|
|
448
|
+
update(): Promise<void>;
|
|
449
|
+
discard(): Promise<void>;
|
|
450
|
+
getStatus(): Promise<BranchStatus>;
|
|
451
|
+
getChanges(): Promise<FileChange[]>;
|
|
452
|
+
}
|
|
453
|
+
export {};
|