Store
Provides an API to retrieve decisions and resolve their values.
export type Store = { context: () => StoreContext; inputErrors: () => DecisionInputError[]; records: (filter?: (record: ValidatedRecord) => boolean) => ValidatedRecord[]; decision: (ref: DecisionRef) => [DecisionContext, Decision<V> | undefined]; createDecisionContext: (contexts?: LookupContexts) => DecisionContext; createValueContext: (lookupContexts?: LookupContexts) => ValueContext;};Implementation
You can create a Store via:
- staticStoreBuilder() (recommended)
- createStaticStore() (advanced)
Usage
Recommended:
Using the dd.config.mjs configuration file and staticStoreBuilder().
import { loadConfig, createStoreContext, staticStoreBuilder } from '@noodlestan/designer-functions';
const config = await loadConfig();const context = createStoreContext(config.store);const build = staticStoreBuilder(context);
const store = await build();const primary = store.decision({ $name: 'Primary color' });const color = primary.produce().toString('oklch');Advanced use cases
You can use lower lever APIs to compose your own use cases.
The following snippet is taken from the staticStoreBuilder() implementation.
const context = createStoreContext(options);const schemaMap = await loadSchemasFromSources(context);const validator = createDecisionValidator(context, schemaMap);
const loadedRecords = await loadDecisionsFromSources(context);const validatedMap = createStaticValidatedMap(context, loadedRecords, validator);const store = createStaticStore(context, validatedMap);Refer to createStaticStore() for more examples.
See also
- Guides / Loading and Validating
- API / configuration
- API / designer-functions / Store and StoreContext
- API / designer-functions / staticStoreBuilder()
- API / designer-functions / createStaticStore()