DMNO base types
Primitive types
DMNO comes with a comprehensive set of types to cover the majority of use cases.
These types are used when defining your config schema and can be extended to create more application specific types as needed.
See creating your own types for more on this.
string
DmnoBaseTypes.string({ settingsSchema? })
DMNO Built-in data type for Strings. Includes the following optional settings:
type StringDataTypeSettings = { allowEmpty?: boolean,endsWith?: string,isLength?: number,matches?: RegExp | string,maxLength?: number,minLength?: number,startsWith?: string,toLowerCase?: boolean,toUpperCase?: boolean }
Name | Type | Required | Description |
---|---|---|---|
allowEmpty | boolean | No | allow empty string as a valid string (default is to NOT allow it) |
endsWith | string | No | The required ending substring of the string. |
isLength | number | No | The exact length of the string. |
matches | RegExp | string | No | The regular expression or string pattern that the string must match. |
maxLength | number | No | The maximum length of the string. |
minLength | number | No | The minimum length of the string. |
startsWith | string | No | The required starting substring of the string. |
toLowerCase | boolean | No | converts to lower case |
toUpperCase | boolean | No | converts to upper case |
Examples
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { MY_STRING: DmnoBaseTypes.string({ minLength: 2, maxLength: 5, }), MY_STRING2: DmnoBaseTypes.string({ isLength: 5, }), MY_STRING3: DmnoBaseTypes.string({ startsWith: 'pk_', }), // ... }, // ...});
number
DmnoBaseTypes.number({ settingsSchema? })
DMNO Built-in data type for Numbers. Includes the following optional settings:
type NumberDataTypeSettings = { coerceToMinMaxRange?: boolean,isDivisibleBy?: number,isInt?: boolean,max?: number,min?: number,precision?: number }
Name | Type | Required | Description |
---|---|---|---|
coerceToMinMaxRange | boolean | No | Determines whether the number should be coerced to the minimum or maximum value if it is outside the range. |
isDivisibleBy | number | No | The number that the value must be divisible by. |
isInt | boolean | No | checks if it's an integer |
max | number | No | The maximum value allowed for the number. |
min | number | No | The minimum value allowed for the number. |
precision | number | No | The number of decimal places allowed (for non-integers) |
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { MY_NUMBER: DmnoBaseTypes.number({ min: 2, max: 5, }), // ... }, // ...});
boolean
DmnoBaseTypes.boolean()
DMNO Built-in data type for Booleans.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { MY_BOOLEAN: DmnoBaseTypes.boolean(), // ... }, // ...});
enum
DmnoBaseTypes.Enum({ settingsSchema? })
DMNO Built-in data type for Enums. Includes the following optional settings:
type settingsSchema = { // simple list of values values: Array<string> // array or values with extra metadata | Array< { value: string | number | boolean, description: string }> // object with key value pairs (strings only) | Record<string, string>;};
Example:
const myEnumType = DmnoBaseTypes.Enum({ values: ['one', 'two', 'three'] });const myEnumType2 = DmnoBaseTypes.Enum({ values: [ { value: 'one', description: 'The first one' }, { value: 'two', description: 'The second one' }],});const myEnumType3 = DmnoBaseTypes.Enum( { values: { one: 'The first one', two: 'The second one', }, },);
Composite types
email
DmnoBaseTypes.email({ settingsSchema? })
DMNO Built-in data type for Email addresses.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { EMAIL: DmnoBaseTypes.email({ normalize: true, }), // ... }, // ...});
url
DmnoBaseTypes.url({ settingsSchema? })
DMNO Built-in data type for URLs.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { URL: DmnoBaseTypes.url({ prependProtocol: true, // adds https:// if missing }), // ... }, // ...});
ipAddress
DmnoBaseTypes.ipAddress({ settingsSchema? })
DMNO Built-in data type for IP Addresses.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { IP: DmnoBaseTypes.ipAddress({ version: 4, // or 6 }), // ... }, // ...});
port
DmnoBaseTypes.port({ settingsSchema? })
DMNO Built-in data type for Ports.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { PORT: DmnoBaseTypes.port({ min: 1024, // > 0 max: 49151, // < 65535 }), // ... }, // ...});
semver
DmnoBaseTypes.semver()
DMNO Built-in data type for Semantic Versioning.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { VERSION: DmnoBaseTypes.semver(), // ... }, // ...});
isoDate
DmnoBaseTypes.isoDate()
DMNO Built-in data type for ISO Dates. Ex. 2022-01-01T00:00:00.000Z
.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { DATE: DmnoBaseTypes.isoDate(), // ... }, // ...});
uuid
DmnoBaseTypes.uuid()
DMNO Built-in data type for UUIDs.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { UUID: DmnoBaseTypes.uuid(), // ... }, // ...});
md5
DmnoBaseTypes.md5()
DMNO Built-in data type for MD5 Hashes.
Example:
import { DmnoBaseTypes, defineDmnoService } from 'dmno';
export default defineDmnoService({ name: 'MyConfig', // ... schema: { MD5: DmnoBaseTypes.md5(), // ... }, // ...});
NodeEnvType
DMNO Built-in data type for NODE_ENV
, built using Enum
.
Its definition looks like this:
const NodeEnvType = createDmnoDataType({ extends: DmnoBaseTypes.enum({ development: { description: 'true during local development' }, test: { description: 'true while running tests' }, production: { description: 'true for production' }, }),});
Example:
import { NodeEnvType, defineDmnoService } from 'dmno';// ...
export default defineDmnoService({ name: 'MyConfig', // ... schema: { NODE_ENV: NodeEnvType, // ... }, // ...});