refactor(platform): runtime mixins and export manifest (Phase 738)
Extract _hyperswarmOpts/_newHyperswarm and _startupStepTimeout to platform-hyperswarm-runtime-mixin and platform-session-startup-mixin (62 manifest rows). Add platform-class-imports and platform-index-export-manifest; registries derive counts from manifest. No behavior change. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -54,6 +54,8 @@ Application facade: one `PearcordPlatform` class that wires identity, database,
|
||||
|
||||
**Phase 723 (v0.8.699):** Dedicated slash registry & invoke audit export JSON — `slash-registry-json-mixin.js`, `slash-invoke-audit-json-mixin.js`, spans `slash-registry.json` / `slash-invoke-audit.json`, `getSlashInvokeAuditExportJsonExport`, `clearSlashInvokeAuditExportJsonExports`, deep links `openSlashRegistryJson` / `openSlashInvokeAuditJson`. Bundle: `npm run test:ci-phase723`.
|
||||
|
||||
**Phase 738 (v0.8.714):** `platform-hyperswarm-runtime-mixin.js`, `platform-session-startup-mixin.js` (62 mixin rows); `platform-class-imports.js`, `platform-index-export-manifest.js`. Bundle: `npm run test:ci-phase738`.
|
||||
|
||||
**Phase 737 (v0.8.713):** `platform-pearcord-platform-class.js` holds `PearcordPlatform`; `platform-index-bindings.js` unpacks preamble; `index.js` thin entry (≤12 lines). Bundle: `npm run test:ci-phase737`.
|
||||
|
||||
**Phase 736 (v0.8.712):** `platform-index-preamble.js` centralizes 92 import bindings; `platform-index-preamble-registry.js`. Bundle: `npm run test:ci-phase736`.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('bare-fs')
|
||||
const path = require('bare-path')
|
||||
const b4a = require('b4a')
|
||||
const EventEmitter = require('bare-events')
|
||||
const bindings = require('./platform-index-bindings')
|
||||
|
||||
module.exports = {
|
||||
fs,
|
||||
path,
|
||||
b4a,
|
||||
EventEmitter,
|
||||
...bindings
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
const Hyperswarm = require('hyperswarm')
|
||||
|
||||
/** Hyperswarm construction helpers (extracted from PearcordPlatform, Phase 738). */
|
||||
const platformHyperswarmRuntimeMixin = {
|
||||
_hyperswarmOpts (keyPair) {
|
||||
const o = { keyPair }
|
||||
if (this._hyperswarmDht) o.dht = this._hyperswarmDht
|
||||
return o
|
||||
},
|
||||
|
||||
_newHyperswarm (keyPair) {
|
||||
return new Hyperswarm(this._hyperswarmOpts(keyPair))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformHyperswarmRuntimeMixin }
|
||||
@@ -3,8 +3,10 @@
|
||||
/** Runtime bindings unpacked from preamble for the platform class (Phase 737). */
|
||||
const INDEX_BINDINGS_MODULE = './platform-index-bindings'
|
||||
|
||||
const { INDEX_TOP_LEVEL_BINDING_KEY_COUNT } = require('./platform-index-export-manifest')
|
||||
|
||||
/** Preamble exports (92) plus id/now/guildTopic top-level aliases. */
|
||||
const INDEX_BINDINGS_EXPORT_COUNT = 95
|
||||
const INDEX_BINDINGS_EXPORT_COUNT = INDEX_TOP_LEVEL_BINDING_KEY_COUNT
|
||||
|
||||
module.exports = {
|
||||
INDEX_BINDINGS_MODULE,
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
'use strict'
|
||||
|
||||
const { INDEX_IMPORT_SCOPES, INDEX_IMPORT_SCOPE_COUNT } = require('./platform-index-scope-registry')
|
||||
|
||||
const INDEX_PREAMBLE_EXPORT_KEYS = [
|
||||
'swarmScope',
|
||||
'dmScope',
|
||||
'appEventsScope',
|
||||
'automationScope',
|
||||
'deliveryScope',
|
||||
'integrationScope',
|
||||
'botAuthScope',
|
||||
'cryptoScope',
|
||||
'threadsScope',
|
||||
'searchScope',
|
||||
'channelMetaScope',
|
||||
'localScope',
|
||||
'foldersScope',
|
||||
'enrichmentScope',
|
||||
'sharedScope',
|
||||
'permissionsScope',
|
||||
'hyperdbScope',
|
||||
'createLogger',
|
||||
'LocalDatabase',
|
||||
'PearcordIdentity',
|
||||
'resolveStoragePath',
|
||||
'writeOnboardedMarker',
|
||||
'PearcordGuild',
|
||||
'GuildReplicator',
|
||||
'GuildSidecarStore',
|
||||
'PearcordMessage',
|
||||
'PearcordPresence',
|
||||
'PearcordInvite',
|
||||
'DmVideoFramePublisher',
|
||||
'PearcordAttachments',
|
||||
'PearcordVoiceNotes',
|
||||
'canSendVoiceNote',
|
||||
'PearcordModeration',
|
||||
'PearcordVoice',
|
||||
'VoiceMediaHub',
|
||||
'PearcordDmVoice',
|
||||
'VoiceCaptureFeed',
|
||||
'PearcordSlashRegistry',
|
||||
'parseSlashInvocation',
|
||||
'PearcordEmojiRegistry',
|
||||
'buildEmojiSlotSnapshot',
|
||||
'BotEventFanout',
|
||||
'BOT_EVENTS',
|
||||
'exportBodyFromSlice',
|
||||
'PearcordIntegrationWorker',
|
||||
'INTENTS',
|
||||
'BotRateLimits',
|
||||
'PearcordStepUp',
|
||||
'PearcordForum',
|
||||
'PearcordStage',
|
||||
'STAGE_ROLE',
|
||||
'isStageChannel',
|
||||
'PearcordAutomod',
|
||||
'PearcordWebhooks',
|
||||
'ScreenShareHub',
|
||||
'broadcastScreenMedia',
|
||||
'DisplayCaptureFeed',
|
||||
'PearcordAnnouncements',
|
||||
'formatCrosspostBody',
|
||||
'PearcordBoosts',
|
||||
'MAX_BOOSTS',
|
||||
'MAX_SLOTS_PER_USER',
|
||||
'PearcordStickerRegistry',
|
||||
'PearcordSoundboardRegistry',
|
||||
'decodeSoundToPcm',
|
||||
'ALLOWED_MIMES',
|
||||
'PearcordAnnouncementHub',
|
||||
'formatRemoteHubBody',
|
||||
'buildHubMirrorCard',
|
||||
'formatHubMirrorFallback',
|
||||
'PearcordContacts',
|
||||
'PearcordNotifications',
|
||||
'PearcordSettings',
|
||||
'UserPrefsMirrorStore',
|
||||
'DmCallHistoryStore',
|
||||
'PearcordProfileCosmetics',
|
||||
'enrichProfileCosmeticGossip',
|
||||
'enrichGuildUpdateGossip',
|
||||
'pickBannerHash',
|
||||
'PearcordDeviceSync',
|
||||
'PearcordDiscovery',
|
||||
'collectDiscoveryTags',
|
||||
'getListingTtlMs',
|
||||
'getGuildDrive',
|
||||
'isHexDriveKey',
|
||||
'fetchFromProvider',
|
||||
'PearcordEmbed',
|
||||
'forumPostHaystack',
|
||||
'buildActivityFeed',
|
||||
'enrichActivityWithAttachments',
|
||||
'IPC_CONTRACT_VERSION',
|
||||
'Hyperswarm'
|
||||
]
|
||||
|
||||
const INDEX_TOP_LEVEL_BINDING_KEYS = [
|
||||
...INDEX_PREAMBLE_EXPORT_KEYS,
|
||||
'id',
|
||||
'now',
|
||||
'guildTopic'
|
||||
]
|
||||
|
||||
const INDEX_PREAMBLE_EXPORT_KEY_COUNT = INDEX_PREAMBLE_EXPORT_KEYS.length
|
||||
const INDEX_TOP_LEVEL_BINDING_KEY_COUNT = INDEX_TOP_LEVEL_BINDING_KEYS.length
|
||||
|
||||
const preambleScopeCount = INDEX_PREAMBLE_EXPORT_KEYS.filter((k) => k.endsWith('Scope')).length
|
||||
if (preambleScopeCount !== INDEX_IMPORT_SCOPE_COUNT) {
|
||||
throw new Error(`preamble scope keys ${preambleScopeCount} !== registry ${INDEX_IMPORT_SCOPE_COUNT}`)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
INDEX_PREAMBLE_EXPORT_KEYS,
|
||||
INDEX_TOP_LEVEL_BINDING_KEYS,
|
||||
INDEX_PREAMBLE_EXPORT_KEY_COUNT,
|
||||
INDEX_TOP_LEVEL_BINDING_KEY_COUNT
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
/** Flat + scope bindings re-exported from `platform-index-preamble.js` (Phase 736). */
|
||||
const INDEX_PREAMBLE_MODULE = './platform-index-preamble'
|
||||
|
||||
const INDEX_PREAMBLE_EXPORT_COUNT = 92
|
||||
const { INDEX_PREAMBLE_EXPORT_KEY_COUNT } = require('./platform-index-export-manifest')
|
||||
|
||||
const INDEX_PREAMBLE_EXPORT_COUNT = INDEX_PREAMBLE_EXPORT_KEY_COUNT
|
||||
|
||||
module.exports = {
|
||||
INDEX_PREAMBLE_MODULE,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Ordered PearcordPlatform prototype mixin registration (Phase 730).
|
||||
* Preserves assign order from index.js / apply-platform-mixins (Phase 727).
|
||||
*/
|
||||
const PLATFORM_MIXIN_ASSIGNMENT_COUNT = 60
|
||||
const PLATFORM_MIXIN_ASSIGNMENT_COUNT = 62
|
||||
|
||||
const PLATFORM_MIXIN_ASSIGNMENTS = [
|
||||
{ module: './polls-scheduling', export: 'pollSchedulingMixin' },
|
||||
@@ -66,6 +66,8 @@ const PLATFORM_MIXIN_ASSIGNMENTS = [
|
||||
{ module: './slash-invoke-audit-json-mixin', export: 'slashInvokeAuditJsonMixin' },
|
||||
{ module: './worker-release-json-mixin', export: 'workerReleaseJsonMixin' },
|
||||
{ module: './integration-manifest-json-mixin', export: 'integrationManifestJsonMixin' },
|
||||
{ module: './platform-hyperswarm-runtime-mixin', export: 'platformHyperswarmRuntimeMixin' },
|
||||
{ module: './platform-session-startup-mixin', export: 'platformSessionStartupMixin' },
|
||||
{ module: './platform-diagnostics-mixin', export: 'platformDiagnosticsMixin' }
|
||||
]
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('bare-fs')
|
||||
const path = require('bare-path')
|
||||
const b4a = require('b4a')
|
||||
const EventEmitter = require('bare-events')
|
||||
const {
|
||||
fs, path, b4a, EventEmitter,
|
||||
swarmScope, dmScope, appEventsScope, automationScope,
|
||||
deliveryScope, integrationScope, botAuthScope, cryptoScope,
|
||||
threadsScope, searchScope, channelMetaScope, localScope,
|
||||
@@ -29,7 +26,7 @@ const {
|
||||
isHexDriveKey, fetchFromProvider, PearcordEmbed, forumPostHaystack,
|
||||
buildActivityFeed, enrichActivityWithAttachments, IPC_CONTRACT_VERSION, Hyperswarm,
|
||||
id, now, guildTopic
|
||||
} = require('./platform-index-bindings')
|
||||
} = require('./platform-class-imports')
|
||||
|
||||
class PearcordPlatform extends EventEmitter {
|
||||
constructor (opts = {}) {
|
||||
@@ -2211,16 +2208,6 @@ class PearcordPlatform extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
_hyperswarmOpts (keyPair) {
|
||||
const o = { keyPair }
|
||||
if (this._hyperswarmDht) o.dht = this._hyperswarmDht
|
||||
return o
|
||||
}
|
||||
|
||||
_newHyperswarm (keyPair) {
|
||||
return new Hyperswarm(this._hyperswarmOpts(keyPair))
|
||||
}
|
||||
|
||||
get guildOpenNoViewableChannels () {
|
||||
return !!this._guildOpenNoViewableChannels
|
||||
}
|
||||
@@ -2308,28 +2295,6 @@ class PearcordPlatform extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
_startupStepTimeout (promise, ms, label) {
|
||||
const cap = Math.max(500, Number(ms) || 8000)
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve({ timedOut: true, label }), cap)
|
||||
})
|
||||
]).then((result) => {
|
||||
if (result && result.timedOut) {
|
||||
this.log.warn('session startup step timed out', { label, ms: cap })
|
||||
return null
|
||||
}
|
||||
return result
|
||||
}).catch((err) => {
|
||||
this.log.warn('session startup step failed', {
|
||||
label,
|
||||
err: err?.message || String(err)
|
||||
})
|
||||
return null
|
||||
})
|
||||
}
|
||||
|
||||
async _joinSessionStartupMeshes () {
|
||||
const meshMs = Number(process.env.PEARCORD_SESSION_MESH_MS) || 12000
|
||||
await this._startupStepTimeout(
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
|
||||
/** Session startup step timeout helper (extracted from PearcordPlatform, Phase 738). */
|
||||
const platformSessionStartupMixin = {
|
||||
_startupStepTimeout (promise, ms, label) {
|
||||
const cap = Math.max(500, Number(ms) || 8000)
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve({ timedOut: true, label }), cap)
|
||||
})
|
||||
]).then((result) => {
|
||||
if (result && result.timedOut) {
|
||||
this.log.warn('session startup step timed out', { label, ms: cap })
|
||||
return null
|
||||
}
|
||||
return result
|
||||
}).catch((err) => {
|
||||
this.log.warn('session startup step failed', {
|
||||
label,
|
||||
err: err?.message || String(err)
|
||||
})
|
||||
return null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { platformSessionStartupMixin }
|
||||
Reference in New Issue
Block a user