Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- [@edusperoni/nativescript-mqtt](packages/nativescript-mqtt/README.md)
- [nativescript-ripple](packages/nativescript-ripple/README.md)
- [@edusperoni/nativescript-sms-inbox](packages/nativescript-sms-inbox/README.md)
- [@edusperoni/nativescript-sqlite](packages/nativescript-sqlite/README.md)
- [@edusperoni/nativescript-supabase](packages/nativescript-supabase/README.md)

# How to use?
Expand Down
5 changes: 3 additions & 2 deletions apps/demo-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"@edusperoni/nativescript-mqtt": "file:../../packages/nativescript-mqtt",
"nativescript-ripple": "file:../../packages/nativescript-ripple",
"@valor/nativescript-websockets": "^1.0.3",
"@edusperoni/nativescript-supabase": "file:../../dist/packages/nativescript-supabase"
"@edusperoni/nativescript-supabase": "file:../../dist/packages/nativescript-supabase",
"@edusperoni/nativescript-sqlite": "file:../../dist/packages/nativescript-sqlite"
},
"devDependencies": {
"@nativescript/android": "~8.9.0",
"@nativescript/android": "~9.1.1",
"@nativescript/ios": "~8.9.0"
}
}
1 change: 1 addition & 0 deletions apps/demo-angular/src/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const routes: Routes = [
{ path: 'nativescript-mqtt', loadChildren: () => import('./plugin-demos/nativescript-mqtt.module').then((m) => m.NativescriptMqttModule) },
{ path: 'nativescript-ripple', loadChildren: () => import('./plugin-demos/nativescript-ripple.module').then((m) => m.NativescriptRippleModule) },
{ path: 'nativescript-sms-inbox', loadChildren: () => import('./plugin-demos/nativescript-sms-inbox.module').then((m) => m.NativescriptSmsInboxModule) },
{ path: 'nativescript-sqlite', loadChildren: () => import('./plugin-demos/nativescript-sqlite.module').then((m) => m.NativescriptSqliteModule) },
{ path: 'nativescript-supabase', loadChildren: () => import('./plugin-demos/nativescript-supabase.module').then((m) => m.NativescriptSupabaseModule) },
];

Expand Down
3 changes: 3 additions & 0 deletions apps/demo-angular/src/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class HomeComponent {
{
name: 'nativescript-sms-inbox',
},
{
name: 'nativescript-sqlite',
},
{
name: 'nativescript-supabase',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<ActionBar title="nativescript-sqlite" class="action-bar"> </ActionBar>
<StackLayout class="p-20">
<!-- Rotating square — stays smooth as long as the UI thread is free -->
<StackLayout class="h-full" orientation="vertical">
<StackLayout orientation="horizontal" horizontalAlignment="center" class="m-b-10 p-10">
<StackLayout #spinner width="60" height="60" backgroundColor="#3d5afe" borderRadius="8" class="m-r-10 m-10"></StackLayout>
<Label text="UI thread free ✓" verticalAlignment="center" fontSize="14" color="#3d5afe"></Label>
</StackLayout>
<ScrollView>
<StackLayout>
<Label text="─── Tests ───" class="h3 text-center m-b-10"></Label>
<Button text="Run All Tests" (tap)="demoShared.testAll()" class="btn btn-primary m-b-5"></Button>
<Button text="CRUD" (tap)="demoShared.testCRUD()" class="btn btn-outline m-b-5"></Button>
<Button text="Data Types (NULL/INT/REAL/TEXT/BLOB)" (tap)="demoShared.testDataTypes()" class="btn btn-outline m-b-5"></Button>
<Button text="Parameter Binding (positional &amp; named)" (tap)="demoShared.testParams()" class="btn btn-outline m-b-5"></Button>
<Button text="selectArray / getArray" (tap)="demoShared.testSelectArray()" class="btn btn-outline m-b-5"></Button>
<Button text="Transactions &amp; Savepoints" (tap)="demoShared.testTransactions()" class="btn btn-outline m-b-5"></Button>
<Button text="Prepared Statements" (tap)="demoShared.testPreparedStatements()" class="btn btn-outline m-b-5"></Button>
<Button text="Sync API" (tap)="demoShared.testSyncAPI()" class="btn btn-outline m-b-5"></Button>
<Button text="Error Handling" (tap)="demoShared.testErrorHandling()" class="btn btn-outline m-b-5"></Button>
<Button text="getRuntimeInfo" (tap)="demoShared.testRuntimeInfo()" class="btn btn-outline m-b-5"></Button>
<Button text="In-Memory Database" (tap)="demoShared.testInMemoryDB()" class="btn btn-outline m-b-5"></Button>
<Button text="Low-Level Transaction API" (tap)="demoShared.testLowLevelTransactions()" class="btn btn-outline m-b-5"></Button>
<Button text="SQLCipher (Android optional dep)" (tap)="demoShared.testSQLCipher()" class="btn btn-outline m-b-5"></Button>

<Label text="─── Benchmarks ───" class="h3 text-center m-t-20 m-b-10"></Label>
<Button text="Run Full Benchmark Suite" (tap)="demoShared.benchmarkAll()" class="btn btn-primary m-b-5"></Button>
<Button text="Run Quick Benchmark Suite (smoke)" (tap)="demoShared.benchmarkQuick()" class="btn btn-outline m-b-5"></Button>
</StackLayout>
</ScrollView>
</StackLayout>
</StackLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Component, ElementRef, NgZone, ViewChild, OnInit, OnDestroy } from '@angular/core';
import { DemoSharedNativescriptSqlite } from '@demo/shared';
import {} from '@edusperoni/nativescript-sqlite';
import { StackLayout } from '@nativescript/core';

@Component({
selector: 'demo-nativescript-sqlite',
standalone: false,
templateUrl: 'nativescript-sqlite.component.html',
})
export class NativescriptSqliteComponent implements OnInit, OnDestroy {
demoShared: DemoSharedNativescriptSqlite;
@ViewChild('spinner', { static: false }) spinnerRef: ElementRef;

private _spinning = true;

constructor(private _ngZone: NgZone) {}

ngOnInit() {
this.demoShared = new DemoSharedNativescriptSqlite();
}

ngAfterViewInit() {
this._spin();
}

ngOnDestroy() {
this._spinning = false;
}

private _spin() {
if (!this._spinning) return;
const view: StackLayout = this.spinnerRef?.nativeElement;
if (!view) return;
let last: number | null = null;
const step = (ts: number) => {
if (!this._spinning) return;
if (last !== null) {
const delta = ts - last;
view.rotate = (view.rotate + (delta / 800) * 360) % 360;
}
last = ts;
requestAnimationFrame(step);
};
requestAnimationFrame(step);
}
}
10 changes: 10 additions & 0 deletions apps/demo-angular/src/plugin-demos/nativescript-sqlite.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
import { NativescriptSqliteComponent } from './nativescript-sqlite.component';

@NgModule({
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: NativescriptSqliteComponent }])],
declarations: [NativescriptSqliteComponent],
schemas: [NO_ERRORS_SCHEMA],
})
export class NativescriptSqliteModule {}
3 changes: 2 additions & 1 deletion apps/demo-angular/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"nativescript-ripple/angular": ["packages/nativescript-ripple/angular/index.ts"],
"@edusperoni/nativescript-sms-inbox": ["packages/nativescript-sms-inbox/index.d.ts"],
"~/*": ["apps/demo-angular/src/*"],
"@edusperoni/nativescript-supabase": ["../../packages/nativescript-supabase/index.ts"]
"@edusperoni/nativescript-supabase": ["../../packages/nativescript-supabase/index.ts"],
"@edusperoni/nativescript-sqlite": ["packages/nativescript-sqlite/index.android.ts"]
}
},
"files": ["./references.d.ts", "./src/main.ts", "./src/polyfills.ts"],
Expand Down
5 changes: 3 additions & 2 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"@nativescript/core": "file:../../node_modules/@nativescript/core",
"@nativescript/unit-test-runner": "^3.0.2",
"@valor/nativescript-websockets": "^1.0.3",
"@edusperoni/nativescript-supabase": "file:../../packages/nativescript-supabase"
"@edusperoni/nativescript-supabase": "file:../../packages/nativescript-supabase",
"@edusperoni/nativescript-sqlite": "file:../../packages/nativescript-sqlite"
},
"devDependencies": {
"@nativescript/android": "~8.9.0",
"@nativescript/android": "~9.1.1",
"@nativescript/ios": "~8.9.0"
}
}
82 changes: 82 additions & 0 deletions apps/demo/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,85 @@
import { Application } from '@nativescript/core';
import { runBenchmarks, RunBenchmarksOptions, runCorrectnessTests, RunCorrectnessTestsOptions, runEncryptedWalTest, RunEncryptedWalOptions } from '@demo/shared';

const BENCH_START_DELAY_MS = 1500;
const BENCH_LAUNCH_FALLBACK_MS = 6000;

type BenchRequest = { mode: 'full' | 'quick'; options: RunBenchmarksOptions } | { mode: 'test'; options: RunCorrectnessTestsOptions } | { mode: 'encwal'; options: RunEncryptedWalOptions };

/** The three values each platform carries, before they are checked. */
interface BenchArgs {
mode: string | null;
label?: string;
filter?: string;
}

function readAndroidArgs(): BenchArgs | null {
const androidApp = Application.android;
const activity = androidApp.foregroundActivity || androidApp.startActivity;
const intent = activity && activity.getIntent();
if (!intent) return null;
return {
mode: intent.getStringExtra('nscbench'),
label: intent.getStringExtra('nscbenchLabel') || undefined,
filter: intent.getStringExtra('nscbenchFilter') || undefined,
};
}

function readIOSArgs(): BenchArgs | null {
if (typeof NSProcessInfo === 'undefined') return null;
const argv = NSProcessInfo.processInfo.arguments;
const flag = (name: string): string | undefined => {
for (let i = 0; i + 1 < argv.count; i++) {
if (argv.objectAtIndex(i) === name) return argv.objectAtIndex(i + 1) || undefined;
}
return undefined;
};
return {
mode: flag('-nscbench') ?? null,
label: flag('-nscbenchLabel'),
filter: flag('-nscbenchFilter'),
};
}

function readBenchRequest(): BenchRequest | null {
try {
const args = Application.android ? readAndroidArgs() : readIOSArgs();
if (!args) return null;
const mode = args.mode;
if (mode !== 'full' && mode !== 'quick' && mode !== 'test' && mode !== 'encwal') return null;
if (mode === 'test' || mode === 'encwal') return { mode, options: { label: args.label } };
return {
mode,
options: {
quick: mode === 'quick',
label: args.label,
filter: args.filter,
},
};
} catch (err) {
return null;
}
}

let benchScheduled = false;
function scheduleBench() {
if (benchScheduled) return;
benchScheduled = true;
setTimeout(() => {
const request = readBenchRequest();
if (!request) return;
let run: Promise<unknown>;
if (request.mode === 'test') run = runCorrectnessTests(request.options);
else if (request.mode === 'encwal') run = runEncryptedWalTest(request.options);
else run = runBenchmarks(request.options);
run.catch(() => {
/* the runner already logged its [NSCBENCH_ERROR]/[NSCTEST_ERROR]/[NSCENCWAL_ERROR] line */
});
}, BENCH_START_DELAY_MS);
}

Application.on(Application.displayedEvent, scheduleBench);
// Not every root view emits `displayed`; without this fallback an adb-triggered run could never start.
Application.on(Application.launchEvent, () => setTimeout(scheduleBench, BENCH_LAUNCH_FALLBACK_MS));

Application.run({ moduleName: 'app-root' });
1 change: 1 addition & 0 deletions apps/demo/src/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Button text="nativescript-mqtt" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="nativescript-ripple" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="nativescript-supabase" tap="{{ viewDemo }}" class="btn btn-primary rounded view-demo"/>
<Button text="nativescript-sqlite" tap="{{ viewDemo }}" class="btn btn-primary rounded view-demo"/>
</StackLayout>
</ScrollView>
</StackLayout>
Expand Down
10 changes: 10 additions & 0 deletions apps/demo/src/plugin-demos/nativescript-sqlite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Observable, EventData, Page } from '@nativescript/core';
import { DemoSharedNativescriptSqlite } from '@demo/shared';
import {} from '@edusperoni/nativescript-sqlite';

export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new DemoModel();
}

export class DemoModel extends DemoSharedNativescriptSqlite {}
30 changes: 30 additions & 0 deletions apps/demo/src/plugin-demos/nativescript-sqlite.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<Page.actionBar>
<ActionBar title="nativescript-sqlite" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>
<StackLayout class="p-20">
<ScrollView class="h-full">
<StackLayout>
<Label text="─── Tests ───" class="h3 text-center m-b-10"/>
<Button text="Run All Tests" tap="{{ testAll }}" class="btn btn-primary m-b-5"/>
<Button text="CRUD" tap="{{ testCRUD }}" class="btn btn-outline m-b-5"/>
<Button text="Data Types (NULL/INT/REAL/TEXT/BLOB)" tap="{{ testDataTypes }}" class="btn btn-outline m-b-5"/>
<Button text="Parameter Binding (positional &amp; named)" tap="{{ testParams }}" class="btn btn-outline m-b-5"/>
<Button text="selectArray / getArray" tap="{{ testSelectArray }}" class="btn btn-outline m-b-5"/>
<Button text="Transactions &amp; Savepoints" tap="{{ testTransactions }}" class="btn btn-outline m-b-5"/>
<Button text="Prepared Statements" tap="{{ testPreparedStatements }}" class="btn btn-outline m-b-5"/>
<Button text="Sync API" tap="{{ testSyncAPI }}" class="btn btn-outline m-b-5"/>
<Button text="Error Handling" tap="{{ testErrorHandling }}" class="btn btn-outline m-b-5"/>
<Button text="getRuntimeInfo" tap="{{ testRuntimeInfo }}" class="btn btn-outline m-b-5"/>
<Button text="In-Memory Database" tap="{{ testInMemoryDB }}" class="btn btn-outline m-b-5"/>
<Button text="Low-Level Transaction API" tap="{{ testLowLevelTransactions }}" class="btn btn-outline m-b-5"/>
<Button text="SQLCipher (Android optional dep)" tap="{{ testSQLCipher }}" class="btn btn-outline m-b-5"/>

<Label text="─── Benchmarks ───" class="h3 text-center m-t-20 m-b-10"/>
<Button text="Run Full Benchmark Suite" tap="{{ benchmarkAll }}" class="btn btn-primary m-b-5"/>
<Button text="Run Quick Benchmark Suite (smoke)" tap="{{ benchmarkQuick }}" class="btn btn-outline m-b-5"/>
</StackLayout>
</ScrollView>
</StackLayout>
</Page>
3 changes: 2 additions & 1 deletion apps/demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"@edusperoni/nativescript-sms-inbox": ["../../packages/nativescript-sms-inbox/index.d.ts"],
"@demo/shared": ["../../tools/demo/index.ts"],
"nativescript-ripple/angular": ["../../packages/nativescript-ripple/angular/index.ts"],
"@edusperoni/nativescript-supabase": ["../../packages/nativescript-supabase/index.ts"]
"@edusperoni/nativescript-supabase": ["../../packages/nativescript-supabase/index.ts"],
"@edusperoni/nativescript-sqlite": ["../../packages/nativescript-sqlite/index.d.ts"]
}
},
"exclude": ["**/*.spec.ts"]
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"pluginsConfig": {
"@nrwl/js": {
"@nx/js": {
"analyzeSourceFiles": true
}
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"@ngtools/webpack": "^19.0.0",
"@typescript-eslint/eslint-plugin": "8.56.1",
"@typescript-eslint/parser": "8.56.1",
"eslint": "8.2.0",
"drizzle-orm": "^0.45.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.3.0",
"husky": "~9.0.0",
"karma": "6.3.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/nativescript-mqtt/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sourceRoot": "packages/nativescript-mqtt",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"executor": "@nx/js:tsc",
"options": {
"outputPath": "dist/packages/nativescript-mqtt",
"tsConfig": "packages/nativescript-mqtt/tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/nativescript-ripple/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sourceRoot": "packages/nativescript-ripple",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"executor": "@nx/js:tsc",
"options": {
"outputPath": "dist/packages/nativescript-ripple",
"tsConfig": "packages/nativescript-ripple/tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/nativescript-sms-inbox/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sourceRoot": "packages/nativescript-sms-inbox",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"executor": "@nx/js:tsc",
"options": {
"outputPath": "dist/packages/nativescript-sms-inbox",
"tsConfig": "packages/nativescript-sms-inbox/tsconfig.json",
Expand Down
18 changes: 18 additions & 0 deletions packages/nativescript-sqlite/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "node_modules/**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Loading
Loading