Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalumickas committed Mar 17, 2024
1 parent ec626d3 commit dfb2177
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 56 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ jobs:
- name: Build with Next.js
run: pnpm next build

- name: Static HTML export with Next.js
run: pnpm next export

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
14 changes: 11 additions & 3 deletions docs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
const { default: next } = require('next');

const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.jsx',
})
});

module.exports = withNextra({
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
output: 'export',
images: {
unoptimized: true,
},
})
};

module.exports = withNextra(nextConfig);
4 changes: 2 additions & 2 deletions packages/analyzer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface AnalyzerOptions {
analyzers: Analyzer[];
}

export const analyzer = ({ analyzers = [] }: AnalyzerOptions) => {
export const UploAnalyzer = ({ analyzers = [] }: AnalyzerOptions) => {
return {
analyze: analyze(analyzers),
downloadToTempfile,
Expand All @@ -15,4 +15,4 @@ export const analyzer = ({ analyzers = [] }: AnalyzerOptions) => {

export type * from './types';

export default analyzer;
export default UploAnalyzer;
79 changes: 49 additions & 30 deletions packages/fastify/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { FastifyPluginAsync } from 'fastify';
import fp from 'fastify-plugin'
import { Uplo, UploOptionsAttachments } from '@uplo/node';
import fp from 'fastify-plugin';
import type { UploInstance, UploOptionsAttachments } from '@uplo/node';

export interface UploPluginOptions<AttachmentsList extends UploOptionsAttachments> {
export interface UploPluginOptions<
AttachmentsList extends UploOptionsAttachments,
> {
mountPath?: string;
uplo: Uplo<AttachmentsList>;
uplo: UploInstance<AttachmentsList>;
}

const createDirectUploadOptions = {
schema: {
body: {
type: 'object',
required: ['attachmentName', 'fileName', 'contentType', 'checksum', 'size'],
required: [
'attachmentName',
'fileName',
'contentType',
'checksum',
'size',
],
properties: {
attachmentName: { type: 'string' },
fileName: { type: 'string' },
contentType: { type: 'string' },
checksum: { type: 'string' },
size: { type: 'number' },
metadata: { type: 'object' },
}
}
}
}
},
},
},
};

interface CreateDirectUploadBody {
attachmentName: `${string}.${string}`;
Expand All @@ -36,36 +44,47 @@ interface CreateDirectUploadBody {
}

// @ts-ignore
const fastifyPlugin: FastifyPluginAsync<UploPluginOptions> = async (fastify, opts) => {
const fastifyPlugin: FastifyPluginAsync<UploPluginOptions> = async (
fastify,
opts
) => {
const options = typeof opts === 'function' ? await opts(fastify) : opts;

const { uplo } = options
const { uplo } = options;

fastify.decorate('uplo', uplo);

const mountPath = options.mountPath || '/uploads'
const mountPath = options.mountPath || '/uploads';

fastify.post<{ Body: CreateDirectUploadBody}>(`${mountPath}/create-direct-upload`, createDirectUploadOptions, async (request, reply) => {
const attachmentName = request.body['attachmentName'];
const attachment = uplo.$findGenericAttachment(attachmentName);
fastify.post<{ Body: CreateDirectUploadBody }>(
`${mountPath}/create-direct-upload`,
createDirectUploadOptions,
async (request, reply) => {
const attachmentName = request.body['attachmentName'];
const attachment = uplo.$findGenericAttachment(attachmentName);

if (!attachment) {
reply.send({ error: { message: `Cannot find attachment ${attachmentName}`} }).status(422);
return;
}
if (!attachment) {
reply
.send({
error: { message: `Cannot find attachment ${attachmentName}` },
})
.status(422);
return;
}

const params = {
fileName: request.body['fileName'],
contentType: request.body['contentType'],
size: request.body['size'],
checksum: request.body['checksum'],
metadata: request.body['metadata'],
};
const params = {
fileName: request.body['fileName'],
contentType: request.body['contentType'],
size: request.body['size'],
checksum: request.body['checksum'],
metadata: request.body['metadata'],
};

const data = await attachment.createDirectUpload({ params });
const data = await attachment.createDirectUpload({ params });

reply.send(data).status(201);
})
}
reply.send(data).status(201);
}
);
};

export default fp(fastifyPlugin);
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"sideEffects": false,
Expand Down
17 changes: 9 additions & 8 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { getDeepValue } from '@uplo/utils';
import { ID } from '@uplo/types';
import {
import type { ID } from '@uplo/types';
import type {
UploOptions,
Uplo as TUplo,
UploAttachments,
UploOptionsAttachments,
UploOptionsAttachment,
UploInstance,
} from './types';
import { UploError, AttachmentNotFoundError } from './errors';
import { Signer } from './Signer';
Expand All @@ -14,14 +15,14 @@ import { GenericAttachment } from './GenericAttachment';
import { formatAttachmentOptions } from './lib/formatAttachmentOptions';
import { defaultConfig } from './lib/defaultConfig';

const Uplo = <AttachmentsList extends UploOptionsAttachments>({
export const Uplo = <AttachmentsList extends UploOptionsAttachments>({
services = {},
defaultServiceName,
adapter,
config: providedConfig,
callbacks = {},
attachments,
}: UploOptions<AttachmentsList>): TUplo<AttachmentsList> => {
}: UploOptions<AttachmentsList>): UploInstance<AttachmentsList> => {
const config = Object.assign({}, defaultConfig, providedConfig);
const signer = Signer(config);

Expand Down Expand Up @@ -69,7 +70,7 @@ const Uplo = <AttachmentsList extends UploOptionsAttachments>({
return result;
},
{}
);
) as UploAttachments<typeof attachments>;

return {
signer,
Expand Down Expand Up @@ -99,8 +100,8 @@ const Uplo = <AttachmentsList extends UploOptionsAttachments>({
};
};

export * from '@uplo/types';
export * from './types';
export type * from '@uplo/types';
export type * from './types';
export * from './errors';
export * from './blobInputs';

Expand Down
16 changes: 8 additions & 8 deletions packages/node/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export interface UploOptions<AttachmentsList extends UploOptionsAttachments> {
attachments: AttachmentsList;
}

export interface Uplo<AttachmentsList extends UploOptionsAttachments> {
export type UploAttachments<AttachmentsList> = {
[ModelName in keyof AttachmentsList]: (id: ID) => {
[AttachmentName in keyof AttachmentsList[ModelName]]: ModelAttachment;
};
};

export interface UploInstance<AttachmentsList extends UploOptionsAttachments> {
signer: ReturnType<typeof Signer>;
adapter: Adapter;
$services: Record<string, Service>;
Expand All @@ -42,13 +48,7 @@ export interface Uplo<AttachmentsList extends UploOptionsAttachments> {
name: `${string}.${string}`
) => ReturnType<typeof GenericAttachment>;

// attachments: Record<ModelNames, Record<string, ModelAttachment>>

attachments: {
[ModelName in keyof AttachmentsList]: (id: ID) => {
[AttachmentName in keyof AttachmentsList[ModelName]]: ModelAttachment;
};
};
attachments: UploAttachments<AttachmentsList>;
}

export interface CreateDirectUploadParamsMetadata {
Expand Down

0 comments on commit dfb2177

Please sign in to comment.