@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.
Files changed (128) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/build/angular/index.d.ts +2 -0
  4. package/build/angular/index.js +2 -0
  5. package/build/angular/sqlite.service.d.ts +41 -0
  6. package/build/angular/sqlite.service.js +127 -0
  7. package/build/core/index.d.ts +10 -0
  8. package/build/core/index.js +6 -0
  9. package/build/core/native-database.d.ts +65 -0
  10. package/build/core/native-database.js +13 -0
  11. package/build/core/native-module.d.ts +25 -0
  12. package/build/core/native-module.js +17 -0
  13. package/build/core/native-session.d.ts +20 -0
  14. package/build/core/native-session.js +1 -0
  15. package/build/core/native-statement.d.ts +45 -0
  16. package/build/core/native-statement.js +6 -0
  17. package/build/core/param-utils.d.ts +28 -0
  18. package/build/core/param-utils.js +126 -0
  19. package/build/core/path-utils.d.ts +6 -0
  20. package/build/core/path-utils.js +29 -0
  21. package/build/core/query-utils.d.ts +17 -0
  22. package/build/core/query-utils.js +37 -0
  23. package/build/core/sqlite-database.d.ts +246 -0
  24. package/build/core/sqlite-database.js +427 -0
  25. package/build/core/sqlite-session.d.ts +84 -0
  26. package/build/core/sqlite-session.js +121 -0
  27. package/build/core/sqlite-statement.d.ts +96 -0
  28. package/build/core/sqlite-statement.js +321 -0
  29. package/build/core/sqlite-tagged-query.d.ts +73 -0
  30. package/build/core/sqlite-tagged-query.js +119 -0
  31. package/build/core/storage.d.ts +107 -0
  32. package/build/core/storage.js +382 -0
  33. package/build/core/types.d.ts +30 -0
  34. package/build/core/types.js +1 -0
  35. package/build/react/index.d.ts +2 -0
  36. package/build/react/index.js +2 -0
  37. package/build/react/sqlite-context.d.ts +25 -0
  38. package/build/react/sqlite-context.js +129 -0
  39. package/build/solid/index.d.ts +2 -0
  40. package/build/solid/index.js +2 -0
  41. package/build/solid/sqlite-context.d.ts +23 -0
  42. package/build/solid/sqlite-context.js +106 -0
  43. package/build/svelte/SQLiteProvider.svelte +88 -0
  44. package/build/svelte/SQLiteProvider.svelte.d.ts +13 -0
  45. package/build/svelte/index.d.ts +3 -0
  46. package/build/svelte/index.js +5 -0
  47. package/build/svelte/sqlite-context.d.ts +11 -0
  48. package/build/svelte/sqlite-context.js +23 -0
  49. package/build/vue/index.d.ts +2 -0
  50. package/build/vue/index.js +2 -0
  51. package/build/vue/sqlite-context.d.ts +21 -0
  52. package/build/vue/sqlite-context.js +69 -0
  53. package/build-ngc/angular/index.d.ts +2 -0
  54. package/build-ngc/angular/index.js +3 -0
  55. package/build-ngc/angular/index.js.map +1 -0
  56. package/build-ngc/angular/sqlite.service.d.ts +44 -0
  57. package/build-ngc/angular/sqlite.service.js +85 -0
  58. package/build-ngc/angular/sqlite.service.js.map +1 -0
  59. package/build-ngc/core/index.d.ts +10 -0
  60. package/build-ngc/core/index.js +7 -0
  61. package/build-ngc/core/index.js.map +1 -0
  62. package/build-ngc/core/native-database.d.ts +65 -0
  63. package/build-ngc/core/native-database.js +14 -0
  64. package/build-ngc/core/native-database.js.map +1 -0
  65. package/build-ngc/core/native-module.d.ts +25 -0
  66. package/build-ngc/core/native-module.js +18 -0
  67. package/build-ngc/core/native-module.js.map +1 -0
  68. package/build-ngc/core/native-session.d.ts +20 -0
  69. package/build-ngc/core/native-session.js +2 -0
  70. package/build-ngc/core/native-session.js.map +1 -0
  71. package/build-ngc/core/native-statement.d.ts +45 -0
  72. package/build-ngc/core/native-statement.js +7 -0
  73. package/build-ngc/core/native-statement.js.map +1 -0
  74. package/build-ngc/core/param-utils.d.ts +28 -0
  75. package/build-ngc/core/param-utils.js +127 -0
  76. package/build-ngc/core/param-utils.js.map +1 -0
  77. package/build-ngc/core/path-utils.d.ts +6 -0
  78. package/build-ngc/core/path-utils.js +30 -0
  79. package/build-ngc/core/path-utils.js.map +1 -0
  80. package/build-ngc/core/query-utils.d.ts +17 -0
  81. package/build-ngc/core/query-utils.js +38 -0
  82. package/build-ngc/core/query-utils.js.map +1 -0
  83. package/build-ngc/core/sqlite-database.d.ts +246 -0
  84. package/build-ngc/core/sqlite-database.js +428 -0
  85. package/build-ngc/core/sqlite-database.js.map +1 -0
  86. package/build-ngc/core/sqlite-session.d.ts +84 -0
  87. package/build-ngc/core/sqlite-session.js +122 -0
  88. package/build-ngc/core/sqlite-session.js.map +1 -0
  89. package/build-ngc/core/sqlite-statement.d.ts +96 -0
  90. package/build-ngc/core/sqlite-statement.js +322 -0
  91. package/build-ngc/core/sqlite-statement.js.map +1 -0
  92. package/build-ngc/core/sqlite-tagged-query.d.ts +73 -0
  93. package/build-ngc/core/sqlite-tagged-query.js +120 -0
  94. package/build-ngc/core/sqlite-tagged-query.js.map +1 -0
  95. package/build-ngc/core/storage.d.ts +107 -0
  96. package/build-ngc/core/storage.js +383 -0
  97. package/build-ngc/core/storage.js.map +1 -0
  98. package/build-ngc/core/types.d.ts +30 -0
  99. package/build-ngc/core/types.js +2 -0
  100. package/build-ngc/core/types.js.map +1 -0
  101. package/native-link.json +12 -0
  102. package/package.json +141 -0
  103. package/src/angular/index.ts +2 -0
  104. package/src/angular/sqlite.service.ts +114 -0
  105. package/src/core/index.ts +40 -0
  106. package/src/core/native-database.ts +118 -0
  107. package/src/core/native-module.ts +57 -0
  108. package/src/core/native-session.ts +64 -0
  109. package/src/core/native-statement.ts +85 -0
  110. package/src/core/param-utils.ts +163 -0
  111. package/src/core/path-utils.ts +38 -0
  112. package/src/core/query-utils.ts +45 -0
  113. package/src/core/sqlite-database.ts +676 -0
  114. package/src/core/sqlite-session.ts +165 -0
  115. package/src/core/sqlite-statement.ts +578 -0
  116. package/src/core/sqlite-tagged-query.ts +160 -0
  117. package/src/core/storage.ts +492 -0
  118. package/src/core/types.ts +33 -0
  119. package/src/react/index.ts +2 -0
  120. package/src/react/sqlite-context.tsx +244 -0
  121. package/src/solid/index.ts +2 -0
  122. package/src/solid/sqlite-context.ts +156 -0
  123. package/src/svelte/SQLiteProvider.svelte +88 -0
  124. package/src/svelte/index.ts +6 -0
  125. package/src/svelte/sqlite-context.ts +32 -0
  126. package/src/svelte/svelte-compile.test-helper.ts +135 -0
  127. package/src/vue/index.ts +2 -0
  128. 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
+ }