@famgia/omnify-types 0.0.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 ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ err: () => err,
24
+ ok: () => ok
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/errors.ts
29
+ function ok(value) {
30
+ return { ok: true, value };
31
+ }
32
+ function err(error) {
33
+ return { ok: false, error };
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ err,
38
+ ok
39
+ });
40
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts"],"sourcesContent":["/**\n * @famgia/omnify-types\n * Core type definitions for omnify-schema\n *\n * This package provides shared TypeScript interfaces and types\n * used across all omnify packages.\n */\n\n// ============================================================================\n// Schema Types\n// ============================================================================\n\nexport type {\n // Property types\n BuiltInPropertyType,\n PropertyType,\n // Association types\n AssociationRelation,\n ReferentialAction,\n AssociationDefinition,\n // Property definitions\n BasePropertyDefinition,\n StringPropertyDefinition,\n NumericPropertyDefinition,\n EnumPropertyDefinition,\n SelectPropertyDefinition,\n PropertyDefinition,\n // Schema options\n IndexDefinition,\n SchemaOptions,\n // Schema definitions\n SchemaKind,\n SchemaDefinition,\n LoadedSchema,\n SchemaCollection,\n} from './schema.js';\n\n// ============================================================================\n// Configuration Types\n// ============================================================================\n\nexport type {\n // Database config\n DatabaseDriver,\n DatabaseConfig,\n // Output config\n LaravelOutputConfig,\n TypeScriptOutputConfig,\n OutputConfig,\n // Main config\n OmnifyConfig,\n ResolvedOmnifyConfig,\n} from './config.js';\n\n// ============================================================================\n// Plugin Types\n// ============================================================================\n\nexport type {\n // Type definitions\n SqlColumnDefinition,\n TypeScriptTypeInfo,\n ExpandedFieldDefinition,\n CustomTypeDefinition,\n // Plugin interface\n PluginContext,\n PluginLogger,\n OmnifyPlugin,\n PluginFactory,\n} from './plugin.js';\n\n// ============================================================================\n// Error Types\n// ============================================================================\n\nexport type {\n ErrorCode,\n ErrorLocation,\n OmnifyErrorInfo,\n Result,\n} from './errors.js';\n\nexport { ok, err } from './errors.js';\n","/**\n * @famgia/omnify-types - Error Types\n *\n * Type definitions for omnify error handling.\n * Errors follow the format: file:line + message + suggestion\n */\n\n// ============================================================================\n// Error Codes\n// ============================================================================\n\n/**\n * Error code categories:\n * - E0xx: Configuration errors\n * - E1xx: Schema parsing errors\n * - E2xx: Schema validation errors\n * - E3xx: Plugin errors\n * - E4xx: Atlas/Database errors\n * - E5xx: Generation errors\n * - E9xx: Internal errors\n */\nexport type ErrorCode =\n // Configuration errors (E0xx)\n | 'E001' // Config file not found\n | 'E002' // Invalid config format\n | 'E003' // Missing required config field\n | 'E004' // Invalid database driver\n | 'E005' // Invalid output path\n // Schema parsing errors (E1xx)\n | 'E101' // Schema file not found\n | 'E102' // Invalid YAML syntax\n | 'E103' // Invalid JSON syntax\n | 'E104' // Empty schema file\n | 'E105' // Schema read error\n // Schema validation errors (E2xx)\n | 'E201' // Invalid property type\n | 'E202' // Missing required field\n | 'E203' // Invalid association target\n | 'E204' // Circular reference detected\n | 'E205' // Duplicate schema name\n | 'E206' // Invalid schema options\n | 'E207' // Invalid enum values\n | 'E208' // Orphaned inverse relation\n // Plugin errors (E3xx)\n | 'E301' // Plugin not found\n | 'E302' // Plugin load error\n | 'E303' // Invalid plugin format\n | 'E304' // Plugin type conflict\n | 'E305' // Plugin setup error\n // Atlas/Database errors (E4xx)\n | 'E401' // Atlas CLI not found\n | 'E402' // Atlas diff failed\n | 'E403' // Database connection error\n | 'E404' // HCL generation error\n | 'E405' // Lock file error\n // Generation errors (E5xx)\n | 'E501' // Migration generation failed\n | 'E502' // TypeScript generation failed\n | 'E503' // Output write error\n | 'E504' // Template error\n // Internal errors (E9xx)\n | 'E901' // Unexpected error\n | 'E902'; // Not implemented\n\n// ============================================================================\n// Error Info\n// ============================================================================\n\n/**\n * Source location where an error occurred.\n */\nexport interface ErrorLocation {\n /** File path where the error occurred */\n readonly file?: string;\n /** Line number (1-based) */\n readonly line?: number;\n /** Column number (1-based) */\n readonly column?: number;\n}\n\n/**\n * Structured error information for omnify errors.\n */\nexport interface OmnifyErrorInfo {\n /** Error code (e.g., 'E201') */\n readonly code: ErrorCode;\n /** Human-readable error message */\n readonly message: string;\n /** Location where the error occurred */\n readonly location?: ErrorLocation;\n /** Suggested fix for the error */\n readonly suggestion?: string;\n /** Additional context or details */\n readonly details?: Record<string, unknown>;\n /** Original error if this wraps another error */\n readonly cause?: Error;\n}\n\n/**\n * Result type for operations that may fail.\n */\nexport type Result<T, E = OmnifyErrorInfo> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly error: E };\n\n/**\n * Helper to create a successful result.\n */\nexport function ok<T>(value: T): Result<T, never> {\n return { ok: true, value };\n}\n\n/**\n * Helper to create an error result.\n */\nexport function err<E>(error: E): Result<never, E> {\n return { ok: false, error };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4GO,SAAS,GAAM,OAA4B;AAChD,SAAO,EAAE,IAAI,MAAM,MAAM;AAC3B;AAKO,SAAS,IAAO,OAA4B;AACjD,SAAO,EAAE,IAAI,OAAO,MAAM;AAC5B;","names":[]}
@@ -0,0 +1,511 @@
1
+ /**
2
+ * @famgia/omnify-types - Schema Definition Types
3
+ *
4
+ * Core type definitions for schema objects, properties, and associations.
5
+ */
6
+ /**
7
+ * Built-in property types supported by omnify-schema.
8
+ * Custom types can be added via plugins.
9
+ */
10
+ type BuiltInPropertyType = 'String' | 'Int' | 'BigInt' | 'Float' | 'Boolean' | 'Text' | 'LongText' | 'Date' | 'Time' | 'Timestamp' | 'Json' | 'Email' | 'Password' | 'File' | 'MultiFile' | 'Enum' | 'Select' | 'Lookup' | 'Association' | 'Polymorphic';
11
+ /**
12
+ * Property type - can be a built-in type or a custom plugin type (string).
13
+ */
14
+ type PropertyType = BuiltInPropertyType | (string & {});
15
+ /**
16
+ * Relationship cardinality types for associations.
17
+ */
18
+ type AssociationRelation = 'OneToOne' | 'OneToMany' | 'ManyToOne' | 'ManyToMany';
19
+ /**
20
+ * Referential action for foreign key constraints.
21
+ */
22
+ type ReferentialAction = 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION';
23
+ /**
24
+ * Association property definition - defines a relationship to another schema.
25
+ */
26
+ interface AssociationDefinition {
27
+ /** Display name for the association */
28
+ readonly displayName?: string;
29
+ /** Must be 'Association' for association properties */
30
+ readonly type: 'Association';
31
+ /** Relationship cardinality */
32
+ readonly relation: AssociationRelation;
33
+ /** Target schema name (e.g., 'User', 'Product') */
34
+ readonly target: string;
35
+ /** Property name on the target schema that maps back (for bidirectional) */
36
+ readonly inversedBy?: string;
37
+ /** Property name on this schema that is mapped by target (for bidirectional) */
38
+ readonly mappedBy?: string;
39
+ /** Action when referenced record is deleted */
40
+ readonly onDelete?: ReferentialAction;
41
+ /** Action when referenced record is updated */
42
+ readonly onUpdate?: ReferentialAction;
43
+ /** Whether this side owns the relationship (has the foreign key) */
44
+ readonly owning?: boolean;
45
+ /** Custom join table name for ManyToMany */
46
+ readonly joinTable?: string;
47
+ }
48
+ /**
49
+ * Base property definition shared by all property types.
50
+ */
51
+ interface BasePropertyDefinition {
52
+ /** Property type (String, Int, Association, etc.) */
53
+ readonly type: PropertyType;
54
+ /** Human-readable display name */
55
+ readonly displayName?: string;
56
+ /** Whether the field can be null */
57
+ readonly nullable?: boolean;
58
+ /** Default value for the field */
59
+ readonly default?: unknown;
60
+ /** Whether this field must be unique */
61
+ readonly unique?: boolean;
62
+ /** Field description/comment */
63
+ readonly description?: string;
64
+ }
65
+ /**
66
+ * String property with length constraint.
67
+ */
68
+ interface StringPropertyDefinition extends BasePropertyDefinition {
69
+ readonly type: 'String' | 'Email' | 'Password';
70
+ /** Maximum character length */
71
+ readonly length?: number;
72
+ }
73
+ /**
74
+ * Numeric property definition.
75
+ */
76
+ interface NumericPropertyDefinition extends BasePropertyDefinition {
77
+ readonly type: 'Int' | 'BigInt' | 'Float';
78
+ /** Whether the number is unsigned (positive only) */
79
+ readonly unsigned?: boolean;
80
+ /** Precision for decimal types */
81
+ readonly precision?: number;
82
+ /** Scale for decimal types */
83
+ readonly scale?: number;
84
+ }
85
+ /**
86
+ * Enum property definition - references an enum.
87
+ */
88
+ interface EnumPropertyDefinition extends BasePropertyDefinition {
89
+ readonly type: 'Enum';
90
+ /** Enum name or inline enum values */
91
+ readonly enum: string | readonly string[];
92
+ }
93
+ /**
94
+ * Select/Lookup property definition.
95
+ */
96
+ interface SelectPropertyDefinition extends BasePropertyDefinition {
97
+ readonly type: 'Select' | 'Lookup';
98
+ /** Available options */
99
+ readonly options?: readonly string[];
100
+ /** Reference to another schema for lookup */
101
+ readonly source?: string;
102
+ }
103
+ /**
104
+ * Union type for all property definitions.
105
+ */
106
+ type PropertyDefinition = (BasePropertyDefinition & {
107
+ readonly type: PropertyType;
108
+ }) | StringPropertyDefinition | NumericPropertyDefinition | EnumPropertyDefinition | SelectPropertyDefinition | AssociationDefinition;
109
+ /**
110
+ * Index definition for database optimization.
111
+ */
112
+ interface IndexDefinition {
113
+ /** Columns to include in the index */
114
+ readonly columns: readonly string[];
115
+ /** Whether this is a unique index */
116
+ readonly unique?: boolean;
117
+ /** Custom index name */
118
+ readonly name?: string;
119
+ }
120
+ /**
121
+ * Schema-level options for behavior configuration.
122
+ */
123
+ interface SchemaOptions {
124
+ /** Add created_at and updated_at timestamp columns */
125
+ readonly timestamps?: boolean;
126
+ /** Add deleted_at column for soft deletes */
127
+ readonly softDelete?: boolean;
128
+ /** Columns that should be unique (simple unique constraints) */
129
+ readonly unique?: readonly string[] | readonly (readonly string[])[];
130
+ /** Database indexes for query optimization */
131
+ readonly indexes?: readonly IndexDefinition[];
132
+ /** Enable translations support */
133
+ readonly translations?: boolean;
134
+ /** Custom table name (defaults to pluralized snake_case of schema name) */
135
+ readonly tableName?: string;
136
+ /** Primary key type */
137
+ readonly primaryKeyType?: 'Int' | 'BigInt' | 'Uuid' | 'String';
138
+ /** Enable authenticatable trait (for User-like schemas) */
139
+ readonly authenticatable?: boolean;
140
+ /** Login ID field for authenticatable */
141
+ readonly authenticatableLoginIdField?: string;
142
+ /** Password field for authenticatable */
143
+ readonly authenticatablePasswordField?: string;
144
+ /** Guard name for authenticatable */
145
+ readonly authenticatableGuardName?: string;
146
+ }
147
+ /**
148
+ * Schema kind - determines how the schema is processed.
149
+ */
150
+ type SchemaKind = 'object' | 'enum';
151
+ /**
152
+ * Complete schema definition representing a database entity.
153
+ */
154
+ interface SchemaDefinition {
155
+ /** Schema kind (defaults to 'object') */
156
+ readonly kind?: SchemaKind;
157
+ /** Human-readable display name */
158
+ readonly displayName?: string;
159
+ /** Property to use as the title/label for records */
160
+ readonly titleIndex?: string;
161
+ /** Schema group for organization */
162
+ readonly group?: string;
163
+ /** Schema-level options */
164
+ readonly options?: SchemaOptions;
165
+ /** Property definitions */
166
+ readonly properties?: Readonly<Record<string, PropertyDefinition>>;
167
+ /** Enum values (when kind is 'enum') */
168
+ readonly values?: readonly string[];
169
+ }
170
+ /**
171
+ * Loaded schema with additional metadata.
172
+ */
173
+ interface LoadedSchema extends SchemaDefinition {
174
+ /** Schema name (derived from file name) */
175
+ readonly name: string;
176
+ /** File path where the schema was loaded from */
177
+ readonly filePath: string;
178
+ /** Relative path within schemas directory */
179
+ readonly relativePath: string;
180
+ }
181
+ /**
182
+ * Collection of loaded schemas indexed by name.
183
+ */
184
+ type SchemaCollection = Readonly<Record<string, LoadedSchema>>;
185
+
186
+ /**
187
+ * @famgia/omnify-types - Plugin Types
188
+ *
189
+ * Type definitions for omnify plugins that provide custom types.
190
+ */
191
+
192
+ /**
193
+ * SQL column definition for a custom type.
194
+ */
195
+ interface SqlColumnDefinition {
196
+ /** SQL type (e.g., 'VARCHAR', 'INT', 'TEXT') */
197
+ readonly sqlType: string;
198
+ /** Column length/size if applicable */
199
+ readonly length?: number;
200
+ /** Precision for decimal types */
201
+ readonly precision?: number;
202
+ /** Scale for decimal types */
203
+ readonly scale?: number;
204
+ /** Whether the column is nullable */
205
+ readonly nullable?: boolean;
206
+ /** Default value */
207
+ readonly default?: unknown;
208
+ }
209
+ /**
210
+ * TypeScript type information for code generation.
211
+ */
212
+ interface TypeScriptTypeInfo {
213
+ /** TypeScript type as a string (e.g., 'string', 'number', 'MyCustomType') */
214
+ readonly type: string;
215
+ /** Whether to import this type from somewhere */
216
+ readonly import?: {
217
+ readonly from: string;
218
+ readonly name: string;
219
+ };
220
+ }
221
+ /**
222
+ * Expanded field definition for compound types.
223
+ * Used when a single custom type expands to multiple database columns.
224
+ */
225
+ interface ExpandedFieldDefinition {
226
+ /** Field name suffix (appended to property name) */
227
+ readonly suffix: string;
228
+ /** SQL column definition */
229
+ readonly sql: SqlColumnDefinition;
230
+ /** TypeScript type for this field */
231
+ readonly typescript: TypeScriptTypeInfo;
232
+ }
233
+ /**
234
+ * Definition of a custom property type provided by a plugin.
235
+ */
236
+ interface CustomTypeDefinition {
237
+ /** Type name as used in schema files (e.g., 'JapanPhone') */
238
+ readonly name: string;
239
+ /**
240
+ * Description of this custom type.
241
+ */
242
+ readonly description?: string;
243
+ /**
244
+ * Whether this is a compound type that expands to multiple columns.
245
+ * If true, use `expand` to define the columns.
246
+ * If false or undefined, use `sql` and `typescript` for single column.
247
+ */
248
+ readonly compound?: boolean;
249
+ /**
250
+ * SQL column definition (for single-column types).
251
+ */
252
+ readonly sql?: SqlColumnDefinition;
253
+ /**
254
+ * TypeScript type info (for single-column types).
255
+ */
256
+ readonly typescript?: TypeScriptTypeInfo;
257
+ /**
258
+ * Expanded field definitions (for compound types).
259
+ * Each entry creates an additional column.
260
+ */
261
+ readonly expand?: readonly ExpandedFieldDefinition[];
262
+ /**
263
+ * Validation function for schema validation.
264
+ * @param value - The property definition using this type
265
+ * @returns Error message if invalid, undefined if valid
266
+ */
267
+ readonly validate?: (value: PropertyDefinition) => string | undefined;
268
+ }
269
+ /**
270
+ * Plugin context provided during plugin initialization.
271
+ */
272
+ interface PluginContext {
273
+ /** Current working directory */
274
+ readonly cwd: string;
275
+ /** Whether verbose logging is enabled */
276
+ readonly verbose: boolean;
277
+ /** Logger for plugin output */
278
+ readonly logger: PluginLogger;
279
+ }
280
+ /**
281
+ * Logger interface for plugin output.
282
+ */
283
+ interface PluginLogger {
284
+ /** Log debug message (only in verbose mode) */
285
+ debug(message: string): void;
286
+ /** Log info message */
287
+ info(message: string): void;
288
+ /** Log warning message */
289
+ warn(message: string): void;
290
+ /** Log error message */
291
+ error(message: string): void;
292
+ }
293
+ /**
294
+ * Plugin interface for extending omnify with custom types.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * const japanTypesPlugin: OmnifyPlugin = {
299
+ * name: '@famgia/omnify-japan',
300
+ * version: '1.0.0',
301
+ * types: [
302
+ * {
303
+ * name: 'JapanPhone',
304
+ * sql: { sqlType: 'VARCHAR', length: 15 },
305
+ * typescript: { type: 'string' },
306
+ * },
307
+ * {
308
+ * name: 'JapanAddress',
309
+ * compound: true,
310
+ * expand: [
311
+ * { suffix: '_postal', sql: { sqlType: 'VARCHAR', length: 8 }, typescript: { type: 'string' } },
312
+ * { suffix: '_prefecture', sql: { sqlType: 'VARCHAR', length: 10 }, typescript: { type: 'string' } },
313
+ * { suffix: '_city', sql: { sqlType: 'VARCHAR', length: 100 }, typescript: { type: 'string' } },
314
+ * { suffix: '_address', sql: { sqlType: 'VARCHAR', length: 255 }, typescript: { type: 'string' } },
315
+ * ],
316
+ * },
317
+ * ],
318
+ * };
319
+ * ```
320
+ */
321
+ interface OmnifyPlugin {
322
+ /** Plugin name (typically npm package name) */
323
+ readonly name: string;
324
+ /** Plugin version */
325
+ readonly version: string;
326
+ /**
327
+ * Custom type definitions provided by this plugin.
328
+ */
329
+ readonly types?: readonly CustomTypeDefinition[];
330
+ /**
331
+ * Optional setup function called when plugin is loaded.
332
+ * @param context - Plugin context with utilities
333
+ */
334
+ readonly setup?: (context: PluginContext) => void | Promise<void>;
335
+ /**
336
+ * Optional cleanup function called when plugin is unloaded.
337
+ */
338
+ readonly teardown?: () => void | Promise<void>;
339
+ }
340
+ /**
341
+ * Factory function type for creating plugins.
342
+ * Useful for plugins that need configuration.
343
+ */
344
+ type PluginFactory<TOptions = unknown> = (options?: TOptions) => OmnifyPlugin;
345
+
346
+ /**
347
+ * @famgia/omnify-types - Configuration Types
348
+ *
349
+ * Type definitions for omnify.config.ts configuration file.
350
+ */
351
+
352
+ /**
353
+ * Supported database drivers.
354
+ */
355
+ type DatabaseDriver = 'mysql' | 'pgsql' | 'postgres' | 'sqlite' | 'sqlsrv' | 'mariadb';
356
+ /**
357
+ * Database configuration for Atlas and migrations.
358
+ */
359
+ interface DatabaseConfig {
360
+ /** Database driver type */
361
+ readonly driver: DatabaseDriver;
362
+ /** Development database URL for Atlas diff operations */
363
+ readonly devUrl?: string;
364
+ /** Enable field comments in migrations (MySQL only) */
365
+ readonly enableFieldComments?: boolean;
366
+ }
367
+ /**
368
+ * Laravel output configuration.
369
+ */
370
+ interface LaravelOutputConfig {
371
+ /** Directory for generated migration files */
372
+ readonly migrationsPath: string;
373
+ /** Directory for generated model files */
374
+ readonly modelsPath?: string;
375
+ /** Model namespace */
376
+ readonly modelsNamespace?: string;
377
+ /** Directory for generated factory files */
378
+ readonly factoriesPath?: string;
379
+ /** Directory for generated enum files */
380
+ readonly enumsPath?: string;
381
+ /** Enum namespace */
382
+ readonly enumsNamespace?: string;
383
+ }
384
+ /**
385
+ * TypeScript output configuration.
386
+ */
387
+ interface TypeScriptOutputConfig {
388
+ /** Output file or directory for TypeScript types */
389
+ readonly path: string;
390
+ /** Whether to generate a single file or multiple files */
391
+ readonly singleFile?: boolean;
392
+ /** Whether to generate enum types */
393
+ readonly generateEnums?: boolean;
394
+ /** Whether to generate relationship types */
395
+ readonly generateRelationships?: boolean;
396
+ }
397
+ /**
398
+ * Combined output configuration.
399
+ */
400
+ interface OutputConfig {
401
+ /** Laravel migration and model output */
402
+ readonly laravel?: LaravelOutputConfig;
403
+ /** TypeScript type definitions output */
404
+ readonly typescript?: TypeScriptOutputConfig;
405
+ }
406
+ /**
407
+ * Main omnify configuration interface.
408
+ * Used in omnify.config.ts files.
409
+ */
410
+ interface OmnifyConfig {
411
+ /**
412
+ * Directory containing schema definition files.
413
+ * @default './schemas'
414
+ */
415
+ readonly schemasDir?: string;
416
+ /**
417
+ * Database configuration.
418
+ */
419
+ readonly database: DatabaseConfig;
420
+ /**
421
+ * Output configuration for generated files.
422
+ */
423
+ readonly output?: OutputConfig;
424
+ /**
425
+ * Plugins to load for custom types.
426
+ * Can be npm package names or plugin objects.
427
+ */
428
+ readonly plugins?: readonly (string | OmnifyPlugin)[];
429
+ /**
430
+ * Enable verbose logging.
431
+ * @default false
432
+ */
433
+ readonly verbose?: boolean;
434
+ /**
435
+ * Lock file path for tracking schema state.
436
+ * @default '.omnify.lock'
437
+ */
438
+ readonly lockFilePath?: string;
439
+ }
440
+ /**
441
+ * Resolved configuration with all defaults applied.
442
+ */
443
+ interface ResolvedOmnifyConfig extends Required<Omit<OmnifyConfig, 'plugins'>> {
444
+ readonly plugins: readonly OmnifyPlugin[];
445
+ }
446
+
447
+ /**
448
+ * @famgia/omnify-types - Error Types
449
+ *
450
+ * Type definitions for omnify error handling.
451
+ * Errors follow the format: file:line + message + suggestion
452
+ */
453
+ /**
454
+ * Error code categories:
455
+ * - E0xx: Configuration errors
456
+ * - E1xx: Schema parsing errors
457
+ * - E2xx: Schema validation errors
458
+ * - E3xx: Plugin errors
459
+ * - E4xx: Atlas/Database errors
460
+ * - E5xx: Generation errors
461
+ * - E9xx: Internal errors
462
+ */
463
+ type ErrorCode = 'E001' | 'E002' | 'E003' | 'E004' | 'E005' | 'E101' | 'E102' | 'E103' | 'E104' | 'E105' | 'E201' | 'E202' | 'E203' | 'E204' | 'E205' | 'E206' | 'E207' | 'E208' | 'E301' | 'E302' | 'E303' | 'E304' | 'E305' | 'E401' | 'E402' | 'E403' | 'E404' | 'E405' | 'E501' | 'E502' | 'E503' | 'E504' | 'E901' | 'E902';
464
+ /**
465
+ * Source location where an error occurred.
466
+ */
467
+ interface ErrorLocation {
468
+ /** File path where the error occurred */
469
+ readonly file?: string;
470
+ /** Line number (1-based) */
471
+ readonly line?: number;
472
+ /** Column number (1-based) */
473
+ readonly column?: number;
474
+ }
475
+ /**
476
+ * Structured error information for omnify errors.
477
+ */
478
+ interface OmnifyErrorInfo {
479
+ /** Error code (e.g., 'E201') */
480
+ readonly code: ErrorCode;
481
+ /** Human-readable error message */
482
+ readonly message: string;
483
+ /** Location where the error occurred */
484
+ readonly location?: ErrorLocation;
485
+ /** Suggested fix for the error */
486
+ readonly suggestion?: string;
487
+ /** Additional context or details */
488
+ readonly details?: Record<string, unknown>;
489
+ /** Original error if this wraps another error */
490
+ readonly cause?: Error;
491
+ }
492
+ /**
493
+ * Result type for operations that may fail.
494
+ */
495
+ type Result<T, E = OmnifyErrorInfo> = {
496
+ readonly ok: true;
497
+ readonly value: T;
498
+ } | {
499
+ readonly ok: false;
500
+ readonly error: E;
501
+ };
502
+ /**
503
+ * Helper to create a successful result.
504
+ */
505
+ declare function ok<T>(value: T): Result<T, never>;
506
+ /**
507
+ * Helper to create an error result.
508
+ */
509
+ declare function err<E>(error: E): Result<never, E>;
510
+
511
+ export { type AssociationDefinition, type AssociationRelation, type BasePropertyDefinition, type BuiltInPropertyType, type CustomTypeDefinition, type DatabaseConfig, type DatabaseDriver, type EnumPropertyDefinition, type ErrorCode, type ErrorLocation, type ExpandedFieldDefinition, type IndexDefinition, type LaravelOutputConfig, type LoadedSchema, type NumericPropertyDefinition, type OmnifyConfig, type OmnifyErrorInfo, type OmnifyPlugin, type OutputConfig, type PluginContext, type PluginFactory, type PluginLogger, type PropertyDefinition, type PropertyType, type ReferentialAction, type ResolvedOmnifyConfig, type Result, type SchemaCollection, type SchemaDefinition, type SchemaKind, type SchemaOptions, type SelectPropertyDefinition, type SqlColumnDefinition, type StringPropertyDefinition, type TypeScriptOutputConfig, type TypeScriptTypeInfo, err, ok };
@@ -0,0 +1,511 @@
1
+ /**
2
+ * @famgia/omnify-types - Schema Definition Types
3
+ *
4
+ * Core type definitions for schema objects, properties, and associations.
5
+ */
6
+ /**
7
+ * Built-in property types supported by omnify-schema.
8
+ * Custom types can be added via plugins.
9
+ */
10
+ type BuiltInPropertyType = 'String' | 'Int' | 'BigInt' | 'Float' | 'Boolean' | 'Text' | 'LongText' | 'Date' | 'Time' | 'Timestamp' | 'Json' | 'Email' | 'Password' | 'File' | 'MultiFile' | 'Enum' | 'Select' | 'Lookup' | 'Association' | 'Polymorphic';
11
+ /**
12
+ * Property type - can be a built-in type or a custom plugin type (string).
13
+ */
14
+ type PropertyType = BuiltInPropertyType | (string & {});
15
+ /**
16
+ * Relationship cardinality types for associations.
17
+ */
18
+ type AssociationRelation = 'OneToOne' | 'OneToMany' | 'ManyToOne' | 'ManyToMany';
19
+ /**
20
+ * Referential action for foreign key constraints.
21
+ */
22
+ type ReferentialAction = 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION';
23
+ /**
24
+ * Association property definition - defines a relationship to another schema.
25
+ */
26
+ interface AssociationDefinition {
27
+ /** Display name for the association */
28
+ readonly displayName?: string;
29
+ /** Must be 'Association' for association properties */
30
+ readonly type: 'Association';
31
+ /** Relationship cardinality */
32
+ readonly relation: AssociationRelation;
33
+ /** Target schema name (e.g., 'User', 'Product') */
34
+ readonly target: string;
35
+ /** Property name on the target schema that maps back (for bidirectional) */
36
+ readonly inversedBy?: string;
37
+ /** Property name on this schema that is mapped by target (for bidirectional) */
38
+ readonly mappedBy?: string;
39
+ /** Action when referenced record is deleted */
40
+ readonly onDelete?: ReferentialAction;
41
+ /** Action when referenced record is updated */
42
+ readonly onUpdate?: ReferentialAction;
43
+ /** Whether this side owns the relationship (has the foreign key) */
44
+ readonly owning?: boolean;
45
+ /** Custom join table name for ManyToMany */
46
+ readonly joinTable?: string;
47
+ }
48
+ /**
49
+ * Base property definition shared by all property types.
50
+ */
51
+ interface BasePropertyDefinition {
52
+ /** Property type (String, Int, Association, etc.) */
53
+ readonly type: PropertyType;
54
+ /** Human-readable display name */
55
+ readonly displayName?: string;
56
+ /** Whether the field can be null */
57
+ readonly nullable?: boolean;
58
+ /** Default value for the field */
59
+ readonly default?: unknown;
60
+ /** Whether this field must be unique */
61
+ readonly unique?: boolean;
62
+ /** Field description/comment */
63
+ readonly description?: string;
64
+ }
65
+ /**
66
+ * String property with length constraint.
67
+ */
68
+ interface StringPropertyDefinition extends BasePropertyDefinition {
69
+ readonly type: 'String' | 'Email' | 'Password';
70
+ /** Maximum character length */
71
+ readonly length?: number;
72
+ }
73
+ /**
74
+ * Numeric property definition.
75
+ */
76
+ interface NumericPropertyDefinition extends BasePropertyDefinition {
77
+ readonly type: 'Int' | 'BigInt' | 'Float';
78
+ /** Whether the number is unsigned (positive only) */
79
+ readonly unsigned?: boolean;
80
+ /** Precision for decimal types */
81
+ readonly precision?: number;
82
+ /** Scale for decimal types */
83
+ readonly scale?: number;
84
+ }
85
+ /**
86
+ * Enum property definition - references an enum.
87
+ */
88
+ interface EnumPropertyDefinition extends BasePropertyDefinition {
89
+ readonly type: 'Enum';
90
+ /** Enum name or inline enum values */
91
+ readonly enum: string | readonly string[];
92
+ }
93
+ /**
94
+ * Select/Lookup property definition.
95
+ */
96
+ interface SelectPropertyDefinition extends BasePropertyDefinition {
97
+ readonly type: 'Select' | 'Lookup';
98
+ /** Available options */
99
+ readonly options?: readonly string[];
100
+ /** Reference to another schema for lookup */
101
+ readonly source?: string;
102
+ }
103
+ /**
104
+ * Union type for all property definitions.
105
+ */
106
+ type PropertyDefinition = (BasePropertyDefinition & {
107
+ readonly type: PropertyType;
108
+ }) | StringPropertyDefinition | NumericPropertyDefinition | EnumPropertyDefinition | SelectPropertyDefinition | AssociationDefinition;
109
+ /**
110
+ * Index definition for database optimization.
111
+ */
112
+ interface IndexDefinition {
113
+ /** Columns to include in the index */
114
+ readonly columns: readonly string[];
115
+ /** Whether this is a unique index */
116
+ readonly unique?: boolean;
117
+ /** Custom index name */
118
+ readonly name?: string;
119
+ }
120
+ /**
121
+ * Schema-level options for behavior configuration.
122
+ */
123
+ interface SchemaOptions {
124
+ /** Add created_at and updated_at timestamp columns */
125
+ readonly timestamps?: boolean;
126
+ /** Add deleted_at column for soft deletes */
127
+ readonly softDelete?: boolean;
128
+ /** Columns that should be unique (simple unique constraints) */
129
+ readonly unique?: readonly string[] | readonly (readonly string[])[];
130
+ /** Database indexes for query optimization */
131
+ readonly indexes?: readonly IndexDefinition[];
132
+ /** Enable translations support */
133
+ readonly translations?: boolean;
134
+ /** Custom table name (defaults to pluralized snake_case of schema name) */
135
+ readonly tableName?: string;
136
+ /** Primary key type */
137
+ readonly primaryKeyType?: 'Int' | 'BigInt' | 'Uuid' | 'String';
138
+ /** Enable authenticatable trait (for User-like schemas) */
139
+ readonly authenticatable?: boolean;
140
+ /** Login ID field for authenticatable */
141
+ readonly authenticatableLoginIdField?: string;
142
+ /** Password field for authenticatable */
143
+ readonly authenticatablePasswordField?: string;
144
+ /** Guard name for authenticatable */
145
+ readonly authenticatableGuardName?: string;
146
+ }
147
+ /**
148
+ * Schema kind - determines how the schema is processed.
149
+ */
150
+ type SchemaKind = 'object' | 'enum';
151
+ /**
152
+ * Complete schema definition representing a database entity.
153
+ */
154
+ interface SchemaDefinition {
155
+ /** Schema kind (defaults to 'object') */
156
+ readonly kind?: SchemaKind;
157
+ /** Human-readable display name */
158
+ readonly displayName?: string;
159
+ /** Property to use as the title/label for records */
160
+ readonly titleIndex?: string;
161
+ /** Schema group for organization */
162
+ readonly group?: string;
163
+ /** Schema-level options */
164
+ readonly options?: SchemaOptions;
165
+ /** Property definitions */
166
+ readonly properties?: Readonly<Record<string, PropertyDefinition>>;
167
+ /** Enum values (when kind is 'enum') */
168
+ readonly values?: readonly string[];
169
+ }
170
+ /**
171
+ * Loaded schema with additional metadata.
172
+ */
173
+ interface LoadedSchema extends SchemaDefinition {
174
+ /** Schema name (derived from file name) */
175
+ readonly name: string;
176
+ /** File path where the schema was loaded from */
177
+ readonly filePath: string;
178
+ /** Relative path within schemas directory */
179
+ readonly relativePath: string;
180
+ }
181
+ /**
182
+ * Collection of loaded schemas indexed by name.
183
+ */
184
+ type SchemaCollection = Readonly<Record<string, LoadedSchema>>;
185
+
186
+ /**
187
+ * @famgia/omnify-types - Plugin Types
188
+ *
189
+ * Type definitions for omnify plugins that provide custom types.
190
+ */
191
+
192
+ /**
193
+ * SQL column definition for a custom type.
194
+ */
195
+ interface SqlColumnDefinition {
196
+ /** SQL type (e.g., 'VARCHAR', 'INT', 'TEXT') */
197
+ readonly sqlType: string;
198
+ /** Column length/size if applicable */
199
+ readonly length?: number;
200
+ /** Precision for decimal types */
201
+ readonly precision?: number;
202
+ /** Scale for decimal types */
203
+ readonly scale?: number;
204
+ /** Whether the column is nullable */
205
+ readonly nullable?: boolean;
206
+ /** Default value */
207
+ readonly default?: unknown;
208
+ }
209
+ /**
210
+ * TypeScript type information for code generation.
211
+ */
212
+ interface TypeScriptTypeInfo {
213
+ /** TypeScript type as a string (e.g., 'string', 'number', 'MyCustomType') */
214
+ readonly type: string;
215
+ /** Whether to import this type from somewhere */
216
+ readonly import?: {
217
+ readonly from: string;
218
+ readonly name: string;
219
+ };
220
+ }
221
+ /**
222
+ * Expanded field definition for compound types.
223
+ * Used when a single custom type expands to multiple database columns.
224
+ */
225
+ interface ExpandedFieldDefinition {
226
+ /** Field name suffix (appended to property name) */
227
+ readonly suffix: string;
228
+ /** SQL column definition */
229
+ readonly sql: SqlColumnDefinition;
230
+ /** TypeScript type for this field */
231
+ readonly typescript: TypeScriptTypeInfo;
232
+ }
233
+ /**
234
+ * Definition of a custom property type provided by a plugin.
235
+ */
236
+ interface CustomTypeDefinition {
237
+ /** Type name as used in schema files (e.g., 'JapanPhone') */
238
+ readonly name: string;
239
+ /**
240
+ * Description of this custom type.
241
+ */
242
+ readonly description?: string;
243
+ /**
244
+ * Whether this is a compound type that expands to multiple columns.
245
+ * If true, use `expand` to define the columns.
246
+ * If false or undefined, use `sql` and `typescript` for single column.
247
+ */
248
+ readonly compound?: boolean;
249
+ /**
250
+ * SQL column definition (for single-column types).
251
+ */
252
+ readonly sql?: SqlColumnDefinition;
253
+ /**
254
+ * TypeScript type info (for single-column types).
255
+ */
256
+ readonly typescript?: TypeScriptTypeInfo;
257
+ /**
258
+ * Expanded field definitions (for compound types).
259
+ * Each entry creates an additional column.
260
+ */
261
+ readonly expand?: readonly ExpandedFieldDefinition[];
262
+ /**
263
+ * Validation function for schema validation.
264
+ * @param value - The property definition using this type
265
+ * @returns Error message if invalid, undefined if valid
266
+ */
267
+ readonly validate?: (value: PropertyDefinition) => string | undefined;
268
+ }
269
+ /**
270
+ * Plugin context provided during plugin initialization.
271
+ */
272
+ interface PluginContext {
273
+ /** Current working directory */
274
+ readonly cwd: string;
275
+ /** Whether verbose logging is enabled */
276
+ readonly verbose: boolean;
277
+ /** Logger for plugin output */
278
+ readonly logger: PluginLogger;
279
+ }
280
+ /**
281
+ * Logger interface for plugin output.
282
+ */
283
+ interface PluginLogger {
284
+ /** Log debug message (only in verbose mode) */
285
+ debug(message: string): void;
286
+ /** Log info message */
287
+ info(message: string): void;
288
+ /** Log warning message */
289
+ warn(message: string): void;
290
+ /** Log error message */
291
+ error(message: string): void;
292
+ }
293
+ /**
294
+ * Plugin interface for extending omnify with custom types.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * const japanTypesPlugin: OmnifyPlugin = {
299
+ * name: '@famgia/omnify-japan',
300
+ * version: '1.0.0',
301
+ * types: [
302
+ * {
303
+ * name: 'JapanPhone',
304
+ * sql: { sqlType: 'VARCHAR', length: 15 },
305
+ * typescript: { type: 'string' },
306
+ * },
307
+ * {
308
+ * name: 'JapanAddress',
309
+ * compound: true,
310
+ * expand: [
311
+ * { suffix: '_postal', sql: { sqlType: 'VARCHAR', length: 8 }, typescript: { type: 'string' } },
312
+ * { suffix: '_prefecture', sql: { sqlType: 'VARCHAR', length: 10 }, typescript: { type: 'string' } },
313
+ * { suffix: '_city', sql: { sqlType: 'VARCHAR', length: 100 }, typescript: { type: 'string' } },
314
+ * { suffix: '_address', sql: { sqlType: 'VARCHAR', length: 255 }, typescript: { type: 'string' } },
315
+ * ],
316
+ * },
317
+ * ],
318
+ * };
319
+ * ```
320
+ */
321
+ interface OmnifyPlugin {
322
+ /** Plugin name (typically npm package name) */
323
+ readonly name: string;
324
+ /** Plugin version */
325
+ readonly version: string;
326
+ /**
327
+ * Custom type definitions provided by this plugin.
328
+ */
329
+ readonly types?: readonly CustomTypeDefinition[];
330
+ /**
331
+ * Optional setup function called when plugin is loaded.
332
+ * @param context - Plugin context with utilities
333
+ */
334
+ readonly setup?: (context: PluginContext) => void | Promise<void>;
335
+ /**
336
+ * Optional cleanup function called when plugin is unloaded.
337
+ */
338
+ readonly teardown?: () => void | Promise<void>;
339
+ }
340
+ /**
341
+ * Factory function type for creating plugins.
342
+ * Useful for plugins that need configuration.
343
+ */
344
+ type PluginFactory<TOptions = unknown> = (options?: TOptions) => OmnifyPlugin;
345
+
346
+ /**
347
+ * @famgia/omnify-types - Configuration Types
348
+ *
349
+ * Type definitions for omnify.config.ts configuration file.
350
+ */
351
+
352
+ /**
353
+ * Supported database drivers.
354
+ */
355
+ type DatabaseDriver = 'mysql' | 'pgsql' | 'postgres' | 'sqlite' | 'sqlsrv' | 'mariadb';
356
+ /**
357
+ * Database configuration for Atlas and migrations.
358
+ */
359
+ interface DatabaseConfig {
360
+ /** Database driver type */
361
+ readonly driver: DatabaseDriver;
362
+ /** Development database URL for Atlas diff operations */
363
+ readonly devUrl?: string;
364
+ /** Enable field comments in migrations (MySQL only) */
365
+ readonly enableFieldComments?: boolean;
366
+ }
367
+ /**
368
+ * Laravel output configuration.
369
+ */
370
+ interface LaravelOutputConfig {
371
+ /** Directory for generated migration files */
372
+ readonly migrationsPath: string;
373
+ /** Directory for generated model files */
374
+ readonly modelsPath?: string;
375
+ /** Model namespace */
376
+ readonly modelsNamespace?: string;
377
+ /** Directory for generated factory files */
378
+ readonly factoriesPath?: string;
379
+ /** Directory for generated enum files */
380
+ readonly enumsPath?: string;
381
+ /** Enum namespace */
382
+ readonly enumsNamespace?: string;
383
+ }
384
+ /**
385
+ * TypeScript output configuration.
386
+ */
387
+ interface TypeScriptOutputConfig {
388
+ /** Output file or directory for TypeScript types */
389
+ readonly path: string;
390
+ /** Whether to generate a single file or multiple files */
391
+ readonly singleFile?: boolean;
392
+ /** Whether to generate enum types */
393
+ readonly generateEnums?: boolean;
394
+ /** Whether to generate relationship types */
395
+ readonly generateRelationships?: boolean;
396
+ }
397
+ /**
398
+ * Combined output configuration.
399
+ */
400
+ interface OutputConfig {
401
+ /** Laravel migration and model output */
402
+ readonly laravel?: LaravelOutputConfig;
403
+ /** TypeScript type definitions output */
404
+ readonly typescript?: TypeScriptOutputConfig;
405
+ }
406
+ /**
407
+ * Main omnify configuration interface.
408
+ * Used in omnify.config.ts files.
409
+ */
410
+ interface OmnifyConfig {
411
+ /**
412
+ * Directory containing schema definition files.
413
+ * @default './schemas'
414
+ */
415
+ readonly schemasDir?: string;
416
+ /**
417
+ * Database configuration.
418
+ */
419
+ readonly database: DatabaseConfig;
420
+ /**
421
+ * Output configuration for generated files.
422
+ */
423
+ readonly output?: OutputConfig;
424
+ /**
425
+ * Plugins to load for custom types.
426
+ * Can be npm package names or plugin objects.
427
+ */
428
+ readonly plugins?: readonly (string | OmnifyPlugin)[];
429
+ /**
430
+ * Enable verbose logging.
431
+ * @default false
432
+ */
433
+ readonly verbose?: boolean;
434
+ /**
435
+ * Lock file path for tracking schema state.
436
+ * @default '.omnify.lock'
437
+ */
438
+ readonly lockFilePath?: string;
439
+ }
440
+ /**
441
+ * Resolved configuration with all defaults applied.
442
+ */
443
+ interface ResolvedOmnifyConfig extends Required<Omit<OmnifyConfig, 'plugins'>> {
444
+ readonly plugins: readonly OmnifyPlugin[];
445
+ }
446
+
447
+ /**
448
+ * @famgia/omnify-types - Error Types
449
+ *
450
+ * Type definitions for omnify error handling.
451
+ * Errors follow the format: file:line + message + suggestion
452
+ */
453
+ /**
454
+ * Error code categories:
455
+ * - E0xx: Configuration errors
456
+ * - E1xx: Schema parsing errors
457
+ * - E2xx: Schema validation errors
458
+ * - E3xx: Plugin errors
459
+ * - E4xx: Atlas/Database errors
460
+ * - E5xx: Generation errors
461
+ * - E9xx: Internal errors
462
+ */
463
+ type ErrorCode = 'E001' | 'E002' | 'E003' | 'E004' | 'E005' | 'E101' | 'E102' | 'E103' | 'E104' | 'E105' | 'E201' | 'E202' | 'E203' | 'E204' | 'E205' | 'E206' | 'E207' | 'E208' | 'E301' | 'E302' | 'E303' | 'E304' | 'E305' | 'E401' | 'E402' | 'E403' | 'E404' | 'E405' | 'E501' | 'E502' | 'E503' | 'E504' | 'E901' | 'E902';
464
+ /**
465
+ * Source location where an error occurred.
466
+ */
467
+ interface ErrorLocation {
468
+ /** File path where the error occurred */
469
+ readonly file?: string;
470
+ /** Line number (1-based) */
471
+ readonly line?: number;
472
+ /** Column number (1-based) */
473
+ readonly column?: number;
474
+ }
475
+ /**
476
+ * Structured error information for omnify errors.
477
+ */
478
+ interface OmnifyErrorInfo {
479
+ /** Error code (e.g., 'E201') */
480
+ readonly code: ErrorCode;
481
+ /** Human-readable error message */
482
+ readonly message: string;
483
+ /** Location where the error occurred */
484
+ readonly location?: ErrorLocation;
485
+ /** Suggested fix for the error */
486
+ readonly suggestion?: string;
487
+ /** Additional context or details */
488
+ readonly details?: Record<string, unknown>;
489
+ /** Original error if this wraps another error */
490
+ readonly cause?: Error;
491
+ }
492
+ /**
493
+ * Result type for operations that may fail.
494
+ */
495
+ type Result<T, E = OmnifyErrorInfo> = {
496
+ readonly ok: true;
497
+ readonly value: T;
498
+ } | {
499
+ readonly ok: false;
500
+ readonly error: E;
501
+ };
502
+ /**
503
+ * Helper to create a successful result.
504
+ */
505
+ declare function ok<T>(value: T): Result<T, never>;
506
+ /**
507
+ * Helper to create an error result.
508
+ */
509
+ declare function err<E>(error: E): Result<never, E>;
510
+
511
+ export { type AssociationDefinition, type AssociationRelation, type BasePropertyDefinition, type BuiltInPropertyType, type CustomTypeDefinition, type DatabaseConfig, type DatabaseDriver, type EnumPropertyDefinition, type ErrorCode, type ErrorLocation, type ExpandedFieldDefinition, type IndexDefinition, type LaravelOutputConfig, type LoadedSchema, type NumericPropertyDefinition, type OmnifyConfig, type OmnifyErrorInfo, type OmnifyPlugin, type OutputConfig, type PluginContext, type PluginFactory, type PluginLogger, type PropertyDefinition, type PropertyType, type ReferentialAction, type ResolvedOmnifyConfig, type Result, type SchemaCollection, type SchemaDefinition, type SchemaKind, type SchemaOptions, type SelectPropertyDefinition, type SqlColumnDefinition, type StringPropertyDefinition, type TypeScriptOutputConfig, type TypeScriptTypeInfo, err, ok };
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // src/errors.ts
2
+ function ok(value) {
3
+ return { ok: true, value };
4
+ }
5
+ function err(error) {
6
+ return { ok: false, error };
7
+ }
8
+ export {
9
+ err,
10
+ ok
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * @famgia/omnify-types - Error Types\n *\n * Type definitions for omnify error handling.\n * Errors follow the format: file:line + message + suggestion\n */\n\n// ============================================================================\n// Error Codes\n// ============================================================================\n\n/**\n * Error code categories:\n * - E0xx: Configuration errors\n * - E1xx: Schema parsing errors\n * - E2xx: Schema validation errors\n * - E3xx: Plugin errors\n * - E4xx: Atlas/Database errors\n * - E5xx: Generation errors\n * - E9xx: Internal errors\n */\nexport type ErrorCode =\n // Configuration errors (E0xx)\n | 'E001' // Config file not found\n | 'E002' // Invalid config format\n | 'E003' // Missing required config field\n | 'E004' // Invalid database driver\n | 'E005' // Invalid output path\n // Schema parsing errors (E1xx)\n | 'E101' // Schema file not found\n | 'E102' // Invalid YAML syntax\n | 'E103' // Invalid JSON syntax\n | 'E104' // Empty schema file\n | 'E105' // Schema read error\n // Schema validation errors (E2xx)\n | 'E201' // Invalid property type\n | 'E202' // Missing required field\n | 'E203' // Invalid association target\n | 'E204' // Circular reference detected\n | 'E205' // Duplicate schema name\n | 'E206' // Invalid schema options\n | 'E207' // Invalid enum values\n | 'E208' // Orphaned inverse relation\n // Plugin errors (E3xx)\n | 'E301' // Plugin not found\n | 'E302' // Plugin load error\n | 'E303' // Invalid plugin format\n | 'E304' // Plugin type conflict\n | 'E305' // Plugin setup error\n // Atlas/Database errors (E4xx)\n | 'E401' // Atlas CLI not found\n | 'E402' // Atlas diff failed\n | 'E403' // Database connection error\n | 'E404' // HCL generation error\n | 'E405' // Lock file error\n // Generation errors (E5xx)\n | 'E501' // Migration generation failed\n | 'E502' // TypeScript generation failed\n | 'E503' // Output write error\n | 'E504' // Template error\n // Internal errors (E9xx)\n | 'E901' // Unexpected error\n | 'E902'; // Not implemented\n\n// ============================================================================\n// Error Info\n// ============================================================================\n\n/**\n * Source location where an error occurred.\n */\nexport interface ErrorLocation {\n /** File path where the error occurred */\n readonly file?: string;\n /** Line number (1-based) */\n readonly line?: number;\n /** Column number (1-based) */\n readonly column?: number;\n}\n\n/**\n * Structured error information for omnify errors.\n */\nexport interface OmnifyErrorInfo {\n /** Error code (e.g., 'E201') */\n readonly code: ErrorCode;\n /** Human-readable error message */\n readonly message: string;\n /** Location where the error occurred */\n readonly location?: ErrorLocation;\n /** Suggested fix for the error */\n readonly suggestion?: string;\n /** Additional context or details */\n readonly details?: Record<string, unknown>;\n /** Original error if this wraps another error */\n readonly cause?: Error;\n}\n\n/**\n * Result type for operations that may fail.\n */\nexport type Result<T, E = OmnifyErrorInfo> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly error: E };\n\n/**\n * Helper to create a successful result.\n */\nexport function ok<T>(value: T): Result<T, never> {\n return { ok: true, value };\n}\n\n/**\n * Helper to create an error result.\n */\nexport function err<E>(error: E): Result<never, E> {\n return { ok: false, error };\n}\n"],"mappings":";AA4GO,SAAS,GAAM,OAA4B;AAChD,SAAO,EAAE,IAAI,MAAM,MAAM;AAC3B;AAKO,SAAS,IAAO,OAA4B;AACjD,SAAO,EAAE,IAAI,OAAO,MAAM;AAC5B;","names":[]}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@famgia/omnify-types",
3
+ "version": "0.0.1",
4
+ "description": "Shared TypeScript types for omnify-schema",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "clean": "rm -rf dist",
22
+ "test": "vitest run --passWithNoTests",
23
+ "test:watch": "vitest",
24
+ "lint": "eslint src"
25
+ }
26
+ }