{"_id":"socket-post-message","_rev":"3-b9fa13c169295e3c6191fff306a86c45","name":"socket-post-message","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"socket-post-message","version":"1.0.0","devDependencies":{"@types/node":"^20.8.7","minipass":"^7.0.4","prettier":"^2.8.8","tap":"^18.5.2","tshy":"^1.6.0"},"tshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts"}},"exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","type":"module","prettier":{"semi":false,"printWidth":70,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"scripts":{"prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","snap":"tap","test":"tap","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","format":"prettier --write . --loglevel warn --cache","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"tap":{"coverage-map":"map.js"},"dependencies":{"typedoc":"^0.25.2"},"_id":"socket-post-message@1.0.0","gitHead":"cbb0136a2aa1166398aceec056dde5fa46f0507a","description":"Do the `postMessage()`/`on('message')` thing with any arbitrary socket (really, any stream) in Node.js.","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-SoBQdK5K8ll1/m1HiUz3YHb1TyQEh/ntQScutOsIG/I4tVJF2xqhGFDEVWccMEociO0iUXYCfSfQ5n0A7lyMtw==","shasum":"a1b866ba5e3b273047b8824f557b08d7993195e4","tarball":"https://registry.npmjs.org/socket-post-message/-/socket-post-message-1.0.0.tgz","fileCount":16,"unpackedSize":16711,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFhIHkjc47ze4Ig7swB/JhDXfaCnY5w0FBaGola+PpEzAiEAiFzFR3if66DRebTUie20gr7j16hruRCQEOkvi1tmNmk="}]},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/socket-post-message_1.0.0_1698020216419_0.4451912580127504"},"_hasShrinkwrap":false},"1.0.1":{"name":"socket-post-message","version":"1.0.1","devDependencies":{"@types/node":"^20.8.7","minipass":"^7.0.4","prettier":"^2.8.8","tap":"^18.5.2","tshy":"^1.6.0"},"tshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts"}},"exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","type":"module","prettier":{"semi":false,"printWidth":70,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"scripts":{"prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","snap":"tap","test":"tap","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","format":"prettier --write . --loglevel warn --cache","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"dependencies":{"typedoc":"^0.25.2"},"_id":"socket-post-message@1.0.1","gitHead":"20b9c2fe31cd07fbf3a0f74bdd6b57678300f0c1","description":"Do the `postMessage()`/`on('message')` thing with any arbitrary socket (really, any stream) in Node.js.","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-N9ibBZq0WDOxlHe/IvlTJ87cRxblFniBzdCr3d5EZSNQkcmF2WVVgDvZ0rrMkv1f0yZfkPHW46Yr+neQ7eXD9g==","shasum":"b235c3dcf60bfa4cb8deea6c75e4fe0dcbfdd277","tarball":"https://registry.npmjs.org/socket-post-message/-/socket-post-message-1.0.1.tgz","fileCount":20,"unpackedSize":42065,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD5Ih74DrNlXXQJnmxxpsXcDcWzs1evaIB5xl9Mi/LITAIgVerdMDd9/FxJLS/FhZbU2q8eW2IxDd8P5L3XhD8gS2U="}]},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/socket-post-message_1.0.1_1698083845251_0.8548899820831066"},"_hasShrinkwrap":false},"1.0.2":{"name":"socket-post-message","version":"1.0.2","devDependencies":{"@types/node":"^20.8.7","minipass":"^7.0.4","prettier":"^2.8.8","tap":"^18.5.2","tshy":"^1.6.0","typedoc":"^0.25.2"},"tshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts"}},"exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","type":"module","prettier":{"semi":false,"printWidth":70,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"scripts":{"prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","snap":"tap","test":"tap","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","format":"prettier --write . --loglevel warn --cache","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"_id":"socket-post-message@1.0.2","gitHead":"04950b81a310884d4682baa01a79efdd32443c83","description":"Do the `postMessage()`/`on('message')` thing with any arbitrary socket (really, any stream) in Node.js.","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-i9Z93PZJoN9KltYruIjSemDInTLxOOBqgK8XIRJ47uMefFSprvmSOa+VYAl7wq0lCr4t7IEsEtTEeRAjDUCOvQ==","shasum":"26601fe6756a36b20ee9e6f3a08ea05eaea5e39a","tarball":"https://registry.npmjs.org/socket-post-message/-/socket-post-message-1.0.2.tgz","fileCount":20,"unpackedSize":42041,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDVDGoNgK9Hw6/sCgAcbStyygZTMP6nIhQo1t3A/tRISAIhAMeFqRkGhpeWm36VBCzqu8IeNqyq3BRGBPYmtdGgJ+uZ"}]},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/socket-post-message_1.0.2_1698084958013_0.9374817274404315"},"_hasShrinkwrap":false},"1.0.3":{"name":"socket-post-message","version":"1.0.3","devDependencies":{"@types/node":"^20.8.7","minipass":"^7.0.4","prettier":"^2.8.8","tap":"^18.5.2","tshy":"^1.6.0","typedoc":"^0.25.2"},"tshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts"}},"exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","type":"module","prettier":{"semi":false,"printWidth":70,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"scripts":{"prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","snap":"tap","test":"tap","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","format":"prettier --write . --loglevel warn --cache","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"_id":"socket-post-message@1.0.3","gitHead":"f304f24b0b8ea7278cc8a261937434a5570adce4","description":"Do the `postMessage()`/`on('message')` thing with any arbitrary socket (really, any stream) in Node.js.","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-UhJaB3xR2oF+HvddFOq2cBZi4zVKOHvdiBo+BaScNxsEUg3TLWSP8BkweKfe07kfH1thjn1hJR0af/w1EtBFjg==","shasum":"638dfca32064eee9a784bb5be9634b19e649ac39","tarball":"https://registry.npmjs.org/socket-post-message/-/socket-post-message-1.0.3.tgz","fileCount":20,"unpackedSize":42812,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDY9N5KYdNjf53ns5bxPGjOWo/ztocgO6rk6jBzI9EemwIgJI1DwzFDX93YTNuf4GUBU+Tdw6peFnwhNl6le9rJDbw="}]},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/socket-post-message_1.0.3_1698099666195_0.2911110709536795"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-23T00:16:56.316Z","1.0.0":"2023-10-23T00:16:56.645Z","modified":"2023-10-23T22:21:06.608Z","1.0.1":"2023-10-23T17:57:25.437Z","1.0.2":"2023-10-23T18:15:58.417Z","1.0.3":"2023-10-23T22:21:06.424Z"},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"description":"Do the `postMessage()`/`on('message')` thing with any arbitrary socket (really, any stream) in Node.js.","readme":"# socket-post-message\n\nDo the `postMessage()`/`on('message')` thing with any arbitrary\nsocket (really, any stream) in Node.js.\n\n## What this is for\n\nSay you have a socket, like a server/client connected on a\ndomain socket or over a TCP connection, and you want to send and\nreceive arbitrary messages.\n\nThis lets you do that.\n\n## How it works\n\nMessages are encoded using the `serialize` and `deserialize`\nmethods from `node:v8`, and adding a 4 byte header for the\nmessage length.\n\nThis supports many things that are not supported by\nJSON.stringify/parse, like cyclical objects and native JS object\ntypes, but is limited to things that are serializable, so for\nexample, you can't pass a function through the stream and expect\nit to remain intact.\n\nIf the stream emits data that is not parseable, doesn't have a\ncorrect message header, etc., then the returned `messageHost`\nobject will emit an `'error'` event.\n\nIn almost all cases, this is done with zero copying. (There is a\nsmall copy when the message is split across more than 2 chunks,\nbut that's pretty rare.)\n\n## USAGE\n\nInstall it with npm\n\n```\nnpm install socket-post-message\n```\n\nIn the server:\n\n```js\nimport { createServer } from 'node:net'\nimport { socketPostMessage } from 'socket-post-message'\n\nconst server = createServer(connection => {\n  const messageHost = socketPostMessage(connection)\n\n  messageHost.on('message', msg => {\n    messageHost.postMessage(['received', msg])\n  })\n\n  messageHost.postMessage({ status: 'connected' })\n})\n\nsocket.listen('socket-name')\n```\n\nIn the client:\n\n```js\nimport { connect } from 'node:net'\nimport { socketPostMessage } from 'socket-post-message'\n\nconst socket = connect('socket-name')\nconst messageHost = socketPostMessage(socket)\n\nmessageHost.on('message', msg => console.log(msg))\n\nmessageHost.once('connect', () => {\n  messageHost.postMessage({ hello: 'world' })\n})\n\n// outputs:\n// { status: 'connected' }\n// [ 'received', { hello: 'world' } ]\n```\n\n## Caveats\n\nYou can't send file descriptors over the message channel, because\nthat is not supported in Node for sockets. (It was once upon a\ntime supported for domain sockets, but that's not supported by\nWindows named pipes, and so was removed in Node v0.6 when Windows\nsupport was added.) So, the `transferList` feature is not\nsupported.\n\nIf you use the stream for any other kind of data, it's going to\nget weird. You really need to ensure that both sides of the\nchannel stream are using this library (or another \"UInt32BE\nmessage length header + v8 serialized message\" implementation) to\nsend and receive messages. Because basically _any_ series of 4\nbytes can be interpreted as a number, if you write something like\n`\"hello, world\"` to the stream, then it will be interpreted as a\nmessage length header of `0x68656c6c`, and keep reading until it\nhas consumed 1751477356 bytes. Probably not what you want.\n\nIf you do have a message like `'\\0\\0\\0\\x0chello world'`, then the\nreader will consume the 12 bytes of `'hello world'` and then try\nto deserialize it, and that will fail, emitting an error on the\n`messageHost`.\n\nIf communicating across _threads_ in Node, or worker/forked\nprocesses that you control, it's usually better to use either a\n`MessageChannel` pair or an `IPC` stdio file descriptor, as this\nhas more features and an easier setup.\n\nBut if you need to efficiently send and receive arbitrary\nmessages between arbitrary processes, then this is a good choice.\n","readmeFilename":"README.md"}