@allgemein/base 1.9.1 → 1.10.1
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 -2
- package/Constants.js +5 -8
- 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 -27
- 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 +2 -6
- 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 +1465 -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 -7
- package/locking/Semaphore.js.map +1 -1
- package/package.json +2 -2
- package/shared.d.ts +18 -17
- package/shared.js +18 -41
- 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 -46
- 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 -10
- 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 -65
- 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/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)) {
|
|
@@ -168,7 +163,6 @@ class PlatformUtils {
|
|
|
168
163
|
}
|
|
169
164
|
str = fn(str);
|
|
170
165
|
for (const _m in cache) {
|
|
171
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
172
166
|
if (cache.hasOwnProperty(_m)) {
|
|
173
167
|
str = str.replace(_m, cache[_m]);
|
|
174
168
|
}
|
|
@@ -180,17 +174,17 @@ class PlatformUtils {
|
|
|
180
174
|
* Returns the filename only (without extension)
|
|
181
175
|
*/
|
|
182
176
|
static filename(pathStr) {
|
|
183
|
-
const base =
|
|
177
|
+
const base = basename(pathStr);
|
|
184
178
|
if (/\$\{.*\}/.test(base)) {
|
|
185
|
-
return this.withoutInterpolation(base, (str) => str.replace(new RegExp('\\' +
|
|
179
|
+
return this.withoutInterpolation(base, (str) => str.replace(new RegExp('\\' + extname(str) + '$'), ''));
|
|
186
180
|
}
|
|
187
|
-
return base.replace(new RegExp('\\' +
|
|
181
|
+
return base.replace(new RegExp('\\' + extname(base) + '$'), '');
|
|
188
182
|
}
|
|
189
183
|
/**
|
|
190
184
|
* Returns the dirname of the file
|
|
191
185
|
*/
|
|
192
186
|
static dirname(pathStr) {
|
|
193
|
-
return
|
|
187
|
+
return dirname(pathStr);
|
|
194
188
|
}
|
|
195
189
|
static testForFilePath(path) {
|
|
196
190
|
return FILEPATH.test(path);
|
|
@@ -199,7 +193,7 @@ class PlatformUtils {
|
|
|
199
193
|
* Normalizes given Does "normalize".
|
|
200
194
|
*/
|
|
201
195
|
static pathNormalize(pathStr) {
|
|
202
|
-
return
|
|
196
|
+
return normalize(pathStr);
|
|
203
197
|
}
|
|
204
198
|
/**
|
|
205
199
|
* Normalizes given Does "normalize".
|
|
@@ -211,10 +205,10 @@ class PlatformUtils {
|
|
|
211
205
|
* Test if path is absolute.
|
|
212
206
|
*/
|
|
213
207
|
static isAbsolute(pathStr) {
|
|
214
|
-
return
|
|
208
|
+
return isAbsolute(pathStr);
|
|
215
209
|
}
|
|
216
210
|
static directory(file) {
|
|
217
|
-
return
|
|
211
|
+
return dirname(file);
|
|
218
212
|
}
|
|
219
213
|
/**
|
|
220
214
|
* Gets environment variable.
|
|
@@ -224,47 +218,47 @@ class PlatformUtils {
|
|
|
224
218
|
}
|
|
225
219
|
static getHostPath() {
|
|
226
220
|
if (process.platform === 'win32') {
|
|
227
|
-
return
|
|
221
|
+
return join(process.env.SYSTEMROOT, '/System32/drivers/etc/hosts');
|
|
228
222
|
}
|
|
229
223
|
return '/etc/hosts';
|
|
230
224
|
}
|
|
231
225
|
static getHostFileContent() {
|
|
232
|
-
return
|
|
226
|
+
return readFileSync(this.getHostPath(), { encoding: 'utf-8' });
|
|
233
227
|
}
|
|
234
|
-
static mkdir(targetDir, _sep =
|
|
235
|
-
const initDir =
|
|
228
|
+
static mkdir(targetDir, _sep = sep) {
|
|
229
|
+
const initDir = isAbsolute(targetDir) ? _sep : '';
|
|
236
230
|
targetDir.split(_sep).reduce((parentDir, childDir) => {
|
|
237
|
-
const curDir =
|
|
238
|
-
if (!
|
|
239
|
-
|
|
231
|
+
const curDir = resolve(parentDir, childDir);
|
|
232
|
+
if (!existsSync(curDir)) {
|
|
233
|
+
mkdirSync(curDir);
|
|
240
234
|
}
|
|
241
235
|
return curDir;
|
|
242
236
|
}, initDir);
|
|
243
237
|
return true;
|
|
244
238
|
}
|
|
245
239
|
static readFile(filename) {
|
|
246
|
-
return
|
|
240
|
+
return FileUtils.readFile(filename);
|
|
247
241
|
}
|
|
248
242
|
static readFileSync(filename) {
|
|
249
|
-
return
|
|
243
|
+
return FileUtils.readFileSync(filename);
|
|
250
244
|
}
|
|
251
245
|
static deleteFile(dir, file) {
|
|
252
|
-
return
|
|
246
|
+
return FileUtils.deleteFile(dir, file);
|
|
253
247
|
}
|
|
254
248
|
static deleteDirectory(dir) {
|
|
255
249
|
return new Promise(function (resolve, reject) {
|
|
256
|
-
|
|
250
|
+
access(dir, function (err) {
|
|
257
251
|
if (err) {
|
|
258
252
|
return reject(err);
|
|
259
253
|
}
|
|
260
|
-
|
|
254
|
+
readdir(dir, function (err, files) {
|
|
261
255
|
if (err) {
|
|
262
256
|
return reject(err);
|
|
263
257
|
}
|
|
264
258
|
Promise.all(files.map(function (file) {
|
|
265
259
|
return PlatformUtils.deleteFile(dir, file);
|
|
266
260
|
})).then(function () {
|
|
267
|
-
|
|
261
|
+
rmdir(dir, function (err) {
|
|
268
262
|
if (err) {
|
|
269
263
|
return reject(err);
|
|
270
264
|
}
|
|
@@ -276,7 +270,6 @@ class PlatformUtils {
|
|
|
276
270
|
});
|
|
277
271
|
}
|
|
278
272
|
}
|
|
279
|
-
exports.PlatformUtils = PlatformUtils;
|
|
280
273
|
/**
|
|
281
274
|
* Type of the currently running platform.
|
|
282
275
|
*/
|
|
@@ -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,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAEzC,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAGhD,MAAM,QAAQ,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,+DAA+D,CAAC;AAEjI;;GAEG;AACH,MAAM,OAAO,aAAa;IASxB;;OA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AK;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;CAGF;AArTC;;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,iB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AAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,SAAiB,EAAE,GAAG,GAAW,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;CAGF;AA3MC;;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
|