@haneullabs/utils 0.1.0 → 0.3.2

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/b58.d.mts +6 -0
  3. package/dist/b58.d.mts.map +1 -0
  4. package/dist/{esm/b58.js → b58.mjs} +6 -5
  5. package/dist/b58.mjs.map +1 -0
  6. package/dist/b64.d.mts +6 -0
  7. package/dist/b64.d.mts.map +1 -0
  8. package/dist/b64.mjs +18 -0
  9. package/dist/b64.mjs.map +1 -0
  10. package/dist/chunk.d.mts +5 -0
  11. package/dist/chunk.d.mts.map +1 -0
  12. package/dist/chunk.mjs +10 -0
  13. package/dist/chunk.mjs.map +1 -0
  14. package/dist/dataloader.d.mts +139 -0
  15. package/dist/dataloader.d.mts.map +1 -0
  16. package/dist/dataloader.mjs +236 -0
  17. package/dist/dataloader.mjs.map +1 -0
  18. package/dist/hex.d.mts +6 -0
  19. package/dist/hex.d.mts.map +1 -0
  20. package/dist/hex.mjs +15 -0
  21. package/dist/hex.mjs.map +1 -0
  22. package/dist/index.d.mts +9 -0
  23. package/dist/index.mjs +9 -0
  24. package/dist/mitt.d.mts +32 -0
  25. package/dist/mitt.d.mts.map +1 -0
  26. package/dist/mitt.mjs +36 -0
  27. package/dist/mitt.mjs.map +1 -0
  28. package/dist/types.d.mts +6 -0
  29. package/dist/types.d.mts.map +1 -0
  30. package/dist/with-resolver.d.mts +10 -0
  31. package/dist/with-resolver.d.mts.map +1 -0
  32. package/dist/with-resolver.mjs +17 -0
  33. package/dist/with-resolver.mjs.map +1 -0
  34. package/package.json +18 -20
  35. package/src/dataloader.ts +8 -1
  36. package/src/index.ts +7 -0
  37. package/src/mitt.ts +118 -0
  38. package/src/types.ts +0 -1
  39. package/dist/cjs/b58.d.ts +0 -2
  40. package/dist/cjs/b58.js +0 -28
  41. package/dist/cjs/b58.js.map +0 -7
  42. package/dist/cjs/b64.d.ts +0 -2
  43. package/dist/cjs/b64.js +0 -40
  44. package/dist/cjs/b64.js.map +0 -7
  45. package/dist/cjs/chunk.d.ts +0 -1
  46. package/dist/cjs/chunk.js +0 -29
  47. package/dist/cjs/chunk.js.map +0 -7
  48. package/dist/cjs/dataloader.d.ts +0 -129
  49. package/dist/cjs/dataloader.js +0 -318
  50. package/dist/cjs/dataloader.js.map +0 -7
  51. package/dist/cjs/hex.d.ts +0 -2
  52. package/dist/cjs/hex.js +0 -37
  53. package/dist/cjs/hex.js.map +0 -7
  54. package/dist/cjs/index.d.ts +0 -7
  55. package/dist/cjs/index.js +0 -38
  56. package/dist/cjs/index.js.map +0 -7
  57. package/dist/cjs/package.json +0 -5
  58. package/dist/cjs/types.d.ts +0 -4
  59. package/dist/cjs/types.js +0 -17
  60. package/dist/cjs/types.js.map +0 -7
  61. package/dist/cjs/with-resolver.d.ts +0 -6
  62. package/dist/cjs/with-resolver.js +0 -37
  63. package/dist/cjs/with-resolver.js.map +0 -7
  64. package/dist/esm/b58.d.ts +0 -2
  65. package/dist/esm/b58.js.map +0 -7
  66. package/dist/esm/b64.d.ts +0 -2
  67. package/dist/esm/b64.js +0 -20
  68. package/dist/esm/b64.js.map +0 -7
  69. package/dist/esm/chunk.d.ts +0 -1
  70. package/dist/esm/chunk.js +0 -9
  71. package/dist/esm/chunk.js.map +0 -7
  72. package/dist/esm/dataloader.d.ts +0 -129
  73. package/dist/esm/dataloader.js +0 -298
  74. package/dist/esm/dataloader.js.map +0 -7
  75. package/dist/esm/hex.d.ts +0 -2
  76. package/dist/esm/hex.js +0 -17
  77. package/dist/esm/hex.js.map +0 -7
  78. package/dist/esm/index.d.ts +0 -7
  79. package/dist/esm/index.js +0 -18
  80. package/dist/esm/index.js.map +0 -7
  81. package/dist/esm/package.json +0 -5
  82. package/dist/esm/types.d.ts +0 -4
  83. package/dist/esm/types.js +0 -1
  84. package/dist/esm/types.js.map +0 -7
  85. package/dist/esm/with-resolver.d.ts +0 -6
  86. package/dist/esm/with-resolver.js +0 -17
  87. package/dist/esm/with-resolver.js.map +0 -7
  88. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  89. package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/mitt.mjs ADDED
@@ -0,0 +1,36 @@
1
+ //#region src/mitt.ts
2
+ /**
3
+ * Mitt: Tiny (~200b) functional event emitter / pubsub.
4
+ * @name mitt
5
+ * @returns {Mitt}
6
+ */
7
+ function mitt(all) {
8
+ all = all || /* @__PURE__ */ new Map();
9
+ return {
10
+ all,
11
+ on(type, handler) {
12
+ const handlers = all.get(type);
13
+ if (handlers) handlers.push(handler);
14
+ else all.set(type, [handler]);
15
+ },
16
+ off(type, handler) {
17
+ const handlers = all.get(type);
18
+ if (handlers) if (handler) handlers.splice(handlers.indexOf(handler) >>> 0, 1);
19
+ else all.set(type, []);
20
+ },
21
+ emit(type, evt) {
22
+ let handlers = all.get(type);
23
+ if (handlers) handlers.slice().map((handler) => {
24
+ handler(evt);
25
+ });
26
+ handlers = all.get("*");
27
+ if (handlers) handlers.slice().map((handler) => {
28
+ handler(type, evt);
29
+ });
30
+ }
31
+ };
32
+ }
33
+
34
+ //#endregion
35
+ export { mitt as default };
36
+ //# sourceMappingURL=mitt.mjs.map
@@ -0,0 +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;AAElB,OAAM,uBAAO,IAAI,KAAK;AAEtB,QAAO;EAIN;EAOA,GAA6B,MAAW,SAA8B;GACrE,MAAM,WAAmD,IAAK,IAAI,KAAK;AACvE,OAAI,SACH,UAAS,KAAK,QAAQ;OAEtB,KAAK,IAAI,MAAM,CAAC,QAAQ,CAA2C;;EAUrE,IAA8B,MAAW,SAA+B;GACvE,MAAM,WAAmD,IAAK,IAAI,KAAK;AACvE,OAAI,SACH,KAAI,QACH,UAAS,OAAO,SAAS,QAAQ,QAAQ,KAAK,GAAG,EAAE;OAEnD,KAAK,IAAI,MAAM,EAAE,CAAC;;EAcrB,KAA+B,MAAW,KAAmB;GAC5D,IAAI,WAAW,IAAK,IAAI,KAAK;AAC7B,OAAI,SACH,CAAC,SAAoD,OAAO,CAAC,KAAK,YAAY;AAC7E,YAAQ,IAAK;KACZ;AAGH,cAAW,IAAK,IAAI,IAAI;AACxB,OAAI,SACH,CAAC,SAA8C,OAAO,CAAC,KAAK,YAAY;AACvE,YAAQ,MAAM,IAAK;KAClB;;EAGJ"}
@@ -0,0 +1,6 @@
1
+ //#region src/types.d.ts
2
+ type Simplify<T> = { [K in keyof T]: T[K] } & {};
3
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
4
+ //#endregion
5
+ export { Simplify, UnionToIntersection };
6
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +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,CAAA,6BACzD,CAAA,sBAEE,CAAA"}
@@ -0,0 +1,10 @@
1
+ //#region src/with-resolver.d.ts
2
+ interface PromiseWithResolvers<T> {
3
+ promise: Promise<T>;
4
+ resolve: (value: T) => void;
5
+ reject: (error: unknown) => void;
6
+ }
7
+ declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
8
+ //#endregion
9
+ export { PromiseWithResolvers, promiseWithResolvers };
10
+ //# sourceMappingURL=with-resolver.d.mts.map
@@ -0,0 +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,GAAA,CAAA,GAA2B,oBAAA,CAAqB,CAAA"}
@@ -0,0 +1,17 @@
1
+ //#region src/with-resolver.ts
2
+ function promiseWithResolvers() {
3
+ let resolver;
4
+ let rejecter;
5
+ return {
6
+ promise: new Promise((resolve, reject) => {
7
+ resolver = resolve;
8
+ rejecter = reject;
9
+ }),
10
+ resolve: resolver,
11
+ reject: rejecter
12
+ };
13
+ }
14
+
15
+ //#endregion
16
+ export { promiseWithResolvers };
17
+ //# sourceMappingURL=with-resolver.mjs.map
@@ -0,0 +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;AAOJ,QAAO;EACN,SANe,IAAI,SAAY,SAAS,WAAW;AACnD,cAAW;AACX,cAAW;IACV;EAID,SAAS;EACT,QAAQ;EACR"}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@haneullabs/utils",
3
- "version": "0.1.0",
3
+ "version": "0.3.2",
4
4
  "description": "Shared utilities for @haneullabs/* packages",
5
5
  "license": "Apache-2.0",
6
- "author": "Haneul Labs <build@haneullabs.com>",
6
+ "author": "Haneul Labs <build@haneul-labs.com>",
7
7
  "sideEffects": false,
8
- "type": "commonjs",
9
- "main": "./dist/cjs/index.js",
10
- "module": "./dist/esm/index.js",
11
- "types": "./dist/cjs/index.d.ts",
8
+ "type": "module",
9
+ "main": "./dist/index.mjs",
10
+ "types": "./dist/index.d.mts",
12
11
  "exports": {
13
12
  ".": {
14
- "import": "./dist/esm/index.js",
15
- "require": "./dist/cjs/index.js"
13
+ "types": "./dist/index.d.mts",
14
+ "import": "./dist/index.mjs",
15
+ "default": "./dist/index.mjs"
16
16
  }
17
17
  },
18
18
  "files": [
@@ -22,32 +22,30 @@
22
22
  ],
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "git+https://github.com/GeunhwaJeong/haneul-ts-sdks.git"
25
+ "url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
26
26
  },
27
27
  "keywords": [
28
28
  "utils"
29
29
  ],
30
30
  "bugs": {
31
- "url": "https://github.com/GeunhwaJeong/haneul-ts-sdks/issues"
31
+ "url": "https://github.com/GeunhwaJeong/ts-sdks/issues"
32
32
  },
33
- "homepage": "https://github.com/GeunhwaJeong/haneul-ts-sdks/tree/main/packages/utils#readme",
33
+ "homepage": "https://github.com/GeunhwaJeong/ts-sdks/tree/main/packages/utils#readme",
34
34
  "devDependencies": {
35
35
  "typescript": "^5.9.3",
36
- "vitest": "^4.0.15",
37
- "@haneullabs/build-scripts": "0.1.0"
36
+ "vitest": "^4.0.17"
38
37
  },
39
38
  "dependencies": {
40
- "@scure/base": "^1.2.6"
39
+ "@scure/base": "^2.0.0"
41
40
  },
42
41
  "scripts": {
43
42
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
44
- "dev": "pnpm build --watch",
45
- "build": "build-package",
43
+ "build": "rm -rf dist && tsc --noEmit && tsdown",
46
44
  "prettier:check": "prettier -c --ignore-unknown .",
47
45
  "prettier:fix": "prettier -w --ignore-unknown .",
48
- "eslint:check": "eslint --max-warnings=0 .",
49
- "eslint:fix": "pnpm run eslint:check --fix",
50
- "lint": "pnpm run eslint:check && pnpm run prettier:check",
51
- "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix"
46
+ "oxlint:check": "oxlint .",
47
+ "oxlint:fix": "oxlint --fix",
48
+ "lint": "pnpm run oxlint:check && pnpm run prettier:check",
49
+ "lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
52
50
  }
53
51
  }
package/src/dataloader.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- /** Copied from https://github.com/graphql/dataloader/blob/a10773043d41a56bde4219c155fcf5633e6c9bcb/src/index.js */
4
+ /**
5
+ * DataLoader - A generic utility for batching and caching data fetches.
6
+ *
7
+ * Vendored from: https://github.com/graphql/dataloader
8
+ * Commit: a10773043d41a56bde4219c155fcf5633e6c9bcb
9
+ * License: MIT
10
+ * Copyright (c) GraphQL Contributors
11
+ */
5
12
 
6
13
  /**
7
14
  * A `DataLoader` creates a public API for loading data from a particular
package/src/index.ts CHANGED
@@ -8,3 +8,10 @@ export type { Simplify, UnionToIntersection } from './types.js';
8
8
  export { chunk } from './chunk.js';
9
9
  export { promiseWithResolvers, type PromiseWithResolvers } from './with-resolver.js';
10
10
  export { DataLoader } from './dataloader.js';
11
+ export {
12
+ default as mitt,
13
+ type Emitter,
14
+ type EventHandlerMap,
15
+ type Handler,
16
+ type WildcardHandler,
17
+ } from './mitt.js';
package/src/mitt.ts ADDED
@@ -0,0 +1,118 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Mitt - Tiny (~200b) functional event emitter / pubsub.
6
+ *
7
+ * Vendored from: https://github.com/developit/mitt
8
+ * License: MIT
9
+ * Copyright (c) 2021 Jason Miller
10
+ */
11
+
12
+ export type EventType = string | symbol;
13
+
14
+ // An event handler can take an optional event argument
15
+ // and should not return a value
16
+ export type Handler<T = unknown> = (event: T) => void;
17
+ export type WildcardHandler<T = Record<string, unknown>> = (
18
+ type: keyof T,
19
+ event: T[keyof T],
20
+ ) => void;
21
+
22
+ // An array of all currently registered event handlers for a type
23
+ export type EventHandlerList<T = unknown> = Array<Handler<T>>;
24
+ export type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>;
25
+
26
+ // A map of event types and their corresponding event handlers.
27
+ export type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<
28
+ keyof Events | '*',
29
+ EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>
30
+ >;
31
+
32
+ export interface Emitter<Events extends Record<EventType, unknown>> {
33
+ all: EventHandlerMap<Events>;
34
+
35
+ on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
36
+ on(type: '*', handler: WildcardHandler<Events>): void;
37
+
38
+ off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
39
+ off(type: '*', handler: WildcardHandler<Events>): void;
40
+
41
+ emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;
42
+ emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;
43
+ }
44
+
45
+ /**
46
+ * Mitt: Tiny (~200b) functional event emitter / pubsub.
47
+ * @name mitt
48
+ * @returns {Mitt}
49
+ */
50
+ export default function mitt<Events extends Record<EventType, unknown>>(
51
+ all?: EventHandlerMap<Events>,
52
+ ): Emitter<Events> {
53
+ type GenericEventHandler = Handler<Events[keyof Events]> | WildcardHandler<Events>;
54
+ all = all || new Map();
55
+
56
+ return {
57
+ /**
58
+ * A Map of event names to registered handler functions.
59
+ */
60
+ all,
61
+
62
+ /**
63
+ * Register an event handler for the given type.
64
+ * @param type Type of event to listen for, or `'*'` for all events
65
+ * @param handler Function to call in response to given event
66
+ */
67
+ on<Key extends keyof Events>(type: Key, handler: GenericEventHandler) {
68
+ const handlers: Array<GenericEventHandler> | undefined = all!.get(type);
69
+ if (handlers) {
70
+ handlers.push(handler);
71
+ } else {
72
+ all!.set(type, [handler] as EventHandlerList<Events[keyof Events]>);
73
+ }
74
+ },
75
+
76
+ /**
77
+ * Remove an event handler for the given type.
78
+ * If `handler` is omitted, all handlers of the given type are removed.
79
+ * @param type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)
80
+ * @param handler Handler function to remove
81
+ */
82
+ off<Key extends keyof Events>(type: Key, handler?: GenericEventHandler) {
83
+ const handlers: Array<GenericEventHandler> | undefined = all!.get(type);
84
+ if (handlers) {
85
+ if (handler) {
86
+ handlers.splice(handlers.indexOf(handler) >>> 0, 1);
87
+ } else {
88
+ all!.set(type, []);
89
+ }
90
+ }
91
+ },
92
+
93
+ /**
94
+ * Invoke all handlers for the given type.
95
+ * If present, `'*'` handlers are invoked after type-matched handlers.
96
+ *
97
+ * Note: Manually firing '*' handlers is not supported.
98
+ *
99
+ * @param type The event type to invoke
100
+ * @param evt Any value (object is recommended and powerful), passed to each handler
101
+ */
102
+ emit<Key extends keyof Events>(type: Key, evt?: Events[Key]) {
103
+ let handlers = all!.get(type);
104
+ if (handlers) {
105
+ (handlers as EventHandlerList<Events[keyof Events]>).slice().map((handler) => {
106
+ handler(evt!);
107
+ });
108
+ }
109
+
110
+ handlers = all!.get('*');
111
+ if (handlers) {
112
+ (handlers as WildCardEventHandlerList<Events>).slice().map((handler) => {
113
+ handler(type, evt!);
114
+ });
115
+ }
116
+ },
117
+ };
118
+ }
package/src/types.ts CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  export type Simplify<T> = {
5
5
  [K in keyof T]: T[K];
6
- // eslint-disable-next-line @typescript-eslint/ban-types
7
6
  } & {};
8
7
 
9
8
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
package/dist/cjs/b58.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const toBase58: (buffer: Uint8Array) => string;
2
- export declare const fromBase58: (str: string) => Uint8Array<ArrayBuffer>;
package/dist/cjs/b58.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var b58_exports = {};
20
- __export(b58_exports, {
21
- fromBase58: () => fromBase58,
22
- toBase58: () => toBase58
23
- });
24
- module.exports = __toCommonJS(b58_exports);
25
- var import_base = require("@scure/base");
26
- const toBase58 = (buffer) => import_base.base58.encode(buffer);
27
- const fromBase58 = (str) => import_base.base58.decode(str);
28
- //# sourceMappingURL=b58.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/b58.ts"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuB;AAEhB,MAAM,WAAW,CAAC,WAAuB,mBAAO,OAAO,MAAM;AAC7D,MAAM,aAAa,CAAC,QAAgB,mBAAO,OAAO,GAAG;",
6
- "names": []
7
- }
package/dist/cjs/b64.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function fromBase64(base64String: string): Uint8Array<ArrayBuffer>;
2
- export declare function toBase64(bytes: Uint8Array): string;
package/dist/cjs/b64.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var b64_exports = {};
20
- __export(b64_exports, {
21
- fromBase64: () => fromBase64,
22
- toBase64: () => toBase64
23
- });
24
- module.exports = __toCommonJS(b64_exports);
25
- function fromBase64(base64String) {
26
- return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
27
- }
28
- const CHUNK_SIZE = 8192;
29
- function toBase64(bytes) {
30
- if (bytes.length < CHUNK_SIZE) {
31
- return btoa(String.fromCharCode(...bytes));
32
- }
33
- let output = "";
34
- for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
35
- const chunk = bytes.slice(i, i + CHUNK_SIZE);
36
- output += String.fromCharCode(...chunk);
37
- }
38
- return btoa(output);
39
- }
40
- //# sourceMappingURL=b64.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/b64.ts"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,WAAW,cAA+C;AACzE,SAAO,WAAW,KAAK,KAAK,YAAY,GAAG,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC;AACxE;AAEA,MAAM,aAAa;AACZ,SAAS,SAAS,OAA2B;AAEnD,MAAI,MAAM,SAAS,YAAY;AAC9B,WAAO,KAAK,OAAO,aAAa,GAAG,KAAK,CAAC;AAAA,EAC1C;AAEA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,YAAY;AAClD,UAAM,QAAQ,MAAM,MAAM,GAAG,IAAI,UAAU;AAC3C,cAAU,OAAO,aAAa,GAAG,KAAK;AAAA,EACvC;AAEA,SAAO,KAAK,MAAM;AACnB;",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- export declare function chunk<T>(array: readonly T[], size: number): T[][];
package/dist/cjs/chunk.js DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_exports = {};
20
- __export(chunk_exports, {
21
- chunk: () => chunk
22
- });
23
- module.exports = __toCommonJS(chunk_exports);
24
- function chunk(array, size) {
25
- return Array.from({ length: Math.ceil(array.length / size) }, (_, i) => {
26
- return array.slice(i * size, (i + 1) * size);
27
- });
28
- }
29
- //# sourceMappingURL=chunk.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/chunk.ts"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,MAAS,OAAqB,MAAqB;AAClE,SAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,KAAK,MAAM,SAAS,IAAI,EAAE,GAAG,CAAC,GAAG,MAAM;AACvE,WAAO,MAAM,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI;AAAA,EAC5C,CAAC;AACF;",
6
- "names": []
7
- }
@@ -1,129 +0,0 @@
1
- /** Copied from https://github.com/graphql/dataloader/blob/a10773043d41a56bde4219c155fcf5633e6c9bcb/src/index.js */
2
- /**
3
- * A `DataLoader` creates a public API for loading data from a particular
4
- * data back-end with unique keys such as the `id` column of a SQL table or
5
- * document name in a MongoDB database, given a batch loading function.
6
- *
7
- * Each `DataLoader` instance contains a unique memoized cache. Use caution when
8
- * used in long-lived applications or those which serve many users with
9
- * different access permissions and consider creating a new instance per
10
- * web request.
11
- */
12
- export declare class DataLoader<K, V, C = K> {
13
- constructor(batchLoadFn: DataLoader.BatchLoadFn<K, V>, options?: DataLoader.Options<K, V, C>);
14
- _batchLoadFn: DataLoader.BatchLoadFn<K, V>;
15
- _maxBatchSize: number;
16
- _batchScheduleFn: (cb: () => void) => void;
17
- _cacheKeyFn: (key: K) => C;
18
- _cacheMap: DataLoader.CacheMap<C, Promise<V>> | null;
19
- _batch: Batch<K, V> | null;
20
- /**
21
- * Loads a key, returning a `Promise` for the value represented by that key.
22
- */
23
- load(key: K): Promise<V>;
24
- /**
25
- * Loads multiple keys, promising an array of values:
26
- *
27
- * var [ a, b ] = await myLoader.loadMany([ 'a', 'b' ]);
28
- *
29
- * This is similar to the more verbose:
30
- *
31
- * var [ a, b ] = await Promise.all([
32
- * myLoader.load('a'),
33
- * myLoader.load('b')
34
- * ]);
35
- *
36
- * However it is different in the case where any load fails. Where
37
- * Promise.all() would reject, loadMany() always resolves, however each result
38
- * is either a value or an Error instance.
39
- *
40
- * var [ a, b, c ] = await myLoader.loadMany([ 'a', 'b', 'badkey' ]);
41
- * // c instanceof Error
42
- *
43
- */
44
- loadMany(keys: ReadonlyArray<K>): Promise<Array<V | Error>>;
45
- /**
46
- * Clears the value at `key` from the cache, if it exists. Returns itself for
47
- * method chaining.
48
- */
49
- clear(key: K): this;
50
- /**
51
- * Clears the entire cache. To be used when some event results in unknown
52
- * invalidations across this particular `DataLoader`. Returns itself for
53
- * method chaining.
54
- */
55
- clearAll(): this;
56
- /**
57
- * Adds the provided key and value to the cache. If the key already
58
- * exists, no change is made. Returns itself for method chaining.
59
- *
60
- * To prime the cache with an error at a key, provide an Error instance.
61
- */
62
- prime(key: K, value: V | Promise<V> | Error): this;
63
- /**
64
- * The name given to this `DataLoader` instance. Useful for APM tools.
65
- *
66
- * Is `null` if not set in the constructor.
67
- */
68
- name: string | null;
69
- }
70
- type Batch<K, V> = {
71
- hasDispatched: boolean;
72
- keys: Array<K>;
73
- callbacks: Array<{
74
- resolve: (value: V) => void;
75
- reject: (error: Error) => void;
76
- }>;
77
- cacheHits?: Array<() => void>;
78
- };
79
- export declare namespace DataLoader {
80
- type CacheMap<K, V> = {
81
- get(key: K): V | void;
82
- set(key: K, value: V): any;
83
- delete(key: K): any;
84
- clear(): any;
85
- };
86
- type BatchLoadFn<K, V> = (keys: ReadonlyArray<K>) => PromiseLike<ArrayLike<V | Error>>;
87
- type Options<K, V, C = K> = {
88
- /**
89
- * Default `true`. Set to `false` to disable batching, invoking
90
- * `batchLoadFn` with a single load key. This is equivalent to setting
91
- * `maxBatchSize` to `1`.
92
- */
93
- batch?: boolean;
94
- /**
95
- * Default `Infinity`. Limits the number of items that get passed in to the
96
- * `batchLoadFn`. May be set to `1` to disable batching.
97
- */
98
- maxBatchSize?: number;
99
- /**
100
- * Default see https://github.com/graphql/dataloader#batch-scheduling.
101
- * A function to schedule the later execution of a batch. The function is
102
- * expected to call the provided callback in the immediate future.
103
- */
104
- batchScheduleFn?: (callback: () => void) => void;
105
- /**
106
- * Default `true`. Set to `false` to disable memoization caching, creating a
107
- * new Promise and new key in the `batchLoadFn` for every load of the same
108
- * key. This is equivalent to setting `cacheMap` to `null`.
109
- */
110
- cache?: boolean;
111
- /**
112
- * Default `key => key`. Produces cache key for a given load key. Useful
113
- * when keys are objects and two objects should be considered equivalent.
114
- */
115
- cacheKeyFn?: (key: K) => C;
116
- /**
117
- * Default `new Map()`. Instance of `Map` (or an object with a similar API)
118
- * to be used as cache. May be set to `null` to disable caching.
119
- */
120
- cacheMap?: CacheMap<C, Promise<V>> | null;
121
- /**
122
- * The name given to this `DataLoader` instance. Useful for APM tools.
123
- *
124
- * Is `null` if not set in the constructor.
125
- */
126
- name?: string | null;
127
- };
128
- }
129
- export {};