1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//! Asset types for external resources.
//!
//! Assets are external inputs (files, network resources, etc.) that:
//! - Are always leaves in the dependency graph (no dependencies)
//! - May need IO to load
//! - Loading differs by platform (filesystem locally, network/memory in playground)
//! - Can be depended upon by queries with proper dependency tracking
use ;
use Debug;
use Arc;
use crateDb;
use crateQueryError;
use crateCacheKey;
/// Durability levels for dependency tracking optimization.
///
/// Higher values indicate the data changes less frequently.
/// Durability is specified when resolving assets, not on the type itself.
/// Trait for asset keys that map to loadable assets.
///
/// Asset keys identify external resources (files, URLs, etc.) and define
/// the type of asset they load. Assets are leaf nodes in the dependency
/// graph - they have no dependencies but can be depended upon by queries.
///
/// Durability is specified when calling `resolve_asset()`, not on the key type.
///
/// # Example
///
/// ```ignore
/// use query_flow::{asset_key, AssetKey};
///
/// #[asset_key(asset = String)]
/// pub struct ConfigFile(pub PathBuf);
///
/// // Or manually:
/// #[derive(Clone, Debug, Hash, PartialEq, Eq)]
/// pub struct TextureId(pub u32);
///
/// impl AssetKey for TextureId {
/// type Asset = ImageData;
///
/// fn asset_eq(old: &Self::Asset, new: &Self::Asset) -> bool {
/// old.bytes == new.bytes
/// }
/// }
/// ```
/// Result of locating an asset.
/// Trait for locating and loading assets.
///
/// Implement this trait to define how assets are found for a given key type.
/// Different locators can be registered for different platforms:
/// - Filesystem locator for desktop
/// - Network locator for web/playground
/// - Memory locator for testing
///
/// # Database Access
///
/// The `locate` method receives a database handle, allowing locators to:
/// - Query configuration to determine loading behavior
/// - Access other assets as dependencies
/// - Make dynamic decisions based on runtime state
///
/// Any queries or assets accessed during `locate()` are tracked as dependencies
/// of the calling query.
///
/// # Example
///
/// ```ignore
/// struct ConfigAwareLocator;
///
/// impl AssetLocator<FilePath> for ConfigAwareLocator {
/// fn locate(&self, db: &impl Db, key: &FilePath) -> Result<LocateResult<String>, QueryError> {
/// // Access config to check if path is allowed
/// let config = db.query(GetConfig)?.clone();
/// if !config.allowed_paths.contains(&key.0) {
/// return Err(anyhow::anyhow!("Path not allowed: {:?}", key.0).into());
/// }
///
/// // Return pending for async loading
/// Ok(LocateResult::Pending)
/// }
/// }
/// ```
/// A pending asset request that needs to be resolved.