@pdfme/generator 4.2.4 → 4.2.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.
@@ -8,6 +8,7 @@ export declare const getEmbedPdfPages: (arg: {
8
8
  basePages: (PDFEmbeddedPage | PDFPage)[];
9
9
  embedPdfBoxes: EmbedPdfBox[];
10
10
  }>;
11
+ export declare const validateRequiredFields: (template: Template, inputs: Record<string, any>[]) => void;
11
12
  export declare const preprocessing: (arg: {
12
13
  template: Template;
13
14
  userPlugins: Plugins;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/generator",
3
- "version": "4.2.4",
3
+ "version": "4.2.5",
4
4
  "sideEffects": false,
5
5
  "author": "hand-dot",
6
6
  "license": "MIT",
package/src/generate.ts CHANGED
@@ -2,7 +2,7 @@ import * as pdfLib from '@pdfme/pdf-lib';
2
2
  import type { GenerateProps } from '@pdfme/common';
3
3
  import { checkGenerateProps, getDynamicTemplate } from '@pdfme/common';
4
4
  import { modifyTemplateForTable, getDynamicHeightForTable } from '@pdfme/schemas';
5
- import { insertPage, preprocessing, postProcessing, getEmbedPdfPages } from './helper.js';
5
+ import { insertPage, preprocessing, postProcessing, getEmbedPdfPages, validateRequiredFields } from './helper.js';
6
6
 
7
7
  const generate = async (props: GenerateProps) => {
8
8
  checkGenerateProps(props);
@@ -10,9 +10,11 @@ const generate = async (props: GenerateProps) => {
10
10
  const basePdf = template.basePdf;
11
11
 
12
12
  if (inputs.length === 0) {
13
- throw new Error('inputs should not be empty');
13
+ throw new Error('[@pdfme/generator] inputs should not be empty, pass at least an empty object in the array');
14
14
  }
15
15
 
16
+ validateRequiredFields(template, inputs);
17
+
16
18
  const { pdfDoc, renderObj } = await preprocessing({ template, userPlugins });
17
19
 
18
20
  const _cache = new Map();
package/src/helper.ts CHANGED
@@ -58,6 +58,16 @@ export const getEmbedPdfPages = async (arg: { template: Template; pdfDoc: PDFDoc
58
58
  return { basePages, embedPdfBoxes };
59
59
  };
60
60
 
61
+ export const validateRequiredFields = (template: Template, inputs: Record<string, any>[]) => {
62
+ template.schemas.forEach((schemaObj) =>
63
+ Object.entries(schemaObj).forEach(([fieldName, schema]) => {
64
+ if (schema.required && !schema.readOnly && !inputs.some((input) => input[fieldName])) {
65
+ throw new Error(`[@pdfme/generator] input for '${fieldName}' is required to generate this PDF`);
66
+ }
67
+ })
68
+ );
69
+ }
70
+
61
71
  export const preprocessing = async (arg: { template: Template; userPlugins: Plugins }) => {
62
72
  const { template, userPlugins } = arg;
63
73
  const { schemas } = template;
package/tsconfig.json CHANGED
@@ -2,13 +2,13 @@
2
2
  "extends": "./tsconfig.esm",
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
- },
6
- "paths": {
7
- "@pdfme/common": [
8
- "packages/common/dist/esm/src"
9
- ],
10
- "@pdfme/schemas": [
11
- "packages/schemas/dist/esm/src"
12
- ]
5
+ "paths": {
6
+ "@pdfme/common": [
7
+ "packages/common/dist/esm/src"
8
+ ],
9
+ "@pdfme/schemas": [
10
+ "packages/schemas/dist/esm/src"
11
+ ]
12
+ }
13
13
  },
14
14
  }