@oxog/types 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -217,6 +217,7 @@ const handler: EventHandler<AppEvents, 'user:login'> = (payload) => {
217
217
  - `DeepPartial<T>` - All properties optional
218
218
  - `DeepReadonly<T>` - All properties readonly
219
219
  - `DeepRequired<T>` - All properties required
220
+ - `DeepMutable<T>` - All properties mutable (removes readonly)
220
221
 
221
222
  **Function:**
222
223
  - `MaybePromise<T>` - Sync or async value
@@ -237,6 +238,17 @@ const handler: EventHandler<AppEvents, 'user:login'> = (payload) => {
237
238
  - `NonEmptyArray<T>` - Array with ≥1 element
238
239
  - `Nullable<T>` - T | null
239
240
  - `Optional<T>` - T | undefined
241
+ - `ValueOf<T>` - Extract value types from object
242
+ - `RequireKeys<T, K>` - Make specific keys required
243
+ - `OptionalKeys<T, K>` - Make specific keys optional
244
+ - `KeysOfType<T, V>` - Extract keys with matching value type
245
+ - `NonNullish<T>` - Exclude null and undefined
246
+ - `Mutable<T>` - Remove readonly from properties
247
+
248
+ **Array:**
249
+ - `Tuple<T, N>` - Fixed-length tuple type
250
+ - `ArrayElement<T>` - Extract element type from array
251
+ - `LiteralUnion<T, U>` - Literal union with autocomplete
240
252
 
241
253
  ### Events
242
254
 
@@ -298,6 +310,7 @@ npm run example:02-result-type
298
310
  ### Testing
299
311
 
300
312
  - 100% code coverage
313
+ - 229 tests across 7 test files
301
314
  - Unit tests for all modules
302
315
  - Integration tests
303
316
  - Vitest test runner
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var l=class{constructor(e){this.value=e;}ok=true;error=void 0;map(e){return E(e(this.value))}mapErr(e){return this}match(e){return e.ok(this.value)}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}},p=class{constructor(e){this.error=e;}ok=false;value=void 0;map(e){return this}mapErr(e){return T(e(this.error))}match(e){return e.err(this.error)}unwrap(){throw new Error(`Cannot unwrap Err: ${String(this.error)}`)}unwrapOr(e){return e}unwrapOrElse(e){return e(this.error)}};function E(r){return new l(r)}function T(r){return new p(r)}var c=(n=>(n.UNKNOWN="UNKNOWN",n.VALIDATION_ERROR="VALIDATION_ERROR",n.PLUGIN_ERROR="PLUGIN_ERROR",n.NOT_FOUND="NOT_FOUND",n.TIMEOUT="TIMEOUT",n.DEPENDENCY_ERROR="DEPENDENCY_ERROR",n))(c||{}),t=class extends Error{constructor(o,u,a){super(o);this.code=u;this.context=a;this.name="OxogError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},s=class extends t{constructor(o,u){super(o,"VALIDATION_ERROR",u);this.context=u;this.name="ValidationError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},i=class extends t{constructor(o,u,a){super(o,"PLUGIN_ERROR",a?{pluginName:u,...a}:void 0);this.pluginName=u;this.name="PluginError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name};function d(r){return r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.version=="string"&&typeof r.install=="function"}function m(r){return r!==null&&typeof r=="object"&&typeof r.use=="function"&&typeof r.unregister=="function"&&typeof r.getPlugin=="function"&&typeof r.listPlugins=="function"&&typeof r.hasPlugin=="function"&&typeof r.emit=="function"&&typeof r.on=="function"&&typeof r.getContext=="function"}function R(r){return r instanceof t}function x(r){return r instanceof s}function k(r){return r instanceof i}function f(r){return r!==null&&typeof r=="object"&&typeof r.ok=="boolean"&&("value"in r||"error"in r)}function U(r){return f(r)&&r.ok===true}function w(r){return f(r)&&r.ok===false}var N=Symbol.for("@oxog/plugin"),P=Symbol.for("@oxog/kernel"),b="1.0.1";exports.Err=T;exports.ErrorCodes=c;exports.OXOG_KERNEL=P;exports.OXOG_PLUGIN=N;exports.OXOG_VERSION=b;exports.Ok=E;exports.OxogError=t;exports.PluginError=i;exports.ValidationError=s;exports.isErr=w;exports.isKernel=m;exports.isOk=U;exports.isOxogError=R;exports.isPlugin=d;exports.isPluginError=k;exports.isResult=f;exports.isValidationError=x;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var i=class{constructor(e){this.value=e;}ok=true;error=void 0;map(e){return E(e(this.value))}mapErr(e){return this}match(e){return e.ok(this.value)}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}},l=class{constructor(e){this.error=e;}ok=false;value=void 0;map(e){return this}mapErr(e){return T(e(this.error))}match(e){return e.err(this.error)}unwrap(){throw new Error(`Cannot unwrap Err: ${String(this.error)}`)}unwrapOr(e){return e}unwrapOrElse(e){return e(this.error)}};function E(r){return new i(r)}function T(r){return new l(r)}var c=(n=>(n.UNKNOWN="UNKNOWN",n.VALIDATION_ERROR="VALIDATION_ERROR",n.PLUGIN_ERROR="PLUGIN_ERROR",n.NOT_FOUND="NOT_FOUND",n.TIMEOUT="TIMEOUT",n.DEPENDENCY_ERROR="DEPENDENCY_ERROR",n))(c||{}),t=class extends Error{constructor(o,u,p){super(o);this.code=u;this.context=p;this.name="OxogError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},s=class extends t{constructor(o,u){super(o,"VALIDATION_ERROR",u);this.context=u;this.name="ValidationError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},a=class extends t{constructor(o,u,p){super(o,"PLUGIN_ERROR",{pluginName:u,...p});this.pluginName=u;this.name="PluginError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name};function m(r){return r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.version=="string"&&typeof r.install=="function"}function R(r){return r!==null&&typeof r=="object"&&typeof r.use=="function"&&typeof r.unregister=="function"&&typeof r.getPlugin=="function"&&typeof r.listPlugins=="function"&&typeof r.hasPlugin=="function"&&typeof r.emit=="function"&&typeof r.on=="function"&&typeof r.getContext=="function"}function d(r){return r instanceof t}function x(r){return r instanceof s}function k(r){return r instanceof a}function f(r){return r!==null&&typeof r=="object"&&typeof r.ok=="boolean"&&("value"in r||"error"in r)}function U(r){return f(r)&&r.ok===true}function w(r){return f(r)&&r.ok===false}var N=Symbol.for("@oxog/plugin"),P=Symbol.for("@oxog/kernel"),b="1.0.2";exports.Err=T;exports.ErrorCodes=c;exports.OXOG_KERNEL=P;exports.OXOG_PLUGIN=N;exports.OXOG_VERSION=b;exports.Ok=E;exports.OxogError=t;exports.PluginError=a;exports.ValidationError=s;exports.isErr=w;exports.isKernel=R;exports.isOk=U;exports.isOxogError=d;exports.isPlugin=m;exports.isPluginError=k;exports.isResult=f;exports.isValidationError=x;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/result.ts","../src/errors.ts","../src/guards.ts","../src/constants.ts"],"names":["OkImpl","value","fn","Ok","_fn","handlers","_defaultValue","ErrImpl","error","Err","defaultValue","ErrorCodes","OxogError","message","code","context","ValidationError","PluginError","pluginName","isPlugin","isKernel","isOxogError","isValidationError","isPluginError","isResult","isOk","isErr","OXOG_PLUGIN","OXOG_KERNEL","OXOG_VERSION"],"mappings":"aAqHA,IAAMA,CAAAA,CAAN,KAAiC,CAI/B,WAAA,CAA4BC,EAAU,CAAV,IAAA,CAAA,KAAA,CAAAA,EAAW,CAH9B,EAAA,CAAK,IAAA,CACL,MAAQ,MAAA,CAIjB,GAAA,CAAOC,EAAuC,CAC5C,OAAOC,EAAGD,CAAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAC1B,CAEA,OAAUE,CAAAA,CAAiC,CACzC,OAAO,IACT,CAEA,MAASC,CAAAA,CAAgE,CACvE,OAAOA,CAAAA,CAAS,EAAA,CAAG,IAAA,CAAK,KAAK,CAC/B,CAEA,MAAA,EAAY,CACV,OAAO,IAAA,CAAK,KACd,CAEA,QAAA,CAASC,CAAAA,CAAqB,CAC5B,OAAO,IAAA,CAAK,KACd,CAEA,YAAA,CAAaF,E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Content":["/**\n * @oxog/types - Result type for functional error handling\n * @version 1.0.1\n * @author Ersin Koç\n */\n\n/**\n * Represents a successful result.\n *\n * Contains a value and provides methods for transforming the value\n * or handling errors. Only available on successful results.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // 42\n * }\n * ```\n */\nexport interface Ok<T> {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n\n /** Transform the value if successful */\n map<U>(fn: (value: T) => U): Result<U, never>;\n\n /** Transform the error (no-op for Ok) */\n mapErr<F>(fn: (error: never) => F): Ok<T>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U;\n\n /** Unwrap the value (asserts success) */\n unwrap(): T;\n\n /** Unwrap with default value */\n unwrapOr(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse(fn: () => T): T;\n}\n\n/**\n * Represents a failed result.\n *\n * Contains an error and provides methods for transforming the error\n * or handling success cases. Only available on failed results.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * if (isErr(err)) {\n * console.log(err.error); // 'Something went wrong'\n * }\n * ```\n */\nexport interface Err<E> {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n\n /** Transform the value (no-op for Err) */\n map<U>(fn: (value: never) => U): Err<E>;\n\n /** Transform the error if failed */\n mapErr<F>(fn: (error: E) => F): Result<never, F>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U;\n\n /** Unwrap the value (asserts success, throws for Err) */\n unwrap(): never;\n\n /** Unwrap with default value */\n unwrapOr<T>(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse<T>(fn: () => T): T;\n}\n\n/**\n * Result type - either Ok<T> or Err<E>.\n *\n * A type that represents either success (Ok) or failure (Err).\n * This is inspired by Rust's Result type and provides functional\n * error handling without exceptions.\n *\n * @example\n * ```typescript\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) {\n * return Err('Division by zero');\n * }\n * return Ok(a / b);\n * }\n *\n * const result = divide(10, 2);\n *\n * // Pattern matching\n * const message = result.match({\n * ok: (value) => `Result: ${value}`,\n * err: (error) => `Error: ${error}`\n * });\n *\n * // Chaining\n * const doubled = result\n * .map(x => x * 2)\n * .mapErr(e => `Calculation failed: ${e}`);\n * ```\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Internal implementation of Ok result.\n */\nclass OkImpl<T> implements Ok<T> {\n readonly ok = true as const;\n readonly error = undefined as never;\n\n constructor(public readonly value: T) {}\n\n map<U>(fn: (value: T) => U): Result<U, never> {\n return Ok(fn(this.value));\n }\n\n mapErr<F>(_fn: (error: never) => F): Ok<T> {\n return this;\n }\n\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U {\n return handlers.ok(this.value);\n }\n\n unwrap(): T {\n return this.value;\n }\n\n unwrapOr(_defaultValue: T): T {\n return this.value;\n }\n\n unwrapOrElse(_fn: () => T): T {\n return this.value;\n }\n}\n\n/**\n * Internal implementation of Err result.\n */\nclass ErrImpl<E> implements Err<E> {\n readonly ok = false as const;\n readonly value = undefined as never;\n\n constructor(public readonly error: E) {}\n\n map<U>(_fn: (value: never) => U): Err<E> {\n return this;\n }\n\n mapErr<F>(fn: (error: E) => F): Result<never, F> {\n return Err(fn(this.error));\n }\n\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U {\n return handlers.err(this.error);\n }\n\n unwrap(): never {\n throw new Error(`Cannot unwrap Err: ${String(this.error)}`);\n }\n\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n unwrapOrElse<T>(fn: (error: E) => T): T {\n return fn(this.error);\n }\n}\n\n/**\n * Creates a successful Result containing a value.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * const okStr = Ok('hello');\n * const okObj = Ok({ id: 1 });\n * ```\n *\n * @param value - The value to wrap\n * @returns An Ok result containing the value\n */\nexport function Ok<T>(value: T): Ok<T> {\n return new OkImpl(value);\n}\n\n/**\n * Creates a failed Result containing an error.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * const errNum = Err(404);\n * const errObj = Err({ code: 'NOT_FOUND' });\n * ```\n *\n * @param error - The error to wrap\n * @returns An Err result containing the error\n */\nexport function Err<E>(error: E): Err<E> {\n return new ErrImpl(error);\n}\n","/**\n * @oxog/types - Standardized error classes\n * @version 1.0.1\n * @author Ersin Koç\n */\n\n/**\n * Standard error codes for @oxog ecosystem.\n *\n * These codes provide programmatic ways to identify and handle errors.\n */\nexport enum ErrorCodes {\n /** Unknown error */\n UNKNOWN = 'UNKNOWN',\n\n /** Validation error */\n VALIDATION_ERROR = 'VALIDATION_ERROR',\n\n /** Plugin-related error */\n PLUGIN_ERROR = 'PLUGIN_ERROR',\n\n /** Resource not found */\n NOT_FOUND = 'NOT_FOUND',\n\n /** Operation timed out */\n TIMEOUT = 'TIMEOUT',\n\n /** Dependency error */\n DEPENDENCY_ERROR = 'DEPENDENCY_ERROR',\n}\n\n/**\n * Base error class for all @oxog errors.\n *\n * Provides structured error information with code, message, and context.\n * All other @oxog errors inherit from this class.\n *\n * @example\n * ```typescript\n * throw new OxogError(\n * 'Database connection failed',\n * ErrorCodes.DEPENDENCY_ERROR,\n * { host: 'localhost', port: 5432 }\n * );\n * ```\n */\nexport class OxogError extends Error {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new OxogError.\n *\n * @param message - Human-readable error message\n * @param code - Error code for programmatic handling\n * @param context - Additional context about the error\n */\n constructor(\n message: string,\n public readonly code: string,\n public readonly context?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'OxogError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when validation fails.\n *\n * Used for input validation, schema validation, and type checking errors.\n *\n * @example\n * ```typescript\n * throw new ValidationError(\n * 'Invalid email format',\n * { field: 'email', value: 'not-an-email' }\n * );\n * ```\n */\nexport class ValidationError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new ValidationError.\n *\n * @param message - Human-readable error message\n * @param context - Additional context about the validation failure\n */\n constructor(\n message: string,\n public override readonly context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.VALIDATION_ERROR, context);\n this.name = 'ValidationError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Used for plugin initialization, dependency resolution, and runtime errors\n * specific to plugins.\n *\n * @example\n * ```typescript\n * throw new PluginError(\n * 'Failed to initialize cache plugin',\n * 'cache-plugin',\n * { reason: 'Redis connection failed' }\n * );\n * ```\n */\nexport class PluginError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new PluginError.\n *\n * @param message - Human-readable error message\n * @param pluginName - Name of the plugin that caused the error\n * @param context - Additional context about the plugin error\n */\n constructor(\n message: string,\n public readonly pluginName: string,\n context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.PLUGIN_ERROR, context ? { pluginName, ...context } : undefined);\n this.name = 'PluginError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n","/**\n * @oxog/types - Type guard functions\n * @version 1.0.1\n * @author Ersin Koç\n */\n\nimport type { Plugin, Kernel } from './plugin.js';\nimport type { Result, Ok, Err } from './result.js';\nimport { OxogError, ValidationError, PluginError } from './errors.js';\n\n/**\n * Type guard for Plugin.\n *\n * Checks if a value is a valid Plugin instance.\n *\n * @example\n * ```typescript\n * const plugin = { name: 'test', version: '1.0.0', install: () => {} };\n * if (isPlugin(plugin)) {\n * console.log(plugin.name); // TypeScript knows it's a Plugin\n * }\n * ```\n */\nexport function isPlugin<T>(value: unknown): value is Plugin<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Plugin<T>).name === 'string' &&\n typeof (value as Plugin<T>).version === 'string' &&\n typeof (value as Plugin<T>).install === 'function'\n );\n}\n\n/**\n * Type guard for Kernel.\n *\n * Checks if a value is a valid Kernel instance.\n *\n * @example\n * ```typescript\n * const kernel = {\n * use: (plugin) => kernel,\n * unregister: () => true,\n * getPlugin: () => undefined,\n * listPlugins: () => [],\n * hasPlugin: () => false,\n * emit: () => {},\n * on: () => () => {},\n * getContext: () => null\n * };\n * if (isKernel(kernel)) {\n * console.log(kernel.listPlugins()); // TypeScript knows it's a Kernel\n * }\n * ```\n */\nexport function isKernel<T>(value: unknown): value is Kernel<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Kernel<T>).use === 'function' &&\n typeof (value as Kernel<T>).unregister === 'function' &&\n typeof (value as Kernel<T>).getPlugin === 'function' &&\n typeof (value as Kernel<T>).listPlugins === 'function' &&\n typeof (value as Kernel<T>).hasPlugin === 'function' &&\n typeof (value as Kernel<T>).emit === 'function' &&\n typeof (value as Kernel<T>).on === 'function' &&\n typeof (value as Kernel<T>).getContext === 'function'\n );\n}\n\n/**\n * Type guard for OxogError.\n *\n * Checks if a value is an OxogError instance.\n *\n * @example\n * ```typescript\n * const error = new OxogError('Test', 'TEST');\n * if (isOxogError(error)) {\n * console.log(error.code); // TypeScript knows it's an OxogError\n * }\n * ```\n */\nexport function isOxogError(value: unknown): value is OxogError {\n return value instanceof OxogError;\n}\n\n/**\n * Type guard for ValidationError.\n *\n * Checks if a value is a ValidationError instance.\n *\n * @example\n * ```typescript\n * const error = new ValidationError('Invalid', { field: 'test' });\n * if (isValidationError(error)) {\n * console.log(error.context); // TypeScript knows it's a ValidationError\n * }\n * ```\n */\nexport function isValidationError(value: unknown): value is ValidationError {\n return value instanceof ValidationError;\n}\n\n/**\n * Type guard for PluginError.\n *\n * Checks if a value is a PluginError instance.\n *\n * @example\n * ```typescript\n * const error = new PluginError('Plugin failed', 'my-plugin');\n * if (isPluginError(error)) {\n * console.log(error.pluginName); // TypeScript knows it's a PluginError\n * }\n * ```\n */\nexport function isPluginError(value: unknown): value is PluginError {\n return value instanceof PluginError;\n}\n\n/**\n * Type guard for Result.\n *\n * Checks if a value is a Result instance (either Ok or Err).\n *\n * @example\n * ```typescript\n * const result = Ok(42);\n * if (isResult(result)) {\n * // result is Ok<number, unknown>\n * }\n *\n * const err = Err('error');\n * if (isResult(err)) {\n * // err is Err<unknown, string>\n * }\n * ```\n */\nexport function isResult<T, E>(value: unknown): value is Result<T, E> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Result<T, E>).ok === 'boolean' &&\n (('value' in (value as object)) || ('error' in (value as object)))\n );\n}\n\n/**\n * Type guard for Ok result.\n *\n * Checks if a Result is an Ok (success) instance.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // TypeScript knows it's Ok\n * }\n * ```\n */\nexport function isOk<T>(value: Result<T, unknown>): value is Ok<T> {\n return isResult(value) && value.ok === true;\n}\n\n/**\n * Type guard for Err result.\n *\n * Checks if a Result is an Err (failure) instance.\n *\n * @example\n * ```typescript\n * const err = Err('error');\n * if (isErr(err)) {\n * console.log(err.error); // TypeScript knows it's Err\n * }\n * ```\n */\nexport function isErr<E>(value: Result<unknown, E>): value is Err<E> {\n return isResult(value) && value.ok === false;\n}\n","/**\n * @oxog/types - Well-known symbols and constants\n * @version 1.0.1\n * @author Ersin Koç\n */\n\nimport { ErrorCodes } from './errors.js';\n\n/**\n * Well-known symbol for @oxog plugins.\n *\n * Use this symbol to mark objects as @oxog plugins.\n * This enables runtime detection and validation.\n *\n * @example\n * ```typescript\n * const myPlugin = {\n * [OXOG_PLUGIN]: true,\n * name: 'my-plugin',\n * version: '1.0.0',\n * install: () => {}\n * };\n * ```\n */\nexport const OXOG_PLUGIN = Symbol.for('@oxog/plugin');\n\n/**\n * Well-known symbol for @oxog kernels.\n *\n * Use this symbol to mark objects as @oxog kernels.\n * This enables runtime detection and validation.\n *\n * @example\n * ```typescript\n * const myKernel = {\n * [OXOG_KERNEL]: true,\n * use: (plugin) => kernel,\n * // ... other methods\n * };\n * ```\n */\nexport const OXOG_KERNEL = Symbol.for('@oxog/kernel');\n\n/**\n * @oxog/types package version.\n *\n * Current version of the @oxog/types package.\n *\n * @example\n * ```typescript\n * console.log(`Using @oxog/types v${OXOG_VERSION}`);\n * ```\n */\nexport const OXOG_VERSION = '1.0.1';\n\n/**\n * Standard error codes for @oxog ecosystem.\n *\n * Re-exported from errors module for convenience.\n *\n * @example\n * ```typescript\n * throw new OxogError('Not found', ErrorCodes.NOT_FOUND);\n * ```\n */\nexport { ErrorCodes };\n"]}
1
+ {"version":3,"sources":["../src/result.ts","../src/errors.ts","../src/guards.ts","../src/constants.ts"],"names":["OkImpl","value","fn","Ok","_fn","handlers","_defaultValue","ErrImpl","error","Err","defaultValue","ErrorCodes","OxogError","message","code","context","ValidationError","PluginError","pluginName","isPlugin","isKernel","isOxogError","isValidationError","isPluginError","isResult","isOk","isErr","OXOG_PLUGIN","OXOG_KERNEL","OXOG_VERSION"],"mappings":"aAqHA,IAAMA,CAAAA,CAAN,KAAiC,CAI/B,WAAA,CAA4BC,EAAU,CAAV,IAAA,CAAA,KAAA,CAAAA,EAAW,CAH9B,EAAA,CAAK,IAAA,CACL,MAAQ,MAAA,CAIjB,GAAA,CAAOC,EAAuC,CAC5C,OAAOC,EAAGD,CAAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAC1B,CAEA,OAAUE,CAAAA,CAAiC,CACzC,OAAO,IACT,CAEA,MAASC,CAAAA,CAAgE,CACvE,OAAOA,CAAAA,CAAS,EAAA,CAAG,IAAA,CAAK,KAAK,CAC/B,CAEA,QAAY,CACV,OAAO,KAAK,KACd,CAEA,QAAA,CAASC,CAAAA,CAAqB,CAC5B,OAAO,KAAK,KACd,CAEA,aAAaF,CAAAA,CAAiB,CAC5B,OAAO,IAAA,CAAK,KACd,CACF,CAAA,CAKMG,CAAAA,CAAN,KAAmC,CAIjC,WAAA,CAA4BC,CAAAA,CAAU,CAAV,IAAA,CAAA,KAAA,CAAAA,EAAW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functional error handling\n * @version 1.0.2\n * @author Ersin Koç\n */\n\n/**\n * Represents a successful result.\n *\n * Contains a value and provides methods for transforming the value\n * or handling errors. Only available on successful results.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // 42\n * }\n * ```\n */\nexport interface Ok<T> {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n\n /** Transform the value if successful */\n map<U>(fn: (value: T) => U): Result<U, never>;\n\n /** Transform the error (no-op for Ok) */\n mapErr<F>(fn: (error: never) => F): Ok<T>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U;\n\n /** Unwrap the value (asserts success) */\n unwrap(): T;\n\n /** Unwrap with default value */\n unwrapOr(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse(fn: () => T): T;\n}\n\n/**\n * Represents a failed result.\n *\n * Contains an error and provides methods for transforming the error\n * or handling success cases. Only available on failed results.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * if (isErr(err)) {\n * console.log(err.error); // 'Something went wrong'\n * }\n * ```\n */\nexport interface Err<E> {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n\n /** Transform the value (no-op for Err) */\n map<U>(fn: (value: never) => U): Err<E>;\n\n /** Transform the error if failed */\n mapErr<F>(fn: (error: E) => F): Result<never, F>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U;\n\n /** Unwrap the value (asserts success, throws for Err) */\n unwrap(): never;\n\n /** Unwrap with default value */\n unwrapOr<T>(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse<T>(fn: () => T): T;\n}\n\n/**\n * Result type - either Ok<T> or Err<E>.\n *\n * A type that represents either success (Ok) or failure (Err).\n * This is inspired by Rust's Result type and provides functional\n * error handling without exceptions.\n *\n * @example\n * ```typescript\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) {\n * return Err('Division by zero');\n * }\n * return Ok(a / b);\n * }\n *\n * const result = divide(10, 2);\n *\n * // Pattern matching\n * const message = result.match({\n * ok: (value) => `Result: ${value}`,\n * err: (error) => `Error: ${error}`\n * });\n *\n * // Chaining\n * const doubled = result\n * .map(x => x * 2)\n * .mapErr(e => `Calculation failed: ${e}`);\n * ```\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Internal implementation of Ok result.\n */\nclass OkImpl<T> implements Ok<T> {\n readonly ok = true as const;\n readonly error = undefined as never;\n\n constructor(public readonly value: T) {}\n\n map<U>(fn: (value: T) => U): Result<U, never> {\n return Ok(fn(this.value));\n }\n\n mapErr<F>(_fn: (error: never) => F): Ok<T> {\n return this;\n }\n\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U {\n return handlers.ok(this.value);\n }\n\n unwrap(): T {\n return this.value;\n }\n\n unwrapOr(_defaultValue: T): T {\n return this.value;\n }\n\n unwrapOrElse(_fn: () => T): T {\n return this.value;\n }\n}\n\n/**\n * Internal implementation of Err result.\n */\nclass ErrImpl<E> implements Err<E> {\n readonly ok = false as const;\n readonly value = undefined as never;\n\n constructor(public readonly error: E) {}\n\n map<U>(_fn: (value: never) => U): Err<E> {\n return this;\n }\n\n mapErr<F>(fn: (error: E) => F): Result<never, F> {\n return Err(fn(this.error));\n }\n\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U {\n return handlers.err(this.error);\n }\n\n unwrap(): never {\n throw new Error(`Cannot unwrap Err: ${String(this.error)}`);\n }\n\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n unwrapOrElse<T>(fn: (error: E) => T): T {\n return fn(this.error);\n }\n}\n\n/**\n * Creates a successful Result containing a value.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * const okStr = Ok('hello');\n * const okObj = Ok({ id: 1 });\n * ```\n *\n * @param value - The value to wrap\n * @returns An Ok result containing the value\n */\nexport function Ok<T>(value: T): Ok<T> {\n return new OkImpl(value);\n}\n\n/**\n * Creates a failed Result containing an error.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * const errNum = Err(404);\n * const errObj = Err({ code: 'NOT_FOUND' });\n * ```\n *\n * @param error - The error to wrap\n * @returns An Err result containing the error\n */\nexport function Err<E>(error: E): Err<E> {\n return new ErrImpl(error);\n}\n","/**\n * @oxog/types - Standardized error classes\n * @version 1.0.2\n * @author Ersin Koç\n */\n\n/**\n * Standard error codes for @oxog ecosystem.\n *\n * These codes provide programmatic ways to identify and handle errors.\n */\nexport enum ErrorCodes {\n /** Unknown error */\n UNKNOWN = 'UNKNOWN',\n\n /** Validation error */\n VALIDATION_ERROR = 'VALIDATION_ERROR',\n\n /** Plugin-related error */\n PLUGIN_ERROR = 'PLUGIN_ERROR',\n\n /** Resource not found */\n NOT_FOUND = 'NOT_FOUND',\n\n /** Operation timed out */\n TIMEOUT = 'TIMEOUT',\n\n /** Dependency error */\n DEPENDENCY_ERROR = 'DEPENDENCY_ERROR',\n}\n\n/**\n * Base error class for all @oxog errors.\n *\n * Provides structured error information with code, message, and context.\n * All other @oxog errors inherit from this class.\n *\n * @example\n * ```typescript\n * throw new OxogError(\n * 'Database connection failed',\n * ErrorCodes.DEPENDENCY_ERROR,\n * { host: 'localhost', port: 5432 }\n * );\n * ```\n */\nexport class OxogError extends Error {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new OxogError.\n *\n * @param message - Human-readable error message\n * @param code - Error code for programmatic handling\n * @param context - Additional context about the error\n */\n constructor(\n message: string,\n public readonly code: string,\n public readonly context?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'OxogError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when validation fails.\n *\n * Used for input validation, schema validation, and type checking errors.\n *\n * @example\n * ```typescript\n * throw new ValidationError(\n * 'Invalid email format',\n * { field: 'email', value: 'not-an-email' }\n * );\n * ```\n */\nexport class ValidationError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new ValidationError.\n *\n * @param message - Human-readable error message\n * @param context - Additional context about the validation failure\n */\n constructor(\n message: string,\n public override readonly context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.VALIDATION_ERROR, context);\n this.name = 'ValidationError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Used for plugin initialization, dependency resolution, and runtime errors\n * specific to plugins.\n *\n * @example\n * ```typescript\n * throw new PluginError(\n * 'Failed to initialize cache plugin',\n * 'cache-plugin',\n * { reason: 'Redis connection failed' }\n * );\n * ```\n */\nexport class PluginError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new PluginError.\n *\n * @param message - Human-readable error message\n * @param pluginName - Name of the plugin that caused the error\n * @param context - Additional context about the plugin error\n */\n constructor(\n message: string,\n public readonly pluginName: string,\n context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.PLUGIN_ERROR, { pluginName, ...context });\n this.name = 'PluginError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n","/**\n * @oxog/types - Type guard functions\n * @version 1.0.2\n * @author Ersin Koç\n */\n\nimport type { Plugin, Kernel } from './plugin.js';\nimport type { Result, Ok, Err } from './result.js';\nimport { OxogError, ValidationError, PluginError } from './errors.js';\n\n/**\n * Type guard for Plugin.\n *\n * Checks if a value is a valid Plugin instance.\n *\n * @example\n * ```typescript\n * const plugin = { name: 'test', version: '1.0.0', install: () => {} };\n * if (isPlugin(plugin)) {\n * console.log(plugin.name); // TypeScript knows it's a Plugin\n * }\n * ```\n */\nexport function isPlugin<T>(value: unknown): value is Plugin<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Plugin<T>).name === 'string' &&\n typeof (value as Plugin<T>).version === 'string' &&\n typeof (value as Plugin<T>).install === 'function'\n );\n}\n\n/**\n * Type guard for Kernel.\n *\n * Checks if a value is a valid Kernel instance.\n *\n * @example\n * ```typescript\n * const kernel = {\n * use: (plugin) => kernel,\n * unregister: () => true,\n * getPlugin: () => undefined,\n * listPlugins: () => [],\n * hasPlugin: () => false,\n * emit: () => {},\n * on: () => () => {},\n * getContext: () => null\n * };\n * if (isKernel(kernel)) {\n * console.log(kernel.listPlugins()); // TypeScript knows it's a Kernel\n * }\n * ```\n */\nexport function isKernel<T>(value: unknown): value is Kernel<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Kernel<T>).use === 'function' &&\n typeof (value as Kernel<T>).unregister === 'function' &&\n typeof (value as Kernel<T>).getPlugin === 'function' &&\n typeof (value as Kernel<T>).listPlugins === 'function' &&\n typeof (value as Kernel<T>).hasPlugin === 'function' &&\n typeof (value as Kernel<T>).emit === 'function' &&\n typeof (value as Kernel<T>).on === 'function' &&\n typeof (value as Kernel<T>).getContext === 'function'\n );\n}\n\n/**\n * Type guard for OxogError.\n *\n * Checks if a value is an OxogError instance.\n *\n * @example\n * ```typescript\n * const error = new OxogError('Test', 'TEST');\n * if (isOxogError(error)) {\n * console.log(error.code); // TypeScript knows it's an OxogError\n * }\n * ```\n */\nexport function isOxogError(value: unknown): value is OxogError {\n return value instanceof OxogError;\n}\n\n/**\n * Type guard for ValidationError.\n *\n * Checks if a value is a ValidationError instance.\n *\n * @example\n * ```typescript\n * const error = new ValidationError('Invalid', { field: 'test' });\n * if (isValidationError(error)) {\n * console.log(error.context); // TypeScript knows it's a ValidationError\n * }\n * ```\n */\nexport function isValidationError(value: unknown): value is ValidationError {\n return value instanceof ValidationError;\n}\n\n/**\n * Type guard for PluginError.\n *\n * Checks if a value is a PluginError instance.\n *\n * @example\n * ```typescript\n * const error = new PluginError('Plugin failed', 'my-plugin');\n * if (isPluginError(error)) {\n * console.log(error.pluginName); // TypeScript knows it's a PluginError\n * }\n * ```\n */\nexport function isPluginError(value: unknown): value is PluginError {\n return value instanceof PluginError;\n}\n\n/**\n * Type guard for Result.\n *\n * Checks if a value is a Result instance (either Ok or Err).\n *\n * @example\n * ```typescript\n * const result = Ok(42);\n * if (isResult(result)) {\n * // result is Ok<number, unknown>\n * }\n *\n * const err = Err('error');\n * if (isResult(err)) {\n * // err is Err<unknown, string>\n * }\n * ```\n */\nexport function isResult<T, E>(value: unknown): value is Result<T, E> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Result<T, E>).ok === 'boolean' &&\n (('value' in (value as object)) || ('error' in (value as object)))\n );\n}\n\n/**\n * Type guard for Ok result.\n *\n * Checks if a Result is an Ok (success) instance.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // TypeScript knows it's Ok\n * }\n * ```\n */\nexport function isOk<T>(value: Result<T, unknown>): value is Ok<T> {\n return isResult(value) && value.ok === true;\n}\n\n/**\n * Type guard for Err result.\n *\n * Checks if a Result is an Err (failure) instance.\n *\n * @example\n * ```typescript\n * const err = Err('error');\n * if (isErr(err)) {\n * console.log(err.error); // TypeScript knows it's Err\n * }\n * ```\n */\nexport function isErr<E>(value: Result<unknown, E>): value is Err<E> {\n return isResult(value) && value.ok === false;\n}\n","/**\r\n * @oxog/types - Well-known symbols and constants\r\n * @version 1.0.2\r\n * @author Ersin Koç\r\n */\r\n\r\nimport { ErrorCodes } from './errors.js';\r\n\r\n/**\r\n * Well-known symbol for @oxog plugins.\r\n *\r\n * Use this symbol to mark objects as @oxog plugins.\r\n * This enables runtime detection and validation.\r\n *\r\n * @example\r\n * ```typescript\r\n * const myPlugin = {\r\n * [OXOG_PLUGIN]: true,\r\n * name: 'my-plugin',\r\n * version: '1.0.0',\r\n * install: () => {}\r\n * };\r\n * ```\r\n */\r\nexport const OXOG_PLUGIN = Symbol.for('@oxog/plugin');\r\n\r\n/**\r\n * Well-known symbol for @oxog kernels.\r\n *\r\n * Use this symbol to mark objects as @oxog kernels.\r\n * This enables runtime detection and validation.\r\n *\r\n * @example\r\n * ```typescript\r\n * const myKernel = {\r\n * [OXOG_KERNEL]: true,\r\n * use: (plugin) => kernel,\r\n * // ... other methods\r\n * };\r\n * ```\r\n */\r\nexport const OXOG_KERNEL = Symbol.for('@oxog/kernel');\r\n\r\n/**\r\n * @oxog/types package version.\r\n *\r\n * Current version of the @oxog/types package.\r\n *\r\n * @example\r\n * ```typescript\r\n * console.log(`Using @oxog/types v${OXOG_VERSION}`);\r\n * ```\r\n */\r\nexport const OXOG_VERSION = '1.0.2';\r\n\r\n/**\r\n * Standard error codes for @oxog ecosystem.\r\n *\r\n * Re-exported from errors module for convenience.\r\n *\r\n * @example\r\n * ```typescript\r\n * throw new OxogError('Not found', ErrorCodes.NOT_FOUND);\r\n * ```\r\n */\r\nexport { ErrorCodes };\r\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @oxog/types - Common TypeScript utility types
3
- * @version 1.0.1
3
+ * @version 1.0.2
4
4
  * @author Ersin Koç
5
5
  */
6
6
  /** Brand symbol for branded types */
@@ -294,10 +294,150 @@ type Optional<T> = T | undefined;
294
294
  * ```
295
295
  */
296
296
  type Unsubscribe = () => void;
297
+ /**
298
+ * Extract the value types from an object type.
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * const colors = { red: '#ff0000', green: '#00ff00' } as const;
303
+ * type ColorValue = ValueOf<typeof colors>; // '#ff0000' | '#00ff00'
304
+ * ```
305
+ */
306
+ type ValueOf<T> = T[keyof T];
307
+ /**
308
+ * Make specified keys required while keeping others optional.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * interface User {
313
+ * id?: string;
314
+ * name?: string;
315
+ * email?: string;
316
+ * }
317
+ *
318
+ * type UserWithId = RequireKeys<User, 'id'>;
319
+ * // { id: string; name?: string; email?: string }
320
+ * ```
321
+ */
322
+ type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
323
+ /**
324
+ * Make specified keys optional while keeping others required.
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * interface User {
329
+ * id: string;
330
+ * name: string;
331
+ * email: string;
332
+ * }
333
+ *
334
+ * type UserDraft = OptionalKeys<User, 'id'>;
335
+ * // { id?: string; name: string; email: string }
336
+ * ```
337
+ */
338
+ type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
339
+ /**
340
+ * Extract keys of T that have values assignable to V.
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * interface User {
345
+ * id: number;
346
+ * name: string;
347
+ * email: string;
348
+ * age: number;
349
+ * }
350
+ *
351
+ * type StringKeys = KeysOfType<User, string>; // 'name' | 'email'
352
+ * ```
353
+ */
354
+ type KeysOfType<T, V> = {
355
+ [K in keyof T]: T[K] extends V ? K : never;
356
+ }[keyof T];
357
+ /**
358
+ * Type that excludes null and undefined from T.
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * type MaybeString = string | null | undefined;
363
+ * type DefinitelyString = NonNullish<MaybeString>; // string
364
+ * ```
365
+ */
366
+ type NonNullish<T> = Exclude<T, null | undefined>;
367
+ /**
368
+ * Makes all properties of T mutable (removes readonly).
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * interface ReadonlyUser {
373
+ * readonly id: string;
374
+ * readonly name: string;
375
+ * }
376
+ *
377
+ * type MutableUser = Mutable<ReadonlyUser>;
378
+ * // { id: string; name: string }
379
+ * ```
380
+ */
381
+ type Mutable<T> = {
382
+ -readonly [P in keyof T]: T[P];
383
+ };
384
+ /**
385
+ * Deep mutable - removes readonly from all nested properties.
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * interface ReadonlyConfig {
390
+ * readonly api: {
391
+ * readonly url: string;
392
+ * };
393
+ * }
394
+ *
395
+ * type MutableConfig = DeepMutable<ReadonlyConfig>;
396
+ * // { api: { url: string } }
397
+ * ```
398
+ */
399
+ type DeepMutable<T> = T extends object ? {
400
+ -readonly [P in keyof T]: DeepMutable<T[P]>;
401
+ } : T;
402
+ /**
403
+ * Tuple type with exact length.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * type Point2D = Tuple<number, 2>; // [number, number]
408
+ * type RGB = Tuple<number, 3>; // [number, number, number]
409
+ * ```
410
+ */
411
+ type Tuple<T, N extends number, R extends T[] = []> = R['length'] extends N ? R : Tuple<T, N, [T, ...R]>;
412
+ /**
413
+ * Get the element type of an array.
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * type Numbers = number[];
418
+ * type Num = ArrayElement<Numbers>; // number
419
+ *
420
+ * const tuple = ['a', 1, true] as const;
421
+ * type TupleElement = ArrayElement<typeof tuple>; // 'a' | 1 | true
422
+ * ```
423
+ */
424
+ type ArrayElement<T extends readonly unknown[]> = T[number];
425
+ /**
426
+ * Literal union type helper for better autocomplete.
427
+ *
428
+ * @example
429
+ * ```typescript
430
+ * type Color = LiteralUnion<'red' | 'green' | 'blue', string>;
431
+ * // Allows 'red', 'green', 'blue' with autocomplete, but accepts any string
432
+ * ```
433
+ */
434
+ type LiteralUnion<T extends U, U = string> = T | (U & {
435
+ _brand?: never;
436
+ });
297
437
 
298
438
  /**
299
439
  * @oxog/types - Plugin and Kernel interfaces
300
- * @version 1.0.1
440
+ * @version 1.0.2
301
441
  * @author Ersin Koç
302
442
  */
303
443
 
@@ -468,7 +608,7 @@ interface PluginLogger {
468
608
  type Result<T, E> = Ok<T> | Err<E>;
469
609
  /**
470
610
  * @oxog/types - Result type for functional error handling
471
- * @version 1.0.1
611
+ * @version 1.0.2
472
612
  * @author Ersin Koç
473
613
  */
474
614
  /**
@@ -570,7 +710,7 @@ declare function Err<E>(error: E): Err<E>;
570
710
 
571
711
  /**
572
712
  * @oxog/types - Standardized error classes
573
- * @version 1.0.1
713
+ * @version 1.0.2
574
714
  * @author Ersin Koç
575
715
  */
576
716
  /**
@@ -677,7 +817,7 @@ declare class PluginError extends OxogError {
677
817
 
678
818
  /**
679
819
  * @oxog/types - Type guard functions
680
- * @version 1.0.1
820
+ * @version 1.0.2
681
821
  * @author Ersin Koç
682
822
  */
683
823
 
@@ -810,7 +950,7 @@ declare function isErr<E>(value: Result<unknown, E>): value is Err<E>;
810
950
 
811
951
  /**
812
952
  * @oxog/types - Event system types
813
- * @version 1.0.1
953
+ * @version 1.0.2
814
954
  * @author Ersin Koç
815
955
  */
816
956
 
@@ -893,7 +1033,7 @@ interface TypedEventEmitter<TEvents extends EventMap> {
893
1033
 
894
1034
  /**
895
1035
  * @oxog/types - Well-known symbols and constants
896
- * @version 1.0.1
1036
+ * @version 1.0.2
897
1037
  * @author Ersin Koç
898
1038
  */
899
1039
 
@@ -940,6 +1080,6 @@ declare const OXOG_KERNEL: unique symbol;
940
1080
  * console.log(`Using @oxog/types v${OXOG_VERSION}`);
941
1081
  * ```
942
1082
  */
943
- declare const OXOG_VERSION = "1.0.1";
1083
+ declare const OXOG_VERSION = "1.0.2";
944
1084
 
945
- export { type AnyFunction, type AsyncFunction, type Brand, type Branded, type DeepPartial, type DeepReadonly, type DeepRequired, Err, ErrorCodes, type EventHandler, type EventMap, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type Kernel, type MaybePromise, type NonEmptyArray, type Nullable, OXOG_KERNEL, OXOG_PLUGIN, OXOG_VERSION, Ok, type Optional, OxogError, type Plugin, PluginError, type PluginLogger, type PluginOptions, type Prettify, type Result, type StrictOmit, type StrictPick, type SyncFunction, type TypedEventEmitter, type Unsubscribe, ValidationError, isErr, isKernel, isOk, isOxogError, isPlugin, isPluginError, isResult, isValidationError };
1085
+ export { type AnyFunction, type ArrayElement, type AsyncFunction, type Brand, type Branded, type DeepMutable, type DeepPartial, type DeepReadonly, type DeepRequired, Err, ErrorCodes, type EventHandler, type EventMap, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type Kernel, type KeysOfType, type LiteralUnion, type MaybePromise, type Mutable, type NonEmptyArray, type NonNullish, type Nullable, OXOG_KERNEL, OXOG_PLUGIN, OXOG_VERSION, Ok, type Optional, type OptionalKeys, OxogError, type Plugin, PluginError, type PluginLogger, type PluginOptions, type Prettify, type RequireKeys, type Result, type StrictOmit, type StrictPick, type SyncFunction, type Tuple, type TypedEventEmitter, type Unsubscribe, ValidationError, type ValueOf, isErr, isKernel, isOk, isOxogError, isPlugin, isPluginError, isResult, isValidationError };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @oxog/types - Common TypeScript utility types
3
- * @version 1.0.1
3
+ * @version 1.0.2
4
4
  * @author Ersin Koç
5
5
  */
6
6
  /** Brand symbol for branded types */
@@ -294,10 +294,150 @@ type Optional<T> = T | undefined;
294
294
  * ```
295
295
  */
296
296
  type Unsubscribe = () => void;
297
+ /**
298
+ * Extract the value types from an object type.
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * const colors = { red: '#ff0000', green: '#00ff00' } as const;
303
+ * type ColorValue = ValueOf<typeof colors>; // '#ff0000' | '#00ff00'
304
+ * ```
305
+ */
306
+ type ValueOf<T> = T[keyof T];
307
+ /**
308
+ * Make specified keys required while keeping others optional.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * interface User {
313
+ * id?: string;
314
+ * name?: string;
315
+ * email?: string;
316
+ * }
317
+ *
318
+ * type UserWithId = RequireKeys<User, 'id'>;
319
+ * // { id: string; name?: string; email?: string }
320
+ * ```
321
+ */
322
+ type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
323
+ /**
324
+ * Make specified keys optional while keeping others required.
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * interface User {
329
+ * id: string;
330
+ * name: string;
331
+ * email: string;
332
+ * }
333
+ *
334
+ * type UserDraft = OptionalKeys<User, 'id'>;
335
+ * // { id?: string; name: string; email: string }
336
+ * ```
337
+ */
338
+ type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
339
+ /**
340
+ * Extract keys of T that have values assignable to V.
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * interface User {
345
+ * id: number;
346
+ * name: string;
347
+ * email: string;
348
+ * age: number;
349
+ * }
350
+ *
351
+ * type StringKeys = KeysOfType<User, string>; // 'name' | 'email'
352
+ * ```
353
+ */
354
+ type KeysOfType<T, V> = {
355
+ [K in keyof T]: T[K] extends V ? K : never;
356
+ }[keyof T];
357
+ /**
358
+ * Type that excludes null and undefined from T.
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * type MaybeString = string | null | undefined;
363
+ * type DefinitelyString = NonNullish<MaybeString>; // string
364
+ * ```
365
+ */
366
+ type NonNullish<T> = Exclude<T, null | undefined>;
367
+ /**
368
+ * Makes all properties of T mutable (removes readonly).
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * interface ReadonlyUser {
373
+ * readonly id: string;
374
+ * readonly name: string;
375
+ * }
376
+ *
377
+ * type MutableUser = Mutable<ReadonlyUser>;
378
+ * // { id: string; name: string }
379
+ * ```
380
+ */
381
+ type Mutable<T> = {
382
+ -readonly [P in keyof T]: T[P];
383
+ };
384
+ /**
385
+ * Deep mutable - removes readonly from all nested properties.
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * interface ReadonlyConfig {
390
+ * readonly api: {
391
+ * readonly url: string;
392
+ * };
393
+ * }
394
+ *
395
+ * type MutableConfig = DeepMutable<ReadonlyConfig>;
396
+ * // { api: { url: string } }
397
+ * ```
398
+ */
399
+ type DeepMutable<T> = T extends object ? {
400
+ -readonly [P in keyof T]: DeepMutable<T[P]>;
401
+ } : T;
402
+ /**
403
+ * Tuple type with exact length.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * type Point2D = Tuple<number, 2>; // [number, number]
408
+ * type RGB = Tuple<number, 3>; // [number, number, number]
409
+ * ```
410
+ */
411
+ type Tuple<T, N extends number, R extends T[] = []> = R['length'] extends N ? R : Tuple<T, N, [T, ...R]>;
412
+ /**
413
+ * Get the element type of an array.
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * type Numbers = number[];
418
+ * type Num = ArrayElement<Numbers>; // number
419
+ *
420
+ * const tuple = ['a', 1, true] as const;
421
+ * type TupleElement = ArrayElement<typeof tuple>; // 'a' | 1 | true
422
+ * ```
423
+ */
424
+ type ArrayElement<T extends readonly unknown[]> = T[number];
425
+ /**
426
+ * Literal union type helper for better autocomplete.
427
+ *
428
+ * @example
429
+ * ```typescript
430
+ * type Color = LiteralUnion<'red' | 'green' | 'blue', string>;
431
+ * // Allows 'red', 'green', 'blue' with autocomplete, but accepts any string
432
+ * ```
433
+ */
434
+ type LiteralUnion<T extends U, U = string> = T | (U & {
435
+ _brand?: never;
436
+ });
297
437
 
298
438
  /**
299
439
  * @oxog/types - Plugin and Kernel interfaces
300
- * @version 1.0.1
440
+ * @version 1.0.2
301
441
  * @author Ersin Koç
302
442
  */
303
443
 
@@ -468,7 +608,7 @@ interface PluginLogger {
468
608
  type Result<T, E> = Ok<T> | Err<E>;
469
609
  /**
470
610
  * @oxog/types - Result type for functional error handling
471
- * @version 1.0.1
611
+ * @version 1.0.2
472
612
  * @author Ersin Koç
473
613
  */
474
614
  /**
@@ -570,7 +710,7 @@ declare function Err<E>(error: E): Err<E>;
570
710
 
571
711
  /**
572
712
  * @oxog/types - Standardized error classes
573
- * @version 1.0.1
713
+ * @version 1.0.2
574
714
  * @author Ersin Koç
575
715
  */
576
716
  /**
@@ -677,7 +817,7 @@ declare class PluginError extends OxogError {
677
817
 
678
818
  /**
679
819
  * @oxog/types - Type guard functions
680
- * @version 1.0.1
820
+ * @version 1.0.2
681
821
  * @author Ersin Koç
682
822
  */
683
823
 
@@ -810,7 +950,7 @@ declare function isErr<E>(value: Result<unknown, E>): value is Err<E>;
810
950
 
811
951
  /**
812
952
  * @oxog/types - Event system types
813
- * @version 1.0.1
953
+ * @version 1.0.2
814
954
  * @author Ersin Koç
815
955
  */
816
956
 
@@ -893,7 +1033,7 @@ interface TypedEventEmitter<TEvents extends EventMap> {
893
1033
 
894
1034
  /**
895
1035
  * @oxog/types - Well-known symbols and constants
896
- * @version 1.0.1
1036
+ * @version 1.0.2
897
1037
  * @author Ersin Koç
898
1038
  */
899
1039
 
@@ -940,6 +1080,6 @@ declare const OXOG_KERNEL: unique symbol;
940
1080
  * console.log(`Using @oxog/types v${OXOG_VERSION}`);
941
1081
  * ```
942
1082
  */
943
- declare const OXOG_VERSION = "1.0.1";
1083
+ declare const OXOG_VERSION = "1.0.2";
944
1084
 
945
- export { type AnyFunction, type AsyncFunction, type Brand, type Branded, type DeepPartial, type DeepReadonly, type DeepRequired, Err, ErrorCodes, type EventHandler, type EventMap, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type Kernel, type MaybePromise, type NonEmptyArray, type Nullable, OXOG_KERNEL, OXOG_PLUGIN, OXOG_VERSION, Ok, type Optional, OxogError, type Plugin, PluginError, type PluginLogger, type PluginOptions, type Prettify, type Result, type StrictOmit, type StrictPick, type SyncFunction, type TypedEventEmitter, type Unsubscribe, ValidationError, isErr, isKernel, isOk, isOxogError, isPlugin, isPluginError, isResult, isValidationError };
1085
+ export { type AnyFunction, type ArrayElement, type AsyncFunction, type Brand, type Branded, type DeepMutable, type DeepPartial, type DeepReadonly, type DeepRequired, Err, ErrorCodes, type EventHandler, type EventMap, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type Kernel, type KeysOfType, type LiteralUnion, type MaybePromise, type Mutable, type NonEmptyArray, type NonNullish, type Nullable, OXOG_KERNEL, OXOG_PLUGIN, OXOG_VERSION, Ok, type Optional, type OptionalKeys, OxogError, type Plugin, PluginError, type PluginLogger, type PluginOptions, type Prettify, type RequireKeys, type Result, type StrictOmit, type StrictPick, type SyncFunction, type Tuple, type TypedEventEmitter, type Unsubscribe, ValidationError, type ValueOf, isErr, isKernel, isOk, isOxogError, isPlugin, isPluginError, isResult, isValidationError };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var l=class{constructor(e){this.value=e;}ok=true;error=void 0;map(e){return E(e(this.value))}mapErr(e){return this}match(e){return e.ok(this.value)}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}},p=class{constructor(e){this.error=e;}ok=false;value=void 0;map(e){return this}mapErr(e){return T(e(this.error))}match(e){return e.err(this.error)}unwrap(){throw new Error(`Cannot unwrap Err: ${String(this.error)}`)}unwrapOr(e){return e}unwrapOrElse(e){return e(this.error)}};function E(r){return new l(r)}function T(r){return new p(r)}var c=(n=>(n.UNKNOWN="UNKNOWN",n.VALIDATION_ERROR="VALIDATION_ERROR",n.PLUGIN_ERROR="PLUGIN_ERROR",n.NOT_FOUND="NOT_FOUND",n.TIMEOUT="TIMEOUT",n.DEPENDENCY_ERROR="DEPENDENCY_ERROR",n))(c||{}),t=class extends Error{constructor(o,u,a){super(o);this.code=u;this.context=a;this.name="OxogError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},s=class extends t{constructor(o,u){super(o,"VALIDATION_ERROR",u);this.context=u;this.name="ValidationError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},i=class extends t{constructor(o,u,a){super(o,"PLUGIN_ERROR",a?{pluginName:u,...a}:void 0);this.pluginName=u;this.name="PluginError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name};function d(r){return r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.version=="string"&&typeof r.install=="function"}function m(r){return r!==null&&typeof r=="object"&&typeof r.use=="function"&&typeof r.unregister=="function"&&typeof r.getPlugin=="function"&&typeof r.listPlugins=="function"&&typeof r.hasPlugin=="function"&&typeof r.emit=="function"&&typeof r.on=="function"&&typeof r.getContext=="function"}function R(r){return r instanceof t}function x(r){return r instanceof s}function k(r){return r instanceof i}function f(r){return r!==null&&typeof r=="object"&&typeof r.ok=="boolean"&&("value"in r||"error"in r)}function U(r){return f(r)&&r.ok===true}function w(r){return f(r)&&r.ok===false}var N=Symbol.for("@oxog/plugin"),P=Symbol.for("@oxog/kernel"),b="1.0.1";export{T as Err,c as ErrorCodes,P as OXOG_KERNEL,N as OXOG_PLUGIN,b as OXOG_VERSION,E as Ok,t as OxogError,i as PluginError,s as ValidationError,w as isErr,m as isKernel,U as isOk,R as isOxogError,d as isPlugin,k as isPluginError,f as isResult,x as isValidationError};//# sourceMappingURL=index.js.map
1
+ var i=class{constructor(e){this.value=e;}ok=true;error=void 0;map(e){return E(e(this.value))}mapErr(e){return this}match(e){return e.ok(this.value)}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}},l=class{constructor(e){this.error=e;}ok=false;value=void 0;map(e){return this}mapErr(e){return T(e(this.error))}match(e){return e.err(this.error)}unwrap(){throw new Error(`Cannot unwrap Err: ${String(this.error)}`)}unwrapOr(e){return e}unwrapOrElse(e){return e(this.error)}};function E(r){return new i(r)}function T(r){return new l(r)}var c=(n=>(n.UNKNOWN="UNKNOWN",n.VALIDATION_ERROR="VALIDATION_ERROR",n.PLUGIN_ERROR="PLUGIN_ERROR",n.NOT_FOUND="NOT_FOUND",n.TIMEOUT="TIMEOUT",n.DEPENDENCY_ERROR="DEPENDENCY_ERROR",n))(c||{}),t=class extends Error{constructor(o,u,p){super(o);this.code=u;this.context=p;this.name="OxogError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},s=class extends t{constructor(o,u){super(o,"VALIDATION_ERROR",u);this.context=u;this.name="ValidationError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name},a=class extends t{constructor(o,u,p){super(o,"PLUGIN_ERROR",{pluginName:u,...p});this.pluginName=u;this.name="PluginError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace(this,new.target);}name};function m(r){return r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.version=="string"&&typeof r.install=="function"}function R(r){return r!==null&&typeof r=="object"&&typeof r.use=="function"&&typeof r.unregister=="function"&&typeof r.getPlugin=="function"&&typeof r.listPlugins=="function"&&typeof r.hasPlugin=="function"&&typeof r.emit=="function"&&typeof r.on=="function"&&typeof r.getContext=="function"}function d(r){return r instanceof t}function x(r){return r instanceof s}function k(r){return r instanceof a}function f(r){return r!==null&&typeof r=="object"&&typeof r.ok=="boolean"&&("value"in r||"error"in r)}function U(r){return f(r)&&r.ok===true}function w(r){return f(r)&&r.ok===false}var N=Symbol.for("@oxog/plugin"),P=Symbol.for("@oxog/kernel"),b="1.0.2";export{T as Err,c as ErrorCodes,P as OXOG_KERNEL,N as OXOG_PLUGIN,b as OXOG_VERSION,E as Ok,t as OxogError,a as PluginError,s as ValidationError,w as isErr,R as isKernel,U as isOk,d as isOxogError,m as isPlugin,k as isPluginError,f as isResult,x as isValidationError};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/result.ts","../src/errors.ts","../src/guards.ts","../src/constants.ts"],"names":["OkImpl","value","fn","Ok","_fn","handlers","_defaultValue","ErrImpl","error","Err","defaultValue","ErrorCodes","OxogError","message","code","context","ValidationError","PluginError","pluginName","isPlugin","isKernel","isOxogError","isValidationError","isPluginError","isResult","isOk","isErr","OXOG_PLUGIN","OXOG_KERNEL","OXOG_VERSION"],"mappings":"AAqHA,IAAMA,CAAAA,CAAN,KAAiC,CAI/B,WAAA,CAA4BC,EAAU,CAAV,IAAA,CAAA,KAAA,CAAAA,EAAW,CAH9B,EAAA,CAAK,IAAA,CACL,MAAQ,MAAA,CAIjB,GAAA,CAAOC,EAAuC,CAC5C,OAAOC,EAAGD,CAAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAC1B,CAEA,OAAUE,CAAAA,CAAiC,CACzC,OAAO,IACT,CAEA,MAASC,CAAAA,CAAgE,CACvE,OAAOA,CAAAA,CAAS,EAAA,CAAG,IAAA,CAAK,KAAK,CAC/B,CAEA,MAAA,EAAY,CACV,OAAO,IAAA,CAAK,KACd,CAEA,QAAA,CAASC,CAAAA,CAAqB,CAC5B,OAAO,IAAA,CAAK,KACd,CAEA,YAAA,CAAaF,EAAiB,CAC5B,OAAO,KAAK,KACd,CACF,CAAA,CAKMG,CAAAA,CAAN,KAAmC,CAI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OAAOA,CAAAA,EAAU,UACjB,OAAQA,CAAAA,CAAoB,GAAA,EAAQ,UAAA,EACpC,OAAQA,CAAAA,CAAoB,YAAe,UAAA,EAC3C,OAAQA,EAAoB,SAAA,EAAc,UAAA,EAC1C,OAAQA,CAAAA,CAAoB,WAAA,EAAgB,UAAA,EAC5C,OAAQA,CAAAA,CAAoB,SAAA,EAAc,YAC1C,OAAQA,CAAAA,CAAoB,MAAS,UAAA,EACrC,OAAQA,EAAoB,EAAA,EAAO,UAAA,EACnC,OAAQA,CAAAA,CAAoB,UAAA,EAAe,UAE/C,CAeO,SAASoB,CAAAA,CAAYpB,EAAoC,CAC9D,OAAOA,aAAiBW,CAC1B,CAeO,SAASU,CAAAA,CAAkBrB,CAAAA,CAA0C,CAC1E,OAAOA,CAAAA,YAAiBe,CAC1B,CAeO,SAASO,CAAAA,CAActB,CAAAA,CAAsC,CAClE,OAAOA,CAAAA,YAAiBgB,CAC1B,CAoBO,SAASO,CAAAA,CAAevB,EAAuC,CACpE,OACEA,IAAU,IAAA,EACV,OAAOA,GAAU,QAAA,EACjB,OAAQA,CAAAA,CAAuB,EAAA,EAAO,SAAA,GACpC,OAAA,GAAYA,GAAsB,OAAA,GAAYA,CAAAA,CAEpD,CAeO,SAASwB,CAAAA,CAAQxB,CAAAA,CAA2C,CACjE,OAAOuB,CAAAA,CAASvB,CAAK,CAAA,EAAKA,CAAAA,CAAM,EAAA,GAAO,IACzC,CAeO,SAASyB,EAASzB,CAAAA,CAA4C,CACnE,OAAOuB,CAAAA,CAASvB,CAAK,CAAA,EAAKA,CAAAA,CAAM,EAAA,GAAO,KACzC,CC5JO,IAAM0B,CAAAA,CAAc,MAAA,CAAO,GAAA,CAAI,cAAc,CAAA,CAiBvCC,EAAc,MAAA,CAAO,GAAA,CAAI,cAAc,CAAA,CAYvCC,CAAAA,CAAe","file":"index.js","sourcesContent":["/**\n * @oxog/types - Result type for functional error handling\n * @version 1.0.1\n * @author Ersin Koç\n */\n\n/**\n * Represents a successful result.\n *\n * Contains a value and provides methods for transforming the value\n * or handling errors. Only available on successful results.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // 42\n * }\n * ```\n */\nexport interface Ok<T> {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n\n /** Transform the value if successful */\n map<U>(fn: (value: T) => U): Result<U, never>;\n\n /** Transform the error (no-op for Ok) */\n mapErr<F>(fn: (error: never) => F): Ok<T>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U;\n\n /** Unwrap the value (asserts success) */\n unwrap(): T;\n\n /** Unwrap with default value */\n unwrapOr(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse(fn: () => T): T;\n}\n\n/**\n * Represents a failed result.\n *\n * Contains an error and provides methods for transforming the error\n * or handling success cases. Only available on failed results.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * if (isErr(err)) {\n * console.log(err.error); // 'Something went wrong'\n * }\n * ```\n */\nexport interface Err<E> {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n\n /** Transform the value (no-op for Err) */\n map<U>(fn: (value: never) => U): Err<E>;\n\n /** Transform the error if failed */\n mapErr<F>(fn: (error: E) => F): Result<never, F>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U;\n\n /** Unwrap the value (asserts success, throws for Err) */\n unwrap(): never;\n\n /** Unwrap with default value */\n unwrapOr<T>(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse<T>(fn: () => T): T;\n}\n\n/**\n * Result type - either Ok<T> or Err<E>.\n *\n * A type that represents either success (Ok) or failure (Err).\n * This is inspired by Rust's Result type and provides functional\n * error handling without exceptions.\n *\n * @example\n * ```typescript\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) {\n * return Err('Division by zero');\n * }\n * return Ok(a / b);\n * }\n *\n * const result = divide(10, 2);\n *\n * // Pattern matching\n * const message = result.match({\n * ok: (value) => `Result: ${value}`,\n * err: (error) => `Error: ${error}`\n * });\n *\n * // Chaining\n * const doubled = result\n * .map(x => x * 2)\n * .mapErr(e => `Calculation failed: ${e}`);\n * ```\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Internal implementation of Ok result.\n */\nclass OkImpl<T> implements Ok<T> {\n readonly ok = true as const;\n readonly error = undefined as never;\n\n constructor(public readonly value: T) {}\n\n map<U>(fn: (value: T) => U): Result<U, never> {\n return Ok(fn(this.value));\n }\n\n mapErr<F>(_fn: (error: never) => F): Ok<T> {\n return this;\n }\n\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U {\n return handlers.ok(this.value);\n }\n\n unwrap(): T {\n return this.value;\n }\n\n unwrapOr(_defaultValue: T): T {\n return this.value;\n }\n\n unwrapOrElse(_fn: () => T): T {\n return this.value;\n }\n}\n\n/**\n * Internal implementation of Err result.\n */\nclass ErrImpl<E> implements Err<E> {\n readonly ok = false as const;\n readonly value = undefined as never;\n\n constructor(public readonly error: E) {}\n\n map<U>(_fn: (value: never) => U): Err<E> {\n return this;\n }\n\n mapErr<F>(fn: (error: E) => F): Result<never, F> {\n return Err(fn(this.error));\n }\n\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U {\n return handlers.err(this.error);\n }\n\n unwrap(): never {\n throw new Error(`Cannot unwrap Err: ${String(this.error)}`);\n }\n\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n unwrapOrElse<T>(fn: (error: E) => T): T {\n return fn(this.error);\n }\n}\n\n/**\n * Creates a successful Result containing a value.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * const okStr = Ok('hello');\n * const okObj = Ok({ id: 1 });\n * ```\n *\n * @param value - The value to wrap\n * @returns An Ok result containing the value\n */\nexport function Ok<T>(value: T): Ok<T> {\n return new OkImpl(value);\n}\n\n/**\n * Creates a failed Result containing an error.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * const errNum = Err(404);\n * const errObj = Err({ code: 'NOT_FOUND' });\n * ```\n *\n * @param error - The error to wrap\n * @returns An Err result containing the error\n */\nexport function Err<E>(error: E): Err<E> {\n return new ErrImpl(error);\n}\n","/**\n * @oxog/types - Standardized error classes\n * @version 1.0.1\n * @author Ersin Koç\n */\n\n/**\n * Standard error codes for @oxog ecosystem.\n *\n * These codes provide programmatic ways to identify and handle errors.\n */\nexport enum ErrorCodes {\n /** Unknown error */\n UNKNOWN = 'UNKNOWN',\n\n /** Validation error */\n VALIDATION_ERROR = 'VALIDATION_ERROR',\n\n /** Plugin-related error */\n PLUGIN_ERROR = 'PLUGIN_ERROR',\n\n /** Resource not found */\n NOT_FOUND = 'NOT_FOUND',\n\n /** Operation timed out */\n TIMEOUT = 'TIMEOUT',\n\n /** Dependency error */\n DEPENDENCY_ERROR = 'DEPENDENCY_ERROR',\n}\n\n/**\n * Base error class for all @oxog errors.\n *\n * Provides structured error information with code, message, and context.\n * All other @oxog errors inherit from this class.\n *\n * @example\n * ```typescript\n * throw new OxogError(\n * 'Database connection failed',\n * ErrorCodes.DEPENDENCY_ERROR,\n * { host: 'localhost', port: 5432 }\n * );\n * ```\n */\nexport class OxogError extends Error {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new OxogError.\n *\n * @param message - Human-readable error message\n * @param code - Error code for programmatic handling\n * @param context - Additional context about the error\n */\n constructor(\n message: string,\n public readonly code: string,\n public readonly context?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'OxogError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when validation fails.\n *\n * Used for input validation, schema validation, and type checking errors.\n *\n * @example\n * ```typescript\n * throw new ValidationError(\n * 'Invalid email format',\n * { field: 'email', value: 'not-an-email' }\n * );\n * ```\n */\nexport class ValidationError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new ValidationError.\n *\n * @param message - Human-readable error message\n * @param context - Additional context about the validation failure\n */\n constructor(\n message: string,\n public override readonly context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.VALIDATION_ERROR, context);\n this.name = 'ValidationError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Used for plugin initialization, dependency resolution, and runtime errors\n * specific to plugins.\n *\n * @example\n * ```typescript\n * throw new PluginError(\n * 'Failed to initialize cache plugin',\n * 'cache-plugin',\n * { reason: 'Redis connection failed' }\n * );\n * ```\n */\nexport class PluginError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new PluginError.\n *\n * @param message - Human-readable error message\n * @param pluginName - Name of the plugin that caused the error\n * @param context - Additional context about the plugin error\n */\n constructor(\n message: string,\n public readonly pluginName: string,\n context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.PLUGIN_ERROR, context ? { pluginName, ...context } : undefined);\n this.name = 'PluginError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n","/**\n * @oxog/types - Type guard functions\n * @version 1.0.1\n * @author Ersin Koç\n */\n\nimport type { Plugin, Kernel } from './plugin.js';\nimport type { Result, Ok, Err } from './result.js';\nimport { OxogError, ValidationError, PluginError } from './errors.js';\n\n/**\n * Type guard for Plugin.\n *\n * Checks if a value is a valid Plugin instance.\n *\n * @example\n * ```typescript\n * const plugin = { name: 'test', version: '1.0.0', install: () => {} };\n * if (isPlugin(plugin)) {\n * console.log(plugin.name); // TypeScript knows it's a Plugin\n * }\n * ```\n */\nexport function isPlugin<T>(value: unknown): value is Plugin<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Plugin<T>).name === 'string' &&\n typeof (value as Plugin<T>).version === 'string' &&\n typeof (value as Plugin<T>).install === 'function'\n );\n}\n\n/**\n * Type guard for Kernel.\n *\n * Checks if a value is a valid Kernel instance.\n *\n * @example\n * ```typescript\n * const kernel = {\n * use: (plugin) => kernel,\n * unregister: () => true,\n * getPlugin: () => undefined,\n * listPlugins: () => [],\n * hasPlugin: () => false,\n * emit: () => {},\n * on: () => () => {},\n * getContext: () => null\n * };\n * if (isKernel(kernel)) {\n * console.log(kernel.listPlugins()); // TypeScript knows it's a Kernel\n * }\n * ```\n */\nexport function isKernel<T>(value: unknown): value is Kernel<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Kernel<T>).use === 'function' &&\n typeof (value as Kernel<T>).unregister === 'function' &&\n typeof (value as Kernel<T>).getPlugin === 'function' &&\n typeof (value as Kernel<T>).listPlugins === 'function' &&\n typeof (value as Kernel<T>).hasPlugin === 'function' &&\n typeof (value as Kernel<T>).emit === 'function' &&\n typeof (value as Kernel<T>).on === 'function' &&\n typeof (value as Kernel<T>).getContext === 'function'\n );\n}\n\n/**\n * Type guard for OxogError.\n *\n * Checks if a value is an OxogError instance.\n *\n * @example\n * ```typescript\n * const error = new OxogError('Test', 'TEST');\n * if (isOxogError(error)) {\n * console.log(error.code); // TypeScript knows it's an OxogError\n * }\n * ```\n */\nexport function isOxogError(value: unknown): value is OxogError {\n return value instanceof OxogError;\n}\n\n/**\n * Type guard for ValidationError.\n *\n * Checks if a value is a ValidationError instance.\n *\n * @example\n * ```typescript\n * const error = new ValidationError('Invalid', { field: 'test' });\n * if (isValidationError(error)) {\n * console.log(error.context); // TypeScript knows it's a ValidationError\n * }\n * ```\n */\nexport function isValidationError(value: unknown): value is ValidationError {\n return value instanceof ValidationError;\n}\n\n/**\n * Type guard for PluginError.\n *\n * Checks if a value is a PluginError instance.\n *\n * @example\n * ```typescript\n * const error = new PluginError('Plugin failed', 'my-plugin');\n * if (isPluginError(error)) {\n * console.log(error.pluginName); // TypeScript knows it's a PluginError\n * }\n * ```\n */\nexport function isPluginError(value: unknown): value is PluginError {\n return value instanceof PluginError;\n}\n\n/**\n * Type guard for Result.\n *\n * Checks if a value is a Result instance (either Ok or Err).\n *\n * @example\n * ```typescript\n * const result = Ok(42);\n * if (isResult(result)) {\n * // result is Ok<number, unknown>\n * }\n *\n * const err = Err('error');\n * if (isResult(err)) {\n * // err is Err<unknown, string>\n * }\n * ```\n */\nexport function isResult<T, E>(value: unknown): value is Result<T, E> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Result<T, E>).ok === 'boolean' &&\n (('value' in (value as object)) || ('error' in (value as object)))\n );\n}\n\n/**\n * Type guard for Ok result.\n *\n * Checks if a Result is an Ok (success) instance.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // TypeScript knows it's Ok\n * }\n * ```\n */\nexport function isOk<T>(value: Result<T, unknown>): value is Ok<T> {\n return isResult(value) && value.ok === true;\n}\n\n/**\n * Type guard for Err result.\n *\n * Checks if a Result is an Err (failure) instance.\n *\n * @example\n * ```typescript\n * const err = Err('error');\n * if (isErr(err)) {\n * console.log(err.error); // TypeScript knows it's Err\n * }\n * ```\n */\nexport function isErr<E>(value: Result<unknown, E>): value is Err<E> {\n return isResult(value) && value.ok === false;\n}\n","/**\n * @oxog/types - Well-known symbols and constants\n * @version 1.0.1\n * @author Ersin Koç\n */\n\nimport { ErrorCodes } from './errors.js';\n\n/**\n * Well-known symbol for @oxog plugins.\n *\n * Use this symbol to mark objects as @oxog plugins.\n * This enables runtime detection and validation.\n *\n * @example\n * ```typescript\n * const myPlugin = {\n * [OXOG_PLUGIN]: true,\n * name: 'my-plugin',\n * version: '1.0.0',\n * install: () => {}\n * };\n * ```\n */\nexport const OXOG_PLUGIN = Symbol.for('@oxog/plugin');\n\n/**\n * Well-known symbol for @oxog kernels.\n *\n * Use this symbol to mark objects as @oxog kernels.\n * This enables runtime detection and validation.\n *\n * @example\n * ```typescript\n * const myKernel = {\n * [OXOG_KERNEL]: true,\n * use: (plugin) => kernel,\n * // ... other methods\n * };\n * ```\n */\nexport const OXOG_KERNEL = Symbol.for('@oxog/kernel');\n\n/**\n * @oxog/types package version.\n *\n * Current version of the @oxog/types package.\n *\n * @example\n * ```typescript\n * console.log(`Using @oxog/types v${OXOG_VERSION}`);\n * ```\n */\nexport const OXOG_VERSION = '1.0.1';\n\n/**\n * Standard error codes for @oxog ecosystem.\n *\n * Re-exported from errors module for convenience.\n *\n * @example\n * ```typescript\n * throw new OxogError('Not found', ErrorCodes.NOT_FOUND);\n * ```\n */\nexport { ErrorCodes };\n"]}
1
+ {"version":3,"sources":["../src/result.ts","../src/errors.ts","../src/guards.ts","../src/constants.ts"],"names":["OkImpl","value","fn","Ok","_fn","handlers","_defaultValue","ErrImpl","error","Err","defaultValue","ErrorCodes","OxogError","message","code","context","ValidationError","PluginError","pluginName","isPlugin","isKernel","isOxogError","isValidationError","isPluginError","isResult","isOk","isErr","OXOG_PLUGIN","OXOG_KERNEL","OXOG_VERSION"],"mappings":"AAqHA,IAAMA,CAAAA,CAAN,KAAiC,CAI/B,WAAA,CAA4BC,EAAU,CAAV,IAAA,CAAA,KAAA,CAAAA,EAAW,CAH9B,EAAA,CAAK,IAAA,CACL,MAAQ,MAAA,CAIjB,GAAA,CAAOC,EAAuC,CAC5C,OAAOC,EAAGD,CAAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAC1B,CAEA,OAAUE,CAAAA,CAAiC,CACzC,OAAO,IACT,CAEA,MAASC,CAAAA,CAAgE,CACvE,OAAOA,CAAAA,CAAS,EAAA,CAAG,IAAA,CAAK,KAAK,CAC/B,CAEA,QAAY,CACV,OAAO,KAAK,KACd,CAEA,QAAA,CAASC,CAAAA,CAAqB,CAC5B,OAAO,KAAK,KACd,CAEA,aAAaF,CAAAA,CAAiB,CAC5B,OAAO,IAAA,CAAK,KACd,CACF,CAAA,CAKMG,CAAAA,CAAN,KAAmC,CAIjC,WAAA,CAA4BC,CAAAA,CAAU,CAAV,IAAA,CAAA,KAAA,CAAAA,EAAW,CAH9B,EAAA,CAAK,KAAA,CACL,KAAA,CAAQ,MAAA,CAIjB,GAAA,CAAOJ,CA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B,GAAA,EAAQ,UAAA,EACpC,OAAQA,CAAAA,CAAoB,UAAA,EAAe,YAC3C,OAAQA,CAAAA,CAAoB,WAAc,UAAA,EAC1C,OAAQA,EAAoB,WAAA,EAAgB,UAAA,EAC5C,OAAQA,CAAAA,CAAoB,SAAA,EAAc,UAAA,EAC1C,OAAQA,CAAAA,CAAoB,IAAA,EAAS,YACrC,OAAQA,CAAAA,CAAoB,IAAO,UAAA,EACnC,OAAQA,CAAAA,CAAoB,UAAA,EAAe,UAE/C,CAeO,SAASoB,CAAAA,CAAYpB,CAAAA,CAAoC,CAC9D,OAAOA,CAAAA,YAAiBW,CAC1B,CAeO,SAASU,CAAAA,CAAkBrB,CAAAA,CAA0C,CAC1E,OAAOA,aAAiBe,CAC1B,CAeO,SAASO,CAAAA,CAActB,CAAAA,CAAsC,CAClE,OAAOA,CAAAA,YAAiBgB,CAC1B,CAoBO,SAASO,CAAAA,CAAevB,CAAAA,CAAuC,CACpE,OACEA,CAAAA,GAAU,MACV,OAAOA,CAAAA,EAAU,UACjB,OAAQA,CAAAA,CAAuB,EAAA,EAAO,SAAA,GACpC,OAAA,GAAYA,CAAAA,EAAsB,UAAYA,CAAAA,CAEpD,CAeO,SAASwB,CAAAA,CAAQxB,CAAAA,CAA2C,CACjE,OAAOuB,CAAAA,CAASvB,CAAK,CAAA,EAAKA,CAAAA,CAAM,EAAA,GAAO,IACzC,CAeO,SAASyB,EAASzB,CAAAA,CAA4C,CACnE,OAAOuB,CAAAA,CAASvB,CAAK,CAAA,EAAKA,CAAAA,CAAM,EAAA,GAAO,KACzC,CC5JO,IAAM0B,CAAAA,CAAc,MAAA,CAAO,GAAA,CAAI,cAAc,CAAA,CAiBvCC,EAAc,MAAA,CAAO,GAAA,CAAI,cAAc,CAAA,CAYvCC,CAAAA,CAAe","file":"index.js","sourcesContent":["/**\n * @oxog/types - Result type for functional error handling\n * @version 1.0.2\n * @author Ersin Koç\n */\n\n/**\n * Represents a successful result.\n *\n * Contains a value and provides methods for transforming the value\n * or handling errors. Only available on successful results.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // 42\n * }\n * ```\n */\nexport interface Ok<T> {\n readonly ok: true;\n readonly value: T;\n readonly error?: never;\n\n /** Transform the value if successful */\n map<U>(fn: (value: T) => U): Result<U, never>;\n\n /** Transform the error (no-op for Ok) */\n mapErr<F>(fn: (error: never) => F): Ok<T>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U;\n\n /** Unwrap the value (asserts success) */\n unwrap(): T;\n\n /** Unwrap with default value */\n unwrapOr(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse(fn: () => T): T;\n}\n\n/**\n * Represents a failed result.\n *\n * Contains an error and provides methods for transforming the error\n * or handling success cases. Only available on failed results.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * if (isErr(err)) {\n * console.log(err.error); // 'Something went wrong'\n * }\n * ```\n */\nexport interface Err<E> {\n readonly ok: false;\n readonly value?: never;\n readonly error: E;\n\n /** Transform the value (no-op for Err) */\n map<U>(fn: (value: never) => U): Err<E>;\n\n /** Transform the error if failed */\n mapErr<F>(fn: (error: E) => F): Result<never, F>;\n\n /** Pattern matching for both cases */\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U;\n\n /** Unwrap the value (asserts success, throws for Err) */\n unwrap(): never;\n\n /** Unwrap with default value */\n unwrapOr<T>(defaultValue: T): T;\n\n /** Unwrap using a fallback function */\n unwrapOrElse<T>(fn: () => T): T;\n}\n\n/**\n * Result type - either Ok<T> or Err<E>.\n *\n * A type that represents either success (Ok) or failure (Err).\n * This is inspired by Rust's Result type and provides functional\n * error handling without exceptions.\n *\n * @example\n * ```typescript\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) {\n * return Err('Division by zero');\n * }\n * return Ok(a / b);\n * }\n *\n * const result = divide(10, 2);\n *\n * // Pattern matching\n * const message = result.match({\n * ok: (value) => `Result: ${value}`,\n * err: (error) => `Error: ${error}`\n * });\n *\n * // Chaining\n * const doubled = result\n * .map(x => x * 2)\n * .mapErr(e => `Calculation failed: ${e}`);\n * ```\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Internal implementation of Ok result.\n */\nclass OkImpl<T> implements Ok<T> {\n readonly ok = true as const;\n readonly error = undefined as never;\n\n constructor(public readonly value: T) {}\n\n map<U>(fn: (value: T) => U): Result<U, never> {\n return Ok(fn(this.value));\n }\n\n mapErr<F>(_fn: (error: never) => F): Ok<T> {\n return this;\n }\n\n match<U>(handlers: { ok: (value: T) => U; err: (error: never) => U }): U {\n return handlers.ok(this.value);\n }\n\n unwrap(): T {\n return this.value;\n }\n\n unwrapOr(_defaultValue: T): T {\n return this.value;\n }\n\n unwrapOrElse(_fn: () => T): T {\n return this.value;\n }\n}\n\n/**\n * Internal implementation of Err result.\n */\nclass ErrImpl<E> implements Err<E> {\n readonly ok = false as const;\n readonly value = undefined as never;\n\n constructor(public readonly error: E) {}\n\n map<U>(_fn: (value: never) => U): Err<E> {\n return this;\n }\n\n mapErr<F>(fn: (error: E) => F): Result<never, F> {\n return Err(fn(this.error));\n }\n\n match<U>(handlers: { ok: (value: never) => U; err: (error: E) => U }): U {\n return handlers.err(this.error);\n }\n\n unwrap(): never {\n throw new Error(`Cannot unwrap Err: ${String(this.error)}`);\n }\n\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n unwrapOrElse<T>(fn: (error: E) => T): T {\n return fn(this.error);\n }\n}\n\n/**\n * Creates a successful Result containing a value.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * const okStr = Ok('hello');\n * const okObj = Ok({ id: 1 });\n * ```\n *\n * @param value - The value to wrap\n * @returns An Ok result containing the value\n */\nexport function Ok<T>(value: T): Ok<T> {\n return new OkImpl(value);\n}\n\n/**\n * Creates a failed Result containing an error.\n *\n * @example\n * ```typescript\n * const err = Err('Something went wrong');\n * const errNum = Err(404);\n * const errObj = Err({ code: 'NOT_FOUND' });\n * ```\n *\n * @param error - The error to wrap\n * @returns An Err result containing the error\n */\nexport function Err<E>(error: E): Err<E> {\n return new ErrImpl(error);\n}\n","/**\n * @oxog/types - Standardized error classes\n * @version 1.0.2\n * @author Ersin Koç\n */\n\n/**\n * Standard error codes for @oxog ecosystem.\n *\n * These codes provide programmatic ways to identify and handle errors.\n */\nexport enum ErrorCodes {\n /** Unknown error */\n UNKNOWN = 'UNKNOWN',\n\n /** Validation error */\n VALIDATION_ERROR = 'VALIDATION_ERROR',\n\n /** Plugin-related error */\n PLUGIN_ERROR = 'PLUGIN_ERROR',\n\n /** Resource not found */\n NOT_FOUND = 'NOT_FOUND',\n\n /** Operation timed out */\n TIMEOUT = 'TIMEOUT',\n\n /** Dependency error */\n DEPENDENCY_ERROR = 'DEPENDENCY_ERROR',\n}\n\n/**\n * Base error class for all @oxog errors.\n *\n * Provides structured error information with code, message, and context.\n * All other @oxog errors inherit from this class.\n *\n * @example\n * ```typescript\n * throw new OxogError(\n * 'Database connection failed',\n * ErrorCodes.DEPENDENCY_ERROR,\n * { host: 'localhost', port: 5432 }\n * );\n * ```\n */\nexport class OxogError extends Error {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new OxogError.\n *\n * @param message - Human-readable error message\n * @param code - Error code for programmatic handling\n * @param context - Additional context about the error\n */\n constructor(\n message: string,\n public readonly code: string,\n public readonly context?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'OxogError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when validation fails.\n *\n * Used for input validation, schema validation, and type checking errors.\n *\n * @example\n * ```typescript\n * throw new ValidationError(\n * 'Invalid email format',\n * { field: 'email', value: 'not-an-email' }\n * );\n * ```\n */\nexport class ValidationError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new ValidationError.\n *\n * @param message - Human-readable error message\n * @param context - Additional context about the validation failure\n */\n constructor(\n message: string,\n public override readonly context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.VALIDATION_ERROR, context);\n this.name = 'ValidationError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Used for plugin initialization, dependency resolution, and runtime errors\n * specific to plugins.\n *\n * @example\n * ```typescript\n * throw new PluginError(\n * 'Failed to initialize cache plugin',\n * 'cache-plugin',\n * { reason: 'Redis connection failed' }\n * );\n * ```\n */\nexport class PluginError extends OxogError {\n /** Error name */\n public override readonly name: string;\n\n /**\n * Creates a new PluginError.\n *\n * @param message - Human-readable error message\n * @param pluginName - Name of the plugin that caused the error\n * @param context - Additional context about the plugin error\n */\n constructor(\n message: string,\n public readonly pluginName: string,\n context?: Record<string, unknown>\n ) {\n super(message, ErrorCodes.PLUGIN_ERROR, { pluginName, ...context });\n this.name = 'PluginError';\n Object.setPrototypeOf(this, new.target.prototype);\n Error.captureStackTrace(this, new.target);\n }\n}\n","/**\n * @oxog/types - Type guard functions\n * @version 1.0.2\n * @author Ersin Koç\n */\n\nimport type { Plugin, Kernel } from './plugin.js';\nimport type { Result, Ok, Err } from './result.js';\nimport { OxogError, ValidationError, PluginError } from './errors.js';\n\n/**\n * Type guard for Plugin.\n *\n * Checks if a value is a valid Plugin instance.\n *\n * @example\n * ```typescript\n * const plugin = { name: 'test', version: '1.0.0', install: () => {} };\n * if (isPlugin(plugin)) {\n * console.log(plugin.name); // TypeScript knows it's a Plugin\n * }\n * ```\n */\nexport function isPlugin<T>(value: unknown): value is Plugin<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Plugin<T>).name === 'string' &&\n typeof (value as Plugin<T>).version === 'string' &&\n typeof (value as Plugin<T>).install === 'function'\n );\n}\n\n/**\n * Type guard for Kernel.\n *\n * Checks if a value is a valid Kernel instance.\n *\n * @example\n * ```typescript\n * const kernel = {\n * use: (plugin) => kernel,\n * unregister: () => true,\n * getPlugin: () => undefined,\n * listPlugins: () => [],\n * hasPlugin: () => false,\n * emit: () => {},\n * on: () => () => {},\n * getContext: () => null\n * };\n * if (isKernel(kernel)) {\n * console.log(kernel.listPlugins()); // TypeScript knows it's a Kernel\n * }\n * ```\n */\nexport function isKernel<T>(value: unknown): value is Kernel<T> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Kernel<T>).use === 'function' &&\n typeof (value as Kernel<T>).unregister === 'function' &&\n typeof (value as Kernel<T>).getPlugin === 'function' &&\n typeof (value as Kernel<T>).listPlugins === 'function' &&\n typeof (value as Kernel<T>).hasPlugin === 'function' &&\n typeof (value as Kernel<T>).emit === 'function' &&\n typeof (value as Kernel<T>).on === 'function' &&\n typeof (value as Kernel<T>).getContext === 'function'\n );\n}\n\n/**\n * Type guard for OxogError.\n *\n * Checks if a value is an OxogError instance.\n *\n * @example\n * ```typescript\n * const error = new OxogError('Test', 'TEST');\n * if (isOxogError(error)) {\n * console.log(error.code); // TypeScript knows it's an OxogError\n * }\n * ```\n */\nexport function isOxogError(value: unknown): value is OxogError {\n return value instanceof OxogError;\n}\n\n/**\n * Type guard for ValidationError.\n *\n * Checks if a value is a ValidationError instance.\n *\n * @example\n * ```typescript\n * const error = new ValidationError('Invalid', { field: 'test' });\n * if (isValidationError(error)) {\n * console.log(error.context); // TypeScript knows it's a ValidationError\n * }\n * ```\n */\nexport function isValidationError(value: unknown): value is ValidationError {\n return value instanceof ValidationError;\n}\n\n/**\n * Type guard for PluginError.\n *\n * Checks if a value is a PluginError instance.\n *\n * @example\n * ```typescript\n * const error = new PluginError('Plugin failed', 'my-plugin');\n * if (isPluginError(error)) {\n * console.log(error.pluginName); // TypeScript knows it's a PluginError\n * }\n * ```\n */\nexport function isPluginError(value: unknown): value is PluginError {\n return value instanceof PluginError;\n}\n\n/**\n * Type guard for Result.\n *\n * Checks if a value is a Result instance (either Ok or Err).\n *\n * @example\n * ```typescript\n * const result = Ok(42);\n * if (isResult(result)) {\n * // result is Ok<number, unknown>\n * }\n *\n * const err = Err('error');\n * if (isResult(err)) {\n * // err is Err<unknown, string>\n * }\n * ```\n */\nexport function isResult<T, E>(value: unknown): value is Result<T, E> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Result<T, E>).ok === 'boolean' &&\n (('value' in (value as object)) || ('error' in (value as object)))\n );\n}\n\n/**\n * Type guard for Ok result.\n *\n * Checks if a Result is an Ok (success) instance.\n *\n * @example\n * ```typescript\n * const ok = Ok(42);\n * if (isOk(ok)) {\n * console.log(ok.value); // TypeScript knows it's Ok\n * }\n * ```\n */\nexport function isOk<T>(value: Result<T, unknown>): value is Ok<T> {\n return isResult(value) && value.ok === true;\n}\n\n/**\n * Type guard for Err result.\n *\n * Checks if a Result is an Err (failure) instance.\n *\n * @example\n * ```typescript\n * const err = Err('error');\n * if (isErr(err)) {\n * console.log(err.error); // TypeScript knows it's Err\n * }\n * ```\n */\nexport function isErr<E>(value: Result<unknown, E>): value is Err<E> {\n return isResult(value) && value.ok === false;\n}\n","/**\r\n * @oxog/types - Well-known symbols and constants\r\n * @version 1.0.2\r\n * @author Ersin Koç\r\n */\r\n\r\nimport { ErrorCodes } from './errors.js';\r\n\r\n/**\r\n * Well-known symbol for @oxog plugins.\r\n *\r\n * Use this symbol to mark objects as @oxog plugins.\r\n * This enables runtime detection and validation.\r\n *\r\n * @example\r\n * ```typescript\r\n * const myPlugin = {\r\n * [OXOG_PLUGIN]: true,\r\n * name: 'my-plugin',\r\n * version: '1.0.0',\r\n * install: () => {}\r\n * };\r\n * ```\r\n */\r\nexport const OXOG_PLUGIN = Symbol.for('@oxog/plugin');\r\n\r\n/**\r\n * Well-known symbol for @oxog kernels.\r\n *\r\n * Use this symbol to mark objects as @oxog kernels.\r\n * This enables runtime detection and validation.\r\n *\r\n * @example\r\n * ```typescript\r\n * const myKernel = {\r\n * [OXOG_KERNEL]: true,\r\n * use: (plugin) => kernel,\r\n * // ... other methods\r\n * };\r\n * ```\r\n */\r\nexport const OXOG_KERNEL = Symbol.for('@oxog/kernel');\r\n\r\n/**\r\n * @oxog/types package version.\r\n *\r\n * Current version of the @oxog/types package.\r\n *\r\n * @example\r\n * ```typescript\r\n * console.log(`Using @oxog/types v${OXOG_VERSION}`);\r\n * ```\r\n */\r\nexport const OXOG_VERSION = '1.0.2';\r\n\r\n/**\r\n * Standard error codes for @oxog ecosystem.\r\n *\r\n * Re-exported from errors module for convenience.\r\n *\r\n * @example\r\n * ```typescript\r\n * throw new OxogError('Not found', ErrorCodes.NOT_FOUND);\r\n * ```\r\n */\r\nexport { ErrorCodes };\r\n"]}
@@ -1 +1 @@
1
- {"inputs":{"src/plugin.ts":{"bytes":4156,"imports":[],"format":"esm"},"src/result.ts":{"bytes":4793,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":3454,"imports":[],"format":"esm"},"src/guards.ts":{"bytes":4507,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/events.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":6788,"imports":[],"format":"esm"},"src/constants.ts":{"bytes":1323,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/index.ts":{"bytes":981,"imports":[{"path":"src/plugin.ts","kind":"import-statement","original":"./plugin.js"},{"path":"src/result.ts","kind":"import-statement","original":"./result.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"src/guards.ts","kind":"import-statement","original":"./guards.js"},{"path":"src/events.ts","kind":"import-statement","original":"./events.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17704},"dist/index.cjs":{"imports":[],"exports":["Err","ErrorCodes","OXOG_KERNEL","OXOG_PLUGIN","OXOG_VERSION","Ok","OxogError","PluginError","ValidationError","isErr","isKernel","isOk","isOxogError","isPlugin","isPluginError","isResult","isValidationError"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/result.ts":{"bytesInOutput":569},"src/errors.ts":{"bytesInOutput":819},"src/guards.ts":{"bytesInOutput":709},"src/constants.ts":{"bytesInOutput":72}},"bytes":2438}}}
1
+ {"inputs":{"src/plugin.ts":{"bytes":4156,"imports":[],"format":"esm"},"src/result.ts":{"bytes":4793,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":3432,"imports":[],"format":"esm"},"src/guards.ts":{"bytes":4507,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/events.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":10153,"imports":[],"format":"esm"},"src/constants.ts":{"bytes":1389,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/index.ts":{"bytes":981,"imports":[{"path":"src/plugin.ts","kind":"import-statement","original":"./plugin.js"},{"path":"src/result.ts","kind":"import-statement","original":"./result.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"src/guards.ts","kind":"import-statement","original":"./guards.js"},{"path":"src/events.ts","kind":"import-statement","original":"./events.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17803},"dist/index.cjs":{"imports":[],"exports":["Err","ErrorCodes","OXOG_KERNEL","OXOG_PLUGIN","OXOG_VERSION","Ok","OxogError","PluginError","ValidationError","isErr","isKernel","isOk","isOxogError","isPlugin","isPluginError","isResult","isValidationError"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/result.ts":{"bytesInOutput":569},"src/errors.ts":{"bytesInOutput":810},"src/guards.ts":{"bytesInOutput":709},"src/constants.ts":{"bytesInOutput":72}},"bytes":2429}}}
@@ -1 +1 @@
1
- {"inputs":{"src/plugin.ts":{"bytes":4156,"imports":[],"format":"esm"},"src/result.ts":{"bytes":4793,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":3454,"imports":[],"format":"esm"},"src/guards.ts":{"bytes":4507,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/events.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":6788,"imports":[],"format":"esm"},"src/constants.ts":{"bytes":1323,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/index.ts":{"bytes":981,"imports":[{"path":"src/plugin.ts","kind":"import-statement","original":"./plugin.js"},{"path":"src/result.ts","kind":"import-statement","original":"./result.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"src/guards.ts","kind":"import-statement","original":"./guards.js"},{"path":"src/events.ts","kind":"import-statement","original":"./events.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":17704},"dist/index.js":{"imports":[],"exports":["Err","ErrorCodes","OXOG_KERNEL","OXOG_PLUGIN","OXOG_VERSION","Ok","OxogError","PluginError","ValidationError","isErr","isKernel","isOk","isOxogError","isPlugin","isPluginError","isResult","isValidationError"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/result.ts":{"bytesInOutput":569},"src/errors.ts":{"bytesInOutput":819},"src/guards.ts":{"bytesInOutput":709},"src/constants.ts":{"bytesInOutput":72}},"bytes":2438}}}
1
+ {"inputs":{"src/plugin.ts":{"bytes":4156,"imports":[],"format":"esm"},"src/result.ts":{"bytes":4793,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":3432,"imports":[],"format":"esm"},"src/guards.ts":{"bytes":4507,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/events.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":10153,"imports":[],"format":"esm"},"src/constants.ts":{"bytes":1389,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"}],"format":"esm"},"src/index.ts":{"bytes":981,"imports":[{"path":"src/plugin.ts","kind":"import-statement","original":"./plugin.js"},{"path":"src/result.ts","kind":"import-statement","original":"./result.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"src/guards.ts","kind":"import-statement","original":"./guards.js"},{"path":"src/events.ts","kind":"import-statement","original":"./events.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":17803},"dist/index.js":{"imports":[],"exports":["Err","ErrorCodes","OXOG_KERNEL","OXOG_PLUGIN","OXOG_VERSION","Ok","OxogError","PluginError","ValidationError","isErr","isKernel","isOk","isOxogError","isPlugin","isPluginError","isResult","isValidationError"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/result.ts":{"bytesInOutput":569},"src/errors.ts":{"bytesInOutput":810},"src/guards.ts":{"bytesInOutput":709},"src/constants.ts":{"bytesInOutput":72}},"bytes":2429}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxog/types",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Shared TypeScript types, interfaces, and utilities for the @oxog ecosystem",
5
5
  "author": "Ersin Koç",
6
6
  "license": "MIT",
@@ -13,6 +13,41 @@
13
13
  "types": "./dist/index.d.ts",
14
14
  "import": "./dist/index.js",
15
15
  "require": "./dist/index.cjs"
16
+ },
17
+ "./plugin": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./result": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.cjs"
26
+ },
27
+ "./errors": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs"
31
+ },
32
+ "./guards": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.cjs"
36
+ },
37
+ "./events": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "require": "./dist/index.cjs"
41
+ },
42
+ "./utils": {
43
+ "types": "./dist/index.d.ts",
44
+ "import": "./dist/index.js",
45
+ "require": "./dist/index.cjs"
46
+ },
47
+ "./constants": {
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/index.js",
50
+ "require": "./dist/index.cjs"
16
51
  }
17
52
  },
18
53
  "files": [
@@ -62,4 +97,5 @@
62
97
  "bugs": {
63
98
  "url": "https://github.com/ersinkoc/types/issues"
64
99
  },
65
- "homepage": "https://types.oxog.dev"}
100
+ "homepage": "https://types.oxog.dev"
101
+ }