lucid-extension-sdk
Advanced tools
Comparing version
@@ -16,3 +16,3 @@ import { isObject, isString } from '../../checks'; | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
}>; | ||
@@ -36,3 +36,3 @@ /** @ignore until spreadsheet integration is ready for launch (CHART-51946) */ | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
UpstreamConfig: typeof isObject; | ||
@@ -42,3 +42,3 @@ Metadata: (val: unknown) => val is Record<string, import("../../guards").DestructureGuardedTypeObj<{ | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
}>>; | ||
@@ -75,3 +75,3 @@ DataIsPartial: (x: unknown) => x is true | undefined; | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
UpstreamConfig: typeof isObject; | ||
@@ -81,3 +81,3 @@ Metadata: (val: unknown) => val is Record<string, import("../../guards").DestructureGuardedTypeObj<{ | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
}>>; | ||
@@ -117,3 +117,3 @@ DataIsPartial: (x: unknown) => x is true | undefined; | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
UpstreamConfig: typeof isObject; | ||
@@ -123,3 +123,3 @@ Metadata: (val: unknown) => val is Record<string, import("../../guards").DestructureGuardedTypeObj<{ | ||
Schema: typeof isSerializedSchema; | ||
Items: (x: unknown) => x is Record<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>; | ||
}>>; | ||
@@ -126,0 +126,0 @@ DataIsPartial: (x: unknown) => x is true | undefined; |
@@ -5,2 +5,2 @@ import { SerializedFields } from './serializedfields'; | ||
} | ||
export declare const isSerializedDataItems: (x: unknown) => x is Record<any, Record<any, import("./serializedfields").SerializedFieldType>>; | ||
export declare const isSerializedDataItems: (x: unknown) => x is Record<string | number, Record<string | number, import("./serializedfields").SerializedFieldType>>; |
@@ -118,2 +118,2 @@ import { isNumber, isString } from '../../checks'; | ||
export declare function isSerializedJsonFieldType(value: any): value is SerializedJsonFieldType; | ||
export declare const isSerializedFields: (x: unknown) => x is Record<any, SerializedFieldType>; | ||
export declare const isSerializedFields: (x: unknown) => x is Record<string | number, SerializedFieldType>; |
@@ -14,2 +14,10 @@ import { Pruner } from '../guards'; | ||
/** | ||
* Creates a pruner function that will set ALL object fields that are invalid to undefined. | ||
* Use this pruner when an object's key names are not known ahead of time (e.g. UUIDs as object key names). | ||
* @param subPruner the pruner to be used on the object fields | ||
* @returns A pruner function that takes data and invalid fields. If data is not an | ||
* object, it will return the data as is instead of pruning. | ||
*/ | ||
export declare function objectOfPruner(subPruner: Pruner): Pruner; | ||
/** | ||
* Creates a pruner function that will remove array elements that are invalid. | ||
@@ -16,0 +24,0 @@ * If a sub-pruner is provided, then the elements themselves will be pruned rather |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pruneObjectField = exports.arrayPruner = exports.objectPruner = void 0; | ||
exports.pruneObjectField = exports.arrayPruner = exports.objectOfPruner = exports.objectPruner = void 0; | ||
const checks_1 = require("../checks"); | ||
@@ -27,2 +27,22 @@ /** | ||
/** | ||
* Creates a pruner function that will set ALL object fields that are invalid to undefined. | ||
* Use this pruner when an object's key names are not known ahead of time (e.g. UUIDs as object key names). | ||
* @param subPruner the pruner to be used on the object fields | ||
* @returns A pruner function that takes data and invalid fields. If data is not an | ||
* object, it will return the data as is instead of pruning. | ||
*/ | ||
function objectOfPruner(subPruner) { | ||
return (data, invalidFields, level = 0) => { | ||
if ((0, checks_1.isArray)(data) || !(0, checks_1.isObjectUnsafe)(data)) { | ||
return data; | ||
} | ||
const dataToBePruned = Object.assign({}, data); | ||
Object.entries(dataToBePruned).forEach(([key, value]) => { | ||
dataToBePruned[key] = subPruner(dataToBePruned[key], invalidFields, level + 1, key); | ||
}); | ||
return dataToBePruned; | ||
}; | ||
} | ||
exports.objectOfPruner = objectOfPruner; | ||
/** | ||
* Creates a pruner function that will remove array elements that are invalid. | ||
@@ -62,3 +82,3 @@ * If a sub-pruner is provided, then the elements themselves will be pruned rather | ||
/* | ||
* Creates a pruner function to be passed in with the object pruner that will remove the field if it is invalid. | ||
* Creates a pruner function to be passed in with the object/objectOf pruner that will remove the field if it is invalid. | ||
*/ | ||
@@ -68,3 +88,3 @@ function pruneObjectField() { | ||
var _a; | ||
// When this is called as a part of objectPruner, level will be atleast 1 | ||
// When this is called as a part of objectPruner/objectOfPruner, level will be atleast 1 | ||
if ((0, checks_1.isArray)(data) || level <= 0) { | ||
@@ -71,0 +91,0 @@ return data; |
@@ -106,8 +106,15 @@ import { isNumber, isString } from '../checks'; | ||
export declare function typedRecordValidator<K extends string | number | symbol, V>(keyValidator: Validator<K>, valueValidator: Validator<V>): (x: unknown) => x is Record<K, V>; | ||
export declare function objectOfValidator<T>(subValidator: Validator<T>): (x: unknown) => x is Record<any, T>; | ||
/** | ||
* Validates a structure that is an object of a specific type (defined by the subValidator). | ||
* @param valueValidator The validator to be used on the object fields | ||
* @param keyValidator Optional validator to be used on the object keys. If not provided, all key types are validated. | ||
*/ | ||
export declare function objectOfValidator<T, K extends string | number | symbol = string>(valueValidator: Validator<T>, keyValidator?: Validator<K>): (x: unknown) => x is Record<K, T>; | ||
/** | ||
* This validator functions the same as {@link objectOfValidator}, with the option of passing in a map | ||
* which will track all of the fields that were found to be invalid. | ||
* @param valueValidator The validator to be used on the object fields | ||
* @param keyValidator Optional validator to be used on the object keys. If not provided, keys are not validated and asserted to be strings. | ||
*/ | ||
export declare function objectOfValidatorWithInvalidFieldTracking<T>(subValidator: ValidatorWithTracking<T>): (subject: unknown, invalidFields?: Map<number, unknown[]>, level?: number) => subject is Record<any, T>; | ||
export declare function objectOfValidatorWithInvalidFieldTracking<T, K extends string | number | symbol = string>(valueValidator: ValidatorWithTracking<T>, keyValidator?: ValidatorWithTracking<K>): (subject: unknown, invalidFields?: Map<number, unknown[]>, level?: number) => subject is Record<K, T>; | ||
/** | ||
@@ -114,0 +121,0 @@ * Create a validator which allows the target to be either null or satisfy the |
@@ -257,3 +257,8 @@ "use strict"; | ||
exports.typedRecordValidator = typedRecordValidator; | ||
function objectOfValidator(subValidator) { | ||
/** | ||
* Validates a structure that is an object of a specific type (defined by the subValidator). | ||
* @param valueValidator The validator to be used on the object fields | ||
* @param keyValidator Optional validator to be used on the object keys. If not provided, all key types are validated. | ||
*/ | ||
function objectOfValidator(valueValidator, keyValidator = (key) => true) { | ||
return (x) => { | ||
@@ -263,3 +268,5 @@ if ((0, checks_1.isArray)(x) || !(0, checks_1.isObject)(x)) { | ||
} | ||
return Object.values(x).every((val) => subValidator(val)); | ||
return Object.entries(x).every(([key, val]) => { | ||
return keyValidator(key) && valueValidator(val); | ||
}); | ||
}; | ||
@@ -271,4 +278,6 @@ } | ||
* which will track all of the fields that were found to be invalid. | ||
* @param valueValidator The validator to be used on the object fields | ||
* @param keyValidator Optional validator to be used on the object keys. If not provided, keys are not validated and asserted to be strings. | ||
*/ | ||
function objectOfValidatorWithInvalidFieldTracking(subValidator) { | ||
function objectOfValidatorWithInvalidFieldTracking(valueValidator, keyValidator = (key) => true) { | ||
return (subject, invalidFields, level = 0) => { | ||
@@ -282,3 +291,5 @@ var _a; | ||
Object.entries(subject).forEach(([key, val]) => { | ||
if (!subValidator(val, invalidFields, level + 1)) { | ||
const isKeyValid = keyValidator(key, invalidFields, level + 1); | ||
const isValueValid = valueValidator(val, invalidFields, level + 1); | ||
if (!isKeyValid || !isValueValid) { | ||
invalidList.push([key, val]); | ||
@@ -285,0 +296,0 @@ valid = false; |
@@ -5,6 +5,6 @@ import { isString, isUnknown } from '../../core/checks'; | ||
export declare const patchItemValidator: (subject: unknown) => subject is import("../../core/guards").DestructureGuardedTypeObj<{ | ||
itemsAdded: (x: unknown) => x is Record<any, { | ||
itemsAdded: (x: unknown) => x is Record<string, { | ||
[key: string]: unknown; | ||
}>; | ||
itemsChanged: (x: unknown) => x is Record<any, { | ||
itemsChanged: (x: unknown) => x is Record<string, { | ||
[key: string]: unknown; | ||
@@ -47,6 +47,6 @@ }>; | ||
export declare const patchValidator: (x: unknown) => x is import("../../core/guards").DestructureGuardedTypeObj<{ | ||
itemsAdded: (x: unknown) => x is Record<any, { | ||
itemsAdded: (x: unknown) => x is Record<string, { | ||
[key: string]: unknown; | ||
}>; | ||
itemsChanged: (x: unknown) => x is Record<any, { | ||
itemsChanged: (x: unknown) => x is Record<string, { | ||
[key: string]: unknown; | ||
@@ -53,0 +53,0 @@ }>; |
{ | ||
"name": "lucid-extension-sdk", | ||
"version": "0.0.378", | ||
"version": "0.0.379", | ||
"description": "Utility classes for writing Lucid Software editor extensions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
946124
0.33%21356
0.22%