lucid-extension-sdk 0.0.377 → 0.0.378

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;
@@ -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 ||
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.378",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",