@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
package/README.md CHANGED
@@ -17,8 +17,7 @@ pnpm add @vite-hub/source
17
17
  ## Open a Source
18
18
 
19
19
  ```ts
20
- import { createSource } from "@vite-hub/source"
21
- import { glob } from "@vite-hub/source/glob"
20
+ import { createSource, glob } from "@vite-hub/source"
22
21
 
23
22
  export const docs = glob({ cwd: "docs", include: "**/*.md" })
24
23
 
@@ -82,16 +81,44 @@ and `exists()`. File readers also expose `read()` and `list()`. Built-in `file`,
82
81
  Their `SourceFile` items guarantee `content`. Custom loaders that guarantee
83
82
  content receive file methods too. Record readers use `get()` and `items()`.
84
83
 
85
- `github()` reads GitHub through `@vite-hub/forge`. `auth` is a token or a trusted
84
+ `github()` reads GitHub through `@vite-hub/forge`, an optional peer that it loads on the first read. Install it with
85
+ `pnpm add @vite-hub/forge`. `auth` is a token or a trusted
86
86
  callback. Without `auth`, it reads Server Env `VITEHUB_GITHUB_TOKEN`, then
87
87
  `FORGES_GITHUB_TOKEN`. It does not read `GH_TOKEN` or `GITHUB_TOKEN`.
88
- `auth: false` reads without a token.
88
+ `auth: false` reads without a token. `authenticated()` tells whether reads send a
89
+ token. Content serves a `github()` Source from a validated head commit only when
90
+ it does.
91
+
92
+ `history(key, { sha, page, perPage })` lists the commits that changed one file,
93
+ newest first, from the commit `sha` back. It reads GitHub's commits endpoint with
94
+ `path`, so it does not follow renames. Each commit has `sha`, `date`, `author`,
95
+ the first line of `message`, and `url`. `content.history()` uses it.
96
+
97
+ `latest(keys, { sha })` returns the latest commit of many files at once, as a
98
+ `Map` from key to commit. It sends one GitHub GraphQL request per 150 files, 4
99
+ at a time, so 2,600 files cost 18 requests. When GitHub stops a request after 10
100
+ seconds (502), it asks again with half the files. `changes(base, head)` returns
101
+ the keys that a commit from one commit to a later one changed, with a file that
102
+ one commit edits and a later one reverts. It sends one compare request, plus one
103
+ commit request per commit when there is more than one. It returns undefined when
104
+ GitHub cannot list them all or more than 20 commits lie between them. The Content sitemap and RSS feed
105
+ use both to date Source pages. `pullChanges(number)` returns the keys that a pull
106
+ request adds or changes, from its file list, with the new key of a renamed file
107
+ and without removed files. GitHub lists at most 3,000 files of a pull request.
108
+ `vitehub content previews comment` uses it.
109
+
110
+ `resolveRef()` returns the commit that a ref of the repository points to now:
111
+ `{ sha }` for `{ sha }` or `{ branch }`, and `{ sha, pull }` for `{ pull: 12 }`.
112
+ `pull` has the state, the head and base branches, `fork`, and the label names. A
113
+ branch must match its full name, and a SHA must be a full commit SHA. It returns
114
+ undefined when the repository has no such ref. Content uses it for
115
+ `content.sources.at()`.
89
116
 
90
117
  `glob()` takes a pattern or options. In a pattern, the folders before the first
91
118
  wildcard are `cwd`, so keys are the paths below them:
92
119
 
93
120
  ```ts
94
- import { glob } from "@vite-hub/source/glob"
121
+ import { glob } from "@vite-hub/source"
95
122
 
96
123
  export const docs = glob("content/docs/**/*.md") // keys like "guide/setup.md"
97
124
  ```
@@ -99,22 +126,26 @@ export const docs = glob("content/docs/**/*.md") // keys like "guide/setup.md"
99
126
  Under `vite dev` it reads the files from disk. A server build with `hubSource()`
100
127
  bundles the files of a call whose options are literals, through `files()`, so
101
128
  hosts without a runtime file system, such as Cloudflare Workers, serve them.
102
- `files(entries, { base, prefix })` serves files the server already holds.
129
+ `files(entries, { base, prefix })` serves files the server already holds. An
130
+ entry can be the content or a function that loads it, such as an
131
+ `import.meta.glob()` loader. After removing `base`, a leading `./` is removed
132
+ from each key: `./content/a.md` becomes `content/a.md`, or `a.md` with
133
+ `base: "./content"`.
103
134
 
104
135
  ## Reuse a definition
105
136
 
106
137
  Content accepts Source definitions directly. It opens a new reader on each
107
138
  refresh, so overlapping loads keep separate revisions:
108
139
 
109
- ```ts
140
+ ```ts fragment
110
141
  import { defineContent } from "@vite-hub/content"
111
142
 
112
- export const content = defineContent({ source: docs })
143
+ export default defineContent({ source: docs })
113
144
  ```
114
145
 
115
146
  Workspace binds the same definition to a persistent file tree:
116
147
 
117
- ```ts
148
+ ```ts fragment
118
149
  import { defineWorkspace } from "@vite-hub/workspace"
119
150
 
120
151
  export default defineWorkspace({
@@ -129,11 +160,10 @@ retrieval. Content owns parsed documents, navigation, queries, and search.
129
160
 
130
161
  ## Optional name lookup
131
162
 
132
- ```ts
133
- import { defineSources, registerSources, useSource } from "@vite-hub/source"
163
+ ```ts fragment
164
+ import { registerSources, useSource } from "@vite-hub/source"
134
165
 
135
- const sources = defineSources({ docs })
136
- registerSources(sources)
166
+ registerSources({ docs })
137
167
 
138
168
  declare global {
139
169
  interface ViteHubSourceMap {
@@ -155,8 +185,7 @@ for Collections and Content does not generate `ViteHubSourceMap`.
155
185
  sections of a Markdown file. Each part key is `<parent key>#<part key>`:
156
186
 
157
187
  ```ts
158
- import { createSource, splitSource } from "@vite-hub/source"
159
- import { glob } from "@vite-hub/source/glob"
188
+ import { createSource, splitSource, glob } from "@vite-hub/source"
160
189
 
161
190
  const sections = splitSource({
162
191
  source: glob({ cwd: "docs", include: "**/*.md" }),
@@ -171,41 +200,24 @@ The result is a Source definition. `get()` reads only the parent item of the
171
200
  part, and a part without a `path` keeps the parent's path. Part keys must be
172
201
  unique in their parent item and must not contain `#`.
173
202
 
174
- ## Combine keyed readers
175
-
176
- Use ordinary objects or functions for readers that do not need a loader
177
- lifecycle. `combineSources()` keeps aliases in each key and result:
178
-
179
- ```ts
180
- import { combineSources } from "@vite-hub/source"
181
-
182
- const recaps = combineSources({
183
- sources: {
184
- github: {
185
- get: async (month: `${number}-${number}`) => ({ month }),
186
- items: async () => [{ key: "2026-07" as const }],
187
- },
188
- },
189
- })
190
-
191
- await recaps.get(["github", "2026-07"])
192
- await recaps.items() // [{ key: "2026-07", source: "github", identity: ["github", "2026-07"] }]
193
- ```
194
-
195
- A combined reader exposes `items()` only when every input implements it.
203
+ ## Cache keyed readers
196
204
 
197
205
  Use `cachedSource()` to add Nitro caching to a keyed reader. It loads
198
206
  `nitro/cache` on the first `get()`, so the app must run on Nitro:
199
207
 
200
- ```ts
208
+ ```ts fragment
201
209
  import { cachedSource } from "@vite-hub/source/server"
202
210
 
203
211
  const cachedDocs = cachedSource(createSource(docs), { name: "docs", maxAge: 60 })
204
212
  await cachedDocs.get("intro.md")
205
213
  ```
206
214
 
207
- Use a different cache name for each origin and access scope. Cache ordinary
208
- readers before passing them to `combineSources()`.
215
+ Use a different cache name for each origin and access scope.
216
+
217
+ The `cache` option of a loader, such as `github({ cache: { maxAge } })`, is a
218
+ hint for the consumer of the Source. The Workspace reads it to decide when its
219
+ copy of the Source content is stale. A reader from `createSource()` alone does
220
+ not read `cache` and does not cache.
209
221
 
210
222
  ## Collections
211
223
 
@@ -217,9 +229,19 @@ paginated client read model:
217
229
  import { defineCollection } from "@vite-hub/source"
218
230
  import * as v from "valibot"
219
231
 
232
+ interface Article { id: string, title: string, createdAt: number }
233
+
220
234
  export const articles = defineCollection(async ({ cursor, limit, query }) => {
221
- return db.listArticles({ after: cursor, author: query.author, limit })
235
+ // A CMS API that pages by the last (createdAt, id) it returned
236
+ const url = new URL("https://cms.example.com/api/articles")
237
+ url.searchParams.set("limit", String(limit))
238
+ if (cursor) url.searchParams.set("after", cursor.join(","))
239
+ if (query.author) url.searchParams.set("author", query.author)
240
+ const response = await fetch(url)
241
+ if (!response.ok) throw new Error(`The CMS answered ${response.status}`)
242
+ return await response.json() as Article[]
222
243
  }, {
244
+ access: 'public',
223
245
  cursor: article => [article.createdAt, article.id] as const,
224
246
  cursorSchema: v.tuple([v.number(), v.string()]),
225
247
  querySchema: v.object({ author: v.optional(v.string()) }),
@@ -245,7 +267,10 @@ export const useArticles = () => useCollection("articles", {
245
267
  ViteHub discovers modules in `server/collections` and generates the collection
246
268
  registry and GET handler. The module must export a Collection with the same name
247
269
  as its filename, so `articles.ts` exports `articles` and maps to `/api/articles`.
248
- A Collection is a public read model unless it sets `authorize`. `authorize: true`
270
+ Each routed Collection must set `authorize` or `access: "public"`, or
271
+ `defineCollection()` throws `SOURCE_COLLECTION_ACCESS_REQUIRED`. `access: "public"` makes the route
272
+ public. `authorize: false` throws `SOURCE_COLLECTION_AUTHORIZE_FALSE`, and `access: "public"` with
273
+ `authorize` throws `SOURCE_COLLECTION_ACCESS_CONFLICT`. `authorize: true`
249
274
  requires a signed-in `@vite-hub/auth` session, and a callback receives
250
275
  `{ request, session, user }` and returns `true`, `false` for `403`, or a
251
276
  `Response`. The route checks access before it parses the query. Without a session
@@ -253,7 +278,8 @@ it returns `401`, and `useCollection()` sets `error` to a `CollectionAccessError
253
278
  with that `status`. Generated routes wrap the page with Auth's `withAuthorization` when the host
254
279
  enables Auth with a discovered Auth Definition (`hubSource({ auth: true })`
255
280
  alongside `hubAuth()` outside `vite-hub`); otherwise a
256
- Collection with `authorize` fails closed. Do not repeat the route under
281
+ Collection with `authorize: true` or a callback fails closed. Set `route: false`
282
+ to keep a Collection server-only. Then neither is needed. Do not repeat the route under
257
283
  `server/api`. Restart Nuxt after
258
284
  adding, removing, or renaming a Collection module so Nitro rebuilds its handler
259
285
  manifest.
@@ -271,11 +297,12 @@ When the whole data set fits in memory, pass `array()` as the Collection source.
271
297
  It filters, searches, sorts, counts, and pages the array, and returns `total` and
272
298
  `facets` with each page:
273
299
 
274
- ```ts
300
+ ```ts fragment
275
301
  // server/collections/articles.ts
276
302
  import { array, defineCollection } from "@vite-hub/source"
277
303
 
278
304
  export const articles = defineCollection({
305
+ access: 'public',
279
306
  source: array(() => loadArticles(), {
280
307
  facets: ["category"],
281
308
  filters: ["category", "authors.name"],
@@ -298,11 +325,18 @@ hashes the items for pagination. Keyed lookups do not compute a digest.
298
325
  page. `key` adds `collection.get(key)` for server code, and `schema` validates
299
326
  every item and types it from the schema output. Use a database `table()`
300
327
  from `@vite-hub/source/drizzle` when the data set should not be loaded per
301
- request. `table()` needs the optional `drizzle-orm` peer. `vite-hub/source`
302
- exports `table()` too.
303
-
304
- `workspaceFile()` from `@vite-hub/workspace` is the same source over a JSON array
305
- in a Workspace file.
328
+ request. `table()` needs the optional `drizzle-orm` peer. Apps import it from
329
+ `vite-hub/source/drizzle`. `table()` selects every column. A public Collection
330
+ over it must set `transform` to return only the public fields, or
331
+ `defineCollection()` throws `SOURCE_COLLECTION_PUBLIC_TRANSFORM_REQUIRED`:
332
+
333
+ ```ts fragment
334
+ export const authors = defineCollection({
335
+ access: 'public',
336
+ source: table({ db, orderBy: { column: users.id, direction: "asc", tieBreaker: users.id }, table: users }),
337
+ transform: ({ id, name }) => ({ id, name }),
338
+ })
339
+ ```
306
340
 
307
341
  Pass `{ signal }` to `collection.get(key, { signal })` to cancel a direct read.
308
342
  Cancelled reads reject with the signal's reason, including when a loader or
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as CollectionPage, i as CollectionClientItem, m as CollectionQuery, s as CollectionFacets, t as AnyCollection } from "./collection-B_4w_J8h.js";
1
+ import { a as CollectionClientItem, c as CollectionFacets, h as CollectionQuery, p as CollectionPage, t as AnyCollection } from "./collection-B8sgxw5-.js";
2
2
  import { Diagnostic } from "nostics";
3
3
  import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
4
4
  //#region src/client.d.ts
package/dist/client.js CHANGED
@@ -1,11 +1,36 @@
1
1
  import { n as encodeCollectionRouteSegment } from "./collection-route-BplWPxHR.js";
2
- import { t as sourceErrorDiagnostics } from "./error-diagnostics-X0kuFjBT.js";
2
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
3
3
  import { Diagnostic } from "nostics";
4
- import { $fetch } from "ofetch";
5
4
  import { computed, onScopeDispose, ref, toValue, watch } from "vue";
6
5
  //#region src/client.ts
6
+ /** Thrown by the default requester when a Collection route answers with an error status. */
7
+ var CollectionRequestError = class CollectionRequestError extends Diagnostic {
8
+ status;
9
+ constructor(endpoint, status) {
10
+ super(sourceErrorDiagnostics.SOURCE_R0034({
11
+ endpoint,
12
+ status
13
+ }), CollectionRequestError);
14
+ this.name = "CollectionRequestError";
15
+ this.status = status;
16
+ }
17
+ };
18
+ function queryString(query = {}) {
19
+ const params = new URLSearchParams();
20
+ for (const [key, value] of Object.entries(query)) for (const item of Array.isArray(value) ? value : [value]) {
21
+ if (item === void 0) continue;
22
+ params.append(key, item === null ? "" : String(item) === item ? item : JSON.stringify(item));
23
+ }
24
+ const search = params.toString();
25
+ return search ? `?${search}` : "";
26
+ }
7
27
  const defaultRequester = async (endpoint, options) => {
8
- return await $fetch(endpoint, options);
28
+ const response = await fetch(`${endpoint}${queryString(options.query)}`, {
29
+ headers: { accept: "application/json" },
30
+ signal: options.signal
31
+ });
32
+ if (!response.ok) throw new CollectionRequestError(endpoint, response.status);
33
+ return await response.json();
9
34
  };
10
35
  /** A Collection route rejected the request: `401` without a session, `403` when `authorize` denied it. */
11
36
  var CollectionAccessError = class CollectionAccessError extends Diagnostic {
@@ -14,7 +39,8 @@ var CollectionAccessError = class CollectionAccessError extends Diagnostic {
14
39
  super({
15
40
  cause: options?.cause,
16
41
  code: "SOURCE_R0026",
17
- docs: "https://vitehub.dev/docs/reference/diagnostics",
42
+ fix: sourceErrorDiagnostics.SOURCE_R0026({ message: "" }).fix,
43
+ docs: "https://vitehub.dev/docs/source/diagnostics/source_r0026",
18
44
  why: status === 401 ? "[vitehub] Collection requires a signed-in session." : "[vitehub] Collection access is forbidden."
19
45
  }, CollectionAccessError);
20
46
  this.name = "CollectionAccessError";
@@ -1,5 +1,5 @@
1
1
  import { Diagnostic } from "nostics";
2
- import { AccessAuthorizeOption } from "@vite-hub/runtime";
2
+ import { AccessAuthorizeOption, ViteHubContext } from "@vite-hub/runtime";
3
3
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
4
  //#region src/core/collection-cursor.d.ts
5
5
  /** Why a Collection rejected a cursor: it cannot be decoded, or it belongs to other data or another query. */
@@ -48,8 +48,10 @@ interface CollectionPage<TItem> {
48
48
  }
49
49
  interface Collection<TItem, TQuery extends object = CollectionRequestQuery, TQueryInput extends object = TQuery> {
50
50
  readonly [collectionQueryInput]?: TQueryInput;
51
- /** Access rule for the generated route. Omit it for a public Collection. */
52
- readonly authorize?: AccessAuthorizeOption;
51
+ /** `"public"` lets anyone read the generated route without sign-in. */
52
+ readonly access?: "public";
53
+ /** Access rule for the generated route. Undefined only with `access: "public"` or `route: false`. */
54
+ readonly authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
53
55
  readonly route?: false;
54
56
  readonly get?: (key: string, options?: {
55
57
  signal?: AbortSignal;
@@ -112,14 +114,40 @@ type ProviderCollectionLoader<TSourceItem, TQuery extends object> = (options: {
112
114
  signal?: AbortSignal;
113
115
  }) => Promise<ProviderCollectionPage<TSourceItem>>;
114
116
  type CollectionTransform<TSourceItem> = (item: NoInfer<TSourceItem>) => unknown;
117
+ /**
118
+ * Who can read the generated `/api/<name>` route. A routed Collection must set `authorize` (`true` requires a
119
+ * signed-in Auth session, a callback also decides each request) or `access: "public"`, so a route is never public by
120
+ * accident. Set `route: false` to keep the Collection server-only.
121
+ */
122
+ type CollectionAccess = {
123
+ access?: undefined;
124
+ authorize: AccessAuthorizeOption<Request & ViteHubContext>;
125
+ route?: undefined;
126
+ } | {
127
+ access: "public";
128
+ authorize?: undefined;
129
+ route?: undefined;
130
+ } | {
131
+ access?: undefined;
132
+ authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
133
+ route: false;
134
+ };
135
+ /** The access of a source that returns whole table rows without `transform`. The route cannot be public. */
136
+ type RawRowsAccess = {
137
+ access?: undefined;
138
+ authorize: AccessAuthorizeOption<Request & ViteHubContext>;
139
+ route?: undefined;
140
+ } | {
141
+ access?: undefined;
142
+ authorize?: AccessAuthorizeOption<Request & ViteHubContext>;
143
+ route: false;
144
+ };
115
145
  /**
116
146
  * A cursor the loader must not mutate. Only object cursors become readonly, so `AnyCollectionSource` keeps `any`
117
147
  * instead of `Readonly<any>`, an index-signature object that rejects string and number cursors.
118
148
  */
119
149
  type ReadonlyCursor<TCursorInput> = TCursorInput extends object ? Readonly<TCursorInput> : TCursorInput;
120
- interface CollectionOptions<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput> {
121
- /** `true` requires a signed-in Auth session. A callback also decides each request after sign-in. */
122
- authorize?: AccessAuthorizeOption;
150
+ interface CollectionLoaderOptions<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput> {
123
151
  cursor(item: NoInfer<TSourceItem>): ReadonlyCursor<TCursorInput>;
124
152
  cursorSchema: StandardSchemaV1<TCursorInput, TCursorOutput>;
125
153
  defaultLimit?: number;
@@ -129,11 +157,9 @@ interface CollectionOptions<TSourceItem, TQuery extends object, TCursorInput ext
129
157
  get?: (key: string, options: {
130
158
  signal?: AbortSignal;
131
159
  }) => Promise<TSourceItem | null | undefined>;
132
- route?: false;
133
160
  }
134
- interface ProviderCollectionOptions<TSourceItem, TQuery extends object = CollectionRequestQuery, TItem = unknown> {
135
- authorize?: AccessAuthorizeOption;
136
- route?: false;
161
+ type CollectionOptions<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput> = CollectionLoaderOptions<TSourceItem, TQuery, TCursorInput, TCursorOutput> & CollectionAccess;
162
+ interface ProviderCollectionLoaderOptions<TSourceItem, TQuery extends object = CollectionRequestQuery, TItem = unknown> {
137
163
  pagination: "provider";
138
164
  get?: (key: string, options: {
139
165
  signal?: AbortSignal;
@@ -143,6 +169,7 @@ interface ProviderCollectionOptions<TSourceItem, TQuery extends object = Collect
143
169
  querySchema?: StandardSchemaV1<unknown, TQuery>;
144
170
  transform?: (item: NoInfer<TSourceItem>) => Promise<TItem> | TItem;
145
171
  }
172
+ type ProviderCollectionOptions<TSourceItem, TQuery extends object = CollectionRequestQuery, TItem = unknown> = ProviderCollectionLoaderOptions<TSourceItem, TQuery, TItem> & CollectionAccess;
146
173
  interface CollectionSourceBase<TSourceItem, TQueryInput extends object, TQuery extends object> {
147
174
  get?: (key: string, options: {
148
175
  signal?: AbortSignal;
@@ -150,6 +177,11 @@ interface CollectionSourceBase<TSourceItem, TQueryInput extends object, TQuery e
150
177
  defaultLimit?: number;
151
178
  maxLimit?: number;
152
179
  querySchema?: StandardSchemaV1<TQueryInput, TQuery>;
180
+ /**
181
+ * `true` when the source returns whole rows, such as every column of a database table. A Collection over it needs
182
+ * `transform` to pick the public fields before it can set `access: "public"`.
183
+ */
184
+ rawRows?: boolean;
153
185
  }
154
186
  /** A loader whose rows carry their own cursor. The Collection requests one extra row to detect the next page. */
155
187
  interface CursorCollectionSource<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput, TQueryInput extends object = TQuery> extends CollectionSourceBase<TSourceItem, TQueryInput, TQuery> {
@@ -165,7 +197,7 @@ interface ProviderCollectionSource<TSourceItem, TQuery extends object, TQueryInp
165
197
  cursor?: undefined;
166
198
  cursorSchema?: undefined;
167
199
  }
168
- /** Where a Collection reads rows from: `array()`, `table()`, `workspaceFile()`, or your own object. */
200
+ /** Where a Collection reads rows from: `array()`, `table()`, or your own object. */
169
201
  type CollectionSource<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput, TQueryInput extends object = TQuery> = CursorCollectionSource<TSourceItem, TQuery, TCursorInput, TCursorOutput, TQueryInput> | ProviderCollectionSource<TSourceItem, TQuery, TQueryInput>;
170
202
  type AnyCollectionSource = CollectionSource<any, any, any, any, any>;
171
203
  type SourceItemOf<TSource extends AnyCollectionSource> = TSource extends CollectionSource<infer TItem, any, any, any, any> ? TItem : never;
@@ -200,13 +232,14 @@ type SourceContract<TSource> = (TSource extends {
200
232
  query: TQuery;
201
233
  }) => unknown;
202
234
  } : unknown);
203
- interface SourceCollectionOptions<TSource extends AnyCollectionSource> {
204
- /** `true` requires a signed-in Auth session. A callback also decides each request after sign-in. */
205
- authorize?: AccessAuthorizeOption;
206
- route?: false;
235
+ type SourceCollectionOptions<TSource extends AnyCollectionSource> = {
207
236
  source: TSource & SourceContract<TSource>;
208
- }
209
- type CollectionDefinition<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue> = Omit<CollectionOptions<TSourceItem, TQuery, TCursorInput>, "cursorSchema" | "querySchema" | "transform">;
237
+ } & CollectionAccess;
238
+ /** A source with `rawRows: true` and no `transform` cannot have a public route. */
239
+ type SourceAccessWithoutTransform<TSource> = TSource extends {
240
+ rawRows: true;
241
+ } ? RawRowsAccess : unknown;
242
+ type CollectionDefinition<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue> = Omit<CollectionLoaderOptions<TSourceItem, TQuery, TCursorInput>, "cursorSchema" | "querySchema" | "transform"> & CollectionAccess;
210
243
  type CursorInput<TSchema extends StandardSchemaV1> = [StandardSchemaV1.InferInput<TSchema>] extends [CollectionCursorValue] ? StandardSchemaV1.InferInput<TSchema> : never;
211
244
  type CursorOutput<TSchema extends StandardSchemaV1> = [StandardSchemaV1.InferOutput<TSchema>] extends [CollectionCursorValue] ? StandardSchemaV1.InferOutput<TSchema> : never;
212
245
  type RepeatedQueryValues = [string, string, ...string[]];
@@ -219,7 +252,7 @@ declare function defineCollection<TSource extends AnyCollectionSource, TTransfor
219
252
  }): Collection<Awaited<ReturnType<TTransform>>, SourceQueryOf<TSource>, SourceQueryInputOf<TSource>>;
220
253
  declare function defineCollection<TSource extends AnyCollectionSource>(options: SourceCollectionOptions<TSource> & {
221
254
  transform?: undefined;
222
- }): Collection<SourceItemOf<TSource>, SourceQueryOf<TSource>, SourceQueryInputOf<TSource>>;
255
+ } & SourceAccessWithoutTransform<TSource>): Collection<SourceItemOf<TSource>, SourceQueryOf<TSource>, SourceQueryInputOf<TSource>>;
223
256
  declare function defineCollection<TSourceItem, TCursorSchema extends StandardSchemaV1, TQuerySchema extends StandardSchemaV1<unknown, object>, TTransform extends CollectionTransform<TSourceItem>>(load: CollectionLoader<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>, CursorOutput<TCursorSchema>>, options: CollectionDefinition<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>, CursorInput<TCursorSchema>> & {
224
257
  cursorSchema: TCursorSchema;
225
258
  querySchema: TQuerySchema;
@@ -254,4 +287,4 @@ declare function defineCollection<TSourceItem, TCursorSchema extends StandardSch
254
287
  transform?: undefined;
255
288
  }): Collection<TSourceItem, CollectionRequestQuery, CollectionRequestQuery>;
256
289
  //#endregion
257
- export { ProviderCollectionPage as C, CollectionCursorError as D, defineCollection as E, CollectionCursorErrorOptions as O, ProviderCollectionOptions as S, SourceCollectionOptions as T, CollectionReadOptions as _, CollectionCursorValue as a, CursorCollectionSource as b, CollectionItem as c, CollectionOptions as d, CollectionPage as f, CollectionQueryInput as g, CollectionQueryBuilder as h, CollectionClientItem as i, CollectionCursorErrorReason as k, CollectionLoadOptions as l, CollectionQuery as m, AnyCollectionSource as n, CollectionFacetValue as o, CollectionPageOptions as p, Collection as r, CollectionFacets as s, AnyCollection as t, CollectionLoader as u, CollectionRequestQuery as v, ProviderCollectionSource as w, ProviderCollectionLoader as x, CollectionSource as y };
290
+ export { CollectionCursorErrorReason as A, ProviderCollectionOptions as C, defineCollection as D, SourceCollectionOptions as E, CollectionCursorError as O, ProviderCollectionLoader as S, ProviderCollectionSource as T, CollectionQueryInput as _, CollectionClientItem as a, CollectionSource as b, CollectionFacets as c, CollectionLoader as d, CollectionOptions as f, CollectionQueryBuilder as g, CollectionQuery as h, CollectionAccess as i, CollectionCursorErrorOptions as k, CollectionItem as l, CollectionPageOptions as m, AnyCollectionSource as n, CollectionCursorValue as o, CollectionPage as p, Collection as r, CollectionFacetValue as s, AnyCollection as t, CollectionLoadOptions as u, CollectionReadOptions as v, ProviderCollectionPage as w, CursorCollectionSource as x, CollectionRequestQuery as y };