lib0 0.2.82 → 0.2.84

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/crypto/jwt.d.ts CHANGED
@@ -3,4 +3,8 @@ export function verifyJwt(publicKey: CryptoKey, jwt: string): Promise<{
3
3
  header: any;
4
4
  payload: any;
5
5
  }>;
6
+ export function unsafeDecode(jwt: string): {
7
+ header: any;
8
+ payload: any;
9
+ };
6
10
  //# sourceMappingURL=jwt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB;AAOM,kCAFI,MAAM;;;EAQhB"}
package/crypto/jwt.js CHANGED
@@ -50,3 +50,16 @@ export const verifyJwt = async (publicKey, jwt) => {
50
50
  payload: _parse(payloadBase64)
51
51
  }
52
52
  }
53
+
54
+ /**
55
+ * Decode a jwt without verifying it. Probably a bad idea to use this. Only use if you know the jwt was already verified!
56
+ *
57
+ * @param {string} jwt
58
+ */
59
+ export const unsafeDecode = jwt => {
60
+ const [headerBase64, payloadBase64] = jwt.split('.')
61
+ return {
62
+ header: _parse(headerBase64),
63
+ payload: _parse(payloadBase64)
64
+ }
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAYO,6BAFI,EAAE,QAAQ,iBAgBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBAzRkB,cAAc"}
1
+ {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAWO,6BAFI,EAAE,QAAQ,iBAkBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBA1RkB,cAAc"}
@@ -3,4 +3,8 @@ export function verifyJwt(publicKey: CryptoKey, jwt: string): Promise<{
3
3
  header: any;
4
4
  payload: any;
5
5
  }>;
6
+ export function unsafeDecode(jwt: string): {
7
+ header: any;
8
+ payload: any;
9
+ };
6
10
  //# sourceMappingURL=jwt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../crypto/jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../crypto/jwt.js"],"names":[],"mappings":"AAoBO,sCAHI,SAAS,WACT,MAAM,uBAgBhB;AAMM,qCAHI,SAAS,OACT,MAAM;;;GAahB;AAOM,kCAFI,MAAM;;;EAQhB"}
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../crypto.test.js"],"names":[],"mappings":"AAYO,6BAFI,EAAE,QAAQ,iBAgBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBAzRkB,cAAc"}
1
+ {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../crypto.test.js"],"names":[],"mappings":"AAWO,6BAFI,EAAE,QAAQ,iBAkBpB;AAKM,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBA1RkB,cAAc"}
@@ -1,3 +1,4 @@
1
+ export function testSelfReferencingHash(_tc: t.TestCase): void;
1
2
  export function testSha256Basics(_tc: t.TestCase): Promise<void>;
2
3
  export function testLargeValue(_tc: t.TestCase): Promise<void>;
3
4
  export function testRepeatSha256Hashing(tc: t.TestCase): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"sha256.test.d.ts","sourceRoot":"","sources":["../../hash/sha256.test.js"],"names":[],"mappings":"AAcO,sCAFI,EAAE,QAAQ,iBA2BpB;AAOM,oCAFI,EAAE,QAAQ,iBA4BpB;AAKM,4CAFI,EAAE,QAAQ,iBAQpB;AAKM,yCAFI,EAAE,QAAQ,iBAmDpB;mBAzIkB,eAAe"}
1
+ {"version":3,"file":"sha256.test.d.ts","sourceRoot":"","sources":["../../hash/sha256.test.js"],"names":[],"mappings":"AAcO,6CAFI,EAAE,QAAQ,QAKpB;AAKM,sCAFI,EAAE,QAAQ,iBA2BpB;AAOM,oCAFI,EAAE,QAAQ,iBA4BpB;AAKM,4CAFI,EAAE,QAAQ,iBAQpB;AAKM,yCAFI,EAAE,QAAQ,iBAmDpB;mBAjJkB,eAAe"}
package/dist/jwt.cjs CHANGED
@@ -68,6 +68,20 @@ const verifyJwt = async (publicKey, jwt) => {
68
68
  }
69
69
  };
70
70
 
71
+ /**
72
+ * Decode a jwt without verifying it. Probably a bad idea to use this. Only use if you know the jwt was already verified!
73
+ *
74
+ * @param {string} jwt
75
+ */
76
+ const unsafeDecode = jwt => {
77
+ const [headerBase64, payloadBase64] = jwt.split('.');
78
+ return {
79
+ header: _parse(headerBase64),
80
+ payload: _parse(payloadBase64)
81
+ }
82
+ };
83
+
71
84
  exports.encodeJwt = encodeJwt;
85
+ exports.unsafeDecode = unsafeDecode;
72
86
  exports.verifyJwt = verifyJwt;
73
87
  //# sourceMappingURL=jwt.cjs.map
package/dist/jwt.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.cjs","sources":["../crypto/jwt.js"],"sourcesContent":["import * as error from '../error.js'\nimport * as buffer from '../buffer.js'\nimport * as string from '../string.js'\nimport * as json from '../json.js'\nimport * as ecdsa from '../crypto/ecdsa.js'\n\n/**\n * @param {Object} data\n */\nconst _stringify = data => buffer.toBase64UrlEncoded(string.encodeUtf8(json.stringify(data)))\n\n/**\n * @param {string} base64url\n */\nconst _parse = base64url => json.parse(string.decodeUtf8(buffer.fromBase64UrlEncoded(base64url)))\n\n/**\n * @param {CryptoKey} privateKey\n * @param {Object} payload\n */\nexport const encodeJwt = (privateKey, payload) => {\n const { name: algName, namedCurve: algCurve } = /** @type {any} */ (privateKey.algorithm)\n /* c8 ignore next 3 */\n if (algName !== 'ECDSA' || algCurve !== 'P-384') {\n error.unexpectedCase()\n }\n const header = {\n alg: 'ES384',\n typ: 'JWT'\n }\n const jwt = _stringify(header) + '.' + _stringify(payload)\n return ecdsa.sign(privateKey, string.encodeUtf8(jwt)).then(signature =>\n jwt + '.' + buffer.toBase64UrlEncoded(signature)\n )\n}\n\n/**\n * @param {CryptoKey} publicKey\n * @param {string} jwt\n */\nexport const verifyJwt = async (publicKey, jwt) => {\n const [headerBase64, payloadBase64, signatureBase64] = jwt.split('.')\n const verified = await ecdsa.verify(publicKey, buffer.fromBase64UrlEncoded(signatureBase64), string.encodeUtf8(headerBase64 + '.' + payloadBase64))\n /* c8 ignore next 3 */\n if (!verified) {\n throw new Error('Invalid JWT')\n }\n return {\n header: _parse(headerBase64),\n payload: _parse(payloadBase64)\n }\n}\n"],"names":["buffer.toBase64UrlEncoded","string.encodeUtf8","json.stringify","json.parse","string.decodeUtf8","buffer.fromBase64UrlEncoded","error.unexpectedCase","ecdsa.sign","ecdsa.verify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI,IAAIA,2BAAyB,CAACC,iBAAiB,CAACC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAC;AAC7F;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,SAAS,IAAIC,UAAU,CAACC,iBAAiB,CAACC,6BAA2B,CAAC,SAAS,CAAC,CAAC,EAAC;AACjG;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,UAAU,EAAE,OAAO,KAAK;AAClD,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,uBAAuB,UAAU,CAAC,SAAS,EAAC;AAC3F;AACA,EAAE,IAAI,OAAO,KAAK,OAAO,IAAI,QAAQ,KAAK,OAAO,EAAE;AACnD,IAAIC,oBAAoB,GAAE;AAC1B,GAAG;AACH,EAAE,MAAM,MAAM,GAAG;AACjB,IAAI,GAAG,EAAE,OAAO;AAChB,IAAI,GAAG,EAAE,KAAK;AACd,IAAG;AACH,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAC;AAC5D,EAAE,OAAOC,UAAU,CAAC,UAAU,EAAEN,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS;AACtE,IAAI,GAAG,GAAG,GAAG,GAAGD,2BAAyB,CAAC,SAAS,CAAC;AACpD,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,OAAO,SAAS,EAAE,GAAG,KAAK;AACnD,EAAE,MAAM,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAC;AACvE,EAAE,MAAM,QAAQ,GAAG,MAAMQ,YAAY,CAAC,SAAS,EAAEH,6BAA2B,CAAC,eAAe,CAAC,EAAEJ,iBAAiB,CAAC,YAAY,GAAG,GAAG,GAAG,aAAa,CAAC,EAAC;AACrJ;AACA,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC;AAClC,GAAG;AACH,EAAE,OAAO;AACT,IAAI,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;AAClC,GAAG;AACH;;;;;"}
1
+ {"version":3,"file":"jwt.cjs","sources":["../crypto/jwt.js"],"sourcesContent":["import * as error from '../error.js'\nimport * as buffer from '../buffer.js'\nimport * as string from '../string.js'\nimport * as json from '../json.js'\nimport * as ecdsa from '../crypto/ecdsa.js'\n\n/**\n * @param {Object} data\n */\nconst _stringify = data => buffer.toBase64UrlEncoded(string.encodeUtf8(json.stringify(data)))\n\n/**\n * @param {string} base64url\n */\nconst _parse = base64url => json.parse(string.decodeUtf8(buffer.fromBase64UrlEncoded(base64url)))\n\n/**\n * @param {CryptoKey} privateKey\n * @param {Object} payload\n */\nexport const encodeJwt = (privateKey, payload) => {\n const { name: algName, namedCurve: algCurve } = /** @type {any} */ (privateKey.algorithm)\n /* c8 ignore next 3 */\n if (algName !== 'ECDSA' || algCurve !== 'P-384') {\n error.unexpectedCase()\n }\n const header = {\n alg: 'ES384',\n typ: 'JWT'\n }\n const jwt = _stringify(header) + '.' + _stringify(payload)\n return ecdsa.sign(privateKey, string.encodeUtf8(jwt)).then(signature =>\n jwt + '.' + buffer.toBase64UrlEncoded(signature)\n )\n}\n\n/**\n * @param {CryptoKey} publicKey\n * @param {string} jwt\n */\nexport const verifyJwt = async (publicKey, jwt) => {\n const [headerBase64, payloadBase64, signatureBase64] = jwt.split('.')\n const verified = await ecdsa.verify(publicKey, buffer.fromBase64UrlEncoded(signatureBase64), string.encodeUtf8(headerBase64 + '.' + payloadBase64))\n /* c8 ignore next 3 */\n if (!verified) {\n throw new Error('Invalid JWT')\n }\n return {\n header: _parse(headerBase64),\n payload: _parse(payloadBase64)\n }\n}\n\n/**\n * Decode a jwt without verifying it. Probably a bad idea to use this. Only use if you know the jwt was already verified!\n *\n * @param {string} jwt\n */\nexport const unsafeDecode = jwt => {\n const [headerBase64, payloadBase64] = jwt.split('.')\n return {\n header: _parse(headerBase64),\n payload: _parse(payloadBase64)\n }\n}\n"],"names":["buffer.toBase64UrlEncoded","string.encodeUtf8","json.stringify","json.parse","string.decodeUtf8","buffer.fromBase64UrlEncoded","error.unexpectedCase","ecdsa.sign","ecdsa.verify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI,IAAIA,2BAAyB,CAACC,iBAAiB,CAACC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAC;AAC7F;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,SAAS,IAAIC,UAAU,CAACC,iBAAiB,CAACC,6BAA2B,CAAC,SAAS,CAAC,CAAC,EAAC;AACjG;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,UAAU,EAAE,OAAO,KAAK;AAClD,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,uBAAuB,UAAU,CAAC,SAAS,EAAC;AAC3F;AACA,EAAE,IAAI,OAAO,KAAK,OAAO,IAAI,QAAQ,KAAK,OAAO,EAAE;AACnD,IAAIC,oBAAoB,GAAE;AAC1B,GAAG;AACH,EAAE,MAAM,MAAM,GAAG;AACjB,IAAI,GAAG,EAAE,OAAO;AAChB,IAAI,GAAG,EAAE,KAAK;AACd,IAAG;AACH,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAC;AAC5D,EAAE,OAAOC,UAAU,CAAC,UAAU,EAAEN,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS;AACtE,IAAI,GAAG,GAAG,GAAG,GAAGD,2BAAyB,CAAC,SAAS,CAAC;AACpD,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,OAAO,SAAS,EAAE,GAAG,KAAK;AACnD,EAAE,MAAM,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAC;AACvE,EAAE,MAAM,QAAQ,GAAG,MAAMQ,YAAY,CAAC,SAAS,EAAEH,6BAA2B,CAAC,eAAe,CAAC,EAAEJ,iBAAiB,CAAC,YAAY,GAAG,GAAG,GAAG,aAAa,CAAC,EAAC;AACrJ;AACA,EAAE,IAAI,CAAC,QAAQ,EAAE;AACjB,IAAI,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC;AAClC,GAAG;AACH,EAAE,OAAO;AACT,IAAI,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;AAClC,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,GAAG,IAAI;AACnC,EAAE,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAC;AACtD,EAAE,OAAO;AACT,IAAI,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;AAClC,GAAG;AACH;;;;;;"}
package/dist/queue.cjs CHANGED
@@ -11,14 +11,30 @@ class QueueNode {
11
11
  }
12
12
  }
13
13
 
14
+ /**
15
+ * @template V
16
+ */
17
+ class QueueValue extends QueueNode {
18
+ /**
19
+ * @param {V} v
20
+ */
21
+ constructor (v) {
22
+ super();
23
+ this.v = v;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * @template {QueueNode} N
29
+ */
14
30
  class Queue {
15
31
  constructor () {
16
32
  /**
17
- * @type {QueueNode | null}
33
+ * @type {N | null}
18
34
  */
19
35
  this.start = null;
20
36
  /**
21
- * @type {QueueNode | null}
37
+ * @type {N | null}
22
38
  */
23
39
  this.end = null;
24
40
  }
@@ -28,18 +44,20 @@ class Queue {
28
44
  * @note The queue implementation is experimental and unfinished.
29
45
  * Don't use this in production yet.
30
46
  *
31
- * @return {Queue}
47
+ * @template {QueueNode} N
48
+ * @return {Queue<N>}
32
49
  */
33
50
  const create = () => new Queue();
34
51
 
35
52
  /**
36
- * @param {Queue} queue
53
+ * @param {Queue<any>} queue
37
54
  */
38
55
  const isEmpty = queue => queue.start === null;
39
56
 
40
57
  /**
41
- * @param {Queue} queue
42
- * @param {QueueNode} n
58
+ * @template {Queue<any>} Q
59
+ * @param {Q} queue
60
+ * @param {Q extends Queue<infer N> ? N : never} n
43
61
  */
44
62
  const enqueue = (queue, n) => {
45
63
  if (queue.end !== null) {
@@ -52,8 +70,9 @@ const enqueue = (queue, n) => {
52
70
  };
53
71
 
54
72
  /**
55
- * @param {Queue} queue
56
- * @return {QueueNode | null}
73
+ * @template {QueueNode} N
74
+ * @param {Queue<N>} queue
75
+ * @return {N | null}
57
76
  */
58
77
  const dequeue = queue => {
59
78
  const n = queue.start;
@@ -70,6 +89,7 @@ const dequeue = queue => {
70
89
 
71
90
  exports.Queue = Queue;
72
91
  exports.QueueNode = QueueNode;
92
+ exports.QueueValue = QueueValue;
73
93
  exports.create = create;
74
94
  exports.dequeue = dequeue;
75
95
  exports.enqueue = enqueue;
@@ -1 +1 @@
1
- {"version":3,"file":"queue.cjs","sources":["../queue.js"],"sourcesContent":["export class QueueNode {\n constructor () {\n /**\n * @type {QueueNode|null}\n */\n this.next = null\n }\n}\n\nexport class Queue {\n constructor () {\n /**\n * @type {QueueNode | null}\n */\n this.start = null\n /**\n * @type {QueueNode | null}\n */\n this.end = null\n }\n}\n\n/**\n * @note The queue implementation is experimental and unfinished.\n * Don't use this in production yet.\n *\n * @return {Queue}\n */\nexport const create = () => new Queue()\n\n/**\n * @param {Queue} queue\n */\nexport const isEmpty = queue => queue.start === null\n\n/**\n * @param {Queue} queue\n * @param {QueueNode} n\n */\nexport const enqueue = (queue, n) => {\n if (queue.end !== null) {\n queue.end.next = n\n queue.end = n\n } else {\n queue.end = n\n queue.start = n\n }\n}\n\n/**\n * @param {Queue} queue\n * @return {QueueNode | null}\n */\nexport const dequeue = queue => {\n const n = queue.start\n if (n !== null) {\n // @ts-ignore\n queue.start = n.next\n if (queue.start === null) {\n queue.end = null\n }\n return n\n }\n return null\n}\n"],"names":[],"mappings":";;;;AAAO,MAAM,SAAS,CAAC;AACvB,EAAE,WAAW,CAAC,GAAG;AACjB;AACA;AACA;AACA,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB,GAAG;AACH,CAAC;AACD;AACO,MAAM,KAAK,CAAC;AACnB,EAAE,WAAW,CAAC,GAAG;AACjB;AACA;AACA;AACA,IAAI,IAAI,CAAC,KAAK,GAAG,KAAI;AACrB;AACA;AACA;AACA,IAAI,IAAI,CAAC,GAAG,GAAG,KAAI;AACnB,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,IAAI,KAAK,GAAE;AACvC;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,KAAI;AACpD;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK;AACrC,EAAE,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,EAAE;AAC1B,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,EAAC;AACtB,IAAI,KAAK,CAAC,GAAG,GAAG,EAAC;AACjB,GAAG,MAAM;AACT,IAAI,KAAK,CAAC,GAAG,GAAG,EAAC;AACjB,IAAI,KAAK,CAAC,KAAK,GAAG,EAAC;AACnB,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,KAAK,IAAI;AAChC,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAK;AACvB,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;AAClB;AACA,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAI;AACxB,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,EAAE;AAC9B,MAAM,KAAK,CAAC,GAAG,GAAG,KAAI;AACtB,KAAK;AACL,IAAI,OAAO,CAAC;AACZ,GAAG;AACH,EAAE,OAAO,IAAI;AACb;;;;;;;;;"}
1
+ {"version":3,"file":"queue.cjs","sources":["../queue.js"],"sourcesContent":["export class QueueNode {\n constructor () {\n /**\n * @type {QueueNode|null}\n */\n this.next = null\n }\n}\n\n/**\n * @template V\n */\nexport class QueueValue extends QueueNode {\n /**\n * @param {V} v\n */\n constructor (v) {\n super()\n this.v = v\n }\n}\n\n/**\n * @template {QueueNode} N\n */\nexport class Queue {\n constructor () {\n /**\n * @type {N | null}\n */\n this.start = null\n /**\n * @type {N | null}\n */\n this.end = null\n }\n}\n\n/**\n * @note The queue implementation is experimental and unfinished.\n * Don't use this in production yet.\n *\n * @template {QueueNode} N\n * @return {Queue<N>}\n */\nexport const create = () => new Queue()\n\n/**\n * @param {Queue<any>} queue\n */\nexport const isEmpty = queue => queue.start === null\n\n/**\n * @template {Queue<any>} Q\n * @param {Q} queue\n * @param {Q extends Queue<infer N> ? N : never} n\n */\nexport const enqueue = (queue, n) => {\n if (queue.end !== null) {\n queue.end.next = n\n queue.end = n\n } else {\n queue.end = n\n queue.start = n\n }\n}\n\n/**\n * @template {QueueNode} N\n * @param {Queue<N>} queue\n * @return {N | null}\n */\nexport const dequeue = queue => {\n const n = queue.start\n if (n !== null) {\n // @ts-ignore\n queue.start = n.next\n if (queue.start === null) {\n queue.end = null\n }\n return n\n }\n return null\n}\n"],"names":[],"mappings":";;;;AAAO,MAAM,SAAS,CAAC;AACvB,EAAE,WAAW,CAAC,GAAG;AACjB;AACA;AACA;AACA,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACO,MAAM,UAAU,SAAS,SAAS,CAAC;AAC1C;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE;AAClB,IAAI,KAAK,GAAE;AACX,IAAI,IAAI,CAAC,CAAC,GAAG,EAAC;AACd,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACO,MAAM,KAAK,CAAC;AACnB,EAAE,WAAW,CAAC,GAAG;AACjB;AACA;AACA;AACA,IAAI,IAAI,CAAC,KAAK,GAAG,KAAI;AACrB;AACA;AACA;AACA,IAAI,IAAI,CAAC,GAAG,GAAG,KAAI;AACnB,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,IAAI,KAAK,GAAE;AACvC;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,KAAI;AACpD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK;AACrC,EAAE,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,EAAE;AAC1B,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,EAAC;AACtB,IAAI,KAAK,CAAC,GAAG,GAAG,EAAC;AACjB,GAAG,MAAM;AACT,IAAI,KAAK,CAAC,GAAG,GAAG,EAAC;AACjB,IAAI,KAAK,CAAC,KAAK,GAAG,EAAC;AACnB,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,KAAK,IAAI;AAChC,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAK;AACvB,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;AAClB;AACA,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAI;AACxB,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,EAAE;AAC9B,MAAM,KAAK,CAAC,GAAG,GAAG,KAAI;AACtB,KAAK;AACL,IAAI,OAAO,CAAC;AACZ,GAAG;AACH,EAAE,OAAO,IAAI;AACb;;;;;;;;;;"}
package/dist/queue.d.ts CHANGED
@@ -4,18 +4,31 @@ export class QueueNode {
4
4
  */
5
5
  next: QueueNode | null;
6
6
  }
7
- export class Queue {
7
+ /**
8
+ * @template V
9
+ */
10
+ export class QueueValue<V> extends QueueNode {
8
11
  /**
9
- * @type {QueueNode | null}
12
+ * @param {V} v
10
13
  */
11
- start: QueueNode | null;
14
+ constructor(v: V);
15
+ v: V;
16
+ }
17
+ /**
18
+ * @template {QueueNode} N
19
+ */
20
+ export class Queue<N extends QueueNode> {
21
+ /**
22
+ * @type {N | null}
23
+ */
24
+ start: N | null;
12
25
  /**
13
- * @type {QueueNode | null}
26
+ * @type {N | null}
14
27
  */
15
- end: QueueNode | null;
28
+ end: N | null;
16
29
  }
17
- export function create(): Queue;
18
- export function isEmpty(queue: Queue): boolean;
19
- export function enqueue(queue: Queue, n: QueueNode): void;
20
- export function dequeue(queue: Queue): QueueNode | null;
30
+ export function create<N extends QueueNode>(): Queue<N>;
31
+ export function isEmpty(queue: Queue<any>): boolean;
32
+ export function enqueue<Q extends Queue<any>>(queue: Q, n: Q extends Queue<infer N extends QueueNode> ? N : never): void;
33
+ export function dequeue<N extends QueueNode>(queue: Queue<N>): N | null;
21
34
  //# sourceMappingURL=queue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../queue.js"],"names":[],"mappings":"AAAA;IAEI;;OAEG;IACH,MAFU,SAAS,GAAC,IAAI,CAER;CAEnB;AAED;IAEI;;OAEG;IACH,OAFU,SAAS,GAAG,IAAI,CAET;IACjB;;OAEG;IACH,KAFU,SAAS,GAAG,IAAI,CAEX;CAElB;AAQM,0BAFK,KAAK,CAEsB;AAKhC,+BAFI,KAAK,WAEoC;AAM7C,+BAHI,KAAK,KACL,SAAS,QAUnB;AAMM,+BAHI,KAAK,GACJ,SAAS,GAAG,IAAI,CAa3B"}
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../queue.js"],"names":[],"mappings":"AAAA;IAEI;;OAEG;IACH,MAFU,SAAS,GAAC,IAAI,CAER;CAEnB;AAED;;GAEG;AACH;IACE;;OAEG;IACH,eAFW,CAAC,EAKX;IADC,KAAU;CAEb;AAED;;GAEG;AACH;IAEI;;OAEG;IACH,OAFU,CAAC,GAAG,IAAI,CAED;IACjB;;OAEG;IACH,KAFU,CAAC,GAAG,IAAI,CAEH;CAElB;AASM,wDAAgC;AAKhC,+BAFI,MAAM,GAAG,CAAC,WAE+B;AAO7C,yHAQN;AAOM,wEAWN"}
@@ -1,3 +1,3 @@
1
- export function testEnqueueDequeue(tc: t.TestCase): void;
1
+ export function testEnqueueDequeue(_tc: t.TestCase): void;
2
2
  import * as t from './testing.js';
3
3
  //# sourceMappingURL=queue.test.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue.test.d.ts","sourceRoot":"","sources":["../queue.test.js"],"names":[],"mappings":"AAgBO,uCAFI,EAAE,QAAQ,QA8BpB;mBA5CkB,cAAc"}
1
+ {"version":3,"file":"queue.test.d.ts","sourceRoot":"","sources":["../queue.test.js"],"names":[],"mappings":"AAMO,wCAFI,EAAE,QAAQ,QA8BpB;mBAlCkB,cAAc"}
@@ -1,3 +1,4 @@
1
+ export function testSelfReferencingHash(_tc: t.TestCase): void;
1
2
  export function testSha256Basics(_tc: t.TestCase): Promise<void>;
2
3
  export function testLargeValue(_tc: t.TestCase): Promise<void>;
3
4
  export function testRepeatSha256Hashing(tc: t.TestCase): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"sha256.test.d.ts","sourceRoot":"","sources":["sha256.test.js"],"names":[],"mappings":"AAcO,sCAFI,EAAE,QAAQ,iBA2BpB;AAOM,oCAFI,EAAE,QAAQ,iBA4BpB;AAKM,4CAFI,EAAE,QAAQ,iBAQpB;AAKM,yCAFI,EAAE,QAAQ,iBAmDpB;mBAzIkB,eAAe"}
1
+ {"version":3,"file":"sha256.test.d.ts","sourceRoot":"","sources":["sha256.test.js"],"names":[],"mappings":"AAcO,6CAFI,EAAE,QAAQ,QAKpB;AAKM,sCAFI,EAAE,QAAQ,iBA2BpB;AAOM,oCAFI,EAAE,QAAQ,iBA4BpB;AAKM,4CAFI,EAAE,QAAQ,iBAQpB;AAKM,yCAFI,EAAE,QAAQ,iBAmDpB;mBAjJkB,eAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "0.2.82",
3
+ "version": "0.2.84",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "type": "module",
package/queue.d.ts CHANGED
@@ -4,18 +4,31 @@ export class QueueNode {
4
4
  */
5
5
  next: QueueNode | null;
6
6
  }
7
- export class Queue {
7
+ /**
8
+ * @template V
9
+ */
10
+ export class QueueValue<V> extends QueueNode {
8
11
  /**
9
- * @type {QueueNode | null}
12
+ * @param {V} v
10
13
  */
11
- start: QueueNode | null;
14
+ constructor(v: V);
15
+ v: V;
16
+ }
17
+ /**
18
+ * @template {QueueNode} N
19
+ */
20
+ export class Queue<N extends QueueNode> {
21
+ /**
22
+ * @type {N | null}
23
+ */
24
+ start: N | null;
12
25
  /**
13
- * @type {QueueNode | null}
26
+ * @type {N | null}
14
27
  */
15
- end: QueueNode | null;
28
+ end: N | null;
16
29
  }
17
- export function create(): Queue;
18
- export function isEmpty(queue: Queue): boolean;
19
- export function enqueue(queue: Queue, n: QueueNode): void;
20
- export function dequeue(queue: Queue): QueueNode | null;
30
+ export function create<N extends QueueNode>(): Queue<N>;
31
+ export function isEmpty(queue: Queue<any>): boolean;
32
+ export function enqueue<Q extends Queue<any>>(queue: Q, n: Q extends Queue<infer N extends QueueNode> ? N : never): void;
33
+ export function dequeue<N extends QueueNode>(queue: Queue<N>): N | null;
21
34
  //# sourceMappingURL=queue.d.ts.map
package/queue.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["queue.js"],"names":[],"mappings":"AAAA;IAEI;;OAEG;IACH,MAFU,SAAS,GAAC,IAAI,CAER;CAEnB;AAED;IAEI;;OAEG;IACH,OAFU,SAAS,GAAG,IAAI,CAET;IACjB;;OAEG;IACH,KAFU,SAAS,GAAG,IAAI,CAEX;CAElB;AAQM,0BAFK,KAAK,CAEsB;AAKhC,+BAFI,KAAK,WAEoC;AAM7C,+BAHI,KAAK,KACL,SAAS,QAUnB;AAMM,+BAHI,KAAK,GACJ,SAAS,GAAG,IAAI,CAa3B"}
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["queue.js"],"names":[],"mappings":"AAAA;IAEI;;OAEG;IACH,MAFU,SAAS,GAAC,IAAI,CAER;CAEnB;AAED;;GAEG;AACH;IACE;;OAEG;IACH,eAFW,CAAC,EAKX;IADC,KAAU;CAEb;AAED;;GAEG;AACH;IAEI;;OAEG;IACH,OAFU,CAAC,GAAG,IAAI,CAED;IACjB;;OAEG;IACH,KAFU,CAAC,GAAG,IAAI,CAEH;CAElB;AASM,wDAAgC;AAKhC,+BAFI,MAAM,GAAG,CAAC,WAE+B;AAO7C,yHAQN;AAOM,wEAWN"}
package/queue.js CHANGED
@@ -7,14 +7,30 @@ export class QueueNode {
7
7
  }
8
8
  }
9
9
 
10
+ /**
11
+ * @template V
12
+ */
13
+ export class QueueValue extends QueueNode {
14
+ /**
15
+ * @param {V} v
16
+ */
17
+ constructor (v) {
18
+ super()
19
+ this.v = v
20
+ }
21
+ }
22
+
23
+ /**
24
+ * @template {QueueNode} N
25
+ */
10
26
  export class Queue {
11
27
  constructor () {
12
28
  /**
13
- * @type {QueueNode | null}
29
+ * @type {N | null}
14
30
  */
15
31
  this.start = null
16
32
  /**
17
- * @type {QueueNode | null}
33
+ * @type {N | null}
18
34
  */
19
35
  this.end = null
20
36
  }
@@ -24,18 +40,20 @@ export class Queue {
24
40
  * @note The queue implementation is experimental and unfinished.
25
41
  * Don't use this in production yet.
26
42
  *
27
- * @return {Queue}
43
+ * @template {QueueNode} N
44
+ * @return {Queue<N>}
28
45
  */
29
46
  export const create = () => new Queue()
30
47
 
31
48
  /**
32
- * @param {Queue} queue
49
+ * @param {Queue<any>} queue
33
50
  */
34
51
  export const isEmpty = queue => queue.start === null
35
52
 
36
53
  /**
37
- * @param {Queue} queue
38
- * @param {QueueNode} n
54
+ * @template {Queue<any>} Q
55
+ * @param {Q} queue
56
+ * @param {Q extends Queue<infer N> ? N : never} n
39
57
  */
40
58
  export const enqueue = (queue, n) => {
41
59
  if (queue.end !== null) {
@@ -48,8 +66,9 @@ export const enqueue = (queue, n) => {
48
66
  }
49
67
 
50
68
  /**
51
- * @param {Queue} queue
52
- * @return {QueueNode | null}
69
+ * @template {QueueNode} N
70
+ * @param {Queue<N>} queue
71
+ * @return {N | null}
53
72
  */
54
73
  export const dequeue = queue => {
55
74
  const n = queue.start
package/queue.test.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export function testEnqueueDequeue(tc: t.TestCase): void;
1
+ export function testEnqueueDequeue(_tc: t.TestCase): void;
2
2
  import * as t from './testing.js';
3
3
  //# sourceMappingURL=queue.test.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue.test.d.ts","sourceRoot":"","sources":["queue.test.js"],"names":[],"mappings":"AAgBO,uCAFI,EAAE,QAAQ,QA8BpB;mBA5CkB,cAAc"}
1
+ {"version":3,"file":"queue.test.d.ts","sourceRoot":"","sources":["queue.test.js"],"names":[],"mappings":"AAMO,wCAFI,EAAE,QAAQ,QA8BpB;mBAlCkB,cAAc"}