Skip to content

Commit

Permalink
fix: add separate folder for types, use it in named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Sep 18, 2023
1 parent 4cd3fb5 commit 7bd1e63
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 57 deletions.
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0-alpha.10",
"type": "module",
"main": "./lib/cjs/node/index.js",
"types": "./lib/cjs/node/index.d.ts",
"types": "./lib/types/node/index.d.ts",
"module": "./lib/esm/node/index.js",
"browser": "./bundles/web.bundle.min.js",
"repository": {
Expand All @@ -25,23 +25,18 @@
".": {
"import": "./lib/esm/node/index.js",
"require": "./lib/cjs/node/index.js",
"types": "./lib/node/index.d.ts"
"types": "./lib/types/node/index.d.ts"
},
"./node": {
"import": "./lib/esm/node/index.js",
"require": "./lib/cjs/node/index.js",
"types": "./lib/node/index.d.ts"
"types": "./lib/types/node/index.d.ts"
},
"./web": {
"import": "./lib/web/index.js",
"require": "./lib/web/index.js",
"types": "./lib/web/index.d.ts",
"types": "./lib/types/web/index.d.ts",
"browser": "./bundles/web.bundle.min.js"
},
"./*": {
"import": "./*.js",
"require": "./*.js",
"types": "./lib/web/index.d.ts"
}
},
"engines": {
Expand All @@ -50,7 +45,10 @@
"license": "AGPL-3.0-or-later",
"scripts": {
"build:web": "node bundle.cjs",
"build": "yarn clean && yarn tsc -p tsconfig.json && yarn tsc -p tsconfig.cjs.json",
"build:esm": "yarn tsc -p tsconfig.json",
"build:cjs": "yarn tsc -p tsconfig.cjs.json",
"build:types": "yarn tsc -p tsconfig.types.json",
"build": "yarn clean && yarn build:web && yarn build:esm && yarn build:cjs && yarn build:types",
"clean": "rimraf [ lib coverage bundles ]",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
Expand Down
2 changes: 1 addition & 1 deletion src/common/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { TurboPublicConfiguration } from '../types/turbo.js';
import { TurboPublicConfiguration } from '../types.js';
import { TurboUnauthenticatedPaymentService } from './payment.js';
import { TurboUnauthenticatedClient } from './turbo.js';
import { TurboUnauthenticatedUploadService } from './upload.js';
Expand Down
2 changes: 1 addition & 1 deletion src/common/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ReadableStream } from 'stream/web';
import {
TurboHTTPServiceInterface,
TurboSignedRequestHeaders,
} from '../types/turbo.js';
} from '../types.js';
import { createAxiosInstance } from '../utils/axiosClient.js';
import { FailedRequestError } from '../utils/errors.js';

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/common/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
TurboUnauthenticatedPaymentServiceInterface,
TurboUnauthenticatedPaymentServiceInterfaceConfiguration,
TurboWalletSigner,
} from '../types/turbo.js';
} from '../types.js';
import { TurboHTTPService } from './http.js';

export class TurboUnauthenticatedPaymentService
Expand Down
2 changes: 1 addition & 1 deletion src/common/turbo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
TurboUnauthenticatedPaymentServiceInterface,
TurboUnauthenticatedUploadServiceInterface,
TurboUploadDataItemResponse,
} from '../types/index.js';
} from '../types.js';
import { TurboUnauthenticatedPaymentService } from './payment.js';
import { TurboUnauthenticatedUploadService } from './upload.js';

Expand Down
2 changes: 1 addition & 1 deletion src/common/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
TurboUnauthenticatedUploadServiceInterfaceConfiguration,
TurboUploadDataItemResponse,
TurboWalletSigner,
} from '../types/turbo.js';
} from '../types.js';
import { TurboHTTPService } from './http.js';

export class TurboUnauthenticatedUploadService
Expand Down
2 changes: 1 addition & 1 deletion src/node/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TurboAuthenticatedPaymentService,
TurboAuthenticatedUploadService,
} from '../common/index.js';
import { TurboPrivateConfiguration } from '../types/index.js';
import { TurboPrivateConfiguration } from '../types.js';
import { TurboNodeArweaveSigner } from './signer.js';

export class TurboFactory extends TurboBaseFactory {
Expand Down
2 changes: 1 addition & 1 deletion src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
*/
export * from './factory.js';
export * from './signer.js';
export * from '../types.js';
export * from '../common/index.js';
export * from '../types/index.js';
4 changes: 2 additions & 2 deletions src/node/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import Arweave from 'arweave/node/index.js';
import { randomBytes } from 'node:crypto';
import { Readable } from 'node:stream';

import { JWKInterface } from '../types/arweave.js';
import { TurboWalletSigner } from '../types/turbo.js';
import { JWKInterface } from '../common/jwk.js';
import { TurboWalletSigner } from '../types.js';
import { toB64Url } from '../utils/base64.js';

export class TurboNodeArweaveSigner implements TurboWalletSigner {
Expand Down
2 changes: 1 addition & 1 deletion src/types/turbo.ts → src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ReadableStream } from 'node:stream/web';
import { RetryConfig } from 'retry-axios';
import winston from 'winston';

import { JWKInterface } from './arweave.js';
import { JWKInterface } from './common/jwk.js';

export type Base64String = string;
export type PublicArweaveAddress = Base64String;
Expand Down
18 changes: 0 additions & 18 deletions src/types/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/utils/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { bufferTob64Url } from 'arweave/node/lib/utils.js';
import { createHash } from 'crypto';

import { JWKInterface } from '../types/index.js';
import { Base64String, PublicArweaveAddress } from '../types/index.js';
import { JWKInterface } from '../common/jwk.js';
import { Base64String, PublicArweaveAddress } from '../types.js';

export const base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;

Expand Down
2 changes: 1 addition & 1 deletion src/web/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TurboAuthenticatedPaymentService,
TurboAuthenticatedUploadService,
} from '../common/index.js';
import { TurboPrivateConfiguration } from '../types/index.js';
import { TurboPrivateConfiguration } from '../types.js';
import { TurboWebArweaveSigner } from './signer.js';

export class TurboFactory extends TurboBaseFactory {
Expand Down
2 changes: 1 addition & 1 deletion src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
export * from './factory.js';
export * from './signer.js';
export * from '../common/index.js';
export * from '../types/index.js';
export * from '../types.js';
13 changes: 5 additions & 8 deletions src/web/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import Arweave from 'arweave';
import { randomBytes } from 'node:crypto';
import { ReadableStream } from 'node:stream/web';

import { JWKInterface } from '../types/arweave.js';
import { TurboWalletSigner } from '../types/turbo.js';
import { JWKInterface } from '../common/jwk.js';
import { TurboWalletSigner } from '../types.js';
import { toB64Url } from '../utils/base64.js';
import { readableStreamToBuffer } from '../utils/readableStream.js';

Expand Down Expand Up @@ -50,14 +50,11 @@ export class TurboWebArweaveSigner implements TurboWalletSigner {

// NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto
async generateSignedRequestHeaders() {
// a bit hacky - but arweave exports cause issues in tests vs. browser
const arweave: Arweave = (Arweave as any).default ?? Arweave;
const nonce = randomBytes(16).toString('hex');
const buffer = Buffer.from(nonce);
// a bit hacky - but easiest way to solve web signing issues while still building for cjs
const signature = await (Arweave as any).default.crypto.sign(
this.privateKey,
buffer,
{},
);
const signature = await arweave.crypto.sign(this.privateKey, buffer, {});

return {
'x-public-key': this.privateKey.n,
Expand Down
2 changes: 1 addition & 1 deletion tests/turbo.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { expect } from 'chai';
import fs from 'fs';
import { Readable } from 'node:stream';

import { JWKInterface } from '../src/common/jwk.js';
import {
TurboAuthenticatedClient,
TurboUnauthenticatedClient,
} from '../src/common/turbo.js';
import { TurboFactory } from '../src/node/factory.js';
import { JWKInterface } from '../src/types/index.js';
import { jwkToPublicArweaveAddress } from '../src/utils/base64.js';

describe('Node environment', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/turbo.web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { CanceledError } from 'axios';
import { expect } from 'chai';
import { ReadableStream } from 'node:stream/web';

import { JWKInterface } from '../src/common/jwk.js';
import {
TurboAuthenticatedClient,
TurboUnauthenticatedClient,
} from '../src/common/turbo.js';
import { JWKInterface } from '../src/types/index.js';
import { jwkToPublicArweaveAddress } from '../src/utils/base64.js';
import { TurboFactory } from '../src/web/index.js';

Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"compilerOptions": {
"target": "es6",
"allowSyntheticDefaultImports": true,
"declaration": true,
"lib": ["esnext", "dom"],
"outDir": "./lib/esm",
"listEmittedFiles": false,
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.node.json

This file was deleted.

9 changes: 9 additions & 0 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"outDir": "./lib/types",
"emitDeclarationOnly": true
}
}

0 comments on commit 7bd1e63

Please sign in to comment.