@forgeax/engine-net 0.1.2

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.
Files changed (45) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +145 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/endpoint/endpoint.d.ts +36 -0
  5. package/dist/endpoint/endpoint.d.ts.map +1 -0
  6. package/dist/endpoint/errors.d.ts +82 -0
  7. package/dist/endpoint/errors.d.ts.map +1 -0
  8. package/dist/endpoint/memory.d.ts +13 -0
  9. package/dist/endpoint/memory.d.ts.map +1 -0
  10. package/dist/index.d.ts +17 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.mjs +903 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/replication/authority.d.ts +17 -0
  15. package/dist/replication/authority.d.ts.map +1 -0
  16. package/dist/replication/codec.d.ts +26 -0
  17. package/dist/replication/codec.d.ts.map +1 -0
  18. package/dist/replication/constants.d.ts +2 -0
  19. package/dist/replication/constants.d.ts.map +1 -0
  20. package/dist/replication/errors.d.ts +66 -0
  21. package/dist/replication/errors.d.ts.map +1 -0
  22. package/dist/replication/handshake.d.ts +5 -0
  23. package/dist/replication/handshake.d.ts.map +1 -0
  24. package/dist/replication/profile.d.ts +31 -0
  25. package/dist/replication/profile.d.ts.map +1 -0
  26. package/dist/replication/replica.d.ts +27 -0
  27. package/dist/replication/replica.d.ts.map +1 -0
  28. package/dist/session/net-session.d.ts +32 -0
  29. package/dist/session/net-session.d.ts.map +1 -0
  30. package/dist/session/session-plugin.d.ts +8 -0
  31. package/dist/session/session-plugin.d.ts.map +1 -0
  32. package/package.json +58 -0
  33. package/src/endpoint/endpoint.ts +50 -0
  34. package/src/endpoint/errors.ts +164 -0
  35. package/src/endpoint/memory.ts +172 -0
  36. package/src/index.ts +46 -0
  37. package/src/replication/authority.ts +145 -0
  38. package/src/replication/codec.ts +257 -0
  39. package/src/replication/constants.ts +1 -0
  40. package/src/replication/errors.ts +60 -0
  41. package/src/replication/handshake.ts +18 -0
  42. package/src/replication/profile.ts +111 -0
  43. package/src/replication/replica.ts +240 -0
  44. package/src/session/net-session.ts +118 -0
  45. package/src/session/session-plugin.ts +52 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/endpoint/errors.ts","../src/endpoint/memory.ts","../src/replication/constants.ts","../src/replication/errors.ts","../src/replication/codec.ts","../src/replication/profile.ts","../src/replication/authority.ts","../src/replication/handshake.ts","../src/replication/replica.ts","../src/session/net-session.ts","../src/session/session-plugin.ts"],"names":["err","revived","ok","componentSchema","published","world"],"mappings":";;;;;;AAgEA,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EAC5B,IAAA;AAAA,EACA,QAAA;AAAA,EACA,IAAA;AAAA,EACA,MAAA;AAAA,EAET,YAAY,IAAA,EAKT;AACD,IAAA,IAAI,MAAA,GAAS,EAAA;AACb,IAAA,IAAI,IAAA,CAAK,SAAS,gBAAA,EAAkB;AAClC,MAAA,MAAM,IAAI,IAAA,CAAK,MAAA;AACf,MAAA,MAAA,GAAS,CAAA,SAAA,EAAY,EAAE,MAAM,CAAA,CAAA,CAAA;AAAA,IAC/B,CAAA,MAAA,IAAW,IAAA,CAAK,IAAA,KAAS,mBAAA,EAAqB;AAC5C,MAAA,MAAM,IAAI,IAAA,CAAK,MAAA;AACf,MAAA,MAAA,GAAS,CAAA,SAAA,EAAY,EAAE,MAAM,CAAA,CAAA,CAAA;AAAA,IAC/B,CAAA,MAAA,IAAW,IAAA,CAAK,IAAA,KAAS,aAAA,EAAe;AACtC,MAAA,MAAM,IAAI,IAAA,CAAK,MAAA;AACf,MAAA,MAAA,GAAS,CAAA,SAAA,EAAY,CAAA,CAAE,MAAM,CAAA,QAAA,EAAW,EAAE,KAAK,CAAA,CAAA,CAAA;AAAA,IACjD,CAAA,MAAA,IAAW,IAAA,CAAK,IAAA,KAAS,gBAAA,EAAkB;AACzC,MAAA,MAAM,IAAI,IAA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AA;AACD,MAAA,GAAA,CAAI,OAAO,MAAM;AACf,QAAA,KAAA,CAAM,cAAA,CAAe,eAAe,OAAO,CAAA;AAC3C,QAAA,OAAO,MAAM,KAAA,CAAM,cAAA,CAAe,aAAa,CAAA;AAAA,MACjD,GAAG,sBAAsB,CAAA;AACzB,MAAA,GAAA,CAAI,OAAO,MAAM;AACf,QAAA,KAAA,CACG,UAAU,MAAA,EAAQ;AAAA,UACjB,IAAA,EAAM,aAAA;AAAA,UACN,SAAS,EAAC;AAAA,UACV,MAAA,EAAQ,CAAC,WAAW,CAAA;AAAA,UACpB,IAAI,CAACG,MAAAA,KAAUA,OAAM,WAAA,CAAwB,aAAa,EAAE,aAAA;AAAc,SAC3E,EACA,MAAA,EAAO;AACV,QAAA,OAAO,MAAM,KAAA,CAAM,YAAA,CAAa,MAAA,EAAQ,aAAa,CAAA;AAAA,MACvD,GAAG,aAAa,CAAA;AAChB,MAAA,GAAA,CAAI,OAAO,MAAM;AACf,QAAA,KAAA,CACG,UAAU,MAAA,EAAQ;AAAA,UACjB,IAAA,EAAM,aAAA;AAAA,UACN,SAAS,EAAC;AAAA,UACV,KAAA,EAAO,CAAC,WAAW,CAAA;AAAA,UACnB,IAAI,CAACA,MAAAA,KAAUA,OAAM,WAAA,CAAwB,aAAa,EAAE,OAAA;AAAQ,SACrE,EACA,MAAA,EAAO;AACV,QAAA,OAAO,MAAM,KAAA,CAAM,YAAA,CAAa,MAAA,EAAQ,aAAa,CAAA;AAAA,MACvD,GAAG,aAAa,CAAA;AAAA,IAClB;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["// @forgeax/engine-net -- endpoint structured errors.\n//\n// Closed union of transport-level failures. Each variant carries .code, .expected,\n// .hint, and per-code .detail. AI users exhaustively switch on .code without a\n// default branch (requirements AC-13).\n\nimport type { PeerId } from './endpoint';\n\n// ---------------------------------------------------------------------------\n// EndpointErrorCode -- closed 5-member union derived from endpointErrorPolicy\n// ---------------------------------------------------------------------------\n\n/** Transport-level endpoint error codes (requirements AC-02, AC-13). */\nexport type EndpointErrorCode = keyof typeof endpointErrorPolicy;\n\n// ---------------------------------------------------------------------------\n// Per-code detail payloads\n// ---------------------------------------------------------------------------\n\nexport interface EndpointDetailPeerNotFound {\n readonly peerId: PeerId;\n}\n\nexport interface EndpointDetailConnectionClosed {\n readonly peerId: PeerId;\n}\n\nexport interface EndpointDetailSendFailed {\n readonly peerId: PeerId;\n readonly cause: string;\n}\n\nexport interface EndpointDetailAlreadyClosed {\n readonly cause: string;\n}\n\nexport interface EndpointDetailConnectionFailed {\n readonly address: string;\n readonly cause: string;\n}\n\n// ---------------------------------------------------------------------------\n// Conditional resolver\n// ---------------------------------------------------------------------------\n\nexport type EndpointErrorDetailFor<C extends EndpointErrorCode> = C extends 'peer-not-found'\n ? EndpointDetailPeerNotFound\n : C extends 'connection-closed'\n ? EndpointDetailConnectionClosed\n : C extends 'send-failed'\n ? EndpointDetailSendFailed\n : C extends 'already-closed'\n ? EndpointDetailAlreadyClosed\n : C extends 'connection-failed'\n ? EndpointDetailConnectionFailed\n : never;\n\n/** Tagged union of all endpoint error detail variants. */\nexport type EndpointErrorDetail = EndpointErrorDetailFor<EndpointErrorCode>;\n\n// ---------------------------------------------------------------------------\n// Error class\n// ---------------------------------------------------------------------------\n\nclass EndpointErrorClass extends Error {\n readonly code: EndpointErrorCode;\n readonly expected: string;\n readonly hint: string;\n readonly detail: EndpointErrorDetail;\n\n constructor(args: {\n code: EndpointErrorCode;\n expected: string;\n hint: string;\n detail: EndpointErrorDetail;\n }) {\n let suffix = '';\n if (args.code === 'peer-not-found') {\n const d = args.detail as EndpointDetailPeerNotFound;\n suffix = ` (peerId=${d.peerId})`;\n } else if (args.code === 'connection-closed') {\n const d = args.detail as EndpointDetailConnectionClosed;\n suffix = ` (peerId=${d.peerId})`;\n } else if (args.code === 'send-failed') {\n const d = args.detail as EndpointDetailSendFailed;\n suffix = ` (peerId=${d.peerId}, cause=${d.cause})`;\n } else if (args.code === 'already-closed') {\n const d = args.detail as EndpointDetailAlreadyClosed;\n suffix = ` (cause=${d.cause})`;\n } else if (args.code === 'connection-failed') {\n const d = args.detail as EndpointDetailConnectionFailed;\n suffix = ` (address=${d.address}, cause=${d.cause})`;\n }\n super(`[EndpointError ${args.code}] expected: ${args.expected}; hint: ${args.hint}${suffix}`);\n this.name = 'EndpointError';\n this.code = args.code;\n this.expected = args.expected;\n this.hint = args.hint;\n this.detail = args.detail;\n }\n}\n\ntype EndpointErrorVariant<C extends EndpointErrorCode> = EndpointErrorClass & {\n readonly code: C;\n readonly detail: EndpointErrorDetailFor<C>;\n};\n\nexport type EndpointError = {\n [C in EndpointErrorCode]: EndpointErrorVariant<C>;\n}[EndpointErrorCode];\n\ninterface EndpointErrorConstructor {\n new <C extends EndpointErrorCode>(args: {\n code: C;\n expected: string;\n hint: string;\n detail: EndpointErrorDetailFor<C>;\n }): EndpointErrorVariant<C>;\n readonly prototype: EndpointErrorClass;\n}\n\nexport const EndpointError: EndpointErrorConstructor =\n EndpointErrorClass as unknown as EndpointErrorConstructor;\n\ntype EndpointErrorPolicy = { readonly expected: string; readonly hint: string };\n\nconst endpointErrorPolicy = {\n 'peer-not-found': {\n expected: 'the target peer must exist in the current connection set',\n hint: 'verify the PeerId is from a connect event; check that the peer has not disconnected',\n },\n 'connection-closed': {\n expected: 'the peer connection must be alive for the operation',\n hint: 'the peer disconnected; poll for a disconnect event and handle the lifecycle',\n },\n 'send-failed': {\n expected: 'message bytes must be delivered to the target peer or the connection must fail',\n hint: 'the memory connection is broken; the peer may have disconnected or the buffer is full',\n },\n 'already-closed': {\n expected: 'the endpoint must be open for any operation',\n hint: 'the endpoint is closed; create a new endpoint pair for further communication',\n },\n 'connection-failed': {\n expected:\n 'the endpoint factory must successfully establish a connection or bind to the listen address',\n hint: 'the initial connection or bind failed; verify the address is reachable and the port is not in use, then retry',\n },\n} satisfies Record<string, EndpointErrorPolicy>;\n\n/** Expected-invariant table per error code. */\nexport const ENDPOINT_EXPECTED: Readonly<Record<EndpointErrorCode, string>> = Object.fromEntries(\n Object.entries(endpointErrorPolicy).map(([code, policy]) => [code, policy.expected]),\n) as Readonly<Record<EndpointErrorCode, string>>;\n\n/** Actionable hint table per error code. */\nexport const ENDPOINT_ERROR_HINTS: Readonly<Record<EndpointErrorCode, string>> = Object.fromEntries(\n Object.entries(endpointErrorPolicy).map(([code, policy]) => [code, policy.hint]),\n) as Readonly<Record<EndpointErrorCode, string>>;\n\n/** Type guard for narrowing unknown to EndpointError. */\nexport function isEndpointError(err: unknown): err is EndpointError {\n return err instanceof EndpointErrorClass;\n}\n","// @forgeax/engine-net -- memory endpoint implementation.\n// Deterministic memory backend for the NetEndpoint contract.\n// (requirements AC-03, plan-strategy D-3)\n\nimport type { Result } from '@forgeax/engine-types';\nimport { err, ok } from '@forgeax/engine-types';\nimport type { EndpointEvent, NetEndpoint, PeerId } from './endpoint';\nimport type { EndpointError as EndpointErrorType } from './errors';\nimport { ENDPOINT_ERROR_HINTS, ENDPOINT_EXPECTED, EndpointError } from './errors';\n\ninterface InternalState {\n delayNext: boolean;\n duplicateNext: boolean;\n malformNext: boolean;\n}\n\nclass MemoryEndpoint implements NetEndpoint {\n readonly _peerId: PeerId;\n _remote: MemoryEndpoint | null = null;\n _closed = false;\n _remoteConnected = false;\n _incoming: EndpointEvent[] = [];\n _delayed: EndpointEvent[] = [];\n _state: InternalState = { delayNext: false, duplicateNext: false, malformNext: false };\n\n constructor(peerId: PeerId) {\n this._peerId = peerId;\n }\n\n poll(): EndpointEvent[] {\n if (this._closed) return [];\n const events = this._incoming.splice(0);\n this._incoming = this._delayed.splice(0);\n return events;\n }\n\n send(peerId: PeerId, data: Uint8Array): Result<void, EndpointErrorType> {\n if (this._closed) {\n return err(\n new EndpointError({\n code: 'already-closed',\n expected: ENDPOINT_EXPECTED['already-closed'],\n hint: ENDPOINT_ERROR_HINTS['already-closed'],\n detail: { cause: 'endpoint is closed' },\n }),\n );\n }\n if (!this._remote || this._remote._peerId !== peerId) {\n return err(\n new EndpointError({\n code: 'peer-not-found',\n expected: ENDPOINT_EXPECTED['peer-not-found'],\n hint: ENDPOINT_ERROR_HINTS['peer-not-found'],\n detail: { peerId },\n }),\n );\n }\n if (!this._remoteConnected) {\n return err(\n new EndpointError({\n code: 'connection-closed',\n expected: ENDPOINT_EXPECTED['connection-closed'],\n hint: ENDPOINT_ERROR_HINTS['connection-closed'],\n detail: { peerId },\n }),\n );\n }\n\n const deliver = (bytes: Uint8Array) => {\n if (this._state.delayNext) {\n this._remote?._delayed.push({ kind: 'message', peerId: this._peerId, data: bytes });\n this._state.delayNext = false;\n } else {\n this._remote?._incoming.push({ kind: 'message', peerId: this._peerId, data: bytes });\n }\n };\n\n if (this._state.malformNext) {\n const corrupted = new Uint8Array(data);\n if (corrupted.length > 0) {\n const firstByte = corrupted[0];\n if (firstByte !== undefined) corrupted[0] = firstByte ^ 0xff;\n }\n deliver(corrupted);\n this._state.malformNext = false;\n } else {\n deliver(data);\n if (this._state.duplicateNext) {\n this._state.duplicateNext = false;\n if (this._state.delayNext) {\n this._remote?._delayed.push({ kind: 'message', peerId: this._peerId, data });\n this._state.delayNext = false;\n } else {\n this._remote?._incoming.push({ kind: 'message', peerId: this._peerId, data });\n }\n }\n }\n\n return ok(undefined);\n }\n\n close(): Result<void, EndpointErrorType> {\n if (this._closed) {\n return err(\n new EndpointError({\n code: 'already-closed',\n expected: ENDPOINT_EXPECTED['already-closed'],\n hint: ENDPOINT_ERROR_HINTS['already-closed'],\n detail: { cause: 'endpoint is already closed' },\n }),\n );\n }\n this._closed = true;\n this._remoteConnected = false;\n if (this._remote && !this._remote._closed) {\n this._remote._remoteConnected = false;\n this._remote._incoming.push({ kind: 'peer-disconnected', peerId: this._peerId });\n }\n return ok(undefined);\n }\n\n _forceDisconnect(): void {\n if (this._remote && !this._remote._closed) {\n this._remote._remoteConnected = false;\n this._remote._incoming.push({ kind: 'peer-disconnected', peerId: this._peerId });\n }\n this._remoteConnected = false;\n }\n}\n\nexport function createMemoryEndpointPair(): [NetEndpoint, NetEndpoint] {\n const epA = new MemoryEndpoint(1 as PeerId);\n const epB = new MemoryEndpoint(2 as PeerId);\n epA._remote = epB;\n epB._remote = epA;\n epA._remoteConnected = true;\n epB._remoteConnected = true;\n epA._incoming.push({ kind: 'peer-connected', peerId: 2 as PeerId });\n epB._incoming.push({ kind: 'peer-connected', peerId: 1 as PeerId });\n return [epA, epB];\n}\n\nexport interface MemoryFaultController {\n delayNextDelivery(ms: number): void;\n duplicateNextDelivery(): void;\n malformNextDelivery(): void;\n disconnectPeer(endpoint: NetEndpoint): void;\n}\n\nexport function createMemoryEndpointPairWithController(): {\n readonly endpoints: [NetEndpoint, NetEndpoint];\n readonly controller: MemoryFaultController;\n} {\n const [epA, epB] = createMemoryEndpointPair();\n\n const controller: MemoryFaultController = {\n delayNextDelivery(_ms: number): void {\n (epA as MemoryEndpoint)._state.delayNext = true;\n },\n duplicateNextDelivery(): void {\n (epA as MemoryEndpoint)._state.duplicateNext = true;\n },\n malformNextDelivery(): void {\n (epA as MemoryEndpoint)._state.malformNext = true;\n },\n disconnectPeer(endpoint: NetEndpoint): void {\n (endpoint as MemoryEndpoint)._forceDisconnect();\n },\n };\n\n return { endpoints: [epA, epB], controller };\n}\n","export const REPLICATION_PROTOCOL_VERSION = 1;\n","type NetErrorDetailByCode = {\n 'handshake-profile-mismatch': {\n readonly localFingerprint: string;\n readonly remoteFingerprint: string;\n };\n 'decode-invalid-payload': { readonly reason: string };\n 'decode-limit-exceeded': {\n readonly limit: string;\n readonly actual: number;\n readonly maximum: number;\n };\n 'ordering-invalid-tick': { readonly receivedTick: number; readonly lastTick: number };\n 'identity-invalid': { readonly id: number; readonly reason: string };\n 'schema-invalid': { readonly component: string; readonly reason: string };\n 'remap-unresolved-reference': { readonly id: number; readonly referencedId: number };\n 'apply-invariant-failed': { readonly reason: string };\n};\n\nexport type NetErrorCode = keyof NetErrorDetailByCode;\nexport type NetErrorDetail = NetErrorDetailByCode[NetErrorCode];\n\nclass NetErrorClass extends Error {\n readonly code: NetErrorCode;\n readonly expected: string;\n readonly hint: string;\n readonly detail: NetErrorDetail;\n constructor(args: {\n code: NetErrorCode;\n expected: string;\n hint: string;\n detail: NetErrorDetail;\n }) {\n super(`[NetError ${args.code}] expected: ${args.expected}; hint: ${args.hint}`);\n this.name = 'NetError';\n this.code = args.code;\n this.expected = args.expected;\n this.hint = args.hint;\n this.detail = args.detail;\n }\n}\n\ntype Variant<C extends NetErrorCode> = NetErrorClass & {\n readonly code: C;\n readonly detail: NetErrorDetailByCode[C];\n};\n\nexport type NetError = {\n [C in NetErrorCode]: Variant<C>;\n}[NetErrorCode];\n\ninterface NetErrorConstructor {\n new <C extends NetErrorCode>(args: {\n code: C;\n expected: string;\n hint: string;\n detail: NetErrorDetailByCode[C];\n }): Variant<C>;\n readonly prototype: NetErrorClass;\n}\nexport const NetError: NetErrorConstructor = NetErrorClass as unknown as NetErrorConstructor;\n","import { err, ok, type Result } from '@forgeax/engine-types';\nimport { REPLICATION_PROTOCOL_VERSION } from './constants';\nimport { NetError } from './errors';\nimport type { ReplicationLimits } from './profile';\n\nexport type NetEntityId = number & { readonly __netEntityId: unique symbol };\nexport interface ReplicationComponentRecord {\n readonly name: string;\n readonly operation?: 'replace' | 'remove';\n readonly data: Record<string, unknown>;\n}\nexport interface ReplicationEntityRecord {\n readonly id: number;\n readonly kind: 'upsert' | 'despawn';\n readonly components: readonly ReplicationComponentRecord[];\n}\nexport interface ReplicationBatch {\n readonly version: number;\n readonly fingerprint: string;\n readonly tick: number;\n readonly full: boolean;\n readonly entities: readonly ReplicationEntityRecord[];\n}\n\nconst REPLICATION_ENTITY_KINDS = [\n 'upsert',\n 'despawn',\n] as const satisfies readonly ReplicationEntityRecord['kind'][];\n\nfunction isReplicationEntityKind(value: unknown): value is ReplicationEntityRecord['kind'] {\n return REPLICATION_ENTITY_KINDS.some((kind) => kind === value);\n}\n\nconst TYPED_ARRAYS = {\n Float32Array,\n Float64Array,\n Int8Array,\n Int16Array,\n Int32Array,\n Uint8Array,\n Uint8ClampedArray,\n Uint16Array,\n Uint32Array,\n} as const;\ntype TypedArrayName = keyof typeof TYPED_ARRAYS;\ntype PortableTypedArray = InstanceType<(typeof TYPED_ARRAYS)[TypedArrayName]>;\n\nfunction typedArrayName(value: unknown): TypedArrayName | undefined {\n for (const [name, typedArrayConstructor] of Object.entries(TYPED_ARRAYS) as [\n TypedArrayName,\n (typeof TYPED_ARRAYS)[TypedArrayName],\n ][]) {\n if (value instanceof typedArrayConstructor) return name;\n }\n return undefined;\n}\n\nfunction canonicalize(value: unknown): unknown {\n const name = typedArrayName(value);\n if (name !== undefined)\n return { $typedArray: name, values: Array.from(value as PortableTypedArray) };\n if (Array.isArray(value)) return value.map(canonicalize);\n if (value !== null && typeof value === 'object') {\n return Object.fromEntries(\n Object.keys(value)\n .sort()\n .map((key) => [key, canonicalize((value as Record<string, unknown>)[key])]),\n );\n }\n return value;\n}\n\nfunction reviveTypedArrays(\n value: unknown,\n): { readonly value: unknown } | { readonly reason: string } {\n if (Array.isArray(value)) {\n const values: unknown[] = [];\n for (const item of value) {\n const revived = reviveTypedArrays(item);\n if ('reason' in revived) return revived;\n values.push(revived.value);\n }\n return { value: values };\n }\n if (value === null || typeof value !== 'object') return { value };\n const record = value as Record<string, unknown>;\n if ('$typedArray' in record || 'values' in record) {\n if (\n Object.keys(record).length !== 2 ||\n typeof record.$typedArray !== 'string' ||\n !Array.isArray(record.values)\n )\n return { reason: 'typed-array tag must contain only an allowlisted name and values array' };\n const typedArrayConstructor = TYPED_ARRAYS[record.$typedArray as TypedArrayName];\n if (\n typedArrayConstructor === undefined ||\n record.values.some((item) => typeof item !== 'number')\n )\n return { reason: 'typed-array tag contains an unsupported type or non-numeric value' };\n return { value: new typedArrayConstructor(record.values) };\n }\n const revived: Record<string, unknown> = {};\n for (const [key, item] of Object.entries(record)) {\n const nested = reviveTypedArrays(item);\n if ('reason' in nested) return nested;\n revived[key] = nested.value;\n }\n return { value: revived };\n}\nfunction limitError(limit: string, actual: number, maximum: number): NetError {\n return new NetError({\n code: 'decode-limit-exceeded',\n expected: `${limit} must not exceed ${maximum}`,\n hint: 'reduce the replicated payload or configure matching declared limits',\n detail: { limit, actual, maximum },\n });\n}\nfunction validateLimits(\n batch: ReplicationBatch,\n bytes: Uint8Array | undefined,\n limits: ReplicationLimits,\n): NetError | null {\n if (bytes !== undefined && bytes.byteLength > limits.maxMessageBytes)\n return limitError('maxMessageBytes', bytes.byteLength, limits.maxMessageBytes);\n if (batch.entities.length > limits.maxEntities)\n return limitError('maxEntities', batch.entities.length, limits.maxEntities);\n let operations = 0;\n const visit = (value: unknown): NetError | null => {\n if (\n typeof value === 'string' &&\n new TextEncoder().encode(value).byteLength > limits.maxStringBytes\n )\n return limitError(\n 'maxStringBytes',\n new TextEncoder().encode(value).byteLength,\n limits.maxStringBytes,\n );\n const typedArray = typedArrayName(value);\n if (typedArray !== undefined) {\n const contents = value as PortableTypedArray;\n if (contents.byteLength > limits.maxBufferBytes)\n return limitError('maxBufferBytes', contents.byteLength, limits.maxBufferBytes);\n if (contents.length > limits.maxArrayElements)\n return limitError('maxArrayElements', contents.length, limits.maxArrayElements);\n return null;\n }\n if (Array.isArray(value)) {\n if (value.length > limits.maxArrayElements)\n return limitError('maxArrayElements', value.length, limits.maxArrayElements);\n for (const item of value) {\n const problem = visit(item);\n if (problem) return problem;\n }\n }\n if (value !== null && typeof value === 'object' && !(value instanceof Uint8Array))\n for (const item of Object.values(value as Record<string, unknown>)) {\n const problem = visit(item);\n if (problem) return problem;\n }\n return null;\n };\n for (const entity of batch.entities) {\n operations += entity.components.length;\n for (const component of entity.components) {\n const problem = visit(component.data);\n if (problem) return problem;\n }\n }\n return operations > limits.maxComponentOperations\n ? limitError('maxComponentOperations', operations, limits.maxComponentOperations)\n : null;\n}\nfunction parse(\n bytes: Uint8Array,\n): { readonly batch: ReplicationBatch } | { readonly reason: string } {\n try {\n const decoded: unknown = JSON.parse(new TextDecoder().decode(bytes));\n const revived = reviveTypedArrays(decoded);\n if ('reason' in revived) return revived;\n if (revived.value === null || typeof revived.value !== 'object')\n return { reason: 'batch must be an object' };\n const batch = revived.value as Partial<ReplicationBatch>;\n if (\n !Array.isArray(batch.entities) ||\n typeof batch.fingerprint !== 'string' ||\n !Number.isSafeInteger(batch.tick) ||\n !Number.isSafeInteger(batch.version) ||\n typeof batch.full !== 'boolean'\n )\n return { reason: 'batch envelope has an invalid field type' };\n for (const [entityIndex, entity] of batch.entities.entries()) {\n if (entity === null || typeof entity !== 'object')\n return { reason: `entity record ${entityIndex} must be an object` };\n const record = entity as Partial<ReplicationEntityRecord>;\n if (\n !Number.isSafeInteger(record.id) ||\n !isReplicationEntityKind(record.kind) ||\n !Array.isArray(record.components)\n )\n return { reason: `entity record ${entityIndex} has an invalid field type` };\n for (const [componentIndex, component] of record.components.entries()) {\n if (component === null || typeof component !== 'object')\n return { reason: `component record ${entityIndex}:${componentIndex} must be an object` };\n const entry = component as Partial<ReplicationComponentRecord>;\n if (\n typeof entry.name !== 'string' ||\n entry.name.length === 0 ||\n (entry.operation !== undefined &&\n entry.operation !== 'replace' &&\n entry.operation !== 'remove') ||\n entry.data === null ||\n typeof entry.data !== 'object' ||\n Array.isArray(entry.data) ||\n (entry.operation === 'remove' && Object.keys(entry.data).length !== 0)\n )\n return {\n reason: `component record ${entityIndex}:${componentIndex} has an invalid field type`,\n };\n }\n }\n return { batch: batch as ReplicationBatch };\n } catch {\n return { reason: 'payload is not valid JSON' };\n }\n}\nexport function encodeReplicationBatch(\n batch: ReplicationBatch,\n limits: ReplicationLimits,\n): Result<Uint8Array, NetError> {\n const bytes = new TextEncoder().encode(JSON.stringify(canonicalize(batch)));\n const failure = validateLimits(batch, bytes, limits);\n return failure ? err(failure) : ok(bytes);\n}\nexport function decodeReplicationBatch(\n bytes: Uint8Array,\n limits: ReplicationLimits,\n): Result<ReplicationBatch, NetError> {\n if (bytes.byteLength > limits.maxMessageBytes)\n return err(limitError('maxMessageBytes', bytes.byteLength, limits.maxMessageBytes));\n const parsed = parse(bytes);\n if ('reason' in parsed || parsed.batch.version !== REPLICATION_PROTOCOL_VERSION)\n return err(\n new NetError({\n code: 'decode-invalid-payload',\n expected: `a version ${REPLICATION_PROTOCOL_VERSION} canonical replication batch`,\n hint: 'send bytes produced by the replication codec for the negotiated protocol',\n detail: {\n reason:\n 'reason' in parsed\n ? parsed.reason\n : 'batch protocol version does not match the decoder',\n },\n }),\n );\n const failure = validateLimits(parsed.batch, bytes, limits);\n return failure ? err(failure) : ok(parsed.batch);\n}\n","import type { Component } from '@forgeax/engine-ecs';\nimport { validateProfileComponents } from '@forgeax/engine-ecs/externalization';\nimport { componentSchema } from '@forgeax/engine-ecs/internal';\nimport { err, ok, type Result } from '@forgeax/engine-types';\nexport interface ReplicationLimits {\n readonly maxMessageBytes: number;\n readonly maxEntities: number;\n readonly maxComponentOperations: number;\n readonly maxStringBytes: number;\n readonly maxBufferBytes: number;\n readonly maxArrayElements: number;\n}\nexport const DEFAULT_REPLICATION_LIMITS: ReplicationLimits = {\n maxMessageBytes: 64 * 1024,\n maxEntities: 1024,\n maxComponentOperations: 4096,\n maxStringBytes: 4096,\n maxBufferBytes: 16 * 1024,\n maxArrayElements: 1024,\n};\n\nimport { NetError } from './errors';\n\nexport interface ReplicationProfile {\n readonly name: string;\n readonly entities: ReplicationEntityFilter;\n readonly components: readonly Component[];\n readonly limits: ReplicationLimits;\n readonly fingerprint: string;\n}\nexport interface ReplicationEntityFilter {\n readonly with: readonly Component[];\n readonly without?: readonly Component[];\n}\nexport interface DefineReplicationOptions {\n readonly name: string;\n readonly entities: ReplicationEntityFilter;\n readonly components: readonly Component[];\n readonly limits?: Partial<ReplicationLimits>;\n}\nfunction hash(text: string): string {\n let value = 2166136261;\n for (const char of text) {\n value ^= char.charCodeAt(0);\n value = Math.imul(value, 16777619);\n }\n return (value >>> 0).toString(16).padStart(8, '0');\n}\n\nfunction immutableProfile(\n options: DefineReplicationOptions,\n limits: ReplicationLimits,\n fingerprint: string,\n): ReplicationProfile {\n const entities: ReplicationEntityFilter = Object.freeze({\n with: Object.freeze([...options.entities.with]),\n ...(options.entities.without === undefined\n ? {}\n : { without: Object.freeze([...options.entities.without]) }),\n });\n return Object.freeze({\n name: options.name,\n entities,\n components: Object.freeze([...options.components]),\n limits: Object.freeze({ ...limits }),\n fingerprint,\n });\n}\n\nexport function defineReplication(\n options: DefineReplicationOptions,\n): Result<ReplicationProfile, NetError> {\n const portable = validateProfileComponents(options.components);\n if (!portable.valid) {\n const first = portable.errors[0];\n if (first === undefined) {\n return err(\n new NetError({\n code: 'schema-invalid',\n expected: 'portable replication components',\n hint: 'select only components accepted by the ECS externalization kernel',\n detail: { component: '', reason: 'portable validation failed without a diagnostic' },\n }),\n );\n }\n return err(\n new NetError({\n code: 'schema-invalid',\n expected: first.expected,\n hint: first.hint,\n detail: { component: first.component, reason: first.code },\n }),\n );\n }\n const limits: ReplicationLimits = { ...DEFAULT_REPLICATION_LIMITS, ...options.limits };\n const signature = JSON.stringify({\n name: options.name,\n query: {\n with: options.entities.with.map((component) => component.name),\n ...(options.entities.without === undefined\n ? {}\n : { without: options.entities.without.map((component) => component.name) }),\n },\n components: options.components.map((component) => ({\n name: component.name,\n schema: componentSchema(component),\n })),\n limits,\n });\n return ok(immutableProfile(options, limits, hash(signature)));\n}\n","import type { EntityHandle, World } from '@forgeax/engine-ecs';\nimport { projectComponentData } from '@forgeax/engine-ecs/externalization';\nimport { err, ok, type Result } from '@forgeax/engine-types';\nimport {\n encodeReplicationBatch,\n type ReplicationBatch,\n type ReplicationComponentRecord,\n type ReplicationEntityRecord,\n} from './codec';\nimport { REPLICATION_PROTOCOL_VERSION } from './constants';\nimport type { NetError } from './errors';\nimport { DEFAULT_REPLICATION_LIMITS, type ReplicationProfile } from './profile';\n\nexport interface PublishedBatch extends ReplicationBatch {\n readonly bytes: Uint8Array;\n}\ninterface KnownEntity {\n readonly id: number;\n readonly components: Map<string, string>;\n}\nfunction stable(value: unknown): string {\n return JSON.stringify(value);\n}\n\nexport class AuthorityCoordinator {\n readonly #world: World;\n readonly #profile: ReplicationProfile;\n readonly #ids = new Map<EntityHandle, number>();\n readonly #known = new Map<EntityHandle, KnownEntity>();\n #nextId = 1;\n #tick = 0;\n constructor(world: World, profile: ReplicationProfile) {\n this.#world = world;\n this.#profile = profile;\n }\n idFor(entity: EntityHandle): number {\n return this.#ids.get(entity) ?? 0;\n }\n publish(): Result<PublishedBatch, NetError> {\n return this.#publish(false);\n }\n publishFull(): Result<PublishedBatch, NetError> {\n return this.#publish(true);\n }\n #publish(forceFull: boolean): Result<PublishedBatch, NetError> {\n const candidateIds = new Map(this.#ids);\n let candidateNextId = this.#nextId;\n const current = new Map<\n EntityHandle,\n { id: number; components: ReplicationComponentRecord[] }\n >();\n const query = this.#world.query(this.#profile.entities).unwrap();\n // Allocate every visible entity id before projecting any component data.\n // Query iteration visits storage groups independently, so projecting while\n // discovering ids can encode references to a later chunk as zero.\n for (const row of query) {\n if (!candidateIds.has(row.entity)) candidateIds.set(row.entity, candidateNextId++);\n }\n for (const row of query) {\n const entity = row.entity;\n const components: ReplicationComponentRecord[] = [];\n for (const component of this.#profile.components) {\n const raw = this.#world.get(entity, component);\n if (raw.ok) {\n components.push({\n name: component.name,\n data: projectComponentData(\n component,\n raw.value as Record<string, unknown>,\n (reference) => candidateIds.get(reference as EntityHandle) ?? 0,\n ),\n });\n }\n }\n const id = candidateIds.get(entity);\n if (id !== undefined) current.set(entity, { id, components });\n }\n\n const full = forceFull || this.#tick === 0;\n const entities: ReplicationEntityRecord[] = [];\n for (const [entity, entry] of current) {\n const prior = this.#known.get(entity);\n const components =\n full || prior === undefined\n ? entry.components\n : [\n ...entry.components.filter(\n (component) => prior.components.get(component.name) !== stable(component.data),\n ),\n ...[...prior.components.keys()]\n .filter((name) => !entry.components.some((component) => component.name === name))\n .map((name) => ({ name, operation: 'remove' as const, data: {} })),\n ];\n if (full || prior === undefined || components.length > 0)\n entities.push({ id: entry.id, kind: 'upsert', components });\n }\n // A full baseline is consumed by a fresh replica, so it must describe\n // only live entities. Despawn records refer to the previous authority\n // baseline and would be unknown identities on a late-joining replica.\n if (!full)\n for (const [entity, prior] of this.#known) {\n if (!current.has(entity)) entities.push({ id: prior.id, kind: 'despawn', components: [] });\n }\n\n const candidateKnown = new Map<EntityHandle, KnownEntity>();\n for (const [entity, entry] of current) {\n candidateKnown.set(entity, {\n id: entry.id,\n components: new Map(\n entry.components.map((component) => [component.name, stable(component.data)]),\n ),\n });\n }\n for (const [entity] of candidateIds) {\n if (!current.has(entity)) candidateIds.delete(entity);\n }\n\n const batch: ReplicationBatch = {\n version: REPLICATION_PROTOCOL_VERSION,\n fingerprint: this.#profile.fingerprint,\n tick: this.#tick + 1,\n full,\n entities,\n };\n const encoded = encodeReplicationBatch(\n batch,\n this.#profile.limits ?? DEFAULT_REPLICATION_LIMITS,\n );\n if (!encoded.ok) return err(encoded.error);\n\n this.#ids.clear();\n for (const [entity, id] of candidateIds) this.#ids.set(entity, id);\n this.#known.clear();\n for (const [entity, known] of candidateKnown) this.#known.set(entity, known);\n this.#nextId = candidateNextId;\n this.#tick = batch.tick;\n return ok({ ...batch, bytes: encoded.value });\n }\n}\nexport function createAuthorityCoordinator(\n world: World,\n profile: ReplicationProfile,\n): AuthorityCoordinator {\n return new AuthorityCoordinator(world, profile);\n}\n","import { err, ok, type Result } from '@forgeax/engine-types';\nimport { NetError } from './errors';\nimport type { ReplicationProfile } from './profile';\nexport function validateHandshake(\n local: ReplicationProfile,\n remote: ReplicationProfile,\n): Result<void, NetError> {\n if (local.fingerprint !== remote.fingerprint)\n return err(\n new NetError({\n code: 'handshake-profile-mismatch',\n expected: 'matching protocol, profile, and declared limits',\n hint: 'use identical ordered replication components and limits on both peers',\n detail: { localFingerprint: local.fingerprint, remoteFingerprint: remote.fingerprint },\n }),\n );\n return ok(undefined);\n}\n","import type { Component, EntityHandle, World } from '@forgeax/engine-ecs';\nimport { classifyEntityField } from '@forgeax/engine-ecs/externalization';\nimport { componentSchema } from '@forgeax/engine-ecs/internal';\nimport { err, ok, type Result } from '@forgeax/engine-types';\nimport type { NetEndpoint } from '../endpoint/endpoint';\nimport { decodeReplicationBatch, type ReplicationBatch } from './codec';\nimport { NetError } from './errors';\nimport type { ReplicationLimits, ReplicationProfile } from './profile';\n\nexport class ReplicaCoordinator {\n readonly #world: World;\n readonly #profile: ReplicationProfile;\n readonly #endpoint: NetEndpoint | undefined;\n readonly #entities = new Map<number, EntityHandle>();\n #lastTick = 0;\n #stopped = false;\n constructor(world: World, profile: ReplicationProfile, endpoint?: NetEndpoint) {\n this.#world = world;\n this.#profile = profile;\n this.#endpoint = endpoint;\n }\n entityFor(id: number): EntityHandle | undefined {\n return this.#entities.get(id);\n }\n readComponent(id: number, component: Component): Record<string, unknown> | undefined {\n const entity = this.#entities.get(id);\n if (entity === undefined) return undefined;\n const read = this.#world.get(entity, component);\n return read.ok ? (read.value as Record<string, unknown>) : undefined;\n }\n snapshot(): readonly { id: number; components: readonly string[] }[] {\n return [...this.#entities]\n .map(([id, entity]) => ({\n id,\n components: this.#profile.components\n .filter((component) => this.#world.get(entity, component).ok)\n .map((component) => component.name),\n }))\n .sort((a, b) => a.id - b.id);\n }\n disconnect(): void {\n this.#endpoint?.close();\n }\n /** Remove the last replica baseline when the authority connection closes. */\n clear(): void {\n for (const entity of this.#entities.values()) this.#world.despawn(entity).unwrap();\n this.#entities.clear();\n }\n get stopped(): boolean {\n return this.#stopped;\n }\n get tick(): number {\n return this.#lastTick;\n }\n #entityReferences(value: unknown): readonly unknown[] {\n if (Array.isArray(value) || ArrayBuffer.isView(value)) {\n return Array.from(value as ArrayLike<unknown>);\n }\n return [];\n }\n validate(batch: ReplicationBatch): NetError | null {\n if (this.#stopped)\n return new NetError({\n code: 'apply-invariant-failed',\n expected: 'an active replica coordinator',\n hint: 'create a new session after a fatal apply failure',\n detail: { reason: 'replication stopped' },\n });\n if (batch.fingerprint !== this.#profile.fingerprint)\n return new NetError({\n code: 'schema-invalid',\n expected: 'a batch for the negotiated replication profile',\n hint: 'complete handshake before applying replication bytes',\n detail: { component: '', reason: 'fingerprint mismatch' },\n });\n if (batch.tick <= this.#lastTick)\n return new NetError({\n code: 'ordering-invalid-tick',\n expected: 'a strictly monotonic authority tick',\n hint: 'discard duplicate, stale, and out-of-order batches',\n detail: { receivedTick: batch.tick, lastTick: this.#lastTick },\n });\n const batchIds = new Set<number>();\n for (const record of batch.entities) {\n if (!Number.isSafeInteger(record.id) || record.id <= 0 || batchIds.has(record.id))\n return new NetError({\n code: 'identity-invalid',\n expected: 'unique non-zero NetEntityId values',\n hint: 'use session-issued identity values exactly once per batch',\n detail: { id: record.id, reason: 'zero, invalid, or duplicate identity' },\n });\n batchIds.add(record.id);\n }\n for (const record of batch.entities) {\n if (record.kind === 'despawn' && !this.#entities.has(record.id))\n return new NetError({\n code: 'identity-invalid',\n expected: 'a known identity for despawn',\n hint: 'do not reuse or despawn unknown network identities',\n detail: { id: record.id, reason: 'unknown identity' },\n });\n for (const entry of record.components) {\n const component = this.#profile.components.find(\n (candidate) => candidate.name === entry.name,\n );\n if (component === undefined)\n return new NetError({\n code: 'schema-invalid',\n expected: 'a component selected by the negotiated profile',\n hint: 'send only components from the ordered replication profile',\n detail: { component: entry.name, reason: 'unselected component' },\n });\n if (entry.operation === 'remove') continue;\n for (const [field, value] of Object.entries(entry.data)) {\n if (!(field in componentSchema(component)))\n return new NetError({\n code: 'schema-invalid',\n expected: 'component fields declared by the negotiated ECS schema',\n hint: 'send only fields declared by the replicated component token',\n detail: { component: entry.name, reason: `unknown field ${field}` },\n });\n const kind = classifyEntityField(component, field);\n const refs = kind?.isArray ? this.#entityReferences(value) : kind ? [value] : [];\n for (const reference of refs)\n if (\n reference !== null &&\n (typeof reference !== 'number' ||\n reference === 0 ||\n (!this.#entities.has(reference) && !batchIds.has(reference)))\n )\n return new NetError({\n code: 'remap-unresolved-reference',\n expected: 'every entity reference to resolve in the current or same batch',\n hint: 'include the referenced spawn in this batch; cross-batch pending references are unsupported',\n detail: { id: record.id, referencedId: Number(reference) },\n });\n }\n }\n }\n return null;\n }\n apply(batch: ReplicationBatch): Result<void, NetError> {\n const failure = this.validate(batch);\n if (failure) {\n this.disconnect();\n return err(failure);\n }\n try {\n for (const record of batch.entities)\n if (record.kind === 'upsert' && !this.#entities.has(record.id))\n this.#entities.set(record.id, this.#world.spawn().unwrap());\n for (const record of batch.entities)\n if (record.kind === 'upsert') {\n const entity = this.#entities.get(record.id);\n if (entity === undefined) throw new Error(`missing allocated entity ${record.id}`);\n for (const entry of record.components) {\n const component = this.#profile.components.find(\n (candidate) => candidate.name === entry.name,\n );\n if (component === undefined) throw new Error(`missing profile component ${entry.name}`);\n if (entry.operation === 'remove') {\n const removal = this.#world.removeComponent(entity, component);\n if (!removal.ok) throw removal.error;\n continue;\n }\n const data = Object.fromEntries(\n Object.entries(entry.data).map(([field, value]) => {\n const kind = classifyEntityField(component, field);\n if (kind === null) return [field, value];\n const mapped = kind.isArray\n ? this.#entityReferences(value).map((id) => {\n if (id === null) return null;\n const reference = this.#entities.get(id as number);\n if (reference === undefined)\n throw new Error(`missing entity reference ${id}`);\n return reference;\n })\n : value === null\n ? null\n : this.#entities.get(value as number);\n if (mapped === undefined) throw new Error(`missing entity reference ${value}`);\n return [field, mapped];\n }),\n );\n const typedData = data as never;\n const exists = this.#world.get(entity, component);\n const write = exists.ok\n ? this.#world.set(entity, component, typedData)\n : this.#world.addComponent(entity, { component, data: typedData });\n if (!write.ok) throw write.error;\n }\n }\n for (const record of batch.entities)\n if (record.kind === 'despawn') {\n const entity = this.#entities.get(record.id);\n if (entity === undefined) throw new Error(`missing despawn entity ${record.id}`);\n this.#world.despawn(entity).unwrap();\n this.#entities.delete(record.id);\n }\n this.#lastTick = batch.tick;\n return ok(undefined);\n } catch (cause) {\n this.#stopped = true;\n return err(\n new NetError({\n code: 'apply-invariant-failed',\n expected: 'ECS apply invariants to accept a validated batch',\n hint: 'stop this replication session and inspect the ECS error',\n detail: { reason: cause instanceof Error ? cause.message : String(cause) },\n }),\n );\n }\n }\n}\nexport function createReplicaCoordinator(\n world: World,\n profile: ReplicationProfile,\n endpoint?: NetEndpoint,\n): ReplicaCoordinator {\n return new ReplicaCoordinator(world, profile, endpoint);\n}\nexport function applyReplicaBatch(\n replica: ReplicaCoordinator,\n batch: ReplicationBatch,\n): Result<void, NetError> {\n return replica.apply(batch);\n}\n\nexport function decodeAndApplyReplicaBatch(\n replica: ReplicaCoordinator,\n bytes: Uint8Array,\n limits: ReplicationLimits,\n): Result<void, NetError> {\n const decoded = decodeReplicationBatch(bytes, limits);\n if (!decoded.ok) {\n replica.disconnect();\n return err(decoded.error);\n }\n return replica.apply(decoded.value);\n}\n","// @forgeax/engine-net -- NetSession host-neutral World integration.\n// (requirements AC-04, plan-strategy D-1/D-3)\n\nimport { err, ok, type Result } from '@forgeax/engine-types';\nimport type { NetEndpoint, PeerId } from '../endpoint/endpoint';\nimport type { EndpointError } from '../endpoint/errors';\nimport type { AuthorityCoordinator } from '../replication/authority';\nimport type { NetError } from '../replication/errors';\nimport type { ReplicationLimits } from '../replication/profile';\nimport { decodeAndApplyReplicaBatch, type ReplicaCoordinator } from '../replication/replica';\n\nexport interface PeerSnapshot {\n readonly peerIds: ReadonlyArray<PeerId>;\n readonly connected: boolean;\n}\n\nexport interface NetSessionConfig {\n readonly endpoint: NetEndpoint;\n readonly maxRawMessages: number;\n}\n\nexport interface RawMessage {\n readonly peerId: PeerId;\n readonly data: Uint8Array;\n}\n\nexport class NetSession {\n readonly #endpoint: NetEndpoint;\n readonly #peerIds = new Set<PeerId>();\n #rawMessages: RawMessage[] = [];\n readonly #maxRawMessages: number;\n #authority: AuthorityCoordinator | undefined;\n readonly #pendingFullPeers = new Set<PeerId>();\n #replica:\n | { readonly coordinator: ReplicaCoordinator; readonly limits: ReplicationLimits }\n | undefined;\n\n constructor(config: NetSessionConfig) {\n this.#endpoint = config.endpoint;\n this.#maxRawMessages = config.maxRawMessages;\n }\n\n receiveEvents(): readonly NetError[] {\n const errors: NetError[] = [];\n for (const event of this.#endpoint.poll()) {\n if (event.kind === 'peer-connected') {\n this.#peerIds.add(event.peerId);\n // Transport admission must not imply application admission, but every\n // newly connected replica still needs the generic replication baseline.\n this.#pendingFullPeers.add(event.peerId);\n } else if (event.kind === 'peer-disconnected') {\n this.#peerIds.delete(event.peerId);\n this.#pendingFullPeers.delete(event.peerId);\n this.#replica?.coordinator.clear();\n } else {\n if (this.#replica !== undefined) {\n const result = decodeAndApplyReplicaBatch(\n this.#replica.coordinator,\n event.data,\n this.#replica.limits,\n );\n if (!result.ok) errors.push(result.error);\n } else if (this.#rawMessages.length < this.#maxRawMessages) {\n this.#rawMessages.push({ peerId: event.peerId, data: event.data });\n }\n }\n }\n return errors;\n }\n\n drainRawMessages(): RawMessage[] {\n return this.#rawMessages.splice(0);\n }\n\n getPeerSnapshot(): PeerSnapshot {\n const peerIds = [...this.#peerIds].sort((left, right) => left - right);\n return { peerIds, connected: peerIds.length > 0 };\n }\n\n sendRaw(peerId: PeerId, data: Uint8Array): Result<void, EndpointError> {\n const result = this.#endpoint.send(peerId, data);\n return result.ok ? ok(undefined) : err(result.error);\n }\n\n attachAuthority(authority: AuthorityCoordinator): void {\n this.#authority = authority;\n }\n\n requestFullBaseline(peerId: PeerId): void {\n if (this.#peerIds.has(peerId)) this.#pendingFullPeers.add(peerId);\n }\n\n attachReplica(coordinator: ReplicaCoordinator, limits: ReplicationLimits): void {\n this.#replica = { coordinator, limits };\n }\n\n publish(): Result<void, NetError | EndpointError> {\n if (this.#authority === undefined) return ok(undefined);\n if (this.#pendingFullPeers.size > 0) {\n const published = this.#authority.publishFull();\n if (!published.ok) return err(published.error);\n for (const peerId of this.#pendingFullPeers) {\n if (this.#peerIds.has(peerId)) {\n const sent = this.#endpoint.send(peerId, published.value.bytes);\n if (!sent.ok) return err(sent.error);\n }\n }\n this.#pendingFullPeers.clear();\n }\n const published = this.#authority.publish();\n if (!published.ok) return err(published.error);\n for (const peerId of this.#peerIds) {\n const sent = this.#endpoint.send(peerId, published.value.bytes);\n if (!sent.ok) return err(sent.error);\n }\n return ok(undefined);\n }\n}\n","// @forgeax/engine-net -- session plugin (host-neutral World integration).\n// (requirements AC-04, plan-strategy D-1/D-3)\n\nimport { FixedUpdate, Update } from '@forgeax/engine-ecs';\nimport type { Plugin } from '@forgeax/engine-plugin';\nimport type { NetEndpoint } from '../endpoint/endpoint';\nimport { NetSession } from './net-session';\n\nexport interface NetPluginConfig {\n readonly endpoint: NetEndpoint;\n readonly maxRawMessages?: number;\n}\n\nexport function netPlugin(config: NetPluginConfig): Plugin {\n return {\n name: 'net-session',\n inject: ['world'],\n apply(ctx) {\n const world = ctx.world;\n const session = new NetSession({\n endpoint: config.endpoint,\n maxRawMessages: config.maxRawMessages ?? 256,\n });\n ctx.effect(() => {\n world.insertResource('net-session', session);\n return () => world.removeResource('net-session');\n }, 'net/session-resource');\n ctx.effect(() => {\n world\n .addSystem(Update, {\n name: 'net-receive',\n queries: [],\n before: [FixedUpdate],\n fn: (world) => world.getResource<NetSession>('net-session').receiveEvents(),\n })\n .unwrap();\n return () => world.removeSystem(Update, 'net-receive');\n }, 'net/receive');\n ctx.effect(() => {\n world\n .addSystem(Update, {\n name: 'net-publish',\n queries: [],\n after: [FixedUpdate],\n fn: (world) => world.getResource<NetSession>('net-session').publish(),\n })\n .unwrap();\n return () => world.removeSystem(Update, 'net-publish');\n }, 'net/publish');\n },\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { EntityHandle, World } from '@forgeax/engine-ecs';
2
+ import { type Result } from '@forgeax/engine-types';
3
+ import { type ReplicationBatch } from './codec';
4
+ import type { NetError } from './errors';
5
+ import { type ReplicationProfile } from './profile';
6
+ export interface PublishedBatch extends ReplicationBatch {
7
+ readonly bytes: Uint8Array;
8
+ }
9
+ export declare class AuthorityCoordinator {
10
+ #private;
11
+ constructor(world: World, profile: ReplicationProfile);
12
+ idFor(entity: EntityHandle): number;
13
+ publish(): Result<PublishedBatch, NetError>;
14
+ publishFull(): Result<PublishedBatch, NetError>;
15
+ }
16
+ export declare function createAuthorityCoordinator(world: World, profile: ReplicationProfile): AuthorityCoordinator;
17
+ //# sourceMappingURL=authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../../src/replication/authority.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAA8B,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEhF,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AASD,qBAAa,oBAAoB;;gBAOnB,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB;IAIrD,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;IAGnC,OAAO,IAAI,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC;IAG3C,WAAW,IAAI,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC;CAiGhD;AACD,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,kBAAkB,GAC1B,oBAAoB,CAEtB"}
@@ -0,0 +1,26 @@
1
+ import { type Result } from '@forgeax/engine-types';
2
+ import { NetError } from './errors';
3
+ import type { ReplicationLimits } from './profile';
4
+ export type NetEntityId = number & {
5
+ readonly __netEntityId: unique symbol;
6
+ };
7
+ export interface ReplicationComponentRecord {
8
+ readonly name: string;
9
+ readonly operation?: 'replace' | 'remove';
10
+ readonly data: Record<string, unknown>;
11
+ }
12
+ export interface ReplicationEntityRecord {
13
+ readonly id: number;
14
+ readonly kind: 'upsert' | 'despawn';
15
+ readonly components: readonly ReplicationComponentRecord[];
16
+ }
17
+ export interface ReplicationBatch {
18
+ readonly version: number;
19
+ readonly fingerprint: string;
20
+ readonly tick: number;
21
+ readonly full: boolean;
22
+ readonly entities: readonly ReplicationEntityRecord[];
23
+ }
24
+ export declare function encodeReplicationBatch(batch: ReplicationBatch, limits: ReplicationLimits): Result<Uint8Array, NetError>;
25
+ export declare function decodeReplicationBatch(bytes: Uint8Array, limits: ReplicationLimits): Result<ReplicationBatch, NetError>;
26
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/replication/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,aAAa,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAC7E,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AACD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,SAAS,0BAA0B,EAAE,CAAC;CAC5D;AACD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,uBAAuB,EAAE,CAAC;CACvD;AA2MD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,iBAAiB,GACxB,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAI9B;AACD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,iBAAiB,GACxB,MAAM,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAoBpC"}
@@ -0,0 +1,2 @@
1
+ export declare const REPLICATION_PROTOCOL_VERSION = 1;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/replication/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,IAAI,CAAC"}
@@ -0,0 +1,66 @@
1
+ type NetErrorDetailByCode = {
2
+ 'handshake-profile-mismatch': {
3
+ readonly localFingerprint: string;
4
+ readonly remoteFingerprint: string;
5
+ };
6
+ 'decode-invalid-payload': {
7
+ readonly reason: string;
8
+ };
9
+ 'decode-limit-exceeded': {
10
+ readonly limit: string;
11
+ readonly actual: number;
12
+ readonly maximum: number;
13
+ };
14
+ 'ordering-invalid-tick': {
15
+ readonly receivedTick: number;
16
+ readonly lastTick: number;
17
+ };
18
+ 'identity-invalid': {
19
+ readonly id: number;
20
+ readonly reason: string;
21
+ };
22
+ 'schema-invalid': {
23
+ readonly component: string;
24
+ readonly reason: string;
25
+ };
26
+ 'remap-unresolved-reference': {
27
+ readonly id: number;
28
+ readonly referencedId: number;
29
+ };
30
+ 'apply-invariant-failed': {
31
+ readonly reason: string;
32
+ };
33
+ };
34
+ export type NetErrorCode = keyof NetErrorDetailByCode;
35
+ export type NetErrorDetail = NetErrorDetailByCode[NetErrorCode];
36
+ declare class NetErrorClass extends Error {
37
+ readonly code: NetErrorCode;
38
+ readonly expected: string;
39
+ readonly hint: string;
40
+ readonly detail: NetErrorDetail;
41
+ constructor(args: {
42
+ code: NetErrorCode;
43
+ expected: string;
44
+ hint: string;
45
+ detail: NetErrorDetail;
46
+ });
47
+ }
48
+ type Variant<C extends NetErrorCode> = NetErrorClass & {
49
+ readonly code: C;
50
+ readonly detail: NetErrorDetailByCode[C];
51
+ };
52
+ export type NetError = {
53
+ [C in NetErrorCode]: Variant<C>;
54
+ }[NetErrorCode];
55
+ interface NetErrorConstructor {
56
+ new <C extends NetErrorCode>(args: {
57
+ code: C;
58
+ expected: string;
59
+ hint: string;
60
+ detail: NetErrorDetailByCode[C];
61
+ }): Variant<C>;
62
+ readonly prototype: NetErrorClass;
63
+ }
64
+ export declare const NetError: NetErrorConstructor;
65
+ export {};
66
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/replication/errors.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG;IAC1B,4BAA4B,EAAE;QAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;QAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;KACpC,CAAC;IACF,wBAAwB,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,uBAAuB,EAAE;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,uBAAuB,EAAE;QAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACtF,kBAAkB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KAAK,CAAC,SAAS,YAAY,EAAE,IAAI,EAAE;QACjC,IAAI,EAAE,CAAC,CAAC;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;KACjC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACf,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;CACnC;AACD,eAAO,MAAM,QAAQ,EAAE,mBAAqE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type Result } from '@forgeax/engine-types';
2
+ import { NetError } from './errors';
3
+ import type { ReplicationProfile } from './profile';
4
+ export declare function validateHandshake(local: ReplicationProfile, remote: ReplicationProfile): Result<void, NetError>;
5
+ //# sourceMappingURL=handshake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/replication/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,kBAAkB,GACzB,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAWxB"}
@@ -0,0 +1,31 @@
1
+ import type { Component } from '@forgeax/engine-ecs';
2
+ import { type Result } from '@forgeax/engine-types';
3
+ export interface ReplicationLimits {
4
+ readonly maxMessageBytes: number;
5
+ readonly maxEntities: number;
6
+ readonly maxComponentOperations: number;
7
+ readonly maxStringBytes: number;
8
+ readonly maxBufferBytes: number;
9
+ readonly maxArrayElements: number;
10
+ }
11
+ export declare const DEFAULT_REPLICATION_LIMITS: ReplicationLimits;
12
+ import { NetError } from './errors';
13
+ export interface ReplicationProfile {
14
+ readonly name: string;
15
+ readonly entities: ReplicationEntityFilter;
16
+ readonly components: readonly Component[];
17
+ readonly limits: ReplicationLimits;
18
+ readonly fingerprint: string;
19
+ }
20
+ export interface ReplicationEntityFilter {
21
+ readonly with: readonly Component[];
22
+ readonly without?: readonly Component[];
23
+ }
24
+ export interface DefineReplicationOptions {
25
+ readonly name: string;
26
+ readonly entities: ReplicationEntityFilter;
27
+ readonly components: readonly Component[];
28
+ readonly limits?: Partial<ReplicationLimits>;
29
+ }
30
+ export declare function defineReplication(options: DefineReplicationOptions): Result<ReplicationProfile, NetError>;
31
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/replication/profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC7D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AACD,eAAO,MAAM,0BAA0B,EAAE,iBAOxC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,CAAC;IAC3C,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AACD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;CACzC;AACD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,CAAC;IAC3C,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC9C;AA8BD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,wBAAwB,GAChC,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAuCtC"}
@@ -0,0 +1,27 @@
1
+ import type { Component, EntityHandle, World } from '@forgeax/engine-ecs';
2
+ import { type Result } from '@forgeax/engine-types';
3
+ import type { NetEndpoint } from '../endpoint/endpoint';
4
+ import { type ReplicationBatch } from './codec';
5
+ import { NetError } from './errors';
6
+ import type { ReplicationLimits, ReplicationProfile } from './profile';
7
+ export declare class ReplicaCoordinator {
8
+ #private;
9
+ constructor(world: World, profile: ReplicationProfile, endpoint?: NetEndpoint);
10
+ entityFor(id: number): EntityHandle | undefined;
11
+ readComponent(id: number, component: Component): Record<string, unknown> | undefined;
12
+ snapshot(): readonly {
13
+ id: number;
14
+ components: readonly string[];
15
+ }[];
16
+ disconnect(): void;
17
+ /** Remove the last replica baseline when the authority connection closes. */
18
+ clear(): void;
19
+ get stopped(): boolean;
20
+ get tick(): number;
21
+ validate(batch: ReplicationBatch): NetError | null;
22
+ apply(batch: ReplicationBatch): Result<void, NetError>;
23
+ }
24
+ export declare function createReplicaCoordinator(world: World, profile: ReplicationProfile, endpoint?: NetEndpoint): ReplicaCoordinator;
25
+ export declare function applyReplicaBatch(replica: ReplicaCoordinator, batch: ReplicationBatch): Result<void, NetError>;
26
+ export declare function decodeAndApplyReplicaBatch(replica: ReplicaCoordinator, bytes: Uint8Array, limits: ReplicationLimits): Result<void, NetError>;
27
+ //# sourceMappingURL=replica.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../../src/replication/replica.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG1E,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEvE,qBAAa,kBAAkB;;gBAOjB,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,CAAC,EAAE,WAAW;IAK7E,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAG/C,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAMpF,QAAQ,IAAI,SAAS;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,EAAE;IAUpE,UAAU,IAAI,IAAI;IAGlB,6EAA6E;IAC7E,KAAK,IAAI,IAAI;IAIb,IAAI,OAAO,IAAI,OAAO,CAErB;IACD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAOD,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,QAAQ,GAAG,IAAI;IAiFlD,KAAK,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC;CAwEvD;AACD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,CAAC,EAAE,WAAW,GACrB,kBAAkB,CAEpB;AACD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,gBAAgB,GACtB,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAExB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,iBAAiB,GACxB,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAOxB"}
@@ -0,0 +1,32 @@
1
+ import { type Result } from '@forgeax/engine-types';
2
+ import type { NetEndpoint, PeerId } from '../endpoint/endpoint';
3
+ import type { EndpointError } from '../endpoint/errors';
4
+ import type { AuthorityCoordinator } from '../replication/authority';
5
+ import type { NetError } from '../replication/errors';
6
+ import type { ReplicationLimits } from '../replication/profile';
7
+ import { type ReplicaCoordinator } from '../replication/replica';
8
+ export interface PeerSnapshot {
9
+ readonly peerIds: ReadonlyArray<PeerId>;
10
+ readonly connected: boolean;
11
+ }
12
+ export interface NetSessionConfig {
13
+ readonly endpoint: NetEndpoint;
14
+ readonly maxRawMessages: number;
15
+ }
16
+ export interface RawMessage {
17
+ readonly peerId: PeerId;
18
+ readonly data: Uint8Array;
19
+ }
20
+ export declare class NetSession {
21
+ #private;
22
+ constructor(config: NetSessionConfig);
23
+ receiveEvents(): readonly NetError[];
24
+ drainRawMessages(): RawMessage[];
25
+ getPeerSnapshot(): PeerSnapshot;
26
+ sendRaw(peerId: PeerId, data: Uint8Array): Result<void, EndpointError>;
27
+ attachAuthority(authority: AuthorityCoordinator): void;
28
+ requestFullBaseline(peerId: PeerId): void;
29
+ attachReplica(coordinator: ReplicaCoordinator, limits: ReplicationLimits): void;
30
+ publish(): Result<void, NetError | Endp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AItD,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIzC,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAI/E,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,aAAa,CAAC;CAqBlD"}
@@ -0,0 +1,8 @@
1
+ import type { Plugin } from '@forgeax/engine-plugin';
2
+ import type { NetEndpoint } from '../endpoint/endpoint';
3
+ export interface NetPluginConfig {
4
+ readonly endpoint: NetEndpoint;
5
+ readonly maxRawMessages?: number;
6
+ }
7
+ export declare function netPlugin(config: NetPluginConfig): Plugin;
8
+ //# sourceMappingURL=session-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-plugin.d.ts","sourceRoot":"","sources":["../../src/session/session-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAsCzD"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@forgeax/engine-net",
3
+ "version": "0.1.2",
4
+ "private": false,
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "sideEffects": false,
8
+ "description": "Memory network transport, replication session, and profile-driven ECS sync for forgeax Engine.",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "main": "./dist/index.mjs",
17
+ "types": "./dist/index.d.ts",
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "dependencies": {
25
+ "@forgeax/engine-ecs": "0.1.2",
26
+ "@forgeax/engine-plugin": "0.1.2",
27
+ "@forgeax/engine-types": "0.1.2"
28
+ },
29
+ "forgeax": {
30
+ "metrics": {
31
+ "bundle-size": {
32
+ "enabled": true,
33
+ "path": "dist/index.mjs",
34
+ "compression": "gzip"
35
+ },
36
+ "fps": {
37
+ "enabled": false,
38
+ "reason": "library package; no runtime canvas; E2E proof deferred to Loop 3"
39
+ },
40
+ "bench": {
41
+ "enabled": false,
42
+ "reason": "no performance benchmarks; deterministic correctness verified by unit and model tests"
43
+ },
44
+ "gate": {
45
+ "enabled": false,
46
+ "reason": "no package-level binary gate; net correctness gated by pnpm test:unit"
47
+ },
48
+ "spike-report": {
49
+ "enabled": false,
50
+ "reason": "not a spike package"
51
+ }
52
+ }
53
+ },
54
+ "scripts": {
55
+ "build": "tsup",
56
+ "test": "vitest run"
57
+ }
58
+ }
@@ -0,0 +1,50 @@
1
+ // @forgeax/engine-net -- transport-only endpoint contract.
2
+ //
3
+ // NetEndpoint is the minimum transport seam: complete bytes, actual PeerId,
4
+ // and connect/disconnect lifecycle. No ECS, profile, or codec dependency.
5
+ // Reliable ordered delivery per peer or explicit connection failure.
6
+ // (requirements AC-02, plan-strategy D-3)
7
+
8
+ import type { Result } from '@forgeax/engine-types';
9
+ import type { EndpointError } from './errors';
10
+
11
+ // ---------------------------------------------------------------------------
12
+ // PeerId -- opaque, branded peer identity (transport-level, not NetEntityId)
13
+ // ---------------------------------------------------------------------------
14
+
15
+ declare const __peerIdBrand: unique symbol;
16
+
17
+ /** Opaque transport-level peer identity. Never a plain number. */
18
+ export type PeerId = number & { readonly [__peerIdBrand]: true };
19
+
20
+ // ---------------------------------------------------------------------------
21
+ // Endpoint events
22
+ // ---------------------------------------------------------------------------
23
+
24
+ /** Transport-level event emitted by NetEndpoint.poll(). */
25
+ export type EndpointEvent =
26
+ | { readonly kind: 'peer-connected'; readonly peerId: PeerId }
27
+ | { readonly kind: 'peer-disconnected'; readonly peerId: PeerId }
28
+ | { readonly kind: 'message'; readonly peerId: PeerId; readonly data: Uint8Array };
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // NetEndpoint -- transport-only contract
32
+ // ---------------------------------------------------------------------------
33
+
34
+ /**
35
+ * Transport-only endpoint contract.
36
+ *
37
+ * Delivers complete Uint8Array messages with actual PeerId and connect/disconnect
38
+ * lifecycle. Reliable ordered delivery per peer or explicit connection failure.
39
+ * No ECS, profile, or codec knowledge.
40
+ */
41
+ export interface NetEndpoint {
42
+ /** Poll for pending events (connect, disconnect, message). Returns empty array when idle. */
43
+ poll(): EndpointEvent[];
44
+
45
+ /** Send a complete message to a connected peer. Returns structured error on failure. */
46
+ send(peerId: PeerId, data: Uint8Array): Result<void, EndpointError>;
47
+
48
+ /** Close the endpoint. No further send/poll should succeed after close. */
49
+ close(): Result<void, EndpointError>;
50
+ }