hono-crud 0.10.0 → 0.11.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/CHANGELOG.md +2 -0
- package/dist/adapters/drizzle/index.d.ts +4 -4
- package/dist/adapters/memory/index.d.ts +4 -4
- package/dist/adapters/prisma/index.d.ts +4 -4
- package/dist/audit/index.d.ts +1 -1
- package/dist/auth/index.d.ts +3 -3
- package/dist/{bulk-patch-qEj-oZiL.d.ts → bulk-patch-DX-qtuN4.d.ts} +2 -2
- package/dist/cache/index.d.ts +2 -2
- package/dist/{import-DzAuLZQf.d.ts → import-BowFqS6q.d.ts} +113 -113
- package/dist/{index-BOWqsE16.d.ts → index-C7qXEfCh.d.ts} +3 -3
- package/dist/index.d.ts +83 -9
- package/dist/index.js +2 -2
- package/dist/{route-zMPr_8wn.d.ts → route-CTec4QxL.d.ts} +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/{types-CJ0rN_9M.d.ts → types-QHT43lek.d.ts} +17 -0
- package/dist/versioning/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
%b
|
|
8
9
|
%b
|
|
9
10
|
%b
|
|
10
11
|
## [0.8.0] — 2026-05-03
|
|
@@ -79,3 +80,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
79
80
|
[0.8.0]: https://github.com/kshdotdev/hono-crud/compare/v0.7.0...v0.8.0
|
|
80
81
|
[0.9.0]: https://github.com/kshdotdev/hono-crud/compare/v0.7.0...v0.9.0
|
|
81
82
|
[0.10.0]: https://github.com/kshdotdev/hono-crud/compare/v0.9.0...v0.10.0
|
|
83
|
+
[0.11.0]: https://github.com/kshdotdev/hono-crud/compare/v0.10.0...v0.11.0
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Table, SQL, Column } from 'drizzle-orm';
|
|
2
|
-
import { M as MetaInput, I as IncludeOptions, n as FilterCondition, h as RelationConfig, N as NestedUpdateInput, i as NestedWriteResult, L as ListFilters, P as PaginatedResult, j as AggregateOptions, k as AggregateResult, S as SearchOptions, l as SearchResult } from '../../types-
|
|
2
|
+
import { M as MetaInput, I as IncludeOptions, n as FilterCondition, h as RelationConfig, N as NestedUpdateInput, i as NestedWriteResult, L as ListFilters, P as PaginatedResult, j as AggregateOptions, k as AggregateResult, S as SearchOptions, l as SearchResult } from '../../types-QHT43lek.js';
|
|
3
3
|
import { Env } from 'hono';
|
|
4
|
-
import { a as CreateEndpoint, M as ModelObject, R as ReadEndpoint, U as UpdateEndpoint, D as DeleteEndpoint, L as ListEndpoint, b as RestoreEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, d as BatchRestoreEndpoint, e as BatchUpdateEndpoint, f as BatchUpdateItem, A as AggregateEndpoint, g as BatchUpsertEndpoint, h as CloneEndpoint, i as UpsertEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint } from '../../import-
|
|
4
|
+
import { a as CreateEndpoint, M as ModelObject, R as ReadEndpoint, U as UpdateEndpoint, D as DeleteEndpoint, L as ListEndpoint, b as RestoreEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, d as BatchRestoreEndpoint, e as BatchUpdateEndpoint, f as BatchUpdateItem, A as AggregateEndpoint, g as BatchUpsertEndpoint, h as CloneEndpoint, i as UpsertEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint } from '../../import-BowFqS6q.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { A as AdapterBundle } from '../../index-
|
|
6
|
+
import { A as AdapterBundle } from '../../index-C7qXEfCh.js';
|
|
7
7
|
import '../../types-B5wq2iKZ.js';
|
|
8
8
|
import '../../types-BAcN7U0B.js';
|
|
9
9
|
import '@hono/zod-openapi';
|
|
10
|
-
import '../../route-
|
|
10
|
+
import '../../route-CTec4QxL.js';
|
|
11
11
|
import 'hono/utils/http-status';
|
|
12
12
|
import '../../audit/index.js';
|
|
13
13
|
import '../../registry-PNJjvSvm.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Env } from 'hono';
|
|
2
|
-
import { a as CreateEndpoint, M as ModelObject, D as DeleteEndpoint, L as ListEndpoint, R as ReadEndpoint, b as RestoreEndpoint, U as UpdateEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, d as BatchRestoreEndpoint, e as BatchUpdateEndpoint, f as BatchUpdateItem, g as BatchUpsertEndpoint, A as AggregateEndpoint, h as CloneEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, i as UpsertEndpoint, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint } from '../../import-
|
|
3
|
-
import { M as MetaInput, h as RelationConfig, L as ListFilters, P as PaginatedResult, I as IncludeOptions, N as NestedUpdateInput, i as NestedWriteResult, j as AggregateOptions, k as AggregateResult, S as SearchOptions, l as SearchResult } from '../../types-
|
|
4
|
-
import { B as BulkPatchEndpoint } from '../../bulk-patch-
|
|
2
|
+
import { a as CreateEndpoint, M as ModelObject, D as DeleteEndpoint, L as ListEndpoint, R as ReadEndpoint, b as RestoreEndpoint, U as UpdateEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, d as BatchRestoreEndpoint, e as BatchUpdateEndpoint, f as BatchUpdateItem, g as BatchUpsertEndpoint, A as AggregateEndpoint, h as CloneEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, i as UpsertEndpoint, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint } from '../../import-BowFqS6q.js';
|
|
3
|
+
import { M as MetaInput, h as RelationConfig, L as ListFilters, P as PaginatedResult, I as IncludeOptions, N as NestedUpdateInput, i as NestedWriteResult, j as AggregateOptions, k as AggregateResult, S as SearchOptions, l as SearchResult } from '../../types-QHT43lek.js';
|
|
4
|
+
import { B as BulkPatchEndpoint } from '../../bulk-patch-DX-qtuN4.js';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../../route-
|
|
6
|
+
import '../../route-CTec4QxL.js';
|
|
7
7
|
import 'hono/utils/http-status';
|
|
8
8
|
import '../../audit/index.js';
|
|
9
9
|
import '../../registry-PNJjvSvm.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Env } from 'hono';
|
|
2
|
-
import { a as CreateEndpoint, M as ModelObject, D as DeleteEndpoint, L as ListEndpoint, R as ReadEndpoint, U as UpdateEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, d as BatchRestoreEndpoint, e as BatchUpdateEndpoint, f as BatchUpdateItem, g as BatchUpsertEndpoint, b as RestoreEndpoint, A as AggregateEndpoint, h as CloneEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, i as UpsertEndpoint, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint } from '../../import-
|
|
3
|
-
import { M as MetaInput, L as ListFilters, P as PaginatedResult, I as IncludeOptions, j as AggregateOptions, k as AggregateResult, m as AggregateField, S as SearchOptions, l as SearchResult } from '../../types-
|
|
4
|
-
import { A as AdapterBundle } from '../../index-
|
|
2
|
+
import { a as CreateEndpoint, M as ModelObject, D as DeleteEndpoint, L as ListEndpoint, R as ReadEndpoint, U as UpdateEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, d as BatchRestoreEndpoint, e as BatchUpdateEndpoint, f as BatchUpdateItem, g as BatchUpsertEndpoint, b as RestoreEndpoint, A as AggregateEndpoint, h as CloneEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, i as UpsertEndpoint, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint } from '../../import-BowFqS6q.js';
|
|
3
|
+
import { M as MetaInput, L as ListFilters, P as PaginatedResult, I as IncludeOptions, j as AggregateOptions, k as AggregateResult, m as AggregateField, S as SearchOptions, l as SearchResult } from '../../types-QHT43lek.js';
|
|
4
|
+
import { A as AdapterBundle } from '../../index-C7qXEfCh.js';
|
|
5
5
|
import 'zod';
|
|
6
|
-
import '../../route-
|
|
6
|
+
import '../../route-CTec4QxL.js';
|
|
7
7
|
import 'hono/utils/http-status';
|
|
8
8
|
import '../../audit/index.js';
|
|
9
9
|
import '../../registry-PNJjvSvm.js';
|
package/dist/audit/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Env } from 'hono';
|
|
2
|
-
import { A as AuditConfig, c as AuditLogEntry, d as AuditAction } from '../types-
|
|
2
|
+
import { A as AuditConfig, c as AuditLogEntry, d as AuditAction } from '../types-QHT43lek.js';
|
|
3
3
|
import { S as StorageRegistry } from '../registry-PNJjvSvm.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../types-B5wq2iKZ.js';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as AuthEnv, a9 as JWTConfig, a7 as JWTClaims, s as APIKeyConfig, t as APIKeyEntry, D as AuthConfig, _ as Guard, B as ApprovalConfig, J as AuthorizationCheck, an as OwnershipExtractor, ac as ModelPolicies, C as ApprovalStorage, aq as PendingAction, G as AuthUser, M as MetaInput, O as OpenAPIRouteSchema, aX as Constructor, X as EndpointAuthConfig, aY as APIKeyStorage, u as APIKeyLookupResult } from '../types-
|
|
2
|
-
export { v as ActionSource, E as AuthType, a6 as JWTAlgorithm, a8 as JWTClaimsSchema, ap as PathPattern, ar as PendingActionStatus, aD as ValidatedJWTClaims, aU as parseJWTClaims, aW as safeParseJWTClaims } from '../types-
|
|
1
|
+
import { r as AuthEnv, a9 as JWTConfig, a7 as JWTClaims, s as APIKeyConfig, t as APIKeyEntry, D as AuthConfig, _ as Guard, B as ApprovalConfig, J as AuthorizationCheck, an as OwnershipExtractor, ac as ModelPolicies, C as ApprovalStorage, aq as PendingAction, G as AuthUser, M as MetaInput, O as OpenAPIRouteSchema, aX as Constructor, X as EndpointAuthConfig, aY as APIKeyStorage, u as APIKeyLookupResult } from '../types-QHT43lek.js';
|
|
2
|
+
export { v as ActionSource, E as AuthType, a6 as JWTAlgorithm, a8 as JWTClaimsSchema, ap as PathPattern, ar as PendingActionStatus, aD as ValidatedJWTClaims, aU as parseJWTClaims, aW as safeParseJWTClaims } from '../types-QHT43lek.js';
|
|
3
3
|
import { MiddlewareHandler, Context } from 'hono';
|
|
4
|
-
import { O as OpenAPIRoute } from '../route-
|
|
4
|
+
import { O as OpenAPIRoute } from '../route-CTec4QxL.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '../types-B5wq2iKZ.js';
|
|
7
7
|
import '../types-BAcN7U0B.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
2
2
|
import { Env } from 'hono';
|
|
3
|
-
import { C as CrudEndpoint, M as ModelObject } from './import-
|
|
4
|
-
import { M as MetaInput, H as HookMode, L as ListFilters, O as OpenAPIRouteSchema } from './types-
|
|
3
|
+
import { C as CrudEndpoint, M as ModelObject } from './import-BowFqS6q.js';
|
|
4
|
+
import { M as MetaInput, H as HookMode, L as ListFilters, O as OpenAPIRouteSchema } from './types-QHT43lek.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Result of a bulk patch operation.
|
package/dist/cache/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { I as InvalidationPatternOptions, d as CacheKeyOptions, C as CacheStorage, b as CacheEntry, e as CacheSetOptions, f as CacheStats, a as CacheConfig, c as CacheInvalidationConfig } from '../types-BdRvpp1z.js';
|
|
2
2
|
export { g as InvalidationStrategy } from '../types-BdRvpp1z.js';
|
|
3
3
|
import { K as KVNamespace } from '../cloudflare-kv-types-ByUEHhBc.js';
|
|
4
|
-
import { aX as Constructor } from '../types-
|
|
5
|
-
import { O as OpenAPIRoute } from '../route-
|
|
4
|
+
import { aX as Constructor } from '../types-QHT43lek.js';
|
|
5
|
+
import { O as OpenAPIRoute } from '../route-CTec4QxL.js';
|
|
6
6
|
import 'hono';
|
|
7
7
|
import 'zod';
|
|
8
8
|
import '../types-B5wq2iKZ.js';
|
|
@@ -1,11 +1,122 @@
|
|
|
1
1
|
import { z, ZodObject, ZodRawShape } from 'zod';
|
|
2
2
|
import { Env } from 'hono';
|
|
3
|
-
import { M as MetaInput, aj as NormalizedAuditConfig, am as NormalizedVersioningConfig, al as NormalizedSoftDeleteConfig, ak as NormalizedMultiTenantConfig, ac as ModelPolicies, as as PolicyContext, n as FilterCondition, a1 as HookContext, V as ValidatedData,
|
|
4
|
-
import { O as OpenAPIRoute } from './route-
|
|
3
|
+
import { ab as Model, F as FilterConfig, Z as FilterOperator, L as ListFilters, M as MetaInput, aj as NormalizedAuditConfig, am as NormalizedVersioningConfig, al as NormalizedSoftDeleteConfig, ak as NormalizedMultiTenantConfig, ac as ModelPolicies, as as PolicyContext, n as FilterCondition, a1 as HookContext, V as ValidatedData, H as HookMode, O as OpenAPIRouteSchema, h as RelationConfig, I as IncludeOptions, N as NestedUpdateInput, i as NestedWriteResult, K as CascadeAction, P as PaginatedResult, y as AggregateConfig, j as AggregateOptions, m as AggregateField, k as AggregateResult, p as SearchFieldConfig, q as SearchMode, S as SearchOptions, az as SearchResultItem, l as SearchResult } from './types-QHT43lek.js';
|
|
4
|
+
import { O as OpenAPIRoute } from './route-CTec4QxL.js';
|
|
5
5
|
import { AuditLogger } from './audit/index.js';
|
|
6
6
|
import { VersionManager } from './versioning/index.js';
|
|
7
7
|
import { C as CrudEventType } from './types-rJSyOxkJ.js';
|
|
8
8
|
|
|
9
|
+
interface ListEndpointConfig {
|
|
10
|
+
filterFields?: string[];
|
|
11
|
+
filterConfig?: FilterConfig;
|
|
12
|
+
searchFields?: string[];
|
|
13
|
+
searchFieldName?: string;
|
|
14
|
+
sortFields?: string[];
|
|
15
|
+
defaultSort?: {
|
|
16
|
+
field: string;
|
|
17
|
+
order: 'asc' | 'desc';
|
|
18
|
+
};
|
|
19
|
+
defaultPerPage?: number;
|
|
20
|
+
maxPerPage?: number;
|
|
21
|
+
cursorPaginationEnabled?: boolean;
|
|
22
|
+
cursorField?: string;
|
|
23
|
+
softDeleteQueryParam?: string;
|
|
24
|
+
allowedIncludes?: string[];
|
|
25
|
+
fieldSelectionEnabled?: boolean;
|
|
26
|
+
allowedSelectFields?: string[];
|
|
27
|
+
blockedSelectFields?: string[];
|
|
28
|
+
alwaysIncludeFields?: string[];
|
|
29
|
+
defaultSelectFields?: string[];
|
|
30
|
+
}
|
|
31
|
+
interface SingleEndpointConfig {
|
|
32
|
+
lookupField?: string;
|
|
33
|
+
lookupFields?: string[];
|
|
34
|
+
additionalFilters?: string[];
|
|
35
|
+
}
|
|
36
|
+
interface UpdateEndpointConfig extends SingleEndpointConfig {
|
|
37
|
+
allowedUpdateFields?: string[];
|
|
38
|
+
blockedUpdateFields?: string[];
|
|
39
|
+
}
|
|
40
|
+
declare function parseFilterValue(value: string): {
|
|
41
|
+
operator: FilterOperator;
|
|
42
|
+
value: unknown;
|
|
43
|
+
};
|
|
44
|
+
declare function parseListFilters(query: Record<string, unknown>, config: ListEndpointConfig): ListFilters;
|
|
45
|
+
declare function getSchemaFields<T extends ZodObject<ZodRawShape>>(schema: T, exclude?: string[]): ZodObject<ZodRawShape>;
|
|
46
|
+
type ModelObject<M extends Model> = z.infer<M['schema']>;
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for field selection on endpoints.
|
|
49
|
+
*/
|
|
50
|
+
interface FieldSelectionConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Fields that are allowed to be selected.
|
|
53
|
+
* If empty, all schema fields are allowed.
|
|
54
|
+
*/
|
|
55
|
+
allowedFields?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* Fields that are never returned, even if requested.
|
|
58
|
+
* Useful for sensitive fields like passwords.
|
|
59
|
+
*/
|
|
60
|
+
blockedFields?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Fields that are always included in the response,
|
|
63
|
+
* regardless of what the client requests.
|
|
64
|
+
* Typically includes primary keys.
|
|
65
|
+
*/
|
|
66
|
+
alwaysIncludeFields?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Default fields to return when no fields parameter is provided.
|
|
69
|
+
* If empty, returns all allowed fields.
|
|
70
|
+
*/
|
|
71
|
+
defaultFields?: string[];
|
|
72
|
+
/**
|
|
73
|
+
* Whether to allow selecting computed fields.
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
allowComputedFields?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether to allow selecting relation fields.
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
allowRelationFields?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parsed field selection from query parameters.
|
|
85
|
+
*/
|
|
86
|
+
interface FieldSelection {
|
|
87
|
+
/** The fields to include in the response */
|
|
88
|
+
fields: string[];
|
|
89
|
+
/** Whether field selection is active (fields param was provided) */
|
|
90
|
+
isActive: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parse the fields query parameter.
|
|
94
|
+
*
|
|
95
|
+
* @param fieldsParam - The raw fields parameter value (comma-separated string)
|
|
96
|
+
* @param config - Field selection configuration
|
|
97
|
+
* @param schemaFields - Available fields from the schema
|
|
98
|
+
* @param computedFields - Available computed field names
|
|
99
|
+
* @param relationFields - Available relation field names
|
|
100
|
+
* @returns Parsed field selection
|
|
101
|
+
*/
|
|
102
|
+
declare function parseFieldSelection(fieldsParam: string | undefined | null, config?: FieldSelectionConfig, schemaFields?: string[], computedFields?: string[], relationFields?: string[]): FieldSelection;
|
|
103
|
+
/**
|
|
104
|
+
* Apply field selection to a single record.
|
|
105
|
+
*
|
|
106
|
+
* @param record - The record to filter
|
|
107
|
+
* @param selection - The field selection
|
|
108
|
+
* @returns The record with only selected fields
|
|
109
|
+
*/
|
|
110
|
+
declare function applyFieldSelection<T extends Record<string, unknown>>(record: T, selection: FieldSelection): Record<string, unknown>;
|
|
111
|
+
/**
|
|
112
|
+
* Apply field selection to an array of records.
|
|
113
|
+
*
|
|
114
|
+
* @param records - The records to filter
|
|
115
|
+
* @param selection - The field selection
|
|
116
|
+
* @returns The records with only selected fields
|
|
117
|
+
*/
|
|
118
|
+
declare function applyFieldSelectionToArray<T extends Record<string, unknown>>(records: T[], selection: FieldSelection): Array<Record<string, unknown>>;
|
|
119
|
+
|
|
9
120
|
/**
|
|
10
121
|
* Shared base class for every CRUD endpoint.
|
|
11
122
|
*
|
|
@@ -196,117 +307,6 @@ declare abstract class CrudEndpoint<E extends Env = Env, M extends MetaInput = M
|
|
|
196
307
|
getValidatedData<T = unknown>(): Promise<ValidatedData<T>>;
|
|
197
308
|
}
|
|
198
309
|
|
|
199
|
-
interface ListEndpointConfig {
|
|
200
|
-
filterFields?: string[];
|
|
201
|
-
filterConfig?: FilterConfig;
|
|
202
|
-
searchFields?: string[];
|
|
203
|
-
searchFieldName?: string;
|
|
204
|
-
sortFields?: string[];
|
|
205
|
-
defaultSort?: {
|
|
206
|
-
field: string;
|
|
207
|
-
order: 'asc' | 'desc';
|
|
208
|
-
};
|
|
209
|
-
defaultPerPage?: number;
|
|
210
|
-
maxPerPage?: number;
|
|
211
|
-
cursorPaginationEnabled?: boolean;
|
|
212
|
-
cursorField?: string;
|
|
213
|
-
softDeleteQueryParam?: string;
|
|
214
|
-
allowedIncludes?: string[];
|
|
215
|
-
fieldSelectionEnabled?: boolean;
|
|
216
|
-
allowedSelectFields?: string[];
|
|
217
|
-
blockedSelectFields?: string[];
|
|
218
|
-
alwaysIncludeFields?: string[];
|
|
219
|
-
defaultSelectFields?: string[];
|
|
220
|
-
}
|
|
221
|
-
interface SingleEndpointConfig {
|
|
222
|
-
lookupField?: string;
|
|
223
|
-
lookupFields?: string[];
|
|
224
|
-
additionalFilters?: string[];
|
|
225
|
-
}
|
|
226
|
-
interface UpdateEndpointConfig extends SingleEndpointConfig {
|
|
227
|
-
allowedUpdateFields?: string[];
|
|
228
|
-
blockedUpdateFields?: string[];
|
|
229
|
-
}
|
|
230
|
-
declare function parseFilterValue(value: string): {
|
|
231
|
-
operator: FilterOperator;
|
|
232
|
-
value: unknown;
|
|
233
|
-
};
|
|
234
|
-
declare function parseListFilters(query: Record<string, unknown>, config: ListEndpointConfig): ListFilters;
|
|
235
|
-
declare function getSchemaFields<T extends ZodObject<ZodRawShape>>(schema: T, exclude?: string[]): ZodObject<ZodRawShape>;
|
|
236
|
-
type ModelObject<M extends Model> = z.infer<M['schema']>;
|
|
237
|
-
/**
|
|
238
|
-
* Configuration for field selection on endpoints.
|
|
239
|
-
*/
|
|
240
|
-
interface FieldSelectionConfig {
|
|
241
|
-
/**
|
|
242
|
-
* Fields that are allowed to be selected.
|
|
243
|
-
* If empty, all schema fields are allowed.
|
|
244
|
-
*/
|
|
245
|
-
allowedFields?: string[];
|
|
246
|
-
/**
|
|
247
|
-
* Fields that are never returned, even if requested.
|
|
248
|
-
* Useful for sensitive fields like passwords.
|
|
249
|
-
*/
|
|
250
|
-
blockedFields?: string[];
|
|
251
|
-
/**
|
|
252
|
-
* Fields that are always included in the response,
|
|
253
|
-
* regardless of what the client requests.
|
|
254
|
-
* Typically includes primary keys.
|
|
255
|
-
*/
|
|
256
|
-
alwaysIncludeFields?: string[];
|
|
257
|
-
/**
|
|
258
|
-
* Default fields to return when no fields parameter is provided.
|
|
259
|
-
* If empty, returns all allowed fields.
|
|
260
|
-
*/
|
|
261
|
-
defaultFields?: string[];
|
|
262
|
-
/**
|
|
263
|
-
* Whether to allow selecting computed fields.
|
|
264
|
-
* @default true
|
|
265
|
-
*/
|
|
266
|
-
allowComputedFields?: boolean;
|
|
267
|
-
/**
|
|
268
|
-
* Whether to allow selecting relation fields.
|
|
269
|
-
* @default true
|
|
270
|
-
*/
|
|
271
|
-
allowRelationFields?: boolean;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Parsed field selection from query parameters.
|
|
275
|
-
*/
|
|
276
|
-
interface FieldSelection {
|
|
277
|
-
/** The fields to include in the response */
|
|
278
|
-
fields: string[];
|
|
279
|
-
/** Whether field selection is active (fields param was provided) */
|
|
280
|
-
isActive: boolean;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Parse the fields query parameter.
|
|
284
|
-
*
|
|
285
|
-
* @param fieldsParam - The raw fields parameter value (comma-separated string)
|
|
286
|
-
* @param config - Field selection configuration
|
|
287
|
-
* @param schemaFields - Available fields from the schema
|
|
288
|
-
* @param computedFields - Available computed field names
|
|
289
|
-
* @param relationFields - Available relation field names
|
|
290
|
-
* @returns Parsed field selection
|
|
291
|
-
*/
|
|
292
|
-
declare function parseFieldSelection(fieldsParam: string | undefined | null, config?: FieldSelectionConfig, schemaFields?: string[], computedFields?: string[], relationFields?: string[]): FieldSelection;
|
|
293
|
-
/**
|
|
294
|
-
* Apply field selection to a single record.
|
|
295
|
-
*
|
|
296
|
-
* @param record - The record to filter
|
|
297
|
-
* @param selection - The field selection
|
|
298
|
-
* @returns The record with only selected fields
|
|
299
|
-
*/
|
|
300
|
-
declare function applyFieldSelection<T extends Record<string, unknown>>(record: T, selection: FieldSelection): Record<string, unknown>;
|
|
301
|
-
/**
|
|
302
|
-
* Apply field selection to an array of records.
|
|
303
|
-
*
|
|
304
|
-
* @param records - The records to filter
|
|
305
|
-
* @param selection - The field selection
|
|
306
|
-
* @returns The records with only selected fields
|
|
307
|
-
*/
|
|
308
|
-
declare function applyFieldSelectionToArray<T extends Record<string, unknown>>(records: T[], selection: FieldSelection): Array<Record<string, unknown>>;
|
|
309
|
-
|
|
310
310
|
/**
|
|
311
311
|
* Base endpoint for creating resources.
|
|
312
312
|
* Extend this class and implement the `create` method for your ORM.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Env, MiddlewareHandler } from 'hono';
|
|
2
2
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
3
|
-
import { a as ResponseEnvelope, M as MetaInput, H as HookMode, F as FilterConfig } from './types-
|
|
4
|
-
import { O as OpenAPIRoute } from './route-
|
|
3
|
+
import { a as ResponseEnvelope, M as MetaInput, H as HookMode, F as FilterConfig } from './types-QHT43lek.js';
|
|
4
|
+
import { O as OpenAPIRoute } from './route-CTec4QxL.js';
|
|
5
5
|
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
6
|
-
import { M as ModelObject } from './import-
|
|
6
|
+
import { M as ModelObject } from './import-BowFqS6q.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Type for an OpenAPIRoute class constructor.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { O as OpenAPIRouteSchema, o as SchemaResolveContext, a as ResponseEnvelope, p as SearchFieldConfig, q as SearchMode, M as MetaInput, H as HookMode, F as FilterConfig, r as AuthEnv } from './types-
|
|
2
|
-
export { s as APIKeyConfig, t as APIKeyEntry, u as APIKeyLookupResult, v as ActionSource, w as AfterDeleteHook, x as AfterUpdateHook, y as AggregateConfig, m as AggregateField, z as AggregateOperation, j as AggregateOptions, k as AggregateResult, B as ApprovalConfig, C as ApprovalStorage, d as AuditAction, A as AuditConfig, g as AuditFieldChange, c as AuditLogEntry, D as AuthConfig, E as AuthType, G as AuthUser, J as AuthorizationCheck, K as CascadeAction, Q as CascadeConfig, T as ComputedFieldConfig, U as ComputedFieldFn, W as ComputedFieldsConfig, X as EndpointAuthConfig, Y as ErrorResponse, n as FilterCondition, Z as FilterOperator, _ as Guard, $ as HandleArgs, a0 as HookConfig, a1 as HookContext, a2 as HookFn, I as IncludeOptions, a3 as InferMeta, a4 as InferModel, a5 as InferSchema, a6 as JWTAlgorithm, a7 as JWTClaims, a8 as JWTClaimsSchema, a9 as JWTConfig, L as ListFilters, aa as ListOptions, ab as Model, ac as ModelPolicies, ad as ModelTable, ae as MultiTenantConfig, af as NestedCreateManyInput, ag as NestedCreateOneInput, N as NestedUpdateInput, ah as NestedWriteConfig, i as NestedWriteResult, ai as NestedWritesConfig, aj as NormalizedAuditConfig, ak as NormalizedMultiTenantConfig, al as NormalizedSoftDeleteConfig, am as NormalizedVersioningConfig, an as OwnershipExtractor, P as PaginatedResult, ao as PartialBy, ap as PathPattern, aq as PendingAction, ar as PendingActionStatus, as as PolicyContext, at as RESPONSE_ENVELOPE_CONTEXT_KEY, h as RelationConfig, au as RelationType, av as RelationsConfig, aw as RequiredBy, b as ResponseEnvelopeInfo, R as RouteOptions, ax as SchemaKeys, ay as SearchConfig, S as SearchOptions, l as SearchResult, az as SearchResultItem, aA as SoftDeleteConfig, aB as StructuredError, aC as SuccessResponse, V as ValidatedData, aD as ValidatedJWTClaims, f as VersionHistoryEntry, e as VersioningConfig, aE as applyComputedFields, aF as applyComputedFieldsToArray, aG as calculateChanges, aH as decodeCursor, aI as defineMeta, aJ as defineModel, aK as encodeCursor, aL as extractNestedData, aM as extractTenantId, aN as getAuditConfig, aO as getMultiTenantConfig, aP as getSoftDeleteConfig, aQ as getVersioningConfig, aR as isDirectNestedData, aS as parseAggregateField, aT as parseAggregateQuery, aU as parseJWTClaims, aV as parseSearchMode, aW as safeParseJWTClaims } from './types-
|
|
1
|
+
import { O as OpenAPIRouteSchema, o as SchemaResolveContext, a as ResponseEnvelope, p as SearchFieldConfig, q as SearchMode, M as MetaInput, H as HookMode, F as FilterConfig, r as AuthEnv } from './types-QHT43lek.js';
|
|
2
|
+
export { s as APIKeyConfig, t as APIKeyEntry, u as APIKeyLookupResult, v as ActionSource, w as AfterDeleteHook, x as AfterUpdateHook, y as AggregateConfig, m as AggregateField, z as AggregateOperation, j as AggregateOptions, k as AggregateResult, B as ApprovalConfig, C as ApprovalStorage, d as AuditAction, A as AuditConfig, g as AuditFieldChange, c as AuditLogEntry, D as AuthConfig, E as AuthType, G as AuthUser, J as AuthorizationCheck, K as CascadeAction, Q as CascadeConfig, T as ComputedFieldConfig, U as ComputedFieldFn, W as ComputedFieldsConfig, X as EndpointAuthConfig, Y as ErrorResponse, n as FilterCondition, Z as FilterOperator, _ as Guard, $ as HandleArgs, a0 as HookConfig, a1 as HookContext, a2 as HookFn, I as IncludeOptions, a3 as InferMeta, a4 as InferModel, a5 as InferSchema, a6 as JWTAlgorithm, a7 as JWTClaims, a8 as JWTClaimsSchema, a9 as JWTConfig, L as ListFilters, aa as ListOptions, ab as Model, ac as ModelPolicies, ad as ModelTable, ae as MultiTenantConfig, af as NestedCreateManyInput, ag as NestedCreateOneInput, N as NestedUpdateInput, ah as NestedWriteConfig, i as NestedWriteResult, ai as NestedWritesConfig, aj as NormalizedAuditConfig, ak as NormalizedMultiTenantConfig, al as NormalizedSoftDeleteConfig, am as NormalizedVersioningConfig, an as OwnershipExtractor, P as PaginatedResult, ao as PartialBy, ap as PathPattern, aq as PendingAction, ar as PendingActionStatus, as as PolicyContext, at as RESPONSE_ENVELOPE_CONTEXT_KEY, h as RelationConfig, au as RelationType, av as RelationsConfig, aw as RequiredBy, b as ResponseEnvelopeInfo, R as RouteOptions, ax as SchemaKeys, ay as SearchConfig, S as SearchOptions, l as SearchResult, az as SearchResultItem, aA as SoftDeleteConfig, aB as StructuredError, aC as SuccessResponse, V as ValidatedData, aD as ValidatedJWTClaims, f as VersionHistoryEntry, e as VersioningConfig, aE as applyComputedFields, aF as applyComputedFieldsToArray, aG as calculateChanges, aH as decodeCursor, aI as defineMeta, aJ as defineModel, aK as encodeCursor, aL as extractNestedData, aM as extractTenantId, aN as getAuditConfig, aO as getMultiTenantConfig, aP as getSoftDeleteConfig, aQ as getVersioningConfig, aR as isDirectNestedData, aS as parseAggregateField, aT as parseAggregateQuery, aU as parseJWTClaims, aV as parseSearchMode, aW as safeParseJWTClaims } from './types-QHT43lek.js';
|
|
3
3
|
import { L as LoggingStorage, a as LoggingEnv } from './types-SnlsH9UT.js';
|
|
4
4
|
export { b as LogEntry, c as LogLevel, d as LogQueryOptions, e as LoggingConfig, P as LoggingPathPattern, R as RedactField, f as RequestBodyConfig, g as RequestLogEntry, h as ResponseBodyConfig, i as ResponseLogEntry } from './types-SnlsH9UT.js';
|
|
5
5
|
import { R as RateLimitStorage, a as RateLimitEnv } from './types-Bjef1r9u.js';
|
|
6
6
|
export { F as FixedWindowEntry, K as KeyExtractor, b as KeyStrategy, O as OnRateLimitExceeded, c as RateLimitAlgorithm, d as RateLimitConfig, e as RateLimitEntry, P as RateLimitPathPattern, f as RateLimitResult, g as RateLimitTier, S as SlidingWindowEntry, T as TierFunction } from './types-Bjef1r9u.js';
|
|
7
7
|
import { StorageEnv } from './storage/index.js';
|
|
8
8
|
export { StorageMiddlewareConfig, createAPIKeyStorageMiddleware, createAuditStorageMiddleware, createCacheStorageMiddleware, createLoggingStorageMiddleware, createRateLimitStorageMiddleware, createStorageMiddleware, createVersioningStorageMiddleware, resolveAPIKeyStorage, resolveAuditStorage, resolveCacheStorage, resolveIdempotencyStorage, resolveLoggingStorage, resolveRateLimitStorage, resolveVersioningStorage } from './storage/index.js';
|
|
9
|
-
import { O as OpenAPIRoute } from './route-
|
|
10
|
-
export { i as isRouteClass } from './route-
|
|
9
|
+
import { O as OpenAPIRoute } from './route-CTec4QxL.js';
|
|
10
|
+
export { i as isRouteClass } from './route-CTec4QxL.js';
|
|
11
11
|
import { Env, Context, MiddlewareHandler, Hono, ErrorHandler } from 'hono';
|
|
12
12
|
import { OpenAPIHono, Hook } from '@hono/zod-openapi';
|
|
13
|
+
import { G as GeneratedEndpoints } from './index-C7qXEfCh.js';
|
|
14
|
+
export { A as AdapterBundle, a as ConfigAggregateEndpoint, B as ConfigBatchCreateEndpoint, b as ConfigBatchDeleteEndpoint, c as ConfigBatchRestoreEndpoint, d as ConfigBatchUpdateEndpoint, e as ConfigBatchUpsertEndpoint, C as ConfigCloneEndpoint, f as ConfigCreateEndpoint, D as ConfigDeleteEndpoint, E as ConfigExportEndpoint, I as ConfigImportEndpoint, L as ConfigListEndpoint, R as ConfigReadEndpoint, g as ConfigRestoreEndpoint, S as ConfigSearchEndpoint, U as ConfigUpdateEndpoint, h as ConfigUpsertEndpoint, i as CrudEndpointName, j as CrudEndpoints, k as EndpointClass, l as EndpointMiddlewares, m as EndpointsConfig, H as HonoOpenAPIApp, M as MemoryAdapters, n as RegisterCrudOptions, o as contentJson, p as defineEndpoints, q as errorResponse, r as registerCrud, s as successResponse } from './index-C7qXEfCh.js';
|
|
13
15
|
import { A as ApiException } from './index-DhCIATbD.js';
|
|
14
16
|
export { a as AggregationException, C as CacheException, b as ConfigurationException, c as ConflictException, F as ForbiddenException, I as InputValidationException, K as KVRateLimitStorage, d as KVRateLimitStorageOptions, M as MemoryRateLimitStorage, e as MemoryRateLimitStorageOptions, N as NotFoundException, R as RateLimitExceededException, f as RedisRateLimitClient, g as RedisRateLimitStorage, h as RedisRateLimitStorageOptions, U as UnauthorizedException, i as createRateLimitMiddleware, j as extractAPIKey, k as extractIP, l as extractUserId, m as generateKey, n as getRateLimitStorage, o as matchPath, r as resetRateLimit, s as setRateLimitStorage, p as shouldSkipPath } from './index-DhCIATbD.js';
|
|
15
17
|
import { AuditLogStorage } from './audit/index.js';
|
|
@@ -17,14 +19,13 @@ export { AuditLogger, MemoryAuditLogStorage, createAuditLogger, getAuditStorage,
|
|
|
17
19
|
import { VersioningStorage } from './versioning/index.js';
|
|
18
20
|
export { MemoryVersioningStorage, VersionManager, createVersionManager, getVersioningStorage, setVersioningStorage } from './versioning/index.js';
|
|
19
21
|
export { MultiTenantMiddlewareOptions, TenantEnv, multiTenant } from './multi-tenant/index.js';
|
|
20
|
-
import { M as ModelObject } from './import-
|
|
21
|
-
export { A as AggregateEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, m as BatchDeleteResult, d as BatchRestoreEndpoint, n as BatchRestoreResult, e as BatchUpdateEndpoint, f as BatchUpdateItem, o as BatchUpdateResult, g as BatchUpsertEndpoint, p as BatchUpsertItemResult, q as BatchUpsertResult, r as CascadeResult, h as CloneEndpoint, a as CreateEndpoint, s as CsvGenerateOptions, t as CsvParseError, u as CsvParseOptions, v as CsvParseResult, w as CsvValidationResult, D as DeleteEndpoint, E as ExportEndpoint, x as ExportFormat, y as ExportOptions, z as ExportResult, F as FieldSelection, G as FieldSelectionConfig, I as ImportEndpoint, H as ImportMode, J as ImportOptions, K as ImportResult, N as ImportRowResult, O as ImportRowStatus, P as ImportSummary, L as ListEndpoint, Q as ListEndpointConfig, R as ReadEndpoint, b as RestoreEndpoint, S as SearchEndpoint, T as SingleEndpointConfig, U as UpdateEndpoint, W as UpdateEndpointConfig, i as UpsertEndpoint, X as UpsertResult, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint, Y as applyFieldSelection, Z as applyFieldSelectionToArray, _ as computeAggregations, $ as createCsvStream, a0 as csvToJson, a1 as escapeCsvValue, a2 as generateCsv, a3 as getSchemaFields, a4 as inferCsvContentType, a5 as jsonToCsv, a6 as parseCsv, a7 as parseFieldSelection, a8 as parseFilterValue, a9 as parseListFilters, aa as searchInMemory, ab as validateCsvHeaders } from './import-
|
|
22
|
+
import { M as ModelObject } from './import-BowFqS6q.js';
|
|
23
|
+
export { A as AggregateEndpoint, B as BatchCreateEndpoint, c as BatchDeleteEndpoint, m as BatchDeleteResult, d as BatchRestoreEndpoint, n as BatchRestoreResult, e as BatchUpdateEndpoint, f as BatchUpdateItem, o as BatchUpdateResult, g as BatchUpsertEndpoint, p as BatchUpsertItemResult, q as BatchUpsertResult, r as CascadeResult, h as CloneEndpoint, a as CreateEndpoint, s as CsvGenerateOptions, t as CsvParseError, u as CsvParseOptions, v as CsvParseResult, w as CsvValidationResult, D as DeleteEndpoint, E as ExportEndpoint, x as ExportFormat, y as ExportOptions, z as ExportResult, F as FieldSelection, G as FieldSelectionConfig, I as ImportEndpoint, H as ImportMode, J as ImportOptions, K as ImportResult, N as ImportRowResult, O as ImportRowStatus, P as ImportSummary, L as ListEndpoint, Q as ListEndpointConfig, R as ReadEndpoint, b as RestoreEndpoint, S as SearchEndpoint, T as SingleEndpointConfig, U as UpdateEndpoint, W as UpdateEndpointConfig, i as UpsertEndpoint, X as UpsertResult, V as VersionCompareEndpoint, j as VersionHistoryEndpoint, k as VersionReadEndpoint, l as VersionRollbackEndpoint, Y as applyFieldSelection, Z as applyFieldSelectionToArray, _ as computeAggregations, $ as createCsvStream, a0 as csvToJson, a1 as escapeCsvValue, a2 as generateCsv, a3 as getSchemaFields, a4 as inferCsvContentType, a5 as jsonToCsv, a6 as parseCsv, a7 as parseFieldSelection, a8 as parseFilterValue, a9 as parseListFilters, aa as searchInMemory, ab as validateCsvHeaders } from './import-BowFqS6q.js';
|
|
22
24
|
import { C as CrudEventType, b as CrudEventPayload } from './types-rJSyOxkJ.js';
|
|
23
25
|
export { a as CrudEventListener, E as EventSubscription } from './types-rJSyOxkJ.js';
|
|
24
26
|
import { C as CrudEventEmitter } from './emitter-vW4MflrJ.js';
|
|
25
27
|
export { g as getEventEmitter, r as resolveEventEmitter, s as setEventEmitter } from './emitter-vW4MflrJ.js';
|
|
26
|
-
export { B as BulkPatchEndpoint, a as BulkPatchResult } from './bulk-patch-
|
|
27
|
-
export { A as AdapterBundle, a as ConfigAggregateEndpoint, B as ConfigBatchCreateEndpoint, b as ConfigBatchDeleteEndpoint, c as ConfigBatchRestoreEndpoint, d as ConfigBatchUpdateEndpoint, e as ConfigBatchUpsertEndpoint, C as ConfigCloneEndpoint, f as ConfigCreateEndpoint, D as ConfigDeleteEndpoint, E as ConfigExportEndpoint, I as ConfigImportEndpoint, L as ConfigListEndpoint, R as ConfigReadEndpoint, g as ConfigRestoreEndpoint, S as ConfigSearchEndpoint, U as ConfigUpdateEndpoint, h as ConfigUpsertEndpoint, i as CrudEndpointName, j as CrudEndpoints, k as EndpointClass, l as EndpointMiddlewares, m as EndpointsConfig, G as GeneratedEndpoints, H as HonoOpenAPIApp, M as MemoryAdapters, n as RegisterCrudOptions, o as contentJson, p as defineEndpoints, q as errorResponse, r as registerCrud, s as successResponse } from './index-BOWqsE16.js';
|
|
28
|
+
export { B as BulkPatchEndpoint, a as BulkPatchResult } from './bulk-patch-DX-qtuN4.js';
|
|
28
29
|
export { S as ScalarConfig, a as ScalarTheme, U as UIOptions, s as scalarUI, b as setupDocs, c as setupDocsIndex, d as setupReDoc, e as setupScalar, f as setupSwaggerUI } from './ui-CNJUoCg1.js';
|
|
29
30
|
import { z } from 'zod';
|
|
30
31
|
export { AuthEndpointMethods, AuthenticatedEndpoint, JWTClaimsValidationOptions, MemoryAPIKeyStorage, MemoryApprovalStorage, POLICIES_CONTEXT_KEY, allOf, allowAll, anyOf, createAPIKeyMiddleware, createAuthMiddleware, createJWTMiddleware, decodeJWT, defaultHashAPIKey, denyAll, generateAPIKey, getAPIKeyStorage, hashAPIKey, isValidAPIKeyFormat, optionalAuth, parseIso8601Duration, requireAllRoles, requireAnyPermission, requireApproval, requireAuth, requireAuthenticated, requireAuthentication, requireOwnership, requireOwnershipOrRole, requirePermissions, requirePolicy, requireRoles, setAPIKeyStorage, validateAPIKey, validateAPIKeyEntry, validateJWTClaims, verifyJWT, withAuth } from './auth/index.js';
|
|
@@ -290,6 +291,79 @@ declare function wrapCacheStorageForOpenApi(storage: {
|
|
|
290
291
|
}): Promise<void>;
|
|
291
292
|
}): PerTenantOpenApiCache;
|
|
292
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Pure, synchronous OpenAPI paths emission.
|
|
296
|
+
*
|
|
297
|
+
* `toOpenApiPaths(endpoints, options?)` turns a `defineEndpoints(...)` result
|
|
298
|
+
* (`GeneratedEndpoints`) into an OpenAPI 3.1 *paths fragment* —
|
|
299
|
+
* `{ [path]: { [verb]: operation } }` — without a running server, without
|
|
300
|
+
* `await`, and without calling `Model.resolveSchema()`.
|
|
301
|
+
*
|
|
302
|
+
* It exists so consumers (NestJS-style wrappers, doc aggregators, gateway
|
|
303
|
+
* config generators) stop hand-deriving a lossy OpenAPI fragment from static
|
|
304
|
+
* config. hono-crud already owns the authoritative per-endpoint
|
|
305
|
+
* `OpenAPIRouteSchema` (every generated endpoint exposes `getSchema()`); this
|
|
306
|
+
* function is the single source of truth for turning that into emitted
|
|
307
|
+
* OpenAPI.
|
|
308
|
+
*
|
|
309
|
+
* For a statically-defined model (`defineModel({ schema: <zod object>, ... })`
|
|
310
|
+
* with no `resolveSchema`), `endpoint.getSchema()` returns fully-populated
|
|
311
|
+
* request/response Zod schemas synchronously — no context, no resolution
|
|
312
|
+
* needed. This function feeds those through the exact same
|
|
313
|
+
* `createRoute` + `OpenAPIHono` + `getOpenAPI31Document` pipeline that
|
|
314
|
+
* `registerCrud`/`buildPerTenantOpenApi` use internally, then returns only
|
|
315
|
+
* the `paths` object. Models that rely on the async `resolveSchema` hook for
|
|
316
|
+
* per-tenant shapes still emit their *static* `schema` here (the documented
|
|
317
|
+
* fallback) — use `buildPerTenantOpenApi(...)` when a resolved per-tenant
|
|
318
|
+
* document is required.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* A single OpenAPI 3.1 Path Item: a map of lowercase HTTP verbs to
|
|
323
|
+
* Operation objects (plus the occasional `parameters`/`$ref`). Kept as a
|
|
324
|
+
* loose JSON-serializable record so this module doesn't leak the deep
|
|
325
|
+
* `openapi3-ts` generic surface onto consumers — the values are plain
|
|
326
|
+
* objects produced by `@hono/zod-openapi`'s document generator.
|
|
327
|
+
*/
|
|
328
|
+
type OpenApiPathItem = Record<string, unknown>;
|
|
329
|
+
/**
|
|
330
|
+
* Options for {@link toOpenApiPaths}.
|
|
331
|
+
*/
|
|
332
|
+
interface ToOpenApiPathsOptions {
|
|
333
|
+
/**
|
|
334
|
+
* Prefix prepended to every emitted path key (e.g. `'/api/v1/users'`).
|
|
335
|
+
* Slash-normalized: leading slash is ensured, duplicate slashes are
|
|
336
|
+
* collapsed, a trailing slash is dropped. Defaults to `''` (paths are
|
|
337
|
+
* emitted relative to the resource root, e.g. `/`, `/{id}`).
|
|
338
|
+
*/
|
|
339
|
+
basePath?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Override the OpenAPI tag for every emitted operation. When set, this
|
|
342
|
+
* replaces whatever tag the endpoint's `getSchema()` resolved (model
|
|
343
|
+
* `tag` / `tableName` / explicit `openapi.tags`). When unset, the
|
|
344
|
+
* per-endpoint tags are preserved as-is.
|
|
345
|
+
*/
|
|
346
|
+
tag?: string;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Turn a `defineEndpoints(...)` result into an OpenAPI 3.1 paths fragment.
|
|
350
|
+
*
|
|
351
|
+
* Pure and synchronous: no `await`, no server start, no
|
|
352
|
+
* `Model.resolveSchema()` invocation. Returns plain JSON-serializable
|
|
353
|
+
* objects. Covers *every* endpoint `defineEndpoints` actually generated
|
|
354
|
+
* (list/read/create/update/delete plus search/aggregate/upsert/restore/
|
|
355
|
+
* clone/export/import and all `batch*` verbs) — completeness vs a
|
|
356
|
+
* hand-rolled 5-verb subset is the entire point.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* const endpoints = defineEndpoints({ meta: userMeta, list: {}, create: {} }, MemoryAdapters);
|
|
361
|
+
* const paths = toOpenApiPaths(endpoints, { basePath: '/api/users' });
|
|
362
|
+
* // => { '/api/users': { get: {...}, post: {...} } }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
declare function toOpenApiPaths(endpoints: GeneratedEndpoints, options?: ToOpenApiPathsOptions): Record<string, OpenApiPathItem>;
|
|
366
|
+
|
|
293
367
|
/**
|
|
294
368
|
* Error mapper: transforms unknown errors to ApiException.
|
|
295
369
|
* Return undefined to skip this mapper and try the next one.
|
|
@@ -1425,4 +1499,4 @@ declare function crud<M extends MetaInput, E extends Env = Env>(meta: M): CrudBu
|
|
|
1425
1499
|
/** Combined environment type with all hono-crud context variables */
|
|
1426
1500
|
type HonoCrudEnv = AuthEnv & LoggingEnv & RateLimitEnv & StorageEnv;
|
|
1427
1501
|
|
|
1428
|
-
export { ApiException, AuditLogStorage, AuthEnv, CacheStorage, CreateBuilder, type CreateConfig, CrudBuilder, CrudEventEmitter, CrudEventPayload, CrudEventType, type CrudMiddlewareConfig, DeleteBuilder, type DeleteConfig, type ErrorHandlerConfig, type ErrorHook, type ErrorMapper, FilterConfig, type HonoCrudEnv, HonoOpenAPIHandler, HookMode, HttpErrorSchema, IdempotencyStorage, type InferZodSchema, ListBuilder, type ListConfig, type Logger, LoggingEnv, LoggingStorage, MetaInput, ModelObject, type OpenAPIConfig, OpenAPIRoute, OpenAPIRouteSchema, type PerTenantOpenApiCache, type PerTenantOpenApiConfig, type PerTenantOpenApiOptions, RateLimitEnv, RateLimitStorage, ReadBuilder, type ReadConfig, type RegisteredRoute, ResponseEnvelope, type RouterOptions, SchemaResolveContext, SearchFieldConfig, SearchMode, StorageEnv, type SubscribeEndpointConfig, UpdateBuilder, type UpdateConfig, type ValidationHookResult, VersioningStorage, ZodErrorSchema, ZodIssueSchema, buildPerTenantOpenApi, buildSearchConfig, calculateScore, commonResponses, createCreate, createCrudMiddleware, createDelete, createErrorHandler, createErrorSchema, createList, createOneOfErrorSchema, createRead, createSubscribeHandler, createUpdate, createValidationHook, crud, fromHono, generateETag, generateHighlights, getAuthType, getRequestId as getContextRequestId, getContextVar, getErrorMessage, getHandlerForApp, getLogger, getTenantId, getUser, getUserId, getUserPermissions, getUserRoles, hasAllPermissions, hasAllRoles, hasAnyRole, hasPermission, hasRole, httpErrorContent, jsonContent, jsonContentRequired, matchesIfMatch, matchesIfNoneMatch, openApiValidationHook, parseSearchFields, resolveErrorEnvelope, setContextVar, setLogger, termFrequency, toError, tokenize, tokenizeQuery, wrapCacheStorageForOpenApi, wrapError, zodErrorMapper };
|
|
1502
|
+
export { ApiException, AuditLogStorage, AuthEnv, CacheStorage, CreateBuilder, type CreateConfig, CrudBuilder, CrudEventEmitter, CrudEventPayload, CrudEventType, type CrudMiddlewareConfig, DeleteBuilder, type DeleteConfig, type ErrorHandlerConfig, type ErrorHook, type ErrorMapper, FilterConfig, GeneratedEndpoints, type HonoCrudEnv, HonoOpenAPIHandler, HookMode, HttpErrorSchema, IdempotencyStorage, type InferZodSchema, ListBuilder, type ListConfig, type Logger, LoggingEnv, LoggingStorage, MetaInput, ModelObject, type OpenAPIConfig, OpenAPIRoute, OpenAPIRouteSchema, type OpenApiPathItem, type PerTenantOpenApiCache, type PerTenantOpenApiConfig, type PerTenantOpenApiOptions, RateLimitEnv, RateLimitStorage, ReadBuilder, type ReadConfig, type RegisteredRoute, ResponseEnvelope, type RouterOptions, SchemaResolveContext, SearchFieldConfig, SearchMode, StorageEnv, type SubscribeEndpointConfig, type ToOpenApiPathsOptions, UpdateBuilder, type UpdateConfig, type ValidationHookResult, VersioningStorage, ZodErrorSchema, ZodIssueSchema, buildPerTenantOpenApi, buildSearchConfig, calculateScore, commonResponses, createCreate, createCrudMiddleware, createDelete, createErrorHandler, createErrorSchema, createList, createOneOfErrorSchema, createRead, createSubscribeHandler, createUpdate, createValidationHook, crud, fromHono, generateETag, generateHighlights, getAuthType, getRequestId as getContextRequestId, getContextVar, getErrorMessage, getHandlerForApp, getLogger, getTenantId, getUser, getUserId, getUserPermissions, getUserRoles, hasAllPermissions, hasAllRoles, hasAnyRole, hasPermission, hasRole, httpErrorContent, jsonContent, jsonContentRequired, matchesIfMatch, matchesIfNoneMatch, openApiValidationHook, parseSearchFields, resolveErrorEnvelope, setContextVar, setLogger, termFrequency, toError, toOpenApiPaths, tokenize, tokenizeQuery, wrapCacheStorageForOpenApi, wrapError, zodErrorMapper };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{I as DrizzleAdapters}from'./chunk-UQUDEKCP.js';import {r,s as s$1,A as A$1,z as z$1,q as q$1,p,o,n,m,l,x,y as y$1,j as j$1,i,h,k,g}from'./chunk-QK65CFMV.js';export{a as BulkPatchEndpoint}from'./chunk-QK65CFMV.js';export{y as PrismaAdapters}from'./chunk-MKMSOGVE.js';export{B as AggregateEndpoint,s as BatchCreateEndpoint,u as BatchDeleteEndpoint,v as BatchRestoreEndpoint,t as BatchUpdateEndpoint,w as BatchUpsertEndpoint,p as CloneEndpoint,k as CreateEndpoint,n as DeleteEndpoint,U as ExportEndpoint,V as ImportEndpoint,o as ListEndpoint,l as ReadEndpoint,q as RestoreEndpoint,K as SearchEndpoint,m as UpdateEndpoint,r as UpsertEndpoint,z as VersionCompareEndpoint,x as VersionHistoryEndpoint,y as VersionReadEndpoint,A as VersionRollbackEndpoint,i as applyFieldSelection,j as applyFieldSelectionToArray,J as buildSearchConfig,G as calculateScore,C as computeAggregations,O as createCsvStream,T as csvToJson,M as escapeCsvValue,N as generateCsv,a as generateETag,H as generateHighlights,g as getSchemaFields,R as inferCsvContentType,S as jsonToCsv,c as matchesIfMatch,b as matchesIfNoneMatch,P as parseCsv,h as parseFieldSelection,e as parseFilterValue,f as parseListFilters,I as parseSearchFields,L as searchInMemory,F as termFrequency,D as tokenize,E as tokenizeQuery,Q as validateCsvHeaders}from'./chunk-A5UWQNQQ.js';export{a as createHealthEndpoints,b as createHealthHandler}from'./chunk-XH7DEPW2.js';export{a as MemoryIdempotencyStorage}from'./chunk-FXIMMYFV.js';export{a as MemoryLoggingStorage}from'./chunk-3HBOKHIU.js';export{a as multiTenant}from'./chunk-L4X7KFWN.js';export{c as KVRateLimitStorage,a as MemoryRateLimitStorage,b as RedisRateLimitStorage}from'./chunk-EWKQ6BPV.js';import'./chunk-BJTWQHEV.js';export{a as applyProfile,b as applyProfileToArray,e as createArraySerializer,d as createSerializer,c as resolveProfile}from'./chunk-SDNXN7M5.js';export{g as createAPIKeyStorageMiddleware,e as createAuditStorageMiddleware,d as createCacheStorageMiddleware,c as createLoggingStorageMiddleware,b as createRateLimitStorageMiddleware,a as createStorageMiddleware,f as createVersioningStorageMiddleware}from'./chunk-R3WESU6C.js';export{a as scalarUI,e as setupDocs,f as setupDocsIndex,d as setupReDoc,b as setupScalar,c as setupSwaggerUI}from'./chunk-SPICOFUM.js';export{a as apiVersion,b as getApiVersion,c as getApiVersionConfig,d as versionedResponse}from'./chunk-KKLMXJY4.js';export{o as AuthenticatedEndpoint,a as JWTClaimsSchema,j as createAPIKeyMiddleware,l as createAuthMiddleware,e as createJWTMiddleware,g as decodeJWT,i as defaultHashAPIKey,m as optionalAuth,b as parseJWTClaims,n as requireAuthentication,c as safeParseJWTClaims,k as validateAPIKey,h as validateAPIKeyEntry,d as validateJWTClaims,f as verifyJWT,p as withAuth}from'./chunk-VSTEFZOU.js';import {a as a$1,c}from'./chunk-RXUYM2KD.js';export{e as MemoryApprovalStorage,b as OpenAPIRoute,f as POLICIES_CONTEXT_KEY,n as allOf,q as allowAll,o as anyOf,p as denyAll,c as isRouteClass,d as parseIso8601Duration,h as requireAllRoles,j as requireAnyPermission,t as requireApproval,k as requireAuth,r as requireAuthenticated,l as requireOwnership,m as requireOwnershipOrRole,i as requirePermissions,s as requirePolicy,g as requireRoles}from'./chunk-RXUYM2KD.js';export{b as KVCacheStorage,a as RedisCacheStorage}from'./chunk-H3H65KZF.js';import {T}from'./chunk-MGEQVZAI.js';export{C as MemoryCacheStorage,m as RateLimitExceededException,y as createInvalidationPattern,V as createLoggingMiddleware,v as createRateLimitMiddleware,z as createRelatedPatterns,p as extractAPIKey,f as extractClientIp,g as extractHeaders,n as extractIP,k as extractLoggingUserId,h as extractQuery,o as extractUserId,x as generateCacheKey,s as generateKey,l as generateRequestId,E as getCacheStorage,Q as getErrorMessage,S as getLoggingStorage,u as getRateLimitStorage,T as getRequestId,U as getRequestStartTime,j as isAllowedContentType,d as matchLoggingPath,q as matchPath,A as matchesPattern,B as parseCacheKey,c as redactHeaders,b as redactObject,w as resetRateLimit,M as resolveAPIKeyStorage,K as resolveAuditStorage,J as resolveCacheStorage,N as resolveIdempotencyStorage,I as resolveLoggingStorage,H as resolveRateLimitStorage,L as resolveVersioningStorage,D as setCacheStorage,R as setLoggingStorage,t as setRateLimitStorage,e as shouldExcludePath,a as shouldRedact,r as shouldSkipPath,O as toError,i as truncateBody,F as withCache,G as withCacheInvalidation,P as wrapError}from'./chunk-MGEQVZAI.js';export{a as MemoryVersioningStorage,e as VersionManager,f as createVersionManager,d as getVersioningStorage,c as setVersioningStorage}from'./chunk-U4PDR4P3.js';export{c as getIdempotencyStorage,d as idempotency,b as setIdempotencyStorage}from'./chunk-GF2EC5G4.js';export{e as AuditLogger,a as MemoryAuditLogStorage,f as createAuditLogger,d as getAuditStorage,c as setAuditStorage}from'./chunk-IDUJWS5U.js';export{c as MemoryAPIKeyStorage,d as generateAPIKey,h as getAPIKeyStorage,e as hashAPIKey,f as isValidAPIKeyFormat,i as setAPIKeyStorage}from'./chunk-2M5BM4VD.js';import {a,b}from'./chunk-FC56WWPB.js';export{g as AggregationException,a as ApiException,h as CacheException,i as ConfigurationException,d as ConflictException,f as ForbiddenException,b as InputValidationException,c as NotFoundException,e as UnauthorizedException}from'./chunk-FC56WWPB.js';import {q as q$2}from'./chunk-QJPUXVTT.js';export{q as RESPONSE_ENVELOPE_CONTEXT_KEY,j as applyComputedFields,k as applyComputedFieldsToArray,f as calculateChanges,b as decodeCursor,m as defineMeta,l as defineModel,a as encodeCursor,c as extractNestedData,p as extractTenantId,e as getAuditConfig,o as getMultiTenantConfig,n as getSoftDeleteConfig,g as getVersioningConfig,d as isDirectNestedData,h as parseAggregateField,i as parseAggregateQuery,r as parseSearchMode}from'./chunk-QJPUXVTT.js';export{a as StorageRegistry,b as createNullableRegistry,c as createRegistryWithDefault}from'./chunk-GBQQ3YQX.js';import'./chunk-CCGZ5UPB.js';export{f as StaticKeyProvider,e as decryptFields,b as decryptValue,d as encryptFields,a as encryptValue,c as isEncryptedValue}from'./chunk-QRXEQTNE.js';export{a as registerWebhooks}from'./chunk-7DDNX2F2.js';import {d}from'./chunk-QXFY6NYI.js';export{a as CrudEventEmitter,b as getEventEmitter,d as resolveEventEmitter,c as setEventEmitter}from'./chunk-QXFY6NYI.js';import {b as b$1}from'./chunk-DMGP7QDL.js';export{b as getLogger,a as setLogger}from'./chunk-DMGP7QDL.js';export{e as getAuthType,b as getUser,a as getUserId,d as getUserPermissions,c as getUserRoles,j as hasAllPermissions,h as hasAllRoles,i as hasAnyRole,g as hasPermission,f as hasRole}from'./chunk-MDHMZPXK.js';import {b as b$2}from'./chunk-VJRDAVID.js';export{c as getContextRequestId,a as getContextVar,d as getTenantId,b as setContextVar}from'./chunk-VJRDAVID.js';import {OpenAPIHono,createRoute}from'@hono/zod-openapi';import {z,ZodError}from'zod';import {HTTPException}from'hono/http-exception';import {streamSSE}from'hono/streaming';var pe=new WeakMap;function V(o){return pe.get(o)}var v=class{app;options;routes=new Map;constructor(e,n={}){this.app=e,this.options={docs_url:"/docs",redoc_url:"/redoc",openapi_url:"/openapi.json",...n};}registerRoute(e,n,t,r=[]){let c=`${e.toUpperCase()} ${n}`,f=t,u=new f().getSchema();this.routes.set(c,{method:e,path:n,schema:u,routeClass:t});let l=createRoute({method:e,path:this.convertPath(n),...u,responses:u.responses||{200:{description:"Success",content:{"application/json":{schema:{type:"object"}}}}}});if(r.length>0)for(let m of r)this.app.use(n,async(a,i)=>{if(a.req.method.toLowerCase()===e)return m(a,i);await i();});this.app.openapi(l,async m=>{let a$2=new f;a$2.setContext(m);try{return await a$2.handle()}catch(i){if(i instanceof a){let p=i.toJSON(),E=m?.var?.[q$2];return E?a$1(m,E.error(p.error),i.status):a$1(m,p,i.status)}throw i}});}convertPath(e){return e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}setupDocs(e,n){let t=e??this.options.openapi_url??"/openapi.json";this.app.doc(t,{openapi:n.openapi||"3.1.0",info:n.info,servers:n.servers,security:n.security});}getApp(){return this.app}getRegisteredRoutes(){return this.routes}toOpenApiPath(e){return this.convertPath(e)}};function jr(o=new OpenAPIHono,e={}){let n="openAPIRegistry"in o?o:new OpenAPIHono,t=new v(n,e),r=["get","post","put","patch","delete","options","head"],c$1=new Proxy(n,{get(f,h){if(r.includes(h))return (l,...m)=>{let a=m[m.length-1];if(c(a)){let i=m.slice(0,-1);return t.registerRoute(h,l,a,i),c$1}return f[h](l,...m)};if(h==="doc")return (l,m)=>{t.setupDocs(l,m);};if(h==="use")return (...l)=>(f[h](...l),c$1);let u=f[h];return typeof u=="function"?u.bind(f):u}});return pe.set(c$1,t),c$1}var Lr=6e4,Nr={openapi:"3.1.0",info:{title:"API",version:"1.0.0"}};async function Dr(o,e,n={}){let t=V(o);if(!t)throw new Error("buildPerTenantOpenApi: app was not produced by fromHono(...). Cannot find route registry.");let r=n.config??Nr,c=`openapi:${e.tenantId??"global"}:${r.info.version}`;if(n.cache){let l=await n.cache.get(c);if(l!=null)return l}let f=new OpenAPIHono;for(let l of t.getRegisteredRoutes().values()){let m=l.routeClass,a=new m,i=zr(e);a.setContext(i),typeof a.resolveModelSchema=="function"&&await a.resolveModelSchema();let p=a.getSchema(),E=createRoute({...p,method:l.method,path:t.toOpenApiPath(l.path),responses:p.responses??{200:{description:"Success",content:{"application/json":{schema:z.unknown()}}}}});f.openapi(E,()=>new Response);}let h={openapi:r.openapi??"3.1.0",info:r.info,servers:r.servers,security:r.security},u=n.spec==="3.0"?f.getOpenAPIDocument(h):f.getOpenAPI31Document(h);return n.cache&&await n.cache.set(c,u,n.cacheTtlMs??Lr),u}function zr(o){let e={};o.tenantId!==void 0&&(e.tenantId=o.tenantId),o.organizationId!==void 0&&(e.organizationId=o.organizationId);let n=o.request??new Request("http://localhost/");return {var:e,env:o.env,req:{raw:n,header:()=>{},query:()=>{},param:()=>{}},set(t,r){e[t]=r;},get(t){return e[t]},executionCtx:void 0}}function Vr(o){return {async get(e){let n=await o.get(e);return n?n.data:void 0},async set(e,n,t){let r=t?Math.ceil(t/1e3):void 0;await o.set(e,n,r?{ttl:r}:void 0);}}}var ce=o=>{if(o instanceof ZodError)return b.fromZodError(o)};function Wr(o={}){let{mappers:e=[],hooks:n=[],includeRequestId:t=true,includeStackTrace:r=false,defaultErrorCode:c="INTERNAL_ERROR",defaultErrorMessage:f="An internal error occurred",logUnmappedErrors:h=true,onHookError:u,responseEnvelope:l}=o,m=[...e,ce];return async(a$2,i)=>{let p,E=false;if(a$2 instanceof a)p=a$2,E=true;else if(a$2 instanceof HTTPException)p=new a(a$2.message,a$2.status,"HTTP_ERROR"),E=true;else {for(let d of m)try{let w=await d(a$2,i);if(w){p=w,E=!0;break}}catch{}E||(h&&b$1().error("Unmapped error",{error:a$2 instanceof Error?a$2.message:String(a$2)}),p=new a(f,500,c));}for(let d of n)try{let w=d(a$2,i,p);w instanceof Promise&&w.catch(B=>{u&&u(B,a$2,i);});}catch(w){u&&u(w,a$2,i);}let M=p.toJSON();if(t){let d=T(i);d&&(M.error.requestId=d);}r&&a$2.stack&&(M.error.stack=a$2.stack);let k=ue(i,l),C=k?k.error(M.error):M;return a$1(i,C,p.status)}}function ue(o,e){return o?.var?.[q$2]??e}var O=new Map,$r=["password","token","secret","apiKey","creditCard","ssn"];function P(o,e){if(o==null||typeof o!="object")return o;if(Array.isArray(o))return o.map(t=>P(t,e));let n={};for(let[t,r]of Object.entries(o))e.includes(t)||(n[t]=typeof r=="object"&&r!==null?P(r,e):r);return n}function Gr(o){let{table:e,events:n,emitter:t,filter:r,heartbeatInterval:c=3e4,maxConnections:f=1e3,connectionTimeout:h=3e5,excludeFields:u=$r}=o;return l=>{let m=d(l,t);if(!m)return l.json({success:false,error:{code:"EVENT_EMITTER_NOT_CONFIGURED",message:"Event emitter not configured"}},500);let a=O.get(e)||0;return a>=f?l.json({success:false,error:{code:"TOO_MANY_CONNECTIONS",message:"Too many SSE connections"}},503):(O.set(e,a+1),streamSSE(l,async i=>{let p,E=async d=>{if(n&&n.length>0&&!n.includes(d.type)||r&&!r(d,l))return;let w=u.length>0?P(d.data,u):d.data,B=d.previousData&&u.length>0?P(d.previousData,u):d.previousData;try{await i.writeSSE({event:`${d.table}.${d.type}`,data:JSON.stringify({type:d.type,table:d.table,recordId:d.recordId,data:w,previousData:B,timestamp:d.timestamp}),id:`${d.table}-${d.recordId}-${Date.now()}`});}catch{}};p=m.onTable(e,E);let M=()=>{p.unsubscribe();let d=O.get(e)||1;d<=1?O.delete(e):O.set(e,d-1);};i.onAbort(()=>{M();});let k=Date.now(),C=k;for(;!i.closed;){await i.sleep(1e3);let d=Date.now();if(d-k>=h){i.abort();break}if(d-C>=c){C=d;try{await i.writeSSE({event:"heartbeat",data:JSON.stringify({timestamp:new Date().toISOString()})});}catch{break}}}}))}}function Jr(o,e,n,t={}){let r=e.endsWith("/")?e.slice(0,-1):e,c=o,{middlewares:f=[],endpointMiddlewares:h={},responseEnvelope:u}=t,l=u?async(i,p)=>{b$2(i,q$2,u),await p();}:void 0,m=i=>{let p=n[i],E=p&&"_middlewares"in p?p._middlewares||[]:[];return [...l?[l]:[],...f,...h[i]||[],...E]},a=(i,p,E,M)=>{let k=m(E),C=c[i];k.length>0?C(p,...k,M):C(p,M);};n.create&&a("post",r,"create",n.create),n.list&&a("get",r,"list",n.list),n.batchCreate&&a("post",`${r}/batch`,"batchCreate",n.batchCreate),n.batchUpdate&&a("patch",`${r}/batch`,"batchUpdate",n.batchUpdate),n.batchDelete&&a("delete",`${r}/batch`,"batchDelete",n.batchDelete),n.batchRestore&&a("post",`${r}/batch/restore`,"batchRestore",n.batchRestore),n.batchUpsert&&a("post",`${r}/batch/upsert`,"batchUpsert",n.batchUpsert),n.search&&a("get",`${r}/search`,"search",n.search),n.aggregate&&a("get",`${r}/aggregate`,"aggregate",n.aggregate),n.export&&a("get",`${r}/export`,"export",n.export),n.import&&a("post",`${r}/import`,"import",n.import),n.upsert&&a("post",`${r}/upsert`,"upsert",n.upsert),n.read&&a("get",`${r}/:id`,"read",n.read),n.update&&a("patch",`${r}/:id`,"update",n.update),n.delete&&a("delete",`${r}/:id`,"delete",n.delete),n.restore&&a("post",`${r}/:id/restore`,"restore",n.restore),n.clone&&a("post",`${r}/:id/clone`,"clone",n.clone);}function q(o){return {content:{"application/json":{schema:o}}}}function Yr(o){return {description:"Success",...q({type:"object",properties:{success:{type:"boolean",enum:[true]},result:o},required:["success","result"]})}}function Xr(o="Error"){return {description:o,...q({type:"object",properties:{success:{type:"boolean",enum:[false]},error:{type:"object",properties:{code:{type:"string"},message:{type:"string"},details:{}},required:["code","message"]}},required:["success","error"]})}}function Z(o,e){return {content:{"application/json":{schema:o}},description:e}}function Qr(o,e){return {content:{"application/json":{schema:o}},description:e,required:true}}var me=z.object({code:z.string(),path:z.array(z.union([z.string(),z.number()])),message:z.string()}),I=z.object({success:z.literal(false),error:z.object({name:z.literal("ZodError"),issues:z.array(me)})});function ea(o){return I}function ta(...o){return I}var oa=(o,e)=>{if(!o.success)return e.json({success:false,error:{name:"ZodError",issues:o.error.issues}},422)};function na(o,e=422){return (n,t)=>{if(!n.success)return t.json(o(n.error),e)}}var fe=z.object({success:z.literal(false),error:z.object({message:z.string(),code:z.string().optional()})});function y(o){return Z(fe,o)}var ra={badRequest:y("Bad request"),unauthorized:y("Unauthorized"),forbidden:y("Forbidden"),notFound:y("Resource not found"),conflict:y("Resource conflict"),validationError:Z(I,"Validation error"),internalError:y("Internal server error")};function aa(o){return async(e,n)=>{o.cache&&e.set("cacheStorage",o.cache),o.rateLimit&&e.set("rateLimitStorage",o.rateLimit),o.audit&&e.set("auditStorage",o.audit),o.versioning&&e.set("versioningStorage",o.versioning),o.logging&&e.set("loggingStorage",o.logging),o.idempotency&&e.set("idempotencyStorage",o.idempotency),o.events&&e.set("eventEmitter",o.events),await n();}}function s(o,e){let n=e.middlewares??[],t=e.extras;return class extends o{static _middlewares=n;constructor(){super(),t&&Object.assign(this,t);}_meta=e.meta;schema=e.schema??{};beforeHookMode=e.beforeHookMode??"sequential";afterHookMode=e.afterHookMode??"sequential";allowNestedCreate=e.allowNestedCreate??[];lookupField=e.lookupField??"id";additionalFilters=e.additionalFilters;allowedUpdateFields=e.allowedUpdateFields;blockedUpdateFields=e.blockedUpdateFields;allowNestedWrites=e.allowNestedWrites??[];includeCascadeResults=e.includeCascadeResults??false;filterFields=e.filterFields??[];filterConfig=e.filterConfig;searchFields=e.searchFields??[];searchFieldName=e.searchFieldName??"search";sortFields=e.sortFields??[];defaultSort=e.defaultSort;defaultPerPage=e.defaultPerPage??20;maxPerPage=e.maxPerPage??100;allowedIncludes=e.allowedIncludes??[];fieldSelectionEnabled=e.fieldSelectionEnabled??false;allowedSelectFields=e.allowedSelectFields??[];blockedSelectFields=e.blockedSelectFields??[];alwaysIncludeFields=e.alwaysIncludeFields??[];defaultSelectFields=e.defaultSelectFields??[];getBodySchema(){return e.bodySchema?e.bodySchema:super.getBodySchema()}async before(...c){return e.before?e.before(...c):super.before(...c)}async after(...c){return e.after?e.after(...c):super.after(...c)}transform(c){return e.transform?e.transform(c):super.transform(c)}}}function ia(o,e){return s(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,before:o.before,after:o.after,beforeHookMode:o.beforeHookMode,afterHookMode:o.afterHookMode,allowNestedCreate:o.allowNestedCreate})}function sa(o,e){let n=o.defaultSort??(o.defaultOrderBy?{field:o.defaultOrderBy,order:o.defaultOrderDirection??"asc"}:void 0);return s(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,after:o.after,transform:o.transform,filterFields:o.filterFields,filterConfig:o.filterConfig,searchFields:o.searchFields,searchFieldName:o.searchFieldName,sortFields:o.sortFields??o.orderByFields,defaultSort:n,defaultPerPage:o.defaultPerPage,maxPerPage:o.maxPerPage,allowedIncludes:o.allowedIncludes,fieldSelectionEnabled:o.fieldSelectionEnabled,allowedSelectFields:o.allowedSelectFields,blockedSelectFields:o.blockedSelectFields,alwaysIncludeFields:o.alwaysIncludeFields,defaultSelectFields:o.defaultSelectFields})}function da(o,e){return s(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,after:o.after,transform:o.transform,lookupField:o.lookupField,additionalFilters:o.additionalFilters,allowedIncludes:o.allowedIncludes,fieldSelectionEnabled:o.fieldSelectionEnabled,allowedSelectFields:o.allowedSelectFields,blockedSelectFields:o.blockedSelectFields,alwaysIncludeFields:o.alwaysIncludeFields,defaultSelectFields:o.defaultSelectFields})}function la(o,e){return s(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,before:o.before,after:o.after,transform:o.transform,beforeHookMode:o.beforeHookMode,afterHookMode:o.afterHookMode,lookupField:o.lookupField,additionalFilters:o.additionalFilters,allowedUpdateFields:o.allowedUpdateFields,blockedUpdateFields:o.blockedUpdateFields,allowNestedWrites:o.allowNestedWrites})}function pa(o,e){return s(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,before:o.before,after:o.after,beforeHookMode:o.beforeHookMode,afterHookMode:o.afterHookMode,lookupField:o.lookupField,additionalFilters:o.additionalFilters,includeCascadeResults:o.includeCascadeResults})}var R=class{constructor(e){this.meta=e;}_schema={};_before;_after;_beforeHookMode="sequential";_afterHookMode="sequential";_allowNestedCreate=[];_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}before(e){return this._before=e,this}after(e){return this._after=e,this}beforeMode(e){return this._beforeHookMode=e,this}afterMode(e){return this._afterHookMode=e,this}nestedCreate(...e){return this._allowNestedCreate=e,this}build(e){return s(e,{meta:this.meta,schema:this._schema,before:this._before,after:this._after,beforeHookMode:this._beforeHookMode,afterHookMode:this._afterHookMode,allowNestedCreate:this._allowNestedCreate,middlewares:this._middlewares})}},A=class{constructor(e){this.meta=e;}_schema={};_filterFields=[];_filterConfig;_searchFields=[];_searchFieldName="search";_sortFields=[];_defaultSort;_defaultPerPage=20;_maxPerPage=100;_allowedIncludes=[];_fieldSelectionEnabled=false;_allowedSelectFields=[];_blockedSelectFields=[];_alwaysIncludeFields=[];_defaultSelectFields=[];_after;_transform;_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}filter(...e){return this._filterFields=e,this}filterWith(e){return this._filterConfig=e,this}search(...e){return this._searchFields=e,this}searchParam(e){return this._searchFieldName=e,this}sortable(...e){return this._sortFields=e,this}orderBy(...e){return this.sortable(...e)}defaultSort(e,n="asc"){return this._defaultSort={field:e,order:n},this}defaultOrder(e,n="asc"){return this.defaultSort(e,n)}pagination(e,n){return this._defaultPerPage=e,n!==void 0&&(this._maxPerPage=n),this}include(...e){return this._allowedIncludes=e,this}fieldSelection(e){return this._fieldSelectionEnabled=true,e?.allowed&&(this._allowedSelectFields=e.allowed),e?.blocked&&(this._blockedSelectFields=e.blocked),e?.alwaysInclude&&(this._alwaysIncludeFields=e.alwaysInclude),e?.defaults&&(this._defaultSelectFields=e.defaults),this}after(e){return this._after=e,this}transform(e){return this._transform=e,this}build(e){return s(e,{meta:this.meta,schema:this._schema,filterFields:this._filterFields,filterConfig:this._filterConfig,searchFields:this._searchFields,searchFieldName:this._searchFieldName,sortFields:this._sortFields,defaultSort:this._defaultSort,defaultPerPage:this._defaultPerPage,maxPerPage:this._maxPerPage,allowedIncludes:this._allowedIncludes,fieldSelectionEnabled:this._fieldSelectionEnabled,allowedSelectFields:this._allowedSelectFields,blockedSelectFields:this._blockedSelectFields,alwaysIncludeFields:this._alwaysIncludeFields,defaultSelectFields:this._defaultSelectFields,after:this._after,transform:this._transform,middlewares:this._middlewares})}},H=class{constructor(e){this.meta=e;}_schema={};_lookupField="id";_additionalFilters;_allowedIncludes=[];_fieldSelectionEnabled=false;_allowedSelectFields=[];_blockedSelectFields=[];_alwaysIncludeFields=[];_defaultSelectFields=[];_after;_transform;_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}lookupField(e){return this._lookupField=e,this}additionalFilters(...e){return this._additionalFilters=e,this}include(...e){return this._allowedIncludes=e,this}fieldSelection(e){return this._fieldSelectionEnabled=true,e?.allowed&&(this._allowedSelectFields=e.allowed),e?.blocked&&(this._blockedSelectFields=e.blocked),e?.alwaysInclude&&(this._alwaysIncludeFields=e.alwaysInclude),e?.defaults&&(this._defaultSelectFields=e.defaults),this}after(e){return this._after=e,this}transform(e){return this._transform=e,this}build(e){return s(e,{meta:this.meta,schema:this._schema,lookupField:this._lookupField,additionalFilters:this._additionalFilters,allowedIncludes:this._allowedIncludes,fieldSelectionEnabled:this._fieldSelectionEnabled,allowedSelectFields:this._allowedSelectFields,blockedSelectFields:this._blockedSelectFields,alwaysIncludeFields:this._alwaysIncludeFields,defaultSelectFields:this._defaultSelectFields,after:this._after,transform:this._transform,middlewares:this._middlewares})}},F=class{constructor(e){this.meta=e;}_schema={};_lookupField="id";_additionalFilters;_allowedUpdateFields;_blockedUpdateFields;_allowNestedWrites=[];_before;_after;_beforeHookMode="sequential";_afterHookMode="sequential";_transform;_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}lookupField(e){return this._lookupField=e,this}additionalFilters(...e){return this._additionalFilters=e,this}allowedFields(...e){return this._allowedUpdateFields=e,this}blockedFields(...e){return this._blockedUpdateFields=e,this}nestedWrites(...e){return this._allowNestedWrites=e,this}before(e){return this._before=e,this}after(e){return this._after=e,this}beforeMode(e){return this._beforeHookMode=e,this}afterMode(e){return this._afterHookMode=e,this}transform(e){return this._transform=e,this}build(e){return s(e,{meta:this.meta,schema:this._schema,lookupField:this._lookupField,additionalFilters:this._additionalFilters,allowedUpdateFields:this._allowedUpdateFields,blockedUpdateFields:this._blockedUpdateFields,allowNestedWrites:this._allowNestedWrites,before:this._before,after:this._after,beforeHookMode:this._beforeHookMode,afterHookMode:this._afterHookMode,transform:this._transform,middlewares:this._middlewares})}},_=class{constructor(e){this.meta=e;}_schema={};_lookupField="id";_additionalFilters;_includeCascadeResults=false;_before;_after;_beforeHookMode="sequential";_afterHookMode="sequential";_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}lookupField(e){return this._lookupField=e,this}additionalFilters(...e){return this._additionalFilters=e,this}includeCascade(e=true){return this._includeCascadeResults=e,this}before(e){return this._before=e,this}after(e){return this._after=e,this}beforeMode(e){return this._beforeHookMode=e,this}afterMode(e){return this._afterHookMode=e,this}build(e){return s(e,{meta:this.meta,schema:this._schema,lookupField:this._lookupField,additionalFilters:this._additionalFilters,includeCascadeResults:this._includeCascadeResults,before:this._before,after:this._after,beforeHookMode:this._beforeHookMode,afterHookMode:this._afterHookMode,middlewares:this._middlewares})}},j=class{constructor(e){this.meta=e;}create(){return new R(this.meta)}list(){return new A(this.meta)}read(){return new H(this.meta)}update(){return new F(this.meta)}delete(){return new _(this.meta)}};function ca(o){return new j(o)}var ua={CreateEndpoint:g,ListEndpoint:k,ReadEndpoint:h,UpdateEndpoint:i,DeleteEndpoint:j$1,SearchEndpoint:y$1,AggregateEndpoint:x,RestoreEndpoint:l,BatchCreateEndpoint:m,BatchUpdateEndpoint:n,BatchDeleteEndpoint:o,BatchRestoreEndpoint:p,BatchUpsertEndpoint:q$1,ExportEndpoint:z$1,ImportEndpoint:A$1,UpsertEndpoint:s$1,CloneEndpoint:r};function ma(o,e){let n={};if(o.create!==void 0){let t=o.create;n.create=s(e.CreateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,allowNestedCreate:t.nestedCreate,before:t.hooks?.before,after:t.hooks?.after});}if(o.list!==void 0){let t=o.list;n.list=s(e.ListEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,filterFields:t.filtering?.fields,filterConfig:t.filtering?.config,searchFields:t.search?.fields,searchFieldName:t.search?.paramName,sortFields:t.sorting?.fields,defaultSort:t.sorting?.default?{field:t.sorting.default,order:t.sorting.defaultOrder??t.sorting.defaultDirection??"asc"}:void 0,defaultPerPage:t.pagination?.defaultPerPage,maxPerPage:t.pagination?.maxPerPage,allowedIncludes:t.includes,fieldSelectionEnabled:t.fieldSelection?.enabled,allowedSelectFields:t.fieldSelection?.allowed,blockedSelectFields:t.fieldSelection?.blocked,alwaysIncludeFields:t.fieldSelection?.alwaysInclude,defaultSelectFields:t.fieldSelection?.defaults,after:t.hooks?.after,transform:t.hooks?.transform});}if(o.read!==void 0){let t=o.read;n.read=s(e.ReadEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,lookupField:t.lookupField,additionalFilters:t.additionalFilters,allowedIncludes:t.includes,fieldSelectionEnabled:t.fieldSelection?.enabled,allowedSelectFields:t.fieldSelection?.allowed,blockedSelectFields:t.fieldSelection?.blocked,alwaysIncludeFields:t.fieldSelection?.alwaysInclude,defaultSelectFields:t.fieldSelection?.defaults,after:t.hooks?.after,transform:t.hooks?.transform});}if(o.update!==void 0){let t=o.update;n.update=s(e.UpdateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,lookupField:t.lookupField,additionalFilters:t.additionalFilters,allowedUpdateFields:t.fields?.allowed,blockedUpdateFields:t.fields?.blocked,allowNestedWrites:t.nestedWrites,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,transform:t.hooks?.transform});}if(o.delete!==void 0){let t=o.delete;n.delete=s(e.DeleteEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,lookupField:t.lookupField,additionalFilters:t.additionalFilters,includeCascadeResults:t.includeCascadeResults,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after});}if(o.search!==void 0&&e.SearchEndpoint){let t=o.search;n.search=s(e.SearchEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,after:t.hooks?.after,extras:{...t.fields!==void 0?{searchFields:t.fields}:{},...t.mode!==void 0?{defaultMode:t.mode}:{}}});}if(o.aggregate!==void 0&&e.AggregateEndpoint){let t=o.aggregate;n.aggregate=s(e.AggregateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,after:t.hooks?.after,extras:{...t.fields!==void 0?{filterFields:t.fields}:{}}});}if(o.restore!==void 0&&e.RestoreEndpoint){let t=o.restore;n.restore=s(e.RestoreEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after});}if(o.batchCreate!==void 0&&e.BatchCreateEndpoint){let t=o.batchCreate;n.batchCreate=s(e.BatchCreateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchUpdate!==void 0&&e.BatchUpdateEndpoint){let t=o.batchUpdate;n.batchUpdate=s(e.BatchUpdateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchDelete!==void 0&&e.BatchDeleteEndpoint){let t=o.batchDelete;n.batchDelete=s(e.BatchDeleteEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchRestore!==void 0&&e.BatchRestoreEndpoint){let t=o.batchRestore;n.batchRestore=s(e.BatchRestoreEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchUpsert!==void 0&&e.BatchUpsertEndpoint){let t=o.batchUpsert,r=typeof t.conflictTarget=="string"?[t.conflictTarget]:t.conflictTarget;n.batchUpsert=s(e.BatchUpsertEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{},...r!==void 0?{upsertKeys:r}:{}}});}if(o.export!==void 0&&e.ExportEndpoint){let t=o.export;n.export=s(e.ExportEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,extras:{...t.maxRows!==void 0?{maxExportRecords:t.maxRows}:{},...t.formats!==void 0&&t.formats.length>0?{defaultFormat:t.formats[0]}:{}}});}if(o.import!==void 0&&e.ImportEndpoint){let t=o.import;n.import=s(e.ImportEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxRows!==void 0?{maxBatchSize:t.maxRows}:{}}});}if(o.upsert!==void 0&&e.UpsertEndpoint){let t=o.upsert,r=typeof t.conflictTarget=="string"?[t.conflictTarget]:t.conflictTarget;n.upsert=s(e.UpsertEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...r!==void 0?{upsertKeys:r}:{}}});}if(o.clone!==void 0&&e.CloneEndpoint){let t=o.clone;n.clone=s(e.CloneEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.fieldsToReset!==void 0?{excludeFromClone:t.fieldsToReset}:{}}});}return n}
|
|
2
|
-
export{R as CreateBuilder,j as CrudBuilder,_ as DeleteBuilder,
|
|
1
|
+
export{I as DrizzleAdapters}from'./chunk-UQUDEKCP.js';import {r,s,A as A$1,z as z$1,q as q$1,p,o,n,m,l,x,y as y$1,j as j$1,i,h,k,g}from'./chunk-QK65CFMV.js';export{a as BulkPatchEndpoint}from'./chunk-QK65CFMV.js';export{y as PrismaAdapters}from'./chunk-MKMSOGVE.js';export{B as AggregateEndpoint,s as BatchCreateEndpoint,u as BatchDeleteEndpoint,v as BatchRestoreEndpoint,t as BatchUpdateEndpoint,w as BatchUpsertEndpoint,p as CloneEndpoint,k as CreateEndpoint,n as DeleteEndpoint,U as ExportEndpoint,V as ImportEndpoint,o as ListEndpoint,l as ReadEndpoint,q as RestoreEndpoint,K as SearchEndpoint,m as UpdateEndpoint,r as UpsertEndpoint,z as VersionCompareEndpoint,x as VersionHistoryEndpoint,y as VersionReadEndpoint,A as VersionRollbackEndpoint,i as applyFieldSelection,j as applyFieldSelectionToArray,J as buildSearchConfig,G as calculateScore,C as computeAggregations,O as createCsvStream,T as csvToJson,M as escapeCsvValue,N as generateCsv,a as generateETag,H as generateHighlights,g as getSchemaFields,R as inferCsvContentType,S as jsonToCsv,c as matchesIfMatch,b as matchesIfNoneMatch,P as parseCsv,h as parseFieldSelection,e as parseFilterValue,f as parseListFilters,I as parseSearchFields,L as searchInMemory,F as termFrequency,D as tokenize,E as tokenizeQuery,Q as validateCsvHeaders}from'./chunk-A5UWQNQQ.js';export{a as createHealthEndpoints,b as createHealthHandler}from'./chunk-XH7DEPW2.js';export{a as MemoryIdempotencyStorage}from'./chunk-FXIMMYFV.js';export{a as MemoryLoggingStorage}from'./chunk-3HBOKHIU.js';export{a as multiTenant}from'./chunk-L4X7KFWN.js';export{c as KVRateLimitStorage,a as MemoryRateLimitStorage,b as RedisRateLimitStorage}from'./chunk-EWKQ6BPV.js';import'./chunk-BJTWQHEV.js';export{a as applyProfile,b as applyProfileToArray,e as createArraySerializer,d as createSerializer,c as resolveProfile}from'./chunk-SDNXN7M5.js';export{g as createAPIKeyStorageMiddleware,e as createAuditStorageMiddleware,d as createCacheStorageMiddleware,c as createLoggingStorageMiddleware,b as createRateLimitStorageMiddleware,a as createStorageMiddleware,f as createVersioningStorageMiddleware}from'./chunk-R3WESU6C.js';export{a as scalarUI,e as setupDocs,f as setupDocsIndex,d as setupReDoc,b as setupScalar,c as setupSwaggerUI}from'./chunk-SPICOFUM.js';export{a as apiVersion,b as getApiVersion,c as getApiVersionConfig,d as versionedResponse}from'./chunk-KKLMXJY4.js';export{o as AuthenticatedEndpoint,a as JWTClaimsSchema,j as createAPIKeyMiddleware,l as createAuthMiddleware,e as createJWTMiddleware,g as decodeJWT,i as defaultHashAPIKey,m as optionalAuth,b as parseJWTClaims,n as requireAuthentication,c as safeParseJWTClaims,k as validateAPIKey,h as validateAPIKeyEntry,d as validateJWTClaims,f as verifyJWT,p as withAuth}from'./chunk-VSTEFZOU.js';import {a as a$1,c}from'./chunk-RXUYM2KD.js';export{e as MemoryApprovalStorage,b as OpenAPIRoute,f as POLICIES_CONTEXT_KEY,n as allOf,q as allowAll,o as anyOf,p as denyAll,c as isRouteClass,d as parseIso8601Duration,h as requireAllRoles,j as requireAnyPermission,t as requireApproval,k as requireAuth,r as requireAuthenticated,l as requireOwnership,m as requireOwnershipOrRole,i as requirePermissions,s as requirePolicy,g as requireRoles}from'./chunk-RXUYM2KD.js';export{b as KVCacheStorage,a as RedisCacheStorage}from'./chunk-H3H65KZF.js';import {T}from'./chunk-MGEQVZAI.js';export{C as MemoryCacheStorage,m as RateLimitExceededException,y as createInvalidationPattern,V as createLoggingMiddleware,v as createRateLimitMiddleware,z as createRelatedPatterns,p as extractAPIKey,f as extractClientIp,g as extractHeaders,n as extractIP,k as extractLoggingUserId,h as extractQuery,o as extractUserId,x as generateCacheKey,s as generateKey,l as generateRequestId,E as getCacheStorage,Q as getErrorMessage,S as getLoggingStorage,u as getRateLimitStorage,T as getRequestId,U as getRequestStartTime,j as isAllowedContentType,d as matchLoggingPath,q as matchPath,A as matchesPattern,B as parseCacheKey,c as redactHeaders,b as redactObject,w as resetRateLimit,M as resolveAPIKeyStorage,K as resolveAuditStorage,J as resolveCacheStorage,N as resolveIdempotencyStorage,I as resolveLoggingStorage,H as resolveRateLimitStorage,L as resolveVersioningStorage,D as setCacheStorage,R as setLoggingStorage,t as setRateLimitStorage,e as shouldExcludePath,a as shouldRedact,r as shouldSkipPath,O as toError,i as truncateBody,F as withCache,G as withCacheInvalidation,P as wrapError}from'./chunk-MGEQVZAI.js';export{a as MemoryVersioningStorage,e as VersionManager,f as createVersionManager,d as getVersioningStorage,c as setVersioningStorage}from'./chunk-U4PDR4P3.js';export{c as getIdempotencyStorage,d as idempotency,b as setIdempotencyStorage}from'./chunk-GF2EC5G4.js';export{e as AuditLogger,a as MemoryAuditLogStorage,f as createAuditLogger,d as getAuditStorage,c as setAuditStorage}from'./chunk-IDUJWS5U.js';export{c as MemoryAPIKeyStorage,d as generateAPIKey,h as getAPIKeyStorage,e as hashAPIKey,f as isValidAPIKeyFormat,i as setAPIKeyStorage}from'./chunk-2M5BM4VD.js';import {a,b}from'./chunk-FC56WWPB.js';export{g as AggregationException,a as ApiException,h as CacheException,i as ConfigurationException,d as ConflictException,f as ForbiddenException,b as InputValidationException,c as NotFoundException,e as UnauthorizedException}from'./chunk-FC56WWPB.js';import {q as q$2}from'./chunk-QJPUXVTT.js';export{q as RESPONSE_ENVELOPE_CONTEXT_KEY,j as applyComputedFields,k as applyComputedFieldsToArray,f as calculateChanges,b as decodeCursor,m as defineMeta,l as defineModel,a as encodeCursor,c as extractNestedData,p as extractTenantId,e as getAuditConfig,o as getMultiTenantConfig,n as getSoftDeleteConfig,g as getVersioningConfig,d as isDirectNestedData,h as parseAggregateField,i as parseAggregateQuery,r as parseSearchMode}from'./chunk-QJPUXVTT.js';export{a as StorageRegistry,b as createNullableRegistry,c as createRegistryWithDefault}from'./chunk-GBQQ3YQX.js';import'./chunk-CCGZ5UPB.js';export{f as StaticKeyProvider,e as decryptFields,b as decryptValue,d as encryptFields,a as encryptValue,c as isEncryptedValue}from'./chunk-QRXEQTNE.js';export{a as registerWebhooks}from'./chunk-7DDNX2F2.js';import {d as d$1}from'./chunk-QXFY6NYI.js';export{a as CrudEventEmitter,b as getEventEmitter,d as resolveEventEmitter,c as setEventEmitter}from'./chunk-QXFY6NYI.js';import {b as b$1}from'./chunk-DMGP7QDL.js';export{b as getLogger,a as setLogger}from'./chunk-DMGP7QDL.js';export{e as getAuthType,b as getUser,a as getUserId,d as getUserPermissions,c as getUserRoles,j as hasAllPermissions,h as hasAllRoles,i as hasAnyRole,g as hasPermission,f as hasRole}from'./chunk-MDHMZPXK.js';import {b as b$2}from'./chunk-VJRDAVID.js';export{c as getContextRequestId,a as getContextVar,d as getTenantId,b as setContextVar}from'./chunk-VJRDAVID.js';import {OpenAPIHono,createRoute}from'@hono/zod-openapi';import {z,ZodError}from'zod';import {HTTPException}from'hono/http-exception';import {streamSSE}from'hono/streaming';var pe=new WeakMap;function V(o){return pe.get(o)}var P=class{app;options;routes=new Map;constructor(e,n={}){this.app=e,this.options={docs_url:"/docs",redoc_url:"/redoc",openapi_url:"/openapi.json",...n};}registerRoute(e,n,t,r=[]){let m=`${e.toUpperCase()} ${n}`,f=t,c=new f().getSchema();this.routes.set(m,{method:e,path:n,schema:c,routeClass:t});let i=createRoute({method:e,path:this.convertPath(n),...c,responses:c.responses||{200:{description:"Success",content:{"application/json":{schema:{type:"object"}}}}}});if(r.length>0)for(let u of r)this.app.use(n,async(a,s)=>{if(a.req.method.toLowerCase()===e)return u(a,s);await s();});this.app.openapi(i,async u=>{let a$2=new f;a$2.setContext(u);try{return await a$2.handle()}catch(s){if(s instanceof a){let p=s.toJSON(),g=u?.var?.[q$2];return g?a$1(u,g.error(p.error),s.status):a$1(u,p,s.status)}throw s}});}convertPath(e){return e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}setupDocs(e,n){let t=e??this.options.openapi_url??"/openapi.json";this.app.doc(t,{openapi:n.openapi||"3.1.0",info:n.info,servers:n.servers,security:n.security});}getApp(){return this.app}getRegisteredRoutes(){return this.routes}toOpenApiPath(e){return this.convertPath(e)}};function jr(o=new OpenAPIHono,e={}){let n="openAPIRegistry"in o?o:new OpenAPIHono,t=new P(n,e),r=["get","post","put","patch","delete","options","head"],m=new Proxy(n,{get(f,h){if(r.includes(h))return (i,...u)=>{let a=u[u.length-1];if(c(a)){let s=u.slice(0,-1);return t.registerRoute(h,i,a,s),m}return f[h](i,...u)};if(h==="doc")return (i,u)=>{t.setupDocs(i,u);};if(h==="use")return (...i)=>(f[h](...i),m);let c$1=f[h];return typeof c$1=="function"?c$1.bind(f):c$1}});return pe.set(m,t),m}var Lr=6e4,Nr={openapi:"3.1.0",info:{title:"API",version:"1.0.0"}};async function Dr(o,e,n={}){let t=V(o);if(!t)throw new Error("buildPerTenantOpenApi: app was not produced by fromHono(...). Cannot find route registry.");let r=n.config??Nr,m=`openapi:${e.tenantId??"global"}:${r.info.version}`;if(n.cache){let i=await n.cache.get(m);if(i!=null)return i}let f=new OpenAPIHono;for(let i of t.getRegisteredRoutes().values()){let u=i.routeClass,a=new u,s=zr(e);a.setContext(s),typeof a.resolveModelSchema=="function"&&await a.resolveModelSchema();let p=a.getSchema(),g=createRoute({...p,method:i.method,path:t.toOpenApiPath(i.path),responses:p.responses??{200:{description:"Success",content:{"application/json":{schema:z.unknown()}}}}});f.openapi(g,()=>new Response);}let h={openapi:r.openapi??"3.1.0",info:r.info,servers:r.servers,security:r.security},c=n.spec==="3.0"?f.getOpenAPIDocument(h):f.getOpenAPI31Document(h);return n.cache&&await n.cache.set(m,c,n.cacheTtlMs??Lr),c}function zr(o){let e={};o.tenantId!==void 0&&(e.tenantId=o.tenantId),o.organizationId!==void 0&&(e.organizationId=o.organizationId);let n=o.request??new Request("http://localhost/");return {var:e,env:o.env,req:{raw:n,header:()=>{},query:()=>{},param:()=>{}},set(t,r){e[t]=r;},get(t){return e[t]},executionCtx:void 0}}function Vr(o){return {async get(e){let n=await o.get(e);return n?n.data:void 0},async set(e,n,t){let r=t?Math.ceil(t/1e3):void 0;await o.set(e,n,r?{ttl:r}:void 0);}}}var Kr=[["create","post",""],["list","get",""],["batchCreate","post","/batch"],["batchUpdate","patch","/batch"],["batchDelete","delete","/batch"],["batchRestore","post","/batch/restore"],["batchUpsert","post","/batch/upsert"],["search","get","/search"],["aggregate","get","/aggregate"],["export","get","/export"],["import","post","/import"],["upsert","post","/upsert"],["read","get","/:id"],["update","patch","/:id"],["delete","delete","/:id"],["restore","post","/:id/restore"],["clone","post","/:id/clone"]];function $r(o){return o.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,"{$1}")}function Gr(o,e){let t=`/${o}/${e}`.replace(/\/{2,}/g,"/");return t.length>1&&t.endsWith("/")?t.slice(0,-1):t}function Jr(o,e={}){let n=e.basePath??"",t=e.tag,r=new OpenAPIHono,m=0;for(let[c,i,u]of Kr){let a=o[c];if(!a)continue;let p=new a().getSchema(),g=t!==void 0?{...p,tags:[t]}:p,M=Gr(n,$r(u)),w=createRoute({...g,method:i,path:M,responses:g.responses??{200:{description:"Success",content:{"application/json":{schema:z.unknown()}}}}});r.openapi(w,()=>new Response),m+=1;}return m===0?{}:r.getOpenAPI31Document({openapi:"3.1.0",info:{title:"hono-crud",version:"1.0.0"}}).paths??{}}var ce=o=>{if(o instanceof ZodError)return b.fromZodError(o)};function Qr(o={}){let{mappers:e=[],hooks:n=[],includeRequestId:t=true,includeStackTrace:r=false,defaultErrorCode:m="INTERNAL_ERROR",defaultErrorMessage:f="An internal error occurred",logUnmappedErrors:h=true,onHookError:c,responseEnvelope:i}=o,u=[...e,ce];return async(a$2,s)=>{let p,g=false;if(a$2 instanceof a)p=a$2,g=true;else if(a$2 instanceof HTTPException)p=new a(a$2.message,a$2.status,"HTTP_ERROR"),g=true;else {for(let l of u)try{let k=await l(a$2,s);if(k){p=k,g=!0;break}}catch{}g||(h&&b$1().error("Unmapped error",{error:a$2 instanceof Error?a$2.message:String(a$2)}),p=new a(f,500,m));}for(let l of n)try{let k=l(a$2,s,p);k instanceof Promise&&k.catch(B=>{c&&c(B,a$2,s);});}catch(k){c&&c(k,a$2,s);}let M=p.toJSON();if(t){let l=T(s);l&&(M.error.requestId=l);}r&&a$2.stack&&(M.error.stack=a$2.stack);let w=ue(s,i),C=w?w.error(M.error):M;return a$1(s,C,p.status)}}function ue(o,e){return o?.var?.[q$2]??e}var S=new Map,ta=["password","token","secret","apiKey","creditCard","ssn"];function v(o,e){if(o==null||typeof o!="object")return o;if(Array.isArray(o))return o.map(t=>v(t,e));let n={};for(let[t,r]of Object.entries(o))e.includes(t)||(n[t]=typeof r=="object"&&r!==null?v(r,e):r);return n}function oa(o){let{table:e,events:n,emitter:t,filter:r,heartbeatInterval:m=3e4,maxConnections:f=1e3,connectionTimeout:h=3e5,excludeFields:c=ta}=o;return i=>{let u=d$1(i,t);if(!u)return i.json({success:false,error:{code:"EVENT_EMITTER_NOT_CONFIGURED",message:"Event emitter not configured"}},500);let a=S.get(e)||0;return a>=f?i.json({success:false,error:{code:"TOO_MANY_CONNECTIONS",message:"Too many SSE connections"}},503):(S.set(e,a+1),streamSSE(i,async s=>{let p,g=async l=>{if(n&&n.length>0&&!n.includes(l.type)||r&&!r(l,i))return;let k=c.length>0?v(l.data,c):l.data,B=l.previousData&&c.length>0?v(l.previousData,c):l.previousData;try{await s.writeSSE({event:`${l.table}.${l.type}`,data:JSON.stringify({type:l.type,table:l.table,recordId:l.recordId,data:k,previousData:B,timestamp:l.timestamp}),id:`${l.table}-${l.recordId}-${Date.now()}`});}catch{}};p=u.onTable(e,g);let M=()=>{p.unsubscribe();let l=S.get(e)||1;l<=1?S.delete(e):S.set(e,l-1);};s.onAbort(()=>{M();});let w=Date.now(),C=w;for(;!s.closed;){await s.sleep(1e3);let l=Date.now();if(l-w>=h){s.abort();break}if(l-C>=m){C=l;try{await s.writeSSE({event:"heartbeat",data:JSON.stringify({timestamp:new Date().toISOString()})});}catch{break}}}}))}}function na(o,e,n,t={}){let r=e.endsWith("/")?e.slice(0,-1):e,m=o,{middlewares:f=[],endpointMiddlewares:h={},responseEnvelope:c}=t,i=c?async(s,p)=>{b$2(s,q$2,c),await p();}:void 0,u=s=>{let p=n[s],g=p&&"_middlewares"in p?p._middlewares||[]:[];return [...i?[i]:[],...f,...h[s]||[],...g]},a=(s,p,g,M)=>{let w=u(g),C=m[s];w.length>0?C(p,...w,M):C(p,M);};n.create&&a("post",r,"create",n.create),n.list&&a("get",r,"list",n.list),n.batchCreate&&a("post",`${r}/batch`,"batchCreate",n.batchCreate),n.batchUpdate&&a("patch",`${r}/batch`,"batchUpdate",n.batchUpdate),n.batchDelete&&a("delete",`${r}/batch`,"batchDelete",n.batchDelete),n.batchRestore&&a("post",`${r}/batch/restore`,"batchRestore",n.batchRestore),n.batchUpsert&&a("post",`${r}/batch/upsert`,"batchUpsert",n.batchUpsert),n.search&&a("get",`${r}/search`,"search",n.search),n.aggregate&&a("get",`${r}/aggregate`,"aggregate",n.aggregate),n.export&&a("get",`${r}/export`,"export",n.export),n.import&&a("post",`${r}/import`,"import",n.import),n.upsert&&a("post",`${r}/upsert`,"upsert",n.upsert),n.read&&a("get",`${r}/:id`,"read",n.read),n.update&&a("patch",`${r}/:id`,"update",n.update),n.delete&&a("delete",`${r}/:id`,"delete",n.delete),n.restore&&a("post",`${r}/:id/restore`,"restore",n.restore),n.clone&&a("post",`${r}/:id/clone`,"clone",n.clone);}function q(o){return {content:{"application/json":{schema:o}}}}function ra(o){return {description:"Success",...q({type:"object",properties:{success:{type:"boolean",enum:[true]},result:o},required:["success","result"]})}}function aa(o="Error"){return {description:o,...q({type:"object",properties:{success:{type:"boolean",enum:[false]},error:{type:"object",properties:{code:{type:"string"},message:{type:"string"},details:{}},required:["code","message"]}},required:["success","error"]})}}function Z(o,e){return {content:{"application/json":{schema:o}},description:e}}function ia(o,e){return {content:{"application/json":{schema:o}},description:e,required:true}}var me=z.object({code:z.string(),path:z.array(z.union([z.string(),z.number()])),message:z.string()}),I=z.object({success:z.literal(false),error:z.object({name:z.literal("ZodError"),issues:z.array(me)})});function sa(o){return I}function da(...o){return I}var la=(o,e)=>{if(!o.success)return e.json({success:false,error:{name:"ZodError",issues:o.error.issues}},422)};function pa(o,e=422){return (n,t)=>{if(!n.success)return t.json(o(n.error),e)}}var fe=z.object({success:z.literal(false),error:z.object({message:z.string(),code:z.string().optional()})});function y(o){return Z(fe,o)}var ca={badRequest:y("Bad request"),unauthorized:y("Unauthorized"),forbidden:y("Forbidden"),notFound:y("Resource not found"),conflict:y("Resource conflict"),validationError:Z(I,"Validation error"),internalError:y("Internal server error")};function ua(o){return async(e,n)=>{o.cache&&e.set("cacheStorage",o.cache),o.rateLimit&&e.set("rateLimitStorage",o.rateLimit),o.audit&&e.set("auditStorage",o.audit),o.versioning&&e.set("versioningStorage",o.versioning),o.logging&&e.set("loggingStorage",o.logging),o.idempotency&&e.set("idempotencyStorage",o.idempotency),o.events&&e.set("eventEmitter",o.events),await n();}}function d(o,e){let n=e.middlewares??[],t=e.extras,r=e.schema??{},m=Array.isArray(r.tags)&&r.tags.length>0,f=e.meta.model.tag??e.meta.model.tableName,h=m?r:{...r,tags:[f]};return class extends o{static _middlewares=n;constructor(){super(),t&&Object.assign(this,t);}_meta=e.meta;schema=h;beforeHookMode=e.beforeHookMode??"sequential";afterHookMode=e.afterHookMode??"sequential";allowNestedCreate=e.allowNestedCreate??[];lookupField=e.lookupField??"id";additionalFilters=e.additionalFilters;allowedUpdateFields=e.allowedUpdateFields;blockedUpdateFields=e.blockedUpdateFields;allowNestedWrites=e.allowNestedWrites??[];includeCascadeResults=e.includeCascadeResults??false;filterFields=e.filterFields??[];filterConfig=e.filterConfig;searchFields=e.searchFields??[];searchFieldName=e.searchFieldName??"search";sortFields=e.sortFields??[];defaultSort=e.defaultSort;defaultPerPage=e.defaultPerPage??20;maxPerPage=e.maxPerPage??100;allowedIncludes=e.allowedIncludes??[];fieldSelectionEnabled=e.fieldSelectionEnabled??false;allowedSelectFields=e.allowedSelectFields??[];blockedSelectFields=e.blockedSelectFields??[];alwaysIncludeFields=e.alwaysIncludeFields??[];defaultSelectFields=e.defaultSelectFields??[];getBodySchema(){return e.bodySchema?e.bodySchema:super.getBodySchema()}async before(...i){return e.before?e.before(...i):super.before(...i)}async after(...i){return e.after?e.after(...i):super.after(...i)}transform(i){return e.transform?e.transform(i):super.transform(i)}}}function ma(o,e){return d(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,before:o.before,after:o.after,beforeHookMode:o.beforeHookMode,afterHookMode:o.afterHookMode,allowNestedCreate:o.allowNestedCreate})}function fa(o,e){let n=o.defaultSort??(o.defaultOrderBy?{field:o.defaultOrderBy,order:o.defaultOrderDirection??"asc"}:void 0);return d(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,after:o.after,transform:o.transform,filterFields:o.filterFields,filterConfig:o.filterConfig,searchFields:o.searchFields,searchFieldName:o.searchFieldName,sortFields:o.sortFields??o.orderByFields,defaultSort:n,defaultPerPage:o.defaultPerPage,maxPerPage:o.maxPerPage,allowedIncludes:o.allowedIncludes,fieldSelectionEnabled:o.fieldSelectionEnabled,allowedSelectFields:o.allowedSelectFields,blockedSelectFields:o.blockedSelectFields,alwaysIncludeFields:o.alwaysIncludeFields,defaultSelectFields:o.defaultSelectFields})}function ha(o,e){return d(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,after:o.after,transform:o.transform,lookupField:o.lookupField,additionalFilters:o.additionalFilters,allowedIncludes:o.allowedIncludes,fieldSelectionEnabled:o.fieldSelectionEnabled,allowedSelectFields:o.allowedSelectFields,blockedSelectFields:o.blockedSelectFields,alwaysIncludeFields:o.alwaysIncludeFields,defaultSelectFields:o.defaultSelectFields})}function ga(o,e){return d(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,before:o.before,after:o.after,transform:o.transform,beforeHookMode:o.beforeHookMode,afterHookMode:o.afterHookMode,lookupField:o.lookupField,additionalFilters:o.additionalFilters,allowedUpdateFields:o.allowedUpdateFields,blockedUpdateFields:o.blockedUpdateFields,allowNestedWrites:o.allowNestedWrites})}function Ea(o,e){return d(e,{meta:o.meta,schema:o.schema,middlewares:o.middlewares,before:o.before,after:o.after,beforeHookMode:o.beforeHookMode,afterHookMode:o.afterHookMode,lookupField:o.lookupField,additionalFilters:o.additionalFilters,includeCascadeResults:o.includeCascadeResults})}var R=class{constructor(e){this.meta=e;}_schema={};_before;_after;_beforeHookMode="sequential";_afterHookMode="sequential";_allowNestedCreate=[];_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}before(e){return this._before=e,this}after(e){return this._after=e,this}beforeMode(e){return this._beforeHookMode=e,this}afterMode(e){return this._afterHookMode=e,this}nestedCreate(...e){return this._allowNestedCreate=e,this}build(e){return d(e,{meta:this.meta,schema:this._schema,before:this._before,after:this._after,beforeHookMode:this._beforeHookMode,afterHookMode:this._afterHookMode,allowNestedCreate:this._allowNestedCreate,middlewares:this._middlewares})}},A=class{constructor(e){this.meta=e;}_schema={};_filterFields=[];_filterConfig;_searchFields=[];_searchFieldName="search";_sortFields=[];_defaultSort;_defaultPerPage=20;_maxPerPage=100;_allowedIncludes=[];_fieldSelectionEnabled=false;_allowedSelectFields=[];_blockedSelectFields=[];_alwaysIncludeFields=[];_defaultSelectFields=[];_after;_transform;_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}filter(...e){return this._filterFields=e,this}filterWith(e){return this._filterConfig=e,this}search(...e){return this._searchFields=e,this}searchParam(e){return this._searchFieldName=e,this}sortable(...e){return this._sortFields=e,this}orderBy(...e){return this.sortable(...e)}defaultSort(e,n="asc"){return this._defaultSort={field:e,order:n},this}defaultOrder(e,n="asc"){return this.defaultSort(e,n)}pagination(e,n){return this._defaultPerPage=e,n!==void 0&&(this._maxPerPage=n),this}include(...e){return this._allowedIncludes=e,this}fieldSelection(e){return this._fieldSelectionEnabled=true,e?.allowed&&(this._allowedSelectFields=e.allowed),e?.blocked&&(this._blockedSelectFields=e.blocked),e?.alwaysInclude&&(this._alwaysIncludeFields=e.alwaysInclude),e?.defaults&&(this._defaultSelectFields=e.defaults),this}after(e){return this._after=e,this}transform(e){return this._transform=e,this}build(e){return d(e,{meta:this.meta,schema:this._schema,filterFields:this._filterFields,filterConfig:this._filterConfig,searchFields:this._searchFields,searchFieldName:this._searchFieldName,sortFields:this._sortFields,defaultSort:this._defaultSort,defaultPerPage:this._defaultPerPage,maxPerPage:this._maxPerPage,allowedIncludes:this._allowedIncludes,fieldSelectionEnabled:this._fieldSelectionEnabled,allowedSelectFields:this._allowedSelectFields,blockedSelectFields:this._blockedSelectFields,alwaysIncludeFields:this._alwaysIncludeFields,defaultSelectFields:this._defaultSelectFields,after:this._after,transform:this._transform,middlewares:this._middlewares})}},H=class{constructor(e){this.meta=e;}_schema={};_lookupField="id";_additionalFilters;_allowedIncludes=[];_fieldSelectionEnabled=false;_allowedSelectFields=[];_blockedSelectFields=[];_alwaysIncludeFields=[];_defaultSelectFields=[];_after;_transform;_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}lookupField(e){return this._lookupField=e,this}additionalFilters(...e){return this._additionalFilters=e,this}include(...e){return this._allowedIncludes=e,this}fieldSelection(e){return this._fieldSelectionEnabled=true,e?.allowed&&(this._allowedSelectFields=e.allowed),e?.blocked&&(this._blockedSelectFields=e.blocked),e?.alwaysInclude&&(this._alwaysIncludeFields=e.alwaysInclude),e?.defaults&&(this._defaultSelectFields=e.defaults),this}after(e){return this._after=e,this}transform(e){return this._transform=e,this}build(e){return d(e,{meta:this.meta,schema:this._schema,lookupField:this._lookupField,additionalFilters:this._additionalFilters,allowedIncludes:this._allowedIncludes,fieldSelectionEnabled:this._fieldSelectionEnabled,allowedSelectFields:this._allowedSelectFields,blockedSelectFields:this._blockedSelectFields,alwaysIncludeFields:this._alwaysIncludeFields,defaultSelectFields:this._defaultSelectFields,after:this._after,transform:this._transform,middlewares:this._middlewares})}},F=class{constructor(e){this.meta=e;}_schema={};_lookupField="id";_additionalFilters;_allowedUpdateFields;_blockedUpdateFields;_allowNestedWrites=[];_before;_after;_beforeHookMode="sequential";_afterHookMode="sequential";_transform;_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}lookupField(e){return this._lookupField=e,this}additionalFilters(...e){return this._additionalFilters=e,this}allowedFields(...e){return this._allowedUpdateFields=e,this}blockedFields(...e){return this._blockedUpdateFields=e,this}nestedWrites(...e){return this._allowNestedWrites=e,this}before(e){return this._before=e,this}after(e){return this._after=e,this}beforeMode(e){return this._beforeHookMode=e,this}afterMode(e){return this._afterHookMode=e,this}transform(e){return this._transform=e,this}build(e){return d(e,{meta:this.meta,schema:this._schema,lookupField:this._lookupField,additionalFilters:this._additionalFilters,allowedUpdateFields:this._allowedUpdateFields,blockedUpdateFields:this._blockedUpdateFields,allowNestedWrites:this._allowNestedWrites,before:this._before,after:this._after,beforeHookMode:this._beforeHookMode,afterHookMode:this._afterHookMode,transform:this._transform,middlewares:this._middlewares})}},_=class{constructor(e){this.meta=e;}_schema={};_lookupField="id";_additionalFilters;_includeCascadeResults=false;_before;_after;_beforeHookMode="sequential";_afterHookMode="sequential";_middlewares=[];middleware(...e){return this._middlewares.push(...e),this}tags(...e){return this._schema.tags=e,this}summary(e){return this._schema.summary=e,this}description(e){return this._schema.description=e,this}lookupField(e){return this._lookupField=e,this}additionalFilters(...e){return this._additionalFilters=e,this}includeCascade(e=true){return this._includeCascadeResults=e,this}before(e){return this._before=e,this}after(e){return this._after=e,this}beforeMode(e){return this._beforeHookMode=e,this}afterMode(e){return this._afterHookMode=e,this}build(e){return d(e,{meta:this.meta,schema:this._schema,lookupField:this._lookupField,additionalFilters:this._additionalFilters,includeCascadeResults:this._includeCascadeResults,before:this._before,after:this._after,beforeHookMode:this._beforeHookMode,afterHookMode:this._afterHookMode,middlewares:this._middlewares})}},j=class{constructor(e){this.meta=e;}create(){return new R(this.meta)}list(){return new A(this.meta)}read(){return new H(this.meta)}update(){return new F(this.meta)}delete(){return new _(this.meta)}};function Ma(o){return new j(o)}var wa={CreateEndpoint:g,ListEndpoint:k,ReadEndpoint:h,UpdateEndpoint:i,DeleteEndpoint:j$1,SearchEndpoint:y$1,AggregateEndpoint:x,RestoreEndpoint:l,BatchCreateEndpoint:m,BatchUpdateEndpoint:n,BatchDeleteEndpoint:o,BatchRestoreEndpoint:p,BatchUpsertEndpoint:q$1,ExportEndpoint:z$1,ImportEndpoint:A$1,UpsertEndpoint:s,CloneEndpoint:r};function ka(o,e){let n={};if(o.create!==void 0){let t=o.create;n.create=d(e.CreateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,allowNestedCreate:t.nestedCreate,before:t.hooks?.before,after:t.hooks?.after});}if(o.list!==void 0){let t=o.list;n.list=d(e.ListEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,filterFields:t.filtering?.fields,filterConfig:t.filtering?.config,searchFields:t.search?.fields,searchFieldName:t.search?.paramName,sortFields:t.sorting?.fields,defaultSort:t.sorting?.default?{field:t.sorting.default,order:t.sorting.defaultOrder??t.sorting.defaultDirection??"asc"}:void 0,defaultPerPage:t.pagination?.defaultPerPage,maxPerPage:t.pagination?.maxPerPage,allowedIncludes:t.includes,fieldSelectionEnabled:t.fieldSelection?.enabled,allowedSelectFields:t.fieldSelection?.allowed,blockedSelectFields:t.fieldSelection?.blocked,alwaysIncludeFields:t.fieldSelection?.alwaysInclude,defaultSelectFields:t.fieldSelection?.defaults,after:t.hooks?.after,transform:t.hooks?.transform});}if(o.read!==void 0){let t=o.read;n.read=d(e.ReadEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,lookupField:t.lookupField,additionalFilters:t.additionalFilters,allowedIncludes:t.includes,fieldSelectionEnabled:t.fieldSelection?.enabled,allowedSelectFields:t.fieldSelection?.allowed,blockedSelectFields:t.fieldSelection?.blocked,alwaysIncludeFields:t.fieldSelection?.alwaysInclude,defaultSelectFields:t.fieldSelection?.defaults,after:t.hooks?.after,transform:t.hooks?.transform});}if(o.update!==void 0){let t=o.update;n.update=d(e.UpdateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,lookupField:t.lookupField,additionalFilters:t.additionalFilters,allowedUpdateFields:t.fields?.allowed,blockedUpdateFields:t.fields?.blocked,allowNestedWrites:t.nestedWrites,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,transform:t.hooks?.transform});}if(o.delete!==void 0){let t=o.delete;n.delete=d(e.DeleteEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,lookupField:t.lookupField,additionalFilters:t.additionalFilters,includeCascadeResults:t.includeCascadeResults,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after});}if(o.search!==void 0&&e.SearchEndpoint){let t=o.search;n.search=d(e.SearchEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,after:t.hooks?.after,extras:{...t.fields!==void 0?{searchFields:t.fields}:{},...t.mode!==void 0?{defaultMode:t.mode}:{}}});}if(o.aggregate!==void 0&&e.AggregateEndpoint){let t=o.aggregate;n.aggregate=d(e.AggregateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,after:t.hooks?.after,extras:{...t.fields!==void 0?{filterFields:t.fields}:{}}});}if(o.restore!==void 0&&e.RestoreEndpoint){let t=o.restore;n.restore=d(e.RestoreEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after});}if(o.batchCreate!==void 0&&e.BatchCreateEndpoint){let t=o.batchCreate;n.batchCreate=d(e.BatchCreateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchUpdate!==void 0&&e.BatchUpdateEndpoint){let t=o.batchUpdate;n.batchUpdate=d(e.BatchUpdateEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchDelete!==void 0&&e.BatchDeleteEndpoint){let t=o.batchDelete;n.batchDelete=d(e.BatchDeleteEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchRestore!==void 0&&e.BatchRestoreEndpoint){let t=o.batchRestore;n.batchRestore=d(e.BatchRestoreEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{}}});}if(o.batchUpsert!==void 0&&e.BatchUpsertEndpoint){let t=o.batchUpsert,r=typeof t.conflictTarget=="string"?[t.conflictTarget]:t.conflictTarget;n.batchUpsert=d(e.BatchUpsertEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxBatchSize!==void 0?{maxBatchSize:t.maxBatchSize}:{},...r!==void 0?{upsertKeys:r}:{}}});}if(o.export!==void 0&&e.ExportEndpoint){let t=o.export;n.export=d(e.ExportEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,extras:{...t.maxRows!==void 0?{maxExportRecords:t.maxRows}:{},...t.formats!==void 0&&t.formats.length>0?{defaultFormat:t.formats[0]}:{}}});}if(o.import!==void 0&&e.ImportEndpoint){let t=o.import;n.import=d(e.ImportEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.maxRows!==void 0?{maxBatchSize:t.maxRows}:{}}});}if(o.upsert!==void 0&&e.UpsertEndpoint){let t=o.upsert,r=typeof t.conflictTarget=="string"?[t.conflictTarget]:t.conflictTarget;n.upsert=d(e.UpsertEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,bodySchema:t.bodySchema,beforeHookMode:t.hooks?.beforeMode,afterHookMode:t.hooks?.afterMode,before:t.hooks?.before,after:t.hooks?.after,extras:{...r!==void 0?{upsertKeys:r}:{}}});}if(o.clone!==void 0&&e.CloneEndpoint){let t=o.clone;n.clone=d(e.CloneEndpoint,{meta:o.meta,schema:t.openapi,middlewares:t.middlewares,before:t.hooks?.before,after:t.hooks?.after,extras:{...t.fieldsToReset!==void 0?{excludeFromClone:t.fieldsToReset}:{}}});}return n}
|
|
2
|
+
export{R as CreateBuilder,j as CrudBuilder,_ as DeleteBuilder,P as HonoOpenAPIHandler,fe as HttpErrorSchema,A as ListBuilder,wa as MemoryAdapters,H as ReadBuilder,F as UpdateBuilder,I as ZodErrorSchema,me as ZodIssueSchema,Dr as buildPerTenantOpenApi,ca as commonResponses,q as contentJson,ma as createCreate,ua as createCrudMiddleware,Ea as createDelete,Qr as createErrorHandler,sa as createErrorSchema,fa as createList,da as createOneOfErrorSchema,ha as createRead,oa as createSubscribeHandler,ga as createUpdate,pa as createValidationHook,Ma as crud,ka as defineEndpoints,aa as errorResponse,jr as fromHono,V as getHandlerForApp,y as httpErrorContent,Z as jsonContent,ia as jsonContentRequired,la as openApiValidationHook,na as registerCrud,ue as resolveErrorEnvelope,ra as successResponse,Jr as toOpenApiPaths,Vr as wrapCacheStorageForOpenApi,ce as zodErrorMapper};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Env, Context } from 'hono';
|
|
2
2
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
3
3
|
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
4
|
-
import { O as OpenAPIRouteSchema, R as RouteOptions, V as ValidatedData, a as ResponseEnvelope, b as ResponseEnvelopeInfo } from './types-
|
|
4
|
+
import { O as OpenAPIRouteSchema, R as RouteOptions, V as ValidatedData, a as ResponseEnvelope, b as ResponseEnvelopeInfo } from './types-QHT43lek.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Base class for OpenAPI routes.
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { L as LoggingStorage } from '../types-SnlsH9UT.js';
|
|
|
4
4
|
import { C as CacheStorage } from '../types-BdRvpp1z.js';
|
|
5
5
|
import { AuditLogStorage } from '../audit/index.js';
|
|
6
6
|
import { VersioningStorage } from '../versioning/index.js';
|
|
7
|
-
import { aY as APIKeyStorage } from '../types-
|
|
7
|
+
import { aY as APIKeyStorage } from '../types-QHT43lek.js';
|
|
8
8
|
import { I as IdempotencyStorage } from '../types-BNui1SQl.js';
|
|
9
9
|
import { C as CrudEventEmitter } from '../emitter-vW4MflrJ.js';
|
|
10
10
|
export { S as StorageRegistry, c as createNullableRegistry, a as createRegistryWithDefault } from '../registry-PNJjvSvm.js';
|
|
@@ -1087,6 +1087,23 @@ interface SchemaResolveContext {
|
|
|
1087
1087
|
interface Model<T extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TTable = unknown> {
|
|
1088
1088
|
/** Database table name */
|
|
1089
1089
|
tableName: string;
|
|
1090
|
+
/**
|
|
1091
|
+
* Optional OpenAPI tag / API group for this resource.
|
|
1092
|
+
*
|
|
1093
|
+
* This is the canonical "what API group does this resource belong to"
|
|
1094
|
+
* home. It flows into every generated endpoint's
|
|
1095
|
+
* `OpenAPIRouteSchema.tags` (and therefore the emitted OpenAPI
|
|
1096
|
+
* operations) unless a per-endpoint `openapi.tags` override is set,
|
|
1097
|
+
* which always wins. When unset, the effective tag falls back to
|
|
1098
|
+
* `tableName`, so consumers that never set explicit tags get stable,
|
|
1099
|
+
* resource-grouped documentation by default.
|
|
1100
|
+
*
|
|
1101
|
+
* @example
|
|
1102
|
+
* ```ts
|
|
1103
|
+
* defineModel({ tableName: 'users', tag: 'Accounts', schema, primaryKeys: ['id'] });
|
|
1104
|
+
* ```
|
|
1105
|
+
*/
|
|
1106
|
+
tag?: string;
|
|
1090
1107
|
/** Zod schema for validation and type inference */
|
|
1091
1108
|
schema: T;
|
|
1092
1109
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Env } from 'hono';
|
|
2
|
-
import { e as VersioningConfig, f as VersionHistoryEntry, g as AuditFieldChange } from '../types-
|
|
2
|
+
import { e as VersioningConfig, f as VersionHistoryEntry, g as AuditFieldChange } from '../types-QHT43lek.js';
|
|
3
3
|
import { S as StorageRegistry } from '../registry-PNJjvSvm.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../types-B5wq2iKZ.js';
|