Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
77it committed Feb 29, 2024
1 parent 5d79fcb commit 7f7476e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/modules/_samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// for documentation about how to write module config see comments in "settings.js", in this folder
7 changes: 7 additions & 0 deletions src/config/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const ACTIVESET_DATE = 'date';
const ACTIVESET_VALUE = 'value';
//#endregion names

// used by `sanitizeModuleData` function.
// keys explanation:
// - tableName: name of the table in the database
// - columns: names of the columns in the table
// - parsing: [OPTIONAL] parsing method for the column, done before sanitization
// - sanitization: [OPTIONAL] sanitization method for the columns; if not present, the column will not be sanitized
// - sanitizationOptions: [OPTIONAL] options for sanitization `sanitizeObj` function
const tablesInfo = {
Set: {
tableName: SET,
Expand Down
1 change: 1 addition & 0 deletions src/lib/schema_sanitization_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ function sanitize ({ value, sanitization, options, validate = false }) {
* Any, object, function, class are ignored and returned as is.
* Array are sanitized without cloning them.
* A non-array value sanitized to array becomes an array with the value added as first element.
* Object keys missing from the sanitization object are ignored and not sanitized.
* @param {Object} p
* @param {*} p.obj - Object to sanitize
* @param {*} p.sanitization - Sanitization object {key1: 'string', key2: 'number?'}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/_utils/sanitization_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ModuleData, schema, validateObj, sanitizeObj, eq2, parseYAML, parseJSON
* Sanitize and parse values of moduleData tables in place (without cloning moduleData).
* tableName is matched between moduleData and moduleSanitization in a case insensitive & trim way.
* sanitization and parsing is also done in a case insensitive & trim way, matching the keys of the object to sanitize to the sanitization object keys.
* parsing is done before sanitization, with YAML or JSON5 (values from config/modules/_const.js)
* parsing is done before sanitization, with YAML or JSON5 (values from config/modules/_const.js), only for the keys specified in the sanitization object.
* @param {Object} p
* @param {ModuleData} p.moduleData
* @param {{tableName: string, parsing: *, sanitization: *, sanitizationOptions?: *}[]} p.moduleSanitization
Expand All @@ -22,6 +22,7 @@ function sanitizeModuleData ({ moduleData, moduleSanitization }) {
for (const _table of moduleData.tables) {
// search for `_table.tableName` in `moduleSanitization` array (in a case insensitive way); if not found, `_pss` is undefined
// if found, `_pss` contains the parsing and sanitization settings object for the table
/** @type {{tableName: string, parsing: *, sanitization: *, sanitizationOptions?: *} | undefined} */
const _pss = moduleSanitization.find(_ => eq2(_.tableName, _table.tableName));

// if `_pss` has a value, parse and sanitize `_table.table` with it
Expand Down

0 comments on commit 7f7476e

Please sign in to comment.