@tellescope/validation 1.3.36 → 1.3.38

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tellescope/validation",
3
- "version": "1.3.36",
3
+ "version": "1.3.38",
4
4
  "description": "Input validation functions for server, client, and schema definition",
5
5
  "main": "./lib/cjs/validation.js",
6
6
  "module": "./lib/esm/validation.js",
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "homepage": "https://github.com/tellescope-os/tellescope#readme",
25
25
  "dependencies": {
26
- "@tellescope/constants": "^1.3.36",
27
- "@tellescope/types-client": "^1.3.36",
28
- "@tellescope/types-models": "^1.3.36",
26
+ "@tellescope/constants": "^1.3.38",
27
+ "@tellescope/types-client": "^1.3.38",
28
+ "@tellescope/types-models": "^1.3.38",
29
29
  "@tellescope/types-utilities": "^1.3.20",
30
- "@tellescope/utilities": "^1.3.36",
30
+ "@tellescope/utilities": "^1.3.38",
31
31
  "validator": "^13.5.2"
32
32
  },
33
33
  "devDependencies": {
@@ -44,6 +44,6 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "a4de21cffb8afc24bb354cb37c27537b893d65f2",
47
+ "gitHead": "672f374369cbffaf534e9676c5402c25cdb118d8",
48
48
  "composite": true
49
49
  }
package/src/validation.ts CHANGED
@@ -124,8 +124,13 @@ import {
124
124
  BlockContentH2,
125
125
  PortalSettings,
126
126
  BlockContentPDF,
127
+ DatabaseRecordFieldType,
128
+ DatabaseRecordFields,
129
+ DatabaseRecordValues,
130
+ DatabaseRecordField,
127
131
  } from "@tellescope/types-models"
128
132
  import {
133
+ DatabaseRecord,
129
134
  UserDisplayInfo,
130
135
  } from "@tellescope/types-client"
131
136
 
@@ -1679,4 +1684,54 @@ export const BLOCK_TYPES = Object.keys(_BLOCK_TYPES) as BlockType[]
1679
1684
  export const blockTypeValidator = exactMatchValidator<BlockType>(BLOCK_TYPES)
1680
1685
  export const is_block_type = (type: any): type is BlockType => BLOCK_TYPES.includes(type)
1681
1686
 
1682
- export const blocksValidator = listValidatorEmptyOk(blockValidator())
1687
+ export const blocksValidator = listValidatorEmptyOk(blockValidator())
1688
+
1689
+
1690
+ const _DATABASE_RECORD_FIELD_TYPES: { [K in DatabaseRecordFieldType]: any } = {
1691
+ "string-long": '',
1692
+ number: '',
1693
+ string: '',
1694
+ }
1695
+ export const DATABASE_RECORD_FIELD_TYPES = Object.keys(_DATABASE_RECORD_FIELD_TYPES) as DatabaseRecordFieldType[]
1696
+ export const databaseRecordFieldTypeValidator = exactMatchValidator<DatabaseRecordFieldType>(DATABASE_RECORD_FIELD_TYPES)
1697
+ export const is_database_record_field_type = (type: any): type is DatabaseRecordFieldType => DATABASE_RECORD_FIELD_TYPES.includes(type)
1698
+
1699
+ // structure in this way to support potential differences in the future, like options which apply to only specific types
1700
+ // export const databaseFieldValidator = orValidator<{ [K in DatabaseRecordFieldType]: DatabaseRecordFields[K] } >({
1701
+ // string: objectValidator<DatabaseRecordFields['string']>({
1702
+ // type: exactMatchValidator(['string'])(),
1703
+ // label: stringValidator250(),
1704
+ // })(),
1705
+ // 'string-long': objectValidator<DatabaseRecordFields['string-long']>({
1706
+ // type: exactMatchValidator(['string-long'])(),
1707
+ // label: stringValidator250(),
1708
+ // })(),
1709
+ // 'number': objectValidator<DatabaseRecordFields['number']>({
1710
+ // type: exactMatchValidator(['number'])(),
1711
+ // label: stringValidator250(),
1712
+ // })(),
1713
+ // })
1714
+
1715
+ // structure as above instead if need unique label or additional config based on type
1716
+ export const databaseFieldValidator = objectValidator<DatabaseRecordField>({
1717
+ type: databaseRecordFieldTypeValidator(),
1718
+ label: stringValidator250(),
1719
+ })
1720
+ export const databaseFieldsValidator = listValidator(databaseFieldValidator())
1721
+
1722
+
1723
+ export const databaseRecordValueValidator = orValidator<{ [K in DatabaseRecordFieldType]: DatabaseRecordValues[K] } >({
1724
+ string: objectValidator<DatabaseRecordValues['string']>({
1725
+ type: exactMatchValidator(['string'])(),
1726
+ value: stringValidator1000(),
1727
+ })(),
1728
+ 'string-long': objectValidator<DatabaseRecordValues['string-long']>({
1729
+ type: exactMatchValidator(['string-long'])(),
1730
+ value: stringValidator5000(),
1731
+ })(),
1732
+ 'number': objectValidator<DatabaseRecordValues['number']>({
1733
+ type: exactMatchValidator(['number'])(),
1734
+ value: numberValidator(),
1735
+ })(),
1736
+ })
1737
+ export const databaseRecordValuesValidator = listValidator(databaseRecordValueValidator())