@instantdb/core
Advanced tools
Comparing version 0.17.0-experimental.5 to 0.17.0
@@ -194,2 +194,25 @@ import { test, expect } from "vitest"; | ||
test("like case sensitivity", () => { | ||
function runQuery(where) { | ||
return query( | ||
{ store }, | ||
{ | ||
users: { | ||
$: { | ||
where: { | ||
fullName: where, | ||
}, | ||
}, | ||
}, | ||
}, | ||
) | ||
.data.users.map((x) => x.fullName) | ||
.sort(); | ||
} | ||
expect(runQuery({ $like: "%O%" })).toEqual([]); | ||
expect(runQuery({ $ilike: "%O%" })).toEqual(["Joe Averbukh", "Nicole"]); | ||
expect(runQuery({ $like: "%j%" })).toEqual([]); | ||
expect(runQuery({ $ilike: "%j%" })).toEqual(["Joe Averbukh"]); | ||
}); | ||
test("Where and", () => { | ||
@@ -196,0 +219,0 @@ expect( |
@@ -98,8 +98,16 @@ "use strict"; | ||
} | ||
function matchesLikePattern(value, pattern) { | ||
if (typeof value !== "string" || typeof pattern !== "string") | ||
return false; | ||
function makeLikeMatcher(caseSensitive, pattern) { | ||
if (typeof pattern !== "string") { | ||
return function likeMatcher(_value) { | ||
return false; | ||
}; | ||
} | ||
const regexPattern = pattern.replace(/%/g, ".*").replace(/_/g, "."); | ||
const regex = new RegExp(`^${regexPattern}$`); | ||
return regex.test(value); | ||
const regex = new RegExp(`^${regexPattern}$`, caseSensitive ? undefined : "i"); | ||
return function likeMatcher(value) { | ||
if (typeof value !== "string") { | ||
return false; | ||
} | ||
return regex.test(value); | ||
}; | ||
} | ||
@@ -162,9 +170,19 @@ function parseValue(attr, v) { | ||
if (v.hasOwnProperty("$like")) { | ||
const matcher = makeLikeMatcher(true, v.$like); | ||
return { | ||
$comparator: true, | ||
$op: function like(triple) { | ||
return matchesLikePattern(triple[2], v.$like); | ||
return matcher(triple[2]); | ||
}, | ||
}; | ||
} | ||
if (v.hasOwnProperty("$ilike")) { | ||
const matcher = makeLikeMatcher(false, v.$ilike); | ||
return { | ||
$comparator: true, | ||
$op: function ilike(triple) { | ||
return matcher(triple[2]); | ||
}, | ||
}; | ||
} | ||
return v; | ||
@@ -171,0 +189,0 @@ } |
@@ -72,8 +72,16 @@ import { query as datalogQuery } from "./datalog"; | ||
} | ||
function matchesLikePattern(value, pattern) { | ||
if (typeof value !== "string" || typeof pattern !== "string") | ||
return false; | ||
function makeLikeMatcher(caseSensitive, pattern) { | ||
if (typeof pattern !== "string") { | ||
return function likeMatcher(_value) { | ||
return false; | ||
}; | ||
} | ||
const regexPattern = pattern.replace(/%/g, ".*").replace(/_/g, "."); | ||
const regex = new RegExp(`^${regexPattern}$`); | ||
return regex.test(value); | ||
const regex = new RegExp(`^${regexPattern}$`, caseSensitive ? undefined : "i"); | ||
return function likeMatcher(value) { | ||
if (typeof value !== "string") { | ||
return false; | ||
} | ||
return regex.test(value); | ||
}; | ||
} | ||
@@ -136,9 +144,19 @@ function parseValue(attr, v) { | ||
if (v.hasOwnProperty("$like")) { | ||
const matcher = makeLikeMatcher(true, v.$like); | ||
return { | ||
$comparator: true, | ||
$op: function like(triple) { | ||
return matchesLikePattern(triple[2], v.$like); | ||
return matcher(triple[2]); | ||
}, | ||
}; | ||
} | ||
if (v.hasOwnProperty("$ilike")) { | ||
const matcher = makeLikeMatcher(false, v.$ilike); | ||
return { | ||
$comparator: true, | ||
$op: function ilike(triple) { | ||
return matcher(triple[2]); | ||
}, | ||
}; | ||
} | ||
return v; | ||
@@ -145,0 +163,0 @@ } |
@@ -19,2 +19,3 @@ import type { EntitiesDef, IContainEntitiesAndLinks, InstantGraph, LinkAttrDef, ResolveAttrs, ResolveEntityAttrs } from "./schemaTypes"; | ||
$like?: string; | ||
$ilike?: string; | ||
}; | ||
@@ -21,0 +22,0 @@ type WhereClauseValue = string | number | boolean | NonEmpty<WhereArgs>; |
export default version; | ||
declare const version: "0.17.0-experimental.5"; | ||
declare const version: "v0.17.0"; | ||
//# sourceMappingURL=version.d.ts.map |
// Autogenerated by publish_packages.clj | ||
const version = "0.17.0-experimental.5"; | ||
const version = "v0.17.0"; | ||
export default version; | ||
//# sourceMappingURL=version.js.map |
@@ -19,2 +19,3 @@ import type { EntitiesDef, IContainEntitiesAndLinks, InstantGraph, LinkAttrDef, ResolveAttrs, ResolveEntityAttrs } from "./schemaTypes"; | ||
$like?: string; | ||
$ilike?: string; | ||
}; | ||
@@ -21,0 +22,0 @@ type WhereClauseValue = string | number | boolean | NonEmpty<WhereArgs>; |
export default version; | ||
declare const version: "0.17.0-experimental.5"; | ||
declare const version: "v0.17.0"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Autogenerated by publish_packages.clj | ||
const version = "0.17.0-experimental.5"; | ||
const version = "v0.17.0"; | ||
exports.default = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@instantdb/core", | ||
"version": "0.17.0-experimental.5", | ||
"version": "v0.17.0", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -91,7 +91,19 @@ import { query as datalogQuery } from "./datalog"; | ||
function matchesLikePattern(value, pattern) { | ||
if (typeof value !== "string" || typeof pattern !== "string") return false; | ||
function makeLikeMatcher(caseSensitive, pattern) { | ||
if (typeof pattern !== "string") { | ||
return function likeMatcher(_value) { | ||
return false; | ||
}; | ||
} | ||
const regexPattern = pattern.replace(/%/g, ".*").replace(/_/g, "."); | ||
const regex = new RegExp(`^${regexPattern}$`); | ||
return regex.test(value); | ||
const regex = new RegExp( | ||
`^${regexPattern}$`, | ||
caseSensitive ? undefined : "i", | ||
); | ||
return function likeMatcher(value) { | ||
if (typeof value !== "string") { | ||
return false; | ||
} | ||
return regex.test(value); | ||
}; | ||
} | ||
@@ -161,6 +173,7 @@ | ||
if (v.hasOwnProperty("$like")) { | ||
const matcher = makeLikeMatcher(true, v.$like); | ||
return { | ||
$comparator: true, | ||
$op: function like(triple) { | ||
return matchesLikePattern(triple[2], v.$like); | ||
return matcher(triple[2]); | ||
}, | ||
@@ -170,2 +183,12 @@ }; | ||
if (v.hasOwnProperty("$ilike")) { | ||
const matcher = makeLikeMatcher(false, v.$ilike); | ||
return { | ||
$comparator: true, | ||
$op: function ilike(triple) { | ||
return matcher(triple[2]); | ||
}, | ||
}; | ||
} | ||
return v; | ||
@@ -172,0 +195,0 @@ } |
@@ -35,2 +35,3 @@ // Query | ||
$like?: string; | ||
$ilike?: string; | ||
}; | ||
@@ -37,0 +38,0 @@ |
// Autogenerated by publish_packages.clj | ||
const version = "0.17.0-experimental.5"; | ||
const version = "v0.17.0"; | ||
export default version; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
2572519
45788
9