@dynamic-labs-sdk/assert-package-version 0.25.1 → 0.26.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.
@@ -60,4 +60,4 @@ const assertPackageVersion = (packageName, version) => {
60
60
 
61
61
  //#endregion
62
62
  exports.assertPackageVersion = assertPackageVersion;
63
- //# sourceMappingURL=index.cjs.js.map
63
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["packageVersions","packageVersions: Record<string, string>","versionCheckTimeout: NodeJS.Timeout | null"],"sources":["../src/errors/VersionMismatchError.ts","../src/assertPackageVersion/assertPackageVersion.ts"],"sourcesContent":["export class VersionMismatchError extends Error {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(targetVersion: string, packageVersions: Record<string, string>) {\n // Identify packages with mismatched versions\n const affectedPackages = Object.entries(packageVersions)\n .filter(([, v]) => v !== targetVersion)\n .map(\n ([pkgName, installedVersion]) =>\n `- \\`${pkgName}\\` (installed: **${installedVersion}**, required: **${targetVersion}**)`\n )\n .join('\\n');\n\n // Error message template\n const errorMessage = `\n🚨 Version Mismatch Error\n\nOne or more \\`@dynamic-labs-sdk\\` packages are installed with mismatched versions. All \\`@dynamic-labs-sdk\\` packages must be on the same version to work correctly.\n\nAffected Packages:\n${affectedPackages}\n\n💡 To fix this issue, update all @dynamic-labs-sdk/* packages to version \\`${targetVersion}\\` in your package.json\n`;\n\n super(errorMessage.trim());\n\n this.name = 'VersionMismatchError';\n }\n}\n","import { VersionMismatchError } from '../errors/VersionMismatchError.js';\n\n/**\n * A mapping of package names to their versions.\n * @not-instrumented\n */\nlet packageVersions: Record<string, string> = {};\n\n/**\n * Timeout ID for batching version checks.\n */\nlet versionCheckTimeout: NodeJS.Timeout | null = null;\n\n/**\n * Asserts that all `@dynamic-labs-sdk` packages are on the same version.\n * Throws an error with instructions if versions mismatch.\n *\n * @param {string} packageName - The name of the package to assert.\n * @param {string} version - The version of the package.\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const assertPackageVersion = (\n packageName: string,\n version: string\n): void => {\n // Update the package version mapping\n packageVersions[packageName] = version;\n\n // Clear any existing timeout\n if (versionCheckTimeout) {\n clearTimeout(versionCheckTimeout);\n versionCheckTimeout = null;\n }\n\n /**\n * Timeout is set to 100ms to ensure the following:\n * - All package versions have been imported and registered.\n */\n const timeout = 100;\n\n /**\n * Set a timeout to batch the version check.\n * This ensures that the check is executed after all package versions have been imported\n * and registered.\n */\n versionCheckTimeout = setTimeout(() => {\n const versions = Object.values(packageVersions);\n const [firstVersion] = versions;\n const allSameVersion = versions.every((v) => v === firstVersion);\n\n if (!allSameVersion) {\n // Determine the required (target) version\n const targetVersion =\n packageVersions['@dynamic-labs-sdk/client'] || firstVersion;\n\n const error = new VersionMismatchError(targetVersion, packageVersions);\n\n // eslint-disable-next-line no-console\n console.error(error);\n }\n\n versionCheckTimeout = null;\n }, timeout);\n};\n\n// Helper functions meant only for testing\n\n/** @not-instrumented */\n// eslint-disable-next-line custom-rules/one-function-per-file\nexport const clearPackageVersionState = (): void => {\n if (versionCheckTimeout) {\n clearTimeout(versionCheckTimeout);\n }\n\n packageVersions = {};\n versionCheckTimeout = null;\n};\n\n/** @not-instrumented */\n \nexport const getVersionCheckTimeout = (): NodeJS.Timeout | null =>\n versionCheckTimeout;\n"],"mappings":";;AAAA,IAAa,uBAAb,cAA0C,MAAM;CAE9C,YAAY,eAAuB,mBAAyC;EAW1E,MAAM,eAAe;;;;;;EATI,OAAO,QAAQA,kBAAgB,CACrD,QAAQ,GAAG,OAAO,MAAM,cAAc,CACtC,KACE,CAAC,SAAS,sBACT,OAAO,QAAQ,mBAAmB,iBAAiB,kBAAkB,cAAc,KACtF,CACA,KAAK,KAAK,CASE;;6EAE0D,cAAc;;AAGvF,QAAM,aAAa,MAAM,CAAC;AAE1B,OAAK,OAAO;;;;;;;;;;ACpBhB,IAAIC,kBAA0C,EAAE;;;;AAKhD,IAAIC,sBAA6C;;;;;;;;;AAWjD,MAAa,wBACX,aACA,YACS;AAET,iBAAgB,eAAe;AAG/B,KAAI,qBAAqB;AACvB,eAAa,oBAAoB;AACjC,wBAAsB;;;;;;;AAcxB,uBAAsB,iBAAiB;EACrC,MAAM,WAAW,OAAO,OAAO,gBAAgB;EAC/C,MAAM,CAAC,gBAAgB;AAGvB,MAAI,CAFmB,SAAS,OAAO,MAAM,MAAM,aAAa,EAE3C;GAKnB,MAAM,QAAQ,IAAI,qBAFhB,gBAAgB,+BAA+B,cAEK,gBAAgB;AAGtE,WAAQ,MAAM,MAAM;;AAGtB,wBAAsB;IAvBR,IAwBL"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dynamic-labs-sdk/assert-package-version",
3
- "version": "0.25.1",
3
+ "version": "0.26.0",
4
4
  "type": "module",
5
- "main": "./dist/index.cjs.js",
5
+ "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",
7
7
  "types": "./dist/exports/index.d.ts",
8
8
  "files": [
@@ -13,7 +13,7 @@
13
13
  ".": {
14
14
  "types": "./dist/exports/index.d.ts",
15
15
  "import": "./dist/index.esm.js",
16
- "default": "./dist/index.cjs.js"
16
+ "default": "./dist/index.cjs"
17
17
  }
18
18
  },
19
19
  "devDependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","names":["packageVersions","packageVersions: Record<string, string>","versionCheckTimeout: NodeJS.Timeout | null"],"sources":["../src/errors/VersionMismatchError.ts","../src/assertPackageVersion/assertPackageVersion.ts"],"sourcesContent":["export class VersionMismatchError extends Error {\n // eslint-disable-next-line custom-rules/require-single-object-param\n constructor(targetVersion: string, packageVersions: Record<string, string>) {\n // Identify packages with mismatched versions\n const affectedPackages = Object.entries(packageVersions)\n .filter(([, v]) => v !== targetVersion)\n .map(\n ([pkgName, installedVersion]) =>\n `- \\`${pkgName}\\` (installed: **${installedVersion}**, required: **${targetVersion}**)`\n )\n .join('\\n');\n\n // Error message template\n const errorMessage = `\n🚨 Version Mismatch Error\n\nOne or more \\`@dynamic-labs-sdk\\` packages are installed with mismatched versions. All \\`@dynamic-labs-sdk\\` packages must be on the same version to work correctly.\n\nAffected Packages:\n${affectedPackages}\n\n💡 To fix this issue, update all @dynamic-labs-sdk/* packages to version \\`${targetVersion}\\` in your package.json\n`;\n\n super(errorMessage.trim());\n\n this.name = 'VersionMismatchError';\n }\n}\n","import { VersionMismatchError } from '../errors/VersionMismatchError.js';\n\n/**\n * A mapping of package names to their versions.\n * @not-instrumented\n */\nlet packageVersions: Record<string, string> = {};\n\n/**\n * Timeout ID for batching version checks.\n */\nlet versionCheckTimeout: NodeJS.Timeout | null = null;\n\n/**\n * Asserts that all `@dynamic-labs-sdk` packages are on the same version.\n * Throws an error with instructions if versions mismatch.\n *\n * @param {string} packageName - The name of the package to assert.\n * @param {string} version - The version of the package.\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const assertPackageVersion = (\n packageName: string,\n version: string\n): void => {\n // Update the package version mapping\n packageVersions[packageName] = version;\n\n // Clear any existing timeout\n if (versionCheckTimeout) {\n clearTimeout(versionCheckTimeout);\n versionCheckTimeout = null;\n }\n\n /**\n * Timeout is set to 100ms to ensure the following:\n * - All package versions have been imported and registered.\n */\n const timeout = 100;\n\n /**\n * Set a timeout to batch the version check.\n * This ensures that the check is executed after all package versions have been imported\n * and registered.\n */\n versionCheckTimeout = setTimeout(() => {\n const versions = Object.values(packageVersions);\n const [firstVersion] = versions;\n const allSameVersion = versions.every((v) => v === firstVersion);\n\n if (!allSameVersion) {\n // Determine the required (target) version\n const targetVersion =\n packageVersions['@dynamic-labs-sdk/client'] || firstVersion;\n\n const error = new VersionMismatchError(targetVersion, packageVersions);\n\n // eslint-disable-next-line no-console\n console.error(error);\n }\n\n versionCheckTimeout = null;\n }, timeout);\n};\n\n// Helper functions meant only for testing\n\n/** @not-instrumented */\n// eslint-disable-next-line custom-rules/one-function-per-file\nexport const clearPackageVersionState = (): void => {\n if (versionCheckTimeout) {\n clearTimeout(versionCheckTimeout);\n }\n\n packageVersions = {};\n versionCheckTimeout = null;\n};\n\n/** @not-instrumented */\n \nexport const getVersionCheckTimeout = (): NodeJS.Timeout | null =>\n versionCheckTimeout;\n"],"mappings":";;AAAA,IAAa,uBAAb,cAA0C,MAAM;CAE9C,YAAY,eAAuB,mBAAyC;EAW1E,MAAM,eAAe;;;;;;EATI,OAAO,QAAQA,kBAAgB,CACrD,QAAQ,GAAG,OAAO,MAAM,cAAc,CACtC,KACE,CAAC,SAAS,sBACT,OAAO,QAAQ,mBAAmB,iBAAiB,kBAAkB,cAAc,KACtF,CACA,KAAK,KAAK,CASE;;6EAE0D,cAAc;;AAGvF,QAAM,aAAa,MAAM,CAAC;AAE1B,OAAK,OAAO;;;;;;;;;;ACpBhB,IAAIC,kBAA0C,EAAE;;;;AAKhD,IAAIC,sBAA6C;;;;;;;;;AAWjD,MAAa,wBACX,aACA,YACS;AAET,iBAAgB,eAAe;AAG/B,KAAI,qBAAqB;AACvB,eAAa,oBAAoB;AACjC,wBAAsB;;;;;;;AAcxB,uBAAsB,iBAAiB;EACrC,MAAM,WAAW,OAAO,OAAO,gBAAgB;EAC/C,MAAM,CAAC,gBAAgB;AAGvB,MAAI,CAFmB,SAAS,OAAO,MAAM,MAAM,aAAa,EAE3C;GAKnB,MAAM,QAAQ,IAAI,qBAFhB,gBAAgB,+BAA+B,cAEK,gBAAgB;AAGtE,WAAQ,MAAM,MAAM;;AAGtB,wBAAsB;IAvBR,IAwBL"}