Tsentials meta

From senrecep/tsentials · View interactive version

Tsentials meta is an AI agent skill from the GitHub repository senrecep/tsentials. Use when deciding which tsentials module to use — overview of all 24 subpath imports organized by concern, install command, and a quick-reference table mapping problems to modules.

How to use this skill

Skill file

tsentials — Module Index

tsentials is a modular TypeScript library for railway-oriented programming. Each module is a separate subpath import — import only what you need, everything is tree-shakeable.

Installation

npm install tsentials

Requirements: Node.js ≥ 22, TypeScript ≥ 5.0

All Modules

Functional Core

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/result | Result<T>, ResultChain, ResultAsync<T>, fromAsync | tsentials-result |

| tsentials/errors | AppError, ErrorType, Err factory | tsentials-errors |

| tsentials/maybe | Maybe<T>, tryFirst, tryFind, choose | tsentials-maybe |

| tsentials/union | Union<T> discriminated union utility | tsentials-union |

| tsentials/function | pipe, flow, identity, constant, flip | tsentials-function |

| tsentials/string | toPascalCase, toCamelCase, toKebabCase, toSnakeCase, toMacroCase, toTrainCase, toTitleCase, toUnderscoreCamelCase | tsentials-string |

| tsentials/uuid | uuidv7, monotonicUuidv7 | tsentials-uuid |

Data Structures & Types

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/array | NonEmptyArray<T>, head, last, asNonEmptyArray | tsentials-array |

| tsentials/these | These<E, A> partial success type | tsentials-these |

| tsentials/tree | Tree<T> recursive hierarchy | tsentials-tree |

| tsentials/record | Record object utilities | tsentials-record |

Type Classes

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/eq | Eq<T> equality type class | tsentials-eq |

| tsentials/ord | Ord<T> ordering type class | tsentials-ord |

| tsentials/predicate | Predicate<T> composable booleans | tsentials-predicate |

Business Rules

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/rules | Rule<T>, RuleEngine | tsentials-rules |

Domain Model (DDD)

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/entity | createEntityBase, createSoftDeletable, DomainEvent, DomainEventTiming, EntityBase, EntityBaseWithId<TId>, CreationAudit, ModificationAudit, FullAudit, SoftDeletable | tsentials-entity |

Validation, Resilience & Application Services (subpath-only)

These modules are not re-exported from the root tsentials entry — import them from their subpath.

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/validation | Validator<T>, RuleContext, RuleChain, CascadeMode | tsentials-validation |

| tsentials/resilience | ResiliencePolicy, retryIfFailed, isRetryable, ResilienceErrorCode | tsentials-resilience |

| tsentials/pagination | paginate, keysetOrdering, keysetPaginate, planKeysetPage, cursor helpers | tsentials-pagination |

| tsentials/enums | defineEnum, EnumMember | tsentials-enums |

| tsentials/mediator | createMediator, pipeline, behaviors, InProcessResourceLock | tsentials-mediator |

| tsentials/idempotency | idempotent, idempotencyBehavior, withIdempotency, createIdempotency, stores, keys, scopes | tsentials-idempotency |

Web / Infrastructure

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/http | fetchResult, RequestBuilder, httpStatusToError, extractErrorDescription | tsentials-http |

Utilities

| Import | Contents | Skill |

|--------|----------|-------|

| tsentials/time | DateTimeProvider, SystemDateTimeProvider, createFakeDateTimeProvider, nextDayOfWeek, previousDayOfWeek, DayOfWeek, getAge, toDateOnly, toTimeOnly, msToDate | tsentials-time |

| tsentials/clone | Cloneable<T>, deepClone, cloneArray | tsentials-clone |

| tsentials/json | Json, JsonObject, JsonArray, JsonPrimitive, safeJsonParse, safeJsonStringify, parseAndValidate, type guards | tsentials-json |


Problem → Module Quick Reference

| Problem | Module |

|---------|--------|

| Return errors without throwing exceptions | tsentials/result + tsentials/errors |

| Chain async operations without try/catch | tsentials/result (fromAsync) |

| Represent optional / nullable values safely | tsentials/maybe |

| Return one of several distinct typed outcomes | tsentials/union |

| Compose business validation rules | tsentials/rules |

| DDD aggregate base class + domain events | tsentials/entity |

| Soft-deletable domain entities | tsentials/entity (createSoftDeletable) |

| HTTP calls that return Result<T> | tsentials/http |

| Testable time / freeze clock in tests | tsentials/time |

| Deep-copy domain objects | tsentials/clone |

| Parse JSON without try/catch | tsentials/json (safeJsonParse) |

| Parse JSON and validate against a type | tsentials/json (parseAndValidate) |

| Build left-to-right function pipelines | tsentials/function (pipe, flow) |

| Guarantee an array has at least one element | tsentials/array (NonEmptyArray) |

| Model partial success (value + warnings) | tsentials/these |

| Model recursive hierarchies | tsentials/tree |

| Validate a model with fluent Result-based rules | tsentials/validation |

| Retry, circuit breaker, timeout, fallback around a Result operation | tsentials/resilience |

| Offset paging of a list | tsentials/pagination (paginate) |

| Stable cursor (keyset) paging | tsentials/pagination (keysetPaginate) |

| Enum with wire names, aliases and safe parsing | tsentials/enums (defineEnum) |

| Typed request/response dispatch with pipeline behaviors | tsentials/mediator |

| Run an operation once per idempotency key | tsentials/idempotency |

| Next/previous weekday, age, date-only / time-only | tsentials/time |

| Functional object manipulation | tsentials/record |

| Composable equality checks | tsentials/eq |

| Type-safe sorting and ordering | tsentials/ord |

| Composable boolean predicates | tsentials/predicate |

| Convert between naming conventions (camelCase, kebab-case, snake_case, ...) | tsentials/string |

| Time-ordered UUIDv7 ids | tsentials/uuid |


Import Reference

import { Result, ResultChain, ResultAsync, fromAsync } from 'tsentials/result';
import { Err, AppError, ErrorType }                    from 'tsentials/errors';
import { Maybe, tryFirst, tryFind, choose }            from 'tsentials/maybe';
import { Union }                                        from 'tsentials/union';
import { pipe, flow }                                   from 'tsentials/function';
import { Eq }                                           from 'tsentials/eq';
import { Ord, sortBy }                                  from 'tsentials/ord';
import { Predicate }                                    from 'tsentials/predicate';
import { NonEmptyArray, asNonEmptyArray }               from 'tsentials/array';
import { These }                                        from 'tsentials/these';
import { Tree }                                         from 'tsentials/tree';
import { Record }                                       from 'tsentials/record';
import { RuleEngine }                                   from 'tsentials/rules';
import type { Rule }                                    from 'tsentials/rules';
import { createEntityBase, createSoftDeletable }       from 'tsentials/entity';
import type { DomainEvent, DomainEventTiming }          from 'tsentials/entity';
import type { EntityBase, EntityBaseWithId }             from 'tsentials/entity';
import type { CreationAudit, ModificationAudit, FullAudit, SoftDeletable } from 'tsentials/entity';
import { fetchResult, RequestBuilder, httpStatusToError, extractErrorDescription } from 'tsentials/http';
import { SystemDateTimeProvider, createFakeDateTimeProvider } from 'tsentials/time';
import { nextDayOfWeek, previousDayOfWeek, DayOfWeek, getAge, toDateOnly, toTimeOnly, msToDate } from 'tsentials/time';
import type { DateTimeProvider }                        from 'tsentials/time';
import { deepClone, cloneArray }                        from 'tsentials/clone';
import type { Cloneable }                               from 'tsentials/clone';
import { safeJsonParse, safeJsonStringify, parseAndValidate } from 'tsentials/json';
import { isJson, isJsonObject }                         from 'tsentials/json';
import type { Json, JsonObject }                        from 'tsentials/json';
import { toPascalCase, toCamelCase, toKebabCase, toSnakeCase, toMacroCase, toTrainCase, toTitleCase, toUnderscoreCamelCase } from 'tsentials/string';
import { uuidv7, monotonicUuidv7 }                     from 'tsentials/uuid';
import { Validator, CascadeMode }                      from 'tsentials/validation';
import { ResiliencePolicy, retryIfFailed }             from 'tsentials/resilience';
import { paginate, keysetOrdering, keysetPaginate }    from 'tsentials/pagination';
import { defineEnum }                                   from 'tsentials/enums';
import type { EnumMember }                              from 'tsentials/enums';
import { createMediator, exceptionHandlingBehavior, validationBehavior } from 'tsentials/mediator';
import { createIdempotency, idempotent, withIdempotency, idempotencyKeys, idempotencyScopes } from 'tsentials/idempotency';

Key Design Decisions

| Decision | Detail |

|----------|--------|

| Result<T> shape | { ok: true; value: T } \| { ok: false; errors: AppError[] } — discriminated union, no class |

| ResultAsync<T> | Implements PromiseLike<Result<T>> — direct await; monadic bind is andThen() not then() |

| ResultChain<T> | Fluent sync wrapper; monadic bind is bind() not then() |

| Maybe<T> | Pure functional namespace — all operations are static functions |

| Rule<T> | Just (ctx: T) => VoidResult — no interface hierarchy |

| Entity base | Mixin factory pattern (createEntityBase()) — not abstract class inheritance |

| sideEffects: false | All subpath imports are fully tree-shakeable |

| ESM only | "type": "module", moduleResolution: "bundler" |


Common Pitfalls

| Wrong | Correct | Why |

|-------|---------|-----|

| resultAsync.then(fn) | resultAsync.andThen(fn) | .then() is the PromiseLike protocol |

| chain.then(fn) | chain.bind(fn) | Same reason — breaks await |

| import { Validator } from 'tsentials' | import { Validator } from 'tsentials/validation' | validation, resilience, pagination, enums, mediator, idempotency are subpath-only |

| import { Err } from 'tsentials/result' | import { Err } from 'tsentials/errors' | Err lives in the errors module |

| error.message | error.description | Property is named description |

| throw new Error(...) | Result.failure(Err.unexpected(...)) | Errors are values, not exceptions |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.