@vite-hub/source 0.1.0 → 0.3.1

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 (48) hide show
  1. package/README.md +83 -49
  2. package/dist/client.d.ts +1 -1
  3. package/dist/client.js +30 -4
  4. package/dist/{collection-B_4w_J8h.d.ts → collection-B8sgxw5-.d.ts} +52 -19
  5. package/dist/collection-C0Rvrx3p.js +297 -0
  6. package/dist/drizzle.d.ts +11 -4
  7. package/dist/drizzle.js +6 -8
  8. package/dist/error-diagnostics-ClQKdi7c.js +194 -0
  9. package/dist/github-D5S0dEZe.js +1312 -0
  10. package/dist/{glob-BmFqTvJY.js → glob-DmdMVqjx.js} +1 -2
  11. package/dist/index.d.ts +186 -55
  12. package/dist/index.js +152 -207
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/mcp.d.ts +1 -1
  15. package/dist/mcp.js +25 -140
  16. package/dist/object-CtSHeGQO.js +17 -0
  17. package/dist/{path-BS8rYm0n.js → path-DFlSryRA.js} +32 -2
  18. package/dist/root-DJNmqCEW.js +11 -0
  19. package/dist/server.d.ts +7 -244
  20. package/dist/server.js +38 -45
  21. package/dist/{types-BigOktIj.d.ts → types-Ln-FxVFn.d.ts} +6 -1
  22. package/dist/vite.d.ts +77 -10
  23. package/dist/vite.js +619 -713
  24. package/package.json +25 -47
  25. package/dist/auth-B-tX_rp0.js +0 -1426
  26. package/dist/client-BwstxtdY.js +0 -8280
  27. package/dist/collection-cursor-WzV1Jd6v.js +0 -124
  28. package/dist/error-diagnostics-X0kuFjBT.js +0 -51
  29. package/dist/file-BX0FSvgE.js +0 -60
  30. package/dist/file-DadN9dbN.d.ts +0 -19
  31. package/dist/file.d.ts +0 -2
  32. package/dist/file.js +0 -2
  33. package/dist/files.d.ts +0 -15
  34. package/dist/files.js +0 -38
  35. package/dist/github.d.ts +0 -20
  36. package/dist/github.js +0 -1332
  37. package/dist/glob.d.ts +0 -23
  38. package/dist/glob.js +0 -2
  39. package/dist/markdown.d.ts +0 -5
  40. package/dist/markdown.js +0 -10
  41. package/dist/mrmime-40h5OOIp.js +0 -448
  42. package/dist/path-DOBpV8ol.js +0 -32
  43. package/dist/sse-D9gqqNPj.js +0 -448
  44. package/dist/streamableHttp-BL-E7pl5.js +0 -509
  45. package/dist/types-CoWcW8oz.js +0 -7590
  46. package/tsconfig.vite.json +0 -6
  47. package/types/source/fallback.d.ts +0 -1
  48. package/types/source/index.d.ts +0 -1
@@ -0,0 +1,297 @@
1
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
2
+ import { t as isPlainRecord } from "./object-CtSHeGQO.js";
3
+ import { Diagnostic } from "nostics";
4
+ //#region src/core/schema.ts
5
+ async function parseCollectionSchema(schema, value) {
6
+ const result = await schema["~standard"].validate(value);
7
+ if (result.issues) throw sourceErrorDiagnostics.SOURCE_R0006({ message: result.issues[0]?.message ?? "Collection value is invalid." });
8
+ return result.value;
9
+ }
10
+ //#endregion
11
+ //#region src/core/collection-cursor.ts
12
+ /** A Collection cursor was rejected. Routes answer `400` for `malformed` and `409` for `stale`. */
13
+ var CollectionCursorError = class CollectionCursorError extends Diagnostic {
14
+ reason;
15
+ constructor(message, options) {
16
+ const reason = options?.reason ?? "malformed";
17
+ super({
18
+ cause: options?.cause,
19
+ code: reason === "stale" ? "SOURCE_R0027" : "SOURCE_R0023",
20
+ fix: (reason === "stale" ? sourceErrorDiagnostics.SOURCE_R0027 : sourceErrorDiagnostics.SOURCE_R0023)({ message: "" }).fix,
21
+ docs: `https://vitehub.dev/docs/source/diagnostics/${reason === "stale" ? "source_r0027" : "source_r0023"}`,
22
+ why: message ?? (reason === "stale" ? "[vitehub] Collection cursor is stale. Its data or query changed; reload from the first page." : "[vitehub] Collection cursor is malformed.")
23
+ }, CollectionCursorError);
24
+ this.name = "CollectionCursorError";
25
+ this.reason = reason;
26
+ }
27
+ };
28
+ function encodeBase64Url(value) {
29
+ const bytes = new TextEncoder().encode(value);
30
+ let binary = "";
31
+ for (const byte of bytes) binary += String.fromCharCode(byte);
32
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
33
+ }
34
+ /** The decoded text, or undefined for a value that is not canonical unpadded base64url. */
35
+ function decodeBase64Url(value) {
36
+ if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) return;
37
+ const normalized = value.replaceAll("-", "+").replaceAll("_", "/");
38
+ const binary = atob(normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "="));
39
+ if (btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "") !== value) return;
40
+ return new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(binary, (character) => character.charCodeAt(0)));
41
+ }
42
+ function isRuntimeObject(value) {
43
+ return value !== null && Object(value) === value;
44
+ }
45
+ function isCursorValue(value, ancestors = /* @__PURE__ */ new Set()) {
46
+ if (typeof value === "number") return Number.isFinite(value) && !Object.is(value, -0);
47
+ if (value === null || value === true || value === false || typeof value === "string") return true;
48
+ if (!isRuntimeObject(value) || ancestors.has(value)) return false;
49
+ ancestors.add(value);
50
+ try {
51
+ if (Array.isArray(value)) {
52
+ const keys = Reflect.ownKeys(value);
53
+ if (keys.length !== value.length + 1 || keys.some((key) => key !== "length" && typeof key !== "string")) return false;
54
+ for (let index = 0; index < value.length; index += 1) {
55
+ const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
56
+ if (!descriptor?.enumerable || !("value" in descriptor) || !isCursorValue(descriptor.value, ancestors)) return false;
57
+ }
58
+ return true;
59
+ }
60
+ if (!isPlainRecord(value)) return false;
61
+ for (const key of Reflect.ownKeys(value)) {
62
+ if (typeof key !== "string") return false;
63
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
64
+ if (!descriptor?.enumerable || !("value" in descriptor) || !isCursorValue(descriptor.value, ancestors)) return false;
65
+ }
66
+ return true;
67
+ } catch {
68
+ return false;
69
+ } finally {
70
+ ancestors.delete(value);
71
+ }
72
+ }
73
+ function encodeCursor(value) {
74
+ if (!isCursorValue(value)) throw sourceErrorDiagnostics.SOURCE_R0005({ message: "[vitehub] Collection cursor() must return a JSON-serializable value." });
75
+ return encodeBase64Url(JSON.stringify(value));
76
+ }
77
+ async function decodeCursor(value, schema) {
78
+ if (value === void 0) return;
79
+ let decoded;
80
+ try {
81
+ const text = decodeBase64Url(value);
82
+ decoded = text === void 0 ? void 0 : JSON.parse(text);
83
+ } catch (cause) {
84
+ throw new CollectionCursorError(void 0, { cause });
85
+ }
86
+ if (!isCursorValue(decoded)) throw new CollectionCursorError();
87
+ let cursor;
88
+ try {
89
+ cursor = await parseCollectionSchema(schema, decoded);
90
+ } catch (cause) {
91
+ throw new CollectionCursorError(void 0, { cause });
92
+ }
93
+ if (!isCursorValue(cursor)) throw new CollectionCursorError();
94
+ return cursor;
95
+ }
96
+ /** Bind cursor transport and validation to the Collection's schema once. */
97
+ function createCollectionCursorCodec(schema) {
98
+ return {
99
+ encode(value) {
100
+ return encodeCursor(value);
101
+ },
102
+ decode(value) {
103
+ return decodeCursor(value, schema);
104
+ }
105
+ };
106
+ }
107
+ //#endregion
108
+ //#region src/core/collection.ts
109
+ const untransformedTableRows = Symbol.for("@vite-hub/source/untransformed-table-rows");
110
+ const defaultPageLimit = 50;
111
+ const defaultMaxLimit = 100;
112
+ function isCollectionFacets(value) {
113
+ return Object(value) === value && !Array.isArray(value) && Object.values(Object(value)).every((entries) => Array.isArray(entries) && entries.every((entry) => Object(entry) === entry && String(Reflect.get(entry, "value")) === Reflect.get(entry, "value") && Number.isSafeInteger(Reflect.get(entry, "count")) && Number(Reflect.get(entry, "count")) >= 0));
114
+ }
115
+ function assertPositiveInteger(value, label) {
116
+ if (!Number.isSafeInteger(value) || value < 1) throw sourceErrorDiagnostics.SOURCE_R0004({ message: `[vitehub] Collection ${label} must be a positive integer.` });
117
+ }
118
+ function resolveLimit(limit, defaultLimit, maxLimit) {
119
+ if (limit !== void 0) assertPositiveInteger(limit, "limit");
120
+ return Math.min(limit ?? defaultLimit, maxLimit);
121
+ }
122
+ function defineCollection(input, options) {
123
+ const [load, definition] = typeof input === "function" ? [input, options] : sourceDefinition(input);
124
+ if (!definition) throw sourceErrorDiagnostics.SOURCE_R0009({ message: "[vitehub] defineCollection() requires a loader with options, or { source }." });
125
+ const defaultLimit = definition.defaultLimit ?? defaultPageLimit;
126
+ const maxLimit = definition.maxLimit ?? defaultMaxLimit;
127
+ assertPositiveInteger(defaultLimit, "defaultLimit");
128
+ assertPositiveInteger(maxLimit, "maxLimit");
129
+ if (defaultLimit > maxLimit) throw sourceErrorDiagnostics.SOURCE_R0008({ message: "[vitehub] Collection defaultLimit cannot exceed maxLimit." });
130
+ const cursorDefinition = "cursorSchema" in definition ? definition : void 0;
131
+ const cursorCodec = cursorDefinition ? createCollectionCursorCodec(cursorDefinition.cursorSchema) : void 0;
132
+ const { access, authorize } = assertCollectionAccess(definition);
133
+ const collection = {
134
+ ...access === void 0 ? {} : { access },
135
+ ...authorize === void 0 ? {} : { authorize },
136
+ route: definition.route,
137
+ async page(request) {
138
+ request.signal?.throwIfAborted();
139
+ const limit = resolveLimit(request.limit, defaultLimit, maxLimit);
140
+ if (!cursorDefinition || !cursorCodec) {
141
+ const result = await load({
142
+ cursor: request.cursor,
143
+ limit,
144
+ query: request.query,
145
+ signal: request.signal
146
+ });
147
+ request.signal?.throwIfAborted();
148
+ if (!result || !Array.isArray(result.items) || result.nextCursor !== null && !isProviderCursor(result.nextCursor)) throw sourceErrorDiagnostics.SOURCE_R0009({ message: "[vitehub] Provider Collection load() must return items and nextCursor." });
149
+ const transformedItems = definition.transform ? await Promise.all(result.items.map(definition.transform)) : result.items;
150
+ request.signal?.throwIfAborted();
151
+ const page = {
152
+ items: transformedItems,
153
+ nextCursor: result.nextCursor
154
+ };
155
+ if (result.total !== void 0) {
156
+ if (!Number.isSafeInteger(result.total) || result.total < 0) throw sourceErrorDiagnostics.SOURCE_R0009({ message: "[vitehub] Provider Collection total must be a non-negative integer." });
157
+ page.total = result.total;
158
+ }
159
+ if (result.facets !== void 0) {
160
+ if (!isCollectionFacets(result.facets)) throw sourceErrorDiagnostics.SOURCE_R0009({ message: "[vitehub] Provider Collection facets must map fields to { value, count } lists." });
161
+ page.facets = result.facets;
162
+ }
163
+ return page;
164
+ }
165
+ const decodedCursor = await cursorCodec.decode(request.cursor);
166
+ request.signal?.throwIfAborted();
167
+ const sourceItems = await load({
168
+ cursor: decodedCursor,
169
+ limit: limit + 1,
170
+ query: request.query,
171
+ signal: request.signal
172
+ });
173
+ request.signal?.throwIfAborted();
174
+ if (!Array.isArray(sourceItems)) throw sourceErrorDiagnostics.SOURCE_R0009({ message: "[vitehub] Collection load() must return an array." });
175
+ const hasMore = sourceItems.length > limit;
176
+ const pageItems = sourceItems.slice(0, limit);
177
+ const nextCursor = hasMore && pageItems.length ? cursorCodec.encode(cursorDefinition.cursor(pageItems[pageItems.length - 1])) : null;
178
+ const transformedItems = definition.transform ? await Promise.all(pageItems.map(definition.transform)) : pageItems;
179
+ request.signal?.throwIfAborted();
180
+ return {
181
+ items: transformedItems,
182
+ nextCursor
183
+ };
184
+ },
185
+ async parseQuery(input) {
186
+ if (definition.querySchema) return await parseCollectionSchema(definition.querySchema, input);
187
+ return input;
188
+ },
189
+ query(input = {}) {
190
+ const project = (item, keys) => keys ? Object.fromEntries(keys.map((key) => [key, item[key]])) : item;
191
+ const build = (keys) => ({
192
+ select(...selected) {
193
+ return build(selected);
194
+ },
195
+ async page(options = {}) {
196
+ options.signal?.throwIfAborted();
197
+ const query = await collection.parseQuery(input);
198
+ const result = await collection.page({
199
+ ...options,
200
+ query
201
+ });
202
+ return {
203
+ ...result,
204
+ items: result.items.map((item) => project(item, keys))
205
+ };
206
+ },
207
+ async all(options = {}) {
208
+ options.signal?.throwIfAborted();
209
+ const items = [];
210
+ const query = await collection.parseQuery(input);
211
+ let cursor;
212
+ const seen = /* @__PURE__ */ new Set();
213
+ do {
214
+ options.signal?.throwIfAborted();
215
+ const result = await collection.page({
216
+ ...options,
217
+ cursor,
218
+ query
219
+ });
220
+ for (const item of result.items) items.push(project(item, keys));
221
+ cursor = result.nextCursor ?? void 0;
222
+ if (cursor !== void 0) {
223
+ if (seen.has(cursor)) throw new CollectionCursorError("[vitehub] Collection loader repeated a pagination cursor.");
224
+ seen.add(cursor);
225
+ }
226
+ } while (cursor !== void 0);
227
+ return items;
228
+ }
229
+ });
230
+ return build();
231
+ },
232
+ async all(options = {}) {
233
+ return collection.query(options.query).all(options);
234
+ },
235
+ ...definition.querySchema ? { querySchema: definition.querySchema } : {}
236
+ };
237
+ const get = definition.get;
238
+ if (get) {
239
+ const lookup = async (key, options) => {
240
+ options?.signal?.throwIfAborted();
241
+ const item = await get(key, options ?? {});
242
+ options?.signal?.throwIfAborted();
243
+ if (item === null || item === void 0) return item;
244
+ const result = definition.transform ? await definition.transform(item) : item;
245
+ options?.signal?.throwIfAborted();
246
+ return result;
247
+ };
248
+ Object.assign(collection, { get: lookup });
249
+ }
250
+ if (typeof input !== "function" && input.source.rawRows === true && definition.transform === void 0) Object.defineProperty(collection.page, untransformedTableRows, { value: true });
251
+ return collection;
252
+ }
253
+ function sourceDefinition(input) {
254
+ const { access, authorize, route, source, transform } = input;
255
+ if (Object(source) !== source || typeof source.load !== "function") throw sourceErrorDiagnostics.SOURCE_R0009({ message: "[vitehub] defineCollection({ source }) requires a Collection source with load()." });
256
+ if (source.rawRows === true && access === "public" && route !== false && transform === void 0) throw sourceErrorDiagnostics.SOURCE_COLLECTION_PUBLIC_TRANSFORM_REQUIRED();
257
+ const shared = {
258
+ access,
259
+ authorize,
260
+ route,
261
+ get: source.get,
262
+ defaultLimit: source.defaultLimit,
263
+ maxLimit: source.maxLimit,
264
+ querySchema: source.querySchema,
265
+ transform
266
+ };
267
+ return source.pagination === "provider" ? [source.load, {
268
+ ...shared,
269
+ pagination: "provider"
270
+ }] : [source.load, {
271
+ ...shared,
272
+ cursor: source.cursor,
273
+ cursorSchema: source.cursorSchema
274
+ }];
275
+ }
276
+ /**
277
+ * Checks who can read a Collection route and returns the checked values. `defineCollectionHandler()` runs it again
278
+ * for Collection objects that did not come from `defineCollection()`.
279
+ */
280
+ function assertCollectionAccess(definition) {
281
+ const { access, authorize } = definition;
282
+ if (authorize === false) throw sourceErrorDiagnostics.SOURCE_COLLECTION_AUTHORIZE_FALSE();
283
+ if (authorize !== void 0 && authorize !== true && typeof authorize !== "function") throw sourceErrorDiagnostics.SOURCE_R0024({ message: "[vitehub] Collection authorize must be true or a function." });
284
+ if (access !== void 0 && access !== "public") throw sourceErrorDiagnostics.SOURCE_R0024({ message: "[vitehub] Collection access must be \"public\" when it is set." });
285
+ if (access === "public" && authorize !== void 0) throw sourceErrorDiagnostics.SOURCE_COLLECTION_ACCESS_CONFLICT();
286
+ if (access === void 0 && authorize === void 0 && definition.route !== false) throw sourceErrorDiagnostics.SOURCE_COLLECTION_ACCESS_REQUIRED();
287
+ if (access === "public" && definition.route !== false && typeof definition.page === "function" && Reflect.get(definition.page, untransformedTableRows) === true) throw sourceErrorDiagnostics.SOURCE_COLLECTION_PUBLIC_TRANSFORM_REQUIRED();
288
+ return {
289
+ access,
290
+ authorize
291
+ };
292
+ }
293
+ function isProviderCursor(value) {
294
+ return value === String(value);
295
+ }
296
+ //#endregion
297
+ export { parseCollectionSchema as a, createCollectionCursorCodec as i, defineCollection as n, CollectionCursorError as r, assertCollectionAccess as t };
package/dist/drizzle.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { g as CollectionQueryInput, v as CollectionRequestQuery, y as CollectionSource } from "./collection-B_4w_J8h.js";
1
+ import { _ as CollectionQueryInput, b as CollectionSource, y as CollectionRequestQuery } from "./collection-B8sgxw5-.js";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
3
  //#region src/drizzle.d.ts
4
4
  interface TableShape {
@@ -31,11 +31,18 @@ export interface TableSourceOptions<TTable extends TableShape, TQuerySchema exte
31
31
  } | undefined;
32
32
  }
33
33
  type KeysetCursor = readonly (boolean | null | number | string)[];
34
- /** Read a Drizzle SQLite table as a Collection source with keyset pagination. */
34
+ /**
35
+ * Read a Drizzle SQLite table as a Collection source with keyset pagination. It selects every column, so a public
36
+ * Collection (`access: "public"`) over it must pick the public fields with `transform`.
37
+ */
35
38
  export declare function table<TTable extends TableShape, TQuerySchema extends StandardSchemaV1<unknown, object>>(options: TableSourceOptions<TTable, TQuerySchema> & {
36
39
  querySchema: TQuerySchema;
37
- }): CollectionSource<TTable["$inferSelect"], StandardSchemaV1.InferOutput<TQuerySchema>, KeysetCursor, KeysetCursor, QueryInput<TQuerySchema>>;
40
+ }): CollectionSource<TTable["$inferSelect"], StandardSchemaV1.InferOutput<TQuerySchema>, KeysetCursor, KeysetCursor, QueryInput<TQuerySchema>> & {
41
+ rawRows: true;
42
+ };
38
43
  export declare function table<TTable extends TableShape>(options: TableSourceOptions<TTable> & {
39
44
  querySchema?: undefined;
40
- }): CollectionSource<TTable["$inferSelect"], CollectionRequestQuery, KeysetCursor>;
45
+ }): CollectionSource<TTable["$inferSelect"], CollectionRequestQuery, KeysetCursor> & {
46
+ rawRows: true;
47
+ };
41
48
  //#endregion
package/dist/drizzle.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
1
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
2
2
  import { and, asc, desc, eq, getTableColumns, gt, lt, or } from "drizzle-orm";
3
3
  //#region src/drizzle.ts
4
4
  const requestQuerySchema = { "~standard": {
@@ -13,12 +13,9 @@ function isCursorScalar(value) {
13
13
  return value === null || value === true || value === false || String(value) === value || Number(value) === value && Number.isFinite(Number(value));
14
14
  }
15
15
  function driverType(column) {
16
- if ([
17
- "boolean",
18
- "date",
19
- "number"
20
- ].includes(column.dataType)) return "number";
21
- if (column.dataType === "string") return "string";
16
+ const [type, constraint] = column.dataType.split(" ");
17
+ if (type === "boolean" || type === "number" || type === "object" && constraint === "date") return "number";
18
+ if (type === "string") return "string";
22
19
  throw sourceErrorDiagnostics.SOURCE_R0029({ message: "[vitehub] Collection orderBy columns must encode as number or string values." });
23
20
  }
24
21
  function isColumnDriverValue(column, type, value) {
@@ -82,7 +79,8 @@ function table(input) {
82
79
  return rows;
83
80
  },
84
81
  maxLimit: options.maxLimit,
85
- querySchema
82
+ querySchema,
83
+ rawRows: true
86
84
  };
87
85
  }
88
86
  //#endregion
@@ -0,0 +1,194 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const sourceErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: "https://vitehub.dev/docs/source/diagnostics",
6
+ codes: {
7
+ SOURCE_COLLECTION_ACCESS_CONFLICT: {
8
+ why: "[vitehub] A Collection cannot set both `access: \"public\"` and `authorize`.",
9
+ fix: "Keep `access: \"public\"` to let anyone read the route, or keep `authorize` to check each request. Remove the other."
10
+ },
11
+ SOURCE_COLLECTION_ACCESS_REQUIRED: {
12
+ why: "[vitehub] A routed Collection must set authorize or access. Without one, the generated /api route would serve every item to anyone.",
13
+ fix: "Set `authorize: true` to require a signed-in session, a callback to decide each request, or `access: \"public\"` for a public route. Set `route: false` to keep the Collection server-only."
14
+ },
15
+ SOURCE_COLLECTION_AUTHORIZE_FALSE: {
16
+ why: "[vitehub] Collection `authorize: false` does not make a route public.",
17
+ fix: "Replace `authorize: false` with `access: \"public\"` to let anyone read the route. Use `authorize: true` or a callback to require sign-in."
18
+ },
19
+ SOURCE_COLLECTION_PUBLIC_TRANSFORM_REQUIRED: {
20
+ why: "[vitehub] A Collection over table() with `access: \"public\"` would serve every column of each row, such as password hashes or emails.",
21
+ fix: "Add `transform` that returns only the public fields, or replace `access: \"public\"` with `authorize: true` or a callback."
22
+ },
23
+ SOURCE_R0023: {
24
+ ...dynamicError,
25
+ fix: "Pass the `cursor` of the last page of this Collection without changes, or omit `cursor` to read the first page."
26
+ },
27
+ SOURCE_R0001: {
28
+ ...dynamicError,
29
+ fix: "Check that only the Collection route of `defineCollectionHandler()` answers at `/api/<name>`, with no other route or proxy there, and that the client and the server use the same `@vite-hub/source` version."
30
+ },
31
+ SOURCE_R0002: {
32
+ ...dynamicError,
33
+ fix: "Check that only the Collection route of `defineCollectionHandler()` answers at `/api/<name>`, with no other route or proxy there, and that the client and the server use the same `@vite-hub/source` version."
34
+ },
35
+ SOURCE_R0003: {
36
+ ...dynamicError,
37
+ fix: "Make the Collection return a different `nextCursor` on each page, such as a `cursor()` that returns the id of the last item."
38
+ },
39
+ SOURCE_R0004: {
40
+ ...dynamicError,
41
+ fix: "Pass `limit`, and `defaultLimit` and `maxLimit` of `defineCollection()`, as whole numbers of 1 or more."
42
+ },
43
+ SOURCE_R0005: {
44
+ ...dynamicError,
45
+ fix: "Return only JSON values from `cursor()` of the Collection: strings, numbers, booleans, null, arrays, and plain objects."
46
+ },
47
+ SOURCE_R0006: {
48
+ ...dynamicError,
49
+ fix: "Change the value that the message names so that the Collection schema accepts it: the item for `array({ schema })`, or the `filter` query for `querySchema`."
50
+ },
51
+ SOURCE_R0008: {
52
+ ...dynamicError,
53
+ fix: "Set `defaultLimit` of `defineCollection()` to a value that is not larger than `maxLimit`."
54
+ },
55
+ SOURCE_R0009: {
56
+ ...dynamicError,
57
+ fix: "Pass `defineCollection()` a loader with options, or `{ source }` with a `load()` method. Return what the message names: an array, `{ items, nextCursor }` from a provider loader, or `{ items, digest }` from the `array()` load."
58
+ },
59
+ SOURCE_R0011: {
60
+ ...dynamicError,
61
+ fix: "Send each Collection query parameter, such as `limit` or `cursor`, at most one time in the URL."
62
+ },
63
+ SOURCE_R0012: {
64
+ ...dynamicError,
65
+ fix: "Send `limit` as a whole number of 1 or more in the Collection URL, such as `?limit=20`."
66
+ },
67
+ SOURCE_R0013: {
68
+ ...dynamicError,
69
+ fix: "Send `limit` as a whole number of 1 or more in the Collection URL, such as `?limit=20`."
70
+ },
71
+ SOURCE_R0014: {
72
+ ...dynamicError,
73
+ fix: "Use `transform` of `defineCollection()` to return plain objects, arrays, and values with `toJSON()`, such as a Date, in place of class instances."
74
+ },
75
+ SOURCE_R0015: {
76
+ ...dynamicError,
77
+ fix: "Use `transform` of `defineCollection()` to return JSON values only. Remove functions, symbols, and `undefined` items from the page."
78
+ },
79
+ SOURCE_R0016: {
80
+ ...dynamicError,
81
+ fix: "Pass `defineCollectionHandler()` a Collection that `defineCollection()` returns."
82
+ },
83
+ SOURCE_R0017: {
84
+ ...dynamicError,
85
+ fix: "Pass `file()` a `path` or a `workspacePath`."
86
+ },
87
+ SOURCE_R0018: {
88
+ ...dynamicError,
89
+ fix: "Pass `file()` a `path` to read, or the `content` of the file."
90
+ },
91
+ SOURCE_R0021: {
92
+ ...dynamicError,
93
+ fix: "Make `mcpResources({ server })` resolve to an MCP client or an MCP client config, such as `{ url }`."
94
+ },
95
+ SOURCE_R0022: {
96
+ ...dynamicError,
97
+ fix: "Pass `mcpResources()` a `server` option with an MCP client, an MCP client config, or a function that returns one."
98
+ },
99
+ SOURCE_R0024: {
100
+ ...dynamicError,
101
+ fix: "Set `authorize` of `defineCollection()` to `true`, or to a function that returns `true`, `false`, or a `Response`."
102
+ },
103
+ SOURCE_R0025: {
104
+ ...dynamicError,
105
+ fix: "Enable Auth with a `server/auth.ts` Auth Definition, or remove `authorize` from the Collection to make it public."
106
+ },
107
+ SOURCE_R0026: {
108
+ ...dynamicError,
109
+ fix: "Sign in before you read this Collection, or change its `authorize` callback so that it allows this user."
110
+ },
111
+ SOURCE_R0027: {
112
+ ...dynamicError,
113
+ fix: "Read the Collection again from the first page without `cursor`, because its data or query changed after that cursor."
114
+ },
115
+ SOURCE_R0028: {
116
+ ...dynamicError,
117
+ fix: "Pass `array()` field paths as non-empty strings in `filters`, `search`, `facets`, `key`, and `sort.field`. Do not name a filter `cursor`, `empty`, `limit`, or `search`."
118
+ },
119
+ SOURCE_R0029: {
120
+ ...dynamicError,
121
+ fix: "Use `orderBy` columns of `table()` that store numbers, strings, booleans, or dates."
122
+ },
123
+ SOURCE_R0030: {
124
+ ...dynamicError,
125
+ fix: "Use `orderBy.column` and `orderBy.tieBreaker` columns from the table that you pass to `table()`."
126
+ },
127
+ SOURCE_R0031: {
128
+ ...dynamicError,
129
+ fix: "Use `orderBy` columns of `table()` whose values the database stores as a number, a string, or a boolean."
130
+ },
131
+ SOURCE_R0032: {
132
+ ...dynamicError,
133
+ fix: "Use `orderBy` columns of `table()` that have `.notNull()` in the Drizzle schema."
134
+ },
135
+ SOURCE_R0033: {
136
+ ...dynamicError,
137
+ fix: "Use a primary key or a `.unique()` column as `orderBy.tieBreaker` of `table()`, such as the `id` column."
138
+ },
139
+ SOURCE_R0034: {
140
+ why: ({ endpoint, status }) => `[vitehub] Collection request to ${endpoint} failed with status ${status}.`,
141
+ fix: "Check the Collection route and server logs for this HTTP status, correct the request or server error, then refresh the Collection."
142
+ },
143
+ SOURCE_B0001: {
144
+ ...dynamicError,
145
+ fix: "Remove the server route that answers the route that the message names. To keep your route, turn off the generated one: set `route: false` in the Collection or in `defineContent()`, or turn off the `seo` option of server/content.ts that adds it."
146
+ },
147
+ SOURCE_B0002: {
148
+ ...dynamicError,
149
+ fix: "Remove the handler for the route that the message names from the Nitro `handlers` config, or from `serverHandlers` in Nuxt. To keep it, turn off the generated route: set `route: false` in the Collection or in `defineContent()`, or turn off the `seo` option of server/content.ts that adds it."
150
+ },
151
+ SOURCE_B0003: {
152
+ ...dynamicError,
153
+ fix: "Rename the Collection file under server/collections/ to a valid JavaScript identifier, such as `posts.ts` or `blog_posts.ts`, without dashes, dots, or a leading digit."
154
+ },
155
+ SOURCE_B0004: {
156
+ ...dynamicError,
157
+ fix: "Export the Collection from the file with the same name as the file: `export const posts = defineCollection(...)` in server/collections/posts.ts."
158
+ },
159
+ SOURCE_B0005: {
160
+ ...dynamicError,
161
+ fix: "Keep each Collection name in one server directory. Rename or remove the file under server/collections/ in one of the server directories, such as a Nuxt layer."
162
+ },
163
+ SOURCE_B0006: {
164
+ ...dynamicError,
165
+ fix: "Rename one of the two Collection files under server/collections/, so that the names are different also when you ignore the letter case."
166
+ },
167
+ SOURCE_B0007: {
168
+ ...dynamicError,
169
+ fix: "Keep one Content file. Remove the other server/content.ts files from the other server directories, such as a Nuxt layer."
170
+ },
171
+ SOURCE_B0008: {
172
+ ...dynamicError,
173
+ fix: "Write `export default defineContent({ ... })` in the Content file that the message names."
174
+ },
175
+ SOURCE_B0009: {
176
+ ...dynamicError,
177
+ fix: "Write `export default defineContent({ ... })` in server/content.ts. Run `npx @vite-hub/codemods define-forms` to move the export and the imports of it."
178
+ },
179
+ SOURCE_B0010: {
180
+ why: ({ route, other }) => `[vitehub] defineContent({ seo: { mcp } }) serves its MCP server at ${JSON.stringify(route)}, and ${other} answers there too.`,
181
+ fix: "One route serves one MCP server. Give the app MCP server another route, such as `vitehub({ mcp: { route: '/mcp/app' } })`, or another `publicRoute`. Or set `seo: { mcp: false }` in server/content.ts."
182
+ },
183
+ SOURCE_GITHUB_ARCHIVE_INVALID: {
184
+ why: "[vitehub] The archive of the github() Source has an entry with an invalid size.",
185
+ fix: "Load the Source again: GitHub or `git archive` sent a cut or broken archive. If it fails again, check the network and that the ref of the `github()` Source exists."
186
+ },
187
+ SOURCE_GLOB_OPTIONS_NOT_LITERAL: {
188
+ why: "glob() here takes options that are not literals, so the build cannot bundle its files. It reads them from disk at runtime, which hosts such as Cloudflare Workers do not have.",
189
+ fix: "Write the options of `glob()` as literals in the call, such as `glob({ cwd: \"content\", include: [\"**/*.md\"] })`, so the build can find and bundle the files."
190
+ }
191
+ }
192
+ });
193
+ //#endregion
194
+ export { sourceErrorDiagnostics as t };