ovr 6.2.4 → 7.0.0-next.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 (136) hide show
  1. package/README.md +3 -1
  2. package/dist/app/index.d.ts +51 -7
  3. package/dist/app/index.d.ts.map +1 -1
  4. package/dist/app/index.js +163 -28
  5. package/dist/auth/auth-data.d.ts +26 -0
  6. package/dist/auth/auth-data.d.ts.map +1 -0
  7. package/dist/auth/auth-data.js +42 -0
  8. package/dist/auth/cbor.d.ts +50 -0
  9. package/dist/auth/cbor.d.ts.map +1 -0
  10. package/dist/auth/cbor.js +200 -0
  11. package/dist/auth/client-source.d.ts +3 -0
  12. package/dist/auth/client-source.d.ts.map +1 -0
  13. package/dist/auth/client-source.js +3 -0
  14. package/dist/auth/client.d.ts +3 -0
  15. package/dist/auth/client.d.ts.map +1 -0
  16. package/dist/auth/client.js +186 -0
  17. package/dist/auth/configure.d.ts +28 -0
  18. package/dist/auth/configure.d.ts.map +1 -0
  19. package/dist/auth/configure.js +228 -0
  20. package/dist/auth/der.d.ts +6 -0
  21. package/dist/auth/der.d.ts.map +1 -0
  22. package/dist/auth/der.js +36 -0
  23. package/dist/auth/index.d.ts +242 -0
  24. package/dist/auth/index.d.ts.map +1 -0
  25. package/dist/auth/index.js +152 -0
  26. package/dist/auth/issue.d.ts +36 -0
  27. package/dist/auth/issue.d.ts.map +1 -0
  28. package/dist/auth/issue.js +47 -0
  29. package/dist/auth/metadata.d.ts +22 -0
  30. package/dist/auth/metadata.d.ts.map +1 -0
  31. package/dist/auth/metadata.js +134 -0
  32. package/dist/auth/oauth.d.ts +29 -0
  33. package/dist/auth/oauth.d.ts.map +1 -0
  34. package/dist/auth/oauth.js +724 -0
  35. package/dist/auth/passkey.d.ts +101 -0
  36. package/dist/auth/passkey.d.ts.map +1 -0
  37. package/dist/auth/passkey.js +393 -0
  38. package/dist/auth/state.d.ts +49 -0
  39. package/dist/auth/state.d.ts.map +1 -0
  40. package/dist/auth/state.js +184 -0
  41. package/dist/auth/storage.d.ts +193 -0
  42. package/dist/auth/storage.d.ts.map +1 -0
  43. package/dist/auth/storage.js +410 -0
  44. package/dist/auth/token.d.ts +12 -0
  45. package/dist/auth/token.d.ts.map +1 -0
  46. package/dist/auth/token.js +39 -0
  47. package/dist/context/index.d.ts +86 -16
  48. package/dist/context/index.d.ts.map +1 -1
  49. package/dist/context/index.js +166 -42
  50. package/dist/cookie/index.d.ts +3 -0
  51. package/dist/cookie/index.d.ts.map +1 -1
  52. package/dist/cookie/index.js +1 -0
  53. package/dist/database/index.d.ts +262 -0
  54. package/dist/database/index.d.ts.map +1 -0
  55. package/dist/database/index.js +807 -0
  56. package/dist/form/index.d.ts +699 -0
  57. package/dist/form/index.d.ts.map +1 -0
  58. package/dist/form/index.js +901 -0
  59. package/dist/index.d.ts +10 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +9 -3
  62. package/dist/jsx/elements.d.ts +28 -2
  63. package/dist/jsx/elements.d.ts.map +1 -1
  64. package/dist/jsx/index.d.ts +20 -4
  65. package/dist/jsx/index.d.ts.map +1 -1
  66. package/dist/jsx/index.js +6 -65
  67. package/dist/limiter/index.d.ts +65 -0
  68. package/dist/limiter/index.d.ts.map +1 -0
  69. package/dist/limiter/index.js +157 -0
  70. package/dist/markdown/index.d.ts +61 -0
  71. package/dist/markdown/index.d.ts.map +1 -0
  72. package/dist/markdown/index.js +1160 -0
  73. package/dist/markup/index.d.ts +188 -0
  74. package/dist/markup/index.d.ts.map +1 -0
  75. package/dist/markup/index.js +718 -0
  76. package/dist/mcp/index.d.ts +73 -0
  77. package/dist/mcp/index.d.ts.map +1 -0
  78. package/dist/mcp/index.js +988 -0
  79. package/dist/middleware/index.d.ts +3 -4
  80. package/dist/middleware/index.d.ts.map +1 -1
  81. package/dist/multipart/index.d.ts +53 -7
  82. package/dist/multipart/index.d.ts.map +1 -1
  83. package/dist/multipart/index.js +332 -124
  84. package/dist/route/index.d.ts +226 -80
  85. package/dist/route/index.d.ts.map +1 -1
  86. package/dist/route/index.js +239 -99
  87. package/dist/schema/index.d.ts +307 -734
  88. package/dist/schema/index.d.ts.map +1 -1
  89. package/dist/schema/index.js +783 -1050
  90. package/dist/table/index.d.ts +132 -0
  91. package/dist/table/index.d.ts.map +1 -0
  92. package/dist/table/index.js +188 -0
  93. package/dist/trie/index.js +4 -4
  94. package/dist/util/index.d.ts +37 -5
  95. package/dist/util/index.d.ts.map +1 -1
  96. package/dist/util/index.js +156 -41
  97. package/package.json +11 -4
  98. package/src/app/index.ts +230 -42
  99. package/src/auth/auth-data.ts +56 -0
  100. package/src/auth/cbor.ts +231 -0
  101. package/src/auth/client-source.ts +3 -0
  102. package/src/auth/client.ts +205 -0
  103. package/src/auth/configure.ts +279 -0
  104. package/src/auth/der.ts +35 -0
  105. package/src/auth/index.ts +387 -0
  106. package/src/auth/issue.ts +52 -0
  107. package/src/auth/metadata.ts +149 -0
  108. package/src/auth/oauth.ts +882 -0
  109. package/src/auth/passkey.ts +556 -0
  110. package/src/auth/state.ts +213 -0
  111. package/src/auth/storage.ts +572 -0
  112. package/src/auth/token.ts +67 -0
  113. package/src/context/index.ts +240 -65
  114. package/src/cookie/index.ts +3 -0
  115. package/src/database/index.ts +1193 -0
  116. package/src/form/index.ts +1720 -0
  117. package/src/index.ts +10 -3
  118. package/src/jsx/elements.ts +45 -25
  119. package/src/jsx/index.ts +24 -69
  120. package/src/limiter/index.ts +221 -0
  121. package/src/markdown/index.ts +1322 -0
  122. package/src/markup/index.ts +853 -0
  123. package/src/mcp/conformance.2025-11-25.yml +39 -0
  124. package/src/mcp/conformance.2026-07-28.yml +56 -0
  125. package/src/mcp/index.ts +1262 -0
  126. package/src/middleware/index.ts +5 -6
  127. package/src/multipart/index.ts +410 -158
  128. package/src/route/index.ts +559 -278
  129. package/src/schema/index.ts +1542 -2256
  130. package/src/table/index.ts +387 -0
  131. package/src/trie/index.ts +4 -4
  132. package/src/util/index.ts +163 -49
  133. package/dist/render/index.d.ts +0 -79
  134. package/dist/render/index.d.ts.map +0 -1
  135. package/dist/render/index.js +0 -257
  136. package/src/render/index.ts +0 -314
@@ -0,0 +1,387 @@
1
+ import { Schema, normalizers } from "../schema/index.js";
2
+
3
+ /**
4
+ * Internal protocol for `describe()`, to give the table it makes its
5
+ * description, which the constructor puts in the schema's definition.
6
+ */
7
+ const described = Symbol("described");
8
+
9
+ /** Options of a table `describe()` makes */
10
+ type Described = { readonly [described]?: string };
11
+
12
+ export namespace Table {
13
+ /** Column schemas keyed by column name. */
14
+ export type Shape = Schema.Object.Shape;
15
+
16
+ /**
17
+ * Column name of a shape.
18
+ *
19
+ * @template S Table shape
20
+ */
21
+ export type Key<S extends Shape> = Extract<keyof S, string>;
22
+
23
+ /**
24
+ * Postgres schema and the columns the database supplies.
25
+ *
26
+ * @template S Table shape
27
+ */
28
+ export interface Options<S extends Shape = Shape> {
29
+ /** Schema containing the table, defaults to the connection's search path. */
30
+ readonly schema?: string;
31
+
32
+ /**
33
+ * Columns that may be omitted on insert because the database supplies a
34
+ * value, with a `DEFAULT`, identity, or generated column.
35
+ */
36
+ readonly default?: readonly Key<S>[];
37
+ }
38
+
39
+ /** Any table. */
40
+ export type Any = Table<string, any, any>;
41
+
42
+ /**
43
+ * Columns whose value may be left out, as with `optional()`, which a row
44
+ * read from the database always has.
45
+ *
46
+ * @template S Table shape
47
+ */
48
+ export type Omissible<S extends Shape> = {
49
+ [K in keyof S]: undefined extends Schema.Infer<S[K]>
50
+ ? unknown extends Schema.Infer<S[K]>
51
+ ? never
52
+ : K
53
+ : never;
54
+ }[keyof S];
55
+
56
+ /**
57
+ * A name Postgres can quote: not empty and without a NUL character.
58
+ *
59
+ * @template N Table, schema, or column name
60
+ */
61
+ export type Identifier<N extends string> = N extends
62
+ "" | `${string}\0${string}`
63
+ ? never
64
+ : N;
65
+
66
+ /**
67
+ * Row returned from the table.
68
+ *
69
+ * @template S Table shape
70
+ */
71
+ export type Row<S extends Shape> = { [K in keyof S]: Schema.Infer<S[K]> };
72
+
73
+ /**
74
+ * Column names that may be omitted from an insert: nullable or supplied by the database.
75
+ *
76
+ * @template S Table shape
77
+ * @template O Table options
78
+ */
79
+ export type Defaulted<S extends Shape, O extends Options<S>> =
80
+ | Extract<NonNullable<O["default"]>[number], Key<S>>
81
+ | {
82
+ [K in Key<S>]: unknown extends Schema.Infer<S[K]>
83
+ ? never // unknown columns store JSON null, so they are NOT NULL
84
+ : null extends Schema.Infer<S[K]>
85
+ ? K
86
+ : never;
87
+ }[Key<S>];
88
+
89
+ /**
90
+ * Values accepted by `sql.values` for one row.
91
+ *
92
+ * @template S Table shape
93
+ * @template O Table options
94
+ */
95
+ export type Insert<S extends Shape, O extends Options<S>> = {
96
+ [K in Exclude<Key<S>, Defaulted<S, O>>]: Schema.Infer<S[K]>;
97
+ } & { [K in Defaulted<S, O>]?: Schema.Infer<S[K]> };
98
+
99
+ /**
100
+ * Values accepted by `sql.set`.
101
+ *
102
+ * @template S Table shape
103
+ */
104
+ export type Update<S extends Shape> = Partial<Row<S>>;
105
+
106
+ /** Kind of value a column stores, each compatible with several Postgres types. */
107
+ export type Type =
108
+ "string" | "number" | "bigint" | "boolean" | "date" | "json";
109
+ }
110
+
111
+ /** Reference to one column, interpolated by `sql` as a qualified identifier. */
112
+ export class Column {
113
+ /** Table containing the column. */
114
+ readonly table: Table.Any;
115
+
116
+ /** Column name. */
117
+ readonly name: string;
118
+
119
+ /** Kind of value derived from the column schema. */
120
+ readonly type: Table.Type;
121
+
122
+ /** If the column allows `NULL`. */
123
+ readonly nullable: boolean;
124
+
125
+ /**
126
+ * @param table Table containing the column
127
+ * @param name Column name
128
+ * @param type Kind of value
129
+ * @param nullable If the column allows `NULL`
130
+ */
131
+ constructor(
132
+ table: Table.Any,
133
+ name: string,
134
+ type: Table.Type,
135
+ nullable: boolean,
136
+ ) {
137
+ this.table = table;
138
+ this.name = name;
139
+ this.type = type;
140
+ this.nullable = nullable;
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Postgres table defined with validation schemas.
146
+ *
147
+ * The table is a schema of its rows, so `Schema.Infer<typeof table>` is the
148
+ * row type and `sql.parse(table)` validates returned rows. Keys, constraints, and
149
+ * indexes belong in migrations.
150
+ *
151
+ * @template Name Table name
152
+ * @template S Column schemas
153
+ * @template O Table options
154
+ */
155
+ export class Table<
156
+ Name extends string,
157
+ S extends Table.Shape,
158
+ const O extends Table.Options<S> = {},
159
+ > extends Schema<Table.Row<S>> {
160
+ /** Table name. */
161
+ readonly name: Name;
162
+
163
+ /** Column schemas. */
164
+ readonly shape: S;
165
+
166
+ /** Postgres schema and the columns the database supplies. */
167
+ readonly options: O;
168
+
169
+ /** Column references for `sql`. */
170
+ readonly columns: { readonly [K in keyof S]: Column };
171
+
172
+ /**
173
+ * Define a table.
174
+ *
175
+ * @param name Table name
176
+ * @param shape Column schemas
177
+ * @param options Postgres schema and the columns the database supplies
178
+ */
179
+ constructor(
180
+ name: Table.Identifier<Name>,
181
+ // every column's name is quoted as an identifier too
182
+ shape: S &
183
+ ([Extract<keyof S, string>] extends [
184
+ Table.Identifier<Extract<keyof S, string>>,
185
+ ]
186
+ ? unknown
187
+ : "Column names cannot be empty or hold a NUL character") &
188
+ ([Table.Omissible<S>] extends [never]
189
+ ? unknown
190
+ : `Column ${Extract<Table.Omissible<S>, string>} can be left out: use nullable() or the default option, not optional()`),
191
+ options = {} as O &
192
+ (O["schema"] extends string
193
+ ? [Table.Identifier<O["schema"]>] extends [never]
194
+ ? "A schema name cannot be empty or hold a NUL character"
195
+ : unknown
196
+ : unknown),
197
+ ) {
198
+ const description = (options as Described)[described];
199
+
200
+ super({
201
+ type: "object",
202
+ shape,
203
+ mode: "strip",
204
+ ...(description !== undefined && { description }),
205
+ });
206
+
207
+ this.name = name;
208
+ this.shape = shape;
209
+ this.options = options;
210
+
211
+ const columns: Record<string, Column> = {};
212
+
213
+ for (const [key, schema] of Object.entries(shape)) {
214
+ const [type, nullable] = Table.#type(schema.def, `${name}.${key}`);
215
+
216
+ columns[key] = new Column(this, key, type, nullable);
217
+ }
218
+
219
+ this.columns = columns as { readonly [K in keyof S]: Column };
220
+ }
221
+
222
+ override describe(text: string) {
223
+ // still a table, which `derive` would not make, with the names and
224
+ // columns checked when this one was made
225
+ return new Table(
226
+ this.name as never,
227
+ this.shape as never,
228
+ { ...this.options, [described]: text } as never,
229
+ ) as unknown as this;
230
+ }
231
+
232
+ /**
233
+ * Map a column definition to the kind of value it stores.
234
+ *
235
+ * @param def Column schema definition
236
+ * @param column Column label for errors
237
+ * @returns Kind of value and nullability
238
+ */
239
+ static #type(
240
+ def: Schema.Def,
241
+ column: string,
242
+ ): [type: Table.Type, nullable: boolean] {
243
+ switch (def.type) {
244
+ case "string":
245
+ case "boolean":
246
+ case "number":
247
+ case "bigint":
248
+ case "date":
249
+ return [def.type, false];
250
+ case "unknown":
251
+ case "object":
252
+ case "array":
253
+ Table.#json(def, column);
254
+
255
+ return ["json", false];
256
+ case "literal":
257
+ case "enum": {
258
+ const kinds = new Set(
259
+ (def.type === "literal" ? [def.value] : def.values).map(
260
+ (value) => typeof value,
261
+ ),
262
+ );
263
+ const [kind] = kinds;
264
+
265
+ if (
266
+ kinds.size === 1 &&
267
+ (kind === "string" || kind === "boolean" || kind === "number")
268
+ )
269
+ return [kind, false];
270
+
271
+ break;
272
+ }
273
+ case "nullable":
274
+ return [Table.#type(def.inner.def, column)[0], true];
275
+ case "check":
276
+ return Table.#type(def.inner.def, column);
277
+ case "preprocess":
278
+ // form fields normalize their input, a stored value parses unchanged
279
+ if (normalizers.has(def.fn)) return Table.#type(def.inner.def, column);
280
+
281
+ throw Table.#invalid(
282
+ column,
283
+ `preprocess() would change stored values when they are read, convert before inserting instead`,
284
+ );
285
+ case "json":
286
+ throw Table.#invalid(
287
+ column,
288
+ `use the parsed object or array schema for JSON instead of json()`,
289
+ );
290
+ // optional() and nullish() are type errors, see `Table.Omissible`
291
+ case "default":
292
+ throw Table.#invalid(
293
+ column,
294
+ `use nullable() or the default option instead of ${def.type}()`,
295
+ );
296
+ }
297
+
298
+ throw Table.#invalid(
299
+ column,
300
+ `${def.type} schemas cannot be stored as a column`,
301
+ );
302
+ }
303
+
304
+ /**
305
+ * @param column Column label
306
+ * @param problem What is wrong with the column's schema
307
+ * @returns Error for a column schema the table cannot store
308
+ */
309
+ static #invalid(column: string, problem: string) {
310
+ return new TypeError(`Table ${column}: ${problem}`);
311
+ }
312
+
313
+ /**
314
+ * Ensure values stored as JSON parse again when read.
315
+ *
316
+ * @param def Schema definition inside a JSON column
317
+ * @param column Column label for errors
318
+ */
319
+ static #json(def: Schema.Def, column: string): void {
320
+ switch (def.type) {
321
+ case "unknown":
322
+ case "string":
323
+ case "boolean":
324
+ case "number":
325
+ // stored as an ISO string, read back as a date by the table's schema
326
+ case "date":
327
+ return;
328
+ case "literal":
329
+ case "enum":
330
+ if (
331
+ (def.type === "literal" ? [def.value] : def.values).every(
332
+ (value) =>
333
+ value === null ||
334
+ ["string", "number", "boolean", "undefined"].includes(
335
+ typeof value,
336
+ ),
337
+ )
338
+ )
339
+ return;
340
+
341
+ break;
342
+ case "array": {
343
+ const empty = def.item.parse(undefined);
344
+
345
+ // JSON stores undefined items as null, which must parse again
346
+ if (
347
+ !empty.issues &&
348
+ empty.data === undefined &&
349
+ def.item.parse(null).issues
350
+ )
351
+ throw Table.#invalid(
352
+ column,
353
+ `JSON stores undefined array items as null, allow null instead of undefined`,
354
+ );
355
+
356
+ return Table.#json(def.item.def, column);
357
+ }
358
+ case "object":
359
+ for (const schema of Object.values(def.shape)) {
360
+ Table.#json(schema.def, column);
361
+ }
362
+
363
+ return;
364
+ case "union":
365
+ for (const schema of def.options) {
366
+ Table.#json(schema.def, column);
367
+ }
368
+
369
+ return;
370
+ case "pipe":
371
+ Table.#json(def.inner.def, column);
372
+
373
+ return Table.#json(def.next.def, column);
374
+ case "optional":
375
+ case "nullable":
376
+ case "nullish":
377
+ case "default":
378
+ case "check":
379
+ return Table.#json(def.inner.def, column);
380
+ }
381
+
382
+ throw Table.#invalid(
383
+ column,
384
+ `${def.type} schemas cannot be stored in JSON`,
385
+ );
386
+ }
387
+ }
package/src/trie/index.ts CHANGED
@@ -41,8 +41,8 @@ export class Trie {
41
41
  /** Matched wildcard route */
42
42
  wild: Route | undefined;
43
43
 
44
- static readonly #paramMatch = /:.+?(?=\/|$)/g;
45
- static readonly #paramSplit = /:.+?(?=\/|$)/;
44
+ /** A parameter, `split` ignores the global flag `match` needs */
45
+ static readonly #param = /:.+?(?=\/|$)/g;
46
46
 
47
47
  /**
48
48
  * Create a new trie.
@@ -144,8 +144,8 @@ export class Trie {
144
144
  const endsWithWildcard = pattern.endsWith("*");
145
145
  if (endsWithWildcard) pattern = pattern.slice(0, -1);
146
146
 
147
- const paramSegments = pattern.match(Trie.#paramMatch) ?? [];
148
- const staticSegments = pattern.split(Trie.#paramSplit);
147
+ const paramSegments = pattern.match(Trie.#param) ?? [];
148
+ const staticSegments = pattern.split(Trie.#param);
149
149
 
150
150
  // if the last segment is a param without a trailing slash
151
151
  // then there will be an empty string, remove