Skip to content

Store

Provides an API to retrieve decisions and resolve their values.

export type Store = {
inputErrors: () => RecordError[];
records: (filter?: (record: ValidatedRecord) => boolean) => ValidatedRecord[];
decision: (ref: DecisionRef) => Decision<V> | undefined;
createDecisionContext: (contexts?: LookupContexts) => DecisionContext;
createValueContext: (input?: unknown, lookupContexts?: LookupContexts) => ValueContext;
};

Implementation

You can create a Store via:

Usage

Recommended:

Using the dd.config.mjs configuration file and buildStaticStore().

import { loadConfig, createBuilderContext, buildStaticStore } from '@noodlestan/designer-functions';
const config = await loadConfig();
const context = createBuilderContext(config.store);
const build = buildStaticStore(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 buildStaticStore() implementation.

const context = createBuilderContext(options);
const schemaMap = await loadSchemasFromSources(context);
const validator = createDecisionValidator(schemaMap);
const loadedRecords = await loadDecisionsFromSources(context);
const recordMap = createRecordMap(loadedRecords, validator);
const store = createStore(recordMap);

Refer to createStore() for more examples.

See also