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
|
@@ -106,9 +106,11 @@ export function killPort(port: string = '3000'): Promise<void> {
|
|
|
106
106
|
return new Promise<void>((resolve) => {
|
|
107
107
|
const isWindows = os.platform() === 'win32';
|
|
108
108
|
|
|
109
|
+
// On Windows, we use netstat to find the PID of the process using the port as LOCAL address.
|
|
110
|
+
// On Unix, we use lsof with -sTCP:LISTEN to only get the listening process (avoiding killing clients/browsers).
|
|
109
111
|
const command = isWindows
|
|
110
112
|
? `netstat -ano | findstr :${port}`
|
|
111
|
-
: `lsof -ti :${port}`;
|
|
113
|
+
: `lsof -ti :${port} -sTCP:LISTEN`;
|
|
112
114
|
|
|
113
115
|
exec(command, (_error, stdout) => {
|
|
114
116
|
if (!stdout) {
|
|
@@ -119,9 +121,17 @@ export function killPort(port: string = '3000'): Promise<void> {
|
|
|
119
121
|
const pids = isWindows
|
|
120
122
|
? [...new Set(stdout.trim().split('\n').map(line => {
|
|
121
123
|
const parts = line.trim().split(/\s+/);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
// netstat -ano output: Proto, Local Address, Foreign Address, State, PID
|
|
125
|
+
const localAddress = parts[1] || "";
|
|
126
|
+
const pid = parts[parts.length - 1];
|
|
127
|
+
// Check if it's exactly the port (avoiding :3000 matching :30000)
|
|
128
|
+
// and ensure it's the local address (avoiding killing clients connected to this port)
|
|
129
|
+
if (localAddress.endsWith(`:${port}`)) {
|
|
130
|
+
return pid;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}).filter((pid): pid is string => !!(pid && /^\d+$/.test(pid) && pid !== '0')))]
|
|
134
|
+
: stdout.trim().split('\n').filter(pid => pid && /^\d+$/.test(pid));
|
|
125
135
|
|
|
126
136
|
const killCmd = isWindows ? 'taskkill /PID' : 'kill -9';
|
|
127
137
|
let pending = pids.length;
|
|
@@ -133,8 +143,11 @@ export function killPort(port: string = '3000'): Promise<void> {
|
|
|
133
143
|
|
|
134
144
|
pids.forEach(pid => {
|
|
135
145
|
exec(`${killCmd} ${pid}${isWindows ? ' /F' : ''}`, async (err) => {
|
|
136
|
-
if (err)
|
|
137
|
-
|
|
146
|
+
if (err) {
|
|
147
|
+
// Process might have already exited
|
|
148
|
+
} else {
|
|
149
|
+
console.log(`⚠️ Process ${pid} automatically killed to free the port ${port}`);
|
|
150
|
+
}
|
|
138
151
|
|
|
139
152
|
if (--pending === 0) {
|
|
140
153
|
await jk_timer.tick(250);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serverType = exports.isBrowser = exports.isServerSide = exports.isBunJS = exports.isNodeJS = void 0;
|
|
4
|
+
exports.isNodeJS = typeof (Bun) === "undefined";
|
|
5
|
+
exports.isBunJS = typeof (Bun) !== "undefined";
|
|
6
|
+
exports.isServerSide = true;
|
|
7
|
+
exports.isBrowser = false;
|
|
8
|
+
exports.serverType = exports.isNodeJS ? "node" : "bun";
|
|
@@ -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 {};
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
|
-
import { generateUUIDv4 } from "jopi-toolkit/jk_tools";
|
|
3
|
-
//region Validation
|
|
4
|
-
/**
|
|
5
|
-
* Throwing this error allows it to be caught
|
|
6
|
-
* when validating an object.
|
|
7
|
-
*/
|
|
8
|
-
class SchemaError extends Error {
|
|
9
|
-
errorMessage;
|
|
10
|
-
errorCode;
|
|
11
|
-
constructor(errorMessage, errorCode) {
|
|
12
|
-
super("");
|
|
13
|
-
this.errorMessage = errorMessage;
|
|
14
|
-
this.errorCode = errorCode;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Declare an error when validating a schema.
|
|
19
|
-
* Must be called when validating or normalizing.
|
|
20
|
-
*/
|
|
21
|
-
export function declareError(message, errorCode) {
|
|
22
|
-
throw new SchemaError(message, errorCode);
|
|
23
|
-
}
|
|
24
|
-
export function validateSchema(data, schema) {
|
|
25
|
-
// Normalize the data.
|
|
26
|
-
// It's a step where we apply automatic corrections.
|
|
27
|
-
//
|
|
28
|
-
if (schema.schemaMeta.normalize) {
|
|
29
|
-
try {
|
|
30
|
-
schema.schemaMeta.normalize(data);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
if (e instanceof SchemaError) {
|
|
34
|
-
return {
|
|
35
|
-
globalError: e.errorMessage || `Schema validation failed`,
|
|
36
|
-
globalErrorCode: e.errorCode || "SCHEMA_VALIDATION_FAILED"
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw e;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// >>> Check each field individually.
|
|
45
|
-
// Each time it will:
|
|
46
|
-
// - Normalize the value.
|
|
47
|
-
// - Check if optional + undefined.
|
|
48
|
-
// - Apply validator for the field type.
|
|
49
|
-
let fieldErrors;
|
|
50
|
-
for (let fieldName in schema.desc) {
|
|
51
|
-
let defaultErrorMessage;
|
|
52
|
-
try {
|
|
53
|
-
const field = schema.desc[fieldName];
|
|
54
|
-
const value = data[fieldName];
|
|
55
|
-
if (field.normalize) {
|
|
56
|
-
defaultErrorMessage = field.errorMessage_theValueIsInvalid;
|
|
57
|
-
field.normalize(value, data);
|
|
58
|
-
}
|
|
59
|
-
if (!field.optional) {
|
|
60
|
-
if (value === undefined) {
|
|
61
|
-
if (field.errorMessage_isRequired) {
|
|
62
|
-
declareError(field.errorMessage_isRequired, "VALUE_REQUIRED");
|
|
63
|
-
}
|
|
64
|
-
else if (field.errorMessage_theValueIsInvalid) {
|
|
65
|
-
declareError(field.errorMessage_theValueIsInvalid, "VALUE_REQUIRED");
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
declareError(`Field ${fieldName} is required`, "VALUE_REQUIRED");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
let typeValidator = byTypeValidator[field.type];
|
|
73
|
-
if (typeValidator) {
|
|
74
|
-
typeValidator(value, field);
|
|
75
|
-
}
|
|
76
|
-
if (field.validator) {
|
|
77
|
-
defaultErrorMessage = field.errorMessage_theValueIsInvalid;
|
|
78
|
-
field.validator(value, data);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
if (e instanceof SchemaError) {
|
|
83
|
-
if (!fieldErrors)
|
|
84
|
-
fieldErrors = {};
|
|
85
|
-
fieldErrors[fieldName] = {
|
|
86
|
-
fieldName,
|
|
87
|
-
message: e.errorMessage || defaultErrorMessage || `Field ${fieldName} is invalid`,
|
|
88
|
-
code: e.errorCode || "FIELD_VALIDATION_FAILED"
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
throw e;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// >>> Validate the whole fields.
|
|
97
|
-
// Allow validating if values are ok with each others.
|
|
98
|
-
if (schema.schemaMeta.validate) {
|
|
99
|
-
try {
|
|
100
|
-
schema.schemaMeta.validate(data);
|
|
101
|
-
}
|
|
102
|
-
catch (e) {
|
|
103
|
-
if (e instanceof SchemaError) {
|
|
104
|
-
return {
|
|
105
|
-
globalError: e.errorMessage || `Schema validation failed`,
|
|
106
|
-
globalErrorCode: e.errorCode || "SCHEMA_VALIDATION_FAILED",
|
|
107
|
-
fields: fieldErrors
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
throw e;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// No error ? --> undefined.
|
|
116
|
-
// Otherwise returns the errors.
|
|
117
|
-
//
|
|
118
|
-
if (!fieldErrors)
|
|
119
|
-
return undefined;
|
|
120
|
-
return { fields: fieldErrors };
|
|
121
|
-
}
|
|
122
|
-
const byTypeValidator = {};
|
|
123
|
-
export function registerSchema(schemaId, schema, meta) {
|
|
124
|
-
if (!schemaId) {
|
|
125
|
-
throw new Error("jk_schemas - Schema id required. If you need an uid you can use: " + generateUUIDv4());
|
|
126
|
-
}
|
|
127
|
-
gRegistry[schemaId] = { schema, meta };
|
|
128
|
-
}
|
|
129
|
-
export function getSchemaMeta(schemaId) {
|
|
130
|
-
const entry = gRegistry[schemaId];
|
|
131
|
-
if (entry)
|
|
132
|
-
return entry.schema;
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
export function getSchema(schemaId) {
|
|
136
|
-
const entry = gRegistry[schemaId];
|
|
137
|
-
if (entry)
|
|
138
|
-
return entry.schema;
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
export function requireSchema(schemaId) {
|
|
142
|
-
const s = getSchema(schemaId);
|
|
143
|
-
if (!s) {
|
|
144
|
-
throw new Error(`jk_schemas - Schema ${schemaId} not found`);
|
|
145
|
-
}
|
|
146
|
-
return s;
|
|
147
|
-
}
|
|
148
|
-
const gRegistry = {};
|
|
149
|
-
//endregion
|
|
150
|
-
//region Schema
|
|
151
|
-
export function schema(descriptor, meta) {
|
|
152
|
-
return { desc: descriptor, schemaMeta: meta || {} };
|
|
153
|
-
}
|
|
154
|
-
export function toJson(schema) {
|
|
155
|
-
return schema;
|
|
156
|
-
}
|
|
157
|
-
export function string(title, optional, infos) {
|
|
158
|
-
if (!optional) {
|
|
159
|
-
if (!infos)
|
|
160
|
-
infos = {};
|
|
161
|
-
if (infos.minLength === undefined)
|
|
162
|
-
infos.minLength = 1;
|
|
163
|
-
}
|
|
164
|
-
return { ...infos, title, optional, type: "string" };
|
|
165
|
-
}
|
|
166
|
-
byTypeValidator["string"] = (v, f) => {
|
|
167
|
-
if (typeof v !== "string") {
|
|
168
|
-
declareError(f.errorMessage_theValueIsInvalid || `Value must be a string`, "INVALID_TYPE");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
let sf = f;
|
|
172
|
-
if ((sf.minLength !== undefined) && (v.length < sf.minLength)) {
|
|
173
|
-
declareError(sf.errorMessage_minLength || `Value must be at least ${sf.minLength} characters long`, "INVALID_LENGTH");
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if ((sf.maxLength !== undefined) && (v.length > sf.maxLength)) {
|
|
177
|
-
declareError(sf.errorMessage_maxLength || `Value must be less than ${sf.maxLength} characters long`, "INVALID_LENGTH");
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
export function boolean(title, optional, infos) {
|
|
182
|
-
return { ...infos, title, optional, type: "boolean" };
|
|
183
|
-
}
|
|
184
|
-
byTypeValidator["boolean"] = (v, f) => {
|
|
185
|
-
if (typeof v !== "boolean") {
|
|
186
|
-
declareError(f.errorMessage_theValueIsInvalid || `Value must be a boolean`, "INVALID_TYPE");
|
|
187
|
-
}
|
|
188
|
-
let sf = f;
|
|
189
|
-
if (sf.requireTrue) {
|
|
190
|
-
if (v !== true) {
|
|
191
|
-
declareError(sf.errorMessage_requireTrue || `Value must be true`, "INVALID_VALUE");
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else if (sf.requireFalse) {
|
|
195
|
-
if (v !== false) {
|
|
196
|
-
declareError(sf.errorMessage_requireFalse || `Value must be false`, "INVALID_VALUE");
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
export function number(title, optional, infos) {
|
|
201
|
-
return { ...infos, title, optional, type: "number" };
|
|
202
|
-
}
|
|
203
|
-
export function formatNumber(value, fieldNumber, defaultLocalFormat = "en-US", defaultCurrency = "USD") {
|
|
204
|
-
const amount = parseFloat(value);
|
|
205
|
-
let localFormat = fieldNumber.localFormat || defaultLocalFormat;
|
|
206
|
-
switch (fieldNumber.displayType) {
|
|
207
|
-
case "currency":
|
|
208
|
-
return new Intl.NumberFormat(localFormat, {
|
|
209
|
-
style: "currency",
|
|
210
|
-
currency: fieldNumber.currency || defaultCurrency,
|
|
211
|
-
}).format(amount);
|
|
212
|
-
default:
|
|
213
|
-
return new Intl.NumberFormat(localFormat, { style: fieldNumber.displayType || "decimal" }).format(amount);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
byTypeValidator["number"] = (v, f) => {
|
|
217
|
-
if (typeof v !== "number") {
|
|
218
|
-
declareError(f.errorMessage_theValueIsInvalid || `Value must be a number`, "INVALID_TYPE");
|
|
219
|
-
}
|
|
220
|
-
let sf = f;
|
|
221
|
-
if ((sf.minValue !== undefined) && (v < sf.minValue)) {
|
|
222
|
-
declareError(sf.errorMessage_minValue || `Value must be at least ${sf.minValue}`, "INVALID_LENGTH");
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if ((sf.maxValue !== undefined) && (v > sf.maxValue)) {
|
|
226
|
-
declareError(sf.errorMessage_maxValue || `Value must be less than ${sf.maxValue}`, "INVALID_LENGTH");
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
//endregion
|
|
231
|
-
//region Currency
|
|
232
|
-
export function currency(title, optional, infos) {
|
|
233
|
-
return number(title, optional, { ...infos, displayType: "currency" });
|
|
234
|
-
}
|
|
235
|
-
//endregion
|
|
236
|
-
//region Percent
|
|
237
|
-
export function percent(title, optional, infos) {
|
|
238
|
-
return number(title, optional, { ...infos, displayType: "percent" });
|
|
239
|
-
}
|
|
240
|
-
export function file(title, optional, infos) {
|
|
241
|
-
return { ...infos, title, optional, type: "file" };
|
|
242
|
-
}
|
|
243
|
-
//endregion
|
|
244
|
-
//endregion
|
|
245
|
-
/*const MAKE_OPTIONAL = true;
|
|
246
|
-
//
|
|
247
|
-
const UserSchema1 = schema({
|
|
248
|
-
testOptional: string("testOptional", true),
|
|
249
|
-
testString: string("testString", MAKE_OPTIONAL),
|
|
250
|
-
testBool: boolean("testBool", MAKE_OPTIONAL),
|
|
251
|
-
testNumber: number("testNumber", MAKE_OPTIONAL),
|
|
252
|
-
testFile: file("testFile", MAKE_OPTIONAL)
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
type UserDataType1 = SchemaToType<typeof UserSchema1>;
|
|
256
|
-
let ud1: UserDataType1 = {};*/
|
|
257
|
-
//# sourceMappingURL=jkSchemas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jkSchem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W8B"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface TranslationRequest {
|
|
2
|
-
/**
|
|
3
|
-
* The default value for the translation.
|
|
4
|
-
*/
|
|
5
|
-
default?: string;
|
|
6
|
-
/**
|
|
7
|
-
* The parameters to use for values with parameters
|
|
8
|
-
*/
|
|
9
|
-
params?: any;
|
|
10
|
-
/**
|
|
11
|
-
* If 'count' is more than one, then use plural form.
|
|
12
|
-
*/
|
|
13
|
-
count?: number;
|
|
14
|
-
}
|
|
15
|
-
export declare function setLanguage(languageName: string): void;
|
|
16
|
-
export declare function translate(key: string, p: TranslationRequest): string;
|
|
17
|
-
export declare function translateTo(language: string, key: string, p: TranslationRequest): string;
|
|
18
|
-
export declare function addTranslation(language: string, key: string, value: string): void;
|
|
19
|
-
export declare function addTranslations(language: string, newTranslations: {
|
|
20
|
-
[key: string]: string;
|
|
21
|
-
}): void;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
let gCurrentLanguage = 'en';
|
|
2
|
-
const gTranslations = {};
|
|
3
|
-
export function setLanguage(languageName) {
|
|
4
|
-
gCurrentLanguage = languageName;
|
|
5
|
-
}
|
|
6
|
-
export function translate(key, p) {
|
|
7
|
-
return translateTo(gCurrentLanguage, key, p);
|
|
8
|
-
}
|
|
9
|
-
export function translateTo(language, key, p) {
|
|
10
|
-
// Does it exist?
|
|
11
|
-
if (!gTranslations[language]) {
|
|
12
|
-
gTranslations[language] = {};
|
|
13
|
-
}
|
|
14
|
-
let translation;
|
|
15
|
-
// Must use plural?
|
|
16
|
-
//
|
|
17
|
-
let translationKey = key;
|
|
18
|
-
//
|
|
19
|
-
if ((p.count !== undefined) && (p.count > 1)) {
|
|
20
|
-
const pluralKey = `${key}_plural`;
|
|
21
|
-
translation = gTranslations[language][pluralKey];
|
|
22
|
-
}
|
|
23
|
-
// Get the translation.
|
|
24
|
-
if (!translation) {
|
|
25
|
-
translation = gTranslations[language][translationKey];
|
|
26
|
-
}
|
|
27
|
-
// Not found?
|
|
28
|
-
if (!translation) {
|
|
29
|
-
if (p.default) {
|
|
30
|
-
gTranslations[language][translationKey] = p.default;
|
|
31
|
-
return p.default;
|
|
32
|
-
}
|
|
33
|
-
translation = `[trNotFound:${key}]`;
|
|
34
|
-
}
|
|
35
|
-
// Replace the parameters in the translation.
|
|
36
|
-
if (p.params && translation.includes("$")) {
|
|
37
|
-
for (const [paramKey, paramValue] of Object.entries(p.params)) {
|
|
38
|
-
const placeholder = "$" + paramKey;
|
|
39
|
-
translation = translation.replace(placeholder, String(paramValue));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return translation;
|
|
43
|
-
}
|
|
44
|
-
export function addTranslation(language, key, value) {
|
|
45
|
-
if (!gTranslations[language]) {
|
|
46
|
-
gTranslations[language] = {};
|
|
47
|
-
}
|
|
48
|
-
gTranslations[language][key] = value;
|
|
49
|
-
}
|
|
50
|
-
export function addTranslations(language, newTranslations) {
|
|
51
|
-
if (!gTranslations[language]) {
|
|
52
|
-
gTranslations[language] = {};
|
|
53
|
-
}
|
|
54
|
-
Object.assign(gTranslations[language], newTranslations);
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jk_translate/index.ts"],"names":[],"mappings":"AAAA,IAAI,gBAAgB,GAAG,IAAI,CAAC;AAC5B,MAAM,aAAa,GAAsD,EAAE,CAAC;AAmB5E,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC5C,gBAAgB,GAAG,YAAY,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,CAAqB;IACxD,OAAO,WAAW,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,GAAW,EAAE,CAAqB;IAC5E,iBAAiB;IACjB,IAAI,CAAC,aAAa,CAAC,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