@inixiative/json-rules 2.0.0 → 2.1.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 +29 -11
- package/dist/index.cjs +18 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -12
- package/dist/index.d.ts +74 -12
- package/dist/index.js +18 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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
|
};
|
|
@@ -266,6 +278,21 @@ type BridgeEndpoint = {
|
|
|
266
278
|
on: string;
|
|
267
279
|
};
|
|
268
280
|
type BridgeCardinality = 'oneToOne' | 'oneToMany';
|
|
281
|
+
/**
|
|
282
|
+
* A cross-source edge between two endpoints.
|
|
283
|
+
*
|
|
284
|
+
* Endpoint ordering convention for `oneToMany`:
|
|
285
|
+
* - `endpoints[0]` is the "one" side — its `on` field must be unique per row
|
|
286
|
+
* (typically a primary key).
|
|
287
|
+
* - `endpoints[1]` is the "many" side — its `on` field may repeat across rows
|
|
288
|
+
* (typically a foreign key).
|
|
289
|
+
*
|
|
290
|
+
* Mis-ordering produces wrong `isList` flags during stitching and silent
|
|
291
|
+
* row-dedup when building bridge dictionaries. `buildBridgeDictionary` throws
|
|
292
|
+
* at runtime if endpoint[0]'s data has duplicate `on` values to catch this.
|
|
293
|
+
*
|
|
294
|
+
* For `oneToOne`, both `on` fields must be unique; endpoint order is symmetric.
|
|
295
|
+
*/
|
|
269
296
|
type Bridge = {
|
|
270
297
|
endpoints: [BridgeEndpoint, BridgeEndpoint];
|
|
271
298
|
cardinality: BridgeCardinality;
|
|
@@ -290,21 +317,56 @@ type Lens = FieldMapSet & {
|
|
|
290
317
|
mapName: string;
|
|
291
318
|
model: string;
|
|
292
319
|
};
|
|
293
|
-
|
|
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 = {
|
|
294
332
|
picks?: string[];
|
|
295
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 & {
|
|
296
344
|
relations?: Record<string, ModelNarrowing>;
|
|
297
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
|
+
};
|
|
298
356
|
type MapNarrowing = {
|
|
357
|
+
/** Path-specific narrowings, root + relations tree. */
|
|
299
358
|
models: Record<string, ModelNarrowing>;
|
|
359
|
+
/** Applies-everywhere narrowings, intersect with path-specific. */
|
|
360
|
+
defaults?: NarrowingDefaults;
|
|
300
361
|
};
|
|
301
362
|
type LensNarrowing = {
|
|
302
363
|
parent: Lens | LensNarrowing;
|
|
303
364
|
maps: Record<string, MapNarrowing>;
|
|
304
|
-
|
|
365
|
+
/** Lens-level row filter, anchored to the root model. ANDs into the root rule. */
|
|
366
|
+
where?: Condition;
|
|
305
367
|
};
|
|
306
368
|
|
|
307
|
-
declare const applyLens: (rule: Condition,
|
|
369
|
+
declare const applyLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
|
|
308
370
|
|
|
309
371
|
type RuleLensViolation = {
|
|
310
372
|
path: string;
|
|
@@ -475,4 +537,4 @@ declare const assertValidRule: (condition: unknown, options?: {
|
|
|
475
537
|
target?: RuleTarget;
|
|
476
538
|
}) => asserts condition is Condition;
|
|
477
539
|
|
|
478
|
-
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
|
};
|
|
@@ -266,6 +278,21 @@ type BridgeEndpoint = {
|
|
|
266
278
|
on: string;
|
|
267
279
|
};
|
|
268
280
|
type BridgeCardinality = 'oneToOne' | 'oneToMany';
|
|
281
|
+
/**
|
|
282
|
+
* A cross-source edge between two endpoints.
|
|
283
|
+
*
|
|
284
|
+
* Endpoint ordering convention for `oneToMany`:
|
|
285
|
+
* - `endpoints[0]` is the "one" side — its `on` field must be unique per row
|
|
286
|
+
* (typically a primary key).
|
|
287
|
+
* - `endpoints[1]` is the "many" side — its `on` field may repeat across rows
|
|
288
|
+
* (typically a foreign key).
|
|
289
|
+
*
|
|
290
|
+
* Mis-ordering produces wrong `isList` flags during stitching and silent
|
|
291
|
+
* row-dedup when building bridge dictionaries. `buildBridgeDictionary` throws
|
|
292
|
+
* at runtime if endpoint[0]'s data has duplicate `on` values to catch this.
|
|
293
|
+
*
|
|
294
|
+
* For `oneToOne`, both `on` fields must be unique; endpoint order is symmetric.
|
|
295
|
+
*/
|
|
269
296
|
type Bridge = {
|
|
270
297
|
endpoints: [BridgeEndpoint, BridgeEndpoint];
|
|
271
298
|
cardinality: BridgeCardinality;
|
|
@@ -290,21 +317,56 @@ type Lens = FieldMapSet & {
|
|
|
290
317
|
mapName: string;
|
|
291
318
|
model: string;
|
|
292
319
|
};
|
|
293
|
-
|
|
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 = {
|
|
294
332
|
picks?: string[];
|
|
295
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 & {
|
|
296
344
|
relations?: Record<string, ModelNarrowing>;
|
|
297
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
|
+
};
|
|
298
356
|
type MapNarrowing = {
|
|
357
|
+
/** Path-specific narrowings, root + relations tree. */
|
|
299
358
|
models: Record<string, ModelNarrowing>;
|
|
359
|
+
/** Applies-everywhere narrowings, intersect with path-specific. */
|
|
360
|
+
defaults?: NarrowingDefaults;
|
|
300
361
|
};
|
|
301
362
|
type LensNarrowing = {
|
|
302
363
|
parent: Lens | LensNarrowing;
|
|
303
364
|
maps: Record<string, MapNarrowing>;
|
|
304
|
-
|
|
365
|
+
/** Lens-level row filter, anchored to the root model. ANDs into the root rule. */
|
|
366
|
+
where?: Condition;
|
|
305
367
|
};
|
|
306
368
|
|
|
307
|
-
declare const applyLens: (rule: Condition,
|
|
369
|
+
declare const applyLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => Condition;
|
|
308
370
|
|
|
309
371
|
type RuleLensViolation = {
|
|
310
372
|
path: string;
|
|
@@ -475,4 +537,4 @@ declare const assertValidRule: (condition: unknown, options?: {
|
|
|
475
537
|
target?: RuleTarget;
|
|
476
538
|
}) => asserts condition is Condition;
|
|
477
539
|
|
|
478
|
-
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 };
|