@hardkas/artifacts 0.6.0-alpha → 0.6.1-alpha
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/dist/index.d.ts +115 -2
- package/dist/index.js +145 -20
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1874,11 +1874,124 @@ declare class InvariantWatcher {
|
|
|
1874
1874
|
private emitViolation;
|
|
1875
1875
|
}
|
|
1876
1876
|
|
|
1877
|
+
/**
|
|
1878
|
+
* Represents the payload of any HardKAS artifact in its raw (parsed JSON) form.
|
|
1879
|
+
* The migration engine operates on this untyped representation to support
|
|
1880
|
+
* artifacts across schema versions.
|
|
1881
|
+
*/
|
|
1882
|
+
type ArtifactPayload = Record<string, unknown>;
|
|
1883
|
+
/**
|
|
1884
|
+
* A single versioned migration step that transforms an artifact payload
|
|
1885
|
+
* from one schema version to the next.
|
|
1886
|
+
*/
|
|
1887
|
+
interface MigrationStep {
|
|
1888
|
+
/** Source version string (e.g., "0.1.0", "1.0.0-alpha") */
|
|
1889
|
+
readonly fromVersion: string;
|
|
1890
|
+
/** Target version string */
|
|
1891
|
+
readonly toVersion: string;
|
|
1892
|
+
/** Human-readable description of what this migration does */
|
|
1893
|
+
readonly description: string;
|
|
1894
|
+
/**
|
|
1895
|
+
* Transform function. Receives a shallow clone of the artifact payload
|
|
1896
|
+
* and returns the migrated payload. MUST NOT mutate the input.
|
|
1897
|
+
*/
|
|
1898
|
+
transform(artifact: ArtifactPayload): ArtifactPayload;
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Result of a migration operation.
|
|
1902
|
+
*/
|
|
1903
|
+
interface MigrationResult {
|
|
1904
|
+
/** The migrated artifact payload */
|
|
1905
|
+
artifact: ArtifactPayload;
|
|
1906
|
+
/** Whether any migration was actually applied */
|
|
1907
|
+
migrated: boolean;
|
|
1908
|
+
/** The original content hash (before migration), preserved for lineage */
|
|
1909
|
+
originalContentHash: string | undefined;
|
|
1910
|
+
/** Ordered list of migration steps that were applied */
|
|
1911
|
+
appliedSteps: ReadonlyArray<{
|
|
1912
|
+
fromVersion: string;
|
|
1913
|
+
toVersion: string;
|
|
1914
|
+
description: string;
|
|
1915
|
+
}>;
|
|
1916
|
+
}
|
|
1917
|
+
/**
|
|
1918
|
+
* Registers a migration step in the global registry.
|
|
1919
|
+
* Steps should be registered in chronological order (oldest → newest).
|
|
1920
|
+
*
|
|
1921
|
+
* @param step - The migration step to register
|
|
1922
|
+
*/
|
|
1923
|
+
declare function registerMigrationStep(step: MigrationStep): void;
|
|
1924
|
+
/**
|
|
1925
|
+
* Returns all registered migration steps (read-only copy).
|
|
1926
|
+
*/
|
|
1927
|
+
declare function getRegisteredMigrationSteps(): ReadonlyArray<MigrationStep>;
|
|
1928
|
+
/**
|
|
1929
|
+
* Determines the version of an artifact based on its `version` field,
|
|
1930
|
+
* falling back to heuristics for truly legacy artifacts.
|
|
1931
|
+
*/
|
|
1932
|
+
declare function detectArtifactVersion(artifact: ArtifactPayload): string;
|
|
1933
|
+
/**
|
|
1934
|
+
* Resolves the ordered list of migration steps needed to go from
|
|
1935
|
+
* `fromVersion` to `toVersion`.
|
|
1936
|
+
*
|
|
1937
|
+
* Uses a simple BFS/chain walk through the migration registry.
|
|
1938
|
+
* Returns an empty array if no migration path exists or if the artifact
|
|
1939
|
+
* is already at the target version.
|
|
1940
|
+
*
|
|
1941
|
+
* @param fromVersion - The current artifact version
|
|
1942
|
+
* @param toVersion - The desired target version
|
|
1943
|
+
* @returns Ordered array of migration steps, or empty if no path or already current
|
|
1944
|
+
*/
|
|
1945
|
+
declare function getMigrationPath(fromVersion: string, toVersion: string): ReadonlyArray<MigrationStep>;
|
|
1946
|
+
/**
|
|
1947
|
+
* Checks whether a migration path exists from the artifact's current
|
|
1948
|
+
* version to the target version.
|
|
1949
|
+
*
|
|
1950
|
+
* @param artifact - The artifact payload to check
|
|
1951
|
+
* @param targetVersion - The desired target version (defaults to ARTIFACT_VERSION)
|
|
1952
|
+
* @returns `true` if a migration path exists or the artifact is already at the target version
|
|
1953
|
+
*/
|
|
1954
|
+
declare function canMigrate(artifact: ArtifactPayload, targetVersion?: string): boolean;
|
|
1955
|
+
/**
|
|
1956
|
+
* Migrates an artifact payload from its current schema version to the
|
|
1957
|
+
* specified target version.
|
|
1958
|
+
*
|
|
1959
|
+
* **Identity Preservation:**
|
|
1960
|
+
* - The original `contentHash` is preserved as `originalContentHash`
|
|
1961
|
+
* - The `lineage.rootArtifactId` is NEVER modified
|
|
1962
|
+
* - A new `contentHash` is computed after migration using `CURRENT_HASH_VERSION`
|
|
1963
|
+
*
|
|
1964
|
+
* **Non-Destructive:**
|
|
1965
|
+
* - The input artifact object is never mutated
|
|
1966
|
+
* - The canonical artifact file on disk is never modified
|
|
1967
|
+
* - Migration produces a new in-memory representation only
|
|
1968
|
+
*
|
|
1969
|
+
* @param artifact - The artifact payload to migrate
|
|
1970
|
+
* @param targetVersion - The desired target version (defaults to ARTIFACT_VERSION)
|
|
1971
|
+
* @returns MigrationResult with the migrated artifact and metadata
|
|
1972
|
+
* @throws Error if no migration path exists
|
|
1973
|
+
*
|
|
1974
|
+
* @example
|
|
1975
|
+
* ```typescript
|
|
1976
|
+
* const result = migrateArtifactPayload(legacyArtifact);
|
|
1977
|
+
* if (result.migrated) {
|
|
1978
|
+
* console.log(`Migrated from ${result.appliedSteps[0].fromVersion}`);
|
|
1979
|
+
* console.log(`Original hash preserved: ${result.originalContentHash}`);
|
|
1980
|
+
* }
|
|
1981
|
+
* ```
|
|
1982
|
+
*/
|
|
1983
|
+
declare function migrateArtifactPayload(artifact: ArtifactPayload, targetVersion?: string): MigrationResult;
|
|
1877
1984
|
/**
|
|
1878
1985
|
* Migrates a v1 artifact to canonical format by updating the schema, version,
|
|
1879
1986
|
* and calculating the contentHash.
|
|
1987
|
+
*
|
|
1988
|
+
* @deprecated Use `migrateArtifactPayload()` instead. This function is retained
|
|
1989
|
+
* for backward compatibility with existing callers.
|
|
1990
|
+
*
|
|
1991
|
+
* @param v1Artifact - The legacy v1 artifact to migrate
|
|
1992
|
+
* @returns The migrated artifact in canonical format
|
|
1880
1993
|
*/
|
|
1881
|
-
declare function migrateToCanonical(v1Artifact:
|
|
1994
|
+
declare function migrateToCanonical(v1Artifact: ArtifactPayload): ArtifactPayload;
|
|
1882
1995
|
|
|
1883
1996
|
declare const bigIntReplacer: (_key: string, value: unknown) => unknown;
|
|
1884
1997
|
declare function writeArtifact(filePath: string, artifact: unknown): Promise<void>;
|
|
@@ -2100,4 +2213,4 @@ declare function listDeployments(rootDir: string, networkId?: string): Promise<D
|
|
|
2100
2213
|
declare function updateDeployment(rootDir: string, networkId: string, label: string, update: Partial<DeploymentRecord>): Promise<DeploymentRecord>;
|
|
2101
2214
|
declare function deleteDeployment(rootDir: string, networkId: string, label: string): Promise<boolean>;
|
|
2102
2215
|
|
|
2103
|
-
export { ARTIFACT_SCHEMAS, ARTIFACT_VERSION, AccountRefSchema, type ArtifactDiff, type ArtifactExplanation, ArtifactLineageSchema, type ArtifactLookup, type ArtifactValidationResult, type ArtifactVerificationResult, type AssumptionLevel, type BaseArtifact, BaseArtifactSchema, BasicCorrelationInvariant, BasicLineageInvariant, CURRENT_HASH_VERSION, type Clock, type CreateTxPlanArtifactOptions, type DagContext, DagContextSchema, type DeploymentIndex, type DeploymentRecord, type DeploymentSummary, type DiffEntry, type DraftArtifact, type FeeAuditResult, HARDKAS_VERSION, type HardkasArtifactBase, type HardkasArtifactMode, type HardkasArtifactSchema, HashInvariant, type IgraSignedTxArtifact, type IgraTxPlanArtifact, type IgraTxReceiptArtifact, type IgraTxRequestArtifact, type Invariant, type InvariantContext, type InvariantViolation, InvariantWatcher, LifecycleInvariant, type LineageOptions, type LineageValidationResult, LocalnetUtxoSchemaV2, NetworkInvariant, ReplayInvariant, SEMANTIC_EXCLUSIONS, SchemaInvariant, type SignedTx, type SignedTxArtifact, type SignedTxArtifactV1, SignedTxSchema, type Snapshot, type SnapshotArtifact, SnapshotSchema, type TxOutputArtifact, type TxPlan, type TxPlanArtifact, type TxPlanArtifactV1, TxPlanSchema, type TxReceipt, type TxReceiptArtifact, type TxReceiptArtifactV1, TxReceiptSchema, type TxTrace, type TxTraceArtifact, type TxTraceArtifactV1, TxTraceSchema, type UtxoArtifact, type VerificationContext, type VerificationIssue, type VerificationSeverity, type WatcherOptions, type Workflow, type WorkflowArtifact, WorkflowSchema, assertDecimalBigIntString, assertEvmAddress, assertEvmTxHash, assertHexData, assertValidIgraSignedTxArtifact, assertValidIgraTxPlanArtifact, assertValidIgraTxReceiptArtifact, assertValidSignedTxArtifact, assertValidTxPlanArtifact, assertValidTxReceiptArtifact, bigIntReplacer, calculateContentHash, canonicalStringify, createDeploymentRecord, createIgraDeployPlanId, createIgraPlanId, createIgraSignedId, createSimulatedSignedTxArtifact, createSimulatedTxReceipt, createTxPlanArtifact, defaultClock, deleteDeployment, diffArtifacts, explainArtifact, formatSignedTxArtifact, formatTxPlanArtifact, formatTxReceiptArtifact, getBroadcastableSignedTransaction, getDefaultL2ReceiptsDir, getDefaultReceiptPath, getL2ReceiptPath, isIgraTxPlanArtifact, listDeployments, listIgraTxReceiptArtifacts, loadDeployment, loadIgraTxReceiptArtifact, migrateToCanonical, readArtifact, readSignedTxArtifact, readTxPlanArtifact, readTxReceiptArtifact, recomputeMass, saveDeployment, saveIgraTxReceiptArtifact, sortUtxosByOutpoint, txOutputFromArtifact, txOutputToArtifact, updateDeployment, updateDeploymentStatus, utxoFromArtifact, utxoToArtifact, validateArtifact, validateIgraSignedTxArtifact, validateIgraTxPlanArtifact, validateIgraTxReceiptArtifact, validateSignedTxArtifact, validateTxPlanArtifact, validateTxReceiptArtifact, verifyArtifact, verifyArtifactFile, verifyArtifactIntegrity, verifyArtifactReplay, verifyArtifactSemantics, verifyFeeSemantics, verifyLineage, writeArtifact };
|
|
2216
|
+
export { ARTIFACT_SCHEMAS, ARTIFACT_VERSION, AccountRefSchema, type ArtifactDiff, type ArtifactExplanation, ArtifactLineageSchema, type ArtifactLookup, type ArtifactPayload, type ArtifactValidationResult, type ArtifactVerificationResult, type AssumptionLevel, type BaseArtifact, BaseArtifactSchema, BasicCorrelationInvariant, BasicLineageInvariant, CURRENT_HASH_VERSION, type Clock, type CreateTxPlanArtifactOptions, type DagContext, DagContextSchema, type DeploymentIndex, type DeploymentRecord, type DeploymentSummary, type DiffEntry, type DraftArtifact, type FeeAuditResult, HARDKAS_VERSION, type HardkasArtifactBase, type HardkasArtifactMode, type HardkasArtifactSchema, HashInvariant, type IgraSignedTxArtifact, type IgraTxPlanArtifact, type IgraTxReceiptArtifact, type IgraTxRequestArtifact, type Invariant, type InvariantContext, type InvariantViolation, InvariantWatcher, LifecycleInvariant, type LineageOptions, type LineageValidationResult, LocalnetUtxoSchemaV2, type MigrationResult, type MigrationStep, NetworkInvariant, ReplayInvariant, SEMANTIC_EXCLUSIONS, SchemaInvariant, type SignedTx, type SignedTxArtifact, type SignedTxArtifactV1, SignedTxSchema, type Snapshot, type SnapshotArtifact, SnapshotSchema, type TxOutputArtifact, type TxPlan, type TxPlanArtifact, type TxPlanArtifactV1, TxPlanSchema, type TxReceipt, type TxReceiptArtifact, type TxReceiptArtifactV1, TxReceiptSchema, type TxTrace, type TxTraceArtifact, type TxTraceArtifactV1, TxTraceSchema, type UtxoArtifact, type VerificationContext, type VerificationIssue, type VerificationSeverity, type WatcherOptions, type Workflow, type WorkflowArtifact, WorkflowSchema, assertDecimalBigIntString, assertEvmAddress, assertEvmTxHash, assertHexData, assertValidIgraSignedTxArtifact, assertValidIgraTxPlanArtifact, assertValidIgraTxReceiptArtifact, assertValidSignedTxArtifact, assertValidTxPlanArtifact, assertValidTxReceiptArtifact, bigIntReplacer, calculateContentHash, canMigrate, canonicalStringify, createDeploymentRecord, createIgraDeployPlanId, createIgraPlanId, createIgraSignedId, createSimulatedSignedTxArtifact, createSimulatedTxReceipt, createTxPlanArtifact, defaultClock, deleteDeployment, detectArtifactVersion, diffArtifacts, explainArtifact, formatSignedTxArtifact, formatTxPlanArtifact, formatTxReceiptArtifact, getBroadcastableSignedTransaction, getDefaultL2ReceiptsDir, getDefaultReceiptPath, getL2ReceiptPath, getMigrationPath, getRegisteredMigrationSteps, isIgraTxPlanArtifact, listDeployments, listIgraTxReceiptArtifacts, loadDeployment, loadIgraTxReceiptArtifact, migrateArtifactPayload, migrateToCanonical, readArtifact, readSignedTxArtifact, readTxPlanArtifact, readTxReceiptArtifact, recomputeMass, registerMigrationStep, saveDeployment, saveIgraTxReceiptArtifact, sortUtxosByOutpoint, txOutputFromArtifact, txOutputToArtifact, updateDeployment, updateDeploymentStatus, utxoFromArtifact, utxoToArtifact, validateArtifact, validateIgraSignedTxArtifact, validateIgraTxPlanArtifact, validateIgraTxReceiptArtifact, validateSignedTxArtifact, validateTxPlanArtifact, validateTxReceiptArtifact, verifyArtifact, verifyArtifactFile, verifyArtifactIntegrity, verifyArtifactReplay, verifyArtifactSemantics, verifyFeeSemantics, verifyLineage, writeArtifact };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@hardkas/artifacts",
|
|
4
|
-
version: "0.6.
|
|
4
|
+
version: "0.6.1-alpha",
|
|
5
5
|
type: "module",
|
|
6
6
|
license: "MIT",
|
|
7
7
|
author: "Javier Rodriguez",
|
|
@@ -214,7 +214,7 @@ function canonicalStringify(obj, version = CURRENT_HASH_VERSION) {
|
|
|
214
214
|
return JSON.stringify(obj.toString());
|
|
215
215
|
}
|
|
216
216
|
if (typeof obj === "string" && version >= 3) {
|
|
217
|
-
const normalized = obj.normalize("NFC").replace(/\r\n/g, "\n");
|
|
217
|
+
const normalized = obj.normalize("NFC").replace(/\r\n/g, "\n").replace(/\\/g, "/");
|
|
218
218
|
return JSON.stringify(normalized);
|
|
219
219
|
}
|
|
220
220
|
return JSON.stringify(obj);
|
|
@@ -595,6 +595,7 @@ function verifyLineage(artifact, parent, options = {}) {
|
|
|
595
595
|
// src/verify.ts
|
|
596
596
|
var defaultClock = {
|
|
597
597
|
now: () => Date.now()
|
|
598
|
+
// hardkas-determinism-allow: default clock ambient source
|
|
598
599
|
};
|
|
599
600
|
function deterministicCompare2(a, b) {
|
|
600
601
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -995,30 +996,148 @@ var InvariantWatcher = class {
|
|
|
995
996
|
};
|
|
996
997
|
|
|
997
998
|
// src/migration.ts
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
999
|
+
var migrationRegistry = [];
|
|
1000
|
+
function registerMigrationStep(step) {
|
|
1001
|
+
const existing = migrationRegistry.find(
|
|
1002
|
+
(s) => s.fromVersion === step.fromVersion && s.toVersion === step.toVersion
|
|
1003
|
+
);
|
|
1004
|
+
if (existing) {
|
|
1005
|
+
throw new Error(
|
|
1006
|
+
`Duplicate migration step: ${step.fromVersion} \u2192 ${step.toVersion} already registered`
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
migrationRegistry.push(step);
|
|
1010
|
+
}
|
|
1011
|
+
function getRegisteredMigrationSteps() {
|
|
1012
|
+
return [...migrationRegistry];
|
|
1013
|
+
}
|
|
1014
|
+
registerMigrationStep({
|
|
1015
|
+
fromVersion: "0.1.0",
|
|
1016
|
+
toVersion: ARTIFACT_VERSION,
|
|
1017
|
+
description: "Legacy v1 schemas to canonical 1.0.0-alpha format",
|
|
1018
|
+
transform(artifact) {
|
|
1019
|
+
const migrated = { ...artifact };
|
|
1020
|
+
if (typeof migrated.schema === "string" && migrated.schema.endsWith(".v1")) {
|
|
1021
|
+
if (migrated.schema !== "hardkas.workflow.v1") {
|
|
1022
|
+
migrated.schema = migrated.schema.replace(/\.v1$/, "");
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
migrated.version = ARTIFACT_VERSION;
|
|
1026
|
+
if (migrated.schema === "hardkas.txPlan" && migrated.selectedUtxos !== void 0) {
|
|
1027
|
+
migrated.inputs = migrated.selectedUtxos;
|
|
1028
|
+
delete migrated.selectedUtxos;
|
|
1029
|
+
}
|
|
1030
|
+
if (migrated.schema === "hardkas.snapshot" && Array.isArray(migrated.utxos)) {
|
|
1031
|
+
migrated.utxos = sortUtxosByOutpoint(migrated.utxos);
|
|
1032
|
+
}
|
|
1033
|
+
if (!migrated.hardkasVersion) {
|
|
1034
|
+
migrated.hardkasVersion = HARDKAS_VERSION;
|
|
1035
|
+
}
|
|
1036
|
+
if (!migrated.createdAt) {
|
|
1037
|
+
migrated.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1038
|
+
}
|
|
1039
|
+
if (migrated.hashVersion === void 0 || migrated.hashVersion === null) {
|
|
1040
|
+
migrated.hashVersion = CURRENT_HASH_VERSION;
|
|
1041
|
+
}
|
|
1042
|
+
return migrated;
|
|
1001
1043
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1044
|
+
});
|
|
1045
|
+
function detectArtifactVersion(artifact) {
|
|
1046
|
+
if (typeof artifact.version === "string" && artifact.version.length > 0) {
|
|
1047
|
+
return artifact.version;
|
|
1005
1048
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
v2Artifact.inputs = v1Artifact.selectedUtxos;
|
|
1009
|
-
delete v2Artifact.selectedUtxos;
|
|
1049
|
+
if (typeof artifact.schema === "string" && artifact.schema.endsWith(".v1")) {
|
|
1050
|
+
return "0.1.0";
|
|
1010
1051
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1052
|
+
return "0.1.0";
|
|
1053
|
+
}
|
|
1054
|
+
function getMigrationPath(fromVersion, toVersion) {
|
|
1055
|
+
if (fromVersion === toVersion) {
|
|
1056
|
+
return [];
|
|
1013
1057
|
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1058
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1059
|
+
const queue = [
|
|
1060
|
+
{ version: fromVersion, path: [] }
|
|
1061
|
+
];
|
|
1062
|
+
visited.add(fromVersion);
|
|
1063
|
+
while (queue.length > 0) {
|
|
1064
|
+
const current = queue.shift();
|
|
1065
|
+
const outgoing = migrationRegistry.filter(
|
|
1066
|
+
(s) => s.fromVersion === current.version
|
|
1067
|
+
);
|
|
1068
|
+
for (const step of outgoing) {
|
|
1069
|
+
const newPath = [...current.path, step];
|
|
1070
|
+
if (step.toVersion === toVersion) {
|
|
1071
|
+
return newPath;
|
|
1072
|
+
}
|
|
1073
|
+
if (!visited.has(step.toVersion)) {
|
|
1074
|
+
visited.add(step.toVersion);
|
|
1075
|
+
queue.push({ version: step.toVersion, path: newPath });
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1016
1078
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1079
|
+
return [];
|
|
1080
|
+
}
|
|
1081
|
+
function canMigrate(artifact, targetVersion = ARTIFACT_VERSION) {
|
|
1082
|
+
const currentVersion = detectArtifactVersion(artifact);
|
|
1083
|
+
if (currentVersion === targetVersion) {
|
|
1084
|
+
return true;
|
|
1085
|
+
}
|
|
1086
|
+
const path4 = getMigrationPath(currentVersion, targetVersion);
|
|
1087
|
+
return path4.length > 0;
|
|
1088
|
+
}
|
|
1089
|
+
function migrateArtifactPayload(artifact, targetVersion = ARTIFACT_VERSION) {
|
|
1090
|
+
const currentVersion = detectArtifactVersion(artifact);
|
|
1091
|
+
if (currentVersion === targetVersion) {
|
|
1092
|
+
return {
|
|
1093
|
+
artifact,
|
|
1094
|
+
migrated: false,
|
|
1095
|
+
originalContentHash: artifact.contentHash,
|
|
1096
|
+
appliedSteps: []
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
const path4 = getMigrationPath(currentVersion, targetVersion);
|
|
1100
|
+
if (path4.length === 0) {
|
|
1101
|
+
throw new Error(
|
|
1102
|
+
`No migration path from version "${currentVersion}" to "${targetVersion}". Registered steps: [${migrationRegistry.map((s) => `${s.fromVersion}\u2192${s.toVersion}`).join(", ")}]`
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
const originalContentHash = artifact.contentHash;
|
|
1106
|
+
const originalLineage = artifact.lineage;
|
|
1107
|
+
let current = { ...artifact };
|
|
1108
|
+
const appliedSteps = [];
|
|
1109
|
+
for (const step of path4) {
|
|
1110
|
+
current = step.transform(current);
|
|
1111
|
+
appliedSteps.push({
|
|
1112
|
+
fromVersion: step.fromVersion,
|
|
1113
|
+
toVersion: step.toVersion,
|
|
1114
|
+
description: step.description
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
if (originalContentHash) {
|
|
1118
|
+
current.originalContentHash = originalContentHash;
|
|
1119
|
+
}
|
|
1120
|
+
if (originalLineage && typeof originalLineage === "object") {
|
|
1121
|
+
const migratedLineage = current.lineage;
|
|
1122
|
+
if (migratedLineage && typeof migratedLineage === "object") {
|
|
1123
|
+
migratedLineage.rootArtifactId = originalLineage.rootArtifactId;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
current.hashVersion = CURRENT_HASH_VERSION;
|
|
1127
|
+
current.contentHash = calculateContentHash(current, CURRENT_HASH_VERSION);
|
|
1128
|
+
return {
|
|
1129
|
+
artifact: current,
|
|
1130
|
+
migrated: true,
|
|
1131
|
+
originalContentHash,
|
|
1132
|
+
appliedSteps
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
function migrateToCanonical(v1Artifact) {
|
|
1136
|
+
if (v1Artifact.version === ARTIFACT_VERSION) {
|
|
1137
|
+
return v1Artifact;
|
|
1019
1138
|
}
|
|
1020
|
-
|
|
1021
|
-
return
|
|
1139
|
+
const result = migrateArtifactPayload(v1Artifact, ARTIFACT_VERSION);
|
|
1140
|
+
return result.artifact;
|
|
1022
1141
|
}
|
|
1023
1142
|
|
|
1024
1143
|
// src/io.ts
|
|
@@ -1710,6 +1829,7 @@ export {
|
|
|
1710
1829
|
assertValidTxReceiptArtifact,
|
|
1711
1830
|
bigIntReplacer,
|
|
1712
1831
|
calculateContentHash,
|
|
1832
|
+
canMigrate,
|
|
1713
1833
|
canonicalStringify,
|
|
1714
1834
|
createDeploymentRecord,
|
|
1715
1835
|
createIgraDeployPlanId,
|
|
@@ -1720,6 +1840,7 @@ export {
|
|
|
1720
1840
|
createTxPlanArtifact,
|
|
1721
1841
|
defaultClock,
|
|
1722
1842
|
deleteDeployment,
|
|
1843
|
+
detectArtifactVersion,
|
|
1723
1844
|
diffArtifacts,
|
|
1724
1845
|
explainArtifact,
|
|
1725
1846
|
formatSignedTxArtifact,
|
|
@@ -1729,17 +1850,21 @@ export {
|
|
|
1729
1850
|
getDefaultL2ReceiptsDir,
|
|
1730
1851
|
getDefaultReceiptPath,
|
|
1731
1852
|
getL2ReceiptPath,
|
|
1853
|
+
getMigrationPath,
|
|
1854
|
+
getRegisteredMigrationSteps,
|
|
1732
1855
|
isIgraTxPlanArtifact,
|
|
1733
1856
|
listDeployments,
|
|
1734
1857
|
listIgraTxReceiptArtifacts,
|
|
1735
1858
|
loadDeployment,
|
|
1736
1859
|
loadIgraTxReceiptArtifact,
|
|
1860
|
+
migrateArtifactPayload,
|
|
1737
1861
|
migrateToCanonical,
|
|
1738
1862
|
readArtifact,
|
|
1739
1863
|
readSignedTxArtifact,
|
|
1740
1864
|
readTxPlanArtifact,
|
|
1741
1865
|
readTxReceiptArtifact,
|
|
1742
1866
|
recomputeMass,
|
|
1867
|
+
registerMigrationStep,
|
|
1743
1868
|
saveDeployment,
|
|
1744
1869
|
saveIgraTxReceiptArtifact,
|
|
1745
1870
|
sortUtxosByOutpoint,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/artifacts",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Javier Rodriguez",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"zod": "^3.24.1",
|
|
27
|
-
"@hardkas/core": "0.6.
|
|
28
|
-
"@hardkas/tx-builder": "0.6.
|
|
27
|
+
"@hardkas/core": "0.6.1-alpha",
|
|
28
|
+
"@hardkas/tx-builder": "0.6.1-alpha"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"tsup": "^8.3.5",
|