Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fergies-inverted-index

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fergies-inverted-index - npm Package Compare versions

Comparing version 13.0.0-rc.3 to 13.0.0-rc.4

2

package.json
{
"name": "fergies-inverted-index",
"version": "13.0.0-rc.3",
"version": "13.0.0-rc.4",
"description": "An inverted index that allows javascript objects to be easily serialised and retrieved using promises and map-reduce",

@@ -5,0 +5,0 @@ "browser": "src/entrypoints/browser.js",

@@ -20,9 +20,10 @@ import charwise from 'charwise'

}),
tokenParser: new TokenParser(),
...ops
}
const r = read(ops)
const w = write(ops)
const tokenParser = new TokenParser(ops.caseSensitive)
const r = read(ops, tokenParser)
const w = write(ops, tokenParser)
// timestamp with time of creation (if not created already)

@@ -62,3 +63,3 @@ // note: async, so this is "fire and forget"

this.TIMESTAMP_LAST_UPDATED = w.TIMESTAMP_LAST_UPDATED
this.TOKEN_PARSER = ops.tokenParser
this.TOKEN_PARSER = tokenParser
}

@@ -65,0 +66,0 @@

@@ -9,10 +9,25 @@ // polyfill- HI and LO coming in next version of charwise

export class TokenParser {
constructor (availableFields = []) {
this.setAvailableFields(availableFields)
availableFields = []
#caseSensitive
constructor (caseSensitive) {
this.#caseSensitive = caseSensitive
}
setAvailableFields (availableFields) {
setAvailableFields = availableFields => {
this.availableFields = availableFields
}
#setCaseSensitivity = token => {
const setCase = str =>
this.#caseSensitive || typeof str !== 'string' ? str : str.toLowerCase()
return {
FIELD: token.FIELD.map(setCase),
VALUE: {
GTE: setCase(token.VALUE.GTE),
LTE: setCase(token.VALUE.LTE)
}
}
}
parse (token) {

@@ -34,3 +49,3 @@ // case: <value>

if (token.indexOf(':') === -1) {
return {
return this.#setCaseSensitivity({
FIELD: this.availableFields,

@@ -41,7 +56,7 @@ VALUE: {

}
}
})
}
const [field, ...value] = token.split(':')
return {
return this.#setCaseSensitivity({
FIELD: [field],

@@ -52,3 +67,3 @@ VALUE: {

}
}
})
}

@@ -110,6 +125,6 @@

if (typeof token.FIELD === 'undefined') {
return {
return this.#setCaseSensitivity({
FIELD: this.availableFields,
...token
}
})
}

@@ -119,4 +134,4 @@ // Allow FIELD to be an array or a string

return token
return this.#setCaseSensitivity(token)
}
}

@@ -7,3 +7,3 @@ import charwise from 'charwise'

export default function (ops) {
export default function (ops, tokenParser) {
const isString = s => typeof s === 'string'

@@ -36,14 +36,2 @@

const setCaseSensitivity = token => {
const setCase = str =>
ops.caseSensitive || typeof str !== 'string' ? str : str.toLowerCase()
return {
FIELD: token.FIELD.map(setCase),
VALUE: {
GTE: setCase(token.VALUE.GTE),
LTE: setCase(token.VALUE.LTE)
}
}
}
// If this token is a stopword then return 'undefined'

@@ -72,5 +60,6 @@ const removeStopwords = token =>

token = ops.tokenParser.parse(token)
token = tokenParser.parse(token)
// testForBreak(token) // ?
token = await setCaseSensitivity(token)
// token = await setCaseSensitivity(token)
// testForBreak(token) // ?

@@ -222,3 +211,3 @@ token = await removeStopwords(token)

const BUCKET = token => {
token = ops.tokenParser.parse(token)
token = tokenParser.parse(token)
return GET(token).then(result => ({

@@ -252,3 +241,3 @@ _id: [...result.reduce((acc, cur) => acc.add(cur._id), new Set())].sort(),

RANGE({
...ops.tokenParser.parse(token),
...tokenParser.parse(token),
LIMIT: 1,

@@ -273,3 +262,3 @@ REVERSE: reverse

const DIST = token => {
token = ops.tokenParser.parse(token)
token = tokenParser.parse(token)
return Promise.all(

@@ -322,3 +311,3 @@ token.FIELD.map(field => {

const FACET = token => {
token = ops.tokenParser.parse(token)
token = tokenParser.parse(token)
return Promise.all(

@@ -325,0 +314,0 @@ token.FIELD.map(field =>

import trav from 'traverse'
import reader from './read.js'
export default function (ops) {
export default function (ops, tokenParser) {
// TODO: set reset this to the max value every time the DB is restarted

@@ -35,3 +35,9 @@ let incrementalId = 0

fieldName,
[this.node].flat(Infinity)
[this.node]
.flat(Infinity)
.map(item =>
typeof item === 'string' && !ops.caseSensitive
? item.toLowerCase()
: item
)
])

@@ -211,3 +217,3 @@ // bump to lower case if not case sensitive

.then(() => reader(ops).FIELDS())
.then(fields => ops.tokenParser.setAvailableFields(fields))
.then(fields => tokenParser.setAvailableFields(fields))

@@ -228,3 +234,3 @@ const PUT = (docs, putOptions = {}) =>

// TODO: reader should not be inited here
ops.tokenParser.setAvailableFields(await reader(ops).FIELDS())
tokenParser.setAvailableFields(await reader(ops).FIELDS())
return passThrough

@@ -231,0 +237,0 @@ })

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