@famgia/omnify-types 0.0.21 → 0.0.22
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.map +1 -1
- package/dist/index.d.cts +109 -2
- package/dist/index.d.ts +109 -2
- package/package.json +2 -2
- package/schemas/omnify-schema.json +29 -2
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/i18n.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 PivotFieldDefinition,\n AssociationDefinition,\n // Property definitions\n BasePropertyDefinition,\n StringPropertyDefinition,\n NumericPropertyDefinition,\n EnumPropertyDefinition,\n EnumRefPropertyDefinition,\n FilePropertyDefinition,\n InlineEnumValue,\n PropertyDefinition,\n // Schema options\n IdType,\n IndexType,\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 PluginEnumDefinition,\n PluginEnumValue,\n // Generator types\n GeneratorOutputType,\n GeneratorOutput,\n GeneratorContext,\n GeneratorDefinition,\n // Schema change types\n PropertySnapshot,\n IndexSnapshot,\n SchemaChangeType,\n ColumnChange,\n IndexChange,\n SchemaChange,\n // Plugin config schema (WordPress-like)\n PluginConfigFieldType,\n PluginConfigSelectOption,\n PluginConfigField,\n PluginConfigSchema,\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// ============================================================================\n// Internationalization (i18n) Types\n// ============================================================================\n\nexport type {\n LocaleCode,\n LocaleMap,\n LocalizedString,\n LocaleConfig,\n LocaleResolutionOptions,\n} from './i18n.js';\n\nexport {\n DEFAULT_LOCALE_CONFIG,\n isLocaleMap,\n isLocalizedString,\n resolveLocalizedString,\n getAvailableLocales,\n toLocaleMap,\n mergeLocalizedStrings,\n} from './i18n.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","/**\n * @famgia/omnify-types - Internationalization (i18n) Types\n *\n * Types for multi-language support in schema definitions.\n * Supports displayName, description, and other localizable strings.\n */\n\n// ============================================================================\n// Locale Types\n// ============================================================================\n\n/**\n * Supported locale code format (ISO 639-1 language codes).\n * Examples: 'en', 'ja', 'vi', 'zh', 'ko', 'fr', 'de', 'es', 'pt'\n */\nexport type LocaleCode = string;\n\n/**\n * Map of locale codes to localized strings.\n * @example { en: 'User Name', ja: 'ユーザー名', vi: 'Tên người dùng' }\n */\nexport type LocaleMap = Readonly<Record<LocaleCode, string>>;\n\n/**\n * Localized string - can be either a simple string (default locale)\n * or a map of locale codes to localized strings.\n *\n * @example\n * // Simple string (uses default locale)\n * displayName: \"User Name\"\n *\n * // Multi-language object\n * displayName:\n * en: \"User Name\"\n * ja: \"ユーザー名\"\n * vi: \"Tên người dùng\"\n */\nexport type LocalizedString = string | LocaleMap;\n\n// ============================================================================\n// Locale Configuration\n// ============================================================================\n\n/**\n * Locale configuration for omnify projects.\n * Configured in .omnify.yaml or omnify.config.ts\n */\nexport interface LocaleConfig {\n /**\n * List of supported locale codes.\n * @default ['en']\n * @example ['en', 'ja', 'vi']\n */\n readonly locales: readonly LocaleCode[];\n\n /**\n * Default locale code used when:\n * - displayName is a simple string\n * - Requested locale is not found and no fallback matches\n * @default 'en'\n */\n readonly defaultLocale: LocaleCode;\n\n /**\n * Fallback locale code used when requested locale is not found.\n * If not set, falls back to defaultLocale.\n * @example 'en' - If 'ko' not found, try 'en' before defaultLocale\n */\n readonly fallbackLocale?: LocaleCode;\n}\n\n/**\n * Default locale configuration.\n */\nexport const DEFAULT_LOCALE_CONFIG: LocaleConfig = {\n locales: ['en'],\n defaultLocale: 'en',\n};\n\n// ============================================================================\n// Resolution Options\n// ============================================================================\n\n/**\n * Options for resolving localized strings.\n */\nexport interface LocaleResolutionOptions {\n /**\n * Locale to resolve to.\n * If not provided, uses defaultLocale from config.\n */\n readonly locale?: LocaleCode;\n\n /**\n * Locale configuration.\n * If not provided, uses DEFAULT_LOCALE_CONFIG.\n */\n readonly config?: LocaleConfig;\n\n /**\n * Whether to throw an error if locale is not found.\n * If false, returns undefined for missing locales.\n * @default false\n */\n readonly strict?: boolean;\n}\n\n// ============================================================================\n// Utility Type Guards\n// ============================================================================\n\n/**\n * Check if a value is a LocaleMap (object with locale keys).\n */\nexport function isLocaleMap(value: unknown): value is LocaleMap {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n // Check that all values are strings\n return Object.values(value).every(v => typeof v === 'string');\n}\n\n/**\n * Check if a value is a LocalizedString.\n */\nexport function isLocalizedString(value: unknown): value is LocalizedString {\n return typeof value === 'string' || isLocaleMap(value);\n}\n\n// ============================================================================\n// Resolution Functions\n// ============================================================================\n\n/**\n * Resolve a localized string to a specific locale.\n *\n * Resolution order:\n * 1. Requested locale (if provided)\n * 2. Fallback locale (if configured)\n * 3. Default locale\n * 4. First available locale (if none of the above match)\n * 5. undefined (if strict=false) or throws error (if strict=true)\n *\n * @param value - The localized string value\n * @param options - Resolution options\n * @returns The resolved string or undefined\n *\n * @example\n * // Simple string\n * resolveLocalizedString('Hello') // => 'Hello'\n *\n * // Multi-language with locale\n * resolveLocalizedString({ en: 'Hello', ja: 'こんにちは' }, { locale: 'ja' })\n * // => 'こんにちは'\n *\n * // Multi-language with fallback\n * resolveLocalizedString({ en: 'Hello', ja: 'こんにちは' }, { locale: 'ko' })\n * // => 'Hello' (falls back to defaultLocale)\n */\nexport function resolveLocalizedString(\n value: LocalizedString | undefined | null,\n options: LocaleResolutionOptions = {}\n): string | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n // Simple string - return as-is\n if (typeof value === 'string') {\n return value;\n }\n\n const config = options.config ?? DEFAULT_LOCALE_CONFIG;\n const requestedLocale = options.locale ?? config.defaultLocale;\n\n // Try requested locale\n if (requestedLocale in value) {\n return value[requestedLocale];\n }\n\n // Try fallback locale\n if (config.fallbackLocale && config.fallbackLocale in value) {\n return value[config.fallbackLocale];\n }\n\n // Try default locale\n if (config.defaultLocale in value) {\n return value[config.defaultLocale];\n }\n\n // Try first available locale\n const availableLocales = Object.keys(value);\n const firstLocale = availableLocales[0];\n if (firstLocale !== undefined) {\n return value[firstLocale];\n }\n\n // No locale found\n if (options.strict) {\n throw new Error(\n `Locale '${requestedLocale}' not found in localized string. ` +\n `Available locales: none`\n );\n }\n\n return undefined;\n}\n\n/**\n * Get all available locales from a localized string.\n *\n * @param value - The localized string value\n * @returns Array of available locale codes, or ['default'] for simple strings\n */\nexport function getAvailableLocales(\n value: LocalizedString | undefined | null\n): readonly LocaleCode[] {\n if (value === undefined || value === null) {\n return [];\n }\n\n if (typeof value === 'string') {\n return ['default'];\n }\n\n return Object.keys(value);\n}\n\n/**\n * Convert a localized string to a full LocaleMap.\n * Simple strings are converted to { [defaultLocale]: value }.\n *\n * @param value - The localized string value\n * @param defaultLocale - Default locale for simple strings\n * @returns LocaleMap or undefined\n */\nexport function toLocaleMap(\n value: LocalizedString | undefined | null,\n defaultLocale: LocaleCode = 'en'\n): LocaleMap | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (typeof value === 'string') {\n return { [defaultLocale]: value };\n }\n\n return value;\n}\n\n/**\n * Merge two localized strings, with the second taking precedence.\n *\n * @param base - Base localized string\n * @param override - Override localized string\n * @param defaultLocale - Default locale for simple strings\n * @returns Merged LocaleMap\n */\nexport function mergeLocalizedStrings(\n base: LocalizedString | undefined | null,\n override: LocalizedString | undefined | null,\n defaultLocale: LocaleCode = 'en'\n): LocaleMap | undefined {\n const baseMap = toLocaleMap(base, defaultLocale);\n const overrideMap = toLocaleMap(override, defaultLocale);\n\n if (!baseMap && !overrideMap) {\n return undefined;\n }\n\n return {\n ...baseMap,\n ...overrideMap,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;;;AC3CO,IAAM,wBAAsC;AAAA,EACjD,SAAS,CAAC,IAAI;AAAA,EACd,eAAe;AACjB;AAqCO,SAAS,YAAY,OAAoC;AAC9D,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,OAAO,KAAK,EAAE,MAAM,OAAK,OAAO,MAAM,QAAQ;AAC9D;AAKO,SAAS,kBAAkB,OAA0C;AAC1E,SAAO,OAAO,UAAU,YAAY,YAAY,KAAK;AACvD;AAgCO,SAAS,uBACd,OACA,UAAmC,CAAC,GAChB;AACpB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,kBAAkB,QAAQ,UAAU,OAAO;AAGjD,MAAI,mBAAmB,OAAO;AAC5B,WAAO,MAAM,eAAe;AAAA,EAC9B;AAGA,MAAI,OAAO,kBAAkB,OAAO,kBAAkB,OAAO;AAC3D,WAAO,MAAM,OAAO,cAAc;AAAA,EACpC;AAGA,MAAI,OAAO,iBAAiB,OAAO;AACjC,WAAO,MAAM,OAAO,aAAa;AAAA,EACnC;AAGA,QAAM,mBAAmB,OAAO,KAAK,KAAK;AAC1C,QAAM,cAAc,iBAAiB,CAAC;AACtC,MAAI,gBAAgB,QAAW;AAC7B,WAAO,MAAM,WAAW;AAAA,EAC1B;AAGA,MAAI,QAAQ,QAAQ;AAClB,UAAM,IAAI;AAAA,MACR,WAAW,eAAe;AAAA,IAE5B;AAAA,EACF;AAEA,SAAO;AACT;AAQO,SAAS,oBACd,OACuB;AACvB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,CAAC,SAAS;AAAA,EACnB;AAEA,SAAO,OAAO,KAAK,KAAK;AAC1B;AAUO,SAAS,YACd,OACA,gBAA4B,MACL;AACvB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,EAAE,CAAC,aAAa,GAAG,MAAM;AAAA,EAClC;AAEA,SAAO;AACT;AAUO,SAAS,sBACd,MACA,UACA,gBAA4B,MACL;AACvB,QAAM,UAAU,YAAY,MAAM,aAAa;AAC/C,QAAM,cAAc,YAAY,UAAU,aAAa;AAEvD,MAAI,CAAC,WAAW,CAAC,aAAa;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/i18n.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 PivotFieldDefinition,\n AssociationDefinition,\n // Validation rules\n ValidationRules,\n // Property definitions\n BasePropertyDefinition,\n CompoundFieldOverride,\n StringPropertyDefinition,\n NumericPropertyDefinition,\n EnumPropertyDefinition,\n EnumRefPropertyDefinition,\n FilePropertyDefinition,\n InlineEnumValue,\n PropertyDefinition,\n // Schema options\n IdType,\n IndexType,\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 CompoundTypeAccessor,\n CustomTypeDefinition,\n // Plugin interface\n PluginContext,\n PluginLogger,\n OmnifyPlugin,\n PluginFactory,\n PluginEnumDefinition,\n PluginEnumValue,\n // Generator types\n GeneratorOutputType,\n GeneratorOutput,\n GeneratorContext,\n GeneratorDefinition,\n // Schema change types\n PropertySnapshot,\n IndexSnapshot,\n SchemaChangeType,\n ColumnChange,\n IndexChange,\n SchemaChange,\n // Plugin config schema (WordPress-like)\n PluginConfigFieldType,\n PluginConfigSelectOption,\n PluginConfigField,\n PluginConfigSchema,\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// ============================================================================\n// Internationalization (i18n) Types\n// ============================================================================\n\nexport type {\n LocaleCode,\n LocaleMap,\n LocalizedString,\n LocaleConfig,\n LocaleResolutionOptions,\n} from './i18n.js';\n\nexport {\n DEFAULT_LOCALE_CONFIG,\n isLocaleMap,\n isLocalizedString,\n resolveLocalizedString,\n getAvailableLocales,\n toLocaleMap,\n mergeLocalizedStrings,\n} from './i18n.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","/**\n * @famgia/omnify-types - Internationalization (i18n) Types\n *\n * Types for multi-language support in schema definitions.\n * Supports displayName, description, and other localizable strings.\n */\n\n// ============================================================================\n// Locale Types\n// ============================================================================\n\n/**\n * Supported locale code format (ISO 639-1 language codes).\n * Examples: 'en', 'ja', 'vi', 'zh', 'ko', 'fr', 'de', 'es', 'pt'\n */\nexport type LocaleCode = string;\n\n/**\n * Map of locale codes to localized strings.\n * @example { en: 'User Name', ja: 'ユーザー名', vi: 'Tên người dùng' }\n */\nexport type LocaleMap = Readonly<Record<LocaleCode, string>>;\n\n/**\n * Localized string - can be either a simple string (default locale)\n * or a map of locale codes to localized strings.\n *\n * @example\n * // Simple string (uses default locale)\n * displayName: \"User Name\"\n *\n * // Multi-language object\n * displayName:\n * en: \"User Name\"\n * ja: \"ユーザー名\"\n * vi: \"Tên người dùng\"\n */\nexport type LocalizedString = string | LocaleMap;\n\n// ============================================================================\n// Locale Configuration\n// ============================================================================\n\n/**\n * Locale configuration for omnify projects.\n * Configured in .omnify.yaml or omnify.config.ts\n */\nexport interface LocaleConfig {\n /**\n * List of supported locale codes.\n * @default ['en']\n * @example ['en', 'ja', 'vi']\n */\n readonly locales: readonly LocaleCode[];\n\n /**\n * Default locale code used when:\n * - displayName is a simple string\n * - Requested locale is not found and no fallback matches\n * @default 'en'\n */\n readonly defaultLocale: LocaleCode;\n\n /**\n * Fallback locale code used when requested locale is not found.\n * If not set, falls back to defaultLocale.\n * @example 'en' - If 'ko' not found, try 'en' before defaultLocale\n */\n readonly fallbackLocale?: LocaleCode;\n}\n\n/**\n * Default locale configuration.\n */\nexport const DEFAULT_LOCALE_CONFIG: LocaleConfig = {\n locales: ['en'],\n defaultLocale: 'en',\n};\n\n// ============================================================================\n// Resolution Options\n// ============================================================================\n\n/**\n * Options for resolving localized strings.\n */\nexport interface LocaleResolutionOptions {\n /**\n * Locale to resolve to.\n * If not provided, uses defaultLocale from config.\n */\n readonly locale?: LocaleCode;\n\n /**\n * Locale configuration.\n * If not provided, uses DEFAULT_LOCALE_CONFIG.\n */\n readonly config?: LocaleConfig;\n\n /**\n * Whether to throw an error if locale is not found.\n * If false, returns undefined for missing locales.\n * @default false\n */\n readonly strict?: boolean;\n}\n\n// ============================================================================\n// Utility Type Guards\n// ============================================================================\n\n/**\n * Check if a value is a LocaleMap (object with locale keys).\n */\nexport function isLocaleMap(value: unknown): value is LocaleMap {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n // Check that all values are strings\n return Object.values(value).every(v => typeof v === 'string');\n}\n\n/**\n * Check if a value is a LocalizedString.\n */\nexport function isLocalizedString(value: unknown): value is LocalizedString {\n return typeof value === 'string' || isLocaleMap(value);\n}\n\n// ============================================================================\n// Resolution Functions\n// ============================================================================\n\n/**\n * Resolve a localized string to a specific locale.\n *\n * Resolution order:\n * 1. Requested locale (if provided)\n * 2. Fallback locale (if configured)\n * 3. Default locale\n * 4. First available locale (if none of the above match)\n * 5. undefined (if strict=false) or throws error (if strict=true)\n *\n * @param value - The localized string value\n * @param options - Resolution options\n * @returns The resolved string or undefined\n *\n * @example\n * // Simple string\n * resolveLocalizedString('Hello') // => 'Hello'\n *\n * // Multi-language with locale\n * resolveLocalizedString({ en: 'Hello', ja: 'こんにちは' }, { locale: 'ja' })\n * // => 'こんにちは'\n *\n * // Multi-language with fallback\n * resolveLocalizedString({ en: 'Hello', ja: 'こんにちは' }, { locale: 'ko' })\n * // => 'Hello' (falls back to defaultLocale)\n */\nexport function resolveLocalizedString(\n value: LocalizedString | undefined | null,\n options: LocaleResolutionOptions = {}\n): string | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n // Simple string - return as-is\n if (typeof value === 'string') {\n return value;\n }\n\n const config = options.config ?? DEFAULT_LOCALE_CONFIG;\n const requestedLocale = options.locale ?? config.defaultLocale;\n\n // Try requested locale\n if (requestedLocale in value) {\n return value[requestedLocale];\n }\n\n // Try fallback locale\n if (config.fallbackLocale && config.fallbackLocale in value) {\n return value[config.fallbackLocale];\n }\n\n // Try default locale\n if (config.defaultLocale in value) {\n return value[config.defaultLocale];\n }\n\n // Try first available locale\n const availableLocales = Object.keys(value);\n const firstLocale = availableLocales[0];\n if (firstLocale !== undefined) {\n return value[firstLocale];\n }\n\n // No locale found\n if (options.strict) {\n throw new Error(\n `Locale '${requestedLocale}' not found in localized string. ` +\n `Available locales: none`\n );\n }\n\n return undefined;\n}\n\n/**\n * Get all available locales from a localized string.\n *\n * @param value - The localized string value\n * @returns Array of available locale codes, or ['default'] for simple strings\n */\nexport function getAvailableLocales(\n value: LocalizedString | undefined | null\n): readonly LocaleCode[] {\n if (value === undefined || value === null) {\n return [];\n }\n\n if (typeof value === 'string') {\n return ['default'];\n }\n\n return Object.keys(value);\n}\n\n/**\n * Convert a localized string to a full LocaleMap.\n * Simple strings are converted to { [defaultLocale]: value }.\n *\n * @param value - The localized string value\n * @param defaultLocale - Default locale for simple strings\n * @returns LocaleMap or undefined\n */\nexport function toLocaleMap(\n value: LocalizedString | undefined | null,\n defaultLocale: LocaleCode = 'en'\n): LocaleMap | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (typeof value === 'string') {\n return { [defaultLocale]: value };\n }\n\n return value;\n}\n\n/**\n * Merge two localized strings, with the second taking precedence.\n *\n * @param base - Base localized string\n * @param override - Override localized string\n * @param defaultLocale - Default locale for simple strings\n * @returns Merged LocaleMap\n */\nexport function mergeLocalizedStrings(\n base: LocalizedString | undefined | null,\n override: LocalizedString | undefined | null,\n defaultLocale: LocaleCode = 'en'\n): LocaleMap | undefined {\n const baseMap = toLocaleMap(base, defaultLocale);\n const overrideMap = toLocaleMap(override, defaultLocale);\n\n if (!baseMap && !overrideMap) {\n return undefined;\n }\n\n return {\n ...baseMap,\n ...overrideMap,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;;;AC3CO,IAAM,wBAAsC;AAAA,EACjD,SAAS,CAAC,IAAI;AAAA,EACd,eAAe;AACjB;AAqCO,SAAS,YAAY,OAAoC;AAC9D,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,OAAO,KAAK,EAAE,MAAM,OAAK,OAAO,MAAM,QAAQ;AAC9D;AAKO,SAAS,kBAAkB,OAA0C;AAC1E,SAAO,OAAO,UAAU,YAAY,YAAY,KAAK;AACvD;AAgCO,SAAS,uBACd,OACA,UAAmC,CAAC,GAChB;AACpB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,kBAAkB,QAAQ,UAAU,OAAO;AAGjD,MAAI,mBAAmB,OAAO;AAC5B,WAAO,MAAM,eAAe;AAAA,EAC9B;AAGA,MAAI,OAAO,kBAAkB,OAAO,kBAAkB,OAAO;AAC3D,WAAO,MAAM,OAAO,cAAc;AAAA,EACpC;AAGA,MAAI,OAAO,iBAAiB,OAAO;AACjC,WAAO,MAAM,OAAO,aAAa;AAAA,EACnC;AAGA,QAAM,mBAAmB,OAAO,KAAK,KAAK;AAC1C,QAAM,cAAc,iBAAiB,CAAC;AACtC,MAAI,gBAAgB,QAAW;AAC7B,WAAO,MAAM,WAAW;AAAA,EAC1B;AAGA,MAAI,QAAQ,QAAQ;AAClB,UAAM,IAAI;AAAA,MACR,WAAW,eAAe;AAAA,IAE5B;AAAA,EACF;AAEA,SAAO;AACT;AAQO,SAAS,oBACd,OACuB;AACvB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,CAAC,SAAS;AAAA,EACnB;AAEA,SAAO,OAAO,KAAK,KAAK;AAC1B;AAUO,SAAS,YACd,OACA,gBAA4B,MACL;AACvB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,EAAE,CAAC,aAAa,GAAG,MAAM;AAAA,EAClC;AAEA,SAAO;AACT;AAUO,SAAS,sBACd,MACA,UACA,gBAA4B,MACL;AACvB,QAAM,UAAU,YAAY,MAAM,aAAa;AAC/C,QAAM,cAAc,YAAY,UAAU,aAAa;AAEvD,MAAI,CAAC,WAAW,CAAC,aAAa;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -206,6 +206,30 @@ interface AssociationDefinition {
|
|
|
206
206
|
/** Additional fields on the pivot table (for ManyToMany, MorphToMany) */
|
|
207
207
|
readonly pivotFields?: Readonly<Record<string, PivotFieldDefinition>>;
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Validation rules for a property.
|
|
211
|
+
* These are for application-level validation ONLY, NOT database structure.
|
|
212
|
+
* Database structure is controlled by: nullable, length, unique, etc.
|
|
213
|
+
*/
|
|
214
|
+
interface ValidationRules {
|
|
215
|
+
/**
|
|
216
|
+
* Whether the field is required (validation only).
|
|
217
|
+
* This does NOT affect database nullable - use 'nullable' for database.
|
|
218
|
+
* Recommended: set nullable: false if required: true, but this is manual.
|
|
219
|
+
*/
|
|
220
|
+
readonly required?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Minimum length validation (for String, Email, Password types only).
|
|
223
|
+
* Validation rule only - does NOT affect database.
|
|
224
|
+
*/
|
|
225
|
+
readonly minLength?: number;
|
|
226
|
+
/**
|
|
227
|
+
* Maximum length validation (for String, Email, Password types only).
|
|
228
|
+
* Must be <= property 'length' (database column size).
|
|
229
|
+
* Validation rule only - does NOT affect database.
|
|
230
|
+
*/
|
|
231
|
+
readonly maxLength?: number;
|
|
232
|
+
}
|
|
209
233
|
/**
|
|
210
234
|
* Base property definition shared by all property types.
|
|
211
235
|
*/
|
|
@@ -224,6 +248,45 @@ interface BasePropertyDefinition {
|
|
|
224
248
|
readonly description?: LocalizedString;
|
|
225
249
|
/** Previous field name for rename migrations (remove after migration runs) */
|
|
226
250
|
readonly renamedFrom?: string;
|
|
251
|
+
/** Validation rules (application-level only, NOT database) */
|
|
252
|
+
readonly rules?: ValidationRules;
|
|
253
|
+
/**
|
|
254
|
+
* Whether this field should be hidden in API responses/serialization.
|
|
255
|
+
* In Laravel, this adds the field to the $hidden array.
|
|
256
|
+
* Password type is automatically hidden.
|
|
257
|
+
*/
|
|
258
|
+
readonly hidden?: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Whether this field is mass assignable.
|
|
261
|
+
* In Laravel, this controls the $fillable array.
|
|
262
|
+
* @default true (all non-association fields are fillable by default)
|
|
263
|
+
*/
|
|
264
|
+
readonly fillable?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Per-field settings for compound types.
|
|
267
|
+
* Allows overriding nullable, hidden, fillable for specific expanded fields.
|
|
268
|
+
* Field names should match the suffix defined in the compound type (e.g., 'LastName', 'FirstName').
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* fields:
|
|
272
|
+
* LastNameKana:
|
|
273
|
+
* nullable: true
|
|
274
|
+
* FirstNameKana:
|
|
275
|
+
* nullable: true
|
|
276
|
+
* hidden: true
|
|
277
|
+
*/
|
|
278
|
+
readonly fields?: Readonly<Record<string, CompoundFieldOverride>>;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Override settings for a specific expanded field in a compound type.
|
|
282
|
+
*/
|
|
283
|
+
interface CompoundFieldOverride {
|
|
284
|
+
/** Override nullable for this field */
|
|
285
|
+
readonly nullable?: boolean;
|
|
286
|
+
/** Override hidden for this field */
|
|
287
|
+
readonly hidden?: boolean;
|
|
288
|
+
/** Override fillable for this field */
|
|
289
|
+
readonly fillable?: boolean;
|
|
227
290
|
}
|
|
228
291
|
/**
|
|
229
292
|
* String property with length constraint.
|
|
@@ -250,7 +313,8 @@ interface NumericPropertyDefinition extends BasePropertyDefinition {
|
|
|
250
313
|
*/
|
|
251
314
|
interface InlineEnumValue {
|
|
252
315
|
readonly value: string;
|
|
253
|
-
|
|
316
|
+
/** Display label - supports multi-language (string or locale map) */
|
|
317
|
+
readonly label?: LocalizedString;
|
|
254
318
|
readonly extra?: Readonly<Record<string, string | number | boolean>>;
|
|
255
319
|
}
|
|
256
320
|
/**
|
|
@@ -410,6 +474,8 @@ interface SqlColumnDefinition {
|
|
|
410
474
|
readonly nullable?: boolean;
|
|
411
475
|
/** Default value */
|
|
412
476
|
readonly default?: unknown;
|
|
477
|
+
/** Whether the column is unsigned (for integer types) */
|
|
478
|
+
readonly unsigned?: boolean;
|
|
413
479
|
}
|
|
414
480
|
/**
|
|
415
481
|
* TypeScript type information for code generation.
|
|
@@ -436,6 +502,33 @@ interface ExpandedFieldDefinition {
|
|
|
436
502
|
readonly typescript?: TypeScriptTypeInfo;
|
|
437
503
|
/** Reference to a shared enum schema (overrides sql/typescript) */
|
|
438
504
|
readonly enumRef?: string;
|
|
505
|
+
/** Laravel cast type for this field */
|
|
506
|
+
readonly cast?: string;
|
|
507
|
+
/** Default nullable for this field (can be overridden in schema) */
|
|
508
|
+
readonly nullable?: boolean;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Accessor definition for compound types.
|
|
512
|
+
* Defines computed properties that combine multiple fields.
|
|
513
|
+
*/
|
|
514
|
+
interface CompoundTypeAccessor {
|
|
515
|
+
/** Accessor name (will be used as attribute name, e.g., 'full_name') */
|
|
516
|
+
readonly name: string;
|
|
517
|
+
/**
|
|
518
|
+
* Fields to combine (suffixes without underscore prefix).
|
|
519
|
+
* e.g., ['last_name', 'first_name']
|
|
520
|
+
*/
|
|
521
|
+
readonly fields: readonly string[];
|
|
522
|
+
/**
|
|
523
|
+
* Separator between fields.
|
|
524
|
+
* @default ' '
|
|
525
|
+
*/
|
|
526
|
+
readonly separator?: string;
|
|
527
|
+
/**
|
|
528
|
+
* Order of fields (if different from definition order).
|
|
529
|
+
* Use field suffixes. If not specified, uses `fields` order.
|
|
530
|
+
*/
|
|
531
|
+
readonly order?: readonly string[];
|
|
439
532
|
}
|
|
440
533
|
/**
|
|
441
534
|
* Definition of a custom property type provided by a plugin.
|
|
@@ -466,6 +559,18 @@ interface CustomTypeDefinition {
|
|
|
466
559
|
* Each entry creates an additional column.
|
|
467
560
|
*/
|
|
468
561
|
readonly expand?: readonly ExpandedFieldDefinition[];
|
|
562
|
+
/**
|
|
563
|
+
* Accessor definitions for compound types.
|
|
564
|
+
* Creates computed properties that combine multiple fields.
|
|
565
|
+
* In Laravel, generates get{Name}Attribute() methods.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* accessors: [
|
|
569
|
+
* { name: 'full_name', fields: ['last_name', 'first_name'] },
|
|
570
|
+
* { name: 'full_name_kana', fields: ['last_name_kana', 'first_name_kana'] },
|
|
571
|
+
* ]
|
|
572
|
+
*/
|
|
573
|
+
readonly accessors?: readonly CompoundTypeAccessor[];
|
|
469
574
|
/**
|
|
470
575
|
* Additional fields valid for this custom type (beyond base fields).
|
|
471
576
|
* Base fields (type, displayName, nullable, default, unique, description, renamedFrom)
|
|
@@ -717,6 +822,8 @@ interface GeneratorContext {
|
|
|
717
822
|
readonly previousOutputs: ReadonlyMap<string, readonly GeneratorOutput[]>;
|
|
718
823
|
/** Custom types registered by all plugins (for compound type expansion) */
|
|
719
824
|
readonly customTypes: ReadonlyMap<string, CustomTypeDefinition>;
|
|
825
|
+
/** Locale configuration for multi-language support */
|
|
826
|
+
readonly localeConfig?: LocaleConfig | undefined;
|
|
720
827
|
}
|
|
721
828
|
/**
|
|
722
829
|
* Definition of a generator provided by a plugin.
|
|
@@ -979,4 +1086,4 @@ declare function ok<T>(value: T): Result<T, never>;
|
|
|
979
1086
|
*/
|
|
980
1087
|
declare function err<E>(error: E): Result<never, E>;
|
|
981
1088
|
|
|
982
|
-
export { type AssociationDefinition, type AssociationRelation, type BasePropertyDefinition, type BuiltInPropertyType, type ColumnChange, type CustomTypeDefinition, DEFAULT_LOCALE_CONFIG, type DatabaseConfig, type DatabaseDriver, type EnumPropertyDefinition, type EnumRefPropertyDefinition, type ErrorCode, type ErrorLocation, type ExpandedFieldDefinition, type FilePropertyDefinition, type GeneratorContext, type GeneratorDefinition, type GeneratorOutput, type GeneratorOutputType, type IdType, type IndexChange, type IndexDefinition, type IndexSnapshot, type IndexType, type InlineEnumValue, type LaravelOutputConfig, type LoadedSchema, type LocaleCode, type LocaleConfig, type LocaleMap, type LocaleResolutionOptions, type LocalizedString, type NumericPropertyDefinition, type OmnifyConfig, type OmnifyErrorInfo, type OmnifyPlugin, type OutputConfig, type PivotFieldDefinition, type PluginConfigField, type PluginConfigFieldType, type PluginConfigSchema, type PluginConfigSelectOption, type PluginContext, type PluginEnumDefinition, type PluginEnumValue, type PluginFactory, type PluginLogger, type PropertyDefinition, type PropertySnapshot, type PropertyType, type ReferentialAction, type ResolvedOmnifyConfig, type Result, type SchemaChange, type SchemaChangeType, type SchemaCollection, type SchemaDefinition, type SchemaKind, type SchemaOptions, type SqlColumnDefinition, type StringPropertyDefinition, type TypeScriptOutputConfig, type TypeScriptTypeInfo, err, getAvailableLocales, isLocaleMap, isLocalizedString, mergeLocalizedStrings, ok, resolveLocalizedString, toLocaleMap };
|
|
1089
|
+
export { type AssociationDefinition, type AssociationRelation, type BasePropertyDefinition, type BuiltInPropertyType, type ColumnChange, type CompoundFieldOverride, type CompoundTypeAccessor, type CustomTypeDefinition, DEFAULT_LOCALE_CONFIG, type DatabaseConfig, type DatabaseDriver, type EnumPropertyDefinition, type EnumRefPropertyDefinition, type ErrorCode, type ErrorLocation, type ExpandedFieldDefinition, type FilePropertyDefinition, type GeneratorContext, type GeneratorDefinition, type GeneratorOutput, type GeneratorOutputType, type IdType, type IndexChange, type IndexDefinition, type IndexSnapshot, type IndexType, type InlineEnumValue, type LaravelOutputConfig, type LoadedSchema, type LocaleCode, type LocaleConfig, type LocaleMap, type LocaleResolutionOptions, type LocalizedString, type NumericPropertyDefinition, type OmnifyConfig, type OmnifyErrorInfo, type OmnifyPlugin, type OutputConfig, type PivotFieldDefinition, type PluginConfigField, type PluginConfigFieldType, type PluginConfigSchema, type PluginConfigSelectOption, type PluginContext, type PluginEnumDefinition, type PluginEnumValue, type PluginFactory, type PluginLogger, type PropertyDefinition, type PropertySnapshot, type PropertyType, type ReferentialAction, type ResolvedOmnifyConfig, type Result, type SchemaChange, type SchemaChangeType, type SchemaCollection, type SchemaDefinition, type SchemaKind, type SchemaOptions, type SqlColumnDefinition, type StringPropertyDefinition, type TypeScriptOutputConfig, type TypeScriptTypeInfo, type ValidationRules, err, getAvailableLocales, isLocaleMap, isLocalizedString, mergeLocalizedStrings, ok, resolveLocalizedString, toLocaleMap };
|
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,30 @@ interface AssociationDefinition {
|
|
|
206
206
|
/** Additional fields on the pivot table (for ManyToMany, MorphToMany) */
|
|
207
207
|
readonly pivotFields?: Readonly<Record<string, PivotFieldDefinition>>;
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Validation rules for a property.
|
|
211
|
+
* These are for application-level validation ONLY, NOT database structure.
|
|
212
|
+
* Database structure is controlled by: nullable, length, unique, etc.
|
|
213
|
+
*/
|
|
214
|
+
interface ValidationRules {
|
|
215
|
+
/**
|
|
216
|
+
* Whether the field is required (validation only).
|
|
217
|
+
* This does NOT affect database nullable - use 'nullable' for database.
|
|
218
|
+
* Recommended: set nullable: false if required: true, but this is manual.
|
|
219
|
+
*/
|
|
220
|
+
readonly required?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Minimum length validation (for String, Email, Password types only).
|
|
223
|
+
* Validation rule only - does NOT affect database.
|
|
224
|
+
*/
|
|
225
|
+
readonly minLength?: number;
|
|
226
|
+
/**
|
|
227
|
+
* Maximum length validation (for String, Email, Password types only).
|
|
228
|
+
* Must be <= property 'length' (database column size).
|
|
229
|
+
* Validation rule only - does NOT affect database.
|
|
230
|
+
*/
|
|
231
|
+
readonly maxLength?: number;
|
|
232
|
+
}
|
|
209
233
|
/**
|
|
210
234
|
* Base property definition shared by all property types.
|
|
211
235
|
*/
|
|
@@ -224,6 +248,45 @@ interface BasePropertyDefinition {
|
|
|
224
248
|
readonly description?: LocalizedString;
|
|
225
249
|
/** Previous field name for rename migrations (remove after migration runs) */
|
|
226
250
|
readonly renamedFrom?: string;
|
|
251
|
+
/** Validation rules (application-level only, NOT database) */
|
|
252
|
+
readonly rules?: ValidationRules;
|
|
253
|
+
/**
|
|
254
|
+
* Whether this field should be hidden in API responses/serialization.
|
|
255
|
+
* In Laravel, this adds the field to the $hidden array.
|
|
256
|
+
* Password type is automatically hidden.
|
|
257
|
+
*/
|
|
258
|
+
readonly hidden?: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Whether this field is mass assignable.
|
|
261
|
+
* In Laravel, this controls the $fillable array.
|
|
262
|
+
* @default true (all non-association fields are fillable by default)
|
|
263
|
+
*/
|
|
264
|
+
readonly fillable?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Per-field settings for compound types.
|
|
267
|
+
* Allows overriding nullable, hidden, fillable for specific expanded fields.
|
|
268
|
+
* Field names should match the suffix defined in the compound type (e.g., 'LastName', 'FirstName').
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* fields:
|
|
272
|
+
* LastNameKana:
|
|
273
|
+
* nullable: true
|
|
274
|
+
* FirstNameKana:
|
|
275
|
+
* nullable: true
|
|
276
|
+
* hidden: true
|
|
277
|
+
*/
|
|
278
|
+
readonly fields?: Readonly<Record<string, CompoundFieldOverride>>;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Override settings for a specific expanded field in a compound type.
|
|
282
|
+
*/
|
|
283
|
+
interface CompoundFieldOverride {
|
|
284
|
+
/** Override nullable for this field */
|
|
285
|
+
readonly nullable?: boolean;
|
|
286
|
+
/** Override hidden for this field */
|
|
287
|
+
readonly hidden?: boolean;
|
|
288
|
+
/** Override fillable for this field */
|
|
289
|
+
readonly fillable?: boolean;
|
|
227
290
|
}
|
|
228
291
|
/**
|
|
229
292
|
* String property with length constraint.
|
|
@@ -250,7 +313,8 @@ interface NumericPropertyDefinition extends BasePropertyDefinition {
|
|
|
250
313
|
*/
|
|
251
314
|
interface InlineEnumValue {
|
|
252
315
|
readonly value: string;
|
|
253
|
-
|
|
316
|
+
/** Display label - supports multi-language (string or locale map) */
|
|
317
|
+
readonly label?: LocalizedString;
|
|
254
318
|
readonly extra?: Readonly<Record<string, string | number | boolean>>;
|
|
255
319
|
}
|
|
256
320
|
/**
|
|
@@ -410,6 +474,8 @@ interface SqlColumnDefinition {
|
|
|
410
474
|
readonly nullable?: boolean;
|
|
411
475
|
/** Default value */
|
|
412
476
|
readonly default?: unknown;
|
|
477
|
+
/** Whether the column is unsigned (for integer types) */
|
|
478
|
+
readonly unsigned?: boolean;
|
|
413
479
|
}
|
|
414
480
|
/**
|
|
415
481
|
* TypeScript type information for code generation.
|
|
@@ -436,6 +502,33 @@ interface ExpandedFieldDefinition {
|
|
|
436
502
|
readonly typescript?: TypeScriptTypeInfo;
|
|
437
503
|
/** Reference to a shared enum schema (overrides sql/typescript) */
|
|
438
504
|
readonly enumRef?: string;
|
|
505
|
+
/** Laravel cast type for this field */
|
|
506
|
+
readonly cast?: string;
|
|
507
|
+
/** Default nullable for this field (can be overridden in schema) */
|
|
508
|
+
readonly nullable?: boolean;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Accessor definition for compound types.
|
|
512
|
+
* Defines computed properties that combine multiple fields.
|
|
513
|
+
*/
|
|
514
|
+
interface CompoundTypeAccessor {
|
|
515
|
+
/** Accessor name (will be used as attribute name, e.g., 'full_name') */
|
|
516
|
+
readonly name: string;
|
|
517
|
+
/**
|
|
518
|
+
* Fields to combine (suffixes without underscore prefix).
|
|
519
|
+
* e.g., ['last_name', 'first_name']
|
|
520
|
+
*/
|
|
521
|
+
readonly fields: readonly string[];
|
|
522
|
+
/**
|
|
523
|
+
* Separator between fields.
|
|
524
|
+
* @default ' '
|
|
525
|
+
*/
|
|
526
|
+
readonly separator?: string;
|
|
527
|
+
/**
|
|
528
|
+
* Order of fields (if different from definition order).
|
|
529
|
+
* Use field suffixes. If not specified, uses `fields` order.
|
|
530
|
+
*/
|
|
531
|
+
readonly order?: readonly string[];
|
|
439
532
|
}
|
|
440
533
|
/**
|
|
441
534
|
* Definition of a custom property type provided by a plugin.
|
|
@@ -466,6 +559,18 @@ interface CustomTypeDefinition {
|
|
|
466
559
|
* Each entry creates an additional column.
|
|
467
560
|
*/
|
|
468
561
|
readonly expand?: readonly ExpandedFieldDefinition[];
|
|
562
|
+
/**
|
|
563
|
+
* Accessor definitions for compound types.
|
|
564
|
+
* Creates computed properties that combine multiple fields.
|
|
565
|
+
* In Laravel, generates get{Name}Attribute() methods.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* accessors: [
|
|
569
|
+
* { name: 'full_name', fields: ['last_name', 'first_name'] },
|
|
570
|
+
* { name: 'full_name_kana', fields: ['last_name_kana', 'first_name_kana'] },
|
|
571
|
+
* ]
|
|
572
|
+
*/
|
|
573
|
+
readonly accessors?: readonly CompoundTypeAccessor[];
|
|
469
574
|
/**
|
|
470
575
|
* Additional fields valid for this custom type (beyond base fields).
|
|
471
576
|
* Base fields (type, displayName, nullable, default, unique, description, renamedFrom)
|
|
@@ -717,6 +822,8 @@ interface GeneratorContext {
|
|
|
717
822
|
readonly previousOutputs: ReadonlyMap<string, readonly GeneratorOutput[]>;
|
|
718
823
|
/** Custom types registered by all plugins (for compound type expansion) */
|
|
719
824
|
readonly customTypes: ReadonlyMap<string, CustomTypeDefinition>;
|
|
825
|
+
/** Locale configuration for multi-language support */
|
|
826
|
+
readonly localeConfig?: LocaleConfig | undefined;
|
|
720
827
|
}
|
|
721
828
|
/**
|
|
722
829
|
* Definition of a generator provided by a plugin.
|
|
@@ -979,4 +1086,4 @@ declare function ok<T>(value: T): Result<T, never>;
|
|
|
979
1086
|
*/
|
|
980
1087
|
declare function err<E>(error: E): Result<never, E>;
|
|
981
1088
|
|
|
982
|
-
export { type AssociationDefinition, type AssociationRelation, type BasePropertyDefinition, type BuiltInPropertyType, type ColumnChange, type CustomTypeDefinition, DEFAULT_LOCALE_CONFIG, type DatabaseConfig, type DatabaseDriver, type EnumPropertyDefinition, type EnumRefPropertyDefinition, type ErrorCode, type ErrorLocation, type ExpandedFieldDefinition, type FilePropertyDefinition, type GeneratorContext, type GeneratorDefinition, type GeneratorOutput, type GeneratorOutputType, type IdType, type IndexChange, type IndexDefinition, type IndexSnapshot, type IndexType, type InlineEnumValue, type LaravelOutputConfig, type LoadedSchema, type LocaleCode, type LocaleConfig, type LocaleMap, type LocaleResolutionOptions, type LocalizedString, type NumericPropertyDefinition, type OmnifyConfig, type OmnifyErrorInfo, type OmnifyPlugin, type OutputConfig, type PivotFieldDefinition, type PluginConfigField, type PluginConfigFieldType, type PluginConfigSchema, type PluginConfigSelectOption, type PluginContext, type PluginEnumDefinition, type PluginEnumValue, type PluginFactory, type PluginLogger, type PropertyDefinition, type PropertySnapshot, type PropertyType, type ReferentialAction, type ResolvedOmnifyConfig, type Result, type SchemaChange, type SchemaChangeType, type SchemaCollection, type SchemaDefinition, type SchemaKind, type SchemaOptions, type SqlColumnDefinition, type StringPropertyDefinition, type TypeScriptOutputConfig, type TypeScriptTypeInfo, err, getAvailableLocales, isLocaleMap, isLocalizedString, mergeLocalizedStrings, ok, resolveLocalizedString, toLocaleMap };
|
|
1089
|
+
export { type AssociationDefinition, type AssociationRelation, type BasePropertyDefinition, type BuiltInPropertyType, type ColumnChange, type CompoundFieldOverride, type CompoundTypeAccessor, type CustomTypeDefinition, DEFAULT_LOCALE_CONFIG, type DatabaseConfig, type DatabaseDriver, type EnumPropertyDefinition, type EnumRefPropertyDefinition, type ErrorCode, type ErrorLocation, type ExpandedFieldDefinition, type FilePropertyDefinition, type GeneratorContext, type GeneratorDefinition, type GeneratorOutput, type GeneratorOutputType, type IdType, type IndexChange, type IndexDefinition, type IndexSnapshot, type IndexType, type InlineEnumValue, type LaravelOutputConfig, type LoadedSchema, type LocaleCode, type LocaleConfig, type LocaleMap, type LocaleResolutionOptions, type LocalizedString, type NumericPropertyDefinition, type OmnifyConfig, type OmnifyErrorInfo, type OmnifyPlugin, type OutputConfig, type PivotFieldDefinition, type PluginConfigField, type PluginConfigFieldType, type PluginConfigSchema, type PluginConfigSelectOption, type PluginContext, type PluginEnumDefinition, type PluginEnumValue, type PluginFactory, type PluginLogger, type PropertyDefinition, type PropertySnapshot, type PropertyType, type ReferentialAction, type ResolvedOmnifyConfig, type Result, type SchemaChange, type SchemaChangeType, type SchemaCollection, type SchemaDefinition, type SchemaKind, type SchemaOptions, type SqlColumnDefinition, type StringPropertyDefinition, type TypeScriptOutputConfig, type TypeScriptTypeInfo, type ValidationRules, err, getAvailableLocales, isLocaleMap, isLocalizedString, mergeLocalizedStrings, ok, resolveLocalizedString, toLocaleMap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@famgia/omnify-types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "Shared TypeScript types for omnify-schema",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,4 +27,4 @@
|
|
|
27
27
|
"lint": "eslint src",
|
|
28
28
|
"typecheck": "tsc --noEmit"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
|
@@ -139,6 +139,29 @@
|
|
|
139
139
|
{ "$ref": "#/definitions/AssociationProperty" }
|
|
140
140
|
]
|
|
141
141
|
},
|
|
142
|
+
"ValidationRules": {
|
|
143
|
+
"type": "object",
|
|
144
|
+
"description": "Validation rules (application-level only, NOT database structure)",
|
|
145
|
+
"properties": {
|
|
146
|
+
"required": {
|
|
147
|
+
"type": "boolean",
|
|
148
|
+
"default": false,
|
|
149
|
+
"description": "Whether the field is required (validation only, does NOT affect database nullable). Recommended: set nullable: false manually if required: true."
|
|
150
|
+
},
|
|
151
|
+
"minLength": {
|
|
152
|
+
"type": "integer",
|
|
153
|
+
"minimum": 0,
|
|
154
|
+
"maximum": 65535,
|
|
155
|
+
"description": "Minimum length validation (for String, Email, Password only). Does NOT affect database."
|
|
156
|
+
},
|
|
157
|
+
"maxLength": {
|
|
158
|
+
"type": "integer",
|
|
159
|
+
"minimum": 1,
|
|
160
|
+
"maximum": 65535,
|
|
161
|
+
"description": "Maximum length validation (for String, Email, Password only). Must be <= 'length' (database column size). Does NOT affect database."
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
142
165
|
"BaseProperty": {
|
|
143
166
|
"type": "object",
|
|
144
167
|
"properties": {
|
|
@@ -153,7 +176,7 @@
|
|
|
153
176
|
"nullable": {
|
|
154
177
|
"type": "boolean",
|
|
155
178
|
"default": false,
|
|
156
|
-
"description": "Whether the field can be null"
|
|
179
|
+
"description": "Whether the field can be null in database"
|
|
157
180
|
},
|
|
158
181
|
"unique": {
|
|
159
182
|
"type": "boolean",
|
|
@@ -162,6 +185,10 @@
|
|
|
162
185
|
},
|
|
163
186
|
"default": {
|
|
164
187
|
"description": "Default value for the field"
|
|
188
|
+
},
|
|
189
|
+
"rules": {
|
|
190
|
+
"$ref": "#/definitions/ValidationRules",
|
|
191
|
+
"description": "Validation rules (application-level only, NOT database)"
|
|
165
192
|
}
|
|
166
193
|
}
|
|
167
194
|
},
|
|
@@ -182,7 +209,7 @@
|
|
|
182
209
|
"minimum": 1,
|
|
183
210
|
"maximum": 65535,
|
|
184
211
|
"default": 255,
|
|
185
|
-
"description": "
|
|
212
|
+
"description": "Database column size (NOT validation). Use rules.maxLength for validation."
|
|
186
213
|
}
|
|
187
214
|
}
|
|
188
215
|
}
|