lucid-extension-sdk 0.0.378 → 0.0.379
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/core/data/datasource/serializedimporteddatasource.d.ts +7 -7
- package/core/data/serializedfield/serializeddataitems.d.ts +1 -1
- package/core/data/serializedfield/serializedfields.d.ts +1 -1
- package/core/pruners/pruners.d.ts +8 -0
- package/core/pruners/pruners.js +23 -3
- package/core/validators/validators.d.ts +9 -2
- package/core/validators/validators.js +15 -4
- package/dataconnector/actions/serializedpatchtypes.d.ts +4 -4
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ export interface SerializedImportedMetadataCollection {
|
|
|
13
13
|
export declare const isSerializedImportedMetadataCollection: (subject: unknown) => subject is import("../../guards").DestructureGuardedTypeObj<{
|
|
14
14
|
Name: typeof isString;
|
|
15
15
|
Schema: typeof isSerializedSchema;
|
|
16
|
-
Items: (x: unknown) => x is Record<
|
|
16
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
17
17
|
}>;
|
|
18
18
|
/** @ignore until spreadsheet integration is ready for launch (CHART-51946) */
|
|
19
19
|
export interface SerializedImportedCollection {
|
|
@@ -32,12 +32,12 @@ export interface SerializedImportedCollection {
|
|
|
32
32
|
export declare const isSerializedImportedCollection: (subject: unknown) => subject is import("../../guards").DestructureGuardedTypeObj<{
|
|
33
33
|
Name: typeof isString;
|
|
34
34
|
Schema: typeof isSerializedSchema;
|
|
35
|
-
Items: (x: unknown) => x is Record<
|
|
35
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
36
36
|
UpstreamConfig: typeof isObject;
|
|
37
37
|
Metadata: (val: unknown) => val is Record<string, import("../../guards").DestructureGuardedTypeObj<{
|
|
38
38
|
Name: typeof isString;
|
|
39
39
|
Schema: typeof isSerializedSchema;
|
|
40
|
-
Items: (x: unknown) => x is Record<
|
|
40
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
41
41
|
}>>;
|
|
42
42
|
DataIsPartial: (x: unknown) => x is true | undefined;
|
|
43
43
|
}>;
|
|
@@ -69,12 +69,12 @@ export declare const isSerializedImportedDataSource: (subject: unknown) => subje
|
|
|
69
69
|
Collections: (val: unknown) => val is import("../../guards").DestructureGuardedTypeObj<{
|
|
70
70
|
Name: typeof isString;
|
|
71
71
|
Schema: typeof isSerializedSchema;
|
|
72
|
-
Items: (x: unknown) => x is Record<
|
|
72
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
73
73
|
UpstreamConfig: typeof isObject;
|
|
74
74
|
Metadata: (val: unknown) => val is Record<string, import("../../guards").DestructureGuardedTypeObj<{
|
|
75
75
|
Name: typeof isString;
|
|
76
76
|
Schema: typeof isSerializedSchema;
|
|
77
|
-
Items: (x: unknown) => x is Record<
|
|
77
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
78
78
|
}>>;
|
|
79
79
|
DataIsPartial: (x: unknown) => x is true | undefined;
|
|
80
80
|
}>[];
|
|
@@ -109,12 +109,12 @@ export declare const isSerializedPreviewData: (subject: unknown) => subject is i
|
|
|
109
109
|
Data: (subject: unknown) => subject is import("../../guards").DestructureGuardedTypeObj<{
|
|
110
110
|
Name: typeof isString;
|
|
111
111
|
Schema: typeof isSerializedSchema;
|
|
112
|
-
Items: (x: unknown) => x is Record<
|
|
112
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
113
113
|
UpstreamConfig: typeof isObject;
|
|
114
114
|
Metadata: (val: unknown) => val is Record<string, import("../../guards").DestructureGuardedTypeObj<{
|
|
115
115
|
Name: typeof isString;
|
|
116
116
|
Schema: typeof isSerializedSchema;
|
|
117
|
-
Items: (x: unknown) => x is Record<
|
|
117
|
+
Items: (x: unknown) => x is Record<string | number, Record<string | number, import("../serializedfield/serializedfields").SerializedFieldType>>;
|
|
118
118
|
}>>;
|
|
119
119
|
DataIsPartial: (x: unknown) => x is true | undefined;
|
|
120
120
|
}>;
|
|
@@ -2,4 +2,4 @@ import { SerializedFields } from './serializedfields';
|
|
|
2
2
|
export interface SerializedDataItems {
|
|
3
3
|
[primaryKey: string]: SerializedFields;
|
|
4
4
|
}
|
|
5
|
-
export declare const isSerializedDataItems: (x: unknown) => x is Record<
|
|
5
|
+
export declare const isSerializedDataItems: (x: unknown) => x is Record<string | number, Record<string | number, import("./serializedfields").SerializedFieldType>>;
|
|
@@ -115,4 +115,4 @@ export declare const isSerializedTimeObject: (subject: unknown) => subject is im
|
|
|
115
115
|
}>;
|
|
116
116
|
export declare function isSerializedFieldType(value: any): value is SerializedFieldType;
|
|
117
117
|
export declare function isSerializedJsonFieldType(value: any): value is SerializedJsonFieldType;
|
|
118
|
-
export declare const isSerializedFields: (x: unknown) => x is Record<
|
|
118
|
+
export declare const isSerializedFields: (x: unknown) => x is Record<string | number, SerializedFieldType>;
|
|
@@ -10,6 +10,14 @@ import { Pruner } from '../guards';
|
|
|
10
10
|
export declare function objectPruner(subPruners: {
|
|
11
11
|
[key: string]: Pruner;
|
|
12
12
|
}): Pruner;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a pruner function that will set ALL object fields that are invalid to undefined.
|
|
15
|
+
* Use this pruner when an object's key names are not known ahead of time (e.g. UUIDs as object key names).
|
|
16
|
+
* @param subPruner the pruner to be used on the object fields
|
|
17
|
+
* @returns A pruner function that takes data and invalid fields. If data is not an
|
|
18
|
+
* object, it will return the data as is instead of pruning.
|
|
19
|
+
*/
|
|
20
|
+
export declare function objectOfPruner(subPruner: Pruner): Pruner;
|
|
13
21
|
/**
|
|
14
22
|
* Creates a pruner function that will remove array elements that are invalid.
|
|
15
23
|
* If a sub-pruner is provided, then the elements themselves will be pruned rather
|
package/core/pruners/pruners.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pruneObjectField = exports.arrayPruner = exports.objectPruner = void 0;
|
|
3
|
+
exports.pruneObjectField = exports.arrayPruner = exports.objectOfPruner = exports.objectPruner = void 0;
|
|
4
4
|
const checks_1 = require("../checks");
|
|
5
5
|
/**
|
|
6
6
|
* Creates a pruner function that will remove object fields that are invalid.
|
|
@@ -23,6 +23,26 @@ function objectPruner(subPruners) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
exports.objectPruner = objectPruner;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a pruner function that will set ALL object fields that are invalid to undefined.
|
|
28
|
+
* Use this pruner when an object's key names are not known ahead of time (e.g. UUIDs as object key names).
|
|
29
|
+
* @param subPruner the pruner to be used on the object fields
|
|
30
|
+
* @returns A pruner function that takes data and invalid fields. If data is not an
|
|
31
|
+
* object, it will return the data as is instead of pruning.
|
|
32
|
+
*/
|
|
33
|
+
function objectOfPruner(subPruner) {
|
|
34
|
+
return (data, invalidFields, level = 0) => {
|
|
35
|
+
if ((0, checks_1.isArray)(data) || !(0, checks_1.isObjectUnsafe)(data)) {
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
const dataToBePruned = Object.assign({}, data);
|
|
39
|
+
Object.entries(dataToBePruned).forEach(([key, value]) => {
|
|
40
|
+
dataToBePruned[key] = subPruner(dataToBePruned[key], invalidFields, level + 1, key);
|
|
41
|
+
});
|
|
42
|
+
return dataToBePruned;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.objectOfPruner = objectOfPruner;
|
|
26
46
|
/**
|
|
27
47
|
* Creates a pruner function that will remove array elements that are invalid.
|
|
28
48
|
* If a sub-pruner is provided, then the elements themselves will be pruned rather
|
|
@@ -58,12 +78,12 @@ function arrayPruner(subPruner) {
|
|
|
58
78
|
}
|
|
59
79
|
exports.arrayPruner = arrayPruner;
|
|
60
80
|
/*
|
|
61
|
-
* Creates a pruner function to be passed in with the object pruner that will remove the field if it is invalid.
|
|
81
|
+
* Creates a pruner function to be passed in with the object/objectOf pruner that will remove the field if it is invalid.
|
|
62
82
|
*/
|
|
63
83
|
function pruneObjectField() {
|
|
64
84
|
return (data, invalidFields, level = 0, key = undefined) => {
|
|
65
85
|
var _a;
|
|
66
|
-
// When this is called as a part of objectPruner, level will be atleast 1
|
|
86
|
+
// When this is called as a part of objectPruner/objectOfPruner, level will be atleast 1
|
|
67
87
|
if ((0, checks_1.isArray)(data) || level <= 0) {
|
|
68
88
|
return data;
|
|
69
89
|
}
|
|
@@ -103,12 +103,19 @@ export declare function strictObjectValidator<T extends {
|
|
|
103
103
|
}>(validatorStructure: T): (subject: unknown) => subject is DestructureGuardedTypeObj<T>;
|
|
104
104
|
export declare function recordValidator<K extends string, V>(keyList: K[], valueValidator: Validator<V>): (x: unknown) => x is Record<K, V>;
|
|
105
105
|
export declare function typedRecordValidator<K extends string | number | symbol, V>(keyValidator: Validator<K>, valueValidator: Validator<V>): (x: unknown) => x is Record<K, V>;
|
|
106
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Validates a structure that is an object of a specific type (defined by the subValidator).
|
|
108
|
+
* @param valueValidator The validator to be used on the object fields
|
|
109
|
+
* @param keyValidator Optional validator to be used on the object keys. If not provided, all key types are validated.
|
|
110
|
+
*/
|
|
111
|
+
export declare function objectOfValidator<T, K extends string | number | symbol = string>(valueValidator: Validator<T>, keyValidator?: Validator<K>): (x: unknown) => x is Record<K, T>;
|
|
107
112
|
/**
|
|
108
113
|
* This validator functions the same as {@link objectOfValidator}, with the option of passing in a map
|
|
109
114
|
* which will track all of the fields that were found to be invalid.
|
|
115
|
+
* @param valueValidator The validator to be used on the object fields
|
|
116
|
+
* @param keyValidator Optional validator to be used on the object keys. If not provided, keys are not validated and asserted to be strings.
|
|
110
117
|
*/
|
|
111
|
-
export declare function objectOfValidatorWithInvalidFieldTracking<T>(
|
|
118
|
+
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>;
|
|
112
119
|
/**
|
|
113
120
|
* Create a validator which allows the target to be either null or satisfy the
|
|
114
121
|
* sub-validator.
|
|
@@ -254,20 +254,29 @@ function typedRecordValidator(keyValidator, valueValidator) {
|
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
256
|
exports.typedRecordValidator = typedRecordValidator;
|
|
257
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Validates a structure that is an object of a specific type (defined by the subValidator).
|
|
259
|
+
* @param valueValidator The validator to be used on the object fields
|
|
260
|
+
* @param keyValidator Optional validator to be used on the object keys. If not provided, all key types are validated.
|
|
261
|
+
*/
|
|
262
|
+
function objectOfValidator(valueValidator, keyValidator = (key) => true) {
|
|
258
263
|
return (x) => {
|
|
259
264
|
if ((0, checks_1.isArray)(x) || !(0, checks_1.isObject)(x)) {
|
|
260
265
|
return false;
|
|
261
266
|
}
|
|
262
|
-
return Object.
|
|
267
|
+
return Object.entries(x).every(([key, val]) => {
|
|
268
|
+
return keyValidator(key) && valueValidator(val);
|
|
269
|
+
});
|
|
263
270
|
};
|
|
264
271
|
}
|
|
265
272
|
exports.objectOfValidator = objectOfValidator;
|
|
266
273
|
/**
|
|
267
274
|
* This validator functions the same as {@link objectOfValidator}, with the option of passing in a map
|
|
268
275
|
* which will track all of the fields that were found to be invalid.
|
|
276
|
+
* @param valueValidator The validator to be used on the object fields
|
|
277
|
+
* @param keyValidator Optional validator to be used on the object keys. If not provided, keys are not validated and asserted to be strings.
|
|
269
278
|
*/
|
|
270
|
-
function objectOfValidatorWithInvalidFieldTracking(
|
|
279
|
+
function objectOfValidatorWithInvalidFieldTracking(valueValidator, keyValidator = (key) => true) {
|
|
271
280
|
return (subject, invalidFields, level = 0) => {
|
|
272
281
|
var _a;
|
|
273
282
|
if ((0, checks_1.isArray)(subject) || !(0, checks_1.isObjectUnsafe)(subject)) {
|
|
@@ -276,7 +285,9 @@ function objectOfValidatorWithInvalidFieldTracking(subValidator) {
|
|
|
276
285
|
let valid = true;
|
|
277
286
|
const invalidList = [];
|
|
278
287
|
Object.entries(subject).forEach(([key, val]) => {
|
|
279
|
-
|
|
288
|
+
const isKeyValid = keyValidator(key, invalidFields, level + 1);
|
|
289
|
+
const isValueValid = valueValidator(val, invalidFields, level + 1);
|
|
290
|
+
if (!isKeyValid || !isValueValid) {
|
|
280
291
|
invalidList.push([key, val]);
|
|
281
292
|
valid = false;
|
|
282
293
|
}
|
|
@@ -2,10 +2,10 @@ import { isString, isUnknown } from '../../core/checks';
|
|
|
2
2
|
import { isSerializedFieldTypeDefinition } from '../../core/data/fieldtypedefinition/fieldtypedefinition';
|
|
3
3
|
import { GuardToType } from '../../core/guards';
|
|
4
4
|
export declare const patchItemValidator: (subject: unknown) => subject is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
5
|
-
itemsAdded: (x: unknown) => x is Record<
|
|
5
|
+
itemsAdded: (x: unknown) => x is Record<string, {
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}>;
|
|
8
|
-
itemsChanged: (x: unknown) => x is Record<
|
|
8
|
+
itemsChanged: (x: unknown) => x is Record<string, {
|
|
9
9
|
[key: string]: unknown;
|
|
10
10
|
}>;
|
|
11
11
|
itemsDeleted: (p1: unknown) => p1 is string[];
|
|
@@ -43,10 +43,10 @@ export declare const patchSchemaValidator: (subject: unknown) => subject is impo
|
|
|
43
43
|
}>;
|
|
44
44
|
export type SerializedSchemaPatch = GuardToType<typeof patchSchemaValidator>;
|
|
45
45
|
export declare const patchValidator: (x: unknown) => x is import("../../core/guards").DestructureGuardedTypeObj<{
|
|
46
|
-
itemsAdded: (x: unknown) => x is Record<
|
|
46
|
+
itemsAdded: (x: unknown) => x is Record<string, {
|
|
47
47
|
[key: string]: unknown;
|
|
48
48
|
}>;
|
|
49
|
-
itemsChanged: (x: unknown) => x is Record<
|
|
49
|
+
itemsChanged: (x: unknown) => x is Record<string, {
|
|
50
50
|
[key: string]: unknown;
|
|
51
51
|
}>;
|
|
52
52
|
itemsDeleted: (p1: unknown) => p1 is string[];
|