import type { NativeCacheConfig } from '../types' export type NativeStoreRetrieveFn = (key: string) => Promise export type NativeStoreUpsertFn = (key: string, data: unknown) => Promise export interface NativeStoreAdapter { /** * Ready-to-use NativeCacheConfig object. * Pass directly to WorkflowEngine({ nativeCache }) for global config, * or to a descriptor's nativeCache field for per-key config. */ nativeCache: NativeCacheConfig } /** * Creates a NativeCacheConfig from a native SDK's store functions. * * Usage — global (all descriptors): * const native = createNativeStoreAdapter({ * retrieve: (key) => deeplink.STORE_RETRIEVE(key), * upsert: (key, data) => deeplink.STORE_UPSERT(key, data), * }) * const engine = new WorkflowEngine({ queryClient, nativeCache: native.nativeCache }) * * Usage — per descriptor (overrides or disables global): * engine.register({ * key: 'user', * schema: UserSchema, * fetch: eapi.createFetch({ url: '/api/user' }), * nativeCache: { storeKey: 'native_user_key' }, // override store key only * }) * * engine.register({ * key: 'volatile', * schema: VolatileSchema, * fetch: eapi.createFetch({ url: '/api/volatile' }), * nativeCache: false, // disable native cache for this key * }) */ export function createNativeStoreAdapter(config: { retrieve: NativeStoreRetrieveFn upsert: NativeStoreUpsertFn }): NativeStoreAdapter { return { nativeCache: { retrieve: config.retrieve, upsert: config.upsert, }, } }