@prismatic-io/spectral 10.4.1-alpha.0 → 10.4.2
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.
|
@@ -6,5 +6,15 @@ export declare const validate: (expression: ConditionalExpression) => Validation
|
|
|
6
6
|
export declare const parseValue: (value: unknown) => any;
|
|
7
7
|
export declare const contains: (container: unknown, containee: unknown) => boolean;
|
|
8
8
|
export declare const parseDate: (value: unknown) => Date;
|
|
9
|
+
export declare const isEqual: (left: unknown, right: unknown) => boolean;
|
|
10
|
+
export declare const isDeepEqual: (left: unknown, right: unknown) => boolean;
|
|
11
|
+
export declare const evaluatesTrue: (value: string | boolean) => boolean;
|
|
12
|
+
export declare const evaluatesFalse: (value: string | boolean) => boolean;
|
|
13
|
+
export declare const evaluatesNull: (value: unknown) => boolean;
|
|
14
|
+
export declare const evaluatesEmpty: (value: string | Array<unknown>) => boolean;
|
|
15
|
+
export declare const evaluatesNotEmpty: (value: string | Array<unknown>) => boolean;
|
|
16
|
+
export declare const dateIsAfter: (left: unknown, right: unknown) => boolean;
|
|
17
|
+
export declare const dateIsBefore: (left: unknown, right: unknown) => boolean;
|
|
18
|
+
export declare const dateIsEqual: (left: unknown, right: unknown) => boolean;
|
|
9
19
|
export declare const evaluate: (expression: ConditionalExpression) => boolean;
|
|
10
20
|
export * from "./types";
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.evaluate = exports.parseDate = exports.contains = exports.parseValue = exports.validate = void 0;
|
|
20
|
+
exports.evaluate = exports.dateIsEqual = exports.dateIsBefore = exports.dateIsAfter = exports.evaluatesNotEmpty = exports.evaluatesEmpty = exports.evaluatesNull = exports.evaluatesFalse = exports.evaluatesTrue = exports.isDeepEqual = exports.isEqual = exports.parseDate = exports.contains = exports.parseValue = exports.validate = void 0;
|
|
21
21
|
const types_1 = require("./types");
|
|
22
22
|
const date_fns_1 = require("date-fns");
|
|
23
23
|
const isEqualWith_1 = __importDefault(require("lodash/isEqualWith"));
|
|
@@ -110,6 +110,56 @@ const isEqual = (left, right) => left == right ||
|
|
|
110
110
|
}
|
|
111
111
|
return objectA == objectB;
|
|
112
112
|
});
|
|
113
|
+
exports.isEqual = isEqual;
|
|
114
|
+
const isDeepEqual = (left, right) => {
|
|
115
|
+
return (0, isEqual_1.default)(left, right);
|
|
116
|
+
};
|
|
117
|
+
exports.isDeepEqual = isDeepEqual;
|
|
118
|
+
const evaluatesTrue = (value) => {
|
|
119
|
+
return typeof value === "string" ? ["t", "true", "y", "yes"].includes(value) : value;
|
|
120
|
+
};
|
|
121
|
+
exports.evaluatesTrue = evaluatesTrue;
|
|
122
|
+
const evaluatesFalse = (value) => {
|
|
123
|
+
return typeof value === "string" ? ["f", "false", "n", "no"].includes(value) : value;
|
|
124
|
+
};
|
|
125
|
+
exports.evaluatesFalse = evaluatesFalse;
|
|
126
|
+
const evaluatesNull = (value) => {
|
|
127
|
+
const nullValues = [undefined, null, 0, Number.NaN, false, ""];
|
|
128
|
+
return nullValues.includes(value);
|
|
129
|
+
};
|
|
130
|
+
exports.evaluatesNull = evaluatesNull;
|
|
131
|
+
const evaluatesEmpty = (value) => {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
return value.length === 0;
|
|
134
|
+
}
|
|
135
|
+
if (typeof value === "string") {
|
|
136
|
+
return value.length === 0;
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Please provide an array or string");
|
|
139
|
+
};
|
|
140
|
+
exports.evaluatesEmpty = evaluatesEmpty;
|
|
141
|
+
const evaluatesNotEmpty = (value) => {
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
return value.length > 0;
|
|
144
|
+
}
|
|
145
|
+
if (typeof value === "string") {
|
|
146
|
+
return value.length > 0;
|
|
147
|
+
}
|
|
148
|
+
throw new Error("Please provide an array or string");
|
|
149
|
+
};
|
|
150
|
+
exports.evaluatesNotEmpty = evaluatesNotEmpty;
|
|
151
|
+
const dateIsAfter = (left, right) => {
|
|
152
|
+
return (0, date_fns_1.isAfter)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
153
|
+
};
|
|
154
|
+
exports.dateIsAfter = dateIsAfter;
|
|
155
|
+
const dateIsBefore = (left, right) => {
|
|
156
|
+
return (0, date_fns_1.isBefore)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
157
|
+
};
|
|
158
|
+
exports.dateIsBefore = dateIsBefore;
|
|
159
|
+
const dateIsEqual = (left, right) => {
|
|
160
|
+
return (0, date_fns_1.isEqual)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
161
|
+
};
|
|
162
|
+
exports.dateIsEqual = dateIsEqual;
|
|
113
163
|
const evaluate = (expression) => {
|
|
114
164
|
const [valid, message] = (0, exports.validate)(expression);
|
|
115
165
|
if (!valid) {
|
|
@@ -144,10 +194,10 @@ const evaluate = (expression) => {
|
|
|
144
194
|
case types_1.UnaryOperator.isTrue:
|
|
145
195
|
if (typeof left === "string") {
|
|
146
196
|
const lowerValue = left.toLowerCase();
|
|
147
|
-
if (
|
|
197
|
+
if ((0, exports.evaluatesTrue)(lowerValue)) {
|
|
148
198
|
return true;
|
|
149
199
|
}
|
|
150
|
-
else if (
|
|
200
|
+
else if ((0, exports.evaluatesFalse)(lowerValue)) {
|
|
151
201
|
return false;
|
|
152
202
|
}
|
|
153
203
|
}
|
|
@@ -155,25 +205,25 @@ const evaluate = (expression) => {
|
|
|
155
205
|
case types_1.UnaryOperator.isFalse:
|
|
156
206
|
if (typeof left === "string") {
|
|
157
207
|
const lowerValue = left.toLowerCase();
|
|
158
|
-
if (
|
|
208
|
+
if ((0, exports.evaluatesTrue)(lowerValue)) {
|
|
159
209
|
return false;
|
|
160
210
|
}
|
|
161
|
-
else if (
|
|
211
|
+
else if ((0, exports.evaluatesFalse)(lowerValue)) {
|
|
162
212
|
return true;
|
|
163
213
|
}
|
|
164
214
|
}
|
|
165
215
|
return !left;
|
|
166
216
|
case types_1.UnaryOperator.doesNotExist:
|
|
167
|
-
return
|
|
217
|
+
return (0, exports.evaluatesNull)(left);
|
|
168
218
|
case types_1.UnaryOperator.exists:
|
|
169
|
-
return !
|
|
219
|
+
return !(0, exports.evaluatesNull)(left);
|
|
170
220
|
case types_1.UnaryOperator.isEmpty:
|
|
171
221
|
if (Array.isArray(left)) {
|
|
172
|
-
return left
|
|
222
|
+
return (0, exports.evaluatesEmpty)(left);
|
|
173
223
|
}
|
|
174
224
|
// leftTerm is used here, since "123" would be cast to 123 and would not be a string
|
|
175
225
|
if (typeof leftTerm === "string") {
|
|
176
|
-
return leftTerm
|
|
226
|
+
return (0, exports.evaluatesEmpty)(leftTerm);
|
|
177
227
|
}
|
|
178
228
|
throw new Error("Please provide an array or string");
|
|
179
229
|
case types_1.UnaryOperator.isNotEmpty:
|
|
@@ -211,9 +261,9 @@ const evaluate = (expression) => {
|
|
|
211
261
|
try {
|
|
212
262
|
switch (operator) {
|
|
213
263
|
case types_1.BinaryOperator.equal:
|
|
214
|
-
return isEqual(left, right);
|
|
264
|
+
return (0, exports.isEqual)(left, right);
|
|
215
265
|
case types_1.BinaryOperator.notEqual:
|
|
216
|
-
return !isEqual(left, right);
|
|
266
|
+
return !(0, exports.isEqual)(left, right);
|
|
217
267
|
case types_1.BinaryOperator.greaterThan:
|
|
218
268
|
return left > right;
|
|
219
269
|
case types_1.BinaryOperator.greaterThanOrEqual:
|
|
@@ -227,9 +277,9 @@ const evaluate = (expression) => {
|
|
|
227
277
|
case types_1.BinaryOperator.notIn:
|
|
228
278
|
return !(0, exports.contains)(right, leftTerm);
|
|
229
279
|
case types_1.BinaryOperator.exactlyMatches:
|
|
230
|
-
return left === right || (0,
|
|
280
|
+
return left === right || (0, exports.isDeepEqual)(left, right);
|
|
231
281
|
case types_1.BinaryOperator.doesNotExactlyMatch:
|
|
232
|
-
return !(left === right || (0,
|
|
282
|
+
return !(left === right || (0, exports.isDeepEqual)(left, right));
|
|
233
283
|
case types_1.BinaryOperator.startsWith:
|
|
234
284
|
return `${right}`.startsWith(`${left}`);
|
|
235
285
|
case types_1.BinaryOperator.doesNotStartWith:
|
|
@@ -239,11 +289,11 @@ const evaluate = (expression) => {
|
|
|
239
289
|
case types_1.BinaryOperator.doesNotEndWith:
|
|
240
290
|
return !`${right}`.endsWith(`${left}`);
|
|
241
291
|
case types_1.BinaryOperator.dateTimeAfter:
|
|
242
|
-
return (0,
|
|
292
|
+
return (0, exports.dateIsAfter)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
243
293
|
case types_1.BinaryOperator.dateTimeBefore:
|
|
244
|
-
return (0,
|
|
294
|
+
return (0, exports.dateIsBefore)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
245
295
|
case types_1.BinaryOperator.dateTimeSame:
|
|
246
|
-
return (0,
|
|
296
|
+
return (0, exports.dateIsEqual)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
|
|
247
297
|
default:
|
|
248
298
|
throw new Error(`Invalid operator: '${operator}'`);
|
|
249
299
|
}
|
|
@@ -494,9 +494,11 @@ const generateTriggerPerformFn = (componentRef, onTrigger) => {
|
|
|
494
494
|
// @ts-expect-error: _components isn't part of the public API
|
|
495
495
|
const { _components } = context;
|
|
496
496
|
const invokeTrigger = _components.invokeTrigger;
|
|
497
|
-
return yield invokeTrigger(invokeTriggerComponentInput(componentRef, onTrigger, "perform"), context, payload, params);
|
|
497
|
+
return yield invokeTrigger(invokeTriggerComponentInput(componentRef, onTrigger, "perform"), Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), payload, params);
|
|
498
498
|
})
|
|
499
|
-
:
|
|
499
|
+
: (context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
500
|
+
return yield onTrigger(Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), payload, params);
|
|
501
|
+
});
|
|
500
502
|
return performFn;
|
|
501
503
|
};
|
|
502
504
|
/** Generates a wrapper function that calls an existing component's onInstanceDeploy
|
|
@@ -509,14 +511,19 @@ const generateOnInstanceWrapperFn = (componentRef, onTrigger, eventName, customF
|
|
|
509
511
|
// @ts-expect-error: _components isn't part of the public API
|
|
510
512
|
const { _components } = context;
|
|
511
513
|
const invokeTrigger = _components.invokeTrigger;
|
|
512
|
-
const invokeResponse = (yield invokeTrigger(invokeTriggerComponentInput(componentRef, onTrigger, eventName), context, null, params)) || {};
|
|
514
|
+
const invokeResponse = (yield invokeTrigger(invokeTriggerComponentInput(componentRef, onTrigger, eventName), Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), null, params)) || {};
|
|
513
515
|
let customResponse = {};
|
|
514
516
|
if (customFn) {
|
|
515
|
-
customResponse =
|
|
517
|
+
customResponse =
|
|
518
|
+
(yield customFn(Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), params)) || {};
|
|
516
519
|
}
|
|
517
520
|
return (0, merge_1.default)(invokeResponse, customResponse);
|
|
518
521
|
})
|
|
519
|
-
:
|
|
522
|
+
: (context, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
523
|
+
if (customFn) {
|
|
524
|
+
return yield customFn(Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), params);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
520
527
|
return onInstanceFn;
|
|
521
528
|
};
|
|
522
529
|
const convertOnExecution = (onExecution, componentRegistry) => (context, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -546,7 +553,7 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
|
|
|
546
553
|
},
|
|
547
554
|
// older versions of manifests did not contain action.key so we fall back to the registry key
|
|
548
555
|
key: (_a = action.key) !== null && _a !== void 0 ? _a : registryActionKey,
|
|
549
|
-
}, context, transformedValues);
|
|
556
|
+
}, Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), transformedValues);
|
|
550
557
|
});
|
|
551
558
|
return Object.assign(Object.assign({}, actionsAccumulator), { [registryActionKey]: invokeAction });
|
|
552
559
|
}, {});
|
|
@@ -94,7 +94,7 @@ const createInvokePollAction = (context, action, { errorHandler }) => {
|
|
|
94
94
|
* Running clean twice can have unwanted behavior depending on how users have implemented
|
|
95
95
|
* their clean functions.
|
|
96
96
|
*/
|
|
97
|
-
return yield action.perform(context, params);
|
|
97
|
+
return yield action.perform(Object.assign(Object.assign({}, context), { debug: (0, context_1.createDebugContext)(context) }), params);
|
|
98
98
|
}
|
|
99
99
|
catch (error) {
|
|
100
100
|
throw errorHandler ? errorHandler(error) : error;
|
|
@@ -122,6 +122,7 @@ const createPollingPerform = (trigger, { inputCleaners, errorHandler }) => {
|
|
|
122
122
|
context.instanceState.__prismaticInternal = Object.assign(Object.assign({}, castState), { polling: newState });
|
|
123
123
|
},
|
|
124
124
|
},
|
|
125
|
+
debug: (0, context_1.createDebugContext)(context),
|
|
125
126
|
};
|
|
126
127
|
const triggerPerform = (0, exports.createPerform)(trigger.perform, {
|
|
127
128
|
inputCleaners,
|
package/dist/types/Inputs.d.ts
CHANGED
|
@@ -87,8 +87,6 @@ interface BaseInputField {
|
|
|
87
87
|
example?: string;
|
|
88
88
|
/** Indicate if this InputField is required. */
|
|
89
89
|
required?: boolean;
|
|
90
|
-
/** Key of the data source that can be used to set the value of this input. */
|
|
91
|
-
dataSource?: string;
|
|
92
90
|
}
|
|
93
91
|
type CollectionOptions<T> = SingleValue<T> | ValueListCollection<T> | KeyValueListCollection<T>;
|
|
94
92
|
interface SingleValue<T> {
|
package/package.json
CHANGED