json-server
Advanced tools
Comparing version 1.0.0-alpha.18 to 1.0.0-alpha.19
@@ -20,3 +20,3 @@ import { Low } from 'lowdb'; | ||
findById(name: string, id: string, query: { | ||
_embed?: string[]; | ||
_embed?: string[] | string; | ||
}): Item | undefined; | ||
@@ -23,0 +23,0 @@ find(name: string, query?: { |
@@ -27,2 +27,5 @@ import { randomBytes } from 'node:crypto'; | ||
} | ||
function ensureArray(arg = []) { | ||
return Array.isArray(arg) ? arg : [arg]; | ||
} | ||
function embed(db, name, item, related) { | ||
@@ -110,3 +113,3 @@ if (inflection.singularize(related) === related) { | ||
let item = value.find((item) => item['id'] === id); | ||
query._embed?.forEach((related) => { | ||
ensureArray(query._embed).forEach((related) => { | ||
if (item !== undefined) | ||
@@ -125,5 +128,6 @@ item = embed(this.#db, name, item, related); | ||
// Include | ||
query._embed?.forEach((related) => { | ||
if (items !== undefined && Array.isArray(items)) | ||
ensureArray(query._embed).forEach((related) => { | ||
if (items !== undefined && Array.isArray(items)) { | ||
items = items.map((item) => embed(this.#db, name, item, related)); | ||
} | ||
}); | ||
@@ -148,4 +152,13 @@ // Return list if no query params | ||
} | ||
if (['_sort', '_start', '_end', '_limit', '_page', '_per_page'].includes(key)) | ||
if ([ | ||
'_embed', | ||
'_sort', | ||
'_start', | ||
'_end', | ||
'_limit', | ||
'_page', | ||
'_per_page', | ||
].includes(key)) { | ||
continue; | ||
} | ||
conds[key] = [Condition.default, value]; | ||
@@ -152,0 +165,0 @@ } |
{ | ||
"name": "json-server", | ||
"version": "1.0.0-alpha.18", | ||
"version": "1.0.0-alpha.19", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58271
1692