jopi-toolkit 3.0.15 → 3.1.22
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/dist/jk_app/common.d.ts +8 -5
- package/dist/jk_app/common.js +35 -19
- package/dist/jk_app/common.js.map +1 -1
- package/dist/jk_data/index.d.ts +32 -17
- package/dist/jk_data/index.js +55 -25
- package/dist/jk_data/index.js.map +1 -1
- package/dist/jk_events/index.d.ts +2 -0
- package/dist/jk_events/index.js +29 -7
- package/dist/jk_events/index.js.map +1 -1
- package/dist/jk_fs/jBundler_ifBrowser.d.ts +2 -0
- package/dist/jk_fs/jBundler_ifBrowser.js +6 -0
- package/dist/jk_fs/jBundler_ifBrowser.js.map +1 -1
- package/dist/jk_fs/jBundler_ifServer.d.ts +13 -11
- package/dist/jk_fs/jBundler_ifServer.js +53 -7
- package/dist/jk_fs/jBundler_ifServer.js.map +1 -1
- package/dist/jk_logs/jBundler_ifServer.js +5 -0
- package/dist/jk_logs/jBundler_ifServer.js.map +1 -1
- package/dist/jk_process/jBundler_ifServer.d.ts +4 -0
- package/dist/jk_process/jBundler_ifServer.js +31 -0
- package/dist/jk_process/jBundler_ifServer.js.map +1 -1
- package/dist/jk_schemas/index.d.ts +82 -6
- package/dist/jk_schemas/index.js +48 -5
- package/dist/jk_schemas/index.js.map +1 -1
- package/dist/jk_term/index.d.ts +2 -0
- package/dist/jk_term/index.js +2 -0
- package/dist/jk_term/index.js.map +1 -1
- package/dist/jk_tools/jBundler_ifServer.js +19 -7
- package/dist/jk_tools/jBundler_ifServer.js.map +1 -1
- package/package.json +26 -18
- package/src/jk_app/common.js +40 -24
- package/src/jk_app/common.ts +41 -26
- package/src/jk_data/index.js +68 -30
- package/src/jk_data/index.ts +86 -49
- package/src/jk_events/index.js +15 -7
- package/src/jk_events/index.ts +50 -19
- package/src/jk_fs/jBundler_ifBrowser.ts +8 -0
- package/src/jk_fs/jBundler_ifServer.ts +54 -7
- package/src/jk_logs/jBundler_ifServer.ts +6 -0
- package/src/{jk_fs → jk_process}/index.js +0 -1
- package/src/jk_process/jBundler_ifServer.ts +35 -1
- package/src/jk_schemas/index.js +50 -5
- package/src/jk_schemas/index.ts +140 -11
- package/src/jk_term/index.js +2 -0
- package/src/jk_term/index.ts +3 -0
- package/src/jk_tools/jBundler_ifServer.ts +19 -6
- package/src/jk_what/jBundler_ifServer.js +8 -5
- package/dist/jk_schemas/jkSchemas.d.ts +0 -188
- package/dist/jk_schemas/jkSchemas.js +0 -257
- package/dist/jk_schemas/jkSchemas.js.map +0 -1
- package/dist/jk_translate/index.d.ts +0 -21
- package/dist/jk_translate/index.js +0 -56
- package/dist/jk_translate/index.js.map +0 -1
- package/src/jk_fs/common.js +0 -1
- package/src/jk_fs/jBundler_ifServer.js +0 -729
- package/src/jk_translate/index.js +0 -56
- package/src/jk_translate/index.ts +0 -85
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.
|
|
2
|
+
"version": "3.1.22",
|
|
3
3
|
"name": "jopi-toolkit",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/johanpiquet/jopi-toolkit",
|
|
@@ -17,96 +17,104 @@
|
|
|
17
17
|
"src"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build:priority:1": "npx tsc",
|
|
21
|
-
"clean": "rm -rf ./dist .turbo tsconfig.tsbuildinfo",
|
|
22
|
-
"tsc": "tsc",
|
|
23
|
-
"bun-publish": "npx tsc && bun publish",
|
|
24
|
-
"untrack": "git rm -r --cached -- ./dist/**;",
|
|
25
20
|
"jopiLink": "npx jopi-mono link-add",
|
|
26
|
-
"
|
|
21
|
+
"bunLink": "bun link",
|
|
22
|
+
"dev:build": "tsc",
|
|
23
|
+
"dev:tsc-watch": "tsc --watch",
|
|
24
|
+
"dev:tsc-check": "tsc --noEmit"
|
|
27
25
|
},
|
|
28
|
-
"
|
|
26
|
+
"dependencies": {
|
|
29
27
|
"@types/adm-zip": "^0.5.7",
|
|
30
28
|
"@types/bun": "latest",
|
|
31
29
|
"@types/mime-types": "latest",
|
|
32
|
-
"@types/node": "latest"
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
30
|
+
"@types/node": "latest",
|
|
35
31
|
"@types/ws": "^8.18.1",
|
|
36
32
|
"adm-zip": "^0.5.9",
|
|
37
33
|
"mime-types": "^3.0.1",
|
|
38
34
|
"ws": "^8.18.3"
|
|
39
35
|
},
|
|
40
|
-
"publishedDate": "12/
|
|
41
|
-
"publicPublishedDate": "12/
|
|
36
|
+
"publishedDate": "1/12/2026",
|
|
37
|
+
"publicPublishedDate": "1/12/2026",
|
|
42
38
|
"exports": {
|
|
43
39
|
"./jk_schema": {
|
|
40
|
+
"types": "./src/jk_schemas/index.ts",
|
|
44
41
|
"bun": "./src/jk_schemas/index.ts",
|
|
45
42
|
"default": "./dist/jk_schemas/index.js"
|
|
46
43
|
},
|
|
47
44
|
"./jk_tools": {
|
|
45
|
+
"types": "./src/jk_tools/index.ts",
|
|
48
46
|
"bun": "./src/jk_tools/index.ts",
|
|
49
47
|
"default": "./dist/jk_tools/index.js"
|
|
50
48
|
},
|
|
51
|
-
"./jk_translate": {
|
|
52
|
-
"bun": "./src/jk_translate/index.ts",
|
|
53
|
-
"default": "./dist/jk_translate/index.js"
|
|
54
|
-
},
|
|
55
49
|
"./jk_process": {
|
|
50
|
+
"types": "./src/jk_process/index.ts",
|
|
56
51
|
"bun": "./src/jk_process/index.ts",
|
|
57
52
|
"default": "./dist/jk_process/index.js"
|
|
58
53
|
},
|
|
59
54
|
"./jk_data": {
|
|
55
|
+
"types": "./src/jk_data/index.ts",
|
|
60
56
|
"bun": "./src/jk_data/index.ts",
|
|
61
57
|
"default": "./dist/jk_data/index.js"
|
|
62
58
|
},
|
|
63
59
|
"./jk_what": {
|
|
60
|
+
"types": "./src/jk_what/index.ts",
|
|
64
61
|
"bun": "./src/jk_what/index.ts",
|
|
65
62
|
"default": "./dist/jk_what/index.js"
|
|
66
63
|
},
|
|
67
64
|
"./jk_os": {
|
|
65
|
+
"types": "./src/jk_os/index.ts",
|
|
68
66
|
"bun": "./src/jk_os/index.ts",
|
|
69
67
|
"default": "./dist/jk_os/index.js"
|
|
70
68
|
},
|
|
71
69
|
"./jk_crypto": {
|
|
70
|
+
"types": "./src/jk_crypto/index.ts",
|
|
72
71
|
"bun": "./src/jk_crypto/index.ts",
|
|
73
72
|
"default": "./dist/jk_crypto/index.js"
|
|
74
73
|
},
|
|
75
74
|
"./jk_thread": {
|
|
75
|
+
"types": "./src/jk_thread/index.ts",
|
|
76
76
|
"bun": "./src/jk_thread/index.ts",
|
|
77
77
|
"default": "./dist/jk_thread/index.js"
|
|
78
78
|
},
|
|
79
79
|
"./jk_events": {
|
|
80
|
+
"types": "./src/jk_events/index.ts",
|
|
80
81
|
"bun": "./src/jk_events/index.ts",
|
|
81
82
|
"default": "./dist/jk_events/index.js"
|
|
82
83
|
},
|
|
83
84
|
"./jk_fs": {
|
|
85
|
+
"types": "./src/jk_fs/index.ts",
|
|
84
86
|
"bun": "./src/jk_fs/index.ts",
|
|
85
87
|
"default": "./dist/jk_fs/index.js"
|
|
86
88
|
},
|
|
87
89
|
"./jk_timer": {
|
|
90
|
+
"types": "./src/jk_timer/index.ts",
|
|
88
91
|
"bun": "./src/jk_timer/index.ts",
|
|
89
92
|
"default": "./dist/jk_timer/index.js"
|
|
90
93
|
},
|
|
91
94
|
"./jk_term": {
|
|
95
|
+
"types": "./src/jk_term/index.ts",
|
|
92
96
|
"bun": "./src/jk_term/index.ts",
|
|
93
97
|
"default": "./dist/jk_term/index.js"
|
|
94
98
|
},
|
|
95
99
|
"./jk_app": {
|
|
100
|
+
"types": "./src/jk_app/index.ts",
|
|
96
101
|
"bun": "./src/jk_app/index.ts",
|
|
97
102
|
"default": "./dist/jk_app/index.js"
|
|
98
103
|
},
|
|
99
104
|
"./jk_compress": {
|
|
105
|
+
"types": "./src/jk_compress/index.ts",
|
|
100
106
|
"bun": "./src/jk_compress/index.ts",
|
|
101
107
|
"default": "./dist/jk_compress/index.js"
|
|
102
108
|
},
|
|
103
109
|
"./jk_webSocket": {
|
|
110
|
+
"types": "./src/jk_webSocket/index.ts",
|
|
104
111
|
"bun": "./src/jk_webSocket/index.ts",
|
|
105
112
|
"default": "./dist/jk_webSocket/index.js"
|
|
106
113
|
},
|
|
107
114
|
"./jk_logs": {
|
|
115
|
+
"types": "./src/jk_logs/index.ts",
|
|
108
116
|
"bun": "./src/jk_logs/index.ts",
|
|
109
117
|
"default": "./dist/jk_logs/index.js"
|
|
110
118
|
}
|
|
111
119
|
}
|
|
112
|
-
}
|
|
120
|
+
}
|
package/src/jk_app/common.js
CHANGED
|
@@ -258,31 +258,47 @@ var gIsExited = false;
|
|
|
258
258
|
var gTempDir;
|
|
259
259
|
//endregion
|
|
260
260
|
//region Resolving
|
|
261
|
-
export function findNodePackageDir(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
261
|
+
export function findNodePackageDir(packageName_1) {
|
|
262
|
+
return __awaiter(this, arguments, void 0, function (packageName, searchFromDir) {
|
|
263
|
+
var currentDir, packagePath, parentDir;
|
|
264
|
+
if (searchFromDir === void 0) { searchFromDir = getCodeSourceDirHint(); }
|
|
265
|
+
return __generator(this, function (_a) {
|
|
266
|
+
switch (_a.label) {
|
|
267
|
+
case 0:
|
|
268
|
+
currentDir = jk_fs.resolve(searchFromDir);
|
|
269
|
+
_a.label = 1;
|
|
270
|
+
case 1:
|
|
271
|
+
if (!true) return [3 /*break*/, 3];
|
|
272
|
+
packagePath = jk_fs.join(currentDir, 'node_modules', packageName);
|
|
273
|
+
return [4 /*yield*/, jk_fs.isDirectory(packagePath)];
|
|
274
|
+
case 2:
|
|
275
|
+
if (_a.sent())
|
|
276
|
+
return [2 /*return*/, packagePath];
|
|
277
|
+
parentDir = jk_fs.dirname(currentDir);
|
|
278
|
+
if (parentDir === currentDir)
|
|
279
|
+
return [3 /*break*/, 3];
|
|
280
|
+
currentDir = parentDir;
|
|
281
|
+
return [3 /*break*/, 1];
|
|
282
|
+
case 3: return [2 /*return*/, undefined];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
279
286
|
}
|
|
280
|
-
export function requireNodePackageDir(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
287
|
+
export function requireNodePackageDir(packageName_1) {
|
|
288
|
+
return __awaiter(this, arguments, void 0, function (packageName, searchFromDir) {
|
|
289
|
+
var pkgDir;
|
|
290
|
+
if (searchFromDir === void 0) { searchFromDir = getCodeSourceDirHint(); }
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
switch (_a.label) {
|
|
293
|
+
case 0: return [4 /*yield*/, findNodePackageDir(packageName, searchFromDir)];
|
|
294
|
+
case 1:
|
|
295
|
+
pkgDir = _a.sent();
|
|
296
|
+
if (!pkgDir)
|
|
297
|
+
throw new Error("Package '" + packageName + "' not found");
|
|
298
|
+
return [2 /*return*/, pkgDir];
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
286
302
|
}
|
|
287
303
|
export function findPackageJsonDir(searchFromDir) {
|
|
288
304
|
if (searchFromDir === void 0) { searchFromDir = getCodeSourceDirHint(); }
|
package/src/jk_app/common.ts
CHANGED
|
@@ -164,6 +164,10 @@ export function getTempDir(): string {
|
|
|
164
164
|
return gTempDir;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
export function setTempDir(dir: string) {
|
|
168
|
+
gTempDir = dir;
|
|
169
|
+
}
|
|
170
|
+
|
|
167
171
|
let gIsExited = false;
|
|
168
172
|
let gTempDir: string|undefined;
|
|
169
173
|
|
|
@@ -171,43 +175,47 @@ let gTempDir: string|undefined;
|
|
|
171
175
|
|
|
172
176
|
//region Resolving
|
|
173
177
|
|
|
174
|
-
export function findNodePackageDir(packageName: string,
|
|
175
|
-
let currentDir = jk_fs.
|
|
178
|
+
export async function findNodePackageDir(packageName: string, searchFromDir = getCodeSourceDirHint()): Promise<string | undefined> {
|
|
179
|
+
let currentDir = jk_fs.resolve(searchFromDir);
|
|
176
180
|
|
|
177
181
|
while (true) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (jk_fs.isDirectorySync(packagePath)) {
|
|
181
|
-
if (useLinuxPathFormat) return jk_fs.win32ToLinuxPath(packagePath);
|
|
182
|
-
return packagePath;
|
|
183
|
-
}
|
|
184
|
-
|
|
182
|
+
let packagePath = jk_fs.join(currentDir, 'node_modules', packageName);
|
|
183
|
+
if (await jk_fs.isDirectory(packagePath)) return packagePath;
|
|
185
184
|
const parentDir = jk_fs.dirname(currentDir);
|
|
186
|
-
|
|
187
|
-
// Reached root directory
|
|
188
|
-
if (parentDir === currentDir) {
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
|
|
185
|
+
if (parentDir === currentDir) break;
|
|
192
186
|
currentDir = parentDir;
|
|
193
187
|
}
|
|
194
188
|
|
|
195
189
|
return undefined;
|
|
196
190
|
}
|
|
197
191
|
|
|
198
|
-
export function requireNodePackageDir(packageName: string,
|
|
199
|
-
let pkgDir = findNodePackageDir(packageName,
|
|
192
|
+
export async function requireNodePackageDir(packageName: string, searchFromDir = getCodeSourceDirHint()): Promise<string> {
|
|
193
|
+
let pkgDir = await findNodePackageDir(packageName, searchFromDir);
|
|
200
194
|
if (!pkgDir) throw new Error("Package '" + packageName + "' not found");
|
|
201
195
|
return pkgDir;
|
|
202
196
|
}
|
|
203
197
|
|
|
204
|
-
export function
|
|
198
|
+
export function findRequiredPackageJsonDir(searchFromDir = getCodeSourceDirHint()): string {
|
|
199
|
+
let pkgJsonPath = findRequiredPackageJson(searchFromDir);
|
|
200
|
+
return jk_fs.dirname(pkgJsonPath);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function findPackageJsonDir(searchFromDir = getCodeSourceDirHint()): string|undefined {
|
|
205
204
|
let pkgJsonPath = findPackageJson(searchFromDir);
|
|
205
|
+
if (!pkgJsonPath) return undefined;
|
|
206
206
|
return jk_fs.dirname(pkgJsonPath);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
export function
|
|
210
|
-
|
|
209
|
+
export function findRequiredPackageJson(searchFromDir = getCodeSourceDirHint()): string {
|
|
210
|
+
let res = findPackageJson(searchFromDir);
|
|
211
|
+
if (!res) throw new Error("No package.json found.");
|
|
212
|
+
return res;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function findPackageJson(searchFromDir = getCodeSourceDirHint()): string|undefined {
|
|
216
|
+
if (!searchFromDir && (gPackageJsonPath!==undefined)) {
|
|
217
|
+
return gPackageJsonPath;
|
|
218
|
+
}
|
|
211
219
|
|
|
212
220
|
let currentDir = searchFromDir;
|
|
213
221
|
|
|
@@ -224,7 +232,7 @@ export function findPackageJson(searchFromDir = getCodeSourceDirHint()): string
|
|
|
224
232
|
currentDir = parentDir;
|
|
225
233
|
}
|
|
226
234
|
|
|
227
|
-
|
|
235
|
+
return undefined;
|
|
228
236
|
}
|
|
229
237
|
//
|
|
230
238
|
let gPackageJsonPath: string|undefined;
|
|
@@ -246,7 +254,7 @@ export function getCodeSourceDirHint() {
|
|
|
246
254
|
export function getSourceCodeDir(): string {
|
|
247
255
|
if (gSourceCodeDir) return gSourceCodeDir;
|
|
248
256
|
|
|
249
|
-
let pkgJsonPath =
|
|
257
|
+
let pkgJsonPath = findRequiredPackageJson();
|
|
250
258
|
let dirName = jk_fs.join(jk_fs.dirname(pkgJsonPath), "src");
|
|
251
259
|
|
|
252
260
|
if (jk_fs.isDirectorySync(dirName)) {
|
|
@@ -269,7 +277,7 @@ export function getCompiledCodeDir(): string {
|
|
|
269
277
|
return gCompiledSourcesDir = sourceCodeDir;
|
|
270
278
|
}
|
|
271
279
|
|
|
272
|
-
let pkgJsonPath =
|
|
280
|
+
let pkgJsonPath = findRequiredPackageJson();
|
|
273
281
|
|
|
274
282
|
let rootDir = jk_fs.dirname(pkgJsonPath);
|
|
275
283
|
|
|
@@ -283,7 +291,7 @@ export function getCompiledCodeDir(): string {
|
|
|
283
291
|
return rootDir;
|
|
284
292
|
}
|
|
285
293
|
|
|
286
|
-
export function getCompiledFilePathFor(sourceFilePath: string): string {
|
|
294
|
+
export function getCompiledFilePathFor(sourceFilePath: string, replaceExtension = true): string {
|
|
287
295
|
const compiledCodeDir = getCompiledCodeDir();
|
|
288
296
|
const sourceCodeDir = getSourceCodeDir();
|
|
289
297
|
|
|
@@ -293,9 +301,16 @@ export function getCompiledFilePathFor(sourceFilePath: string): string {
|
|
|
293
301
|
|
|
294
302
|
let filePath = sourceFilePath.substring(sourceCodeDir.length);
|
|
295
303
|
|
|
296
|
-
if (
|
|
304
|
+
if (replaceExtension && !filePath.endsWith(".js")) {
|
|
297
305
|
let idx = filePath.lastIndexOf(".");
|
|
298
|
-
|
|
306
|
+
let ext = filePath.substring(idx);
|
|
307
|
+
|
|
308
|
+
// This avoid case where there is no extension but a punct in the name.
|
|
309
|
+
// Ex: importing "@/lib/jopijs.menu.getManager"
|
|
310
|
+
//
|
|
311
|
+
if ((ext === ".ts") || (ext === ".tsx")) {
|
|
312
|
+
filePath = filePath.substring(0, idx) + ".js";
|
|
313
|
+
}
|
|
299
314
|
}
|
|
300
315
|
|
|
301
316
|
return jk_fs.join(compiledCodeDir, filePath);
|
package/src/jk_data/index.js
CHANGED
|
@@ -34,21 +34,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.rows = rows;
|
|
41
|
-
}
|
|
42
|
-
JDataRowSource_UseArray.prototype.read = function (params) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
return __generator(this, function (_a) {
|
|
45
|
-
return [2 /*return*/, simpleRowArrayFilter(this.rows, params)];
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
return JDataRowSource_UseArray;
|
|
50
|
-
}());
|
|
51
|
-
export { JDataRowSource_UseArray };
|
|
37
|
+
/**
|
|
38
|
+
* Filter the row content according to rules.
|
|
39
|
+
*/
|
|
52
40
|
export function simpleRowArrayFilter(rows, params) {
|
|
53
41
|
// > Apply filter.
|
|
54
42
|
if (params.filter) {
|
|
@@ -74,10 +62,9 @@ export function simpleRowArrayFilter(rows, params) {
|
|
|
74
62
|
}
|
|
75
63
|
// > Apply sorting.
|
|
76
64
|
if (params.sorting && params.sorting.length) {
|
|
77
|
-
debugger;
|
|
78
65
|
var sorting = params.sorting[0];
|
|
79
|
-
var sortField_1 = sorting.
|
|
80
|
-
var
|
|
66
|
+
var sortField_1 = sorting.id;
|
|
67
|
+
var sortDesc_1 = sorting.desc;
|
|
81
68
|
rows = rows.sort(function (a, b) {
|
|
82
69
|
var av = a[sortField_1];
|
|
83
70
|
var bv = b[sortField_1];
|
|
@@ -88,30 +75,81 @@ export function simpleRowArrayFilter(rows, params) {
|
|
|
88
75
|
var avIsNumber = typeof av === "number";
|
|
89
76
|
var bvIsNumber = typeof bv === "number";
|
|
90
77
|
if (avIsNumber && bvIsNumber) {
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
78
|
+
if (sortDesc_1) {
|
|
79
|
+
return bv - av;
|
|
93
80
|
}
|
|
94
81
|
else {
|
|
95
|
-
return
|
|
82
|
+
return av - bv;
|
|
96
83
|
}
|
|
97
84
|
}
|
|
98
85
|
else {
|
|
99
86
|
var avStr = String(av);
|
|
100
87
|
var bvStr = String(bv);
|
|
101
|
-
if (
|
|
102
|
-
return
|
|
88
|
+
if (sortDesc_1) {
|
|
89
|
+
return bvStr.localeCompare(avStr);
|
|
103
90
|
}
|
|
104
91
|
else {
|
|
105
|
-
return
|
|
92
|
+
return avStr.localeCompare(bvStr);
|
|
106
93
|
}
|
|
107
94
|
}
|
|
108
95
|
});
|
|
109
96
|
}
|
|
110
97
|
var totalWithoutPagination = rows.length;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
98
|
+
var offset = 0;
|
|
99
|
+
if (params.page) {
|
|
100
|
+
offset = params.page.pageIndex * params.page.pageSize;
|
|
101
|
+
rows = rows.slice(offset, offset + params.page.pageSize);
|
|
102
|
+
}
|
|
103
|
+
return { rows: rows, total: totalWithoutPagination, offset: offset };
|
|
117
104
|
}
|
|
105
|
+
var JTableDs_UseArray = /** @class */ (function () {
|
|
106
|
+
function JTableDs_UseArray(name, schema, rows) {
|
|
107
|
+
this.name = name;
|
|
108
|
+
this.schema = schema;
|
|
109
|
+
this.rows = rows;
|
|
110
|
+
}
|
|
111
|
+
JTableDs_UseArray.prototype.read = function (params) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
return [2 /*return*/, simpleRowArrayFilter(this.rows, params)];
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
return JTableDs_UseArray;
|
|
119
|
+
}());
|
|
120
|
+
export { JTableDs_UseArray };
|
|
121
|
+
var JTableDs_HttpProxy = /** @class */ (function () {
|
|
122
|
+
function JTableDs_HttpProxy(name, url, schema) {
|
|
123
|
+
this.name = name;
|
|
124
|
+
this.url = url;
|
|
125
|
+
this.schema = schema;
|
|
126
|
+
}
|
|
127
|
+
JTableDs_HttpProxy.prototype.read = function (params) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var toSend, res, asJson;
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
toSend = { dsName: this.name, read: params };
|
|
134
|
+
return [4 /*yield*/, fetch(this.url, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: { "Content-Type": "application/json" },
|
|
137
|
+
body: JSON.stringify(toSend)
|
|
138
|
+
})];
|
|
139
|
+
case 1:
|
|
140
|
+
res = _a.sent();
|
|
141
|
+
if (res.status !== 200) {
|
|
142
|
+
throw new Error("Error while reading data source \"".concat(this.name, "\""));
|
|
143
|
+
}
|
|
144
|
+
return [4 /*yield*/, res.json()];
|
|
145
|
+
case 2:
|
|
146
|
+
asJson = _a.sent();
|
|
147
|
+
return [2 /*return*/, asJson];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
return JTableDs_HttpProxy;
|
|
153
|
+
}());
|
|
154
|
+
export { JTableDs_HttpProxy };
|
|
155
|
+
//endregion
|
package/src/jk_data/index.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import {type Schema} from "jopi-toolkit/jk_schema";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
field: string;
|
|
5
|
-
direction: "asc" | "desc";
|
|
6
|
-
}
|
|
3
|
+
//region Rows Arrays
|
|
7
4
|
|
|
8
|
-
export interface
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
export interface JFieldSorting {
|
|
6
|
+
id: string;
|
|
7
|
+
desc: boolean;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export interface JFieldFilter {
|
|
@@ -27,39 +24,27 @@ export type JFieldConstraintType =
|
|
|
27
24
|
| "$nin" // Not in an array of values
|
|
28
25
|
| "$like" // Like search %endsWith or startsWith%
|
|
29
26
|
|
|
30
|
-
export interface
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
filter?: JRowsFilter;
|
|
35
|
-
sorting?: JFieldSorting[];
|
|
36
|
-
fieldFilters?: Record<string, JFieldFilter[]>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface JDataRowSource_ReadParams extends JRowArrayFilter {
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface JDataRowSource_ReadResult {
|
|
43
|
-
rows: any[];
|
|
44
|
-
total?: number;
|
|
45
|
-
offset?: number;
|
|
27
|
+
export interface JRowsFilter {
|
|
28
|
+
field?: string;
|
|
29
|
+
value: string;
|
|
46
30
|
}
|
|
47
31
|
|
|
48
|
-
export interface
|
|
49
|
-
|
|
50
|
-
|
|
32
|
+
export interface JPageExtraction {
|
|
33
|
+
pageIndex: number;
|
|
34
|
+
pageSize: number;
|
|
51
35
|
}
|
|
52
36
|
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return simpleRowArrayFilter(this.rows, params);
|
|
59
|
-
}
|
|
37
|
+
export interface JRowArrayFilter {
|
|
38
|
+
page?: JPageExtraction;
|
|
39
|
+
filter?: JRowsFilter;
|
|
40
|
+
sorting?: JFieldSorting[];
|
|
41
|
+
fieldFilters?: Record<string, JFieldFilter[]>;
|
|
60
42
|
}
|
|
61
43
|
|
|
62
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Filter the row content according to rules.
|
|
46
|
+
*/
|
|
47
|
+
export function simpleRowArrayFilter(rows: any[], params: JRowArrayFilter): JTableDs_ReadResult {
|
|
63
48
|
// > Apply filter.
|
|
64
49
|
|
|
65
50
|
if (params.filter) {
|
|
@@ -84,10 +69,9 @@ export function simpleRowArrayFilter(rows: any[], params: JRowArrayFilter): JDat
|
|
|
84
69
|
// > Apply sorting.
|
|
85
70
|
|
|
86
71
|
if (params.sorting && params.sorting.length) {
|
|
87
|
-
debugger;
|
|
88
72
|
const sorting = params.sorting[0];
|
|
89
|
-
const sortField = sorting.
|
|
90
|
-
const
|
|
73
|
+
const sortField = sorting.id;
|
|
74
|
+
const sortDesc = sorting.desc;
|
|
91
75
|
|
|
92
76
|
rows = rows.sort((a, b) => {
|
|
93
77
|
let av = a[sortField];
|
|
@@ -100,30 +84,83 @@ export function simpleRowArrayFilter(rows: any[], params: JRowArrayFilter): JDat
|
|
|
100
84
|
const bvIsNumber = typeof bv === "number";
|
|
101
85
|
|
|
102
86
|
if (avIsNumber && bvIsNumber) {
|
|
103
|
-
if (
|
|
104
|
-
return av - bv;
|
|
105
|
-
} else {
|
|
87
|
+
if (sortDesc) {
|
|
106
88
|
return bv - av;
|
|
89
|
+
} else {
|
|
90
|
+
return av - bv;
|
|
107
91
|
}
|
|
108
92
|
} else {
|
|
109
93
|
const avStr = String(av);
|
|
110
94
|
const bvStr = String(bv);
|
|
111
95
|
|
|
112
|
-
if (
|
|
113
|
-
return avStr.localeCompare(bvStr);
|
|
114
|
-
} else {
|
|
96
|
+
if (sortDesc) {
|
|
115
97
|
return bvStr.localeCompare(avStr);
|
|
98
|
+
} else {
|
|
99
|
+
return avStr.localeCompare(bvStr);
|
|
116
100
|
}
|
|
117
101
|
}
|
|
118
102
|
});
|
|
119
103
|
}
|
|
120
104
|
|
|
121
105
|
const totalWithoutPagination = rows.length;
|
|
106
|
+
let offset = 0;
|
|
107
|
+
|
|
108
|
+
if (params.page) {
|
|
109
|
+
offset = params.page.pageIndex * params.page.pageSize;
|
|
110
|
+
rows = rows.slice(offset, offset + params.page.pageSize);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {rows, total: totalWithoutPagination, offset};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//endregion
|
|
122
117
|
|
|
123
|
-
|
|
118
|
+
//region JTableDs
|
|
124
119
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
export interface JTableDs_ReadParams extends JRowArrayFilter {
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface JTableDs_ReadResult {
|
|
124
|
+
rows: any[];
|
|
125
|
+
total?: number;
|
|
126
|
+
offset?: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface JTableDs {
|
|
130
|
+
get name(): string;
|
|
131
|
+
get schema(): Schema;
|
|
132
|
+
read(params: JTableDs_ReadParams): Promise<JTableDs_ReadResult>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export class JTableDs_UseArray implements JTableDs {
|
|
136
|
+
public constructor(public readonly name: string, public readonly schema: Schema, private readonly rows: any[]) {
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async read(params: JTableDs_ReadParams): Promise<JTableDs_ReadResult> {
|
|
140
|
+
return simpleRowArrayFilter(this.rows, params);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export class JTableDs_HttpProxy implements JTableDs {
|
|
145
|
+
public constructor(public readonly name: string, private readonly url: string, public readonly schema: Schema) {
|
|
128
146
|
}
|
|
129
|
-
|
|
147
|
+
|
|
148
|
+
async read(params: JTableDs_ReadParams): Promise<JTableDs_ReadResult> {
|
|
149
|
+
let toSend = {dsName: this.name, read: params};
|
|
150
|
+
|
|
151
|
+
let res = await fetch(this.url, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: {"Content-Type": "application/json"},
|
|
154
|
+
body: JSON.stringify(toSend)
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (res.status !== 200) {
|
|
158
|
+
throw new Error(`Error while reading data source "${this.name}"`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let asJson = await res.json();
|
|
162
|
+
return asJson as JTableDs_ReadResult;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
//endregion
|