Socket
Socket
Sign inDemoInstall

json-server

Package Overview
Dependencies
54
Maintainers
1
Versions
151
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-alpha.21 to 1.0.0-alpha.22

14

lib/app.js

@@ -32,3 +32,13 @@ import { dirname, isAbsolute, join } from 'node:path';

const { name = '' } = req.params;
res.locals['data'] = service.find(name, req.query);
const query = Object.fromEntries(Object.entries(req.query)
.map(([key, value]) => {
if (['_start', '_end', '_limit', '_page', '_per_page'].includes(key) && typeof value === 'string') {
return [key, parseInt(value)];
}
else {
return [key, value];
}
})
.filter(([_, value]) => !Number.isNaN(value)));
res.locals['data'] = service.find(name, query);
next();

@@ -78,3 +88,3 @@ });

const { name = '', id = '' } = req.params;
res.locals['data'] = await service.destroyById(name, id);
res.locals['data'] = await service.destroyById(name, id, req.query['dependent']);
next();

@@ -81,0 +91,0 @@ });

5

lib/service.d.ts

@@ -24,4 +24,3 @@ import { Low } from 'lowdb';

[key: string]: unknown;
} & {
_embed?: string[];
_embed?: string | string[];
_sort?: string;

@@ -39,3 +38,3 @@ _start?: number;

patchById(name: string, id: string, body?: Item): Promise<Item | undefined>;
destroyById(name: string, id: string, dependents?: string[]): Promise<Item | undefined>;
destroyById(name: string, id: string, dependent?: string | string[]): Promise<Item | undefined>;
}

@@ -227,8 +227,11 @@ import { randomBytes } from 'node:crypto';

const limit = query._limit;
if (start === undefined && limit) {
if (start !== undefined) {
if (end !== undefined) {
return sorted.slice(start, end);
}
return sorted.slice(start, start + (limit || 0));
}
if (limit !== undefined) {
return sorted.slice(0, limit);
}
if (start && limit) {
return sorted.slice(start, start + limit);
}
// Paginate

@@ -303,3 +306,3 @@ let page = query._page;

}
async destroyById(name, id, dependents = []) {
async destroyById(name, id, dependent) {
const items = this.#get(name);

@@ -314,2 +317,3 @@ if (items === undefined || !Array.isArray(items))

nullifyForeignKey(this.#db, name, id);
const dependents = ensureArray(dependent);
deleteDependents(this.#db, name, dependents);

@@ -316,0 +320,0 @@ await this.#db.write();

{
"name": "json-server",
"version": "1.0.0-alpha.21",
"version": "1.0.0-alpha.22",
"description": "",

@@ -5,0 +5,0 @@ "type": "module",

@@ -172,3 +172,3 @@ > [!IMPORTANT]

DELETE /posts/1
DELETE /posts/1?_embed=comments
DELETE /posts/1?_dependent=comments
```

@@ -175,0 +175,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc