@haneullabs/utils 0.3.2 → 0.4.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.
- package/CHANGELOG.md +21 -0
- package/dist/b58.d.mts.map +1 -1
- package/dist/b58.mjs +1 -2
- package/dist/b58.mjs.map +1 -1
- package/dist/b64.d.mts.map +1 -1
- package/dist/b64.mjs +1 -1
- package/dist/b64.mjs.map +1 -1
- package/dist/chunk.d.mts.map +1 -1
- package/dist/chunk.mjs +1 -1
- package/dist/chunk.mjs.map +1 -1
- package/dist/dataloader.d.mts.map +1 -1
- package/dist/dataloader.mjs +1 -1
- package/dist/dataloader.mjs.map +1 -1
- package/dist/hex.d.mts.map +1 -1
- package/dist/hex.mjs +1 -1
- package/dist/hex.mjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/mitt.d.mts.map +1 -1
- package/dist/mitt.mjs +24 -1
- package/dist/mitt.mjs.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/with-resolver.d.mts.map +1 -1
- package/dist/with-resolver.mjs +1 -1
- package/dist/with-resolver.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @mysten/utils
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bbf63cb: Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 0.3.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- f7de3e5: Restore docs in published tarballs.
|
|
14
|
+
|
|
15
|
+
## 0.3.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 9e067cf: Validate the new per-package release flow end-to-end across every public @mysten package.
|
|
20
|
+
No functional changes — empty patch bump to force the orchestrator to dispatch every
|
|
21
|
+
release-<pkg>.yml workflow with `dry_run=false` so each package publishes via OIDC trusted
|
|
22
|
+
publishing.
|
|
23
|
+
|
|
3
24
|
## 0.3.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/b58.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"b58.d.mts","names":[],"sources":["../src/b58.ts"],"mappings":";cAKa,QAAA,GAAY,
|
|
1
|
+
{"version":3,"file":"b58.d.mts","names":[],"sources":["../src/b58.ts"],"mappings":";cAKa,QAAA,GAAY,MAAkB,EAAV,UAAU;AAAA,cAC9B,UAAA,GAAc,GAAA,aAAsC,UAAU,CAAC,WAAA"}
|
package/dist/b58.mjs
CHANGED
package/dist/b58.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"b58.mjs","names":[],"sources":["../src/b58.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { base58 } from '@scure/base';\n\nexport const toBase58 = (buffer: Uint8Array) => base58.encode(buffer);\nexport const fromBase58 = (str: string) => base58.decode(str) as Uint8Array<ArrayBuffer>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"b58.mjs","names":[],"sources":["../src/b58.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { base58 } from '@scure/base';\n\nexport const toBase58 = (buffer: Uint8Array) => base58.encode(buffer);\nexport const fromBase58 = (str: string) => base58.decode(str) as Uint8Array<ArrayBuffer>;\n"],"mappings":";;AAKA,MAAa,YAAY,WAAuB,OAAO,OAAO,MAAM;AACpE,MAAa,cAAc,QAAgB,OAAO,OAAO,GAAG"}
|
package/dist/b64.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"b64.d.mts","names":[],"sources":["../src/b64.ts"],"mappings":";iBAGgB,UAAA,CAAW,YAAA,WAAuB,
|
|
1
|
+
{"version":3,"file":"b64.d.mts","names":[],"sources":["../src/b64.ts"],"mappings":";iBAGgB,UAAA,CAAW,YAAA,WAAuB,UAAU,CAAC,WAAA;AAAA,iBAK7C,QAAA,CAAS,KAAiB,EAAV,UAAU"}
|
package/dist/b64.mjs
CHANGED
package/dist/b64.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"b64.mjs","names":[],"sources":["../src/b64.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function fromBase64(base64String: string): Uint8Array<ArrayBuffer> {\n\treturn Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));\n}\n\nconst CHUNK_SIZE = 8192;\nexport function toBase64(bytes: Uint8Array): string {\n\t// Special-case the simple case for speed's sake.\n\tif (bytes.length < CHUNK_SIZE) {\n\t\treturn btoa(String.fromCharCode(...bytes));\n\t}\n\n\tlet output = '';\n\tfor (var i = 0; i < bytes.length; i += CHUNK_SIZE) {\n\t\tconst chunk = bytes.slice(i, i + CHUNK_SIZE);\n\t\toutput += String.fromCharCode(...chunk);\n\t}\n\n\treturn btoa(output);\n}\n"],"mappings":";AAGA,SAAgB,WAAW,cAA+C;
|
|
1
|
+
{"version":3,"file":"b64.mjs","names":[],"sources":["../src/b64.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function fromBase64(base64String: string): Uint8Array<ArrayBuffer> {\n\treturn Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));\n}\n\nconst CHUNK_SIZE = 8192;\nexport function toBase64(bytes: Uint8Array): string {\n\t// Special-case the simple case for speed's sake.\n\tif (bytes.length < CHUNK_SIZE) {\n\t\treturn btoa(String.fromCharCode(...bytes));\n\t}\n\n\tlet output = '';\n\tfor (var i = 0; i < bytes.length; i += CHUNK_SIZE) {\n\t\tconst chunk = bytes.slice(i, i + CHUNK_SIZE);\n\t\toutput += String.fromCharCode(...chunk);\n\t}\n\n\treturn btoa(output);\n}\n"],"mappings":";AAGA,SAAgB,WAAW,cAA+C;CACzE,OAAO,WAAW,KAAK,KAAK,YAAY,IAAI,SAAS,KAAK,WAAW,CAAC,CAAC;AACxE;AAEA,MAAM,aAAa;AACnB,SAAgB,SAAS,OAA2B;CAEnD,IAAI,MAAM,SAAS,YAClB,OAAO,KAAK,OAAO,aAAa,GAAG,KAAK,CAAC;CAG1C,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,YAAY;EAClD,MAAM,QAAQ,MAAM,MAAM,GAAG,IAAI,UAAU;EAC3C,UAAU,OAAO,aAAa,GAAG,KAAK;CACvC;CAEA,OAAO,KAAK,MAAM;AACnB"}
|
package/dist/chunk.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.d.mts","names":[],"sources":["../src/chunk.ts"],"mappings":";iBAGgB,KAAA,
|
|
1
|
+
{"version":3,"file":"chunk.d.mts","names":[],"sources":["../src/chunk.ts"],"mappings":";iBAGgB,KAAA,IAAS,KAAA,WAAgB,CAAA,IAAK,IAAA,WAAe,CAAC"}
|
package/dist/chunk.mjs
CHANGED
package/dist/chunk.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.mjs","names":[],"sources":["../src/chunk.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function chunk<T>(array: readonly T[], size: number): T[][] {\n\treturn Array.from({ length: Math.ceil(array.length / size) }, (_, i) => {\n\t\treturn array.slice(i * size, (i + 1) * size);\n\t});\n}\n"],"mappings":";AAGA,SAAgB,MAAS,OAAqB,MAAqB;
|
|
1
|
+
{"version":3,"file":"chunk.mjs","names":[],"sources":["../src/chunk.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function chunk<T>(array: readonly T[], size: number): T[][] {\n\treturn Array.from({ length: Math.ceil(array.length / size) }, (_, i) => {\n\t\treturn array.slice(i * size, (i + 1) * size);\n\t});\n}\n"],"mappings":";AAGA,SAAgB,MAAS,OAAqB,MAAqB;CAClE,OAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,KAAK,MAAM,SAAS,IAAI,EAAE,IAAI,GAAG,MAAM;EACvE,OAAO,MAAM,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI;CAC5C,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataloader.d.mts","names":[],"sources":["../src/dataloader.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;;;;;cAAa,UAAA,WAAqB,CAAA;cACrB,WAAA,EAAa,UAAA,CAAW,WAAA,CAAY,CAAA,EAAG,CAAA,GAAI,OAAA,GAAU,UAAA,CAAW,OAAA,CAAQ,CAAA,EAAG,CAAA,EAAG,CAAA;EAiB1F,YAAA,EAAc,UAAA,CAAW,WAAA,CAAY,CAAA,EAAG,CAAA;EACxC,aAAA;EACA,gBAAA,GAAmB,EAAA;EACnB,WAAA,GAAc,GAAA,EAAK,CAAA,KAAM,CAAA;EACzB,SAAA,EAAW,UAAA,CAAW,QAAA,CAAS,CAAA,EAAG,OAAA,CAAQ,CAAA;EAC1C,MAAA,EAAQ,KAAA,CAAM,CAAA,EAAG,CAAA;EAKH;;;EAAd,IAAA,CAAK,GAAA,EAAK,CAAA,GAAI,OAAA,CAAQ,CAAA;EA4D8B;;;;;;;;;;;;;;;;;;;;EAApD,QAAA,CAAS,IAAA,EAAM,aAAA,CAAc,CAAA,IAAK,OAAA,CAAQ,KAAA,CAAM,CAAA,GAAI,KAAA;EAvFa;;;;EAyGjE,KAAA,CAAM,GAAA,EAAK,CAAA;EAzG4C;;;;;EAuHvD,QAAA
|
|
1
|
+
{"version":3,"file":"dataloader.d.mts","names":[],"sources":["../src/dataloader.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;;;;;cAAa,UAAA,WAAqB,CAAA;cACrB,W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,UAAqB,IAAA,EAAM,aAAA,CAAc,CAAA,MAAO,WAAA,CAAY,SAAA,CAAU,CAAA,GAAI,KAAA;EAAA,KAI1E,OAAA,WAAkB,CAAA;IA7VxB;;;;;IAmWL,KAAA;IAvUwB;;;;IA6UxB,YAAA;IAhTG;AAAA;AACJ;;;IAsTC,eAAA,IAAmB,QAAA;IA9Pd;;;;;IAqQL,KAAA;IAhQgB;;;;IAsQhB,UAAA,IAAc,GAAA,EAAK,CAAA,KAAM,CAAA;IA3QpB;;;;IAiRL,QAAA,GAAW,QAAA,CAAS,CAAA,EAAG,OAAA,CAAQ,CAAA;IA/Qd;;;;;IAsRjB,IAAA;EAAA;AAAA"}
|
package/dist/dataloader.mjs
CHANGED
|
@@ -230,7 +230,7 @@ function getValidName(options) {
|
|
|
230
230
|
function isArrayLike(x) {
|
|
231
231
|
return typeof x === "object" && x !== null && "length" in x && typeof x.length === "number" && (x.length === 0 || x.length > 0 && Object.prototype.hasOwnProperty.call(x, x.length - 1));
|
|
232
232
|
}
|
|
233
|
-
|
|
234
233
|
//#endregion
|
|
235
234
|
export { DataLoader };
|
|
235
|
+
|
|
236
236
|
//# sourceMappingURL=dataloader.mjs.map
|
package/dist/dataloader.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataloader.mjs","names":[],"sources":["../src/dataloader.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * DataLoader - A generic utility for batching and caching data fetches.\n *\n * Vendored from: https://github.com/graphql/dataloader\n * Commit: a10773043d41a56bde4219c155fcf5633e6c9bcb\n * License: MIT\n * Copyright (c) GraphQL Contributors\n */\n\n/**\n * A `DataLoader` creates a public API for loading data from a particular\n * data back-end with unique keys such as the `id` column of a SQL table or\n * document name in a MongoDB database, given a batch loading function.\n *\n * Each `DataLoader` instance contains a unique memoized cache. Use caution when\n * used in long-lived applications or those which serve many users with\n * different access permissions and consider creating a new instance per\n * web request.\n */\nexport class DataLoader<K, V, C = K> {\n\tconstructor(batchLoadFn: DataLoader.BatchLoadFn<K, V>, options?: DataLoader.Options<K, V, C>) {\n\t\tif (typeof batchLoadFn !== 'function') {\n\t\t\tthrow new TypeError(\n\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t`Array<key> and returns Promise<Array<value>>, but got: ${batchLoadFn}.`,\n\t\t\t);\n\t\t}\n\t\tthis._batchLoadFn = batchLoadFn;\n\t\tthis._maxBatchSize = getValidMaxBatchSize(options);\n\t\tthis._batchScheduleFn = getValidBatchScheduleFn(options);\n\t\tthis._cacheKeyFn = getValidCacheKeyFn(options);\n\t\tthis._cacheMap = getValidCacheMap(options);\n\t\tthis._batch = null;\n\t\tthis.name = getValidName(options);\n\t}\n\n\t// Private\n\t_batchLoadFn: DataLoader.BatchLoadFn<K, V>;\n\t_maxBatchSize: number;\n\t_batchScheduleFn: (cb: () => void) => void;\n\t_cacheKeyFn: (key: K) => C;\n\t_cacheMap: DataLoader.CacheMap<C, Promise<V>> | null;\n\t_batch: Batch<K, V> | null;\n\n\t/**\n\t * Loads a key, returning a `Promise` for the value represented by that key.\n\t */\n\tload(key: K): Promise<V> {\n\t\tif (key === null || key === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`The loader.load() function must be called with a value, but got: ${String(key)}.`,\n\t\t\t);\n\t\t}\n\n\t\tconst batch = getCurrentBatch(this);\n\t\tconst cacheMap = this._cacheMap;\n\t\tlet cacheKey: C;\n\n\t\t// If caching and there is a cache-hit, return cached Promise.\n\t\tif (cacheMap) {\n\t\t\tcacheKey = this._cacheKeyFn(key);\n\t\t\tconst cachedPromise = cacheMap.get(cacheKey);\n\t\t\tif (cachedPromise) {\n\t\t\t\tconst cacheHits = batch.cacheHits || (batch.cacheHits = []);\n\t\t\t\treturn new Promise((resolve) => {\n\t\t\t\t\tcacheHits.push(() => {\n\t\t\t\t\t\tresolve(cachedPromise);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Otherwise, produce a new Promise for this key, and enqueue it to be\n\t\t// dispatched along with the current batch.\n\t\tbatch.keys.push(key);\n\t\tconst promise = new Promise<V>((resolve, reject) => {\n\t\t\tbatch.callbacks.push({ resolve, reject });\n\t\t});\n\n\t\t// If caching, cache this promise.\n\t\tif (cacheMap) {\n\t\t\tcacheMap.set(cacheKey!, promise);\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Loads multiple keys, promising an array of values:\n\t *\n\t * var [ a, b ] = await myLoader.loadMany([ 'a', 'b' ]);\n\t *\n\t * This is similar to the more verbose:\n\t *\n\t * var [ a, b ] = await Promise.all([\n\t * myLoader.load('a'),\n\t * myLoader.load('b')\n\t * ]);\n\t *\n\t * However it is different in the case where any load fails. Where\n\t * Promise.all() would reject, loadMany() always resolves, however each result\n\t * is either a value or an Error instance.\n\t *\n\t * var [ a, b, c ] = await myLoader.loadMany([ 'a', 'b', 'badkey' ]);\n\t * // c instanceof Error\n\t *\n\t */\n\tloadMany(keys: ReadonlyArray<K>): Promise<Array<V | Error>> {\n\t\tif (!isArrayLike(keys)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`The loader.loadMany() function must be called with Array<key>, but got: ${keys}.`,\n\t\t\t);\n\t\t}\n\t\t// Support ArrayLike by using only minimal property access\n\t\tconst loadPromises = [];\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tloadPromises.push(this.load(keys[i]).catch((error) => error));\n\t\t}\n\t\treturn Promise.all(loadPromises);\n\t}\n\n\t/**\n\t * Clears the value at `key` from the cache, if it exists. Returns itself for\n\t * method chaining.\n\t */\n\tclear(key: K): this {\n\t\tconst cacheMap = this._cacheMap;\n\t\tif (cacheMap) {\n\t\t\tconst cacheKey = this._cacheKeyFn(key);\n\t\t\tcacheMap.delete(cacheKey);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears the entire cache. To be used when some event results in unknown\n\t * invalidations across this particular `DataLoader`. Returns itself for\n\t * method chaining.\n\t */\n\tclearAll(): this {\n\t\tconst cacheMap = this._cacheMap;\n\t\tif (cacheMap) {\n\t\t\tcacheMap.clear();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the provided key and value to the cache. If the key already\n\t * exists, no change is made. Returns itself for method chaining.\n\t *\n\t * To prime the cache with an error at a key, provide an Error instance.\n\t */\n\tprime(key: K, value: V | Promise<V> | Error): this {\n\t\tconst cacheMap = this._cacheMap;\n\t\tif (cacheMap) {\n\t\t\tconst cacheKey = this._cacheKeyFn(key);\n\n\t\t\t// Only add the key if it does not already exist.\n\t\t\tif (cacheMap.get(cacheKey) === undefined) {\n\t\t\t\t// Cache a rejected promise if the value is an Error, in order to match\n\t\t\t\t// the behavior of load(key).\n\t\t\t\tlet promise;\n\t\t\t\tif (value instanceof Error) {\n\t\t\t\t\tpromise = Promise.reject(value);\n\t\t\t\t\t// Since this is a case where an Error is intentionally being primed\n\t\t\t\t\t// for a given key, we want to disable unhandled promise rejection.\n\t\t\t\t\tpromise.catch(() => {});\n\t\t\t\t} else {\n\t\t\t\t\tpromise = Promise.resolve(value);\n\t\t\t\t}\n\t\t\t\tcacheMap.set(cacheKey, promise);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The name given to this `DataLoader` instance. Useful for APM tools.\n\t *\n\t * Is `null` if not set in the constructor.\n\t */\n\tname: string | null;\n}\n\n// Private: Enqueue a Job to be executed after all \"PromiseJobs\" Jobs.\n//\n// ES6 JavaScript uses the concepts Job and JobQueue to schedule work to occur\n// after the current execution context has completed:\n// http://www.ecma-international.org/ecma-262/6.0/#sec-jobs-and-job-queues\n//\n// Node.js uses the `process.nextTick` mechanism to implement the concept of a\n// Job, maintaining a global FIFO JobQueue for all Jobs, which is flushed after\n// the current call stack ends.\n//\n// When calling `then` on a Promise, it enqueues a Job on a specific\n// \"PromiseJobs\" JobQueue which is flushed in Node as a single Job on the\n// global JobQueue.\n//\n// DataLoader batches all loads which occur in a single frame of execution, but\n// should include in the batch all loads which occur during the flushing of the\n// \"PromiseJobs\" JobQueue after that same execution frame.\n//\n// In order to avoid the DataLoader dispatch Job occuring before \"PromiseJobs\",\n// A Promise Job is created with the sole purpose of enqueuing a global Job,\n// ensuring that it always occurs after \"PromiseJobs\" ends.\n//\n// Node.js's job queue is unique. Browsers do not have an equivalent mechanism\n// for enqueuing a job to be performed after promise microtasks and before the\n// next macrotask. For browser environments, a macrotask is used (via\n// setImmediate or setTimeout) at a potential performance penalty.\nconst enqueuePostPromiseJob: (fn: () => void) => void =\n\t// @ts-ignore\n\ttypeof process === 'object' && typeof process.nextTick === 'function'\n\t\t? function (fn) {\n\t\t\t\tif (!resolvedPromise) {\n\t\t\t\t\tresolvedPromise = Promise.resolve();\n\t\t\t\t}\n\t\t\t\tresolvedPromise.then(() => {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tprocess.nextTick(fn);\n\t\t\t\t});\n\t\t\t}\n\t\t: // @ts-ignore\n\t\t\ttypeof setImmediate === 'function'\n\t\t\t? function (fn) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tsetImmediate(fn);\n\t\t\t\t}\n\t\t\t: function (fn) {\n\t\t\t\t\tsetTimeout(fn);\n\t\t\t\t};\n\n// Private: cached resolved Promise instance\nlet resolvedPromise: Promise<void> | undefined;\n\n// Private: Describes a batch of requests\ntype Batch<K, V> = {\n\thasDispatched: boolean;\n\tkeys: Array<K>;\n\tcallbacks: Array<{\n\t\tresolve: (value: V) => void;\n\t\treject: (error: Error) => void;\n\t}>;\n\tcacheHits?: Array<() => void>;\n};\n\n// Private: Either returns the current batch, or creates and schedules a\n// dispatch of a new batch for the given loader.\nfunction getCurrentBatch<K, V>(loader: DataLoader<K, V, any>): Batch<K, V> {\n\t// If there is an existing batch which has not yet dispatched and is within\n\t// the limit of the batch size, then return it.\n\tconst existingBatch = loader._batch;\n\tif (\n\t\texistingBatch !== null &&\n\t\t!existingBatch.hasDispatched &&\n\t\texistingBatch.keys.length < loader._maxBatchSize\n\t) {\n\t\treturn existingBatch;\n\t}\n\n\t// Otherwise, create a new batch for this loader.\n\tconst newBatch = { hasDispatched: false, keys: [], callbacks: [] };\n\n\t// Store it on the loader so it may be reused.\n\tloader._batch = newBatch;\n\n\t// Then schedule a task to dispatch this batch of requests.\n\tloader._batchScheduleFn(() => {\n\t\tdispatchBatch(loader, newBatch);\n\t});\n\n\treturn newBatch;\n}\n\nfunction dispatchBatch<K, V>(loader: DataLoader<K, V, any>, batch: Batch<K, V>) {\n\t// Mark this batch as having been dispatched.\n\tbatch.hasDispatched = true;\n\n\t// If there's nothing to load, resolve any cache hits and return early.\n\tif (batch.keys.length === 0) {\n\t\tresolveCacheHits(batch);\n\t\treturn;\n\t}\n\n\t// Call the provided batchLoadFn for this loader with the batch's keys and\n\t// with the loader as the `this` context.\n\tlet batchPromise;\n\ttry {\n\t\tbatchPromise = loader._batchLoadFn(batch.keys);\n\t} catch (e) {\n\t\treturn failedDispatch(\n\t\t\tloader,\n\t\t\tbatch,\n\t\t\tnew TypeError(\n\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function ' +\n\t\t\t\t\t`errored synchronously: ${String(e)}.`,\n\t\t\t),\n\t\t);\n\t}\n\n\t// Assert the expected response from batchLoadFn\n\tif (!batchPromise || typeof batchPromise.then !== 'function') {\n\t\treturn failedDispatch(\n\t\t\tloader,\n\t\t\tbatch,\n\t\t\tnew TypeError(\n\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function did ' +\n\t\t\t\t\t`not return a Promise: ${String(batchPromise)}.`,\n\t\t\t),\n\t\t);\n\t}\n\n\t// Await the resolution of the call to batchLoadFn.\n\tPromise.resolve(batchPromise)\n\t\t.then((values) => {\n\t\t\t// Assert the expected resolution from batchLoadFn.\n\t\t\tif (!isArrayLike(values)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function did ' +\n\t\t\t\t\t\t`not return a Promise of an Array: ${String(values)}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (values.length !== batch.keys.length) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function did ' +\n\t\t\t\t\t\t'not return a Promise of an Array of the same length as the Array ' +\n\t\t\t\t\t\t'of keys.' +\n\t\t\t\t\t\t`\\n\\nKeys:\\n${String(batch.keys)}` +\n\t\t\t\t\t\t`\\n\\nValues:\\n${String(values)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Resolve all cache hits in the same micro-task as freshly loaded values.\n\t\t\tresolveCacheHits(batch);\n\n\t\t\t// Step through values, resolving or rejecting each Promise in the batch.\n\t\t\tfor (let i = 0; i < batch.callbacks.length; i++) {\n\t\t\t\tconst value = values[i];\n\t\t\t\tif (value instanceof Error) {\n\t\t\t\t\tbatch.callbacks[i].reject(value);\n\t\t\t\t} else {\n\t\t\t\t\tbatch.callbacks[i].resolve(value);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.catch((error: unknown) => {\n\t\t\tfailedDispatch(loader, batch, error as Error);\n\t\t});\n}\n\n// Private: do not cache individual loads if the entire batch dispatch fails,\n// but still reject each request so they do not hang.\nfunction failedDispatch<K, V>(loader: DataLoader<K, V, any>, batch: Batch<K, V>, error: Error) {\n\t// Cache hits are resolved, even though the batch failed.\n\tresolveCacheHits(batch);\n\tfor (let i = 0; i < batch.keys.length; i++) {\n\t\tloader.clear(batch.keys[i]);\n\t\tbatch.callbacks[i].reject(error);\n\t}\n}\n\n// Private: Resolves the Promises for any cache hits in this batch.\nfunction resolveCacheHits(batch: Batch<any, any>) {\n\tif (batch.cacheHits) {\n\t\tfor (let i = 0; i < batch.cacheHits.length; i++) {\n\t\t\tbatch.cacheHits[i]();\n\t\t}\n\t}\n}\n\n// Private: given the DataLoader's options, produce a valid max batch size.\nfunction getValidMaxBatchSize<K, V, C>(options?: DataLoader.Options<K, V, C>): number {\n\tconst shouldBatch = !options || options.batch !== false;\n\tif (!shouldBatch) {\n\t\treturn 1;\n\t}\n\tconst maxBatchSize = options && options.maxBatchSize;\n\tif (maxBatchSize === undefined) {\n\t\treturn Infinity;\n\t}\n\tif (typeof maxBatchSize !== 'number' || maxBatchSize < 1) {\n\t\tthrow new TypeError(`maxBatchSize must be a positive number: ${maxBatchSize}`);\n\t}\n\treturn maxBatchSize;\n}\n\n// Private\nfunction getValidBatchScheduleFn<K, V, C>(\n\toptions?: DataLoader.Options<K, V, C>,\n): (cb: () => void) => void {\n\tconst batchScheduleFn = options && options.batchScheduleFn;\n\tif (batchScheduleFn === undefined) {\n\t\treturn enqueuePostPromiseJob;\n\t}\n\tif (typeof batchScheduleFn !== 'function') {\n\t\tthrow new TypeError(`batchScheduleFn must be a function: ${batchScheduleFn}`);\n\t}\n\treturn batchScheduleFn;\n}\n\n// Private: given the DataLoader's options, produce a cache key function.\nfunction getValidCacheKeyFn<K, V, C>(options?: DataLoader.Options<K, V, C>): (key: K) => C {\n\tconst cacheKeyFn = options && options.cacheKeyFn;\n\tif (cacheKeyFn === undefined) {\n\t\treturn (key: K) => key as unknown as C;\n\t}\n\tif (typeof cacheKeyFn !== 'function') {\n\t\tthrow new TypeError(`cacheKeyFn must be a function: ${cacheKeyFn}`);\n\t}\n\treturn cacheKeyFn;\n}\n\n// Private: given the DataLoader's options, produce a CacheMap to be used.\nfunction getValidCacheMap<K, V, C>(\n\toptions?: DataLoader.Options<K, V, C>,\n): DataLoader.CacheMap<C, Promise<V>> | null {\n\tconst shouldCache = !options || options.cache !== false;\n\tif (!shouldCache) {\n\t\treturn null;\n\t}\n\tconst cacheMap = options && options.cacheMap;\n\tif (cacheMap === undefined) {\n\t\treturn new Map();\n\t}\n\tif (cacheMap !== null) {\n\t\tconst cacheFunctions = ['get', 'set', 'delete', 'clear'] as const;\n\t\tconst missingFunctions = cacheFunctions.filter(\n\t\t\t(fnName) => cacheMap && typeof cacheMap[fnName] !== 'function',\n\t\t);\n\t\tif (missingFunctions.length !== 0) {\n\t\t\tthrow new TypeError('Custom cacheMap missing methods: ' + missingFunctions.join(', '));\n\t\t}\n\t}\n\treturn cacheMap;\n}\n\nfunction getValidName<K, V, C>(options?: DataLoader.Options<K, V, C>): string | null {\n\tif (options && options.name) {\n\t\treturn options.name;\n\t}\n\n\treturn null;\n}\n\nfunction isArrayLike(x: unknown): x is ArrayLike<unknown> {\n\treturn (\n\t\ttypeof x === 'object' &&\n\t\tx !== null &&\n\t\t'length' in x &&\n\t\ttypeof x.length === 'number' &&\n\t\t(x.length === 0 || (x.length > 0 && Object.prototype.hasOwnProperty.call(x, x.length - 1)))\n\t);\n}\n\nexport declare namespace DataLoader {\n\t// If a custom cache is provided, it must be of this type (a subset of ES6 Map).\n\texport type CacheMap<K, V> = {\n\t\tget(key: K): V | void;\n\t\tset(key: K, value: V): any;\n\t\tdelete(key: K): any;\n\t\tclear(): any;\n\t};\n\n\t// A Function, which when given an Array of keys, returns a Promise of an Array\n\t// of values or Errors.\n\texport type BatchLoadFn<K, V> = (keys: ReadonlyArray<K>) => PromiseLike<ArrayLike<V | Error>>;\n\n\t// Optionally turn off batching or caching or provide a cache key function or a\n\t// custom cache instance.\n\texport type Options<K, V, C = K> = {\n\t\t/**\n\t\t * Default `true`. Set to `false` to disable batching, invoking\n\t\t * `batchLoadFn` with a single load key. This is equivalent to setting\n\t\t * `maxBatchSize` to `1`.\n\t\t */\n\t\tbatch?: boolean;\n\n\t\t/**\n\t\t * Default `Infinity`. Limits the number of items that get passed in to the\n\t\t * `batchLoadFn`. May be set to `1` to disable batching.\n\t\t */\n\t\tmaxBatchSize?: number;\n\n\t\t/**\n\t\t * Default see https://github.com/graphql/dataloader#batch-scheduling.\n\t\t * A function to schedule the later execution of a batch. The function is\n\t\t * expected to call the provided callback in the immediate future.\n\t\t */\n\t\tbatchScheduleFn?: (callback: () => void) => void;\n\n\t\t/**\n\t\t * Default `true`. Set to `false` to disable memoization caching, creating a\n\t\t * new Promise and new key in the `batchLoadFn` for every load of the same\n\t\t * key. This is equivalent to setting `cacheMap` to `null`.\n\t\t */\n\t\tcache?: boolean;\n\n\t\t/**\n\t\t * Default `key => key`. Produces cache key for a given load key. Useful\n\t\t * when keys are objects and two objects should be considered equivalent.\n\t\t */\n\t\tcacheKeyFn?: (key: K) => C;\n\n\t\t/**\n\t\t * Default `new Map()`. Instance of `Map` (or an object with a similar API)\n\t\t * to be used as cache. May be set to `null` to disable caching.\n\t\t */\n\t\tcacheMap?: CacheMap<C, Promise<V>> | null;\n\n\t\t/**\n\t\t * The name given to this `DataLoader` instance. Useful for APM tools.\n\t\t *\n\t\t * Is `null` if not set in the constructor.\n\t\t */\n\t\tname?: string | null;\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,IAAa,aAAb,MAAqC;CACpC,YAAY,aAA2C,SAAuC;AAC7F,MAAI,OAAO,gBAAgB,WAC1B,OAAM,IAAI,UACT,uHAC2D,YAAY,GACvE;AAEF,OAAK,eAAe;AACpB,OAAK,gBAAgB,qBAAqB,QAAQ;AAClD,OAAK,mBAAmB,wBAAwB,QAAQ;AACxD,OAAK,cAAc,mBAAmB,QAAQ;AAC9C,OAAK,YAAY,iBAAiB,QAAQ;AAC1C,OAAK,SAAS;AACd,OAAK,OAAO,aAAa,QAAQ;;;;;CAclC,KAAK,KAAoB;AACxB,MAAI,QAAQ,QAAQ,QAAQ,OAC3B,OAAM,IAAI,UACT,oEAAoE,OAAO,IAAI,CAAC,GAChF;EAGF,MAAM,QAAQ,gBAAgB,KAAK;EACnC,MAAM,WAAW,KAAK;EACtB,IAAI;AAGJ,MAAI,UAAU;AACb,cAAW,KAAK,YAAY,IAAI;GAChC,MAAM,gBAAgB,SAAS,IAAI,SA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AM,WAAW,WAAW,QAAQ;AACpC,KAAI,aAAa,OAChB,wBAAO,IAAI,KAAK;AAEjB,KAAI,aAAa,MAAM;EAEtB,MAAM,mBADiB;GAAC;GAAO;GAAO;GAAU;GAAQ,CAChB,QACtC,WAAW,YAAY,OAAO,SAAS,YAAY,WACpD;AACD,MAAI,iBAAiB,WAAW,EAC/B,OAAM,IAAI,UAAU,sCAAsC,iBAAiB,KAAK,KAAK,CAAC;;AAGxF,QAAO;;AAGR,SAAS,aAAsB,SAAsD;AACpF,KAAI,WAAW,QAAQ,KACtB,QAAO,QAAQ;AAGhB,QAAO;;AAGR,SAAS,YAAY,GAAqC;AACzD,QACC,OAAO,MAAM,YACb,MAAM,QACN,YAAY,KACZ,OAAO,EAAE,WAAW,aACnB,EAAE,WAAW,KAAM,EAAE,SAAS,KAAK,OAAO,UAAU,eAAe,KAAK,GAAG,EAAE,SAAS,EAAE"}
|
|
1
|
+
{"version":3,"file":"dataloader.mjs","names":[],"sources":["../src/dataloader.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * DataLoader - A generic utility for batching and caching data fetches.\n *\n * Vendored from: https://github.com/graphql/dataloader\n * Commit: a10773043d41a56bde4219c155fcf5633e6c9bcb\n * License: MIT\n * Copyright (c) GraphQL Contributors\n */\n\n/**\n * A `DataLoader` creates a public API for loading data from a particular\n * data back-end with unique keys such as the `id` column of a SQL table or\n * document name in a MongoDB database, given a batch loading function.\n *\n * Each `DataLoader` instance contains a unique memoized cache. Use caution when\n * used in long-lived applications or those which serve many users with\n * different access permissions and consider creating a new instance per\n * web request.\n */\nexport class DataLoader<K, V, C = K> {\n\tconstructor(batchLoadFn: DataLoader.BatchLoadFn<K, V>, options?: DataLoader.Options<K, V, C>) {\n\t\tif (typeof batchLoadFn !== 'function') {\n\t\t\tthrow new TypeError(\n\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t`Array<key> and returns Promise<Array<value>>, but got: ${batchLoadFn}.`,\n\t\t\t);\n\t\t}\n\t\tthis._batchLoadFn = batchLoadFn;\n\t\tthis._maxBatchSize = getValidMaxBatchSize(options);\n\t\tthis._batchScheduleFn = getValidBatchScheduleFn(options);\n\t\tthis._cacheKeyFn = getValidCacheKeyFn(options);\n\t\tthis._cacheMap = getValidCacheMap(options);\n\t\tthis._batch = null;\n\t\tthis.name = getValidName(options);\n\t}\n\n\t// Private\n\t_batchLoadFn: DataLoader.BatchLoadFn<K, V>;\n\t_maxBatchSize: number;\n\t_batchScheduleFn: (cb: () => void) => void;\n\t_cacheKeyFn: (key: K) => C;\n\t_cacheMap: DataLoader.CacheMap<C, Promise<V>> | null;\n\t_batch: Batch<K, V> | null;\n\n\t/**\n\t * Loads a key, returning a `Promise` for the value represented by that key.\n\t */\n\tload(key: K): Promise<V> {\n\t\tif (key === null || key === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`The loader.load() function must be called with a value, but got: ${String(key)}.`,\n\t\t\t);\n\t\t}\n\n\t\tconst batch = getCurrentBatch(this);\n\t\tconst cacheMap = this._cacheMap;\n\t\tlet cacheKey: C;\n\n\t\t// If caching and there is a cache-hit, return cached Promise.\n\t\tif (cacheMap) {\n\t\t\tcacheKey = this._cacheKeyFn(key);\n\t\t\tconst cachedPromise = cacheMap.get(cacheKey);\n\t\t\tif (cachedPromise) {\n\t\t\t\tconst cacheHits = batch.cacheHits || (batch.cacheHits = []);\n\t\t\t\treturn new Promise((resolve) => {\n\t\t\t\t\tcacheHits.push(() => {\n\t\t\t\t\t\tresolve(cachedPromise);\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Otherwise, produce a new Promise for this key, and enqueue it to be\n\t\t// dispatched along with the current batch.\n\t\tbatch.keys.push(key);\n\t\tconst promise = new Promise<V>((resolve, reject) => {\n\t\t\tbatch.callbacks.push({ resolve, reject });\n\t\t});\n\n\t\t// If caching, cache this promise.\n\t\tif (cacheMap) {\n\t\t\tcacheMap.set(cacheKey!, promise);\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Loads multiple keys, promising an array of values:\n\t *\n\t * var [ a, b ] = await myLoader.loadMany([ 'a', 'b' ]);\n\t *\n\t * This is similar to the more verbose:\n\t *\n\t * var [ a, b ] = await Promise.all([\n\t * myLoader.load('a'),\n\t * myLoader.load('b')\n\t * ]);\n\t *\n\t * However it is different in the case where any load fails. Where\n\t * Promise.all() would reject, loadMany() always resolves, however each result\n\t * is either a value or an Error instance.\n\t *\n\t * var [ a, b, c ] = await myLoader.loadMany([ 'a', 'b', 'badkey' ]);\n\t * // c instanceof Error\n\t *\n\t */\n\tloadMany(keys: ReadonlyArray<K>): Promise<Array<V | Error>> {\n\t\tif (!isArrayLike(keys)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`The loader.loadMany() function must be called with Array<key>, but got: ${keys}.`,\n\t\t\t);\n\t\t}\n\t\t// Support ArrayLike by using only minimal property access\n\t\tconst loadPromises = [];\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tloadPromises.push(this.load(keys[i]).catch((error) => error));\n\t\t}\n\t\treturn Promise.all(loadPromises);\n\t}\n\n\t/**\n\t * Clears the value at `key` from the cache, if it exists. Returns itself for\n\t * method chaining.\n\t */\n\tclear(key: K): this {\n\t\tconst cacheMap = this._cacheMap;\n\t\tif (cacheMap) {\n\t\t\tconst cacheKey = this._cacheKeyFn(key);\n\t\t\tcacheMap.delete(cacheKey);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears the entire cache. To be used when some event results in unknown\n\t * invalidations across this particular `DataLoader`. Returns itself for\n\t * method chaining.\n\t */\n\tclearAll(): this {\n\t\tconst cacheMap = this._cacheMap;\n\t\tif (cacheMap) {\n\t\t\tcacheMap.clear();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the provided key and value to the cache. If the key already\n\t * exists, no change is made. Returns itself for method chaining.\n\t *\n\t * To prime the cache with an error at a key, provide an Error instance.\n\t */\n\tprime(key: K, value: V | Promise<V> | Error): this {\n\t\tconst cacheMap = this._cacheMap;\n\t\tif (cacheMap) {\n\t\t\tconst cacheKey = this._cacheKeyFn(key);\n\n\t\t\t// Only add the key if it does not already exist.\n\t\t\tif (cacheMap.get(cacheKey) === undefined) {\n\t\t\t\t// Cache a rejected promise if the value is an Error, in order to match\n\t\t\t\t// the behavior of load(key).\n\t\t\t\tlet promise;\n\t\t\t\tif (value instanceof Error) {\n\t\t\t\t\tpromise = Promise.reject(value);\n\t\t\t\t\t// Since this is a case where an Error is intentionally being primed\n\t\t\t\t\t// for a given key, we want to disable unhandled promise rejection.\n\t\t\t\t\tpromise.catch(() => {});\n\t\t\t\t} else {\n\t\t\t\t\tpromise = Promise.resolve(value);\n\t\t\t\t}\n\t\t\t\tcacheMap.set(cacheKey, promise);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The name given to this `DataLoader` instance. Useful for APM tools.\n\t *\n\t * Is `null` if not set in the constructor.\n\t */\n\tname: string | null;\n}\n\n// Private: Enqueue a Job to be executed after all \"PromiseJobs\" Jobs.\n//\n// ES6 JavaScript uses the concepts Job and JobQueue to schedule work to occur\n// after the current execution context has completed:\n// http://www.ecma-international.org/ecma-262/6.0/#sec-jobs-and-job-queues\n//\n// Node.js uses the `process.nextTick` mechanism to implement the concept of a\n// Job, maintaining a global FIFO JobQueue for all Jobs, which is flushed after\n// the current call stack ends.\n//\n// When calling `then` on a Promise, it enqueues a Job on a specific\n// \"PromiseJobs\" JobQueue which is flushed in Node as a single Job on the\n// global JobQueue.\n//\n// DataLoader batches all loads which occur in a single frame of execution, but\n// should include in the batch all loads which occur during the flushing of the\n// \"PromiseJobs\" JobQueue after that same execution frame.\n//\n// In order to avoid the DataLoader dispatch Job occuring before \"PromiseJobs\",\n// A Promise Job is created with the sole purpose of enqueuing a global Job,\n// ensuring that it always occurs after \"PromiseJobs\" ends.\n//\n// Node.js's job queue is unique. Browsers do not have an equivalent mechanism\n// for enqueuing a job to be performed after promise microtasks and before the\n// next macrotask. For browser environments, a macrotask is used (via\n// setImmediate or setTimeout) at a potential performance penalty.\nconst enqueuePostPromiseJob: (fn: () => void) => void =\n\t// @ts-ignore\n\ttypeof process === 'object' && typeof process.nextTick === 'function'\n\t\t? function (fn) {\n\t\t\t\tif (!resolvedPromise) {\n\t\t\t\t\tresolvedPromise = Promise.resolve();\n\t\t\t\t}\n\t\t\t\tresolvedPromise.then(() => {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tprocess.nextTick(fn);\n\t\t\t\t});\n\t\t\t}\n\t\t: // @ts-ignore\n\t\t\ttypeof setImmediate === 'function'\n\t\t\t? function (fn) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tsetImmediate(fn);\n\t\t\t\t}\n\t\t\t: function (fn) {\n\t\t\t\t\tsetTimeout(fn);\n\t\t\t\t};\n\n// Private: cached resolved Promise instance\nlet resolvedPromise: Promise<void> | undefined;\n\n// Private: Describes a batch of requests\ntype Batch<K, V> = {\n\thasDispatched: boolean;\n\tkeys: Array<K>;\n\tcallbacks: Array<{\n\t\tresolve: (value: V) => void;\n\t\treject: (error: Error) => void;\n\t}>;\n\tcacheHits?: Array<() => void>;\n};\n\n// Private: Either returns the current batch, or creates and schedules a\n// dispatch of a new batch for the given loader.\nfunction getCurrentBatch<K, V>(loader: DataLoader<K, V, any>): Batch<K, V> {\n\t// If there is an existing batch which has not yet dispatched and is within\n\t// the limit of the batch size, then return it.\n\tconst existingBatch = loader._batch;\n\tif (\n\t\texistingBatch !== null &&\n\t\t!existingBatch.hasDispatched &&\n\t\texistingBatch.keys.length < loader._maxBatchSize\n\t) {\n\t\treturn existingBatch;\n\t}\n\n\t// Otherwise, create a new batch for this loader.\n\tconst newBatch = { hasDispatched: false, keys: [], callbacks: [] };\n\n\t// Store it on the loader so it may be reused.\n\tloader._batch = newBatch;\n\n\t// Then schedule a task to dispatch this batch of requests.\n\tloader._batchScheduleFn(() => {\n\t\tdispatchBatch(loader, newBatch);\n\t});\n\n\treturn newBatch;\n}\n\nfunction dispatchBatch<K, V>(loader: DataLoader<K, V, any>, batch: Batch<K, V>) {\n\t// Mark this batch as having been dispatched.\n\tbatch.hasDispatched = true;\n\n\t// If there's nothing to load, resolve any cache hits and return early.\n\tif (batch.keys.length === 0) {\n\t\tresolveCacheHits(batch);\n\t\treturn;\n\t}\n\n\t// Call the provided batchLoadFn for this loader with the batch's keys and\n\t// with the loader as the `this` context.\n\tlet batchPromise;\n\ttry {\n\t\tbatchPromise = loader._batchLoadFn(batch.keys);\n\t} catch (e) {\n\t\treturn failedDispatch(\n\t\t\tloader,\n\t\t\tbatch,\n\t\t\tnew TypeError(\n\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function ' +\n\t\t\t\t\t`errored synchronously: ${String(e)}.`,\n\t\t\t),\n\t\t);\n\t}\n\n\t// Assert the expected response from batchLoadFn\n\tif (!batchPromise || typeof batchPromise.then !== 'function') {\n\t\treturn failedDispatch(\n\t\t\tloader,\n\t\t\tbatch,\n\t\t\tnew TypeError(\n\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function did ' +\n\t\t\t\t\t`not return a Promise: ${String(batchPromise)}.`,\n\t\t\t),\n\t\t);\n\t}\n\n\t// Await the resolution of the call to batchLoadFn.\n\tPromise.resolve(batchPromise)\n\t\t.then((values) => {\n\t\t\t// Assert the expected resolution from batchLoadFn.\n\t\t\tif (!isArrayLike(values)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function did ' +\n\t\t\t\t\t\t`not return a Promise of an Array: ${String(values)}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (values.length !== batch.keys.length) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t'DataLoader must be constructed with a function which accepts ' +\n\t\t\t\t\t\t'Array<key> and returns Promise<Array<value>>, but the function did ' +\n\t\t\t\t\t\t'not return a Promise of an Array of the same length as the Array ' +\n\t\t\t\t\t\t'of keys.' +\n\t\t\t\t\t\t`\\n\\nKeys:\\n${String(batch.keys)}` +\n\t\t\t\t\t\t`\\n\\nValues:\\n${String(values)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Resolve all cache hits in the same micro-task as freshly loaded values.\n\t\t\tresolveCacheHits(batch);\n\n\t\t\t// Step through values, resolving or rejecting each Promise in the batch.\n\t\t\tfor (let i = 0; i < batch.callbacks.length; i++) {\n\t\t\t\tconst value = values[i];\n\t\t\t\tif (value instanceof Error) {\n\t\t\t\t\tbatch.callbacks[i].reject(value);\n\t\t\t\t} else {\n\t\t\t\t\tbatch.callbacks[i].resolve(value);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.catch((error: unknown) => {\n\t\t\tfailedDispatch(loader, batch, error as Error);\n\t\t});\n}\n\n// Private: do not cache individual loads if the entire batch dispatch fails,\n// but still reject each request so they do not hang.\nfunction failedDispatch<K, V>(loader: DataLoader<K, V, any>, batch: Batch<K, V>, error: Error) {\n\t// Cache hits are resolved, even though the batch failed.\n\tresolveCacheHits(batch);\n\tfor (let i = 0; i < batch.keys.length; i++) {\n\t\tloader.clear(batch.keys[i]);\n\t\tbatch.callbacks[i].reject(error);\n\t}\n}\n\n// Private: Resolves the Promises for any cache hits in this batch.\nfunction resolveCacheHits(batch: Batch<any, any>) {\n\tif (batch.cacheHits) {\n\t\tfor (let i = 0; i < batch.cacheHits.length; i++) {\n\t\t\tbatch.cacheHits[i]();\n\t\t}\n\t}\n}\n\n// Private: given the DataLoader's options, produce a valid max batch size.\nfunction getValidMaxBatchSize<K, V, C>(options?: DataLoader.Options<K, V, C>): number {\n\tconst shouldBatch = !options || options.batch !== false;\n\tif (!shouldBatch) {\n\t\treturn 1;\n\t}\n\tconst maxBatchSize = options && options.maxBatchSize;\n\tif (maxBatchSize === undefined) {\n\t\treturn Infinity;\n\t}\n\tif (typeof maxBatchSize !== 'number' || maxBatchSize < 1) {\n\t\tthrow new TypeError(`maxBatchSize must be a positive number: ${maxBatchSize}`);\n\t}\n\treturn maxBatchSize;\n}\n\n// Private\nfunction getValidBatchScheduleFn<K, V, C>(\n\toptions?: DataLoader.Options<K, V, C>,\n): (cb: () => void) => void {\n\tconst batchScheduleFn = options && options.batchScheduleFn;\n\tif (batchScheduleFn === undefined) {\n\t\treturn enqueuePostPromiseJob;\n\t}\n\tif (typeof batchScheduleFn !== 'function') {\n\t\tthrow new TypeError(`batchScheduleFn must be a function: ${batchScheduleFn}`);\n\t}\n\treturn batchScheduleFn;\n}\n\n// Private: given the DataLoader's options, produce a cache key function.\nfunction getValidCacheKeyFn<K, V, C>(options?: DataLoader.Options<K, V, C>): (key: K) => C {\n\tconst cacheKeyFn = options && options.cacheKeyFn;\n\tif (cacheKeyFn === undefined) {\n\t\treturn (key: K) => key as unknown as C;\n\t}\n\tif (typeof cacheKeyFn !== 'function') {\n\t\tthrow new TypeError(`cacheKeyFn must be a function: ${cacheKeyFn}`);\n\t}\n\treturn cacheKeyFn;\n}\n\n// Private: given the DataLoader's options, produce a CacheMap to be used.\nfunction getValidCacheMap<K, V, C>(\n\toptions?: DataLoader.Options<K, V, C>,\n): DataLoader.CacheMap<C, Promise<V>> | null {\n\tconst shouldCache = !options || options.cache !== false;\n\tif (!shouldCache) {\n\t\treturn null;\n\t}\n\tconst cacheMap = options && options.cacheMap;\n\tif (cacheMap === undefined) {\n\t\treturn new Map();\n\t}\n\tif (cacheMap !== null) {\n\t\tconst cacheFunctions = ['get', 'set', 'delete', 'clear'] as const;\n\t\tconst missingFunctions = cacheFunctions.filter(\n\t\t\t(fnName) => cacheMap && typeof cacheMap[fnName] !== 'function',\n\t\t);\n\t\tif (missingFunctions.length !== 0) {\n\t\t\tthrow new TypeError('Custom cacheMap missing methods: ' + missingFunctions.join(', '));\n\t\t}\n\t}\n\treturn cacheMap;\n}\n\nfunction getValidName<K, V, C>(options?: DataLoader.Options<K, V, C>): string | null {\n\tif (options && options.name) {\n\t\treturn options.name;\n\t}\n\n\treturn null;\n}\n\nfunction isArrayLike(x: unknown): x is ArrayLike<unknown> {\n\treturn (\n\t\ttypeof x === 'object' &&\n\t\tx !== null &&\n\t\t'length' in x &&\n\t\ttypeof x.length === 'number' &&\n\t\t(x.length === 0 || (x.length > 0 && Object.prototype.hasOwnProperty.call(x, x.length - 1)))\n\t);\n}\n\nexport declare namespace DataLoader {\n\t// If a custom cache is provided, it must be of this type (a subset of ES6 Map).\n\texport type CacheMap<K, V> = {\n\t\tget(key: K): V | void;\n\t\tset(key: K, value: V): any;\n\t\tdelete(key: K): any;\n\t\tclear(): any;\n\t};\n\n\t// A Function, which when given an Array of keys, returns a Promise of an Array\n\t// of values or Errors.\n\texport type BatchLoadFn<K, V> = (keys: ReadonlyArray<K>) => PromiseLike<ArrayLike<V | Error>>;\n\n\t// Optionally turn off batching or caching or provide a cache key function or a\n\t// custom cache instance.\n\texport type Options<K, V, C = K> = {\n\t\t/**\n\t\t * Default `true`. Set to `false` to disable batching, invoking\n\t\t * `batchLoadFn` with a single load key. This is equivalent to setting\n\t\t * `maxBatchSize` to `1`.\n\t\t */\n\t\tbatch?: boolean;\n\n\t\t/**\n\t\t * Default `Infinity`. Limits the number of items that get passed in to the\n\t\t * `batchLoadFn`. May be set to `1` to disable batching.\n\t\t */\n\t\tmaxBatchSize?: number;\n\n\t\t/**\n\t\t * Default see https://github.com/graphql/dataloader#batch-scheduling.\n\t\t * A function to schedule the later execution of a batch. The function is\n\t\t * expected to call the provided callback in the immediate future.\n\t\t */\n\t\tbatchScheduleFn?: (callback: () => void) => void;\n\n\t\t/**\n\t\t * Default `true`. Set to `false` to disable memoization caching, creating a\n\t\t * new Promise and new key in the `batchLoadFn` for every load of the same\n\t\t * key. This is equivalent to setting `cacheMap` to `null`.\n\t\t */\n\t\tcache?: boolean;\n\n\t\t/**\n\t\t * Default `key => key`. Produces cache key for a given load key. Useful\n\t\t * when keys are objects and two objects should be considered equivalent.\n\t\t */\n\t\tcacheKeyFn?: (key: K) => C;\n\n\t\t/**\n\t\t * Default `new Map()`. Instance of `Map` (or an object with a similar API)\n\t\t * to be used as cache. May be set to `null` to disable caching.\n\t\t */\n\t\tcacheMap?: CacheMap<C, Promise<V>> | null;\n\n\t\t/**\n\t\t * The name given to this `DataLoader` instance. Useful for APM tools.\n\t\t *\n\t\t * Is `null` if not set in the constructor.\n\t\t */\n\t\tname?: string | null;\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,IAAa,aAAb,MAAqC;CACpC,YAAY,aAA2C,SAAuC;EAC7F,IAAI,OAAO,gBAAgB,YAC1B,MAAM,IAAI,UACT,uHAC2D,YAAY,EACxE;EAED,KAAK,eAAe;EACpB,KAAK,gBAAgB,qBAAqB,OAAO;EACjD,KAAK,mBAAmB,wBAAwB,OAAO;EACvD,KAAK,cAAc,mBAAmB,OAAO;EAC7C,KAAK,YAAY,iBAAiB,OAAO;EACzC,KAAK,SAAS;EACd,KAAK,OAAO,aAAa,OAAO;CACjC;;;;CAaA,KAAK,KAAoB;EACxB,IAAI,QAAQ,QAAQ,QAAQ,KAAA,GAC3B,MAAM,IAAI,UACT,oEAAoE,OAAO,GAAG,EAAE,EACjF;EAGD,MAAM,QAAQ,gBAAgB,IAAI;EAClC,MAAM,WAAW,KAAK;EACtB,IAAI;EAGJ,IAAI,UAAU;GACb,WAAW,KAAK,YAAY,GAAG;GAC/B,MAAM,gBAAgB,SAAS,IAAI,QAAQ;GAC3C,IAAI,eAAe;IAClB,MAAM,YAAY,MAAM,cAAc,MAAM,YAAY,CAAC;IACzD,OAAO,IAAI,SAAS,YAAY;KAC/B,UAAU,WAAW;MACpB,QAAQ,aAAa;KACtB,CAAC;IACF,CAAC;GACF;EACD;EAIA,MAAM,KAAK,KAAK,GAAG;EACnB,MAAM,UAA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W,WAAW,QAAQ;CACpC,IAAI,aAAa,KAAA,GAChB,uBAAO,IAAI,IAAI;CAEhB,IAAI,aAAa,MAAM;EAEtB,MAAM,mBAAmB;GADD;GAAO;GAAO;GAAU;EACV,CAAC,CAAC,QACtC,WAAW,YAAY,OAAO,SAAS,YAAY,UACrD;EACA,IAAI,iBAAiB,WAAW,GAC/B,MAAM,IAAI,UAAU,sCAAsC,iBAAiB,KAAK,IAAI,CAAC;CAEvF;CACA,OAAO;AACR;AAEA,SAAS,aAAsB,SAAsD;CACpF,IAAI,WAAW,QAAQ,MACtB,OAAO,QAAQ;CAGhB,OAAO;AACR;AAEA,SAAS,YAAY,GAAqC;CACzD,OACC,OAAO,MAAM,YACb,MAAM,QACN,YAAY,KACZ,OAAO,EAAE,WAAW,aACnB,EAAE,WAAW,KAAM,EAAE,SAAS,KAAK,OAAO,UAAU,eAAe,KAAK,GAAG,EAAE,SAAS,CAAC;AAE1F"}
|
package/dist/hex.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.mts","names":[],"sources":["../src/hex.ts"],"mappings":";iBAGgB,OAAA,CAAQ,MAAA,WAAiB,
|
|
1
|
+
{"version":3,"file":"hex.d.mts","names":[],"sources":["../src/hex.ts"],"mappings":";iBAGgB,OAAA,CAAQ,MAAA,WAAiB,UAAU,CAAC,WAAA;AAAA,iBAYpC,KAAA,CAAM,KAAiB,EAAV,UAAU"}
|
package/dist/hex.mjs
CHANGED
package/dist/hex.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.mjs","names":[],"sources":["../src/hex.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function fromHex(hexStr: string): Uint8Array<ArrayBuffer> {\n\tconst normalized = hexStr.startsWith('0x') ? hexStr.slice(2) : hexStr;\n\tconst padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;\n\tconst intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];\n\n\tif (intArr.length !== padded.length / 2) {\n\t\tthrow new Error(`Invalid hex string ${hexStr}`);\n\t}\n\n\treturn Uint8Array.from(intArr);\n}\n\nexport function toHex(bytes: Uint8Array): string {\n\treturn bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n}\n"],"mappings":";AAGA,SAAgB,QAAQ,QAAyC;CAChE,MAAM,aAAa,OAAO,WAAW,
|
|
1
|
+
{"version":3,"file":"hex.mjs","names":[],"sources":["../src/hex.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport function fromHex(hexStr: string): Uint8Array<ArrayBuffer> {\n\tconst normalized = hexStr.startsWith('0x') ? hexStr.slice(2) : hexStr;\n\tconst padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;\n\tconst intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];\n\n\tif (intArr.length !== padded.length / 2) {\n\t\tthrow new Error(`Invalid hex string ${hexStr}`);\n\t}\n\n\treturn Uint8Array.from(intArr);\n}\n\nexport function toHex(bytes: Uint8Array): string {\n\treturn bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n}\n"],"mappings":";AAGA,SAAgB,QAAQ,QAAyC;CAChE,MAAM,aAAa,OAAO,WAAW,IAAI,IAAI,OAAO,MAAM,CAAC,IAAI;CAC/D,MAAM,SAAS,WAAW,SAAS,MAAM,IAAI,aAAa,IAAI;CAC9D,MAAM,SAAS,OAAO,MAAM,iBAAiB,CAAC,EAAE,KAAK,SAAS,SAAS,MAAM,EAAE,CAAC,KAAK,CAAC;CAEtF,IAAI,OAAO,WAAW,OAAO,SAAS,GACrC,MAAM,IAAI,MAAM,sBAAsB,QAAQ;CAG/C,OAAO,WAAW,KAAK,MAAM;AAC9B;AAEA,SAAgB,MAAM,OAA2B;CAChD,OAAO,MAAM,QAAQ,KAAK,SAAS,MAAM,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EAAE;AAChF"}
|
package/dist/index.mjs
CHANGED
|
@@ -5,5 +5,4 @@ import { chunk } from "./chunk.mjs";
|
|
|
5
5
|
import { promiseWithResolvers } from "./with-resolver.mjs";
|
|
6
6
|
import { DataLoader } from "./dataloader.mjs";
|
|
7
7
|
import mitt from "./mitt.mjs";
|
|
8
|
-
|
|
9
|
-
export { DataLoader, chunk, fromBase58, fromBase64, fromHex, mitt, promiseWithResolvers, toBase58, toBase64, toHex };
|
|
8
|
+
export { DataLoader, chunk, fromBase58, fromBase64, fromHex, mitt, promiseWithResolvers, toBase58, toBase64, toHex };
|
package/dist/mitt.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mitt.d.mts","names":[],"sources":["../src/mitt.ts"],"mappings":";;AAWA
|
|
1
|
+
{"version":3,"file":"mitt.d.mts","names":[],"sources":["../src/mitt.ts"],"mappings":";;AAWA;;;;AAAqB;AAIrB;KAJY,SAAA;AAAA,KAIA,OAAA,iBAAwB,KAAA,EAAO,CAAC;AAAA,KAChC,eAAA,KAAoB,MAAA,sBAC/B,IAAA,QAAY,CAAA,EACZ,KAAA,EAAO,CAAA,OAAQ,CAAA;AAAA,KAIJ,gBAAA,gBAAgC,KAAA,CAAM,OAAA,CAAQ,CAAA;AAAA,KAC9C,wBAAA,KAA6B,MAAA,qBAA2B,KAAA,CAAM,eAAA,CAAgB,CAAA;AAAA,KAG9E,eAAA,gBAA+B,MAAA,CAAO,SAAA,cAAuB,GAAA,OAClE,MAAA,QACN,gBAAA,CAAiB,MAAA,OAAa,MAAA,KAAW,wBAAA,CAAyB,MAAA;AAAA,UAGlD,OAAA,gBAAuB,MAAA,CAAO,SAAA;EAC9C,GAAA,EAAK,eAAA,CAAgB,MAAA;EAErB,EAAA,mBAAqB,MAAA,EAAQ,IAAA,EAAM,GAAA,EAAK,OAAA,EAAS,OAAA,CAAQ,MAAA,CAAO,GAAA;EAChE,EAAA,CAAG,IAAA,OAAW,OAAA,EAAS,eAAA,CAAgB,MAAA;EAEvC,GAAA,mBAAsB,MAAA,EAAQ,IAAA,EAAM,GAAA,EAAK,OAAA,GAAU,OAAA,CAAQ,MAAA,CAAO,GAAA;EAClE,GAAA,CAAI,IAAA,OAAW,OAAA,EAAS,eAAA,CAAgB,MAAA;EAExC,IAAA,mBAAuB,MAAA,EAAQ,IAAA,EAAM,GAAA,EAAK,KAAA,EAAO,MAAA,CAAO,GAAA;EACxD,IAAA,mBAAuB,MAAA,EAAQ,IAAA,oBAAwB,MAAA,CAAO,GAAA,IAAO,GAAA;AAAA;;;;;;iBAQ9C,IAAA,gBAAoB,MAAA,CAAO,SAAA,YAClD,GAAA,GAAM,eAAA,CAAgB,MAAA,IACpB,OAAA,CAAQ,MAAA"}
|
package/dist/mitt.mjs
CHANGED
|
@@ -7,17 +7,40 @@
|
|
|
7
7
|
function mitt(all) {
|
|
8
8
|
all = all || /* @__PURE__ */ new Map();
|
|
9
9
|
return {
|
|
10
|
+
/**
|
|
11
|
+
* A Map of event names to registered handler functions.
|
|
12
|
+
*/
|
|
10
13
|
all,
|
|
14
|
+
/**
|
|
15
|
+
* Register an event handler for the given type.
|
|
16
|
+
* @param type Type of event to listen for, or `'*'` for all events
|
|
17
|
+
* @param handler Function to call in response to given event
|
|
18
|
+
*/
|
|
11
19
|
on(type, handler) {
|
|
12
20
|
const handlers = all.get(type);
|
|
13
21
|
if (handlers) handlers.push(handler);
|
|
14
22
|
else all.set(type, [handler]);
|
|
15
23
|
},
|
|
24
|
+
/**
|
|
25
|
+
* Remove an event handler for the given type.
|
|
26
|
+
* If `handler` is omitted, all handlers of the given type are removed.
|
|
27
|
+
* @param type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)
|
|
28
|
+
* @param handler Handler function to remove
|
|
29
|
+
*/
|
|
16
30
|
off(type, handler) {
|
|
17
31
|
const handlers = all.get(type);
|
|
18
32
|
if (handlers) if (handler) handlers.splice(handlers.indexOf(handler) >>> 0, 1);
|
|
19
33
|
else all.set(type, []);
|
|
20
34
|
},
|
|
35
|
+
/**
|
|
36
|
+
* Invoke all handlers for the given type.
|
|
37
|
+
* If present, `'*'` handlers are invoked after type-matched handlers.
|
|
38
|
+
*
|
|
39
|
+
* Note: Manually firing '*' handlers is not supported.
|
|
40
|
+
*
|
|
41
|
+
* @param type The event type to invoke
|
|
42
|
+
* @param evt Any value (object is recommended and powerful), passed to each handler
|
|
43
|
+
*/
|
|
21
44
|
emit(type, evt) {
|
|
22
45
|
let handlers = all.get(type);
|
|
23
46
|
if (handlers) handlers.slice().map((handler) => {
|
|
@@ -30,7 +53,7 @@ function mitt(all) {
|
|
|
30
53
|
}
|
|
31
54
|
};
|
|
32
55
|
}
|
|
33
|
-
|
|
34
56
|
//#endregion
|
|
35
57
|
export { mitt as default };
|
|
58
|
+
|
|
36
59
|
//# sourceMappingURL=mitt.mjs.map
|
package/dist/mitt.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mitt.mjs","names":[],"sources":["../src/mitt.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Mitt - Tiny (~200b) functional event emitter / pubsub.\n *\n * Vendored from: https://github.com/developit/mitt\n * License: MIT\n * Copyright (c) 2021 Jason Miller\n */\n\nexport type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler<T = unknown> = (event: T) => void;\nexport type WildcardHandler<T = Record<string, unknown>> = (\n\ttype: keyof T,\n\tevent: T[keyof T],\n) => void;\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList<T = unknown> = Array<Handler<T>>;\nexport type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<\n\tkeyof Events | '*',\n\tEventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>\n>;\n\nexport interface Emitter<Events extends Record<EventType, unknown>> {\n\tall: EventHandlerMap<Events>;\n\n\ton<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;\n\ton(type: '*', handler: WildcardHandler<Events>): void;\n\n\toff<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;\n\toff(type: '*', handler: WildcardHandler<Events>): void;\n\n\temit<Key extends keyof Events>(type: Key, event: Events[Key]): void;\n\temit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;\n}\n\n/**\n * Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt<Events extends Record<EventType, unknown>>(\n\tall?: EventHandlerMap<Events>,\n): Emitter<Events> {\n\ttype GenericEventHandler = Handler<Events[keyof Events]> | WildcardHandler<Events>;\n\tall = all || new Map();\n\n\treturn {\n\t\t/**\n\t\t * A Map of event names to registered handler functions.\n\t\t */\n\t\tall,\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param type Type of event to listen for, or `'*'` for all events\n\t\t * @param handler Function to call in response to given event\n\t\t */\n\t\ton<Key extends keyof Events>(type: Key, handler: GenericEventHandler) {\n\t\t\tconst handlers: Array<GenericEventHandler> | undefined = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.push(handler);\n\t\t\t} else {\n\t\t\t\tall!.set(type, [handler] as EventHandlerList<Events[keyof Events]>);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t * If `handler` is omitted, all handlers of the given type are removed.\n\t\t * @param type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)\n\t\t * @param handler Handler function to remove\n\t\t */\n\t\toff<Key extends keyof Events>(type: Key, handler?: GenericEventHandler) {\n\t\t\tconst handlers: Array<GenericEventHandler> | undefined = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\tif (handler) {\n\t\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t\t} else {\n\t\t\t\t\tall!.set(type, []);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `'*'` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing '*' handlers is not supported.\n\t\t *\n\t\t * @param type The event type to invoke\n\t\t * @param evt Any value (object is recommended and powerful), passed to each handler\n\t\t */\n\t\temit<Key extends keyof Events>(type: Key, evt?: Events[Key]) {\n\t\t\tlet handlers = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\t(handlers as EventHandlerList<Events[keyof Events]>).slice().map((handler) => {\n\t\t\t\t\thandler(evt!);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\thandlers = all!.get('*');\n\t\t\tif (handlers) {\n\t\t\t\t(handlers as WildCardEventHandlerList<Events>).slice().map((handler) => {\n\t\t\t\t\thandler(type, evt!);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AAiDA,SAAwB,KACvB,KACkB;
|
|
1
|
+
{"version":3,"file":"mitt.mjs","names":[],"sources":["../src/mitt.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Mitt - Tiny (~200b) functional event emitter / pubsub.\n *\n * Vendored from: https://github.com/developit/mitt\n * License: MIT\n * Copyright (c) 2021 Jason Miller\n */\n\nexport type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler<T = unknown> = (event: T) => void;\nexport type WildcardHandler<T = Record<string, unknown>> = (\n\ttype: keyof T,\n\tevent: T[keyof T],\n) => void;\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList<T = unknown> = Array<Handler<T>>;\nexport type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<\n\tkeyof Events | '*',\n\tEventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>\n>;\n\nexport interface Emitter<Events extends Record<EventType, unknown>> {\n\tall: EventHandlerMap<Events>;\n\n\ton<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;\n\ton(type: '*', handler: WildcardHandler<Events>): void;\n\n\toff<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;\n\toff(type: '*', handler: WildcardHandler<Events>): void;\n\n\temit<Key extends keyof Events>(type: Key, event: Events[Key]): void;\n\temit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;\n}\n\n/**\n * Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt<Events extends Record<EventType, unknown>>(\n\tall?: EventHandlerMap<Events>,\n): Emitter<Events> {\n\ttype GenericEventHandler = Handler<Events[keyof Events]> | WildcardHandler<Events>;\n\tall = all || new Map();\n\n\treturn {\n\t\t/**\n\t\t * A Map of event names to registered handler functions.\n\t\t */\n\t\tall,\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param type Type of event to listen for, or `'*'` for all events\n\t\t * @param handler Function to call in response to given event\n\t\t */\n\t\ton<Key extends keyof Events>(type: Key, handler: GenericEventHandler) {\n\t\t\tconst handlers: Array<GenericEventHandler> | undefined = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.push(handler);\n\t\t\t} else {\n\t\t\t\tall!.set(type, [handler] as EventHandlerList<Events[keyof Events]>);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t * If `handler` is omitted, all handlers of the given type are removed.\n\t\t * @param type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)\n\t\t * @param handler Handler function to remove\n\t\t */\n\t\toff<Key extends keyof Events>(type: Key, handler?: GenericEventHandler) {\n\t\t\tconst handlers: Array<GenericEventHandler> | undefined = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\tif (handler) {\n\t\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t\t} else {\n\t\t\t\t\tall!.set(type, []);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `'*'` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing '*' handlers is not supported.\n\t\t *\n\t\t * @param type The event type to invoke\n\t\t * @param evt Any value (object is recommended and powerful), passed to each handler\n\t\t */\n\t\temit<Key extends keyof Events>(type: Key, evt?: Events[Key]) {\n\t\t\tlet handlers = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\t(handlers as EventHandlerList<Events[keyof Events]>).slice().map((handler) => {\n\t\t\t\t\thandler(evt!);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\thandlers = all!.get('*');\n\t\t\tif (handlers) {\n\t\t\t\t(handlers as WildCardEventHandlerList<Events>).slice().map((handler) => {\n\t\t\t\t\thandler(type, evt!);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AAiDA,SAAwB,KACvB,KACkB;CAElB,MAAM,uBAAO,IAAI,IAAI;CAErB,OAAO;;;;EAIN;;;;;;EAOA,GAA6B,MAAW,SAA8B;GACrE,MAAM,WAAmD,IAAK,IAAI,IAAI;GACtE,IAAI,UACH,SAAS,KAAK,OAAO;QAErB,IAAK,IAAI,MAAM,CAAC,OAAO,CAA2C;EAEpE;;;;;;;EAQA,IAA8B,MAAW,SAA+B;GACvE,MAAM,WAAmD,IAAK,IAAI,IAAI;GACtE,IAAI,UACH,IAAI,SACH,SAAS,OAAO,SAAS,QAAQ,OAAO,MAAM,GAAG,CAAC;QAElD,IAAK,IAAI,MAAM,CAAC,CAAC;EAGpB;;;;;;;;;;EAWA,KAA+B,MAAW,KAAmB;GAC5D,IAAI,WAAW,IAAK,IAAI,IAAI;GAC5B,IAAI,UACH,SAAqD,MAAM,CAAC,CAAC,KAAK,YAAY;IAC7E,QAAQ,GAAI;GACb,CAAC;GAGF,WAAW,IAAK,IAAI,GAAG;GACvB,IAAI,UACH,SAA+C,MAAM,CAAC,CAAC,KAAK,YAAY;IACvE,QAAQ,MAAM,GAAI;GACnB,CAAC;EAEH;CACD;AACD"}
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";KAGY,QAAA,oBACC,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KAGP,mBAAA,OAA0B,CAAA,gBAAiB,CAAA,EAAG,
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";KAGY,QAAA,oBACC,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KAGP,mBAAA,OAA0B,CAAA,gBAAiB,CAAA,EAAG,CAAC,6BAC1D,CAAA,sBAEE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-resolver.d.mts","names":[],"sources":["../src/with-resolver.ts"],"mappings":";UAGiB,oBAAA;EAChB,OAAA,EAAS,OAAA,CAAQ,CAAA;EACjB,OAAA,GAAU,KAAA,EAAO,CAAA;EACjB,MAAA,GAAS,KAAA;AAAA;AAAA,iBAGM,oBAAA,
|
|
1
|
+
{"version":3,"file":"with-resolver.d.mts","names":[],"sources":["../src/with-resolver.ts"],"mappings":";UAGiB,oBAAA;EAChB,OAAA,EAAS,OAAA,CAAQ,CAAA;EACjB,OAAA,GAAU,KAAA,EAAO,CAAA;EACjB,MAAA,GAAS,KAAA;AAAA;AAAA,iBAGM,oBAAA,OAA2B,oBAAoB,CAAC,CAAA"}
|
package/dist/with-resolver.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-resolver.mjs","names":[],"sources":["../src/with-resolver.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport interface PromiseWithResolvers<T> {\n\tpromise: Promise<T>;\n\tresolve: (value: T) => void;\n\treject: (error: unknown) => void;\n}\n\nexport function promiseWithResolvers<T>(): PromiseWithResolvers<T> {\n\tlet resolver!: (value: T) => void;\n\tlet rejecter!: (error: unknown) => void;\n\n\tconst promise = new Promise<T>((resolve, reject) => {\n\t\tresolver = resolve;\n\t\trejecter = reject;\n\t});\n\n\treturn {\n\t\tpromise,\n\t\tresolve: resolver,\n\t\treject: rejecter,\n\t};\n}\n"],"mappings":";AASA,SAAgB,uBAAmD;CAClE,IAAI;CACJ,IAAI;
|
|
1
|
+
{"version":3,"file":"with-resolver.mjs","names":[],"sources":["../src/with-resolver.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport interface PromiseWithResolvers<T> {\n\tpromise: Promise<T>;\n\tresolve: (value: T) => void;\n\treject: (error: unknown) => void;\n}\n\nexport function promiseWithResolvers<T>(): PromiseWithResolvers<T> {\n\tlet resolver!: (value: T) => void;\n\tlet rejecter!: (error: unknown) => void;\n\n\tconst promise = new Promise<T>((resolve, reject) => {\n\t\tresolver = resolve;\n\t\trejecter = reject;\n\t});\n\n\treturn {\n\t\tpromise,\n\t\tresolve: resolver,\n\t\treject: rejecter,\n\t};\n}\n"],"mappings":";AASA,SAAgB,uBAAmD;CAClE,IAAI;CACJ,IAAI;CAOJ,OAAO;EACN,SAAA,IANmB,SAAY,SAAS,WAAW;GACnD,WAAW;GACX,WAAW;EACZ,CAGO;EACN,SAAS;EACT,QAAQ;CACT;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haneullabs/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared utilities for @haneullabs/* packages",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Haneul Labs <build@haneul-labs.com>",
|
|
@@ -22,21 +22,21 @@
|
|
|
22
22
|
],
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
|
|
25
|
+
"url": "git+https://github.com/GeunhwaJeong/haneul-ts-sdks.git"
|
|
26
26
|
},
|
|
27
27
|
"keywords": [
|
|
28
28
|
"utils"
|
|
29
29
|
],
|
|
30
30
|
"bugs": {
|
|
31
|
-
"url": "https://github.com/GeunhwaJeong/ts-sdks/issues"
|
|
31
|
+
"url": "https://github.com/GeunhwaJeong/haneul-ts-sdks/issues"
|
|
32
32
|
},
|
|
33
|
-
"homepage": "https://github.com/GeunhwaJeong/ts-sdks/tree/main/packages/utils#readme",
|
|
33
|
+
"homepage": "https://github.com/GeunhwaJeong/haneul-ts-sdks/tree/main/packages/utils#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"typescript": "^
|
|
36
|
-
"vitest": "^4.
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"vitest": "^4.1.8"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@scure/base": "^2.
|
|
39
|
+
"@scure/base": "^2.2.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|