Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
async function logUserData() {
try {
const username = await valTownUser.getUsername();
const userId = await valTownUser.getId();
const bio = await valTownUser.getBio();
const email = await valTownUser.getEmail();
const tier = await valTownUser.getTier();
const profileImageUrl = await valTownUser.getProfileImageUrl();
console.log('User Information:');
console.log(`Username: ${username}`);
console.log(`User ID: ${userId}`);
console.log(`Bio: ${bio || 'Not set'}`);
console.log(`Email: ${email}`);
console.log(`Tier: ${tier}`);
console.log(`Profile Image: ${profileImageUrl || 'Not set'}`);
console.log('\nEndpoint URLs:');
console.log(`For 'myVal': ${await valTownUser.getEndpointUrl('myVal')}`);
console.log(`Val URL for 'myVal': ${await valTownUser.getValUrl('myVal')}`);
console.log('\nLiked Vals:');
const likedVals = await valTownUser.getLikedVals({ limit: 5 });
likedVals.data.forEach((val, index) => {
console.log(`${index + 1}. ${val.name} by ${val.author.username}`);
});
console.log('\nUser Vals:');
const userVals = await valTownUser.listVals({ limit: 5 });
userVals.data.forEach((val, index) => {
console.log(`${index + 1}. ${val.name} (${val.type})`);
});
console.log('\nUser Comments:');
const comments = await valTownUser.getComments({ limit: 5 });
comments.data.forEach((commentObj, index) => {
console.log(`${index + 1}.`);
console.log(` Id: "${commentObj.id}"`);
console.log(` Content: ${commentObj.comment}`);
console.log(` Date: ${commentObj.createdAt}`);
console.log(` Author: ${commentObj.author.username}`);
console.log(` On Val: ${commentObj.val.name}`);
console.log();
});
console.log('\nReferences to Your Vals:');
const references = await valTownUser.getReferences({ limit: 5 });
references.data.forEach((refObj, index) => {
console.log(`${index + 1}.`);
console.log(` Reference ID: "${refObj.reference.id}"`);
console.log(` Reference Val Name: ${refObj.reference.name}`);
console.log(` Dependent Val Name: ${refObj.dependsOn.name}`);
console.log(` Referenced By: ${refObj.reference.username}`);
console.log(` Referenced At: ${refObj.referencedAt}`);
console.log();
});
console.log('\nBlobs:');
const blobs = await valTownUser.listBlobs();
blobs.slice(0, 5).forEach((blob, index) => {
console.log(`${index + 1}. ${blob.key} (${blob.size} bytes)`);
});
// Database Inspection
console.log('\nDatabase Inspection:');
const tablesResult = await valTownUser.executeSqlite("SELECT name FROM sqlite_master WHERE type='table'");
console.log("Tables in the database:");
tablesResult.rows.forEach(row => console.log(row[0]));
for (const [tableName] of tablesResult.rows) {
console.log(`\nSchema for table '${tableName}':`);
const schemaResult = await valTownUser.executeSqlite(`PRAGMA table_info(${tableName})`);
console.table(schemaResult.rows.map(row => ({
name: row[1],
type: row[2],
notNull: row[3] ? 'NOT NULL' : '',
defaultValue: row[4],
primaryKey: row[5] ? 'PRIMARY KEY' : ''
})));
console.log(`\nSample content from '${tableName}' (up to 5 rows):`);
const contentResult = await valTownUser.executeSqlite(`SELECT * FROM ${tableName} LIMIT 5`);
console.table(contentResult.rows);
}
} catch (error) {
console.error('Error fetching user data or inspecting database:', error);
}
}
logUserData();
August 26, 2024