@pdfme/cli 6.1.0 → 6.1.1-dev.5
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/diagnostics.d.ts +2 -2
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/diagnostics.d.ts
CHANGED
|
@@ -25,10 +25,10 @@ export interface FieldInputHint {
|
|
|
25
25
|
pages: number[];
|
|
26
26
|
required: boolean;
|
|
27
27
|
expectedInput: {
|
|
28
|
-
kind: 'string' | 'jsonStringObject' | 'enumString' | 'stringMatrix';
|
|
28
|
+
kind: 'string' | 'jsonStringObject' | 'enumString' | 'stringMatrix' | 'stringArray';
|
|
29
29
|
variableNames?: string[];
|
|
30
30
|
allowedValues?: string[];
|
|
31
|
-
example?: string | string[][];
|
|
31
|
+
example?: string | string[] | string[][];
|
|
32
32
|
format?: string;
|
|
33
33
|
canonicalFormat?: string;
|
|
34
34
|
contentKind?: string;
|
package/dist/index.js
CHANGED
|
@@ -767,6 +767,17 @@ function buildFieldInputHint(schema, page, radioGroupMembers) {
|
|
|
767
767
|
}
|
|
768
768
|
};
|
|
769
769
|
}
|
|
770
|
+
if (type === "list") return {
|
|
771
|
+
name: schema.name,
|
|
772
|
+
type,
|
|
773
|
+
pages: [page],
|
|
774
|
+
required: schema.required === true,
|
|
775
|
+
expectedInput: {
|
|
776
|
+
kind: "stringArray",
|
|
777
|
+
example: ["First item", "Second item"],
|
|
778
|
+
acceptsJsonString: true
|
|
779
|
+
}
|
|
780
|
+
};
|
|
770
781
|
if (type === "date" || type === "time" || type === "dateTime") {
|
|
771
782
|
const canonicalFormat = getCanonicalDateStoredFormat(type);
|
|
772
783
|
return {
|
|
@@ -853,6 +864,7 @@ function getInputContractIssue(hint, input, inputIndex) {
|
|
|
853
864
|
if (hint.expectedInput.kind === "jsonStringObject") return getMultiVariableTextInputIssue(hint, input, inputIndex);
|
|
854
865
|
if (hint.expectedInput.kind === "enumString") return getEnumStringInputIssue(hint, input, inputIndex);
|
|
855
866
|
if (hint.expectedInput.kind === "stringMatrix") return getStringMatrixInputIssue(hint, input, inputIndex);
|
|
867
|
+
if (hint.expectedInput.kind === "stringArray") return getStringArrayInputIssue(hint, input, inputIndex);
|
|
856
868
|
if (isCanonicalDateHint(hint)) return getCanonicalDateInputIssue(hint, input, inputIndex);
|
|
857
869
|
return null;
|
|
858
870
|
}
|
|
@@ -957,6 +969,19 @@ function getStringMatrixInputIssue(hint, input, inputIndex) {
|
|
|
957
969
|
example
|
|
958
970
|
});
|
|
959
971
|
}
|
|
972
|
+
function getStringArrayInputIssue(hint, input, inputIndex) {
|
|
973
|
+
const rawValue = input[hint.name];
|
|
974
|
+
const example = hint.expectedInput.example;
|
|
975
|
+
if (rawValue === void 0 || rawValue === "") return null;
|
|
976
|
+
const issue = getStringArrayShapeIssue(typeof rawValue === "string" && hint.expectedInput.acceptsJsonString === true ? parseListJsonInput(rawValue) ?? rawValue : rawValue);
|
|
977
|
+
if (!issue) return null;
|
|
978
|
+
return buildStringArrayErrorMessage({
|
|
979
|
+
hint,
|
|
980
|
+
inputIndex,
|
|
981
|
+
extra: issue,
|
|
982
|
+
example
|
|
983
|
+
});
|
|
984
|
+
}
|
|
960
985
|
function isCanonicalDateHint(hint) {
|
|
961
986
|
return (hint.type === "date" || hint.type === "time" || hint.type === "dateTime") && typeof hint.expectedInput.canonicalFormat === "string" && hint.expectedInput.canonicalFormat.length > 0;
|
|
962
987
|
}
|
|
@@ -992,6 +1017,12 @@ function getStringMatrixShapeIssue(value, expectedColumnCount) {
|
|
|
992
1017
|
}
|
|
993
1018
|
return null;
|
|
994
1019
|
}
|
|
1020
|
+
function getStringArrayShapeIssue(value) {
|
|
1021
|
+
if (typeof value === "string") return null;
|
|
1022
|
+
if (!Array.isArray(value)) return `Received ${describeValue(value)}.`;
|
|
1023
|
+
for (let index = 0; index < value.length; index++) if (typeof value[index] !== "string") return `Item ${index + 1} must be a string. Received ${describeValue(value[index])}.`;
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
995
1026
|
function getFirstArrayLength(rows) {
|
|
996
1027
|
for (const row of rows) if (Array.isArray(row)) return row.length;
|
|
997
1028
|
return 0;
|
|
@@ -1004,6 +1035,16 @@ function parseTableStringMatrix(rawValue) {
|
|
|
1004
1035
|
return null;
|
|
1005
1036
|
}
|
|
1006
1037
|
}
|
|
1038
|
+
function parseListJsonInput(rawValue) {
|
|
1039
|
+
if (typeof rawValue !== "string") return null;
|
|
1040
|
+
const trimmed = rawValue.trim();
|
|
1041
|
+
if (!trimmed.startsWith("[") && !trimmed.startsWith("{")) return null;
|
|
1042
|
+
try {
|
|
1043
|
+
return JSON.parse(trimmed);
|
|
1044
|
+
} catch {
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1007
1048
|
function isValidCanonicalDateValue(value, type) {
|
|
1008
1049
|
switch (type) {
|
|
1009
1050
|
case "date": return isValidCanonicalDate(value);
|
|
@@ -1077,6 +1118,11 @@ function buildStringMatrixErrorMessage(args) {
|
|
|
1077
1118
|
const compatibilityLabel = args.hint.expectedInput.acceptsJsonString === true ? " JSON string input is also accepted for compatibility." : "";
|
|
1078
1119
|
return `Field "${args.hint.name}" (${args.hint.type}) in input ${args.inputIndex + 1} expects a JSON array of string arrays${columnLabel}.${headerLabel}${exampleLabel}${compatibilityLabel} ${args.extra}`.trim();
|
|
1079
1120
|
}
|
|
1121
|
+
function buildStringArrayErrorMessage(args) {
|
|
1122
|
+
const exampleLabel = args.example !== void 0 ? ` Example: ${JSON.stringify(args.example)}.` : "";
|
|
1123
|
+
const compatibilityLabel = args.hint.expectedInput.acceptsJsonString === true ? " A newline string or JSON string array is also accepted." : "";
|
|
1124
|
+
return `Field "${args.hint.name}" (${args.hint.type}) in input ${args.inputIndex + 1} expects an array of strings.${exampleLabel}${compatibilityLabel} ${args.extra}`.trim();
|
|
1125
|
+
}
|
|
1080
1126
|
function buildCanonicalDateErrorMessage(args) {
|
|
1081
1127
|
const displayFormat = args.hint.expectedInput.format;
|
|
1082
1128
|
const displayLabel = typeof displayFormat === "string" && displayFormat.length > 0 && displayFormat !== args.hint.expectedInput.canonicalFormat ? ` Display format hint: ${displayFormat}.` : "";
|
|
@@ -2246,7 +2292,7 @@ var pdf2size_default = defineCommand({
|
|
|
2246
2292
|
});
|
|
2247
2293
|
//#endregion
|
|
2248
2294
|
//#region src/version.ts
|
|
2249
|
-
var CLI_VERSION = "6.1.
|
|
2295
|
+
var CLI_VERSION = "6.1.1-dev.5";
|
|
2250
2296
|
//#endregion
|
|
2251
2297
|
//#region src/example-templates.ts
|
|
2252
2298
|
function getExamplesBaseUrl() {
|