lucid-extension-sdk 0.0.377 → 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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Use this to assert that a type check is exhaustive at build-time. There should never be a code path that reaches this function.
3
+ * @param x the value to assert is never reached
4
+ */
5
+ export declare function assertNever(x: never): never;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNever = void 0;
4
+ /**
5
+ * Use this to assert that a type check is exhaustive at build-time. There should never be a code path that reaches this function.
6
+ * @param x the value to assert is never reached
7
+ */
8
+ function assertNever(x) {
9
+ throw new Error(`Assertion failed! Expected assertNever to not be called, but it was called with parameter ${JSON.stringify(x)}`);
10
+ }
11
+ exports.assertNever = assertNever;
@@ -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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("../serializedfield/serializedfields").SerializedFieldType>>;
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<any, Record<any, import("./serializedfields").SerializedFieldType>>;
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<any, SerializedFieldType>;
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
@@ -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
- export declare function objectOfValidator<T>(subValidator: Validator<T>): (x: unknown) => x is Record<any, T>;
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>(subValidator: ValidatorWithTracking<T>): (subject: unknown, invalidFields?: Map<number, unknown[]>, level?: number) => subject is Record<any, 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
- function objectOfValidator(subValidator) {
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.values(x).every((val) => subValidator(val));
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(subValidator) {
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
- if (!subValidator(val, invalidFields, level + 1)) {
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
  }
@@ -38,6 +38,7 @@ export interface MaxLengthConstraintDefinition {
38
38
  value: number;
39
39
  }
40
40
  export type FieldConstraintDefinition = RequiredFieldConstraintDefinition | LockedFieldConstraintDefinition | MinValueFieldConstraintDefinition | MaxValueFieldConstraintDefinition | SingleLineFieldConstraintDefinition | NoWhitespaceFieldConstraintDefinition | UniqueEditFieldConstraintDefinition | MaxLengthConstraintDefinition;
41
+ export declare function createFieldConstraintDefinition(type: FieldConstraintType, value?: number): FieldConstraintDefinition;
41
42
  export declare function minMaxFieldConstraintValidator(val: unknown): val is FieldConstraintType.MIN_VALUE | FieldConstraintType.MAX_VALUE | FieldConstraintType.MAX_LENGTH;
42
43
  export declare const isFieldConstraintDefinition: (x: unknown) => x is {
43
44
  type?: FieldConstraintType | undefined;
@@ -1,10 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSchemaDefinition = exports.parseFieldDefinition = exports.serializeSchemaDefinition = exports.serializeFieldDefinition = exports.serializeFieldConstraintDefinition = exports.isFieldConstraintDefinition = exports.minMaxFieldConstraintValidator = void 0;
3
+ exports.parseSchemaDefinition = exports.parseFieldDefinition = exports.serializeSchemaDefinition = exports.serializeFieldDefinition = exports.serializeFieldConstraintDefinition = exports.isFieldConstraintDefinition = exports.minMaxFieldConstraintValidator = exports.createFieldConstraintDefinition = void 0;
4
+ const assertnever_1 = require("../core/assertnever");
4
5
  const checks_1 = require("../core/checks");
5
6
  const fieldtypedefinition_1 = require("../core/data/fieldtypedefinition/fieldtypedefinition");
6
7
  const serializedfielddefinition_1 = require("../core/data/serializedfield/serializedfielddefinition");
7
8
  const validators_1 = require("../core/validators/validators");
9
+ function createFieldConstraintDefinition(type, value) {
10
+ switch (type) {
11
+ case serializedfielddefinition_1.FieldConstraintType.REQUIRED:
12
+ case serializedfielddefinition_1.FieldConstraintType.LOCKED:
13
+ return { type };
14
+ case serializedfielddefinition_1.FieldConstraintType.MIN_VALUE:
15
+ case serializedfielddefinition_1.FieldConstraintType.MAX_VALUE:
16
+ case serializedfielddefinition_1.FieldConstraintType.MAX_LENGTH:
17
+ if (value === undefined) {
18
+ throw new Error('Invalid constraint value');
19
+ }
20
+ return { type, value };
21
+ case serializedfielddefinition_1.FieldConstraintType.SINGLE_LINE_ONLY:
22
+ case serializedfielddefinition_1.FieldConstraintType.NO_WHITESPACE:
23
+ case serializedfielddefinition_1.FieldConstraintType.UNIQUE_EDIT:
24
+ if (value !== undefined) {
25
+ throw new Error('Invalid constraint value');
26
+ }
27
+ return { type };
28
+ default:
29
+ (0, assertnever_1.assertNever)(type);
30
+ }
31
+ }
32
+ exports.createFieldConstraintDefinition = createFieldConstraintDefinition;
8
33
  function minMaxFieldConstraintValidator(val) {
9
34
  return (val === serializedfielddefinition_1.FieldConstraintType.MIN_VALUE ||
10
35
  val === serializedfielddefinition_1.FieldConstraintType.MAX_VALUE ||
@@ -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<any, {
5
+ itemsAdded: (x: unknown) => x is Record<string, {
6
6
  [key: string]: unknown;
7
7
  }>;
8
- itemsChanged: (x: unknown) => x is Record<any, {
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<any, {
46
+ itemsAdded: (x: unknown) => x is Record<string, {
47
47
  [key: string]: unknown;
48
48
  }>;
49
- itemsChanged: (x: unknown) => x is Record<any, {
49
+ itemsChanged: (x: unknown) => x is Record<string, {
50
50
  [key: string]: unknown;
51
51
  }>;
52
52
  itemsDeleted: (p1: unknown) => p1 is string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.377",
3
+ "version": "0.0.379",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",