Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dwn-sdk-js to v0.2.6 #9

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
method: string | null;
schema: string | null;
dataCid: string | null;
dataSize: string | null;
dataSize: number | null;

Check warning on line 20 in src/database.ts

View check run for this annotation

Codecov / codecov/patch

src/database.ts#L20

Added line #L20 was not covered by tests
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