@inixiative/json-rules 3.12.2 → 3.14.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/README.md CHANGED
@@ -460,6 +460,7 @@ format grows a node type, and it goes blind silently.
460
460
  | `listBindings(rule, { required: true })` | Names a bindings map must cover — every `{ bind }` token not marked `bindOptional`, sorted. A name optional at one leaf and required at another is required. |
461
461
  | `listBindings(rule)` | Every `{ bind }` name in the tree, optional or not, sorted — what a lens declares. |
462
462
  | `bindRule(rule, bindings)` | Substitutes covered binds with their values, leaving uncovered tokens in place (partial resolution). |
463
+ | `clockUnit(rule)` | The finest clock unit the rule's answer can change by while its data stays the same: the smallest unit any relative date in the tree names (`{ ago: { hours: 2 } }` → `hour`, `{ this: 'week' }` → `week`, `isoWeek` → `week`), one of `CLOCK_UNITS` (`second` … `year`); throws on a unit finer than the engine's `clock.finestUnit`, as evaluating the rule does. `null` when it reads no clock: absolute dates, column compares and their offsets, weekday lists. A caller re-evaluates a stored rule on that tick instead of guessing from its JSON. |
463
464
 
464
465
  A leaf may mark its bind optional: `{ field, operator, bind: 'region', bindOptional: true }`. An
465
466
  unsupplied required bind is a caller bug — `check()` throws, and both compilers refuse a
@@ -653,6 +654,7 @@ null`.
653
654
  | `string.fuzzy` | `false` | Default for a rule's `fuzzy` (`true` or a `FuzzyConfig` `{ maxDistance?, maxRatio? }`): typo-tolerant `contains` / `notContains` on strings. A rule's own flag wins. The compilers have no fuzzy form: they refuse `contains` / `notContains` whenever fuzzy is on, by the rule or by this default. |
654
655
  | `prismaOptions.datasource.provider` | `'postgresql'` | The Prisma connector. `toPrisma()` emits `mode: 'insensitive'` only for `postgresql`, `cockroachdb` and `mongodb`; the others are case-insensitive by collation and reject it. `toPrisma(rule, { datasource: { provider } })` overrides it per call. |
655
656
  | `prismaOptions.anyNull` | your `@prisma/client`'s | Prisma's `AnyNull` for Json null checks (see above); set it only to use another client's. |
657
+ | `clock.finestUnit` | `'second'` | The finest clock unit a rule may read (one of `CLOCK_UNITS`). A rule reading a finer one fails to evaluate: `check`, `toPrisma` and `toSql` throw and `validateRule` reports `clock_unit_below_floor`. Under `'hour'`, `{ ago: { minutes: 30 } }` and `{ this: 'minute' }` fail; offsets on a column compare read no clock and are unaffected. A caller whose finest tick is an hour sets it once at boot. |
656
658
 
657
659
  ```ts
658
660
  import { engineGlobals } from '@inixiative/json-rules';
@@ -661,6 +663,7 @@ engineGlobals.set('string.caseInsensitive', true);
661
663
  engineGlobals.get('string.caseInsensitive'); // true
662
664
  engineGlobals.set('prismaOptions.datasource.provider', 'mysql');
663
665
  engineGlobals.set('sql.dialect', SqlDialect.mysql); // what toWhereSql / toLensWhereSql write
666
+ engineGlobals.set('clock.finestUnit', 'hour'); // a rule reading minutes or seconds fails to evaluate
664
667
  engineGlobals.reset(); // back to the defaults
665
668
 
666
669
  // A scoped override: merged over the current state for the duration of a synchronous callback.