@inixiative/json-rules 1.3.3 → 2.0.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 +168 -0
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -42
- package/dist/index.d.ts +144 -42
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
package/dist/index.d.cts
CHANGED
|
@@ -86,7 +86,7 @@ type StrictRangeRule = (RuleBase<OperatorValues['between']> & ValueSource<[Order
|
|
|
86
86
|
type StrictPresenceRule = (RuleBase<OperatorValues['isEmpty']> & NoValueSource) | (RuleBase<OperatorValues['notEmpty']> & NoValueSource) | (RuleBase<OperatorValues['exists']> & NoValueSource) | (RuleBase<OperatorValues['notExists']> & NoValueSource);
|
|
87
87
|
type StrictRule<TValue = RuleValue> = StrictEqualityRule<TValue> | StrictOrderedComparisonRule | StrictMembershipRule<TValue> | StrictContainsRule<TValue> | StrictPatternRule | StrictStringBoundaryRule | StrictRangeRule | StrictPresenceRule;
|
|
88
88
|
type ArrayRuleBase<TOperator extends ArrayOperator> = {
|
|
89
|
-
field
|
|
89
|
+
field?: string;
|
|
90
90
|
arrayOperator: TOperator;
|
|
91
91
|
error?: string;
|
|
92
92
|
};
|
|
@@ -164,7 +164,7 @@ type Rule<TValue = RuleValue> = {
|
|
|
164
164
|
error?: string;
|
|
165
165
|
};
|
|
166
166
|
type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
|
|
167
|
-
field
|
|
167
|
+
field?: string;
|
|
168
168
|
arrayOperator: ArrayOperator;
|
|
169
169
|
condition?: Condition<TRuleValue, TDateValue>;
|
|
170
170
|
count?: number;
|
|
@@ -208,11 +208,16 @@ type StrictIfThenElse<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
|
|
|
208
208
|
};
|
|
209
209
|
type StrictCondition<TRuleValue = RuleValue, TDateValue = DateRuleValue> = StrictRule<TRuleValue> | StrictAggregateRule<TRuleValue, TDateValue> | StrictArrayRule<TRuleValue, TDateValue> | StrictDateRule | StrictAll<TRuleValue, TDateValue> | StrictAny<TRuleValue, TDateValue> | StrictIfThenElse<TRuleValue, TDateValue> | boolean;
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
type Row$1 = Record<string, unknown>;
|
|
212
|
+
type CheckData = Row$1 | unknown[];
|
|
213
|
+
type CheckOptions = {
|
|
214
|
+
context?: CheckData;
|
|
215
|
+
};
|
|
216
|
+
declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
|
|
212
217
|
|
|
213
218
|
type PrismaWhere = Record<string, unknown>;
|
|
214
219
|
type FieldMapEntry = {
|
|
215
|
-
kind: 'scalar' | 'object' | 'enum';
|
|
220
|
+
kind: 'scalar' | 'object' | 'enum' | 'bridge';
|
|
216
221
|
type: string;
|
|
217
222
|
isList?: boolean;
|
|
218
223
|
fromFields?: string[];
|
|
@@ -249,11 +254,142 @@ type ToPrismaResult = {
|
|
|
249
254
|
steps: PrismaStep[];
|
|
250
255
|
};
|
|
251
256
|
type BuildOptions = {
|
|
252
|
-
map?: FieldMap;
|
|
257
|
+
map?: FieldMap | FieldMapSet;
|
|
258
|
+
mapName?: string;
|
|
253
259
|
model?: string;
|
|
254
260
|
context?: Record<string, unknown>;
|
|
255
261
|
};
|
|
256
262
|
|
|
263
|
+
type BridgeEndpoint = {
|
|
264
|
+
fieldMap: string;
|
|
265
|
+
model: string;
|
|
266
|
+
on: string;
|
|
267
|
+
};
|
|
268
|
+
type BridgeCardinality = 'oneToOne' | 'oneToMany';
|
|
269
|
+
type Bridge = {
|
|
270
|
+
endpoints: [BridgeEndpoint, BridgeEndpoint];
|
|
271
|
+
cardinality: BridgeCardinality;
|
|
272
|
+
};
|
|
273
|
+
type FieldMapSet = {
|
|
274
|
+
maps: Record<string, FieldMap>;
|
|
275
|
+
bridges?: Bridge[];
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
type Row = Record<string, unknown>;
|
|
279
|
+
type BridgeDictionary = Record<string, // map name
|
|
280
|
+
Record<string, // model name
|
|
281
|
+
Record<string, Record<string, Row | Row[]>>>>;
|
|
282
|
+
declare const buildBridgeDictionary: (set: FieldMapSet, rawData: Record<string, Row[]>) => BridgeDictionary;
|
|
283
|
+
|
|
284
|
+
declare const stitchFieldMaps: (set: FieldMapSet) => FieldMapSet;
|
|
285
|
+
|
|
286
|
+
declare const validateFieldMapSet: (set: FieldMapSet) => void;
|
|
287
|
+
declare const validateFieldMap: (fieldMap: FieldMap, mapName?: string) => void;
|
|
288
|
+
|
|
289
|
+
type Lens = FieldMapSet & {
|
|
290
|
+
mapName: string;
|
|
291
|
+
model: string;
|
|
292
|
+
};
|
|
293
|
+
type ModelNarrowing = {
|
|
294
|
+
picks?: string[];
|
|
295
|
+
omits?: string[];
|
|
296
|
+
relations?: Record<string, ModelNarrowing>;
|
|
297
|
+
};
|
|
298
|
+
type MapNarrowing = {
|
|
299
|
+
models: Record<string, ModelNarrowing>;
|
|
300
|
+
};
|
|
301
|
+
type LensNarrowing = {
|
|
302
|
+
parent: Lens | LensNarrowing;
|
|
303
|
+
maps: Record<string, MapNarrowing>;
|
|
304
|
+
constrains?: Condition;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
declare const applyLens: (rule: Condition, narrowing: Lens | LensNarrowing) => Condition;
|
|
308
|
+
|
|
309
|
+
type RuleLensViolation = {
|
|
310
|
+
path: string;
|
|
311
|
+
reason: string;
|
|
312
|
+
};
|
|
313
|
+
type RuleLensCheck = {
|
|
314
|
+
ok: boolean;
|
|
315
|
+
violations: RuleLensViolation[];
|
|
316
|
+
};
|
|
317
|
+
declare const checkRuleAgainstLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleLensCheck;
|
|
318
|
+
|
|
319
|
+
type CreateLensInput = {
|
|
320
|
+
maps: Record<string, FieldMap>;
|
|
321
|
+
bridges?: Bridge[];
|
|
322
|
+
mapName: string;
|
|
323
|
+
model: string;
|
|
324
|
+
};
|
|
325
|
+
declare const createLens: (input: CreateLensInput) => Lens;
|
|
326
|
+
|
|
327
|
+
declare const validateNarrowing: (narrowing: LensNarrowing) => void;
|
|
328
|
+
|
|
329
|
+
declare const projectNarrowing: (lensOrNarrowing: Lens | LensNarrowing) => FieldMapSet;
|
|
330
|
+
|
|
331
|
+
declare const FieldKind: {
|
|
332
|
+
readonly String: "String";
|
|
333
|
+
readonly Boolean: "Boolean";
|
|
334
|
+
readonly Int: "Int";
|
|
335
|
+
readonly BigInt: "BigInt";
|
|
336
|
+
readonly Float: "Float";
|
|
337
|
+
readonly Decimal: "Decimal";
|
|
338
|
+
readonly DateTime: "DateTime";
|
|
339
|
+
readonly Json: "Json";
|
|
340
|
+
readonly Bytes: "Bytes";
|
|
341
|
+
readonly Enum: "Enum";
|
|
342
|
+
};
|
|
343
|
+
type FieldKind = (typeof FieldKind)[keyof typeof FieldKind];
|
|
344
|
+
declare const NUMERIC_KINDS: readonly FieldKind[];
|
|
345
|
+
declare const ORDERABLE_KINDS: readonly FieldKind[];
|
|
346
|
+
declare const STRINGY_KINDS: readonly FieldKind[];
|
|
347
|
+
declare const EQUATABLE_KINDS: readonly FieldKind[];
|
|
348
|
+
declare const ALL_KINDS: readonly FieldKind[];
|
|
349
|
+
declare const RuleTarget: {
|
|
350
|
+
readonly check: "check";
|
|
351
|
+
readonly toPrisma: "toPrisma";
|
|
352
|
+
readonly toSql: "toSql";
|
|
353
|
+
};
|
|
354
|
+
type RuleTarget = (typeof RuleTarget)[keyof typeof RuleTarget];
|
|
355
|
+
declare const ValueShape: {
|
|
356
|
+
readonly none: "none";
|
|
357
|
+
readonly scalar: "scalar";
|
|
358
|
+
readonly ordered: "ordered";
|
|
359
|
+
readonly array: "array";
|
|
360
|
+
readonly string: "string";
|
|
361
|
+
readonly pattern: "pattern";
|
|
362
|
+
readonly range: "range";
|
|
363
|
+
readonly dateValue: "dateValue";
|
|
364
|
+
readonly dateRange: "dateRange";
|
|
365
|
+
readonly dayList: "dayList";
|
|
366
|
+
readonly count: "count";
|
|
367
|
+
readonly predicate: "predicate";
|
|
368
|
+
};
|
|
369
|
+
type ValueShape = (typeof ValueShape)[keyof typeof ValueShape];
|
|
370
|
+
type CatalogEntry = {
|
|
371
|
+
kinds: readonly FieldKind[];
|
|
372
|
+
targets: readonly RuleTarget[];
|
|
373
|
+
valueShape: ValueShape;
|
|
374
|
+
};
|
|
375
|
+
declare const FIELD_OPERATOR_CATALOG: Record<Operator, CatalogEntry>;
|
|
376
|
+
declare const DATE_OPERATOR_CATALOG: Record<DateOperator, CatalogEntry>;
|
|
377
|
+
type ArrayCatalogEntry = {
|
|
378
|
+
targets: readonly RuleTarget[];
|
|
379
|
+
valueShape: ValueShape;
|
|
380
|
+
};
|
|
381
|
+
declare const ARRAY_OPERATOR_CATALOG: Record<ArrayOperator, ArrayCatalogEntry>;
|
|
382
|
+
declare const AGGREGATE_OPERATORS: readonly Operator[];
|
|
383
|
+
declare const isAggregateSingleOperator: (operator: Operator) => boolean;
|
|
384
|
+
declare const isAggregateRangeOperator: (operator: Operator) => boolean;
|
|
385
|
+
declare const getValueShape: (operator: Operator | DateOperator | ArrayOperator) => ValueShape;
|
|
386
|
+
declare const isOperatorSupportedForTarget: (operator: Operator | DateOperator | ArrayOperator, target: RuleTarget) => boolean;
|
|
387
|
+
declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget) => {
|
|
388
|
+
field: Operator[];
|
|
389
|
+
date: DateOperator[];
|
|
390
|
+
};
|
|
391
|
+
declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
|
|
392
|
+
|
|
257
393
|
/**
|
|
258
394
|
* Execute a Prisma query plan produced by toPrisma().
|
|
259
395
|
*
|
|
@@ -321,42 +457,8 @@ type SqlBuildOptions = {
|
|
|
321
457
|
alias?: string;
|
|
322
458
|
context?: Record<string, unknown>;
|
|
323
459
|
};
|
|
324
|
-
/**
|
|
325
|
-
* Convert a json-rules Condition to a PostgreSQL WHERE clause.
|
|
326
|
-
*
|
|
327
|
-
* @param condition - The rule condition to convert
|
|
328
|
-
* @param options - Optional map/model/alias for JOIN generation; context for path refs
|
|
329
|
-
* @returns Object with `sql`, `params`, and `joins` (LEFT JOIN clauses)
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```typescript
|
|
333
|
-
* // Simple field
|
|
334
|
-
* const { sql, params } = toSql({ field: 'status', operator: Operator.equals, value: 'active' });
|
|
335
|
-
* // sql: '"status" = $1'
|
|
336
|
-
*
|
|
337
|
-
* // Relation traversal with JOINs (map required)
|
|
338
|
-
* const { sql, params, joins } = toSql(
|
|
339
|
-
* { field: 'author.email', operator: Operator.equals, value: 'a@b.com' },
|
|
340
|
-
* { map, model: 'Post', alias: 't0' }
|
|
341
|
-
* );
|
|
342
|
-
* // sql: '"t1"."email" = $1'
|
|
343
|
-
* // joins: ['LEFT JOIN "User" AS "t1" ON "t1"."id" = "t0"."authorId"']
|
|
344
|
-
*
|
|
345
|
-
* // Same-record field comparison ($.field)
|
|
346
|
-
* const { sql: sql2 } = toSql({ field: 'endDate', operator: Operator.greaterThan, path: '$.startDate' });
|
|
347
|
-
* // sql2: '"endDate" > "startDate"'
|
|
348
|
-
*
|
|
349
|
-
* // External context ref
|
|
350
|
-
* const { sql: sql3 } = toSql(
|
|
351
|
-
* { field: 'userId', operator: Operator.equals, path: 'currentUser.id' },
|
|
352
|
-
* { context: { currentUser: { id: '123' } } }
|
|
353
|
-
* );
|
|
354
|
-
* // sql3: '"userId" = $1' params: ['123']
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
460
|
declare const toSql: (condition: Condition, options?: SqlBuildOptions) => SqlResult;
|
|
358
461
|
|
|
359
|
-
type RuleValidationTarget = 'check' | 'toPrisma' | 'toSql';
|
|
360
462
|
type ValidationIssue = {
|
|
361
463
|
path: string;
|
|
362
464
|
message: string;
|
|
@@ -367,10 +469,10 @@ type ValidationResult = {
|
|
|
367
469
|
errors: ValidationIssue[];
|
|
368
470
|
};
|
|
369
471
|
declare const validateRule: (condition: unknown, options?: {
|
|
370
|
-
target?:
|
|
472
|
+
target?: RuleTarget;
|
|
371
473
|
}) => ValidationResult;
|
|
372
474
|
declare const assertValidRule: (condition: unknown, options?: {
|
|
373
|
-
target?:
|
|
475
|
+
target?: RuleTarget;
|
|
374
476
|
}) => asserts condition is Condition;
|
|
375
477
|
|
|
376
|
-
export { type AggregateMode, type AggregateRule, type All, type Any, ArrayOperator, type ArrayRule, type BuildOptions, type Condition, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, type FieldMap, type FieldMapEntry, type GroupByStep, type IfThenElse, Operator, type OrderedRuleValue, type PrismaStep, type PrismaWhere, type Rule, type
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ type StrictRangeRule = (RuleBase<OperatorValues['between']> & ValueSource<[Order
|
|
|
86
86
|
type StrictPresenceRule = (RuleBase<OperatorValues['isEmpty']> & NoValueSource) | (RuleBase<OperatorValues['notEmpty']> & NoValueSource) | (RuleBase<OperatorValues['exists']> & NoValueSource) | (RuleBase<OperatorValues['notExists']> & NoValueSource);
|
|
87
87
|
type StrictRule<TValue = RuleValue> = StrictEqualityRule<TValue> | StrictOrderedComparisonRule | StrictMembershipRule<TValue> | StrictContainsRule<TValue> | StrictPatternRule | StrictStringBoundaryRule | StrictRangeRule | StrictPresenceRule;
|
|
88
88
|
type ArrayRuleBase<TOperator extends ArrayOperator> = {
|
|
89
|
-
field
|
|
89
|
+
field?: string;
|
|
90
90
|
arrayOperator: TOperator;
|
|
91
91
|
error?: string;
|
|
92
92
|
};
|
|
@@ -164,7 +164,7 @@ type Rule<TValue = RuleValue> = {
|
|
|
164
164
|
error?: string;
|
|
165
165
|
};
|
|
166
166
|
type ArrayRule<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
|
|
167
|
-
field
|
|
167
|
+
field?: string;
|
|
168
168
|
arrayOperator: ArrayOperator;
|
|
169
169
|
condition?: Condition<TRuleValue, TDateValue>;
|
|
170
170
|
count?: number;
|
|
@@ -208,11 +208,16 @@ type StrictIfThenElse<TRuleValue = RuleValue, TDateValue = DateRuleValue> = {
|
|
|
208
208
|
};
|
|
209
209
|
type StrictCondition<TRuleValue = RuleValue, TDateValue = DateRuleValue> = StrictRule<TRuleValue> | StrictAggregateRule<TRuleValue, TDateValue> | StrictArrayRule<TRuleValue, TDateValue> | StrictDateRule | StrictAll<TRuleValue, TDateValue> | StrictAny<TRuleValue, TDateValue> | StrictIfThenElse<TRuleValue, TDateValue> | boolean;
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
type Row$1 = Record<string, unknown>;
|
|
212
|
+
type CheckData = Row$1 | unknown[];
|
|
213
|
+
type CheckOptions = {
|
|
214
|
+
context?: CheckData;
|
|
215
|
+
};
|
|
216
|
+
declare const check: <TData extends CheckData>(conditions: Condition, data: TData, options?: CheckOptions) => boolean | string;
|
|
212
217
|
|
|
213
218
|
type PrismaWhere = Record<string, unknown>;
|
|
214
219
|
type FieldMapEntry = {
|
|
215
|
-
kind: 'scalar' | 'object' | 'enum';
|
|
220
|
+
kind: 'scalar' | 'object' | 'enum' | 'bridge';
|
|
216
221
|
type: string;
|
|
217
222
|
isList?: boolean;
|
|
218
223
|
fromFields?: string[];
|
|
@@ -249,11 +254,142 @@ type ToPrismaResult = {
|
|
|
249
254
|
steps: PrismaStep[];
|
|
250
255
|
};
|
|
251
256
|
type BuildOptions = {
|
|
252
|
-
map?: FieldMap;
|
|
257
|
+
map?: FieldMap | FieldMapSet;
|
|
258
|
+
mapName?: string;
|
|
253
259
|
model?: string;
|
|
254
260
|
context?: Record<string, unknown>;
|
|
255
261
|
};
|
|
256
262
|
|
|
263
|
+
type BridgeEndpoint = {
|
|
264
|
+
fieldMap: string;
|
|
265
|
+
model: string;
|
|
266
|
+
on: string;
|
|
267
|
+
};
|
|
268
|
+
type BridgeCardinality = 'oneToOne' | 'oneToMany';
|
|
269
|
+
type Bridge = {
|
|
270
|
+
endpoints: [BridgeEndpoint, BridgeEndpoint];
|
|
271
|
+
cardinality: BridgeCardinality;
|
|
272
|
+
};
|
|
273
|
+
type FieldMapSet = {
|
|
274
|
+
maps: Record<string, FieldMap>;
|
|
275
|
+
bridges?: Bridge[];
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
type Row = Record<string, unknown>;
|
|
279
|
+
type BridgeDictionary = Record<string, // map name
|
|
280
|
+
Record<string, // model name
|
|
281
|
+
Record<string, Record<string, Row | Row[]>>>>;
|
|
282
|
+
declare const buildBridgeDictionary: (set: FieldMapSet, rawData: Record<string, Row[]>) => BridgeDictionary;
|
|
283
|
+
|
|
284
|
+
declare const stitchFieldMaps: (set: FieldMapSet) => FieldMapSet;
|
|
285
|
+
|
|
286
|
+
declare const validateFieldMapSet: (set: FieldMapSet) => void;
|
|
287
|
+
declare const validateFieldMap: (fieldMap: FieldMap, mapName?: string) => void;
|
|
288
|
+
|
|
289
|
+
type Lens = FieldMapSet & {
|
|
290
|
+
mapName: string;
|
|
291
|
+
model: string;
|
|
292
|
+
};
|
|
293
|
+
type ModelNarrowing = {
|
|
294
|
+
picks?: string[];
|
|
295
|
+
omits?: string[];
|
|
296
|
+
relations?: Record<string, ModelNarrowing>;
|
|
297
|
+
};
|
|
298
|
+
type MapNarrowing = {
|
|
299
|
+
models: Record<string, ModelNarrowing>;
|
|
300
|
+
};
|
|
301
|
+
type LensNarrowing = {
|
|
302
|
+
parent: Lens | LensNarrowing;
|
|
303
|
+
maps: Record<string, MapNarrowing>;
|
|
304
|
+
constrains?: Condition;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
declare const applyLens: (rule: Condition, narrowing: Lens | LensNarrowing) => Condition;
|
|
308
|
+
|
|
309
|
+
type RuleLensViolation = {
|
|
310
|
+
path: string;
|
|
311
|
+
reason: string;
|
|
312
|
+
};
|
|
313
|
+
type RuleLensCheck = {
|
|
314
|
+
ok: boolean;
|
|
315
|
+
violations: RuleLensViolation[];
|
|
316
|
+
};
|
|
317
|
+
declare const checkRuleAgainstLens: (rule: Condition, lensOrNarrowing: Lens | LensNarrowing) => RuleLensCheck;
|
|
318
|
+
|
|
319
|
+
type CreateLensInput = {
|
|
320
|
+
maps: Record<string, FieldMap>;
|
|
321
|
+
bridges?: Bridge[];
|
|
322
|
+
mapName: string;
|
|
323
|
+
model: string;
|
|
324
|
+
};
|
|
325
|
+
declare const createLens: (input: CreateLensInput) => Lens;
|
|
326
|
+
|
|
327
|
+
declare const validateNarrowing: (narrowing: LensNarrowing) => void;
|
|
328
|
+
|
|
329
|
+
declare const projectNarrowing: (lensOrNarrowing: Lens | LensNarrowing) => FieldMapSet;
|
|
330
|
+
|
|
331
|
+
declare const FieldKind: {
|
|
332
|
+
readonly String: "String";
|
|
333
|
+
readonly Boolean: "Boolean";
|
|
334
|
+
readonly Int: "Int";
|
|
335
|
+
readonly BigInt: "BigInt";
|
|
336
|
+
readonly Float: "Float";
|
|
337
|
+
readonly Decimal: "Decimal";
|
|
338
|
+
readonly DateTime: "DateTime";
|
|
339
|
+
readonly Json: "Json";
|
|
340
|
+
readonly Bytes: "Bytes";
|
|
341
|
+
readonly Enum: "Enum";
|
|
342
|
+
};
|
|
343
|
+
type FieldKind = (typeof FieldKind)[keyof typeof FieldKind];
|
|
344
|
+
declare const NUMERIC_KINDS: readonly FieldKind[];
|
|
345
|
+
declare const ORDERABLE_KINDS: readonly FieldKind[];
|
|
346
|
+
declare const STRINGY_KINDS: readonly FieldKind[];
|
|
347
|
+
declare const EQUATABLE_KINDS: readonly FieldKind[];
|
|
348
|
+
declare const ALL_KINDS: readonly FieldKind[];
|
|
349
|
+
declare const RuleTarget: {
|
|
350
|
+
readonly check: "check";
|
|
351
|
+
readonly toPrisma: "toPrisma";
|
|
352
|
+
readonly toSql: "toSql";
|
|
353
|
+
};
|
|
354
|
+
type RuleTarget = (typeof RuleTarget)[keyof typeof RuleTarget];
|
|
355
|
+
declare const ValueShape: {
|
|
356
|
+
readonly none: "none";
|
|
357
|
+
readonly scalar: "scalar";
|
|
358
|
+
readonly ordered: "ordered";
|
|
359
|
+
readonly array: "array";
|
|
360
|
+
readonly string: "string";
|
|
361
|
+
readonly pattern: "pattern";
|
|
362
|
+
readonly range: "range";
|
|
363
|
+
readonly dateValue: "dateValue";
|
|
364
|
+
readonly dateRange: "dateRange";
|
|
365
|
+
readonly dayList: "dayList";
|
|
366
|
+
readonly count: "count";
|
|
367
|
+
readonly predicate: "predicate";
|
|
368
|
+
};
|
|
369
|
+
type ValueShape = (typeof ValueShape)[keyof typeof ValueShape];
|
|
370
|
+
type CatalogEntry = {
|
|
371
|
+
kinds: readonly FieldKind[];
|
|
372
|
+
targets: readonly RuleTarget[];
|
|
373
|
+
valueShape: ValueShape;
|
|
374
|
+
};
|
|
375
|
+
declare const FIELD_OPERATOR_CATALOG: Record<Operator, CatalogEntry>;
|
|
376
|
+
declare const DATE_OPERATOR_CATALOG: Record<DateOperator, CatalogEntry>;
|
|
377
|
+
type ArrayCatalogEntry = {
|
|
378
|
+
targets: readonly RuleTarget[];
|
|
379
|
+
valueShape: ValueShape;
|
|
380
|
+
};
|
|
381
|
+
declare const ARRAY_OPERATOR_CATALOG: Record<ArrayOperator, ArrayCatalogEntry>;
|
|
382
|
+
declare const AGGREGATE_OPERATORS: readonly Operator[];
|
|
383
|
+
declare const isAggregateSingleOperator: (operator: Operator) => boolean;
|
|
384
|
+
declare const isAggregateRangeOperator: (operator: Operator) => boolean;
|
|
385
|
+
declare const getValueShape: (operator: Operator | DateOperator | ArrayOperator) => ValueShape;
|
|
386
|
+
declare const isOperatorSupportedForTarget: (operator: Operator | DateOperator | ArrayOperator, target: RuleTarget) => boolean;
|
|
387
|
+
declare const getOperatorsForKind: (kind: FieldKind, target?: RuleTarget) => {
|
|
388
|
+
field: Operator[];
|
|
389
|
+
date: DateOperator[];
|
|
390
|
+
};
|
|
391
|
+
declare const getArrayOperators: (target?: RuleTarget) => ArrayOperator[];
|
|
392
|
+
|
|
257
393
|
/**
|
|
258
394
|
* Execute a Prisma query plan produced by toPrisma().
|
|
259
395
|
*
|
|
@@ -321,42 +457,8 @@ type SqlBuildOptions = {
|
|
|
321
457
|
alias?: string;
|
|
322
458
|
context?: Record<string, unknown>;
|
|
323
459
|
};
|
|
324
|
-
/**
|
|
325
|
-
* Convert a json-rules Condition to a PostgreSQL WHERE clause.
|
|
326
|
-
*
|
|
327
|
-
* @param condition - The rule condition to convert
|
|
328
|
-
* @param options - Optional map/model/alias for JOIN generation; context for path refs
|
|
329
|
-
* @returns Object with `sql`, `params`, and `joins` (LEFT JOIN clauses)
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```typescript
|
|
333
|
-
* // Simple field
|
|
334
|
-
* const { sql, params } = toSql({ field: 'status', operator: Operator.equals, value: 'active' });
|
|
335
|
-
* // sql: '"status" = $1'
|
|
336
|
-
*
|
|
337
|
-
* // Relation traversal with JOINs (map required)
|
|
338
|
-
* const { sql, params, joins } = toSql(
|
|
339
|
-
* { field: 'author.email', operator: Operator.equals, value: 'a@b.com' },
|
|
340
|
-
* { map, model: 'Post', alias: 't0' }
|
|
341
|
-
* );
|
|
342
|
-
* // sql: '"t1"."email" = $1'
|
|
343
|
-
* // joins: ['LEFT JOIN "User" AS "t1" ON "t1"."id" = "t0"."authorId"']
|
|
344
|
-
*
|
|
345
|
-
* // Same-record field comparison ($.field)
|
|
346
|
-
* const { sql: sql2 } = toSql({ field: 'endDate', operator: Operator.greaterThan, path: '$.startDate' });
|
|
347
|
-
* // sql2: '"endDate" > "startDate"'
|
|
348
|
-
*
|
|
349
|
-
* // External context ref
|
|
350
|
-
* const { sql: sql3 } = toSql(
|
|
351
|
-
* { field: 'userId', operator: Operator.equals, path: 'currentUser.id' },
|
|
352
|
-
* { context: { currentUser: { id: '123' } } }
|
|
353
|
-
* );
|
|
354
|
-
* // sql3: '"userId" = $1' params: ['123']
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
460
|
declare const toSql: (condition: Condition, options?: SqlBuildOptions) => SqlResult;
|
|
358
461
|
|
|
359
|
-
type RuleValidationTarget = 'check' | 'toPrisma' | 'toSql';
|
|
360
462
|
type ValidationIssue = {
|
|
361
463
|
path: string;
|
|
362
464
|
message: string;
|
|
@@ -367,10 +469,10 @@ type ValidationResult = {
|
|
|
367
469
|
errors: ValidationIssue[];
|
|
368
470
|
};
|
|
369
471
|
declare const validateRule: (condition: unknown, options?: {
|
|
370
|
-
target?:
|
|
472
|
+
target?: RuleTarget;
|
|
371
473
|
}) => ValidationResult;
|
|
372
474
|
declare const assertValidRule: (condition: unknown, options?: {
|
|
373
|
-
target?:
|
|
475
|
+
target?: RuleTarget;
|
|
374
476
|
}) => asserts condition is Condition;
|
|
375
477
|
|
|
376
|
-
export { type AggregateMode, type AggregateRule, type All, type Any, ArrayOperator, type ArrayRule, type BuildOptions, type Condition, type DateInputValue, DateOperator, type DateRule, type DateRuleValue, type FieldMap, type FieldMapEntry, type GroupByStep, type IfThenElse, Operator, type OrderedRuleValue, type PrismaStep, type PrismaWhere, type Rule, type
|
|
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 };
|