@inixiative/json-rules 2.0.3 → 2.1.1

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
@@ -223,15 +223,27 @@ type FieldMapEntry = {
223
223
  fromFields?: string[];
224
224
  toFields?: string[];
225
225
  relationName?: string;
226
+ /**
227
+ * Per-field allowed values, primarily for enum fields. Takes precedence over
228
+ * `FieldMap.enums[type]` if both are set. Pass-through from codegen
229
+ * (e.g. prisma-map's `EnumField.values`). Consumed by `checkRuleAgainstLens`.
230
+ */
231
+ values?: readonly string[];
232
+ };
233
+ type ModelEntry = {
234
+ dbName?: string | null;
235
+ fields: Record<string, FieldMapEntry>;
236
+ };
237
+ /**
238
+ * A schema map: models keyed by name, plus an optional enum registry scoped to
239
+ * this source. In multi-source setups (Prisma + Salesforce + CRM) each FieldMap
240
+ * carries its own enums so namespaces don't collide across sources.
241
+ */
242
+ type FieldMap = {
243
+ models: Record<string, ModelEntry>;
244
+ /** Enum name → allowed values, e.g. `{ UserRole: ['ADMIN', 'USER'] }`. */
245
+ enums?: Record<string, readonly string[]>;
226
246
  };
227
- interface FieldMap {
228
- [modelName: string]: {
229
- dbName?: string | null;
230
- fields: {
231
- [fieldName: string]: FieldMapEntry;
232
- };
233
- };
234
- }
235
247
  type StepRef = {
236
248
  __step: number;
237
249
  };
@@ -305,21 +317,56 @@ type Lens = FieldMapSet & {
305
317
  mapName: string;
306
318
  model: string;
307
319
  };
308
- type ModelNarrowing = {
320
+ /**
321
+ * Narrowing applied wherever a model appears (intrinsic to the model).
322
+ * Has no `relations` because relations are path-specific by definition.
323
+ *
324
+ * Two kinds of narrowing live here:
325
+ * - SCHEMA narrowing (picks/omits/enumPicks/enumOmits): controls what's visible
326
+ * in the type surface. AI/SDK consumers can't see narrowed-away fields.
327
+ * - DATA narrowing (where): controls which ROWS are in scope. Filter-first
328
+ * semantic, anchored to the model. Under arrayOperator: 'all', applied via
329
+ * implication (negate) to preserve filter-first meaning — see applyLens.
330
+ */
331
+ type ModelDefaultNarrowing = {
309
332
  picks?: string[];
310
333
  omits?: string[];
334
+ enumPicks?: Record<string, readonly string[]>;
335
+ enumOmits?: Record<string, readonly string[]>;
336
+ /**
337
+ * Row-level filter anchored to this model — "from what you can see, this is true."
338
+ * Composes via filter-first semantic at every visit of this model.
339
+ */
340
+ where?: Condition;
341
+ };
342
+ /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
343
+ type ModelNarrowing = ModelDefaultNarrowing & {
311
344
  relations?: Record<string, ModelNarrowing>;
312
345
  };
346
+ /** Narrowing for an enum type (applies anywhere the enum is referenced). */
347
+ type EnumNarrowing = {
348
+ picks?: readonly string[];
349
+ omits?: readonly string[];
350
+ };
351
+ /** Applies-everywhere narrowings — per-model (no relations) + per-enum-type. */
352
+ type NarrowingDefaults = {
353
+ models?: Record<string, ModelDefaultNarrowing>;
354
+ enums?: Record<string, EnumNarrowing>;
355
+ };
313
356
  type MapNarrowing = {
357
+ /** Path-specific narrowings, root + relations tree. */
314
358
  models: Record<string, ModelNarrowing>;
359
+ /** Applies-everywhere narrowings, intersect with path-specific. */
360
+ defaults?: NarrowingDefaults;
315
361
  };
316
362
  type LensNarrowing = {
317
363
  parent: Lens | LensNarrowing;
318
364
  maps: Record<string, MapNarrowing>;
319
- constrains?: Condition;
365
+ /** Lens-level row filter, anchored to the root model. ANDs into the root rule. */
366
+ where?: Condition;
320
367
  };
321
368
 
322
- declare const applyLens: (rule: Condition, narrowing: Lens | LensNarrowing) => Condition;
369
+ declare const applyLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
323
370
 
324
371
  type RuleLensViolation = {
325
372
  path: string;
@@ -490,4 +537,4 @@ declare const assertValidRule: (condition: unknown, options?: {
490
537
  target?: RuleTarget;
491
538
  }) => asserts condition is Condition;
492
539
 
493
- 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 DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type MapNarrowing, type ModelNarrowing, NUMERIC_KINDS, ORDERABLE_KINDS, Operator, type OrderedRuleValue, type PrismaStep, type PrismaWhere, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, 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 ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WhereStep, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectNarrowing, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
540
+ 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 DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type MapNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderedRuleValue, type PrismaStep, type PrismaWhere, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, 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 ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WhereStep, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectNarrowing, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
package/dist/index.d.ts CHANGED
@@ -223,15 +223,27 @@ type FieldMapEntry = {
223
223
  fromFields?: string[];
224
224
  toFields?: string[];
225
225
  relationName?: string;
226
+ /**
227
+ * Per-field allowed values, primarily for enum fields. Takes precedence over
228
+ * `FieldMap.enums[type]` if both are set. Pass-through from codegen
229
+ * (e.g. prisma-map's `EnumField.values`). Consumed by `checkRuleAgainstLens`.
230
+ */
231
+ values?: readonly string[];
232
+ };
233
+ type ModelEntry = {
234
+ dbName?: string | null;
235
+ fields: Record<string, FieldMapEntry>;
236
+ };
237
+ /**
238
+ * A schema map: models keyed by name, plus an optional enum registry scoped to
239
+ * this source. In multi-source setups (Prisma + Salesforce + CRM) each FieldMap
240
+ * carries its own enums so namespaces don't collide across sources.
241
+ */
242
+ type FieldMap = {
243
+ models: Record<string, ModelEntry>;
244
+ /** Enum name → allowed values, e.g. `{ UserRole: ['ADMIN', 'USER'] }`. */
245
+ enums?: Record<string, readonly string[]>;
226
246
  };
227
- interface FieldMap {
228
- [modelName: string]: {
229
- dbName?: string | null;
230
- fields: {
231
- [fieldName: string]: FieldMapEntry;
232
- };
233
- };
234
- }
235
247
  type StepRef = {
236
248
  __step: number;
237
249
  };
@@ -305,21 +317,56 @@ type Lens = FieldMapSet & {
305
317
  mapName: string;
306
318
  model: string;
307
319
  };
308
- type ModelNarrowing = {
320
+ /**
321
+ * Narrowing applied wherever a model appears (intrinsic to the model).
322
+ * Has no `relations` because relations are path-specific by definition.
323
+ *
324
+ * Two kinds of narrowing live here:
325
+ * - SCHEMA narrowing (picks/omits/enumPicks/enumOmits): controls what's visible
326
+ * in the type surface. AI/SDK consumers can't see narrowed-away fields.
327
+ * - DATA narrowing (where): controls which ROWS are in scope. Filter-first
328
+ * semantic, anchored to the model. Under arrayOperator: 'all', applied via
329
+ * implication (negate) to preserve filter-first meaning — see applyLens.
330
+ */
331
+ type ModelDefaultNarrowing = {
309
332
  picks?: string[];
310
333
  omits?: string[];
334
+ enumPicks?: Record<string, readonly string[]>;
335
+ enumOmits?: Record<string, readonly string[]>;
336
+ /**
337
+ * Row-level filter anchored to this model — "from what you can see, this is true."
338
+ * Composes via filter-first semantic at every visit of this model.
339
+ */
340
+ where?: Condition;
341
+ };
342
+ /** Narrowing for a model at a specific traversal path. Adds relations to the default shape. */
343
+ type ModelNarrowing = ModelDefaultNarrowing & {
311
344
  relations?: Record<string, ModelNarrowing>;
312
345
  };
346
+ /** Narrowing for an enum type (applies anywhere the enum is referenced). */
347
+ type EnumNarrowing = {
348
+ picks?: readonly string[];
349
+ omits?: readonly string[];
350
+ };
351
+ /** Applies-everywhere narrowings — per-model (no relations) + per-enum-type. */
352
+ type NarrowingDefaults = {
353
+ models?: Record<string, ModelDefaultNarrowing>;
354
+ enums?: Record<string, EnumNarrowing>;
355
+ };
313
356
  type MapNarrowing = {
357
+ /** Path-specific narrowings, root + relations tree. */
314
358
  models: Record<string, ModelNarrowing>;
359
+ /** Applies-everywhere narrowings, intersect with path-specific. */
360
+ defaults?: NarrowingDefaults;
315
361
  };
316
362
  type LensNarrowing = {
317
363
  parent: Lens | LensNarrowing;
318
364
  maps: Record<string, MapNarrowing>;
319
- constrains?: Condition;
365
+ /** Lens-level row filter, anchored to the root model. ANDs into the root rule. */
366
+ where?: Condition;
320
367
  };
321
368
 
322
- declare const applyLens: (rule: Condition, narrowing: Lens | LensNarrowing) => Condition;
369
+ declare const applyLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
323
370
 
324
371
  type RuleLensViolation = {
325
372
  path: string;
@@ -490,4 +537,4 @@ declare const assertValidRule: (condition: unknown, options?: {
490
537
  target?: RuleTarget;
491
538
  }) => asserts condition is Condition;
492
539
 
493
- 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 DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type MapNarrowing, type ModelNarrowing, NUMERIC_KINDS, ORDERABLE_KINDS, Operator, type OrderedRuleValue, type PrismaStep, type PrismaWhere, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, 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 ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WhereStep, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectNarrowing, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };
540
+ 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 DateInputValue, DateOperator, type DateRule, type DateRuleValue, EQUATABLE_KINDS, type EnumNarrowing, FIELD_OPERATOR_CATALOG, FieldKind, type FieldMap, type FieldMapEntry, type FieldMapSet, type GroupByStep, type IfThenElse, type Lens, type LensNarrowing, type MapNarrowing, type ModelDefaultNarrowing, type ModelNarrowing, NUMERIC_KINDS, type NarrowingDefaults, ORDERABLE_KINDS, Operator, type OrderedRuleValue, type PrismaStep, type PrismaWhere, type Rule, type RuleLensCheck, type RuleLensViolation, type RuleScalar, RuleTarget, type RuleValue, STRINGY_KINDS, 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 ToPrismaResult, type ValidationIssue, type ValidationResult, ValueShape, type WhereStep, applyLens, assertValidRule, buildBridgeDictionary, check, checkRuleAgainstLens, createLens, executePrismaQueryPlan, getArrayOperators, getOperatorsForKind, getValueShape, isAggregateRangeOperator, isAggregateSingleOperator, isOperatorSupportedForTarget, projectNarrowing, stitchFieldMaps, toPrisma, toSql, validateFieldMap, validateFieldMapSet, validateNarrowing, validateRule };