@pkcprotocol/pkc-js 0.0.80 → 0.0.82
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/README.md +3 -1
- package/dist/browser/clients/base-client-manager.js +19 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +3 -0
- package/dist/browser/community/schema.d.ts +24 -0
- package/dist/browser/community/schema.js +6 -1
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/errors.d.ts +10 -1
- package/dist/browser/errors.js +10 -1
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pages/pages.js +8 -0
- package/dist/browser/pages/pages.js.map +1 -1
- package/dist/browser/pages/schema.d.ts +4 -0
- package/dist/browser/pages/util.d.ts +2 -0
- package/dist/browser/pages/util.js +23 -3
- package/dist/browser/pages/util.js.map +1 -1
- package/dist/browser/pkc/pkc.d.ts +3 -2
- package/dist/browser/pkc/pkc.js +37 -24
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment-client-manager.js +22 -4
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/browser/publications/comment/comment.d.ts +2 -1
- package/dist/browser/publications/comment/comment.js +29 -6
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/comment/crosspost-depth.d.ts +5 -0
- package/dist/browser/publications/comment/crosspost-depth.js +75 -0
- package/dist/browser/publications/comment/crosspost-depth.js.map +1 -0
- package/dist/browser/publications/comment/crosspost-runtime.d.ts +30 -0
- package/dist/browser/publications/comment/crosspost-runtime.js +133 -0
- package/dist/browser/publications/comment/crosspost-runtime.js.map +1 -0
- package/dist/browser/publications/comment/schema.d.ts +20 -2
- package/dist/browser/publications/comment/schema.js +21 -10
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/publications/comment/types.d.ts +10 -0
- package/dist/browser/publications/community-edit/schema.d.ts +4 -0
- package/dist/browser/publications/publication.d.ts +4 -0
- package/dist/browser/publications/publication.js +80 -5
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/pubsub-messages/schema.d.ts +5 -0
- package/dist/browser/rpc/src/index.js +14 -2
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/browser/setup-kubo-http-routers.d.ts +1 -0
- package/dist/browser/runtime/browser/setup-kubo-http-routers.js +4 -0
- package/dist/browser/runtime/browser/setup-kubo-http-routers.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.js +3 -2
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +15 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.d.ts +3 -2
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js +19 -10
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
- package/dist/browser/runtime/node/community/page-generator.d.ts +2 -0
- package/dist/browser/runtime/node/setup-kubo-http-routers.d.ts +2 -0
- package/dist/browser/runtime/node/{setup-kubo-address-rewriter-and-http-router.js → setup-kubo-http-routers.js} +54 -112
- package/dist/browser/runtime/node/setup-kubo-http-routers.js.map +1 -0
- package/dist/browser/schema/schema-util.d.ts +17 -0
- package/dist/browser/schema/schema-util.js +49 -5
- package/dist/browser/schema/schema-util.js.map +1 -1
- package/dist/browser/signer/signatures.d.ts +1 -10
- package/dist/browser/signer/signatures.js +83 -0
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +6 -0
- package/dist/browser/util.d.ts +3 -4
- package/dist/browser/util.js +7 -3
- package/dist/browser/util.js.map +1 -1
- package/dist/browser/version.js +1 -1
- package/dist/bundled/bundle-manifest.json +78 -93
- package/dist/bundled/chunks/{helia-for-pkc-BsYWQ7qS.js → helia-for-pkc-CQY3-UYD.js} +31 -31
- package/dist/bundled/chunks/{local-community-EqWKTLxr.js → local-community-AZAEiiht.js} +1 -1
- package/dist/bundled/chunks/{local-community-CHzhypCp.js → local-community-DRm3r1-Y.js} +16 -6
- package/dist/bundled/chunks/{node-4qAZNuJG.js → node-B1J8psGZ.js} +380 -2372
- package/dist/bundled/chunks/{rpc-local-community-Cog5rZLG.js → rpc-local-community-0XmKyOdO.js} +298 -580
- package/dist/bundled/chunks/{schema-Iavj-cRD.js → schema-BUUhufdT.js} +26 -11
- package/dist/bundled/chunks/{util-CfSUfLkV.js → util-Cct7-RT3.js} +1 -1
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +13 -5
- package/dist/node/clients/base-client-manager.js +19 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/node/clients/rpc-client/schema.d.ts +3 -0
- package/dist/node/community/schema.d.ts +24 -0
- package/dist/node/community/schema.js +6 -1
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/errors.d.ts +10 -1
- package/dist/node/errors.js +10 -1
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pages/pages.js +8 -0
- package/dist/node/pages/pages.js.map +1 -1
- package/dist/node/pages/schema.d.ts +4 -0
- package/dist/node/pages/util.d.ts +2 -0
- package/dist/node/pages/util.js +23 -3
- package/dist/node/pages/util.js.map +1 -1
- package/dist/node/pkc/pkc.d.ts +3 -2
- package/dist/node/pkc/pkc.js +37 -24
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment-client-manager.js +22 -4
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/node/publications/comment/comment.d.ts +2 -1
- package/dist/node/publications/comment/comment.js +29 -6
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/comment/crosspost-depth.d.ts +5 -0
- package/dist/node/publications/comment/crosspost-depth.js +75 -0
- package/dist/node/publications/comment/crosspost-depth.js.map +1 -0
- package/dist/node/publications/comment/crosspost-runtime.d.ts +30 -0
- package/dist/node/publications/comment/crosspost-runtime.js +133 -0
- package/dist/node/publications/comment/crosspost-runtime.js.map +1 -0
- package/dist/node/publications/comment/schema.d.ts +20 -2
- package/dist/node/publications/comment/schema.js +21 -10
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/publications/comment/types.d.ts +10 -0
- package/dist/node/publications/community-edit/schema.d.ts +4 -0
- package/dist/node/publications/publication.d.ts +4 -0
- package/dist/node/publications/publication.js +80 -5
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/pubsub-messages/schema.d.ts +5 -0
- package/dist/node/rpc/src/index.js +14 -2
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/browser/setup-kubo-http-routers.d.ts +1 -0
- package/dist/node/runtime/browser/setup-kubo-http-routers.js +4 -0
- package/dist/node/runtime/browser/setup-kubo-http-routers.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.js +3 -2
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-validation.js +15 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.d.ts +3 -2
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js +19 -10
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
- package/dist/node/runtime/node/community/page-generator.d.ts +2 -0
- package/dist/node/runtime/node/setup-kubo-http-routers.d.ts +2 -0
- package/dist/node/runtime/node/{setup-kubo-address-rewriter-and-http-router.js → setup-kubo-http-routers.js} +54 -112
- package/dist/node/runtime/node/setup-kubo-http-routers.js.map +1 -0
- package/dist/node/schema/schema-util.d.ts +17 -0
- package/dist/node/schema/schema-util.js +49 -5
- package/dist/node/schema/schema-util.js.map +1 -1
- package/dist/node/signer/signatures.d.ts +1 -10
- package/dist/node/signer/signatures.js +83 -0
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +6 -0
- package/dist/node/util.d.ts +3 -4
- package/dist/node/util.js +7 -3
- package/dist/node/util.js.map +1 -1
- package/dist/node/version.js +1 -1
- package/package.json +2 -2
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +0 -1
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +0 -4
- package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
- package/dist/browser/runtime/node/address-rewriter-db.d.ts +0 -33
- package/dist/browser/runtime/node/address-rewriter-db.js +0 -156
- package/dist/browser/runtime/node/address-rewriter-db.js.map +0 -1
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +0 -47
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +0 -534
- package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +0 -1
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +0 -4
- package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +0 -1
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +0 -4
- package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
- package/dist/node/runtime/node/address-rewriter-db.d.ts +0 -33
- package/dist/node/runtime/node/address-rewriter-db.js +0 -156
- package/dist/node/runtime/node/address-rewriter-db.js.map +0 -1
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +0 -47
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +0 -534
- package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +0 -1
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +0 -4
- package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
- package/dist/bundled/chunks/{src-BEjAH2gY.js → src-WLgFbUwZ.js} +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as n$1, B as isIpfsCid, Cr as setErrorMap, Ct as findUpdatingCommunity, D as deepMergeRuntimeFields, Dn as CommentUpdateSchema, Dt as refreshTrackedCommentAliases, E as createAbortError, Et as listUpdatingCommunities, Fr as parsedType, H as isIpns, Ir as stringifyPrimitive, It as require_sha256, L as hideClassPrivateProps, Lt as TimeoutError, Pr as joinValues, Pt as untrackUpdatingComment, Q as isStringDomain, Qt as CommunityAnchorSchema, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, St as findUpdatingComment, Tt as listUpdatingComments, Zn as n$2, _t as timestamp, a as ChallengeRequestMessageSchema, ar as r, b as areEquivalentCommunityAddresses, br as logger_default, ct as resolveWhenPredicateIsTrue, fr as require_retry, ft as shortifyAddress, jt as trackUpdatingComment, k as doesDomainAddressHaveCapitalLetter, ln as PubsubTopicSchema, mt as sleepUntilTimeoutOrAbort, nr as e, ot as removeUndefinedValuesRecursively, pr as FailedToFetchCommentIpfsFromGatewaysError, pt as shortifyCid, r as ChallengeMessageSchema, rn as CommunityIpfsSchema, rr as e$1, s as ChallengeVerificationMessageSchema, st as replaceXWithY, t as ChallengeAnswerMessageSchema, tr as t$1, ut as retryKuboIpfsAdd, vr as PKCError, vt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, wn as CommentUpdateForChallengeVerificationSchema, wt as listStartedCommunities,
|
|
3
|
-
import { $ as
|
|
4
|
-
import { o as getHeliaDebugContext } from "./util-
|
|
2
|
+
import { $n as n$1, B as isIpfsCid, Cr as setErrorMap, Ct as findUpdatingCommunity, D as deepMergeRuntimeFields, Dn as CommentUpdateSchema, Dt as refreshTrackedCommentAliases, E as createAbortError, Et as listUpdatingCommunities, Fr as parsedType, H as isIpns, Ir as stringifyPrimitive, It as require_sha256, L as hideClassPrivateProps, Lt as TimeoutError, Pr as joinValues, Pt as untrackUpdatingComment, Q as isStringDomain, Qt as CommunityAnchorSchema, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, St as findUpdatingComment, Tt as listUpdatingComments, Zn as n$2, _t as timestamp, a as ChallengeRequestMessageSchema, ar as r, b as areEquivalentCommunityAddresses, br as logger_default, ct as resolveWhenPredicateIsTrue, fr as require_retry, ft as shortifyAddress, jt as trackUpdatingComment, k as doesDomainAddressHaveCapitalLetter, ln as PubsubTopicSchema, mt as sleepUntilTimeoutOrAbort, nr as e, ot as removeUndefinedValuesRecursively, pr as FailedToFetchCommentIpfsFromGatewaysError, pt as shortifyCid, r as ChallengeMessageSchema, rn as CommunityIpfsSchema, rr as e$1, s as ChallengeVerificationMessageSchema, st as replaceXWithY, t as ChallengeAnswerMessageSchema, tr as t$1, ut as retryKuboIpfsAdd, vr as PKCError, vt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, wn as CommentUpdateForChallengeVerificationSchema, wt as listStartedCommunities, xt as findStartedCommunity, y as version_default, yn as CommentIpfsSchema, yr as messages, z as isAbortError } from "./schema-BUUhufdT.js";
|
|
3
|
+
import { $ as applyNameResolvedCacheToCrosspost, At as verifyCommentModeration, B as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Bn as RpcExportCommunityModLogsParamSchema, Bt as normalizeCreatePublicationAuthor, Cn as parseDecryptedChallengeVerification, Ct as signVote, Dn as parseRpcCommentEventWithPKCErrorIfItFails, Dt as verifyChallengeVerification, E as createKuboRpcClient, En as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, F as listCommunitiesSync, Fn as RpcCidParamSchema, Ft as verifyVote, Gn as RpcFetchCidResultSchema, Gt as normalizeCommunityInputFromCommunity, Hn as RpcExportCommunityParamSchema, Ht as getCommunityAddressFromRecord, I as monitorCommunitiesDirectory, In as RpcCommentRepliesPageParamSchema, It as buildRuntimeAuthor, J as extractCommunityRuntimeFieldsFromParsedPages, Jn as RpcPublishedAnchorRecordResultSchema, Jt as getBufferedPKCAddressFromPublicKey, Kn as RpcPublishAnchorRecordParamSchema, Kt as decode, Ln as RpcCommunityIdentifierParamSchema, Lt as cleanWireAuthor, M as getDefaultDataPath, Mn as RpcAnchorPublishPreparationResultSchema, Mt as verifyCommentUpdate, Nn as RpcAuthorNameParamSchema, On as parseRpcCommentUpdateEventWithPKCErrorIfItFails, Ot as verifyCommentEdit, Pn as RpcCancelExportParamSchema, Pt as verifyCommunityEdit, Q as RepliesPages, Qn as RpcUnsubscribeParamSchema, Rn as RpcCommunityPageParamSchema, Rt as getAuthorNameFromRuntime, Sn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, St as signCommunityEdit, Tn as parseJsonWithPKCErrorIfFails, Tt as verifyChallengeMessage, Un as RpcExportCommunityResultSchema, Ut as getCommunityNameFromWire, V as CommentClientsManager, Vn as RpcExportCommunityModLogsResultSchema, Vt as buildRuntimeCommunityFields, Wn as RpcFetchCidParamSchema, Wt as getCommunityPublicKeyFromWire, Xn as RpcSubscriptionIdResultSchema, Y as findCommentInPageInstanceRecursively, Yn as RpcResolveAuthorNameResultSchema, Z as parseRawPages, Zn as RpcSuccessResultSchema, Zt as getPKCAddressFromPublicKeySync, _ as createAnchorIpnsRecord$1, _t as signCommentEdit, a as pkcJsChallenges, ar as n$3, at as PKCClientsManager, b as encryptEd25519AesGcm, bn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, c as RemoteCommunity, cn as parseCommunityAddressWithPKCErrorIfItFails, cr as t$5, d as decodeRpcChallengeAnswerPubsubMsg, dn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, dt as cleanUpBeforePublishing, en as parseCidStringSchemaWithPKCErrorIfItFails, et as cloneCrosspostForRuntime, f as decodeRpcChallengePubsubMsg, fr as nativeFunctions$2, ft as signChallengeAnswer, g as createSigner, gn as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, gt as signComment, hn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, in as parseCommentIpfsSchemaWithPKCErrorIfItFails, ir as t$3, it as PublicationClientsManager, jn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, jt as verifyCommentPubsubMessage, kn as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, kt as verifyCommentIpfs, lt as PKCTypedEmitter, m as decodeRpcChallengeVerificationPubsubMsg, mn as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, mt as signChallengeRequest, n as RpcRemoteCommunity, o as TrackedInstanceRegistry, on as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ot as InflightFetchManager, p as decodeRpcChallengeRequestPubsubMsg, pn as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, pr as require_undici, qn as RpcPublishChallengeAnswersParamSchema, rn as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, rt as stripNameResolvedFromCrosspost, s as LRUCache, sn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, sr as t$2, t as RpcLocalCommunity, tr as t$4, tt as collectCrosspostAuthorsToResolve, u as KeyvBetterSqlite3, ut as require_lib$1, v as decryptEd25519AesGcm, vt as signCommentModeration, wn as parseDecryptedChallengeWithPKCErrorIfItFails, xn as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, yn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, z as setNativeFunctions$1, zn as RpcEditCommunityParamSchema } from "./rpc-local-community-0XmKyOdO.js";
|
|
4
|
+
import { o as getHeliaDebugContext } from "./util-Cct7-RT3.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -637,17 +637,24 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
637
637
|
if (cachedCommunity) {
|
|
638
638
|
if (!this._pkc._memCaches.communityForPublishing.has(this.communityAddress)) {
|
|
639
639
|
log("The cache of community is stale, we will use the cached and update in the background");
|
|
640
|
-
this._pkc.getCommunity({
|
|
640
|
+
const refresh = this._pkc.getCommunity({
|
|
641
641
|
publicKey: this.communityPublicKey,
|
|
642
642
|
name: this.communityName
|
|
643
|
-
}).catch((e) => log.error("Failed to update cache of community", this.communityAddress, e))
|
|
643
|
+
}).catch((e) => log.error("Failed to update cache of community", this.communityAddress, e)).finally(() => {
|
|
644
|
+
if (this._backgroundCommunityRefresh === refresh) this._backgroundCommunityRefresh = void 0;
|
|
645
|
+
});
|
|
646
|
+
this._backgroundCommunityRefresh = refresh;
|
|
644
647
|
}
|
|
645
648
|
return cachedCommunity;
|
|
646
649
|
} else return this._clientsManager.fetchCommunityForPublishingWithCacheGuard();
|
|
647
650
|
}
|
|
648
651
|
async stop() {
|
|
649
|
-
|
|
650
|
-
|
|
652
|
+
try {
|
|
653
|
+
await this._postSucessOrFailurePublishing();
|
|
654
|
+
} finally {
|
|
655
|
+
if (this._backgroundCommunityRefresh) await this._backgroundCommunityRefresh;
|
|
656
|
+
this._updatePublishingStateWithEmission("stopped");
|
|
657
|
+
}
|
|
651
658
|
}
|
|
652
659
|
_isAllAttemptsExhausted(maxNumOfChallengeExchanges) {
|
|
653
660
|
if (Object.keys(this._challengeExchanges).length !== maxNumOfChallengeExchanges) return false;
|
|
@@ -656,8 +663,26 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
656
663
|
return typeof exchange.challengeRequestPublishTimestamp === "number" && exchange.challengeRequestPublishTimestamp + this._setProviderFailureThresholdSeconds <= timestamp();
|
|
657
664
|
});
|
|
658
665
|
}
|
|
666
|
+
async _abandonProviderIfStoppedWhileSubscribing(providerUrl) {
|
|
667
|
+
if (!this._pkc.destroyed && this.state !== "stopped") return false;
|
|
668
|
+
const log = logger_default("pkc-js:publication:publish:_abandonProviderIfStoppedWhileSubscribing");
|
|
669
|
+
log("Publication was stopped while subscribing to pubsub, will not publish a challenge request", providerUrl);
|
|
670
|
+
try {
|
|
671
|
+
await this._clientsManager.pubsubUnsubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), providerUrl, this._handleChallengeExchange);
|
|
672
|
+
} catch (e) {
|
|
673
|
+
log.error("Failed to undo the pubsub subscription that resolved after being stopped", providerUrl, e);
|
|
674
|
+
}
|
|
675
|
+
this._updatePubsubState("stopped", providerUrl);
|
|
676
|
+
return true;
|
|
677
|
+
}
|
|
678
|
+
_unregisterFromPkcOncePublishWorkSettles() {
|
|
679
|
+
const refresh = this._backgroundCommunityRefresh;
|
|
680
|
+
if (refresh) refresh.finally(() => this._pkc._publishingPublications.delete(this));
|
|
681
|
+
else this._pkc._publishingPublications.delete(this);
|
|
682
|
+
}
|
|
659
683
|
async _postSucessOrFailurePublishing() {
|
|
660
684
|
const log = logger_default("pkc-js:publication:_postSucessOrFailurePublishing");
|
|
685
|
+
this._unregisterFromPkcOncePublishWorkSettles();
|
|
661
686
|
this._setStateWithEmission("stopped");
|
|
662
687
|
if (this._rpcPublishSubscriptionId) {
|
|
663
688
|
try {
|
|
@@ -877,6 +902,7 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
877
902
|
this._updatePubsubState("subscribing-pubsub", providerUrl);
|
|
878
903
|
try {
|
|
879
904
|
await this._clientsManager.pubsubSubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), this._handleChallengeExchange, providerUrl);
|
|
905
|
+
if (await this._abandonProviderIfStoppedWhileSubscribing(providerUrl)) return;
|
|
880
906
|
this._updatePubsubState("publishing-challenge-request", providerUrl);
|
|
881
907
|
await this._clientsManager.pubsubPublishOnProvider(this._communityChallengePubsubExchangeTopic(), challengeRequest, providerUrl);
|
|
882
908
|
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp = timestamp();
|
|
@@ -958,8 +984,17 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
958
984
|
});
|
|
959
985
|
}
|
|
960
986
|
async publish() {
|
|
961
|
-
const log = logger_default("pkc-js:publication:publish");
|
|
962
987
|
this._validatePublicationFields();
|
|
988
|
+
this._pkc._publishingPublications.add(this);
|
|
989
|
+
try {
|
|
990
|
+
return await this._publishAfterRegistering();
|
|
991
|
+
} catch (e) {
|
|
992
|
+
this._unregisterFromPkcOncePublishWorkSettles();
|
|
993
|
+
throw e;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
async _publishAfterRegistering() {
|
|
997
|
+
const log = logger_default("pkc-js:publication:publish");
|
|
963
998
|
this._setStateWithEmission("publishing");
|
|
964
999
|
await this._initCommunity();
|
|
965
1000
|
if (this.raw.unsignedPublicationOptions && !this.raw.pubsubMessageToPublish) await this._signPublicationWithCommunityFields();
|
|
@@ -998,6 +1033,7 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
998
1033
|
this._updatePubsubState("subscribing-pubsub", providerUrl);
|
|
999
1034
|
try {
|
|
1000
1035
|
await this._clientsManager.pubsubSubscribeOnProvider(this._communityChallengePubsubExchangeTopic(), this._handleChallengeExchange, providerUrl);
|
|
1036
|
+
if (await this._abandonProviderIfStoppedWhileSubscribing(providerUrl)) return;
|
|
1001
1037
|
this._updatePubsubState("publishing-challenge-request", providerUrl);
|
|
1002
1038
|
await this._clientsManager.pubsubPublishOnProvider(this._communityChallengePubsubExchangeTopic(), challengeRequest, providerUrl);
|
|
1003
1039
|
this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp = timestamp();
|
|
@@ -1105,6 +1141,7 @@ var Comment = class extends Publication {
|
|
|
1105
1141
|
this.nsfw = o.nsfw;
|
|
1106
1142
|
this.flairs = o.flairs;
|
|
1107
1143
|
this.quotedCids = o.quotedCids;
|
|
1144
|
+
this.crosspost = o.crosspost ? cloneCrosspostForRuntime(o.crosspost) : void 0;
|
|
1108
1145
|
}
|
|
1109
1146
|
_initLocalProps(props) {
|
|
1110
1147
|
this._initPubsubMessageProps(props.comment);
|
|
@@ -1134,6 +1171,10 @@ var Comment = class extends Publication {
|
|
|
1134
1171
|
this._setAuthorNameResolvedFromCache();
|
|
1135
1172
|
}
|
|
1136
1173
|
_setAuthorNameResolvedFromCache() {
|
|
1174
|
+
if (this.crosspost) applyNameResolvedCacheToCrosspost({
|
|
1175
|
+
crosspost: this.crosspost,
|
|
1176
|
+
cache: this._pkc._memCaches.nameResolvedCache
|
|
1177
|
+
});
|
|
1137
1178
|
const domain = getAuthorNameFromRuntime(this.author);
|
|
1138
1179
|
if (!domain) return;
|
|
1139
1180
|
const cached = this._pkc._memCaches.nameResolvedCache.get((0, import_sha256.sha256)(domain + this.signature.publicKey));
|
|
@@ -1160,14 +1201,19 @@ var Comment = class extends Publication {
|
|
|
1160
1201
|
});
|
|
1161
1202
|
}
|
|
1162
1203
|
}
|
|
1163
|
-
|
|
1204
|
+
const crosspostAuthors = this.crosspost ? collectCrosspostAuthorsToResolve({ crosspost: this.crosspost }) : [];
|
|
1205
|
+
if (ownAuthor.length === 0 && replyAuthors.length === 0 && crosspostAuthors.length === 0) return;
|
|
1164
1206
|
const previousNameResolved = this.author.nameResolved;
|
|
1165
1207
|
const onResolved = () => {
|
|
1208
|
+
const crosspostChanged = this.crosspost ? applyNameResolvedCacheToCrosspost({
|
|
1209
|
+
crosspost: this.crosspost,
|
|
1210
|
+
cache: this._pkc._memCaches.nameResolvedCache
|
|
1211
|
+
}) : false;
|
|
1166
1212
|
this._setAuthorNameResolvedFromCache();
|
|
1167
1213
|
if (this.replies?.pages) {
|
|
1168
1214
|
for (const page of Object.values(this.replies.pages)) if (page) this.replies._applyNameResolvedCacheToPage(page);
|
|
1169
1215
|
}
|
|
1170
|
-
if (this.author.nameResolved !== previousNameResolved) this.emit("update", this);
|
|
1216
|
+
if (this.author.nameResolved !== previousNameResolved || crosspostChanged) this.emit("update", this);
|
|
1171
1217
|
};
|
|
1172
1218
|
const abortSignal = this._getStopAbortSignal();
|
|
1173
1219
|
if (ownAuthor.length > 0) this._clientsManager.resolveAuthorNamesInBackground({
|
|
@@ -1175,8 +1221,8 @@ var Comment = class extends Publication {
|
|
|
1175
1221
|
onResolved,
|
|
1176
1222
|
abortSignal
|
|
1177
1223
|
});
|
|
1178
|
-
if (replyAuthors.length > 0) this._pkc._clientsManager.resolveAuthorNamesInBackground({
|
|
1179
|
-
authors: replyAuthors,
|
|
1224
|
+
if (replyAuthors.length > 0 || crosspostAuthors.length > 0) this._pkc._clientsManager.resolveAuthorNamesInBackground({
|
|
1225
|
+
authors: [...replyAuthors, ...crosspostAuthors],
|
|
1180
1226
|
onResolved,
|
|
1181
1227
|
abortSignal
|
|
1182
1228
|
});
|
|
@@ -1194,6 +1240,7 @@ var Comment = class extends Publication {
|
|
|
1194
1240
|
this.title = props.title;
|
|
1195
1241
|
this.linkHtmlTagName = props.linkHtmlTagName;
|
|
1196
1242
|
this.quotedCids = props.quotedCids;
|
|
1243
|
+
this.crosspost = props.crosspost ? cloneCrosspostForRuntime(props.crosspost) : void 0;
|
|
1197
1244
|
if ("depth" in props && typeof props.depth === "number") {
|
|
1198
1245
|
this.depth = props.depth;
|
|
1199
1246
|
const postCid = props.postCid ? props.postCid : this.cid && this.depth === 0 ? this.cid : void 0;
|
|
@@ -2493,7 +2540,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
2493
2540
|
//#region node_modules/nofilter/lib/index.js
|
|
2494
2541
|
var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2495
2542
|
const stream$5 = __require("stream");
|
|
2496
|
-
const { Buffer: Buffer$
|
|
2543
|
+
const { Buffer: Buffer$6 } = __require("buffer");
|
|
2497
2544
|
const td = new TextDecoder("utf8", {
|
|
2498
2545
|
fatal: true,
|
|
2499
2546
|
ignoreBOM: true
|
|
@@ -2512,7 +2559,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2512
2559
|
let inpE = null;
|
|
2513
2560
|
switch (typeof input) {
|
|
2514
2561
|
case "object":
|
|
2515
|
-
if (Buffer$
|
|
2562
|
+
if (Buffer$6.isBuffer(input)) inp = input;
|
|
2516
2563
|
else if (input) options = input;
|
|
2517
2564
|
break;
|
|
2518
2565
|
case "string":
|
|
@@ -2593,7 +2640,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2593
2640
|
*/
|
|
2594
2641
|
static concat(list, length) {
|
|
2595
2642
|
if (!Array.isArray(list)) throw new TypeError("list argument must be an Array of NoFilters");
|
|
2596
|
-
if (list.length === 0 || length === 0) return Buffer$
|
|
2643
|
+
if (list.length === 0 || length === 0) return Buffer$6.alloc(0);
|
|
2597
2644
|
if (length == null) length = list.reduce((tot, nf) => {
|
|
2598
2645
|
if (!(nf instanceof NoFilter)) throw new TypeError("list argument must be an Array of NoFilters");
|
|
2599
2646
|
return tot + nf.length;
|
|
@@ -2603,11 +2650,11 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2603
2650
|
const bufs = list.map((nf) => {
|
|
2604
2651
|
if (!(nf instanceof NoFilter)) throw new TypeError("list argument must be an Array of NoFilters");
|
|
2605
2652
|
const buf = nf.slice();
|
|
2606
|
-
if (Buffer$
|
|
2653
|
+
if (Buffer$6.isBuffer(buf)) allObjs = false;
|
|
2607
2654
|
else allBufs = false;
|
|
2608
2655
|
return buf;
|
|
2609
2656
|
});
|
|
2610
|
-
if (allBufs) return Buffer$
|
|
2657
|
+
if (allBufs) return Buffer$6.concat(bufs, length);
|
|
2611
2658
|
if (allObjs) return [].concat(...bufs).slice(0, length);
|
|
2612
2659
|
throw new Error("Concatenating mixed object and byte streams not supported");
|
|
2613
2660
|
}
|
|
@@ -2615,7 +2662,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2615
2662
|
* @ignore
|
|
2616
2663
|
*/
|
|
2617
2664
|
_transform(chunk, encoding, callback) {
|
|
2618
|
-
if (!this._readableState.objectMode && !Buffer$
|
|
2665
|
+
if (!this._readableState.objectMode && !Buffer$6.isBuffer(chunk)) chunk = Buffer$6.from(chunk, encoding);
|
|
2619
2666
|
this.push(chunk);
|
|
2620
2667
|
callback();
|
|
2621
2668
|
}
|
|
@@ -2750,7 +2797,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2750
2797
|
if (this === other) return 0;
|
|
2751
2798
|
const buf1 = this.slice();
|
|
2752
2799
|
const buf2 = other.slice();
|
|
2753
|
-
if (Buffer$
|
|
2800
|
+
if (Buffer$6.isBuffer(buf1) && Buffer$6.isBuffer(buf2)) return buf1.compare(buf2);
|
|
2754
2801
|
throw new Error("Cannot compare streams in object mode");
|
|
2755
2802
|
}
|
|
2756
2803
|
/**
|
|
@@ -2778,9 +2825,9 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2778
2825
|
if (this._readableState.objectMode) return this._bufArray().slice(start, end);
|
|
2779
2826
|
const bufs = this._bufArray();
|
|
2780
2827
|
switch (bufs.length) {
|
|
2781
|
-
case 0: return Buffer$
|
|
2828
|
+
case 0: return Buffer$6.alloc(0);
|
|
2782
2829
|
case 1: return bufs[0].slice(start, end);
|
|
2783
|
-
default: return Buffer$
|
|
2830
|
+
default: return Buffer$6.concat(bufs).slice(start, end);
|
|
2784
2831
|
}
|
|
2785
2832
|
}
|
|
2786
2833
|
/**
|
|
@@ -2807,7 +2854,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2807
2854
|
*/
|
|
2808
2855
|
toJSON() {
|
|
2809
2856
|
const b = this.slice();
|
|
2810
|
-
if (Buffer$
|
|
2857
|
+
if (Buffer$6.isBuffer(b)) return b.toJSON();
|
|
2811
2858
|
return b;
|
|
2812
2859
|
}
|
|
2813
2860
|
/**
|
|
@@ -2823,7 +2870,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2823
2870
|
*/
|
|
2824
2871
|
toString(encoding, start, end) {
|
|
2825
2872
|
const buf = this.slice(start, end);
|
|
2826
|
-
if (!Buffer$
|
|
2873
|
+
if (!Buffer$6.isBuffer(buf)) return JSON.stringify(buf);
|
|
2827
2874
|
if (!encoding || encoding === "utf8") return td.decode(buf);
|
|
2828
2875
|
return buf.toString(encoding);
|
|
2829
2876
|
}
|
|
@@ -2832,7 +2879,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2832
2879
|
*/
|
|
2833
2880
|
[Symbol.for("nodejs.util.inspect.custom")](depth, options) {
|
|
2834
2881
|
const hex = this._bufArray().map((b) => {
|
|
2835
|
-
if (Buffer$
|
|
2882
|
+
if (Buffer$6.isBuffer(b)) return options.stylize(b.toString("hex"), "string");
|
|
2836
2883
|
return JSON.stringify(b);
|
|
2837
2884
|
}).join(", ");
|
|
2838
2885
|
return `${this.constructor.name} [${hex}]`;
|
|
@@ -2860,7 +2907,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2860
2907
|
str = val.toString(16);
|
|
2861
2908
|
}
|
|
2862
2909
|
if (str.length % 2) str = `0${str}`;
|
|
2863
|
-
return this.push(Buffer$
|
|
2910
|
+
return this.push(Buffer$6.from(str, "hex"));
|
|
2864
2911
|
}
|
|
2865
2912
|
/**
|
|
2866
2913
|
* Read a variable-sized JavaScript unsigned BigInt from the stream.
|
|
@@ -2871,7 +2918,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2871
2918
|
*/
|
|
2872
2919
|
readUBigInt(len) {
|
|
2873
2920
|
const b = this.read(len);
|
|
2874
|
-
if (!Buffer$
|
|
2921
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
2875
2922
|
return BigInt(`0x${b.toString("hex")}`);
|
|
2876
2923
|
}
|
|
2877
2924
|
/**
|
|
@@ -2884,7 +2931,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2884
2931
|
*/
|
|
2885
2932
|
readBigInt(len) {
|
|
2886
2933
|
const b = this.read(len);
|
|
2887
|
-
if (!Buffer$
|
|
2934
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
2888
2935
|
let ret = BigInt(`0x${b.toString("hex")}`);
|
|
2889
2936
|
if (b[0] & 128) {
|
|
2890
2937
|
const mask = BigInt(1) << BigInt(b.length) * BigInt(8);
|
|
@@ -2899,7 +2946,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2899
2946
|
* @returns {boolean} True on success.
|
|
2900
2947
|
*/
|
|
2901
2948
|
writeUInt8(value) {
|
|
2902
|
-
const b = Buffer$
|
|
2949
|
+
const b = Buffer$6.from([value]);
|
|
2903
2950
|
return this.push(b);
|
|
2904
2951
|
}
|
|
2905
2952
|
/**
|
|
@@ -2910,7 +2957,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2910
2957
|
* @returns {boolean} True on success.
|
|
2911
2958
|
*/
|
|
2912
2959
|
writeUInt16LE(value) {
|
|
2913
|
-
const b = Buffer$
|
|
2960
|
+
const b = Buffer$6.alloc(2);
|
|
2914
2961
|
b.writeUInt16LE(value);
|
|
2915
2962
|
return this.push(b);
|
|
2916
2963
|
}
|
|
@@ -2922,7 +2969,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2922
2969
|
* @returns {boolean} True on success.
|
|
2923
2970
|
*/
|
|
2924
2971
|
writeUInt16BE(value) {
|
|
2925
|
-
const b = Buffer$
|
|
2972
|
+
const b = Buffer$6.alloc(2);
|
|
2926
2973
|
b.writeUInt16BE(value);
|
|
2927
2974
|
return this.push(b);
|
|
2928
2975
|
}
|
|
@@ -2934,7 +2981,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2934
2981
|
* @returns {boolean} True on success.
|
|
2935
2982
|
*/
|
|
2936
2983
|
writeUInt32LE(value) {
|
|
2937
|
-
const b = Buffer$
|
|
2984
|
+
const b = Buffer$6.alloc(4);
|
|
2938
2985
|
b.writeUInt32LE(value);
|
|
2939
2986
|
return this.push(b);
|
|
2940
2987
|
}
|
|
@@ -2946,7 +2993,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2946
2993
|
* @returns {boolean} True on success.
|
|
2947
2994
|
*/
|
|
2948
2995
|
writeUInt32BE(value) {
|
|
2949
|
-
const b = Buffer$
|
|
2996
|
+
const b = Buffer$6.alloc(4);
|
|
2950
2997
|
b.writeUInt32BE(value);
|
|
2951
2998
|
return this.push(b);
|
|
2952
2999
|
}
|
|
@@ -2957,7 +3004,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2957
3004
|
* @returns {boolean} True on success.
|
|
2958
3005
|
*/
|
|
2959
3006
|
writeInt8(value) {
|
|
2960
|
-
const b = Buffer$
|
|
3007
|
+
const b = Buffer$6.from([value]);
|
|
2961
3008
|
return this.push(b);
|
|
2962
3009
|
}
|
|
2963
3010
|
/**
|
|
@@ -2967,7 +3014,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2967
3014
|
* @returns {boolean} True on success.
|
|
2968
3015
|
*/
|
|
2969
3016
|
writeInt16LE(value) {
|
|
2970
|
-
const b = Buffer$
|
|
3017
|
+
const b = Buffer$6.alloc(2);
|
|
2971
3018
|
b.writeUInt16LE(value);
|
|
2972
3019
|
return this.push(b);
|
|
2973
3020
|
}
|
|
@@ -2978,7 +3025,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2978
3025
|
* @returns {boolean} True on success.
|
|
2979
3026
|
*/
|
|
2980
3027
|
writeInt16BE(value) {
|
|
2981
|
-
const b = Buffer$
|
|
3028
|
+
const b = Buffer$6.alloc(2);
|
|
2982
3029
|
b.writeUInt16BE(value);
|
|
2983
3030
|
return this.push(b);
|
|
2984
3031
|
}
|
|
@@ -2989,7 +3036,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2989
3036
|
* @returns {boolean} True on success.
|
|
2990
3037
|
*/
|
|
2991
3038
|
writeInt32LE(value) {
|
|
2992
|
-
const b = Buffer$
|
|
3039
|
+
const b = Buffer$6.alloc(4);
|
|
2993
3040
|
b.writeUInt32LE(value);
|
|
2994
3041
|
return this.push(b);
|
|
2995
3042
|
}
|
|
@@ -3000,7 +3047,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3000
3047
|
* @returns {boolean} True on success.
|
|
3001
3048
|
*/
|
|
3002
3049
|
writeInt32BE(value) {
|
|
3003
|
-
const b = Buffer$
|
|
3050
|
+
const b = Buffer$6.alloc(4);
|
|
3004
3051
|
b.writeUInt32BE(value);
|
|
3005
3052
|
return this.push(b);
|
|
3006
3053
|
}
|
|
@@ -3011,7 +3058,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3011
3058
|
* @returns {boolean} True on success.
|
|
3012
3059
|
*/
|
|
3013
3060
|
writeFloatLE(value) {
|
|
3014
|
-
const b = Buffer$
|
|
3061
|
+
const b = Buffer$6.alloc(4);
|
|
3015
3062
|
b.writeFloatLE(value);
|
|
3016
3063
|
return this.push(b);
|
|
3017
3064
|
}
|
|
@@ -3022,7 +3069,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3022
3069
|
* @returns {boolean} True on success.
|
|
3023
3070
|
*/
|
|
3024
3071
|
writeFloatBE(value) {
|
|
3025
|
-
const b = Buffer$
|
|
3072
|
+
const b = Buffer$6.alloc(4);
|
|
3026
3073
|
b.writeFloatBE(value);
|
|
3027
3074
|
return this.push(b);
|
|
3028
3075
|
}
|
|
@@ -3033,7 +3080,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3033
3080
|
* @returns {boolean} True on success.
|
|
3034
3081
|
*/
|
|
3035
3082
|
writeDoubleLE(value) {
|
|
3036
|
-
const b = Buffer$
|
|
3083
|
+
const b = Buffer$6.alloc(8);
|
|
3037
3084
|
b.writeDoubleLE(value);
|
|
3038
3085
|
return this.push(b);
|
|
3039
3086
|
}
|
|
@@ -3044,7 +3091,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3044
3091
|
* @returns {boolean} True on success.
|
|
3045
3092
|
*/
|
|
3046
3093
|
writeDoubleBE(value) {
|
|
3047
|
-
const b = Buffer$
|
|
3094
|
+
const b = Buffer$6.alloc(8);
|
|
3048
3095
|
b.writeDoubleBE(value);
|
|
3049
3096
|
return this.push(b);
|
|
3050
3097
|
}
|
|
@@ -3055,7 +3102,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3055
3102
|
* @returns {boolean} True on success.
|
|
3056
3103
|
*/
|
|
3057
3104
|
writeBigInt64LE(value) {
|
|
3058
|
-
const b = Buffer$
|
|
3105
|
+
const b = Buffer$6.alloc(8);
|
|
3059
3106
|
b.writeBigInt64LE(value);
|
|
3060
3107
|
return this.push(b);
|
|
3061
3108
|
}
|
|
@@ -3066,7 +3113,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3066
3113
|
* @returns {boolean} True on success.
|
|
3067
3114
|
*/
|
|
3068
3115
|
writeBigInt64BE(value) {
|
|
3069
|
-
const b = Buffer$
|
|
3116
|
+
const b = Buffer$6.alloc(8);
|
|
3070
3117
|
b.writeBigInt64BE(value);
|
|
3071
3118
|
return this.push(b);
|
|
3072
3119
|
}
|
|
@@ -3077,7 +3124,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3077
3124
|
* @returns {boolean} True on success.
|
|
3078
3125
|
*/
|
|
3079
3126
|
writeBigUInt64LE(value) {
|
|
3080
|
-
const b = Buffer$
|
|
3127
|
+
const b = Buffer$6.alloc(8);
|
|
3081
3128
|
b.writeBigUInt64LE(value);
|
|
3082
3129
|
return this.push(b);
|
|
3083
3130
|
}
|
|
@@ -3088,7 +3135,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3088
3135
|
* @returns {boolean} True on success.
|
|
3089
3136
|
*/
|
|
3090
3137
|
writeBigUInt64BE(value) {
|
|
3091
|
-
const b = Buffer$
|
|
3138
|
+
const b = Buffer$6.alloc(8);
|
|
3092
3139
|
b.writeBigUInt64BE(value);
|
|
3093
3140
|
return this.push(b);
|
|
3094
3141
|
}
|
|
@@ -3099,7 +3146,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3099
3146
|
*/
|
|
3100
3147
|
readUInt8() {
|
|
3101
3148
|
const b = this.read(1);
|
|
3102
|
-
if (!Buffer$
|
|
3149
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3103
3150
|
return b.readUInt8();
|
|
3104
3151
|
}
|
|
3105
3152
|
/**
|
|
@@ -3110,7 +3157,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3110
3157
|
*/
|
|
3111
3158
|
readUInt16LE() {
|
|
3112
3159
|
const b = this.read(2);
|
|
3113
|
-
if (!Buffer$
|
|
3160
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3114
3161
|
return b.readUInt16LE();
|
|
3115
3162
|
}
|
|
3116
3163
|
/**
|
|
@@ -3121,7 +3168,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3121
3168
|
*/
|
|
3122
3169
|
readUInt16BE() {
|
|
3123
3170
|
const b = this.read(2);
|
|
3124
|
-
if (!Buffer$
|
|
3171
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3125
3172
|
return b.readUInt16BE();
|
|
3126
3173
|
}
|
|
3127
3174
|
/**
|
|
@@ -3132,7 +3179,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3132
3179
|
*/
|
|
3133
3180
|
readUInt32LE() {
|
|
3134
3181
|
const b = this.read(4);
|
|
3135
|
-
if (!Buffer$
|
|
3182
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3136
3183
|
return b.readUInt32LE();
|
|
3137
3184
|
}
|
|
3138
3185
|
/**
|
|
@@ -3143,7 +3190,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3143
3190
|
*/
|
|
3144
3191
|
readUInt32BE() {
|
|
3145
3192
|
const b = this.read(4);
|
|
3146
|
-
if (!Buffer$
|
|
3193
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3147
3194
|
return b.readUInt32BE();
|
|
3148
3195
|
}
|
|
3149
3196
|
/**
|
|
@@ -3153,7 +3200,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3153
3200
|
*/
|
|
3154
3201
|
readInt8() {
|
|
3155
3202
|
const b = this.read(1);
|
|
3156
|
-
if (!Buffer$
|
|
3203
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3157
3204
|
return b.readInt8();
|
|
3158
3205
|
}
|
|
3159
3206
|
/**
|
|
@@ -3164,7 +3211,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3164
3211
|
*/
|
|
3165
3212
|
readInt16LE() {
|
|
3166
3213
|
const b = this.read(2);
|
|
3167
|
-
if (!Buffer$
|
|
3214
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3168
3215
|
return b.readInt16LE();
|
|
3169
3216
|
}
|
|
3170
3217
|
/**
|
|
@@ -3175,7 +3222,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3175
3222
|
*/
|
|
3176
3223
|
readInt16BE() {
|
|
3177
3224
|
const b = this.read(2);
|
|
3178
|
-
if (!Buffer$
|
|
3225
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3179
3226
|
return b.readInt16BE();
|
|
3180
3227
|
}
|
|
3181
3228
|
/**
|
|
@@ -3186,7 +3233,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3186
3233
|
*/
|
|
3187
3234
|
readInt32LE() {
|
|
3188
3235
|
const b = this.read(4);
|
|
3189
|
-
if (!Buffer$
|
|
3236
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3190
3237
|
return b.readInt32LE();
|
|
3191
3238
|
}
|
|
3192
3239
|
/**
|
|
@@ -3197,7 +3244,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3197
3244
|
*/
|
|
3198
3245
|
readInt32BE() {
|
|
3199
3246
|
const b = this.read(4);
|
|
3200
|
-
if (!Buffer$
|
|
3247
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3201
3248
|
return b.readInt32BE();
|
|
3202
3249
|
}
|
|
3203
3250
|
/**
|
|
@@ -3208,7 +3255,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3208
3255
|
*/
|
|
3209
3256
|
readFloatLE() {
|
|
3210
3257
|
const b = this.read(4);
|
|
3211
|
-
if (!Buffer$
|
|
3258
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3212
3259
|
return b.readFloatLE();
|
|
3213
3260
|
}
|
|
3214
3261
|
/**
|
|
@@ -3219,7 +3266,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3219
3266
|
*/
|
|
3220
3267
|
readFloatBE() {
|
|
3221
3268
|
const b = this.read(4);
|
|
3222
|
-
if (!Buffer$
|
|
3269
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3223
3270
|
return b.readFloatBE();
|
|
3224
3271
|
}
|
|
3225
3272
|
/**
|
|
@@ -3230,7 +3277,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3230
3277
|
*/
|
|
3231
3278
|
readDoubleLE() {
|
|
3232
3279
|
const b = this.read(8);
|
|
3233
|
-
if (!Buffer$
|
|
3280
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3234
3281
|
return b.readDoubleLE();
|
|
3235
3282
|
}
|
|
3236
3283
|
/**
|
|
@@ -3241,7 +3288,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3241
3288
|
*/
|
|
3242
3289
|
readDoubleBE() {
|
|
3243
3290
|
const b = this.read(8);
|
|
3244
|
-
if (!Buffer$
|
|
3291
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3245
3292
|
return b.readDoubleBE();
|
|
3246
3293
|
}
|
|
3247
3294
|
/**
|
|
@@ -3252,7 +3299,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3252
3299
|
*/
|
|
3253
3300
|
readBigInt64LE() {
|
|
3254
3301
|
const b = this.read(8);
|
|
3255
|
-
if (!Buffer$
|
|
3302
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3256
3303
|
return b.readBigInt64LE();
|
|
3257
3304
|
}
|
|
3258
3305
|
/**
|
|
@@ -3263,7 +3310,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3263
3310
|
*/
|
|
3264
3311
|
readBigInt64BE() {
|
|
3265
3312
|
const b = this.read(8);
|
|
3266
|
-
if (!Buffer$
|
|
3313
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3267
3314
|
return b.readBigInt64BE();
|
|
3268
3315
|
}
|
|
3269
3316
|
/**
|
|
@@ -3274,7 +3321,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3274
3321
|
*/
|
|
3275
3322
|
readBigUInt64LE() {
|
|
3276
3323
|
const b = this.read(8);
|
|
3277
|
-
if (!Buffer$
|
|
3324
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3278
3325
|
return b.readBigUInt64LE();
|
|
3279
3326
|
}
|
|
3280
3327
|
/**
|
|
@@ -3285,7 +3332,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3285
3332
|
*/
|
|
3286
3333
|
readBigUInt64BE() {
|
|
3287
3334
|
const b = this.read(8);
|
|
3288
|
-
if (!Buffer$
|
|
3335
|
+
if (!Buffer$6.isBuffer(b)) return null;
|
|
3289
3336
|
return b.readBigUInt64BE();
|
|
3290
3337
|
}
|
|
3291
3338
|
};
|
|
@@ -3366,7 +3413,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3366
3413
|
//#endregion
|
|
3367
3414
|
//#region node_modules/cbor/lib/utils.js
|
|
3368
3415
|
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3369
|
-
const { Buffer: Buffer$
|
|
3416
|
+
const { Buffer: Buffer$5 } = __require("buffer");
|
|
3370
3417
|
const NoFilter = require_lib();
|
|
3371
3418
|
const stream$4 = __require("stream");
|
|
3372
3419
|
const { NUMBYTES, SHIFT32, BI, SYMS } = require_constants();
|
|
@@ -3392,12 +3439,12 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3392
3439
|
].every((f) => typeof s[f] === "function");
|
|
3393
3440
|
}
|
|
3394
3441
|
exports.isBufferish = function isBufferish(b) {
|
|
3395
|
-
return b && typeof b === "object" && (Buffer$
|
|
3442
|
+
return b && typeof b === "object" && (Buffer$5.isBuffer(b) || b instanceof Uint8Array || b instanceof Uint8ClampedArray || b instanceof ArrayBuffer || b instanceof DataView);
|
|
3396
3443
|
};
|
|
3397
3444
|
exports.bufferishToBuffer = function bufferishToBuffer(b) {
|
|
3398
|
-
if (Buffer$
|
|
3399
|
-
else if (ArrayBuffer.isView(b)) return Buffer$
|
|
3400
|
-
else if (b instanceof ArrayBuffer) return Buffer$
|
|
3445
|
+
if (Buffer$5.isBuffer(b)) return b;
|
|
3446
|
+
else if (ArrayBuffer.isView(b)) return Buffer$5.from(b.buffer, b.byteOffset, b.byteLength);
|
|
3447
|
+
else if (b instanceof ArrayBuffer) return Buffer$5.from(b);
|
|
3401
3448
|
return null;
|
|
3402
3449
|
};
|
|
3403
3450
|
exports.parseCBORint = function parseCBORint(ai, buf) {
|
|
@@ -3415,7 +3462,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3415
3462
|
}
|
|
3416
3463
|
};
|
|
3417
3464
|
exports.writeHalf = function writeHalf(buf, half) {
|
|
3418
|
-
const u32 = Buffer$
|
|
3465
|
+
const u32 = Buffer$5.allocUnsafe(4);
|
|
3419
3466
|
u32.writeFloatBE(half, 0);
|
|
3420
3467
|
const u = u32.readUInt32BE(0);
|
|
3421
3468
|
if ((u & 8191) !== 0) return false;
|
|
@@ -3447,7 +3494,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3447
3494
|
}
|
|
3448
3495
|
};
|
|
3449
3496
|
exports.hex = function hex(s) {
|
|
3450
|
-
return Buffer$
|
|
3497
|
+
return Buffer$5.from(s.replace(/^0x/, ""), "hex");
|
|
3451
3498
|
};
|
|
3452
3499
|
exports.bin = function bin(s) {
|
|
3453
3500
|
s = s.replace(/\s/g, "");
|
|
@@ -3459,7 +3506,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3459
3506
|
start = end;
|
|
3460
3507
|
end += 8;
|
|
3461
3508
|
}
|
|
3462
|
-
return Buffer$
|
|
3509
|
+
return Buffer$5.from(chunks);
|
|
3463
3510
|
};
|
|
3464
3511
|
exports.arrayEqual = function arrayEqual(a, b) {
|
|
3465
3512
|
if (a == null && b == null) return true;
|
|
@@ -3951,7 +3998,7 @@ var require_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3951
3998
|
const utils = require_utils();
|
|
3952
3999
|
const NoFilter = require_lib();
|
|
3953
4000
|
const { MT, NUMBYTES, SYMS, BI } = require_constants();
|
|
3954
|
-
const { Buffer: Buffer$
|
|
4001
|
+
const { Buffer: Buffer$4 } = __require("buffer");
|
|
3955
4002
|
const COUNT = Symbol("count");
|
|
3956
4003
|
const MAJOR = Symbol("major type");
|
|
3957
4004
|
const ERROR = Symbol("error");
|
|
@@ -4300,7 +4347,7 @@ var require_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4300
4347
|
if (this.max_depth >= 0 && depth > this.max_depth) throw new Error(`Maximum depth ${this.max_depth} exceeded`);
|
|
4301
4348
|
const [octet] = yield 1;
|
|
4302
4349
|
if (!this.running) {
|
|
4303
|
-
this.bs.unshift(Buffer$
|
|
4350
|
+
this.bs.unshift(Buffer$4.from([octet]));
|
|
4304
4351
|
throw new UnexpectedDataError(octet);
|
|
4305
4352
|
}
|
|
4306
4353
|
const mt = octet >> 5;
|
|
@@ -4348,7 +4395,7 @@ var require_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4348
4395
|
case 0:
|
|
4349
4396
|
this.emit("start-string", mt, val, parent_major, parent_length);
|
|
4350
4397
|
if (mt === MT.UTF8_STRING) val = "";
|
|
4351
|
-
else val = this.preferWeb ? new Uint8Array(0) : Buffer$
|
|
4398
|
+
else val = this.preferWeb ? new Uint8Array(0) : Buffer$4.allocUnsafe(0);
|
|
4352
4399
|
break;
|
|
4353
4400
|
case -1:
|
|
4354
4401
|
this.emit("start", mt, SYMS.STREAM, parent_major, parent_length);
|
|
@@ -4491,7 +4538,7 @@ var require_commented = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4491
4538
|
const Decoder = require_decoder();
|
|
4492
4539
|
const NoFilter = require_lib();
|
|
4493
4540
|
const { MT, NUMBYTES, SYMS } = require_constants();
|
|
4494
|
-
const { Buffer: Buffer$
|
|
4541
|
+
const { Buffer: Buffer$3 } = __require("buffer");
|
|
4495
4542
|
function plural(c) {
|
|
4496
4543
|
if (c > 1) return "s";
|
|
4497
4544
|
return "";
|
|
@@ -4773,7 +4820,7 @@ var require_commented = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4773
4820
|
break;
|
|
4774
4821
|
}
|
|
4775
4822
|
const str = utils.cborValueToString(val, -Infinity);
|
|
4776
|
-
if (typeof val === "string" || Buffer$
|
|
4823
|
+
if (typeof val === "string" || Buffer$3.isBuffer(val)) {
|
|
4777
4824
|
if (val.length > 0) {
|
|
4778
4825
|
this.push(str);
|
|
4779
4826
|
this.push("\n");
|
|
@@ -5033,7 +5080,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5033
5080
|
const NoFilter = require_lib();
|
|
5034
5081
|
const utils = require_utils();
|
|
5035
5082
|
const { MT, NUMBYTES, SHIFT32, SIMPLE, SYMS, TAG, BI } = require_constants();
|
|
5036
|
-
const { Buffer: Buffer$
|
|
5083
|
+
const { Buffer: Buffer$2 } = __require("buffer");
|
|
5037
5084
|
const HALF = MT.SIMPLE_FLOAT << 5 | NUMBYTES.TWO;
|
|
5038
5085
|
const FLOAT = MT.SIMPLE_FLOAT << 5 | NUMBYTES.FOUR;
|
|
5039
5086
|
const DOUBLE = MT.SIMPLE_FLOAT << 5 | NUMBYTES.EIGHT;
|
|
@@ -5041,11 +5088,11 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5041
5088
|
const FALSE = MT.SIMPLE_FLOAT << 5 | SIMPLE.FALSE;
|
|
5042
5089
|
const UNDEFINED = MT.SIMPLE_FLOAT << 5 | SIMPLE.UNDEFINED;
|
|
5043
5090
|
const NULL = MT.SIMPLE_FLOAT << 5 | SIMPLE.NULL;
|
|
5044
|
-
const BREAK = Buffer$
|
|
5045
|
-
const BUF_NAN = Buffer$
|
|
5046
|
-
const BUF_INF_NEG = Buffer$
|
|
5047
|
-
const BUF_INF_POS = Buffer$
|
|
5048
|
-
const BUF_NEG_ZERO = Buffer$
|
|
5091
|
+
const BREAK = Buffer$2.from([255]);
|
|
5092
|
+
const BUF_NAN = Buffer$2.from("f97e00", "hex");
|
|
5093
|
+
const BUF_INF_NEG = Buffer$2.from("f9fc00", "hex");
|
|
5094
|
+
const BUF_INF_POS = Buffer$2.from("f97c00", "hex");
|
|
5095
|
+
const BUF_NEG_ZERO = Buffer$2.from("f98000", "hex");
|
|
5049
5096
|
/**
|
|
5050
5097
|
* Generate the CBOR for a value. If you are using this, you'll either need
|
|
5051
5098
|
* to call {@link Encoder.write} with a Buffer, or look into the internals of
|
|
@@ -5195,7 +5242,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5195
5242
|
* @ignore
|
|
5196
5243
|
*/
|
|
5197
5244
|
_pushUInt8(val) {
|
|
5198
|
-
const b = Buffer$
|
|
5245
|
+
const b = Buffer$2.allocUnsafe(1);
|
|
5199
5246
|
b.writeUInt8(val, 0);
|
|
5200
5247
|
return this.push(b);
|
|
5201
5248
|
}
|
|
@@ -5205,7 +5252,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5205
5252
|
* @ignore
|
|
5206
5253
|
*/
|
|
5207
5254
|
_pushUInt16BE(val) {
|
|
5208
|
-
const b = Buffer$
|
|
5255
|
+
const b = Buffer$2.allocUnsafe(2);
|
|
5209
5256
|
b.writeUInt16BE(val, 0);
|
|
5210
5257
|
return this.push(b);
|
|
5211
5258
|
}
|
|
@@ -5215,7 +5262,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5215
5262
|
* @ignore
|
|
5216
5263
|
*/
|
|
5217
5264
|
_pushUInt32BE(val) {
|
|
5218
|
-
const b = Buffer$
|
|
5265
|
+
const b = Buffer$2.allocUnsafe(4);
|
|
5219
5266
|
b.writeUInt32BE(val, 0);
|
|
5220
5267
|
return this.push(b);
|
|
5221
5268
|
}
|
|
@@ -5225,7 +5272,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5225
5272
|
* @ignore
|
|
5226
5273
|
*/
|
|
5227
5274
|
_pushFloatBE(val) {
|
|
5228
|
-
const b = Buffer$
|
|
5275
|
+
const b = Buffer$2.allocUnsafe(4);
|
|
5229
5276
|
b.writeFloatBE(val, 0);
|
|
5230
5277
|
return this.push(b);
|
|
5231
5278
|
}
|
|
@@ -5235,7 +5282,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5235
5282
|
* @ignore
|
|
5236
5283
|
*/
|
|
5237
5284
|
_pushDoubleBE(val) {
|
|
5238
|
-
const b = Buffer$
|
|
5285
|
+
const b = Buffer$2.allocUnsafe(8);
|
|
5239
5286
|
b.writeDoubleBE(val, 0);
|
|
5240
5287
|
return this.push(b);
|
|
5241
5288
|
}
|
|
@@ -5265,7 +5312,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5265
5312
|
*/
|
|
5266
5313
|
_pushFloat(obj) {
|
|
5267
5314
|
if (this.canonical) {
|
|
5268
|
-
const b2 = Buffer$
|
|
5315
|
+
const b2 = Buffer$2.allocUnsafe(2);
|
|
5269
5316
|
if (utils.writeHalf(b2, obj)) return this._pushUInt8(HALF) && this.push(b2);
|
|
5270
5317
|
}
|
|
5271
5318
|
if (Math.fround(obj) === obj) return this._pushUInt8(FLOAT) && this._pushFloatBE(obj);
|
|
@@ -5329,7 +5376,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5329
5376
|
* @ignore
|
|
5330
5377
|
*/
|
|
5331
5378
|
_pushString(obj) {
|
|
5332
|
-
const len = Buffer$
|
|
5379
|
+
const len = Buffer$2.byteLength(obj, "utf8");
|
|
5333
5380
|
return this._pushInt(len, MT.UTF8_STRING) && this.push(obj, "utf8");
|
|
5334
5381
|
}
|
|
5335
5382
|
/**
|
|
@@ -5391,7 +5438,7 @@ var require_encoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5391
5438
|
}
|
|
5392
5439
|
let str = obj.toString(16);
|
|
5393
5440
|
if (str.length % 2) str = `0${str}`;
|
|
5394
|
-
const buf = Buffer$
|
|
5441
|
+
const buf = Buffer$2.from(str, "hex");
|
|
5395
5442
|
return this._pushTag(tag) && Encoder._pushBuffer(this, buf);
|
|
5396
5443
|
}
|
|
5397
5444
|
/**
|
|
@@ -5675,7 +5722,7 @@ Call removeLoopDetectors before resuming.`);
|
|
|
5675
5722
|
8: 3
|
|
5676
5723
|
}[sz];
|
|
5677
5724
|
if (!gen._pushTag(typ)) return false;
|
|
5678
|
-
return Encoder._pushBuffer(gen, Buffer$
|
|
5725
|
+
return Encoder._pushBuffer(gen, Buffer$2.from(obj.buffer, obj.byteOffset, obj.byteLength));
|
|
5679
5726
|
}
|
|
5680
5727
|
/**
|
|
5681
5728
|
* @param {Encoder} gen Encoder.
|
|
@@ -5684,7 +5731,7 @@ Call removeLoopDetectors before resuming.`);
|
|
|
5684
5731
|
* @ignore
|
|
5685
5732
|
*/
|
|
5686
5733
|
static _pushArrayBuffer(gen, obj) {
|
|
5687
|
-
return Encoder._pushBuffer(gen, Buffer$
|
|
5734
|
+
return Encoder._pushBuffer(gen, Buffer$2.from(obj));
|
|
5688
5735
|
}
|
|
5689
5736
|
/**
|
|
5690
5737
|
* Encode the given object with indefinite length. There are apparently
|
|
@@ -5792,7 +5839,7 @@ Call removeLoopDetectors before resuming.`);
|
|
|
5792
5839
|
const enc = new Encoder(options);
|
|
5793
5840
|
enc.on("data", (buf) => bufs.push(buf));
|
|
5794
5841
|
enc.on("error", reject);
|
|
5795
|
-
enc.on("finish", () => resolve(Buffer$
|
|
5842
|
+
enc.on("finish", () => resolve(Buffer$2.concat(bufs)));
|
|
5796
5843
|
enc.pushAny(obj);
|
|
5797
5844
|
enc.end();
|
|
5798
5845
|
});
|
|
@@ -5820,7 +5867,7 @@ Call removeLoopDetectors before resuming.`);
|
|
|
5820
5867
|
Array: Encoder.pushArray,
|
|
5821
5868
|
Date: Encoder._pushDate,
|
|
5822
5869
|
Buffer: Encoder._pushBuffer,
|
|
5823
|
-
[Buffer$
|
|
5870
|
+
[Buffer$2.name]: Encoder._pushBuffer,
|
|
5824
5871
|
Map: Encoder._pushMap,
|
|
5825
5872
|
NoFilter: Encoder._pushNoFilter,
|
|
5826
5873
|
[NoFilter.name]: Encoder._pushNoFilter,
|
|
@@ -5849,7 +5896,7 @@ Call removeLoopDetectors before resuming.`);
|
|
|
5849
5896
|
//#endregion
|
|
5850
5897
|
//#region node_modules/cbor/lib/map.js
|
|
5851
5898
|
var require_map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5852
|
-
const { Buffer: Buffer$
|
|
5899
|
+
const { Buffer: Buffer$1 } = __require("buffer");
|
|
5853
5900
|
const encoder = require_encoder();
|
|
5854
5901
|
const decoder = require_decoder();
|
|
5855
5902
|
const { MT } = require_constants();
|
|
@@ -5979,10 +6026,10 @@ var require_map = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5979
6026
|
encodeCBOR(gen) {
|
|
5980
6027
|
if (!gen._pushInt(this.size, MT.MAP)) return false;
|
|
5981
6028
|
if (gen.canonical) {
|
|
5982
|
-
const entries = Array.from(super.entries()).map((kv) => [Buffer$
|
|
6029
|
+
const entries = Array.from(super.entries()).map((kv) => [Buffer$1.from(kv[0], "base64"), kv[1]]);
|
|
5983
6030
|
entries.sort((a, b) => a[0].compare(b[0]));
|
|
5984
6031
|
for (const kv of entries) if (!(gen.push(kv[0]) && gen.pushAny(kv[1]))) return false;
|
|
5985
|
-
} else for (const kv of super.entries()) if (!(gen.push(Buffer$
|
|
6032
|
+
} else for (const kv of super.entries()) if (!(gen.push(Buffer$1.from(kv[0], "base64")) && gen.pushAny(kv[1]))) return false;
|
|
5986
6033
|
return true;
|
|
5987
6034
|
}
|
|
5988
6035
|
};
|
|
@@ -6051,7 +6098,7 @@ var require_objectRecorder = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
6051
6098
|
var require_sharedValueEncoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
6052
6099
|
const Encoder = require_encoder();
|
|
6053
6100
|
const ObjectRecorder = require_objectRecorder();
|
|
6054
|
-
const { Buffer
|
|
6101
|
+
const { Buffer } = __require("buffer");
|
|
6055
6102
|
module.exports = class SharedValueEncoder extends Encoder {
|
|
6056
6103
|
constructor(opts) {
|
|
6057
6104
|
super(opts);
|
|
@@ -6153,7 +6200,7 @@ var require_sharedValueEncoder = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
6153
6200
|
const enc = new SharedValueEncoder(options);
|
|
6154
6201
|
enc.on("data", () => {});
|
|
6155
6202
|
enc.on("error", reject);
|
|
6156
|
-
enc.on("finish", () => resolve(Buffer
|
|
6203
|
+
enc.on("finish", () => resolve(Buffer.concat(bufs)));
|
|
6157
6204
|
enc.pushAny(obj);
|
|
6158
6205
|
enc.stopRecording();
|
|
6159
6206
|
enc.removeAllListeners("data");
|
|
@@ -6522,2273 +6569,236 @@ var CommentModeration = class extends Publication {
|
|
|
6522
6569
|
}
|
|
6523
6570
|
};
|
|
6524
6571
|
//#endregion
|
|
6525
|
-
//#region
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6572
|
+
//#region dist/node/runtime/node/setup-kubo-http-routers.js
|
|
6573
|
+
function _mergeRouterConfigs(existingConfig, newConfig) {
|
|
6574
|
+
if (!existingConfig?.Routers) return newConfig;
|
|
6575
|
+
const existingRoutersByEndpoint = /* @__PURE__ */ new Map();
|
|
6576
|
+
Object.entries(existingConfig.Routers).forEach(([routerName, router]) => {
|
|
6577
|
+
if (router.Parameters?.Endpoint) existingRoutersByEndpoint.set(router.Parameters.Endpoint, {
|
|
6578
|
+
routerName,
|
|
6579
|
+
router
|
|
6580
|
+
});
|
|
6581
|
+
});
|
|
6582
|
+
const mergedRouters = { ...newConfig.Routers };
|
|
6583
|
+
Object.entries(newConfig.Routers).forEach(([newRouterName, newRouter]) => {
|
|
6584
|
+
if (newRouter.Parameters?.Endpoint) {
|
|
6585
|
+
const existing = existingRoutersByEndpoint.get(newRouter.Parameters.Endpoint);
|
|
6586
|
+
if (existing) mergedRouters[newRouterName] = {
|
|
6587
|
+
...existing.router,
|
|
6588
|
+
...newRouter,
|
|
6589
|
+
Parameters: {
|
|
6590
|
+
...existing.router.Parameters,
|
|
6591
|
+
...newRouter.Parameters
|
|
6592
|
+
}
|
|
6593
|
+
};
|
|
6594
|
+
}
|
|
6595
|
+
});
|
|
6596
|
+
return {
|
|
6597
|
+
...newConfig,
|
|
6598
|
+
Routers: mergedRouters
|
|
6540
6599
|
};
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6600
|
+
}
|
|
6601
|
+
async function _setProvideDhtSweepEnabledOnKuboNode(kuboClient, sweepEnabled, signal) {
|
|
6602
|
+
const log = logger_default("pkc-js:pkc:_init:retrySettingHttpRoutersOnIpfsNodes:setProvideDhtSweepEnabledOnIpfsNode");
|
|
6603
|
+
const configKey = "Provide.DHT.SweepEnabled";
|
|
6604
|
+
const url = `${kuboClient._clientOptions.url}/config?arg=${configKey}&arg=${JSON.stringify(sweepEnabled)}&json=true`;
|
|
6605
|
+
try {
|
|
6606
|
+
await fetch(url, {
|
|
6607
|
+
method: "POST",
|
|
6608
|
+
headers: kuboClient._clientOptions.headers,
|
|
6609
|
+
signal
|
|
6610
|
+
});
|
|
6611
|
+
} catch (e) {
|
|
6612
|
+
const error = new PKCError("ERR_FAILED_TO_SET_CONFIG_ON_KUBO_NODE", {
|
|
6613
|
+
fullUrl: url,
|
|
6614
|
+
actualError: e,
|
|
6615
|
+
kuboEndpoint: kuboClient._clientOptions.url,
|
|
6616
|
+
configKey,
|
|
6617
|
+
configValueToBeSet: sweepEnabled
|
|
6618
|
+
});
|
|
6619
|
+
log.error(e);
|
|
6620
|
+
throw error;
|
|
6546
6621
|
}
|
|
6547
|
-
|
|
6548
|
-
|
|
6622
|
+
log.trace("Succeeded in setting config key", configKey, "on node", kuboClient._clientOptions.url, "to be", sweepEnabled);
|
|
6623
|
+
}
|
|
6624
|
+
async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue, signal) {
|
|
6625
|
+
const log = logger_default("pkc-js:pkc:_init:retrySettingHttpRoutersOnIpfsNodes:setHttpRouterOptionsOnIpfsNode");
|
|
6626
|
+
const routingKey = "Routing";
|
|
6627
|
+
let routingConfigBeforeChanging;
|
|
6628
|
+
try {
|
|
6629
|
+
routingConfigBeforeChanging = await kuboClient._client.config.get(routingKey, { signal });
|
|
6630
|
+
} catch (e) {
|
|
6631
|
+
const error = new PKCError("ERR_FAILED_TO_GET_CONFIG_ON_KUBO_NODE", {
|
|
6632
|
+
actualError: e,
|
|
6633
|
+
kuboEndpoint: kuboClient._clientOptions.url,
|
|
6634
|
+
configKey: routingKey
|
|
6635
|
+
});
|
|
6636
|
+
log.error(e);
|
|
6637
|
+
throw error;
|
|
6549
6638
|
}
|
|
6550
|
-
|
|
6551
|
-
|
|
6639
|
+
const mergedRoutingValue = _mergeRouterConfigs(routingConfigBeforeChanging, routingValue);
|
|
6640
|
+
const url = `${kuboClient._clientOptions.url}/config?arg=${routingKey}&arg=${JSON.stringify(mergedRoutingValue)}&json=true`;
|
|
6641
|
+
try {
|
|
6642
|
+
await fetch(url, {
|
|
6643
|
+
method: "POST",
|
|
6644
|
+
headers: kuboClient._clientOptions.headers,
|
|
6645
|
+
signal
|
|
6646
|
+
});
|
|
6647
|
+
} catch (e) {
|
|
6648
|
+
const error = new PKCError("ERR_FAILED_TO_SET_CONFIG_ON_KUBO_NODE", {
|
|
6649
|
+
fullUrl: url,
|
|
6650
|
+
actualError: e,
|
|
6651
|
+
kuboEndpoint: kuboClient._clientOptions.url,
|
|
6652
|
+
configKey: routingKey,
|
|
6653
|
+
configValueToBeSet: mergedRoutingValue
|
|
6654
|
+
});
|
|
6655
|
+
log.error(e);
|
|
6656
|
+
throw error;
|
|
6552
6657
|
}
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
return deepEqual(a, b);
|
|
6561
|
-
}
|
|
6658
|
+
log.trace("Succeeded in setting config key", routingKey, "on node", kuboClient._clientOptions.url, "to be", mergedRoutingValue);
|
|
6659
|
+
await _setProvideDhtSweepEnabledOnKuboNode(kuboClient, false, signal);
|
|
6660
|
+
const endpointsBefore = Object.values(routingConfigBeforeChanging?.Routers || {}).map((router) => router.Parameters?.Endpoint).filter((endpoint) => endpoint !== void 0);
|
|
6661
|
+
const endpointsAfter = Object.values(mergedRoutingValue.Routers).map((router) => router.Parameters?.Endpoint).filter((endpoint) => endpoint !== void 0);
|
|
6662
|
+
if (!t$3(endpointsBefore.sort(), endpointsAfter.sort())) {
|
|
6663
|
+
log("Config on kubo node has been changed. PKC-js will send shutdown command to node", kuboClient._clientOptions.url, "Clients of pkc-js should restart ipfs node");
|
|
6664
|
+
const shutdownUrl = `${kuboClient._clientOptions.url}/shutdown`;
|
|
6562
6665
|
try {
|
|
6563
|
-
|
|
6666
|
+
await fetch(shutdownUrl, {
|
|
6667
|
+
method: "POST",
|
|
6668
|
+
headers: kuboClient._clientOptions.headers,
|
|
6669
|
+
signal
|
|
6670
|
+
});
|
|
6564
6671
|
} catch (e) {
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
key = ka[i];
|
|
6573
|
-
if (!deepEqual(a[key], b[key])) return false;
|
|
6672
|
+
const error = new PKCError("ERR_FAILED_TO_SHUTDOWN_KUBO_NODE", {
|
|
6673
|
+
actualError: e,
|
|
6674
|
+
kuboEndpoint: kuboClient._clientOptions.url,
|
|
6675
|
+
shutdownUrl
|
|
6676
|
+
});
|
|
6677
|
+
log.error(e);
|
|
6678
|
+
throw error;
|
|
6574
6679
|
}
|
|
6575
|
-
return true;
|
|
6576
6680
|
}
|
|
6577
|
-
}
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
const
|
|
6583
|
-
const
|
|
6584
|
-
const
|
|
6585
|
-
const
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
(?:${v6seg}:){4}(?:(?::${v6seg}){0,1}:${v4}|(?::${v6seg}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
6591
|
-
(?:${v6seg}:){3}(?:(?::${v6seg}){0,2}:${v4}|(?::${v6seg}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
6592
|
-
(?:${v6seg}:){2}(?:(?::${v6seg}){0,3}:${v4}|(?::${v6seg}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
6593
|
-
(?:${v6seg}:){1}(?:(?::${v6seg}){0,4}:${v4}|(?::${v6seg}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
6594
|
-
(?::(?:(?::${v6seg}){0,5}:${v4}|(?::${v6seg}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
6595
|
-
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
6596
|
-
`.replace(/\s*\/\/.*$/gm, "").replace(/\n/g, "").trim();
|
|
6597
|
-
const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
|
|
6598
|
-
const v4exact = new RegExp(`^${v4}$`);
|
|
6599
|
-
const v6exact = new RegExp(`^${v6}$`);
|
|
6600
|
-
const ip = (options) => options && options.exact ? v46Exact : new RegExp(`(?:${b(options)}${v4}${b(options)})|(?:${b(options)}${v6}${b(options)})`, "g");
|
|
6601
|
-
ip.v4 = (options) => options && options.exact ? v4exact : new RegExp(`${b(options)}${v4}${b(options)}`, "g");
|
|
6602
|
-
ip.v6 = (options) => options && options.exact ? v6exact : new RegExp(`${b(options)}${v6}${b(options)}`, "g");
|
|
6603
|
-
module.exports = ip;
|
|
6604
|
-
}));
|
|
6605
|
-
//#endregion
|
|
6606
|
-
//#region node_modules/is2/package.json
|
|
6607
|
-
var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
6608
|
-
module.exports = {
|
|
6609
|
-
"name": "is2",
|
|
6610
|
-
"version": "2.0.9",
|
|
6611
|
-
"description": "A type checking library where each exported function returns either true or false and does not throw. Also added tests.",
|
|
6612
|
-
"license": "MIT",
|
|
6613
|
-
"tags": [
|
|
6614
|
-
"type",
|
|
6615
|
-
"check",
|
|
6616
|
-
"checker",
|
|
6617
|
-
"checking",
|
|
6618
|
-
"utilities",
|
|
6619
|
-
"network",
|
|
6620
|
-
"networking",
|
|
6621
|
-
"credit",
|
|
6622
|
-
"card",
|
|
6623
|
-
"validation"
|
|
6624
|
-
],
|
|
6625
|
-
"keywords": [
|
|
6626
|
-
"type",
|
|
6627
|
-
"check",
|
|
6628
|
-
"checker",
|
|
6629
|
-
"checking",
|
|
6630
|
-
"utilities",
|
|
6631
|
-
"network",
|
|
6632
|
-
"networking",
|
|
6633
|
-
"credit",
|
|
6634
|
-
"card",
|
|
6635
|
-
"validation"
|
|
6636
|
-
],
|
|
6637
|
-
"author": "Enrico Marino <enrico.marino@email.com>",
|
|
6638
|
-
"maintainers": "Edmond Meinfelder <edmond@stdarg.com>, Chris Oyler <christopher.oyler@gmail.com>",
|
|
6639
|
-
"homepage": "http://github.com/stdarg/is2",
|
|
6640
|
-
"repository": {
|
|
6641
|
-
"type": "git",
|
|
6642
|
-
"url": "git@github.com:stdarg/is2.git"
|
|
6643
|
-
},
|
|
6644
|
-
"bugs": { "url": "http://github.com/stdarg/is/issues" },
|
|
6645
|
-
"main": "./index.js",
|
|
6646
|
-
"scripts": { "test": "./node_modules/.bin/mocha -C --reporter list tests.js" },
|
|
6647
|
-
"engines": { "node": ">=v0.10.0" },
|
|
6648
|
-
"dependencies": {
|
|
6649
|
-
"deep-is": "^0.1.3",
|
|
6650
|
-
"ip-regex": "^4.1.0",
|
|
6651
|
-
"is-url": "^1.2.4"
|
|
6681
|
+
}
|
|
6682
|
+
async function setupKuboHttpRouters(pkc) {
|
|
6683
|
+
if (pkc.destroyed) return;
|
|
6684
|
+
if (!Array.isArray(pkc.kuboRpcClientsOptions) || pkc.kuboRpcClientsOptions.length <= 0) throw Error("need ipfs http client to be defined");
|
|
6685
|
+
if (!Array.isArray(pkc.httpRoutersOptions) || pkc.httpRoutersOptions.length <= 0) throw Error("Need http router options to defined");
|
|
6686
|
+
const log = logger_default("pkc-js:node:setupKuboHttpRouters");
|
|
6687
|
+
const httpRouterUrls = [...pkc.httpRoutersOptions].sort();
|
|
6688
|
+
const kuboClients = pkc.clients.kuboRpcClients;
|
|
6689
|
+
const parallelRouters = [];
|
|
6690
|
+
const httpRoutersConfig = {
|
|
6691
|
+
HttpRoutersParallel: {
|
|
6692
|
+
Type: "parallel",
|
|
6693
|
+
Parameters: { Routers: parallelRouters }
|
|
6652
6694
|
},
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6695
|
+
HttpRouterNotSupported: {
|
|
6696
|
+
Type: "http",
|
|
6697
|
+
Parameters: { Endpoint: "http://kubohttprouternotsupported" }
|
|
6656
6698
|
}
|
|
6657
6699
|
};
|
|
6658
|
-
|
|
6700
|
+
for (const [i, httpRouterUrl] of httpRouterUrls.entries()) {
|
|
6701
|
+
const RouterName = `HttpRouter${i + 1}`;
|
|
6702
|
+
httpRoutersConfig[RouterName] = {
|
|
6703
|
+
Type: "http",
|
|
6704
|
+
Parameters: { Endpoint: httpRouterUrl }
|
|
6705
|
+
};
|
|
6706
|
+
parallelRouters[i] = {
|
|
6707
|
+
RouterName,
|
|
6708
|
+
IgnoreErrors: true,
|
|
6709
|
+
Timeout: "10s"
|
|
6710
|
+
};
|
|
6711
|
+
}
|
|
6712
|
+
const routingValue = {
|
|
6713
|
+
Type: "custom",
|
|
6714
|
+
Methods: {
|
|
6715
|
+
"find-providers": { RouterName: "HttpRoutersParallel" },
|
|
6716
|
+
provide: { RouterName: "HttpRoutersParallel" },
|
|
6717
|
+
"find-peers": { RouterName: "HttpRouterNotSupported" },
|
|
6718
|
+
"get-ipns": { RouterName: "HttpRouterNotSupported" },
|
|
6719
|
+
"put-ipns": { RouterName: "HttpRouterNotSupported" }
|
|
6720
|
+
},
|
|
6721
|
+
Routers: httpRoutersConfig
|
|
6722
|
+
};
|
|
6723
|
+
const settingOptionRetryOption = import_retry.operation({
|
|
6724
|
+
forever: true,
|
|
6725
|
+
factor: 2,
|
|
6726
|
+
maxTimeout: 60 * 1e3
|
|
6727
|
+
});
|
|
6728
|
+
const destroySignal = pkc._getDestroyAbortSignal();
|
|
6729
|
+
let removeDestroyListener;
|
|
6730
|
+
await new Promise((resolve) => {
|
|
6731
|
+
const onDestroy = () => {
|
|
6732
|
+
settingOptionRetryOption.stop();
|
|
6733
|
+
resolve();
|
|
6734
|
+
};
|
|
6735
|
+
if (destroySignal.aborted) {
|
|
6736
|
+
onDestroy();
|
|
6737
|
+
return;
|
|
6738
|
+
}
|
|
6739
|
+
destroySignal.addEventListener("abort", onDestroy, { once: true });
|
|
6740
|
+
removeDestroyListener = () => destroySignal.removeEventListener("abort", onDestroy);
|
|
6741
|
+
settingOptionRetryOption.attempt(async () => {
|
|
6742
|
+
if (pkc.destroyed) {
|
|
6743
|
+
resolve();
|
|
6744
|
+
return;
|
|
6745
|
+
}
|
|
6746
|
+
for (const kuboClient of Object.values(kuboClients)) try {
|
|
6747
|
+
await _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue, destroySignal);
|
|
6748
|
+
} catch (e) {
|
|
6749
|
+
settingOptionRetryOption.retry(e);
|
|
6750
|
+
return;
|
|
6751
|
+
}
|
|
6752
|
+
resolve();
|
|
6753
|
+
});
|
|
6754
|
+
});
|
|
6755
|
+
removeDestroyListener?.();
|
|
6756
|
+
settingOptionRetryOption.stop();
|
|
6757
|
+
if (pkc.destroyed) return;
|
|
6758
|
+
log.trace("Set http router config on all kubo nodes", Object.keys(kuboClients), "to", httpRouterUrls);
|
|
6759
|
+
}
|
|
6659
6760
|
//#endregion
|
|
6660
|
-
//#region
|
|
6661
|
-
var
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
* RegExps.
|
|
6668
|
-
* A URL must match #1 and then at least one of #2/#3.
|
|
6669
|
-
* Use two levels of REs to avoid REDOS.
|
|
6670
|
-
*/
|
|
6671
|
-
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
|
|
6672
|
-
var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/;
|
|
6673
|
-
var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
|
|
6674
|
-
/**
|
|
6675
|
-
* Loosely validate a URL `string`.
|
|
6676
|
-
*
|
|
6677
|
-
* @param {String} string
|
|
6678
|
-
* @return {Boolean}
|
|
6679
|
-
*/
|
|
6680
|
-
function isUrl(string) {
|
|
6681
|
-
if (typeof string !== "string") return false;
|
|
6682
|
-
var match = string.match(protocolAndDomainRE);
|
|
6683
|
-
if (!match) return false;
|
|
6684
|
-
var everythingAfterProtocol = match[1];
|
|
6685
|
-
if (!everythingAfterProtocol) return false;
|
|
6686
|
-
if (localhostDomainRE.test(everythingAfterProtocol) || nonLocalhostDomainRE.test(everythingAfterProtocol)) return true;
|
|
6687
|
-
return false;
|
|
6761
|
+
//#region dist/node/publications/community-edit/community-edit.js
|
|
6762
|
+
var CommunityEdit = class extends Publication {
|
|
6763
|
+
constructor(pkc) {
|
|
6764
|
+
super(pkc);
|
|
6765
|
+
this.raw = {};
|
|
6766
|
+
this.publish = this.publish.bind(this);
|
|
6767
|
+
hideClassPrivateProps(this);
|
|
6688
6768
|
}
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
*/
|
|
6723
|
-
is.defined = function(value) {
|
|
6724
|
-
return typeof value !== "undefined";
|
|
6725
|
-
};
|
|
6726
|
-
is.def = is.defined;
|
|
6727
|
-
/**
|
|
6728
|
-
* Tests if is is running under node.js
|
|
6729
|
-
* @return {Boolean} true if the environment has process, process.version and process.versions.
|
|
6730
|
-
*/
|
|
6731
|
-
is.nodejs = function() {
|
|
6732
|
-
return process && process.hasOwnProperty("version") && process.hasOwnProperty("versions");
|
|
6733
|
-
};
|
|
6734
|
-
is.node = is.nodejs;
|
|
6735
|
-
/**
|
|
6736
|
-
* Test if 'value' is undefined.
|
|
6737
|
-
* Aliases: undef, udef
|
|
6738
|
-
* @param {Any} value value to test.
|
|
6739
|
-
* @return {Boolean} true if 'value' is undefined, false otherwise.
|
|
6740
|
-
*/
|
|
6741
|
-
is.undefined = function(value) {
|
|
6742
|
-
return value === void 0;
|
|
6743
|
-
};
|
|
6744
|
-
is.udef = is.undef = is.undefined;
|
|
6745
|
-
/**
|
|
6746
|
-
* Test if 'value' is an array.
|
|
6747
|
-
* Alias: ary, arry
|
|
6748
|
-
* @param {Any} value value to test.
|
|
6749
|
-
* @return {Boolean} true if 'value' is an array, false otherwise.
|
|
6750
|
-
*/
|
|
6751
|
-
is.array = function(value) {
|
|
6752
|
-
return "[object Array]" === toString.call(value);
|
|
6753
|
-
};
|
|
6754
|
-
is.arr = is.ary = is.arry = is.array;
|
|
6755
|
-
/**
|
|
6756
|
-
* Test if 'value' is an arraylike object (i.e. it has a length property with a valid value)
|
|
6757
|
-
* Aliases: arraylike, arryLike, aryLike
|
|
6758
|
-
* @param {Any} value value to test.
|
|
6759
|
-
* @return {Boolean} true if 'value' is an arguments object, false otherwise.
|
|
6760
|
-
*/
|
|
6761
|
-
is.arrayLike = function(value) {
|
|
6762
|
-
if (is.nullOrUndef(value)) return false;
|
|
6763
|
-
return value !== void 0 && owns.call(value, "length") && isFinite(value.length);
|
|
6764
|
-
};
|
|
6765
|
-
is.arrLike = is.arryLike = is.aryLike = is.arraylike = is.arrayLike;
|
|
6766
|
-
/**
|
|
6767
|
-
* Test if 'value' is an arguments object.
|
|
6768
|
-
* Alias: args
|
|
6769
|
-
* @param {Any} value value to test
|
|
6770
|
-
* @return {Boolean} true if 'value' is an arguments object, false otherwise
|
|
6771
|
-
*/
|
|
6772
|
-
is.arguments = function(value) {
|
|
6773
|
-
return "[object Arguments]" === toString.call(value);
|
|
6774
|
-
};
|
|
6775
|
-
is.args = is.arguments;
|
|
6776
|
-
/**
|
|
6777
|
-
* Test if 'value' is a boolean.
|
|
6778
|
-
* Alias: bool
|
|
6779
|
-
* @param {Any} value value to test.
|
|
6780
|
-
* @return {Boolean} true if 'value' is a boolean, false otherwise.
|
|
6781
|
-
*/
|
|
6782
|
-
is.boolean = function(value) {
|
|
6783
|
-
return "[object Boolean]" === toString.call(value);
|
|
6784
|
-
};
|
|
6785
|
-
is.bool = is.boolean;
|
|
6786
|
-
/**
|
|
6787
|
-
* Test if 'value' is an instance of Buffer.
|
|
6788
|
-
* Aliases: instOf, instanceof
|
|
6789
|
-
* @param {Any} value value to test.
|
|
6790
|
-
* @return {Boolean} true if 'value' is an instance of 'constructor'.
|
|
6791
|
-
*/
|
|
6792
|
-
is.buffer = function(value) {
|
|
6793
|
-
return is.nodejs() && Buffer && Buffer.hasOwnProperty("isBuffer") && Buffer.isBuffer(value);
|
|
6794
|
-
};
|
|
6795
|
-
is.buff = is.buf = is.buffer;
|
|
6796
|
-
/**
|
|
6797
|
-
* Test if 'value' is a date.
|
|
6798
|
-
* @param {Any} value value to test.
|
|
6799
|
-
* @return {Boolean} true if 'value' is a date, false otherwise.
|
|
6800
|
-
*/
|
|
6801
|
-
is.date = function(value) {
|
|
6802
|
-
return "[object Date]" === toString.call(value);
|
|
6803
|
-
};
|
|
6804
|
-
/**
|
|
6805
|
-
* Test if 'value' is an error object.
|
|
6806
|
-
* Alias: err
|
|
6807
|
-
* @param value value to test.
|
|
6808
|
-
* @return {Boolean} true if 'value' is an error object, false otherwise.
|
|
6809
|
-
*/
|
|
6810
|
-
is.error = function(value) {
|
|
6811
|
-
return "[object Error]" === toString.call(value);
|
|
6812
|
-
};
|
|
6813
|
-
is.err = is.error;
|
|
6814
|
-
/**
|
|
6815
|
-
* Test if 'value' is false.
|
|
6816
|
-
* @param {Any} value value to test.
|
|
6817
|
-
* @return {Boolean} true if 'value' is false, false otherwise
|
|
6818
|
-
*/
|
|
6819
|
-
is.false = function(value) {
|
|
6820
|
-
return value === false;
|
|
6821
|
-
};
|
|
6822
|
-
/**
|
|
6823
|
-
* Test if 'value' is a function or async function.
|
|
6824
|
-
* Alias: func
|
|
6825
|
-
* @param {Any} value value to test.
|
|
6826
|
-
* @return {Boolean} true if 'value' is a function, false otherwise.
|
|
6827
|
-
*/
|
|
6828
|
-
is.function = function(value) {
|
|
6829
|
-
return is.syncFunction(value) || is.asyncFunction(value);
|
|
6830
|
-
};
|
|
6831
|
-
is.fun = is.func = is.function;
|
|
6832
|
-
/**
|
|
6833
|
-
* Test if 'value' is an async function using `async () => {}` or `async function () {}`.
|
|
6834
|
-
* Alias: func
|
|
6835
|
-
* @param {Any} value value to test.
|
|
6836
|
-
* @return {Boolean} true if 'value' is a function, false otherwise.
|
|
6837
|
-
*/
|
|
6838
|
-
is.asyncFunction = function(value) {
|
|
6839
|
-
return "[object AsyncFunction]" === toString.call(value);
|
|
6840
|
-
};
|
|
6841
|
-
is.asyncFun = is.asyncFunc = is.asyncFunction;
|
|
6842
|
-
/**
|
|
6843
|
-
* Test if 'value' is a synchronous function.
|
|
6844
|
-
* Alias: syncFunc
|
|
6845
|
-
* @param {Any} value value to test.
|
|
6846
|
-
* @return {Boolean} true if 'value' is a function, false otherwise.
|
|
6847
|
-
*/
|
|
6848
|
-
is.syncFunction = function(value) {
|
|
6849
|
-
return "[object Function]" === toString.call(value);
|
|
6850
|
-
};
|
|
6851
|
-
is.syncFun = is.syncFunc = is.syncFunction;
|
|
6852
|
-
/**
|
|
6853
|
-
* Test if 'value' is null.
|
|
6854
|
-
* @param {Any} value to test.
|
|
6855
|
-
* @return {Boolean} true if 'value' is null, false otherwise.
|
|
6856
|
-
*/
|
|
6857
|
-
is.null = function(value) {
|
|
6858
|
-
return value === null;
|
|
6859
|
-
};
|
|
6860
|
-
/**
|
|
6861
|
-
* Test is 'value' is either null or undefined.
|
|
6862
|
-
* Alias: nullOrUndef
|
|
6863
|
-
* @param {Any} value value to test.
|
|
6864
|
-
* @return {Boolean} True if value is null or undefined, false otherwise.
|
|
6865
|
-
*/
|
|
6866
|
-
is.nullOrUndefined = function(value) {
|
|
6867
|
-
return value === null || typeof value === "undefined";
|
|
6868
|
-
};
|
|
6869
|
-
is.nullOrUndef = is.nullOrUndefined;
|
|
6870
|
-
/**
|
|
6871
|
-
* Test if 'value' is a number.
|
|
6872
|
-
* Alias: num
|
|
6873
|
-
* @param {Any} value to test.
|
|
6874
|
-
* @return {Boolean} true if 'value' is a number, false otherwise.
|
|
6875
|
-
*/
|
|
6876
|
-
is.number = function(value) {
|
|
6877
|
-
return "[object Number]" === toString.call(value);
|
|
6878
|
-
};
|
|
6879
|
-
is.num = is.number;
|
|
6880
|
-
/**
|
|
6881
|
-
* Test if 'value' is an object. Note: Arrays, RegExps, Date, Error, etc all return false.
|
|
6882
|
-
* Alias: obj
|
|
6883
|
-
* @param {Any} value to test.
|
|
6884
|
-
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
6885
|
-
*/
|
|
6886
|
-
is.object = function(value) {
|
|
6887
|
-
return "[object Object]" === toString.call(value);
|
|
6888
|
-
};
|
|
6889
|
-
is.obj = is.object;
|
|
6890
|
-
/**
|
|
6891
|
-
* Test if 'value' is a regular expression.
|
|
6892
|
-
* Alias: regexp
|
|
6893
|
-
* @param {Any} value to test.
|
|
6894
|
-
* @return {Boolean} true if 'value' is a regexp, false otherwise.
|
|
6895
|
-
*/
|
|
6896
|
-
is.regExp = function(value) {
|
|
6897
|
-
return "[object RegExp]" === toString.call(value);
|
|
6898
|
-
};
|
|
6899
|
-
is.re = is.regexp = is.regExp;
|
|
6900
|
-
/**
|
|
6901
|
-
* Test if 'value' is a string.
|
|
6902
|
-
* Alias: str
|
|
6903
|
-
* @param {Any} value to test.
|
|
6904
|
-
* @return {Boolean} true if 'value' is a string, false otherwise.
|
|
6905
|
-
*/
|
|
6906
|
-
is.string = function(value) {
|
|
6907
|
-
return "[object String]" === toString.call(value);
|
|
6908
|
-
};
|
|
6909
|
-
is.str = is.string;
|
|
6910
|
-
/**
|
|
6911
|
-
* Test if 'value' is true.
|
|
6912
|
-
* @param {Any} value to test.
|
|
6913
|
-
* @return {Boolean} true if 'value' is true, false otherwise.
|
|
6914
|
-
*/
|
|
6915
|
-
is.true = function(value) {
|
|
6916
|
-
return value === true;
|
|
6917
|
-
};
|
|
6918
|
-
/**
|
|
6919
|
-
* Test if 'value' is a uuid (v1-v5)
|
|
6920
|
-
* @param {Any} value to test.
|
|
6921
|
-
* @return {Boolean} true if 'value is a valid RFC4122 UUID. Case non-specific.
|
|
6922
|
-
*/
|
|
6923
|
-
var uuidRegExp = /* @__PURE__ */ new RegExp("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", "i");
|
|
6924
|
-
is.uuid = function(value) {
|
|
6925
|
-
return uuidRegExp.test(value);
|
|
6926
|
-
};
|
|
6927
|
-
/**
|
|
6928
|
-
* Test if 'value' is equal to 'other'. Works for objects and arrays and will do deep comparisions,
|
|
6929
|
-
* using recursion.
|
|
6930
|
-
* Alias: eq
|
|
6931
|
-
* @param {Any} value value.
|
|
6932
|
-
* @param {Any} other value to compare with.
|
|
6933
|
-
* @return {Boolean} true if 'value' is equal to 'other', false otherwise
|
|
6934
|
-
*/
|
|
6935
|
-
is.equal = function(value, other) {
|
|
6936
|
-
var type = toString.call(value);
|
|
6937
|
-
if (typeof value !== typeof other) return false;
|
|
6938
|
-
if (type !== toString.call(other)) return false;
|
|
6939
|
-
if ("[object Object]" === type || "[object Array]" === type) return deepIs(value, other);
|
|
6940
|
-
else if ("[object Function]" === type) return value.prototype === other.prototype;
|
|
6941
|
-
else if ("[object Date]" === type) return value.getTime() === other.getTime();
|
|
6942
|
-
return value === other;
|
|
6943
|
-
};
|
|
6944
|
-
is.objEquals = is.eq = is.equal;
|
|
6945
|
-
/**
|
|
6946
|
-
* JS Type definitions which cannot host values.
|
|
6947
|
-
* @api private
|
|
6948
|
-
*/
|
|
6949
|
-
var NON_HOST_TYPES = {
|
|
6950
|
-
"boolean": 1,
|
|
6951
|
-
"number": 1,
|
|
6952
|
-
"string": 1,
|
|
6953
|
-
"undefined": 1
|
|
6954
|
-
};
|
|
6955
|
-
/**
|
|
6956
|
-
* Test if 'key' in host is an object. To be hosted means host[value] is an object.
|
|
6957
|
-
* @param {Any} value The value to test.
|
|
6958
|
-
* @param {Any} host Host that may contain value.
|
|
6959
|
-
* @return {Boolean} true if 'value' is hosted by 'host', false otherwise.
|
|
6960
|
-
*/
|
|
6961
|
-
is.hosted = function(value, host) {
|
|
6962
|
-
if (is.nullOrUndef(value)) return false;
|
|
6963
|
-
var type = typeof host[value];
|
|
6964
|
-
return type === "object" ? !!host[value] : !NON_HOST_TYPES[type];
|
|
6965
|
-
};
|
|
6966
|
-
/**
|
|
6967
|
-
* Test if 'value' is an instance of 'constructor'.
|
|
6968
|
-
* Aliases: instOf, instanceof
|
|
6969
|
-
* @param {Any} value value to test.
|
|
6970
|
-
* @return {Boolean} true if 'value' is an instance of 'constructor'.
|
|
6971
|
-
*/
|
|
6972
|
-
is.instanceOf = function(value, constructor) {
|
|
6973
|
-
if (is.nullOrUndef(value) || is.nullOrUndef(constructor)) return false;
|
|
6974
|
-
return value instanceof constructor;
|
|
6975
|
-
};
|
|
6976
|
-
is.instOf = is.instanceof = is.instanceOf;
|
|
6977
|
-
/**
|
|
6978
|
-
* Test if 'value' is an instance type objType.
|
|
6979
|
-
* Aliases: objInstOf, objectinstanceof, instOf, instanceOf
|
|
6980
|
-
* @param {object} objInst an object to testfor type.
|
|
6981
|
-
* @param {object} objType an object type to compare.
|
|
6982
|
-
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
6983
|
-
*/
|
|
6984
|
-
is.objectInstanceOf = function(objInst, objType) {
|
|
6985
|
-
try {
|
|
6986
|
-
return "[object Object]" === toString.call(objInst) && objInst instanceof objType;
|
|
6987
|
-
} catch (err) {
|
|
6988
|
-
return false;
|
|
6989
|
-
}
|
|
6990
|
-
};
|
|
6991
|
-
is.instOf = is.instanceOf = is.objInstOf = is.objectInstanceOf;
|
|
6992
|
-
/**
|
|
6993
|
-
* Test if 'value' is a type of 'type'.
|
|
6994
|
-
* Alias: a
|
|
6995
|
-
* @param value value to test.
|
|
6996
|
-
* @param {String} type The name of the type.
|
|
6997
|
-
* @return {Boolean} true if 'value' is an arguments object, false otherwise.
|
|
6998
|
-
*/
|
|
6999
|
-
is.type = function(value, type) {
|
|
7000
|
-
return typeof value === type;
|
|
7001
|
-
};
|
|
7002
|
-
is.a = is.type;
|
|
7003
|
-
/**
|
|
7004
|
-
* Test if 'value' is empty. To be empty means to be an array, object or string with nothing contained.
|
|
7005
|
-
* @param {Any} value value to test.
|
|
7006
|
-
* @return {Boolean} true if 'value' is empty, false otherwise.
|
|
7007
|
-
*/
|
|
7008
|
-
is.empty = function(value) {
|
|
7009
|
-
var type = toString.call(value);
|
|
7010
|
-
if ("[object Array]" === type || "[object Arguments]" === type) return value.length === 0;
|
|
7011
|
-
if ("[object Object]" === type) {
|
|
7012
|
-
for (var key in value) if (owns.call(value, key)) return false;
|
|
7013
|
-
return true;
|
|
7014
|
-
}
|
|
7015
|
-
if ("[object String]" === type) return value === "";
|
|
7016
|
-
return false;
|
|
7017
|
-
};
|
|
7018
|
-
/**
|
|
7019
|
-
* Test if 'value' is an arguments object that is empty.
|
|
7020
|
-
* Alias: args
|
|
7021
|
-
* @param {Any} value value to test
|
|
7022
|
-
* @return {Boolean} true if 'value' is an arguments object with no args, false otherwise
|
|
7023
|
-
*/
|
|
7024
|
-
is.emptyArguments = function(value) {
|
|
7025
|
-
return "[object Arguments]" === toString.call(value) && value.length === 0;
|
|
7026
|
-
};
|
|
7027
|
-
is.noArgs = is.emptyArgs = is.emptyArguments;
|
|
7028
|
-
/**
|
|
7029
|
-
* Test if 'value' is an array containing no entries.
|
|
7030
|
-
* Aliases: emptyArry, emptyAry
|
|
7031
|
-
* @param {Any} value The value to test.
|
|
7032
|
-
* @return {Boolean} true if 'value' is an array with no elemnets.
|
|
7033
|
-
*/
|
|
7034
|
-
is.emptyArray = function(value) {
|
|
7035
|
-
return "[object Array]" === toString.call(value) && value.length === 0;
|
|
7036
|
-
};
|
|
7037
|
-
is.emptyArry = is.emptyAry = is.emptyArray;
|
|
7038
|
-
/**
|
|
7039
|
-
* Test if 'value' is an empty array(like) object.
|
|
7040
|
-
* Aliases: arguents.empty, args.empty, ary.empty, arry.empty
|
|
7041
|
-
* @param {Any} value value to test.
|
|
7042
|
-
* @return {Boolean} true if 'value' is an empty array(like), false otherwise.
|
|
7043
|
-
*/
|
|
7044
|
-
is.emptyArrayLike = function(value) {
|
|
7045
|
-
return value.length === 0;
|
|
7046
|
-
};
|
|
7047
|
-
is.emptyArrLike = is.emptyArrayLike;
|
|
7048
|
-
/**
|
|
7049
|
-
* Test if 'value' is an empty string.
|
|
7050
|
-
* Alias: emptyStr
|
|
7051
|
-
* @param {Any} value to test.
|
|
7052
|
-
* @return {Boolean} true if 'value' is am empty string, false otherwise.
|
|
7053
|
-
*/
|
|
7054
|
-
is.emptyString = function(value) {
|
|
7055
|
-
return is.string(value) && value.length === 0;
|
|
7056
|
-
};
|
|
7057
|
-
is.emptyStr = is.emptyString;
|
|
7058
|
-
/**
|
|
7059
|
-
* Test if 'value' is an array containing at least 1 entry.
|
|
7060
|
-
* Aliases: nonEmptyArry, nonEmptyAry
|
|
7061
|
-
* @param {Any} value The value to test.
|
|
7062
|
-
* @return {Boolean} true if 'value' is an array with at least 1 value, false otherwise.
|
|
7063
|
-
*/
|
|
7064
|
-
is.nonEmptyArray = function(value) {
|
|
7065
|
-
return "[object Array]" === toString.call(value) && value.length > 0;
|
|
7066
|
-
};
|
|
7067
|
-
is.nonEmptyArr = is.nonEmptyArry = is.nonEmptyAry = is.nonEmptyArray;
|
|
7068
|
-
/**
|
|
7069
|
-
* Test if 'value' is an object with properties. Note: Arrays are objects.
|
|
7070
|
-
* Alias: nonEmptyObj
|
|
7071
|
-
* @param {Any} value to test.
|
|
7072
|
-
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
7073
|
-
*/
|
|
7074
|
-
is.nonEmptyObject = function(value) {
|
|
7075
|
-
return "[object Object]" === toString.call(value) && Object.keys(value).length > 0;
|
|
7076
|
-
};
|
|
7077
|
-
is.nonEmptyObj = is.nonEmptyObject;
|
|
7078
|
-
/**
|
|
7079
|
-
* Test if 'value' is an object with no properties. Note: Arrays are objects.
|
|
7080
|
-
* Alias: nonEmptyObj
|
|
7081
|
-
* @param {Any} value to test.
|
|
7082
|
-
* @return {Boolean} true if 'value' is an object, false otherwise.
|
|
7083
|
-
*/
|
|
7084
|
-
is.emptyObject = function(value) {
|
|
7085
|
-
return "[object Object]" === toString.call(value) && Object.keys(value).length === 0;
|
|
7086
|
-
};
|
|
7087
|
-
is.emptyObj = is.emptyObject;
|
|
7088
|
-
/**
|
|
7089
|
-
* Test if 'value' is a non-empty string.
|
|
7090
|
-
* Alias: nonEmptyStr
|
|
7091
|
-
* @param {Any} value to test.
|
|
7092
|
-
* @return {Boolean} true if 'value' is a non-empty string, false otherwise.
|
|
7093
|
-
*/
|
|
7094
|
-
is.nonEmptyString = function(value) {
|
|
7095
|
-
return is.string(value) && value.length > 0;
|
|
7096
|
-
};
|
|
7097
|
-
is.nonEmptyStr = is.nonEmptyString;
|
|
7098
|
-
/**
|
|
7099
|
-
* Test if 'value' is an even number.
|
|
7100
|
-
* @param {Number} value to test.
|
|
7101
|
-
* @return {Boolean} true if 'value' is an even number, false otherwise.
|
|
7102
|
-
*/
|
|
7103
|
-
is.even = function(value) {
|
|
7104
|
-
return "[object Number]" === toString.call(value) && value % 2 === 0;
|
|
7105
|
-
};
|
|
7106
|
-
/**
|
|
7107
|
-
* Test if 'value' is a decimal number.
|
|
7108
|
-
* Aliases: decimalNumber, decNum
|
|
7109
|
-
* @param {Any} value value to test.
|
|
7110
|
-
* @return {Boolean} true if 'value' is a decimal number, false otherwise.
|
|
7111
|
-
*/
|
|
7112
|
-
is.decimal = function(value) {
|
|
7113
|
-
return "[object Number]" === toString.call(value) && value % 1 !== 0;
|
|
7114
|
-
};
|
|
7115
|
-
is.dec = is.decNum = is.decimal;
|
|
7116
|
-
/**
|
|
7117
|
-
* Test if 'value' is an integer.
|
|
7118
|
-
* Alias: integer
|
|
7119
|
-
* @param {Any} value to test.
|
|
7120
|
-
* @return {Boolean} true if 'value' is an integer, false otherwise.
|
|
7121
|
-
*/
|
|
7122
|
-
is.integer = function(value) {
|
|
7123
|
-
return "[object Number]" === toString.call(value) && value % 1 === 0;
|
|
7124
|
-
};
|
|
7125
|
-
is.int = is.integer;
|
|
7126
|
-
/**
|
|
7127
|
-
* is.nan
|
|
7128
|
-
* Test if `value` is not a number.
|
|
7129
|
-
*
|
|
7130
|
-
* @param {Mixed} value value to test
|
|
7131
|
-
* @return {Boolean} true if `value` is not a number, false otherwise
|
|
7132
|
-
* @api public
|
|
7133
|
-
*/
|
|
7134
|
-
is.notANumber = function(value) {
|
|
7135
|
-
return !is.num(value) || value !== value;
|
|
7136
|
-
};
|
|
7137
|
-
is.nan = is.notANum = is.notANumber;
|
|
7138
|
-
/**
|
|
7139
|
-
* Test if 'value' is an odd number.
|
|
7140
|
-
* @param {Number} value to test.
|
|
7141
|
-
* @return {Boolean} true if 'value' is an odd number, false otherwise.
|
|
7142
|
-
*/
|
|
7143
|
-
is.odd = function(value) {
|
|
7144
|
-
return !is.decimal(value) && "[object Number]" === toString.call(value) && value % 2 !== 0;
|
|
7145
|
-
};
|
|
7146
|
-
is.oddNumber = is.oddNum = is.odd;
|
|
7147
|
-
/**
|
|
7148
|
-
* Test if 'value' is a positive number.
|
|
7149
|
-
* Alias: positiveNum, posNum
|
|
7150
|
-
* @param {Any} value to test.
|
|
7151
|
-
* @return {Boolean} true if 'value' is a number, false otherwise.
|
|
7152
|
-
*/
|
|
7153
|
-
is.positiveNumber = function(value) {
|
|
7154
|
-
return "[object Number]" === toString.call(value) && value > 0;
|
|
7155
|
-
};
|
|
7156
|
-
is.pos = is.positive = is.posNum = is.positiveNum = is.positiveNumber;
|
|
7157
|
-
/**
|
|
7158
|
-
* Test if 'value' is a negative number.
|
|
7159
|
-
* Aliases: negNum, negativeNum
|
|
7160
|
-
* @param {Any} value to test.
|
|
7161
|
-
* @return {Boolean} true if 'value' is a number, false otherwise.
|
|
7162
|
-
*/
|
|
7163
|
-
is.negativeNumber = function(value) {
|
|
7164
|
-
return "[object Number]" === toString.call(value) && value < 0;
|
|
7165
|
-
};
|
|
7166
|
-
is.neg = is.negNum = is.negativeNum = is.negativeNumber;
|
|
7167
|
-
/**
|
|
7168
|
-
* Test if 'value' is a negative integer.
|
|
7169
|
-
* Aliases: negInt, negativeInteger
|
|
7170
|
-
* @param {Any} value to test.
|
|
7171
|
-
* @return {Boolean} true if 'value' is a negative integer, false otherwise.
|
|
7172
|
-
*/
|
|
7173
|
-
is.negativeInteger = function(value) {
|
|
7174
|
-
return "[object Number]" === toString.call(value) && value % 1 === 0 && value < 0;
|
|
7175
|
-
};
|
|
7176
|
-
is.negativeInt = is.negInt = is.negativeInteger;
|
|
7177
|
-
/**
|
|
7178
|
-
* Test if 'value' is a positive integer.
|
|
7179
|
-
* Alias: posInt
|
|
7180
|
-
* @param {Any} value to test.
|
|
7181
|
-
* @return {Boolean} true if 'value' is a positive integer, false otherwise.
|
|
7182
|
-
*/
|
|
7183
|
-
is.positiveInteger = function(value) {
|
|
7184
|
-
return "[object Number]" === toString.call(value) && value % 1 === 0 && value > 0;
|
|
7185
|
-
};
|
|
7186
|
-
is.posInt = is.positiveInt = is.positiveInteger;
|
|
7187
|
-
/**
|
|
7188
|
-
* Test if 'value' is divisible by 'n'.
|
|
7189
|
-
* Alias: divisBy
|
|
7190
|
-
* @param {Number} value value to test.
|
|
7191
|
-
* @param {Number} n dividend.
|
|
7192
|
-
* @return {Boolean} true if 'value' is divisible by 'n', false otherwise.
|
|
7193
|
-
*/
|
|
7194
|
-
is.divisibleBy = function(value, n) {
|
|
7195
|
-
if (value === 0) return false;
|
|
7196
|
-
return "[object Number]" === toString.call(value) && n !== 0 && value % n === 0;
|
|
7197
|
-
};
|
|
7198
|
-
is.divBy = is.divisBy = is.divisibleBy;
|
|
7199
|
-
/**
|
|
7200
|
-
* Test if 'value' is greater than or equal to 'other'.
|
|
7201
|
-
* Aliases: greaterOrEq, greaterOrEqual
|
|
7202
|
-
* @param {Number} value value to test.
|
|
7203
|
-
* @param {Number} other value to compare with.
|
|
7204
|
-
* @return {Boolean} true, if value is greater than or equal to other, false otherwise.
|
|
7205
|
-
*/
|
|
7206
|
-
is.greaterOrEqualTo = function(value, other) {
|
|
7207
|
-
return value >= other;
|
|
7208
|
-
};
|
|
7209
|
-
is.greaterOrEqual = is.ge = is.greaterOrEqualTo;
|
|
7210
|
-
/**
|
|
7211
|
-
* Test if 'value' is greater than 'other'.
|
|
7212
|
-
* Aliases: greaterThan
|
|
7213
|
-
* @param {Number} value value to test.
|
|
7214
|
-
* @param {Number} other value to compare with.
|
|
7215
|
-
* @return {Boolean} true, if value is greater than other, false otherwise.
|
|
7216
|
-
*/
|
|
7217
|
-
is.greaterThan = function(value, other) {
|
|
7218
|
-
return value > other;
|
|
7219
|
-
};
|
|
7220
|
-
is.gt = is.greaterThan;
|
|
7221
|
-
/**
|
|
7222
|
-
* Test if 'value' is less than or equal to 'other'.
|
|
7223
|
-
* Alias: lessThanOrEq, lessThanOrEqual
|
|
7224
|
-
* @param {Number} value value to test
|
|
7225
|
-
* @param {Number} other value to compare with
|
|
7226
|
-
* @return {Boolean} true, if 'value' is less than or equal to 'other', false otherwise.
|
|
7227
|
-
*/
|
|
7228
|
-
is.lessThanOrEqualTo = function(value, other) {
|
|
7229
|
-
return value <= other;
|
|
7230
|
-
};
|
|
7231
|
-
is.lessThanOrEq = is.lessThanOrEqual = is.le = is.lessThanOrEqualTo;
|
|
7232
|
-
/**
|
|
7233
|
-
* Test if 'value' is less than 'other'.
|
|
7234
|
-
* Alias: lessThan
|
|
7235
|
-
* @param {Number} value value to test
|
|
7236
|
-
* @param {Number} other value to compare with
|
|
7237
|
-
* @return {Boolean} true, if 'value' is less than 'other', false otherwise.
|
|
7238
|
-
*/
|
|
7239
|
-
is.lessThan = function(value, other) {
|
|
7240
|
-
return value < other;
|
|
7241
|
-
};
|
|
7242
|
-
is.lt = is.lessThan;
|
|
7243
|
-
/**
|
|
7244
|
-
* Test if 'value' is greater than 'others' values.
|
|
7245
|
-
* Alias: max
|
|
7246
|
-
* @param {Number} value value to test.
|
|
7247
|
-
* @param {Array} others values to compare with.
|
|
7248
|
-
* @return {Boolean} true if 'value' is greater than 'others' values.
|
|
7249
|
-
*/
|
|
7250
|
-
is.maximum = function(value, others) {
|
|
7251
|
-
if (!is.arrayLike(others) || !is.number(value)) return false;
|
|
7252
|
-
var len = others.length;
|
|
7253
|
-
while (--len > -1) if (value < others[len]) return false;
|
|
7254
|
-
return true;
|
|
7255
|
-
};
|
|
7256
|
-
is.max = is.maximum;
|
|
7257
|
-
/**
|
|
7258
|
-
* Test if 'value' is less than 'others' values.
|
|
7259
|
-
* Alias: min
|
|
7260
|
-
* @param {Number} value value to test.
|
|
7261
|
-
* @param {Array} others values to compare with.
|
|
7262
|
-
* @return {Boolean} true if 'value' is less than 'others' values.
|
|
7263
|
-
*/
|
|
7264
|
-
is.minimum = function(value, others) {
|
|
7265
|
-
if (!is.arrayLike(others) || !is.number(value)) return false;
|
|
7266
|
-
var len = others.length;
|
|
7267
|
-
while (--len > -1) if (value > others[len]) return false;
|
|
7268
|
-
return true;
|
|
7269
|
-
};
|
|
7270
|
-
is.min = is.minimum;
|
|
7271
|
-
/**
|
|
7272
|
-
* Test if 'value' is within 'start' and 'finish'.
|
|
7273
|
-
* Alias: withIn
|
|
7274
|
-
* @param {Number} value value to test.
|
|
7275
|
-
* @param {Number} start lower bound.
|
|
7276
|
-
* @param {Number} finish upper bound.
|
|
7277
|
-
* @return {Boolean} true if 'value' is is within 'start' and 'finish', false otherwise.
|
|
7278
|
-
*/
|
|
7279
|
-
is.within = function(value, start, finish) {
|
|
7280
|
-
return value >= start && value <= finish;
|
|
7281
|
-
};
|
|
7282
|
-
is.withIn = is.within;
|
|
7283
|
-
/**
|
|
7284
|
-
* Test if 'value' is within 'precision' decimal places from 'comparitor'.
|
|
7285
|
-
* Alias: closish, near.
|
|
7286
|
-
* @param {Number} value value to test
|
|
7287
|
-
* @param {Number} comparitor value to test 'value' against
|
|
7288
|
-
* @param {Number} precision number of decimals to compare floating points, defaults to 2
|
|
7289
|
-
* @return {Boolean} true if 'value' is within 'precision' decimal places from 'comparitor', false otherwise.
|
|
7290
|
-
*/
|
|
7291
|
-
is.prettyClose = function(value, comparitor, precision) {
|
|
7292
|
-
if (!is.number(value) || !is.number(comparitor)) return false;
|
|
7293
|
-
if (is.defined(precision) && !is.posInt(precision)) return false;
|
|
7294
|
-
if (is.undefined(precision)) precision = 2;
|
|
7295
|
-
return value.toFixed(precision) === comparitor.toFixed(precision);
|
|
7296
|
-
};
|
|
7297
|
-
is.closish = is.near = is.prettyClose;
|
|
7298
|
-
/**
|
|
7299
|
-
* Test if a value is a valid DNS address. eg www.stdarg.com is true while
|
|
7300
|
-
* 127.0.0.1 is false.
|
|
7301
|
-
* @param {Any} value to test if a DNS address.
|
|
7302
|
-
* @return {Boolean} true if a DNS address, false otherwise.
|
|
7303
|
-
* DNS Address is made up of labels separated by '.'
|
|
7304
|
-
* Each label must be between 1 and 63 characters long
|
|
7305
|
-
* The entire hostname (including the delimiting dots) has a maximum of 255 characters.
|
|
7306
|
-
* Hostname may not contain other characters, such as the underscore character (_)
|
|
7307
|
-
* other DNS names may contain the underscore.
|
|
7308
|
-
*/
|
|
7309
|
-
is.dnsAddress = function(value) {
|
|
7310
|
-
if (!is.nonEmptyStr(value)) return false;
|
|
7311
|
-
if (value.length > 255) return false;
|
|
7312
|
-
if (numbersLabel.test(value)) return false;
|
|
7313
|
-
if (!dnsLabel.test(value)) return false;
|
|
7314
|
-
return true;
|
|
7315
|
-
};
|
|
7316
|
-
is.dnsAddr = is.dns = is.dnsAddress;
|
|
7317
|
-
var dnsLabel = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/;
|
|
7318
|
-
var numbersLabel = /^([0-9]|[0-9][0-9\-]{0,61}[0-9])(\.([0-9]|[0-9][0-9\-]{0,61}[0-9]))*$/;
|
|
7319
|
-
/**
|
|
7320
|
-
* Test if value is a valid email address.
|
|
7321
|
-
* @param {Any} value to test if an email address.
|
|
7322
|
-
* @return {Boolean} true if an email address, false otherwise.
|
|
7323
|
-
*/
|
|
7324
|
-
is.emailAddress = function(value) {
|
|
7325
|
-
if (!is.nonEmptyStr(value)) return false;
|
|
7326
|
-
return emailRegexp.test(value);
|
|
7327
|
-
};
|
|
7328
|
-
is.email = is.emailAddr = is.emailAddress;
|
|
7329
|
-
var emailRegexp = /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/;
|
|
7330
|
-
/**
|
|
7331
|
-
* Test if a value is either an IPv4 numeric IP address.
|
|
7332
|
-
* The rules are:
|
|
7333
|
-
* must be a string
|
|
7334
|
-
* length must be 15 characters or less
|
|
7335
|
-
* There must be four octets separated by a '.'
|
|
7336
|
-
* No octet can be less than 0 or greater than 255.
|
|
7337
|
-
* @param {Any} value to test if an ip address.
|
|
7338
|
-
* @return {Boolean} true if an ip address, false otherwise.
|
|
7339
|
-
*/
|
|
7340
|
-
is.ipv4Address = function(value) {
|
|
7341
|
-
if (!is.nonEmptyStr(value)) return false;
|
|
7342
|
-
if (value.length > 15) return false;
|
|
7343
|
-
var octets = value.split(".");
|
|
7344
|
-
if (!is.array(octets) || octets.length !== 4) return false;
|
|
7345
|
-
for (var i = 0; i < octets.length; i++) {
|
|
7346
|
-
var val = parseInt(octets[i], 10);
|
|
7347
|
-
if (isNaN(val)) return false;
|
|
7348
|
-
if (val < 0 || val > 255) return false;
|
|
7349
|
-
}
|
|
7350
|
-
return true;
|
|
7351
|
-
};
|
|
7352
|
-
is.ipv4 = is.ipv4Addr = is.ipv4Address;
|
|
7353
|
-
/**
|
|
7354
|
-
* Test if a value is either an IPv6 numeric IP address.
|
|
7355
|
-
* @param {Any} value to test if an ip address.
|
|
7356
|
-
* @return {Boolean} true if an ip address, false otherwise.
|
|
7357
|
-
*/
|
|
7358
|
-
is.ipv6Address = function(value) {
|
|
7359
|
-
if (!is.nonEmptyStr(value)) return false;
|
|
7360
|
-
return ipRegEx.v6({ extract: true }).test(value);
|
|
7361
|
-
};
|
|
7362
|
-
is.ipv6 = is.ipv6Addr = is.ipv6Address;
|
|
7363
|
-
/**
|
|
7364
|
-
* Test if a value is either an IPv4 or IPv6 numeric IP address.
|
|
7365
|
-
* @param {Any} value to test if an ip address.
|
|
7366
|
-
* @return {Boolean} true if an ip address, false otherwise.
|
|
7367
|
-
*/
|
|
7368
|
-
is.ipAddress = function(value) {
|
|
7369
|
-
if (!is.nonEmptyStr(value)) return false;
|
|
7370
|
-
return is.ipv4Address(value) || is.ipv6Address(value);
|
|
7371
|
-
};
|
|
7372
|
-
is.ip = is.ipAddr = is.ipAddress;
|
|
7373
|
-
/**
|
|
7374
|
-
* Test is a value is a valid ipv4, ipv6 or DNS name.
|
|
7375
|
-
* Aliases: host, hostAddr, hostAddress.
|
|
7376
|
-
* @param {Any} value to test if a host address.
|
|
7377
|
-
* @return {Boolean} true if a host address, false otherwise.
|
|
7378
|
-
*/
|
|
7379
|
-
is.hostAddress = function(value) {
|
|
7380
|
-
if (!is.nonEmptyStr(value)) return false;
|
|
7381
|
-
return is.dns(value) || is.ipv4(value) || is.ipv6(value);
|
|
7382
|
-
};
|
|
7383
|
-
is.host = is.hostIp = is.hostAddr = is.hostAddress;
|
|
7384
|
-
/**
|
|
7385
|
-
* Test if a number is a valid TCP port
|
|
7386
|
-
* @param {Any} value to test if its a valid TCP port
|
|
7387
|
-
*/
|
|
7388
|
-
is.port = function(value) {
|
|
7389
|
-
if (!is.num(value) || is.negativeInt(value) || value > 65535) return false;
|
|
7390
|
-
return true;
|
|
7391
|
-
};
|
|
7392
|
-
/**
|
|
7393
|
-
* Test if a number is a valid TCP port in the range 0-1023.
|
|
7394
|
-
* Alias: is.sysPort.
|
|
7395
|
-
* @param {Any} value to test if its a valid TCP port
|
|
7396
|
-
*/
|
|
7397
|
-
is.systemPort = function(value) {
|
|
7398
|
-
if (is.port(value) && value < 1024) return true;
|
|
7399
|
-
return false;
|
|
7400
|
-
};
|
|
7401
|
-
is.sysPort = is.systemPort;
|
|
7402
|
-
/**
|
|
7403
|
-
* Test if a number is a valid TCP port in the range 1024-65535.
|
|
7404
|
-
* @param {Any} value to test if its a valid TCP port
|
|
7405
|
-
*/
|
|
7406
|
-
is.userPort = function(value) {
|
|
7407
|
-
if (is.port(value) && value > 1023) return true;
|
|
7408
|
-
return false;
|
|
7409
|
-
};
|
|
7410
|
-
/**
|
|
7411
|
-
* Test if a string is a credit card.
|
|
7412
|
-
* From http://en.wikipedia.org/wiki/Luhn_algorithm
|
|
7413
|
-
* @param {String} value to test if a credit card.
|
|
7414
|
-
* @return true if the string is the correct format, false otherwise
|
|
7415
|
-
*/
|
|
7416
|
-
is.creditCardNumber = function(str) {
|
|
7417
|
-
if (!is.str(str)) return false;
|
|
7418
|
-
var ary = str.split("");
|
|
7419
|
-
var i, cnt;
|
|
7420
|
-
for (i = ary.length - 1, cnt = 1; i > -1; i--, cnt++) if (cnt % 2 === 0) ary[i] *= 2;
|
|
7421
|
-
str = ary.join("");
|
|
7422
|
-
var sum = 0;
|
|
7423
|
-
for (i = 0; i < str.length; i++) sum += Math.floor(str[i]);
|
|
7424
|
-
return sum % 10 === 0;
|
|
7425
|
-
};
|
|
7426
|
-
is.creditCard = is.creditCardNum = is.creditCardNumber;
|
|
7427
|
-
/**
|
|
7428
|
-
* Test if card number is an American Express card.
|
|
7429
|
-
* @param {String} the credit card number string to test.
|
|
7430
|
-
* @return true if the string is the correct format, false otherwise
|
|
7431
|
-
*/
|
|
7432
|
-
is.americanExpressCardNumber = function(str) {
|
|
7433
|
-
if (!is.str(str) || str.length !== 15) return false;
|
|
7434
|
-
var prefix = Math.floor(str.slice(0, 2));
|
|
7435
|
-
if (prefix !== 34 && prefix !== 37) return false;
|
|
7436
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7437
|
-
return true;
|
|
7438
|
-
};
|
|
7439
|
-
is.amexCard = is.amexCardNum = is.americanExpressCardNumber;
|
|
7440
|
-
/**
|
|
7441
|
-
* Test if card number is a China UnionPay card.
|
|
7442
|
-
* @param {String} the credit card number string to test.
|
|
7443
|
-
* @return true if the string is the correct format, false otherwise
|
|
7444
|
-
*/
|
|
7445
|
-
is.chinaUnionPayCardNumber = function(str) {
|
|
7446
|
-
if (!is.str(str) || str.length < 16 && str.length > 19) return false;
|
|
7447
|
-
var prefix = Math.floor(str.slice(0, 2));
|
|
7448
|
-
if (prefix !== 62 && prefix !== 88) return false;
|
|
7449
|
-
return true;
|
|
7450
|
-
};
|
|
7451
|
-
is.chinaUnion = is.chinaUnionPayCard = is.chinaUnionPayCardNumber;
|
|
7452
|
-
/**
|
|
7453
|
-
* Test if card number is a Diner's Club Carte Blance card.
|
|
7454
|
-
* @param {String} the credit card number string to test.
|
|
7455
|
-
* @return true if the string is the correct format, false otherwise
|
|
7456
|
-
*/
|
|
7457
|
-
is.dinersClubCarteBlancheCardNumber = function(str) {
|
|
7458
|
-
if (!is.str(str) || str.length !== 14) return false;
|
|
7459
|
-
var prefix = Math.floor(str.slice(0, 3));
|
|
7460
|
-
if (prefix < 300 || prefix > 305) return false;
|
|
7461
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7462
|
-
return true;
|
|
7463
|
-
};
|
|
7464
|
-
is.dinersClubCB = is.dinersClubCarteBlancheCard = is.dinersClubCarteBlancheCardNumber;
|
|
7465
|
-
/**
|
|
7466
|
-
* Test if card number is a Diner's Club International card.
|
|
7467
|
-
* @param {String} the credit card number string to test.
|
|
7468
|
-
* @return true if the string is the correct format, false otherwise
|
|
7469
|
-
*/
|
|
7470
|
-
is.dinersClubInternationalCardNumber = function(str) {
|
|
7471
|
-
if (!is.str(str) || str.length !== 14) return false;
|
|
7472
|
-
var prefix = Math.floor(str.slice(0, 3));
|
|
7473
|
-
var prefix2 = Math.floor(str.slice(0, 2));
|
|
7474
|
-
if ((prefix < 300 || prefix > 305) && prefix !== 309 && prefix2 !== 36 && (prefix2 < 38 || prefix2 > 39)) return false;
|
|
7475
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7476
|
-
return true;
|
|
7477
|
-
};
|
|
7478
|
-
is.dinersClubInt = is.dinersClubInternationalCard = is.dinersClubInternationalCardNumber;
|
|
7479
|
-
/**
|
|
7480
|
-
* Test if card number is a Diner's Club USA & CA card.
|
|
7481
|
-
* @param {String} the credit card number string to test.
|
|
7482
|
-
* @return true if the string is the correct format, false otherwise
|
|
7483
|
-
*/
|
|
7484
|
-
is.dinersClubUSACanadaCardNumber = function(str) {
|
|
7485
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7486
|
-
var prefix = Math.floor(str.slice(0, 2));
|
|
7487
|
-
if (prefix !== 54 && prefix !== 55) return false;
|
|
7488
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7489
|
-
return true;
|
|
7490
|
-
};
|
|
7491
|
-
is.dinersClub = is.dinersClubUSACanCard = is.dinersClubUSACanadaCardNumber;
|
|
7492
|
-
/**
|
|
7493
|
-
* Test if card number is a Diner's Club USA/CA card.
|
|
7494
|
-
* @param {String} the credit card number string to test.
|
|
7495
|
-
* @return true if the string is the correct format, false otherwise
|
|
7496
|
-
*/
|
|
7497
|
-
is.discoverCardNumber = function(str) {
|
|
7498
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7499
|
-
var prefix = Math.floor(str.slice(0, 6));
|
|
7500
|
-
var prefix2 = Math.floor(str.slice(0, 3));
|
|
7501
|
-
if (str.slice(0, 4) !== "6011" && (prefix < 622126 || prefix > 622925) && (prefix2 < 644 || prefix2 > 649) && str.slice(0, 2) !== "65") return false;
|
|
7502
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7503
|
-
return true;
|
|
7504
|
-
};
|
|
7505
|
-
is.discover = is.discoverCard = is.discoverCardNumber;
|
|
7506
|
-
/**
|
|
7507
|
-
* Test if card number is an InstaPayment card number
|
|
7508
|
-
* @param {String} the credit card number string to test.
|
|
7509
|
-
* @return true if the string is the correct format, false otherwise
|
|
7510
|
-
*/
|
|
7511
|
-
is.instaPaymentCardNumber = function(str) {
|
|
7512
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7513
|
-
var prefix = Math.floor(str.slice(0, 3));
|
|
7514
|
-
if (prefix < 637 || prefix > 639) return false;
|
|
7515
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7516
|
-
return true;
|
|
7517
|
-
};
|
|
7518
|
-
is.instaPayment = is.instaPaymentCardNumber;
|
|
7519
|
-
/**
|
|
7520
|
-
* Test if card number is a JCB card number
|
|
7521
|
-
* @param {String} the credit card number string to test.
|
|
7522
|
-
* @return true if the string is the correct format, false otherwise
|
|
7523
|
-
*/
|
|
7524
|
-
is.jcbCardNumber = function(str) {
|
|
7525
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7526
|
-
var prefix = Math.floor(str.slice(0, 4));
|
|
7527
|
-
if (prefix < 3528 || prefix > 3589) return false;
|
|
7528
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7529
|
-
return true;
|
|
7530
|
-
};
|
|
7531
|
-
is.jcb = is.jcbCard = is.jcbCardNumber;
|
|
7532
|
-
/**
|
|
7533
|
-
* Test if card number is a Laser card number
|
|
7534
|
-
* @param {String} the credit card number string to test.
|
|
7535
|
-
* @return true if the string is the correct format, false otherwise
|
|
7536
|
-
*/
|
|
7537
|
-
is.laserCardNumber = function(str) {
|
|
7538
|
-
if (!is.str(str) || str.length < 16 && str.length > 19) return false;
|
|
7539
|
-
var prefix = Math.floor(str.slice(0, 4));
|
|
7540
|
-
if ([
|
|
7541
|
-
6304,
|
|
7542
|
-
6706,
|
|
7543
|
-
6771,
|
|
7544
|
-
6709
|
|
7545
|
-
].indexOf(prefix) === -1) return false;
|
|
7546
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7547
|
-
return true;
|
|
7548
|
-
};
|
|
7549
|
-
is.laser = is.laserCard = is.laserCardNumber;
|
|
7550
|
-
/**
|
|
7551
|
-
* Test if card number is a Maestro card number
|
|
7552
|
-
* @param {String} the credit card number string to test.
|
|
7553
|
-
* @return true if the string is the correct format, false otherwise
|
|
7554
|
-
*/
|
|
7555
|
-
is.maestroCardNumber = function(str) {
|
|
7556
|
-
if (!is.str(str) || str.length < 12 || str.length > 19) return false;
|
|
7557
|
-
var prefix = str.slice(0, 4);
|
|
7558
|
-
if ([
|
|
7559
|
-
"5018",
|
|
7560
|
-
"5020",
|
|
7561
|
-
"5038",
|
|
7562
|
-
"5612",
|
|
7563
|
-
"5893",
|
|
7564
|
-
"6304",
|
|
7565
|
-
"6759",
|
|
7566
|
-
"6761",
|
|
7567
|
-
"6762",
|
|
7568
|
-
"6763",
|
|
7569
|
-
"0604",
|
|
7570
|
-
"6390"
|
|
7571
|
-
].indexOf(prefix) === -1) return false;
|
|
7572
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7573
|
-
return true;
|
|
7574
|
-
};
|
|
7575
|
-
is.maestro = is.maestroCard = is.maestroCardNumber;
|
|
7576
|
-
/**
|
|
7577
|
-
* Test if card number is a Dankort card number
|
|
7578
|
-
* @param {String} the credit card number string to test.
|
|
7579
|
-
* @return true if the string is the correct format, false otherwise
|
|
7580
|
-
*/
|
|
7581
|
-
is.dankortCardNumber = function(str) {
|
|
7582
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7583
|
-
if (str.slice(0, 4) !== "5019") return false;
|
|
7584
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7585
|
-
return true;
|
|
7586
|
-
};
|
|
7587
|
-
is.dankort = is.dankortCard = is.dankortCardNumber;
|
|
7588
|
-
/**
|
|
7589
|
-
* Test if card number is a MasterCard card number
|
|
7590
|
-
* @param {String} the credit card number string to test.
|
|
7591
|
-
* @return true if the string is the correct format, false otherwise
|
|
7592
|
-
*/
|
|
7593
|
-
is.masterCardCardNumber = function(str) {
|
|
7594
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7595
|
-
var prefix = Math.floor(str.slice(0, 2));
|
|
7596
|
-
if (prefix < 50 || prefix > 55) return false;
|
|
7597
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7598
|
-
return true;
|
|
7599
|
-
};
|
|
7600
|
-
is.masterCard = is.masterCardCard = is.masterCardCardNumber;
|
|
7601
|
-
/**
|
|
7602
|
-
* Test if card number is a Visa card number
|
|
7603
|
-
* @param {String} the credit card number string to test.
|
|
7604
|
-
* @return true if the string is the correct format, false otherwise
|
|
7605
|
-
*/
|
|
7606
|
-
is.visaCardNumber = function(str) {
|
|
7607
|
-
if (!is.str(str) || str.length !== 13 && str.length !== 16) return false;
|
|
7608
|
-
if ("4" !== str.slice(0, 1)) return false;
|
|
7609
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7610
|
-
return true;
|
|
7611
|
-
};
|
|
7612
|
-
is.visa = is.visaCard = is.visaCardNumber;
|
|
7613
|
-
/**
|
|
7614
|
-
* Test if card number is a Visa card number
|
|
7615
|
-
* @param {String} the credit card number string to test.
|
|
7616
|
-
* @return true if the string is the correct format, false otherwise
|
|
7617
|
-
*/
|
|
7618
|
-
is.visaElectronCardNumber = function(str) {
|
|
7619
|
-
if (!is.str(str) || str.length !== 16) return false;
|
|
7620
|
-
var prefix = Math.floor(str.slice(0, 4));
|
|
7621
|
-
if ("417500" !== str.slice(0, 6) && [
|
|
7622
|
-
4026,
|
|
7623
|
-
4405,
|
|
7624
|
-
4508,
|
|
7625
|
-
4844,
|
|
7626
|
-
4913,
|
|
7627
|
-
4917
|
|
7628
|
-
].indexOf(prefix) === -1) return false;
|
|
7629
|
-
if (!is.creditCardNumber(str)) return false;
|
|
7630
|
-
return false;
|
|
7631
|
-
};
|
|
7632
|
-
is.visaElectron = is.visaElectronCard = is.visaElectronCardNumber;
|
|
7633
|
-
/**
|
|
7634
|
-
* Test if the input is a valid MongoDB id.
|
|
7635
|
-
* @param {String|Object} Either a mongodb object id or a string representation.
|
|
7636
|
-
* @return true if the string is the correct format, false otherwise
|
|
7637
|
-
* Thanks to Jason Denizac (https://github.com/jden) for pointing this out.
|
|
7638
|
-
* https://github.com/jden/objectid/blob/master/index.js#L7-L10
|
|
7639
|
-
*/
|
|
7640
|
-
var objIdPattern = /^[0-9a-fA-F]{24}$/;
|
|
7641
|
-
is.mongoId = is.objectId = is.objId = function(id) {
|
|
7642
|
-
return Boolean(id) && !Array.isArray(id) && objIdPattern.test(String(id));
|
|
7643
|
-
};
|
|
7644
|
-
/**
|
|
7645
|
-
* Test is the first argument is structly equal to any of the subsequent args.
|
|
7646
|
-
* @param Value to test against subsequent arguments.
|
|
7647
|
-
* @return true if the first value matches any of subsequent values.
|
|
7648
|
-
*/
|
|
7649
|
-
is.matching = is.match = is.inArgs = function(val) {
|
|
7650
|
-
if (arguments.length < 2) return false;
|
|
7651
|
-
var result = false;
|
|
7652
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
7653
|
-
var eq = is.equal(val, arguments[i]);
|
|
7654
|
-
result = result || eq;
|
|
7655
|
-
}
|
|
7656
|
-
return result;
|
|
7657
|
-
};
|
|
7658
|
-
/**********************************
|
|
7659
|
-
***Definitely a work in progress***
|
|
7660
|
-
**********************************/
|
|
7661
|
-
/**
|
|
7662
|
-
* Test if a string contains a US street address
|
|
7663
|
-
* @param {String} the string to search
|
|
7664
|
-
* @return true if an address is present, false otherwise
|
|
7665
|
-
*/
|
|
7666
|
-
is.streetAddress = function(str) {
|
|
7667
|
-
if (!is.str(str)) return false;
|
|
7668
|
-
return /\b\d+[\s](?:[A-Za-z0-9.-]+[\s]+)+\b(ALLEY|ALY|AVENUE|AVE|BEND|BND|BLUFFS?|BLFS?|BOULEVARD|BLVD|BRANCH|BR|CENTERS?|CTRS?|CIRCLES?|CIRS?|CLIFFS?|CLFS?|COURTS?|CTS?|COVES?|CVS?|CREEK|CRK|CRESCENT|CRES|CREST|CRST|CROSSING|XING|DRIVES?|DRS?|EXPRESSWAY|EXPY|FREEWAY|FWY|HEIGHTS|HTS|HIGHWAY|HWY|HILLS?|HLS?|LANE|LN|LOOP|MANORS?|MNRS?|MOTORWAY|MTWY|MOUNT|MT|PARKS?|PARKWAYS?|PKWY|PASS|PLACE|PL|PLAZA|PLZ|POINTS?|PTS?|RIDGES?|RDGS?|ROADS?|RDS?|ROUTE|RTE?|SHOALS?|SHLS?|SHORES?|SHRS?|SPRINGS?|SPGS?|SPURS?|STREETS?|STS?|SUMMIT|SMT|TERRACE|TER|THROUGHWAY|TRWY|TRAFFICWAY|TRFY|TRAIL|TRL|TURNPIKE|TPKE|VALLEYS?|VLYS?|WAYS?)+(?:[\.\-\s\,]?)*((APARTMENT|APT|APPT|#|NUMBER|NUM|FLOOR|FL|\s)?(\d)*)\b/gi.test(str);
|
|
7669
|
-
};
|
|
7670
|
-
is.street = is.address = is.streetAddress;
|
|
7671
|
-
/**
|
|
7672
|
-
* Test if a string resembles a US Zip code,
|
|
7673
|
-
* no regular expression will be perfect for this,
|
|
7674
|
-
* as there are many numbers that aren't valid zip codes
|
|
7675
|
-
* @param {String || Number} the string or number literal to test
|
|
7676
|
-
* @return true if zipcode like, false otherwise
|
|
7677
|
-
*/
|
|
7678
|
-
is.zipCode = function(str) {
|
|
7679
|
-
if (is.undefined(str) || !(is.string(str) || is.number(str))) return false;
|
|
7680
|
-
return /^\d{5}(?:-\d{4})?$/.test(str);
|
|
7681
|
-
};
|
|
7682
|
-
is.zip = is.zipCode;
|
|
7683
|
-
/**
|
|
7684
|
-
* Test if a string contains a US phone number
|
|
7685
|
-
* @param {String} the string to search
|
|
7686
|
-
* @return true if str contains a phone number, false otherwise.
|
|
7687
|
-
*/
|
|
7688
|
-
is.phoneNumber = function(str) {
|
|
7689
|
-
if (!is.string(str)) return false;
|
|
7690
|
-
return /(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\(?)(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\)?)\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})/g.test(str);
|
|
7691
|
-
};
|
|
7692
|
-
is.phone = is.phoneNumber;
|
|
7693
|
-
/**
|
|
7694
|
-
* Test is a string is a valid URL
|
|
7695
|
-
* @param {string} val - the possible url to check
|
|
7696
|
-
* @return true if str contains a phone number, false otherwise.
|
|
7697
|
-
*/
|
|
7698
|
-
var isUrl = require_is_url();
|
|
7699
|
-
is.url = function(val) {
|
|
7700
|
-
return isUrl(val);
|
|
7701
|
-
};
|
|
7702
|
-
is.uri = is.url;
|
|
7703
|
-
is.enumerator = function(val, ary) {
|
|
7704
|
-
var value = false;
|
|
7705
|
-
if (!is.defined(val) || !is.defined(ary) || !is.arrayLike(ary)) return value;
|
|
7706
|
-
for (var i = 0, len = ary.length; i < len; i++) if (is.equal(val, ary[i])) {
|
|
7707
|
-
value = true;
|
|
7708
|
-
break;
|
|
7709
|
-
}
|
|
7710
|
-
return value;
|
|
7711
|
-
};
|
|
7712
|
-
is.enum = is.inArray = is.enumerator;
|
|
7713
|
-
}));
|
|
7714
|
-
//#endregion
|
|
7715
|
-
//#region node_modules/tcp-port-used/node_modules/ms/index.js
|
|
7716
|
-
var require_ms = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7717
|
-
/**
|
|
7718
|
-
* Helpers.
|
|
7719
|
-
*/
|
|
7720
|
-
var s = 1e3;
|
|
7721
|
-
var m = s * 60;
|
|
7722
|
-
var h = m * 60;
|
|
7723
|
-
var d = h * 24;
|
|
7724
|
-
var w = d * 7;
|
|
7725
|
-
var y = d * 365.25;
|
|
7726
|
-
/**
|
|
7727
|
-
* Parse or format the given `val`.
|
|
7728
|
-
*
|
|
7729
|
-
* Options:
|
|
7730
|
-
*
|
|
7731
|
-
* - `long` verbose formatting [false]
|
|
7732
|
-
*
|
|
7733
|
-
* @param {String|Number} val
|
|
7734
|
-
* @param {Object} [options]
|
|
7735
|
-
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
7736
|
-
* @return {String|Number}
|
|
7737
|
-
* @api public
|
|
7738
|
-
*/
|
|
7739
|
-
module.exports = function(val, options) {
|
|
7740
|
-
options = options || {};
|
|
7741
|
-
var type = typeof val;
|
|
7742
|
-
if (type === "string" && val.length > 0) return parse(val);
|
|
7743
|
-
else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
|
|
7744
|
-
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
7745
|
-
};
|
|
7746
|
-
/**
|
|
7747
|
-
* Parse the given `str` and return milliseconds.
|
|
7748
|
-
*
|
|
7749
|
-
* @param {String} str
|
|
7750
|
-
* @return {Number}
|
|
7751
|
-
* @api private
|
|
7752
|
-
*/
|
|
7753
|
-
function parse(str) {
|
|
7754
|
-
str = String(str);
|
|
7755
|
-
if (str.length > 100) return;
|
|
7756
|
-
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
7757
|
-
if (!match) return;
|
|
7758
|
-
var n = parseFloat(match[1]);
|
|
7759
|
-
switch ((match[2] || "ms").toLowerCase()) {
|
|
7760
|
-
case "years":
|
|
7761
|
-
case "year":
|
|
7762
|
-
case "yrs":
|
|
7763
|
-
case "yr":
|
|
7764
|
-
case "y": return n * y;
|
|
7765
|
-
case "weeks":
|
|
7766
|
-
case "week":
|
|
7767
|
-
case "w": return n * w;
|
|
7768
|
-
case "days":
|
|
7769
|
-
case "day":
|
|
7770
|
-
case "d": return n * d;
|
|
7771
|
-
case "hours":
|
|
7772
|
-
case "hour":
|
|
7773
|
-
case "hrs":
|
|
7774
|
-
case "hr":
|
|
7775
|
-
case "h": return n * h;
|
|
7776
|
-
case "minutes":
|
|
7777
|
-
case "minute":
|
|
7778
|
-
case "mins":
|
|
7779
|
-
case "min":
|
|
7780
|
-
case "m": return n * m;
|
|
7781
|
-
case "seconds":
|
|
7782
|
-
case "second":
|
|
7783
|
-
case "secs":
|
|
7784
|
-
case "sec":
|
|
7785
|
-
case "s": return n * s;
|
|
7786
|
-
case "milliseconds":
|
|
7787
|
-
case "millisecond":
|
|
7788
|
-
case "msecs":
|
|
7789
|
-
case "msec":
|
|
7790
|
-
case "ms": return n;
|
|
7791
|
-
default: return;
|
|
7792
|
-
}
|
|
7793
|
-
}
|
|
7794
|
-
/**
|
|
7795
|
-
* Short format for `ms`.
|
|
7796
|
-
*
|
|
7797
|
-
* @param {Number} ms
|
|
7798
|
-
* @return {String}
|
|
7799
|
-
* @api private
|
|
7800
|
-
*/
|
|
7801
|
-
function fmtShort(ms) {
|
|
7802
|
-
var msAbs = Math.abs(ms);
|
|
7803
|
-
if (msAbs >= d) return Math.round(ms / d) + "d";
|
|
7804
|
-
if (msAbs >= h) return Math.round(ms / h) + "h";
|
|
7805
|
-
if (msAbs >= m) return Math.round(ms / m) + "m";
|
|
7806
|
-
if (msAbs >= s) return Math.round(ms / s) + "s";
|
|
7807
|
-
return ms + "ms";
|
|
7808
|
-
}
|
|
7809
|
-
/**
|
|
7810
|
-
* Long format for `ms`.
|
|
7811
|
-
*
|
|
7812
|
-
* @param {Number} ms
|
|
7813
|
-
* @return {String}
|
|
7814
|
-
* @api private
|
|
7815
|
-
*/
|
|
7816
|
-
function fmtLong(ms) {
|
|
7817
|
-
var msAbs = Math.abs(ms);
|
|
7818
|
-
if (msAbs >= d) return plural(ms, msAbs, d, "day");
|
|
7819
|
-
if (msAbs >= h) return plural(ms, msAbs, h, "hour");
|
|
7820
|
-
if (msAbs >= m) return plural(ms, msAbs, m, "minute");
|
|
7821
|
-
if (msAbs >= s) return plural(ms, msAbs, s, "second");
|
|
7822
|
-
return ms + " ms";
|
|
7823
|
-
}
|
|
7824
|
-
/**
|
|
7825
|
-
* Pluralization helper.
|
|
7826
|
-
*/
|
|
7827
|
-
function plural(ms, msAbs, n, name) {
|
|
7828
|
-
var isPlural = msAbs >= n * 1.5;
|
|
7829
|
-
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
7830
|
-
}
|
|
7831
|
-
}));
|
|
7832
|
-
//#endregion
|
|
7833
|
-
//#region node_modules/tcp-port-used/node_modules/debug/src/common.js
|
|
7834
|
-
var require_common = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7835
|
-
/**
|
|
7836
|
-
* This is the common logic for both the Node.js and web browser
|
|
7837
|
-
* implementations of `debug()`.
|
|
7838
|
-
*/
|
|
7839
|
-
function setup(env) {
|
|
7840
|
-
createDebug.debug = createDebug;
|
|
7841
|
-
createDebug.default = createDebug;
|
|
7842
|
-
createDebug.coerce = coerce;
|
|
7843
|
-
createDebug.disable = disable;
|
|
7844
|
-
createDebug.enable = enable;
|
|
7845
|
-
createDebug.enabled = enabled;
|
|
7846
|
-
createDebug.humanize = require_ms();
|
|
7847
|
-
createDebug.destroy = destroy;
|
|
7848
|
-
Object.keys(env).forEach((key) => {
|
|
7849
|
-
createDebug[key] = env[key];
|
|
7850
|
-
});
|
|
7851
|
-
/**
|
|
7852
|
-
* The currently active debug mode names, and names to skip.
|
|
7853
|
-
*/
|
|
7854
|
-
createDebug.names = [];
|
|
7855
|
-
createDebug.skips = [];
|
|
7856
|
-
/**
|
|
7857
|
-
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
7858
|
-
*
|
|
7859
|
-
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
7860
|
-
*/
|
|
7861
|
-
createDebug.formatters = {};
|
|
7862
|
-
/**
|
|
7863
|
-
* Selects a color for a debug namespace
|
|
7864
|
-
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
|
7865
|
-
* @return {Number|String} An ANSI color code for the given namespace
|
|
7866
|
-
* @api private
|
|
7867
|
-
*/
|
|
7868
|
-
function selectColor(namespace) {
|
|
7869
|
-
let hash = 0;
|
|
7870
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
7871
|
-
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
7872
|
-
hash |= 0;
|
|
7873
|
-
}
|
|
7874
|
-
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
7875
|
-
}
|
|
7876
|
-
createDebug.selectColor = selectColor;
|
|
7877
|
-
/**
|
|
7878
|
-
* Create a debugger with the given `namespace`.
|
|
7879
|
-
*
|
|
7880
|
-
* @param {String} namespace
|
|
7881
|
-
* @return {Function}
|
|
7882
|
-
* @api public
|
|
7883
|
-
*/
|
|
7884
|
-
function createDebug(namespace) {
|
|
7885
|
-
let prevTime;
|
|
7886
|
-
let enableOverride = null;
|
|
7887
|
-
function debug(...args) {
|
|
7888
|
-
if (!debug.enabled) return;
|
|
7889
|
-
const self = debug;
|
|
7890
|
-
const curr = Number(/* @__PURE__ */ new Date());
|
|
7891
|
-
self.diff = curr - (prevTime || curr);
|
|
7892
|
-
self.prev = prevTime;
|
|
7893
|
-
self.curr = curr;
|
|
7894
|
-
prevTime = curr;
|
|
7895
|
-
args[0] = createDebug.coerce(args[0]);
|
|
7896
|
-
if (typeof args[0] !== "string") args.unshift("%O");
|
|
7897
|
-
let index = 0;
|
|
7898
|
-
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
7899
|
-
if (match === "%%") return "%";
|
|
7900
|
-
index++;
|
|
7901
|
-
const formatter = createDebug.formatters[format];
|
|
7902
|
-
if (typeof formatter === "function") {
|
|
7903
|
-
const val = args[index];
|
|
7904
|
-
match = formatter.call(self, val);
|
|
7905
|
-
args.splice(index, 1);
|
|
7906
|
-
index--;
|
|
7907
|
-
}
|
|
7908
|
-
return match;
|
|
7909
|
-
});
|
|
7910
|
-
createDebug.formatArgs.call(self, args);
|
|
7911
|
-
(self.log || createDebug.log).apply(self, args);
|
|
7912
|
-
}
|
|
7913
|
-
debug.namespace = namespace;
|
|
7914
|
-
debug.useColors = createDebug.useColors();
|
|
7915
|
-
debug.color = createDebug.selectColor(namespace);
|
|
7916
|
-
debug.extend = extend;
|
|
7917
|
-
debug.destroy = createDebug.destroy;
|
|
7918
|
-
Object.defineProperty(debug, "enabled", {
|
|
7919
|
-
enumerable: true,
|
|
7920
|
-
configurable: false,
|
|
7921
|
-
get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
|
|
7922
|
-
set: (v) => {
|
|
7923
|
-
enableOverride = v;
|
|
7924
|
-
}
|
|
7925
|
-
});
|
|
7926
|
-
if (typeof createDebug.init === "function") createDebug.init(debug);
|
|
7927
|
-
return debug;
|
|
7928
|
-
}
|
|
7929
|
-
function extend(namespace, delimiter) {
|
|
7930
|
-
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
7931
|
-
newDebug.log = this.log;
|
|
7932
|
-
return newDebug;
|
|
7933
|
-
}
|
|
7934
|
-
/**
|
|
7935
|
-
* Enables a debug mode by namespaces. This can include modes
|
|
7936
|
-
* separated by a colon and wildcards.
|
|
7937
|
-
*
|
|
7938
|
-
* @param {String} namespaces
|
|
7939
|
-
* @api public
|
|
7940
|
-
*/
|
|
7941
|
-
function enable(namespaces) {
|
|
7942
|
-
createDebug.save(namespaces);
|
|
7943
|
-
createDebug.names = [];
|
|
7944
|
-
createDebug.skips = [];
|
|
7945
|
-
let i;
|
|
7946
|
-
const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
|
|
7947
|
-
const len = split.length;
|
|
7948
|
-
for (i = 0; i < len; i++) {
|
|
7949
|
-
if (!split[i]) continue;
|
|
7950
|
-
namespaces = split[i].replace(/\*/g, ".*?");
|
|
7951
|
-
if (namespaces[0] === "-") createDebug.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
|
|
7952
|
-
else createDebug.names.push(new RegExp("^" + namespaces + "$"));
|
|
7953
|
-
}
|
|
7954
|
-
}
|
|
7955
|
-
/**
|
|
7956
|
-
* Disable debug output.
|
|
7957
|
-
*
|
|
7958
|
-
* @return {String} namespaces
|
|
7959
|
-
* @api public
|
|
7960
|
-
*/
|
|
7961
|
-
function disable() {
|
|
7962
|
-
const namespaces = [...createDebug.names.map(toNamespace), ...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)].join(",");
|
|
7963
|
-
createDebug.enable("");
|
|
7964
|
-
return namespaces;
|
|
7965
|
-
}
|
|
7966
|
-
/**
|
|
7967
|
-
* Returns true if the given mode name is enabled, false otherwise.
|
|
7968
|
-
*
|
|
7969
|
-
* @param {String} name
|
|
7970
|
-
* @return {Boolean}
|
|
7971
|
-
* @api public
|
|
7972
|
-
*/
|
|
7973
|
-
function enabled(name) {
|
|
7974
|
-
if (name[name.length - 1] === "*") return true;
|
|
7975
|
-
let i;
|
|
7976
|
-
let len;
|
|
7977
|
-
for (i = 0, len = createDebug.skips.length; i < len; i++) if (createDebug.skips[i].test(name)) return false;
|
|
7978
|
-
for (i = 0, len = createDebug.names.length; i < len; i++) if (createDebug.names[i].test(name)) return true;
|
|
7979
|
-
return false;
|
|
7980
|
-
}
|
|
7981
|
-
/**
|
|
7982
|
-
* Convert regexp to namespace
|
|
7983
|
-
*
|
|
7984
|
-
* @param {RegExp} regxep
|
|
7985
|
-
* @return {String} namespace
|
|
7986
|
-
* @api private
|
|
7987
|
-
*/
|
|
7988
|
-
function toNamespace(regexp) {
|
|
7989
|
-
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
|
|
7990
|
-
}
|
|
7991
|
-
/**
|
|
7992
|
-
* Coerce `val`.
|
|
7993
|
-
*
|
|
7994
|
-
* @param {Mixed} val
|
|
7995
|
-
* @return {Mixed}
|
|
7996
|
-
* @api private
|
|
7997
|
-
*/
|
|
7998
|
-
function coerce(val) {
|
|
7999
|
-
if (val instanceof Error) return val.stack || val.message;
|
|
8000
|
-
return val;
|
|
8001
|
-
}
|
|
8002
|
-
/**
|
|
8003
|
-
* XXX DO NOT USE. This is a temporary stub function.
|
|
8004
|
-
* XXX It WILL be removed in the next major release.
|
|
8005
|
-
*/
|
|
8006
|
-
function destroy() {
|
|
8007
|
-
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
8008
|
-
}
|
|
8009
|
-
createDebug.enable(createDebug.load());
|
|
8010
|
-
return createDebug;
|
|
8011
|
-
}
|
|
8012
|
-
module.exports = setup;
|
|
8013
|
-
}));
|
|
8014
|
-
//#endregion
|
|
8015
|
-
//#region node_modules/tcp-port-used/node_modules/debug/src/browser.js
|
|
8016
|
-
var require_browser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
8017
|
-
/**
|
|
8018
|
-
* This is the web browser implementation of `debug()`.
|
|
8019
|
-
*/
|
|
8020
|
-
exports.formatArgs = formatArgs;
|
|
8021
|
-
exports.save = save;
|
|
8022
|
-
exports.load = load;
|
|
8023
|
-
exports.useColors = useColors;
|
|
8024
|
-
exports.storage = localstorage();
|
|
8025
|
-
exports.destroy = (() => {
|
|
8026
|
-
let warned = false;
|
|
8027
|
-
return () => {
|
|
8028
|
-
if (!warned) {
|
|
8029
|
-
warned = true;
|
|
8030
|
-
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
8031
|
-
}
|
|
8032
|
-
};
|
|
8033
|
-
})();
|
|
8034
|
-
/**
|
|
8035
|
-
* Colors.
|
|
8036
|
-
*/
|
|
8037
|
-
exports.colors = [
|
|
8038
|
-
"#0000CC",
|
|
8039
|
-
"#0000FF",
|
|
8040
|
-
"#0033CC",
|
|
8041
|
-
"#0033FF",
|
|
8042
|
-
"#0066CC",
|
|
8043
|
-
"#0066FF",
|
|
8044
|
-
"#0099CC",
|
|
8045
|
-
"#0099FF",
|
|
8046
|
-
"#00CC00",
|
|
8047
|
-
"#00CC33",
|
|
8048
|
-
"#00CC66",
|
|
8049
|
-
"#00CC99",
|
|
8050
|
-
"#00CCCC",
|
|
8051
|
-
"#00CCFF",
|
|
8052
|
-
"#3300CC",
|
|
8053
|
-
"#3300FF",
|
|
8054
|
-
"#3333CC",
|
|
8055
|
-
"#3333FF",
|
|
8056
|
-
"#3366CC",
|
|
8057
|
-
"#3366FF",
|
|
8058
|
-
"#3399CC",
|
|
8059
|
-
"#3399FF",
|
|
8060
|
-
"#33CC00",
|
|
8061
|
-
"#33CC33",
|
|
8062
|
-
"#33CC66",
|
|
8063
|
-
"#33CC99",
|
|
8064
|
-
"#33CCCC",
|
|
8065
|
-
"#33CCFF",
|
|
8066
|
-
"#6600CC",
|
|
8067
|
-
"#6600FF",
|
|
8068
|
-
"#6633CC",
|
|
8069
|
-
"#6633FF",
|
|
8070
|
-
"#66CC00",
|
|
8071
|
-
"#66CC33",
|
|
8072
|
-
"#9900CC",
|
|
8073
|
-
"#9900FF",
|
|
8074
|
-
"#9933CC",
|
|
8075
|
-
"#9933FF",
|
|
8076
|
-
"#99CC00",
|
|
8077
|
-
"#99CC33",
|
|
8078
|
-
"#CC0000",
|
|
8079
|
-
"#CC0033",
|
|
8080
|
-
"#CC0066",
|
|
8081
|
-
"#CC0099",
|
|
8082
|
-
"#CC00CC",
|
|
8083
|
-
"#CC00FF",
|
|
8084
|
-
"#CC3300",
|
|
8085
|
-
"#CC3333",
|
|
8086
|
-
"#CC3366",
|
|
8087
|
-
"#CC3399",
|
|
8088
|
-
"#CC33CC",
|
|
8089
|
-
"#CC33FF",
|
|
8090
|
-
"#CC6600",
|
|
8091
|
-
"#CC6633",
|
|
8092
|
-
"#CC9900",
|
|
8093
|
-
"#CC9933",
|
|
8094
|
-
"#CCCC00",
|
|
8095
|
-
"#CCCC33",
|
|
8096
|
-
"#FF0000",
|
|
8097
|
-
"#FF0033",
|
|
8098
|
-
"#FF0066",
|
|
8099
|
-
"#FF0099",
|
|
8100
|
-
"#FF00CC",
|
|
8101
|
-
"#FF00FF",
|
|
8102
|
-
"#FF3300",
|
|
8103
|
-
"#FF3333",
|
|
8104
|
-
"#FF3366",
|
|
8105
|
-
"#FF3399",
|
|
8106
|
-
"#FF33CC",
|
|
8107
|
-
"#FF33FF",
|
|
8108
|
-
"#FF6600",
|
|
8109
|
-
"#FF6633",
|
|
8110
|
-
"#FF9900",
|
|
8111
|
-
"#FF9933",
|
|
8112
|
-
"#FFCC00",
|
|
8113
|
-
"#FFCC33"
|
|
8114
|
-
];
|
|
8115
|
-
/**
|
|
8116
|
-
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
8117
|
-
* and the Firebug extension (any Firefox version) are known
|
|
8118
|
-
* to support "%c" CSS customizations.
|
|
8119
|
-
*
|
|
8120
|
-
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
8121
|
-
*/
|
|
8122
|
-
function useColors() {
|
|
8123
|
-
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true;
|
|
8124
|
-
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false;
|
|
8125
|
-
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
8126
|
-
}
|
|
8127
|
-
/**
|
|
8128
|
-
* Colorize log arguments if enabled.
|
|
8129
|
-
*
|
|
8130
|
-
* @api public
|
|
8131
|
-
*/
|
|
8132
|
-
function formatArgs(args) {
|
|
8133
|
-
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
8134
|
-
if (!this.useColors) return;
|
|
8135
|
-
const c = "color: " + this.color;
|
|
8136
|
-
args.splice(1, 0, c, "color: inherit");
|
|
8137
|
-
let index = 0;
|
|
8138
|
-
let lastC = 0;
|
|
8139
|
-
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
8140
|
-
if (match === "%%") return;
|
|
8141
|
-
index++;
|
|
8142
|
-
if (match === "%c") lastC = index;
|
|
8143
|
-
});
|
|
8144
|
-
args.splice(lastC, 0, c);
|
|
8145
|
-
}
|
|
8146
|
-
/**
|
|
8147
|
-
* Invokes `console.debug()` when available.
|
|
8148
|
-
* No-op when `console.debug` is not a "function".
|
|
8149
|
-
* If `console.debug` is not available, falls back
|
|
8150
|
-
* to `console.log`.
|
|
8151
|
-
*
|
|
8152
|
-
* @api public
|
|
8153
|
-
*/
|
|
8154
|
-
exports.log = console.debug || console.log || (() => {});
|
|
8155
|
-
/**
|
|
8156
|
-
* Save `namespaces`.
|
|
8157
|
-
*
|
|
8158
|
-
* @param {String} namespaces
|
|
8159
|
-
* @api private
|
|
8160
|
-
*/
|
|
8161
|
-
function save(namespaces) {
|
|
8162
|
-
try {
|
|
8163
|
-
if (namespaces) exports.storage.setItem("debug", namespaces);
|
|
8164
|
-
else exports.storage.removeItem("debug");
|
|
8165
|
-
} catch (error) {}
|
|
8166
|
-
}
|
|
8167
|
-
/**
|
|
8168
|
-
* Load `namespaces`.
|
|
8169
|
-
*
|
|
8170
|
-
* @return {String} returns the previously persisted debug modes
|
|
8171
|
-
* @api private
|
|
8172
|
-
*/
|
|
8173
|
-
function load() {
|
|
8174
|
-
let r;
|
|
8175
|
-
try {
|
|
8176
|
-
r = exports.storage.getItem("debug");
|
|
8177
|
-
} catch (error) {}
|
|
8178
|
-
if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
|
|
8179
|
-
return r;
|
|
8180
|
-
}
|
|
8181
|
-
/**
|
|
8182
|
-
* Localstorage attempts to return the localstorage.
|
|
8183
|
-
*
|
|
8184
|
-
* This is necessary because safari throws
|
|
8185
|
-
* when a user disables cookies/localstorage
|
|
8186
|
-
* and you attempt to access it.
|
|
8187
|
-
*
|
|
8188
|
-
* @return {LocalStorage}
|
|
8189
|
-
* @api private
|
|
8190
|
-
*/
|
|
8191
|
-
function localstorage() {
|
|
8192
|
-
try {
|
|
8193
|
-
return localStorage;
|
|
8194
|
-
} catch (error) {}
|
|
8195
|
-
}
|
|
8196
|
-
module.exports = require_common()(exports);
|
|
8197
|
-
const { formatters } = module.exports;
|
|
8198
|
-
/**
|
|
8199
|
-
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
8200
|
-
*/
|
|
8201
|
-
formatters.j = function(v) {
|
|
8202
|
-
try {
|
|
8203
|
-
return JSON.stringify(v);
|
|
8204
|
-
} catch (error) {
|
|
8205
|
-
return "[UnexpectedJSONParseError]: " + error.message;
|
|
8206
|
-
}
|
|
8207
|
-
};
|
|
8208
|
-
}));
|
|
8209
|
-
//#endregion
|
|
8210
|
-
//#region node_modules/tcp-port-used/node_modules/debug/src/node.js
|
|
8211
|
-
var require_node = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
8212
|
-
/**
|
|
8213
|
-
* Module dependencies.
|
|
8214
|
-
*/
|
|
8215
|
-
const tty = __require("tty");
|
|
8216
|
-
const util$1 = __require("util");
|
|
8217
|
-
/**
|
|
8218
|
-
* This is the Node.js implementation of `debug()`.
|
|
8219
|
-
*/
|
|
8220
|
-
exports.init = init;
|
|
8221
|
-
exports.log = log;
|
|
8222
|
-
exports.formatArgs = formatArgs;
|
|
8223
|
-
exports.save = save;
|
|
8224
|
-
exports.load = load;
|
|
8225
|
-
exports.useColors = useColors;
|
|
8226
|
-
exports.destroy = util$1.deprecate(() => {}, "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
8227
|
-
/**
|
|
8228
|
-
* Colors.
|
|
8229
|
-
*/
|
|
8230
|
-
exports.colors = [
|
|
8231
|
-
6,
|
|
8232
|
-
2,
|
|
8233
|
-
3,
|
|
8234
|
-
4,
|
|
8235
|
-
5,
|
|
8236
|
-
1
|
|
8237
|
-
];
|
|
8238
|
-
try {
|
|
8239
|
-
const supportsColor = require_supports_color();
|
|
8240
|
-
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) exports.colors = [
|
|
8241
|
-
20,
|
|
8242
|
-
21,
|
|
8243
|
-
26,
|
|
8244
|
-
27,
|
|
8245
|
-
32,
|
|
8246
|
-
33,
|
|
8247
|
-
38,
|
|
8248
|
-
39,
|
|
8249
|
-
40,
|
|
8250
|
-
41,
|
|
8251
|
-
42,
|
|
8252
|
-
43,
|
|
8253
|
-
44,
|
|
8254
|
-
45,
|
|
8255
|
-
56,
|
|
8256
|
-
57,
|
|
8257
|
-
62,
|
|
8258
|
-
63,
|
|
8259
|
-
68,
|
|
8260
|
-
69,
|
|
8261
|
-
74,
|
|
8262
|
-
75,
|
|
8263
|
-
76,
|
|
8264
|
-
77,
|
|
8265
|
-
78,
|
|
8266
|
-
79,
|
|
8267
|
-
80,
|
|
8268
|
-
81,
|
|
8269
|
-
92,
|
|
8270
|
-
93,
|
|
8271
|
-
98,
|
|
8272
|
-
99,
|
|
8273
|
-
112,
|
|
8274
|
-
113,
|
|
8275
|
-
128,
|
|
8276
|
-
129,
|
|
8277
|
-
134,
|
|
8278
|
-
135,
|
|
8279
|
-
148,
|
|
8280
|
-
149,
|
|
8281
|
-
160,
|
|
8282
|
-
161,
|
|
8283
|
-
162,
|
|
8284
|
-
163,
|
|
8285
|
-
164,
|
|
8286
|
-
165,
|
|
8287
|
-
166,
|
|
8288
|
-
167,
|
|
8289
|
-
168,
|
|
8290
|
-
169,
|
|
8291
|
-
170,
|
|
8292
|
-
171,
|
|
8293
|
-
172,
|
|
8294
|
-
173,
|
|
8295
|
-
178,
|
|
8296
|
-
179,
|
|
8297
|
-
184,
|
|
8298
|
-
185,
|
|
8299
|
-
196,
|
|
8300
|
-
197,
|
|
8301
|
-
198,
|
|
8302
|
-
199,
|
|
8303
|
-
200,
|
|
8304
|
-
201,
|
|
8305
|
-
202,
|
|
8306
|
-
203,
|
|
8307
|
-
204,
|
|
8308
|
-
205,
|
|
8309
|
-
206,
|
|
8310
|
-
207,
|
|
8311
|
-
208,
|
|
8312
|
-
209,
|
|
8313
|
-
214,
|
|
8314
|
-
215,
|
|
8315
|
-
220,
|
|
8316
|
-
221
|
|
8317
|
-
];
|
|
8318
|
-
} catch (error) {}
|
|
8319
|
-
/**
|
|
8320
|
-
* Build up the default `inspectOpts` object from the environment variables.
|
|
8321
|
-
*
|
|
8322
|
-
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
8323
|
-
*/
|
|
8324
|
-
exports.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
8325
|
-
return /^debug_/i.test(key);
|
|
8326
|
-
}).reduce((obj, key) => {
|
|
8327
|
-
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
8328
|
-
return k.toUpperCase();
|
|
8329
|
-
});
|
|
8330
|
-
let val = process.env[key];
|
|
8331
|
-
if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
|
|
8332
|
-
else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
|
|
8333
|
-
else if (val === "null") val = null;
|
|
8334
|
-
else val = Number(val);
|
|
8335
|
-
obj[prop] = val;
|
|
8336
|
-
return obj;
|
|
8337
|
-
}, {});
|
|
8338
|
-
/**
|
|
8339
|
-
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
8340
|
-
*/
|
|
8341
|
-
function useColors() {
|
|
8342
|
-
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
8343
|
-
}
|
|
8344
|
-
/**
|
|
8345
|
-
* Adds ANSI color escape codes if enabled.
|
|
8346
|
-
*
|
|
8347
|
-
* @api public
|
|
8348
|
-
*/
|
|
8349
|
-
function formatArgs(args) {
|
|
8350
|
-
const { namespace: name, useColors } = this;
|
|
8351
|
-
if (useColors) {
|
|
8352
|
-
const c = this.color;
|
|
8353
|
-
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
8354
|
-
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
8355
|
-
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
8356
|
-
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
8357
|
-
} else args[0] = getDate() + name + " " + args[0];
|
|
8358
|
-
}
|
|
8359
|
-
function getDate() {
|
|
8360
|
-
if (exports.inspectOpts.hideDate) return "";
|
|
8361
|
-
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
8362
|
-
}
|
|
8363
|
-
/**
|
|
8364
|
-
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
8365
|
-
*/
|
|
8366
|
-
function log(...args) {
|
|
8367
|
-
return process.stderr.write(util$1.format(...args) + "\n");
|
|
8368
|
-
}
|
|
8369
|
-
/**
|
|
8370
|
-
* Save `namespaces`.
|
|
8371
|
-
*
|
|
8372
|
-
* @param {String} namespaces
|
|
8373
|
-
* @api private
|
|
8374
|
-
*/
|
|
8375
|
-
function save(namespaces) {
|
|
8376
|
-
if (namespaces) process.env.DEBUG = namespaces;
|
|
8377
|
-
else delete process.env.DEBUG;
|
|
8378
|
-
}
|
|
8379
|
-
/**
|
|
8380
|
-
* Load `namespaces`.
|
|
8381
|
-
*
|
|
8382
|
-
* @return {String} returns the previously persisted debug modes
|
|
8383
|
-
* @api private
|
|
8384
|
-
*/
|
|
8385
|
-
function load() {
|
|
8386
|
-
return process.env.DEBUG;
|
|
8387
|
-
}
|
|
8388
|
-
/**
|
|
8389
|
-
* Init logic for `debug` instances.
|
|
8390
|
-
*
|
|
8391
|
-
* Create a new `inspectOpts` object in case `useColors` is set
|
|
8392
|
-
* differently for a particular `debug` instance.
|
|
8393
|
-
*/
|
|
8394
|
-
function init(debug) {
|
|
8395
|
-
debug.inspectOpts = {};
|
|
8396
|
-
const keys = Object.keys(exports.inspectOpts);
|
|
8397
|
-
for (let i = 0; i < keys.length; i++) debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
8398
|
-
}
|
|
8399
|
-
module.exports = require_common()(exports);
|
|
8400
|
-
const { formatters } = module.exports;
|
|
8401
|
-
/**
|
|
8402
|
-
* Map %o to `util.inspect()`, all on a single line.
|
|
8403
|
-
*/
|
|
8404
|
-
formatters.o = function(v) {
|
|
8405
|
-
this.inspectOpts.colors = this.useColors;
|
|
8406
|
-
return util$1.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
8407
|
-
};
|
|
8408
|
-
/**
|
|
8409
|
-
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
8410
|
-
*/
|
|
8411
|
-
formatters.O = function(v) {
|
|
8412
|
-
this.inspectOpts.colors = this.useColors;
|
|
8413
|
-
return util$1.inspect(v, this.inspectOpts);
|
|
8414
|
-
};
|
|
8415
|
-
}));
|
|
8416
|
-
//#endregion
|
|
8417
|
-
//#region node_modules/tcp-port-used/node_modules/debug/src/index.js
|
|
8418
|
-
var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
8419
|
-
/**
|
|
8420
|
-
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
8421
|
-
* treat as a browser.
|
|
8422
|
-
*/
|
|
8423
|
-
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) module.exports = require_browser();
|
|
8424
|
-
else module.exports = require_node();
|
|
8425
|
-
}));
|
|
8426
|
-
//#endregion
|
|
8427
|
-
//#region dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js
|
|
8428
|
-
var import_tcp_port_used = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
8429
|
-
exports.check = check;
|
|
8430
|
-
var is = require_is2();
|
|
8431
|
-
var net = __require("net");
|
|
8432
|
-
var util = __require("util");
|
|
8433
|
-
var debug = require_src()("tcp-port-used");
|
|
8434
|
-
function getDeferred() {
|
|
8435
|
-
var resolve, reject, promise = new Promise(function(res, rej) {
|
|
8436
|
-
resolve = res;
|
|
8437
|
-
reject = rej;
|
|
8438
|
-
});
|
|
8439
|
-
return {
|
|
8440
|
-
resolve,
|
|
8441
|
-
reject,
|
|
8442
|
-
promise
|
|
8443
|
-
};
|
|
8444
|
-
}
|
|
8445
|
-
/**
|
|
8446
|
-
* Creates an options object from all the possible arguments
|
|
8447
|
-
* @private
|
|
8448
|
-
* @param {Number} port a valid TCP port number
|
|
8449
|
-
* @param {String} host The DNS name or IP address.
|
|
8450
|
-
* @param {Boolean} status The desired in use status to wait for: false === not in use, true === in use
|
|
8451
|
-
* @param {Number} retryTimeMs the retry interval in milliseconds - defaultis is 200ms
|
|
8452
|
-
* @param {Number} timeOutMs the amount of time to wait until port is free default is 1000ms
|
|
8453
|
-
* @return {Object} An options object with all the above parameters as properties.
|
|
8454
|
-
*/
|
|
8455
|
-
function makeOptionsObj(port, host, inUse, retryTimeMs, timeOutMs) {
|
|
8456
|
-
var opts = {};
|
|
8457
|
-
opts.port = port;
|
|
8458
|
-
opts.host = host;
|
|
8459
|
-
opts.inUse = inUse;
|
|
8460
|
-
opts.retryTimeMs = retryTimeMs;
|
|
8461
|
-
opts.timeOutMs = timeOutMs;
|
|
8462
|
-
return opts;
|
|
8463
|
-
}
|
|
8464
|
-
/**
|
|
8465
|
-
* Checks if a TCP port is in use by creating the socket and binding it to the
|
|
8466
|
-
* target port. Once bound, successfully, it's assume the port is availble.
|
|
8467
|
-
* After the socket is closed or in error, the promise is resolved.
|
|
8468
|
-
* Note: you have to be super user to correctly test system ports (0-1023).
|
|
8469
|
-
* @param {Number|Object} port The port you are curious to see if available. If an object, must have the parameters as properties.
|
|
8470
|
-
* @param {String} [host] May be a DNS name or IP address. Default '127.0.0.1'
|
|
8471
|
-
* @return {Object} A deferred Q promise.
|
|
8472
|
-
*
|
|
8473
|
-
* Example usage:
|
|
8474
|
-
*
|
|
8475
|
-
* var tcpPortUsed = require('tcp-port-used');
|
|
8476
|
-
* tcpPortUsed.check(22, '127.0.0.1')
|
|
8477
|
-
* .then(function(inUse) {
|
|
8478
|
-
* debug('Port 22 usage: '+inUse);
|
|
8479
|
-
* }, function(err) {
|
|
8480
|
-
* console.error('Error on check: '+util.inspect(err));
|
|
8481
|
-
* });
|
|
8482
|
-
*/
|
|
8483
|
-
function check(port, host) {
|
|
8484
|
-
var deferred = getDeferred();
|
|
8485
|
-
var inUse = true;
|
|
8486
|
-
var client;
|
|
8487
|
-
var opts;
|
|
8488
|
-
if (!is.obj(port)) opts = makeOptionsObj(port, host);
|
|
8489
|
-
else opts = port;
|
|
8490
|
-
if (!is.port(opts.port)) {
|
|
8491
|
-
debug("Error invalid port: " + util.inspect(opts.port));
|
|
8492
|
-
deferred.reject(/* @__PURE__ */ new Error("invalid port: " + util.inspect(opts.port)));
|
|
8493
|
-
return deferred.promise;
|
|
8494
|
-
}
|
|
8495
|
-
if (is.nullOrUndefined(opts.host)) {
|
|
8496
|
-
debug("set host address to default 127.0.0.1");
|
|
8497
|
-
opts.host = "127.0.0.1";
|
|
8498
|
-
}
|
|
8499
|
-
function cleanUp() {
|
|
8500
|
-
if (client) {
|
|
8501
|
-
client.removeAllListeners("connect");
|
|
8502
|
-
client.removeAllListeners("error");
|
|
8503
|
-
client.end();
|
|
8504
|
-
client.destroy();
|
|
8505
|
-
client.unref();
|
|
8506
|
-
}
|
|
8507
|
-
}
|
|
8508
|
-
function onConnectCb() {
|
|
8509
|
-
deferred.resolve(inUse);
|
|
8510
|
-
cleanUp();
|
|
8511
|
-
}
|
|
8512
|
-
function onErrorCb(err) {
|
|
8513
|
-
if (err.code !== "ECONNREFUSED") deferred.reject(err);
|
|
8514
|
-
else {
|
|
8515
|
-
inUse = false;
|
|
8516
|
-
deferred.resolve(inUse);
|
|
8517
|
-
}
|
|
8518
|
-
cleanUp();
|
|
8519
|
-
}
|
|
8520
|
-
client = new net.Socket();
|
|
8521
|
-
client.once("connect", onConnectCb);
|
|
8522
|
-
client.once("error", onErrorCb);
|
|
8523
|
-
client.connect({
|
|
8524
|
-
port: opts.port,
|
|
8525
|
-
host: opts.host
|
|
8526
|
-
}, function() {});
|
|
8527
|
-
return deferred.promise;
|
|
8528
|
-
}
|
|
8529
|
-
})))(), 1);
|
|
8530
|
-
const MAX_TCP_PORT = 65535;
|
|
8531
|
-
function _mergeRouterConfigs(existingConfig, newConfig) {
|
|
8532
|
-
if (!existingConfig?.Routers) return newConfig;
|
|
8533
|
-
const existingRoutersByEndpoint = /* @__PURE__ */ new Map();
|
|
8534
|
-
Object.entries(existingConfig.Routers).forEach(([routerName, router]) => {
|
|
8535
|
-
if (router.Parameters?.Endpoint) existingRoutersByEndpoint.set(router.Parameters.Endpoint, {
|
|
8536
|
-
routerName,
|
|
8537
|
-
router
|
|
8538
|
-
});
|
|
8539
|
-
});
|
|
8540
|
-
const mergedRouters = { ...newConfig.Routers };
|
|
8541
|
-
Object.entries(newConfig.Routers).forEach(([newRouterName, newRouter]) => {
|
|
8542
|
-
if (newRouter.Parameters?.Endpoint) {
|
|
8543
|
-
const existing = existingRoutersByEndpoint.get(newRouter.Parameters.Endpoint);
|
|
8544
|
-
if (existing) mergedRouters[newRouterName] = {
|
|
8545
|
-
...existing.router,
|
|
8546
|
-
...newRouter,
|
|
8547
|
-
Parameters: {
|
|
8548
|
-
...existing.router.Parameters,
|
|
8549
|
-
...newRouter.Parameters
|
|
8550
|
-
}
|
|
8551
|
-
};
|
|
8552
|
-
}
|
|
8553
|
-
});
|
|
8554
|
-
return {
|
|
8555
|
-
...newConfig,
|
|
8556
|
-
Routers: mergedRouters
|
|
8557
|
-
};
|
|
8558
|
-
}
|
|
8559
|
-
async function _setProvideDhtSweepEnabledOnKuboNode(kuboClient, sweepEnabled) {
|
|
8560
|
-
const log = logger_default("pkc-js:pkc:_init:retrySettingHttpRoutersOnIpfsNodes:setProvideDhtSweepEnabledOnIpfsNode");
|
|
8561
|
-
const configKey = "Provide.DHT.SweepEnabled";
|
|
8562
|
-
const url = `${kuboClient._clientOptions.url}/config?arg=${configKey}&arg=${JSON.stringify(sweepEnabled)}&json=true`;
|
|
8563
|
-
try {
|
|
8564
|
-
await fetch(url, {
|
|
8565
|
-
method: "POST",
|
|
8566
|
-
headers: kuboClient._clientOptions.headers
|
|
8567
|
-
});
|
|
8568
|
-
} catch (e) {
|
|
8569
|
-
const error = new PKCError("ERR_FAILED_TO_SET_CONFIG_ON_KUBO_NODE", {
|
|
8570
|
-
fullUrl: url,
|
|
8571
|
-
actualError: e,
|
|
8572
|
-
kuboEndpoint: kuboClient._clientOptions.url,
|
|
8573
|
-
configKey,
|
|
8574
|
-
configValueToBeSet: sweepEnabled
|
|
8575
|
-
});
|
|
8576
|
-
log.error(e);
|
|
8577
|
-
throw error;
|
|
8578
|
-
}
|
|
8579
|
-
log.trace("Succeeded in setting config key", configKey, "on node", kuboClient._clientOptions.url, "to be", sweepEnabled);
|
|
8580
|
-
}
|
|
8581
|
-
async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
|
|
8582
|
-
const log = logger_default("pkc-js:pkc:_init:retrySettingHttpRoutersOnIpfsNodes:setHttpRouterOptionsOnIpfsNode");
|
|
8583
|
-
const routingKey = "Routing";
|
|
8584
|
-
let routingConfigBeforeChanging;
|
|
8585
|
-
try {
|
|
8586
|
-
routingConfigBeforeChanging = await kuboClient._client.config.get(routingKey);
|
|
8587
|
-
} catch (e) {
|
|
8588
|
-
const error = new PKCError("ERR_FAILED_TO_GET_CONFIG_ON_KUBO_NODE", {
|
|
8589
|
-
actualError: e,
|
|
8590
|
-
kuboEndpoint: kuboClient._clientOptions.url,
|
|
8591
|
-
configKey: routingKey
|
|
8592
|
-
});
|
|
8593
|
-
log.error(e);
|
|
8594
|
-
throw error;
|
|
8595
|
-
}
|
|
8596
|
-
const mergedRoutingValue = _mergeRouterConfigs(routingConfigBeforeChanging, routingValue);
|
|
8597
|
-
const url = `${kuboClient._clientOptions.url}/config?arg=${routingKey}&arg=${JSON.stringify(mergedRoutingValue)}&json=true`;
|
|
8598
|
-
try {
|
|
8599
|
-
await fetch(url, {
|
|
8600
|
-
method: "POST",
|
|
8601
|
-
headers: kuboClient._clientOptions.headers
|
|
8602
|
-
});
|
|
8603
|
-
} catch (e) {
|
|
8604
|
-
const error = new PKCError("ERR_FAILED_TO_SET_CONFIG_ON_KUBO_NODE", {
|
|
8605
|
-
fullUrl: url,
|
|
8606
|
-
actualError: e,
|
|
8607
|
-
kuboEndpoint: kuboClient._clientOptions.url,
|
|
8608
|
-
configKey: routingKey,
|
|
8609
|
-
configValueToBeSet: mergedRoutingValue
|
|
8610
|
-
});
|
|
8611
|
-
log.error(e);
|
|
8612
|
-
throw error;
|
|
8613
|
-
}
|
|
8614
|
-
log.trace("Succeeded in setting config key", routingKey, "on node", kuboClient._clientOptions.url, "to be", mergedRoutingValue);
|
|
8615
|
-
await _setProvideDhtSweepEnabledOnKuboNode(kuboClient, false);
|
|
8616
|
-
const endpointsBefore = Object.values(routingConfigBeforeChanging?.Routers || {}).map((router) => router.Parameters?.Endpoint).filter((endpoint) => endpoint !== void 0);
|
|
8617
|
-
const endpointsAfter = Object.values(mergedRoutingValue.Routers).map((router) => router.Parameters?.Endpoint).filter((endpoint) => endpoint !== void 0);
|
|
8618
|
-
if (!t$3(endpointsBefore.sort(), endpointsAfter.sort())) {
|
|
8619
|
-
log("Config on kubo node has been changed. PKC-js will send shutdown command to node", kuboClient._clientOptions.url, "Clients of pkc-js should restart ipfs node");
|
|
8620
|
-
const shutdownUrl = `${kuboClient._clientOptions.url}/shutdown`;
|
|
8621
|
-
try {
|
|
8622
|
-
await fetch(shutdownUrl, {
|
|
8623
|
-
method: "POST",
|
|
8624
|
-
headers: kuboClient._clientOptions.headers
|
|
8625
|
-
});
|
|
8626
|
-
} catch (e) {
|
|
8627
|
-
const error = new PKCError("ERR_FAILED_TO_SHUTDOWN_KUBO_NODE", {
|
|
8628
|
-
actualError: e,
|
|
8629
|
-
kuboEndpoint: kuboClient._clientOptions.url,
|
|
8630
|
-
shutdownUrl
|
|
8631
|
-
});
|
|
8632
|
-
log.error(e);
|
|
8633
|
-
throw error;
|
|
8634
|
-
}
|
|
8635
|
-
}
|
|
8636
|
-
}
|
|
8637
|
-
async function _getStartedProxyUrl(pkc, httpRouterUrl) {
|
|
8638
|
-
if (pkc.destroyed) return void 0;
|
|
8639
|
-
const mappingKeyName = `httprouter_proxy_${httpRouterUrl}`;
|
|
8640
|
-
try {
|
|
8641
|
-
const urlOfProxyOfHttpRouter = await pkc._storage.getItem(mappingKeyName);
|
|
8642
|
-
if (pkc.destroyed) return void 0;
|
|
8643
|
-
if (urlOfProxyOfHttpRouter) {
|
|
8644
|
-
const proxyHttpUrl = new URL(urlOfProxyOfHttpRouter);
|
|
8645
|
-
if (await import_tcp_port_used.check(Number(proxyHttpUrl.port), "127.0.0.1")) return urlOfProxyOfHttpRouter;
|
|
8646
|
-
if (pkc.destroyed) return void 0;
|
|
8647
|
-
await pkc._storage.removeItem(mappingKeyName);
|
|
8648
|
-
}
|
|
8649
|
-
return;
|
|
8650
|
-
} catch (error) {
|
|
8651
|
-
if (pkc.destroyed && error instanceof Error && error.message.includes("database connection is not open")) return;
|
|
8652
|
-
throw error;
|
|
8653
|
-
}
|
|
8654
|
-
}
|
|
8655
|
-
async function setupKuboAddressesRewriterAndHttpRouters(pkc) {
|
|
8656
|
-
if (pkc.destroyed) return { destroy: async () => {} };
|
|
8657
|
-
if (!Array.isArray(pkc.kuboRpcClientsOptions) || pkc.kuboRpcClientsOptions.length <= 0) throw Error("need ipfs http client to be defined");
|
|
8658
|
-
if (!Array.isArray(pkc.httpRoutersOptions) || pkc.httpRoutersOptions.length <= 0) throw Error("Need http router options to defined");
|
|
8659
|
-
logger_default("pkc-js:node:setupKuboAddressesRewriterAndHttpRouters");
|
|
8660
|
-
const httpRouterProxyUrls = [];
|
|
8661
|
-
const proxyServers = [];
|
|
8662
|
-
const parsedStartPortOverride = Number(process.env.PKC_ADDRESSES_REWRITER_START_PORT);
|
|
8663
|
-
let addressesRewriterStartPort = Number.isInteger(parsedStartPortOverride) && parsedStartPortOverride > 0 && parsedStartPortOverride <= MAX_TCP_PORT ? parsedStartPortOverride : 19575;
|
|
8664
|
-
for (const httpRouter of pkc.httpRoutersOptions) {
|
|
8665
|
-
if (pkc.destroyed) break;
|
|
8666
|
-
const startedProxyUrl = await _getStartedProxyUrl(pkc, httpRouter);
|
|
8667
|
-
if (startedProxyUrl) {
|
|
8668
|
-
httpRouterProxyUrls.push(startedProxyUrl);
|
|
8669
|
-
continue;
|
|
8670
|
-
}
|
|
8671
|
-
let port = addressesRewriterStartPort;
|
|
8672
|
-
const hostname = "127.0.0.1";
|
|
8673
|
-
while (await import_tcp_port_used.check(port, hostname)) {
|
|
8674
|
-
port++;
|
|
8675
|
-
if (port > MAX_TCP_PORT) throw Error(`No free loopback port for the addresses rewriter proxy between ${addressesRewriterStartPort} and ${MAX_TCP_PORT}`);
|
|
8676
|
-
}
|
|
8677
|
-
const addressesRewriterProxyServer = new AddressesRewriterProxyServer({
|
|
8678
|
-
kuboClients: Object.values(pkc.clients.kuboRpcClients).map((kubo) => kubo._client),
|
|
8679
|
-
port,
|
|
8680
|
-
hostname,
|
|
8681
|
-
proxyTargetUrl: httpRouter,
|
|
8682
|
-
pkc
|
|
8683
|
-
});
|
|
8684
|
-
await addressesRewriterProxyServer.listen();
|
|
8685
|
-
if (pkc.destroyed) {
|
|
8686
|
-
await addressesRewriterProxyServer.destroy();
|
|
8687
|
-
break;
|
|
8688
|
-
}
|
|
8689
|
-
proxyServers.push(addressesRewriterProxyServer);
|
|
8690
|
-
const httpRouterProxyUrl = `http://${hostname}:${port}`;
|
|
8691
|
-
httpRouterProxyUrls.push(httpRouterProxyUrl);
|
|
8692
|
-
}
|
|
8693
|
-
httpRouterProxyUrls.sort();
|
|
8694
|
-
const kuboClients = pkc.clients.kuboRpcClients;
|
|
8695
|
-
const parallelRouters = [];
|
|
8696
|
-
const httpRoutersConfig = {
|
|
8697
|
-
HttpRoutersParallel: {
|
|
8698
|
-
Type: "parallel",
|
|
8699
|
-
Parameters: { Routers: parallelRouters }
|
|
8700
|
-
},
|
|
8701
|
-
HttpRouterNotSupported: {
|
|
8702
|
-
Type: "http",
|
|
8703
|
-
Parameters: { Endpoint: "http://kubohttprouternotsupported" }
|
|
8704
|
-
}
|
|
8705
|
-
};
|
|
8706
|
-
for (const [i, httpRouterUrl] of httpRouterProxyUrls.entries()) {
|
|
8707
|
-
const RouterName = `HttpRouter${i + 1}`;
|
|
8708
|
-
httpRoutersConfig[RouterName] = {
|
|
8709
|
-
Type: "http",
|
|
8710
|
-
Parameters: { Endpoint: httpRouterUrl }
|
|
8711
|
-
};
|
|
8712
|
-
parallelRouters[i] = {
|
|
8713
|
-
RouterName,
|
|
8714
|
-
IgnoreErrors: true,
|
|
8715
|
-
Timeout: "10s"
|
|
8716
|
-
};
|
|
8717
|
-
}
|
|
8718
|
-
const routingValue = {
|
|
8719
|
-
Type: "custom",
|
|
8720
|
-
Methods: {
|
|
8721
|
-
"find-providers": { RouterName: "HttpRoutersParallel" },
|
|
8722
|
-
provide: { RouterName: "HttpRoutersParallel" },
|
|
8723
|
-
"find-peers": { RouterName: "HttpRouterNotSupported" },
|
|
8724
|
-
"get-ipns": { RouterName: "HttpRouterNotSupported" },
|
|
8725
|
-
"put-ipns": { RouterName: "HttpRouterNotSupported" }
|
|
8726
|
-
},
|
|
8727
|
-
Routers: httpRoutersConfig
|
|
8728
|
-
};
|
|
8729
|
-
const settingOptionRetryOption = import_retry.operation({
|
|
8730
|
-
forever: true,
|
|
8731
|
-
factor: 2,
|
|
8732
|
-
maxTimeout: 60 * 1e3
|
|
8733
|
-
});
|
|
8734
|
-
await new Promise((resolve) => {
|
|
8735
|
-
settingOptionRetryOption.attempt(async (curAttempt) => {
|
|
8736
|
-
for (const kuboClient of Object.values(kuboClients)) try {
|
|
8737
|
-
await _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue);
|
|
8738
|
-
} catch (e) {
|
|
8739
|
-
settingOptionRetryOption.retry(e);
|
|
8740
|
-
return;
|
|
8741
|
-
}
|
|
8742
|
-
resolve(1);
|
|
8743
|
-
});
|
|
8744
|
-
});
|
|
8745
|
-
settingOptionRetryOption.stop();
|
|
8746
|
-
return { destroy: async () => {
|
|
8747
|
-
for (const proxyServer of proxyServers) await proxyServer.destroy();
|
|
8748
|
-
} };
|
|
8749
|
-
}
|
|
8750
|
-
//#endregion
|
|
8751
|
-
//#region dist/node/publications/community-edit/community-edit.js
|
|
8752
|
-
var CommunityEdit = class extends Publication {
|
|
8753
|
-
constructor(pkc) {
|
|
8754
|
-
super(pkc);
|
|
8755
|
-
this.raw = {};
|
|
8756
|
-
this.publish = this.publish.bind(this);
|
|
8757
|
-
hideClassPrivateProps(this);
|
|
8758
|
-
}
|
|
8759
|
-
_initUnsignedLocalProps(opts) {
|
|
8760
|
-
super._initUnsignedLocalProps(opts);
|
|
8761
|
-
const o = opts.unsignedOptions;
|
|
8762
|
-
this.communityEdit = o.communityEdit;
|
|
8763
|
-
}
|
|
8764
|
-
_initLocalProps(props) {
|
|
8765
|
-
this._initRemoteProps(props.communityEdit);
|
|
8766
|
-
this.challengeRequest = props.challengeRequest;
|
|
8767
|
-
this.signer = props.signer;
|
|
8768
|
-
}
|
|
8769
|
-
async _signPublicationOptionsToPublish(cleanedPublication) {
|
|
8770
|
-
return signCommunityEdit({
|
|
8771
|
-
communityEdit: cleanedPublication,
|
|
8772
|
-
pkc: this._pkc
|
|
8773
|
-
});
|
|
8774
|
-
}
|
|
8775
|
-
_initRemoteProps(props) {
|
|
8776
|
-
super._initBaseRemoteProps(props);
|
|
8777
|
-
this.communityEdit = props.communityEdit;
|
|
8778
|
-
this.raw.pubsubMessageToPublish = props;
|
|
8779
|
-
}
|
|
8780
|
-
getType() {
|
|
8781
|
-
return "communityEdit";
|
|
8782
|
-
}
|
|
8783
|
-
async _validateSignatureHook() {
|
|
8784
|
-
const signatureValidity = await verifyCommunityEdit({
|
|
8785
|
-
communityEdit: JSON.parse(JSON.stringify(this.raw.pubsubMessageToPublish)),
|
|
8786
|
-
resolveAuthorNames: this._pkc.resolveAuthorNames,
|
|
8787
|
-
clientsManager: this._clientsManager
|
|
8788
|
-
});
|
|
8789
|
-
if (!signatureValidity.valid) throw new PKCError("ERR_SIGNATURE_IS_INVALID", { signatureValidity });
|
|
8790
|
-
}
|
|
8791
|
-
};
|
|
6769
|
+
_initUnsignedLocalProps(opts) {
|
|
6770
|
+
super._initUnsignedLocalProps(opts);
|
|
6771
|
+
const o = opts.unsignedOptions;
|
|
6772
|
+
this.communityEdit = o.communityEdit;
|
|
6773
|
+
}
|
|
6774
|
+
_initLocalProps(props) {
|
|
6775
|
+
this._initRemoteProps(props.communityEdit);
|
|
6776
|
+
this.challengeRequest = props.challengeRequest;
|
|
6777
|
+
this.signer = props.signer;
|
|
6778
|
+
}
|
|
6779
|
+
async _signPublicationOptionsToPublish(cleanedPublication) {
|
|
6780
|
+
return signCommunityEdit({
|
|
6781
|
+
communityEdit: cleanedPublication,
|
|
6782
|
+
pkc: this._pkc
|
|
6783
|
+
});
|
|
6784
|
+
}
|
|
6785
|
+
_initRemoteProps(props) {
|
|
6786
|
+
super._initBaseRemoteProps(props);
|
|
6787
|
+
this.communityEdit = props.communityEdit;
|
|
6788
|
+
this.raw.pubsubMessageToPublish = props;
|
|
6789
|
+
}
|
|
6790
|
+
getType() {
|
|
6791
|
+
return "communityEdit";
|
|
6792
|
+
}
|
|
6793
|
+
async _validateSignatureHook() {
|
|
6794
|
+
const signatureValidity = await verifyCommunityEdit({
|
|
6795
|
+
communityEdit: JSON.parse(JSON.stringify(this.raw.pubsubMessageToPublish)),
|
|
6796
|
+
resolveAuthorNames: this._pkc.resolveAuthorNames,
|
|
6797
|
+
clientsManager: this._clientsManager
|
|
6798
|
+
});
|
|
6799
|
+
if (!signatureValidity.valid) throw new PKCError("ERR_SIGNATURE_IS_INVALID", { signatureValidity });
|
|
6800
|
+
}
|
|
6801
|
+
};
|
|
8792
6802
|
//#endregion
|
|
8793
6803
|
//#region dist/node/pkc/pkc.js
|
|
8794
6804
|
var PKC$1 = class extends PKCTypedEmitter {
|
|
@@ -8798,6 +6808,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8798
6808
|
this._updatingCommunities = new TrackedInstanceRegistry();
|
|
8799
6809
|
this._updatingComments = new TrackedInstanceRegistry();
|
|
8800
6810
|
this._startedCommunities = new TrackedInstanceRegistry();
|
|
6811
|
+
this._publishingPublications = /* @__PURE__ */ new Set();
|
|
8801
6812
|
this.destroyed = false;
|
|
8802
6813
|
this._storageLRUs = {};
|
|
8803
6814
|
this._timeouts = {
|
|
@@ -8917,7 +6928,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8917
6928
|
this.clients.libp2pJsClients = {};
|
|
8918
6929
|
if (!this.libp2pJsClientsOptions) return;
|
|
8919
6930
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
8920
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
6931
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-CQY3-UYD.js");
|
|
8921
6932
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
8922
6933
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
8923
6934
|
...clientOptions,
|
|
@@ -8941,23 +6952,19 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
8941
6952
|
const log = logger_default("pkc-js:pkc:_initHttpRoutersWithIpfsInBackground");
|
|
8942
6953
|
if (this.destroyed) return;
|
|
8943
6954
|
if (this.httpRoutersOptions?.length && this.kuboRpcClientsOptions?.length && this._canCreateNewLocalCommunity()) {
|
|
8944
|
-
const setupPromise =
|
|
8945
|
-
if (this.destroyed)
|
|
8946
|
-
|
|
8947
|
-
return;
|
|
8948
|
-
}
|
|
8949
|
-
log("Set http router options and their proxies successfully on all connected ipfs", Object.keys(this.clients.kuboRpcClients));
|
|
8950
|
-
this._addressRewriterDestroy = addressesRewriterProxyServer.destroy;
|
|
6955
|
+
const setupPromise = setupKuboHttpRouters(this).then(() => {
|
|
6956
|
+
if (this.destroyed) return;
|
|
6957
|
+
log("Set http router options successfully on all connected ipfs", Object.keys(this.clients.kuboRpcClients));
|
|
8951
6958
|
}).catch((e) => {
|
|
8952
6959
|
if (this.destroyed) return;
|
|
8953
|
-
log.error("Failed to set http router options
|
|
6960
|
+
log.error("Failed to set http router options on ipfs nodes due to error", e);
|
|
8954
6961
|
this.emit("error", e);
|
|
8955
6962
|
});
|
|
8956
|
-
this.
|
|
6963
|
+
this._httpRouterSetupPromise = setupPromise;
|
|
8957
6964
|
}
|
|
8958
6965
|
}
|
|
8959
6966
|
async _waitForHttpRoutersSetupToSettle() {
|
|
8960
|
-
if (this.
|
|
6967
|
+
if (this._httpRouterSetupPromise) await this._httpRouterSetupPromise;
|
|
8961
6968
|
}
|
|
8962
6969
|
async _init() {
|
|
8963
6970
|
const log = logger_default("pkc-js:pkc:_init");
|
|
@@ -9021,6 +7028,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
9021
7028
|
}
|
|
9022
7029
|
if (e$1(cleanedAuthor)) cleanedAuthor = void 0;
|
|
9023
7030
|
}
|
|
7031
|
+
if ("crosspost" in finalOptions && finalOptions.crosspost) stripNameResolvedFromCrosspost(finalOptions.crosspost);
|
|
9024
7032
|
const filledTimestamp = typeof finalOptions.timestamp !== "number" ? timestamp() : finalOptions.timestamp;
|
|
9025
7033
|
const filledSigner = await this.createSigner(finalOptions.signer);
|
|
9026
7034
|
const filledProtocolVersion = finalOptions.protocolVersion || version_default.PROTOCOL_VERSION;
|
|
@@ -9069,6 +7077,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
9069
7077
|
if ("commentUpdateFromChallengeVerification" in options.raw && options.raw.commentUpdateFromChallengeVerification) commentInstance._initCommentUpdateFromChallengeVerificationProps(options.raw.commentUpdateFromChallengeVerification);
|
|
9070
7078
|
if (options.raw.commentUpdate) commentInstance._initCommentUpdate(options.raw.commentUpdate);
|
|
9071
7079
|
if (commentInstance.author?.nameResolved !== void 0) delete commentInstance.author.nameResolved;
|
|
7080
|
+
if (commentInstance.crosspost) stripNameResolvedFromCrosspost(commentInstance.crosspost);
|
|
9072
7081
|
return commentInstance;
|
|
9073
7082
|
}
|
|
9074
7083
|
async createComment(options) {
|
|
@@ -9087,6 +7096,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
9087
7096
|
if (!("signature" in options)) Object.assign(commentInstance, options);
|
|
9088
7097
|
else commentInstance._initIpfsProps(parseCommentIpfsSchemaWithPKCErrorIfItFails(commentIpfs));
|
|
9089
7098
|
if (commentInstance.author?.nameResolved !== void 0) delete commentInstance.author.nameResolved;
|
|
7099
|
+
if (commentInstance.crosspost) stripNameResolvedFromCrosspost(commentInstance.crosspost);
|
|
9090
7100
|
} else if ("signature" in options) {
|
|
9091
7101
|
const parsedOptions = parseCommentPubsubMessagePublicationWithPKCErrorIfItFails(options);
|
|
9092
7102
|
commentInstance._initPubsubMessageProps(parsedOptions);
|
|
@@ -9166,7 +7176,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
9166
7176
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
9167
7177
|
log.trace("Received community options to create a local community instance:", options);
|
|
9168
7178
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
9169
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
7179
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-AZAEiiht.js");
|
|
9170
7180
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
9171
7181
|
const community = new LocalCommunity(this);
|
|
9172
7182
|
if (isLocalCommunity) {
|
|
@@ -9540,17 +7550,15 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
9540
7550
|
}
|
|
9541
7551
|
}
|
|
9542
7552
|
if (exportDonePromises.length) await Promise.all(exportDonePromises);
|
|
7553
|
+
await Promise.all([...this._publishingPublications].map((publication) => publication.stop().catch((e) => log.error("Error stopping publication during destroy", e))));
|
|
7554
|
+
this._publishingPublications.clear();
|
|
9543
7555
|
for (const comment of listUpdatingComments(this)) await comment.stop();
|
|
9544
7556
|
for (const community of listUpdatingCommunities(this)) await community.stop();
|
|
9545
7557
|
await Promise.all(listStartedCommunities(this).map((community) => community.stop()));
|
|
9546
7558
|
if (this._communityFsWatchAbort) this._communityFsWatchAbort.abort();
|
|
9547
|
-
if (this.
|
|
9548
|
-
await this.
|
|
9549
|
-
this.
|
|
9550
|
-
}
|
|
9551
|
-
if (this._addressRewriterDestroy) {
|
|
9552
|
-
await this._addressRewriterDestroy();
|
|
9553
|
-
this._addressRewriterDestroy = void 0;
|
|
7559
|
+
if (this._httpRouterSetupPromise) {
|
|
7560
|
+
await this._httpRouterSetupPromise;
|
|
7561
|
+
this._httpRouterSetupPromise = void 0;
|
|
9554
7562
|
}
|
|
9555
7563
|
await this._storage.destroy();
|
|
9556
7564
|
for (const storage of Object.values(this._storageLRUs)) await storage.destroy();
|