pubky-app-specs 0.3.5 โ†’ 0.4.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ๐Ÿฆ„ Pubky App Specs (WASM) ยท `pubky-app-specs`
1
+ # Pubky App Specs ยท `pubky-app-specs`
2
2
 
3
3
  A WASM library for building and validating structured JSON models compatible with Pubky.App social powered by [`@synonymdev/pubky`](https://www.npmjs.com/package/@synonymdev/pubky). It handles domain objects like **Users**, **Posts**, **Feeds**, **Bookmarks**, **Tags**, and more. Each object is:
4
4
 
@@ -24,27 +24,28 @@ npm install pubky-app-specs
24
24
  yarn add pubky-app-specs
25
25
  ```
26
26
 
27
- > **Note**: This package uses WASM. Ensure your bundler or environment supports loading WASM modules (e.g. Next.js, Vite, etc.).
27
+ > **Note**: This package uses WASM with embedded bytes for automatic initialization. No manual WASM loading required - just import and use!
28
28
 
29
29
  ---
30
30
 
31
31
  ## ๐Ÿš€ Quick Start
32
32
 
33
- 1. **Initialize** the WASM module.
33
+ 1. **Import** the library.
34
34
  2. **Construct** a `PubkySpecsBuilder(pubkyId)` object.
35
35
  3. **Create** validated domain objects (User, Post, Tag, etc.).
36
36
  4. **Store** them on the [PubKy homeserver](https://github.com/synonymdev/pubky) or any distributed storage solution you prefer.
37
37
 
38
- ### Import & Initialize
38
+ ### Import & Usage
39
39
 
40
40
  ```js
41
- import init, { PubkySpecsBuilder } from "pubky-app-specs";
41
+ // ES Modules
42
+ import { PubkySpecsBuilder } from "pubky-app-specs";
42
43
 
43
- async function loadSpecs(pubkyId) {
44
- // 1. Initialize WASM
45
- await init();
44
+ // OR CommonJS
45
+ const { PubkySpecsBuilder } = require("pubky-app-specs/index.cjs");
46
46
 
47
- // 2. Create a specs builder instance
47
+ function loadSpecs(pubkyId) {
48
+ // Create a specs builder instance - WASM is already initialized
48
49
  const specs = new PubkySpecsBuilder(pubkyId);
49
50
  return specs;
50
51
  }
@@ -67,7 +68,7 @@ async function createUser(pubkyId) {
67
68
  const specs = new PubkySpecsBuilder(pubkyId);
68
69
 
69
70
  // Create user object with minimal fields
70
- const userResult = specs.createUser(
71
+ const {user, meta} = specs.createUser(
71
72
  "Alice", // Name
72
73
  "Hello from WASM", // Bio
73
74
  null, // Image URL or File
@@ -75,11 +76,11 @@ async function createUser(pubkyId) {
75
76
  "active" // Status
76
77
  );
77
78
 
78
- // userResult.meta contains { id, path, url }.
79
- // userResult.user is the Rust "PubkyAppUser" object.
79
+ // meta contains { id, path, url }.
80
+ // user is the Rust "PubkyAppUser" object.
80
81
 
81
82
  // We bring the Rust object to JS using the .toJson() method.
82
- const userJson = userResult.user.toJson();
83
+ const userJson = user.toJson();
83
84
 
84
85
  // Store in homeserver via pubky
85
86
  const response = await client.fetch(userResult.meta.url, {
@@ -109,7 +110,7 @@ async function createPost(pubkyId, content) {
109
110
  const specs = new PubkySpecsBuilder(pubkyId);
110
111
 
111
112
  // Create the Post object referencing your (optional) attachment
112
- const postResult = specs.createPost(
113
+ const {post, meta} = specs.createPost(
113
114
  content,
114
115
  PubkyAppPostKind.Short,
115
116
  null, // parent post
@@ -118,14 +119,14 @@ async function createPost(pubkyId, content) {
118
119
  );
119
120
 
120
121
  // Store the post
121
- const postJson = postResult.post.toJson();
122
- await client.fetch(postResult.meta.url, {
122
+ const postJson = post.toJson();
123
+ await client.fetch(meta.url, {
123
124
  method: "PUT",
124
125
  body: JSON.stringify(postJson),
125
126
  });
126
127
 
127
- console.log("Post stored at:", postResult.meta.url);
128
- return postResult;
128
+ console.log("Post stored at:", meta.url);
129
+ return {post, meta};
129
130
  }
130
131
  ```
131
132
 
@@ -139,12 +140,12 @@ async function followUser(myPubkyId, userToFollow) {
139
140
  const client = new Client();
140
141
  const specs = new PubkySpecsBuilder(myPubkyId);
141
142
 
142
- const followResult = specs.createFollow(userToFollow);
143
+ const {follow, meta} = specs.createFollow(userToFollow);
143
144
 
144
145
  // We only need to store the JSON in the homeserver
145
- await client.fetch(followResult.meta.url, {
146
+ await client.fetch(meta.url, {
146
147
  method: "PUT",
147
- body: JSON.stringify(followResult.follow.toJson()),
148
+ body: JSON.stringify(follow.toJson()),
148
149
  });
149
150
 
150
151
  console.log(`Successfully followed: ${userToFollow}`);
package/example.js ADDED
@@ -0,0 +1,93 @@
1
+ import { PubkyAppPostKind, PubkySpecsBuilder, PubkyAppPostEmbed } from "./index.js";
2
+
3
+ const OTTO = "8kkppkmiubfq4pxn6f73nqrhhhgkb5xyfprntc9si3np9ydbotto";
4
+ const RIO = "dzswkfy7ek3bqnoc89jxuqqfbzhjrj6mi8qthgbxxcqkdugm3rio";
5
+
6
+ // ๐Ÿ‘ค Create a user profile
7
+ console.log("๐Ÿ‘ค Creating User Profile...");
8
+ const specsBuilder = new PubkySpecsBuilder(OTTO);
9
+ const { user, meta: userMeta } =
10
+ specsBuilder.createUser("Alice Smith", "Software Developer", null, null, "active");
11
+ console.log("User Profile URL:", userMeta.url);
12
+ console.log("User Data:", JSON.stringify(user.toJson(), null, 2));
13
+ console.log("-".repeat(60));
14
+
15
+ // ๐Ÿ“ Create different posts
16
+ console.log("๐Ÿ“ Creating First Post...");
17
+ const { post, meta } = specsBuilder.createPost("Hello, Pubky world! This is my first post.", PubkyAppPostKind.Short, null, null, null);
18
+ console.log("Post ID:", meta.id);
19
+ console.log("Post URL:", meta.url);
20
+ console.log("Post Data:", JSON.stringify(post.toJson(), null, 2));
21
+ console.log("-".repeat(60));
22
+
23
+ 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);
25
+ console.log("Reply Post ID:", replyMeta.id);
26
+ console.log("Reply Post URL:", replyMeta.url);
27
+ console.log("Reply Data:", JSON.stringify(replyPost.toJson(), null, 2));
28
+ console.log("-".repeat(60));
29
+
30
+ 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);
33
+ console.log("Repost Post ID:", repostMeta.id);
34
+ console.log("Repost Post URL:", repostMeta.url);
35
+ console.log("Repost Data:", JSON.stringify(repost.toJson(), null, 2));
36
+ console.log("-".repeat(60));
37
+
38
+ console.log("๐Ÿ”– Creating Bookmark...");
39
+ let { bookmark, meta: bookmarkMeta } = specsBuilder.createBookmark(`pubky://${RIO}/pub/pubky.app/posts/0033SREKPC4N0`);
40
+ console.log("Bookmark ID:", bookmarkMeta.id);
41
+ console.log("Bookmark URL:", bookmarkMeta.url);
42
+ console.log("Bookmark Data:", JSON.stringify(bookmark.toJson(), null, 2));
43
+ console.log("-".repeat(60));
44
+
45
+ console.log("๐Ÿ‘ฅ Creating Follow...");
46
+ let {follow, meta: followMeta} = specsBuilder.createFollow(RIO);
47
+ console.log("Follow ID:", followMeta.id);
48
+ console.log("Follow URL:", followMeta.url);
49
+ console.log("Follow Data:", JSON.stringify(follow.toJson(), null, 2));
50
+ console.log("-".repeat(60));
51
+
52
+ console.log("๐Ÿท๏ธ Creating Tag...");
53
+ let {tag, meta: tagMeta} = specsBuilder.createTag(`pubky://${OTTO}/pub/pubky.app/profile.json`, "otto");
54
+ console.log("Tag ID:", tagMeta.id);
55
+ console.log("Tag URL:", tagMeta.url);
56
+ console.log("Tag Data:", JSON.stringify(tag.toJson(), null, 2));
57
+ console.log("-".repeat(60));
58
+
59
+ console.log("๐Ÿ”‡ Creating Mute...");
60
+ let {mute, meta: muteMeta} = specsBuilder.createMute(RIO);
61
+ console.log("Mute ID:", muteMeta.id);
62
+ console.log("Mute URL:", muteMeta.url);
63
+ console.log("Mute Data:", JSON.stringify(mute.toJson(), null, 2));
64
+ console.log("-".repeat(60));
65
+
66
+ console.log("๐Ÿ“– Creating Last Read...");
67
+ let {last_read, meta: lastReadMeta} = specsBuilder.createLastRead(RIO);
68
+ console.log("LastRead Timestamp:", lastReadMeta.url);
69
+ console.log("LastRead Data:", JSON.stringify(last_read.toJson(), null, 2));
70
+ console.log("-".repeat(60));
71
+
72
+ console.log("๐Ÿ’พ Creating Blob...");
73
+ let { blob, meta: blobMeta } = specsBuilder.createBlob(Array.from({length: 8}, () => Math.floor(Math.random() * 256)));
74
+ console.log("Blob ID:", blobMeta.id);
75
+ console.log("Blob URL:", blobMeta.url);
76
+ console.log("Blob Data:", JSON.stringify(blob.toJson(), null, 2));
77
+ console.log("-".repeat(60));
78
+
79
+ console.log("๐Ÿ“„ Creating File...");
80
+ let { file, meta: fileMeta } = specsBuilder.createFile("My adventures", blobMeta.url, "application/pdf", 88);
81
+ console.log("File ID:", fileMeta.id);
82
+ console.log("File URL:", fileMeta.url);
83
+ console.log("File Data:", JSON.stringify(file.toJson(), null, 2));
84
+ console.log("-".repeat(60));
85
+
86
+ console.log("๐Ÿ“ฐ Creating Feed...");
87
+ let { feed, meta: feedMeta } = specsBuilder.createFeed(["mountain","hike"], "all", "columns", "recent", "image", "nature");
88
+ console.log("Feed ID:", feedMeta.id);
89
+ console.log("Feed URL:", feedMeta.url);
90
+ console.log("Feed Data:", JSON.stringify(feed.toJson(), null, 2));
91
+ console.log("=".repeat(60));
92
+ console.log("๐ŸŽ‰ All Pubky App Specs examples completed successfully!");
93
+ console.log("=".repeat(60));