|
24 | 24 |
|
25 | 25 | import type { Contracts } from '@objectstack/spec'; |
26 | 26 | import { Plugin, PluginContext } from '@objectstack/core'; |
| 27 | +import { SeedLoaderConfigSchema } from '@objectstack/spec/data'; |
27 | 28 | import { |
28 | 29 | DefaultEnvironmentDriverRegistry, |
29 | 30 | type EnvironmentDriverRegistry, |
@@ -159,7 +160,7 @@ function createTemplateSeeder( |
159 | 160 |
|
160 | 161 | const bundle = await template.load(); |
161 | 162 | const items = bundle ? extractMetadataItems(bundle) : []; |
162 | | - const dataSets = Array.isArray(bundle?.data) ? bundle.data : []; |
| 163 | + const dataSets = bundle ? namespaceDatasets(bundle) : []; |
163 | 164 |
|
164 | 165 | // Empty bundle (e.g. the "blank" template) → nothing to seed. |
165 | 166 | if (items.length === 0 && dataSets.length === 0) return; |
@@ -206,7 +207,20 @@ function createTemplateSeeder( |
206 | 207 |
|
207 | 208 | if (dataSets.length > 0) { |
208 | 209 | const seedLoader = new SeedLoaderService(engine, metadata, console as any); |
209 | | - await seedLoader.load({ datasets: dataSets, config: {} as any }); |
| 210 | + const config = SeedLoaderConfigSchema.parse({}); |
| 211 | + await seedLoader.load({ datasets: dataSets, config }); |
| 212 | + } |
| 213 | + |
| 214 | + // Force a persistence flush so the per-project JSON file is |
| 215 | + // written before the provisioning handler returns; otherwise |
| 216 | + // the memory driver's dirty flag only saves on a 2s timer and |
| 217 | + // early HTTP responses may see an empty file on disk. |
| 218 | + const driverWithFlush = (kernel as any).services?.driver ?? (kernel as any).getService?.('driver'); |
| 219 | + const flushable = typeof driverWithFlush?.flush === 'function' |
| 220 | + ? driverWithFlush |
| 221 | + : null; |
| 222 | + if (flushable) { |
| 223 | + try { await flushable.flush(); } catch { /* best effort */ } |
210 | 224 | } |
211 | 225 | }, |
212 | 226 | }; |
|
0 commit comments