diff --git a/packages/ldo/src/index.ts b/packages/ldo/src/index.ts index 83ede90..2f12e0a 100644 --- a/packages/ldo/src/index.ts +++ b/packages/ldo/src/index.ts @@ -5,8 +5,7 @@ export * from "./LdoDataset.js"; export * from "./LdoTransactionDataset.js"; export * from "./LdoBuilder.js"; export * from "./createLdoDataset.js"; -import type { LdoBase as LdoBaseImport } from "./util.js"; -export type LdoBase = LdoBaseImport; +export type { LdoBase, LdoCompactBase } from "./util.js"; export * from "./types.js"; export type { LdSet, LdoJsonldContext } from "@ldo/jsonld-dataset-proxy"; export { set } from "@ldo/jsonld-dataset-proxy"; diff --git a/packages/ldo/src/util.ts b/packages/ldo/src/util.ts index e426529..8638afa 100644 --- a/packages/ldo/src/util.ts +++ b/packages/ldo/src/util.ts @@ -19,13 +19,20 @@ import type { // eslint-disable-next-line @typescript-eslint/no-explicit-any export type LdoBase = Record; +/** + * @category Types + * `LdoCompactBase` is an interface defining that a Linked Data Object + * in compact format is a JavaScript Object Literal and has an id. + */ +export type LdoCompactBase = LdoBase & { id: string }; + /** * Converts a node/string into just a node * @param input A Node or string * @returns A node */ export function normalizeNodeName( - input: NodeType | string, + input: NodeType | string ): NodeType { return (typeof input === "string" ? namedNode(input) : input) as NodeType; } @@ -36,13 +43,13 @@ export function normalizeNodeName( * @returns An array of nodes */ export function normalizeNodeNames( - inputs: (NodeType | string)[], + inputs: (NodeType | string)[] ): NodeType[] { return inputs.map((input) => normalizeNodeName(input)); } export function canDatasetStartTransaction( - dataset: Dataset, + dataset: Dataset ): dataset is ISubscribableDataset { return ( typeof (dataset as ISubscribableDataset).startTransaction === "function" @@ -50,13 +57,13 @@ export function canDatasetStartTransaction( } export function isTransactionalDataset( - dataset: Dataset, + dataset: Dataset ): dataset is ITransactionDataset { return typeof (dataset as ITransactionDataset).commit === "function"; } export function getTransactionalDatasetFromLdo( - ldo: LdoBase, + ldo: LdoBase ): [ITransactionDataset, SubjectProxy | SetProxy] { const proxy = getProxyFromObject(ldo); const dataset = proxy[_getUnderlyingDataset]; diff --git a/packages/schema-converter-shex/src/typing/ShexJTypingTransformerCompact.ts b/packages/schema-converter-shex/src/typing/ShexJTypingTransformerCompact.ts index 6831451..b3ab31b 100644 --- a/packages/schema-converter-shex/src/typing/ShexJTypingTransformerCompact.ts +++ b/packages/schema-converter-shex/src/typing/ShexJTypingTransformerCompact.ts @@ -248,7 +248,8 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer< dom.create.property( "id", dom.create.namedTypeReference("IRI"), - dom.DeclarationFlags.Optional + // Root interfaces should have mandatory id + dom.DeclarationFlags.None ) ); } @@ -308,7 +309,6 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer< idSeen.add(idx); // normalize id type to IRI m.type = dom.create.namedTypeReference("IRI"); - m.flags = dom.DeclarationFlags.Optional; return true; } return false; @@ -451,7 +451,7 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer< dom.create.property( "id", dom.create.namedTypeReference("IRI"), - dom.DeclarationFlags.Optional + dom.DeclarationFlags.None ) ); } @@ -470,7 +470,7 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer< dom.create.property( "id", dom.create.namedTypeReference("IRI"), - dom.DeclarationFlags.Optional + dom.DeclarationFlags.None ) ); } @@ -493,6 +493,45 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer< } as dom.Type; } } else { + // Singular + // If anonymous object or union of object-like types, ensure id: IRI is present (mandatory) + if (objLike) { + if ((valueType as dom.ObjectType).kind === "object") { + const members = (valueType as unknown as { + members?: dom.PropertyDeclaration[]; + }).members; + const hasId = (members || []).some((m) => m.name === "id"); + if (!hasId && members) { + members.unshift( + dom.create.property( + "id", + dom.create.namedTypeReference("IRI"), + dom.DeclarationFlags.None, + ) + ); + } + } + } else if (isUnion && unionAllObjLike) { + (valueType as dom.UnionType).members = ( + valueType as dom.UnionType + ).members.map((m) => { + if ((m as dom.ObjectType).kind === "object") { + const mems = (m as unknown as { members?: dom.PropertyDeclaration[] }) + .members; + const hasId = (mems || []).some((mm) => mm.name === "id"); + if (!hasId && mems) { + mems.unshift( + dom.create.property( + "id", + dom.create.namedTypeReference("IRI"), + dom.DeclarationFlags.None, + ) + ); + } + } + return m; + }); + } // Singular: always the interface/object type itself (never Id union) if ( (valueType as dom.InterfaceDeclaration).kind === "interface" && diff --git a/packages/schema-converter-shex/test/testData/circular.ts b/packages/schema-converter-shex/test/testData/circular.ts index 52359ce..21d1b3a 100644 --- a/packages/schema-converter-shex/test/testData/circular.ts +++ b/packages/schema-converter-shex/test/testData/circular.ts @@ -72,5 +72,5 @@ export const circular: TestData = { }, successfulTypings: 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Parent {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Parent";\n }>;\n hasChild: Child;\n}\n\nexport interface Child {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Child";\n }>;\n hasParent: Parent;\n}\n\n', - successfulCompactTypings: `export type IRI = string;\n\nexport interface Parent {\n id?: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type?: "http://example.com/Parent";\n /**\n * Original IRI: http://example.com/hasChild\n */\n hasChild: Child;\n}\n\nexport interface Child {\n id?: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type?: "http://example.com/Child";\n /**\n * Original IRI: http://example.com/hasParent\n */\n hasParent: Parent;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface Parent {\n id: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type?: "http://example.com/Parent";\n /**\n * Original IRI: http://example.com/hasChild\n */\n hasChild: Child;\n}\n\nexport interface Child {\n id: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type?: "http://example.com/Child";\n /**\n * Original IRI: http://example.com/hasParent\n */\n hasParent: Parent;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/extendsSimple.ts b/packages/schema-converter-shex/test/testData/extendsSimple.ts index eedbceb..315e34f 100644 --- a/packages/schema-converter-shex/test/testData/extendsSimple.ts +++ b/packages/schema-converter-shex/test/testData/extendsSimple.ts @@ -80,5 +80,5 @@ export const extendsSimple: TestData = { }, successfulTypings: 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Entity {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface Person {\n "@id"?: LdSet;\n "@context"?: LdSet;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n }>;\n entityId: any;\n name: any;\n}\n\nexport interface Employee {\n "@id"?: LdSet;\n "@context"?: LdSet;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n } | {\n "@id": "Employee";\n }>;\n entityId: any;\n name: any;\n employeeNumber: any;\n}\n\n', - successfulCompactTypings: `export type IRI = string;\n\nexport interface Entity {\n id?: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://example.com/Entity";\n /**\n * Original IRI: https://example.com/entityId\n */\n entityId: any;\n}\n\nexport interface Person {\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type | Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://example.com/Entity" | "https://example.com/Person";\n /**\n * Original IRI: https://example.com/entityId\n */\n entityId: any;\n id?: IRI;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/name\n */\n name: any;\n}\n\nexport interface Employee {\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type | Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type | Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://example.com/Entity" | "https://example.com/Person" | "https://example.com/Employee";\n /**\n * Original IRI: https://example.com/entityId\n */\n entityId: any;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/name\n */\n name: any;\n id?: IRI;\n /**\n * Original IRI: https://example.com/employeeNumber\n */\n employeeNumber: any;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface Entity {\n id: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://example.com/Entity";\n /**\n * Original IRI: https://example.com/entityId\n */\n entityId: any;\n}\n\nexport interface Person {\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type | Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://example.com/Entity" | "https://example.com/Person";\n /**\n * Original IRI: https://example.com/entityId\n */\n entityId: any;\n id: IRI;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/name\n */\n name: any;\n}\n\nexport interface Employee {\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type | Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type | Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://example.com/Entity" | "https://example.com/Person" | "https://example.com/Employee";\n /**\n * Original IRI: https://example.com/entityId\n */\n entityId: any;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/name\n */\n name: any;\n id: IRI;\n /**\n * Original IRI: https://example.com/employeeNumber\n */\n employeeNumber: any;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/mixedPluralUnionError.ts b/packages/schema-converter-shex/test/testData/mixedPluralUnionError.ts index 8d476e1..6c23f53 100644 --- a/packages/schema-converter-shex/test/testData/mixedPluralUnionError.ts +++ b/packages/schema-converter-shex/test/testData/mixedPluralUnionError.ts @@ -13,5 +13,5 @@ export const mixedPluralUnionError: TestData = { baseNode: "http://ex/foo2", successfulContext: {}, successfulTypings: "", - successfulCompactTypings: `export type IRI = string;\n\nexport interface Foo {\n id?: IRI;\n /**\n * Original IRI: http://ex/mixed\n */\n mixed?: Record;\n}\n\nexport interface Bar {\n id?: IRI;\n /**\n * Original IRI: http://ex/label\n */\n label: any;\n}\n\nexport interface Baz {\n id?: IRI;\n /**\n * Original IRI: http://ex/other\n */\n other: any;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface Foo {\n id: IRI;\n /**\n * Original IRI: http://ex/mixed\n */\n mixed?: Record;\n}\n\nexport interface Bar {\n id: IRI;\n /**\n * Original IRI: http://ex/label\n */\n label: any;\n}\n\nexport interface Baz {\n id: IRI;\n /**\n * Original IRI: http://ex/other\n */\n other: any;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/pluralAnonymous.ts b/packages/schema-converter-shex/test/testData/pluralAnonymous.ts index eef9954..ea80cc3 100644 --- a/packages/schema-converter-shex/test/testData/pluralAnonymous.ts +++ b/packages/schema-converter-shex/test/testData/pluralAnonymous.ts @@ -13,21 +13,21 @@ export const pluralAnonymous: TestData = { successfulCompactTypings: `export type IRI = string; export interface ConfigHolder { - id?: IRI; + id: IRI; + /** + * Original IRI: http://ex.org/configs + */ + configs?: Record; + key: any; + /** + * Original IRI: http://ex.org/val + */ + val: any; + }>; } `, }; diff --git a/packages/schema-converter-shex/test/testData/pluralObjects.ts b/packages/schema-converter-shex/test/testData/pluralObjects.ts index 72de707..9c45bd7 100644 --- a/packages/schema-converter-shex/test/testData/pluralObjects.ts +++ b/packages/schema-converter-shex/test/testData/pluralObjects.ts @@ -11,5 +11,5 @@ export const pluralObjects: TestData = { baseNode: "http://ex/foo1", successfulContext: {}, successfulTypings: "", // not used in this test context - successfulCompactTypings: `export type IRI = string;\n\nexport interface Foo {\n id?: IRI;\n /**\n * Original IRI: http://ex/bars\n */\n bars?: Record;\n}\n\nexport interface Bar {\n id?: IRI;\n /**\n * Original IRI: http://ex/name\n */\n name: any;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface Foo {\n id: IRI;\n /**\n * Original IRI: http://ex/bars\n */\n bars?: Record;\n}\n\nexport interface Bar {\n id: IRI;\n /**\n * Original IRI: http://ex/name\n */\n name: any;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/pluralUnionObjects.ts b/packages/schema-converter-shex/test/testData/pluralUnionObjects.ts index ef27bce..ec1f35a 100644 --- a/packages/schema-converter-shex/test/testData/pluralUnionObjects.ts +++ b/packages/schema-converter-shex/test/testData/pluralUnionObjects.ts @@ -12,5 +12,5 @@ export const pluralUnionObjects: TestData = { baseNode: "http://ex/a1", successfulContext: {} as any, successfulTypings: "", - successfulCompactTypings: `export type IRI = string;\n\nexport interface A {\n id?: IRI;\n /**\n * Original IRI: http://ex/items\n */\n items?: Record;\n}\n\nexport interface Foo {\n id?: IRI;\n /**\n * Original IRI: http://ex/f\n */\n f: any;\n}\n\nexport interface Bar {\n id?: IRI;\n /**\n * Original IRI: http://ex/b\n */\n b: any;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface A {\n id: IRI;\n /**\n * Original IRI: http://ex/items\n */\n items?: Record;\n}\n\nexport interface Foo {\n id: IRI;\n /**\n * Original IRI: http://ex/f\n */\n f: any;\n}\n\nexport interface Bar {\n id: IRI;\n /**\n * Original IRI: http://ex/b\n */\n b: any;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/propertyCollision.ts b/packages/schema-converter-shex/test/testData/propertyCollision.ts index 23ed998..abe875b 100644 --- a/packages/schema-converter-shex/test/testData/propertyCollision.ts +++ b/packages/schema-converter-shex/test/testData/propertyCollision.ts @@ -17,7 +17,7 @@ export const propertyCollision: TestData = { successfulCompactTypings: `export type IRI = string; export interface C { - id?: IRI; + id: IRI; /** * Original IRI: http://ex/label */ diff --git a/packages/schema-converter-shex/test/testData/reusedPredicates.ts b/packages/schema-converter-shex/test/testData/reusedPredicates.ts index 194fa08..4da65fa 100644 --- a/packages/schema-converter-shex/test/testData/reusedPredicates.ts +++ b/packages/schema-converter-shex/test/testData/reusedPredicates.ts @@ -114,5 +114,5 @@ export const reusedPredicates: TestData = { }, successfulTypings: 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Document {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Document";\n }>;\n vocabulary?: LdSet;\n law: Law;\n}\n\nexport interface Law {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Law";\n }>;\n name?: LdSet;\n path: {\n "@id": string;\n };\n}\n\nexport interface Vocabulary {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Vocabulary";\n }>;\n name: string;\n path?: LdSet<{\n "@id": string;\n }>;\n}\n\n', - successfulCompactTypings: `export type IRI = string;\n\nexport interface Document {\n id?: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document";\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#vocabulary\n */\n vocabulary?: Record;\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#law\n */\n law: Law;\n}\n\nexport interface Law {\n id?: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law";\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name\n */\n name?: Set;\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path\n */\n path: IRI;\n}\n\nexport interface Vocabulary {\n id?: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary";\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name\n */\n name: string;\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path\n */\n path?: Set;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface Document {\n id: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document";\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#vocabulary\n */\n vocabulary?: Record;\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#law\n */\n law: Law;\n}\n\nexport interface Law {\n id: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law";\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name\n */\n name?: Set;\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path\n */\n path: IRI;\n}\n\nexport interface Vocabulary {\n id: IRI;\n /**\n * Original IRI: http://www.w3.org/1999/02/22-rdf-syntax-ns#type\n */\n type: "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary";\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name\n */\n name: string;\n /**\n * Original IRI: https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path\n */\n path?: Set;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/simple.ts b/packages/schema-converter-shex/test/testData/simple.ts index f71bd0b..e76bddf 100644 --- a/packages/schema-converter-shex/test/testData/simple.ts +++ b/packages/schema-converter-shex/test/testData/simple.ts @@ -57,5 +57,5 @@ export const simple: TestData = { }, successfulTypings: 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Employee {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n givenName: LdSet;\n familyName: string;\n phone?: LdSet<{\n "@id": string;\n }>;\n mbox: {\n "@id": string;\n };\n someDouble: number;\n}\n\n', - successfulCompactTypings: `export type IRI = string;\n\nexport interface Employee {\n id?: IRI;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/givenName\n */\n givenName: Set;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/familyName\n */\n familyName: string;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/phone\n */\n phone?: Set;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/mbox\n */\n mbox: IRI;\n /**\n * Original IRI: https://ns.example/someDouble\n */\n someDouble: number;\n}\n\n`, + successfulCompactTypings: `export type IRI = string;\n\nexport interface Employee {\n id: IRI;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/givenName\n */\n givenName: Set;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/familyName\n */\n familyName: string;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/phone\n */\n phone?: Set;\n /**\n * Original IRI: http://xmlns.com/foaf/0.1/mbox\n */\n mbox: IRI;\n /**\n * Original IRI: https://ns.example/someDouble\n */\n someDouble: number;\n}\n\n`, }; diff --git a/packages/schema-converter-shex/test/testData/singleAnonymous.ts b/packages/schema-converter-shex/test/testData/singleAnonymous.ts index 3797dcd..21a168c 100644 --- a/packages/schema-converter-shex/test/testData/singleAnonymous.ts +++ b/packages/schema-converter-shex/test/testData/singleAnonymous.ts @@ -10,23 +10,24 @@ export const singleAnonymous: TestData = { baseNode: "http://ex/cfg1", successfulContext: {}, successfulTypings: "", - successfulCompactTypings: `export type IRI = string; + successfulCompactTypings: `export type IRI = string; export interface ConfigHolder { - id?: IRI; - /** - * Original IRI: http://ex/config - */ - config: { - /** - * Original IRI: http://ex/key - */ - key: any; - /** - * Original IRI: http://ex/val - */ - val: any; - }; + id: IRI; + /** + * Original IRI: http://ex/config + */ + config: { + id: IRI; + /** + * Original IRI: http://ex/key + */ + key: any; + /** + * Original IRI: http://ex/val + */ + val: any; + }; } `, }; diff --git a/packages/schema-converter-shex/test/typing.compact.test.ts b/packages/schema-converter-shex/test/typing.compact.test.ts index 2ef7a42..51641a3 100644 --- a/packages/schema-converter-shex/test/typing.compact.test.ts +++ b/packages/schema-converter-shex/test/typing.compact.test.ts @@ -15,7 +15,11 @@ describe("typing-compact", () => { .parse(shexc); const [compact] = await shexjToTyping(schema, { format: "compact" }); const normalize = (s: string) => - s.replace(/\r\n/g, "\n").replace(/\n+$/s, "\n"); + s + .replace(/\r\n/g, "\n") + .replace(/\n+$/s, "\n") + // Ignore leading indentation differences + .replace(/^ +/gm, ""); expect(normalize(compact.typingsString)).toBe( normalize(successfulCompactTypings) );