MCPcopy
hub / github.com/typicode/json-server / list

Function list

src/server/router/plural.js:51–228  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

49 // GET /name?_start=&_end=&
50 // GET /name?_embed=&_expand=
51 function list(req, res, next) {
52 // Resource chain
53 let chain = db.get(name)
54
55 // Remove q, _start, _end, ... from req.query to avoid filtering using those
56 // parameters
57 let q = req.query.q
58 let _start = req.query._start
59 let _end = req.query._end
60 let _page = req.query._page
61 const _sort = req.query._sort
62 const _order = req.query._order
63 let _limit = req.query._limit
64 const _embed = req.query._embed
65 const _expand = req.query._expand
66 delete req.query.q
67 delete req.query._start
68 delete req.query._end
69 delete req.query._sort
70 delete req.query._order
71 delete req.query._limit
72 delete req.query._embed
73 delete req.query._expand
74
75 // Automatically delete query parameters that can't be found
76 // in the database
77 Object.keys(req.query).forEach((query) => {
78 const arr = db.get(name).value()
79 for (const i in arr) {
80 if (
81 _.has(arr[i], query) ||
82 query === 'callback' ||
83 query === '_' ||
84 /_lte$/.test(query) ||
85 /_gte$/.test(query) ||
86 /_ne$/.test(query) ||
87 /_like$/.test(query)
88 )
89 return
90 }
91 delete req.query[query]
92 })
93
94 if (q) {
95 // Full-text search
96 if (Array.isArray(q)) {
97 q = q[0]
98 }
99
100 q = q.toLowerCase()
101
102 chain = chain.filter((obj) => {
103 for (const key in obj) {
104 const value = obj[key]
105 if (db._.deepQuery(value, q)) {
106 return true
107 }
108 }

Callers

nothing calls this directly

Calls 2

embedFunction · 0.85
expandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…