@glion/lint-max-message-size 0.22.0 → 0.24.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.
package/README.md CHANGED
@@ -70,16 +70,16 @@ PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
70
70
  A message whose UTF-8 size exceeds `maxBytes`:
71
71
 
72
72
  ```
73
- Message size 2,000,000 bytes exceeds 1,000,000 bytes limit — trim payload or raise "maxBytes"
73
+ The message is 2000000 bytes; the configured limit is 1000000 bytes. Shorten the message or raise `maxBytes`.
74
74
  ```
75
75
 
76
76
  A tree with more segments than `maxSegments`:
77
77
 
78
78
  ```
79
- Message contains 150 segments (limit 100 segments) — reduce segment count or raise "maxSegments"
79
+ The message has 150 segments; the configured limit is 100 segments. Remove segments or raise `maxSegments`.
80
80
  ```
81
81
 
82
- Byte and segment counts are interpolated with pluralization. Both checks are independent — if the message violates both thresholds, two messages are reported.
82
+ Each report sets `actual` to the byte or segment count. Both checks are independent — if the message violates both thresholds, two messages are reported.
83
83
 
84
84
  ## Part of Glion
85
85
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKvC,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AASD;;;;;GAKG;AACH,QAAA,MAAM,uBAAuB,iEAwC5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKvC,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAgBD;;;;;GAKG;AACH,QAAA,MAAM,uBAAuB,iEAkC5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,10 @@ import pluralize from "pluralize";
2
2
  import { lintRule } from "unified-lint-rule";
3
3
  import { SKIP, visit } from "unist-util-visit";
4
4
  //#region src/index.ts
5
+ const messages = {
6
+ tooManyBytes: (byteLength, maxBytes) => `The message is ${pluralize("byte", byteLength, true)}; the configured limit is ${pluralize("byte", maxBytes, true)}. Shorten the message or raise \`maxBytes\`.`,
7
+ tooManySegments: (segmentCount, maxSegments) => `The message has ${pluralize("segment", segmentCount, true)}; the configured limit is ${pluralize("segment", maxSegments, true)}. Remove segments or raise \`maxSegments\`.`
8
+ };
5
9
  const defaultOptions = {
6
10
  maxBytes: 1e7,
7
11
  maxSegments: void 0
@@ -14,14 +18,17 @@ const defaultOptions = {
14
18
  */
15
19
  const hl7v2LintMaxMessageSize = lintRule({
16
20
  origin: "hl7v2-lint:max-message-size",
17
- url: "https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-max-message-size#readme"
21
+ url: "https://github.com/rethinkhealth/glion/tree/main/packages/lint-max-message-size#readme"
18
22
  }, (tree, file, opts) => {
19
23
  const options = {
20
24
  ...defaultOptions,
21
25
  ...opts
22
26
  };
23
27
  const byteLength = Buffer.byteLength(String(file.value), "utf8");
24
- if (byteLength > options.maxBytes) file.message(`Message size ${pluralize("byte", byteLength, true)} exceeds ${pluralize("byte", options.maxBytes, true)} limit — trim payload or raise "maxBytes"`);
28
+ if (byteLength > options.maxBytes) {
29
+ const message = file.message(messages.tooManyBytes(byteLength, options.maxBytes));
30
+ message.actual = String(byteLength);
31
+ }
25
32
  let totalSegments = 0;
26
33
  visit(tree, (node) => {
27
34
  if (node.type === "segment") {
@@ -29,7 +36,10 @@ const hl7v2LintMaxMessageSize = lintRule({
29
36
  return SKIP;
30
37
  }
31
38
  });
32
- if (options.maxSegments && totalSegments > options.maxSegments) file.message(`Message contains ${pluralize("segment", totalSegments, true)} (limit ${pluralize("segment", options.maxSegments, true)}) — reduce segment count or raise "maxSegments"`);
39
+ if (options.maxSegments && totalSegments > options.maxSegments) {
40
+ const message = file.message(messages.tooManySegments(totalSegments, options.maxSegments));
41
+ message.actual = String(totalSegments);
42
+ }
33
43
  });
34
44
  //#endregion
35
45
  export { hl7v2LintMaxMessageSize as default };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Node } from \"@glion/ast\";\nimport pluralize from \"pluralize\";\nimport { lintRule } from \"unified-lint-rule\";\nimport { SKIP, visit } from \"unist-util-visit\";\n\nexport interface MaxMessageSizeOptions {\n /**\n * Max allowed size of the HL7v2 message in bytes (UTF-8). Default: 1_000_000\n * (1MB).\n */\n maxBytes?: number;\n /**\n * Max allowed number of segments (counts nodes with `type: \"segment\"`).\n * Default: undefined (disabled). Set to a number to enable.\n */\n maxSegments?: number;\n}\n\nconst defaultOptions: Required<Omit<MaxMessageSizeOptions, \"maxSegments\">> & {\n maxSegments?: number;\n} = {\n maxBytes: 10_000_000, // 10MB\n maxSegments: undefined,\n};\n\n/**\n * Hl7v2-lint rule to warn when message size exceeds the maximum allowed size.\n *\n * This rule is useful for ensuring that HL7v2 messages do not exceed a safe\n * or expected size limit (default: 10MB).\n */\nconst hl7v2LintMaxMessageSize = lintRule<Node, MaxMessageSizeOptions>(\n {\n origin: \"hl7v2-lint:max-message-size\",\n url: \"https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-max-message-size#readme\",\n },\n (tree, file, opts) => {\n const options = { ...defaultOptions, ...opts };\n\n // Byte length of the message\n const byteLength = Buffer.byteLength(String(file.value), \"utf8\");\n if (byteLength > options.maxBytes) {\n file.message(\n `Message size ${pluralize(\"byte\", byteLength, true)} exceeds ${pluralize(\"byte\", options.maxBytes, true)} limit — trim payload or raise \"maxBytes\"`\n );\n }\n\n let totalSegments = 0;\n\n visit(tree, (node) => {\n // Count all segments including those in nested groups\n if (node.type === \"segment\") {\n totalSegments += 1;\n return SKIP;\n }\n });\n\n if (options.maxSegments && totalSegments > options.maxSegments) {\n file.message(\n `Message contains ${pluralize(\n \"segment\",\n totalSegments,\n true\n )} (limit ${pluralize(\n \"segment\",\n options.maxSegments,\n true\n )}) — reduce segment count or raise \"maxSegments\"`\n );\n }\n }\n);\n\nexport default hl7v2LintMaxMessageSize;\n"],"mappings":";;;;AAkBA,MAAM,iBAEF;CACF,UAAU;CACV,aAAa,KAAA;CACd;;;;;;;AAQD,MAAM,0BAA0B,SAC9B;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,MAAM,SAAS;CACpB,MAAM,UAAU;EAAE,GAAG;EAAgB,GAAG;EAAM;CAG9C,MAAM,aAAa,OAAO,WAAW,OAAO,KAAK,MAAM,EAAE,OAAO;AAChE,KAAI,aAAa,QAAQ,SACvB,MAAK,QACH,gBAAgB,UAAU,QAAQ,YAAY,KAAK,CAAC,WAAW,UAAU,QAAQ,QAAQ,UAAU,KAAK,CAAC,2CAC1G;CAGH,IAAI,gBAAgB;AAEpB,OAAM,OAAO,SAAS;AAEpB,MAAI,KAAK,SAAS,WAAW;AAC3B,oBAAiB;AACjB,UAAO;;GAET;AAEF,KAAI,QAAQ,eAAe,gBAAgB,QAAQ,YACjD,MAAK,QACH,oBAAoB,UAClB,WACA,eACA,KACD,CAAC,UAAU,UACV,WACA,QAAQ,aACR,KACD,CAAC,iDACH;EAGN"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Node } from \"@glion/ast\";\nimport pluralize from \"pluralize\";\nimport { lintRule } from \"unified-lint-rule\";\nimport { SKIP, visit } from \"unist-util-visit\";\n\nexport interface MaxMessageSizeOptions {\n /**\n * Max allowed size of the HL7v2 message in bytes (UTF-8). Default: 1_000_000\n * (1MB).\n */\n maxBytes?: number;\n /**\n * Max allowed number of segments (counts nodes with `type: \"segment\"`).\n * Default: undefined (disabled). Set to a number to enable.\n */\n maxSegments?: number;\n}\n\nconst messages = {\n tooManyBytes: (byteLength: number, maxBytes: number) =>\n `The message is ${pluralize(\"byte\", byteLength, true)}; the configured limit is ${pluralize(\"byte\", maxBytes, true)}. Shorten the message or raise \\`maxBytes\\`.`,\n tooManySegments: (segmentCount: number, maxSegments: number) =>\n `The message has ${pluralize(\"segment\", segmentCount, true)}; the configured limit is ${pluralize(\"segment\", maxSegments, true)}. Remove segments or raise \\`maxSegments\\`.`,\n} as const;\n\nconst defaultOptions: Required<Omit<MaxMessageSizeOptions, \"maxSegments\">> & {\n maxSegments?: number;\n} = {\n maxBytes: 10_000_000, // 10MB\n maxSegments: undefined,\n};\n\n/**\n * Hl7v2-lint rule to warn when message size exceeds the maximum allowed size.\n *\n * This rule is useful for ensuring that HL7v2 messages do not exceed a safe\n * or expected size limit (default: 10MB).\n */\nconst hl7v2LintMaxMessageSize = lintRule<Node, MaxMessageSizeOptions>(\n {\n origin: \"hl7v2-lint:max-message-size\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-max-message-size#readme\",\n },\n (tree, file, opts) => {\n const options = { ...defaultOptions, ...opts };\n\n // Byte length of the message\n const byteLength = Buffer.byteLength(String(file.value), \"utf8\");\n if (byteLength > options.maxBytes) {\n const message = file.message(\n messages.tooManyBytes(byteLength, options.maxBytes)\n );\n message.actual = String(byteLength);\n }\n\n let totalSegments = 0;\n\n visit(tree, (node) => {\n // Count all segments including those in nested groups\n if (node.type === \"segment\") {\n totalSegments += 1;\n return SKIP;\n }\n });\n\n if (options.maxSegments && totalSegments > options.maxSegments) {\n const message = file.message(\n messages.tooManySegments(totalSegments, options.maxSegments)\n );\n message.actual = String(totalSegments);\n }\n }\n);\n\nexport default hl7v2LintMaxMessageSize;\n"],"mappings":";;;;AAkBA,MAAM,WAAW;CACf,eAAe,YAAoB,aACjC,kBAAkB,UAAU,QAAQ,YAAY,KAAK,CAAC,4BAA4B,UAAU,QAAQ,UAAU,KAAK,CAAC;CACtH,kBAAkB,cAAsB,gBACtC,mBAAmB,UAAU,WAAW,cAAc,KAAK,CAAC,4BAA4B,UAAU,WAAW,aAAa,KAAK,CAAC;CACnI;AAED,MAAM,iBAEF;CACF,UAAU;CACV,aAAa,KAAA;CACd;;;;;;;AAQD,MAAM,0BAA0B,SAC9B;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,MAAM,SAAS;CACpB,MAAM,UAAU;EAAE,GAAG;EAAgB,GAAG;EAAM;CAG9C,MAAM,aAAa,OAAO,WAAW,OAAO,KAAK,MAAM,EAAE,OAAO;AAChE,KAAI,aAAa,QAAQ,UAAU;EACjC,MAAM,UAAU,KAAK,QACnB,SAAS,aAAa,YAAY,QAAQ,SAAS,CACpD;AACD,UAAQ,SAAS,OAAO,WAAW;;CAGrC,IAAI,gBAAgB;AAEpB,OAAM,OAAO,SAAS;AAEpB,MAAI,KAAK,SAAS,WAAW;AAC3B,oBAAiB;AACjB,UAAO;;GAET;AAEF,KAAI,QAAQ,eAAe,gBAAgB,QAAQ,aAAa;EAC9D,MAAM,UAAU,KAAK,QACnB,SAAS,gBAAgB,eAAe,QAAQ,YAAY,CAC7D;AACD,UAAQ,SAAS,OAAO,cAAc;;EAG3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/lint-max-message-size",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "hl7v2-lint rule to warn when message size exceeds the maximum allowed size",
5
5
  "keywords": [
6
6
  "definition",
@@ -52,8 +52,8 @@
52
52
  "typescript": "6.0.3",
53
53
  "vfile": "^6.0.3",
54
54
  "vitest": "4.1.11",
55
- "@glion/ast": "0.22.0",
56
- "@glion/builder": "0.22.0",
55
+ "@glion/ast": "0.24.0",
56
+ "@glion/builder": "0.24.0",
57
57
  "@glion/check-readme": "0.18.0",
58
58
  "@glion/testing": "0.18.0",
59
59
  "@glion/tsconfig": "0.18.0"