MCPcopy Create free account
hub / github.com/TanStack/db / setupInitialData

Function setupInitialData

packages/trailbase-db-collection/e2e/trailbase.e2e.test.ts:282–333  ·  view source on GitHub ↗
(client: Client, seedData: SeedDataResult)

Source from the content-addressed store, hash-verified

280}
281
282async function setupInitialData(client: Client, seedData: SeedDataResult) {
283 const usersRecordApi = client.records<UserRecord>(`users_e2e`)
284 const postsRecordApi = client.records<PostRecord>(`posts_e2e`)
285 const commentsRecordApi = client.records<CommentRecord>(`comments_e2e`)
286
287 // Insert seed data - we provide the ID so the original UUIDs are preserved
288 console.log(`Inserting ${seedData.users.length} users...`)
289 let userErrors = 0
290 for (const user of seedData.users) {
291 try {
292 const serialized = serializeUser(user)
293 if (userErrors === 0)
294 console.log('First user data:', JSON.stringify(serialized))
295 await usersRecordApi.create(serialized)
296 } catch (e) {
297 userErrors++
298 if (userErrors <= 3) console.error('User insert error:', e)
299 }
300 }
301 console.log(
302 `Inserted users: ${seedData.users.length - userErrors} success, ${userErrors} errors`,
303 )
304 console.log(`First user ID: ${seedData.users.at(0)?.id}`)
305
306 console.log(`Inserting ${seedData.posts.length} posts...`)
307 let postErrors = 0
308 for (const post of seedData.posts) {
309 try {
310 await postsRecordApi.create(serializePost(post))
311 } catch (e) {
312 postErrors++
313 if (postErrors <= 3) console.error('Post insert error:', e)
314 }
315 }
316 console.log(
317 `Inserted posts: ${seedData.posts.length - postErrors} success, ${postErrors} errors`,
318 )
319
320 console.log(`Inserting ${seedData.comments.length} comments...`)
321 let commentErrors = 0
322 for (const comment of seedData.comments) {
323 try {
324 await commentsRecordApi.create(serializeComment(comment))
325 } catch (e) {
326 commentErrors++
327 if (commentErrors <= 3) console.error('Comment insert error:', e)
328 }
329 }
330 console.log(
331 `Inserted comments: ${seedData.comments.length - commentErrors} success, ${commentErrors} errors`,
332 )
333}
334
335describe(`TrailBase Collection E2E Tests`, async () => {
336 const baseUrl = inject(`baseUrl`)

Callers 1

Calls 3

serializeUserFunction · 0.85
serializePostFunction · 0.85
serializeCommentFunction · 0.85

Tested by

no test coverage detected