@endevops/peppol-schema 0.1.0-beta.7 → 0.1.1-alpha.1

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.
@@ -0,0 +1,74 @@
1
+ import { NumberValueParser } from "@nodable/base-output-builder";
2
+ import { CompactBuilderFactory } from "@nodable/compact-builder";
3
+ import { XMLParser } from "@nodable/flexible-xml-parser";
4
+ //#region src/xml/common-xml-options.ts
5
+ const commonXmlOptions = {
6
+ attributeNamePrefix: "@",
7
+ format: false,
8
+ ignoreAttributes: false,
9
+ numberParseOptions: {
10
+ hex: false,
11
+ leadingZeros: false
12
+ },
13
+ parseAttributeValue: true,
14
+ suppressBooleanAttributes: true,
15
+ suppressEmptyNode: true,
16
+ trimValues: true
17
+ };
18
+ //#endregion
19
+ //#region src/xml/builder-options.ts
20
+ const builderOptions = {
21
+ ...commonXmlOptions,
22
+ suppressEmptyNode: true
23
+ };
24
+ //#endregion
25
+ //#region src/xml/nodable-parser.ts
26
+ const numberParser = new NumberValueParser({
27
+ eNotation: true,
28
+ hex: false,
29
+ leadingZeros: false
30
+ });
31
+ const compactFactory = new CompactBuilderFactory({
32
+ attributes: { valueParsers: [
33
+ "entity",
34
+ numberParser,
35
+ "boolean"
36
+ ] },
37
+ tags: { valueParsers: [
38
+ "trim",
39
+ "entity",
40
+ "boolean",
41
+ numberParser
42
+ ] }
43
+ });
44
+ const nodableParser = new XMLParser({
45
+ OutputBuilder: compactFactory,
46
+ attributes: {
47
+ booleanType: "allow",
48
+ prefix: "@"
49
+ },
50
+ skip: {
51
+ attributes: false,
52
+ nsPrefix: true
53
+ }
54
+ });
55
+ function parseXmlNodable(value) {
56
+ const parsed = nodableParser.parse(value);
57
+ stripDefaultXmlns(parsed);
58
+ return parsed;
59
+ }
60
+ function stripDefaultXmlns(node) {
61
+ if (Array.isArray(node)) {
62
+ for (const item of node) stripDefaultXmlns(item);
63
+ return;
64
+ }
65
+ if (typeof node === "object" && node !== null) {
66
+ const record = node;
67
+ delete record["@xmlns"];
68
+ for (const key of Object.keys(record)) stripDefaultXmlns(record[key]);
69
+ }
70
+ }
71
+ //#endregion
72
+ export { builderOptions as n, commonXmlOptions as r, parseXmlNodable as t };
73
+
74
+ //# sourceMappingURL=nodable-parser-CyDZtLCK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodable-parser-CyDZtLCK.js","names":[],"sources":["../src/xml/common-xml-options.ts","../src/xml/builder-options.ts","../src/xml/nodable-parser.ts"],"sourcesContent":["import type { XmlBuilderOptions } from 'fast-xml-builder';\nimport type { X2jOptions } from 'fast-xml-parser';\n\nexport const commonXmlOptions = {\n attributeNamePrefix: '@',\n format: false,\n ignoreAttributes: false,\n numberParseOptions: { hex: false, leadingZeros: false },\n parseAttributeValue: true,\n suppressBooleanAttributes: true,\n suppressEmptyNode: true,\n trimValues: true,\n} satisfies X2jOptions & XmlBuilderOptions;\n","import type { XmlBuilderOptions } from 'fast-xml-builder';\n\nimport { commonXmlOptions } from '#/xml/common-xml-options.ts';\n\nexport const builderOptions = { ...commonXmlOptions, suppressEmptyNode: true } satisfies XmlBuilderOptions;\n","import { NumberValueParser } from '@nodable/base-output-builder';\nimport { CompactBuilderFactory } from '@nodable/compact-builder';\nimport { XMLParser } from '@nodable/flexible-xml-parser';\n\nimport type { XmlNode } from '#/helpers/get-prop.ts';\n\nconst numberParser = new NumberValueParser({ eNotation: true, hex: false, leadingZeros: false });\n\nconst compactFactory = new CompactBuilderFactory({\n attributes: { valueParsers: ['entity', numberParser, 'boolean'] },\n tags: { valueParsers: ['trim', 'entity', 'boolean', numberParser] },\n});\n\nconst nodableParser = new XMLParser({\n OutputBuilder: compactFactory,\n attributes: { booleanType: 'allow', prefix: '@' },\n skip: { attributes: false, nsPrefix: true },\n});\n\nexport function parseXmlNodable(value: string): XmlNode {\n const parsed = nodableParser.parse(value) as XmlNode;\n stripDefaultXmlns(parsed);\n return parsed;\n}\n\nfunction stripDefaultXmlns(node: unknown): void {\n if (Array.isArray(node)) {\n for (const item of node) stripDefaultXmlns(item);\n return;\n }\n if (typeof node === 'object' && node !== null) {\n const record = node as Record<string, unknown>;\n delete record['@xmlns'];\n for (const key of Object.keys(record)) stripDefaultXmlns(record[key]);\n }\n}\n"],"mappings":";;;;AAGA,MAAa,mBAAmB;CAC9B,qBAAqB;CACrB,QAAQ;CACR,kBAAkB;CAClB,oBAAoB;EAAE,KAAK;EAAO,cAAc;CAAM;CACtD,qBAAqB;CACrB,2BAA2B;CAC3B,mBAAmB;CACnB,YAAY;AACd;;;ACRA,MAAa,iBAAiB;CAAE,GAAG;CAAkB,mBAAmB;AAAK;;;ACE7E,MAAM,eAAe,IAAI,kBAAkB;CAAE,WAAW;CAAM,KAAK;CAAO,cAAc;AAAM,CAAC;AAE/F,MAAM,iBAAiB,IAAI,sBAAsB;CAC/C,YAAY,EAAE,cAAc;EAAC;EAAU;EAAc;CAAS,EAAE;CAChE,MAAM,EAAE,cAAc;EAAC;EAAQ;EAAU;EAAW;CAAY,EAAE;AACpE,CAAC;AAED,MAAM,gBAAgB,IAAI,UAAU;CAClC,eAAe;CACf,YAAY;EAAE,aAAa;EAAS,QAAQ;CAAI;CAChD,MAAM;EAAE,YAAY;EAAO,UAAU;CAAK;AAC5C,CAAC;AAED,SAAgB,gBAAgB,OAAwB;CACtD,MAAM,SAAS,cAAc,MAAM,KAAK;CACxC,kBAAkB,MAAM;CACxB,OAAO;AACT;AAEA,SAAS,kBAAkB,MAAqB;CAC9C,IAAI,MAAM,QAAQ,IAAI,GAAG;EACvB,KAAK,MAAM,QAAQ,MAAM,kBAAkB,IAAI;EAC/C;CACF;CACA,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM;EAC7C,MAAM,SAAS;EACf,OAAO,OAAO;EACd,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAAG,kBAAkB,OAAO,IAAI;CACtE;AACF"}
package/dist/xml.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Effect } from "effect";
1
2
  //#region src/xml/builder-options.d.ts
2
3
  export declare const builderOptions: {
3
4
  attributeNamePrefix: string;
@@ -13,6 +14,12 @@ export declare const builderOptions: {
13
14
  suppressEmptyNode: true;
14
15
  };
15
16
  //#endregion
17
+ //#region src/helpers/get-prop.d.ts
18
+ type XmlNode = any;
19
+ //#endregion
20
+ //#region src/xml/nodable-parser.d.ts
21
+ export declare function parseXmlNodable(value: string): XmlNode;
22
+ //#endregion
16
23
  //#region src/xml/parser-options.d.ts
17
24
  export declare const parserOptions: {
18
25
  attributeNamePrefix: string;
package/dist/xml.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"xml.d.ts","names":[],"sources":["../src/xml/builder-options.ts","../src/xml/parser-options.ts"],"mappings":";qBAIa;;;;;;;;;;;;;;;qBCAA"}
1
+ {"version":3,"file":"xml.d.ts","names":[],"sources":["../src/xml/builder-options.ts","../src/helpers/get-prop.ts","../src/xml/nodable-parser.ts","../src/xml/parser-options.ts"],"mappings":";;qBAIa;;;;;;;;;;;;;;;KCDD;;;wBCgBI,gBAAgB,gBAAgB;;;qBCfnC"}
package/dist/xml.js CHANGED
@@ -1,2 +1,7 @@
1
- import { n as builderOptions, t as parserOptions } from "./parser-options-mbqEQPSY.js";
2
- export { builderOptions, parserOptions };
1
+ import { n as builderOptions, r as commonXmlOptions, t as parseXmlNodable } from "./nodable-parser-CyDZtLCK.js";
2
+ //#region src/xml/parser-options.ts
3
+ const parserOptions = { ...commonXmlOptions };
4
+ //#endregion
5
+ export { builderOptions, parseXmlNodable, parserOptions };
6
+
7
+ //# sourceMappingURL=xml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml.js","names":[],"sources":["../src/xml/parser-options.ts"],"sourcesContent":["import type { X2jOptions } from 'fast-xml-parser';\n\nimport { commonXmlOptions } from '#/xml/common-xml-options.ts';\n\nexport const parserOptions = { ...commonXmlOptions } satisfies X2jOptions;\n"],"mappings":";;AAIA,MAAa,gBAAgB,EAAE,GAAG,iBAAiB"}
package/package.json CHANGED
@@ -1,8 +1,24 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/refs/heads/master/src/schemas/json/package.json",
3
3
  "name": "@endevops/peppol-schema",
4
- "version": "0.1.0-beta.7",
5
- "description": "A simple example library built by tsdown",
4
+ "version": "0.1.1-alpha.1",
5
+ "description": "TypeScript Effect Schema models for PEPPOL BIS Billing 3.0 — decode, validate and encode Invoice, Credit Note, Invoice Response and Message Level Response XML, with generated code lists, Schematron rules and identifier validations",
6
+ "keywords": [
7
+ "bis-billing",
8
+ "credit-note",
9
+ "e-invoicing",
10
+ "e-procurement",
11
+ "effect",
12
+ "invoice",
13
+ "openpeppol",
14
+ "peppol",
15
+ "peppol-bis",
16
+ "schematron",
17
+ "typescript",
18
+ "ubl",
19
+ "validation",
20
+ "xml"
21
+ ],
6
22
  "license": "Apache-2.0",
7
23
  "contributors": [
8
24
  {
@@ -98,6 +114,7 @@
98
114
  "@arethetypeswrong/core": "^0.18.5",
99
115
  "@effect/tsgo": "^0.45.0",
100
116
  "@effect/vitest": "^4.0.0-rc.113",
117
+ "@nodable/base-output-builder": "^2.0.0",
101
118
  "@nodable/compact-builder": "^2.0.0",
102
119
  "@nodable/flexible-xml-parser": "^1.11.3",
103
120
  "@types/bun": "^1.4.2",
@@ -121,6 +138,9 @@
121
138
  "vitest": "^5.0.0"
122
139
  },
123
140
  "peerDependencies": {
141
+ "@nodable/base-output-builder": "^2",
142
+ "@nodable/compact-builder": "^2",
143
+ "@nodable/flexible-xml-parser": "^1",
124
144
  "effect": "^4.0.0-rc.113",
125
145
  "fast-xml-builder": "^1",
126
146
  "fast-xml-parser": "^5"
@@ -2,7 +2,6 @@ import type { SchemaAST } from 'effect';
2
2
 
3
3
  import { Effect, Predicate, Schema, SchemaGetter, SchemaIssue } from 'effect';
4
4
  import XMLBuilder from 'fast-xml-builder';
5
- import { XMLParser } from 'fast-xml-parser';
6
5
 
7
6
  import type { XmlNode } from '#/helpers/get-prop.ts';
8
7
  import type { PeppolCreditNoteLine } from '#/schemas/fields/peppol-credit-note-line-schema.ts';
@@ -24,7 +23,7 @@ import { PeppolInvoiceResponse } from '#/schemas/peppol-invoice-response-schema.
24
23
  import { PeppolInvoice } from '#/schemas/peppol-invoice-schema.ts';
25
24
  import { PeppolMessageLevelResponse } from '#/schemas/peppol-message-level-response-schema.ts';
26
25
  import { builderOptions } from '#/xml/builder-options.ts';
27
- import { parserOptions } from '#/xml/parser-options.ts';
26
+ import { parseXmlNodable } from '#/xml/nodable-parser.ts';
28
27
 
29
28
  /**
30
29
  * @description Object representation of a PEPPOL document, before the member schemas normalise it (dates stay strings, enums stay loose). This is the shape
@@ -36,7 +35,7 @@ const peppolDocumentObjectSchema = Schema.Union([PeppolInvoice, PeppolCreditNote
36
35
 
37
36
  type PeppolDocumentObject = typeof peppolDocumentObjectSchema.Encoded;
38
37
 
39
- const parseXml = (value: string): XmlNode => new XMLParser({ ...parserOptions, removeNSPrefix: true }).parse(value);
38
+ const parseXml = (value: string): XmlNode => parseXmlNodable(value);
40
39
 
41
40
  export const isPeppolInvoice = Schema.is(PeppolInvoice);
42
41
  export const isPeppolCreditNote = Schema.is(PeppolCreditNote);
@@ -0,0 +1,36 @@
1
+ import { NumberValueParser } from '@nodable/base-output-builder';
2
+ import { CompactBuilderFactory } from '@nodable/compact-builder';
3
+ import { XMLParser } from '@nodable/flexible-xml-parser';
4
+
5
+ import type { XmlNode } from '#/helpers/get-prop.ts';
6
+
7
+ const numberParser = new NumberValueParser({ eNotation: true, hex: false, leadingZeros: false });
8
+
9
+ const compactFactory = new CompactBuilderFactory({
10
+ attributes: { valueParsers: ['entity', numberParser, 'boolean'] },
11
+ tags: { valueParsers: ['trim', 'entity', 'boolean', numberParser] },
12
+ });
13
+
14
+ const nodableParser = new XMLParser({
15
+ OutputBuilder: compactFactory,
16
+ attributes: { booleanType: 'allow', prefix: '@' },
17
+ skip: { attributes: false, nsPrefix: true },
18
+ });
19
+
20
+ export function parseXmlNodable(value: string): XmlNode {
21
+ const parsed = nodableParser.parse(value) as XmlNode;
22
+ stripDefaultXmlns(parsed);
23
+ return parsed;
24
+ }
25
+
26
+ function stripDefaultXmlns(node: unknown): void {
27
+ if (Array.isArray(node)) {
28
+ for (const item of node) stripDefaultXmlns(item);
29
+ return;
30
+ }
31
+ if (typeof node === 'object' && node !== null) {
32
+ const record = node as Record<string, unknown>;
33
+ delete record['@xmlns'];
34
+ for (const key of Object.keys(record)) stripDefaultXmlns(record[key]);
35
+ }
36
+ }
package/src/xml.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './xml/builder-options.ts';
2
+ export * from './xml/nodable-parser.ts';
2
3
  export * from './xml/parser-options.ts';
@@ -1,27 +0,0 @@
1
- //#region src/xml/common-xml-options.ts
2
- const commonXmlOptions = {
3
- attributeNamePrefix: "@",
4
- format: false,
5
- ignoreAttributes: false,
6
- numberParseOptions: {
7
- hex: false,
8
- leadingZeros: false
9
- },
10
- parseAttributeValue: true,
11
- suppressBooleanAttributes: true,
12
- suppressEmptyNode: true,
13
- trimValues: true
14
- };
15
- //#endregion
16
- //#region src/xml/builder-options.ts
17
- const builderOptions = {
18
- ...commonXmlOptions,
19
- suppressEmptyNode: true
20
- };
21
- //#endregion
22
- //#region src/xml/parser-options.ts
23
- const parserOptions = { ...commonXmlOptions };
24
- //#endregion
25
- export { builderOptions as n, parserOptions as t };
26
-
27
- //# sourceMappingURL=parser-options-mbqEQPSY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser-options-mbqEQPSY.js","names":[],"sources":["../src/xml/common-xml-options.ts","../src/xml/builder-options.ts","../src/xml/parser-options.ts"],"sourcesContent":["import type { XmlBuilderOptions } from 'fast-xml-builder';\nimport type { X2jOptions } from 'fast-xml-parser';\n\nexport const commonXmlOptions = {\n attributeNamePrefix: '@',\n format: false,\n ignoreAttributes: false,\n numberParseOptions: { hex: false, leadingZeros: false },\n parseAttributeValue: true,\n suppressBooleanAttributes: true,\n suppressEmptyNode: true,\n trimValues: true,\n} satisfies X2jOptions & XmlBuilderOptions;\n","import type { XmlBuilderOptions } from 'fast-xml-builder';\n\nimport { commonXmlOptions } from '#/xml/common-xml-options.ts';\n\nexport const builderOptions = { ...commonXmlOptions, suppressEmptyNode: true } satisfies XmlBuilderOptions;\n","import type { X2jOptions } from 'fast-xml-parser';\n\nimport { commonXmlOptions } from '#/xml/common-xml-options.ts';\n\nexport const parserOptions = { ...commonXmlOptions } satisfies X2jOptions;\n"],"mappings":";AAGA,MAAa,mBAAmB;CAC9B,qBAAqB;CACrB,QAAQ;CACR,kBAAkB;CAClB,oBAAoB;EAAE,KAAK;EAAO,cAAc;CAAM;CACtD,qBAAqB;CACrB,2BAA2B;CAC3B,mBAAmB;CACnB,YAAY;AACd;;;ACRA,MAAa,iBAAiB;CAAE,GAAG;CAAkB,mBAAmB;AAAK;;;ACA7E,MAAa,gBAAgB,EAAE,GAAG,iBAAiB"}