-
Multiple Providers: File-based, environment variables, API, and in-memory storage
-
Priority System: Resolve conflicts between providers using customizable strategies
-
Type Safety: Full ReScript type safety with pattern matching
-
Caching: LRU and TTL caching strategies for performance
-
Validation: Schema-based and custom validation rules
-
Encryption: AES-256-GCM encryption for sensitive preferences
-
Audit Logging: Track all preference operations
-
Migrations: Version and migrate preference schemas
-
CRDT Support: Distributed preference synchronization
-
Post-Quantum Crypto: Future-proof cryptographic operations
This project follows the Hyperpolymath Language Standard:
| Allowed | Banned |
|---|---|
ReScript |
TypeScript |
Deno |
Node.js, npm, bun |
Rust (for extensions) |
Go, Python (except SaltStack) |
Nickel (configuration) |
Makefile |
open Types
open Injector
// Create an injector with configuration
let injector = make(
~config=Some({
conflictResolution: Some(HighestPriority),
enableCache: Some(true),
cacheTTL: Some(3600000),
enableValidation: Some(true),
enableEncryption: None,
enableAudit: Some(true),
encryptionKey: None,
}),
)
// Create a memory provider
let memProvider = MemoryProvider.make(~priority=Normal)
// Add provider and initialize
addProvider(injector, provider)
await initialize(injector)
// Set preferences
switch await set(injector, "theme", String("dark"), None) {
| Ok() => Js.Console.log("Theme set!")
| Error(e) => Js.Console.error(e.message)
}
// Get preferences
switch await get(injector, "theme", None) {
| Ok(String(value)) => Js.Console.log(`Theme: ${value}`)
| Ok(_) => Js.Console.error("Unexpected type")
| Error(e) => Js.Console.error(e.message)
}In-memory storage for runtime preferences:
let provider = MemoryProvider.make(~priority=Normal)JSON or .env file-based storage:
let provider = FileProvider.make(
~config={
filePath: "./config.json",
priority: Normal,
format: JSON,
watchForChanges: true,
}
)Environment variable integration:
let provider = EnvProvider.make(
~config=Some({
prefix: Some("APP_"),
priority: Highest,
parseValues: true,
})
)Add validation rules to ensure preference values are valid:
// Add validation rules
addValidationRule(injector, "email", Validator.CommonRules.email())
addValidationRule(injector, "age", Validator.CommonRules.numberRange(~min=0.0, ~max=150.0))
addValidationRule(injector, "username", Validator.CommonRules.stringLength(~min=3, ~max=20))Distributed preference synchronization with conflict-free replicated data types:
-
G-Counter: Grow-only counter
-
PN-Counter: Positive-negative counter
-
LWW-Register: Last-writer-wins register
-
LWW-Map: Last-writer-wins map
-
OR-Set: Observed-remove set
Modern cryptographic primitives (RSR-compliant, no MD5/SHA1):
-
Hashing: SHA-256, SHA-512, BLAKE3
-
Encryption: AES-256-GCM
-
Signatures: ECDSA (P-256, P-384)
-
Key Exchange: ECDH
-
Post-Quantum: Kyber support planned
just test # Run all tests
just test-rescript # Run ReScript tests
just test-coverage # Run with coveragepreference-injector/
├── src/rescript/ # ReScript source code
│ ├── core/ # Core injector logic
│ ├── providers/ # Preference providers
│ ├── utils/ # Utility functions
│ ├── types/ # Type definitions
│ ├── errors/ # Error handling
│ ├── crdt/ # CRDT implementations
│ └── crypto/ # Cryptographic utilities
├── tests/rescript/ # ReScript tests
├── examples/ # Usage examples
├── docs/ # Documentation
├── deno.json # Deno configuration
├── bsconfig.json # ReScript configuration
├── Justfile # Just task runner
├── Mustfile.epx # Deployment state contract
└── config.ncl # Nickel configurationConfiguration is managed via Nickel (config.ncl) for type-safe, validated settings.
just nickel-check # Validate Nickel config
just nickel-export # Export to JSONSee the API Documentation for detailed API reference.
Check the examples/ directory for usage examples:
-
basic_usage.res- Basic preference management
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Important: All contributions must follow the Hyperpolymath Language Policy. TypeScript, Node.js, npm, and Makefile contributions will be rejected.
This project is licensed under the Mozilla Public License, v. 2.0. See the LICENSE file for details.
SPDX-License-Identifier: MPL-2.0
See CHANGELOG.md for release history.
See TOPOLOGY.md for a visual architecture map and completion dashboard.