Files
start-os/sdk/package/lib/store/setupExposeStore.ts
Matt Hill 12dec676db Update sdk comments (#2793)
* sdk tweaks

* switch back to deeppartial

* WIP, update comments

* reinstall chesterton's fence

---------

Co-authored-by: Aiden McClelland <me@drbonez.dev>
2024-11-26 23:54:05 -07:00

28 lines
977 B
TypeScript

import { ExposedStorePaths } from "../../../base/lib/types"
import {
PathBuilder,
extractJsonPath,
pathBuilder,
} from "../../../base/lib/util/PathBuilder"
/**
* @description Use this function to determine which Store values to expose and make available to other services running on StartOS. Store values not exposed here will be kept private. Use the type safe pathBuilder to traverse your Store's structure.
* @example
* In this example, we expose the hypothetical Store values "adminPassword" and "nameLastUpdatedAt".
*
* ```
export const exposedStore = setupExposeStore<Store>((pathBuilder) => [
pathBuilder.adminPassword
pathBuilder.nameLastUpdatedAt,
])
* ```
*/
export const setupExposeStore = <Store extends Record<string, any>>(
fn: (pathBuilder: PathBuilder<Store>) => PathBuilder<Store, any>[],
) => {
return fn(pathBuilder<Store>()).map(
(x) => extractJsonPath(x) as string,
) as ExposedStorePaths
}
export { ExposedStorePaths }