@symbiote-native/sqlite 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +283 -0
- package/build/angular/index.d.ts +2 -0
- package/build/angular/index.js +2 -0
- package/build/angular/sqlite.service.d.ts +41 -0
- package/build/angular/sqlite.service.js +127 -0
- package/build/core/index.d.ts +10 -0
- package/build/core/index.js +6 -0
- package/build/core/native-database.d.ts +65 -0
- package/build/core/native-database.js +13 -0
- package/build/core/native-module.d.ts +25 -0
- package/build/core/native-module.js +17 -0
- package/build/core/native-session.d.ts +20 -0
- package/build/core/native-session.js +1 -0
- package/build/core/native-statement.d.ts +45 -0
- package/build/core/native-statement.js +6 -0
- package/build/core/param-utils.d.ts +28 -0
- package/build/core/param-utils.js +126 -0
- package/build/core/path-utils.d.ts +6 -0
- package/build/core/path-utils.js +29 -0
- package/build/core/query-utils.d.ts +17 -0
- package/build/core/query-utils.js +37 -0
- package/build/core/sqlite-database.d.ts +246 -0
- package/build/core/sqlite-database.js +427 -0
- package/build/core/sqlite-session.d.ts +84 -0
- package/build/core/sqlite-session.js +121 -0
- package/build/core/sqlite-statement.d.ts +96 -0
- package/build/core/sqlite-statement.js +321 -0
- package/build/core/sqlite-tagged-query.d.ts +73 -0
- package/build/core/sqlite-tagged-query.js +119 -0
- package/build/core/storage.d.ts +107 -0
- package/build/core/storage.js +382 -0
- package/build/core/types.d.ts +30 -0
- package/build/core/types.js +1 -0
- package/build/react/index.d.ts +2 -0
- package/build/react/index.js +2 -0
- package/build/react/sqlite-context.d.ts +25 -0
- package/build/react/sqlite-context.js +129 -0
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +2 -0
- package/build/solid/sqlite-context.d.ts +23 -0
- package/build/solid/sqlite-context.js +106 -0
- package/build/svelte/SQLiteProvider.svelte +88 -0
- package/build/svelte/SQLiteProvider.svelte.d.ts +13 -0
- package/build/svelte/index.d.ts +3 -0
- package/build/svelte/index.js +5 -0
- package/build/svelte/sqlite-context.d.ts +11 -0
- package/build/svelte/sqlite-context.js +23 -0
- package/build/vue/index.d.ts +2 -0
- package/build/vue/index.js +2 -0
- package/build/vue/sqlite-context.d.ts +21 -0
- package/build/vue/sqlite-context.js +69 -0
- package/build-ngc/angular/index.d.ts +2 -0
- package/build-ngc/angular/index.js +3 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/angular/sqlite.service.d.ts +44 -0
- package/build-ngc/angular/sqlite.service.js +85 -0
- package/build-ngc/angular/sqlite.service.js.map +1 -0
- package/build-ngc/core/index.d.ts +10 -0
- package/build-ngc/core/index.js +7 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/native-database.d.ts +65 -0
- package/build-ngc/core/native-database.js +14 -0
- package/build-ngc/core/native-database.js.map +1 -0
- package/build-ngc/core/native-module.d.ts +25 -0
- package/build-ngc/core/native-module.js +18 -0
- package/build-ngc/core/native-module.js.map +1 -0
- package/build-ngc/core/native-session.d.ts +20 -0
- package/build-ngc/core/native-session.js +2 -0
- package/build-ngc/core/native-session.js.map +1 -0
- package/build-ngc/core/native-statement.d.ts +45 -0
- package/build-ngc/core/native-statement.js +7 -0
- package/build-ngc/core/native-statement.js.map +1 -0
- package/build-ngc/core/param-utils.d.ts +28 -0
- package/build-ngc/core/param-utils.js +127 -0
- package/build-ngc/core/param-utils.js.map +1 -0
- package/build-ngc/core/path-utils.d.ts +6 -0
- package/build-ngc/core/path-utils.js +30 -0
- package/build-ngc/core/path-utils.js.map +1 -0
- package/build-ngc/core/query-utils.d.ts +17 -0
- package/build-ngc/core/query-utils.js +38 -0
- package/build-ngc/core/query-utils.js.map +1 -0
- package/build-ngc/core/sqlite-database.d.ts +246 -0
- package/build-ngc/core/sqlite-database.js +428 -0
- package/build-ngc/core/sqlite-database.js.map +1 -0
- package/build-ngc/core/sqlite-session.d.ts +84 -0
- package/build-ngc/core/sqlite-session.js +122 -0
- package/build-ngc/core/sqlite-session.js.map +1 -0
- package/build-ngc/core/sqlite-statement.d.ts +96 -0
- package/build-ngc/core/sqlite-statement.js +322 -0
- package/build-ngc/core/sqlite-statement.js.map +1 -0
- package/build-ngc/core/sqlite-tagged-query.d.ts +73 -0
- package/build-ngc/core/sqlite-tagged-query.js +120 -0
- package/build-ngc/core/sqlite-tagged-query.js.map +1 -0
- package/build-ngc/core/storage.d.ts +107 -0
- package/build-ngc/core/storage.js +383 -0
- package/build-ngc/core/storage.js.map +1 -0
- package/build-ngc/core/types.d.ts +30 -0
- package/build-ngc/core/types.js +2 -0
- package/build-ngc/core/types.js.map +1 -0
- package/native-link.json +12 -0
- package/package.json +141 -0
- package/src/angular/index.ts +2 -0
- package/src/angular/sqlite.service.ts +114 -0
- package/src/core/index.ts +40 -0
- package/src/core/native-database.ts +118 -0
- package/src/core/native-module.ts +57 -0
- package/src/core/native-session.ts +64 -0
- package/src/core/native-statement.ts +85 -0
- package/src/core/param-utils.ts +163 -0
- package/src/core/path-utils.ts +38 -0
- package/src/core/query-utils.ts +45 -0
- package/src/core/sqlite-database.ts +676 -0
- package/src/core/sqlite-session.ts +165 -0
- package/src/core/sqlite-statement.ts +578 -0
- package/src/core/sqlite-tagged-query.ts +160 -0
- package/src/core/storage.ts +492 -0
- package/src/core/types.ts +33 -0
- package/src/react/index.ts +2 -0
- package/src/react/sqlite-context.tsx +244 -0
- package/src/solid/index.ts +2 -0
- package/src/solid/sqlite-context.ts +156 -0
- package/src/svelte/SQLiteProvider.svelte +88 -0
- package/src/svelte/index.ts +6 -0
- package/src/svelte/sqlite-context.ts +32 -0
- package/src/svelte/svelte-compile.test-helper.ts +135 -0
- package/src/vue/index.ts +2 -0
- package/src/vue/sqlite-context.ts +105 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Vue twin of upstream's `SQLiteProvider`/`useSQLiteContext`
|
|
2
|
+
// (.vendors/expo @ origin/sdk-57, packages/expo-sqlite/src/hooks.tsx). React's mechanics
|
|
3
|
+
// (useEffect/React.use/Suspense) don't transfer; this reproduces the OBSERVABLE contract with
|
|
4
|
+
// Vue's own provide/inject, following packages/navigation/src/vue/navigation-context.ts's shape
|
|
5
|
+
// (a symbol-keyed InjectionKey, a `require*` getter that throws with a hook-scoped message).
|
|
6
|
+
//
|
|
7
|
+
// Deliberately excluded, mirroring core's own `IOpenDatabaseOptions` (see core/types.ts):
|
|
8
|
+
// `assetSource` — needs `expo-asset`, out of scope for this package.
|
|
9
|
+
// Deliberately excluded, this pass only: Suspense integration (`useSuspense`). Vue has its own
|
|
10
|
+
// `<Suspense>` + async `setup()` idiom instead of React's `use()`; wiring this Provider into it is
|
|
11
|
+
// a separate, later decision, not a straight port of React's `useSuspense` flag.
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
defineComponent,
|
|
15
|
+
inject,
|
|
16
|
+
onUnmounted,
|
|
17
|
+
provide,
|
|
18
|
+
shallowRef,
|
|
19
|
+
watch,
|
|
20
|
+
} from '@vue/runtime-core';
|
|
21
|
+
import type { InjectionKey, ShallowRef } from '@vue/runtime-core';
|
|
22
|
+
import { openDatabaseAsync } from '../core';
|
|
23
|
+
import type { ISQLiteOpenOptions, SQLiteDatabase } from '../core';
|
|
24
|
+
|
|
25
|
+
export type ISQLiteProviderProps = {
|
|
26
|
+
databaseName: string;
|
|
27
|
+
directory?: string;
|
|
28
|
+
options?: ISQLiteOpenOptions;
|
|
29
|
+
onInit?: (db: SQLiteDatabase) => Promise<void> | void;
|
|
30
|
+
onError?: (error: Error) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const SQLITE_CONTEXT_KEY: InjectionKey<ShallowRef<SQLiteDatabase | null>> =
|
|
34
|
+
Symbol('sqlite-context');
|
|
35
|
+
|
|
36
|
+
function toError(reason: unknown): Error {
|
|
37
|
+
return reason instanceof Error ? reason : new Error(String(reason));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Opens `databaseName` (re-opening whenever `databaseName`/`directory`/`options`/`onInit`
|
|
42
|
+
* change) and provides the resulting `SQLiteDatabase` to its default-slot children via
|
|
43
|
+
* `useSQLiteContext`. Renders nothing while opening or on failure with no `onError`; on failure
|
|
44
|
+
* with `onError`, calls it and renders nothing. Closes the database before re-opening and on
|
|
45
|
+
* unmount.
|
|
46
|
+
*/
|
|
47
|
+
export const SQLiteProvider = defineComponent<ISQLiteProviderProps>(
|
|
48
|
+
(props, { slots }) => {
|
|
49
|
+
const database = shallowRef<SQLiteDatabase | null>(null);
|
|
50
|
+
provide(SQLITE_CONTEXT_KEY, database);
|
|
51
|
+
|
|
52
|
+
// Async watch callback: Vue's `callWithAsyncErrorHandling` attaches a `.catch` to the
|
|
53
|
+
// returned promise and routes a rejection through `app.config.errorHandler`
|
|
54
|
+
// (`handleError`) — the same channel `mount()` wires to the engine's shared reporter (see
|
|
55
|
+
// packages/navigation's composables.test.ts). So a thrown `Error` here IS the Vue-idiomatic
|
|
56
|
+
// "rethrow", not a swallowed unhandled rejection.
|
|
57
|
+
watch(
|
|
58
|
+
() => [props.databaseName, props.directory, props.options, props.onInit],
|
|
59
|
+
async () => {
|
|
60
|
+
const previous = database.value;
|
|
61
|
+
database.value = null;
|
|
62
|
+
await previous?.closeAsync();
|
|
63
|
+
|
|
64
|
+
const { databaseName, directory, options, onInit, onError } = props;
|
|
65
|
+
try {
|
|
66
|
+
database.value = await openDatabaseAsync(
|
|
67
|
+
databaseName,
|
|
68
|
+
{ ...options, onInit },
|
|
69
|
+
directory,
|
|
70
|
+
);
|
|
71
|
+
} catch (reason) {
|
|
72
|
+
const error = toError(reason);
|
|
73
|
+
if (onError !== undefined) {
|
|
74
|
+
onError(error);
|
|
75
|
+
} else {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{ immediate: true },
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
onUnmounted(() => {
|
|
84
|
+
void database.value?.closeAsync();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return () => (database.value !== null ? slots.default?.() : null);
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'SQLiteProvider',
|
|
91
|
+
props: ['databaseName', 'directory', 'options', 'onInit', 'onError'],
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Reads the `SQLiteDatabase` opened by the nearest ancestor `<SQLiteProvider>`. Throws when
|
|
97
|
+
* called outside one.
|
|
98
|
+
*/
|
|
99
|
+
export function useSQLiteContext(): SQLiteDatabase {
|
|
100
|
+
const context = inject(SQLITE_CONTEXT_KEY, undefined);
|
|
101
|
+
if (context === undefined || context.value === null) {
|
|
102
|
+
throw new Error('useSQLiteContext must be used within a <SQLiteProvider>');
|
|
103
|
+
}
|
|
104
|
+
return context.value;
|
|
105
|
+
}
|