articulated 1.2.0 → 1.3.0

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.
@@ -22,6 +22,12 @@ export declare class ElementIdGenerator {
22
22
  * { bunchId: beforeId.bunchId, counter: beforeId.counter + 1 }
23
23
  * ```
24
24
  * which compresses well when inserted after beforeId.
25
+ *
26
+ * @param count Provide this if you are planning to bulk-insert `count` ids from left-to-right
27
+ * (by supplying the same `count` to insertAfter/insertBefore).
28
+ * Only the first id is returned, but we will reserve space for the other ids so that
29
+ * they are not generated again.
30
+ * @throws If count is provided but is not >= 1.
25
31
  */
26
- generateAfter(beforeId: ElementId | null): ElementId;
32
+ generateAfter(beforeId: ElementId | null, count?: number): ElementId;
27
33
  }
@@ -25,19 +25,28 @@ class ElementIdGenerator {
25
25
  * { bunchId: beforeId.bunchId, counter: beforeId.counter + 1 }
26
26
  * ```
27
27
  * which compresses well when inserted after beforeId.
28
+ *
29
+ * @param count Provide this if you are planning to bulk-insert `count` ids from left-to-right
30
+ * (by supplying the same `count` to insertAfter/insertBefore).
31
+ * Only the first id is returned, but we will reserve space for the other ids so that
32
+ * they are not generated again.
33
+ * @throws If count is provided but is not >= 1.
28
34
  */
29
- generateAfter(beforeId) {
35
+ generateAfter(beforeId, count = 1) {
36
+ if (!(Number.isSafeInteger(count) && count >= 1)) {
37
+ throw new Error(`Invalid count: ${count}`);
38
+ }
30
39
  if (beforeId !== null) {
31
40
  const nextCounter = this.nextCounterMap.get(beforeId.bunchId);
32
41
  if (nextCounter !== undefined && nextCounter === beforeId.counter + 1) {
33
42
  // It's our own ElementId and the last in its bunch. Extend the bunch.
34
- this.nextCounterMap.set(beforeId.bunchId, nextCounter + 1);
43
+ this.nextCounterMap.set(beforeId.bunchId, nextCounter + count);
35
44
  return { bunchId: beforeId.bunchId, counter: nextCounter };
36
45
  }
37
46
  }
38
47
  // In all other cases, start a new bunch.
39
48
  const bunchId = this.newBunchId();
40
- this.nextCounterMap.set(bunchId, 1);
49
+ this.nextCounterMap.set(bunchId, count);
41
50
  return { bunchId, counter: 0 };
42
51
  }
43
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"element_id_generator.js","sourceRoot":"","sources":["../../src/element_id_generator.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,kBAAkB;IAM7B;;;OAGG;IACH,YAA6B,UAAwB;QAAxB,eAAU,GAAV,UAAU,CAAc;QATrD;;WAEG;QACc,mBAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IAMJ,CAAC;IAEzD;;;;;;;;;OASG;IACH,aAAa,CAAC,QAA0B;QACtC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC9D,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,QAAQ,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;gBACtE,sEAAsE;gBACtE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;gBAC3D,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;YAC7D,CAAC;QACH,CAAC;QAED,yCAAyC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACjC,CAAC;CACF;AArCD,gDAqCC"}
1
+ {"version":3,"file":"element_id_generator.js","sourceRoot":"","sources":["../../src/element_id_generator.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,kBAAkB;IAM7B;;;OAGG;IACH,YAA6B,UAAwB;QAAxB,eAAU,GAAV,UAAU,CAAc;QATrD;;WAEG;QACc,mBAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;IAMJ,CAAC;IAEzD;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,QAA0B,EAAE,KAAK,GAAG,CAAC;QACjD,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC9D,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,QAAQ,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;gBACtE,sEAAsE;gBACtE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,KAAK,CAAC,CAAC;gBAC/D,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;YAC7D,CAAC;QACH,CAAC;QAED,yCAAyC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACjC,CAAC;CACF;AA/CD,gDA+CC"}
@@ -22,6 +22,12 @@ export declare class ElementIdGenerator {
22
22
  * { bunchId: beforeId.bunchId, counter: beforeId.counter + 1 }
23
23
  * ```
24
24
  * which compresses well when inserted after beforeId.
25
+ *
26
+ * @param count Provide this if you are planning to bulk-insert `count` ids from left-to-right
27
+ * (by supplying the same `count` to insertAfter/insertBefore).
28
+ * Only the first id is returned, but we will reserve space for the other ids so that
29
+ * they are not generated again.
30
+ * @throws If count is provided but is not >= 1.
25
31
  */
26
- generateAfter(beforeId: ElementId | null): ElementId;
32
+ generateAfter(beforeId: ElementId | null, count?: number): ElementId;
27
33
  }
@@ -22,19 +22,28 @@ export class ElementIdGenerator {
22
22
  * { bunchId: beforeId.bunchId, counter: beforeId.counter + 1 }
23
23
  * ```
24
24
  * which compresses well when inserted after beforeId.
25
+ *
26
+ * @param count Provide this if you are planning to bulk-insert `count` ids from left-to-right
27
+ * (by supplying the same `count` to insertAfter/insertBefore).
28
+ * Only the first id is returned, but we will reserve space for the other ids so that
29
+ * they are not generated again.
30
+ * @throws If count is provided but is not >= 1.
25
31
  */
26
- generateAfter(beforeId) {
32
+ generateAfter(beforeId, count = 1) {
33
+ if (!(Number.isSafeInteger(count) && count >= 1)) {
34
+ throw new Error(`Invalid count: ${count}`);
35
+ }
27
36
  if (beforeId !== null) {
28
37
  const nextCounter = this.nextCounterMap.get(beforeId.bunchId);
29
38
  if (nextCounter !== undefined && nextCounter === beforeId.counter + 1) {
30
39
  // It's our own ElementId and the last in its bunch. Extend the bunch.
31
- this.nextCounterMap.set(beforeId.bunchId, nextCounter + 1);
40
+ this.nextCounterMap.set(beforeId.bunchId, nextCounter + count);
32
41
  return { bunchId: beforeId.bunchId, counter: nextCounter };
33
42
  }
34
43
  }
35
44
  // In all other cases, start a new bunch.
36
45
  const bunchId = this.newBunchId();
37
- this.nextCounterMap.set(bunchId, 1);
46
+ this.nextCounterMap.set(bunchId, count);
38
47
  return { bunchId, counter: 0 };
39
48
  }
40
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"element_id_generator.js","sourceRoot":"","sources":["../../src/element_id_generator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAM7B;;;OAGG;IACH,YAA6B,UAAwB;QAAxB,eAAU,GAAV,UAAU,CAAc;QATrD;;WAEG;QACc,mBAAc,GAA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,EAAE,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC9D,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,QAAQ,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;gBACtE,sEAAsE;gBACtE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,KAAK,CAAC,CAAC;gBAC/D,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;YAC7D,CAAC;QACH,CAAC;QAED,yCAAyC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACjC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "articulated",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A TypeScript library for managing stable element identifiers in mutable lists",
5
5
  "author": "Matthew Weidner",
6
6
  "license": "MIT",
@@ -24,20 +24,30 @@ export class ElementIdGenerator {
24
24
  * { bunchId: beforeId.bunchId, counter: beforeId.counter + 1 }
25
25
  * ```
26
26
  * which compresses well when inserted after beforeId.
27
+ *
28
+ * @param count Provide this if you are planning to bulk-insert `count` ids from left-to-right
29
+ * (by supplying the same `count` to insertAfter/insertBefore).
30
+ * Only the first id is returned, but we will reserve space for the other ids so that
31
+ * they are not generated again.
32
+ * @throws If count is provided but is not >= 1.
27
33
  */
28
- generateAfter(beforeId: ElementId | null): ElementId {
34
+ generateAfter(beforeId: ElementId | null, count = 1): ElementId {
35
+ if (!(Number.isSafeInteger(count) && count >= 1)) {
36
+ throw new Error(`Invalid count: ${count}`);
37
+ }
38
+
29
39
  if (beforeId !== null) {
30
40
  const nextCounter = this.nextCounterMap.get(beforeId.bunchId);
31
41
  if (nextCounter !== undefined && nextCounter === beforeId.counter + 1) {
32
42
  // It's our own ElementId and the last in its bunch. Extend the bunch.
33
- this.nextCounterMap.set(beforeId.bunchId, nextCounter + 1);
43
+ this.nextCounterMap.set(beforeId.bunchId, nextCounter + count);
34
44
  return { bunchId: beforeId.bunchId, counter: nextCounter };
35
45
  }
36
46
  }
37
47
 
38
48
  // In all other cases, start a new bunch.
39
49
  const bunchId = this.newBunchId();
40
- this.nextCounterMap.set(bunchId, 1);
50
+ this.nextCounterMap.set(bunchId, count);
41
51
  return { bunchId, counter: 0 };
42
52
  }
43
53
  }