Skip to content

Commit

Permalink
chore: pull up TurboBaseFactory to common
Browse files Browse the repository at this point in the history
Implement private in enviornment specific TurboFactory, update examples in README
  • Loading branch information
dtfiedler committed Sep 6, 2023
1 parent 3acba94 commit 96208ea
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 110 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
38 changes: 38 additions & 0 deletions src/common/factory.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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,
});
}
}
46 changes: 46 additions & 0 deletions src/node/factory.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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,
});
}
}
56 changes: 2 additions & 54 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,6 @@
* 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 {
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';
46 changes: 46 additions & 0 deletions src/web/factory.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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,
});
}
}
55 changes: 2 additions & 53 deletions src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,6 @@
* 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 {
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';

0 comments on commit 96208ea

Please sign in to comment.