@allgemein/base 1.8.1 → 1.10.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/Constants.d.ts +2 -8
- package/Constants.js +5 -15
- package/Constants.js.map +1 -1
- package/MetaArgs.d.ts +1 -1
- package/MetaArgs.js +4 -8
- package/MetaArgs.js.map +1 -1
- package/MetadataStorage.js +6 -10
- package/MetadataStorage.js.map +1 -1
- package/README.md +71 -0
- package/browser.d.ts +2 -2
- package/browser.js +2 -36
- package/browser.js.map +1 -1
- package/exceptions/NestedException.js +1 -5
- package/exceptions/NestedException.js.map +1 -1
- package/exceptions/NotSupportedError.js +1 -5
- package/exceptions/NotSupportedError.js.map +1 -1
- package/exceptions/NotYetImplementedError.js +1 -5
- package/exceptions/NotYetImplementedError.js.map +1 -1
- package/exceptions/TodoException.js +1 -5
- package/exceptions/TodoException.js.map +1 -1
- package/fns/isPromiseLike.js +1 -4
- package/fns/isPromiseLike.js.map +1 -1
- package/generics.d.ts +60 -0
- package/generics.js +1463 -0
- package/generics.js.map +1 -0
- package/index.d.ts +5 -5
- package/index.js +5 -26
- package/index.js.map +1 -1
- package/locking/LockFactory.d.ts +1 -1
- package/locking/LockFactory.js +8 -12
- package/locking/LockFactory.js.map +1 -1
- package/locking/Semaphore.js +2 -6
- package/locking/Semaphore.js.map +1 -1
- package/package.json +2 -2
- package/shared.d.ts +18 -23
- package/shared.js +18 -53
- package/shared.js.map +1 -1
- package/utils/ArrayUtils.js +22 -26
- package/utils/ArrayUtils.js.map +1 -1
- package/utils/ClassLoader.d.ts +5 -5
- package/utils/ClassLoader.js +41 -41
- package/utils/ClassLoader.js.map +1 -1
- package/utils/ClassUtils.d.ts +2 -2
- package/utils/ClassUtils.js +11 -15
- package/utils/ClassUtils.js.map +1 -1
- package/utils/CryptUtils.js +1 -5
- package/utils/CryptUtils.js.map +1 -1
- package/utils/FileUtils.js +12 -16
- package/utils/FileUtils.js.map +1 -1
- package/utils/Glob.js +6 -10
- package/utils/Glob.js.map +1 -1
- package/utils/Interpolation.js +5 -9
- package/utils/Interpolation.js.map +1 -1
- package/utils/JsonUtils.js +8 -12
- package/utils/JsonUtils.js.map +1 -1
- package/utils/PlatformUtils.d.ts +2 -1
- package/utils/PlatformUtils.js +58 -64
- package/utils/PlatformUtils.js.map +1 -1
- package/utils/PlatformUtilsBrowser.js +27 -31
- package/utils/PlatformUtilsBrowser.js.map +1 -1
- package/utils/Serializer.js +23 -27
- package/utils/Serializer.js.map +1 -1
- package/utils/TreeUtils.js +9 -13
- package/utils/TreeUtils.js.map +1 -1
- package/logging/AbstractLogger.d.ts +0 -24
- package/logging/AbstractLogger.js +0 -72
- package/logging/AbstractLogger.js.map +0 -1
- package/logging/ConsoleLogger.d.ts +0 -4
- package/logging/ConsoleLogger.js +0 -30
- package/logging/ConsoleLogger.js.map +0 -1
- package/logging/ILogLevel.d.ts +0 -4
- package/logging/ILogLevel.js +0 -3
- package/logging/ILogLevel.js.map +0 -1
- package/logging/ILoggerApi.d.ts +0 -12
- package/logging/ILoggerApi.js +0 -3
- package/logging/ILoggerApi.js.map +0 -1
- package/logging/ILoggerOptions.d.ts +0 -7
- package/logging/ILoggerOptions.js +0 -3
- package/logging/ILoggerOptions.js.map +0 -1
- package/logging/Logger.d.ts +0 -23
- package/logging/Logger.js +0 -65
- package/logging/Logger.js.map +0 -1
package/utils/PlatformUtils.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* see https://github.com/typeorm/typeorm/blob/master/src/platform/PlatformTools.ts
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
4
|
+
import { extname, normalize, basename, isAbsolute, join, resolve, sep, dirname } from 'node:path';
|
|
5
|
+
import { access, existsSync, mkdirSync, stat, readdir, readFileSync, rmdir, statSync } from 'node:fs';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { isString } from '../generics.js';
|
|
9
|
+
import { FileUtils } from './FileUtils.js';
|
|
10
|
+
const _require = createRequire(import.meta.url);
|
|
11
|
+
const FILEPATH = sep === '/' ? /^(\.|\.\/|\/)([\w\/\.\-_ ]*)$/ : /^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+$/;
|
|
12
12
|
/**
|
|
13
13
|
* Platform-specific tools.
|
|
14
14
|
*/
|
|
15
|
-
class PlatformUtils {
|
|
15
|
+
export class PlatformUtils {
|
|
16
16
|
/**
|
|
17
17
|
* Gets global variable where global stuff can be stored.
|
|
18
18
|
*/
|
|
@@ -23,7 +23,7 @@ class PlatformUtils {
|
|
|
23
23
|
* set workdir
|
|
24
24
|
*/
|
|
25
25
|
static setWorkDir(workdir) {
|
|
26
|
-
if (
|
|
26
|
+
if (isString(workdir)) {
|
|
27
27
|
this.workdir = PlatformUtils.pathResolve(workdir);
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
@@ -31,7 +31,7 @@ class PlatformUtils {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
static join(...args) {
|
|
34
|
-
return
|
|
34
|
+
return join(...args);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Loads ("require"-s) given file or package.
|
|
@@ -42,52 +42,47 @@ class PlatformUtils {
|
|
|
42
42
|
// this is useful when we are using typeorm package globally installed and it accesses drivers
|
|
43
43
|
// that are not installed globally
|
|
44
44
|
try {
|
|
45
|
-
|
|
46
|
-
const ext = this.pathExtname(name);
|
|
47
|
-
if (ext) {
|
|
48
|
-
// name without ext
|
|
49
|
-
name = name.replace(ext, '');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return require(name);
|
|
45
|
+
return _require(name);
|
|
53
46
|
}
|
|
54
47
|
catch (err) {
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
48
|
+
if (this.isBareSpecifier(name)) {
|
|
49
|
+
return _require(_require.resolve(name, { paths: [process.cwd()] }));
|
|
57
50
|
}
|
|
58
51
|
throw err;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
54
|
/**
|
|
62
|
-
* Loads ("
|
|
55
|
+
* Loads ("import"-s) given file or package.
|
|
63
56
|
* This operation only supports on node platform
|
|
64
57
|
*/
|
|
65
|
-
static loadAsync(name) {
|
|
58
|
+
static async loadAsync(name) {
|
|
66
59
|
// if name is not absolute or relative, then try to load package from the node_modules of the directory we are currenly in
|
|
67
60
|
// this is useful when we are using typeorm package globally installed and it accesses drivers
|
|
68
61
|
// that are not installed globally
|
|
62
|
+
if (this.pathExtname(name) === '.json') {
|
|
63
|
+
return this.load(name);
|
|
64
|
+
}
|
|
65
|
+
if (this.fileExist(name)) {
|
|
66
|
+
return import(pathToFileURL(resolve(name)).href);
|
|
67
|
+
}
|
|
69
68
|
try {
|
|
70
|
-
|
|
71
|
-
const ext = this.pathExtname(name);
|
|
72
|
-
if (ext) {
|
|
73
|
-
// name without ext
|
|
74
|
-
name = name.replace(ext, '');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return Promise.resolve(`${name}`).then(s => require(s));
|
|
69
|
+
return await import(name);
|
|
78
70
|
}
|
|
79
71
|
catch (err) {
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
72
|
+
if (this.isBareSpecifier(name)) {
|
|
73
|
+
return import(pathToFileURL(_require.resolve(name, { paths: [process.cwd()] })).href);
|
|
82
74
|
}
|
|
83
75
|
throw err;
|
|
84
76
|
}
|
|
85
77
|
}
|
|
78
|
+
static isBareSpecifier(name) {
|
|
79
|
+
return !isAbsolute(name) && name.substr(0, 2) !== './' && name.substr(0, 3) !== '../';
|
|
80
|
+
}
|
|
86
81
|
/**
|
|
87
82
|
* Normalizes given Does "normalize".
|
|
88
83
|
*/
|
|
89
84
|
static pathNormilize(pathStr) {
|
|
90
|
-
return
|
|
85
|
+
return normalize(pathStr);
|
|
91
86
|
}
|
|
92
87
|
/**
|
|
93
88
|
* Gets file extension. Does "extname".
|
|
@@ -95,10 +90,10 @@ class PlatformUtils {
|
|
|
95
90
|
static pathExtname(pathStr, dotted = true) {
|
|
96
91
|
let str = '';
|
|
97
92
|
if (/\$\{.*\}/.test(pathStr)) {
|
|
98
|
-
str = this.withoutInterpolation(pathStr, (str) =>
|
|
93
|
+
str = this.withoutInterpolation(pathStr, (str) => extname(str));
|
|
99
94
|
}
|
|
100
95
|
else {
|
|
101
|
-
str =
|
|
96
|
+
str = extname(pathStr);
|
|
102
97
|
}
|
|
103
98
|
if (!dotted) {
|
|
104
99
|
str = str.replace('.', '');
|
|
@@ -110,9 +105,9 @@ class PlatformUtils {
|
|
|
110
105
|
*/
|
|
111
106
|
static pathResolve(pathStr) {
|
|
112
107
|
if (this.workdir) {
|
|
113
|
-
return
|
|
108
|
+
return resolve(this.workdir, pathStr);
|
|
114
109
|
}
|
|
115
|
-
return
|
|
110
|
+
return resolve(pathStr);
|
|
116
111
|
}
|
|
117
112
|
/**
|
|
118
113
|
* Resolved given Does "resolve".
|
|
@@ -121,23 +116,23 @@ class PlatformUtils {
|
|
|
121
116
|
return this.pathNormilize(this.pathResolve(pathStr));
|
|
122
117
|
}
|
|
123
118
|
static isFile(pathStr) {
|
|
124
|
-
return
|
|
119
|
+
return statSync(pathStr).isFile();
|
|
125
120
|
}
|
|
126
121
|
static isDir(pathStr) {
|
|
127
|
-
return
|
|
122
|
+
return statSync(pathStr).isDirectory();
|
|
128
123
|
}
|
|
129
124
|
/**
|
|
130
125
|
* Synchronously checks if file exist. Does "existsSync".
|
|
131
126
|
*/
|
|
132
127
|
static fileExist(pathStr) {
|
|
133
|
-
return
|
|
128
|
+
return existsSync(pathStr);
|
|
134
129
|
}
|
|
135
130
|
/**
|
|
136
131
|
* Synchronously checks if file exist. Does "existsSync".
|
|
137
132
|
*/
|
|
138
133
|
static fileExistAsync(pathStr) {
|
|
139
134
|
return new Promise((resolve, reject) => {
|
|
140
|
-
|
|
135
|
+
stat(pathStr, err => {
|
|
141
136
|
if (err) {
|
|
142
137
|
reject(err);
|
|
143
138
|
}
|
|
@@ -151,7 +146,7 @@ class PlatformUtils {
|
|
|
151
146
|
* Returns the basename of a file
|
|
152
147
|
*/
|
|
153
148
|
static basename(pathStr) {
|
|
154
|
-
return
|
|
149
|
+
return basename(pathStr);
|
|
155
150
|
}
|
|
156
151
|
static withoutInterpolation(str, fn) {
|
|
157
152
|
if (/\$\{.*\}/.test(str)) {
|
|
@@ -180,17 +175,17 @@ class PlatformUtils {
|
|
|
180
175
|
* Returns the filename only (without extension)
|
|
181
176
|
*/
|
|
182
177
|
static filename(pathStr) {
|
|
183
|
-
const base =
|
|
178
|
+
const base = basename(pathStr);
|
|
184
179
|
if (/\$\{.*\}/.test(base)) {
|
|
185
|
-
return this.withoutInterpolation(base, (str) => str.replace(new RegExp('\\' +
|
|
180
|
+
return this.withoutInterpolation(base, (str) => str.replace(new RegExp('\\' + extname(str) + '$'), ''));
|
|
186
181
|
}
|
|
187
|
-
return base.replace(new RegExp('\\' +
|
|
182
|
+
return base.replace(new RegExp('\\' + extname(base) + '$'), '');
|
|
188
183
|
}
|
|
189
184
|
/**
|
|
190
185
|
* Returns the dirname of the file
|
|
191
186
|
*/
|
|
192
187
|
static dirname(pathStr) {
|
|
193
|
-
return
|
|
188
|
+
return dirname(pathStr);
|
|
194
189
|
}
|
|
195
190
|
static testForFilePath(path) {
|
|
196
191
|
return FILEPATH.test(path);
|
|
@@ -199,7 +194,7 @@ class PlatformUtils {
|
|
|
199
194
|
* Normalizes given Does "normalize".
|
|
200
195
|
*/
|
|
201
196
|
static pathNormalize(pathStr) {
|
|
202
|
-
return
|
|
197
|
+
return normalize(pathStr);
|
|
203
198
|
}
|
|
204
199
|
/**
|
|
205
200
|
* Normalizes given Does "normalize".
|
|
@@ -211,10 +206,10 @@ class PlatformUtils {
|
|
|
211
206
|
* Test if path is absolute.
|
|
212
207
|
*/
|
|
213
208
|
static isAbsolute(pathStr) {
|
|
214
|
-
return
|
|
209
|
+
return isAbsolute(pathStr);
|
|
215
210
|
}
|
|
216
211
|
static directory(file) {
|
|
217
|
-
return
|
|
212
|
+
return dirname(file);
|
|
218
213
|
}
|
|
219
214
|
/**
|
|
220
215
|
* Gets environment variable.
|
|
@@ -224,47 +219,47 @@ class PlatformUtils {
|
|
|
224
219
|
}
|
|
225
220
|
static getHostPath() {
|
|
226
221
|
if (process.platform === 'win32') {
|
|
227
|
-
return
|
|
222
|
+
return join(process.env.SYSTEMROOT, '/System32/drivers/etc/hosts');
|
|
228
223
|
}
|
|
229
224
|
return '/etc/hosts';
|
|
230
225
|
}
|
|
231
226
|
static getHostFileContent() {
|
|
232
|
-
return
|
|
227
|
+
return readFileSync(this.getHostPath(), { encoding: 'utf-8' });
|
|
233
228
|
}
|
|
234
|
-
static mkdir(targetDir, _sep =
|
|
235
|
-
const initDir =
|
|
229
|
+
static mkdir(targetDir, _sep = sep) {
|
|
230
|
+
const initDir = isAbsolute(targetDir) ? _sep : '';
|
|
236
231
|
targetDir.split(_sep).reduce((parentDir, childDir) => {
|
|
237
|
-
const curDir =
|
|
238
|
-
if (!
|
|
239
|
-
|
|
232
|
+
const curDir = resolve(parentDir, childDir);
|
|
233
|
+
if (!existsSync(curDir)) {
|
|
234
|
+
mkdirSync(curDir);
|
|
240
235
|
}
|
|
241
236
|
return curDir;
|
|
242
237
|
}, initDir);
|
|
243
238
|
return true;
|
|
244
239
|
}
|
|
245
240
|
static readFile(filename) {
|
|
246
|
-
return
|
|
241
|
+
return FileUtils.readFile(filename);
|
|
247
242
|
}
|
|
248
243
|
static readFileSync(filename) {
|
|
249
|
-
return
|
|
244
|
+
return FileUtils.readFileSync(filename);
|
|
250
245
|
}
|
|
251
246
|
static deleteFile(dir, file) {
|
|
252
|
-
return
|
|
247
|
+
return FileUtils.deleteFile(dir, file);
|
|
253
248
|
}
|
|
254
249
|
static deleteDirectory(dir) {
|
|
255
250
|
return new Promise(function (resolve, reject) {
|
|
256
|
-
|
|
251
|
+
access(dir, function (err) {
|
|
257
252
|
if (err) {
|
|
258
253
|
return reject(err);
|
|
259
254
|
}
|
|
260
|
-
|
|
255
|
+
readdir(dir, function (err, files) {
|
|
261
256
|
if (err) {
|
|
262
257
|
return reject(err);
|
|
263
258
|
}
|
|
264
259
|
Promise.all(files.map(function (file) {
|
|
265
260
|
return PlatformUtils.deleteFile(dir, file);
|
|
266
261
|
})).then(function () {
|
|
267
|
-
|
|
262
|
+
rmdir(dir, function (err) {
|
|
268
263
|
if (err) {
|
|
269
264
|
return reject(err);
|
|
270
265
|
}
|
|
@@ -276,7 +271,6 @@ class PlatformUtils {
|
|
|
276
271
|
});
|
|
277
272
|
}
|
|
278
273
|
}
|
|
279
|
-
exports.PlatformUtils = PlatformUtils;
|
|
280
274
|
/**
|
|
281
275
|
* Type of the currently running platform.
|
|
282
276
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformUtils.js","sourceRoot":"","sources":["../../../src/utils/PlatformUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformUtils.js","sourceRoot":"","sources":["../../../src/utils/PlatformUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAC,MAAM,WAAW,CAAC;AAChG,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AACpG,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AACvC,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC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AED,MAAM,CAAC,eAAe,CAAC,GAAW;QAChC,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;YAC1C,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG;gBACvB,IAAI,GAAG,EAAE,CAAC;oBACR,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;gBACrB,CAAC;gBACD,OAAO,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,KAAK;oBAC/B,IAAI,GAAG,EAAE,CAAC;wBACR,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;oBACrB,CAAC;oBACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,IAAI;wBAClC,OAAO,aAAa,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;oBAC7C,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;wBACP,KAAK,CAAC,GAAG,EAAE,UAAU,GAAU;4BAC7B,IAAI,GAAG,EAAE,CAAC;gCACR,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;4BACrB,CAAC;4BACD,OAAO,CAAC,IAAI,CAAC,CAAC;wBAChB,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnB,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;;AAlTD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAC;AAElC,qBAAO,GAAW,IAAI,CAAC"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* see https://github.com/typeorm/typeorm/blob/master/src/platform/PlatformTools.ts
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const lodash_1 = require("lodash");
|
|
8
|
-
const NotSupportedError_1 = require("../exceptions/NotSupportedError");
|
|
4
|
+
import { isString } from '../generics.js';
|
|
5
|
+
import { NotSupportedError } from '../exceptions/NotSupportedError.js';
|
|
9
6
|
/**
|
|
10
7
|
* Platform-specific tools.
|
|
11
8
|
*/
|
|
12
|
-
class PlatformUtils {
|
|
9
|
+
export class PlatformUtils {
|
|
13
10
|
/**
|
|
14
11
|
* Gets global variable where global stuff can be stored.
|
|
15
12
|
*/
|
|
@@ -20,7 +17,7 @@ class PlatformUtils {
|
|
|
20
17
|
* set workdir
|
|
21
18
|
*/
|
|
22
19
|
static setWorkDir(workdir) {
|
|
23
|
-
if (
|
|
20
|
+
if (isString(workdir)) {
|
|
24
21
|
this.workdir = PlatformUtils.pathResolve(workdir);
|
|
25
22
|
}
|
|
26
23
|
else {
|
|
@@ -31,28 +28,28 @@ class PlatformUtils {
|
|
|
31
28
|
return args.join('/');
|
|
32
29
|
}
|
|
33
30
|
static load(name) {
|
|
34
|
-
throw new
|
|
31
|
+
throw new NotSupportedError('not supported');
|
|
35
32
|
}
|
|
36
33
|
static loadAsync(name) {
|
|
37
|
-
throw new
|
|
34
|
+
throw new NotSupportedError('not supported');
|
|
38
35
|
}
|
|
39
36
|
/**
|
|
40
37
|
* Normalizes given path. Does "path.normalize".
|
|
41
38
|
*/
|
|
42
39
|
static pathNormilize(pathStr) {
|
|
43
|
-
throw new
|
|
40
|
+
throw new NotSupportedError('not supported');
|
|
44
41
|
}
|
|
45
42
|
/**
|
|
46
43
|
* Gets file extension. Does "path.extname".
|
|
47
44
|
*/
|
|
48
45
|
static pathExtname(pathStr, dotted = true) {
|
|
49
|
-
throw new
|
|
46
|
+
throw new NotSupportedError('not supported');
|
|
50
47
|
}
|
|
51
48
|
/**
|
|
52
49
|
* Resolved given path. Does "path.resolve".
|
|
53
50
|
*/
|
|
54
51
|
static pathResolve(pathStr) {
|
|
55
|
-
throw new
|
|
52
|
+
throw new NotSupportedError('not supported');
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
55
|
* Resolved given path. Does "path.resolve".
|
|
@@ -61,25 +58,25 @@ class PlatformUtils {
|
|
|
61
58
|
return this.pathNormilize(this.pathResolve(pathStr));
|
|
62
59
|
}
|
|
63
60
|
static isFile(pathStr) {
|
|
64
|
-
throw new
|
|
61
|
+
throw new NotSupportedError('not supported');
|
|
65
62
|
}
|
|
66
63
|
static isDir(pathStr) {
|
|
67
|
-
throw new
|
|
64
|
+
throw new NotSupportedError('not supported');
|
|
68
65
|
}
|
|
69
66
|
/**
|
|
70
67
|
* Synchronously checks if file exist. Does "fs.existsSync".
|
|
71
68
|
*/
|
|
72
69
|
static fileExist(pathStr) {
|
|
73
|
-
throw new
|
|
70
|
+
throw new NotSupportedError('not supported');
|
|
74
71
|
}
|
|
75
72
|
static fileExistAsync(pathStr) {
|
|
76
|
-
throw new
|
|
73
|
+
throw new NotSupportedError('not supported');
|
|
77
74
|
}
|
|
78
75
|
/**
|
|
79
76
|
* Returns the basename of a file
|
|
80
77
|
*/
|
|
81
78
|
static basename(pathStr) {
|
|
82
|
-
throw new
|
|
79
|
+
throw new NotSupportedError('not supported');
|
|
83
80
|
}
|
|
84
81
|
static withoutInterpolation(str, fn) {
|
|
85
82
|
if (/\$\{.*\}/.test(str)) {
|
|
@@ -108,22 +105,22 @@ class PlatformUtils {
|
|
|
108
105
|
* Returns the filename only (without extension)
|
|
109
106
|
*/
|
|
110
107
|
static filename(pathStr) {
|
|
111
|
-
throw new
|
|
108
|
+
throw new NotSupportedError('not supported');
|
|
112
109
|
}
|
|
113
110
|
/**
|
|
114
111
|
* Returns the dirname of the file
|
|
115
112
|
*/
|
|
116
113
|
static dirname(pathStr) {
|
|
117
|
-
throw new
|
|
114
|
+
throw new NotSupportedError('not supported');
|
|
118
115
|
}
|
|
119
116
|
static testForFilePath(path) {
|
|
120
|
-
throw new
|
|
117
|
+
throw new NotSupportedError('not supported');
|
|
121
118
|
}
|
|
122
119
|
/**
|
|
123
120
|
* Normalizes given path. Does "path.normalize".
|
|
124
121
|
*/
|
|
125
122
|
static pathNormalize(pathStr) {
|
|
126
|
-
throw new
|
|
123
|
+
throw new NotSupportedError('not supported');
|
|
127
124
|
}
|
|
128
125
|
/**
|
|
129
126
|
* Normalizes given path. Does "path.normalize".
|
|
@@ -135,10 +132,10 @@ class PlatformUtils {
|
|
|
135
132
|
* Test if path is absolute.
|
|
136
133
|
*/
|
|
137
134
|
static isAbsolute(pathStr) {
|
|
138
|
-
throw new
|
|
135
|
+
throw new NotSupportedError('not supported');
|
|
139
136
|
}
|
|
140
137
|
static directory(file) {
|
|
141
|
-
throw new
|
|
138
|
+
throw new NotSupportedError('not supported');
|
|
142
139
|
}
|
|
143
140
|
/**
|
|
144
141
|
* Gets environment variable.
|
|
@@ -147,28 +144,27 @@ class PlatformUtils {
|
|
|
147
144
|
return process.env[name];
|
|
148
145
|
}
|
|
149
146
|
static getHostPath() {
|
|
150
|
-
throw new
|
|
147
|
+
throw new NotSupportedError('not supported');
|
|
151
148
|
}
|
|
152
149
|
static getHostFileContent() {
|
|
153
|
-
throw new
|
|
150
|
+
throw new NotSupportedError('not supported');
|
|
154
151
|
}
|
|
155
152
|
static mkdir(targetDir, sep = null) {
|
|
156
|
-
throw new
|
|
153
|
+
throw new NotSupportedError('not supported');
|
|
157
154
|
}
|
|
158
155
|
static readFile(filename) {
|
|
159
|
-
throw new
|
|
156
|
+
throw new NotSupportedError('not supported');
|
|
160
157
|
}
|
|
161
158
|
static readFileSync(filename) {
|
|
162
|
-
throw new
|
|
159
|
+
throw new NotSupportedError('not supported');
|
|
163
160
|
}
|
|
164
161
|
static deleteFile(dir, file) {
|
|
165
|
-
throw new
|
|
162
|
+
throw new NotSupportedError('not supported');
|
|
166
163
|
}
|
|
167
164
|
static deleteDirectory(dir) {
|
|
168
|
-
throw new
|
|
165
|
+
throw new NotSupportedError('not supported');
|
|
169
166
|
}
|
|
170
167
|
}
|
|
171
|
-
exports.PlatformUtils = PlatformUtils;
|
|
172
168
|
/**
|
|
173
169
|
* Type of the currently running platform.
|
|
174
170
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformUtilsBrowser.js","sourceRoot":"","sources":["../../../src/utils/PlatformUtilsBrowser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformUtilsBrowser.js","sourceRoot":"","sources":["../../../src/utils/PlatformUtilsBrowser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,iBAAiB,EAAC,MAAM,oCAAoC,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,aAAa;IASxB;;OAEG;IACH,MAAM,CAAC,iBAAiB;QACtB,OAAO,MAAM,CAAC;IAChB,CAAC;IAGD;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAe;QAC/B,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAGD,MAAM,CAAC,IAAI,CAAC,GAAG,IAAc;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAY;QACtB,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,IAAY;QAC3B,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAGD;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAe;QAClC,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAe,EAAE,SAAkB,IAAI;QACxD,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH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AAC,CAAC;IAC/C,CAAC;IAGD;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,IAAY;QAChC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAGD,MAAM,CAAC,WAAW;QAChB,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,kBAAkB;QACvB,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,SAAiB,EAAE,MAAc,IAAI;QAChD,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAGD,MAAM,CAAC,QAAQ,CAAC,QAAgB;QAC9B,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,QAAgB;QAClC,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,GAAW,EAAE,IAAY;QACzC,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,GAAW;QAChC,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;;AAxMD;;GAEG;AACI,kBAAI,GAAuB,MAAM,CAAC;AAElC,qBAAO,GAAW,IAAI,CAAC"}
|
package/utils/Serializer.js
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const ClassUtils_1 = require("./ClassUtils");
|
|
8
|
-
const Constants_1 = require("../Constants");
|
|
9
|
-
class Serializer {
|
|
1
|
+
import { assign, cloneDeep, get, isArray, isNumber, isObjectLike, set } from '../generics.js';
|
|
2
|
+
import { JsonUtils } from './JsonUtils.js';
|
|
3
|
+
import { TreeUtils } from './TreeUtils.js';
|
|
4
|
+
import { ClassUtils } from './ClassUtils.js';
|
|
5
|
+
import { __CLASS__ } from '../Constants.js';
|
|
6
|
+
export class Serializer {
|
|
10
7
|
static serialize(data) {
|
|
11
|
-
const x =
|
|
8
|
+
const x = cloneDeep(data);
|
|
12
9
|
this.serializeObject(x);
|
|
13
|
-
return
|
|
10
|
+
return JsonUtils.stringify(x);
|
|
14
11
|
}
|
|
15
12
|
static deserialize(data) {
|
|
16
|
-
let x =
|
|
13
|
+
let x = JsonUtils.parse(data);
|
|
17
14
|
x = this.deserializeObject(x);
|
|
18
15
|
return x;
|
|
19
16
|
}
|
|
20
17
|
static serializeObject(x) {
|
|
21
|
-
if (
|
|
18
|
+
if (isObjectLike(x) && !isArray(x)) {
|
|
22
19
|
this.serializeClass(x);
|
|
23
|
-
|
|
24
|
-
if (
|
|
20
|
+
TreeUtils.walk(x, (v) => {
|
|
21
|
+
if (isObjectLike(v.value) && !isArray(v.value)) {
|
|
25
22
|
this.serializeClass(v.value);
|
|
26
23
|
}
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
|
-
else if (
|
|
26
|
+
else if (isArray(x)) {
|
|
30
27
|
for (let i = 0; i < x.length; i++) {
|
|
31
28
|
this.serializeObject(x[i]);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
static deserializeObject(x) {
|
|
36
|
-
if (
|
|
33
|
+
if (isObjectLike(x) && !isArray(x)) {
|
|
37
34
|
x = this.deserializeClass(x);
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
if (
|
|
35
|
+
TreeUtils.walk(x, (y) => {
|
|
36
|
+
if (isObjectLike(y.value) && !isArray(y.value)) {
|
|
37
|
+
if (isNumber(y.index)) {
|
|
41
38
|
y.parent[y.index] = this.deserializeClass(y.value);
|
|
42
39
|
}
|
|
43
40
|
else {
|
|
@@ -46,7 +43,7 @@ class Serializer {
|
|
|
46
43
|
}
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
|
-
else if (
|
|
46
|
+
else if (isArray(x)) {
|
|
50
47
|
for (let i = 0; i < x.length; i++) {
|
|
51
48
|
x[i] = this.deserializeObject(x[i]);
|
|
52
49
|
}
|
|
@@ -54,30 +51,29 @@ class Serializer {
|
|
|
54
51
|
return x;
|
|
55
52
|
}
|
|
56
53
|
static serializeClass(x) {
|
|
57
|
-
const clsName =
|
|
54
|
+
const clsName = ClassUtils.getClassName(x);
|
|
58
55
|
if (![Object.name, Array.name, Date.name].includes(clsName)) {
|
|
59
56
|
const fn = Object.getPrototypeOf(x);
|
|
60
57
|
if (!this.TYPES[clsName]) {
|
|
61
58
|
this.TYPES[clsName] = fn.constructor;
|
|
62
59
|
}
|
|
63
|
-
|
|
60
|
+
set(x, __CLASS__, clsName);
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
static deserializeClass(x) {
|
|
67
|
-
const clsName =
|
|
64
|
+
const clsName = get(x, __CLASS__, null);
|
|
68
65
|
let constructor = null;
|
|
69
66
|
if (this.TYPES[clsName]) {
|
|
70
67
|
constructor = this.TYPES[clsName];
|
|
71
68
|
if (constructor) {
|
|
72
69
|
const y = Reflect.construct(constructor, []);
|
|
73
|
-
|
|
74
|
-
delete y[
|
|
70
|
+
assign(y, x);
|
|
71
|
+
delete y[__CLASS__];
|
|
75
72
|
return y;
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
return x;
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
|
-
exports.Serializer = Serializer;
|
|
82
78
|
Serializer.TYPES = {};
|
|
83
79
|
//# sourceMappingURL=Serializer.js.map
|
package/utils/Serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serializer.js","sourceRoot":"","sources":["../../../src/utils/Serializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Serializer.js","sourceRoot":"","sources":["../../../src/utils/Serializer.ts"],"names":[],"mappings":"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