feat: progressive init and readiness API for cloud storage
- Add `initMode` option to all cloud storage adapters (GCS, S3, Azure) - 'auto' (default): progressive in cloud, strict locally - 'progressive': <200ms cold starts, lazy bucket validation - 'strict': blocking validation (current behavior) - Add cloud environment auto-detection for: - Cloud Run (K_SERVICE, K_REVISION) - AWS Lambda (AWS_LAMBDA_FUNCTION_NAME) - Cloud Functions (FUNCTIONS_TARGET) - Azure Functions (AZURE_FUNCTIONS_ENVIRONMENT) - Add readiness API to Brainy class: - `brain.ready`: Promise that resolves when init() completes - `brain.isFullyInitialized()`: checks if background tasks done - `brain.awaitBackgroundInit()`: waits for background tasks - Lazy bucket validation on first write (not during init) - Background count synchronization - Update AWS/GCP deployment docs with readiness patterns 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
19c5e67035
commit
d938a6bd4f
10 changed files with 1470 additions and 62 deletions
|
|
@ -92,6 +92,20 @@ export interface StorageOptions {
|
|||
* AWS session token (optional)
|
||||
*/
|
||||
sessionToken?: string
|
||||
|
||||
/**
|
||||
* Initialization mode for fast cold starts (v7.3.0+)
|
||||
*
|
||||
* - `'auto'` (default): Progressive in cloud environments (Lambda),
|
||||
* strict locally. Zero-config optimization.
|
||||
* - `'progressive'`: Always use fast init (<200ms). Bucket validation and
|
||||
* count loading happen in background. First write validates bucket.
|
||||
* - `'strict'`: Traditional blocking init. Validates bucket and loads counts
|
||||
* before init() returns.
|
||||
*
|
||||
* @since v7.3.0
|
||||
*/
|
||||
initMode?: 'progressive' | 'strict' | 'auto'
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -196,8 +210,23 @@ export interface StorageOptions {
|
|||
* Skip loading and saving the counts file entirely
|
||||
* Useful for very large datasets where counts aren't critical
|
||||
* @default false
|
||||
* @deprecated Use `initMode: 'progressive'` instead
|
||||
*/
|
||||
skipCountsFile?: boolean
|
||||
|
||||
/**
|
||||
* Initialization mode for fast cold starts (v7.3.0+)
|
||||
*
|
||||
* - `'auto'` (default): Progressive in cloud environments (Cloud Run),
|
||||
* strict locally. Zero-config optimization.
|
||||
* - `'progressive'`: Always use fast init (<200ms). Bucket validation and
|
||||
* count loading happen in background. First write validates bucket.
|
||||
* - `'strict'`: Traditional blocking init. Validates bucket and loads counts
|
||||
* before init() returns.
|
||||
*
|
||||
* @since v7.3.0
|
||||
*/
|
||||
initMode?: 'progressive' | 'strict' | 'auto'
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -228,6 +257,20 @@ export interface StorageOptions {
|
|||
* SAS token (optional, alternative to account key)
|
||||
*/
|
||||
sasToken?: string
|
||||
|
||||
/**
|
||||
* Initialization mode for fast cold starts (v7.3.0+)
|
||||
*
|
||||
* - `'auto'` (default): Progressive in cloud environments (Azure Functions),
|
||||
* strict locally. Zero-config optimization.
|
||||
* - `'progressive'`: Always use fast init (<200ms). Container validation and
|
||||
* count loading happen in background. First write validates container.
|
||||
* - `'strict'`: Traditional blocking init. Validates container and loads counts
|
||||
* before init() returns.
|
||||
*
|
||||
* @since v7.3.0
|
||||
*/
|
||||
initMode?: 'progressive' | 'strict' | 'auto'
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -504,6 +547,7 @@ export async function createStorage(
|
|||
accessKeyId: options.s3Storage.accessKeyId,
|
||||
secretAccessKey: options.s3Storage.secretAccessKey,
|
||||
sessionToken: options.s3Storage.sessionToken,
|
||||
initMode: options.s3Storage.initMode,
|
||||
serviceType: 's3',
|
||||
operationConfig: options.operationConfig,
|
||||
cacheConfig: options.cacheConfig
|
||||
|
|
@ -597,6 +641,7 @@ export async function createStorage(
|
|||
secretAccessKey: config.secretAccessKey,
|
||||
skipInitialScan: gcsNative?.skipInitialScan,
|
||||
skipCountsFile: gcsNative?.skipCountsFile,
|
||||
initMode: gcsNative?.initMode,
|
||||
cacheConfig: options.cacheConfig
|
||||
})
|
||||
configureCOW(storage, options)
|
||||
|
|
@ -612,6 +657,7 @@ export async function createStorage(
|
|||
accountKey: options.azureStorage.accountKey,
|
||||
connectionString: options.azureStorage.connectionString,
|
||||
sasToken: options.azureStorage.sasToken,
|
||||
initMode: options.azureStorage.initMode,
|
||||
cacheConfig: options.cacheConfig
|
||||
})
|
||||
configureCOW(storage, options)
|
||||
|
|
@ -691,6 +737,7 @@ export async function createStorage(
|
|||
accessKeyId: options.s3Storage.accessKeyId,
|
||||
secretAccessKey: options.s3Storage.secretAccessKey,
|
||||
sessionToken: options.s3Storage.sessionToken,
|
||||
initMode: options.s3Storage.initMode,
|
||||
serviceType: 's3',
|
||||
cacheConfig: options.cacheConfig
|
||||
})
|
||||
|
|
@ -738,6 +785,7 @@ export async function createStorage(
|
|||
secretAccessKey: config.secretAccessKey,
|
||||
skipInitialScan: gcsNative?.skipInitialScan,
|
||||
skipCountsFile: gcsNative?.skipCountsFile,
|
||||
initMode: gcsNative?.initMode,
|
||||
cacheConfig: options.cacheConfig
|
||||
})
|
||||
configureCOW(storage, options)
|
||||
|
|
@ -753,6 +801,7 @@ export async function createStorage(
|
|||
accountKey: options.azureStorage.accountKey,
|
||||
connectionString: options.azureStorage.connectionString,
|
||||
sasToken: options.azureStorage.sasToken,
|
||||
initMode: options.azureStorage.initMode,
|
||||
cacheConfig: options.cacheConfig
|
||||
})
|
||||
configureCOW(storage, options)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue