denotify-client 1.1.9 → 1.1.11

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.
@@ -1,14 +0,0 @@
1
- import { HandlerFunctionCall } from "./handler_function_call.js";
2
- import { HandlerOnchainEvent } from "./handler_onchain_event.js";
3
- import { HandlerFunctionCallV2 } from "./handler_function_call_v2.js";
4
- export class Trigger {
5
- static SimpleToRaw(name, id, network, config) {
6
- switch (id) {
7
- case 'PollFunctionV2': return HandlerFunctionCallV2.SimpleToRaw(name, network, config);
8
- case 'PollFunctionV1': return HandlerFunctionCall.SimpleToRaw(name, network, config);
9
- case 'OnchainEventV1': return HandlerOnchainEvent.SimpleToRaw(name, network, config);
10
- default:
11
- throw new Error('Invalid Trigger ID');
12
- }
13
- }
14
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,160 +0,0 @@
1
- import * as yup from 'yup';
2
- export class Filter {
3
- static version() {
4
- return 'v1';
5
- }
6
- static execute(record, groupsIn, version = 'v1') {
7
- // Deep copy to so we can edit the object during recursion
8
- const groups = JSON.parse(JSON.stringify(groupsIn));
9
- let lhs = true;
10
- for (const group of groups) {
11
- const rhs = Filter.process(record, group.conditions);
12
- lhs = Filter.execLogic(lhs, group.logic, rhs);
13
- }
14
- return lhs;
15
- }
16
- static process(record, conditions, lhs) {
17
- const condition = conditions.shift();
18
- if (!condition) {
19
- if (lhs === undefined)
20
- return true;
21
- return lhs;
22
- }
23
- // lhs <logic> rhs
24
- const rhs = Filter.execCondition(record, condition);
25
- if (lhs === undefined || condition.logic === 'WHERE')
26
- return Filter.process(record, conditions, rhs);
27
- if (condition.logic === undefined)
28
- throw new Error('Invalid filter. Condition must have logic value');
29
- const next = Filter.execLogic(lhs, condition.logic, rhs);
30
- return Filter.process(record, conditions, next);
31
- }
32
- static execLogic(lhs, logic, rhs) {
33
- switch (logic) {
34
- case 'AND': return lhs && rhs;
35
- case 'OR': return lhs || rhs;
36
- case 'XOR': return (lhs || rhs) && !(lhs && rhs);
37
- case 'NAND': return !(lhs && rhs);
38
- case 'NOR': return !(lhs && rhs);
39
- case 'WHERE': return rhs;
40
- default: throw new Error(`Invalid Filter. Bad logic value: ${logic}`);
41
- }
42
- }
43
- static execCondition(record, condition) {
44
- const data = record[condition.key];
45
- if (condition.type === 'Number') {
46
- if (typeof condition.constant !== 'number' || typeof data !== 'number')
47
- throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
48
- const n = data;
49
- const constant = condition.constant;
50
- switch (condition.operation) {
51
- case 'eq': return n === constant;
52
- case '!eq': return n !== constant;
53
- case 'gt': return n > constant;
54
- case 'gte': return n >= constant;
55
- case 'lt': return n < constant;
56
- case 'lte': return n <= constant;
57
- default: throw new Error('Invalid Filter. Operation does not match type');
58
- }
59
- }
60
- if (condition.type === 'String') {
61
- if (typeof condition.constant !== 'string' || typeof data !== 'string')
62
- throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
63
- const str = data;
64
- const constant = condition.constant;
65
- switch (condition.operation) {
66
- case 'contains': return str.includes(constant);
67
- case '!contains': return !str.includes(constant);
68
- case 'is': return str === constant;
69
- case '!is': return str !== constant;
70
- case 'isEmpty': return str === '';
71
- case '!isEmpty': return str !== '';
72
- default: throw new Error('Invalid Filter. Operation does not match type');
73
- }
74
- }
75
- if (condition.type === 'Address') {
76
- if (typeof condition.constant !== 'string' || typeof data !== 'string')
77
- throw new Error(`Invalid filter. Type miss-match. Type: ${condition.type}, Variable: ${condition.constant}, Data: ${data}`);
78
- const str = data;
79
- const constant = condition.constant;
80
- switch (condition.operation) {
81
- case 'contains': return str.toLowerCase().includes(constant.toLowerCase());
82
- case '!contains': return !str.toLowerCase().includes(constant.toLowerCase());
83
- case 'is': return str.toLowerCase() === constant.toLowerCase();
84
- case '!is': return str.toLowerCase() !== constant.toLowerCase();
85
- case 'isEmpty': return str === '';
86
- case '!isEmpty': return str !== '';
87
- default: throw new Error('Invalid Filter. Operation does not match type');
88
- }
89
- }
90
- throw new Error('Invalid Filter. Unknown Type');
91
- }
92
- }
93
- export class FilterBuilder {
94
- groups = [];
95
- constructor() {
96
- this.newGroup('WHERE');
97
- }
98
- static version() {
99
- return Filter.version();
100
- }
101
- static new() {
102
- return new FilterBuilder();
103
- }
104
- newGroup(logic) {
105
- if (this.groups.length !== 0 && logic === 'WHERE')
106
- throw new Error('Only the first groups can start with "WHERE"');
107
- this.groups.push({ logic: 'WHERE', conditions: [] });
108
- return this;
109
- }
110
- addCondition(logic, key, type, operation, constant) {
111
- const group = this.groups[this.groups.length - 1];
112
- if (group.conditions.length === 0 && logic !== 'WHERE')
113
- throw new Error('Logic for the first condition of a group must be "WHERE"');
114
- if (group.conditions.length > 0 && logic === 'WHERE')
115
- throw new Error('Only the first condition of a group can be "WHERE"');
116
- group.conditions.push({
117
- logic,
118
- key,
119
- type,
120
- operation,
121
- constant
122
- });
123
- return this;
124
- }
125
- finalise() {
126
- for (const group of this.groups) {
127
- if (group.conditions.length === 0)
128
- throw new Error('Bad Filter. All Groups must have atleast one condition');
129
- }
130
- return this.groups;
131
- }
132
- static schema() {
133
- const logic = yup.string().oneOf(['AND', 'OR', 'XOR', 'NAND', 'NOR', 'WHERE']).required();
134
- const condition = yup.object({
135
- logic,
136
- key: yup.string().required(),
137
- type: yup.string().oneOf(['String', 'Address', 'Number']).required(),
138
- operation: yup.string().when('type', ([type], schema) => {
139
- switch (type) {
140
- case 'String': return schema.oneOf(['contains', '!contains', 'is', '!is', 'isEmpty', '!isEmpty']);
141
- case 'Address': return schema.oneOf(['is', '!is', 'isEmpty', '!isEmpty']);
142
- case 'Number': return schema.oneOf(['String', 'Address', 'Number']);
143
- default: throw new Error('Invalid Filter Data Type');
144
- }
145
- }),
146
- constant: yup.mixed().when('type', ([type]) => {
147
- switch (type) {
148
- case 'String': return yup.string();
149
- case 'Address': return yup.string();
150
- case 'Number': return yup.number();
151
- default: throw new Error('Invalid Filter Data Type');
152
- }
153
- }),
154
- });
155
- return yup.array().of(yup.object({
156
- logic,
157
- conditions: yup.array().of(condition)
158
- }));
159
- }
160
- }
File without changes