semola 0.5.3 → 0.5.4
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/dist/index-BhGNDjPq.d.mts +13 -0
- package/dist/index-DxSbeGP-.d.cts +13 -0
- package/dist/lib/api/index.cjs +522 -4
- package/dist/lib/api/index.d.cts +270 -4
- package/dist/lib/api/index.d.mts +270 -4
- package/dist/lib/api/index.mjs +520 -2
- package/dist/lib/cache/index.d.cts +16 -4
- package/dist/lib/cache/index.d.mts +16 -4
- package/dist/lib/cache/index.mjs +0 -2
- package/dist/lib/cron/index.cjs +734 -12
- package/dist/lib/cron/index.d.cts +145 -3
- package/dist/lib/cron/index.d.mts +145 -3
- package/dist/lib/cron/index.mjs +725 -3
- package/dist/lib/errors/index.d.cts +2 -13
- package/dist/lib/errors/index.d.mts +2 -13
- package/dist/lib/errors/index.mjs +0 -2
- package/dist/lib/i18n/index.d.cts +12 -4
- package/dist/lib/i18n/index.d.mts +12 -4
- package/dist/lib/i18n/index.mjs +0 -2
- package/dist/lib/logging/index.cjs +386 -17
- package/dist/lib/logging/index.d.cts +107 -6
- package/dist/lib/logging/index.d.mts +107 -6
- package/dist/lib/logging/index.mjs +373 -4
- package/dist/lib/policy/index.cjs +206 -20
- package/dist/lib/policy/index.d.cts +61 -5
- package/dist/lib/policy/index.d.mts +61 -5
- package/dist/lib/policy/index.mjs +187 -3
- package/dist/lib/prompts/index.cjs +374 -14
- package/dist/lib/prompts/index.d.cts +69 -4
- package/dist/lib/prompts/index.d.mts +69 -4
- package/dist/lib/prompts/index.mjs +362 -4
- package/dist/lib/pubsub/index.d.cts +9 -4
- package/dist/lib/pubsub/index.d.mts +9 -4
- package/dist/lib/pubsub/index.mjs +0 -2
- package/dist/lib/queue/index.d.cts +48 -6
- package/dist/lib/queue/index.d.mts +48 -6
- package/dist/lib/queue/index.mjs +0 -2
- package/dist/lib/workflow/index.d.cts +82 -4
- package/dist/lib/workflow/index.d.mts +82 -4
- package/dist/lib/workflow/index.mjs +0 -2
- package/package.json +1 -1
- package/dist/api/core/index.cjs +0 -206
- package/dist/api/core/index.d.cts +0 -21
- package/dist/api/core/index.d.cts.map +0 -1
- package/dist/api/core/index.d.mts +0 -21
- package/dist/api/core/index.d.mts.map +0 -1
- package/dist/api/core/index.mjs +0 -208
- package/dist/api/core/index.mjs.map +0 -1
- package/dist/api/core/types.d.cts +0 -107
- package/dist/api/core/types.d.cts.map +0 -1
- package/dist/api/core/types.d.mts +0 -107
- package/dist/api/core/types.d.mts.map +0 -1
- package/dist/api/middleware/index.cjs +0 -8
- package/dist/api/middleware/index.d.cts +0 -11
- package/dist/api/middleware/index.d.cts.map +0 -1
- package/dist/api/middleware/index.d.mts +0 -11
- package/dist/api/middleware/index.d.mts.map +0 -1
- package/dist/api/middleware/index.mjs +0 -10
- package/dist/api/middleware/index.mjs.map +0 -1
- package/dist/api/middleware/types.d.cts +0 -16
- package/dist/api/middleware/types.d.cts.map +0 -1
- package/dist/api/middleware/types.d.mts +0 -16
- package/dist/api/middleware/types.d.mts.map +0 -1
- package/dist/api/openapi/index.cjs +0 -254
- package/dist/api/openapi/index.mjs +0 -256
- package/dist/api/openapi/index.mjs.map +0 -1
- package/dist/api/openapi/types.d.cts +0 -60
- package/dist/api/openapi/types.d.cts.map +0 -1
- package/dist/api/openapi/types.d.mts +0 -60
- package/dist/api/openapi/types.d.mts.map +0 -1
- package/dist/api/validation/index.cjs +0 -64
- package/dist/api/validation/index.mjs +0 -61
- package/dist/api/validation/index.mjs.map +0 -1
- package/dist/cache/types.d.cts +0 -17
- package/dist/cache/types.d.cts.map +0 -1
- package/dist/cache/types.d.mts +0 -17
- package/dist/cache/types.d.mts.map +0 -1
- package/dist/cron/builder/index.cjs +0 -166
- package/dist/cron/builder/index.d.cts +0 -28
- package/dist/cron/builder/index.d.cts.map +0 -1
- package/dist/cron/builder/index.d.mts +0 -28
- package/dist/cron/builder/index.d.mts.map +0 -1
- package/dist/cron/builder/index.mjs +0 -163
- package/dist/cron/builder/index.mjs.map +0 -1
- package/dist/cron/builder/types.cjs +0 -27
- package/dist/cron/builder/types.d.cts +0 -79
- package/dist/cron/builder/types.d.cts.map +0 -1
- package/dist/cron/builder/types.d.mts +0 -79
- package/dist/cron/builder/types.d.mts.map +0 -1
- package/dist/cron/builder/types.mjs +0 -28
- package/dist/cron/builder/types.mjs.map +0 -1
- package/dist/cron/core/index.cjs +0 -308
- package/dist/cron/core/index.d.cts +0 -39
- package/dist/cron/core/index.d.cts.map +0 -1
- package/dist/cron/core/index.d.mts +0 -39
- package/dist/cron/core/index.d.mts.map +0 -1
- package/dist/cron/core/index.mjs +0 -310
- package/dist/cron/core/index.mjs.map +0 -1
- package/dist/cron/core/scanner.cjs +0 -237
- package/dist/cron/core/scanner.mjs +0 -238
- package/dist/cron/core/scanner.mjs.map +0 -1
- package/dist/cron/core/types.d.cts +0 -11
- package/dist/cron/core/types.d.cts.map +0 -1
- package/dist/cron/core/types.d.mts +0 -11
- package/dist/cron/core/types.d.mts.map +0 -1
- package/dist/errors/types.d.cts +0 -5
- package/dist/errors/types.d.cts.map +0 -1
- package/dist/errors/types.d.mts +0 -5
- package/dist/errors/types.d.mts.map +0 -1
- package/dist/i18n/types.d.cts +0 -13
- package/dist/i18n/types.d.cts.map +0 -1
- package/dist/i18n/types.d.mts +0 -13
- package/dist/i18n/types.d.mts.map +0 -1
- package/dist/lib/cache/index.d.cts.map +0 -1
- package/dist/lib/cache/index.d.mts.map +0 -1
- package/dist/lib/cache/index.mjs.map +0 -1
- package/dist/lib/errors/index.d.cts.map +0 -1
- package/dist/lib/errors/index.d.mts.map +0 -1
- package/dist/lib/errors/index.mjs.map +0 -1
- package/dist/lib/i18n/index.d.cts.map +0 -1
- package/dist/lib/i18n/index.d.mts.map +0 -1
- package/dist/lib/i18n/index.mjs.map +0 -1
- package/dist/lib/orm/index.cjs +0 -20
- package/dist/lib/orm/index.d.cts +0 -7
- package/dist/lib/orm/index.d.mts +0 -7
- package/dist/lib/orm/index.mjs +0 -6
- package/dist/lib/policy/index.d.cts.map +0 -1
- package/dist/lib/policy/index.d.mts.map +0 -1
- package/dist/lib/policy/index.mjs.map +0 -1
- package/dist/lib/prompts/index.d.cts.map +0 -1
- package/dist/lib/prompts/index.d.mts.map +0 -1
- package/dist/lib/prompts/index.mjs.map +0 -1
- package/dist/lib/pubsub/index.d.cts.map +0 -1
- package/dist/lib/pubsub/index.d.mts.map +0 -1
- package/dist/lib/pubsub/index.mjs.map +0 -1
- package/dist/lib/queue/index.d.cts.map +0 -1
- package/dist/lib/queue/index.d.mts.map +0 -1
- package/dist/lib/queue/index.mjs.map +0 -1
- package/dist/lib/workflow/index.d.cts.map +0 -1
- package/dist/lib/workflow/index.d.mts.map +0 -1
- package/dist/lib/workflow/index.mjs.map +0 -1
- package/dist/logging/core/index.cjs +0 -99
- package/dist/logging/core/index.d.cts +0 -26
- package/dist/logging/core/index.d.cts.map +0 -1
- package/dist/logging/core/index.d.mts +0 -26
- package/dist/logging/core/index.d.mts.map +0 -1
- package/dist/logging/core/index.mjs +0 -99
- package/dist/logging/core/index.mjs.map +0 -1
- package/dist/logging/core/types.cjs +0 -10
- package/dist/logging/core/types.d.cts +0 -22
- package/dist/logging/core/types.d.cts.map +0 -1
- package/dist/logging/core/types.d.mts +0 -22
- package/dist/logging/core/types.d.mts.map +0 -1
- package/dist/logging/core/types.mjs +0 -12
- package/dist/logging/core/types.mjs.map +0 -1
- package/dist/logging/formatter/index.cjs +0 -119
- package/dist/logging/formatter/index.d.cts +0 -27
- package/dist/logging/formatter/index.d.cts.map +0 -1
- package/dist/logging/formatter/index.d.mts +0 -27
- package/dist/logging/formatter/index.d.mts.map +0 -1
- package/dist/logging/formatter/index.mjs +0 -115
- package/dist/logging/formatter/index.mjs.map +0 -1
- package/dist/logging/formatter/types.d.cts +0 -5
- package/dist/logging/formatter/types.d.cts.map +0 -1
- package/dist/logging/formatter/types.d.mts +0 -5
- package/dist/logging/formatter/types.d.mts.map +0 -1
- package/dist/logging/provider/index.cjs +0 -165
- package/dist/logging/provider/index.d.cts +0 -28
- package/dist/logging/provider/index.d.cts.map +0 -1
- package/dist/logging/provider/index.d.mts +0 -28
- package/dist/logging/provider/index.d.mts.map +0 -1
- package/dist/logging/provider/index.mjs +0 -165
- package/dist/logging/provider/index.mjs.map +0 -1
- package/dist/logging/provider/types.d.cts +0 -23
- package/dist/logging/provider/types.d.cts.map +0 -1
- package/dist/logging/provider/types.d.mts +0 -23
- package/dist/logging/provider/types.d.mts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
- package/dist/orm/column.cjs +0 -137
- package/dist/orm/column.d.cts +0 -121
- package/dist/orm/column.d.cts.map +0 -1
- package/dist/orm/column.d.mts +0 -121
- package/dist/orm/column.d.mts.map +0 -1
- package/dist/orm/column.mjs +0 -132
- package/dist/orm/column.mjs.map +0 -1
- package/dist/orm/dialect/index.cjs +0 -14
- package/dist/orm/dialect/index.mjs +0 -16
- package/dist/orm/dialect/index.mjs.map +0 -1
- package/dist/orm/dialect/mysql.cjs +0 -31
- package/dist/orm/dialect/mysql.mjs +0 -33
- package/dist/orm/dialect/mysql.mjs.map +0 -1
- package/dist/orm/dialect/postgres.cjs +0 -23
- package/dist/orm/dialect/postgres.mjs +0 -25
- package/dist/orm/dialect/postgres.mjs.map +0 -1
- package/dist/orm/dialect/sqlite.cjs +0 -31
- package/dist/orm/dialect/sqlite.mjs +0 -33
- package/dist/orm/dialect/sqlite.mjs.map +0 -1
- package/dist/orm/dialect/utils.cjs +0 -8
- package/dist/orm/dialect/utils.mjs +0 -10
- package/dist/orm/dialect/utils.mjs.map +0 -1
- package/dist/orm/internal/table-columns.cjs +0 -31
- package/dist/orm/internal/table-columns.mjs +0 -32
- package/dist/orm/internal/table-columns.mjs.map +0 -1
- package/dist/orm/internal/table-lookup.cjs +0 -35
- package/dist/orm/internal/table-lookup.mjs +0 -35
- package/dist/orm/internal/table-lookup.mjs.map +0 -1
- package/dist/orm/internal/table-relations.cjs +0 -28
- package/dist/orm/internal/table-relations.mjs +0 -29
- package/dist/orm/internal/table-relations.mjs.map +0 -1
- package/dist/orm/migration/config.cjs +0 -7
- package/dist/orm/migration/config.d.cts +0 -7
- package/dist/orm/migration/config.d.cts.map +0 -1
- package/dist/orm/migration/config.d.mts +0 -7
- package/dist/orm/migration/config.d.mts.map +0 -1
- package/dist/orm/migration/config.mjs +0 -8
- package/dist/orm/migration/config.mjs.map +0 -1
- package/dist/orm/migration/types.d.cts +0 -20
- package/dist/orm/migration/types.d.cts.map +0 -1
- package/dist/orm/migration/types.d.mts +0 -20
- package/dist/orm/migration/types.d.mts.map +0 -1
- package/dist/orm/orm.cjs +0 -41
- package/dist/orm/orm.d.cts +0 -18
- package/dist/orm/orm.d.cts.map +0 -1
- package/dist/orm/orm.d.mts +0 -18
- package/dist/orm/orm.d.mts.map +0 -1
- package/dist/orm/orm.mjs +0 -43
- package/dist/orm/orm.mjs.map +0 -1
- package/dist/orm/relation.cjs +0 -18
- package/dist/orm/relation.d.cts +0 -8
- package/dist/orm/relation.d.cts.map +0 -1
- package/dist/orm/relation.d.mts +0 -8
- package/dist/orm/relation.d.mts.map +0 -1
- package/dist/orm/relation.mjs +0 -19
- package/dist/orm/relation.mjs.map +0 -1
- package/dist/orm/runtime/builders/mutations.cjs +0 -29
- package/dist/orm/runtime/builders/mutations.mjs +0 -28
- package/dist/orm/runtime/builders/mutations.mjs.map +0 -1
- package/dist/orm/runtime/builders/select.cjs +0 -18
- package/dist/orm/runtime/builders/select.mjs +0 -19
- package/dist/orm/runtime/builders/select.mjs.map +0 -1
- package/dist/orm/runtime/client.cjs +0 -90
- package/dist/orm/runtime/client.mjs +0 -92
- package/dist/orm/runtime/client.mjs.map +0 -1
- package/dist/orm/runtime/context.cjs +0 -49
- package/dist/orm/runtime/context.mjs +0 -51
- package/dist/orm/runtime/context.mjs.map +0 -1
- package/dist/orm/runtime/dialect/index.cjs +0 -11
- package/dist/orm/runtime/dialect/index.mjs +0 -13
- package/dist/orm/runtime/dialect/index.mjs.map +0 -1
- package/dist/orm/runtime/dialect/mysql.cjs +0 -95
- package/dist/orm/runtime/dialect/mysql.mjs +0 -97
- package/dist/orm/runtime/dialect/mysql.mjs.map +0 -1
- package/dist/orm/runtime/dialect/postgres.cjs +0 -51
- package/dist/orm/runtime/dialect/postgres.mjs +0 -53
- package/dist/orm/runtime/dialect/postgres.mjs.map +0 -1
- package/dist/orm/runtime/dialect/sqlite.cjs +0 -4
- package/dist/orm/runtime/dialect/sqlite.mjs +0 -7
- package/dist/orm/runtime/dialect/sqlite.mjs.map +0 -1
- package/dist/orm/runtime/errors.cjs +0 -19
- package/dist/orm/runtime/errors.mjs +0 -21
- package/dist/orm/runtime/errors.mjs.map +0 -1
- package/dist/orm/runtime/hydrate/many.cjs +0 -46
- package/dist/orm/runtime/hydrate/many.mjs +0 -48
- package/dist/orm/runtime/hydrate/many.mjs.map +0 -1
- package/dist/orm/runtime/hydrate/one.cjs +0 -38
- package/dist/orm/runtime/hydrate/one.mjs +0 -40
- package/dist/orm/runtime/hydrate/one.mjs.map +0 -1
- package/dist/orm/runtime/hydrate.cjs +0 -49
- package/dist/orm/runtime/hydrate.mjs +0 -51
- package/dist/orm/runtime/hydrate.mjs.map +0 -1
- package/dist/orm/runtime/rows.cjs +0 -30
- package/dist/orm/runtime/rows.mjs +0 -31
- package/dist/orm/runtime/rows.mjs.map +0 -1
- package/dist/orm/runtime/utils.cjs +0 -27
- package/dist/orm/runtime/utils.mjs +0 -27
- package/dist/orm/runtime/utils.mjs.map +0 -1
- package/dist/orm/sql/parse-array.cjs +0 -64
- package/dist/orm/sql/parse-array.mjs +0 -66
- package/dist/orm/sql/parse-array.mjs.map +0 -1
- package/dist/orm/sql/plan/select.cjs +0 -36
- package/dist/orm/sql/plan/select.mjs +0 -38
- package/dist/orm/sql/plan/select.mjs.map +0 -1
- package/dist/orm/sql/plan/where/operators.cjs +0 -95
- package/dist/orm/sql/plan/where/operators.mjs +0 -97
- package/dist/orm/sql/plan/where/operators.mjs.map +0 -1
- package/dist/orm/sql/plan/where.cjs +0 -59
- package/dist/orm/sql/plan/where.mjs +0 -61
- package/dist/orm/sql/plan/where.mjs.map +0 -1
- package/dist/orm/sql/serialize/clauses.cjs +0 -36
- package/dist/orm/sql/serialize/clauses.mjs +0 -37
- package/dist/orm/sql/serialize/clauses.mjs.map +0 -1
- package/dist/orm/sql/serialize/joins.cjs +0 -31
- package/dist/orm/sql/serialize/joins.mjs +0 -33
- package/dist/orm/sql/serialize/joins.mjs.map +0 -1
- package/dist/orm/sql/serialize/values.cjs +0 -30
- package/dist/orm/sql/serialize/values.mjs +0 -32
- package/dist/orm/sql/serialize/values.mjs.map +0 -1
- package/dist/orm/sql/serialize/where/predicate.cjs +0 -73
- package/dist/orm/sql/serialize/where/predicate.mjs +0 -75
- package/dist/orm/sql/serialize/where/predicate.mjs.map +0 -1
- package/dist/orm/sql/serialize/where/tree.cjs +0 -26
- package/dist/orm/sql/serialize/where/tree.mjs +0 -28
- package/dist/orm/sql/serialize/where/tree.mjs.map +0 -1
- package/dist/orm/sql/serialize/where.cjs +0 -10
- package/dist/orm/sql/serialize/where.mjs +0 -12
- package/dist/orm/sql/serialize/where.mjs.map +0 -1
- package/dist/orm/sql/serialize.cjs +0 -24
- package/dist/orm/sql/serialize.mjs +0 -25
- package/dist/orm/sql/serialize.mjs.map +0 -1
- package/dist/orm/table.cjs +0 -12
- package/dist/orm/table.d.cts +0 -12
- package/dist/orm/table.d.cts.map +0 -1
- package/dist/orm/table.d.mts +0 -12
- package/dist/orm/table.d.mts.map +0 -1
- package/dist/orm/table.mjs +0 -14
- package/dist/orm/table.mjs.map +0 -1
- package/dist/orm/types.d.cts +0 -183
- package/dist/orm/types.d.cts.map +0 -1
- package/dist/orm/types.d.mts +0 -183
- package/dist/orm/types.d.mts.map +0 -1
- package/dist/policy/helpers.cjs +0 -206
- package/dist/policy/helpers.d.cts +0 -50
- package/dist/policy/helpers.d.cts.map +0 -1
- package/dist/policy/helpers.d.mts +0 -50
- package/dist/policy/helpers.d.mts.map +0 -1
- package/dist/policy/helpers.mjs +0 -190
- package/dist/policy/helpers.mjs.map +0 -1
- package/dist/policy/types.d.cts +0 -16
- package/dist/policy/types.d.cts.map +0 -1
- package/dist/policy/types.d.mts +0 -16
- package/dist/policy/types.d.mts.map +0 -1
- package/dist/prompts/core/keys.cjs +0 -165
- package/dist/prompts/core/keys.mjs +0 -167
- package/dist/prompts/core/keys.mjs.map +0 -1
- package/dist/prompts/core/runtime.cjs +0 -104
- package/dist/prompts/core/runtime.mjs +0 -106
- package/dist/prompts/core/runtime.mjs.map +0 -1
- package/dist/prompts/core/session.cjs +0 -98
- package/dist/prompts/core/session.mjs +0 -100
- package/dist/prompts/core/session.mjs.map +0 -1
- package/dist/prompts/core/types.d.cts +0 -21
- package/dist/prompts/core/types.d.cts.map +0 -1
- package/dist/prompts/core/types.d.mts +0 -21
- package/dist/prompts/core/types.d.mts.map +0 -1
- package/dist/prompts/types.d.cts +0 -52
- package/dist/prompts/types.d.cts.map +0 -1
- package/dist/prompts/types.d.mts +0 -52
- package/dist/prompts/types.d.mts.map +0 -1
- package/dist/pubsub/types.d.cts +0 -10
- package/dist/pubsub/types.d.cts.map +0 -1
- package/dist/pubsub/types.d.mts +0 -10
- package/dist/pubsub/types.d.mts.map +0 -1
- package/dist/queue/types.d.cts +0 -47
- package/dist/queue/types.d.cts.map +0 -1
- package/dist/queue/types.d.mts +0 -47
- package/dist/queue/types.d.mts.map +0 -1
- package/dist/workflow/types.d.cts +0 -83
- package/dist/workflow/types.d.cts.map +0 -1
- package/dist/workflow/types.d.mts +0 -83
- package/dist/workflow/types.d.mts.map +0 -1
package/dist/lib/api/index.mjs
CHANGED
|
@@ -1,3 +1,521 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { err, mightThrow, ok } from "../errors/index.mjs";
|
|
2
|
+
//#region src/lib/api/openapi/index.ts
|
|
3
|
+
const toOpenAPISchema = (schema, io = "input") => ({ schema: schema["~standard"].jsonSchema[io]({ target: "draft-2020-12" }) });
|
|
4
|
+
const getSchemaDescription = (schema) => {
|
|
5
|
+
const metadata = schema["~standard"];
|
|
6
|
+
if (!metadata) return "";
|
|
7
|
+
if ("description" in metadata && typeof metadata.description === "string") return metadata.description;
|
|
8
|
+
return "";
|
|
9
|
+
};
|
|
10
|
+
const requestFields = [
|
|
11
|
+
"body",
|
|
12
|
+
"query",
|
|
13
|
+
"headers",
|
|
14
|
+
"cookies",
|
|
15
|
+
"params"
|
|
16
|
+
];
|
|
17
|
+
const mergeRequestSchemas = (schemas) => {
|
|
18
|
+
const merged = {};
|
|
19
|
+
for (const schema of schemas) {
|
|
20
|
+
if (!schema) continue;
|
|
21
|
+
for (const field of requestFields) if (schema[field]) merged[field] = schema[field];
|
|
22
|
+
}
|
|
23
|
+
return merged;
|
|
24
|
+
};
|
|
25
|
+
const mergeResponseSchemas = (schemas) => {
|
|
26
|
+
const merged = {};
|
|
27
|
+
for (const schema of schemas) {
|
|
28
|
+
if (!schema) continue;
|
|
29
|
+
for (const status in schema) {
|
|
30
|
+
const statusCode = Number(status);
|
|
31
|
+
const responseSchema = schema[statusCode];
|
|
32
|
+
if (responseSchema) merged[statusCode] = responseSchema;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
36
|
+
};
|
|
37
|
+
const convertSchemaToOpenApi = async (schema, io = "input") => {
|
|
38
|
+
const result = toOpenAPISchema(schema, io);
|
|
39
|
+
const { schema: jsonSchema } = result;
|
|
40
|
+
const schemaId = jsonSchema.id;
|
|
41
|
+
if (schemaId && typeof schemaId === "string") {
|
|
42
|
+
const schemaWithoutId = { ...jsonSchema };
|
|
43
|
+
delete schemaWithoutId.id;
|
|
44
|
+
delete schemaWithoutId.$schema;
|
|
45
|
+
return {
|
|
46
|
+
schema: { $ref: `#/components/schemas/${schemaId}` },
|
|
47
|
+
components: { schemas: { [schemaId]: schemaWithoutId } }
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (jsonSchema.$schema) {
|
|
51
|
+
const schemaWithoutMeta = { ...jsonSchema };
|
|
52
|
+
delete schemaWithoutMeta.$schema;
|
|
53
|
+
return {
|
|
54
|
+
schema: schemaWithoutMeta,
|
|
55
|
+
components: void 0
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
const convertSchemaToInlineOpenApi = async (schema, io = "input") => {
|
|
61
|
+
const { schema: jsonSchema } = toOpenAPISchema(schema, io);
|
|
62
|
+
const cleanSchema = { ...jsonSchema };
|
|
63
|
+
delete cleanSchema.$schema;
|
|
64
|
+
delete cleanSchema.id;
|
|
65
|
+
return {
|
|
66
|
+
schema: cleanSchema,
|
|
67
|
+
components: void 0
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const extractParametersFromSchema = async (schema, location) => {
|
|
71
|
+
const { schema: jsonSchema, components } = await convertSchemaToInlineOpenApi(schema);
|
|
72
|
+
if (jsonSchema.type !== "object") return {
|
|
73
|
+
parameters: [],
|
|
74
|
+
components
|
|
75
|
+
};
|
|
76
|
+
if (!jsonSchema.properties) return {
|
|
77
|
+
parameters: [],
|
|
78
|
+
components
|
|
79
|
+
};
|
|
80
|
+
const parameters = [];
|
|
81
|
+
const requiredFields = jsonSchema.required ?? [];
|
|
82
|
+
for (const name in jsonSchema.properties) {
|
|
83
|
+
const propertySchema = jsonSchema.properties[name];
|
|
84
|
+
const isRequired = requiredFields.includes(name);
|
|
85
|
+
parameters.push({
|
|
86
|
+
name,
|
|
87
|
+
in: location,
|
|
88
|
+
required: isRequired,
|
|
89
|
+
schema: propertySchema
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
parameters,
|
|
94
|
+
components
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const normalizePathForOpenAPI = (path) => {
|
|
98
|
+
return path.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, "{$1}");
|
|
99
|
+
};
|
|
100
|
+
const extractPathParameters = (path) => {
|
|
101
|
+
const matches = path.match(/:([a-zA-Z_][a-zA-Z0-9_]*)/g);
|
|
102
|
+
if (!matches) return [];
|
|
103
|
+
return matches.map((match) => match.slice(1));
|
|
104
|
+
};
|
|
105
|
+
const paramSources = [
|
|
106
|
+
["query", "query"],
|
|
107
|
+
["headers", "header"],
|
|
108
|
+
["cookies", "cookie"]
|
|
109
|
+
];
|
|
110
|
+
const createParameters = async (request, path) => {
|
|
111
|
+
const parameters = [];
|
|
112
|
+
const allComponents = [];
|
|
113
|
+
for (const [field, location] of paramSources) if (request[field]) {
|
|
114
|
+
const { parameters: params, components } = await extractParametersFromSchema(request[field], location);
|
|
115
|
+
parameters.push(...params);
|
|
116
|
+
if (components) allComponents.push(components);
|
|
117
|
+
}
|
|
118
|
+
const pathParamNames = extractPathParameters(path);
|
|
119
|
+
if (pathParamNames.length > 0 && request.params) {
|
|
120
|
+
const { schema: jsonSchema, components } = await convertSchemaToInlineOpenApi(request.params);
|
|
121
|
+
if (components) allComponents.push(components);
|
|
122
|
+
if (jsonSchema.type === "object" && jsonSchema.properties) for (const name of pathParamNames) {
|
|
123
|
+
const propertySchema = jsonSchema.properties[name];
|
|
124
|
+
if (propertySchema) parameters.push({
|
|
125
|
+
name,
|
|
126
|
+
in: "path",
|
|
127
|
+
required: true,
|
|
128
|
+
schema: propertySchema
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
parameters,
|
|
134
|
+
components: allComponents
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const createRequestBody = async (bodySchema) => {
|
|
138
|
+
const { schema, components } = await convertSchemaToOpenApi(bodySchema);
|
|
139
|
+
return {
|
|
140
|
+
components,
|
|
141
|
+
requestBody: {
|
|
142
|
+
required: true,
|
|
143
|
+
content: { "application/json": { schema } }
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const createResponses = async (response) => {
|
|
148
|
+
const responses = {};
|
|
149
|
+
const allComponents = [];
|
|
150
|
+
if (!response) return {
|
|
151
|
+
responses,
|
|
152
|
+
components: allComponents
|
|
153
|
+
};
|
|
154
|
+
for (const status in response) {
|
|
155
|
+
const statusCode = String(status);
|
|
156
|
+
const schema = response[Number(status)];
|
|
157
|
+
if (!schema) continue;
|
|
158
|
+
const description = getSchemaDescription(schema);
|
|
159
|
+
const { schema: jsonSchema, components } = await convertSchemaToOpenApi(schema, "output");
|
|
160
|
+
if (components) allComponents.push(components);
|
|
161
|
+
responses[statusCode] = {
|
|
162
|
+
description: description || `Response with status ${statusCode}`,
|
|
163
|
+
content: { "application/json": { schema: jsonSchema } }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
responses,
|
|
168
|
+
components: allComponents
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
const createOperation = async (route, globalMiddlewares, prefix) => {
|
|
172
|
+
const allMiddlewares = [...globalMiddlewares ?? [], ...route.middlewares ?? []];
|
|
173
|
+
const requestSchemas = [];
|
|
174
|
+
const responseSchemas = [];
|
|
175
|
+
for (const middleware of allMiddlewares) {
|
|
176
|
+
requestSchemas.push(middleware.options.request);
|
|
177
|
+
responseSchemas.push(middleware.options.response);
|
|
178
|
+
}
|
|
179
|
+
requestSchemas.push(route.request);
|
|
180
|
+
responseSchemas.push(route.response);
|
|
181
|
+
const mergedRequest = mergeRequestSchemas(requestSchemas);
|
|
182
|
+
const mergedResponse = mergeResponseSchemas(responseSchemas);
|
|
183
|
+
const { parameters, components: parameterComponents } = await createParameters(mergedRequest, prefix ? prefix + route.path : route.path);
|
|
184
|
+
const { responses, components: responseComponents } = await createResponses(mergedResponse);
|
|
185
|
+
const operation = { responses };
|
|
186
|
+
const allComponents = [];
|
|
187
|
+
allComponents.push(...responseComponents);
|
|
188
|
+
allComponents.push(...parameterComponents);
|
|
189
|
+
for (const field of [
|
|
190
|
+
"summary",
|
|
191
|
+
"description",
|
|
192
|
+
"operationId"
|
|
193
|
+
]) if (route[field]) operation[field] = route[field];
|
|
194
|
+
if (route.tags && route.tags.length > 0) operation.tags = route.tags;
|
|
195
|
+
if (parameters.length > 0) operation.parameters = parameters;
|
|
196
|
+
const bodySchema = mergedRequest.body;
|
|
197
|
+
if (bodySchema) {
|
|
198
|
+
const { requestBody, components: bodyComponents } = await createRequestBody(bodySchema);
|
|
199
|
+
operation.requestBody = requestBody;
|
|
200
|
+
if (bodyComponents) allComponents.push(bodyComponents);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
operation,
|
|
204
|
+
components: allComponents
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const componentKeys = [
|
|
208
|
+
"schemas",
|
|
209
|
+
"responses",
|
|
210
|
+
"parameters",
|
|
211
|
+
"requestBodies"
|
|
212
|
+
];
|
|
213
|
+
const mergeComponents = (componentsArray) => {
|
|
214
|
+
const merged = {};
|
|
215
|
+
for (const components of componentsArray) {
|
|
216
|
+
if (!components) continue;
|
|
217
|
+
for (const key of componentKeys) if (components[key]) merged[key] = {
|
|
218
|
+
...merged[key],
|
|
219
|
+
...components[key]
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return merged;
|
|
223
|
+
};
|
|
224
|
+
const generateOpenApiSpec = async (options) => {
|
|
225
|
+
const spec = {
|
|
226
|
+
openapi: "3.1.0",
|
|
227
|
+
info: {
|
|
228
|
+
title: options.title,
|
|
229
|
+
description: options.description,
|
|
230
|
+
version: options.version
|
|
231
|
+
},
|
|
232
|
+
paths: {}
|
|
233
|
+
};
|
|
234
|
+
if (options.servers && options.servers.length > 0) spec.servers = options.servers;
|
|
235
|
+
if (options.securitySchemes) spec.components = { securitySchemes: options.securitySchemes };
|
|
236
|
+
const allRouteComponents = [];
|
|
237
|
+
for (const route of options.routes) {
|
|
238
|
+
const openApiPath = normalizePathForOpenAPI(options.prefix ? options.prefix + route.path : route.path);
|
|
239
|
+
const method = route.method.toLowerCase();
|
|
240
|
+
if (!spec.paths[openApiPath]) spec.paths[openApiPath] = {};
|
|
241
|
+
const { operation, components } = await createOperation(route, options.globalMiddlewares ?? [], options.prefix);
|
|
242
|
+
spec.paths[openApiPath][method] = operation;
|
|
243
|
+
allRouteComponents.push(...components);
|
|
244
|
+
}
|
|
245
|
+
const mergedComponents = mergeComponents(allRouteComponents);
|
|
246
|
+
if (!spec.components) spec.components = {};
|
|
247
|
+
if (options.securitySchemes) spec.components.securitySchemes = options.securitySchemes;
|
|
248
|
+
for (const key of componentKeys) {
|
|
249
|
+
const value = mergedComponents[key];
|
|
250
|
+
if (value && Object.keys(value).length > 0) spec.components[key] = value;
|
|
251
|
+
}
|
|
252
|
+
return spec;
|
|
253
|
+
};
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/lib/api/validation/index.ts
|
|
256
|
+
const validateSchema = async (schema, data) => {
|
|
257
|
+
const result = await schema["~standard"].validate(data);
|
|
258
|
+
if (!result.issues) return ok(result.value);
|
|
259
|
+
return err("ValidationError", result.issues.map((issue) => {
|
|
260
|
+
let path = "unknown";
|
|
261
|
+
if (Array.isArray(issue.path)) path = issue.path.map(String).join(".");
|
|
262
|
+
return `${path}: ${issue.message ?? "validation failed"}`;
|
|
263
|
+
}).join(", "));
|
|
264
|
+
};
|
|
265
|
+
const validateBody = async (req, bodySchema, bodyCache) => {
|
|
266
|
+
if (!bodySchema) return ok(true);
|
|
267
|
+
if (!(req.headers.get("content-type") ?? "").includes("application/json")) return ok(void 0);
|
|
268
|
+
if (bodyCache?.parsed) return validateSchema(bodySchema, bodyCache.value);
|
|
269
|
+
const [parseError, parsedBody] = await mightThrow(req.json());
|
|
270
|
+
if (parseError) return err("ParseError", "Invalid JSON body");
|
|
271
|
+
if (bodyCache) {
|
|
272
|
+
bodyCache.parsed = true;
|
|
273
|
+
bodyCache.value = parsedBody;
|
|
274
|
+
}
|
|
275
|
+
return validateSchema(bodySchema, parsedBody);
|
|
276
|
+
};
|
|
277
|
+
const validateQuery = async (req, querySchema) => {
|
|
278
|
+
if (!querySchema) return ok(true);
|
|
279
|
+
const qIndex = req.url.indexOf("?");
|
|
280
|
+
if (qIndex === -1) return validateSchema(querySchema, {});
|
|
281
|
+
const hashIndex = req.url.indexOf("#", qIndex + 1);
|
|
282
|
+
const queryString = hashIndex === -1 ? req.url.slice(qIndex + 1) : req.url.slice(qIndex + 1, hashIndex);
|
|
283
|
+
const searchParams = new URLSearchParams(queryString);
|
|
284
|
+
const queryParams = {};
|
|
285
|
+
for (const key of searchParams.keys()) {
|
|
286
|
+
const values = searchParams.getAll(key);
|
|
287
|
+
const [firstValue] = values;
|
|
288
|
+
if (values.length === 1) queryParams[key] = firstValue;
|
|
289
|
+
else queryParams[key] = values;
|
|
290
|
+
}
|
|
291
|
+
return validateSchema(querySchema, queryParams);
|
|
292
|
+
};
|
|
293
|
+
const validateHeaders = async (req, headersSchema) => {
|
|
294
|
+
if (!headersSchema) return ok(true);
|
|
295
|
+
const headers = {};
|
|
296
|
+
req.headers.forEach((value, key) => {
|
|
297
|
+
headers[key] = value;
|
|
298
|
+
});
|
|
299
|
+
return validateSchema(headersSchema, headers);
|
|
300
|
+
};
|
|
301
|
+
const validateCookies = async (req, cookiesSchema) => {
|
|
302
|
+
if (!cookiesSchema) return ok(true);
|
|
303
|
+
const cookieHeader = req.headers.get("cookie") ?? "";
|
|
304
|
+
const cookieMap = new Bun.CookieMap(cookieHeader);
|
|
305
|
+
return validateSchema(cookiesSchema, Object.fromEntries(cookieMap));
|
|
306
|
+
};
|
|
307
|
+
const validateParams = async (req, paramsSchema) => {
|
|
308
|
+
if (!paramsSchema) return ok(true);
|
|
309
|
+
return validateSchema(paramsSchema, req.params);
|
|
310
|
+
};
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/lib/api/core/index.ts
|
|
313
|
+
const defaultValidated = Object.freeze({
|
|
314
|
+
body: void 0,
|
|
315
|
+
query: void 0,
|
|
316
|
+
headers: void 0,
|
|
317
|
+
cookies: void 0,
|
|
318
|
+
params: void 0
|
|
319
|
+
});
|
|
320
|
+
const responseHelpers = {
|
|
321
|
+
json: (status, data) => Response.json(data, { status }),
|
|
322
|
+
text: (status, text) => new Response(text, { status }),
|
|
323
|
+
html: (status, html) => new Response(html, {
|
|
324
|
+
status,
|
|
325
|
+
headers: { "Content-Type": "text/html" }
|
|
326
|
+
}),
|
|
327
|
+
redirect: (status, url) => Response.redirect(url, status)
|
|
328
|
+
};
|
|
329
|
+
const noopGet = () => void 0;
|
|
330
|
+
const stripTrailingSlash = (path) => {
|
|
331
|
+
if (path !== "/" && path.endsWith("/")) return path.slice(0, -1);
|
|
332
|
+
return path;
|
|
333
|
+
};
|
|
334
|
+
const hasSchemas = (schema) => schema && (schema.body || schema.query || schema.headers || schema.cookies || schema.params);
|
|
335
|
+
const needsBodyCache = (schema) => schema?.body !== void 0;
|
|
336
|
+
const shouldCreateBodyCache = (hasMiddlewares, allMiddlewares, request) => {
|
|
337
|
+
if (needsBodyCache(request)) return true;
|
|
338
|
+
if (!hasMiddlewares) return false;
|
|
339
|
+
return allMiddlewares.some((mw) => needsBodyCache(mw.options.request));
|
|
340
|
+
};
|
|
341
|
+
const resolveValidation = (v) => {
|
|
342
|
+
if (v === void 0 || v === true) return {
|
|
343
|
+
input: true,
|
|
344
|
+
output: true
|
|
345
|
+
};
|
|
346
|
+
if (v === false) return {
|
|
347
|
+
input: false,
|
|
348
|
+
output: false
|
|
349
|
+
};
|
|
350
|
+
return {
|
|
351
|
+
input: v.input !== false,
|
|
352
|
+
output: v.output !== false
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
var Api = class {
|
|
356
|
+
options;
|
|
357
|
+
routes = [];
|
|
358
|
+
constructor(options = {}) {
|
|
359
|
+
this.options = options;
|
|
360
|
+
}
|
|
361
|
+
getFullPath(path) {
|
|
362
|
+
const normalizedPath = stripTrailingSlash(path) || "/";
|
|
363
|
+
if (!this.options.prefix) return normalizedPath;
|
|
364
|
+
const normalizedPrefix = stripTrailingSlash(this.options.prefix);
|
|
365
|
+
if (normalizedPrefix === "/") return normalizedPath;
|
|
366
|
+
if (normalizedPath === "/") return normalizedPrefix;
|
|
367
|
+
return normalizedPrefix + normalizedPath;
|
|
368
|
+
}
|
|
369
|
+
async validateRequestSchema(req, schema, bodyCache) {
|
|
370
|
+
if (!schema) return {
|
|
371
|
+
success: true,
|
|
372
|
+
data: {}
|
|
373
|
+
};
|
|
374
|
+
const v = {};
|
|
375
|
+
if (schema.body) {
|
|
376
|
+
const [err, val] = await validateBody(req, schema.body, bodyCache);
|
|
377
|
+
if (err) return {
|
|
378
|
+
success: false,
|
|
379
|
+
error: err
|
|
380
|
+
};
|
|
381
|
+
v.body = val;
|
|
382
|
+
}
|
|
383
|
+
if (schema.query) {
|
|
384
|
+
const [err, val] = await validateQuery(req, schema.query);
|
|
385
|
+
if (err) return {
|
|
386
|
+
success: false,
|
|
387
|
+
error: err
|
|
388
|
+
};
|
|
389
|
+
v.query = val;
|
|
390
|
+
}
|
|
391
|
+
if (schema.headers) {
|
|
392
|
+
const [err, val] = await validateHeaders(req, schema.headers);
|
|
393
|
+
if (err) return {
|
|
394
|
+
success: false,
|
|
395
|
+
error: err
|
|
396
|
+
};
|
|
397
|
+
v.headers = val;
|
|
398
|
+
}
|
|
399
|
+
if (schema.cookies) {
|
|
400
|
+
const [err, val] = await validateCookies(req, schema.cookies);
|
|
401
|
+
if (err) return {
|
|
402
|
+
success: false,
|
|
403
|
+
error: err
|
|
404
|
+
};
|
|
405
|
+
v.cookies = val;
|
|
406
|
+
}
|
|
407
|
+
if (schema.params) {
|
|
408
|
+
const [err, val] = await validateParams(req, schema.params);
|
|
409
|
+
if (err) return {
|
|
410
|
+
success: false,
|
|
411
|
+
error: err
|
|
412
|
+
};
|
|
413
|
+
v.params = val;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
success: true,
|
|
417
|
+
data: v
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
createContext(req, validated, extensions) {
|
|
421
|
+
return {
|
|
422
|
+
raw: req,
|
|
423
|
+
req: validated,
|
|
424
|
+
...responseHelpers,
|
|
425
|
+
get: (key) => extensions[key]
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
async validateResponseBody(response, schema) {
|
|
429
|
+
if (!schema) return response;
|
|
430
|
+
const statusSchema = schema[response.status];
|
|
431
|
+
if (!statusSchema) return response;
|
|
432
|
+
if (!(response.headers.get("content-type") ?? "").includes("application/json")) return response;
|
|
433
|
+
const [parseError, body] = await mightThrow(response.clone().json());
|
|
434
|
+
if (parseError) return responseHelpers.json(400, { message: "Invalid response body" });
|
|
435
|
+
const [validationError] = await validateSchema(statusSchema, body);
|
|
436
|
+
if (validationError) return responseHelpers.json(400, { message: validationError.message });
|
|
437
|
+
return response;
|
|
438
|
+
}
|
|
439
|
+
buildBunRoutes() {
|
|
440
|
+
const bunRoutes = {};
|
|
441
|
+
const validationConfig = resolveValidation(this.options.validation);
|
|
442
|
+
for (const route of this.routes) {
|
|
443
|
+
const { path, method, handler, request, response, middlewares } = route;
|
|
444
|
+
const fullPath = this.getFullPath(path);
|
|
445
|
+
if (!bunRoutes[fullPath]) bunRoutes[fullPath] = {};
|
|
446
|
+
const allMiddlewares = [...this.options.middlewares ?? [], ...middlewares ?? []];
|
|
447
|
+
const hasMiddlewares = allMiddlewares.length > 0;
|
|
448
|
+
const hasRouteSchemas = hasSchemas(request);
|
|
449
|
+
const effectiveOutputValidation = validationConfig.output && !!response;
|
|
450
|
+
if (!hasMiddlewares && !(validationConfig.input && hasRouteSchemas) && !effectiveOutputValidation) bunRoutes[fullPath][method] = (req) => {
|
|
451
|
+
const context = Object.create(responseHelpers);
|
|
452
|
+
context.raw = req;
|
|
453
|
+
context.req = defaultValidated;
|
|
454
|
+
context.get = noopGet;
|
|
455
|
+
return handler(context);
|
|
456
|
+
};
|
|
457
|
+
else bunRoutes[fullPath][method] = async (req) => {
|
|
458
|
+
const extensions = {};
|
|
459
|
+
const bodyCache = validationConfig.input && shouldCreateBodyCache(hasMiddlewares, allMiddlewares, request) ? {
|
|
460
|
+
parsed: false,
|
|
461
|
+
value: void 0
|
|
462
|
+
} : void 0;
|
|
463
|
+
for (const mw of allMiddlewares) {
|
|
464
|
+
const { request: reqSchema, handler: mwHandler } = mw.options;
|
|
465
|
+
let validated = defaultValidated;
|
|
466
|
+
if (validationConfig.input && hasSchemas(reqSchema)) {
|
|
467
|
+
const result = await this.validateRequestSchema(req, reqSchema, bodyCache);
|
|
468
|
+
if (!result.success) return responseHelpers.json(400, { message: result.error?.message });
|
|
469
|
+
validated = result.data;
|
|
470
|
+
}
|
|
471
|
+
const mwResult = await mwHandler(this.createContext(req, validated, extensions));
|
|
472
|
+
if (mwResult instanceof Response) return mwResult;
|
|
473
|
+
if (mwResult) Object.assign(extensions, mwResult);
|
|
474
|
+
}
|
|
475
|
+
let routeValidated = defaultValidated;
|
|
476
|
+
if (validationConfig.input && hasRouteSchemas) {
|
|
477
|
+
const result = await this.validateRequestSchema(req, request, bodyCache);
|
|
478
|
+
if (!result.success) return responseHelpers.json(400, { message: result.error?.message });
|
|
479
|
+
routeValidated = result.data;
|
|
480
|
+
}
|
|
481
|
+
const handlerResponse = await handler(this.createContext(req, routeValidated, extensions));
|
|
482
|
+
if (effectiveOutputValidation) return this.validateResponseBody(handlerResponse, response);
|
|
483
|
+
return handlerResponse;
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
return bunRoutes;
|
|
487
|
+
}
|
|
488
|
+
defineRoute(config) {
|
|
489
|
+
this.routes.push(config);
|
|
490
|
+
}
|
|
491
|
+
getOpenApiSpec() {
|
|
492
|
+
return generateOpenApiSpec({
|
|
493
|
+
title: this.options.openapi?.title ?? "API",
|
|
494
|
+
description: this.options.openapi?.description,
|
|
495
|
+
version: this.options.openapi?.version ?? "1.0.0",
|
|
496
|
+
prefix: this.options.prefix,
|
|
497
|
+
servers: this.options.openapi?.servers,
|
|
498
|
+
securitySchemes: this.options.openapi?.securitySchemes,
|
|
499
|
+
routes: this.routes,
|
|
500
|
+
globalMiddlewares: this.options.middlewares
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
serve(port, callback) {
|
|
504
|
+
const bunRoutes = this.buildBunRoutes();
|
|
505
|
+
const server = Bun.serve({
|
|
506
|
+
port,
|
|
507
|
+
routes: bunRoutes,
|
|
508
|
+
fetch: () => new Response("Not found", { status: 404 })
|
|
509
|
+
});
|
|
510
|
+
if (callback) callback(server);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/lib/api/middleware/index.ts
|
|
515
|
+
var Middleware = class {
|
|
516
|
+
constructor(options) {
|
|
517
|
+
this.options = options;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
//#endregion
|
|
3
521
|
export { Api, Middleware };
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/lib/cache/types.d.ts
|
|
2
|
+
type CacheError = "CacheError" | "InvalidTTLError" | "NotFoundError";
|
|
3
|
+
type CacheOptions<T> = {
|
|
4
|
+
redis: Bun.RedisClient;
|
|
5
|
+
ttl?: number | ((key: string, value: T) => number);
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
serializer?: (value: T) => string;
|
|
9
|
+
deserializer?: (raw: string) => T;
|
|
10
|
+
onError?: (error: {
|
|
11
|
+
type: CacheError;
|
|
12
|
+
message: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
3
16
|
//#region src/lib/cache/index.d.ts
|
|
4
17
|
declare class Cache<T> {
|
|
5
18
|
private options;
|
|
@@ -32,5 +45,4 @@ declare class Cache<T> {
|
|
|
32
45
|
private isTTLValid;
|
|
33
46
|
}
|
|
34
47
|
//#endregion
|
|
35
|
-
export { Cache };
|
|
36
|
-
//# sourceMappingURL=index.d.cts.map
|
|
48
|
+
export { Cache };
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/lib/cache/types.d.ts
|
|
2
|
+
type CacheError = "CacheError" | "InvalidTTLError" | "NotFoundError";
|
|
3
|
+
type CacheOptions<T> = {
|
|
4
|
+
redis: Bun.RedisClient;
|
|
5
|
+
ttl?: number | ((key: string, value: T) => number);
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
serializer?: (value: T) => string;
|
|
9
|
+
deserializer?: (raw: string) => T;
|
|
10
|
+
onError?: (error: {
|
|
11
|
+
type: CacheError;
|
|
12
|
+
message: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
3
16
|
//#region src/lib/cache/index.d.ts
|
|
4
17
|
declare class Cache<T> {
|
|
5
18
|
private options;
|
|
@@ -32,5 +45,4 @@ declare class Cache<T> {
|
|
|
32
45
|
private isTTLValid;
|
|
33
46
|
}
|
|
34
47
|
//#endregion
|
|
35
|
-
export { Cache };
|
|
36
|
-
//# sourceMappingURL=index.d.mts.map
|
|
48
|
+
export { Cache };
|