@atproto/lex-installer 0.0.14 → 0.0.16

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/src/nsid-set.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  import { NSID } from '@atproto/syntax'
2
2
 
3
3
  /**
4
- * A Set implementation that maps values of type K to an internal representation
5
- * I. Value identity is determined by the {@link Object.is} comparison of the
6
- * encoded values.
4
+ * A Set implementation that maps values of type K to an internal representation I.
7
5
  *
8
- * This is typically useful for values that can be serialized to a unique string
9
- * representation.
6
+ * Value identity is determined by the {@link Object.is} comparison of the
7
+ * encoded values. This is useful for complex types that can be serialized
8
+ * to a unique primitive representation (typically strings).
9
+ *
10
+ * @typeParam K - The external value type stored in the set
11
+ * @typeParam I - The internal encoded type used for identity comparison
10
12
  */
11
13
  export class MappedSet<K, I = any> implements Set<K> {
12
14
  private set = new Set<I>()
13
15
 
16
+ /**
17
+ * Creates a new MappedSet with custom encoding/decoding functions.
18
+ *
19
+ * @param encodeValue - Function to convert external values to internal representation
20
+ * @param decodeValue - Function to convert internal representation back to external values
21
+ */
14
22
  constructor(
15
23
  private readonly encodeValue: (val: K) => I,
16
24
  private readonly decodeValue: (enc: I) => K,
@@ -67,7 +75,35 @@ export class MappedSet<K, I = any> implements Set<K> {
67
75
  [Symbol.toStringTag]: string = 'MappedSet'
68
76
  }
69
77
 
78
+ /**
79
+ * A Set specialized for storing NSID (Namespaced Identifier) values.
80
+ *
81
+ * NSIDs are compared by their string representation, allowing different
82
+ * NSID object instances with the same value to be treated as equal.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { NsidSet } from '@atproto/lex-installer'
87
+ * import { NSID } from '@atproto/syntax'
88
+ *
89
+ * const nsidSet = new NsidSet()
90
+ *
91
+ * nsidSet.add(NSID.from('app.bsky.feed.post'))
92
+ * nsidSet.add(NSID.from('app.bsky.actor.profile'))
93
+ *
94
+ * // Check membership
95
+ * nsidSet.has(NSID.from('app.bsky.feed.post')) // true
96
+ *
97
+ * // Iterate over NSIDs
98
+ * for (const nsid of nsidSet) {
99
+ * console.log(nsid.toString())
100
+ * }
101
+ * ```
102
+ */
70
103
  export class NsidSet extends MappedSet<NSID, string> {
104
+ /**
105
+ * Creates a new empty NsidSet.
106
+ */
71
107
  constructor() {
72
108
  super(
73
109
  (val) => val.toString(),