crudora 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -165,6 +165,18 @@ declare class Repository<T extends Model> {
165
165
  transaction<R>(fn: (trx: Repository<T>) => Promise<R>): Promise<R>;
166
166
  }
167
167
 
168
+ interface OpenApiInfo {
169
+ title?: string;
170
+ version?: string;
171
+ description?: string;
172
+ }
173
+ declare class OpenApiGenerator {
174
+ static generate(models: Map<string, ModelConstructor>, customRoutes: Array<{
175
+ method: string;
176
+ path: string;
177
+ }>, basePath: string, info?: OpenApiInfo): Record<string, any>;
178
+ }
179
+
168
180
  type FieldType = 'string' | 'text' | 'integer' | 'number' | 'boolean' | 'date' | 'uuid' | 'decimal' | 'json' | 'enum' | 'bigint' | 'serial' | 'array';
169
181
  interface FieldOptions {
170
182
  type: FieldType;
@@ -241,6 +253,7 @@ declare class Crudora {
241
253
  */
242
254
  getTable<T extends Model>(modelClass: ModelConstructor<T>): any;
243
255
  generateDrizzleSchema(): string;
256
+ generateOpenApiSpec(basePath?: string, info?: OpenApiInfo): Record<string, any>;
244
257
  getValidationSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<Partial<T>>;
245
258
  getStrictValidationSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<T>;
246
259
  get(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
@@ -266,6 +279,98 @@ interface RateLimitConfig {
266
279
  */
267
280
  keyGenerator?: (req: any) => string;
268
281
  }
282
+ /**
283
+ * Configuration options forwarded to `@scalar/express-api-reference`.
284
+ * All known options are typed for autocomplete. Any additional option is also
285
+ * accepted via the index signature.
286
+ *
287
+ * Full reference: https://github.com/scalar/scalar/blob/main/documentation/configuration.md
288
+ */
289
+ interface ScalarConfig {
290
+ /**
291
+ * UI color theme.
292
+ * @default 'default'
293
+ */
294
+ theme?: 'default' | 'alternate' | 'moon' | 'purple' | 'solarized' | 'mars' | 'deepSpace' | 'none';
295
+ /**
296
+ * Page layout style.
297
+ * @default 'modern'
298
+ */
299
+ layout?: 'modern' | 'classic';
300
+ /** Enable dark mode by default. */
301
+ darkMode?: boolean;
302
+ /** Force light or dark mode, ignoring system preference. */
303
+ forceDarkModeState?: 'dark' | 'light';
304
+ /** Hide the dark-mode toggle button. */
305
+ hideDarkModeToggle?: boolean;
306
+ /** Hide the model/schema section. */
307
+ hideModels?: boolean;
308
+ /** Hide the "Download" button in the spec header. */
309
+ hideDownloadButton?: boolean;
310
+ /** Hide the "Test Request" (client) button on each operation. */
311
+ hideClientButton?: boolean;
312
+ /** Show or hide the sidebar. @default true */
313
+ showSidebar?: boolean;
314
+ /** Expand all operation tags on load. */
315
+ defaultOpenAllTags?: boolean;
316
+ /** Inject custom CSS into the Scalar page. */
317
+ customCss?: string;
318
+ /** Custom favicon URL or data URI. */
319
+ favicon?: string;
320
+ /** Keyboard shortcut that opens the search dialog. @default 'k' */
321
+ searchHotKey?: string;
322
+ /**
323
+ * Override the server list shown in the UI.
324
+ * Each entry is `{ url: string; description?: string }`.
325
+ */
326
+ servers?: Array<{
327
+ url: string;
328
+ description?: string;
329
+ [key: string]: any;
330
+ }>;
331
+ /**
332
+ * Default values pre-filled in the "Try it out" form — useful for dev tokens.
333
+ * Shape depends on your security scheme; see Scalar docs for details.
334
+ */
335
+ authentication?: Record<string, any>;
336
+ /**
337
+ * HTML `<meta>` / Open Graph values for the docs page.
338
+ * Accepts `title`, `description`, `ogDescription`, `ogTitle`, `ogImage`, `twitterTitle`.
339
+ */
340
+ metaData?: {
341
+ title?: string;
342
+ description?: string;
343
+ ogDescription?: string;
344
+ ogTitle?: string;
345
+ ogImage?: string;
346
+ twitterTitle?: string;
347
+ [key: string]: any;
348
+ };
349
+ /** Use Scalar's default font stack. @default true */
350
+ withDefaultFonts?: boolean;
351
+ /** Allow users to edit the spec inline (read-only by default). */
352
+ isEditable?: boolean;
353
+ /** Any other Scalar option not listed above. */
354
+ [key: string]: any;
355
+ }
356
+ interface DocsConfig {
357
+ /** Path where the UI and spec are served. Default: `'/docs'`. */
358
+ path?: string;
359
+ /** OpenAPI `info.title`. Default: `'Crudora API'`. */
360
+ title?: string;
361
+ /** OpenAPI `info.version`. Default: `'1.0.0'`. */
362
+ version?: string;
363
+ /** OpenAPI `info.description`. */
364
+ description?: string;
365
+ /**
366
+ * Options forwarded directly to `apiReference()` from `@scalar/express-api-reference`.
367
+ * Fully typed for autocomplete — see `ScalarConfig` for all available fields.
368
+ *
369
+ * @example
370
+ * scalar: { theme: 'purple', darkMode: true, layout: 'classic' }
371
+ */
372
+ scalar?: ScalarConfig;
373
+ }
269
374
  interface CrudoraServerConfig {
270
375
  port?: number;
271
376
  /**
@@ -319,6 +424,19 @@ interface CrudoraServerConfig {
319
424
  * - `false`: disable entirely.
320
425
  */
321
426
  healthCheck?: boolean | string;
427
+ /**
428
+ * Built-in API documentation powered by Scalar.
429
+ * Requires `@scalar/express-api-reference` to be installed separately.
430
+ *
431
+ * - `false` (default): disabled.
432
+ * - `true`: mount UI at `GET /docs` and spec at `GET /docs/openapi.json`.
433
+ * - `string`: custom base path, e.g. `'/api-docs'`.
434
+ * - `DocsConfig`: full control — path, OpenAPI info, Scalar theme/layout/etc.
435
+ *
436
+ * @example
437
+ * docs: { path: '/docs', title: 'My API', scalar: { theme: 'purple' } }
438
+ */
439
+ docs?: boolean | string | DocsConfig;
322
440
  }
323
441
  declare class CrudoraServer {
324
442
  private app;
@@ -435,4 +553,4 @@ declare function BelongsTo(model: () => any, foreignKey: string, ownerKey?: stri
435
553
  declare function BelongsToMany(model: () => any, pivotModel: () => any, pivotForeignKey: string, pivotRelatedKey: string, localKey?: string): (target: any, propertyKey: string) => void;
436
554
  declare function getRelationMetadata(target: any): Record<string, RelationDefinition>;
437
555
 
438
- export { BelongsTo, BelongsToMany, Crudora, type CrudoraLogger, CrudoraServer, type CrudoraServerConfig, type CursorPaginationOptions, type CursorResult, type Dialect, DrizzleTableBuilder, Field, type FieldOptions, type FieldType, type FindAllOptions, type FindByIdOptions, HasMany, HasOne, Model, type ModelConstructor, type ModelOptions, NotFoundError, type RateLimitConfig, type RelationDefinition, type RelationType, Repository, SchemaGenerator, ValidationGenerator, getFieldMetadata, getRelationMetadata };
556
+ export { BelongsTo, BelongsToMany, Crudora, type CrudoraLogger, CrudoraServer, type CrudoraServerConfig, type CursorPaginationOptions, type CursorResult, type Dialect, type DocsConfig, DrizzleTableBuilder, Field, type FieldOptions, type FieldType, type FindAllOptions, type FindByIdOptions, HasMany, HasOne, Model, type ModelConstructor, type ModelOptions, NotFoundError, OpenApiGenerator, type OpenApiInfo, type RateLimitConfig, type RelationDefinition, type RelationType, Repository, type ScalarConfig, SchemaGenerator, ValidationGenerator, getFieldMetadata, getRelationMetadata };
package/dist/index.d.ts CHANGED
@@ -165,6 +165,18 @@ declare class Repository<T extends Model> {
165
165
  transaction<R>(fn: (trx: Repository<T>) => Promise<R>): Promise<R>;
166
166
  }
167
167
 
168
+ interface OpenApiInfo {
169
+ title?: string;
170
+ version?: string;
171
+ description?: string;
172
+ }
173
+ declare class OpenApiGenerator {
174
+ static generate(models: Map<string, ModelConstructor>, customRoutes: Array<{
175
+ method: string;
176
+ path: string;
177
+ }>, basePath: string, info?: OpenApiInfo): Record<string, any>;
178
+ }
179
+
168
180
  type FieldType = 'string' | 'text' | 'integer' | 'number' | 'boolean' | 'date' | 'uuid' | 'decimal' | 'json' | 'enum' | 'bigint' | 'serial' | 'array';
169
181
  interface FieldOptions {
170
182
  type: FieldType;
@@ -241,6 +253,7 @@ declare class Crudora {
241
253
  */
242
254
  getTable<T extends Model>(modelClass: ModelConstructor<T>): any;
243
255
  generateDrizzleSchema(): string;
256
+ generateOpenApiSpec(basePath?: string, info?: OpenApiInfo): Record<string, any>;
244
257
  getValidationSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<Partial<T>>;
245
258
  getStrictValidationSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<T>;
246
259
  get(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
@@ -266,6 +279,98 @@ interface RateLimitConfig {
266
279
  */
267
280
  keyGenerator?: (req: any) => string;
268
281
  }
282
+ /**
283
+ * Configuration options forwarded to `@scalar/express-api-reference`.
284
+ * All known options are typed for autocomplete. Any additional option is also
285
+ * accepted via the index signature.
286
+ *
287
+ * Full reference: https://github.com/scalar/scalar/blob/main/documentation/configuration.md
288
+ */
289
+ interface ScalarConfig {
290
+ /**
291
+ * UI color theme.
292
+ * @default 'default'
293
+ */
294
+ theme?: 'default' | 'alternate' | 'moon' | 'purple' | 'solarized' | 'mars' | 'deepSpace' | 'none';
295
+ /**
296
+ * Page layout style.
297
+ * @default 'modern'
298
+ */
299
+ layout?: 'modern' | 'classic';
300
+ /** Enable dark mode by default. */
301
+ darkMode?: boolean;
302
+ /** Force light or dark mode, ignoring system preference. */
303
+ forceDarkModeState?: 'dark' | 'light';
304
+ /** Hide the dark-mode toggle button. */
305
+ hideDarkModeToggle?: boolean;
306
+ /** Hide the model/schema section. */
307
+ hideModels?: boolean;
308
+ /** Hide the "Download" button in the spec header. */
309
+ hideDownloadButton?: boolean;
310
+ /** Hide the "Test Request" (client) button on each operation. */
311
+ hideClientButton?: boolean;
312
+ /** Show or hide the sidebar. @default true */
313
+ showSidebar?: boolean;
314
+ /** Expand all operation tags on load. */
315
+ defaultOpenAllTags?: boolean;
316
+ /** Inject custom CSS into the Scalar page. */
317
+ customCss?: string;
318
+ /** Custom favicon URL or data URI. */
319
+ favicon?: string;
320
+ /** Keyboard shortcut that opens the search dialog. @default 'k' */
321
+ searchHotKey?: string;
322
+ /**
323
+ * Override the server list shown in the UI.
324
+ * Each entry is `{ url: string; description?: string }`.
325
+ */
326
+ servers?: Array<{
327
+ url: string;
328
+ description?: string;
329
+ [key: string]: any;
330
+ }>;
331
+ /**
332
+ * Default values pre-filled in the "Try it out" form — useful for dev tokens.
333
+ * Shape depends on your security scheme; see Scalar docs for details.
334
+ */
335
+ authentication?: Record<string, any>;
336
+ /**
337
+ * HTML `<meta>` / Open Graph values for the docs page.
338
+ * Accepts `title`, `description`, `ogDescription`, `ogTitle`, `ogImage`, `twitterTitle`.
339
+ */
340
+ metaData?: {
341
+ title?: string;
342
+ description?: string;
343
+ ogDescription?: string;
344
+ ogTitle?: string;
345
+ ogImage?: string;
346
+ twitterTitle?: string;
347
+ [key: string]: any;
348
+ };
349
+ /** Use Scalar's default font stack. @default true */
350
+ withDefaultFonts?: boolean;
351
+ /** Allow users to edit the spec inline (read-only by default). */
352
+ isEditable?: boolean;
353
+ /** Any other Scalar option not listed above. */
354
+ [key: string]: any;
355
+ }
356
+ interface DocsConfig {
357
+ /** Path where the UI and spec are served. Default: `'/docs'`. */
358
+ path?: string;
359
+ /** OpenAPI `info.title`. Default: `'Crudora API'`. */
360
+ title?: string;
361
+ /** OpenAPI `info.version`. Default: `'1.0.0'`. */
362
+ version?: string;
363
+ /** OpenAPI `info.description`. */
364
+ description?: string;
365
+ /**
366
+ * Options forwarded directly to `apiReference()` from `@scalar/express-api-reference`.
367
+ * Fully typed for autocomplete — see `ScalarConfig` for all available fields.
368
+ *
369
+ * @example
370
+ * scalar: { theme: 'purple', darkMode: true, layout: 'classic' }
371
+ */
372
+ scalar?: ScalarConfig;
373
+ }
269
374
  interface CrudoraServerConfig {
270
375
  port?: number;
271
376
  /**
@@ -319,6 +424,19 @@ interface CrudoraServerConfig {
319
424
  * - `false`: disable entirely.
320
425
  */
321
426
  healthCheck?: boolean | string;
427
+ /**
428
+ * Built-in API documentation powered by Scalar.
429
+ * Requires `@scalar/express-api-reference` to be installed separately.
430
+ *
431
+ * - `false` (default): disabled.
432
+ * - `true`: mount UI at `GET /docs` and spec at `GET /docs/openapi.json`.
433
+ * - `string`: custom base path, e.g. `'/api-docs'`.
434
+ * - `DocsConfig`: full control — path, OpenAPI info, Scalar theme/layout/etc.
435
+ *
436
+ * @example
437
+ * docs: { path: '/docs', title: 'My API', scalar: { theme: 'purple' } }
438
+ */
439
+ docs?: boolean | string | DocsConfig;
322
440
  }
323
441
  declare class CrudoraServer {
324
442
  private app;
@@ -435,4 +553,4 @@ declare function BelongsTo(model: () => any, foreignKey: string, ownerKey?: stri
435
553
  declare function BelongsToMany(model: () => any, pivotModel: () => any, pivotForeignKey: string, pivotRelatedKey: string, localKey?: string): (target: any, propertyKey: string) => void;
436
554
  declare function getRelationMetadata(target: any): Record<string, RelationDefinition>;
437
555
 
438
- export { BelongsTo, BelongsToMany, Crudora, type CrudoraLogger, CrudoraServer, type CrudoraServerConfig, type CursorPaginationOptions, type CursorResult, type Dialect, DrizzleTableBuilder, Field, type FieldOptions, type FieldType, type FindAllOptions, type FindByIdOptions, HasMany, HasOne, Model, type ModelConstructor, type ModelOptions, NotFoundError, type RateLimitConfig, type RelationDefinition, type RelationType, Repository, SchemaGenerator, ValidationGenerator, getFieldMetadata, getRelationMetadata };
556
+ export { BelongsTo, BelongsToMany, Crudora, type CrudoraLogger, CrudoraServer, type CrudoraServerConfig, type CursorPaginationOptions, type CursorResult, type Dialect, type DocsConfig, DrizzleTableBuilder, Field, type FieldOptions, type FieldType, type FindAllOptions, type FindByIdOptions, HasMany, HasOne, Model, type ModelConstructor, type ModelOptions, NotFoundError, OpenApiGenerator, type OpenApiInfo, type RateLimitConfig, type RelationDefinition, type RelationType, Repository, type ScalarConfig, SchemaGenerator, ValidationGenerator, getFieldMetadata, getRelationMetadata };