jopi-toolkit 3.0.5 → 3.0.10
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/README.md +1 -1
- package/dist/jk_crypto/jBundler_ifServer.d.ts +2 -2
- package/dist/jk_crypto/jBundler_ifServer.js +8 -8
- package/dist/jk_crypto/jBundler_ifServer.js.map +1 -1
- package/dist/jk_events/index.d.ts +5 -5
- package/dist/jk_events/index.js +20 -10
- package/dist/jk_events/index.js.map +1 -1
- package/dist/jk_fs/jBundler_ifBrowser.d.ts +2 -2
- package/dist/jk_fs/jBundler_ifBrowser.js +2 -2
- package/dist/jk_fs/jBundler_ifServer.d.ts +39 -3
- package/dist/jk_fs/jBundler_ifServer.js +152 -3
- package/dist/jk_fs/jBundler_ifServer.js.map +1 -1
- package/dist/jk_logs/index.d.ts +54 -0
- package/dist/jk_logs/index.js +316 -0
- package/dist/jk_logs/index.js.map +1 -0
- package/dist/jk_logs/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_logs/jBundler_ifServer.d.ts +2 -0
- package/dist/jk_logs/jBundler_ifServer.js +25 -0
- package/dist/jk_logs/jBundler_ifServer.js.map +1 -0
- package/dist/jk_schemas/index.js +2 -0
- package/dist/jk_schemas/index.js.map +1 -1
- package/dist/jk_timer/index.js +9 -4
- package/dist/jk_timer/index.js.map +1 -1
- package/dist/jk_tools/common.d.ts +29 -0
- package/dist/jk_tools/common.js +89 -0
- package/dist/jk_tools/common.js.map +1 -0
- package/dist/jk_tools/index.d.ts +1 -20
- package/dist/jk_tools/index.js +1 -71
- package/dist/jk_tools/index.js.map +1 -1
- package/dist/jk_tools/jBundler_ifBrowser.d.ts +1 -0
- package/dist/jk_tools/jBundler_ifBrowser.js +2 -0
- package/dist/jk_tools/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_tools/jBundler_ifServer.d.ts +22 -0
- package/dist/jk_tools/jBundler_ifServer.js +75 -0
- package/dist/jk_tools/jBundler_ifServer.js.map +1 -0
- package/package.json +11 -4
- package/src/jk_crypto/jBundler_ifServer.ts +8 -8
- package/src/jk_events/index.js +17 -7
- package/src/jk_events/index.ts +24 -3
- package/src/jk_fs/jBundler_ifBrowser.ts +2 -2
- package/src/jk_fs/jBundler_ifServer.js +552 -0
- package/src/jk_fs/jBundler_ifServer.ts +171 -4
- package/src/jk_logs/index.ts +444 -0
- package/src/jk_logs/jBundler_ifBrowser.ts +2 -0
- package/src/jk_logs/jBundler_ifServer.ts +27 -0
- package/src/jk_thread/common.js +7 -0
- package/src/jk_tools/common.js +101 -0
- package/src/jk_tools/common.ts +99 -0
- package/src/jk_tools/index.js +1 -82
- package/src/jk_tools/index.ts +1 -82
- package/src/jk_tools/jBundler_ifBrowser.ts +1 -0
- package/src/jk_tools/jBundler_ifServer.js +167 -0
- package/src/jk_tools/jBundler_ifServer.ts +109 -0
- package/src/jk_what/jBundler_ifServer.js +5 -0
- package/dist/jk_appResolver/common.d.ts +0 -40
- package/dist/jk_appResolver/common.js +0 -306
- package/dist/jk_appResolver/common.js.map +0 -1
- package/dist/jk_appResolver/index.d.ts +0 -30
- package/dist/jk_appResolver/index.js +0 -276
- package/dist/jk_appResolver/index.js.map +0 -1
- package/dist/jk_appResolver/jBundler_ifBrowser.js.map +0 -1
- package/dist/jk_appResolver/jBundler_ifServer.d.ts +0 -1
- package/dist/jk_appResolver/jBundler_ifServer.js +0 -9
- package/dist/jk_appResolver/jBundler_ifServer.js.map +0 -1
- package/dist/jk_linker/TypeComposite.d.ts +0 -12
- package/dist/jk_linker/TypeComposite.js +0 -112
- package/dist/jk_linker/TypeComposite.js.map +0 -1
- package/dist/jk_linker/arobaseType_List.d.ts +0 -44
- package/dist/jk_linker/arobaseType_List.js +0 -183
- package/dist/jk_linker/arobaseType_List.js.map +0 -1
- package/dist/jk_linker/arobaseTypes.d.ts +0 -45
- package/dist/jk_linker/arobaseTypes.js +0 -181
- package/dist/jk_linker/arobaseTypes.js.map +0 -1
- package/dist/jk_linker/binding.d.ts +0 -1
- package/dist/jk_linker/binding.js +0 -13
- package/dist/jk_linker/binding.js.map +0 -1
- package/dist/jk_linker/engine.d.ts +0 -119
- package/dist/jk_linker/engine.js +0 -553
- package/dist/jk_linker/engine.js.map +0 -1
- package/dist/jk_linker/index.d.ts +0 -1
- package/dist/jk_linker/index.js +0 -2
- package/dist/jk_linker/index.js.map +0 -1
- package/dist/jk_linker/install.d.ts +0 -4
- package/dist/jk_linker/install.js +0 -44
- package/dist/jk_linker/install.js.map +0 -1
- package/dist/jk_linker/jBundler_ifServer.d.ts +0 -3
- package/dist/jk_linker/jBundler_ifServer.js +0 -4
- package/dist/jk_linker/jBundler_ifServer.js.map +0 -1
- package/dist/jk_linker/modulesInitProcessor.d.ts +0 -7
- package/dist/jk_linker/modulesInitProcessor.js +0 -36
- package/dist/jk_linker/modulesInitProcessor.js.map +0 -1
- package/dist/jk_linker/typeChunks.d.ts +0 -15
- package/dist/jk_linker/typeChunks.js +0 -42
- package/dist/jk_linker/typeChunks.js.map +0 -1
- package/dist/jk_linker/typeComposites.d.ts +0 -13
- package/dist/jk_linker/typeComposites.js +0 -121
- package/dist/jk_linker/typeComposites.js.map +0 -1
- package/dist/jk_linker/typeEvents.d.ts +0 -5
- package/dist/jk_linker/typeEvents.js +0 -29
- package/dist/jk_linker/typeEvents.js.map +0 -1
- package/dist/jk_linker/typeList.d.ts +0 -30
- package/dist/jk_linker/typeList.js +0 -144
- package/dist/jk_linker/typeList.js.map +0 -1
- package/dist/jk_linker/typeListeners.d.ts +0 -21
- package/dist/jk_linker/typeListeners.js +0 -188
- package/dist/jk_linker/typeListeners.js.map +0 -1
- package/dist/jk_linker/typeReplaces.d.ts +0 -8
- package/dist/jk_linker/typeReplaces.js +0 -41
- package/dist/jk_linker/typeReplaces.js.map +0 -1
- package/dist/jk_registry/index.d.ts +0 -11
- package/dist/jk_registry/index.js +0 -36
- package/dist/jk_registry/index.js.map +0 -1
- /package/dist/{jk_appResolver → jk_logs}/jBundler_ifBrowser.d.ts +0 -0
- /package/dist/{jk_appResolver → jk_logs}/jBundler_ifBrowser.js +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
export function generateUUIDv4() {
|
|
13
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
14
|
+
return crypto.randomUUID();
|
|
15
|
+
}
|
|
16
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
17
|
+
var r = Math.random() * 16 | 0;
|
|
18
|
+
var v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
19
|
+
return v.toString(16);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function isUUIDv4(text) {
|
|
23
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(text);
|
|
24
|
+
}
|
|
25
|
+
export function getErrorMessage(e) {
|
|
26
|
+
if (e instanceof Error)
|
|
27
|
+
return e.message;
|
|
28
|
+
return "" + e;
|
|
29
|
+
}
|
|
30
|
+
export function applyDefaults(source, defaults) {
|
|
31
|
+
if (!source)
|
|
32
|
+
source = {};
|
|
33
|
+
return __assign(__assign({}, defaults), source);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Allow knowing the file path of the function calling us.
|
|
37
|
+
*/
|
|
38
|
+
export function getCallerFilePath() {
|
|
39
|
+
try {
|
|
40
|
+
throw new Error("");
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
var error = e;
|
|
44
|
+
if (!error.stack)
|
|
45
|
+
return undefined;
|
|
46
|
+
var stackLines = error.stack.split('\n');
|
|
47
|
+
if (stackLines.length < 4)
|
|
48
|
+
return undefined;
|
|
49
|
+
// Here we have something like:
|
|
50
|
+
// at file:///Users/johan/Projets/jopijs-workspace/__tests/jopi-ui-sample/dist/mod_sample/routes/tests/test3.page.js:4:1
|
|
51
|
+
//
|
|
52
|
+
var fileUrl = stackLines[3].trim();
|
|
53
|
+
var idx = fileUrl.indexOf("file://");
|
|
54
|
+
fileUrl = fileUrl.substring(idx);
|
|
55
|
+
idx = fileUrl.lastIndexOf(":");
|
|
56
|
+
fileUrl = fileUrl.substring(0, idx);
|
|
57
|
+
idx = fileUrl.lastIndexOf(":");
|
|
58
|
+
if (idx !== -1)
|
|
59
|
+
fileUrl = fileUrl.substring(0, idx);
|
|
60
|
+
return fileUrl;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export var PriorityLevel;
|
|
64
|
+
(function (PriorityLevel) {
|
|
65
|
+
PriorityLevel[PriorityLevel["veryLow"] = -200] = "veryLow";
|
|
66
|
+
PriorityLevel[PriorityLevel["low"] = -100] = "low";
|
|
67
|
+
PriorityLevel[PriorityLevel["default"] = 0] = "default";
|
|
68
|
+
PriorityLevel[PriorityLevel["high"] = 100] = "high";
|
|
69
|
+
PriorityLevel[PriorityLevel["veryHigh"] = 200] = "veryHigh";
|
|
70
|
+
})(PriorityLevel || (PriorityLevel = {}));
|
|
71
|
+
export function sortByPriority(values) {
|
|
72
|
+
if (values === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
values.sort(function (a, b) {
|
|
75
|
+
if (a.priority < b.priority)
|
|
76
|
+
return -1;
|
|
77
|
+
if (a.priority > b.priority)
|
|
78
|
+
return 1;
|
|
79
|
+
return 0;
|
|
80
|
+
});
|
|
81
|
+
return values.map(function (v) { return v.value; });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Allows avoiding calling a function before n-milliseconds is elapsed.
|
|
85
|
+
*/
|
|
86
|
+
var DontCallBeforeElapsed = /** @class */ (function () {
|
|
87
|
+
function DontCallBeforeElapsed(requireMs) {
|
|
88
|
+
if (requireMs === void 0) { requireMs = 1000; }
|
|
89
|
+
this.requireMs = requireMs;
|
|
90
|
+
this.lastTime = 0;
|
|
91
|
+
}
|
|
92
|
+
DontCallBeforeElapsed.prototype.check = function () {
|
|
93
|
+
var now = Date.now();
|
|
94
|
+
if (now - this.lastTime < this.requireMs)
|
|
95
|
+
return false;
|
|
96
|
+
this.lastTime = now;
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
99
|
+
return DontCallBeforeElapsed;
|
|
100
|
+
}());
|
|
101
|
+
export { DontCallBeforeElapsed };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export function generateUUIDv4(): string {
|
|
2
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
3
|
+
return crypto.randomUUID();
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
7
|
+
const r = Math.random() * 16 | 0;
|
|
8
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
9
|
+
return v.toString(16);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isUUIDv4(text: string): boolean {
|
|
14
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(text);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getErrorMessage(e: unknown): string {
|
|
18
|
+
if (e instanceof Error) return e.message;
|
|
19
|
+
return "" + e;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function applyDefaults<T>(source: T|undefined, defaults: T): T {
|
|
23
|
+
if (!source) source = {} as T;
|
|
24
|
+
return {...defaults, ...source};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Allow knowing the file path of the function calling us.
|
|
29
|
+
*/
|
|
30
|
+
export function getCallerFilePath(): string|undefined {
|
|
31
|
+
try {
|
|
32
|
+
throw new Error("");
|
|
33
|
+
} catch (e: any) {
|
|
34
|
+
let error: Error = e;
|
|
35
|
+
|
|
36
|
+
if (!error.stack) return undefined;
|
|
37
|
+
|
|
38
|
+
const stackLines = error.stack.split('\n');
|
|
39
|
+
if (stackLines.length < 4) return undefined;
|
|
40
|
+
|
|
41
|
+
// Here we have something like:
|
|
42
|
+
// at file:///Users/johan/Projets/jopijs-workspace/__tests/jopi-ui-sample/dist/mod_sample/routes/tests/test3.page.js:4:1
|
|
43
|
+
//
|
|
44
|
+
let fileUrl = stackLines[3].trim();
|
|
45
|
+
|
|
46
|
+
let idx = fileUrl.indexOf("file://");
|
|
47
|
+
fileUrl = fileUrl.substring(idx);
|
|
48
|
+
|
|
49
|
+
idx = fileUrl.lastIndexOf(":");
|
|
50
|
+
fileUrl = fileUrl.substring(0, idx);
|
|
51
|
+
|
|
52
|
+
idx = fileUrl.lastIndexOf(":");
|
|
53
|
+
if (idx!==-1) fileUrl = fileUrl.substring(0, idx);
|
|
54
|
+
|
|
55
|
+
return fileUrl;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export enum PriorityLevel {
|
|
60
|
+
veryLow = -200,
|
|
61
|
+
low = -100,
|
|
62
|
+
default = 0,
|
|
63
|
+
high = 100,
|
|
64
|
+
veryHigh = 200,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ValueWithPriority<T> {
|
|
68
|
+
value: T;
|
|
69
|
+
priority: PriorityLevel;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function sortByPriority<T>(values: undefined|ValueWithPriority<T>[]): undefined|(T[]) {
|
|
73
|
+
if (values === undefined) return undefined;
|
|
74
|
+
|
|
75
|
+
values.sort((a, b) => {
|
|
76
|
+
if (a.priority < b.priority) return -1;
|
|
77
|
+
if (a.priority > b.priority) return 1;
|
|
78
|
+
return 0;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return values.map(v => v.value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Allows avoiding calling a function before n-milliseconds is elapsed.
|
|
86
|
+
*/
|
|
87
|
+
export class DontCallBeforeElapsed {
|
|
88
|
+
private lastTime = 0;
|
|
89
|
+
|
|
90
|
+
constructor(public readonly requireMs = 1000) {
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
check(): boolean {
|
|
94
|
+
let now = Date.now();
|
|
95
|
+
if (now-this.lastTime<this.requireMs) return false;
|
|
96
|
+
this.lastTime = now;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/jk_tools/index.js
CHANGED
|
@@ -1,82 +1 @@
|
|
|
1
|
-
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
export function generateUUIDv4() {
|
|
13
|
-
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
14
|
-
return crypto.randomUUID();
|
|
15
|
-
}
|
|
16
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
17
|
-
var r = Math.random() * 16 | 0;
|
|
18
|
-
var v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
19
|
-
return v.toString(16);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
export function isUUIDv4(text) {
|
|
23
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(text);
|
|
24
|
-
}
|
|
25
|
-
export function getErrorMessage(e) {
|
|
26
|
-
if (e instanceof Error)
|
|
27
|
-
return e.message;
|
|
28
|
-
return "" + e;
|
|
29
|
-
}
|
|
30
|
-
export function applyDefaults(source, defaults) {
|
|
31
|
-
if (!source)
|
|
32
|
-
source = {};
|
|
33
|
-
return __assign(__assign({}, defaults), source);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Allow knowing the file path of the function calling us.
|
|
37
|
-
*/
|
|
38
|
-
export function getCallerFilePath() {
|
|
39
|
-
try {
|
|
40
|
-
throw new Error("");
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
var error = e;
|
|
44
|
-
if (!error.stack)
|
|
45
|
-
return undefined;
|
|
46
|
-
var stackLines = error.stack.split('\n');
|
|
47
|
-
if (stackLines.length < 4)
|
|
48
|
-
return undefined;
|
|
49
|
-
// Here we have something like:
|
|
50
|
-
// at file:///Users/johan/Projets/jopi-rewrite-workspace/__tests/jopi-ui-sample/dist/mod_sample/routes/tests/test3.page.js:4:1
|
|
51
|
-
//
|
|
52
|
-
var fileUrl = stackLines[3].trim();
|
|
53
|
-
var idx = fileUrl.indexOf("file://");
|
|
54
|
-
fileUrl = fileUrl.substring(idx);
|
|
55
|
-
idx = fileUrl.lastIndexOf(":");
|
|
56
|
-
fileUrl = fileUrl.substring(0, idx);
|
|
57
|
-
idx = fileUrl.lastIndexOf(":");
|
|
58
|
-
if (idx !== -1)
|
|
59
|
-
fileUrl = fileUrl.substring(0, idx);
|
|
60
|
-
return fileUrl;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export var PriorityLevel;
|
|
64
|
-
(function (PriorityLevel) {
|
|
65
|
-
PriorityLevel[PriorityLevel["veryLow"] = -200] = "veryLow";
|
|
66
|
-
PriorityLevel[PriorityLevel["low"] = -100] = "low";
|
|
67
|
-
PriorityLevel[PriorityLevel["default"] = 0] = "default";
|
|
68
|
-
PriorityLevel[PriorityLevel["high"] = 100] = "high";
|
|
69
|
-
PriorityLevel[PriorityLevel["veryHigh"] = 200] = "veryHigh";
|
|
70
|
-
})(PriorityLevel || (PriorityLevel = {}));
|
|
71
|
-
export function sortByPriority(values) {
|
|
72
|
-
if (values === undefined)
|
|
73
|
-
return undefined;
|
|
74
|
-
values.sort(function (a, b) {
|
|
75
|
-
if (a.priority < b.priority)
|
|
76
|
-
return -1;
|
|
77
|
-
if (a.priority > b.priority)
|
|
78
|
-
return 1;
|
|
79
|
-
return 0;
|
|
80
|
-
});
|
|
81
|
-
return values.map(function (v) { return v.value; });
|
|
82
|
-
}
|
|
1
|
+
export * from "./jBundler_ifServer.ts";
|
package/src/jk_tools/index.ts
CHANGED
|
@@ -1,82 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
3
|
-
return crypto.randomUUID();
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
7
|
-
const r = Math.random() * 16 | 0;
|
|
8
|
-
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
9
|
-
return v.toString(16);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function isUUIDv4(text: string): boolean {
|
|
14
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(text);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function getErrorMessage(e: unknown): string {
|
|
18
|
-
if (e instanceof Error) return e.message;
|
|
19
|
-
return "" + e;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function applyDefaults<T>(source: T|undefined, defaults: T): T {
|
|
23
|
-
if (!source) source = {} as T;
|
|
24
|
-
return {...defaults, ...source};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Allow knowing the file path of the function calling us.
|
|
29
|
-
*/
|
|
30
|
-
export function getCallerFilePath(): string|undefined {
|
|
31
|
-
try {
|
|
32
|
-
throw new Error("");
|
|
33
|
-
} catch (e: any) {
|
|
34
|
-
let error: Error = e;
|
|
35
|
-
|
|
36
|
-
if (!error.stack) return undefined;
|
|
37
|
-
|
|
38
|
-
const stackLines = error.stack.split('\n');
|
|
39
|
-
if (stackLines.length < 4) return undefined;
|
|
40
|
-
|
|
41
|
-
// Here we have something like:
|
|
42
|
-
// at file:///Users/johan/Projets/jopi-rewrite-workspace/__tests/jopi-ui-sample/dist/mod_sample/routes/tests/test3.page.js:4:1
|
|
43
|
-
//
|
|
44
|
-
let fileUrl = stackLines[3].trim();
|
|
45
|
-
|
|
46
|
-
let idx = fileUrl.indexOf("file://");
|
|
47
|
-
fileUrl = fileUrl.substring(idx);
|
|
48
|
-
|
|
49
|
-
idx = fileUrl.lastIndexOf(":");
|
|
50
|
-
fileUrl = fileUrl.substring(0, idx);
|
|
51
|
-
|
|
52
|
-
idx = fileUrl.lastIndexOf(":");
|
|
53
|
-
if (idx!==-1) fileUrl = fileUrl.substring(0, idx);
|
|
54
|
-
|
|
55
|
-
return fileUrl;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export enum PriorityLevel {
|
|
60
|
-
veryLow = -200,
|
|
61
|
-
low = -100,
|
|
62
|
-
default = 0,
|
|
63
|
-
high = 100,
|
|
64
|
-
veryHigh = 200,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface ValueWithPriority<T> {
|
|
68
|
-
value: T;
|
|
69
|
-
priority: PriorityLevel;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function sortByPriority<T>(values: undefined|ValueWithPriority<T>[]): undefined|(T[]) {
|
|
73
|
-
if (values === undefined) return undefined;
|
|
74
|
-
|
|
75
|
-
values.sort((a, b) => {
|
|
76
|
-
if (a.priority < b.priority) return -1;
|
|
77
|
-
if (a.priority > b.priority) return 1;
|
|
78
|
-
return 0;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return values.map(v => v.value);
|
|
82
|
-
}
|
|
1
|
+
export * from "./jBundler_ifServer.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./common.ts";
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import * as fs from 'node:fs/promises';
|
|
38
|
+
import * as path from 'node:path';
|
|
39
|
+
export * from "./common.ts";
|
|
40
|
+
import * as jk_timer from "jopi-toolkit/jk_timer";
|
|
41
|
+
/**
|
|
42
|
+
* Download a file or a directory from a GitHub repository.
|
|
43
|
+
*/
|
|
44
|
+
export function githubDownload(params) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
function downloadFile(localPath, contentUrl) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var localDir, headers, response, buffer;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
localDir = path.dirname(localPath);
|
|
53
|
+
headers = {};
|
|
54
|
+
return [4 /*yield*/, fs.mkdir(localDir, { recursive: true })];
|
|
55
|
+
case 1:
|
|
56
|
+
_a.sent();
|
|
57
|
+
return [4 /*yield*/, fetch(contentUrl, { headers: headers, })];
|
|
58
|
+
case 2:
|
|
59
|
+
response = _a.sent();
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
throw new Error("Github download error: ".concat(response.status, " ").concat(response.statusText));
|
|
62
|
+
}
|
|
63
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
64
|
+
case 3:
|
|
65
|
+
buffer = _a.sent();
|
|
66
|
+
return [4 /*yield*/, fs.writeFile(localPath, Buffer.from(buffer))];
|
|
67
|
+
case 4:
|
|
68
|
+
_a.sent();
|
|
69
|
+
if (params.log)
|
|
70
|
+
console.log("Downloaded", contentUrl);
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function fetchAndProcessContent(currentPath, downloadRoot) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var apiUrl, headers, response, data, isFile, contents, _i, contents_1, item, itemPath;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
apiUrl = "https://api.github.com/repos/".concat(repoOwner, "/").concat(repoName, "/contents/").concat(currentPath, "?ref=").concat(branchName);
|
|
83
|
+
headers = {};
|
|
84
|
+
return [4 /*yield*/, fetch(apiUrl, { headers: headers })];
|
|
85
|
+
case 1:
|
|
86
|
+
response = _a.sent();
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error("Github download error: ".concat(response.status, " ").concat(response.statusText));
|
|
89
|
+
}
|
|
90
|
+
return [4 /*yield*/, response.json()];
|
|
91
|
+
case 2:
|
|
92
|
+
data = _a.sent();
|
|
93
|
+
isFile = !Array.isArray(data) && (data.type === 'file');
|
|
94
|
+
if (!(isFile && isFirst)) return [3 /*break*/, 4];
|
|
95
|
+
return [4 /*yield*/, downloadFile(downloadRoot, data.download_url)];
|
|
96
|
+
case 3:
|
|
97
|
+
_a.sent();
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
case 4:
|
|
100
|
+
contents = Array.isArray(data) ? data : [data];
|
|
101
|
+
isFirst = false;
|
|
102
|
+
_i = 0, contents_1 = contents;
|
|
103
|
+
_a.label = 5;
|
|
104
|
+
case 5:
|
|
105
|
+
if (!(_i < contents_1.length)) return [3 /*break*/, 11];
|
|
106
|
+
item = contents_1[_i];
|
|
107
|
+
// Reduce, otherwise we get a "403 rate limit exceed" error.
|
|
108
|
+
return [4 /*yield*/, jk_timer.tick(gRateLimit)];
|
|
109
|
+
case 6:
|
|
110
|
+
// Reduce, otherwise we get a "403 rate limit exceed" error.
|
|
111
|
+
_a.sent();
|
|
112
|
+
if (!(item.type === 'file' && item.download_url)) return [3 /*break*/, 8];
|
|
113
|
+
itemPath = item.path;
|
|
114
|
+
itemPath = itemPath.substring(pathInsideRepo.length + 1);
|
|
115
|
+
return [4 /*yield*/, downloadFile(path.join(downloadRoot, itemPath), item.download_url)];
|
|
116
|
+
case 7:
|
|
117
|
+
_a.sent();
|
|
118
|
+
return [3 /*break*/, 10];
|
|
119
|
+
case 8:
|
|
120
|
+
if (!(item.type === 'dir')) return [3 /*break*/, 10];
|
|
121
|
+
return [4 /*yield*/, fetchAndProcessContent(item.path, downloadRoot)];
|
|
122
|
+
case 9:
|
|
123
|
+
_a.sent();
|
|
124
|
+
_a.label = 10;
|
|
125
|
+
case 10:
|
|
126
|
+
_i++;
|
|
127
|
+
return [3 /*break*/, 5];
|
|
128
|
+
case 11: return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
var isFirst, url, parts, repoOwner, repoName, tree, branchName, pathInsideRepo;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
isFirst = true;
|
|
138
|
+
url = params.url;
|
|
139
|
+
if (!url.startsWith("https://github.com/"))
|
|
140
|
+
throw new Error("Invalid URL - Must be of type https://github.com/ownerName/repoName/tree/branchName/path/to/folder");
|
|
141
|
+
url = url.substring("https://github.com/".length);
|
|
142
|
+
parts = url.split("/").reverse();
|
|
143
|
+
repoOwner = parts.pop();
|
|
144
|
+
repoName = parts.pop();
|
|
145
|
+
tree = parts.pop();
|
|
146
|
+
if (tree !== "tree")
|
|
147
|
+
throw new Error("Invalid URL - Must be of type https://github.com/ownerName/repoName/tree/branchName/path/to/folder");
|
|
148
|
+
branchName = parts.pop();
|
|
149
|
+
pathInsideRepo = parts.reverse().join("/");
|
|
150
|
+
return [4 /*yield*/, fetchAndProcessContent(pathInsideRepo, params.downloadPath)];
|
|
151
|
+
case 1:
|
|
152
|
+
_a.sent();
|
|
153
|
+
return [2 /*return*/];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function getRateLimit() {
|
|
159
|
+
var sLimit = process.env.GITHUB_API_LIMIT_SECONDS;
|
|
160
|
+
if (!sLimit)
|
|
161
|
+
return 50;
|
|
162
|
+
var res = parseInt(sLimit);
|
|
163
|
+
if (isNaN(res))
|
|
164
|
+
return 50;
|
|
165
|
+
return res;
|
|
166
|
+
}
|
|
167
|
+
var gRateLimit = getRateLimit();
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
export * from "./common.ts";
|
|
4
|
+
import * as jk_timer from "jopi-toolkit/jk_timer";
|
|
5
|
+
|
|
6
|
+
export interface GithubDownloadParams {
|
|
7
|
+
/**
|
|
8
|
+
* The file or directory to download.
|
|
9
|
+
* Must be of type: https://github.com/ownerName/repoName/tree/branchName/path/to/folder
|
|
10
|
+
*/
|
|
11
|
+
url: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Where to save the files.
|
|
15
|
+
* If downloading a directory: download the directory inside this folder.
|
|
16
|
+
* If downloading a file: this path is the name of the downloaded file.
|
|
17
|
+
*/
|
|
18
|
+
downloadPath: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* If true, then log the download progress.
|
|
22
|
+
*/
|
|
23
|
+
log?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Download a file or a directory from a GitHub repository.
|
|
28
|
+
*/
|
|
29
|
+
export async function githubDownload(params: GithubDownloadParams) {
|
|
30
|
+
async function downloadFile(localPath: string, contentUrl: string): Promise<void> {
|
|
31
|
+
const localDir = path.dirname(localPath);
|
|
32
|
+
const headers: HeadersInit = {};
|
|
33
|
+
|
|
34
|
+
await fs.mkdir(localDir, { recursive: true });
|
|
35
|
+
|
|
36
|
+
const response = await fetch(contentUrl, {headers: headers,});
|
|
37
|
+
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`Github download error: ${response.status} ${response.statusText}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const buffer = await response.arrayBuffer();
|
|
43
|
+
await fs.writeFile(localPath, Buffer.from(buffer));
|
|
44
|
+
|
|
45
|
+
if (params.log) console.log("Downloaded", contentUrl)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function fetchAndProcessContent(currentPath: string, downloadRoot: string): Promise<void> {
|
|
49
|
+
const apiUrl = `https://api.github.com/repos/${repoOwner}/${repoName}/contents/${currentPath}?ref=${branchName}`;
|
|
50
|
+
const headers: HeadersInit = {};
|
|
51
|
+
|
|
52
|
+
const response = await fetch(apiUrl, { headers });
|
|
53
|
+
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(`Github download error: ${response.status} ${response.statusText}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
const isFile = !Array.isArray(data) && (data.type === 'file');
|
|
60
|
+
|
|
61
|
+
if (isFile && isFirst) {
|
|
62
|
+
await downloadFile(downloadRoot, data.download_url);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const contents: any[] = Array.isArray(data) ? data : [data];
|
|
67
|
+
isFirst = false;
|
|
68
|
+
|
|
69
|
+
for (const item of contents) {
|
|
70
|
+
// Reduce, otherwise we get a "403 rate limit exceed" error.
|
|
71
|
+
await jk_timer.tick(gRateLimit);
|
|
72
|
+
|
|
73
|
+
if (item.type === 'file' && item.download_url) {
|
|
74
|
+
let itemPath = item.path;
|
|
75
|
+
itemPath = itemPath.substring(pathInsideRepo.length + 1);
|
|
76
|
+
await downloadFile(path.join(downloadRoot, itemPath), item.download_url);
|
|
77
|
+
} else if (item.type === 'dir') {
|
|
78
|
+
await fetchAndProcessContent(item.path, downloadRoot);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let isFirst = true;
|
|
84
|
+
|
|
85
|
+
let url = params.url;
|
|
86
|
+
if (!url.startsWith("https://github.com/")) throw new Error("Invalid URL - Must be of type https://github.com/ownerName/repoName/tree/branchName/path/to/folder");
|
|
87
|
+
|
|
88
|
+
url = url.substring("https://github.com/".length);
|
|
89
|
+
let parts = url.split("/").reverse();
|
|
90
|
+
|
|
91
|
+
let repoOwner = parts.pop();
|
|
92
|
+
let repoName = parts.pop();
|
|
93
|
+
let tree = parts.pop();
|
|
94
|
+
if (tree!=="tree") throw new Error("Invalid URL - Must be of type https://github.com/ownerName/repoName/tree/branchName/path/to/folder");
|
|
95
|
+
let branchName = parts.pop();
|
|
96
|
+
const pathInsideRepo = parts.reverse().join("/");
|
|
97
|
+
|
|
98
|
+
await fetchAndProcessContent(pathInsideRepo, params.downloadPath);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getRateLimit() {
|
|
102
|
+
let sLimit = process.env.GITHUB_API_LIMIT_SECONDS;
|
|
103
|
+
if (!sLimit) return 50;
|
|
104
|
+
let res = parseInt(sLimit);
|
|
105
|
+
if (isNaN(res)) return 50;
|
|
106
|
+
return res;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const gRateLimit = getRateLimit();
|