@rsdk/common 4.0.0-next.12 → 4.0.0-next.14
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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/observable/index.d.ts +1 -0
- package/dist/observable/index.js +18 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/observable/observable-to-async-iterable.d.ts +7 -0
- package/dist/observable/observable-to-async-iterable.js +91 -0
- package/dist/observable/observable-to-async-iterable.js.map +1 -0
- package/dist/strings/get-random-bytes.d.ts +6 -0
- package/dist/strings/get-random-bytes.js +19 -0
- package/dist/strings/get-random-bytes.js.map +1 -0
- package/dist/strings/index.d.ts +1 -0
- package/dist/strings/index.js +1 -0
- package/dist/strings/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/observable/index.ts +1 -0
- package/src/observable/observable-to-async-iterable.ts +99 -0
- package/src/strings/get-random-bytes.ts +16 -0
- package/src/strings/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.0-next.14](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.13...v4.0.0-next.14) (2023-11-29)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **core:** PFM-601 Add support send trace id from client to server ([#164](https://github.com/R-Vision/rsdk/issues/164)) ([9e37243](https://github.com/R-Vision/rsdk/commit/9e372437fbb3d7d2b1167b99d07b0ac64cb4013d)), closes [#pfm-601](https://github.com/R-Vision/rsdk/issues/pfm-601) [#pfm-601](https://github.com/R-Vision/rsdk/issues/pfm-601)
|
|
11
|
+
|
|
12
|
+
## [4.0.0-next.13](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.12...v4.0.0-next.13) (2023-11-29)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/common
|
|
15
|
+
|
|
6
16
|
## [4.0.0-next.12](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.11...v4.0.0-next.12) (2023-11-29)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/common
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,4 +21,5 @@ __exportStar(require("./time"), exports);
|
|
|
21
21
|
__exportStar(require("./functions"), exports);
|
|
22
22
|
__exportStar(require("./size"), exports);
|
|
23
23
|
__exportStar(require("./strings"), exports);
|
|
24
|
+
__exportStar(require("./observable"), exports);
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,yCAAuB;AACvB,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,yCAAuB;AACvB,4CAA0B;AAC1B,+CAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './observable-to-async-iterable';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./observable-to-async-iterable"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observable/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
export type Callback = (value?: any) => any;
|
|
3
|
+
/**
|
|
4
|
+
* Утилита для создания асинк итератора из обзервабл
|
|
5
|
+
* поиском "observableToAsyncIterable" можно найти тесты в которых есть пример использования
|
|
6
|
+
*/
|
|
7
|
+
export declare function observableToAsyncIterable<T>(observable: Observable<T>): AsyncIterableIterator<T>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.observableToAsyncIterable = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Утилита для создания асинк итератора из обзервабл
|
|
7
|
+
* поиском "observableToAsyncIterable" можно найти тесты в которых есть пример использования
|
|
8
|
+
*/
|
|
9
|
+
function observableToAsyncIterable(observable) {
|
|
10
|
+
const pullQueue = [];
|
|
11
|
+
const pushQueue = [];
|
|
12
|
+
let listening = true;
|
|
13
|
+
const pushValue = (value) => {
|
|
14
|
+
if (pullQueue.length > 0) {
|
|
15
|
+
// It is safe to use the ! operator here as we check the length.
|
|
16
|
+
pullQueue.shift()({ value, done: false });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
pushQueue.push({ value, done: false });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const pushError = (error) => {
|
|
23
|
+
if (pullQueue.length > 0) {
|
|
24
|
+
// It is safe to use the ! operator here as we check the length.
|
|
25
|
+
pullQueue.shift()({ value: { errors: [error] }, done: false });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
pushQueue.push({ value: { errors: [error] }, done: false });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const pushDone = () => {
|
|
32
|
+
if (pullQueue.length > 0) {
|
|
33
|
+
// It is safe to use the ! operator here as we check the length.
|
|
34
|
+
pullQueue.shift()({ done: true });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
pushQueue.push({ done: true });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const pullValue = () => new Promise((resolve) => {
|
|
41
|
+
if (pushQueue.length > 0) {
|
|
42
|
+
const element = pushQueue.shift();
|
|
43
|
+
// either {value: {errors: [...]}} or {value: ...}
|
|
44
|
+
resolve(element);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
pullQueue.push(resolve);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const subscription = observable.subscribe({
|
|
51
|
+
next(value) {
|
|
52
|
+
pushValue(value);
|
|
53
|
+
},
|
|
54
|
+
error(err) {
|
|
55
|
+
pushError(err);
|
|
56
|
+
},
|
|
57
|
+
complete() {
|
|
58
|
+
pushDone();
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const emptyQueue = () => {
|
|
62
|
+
if (listening) {
|
|
63
|
+
listening = false;
|
|
64
|
+
subscription.unsubscribe();
|
|
65
|
+
for (const resolve of pullQueue) {
|
|
66
|
+
resolve({ value: undefined, done: true });
|
|
67
|
+
}
|
|
68
|
+
pullQueue.length = 0;
|
|
69
|
+
pushQueue.length = 0;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
next() {
|
|
74
|
+
// return is a defined method, so it is safe to call it.
|
|
75
|
+
return listening ? pullValue() : this.return();
|
|
76
|
+
},
|
|
77
|
+
return() {
|
|
78
|
+
emptyQueue();
|
|
79
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
80
|
+
},
|
|
81
|
+
throw(error) {
|
|
82
|
+
emptyQueue();
|
|
83
|
+
return Promise.reject(error);
|
|
84
|
+
},
|
|
85
|
+
[Symbol.asyncIterator]() {
|
|
86
|
+
return this;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.observableToAsyncIterable = observableToAsyncIterable;
|
|
91
|
+
//# sourceMappingURL=observable-to-async-iterable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observable-to-async-iterable.js","sourceRoot":"","sources":["../../src/observable/observable-to-async-iterable.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandomBytes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get random bytes in Javascript
|
|
6
|
+
* @param length - count of random bytes
|
|
7
|
+
* @returns string
|
|
8
|
+
*/
|
|
9
|
+
function getRandomBytes(length) {
|
|
10
|
+
const digits = '0123456789abcdef';
|
|
11
|
+
let n = '';
|
|
12
|
+
for (let i = 0; i < length; i += 1) {
|
|
13
|
+
const rand = Math.floor(Math.random() * 16);
|
|
14
|
+
n += digits[rand];
|
|
15
|
+
}
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
exports.getRandomBytes = getRandomBytes;
|
|
19
|
+
//# sourceMappingURL=get-random-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-random-bytes.js","sourceRoot":"","sources":["../../src/strings/get-random-bytes.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,MAAM,GAAG,kBAAkB,CAAC;IAClC,IAAI,CAAC,GAAG,EAAE,CAAC;IAEX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QAE5C,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;KACnB;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAVD,wCAUC"}
|
package/dist/strings/index.d.ts
CHANGED
package/dist/strings/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./text.fn"), exports);
|
|
18
18
|
__exportStar(require("./capitalize.fn"), exports);
|
|
19
19
|
__exportStar(require("./case"), exports);
|
|
20
|
+
__exportStar(require("./get-random-bytes"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strings/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,kDAAgC;AAChC,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strings/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,kDAAgC;AAChC,yCAAuB;AACvB,qDAAmC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/common",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.14",
|
|
4
4
|
"description": "Useful common classes, functions and types",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"rxjs": "^7.8.1"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "567e6d331c4caa6fdadbe0329f91c471b877f7a4"
|
|
20
20
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './observable-to-async-iterable';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
|
|
3
|
+
import type { Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
export type Callback = (value?: any) => any;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Утилита для создания асинк итератора из обзервабл
|
|
9
|
+
* поиском "observableToAsyncIterable" можно найти тесты в которых есть пример использования
|
|
10
|
+
*/
|
|
11
|
+
export function observableToAsyncIterable<T>(
|
|
12
|
+
observable: Observable<T>,
|
|
13
|
+
): AsyncIterableIterator<T> {
|
|
14
|
+
const pullQueue: Array<Callback> = [];
|
|
15
|
+
const pushQueue: Array<any> = [];
|
|
16
|
+
|
|
17
|
+
let listening = true;
|
|
18
|
+
|
|
19
|
+
const pushValue = (value: any) => {
|
|
20
|
+
if (pullQueue.length > 0) {
|
|
21
|
+
// It is safe to use the ! operator here as we check the length.
|
|
22
|
+
pullQueue.shift()!({ value, done: false });
|
|
23
|
+
} else {
|
|
24
|
+
pushQueue.push({ value, done: false });
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const pushError = (error: any) => {
|
|
29
|
+
if (pullQueue.length > 0) {
|
|
30
|
+
// It is safe to use the ! operator here as we check the length.
|
|
31
|
+
pullQueue.shift()!({ value: { errors: [error] }, done: false });
|
|
32
|
+
} else {
|
|
33
|
+
pushQueue.push({ value: { errors: [error] }, done: false });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const pushDone = () => {
|
|
38
|
+
if (pullQueue.length > 0) {
|
|
39
|
+
// It is safe to use the ! operator here as we check the length.
|
|
40
|
+
pullQueue.shift()!({ done: true });
|
|
41
|
+
} else {
|
|
42
|
+
pushQueue.push({ done: true });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const pullValue = () =>
|
|
47
|
+
new Promise<IteratorResult<T>>((resolve) => {
|
|
48
|
+
if (pushQueue.length > 0) {
|
|
49
|
+
const element = pushQueue.shift();
|
|
50
|
+
|
|
51
|
+
// either {value: {errors: [...]}} or {value: ...}
|
|
52
|
+
resolve(element);
|
|
53
|
+
} else {
|
|
54
|
+
pullQueue.push(resolve);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const subscription = observable.subscribe({
|
|
59
|
+
next(value: any) {
|
|
60
|
+
pushValue(value);
|
|
61
|
+
},
|
|
62
|
+
error(err: Error) {
|
|
63
|
+
pushError(err);
|
|
64
|
+
},
|
|
65
|
+
complete() {
|
|
66
|
+
pushDone();
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const emptyQueue = () => {
|
|
71
|
+
if (listening) {
|
|
72
|
+
listening = false;
|
|
73
|
+
subscription.unsubscribe();
|
|
74
|
+
for (const resolve of pullQueue) {
|
|
75
|
+
resolve({ value: undefined, done: true });
|
|
76
|
+
}
|
|
77
|
+
pullQueue.length = 0;
|
|
78
|
+
pushQueue.length = 0;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
next() {
|
|
84
|
+
// return is a defined method, so it is safe to call it.
|
|
85
|
+
return listening ? pullValue() : this.return!();
|
|
86
|
+
},
|
|
87
|
+
return() {
|
|
88
|
+
emptyQueue();
|
|
89
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
90
|
+
},
|
|
91
|
+
throw(error) {
|
|
92
|
+
emptyQueue();
|
|
93
|
+
return Promise.reject(error);
|
|
94
|
+
},
|
|
95
|
+
[Symbol.asyncIterator]() {
|
|
96
|
+
return this;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get random bytes in Javascript
|
|
3
|
+
* @param length - count of random bytes
|
|
4
|
+
* @returns string
|
|
5
|
+
*/
|
|
6
|
+
export function getRandomBytes(length: number): string {
|
|
7
|
+
const digits = '0123456789abcdef';
|
|
8
|
+
let n = '';
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < length; i += 1) {
|
|
11
|
+
const rand = Math.floor(Math.random() * 16);
|
|
12
|
+
|
|
13
|
+
n += digits[rand];
|
|
14
|
+
}
|
|
15
|
+
return n;
|
|
16
|
+
}
|
package/src/strings/index.ts
CHANGED