@quereus/quereus 0.6.2 → 0.6.4

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 (89) hide show
  1. package/README.md +1 -1
  2. package/dist/src/index.d.ts +4 -6
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/index.js +2 -4
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/runtime/emit/schema-declarative.js +1 -1
  7. package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
  8. package/dist/src/schema/schema-hasher.d.ts +3 -3
  9. package/dist/src/schema/schema-hasher.d.ts.map +1 -1
  10. package/dist/src/schema/schema-hasher.js +9 -27
  11. package/dist/src/schema/schema-hasher.js.map +1 -1
  12. package/dist/src/util/hash.d.ts +19 -0
  13. package/dist/src/util/hash.d.ts.map +1 -0
  14. package/dist/src/util/hash.js +76 -0
  15. package/dist/src/util/hash.js.map +1 -0
  16. package/dist/src/util/plugin-helper.d.ts +45 -0
  17. package/dist/src/util/plugin-helper.d.ts.map +1 -0
  18. package/dist/src/util/plugin-helper.js +85 -0
  19. package/dist/src/util/plugin-helper.js.map +1 -0
  20. package/package.json +4 -2
  21. package/src/index.ts +10 -16
  22. package/src/planner/building/delete.ts +214 -214
  23. package/src/planner/building/insert.ts +428 -428
  24. package/src/planner/building/update.ts +319 -319
  25. package/src/runtime/emit/schema-declarative.ts +1 -1
  26. package/src/schema/schema-hasher.ts +9 -27
  27. package/src/util/ast-stringify.ts +864 -864
  28. package/src/util/hash.ts +90 -0
  29. package/src/util/plugin-helper.ts +110 -0
  30. package/src/vtab/memory/table.ts +256 -256
  31. package/src/vtab/table.ts +162 -162
  32. package/dist/src/config/loader.d.ts +0 -41
  33. package/dist/src/config/loader.d.ts.map +0 -1
  34. package/dist/src/config/loader.js +0 -102
  35. package/dist/src/config/loader.js.map +0 -1
  36. package/dist/src/planner/nodes/physical-access-nodes.d.ts +0 -83
  37. package/dist/src/planner/nodes/physical-access-nodes.d.ts.map +0 -1
  38. package/dist/src/planner/nodes/physical-access-nodes.js +0 -226
  39. package/dist/src/planner/nodes/physical-access-nodes.js.map +0 -1
  40. package/dist/src/planner/nodes/scan.d.ts +0 -27
  41. package/dist/src/planner/nodes/scan.d.ts.map +0 -1
  42. package/dist/src/planner/nodes/scan.js +0 -78
  43. package/dist/src/planner/nodes/scan.js.map +0 -1
  44. package/dist/src/planner/nodes/update-executor-node.d.ts +0 -24
  45. package/dist/src/planner/nodes/update-executor-node.d.ts.map +0 -1
  46. package/dist/src/planner/nodes/update-executor-node.js +0 -57
  47. package/dist/src/planner/nodes/update-executor-node.js.map +0 -1
  48. package/dist/src/planner/physical-utils.d.ts +0 -36
  49. package/dist/src/planner/physical-utils.d.ts.map +0 -1
  50. package/dist/src/planner/physical-utils.js +0 -122
  51. package/dist/src/planner/physical-utils.js.map +0 -1
  52. package/dist/src/planner/rules/physical/rule-filter-optimization.d.ts +0 -11
  53. package/dist/src/planner/rules/physical/rule-filter-optimization.d.ts.map +0 -1
  54. package/dist/src/planner/rules/physical/rule-filter-optimization.js +0 -49
  55. package/dist/src/planner/rules/physical/rule-filter-optimization.js.map +0 -1
  56. package/dist/src/planner/rules/physical/rule-mark-physical.d.ts +0 -11
  57. package/dist/src/planner/rules/physical/rule-mark-physical.d.ts.map +0 -1
  58. package/dist/src/planner/rules/physical/rule-mark-physical.js +0 -29
  59. package/dist/src/planner/rules/physical/rule-mark-physical.js.map +0 -1
  60. package/dist/src/planner/rules/physical/rule-project-optimization.d.ts +0 -11
  61. package/dist/src/planner/rules/physical/rule-project-optimization.d.ts.map +0 -1
  62. package/dist/src/planner/rules/physical/rule-project-optimization.js +0 -44
  63. package/dist/src/planner/rules/physical/rule-project-optimization.js.map +0 -1
  64. package/dist/src/planner/rules/physical/rule-sort-optimization.d.ts +0 -11
  65. package/dist/src/planner/rules/physical/rule-sort-optimization.d.ts.map +0 -1
  66. package/dist/src/planner/rules/physical/rule-sort-optimization.js +0 -53
  67. package/dist/src/planner/rules/physical/rule-sort-optimization.js.map +0 -1
  68. package/dist/src/planner/rules/rewrite/rule-constant-folding.d.ts +0 -11
  69. package/dist/src/planner/rules/rewrite/rule-constant-folding.d.ts.map +0 -1
  70. package/dist/src/planner/rules/rewrite/rule-constant-folding.js +0 -59
  71. package/dist/src/planner/rules/rewrite/rule-constant-folding.js.map +0 -1
  72. package/dist/src/planner/util/deferred-constraint.d.ts +0 -14
  73. package/dist/src/planner/util/deferred-constraint.d.ts.map +0 -1
  74. package/dist/src/planner/util/deferred-constraint.js +0 -85
  75. package/dist/src/planner/util/deferred-constraint.js.map +0 -1
  76. package/dist/src/runtime/emit/table-reference.d.ts +0 -5
  77. package/dist/src/runtime/emit/table-reference.d.ts.map +0 -1
  78. package/dist/src/runtime/emit/table-reference.js +0 -67
  79. package/dist/src/runtime/emit/table-reference.js.map +0 -1
  80. package/dist/src/runtime/emit/update-executor.d.ts +0 -5
  81. package/dist/src/runtime/emit/update-executor.d.ts.map +0 -1
  82. package/dist/src/runtime/emit/update-executor.js +0 -54
  83. package/dist/src/runtime/emit/update-executor.js.map +0 -1
  84. package/dist/src/util/plugin-loader.d.ts +0 -52
  85. package/dist/src/util/plugin-loader.d.ts.map +0 -1
  86. package/dist/src/util/plugin-loader.js +0 -307
  87. package/dist/src/util/plugin-loader.js.map +0 -1
  88. package/src/config/loader.ts +0 -140
  89. package/src/util/plugin-loader.ts +0 -387
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Hash and encoding utilities
3
+ */
4
+
5
+ /**
6
+ * Computes FNV-1a hash of a string (64-bit variant)
7
+ * Returns an 8-byte array representing the hash
8
+ *
9
+ * FNV-1a is a fast, non-cryptographic hash function with good distribution.
10
+ * See: http://www.isthe.com/chongo/tech/comp/fnv/
11
+ */
12
+ export function fnv1aHash(str: string): Uint8Array {
13
+ // FNV-1a 64-bit parameters
14
+ // Using two 32-bit integers to represent 64-bit hash (JavaScript limitation)
15
+ let hashHigh = 0xcbf29ce4; // Upper 32 bits of FNV offset basis
16
+ let hashLow = 0x84222325; // Lower 32 bits of FNV offset basis
17
+
18
+ const fnvPrimeHigh = 0x00000100; // Upper 32 bits of FNV prime
19
+ const fnvPrimeLow = 0x000001b3; // Lower 32 bits of FNV prime
20
+
21
+ for (let i = 0; i < str.length; i++) {
22
+ const charCode = str.charCodeAt(i);
23
+
24
+ // XOR with byte (handle multi-byte characters)
25
+ hashLow ^= charCode & 0xff;
26
+
27
+ // Multiply by FNV prime (64-bit multiplication using 32-bit parts)
28
+ const aHigh = hashHigh;
29
+ const aLow = hashLow;
30
+
31
+ hashLow = (aLow * fnvPrimeLow) >>> 0;
32
+ hashHigh = (aHigh * fnvPrimeLow + aLow * fnvPrimeHigh + (hashLow / 0x100000000)) >>> 0;
33
+ hashLow = hashLow >>> 0;
34
+
35
+ // Handle high byte of character if present
36
+ if (charCode > 0xff) {
37
+ hashLow ^= (charCode >>> 8) & 0xff;
38
+ const bHigh = hashHigh;
39
+ const bLow = hashLow;
40
+ hashLow = (bLow * fnvPrimeLow) >>> 0;
41
+ hashHigh = (bHigh * fnvPrimeLow + bLow * fnvPrimeHigh + (hashLow / 0x100000000)) >>> 0;
42
+ hashLow = hashLow >>> 0;
43
+ }
44
+ }
45
+
46
+ // Convert to 8-byte array
47
+ const bytes = new Uint8Array(8);
48
+ bytes[0] = (hashHigh >>> 24) & 0xff;
49
+ bytes[1] = (hashHigh >>> 16) & 0xff;
50
+ bytes[2] = (hashHigh >>> 8) & 0xff;
51
+ bytes[3] = hashHigh & 0xff;
52
+ bytes[4] = (hashLow >>> 24) & 0xff;
53
+ bytes[5] = (hashLow >>> 16) & 0xff;
54
+ bytes[6] = (hashLow >>> 8) & 0xff;
55
+ bytes[7] = hashLow & 0xff;
56
+
57
+ return bytes;
58
+ }
59
+
60
+ /**
61
+ * Converts a byte array to base64url encoding
62
+ * (URL-safe base64 without padding: uses - and _ instead of + and /, no = padding)
63
+ *
64
+ * Base64url is defined in RFC 4648 Section 5.
65
+ */
66
+ export function toBase64Url(bytes: Uint8Array): string {
67
+ const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
68
+ let result = '';
69
+
70
+ for (let i = 0; i < bytes.length; i += 3) {
71
+ // Get 3 bytes (24 bits) and convert to 4 base64 characters (6 bits each)
72
+ const byte1 = bytes[i];
73
+ const byte2 = i + 1 < bytes.length ? bytes[i + 1] : 0;
74
+ const byte3 = i + 2 < bytes.length ? bytes[i + 2] : 0;
75
+
76
+ const triplet = (byte1 << 16) | (byte2 << 8) | byte3;
77
+
78
+ result += base64Chars[(triplet >>> 18) & 0x3f];
79
+ result += base64Chars[(triplet >>> 12) & 0x3f];
80
+ if (i + 1 < bytes.length) {
81
+ result += base64Chars[(triplet >>> 6) & 0x3f];
82
+ }
83
+ if (i + 2 < bytes.length) {
84
+ result += base64Chars[triplet & 0x3f];
85
+ }
86
+ }
87
+
88
+ return result;
89
+ }
90
+
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Plugin registration helper for static plugin loading
3
+ *
4
+ * This module provides utilities for registering plugins without dynamic imports,
5
+ * which is useful for React Native and other environments where dynamic imports
6
+ * are not supported.
7
+ */
8
+
9
+ import type { Database } from '../core/database.js';
10
+ import type { PluginRegistrations } from '../vtab/manifest.js';
11
+ import type { SqlValue } from '../common/types.js';
12
+
13
+ /**
14
+ * Plugin function type - what a plugin exports as its default export
15
+ */
16
+ export type PluginFunction = (
17
+ db: Database,
18
+ config?: Record<string, SqlValue>
19
+ ) => Promise<PluginRegistrations> | PluginRegistrations;
20
+
21
+ /**
22
+ * Register a plugin's components with the database.
23
+ *
24
+ * This is a helper function for static plugin loading that handles calling
25
+ * the plugin function and registering all returned components (vtables,
26
+ * functions, collations, types) with the database.
27
+ *
28
+ * @param db Database instance to register with
29
+ * @param plugin Plugin function (the default export from a plugin module)
30
+ * @param config Optional configuration object to pass to the plugin
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { Database } from '@quereus/quereus';
35
+ * import { registerPlugin } from '@quereus/quereus';
36
+ * import myPlugin from './plugins/my-plugin';
37
+ *
38
+ * const db = new Database();
39
+ * await registerPlugin(db, myPlugin, { apiKey: 'secret' });
40
+ * ```
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Register multiple plugins
45
+ * await registerPlugin(db, stringFunctions);
46
+ * await registerPlugin(db, customCollations);
47
+ * await registerPlugin(db, jsonTable, { cacheSize: 100 });
48
+ * ```
49
+ */
50
+ export async function registerPlugin(
51
+ db: Database,
52
+ plugin: PluginFunction,
53
+ config: Record<string, SqlValue> = {}
54
+ ): Promise<void> {
55
+ // Call the plugin function to get registrations
56
+ const registrations = await plugin(db, config);
57
+
58
+ // Register virtual table modules
59
+ if (registrations.vtables) {
60
+ for (const vtable of registrations.vtables) {
61
+ try {
62
+ db.registerVtabModule(vtable.name, vtable.module, vtable.auxData);
63
+ } catch (error) {
64
+ throw new Error(
65
+ `Failed to register vtable module '${vtable.name}': ${error instanceof Error ? error.message : String(error)}`
66
+ );
67
+ }
68
+ }
69
+ }
70
+
71
+ // Register functions
72
+ if (registrations.functions) {
73
+ for (const func of registrations.functions) {
74
+ try {
75
+ db.registerFunction(func.schema);
76
+ } catch (error) {
77
+ throw new Error(
78
+ `Failed to register function '${func.schema.name}/${func.schema.numArgs}': ${error instanceof Error ? error.message : String(error)}`
79
+ );
80
+ }
81
+ }
82
+ }
83
+
84
+ // Register collations
85
+ if (registrations.collations) {
86
+ for (const collation of registrations.collations) {
87
+ try {
88
+ db.registerCollation(collation.name, collation.func);
89
+ } catch (error) {
90
+ throw new Error(
91
+ `Failed to register collation '${collation.name}': ${error instanceof Error ? error.message : String(error)}`
92
+ );
93
+ }
94
+ }
95
+ }
96
+
97
+ // Register types
98
+ if (registrations.types) {
99
+ for (const type of registrations.types) {
100
+ try {
101
+ db.registerType(type.name, type.definition);
102
+ } catch (error) {
103
+ throw new Error(
104
+ `Failed to register type '${type.name}': ${error instanceof Error ? error.message : String(error)}`
105
+ );
106
+ }
107
+ }
108
+ }
109
+ }
110
+