@hyperlane-xyz/registry 10.11.1 → 10.12.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.
@@ -1,9 +1,9 @@
1
1
  import { parse as yamlParse } from 'yaml';
2
2
  import { CHAIN_FILE_REGEX, DEFAULT_GITHUB_REGISTRY, GITHUB_FETCH_CONCURRENCY_LIMIT, WARP_ROUTE_CONFIG_FILE_REGEX, WARP_ROUTE_DEPLOY_FILE_REGEX, } from '../consts.js';
3
- import { concurrentMap, stripLeadingSlash } from '../utils.js';
3
+ import { concurrentMap, parseGitHubPath, stripLeadingSlash } from '../utils.js';
4
4
  import { BaseRegistry } from './BaseRegistry.js';
5
5
  import { RegistryType, } from './IRegistry.js';
6
- import { filterWarpRoutesIds, warpRouteConfigPathToId, warpRouteDeployConfigPathToId } from './warp-utils.js';
6
+ import { filterWarpRoutesIds, warpRouteConfigPathToId, warpRouteDeployConfigPathToId, } from './warp-utils.js';
7
7
  export const GITHUB_API_URL = 'https://api.github.com';
8
8
  /**
9
9
  * A registry that uses a github repository as its data source.
@@ -20,12 +20,12 @@ export class GithubRegistry extends BaseRegistry {
20
20
  constructor(options = {}) {
21
21
  super({ uri: options.uri ?? DEFAULT_GITHUB_REGISTRY, logger: options.logger });
22
22
  this.url = new URL(this.uri);
23
- this.branch = options.branch ?? 'main';
24
- const pathSegments = this.url.pathname.split('/');
25
- if (pathSegments.length < 2)
26
- throw new Error('Invalid github url');
27
- this.repoOwner = pathSegments.at(-2);
28
- this.repoName = pathSegments.at(-1);
23
+ const { repoOwner, repoName, repoBranch } = parseGitHubPath(this.uri);
24
+ this.repoOwner = repoOwner;
25
+ this.repoName = repoName;
26
+ if (options.branch && repoBranch)
27
+ throw new Error('Branch is set in both options and url.');
28
+ this.branch = options.branch ?? repoBranch ?? 'main';
29
29
  this.proxyUrl = options.proxyUrl;
30
30
  }
31
31
  getUri(itemPath) {
@@ -1,3 +1,20 @@
1
1
  import type { Logger } from 'pino';
2
2
  import { IRegistry } from './IRegistry.js';
3
- export declare function getRegistry(registryUris: string[], enableProxy: boolean, branch?: string, logger?: Logger): IRegistry;
3
+ /**
4
+ * Retrieves a registry instance based on the provided registry URIs.
5
+ * The registry can be either a GitHub registry or a file system registry,
6
+ * and the returned instance is a `MergedRegistry` that combines all the
7
+ * specified registries.
8
+ *
9
+ * @param registryUris - An array of registry URIs to use for creating the registry.
10
+ * @param enableProxy - If enabled, forwards all requests to Hyperlane Registry, with higher read limits.
11
+ * @param branch - An optional branch name to use for the GitHub registry.
12
+ * @param logger - An optional logger instance to use for logging.
13
+ * @returns An `IRegistry` instance that combines the specified registries.
14
+ */
15
+ export declare function getRegistry({ registryUris, enableProxy, branch, logger, }: {
16
+ registryUris: string[];
17
+ enableProxy: boolean;
18
+ branch?: string;
19
+ logger?: Logger;
20
+ }): IRegistry;
@@ -1,6 +1,6 @@
1
1
  import { GithubRegistry } from './GithubRegistry.js';
2
2
  import { FileSystemRegistry } from './FileSystemRegistry.js';
3
- import { DEFAULT_GITHUB_REGISTRY, PROXY_DEPLOYED_URL } from '../consts.js';
3
+ import { PROXY_DEPLOYED_URL } from '../consts.js';
4
4
  import { MergedRegistry } from './MergedRegistry.js';
5
5
  const isHttpsUrl = (value) => {
6
6
  try {
@@ -13,9 +13,6 @@ const isHttpsUrl = (value) => {
13
13
  return false;
14
14
  }
15
15
  };
16
- const isCanonicalRepoUrl = (url) => {
17
- return url === DEFAULT_GITHUB_REGISTRY;
18
- };
19
16
  const isValidFilePath = (path) => {
20
17
  try {
21
18
  // Check for control characters (0-31) and DEL (127) without using regex
@@ -41,7 +38,19 @@ const isValidFilePath = (path) => {
41
38
  return false;
42
39
  }
43
40
  };
44
- export function getRegistry(registryUris, enableProxy, branch, logger) {
41
+ /**
42
+ * Retrieves a registry instance based on the provided registry URIs.
43
+ * The registry can be either a GitHub registry or a file system registry,
44
+ * and the returned instance is a `MergedRegistry` that combines all the
45
+ * specified registries.
46
+ *
47
+ * @param registryUris - An array of registry URIs to use for creating the registry.
48
+ * @param enableProxy - If enabled, forwards all requests to Hyperlane Registry, with higher read limits.
49
+ * @param branch - An optional branch name to use for the GitHub registry.
50
+ * @param logger - An optional logger instance to use for logging.
51
+ * @returns An `IRegistry` instance that combines the specified registries.
52
+ */
53
+ export function getRegistry({ registryUris, enableProxy, branch, logger, }) {
45
54
  const registryLogger = logger?.child({ module: 'MergedRegistry' });
46
55
  const registries = registryUris
47
56
  .map((uri) => uri.trim())
@@ -53,7 +62,7 @@ export function getRegistry(registryUris, enableProxy, branch, logger) {
53
62
  uri,
54
63
  branch,
55
64
  logger: childLogger,
56
- proxyUrl: enableProxy && isCanonicalRepoUrl(uri) ? PROXY_DEPLOYED_URL : undefined,
65
+ proxyUrl: enableProxy ? PROXY_DEPLOYED_URL : undefined,
57
66
  });
58
67
  }
59
68
  else {
package/dist/utils.d.ts CHANGED
@@ -5,3 +5,8 @@ export declare function concurrentMap<A, B>(concurrency: number, xs: A[], mapFn:
5
5
  export declare function isObject(item: any): any;
6
6
  export declare function objMerge(a: Record<string, any>, b: Record<string, any>, max_depth?: number): any;
7
7
  export declare function isAbacusWorksChain(metadata: ChainMetadata): boolean;
8
+ export declare function parseGitHubPath(uri: string): {
9
+ repoOwner: string;
10
+ repoName: string;
11
+ repoBranch: string | undefined;
12
+ };
package/dist/utils.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import { stringify } from 'yaml';
2
2
  import { ABACUS_WORKS_DEPLOYER_NAME } from './consts.js';
3
3
  export function toYamlString(data, prefix) {
4
- const yamlString = stringify(data, { indent: 2, sortMapEntries: true, aliasDuplicateObjects: false });
4
+ const yamlString = stringify(data, {
5
+ indent: 2,
6
+ sortMapEntries: true,
7
+ aliasDuplicateObjects: false,
8
+ });
5
9
  return prefix ? `${prefix}\n${yamlString}` : yamlString;
6
10
  }
7
11
  export function stripLeadingSlash(path) {
@@ -51,3 +55,14 @@ export function objMerge(a, b, max_depth = 10) {
51
55
  export function isAbacusWorksChain(metadata) {
52
56
  return metadata.deployer?.name?.toLowerCase() === ABACUS_WORKS_DEPLOYER_NAME.toLowerCase();
53
57
  }
58
+ export function parseGitHubPath(uri) {
59
+ const { pathname } = new URL(uri);
60
+ // Intended pattern: /{user}/{repo}/tree/{branch}
61
+ const regex = /\/([^/]+)\/([^/]+)(?:\/tree\/(.*))?/;
62
+ const match = pathname.match(regex);
63
+ if (!match) {
64
+ throw new Error('Invalid github url');
65
+ }
66
+ const [, repoOwner, repoName, repoBranch] = match;
67
+ return { repoOwner, repoName, repoBranch };
68
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hyperlane-xyz/registry",
3
3
  "description": "A collection of configs, artifacts, and schemas for Hyperlane",
4
- "version": "10.11.1",
4
+ "version": "10.12.0",
5
5
  "dependencies": {
6
6
  "yaml": "2.4.5",
7
7
  "zod": "^3.21.2"
@@ -9,6 +9,7 @@
9
9
  "devDependencies": {
10
10
  "@changesets/cli": "^2.26.2",
11
11
  "@eslint/js": "^9.1.1",
12
+ "@faker-js/faker": "^9.6.0",
12
13
  "@hyperlane-xyz/sdk": "8.8.1",
13
14
  "@types/mocha": "^10.0.1",
14
15
  "@types/node": "^16.9.1",