@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/client.js CHANGED
@@ -1,22 +1,94 @@
1
- import { t as encodeCollectionRouteSegment } from "./collection-route-Dw7QLFyx.js";
2
- import { $fetch } from "ofetch";
1
+ import { n as encodeCollectionRouteSegment } from "./collection-route-BplWPxHR.js";
2
+ import { t as sourceErrorDiagnostics } from "./error-diagnostics-ClQKdi7c.js";
3
+ import { Diagnostic } from "nostics";
3
4
  import { computed, onScopeDispose, ref, toValue, watch } from "vue";
4
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
+ }
5
27
  const defaultRequester = async (endpoint, options) => {
6
- 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();
7
34
  };
35
+ /** A Collection route rejected the request: `401` without a session, `403` when `authorize` denied it. */
36
+ var CollectionAccessError = class CollectionAccessError extends Diagnostic {
37
+ status;
38
+ constructor(status, options) {
39
+ super({
40
+ cause: options?.cause,
41
+ code: "SOURCE_R0026",
42
+ fix: sourceErrorDiagnostics.SOURCE_R0026({ message: "" }).fix,
43
+ docs: "https://vitehub.dev/docs/source/diagnostics/source_r0026",
44
+ why: status === 401 ? "[vitehub] Collection requires a signed-in session." : "[vitehub] Collection access is forbidden."
45
+ }, CollectionAccessError);
46
+ this.name = "CollectionAccessError";
47
+ this.status = status;
48
+ }
49
+ toJSON() {
50
+ return {
51
+ code: this.code,
52
+ data: void 0,
53
+ docs: this.docs,
54
+ fix: this.fix,
55
+ name: this.name,
56
+ status: this.status,
57
+ why: this.why
58
+ };
59
+ }
60
+ };
61
+ function accessError(error) {
62
+ if (Object(error) !== error) return;
63
+ const status = Reflect.get(Object(error), "status") ?? Reflect.get(Object(error), "statusCode");
64
+ if (status === 401 || status === 403) return new CollectionAccessError(status, { cause: error });
65
+ }
8
66
  function isAbortError(error) {
9
67
  return Object(error) === error && Reflect.get(Object(error), "name") === "AbortError";
10
68
  }
11
69
  function parseCollectionPage(value) {
12
- if (Object(value) !== value) throw new TypeError("[vitehub] Collection response must be an object.");
70
+ if (Object(value) !== value) throw sourceErrorDiagnostics.SOURCE_R0001({ message: "[vitehub] Collection response must be an object." });
13
71
  const items = Reflect.get(Object(value), "items");
14
72
  const nextCursor = Reflect.get(Object(value), "nextCursor");
15
- if (!Array.isArray(items) || !(nextCursor === null || String(nextCursor) === nextCursor)) throw new TypeError("[vitehub] Collection response must contain items and nextCursor.");
16
- return {
73
+ if (!Array.isArray(items) || !(nextCursor === null || String(nextCursor) === nextCursor)) throw sourceErrorDiagnostics.SOURCE_R0002({ message: "[vitehub] Collection response must contain items and nextCursor." });
74
+ const page = {
17
75
  items,
18
76
  nextCursor
19
77
  };
78
+ const total = Reflect.get(Object(value), "total");
79
+ if (total !== void 0) {
80
+ if (!Number.isSafeInteger(total) || Number(total) < 0) throw sourceErrorDiagnostics.SOURCE_R0002({ message: "[vitehub] Collection response total must be a non-negative integer." });
81
+ page.total = Number(total);
82
+ }
83
+ const facets = Reflect.get(Object(value), "facets");
84
+ if (facets !== void 0) {
85
+ if (!isFacets(facets)) throw sourceErrorDiagnostics.SOURCE_R0002({ message: "[vitehub] Collection response facets must map fields to { value, count } lists." });
86
+ page.facets = facets;
87
+ }
88
+ return page;
89
+ }
90
+ function isFacets(value) {
91
+ 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));
20
92
  }
21
93
  function appBaseURL() {
22
94
  try {
@@ -34,6 +106,8 @@ function useCollection(name, options = {}) {
34
106
  const endpoint = collectionEndpoint(name);
35
107
  const items = ref([]);
36
108
  const nextCursor = ref(null);
109
+ const total = ref();
110
+ const facets = ref();
37
111
  const pending = ref(false);
38
112
  const error = ref(null);
39
113
  const request = options.request || defaultRequester;
@@ -55,7 +129,9 @@ function useCollection(name, options = {}) {
55
129
  try {
56
130
  const filter = options.filter ? toValue(options.filter) : {};
57
131
  let cursor = reset ? void 0 : nextCursor.value || void 0;
58
- let loadedItems = reset ? [] : [...items.value];
132
+ const loadedItems = reset ? [] : [...items.value];
133
+ let loadedTotal = reset ? void 0 : total.value;
134
+ let loadedFacets = reset ? void 0 : facets.value;
59
135
  let response;
60
136
  const seenCursors = new Set(cursors);
61
137
  if (cursor) seenCursors.add(cursor);
@@ -69,26 +145,32 @@ function useCollection(name, options = {}) {
69
145
  signal: controller.signal
70
146
  }));
71
147
  response = {
72
- items: parsed.items,
73
- nextCursor: parsed.nextCursor
148
+ ...parsed,
149
+ items: parsed.items
74
150
  };
75
151
  if (active !== controller) return;
76
- loadedItems = [...loadedItems, ...response.items];
152
+ if (response.total !== void 0) loadedTotal = response.total;
153
+ if (response.facets !== void 0) loadedFacets = response.facets;
154
+ for (const item of response.items) loadedItems.push(item);
77
155
  cursor = response.nextCursor || void 0;
78
- if (cursor && seenCursors.has(cursor)) throw new TypeError("[vitehub] Collection returned the same cursor twice.");
156
+ if (cursor && seenCursors.has(cursor)) throw sourceErrorDiagnostics.SOURCE_R0003({ message: "[vitehub] Collection returned the same cursor twice." });
79
157
  if (cursor) seenCursors.add(cursor);
80
158
  } while (options.all === true && cursor);
81
159
  items.value = loadedItems;
82
160
  cursors = seenCursors;
83
161
  nextCursor.value = response.nextCursor;
162
+ total.value = loadedTotal;
163
+ facets.value = loadedFacets;
84
164
  loaded = true;
85
165
  return {
166
+ ...response,
86
167
  items: loadedItems,
87
- nextCursor: response.nextCursor
168
+ total: loadedTotal,
169
+ facets: loadedFacets
88
170
  };
89
171
  } catch (cause) {
90
172
  if (active !== controller || isAbortError(cause)) return;
91
- error.value = cause;
173
+ error.value = accessError(cause) ?? cause;
92
174
  } finally {
93
175
  if (active === controller) {
94
176
  active = void 0;
@@ -110,12 +192,14 @@ function useCollection(name, options = {}) {
110
192
  });
111
193
  return {
112
194
  error,
195
+ facets,
113
196
  hasMore: computed(() => Boolean(nextCursor.value)),
114
197
  items,
115
198
  loadMore: () => load(false),
116
199
  pending,
117
- refresh: () => load(true)
200
+ refresh: () => load(true),
201
+ total
118
202
  };
119
203
  }
120
204
  //#endregion
121
- export { useCollection };
205
+ export { CollectionAccessError, useCollection };
@@ -0,0 +1,290 @@
1
+ import { Diagnostic } from "nostics";
2
+ import { AccessAuthorizeOption, ViteHubContext } from "@vite-hub/runtime";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+ //#region src/core/collection-cursor.d.ts
5
+ /** Why a Collection rejected a cursor: it cannot be decoded, or it belongs to other data or another query. */
6
+ type CollectionCursorErrorReason = "malformed" | "stale";
7
+ interface CollectionCursorErrorOptions extends ErrorOptions {
8
+ reason?: CollectionCursorErrorReason;
9
+ }
10
+ /** A Collection cursor was rejected. Routes answer `400` for `malformed` and `409` for `stale`. */
11
+ declare class CollectionCursorError extends Diagnostic {
12
+ readonly reason: CollectionCursorErrorReason;
13
+ constructor(message?: string, options?: CollectionCursorErrorOptions);
14
+ }
15
+ //#endregion
16
+ //#region src/core/collection.d.ts
17
+ declare const collectionQueryInput: unique symbol;
18
+ type CollectionRequestQuery = Record<string, string | readonly string[] | undefined>;
19
+ type CollectionCursorValue = boolean | null | number | string | readonly CollectionCursorValue[] | {
20
+ readonly [key: string]: CollectionCursorValue;
21
+ };
22
+ interface CollectionLoadOptions<TQuery extends object, TCursor extends CollectionCursorValue> {
23
+ cursor?: TCursor;
24
+ limit: number;
25
+ query: TQuery;
26
+ signal?: AbortSignal;
27
+ }
28
+ interface CollectionPageOptions<TQuery extends object> {
29
+ cursor?: string;
30
+ limit?: number;
31
+ query: TQuery;
32
+ signal?: AbortSignal;
33
+ }
34
+ /** One distinct value of a faceted field and how many matching items carry it. */
35
+ interface CollectionFacetValue {
36
+ count: number;
37
+ value: string;
38
+ }
39
+ /** Facet counts keyed by field path, computed over every item that matches the query. */
40
+ type CollectionFacets = Record<string, CollectionFacetValue[]>;
41
+ interface CollectionPage<TItem> {
42
+ items: TItem[];
43
+ nextCursor: string | null;
44
+ /** Number of items that match the query across every page, when the Collection can count them. */
45
+ total?: number;
46
+ /** Facet counts over every item that matches the query, when the Collection declares facets. */
47
+ facets?: CollectionFacets;
48
+ }
49
+ interface Collection<TItem, TQuery extends object = CollectionRequestQuery, TQueryInput extends object = TQuery> {
50
+ readonly [collectionQueryInput]?: TQueryInput;
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>;
55
+ readonly route?: false;
56
+ readonly get?: (key: string, options?: {
57
+ signal?: AbortSignal;
58
+ }) => Promise<TItem | null | undefined>;
59
+ page(options: CollectionPageOptions<TQuery>): Promise<CollectionPage<TItem>>;
60
+ parseQuery(input: TQueryInput | CollectionRequestQuery): Promise<TQuery>;
61
+ query(input?: TQueryInput): CollectionQueryBuilder<TItem>;
62
+ all(options?: CollectionReadOptions & {
63
+ query?: TQueryInput;
64
+ limit?: number;
65
+ }): Promise<TItem[]>;
66
+ /** The query schema, when the Collection has one. Tools read it to describe accepted query keys. */
67
+ readonly querySchema?: StandardSchemaV1<unknown, TQuery>;
68
+ }
69
+ interface CollectionReadOptions {
70
+ signal?: AbortSignal;
71
+ }
72
+ interface CollectionQueryBuilder<TItem> {
73
+ select<TKey extends Extract<keyof TItem, string>>(...keys: TKey[]): CollectionQueryBuilder<Pick<TItem, TKey>>;
74
+ page(options?: CollectionReadOptions & {
75
+ cursor?: string;
76
+ limit?: number;
77
+ }): Promise<CollectionPage<TItem>>;
78
+ all(options?: CollectionReadOptions & {
79
+ limit?: number;
80
+ }): Promise<TItem[]>;
81
+ }
82
+ type AnyCollection = Collection<any, any, any>;
83
+ type CollectionItem<TCollection extends AnyCollection> = TCollection extends Collection<infer TItem, any, any> ? TItem : never;
84
+ type JSONOmitted = undefined | ((...args: any[]) => any) | symbol;
85
+ type JSONUnsupportedObject = ArrayBuffer | ArrayBufferView | Date | Error | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | RegExp | SharedArrayBuffer | URL | WeakMap<object, unknown> | WeakSet<object>;
86
+ type JSONOmittedBranch<T> = T extends {
87
+ toJSON(): infer TJSON;
88
+ } ? TJSON extends JSONOmitted ? TJSON : never : T extends JSONOmitted ? T : never;
89
+ type JSONSerializedValue<T> = T extends {
90
+ toJSON(): infer TJSON;
91
+ } ? JSONSerializedPostToJSON<TJSON> : JSONSerializedPostToJSON<T>;
92
+ type JSONSerializedPostToJSON<T> = T extends bigint | JSONUnsupportedObject ? never : T extends number ? number | null : T extends boolean | null | string ? T : T extends readonly (infer TItem)[] ? Array<JSONSerializedArrayItem<TItem>> : T extends object ? JSONSerializedObject<T> : never;
93
+ type JSONSerialized<T> = T extends unknown ? JSONSerializedValue<T> : never;
94
+ type JSONSerializedArrayItem<T> = T extends {
95
+ toJSON(): infer TJSON;
96
+ } ? JSONSerializedArrayValue<TJSON> : JSONSerializedArrayValue<T>;
97
+ type JSONSerializedArrayValue<T> = T extends JSONOmitted ? null : JSONSerializedPostToJSON<T>;
98
+ type Simplify<T> = { [TKey in keyof T]: T[TKey]; };
99
+ type JSONSerializedObject<T extends object> = Simplify<{ [TKey in keyof T as TKey extends symbol ? never : [JSONOmittedBranch<T[TKey]>] extends [never] ? TKey : never]: JSONSerialized<T[TKey]>; } & { [TKey in keyof T as TKey extends symbol ? never : [JSONOmittedBranch<T[TKey]>] extends [never] ? never : [JSONSerialized<T[TKey]>] extends [never] ? never : TKey]?: JSONSerialized<T[TKey]>; }>;
100
+ type CollectionClientItem<TCollection extends AnyCollection> = JSONSerializedArrayItem<CollectionItem<TCollection>>;
101
+ type CollectionQuery<TCollection extends AnyCollection> = TCollection extends Collection<any, any, infer TQueryInput> ? TQueryInput : never;
102
+ type CollectionLoader<TSourceItem, TQuery extends object, TCursor extends CollectionCursorValue> = (options: CollectionLoadOptions<TQuery, TCursor>) => Promise<readonly TSourceItem[]>;
103
+ /** Result of a provider-paginated loader. `total` and `facets` reach the page unchanged. */
104
+ interface ProviderCollectionPage<TSourceItem> {
105
+ items: readonly TSourceItem[];
106
+ nextCursor: string | null;
107
+ total?: number;
108
+ facets?: CollectionFacets;
109
+ }
110
+ type ProviderCollectionLoader<TSourceItem, TQuery extends object> = (options: {
111
+ cursor?: string;
112
+ limit: number;
113
+ query: TQuery;
114
+ signal?: AbortSignal;
115
+ }) => Promise<ProviderCollectionPage<TSourceItem>>;
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
+ };
145
+ /**
146
+ * A cursor the loader must not mutate. Only object cursors become readonly, so `AnyCollectionSource` keeps `any`
147
+ * instead of `Readonly<any>`, an index-signature object that rejects string and number cursors.
148
+ */
149
+ type ReadonlyCursor<TCursorInput> = TCursorInput extends object ? Readonly<TCursorInput> : TCursorInput;
150
+ interface CollectionLoaderOptions<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput> {
151
+ cursor(item: NoInfer<TSourceItem>): ReadonlyCursor<TCursorInput>;
152
+ cursorSchema: StandardSchemaV1<TCursorInput, TCursorOutput>;
153
+ defaultLimit?: number;
154
+ maxLimit?: number;
155
+ querySchema?: StandardSchemaV1<unknown, TQuery>;
156
+ transform?: CollectionTransform<TSourceItem>;
157
+ get?: (key: string, options: {
158
+ signal?: AbortSignal;
159
+ }) => Promise<TSourceItem | null | undefined>;
160
+ }
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> {
163
+ pagination: "provider";
164
+ get?: (key: string, options: {
165
+ signal?: AbortSignal;
166
+ }) => Promise<TSourceItem | null | undefined>;
167
+ defaultLimit?: number;
168
+ maxLimit?: number;
169
+ querySchema?: StandardSchemaV1<unknown, TQuery>;
170
+ transform?: (item: NoInfer<TSourceItem>) => Promise<TItem> | TItem;
171
+ }
172
+ type ProviderCollectionOptions<TSourceItem, TQuery extends object = CollectionRequestQuery, TItem = unknown> = ProviderCollectionLoaderOptions<TSourceItem, TQuery, TItem> & CollectionAccess;
173
+ interface CollectionSourceBase<TSourceItem, TQueryInput extends object, TQuery extends object> {
174
+ get?: (key: string, options: {
175
+ signal?: AbortSignal;
176
+ }) => Promise<TSourceItem | null | undefined>;
177
+ defaultLimit?: number;
178
+ maxLimit?: number;
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;
185
+ }
186
+ /** A loader whose rows carry their own cursor. The Collection requests one extra row to detect the next page. */
187
+ interface CursorCollectionSource<TSourceItem, TQuery extends object, TCursorInput extends CollectionCursorValue, TCursorOutput extends CollectionCursorValue = TCursorInput, TQueryInput extends object = TQuery> extends CollectionSourceBase<TSourceItem, TQueryInput, TQuery> {
188
+ cursor(item: NoInfer<TSourceItem>): ReadonlyCursor<TCursorInput>;
189
+ cursorSchema: StandardSchemaV1<TCursorInput, TCursorOutput>;
190
+ load: CollectionLoader<TSourceItem, TQuery, TCursorOutput>;
191
+ pagination?: undefined;
192
+ }
193
+ /** A loader that returns whole pages with its own opaque `nextCursor`, and optionally `total` and `facets`. */
194
+ interface ProviderCollectionSource<TSourceItem, TQuery extends object, TQueryInput extends object = TQuery> extends CollectionSourceBase<TSourceItem, TQueryInput, TQuery> {
195
+ load: ProviderCollectionLoader<TSourceItem, TQuery>;
196
+ pagination: "provider";
197
+ cursor?: undefined;
198
+ cursorSchema?: undefined;
199
+ }
200
+ /** Where a Collection reads rows from: `array()`, `table()`, or your own object. */
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>;
202
+ type AnyCollectionSource = CollectionSource<any, any, any, any, any>;
203
+ type SourceItemOf<TSource extends AnyCollectionSource> = TSource extends CollectionSource<infer TItem, any, any, any, any> ? TItem : never;
204
+ type SourceQueryOf<TSource extends AnyCollectionSource> = TSource extends CollectionSource<any, infer TQuery, any, any, any> ? TQuery : never;
205
+ type SourceQueryInputOf<TSource extends AnyCollectionSource> = TSource extends CollectionSource<any, any, any, any, infer TQueryInput> ? TQueryInput : never;
206
+ type LoadedItemOf<TSource> = TSource extends {
207
+ load: (...args: any[]) => infer TResult;
208
+ } ? Awaited<TResult> extends readonly (infer TItem)[] ? TItem : Awaited<TResult> extends {
209
+ items: readonly (infer TItem)[];
210
+ } ? TItem : never : never;
211
+ type LoadOptionsOf<TSource> = TSource extends {
212
+ load: (options: infer TOptions) => unknown;
213
+ } ? TOptions : never;
214
+ /**
215
+ * Ties a source's own parts to its loader. `AnyCollectionSource` only bounds each part, so without this a cursor,
216
+ * `get`, or query schema written for other rows or another query would pass.
217
+ */
218
+ type SourceContract<TSource> = (TSource extends {
219
+ cursor: (item: never) => unknown;
220
+ } ? {
221
+ cursor: (item: LoadedItemOf<TSource>) => unknown;
222
+ } : unknown) & (TSource extends {
223
+ get: (key: string, options: never) => unknown;
224
+ } ? {
225
+ get: (key: string, options: {
226
+ signal?: AbortSignal;
227
+ }) => Promise<LoadedItemOf<TSource> | null | undefined>;
228
+ } : unknown) & (TSource extends {
229
+ querySchema: StandardSchemaV1<any, infer TQuery>;
230
+ } ? [LoadOptionsOf<TSource>] extends [never] ? unknown : {
231
+ load: (options: Omit<LoadOptionsOf<TSource>, "query"> & {
232
+ query: TQuery;
233
+ }) => unknown;
234
+ } : unknown);
235
+ type SourceCollectionOptions<TSource extends AnyCollectionSource> = {
236
+ source: TSource & SourceContract<TSource>;
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;
243
+ type CursorInput<TSchema extends StandardSchemaV1> = [StandardSchemaV1.InferInput<TSchema>] extends [CollectionCursorValue] ? StandardSchemaV1.InferInput<TSchema> : never;
244
+ type CursorOutput<TSchema extends StandardSchemaV1> = [StandardSchemaV1.InferOutput<TSchema>] extends [CollectionCursorValue] ? StandardSchemaV1.InferOutput<TSchema> : never;
245
+ type RepeatedQueryValues = [string, string, ...string[]];
246
+ type AmbiguousArrayQueryKey<TInput extends object> = { [TKey in keyof TInput]-?: [Extract<TInput[TKey], readonly string[]>] extends [never] ? never : RepeatedQueryValues extends TInput[TKey] ? string extends TInput[TKey] ? undefined extends TInput[TKey] ? never : TKey : TKey : TKey; }[keyof TInput];
247
+ type ReservedCollectionQueryKey = "cursor" | "limit";
248
+ type CollectionQueryInput<TInput> = TInput extends object ? [Exclude<keyof TInput, string>] extends [never] ? [Extract<ReservedCollectionQueryKey, keyof TInput>] extends [never] ? [TInput[keyof TInput]] extends [CollectionRequestQuery[string]] ? [AmbiguousArrayQueryKey<TInput>] extends [never] ? TInput : never : never : never : never : never;
249
+ type QueryInput<TSchema extends StandardSchemaV1> = CollectionQueryInput<StandardSchemaV1.InferInput<TSchema>>;
250
+ declare function defineCollection<TSource extends AnyCollectionSource, TTransform extends (item: NoInfer<SourceItemOf<TSource>>) => unknown>(options: SourceCollectionOptions<TSource> & {
251
+ transform: TTransform;
252
+ }): Collection<Awaited<ReturnType<TTransform>>, SourceQueryOf<TSource>, SourceQueryInputOf<TSource>>;
253
+ declare function defineCollection<TSource extends AnyCollectionSource>(options: SourceCollectionOptions<TSource> & {
254
+ transform?: undefined;
255
+ } & SourceAccessWithoutTransform<TSource>): Collection<SourceItemOf<TSource>, SourceQueryOf<TSource>, SourceQueryInputOf<TSource>>;
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>> & {
257
+ cursorSchema: TCursorSchema;
258
+ querySchema: TQuerySchema;
259
+ transform: TTransform;
260
+ }): Collection<Awaited<ReturnType<TTransform>>, StandardSchemaV1.InferOutput<TQuerySchema>, QueryInput<TQuerySchema>>;
261
+ declare function defineCollection<TSourceItem, TCursorSchema extends StandardSchemaV1, TQuerySchema extends StandardSchemaV1<unknown, object>>(load: CollectionLoader<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>, CursorOutput<TCursorSchema>>, options: CollectionDefinition<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>, CursorInput<TCursorSchema>> & {
262
+ cursorSchema: TCursorSchema;
263
+ querySchema: TQuerySchema;
264
+ transform?: undefined;
265
+ }): Collection<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>, QueryInput<TQuerySchema>>;
266
+ declare function defineCollection<TSourceItem, TQuerySchema extends StandardSchemaV1<unknown, object>, TItem = TSourceItem>(load: ProviderCollectionLoader<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>>, options: ProviderCollectionOptions<TSourceItem, StandardSchemaV1.InferOutput<TQuerySchema>, TItem> & {
267
+ querySchema: TQuerySchema;
268
+ }): Collection<TItem, StandardSchemaV1.InferOutput<TQuerySchema>, QueryInput<TQuerySchema>>;
269
+ declare function defineCollection<TSourceItem, TTransform extends CollectionTransform<TSourceItem>>(load: ProviderCollectionLoader<TSourceItem, CollectionRequestQuery>, options: ProviderCollectionOptions<TSourceItem, CollectionRequestQuery, Awaited<ReturnType<TTransform>>> & {
270
+ get: NonNullable<ProviderCollectionOptions<TSourceItem>["get"]>;
271
+ querySchema?: undefined;
272
+ transform: TTransform;
273
+ }): Collection<Awaited<ReturnType<TTransform>>, CollectionRequestQuery, CollectionRequestQuery> & {
274
+ get: (key: string, options?: CollectionReadOptions) => Promise<Awaited<ReturnType<TTransform>> | null | undefined>;
275
+ };
276
+ declare function defineCollection<TSourceItem, TItem = TSourceItem>(load: ProviderCollectionLoader<TSourceItem, CollectionRequestQuery>, options: ProviderCollectionOptions<TSourceItem, CollectionRequestQuery, TItem> & {
277
+ querySchema?: undefined;
278
+ }): Collection<TItem, CollectionRequestQuery, CollectionRequestQuery>;
279
+ declare function defineCollection<TSourceItem, TCursorSchema extends StandardSchemaV1, TTransform extends CollectionTransform<TSourceItem>>(load: CollectionLoader<TSourceItem, CollectionRequestQuery, CursorOutput<TCursorSchema>>, options: CollectionDefinition<TSourceItem, CollectionRequestQuery, CursorInput<TCursorSchema>> & {
280
+ cursorSchema: TCursorSchema;
281
+ querySchema?: undefined;
282
+ transform: TTransform;
283
+ }): Collection<Awaited<ReturnType<TTransform>>, CollectionRequestQuery, CollectionRequestQuery>;
284
+ declare function defineCollection<TSourceItem, TCursorSchema extends StandardSchemaV1>(load: CollectionLoader<TSourceItem, CollectionRequestQuery, CursorOutput<TCursorSchema>>, options: CollectionDefinition<TSourceItem, CollectionRequestQuery, CursorInput<TCursorSchema>> & {
285
+ cursorSchema: TCursorSchema;
286
+ querySchema?: undefined;
287
+ transform?: undefined;
288
+ }): Collection<TSourceItem, CollectionRequestQuery, CollectionRequestQuery>;
289
+ //#endregion
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 };