@vite-hub/cms 0.0.0 → 0.3.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 +201 -0
- package/README.md +75 -0
- package/dist/access.d.ts +69 -0
- package/dist/access.js +119 -0
- package/dist/index-eur9QR7_.d.ts +51 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +61 -0
- package/dist/options-CIxG4vtI.js +96 -0
- package/dist/vite.d.ts +374 -0
- package/dist/vite.js +960 -0
- package/package.json +103 -4
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { defineDiagnostics } from "nostics";
|
|
2
|
+
//#region src/error-diagnostics.ts
|
|
3
|
+
const cmsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
4
|
+
docsBase: "https://vitehub.dev/docs/content/diagnostics",
|
|
5
|
+
codes: {
|
|
6
|
+
CONTENT_B0001: {
|
|
7
|
+
why: ({ message }) => message === void 0 ? "" : String(message),
|
|
8
|
+
fix: "In the file that the message names, pass `extends: cms` or `extends: [cms, { ... }]` with string literal options that the message accepts."
|
|
9
|
+
},
|
|
10
|
+
CONTENT_B0002: {
|
|
11
|
+
why: ({ message }) => message === void 0 ? "" : String(message),
|
|
12
|
+
fix: "Set the `vitehub()` setting or the `cms` preset option that the message names, such as `vitehub({ database: true })` or `extends: [cms, { database: \"default\" }]`."
|
|
13
|
+
},
|
|
14
|
+
CONTENT_CMS_OPTION_INVALID: {
|
|
15
|
+
docs: "https://vitehub.dev/docs/cms/diagnostics/content_cms_option_invalid",
|
|
16
|
+
why: ({ problem }) => `[vitehub] Content cms preset ${problem}`,
|
|
17
|
+
fix: "Set each option of `extends: [cms, { ... }]` to a value that the message accepts. Use `repo`, `branch`, `draftBranch`, `root`, and `publish` only with the GitHub store, and `blob` only without it."
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/options.ts
|
|
23
|
+
/** Options of the `cms` preset that name a resource of the Blob + Database store. */
|
|
24
|
+
const cmsNameOptions = [
|
|
25
|
+
"blob",
|
|
26
|
+
"database",
|
|
27
|
+
"workspace"
|
|
28
|
+
];
|
|
29
|
+
/** Options that only the GitHub store reads. */
|
|
30
|
+
const cmsGitHubOptions = [
|
|
31
|
+
"repo",
|
|
32
|
+
"branch",
|
|
33
|
+
"draftBranch",
|
|
34
|
+
"root",
|
|
35
|
+
"publish"
|
|
36
|
+
];
|
|
37
|
+
/** Every option of the `cms` preset. */
|
|
38
|
+
const cmsOptionKeys = [
|
|
39
|
+
"access",
|
|
40
|
+
...cmsNameOptions,
|
|
41
|
+
"store",
|
|
42
|
+
...cmsGitHubOptions
|
|
43
|
+
];
|
|
44
|
+
const cmsStores = ["blob-database", "github"];
|
|
45
|
+
const cmsPublishModes = ["commit", "pr"];
|
|
46
|
+
const namePattern = /^[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*$/i;
|
|
47
|
+
const repoPattern = /^[A-Za-z0-9-]+\/(?!\.{1,2}$)[A-Za-z0-9_.-]+$/;
|
|
48
|
+
const branchPattern = /^[\w-]+(?:[./][\w-]+)*$/;
|
|
49
|
+
const rootPattern = /^[\w.-]+(?:\/[\w.-]+)*$/;
|
|
50
|
+
/** What the GitHub store of the `cms` preset uses when an option is left out. */
|
|
51
|
+
const cmsGitHubDefaults = {
|
|
52
|
+
branch: "main",
|
|
53
|
+
draftBranch: "vitehub/content",
|
|
54
|
+
publish: "commit",
|
|
55
|
+
root: ""
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Why `value` is not valid for the `cms` preset option `key`, worded to complete `option "key" ...`, or undefined when
|
|
59
|
+
* it is valid. The build and the runtime check the same rules.
|
|
60
|
+
*/
|
|
61
|
+
function cmsOptionProblem(key, value) {
|
|
62
|
+
if (value === void 0) return;
|
|
63
|
+
const text = String(value) === value ? value : void 0;
|
|
64
|
+
if (key === "access") return text === "roles" ? void 0 : `must be "roles".`;
|
|
65
|
+
if (cmsNameOptions.includes(key)) return text !== void 0 && namePattern.test(text) ? void 0 : "must be a name of letters, numbers, dots, underscores, dashes, and slashes.";
|
|
66
|
+
if (key === "store") return text !== void 0 && cmsStores.includes(text) ? void 0 : `must be "blob-database" or "github".`;
|
|
67
|
+
if (key === "repo") return text !== void 0 && repoPattern.test(text) ? void 0 : "must be a repository in owner/name format.";
|
|
68
|
+
if (key === "branch" || key === "draftBranch") return text !== void 0 && text.length <= 128 && branchPattern.test(text) ? void 0 : "must be a branch name of letters, numbers, underscores, and dashes, separated by single dots or slashes.";
|
|
69
|
+
if (key === "root") return text !== void 0 && (text === "" || rootPattern.test(text) && !text.split("/").some((part) => part === "." || part === "..")) ? void 0 : "must be a folder inside the repository, such as \"content\", or \"\" for the repository root.";
|
|
70
|
+
if (key === "publish") return text !== void 0 && cmsPublishModes.includes(text) ? void 0 : `must be "commit" or "pr".`;
|
|
71
|
+
return "is not a cms preset option.";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The store that the options select. `repo` selects the GitHub store, so `store: "github"` is needed only for a GitHub
|
|
75
|
+
* store without `repo`. Never read from the environment: the same config selects the same store on every machine.
|
|
76
|
+
*/
|
|
77
|
+
function cmsStoreOf(options) {
|
|
78
|
+
const store = Reflect.get(options, "store");
|
|
79
|
+
if (store === "github" || store === "blob-database") return store;
|
|
80
|
+
return Reflect.get(options, "repo") === void 0 ? "blob-database" : "github";
|
|
81
|
+
}
|
|
82
|
+
/** A problem with the combination of options, or undefined. Pass only the options that the app set. */
|
|
83
|
+
function cmsOptionsProblem(options) {
|
|
84
|
+
const get = (key) => Reflect.get(options, key);
|
|
85
|
+
if (cmsStoreOf(options) !== "github") {
|
|
86
|
+
const used = cmsGitHubOptions.filter((key) => get(key) !== void 0);
|
|
87
|
+
if (!used.length) return;
|
|
88
|
+
const fix = get("store") === "blob-database" ? `Remove store: "blob-database" to keep content in Git, or remove ${used.length === 1 ? "it" : "them"}.` : `Set repo: "owner/name" to keep content in Git, or remove ${used.length === 1 ? "it" : "them"}.`;
|
|
89
|
+
return `option${used.length === 1 ? "" : "s"} ${used.map((key) => JSON.stringify(key)).join(", ")} only ${used.length === 1 ? "applies" : "apply"} to the GitHub store. ${fix}`;
|
|
90
|
+
}
|
|
91
|
+
if (get("blob") !== void 0) return `option "blob" does not apply to the GitHub store, which keeps files in Git and needs no Blob store.`;
|
|
92
|
+
const branch = get("branch") ?? cmsGitHubDefaults.branch;
|
|
93
|
+
if (branch === (get("draftBranch") ?? cmsGitHubDefaults.draftBranch)) return `option "draftBranch" must differ from "branch". Both are ${JSON.stringify(branch)}.`;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { cmsStoreOf as a, cmsOptionsProblem as i, cmsOptionKeys as n, cmsErrorDiagnostics as o, cmsOptionProblem as r, cmsGitHubDefaults as t };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { t as CmsPresetOptions } from "./index-eur9QR7_.js";
|
|
2
|
+
import "nostics";
|
|
3
|
+
import { Plugin } from "vite";
|
|
4
|
+
import { DatabaseContributionFactory } from "@vite-hub/database/vite";
|
|
5
|
+
import { WorkspaceContributionFactory } from "@vite-hub/workspace/vite";
|
|
6
|
+
//#region ../internal/dist/host-credentials-MN0OQ2os.d.ts
|
|
7
|
+
interface HostCliRunResult {
|
|
8
|
+
exitCode: number | null;
|
|
9
|
+
stdout: string;
|
|
10
|
+
}
|
|
11
|
+
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
12
|
+
type HostCliRun = (command: string, args: readonly string[], options: {
|
|
13
|
+
cwd?: string;
|
|
14
|
+
env: NodeJS.ProcessEnv;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}) => Promise<HostCliRunResult>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region ../internal/dist/provision-k67k9T1h.d.ts
|
|
19
|
+
//#region src/provision.d.ts
|
|
20
|
+
type ProvisionProvider = "cloudflare" | "vercel";
|
|
21
|
+
interface ProvisionLogger {
|
|
22
|
+
log: (message: string) => void;
|
|
23
|
+
warn: (message: string) => void;
|
|
24
|
+
}
|
|
25
|
+
interface ProvisionContext {
|
|
26
|
+
env: Record<string, string | undefined>;
|
|
27
|
+
fetch: typeof globalThis.fetch;
|
|
28
|
+
logger: ProvisionLogger;
|
|
29
|
+
markPlanUnchecked?: () => void;
|
|
30
|
+
}
|
|
31
|
+
interface ProvisionState {
|
|
32
|
+
cloudflare?: Record<string, Record<string, string>>;
|
|
33
|
+
vercel?: Record<string, Record<string, string>>;
|
|
34
|
+
}
|
|
35
|
+
interface ProvisionResult {
|
|
36
|
+
ids?: ProvisionState;
|
|
37
|
+
}
|
|
38
|
+
interface ProvisionAction {
|
|
39
|
+
kind: string;
|
|
40
|
+
name: string;
|
|
41
|
+
exists: boolean;
|
|
42
|
+
pending?: boolean;
|
|
43
|
+
/** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
|
|
44
|
+
update?: string;
|
|
45
|
+
apply: () => Promise<ProvisionResult>;
|
|
46
|
+
}
|
|
47
|
+
/** One Provision State category that a step records, with the keys that current Definitions use. */
|
|
48
|
+
interface ProvisionStateCategory {
|
|
49
|
+
category: string;
|
|
50
|
+
declared: readonly string[];
|
|
51
|
+
/** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
|
|
52
|
+
resourceIdentity?: (entry: {
|
|
53
|
+
id: string;
|
|
54
|
+
key: string;
|
|
55
|
+
}) => string | undefined;
|
|
56
|
+
/** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
|
|
57
|
+
declaredResourceIdentity?: (key: string) => string | undefined;
|
|
58
|
+
/** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
|
|
59
|
+
deleteHint: (entry: {
|
|
60
|
+
id: string;
|
|
61
|
+
key: string;
|
|
62
|
+
}) => string;
|
|
63
|
+
}
|
|
64
|
+
interface ProvisionStep {
|
|
65
|
+
id: string;
|
|
66
|
+
provider: ProvisionProvider;
|
|
67
|
+
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
68
|
+
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
69
|
+
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region ../internal/dist/cli.d.ts
|
|
73
|
+
//#region src/cli.d.ts
|
|
74
|
+
interface ViteHubCliStreams {
|
|
75
|
+
stderr: {
|
|
76
|
+
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
77
|
+
};
|
|
78
|
+
stdout: {
|
|
79
|
+
write: (chunk: string | Uint8Array) => unknown;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
interface ViteHubCliSpawnResult {
|
|
83
|
+
exitCode: number | null;
|
|
84
|
+
signal?: NodeJS.Signals | null;
|
|
85
|
+
/** The output of the child when `stdout` is `pipe`. */
|
|
86
|
+
stdout?: string;
|
|
87
|
+
}
|
|
88
|
+
interface ViteHubCliSpawnOptions {
|
|
89
|
+
cwd?: string;
|
|
90
|
+
env?: NodeJS.ProcessEnv;
|
|
91
|
+
stderr?: "inherit" | "pipe";
|
|
92
|
+
/** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
|
|
93
|
+
stdin?: "ignore" | "inherit";
|
|
94
|
+
/** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
|
|
95
|
+
stdout?: "inherit" | "pipe" | "stderr";
|
|
96
|
+
}
|
|
97
|
+
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
98
|
+
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
99
|
+
cwd: string;
|
|
100
|
+
env: NodeJS.ProcessEnv;
|
|
101
|
+
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
102
|
+
fetch?: typeof fetch;
|
|
103
|
+
/**
|
|
104
|
+
* Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
|
|
105
|
+
* that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
|
|
106
|
+
* steps, so they still run on a config that throws.
|
|
107
|
+
*/
|
|
108
|
+
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
109
|
+
/** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
|
|
110
|
+
publicUrl?: string;
|
|
111
|
+
rootDir: string;
|
|
112
|
+
/** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
|
|
113
|
+
runHostCli?: HostCliRun;
|
|
114
|
+
spawn: ViteHubCliSpawn;
|
|
115
|
+
}
|
|
116
|
+
interface ViteHubCliProvision {
|
|
117
|
+
rootDir: string;
|
|
118
|
+
steps: readonly ProvisionStep[];
|
|
119
|
+
}
|
|
120
|
+
interface ViteHubCliFeature {
|
|
121
|
+
description?: string;
|
|
122
|
+
name: string;
|
|
123
|
+
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
124
|
+
usage?: string;
|
|
125
|
+
}
|
|
126
|
+
interface ViteHubCliCommandNamespace {
|
|
127
|
+
/** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
|
|
128
|
+
defaultFeature?: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
features: ViteHubCliFeature[];
|
|
131
|
+
name: string;
|
|
132
|
+
}
|
|
133
|
+
/** The flags of `vitehub seed` that every seed gets. */
|
|
134
|
+
interface ViteHubCliSeedOptions {
|
|
135
|
+
/** `--database <name>`: seed only this Database. Only the Database seed runs. */
|
|
136
|
+
database?: string;
|
|
137
|
+
/** The process environment with the env files of `--stage`. */
|
|
138
|
+
env: NodeJS.ProcessEnv;
|
|
139
|
+
/** `--remote`: write the deployed stores. Without it, a seed writes only local data. */
|
|
140
|
+
remote: boolean;
|
|
141
|
+
/** `--timeout <ms>` of each call to the app. */
|
|
142
|
+
timeout?: number;
|
|
143
|
+
/** The deployed app with `--remote`: `--url`, or `vitehub({ publicUrl })`. */
|
|
144
|
+
url?: string;
|
|
145
|
+
}
|
|
146
|
+
/** The seed files of one primitive, which `vitehub seed` writes. */
|
|
147
|
+
interface ViteHubCliSeed {
|
|
148
|
+
/** Where the seed files are, such as `server/seed/kv/`. `vitehub seed` names it when it finds no seed files. */
|
|
149
|
+
files: string;
|
|
150
|
+
/** The primitive, such as `database` or `kv`. `vitehub seed <name>` runs only this seed. */
|
|
151
|
+
name: string;
|
|
152
|
+
/** Writes the seed files and returns the exit code, or `undefined` when the project has no seed files for this primitive. */
|
|
153
|
+
run: (options: ViteHubCliSeedOptions, context: ViteHubCliContext) => Promise<number | undefined>;
|
|
154
|
+
}
|
|
155
|
+
interface ViteHubCliContributor {
|
|
156
|
+
namespaces: ViteHubCliCommandNamespace[];
|
|
157
|
+
provision?: ProvisionStep[];
|
|
158
|
+
/** The seed files that `vitehub seed` writes. */
|
|
159
|
+
seeds?: ViteHubCliSeed[];
|
|
160
|
+
/** The deployed app's public origin. Commands receive it as `context.publicUrl`. */
|
|
161
|
+
publicUrl?: string;
|
|
162
|
+
}
|
|
163
|
+
type ViteHubCliContributorFactory = () => ViteHubCliContributor | undefined | Promise<ViteHubCliContributor | undefined>;
|
|
164
|
+
interface ViteHubCliPluginMetadata {
|
|
165
|
+
cli?: ViteHubCliContributor | ViteHubCliContributorFactory;
|
|
166
|
+
}
|
|
167
|
+
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region ../internal/dist/inspect.d.ts
|
|
170
|
+
//#region src/inspect.d.ts
|
|
171
|
+
interface ViteHubDefinitionField {
|
|
172
|
+
label: string;
|
|
173
|
+
value: string;
|
|
174
|
+
}
|
|
175
|
+
/** Serializable summary of one discovered Definition. Files are relative to the project root. */
|
|
176
|
+
interface ViteHubDefinitionSummary {
|
|
177
|
+
fields: readonly ViteHubDefinitionField[];
|
|
178
|
+
file: string;
|
|
179
|
+
name: string;
|
|
180
|
+
source: string;
|
|
181
|
+
}
|
|
182
|
+
/** Lists the Definitions that one owner package discovered for the resolved Vite config. */
|
|
183
|
+
interface ViteHubDefinitionInspector {
|
|
184
|
+
/** Stable singular kind, for example `queue` or `rate-limit`. */
|
|
185
|
+
kind: string;
|
|
186
|
+
label: string;
|
|
187
|
+
list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
|
|
188
|
+
}
|
|
189
|
+
/** One generated Provider Output file or directory that an owner package can write. */
|
|
190
|
+
interface ViteHubProviderOutputEntry {
|
|
191
|
+
description: string;
|
|
192
|
+
owner: string;
|
|
193
|
+
/** Absolute path. */
|
|
194
|
+
path: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
|
|
198
|
+
* The CLI sets `provider-output` when only a generated Wrangler config names the id.
|
|
199
|
+
*/
|
|
200
|
+
type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
|
|
201
|
+
/** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
|
|
202
|
+
interface ViteHubResourceSummary {
|
|
203
|
+
/** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
|
|
204
|
+
binding?: string;
|
|
205
|
+
/** Definition or store name. */
|
|
206
|
+
definition: string;
|
|
207
|
+
/** Env variable that supplied the id when `source` is `env`. */
|
|
208
|
+
env?: string;
|
|
209
|
+
host: "cloudflare" | "vercel";
|
|
210
|
+
id?: string;
|
|
211
|
+
/** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
|
|
212
|
+
kind: string;
|
|
213
|
+
/** Resource name on the host, when the config names it. */
|
|
214
|
+
name?: string;
|
|
215
|
+
/** Explains how the host finds the resource when no id or name is known locally. */
|
|
216
|
+
note?: string;
|
|
217
|
+
owner: string;
|
|
218
|
+
/** Absent when no id is known yet. */
|
|
219
|
+
source?: ViteHubResourceIdSource;
|
|
220
|
+
}
|
|
221
|
+
interface ViteHubInspectionContributor {
|
|
222
|
+
definitions?: readonly ViteHubDefinitionInspector[];
|
|
223
|
+
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
224
|
+
resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
|
|
225
|
+
}
|
|
226
|
+
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
227
|
+
interface ViteHubInspectionPluginMetadata {
|
|
228
|
+
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/build.d.ts
|
|
232
|
+
/** Import paths that select the `cms` preset in `server/content.ts`. */
|
|
233
|
+
export declare const cmsPresetModules: readonly string[];
|
|
234
|
+
/** How `server/content.ts` selects the `cms` preset, read from its source without running it. */
|
|
235
|
+
interface CmsPresetUsage {
|
|
236
|
+
/** The Content Definition file. */
|
|
237
|
+
file: string;
|
|
238
|
+
/** Options from `extends: [cms, options]`. Empty for `extends: cms`. */
|
|
239
|
+
options: CmsPresetOptions;
|
|
240
|
+
/** Whether `defineContent()` passes its own `authorize`, or a spread makes its presence unknown. */
|
|
241
|
+
authorize?: true | "unknown";
|
|
242
|
+
}
|
|
243
|
+
/** The GitHub store of the `cms` preset, with defaults filled in. */
|
|
244
|
+
interface CmsGitHubPlan {
|
|
245
|
+
/** `owner/name`. Without it the store reads `VITEHUB_WORKSPACE_GITHUB_REPOSITORY` when it is first used. */
|
|
246
|
+
repo?: string;
|
|
247
|
+
/** The published branch. */
|
|
248
|
+
branch: string;
|
|
249
|
+
/** The branch that holds drafts. */
|
|
250
|
+
draftBranch: string;
|
|
251
|
+
/** The folder in the repository, or `""` for the repository root. */
|
|
252
|
+
root: string;
|
|
253
|
+
publish: "commit" | "pr";
|
|
254
|
+
}
|
|
255
|
+
/** The resources that the `cms` preset borrows, resolved for one app. */
|
|
256
|
+
interface CmsPresetPlan extends CmsPresetUsage {
|
|
257
|
+
/** Where documents live: the Blob + Database store, or a GitHub repository. */
|
|
258
|
+
store: "blob-database" | "github";
|
|
259
|
+
/** The Blob store. Undefined for the GitHub store, which keeps files in Git. */
|
|
260
|
+
blob?: string;
|
|
261
|
+
/** Set for the GitHub store. */
|
|
262
|
+
github?: CmsGitHubPlan;
|
|
263
|
+
database: string;
|
|
264
|
+
/**
|
|
265
|
+
* How the Database was chosen: the default-or-only rule, the `database` option, or `implicit` when the app has no
|
|
266
|
+
* Database Definition and uses the implicit `default` Database of `@vite-hub/database`.
|
|
267
|
+
*/
|
|
268
|
+
databaseReason: "default" | "implicit" | "only" | "option";
|
|
269
|
+
workspace: string;
|
|
270
|
+
}
|
|
271
|
+
type ParseAst = (source: string, options: {
|
|
272
|
+
lang: "ts" | "tsx" | "js" | "jsx";
|
|
273
|
+
}) => unknown;
|
|
274
|
+
/**
|
|
275
|
+
* Read how `server/content.ts` selects the `cms` preset. The build cannot run the Definition, so the preset must be
|
|
276
|
+
* imported from `vite-hub/cms` or `@vite-hub/cms` and passed as `extends: cms` or `extends: [cms, { ... }]` with string
|
|
277
|
+
* literal options. Returns undefined when the file does not import the preset.
|
|
278
|
+
*/
|
|
279
|
+
export declare function readCmsPresetUsage(source: string, file: string, projectRoot: string, parseAst: ParseAst): CmsPresetUsage | undefined;
|
|
280
|
+
/** Database names and how to pick one, from `@vite-hub/database/config`. */
|
|
281
|
+
interface CmsDatabaseChoices {
|
|
282
|
+
names: readonly string[];
|
|
283
|
+
resolveDefault(names: readonly string[]): {
|
|
284
|
+
status: "resolved";
|
|
285
|
+
name: string;
|
|
286
|
+
reason: "default" | "only";
|
|
287
|
+
} | {
|
|
288
|
+
status: "ambiguous";
|
|
289
|
+
names: string[];
|
|
290
|
+
} | {
|
|
291
|
+
status: "none";
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/** Pick the Database, Blob store, and Workspace name that the preset uses. Fails with the option to set. */
|
|
295
|
+
export declare function resolveCmsPresetPlan(usage: CmsPresetUsage, databases: CmsDatabaseChoices, projectRoot: string): CmsPresetPlan;
|
|
296
|
+
/** Import paths that the generated Workspace module uses. */
|
|
297
|
+
interface CmsWorkspaceImports {
|
|
298
|
+
/** Exports `blob`. */
|
|
299
|
+
blob: string;
|
|
300
|
+
/** Exports `createBlobDatabaseWorkspaceStore` and `workspaceHistorySchema`. */
|
|
301
|
+
blobDatabase: string;
|
|
302
|
+
/** Exports `contentSessionsSchema`, the presence and edit lease table that the preset adds to its Database. */
|
|
303
|
+
contentDatabase?: string;
|
|
304
|
+
/** Exports `databases`, the runtime Database registry. */
|
|
305
|
+
database: string;
|
|
306
|
+
/** Exports `defineWorkspace`. */
|
|
307
|
+
workspace: string;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The generated Workspace Definition module. It only reads the Database registry and creates a lazy store when it
|
|
311
|
+
* loads, so the build can load it to bundle Workspace assets. The GitHub store reads its token on first use.
|
|
312
|
+
*/
|
|
313
|
+
export declare function renderCmsWorkspaceModule(plan: CmsPresetPlan, imports: CmsWorkspaceImports): string;
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/cli.d.ts
|
|
316
|
+
/** The `vitehub cms` commands. */
|
|
317
|
+
export declare function createCmsCliContributor(): ViteHubCliContributor;
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/vite.d.ts
|
|
320
|
+
export declare const CMS_VITE_PLUGIN_NAME = "@vite-hub/cms/vite";
|
|
321
|
+
/** Generated Workspace Definition module of the `cms` preset, relative to the project root. */
|
|
322
|
+
export declare const cmsWorkspaceModulePath = ".vitehub/content/workspace.mjs";
|
|
323
|
+
/**
|
|
324
|
+
* Whether `server/content.ts` selects the `cms` preset. `vitehub()` reads it while Vite filters plugins, so the
|
|
325
|
+
* preset turns on Workspace, Database, and Blob without settings. Reads the file without running it.
|
|
326
|
+
*/
|
|
327
|
+
export declare function usesCms(input: {
|
|
328
|
+
projectRoot: string;
|
|
329
|
+
serverDirs?: readonly string[];
|
|
330
|
+
}): boolean;
|
|
331
|
+
/** The selected CMS store, so framework integrations enable only the services it needs. */
|
|
332
|
+
export declare function cmsStore(input: {
|
|
333
|
+
projectRoot: string;
|
|
334
|
+
serverDirs?: readonly string[];
|
|
335
|
+
}): "blob-database" | "github" | undefined;
|
|
336
|
+
export interface CmsVitePluginOptions {
|
|
337
|
+
/**
|
|
338
|
+
* Import paths for the generated `cms` Workspace module. Defaults to the `@vite-hub/*` packages. The `vite-hub`
|
|
339
|
+
* integration passes its own subpaths, so the module resolves from the app.
|
|
340
|
+
*/
|
|
341
|
+
imports?: Partial<CmsWorkspaceImports>;
|
|
342
|
+
}
|
|
343
|
+
export interface CmsVitePluginAPI {
|
|
344
|
+
/** The resources that the `cms` preset uses, or undefined when `server/content.ts` does not select it. */
|
|
345
|
+
resolvePlan(input: {
|
|
346
|
+
projectRoot: string;
|
|
347
|
+
serverDirs?: readonly string[];
|
|
348
|
+
databaseRoot?: string;
|
|
349
|
+
contributedDefinitions?: readonly {
|
|
350
|
+
name: string;
|
|
351
|
+
}[];
|
|
352
|
+
}): Promise<CmsPresetPlan | undefined>;
|
|
353
|
+
}
|
|
354
|
+
export type CmsVitePlugin = Plugin & {
|
|
355
|
+
api: CmsVitePluginAPI;
|
|
356
|
+
/**
|
|
357
|
+
* Contributions that the Workspace and Database plugins collect, both empty without the `cms` preset. With
|
|
358
|
+
* `server/content.ts`, the `vitehub cms roles` command. With the preset, a `cms` inspector that says whether the CMS
|
|
359
|
+
* roles or the app's `authorize` decide access.
|
|
360
|
+
*/
|
|
361
|
+
vitehub: {
|
|
362
|
+
databases: DatabaseContributionFactory;
|
|
363
|
+
workspaces: WorkspaceContributionFactory;
|
|
364
|
+
} & ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* CMS build integration. When `server/content.ts` selects the `cms` preset, it contributes the preset's Workspace
|
|
368
|
+
* through `vitehub.workspaces`, and the Workspace history tables through `vitehub.databases`. When the app has no
|
|
369
|
+
* Database Definition, the tables go to the implicit `default` Database of `@vite-hub/database`. It checks that Workspace, Database, and Blob are enabled, and restarts the
|
|
370
|
+
* dev server when the selection changes. Apps without the preset are unaffected.
|
|
371
|
+
*/
|
|
372
|
+
export declare function hubCms(options?: CmsVitePluginOptions): CmsVitePlugin;
|
|
373
|
+
//#endregion
|
|
374
|
+
export { type CmsDatabaseChoices, type CmsGitHubPlan, type CmsPresetPlan, type CmsPresetUsage, type CmsWorkspaceImports, hubCms as default };
|