Helper methods
defineDmnoService
defineDmnoService({ opts })
See the service config in the schema guide for more information.
This method is used to define the configuration schema in each of your services, including the root. It takes an object as an argument with the following properties:
Name | Type | Required | Description |
---|---|---|---|
isRoot | boolean | No | MUST be set to true for root service only. |
name | string | No | The name of the workspace. |
parent | string | No | The name of the parent service. |
tags | string[] | No | An array of tags for the service. |
settings | { dynamicConfig: DynamicConfigModes } | No | Settings to apply to the service and as defaults for any children |
pick | Array<PickConfigItemDefinition | string> | No | An array of items to pick from the parent or other service(s). This can be a string (the key) or a PickItemDefinition object. |
schema | Record<string, ConfigItemDefinitionOrShorthand> | Yes | The schema for the workspace. These are the configuration items that will be available to all services. |
Note that when isRoot
is true, some of the options are not available:
parent
is the name of the parent service.tags
is an array of tags for the service.pick
is an array of items to pick from the parent or other services. This can be a string (the key) or aPickConfigItemDefinition
object.
PickItemDefinition
The PickItemDefinition
type is an object with the following properties:
Example:
DynamicConfigModes
The DynamicConfigModes
type has the following values:
ConfigItemDefinition
The ConfigItemDefinition
type is an object with the following properties:
Name | Type | Required | Description |
---|---|---|---|
asyncValidate | function | No | An async function to validate the value. |
coerce | function | No | A function to coerce the value. |
description | string | No | A description of the item. |
dynamic | boolean | No | Whether the item is dynamic. |
exampleValue | any | No | An example value for the item. |
exportEnvKey | string | No | The key to use when exporting the item to an env var. |
expose | boolean | No | Whether the item should be exposed to other services. i.e., is it "pickable" by siblings |
extends | DmnoDataType | string | () => DmnoDataType | No | A string (the name of the type), an initialized dmno data type, or a function that returns a DmnoDataType |
externalDocs | { description?, url } | Array<{ description?, url }> | No | External documentation for the item. |
importEnvKey | string | No | The key to use when importing the item from the environment. |
required | boolean | No | Whether the item is required. |
sensitive | boolean | No | Whether the item is sensitive. |
summary | string | No | A short summary description of the item. |
typeDescription | string | No | A description of the type. |
ui | { color, icon } | No | UI settings for the item. COMING SOON |
useAt | ConfigRequiredAtTypes | No | When the item is required. |
validate | function | No | A function to validate the value. |
value | InlineValueResolverDef | No | A static value, a function that returns a static value, or a "resolver" like a plugin helper function that fetches a value. |
Examples illustrating implicit and explicit type extensions:
createDmnoDataType
createDmnoDataType({ opts })
This method is used to create a new data type. It takes an object as an argument with the following properties:
Example:
You can then use it in your config schema like so:
switchBy
switchBy('SWITCH_BY_KEY': string, { opts })
This method is used to define different configurations for different values of a particular config item. Its arguments are a string (i.e., the key name) and an object with the following properties:
Note: _default
is a reserved key that will be used if the current value is not found. All the other keys should match the possible values of the SWITCH_BY_KEY
config item. You must set _default
value in the switch object, even if it is _default: undefined
.
Example:
switchByNodeEnv
switchByNodeEnv({ opts })
This method is used to define different configurations for different environments. It takes an object as an argument with the following properties:
Note: _default
is a reserved key that will be used if the current environment is not defined in the object. All the other keys should match the possible values of the NODE_ENV
environment variable.
Example: