diff --git a/lib/faker.js b/lib/faker.js index 235cafb..c1f1f00 100644 --- a/lib/faker.js +++ b/lib/faker.js @@ -1,13 +1,9 @@ import { JSONSchemaFaker } from 'json-schema-faker' import { faker } from '@faker-js/faker' import deref from 'dereference-json-schema' -import { readFile } from 'node:fs/promises' - -const geometryPath = new URL( - '../node_modules/@comapeo/geometry/json/geometry.json', - import.meta.url, -).pathname -const Geometry = JSON.parse(await readFile(geometryPath, 'utf-8')) +import { createRequire } from 'module' +const require = createRequire(import.meta.url) +const Geometry = require('@comapeo/geometry/json/geometry.json') /** * @typedef {typeof import('@comapeo/schema').docSchemas[import('@comapeo/schema/dist/types.js').SchemaName]} ValidSchema @@ -176,10 +172,9 @@ function createFakerSchema(schema) { return s } case 'RemoteDetectionAlert': - s.properties.geometry = { - $ref: Geometry.$id, - ...deref.dereferenceSync(Geometry), - } + // @ts-expect-error Dereferencing this causes a type error, but the data + // is generated correctly. + s.properties.geometry = deref.dereferenceSync(Geometry) return s } } diff --git a/tsconfig.json b/tsconfig.json index b63d8a2..bc6ce81 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "emitDeclarationOnly": true, "noFallthroughCasesInSwitch": true, "strictNullChecks": true, - "declarationDir": "./types" + "declarationDir": "./types", + "resolveJsonModule": true }, "include": ["./index.js", "lib/**/*.js"], "exclude": ["bin"]