Skip to content

Commit

Permalink
Merge pull request #302 from frouriojs/develop
Browse files Browse the repository at this point in the history
release v1.0.1
  • Loading branch information
solufa authored Dec 27, 2023
2 parents c048e2b + 8feddb2 commit b487b47
Show file tree
Hide file tree
Showing 41 changed files with 454 additions and 374 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"eslint.run": "onSave",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.referencesCodeLens.enabled": true,
"files.eol": "\n",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"zod": "^3.21.4"
"zod": "^3.22.4"
}
}
2 changes: 1 addition & 1 deletion servers/all/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export default (fastify: FastifyInstance, options: FrourioOptions = {}) => {
preParsing: hooks_gx3glp.preParsing,
preValidation: formatMultipartData([['requiredArr', false], ['optionalArr', true], ['empty', true], ['vals', false], ['files', false]]),
},
methodToHandler(controller_17nfdm3.post.handler),
asyncMethodToHandler(controller_17nfdm3.post.handler),
);

fastify.get(
Expand Down
22 changes: 12 additions & 10 deletions servers/all/api/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/500/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/empty/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/empty/noEmpty/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/multiForm/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
20 changes: 13 additions & 7 deletions servers/all/api/multiForm/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ export default defineController(() => ({
files: z.array(multipartFileValidator()),
}),
},
handler: ({ body }) => ({
status: 201,
body: Object.entries(body).reduce(
(p, [key, val]) => ({ ...p, [key]: Array.isArray(val) ? val.length : -1 }),
{} as Methods['post']['resBody']
),
}),
handler: async ({ body }) => {
const res = {
status: 201 as const,
body: Object.entries(body).reduce(
(p, [key, val]) => ({ ...p, [key]: Array.isArray(val) ? val.length : -1 }),
{} as Methods['post']['resBody']
),
};

await body.icon.toBuffer(); // for validator test

return res;
},
},
}));
22 changes: 12 additions & 10 deletions servers/all/api/texts/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/texts/_label@string/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/texts/sample/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/users/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/users/_userId@number/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/users/_userId@number/_name/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
22 changes: 12 additions & 10 deletions servers/all/api/zod/$relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export function defineController<M extends ServerMethods, T extends Record<strin
}

export const multipartFileValidator = (): z.ZodType<MultipartFile> =>
z.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.promise(z.instanceof(Buffer))),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() })),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
});
z
.object({
type: z.literal('file'),
toBuffer: z.function().returns(z.any()),
file: z.instanceof(Readable).and(z.object({ truncated: z.boolean(), bytesRead: z.number() }).passthrough()),
fieldname: z.string(),
filename: z.string(),
encoding: z.string(),
mimetype: z.string(),
fields: z.record(z.any()),
})
.passthrough();
Loading

0 comments on commit b487b47

Please sign in to comment.