@dataloop-ai/components 0.19.155 → 0.19.156
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/package.json
CHANGED
|
@@ -213,6 +213,10 @@ export default defineComponent({
|
|
|
213
213
|
type: Array as PropType<string[]>,
|
|
214
214
|
default: () => [] as string[]
|
|
215
215
|
},
|
|
216
|
+
forbiddenKeys: {
|
|
217
|
+
type: Array as PropType<string[]>,
|
|
218
|
+
default: () => [] as string[]
|
|
219
|
+
},
|
|
216
220
|
strict: {
|
|
217
221
|
type: Boolean,
|
|
218
222
|
default: false
|
|
@@ -245,7 +249,8 @@ export default defineComponent({
|
|
|
245
249
|
schema,
|
|
246
250
|
omitSuggestions,
|
|
247
251
|
height,
|
|
248
|
-
width
|
|
252
|
+
width,
|
|
253
|
+
forbiddenKeys
|
|
249
254
|
} = toRefs(props)
|
|
250
255
|
//#endregion
|
|
251
256
|
|
|
@@ -269,7 +274,7 @@ export default defineComponent({
|
|
|
269
274
|
// todo: these can be stale data. we need to update them on schema change.
|
|
270
275
|
const { hasEllipsis } = useSizeObserver(input)
|
|
271
276
|
const { suggestions, error, findSuggestions, checkErrors } =
|
|
272
|
-
useSuggestions(schema, aliases, { strict, omitSuggestions })
|
|
277
|
+
useSuggestions(schema, aliases, { strict, forbiddenKeys, omitSuggestions })
|
|
273
278
|
//#endregion
|
|
274
279
|
|
|
275
280
|
//#region methods
|
|
@@ -490,7 +495,7 @@ export default defineComponent({
|
|
|
490
495
|
}
|
|
491
496
|
|
|
492
497
|
if (cancelBlur.value === 0) {
|
|
493
|
-
if (showSuggestions.value) {
|
|
498
|
+
if (showSuggestions.value && computedStatus.value.type !== 'error') {
|
|
494
499
|
focused.value = true
|
|
495
500
|
return
|
|
496
501
|
}
|
|
@@ -123,9 +123,9 @@ const mergeWords = (words: string[]) => {
|
|
|
123
123
|
export const useSuggestions = (
|
|
124
124
|
schema: Ref<Schema>,
|
|
125
125
|
aliases: Ref<Alias[]>,
|
|
126
|
-
options: { strict?: Ref<boolean>; omitSuggestions?: Ref<string[]> } = {}
|
|
126
|
+
options: { strict?: Ref<boolean>; forbiddenKeys?: Ref<string[]>; omitSuggestions?: Ref<string[]> } = {}
|
|
127
127
|
) => {
|
|
128
|
-
const { strict, omitSuggestions } = options
|
|
128
|
+
const { strict, forbiddenKeys, omitSuggestions } = options
|
|
129
129
|
const aliasesArray = aliases.value ?? []
|
|
130
130
|
const schemaValue = schema.value ?? {}
|
|
131
131
|
|
|
@@ -159,7 +159,7 @@ export const useSuggestions = (
|
|
|
159
159
|
const expressions = mapWordsToExpressions(mergedWords)
|
|
160
160
|
|
|
161
161
|
error.value = input.length
|
|
162
|
-
? getError(schemaValue, aliasesArray, expressions, { strict })
|
|
162
|
+
? getError(schemaValue, aliasesArray, expressions, { strict, forbiddenKeys })
|
|
163
163
|
: null
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -329,7 +329,8 @@ export const useSuggestions = (
|
|
|
329
329
|
|
|
330
330
|
const errors = {
|
|
331
331
|
INVALID_EXPRESSION: 'Invalid Expression',
|
|
332
|
-
INVALID_VALUE: (field: string) => `Invalid value for "${field}" field
|
|
332
|
+
INVALID_VALUE: (field: string) => `Invalid value for "${field}" field`,
|
|
333
|
+
FORBIDDEN_KEY: (field: string) => `Forbidden field "${field}"`
|
|
333
334
|
}
|
|
334
335
|
|
|
335
336
|
const isInputAllowed = (input: string, allowedKeys: string[]): boolean => {
|
|
@@ -361,9 +362,9 @@ const getError = (
|
|
|
361
362
|
schema: Schema,
|
|
362
363
|
aliases: Alias[],
|
|
363
364
|
expressions: Expression[],
|
|
364
|
-
options: { strict?: Ref<boolean
|
|
365
|
+
options: { strict?: Ref<boolean>; forbiddenKeys?: Ref<string[]>; } = {}
|
|
365
366
|
): string | null => {
|
|
366
|
-
const { strict } = options
|
|
367
|
+
const { strict, forbiddenKeys } = options
|
|
367
368
|
const hasErrorInStructure = expressions
|
|
368
369
|
.flatMap((exp) => Object.values(exp))
|
|
369
370
|
.some((el, index, arr) => {
|
|
@@ -378,7 +379,7 @@ const getError = (
|
|
|
378
379
|
return expressions
|
|
379
380
|
.filter(({ field, value }) => field !== null && value !== null)
|
|
380
381
|
.reduce<string | null>((acc, { field, value, operator }, _, arr) => {
|
|
381
|
-
if (acc
|
|
382
|
+
if (acc && acc !== 'warning') return acc
|
|
382
383
|
const fieldKey: string =
|
|
383
384
|
getAliasObjByAlias(aliases, field)?.key ?? field
|
|
384
385
|
|
|
@@ -409,14 +410,21 @@ const getError = (
|
|
|
409
410
|
return false
|
|
410
411
|
}
|
|
411
412
|
|
|
412
|
-
const pattern = new RegExp(
|
|
413
|
+
const pattern = new RegExp(`^${fieldKey}\\.\\d`)
|
|
413
414
|
const isValid = isInputAllowed(fieldKey, keys)
|
|
415
|
+
const isForbidden = !!forbiddenKeys?.value?.includes(fieldKey)
|
|
414
416
|
if (
|
|
415
417
|
!keys.includes(fieldKey) &&
|
|
416
418
|
!hasValidExpression(keys, pattern) &&
|
|
417
|
-
!isValid
|
|
419
|
+
!isValid &&
|
|
420
|
+
!isForbidden
|
|
418
421
|
) {
|
|
419
|
-
return strict
|
|
422
|
+
return strict?.value ? errors.INVALID_EXPRESSION : 'warning'
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (isForbidden) {
|
|
426
|
+
arr.splice(1)
|
|
427
|
+
return (acc = errors.FORBIDDEN_KEY(field))
|
|
420
428
|
}
|
|
421
429
|
|
|
422
430
|
const valid = isValidByDataType(
|
|
@@ -430,7 +438,7 @@ const getError = (
|
|
|
430
438
|
return (acc = errors.INVALID_VALUE(field))
|
|
431
439
|
}
|
|
432
440
|
|
|
433
|
-
return (acc = null)
|
|
441
|
+
return (acc === 'warning' ? acc : acc = null)
|
|
434
442
|
}, null)
|
|
435
443
|
}
|
|
436
444
|
|