@nxtedition/shared 1.0.1 → 1.0.11

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/package.json CHANGED
@@ -1,66 +1,31 @@
1
1
  {
2
2
  "name": "@nxtedition/shared",
3
- "version": "1.0.1",
4
- "description": "Ring Buffer for NodeJS cross Worker communication",
5
- "main": "index.js",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/nxtedition/shared.git"
9
- },
10
- "author": "Robert Nagy <ronagy@icloud.com>",
11
- "license": "MIT License",
12
- "bugs": {
13
- "url": "https://github.com/nxtedition/shared/issues"
14
- },
3
+ "version": "1.0.11",
15
4
  "type": "module",
16
- "homepage": "https://github.com/nxtedition/shared#readme",
17
- "lint-staged": {
18
- "*.{js,jsx,ts}": [
19
- "eslint",
20
- "prettier --write"
21
- ]
22
- },
23
- "prettier": {
24
- "printWidth": 100,
25
- "semi": false,
26
- "singleQuote": true,
27
- "jsxSingleQuote": true
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "license": "MIT",
13
+ "publishConfig": {
14
+ "access": "public"
28
15
  },
29
- "eslintConfig": {
30
- "root": true,
31
- "parserOptions": {
32
- "ecmaFeatures": {
33
- "ecmaVersion": 2020
34
- }
35
- },
36
- "extends": [
37
- "standard",
38
- "prettier",
39
- "prettier/prettier"
40
- ],
41
- "rules": {
42
- "quotes": [
43
- "error",
44
- "single",
45
- {
46
- "avoidEscape": true,
47
- "allowTemplateLiterals": true
48
- }
49
- ]
50
- }
16
+ "scripts": {
17
+ "build": "rimraf lib && tsc && amaroc ./src/index.ts && mv src/index.js lib/",
18
+ "prepublishOnly": "yarn build",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "node --test",
21
+ "test:ci": "node --test"
51
22
  },
52
23
  "devDependencies": {
53
- "eslint": "^8.12.0",
54
- "eslint-config-prettier": "^8.4.0",
55
- "eslint-config-standard": "^16.0.3",
56
- "eslint-plugin-import": "^2.25.4",
57
- "eslint-plugin-node": "^11.1.0",
58
- "eslint-plugin-promise": "^6.0.0",
59
- "husky": "^7.0.4",
60
- "lint-staged": "^12.3.7",
61
- "prettier": "^2.6.2"
24
+ "@types/node": "^25.2.3",
25
+ "amaroc": "^1.0.1",
26
+ "oxlint-tsgolint": "^0.12.2",
27
+ "rimraf": "^6.1.2",
28
+ "typescript": "^5.9.3"
62
29
  },
63
- "scripts": {
64
- "prepare": "husky install"
65
- }
30
+ "gitHead": "8d4e78508c35ce7b42e5bed4750add7d548aa86b"
66
31
  }
package/.editorconfig DELETED
@@ -1,12 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- end_of_line = lf
7
- charset = utf-8
8
- trim_trailing_whitespace = true
9
- insert_final_newline = true
10
-
11
- [*.md]
12
- trim_trailing_whitespace = false
package/.husky/pre-commit DELETED
@@ -1,3 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
- npx lint-staged
package/index.js DELETED
@@ -1,128 +0,0 @@
1
- const WRITE_INDEX = 0
2
- const READ_INDEX = 1
3
- const END_OF_PACKET = -1
4
-
5
- export function alloc(size) {
6
- return {
7
- sharedState: new SharedArrayBuffer(8),
8
- sharedBuffer: new SharedArrayBuffer(size),
9
- }
10
- }
11
-
12
- async function* _reader({ sharedState, sharedBuffer }, cb) {
13
- const state = new Int32Array(sharedState)
14
- const buffer = Buffer.from(sharedBuffer)
15
-
16
- let readPos = 0
17
- let writePos = 0
18
-
19
- while (true) {
20
- const { async, value } = Atomics.waitAsync(state, WRITE_INDEX, writePos)
21
- if (async) {
22
- await value
23
- }
24
- writePos = Atomics.load(state, WRITE_INDEX)
25
-
26
- while (readPos !== writePos) {
27
- const len = buffer.readInt32LE(readPos)
28
-
29
- if (len === END_OF_PACKET) {
30
- readPos = 0
31
- } else {
32
- const raw = buffer.slice(readPos + 4, readPos + len)
33
- readPos += len
34
- if (cb) {
35
- const thenable = cb(raw)
36
- if (thenable && typeof thenable.then === 'function') {
37
- await thenable
38
- }
39
- } else {
40
- yield raw
41
- }
42
- }
43
-
44
- Atomics.store(state, READ_INDEX, readPos)
45
- }
46
-
47
- Atomics.notify(state, READ_INDEX)
48
- }
49
- }
50
-
51
- export function reader(options, cb) {
52
- if (cb) {
53
- _reader(options, cb).next()
54
- } else {
55
- return _reader(options)
56
- }
57
- }
58
-
59
- export function writer({ sharedState, sharedBuffer }) {
60
- const state = new Int32Array(sharedState)
61
- const buffer = Buffer.from(sharedBuffer)
62
- const size = buffer.byteLength
63
- const queue = []
64
-
65
- let readPos = 0
66
- let writePos = 0
67
- let flushing = null
68
-
69
- function tryWrite(...raw) {
70
- readPos = Atomics.load(state, READ_INDEX)
71
-
72
- const len = raw.reduce((len, buf) => len + buf.byteLength, 4)
73
-
74
- if (size - writePos < len + 4) {
75
- if (readPos < len + 4) {
76
- return false
77
- }
78
-
79
- buffer.writeInt32LE(-1, writePos)
80
- writePos = 0
81
- } else {
82
- const available = writePos >= readPos ? size - writePos : readPos - writePos
83
-
84
- if (available < len + 4) {
85
- return false
86
- }
87
- }
88
-
89
- buffer.writeInt32LE(len, writePos)
90
- writePos += 4
91
-
92
- for (const buf of raw) {
93
- buffer.set(buf, writePos)
94
- writePos += buf.byteLength
95
- }
96
-
97
- Atomics.store(state, WRITE_INDEX, writePos)
98
- Atomics.notify(state, WRITE_INDEX)
99
-
100
- return true
101
- }
102
-
103
- async function flush() {
104
- while (queue.length) {
105
- while (!tryWrite(queue[0])) {
106
- const { async, value } = Atomics.waitAsync(state, READ_INDEX, readPos)
107
- if (async) {
108
- await value
109
- }
110
- }
111
- queue.shift()
112
- }
113
-
114
- flushing = null
115
- }
116
-
117
- function write(...raw) {
118
- if (!queue.length && tryWrite(...raw)) {
119
- return
120
- }
121
-
122
- queue.push(Buffer.concat(raw))
123
-
124
- return (flushing ??= flush())
125
- }
126
-
127
- return write
128
- }