@effect-vfs/nfs 0.1.0
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/LICENSE +22 -0
- package/README.md +93 -0
- package/dist/NfsServer.d.ts +693 -0
- package/dist/NfsServer.d.ts.map +1 -0
- package/dist/NfsServer.js +439 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/internal/export.d.ts +77 -0
- package/dist/internal/export.d.ts.map +1 -0
- package/dist/internal/export.js +224 -0
- package/dist/internal/lockRanges.d.ts +16 -0
- package/dist/internal/lockRanges.d.ts.map +1 -0
- package/dist/internal/lockRanges.js +12 -0
- package/dist/internal/nfs4.d.ts +194 -0
- package/dist/internal/nfs4.d.ts.map +1 -0
- package/dist/internal/nfs4.js +3561 -0
- package/dist/internal/recordMarking.d.ts +29 -0
- package/dist/internal/recordMarking.d.ts.map +1 -0
- package/dist/internal/recordMarking.js +127 -0
- package/dist/internal/rpc.d.ts +73 -0
- package/dist/internal/rpc.d.ts.map +1 -0
- package/dist/internal/rpc.js +161 -0
- package/dist/internal/server.d.ts +17 -0
- package/dist/internal/server.d.ts.map +1 -0
- package/dist/internal/server.js +78 -0
- package/dist/internal/xdr.d.ts +51 -0
- package/dist/internal/xdr.d.ts.map +1 -0
- package/dist/internal/xdr.js +178 -0
- package/package.json +54 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export class XdrDecodeError extends Data.TaggedError("XdrDecodeError") {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super({ detail: message });
|
|
5
|
+
}
|
|
6
|
+
get message() {
|
|
7
|
+
return this.detail;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const padding = (length) => (4 - length % 4) % 4;
|
|
11
|
+
const assertLimit = (name, value) => {
|
|
12
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
13
|
+
throw new RangeError(`${name} must be a non-negative safe integer`);
|
|
14
|
+
};
|
|
15
|
+
/** @internal */
|
|
16
|
+
export class Reader {
|
|
17
|
+
bytes;
|
|
18
|
+
limits;
|
|
19
|
+
#view;
|
|
20
|
+
#offset = 0;
|
|
21
|
+
constructor(bytes, limits) {
|
|
22
|
+
this.bytes = bytes;
|
|
23
|
+
this.limits = limits;
|
|
24
|
+
assertLimit("maxOpaqueBytes", ByteSize.toNumberUnsafe(limits.maxOpaqueBytes));
|
|
25
|
+
assertLimit("maxStringBytes", ByteSize.toNumberUnsafe(limits.maxStringBytes));
|
|
26
|
+
assertLimit("maxArrayElements", limits.maxArrayElements);
|
|
27
|
+
this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
28
|
+
}
|
|
29
|
+
get remaining() {
|
|
30
|
+
return this.bytes.length - this.#offset;
|
|
31
|
+
}
|
|
32
|
+
#require(length) {
|
|
33
|
+
if (length > this.remaining)
|
|
34
|
+
throw new XdrDecodeError("Truncated XDR value");
|
|
35
|
+
}
|
|
36
|
+
uint32() {
|
|
37
|
+
this.#require(4);
|
|
38
|
+
const value = this.#view.getUint32(this.#offset);
|
|
39
|
+
this.#offset += 4;
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
int32() {
|
|
43
|
+
this.#require(4);
|
|
44
|
+
const value = this.#view.getInt32(this.#offset);
|
|
45
|
+
this.#offset += 4;
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
uint64() {
|
|
49
|
+
this.#require(8);
|
|
50
|
+
const value = this.#view.getBigUint64(this.#offset);
|
|
51
|
+
this.#offset += 8;
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
boolean() {
|
|
55
|
+
const value = this.uint32();
|
|
56
|
+
if (value > 1)
|
|
57
|
+
throw new XdrDecodeError(`Invalid XDR boolean: ${value}`);
|
|
58
|
+
return value === 1;
|
|
59
|
+
}
|
|
60
|
+
fixedOpaque(length) {
|
|
61
|
+
assertLimit("fixed opaque length", length);
|
|
62
|
+
const pad = padding(length);
|
|
63
|
+
this.#require(length + pad);
|
|
64
|
+
const value = this.bytes.slice(this.#offset, this.#offset + length);
|
|
65
|
+
this.#offset += length;
|
|
66
|
+
for (let index = 0; index < pad; index++) {
|
|
67
|
+
if (this.bytes[this.#offset + index] !== 0)
|
|
68
|
+
throw new XdrDecodeError("XDR padding must be zero");
|
|
69
|
+
}
|
|
70
|
+
this.#offset += pad;
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
opaque(maxBytes = this.limits.maxOpaqueBytes) {
|
|
74
|
+
assertLimit("opaque limit", ByteSize.toNumberUnsafe(maxBytes));
|
|
75
|
+
const length = this.uint32();
|
|
76
|
+
if (BigInt(length) > maxBytes || BigInt(length) > this.limits.maxOpaqueBytes) {
|
|
77
|
+
throw new XdrDecodeError("XDR opaque value exceeds its limit");
|
|
78
|
+
}
|
|
79
|
+
return this.fixedOpaque(length);
|
|
80
|
+
}
|
|
81
|
+
string(maxBytes = this.limits.maxStringBytes) {
|
|
82
|
+
assertLimit("string limit", ByteSize.toNumberUnsafe(maxBytes));
|
|
83
|
+
const bytes = this.opaque(ByteSize.min(maxBytes, this.limits.maxStringBytes));
|
|
84
|
+
try {
|
|
85
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw new XdrDecodeError("Invalid UTF-8 in XDR string");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
array(decode, maxElements = this.limits.maxArrayElements) {
|
|
92
|
+
assertLimit("array limit", maxElements);
|
|
93
|
+
const length = this.uint32();
|
|
94
|
+
if (length > maxElements || length > this.limits.maxArrayElements) {
|
|
95
|
+
throw new XdrDecodeError("XDR array exceeds its element limit");
|
|
96
|
+
}
|
|
97
|
+
const values = Array.from({ length });
|
|
98
|
+
for (let index = 0; index < length; index++)
|
|
99
|
+
values[index] = decode(this);
|
|
100
|
+
return values;
|
|
101
|
+
}
|
|
102
|
+
discriminant(cases) {
|
|
103
|
+
const value = this.uint32();
|
|
104
|
+
if (!Object.prototype.hasOwnProperty.call(cases, value)) {
|
|
105
|
+
throw new XdrDecodeError(`Invalid XDR discriminant: ${value}`);
|
|
106
|
+
}
|
|
107
|
+
// SAFETY: The own-property check proves that value indexes the supplied discriminant table.
|
|
108
|
+
return cases[value];
|
|
109
|
+
}
|
|
110
|
+
finish() {
|
|
111
|
+
if (this.remaining !== 0)
|
|
112
|
+
throw new XdrDecodeError("Trailing bytes after XDR message");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** @internal */
|
|
116
|
+
export class Writer {
|
|
117
|
+
#chunks = [];
|
|
118
|
+
#length = 0;
|
|
119
|
+
get length() {
|
|
120
|
+
return this.#length;
|
|
121
|
+
}
|
|
122
|
+
#append(bytes) {
|
|
123
|
+
this.#chunks.push(bytes);
|
|
124
|
+
this.#length += bytes.length;
|
|
125
|
+
}
|
|
126
|
+
uint32(value) {
|
|
127
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xffff_ffff)
|
|
128
|
+
throw new RangeError("uint32 out of range");
|
|
129
|
+
const bytes = new Uint8Array(4);
|
|
130
|
+
new DataView(bytes.buffer).setUint32(0, value);
|
|
131
|
+
this.#append(bytes);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
int32(value) {
|
|
135
|
+
if (!Number.isInteger(value) || value < -0x8000_0000 || value > 0x7fff_ffff) {
|
|
136
|
+
throw new RangeError("int32 out of range");
|
|
137
|
+
}
|
|
138
|
+
return this.uint32(value >>> 0);
|
|
139
|
+
}
|
|
140
|
+
uint64(value) {
|
|
141
|
+
if (value < 0n || value > 0xffffffffffffffffn)
|
|
142
|
+
throw new RangeError("uint64 out of range");
|
|
143
|
+
return this.uint32(Number(value >> 32n)).uint32(Number(value & 0xffffffffn));
|
|
144
|
+
}
|
|
145
|
+
boolean(value) {
|
|
146
|
+
return this.uint32(value ? 1 : 0);
|
|
147
|
+
}
|
|
148
|
+
fixedOpaque(value) {
|
|
149
|
+
this.#append(new Uint8Array(value));
|
|
150
|
+
const pad = padding(value.length);
|
|
151
|
+
if (pad > 0)
|
|
152
|
+
this.#append(new Uint8Array(pad));
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
opaque(value) {
|
|
156
|
+
return this.uint32(value.length).fixedOpaque(value);
|
|
157
|
+
}
|
|
158
|
+
string(value) {
|
|
159
|
+
return this.opaque(new TextEncoder().encode(value));
|
|
160
|
+
}
|
|
161
|
+
array(values, encode) {
|
|
162
|
+
this.uint32(values.length);
|
|
163
|
+
for (const value of values)
|
|
164
|
+
encode(this, value);
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
bytes() {
|
|
168
|
+
const bytes = new Uint8Array(this.#length);
|
|
169
|
+
let offset = 0;
|
|
170
|
+
for (const chunk of this.#chunks) {
|
|
171
|
+
bytes.set(chunk, offset);
|
|
172
|
+
offset += chunk.length;
|
|
173
|
+
}
|
|
174
|
+
return bytes;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
import * as ByteSize from "effect/ByteSize";
|
|
178
|
+
import * as Data from "effect/Data";
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effect-vfs/nfs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Read-only NFSv4.1 server for one live Effect VFS volume.",
|
|
5
|
+
"homepage": "https://github.com/lloydrichards/effect-virtual-fs#readme",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/lloydrichards/effect-virtual-fs.git",
|
|
10
|
+
"directory": "packages/nfs"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./NfsServer": {
|
|
23
|
+
"types": "./dist/NfsServer.d.ts",
|
|
24
|
+
"import": "./dist/NfsServer.js"
|
|
25
|
+
},
|
|
26
|
+
"./internal/*": null,
|
|
27
|
+
"./index": null,
|
|
28
|
+
"./*/index": null,
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": ["dist/**", "README.md", "LICENSE"],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc --project tsconfig.build.json",
|
|
37
|
+
"clean": "git clean -xdf .cache .turbo dist docs node_modules tsconfig.tsbuildinfo",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"type-check": "tsc --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"effect": "4.0.0-rc.114"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@effect-vfs/core": "0.3.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@effect/platform-node-shared": "4.0.0-rc.114",
|
|
49
|
+
"@effect/vitest": "4.0.0-rc.114",
|
|
50
|
+
"@repo/config-typescript": "0.0.0",
|
|
51
|
+
"effect": "4.0.0-rc.114",
|
|
52
|
+
"vitest": "^5.0.1"
|
|
53
|
+
}
|
|
54
|
+
}
|