Skip to content

Commit

Permalink
use standard JS errors. Assert not supported in React Native
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Jan 30, 2024
1 parent f4cd47a commit b8f7cf6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { CrudEntry } from './sync/bucket/CrudEntry';
import { mutexRunExclusive } from '../utils/mutex';
import { BaseObserver } from '../utils/BaseObserver';
import { EventIterator } from 'event-iterator';
import { AssertionError } from 'assert';
import { quoteIdentifier } from '../utils/strings';

export interface DisconnectAndClearOptions {
Expand Down Expand Up @@ -165,7 +164,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB

async updateSchema(schema: Schema) {
if (this.abortController) {
throw new AssertionError({ message: 'Cannot update schema while connected' });
throw new Error('Cannot update schema while connected');
}

schema.validate();
Expand Down
28 changes: 9 additions & 19 deletions packages/powersync-sdk-common/src/db/schema/Table.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash';
import { Column } from '../Column';
import type { Index } from './Index';
import { AssertionError } from 'assert';

export interface TableOptions {
/**
Expand Down Expand Up @@ -83,25 +82,21 @@ export class Table {

validate() {
if (InvalidSQLCharacters.test(this.name)) {
throw new AssertionError({ message: `Invalid characters in table name: ${this.name}` });
throw new Error(`Invalid characters in table name: ${this.name}`);
} else if (this.viewNameOverride && InvalidSQLCharacters.test(this.viewNameOverride!)) {
throw new AssertionError({
message: `
Invalid characters in view name: ${this.viewNameOverride}`
});
throw new Error(`
Invalid characters in view name: ${this.viewNameOverride}`);
}

const columnNames = new Set<string>();
columnNames.add('id');
for (const column in this.columns) {
if (column == 'id') {
throw new AssertionError({
message: `${this.name}: id column is automatically added, custom id columns are not supported`
});
throw new Error(`${this.name}: id column is automatically added, custom id columns are not supported`);
} else if (columnNames.has(column)) {
throw new AssertionError({ message: `Duplicate column ${column}` });
throw new Error(`Duplicate column ${column}`);
} else if (InvalidSQLCharacters.test(column)) {
throw new AssertionError({ message: `Invalid characters in column name: $name.${column}` });
throw new Error(`Invalid characters in column name: $name.${column}`);
}
columnNames.add(column);
}
Expand All @@ -110,19 +105,14 @@ export class Table {

for (const index of this.indexes) {
if (indexNames.has(index.name)) {
throw new AssertionError({ message: `Duplicate index $name.${index}` });
throw new Error(`Duplicate index $name.${index}`);
} else if (InvalidSQLCharacters.test(index.name)) {
throw new AssertionError({
message: `
Invalid characters in index name: $name.${index}`
});
throw new Error(`Invalid characters in index name: $name.${index}`);
}

for (const column of index.columns) {
if (!columnNames.has(column.name)) {
throw new AssertionError({
message: `Column $name.${column.name} not found for index ${index.name}`
});
throw new Error(`Column $name.${column.name} not found for index ${index.name}`);
}
}

Expand Down

0 comments on commit b8f7cf6

Please sign in to comment.