pubky-app-specs 0.4.2 → 0.4.4

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
@@ -71,12 +71,12 @@ async function createUser(pubkyId) {
71
71
  const specs = new PubkySpecsBuilder(pubkyId);
72
72
 
73
73
  // Create user object with minimal fields
74
- const {user, meta} = specs.createUser(
74
+ const { user, meta } = specs.createUser(
75
75
  "Alice", // Name
76
76
  "Hello from WASM", // Bio
77
77
  null, // Image URL or File
78
78
  null, // Links
79
- "active" // Status
79
+ "active", // Status
80
80
  );
81
81
 
82
82
  // meta contains { id, path, url }.
@@ -112,12 +112,12 @@ async function createPost(pubkyId, content) {
112
112
  const specs = new PubkySpecsBuilder(pubkyId);
113
113
 
114
114
  // Create the Post object
115
- const {post, meta} = specs.createPost(
115
+ const { post, meta } = specs.createPost(
116
116
  content,
117
117
  PubkyAppPostKind.Short,
118
118
  null, // parent post URI (for replies)
119
119
  null, // embed object (for reposts)
120
- null // attachments (array of file URLs, max 3)
120
+ null, // attachments (array of file URLs, max 3)
121
121
  );
122
122
 
123
123
  // Store the post
@@ -128,7 +128,7 @@ async function createPost(pubkyId, content) {
128
128
  });
129
129
 
130
130
  console.log("Post stored at:", meta.url);
131
- return {post, meta};
131
+ return { post, meta };
132
132
  }
133
133
  ```
134
134
 
@@ -143,12 +143,12 @@ async function createPostWithAttachments(pubkyId, content, fileUrls) {
143
143
  const specs = new PubkySpecsBuilder(pubkyId);
144
144
 
145
145
  // Create post with attachments (max 3 allowed)
146
- const {post, meta} = specs.createPost(
146
+ const { post, meta } = specs.createPost(
147
147
  content,
148
148
  PubkyAppPostKind.Image,
149
149
  null, // parent
150
150
  null, // embed
151
- fileUrls // e.g. ["pubky://user/pub/pubky.app/files/abc123"]
151
+ fileUrls, // e.g. ["pubky://user/pub/pubky.app/files/abc123"]
152
152
  );
153
153
 
154
154
  const postJson = post.toJson();
@@ -160,7 +160,7 @@ async function createPostWithAttachments(pubkyId, content, fileUrls) {
160
160
  });
161
161
 
162
162
  console.log("Post with attachments stored at:", meta.url);
163
- return {post, meta};
163
+ return { post, meta };
164
164
  }
165
165
  ```
166
166
 
@@ -174,7 +174,7 @@ async function followUser(myPubkyId, userToFollow) {
174
174
  const client = new Client();
175
175
  const specs = new PubkySpecsBuilder(myPubkyId);
176
176
 
177
- const {follow, meta} = specs.createFollow(userToFollow);
177
+ const { follow, meta } = specs.createFollow(userToFollow);
178
178
 
179
179
  // We only need to store the JSON in the homeserver
180
180
  await client.fetch(meta.url, {
@@ -215,7 +215,7 @@ async function uploadFile(pubkyId, fileData, fileName, contentType, fileSize) {
215
215
 
216
216
  // First, create and store the blob (raw binary data)
217
217
  const { blob, meta: blobMeta } = specs.createBlob(fileData);
218
-
218
+
219
219
  await client.fetch(blobMeta.url, {
220
220
  method: "PUT",
221
221
  body: JSON.stringify(blob.toJson()),
@@ -223,10 +223,10 @@ async function uploadFile(pubkyId, fileData, fileName, contentType, fileSize) {
223
223
 
224
224
  // Then create the file metadata pointing to the blob
225
225
  const { file, meta: fileMeta } = specs.createFile(
226
- fileName, // e.g. "vacation-photo.jpg"
227
- blobMeta.url, // Reference to the blob
228
- contentType, // e.g. "image/jpeg"
229
- fileSize // Size in bytes
226
+ fileName, // e.g. "vacation-photo.jpg"
227
+ blobMeta.url, // Reference to the blob
228
+ contentType, // e.g. "image/jpeg"
229
+ fileSize, // Size in bytes
230
230
  );
231
231
 
232
232
  await client.fetch(fileMeta.url, {
@@ -287,16 +287,16 @@ const userId = "8kkppkmiubfq4pxn6f73nqrhhhgkb5xyfprntc9si3np9ydbotto";
287
287
  const targetUserId = "dzswkfy7ek3bqnoc89jxuqqfbzhjrj6mi8qthgbxxcqkdugm3rio";
288
288
 
289
289
  // Build URIs for different resources
290
- userUriBuilder(userId); // pubky://{userId}/pub/pubky.app/profile.json
291
- postUriBuilder(userId, "0033SSE3B1FQ0"); // pubky://{userId}/pub/pubky.app/posts/{postId}
292
- bookmarkUriBuilder(userId, "ABC123"); // pubky://{userId}/pub/pubky.app/bookmarks/{bookmarkId}
293
- followUriBuilder(userId, targetUserId); // pubky://{userId}/pub/pubky.app/follows/{targetUserId}
294
- tagUriBuilder(userId, "XYZ789"); // pubky://{userId}/pub/pubky.app/tags/{tagId}
295
- muteUriBuilder(userId, targetUserId); // pubky://{userId}/pub/pubky.app/mutes/{targetUserId}
296
- lastReadUriBuilder(userId); // pubky://{userId}/pub/pubky.app/last_read
297
- blobUriBuilder(userId, "BLOB123"); // pubky://{userId}/pub/pubky.app/blobs/{blobId}
298
- fileUriBuilder(userId, "FILE456"); // pubky://{userId}/pub/pubky.app/files/{fileId}
299
- feedUriBuilder(userId, "FEED789"); // pubky://{userId}/pub/pubky.app/feeds/{feedId}
290
+ userUriBuilder(userId); // pubky://{userId}/pub/pubky.app/profile.json
291
+ postUriBuilder(userId, "0033SSE3B1FQ0"); // pubky://{userId}/pub/pubky.app/posts/{postId}
292
+ bookmarkUriBuilder(userId, "ABC123"); // pubky://{userId}/pub/pubky.app/bookmarks/{bookmarkId}
293
+ followUriBuilder(userId, targetUserId); // pubky://{userId}/pub/pubky.app/follows/{targetUserId}
294
+ tagUriBuilder(userId, "XYZ789"); // pubky://{userId}/pub/pubky.app/tags/{tagId}
295
+ muteUriBuilder(userId, targetUserId); // pubky://{userId}/pub/pubky.app/mutes/{targetUserId}
296
+ lastReadUriBuilder(userId); // pubky://{userId}/pub/pubky.app/last_read
297
+ blobUriBuilder(userId, "BLOB123"); // pubky://{userId}/pub/pubky.app/blobs/{blobId}
298
+ fileUriBuilder(userId, "FILE456"); // pubky://{userId}/pub/pubky.app/files/{fileId}
299
+ feedUriBuilder(userId, "FEED789"); // pubky://{userId}/pub/pubky.app/feeds/{feedId}
300
300
  ```
301
301
 
302
302
  ---
@@ -330,6 +330,80 @@ A `ParsedUriResult` object with:
330
330
 
331
331
  ---
332
332
 
333
+ ## Validation limits
334
+
335
+ Validation limits are published as JSON so UIs and tests can reuse the
336
+ canonical rules without WASM, plus optional WASM accessors when needed.
337
+
338
+ ### ✅ Recommended (no WASM)
339
+
340
+ **Named export from the package root:**
341
+
342
+ ```js
343
+ import { validationLimits, getValidationLimits } from "pubky-app-specs";
344
+
345
+ console.log(validationLimits);
346
+ const copy = getValidationLimits();
347
+ ```
348
+
349
+ **Direct subpath import (ESM):**
350
+
351
+ ```js
352
+ import limits from "pubky-app-specs/validationLimits";
353
+ // or
354
+ import limitsJson from "pubky-app-specs/validationLimits.json";
355
+ ```
356
+
357
+ **Direct subpath import (CJS):**
358
+
359
+ ```js
360
+ const { validationLimits, getValidationLimits } = require("pubky-app-specs");
361
+ // or
362
+ const limits = require("pubky-app-specs/validationLimits");
363
+ ```
364
+
365
+ ### WASM accessors
366
+
367
+ ```js
368
+ import { PubkySpecsBuilder, getValidationLimits } from "pubky-app-specs";
369
+
370
+ const limitsFromWasm = getValidationLimits();
371
+
372
+ const builder = new PubkySpecsBuilder("pubky_id_here");
373
+ const limitsFromBuilder = builder.validationLimits;
374
+ ```
375
+
376
+ Example output shape:
377
+
378
+ ```json
379
+ {
380
+ "maxBlobSizeBytes": 104857600,
381
+ "maxFileSizeBytes": 104857600,
382
+ "tagLabelMinLength": 1,
383
+ "tagLabelMaxLength": 20,
384
+ "tagInvalidChars": [",", ":", " ", "\t", "\n", "\r"],
385
+ "userNameMinLength": 3,
386
+ "userNameMaxLength": 50,
387
+ "userBioMaxLength": 160,
388
+ "userImageUrlMaxLength": 300,
389
+ "userLinksMaxCount": 5,
390
+ "userLinkTitleMaxLength": 100,
391
+ "userLinkUrlMaxLength": 300,
392
+ "userStatusMaxLength": 50,
393
+ "postShortContentMaxLength": 2000,
394
+ "postLongContentMaxLength": 50000,
395
+ "postAttachmentsMaxCount": 4,
396
+ "postAttachmentUrlMaxLength": 200,
397
+ "postAllowedAttachmentProtocols": ["pubky", "http", "https"],
398
+ "fileNameMinLength": 1,
399
+ "fileNameMaxLength": 255,
400
+ "fileSrcMaxLength": 1024,
401
+ "feedTagsMaxCount": 5
402
+ }
403
+ ```
404
+
405
+ ---
406
+
333
407
  ## 📄 License
334
408
 
335
409
  MIT
package/index.cjs CHANGED
@@ -446,6 +446,24 @@ module.exports.lastReadUriBuilder = function(author_id) {
446
446
  }
447
447
  };
448
448
 
449
+ /**
450
+ * Each FFI function:
451
+ * - Accepts minimal fields in a JavaScript-friendly manner (e.g. strings, JSON).
452
+ * - Creates the Rust model, sanitizes, and validates it.
453
+ * - Generates the ID (if applicable).
454
+ * - Generates the path (if applicable).
455
+ * - Returns { json, id, path, url } or a descriptive error.
456
+ * Returns validation limits as a JSON value for client-side use without a builder.
457
+ * @returns {any}
458
+ */
459
+ module.exports.getValidationLimits = function() {
460
+ const ret = wasm.getValidationLimits();
461
+ if (ret[2]) {
462
+ throw takeFromExternrefTable0(ret[1]);
463
+ }
464
+ return takeFromExternrefTable0(ret[0]);
465
+ };
466
+
449
467
  /**
450
468
  * Returns the list of valid MIME types for file attachments.
451
469
  *
@@ -815,14 +833,7 @@ module.exports.LastReadResult = LastReadResult;
815
833
  const MetaFinalization = (typeof FinalizationRegistry === 'undefined')
816
834
  ? { register: () => {}, unregister: () => {} }
817
835
  : new FinalizationRegistry(ptr => wasm.__wbg_meta_free(ptr >>> 0, 1));
818
- /**
819
- * Each FFI function:
820
- * - Accepts minimal fields in a JavaScript-friendly manner (e.g. strings, JSON).
821
- * - Creates the Rust model, sanitizes, and validates it.
822
- * - Generates the ID (if applicable).
823
- * - Generates the path (if applicable).
824
- * - Returns { json, id, path, url } or a descriptive error.
825
- */
836
+
826
837
  class Meta {
827
838
 
828
839
  static __wrap(ptr) {
@@ -2311,6 +2322,17 @@ class PubkySpecsBuilder {
2311
2322
  PubkySpecsBuilderFinalization.register(this, this.__wbg_ptr, this);
2312
2323
  return this;
2313
2324
  }
2325
+ /**
2326
+ * Returns validation limits as a JSON value for client-side use.
2327
+ * @returns {any}
2328
+ */
2329
+ get validationLimits() {
2330
+ const ret = wasm.pubkyspecsbuilder_validationLimits(this.__wbg_ptr);
2331
+ if (ret[2]) {
2332
+ throw takeFromExternrefTable0(ret[1]);
2333
+ }
2334
+ return takeFromExternrefTable0(ret[0]);
2335
+ }
2314
2336
  /**
2315
2337
  * @param {string} name
2316
2338
  * @param {string | null | undefined} bio
@@ -2617,6 +2639,11 @@ module.exports.__wbg_entries_3265d4158b33e5dc = function(arg0) {
2617
2639
  return ret;
2618
2640
  };
2619
2641
 
2642
+ module.exports.__wbg_fromCodePoint_f37c25c172f2e8b5 = function() { return handleError(function (arg0) {
2643
+ const ret = String.fromCodePoint(arg0 >>> 0);
2644
+ return ret;
2645
+ }, arguments) };
2646
+
2620
2647
  module.exports.__wbg_get_67b2ba62fc30de12 = function() { return handleError(function (arg0, arg1) {
2621
2648
  const ret = Reflect.get(arg0, arg1);
2622
2649
  return ret;