From 96208ea91b46bb26066533127c9cdf298e69cd95 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 5 Sep 2023 19:18:56 -0500 Subject: [PATCH] chore: pull up TurboBaseFactory to common Implement private in enviornment specific TurboFactory, update examples in README --- README.md | 6 ++--- src/common/factory.ts | 38 +++++++++++++++++++++++++++++ src/node/factory.ts | 46 +++++++++++++++++++++++++++++++++++ src/node/index.ts | 56 ++----------------------------------------- src/web/factory.ts | 46 +++++++++++++++++++++++++++++++++++ src/web/index.ts | 55 ++---------------------------------------- 6 files changed, 137 insertions(+), 110 deletions(-) create mode 100644 src/common/factory.ts create mode 100644 src/node/factory.ts create mode 100644 src/web/factory.ts diff --git a/README.md b/README.md index 249f714e..640ace7f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The SDK is available in both CommonJS and ESM formats and is compatible with bun # Bundlers (Webpack, Rollup, ESbuild, etc.) ```javascript -import TurboFactory from '@ardrive/turbo-sdk/web'; +import { TurboFactory } from '@ardrive/turbo-sdk/web'; const turbo = TurboFactory.public({}); const rates = await turbo.getFiatRates(); @@ -60,7 +60,7 @@ const rates = await turbo.getFiatRates(); ### CommonJS ```javascript -const TurboFactory = require('@ardrive/turbo-sdk/node'); +const { TurboFactory } = require('@ardrive/turbo-sdk/node'); const turbo = TurboFactory.public({}); const rates = await turbo.getFiatRates(); @@ -69,7 +69,7 @@ const rates = await turbo.getFiatRates(); ### ESM ```javascript -import TurboFactory from '@ardrive/turbo-sdk/node'; +import { TurboFactory } from '@ardrive/turbo-sdk/node'; const turbo = TurboFactory.public({}); const rates = await turbo.getFiatRates(); diff --git a/src/common/factory.ts b/src/common/factory.ts new file mode 100644 index 00000000..e0011b1f --- /dev/null +++ b/src/common/factory.ts @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { TurboPublicConfiguration } from '../types/turbo.js'; +import { TurboUnauthenticatedPaymentService } from './payment.js'; +import { TurboUnauthenticatedClient } from './turbo.js'; +import { TurboUnauthenticatedUploadService } from './upload.js'; + +export class TurboBaseFactory { + static public({ + paymentServiceConfig = {}, + uploadServiceConfig = {}, + }: TurboPublicConfiguration = {}) { + const paymentService = new TurboUnauthenticatedPaymentService({ + ...paymentServiceConfig, + }); + const uploadService = new TurboUnauthenticatedUploadService({ + ...uploadServiceConfig, + }); + return new TurboUnauthenticatedClient({ + uploadService, + paymentService, + }); + } +} diff --git a/src/node/factory.ts b/src/node/factory.ts new file mode 100644 index 00000000..47669899 --- /dev/null +++ b/src/node/factory.ts @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { TurboBaseFactory } from '../common/factory.js'; +import { + TurboAuthenticatedClient, + TurboAuthenticatedPaymentService, + TurboAuthenticatedUploadService, +} from '../common/index.js'; +import { TurboPrivateConfiguration } from '../types/index.js'; +import { TurboNodeArweaveSigner } from './signer.js'; + +export class TurboFactory extends TurboBaseFactory { + static private({ + privateKey, + paymentServiceConfig = {}, + uploadServiceConfig = {}, + }: TurboPrivateConfiguration) { + const signer = new TurboNodeArweaveSigner({ privateKey }); + const paymentService = new TurboAuthenticatedPaymentService({ + ...paymentServiceConfig, + signer, + }); + const uploadService = new TurboAuthenticatedUploadService({ + ...uploadServiceConfig, + signer, + }); + return new TurboAuthenticatedClient({ + uploadService, + paymentService, + }); + } +} diff --git a/src/node/index.ts b/src/node/index.ts index 82ed56c6..31d71615 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -14,58 +14,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import { - TurboAuthenticatedClient, - TurboAuthenticatedPaymentService, - TurboAuthenticatedUploadService, - TurboUnauthenticatedClient, - TurboUnauthenticatedPaymentService, - TurboUnauthenticatedUploadService, -} from '../common/index.js'; -import { - TurboPrivateConfiguration, - TurboPublicConfiguration, -} from '../types/index.js'; -import { TurboNodeArweaveSigner } from './signer.js'; - -export class TurboFactory { - static public({ - paymentServiceConfig = {}, - uploadServiceConfig = {}, - }: TurboPublicConfiguration = {}) { - const paymentService = new TurboUnauthenticatedPaymentService({ - ...paymentServiceConfig, - }); - const uploadService = new TurboUnauthenticatedUploadService({ - ...uploadServiceConfig, - }); - return new TurboUnauthenticatedClient({ - uploadService, - paymentService, - }); - } - - static private({ - privateKey, - paymentServiceConfig = {}, - uploadServiceConfig = {}, - }: TurboPrivateConfiguration) { - const signer = new TurboNodeArweaveSigner({ privateKey }); - - const paymentService = new TurboAuthenticatedPaymentService({ - ...paymentServiceConfig, - signer, - }); - const uploadService = new TurboAuthenticatedUploadService({ - ...uploadServiceConfig, - signer, - }); - return new TurboAuthenticatedClient({ - uploadService, - paymentService, - }); - } -} - -// additionally export classes +export * from './factory.js'; +export * from './signer.js'; export * from '../common/index.js'; diff --git a/src/web/factory.ts b/src/web/factory.ts new file mode 100644 index 00000000..4c5c04ca --- /dev/null +++ b/src/web/factory.ts @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { TurboBaseFactory } from '../common/factory.js'; +import { + TurboAuthenticatedClient, + TurboAuthenticatedPaymentService, + TurboAuthenticatedUploadService, +} from '../common/index.js'; +import { TurboPrivateConfiguration } from '../types/index.js'; +import { TurboWebArweaveSigner } from './signer.js'; + +export class TurboFactory extends TurboBaseFactory { + static private({ + privateKey, + paymentServiceConfig = {}, + uploadServiceConfig = {}, + }: TurboPrivateConfiguration) { + const signer = new TurboWebArweaveSigner({ privateKey }); + const paymentService = new TurboAuthenticatedPaymentService({ + ...paymentServiceConfig, + signer, + }); + const uploadService = new TurboAuthenticatedUploadService({ + ...uploadServiceConfig, + signer, + }); + return new TurboAuthenticatedClient({ + uploadService, + paymentService, + }); + } +} diff --git a/src/web/index.ts b/src/web/index.ts index 19a23017..31d71615 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -14,57 +14,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import { - TurboAuthenticatedClient, - TurboAuthenticatedPaymentService, - TurboAuthenticatedUploadService, - TurboUnauthenticatedClient, - TurboUnauthenticatedPaymentService, - TurboUnauthenticatedUploadService, -} from '../common/index.js'; -import { - TurboPrivateConfiguration, - TurboPublicConfiguration, -} from '../types/index.js'; -import { TurboWebArweaveSigner } from '../web/signer.js'; - -export class TurboFactory { - static public({ - paymentServiceConfig = {}, - uploadServiceConfig = {}, - }: TurboPublicConfiguration = {}) { - const paymentService = new TurboUnauthenticatedPaymentService({ - ...paymentServiceConfig, - }); - const uploadService = new TurboUnauthenticatedUploadService({ - ...uploadServiceConfig, - }); - return new TurboUnauthenticatedClient({ - uploadService, - paymentService, - }); - } - - static private({ - privateKey, - paymentServiceConfig = {}, - uploadServiceConfig = {}, - }: TurboPrivateConfiguration) { - const signer = new TurboWebArweaveSigner({ privateKey }); - const paymentService = new TurboAuthenticatedPaymentService({ - ...paymentServiceConfig, - signer, - }); - const uploadService = new TurboAuthenticatedUploadService({ - ...uploadServiceConfig, - signer, - }); - return new TurboAuthenticatedClient({ - uploadService, - paymentService, - }); - } -} - -// additionally export classes +export * from './factory.js'; +export * from './signer.js'; export * from '../common/index.js';