0.0.326 • Published 22 days ago

@pristine-ts/configuration v0.0.326

Weekly downloads
-
License
ISC
Repository
-
Last release
22 days ago

Configuration Module

The Configuration Module is used to provide a way for your own module or other modules in Pristine to be dynamically configured. This allows any service injected in the Container to retrieve a parameter. The parameter will be injected as %module_keyname.parameter_name% (it follows the syntax used by Symfony).

In your class, to have a parameter be injected, you simply do this:

class Example {
    public constructor(@inject("%module_keyname.parameter_name%") private readonly parameterName: string) {}
}

How to specify a configuration for your module

Before we begin, there are two terms we use as a convention, and it's important to understand them before continuing.

ConfigurationDefinition

The ConfigurationDefinition is the configuration "model" that the module specifies it needs. By convention, we recommend creating a ConfigurationDefinitionInterface interface that specifies what you are expecting your users to pass. Here's an example:

interface ConfigurationDefinitionInterface {
    test1Parameter: string;
    test2Parameter?: string;
    test3Parameter?: string;
}

Then, you can create a ConfigurationDefinition class that specifies the default values for the required parameters.

    class ConfigurationDefinition implements ConfigurationDefinitionInterface {
        test1Parameter: string = "test1";
        test2Parameter?: string = "test2";
    }

Then, when you define and create your module, you pass the ConfigurationDefinition type object:

    const module: ModuleInterface = {
        keyname: "test",
        importServices: [],
        providerRegistrations: [
        ],
        configurationDefinition: ConfigurationDefinition
    };

That way, the ConfigurationModule now knows which values must be expected and will complain when you start the kernel if the user hasn't provided these values for your module.

Configuration

The Configuration represents the actual values that the configuration parameters will have. The configuration is passed in the init method of the kernel and Pristine evaluates if all the required configuration parameters are present.


NOTE

Now, you might be wondering why you need to create a class (on top of an interface) and define default values because you might want to force the user to pass those values. The problem is that interfaces in Typescript are lost during compile time, and we cannot use them (yet) to retrieve type or optionality information during runtime.

Therefore, that's why we recommend the creation of a ConfigurationDefinitionInterface so that this interface can act as a guide for your users, since this is the interface that you should expose.

When your users will be initiating the kernel, they will need to pass a configuration for each module keyname, and you ask them to use the configuration interface

This part is still pretty weak in our opinion and will need some interesting thinking to make it better, but for now, it works correctly, but is too opinionated for our liking.


##Instantiation and using the Configuration

When you instantiate the kernel, you need to specify the configuration for each module as follows:

    const kernel = new Kernel();

    const testModuleConfiguration: ConfigurationDefinitionInterface = {
        test1Parameter: "NotDefault",
    };

    await kernel.init(module, [{
        moduleKeyname: module.keyname,
        configuration: testModuleConfiguration
    }]);

This is also in the configuration that you can use resolvers to convert or retrieve parameters from the environment variables, your filesystem, AWS SSM, etc.

Using a configuration parameter in your class

This is how you would inject a parameter in the constructor of one of your services

@injectable()
class TestConfigurationParameterInjectedInConstructor {
    public constructor(@inject("%test.test1Parameter%") public readonly test1Parameter: string, @inject("%test.test2Parameter%") public readonly test2Parameter: string,) {
    }
}

Configuration Resolvers

We have made it very easy to create your own ConfigurationResolver. A ConfigurationResolver allows you to retrieve configuration from the configuration parameters from the current environment and inject it into the controller. For example, you can easily create a FileConfigurationResolver(to have configuration parameters retrieved from a file), an AwsSsmConfigurationResolver (to have configuration parameters retrieved from AWS SSM) or anything else you can come up with.

To create a ConfigurationResolver, you simply inherit the ResolverInterface. Then, your user can easily use it when they pass the configuration to the second argument of the init method in the Kernel.

0.0.326

22 days ago

0.0.325

23 days ago

0.0.324

24 days ago

0.0.323

26 days ago

0.0.322

26 days ago

0.0.321

27 days ago

0.0.320

27 days ago

0.0.319

2 months ago

0.0.318

2 months ago

0.0.317

2 months ago

0.0.315

2 months ago

0.0.314

2 months ago

0.0.313

2 months ago

0.0.312

2 months ago

0.0.316

2 months ago

0.0.311

2 months ago

0.0.310

2 months ago

0.0.309

2 months ago

0.0.304

2 months ago

0.0.303

2 months ago

0.0.308

2 months ago

0.0.307

2 months ago

0.0.306

2 months ago

0.0.305

2 months ago

0.0.302

2 months ago

0.0.301

3 months ago

0.0.300

3 months ago

0.0.299

3 months ago

0.0.298

3 months ago

0.0.296

3 months ago

0.0.295

3 months ago

0.0.297

3 months ago

0.0.285

3 months ago

0.0.289

3 months ago

0.0.288

3 months ago

0.0.287

3 months ago

0.0.294

3 months ago

0.0.293

3 months ago

0.0.292

3 months ago

0.0.291

3 months ago

0.0.290

3 months ago

0.0.284

3 months ago

0.0.279

3 months ago

0.0.283

3 months ago

0.0.282

3 months ago

0.0.281

3 months ago

0.0.280

3 months ago

0.0.278

4 months ago

0.0.277

4 months ago

0.0.276

5 months ago

0.0.274

5 months ago

0.0.273

5 months ago

0.0.272

5 months ago

0.0.275

5 months ago

0.0.238

10 months ago

0.0.239

10 months ago

0.0.249

7 months ago

0.0.248

8 months ago

0.0.247

8 months ago

0.0.246

8 months ago

0.0.241

8 months ago

0.0.240

8 months ago

0.0.245

8 months ago

0.0.244

8 months ago

0.0.243

8 months ago

0.0.242

8 months ago

0.0.259

6 months ago

0.0.258

6 months ago

0.0.257

6 months ago

0.0.252

7 months ago

0.0.251

7 months ago

0.0.250

7 months ago

0.0.256

6 months ago

0.0.255

7 months ago

0.0.254

7 months ago

0.0.253

7 months ago

0.0.269

5 months ago

0.0.268

5 months ago

0.0.263

5 months ago

0.0.262

5 months ago

0.0.261

6 months ago

0.0.260

6 months ago

0.0.267

5 months ago

0.0.266

5 months ago

0.0.265

5 months ago

0.0.264

5 months ago

0.0.227

1 year ago

0.0.229

1 year ago

0.0.228

1 year ago

0.0.237

12 months ago

0.0.236

1 year ago

0.0.235

1 year ago

0.0.230

1 year ago

0.0.234

1 year ago

0.0.233

1 year ago

0.0.232

1 year ago

0.0.231

1 year ago

0.0.226

1 year ago

0.0.219

1 year ago

0.0.218

1 year ago

0.0.217

1 year ago

0.0.225

1 year ago

0.0.224

1 year ago

0.0.223

1 year ago

0.0.221

1 year ago

0.0.220

1 year ago

0.0.214

2 years ago

0.0.213

2 years ago

0.0.212

2 years ago

0.0.211

2 years ago

0.0.209

2 years ago

0.0.210

2 years ago

0.0.205

2 years ago

0.0.204

2 years ago

0.0.203

2 years ago

0.0.202

2 years ago

0.0.208

2 years ago

0.0.207

2 years ago

0.0.206

2 years ago

0.0.201

2 years ago

0.0.200

2 years ago

0.0.199

2 years ago

0.0.175

2 years ago

0.0.174

2 years ago

0.0.173

2 years ago

0.0.172

2 years ago

0.0.179

2 years ago

0.0.178

2 years ago

0.0.177

2 years ago

0.0.176

2 years ago

0.0.171

2 years ago

0.0.170

2 years ago

0.0.186

2 years ago

0.0.185

2 years ago

0.0.184

2 years ago

0.0.183

2 years ago

0.0.189

2 years ago

0.0.188

2 years ago

0.0.187

2 years ago

0.0.182

2 years ago

0.0.181

2 years ago

0.0.180

2 years ago

0.0.197

2 years ago

0.0.196

2 years ago

0.0.195

2 years ago

0.0.194

2 years ago

0.0.198

2 years ago

0.0.193

2 years ago

0.0.192

2 years ago

0.0.191

2 years ago

0.0.190

2 years ago

0.0.169

2 years ago

0.0.164

2 years ago

0.0.163

2 years ago

0.0.168

2 years ago

0.0.167

2 years ago

0.0.166

2 years ago

0.0.165

2 years ago

0.0.159

3 years ago

0.0.158

3 years ago

0.0.157

3 years ago

0.0.162

3 years ago

0.0.161

3 years ago

0.0.160

3 years ago

0.0.153

3 years ago

0.0.152

3 years ago

0.0.151

3 years ago

0.0.150

3 years ago

0.0.156

3 years ago

0.0.155

3 years ago

0.0.154

3 years ago

0.0.149

3 years ago

0.0.148

3 years ago

0.0.147

3 years ago

0.0.146

3 years ago

0.0.145

3 years ago

0.0.144

3 years ago

0.0.142

3 years ago

0.0.141

3 years ago

0.0.143

3 years ago

0.0.140

3 years ago

0.0.129

3 years ago

0.0.139

3 years ago

0.0.138

3 years ago

0.0.137

3 years ago

0.0.136

3 years ago

0.0.131

3 years ago

0.0.130

3 years ago

0.0.135

3 years ago

0.0.134

3 years ago

0.0.133

3 years ago

0.0.132

3 years ago

0.0.128

3 years ago

0.0.127

3 years ago

0.0.126

3 years ago

0.0.125

3 years ago

0.0.124

3 years ago

0.0.123

3 years ago

0.0.122

3 years ago

0.0.121

3 years ago

0.0.120

3 years ago

0.0.117

3 years ago

0.0.119

3 years ago

0.0.118

3 years ago

0.0.116

3 years ago

0.0.115

3 years ago

0.0.114

3 years ago

0.0.113

3 years ago

0.0.112

3 years ago

0.0.111

3 years ago

0.0.110

3 years ago

0.0.109

3 years ago

0.0.106

3 years ago

0.0.105

3 years ago

0.0.104

3 years ago

0.0.108

3 years ago

0.0.107

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago

0.0.100

3 years ago

0.0.84

3 years ago

0.0.85

3 years ago

0.0.86

3 years ago

0.0.87

3 years ago

0.0.88

3 years ago

0.0.89

3 years ago

0.0.80

3 years ago

0.0.81

3 years ago

0.0.82

3 years ago

0.0.83

3 years ago

0.0.73

3 years ago

0.0.74

3 years ago

0.0.75

3 years ago

0.0.76

3 years ago

0.0.77

3 years ago

0.0.78

3 years ago

0.0.79

3 years ago

0.0.70

3 years ago

0.0.71

3 years ago

0.0.72

3 years ago

0.0.68

3 years ago

0.0.69

3 years ago

0.0.95

3 years ago

0.0.96

3 years ago

0.0.97

3 years ago

0.0.98

3 years ago

0.0.99

3 years ago

0.0.90

3 years ago

0.0.91

3 years ago

0.0.92

3 years ago

0.0.93

3 years ago

0.0.94

3 years ago

0.0.62

3 years ago

0.0.63

3 years ago

0.0.64

3 years ago

0.0.65

3 years ago

0.0.66

3 years ago

0.0.67

3 years ago

0.0.60

3 years ago

0.0.61

3 years ago

0.0.59

3 years ago

0.0.51

3 years ago

0.0.52

3 years ago

0.0.53

3 years ago

0.0.54

3 years ago

0.0.55

3 years ago

0.0.56

3 years ago

0.0.57

3 years ago

0.0.58

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.48

3 years ago

0.0.47

3 years ago

0.0.46

3 years ago

0.0.45

3 years ago

0.0.44

3 years ago

0.0.43

3 years ago