@le-space/core 0.1.15 → 0.1.16
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/index.d.ts +7 -0
- package/index.js +84 -9
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -320,6 +320,9 @@ declare function retainSuccessfulDeployments(args: {
|
|
|
320
320
|
retainedRecords: RetentionRecord[];
|
|
321
321
|
prunedRecords: RetentionRecord[];
|
|
322
322
|
forgetHashes: string[];
|
|
323
|
+
forgottenHashes: string[];
|
|
324
|
+
outstandingForgetHashes: string[];
|
|
325
|
+
forgetStatuses: Record<string, string>;
|
|
323
326
|
forgetResult: {
|
|
324
327
|
sender: string;
|
|
325
328
|
itemHash: string;
|
|
@@ -327,6 +330,10 @@ declare function retainSuccessfulDeployments(args: {
|
|
|
327
330
|
httpStatus: number;
|
|
328
331
|
status: _shared_aleph_shared_types.MessageStatus;
|
|
329
332
|
} | null;
|
|
333
|
+
followUpForgetResults: {
|
|
334
|
+
hash: string;
|
|
335
|
+
result: Awaited<ReturnType<typeof forgetAlephMessages>>;
|
|
336
|
+
}[];
|
|
330
337
|
}>;
|
|
331
338
|
|
|
332
339
|
declare function createPortForwardAggregateContent(args: {
|
package/index.js
CHANGED
|
@@ -893,6 +893,31 @@ async function publishAggregateKey(args) {
|
|
|
893
893
|
httpStatus
|
|
894
894
|
};
|
|
895
895
|
}
|
|
896
|
+
async function fetchMessageStatus(args) {
|
|
897
|
+
const requestUrl = new URL(`/api/v0/messages/${args.hash}`, args.apiHost ?? "https://api2.aleph.im");
|
|
898
|
+
const response = await args.fetch(requestUrl.toString(), { cache: "no-cache" });
|
|
899
|
+
if (response.status === 404) return "missing";
|
|
900
|
+
if (!response.ok) return "unknown";
|
|
901
|
+
const payload = await response.json();
|
|
902
|
+
return asString3(payload?.status) ?? "unknown";
|
|
903
|
+
}
|
|
904
|
+
async function classifyForgetHashes(args) {
|
|
905
|
+
const statuses = {};
|
|
906
|
+
for (const hash of args.hashes) {
|
|
907
|
+
statuses[hash] = await fetchMessageStatus({
|
|
908
|
+
hash,
|
|
909
|
+
fetch: args.fetch,
|
|
910
|
+
apiHost: args.apiHost
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
const forgottenHashes = args.hashes.filter((hash) => statuses[hash] === "forgotten");
|
|
914
|
+
const outstandingForgetHashes = args.hashes.filter((hash) => statuses[hash] !== "forgotten");
|
|
915
|
+
return {
|
|
916
|
+
forgottenHashes,
|
|
917
|
+
outstandingForgetHashes,
|
|
918
|
+
statuses
|
|
919
|
+
};
|
|
920
|
+
}
|
|
896
921
|
async function retainSuccessfulDeployments(args) {
|
|
897
922
|
const keepCount = Math.max(0, Number.parseInt(String(args.keepCount ?? 0), 10) || 0);
|
|
898
923
|
const aggregateKey = asString3(args.aggregateKey) ?? SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY;
|
|
@@ -940,18 +965,64 @@ async function retainSuccessfulDeployments(args) {
|
|
|
940
965
|
now: args.now
|
|
941
966
|
});
|
|
942
967
|
let forgetResult = null;
|
|
968
|
+
let followUpForgetResults = [];
|
|
969
|
+
let forgottenHashes = [];
|
|
970
|
+
let outstandingForgetHashes = [];
|
|
971
|
+
let forgetStatuses = {};
|
|
943
972
|
if (forgetHashes.length > 0) {
|
|
944
|
-
|
|
945
|
-
sender: args.sender,
|
|
973
|
+
const initiallyOutstanding = await classifyForgetHashes({
|
|
946
974
|
hashes: forgetHashes,
|
|
947
|
-
reason: args.reason ?? `Prune successful deployments beyond retention limit ${keepCount}`,
|
|
948
|
-
signer: args.signer,
|
|
949
|
-
hasher: args.hasher,
|
|
950
975
|
fetch: args.fetch,
|
|
951
|
-
|
|
952
|
-
apiHost: args.apiHost,
|
|
953
|
-
now: args.now
|
|
976
|
+
apiHost: args.apiHost
|
|
954
977
|
});
|
|
978
|
+
forgottenHashes = initiallyOutstanding.forgottenHashes;
|
|
979
|
+
outstandingForgetHashes = initiallyOutstanding.outstandingForgetHashes;
|
|
980
|
+
forgetStatuses = initiallyOutstanding.statuses;
|
|
981
|
+
if (outstandingForgetHashes.length > 0) {
|
|
982
|
+
forgetResult = await forgetAlephMessages({
|
|
983
|
+
sender: args.sender,
|
|
984
|
+
hashes: outstandingForgetHashes,
|
|
985
|
+
reason: args.reason ?? `Prune successful deployments beyond retention limit ${keepCount}`,
|
|
986
|
+
signer: args.signer,
|
|
987
|
+
hasher: args.hasher,
|
|
988
|
+
fetch: args.fetch,
|
|
989
|
+
channel: args.channel,
|
|
990
|
+
apiHost: args.apiHost,
|
|
991
|
+
now: args.now
|
|
992
|
+
});
|
|
993
|
+
let postBatch = await classifyForgetHashes({
|
|
994
|
+
hashes: forgetHashes,
|
|
995
|
+
fetch: args.fetch,
|
|
996
|
+
apiHost: args.apiHost
|
|
997
|
+
});
|
|
998
|
+
forgottenHashes = postBatch.forgottenHashes;
|
|
999
|
+
outstandingForgetHashes = postBatch.outstandingForgetHashes;
|
|
1000
|
+
forgetStatuses = postBatch.statuses;
|
|
1001
|
+
if (outstandingForgetHashes.length > 0) {
|
|
1002
|
+
for (const hash of outstandingForgetHashes) {
|
|
1003
|
+
const result = await forgetAlephMessages({
|
|
1004
|
+
sender: args.sender,
|
|
1005
|
+
hashes: [hash],
|
|
1006
|
+
reason: args.reason ?? `Prune successful deployments beyond retention limit ${keepCount}`,
|
|
1007
|
+
signer: args.signer,
|
|
1008
|
+
hasher: args.hasher,
|
|
1009
|
+
fetch: args.fetch,
|
|
1010
|
+
channel: args.channel,
|
|
1011
|
+
apiHost: args.apiHost,
|
|
1012
|
+
now: args.now
|
|
1013
|
+
});
|
|
1014
|
+
followUpForgetResults.push({ hash, result });
|
|
1015
|
+
}
|
|
1016
|
+
postBatch = await classifyForgetHashes({
|
|
1017
|
+
hashes: forgetHashes,
|
|
1018
|
+
fetch: args.fetch,
|
|
1019
|
+
apiHost: args.apiHost
|
|
1020
|
+
});
|
|
1021
|
+
forgottenHashes = postBatch.forgottenHashes;
|
|
1022
|
+
outstandingForgetHashes = postBatch.outstandingForgetHashes;
|
|
1023
|
+
forgetStatuses = postBatch.statuses;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
955
1026
|
}
|
|
956
1027
|
return {
|
|
957
1028
|
sender: args.sender,
|
|
@@ -961,7 +1032,11 @@ async function retainSuccessfulDeployments(args) {
|
|
|
961
1032
|
retainedRecords,
|
|
962
1033
|
prunedRecords,
|
|
963
1034
|
forgetHashes,
|
|
964
|
-
|
|
1035
|
+
forgottenHashes,
|
|
1036
|
+
outstandingForgetHashes,
|
|
1037
|
+
forgetStatuses,
|
|
1038
|
+
forgetResult,
|
|
1039
|
+
followUpForgetResults
|
|
965
1040
|
};
|
|
966
1041
|
}
|
|
967
1042
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@le-space/shared-types": "0.1.
|
|
19
|
+
"@le-space/shared-types": "0.1.16"
|
|
20
20
|
}
|
|
21
21
|
}
|