Skip to content

Commit

Permalink
Bump dwn-sdk-js to v0.2.6 (#9)
Browse files Browse the repository at this point in the history
* Bump dwn-sdk-js to v0.2.5

* Bump package version

* Bump to v0.2.6

* sanitized values accepts strings or numbers

---------

Co-authored-by: Liran Cohen <[email protected]>
  • Loading branch information
Diane Huxley and LiranCohen authored Nov 7, 2023
1 parent f36d8a3 commit 68b1a81
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
35 changes: 24 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbd54566975/dwn-sql-store",
"version": "0.2.1",
"version": "0.2.2",
"description": "SQL backed implementations of DWN MessageStore, DataStore, and EventLog",
"type": "module",
"license": "Apache-2.0",
Expand All @@ -21,7 +21,7 @@
"react-native": "./dist/esm/src/main.js",
"dependencies": {
"@ipld/dag-cbor": "^9.0.5",
"@tbd54566975/dwn-sdk-js": "0.2.4",
"@tbd54566975/dwn-sdk-js": "0.2.6",
"kysely": "0.26.3",
"multiformats": "12.0.1",
"readable-stream": "4.4.2"
Expand Down
2 changes: 1 addition & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface MessageStoreTable {
method: string | null;
schema: string | null;
dataCid: string | null;
dataSize: string | null;
dataSize: number | null;
dateCreated: string | null;
messageTimestamp: string | null;
dataFormat: string | null;
Expand Down
2 changes: 1 addition & 1 deletion src/message-store-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class MessageStoreSql implements MessageStore {
.addColumn('method', 'text')
.addColumn('schema', 'text')
.addColumn('dataCid', 'text')
.addColumn('dataSize', 'text')
.addColumn('dataSize', 'integer')
.addColumn('dateCreated', 'text')
.addColumn('messageTimestamp', 'text')
.addColumn('dataFormat', 'text')
Expand Down
12 changes: 6 additions & 6 deletions src/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Filter } from '@tbd54566975/dwn-sdk-js';
import { DynamicModule, ExpressionBuilder, OperandExpression, SelectQueryBuilder, SqlBool } from 'kysely';
import { sanitizedString } from './sanitize.js';
import { sanitizedValue } from './sanitize.js';

/**
* Takes multiple Filters and returns a single query.
Expand Down Expand Up @@ -48,19 +48,19 @@ function processFilter<DB = unknown, TB extends keyof DB = keyof DB>(
andOperands.push(eb(column, 'in', value));
} else if (typeof value === 'object') { // RangeFilter
if (value.gt) {
andOperands.push(eb(column, '>', sanitizedString(value.gt)));
andOperands.push(eb(column, '>', sanitizedValue(value.gt)));
}
if (value.gte) {
andOperands.push(eb(column, '>=', sanitizedString(value.gte)));
andOperands.push(eb(column, '>=', sanitizedValue(value.gte)));
}
if (value.lt) {
andOperands.push(eb(column, '<', sanitizedString(value.lt)));
andOperands.push(eb(column, '<', sanitizedValue(value.lt)));
}
if (value.lte) {
andOperands.push(eb(column, '<=', sanitizedString(value.lte)));
andOperands.push(eb(column, '<=', sanitizedValue(value.lte)));
}
} else { // EqualFilter
andOperands.push(eb(column, '=', sanitizedString(value)));
andOperands.push(eb(column, '=', sanitizedValue(value)));
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/utils/sanitize.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export function sanitizeRecords(records: Record<string, string>) {
export function sanitizeRecords(records: Record<string, string | number>) {
for (let key in records) {
let value = records[key];
records[key] = sanitizedString(value);
records[key] = sanitizedValue(value);
}
}

export function sanitizedString(value: any): string {
export function sanitizedValue(value: any): string | number {
if (typeof value === 'string') {
return value;
} else if (typeof value === 'number') {
return value;
} else {
return JSON.stringify(value);
}
Expand Down

0 comments on commit 68b1a81

Please sign in to comment.