Skip to content

Commit 9442dab

Browse files
committed
feat($imports): disallow default imports
BREAKING CHANGE: imports
1 parent 358ac3a commit 9442dab

19 files changed

Lines changed: 85 additions & 99 deletions

src/almanac.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Fact from './fact'
1+
import {Fact} from './fact'
22
import { UndefinedFactError } from './errors'
33

4-
import selectn from 'selectn'
5-
import debug0 from 'debug'
4+
const selectn = require('selectn')
5+
import * as debug0 from 'debug'
66

77
let debug = debug0('json-rules-engine')
88
let verbose = debug0('json-rules-engine-verbose')
@@ -16,7 +16,7 @@ export type FactMap = Map<string, Fact>
1616
* Triggers fact computations and saves the results
1717
* A new almanac is used for every engine run()
1818
*/
19-
export default class Almanac {
19+
export class Almanac {
2020
factResultsCache: Map<string, any>
2121
factMap: FactMap
2222

@@ -83,7 +83,7 @@ export default class Almanac {
8383
if (path) {
8484
return factValuePromise.then(factValue => {
8585
if (factValue && isObjectLike(factValue)) {
86-
let pathValue = selectn<Function>(path)!(factValue)
86+
let pathValue = selectn(path)(factValue)
8787
debug(
8888
`condition::evaluate extracting object property ${path}, received: ${pathValue}`,
8989
)

src/condition.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import debug0 from 'debug'
1+
import * as debug0 from 'debug'
22

33
const debug = debug0('json-rules-engine')
4-
import isObjectLike from 'lodash.isobjectlike'
5-
import Almanac from './almanac'
6-
import Operator from './operator'
4+
const isObjectLike = require('lodash.isobjectlike')
5+
import {Almanac}from './almanac'
6+
import {Operator} from './operator'
77
import {ToJsonAble} from './to-json-able.interface'
88

99
export interface ICouldHavePriority {
@@ -29,7 +29,7 @@ export interface BaseCondition extends ICouldHavePriority {
2929
all?: BaseCondition[]
3030
}
3131

32-
export default class Condition implements ICouldHavePriority, ToJsonAble {
32+
export class Condition implements ICouldHavePriority, ToJsonAble {
3333

3434
priority?: number | string
3535
value: any

src/engine-default-operators.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import Operator from './operator'
1+
import {Operator} from './operator'
22

3-
let Operators: Operator[] = []
4-
Operators.push(new Operator('equal', (a: any, b: any) => a === b))
5-
Operators.push(new Operator('notEqual', (a: any, b: any) => a !== b))
6-
Operators.push(new Operator('in', (a: any, b: any) => b.indexOf(a) > -1))
7-
Operators.push(new Operator('notIn', (a: any, b: any) => b.indexOf(a) === -1))
3+
export const defaultOperators: Operator[] = []
4+
defaultOperators.push(new Operator('equal', (a: any, b: any) => a === b))
5+
defaultOperators.push(new Operator('notEqual', (a: any, b: any) => a !== b))
6+
defaultOperators.push(new Operator('in', (a: any, b: any) => b.indexOf(a) > -1))
7+
defaultOperators.push(new Operator('notIn', (a: any, b: any) => b.indexOf(a) === -1))
88

9-
Operators.push(
9+
defaultOperators.push(
1010
new Operator('contains', (a: any, b: any) => a.indexOf(b) > -1, Array.isArray),
1111
)
12-
Operators.push(
12+
defaultOperators.push(
1313
new Operator(
1414
'doesNotContain',
1515
(a: any, b: any) => a.indexOf(b) === -1,
@@ -20,21 +20,19 @@ Operators.push(
2020
function numberValidator (factValue: string) {
2121
return Number.parseFloat(factValue).toString() !== 'NaN'
2222
}
23-
Operators.push(
23+
defaultOperators.push(
2424
new Operator('lessThan', (a: any, b: any) => a < b, numberValidator),
2525
)
26-
Operators.push(
26+
defaultOperators.push(
2727
new Operator('lessThanInclusive', (a: any, b: any) => a <= b, numberValidator),
2828
)
29-
Operators.push(
29+
defaultOperators.push(
3030
new Operator('greaterThan', (a: any, b: any) => a > b, numberValidator),
3131
)
32-
Operators.push(
32+
defaultOperators.push(
3333
new Operator(
3434
'greaterThanInclusive',
3535
(a: any, b: any) => a >= b,
3636
numberValidator,
3737
),
3838
)
39-
40-
export default Operators

src/engine.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Fact, {FactOptions} from './fact'
2-
import Rule, {RuleConstructorOptions} from './rule'
3-
import Operator from './operator'
4-
import Almanac from './almanac'
1+
import {Fact, FactOptions} from './fact'
2+
import {Rule} from './rule'
3+
import {Operator} from './operator'
4+
import {Almanac} from './almanac'
55
import { EventEmitter } from 'events'
66
import { SuccessEventFact } from './engine-facts'
7-
import defaultOperators from './engine-default-operators'
7+
import {defaultOperators} from './engine-default-operators'
88

99
let debug = require('debug')('json-rules-engine')
1010

@@ -17,7 +17,7 @@ export enum EngineStatus {
1717
FINISHED = 'FINISHED',
1818
}
1919

20-
class Engine extends EventEmitter {
20+
export class Engine extends EventEmitter {
2121
rules: Rule[]
2222
allowUndefinedFacts: boolean
2323
operators: Map<string, Operator>
@@ -281,5 +281,3 @@ class Engine extends EventEmitter {
281281
})
282282
}
283283
}
284-
285-
export default Engine

src/fact.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import hash from 'object-hash'
2-
import debug from 'debug'
3-
import deepClone from 'clone'
1+
import * as hash from 'object-hash'
2+
import * as debug from 'debug'
3+
import * as deepClone from 'clone'
44

5-
import Almanac from './almanac'
5+
import {Almanac} from './almanac'
66
let verbose = debug('json-rules-engine-verbose')
77

88
export interface FactOptions {
99
cache?: boolean
1010
priority?: number
1111
}
1212

13-
class Fact {
13+
export class Fact {
1414
static CONSTANT = 'CONSTANT'
1515
static DYNAMIC = 'DYNAMIC'
1616

@@ -129,5 +129,3 @@ class Fact {
129129
}
130130
}
131131
}
132-
133-
export default Fact

src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
import json_rules_engine, {
2-
Fact,
3-
Rule,
4-
Operator,
5-
Engine,
6-
} from './truegin'
7-
8-
export default json_rules_engine
9-
export { Fact, Rule, Operator, Engine }
1+
export * from './'

src/operator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface CustomOperator {
1414
evaluate (factValue: any, jsonValue: any): boolean
1515
}
1616

17-
export default class Operator implements CustomOperator {
17+
export class Operator implements CustomOperator {
1818
cb: (factValue: any, jsonvalue: any) => boolean
1919
name: string
2020
factValueValidator: FactValueValidator

src/rule-result.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import deepClone from 'clone'
2-
import Condition, {BaseCondition} from './condition'
1+
import * as deepClone from 'clone'
2+
import {Condition} from './condition'
33
import {Action} from './action.interface'
44
import {ToJsonAble} from './to-json-able.interface'
55

6-
export default class RuleResult implements ToJsonAble {
6+
export class RuleResult implements ToJsonAble {
77
conditions: Condition
88
event?: Action
99
priority?: string | number | null

src/rule.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import Condition, {ConditionConstructorOptions, ICouldHavePriority} from './condition'
2-
import RuleResult from './rule-result'
3-
import { EventEmitter } from 'events'
1+
import {Condition, ConditionConstructorOptions, ICouldHavePriority} from './condition'
2+
import {RuleResult} from './rule-result'
3+
import {EventEmitter} from 'events'
44
import {Action} from './action.interface'
5-
import Engine from './engine'
6-
import Almanac from './almanac'
5+
import {Engine} from './engine'
6+
import {Almanac} from './almanac'
77

88
let debug = require('debug')('json-rules-engine')
99

@@ -13,7 +13,7 @@ export interface RuleConstructorOptions {
1313
priority?: number | string,
1414
}
1515

16-
class Rule extends EventEmitter implements ICouldHavePriority {
16+
export class Rule extends EventEmitter implements ICouldHavePriority {
1717

1818
priority?: number
1919
conditions?: Condition
@@ -307,5 +307,3 @@ class Rule extends EventEmitter implements ICouldHavePriority {
307307
}
308308
}
309309
}
310-
311-
export default Rule

src/truegin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import Engine, {EngineOptions} from './engine'
2-
import Fact from './fact'
3-
import Rule from './rule'
4-
import Operator from './operator'
1+
import {Engine, EngineOptions} from './engine'
2+
import {Fact} from './fact'
3+
import {Rule} from './rule'
4+
import {Operator} from './operator'
55

66
export { Fact, Rule, Operator, Engine }
7-
export default function (rules?: Rule[], options?: EngineOptions) {
7+
export function engineFactory (rules?: Rule[], options?: EngineOptions) {
88
return new Engine(rules, options)
99
}

0 commit comments

Comments
 (0)