-
-
Notifications
You must be signed in to change notification settings - Fork 106
feat: bundle mode with atomic deploys, seed assets, and version-gated caching #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
divyanshub024
wants to merge
2
commits into
dev
Choose a base branch
from
feat/bundle-deploy
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| export 'package:stac/src/models/stac_bundle.dart'; | ||
| export 'package:stac/src/models/stac_bundle_config.dart'; | ||
| export 'package:stac/src/models/stac_cache_config.dart'; | ||
| export 'package:stac/src/models/stac_cache.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| part 'stac_bundle.g.dart'; | ||
|
|
||
| /// Model representing a bundle of screens and themes from Stac Cloud. | ||
| /// | ||
| /// A bundle contains every screen and theme for a project at a single | ||
| /// server-owned monotonic [version]. Screens render from the cached bundle; | ||
| /// the body is re-downloaded only when a conditional version check returns | ||
| /// a new version. | ||
| @JsonSerializable() | ||
| class StacBundle { | ||
| /// Creates a [StacBundle] instance. | ||
| const StacBundle({ | ||
| required this.projectId, | ||
| required this.version, | ||
| this.etag, | ||
| this.checksum, | ||
| required this.fetchedAt, | ||
| required this.screens, | ||
| required this.themes, | ||
| }); | ||
|
|
||
| /// The Stac Cloud project this bundle belongs to. | ||
| final String projectId; | ||
|
|
||
| /// The server-owned monotonic bundle version. | ||
| final int version; | ||
|
|
||
| /// The HTTP ETag for conditional (`If-None-Match`) requests. | ||
| final String? etag; | ||
|
|
||
| /// The sha256 checksum of the bundle content. | ||
| final String? checksum; | ||
|
|
||
| /// The timestamp when this bundle was fetched or hydrated. | ||
| final DateTime fetchedAt; | ||
|
|
||
| /// Screen name to Stac JSON string. | ||
| final Map<String, String> screens; | ||
|
|
||
| /// Theme name to Stac JSON string. | ||
| final Map<String, String> themes; | ||
|
|
||
| /// Returns the Stac JSON string for the screen [name], or `null` if the | ||
| /// screen is not part of this bundle. | ||
| String? screen(String name) => screens[name]; | ||
|
|
||
| /// Returns the Stac JSON string for the theme [name], or `null` if the | ||
| /// theme is not part of this bundle. | ||
| String? theme(String name) => themes[name]; | ||
|
|
||
| /// Creates a [StacBundle] from a JSON map. | ||
| factory StacBundle.fromJson(Map<String, dynamic> json) => | ||
| _$StacBundleFromJson(json); | ||
|
|
||
| /// Converts this [StacBundle] to a JSON map. | ||
| Map<String, dynamic> toJson() => _$StacBundleToJson(this); | ||
|
|
||
| /// Creates a [StacBundle] from a JSON string. | ||
| factory StacBundle.fromJsonString(String jsonString) { | ||
| return StacBundle.fromJson(jsonDecode(jsonString) as Map<String, dynamic>); | ||
| } | ||
|
|
||
| /// Converts this [StacBundle] to a JSON string. | ||
| String toJsonString() { | ||
| return jsonEncode(toJson()); | ||
| } | ||
|
|
||
| /// Creates a copy of this [StacBundle] with the given fields replaced. | ||
| StacBundle copyWith({ | ||
| String? projectId, | ||
| int? version, | ||
| String? etag, | ||
| String? checksum, | ||
| DateTime? fetchedAt, | ||
| Map<String, String>? screens, | ||
| Map<String, String>? themes, | ||
| }) { | ||
| return StacBundle( | ||
| projectId: projectId ?? this.projectId, | ||
| version: version ?? this.version, | ||
| etag: etag ?? this.etag, | ||
| checksum: checksum ?? this.checksum, | ||
| fetchedAt: fetchedAt ?? this.fetchedAt, | ||
| screens: screens ?? this.screens, | ||
| themes: themes ?? this.themes, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'StacBundle(projectId: $projectId, version: $version, ' | ||
| 'screens: ${screens.length}, themes: ${themes.length}, ' | ||
| 'fetchedAt: $fetchedAt)'; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /// Configuration for Stac bundle mode. | ||
| /// | ||
| /// Bundle mode replaces per-screen fetches with a single version-gated | ||
| /// bundle download containing every screen and theme for a project. | ||
| /// It is opt-in: [enabled] defaults to `false`, so an app without a | ||
| /// `bundleConfig` behaves exactly as before. | ||
| /// | ||
| /// Bundle caching behavior is fixed (no strategies): screens always render | ||
| /// from the cached bundle, and the body is re-downloaded only when a | ||
| /// conditional version check returns a new version. The check runs at app | ||
| /// launch ([prefetchOnInit]), on app-resume ([checkOnResume]), on an optional | ||
| /// poll interval ([pollingInterval]), or via an explicit | ||
| /// `StacBundleService.sync()` call. | ||
| /// | ||
| /// ## Basic Usage | ||
| /// | ||
| /// ```dart | ||
| /// await Stac.initialize( | ||
| /// options: StacOptions(...), | ||
| /// bundleConfig: StacBundleConfig( | ||
| /// enabled: true, | ||
| /// seedAsset: 'assets/stac_bundle.json', | ||
| /// ), | ||
| /// ); | ||
| /// ``` | ||
| class StacBundleConfig { | ||
| /// Creates a [StacBundleConfig] instance. | ||
| const StacBundleConfig({ | ||
| this.enabled = false, | ||
| this.prefetchOnInit = true, | ||
| this.baseUrl = 'https://api.stac.dev', | ||
| this.seedAsset, | ||
| this.checkOnResume = true, | ||
| this.pollingInterval, | ||
| }); | ||
|
|
||
| /// Whether bundle mode is enabled. | ||
| /// | ||
| /// Defaults to `false` (opt-in). When disabled, the legacy per-artifact | ||
| /// fetch and cache behavior is untouched. | ||
| final bool enabled; | ||
|
|
||
| /// Whether to kick off a conditional bundle sync during initialization. | ||
| /// | ||
| /// Defaults to `true`. The sync is not awaited, so it never delays startup. | ||
| final bool prefetchOnInit; | ||
|
|
||
| /// The base URL used for bundle requests. | ||
| /// | ||
| /// Defaults to `https://api.stac.dev`. | ||
| final String baseUrl; | ||
|
|
||
| /// Optional asset path of a seed bundle shipped with the app | ||
| /// (e.g. `assets/stac_bundle.json`, written by `stac deploy`). | ||
| /// | ||
| /// When set, first launch hydrates from the seed instantly — no loading | ||
| /// wait, and it works offline. Defaults to `null` (no seed). | ||
| final String? seedAsset; | ||
|
|
||
| /// Whether to run a conditional bundle sync when the app returns to the | ||
| /// foreground. | ||
| /// | ||
| /// Defaults to `true`. | ||
| final bool checkOnResume; | ||
|
|
||
| /// Optional interval for periodic conditional bundle syncs while the app | ||
| /// is foregrounded. | ||
| /// | ||
| /// Defaults to `null` (polling off). | ||
| final Duration? pollingInterval; | ||
|
|
||
| // ───────────────────────────────────────────────────────────────────────── | ||
| // Methods | ||
| // ───────────────────────────────────────────────────────────────────────── | ||
|
|
||
| /// Creates a copy of this config with the given fields replaced. | ||
| StacBundleConfig copyWith({ | ||
| bool? enabled, | ||
| bool? prefetchOnInit, | ||
| String? baseUrl, | ||
| String? seedAsset, | ||
| bool? checkOnResume, | ||
| Duration? pollingInterval, | ||
| }) { | ||
| return StacBundleConfig( | ||
| enabled: enabled ?? this.enabled, | ||
| prefetchOnInit: prefetchOnInit ?? this.prefetchOnInit, | ||
| baseUrl: baseUrl ?? this.baseUrl, | ||
| seedAsset: seedAsset ?? this.seedAsset, | ||
| checkOnResume: checkOnResume ?? this.checkOnResume, | ||
| pollingInterval: pollingInterval ?? this.pollingInterval, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'StacBundleConfig(enabled: $enabled, prefetchOnInit: $prefetchOnInit, ' | ||
| 'baseUrl: $baseUrl, seedAsset: $seedAsset, checkOnResume: $checkOnResume, ' | ||
| 'pollingInterval: $pollingInterval)'; | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(this, other)) return true; | ||
|
|
||
| return other is StacBundleConfig && | ||
| other.enabled == enabled && | ||
| other.prefetchOnInit == prefetchOnInit && | ||
| other.baseUrl == baseUrl && | ||
| other.seedAsset == seedAsset && | ||
| other.checkOnResume == checkOnResume && | ||
| other.pollingInterval == pollingInterval; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode { | ||
| return Object.hash( | ||
| enabled, | ||
| prefetchOnInit, | ||
| baseUrl, | ||
| seedAsset, | ||
| checkOnResume, | ||
| pollingInterval, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| export 'package:stac/src/services/stac_bundle_service.dart'; | ||
| export 'package:stac/src/services/stac_bundle_store.dart'; | ||
| export 'package:stac/src/services/stac_cache_service.dart'; | ||
| export 'package:stac/src/services/stac_network_service.dart'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: StacDev/stac
Length of output: 220
🏁 Script executed:
Repository: StacDev/stac
Length of output: 5339
🏁 Script executed:
Repository: StacDev/stac
Length of output: 13675
Propagate
dioto bundle mode, and fail fast whenoptionsis missing.packages/stac/lib/src/framework/stac_service.dart:202-207dio:only reachesStacNetworkService;StacBundleService.sync()still uses its own default client, so bundle requests won’t honor caller auth/interceptors/proxy settings.bundleConfig.enabledis set withoutoptions,StacBundleUpdater.start()still runs and the first resume/poll sync throws from_projectIdoutside thetry, instead of surfacing as an init-time validation error.🤖 Prompt for AI Agents