diff --git a/.eslintrc b/.eslintrc index b534610..dc4d454 100644 --- a/.eslintrc +++ b/.eslintrc @@ -52,5 +52,6 @@ } ], "allow-namespace": "off", + "import/extensions": ["error", "always", { "ignorePackages": true } ] } } diff --git a/cli/deploy.ts b/cli/deploy.ts index 4c5a673..7b49452 100644 --- a/cli/deploy.ts +++ b/cli/deploy.ts @@ -1,5 +1,5 @@ -import { getFrequencyAPI, getSignerAccountKeys } from "./services/connect"; -import dsnp, { SchemaName as DsnpSchemaName } from "../dsnp"; +import { getFrequencyAPI, getSignerAccountKeys } from "./services/connect.js"; +import dsnp, { SchemaName as DsnpSchemaName } from "../dsnp/index.js"; import { EventRecord } from "@polkadot/types/interfaces"; export const deploy = async () => { diff --git a/cli/index.ts b/cli/index.ts index daca9f0..af9e48c 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -1,4 +1,4 @@ -import { deploy } from "./deploy"; +import { deploy } from "./deploy.js"; export const main = async () => { await deploy(); diff --git a/cli/read.ts b/cli/read.ts index 6a671cf..f105292 100644 --- a/cli/read.ts +++ b/cli/read.ts @@ -1,8 +1,8 @@ -import { getEndpoint, getFrequencyAPI } from "./services/connect"; +import { getEndpoint, getFrequencyAPI } from "./services/connect.js"; import stringify from "json-stringify-pretty-compact"; -import { schemas } from "../dsnp"; +import { schemas } from "../dsnp/index.js"; const nameAndSchema = Array.from(schemas.entries(), ([k, v]) => [`dsnp.${k}`, JSON.stringify(v.model)]); diff --git a/dsnp/broadcast.spec.ts b/dsnp/broadcast.spec.ts index c2a88bf..e15a85f 100644 --- a/dsnp/broadcast.spec.ts +++ b/dsnp/broadcast.spec.ts @@ -1,6 +1,6 @@ -import { testCompression, testParquetSchema } from "../test/parquet"; +import { testCompression, testParquetSchema } from "../test/parquet.js"; import * as generators from "@dsnp/test-generators"; -import broadcastSchema from "./broadcast"; +import broadcastSchema from "./broadcast.js"; describe("Broadcast Spec", () => { testParquetSchema(broadcastSchema); diff --git a/dsnp/broadcast.ts b/dsnp/broadcast.ts index de56de4..145d38d 100644 --- a/dsnp/broadcast.ts +++ b/dsnp/broadcast.ts @@ -1,4 +1,4 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; const broadcast: FrequencyParquetSchema = [ { diff --git a/dsnp/graphChange.spec.ts b/dsnp/graphChange.spec.ts index 4c030c7..bdc9770 100644 --- a/dsnp/graphChange.spec.ts +++ b/dsnp/graphChange.spec.ts @@ -1,4 +1,4 @@ -import graphChangeSchema from "./graphChange"; +import graphChangeSchema from "./graphChange.js"; import avro from "avro-js"; describe("Graph Change Schema", () => { diff --git a/dsnp/index.ts b/dsnp/index.ts index 603f677..a259ae1 100644 --- a/dsnp/index.ts +++ b/dsnp/index.ts @@ -1,17 +1,17 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; -import broadcast from "./broadcast"; +import broadcast from "./broadcast.js"; // Deprecated -// import graphChange from "./dsnp/graphChange"; -import profile from "./profile"; -import reaction from "./reaction"; -import reply from "./reply"; -import tombstone from "./tombstone"; -import publicKey from "./publicKey"; -import userPublicFollows from "./userPublicFollows"; -import userPrivateFollows from "./userPrivateFollows"; -import userPrivateConnections from "./userPrivateConnections"; -import update from "./update"; +// import graphChange from "./dsnp/graphChange.js"; +import profile from "./profile.js"; +import reaction from "./reaction.js"; +import reply from "./reply.js"; +import tombstone from "./tombstone.js"; +import publicKey from "./publicKey.js"; +import userPublicFollows from "./userPublicFollows.js"; +import userPrivateFollows from "./userPrivateFollows.js"; +import userPrivateConnections from "./userPrivateConnections.js"; +import update from "./update.js"; export { broadcast, diff --git a/dsnp/profile.spec.ts b/dsnp/profile.spec.ts index d8cd0cd..cf7a4d0 100644 --- a/dsnp/profile.spec.ts +++ b/dsnp/profile.spec.ts @@ -1,6 +1,6 @@ -import { testCompression, testParquetSchema } from "../test/parquet"; +import { testCompression, testParquetSchema } from "../test/parquet.js"; import * as generators from "@dsnp/test-generators"; -import profileSchema from "./profile"; +import profileSchema from "./profile.js"; describe("Profile Spec", () => { testParquetSchema(profileSchema); diff --git a/dsnp/profile.ts b/dsnp/profile.ts index 4cce106..713a71c 100644 --- a/dsnp/profile.ts +++ b/dsnp/profile.ts @@ -1,4 +1,4 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; const profile: FrequencyParquetSchema = [ { diff --git a/dsnp/publicKey.spec.ts b/dsnp/publicKey.spec.ts index 35892ae..1e7b45d 100644 --- a/dsnp/publicKey.spec.ts +++ b/dsnp/publicKey.spec.ts @@ -1,4 +1,4 @@ -import publicKeySchema from "./publicKey"; +import publicKeySchema from "./publicKey.js"; import avro from "avro-js"; describe("Public Key Schema", () => { diff --git a/dsnp/reaction.spec.ts b/dsnp/reaction.spec.ts index 91af648..daba832 100644 --- a/dsnp/reaction.spec.ts +++ b/dsnp/reaction.spec.ts @@ -1,6 +1,6 @@ -import { testCompression, testParquetSchema } from "../test/parquet"; +import { testCompression, testParquetSchema } from "../test/parquet.js"; import * as generators from "@dsnp/test-generators"; -import reactionSchema from "./reaction"; +import reactionSchema from "./reaction.js"; describe("Reaction Spec", () => { testParquetSchema(reactionSchema); diff --git a/dsnp/reaction.ts b/dsnp/reaction.ts index 9471ca0..57b32ad 100644 --- a/dsnp/reaction.ts +++ b/dsnp/reaction.ts @@ -1,4 +1,4 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; const reaction: FrequencyParquetSchema = [ { diff --git a/dsnp/reply.spec.ts b/dsnp/reply.spec.ts index 6ff8594..f90bce7 100644 --- a/dsnp/reply.spec.ts +++ b/dsnp/reply.spec.ts @@ -1,6 +1,6 @@ -import { testCompression, testParquetSchema } from "../test/parquet"; +import { testCompression, testParquetSchema } from "../test/parquet.js"; import * as generators from "@dsnp/test-generators"; -import replySchema from "./reply"; +import replySchema from "./reply.js"; describe("Reply Spec", () => { testParquetSchema(replySchema); diff --git a/dsnp/reply.ts b/dsnp/reply.ts index d899012..3335b7c 100644 --- a/dsnp/reply.ts +++ b/dsnp/reply.ts @@ -1,4 +1,4 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; const reply: FrequencyParquetSchema = [ { diff --git a/dsnp/tombstone.spec.ts b/dsnp/tombstone.spec.ts index 8404fe3..7301815 100644 --- a/dsnp/tombstone.spec.ts +++ b/dsnp/tombstone.spec.ts @@ -1,6 +1,6 @@ -import { testCompression, testParquetSchema } from "../test/parquet"; +import { testCompression, testParquetSchema } from "../test/parquet.js"; import * as generators from "@dsnp/test-generators"; -import tombstoneSchema from "./tombstone"; +import tombstoneSchema from "./tombstone.js"; describe("Tombstone Spec", () => { testParquetSchema(tombstoneSchema); diff --git a/dsnp/tombstone.ts b/dsnp/tombstone.ts index 2ec7a13..da22320 100644 --- a/dsnp/tombstone.ts +++ b/dsnp/tombstone.ts @@ -1,4 +1,4 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; const tombstone: FrequencyParquetSchema = [ { diff --git a/dsnp/update.spec.ts b/dsnp/update.spec.ts index 7085b29..63c02f7 100644 --- a/dsnp/update.spec.ts +++ b/dsnp/update.spec.ts @@ -1,6 +1,6 @@ -import { testCompression, testParquetSchema } from "../test/parquet"; +import { testCompression, testParquetSchema } from "../test/parquet.js"; import * as generators from "@dsnp/test-generators"; -import updateSchema from "./update"; +import updateSchema from "./update.js"; describe("Update Spec", () => { testParquetSchema(updateSchema); diff --git a/dsnp/update.ts b/dsnp/update.ts index e426c8a..1c7810f 100644 --- a/dsnp/update.ts +++ b/dsnp/update.ts @@ -1,4 +1,4 @@ -import { FrequencyParquetSchema } from "../types/frequency"; +import { FrequencyParquetSchema } from "../types/frequency.js"; const update: FrequencyParquetSchema = [ { diff --git a/dsnp/userPrivateConnections.spec.ts b/dsnp/userPrivateConnections.spec.ts index b5f70ca..9321f2d 100644 --- a/dsnp/userPrivateConnections.spec.ts +++ b/dsnp/userPrivateConnections.spec.ts @@ -1,4 +1,4 @@ -import privateConnectionsSchema from "./userPrivateConnections"; +import privateConnectionsSchema from "./userPrivateConnections.js"; import avro from "avro-js"; describe("Private Connections Schema", () => { diff --git a/dsnp/userPrivateFollows.spec.ts b/dsnp/userPrivateFollows.spec.ts index ced13da..1dc41ad 100644 --- a/dsnp/userPrivateFollows.spec.ts +++ b/dsnp/userPrivateFollows.spec.ts @@ -1,4 +1,4 @@ -import privateFollowsSchema from "./userPrivateFollows"; +import privateFollowsSchema from "./userPrivateFollows.js"; import avro from "avro-js"; describe("Private Follows Schema", () => { diff --git a/dsnp/userPublicFollows.spec.ts b/dsnp/userPublicFollows.spec.ts index faf40ce..405f67c 100644 --- a/dsnp/userPublicFollows.spec.ts +++ b/dsnp/userPublicFollows.spec.ts @@ -1,4 +1,4 @@ -import publicFollowsSchema from "./userPublicFollows"; +import publicFollowsSchema from "./userPublicFollows.js"; import avro from "avro-js"; describe("Public Follows Schema", () => { diff --git a/index.ts b/index.ts index 21352cf..71a85d9 100644 --- a/index.ts +++ b/index.ts @@ -1,2 +1,2 @@ -export * as dsnp from "./dsnp"; -export * as parquet from "./parquet"; +export * as dsnp from "./dsnp/index.js"; +export * as parquet from "./parquet.js"; diff --git a/jest.config.cjs b/jest.config.cjs index 8f980b6..36f6169 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -2,5 +2,8 @@ module.exports = { verbose: true, preset: 'ts-jest', testEnvironment: 'jsdom', - setupFiles: ["./test/jestSetup.cjs"] + setupFiles: ["./test/jestSetup.cjs"], + moduleNameMapper: { + "^(\\.\\.?\\/.+)\\.js$": "$1" + } }; diff --git a/parquet.spec.ts b/parquet.spec.ts index dee97d4..1519949 100644 --- a/parquet.spec.ts +++ b/parquet.spec.ts @@ -1,7 +1,7 @@ import fs from "fs"; import { ParquetWriter, ParquetReader } from "@dsnp/parquetjs"; -import { fromFrequencySchema } from "./parquet"; -import { broadcast } from "./dsnp"; +import { fromFrequencySchema } from "./parquet.js"; +import { broadcast } from "./dsnp/index.js"; describe("Frequency Schema Conversion Test File", () => { const [parquetSchema, writerOptions] = fromFrequencySchema(broadcast); diff --git a/parquet.ts b/parquet.ts index d90eaa1..793b342 100644 --- a/parquet.ts +++ b/parquet.ts @@ -1,8 +1,8 @@ import { ParquetSchema } from "@dsnp/parquetjs"; import type { ParquetType, FieldDefinition, SchemaDefinition, WriterOptions } from "@dsnp/parquetjs/dist/lib/declare"; import type { createSBBFParams } from "@dsnp/parquetjs/dist/lib/bloomFilterIO/bloomFilterWriter"; -import { FrequencyParquetSchema, FrequencyParquetType, ParquetColumn } from "./types/frequency"; -import * as dsnp from "./dsnp"; +import { FrequencyParquetSchema, FrequencyParquetType, ParquetColumn } from "./types/frequency.js"; +import * as dsnp from "./dsnp/index.js"; /** * All supported types from Parquetjs diff --git a/scripts/package.cjs b/scripts/package.cjs index d23e133..1f338b7 100644 --- a/scripts/package.cjs +++ b/scripts/package.cjs @@ -33,7 +33,7 @@ rootPackage["exports"] = { }; // Submodules -["parquet", "dsnp/index", "cli/deploy"].forEach((sub) => { +["parquet", "cli/deploy"].forEach((sub) => { rootPackage["exports"][`./${sub}`] = { types: `./${sub}.d.ts`, require: `./cjs/${sub}.js`, @@ -42,6 +42,14 @@ rootPackage["exports"] = { }; }); +// DSNP module +rootPackage["exports"][`./dsnp`] = { + types: `./dsnp/index.d.ts`, + require: `./cjs/dsnp/index.js`, + import: `./esm/dsnp/index.js`, + default: `./esm/dsnp/index.js`, +}; + // Write it out fs.writeFileSync(`${path.join(__dirname, "../dist", "package.json")}`, JSON.stringify(rootPackage, null, 2), (err) => { if (err) throw new Error(err); diff --git a/test/parquet.ts b/test/parquet.ts index d2af735..2da6a02 100644 --- a/test/parquet.ts +++ b/test/parquet.ts @@ -1,8 +1,8 @@ /* eslint-disable jest/no-export */ import fs from "fs"; import { ParquetWriter } from "@dsnp/parquetjs"; -import { FrequencyParquetSchema } from "../types/frequency"; -import { fromFrequencySchema } from "../parquet"; +import { FrequencyParquetSchema } from "../types/frequency.js"; +import { fromFrequencySchema } from "../parquet.js"; type RowGenerator = () => Record;