@metamask-previews/snap-networks-utils 1.0.0-preview-e79d811 → 1.0.0-preview-8ff90d2f

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 CHANGED
@@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  ### Added
11
11
 
12
12
  - Add `InFlightCoalescer`, exported from a new `./dedupe` entry point, which coalesces concurrent async operations by key so callers share one in-flight run ([#149](https://github.com/MetaMask/internal-snaps/pull/149))
13
- - Add shared async batching utilities. ([#211](https://github.com/MetaMask/internal-snaps/pull/211))
14
13
  - Add origin permission helpers ([#193](https://github.com/MetaMask/internal-snaps/pull/193))
15
14
  - `createOriginPermissions` for building origin-to-method maps
16
15
  - `validateOrigin` for checking an origin against a permission map
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateOrigin = exports.DEFAULT_METAMASK_ORIGIN = exports.DEFAULT_DEV_ORIGINS = exports.DEFAULT_PROD_ORIGINS = exports.createOriginPermissions = exports.LogLevel = exports.Logger = exports.chunks = exports.batchesAllWithChunks = exports.batchesAllSettledWithChunks = exports.batchesAllSettled = exports.batchesAll = exports.UrlStruct = exports.sanitizeUri = exports.sanitizeControlCharacters = exports.buildUrl = exports.safeMerge = exports.RemoteFeatureFlagsProvider = exports.REMOTE_FEATURE_FLAGS_PROVIDER_NAME = exports.AssetsProvider = exports.ASSETS_PROVIDER_NAME = void 0;
3
+ exports.validateOrigin = exports.DEFAULT_METAMASK_ORIGIN = exports.DEFAULT_DEV_ORIGINS = exports.DEFAULT_PROD_ORIGINS = exports.createOriginPermissions = exports.LogLevel = exports.Logger = exports.UrlStruct = exports.sanitizeUri = exports.sanitizeControlCharacters = exports.buildUrl = exports.safeMerge = exports.RemoteFeatureFlagsProvider = exports.REMOTE_FEATURE_FLAGS_PROVIDER_NAME = exports.AssetsProvider = exports.ASSETS_PROVIDER_NAME = void 0;
4
4
  var AssetsProvider_1 = require("./providers/assets/AssetsProvider.cjs");
5
5
  Object.defineProperty(exports, "ASSETS_PROVIDER_NAME", { enumerable: true, get: function () { return AssetsProvider_1.ASSETS_PROVIDER_NAME; } });
6
6
  Object.defineProperty(exports, "AssetsProvider", { enumerable: true, get: function () { return AssetsProvider_1.AssetsProvider; } });
@@ -16,12 +16,6 @@ Object.defineProperty(exports, "sanitizeControlCharacters", { enumerable: true,
16
16
  Object.defineProperty(exports, "sanitizeUri", { enumerable: true, get: function () { return sanitize_1.sanitizeUri; } });
17
17
  var urlStruct_1 = require("./urlStruct/urlStruct.cjs");
18
18
  Object.defineProperty(exports, "UrlStruct", { enumerable: true, get: function () { return urlStruct_1.UrlStruct; } });
19
- var async_1 = require("./async.cjs");
20
- Object.defineProperty(exports, "batchesAll", { enumerable: true, get: function () { return async_1.batchesAll; } });
21
- Object.defineProperty(exports, "batchesAllSettled", { enumerable: true, get: function () { return async_1.batchesAllSettled; } });
22
- Object.defineProperty(exports, "batchesAllSettledWithChunks", { enumerable: true, get: function () { return async_1.batchesAllSettledWithChunks; } });
23
- Object.defineProperty(exports, "batchesAllWithChunks", { enumerable: true, get: function () { return async_1.batchesAllWithChunks; } });
24
- Object.defineProperty(exports, "chunks", { enumerable: true, get: function () { return async_1.chunks; } });
25
19
  var logger_1 = require("./logger/index.cjs");
26
20
  Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
27
21
  Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAI2C;AAHzC,sHAAA,oBAAoB,OAAA;AACpB,gHAAA,cAAc,OAAA;AAGhB,8GAIqE;AAHnE,gJAAA,kCAAkC,OAAA;AAClC,wIAAA,0BAA0B,OAAA;AAG5B,uDAAkD;AAAzC,sGAAA,SAAS,OAAA;AAClB,oDAA+C;AAAtC,oGAAA,QAAQ,OAAA;AAEjB,2CAAoE;AAA3D,qHAAA,yBAAyB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAC/C,uDAAkD;AAAzC,sGAAA,SAAS,OAAA;AAClB,qCAMiB;AALf,mGAAA,UAAU,OAAA;AACV,0GAAA,iBAAiB,OAAA;AACjB,oHAAA,2BAA2B,OAAA;AAC3B,6GAAA,oBAAoB,OAAA;AACpB,+FAAA,MAAM,OAAA;AAER,6CAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAQzB,2FAKqD;AAJnD,kIAAA,uBAAuB,OAAA;AACvB,+HAAA,oBAAoB,OAAA;AACpB,8HAAA,mBAAmB,OAAA;AACnB,kIAAA,uBAAuB,OAAA;AAGzB,yEAAoE;AAA3D,gHAAA,cAAc,OAAA","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './safeMerge/safeMerge';\nexport { buildUrl } from './buildUrl/buildUrl';\nexport type { BuildUrlParams } from './buildUrl/buildUrl';\nexport { sanitizeControlCharacters, sanitizeUri } from './sanitize';\nexport { UrlStruct } from './urlStruct/urlStruct';\nexport {\n batchesAll,\n batchesAllSettled,\n batchesAllSettledWithChunks,\n batchesAllWithChunks,\n chunks,\n} from './async';\nexport { Logger, LogLevel } from './logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './logger';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './originPermissions/createOriginPermissions';\nexport { validateOrigin } from './originPermissions/validateOrigin';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAI2C;AAHzC,sHAAA,oBAAoB,OAAA;AACpB,gHAAA,cAAc,OAAA;AAGhB,8GAIqE;AAHnE,gJAAA,kCAAkC,OAAA;AAClC,wIAAA,0BAA0B,OAAA;AAG5B,uDAAkD;AAAzC,sGAAA,SAAS,OAAA;AAClB,oDAA+C;AAAtC,oGAAA,QAAQ,OAAA;AAEjB,2CAAoE;AAA3D,qHAAA,yBAAyB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAC/C,uDAAkD;AAAzC,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAQzB,2FAKqD;AAJnD,kIAAA,uBAAuB,OAAA;AACvB,+HAAA,oBAAoB,OAAA;AACpB,8HAAA,mBAAmB,OAAA;AACnB,kIAAA,uBAAuB,OAAA;AAGzB,yEAAoE;AAA3D,gHAAA,cAAc,OAAA","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './safeMerge/safeMerge';\nexport { buildUrl } from './buildUrl/buildUrl';\nexport type { BuildUrlParams } from './buildUrl/buildUrl';\nexport { sanitizeControlCharacters, sanitizeUri } from './sanitize';\nexport { UrlStruct } from './urlStruct/urlStruct';\nexport { Logger, LogLevel } from './logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './logger';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './originPermissions/createOriginPermissions';\nexport { validateOrigin } from './originPermissions/validateOrigin';\n"]}
package/dist/index.d.cts CHANGED
@@ -5,7 +5,6 @@ export { buildUrl } from "./buildUrl/buildUrl.cjs";
5
5
  export type { BuildUrlParams } from "./buildUrl/buildUrl.cjs";
6
6
  export { sanitizeControlCharacters, sanitizeUri } from "./sanitize.cjs";
7
7
  export { UrlStruct } from "./urlStruct/urlStruct.cjs";
8
- export { batchesAll, batchesAllSettled, batchesAllSettledWithChunks, batchesAllWithChunks, chunks, } from "./async.cjs";
9
8
  export { Logger, LogLevel } from "./logger/index.cjs";
10
9
  export type { LoggerOptions, LoggerMethod, LogMethod, LogMethodDecorator, LoggerDecorators, } from "./logger/index.cjs";
11
10
  export { createOriginPermissions, DEFAULT_PROD_ORIGINS, DEFAULT_DEV_ORIGINS, DEFAULT_METAMASK_ORIGIN, } from "./originPermissions/createOriginPermissions.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,uBAAuB,GAC7B,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,KAAK,mCAAmC,GACzC,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,QAAQ,EAAE,gCAA4B;AAC/C,YAAY,EAAE,cAAc,EAAE,gCAA4B;AAC1D,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,uBAAmB;AACpE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,GACP,oBAAgB;AACjB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,2BAAiB;AAC5C,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,2BAAiB;AAClB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,wDAAoD;AACrD,YAAY,EAAE,6BAA6B,EAAE,wDAAoD;AACjG,OAAO,EAAE,cAAc,EAAE,+CAA2C"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,uBAAuB,GAC7B,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,KAAK,mCAAmC,GACzC,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,QAAQ,EAAE,gCAA4B;AAC/C,YAAY,EAAE,cAAc,EAAE,gCAA4B;AAC1D,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,uBAAmB;AACpE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,2BAAiB;AAC5C,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,2BAAiB;AAClB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,wDAAoD;AACrD,YAAY,EAAE,6BAA6B,EAAE,wDAAoD;AACjG,OAAO,EAAE,cAAc,EAAE,+CAA2C"}
package/dist/index.d.mts CHANGED
@@ -5,7 +5,6 @@ export { buildUrl } from "./buildUrl/buildUrl.mjs";
5
5
  export type { BuildUrlParams } from "./buildUrl/buildUrl.mjs";
6
6
  export { sanitizeControlCharacters, sanitizeUri } from "./sanitize.mjs";
7
7
  export { UrlStruct } from "./urlStruct/urlStruct.mjs";
8
- export { batchesAll, batchesAllSettled, batchesAllSettledWithChunks, batchesAllWithChunks, chunks, } from "./async.mjs";
9
8
  export { Logger, LogLevel } from "./logger/index.mjs";
10
9
  export type { LoggerOptions, LoggerMethod, LogMethod, LogMethodDecorator, LoggerDecorators, } from "./logger/index.mjs";
11
10
  export { createOriginPermissions, DEFAULT_PROD_ORIGINS, DEFAULT_DEV_ORIGINS, DEFAULT_METAMASK_ORIGIN, } from "./originPermissions/createOriginPermissions.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,uBAAuB,GAC7B,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,KAAK,mCAAmC,GACzC,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,QAAQ,EAAE,gCAA4B;AAC/C,YAAY,EAAE,cAAc,EAAE,gCAA4B;AAC1D,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,uBAAmB;AACpE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,GACP,oBAAgB;AACjB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,2BAAiB;AAC5C,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,2BAAiB;AAClB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,wDAAoD;AACrD,YAAY,EAAE,6BAA6B,EAAE,wDAAoD;AACjG,OAAO,EAAE,cAAc,EAAE,+CAA2C"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,KAAK,uBAAuB,GAC7B,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,KAAK,mCAAmC,GACzC,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,QAAQ,EAAE,gCAA4B;AAC/C,YAAY,EAAE,cAAc,EAAE,gCAA4B;AAC1D,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,uBAAmB;AACpE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,2BAAiB;AAC5C,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,2BAAiB;AAClB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,GACxB,wDAAoD;AACrD,YAAY,EAAE,6BAA6B,EAAE,wDAAoD;AACjG,OAAO,EAAE,cAAc,EAAE,+CAA2C"}
package/dist/index.mjs CHANGED
@@ -4,7 +4,6 @@ export { safeMerge } from "./safeMerge/safeMerge.mjs";
4
4
  export { buildUrl } from "./buildUrl/buildUrl.mjs";
5
5
  export { sanitizeControlCharacters, sanitizeUri } from "./sanitize.mjs";
6
6
  export { UrlStruct } from "./urlStruct/urlStruct.mjs";
7
- export { batchesAll, batchesAllSettled, batchesAllSettledWithChunks, batchesAllWithChunks, chunks } from "./async.mjs";
8
7
  export { Logger, LogLevel } from "./logger/index.mjs";
9
8
  export { createOriginPermissions, DEFAULT_PROD_ORIGINS, DEFAULT_DEV_ORIGINS, DEFAULT_METAMASK_ORIGIN } from "./originPermissions/createOriginPermissions.mjs";
10
9
  export { validateOrigin } from "./originPermissions/validateOrigin.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EAEf,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAE3B,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,QAAQ,EAAE,gCAA4B;AAE/C,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,uBAAmB;AACpE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,EACP,oBAAgB;AACjB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,2BAAiB;AAQ5C,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,wDAAoD;AAErD,OAAO,EAAE,cAAc,EAAE,+CAA2C","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './safeMerge/safeMerge';\nexport { buildUrl } from './buildUrl/buildUrl';\nexport type { BuildUrlParams } from './buildUrl/buildUrl';\nexport { sanitizeControlCharacters, sanitizeUri } from './sanitize';\nexport { UrlStruct } from './urlStruct/urlStruct';\nexport {\n batchesAll,\n batchesAllSettled,\n batchesAllSettledWithChunks,\n batchesAllWithChunks,\n chunks,\n} from './async';\nexport { Logger, LogLevel } from './logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './logger';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './originPermissions/createOriginPermissions';\nexport { validateOrigin } from './originPermissions/validateOrigin';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EAEf,8CAA0C;AAC3C,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAE3B,wEAAoE;AACrE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,QAAQ,EAAE,gCAA4B;AAE/C,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,uBAAmB;AACpE,OAAO,EAAE,SAAS,EAAE,kCAA8B;AAClD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,2BAAiB;AAQ5C,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,wDAAoD;AAErD,OAAO,EAAE,cAAc,EAAE,+CAA2C","sourcesContent":["export {\n ASSETS_PROVIDER_NAME,\n AssetsProvider,\n type AssetsProviderMessenger,\n} from './providers/assets/AssetsProvider';\nexport {\n REMOTE_FEATURE_FLAGS_PROVIDER_NAME,\n RemoteFeatureFlagsProvider,\n type RemoteFeatureFlagsProviderMessenger,\n} from './providers/remote-feature-flags/RemoteFeatureFlagsProvider';\nexport { safeMerge } from './safeMerge/safeMerge';\nexport { buildUrl } from './buildUrl/buildUrl';\nexport type { BuildUrlParams } from './buildUrl/buildUrl';\nexport { sanitizeControlCharacters, sanitizeUri } from './sanitize';\nexport { UrlStruct } from './urlStruct/urlStruct';\nexport { Logger, LogLevel } from './logger';\nexport type {\n LoggerOptions,\n LoggerMethod,\n LogMethod,\n LogMethodDecorator,\n LoggerDecorators,\n} from './logger';\nexport {\n createOriginPermissions,\n DEFAULT_PROD_ORIGINS,\n DEFAULT_DEV_ORIGINS,\n DEFAULT_METAMASK_ORIGIN,\n} from './originPermissions/createOriginPermissions';\nexport type { CreateOriginPermissionsParams } from './originPermissions/createOriginPermissions';\nexport { validateOrigin } from './originPermissions/validateOrigin';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/snap-networks-utils",
3
- "version": "1.0.0-preview-e79d811",
3
+ "version": "1.0.0-preview-8ff90d2f",
4
4
  "description": "Shared utilities for MetaMask network snaps",
5
5
  "keywords": [
6
6
  "Ethereum",
package/dist/async.cjs DELETED
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chunks = chunks;
4
- exports.batchesAll = batchesAll;
5
- exports.batchesAllSettled = batchesAllSettled;
6
- exports.batchesAllSettledWithChunks = batchesAllSettledWithChunks;
7
- exports.batchesAllWithChunks = batchesAllWithChunks;
8
- /**
9
- * Splits items into chunks of a given size.
10
- *
11
- * @param items - Input items; order is preserved in the returned chunks.
12
- * @param chunkSize - Size of each chunk (must be ≥ 1).
13
- * @returns An array of chunks, each containing `chunkSize` items.
14
- */
15
- function chunks(items, chunkSize) {
16
- if (chunkSize < 1) {
17
- throw new RangeError('chunkSize must be at least 1');
18
- }
19
- const itemsChunks = [];
20
- for (let index = 0; index < items.length; index += chunkSize) {
21
- itemsChunks.push(items.slice(index, index + chunkSize));
22
- }
23
- return itemsChunks;
24
- }
25
- /**
26
- * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
27
- * The next wave starts only after the current wave completes; any rejection fails the whole call.
28
- *
29
- * @param items - Input items; order is preserved in the returned results.
30
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
31
- * @param mapper - Async function for each item; receives the global index in `items`.
32
- * @returns One result per item, in the same order as `items`.
33
- */
34
- async function batchesAll(items, batchSize, mapper) {
35
- if (batchSize < 1) {
36
- throw new RangeError('batchSize must be at least 1');
37
- }
38
- const results = [];
39
- for (let index = 0; index < items.length; index += batchSize) {
40
- const batch = items.slice(index, index + batchSize);
41
- const batchResults = await Promise.all(batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)));
42
- results.push(...batchResults);
43
- }
44
- return results;
45
- }
46
- /**
47
- * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
48
- * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
49
- *
50
- * @param items - Input items; order is preserved in the returned results.
51
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
52
- * @param mapper - Async function for each item; receives the global index in `items`.
53
- * @returns One settled result per item, in the same order as `items`.
54
- */
55
- async function batchesAllSettled(items, batchSize, mapper) {
56
- if (batchSize < 1) {
57
- throw new RangeError('batchSize must be at least 1');
58
- }
59
- const results = [];
60
- for (let index = 0; index < items.length; index += batchSize) {
61
- const batch = items.slice(index, index + batchSize);
62
- const settled = await Promise.allSettled(batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)));
63
- results.push(...settled);
64
- }
65
- return results;
66
- }
67
- /**
68
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
69
- * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
70
- *
71
- * @param items - Flat input items.
72
- * @param chunkSize - Items per chunk (must be ≥ 1).
73
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
74
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
75
- * @returns One settled result per chunk.
76
- */
77
- async function batchesAllSettledWithChunks(items, chunkSize, batchSize, mapper) {
78
- const itemChunks = chunks(items, chunkSize);
79
- return batchesAllSettled(itemChunks, batchSize, async (chunk, chunkIndex) => mapper(chunk, chunkIndex));
80
- }
81
- /**
82
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
83
- * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
84
- *
85
- * @param items - Flat input items.
86
- * @param chunkSize - Items per chunk (must be ≥ 1).
87
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
88
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
89
- * @returns One result per chunk.
90
- */
91
- async function batchesAllWithChunks(items, chunkSize, batchSize, mapper) {
92
- const itemChunks = chunks(items, chunkSize);
93
- return batchesAll(itemChunks, batchSize, async (chunk, chunkIndex) => mapper(chunk, chunkIndex));
94
- }
95
- //# sourceMappingURL=async.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async.cjs","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Splits items into chunks of a given size.\n *\n * @param items - Input items; order is preserved in the returned chunks.\n * @param chunkSize - Size of each chunk (must be ≥ 1).\n * @returns An array of chunks, each containing `chunkSize` items.\n */\nexport function chunks<TItem>(\n items: readonly TItem[],\n chunkSize: number,\n): TItem[][] {\n if (chunkSize < 1) {\n throw new RangeError('chunkSize must be at least 1');\n }\n\n const itemsChunks: TItem[][] = [];\n for (let index = 0; index < items.length; index += chunkSize) {\n itemsChunks.push(items.slice(index, index + chunkSize));\n }\n return itemsChunks;\n}\n\n/**\n * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.\n * The next wave starts only after the current wave completes; any rejection fails the whole call.\n *\n * @param items - Input items; order is preserved in the returned results.\n * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).\n * @param mapper - Async function for each item; receives the global index in `items`.\n * @returns One result per item, in the same order as `items`.\n */\nexport async function batchesAll<TItem, TResult>(\n items: readonly TItem[],\n batchSize: number,\n mapper: (item: TItem, index: number) => Promise<TResult>,\n): Promise<TResult[]> {\n if (batchSize < 1) {\n throw new RangeError('batchSize must be at least 1');\n }\n\n const results: TResult[] = [];\n\n for (let index = 0; index < items.length; index += batchSize) {\n const batch = items.slice(index, index + batchSize);\n const batchResults = await Promise.all(\n batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)),\n );\n results.push(...batchResults);\n }\n\n return results;\n}\n\n/**\n * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.\n * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.\n *\n * @param items - Input items; order is preserved in the returned results.\n * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).\n * @param mapper - Async function for each item; receives the global index in `items`.\n * @returns One settled result per item, in the same order as `items`.\n */\nexport async function batchesAllSettled<TItem, TResult>(\n items: readonly TItem[],\n batchSize: number,\n mapper: (item: TItem, index: number) => Promise<TResult>,\n): Promise<PromiseSettledResult<TResult>[]> {\n if (batchSize < 1) {\n throw new RangeError('batchSize must be at least 1');\n }\n\n const results: PromiseSettledResult<TResult>[] = [];\n\n for (let index = 0; index < items.length; index += batchSize) {\n const batch = items.slice(index, index + batchSize);\n const settled = await Promise.allSettled(\n batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)),\n );\n results.push(...settled);\n }\n\n return results;\n}\n\n/**\n * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.\n * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).\n *\n * @param items - Flat input items.\n * @param chunkSize - Items per chunk (must be ≥ 1).\n * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).\n * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).\n * @returns One settled result per chunk.\n */\nexport async function batchesAllSettledWithChunks<TItem, TResult>(\n items: readonly TItem[],\n chunkSize: number,\n batchSize: number,\n mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>,\n): Promise<PromiseSettledResult<TResult>[]> {\n const itemChunks = chunks(items, chunkSize);\n return batchesAllSettled(itemChunks, batchSize, async (chunk, chunkIndex) =>\n mapper(chunk, chunkIndex),\n );\n}\n\n/**\n * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.\n * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).\n *\n * @param items - Flat input items.\n * @param chunkSize - Items per chunk (must be ≥ 1).\n * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).\n * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).\n * @returns One result per chunk.\n */\nexport async function batchesAllWithChunks<TItem, TResult>(\n items: readonly TItem[],\n chunkSize: number,\n batchSize: number,\n mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>,\n): Promise<TResult[]> {\n const itemChunks = chunks(items, chunkSize);\n return batchesAll(itemChunks, batchSize, async (chunk, chunkIndex) =>\n mapper(chunk, chunkIndex),\n );\n}\n"]}
package/dist/async.d.cts DELETED
@@ -1,51 +0,0 @@
1
- /**
2
- * Splits items into chunks of a given size.
3
- *
4
- * @param items - Input items; order is preserved in the returned chunks.
5
- * @param chunkSize - Size of each chunk (must be ≥ 1).
6
- * @returns An array of chunks, each containing `chunkSize` items.
7
- */
8
- export declare function chunks<TItem>(items: readonly TItem[], chunkSize: number): TItem[][];
9
- /**
10
- * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
11
- * The next wave starts only after the current wave completes; any rejection fails the whole call.
12
- *
13
- * @param items - Input items; order is preserved in the returned results.
14
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
15
- * @param mapper - Async function for each item; receives the global index in `items`.
16
- * @returns One result per item, in the same order as `items`.
17
- */
18
- export declare function batchesAll<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<TResult[]>;
19
- /**
20
- * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
21
- * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
22
- *
23
- * @param items - Input items; order is preserved in the returned results.
24
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
25
- * @param mapper - Async function for each item; receives the global index in `items`.
26
- * @returns One settled result per item, in the same order as `items`.
27
- */
28
- export declare function batchesAllSettled<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
29
- /**
30
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
31
- * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
32
- *
33
- * @param items - Flat input items.
34
- * @param chunkSize - Items per chunk (must be ≥ 1).
35
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
36
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
37
- * @returns One settled result per chunk.
38
- */
39
- export declare function batchesAllSettledWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
40
- /**
41
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
42
- * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
43
- *
44
- * @param items - Flat input items.
45
- * @param chunkSize - Items per chunk (must be ≥ 1).
46
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
47
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
48
- * @returns One result per chunk.
49
- */
50
- export declare function batchesAllWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<TResult[]>;
51
- //# sourceMappingURL=async.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async.d.cts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAC1B,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,EAAE,CAUX;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,EAC7C,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,OAAO,EAAE,CAAC,CAgBpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EACpD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAgB1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAC9D,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAK1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EACvD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,OAAO,EAAE,CAAC,CAKpB"}
package/dist/async.d.mts DELETED
@@ -1,51 +0,0 @@
1
- /**
2
- * Splits items into chunks of a given size.
3
- *
4
- * @param items - Input items; order is preserved in the returned chunks.
5
- * @param chunkSize - Size of each chunk (must be ≥ 1).
6
- * @returns An array of chunks, each containing `chunkSize` items.
7
- */
8
- export declare function chunks<TItem>(items: readonly TItem[], chunkSize: number): TItem[][];
9
- /**
10
- * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
11
- * The next wave starts only after the current wave completes; any rejection fails the whole call.
12
- *
13
- * @param items - Input items; order is preserved in the returned results.
14
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
15
- * @param mapper - Async function for each item; receives the global index in `items`.
16
- * @returns One result per item, in the same order as `items`.
17
- */
18
- export declare function batchesAll<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<TResult[]>;
19
- /**
20
- * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
21
- * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
22
- *
23
- * @param items - Input items; order is preserved in the returned results.
24
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
25
- * @param mapper - Async function for each item; receives the global index in `items`.
26
- * @returns One settled result per item, in the same order as `items`.
27
- */
28
- export declare function batchesAllSettled<TItem, TResult>(items: readonly TItem[], batchSize: number, mapper: (item: TItem, index: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
29
- /**
30
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
31
- * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
32
- *
33
- * @param items - Flat input items.
34
- * @param chunkSize - Items per chunk (must be ≥ 1).
35
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
36
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
37
- * @returns One settled result per chunk.
38
- */
39
- export declare function batchesAllSettledWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<PromiseSettledResult<TResult>[]>;
40
- /**
41
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
42
- * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
43
- *
44
- * @param items - Flat input items.
45
- * @param chunkSize - Items per chunk (must be ≥ 1).
46
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
47
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
48
- * @returns One result per chunk.
49
- */
50
- export declare function batchesAllWithChunks<TItem, TResult>(items: readonly TItem[], chunkSize: number, batchSize: number, mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>): Promise<TResult[]>;
51
- //# sourceMappingURL=async.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async.d.mts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAC1B,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,EAAE,CAUX;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,EAC7C,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,OAAO,EAAE,CAAC,CAgBpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EACpD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAgB1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAC9D,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAK1C;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EACvD,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,OAAO,EAAE,CAAC,CAKpB"}
package/dist/async.mjs DELETED
@@ -1,88 +0,0 @@
1
- /**
2
- * Splits items into chunks of a given size.
3
- *
4
- * @param items - Input items; order is preserved in the returned chunks.
5
- * @param chunkSize - Size of each chunk (must be ≥ 1).
6
- * @returns An array of chunks, each containing `chunkSize` items.
7
- */
8
- export function chunks(items, chunkSize) {
9
- if (chunkSize < 1) {
10
- throw new RangeError('chunkSize must be at least 1');
11
- }
12
- const itemsChunks = [];
13
- for (let index = 0; index < items.length; index += chunkSize) {
14
- itemsChunks.push(items.slice(index, index + chunkSize));
15
- }
16
- return itemsChunks;
17
- }
18
- /**
19
- * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.
20
- * The next wave starts only after the current wave completes; any rejection fails the whole call.
21
- *
22
- * @param items - Input items; order is preserved in the returned results.
23
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
24
- * @param mapper - Async function for each item; receives the global index in `items`.
25
- * @returns One result per item, in the same order as `items`.
26
- */
27
- export async function batchesAll(items, batchSize, mapper) {
28
- if (batchSize < 1) {
29
- throw new RangeError('batchSize must be at least 1');
30
- }
31
- const results = [];
32
- for (let index = 0; index < items.length; index += batchSize) {
33
- const batch = items.slice(index, index + batchSize);
34
- const batchResults = await Promise.all(batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)));
35
- results.push(...batchResults);
36
- }
37
- return results;
38
- }
39
- /**
40
- * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.
41
- * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.
42
- *
43
- * @param items - Input items; order is preserved in the returned results.
44
- * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).
45
- * @param mapper - Async function for each item; receives the global index in `items`.
46
- * @returns One settled result per item, in the same order as `items`.
47
- */
48
- export async function batchesAllSettled(items, batchSize, mapper) {
49
- if (batchSize < 1) {
50
- throw new RangeError('batchSize must be at least 1');
51
- }
52
- const results = [];
53
- for (let index = 0; index < items.length; index += batchSize) {
54
- const batch = items.slice(index, index + batchSize);
55
- const settled = await Promise.allSettled(batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)));
56
- results.push(...settled);
57
- }
58
- return results;
59
- }
60
- /**
61
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.
62
- * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).
63
- *
64
- * @param items - Flat input items.
65
- * @param chunkSize - Items per chunk (must be ≥ 1).
66
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
67
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
68
- * @returns One settled result per chunk.
69
- */
70
- export async function batchesAllSettledWithChunks(items, chunkSize, batchSize, mapper) {
71
- const itemChunks = chunks(items, chunkSize);
72
- return batchesAllSettled(itemChunks, batchSize, async (chunk, chunkIndex) => mapper(chunk, chunkIndex));
73
- }
74
- /**
75
- * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.
76
- * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).
77
- *
78
- * @param items - Flat input items.
79
- * @param chunkSize - Items per chunk (must be ≥ 1).
80
- * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).
81
- * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).
82
- * @returns One result per chunk.
83
- */
84
- export async function batchesAllWithChunks(items, chunkSize, batchSize, mapper) {
85
- const itemChunks = chunks(items, chunkSize);
86
- return batchesAll(itemChunks, batchSize, async (chunk, chunkIndex) => mapper(chunk, chunkIndex));
87
- }
88
- //# sourceMappingURL=async.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async.mjs","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Splits items into chunks of a given size.\n *\n * @param items - Input items; order is preserved in the returned chunks.\n * @param chunkSize - Size of each chunk (must be ≥ 1).\n * @returns An array of chunks, each containing `chunkSize` items.\n */\nexport function chunks<TItem>(\n items: readonly TItem[],\n chunkSize: number,\n): TItem[][] {\n if (chunkSize < 1) {\n throw new RangeError('chunkSize must be at least 1');\n }\n\n const itemsChunks: TItem[][] = [];\n for (let index = 0; index < items.length; index += chunkSize) {\n itemsChunks.push(items.slice(index, index + chunkSize));\n }\n return itemsChunks;\n}\n\n/**\n * Runs async work on items in fixed-size waves, using {@link Promise.all} per wave.\n * The next wave starts only after the current wave completes; any rejection fails the whole call.\n *\n * @param items - Input items; order is preserved in the returned results.\n * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).\n * @param mapper - Async function for each item; receives the global index in `items`.\n * @returns One result per item, in the same order as `items`.\n */\nexport async function batchesAll<TItem, TResult>(\n items: readonly TItem[],\n batchSize: number,\n mapper: (item: TItem, index: number) => Promise<TResult>,\n): Promise<TResult[]> {\n if (batchSize < 1) {\n throw new RangeError('batchSize must be at least 1');\n }\n\n const results: TResult[] = [];\n\n for (let index = 0; index < items.length; index += batchSize) {\n const batch = items.slice(index, index + batchSize);\n const batchResults = await Promise.all(\n batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)),\n );\n results.push(...batchResults);\n }\n\n return results;\n}\n\n/**\n * Runs async work on items in fixed-size waves, using {@link Promise.allSettled} per wave.\n * The next wave starts only after the current one settles, limiting concurrency to `batchSize`.\n *\n * @param items - Input items; order is preserved in the returned results.\n * @param batchSize - Maximum concurrent mapper invocations per wave (must be ≥ 1).\n * @param mapper - Async function for each item; receives the global index in `items`.\n * @returns One settled result per item, in the same order as `items`.\n */\nexport async function batchesAllSettled<TItem, TResult>(\n items: readonly TItem[],\n batchSize: number,\n mapper: (item: TItem, index: number) => Promise<TResult>,\n): Promise<PromiseSettledResult<TResult>[]> {\n if (batchSize < 1) {\n throw new RangeError('batchSize must be at least 1');\n }\n\n const results: PromiseSettledResult<TResult>[] = [];\n\n for (let index = 0; index < items.length; index += batchSize) {\n const batch = items.slice(index, index + batchSize);\n const settled = await Promise.allSettled(\n batch.map(async (item, batchOffset) => mapper(item, index + batchOffset)),\n );\n results.push(...settled);\n }\n\n return results;\n}\n\n/**\n * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAllSettled} on those chunks.\n * Each mapper call receives one chunk; settled results are in chunk order (same order as {@link chunks}).\n *\n * @param items - Flat input items.\n * @param chunkSize - Items per chunk (must be ≥ 1).\n * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).\n * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).\n * @returns One settled result per chunk.\n */\nexport async function batchesAllSettledWithChunks<TItem, TResult>(\n items: readonly TItem[],\n chunkSize: number,\n batchSize: number,\n mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>,\n): Promise<PromiseSettledResult<TResult>[]> {\n const itemChunks = chunks(items, chunkSize);\n return batchesAllSettled(itemChunks, batchSize, async (chunk, chunkIndex) =>\n mapper(chunk, chunkIndex),\n );\n}\n\n/**\n * Splits `items` into consecutive chunks of `chunkSize`, then runs {@link batchesAll} on those chunks.\n * Each mapper call receives one chunk; results are in chunk order (same order as {@link chunks}).\n *\n * @param items - Flat input items.\n * @param chunkSize - Items per chunk (must be ≥ 1).\n * @param batchSize - Max concurrent chunk mappers per wave (must be ≥ 1).\n * @param mapper - Async work for a single chunk; second argument is the chunk index (0-based).\n * @returns One result per chunk.\n */\nexport async function batchesAllWithChunks<TItem, TResult>(\n items: readonly TItem[],\n chunkSize: number,\n batchSize: number,\n mapper: (chunk: TItem[], chunkIndex: number) => Promise<TResult>,\n): Promise<TResult[]> {\n const itemChunks = chunks(items, chunkSize);\n return batchesAll(itemChunks, batchSize, async (chunk, chunkIndex) =>\n mapper(chunk, chunkIndex),\n );\n}\n"]}