vortez 5.0.0-dev.18 → 5.0.0

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 (136) hide show
  1. package/.gitignore +11 -4
  2. package/README.md +699 -177
  3. package/build/Template/Compiler.d.ts +70 -0
  4. package/build/Template/Compiler.js +135 -0
  5. package/build/Template/Compiler.js.map +1 -0
  6. package/build/Template/StreamCompiler.d.ts +16 -0
  7. package/build/Template/StreamCompiler.js +54 -0
  8. package/build/Template/StreamCompiler.js.map +1 -0
  9. package/build/Template/Template.d.ts +49 -0
  10. package/build/Template/Template.js +77 -0
  11. package/build/Template/Template.js.map +1 -0
  12. package/build/Vortez.d.ts +2 -1
  13. package/build/Vortez.js +2 -1
  14. package/build/Vortez.js.map +1 -1
  15. package/build/beta/JwtManager/JwtError.d.ts +8 -0
  16. package/build/beta/JwtManager/JwtError.js +10 -0
  17. package/build/beta/JwtManager/JwtError.js.map +1 -0
  18. package/build/beta/JwtManager/JwtManager.d.ts +3 -0
  19. package/build/beta/JwtManager/JwtManager.js +24 -7
  20. package/build/beta/JwtManager/JwtManager.js.map +1 -1
  21. package/build/server/BodyParser.d.ts +6 -0
  22. package/build/server/BodyParser.js +18 -3
  23. package/build/server/BodyParser.js.map +1 -1
  24. package/build/server/Request.d.ts +6 -4
  25. package/build/server/Request.js +15 -10
  26. package/build/server/Request.js.map +1 -1
  27. package/build/server/Response.d.ts +25 -10
  28. package/build/server/Response.js +161 -75
  29. package/build/server/Response.js.map +1 -1
  30. package/build/server/Server.d.ts +4 -4
  31. package/build/server/Server.js +34 -11
  32. package/build/server/Server.js.map +1 -1
  33. package/build/server/ServerDebug.d.ts +10 -1
  34. package/build/server/ServerDebug.js +85 -17
  35. package/build/server/ServerDebug.js.map +1 -1
  36. package/build/server/config/Config.d.ts +276 -47
  37. package/build/server/config/Config.js +70 -47
  38. package/build/server/config/Config.js.map +1 -1
  39. package/build/server/config/{ConfigLoader.d.ts → Loader.d.ts} +4 -5
  40. package/build/server/config/{ConfigLoader.js → Loader.js} +8 -11
  41. package/build/server/config/Loader.js.map +1 -0
  42. package/build/server/router/Router.d.ts +88 -31
  43. package/build/server/router/Router.js +113 -51
  44. package/build/server/router/Router.js.map +1 -1
  45. package/build/server/router/algorithm/Algorithm.d.ts +39 -0
  46. package/build/server/router/algorithm/Algorithm.js +20 -0
  47. package/build/server/router/algorithm/Algorithm.js.map +1 -0
  48. package/build/server/router/algorithm/FIFO.d.ts +15 -0
  49. package/build/server/router/algorithm/FIFO.js +24 -0
  50. package/build/server/router/algorithm/FIFO.js.map +1 -0
  51. package/build/server/router/algorithm/Tree.d.ts +38 -0
  52. package/build/server/router/algorithm/Tree.js +126 -0
  53. package/build/server/router/algorithm/Tree.js.map +1 -0
  54. package/build/server/router/middleware/HttpMiddleware.js +1 -1
  55. package/build/server/router/middleware/HttpMiddleware.js.map +1 -1
  56. package/build/server/router/middleware/WsMiddleware.js +1 -1
  57. package/build/server/router/middleware/WsMiddleware.js.map +1 -1
  58. package/build/server/security/PathSecurity.d.ts +45 -0
  59. package/build/server/security/PathSecurity.js +108 -0
  60. package/build/server/security/PathSecurity.js.map +1 -0
  61. package/build/server/websocket/Websocket.js +4 -1
  62. package/build/server/websocket/Websocket.js.map +1 -1
  63. package/build/utilities/ConsoleUI.d.ts +2 -1
  64. package/build/utilities/ConsoleUI.js +2 -1
  65. package/build/utilities/ConsoleUI.js.map +1 -1
  66. package/build/utilities/DebugUI.d.ts +1 -1
  67. package/build/utilities/DebugUI.js +1 -1
  68. package/build/utilities/Encoding.d.ts +22 -0
  69. package/build/utilities/Encoding.js +26 -0
  70. package/build/utilities/Encoding.js.map +1 -0
  71. package/build/utilities/Env.js +7 -2
  72. package/build/utilities/Env.js.map +1 -1
  73. package/build/utilities/File.d.ts +10 -0
  74. package/build/utilities/File.js +19 -0
  75. package/build/utilities/File.js.map +1 -0
  76. package/build/utilities/Flatten.d.ts +73 -0
  77. package/build/utilities/Flatten.js +76 -0
  78. package/build/utilities/Flatten.js.map +1 -0
  79. package/build/utilities/Object.d.ts +16 -0
  80. package/build/utilities/Object.js +48 -0
  81. package/build/utilities/Object.js.map +1 -0
  82. package/build/utilities/Path.d.ts +31 -11
  83. package/build/utilities/Path.js +48 -15
  84. package/build/utilities/Path.js.map +1 -1
  85. package/build/utilities/Time.d.ts +21 -0
  86. package/build/utilities/Time.js +25 -0
  87. package/build/utilities/Time.js.map +1 -0
  88. package/build/utilities/Utilities.d.ts +50 -92
  89. package/build/utilities/Utilities.js +56 -71
  90. package/build/utilities/Utilities.js.map +1 -1
  91. package/build/utilities/schema/Introspection.d.ts +24 -0
  92. package/build/utilities/schema/Introspection.js +87 -0
  93. package/build/utilities/schema/Introspection.js.map +1 -0
  94. package/build/utilities/schema/JSONSchema.d.ts +68 -0
  95. package/build/utilities/schema/JSONSchema.js +13 -0
  96. package/build/utilities/schema/JSONSchema.js.map +1 -0
  97. package/build/utilities/schema/Schema.d.ts +253 -0
  98. package/build/utilities/schema/Schema.js +241 -0
  99. package/build/utilities/schema/Schema.js.map +1 -0
  100. package/build/utilities/schema/SchemaError.d.ts +10 -0
  101. package/build/utilities/schema/SchemaError.js +13 -0
  102. package/build/utilities/schema/SchemaError.js.map +1 -0
  103. package/build/utilities/schema/Validator.d.ts +94 -0
  104. package/build/utilities/schema/Validator.js +246 -0
  105. package/build/utilities/schema/Validator.js.map +1 -0
  106. package/changes.md +4 -0
  107. package/docs/ARCHITECTURE.md +142 -0
  108. package/global/style/template/error.css +29 -0
  109. package/global/style/template/folder.css +79 -0
  110. package/global/{Style/Template/Template.css → style/template/template.css} +60 -68
  111. package/global/template/error.vhtml +29 -0
  112. package/global/template/folder.vhtml +54 -0
  113. package/package.json +2 -2
  114. package/build/Template.d.ts +0 -46
  115. package/build/Template.js +0 -81
  116. package/build/Template.js.map +0 -1
  117. package/build/server/config/ConfigLoader.js.map +0 -1
  118. package/build/server/config/ConfigValidator.d.ts +0 -71
  119. package/build/server/config/ConfigValidator.js +0 -131
  120. package/build/server/config/ConfigValidator.js.map +0 -1
  121. package/examples/in-docs.js +0 -96
  122. package/global/Style/Template/Error.css +0 -30
  123. package/global/Style/Template/Folder.css +0 -77
  124. package/global/Template/Error.vhtml +0 -29
  125. package/global/Template/Folder.vhtml +0 -41
  126. package/tests/Template/template.js +0 -18
  127. package/tests/Template/template.txt +0 -13
  128. package/tests/Template/template.vhtml +0 -23
  129. package/tests/debug.js +0 -34
  130. package/tests/jwtManager/jwtManager.js +0 -342
  131. package/tests/test.js +0 -131
  132. package/tests/test.vhtml +0 -14
  133. package/tests/utilities.js +0 -28
  134. package/tests/websocket.vhtml +0 -86
  135. /package/global/{Source/Logo_960.png → source/logo_960.png} +0 -0
  136. /package/global/{Source/Logo_SM_960.png → source/logo_SM_960.png} +0 -0
@@ -1,120 +1,99 @@
1
1
  /**
2
2
  * @author NetFeez <netfeez.dev@gmail.com>
3
- * @description add useful functions to the Vortez.
3
+ * @description Exports all utility classes and functions, providing a centralized access point for various helper methods used throughout the project.
4
+ * This includes:
5
+ * - file operations: `Utilities.File`.
6
+ * - object manipulation: `Utilities.Object`.
7
+ * - encoding: `Utilities.Encoding`.
8
+ * - time utilities: `Utilities.Time`.
9
+ * and more utilities.
4
10
  * @license Apache-2.0
5
11
  */
6
- import { promises as FSP } from "fs";
7
12
  import _Path from './Path.js';
8
13
  import _Env from './Env.js';
9
14
  import _ConsoleUI from './ConsoleUI.js';
10
15
  import _DebugUI from './DebugUI.js';
16
+ import _Schema from './schema/Schema.js';
17
+ import _Flatten from './Flatten.js';
18
+ import _File from './File.js';
19
+ import _Object from './Object.js';
20
+ import _Encoding from './Encoding.js';
21
+ import _Time from './Time.js';
11
22
  export { Path } from './Path.js';
12
23
  export { Env } from './Env.js';
13
24
  export { ConsoleUI } from './ConsoleUI.js';
14
25
  export { DebugUI } from './DebugUI.js';
26
+ export { Schema } from './schema/Schema.js';
27
+ export { Flatten } from './Flatten.js';
28
+ export { File } from './File.js';
29
+ export { Object } from './Object.js';
30
+ export { Encoding } from './Encoding.js';
31
+ export { Time } from './Time.js';
15
32
  export class Utilities {
16
33
  /**
17
- * Checks if a file exists asynchronously.
18
- * @param path - The path to the file.
19
- * @returns A promise that resolves to `true` if the file exists, `false` otherwise.
34
+ * Checks if a file exists at the given path.
35
+ * @param path - The file path to check.
36
+ * @returns A promise that resolves to true if the file exists, false otherwise.
37
+ * @deprecated Use Utilities.File.exists instead.
20
38
  */
21
39
  static async fileExists(path) {
22
- return FSP.access(path).then(() => true).catch(() => false);
40
+ return Utilities.File.exists(path);
23
41
  }
24
42
  /**
25
- * Compares two objects recursively for deep equality.
26
- * @param obj1 - The first object to compare.
27
- * @param obj2 - The second object to compare.
28
- * @returns A boolean indicating whether the objects are deeply equal or not.
43
+ * Checks if two values are deeply equal.
44
+ * @param obj1 - The first value to compare.
45
+ * @param obj2 - The second value to compare.
46
+ * @returns A boolean indicating if the values are deeply equal.
47
+ * @deprecated Use Utilities.Object.deepEqual instead.
29
48
  */
30
49
  static deepEqual(obj1, obj2) {
31
- if (obj1 === obj2)
32
- return true;
33
- if (typeof obj1 !== typeof obj2 ||
34
- obj1 === null || obj2 === null)
35
- return false;
36
- const keys1 = Object.keys(obj1);
37
- const keys2 = Object.keys(obj2);
38
- if (keys1.length !== keys2.length)
39
- return false;
40
- for (const key of keys1)
41
- if (!keys2.includes(key) ||
42
- !this.deepEqual(obj1[key], obj2[key]))
43
- return false;
44
- return true;
50
+ return Utilities.Object.deepEqual(obj1, obj2);
45
51
  }
46
52
  /**
47
- * Flattens a nested object into a single-level object with dot notation keys.
53
+ * Flattens a nested object into a single-level object with dot-separated keys.
48
54
  * @param object - The object to flatten.
49
- * @param depth - The maximum depth to which the object should be flattened.
50
- * @returns The flattened object.
55
+ * @param depth - The maximum depth to flatten (default is 10).
56
+ * @returns A new object with flattened keys.
57
+ * @deprecated Use Utilities.Flatten.object instead.
51
58
  */
52
59
  static flattenObject(object, depth = 10) {
53
- return this.flattenCore(object, depth);
54
- }
55
- static flattenCore(object, depth = 10, prefix = '') {
56
- const result = {};
57
- for (const key in object) {
58
- const newKey = prefix ? `${prefix}.${key}` : key;
59
- const value = object[key];
60
- if (typeof value === 'object' && !Array.isArray(value) && value !== null && depth > 0) {
61
- Object.assign(result, Utilities.flattenCore(value, depth - 1, newKey));
62
- }
63
- else {
64
- result[newKey] = value;
65
- }
66
- }
67
- return result;
60
+ return Utilities.Flatten.object(object, depth);
68
61
  }
69
62
  /**
70
- * Reconstructs a nested object from a flattened object with dot notation keys.
71
- * @template Result - The type of the unflattened object.
72
- * @param obj - The flattened object to un flatten.
73
- * @returns The unflattened object.
63
+ * Unflattens a flattened object back into its original nested structure.
64
+ * @param obj - The flattened object to unflatten.
65
+ * @returns A new object with the original nested structure.
66
+ * @deprecated Use Utilities.Flatten.unObject instead.
74
67
  */
75
68
  static unFlattenObject(obj) {
76
- const result = {};
77
- for (const key in obj) {
78
- const value = obj[key];
79
- const [first, ...rest] = key.split('.');
80
- if (rest.length === 0)
81
- result[first] = value;
82
- else {
83
- const last = rest.pop();
84
- const subObj = result[first] ?? {};
85
- let current = subObj;
86
- rest.forEach((k) => {
87
- current = current[k] ?? (current[k] = {});
88
- });
89
- current[last] = value;
90
- result[first] = subObj;
91
- }
92
- }
93
- return result;
69
+ return Utilities.Flatten.unObject(obj);
94
70
  }
95
71
  /**
96
- * Pauses the execution of the program for a specified duration.
72
+ * Pauses execution for a specified duration.
97
73
  * @param ms - The number of milliseconds to sleep.
98
74
  * @returns A promise that resolves after the given time.
75
+ * @deprecated Use Utilities.Time.sleep instead.
99
76
  */
100
77
  static sleep(ms) {
101
- return new Promise(resolve => setTimeout(resolve, ms));
78
+ return Utilities.Time.sleep(ms);
102
79
  }
103
80
  /**
104
81
  * Encodes a string to base64url format.
105
- * @param data - The string that needs to be encoded.
82
+ * @param data - The string to encode.
106
83
  * @returns The base64url-encoded string.
84
+ * @deprecated Use Utilities.Encoding.base64UrlEncode instead.
107
85
  */
108
86
  static base64UrlEncode(data) {
109
- return Buffer.from(data).toString('base64url');
87
+ return Utilities.Encoding.base64UrlEncode(data);
110
88
  }
111
89
  /**
112
90
  * Decodes a base64url-encoded string.
113
- * @param data - The base64url-encoded string that needs to be decoded.
114
- * @returns The decoded string.
91
+ * @param data - The base64url-encoded string to decode.
92
+ * @returns The decoded UTF-8 string.
93
+ * @deprecated Use Utilities.Encoding.base64UrlDecode instead.
115
94
  */
116
95
  static base64UrlDecode(data) {
117
- return Buffer.from(data, 'base64url').toString('utf8');
96
+ return Utilities.Encoding.base64UrlDecode(data);
118
97
  }
119
98
  }
120
99
  (function (Utilities) {
@@ -122,6 +101,12 @@ export class Utilities {
122
101
  Utilities.Env = _Env;
123
102
  Utilities.ConsoleUI = _ConsoleUI;
124
103
  Utilities.DebugUI = _DebugUI;
104
+ Utilities.Schema = _Schema;
105
+ Utilities.Flatten = _Flatten;
106
+ Utilities.File = _File;
107
+ Utilities.Object = _Object;
108
+ Utilities.Encoding = _Encoding;
109
+ Utilities.Time = _Time;
125
110
  })(Utilities || (Utilities = {}));
126
111
  export default Utilities;
127
112
  //# sourceMappingURL=Utilities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Utilities.js","sourceRoot":"","sources":["../../src/utilities/Utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,IAAI,CAAC;AAErC,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,IAAI,MAAM,UAAU,CAAC;AAC5B,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,QAAQ,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAO,S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QAAQ,CAAS,GAAiC,CAAC,CAAC;IACjF,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,EAAU;QAC1B,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,IAAY;QACtC,OAAO,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,IAAY;QACtC,OAAO,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACJ;AACD,WAAiB,SAAS;IACR,cAAI,GAAG,KAAK,CAAC;IACb,aAAG,GAAG,IAAI,CAAC;IACX,mBAAS,GAAG,UAAU,CAAC;IACvB,iBAAO,GAAG,QAAQ,CAAC;IACnB,gBAAM,GAAG,OAAO,CAAC;IACjB,iBAAO,GAAG,QAAQ,CAAC;IACnB,cAAI,GAAG,KAAK,CAAC;IACb,gBAAM,GAAG,OAAO,CAAC;IACjB,kBAAQ,GAAG,SAAS,CAAC;IACrB,cAAI,GAAG,KAAK,CAAC;AA0C/B,CAAC,EApDgB,SAAS,KAAT,SAAS,QAoDzB;AACD,eAAe,SAAS,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
+ * @description Provides utilities for schema introspection, including listing unique properties and converting custom schemas to JSON Schema format.
4
+ * @license Apache-2.0
5
+ */
6
+ import type { JSONSchema } from './JSONSchema.js';
7
+ import type { Schema } from './Schema.js';
8
+ export declare class Introspection {
9
+ /**
10
+ * Lists all unique properties in a schema, including nested unique properties, and returns their full paths.
11
+ * @param doc The schema to list unique properties from
12
+ * @param parentKey The parent key of the current schema, used for building full paths of nested properties
13
+ * @returns An array of full paths to unique properties in the schema
14
+ */
15
+ static listUniques(doc: Schema.Schema, parentKey?: string): string[];
16
+ /**
17
+ * Converts a schema to a JSON Schema, used for validating data against the schema and generating documentation.
18
+ * @param schema The schema to convert to JSON Schema
19
+ * @returns The JSON Schema representation of the input schema
20
+ */
21
+ static toJsonSchema(schema: Schema.Schema): JSONSchema.schema;
22
+ }
23
+ export declare namespace Introspection { }
24
+ export default Introspection;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
+ * @description Provides utilities for schema introspection, including listing unique properties and converting custom schemas to JSON Schema format.
4
+ * @license Apache-2.0
5
+ */
6
+ export class Introspection {
7
+ /**
8
+ * Lists all unique properties in a schema, including nested unique properties, and returns their full paths.
9
+ * @param doc The schema to list unique properties from
10
+ * @param parentKey The parent key of the current schema, used for building full paths of nested properties
11
+ * @returns An array of full paths to unique properties in the schema
12
+ */
13
+ static listUniques(doc, parentKey) {
14
+ const uniques = [];
15
+ for (const key in doc) {
16
+ const prop = doc[key];
17
+ if (key !== '_id' && prop.unique)
18
+ uniques.push(parentKey ? `${parentKey}.${key}` : key);
19
+ if (prop.type === 'object') {
20
+ uniques.push(...this.listUniques(prop.schema, parentKey ? `${parentKey}.${key}` : key));
21
+ }
22
+ }
23
+ return uniques;
24
+ }
25
+ /**
26
+ * Converts a schema to a JSON Schema, used for validating data against the schema and generating documentation.
27
+ * @param schema The schema to convert to JSON Schema
28
+ * @returns The JSON Schema representation of the input schema
29
+ */
30
+ static toJsonSchema(schema) {
31
+ const sch = {};
32
+ sch.type = 'object';
33
+ sch.properties = {};
34
+ for (const key in schema) {
35
+ const prop = schema[key];
36
+ let subSch = {};
37
+ subSch.type = prop.nullable ? [prop.type, 'null'] : prop.type;
38
+ if (prop.required) {
39
+ if (sch.required == null)
40
+ sch.required = [];
41
+ sch.required.push(key);
42
+ }
43
+ switch (prop.type) {
44
+ case 'string': {
45
+ if (prop.enum !== undefined)
46
+ subSch.enum = [...prop.enum];
47
+ if (prop.minLength !== undefined)
48
+ subSch.minLength = prop.minLength;
49
+ if (prop.maxLength !== undefined)
50
+ subSch.maxLength = prop.maxLength;
51
+ if (prop.pattern !== undefined)
52
+ subSch.pattern = prop.pattern.source;
53
+ break;
54
+ }
55
+ case 'boolean': break;
56
+ case 'number': {
57
+ if (prop.minimum !== undefined)
58
+ subSch.minimum = prop.minimum;
59
+ if (prop.maximum !== undefined)
60
+ subSch.maximum = prop.maximum;
61
+ break;
62
+ }
63
+ case 'array': {
64
+ if (prop.minimum !== undefined)
65
+ subSch.minItems = prop.minimum;
66
+ if (prop.maximum !== undefined)
67
+ subSch.maxItems = prop.maximum;
68
+ const itemContainer = this.toJsonSchema({ item: prop.property });
69
+ const itemSchema = itemContainer.properties?.item;
70
+ if (itemSchema)
71
+ subSch.items = itemSchema;
72
+ break;
73
+ }
74
+ case 'object': {
75
+ subSch = this.toJsonSchema(prop.schema);
76
+ if (prop.nullable)
77
+ subSch.type = ['object', 'null'];
78
+ break;
79
+ }
80
+ }
81
+ sch.properties[key] = subSch;
82
+ }
83
+ return sch;
84
+ }
85
+ }
86
+ export default Introspection;
87
+ //# sourceMappingURL=Introspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Introspection.js","sourceRoot":"","sources":["../../../src/utilities/schema/Introspection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,OAAO,aAAa;IACtB;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,GAAkB,EAAE,SAAkB;QAC5D,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;YACpB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,GAAG,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM;gBAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACxF,IAAI,IAAI,CAAC,IAAI,KA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AAC,CAAC;oBACpD,MAAM;gBACV,CAAC;YACL,CAAC;YACD,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QACjC,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
+ * @description Provides type definitions for JSON Schema, a powerful tool for validating and describing the structure of JSON data.
4
+ * @license Apache-2.0
5
+ */
6
+ export declare namespace JSONSchema {
7
+ type schemeArray = schemeTypes[];
8
+ type schemaObject = {
9
+ [key: string]: schemeTypes;
10
+ };
11
+ interface SchemaTypeMap {
12
+ string: string;
13
+ number: number;
14
+ boolean: boolean;
15
+ object: schemaObject;
16
+ array: schemeArray;
17
+ null: null;
18
+ }
19
+ type schemaNames = keyof SchemaTypeMap;
20
+ type schemeTypes = SchemaTypeMap[schemaNames];
21
+ type schemaVersion = string;
22
+ type schema = {
23
+ title?: string;
24
+ description?: string;
25
+ multipleOf?: number;
26
+ maximum?: number;
27
+ exclusiveMaximum?: boolean;
28
+ minimum?: number;
29
+ exclusiveMinimum?: boolean;
30
+ maxLength?: number;
31
+ minLength?: number;
32
+ pattern?: string;
33
+ additionalItems?: schema;
34
+ items?: schema | schema[];
35
+ maxItems?: number;
36
+ minItems?: number;
37
+ uniqueItems?: boolean;
38
+ maxProperties?: number;
39
+ minProperties?: number;
40
+ required?: string[];
41
+ properties?: {
42
+ [key: string]: schema;
43
+ };
44
+ additionalProperties?: boolean | schema;
45
+ patternProperties?: {
46
+ [key: string]: schema;
47
+ };
48
+ dependencies?: {
49
+ [key: string]: string[] | schema;
50
+ };
51
+ enum?: schemeTypes[];
52
+ type?: schemaNames | schemaNames[];
53
+ allOf?: schema[];
54
+ anyOf?: schema[];
55
+ oneOf?: schema[];
56
+ not?: schema;
57
+ extends?: string | string[];
58
+ };
59
+ }
60
+ /**
61
+ * provide the type definition of a json schema
62
+ * @param schema the json schema to validate
63
+ */
64
+ export declare function schema(schema: JSONSchema.schema): JSONSchema.schema;
65
+ export declare const JSONSchema: {
66
+ schema: typeof schema;
67
+ };
68
+ export default JSONSchema;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
+ * @description Provides type definitions for JSON Schema, a powerful tool for validating and describing the structure of JSON data.
4
+ * @license Apache-2.0
5
+ */
6
+ /**
7
+ * provide the type definition of a json schema
8
+ * @param schema the json schema to validate
9
+ */
10
+ export function schema(schema) { return schema; }
11
+ export const JSONSchema = { schema };
12
+ export default JSONSchema;
13
+ //# sourceMappingURL=JSONSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JSONSchema.js","sourceRoot":"","sources":["../../../src/utilities/schema/JSONSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoEH;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,MAAyB,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,MAAM,EAAE,CAAC;AACrC,eAAe,UAAU,CAAC"}
@@ -0,0 +1,253 @@
1
+ /**
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
+ * @description Provides a comprehensive schema validation and processing system, allowing developers to define complex data structures.
4
+ * @license Apache-2.0
5
+ */
6
+ import type Utilities from '../Utilities.js';
7
+ import _SchemaError from './SchemaError.js';
8
+ import _JSONSchema from './JSONSchema.js';
9
+ import _Introspection from './Introspection.js';
10
+ import _Validator from './Validator.js';
11
+ export { SchemaError } from './SchemaError.js';
12
+ export { JSONSchema } from './JSONSchema.js';
13
+ export { Introspection } from './Introspection.js';
14
+ export { Validator } from './Validator.js';
15
+ export declare class Schema<const S extends Schema.Schema> {
16
+ readonly schema: S;
17
+ constructor(schema: S);
18
+ /**
19
+ * Get the inferred type of the schema.
20
+ *
21
+ * ⚠️ IMPORTANT: This getter returns an EMPTY object. It is designed ONLY for type inference.
22
+ *
23
+ * Usage: Use with `typeof` to extract the inferred type:
24
+ * ```typescript
25
+ * type infered = typeof schemaInstance.infer;
26
+ * ```
27
+ *
28
+ * DO NOT use the returned value at runtime - it's always an empty object.
29
+ * This is purely a TypeScript type utility.
30
+ *
31
+ * @returns An empty object with the inferred type
32
+ */
33
+ get infer(): Schema.Infer<this['schema']>;
34
+ /**
35
+ * Get the inferred type of the schema for processing (i.e., before applying defaults and handling optional properties).
36
+ *
37
+ * ⚠️ IMPORTANT: This getter returns an EMPTY object. It is designed ONLY for type inference.
38
+ *
39
+ * Usage: Use with `typeof` to extract the inferred type for processing:
40
+ * ```typescript
41
+ * type inferedToProcess = typeof schemaInstance.inferToProcess;
42
+ * ```
43
+ *
44
+ * DO NOT use the returned value at runtime - it's always an empty object.
45
+ * This is purely a TypeScript type utility.
46
+ */
47
+ get inferToProcess(): Schema.InferToProcess<this['schema']>;
48
+ /**
49
+ * get the json schema as an object
50
+ * @returns the json schema
51
+ */
52
+ get jsonSchema(): Schema.JSONSchema.schema;
53
+ /**
54
+ * get the json schema as a JSON string
55
+ * @returns the json schema as a string
56
+ */
57
+ get jsonSchemaJSON(): string;
58
+ /**
59
+ * get the list of unique keys
60
+ * @returns the list of unique keys
61
+ */
62
+ get uniques(): string[];
63
+ /**
64
+ * process the provided data
65
+ * @param data the data to process
66
+ * @param partial if the data is partial
67
+ * @returns the processed data
68
+ * @throws schemaError if the data is not valid
69
+ */
70
+ processData(data: Schema.Infer<this['schema']>, partial?: boolean): Schema.Infer<this['schema']>;
71
+ processData(data: Schema.InferToProcess<this['schema']>, partial?: boolean): Schema.Infer<this['schema']>;
72
+ /**
73
+ * process the provided data as partial, meaning that it will only validate the provided properties and ignore the rest.
74
+ * this is useful for validating data that is only meant to update a document, where only a subset of the properties are provided.
75
+ * @param data the data to process
76
+ * @returns the processed data
77
+ * @throws schemaError if the data is not valid
78
+ */
79
+ processPartialData(data: Partial<Schema.FlattenToProcess<this['schema']>> & Partial<Schema.InferToProcess<this['schema']>> & Schema.Document): Partial<Schema.Flatten<this['schema']>> & Partial<Schema.Infer<this['schema']>> & Schema.Document;
80
+ processPartialData(data: Partial<Schema.Flatten<this['schema']>> & Partial<Schema.Infer<this['schema']>> & Schema.Document): Partial<Schema.Flatten<this['schema']>> & Partial<Schema.Infer<this['schema']>> & Schema.Document;
81
+ /**
82
+ * process a property
83
+ * @param data the data to process
84
+ * @param prop the property to process
85
+ * @param key the key of the property
86
+ * @param partial if the data is partial
87
+ * @returns the processed data
88
+ * @throws schemaError if the data is not valid
89
+ */
90
+ protected processProperty(data: any, prop: Schema.property, key: string, partial?: boolean): any;
91
+ /**
92
+ * validate a array
93
+ * @param value the value to validate
94
+ * @param prop the property to validate
95
+ * @param key the key of the property
96
+ * @returns the data
97
+ * @throws schemaError if the data is not valid
98
+ */
99
+ protected processArray(value: any[], prop: Schema.Property.Array, key: string): any;
100
+ /**
101
+ * validate a object
102
+ * @param value the value to validate
103
+ * @param prop the property to validate
104
+ * @param key the key of the property
105
+ * @returns the data
106
+ * @throws schemaError if the data is not valid
107
+ */
108
+ protected processObject(value: any, prop: Schema.Property.Object, key: string, partial?: boolean): any;
109
+ /**
110
+ * validate a array
111
+ * @param value the value to validate
112
+ * @param prop the property to validate
113
+ * @param key the key of the property
114
+ * @throws schemaError if the data is not valid
115
+ */
116
+ protected validateArray(value: any, prop: Schema.Property.Array, key: string): void;
117
+ /**
118
+ * generate a list of unique keys
119
+ * @param doc the schema to validate
120
+ * @param parentKey the parent key of the schema
121
+ * @returns a list of unique keys
122
+ */
123
+ protected listUniques(doc?: Schema.Schema, parentKey?: string): string[];
124
+ /**
125
+ * convert a schema to a JSON schema
126
+ * @param schema the schema to convert
127
+ * @returns the JSON schema
128
+ */
129
+ protected toJsonSchema(schema?: Schema.Schema): Schema.JSONSchema.schema;
130
+ /**
131
+ * -- TYPE GUARD --
132
+ * verify if the key is in the schema
133
+ * @param doc the object to verify
134
+ * @param key the key to verify
135
+ * @returns true if the key is in the schema
136
+ */
137
+ private isKeyOf;
138
+ }
139
+ export declare namespace Schema {
140
+ export import SchemaError = _SchemaError;
141
+ export import JSONSchema = _JSONSchema;
142
+ export import Introspection = _Introspection;
143
+ export import Validator = _Validator;
144
+ type Infer<S extends Schema> = Schema.Infer.schema<S>;
145
+ type InferToProcess<S extends Schema> = Schema.Infer.schemaToProcess<S>;
146
+ type Flatten<S extends Schema.Schema> = (Utilities.Flatten.Object<Infer.schema<S>, 10>);
147
+ type FlattenToProcess<S extends Schema.Schema> = (Utilities.Flatten.Object<Infer.schemaToProcess<S>, 10>);
148
+ interface Document {
149
+ [Key: string]: any;
150
+ }
151
+ interface TypeMap {
152
+ string: string;
153
+ number: number;
154
+ boolean: boolean;
155
+ object: any;
156
+ array: any[];
157
+ }
158
+ namespace Helper {
159
+ type HasDefault<T> = T extends {
160
+ default: any;
161
+ } ? true : false;
162
+ type IsRequired<T> = T extends {
163
+ required: true;
164
+ } ? true : false;
165
+ type IsNullable<T> = T extends {
166
+ nullable: true;
167
+ } ? true : false;
168
+ type DefaultValue<T> = T extends {
169
+ default: infer D;
170
+ } ? D : never;
171
+ type Prettify<T> = {
172
+ [K in keyof T]: T[K];
173
+ } & {};
174
+ }
175
+ namespace Property {
176
+ interface Base<T extends keyof TypeMap> {
177
+ type: T;
178
+ required?: boolean;
179
+ nullable?: boolean;
180
+ unique?: boolean;
181
+ default?: TypeMap[T] | null;
182
+ }
183
+ export interface String extends Base<'string'> {
184
+ enum?: readonly string[];
185
+ pattern?: RegExp;
186
+ minLength?: number;
187
+ maxLength?: number;
188
+ }
189
+ export interface Number extends Base<'number'> {
190
+ minimum?: number;
191
+ maximum?: number;
192
+ }
193
+ export interface Boolean extends Base<'boolean'> {
194
+ }
195
+ export interface Object extends Base<'object'> {
196
+ schema: Schema;
197
+ }
198
+ export interface Array extends Base<'array'> {
199
+ property: property;
200
+ minimum?: number;
201
+ maximum?: number;
202
+ }
203
+ export interface Map {
204
+ string: String;
205
+ number: Number;
206
+ boolean: Boolean;
207
+ object: Object;
208
+ array: Array;
209
+ }
210
+ export {};
211
+ }
212
+ type property = Property.Map[keyof Property.Map];
213
+ interface Schema {
214
+ [Key: string]: property;
215
+ }
216
+ namespace Infer {
217
+ export type Mode = 'partial' | 'process' | 'complete';
218
+ type ObjectByMode<S extends Schema.Schema, M extends Mode> = (M extends 'process' ? schemaToProcess<S> : M extends 'partial' ? schemaPartial<S> : schema<S>);
219
+ export type propertyType<P extends Schema.property, M extends Mode = 'complete'> = (P extends Property.String ? P extends {
220
+ enum: readonly (infer E extends string)[];
221
+ } ? E : string : P extends Property.Number ? number : P extends Property.Boolean ? boolean : P extends Property.Object ? (ObjectByMode<P['schema'], M>) : P extends Property.Array ? propertyType<P['property'], M>[] : never);
222
+ type OptionalPropertyValue<P extends Schema.property, M extends Mode> = (Helper.IsNullable<P> extends true ? propertyType<P, M> | null : propertyType<P, M> | undefined);
223
+ type DefaultedPropertyValue<P extends Schema.property, M extends Mode> = (Helper.DefaultValue<P> extends null ? propertyType<P, M> | null : propertyType<P, M>);
224
+ type RequiredPropertyValue<P extends Schema.property, M extends Mode> = (Helper.IsNullable<P> extends true ? propertyType<P, M> | null : propertyType<P, M>);
225
+ export type property<P extends Schema.property, M extends Mode = 'complete'> = (Helper.HasDefault<P> extends true ? DefaultedPropertyValue<P, M> : Helper.IsRequired<P> extends true ? RequiredPropertyValue<P, M> : OptionalPropertyValue<P, M>);
226
+ type RequiredKeys<S extends Schema> = {
227
+ [K in keyof S]: Helper.IsRequired<S[K]> extends true ? K : Helper.HasDefault<S[K]> extends true ? K : never;
228
+ }[keyof S];
229
+ type OptionalKeys<S extends Schema> = Exclude<keyof S, RequiredKeys<S>>;
230
+ type RequiredToProcessKeys<S extends Schema> = {
231
+ [K in keyof S]: Helper.IsRequired<S[K]> extends true ? Helper.HasDefault<S[K]> extends false ? K : never : never;
232
+ }[keyof S];
233
+ type OptionalToProcessKeys<S extends Schema> = Exclude<keyof S, RequiredToProcessKeys<S>>;
234
+ export type schema<S extends Schema> = Helper.Prettify<{
235
+ [K in RequiredKeys<S>]: property<S[K]>;
236
+ } & {
237
+ [K in OptionalKeys<S>]?: property<S[K]>;
238
+ }>;
239
+ export type schemaToProcess<S extends Schema> = Helper.Prettify<{
240
+ [K in RequiredToProcessKeys<S>]: property<S[K], 'process'>;
241
+ } & {
242
+ [K in OptionalToProcessKeys<S>]?: property<S[K], 'process'>;
243
+ }>;
244
+ export type schemaPartial<S extends Schema> = Helper.Prettify<{
245
+ [K in keyof S]?: property<S[K], 'partial'>;
246
+ }>;
247
+ export type schemaBase<S extends Schema> = {
248
+ [K in keyof S]: property<S[K]>;
249
+ };
250
+ export {};
251
+ }
252
+ }
253
+ export default Schema;