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.
- package/README.md +3 -1
- package/dist/app/index.d.ts +51 -7
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +163 -28
- package/dist/auth/auth-data.d.ts +26 -0
- package/dist/auth/auth-data.d.ts.map +1 -0
- package/dist/auth/auth-data.js +42 -0
- package/dist/auth/cbor.d.ts +50 -0
- package/dist/auth/cbor.d.ts.map +1 -0
- package/dist/auth/cbor.js +200 -0
- package/dist/auth/client-source.d.ts +3 -0
- package/dist/auth/client-source.d.ts.map +1 -0
- package/dist/auth/client-source.js +3 -0
- package/dist/auth/client.d.ts +3 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +186 -0
- package/dist/auth/configure.d.ts +28 -0
- package/dist/auth/configure.d.ts.map +1 -0
- package/dist/auth/configure.js +228 -0
- package/dist/auth/der.d.ts +6 -0
- package/dist/auth/der.d.ts.map +1 -0
- package/dist/auth/der.js +36 -0
- package/dist/auth/index.d.ts +242 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +152 -0
- package/dist/auth/issue.d.ts +36 -0
- package/dist/auth/issue.d.ts.map +1 -0
- package/dist/auth/issue.js +47 -0
- package/dist/auth/metadata.d.ts +22 -0
- package/dist/auth/metadata.d.ts.map +1 -0
- package/dist/auth/metadata.js +134 -0
- package/dist/auth/oauth.d.ts +29 -0
- package/dist/auth/oauth.d.ts.map +1 -0
- package/dist/auth/oauth.js +724 -0
- package/dist/auth/passkey.d.ts +101 -0
- package/dist/auth/passkey.d.ts.map +1 -0
- package/dist/auth/passkey.js +393 -0
- package/dist/auth/state.d.ts +49 -0
- package/dist/auth/state.d.ts.map +1 -0
- package/dist/auth/state.js +184 -0
- package/dist/auth/storage.d.ts +193 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +410 -0
- package/dist/auth/token.d.ts +12 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +39 -0
- package/dist/context/index.d.ts +86 -16
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +166 -42
- package/dist/cookie/index.d.ts +3 -0
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/cookie/index.js +1 -0
- package/dist/database/index.d.ts +262 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +807 -0
- package/dist/form/index.d.ts +699 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +901 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/jsx/elements.d.ts +28 -2
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts +20 -4
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +6 -65
- package/dist/limiter/index.d.ts +65 -0
- package/dist/limiter/index.d.ts.map +1 -0
- package/dist/limiter/index.js +157 -0
- package/dist/markdown/index.d.ts +61 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +1160 -0
- package/dist/markup/index.d.ts +188 -0
- package/dist/markup/index.d.ts.map +1 -0
- package/dist/markup/index.js +718 -0
- package/dist/mcp/index.d.ts +73 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +988 -0
- package/dist/middleware/index.d.ts +3 -4
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/multipart/index.d.ts +53 -7
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/multipart/index.js +332 -124
- package/dist/route/index.d.ts +226 -80
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +239 -99
- package/dist/schema/index.d.ts +307 -734
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +783 -1050
- package/dist/table/index.d.ts +132 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +188 -0
- package/dist/trie/index.js +4 -4
- package/dist/util/index.d.ts +37 -5
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +156 -41
- package/package.json +11 -4
- package/src/app/index.ts +230 -42
- package/src/auth/auth-data.ts +56 -0
- package/src/auth/cbor.ts +231 -0
- package/src/auth/client-source.ts +3 -0
- package/src/auth/client.ts +205 -0
- package/src/auth/configure.ts +279 -0
- package/src/auth/der.ts +35 -0
- package/src/auth/index.ts +387 -0
- package/src/auth/issue.ts +52 -0
- package/src/auth/metadata.ts +149 -0
- package/src/auth/oauth.ts +882 -0
- package/src/auth/passkey.ts +556 -0
- package/src/auth/state.ts +213 -0
- package/src/auth/storage.ts +572 -0
- package/src/auth/token.ts +67 -0
- package/src/context/index.ts +240 -65
- package/src/cookie/index.ts +3 -0
- package/src/database/index.ts +1193 -0
- package/src/form/index.ts +1720 -0
- package/src/index.ts +10 -3
- package/src/jsx/elements.ts +45 -25
- package/src/jsx/index.ts +24 -69
- package/src/limiter/index.ts +221 -0
- package/src/markdown/index.ts +1322 -0
- package/src/markup/index.ts +853 -0
- package/src/mcp/conformance.2025-11-25.yml +39 -0
- package/src/mcp/conformance.2026-07-28.yml +56 -0
- package/src/mcp/index.ts +1262 -0
- package/src/middleware/index.ts +5 -6
- package/src/multipart/index.ts +410 -158
- package/src/route/index.ts +559 -278
- package/src/schema/index.ts +1542 -2256
- package/src/table/index.ts +387 -0
- package/src/trie/index.ts +4 -4
- package/src/util/index.ts +163 -49
- package/dist/render/index.d.ts +0 -79
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js +0 -257
- package/src/render/index.ts +0 -314
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Schema } from "../schema/index.js";
|
|
2
|
+
export declare namespace Table {
|
|
3
|
+
/** Column schemas keyed by column name. */
|
|
4
|
+
type Shape = Schema.Object.Shape;
|
|
5
|
+
/**
|
|
6
|
+
* Column name of a shape.
|
|
7
|
+
*
|
|
8
|
+
* @template S Table shape
|
|
9
|
+
*/
|
|
10
|
+
type Key<S extends Shape> = Extract<keyof S, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Postgres schema and the columns the database supplies.
|
|
13
|
+
*
|
|
14
|
+
* @template S Table shape
|
|
15
|
+
*/
|
|
16
|
+
interface Options<S extends Shape = Shape> {
|
|
17
|
+
/** Schema containing the table, defaults to the connection's search path. */
|
|
18
|
+
readonly schema?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Columns that may be omitted on insert because the database supplies a
|
|
21
|
+
* value, with a `DEFAULT`, identity, or generated column.
|
|
22
|
+
*/
|
|
23
|
+
readonly default?: readonly Key<S>[];
|
|
24
|
+
}
|
|
25
|
+
/** Any table. */
|
|
26
|
+
type Any = Table<string, any, any>;
|
|
27
|
+
/**
|
|
28
|
+
* Columns whose value may be left out, as with `optional()`, which a row
|
|
29
|
+
* read from the database always has.
|
|
30
|
+
*
|
|
31
|
+
* @template S Table shape
|
|
32
|
+
*/
|
|
33
|
+
type Omissible<S extends Shape> = {
|
|
34
|
+
[K in keyof S]: undefined extends Schema.Infer<S[K]> ? unknown extends Schema.Infer<S[K]> ? never : K : never;
|
|
35
|
+
}[keyof S];
|
|
36
|
+
/**
|
|
37
|
+
* A name Postgres can quote: not empty and without a NUL character.
|
|
38
|
+
*
|
|
39
|
+
* @template N Table, schema, or column name
|
|
40
|
+
*/
|
|
41
|
+
type Identifier<N extends string> = N extends "" | `${string}\0${string}` ? never : N;
|
|
42
|
+
/**
|
|
43
|
+
* Row returned from the table.
|
|
44
|
+
*
|
|
45
|
+
* @template S Table shape
|
|
46
|
+
*/
|
|
47
|
+
type Row<S extends Shape> = {
|
|
48
|
+
[K in keyof S]: Schema.Infer<S[K]>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Column names that may be omitted from an insert: nullable or supplied by the database.
|
|
52
|
+
*
|
|
53
|
+
* @template S Table shape
|
|
54
|
+
* @template O Table options
|
|
55
|
+
*/
|
|
56
|
+
type Defaulted<S extends Shape, O extends Options<S>> = Extract<NonNullable<O["default"]>[number], Key<S>> | {
|
|
57
|
+
[K in Key<S>]: unknown extends Schema.Infer<S[K]> ? never : null extends Schema.Infer<S[K]> ? K : never;
|
|
58
|
+
}[Key<S>];
|
|
59
|
+
/**
|
|
60
|
+
* Values accepted by `sql.values` for one row.
|
|
61
|
+
*
|
|
62
|
+
* @template S Table shape
|
|
63
|
+
* @template O Table options
|
|
64
|
+
*/
|
|
65
|
+
type Insert<S extends Shape, O extends Options<S>> = {
|
|
66
|
+
[K in Exclude<Key<S>, Defaulted<S, O>>]: Schema.Infer<S[K]>;
|
|
67
|
+
} & {
|
|
68
|
+
[K in Defaulted<S, O>]?: Schema.Infer<S[K]>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Values accepted by `sql.set`.
|
|
72
|
+
*
|
|
73
|
+
* @template S Table shape
|
|
74
|
+
*/
|
|
75
|
+
type Update<S extends Shape> = Partial<Row<S>>;
|
|
76
|
+
/** Kind of value a column stores, each compatible with several Postgres types. */
|
|
77
|
+
type Type = "string" | "number" | "bigint" | "boolean" | "date" | "json";
|
|
78
|
+
}
|
|
79
|
+
/** Reference to one column, interpolated by `sql` as a qualified identifier. */
|
|
80
|
+
export declare class Column {
|
|
81
|
+
/** Table containing the column. */
|
|
82
|
+
readonly table: Table.Any;
|
|
83
|
+
/** Column name. */
|
|
84
|
+
readonly name: string;
|
|
85
|
+
/** Kind of value derived from the column schema. */
|
|
86
|
+
readonly type: Table.Type;
|
|
87
|
+
/** If the column allows `NULL`. */
|
|
88
|
+
readonly nullable: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* @param table Table containing the column
|
|
91
|
+
* @param name Column name
|
|
92
|
+
* @param type Kind of value
|
|
93
|
+
* @param nullable If the column allows `NULL`
|
|
94
|
+
*/
|
|
95
|
+
constructor(table: Table.Any, name: string, type: Table.Type, nullable: boolean);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Postgres table defined with validation schemas.
|
|
99
|
+
*
|
|
100
|
+
* The table is a schema of its rows, so `Schema.Infer<typeof table>` is the
|
|
101
|
+
* row type and `sql.parse(table)` validates returned rows. Keys, constraints, and
|
|
102
|
+
* indexes belong in migrations.
|
|
103
|
+
*
|
|
104
|
+
* @template Name Table name
|
|
105
|
+
* @template S Column schemas
|
|
106
|
+
* @template O Table options
|
|
107
|
+
*/
|
|
108
|
+
export declare class Table<Name extends string, S extends Table.Shape, const O extends Table.Options<S> = {}> extends Schema<Table.Row<S>> {
|
|
109
|
+
#private;
|
|
110
|
+
/** Table name. */
|
|
111
|
+
readonly name: Name;
|
|
112
|
+
/** Column schemas. */
|
|
113
|
+
readonly shape: S;
|
|
114
|
+
/** Postgres schema and the columns the database supplies. */
|
|
115
|
+
readonly options: O;
|
|
116
|
+
/** Column references for `sql`. */
|
|
117
|
+
readonly columns: {
|
|
118
|
+
readonly [K in keyof S]: Column;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Define a table.
|
|
122
|
+
*
|
|
123
|
+
* @param name Table name
|
|
124
|
+
* @param shape Column schemas
|
|
125
|
+
* @param options Postgres schema and the columns the database supplies
|
|
126
|
+
*/
|
|
127
|
+
constructor(name: Table.Identifier<Name>, shape: S & ([Extract<keyof S, string>] extends [
|
|
128
|
+
Table.Identifier<Extract<keyof S, string>>
|
|
129
|
+
] ? unknown : "Column names cannot be empty or hold a NUL character") & ([Table.Omissible<S>] extends [never] ? unknown : `Column ${Extract<Table.Omissible<S>, string>} can be left out: use nullable() or the default option, not optional()`), options?: O & (O["schema"] extends string ? [Table.Identifier<O["schema"]>] extends [never] ? "A schema name cannot be empty or hold a NUL character" : unknown : unknown));
|
|
130
|
+
describe(text: string): this;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM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P,UAAU,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,wEAAwE,CAAC,EAC1H,OAAO,GAAS,CAAC,GAChB,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,MAAM,GACxB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC9C,uDAAuD,GACvD,OAAO,GACR,OAAO,CAAC,EAwBZ;IAEQ,QAAQ,CAAC,IAAI,EAAE,MAAM,GAOb,IAAI,CACpB;CA6JD"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Schema, normalizers } from "../schema/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Internal protocol for `describe()`, to give the table it makes its
|
|
4
|
+
* description, which the constructor puts in the schema's definition.
|
|
5
|
+
*/
|
|
6
|
+
const described = Symbol("described");
|
|
7
|
+
/** Reference to one column, interpolated by `sql` as a qualified identifier. */
|
|
8
|
+
export class Column {
|
|
9
|
+
/** Table containing the column. */
|
|
10
|
+
table;
|
|
11
|
+
/** Column name. */
|
|
12
|
+
name;
|
|
13
|
+
/** Kind of value derived from the column schema. */
|
|
14
|
+
type;
|
|
15
|
+
/** If the column allows `NULL`. */
|
|
16
|
+
nullable;
|
|
17
|
+
/**
|
|
18
|
+
* @param table Table containing the column
|
|
19
|
+
* @param name Column name
|
|
20
|
+
* @param type Kind of value
|
|
21
|
+
* @param nullable If the column allows `NULL`
|
|
22
|
+
*/
|
|
23
|
+
constructor(table, name, type, nullable) {
|
|
24
|
+
this.table = table;
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.type = type;
|
|
27
|
+
this.nullable = nullable;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Postgres table defined with validation schemas.
|
|
32
|
+
*
|
|
33
|
+
* The table is a schema of its rows, so `Schema.Infer<typeof table>` is the
|
|
34
|
+
* row type and `sql.parse(table)` validates returned rows. Keys, constraints, and
|
|
35
|
+
* indexes belong in migrations.
|
|
36
|
+
*
|
|
37
|
+
* @template Name Table name
|
|
38
|
+
* @template S Column schemas
|
|
39
|
+
* @template O Table options
|
|
40
|
+
*/
|
|
41
|
+
export class Table extends Schema {
|
|
42
|
+
/** Table name. */
|
|
43
|
+
name;
|
|
44
|
+
/** Column schemas. */
|
|
45
|
+
shape;
|
|
46
|
+
/** Postgres schema and the columns the database supplies. */
|
|
47
|
+
options;
|
|
48
|
+
/** Column references for `sql`. */
|
|
49
|
+
columns;
|
|
50
|
+
/**
|
|
51
|
+
* Define a table.
|
|
52
|
+
*
|
|
53
|
+
* @param name Table name
|
|
54
|
+
* @param shape Column schemas
|
|
55
|
+
* @param options Postgres schema and the columns the database supplies
|
|
56
|
+
*/
|
|
57
|
+
constructor(name,
|
|
58
|
+
// every column's name is quoted as an identifier too
|
|
59
|
+
shape, options = {}) {
|
|
60
|
+
const description = options[described];
|
|
61
|
+
super({
|
|
62
|
+
type: "object",
|
|
63
|
+
shape,
|
|
64
|
+
mode: "strip",
|
|
65
|
+
...(description !== undefined && { description }),
|
|
66
|
+
});
|
|
67
|
+
this.name = name;
|
|
68
|
+
this.shape = shape;
|
|
69
|
+
this.options = options;
|
|
70
|
+
const columns = {};
|
|
71
|
+
for (const [key, schema] of Object.entries(shape)) {
|
|
72
|
+
const [type, nullable] = Table.#type(schema.def, `${name}.${key}`);
|
|
73
|
+
columns[key] = new Column(this, key, type, nullable);
|
|
74
|
+
}
|
|
75
|
+
this.columns = columns;
|
|
76
|
+
}
|
|
77
|
+
describe(text) {
|
|
78
|
+
// still a table, which `derive` would not make, with the names and
|
|
79
|
+
// columns checked when this one was made
|
|
80
|
+
return new Table(this.name, this.shape, { ...this.options, [described]: text });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Map a column definition to the kind of value it stores.
|
|
84
|
+
*
|
|
85
|
+
* @param def Column schema definition
|
|
86
|
+
* @param column Column label for errors
|
|
87
|
+
* @returns Kind of value and nullability
|
|
88
|
+
*/
|
|
89
|
+
static #type(def, column) {
|
|
90
|
+
switch (def.type) {
|
|
91
|
+
case "string":
|
|
92
|
+
case "boolean":
|
|
93
|
+
case "number":
|
|
94
|
+
case "bigint":
|
|
95
|
+
case "date":
|
|
96
|
+
return [def.type, false];
|
|
97
|
+
case "unknown":
|
|
98
|
+
case "object":
|
|
99
|
+
case "array":
|
|
100
|
+
Table.#json(def, column);
|
|
101
|
+
return ["json", false];
|
|
102
|
+
case "literal":
|
|
103
|
+
case "enum": {
|
|
104
|
+
const kinds = new Set((def.type === "literal" ? [def.value] : def.values).map((value) => typeof value));
|
|
105
|
+
const [kind] = kinds;
|
|
106
|
+
if (kinds.size === 1 &&
|
|
107
|
+
(kind === "string" || kind === "boolean" || kind === "number"))
|
|
108
|
+
return [kind, false];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case "nullable":
|
|
112
|
+
return [Table.#type(def.inner.def, column)[0], true];
|
|
113
|
+
case "check":
|
|
114
|
+
return Table.#type(def.inner.def, column);
|
|
115
|
+
case "preprocess":
|
|
116
|
+
// form fields normalize their input, a stored value parses unchanged
|
|
117
|
+
if (normalizers.has(def.fn))
|
|
118
|
+
return Table.#type(def.inner.def, column);
|
|
119
|
+
throw Table.#invalid(column, `preprocess() would change stored values when they are read, convert before inserting instead`);
|
|
120
|
+
case "json":
|
|
121
|
+
throw Table.#invalid(column, `use the parsed object or array schema for JSON instead of json()`);
|
|
122
|
+
// optional() and nullish() are type errors, see `Table.Omissible`
|
|
123
|
+
case "default":
|
|
124
|
+
throw Table.#invalid(column, `use nullable() or the default option instead of ${def.type}()`);
|
|
125
|
+
}
|
|
126
|
+
throw Table.#invalid(column, `${def.type} schemas cannot be stored as a column`);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @param column Column label
|
|
130
|
+
* @param problem What is wrong with the column's schema
|
|
131
|
+
* @returns Error for a column schema the table cannot store
|
|
132
|
+
*/
|
|
133
|
+
static #invalid(column, problem) {
|
|
134
|
+
return new TypeError(`Table ${column}: ${problem}`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Ensure values stored as JSON parse again when read.
|
|
138
|
+
*
|
|
139
|
+
* @param def Schema definition inside a JSON column
|
|
140
|
+
* @param column Column label for errors
|
|
141
|
+
*/
|
|
142
|
+
static #json(def, column) {
|
|
143
|
+
switch (def.type) {
|
|
144
|
+
case "unknown":
|
|
145
|
+
case "string":
|
|
146
|
+
case "boolean":
|
|
147
|
+
case "number":
|
|
148
|
+
// stored as an ISO string, read back as a date by the table's schema
|
|
149
|
+
case "date":
|
|
150
|
+
return;
|
|
151
|
+
case "literal":
|
|
152
|
+
case "enum":
|
|
153
|
+
if ((def.type === "literal" ? [def.value] : def.values).every((value) => value === null ||
|
|
154
|
+
["string", "number", "boolean", "undefined"].includes(typeof value)))
|
|
155
|
+
return;
|
|
156
|
+
break;
|
|
157
|
+
case "array": {
|
|
158
|
+
const empty = def.item.parse(undefined);
|
|
159
|
+
// JSON stores undefined items as null, which must parse again
|
|
160
|
+
if (!empty.issues &&
|
|
161
|
+
empty.data === undefined &&
|
|
162
|
+
def.item.parse(null).issues)
|
|
163
|
+
throw Table.#invalid(column, `JSON stores undefined array items as null, allow null instead of undefined`);
|
|
164
|
+
return Table.#json(def.item.def, column);
|
|
165
|
+
}
|
|
166
|
+
case "object":
|
|
167
|
+
for (const schema of Object.values(def.shape)) {
|
|
168
|
+
Table.#json(schema.def, column);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
case "union":
|
|
172
|
+
for (const schema of def.options) {
|
|
173
|
+
Table.#json(schema.def, column);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
case "pipe":
|
|
177
|
+
Table.#json(def.inner.def, column);
|
|
178
|
+
return Table.#json(def.next.def, column);
|
|
179
|
+
case "optional":
|
|
180
|
+
case "nullable":
|
|
181
|
+
case "nullish":
|
|
182
|
+
case "default":
|
|
183
|
+
case "check":
|
|
184
|
+
return Table.#json(def.inner.def, column);
|
|
185
|
+
}
|
|
186
|
+
throw Table.#invalid(column, `${def.type} schemas cannot be stored in JSON`);
|
|
187
|
+
}
|
|
188
|
+
}
|
package/dist/trie/index.js
CHANGED
|
@@ -25,8 +25,8 @@ export class Trie {
|
|
|
25
25
|
route;
|
|
26
26
|
/** Matched wildcard route */
|
|
27
27
|
wild;
|
|
28
|
-
|
|
29
|
-
static #
|
|
28
|
+
/** A parameter, `split` ignores the global flag `match` needs */
|
|
29
|
+
static #param = /:.+?(?=\/|$)/g;
|
|
30
30
|
/**
|
|
31
31
|
* Create a new trie.
|
|
32
32
|
*
|
|
@@ -106,8 +106,8 @@ export class Trie {
|
|
|
106
106
|
const endsWithWildcard = pattern.endsWith("*");
|
|
107
107
|
if (endsWithWildcard)
|
|
108
108
|
pattern = pattern.slice(0, -1);
|
|
109
|
-
const paramSegments = pattern.match(Trie.#
|
|
110
|
-
const staticSegments = pattern.split(Trie.#
|
|
109
|
+
const paramSegments = pattern.match(Trie.#param) ?? [];
|
|
110
|
+
const staticSegments = pattern.split(Trie.#param);
|
|
111
111
|
// if the last segment is a param without a trailing slash
|
|
112
112
|
// then there will be an empty string, remove
|
|
113
113
|
if (staticSegments.at(-1) === "")
|
package/dist/util/index.d.ts
CHANGED
|
@@ -29,9 +29,14 @@ export declare namespace Util {
|
|
|
29
29
|
/** Media type utils */
|
|
30
30
|
export declare class Mime {
|
|
31
31
|
#private;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Mime type constants. Written out, since a static computed by calling
|
|
34
|
+
* other members is a side effect, which keeps the class in every bundle
|
|
35
|
+
* that imports this module.
|
|
36
|
+
*/
|
|
33
37
|
static type: {
|
|
34
38
|
readonly html: "text/html";
|
|
39
|
+
readonly md: "text/markdown";
|
|
35
40
|
readonly text: "text/plain";
|
|
36
41
|
readonly json: "application/json";
|
|
37
42
|
readonly stream: "application/octet-stream";
|
|
@@ -62,23 +67,42 @@ export declare class Header {
|
|
|
62
67
|
readonly loc: "location";
|
|
63
68
|
readonly origin: "origin";
|
|
64
69
|
readonly fetch: "sec-fetch-site";
|
|
70
|
+
readonly accept: "accept";
|
|
71
|
+
readonly vary: "vary";
|
|
65
72
|
};
|
|
66
73
|
/**
|
|
67
|
-
* @
|
|
68
|
-
* @
|
|
74
|
+
* @template M Media type
|
|
75
|
+
* @param mime Media type
|
|
76
|
+
* @returns The media type with `; charset=utf-8`
|
|
69
77
|
*/
|
|
70
78
|
static utf8<M extends string>(mime: M): `${M}; charset=utf-8`;
|
|
71
79
|
/**
|
|
72
80
|
* @param header header value to parse
|
|
73
|
-
* @returns Base
|
|
81
|
+
* @returns Base, trimmed and lowercase since media types ignore case, and its params
|
|
74
82
|
*/
|
|
75
83
|
static shift(header: string | null): [string | null, string | null];
|
|
84
|
+
/**
|
|
85
|
+
* @param accept `Accept` header
|
|
86
|
+
* @param mime Media type to look for
|
|
87
|
+
* @param exact Ignore wildcard ranges
|
|
88
|
+
* @returns The quality the header gives the type, by its most specific match
|
|
89
|
+
*/
|
|
90
|
+
static quality(accept: string | null, mime: string, exact?: boolean): number;
|
|
76
91
|
/**
|
|
77
92
|
* @param header header value to parse
|
|
93
|
+
* @param insensitive Lowercase each key, a parameter's name is
|
|
94
|
+
* case-insensitive, a cookie's is not
|
|
78
95
|
* @returns Map containing each key=value pair
|
|
79
96
|
*/
|
|
80
|
-
static params(header: string | null): Record<string, string>;
|
|
97
|
+
static params(header: string | null, insensitive?: boolean): Record<string, string>;
|
|
81
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Keeps a response out of shared and browser caches, for one that is
|
|
101
|
+
* personal or used once.
|
|
102
|
+
*
|
|
103
|
+
* @param headers Response headers
|
|
104
|
+
*/
|
|
105
|
+
export declare const noStore: (headers: Headers) => void;
|
|
82
106
|
/** Checksum util */
|
|
83
107
|
export declare class Checksum {
|
|
84
108
|
/**
|
|
@@ -108,6 +132,14 @@ export declare class Codec {
|
|
|
108
132
|
* @returns Decoded string
|
|
109
133
|
*/
|
|
110
134
|
static decode(bytes?: Uint8Array): string;
|
|
135
|
+
/**
|
|
136
|
+
* Reads a body, cancelling it as soon as it exceeds the limit.
|
|
137
|
+
*
|
|
138
|
+
* @param body Body to read
|
|
139
|
+
* @param limit Largest size in bytes
|
|
140
|
+
* @returns The bytes, or `undefined` when the body is too large
|
|
141
|
+
*/
|
|
142
|
+
static read(body: ReadableStream<Uint8Array> | null, limit: number): Promise<Uint8Array<ArrayBufferLike> | undefined>;
|
|
111
143
|
static readonly Base64: {
|
|
112
144
|
new (): {};
|
|
113
145
|
/**
|
package/dist/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,yBAAiB,IAAI,CAAC;IACrB;;;;;;;OAOG;IACH,KAAY,SAAS,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI;QAC3D,SAAS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;KACnD,CAAC,WAAW,CAAC,CAAC;IAEf;;;;OAIG;IACH,KAAY,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9C;;;;OAIG;IACH,KAAY,QAAQ,CAAC,CAAC,IAAI;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAAE,GAAG,EAAE,CAAC;CACxD;AAED,uBAAuB;AACvB,qBAAa,IAAI;;IAChB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,yBAAiB,IAAI,CAAC;IACrB;;;;;;;OAOG;IACH,KAAY,SAAS,C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