@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
100 lines • 2.8 kB
TypeScript
import type { StxOptions } from '../types';
/**
* Map stx strategy name to Workbox strategy
*/
export declare function mapStrategyToWorkbox(strategy: StxCacheStrategy): WorkboxStrategy;
/**
* Get Workbox strategy class name
*/
export declare function getWorkboxStrategyName(strategy: StxCacheStrategy): string;
/**
* Generate ExpirationPlugin config
*/
export declare function createExpirationPlugin(options: {
maxEntries?: number
maxAgeSeconds?: number
purgeOnQuotaError?: boolean
}): WorkboxPlugin;
/**
* Generate CacheableResponsePlugin config
*/
export declare function createCacheableResponsePlugin(options: {
statuses?: number[]
headers?: Record<string, string>
}): WorkboxPlugin;
/**
* Generate BackgroundSyncPlugin config
*/
export declare function createBackgroundSyncPlugin(options: {
name: string
maxRetentionTime?: number
forceSyncFallback?: boolean
}): WorkboxPlugin;
/**
* Convert stx route config to Workbox runtime caching config
*/
export declare function convertRouteToWorkbox(route: {
pattern: string
strategy: StxCacheStrategy
cacheName?: string
maxAgeSeconds?: number
maxEntries?: number
}): RuntimeCachingConfig;
/**
* Generate runtime caching configuration from stx routes
*/
export declare function generateRuntimeCaching(routes: Array<{
pattern: string
strategy: StxCacheStrategy
cacheName?: string
maxAgeSeconds?: number
maxEntries?: number
}>): RuntimeCachingConfig[];
/**
* Generate runtime caching JavaScript code
*/
export declare function generateRuntimeCachingCode(options: StxOptions): string;
/**
* Generate pattern matcher for Workbox registerRoute
*/
export declare function generatePatternMatcher(pattern: string): string;
export declare interface WorkboxStrategy {
className: string
importFrom: 'workbox-strategies'
defaultPlugins?: WorkboxPlugin[]
}
export declare interface WorkboxPlugin {
className: string
importFrom: string
options?: Record<string, unknown>
}
export declare interface WorkboxRoute {
pattern: string
matchType: 'pathname' | 'destination' | 'custom'
strategy: WorkboxStrategy
plugins?: WorkboxPlugin[]
cacheName?: string
}
export declare interface RuntimeCachingConfig {
urlPattern: string | RegExp
handler: string
options?: {
cacheName?: string
plugins?: WorkboxPlugin[]
networkTimeoutSeconds?: number
matchOptions?: {
ignoreSearch?: boolean
ignoreMethod?: boolean
ignoreVary?: boolean
}
}
method?: string
}
// ============================================================================
// Types
// ============================================================================
export type StxCacheStrategy = | 'cache-first'
| 'network-first'
| 'stale-while-revalidate'
| 'network-only'
| 'cache-only'