@synra/protocol 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +128 -25
- package/dist/index.mjs +104 -2
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
+
//#region src/file-transfer.d.ts
|
|
2
|
+
/** Discriminator for file transfer payloads; extend in protocol when adding kinds. */
|
|
3
|
+
type FileTransferKind = 'plugin-bundle' | 'attachment';
|
|
4
|
+
type FileTransferRequestPayload = {
|
|
5
|
+
transferId: string;
|
|
6
|
+
kind: 'plugin-bundle';
|
|
7
|
+
pluginId: string;
|
|
8
|
+
version: string;
|
|
9
|
+
byteLength?: number;
|
|
10
|
+
syncSessionId?: string;
|
|
11
|
+
} | {
|
|
12
|
+
transferId: string;
|
|
13
|
+
kind: 'attachment';
|
|
14
|
+
fileName: string;
|
|
15
|
+
byteLength?: number;
|
|
16
|
+
mimeType?: string;
|
|
17
|
+
contextId?: string;
|
|
18
|
+
syncSessionId?: string;
|
|
19
|
+
};
|
|
20
|
+
type FileTransferChunkPayload = {
|
|
21
|
+
transferId: string;
|
|
22
|
+
kind: 'plugin-bundle';
|
|
23
|
+
pluginId: string;
|
|
24
|
+
version: string;
|
|
25
|
+
chunkIndex: number;
|
|
26
|
+
totalChunks: number;
|
|
27
|
+
chunkBase64: string;
|
|
28
|
+
syncSessionId?: string;
|
|
29
|
+
} | {
|
|
30
|
+
transferId: string;
|
|
31
|
+
kind: 'attachment';
|
|
32
|
+
fileName: string;
|
|
33
|
+
chunkIndex: number;
|
|
34
|
+
totalChunks: number;
|
|
35
|
+
chunkBase64: string;
|
|
36
|
+
syncSessionId?: string;
|
|
37
|
+
contextId?: string;
|
|
38
|
+
};
|
|
39
|
+
type FileTransferCompletePayload = {
|
|
40
|
+
transferId: string;
|
|
41
|
+
kind: 'plugin-bundle';
|
|
42
|
+
pluginId: string;
|
|
43
|
+
version: string;
|
|
44
|
+
totalChunks: number;
|
|
45
|
+
sha256?: string;
|
|
46
|
+
syncSessionId?: string;
|
|
47
|
+
} | {
|
|
48
|
+
transferId: string;
|
|
49
|
+
kind: 'attachment';
|
|
50
|
+
fileName: string;
|
|
51
|
+
totalChunks: number;
|
|
52
|
+
sha256?: string;
|
|
53
|
+
syncSessionId?: string;
|
|
54
|
+
contextId?: string;
|
|
55
|
+
};
|
|
56
|
+
type FileTransferAbortPayload = {
|
|
57
|
+
transferId: string;
|
|
58
|
+
reason?: string; /** Prefer values from SynraErrorCode when emitted by app logic. */
|
|
59
|
+
code?: string;
|
|
60
|
+
};
|
|
61
|
+
/** Session-level progress / checkpoint (optional wire event). Not TCP frame ACK. */
|
|
62
|
+
type FileTransferProgressPayload = {
|
|
63
|
+
transferId: string; /** Inclusive highest chunk index processed (0-based). */
|
|
64
|
+
receivedThroughChunkIndex: number;
|
|
65
|
+
syncSessionId?: string;
|
|
66
|
+
};
|
|
67
|
+
declare function fileTransferChunkCount(byteLength: number, chunkSize: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Outbound plugin-bundle chunks over `file.transfer.chunk` payloads (session layer).
|
|
70
|
+
* SYNRA-COMM::FILE_TRANSFER::SEND::CHUNK_ENCODE
|
|
71
|
+
*/
|
|
72
|
+
declare function iteratePluginBundleChunks(options: {
|
|
73
|
+
transferId: string;
|
|
74
|
+
buffer: Uint8Array;
|
|
75
|
+
chunkSize: number;
|
|
76
|
+
pluginId: string;
|
|
77
|
+
version: string;
|
|
78
|
+
syncSessionId?: string;
|
|
79
|
+
}): Generator<Extract<FileTransferChunkPayload, {
|
|
80
|
+
kind: 'plugin-bundle';
|
|
81
|
+
}>>;
|
|
82
|
+
/** Observable receive progress for UI/analytics later; no wire event required. */
|
|
83
|
+
type PluginBundleTransferProgressSnapshot = {
|
|
84
|
+
transferId: string;
|
|
85
|
+
pluginId: string;
|
|
86
|
+
version: string;
|
|
87
|
+
chunksReceived: number;
|
|
88
|
+
totalChunks: number;
|
|
89
|
+
bytesReceived: number;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Assembles plugin-bundle transfer chunks in memory (receive path).
|
|
93
|
+
* SYNRA-COMM::FILE_TRANSFER::RECEIVE::ASSEMBLE_BUFFER
|
|
94
|
+
*/
|
|
95
|
+
declare class PluginBundleTransferAssembly {
|
|
96
|
+
readonly transferId: string;
|
|
97
|
+
private readonly chunks;
|
|
98
|
+
private expectedTotalChunks;
|
|
99
|
+
private pluginId;
|
|
100
|
+
private version;
|
|
101
|
+
constructor(transferId: string);
|
|
102
|
+
/** Returns error message if chunk is invalid for this assembly. */
|
|
103
|
+
push(payload: Extract<FileTransferChunkPayload, {
|
|
104
|
+
kind: 'plugin-bundle';
|
|
105
|
+
}>): string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Chunk/session stats for progress bars or logging without `file.transfer.progress` on the wire.
|
|
108
|
+
*/
|
|
109
|
+
getProgressSnapshot(): PluginBundleTransferProgressSnapshot;
|
|
110
|
+
isComplete(): boolean;
|
|
111
|
+
/** Concatenates in chunk index order; only call when `isComplete()`. */
|
|
112
|
+
concat(): Uint8Array;
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
1
115
|
//#region src/lan-events.d.ts
|
|
2
116
|
/** Wire `LanFrame` type === `event`: payload uses this envelope (JSON). */
|
|
3
117
|
type LanWireEventEnvelope = {
|
|
@@ -55,7 +169,7 @@ type LanPairingUnpairRequiredPayload = {
|
|
|
55
169
|
* SYNRA-COMM::<Domain>::<Stage>::<NodeId>
|
|
56
170
|
*
|
|
57
171
|
* Domains:
|
|
58
|
-
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE
|
|
172
|
+
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE | FILE_TRANSFER
|
|
59
173
|
*
|
|
60
174
|
* Stages:
|
|
61
175
|
* CONNECT | SEND | RECEIVE | ACK | HEARTBEAT | CLOSE | ERROR
|
|
@@ -115,7 +229,7 @@ type ElectionMessageType = 'election.vote.request' | 'election.vote.response' |
|
|
|
115
229
|
type CustomMessageType = `custom.${string}`;
|
|
116
230
|
type SynraMessageType = LegacySynraMessageType | TransportMessageType | RelayMessageType | ClusterHostMessageType | ElectionMessageType | CustomMessageType;
|
|
117
231
|
type RuntimeMessageType = 'runtime.request' | 'runtime.received' | 'runtime.started' | 'runtime.finished' | 'runtime.error';
|
|
118
|
-
type PluginSyncMessageType = 'plugin.catalog.request' | 'plugin.catalog.response' | '
|
|
232
|
+
type PluginSyncMessageType = 'plugin.catalog.request' | 'plugin.catalog.response' | 'file.transfer.request' | 'file.transfer.chunk' | 'file.transfer.complete' | 'file.transfer.abort' | 'file.transfer.progress';
|
|
119
233
|
type ProtocolMessageType = RuntimeMessageType | PluginSyncMessageType;
|
|
120
234
|
type ShareDetectedPayload = {
|
|
121
235
|
inputType: 'text' | 'url' | 'file';
|
|
@@ -318,8 +432,11 @@ type RuntimeErrorPayload = {
|
|
|
318
432
|
details?: unknown;
|
|
319
433
|
};
|
|
320
434
|
type PluginCatalogRequestPayload = {
|
|
321
|
-
knownPluginIds?: string[];
|
|
435
|
+
knownPluginIds?: string[]; /** Registry keyword or full Synra package name; triggers npm metadata merge when non-empty. */
|
|
436
|
+
query?: string; /** Optional registry base URL used for npm metadata lookup. */
|
|
437
|
+
registryUrl?: string;
|
|
322
438
|
};
|
|
439
|
+
type SynraPluginManifestEntriesWire = Partial<Record<'ui' | 'host' | 'worker' | 'shared', string>>;
|
|
323
440
|
type PluginCatalogItem = {
|
|
324
441
|
pluginId: string;
|
|
325
442
|
version: string;
|
|
@@ -330,28 +447,12 @@ type PluginCatalogItem = {
|
|
|
330
447
|
icon?: string;
|
|
331
448
|
logoPath?: string;
|
|
332
449
|
packageName?: string;
|
|
450
|
+
entries?: SynraPluginManifestEntriesWire;
|
|
333
451
|
};
|
|
334
452
|
type PluginCatalogResponsePayload = {
|
|
335
453
|
plugins: PluginCatalogItem[];
|
|
336
454
|
generatedAt: number;
|
|
337
455
|
};
|
|
338
|
-
type PluginBundleRequestPayload = {
|
|
339
|
-
pluginId: string;
|
|
340
|
-
version: string;
|
|
341
|
-
};
|
|
342
|
-
type PluginBundleChunkPayload = {
|
|
343
|
-
pluginId: string;
|
|
344
|
-
version: string;
|
|
345
|
-
chunkIndex: number;
|
|
346
|
-
totalChunks: number;
|
|
347
|
-
chunkBase64: string;
|
|
348
|
-
};
|
|
349
|
-
type PluginBundleCompletePayload = {
|
|
350
|
-
pluginId: string;
|
|
351
|
-
version: string;
|
|
352
|
-
totalChunks: number;
|
|
353
|
-
sha256?: string;
|
|
354
|
-
};
|
|
355
456
|
type ProtocolPayloadByType = {
|
|
356
457
|
'runtime.request': RuntimeRequestPayload;
|
|
357
458
|
'runtime.received': RuntimeReceivedPayload;
|
|
@@ -360,13 +461,15 @@ type ProtocolPayloadByType = {
|
|
|
360
461
|
'runtime.error': RuntimeErrorPayload;
|
|
361
462
|
'plugin.catalog.request': PluginCatalogRequestPayload;
|
|
362
463
|
'plugin.catalog.response': PluginCatalogResponsePayload;
|
|
363
|
-
'
|
|
364
|
-
'
|
|
365
|
-
'
|
|
464
|
+
'file.transfer.request': FileTransferRequestPayload;
|
|
465
|
+
'file.transfer.chunk': FileTransferChunkPayload;
|
|
466
|
+
'file.transfer.complete': FileTransferCompletePayload;
|
|
467
|
+
'file.transfer.abort': FileTransferAbortPayload;
|
|
468
|
+
'file.transfer.progress': FileTransferProgressPayload;
|
|
366
469
|
};
|
|
367
470
|
type MessageByType<K extends keyof ProtocolPayloadByType> = ProtocolEnvelope<K, ProtocolPayloadByType[K]>;
|
|
368
471
|
type SynraRuntimeMessage = MessageByType<'runtime.request'> | MessageByType<'runtime.received'> | MessageByType<'runtime.started'> | MessageByType<'runtime.finished'> | MessageByType<'runtime.error'>;
|
|
369
|
-
type SynraPluginSyncMessage = MessageByType<'plugin.catalog.request'> | MessageByType<'plugin.catalog.response'> | MessageByType<'
|
|
472
|
+
type SynraPluginSyncMessage = MessageByType<'plugin.catalog.request'> | MessageByType<'plugin.catalog.response'> | MessageByType<'file.transfer.request'> | MessageByType<'file.transfer.chunk'> | MessageByType<'file.transfer.complete'> | MessageByType<'file.transfer.abort'> | MessageByType<'file.transfer.progress'>;
|
|
370
473
|
type SynraProtocolMessage = SynraRuntimeMessage | SynraPluginSyncMessage;
|
|
371
474
|
type SynraActionReceipt = {
|
|
372
475
|
ok: true;
|
|
@@ -390,4 +493,4 @@ declare function unknownToErrorMessage(error: unknown, fallback: string): string
|
|
|
390
493
|
declare function createMessage<TPayload>(input: Omit<SynraCrossDeviceMessage<SynraMessageType, TPayload>, 'protocolVersion'>): SynraCrossDeviceMessage<SynraMessageType, TPayload>;
|
|
391
494
|
declare function createProtocolMessage<TType extends keyof ProtocolPayloadByType>(input: Omit<ProtocolEnvelope<TType, ProtocolPayloadByType[TType]>, 'protocolVersion'>): ProtocolEnvelope<TType, ProtocolPayloadByType[TType]>;
|
|
392
495
|
//#endregion
|
|
393
|
-
export { ActionCompletedPayload, ActionExecutingPayload, ActionFailedPayload, ActionId, ActionProposedPayload, ClusterHostMessageType, CustomMessageType, DEFAULT_SYNRA_SCAN_BUDGET_MS, DEVICE_DISPLAY_NAME_CHANGED_EVENT, DEVICE_HOST_RETIRE_EVENT, DEVICE_MEMBER_OFFLINE_EVENT, DEVICE_PAIRING_PEER_RESET_EVENT, DEVICE_PAIRING_PREFIX, DEVICE_PAIRING_REQUEST_EVENT, DEVICE_PAIRING_RESPONSE_EVENT, DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT, DEVICE_TCP_ACK_EVENT, DEVICE_TCP_CLOSE_EVENT, DEVICE_TCP_CONNECT_ACK_EVENT, DEVICE_TCP_CONNECT_EVENT, DEVICE_TCP_ERROR_EVENT, DEVICE_TCP_HEARTBEAT_EVENT, DeviceId, ElectionMessageType, ElectionVoteRequestPayload, ElectionVoteResponsePayload, ElectionWinPayload, HostAnnouncePayload, HostHeartbeatPayload, HostMemberOfflinePayload, HostRetirePayload, LAN_WIRE_EVENT_NAMES, LanDeviceDisplayNameChangedPayload, LanPairingPeerResetPayload, LanPairingRequestPayload, LanPairingResponsePayload, LanPairingUnpairRequiredPayload, LanWireEventEnvelope, LanWireEventName, LegacySynraMessageType, MessageId, PROTOCOL_VERSION,
|
|
496
|
+
export { ActionCompletedPayload, ActionExecutingPayload, ActionFailedPayload, ActionId, ActionProposedPayload, ClusterHostMessageType, CustomMessageType, DEFAULT_SYNRA_SCAN_BUDGET_MS, DEVICE_DISPLAY_NAME_CHANGED_EVENT, DEVICE_HOST_RETIRE_EVENT, DEVICE_MEMBER_OFFLINE_EVENT, DEVICE_PAIRING_PEER_RESET_EVENT, DEVICE_PAIRING_PREFIX, DEVICE_PAIRING_REQUEST_EVENT, DEVICE_PAIRING_RESPONSE_EVENT, DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT, DEVICE_TCP_ACK_EVENT, DEVICE_TCP_CLOSE_EVENT, DEVICE_TCP_CONNECT_ACK_EVENT, DEVICE_TCP_CONNECT_EVENT, DEVICE_TCP_ERROR_EVENT, DEVICE_TCP_HEARTBEAT_EVENT, DeviceId, ElectionMessageType, ElectionVoteRequestPayload, ElectionVoteResponsePayload, ElectionWinPayload, FileTransferAbortPayload, FileTransferChunkPayload, FileTransferCompletePayload, FileTransferKind, FileTransferProgressPayload, FileTransferRequestPayload, HostAnnouncePayload, HostHeartbeatPayload, HostMemberOfflinePayload, HostRetirePayload, LAN_WIRE_EVENT_NAMES, LanDeviceDisplayNameChangedPayload, LanPairingPeerResetPayload, LanPairingRequestPayload, LanPairingResponsePayload, LanPairingUnpairRequiredPayload, LanWireEventEnvelope, LanWireEventName, LegacySynraMessageType, MessageId, PROTOCOL_VERSION, PluginBundleTransferAssembly, PluginBundleTransferProgressSnapshot, PluginCatalogItem, PluginCatalogRequestPayload, PluginCatalogResponsePayload, PluginSyncMessageType, ProtocolEnvelope, ProtocolErrorCode, ProtocolErrorPayload, ProtocolMessageType, ProtocolPayloadByType, RelayAckPayload, RelayMessageType, RelayRequestPayload, RelayResultPayload, RuntimeErrorPayload, RuntimeFinishedPayload, RuntimeFinishedStatus, RuntimeMessageType, RuntimeReceivedPayload, RuntimeRequestPayload, RuntimeStartedPayload, ShareDetectedPayload, SynraActionReceipt, SynraActionRequest, SynraCrossDeviceMessage, SynraCrossDevicePayloadByType, SynraErrorCode, SynraMessageType, SynraPluginManifestEntriesWire, SynraPluginSyncMessage, SynraProtocolMessage, SynraRuntimeMessage, TraceId, TransportClosedPayload, TransportErrorPayload, TransportMessageAckPayload, TransportMessageReceivedPayload, TransportMessageType, TransportOpenedPayload, createMessage, createProtocolMessage, fileTransferChunkCount, isDevicePairingEvent, isLanWireEventName, iteratePluginBundleChunks, synraDiscoveryTimeoutsFromBudget, unknownToErrorMessage };
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* SYNRA-COMM::<Domain>::<Stage>::<NodeId>
|
|
7
7
|
*
|
|
8
8
|
* Domains:
|
|
9
|
-
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE
|
|
9
|
+
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE | FILE_TRANSFER
|
|
10
10
|
*
|
|
11
11
|
* Stages:
|
|
12
12
|
* CONNECT | SEND | RECEIVE | ACK | HEARTBEAT | CLOSE | ERROR
|
|
@@ -70,6 +70,108 @@ function synraDiscoveryTimeoutsFromBudget(scanBudgetMs) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
//#endregion
|
|
73
|
+
//#region src/file-transfer.ts
|
|
74
|
+
function fileTransferChunkCount(byteLength, chunkSize) {
|
|
75
|
+
return Math.max(1, Math.ceil(byteLength / chunkSize));
|
|
76
|
+
}
|
|
77
|
+
function uint8ToBase64Chunk(bytes) {
|
|
78
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
79
|
+
let binary = "";
|
|
80
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
81
|
+
return btoa(binary);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Outbound plugin-bundle chunks over `file.transfer.chunk` payloads (session layer).
|
|
85
|
+
* SYNRA-COMM::FILE_TRANSFER::SEND::CHUNK_ENCODE
|
|
86
|
+
*/
|
|
87
|
+
function* iteratePluginBundleChunks(options) {
|
|
88
|
+
const totalChunks = fileTransferChunkCount(options.buffer.length, options.chunkSize);
|
|
89
|
+
for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex += 1) {
|
|
90
|
+
const start = chunkIndex * options.chunkSize;
|
|
91
|
+
const slice = options.buffer.subarray(start, Math.min(options.buffer.length, start + options.chunkSize));
|
|
92
|
+
yield {
|
|
93
|
+
transferId: options.transferId,
|
|
94
|
+
kind: "plugin-bundle",
|
|
95
|
+
pluginId: options.pluginId,
|
|
96
|
+
version: options.version,
|
|
97
|
+
chunkIndex,
|
|
98
|
+
totalChunks,
|
|
99
|
+
chunkBase64: uint8ToBase64Chunk(slice),
|
|
100
|
+
syncSessionId: options.syncSessionId
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function base64ToUint8(base64) {
|
|
105
|
+
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(base64, "base64"));
|
|
106
|
+
const bin = atob(base64);
|
|
107
|
+
const out = new Uint8Array(bin.length);
|
|
108
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Assembles plugin-bundle transfer chunks in memory (receive path).
|
|
113
|
+
* SYNRA-COMM::FILE_TRANSFER::RECEIVE::ASSEMBLE_BUFFER
|
|
114
|
+
*/
|
|
115
|
+
var PluginBundleTransferAssembly = class {
|
|
116
|
+
chunks = /* @__PURE__ */ new Map();
|
|
117
|
+
expectedTotalChunks = 0;
|
|
118
|
+
pluginId = "";
|
|
119
|
+
version = "";
|
|
120
|
+
constructor(transferId) {
|
|
121
|
+
this.transferId = transferId;
|
|
122
|
+
}
|
|
123
|
+
/** Returns error message if chunk is invalid for this assembly. */
|
|
124
|
+
push(payload) {
|
|
125
|
+
if (payload.transferId !== this.transferId) return "transferId mismatch";
|
|
126
|
+
if (payload.kind !== "plugin-bundle") return "kind mismatch";
|
|
127
|
+
if (payload.chunkIndex < 0 || payload.totalChunks < 1) return "invalid chunk indices";
|
|
128
|
+
if (this.expectedTotalChunks === 0) this.expectedTotalChunks = payload.totalChunks;
|
|
129
|
+
else if (payload.totalChunks !== this.expectedTotalChunks) return "totalChunks changed";
|
|
130
|
+
if (payload.chunkIndex >= this.expectedTotalChunks) return "chunkIndex out of range";
|
|
131
|
+
if (this.chunks.has(payload.chunkIndex)) return;
|
|
132
|
+
if (this.pluginId.length === 0) {
|
|
133
|
+
this.pluginId = payload.pluginId;
|
|
134
|
+
this.version = payload.version;
|
|
135
|
+
}
|
|
136
|
+
this.chunks.set(payload.chunkIndex, base64ToUint8(payload.chunkBase64));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Chunk/session stats for progress bars or logging without `file.transfer.progress` on the wire.
|
|
140
|
+
*/
|
|
141
|
+
getProgressSnapshot() {
|
|
142
|
+
let bytesReceived = 0;
|
|
143
|
+
for (const u8 of this.chunks.values()) bytesReceived += u8.length;
|
|
144
|
+
return {
|
|
145
|
+
transferId: this.transferId,
|
|
146
|
+
pluginId: this.pluginId,
|
|
147
|
+
version: this.version,
|
|
148
|
+
chunksReceived: this.chunks.size,
|
|
149
|
+
totalChunks: this.expectedTotalChunks,
|
|
150
|
+
bytesReceived
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
isComplete() {
|
|
154
|
+
return this.expectedTotalChunks > 0 && this.chunks.size === this.expectedTotalChunks;
|
|
155
|
+
}
|
|
156
|
+
/** Concatenates in chunk index order; only call when `isComplete()`. */
|
|
157
|
+
concat() {
|
|
158
|
+
let totalLen = 0;
|
|
159
|
+
for (let i = 0; i < this.expectedTotalChunks; i++) {
|
|
160
|
+
const part = this.chunks.get(i);
|
|
161
|
+
if (!part) throw new Error("missing chunk");
|
|
162
|
+
totalLen += part.length;
|
|
163
|
+
}
|
|
164
|
+
const out = new Uint8Array(totalLen);
|
|
165
|
+
let offset = 0;
|
|
166
|
+
for (let i = 0; i < this.expectedTotalChunks; i++) {
|
|
167
|
+
const part = this.chunks.get(i);
|
|
168
|
+
out.set(part, offset);
|
|
169
|
+
offset += part.length;
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
//#endregion
|
|
73
175
|
//#region src/index.ts
|
|
74
176
|
const PROTOCOL_VERSION = "1.0";
|
|
75
177
|
function unknownToErrorMessage(error, fallback) {
|
|
@@ -88,4 +190,4 @@ function createProtocolMessage(input) {
|
|
|
88
190
|
};
|
|
89
191
|
}
|
|
90
192
|
//#endregion
|
|
91
|
-
export { DEFAULT_SYNRA_SCAN_BUDGET_MS, DEVICE_DISPLAY_NAME_CHANGED_EVENT, DEVICE_HOST_RETIRE_EVENT, DEVICE_MEMBER_OFFLINE_EVENT, DEVICE_PAIRING_PEER_RESET_EVENT, DEVICE_PAIRING_PREFIX, DEVICE_PAIRING_REQUEST_EVENT, DEVICE_PAIRING_RESPONSE_EVENT, DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT, DEVICE_TCP_ACK_EVENT, DEVICE_TCP_CLOSE_EVENT, DEVICE_TCP_CONNECT_ACK_EVENT, DEVICE_TCP_CONNECT_EVENT, DEVICE_TCP_ERROR_EVENT, DEVICE_TCP_HEARTBEAT_EVENT, LAN_WIRE_EVENT_NAMES, PROTOCOL_VERSION, createMessage, createProtocolMessage, isDevicePairingEvent, isLanWireEventName, synraDiscoveryTimeoutsFromBudget, unknownToErrorMessage };
|
|
193
|
+
export { DEFAULT_SYNRA_SCAN_BUDGET_MS, DEVICE_DISPLAY_NAME_CHANGED_EVENT, DEVICE_HOST_RETIRE_EVENT, DEVICE_MEMBER_OFFLINE_EVENT, DEVICE_PAIRING_PEER_RESET_EVENT, DEVICE_PAIRING_PREFIX, DEVICE_PAIRING_REQUEST_EVENT, DEVICE_PAIRING_RESPONSE_EVENT, DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT, DEVICE_TCP_ACK_EVENT, DEVICE_TCP_CLOSE_EVENT, DEVICE_TCP_CONNECT_ACK_EVENT, DEVICE_TCP_CONNECT_EVENT, DEVICE_TCP_ERROR_EVENT, DEVICE_TCP_HEARTBEAT_EVENT, LAN_WIRE_EVENT_NAMES, PROTOCOL_VERSION, PluginBundleTransferAssembly, createMessage, createProtocolMessage, fileTransferChunkCount, isDevicePairingEvent, isLanWireEventName, iteratePluginBundleChunks, synraDiscoveryTimeoutsFromBudget, unknownToErrorMessage };
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synra/protocol",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Shared cross-device protocol contracts for Synra.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"type": "module",
|
|
10
|
+
"types": "./src/index.ts",
|
|
10
11
|
"exports": {
|
|
11
12
|
".": "./dist/index.mjs",
|
|
12
13
|
"./package.json": "./package.json"
|