jopi-toolkit 3.1.32 → 3.1.34

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.
Files changed (66) hide show
  1. package/dist/jk_app/common.d.ts +1 -0
  2. package/dist/jk_app/common.js +9 -2
  3. package/dist/jk_app/common.js.map +1 -1
  4. package/dist/jk_data/browserActions.d.ts +8 -0
  5. package/dist/jk_data/browserActions.js +9 -0
  6. package/dist/jk_data/browserActions.js.map +1 -0
  7. package/dist/jk_data/bundler_ifServer.d.ts +2 -0
  8. package/dist/jk_data/bundler_ifServer.js +2 -0
  9. package/dist/jk_data/bundler_ifServer.js.map +1 -0
  10. package/dist/jk_data/common.d.ts +8 -0
  11. package/dist/jk_data/common.js +2 -0
  12. package/dist/jk_data/common.js.map +1 -0
  13. package/dist/jk_data/core.d.ts +13 -0
  14. package/dist/jk_data/core.js +85 -0
  15. package/dist/jk_data/core.js.map +1 -0
  16. package/dist/jk_data/dataTableProxy.d.ts +21 -0
  17. package/dist/jk_data/dataTableProxy.js +49 -0
  18. package/dist/jk_data/dataTableProxy.js.map +1 -0
  19. package/dist/jk_data/ifServerSide.d.ts +0 -0
  20. package/dist/jk_data/ifServerSide.js +2 -0
  21. package/dist/jk_data/ifServerSide.js.map +1 -0
  22. package/dist/jk_data/index.d.ts +3 -55
  23. package/dist/jk_data/index.js +3 -105
  24. package/dist/jk_data/index.js.map +1 -1
  25. package/dist/jk_data/interfaces.d.ts +107 -0
  26. package/dist/jk_data/interfaces.js +2 -0
  27. package/dist/jk_data/interfaces.js.map +1 -0
  28. package/dist/jk_data/jBundler_common.d.ts +12 -0
  29. package/dist/jk_data/jBundler_common.js +2 -0
  30. package/dist/jk_data/jBundler_common.js.map +1 -0
  31. package/dist/jk_data/jBundler_ifBrowser.d.ts +2 -0
  32. package/dist/jk_data/jBundler_ifBrowser.js +2 -0
  33. package/dist/jk_data/jBundler_ifBrowser.js.map +1 -0
  34. package/dist/jk_data/jBundler_ifServer.1.d.ts +2 -0
  35. package/dist/jk_data/jBundler_ifServer.1.js +2 -0
  36. package/dist/jk_data/jBundler_ifServer.1.js.map +1 -0
  37. package/dist/jk_data/jBundler_ifServer.d.ts +2 -0
  38. package/dist/jk_data/jBundler_ifServer.js +2 -0
  39. package/dist/jk_data/jBundler_ifServer.js.map +1 -0
  40. package/dist/jk_data/proxy.d.ts +24 -0
  41. package/dist/jk_data/proxy.js +82 -0
  42. package/dist/jk_data/proxy.js.map +1 -0
  43. package/dist/jk_fs/jBundler_ifServer.d.ts +1 -0
  44. package/dist/jk_fs/jBundler_ifServer.js +1 -0
  45. package/dist/jk_fs/jBundler_ifServer.js.map +1 -1
  46. package/dist/jk_memcache/index.d.ts +1 -0
  47. package/dist/jk_memcache/index.js +1 -5
  48. package/dist/jk_memcache/index.js.map +1 -1
  49. package/dist/jk_schemas/index.d.ts +20 -16
  50. package/dist/jk_schemas/index.js +13 -15
  51. package/dist/jk_schemas/index.js.map +1 -1
  52. package/dist/jk_tools/index.d.ts +1 -0
  53. package/package.json +3 -3
  54. package/src/jk_app/common.ts +12 -2
  55. package/src/jk_data/core.ts +92 -0
  56. package/src/jk_data/index.ts +3 -166
  57. package/src/jk_data/interfaces.ts +140 -0
  58. package/src/jk_data/proxy.ts +102 -0
  59. package/src/jk_fs/jBundler_ifServer.ts +1 -0
  60. package/src/jk_memcache/index.ts +4 -8
  61. package/src/jk_schemas/index.ts +29 -27
  62. package/src/jk_tools/index.ts +3 -1
  63. package/src/jk_compress/index.js +0 -1
  64. package/src/jk_compress/jBundler_ifServer.js +0 -10
  65. package/src/jk_data/index.js +0 -155
  66. package/src/jk_schemas/index.js +0 -330
@@ -1,10 +0,0 @@
1
- import { gunzipSync as n_gunzipSync, gzipSync as n_gzipSync } from "node:zlib";
2
- import { isNodeJS } from "jopi-toolkit/jk_what";
3
- function node_gunzipSync(data) {
4
- return n_gunzipSync(Buffer.from(data));
5
- }
6
- function node_gzipSync(data) {
7
- return n_gzipSync(Buffer.from(data));
8
- }
9
- export var gunzipSync = isNodeJS ? node_gunzipSync : Bun.gunzipSync;
10
- export var gzipSync = isNodeJS ? node_gzipSync : Bun.gzipSync;
@@ -1,155 +0,0 @@
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
- /**
38
- * Filter the row content according to rules.
39
- */
40
- export function simpleRowArrayFilter(rows, params) {
41
- // > Apply filter.
42
- if (params.filter) {
43
- var f_1 = params.filter;
44
- rows = rows.filter(function (r) {
45
- if (f_1.field) {
46
- var v = r[f_1.field];
47
- if (v === undefined)
48
- return false;
49
- return String(v).includes(f_1.value);
50
- }
51
- else {
52
- for (var _i = 0, _a = Object.values(r); _i < _a.length; _i++) {
53
- var v = _a[_i];
54
- if (v === undefined)
55
- continue;
56
- if (String(v).includes(f_1.value))
57
- return true;
58
- }
59
- return false;
60
- }
61
- });
62
- }
63
- // > Apply sorting.
64
- if (params.sorting && params.sorting.length) {
65
- var sorting = params.sorting[0];
66
- var sortField_1 = sorting.id;
67
- var sortDesc_1 = sorting.desc;
68
- rows = rows.sort(function (a, b) {
69
- var av = a[sortField_1];
70
- var bv = b[sortField_1];
71
- if (av === undefined)
72
- av = "";
73
- if (bv === undefined)
74
- bv = "";
75
- var avIsNumber = typeof av === "number";
76
- var bvIsNumber = typeof bv === "number";
77
- if (avIsNumber && bvIsNumber) {
78
- if (sortDesc_1) {
79
- return bv - av;
80
- }
81
- else {
82
- return av - bv;
83
- }
84
- }
85
- else {
86
- var avStr = String(av);
87
- var bvStr = String(bv);
88
- if (sortDesc_1) {
89
- return bvStr.localeCompare(avStr);
90
- }
91
- else {
92
- return avStr.localeCompare(bvStr);
93
- }
94
- }
95
- });
96
- }
97
- var totalWithoutPagination = rows.length;
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 };
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
@@ -1,330 +0,0 @@
1
- // noinspection JSUnusedGlobalSymbols
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- import { generateUUIDv4 } from "jopi-toolkit/jk_tools";
29
- //region Validation
30
- /**
31
- * Throwing this error allows it to be caught
32
- * when validating an object.
33
- */
34
- var SchemaError = /** @class */ (function (_super) {
35
- __extends(SchemaError, _super);
36
- function SchemaError(errorMessage, errorCode) {
37
- var _this = _super.call(this, "") || this;
38
- _this.errorMessage = errorMessage;
39
- _this.errorCode = errorCode;
40
- return _this;
41
- }
42
- return SchemaError;
43
- }(Error));
44
- /**
45
- * Declare an error when validating a schema.
46
- * Must be called when validating or normalizing.
47
- */
48
- export function declareError(message, errorCode) {
49
- throw new SchemaError(message, errorCode);
50
- }
51
- export function validateSchema(data, schema) {
52
- // Normalize the data.
53
- // It's a step where we apply automatic corrections.
54
- //
55
- if (schema.schemaMeta.normalize) {
56
- try {
57
- schema.schemaMeta.normalize(data, gValueCheckingHelper);
58
- }
59
- catch (e) {
60
- if (e instanceof SchemaError) {
61
- return {
62
- globalError: e.errorMessage || "Schema validation failed",
63
- globalErrorCode: e.errorCode || "SCHEMA_VALIDATION_FAILED"
64
- };
65
- }
66
- else {
67
- throw e;
68
- }
69
- }
70
- }
71
- // >>> Check each field individually.
72
- // Each time it will:
73
- // - Normalize the value.
74
- // - Check if optional + undefined.
75
- // - Apply validator for the field type.
76
- var fieldErrors;
77
- for (var fieldName in schema.desc) {
78
- var defaultErrorMessage = void 0;
79
- try {
80
- var field = schema.desc[fieldName];
81
- var value = data[fieldName];
82
- if (field.normalize) {
83
- defaultErrorMessage = field.errorMessage_theValueIsInvalid;
84
- field.normalize(value, data, gValueCheckingHelper);
85
- }
86
- if (!field.optional) {
87
- if (value === undefined) {
88
- if (field.errorMessage_isRequired) {
89
- declareError(field.errorMessage_isRequired, "VALUE_REQUIRED");
90
- }
91
- else if (field.errorMessage_theValueIsInvalid) {
92
- declareError(field.errorMessage_theValueIsInvalid, "VALUE_REQUIRED");
93
- }
94
- else {
95
- declareError("Field ".concat(fieldName, " is required"), "VALUE_REQUIRED");
96
- }
97
- }
98
- }
99
- var typeValidator = byTypeValidator[field.type];
100
- if (typeValidator) {
101
- typeValidator(value, field);
102
- }
103
- if (field.validator) {
104
- defaultErrorMessage = field.errorMessage_theValueIsInvalid;
105
- field.validator(value, data, gValueCheckingHelper);
106
- }
107
- }
108
- catch (e) {
109
- if (e instanceof SchemaError) {
110
- if (!fieldErrors)
111
- fieldErrors = {};
112
- fieldErrors[fieldName] = {
113
- fieldName: fieldName,
114
- message: e.errorMessage || defaultErrorMessage || "Field ".concat(fieldName, " is invalid"),
115
- code: e.errorCode || "FIELD_VALIDATION_FAILED"
116
- };
117
- }
118
- else {
119
- throw e;
120
- }
121
- }
122
- }
123
- // >>> Validate the whole fields.
124
- // Allow validating if values are ok with each others.
125
- if (schema.schemaMeta.validate) {
126
- try {
127
- schema.schemaMeta.validate(data, gValueCheckingHelper);
128
- }
129
- catch (e) {
130
- if (e instanceof SchemaError) {
131
- return {
132
- globalError: e.errorMessage || "Schema validation failed",
133
- globalErrorCode: e.errorCode || "SCHEMA_VALIDATION_FAILED",
134
- fields: fieldErrors
135
- };
136
- }
137
- else {
138
- throw e;
139
- }
140
- }
141
- }
142
- // No error ? --> undefined.
143
- // Otherwise returns the errors.
144
- //
145
- if (!fieldErrors)
146
- return undefined;
147
- return { fields: fieldErrors };
148
- }
149
- var byTypeValidator = {};
150
- /**
151
- * A helper allowing to make field validation easier.
152
- * Is sent to normalize and validate functions.
153
- */
154
- var ValueCheckingHelper = /** @class */ (function () {
155
- function ValueCheckingHelper() {
156
- }
157
- ValueCheckingHelper.prototype.declareError = function (message, errorCode) {
158
- throw new SchemaError(message, errorCode);
159
- };
160
- return ValueCheckingHelper;
161
- }());
162
- var gValueCheckingHelper = new ValueCheckingHelper();
163
- export function registerSchema(schemaId, schema, meta) {
164
- if (!schemaId) {
165
- throw new Error("jk_schemas - Schema id required. If you need an uid you can use: " + generateUUIDv4());
166
- }
167
- gRegistry[schemaId] = { schema: schema, meta: meta };
168
- }
169
- export function getSchemaMeta(schemaId) {
170
- var entry = gRegistry[schemaId];
171
- if (entry)
172
- return entry.schema;
173
- return undefined;
174
- }
175
- export function getSchema(schemaId) {
176
- var entry = gRegistry[schemaId];
177
- if (entry)
178
- return entry.schema;
179
- return undefined;
180
- }
181
- export function requireSchema(schemaId) {
182
- var s = getSchema(schemaId);
183
- if (!s) {
184
- throw new Error("jk_schemas - Schema ".concat(schemaId, " not found"));
185
- }
186
- return s;
187
- }
188
- var gRegistry = {};
189
- //endregion
190
- //region Schema
191
- export function schema(descriptor, meta) {
192
- return new SchemaImpl(descriptor, meta || {});
193
- }
194
- var SchemaImpl = /** @class */ (function () {
195
- function SchemaImpl(desc, schemaMeta) {
196
- this.desc = desc;
197
- this.schemaMeta = schemaMeta;
198
- }
199
- SchemaImpl.prototype.toJson = function () {
200
- return toJson(this);
201
- };
202
- SchemaImpl.prototype.addDataNormalizer = function (f) {
203
- if (!this.schemaMeta.normalize) {
204
- this.schemaMeta.normalize = f;
205
- }
206
- var f1 = this.schemaMeta.normalize;
207
- this.schemaMeta.normalize = function (values, helper) {
208
- f1(values, helper);
209
- f(values, helper);
210
- };
211
- return this;
212
- };
213
- SchemaImpl.prototype.addDataValidator = function (f) {
214
- if (!this.schemaMeta.validate) {
215
- this.schemaMeta.validate = f;
216
- }
217
- var f1 = this.schemaMeta.validate;
218
- this.schemaMeta.validate = function (values, helper) {
219
- f1(values, helper);
220
- f(values, helper);
221
- };
222
- return this;
223
- };
224
- return SchemaImpl;
225
- }());
226
- export function toJson(schema) {
227
- return schema;
228
- }
229
- export function string(title, optional, infos) {
230
- if (!optional) {
231
- if (!infos)
232
- infos = {};
233
- if (infos.minLength === undefined)
234
- infos.minLength = 1;
235
- }
236
- return __assign(__assign({}, infos), { title: title, optional: optional, type: "string" });
237
- }
238
- byTypeValidator["string"] = function (v, f) {
239
- if (typeof v !== "string") {
240
- declareError(f.errorMessage_theValueIsInvalid || "Value must be a string", "INVALID_TYPE");
241
- return;
242
- }
243
- var sf = f;
244
- if ((sf.minLength !== undefined) && (v.length < sf.minLength)) {
245
- declareError(sf.errorMessage_minLength || "Value must be at least ".concat(sf.minLength, " characters long"), "INVALID_LENGTH");
246
- return;
247
- }
248
- if ((sf.maxLength !== undefined) && (v.length > sf.maxLength)) {
249
- declareError(sf.errorMessage_maxLength || "Value must be less than ".concat(sf.maxLength, " characters long"), "INVALID_LENGTH");
250
- return;
251
- }
252
- };
253
- export function boolean(title, optional, infos) {
254
- return __assign(__assign({}, infos), { title: title, optional: optional, type: "boolean" });
255
- }
256
- byTypeValidator["boolean"] = function (v, f) {
257
- if (typeof v !== "boolean") {
258
- declareError(f.errorMessage_theValueIsInvalid || "Value must be a boolean", "INVALID_TYPE");
259
- }
260
- var sf = f;
261
- if (sf.requireTrue) {
262
- if (v !== true) {
263
- declareError(sf.errorMessage_requireTrue || "Value must be true", "INVALID_VALUE");
264
- }
265
- }
266
- else if (sf.requireFalse) {
267
- if (v !== false) {
268
- declareError(sf.errorMessage_requireFalse || "Value must be false", "INVALID_VALUE");
269
- }
270
- }
271
- };
272
- export function number(title, optional, infos) {
273
- return __assign(__assign({}, infos), { title: title, optional: optional, type: "number" });
274
- }
275
- export function formatNumber(value, fieldNumber, defaultLocalFormat, defaultCurrency) {
276
- if (defaultLocalFormat === void 0) { defaultLocalFormat = "en-US"; }
277
- if (defaultCurrency === void 0) { defaultCurrency = "USD"; }
278
- var amount = parseFloat(value);
279
- var localFormat = fieldNumber.localFormat || defaultLocalFormat;
280
- switch (fieldNumber.displayType) {
281
- case "currency":
282
- return new Intl.NumberFormat(localFormat, {
283
- style: "currency",
284
- currency: fieldNumber.currency || defaultCurrency,
285
- }).format(amount);
286
- default:
287
- return new Intl.NumberFormat(localFormat, { style: fieldNumber.displayType || "decimal" }).format(amount);
288
- }
289
- }
290
- byTypeValidator["number"] = function (v, f) {
291
- if (typeof v !== "number") {
292
- declareError(f.errorMessage_theValueIsInvalid || "Value must be a number", "INVALID_TYPE");
293
- }
294
- var sf = f;
295
- if ((sf.minValue !== undefined) && (v < sf.minValue)) {
296
- declareError(sf.errorMessage_minValue || "Value must be at least ".concat(sf.minValue), "INVALID_LENGTH");
297
- return;
298
- }
299
- if ((sf.maxValue !== undefined) && (v > sf.maxValue)) {
300
- declareError(sf.errorMessage_maxValue || "Value must be less than ".concat(sf.maxValue), "INVALID_LENGTH");
301
- return;
302
- }
303
- };
304
- //endregion
305
- //region Currency
306
- export function currency(title, optional, infos) {
307
- return number(title, optional, __assign(__assign({}, infos), { displayType: "currency" }));
308
- }
309
- //endregion
310
- //region Percent
311
- export function percent(title, optional, infos) {
312
- return number(title, optional, __assign(__assign({}, infos), { displayType: "percent" }));
313
- }
314
- export function file(title, optional, infos) {
315
- return __assign(__assign({}, infos), { title: title, optional: optional, type: "file" });
316
- }
317
- //endregion
318
- //endregion
319
- /*const MAKE_OPTIONAL = true;
320
- //
321
- const UserSchema1 = schema({
322
- testOptional: string("testOptional", true),
323
- testString: string("testString", MAKE_OPTIONAL),
324
- testBool: boolean("testBool", MAKE_OPTIONAL),
325
- testNumber: number("testNumber", MAKE_OPTIONAL),
326
- testFile: file("testFile", MAKE_OPTIONAL)
327
- })
328
-
329
- type UserDataType1 = SchemaToType<typeof UserSchema1>;
330
- let ud1: UserDataType1 = {};*/