gingersnap 0.22.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/_virtual/_tslib.cjs +102 -0
- package/_virtual/_tslib.mjs +93 -0
- package/data/AtomicValue.d.ts +15 -0
- package/data/bus.cjs +179 -0
- package/data/bus.d.ts +72 -0
- package/data/bus.mjs +177 -0
- package/data/decoders/index.d.ts +4 -0
- package/data/decoders/json.cjs +12 -0
- package/data/decoders/json.d.ts +7 -0
- package/data/decoders/json.mjs +10 -0
- package/data/decoders/msgpack.cjs +14 -0
- package/data/decoders/msgpack.d.ts +7 -0
- package/data/decoders/msgpack.mjs +12 -0
- package/data/decoders/protobuf.d.ts +13 -0
- package/data/decoders/string.cjs +12 -0
- package/data/decoders/string.d.ts +7 -0
- package/data/decoders/string.mjs +10 -0
- package/data/decoders/type.d.ts +7 -0
- package/data/decoders.cjs +11 -0
- package/data/decoders.mjs +3 -0
- package/data/model/credentials.cjs +114 -0
- package/data/model/credentials.d.ts +61 -0
- package/data/model/credentials.mjs +109 -0
- package/data/model/extra.cjs +88 -0
- package/data/model/extra.d.ts +5 -0
- package/data/model/extra.mjs +66 -0
- package/data/model/index.d.ts +6 -0
- package/data/model/model.cjs +541 -0
- package/data/model/model.d.ts +207 -0
- package/data/model/model.mjs +518 -0
- package/data/model/plugin.cjs +96 -0
- package/data/model/plugin.d.ts +38 -0
- package/data/model/plugin.mjs +72 -0
- package/data/model/property.cjs +310 -0
- package/data/model/property.d.ts +83 -0
- package/data/model/property.mjs +278 -0
- package/data/model/types.cjs +32 -0
- package/data/model/types.d.ts +28 -0
- package/data/model/types.mjs +32 -0
- package/data/model.cjs +43 -0
- package/data/model.mjs +6 -0
- package/data/signal.cjs +47 -0
- package/data/signal.d.ts +17 -0
- package/data/signal.mjs +45 -0
- package/data/store/index.d.ts +4 -0
- package/data/store/json.cjs +58 -0
- package/data/store/json.d.ts +18 -0
- package/data/store/json.mjs +56 -0
- package/data/store/manager.cjs +206 -0
- package/data/store/manager.d.ts +44 -0
- package/data/store/manager.mjs +203 -0
- package/data/store/web.cjs +92 -0
- package/data/store/web.d.ts +25 -0
- package/data/store/web.mjs +89 -0
- package/data/value.cjs +66 -0
- package/data/value.mjs +64 -0
- package/data-structures/array/CyclicalList.cjs +57 -0
- package/data-structures/array/CyclicalList.d.ts +12 -0
- package/data-structures/array/CyclicalList.mjs +55 -0
- package/data-structures/array/Pair.cjs +30 -0
- package/data-structures/array/Pair.d.ts +17 -0
- package/data-structures/array/Pair.mjs +27 -0
- package/data-structures/array/Stack.cjs +96 -0
- package/data-structures/array/Stack.d.ts +41 -0
- package/data-structures/array/Stack.mjs +94 -0
- package/data-structures/array/Triple.cjs +34 -0
- package/data-structures/array/Triple.d.ts +19 -0
- package/data-structures/array/Triple.mjs +31 -0
- package/data-structures/array/Tuple.d.ts +8 -0
- package/data-structures/array/index.d.ts +5 -0
- package/data-structures/array.cjs +15 -0
- package/data-structures/array.mjs +4 -0
- package/data-structures/object/BufferQueue.cjs +98 -0
- package/data-structures/object/BufferQueue.d.ts +21 -0
- package/data-structures/object/BufferQueue.mjs +77 -0
- package/data-structures/object/CyclicalObject.cjs +155 -0
- package/data-structures/object/CyclicalObject.d.ts +74 -0
- package/data-structures/object/CyclicalObject.mjs +134 -0
- package/data-structures/object/Queue.cjs +178 -0
- package/data-structures/object/Queue.d.ts +31 -0
- package/data-structures/object/Queue.mjs +176 -0
- package/data-structures/object/SimpleQueue.cjs +53 -0
- package/data-structures/object/SimpleQueue.d.ts +13 -0
- package/data-structures/object/SimpleQueue.mjs +51 -0
- package/data-structures/object/TimeableObject.cjs +73 -0
- package/data-structures/object/TimeableObject.d.ts +30 -0
- package/data-structures/object/TimeableObject.mjs +71 -0
- package/data-structures/object/WaitableObject.cjs +61 -0
- package/data-structures/object/WaitableObject.d.ts +29 -0
- package/data-structures/object/WaitableObject.mjs +59 -0
- package/data-structures/object/WatchableObject.cjs +251 -0
- package/data-structures/object/WatchableObject.d.ts +88 -0
- package/data-structures/object/WatchableObject.mjs +230 -0
- package/data-structures/object/index.d.ts +7 -0
- package/data-structures/object.cjs +23 -0
- package/data-structures/object.mjs +7 -0
- package/errors/AbortError.cjs +9 -0
- package/errors/AbortError.d.ts +5 -0
- package/errors/AbortError.mjs +7 -0
- package/errors/CallExecutionError.cjs +13 -0
- package/errors/CallExecutionError.d.ts +7 -0
- package/errors/CallExecutionError.mjs +11 -0
- package/errors/FutureCancelled.cjs +11 -0
- package/errors/FutureCancelled.d.ts +6 -0
- package/errors/FutureCancelled.mjs +9 -0
- package/errors/FutureError.cjs +11 -0
- package/errors/FutureError.d.ts +6 -0
- package/errors/FutureError.mjs +9 -0
- package/errors/IllegalArgumentsError.cjs +13 -0
- package/errors/IllegalArgumentsError.d.ts +7 -0
- package/errors/IllegalArgumentsError.mjs +11 -0
- package/errors/IllegalOperationError.cjs +6 -0
- package/errors/IllegalOperationError.d.ts +2 -0
- package/errors/IllegalOperationError.mjs +4 -0
- package/errors/InvalidType.cjs +6 -0
- package/errors/InvalidType.d.ts +2 -0
- package/errors/InvalidType.mjs +4 -0
- package/errors/InvalidValue.cjs +11 -0
- package/errors/InvalidValue.d.ts +4 -0
- package/errors/InvalidValue.mjs +9 -0
- package/errors/MissingArgumentsError.cjs +13 -0
- package/errors/MissingArgumentsError.d.ts +7 -0
- package/errors/MissingArgumentsError.mjs +11 -0
- package/errors/NetworkError.cjs +13 -0
- package/errors/NetworkError.d.ts +8 -0
- package/errors/NetworkError.mjs +11 -0
- package/errors/NoSuchElement.cjs +6 -0
- package/errors/NoSuchElement.d.ts +2 -0
- package/errors/NoSuchElement.mjs +4 -0
- package/errors/NotImplemented.cjs +9 -0
- package/errors/NotImplemented.d.ts +5 -0
- package/errors/NotImplemented.mjs +7 -0
- package/errors/ParsingError.cjs +10 -0
- package/errors/ParsingError.d.ts +5 -0
- package/errors/ParsingError.mjs +8 -0
- package/errors/QueueEmptyError.cjs +6 -0
- package/errors/QueueEmptyError.d.ts +2 -0
- package/errors/QueueEmptyError.mjs +4 -0
- package/errors/QueueFullError.cjs +6 -0
- package/errors/QueueFullError.d.ts +2 -0
- package/errors/QueueFullError.mjs +4 -0
- package/errors/StackEmptyError.cjs +6 -0
- package/errors/StackEmptyError.d.ts +2 -0
- package/errors/StackEmptyError.mjs +4 -0
- package/errors/StackFullError.cjs +6 -0
- package/errors/StackFullError.d.ts +2 -0
- package/errors/StackFullError.mjs +4 -0
- package/errors/StreamEnded.cjs +6 -0
- package/errors/StreamEnded.d.ts +2 -0
- package/errors/StreamEnded.mjs +4 -0
- package/errors/TimeoutError.cjs +11 -0
- package/errors/TimeoutError.d.ts +6 -0
- package/errors/TimeoutError.mjs +9 -0
- package/errors/ValueDestroyedError.cjs +6 -0
- package/errors/ValueDestroyedError.d.ts +2 -0
- package/errors/ValueDestroyedError.mjs +4 -0
- package/errors/VerificationError.cjs +9 -0
- package/errors/VerificationError.d.ts +5 -0
- package/errors/VerificationError.mjs +7 -0
- package/errors/index.d.ts +18 -0
- package/errors.cjs +41 -0
- package/errors.mjs +18 -0
- package/files.cjs +201 -0
- package/files.d.ts +31 -0
- package/files.mjs +180 -0
- package/functools/index.d.ts +31 -0
- package/functools.cjs +371 -0
- package/functools.mjs +334 -0
- package/future/future.cjs +570 -0
- package/future/future.d.ts +208 -0
- package/future/future.mjs +548 -0
- package/future/group.cjs +180 -0
- package/future/group.d.ts +82 -0
- package/future/group.mjs +159 -0
- package/future/index.d.ts +3 -0
- package/future/result.cjs +19 -0
- package/future/result.d.ts +18 -0
- package/future/result.mjs +17 -0
- package/future.cjs +11 -0
- package/future.mjs +3 -0
- package/managers/context.d.ts +8 -0
- package/managers/index.d.ts +1 -0
- package/managers.cjs +2 -0
- package/managers.mjs +1 -0
- package/mocks.cjs +301 -0
- package/mocks.d.ts +125 -0
- package/mocks.mjs +293 -0
- package/networking/EventSourceService.cjs +104 -0
- package/networking/EventSourceService.d.ts +11 -0
- package/networking/EventSourceService.mjs +83 -0
- package/networking/NetworkService.cjs +394 -0
- package/networking/NetworkService.d.ts +97 -0
- package/networking/NetworkService.mjs +373 -0
- package/networking/SocketService.cjs +218 -0
- package/networking/SocketService.d.ts +23 -0
- package/networking/SocketService.mjs +197 -0
- package/networking/decorators/index.d.ts +4 -0
- package/networking/decorators/options.cjs +289 -0
- package/networking/decorators/options.d.ts +148 -0
- package/networking/decorators/options.mjs +242 -0
- package/networking/decorators/requests.cjs +80 -0
- package/networking/decorators/requests.d.ts +34 -0
- package/networking/decorators/requests.mjs +52 -0
- package/networking/decorators/socket.cjs +81 -0
- package/networking/decorators/socket.d.ts +13 -0
- package/networking/decorators/socket.mjs +51 -0
- package/networking/http.cjs +69 -0
- package/networking/http.d.ts +66 -0
- package/networking/http.mjs +69 -0
- package/networking/index.d.ts +39 -0
- package/networking/request.cjs +18 -0
- package/networking/request.d.ts +9 -0
- package/networking/request.mjs +16 -0
- package/networking/types.cjs +37 -0
- package/networking/types.d.ts +132 -0
- package/networking/types.mjs +35 -0
- package/networking.cjs +91 -0
- package/networking.mjs +33 -0
- package/package.json +1 -0
- package/reflection/injector.cjs +43 -0
- package/reflection/injector.d.ts +3 -0
- package/reflection/injector.mjs +40 -0
- package/socket.cjs +239 -0
- package/socket.d.ts +65 -0
- package/socket.mjs +237 -0
- package/store.cjs +12 -0
- package/store.mjs +3 -0
- package/stream/call.cjs +157 -0
- package/stream/call.d.ts +66 -0
- package/stream/call.mjs +154 -0
- package/stream/collector.cjs +217 -0
- package/stream/collector.d.ts +14 -0
- package/stream/collector.mjs +215 -0
- package/stream/index.d.ts +257 -0
- package/stream/observable.cjs +110 -0
- package/stream/observable.d.ts +65 -0
- package/stream/observable.mjs +106 -0
- package/stream/state.cjs +10 -0
- package/stream/state.d.ts +5 -0
- package/stream/state.mjs +8 -0
- package/stream.cjs +1153 -0
- package/stream.mjs +1132 -0
- package/synchronize.cjs +106 -0
- package/synchronize.d.ts +54 -0
- package/synchronize.mjs +103 -0
- package/typing/types.d.ts +24 -0
- package/typing.cjs +2 -0
- package/typing.mjs +1 -0
- package/utils/parser.cjs +37 -0
- package/utils/parser.d.ts +7 -0
- package/utils/parser.mjs +16 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var FutureCancelled = require('./FutureCancelled.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Thrown to indicate that some timed operation has exceeded the maximum duration
|
|
7
|
+
*/
|
|
8
|
+
class TimeoutError extends FutureCancelled.FutureCancelled {
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.TimeoutError = TimeoutError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from "./AbortError";
|
|
2
|
+
export * from "./CallExecutionError";
|
|
3
|
+
export * from "./FutureCancelled";
|
|
4
|
+
export * from "./FutureError";
|
|
5
|
+
export * from "./IllegalArgumentsError";
|
|
6
|
+
export * from "./InvalidType";
|
|
7
|
+
export * from "./InvalidValue";
|
|
8
|
+
export * from "./MissingArgumentsError";
|
|
9
|
+
export * from "./NetworkError";
|
|
10
|
+
export * from "./NoSuchElement";
|
|
11
|
+
export * from "./NotImplemented";
|
|
12
|
+
export * from "./ParsingError";
|
|
13
|
+
export * from "./QueueEmptyError";
|
|
14
|
+
export * from "./StackEmptyError";
|
|
15
|
+
export * from "./StreamEnded";
|
|
16
|
+
export * from "./TimeoutError";
|
|
17
|
+
export * from "./VerificationError";
|
|
18
|
+
export * from "./StackFullError";
|
package/errors.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AbortError = require('./errors/AbortError.cjs');
|
|
4
|
+
var CallExecutionError = require('./errors/CallExecutionError.cjs');
|
|
5
|
+
var FutureCancelled = require('./errors/FutureCancelled.cjs');
|
|
6
|
+
var FutureError = require('./errors/FutureError.cjs');
|
|
7
|
+
var IllegalArgumentsError = require('./errors/IllegalArgumentsError.cjs');
|
|
8
|
+
var InvalidType = require('./errors/InvalidType.cjs');
|
|
9
|
+
var InvalidValue = require('./errors/InvalidValue.cjs');
|
|
10
|
+
var MissingArgumentsError = require('./errors/MissingArgumentsError.cjs');
|
|
11
|
+
var NetworkError = require('./errors/NetworkError.cjs');
|
|
12
|
+
var NoSuchElement = require('./errors/NoSuchElement.cjs');
|
|
13
|
+
var NotImplemented = require('./errors/NotImplemented.cjs');
|
|
14
|
+
var ParsingError = require('./errors/ParsingError.cjs');
|
|
15
|
+
var QueueEmptyError = require('./errors/QueueEmptyError.cjs');
|
|
16
|
+
var StackEmptyError = require('./errors/StackEmptyError.cjs');
|
|
17
|
+
var StreamEnded = require('./errors/StreamEnded.cjs');
|
|
18
|
+
var TimeoutError = require('./errors/TimeoutError.cjs');
|
|
19
|
+
var VerificationError = require('./errors/VerificationError.cjs');
|
|
20
|
+
var StackFullError = require('./errors/StackFullError.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.AbortError = AbortError.AbortError;
|
|
25
|
+
exports.CallExecutionError = CallExecutionError.CallExecutionError;
|
|
26
|
+
exports.FutureCancelled = FutureCancelled.FutureCancelled;
|
|
27
|
+
exports.FutureError = FutureError.FutureError;
|
|
28
|
+
exports.IllegalArgumentsError = IllegalArgumentsError.IllegalArgumentsError;
|
|
29
|
+
exports.InvalidType = InvalidType.InvalidType;
|
|
30
|
+
exports.InvalidValue = InvalidValue.InvalidValue;
|
|
31
|
+
exports.MissingArgumentsError = MissingArgumentsError.MissingArgumentsError;
|
|
32
|
+
exports.NetworkError = NetworkError.NetworkError;
|
|
33
|
+
exports.NoSuchElement = NoSuchElement.NoSuchElement;
|
|
34
|
+
exports.NotImplemented = NotImplemented.NotImplemented;
|
|
35
|
+
exports.ParsingError = ParsingError.ParsingError;
|
|
36
|
+
exports.QueueEmptyError = QueueEmptyError.QueueEmptyError;
|
|
37
|
+
exports.StackEmptyError = StackEmptyError.StackEmptyError;
|
|
38
|
+
exports.StreamEnded = StreamEnded.StreamEnded;
|
|
39
|
+
exports.TimeoutError = TimeoutError.TimeoutError;
|
|
40
|
+
exports.VerificationError = VerificationError.VerificationError;
|
|
41
|
+
exports.StackFullError = StackFullError.StackFullError;
|
package/errors.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { AbortError } from './errors/AbortError.mjs';
|
|
2
|
+
export { CallExecutionError } from './errors/CallExecutionError.mjs';
|
|
3
|
+
export { FutureCancelled } from './errors/FutureCancelled.mjs';
|
|
4
|
+
export { FutureError } from './errors/FutureError.mjs';
|
|
5
|
+
export { IllegalArgumentsError } from './errors/IllegalArgumentsError.mjs';
|
|
6
|
+
export { InvalidType } from './errors/InvalidType.mjs';
|
|
7
|
+
export { InvalidValue } from './errors/InvalidValue.mjs';
|
|
8
|
+
export { MissingArgumentsError } from './errors/MissingArgumentsError.mjs';
|
|
9
|
+
export { NetworkError } from './errors/NetworkError.mjs';
|
|
10
|
+
export { NoSuchElement } from './errors/NoSuchElement.mjs';
|
|
11
|
+
export { NotImplemented } from './errors/NotImplemented.mjs';
|
|
12
|
+
export { ParsingError } from './errors/ParsingError.mjs';
|
|
13
|
+
export { QueueEmptyError } from './errors/QueueEmptyError.mjs';
|
|
14
|
+
export { StackEmptyError } from './errors/StackEmptyError.mjs';
|
|
15
|
+
export { StreamEnded } from './errors/StreamEnded.mjs';
|
|
16
|
+
export { TimeoutError } from './errors/TimeoutError.mjs';
|
|
17
|
+
export { VerificationError } from './errors/VerificationError.mjs';
|
|
18
|
+
export { StackFullError } from './errors/StackFullError.mjs';
|
package/files.cjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _tslib = require('./_virtual/_tslib.cjs');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var readline = require('readline');
|
|
6
|
+
var stream = require('./stream.cjs');
|
|
7
|
+
var future = require('./future/future.cjs');
|
|
8
|
+
var R = require('ramda');
|
|
9
|
+
var path = require('path');
|
|
10
|
+
require('./data-structures/object/WatchableObject.cjs');
|
|
11
|
+
require('object-hash');
|
|
12
|
+
require('uuid');
|
|
13
|
+
var Queue = require('./data-structures/object/Queue.cjs');
|
|
14
|
+
|
|
15
|
+
function _interopNamespaceDefault(e) {
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
|
|
33
|
+
|
|
34
|
+
class Files {
|
|
35
|
+
static watch(source, { objectMaxSize, expiryPeriod }) {
|
|
36
|
+
return Files.watchData(source, { objectMaxSize, expiryPeriod, encoding: "utf-8" });
|
|
37
|
+
}
|
|
38
|
+
static watchBinary(source, { objectMaxSize, expiryPeriod }) {
|
|
39
|
+
return Files.watchData(source, { objectMaxSize, expiryPeriod, encoding: "binary" });
|
|
40
|
+
}
|
|
41
|
+
static removeDirectories(source) {
|
|
42
|
+
return future.Future.of((resolve, reject) => {
|
|
43
|
+
fs.rm(source, { recursive: true, force: true }, (error) => (error ? reject(error) : resolve()));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static remove(source) {
|
|
47
|
+
return future.Future.of((resolve, reject) => {
|
|
48
|
+
fs.rm(source, (error) => (error ? reject(error) : resolve()));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static createDirectories(path) {
|
|
52
|
+
return future.Future.of((resolve, reject) => {
|
|
53
|
+
fs.mkdir(path, { recursive: true }, (error) => (error ? reject(error) : resolve()));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
static list(path) {
|
|
57
|
+
return future.Future.of((resolve, reject, signal) => {
|
|
58
|
+
fs.readdir(path, { withFileTypes: true }, (error, files) => (error ? reject(error) : resolve(files)));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
static move(source, dest, concurrencyLimit = 10) {
|
|
62
|
+
return Files.stat(source).thenApply(({ value }) => {
|
|
63
|
+
if (value.isFile()) {
|
|
64
|
+
return future.Future.of((resolve, reject) => fs.rename(source, dest, (error) => (error ? reject(error) : resolve())));
|
|
65
|
+
}
|
|
66
|
+
return Files.list(source)
|
|
67
|
+
.stream.flatten()
|
|
68
|
+
.parallel(concurrencyLimit)
|
|
69
|
+
.map((stat) => {
|
|
70
|
+
const oldPath = path.join(source, stat.name);
|
|
71
|
+
const newPath = path.join(dest, stat.name);
|
|
72
|
+
if (stat.isDirectory()) {
|
|
73
|
+
return Files.move(oldPath, dest);
|
|
74
|
+
}
|
|
75
|
+
else if (stat.isFile()) {
|
|
76
|
+
return future.Future.of((resolve, reject) => fs.rename(oldPath, newPath, (error) => (error ? reject(error) : resolve(null))));
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
})
|
|
80
|
+
.consume();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
static stat(source) {
|
|
84
|
+
return future.Future.of((resolve, reject, signal) => {
|
|
85
|
+
fs.stat(source, (error, stat) => (error ? reject(error) : resolve(stat)));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static lines(source, encoding = "utf-8") {
|
|
89
|
+
let shutdownHook = () => { };
|
|
90
|
+
return stream.Stream.seed(() => {
|
|
91
|
+
const fileStream = fs.createReadStream(source, encoding);
|
|
92
|
+
const reader = readline__namespace.createInterface({
|
|
93
|
+
input: fileStream,
|
|
94
|
+
crlfDelay: Infinity,
|
|
95
|
+
});
|
|
96
|
+
shutdownHook = () => {
|
|
97
|
+
reader.close();
|
|
98
|
+
fileStream.close();
|
|
99
|
+
};
|
|
100
|
+
return stream.Stream.of(reader[Symbol.asyncIterator]());
|
|
101
|
+
}).onCompletion(() => shutdownHook());
|
|
102
|
+
}
|
|
103
|
+
static readNBytes(source, bufferSize) {
|
|
104
|
+
return Files.read(source, bufferSize).execute();
|
|
105
|
+
}
|
|
106
|
+
static read(source, bufferSize = 100) {
|
|
107
|
+
let shutdownHook = () => { };
|
|
108
|
+
return stream.Stream.seed(() => {
|
|
109
|
+
return future.Future.of((resolve, reject) => {
|
|
110
|
+
fs.open(source, "rb", function (error, fd) {
|
|
111
|
+
shutdownHook = () => fs.close(fd);
|
|
112
|
+
if (error) {
|
|
113
|
+
return reject(error);
|
|
114
|
+
}
|
|
115
|
+
resolve(fd);
|
|
116
|
+
});
|
|
117
|
+
}).stream.map((fd) => future.Future.of((resolve, reject, signal) => {
|
|
118
|
+
const buffer = Buffer.alloc(bufferSize);
|
|
119
|
+
fs.read(fd, buffer, 0, bufferSize, 0, function (error, num) {
|
|
120
|
+
if (signal.aborted) {
|
|
121
|
+
fs.close(fd, (err) => (err ? reject(err) : null));
|
|
122
|
+
shutdownHook = () => { };
|
|
123
|
+
}
|
|
124
|
+
else if (error) {
|
|
125
|
+
reject(error);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
resolve(buffer);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}));
|
|
132
|
+
}).onCompletion(() => shutdownHook());
|
|
133
|
+
}
|
|
134
|
+
static readString(source) {
|
|
135
|
+
return Files.readAll(source, "utf-8");
|
|
136
|
+
}
|
|
137
|
+
static readAll(source, encoding = null) {
|
|
138
|
+
return future.Future.of((resolve, reject, signal) => {
|
|
139
|
+
fs.readFile(source, { encoding, signal }, (error, data) => {
|
|
140
|
+
if (error) {
|
|
141
|
+
reject(error);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
resolve(data);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
static write(data, source, encoding = "utf-8") {
|
|
150
|
+
if (data instanceof stream.Stream) {
|
|
151
|
+
return Files.writeFromStream(data, source, encoding);
|
|
152
|
+
}
|
|
153
|
+
return future.Future.of((resolve, reject, signal) => {
|
|
154
|
+
fs.writeFile(source, data, { encoding, signal }, (error) => {
|
|
155
|
+
if (error) {
|
|
156
|
+
reject(error);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
resolve();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
static writeFromStream(stream, source, encoding = "utf-8") {
|
|
165
|
+
return future.Future.of((resolve, reject, signal) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const fileStream = fs.createWriteStream(source, encoding);
|
|
167
|
+
yield stream
|
|
168
|
+
.map((v) => future.Future.of((resolve, reject) => {
|
|
169
|
+
if (!fileStream.write(v, (error) => {
|
|
170
|
+
if (error) {
|
|
171
|
+
fileStream.close();
|
|
172
|
+
reject(error);
|
|
173
|
+
}
|
|
174
|
+
})) {
|
|
175
|
+
fileStream.once("drain", resolve);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
resolve(null);
|
|
179
|
+
}
|
|
180
|
+
}))
|
|
181
|
+
.onCompletion(() => {
|
|
182
|
+
fileStream.close();
|
|
183
|
+
})
|
|
184
|
+
.cancelOnSignal(signal)
|
|
185
|
+
.consume();
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
static watchData(source, { objectMaxSize, expiryPeriod, encoding }) {
|
|
189
|
+
const getQueue = R.once((signal) => {
|
|
190
|
+
const queue = new Queue.Queue(objectMaxSize, expiryPeriod);
|
|
191
|
+
fs.watch(source, { recursive: true, persistent: true, signal, encoding }, (v) => queue.enqueue(v));
|
|
192
|
+
return queue;
|
|
193
|
+
});
|
|
194
|
+
return new stream.Stream((signal) => {
|
|
195
|
+
const queue = getQueue(signal);
|
|
196
|
+
return queue.awaitDequeue(signal);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
exports.Files = Files;
|
package/files.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import fs, { PathLike } from "fs";
|
|
5
|
+
import { Stream } from "./stream";
|
|
6
|
+
import { Future, WaitPeriod } from "./future";
|
|
7
|
+
import { BufferEncoding } from "object-hash";
|
|
8
|
+
interface FileWatchOptions {
|
|
9
|
+
encoding: BufferEncoding;
|
|
10
|
+
objectMaxSize?: number;
|
|
11
|
+
expiryPeriod?: WaitPeriod;
|
|
12
|
+
}
|
|
13
|
+
export declare class Files {
|
|
14
|
+
static watch(source: PathLike, { objectMaxSize, expiryPeriod }: Omit<FileWatchOptions, "encoding">): Stream<string>;
|
|
15
|
+
static watchBinary(source: PathLike, { objectMaxSize, expiryPeriod }: Omit<FileWatchOptions, "encoding">): Stream<Buffer>;
|
|
16
|
+
static removeDirectories(source: PathLike): Future<void>;
|
|
17
|
+
static remove(source: PathLike): Future<void>;
|
|
18
|
+
static createDirectories(path: PathLike): Future<void>;
|
|
19
|
+
static list(path: PathLike): Future<fs.Dirent[]>;
|
|
20
|
+
static move(source: string, dest: string, concurrencyLimit?: number): Future<void>;
|
|
21
|
+
static stat(source: PathLike): Future<fs.Stats>;
|
|
22
|
+
static lines(source: PathLike, encoding?: BufferEncoding): Stream<string>;
|
|
23
|
+
static readNBytes(source: PathLike, bufferSize: number): Future<Buffer>;
|
|
24
|
+
static read(source: PathLike, bufferSize?: number): Stream<Buffer>;
|
|
25
|
+
static readString(source: PathLike): Future<string>;
|
|
26
|
+
static readAll(source: PathLike, encoding?: BufferEncoding | null): Future<string | Buffer>;
|
|
27
|
+
static write(data: string | NodeJS.ArrayBufferView | Stream<string | NodeJS.ArrayBufferView>, source: PathLike, encoding?: BufferEncoding): Future<void>;
|
|
28
|
+
private static writeFromStream;
|
|
29
|
+
private static watchData;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/files.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { __awaiter } from './_virtual/_tslib.mjs';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import * as readline from 'readline';
|
|
4
|
+
import { Stream } from './stream.mjs';
|
|
5
|
+
import { Future } from './future/future.mjs';
|
|
6
|
+
import R__default from 'ramda';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import './data-structures/object/WatchableObject.mjs';
|
|
9
|
+
import 'object-hash';
|
|
10
|
+
import 'uuid';
|
|
11
|
+
import { Queue } from './data-structures/object/Queue.mjs';
|
|
12
|
+
|
|
13
|
+
class Files {
|
|
14
|
+
static watch(source, { objectMaxSize, expiryPeriod }) {
|
|
15
|
+
return Files.watchData(source, { objectMaxSize, expiryPeriod, encoding: "utf-8" });
|
|
16
|
+
}
|
|
17
|
+
static watchBinary(source, { objectMaxSize, expiryPeriod }) {
|
|
18
|
+
return Files.watchData(source, { objectMaxSize, expiryPeriod, encoding: "binary" });
|
|
19
|
+
}
|
|
20
|
+
static removeDirectories(source) {
|
|
21
|
+
return Future.of((resolve, reject) => {
|
|
22
|
+
fs.rm(source, { recursive: true, force: true }, (error) => (error ? reject(error) : resolve()));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static remove(source) {
|
|
26
|
+
return Future.of((resolve, reject) => {
|
|
27
|
+
fs.rm(source, (error) => (error ? reject(error) : resolve()));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static createDirectories(path) {
|
|
31
|
+
return Future.of((resolve, reject) => {
|
|
32
|
+
fs.mkdir(path, { recursive: true }, (error) => (error ? reject(error) : resolve()));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
static list(path) {
|
|
36
|
+
return Future.of((resolve, reject, signal) => {
|
|
37
|
+
fs.readdir(path, { withFileTypes: true }, (error, files) => (error ? reject(error) : resolve(files)));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
static move(source, dest, concurrencyLimit = 10) {
|
|
41
|
+
return Files.stat(source).thenApply(({ value }) => {
|
|
42
|
+
if (value.isFile()) {
|
|
43
|
+
return Future.of((resolve, reject) => fs.rename(source, dest, (error) => (error ? reject(error) : resolve())));
|
|
44
|
+
}
|
|
45
|
+
return Files.list(source)
|
|
46
|
+
.stream.flatten()
|
|
47
|
+
.parallel(concurrencyLimit)
|
|
48
|
+
.map((stat) => {
|
|
49
|
+
const oldPath = path.join(source, stat.name);
|
|
50
|
+
const newPath = path.join(dest, stat.name);
|
|
51
|
+
if (stat.isDirectory()) {
|
|
52
|
+
return Files.move(oldPath, dest);
|
|
53
|
+
}
|
|
54
|
+
else if (stat.isFile()) {
|
|
55
|
+
return Future.of((resolve, reject) => fs.rename(oldPath, newPath, (error) => (error ? reject(error) : resolve(null))));
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
})
|
|
59
|
+
.consume();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
static stat(source) {
|
|
63
|
+
return Future.of((resolve, reject, signal) => {
|
|
64
|
+
fs.stat(source, (error, stat) => (error ? reject(error) : resolve(stat)));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
static lines(source, encoding = "utf-8") {
|
|
68
|
+
let shutdownHook = () => { };
|
|
69
|
+
return Stream.seed(() => {
|
|
70
|
+
const fileStream = fs.createReadStream(source, encoding);
|
|
71
|
+
const reader = readline.createInterface({
|
|
72
|
+
input: fileStream,
|
|
73
|
+
crlfDelay: Infinity,
|
|
74
|
+
});
|
|
75
|
+
shutdownHook = () => {
|
|
76
|
+
reader.close();
|
|
77
|
+
fileStream.close();
|
|
78
|
+
};
|
|
79
|
+
return Stream.of(reader[Symbol.asyncIterator]());
|
|
80
|
+
}).onCompletion(() => shutdownHook());
|
|
81
|
+
}
|
|
82
|
+
static readNBytes(source, bufferSize) {
|
|
83
|
+
return Files.read(source, bufferSize).execute();
|
|
84
|
+
}
|
|
85
|
+
static read(source, bufferSize = 100) {
|
|
86
|
+
let shutdownHook = () => { };
|
|
87
|
+
return Stream.seed(() => {
|
|
88
|
+
return Future.of((resolve, reject) => {
|
|
89
|
+
fs.open(source, "rb", function (error, fd) {
|
|
90
|
+
shutdownHook = () => fs.close(fd);
|
|
91
|
+
if (error) {
|
|
92
|
+
return reject(error);
|
|
93
|
+
}
|
|
94
|
+
resolve(fd);
|
|
95
|
+
});
|
|
96
|
+
}).stream.map((fd) => Future.of((resolve, reject, signal) => {
|
|
97
|
+
const buffer = Buffer.alloc(bufferSize);
|
|
98
|
+
fs.read(fd, buffer, 0, bufferSize, 0, function (error, num) {
|
|
99
|
+
if (signal.aborted) {
|
|
100
|
+
fs.close(fd, (err) => (err ? reject(err) : null));
|
|
101
|
+
shutdownHook = () => { };
|
|
102
|
+
}
|
|
103
|
+
else if (error) {
|
|
104
|
+
reject(error);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolve(buffer);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}));
|
|
111
|
+
}).onCompletion(() => shutdownHook());
|
|
112
|
+
}
|
|
113
|
+
static readString(source) {
|
|
114
|
+
return Files.readAll(source, "utf-8");
|
|
115
|
+
}
|
|
116
|
+
static readAll(source, encoding = null) {
|
|
117
|
+
return Future.of((resolve, reject, signal) => {
|
|
118
|
+
fs.readFile(source, { encoding, signal }, (error, data) => {
|
|
119
|
+
if (error) {
|
|
120
|
+
reject(error);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
resolve(data);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
static write(data, source, encoding = "utf-8") {
|
|
129
|
+
if (data instanceof Stream) {
|
|
130
|
+
return Files.writeFromStream(data, source, encoding);
|
|
131
|
+
}
|
|
132
|
+
return Future.of((resolve, reject, signal) => {
|
|
133
|
+
fs.writeFile(source, data, { encoding, signal }, (error) => {
|
|
134
|
+
if (error) {
|
|
135
|
+
reject(error);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
resolve();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
static writeFromStream(stream, source, encoding = "utf-8") {
|
|
144
|
+
return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const fileStream = fs.createWriteStream(source, encoding);
|
|
146
|
+
yield stream
|
|
147
|
+
.map((v) => Future.of((resolve, reject) => {
|
|
148
|
+
if (!fileStream.write(v, (error) => {
|
|
149
|
+
if (error) {
|
|
150
|
+
fileStream.close();
|
|
151
|
+
reject(error);
|
|
152
|
+
}
|
|
153
|
+
})) {
|
|
154
|
+
fileStream.once("drain", resolve);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
resolve(null);
|
|
158
|
+
}
|
|
159
|
+
}))
|
|
160
|
+
.onCompletion(() => {
|
|
161
|
+
fileStream.close();
|
|
162
|
+
})
|
|
163
|
+
.cancelOnSignal(signal)
|
|
164
|
+
.consume();
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
static watchData(source, { objectMaxSize, expiryPeriod, encoding }) {
|
|
168
|
+
const getQueue = R__default.once((signal) => {
|
|
169
|
+
const queue = new Queue(objectMaxSize, expiryPeriod);
|
|
170
|
+
fs.watch(source, { recursive: true, persistent: true, signal, encoding }, (v) => queue.enqueue(v));
|
|
171
|
+
return queue;
|
|
172
|
+
});
|
|
173
|
+
return new Stream((signal) => {
|
|
174
|
+
const queue = getQueue(signal);
|
|
175
|
+
return queue.awaitDequeue(signal);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { Files };
|