@inixiative/json-rules 2.15.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -45,6 +45,13 @@ declare const DateOperator: {
45
45
  };
46
46
  type DateOperator = (typeof DateOperator)[keyof typeof DateOperator];
47
47
 
48
+ type FuzzyConfig = {
49
+ maxDistance?: number;
50
+ maxRatio?: number;
51
+ };
52
+ declare const maxFuzzyDistance: (length: number) => number;
53
+ declare const fuzzyContains: (haystack: string, query: string, config?: FuzzyConfig) => boolean;
54
+
48
55
  declare const FieldKind: {
49
56
  readonly String: "String";
50
57
  readonly Boolean: "Boolean";
@@ -206,6 +213,7 @@ type RuleBase<TOperator extends Operator> = {
206
213
  operator: TOperator;
207
214
  error?: string;
208
215
  caseInsensitive?: boolean;
216
+ fuzzy?: boolean | FuzzyConfig;
209
217
  };
210
218
  type DateRuleBase<TOperator extends DateOperator> = {
211
219
  field: string;
@@ -312,6 +320,7 @@ type Rule<TValue = RuleValue> = {
312
320
  bind?: string;
313
321
  error?: string;
314
322
  caseInsensitive?: boolean;
323
+ fuzzy?: boolean | FuzzyConfig;
315
324
  coerceType?: FieldKind;
316
325
  };
317
326
  type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
@@ -383,18 +392,28 @@ declare const check: <TData extends CheckData>(conditions: Condition, data: TDat
383
392
 
384
393
  type PrismaProvider = 'postgresql' | 'mysql' | 'sqlite' | 'sqlserver' | 'cockroachdb' | 'mongodb';
385
394
  type EngineGlobalsState = {
395
+ string: {
396
+ caseInsensitive: boolean;
397
+ fuzzy: boolean | FuzzyConfig;
398
+ };
386
399
  prismaOptions: {
387
400
  datasource: {
388
401
  provider: PrismaProvider;
389
402
  };
390
403
  };
391
404
  };
405
+ type DeepPartial<T> = {
406
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
407
+ };
392
408
  declare const engineGlobals: {
393
409
  set: (path: string, value: unknown) => void;
394
410
  get: (path: string) => unknown;
395
411
  reset: () => void;
412
+ with: <T>(partial: DeepPartial<EngineGlobalsState>, fn: () => T) => T;
396
413
  };
397
414
  declare const supportsQueryMode: (provider: PrismaProvider) => boolean;
415
+ declare const resolveCaseInsensitive: (ruleFlag?: boolean) => boolean;
416
+ declare const resolveFuzzy: (ruleFlag?: boolean | FuzzyConfig) => FuzzyConfig | false;
398
417
 
399
418
  type PrismaWhere = Record<string, unknown>;
400
419
  /** A selectable option — the standard `<select>` shape: a value with an optional display label. */
@@ -810,4 +829,4 @@ declare const assertValidRule: (condition: unknown, options?: {
810
829
  target?: RuleTarget;
811
830
  }) => asserts condition is Condition;
812
831
 
813
- export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EdgeExpr, type EngineGlobalsState, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NULLABLE_KINDS, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaProvider, type PrismaStep, type PrismaWhere, type ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceSpec, type SourceSqlQuery, type SourceValue, type SourceValues, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type TimeZoneConfig, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, engineGlobals, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, lensRequiredBindings, projectByPath, requiredBindings, resolveBindings, resolveLensBindings, sourceQueries, sourceValuesFromRows, stampCoercions, stitchFieldMaps, supportsQueryMode, toPrisma, toSql, validateBindNames, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
832
+ export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EdgeExpr, type EngineGlobalsState, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type FuzzyConfig, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NULLABLE_KINDS, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaProvider, type PrismaStep, type PrismaWhere, type ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceSpec, type SourceSqlQuery, type SourceValue, type SourceValues, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type TimeZoneConfig, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, engineGlobals, executePrismaQueryPlan, exposedSurface, fuzzyContains, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, lensRequiredBindings, maxFuzzyDistance, projectByPath, requiredBindings, resolveBindings, resolveCaseInsensitive, resolveFuzzy, resolveLensBindings, sourceQueries, sourceValuesFromRows, stampCoercions, stitchFieldMaps, supportsQueryMode, toPrisma, toSql, validateBindNames, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
package/dist/index.d.ts CHANGED
@@ -45,6 +45,13 @@ declare const DateOperator: {
45
45
  };
46
46
  type DateOperator = (typeof DateOperator)[keyof typeof DateOperator];
47
47
 
48
+ type FuzzyConfig = {
49
+ maxDistance?: number;
50
+ maxRatio?: number;
51
+ };
52
+ declare const maxFuzzyDistance: (length: number) => number;
53
+ declare const fuzzyContains: (haystack: string, query: string, config?: FuzzyConfig) => boolean;
54
+
48
55
  declare const FieldKind: {
49
56
  readonly String: "String";
50
57
  readonly Boolean: "Boolean";
@@ -206,6 +213,7 @@ type RuleBase<TOperator extends Operator> = {
206
213
  operator: TOperator;
207
214
  error?: string;
208
215
  caseInsensitive?: boolean;
216
+ fuzzy?: boolean | FuzzyConfig;
209
217
  };
210
218
  type DateRuleBase<TOperator extends DateOperator> = {
211
219
  field: string;
@@ -312,6 +320,7 @@ type Rule<TValue = RuleValue> = {
312
320
  bind?: string;
313
321
  error?: string;
314
322
  caseInsensitive?: boolean;
323
+ fuzzy?: boolean | FuzzyConfig;
315
324
  coerceType?: FieldKind;
316
325
  };
317
326
  type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = WindowFields & {
@@ -383,18 +392,28 @@ declare const check: <TData extends CheckData>(conditions: Condition, data: TDat
383
392
 
384
393
  type PrismaProvider = 'postgresql' | 'mysql' | 'sqlite' | 'sqlserver' | 'cockroachdb' | 'mongodb';
385
394
  type EngineGlobalsState = {
395
+ string: {
396
+ caseInsensitive: boolean;
397
+ fuzzy: boolean | FuzzyConfig;
398
+ };
386
399
  prismaOptions: {
387
400
  datasource: {
388
401
  provider: PrismaProvider;
389
402
  };
390
403
  };
391
404
  };
405
+ type DeepPartial<T> = {
406
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
407
+ };
392
408
  declare const engineGlobals: {
393
409
  set: (path: string, value: unknown) => void;
394
410
  get: (path: string) => unknown;
395
411
  reset: () => void;
412
+ with: <T>(partial: DeepPartial<EngineGlobalsState>, fn: () => T) => T;
396
413
  };
397
414
  declare const supportsQueryMode: (provider: PrismaProvider) => boolean;
415
+ declare const resolveCaseInsensitive: (ruleFlag?: boolean) => boolean;
416
+ declare const resolveFuzzy: (ruleFlag?: boolean | FuzzyConfig) => FuzzyConfig | false;
398
417
 
399
418
  type PrismaWhere = Record<string, unknown>;
400
419
  /** A selectable option — the standard `<select>` shape: a value with an optional display label. */
@@ -810,4 +829,4 @@ declare const assertValidRule: (condition: unknown, options?: {
810
829
  target?: RuleTarget;
811
830
  }) => asserts condition is Condition;
812
831
 
813
- export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EdgeExpr, type EngineGlobalsState, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NULLABLE_KINDS, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaProvider, type PrismaStep, type PrismaWhere, type ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceSpec, type SourceSqlQuery, type SourceValue, type SourceValues, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type TimeZoneConfig, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, engineGlobals, executePrismaQueryPlan, exposedSurface, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, lensRequiredBindings, projectByPath, requiredBindings, resolveBindings, resolveLensBindings, sourceQueries, sourceValuesFromRows, stampCoercions, stitchFieldMaps, supportsQueryMode, toPrisma, toSql, validateBindNames, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
832
+ export { AGGREGATE_OPERATORS, ALL_KINDS, ARRAY_OPERATOR_CATALOG, type AggregateMode, type AggregateRule, type All, type Any, type ArrayCatalogEntry, ArrayOperator, type ArrayRule, type Bridge, type BridgeCardinality, type BridgeDictionary, type BridgeEndpoint, type BuildOptions, type CatalogEntry, type CheckOptions, type Condition, type CreateLensInput, DATE_OPERATOR_CATALOG, type DateConfig, type DateExpr, type DateInputOrExpr, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EdgeExpr, type EngineGlobalsState, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type FuzzyConfig, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NULLABLE_KINDS, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderBy, type OrderedRuleValue, type PathProjection, type PeriodExpr, type PeriodUnit, type PrismaProvider, type PrismaStep, type PrismaWhere, type ProjectOptions, type ProjectedVisit, type RelativeUnits, type RollingExpr, type Rule, type RuleDescription, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, type SortDir, type SourceOption, type SourcePrismaQuery, type SourceQuery, type SourceSpec, type SourceSqlQuery, type SourceValue, type SourceValues, type SqlResult, type StepRef, type StrictAggregateRule, type StrictAll, type StrictAny, type StrictArrayCountRule, type StrictArrayPredicateRule, type StrictArrayPresenceRule, type StrictArrayRule, type StrictCondition, type StrictContainsRule, type StrictDateComparisonRule, type StrictDateDayRule, type StrictDateRangeRule, type StrictDateRule, type StrictEqualityRule, type StrictIfThenElse, type StrictMembershipRule, type StrictOrderedComparisonRule, type StrictPatternRule, type StrictPresenceRule, type StrictRangeRule, type StrictRule, type StrictStringBoundaryRule, type TimeZoneConfig, type ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, WINDOW_SELECTOR, type WeekStart, type WhereStep, type WindowFields, type WindowRuleType, WindowSupport, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, describeRule, engineGlobals, executePrismaQueryPlan, exposedSurface, fuzzyContains, getArrayOperators, getOperatorsForKind, getValueShape, getWindowSupport, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, lensRequiredBindings, maxFuzzyDistance, projectByPath, requiredBindings, resolveBindings, resolveCaseInsensitive, resolveFuzzy, resolveLensBindings, sourceQueries, sourceValuesFromRows, stampCoercions, stitchFieldMaps, supportsQueryMode, toPrisma, toSql, validateBindNames, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };