@trigger.dev/core 3.0.0-beta.5 → 3.0.0-beta.51
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/api-Pl9fxB8v.d.mts +13879 -0
- package/dist/api-sNoooMbT.d.ts +13879 -0
- package/dist/catalog-H7yFiZ60.d.mts +202 -0
- package/dist/catalog-h79CG5Wy.d.ts +202 -0
- package/dist/common-CLW82lkt.d.mts +1423 -0
- package/dist/common-CLW82lkt.d.ts +1423 -0
- package/dist/{eventFilterMatches-2kHImluE.d.mts → eventFilter-66NaBAMi.d.mts} +1 -3
- package/dist/{eventFilterMatches-2kHImluE.d.ts → eventFilter-66NaBAMi.d.ts} +1 -3
- package/dist/eventFilterMatches.d.mts +6 -0
- package/dist/eventFilterMatches.d.ts +6 -0
- package/dist/eventFilterMatches.js +165 -0
- package/dist/eventFilterMatches.js.map +1 -0
- package/dist/eventFilterMatches.mjs +163 -0
- package/dist/eventFilterMatches.mjs.map +1 -0
- package/dist/index.d.mts +14 -16657
- package/dist/index.d.ts +14 -16657
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -2
- package/dist/index.mjs.map +1 -1
- package/dist/json-DBPEJQRe.d.mts +16 -0
- package/dist/json-DBPEJQRe.d.ts +16 -0
- package/dist/manager-KvCabW1a.d.mts +18 -0
- package/dist/manager-OBA35PzR.d.ts +18 -0
- package/dist/messages-JvHJ83wv.d.mts +19428 -0
- package/dist/messages-JvHJ83wv.d.ts +19428 -0
- package/dist/replacements.d.mts +22 -0
- package/dist/replacements.d.ts +22 -0
- package/dist/replacements.js +33 -0
- package/dist/replacements.js.map +1 -0
- package/dist/replacements.mjs +28 -0
- package/dist/replacements.mjs.map +1 -0
- package/dist/requestFilter-HNZQEpQb.d.ts +180 -0
- package/dist/requestFilter-b5W2_1oP.d.mts +180 -0
- package/dist/requestFilterMatches.d.mts +13 -0
- package/dist/requestFilterMatches.d.ts +13 -0
- package/dist/requestFilterMatches.js +238 -0
- package/dist/requestFilterMatches.js.map +1 -0
- package/dist/requestFilterMatches.mjs +235 -0
- package/dist/requestFilterMatches.mjs.map +1 -0
- package/dist/retry.d.mts +10 -0
- package/dist/retry.d.ts +10 -0
- package/dist/retry.js +100 -0
- package/dist/retry.js.map +1 -0
- package/dist/retry.mjs +97 -0
- package/dist/retry.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2611 -0
- package/dist/schemas/index.d.ts +2611 -0
- package/dist/schemas/index.js +1630 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/index.mjs +1463 -0
- package/dist/schemas/index.mjs.map +1 -0
- package/dist/schemas-C9ssfehv.d.mts +2568 -0
- package/dist/schemas-C9ssfehv.d.ts +2568 -0
- package/dist/taskLogger-CzADe4je.d.ts +33 -0
- package/dist/taskLogger-r_AFTX45.d.mts +33 -0
- package/dist/tracer-N0p2Fuuv.d.mts +23 -0
- package/dist/tracer-N0p2Fuuv.d.ts +23 -0
- package/dist/types.d.mts +11 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.d.mts +7 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +30 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/v3/dev/index.d.mts +29 -0
- package/dist/v3/dev/index.d.ts +29 -0
- package/dist/v3/dev/index.js +93 -0
- package/dist/v3/dev/index.js.map +1 -0
- package/dist/v3/dev/index.mjs +91 -0
- package/dist/v3/dev/index.mjs.map +1 -0
- package/dist/v3/errors.d.mts +39 -0
- package/dist/v3/errors.d.ts +39 -0
- package/dist/v3/errors.js +204 -0
- package/dist/v3/errors.js.map +1 -0
- package/dist/v3/errors.mjs +195 -0
- package/dist/v3/errors.mjs.map +1 -0
- package/dist/v3/index.d.mts +445 -20508
- package/dist/v3/index.d.ts +445 -20508
- package/dist/v3/index.js +2843 -2884
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +2785 -2856
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/logger-api.d.mts +24 -0
- package/dist/v3/logger-api.d.ts +24 -0
- package/dist/v3/logger-api.js +118 -0
- package/dist/v3/logger-api.js.map +1 -0
- package/dist/v3/logger-api.mjs +116 -0
- package/dist/v3/logger-api.mjs.map +1 -0
- package/dist/v3/otel/index.js +119 -53
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +119 -53
- package/dist/v3/otel/index.mjs.map +1 -1
- package/dist/v3/prod/index.d.mts +46 -0
- package/dist/v3/prod/index.d.ts +46 -0
- package/dist/v3/prod/index.js +180 -0
- package/dist/v3/prod/index.js.map +1 -0
- package/dist/v3/prod/index.mjs +178 -0
- package/dist/v3/prod/index.mjs.map +1 -0
- package/dist/v3/schemas/index.d.mts +4807 -0
- package/dist/v3/schemas/index.d.ts +4807 -0
- package/dist/v3/schemas/index.js +2054 -0
- package/dist/v3/schemas/index.js.map +1 -0
- package/dist/v3/schemas/index.mjs +1913 -0
- package/dist/v3/schemas/index.mjs.map +1 -0
- package/dist/v3/semanticInternalAttributes.d.mts +56 -0
- package/dist/v3/semanticInternalAttributes.d.ts +56 -0
- package/dist/v3/semanticInternalAttributes.js +61 -0
- package/dist/v3/semanticInternalAttributes.js.map +1 -0
- package/dist/v3/semanticInternalAttributes.mjs +59 -0
- package/dist/v3/semanticInternalAttributes.mjs.map +1 -0
- package/dist/v3/utils/durations.d.mts +15 -0
- package/dist/v3/utils/durations.d.ts +15 -0
- package/dist/v3/utils/durations.js +93 -0
- package/dist/v3/utils/durations.js.map +1 -0
- package/dist/v3/utils/durations.mjs +82 -0
- package/dist/v3/utils/durations.mjs.map +1 -0
- package/dist/v3/utils/flattenAttributes.d.mts +8 -0
- package/dist/v3/utils/flattenAttributes.d.ts +8 -0
- package/dist/v3/utils/flattenAttributes.js +131 -0
- package/dist/v3/utils/flattenAttributes.js.map +1 -0
- package/dist/v3/utils/flattenAttributes.mjs +126 -0
- package/dist/v3/utils/flattenAttributes.mjs.map +1 -0
- package/dist/v3/utils/ioSerialization.d.mts +21 -0
- package/dist/v3/utils/ioSerialization.d.ts +21 -0
- package/dist/v3/utils/ioSerialization.js +2392 -0
- package/dist/v3/utils/ioSerialization.js.map +1 -0
- package/dist/v3/utils/ioSerialization.mjs +2383 -0
- package/dist/v3/utils/ioSerialization.mjs.map +1 -0
- package/dist/v3/utils/omit.d.mts +3 -0
- package/dist/v3/utils/omit.d.ts +3 -0
- package/dist/v3/utils/omit.js +20 -0
- package/dist/v3/utils/omit.js.map +1 -0
- package/dist/v3/utils/omit.mjs +18 -0
- package/dist/v3/utils/omit.mjs.map +1 -0
- package/dist/v3/utils/retries.d.mts +46 -0
- package/dist/v3/utils/retries.d.ts +46 -0
- package/dist/v3/utils/retries.js +118 -0
- package/dist/v3/utils/retries.js.map +1 -0
- package/dist/v3/utils/retries.mjs +113 -0
- package/dist/v3/utils/retries.mjs.map +1 -0
- package/dist/v3/utils/structuredLogger.d.mts +31 -0
- package/dist/v3/utils/structuredLogger.d.ts +31 -0
- package/dist/v3/utils/structuredLogger.js +88 -0
- package/dist/v3/utils/structuredLogger.js.map +1 -0
- package/dist/v3/utils/structuredLogger.mjs +86 -0
- package/dist/v3/utils/structuredLogger.mjs.map +1 -0
- package/dist/v3/utils/timers.d.mts +6 -0
- package/dist/v3/utils/timers.d.ts +6 -0
- package/dist/v3/utils/timers.js +31 -0
- package/dist/v3/utils/timers.js.map +1 -0
- package/dist/v3/utils/timers.mjs +28 -0
- package/dist/v3/utils/timers.mjs.map +1 -0
- package/dist/v3/workers/index.d.mts +144 -0
- package/dist/v3/workers/index.d.ts +144 -0
- package/dist/v3/workers/index.js +3708 -0
- package/dist/v3/workers/index.js.map +1 -0
- package/dist/v3/workers/index.mjs +3689 -0
- package/dist/v3/workers/index.mjs.map +1 -0
- package/dist/v3/zodIpc.d.mts +32 -0
- package/dist/v3/zodIpc.d.ts +32 -0
- package/dist/v3/zodIpc.js +268 -0
- package/dist/v3/zodIpc.js.map +1 -0
- package/dist/v3/zodIpc.mjs +266 -0
- package/dist/v3/zodIpc.mjs.map +1 -0
- package/dist/v3/zodMessageHandler.d.mts +82 -0
- package/dist/v3/zodMessageHandler.d.ts +82 -0
- package/dist/v3/zodMessageHandler.js +222 -0
- package/dist/v3/zodMessageHandler.js.map +1 -0
- package/dist/v3/zodMessageHandler.mjs +217 -0
- package/dist/v3/zodMessageHandler.mjs.map +1 -0
- package/dist/v3/zodNamespace.d.mts +3663 -0
- package/dist/v3/zodNamespace.d.ts +3663 -0
- package/dist/v3/zodNamespace.js +397 -0
- package/dist/v3/zodNamespace.js.map +1 -0
- package/dist/v3/zodNamespace.mjs +395 -0
- package/dist/v3/zodNamespace.mjs.map +1 -0
- package/dist/v3/zodSocket.d.mts +93 -0
- package/dist/v3/zodSocket.d.ts +93 -0
- package/dist/v3/zodSocket.js +350 -0
- package/dist/v3/zodSocket.js.map +1 -0
- package/dist/v3/zodSocket.mjs +346 -0
- package/dist/v3/zodSocket.mjs.map +1 -0
- package/dist/v3/zodfetch.d.mts +219 -0
- package/dist/v3/zodfetch.d.ts +219 -0
- package/dist/v3/zodfetch.js +834 -0
- package/dist/v3/zodfetch.js.map +1 -0
- package/dist/v3/zodfetch.mjs +811 -0
- package/dist/v3/zodfetch.mjs.map +1 -0
- package/dist/versions.d.mts +11 -0
- package/dist/versions.d.ts +11 -0
- package/dist/versions.js +31 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +27 -0
- package/dist/versions.mjs.map +1 -0
- package/package.json +223 -5
|
@@ -128,6 +128,4 @@ declare const EventRuleSchema: z.ZodObject<{
|
|
|
128
128
|
}>;
|
|
129
129
|
type EventRule = z.infer<typeof EventRuleSchema>;
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, eventFilterMatches as e, stringPatternMatchers as s };
|
|
131
|
+
export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, stringPatternMatchers as s };
|
|
@@ -128,6 +128,4 @@ declare const EventRuleSchema: z.ZodObject<{
|
|
|
128
128
|
}>;
|
|
129
129
|
type EventRule = z.infer<typeof EventRuleSchema>;
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, eventFilterMatches as e, stringPatternMatchers as s };
|
|
131
|
+
export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, stringPatternMatchers as s };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
// src/eventFilterMatches.ts
|
|
7
|
+
function eventFilterMatches(payload, filter) {
|
|
8
|
+
if (payload === void 0 || payload === null) {
|
|
9
|
+
if (Object.entries(filter).length === 0) {
|
|
10
|
+
return true;
|
|
11
|
+
} else {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
for (const [patternKey, patternValue] of Object.entries(filter)) {
|
|
16
|
+
const payloadValue = payload[patternKey];
|
|
17
|
+
if (Array.isArray(patternValue)) {
|
|
18
|
+
if (patternValue.length === 0) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (patternValue.every((item) => typeof item === "string")) {
|
|
22
|
+
if (patternValue.includes(payloadValue)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (patternValue.every((item) => typeof item === "number")) {
|
|
28
|
+
if (patternValue.includes(payloadValue)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (patternValue.every((item) => typeof item === "boolean")) {
|
|
34
|
+
if (patternValue.includes(payloadValue)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const objectArray = patternValue;
|
|
40
|
+
if (!contentFiltersMatches(payloadValue, objectArray)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
} else if (typeof patternValue === "object") {
|
|
45
|
+
if (Array.isArray(payloadValue)) {
|
|
46
|
+
if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (!eventFilterMatches(payloadValue, patternValue)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
__name(eventFilterMatches, "eventFilterMatches");
|
|
59
|
+
function contentFiltersMatches(actualValue, contentFilters) {
|
|
60
|
+
for (const contentFilter of contentFilters) {
|
|
61
|
+
if (typeof contentFilter === "object") {
|
|
62
|
+
Object.entries(contentFilter)[0];
|
|
63
|
+
if (!contentFilterMatches(actualValue, contentFilter)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
__name(contentFiltersMatches, "contentFiltersMatches");
|
|
71
|
+
function contentFilterMatches(actualValue, contentFilter) {
|
|
72
|
+
if ("$endsWith" in contentFilter) {
|
|
73
|
+
if (typeof actualValue !== "string") {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return actualValue.endsWith(contentFilter.$endsWith);
|
|
77
|
+
}
|
|
78
|
+
if ("$startsWith" in contentFilter) {
|
|
79
|
+
if (typeof actualValue !== "string") {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return actualValue.startsWith(contentFilter.$startsWith);
|
|
83
|
+
}
|
|
84
|
+
if ("$anythingBut" in contentFilter) {
|
|
85
|
+
if (Array.isArray(contentFilter.$anythingBut)) {
|
|
86
|
+
if (contentFilter.$anythingBut.includes(actualValue)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (contentFilter.$anythingBut === actualValue) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if ("$exists" in contentFilter) {
|
|
96
|
+
if (contentFilter.$exists) {
|
|
97
|
+
return actualValue !== void 0;
|
|
98
|
+
}
|
|
99
|
+
return actualValue === void 0;
|
|
100
|
+
}
|
|
101
|
+
if ("$gt" in contentFilter) {
|
|
102
|
+
if (typeof actualValue !== "number") {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return actualValue > contentFilter.$gt;
|
|
106
|
+
}
|
|
107
|
+
if ("$lt" in contentFilter) {
|
|
108
|
+
if (typeof actualValue !== "number") {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return actualValue < contentFilter.$lt;
|
|
112
|
+
}
|
|
113
|
+
if ("$gte" in contentFilter) {
|
|
114
|
+
if (typeof actualValue !== "number") {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return actualValue >= contentFilter.$gte;
|
|
118
|
+
}
|
|
119
|
+
if ("$lte" in contentFilter) {
|
|
120
|
+
if (typeof actualValue !== "number") {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return actualValue <= contentFilter.$lte;
|
|
124
|
+
}
|
|
125
|
+
if ("$between" in contentFilter) {
|
|
126
|
+
if (typeof actualValue !== "number") {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];
|
|
130
|
+
}
|
|
131
|
+
if ("$includes" in contentFilter) {
|
|
132
|
+
if (Array.isArray(actualValue)) {
|
|
133
|
+
return actualValue.includes(contentFilter.$includes);
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if ("$ignoreCaseEquals" in contentFilter) {
|
|
138
|
+
if (typeof actualValue !== "string") {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return actualValue.localeCompare(contentFilter.$ignoreCaseEquals, void 0, {
|
|
142
|
+
sensitivity: "accent"
|
|
143
|
+
}) === 0;
|
|
144
|
+
}
|
|
145
|
+
if ("$isNull" in contentFilter) {
|
|
146
|
+
if (contentFilter.$isNull) {
|
|
147
|
+
return actualValue === null;
|
|
148
|
+
}
|
|
149
|
+
return actualValue !== null;
|
|
150
|
+
}
|
|
151
|
+
if ("$not" in contentFilter) {
|
|
152
|
+
if (Array.isArray(actualValue)) {
|
|
153
|
+
return !actualValue.includes(contentFilter.$not);
|
|
154
|
+
} else if (typeof actualValue === "number" || typeof actualValue === "boolean" || typeof actualValue === "string") {
|
|
155
|
+
return actualValue !== contentFilter.$not;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
__name(contentFilterMatches, "contentFilterMatches");
|
|
162
|
+
|
|
163
|
+
exports.eventFilterMatches = eventFilterMatches;
|
|
164
|
+
//# sourceMappingURL=out.js.map
|
|
165
|
+
//# sourceMappingURL=eventFilterMatches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eventFilterMatches.ts"],"names":["eventFilterMatches","payload","filter","undefined","Object","entries","length","patternKey","patternValue","payloadValue","Array","isArray","every","item","includes","objectArray","contentFiltersMatches","some","actualValue","contentFilters","contentFilter","key","value","contentFilterMatches","endsWith","$endsWith","startsWith","$startsWith","$anythingBut","$exists","$gt","$lt","$gte","$lte","$between","$includes","localeCompare","$ignoreCaseEquals","sensitivity","$isNull","$not"],"mappings":";;;;AAMO,SAASA,mBAAmBC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eE,cAAca;EACtC;AAEA,MAAI,cAAcb,eAAe;AAC/B,QAAI,OAAOF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WAAOA,eAAeE,cAAcc,SAAS,CAAA,KAAMhB,eAAeE,cAAcc,SAAS,CAAA;EAC3F;AAEA,MAAI,eAAed,eAAe;AAChC,QAAIV,MAAMC,QAAQO,WAAAA,GAAc;AAC9B,aAAOA,YAAYJ,SAASM,cAAce,SAAS;IACrD;AAEA,WAAO;EACT;AAGA,MAAI,uBAAuBf,eAAe;AACxC,QAAI,OAAOF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WACEA,YAAYkB,cAAchB,cAAciB,mBAAmBlC,QAAW;MACpEmC,aAAa;IACf,CAAA,MAAO;EAEX;AAEA,MAAI,aAAalB,eAAe;AAC9B,QAAIA,cAAcmB,SAAS;AACzB,aAAOrB,gBAAgB;IACzB;AAEA,WAAOA,gBAAgB;EACzB;AAEA,MAAI,UAAUE,eAAe;AAC3B,QAAIV,MAAMC,QAAQO,WAAAA,GAAc;AAC9B,aAAO,CAACA,YAAYJ,SAASM,cAAcoB,IAAI;IACjD,WAAW,OAAOtB,gBAAgB,YAAY,OAAOA,gBAAgB,aAAa,OAAOA,gBAAgB,UAAU;AACjH,aAAOA,gBAAgBE,cAAcoB;IACvC;AAEA,WAAO;EACT;AAEA,SAAO;AACT;AAvHSjB","sourcesContent":["import { EventFilter } from \"./schemas/eventFilter\";\n\n// EventFilter is a recursive type, where the keys are strings and the values are an array of strings, numbers, booleans, or objects.\n// If the values of the array are strings, numbers, or booleans, than we are matching against the value of the payload.\n// If the values of the array are objects, then we are doing content filtering\n// An example would be [{ $endsWith: \".png\" }, { $startsWith: \"images/\" } ]\nexport function eventFilterMatches(payload: any, filter: EventFilter): boolean {\n if (payload === undefined || payload === null) {\n if (Object.entries(filter).length === 0) {\n return true;\n } else {\n return false;\n }\n }\n\n for (const [patternKey, patternValue] of Object.entries(filter)) {\n const payloadValue = payload[patternKey];\n\n if (Array.isArray(patternValue)) {\n if (patternValue.length === 0) {\n continue;\n }\n\n // Check to see if all the items in the array are a string\n if ((patternValue as unknown[]).every((item) => typeof item === \"string\")) {\n if ((patternValue as string[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Check to see if all the items in the array are a number\n if ((patternValue as unknown[]).every((item) => typeof item === \"number\")) {\n if ((patternValue as number[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Check to see if all the items in the array are a boolean\n if ((patternValue as unknown[]).every((item) => typeof item === \"boolean\")) {\n if ((patternValue as boolean[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Now we know that all the items in the array are objects\n const objectArray = patternValue as Exclude<\n typeof patternValue,\n number[] | string[] | boolean[]\n >;\n\n if (!contentFiltersMatches(payloadValue, objectArray)) {\n return false;\n }\n\n continue;\n } else if (typeof patternValue === \"object\") {\n if (Array.isArray(payloadValue)) {\n if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {\n return false;\n }\n } else {\n if (!eventFilterMatches(payloadValue, patternValue)) {\n return false;\n }\n }\n }\n }\n return true;\n}\n\ntype ContentFilters = Exclude<EventFilter[string], EventFilter | string[] | number[] | boolean[]>;\n\nfunction contentFiltersMatches(actualValue: any, contentFilters: ContentFilters): boolean {\n for (const contentFilter of contentFilters) {\n if (typeof contentFilter === \"object\") {\n const [key, value] = Object.entries(contentFilter)[0];\n\n if (!contentFilterMatches(actualValue, contentFilter)) {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction contentFilterMatches(actualValue: any, contentFilter: ContentFilters[number]): boolean {\n if (\"$endsWith\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return actualValue.endsWith(contentFilter.$endsWith);\n }\n\n if (\"$startsWith\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return actualValue.startsWith(contentFilter.$startsWith);\n }\n\n if (\"$anythingBut\" in contentFilter) {\n if (Array.isArray(contentFilter.$anythingBut)) {\n if ((contentFilter.$anythingBut as any[]).includes(actualValue)) {\n return false;\n }\n }\n\n if (contentFilter.$anythingBut === actualValue) {\n return false;\n }\n\n return true;\n }\n\n if (\"$exists\" in contentFilter) {\n if (contentFilter.$exists) {\n return actualValue !== undefined;\n }\n\n return actualValue === undefined;\n }\n\n if (\"$gt\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue > contentFilter.$gt;\n }\n\n if (\"$lt\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue < contentFilter.$lt;\n }\n\n if (\"$gte\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue >= contentFilter.$gte;\n }\n\n if (\"$lte\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue <= contentFilter.$lte;\n }\n\n if (\"$between\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];\n }\n\n if (\"$includes\" in contentFilter) {\n if (Array.isArray(actualValue)) {\n return actualValue.includes(contentFilter.$includes);\n }\n\n return false;\n }\n\n // Use localCompare\n if (\"$ignoreCaseEquals\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return (\n actualValue.localeCompare(contentFilter.$ignoreCaseEquals, undefined, {\n sensitivity: \"accent\",\n }) === 0\n );\n }\n\n if (\"$isNull\" in contentFilter) {\n if (contentFilter.$isNull) {\n return actualValue === null;\n }\n\n return actualValue !== null;\n }\n\n if (\"$not\" in contentFilter) {\n if (Array.isArray(actualValue)) {\n return !actualValue.includes(contentFilter.$not);\n } else if (typeof actualValue === 'number' || typeof actualValue === 'boolean' || typeof actualValue === 'string') {\n return actualValue !== contentFilter.$not;\n }\n\n return false;\n }\n\n return true;\n}\n"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/eventFilterMatches.ts
|
|
5
|
+
function eventFilterMatches(payload, filter) {
|
|
6
|
+
if (payload === void 0 || payload === null) {
|
|
7
|
+
if (Object.entries(filter).length === 0) {
|
|
8
|
+
return true;
|
|
9
|
+
} else {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
for (const [patternKey, patternValue] of Object.entries(filter)) {
|
|
14
|
+
const payloadValue = payload[patternKey];
|
|
15
|
+
if (Array.isArray(patternValue)) {
|
|
16
|
+
if (patternValue.length === 0) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (patternValue.every((item) => typeof item === "string")) {
|
|
20
|
+
if (patternValue.includes(payloadValue)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (patternValue.every((item) => typeof item === "number")) {
|
|
26
|
+
if (patternValue.includes(payloadValue)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (patternValue.every((item) => typeof item === "boolean")) {
|
|
32
|
+
if (patternValue.includes(payloadValue)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const objectArray = patternValue;
|
|
38
|
+
if (!contentFiltersMatches(payloadValue, objectArray)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
} else if (typeof patternValue === "object") {
|
|
43
|
+
if (Array.isArray(payloadValue)) {
|
|
44
|
+
if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
if (!eventFilterMatches(payloadValue, patternValue)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
__name(eventFilterMatches, "eventFilterMatches");
|
|
57
|
+
function contentFiltersMatches(actualValue, contentFilters) {
|
|
58
|
+
for (const contentFilter of contentFilters) {
|
|
59
|
+
if (typeof contentFilter === "object") {
|
|
60
|
+
Object.entries(contentFilter)[0];
|
|
61
|
+
if (!contentFilterMatches(actualValue, contentFilter)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
__name(contentFiltersMatches, "contentFiltersMatches");
|
|
69
|
+
function contentFilterMatches(actualValue, contentFilter) {
|
|
70
|
+
if ("$endsWith" in contentFilter) {
|
|
71
|
+
if (typeof actualValue !== "string") {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return actualValue.endsWith(contentFilter.$endsWith);
|
|
75
|
+
}
|
|
76
|
+
if ("$startsWith" in contentFilter) {
|
|
77
|
+
if (typeof actualValue !== "string") {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return actualValue.startsWith(contentFilter.$startsWith);
|
|
81
|
+
}
|
|
82
|
+
if ("$anythingBut" in contentFilter) {
|
|
83
|
+
if (Array.isArray(contentFilter.$anythingBut)) {
|
|
84
|
+
if (contentFilter.$anythingBut.includes(actualValue)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (contentFilter.$anythingBut === actualValue) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if ("$exists" in contentFilter) {
|
|
94
|
+
if (contentFilter.$exists) {
|
|
95
|
+
return actualValue !== void 0;
|
|
96
|
+
}
|
|
97
|
+
return actualValue === void 0;
|
|
98
|
+
}
|
|
99
|
+
if ("$gt" in contentFilter) {
|
|
100
|
+
if (typeof actualValue !== "number") {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return actualValue > contentFilter.$gt;
|
|
104
|
+
}
|
|
105
|
+
if ("$lt" in contentFilter) {
|
|
106
|
+
if (typeof actualValue !== "number") {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return actualValue < contentFilter.$lt;
|
|
110
|
+
}
|
|
111
|
+
if ("$gte" in contentFilter) {
|
|
112
|
+
if (typeof actualValue !== "number") {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return actualValue >= contentFilter.$gte;
|
|
116
|
+
}
|
|
117
|
+
if ("$lte" in contentFilter) {
|
|
118
|
+
if (typeof actualValue !== "number") {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return actualValue <= contentFilter.$lte;
|
|
122
|
+
}
|
|
123
|
+
if ("$between" in contentFilter) {
|
|
124
|
+
if (typeof actualValue !== "number") {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];
|
|
128
|
+
}
|
|
129
|
+
if ("$includes" in contentFilter) {
|
|
130
|
+
if (Array.isArray(actualValue)) {
|
|
131
|
+
return actualValue.includes(contentFilter.$includes);
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if ("$ignoreCaseEquals" in contentFilter) {
|
|
136
|
+
if (typeof actualValue !== "string") {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return actualValue.localeCompare(contentFilter.$ignoreCaseEquals, void 0, {
|
|
140
|
+
sensitivity: "accent"
|
|
141
|
+
}) === 0;
|
|
142
|
+
}
|
|
143
|
+
if ("$isNull" in contentFilter) {
|
|
144
|
+
if (contentFilter.$isNull) {
|
|
145
|
+
return actualValue === null;
|
|
146
|
+
}
|
|
147
|
+
return actualValue !== null;
|
|
148
|
+
}
|
|
149
|
+
if ("$not" in contentFilter) {
|
|
150
|
+
if (Array.isArray(actualValue)) {
|
|
151
|
+
return !actualValue.includes(contentFilter.$not);
|
|
152
|
+
} else if (typeof actualValue === "number" || typeof actualValue === "boolean" || typeof actualValue === "string") {
|
|
153
|
+
return actualValue !== contentFilter.$not;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
__name(contentFilterMatches, "contentFilterMatches");
|
|
160
|
+
|
|
161
|
+
export { eventFilterMatches };
|
|
162
|
+
//# sourceMappingURL=out.js.map
|
|
163
|
+
//# sourceMappingURL=eventFilterMatches.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eventFilterMatches.ts"],"names":["eventFilterMatches","payload","filter","undefined","Object","entries","length","patternKey","patternValue","payloadValue","Array","isArray","every","item","includes","objectArray","contentFiltersMatches","some","actualValue","contentFilters","contentFilter","key","value","contentFilterMatches","endsWith","$endsWith","startsWith","$startsWith","$anythingBut","$exists","$gt","$lt","$gte","$lte","$between","$includes","localeCompare","$ignoreCaseEquals","sensitivity","$isNull","$not"],"mappings":";;;;AAMO,SAASA,mBAAmBC,SAAcC,QAA8B;AAC7E,MAAID,YAAYE,UAAaF,YAAY,MAAM;AAC7C,QAAIG,OAAOC,QAAQH,MAAAA,EAAQI,WAAW,GAAG;AACvC,aAAO;IACT,OAAO;AACL,aAAO;IACT;EACF;AAEA,aAAW,CAACC,YAAYC,YAAAA,KAAiBJ,OAAOC,QAAQH,MAAAA,GAAS;AAC/D,UAAMO,eAAeR,QAAQM,UAAAA;AAE7B,QAAIG,MAAMC,QAAQH,YAAAA,GAAe;AAC/B,UAAIA,aAAaF,WAAW,GAAG;AAC7B;MACF;AAGA,UAAKE,aAA2BI,MAAM,CAACC,SAAS,OAAOA,SAAS,QAAA,GAAW;AACzE,YAAKL,aAA0BM,SAASL,YAAAA,GAAe;AACrD;QACF;AAEA,eAAO;MACT;AAGA,UAAKD,aAA2BI,MAAM,CAACC,SAAS,OAAOA,SAAS,QAAA,GAAW;AACzE,YAA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EA,WAAOA,gBAAgB;EACzB;AAEA,MAAI,UAAUE,eAAe;AAC3B,QAAIV,MAAMC,QAAQO,WAAAA,GAAc;AAC9B,aAAO,CAACA,YAAYJ,SAASM,cAAcoB,IAAI;IACjD,WAAW,OAAOtB,gBAAgB,YAAY,OAAOA,gBAAgB,aAAa,OAAOA,gBAAgB,UAAU;AACjH,aAAOA,gBAAgBE,cAAcoB;IACvC;AAEA,WAAO;EACT;AAEA,SAAO;AACT;AAvHSjB","sourcesContent":["import { EventFilter } from \"./schemas/eventFilter\";\n\n// EventFilter is a recursive type, where the keys are strings and the values are an array of strings, numbers, booleans, or objects.\n// If the values of the array are strings, numbers, or booleans, than we are matching against the value of the payload.\n// If the values of the array are objects, then we are doing content filtering\n// An example would be [{ $endsWith: \".png\" }, { $startsWith: \"images/\" } ]\nexport function eventFilterMatches(payload: any, filter: EventFilter): boolean {\n if (payload === undefined || payload === null) {\n if (Object.entries(filter).length === 0) {\n return true;\n } else {\n return false;\n }\n }\n\n for (const [patternKey, patternValue] of Object.entries(filter)) {\n const payloadValue = payload[patternKey];\n\n if (Array.isArray(patternValue)) {\n if (patternValue.length === 0) {\n continue;\n }\n\n // Check to see if all the items in the array are a string\n if ((patternValue as unknown[]).every((item) => typeof item === \"string\")) {\n if ((patternValue as string[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Check to see if all the items in the array are a number\n if ((patternValue as unknown[]).every((item) => typeof item === \"number\")) {\n if ((patternValue as number[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Check to see if all the items in the array are a boolean\n if ((patternValue as unknown[]).every((item) => typeof item === \"boolean\")) {\n if ((patternValue as boolean[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Now we know that all the items in the array are objects\n const objectArray = patternValue as Exclude<\n typeof patternValue,\n number[] | string[] | boolean[]\n >;\n\n if (!contentFiltersMatches(payloadValue, objectArray)) {\n return false;\n }\n\n continue;\n } else if (typeof patternValue === \"object\") {\n if (Array.isArray(payloadValue)) {\n if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {\n return false;\n }\n } else {\n if (!eventFilterMatches(payloadValue, patternValue)) {\n return false;\n }\n }\n }\n }\n return true;\n}\n\ntype ContentFilters = Exclude<EventFilter[string], EventFilter | string[] | number[] | boolean[]>;\n\nfunction contentFiltersMatches(actualValue: any, contentFilters: ContentFilters): boolean {\n for (const contentFilter of contentFilters) {\n if (typeof contentFilter === \"object\") {\n const [key, value] = Object.entries(contentFilter)[0];\n\n if (!contentFilterMatches(actualValue, contentFilter)) {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction contentFilterMatches(actualValue: any, contentFilter: ContentFilters[number]): boolean {\n if (\"$endsWith\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return actualValue.endsWith(contentFilter.$endsWith);\n }\n\n if (\"$startsWith\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return actualValue.startsWith(contentFilter.$startsWith);\n }\n\n if (\"$anythingBut\" in contentFilter) {\n if (Array.isArray(contentFilter.$anythingBut)) {\n if ((contentFilter.$anythingBut as any[]).includes(actualValue)) {\n return false;\n }\n }\n\n if (contentFilter.$anythingBut === actualValue) {\n return false;\n }\n\n return true;\n }\n\n if (\"$exists\" in contentFilter) {\n if (contentFilter.$exists) {\n return actualValue !== undefined;\n }\n\n return actualValue === undefined;\n }\n\n if (\"$gt\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue > contentFilter.$gt;\n }\n\n if (\"$lt\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue < contentFilter.$lt;\n }\n\n if (\"$gte\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue >= contentFilter.$gte;\n }\n\n if (\"$lte\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue <= contentFilter.$lte;\n }\n\n if (\"$between\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];\n }\n\n if (\"$includes\" in contentFilter) {\n if (Array.isArray(actualValue)) {\n return actualValue.includes(contentFilter.$includes);\n }\n\n return false;\n }\n\n // Use localCompare\n if (\"$ignoreCaseEquals\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return (\n actualValue.localeCompare(contentFilter.$ignoreCaseEquals, undefined, {\n sensitivity: \"accent\",\n }) === 0\n );\n }\n\n if (\"$isNull\" in contentFilter) {\n if (contentFilter.$isNull) {\n return actualValue === null;\n }\n\n return actualValue !== null;\n }\n\n if (\"$not\" in contentFilter) {\n if (Array.isArray(actualValue)) {\n return !actualValue.includes(contentFilter.$not);\n } else if (typeof actualValue === 'number' || typeof actualValue === 'boolean' || typeof actualValue === 'string') {\n return actualValue !== contentFilter.$not;\n }\n\n return false;\n }\n\n return true;\n}\n"]}
|