Skip to content

Commit 3500c0b

Browse files
authored
preparing (#81)
1 parent 8b05c5f commit 3500c0b

File tree

2 files changed

+125
-15
lines changed

2 files changed

+125
-15
lines changed

pkg/example.js

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,165 @@
1-
import { PubkyAppPostKind, PubkySpecsBuilder, PubkyAppPostEmbed } from "./index.js";
1+
import {
2+
PubkyAppPostKind,
3+
PubkySpecsBuilder,
4+
PubkyAppPostEmbed,
5+
userUriBuilder,
6+
postUriBuilder,
7+
bookmarkUriBuilder,
8+
followUriBuilder,
9+
tagUriBuilder,
10+
muteUriBuilder,
11+
lastReadUriBuilder,
12+
blobUriBuilder,
13+
fileUriBuilder,
14+
feedUriBuilder,
15+
} from "./index.js";
216

317
const OTTO = "8kkppkmiubfq4pxn6f73nqrhhhgkb5xyfprntc9si3np9ydbotto";
418
const RIO = "dzswkfy7ek3bqnoc89jxuqqfbzhjrj6mi8qthgbxxcqkdugm3rio";
519

620
// 👤 Create a user profile
721
console.log("👤 Creating User Profile...");
822
const specsBuilder = new PubkySpecsBuilder(OTTO);
9-
const { user, meta: userMeta } =
10-
specsBuilder.createUser("Alice Smith", "Software Developer", null, null, "active");
23+
const { user, meta: userMeta } = specsBuilder.createUser(
24+
"Alice Smith",
25+
"Software Developer",
26+
null,
27+
null,
28+
"active"
29+
);
1130
console.log("User Profile URL:", userMeta.url);
1231
console.log("User Data:", JSON.stringify(user.toJson(), null, 2));
1332
console.log("-".repeat(60));
1433

1534
// 📝 Create different posts
1635
console.log("📝 Creating First Post...");
17-
const { post, meta } = specsBuilder.createPost("Hello, Pubky world! This is my first post.", PubkyAppPostKind.Short, null, null, null);
36+
const { post, meta } = specsBuilder.createPost(
37+
"Hello, Pubky world! This is my first post.",
38+
PubkyAppPostKind.Short,
39+
null,
40+
null,
41+
null
42+
);
1843
console.log("Post ID:", meta.id);
1944
console.log("Post URL:", meta.url);
2045
console.log("Post Data:", JSON.stringify(post.toJson(), null, 2));
2146
console.log("-".repeat(60));
2247

2348
console.log("💬 Creating Reply Post...");
24-
const { post: replyPost, meta: replyMeta } = specsBuilder.createPost("This is a reply to the first post!", PubkyAppPostKind.Short, userMeta.url, null, null);
49+
const { post: replyPost, meta: replyMeta } = specsBuilder.createPost(
50+
"This is a reply to the first post!",
51+
PubkyAppPostKind.Short,
52+
userMeta.url,
53+
null,
54+
null
55+
);
2556
console.log("Reply Post ID:", replyMeta.id);
2657
console.log("Reply Post URL:", replyMeta.url);
2758
console.log("Reply Data:", JSON.stringify(replyPost.toJson(), null, 2));
2859
console.log("-".repeat(60));
2960

3061
console.log("🔄 Creating Repost with Embed...");
31-
let embeed = new PubkyAppPostEmbed(`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`, PubkyAppPostKind.Video);
32-
const { post: repost, meta: repostMeta } = specsBuilder.createPost("This is a repost to random post!", PubkyAppPostKind.Short, null, embeed, null);
62+
let embeed = new PubkyAppPostEmbed(
63+
`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`,
64+
PubkyAppPostKind.Video
65+
);
66+
const { post: repost, meta: repostMeta } = specsBuilder.createPost(
67+
"This is a repost to random post!",
68+
PubkyAppPostKind.Short,
69+
null,
70+
embeed,
71+
null
72+
);
3373
console.log("Repost Post ID:", repostMeta.id);
3474
console.log("Repost Post URL:", repostMeta.url);
3575
console.log("Repost Data:", JSON.stringify(repost.toJson(), null, 2));
3676
console.log("-".repeat(60));
3777

3878
console.log("🔖 Creating Bookmark...");
39-
let { bookmark, meta: bookmarkMeta } = specsBuilder.createBookmark(`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`);
79+
let { bookmark, meta: bookmarkMeta } = specsBuilder.createBookmark(
80+
`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`
81+
);
4082
console.log("Bookmark ID:", bookmarkMeta.id);
4183
console.log("Bookmark URL:", bookmarkMeta.url);
4284
console.log("Bookmark Data:", JSON.stringify(bookmark.toJson(), null, 2));
4385
console.log("-".repeat(60));
4486

4587
console.log("👥 Creating Follow...");
46-
let {follow, meta: followMeta} = specsBuilder.createFollow(RIO);
88+
let { follow, meta: followMeta } = specsBuilder.createFollow(RIO);
4789
console.log("Follow ID:", followMeta.id);
4890
console.log("Follow URL:", followMeta.url);
4991
console.log("Follow Data:", JSON.stringify(follow.toJson(), null, 2));
5092
console.log("-".repeat(60));
5193

5294
console.log("🏷️ Creating Tag...");
53-
let {tag, meta: tagMeta} = specsBuilder.createTag(`pubky://${OTTO}/pub/pubky.app/profile.json`, "otto");
95+
let { tag, meta: tagMeta } = specsBuilder.createTag(
96+
`pubky://${OTTO}/pub/pubky.app/profile.json`,
97+
"otto"
98+
);
5499
console.log("Tag ID:", tagMeta.id);
55100
console.log("Tag URL:", tagMeta.url);
56101
console.log("Tag Data:", JSON.stringify(tag.toJson(), null, 2));
57102
console.log("-".repeat(60));
58103

59104
console.log("🔇 Creating Mute...");
60-
let {mute, meta: muteMeta} = specsBuilder.createMute(RIO);
105+
let { mute, meta: muteMeta } = specsBuilder.createMute(RIO);
61106
console.log("Mute ID:", muteMeta.id);
62107
console.log("Mute URL:", muteMeta.url);
63108
console.log("Mute Data:", JSON.stringify(mute.toJson(), null, 2));
64109
console.log("-".repeat(60));
65110

66111
console.log("📖 Creating Last Read...");
67-
let {last_read, meta: lastReadMeta} = specsBuilder.createLastRead(RIO);
112+
let { last_read, meta: lastReadMeta } = specsBuilder.createLastRead(RIO);
68113
console.log("LastRead Timestamp:", lastReadMeta.url);
69114
console.log("LastRead Data:", JSON.stringify(last_read.toJson(), null, 2));
70115
console.log("-".repeat(60));
71116

72117
console.log("💾 Creating Blob...");
73-
let { blob, meta: blobMeta } = specsBuilder.createBlob(Array.from({length: 8}, () => Math.floor(Math.random() * 256)));
118+
let { blob, meta: blobMeta } = specsBuilder.createBlob(
119+
Array.from({ length: 8 }, () => Math.floor(Math.random() * 256))
120+
);
74121
console.log("Blob ID:", blobMeta.id);
75122
console.log("Blob URL:", blobMeta.url);
76123
console.log("Blob Data:", JSON.stringify(blob.toJson(), null, 2));
77124
console.log("-".repeat(60));
78125

79126
console.log("📄 Creating File...");
80-
let { file, meta: fileMeta } = specsBuilder.createFile("My adventures", blobMeta.url, "application/pdf", 88);
127+
let { file, meta: fileMeta } = specsBuilder.createFile(
128+
"My adventures",
129+
blobMeta.url,
130+
"application/pdf",
131+
88
132+
);
81133
console.log("File ID:", fileMeta.id);
82134
console.log("File URL:", fileMeta.url);
83135
console.log("File Data:", JSON.stringify(file.toJson(), null, 2));
84136
console.log("-".repeat(60));
85137

86138
console.log("📰 Creating Feed...");
87-
let { feed, meta: feedMeta } = specsBuilder.createFeed(["mountain","hike"], "all", "columns", "recent", "image", "nature");
139+
let { feed, meta: feedMeta } = specsBuilder.createFeed(
140+
["mountain", "hike"],
141+
"all",
142+
"columns",
143+
"recent",
144+
"image",
145+
"nature"
146+
);
88147
console.log("Feed ID:", feedMeta.id);
89148
console.log("Feed URL:", feedMeta.url);
90149
console.log("Feed Data:", JSON.stringify(feed.toJson(), null, 2));
150+
console.log("-".repeat(60));
151+
152+
console.log("🔗 Utility Functions...");
153+
console.log("User URI:", userUriBuilder(OTTO));
154+
console.log("Post URI:", postUriBuilder(OTTO, meta.id));
155+
console.log("Bookmark URI:", bookmarkUriBuilder(OTTO, bookmarkMeta.id));
156+
console.log("Follow URI:", followUriBuilder(OTTO, RIO));
157+
console.log("Tag URI:", tagUriBuilder(OTTO, tagMeta.id));
158+
console.log("Mute URI:", muteUriBuilder(OTTO, RIO));
159+
console.log("LastRead URI:", lastReadUriBuilder(OTTO));
160+
console.log("Blob URI:", blobUriBuilder(OTTO, blobMeta.id));
161+
console.log("File URI:", fileUriBuilder(OTTO, fileMeta.id));
162+
91163
console.log("=".repeat(60));
92164
console.log("🎉 All Pubky App Specs examples completed successfully!");
93165
console.log("=".repeat(60));

pkg/test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,44 @@ describe("PubkySpecs Example Objects Tests", () => {
167167
assert.ok(tagJson.created_at, "Tag should have created_at timestamp");
168168
assert.ok(typeof tagJson.created_at === "number", "created_at should be a number");
169169
});
170+
it("cannot create a tag with invalid characters (comma, colon, space)", () => {
171+
const userUriRaw = `pubky://${OTTO}/pub/pubky.app/profile.json`;
172+
const userUriFromBuilder = userUriBuilder(OTTO);
173+
assert.strictEqual(userUriFromBuilder, userUriRaw, "User URI should match");
174+
175+
const invalidCases = [
176+
{ label: "otto,rio", invalidChar: "," },
177+
{ label: "otto:rio", invalidChar: ":" },
178+
{ label: "otto rio", invalidChar: " " },
179+
];
180+
181+
invalidCases.forEach(({ label, invalidChar }) => {
182+
assert.throws(
183+
() => {
184+
specsBuilder.createTag(userUriRaw, label);
185+
},
186+
(err) => {
187+
const msg = err instanceof Error ? err.message : String(err);
188+
189+
if (invalidChar === " ") {
190+
// Current implementation uses a slightly different message for whitespace
191+
assert.ok(
192+
msg.startsWith("Validation Error: Tag label has"),
193+
`Unexpected error message for whitespace: "${msg}"`
194+
);
195+
} else {
196+
assert.strictEqual(
197+
msg,
198+
`Validation Error: Tag label has invalid char: ${invalidChar}`
199+
);
200+
}
201+
202+
return true;
203+
},
204+
`Expected validation error when creating tag with invalid char '${invalidChar}' in label`
205+
);
206+
});
207+
});
170208
});
171209

172210
describe("Mute Pubky-app-specs", () => {

0 commit comments

Comments
 (0)