@punks/backend-entity-manager 0.0.413 → 0.0.415
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/cjs/index.js +34 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/serializer.d.ts +1 -1
- package/dist/cjs/types/utils/validators.d.ts +1 -1
- package/dist/esm/index.js +34 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/serializer.d.ts +1 -1
- package/dist/esm/types/utils/validators.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ export type EntitySerializerColumnDefinition<TSheetItem> = {
|
|
|
41
41
|
idColumn?: boolean;
|
|
42
42
|
sheetParser?: EntitySerializerSheetCustomParser;
|
|
43
43
|
array?: boolean;
|
|
44
|
-
arraySeparator?: string;
|
|
44
|
+
arraySeparator?: string | RegExp;
|
|
45
45
|
};
|
|
46
46
|
export type EntitySerializerSheetOptions = {
|
|
47
47
|
name?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntryValidationResult } from "../abstractions/serializer";
|
|
2
2
|
export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => EntryValidationResult;
|
|
3
|
-
export declare const fieldTextValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) =>
|
|
3
|
+
export declare const fieldTextValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => string | string[], params: {
|
|
4
4
|
required?: boolean;
|
|
5
5
|
minLength?: number;
|
|
6
6
|
maxLength?: number;
|
package/dist/esm/index.js
CHANGED
|
@@ -183,9 +183,21 @@ class EntitySeeder {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
|
|
187
186
|
const DEFAULT_DELIMITER$1 = ";";
|
|
188
187
|
const DEFAULT_ARRAY_SEPARATOR$1 = "|";
|
|
188
|
+
const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
|
|
189
|
+
const getRealSeparator = (separator) => {
|
|
190
|
+
if (!separator)
|
|
191
|
+
return DEFAULT_ARRAY_SEPARATOR$1;
|
|
192
|
+
if (typeof separator === "string")
|
|
193
|
+
return separator;
|
|
194
|
+
if (separator instanceof RegExp) {
|
|
195
|
+
const separators = separator.source.split("|");
|
|
196
|
+
if (separators.length > 1)
|
|
197
|
+
return separators[0];
|
|
198
|
+
}
|
|
199
|
+
return DEFAULT_ARRAY_SEPARATOR$1;
|
|
200
|
+
};
|
|
189
201
|
const splitArrayColumn = (value, separator) => value
|
|
190
202
|
?.toString()
|
|
191
203
|
.split(separator ?? DEFAULT_ARRAY_SEPARATOR$1)
|
|
@@ -193,7 +205,7 @@ const splitArrayColumn = (value, separator) => value
|
|
|
193
205
|
const joinArrayColumn$1 = (value, separator) => value
|
|
194
206
|
?.map((x) => x.toString().trim())
|
|
195
207
|
.filter((x) => x)
|
|
196
|
-
.join(separator
|
|
208
|
+
.join(getRealSeparator(separator));
|
|
197
209
|
class EntitySerializer {
|
|
198
210
|
constructor(services, options) {
|
|
199
211
|
this.services = services;
|
|
@@ -40969,19 +40981,17 @@ const fieldRequiredValidator = (item, selector) => {
|
|
|
40969
40981
|
};
|
|
40970
40982
|
const fieldTextValidator = (item, selector, params) => {
|
|
40971
40983
|
const value = selector(item);
|
|
40984
|
+
const values = Array.isArray(value) ? value : [value];
|
|
40972
40985
|
const isRequiredValid = params.required
|
|
40973
|
-
?
|
|
40986
|
+
? values.length > 0 &&
|
|
40987
|
+
values.every((v) => typeof v === "string" && v.length > 0)
|
|
40974
40988
|
: true;
|
|
40975
|
-
const
|
|
40976
|
-
|
|
40977
|
-
|
|
40978
|
-
|
|
40979
|
-
|
|
40980
|
-
|
|
40981
|
-
return {
|
|
40982
|
-
isValid: isMinLengthValid && isMaxLengthValid && isRegexValid && isRequiredValid,
|
|
40983
|
-
validationErrors: [
|
|
40984
|
-
...(isRequiredValid ? [] : [{ errorCode: "required" }]),
|
|
40989
|
+
const validateSingle = (v) => {
|
|
40990
|
+
const length = v.length;
|
|
40991
|
+
const isMinLengthValid = length >= (params.minLength ?? 0);
|
|
40992
|
+
const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
|
|
40993
|
+
const isRegexValid = params.regex?.test(v) ?? true;
|
|
40994
|
+
return [
|
|
40985
40995
|
...(isMinLengthValid
|
|
40986
40996
|
? []
|
|
40987
40997
|
: [
|
|
@@ -41001,6 +41011,14 @@ const fieldTextValidator = (item, selector, params) => {
|
|
|
41001
41011
|
...(isRegexValid
|
|
41002
41012
|
? []
|
|
41003
41013
|
: [{ errorCode: params.regexErrorCode ?? "regex" }]),
|
|
41014
|
+
];
|
|
41015
|
+
};
|
|
41016
|
+
const allErrors = values.flatMap(validateSingle);
|
|
41017
|
+
return {
|
|
41018
|
+
isValid: isRequiredValid && allErrors.length === 0,
|
|
41019
|
+
validationErrors: [
|
|
41020
|
+
...(isRequiredValid ? [] : [{ errorCode: "required" }]),
|
|
41021
|
+
...allErrors,
|
|
41004
41022
|
],
|
|
41005
41023
|
};
|
|
41006
41024
|
};
|
|
@@ -41162,6 +41180,9 @@ let SendgridEmailProvider = class SendgridEmailProvider {
|
|
|
41162
41180
|
this.client.setApiKey(sendgridSettings.value.apiKey);
|
|
41163
41181
|
}
|
|
41164
41182
|
async sendTemplatedEmail(input, template) {
|
|
41183
|
+
if (!input.to?.length && !input.cc?.length && !input.bcc?.length) {
|
|
41184
|
+
throw new Error(`No recipient specified for email ${input.templateId}`);
|
|
41185
|
+
}
|
|
41165
41186
|
const processedPayload = await template.processPayload(input.payload);
|
|
41166
41187
|
const templateData = await template.getTemplateData(processedPayload);
|
|
41167
41188
|
if (templateData.type === "html") {
|