@vite-hub/source 0.0.4 → 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.
Files changed (52) hide show
  1. package/README.md +267 -96
  2. package/dist/client.d.ts +27 -10
  3. package/dist/client.js +99 -15
  4. package/dist/collection-B8sgxw5-.d.ts +290 -0
  5. package/dist/collection-C0Rvrx3p.js +297 -0
  6. package/dist/collection-route-BplWPxHR.js +10 -0
  7. package/dist/drizzle.d.ts +48 -0
  8. package/dist/drizzle.js +87 -0
  9. package/dist/error-diagnostics-ClQKdi7c.js +194 -0
  10. package/dist/github-D5S0dEZe.js +1312 -0
  11. package/dist/{glob.js → glob-DmdMVqjx.js} +154 -57
  12. package/dist/index.d.ts +284 -62
  13. package/dist/index.js +583 -29
  14. package/dist/invariant-DolT9EEx.js +22 -0
  15. package/dist/mcp.d.ts +3 -4
  16. package/dist/mcp.js +184 -5917
  17. package/dist/object-CtSHeGQO.js +17 -0
  18. package/dist/{path-CUhvUREm.js → path-DFlSryRA.js} +90 -40
  19. package/dist/root-DJNmqCEW.js +11 -0
  20. package/dist/server.d.ts +24 -11
  21. package/dist/server.js +97 -26
  22. package/dist/types-Ln-FxVFn.d.ts +98 -0
  23. package/dist/vite.d.ts +202 -14
  24. package/dist/vite.js +1683 -122
  25. package/package.json +55 -58
  26. package/dist/auth-Ddw55OUG.js +0 -1261
  27. package/dist/client-CDfTmtQu.js +0 -7903
  28. package/dist/collection-B8pXGM2d.js +0 -141
  29. package/dist/collection-CF2ON__k.d.ts +0 -92
  30. package/dist/collection-route-Dw7QLFyx.js +0 -6
  31. package/dist/content/client.d.ts +0 -3
  32. package/dist/content/client.js +0 -2
  33. package/dist/content.d.ts +0 -44
  34. package/dist/content.js +0 -157
  35. package/dist/file-BSWQg9Qv.js +0 -503
  36. package/dist/file-EQ3AjVM6.d.ts +0 -20
  37. package/dist/file.d.ts +0 -2
  38. package/dist/file.js +0 -2
  39. package/dist/github.d.ts +0 -17
  40. package/dist/github.js +0 -1033
  41. package/dist/glob.d.ts +0 -15
  42. package/dist/markdown.d.ts +0 -7
  43. package/dist/markdown.js +0 -10
  44. package/dist/path-BzmU4Eni.js +0 -36
  45. package/dist/registry-C8skfCSV.js +0 -120
  46. package/dist/sse-CE9Q2JqM.js +0 -407
  47. package/dist/streamableHttp-BszaXLmg.js +0 -491
  48. package/dist/types-AIBmt_m6.js +0 -6275
  49. package/dist/types-Bu3WvNX9.d.ts +0 -71
  50. package/tsconfig.vite.json +0 -6
  51. package/types/source/fallback.d.ts +0 -1
  52. package/types/source/index.d.ts +0 -1
package/dist/vite.d.ts CHANGED
@@ -1,21 +1,135 @@
1
1
  import { Plugin } from "vite";
2
-
2
+ //#region ../internal/src/inspect.d.ts
3
+ interface ViteHubDefinitionField {
4
+ label: string;
5
+ value: string;
6
+ }
7
+ /** Serializable summary of one discovered Definition. Files are relative to the project root. */
8
+ interface ViteHubDefinitionSummary {
9
+ fields: readonly ViteHubDefinitionField[];
10
+ file: string;
11
+ name: string;
12
+ source: string;
13
+ }
14
+ /** Lists the Definitions that one owner package discovered for the resolved Vite config. */
15
+ interface ViteHubDefinitionInspector {
16
+ /** Stable singular kind, for example `queue` or `rate-limit`. */
17
+ kind: string;
18
+ label: string;
19
+ list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
20
+ }
21
+ /** One generated Provider Output file or directory that an owner package can write. */
22
+ interface ViteHubProviderOutputEntry {
23
+ description: string;
24
+ owner: string;
25
+ /** Absolute path. */
26
+ path: string;
27
+ }
28
+ /**
29
+ * Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
30
+ * The CLI sets `provider-output` when only a generated Wrangler config names the id.
31
+ */
32
+ type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
33
+ /** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
34
+ interface ViteHubResourceSummary {
35
+ /** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
36
+ binding?: string;
37
+ /** Definition or store name. */
38
+ definition: string;
39
+ /** Env variable that supplied the id when `source` is `env`. */
40
+ env?: string;
41
+ host: "cloudflare" | "vercel";
42
+ id?: string;
43
+ /** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
44
+ kind: string;
45
+ /** Resource name on the host, when the config names it. */
46
+ name?: string;
47
+ /** Explains how the host finds the resource when no id or name is known locally. */
48
+ note?: string;
49
+ owner: string;
50
+ /** Absent when no id is known yet. */
51
+ source?: ViteHubResourceIdSource;
52
+ }
53
+ interface ViteHubInspectionContributor {
54
+ definitions?: readonly ViteHubDefinitionInspector[];
55
+ providerOutput?: readonly ViteHubProviderOutputEntry[];
56
+ resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
57
+ }
58
+ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
59
+ interface ViteHubInspectionPluginMetadata {
60
+ inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
61
+ }
62
+ //#endregion
63
+ //#region src/inspect.d.ts
64
+ interface CollectionInspectionOptions {
65
+ projectRoot: string;
66
+ /** Server directories, relative to `projectRoot` or absolute. Defaults to `server`. */
67
+ serverDirs?: string[];
68
+ }
69
+ /**
70
+ * Lists Collections in `server/collections` with their source kind and static options. It reads the module text and
71
+ * does not import it, so values that are computed at runtime show as `Dynamic`.
72
+ */
73
+ export declare function inspectCollectionDefinitions(options: CollectionInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
74
+ //#endregion
3
75
  //#region src/vite.d.ts
4
- interface GeneratedSourceHandler {
76
+ /** A file ViteHub generates for Nitro: a route handler, or a Nitro plugin such as the Content preview scope. */
77
+ export type GeneratedSourceHandler = GeneratedSourceRoute | GeneratedSourcePlugin;
78
+ export interface GeneratedSourceRoute {
5
79
  handler: string;
6
- method?: "get";
80
+ method?: "get" | "post";
81
+ /** Runs for every request and passes through when it does not answer, as Content's `<url>.md` copies do. */
82
+ middleware?: true;
83
+ /**
84
+ * `false` loads the handler when the server starts. Middleware that reads the response of later handlers needs it,
85
+ * because a lazy handler does not receive `next`. Such a handler must load heavy modules itself, on demand.
86
+ */
87
+ lazy?: false;
88
+ plugin?: never;
7
89
  route: string;
8
90
  }
9
- interface SourceGenerationOptions {
91
+ /** A generated Nitro plugin. It registers no route, so it never conflicts with one. */
92
+ export interface GeneratedSourcePlugin {
93
+ handler: string;
94
+ method?: never;
95
+ plugin: true;
96
+ /** Install request interception before an async plugin can let the server accept requests. */
97
+ position?: "start" | "end";
98
+ route?: never;
99
+ }
100
+ export interface SourceGenerationOptions {
101
+ /** Pass Auth's `withAuthorization` to generated Collection routes. Requires the Auth Vite plugin. */
102
+ auth?: boolean;
103
+ /** The routes that the app serves for the whole site, with the Content pages, so Content does not add them. */
104
+ appSeo?: {
105
+ sitemap?: boolean;
106
+ robots?: boolean;
107
+ };
108
+ contentImportBase?: string;
10
109
  importBase?: string;
11
110
  projectRoot: string;
12
111
  serverDirs?: string[];
13
112
  }
14
- interface SourceVitePluginOptions {
113
+ export interface SourceVitePluginOptions {
114
+ /** Pass Auth's `withAuthorization` to generated Collection routes when the Auth Vite plugin has a Definition. */
115
+ auth?: boolean | ((input: {
116
+ projectRoot: string;
117
+ serverDirs?: string[];
118
+ }) => boolean);
119
+ /** The routes that the app serves for the whole site, with the Content pages, so Content does not add them. */
120
+ appSeo?: {
121
+ sitemap?: boolean;
122
+ robots?: boolean;
123
+ };
124
+ contentImportBase?: string;
15
125
  importBase?: string;
16
126
  }
17
- type GeneratedSourceHandlersListener = (handlers: GeneratedSourceHandler[]) => Promise<void> | void;
18
- interface GeneratedSourceHandlersListenerOptions {
127
+ /** The discovered `server/content.ts` file. Its default export is the Content runtime. */
128
+ export interface ContentDefinitionFile {
129
+ handler: string;
130
+ }
131
+ export type GeneratedSourceHandlersListener = (handlers: GeneratedSourceHandler[]) => Promise<void> | void;
132
+ export interface GeneratedSourceHandlersListenerOptions {
19
133
  handlesHostRestart?: boolean;
20
134
  projectRoot?: string;
21
135
  }
@@ -23,19 +137,93 @@ interface NitroGeneratedConfig {
23
137
  handlers?: Array<{
24
138
  handler: string;
25
139
  method?: string;
140
+ middleware?: boolean;
26
141
  route?: string;
27
142
  }>;
28
143
  modules?: unknown[];
144
+ plugins?: unknown[];
145
+ }
146
+ interface SourceNitroHost extends NitroRouteGuard {
147
+ options: NitroGeneratedConfig & NonNullable<NitroRouteGuard["options"]>;
148
+ routing: {
149
+ sync(): void;
150
+ };
151
+ }
152
+ interface NitroRouteGuard {
153
+ options?: {
154
+ dev?: boolean;
155
+ runtimeConfig?: Record<string, unknown>;
156
+ };
157
+ hooks: {
158
+ hook(name: "build:before" | "close", callback: () => void | Promise<void>): void;
159
+ };
160
+ scannedHandlers: Array<{
161
+ method?: string;
162
+ middleware?: boolean;
163
+ route?: string;
164
+ }>;
29
165
  }
30
- declare function mergeGeneratedSourceNitroConfig(value: unknown, generatedHandlers: GeneratedSourceHandler[]): NitroGeneratedConfig;
31
- declare function toRuntimeModuleSpecifier(file: string): string;
32
- declare function toTypeModuleSpecifier(file: string): string;
33
- declare function prepareSourceGeneration(options: SourceGenerationOptions): Promise<GeneratedSourceHandler[]>;
34
- declare function hubSource(options?: SourceVitePluginOptions): Plugin & {
166
+ export declare function mergeGeneratedSourceNitroConfig(value: unknown, generatedHandlers: GeneratedSourceHandler[]): NitroGeneratedConfig;
167
+ export declare function toRuntimeModuleSpecifier(file: string): string;
168
+ export declare function toTypeModuleSpecifier(file: string): string;
169
+ /** Inspects the named Collection export without running application code. The docs snippet check calls it. */
170
+ export declare function inspectCollectionModule(file: string, source: string, exportName: string): {
171
+ exported: boolean;
172
+ routeEnabled: boolean;
173
+ };
174
+ /**
175
+ * Find the `server/content.{ts,js}` file whose default export is the application Content runtime. Returns undefined when
176
+ * the project has none. The generated `/api/content/**` route and the Console content editor import the same file.
177
+ */
178
+ export declare function findContentEntry(options: Pick<SourceGenerationOptions, "projectRoot" | "serverDirs">): Promise<string | undefined>;
179
+ /** What a Content module's `defineContent()` call may define, as far as reading the file without running it can tell. */
180
+ export interface ContentEntryFeatures {
181
+ /** Public HTTP route. True unless `route` is literally false. */
182
+ route: boolean;
183
+ /** Editable `collections`. True when discovery cannot follow the options. */
184
+ collections: boolean;
185
+ /** `seo: { sitemap }` that is not literally false. */
186
+ sitemap: boolean;
187
+ /** `seo: { robots }` that is not literally false. */
188
+ robots: boolean;
189
+ /** `seo: { markdown }` that is not literally false, or `seo: { llms }` on, whose links need the Markdown copies. */
190
+ markdown: boolean;
191
+ /** `seo: { rss }` that is not literally false. */
192
+ rss: boolean;
193
+ /** Whether `seo.mcp` is enabled, or unknown when discovery cannot follow its value. */
194
+ mcp: boolean | "unknown";
195
+ /** `seo: { llms }` that is not literally false. */
196
+ llms: boolean;
197
+ /** `live` that is not literally false: Content edits Markdown documents live where Realtime has a room authority. */
198
+ live: boolean;
199
+ /** `previews` that is set and not literally false: Content serves refs of its `github()` Source at `/tree`, `/blob`, and `/pr` URLs. */
200
+ previews: boolean;
201
+ /** The module imports `sqlite` from `vite-hub/content/sqlite`, so SQLite WASM must load when a Worker starts. */
202
+ sqlite: boolean;
203
+ /** The module imports `github` from `vite-hub/source`, so a push webhook route can move the head of its Sources. */
204
+ github: boolean;
205
+ }
206
+ /**
207
+ * Read the `defineContent()` call that the default export holds. Collections count as present unless the call
208
+ * provably has no non-empty `collections` object. SEO routes count only when the call has a `seo` option: a literal
209
+ * `sitemap`, `robots`, `markdown`, `rss`, `mcp`, or `llms` that is not `false`, or a `seo` value that discovery cannot follow.
210
+ */
211
+ export declare function inspectContentModule(program: unknown, contentImportBase?: string): ContentEntryFeatures;
212
+ /** Read what the Content module defines without running it. A file that does not parse counts as defining everything. */
213
+ export declare function inspectContentEntry(file: string, contentImportBase?: string): Promise<ContentEntryFeatures>;
214
+ export declare function prepareSourceGeneration(options: SourceGenerationOptions): Promise<GeneratedSourceHandler[]>;
215
+ export declare function hubSource(options?: SourceVitePluginOptions): Plugin & {
35
216
  api: {
217
+ /** The `server/content.ts` file found by the last preparation of `projectRoot` (default: the latest root). */
218
+ getContentDefinition: (projectRoot?: string) => ContentDefinitionFile | undefined;
36
219
  onGeneratedHandlersChanged: (listener: GeneratedSourceHandlersListener, options?: GeneratedSourceHandlersListenerOptions) => () => void;
37
- prepareSources: (options: Omit<SourceGenerationOptions, "importBase">) => Promise<GeneratedSourceHandler[]>;
220
+ prepareSources: (options: Omit<SourceGenerationOptions, "appSeo" | "auth" | "contentImportBase" | "importBase">) => Promise<GeneratedSourceHandler[]>;
221
+ };
222
+ nitro: {
223
+ name: string;
224
+ setup(nitro: SourceNitroHost): Promise<void>;
38
225
  };
226
+ vitehub: ViteHubInspectionPluginMetadata;
39
227
  };
40
228
  //#endregion
41
- export { GeneratedSourceHandler, GeneratedSourceHandlersListener, GeneratedSourceHandlersListenerOptions, SourceGenerationOptions, SourceVitePluginOptions, hubSource, mergeGeneratedSourceNitroConfig, prepareSourceGeneration, toRuntimeModuleSpecifier, toTypeModuleSpecifier };
229
+ export type { CollectionInspectionOptions };