jopi-toolkit 3.0.15 → 3.0.24
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 +2 -2
- package/dist/jk_app/common.js +7 -12
- 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.js +14 -6
- package/dist/jk_events/index.js.map +1 -1
- package/dist/jk_fs/jBundler_ifServer.d.ts +3 -3
- package/dist/jk_fs/jBundler_ifServer.js +26 -5
- package/dist/jk_fs/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/package.json +4 -8
- package/src/jk_app/common.ts +7 -17
- 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 +18 -7
- package/src/jk_fs/jBundler_ifServer.js +44 -9
- package/src/jk_fs/jBundler_ifServer.ts +26 -5
- 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/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_translate/index.js +0 -56
- package/src/jk_translate/index.ts +0 -85
|
@@ -322,18 +322,53 @@ export function writeTextToFileSync(filePath, text, createDir) {
|
|
|
322
322
|
}
|
|
323
323
|
fss.writeFileSync(filePath, text, { encoding: 'utf8', flag: 'w' });
|
|
324
324
|
}
|
|
325
|
-
export function readTextFromFile(
|
|
326
|
-
return
|
|
325
|
+
export function readTextFromFile(filePath_1) {
|
|
326
|
+
return __awaiter(this, arguments, void 0, function (filePath, throwError) {
|
|
327
|
+
var _a;
|
|
328
|
+
if (throwError === void 0) { throwError = false; }
|
|
329
|
+
return __generator(this, function (_b) {
|
|
330
|
+
switch (_b.label) {
|
|
331
|
+
case 0:
|
|
332
|
+
if (throwError) {
|
|
333
|
+
return [2 /*return*/, fs.readFile(filePath, 'utf8')];
|
|
334
|
+
}
|
|
335
|
+
_b.label = 1;
|
|
336
|
+
case 1:
|
|
337
|
+
_b.trys.push([1, 3, , 4]);
|
|
338
|
+
return [4 /*yield*/, fs.readFile(filePath, 'utf8')];
|
|
339
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
340
|
+
case 3:
|
|
341
|
+
_a = _b.sent();
|
|
342
|
+
// @ts-ignore
|
|
343
|
+
return [2 /*return*/, undefined];
|
|
344
|
+
case 4: return [2 /*return*/];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
327
348
|
}
|
|
328
|
-
export function readJsonFromFile(
|
|
329
|
-
return __awaiter(this,
|
|
330
|
-
var txt;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
349
|
+
export function readJsonFromFile(filePath_1) {
|
|
350
|
+
return __awaiter(this, arguments, void 0, function (filePath, throwError) {
|
|
351
|
+
var txt, txt, _a;
|
|
352
|
+
if (throwError === void 0) { throwError = false; }
|
|
353
|
+
return __generator(this, function (_b) {
|
|
354
|
+
switch (_b.label) {
|
|
355
|
+
case 0:
|
|
356
|
+
if (!throwError) return [3 /*break*/, 2];
|
|
357
|
+
return [4 /*yield*/, fs.readFile(filePath, 'utf8')];
|
|
334
358
|
case 1:
|
|
335
|
-
txt =
|
|
359
|
+
txt = _b.sent();
|
|
336
360
|
return [2 /*return*/, JSON.parse(txt)];
|
|
361
|
+
case 2:
|
|
362
|
+
_b.trys.push([2, 4, , 5]);
|
|
363
|
+
return [4 /*yield*/, fs.readFile(filePath, 'utf8')];
|
|
364
|
+
case 3:
|
|
365
|
+
txt = _b.sent();
|
|
366
|
+
return [2 /*return*/, JSON.parse(txt)];
|
|
367
|
+
case 4:
|
|
368
|
+
_a = _b.sent();
|
|
369
|
+
// @ts-ignore
|
|
370
|
+
return [2 /*return*/, undefined];
|
|
371
|
+
case 5: return [2 /*return*/];
|
|
337
372
|
}
|
|
338
373
|
});
|
|
339
374
|
});
|
|
@@ -181,13 +181,34 @@ export function writeTextToFileSync(filePath: string, text: string, createDir: b
|
|
|
181
181
|
fss.writeFileSync(filePath, text, {encoding: 'utf8', flag: 'w'});
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
export function readTextFromFile(filePath: string): Promise<string> {
|
|
185
|
-
|
|
184
|
+
export async function readTextFromFile(filePath: string, throwError: boolean = false): Promise<string> {
|
|
185
|
+
if (throwError) {
|
|
186
|
+
return fs.readFile(filePath, 'utf8');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
return await fs.readFile(filePath, 'utf8');
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
186
196
|
}
|
|
187
197
|
|
|
188
|
-
export async function readJsonFromFile<T = any>(filePath: string): Promise<T> {
|
|
189
|
-
|
|
190
|
-
|
|
198
|
+
export async function readJsonFromFile<T = any>(filePath: string, throwError: boolean = false): Promise<T> {
|
|
199
|
+
if (throwError) {
|
|
200
|
+
let txt = await fs.readFile(filePath, 'utf8');
|
|
201
|
+
return JSON.parse(txt) as T;
|
|
202
|
+
} else {
|
|
203
|
+
try {
|
|
204
|
+
let txt = await fs.readFile(filePath, 'utf8');
|
|
205
|
+
return JSON.parse(txt) as T;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// @ts-ignore
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
191
212
|
}
|
|
192
213
|
|
|
193
214
|
export function readTextFromFileSync(filePath: string): string {
|
package/src/jk_schemas/index.js
CHANGED
|
@@ -54,7 +54,7 @@ export function validateSchema(data, schema) {
|
|
|
54
54
|
//
|
|
55
55
|
if (schema.schemaMeta.normalize) {
|
|
56
56
|
try {
|
|
57
|
-
schema.schemaMeta.normalize(data);
|
|
57
|
+
schema.schemaMeta.normalize(data, gValueCheckingHelper);
|
|
58
58
|
}
|
|
59
59
|
catch (e) {
|
|
60
60
|
if (e instanceof SchemaError) {
|
|
@@ -81,7 +81,7 @@ export function validateSchema(data, schema) {
|
|
|
81
81
|
var value = data[fieldName];
|
|
82
82
|
if (field.normalize) {
|
|
83
83
|
defaultErrorMessage = field.errorMessage_theValueIsInvalid;
|
|
84
|
-
field.normalize(value, data);
|
|
84
|
+
field.normalize(value, data, gValueCheckingHelper);
|
|
85
85
|
}
|
|
86
86
|
if (!field.optional) {
|
|
87
87
|
if (value === undefined) {
|
|
@@ -102,7 +102,7 @@ export function validateSchema(data, schema) {
|
|
|
102
102
|
}
|
|
103
103
|
if (field.validator) {
|
|
104
104
|
defaultErrorMessage = field.errorMessage_theValueIsInvalid;
|
|
105
|
-
field.validator(value, data);
|
|
105
|
+
field.validator(value, data, gValueCheckingHelper);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
catch (e) {
|
|
@@ -124,7 +124,7 @@ export function validateSchema(data, schema) {
|
|
|
124
124
|
// Allow validating if values are ok with each others.
|
|
125
125
|
if (schema.schemaMeta.validate) {
|
|
126
126
|
try {
|
|
127
|
-
schema.schemaMeta.validate(data);
|
|
127
|
+
schema.schemaMeta.validate(data, gValueCheckingHelper);
|
|
128
128
|
}
|
|
129
129
|
catch (e) {
|
|
130
130
|
if (e instanceof SchemaError) {
|
|
@@ -147,6 +147,19 @@ export function validateSchema(data, schema) {
|
|
|
147
147
|
return { fields: fieldErrors };
|
|
148
148
|
}
|
|
149
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();
|
|
150
163
|
export function registerSchema(schemaId, schema, meta) {
|
|
151
164
|
if (!schemaId) {
|
|
152
165
|
throw new Error("jk_schemas - Schema id required. If you need an uid you can use: " + generateUUIDv4());
|
|
@@ -176,8 +189,40 @@ var gRegistry = {};
|
|
|
176
189
|
//endregion
|
|
177
190
|
//region Schema
|
|
178
191
|
export function schema(descriptor, meta) {
|
|
179
|
-
return
|
|
192
|
+
return new SchemaImpl(descriptor, meta || {});
|
|
180
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
|
+
}());
|
|
181
226
|
export function toJson(schema) {
|
|
182
227
|
return schema;
|
|
183
228
|
}
|
package/src/jk_schemas/index.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function validateSchema(data: any, schema: Schema): ValidationErrors|unde
|
|
|
47
47
|
//
|
|
48
48
|
if (schema.schemaMeta.normalize) {
|
|
49
49
|
try {
|
|
50
|
-
schema.schemaMeta.normalize(data);
|
|
50
|
+
schema.schemaMeta.normalize(data, gValueCheckingHelper);
|
|
51
51
|
}
|
|
52
52
|
catch (e: any) {
|
|
53
53
|
if (e instanceof SchemaError) {
|
|
@@ -80,7 +80,7 @@ export function validateSchema(data: any, schema: Schema): ValidationErrors|unde
|
|
|
80
80
|
|
|
81
81
|
if (field.normalize) {
|
|
82
82
|
defaultErrorMessage = field.errorMessage_theValueIsInvalid;
|
|
83
|
-
field.normalize(value, data);
|
|
83
|
+
field.normalize(value, data, gValueCheckingHelper);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
if (!field.optional) {
|
|
@@ -103,7 +103,7 @@ export function validateSchema(data: any, schema: Schema): ValidationErrors|unde
|
|
|
103
103
|
|
|
104
104
|
if (field.validator) {
|
|
105
105
|
defaultErrorMessage = field.errorMessage_theValueIsInvalid;
|
|
106
|
-
field.validator(value, data);
|
|
106
|
+
field.validator(value, data, gValueCheckingHelper);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
catch (e: any) {
|
|
@@ -126,7 +126,7 @@ export function validateSchema(data: any, schema: Schema): ValidationErrors|unde
|
|
|
126
126
|
|
|
127
127
|
if (schema.schemaMeta.validate) {
|
|
128
128
|
try {
|
|
129
|
-
schema.schemaMeta.validate(data);
|
|
129
|
+
schema.schemaMeta.validate(data, gValueCheckingHelper);
|
|
130
130
|
}
|
|
131
131
|
catch (e: any) {
|
|
132
132
|
if (e instanceof SchemaError) {
|
|
@@ -151,6 +151,18 @@ export function validateSchema(data: any, schema: Schema): ValidationErrors|unde
|
|
|
151
151
|
|
|
152
152
|
const byTypeValidator: Record<string, (v: any, fieldInfos: SchemaFieldInfos) => void> = {};
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* A helper allowing to make field validation easier.
|
|
156
|
+
* Is sent to normalize and validate functions.
|
|
157
|
+
*/
|
|
158
|
+
class ValueCheckingHelper {
|
|
159
|
+
declareError(message?: string, errorCode?: string) {
|
|
160
|
+
throw new SchemaError(message, errorCode);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const gValueCheckingHelper = new ValueCheckingHelper();
|
|
165
|
+
|
|
154
166
|
//endregion
|
|
155
167
|
|
|
156
168
|
//region Registry
|
|
@@ -197,11 +209,50 @@ const gRegistry: Record<string, RegistryEntry> = {};
|
|
|
197
209
|
//region Schema
|
|
198
210
|
|
|
199
211
|
export function schema<T extends SchemaDescriptor>(descriptor: T, meta?: SchemaMeta): Schema & { desc: T } {
|
|
200
|
-
return
|
|
212
|
+
return new SchemaImpl(descriptor, meta || {});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
class SchemaImpl<T extends SchemaDescriptor> implements Schema {
|
|
216
|
+
constructor(public readonly desc: T, public readonly schemaMeta: SchemaMeta) {
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
toJson(): SchemaInfo {
|
|
220
|
+
return toJson(this);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
addDataNormalizer(f: (allValues: any, checkHelper: ValueCheckingHelper) => void): this {
|
|
224
|
+
if (!this.schemaMeta.normalize) {
|
|
225
|
+
this.schemaMeta.normalize = f;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const f1 = this.schemaMeta.normalize;
|
|
229
|
+
|
|
230
|
+
this.schemaMeta.normalize = function (values, helper) {
|
|
231
|
+
f1(values, helper);
|
|
232
|
+
f(values, helper);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
addDataValidator(f: (allValues: any, checkHelper: ValueCheckingHelper) => void): this {
|
|
239
|
+
if (!this.schemaMeta.validate) {
|
|
240
|
+
this.schemaMeta.validate = f;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const f1 = this.schemaMeta.validate;
|
|
244
|
+
|
|
245
|
+
this.schemaMeta.validate = function (values, helper) {
|
|
246
|
+
f1(values, helper);
|
|
247
|
+
f(values, helper);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
201
252
|
}
|
|
202
253
|
|
|
203
254
|
export interface SchemaDescriptor {
|
|
204
|
-
[field: string]:
|
|
255
|
+
[field: string]: Field;
|
|
205
256
|
}
|
|
206
257
|
|
|
207
258
|
export interface SchemaMeta {
|
|
@@ -209,8 +260,8 @@ export interface SchemaMeta {
|
|
|
209
260
|
description?: string;
|
|
210
261
|
[key: string]: any;
|
|
211
262
|
|
|
212
|
-
normalize?: (allValues: any) => void;
|
|
213
|
-
validate?: (allValues: any) => void;
|
|
263
|
+
normalize?: (allValues: any, checkHelper: ValueCheckingHelper) => void;
|
|
264
|
+
validate?: (allValues: any, checkHelper: ValueCheckingHelper) => void;
|
|
214
265
|
}
|
|
215
266
|
|
|
216
267
|
export interface SchemaInfo {
|
|
@@ -219,6 +270,26 @@ export interface SchemaInfo {
|
|
|
219
270
|
}
|
|
220
271
|
|
|
221
272
|
export interface Schema extends SchemaInfo {
|
|
273
|
+
/**
|
|
274
|
+
* Get serializable data describing this schema.
|
|
275
|
+
*/
|
|
276
|
+
toJson(): SchemaInfo;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Add a function whose role is to normalize the data.
|
|
280
|
+
*
|
|
281
|
+
* Cumulating: if a normalize function has already been added,
|
|
282
|
+
* then the previous function will be called before this one.
|
|
283
|
+
*/
|
|
284
|
+
addDataNormalizer(f: (allValues: any, checkHelper: ValueCheckingHelper) => void): this;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Add a function whose role is to validate the data.
|
|
288
|
+
*
|
|
289
|
+
* Cumulating: if a validate function has already been added,
|
|
290
|
+
* then the previous function will be called before this one.
|
|
291
|
+
*/
|
|
292
|
+
addDataValidator(f: (allValues: any, checkHelper: ValueCheckingHelper) => void): this;
|
|
222
293
|
}
|
|
223
294
|
|
|
224
295
|
export function toJson(schema: Schema): SchemaInfo {
|
|
@@ -304,7 +375,46 @@ export interface ScOnTableRenderingInfo {
|
|
|
304
375
|
textAlign?: "left" | "center" | "right";
|
|
305
376
|
}
|
|
306
377
|
|
|
307
|
-
|
|
378
|
+
/**
|
|
379
|
+
* Get information about how storing this field.
|
|
380
|
+
*/
|
|
381
|
+
export interface ScFieldStore {
|
|
382
|
+
/**
|
|
383
|
+
* Allow knowing if a BDD index must be created for this field.
|
|
384
|
+
* The default is true.
|
|
385
|
+
*/
|
|
386
|
+
mustIndex?: boolean;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Allow knowing if this field is the primary key.
|
|
390
|
+
* If more than one primary is set, then a composed key will be created.
|
|
391
|
+
* The default is false.
|
|
392
|
+
*/
|
|
393
|
+
isPrimaryKey?: boolean;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The column name to use when storing this field in a database.
|
|
397
|
+
* The default is the field name.
|
|
398
|
+
*/
|
|
399
|
+
colName?: string;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* An indication on the size of the data to store.
|
|
403
|
+
* The default is "default".
|
|
404
|
+
*
|
|
405
|
+
* - big: for storing large strings / binary.
|
|
406
|
+
* - medium: for storing item with a common size.
|
|
407
|
+
* - tiny: for storing small strings / binary.
|
|
408
|
+
*/
|
|
409
|
+
dataSize?: "tiny" | "medium" | "big";
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Allow forcing the type name for the BDD.
|
|
413
|
+
*/
|
|
414
|
+
databaseType?: string;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export interface ScField<T, Opt extends boolean> {
|
|
308
418
|
title: string;
|
|
309
419
|
type: string;
|
|
310
420
|
|
|
@@ -316,12 +426,31 @@ interface ScField<T, Opt extends boolean> {
|
|
|
316
426
|
errorMessage_theDataTypeIsInvalid?: string;
|
|
317
427
|
errorMessage_theValueIsInvalid?: string;
|
|
318
428
|
|
|
319
|
-
|
|
320
|
-
|
|
429
|
+
/**
|
|
430
|
+
* A function used to normalize the field value.
|
|
431
|
+
*/
|
|
432
|
+
normalize?: (value: T, allValues: any, valueCheckingHelp: ValueCheckingHelper) => void;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* A function used to validate the field.
|
|
436
|
+
*/
|
|
437
|
+
validator?: (value: T, allValues: any, valueCheckingHelp: ValueCheckingHelper) => void;
|
|
321
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Meta-data associated with this field.
|
|
441
|
+
* The usage is free, you can use it for whatever you want.
|
|
442
|
+
*/
|
|
322
443
|
metas?: Record<string, string>;
|
|
323
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Get information about how to render this field in a data table.
|
|
447
|
+
*/
|
|
324
448
|
onTableRendering?: ScOnTableRenderingInfo;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Get information about how storing this field.
|
|
452
|
+
*/
|
|
453
|
+
store?: ScFieldStore;
|
|
325
454
|
}
|
|
326
455
|
|
|
327
456
|
export type Field = ScField<any, any>;
|
package/src/jk_term/index.js
CHANGED
|
@@ -114,6 +114,8 @@ export var logBgRed = buildLogger(B_RED);
|
|
|
114
114
|
export var textBgRed = buildWriter(B_RED);
|
|
115
115
|
export var logBlue = buildLogger(C_BLUE);
|
|
116
116
|
export var textBlue = buildWriter(C_BLUE);
|
|
117
|
+
export var logGrey = buildLogger(C_GREY);
|
|
118
|
+
export var textGrey = buildWriter(C_GREY);
|
|
117
119
|
export var logBgBlue = buildLogger(B_BLUE, C_WHITE);
|
|
118
120
|
export var textBgBlue = buildWriter(B_BLUE, C_WHITE);
|
|
119
121
|
export var logGreen = buildLogger(C_GREEN);
|
package/src/jk_term/index.ts
CHANGED
|
@@ -105,6 +105,9 @@ export const textBgRed = buildWriter(B_RED);
|
|
|
105
105
|
export const logBlue = buildLogger(C_BLUE);
|
|
106
106
|
export const textBlue = buildWriter(C_BLUE);
|
|
107
107
|
|
|
108
|
+
export const logGrey = buildLogger(C_GREY);
|
|
109
|
+
export const textGrey = buildWriter(C_GREY);
|
|
110
|
+
|
|
108
111
|
export const logBgBlue = buildLogger(B_BLUE, C_WHITE);
|
|
109
112
|
export const textBgBlue = buildWriter(B_BLUE, C_WHITE);
|
|
110
113
|
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Declare an error when validating a schema.
|
|
3
|
-
* Must be called when validating or normalizing.
|
|
4
|
-
*/
|
|
5
|
-
export declare function declareError(message?: string, errorCode?: string): void;
|
|
6
|
-
export interface FieldError {
|
|
7
|
-
fieldName: string;
|
|
8
|
-
message: string;
|
|
9
|
-
code?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface ValidationErrors {
|
|
12
|
-
/**
|
|
13
|
-
* An error about the whole schema.
|
|
14
|
-
*/
|
|
15
|
-
globalError?: string;
|
|
16
|
-
globalErrorCode?: string;
|
|
17
|
-
/**
|
|
18
|
-
* An error per field.
|
|
19
|
-
*/
|
|
20
|
-
fields?: Record<string, FieldError>;
|
|
21
|
-
}
|
|
22
|
-
export declare function validateSchema(data: any, schema: Schema): ValidationErrors | undefined;
|
|
23
|
-
export declare function registerSchema(schemaId: string | undefined, schema: Schema, meta?: any): void;
|
|
24
|
-
export declare function getSchemaMeta(schemaId: string): Schema | undefined;
|
|
25
|
-
export declare function getSchema(schemaId: string): Schema | undefined;
|
|
26
|
-
export declare function requireSchema(schemaId: string): Schema;
|
|
27
|
-
export declare function schema<T extends SchemaDescriptor>(descriptor: T, meta?: SchemaMeta): Schema & {
|
|
28
|
-
desc: T;
|
|
29
|
-
};
|
|
30
|
-
export interface SchemaDescriptor {
|
|
31
|
-
[field: string]: ScField<any, any>;
|
|
32
|
-
}
|
|
33
|
-
export interface SchemaMeta {
|
|
34
|
-
title?: string;
|
|
35
|
-
description?: string;
|
|
36
|
-
[key: string]: any;
|
|
37
|
-
normalize?: (allValues: any) => void;
|
|
38
|
-
validate?: (allValues: any) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface SchemaInfo {
|
|
41
|
-
desc: SchemaDescriptor;
|
|
42
|
-
schemaMeta: SchemaMeta;
|
|
43
|
-
}
|
|
44
|
-
export interface Schema extends SchemaInfo {
|
|
45
|
-
}
|
|
46
|
-
export declare function toJson(schema: Schema): SchemaInfo;
|
|
47
|
-
/**
|
|
48
|
-
* Allow getting a valid TypeScript type for our schema.
|
|
49
|
-
*
|
|
50
|
-
* **Example**
|
|
51
|
-
* ```
|
|
52
|
-
* const UserSchema = { name: string("The name", false), test: string("Test", true) };
|
|
53
|
-
* type UserDataType = SchemaToType<typeof UserSchema>;
|
|
54
|
-
* let ud: UserDataType = {name:"ok", test: "5"};
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export type SchemaToType<S extends Schema> = {
|
|
58
|
-
[K in keyof S['desc'] as S['desc'][K] extends ScField<any, false> ? K : never]: S['desc'][K] extends ScField<infer T, any> ? T : never;
|
|
59
|
-
} & {
|
|
60
|
-
[K in keyof S['desc'] as S['desc'][K] extends ScField<any, true> ? K : never]?: S['desc'][K] extends ScField<infer T, any> ? T : never;
|
|
61
|
-
};
|
|
62
|
-
export interface ScOnTableRenderingInfo {
|
|
63
|
-
/**
|
|
64
|
-
* The title to use if rendering with a Table.
|
|
65
|
-
*/
|
|
66
|
-
title?: string;
|
|
67
|
-
/**
|
|
68
|
-
* If true, then allows hiding the column
|
|
69
|
-
* when rendering into a UI table component.
|
|
70
|
-
*/
|
|
71
|
-
enableHiding?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* If true, then the table column is hidden by default.
|
|
74
|
-
*/
|
|
75
|
-
defaultHidden?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* If true, then the table column is hidden and remain hidden.
|
|
78
|
-
*/
|
|
79
|
-
alwaysHidden?: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* If true, then allows sorting the column
|
|
82
|
-
* when rendering into a UI table component.
|
|
83
|
-
*/
|
|
84
|
-
enableSorting?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* If true, then allows editing the column
|
|
87
|
-
* when rendering into a UI table component.
|
|
88
|
-
*/
|
|
89
|
-
enableEditing?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Contains the name of the renderer to user for the header.
|
|
92
|
-
*/
|
|
93
|
-
rendererForHeader?: string;
|
|
94
|
-
/**
|
|
95
|
-
* Contains the name of the renderer to user for the cell.
|
|
96
|
-
*/
|
|
97
|
-
rendererForCell?: string;
|
|
98
|
-
/**
|
|
99
|
-
* Allows setting the column grow rule.
|
|
100
|
-
*/
|
|
101
|
-
columnGrow?: "takeAllPlace" | "takeMinPlace";
|
|
102
|
-
/**
|
|
103
|
-
* Allows defining extra-css class for rendering the cells.
|
|
104
|
-
*/
|
|
105
|
-
cellCssClass?: string;
|
|
106
|
-
/**
|
|
107
|
-
* Allows defining extra-css class for rendering the header.
|
|
108
|
-
*/
|
|
109
|
-
headerCssClass?: string;
|
|
110
|
-
textAlign?: "left" | "center" | "right";
|
|
111
|
-
}
|
|
112
|
-
interface ScField<T, Opt extends boolean> {
|
|
113
|
-
title: string;
|
|
114
|
-
type: string;
|
|
115
|
-
description?: string;
|
|
116
|
-
default?: T;
|
|
117
|
-
optional?: Opt;
|
|
118
|
-
errorMessage_isRequired?: string;
|
|
119
|
-
errorMessage_theDataTypeIsInvalid?: string;
|
|
120
|
-
errorMessage_theValueIsInvalid?: string;
|
|
121
|
-
normalize?: (value: T, allValues: any) => void;
|
|
122
|
-
validator?: (value: T, allValues: any) => void;
|
|
123
|
-
metas?: Record<string, string>;
|
|
124
|
-
onTableRendering?: ScOnTableRenderingInfo;
|
|
125
|
-
}
|
|
126
|
-
export type Field = ScField<any, any>;
|
|
127
|
-
export type SchemaFieldInfos = Field;
|
|
128
|
-
type OnlyInfos<T> = Omit<T, "title" | "optional" | "type">;
|
|
129
|
-
export interface ScString<Opt extends boolean = boolean> extends ScField<string, Opt> {
|
|
130
|
-
minLength?: number;
|
|
131
|
-
errorMessage_minLength?: string;
|
|
132
|
-
maxLength?: number;
|
|
133
|
-
errorMessage_maxLength?: string;
|
|
134
|
-
placeholder?: string;
|
|
135
|
-
}
|
|
136
|
-
export declare function string<Opt extends boolean>(title: string, optional: Opt, infos?: OnlyInfos<ScString<Opt>>): ScString<Opt>;
|
|
137
|
-
export interface ScBoolean<Opt extends boolean = boolean> extends ScField<boolean, Opt> {
|
|
138
|
-
requireTrue?: boolean;
|
|
139
|
-
errorMessage_requireTrue?: string;
|
|
140
|
-
requireFalse?: boolean;
|
|
141
|
-
errorMessage_requireFalse?: string;
|
|
142
|
-
}
|
|
143
|
-
export declare function boolean<Opt extends boolean>(title: string, optional: Opt, infos?: OnlyInfos<ScBoolean<Opt>>): ScBoolean<Opt>;
|
|
144
|
-
export interface ScNumber<Opt extends boolean = boolean> extends ScField<number, Opt> {
|
|
145
|
-
minValue?: number;
|
|
146
|
-
errorMessage_minValue?: string;
|
|
147
|
-
maxValue?: number;
|
|
148
|
-
errorMessage_maxValue?: string;
|
|
149
|
-
allowDecimal?: boolean;
|
|
150
|
-
roundMethod?: "round" | "floor" | "ceil";
|
|
151
|
-
errorMessage_dontAllowDecimal?: string;
|
|
152
|
-
incrStep?: number;
|
|
153
|
-
placeholder?: string;
|
|
154
|
-
/**
|
|
155
|
-
* Allows displaying this value as a simple
|
|
156
|
-
* number, or a current, or a percent.
|
|
157
|
-
*/
|
|
158
|
-
displayType?: "decimal" | "currency" | "percent";
|
|
159
|
-
/**
|
|
160
|
-
* The regional currency format to use for formating.
|
|
161
|
-
* Ex: "en-US", "fr-FR".
|
|
162
|
-
*/
|
|
163
|
-
localFormat?: string;
|
|
164
|
-
/**
|
|
165
|
-
* The type of currency.
|
|
166
|
-
* Ex: "USD".
|
|
167
|
-
*/
|
|
168
|
-
currency?: string;
|
|
169
|
-
}
|
|
170
|
-
export declare function number<Opt extends boolean>(title: string, optional: Opt, infos?: OnlyInfos<ScNumber<Opt>>): ScNumber<Opt>;
|
|
171
|
-
export declare function formatNumber(value: string, fieldNumber: ScNumber, defaultLocalFormat?: string, defaultCurrency?: string): string;
|
|
172
|
-
export declare function currency<Opt extends boolean>(title: string, optional: Opt, infos?: OnlyInfos<ScNumber<Opt>>): ScNumber<Opt>;
|
|
173
|
-
export declare function percent<Opt extends boolean>(title: string, optional: Opt, infos?: OnlyInfos<ScNumber<Opt>>): ScNumber<Opt>;
|
|
174
|
-
export interface File extends Blob {
|
|
175
|
-
readonly lastModified: number;
|
|
176
|
-
readonly name: string;
|
|
177
|
-
readonly webkitRelativePath: string;
|
|
178
|
-
}
|
|
179
|
-
export interface ScFile<Opt extends boolean> extends ScField<File[], Opt> {
|
|
180
|
-
maxFileCount?: number;
|
|
181
|
-
errorMessage_maxFileCount?: string;
|
|
182
|
-
acceptFileType?: string;
|
|
183
|
-
errorMessage_invalidFileType?: string;
|
|
184
|
-
maxFileSize?: number;
|
|
185
|
-
errorMessage_maxFileSize?: string;
|
|
186
|
-
}
|
|
187
|
-
export declare function file<Opt extends boolean>(title: string, optional: Opt, infos?: OnlyInfos<ScFile<Opt>>): ScFile<Opt>;
|
|
188
|
-
export {};
|