@magnet-cms/common 0.1.0 → 0.1.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.cjs CHANGED
@@ -92,18 +92,36 @@ function isPackageInstalled(packageName) {
92
92
  }
93
93
  }
94
94
  __name(isPackageInstalled, "isPackageInstalled");
95
- function detectDatabaseAdapter() {
95
+ function detectDatabaseAdapter(dbConfig) {
96
+ if (dbConfig) {
97
+ if ("connectionString" in dbConfig || "dialect" in dbConfig) {
98
+ cachedAdapter = "drizzle";
99
+ return cachedAdapter;
100
+ }
101
+ if ("uri" in dbConfig) {
102
+ cachedAdapter = "mongoose";
103
+ return cachedAdapter;
104
+ }
105
+ }
96
106
  if (cachedAdapter) return cachedAdapter;
97
107
  if (isPackageInstalled("@magnet-cms/adapter-mongoose")) {
98
108
  cachedAdapter = "mongoose";
99
- } else if (isPackageInstalled("@magnet-cms/adapter-typeorm")) {
100
- cachedAdapter = "typeorm";
109
+ } else if (isPackageInstalled("@magnet-cms/adapter-drizzle")) {
110
+ cachedAdapter = "drizzle";
101
111
  } else {
102
- throw new Error("\u274C No supported database adapter found. Install @magnet-cms/adapter-mongoose or @magnet-cms/adapter-typeorm.");
112
+ throw new Error("\u274C No supported database adapter found. Install @magnet-cms/adapter-mongoose or @magnet-cms/adapter-drizzle.");
103
113
  }
104
114
  return cachedAdapter;
105
115
  }
106
116
  __name(detectDatabaseAdapter, "detectDatabaseAdapter");
117
+ function setDatabaseAdapter(adapter) {
118
+ cachedAdapter = adapter;
119
+ }
120
+ __name(setDatabaseAdapter, "setDatabaseAdapter");
121
+ function clearAdapterCache() {
122
+ cachedAdapter = null;
123
+ }
124
+ __name(clearAdapterCache, "clearAdapterCache");
107
125
 
108
126
  // src/utils/get-model-token.util.ts
109
127
  function getModelToken(schema) {
@@ -388,8 +406,10 @@ exports.VERSION_METADATA_KEY = VERSION_METADATA_KEY;
388
406
  exports.ValidationException = ValidationException;
389
407
  exports.Validators = Validators;
390
408
  exports.Version = Version;
409
+ exports.clearAdapterCache = clearAdapterCache;
391
410
  exports.detectDatabaseAdapter = detectDatabaseAdapter;
392
411
  exports.getModelToken = getModelToken;
393
412
  exports.getSchemaOptions = getSchemaOptions;
394
413
  exports.getSchemaToken = getSchemaToken;
395
414
  exports.getSettingToken = getSettingToken;
415
+ exports.setDatabaseAdapter = setDatabaseAdapter;
package/dist/index.d.cts CHANGED
@@ -12,7 +12,7 @@ type ResolveOptions = {
12
12
  };
13
13
  type ResolveInput = (() => Type | [Type]) | ResolveOptions;
14
14
  type PropOptions = {
15
- type?: Type | [Type];
15
+ type?: Type | [Type] | any;
16
16
  description?: string;
17
17
  required?: boolean;
18
18
  unique?: boolean;
@@ -21,6 +21,7 @@ type PropOptions = {
21
21
  intl?: boolean;
22
22
  hidden?: boolean;
23
23
  readonly?: boolean;
24
+ ref?: string;
24
25
  };
25
26
  type BaseSchemaOptions = {
26
27
  timestamps?: boolean;
@@ -112,9 +113,13 @@ type SchemaProperty = {
112
113
  required: boolean;
113
114
  validations: SchemaPropertyValidation[];
114
115
  ui: UIDecoratorOptions;
116
+ ref?: string;
115
117
  };
116
118
  type SchemaMetadata = {
117
119
  name: string;
120
+ className?: string;
121
+ apiName?: string;
122
+ displayName?: string;
118
123
  properties: SchemaProperty[];
119
124
  options?: SchemaOptions;
120
125
  };
@@ -176,6 +181,17 @@ interface JwtAuthConfig {
176
181
  /** Token expiration time (e.g., '7d', '1h') */
177
182
  expiresIn?: string;
178
183
  }
184
+ /**
185
+ * Supabase-specific auth configuration
186
+ */
187
+ interface SupabaseAuthConfig {
188
+ /** Supabase project URL */
189
+ supabaseUrl: string;
190
+ /** Supabase anon/public key */
191
+ supabaseKey: string;
192
+ /** Default role for new users */
193
+ defaultRole?: string;
194
+ }
179
195
  /**
180
196
  * Auth configuration for MagnetModuleOptions
181
197
  */
@@ -184,6 +200,14 @@ interface AuthConfig {
184
200
  strategy?: string;
185
201
  /** JWT-specific configuration */
186
202
  jwt?: JwtAuthConfig;
203
+ /** Supabase-specific configuration (when strategy: 'supabase') */
204
+ supabaseUrl?: string;
205
+ /** Supabase anon/public key */
206
+ supabaseKey?: string;
207
+ /** Supabase service role key (required for admin operations like listUsers) */
208
+ supabaseServiceKey?: string;
209
+ /** Default role for new Supabase users */
210
+ defaultRole?: string;
187
211
  /** Allow extensible config for custom strategies */
188
212
  [key: string]: unknown;
189
213
  }
@@ -259,6 +283,13 @@ declare abstract class AuthStrategy {
259
283
  * @param token - The token to invalidate
260
284
  */
261
285
  logout?(token: string): Promise<void>;
286
+ /**
287
+ * Check if any users exist in the system (optional)
288
+ * Strategies that manage their own user storage should implement this.
289
+ * If not implemented, AuthService will fall back to checking the local database.
290
+ * @returns true if users exist, false otherwise
291
+ */
292
+ hasUsers?(): Promise<boolean>;
262
293
  /**
263
294
  * Get the Passport strategy name (for guards)
264
295
  * Returns the name to use with AuthGuard()
@@ -269,15 +300,21 @@ declare abstract class AuthStrategy {
269
300
  type MongooseConfig = {
270
301
  uri: string;
271
302
  };
272
- type TypeORMConfig = {
273
- type: 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' | 'oracle' | 'mongodb';
274
- host: string;
275
- port: number;
276
- username: string;
277
- password: string;
278
- database: string;
303
+ /**
304
+ * Drizzle ORM configuration for SQL databases.
305
+ * Supports PostgreSQL, MySQL, and SQLite through Drizzle ORM.
306
+ */
307
+ type DrizzleConfig = {
308
+ /** Database connection string */
309
+ connectionString: string;
310
+ /** SQL dialect to use */
311
+ dialect: 'postgresql' | 'mysql' | 'sqlite';
312
+ /** Database driver to use (auto-detected if not specified) */
313
+ driver?: 'pg' | 'neon' | 'mysql2' | 'better-sqlite3';
314
+ /** Enable debug logging */
315
+ debug?: boolean;
279
316
  };
280
- type DBConfig = MongooseConfig | TypeORMConfig;
317
+ type DBConfig = MongooseConfig | DrizzleConfig;
281
318
  declare abstract class DatabaseAdapter {
282
319
  abstract connect(options: MagnetModuleOptions): DynamicModule;
283
320
  abstract forFeature(schemas: Type | Type[]): DynamicModule;
@@ -466,15 +503,27 @@ interface R2StorageConfig extends S3StorageConfig {
466
503
  /** Cloudflare account ID */
467
504
  accountId: string;
468
505
  }
506
+ interface SupabaseStorageConfig {
507
+ /** Supabase project URL */
508
+ supabaseUrl: string;
509
+ /** Supabase service role key (required for storage operations) */
510
+ supabaseKey: string;
511
+ /** Storage bucket name */
512
+ bucket: string;
513
+ /** Public URL for the bucket (optional, uses Supabase URL if not provided) */
514
+ publicUrl?: string;
515
+ }
469
516
  interface StorageConfig {
470
517
  /** Storage adapter to use */
471
- adapter: 'local' | 's3' | 'r2';
518
+ adapter: 'local' | 's3' | 'r2' | 'supabase';
472
519
  /** Local storage configuration */
473
520
  local?: LocalStorageConfig;
474
521
  /** S3 storage configuration */
475
522
  s3?: S3StorageConfig;
476
523
  /** R2 storage configuration */
477
524
  r2?: R2StorageConfig;
525
+ /** Supabase storage configuration */
526
+ supabase?: SupabaseStorageConfig;
478
527
  }
479
528
  interface UploadOptions {
480
529
  /** Target folder for the file */
@@ -1041,7 +1090,37 @@ declare class Mixed {
1041
1090
  defaultOptions: Record<string, any>;
1042
1091
  }
1043
1092
 
1044
- declare function detectDatabaseAdapter(): 'mongoose' | 'typeorm';
1093
+ type SupportedAdapter = 'mongoose' | 'drizzle';
1094
+ /**
1095
+ * Detect the database adapter based on configuration or installed packages.
1096
+ *
1097
+ * Detection priority:
1098
+ * 1. Configuration-based: If `connectionString` or `dialect` is present, use drizzle
1099
+ * 2. Configuration-based: If `uri` is present, use mongoose
1100
+ * 3. Package-based: Check which adapter packages are installed (mongoose > drizzle)
1101
+ *
1102
+ * @param dbConfig - Optional database configuration to determine adapter from
1103
+ */
1104
+ declare function detectDatabaseAdapter(dbConfig?: DBConfig): SupportedAdapter;
1105
+ /**
1106
+ * Explicitly set the database adapter.
1107
+ * Call this at the very start of your application, before importing any schemas.
1108
+ *
1109
+ * @example
1110
+ * ```typescript
1111
+ * // main.ts or app.module.ts (at the top, before other imports)
1112
+ * import { setDatabaseAdapter } from '@magnet-cms/common'
1113
+ * setDatabaseAdapter('drizzle')
1114
+ *
1115
+ * // Then import your modules
1116
+ * import { MagnetModule } from '@magnet-cms/core'
1117
+ * ```
1118
+ */
1119
+ declare function setDatabaseAdapter(adapter: SupportedAdapter): void;
1120
+ /**
1121
+ * Clear the cached adapter (useful for testing)
1122
+ */
1123
+ declare function clearAdapterCache(): void;
1045
1124
 
1046
1125
  declare function getModelToken(schema: Type): string;
1047
1126
 
@@ -1062,4 +1141,4 @@ declare const DESIGN_META = "design:metadata";
1062
1141
  declare const DESIGN_PARAM_TYPES = "design:paramtypes";
1063
1142
  declare const DESIGN_RETURN_TYPE = "design:returntype";
1064
1143
 
1065
- export { type AuthConfig, type AuthResult, AuthStrategy, type AuthUser, BASE_SCHEMA_METADATA_KEY, type BaseSchema, type BaseSchemaOptions, type ControllerMetadata, type DBConfig, DESIGN_META, DESIGN_PARAM_TYPES, DESIGN_RETURN_TYPE, DESIGN_TYPE, DatabaseAdapter, type DiscoveredController, type DiscoveredMethod, type DiscoveredSchema, type EnrichedPluginManifest, type FilterQuery, type FilterValue, INJECT_MODEL, type InitialConfig, InjectModel, type InternationalizationOptions, type JwtAuthConfig, type LocalStorageConfig, type LoginCredentials, MagnetModuleOptions, type MagnetModuleOptionsAsync, type MediaQueryOptions, type MethodMetadata, Mixed, Model, type ModelCreateOptions, type ModelUpdateOptions, type MongooseConfig, PROP_METADATA_KEY, type PaginatedMedia, type PaginatedResult, type PlaygroundOptions, type PluginConfig, type PluginFrontendManifest, type PluginHook, type PluginLifecycle, type PluginMetadata, type PluginModuleOptions, type PluginRouteDefinition, type PluginSettingsPage, type PluginSidebarItem, type ProjectionQuery, Prop, type PropOptions, QueryBuilder, type QueryOperator, type QueryOptions, type R2StorageConfig, RESOLVER_METADATA_KEY, RESOLVE_METADATA_KEY, type RegisterData, type RegisteredPluginInfo, Resolve, type ResolveInput, type ResolveOptions, Resolver, type ResolverInput, type ResolverOptions, type S3StorageConfig, SCHEMA_METADATA_KEY, SCHEMA_OPTIONS_METADATA_KEY, SETTING_METADATA_KEY, Schema, type SchemaMetadata, type SchemaOptions, type SchemaProperty, type SchemaPropertyValidation, type SchemaSetting, Setting, type SettingType, type SettingsFeatureOptions, type SortDirection, type SortQuery, StorageAdapter, type StorageConfig, type TransformOptions, type TypeORMConfig, UI, type UIBase, type UICombobox, type UIDecoratorOptions, type UIFieldMetadata, type UIMultiSelect, type UIPresentationFields, type UISelect, type UISelectItem, type UISide, type UITab, type UITable, type UITableColumn, type UITypes, UI_METADATA_KEY, type UploadOptions, type UploadResult, VERSION_METADATA_KEY, ValidationException, type Validations, Validators, Version, type VersionConfig, type VersionData, type VersionStatus, detectDatabaseAdapter, getModelToken, getSchemaOptions, getSchemaToken, getSettingToken };
1144
+ export { type AuthConfig, type AuthResult, AuthStrategy, type AuthUser, BASE_SCHEMA_METADATA_KEY, type BaseSchema, type BaseSchemaOptions, type ControllerMetadata, type DBConfig, DESIGN_META, DESIGN_PARAM_TYPES, DESIGN_RETURN_TYPE, DESIGN_TYPE, DatabaseAdapter, type DiscoveredController, type DiscoveredMethod, type DiscoveredSchema, type DrizzleConfig, type EnrichedPluginManifest, type FilterQuery, type FilterValue, INJECT_MODEL, type InitialConfig, InjectModel, type InternationalizationOptions, type JwtAuthConfig, type LocalStorageConfig, type LoginCredentials, MagnetModuleOptions, type MagnetModuleOptionsAsync, type MediaQueryOptions, type MethodMetadata, Mixed, Model, type ModelCreateOptions, type ModelUpdateOptions, type MongooseConfig, PROP_METADATA_KEY, type PaginatedMedia, type PaginatedResult, type PlaygroundOptions, type PluginConfig, type PluginFrontendManifest, type PluginHook, type PluginLifecycle, type PluginMetadata, type PluginModuleOptions, type PluginRouteDefinition, type PluginSettingsPage, type PluginSidebarItem, type ProjectionQuery, Prop, type PropOptions, QueryBuilder, type QueryOperator, type QueryOptions, type R2StorageConfig, RESOLVER_METADATA_KEY, RESOLVE_METADATA_KEY, type RegisterData, type RegisteredPluginInfo, Resolve, type ResolveInput, type ResolveOptions, Resolver, type ResolverInput, type ResolverOptions, type S3StorageConfig, SCHEMA_METADATA_KEY, SCHEMA_OPTIONS_METADATA_KEY, SETTING_METADATA_KEY, Schema, type SchemaMetadata, type SchemaOptions, type SchemaProperty, type SchemaPropertyValidation, type SchemaSetting, Setting, type SettingType, type SettingsFeatureOptions, type SortDirection, type SortQuery, StorageAdapter, type StorageConfig, type SupabaseAuthConfig, type SupabaseStorageConfig, type SupportedAdapter, type TransformOptions, UI, type UIBase, type UICombobox, type UIDecoratorOptions, type UIFieldMetadata, type UIMultiSelect, type UIPresentationFields, type UISelect, type UISelectItem, type UISide, type UITab, type UITable, type UITableColumn, type UITypes, UI_METADATA_KEY, type UploadOptions, type UploadResult, VERSION_METADATA_KEY, ValidationException, type Validations, Validators, Version, type VersionConfig, type VersionData, type VersionStatus, clearAdapterCache, detectDatabaseAdapter, getModelToken, getSchemaOptions, getSchemaToken, getSettingToken, setDatabaseAdapter };
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ type ResolveOptions = {
12
12
  };
13
13
  type ResolveInput = (() => Type | [Type]) | ResolveOptions;
14
14
  type PropOptions = {
15
- type?: Type | [Type];
15
+ type?: Type | [Type] | any;
16
16
  description?: string;
17
17
  required?: boolean;
18
18
  unique?: boolean;
@@ -21,6 +21,7 @@ type PropOptions = {
21
21
  intl?: boolean;
22
22
  hidden?: boolean;
23
23
  readonly?: boolean;
24
+ ref?: string;
24
25
  };
25
26
  type BaseSchemaOptions = {
26
27
  timestamps?: boolean;
@@ -112,9 +113,13 @@ type SchemaProperty = {
112
113
  required: boolean;
113
114
  validations: SchemaPropertyValidation[];
114
115
  ui: UIDecoratorOptions;
116
+ ref?: string;
115
117
  };
116
118
  type SchemaMetadata = {
117
119
  name: string;
120
+ className?: string;
121
+ apiName?: string;
122
+ displayName?: string;
118
123
  properties: SchemaProperty[];
119
124
  options?: SchemaOptions;
120
125
  };
@@ -176,6 +181,17 @@ interface JwtAuthConfig {
176
181
  /** Token expiration time (e.g., '7d', '1h') */
177
182
  expiresIn?: string;
178
183
  }
184
+ /**
185
+ * Supabase-specific auth configuration
186
+ */
187
+ interface SupabaseAuthConfig {
188
+ /** Supabase project URL */
189
+ supabaseUrl: string;
190
+ /** Supabase anon/public key */
191
+ supabaseKey: string;
192
+ /** Default role for new users */
193
+ defaultRole?: string;
194
+ }
179
195
  /**
180
196
  * Auth configuration for MagnetModuleOptions
181
197
  */
@@ -184,6 +200,14 @@ interface AuthConfig {
184
200
  strategy?: string;
185
201
  /** JWT-specific configuration */
186
202
  jwt?: JwtAuthConfig;
203
+ /** Supabase-specific configuration (when strategy: 'supabase') */
204
+ supabaseUrl?: string;
205
+ /** Supabase anon/public key */
206
+ supabaseKey?: string;
207
+ /** Supabase service role key (required for admin operations like listUsers) */
208
+ supabaseServiceKey?: string;
209
+ /** Default role for new Supabase users */
210
+ defaultRole?: string;
187
211
  /** Allow extensible config for custom strategies */
188
212
  [key: string]: unknown;
189
213
  }
@@ -259,6 +283,13 @@ declare abstract class AuthStrategy {
259
283
  * @param token - The token to invalidate
260
284
  */
261
285
  logout?(token: string): Promise<void>;
286
+ /**
287
+ * Check if any users exist in the system (optional)
288
+ * Strategies that manage their own user storage should implement this.
289
+ * If not implemented, AuthService will fall back to checking the local database.
290
+ * @returns true if users exist, false otherwise
291
+ */
292
+ hasUsers?(): Promise<boolean>;
262
293
  /**
263
294
  * Get the Passport strategy name (for guards)
264
295
  * Returns the name to use with AuthGuard()
@@ -269,15 +300,21 @@ declare abstract class AuthStrategy {
269
300
  type MongooseConfig = {
270
301
  uri: string;
271
302
  };
272
- type TypeORMConfig = {
273
- type: 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' | 'oracle' | 'mongodb';
274
- host: string;
275
- port: number;
276
- username: string;
277
- password: string;
278
- database: string;
303
+ /**
304
+ * Drizzle ORM configuration for SQL databases.
305
+ * Supports PostgreSQL, MySQL, and SQLite through Drizzle ORM.
306
+ */
307
+ type DrizzleConfig = {
308
+ /** Database connection string */
309
+ connectionString: string;
310
+ /** SQL dialect to use */
311
+ dialect: 'postgresql' | 'mysql' | 'sqlite';
312
+ /** Database driver to use (auto-detected if not specified) */
313
+ driver?: 'pg' | 'neon' | 'mysql2' | 'better-sqlite3';
314
+ /** Enable debug logging */
315
+ debug?: boolean;
279
316
  };
280
- type DBConfig = MongooseConfig | TypeORMConfig;
317
+ type DBConfig = MongooseConfig | DrizzleConfig;
281
318
  declare abstract class DatabaseAdapter {
282
319
  abstract connect(options: MagnetModuleOptions): DynamicModule;
283
320
  abstract forFeature(schemas: Type | Type[]): DynamicModule;
@@ -466,15 +503,27 @@ interface R2StorageConfig extends S3StorageConfig {
466
503
  /** Cloudflare account ID */
467
504
  accountId: string;
468
505
  }
506
+ interface SupabaseStorageConfig {
507
+ /** Supabase project URL */
508
+ supabaseUrl: string;
509
+ /** Supabase service role key (required for storage operations) */
510
+ supabaseKey: string;
511
+ /** Storage bucket name */
512
+ bucket: string;
513
+ /** Public URL for the bucket (optional, uses Supabase URL if not provided) */
514
+ publicUrl?: string;
515
+ }
469
516
  interface StorageConfig {
470
517
  /** Storage adapter to use */
471
- adapter: 'local' | 's3' | 'r2';
518
+ adapter: 'local' | 's3' | 'r2' | 'supabase';
472
519
  /** Local storage configuration */
473
520
  local?: LocalStorageConfig;
474
521
  /** S3 storage configuration */
475
522
  s3?: S3StorageConfig;
476
523
  /** R2 storage configuration */
477
524
  r2?: R2StorageConfig;
525
+ /** Supabase storage configuration */
526
+ supabase?: SupabaseStorageConfig;
478
527
  }
479
528
  interface UploadOptions {
480
529
  /** Target folder for the file */
@@ -1041,7 +1090,37 @@ declare class Mixed {
1041
1090
  defaultOptions: Record<string, any>;
1042
1091
  }
1043
1092
 
1044
- declare function detectDatabaseAdapter(): 'mongoose' | 'typeorm';
1093
+ type SupportedAdapter = 'mongoose' | 'drizzle';
1094
+ /**
1095
+ * Detect the database adapter based on configuration or installed packages.
1096
+ *
1097
+ * Detection priority:
1098
+ * 1. Configuration-based: If `connectionString` or `dialect` is present, use drizzle
1099
+ * 2. Configuration-based: If `uri` is present, use mongoose
1100
+ * 3. Package-based: Check which adapter packages are installed (mongoose > drizzle)
1101
+ *
1102
+ * @param dbConfig - Optional database configuration to determine adapter from
1103
+ */
1104
+ declare function detectDatabaseAdapter(dbConfig?: DBConfig): SupportedAdapter;
1105
+ /**
1106
+ * Explicitly set the database adapter.
1107
+ * Call this at the very start of your application, before importing any schemas.
1108
+ *
1109
+ * @example
1110
+ * ```typescript
1111
+ * // main.ts or app.module.ts (at the top, before other imports)
1112
+ * import { setDatabaseAdapter } from '@magnet-cms/common'
1113
+ * setDatabaseAdapter('drizzle')
1114
+ *
1115
+ * // Then import your modules
1116
+ * import { MagnetModule } from '@magnet-cms/core'
1117
+ * ```
1118
+ */
1119
+ declare function setDatabaseAdapter(adapter: SupportedAdapter): void;
1120
+ /**
1121
+ * Clear the cached adapter (useful for testing)
1122
+ */
1123
+ declare function clearAdapterCache(): void;
1045
1124
 
1046
1125
  declare function getModelToken(schema: Type): string;
1047
1126
 
@@ -1062,4 +1141,4 @@ declare const DESIGN_META = "design:metadata";
1062
1141
  declare const DESIGN_PARAM_TYPES = "design:paramtypes";
1063
1142
  declare const DESIGN_RETURN_TYPE = "design:returntype";
1064
1143
 
1065
- export { type AuthConfig, type AuthResult, AuthStrategy, type AuthUser, BASE_SCHEMA_METADATA_KEY, type BaseSchema, type BaseSchemaOptions, type ControllerMetadata, type DBConfig, DESIGN_META, DESIGN_PARAM_TYPES, DESIGN_RETURN_TYPE, DESIGN_TYPE, DatabaseAdapter, type DiscoveredController, type DiscoveredMethod, type DiscoveredSchema, type EnrichedPluginManifest, type FilterQuery, type FilterValue, INJECT_MODEL, type InitialConfig, InjectModel, type InternationalizationOptions, type JwtAuthConfig, type LocalStorageConfig, type LoginCredentials, MagnetModuleOptions, type MagnetModuleOptionsAsync, type MediaQueryOptions, type MethodMetadata, Mixed, Model, type ModelCreateOptions, type ModelUpdateOptions, type MongooseConfig, PROP_METADATA_KEY, type PaginatedMedia, type PaginatedResult, type PlaygroundOptions, type PluginConfig, type PluginFrontendManifest, type PluginHook, type PluginLifecycle, type PluginMetadata, type PluginModuleOptions, type PluginRouteDefinition, type PluginSettingsPage, type PluginSidebarItem, type ProjectionQuery, Prop, type PropOptions, QueryBuilder, type QueryOperator, type QueryOptions, type R2StorageConfig, RESOLVER_METADATA_KEY, RESOLVE_METADATA_KEY, type RegisterData, type RegisteredPluginInfo, Resolve, type ResolveInput, type ResolveOptions, Resolver, type ResolverInput, type ResolverOptions, type S3StorageConfig, SCHEMA_METADATA_KEY, SCHEMA_OPTIONS_METADATA_KEY, SETTING_METADATA_KEY, Schema, type SchemaMetadata, type SchemaOptions, type SchemaProperty, type SchemaPropertyValidation, type SchemaSetting, Setting, type SettingType, type SettingsFeatureOptions, type SortDirection, type SortQuery, StorageAdapter, type StorageConfig, type TransformOptions, type TypeORMConfig, UI, type UIBase, type UICombobox, type UIDecoratorOptions, type UIFieldMetadata, type UIMultiSelect, type UIPresentationFields, type UISelect, type UISelectItem, type UISide, type UITab, type UITable, type UITableColumn, type UITypes, UI_METADATA_KEY, type UploadOptions, type UploadResult, VERSION_METADATA_KEY, ValidationException, type Validations, Validators, Version, type VersionConfig, type VersionData, type VersionStatus, detectDatabaseAdapter, getModelToken, getSchemaOptions, getSchemaToken, getSettingToken };
1144
+ export { type AuthConfig, type AuthResult, AuthStrategy, type AuthUser, BASE_SCHEMA_METADATA_KEY, type BaseSchema, type BaseSchemaOptions, type ControllerMetadata, type DBConfig, DESIGN_META, DESIGN_PARAM_TYPES, DESIGN_RETURN_TYPE, DESIGN_TYPE, DatabaseAdapter, type DiscoveredController, type DiscoveredMethod, type DiscoveredSchema, type DrizzleConfig, type EnrichedPluginManifest, type FilterQuery, type FilterValue, INJECT_MODEL, type InitialConfig, InjectModel, type InternationalizationOptions, type JwtAuthConfig, type LocalStorageConfig, type LoginCredentials, MagnetModuleOptions, type MagnetModuleOptionsAsync, type MediaQueryOptions, type MethodMetadata, Mixed, Model, type ModelCreateOptions, type ModelUpdateOptions, type MongooseConfig, PROP_METADATA_KEY, type PaginatedMedia, type PaginatedResult, type PlaygroundOptions, type PluginConfig, type PluginFrontendManifest, type PluginHook, type PluginLifecycle, type PluginMetadata, type PluginModuleOptions, type PluginRouteDefinition, type PluginSettingsPage, type PluginSidebarItem, type ProjectionQuery, Prop, type PropOptions, QueryBuilder, type QueryOperator, type QueryOptions, type R2StorageConfig, RESOLVER_METADATA_KEY, RESOLVE_METADATA_KEY, type RegisterData, type RegisteredPluginInfo, Resolve, type ResolveInput, type ResolveOptions, Resolver, type ResolverInput, type ResolverOptions, type S3StorageConfig, SCHEMA_METADATA_KEY, SCHEMA_OPTIONS_METADATA_KEY, SETTING_METADATA_KEY, Schema, type SchemaMetadata, type SchemaOptions, type SchemaProperty, type SchemaPropertyValidation, type SchemaSetting, Setting, type SettingType, type SettingsFeatureOptions, type SortDirection, type SortQuery, StorageAdapter, type StorageConfig, type SupabaseAuthConfig, type SupabaseStorageConfig, type SupportedAdapter, type TransformOptions, UI, type UIBase, type UICombobox, type UIDecoratorOptions, type UIFieldMetadata, type UIMultiSelect, type UIPresentationFields, type UISelect, type UISelectItem, type UISide, type UITab, type UITable, type UITableColumn, type UITypes, UI_METADATA_KEY, type UploadOptions, type UploadResult, VERSION_METADATA_KEY, ValidationException, type Validations, Validators, Version, type VersionConfig, type VersionData, type VersionStatus, clearAdapterCache, detectDatabaseAdapter, getModelToken, getSchemaOptions, getSchemaToken, getSettingToken, setDatabaseAdapter };
package/dist/index.js CHANGED
@@ -90,18 +90,36 @@ function isPackageInstalled(packageName) {
90
90
  }
91
91
  }
92
92
  __name(isPackageInstalled, "isPackageInstalled");
93
- function detectDatabaseAdapter() {
93
+ function detectDatabaseAdapter(dbConfig) {
94
+ if (dbConfig) {
95
+ if ("connectionString" in dbConfig || "dialect" in dbConfig) {
96
+ cachedAdapter = "drizzle";
97
+ return cachedAdapter;
98
+ }
99
+ if ("uri" in dbConfig) {
100
+ cachedAdapter = "mongoose";
101
+ return cachedAdapter;
102
+ }
103
+ }
94
104
  if (cachedAdapter) return cachedAdapter;
95
105
  if (isPackageInstalled("@magnet-cms/adapter-mongoose")) {
96
106
  cachedAdapter = "mongoose";
97
- } else if (isPackageInstalled("@magnet-cms/adapter-typeorm")) {
98
- cachedAdapter = "typeorm";
107
+ } else if (isPackageInstalled("@magnet-cms/adapter-drizzle")) {
108
+ cachedAdapter = "drizzle";
99
109
  } else {
100
- throw new Error("\u274C No supported database adapter found. Install @magnet-cms/adapter-mongoose or @magnet-cms/adapter-typeorm.");
110
+ throw new Error("\u274C No supported database adapter found. Install @magnet-cms/adapter-mongoose or @magnet-cms/adapter-drizzle.");
101
111
  }
102
112
  return cachedAdapter;
103
113
  }
104
114
  __name(detectDatabaseAdapter, "detectDatabaseAdapter");
115
+ function setDatabaseAdapter(adapter) {
116
+ cachedAdapter = adapter;
117
+ }
118
+ __name(setDatabaseAdapter, "setDatabaseAdapter");
119
+ function clearAdapterCache() {
120
+ cachedAdapter = null;
121
+ }
122
+ __name(clearAdapterCache, "clearAdapterCache");
105
123
 
106
124
  // src/utils/get-model-token.util.ts
107
125
  function getModelToken(schema) {
@@ -355,4 +373,4 @@ var StorageAdapter = class {
355
373
  }
356
374
  };
357
375
 
358
- export { AuthStrategy, BASE_SCHEMA_METADATA_KEY, DESIGN_META, DESIGN_PARAM_TYPES, DESIGN_RETURN_TYPE, DESIGN_TYPE, DatabaseAdapter, INJECT_MODEL, InjectModel, MagnetModuleOptions, Mixed, Model, PROP_METADATA_KEY, Prop, QueryBuilder, RESOLVER_METADATA_KEY, RESOLVE_METADATA_KEY, Resolve, Resolver, SCHEMA_METADATA_KEY, SCHEMA_OPTIONS_METADATA_KEY, SETTING_METADATA_KEY, Schema, Setting, StorageAdapter, UI, UI_METADATA_KEY, VERSION_METADATA_KEY, ValidationException, Validators, Version, detectDatabaseAdapter, getModelToken, getSchemaOptions, getSchemaToken, getSettingToken };
376
+ export { AuthStrategy, BASE_SCHEMA_METADATA_KEY, DESIGN_META, DESIGN_PARAM_TYPES, DESIGN_RETURN_TYPE, DESIGN_TYPE, DatabaseAdapter, INJECT_MODEL, InjectModel, MagnetModuleOptions, Mixed, Model, PROP_METADATA_KEY, Prop, QueryBuilder, RESOLVER_METADATA_KEY, RESOLVE_METADATA_KEY, Resolve, Resolver, SCHEMA_METADATA_KEY, SCHEMA_OPTIONS_METADATA_KEY, SETTING_METADATA_KEY, Schema, Setting, StorageAdapter, UI, UI_METADATA_KEY, VERSION_METADATA_KEY, ValidationException, Validators, Version, clearAdapterCache, detectDatabaseAdapter, getModelToken, getSchemaOptions, getSchemaToken, getSettingToken, setDatabaseAdapter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magnet-cms/common",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Shared types, decorators, and utilities for Magnet CMS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -24,14 +24,14 @@
24
24
  "build": "tsup"
25
25
  },
26
26
  "devDependencies": {
27
- "@nestjs/common": "^11.0.8",
27
+ "@nestjs/common": "^11.1.12",
28
28
  "@repo/biome": "workspace:*",
29
29
  "@repo/tsup": "workspace:*",
30
30
  "@repo/typescript-config": "workspace:*",
31
31
  "reflect-metadata": "0.2.2"
32
32
  },
33
33
  "peerDependencies": {
34
- "@nestjs/common": "^11.0.0",
34
+ "@nestjs/common": "^11.1.12",
35
35
  "reflect-metadata": "0.2.2"
36
36
  }
37
37
  }