New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fets

Package Overview
Dependencies
Maintainers
1
Versions
707
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fets - npm Package Compare versions

Comparing version 0.0.1-rc-20230302134040-848f7d4 to 0.0.1-rc-20230302142015-030deeb

68

index.js

@@ -8,5 +8,62 @@ 'use strict';

const Response = DefaultFetchAPI.Response;
const Response = new Proxy(DefaultFetchAPI.Response, {
get(OriginalResponse, prop, receiver) {
if (prop === 'json') {
return function createProxyResponseJson(json, init) {
let response;
function getResponse() {
if (!response) {
response = OriginalResponse.json(json, init);
}
return response;
}
return new Proxy({}, {
get(_, prop, receiver) {
if (prop === 'json') {
return json;
}
return Reflect.get(getResponse(), prop, receiver);
},
set(_, prop, value, receiver) {
if (prop === 'json') {
json = value;
return true;
}
return Reflect.set(getResponse(), prop, value, receiver);
},
has(_, prop) {
return Reflect.has(getResponse(), prop);
},
ownKeys() {
return Reflect.ownKeys(getResponse());
},
getOwnPropertyDescriptor(_, prop) {
return Reflect.getOwnPropertyDescriptor(getResponse(), prop);
},
getPrototypeOf() {
return Reflect.getPrototypeOf(getResponse());
},
setPrototypeOf(_, prototype) {
return Reflect.setPrototypeOf(getResponse(), prototype);
},
isExtensible() {
return Reflect.isExtensible(getResponse());
},
preventExtensions() {
return Reflect.preventExtensions(getResponse());
},
defineProperty(_, prop, descriptor) {
return Reflect.defineProperty(getResponse(), prop, descriptor);
},
deleteProperty(_, prop) {
return Reflect.deleteProperty(getResponse(), prop);
},
});
};
}
return Reflect.get(OriginalResponse, prop, receiver);
},
});
function useAjv({ ajv }) {
function useAjv({ ajv, jsonSerializerFactory }) {
return {

@@ -129,2 +186,9 @@ onRoute({ schemas, handlers }) {

}
if (jsonSerializerFactory && (schemas === null || schemas === void 0 ? void 0 : schemas.responses)) {
const serializerByStatusCode = new Map();
for (const statusCode in schemas.responses) {
const schema = schemas.responses[statusCode];
serializerByStatusCode.set(Number(statusCode), jsonSerializerFactory(schema));
}
}
},

@@ -131,0 +195,0 @@ };

5

internal-plugins/ajv.d.ts
import type Ajv from 'ajv';
import { JSONSchema } from 'json-schema-to-ts';
import { RouterPlugin } from '../types';
export type JSONStringifier = (json: any) => string;
export interface AJVPluginOptions {
ajv: Ajv;
jsonSerializerFactory?: (schema: JSONSchema) => JSONStringifier;
}
export declare function useAjv({ ajv }: AJVPluginOptions): RouterPlugin<any>;
export declare function useAjv({ ajv, jsonSerializerFactory }: AJVPluginOptions): RouterPlugin<any>;
{
"name": "fets",
"version": "0.0.1-rc-20230302134040-848f7d4",
"version": "0.0.1-rc-20230302142015-030deeb",
"description": "TypeScript HTTP Framework focusing on e2e type-safety, easy setup, performance & great developer experience",
"sideEffects": false,
"dependencies": {
"@whatwg-node/fetch": "0.8.2-rc-20230302134040-848f7d4",
"@whatwg-node/server": "0.7.2-rc-20230302134040-848f7d4",
"@whatwg-node/fetch": "0.8.2-rc-20230302142015-030deeb",
"@whatwg-node/server": "0.7.2-rc-20230302142015-030deeb",
"json-schema-to-ts": "2.7.2",

@@ -10,0 +10,0 @@ "openapi-types": "12.1.0",

@@ -17,4 +17,7 @@ # FETS

It doesn't need **ANY CODE GENERATION**.
> JSON Schema allows you to have a type-safety during the implementation, request validation and 2x
> faster JSON serialization.
All these doesn't need **ANY CODE GENERATION** at all!
## Installation

@@ -577,2 +580,18 @@

### Safe and faster JSON serialization with `fast-json-stringify`
[`fast-json-stringify`](https://github.com/fastify/fast-json-stringify) is a library that serializes
JavaScript objects into JSON 2x faster than `JSON.stringify` by using JSON Schemas. So FETS can use
that library to serialize the response body. All you have to do is to install `fast-json-stringify`
package and pass `fastJsonStringify` to the router.
```ts
import jsonSerializerFactory from 'fast-json-stringify'
import { createRouter } from 'fets'
const router = createRouter({
jsonSerializerFactory
})
```
### OpenAPI Generation

@@ -579,0 +598,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc