@photostructure/sqlite 0.0.1

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 (53) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/LICENSE +21 -0
  3. package/README.md +522 -0
  4. package/SECURITY.md +114 -0
  5. package/binding.gyp +94 -0
  6. package/dist/index.cjs +134 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +408 -0
  9. package/dist/index.d.mts +408 -0
  10. package/dist/index.d.ts +408 -0
  11. package/dist/index.mjs +103 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +144 -0
  14. package/prebuilds/darwin-arm64/@photostructure+sqlite.glibc.node +0 -0
  15. package/prebuilds/linux-arm64/@photostructure+sqlite.glibc.node +0 -0
  16. package/prebuilds/linux-arm64/@photostructure+sqlite.musl.node +0 -0
  17. package/prebuilds/linux-x64/@photostructure+sqlite.glibc.node +0 -0
  18. package/prebuilds/linux-x64/@photostructure+sqlite.musl.node +0 -0
  19. package/prebuilds/win32-x64/@photostructure+sqlite.glibc.node +0 -0
  20. package/scripts/post-build.mjs +21 -0
  21. package/scripts/prebuild-linux-glibc.sh +108 -0
  22. package/src/aggregate_function.cpp +417 -0
  23. package/src/aggregate_function.h +116 -0
  24. package/src/binding.cpp +160 -0
  25. package/src/dirname.ts +13 -0
  26. package/src/index.ts +465 -0
  27. package/src/shims/base_object-inl.h +8 -0
  28. package/src/shims/base_object.h +50 -0
  29. package/src/shims/debug_utils-inl.h +23 -0
  30. package/src/shims/env-inl.h +19 -0
  31. package/src/shims/memory_tracker-inl.h +17 -0
  32. package/src/shims/napi_extensions.h +73 -0
  33. package/src/shims/node.h +16 -0
  34. package/src/shims/node_errors.h +66 -0
  35. package/src/shims/node_mem-inl.h +8 -0
  36. package/src/shims/node_mem.h +31 -0
  37. package/src/shims/node_url.h +23 -0
  38. package/src/shims/promise_resolver.h +31 -0
  39. package/src/shims/util-inl.h +18 -0
  40. package/src/shims/util.h +101 -0
  41. package/src/sqlite_impl.cpp +2440 -0
  42. package/src/sqlite_impl.h +314 -0
  43. package/src/stack_path.ts +64 -0
  44. package/src/types/node-gyp-build.d.ts +4 -0
  45. package/src/upstream/node_sqlite.cc +2706 -0
  46. package/src/upstream/node_sqlite.h +234 -0
  47. package/src/upstream/sqlite.gyp +38 -0
  48. package/src/upstream/sqlite.js +19 -0
  49. package/src/upstream/sqlite3.c +262809 -0
  50. package/src/upstream/sqlite3.h +13773 -0
  51. package/src/upstream/sqlite3ext.h +723 -0
  52. package/src/user_function.cpp +225 -0
  53. package/src/user_function.h +40 -0
@@ -0,0 +1,66 @@
1
+ #ifndef SRC_SHIMS_NODE_ERRORS_H_
2
+ #define SRC_SHIMS_NODE_ERRORS_H_
3
+
4
+ #include <napi.h>
5
+
6
+ #include <string>
7
+
8
+ namespace node {
9
+
10
+ // Error throwing utilities matching Node.js patterns
11
+ inline void THROW_ERR_INVALID_STATE(Napi::Env env,
12
+ const char *message = nullptr) {
13
+ const char *msg = message ? message : "Invalid state";
14
+ Napi::Error::New(env, msg).ThrowAsJavaScriptException();
15
+ }
16
+
17
+ inline void THROW_ERR_INVALID_ARG_TYPE(Napi::Env env,
18
+ const char *message = nullptr) {
19
+ const char *msg = message ? message : "Invalid argument type";
20
+ Napi::TypeError::New(env, msg).ThrowAsJavaScriptException();
21
+ }
22
+
23
+ inline void THROW_ERR_OUT_OF_RANGE(Napi::Env env,
24
+ const char *message = nullptr) {
25
+ const char *msg = message ? message : "Value out of range";
26
+ Napi::RangeError::New(env, msg).ThrowAsJavaScriptException();
27
+ }
28
+
29
+ inline void THROW_ERR_INVALID_ARG_VALUE(Napi::Env env,
30
+ const char *message = nullptr) {
31
+ const char *msg = message ? message : "Invalid argument value";
32
+ Napi::Error::New(env, msg).ThrowAsJavaScriptException();
33
+ }
34
+
35
+ inline void THROW_ERR_SQLITE_ERROR(Napi::Env env,
36
+ const char *message = nullptr) {
37
+ const char *msg = message ? message : "SQLite error";
38
+ Napi::Error::New(env, msg).ThrowAsJavaScriptException();
39
+ }
40
+
41
+ inline void THROW_ERR_CONSTRUCT_CALL_REQUIRED(Napi::Env env) {
42
+ Napi::TypeError::New(env, "Class constructor cannot be invoked without 'new'")
43
+ .ThrowAsJavaScriptException();
44
+ }
45
+
46
+ inline void THROW_ERR_INVALID_URL_SCHEME(Napi::Env env,
47
+ const char *scheme = nullptr) {
48
+ std::string msg = "Invalid URL scheme";
49
+ if (scheme) {
50
+ msg += ": ";
51
+ msg += scheme;
52
+ }
53
+ Napi::TypeError::New(env, msg).ThrowAsJavaScriptException();
54
+ }
55
+
56
+ inline void THROW_ERR_LOAD_SQLITE_EXTENSION(Napi::Env env,
57
+ const char *message = nullptr) {
58
+ const char *msg = message ? message : "Failed to load SQLite extension";
59
+ Napi::Error::New(env, msg).ThrowAsJavaScriptException();
60
+ }
61
+
62
+ // Macro wrappers for compatibility (removed to avoid conflicts)
63
+
64
+ } // namespace node
65
+
66
+ #endif // SRC_SHIMS_NODE_ERRORS_H_
@@ -0,0 +1,8 @@
1
+ #ifndef SRC_SHIMS_NODE_MEM_INL_H_
2
+ #define SRC_SHIMS_NODE_MEM_INL_H_
3
+
4
+ #include "node_mem.h"
5
+
6
+ // Inline implementations
7
+
8
+ #endif // SRC_SHIMS_NODE_MEM_INL_H_
@@ -0,0 +1,31 @@
1
+ #ifndef SRC_SHIMS_NODE_MEM_H_
2
+ #define SRC_SHIMS_NODE_MEM_H_
3
+
4
+ #include <cstdlib>
5
+ #include <memory>
6
+
7
+ namespace node {
8
+
9
+ // Memory allocation wrappers
10
+ template <typename T> T *Malloc(size_t count) {
11
+ return static_cast<T *>(std::malloc(sizeof(T) * count));
12
+ }
13
+
14
+ template <typename T> T *Realloc(T *ptr, size_t count) {
15
+ return static_cast<T *>(std::realloc(ptr, sizeof(T) * count));
16
+ }
17
+
18
+ inline void Free(void *ptr) { std::free(ptr); }
19
+
20
+ // Memory tracker stub
21
+ class MemoryTracker {
22
+ public:
23
+ template <typename T> void TrackField(const char *, const T &) {}
24
+
25
+ template <typename T>
26
+ void TrackFieldWithSize(const char *, const T &, size_t) {}
27
+ };
28
+
29
+ } // namespace node
30
+
31
+ #endif // SRC_SHIMS_NODE_MEM_H_
@@ -0,0 +1,23 @@
1
+ #ifndef SRC_SHIMS_NODE_URL_H_
2
+ #define SRC_SHIMS_NODE_URL_H_
3
+
4
+ #include <string>
5
+
6
+ namespace node {
7
+ namespace url {
8
+
9
+ // URL utilities - minimal implementation
10
+ class URL {
11
+ public:
12
+ explicit URL(const std::string &input) : href_(input) {}
13
+
14
+ const std::string &href() const { return href_; }
15
+
16
+ private:
17
+ std::string href_;
18
+ };
19
+
20
+ } // namespace url
21
+ } // namespace node
22
+
23
+ #endif // SRC_SHIMS_NODE_URL_H_
@@ -0,0 +1,31 @@
1
+ #ifndef SRC_SHIMS_PROMISE_RESOLVER_H_
2
+ #define SRC_SHIMS_PROMISE_RESOLVER_H_
3
+
4
+ #include <napi.h>
5
+
6
+ namespace node {
7
+
8
+ // Promise resolver wrapper for N-API
9
+ class PromiseResolver {
10
+ public:
11
+ static PromiseResolver Create(Napi::Env env) {
12
+ auto deferred = Napi::Promise::Deferred::New(env);
13
+ return PromiseResolver(deferred);
14
+ }
15
+
16
+ Napi::Promise GetPromise() { return deferred_.Promise(); }
17
+
18
+ void Resolve(Napi::Value value) { deferred_.Resolve(value); }
19
+
20
+ void Reject(Napi::Value value) { deferred_.Reject(value); }
21
+
22
+ private:
23
+ explicit PromiseResolver(Napi::Promise::Deferred deferred)
24
+ : deferred_(deferred) {}
25
+
26
+ Napi::Promise::Deferred deferred_;
27
+ };
28
+
29
+ } // namespace node
30
+
31
+ #endif // SRC_SHIMS_PROMISE_RESOLVER_H_
@@ -0,0 +1,18 @@
1
+ #ifndef SRC_SHIMS_UTIL_INL_H_
2
+ #define SRC_SHIMS_UTIL_INL_H_
3
+
4
+ #include "util.h"
5
+
6
+ namespace node {
7
+
8
+ inline void THROW_ERR_INVALID_ARG_TYPE(Napi::Env env, const char *message) {
9
+ Napi::TypeError::New(env, message).ThrowAsJavaScriptException();
10
+ }
11
+
12
+ inline void THROW_ERR_OUT_OF_RANGE(Napi::Env env, const char *message) {
13
+ Napi::RangeError::New(env, message).ThrowAsJavaScriptException();
14
+ }
15
+
16
+ } // namespace node
17
+
18
+ #endif // SRC_SHIMS_UTIL_INL_H_
@@ -0,0 +1,101 @@
1
+ #ifndef SRC_SHIMS_UTIL_H_
2
+ #define SRC_SHIMS_UTIL_H_
3
+
4
+ #include <napi.h>
5
+
6
+ #include <algorithm>
7
+ #include <string>
8
+ #include <unordered_map>
9
+
10
+ namespace node {
11
+
12
+ // Environment class for Node.js context
13
+ class Environment {
14
+ public:
15
+ static Environment *GetCurrent(Napi::Env env) {
16
+ // Store per-environment instances
17
+ static thread_local std::unordered_map<napi_env,
18
+ std::unique_ptr<Environment>>
19
+ instances;
20
+ auto it = instances.find(env);
21
+ if (it == instances.end()) {
22
+ auto result = instances.emplace(env, std::make_unique<Environment>(env));
23
+ return result.first->second.get();
24
+ }
25
+ return it->second.get();
26
+ }
27
+
28
+ explicit Environment(Napi::Env env) : env_(env) {}
29
+
30
+ Napi::Env env() const { return env_; }
31
+ napi_env raw_env() const { return env_; }
32
+
33
+ // String caching for common strings (simplified)
34
+ Napi::String href_string() const { return Napi::String::New(env_, "href"); }
35
+ Napi::String timeout_string() const {
36
+ return Napi::String::New(env_, "timeout");
37
+ }
38
+ Napi::String backup_string() const {
39
+ return Napi::String::New(env_, "backup");
40
+ }
41
+ Napi::String constants_string() const {
42
+ return Napi::String::New(env_, "constants");
43
+ }
44
+
45
+ // Permission system stub
46
+ class Permission {
47
+ public:
48
+ bool is_granted() const { return true; }
49
+ };
50
+
51
+ Permission *permission() {
52
+ static Permission perm;
53
+ return &perm;
54
+ }
55
+
56
+ private:
57
+ Napi::Env env_;
58
+ };
59
+
60
+ // String utilities
61
+ inline std::string ToLower(const std::string &str) {
62
+ std::string result = str;
63
+ std::transform(result.begin(), result.end(), result.begin(), ::tolower);
64
+ return result;
65
+ }
66
+
67
+ // Template helpers for setting constructor functions
68
+ template <typename T>
69
+ void SetConstructorFunction(Napi::Env env, Napi::Object target,
70
+ const char *name, Napi::Function constructor) {
71
+ target.Set(name, constructor);
72
+ }
73
+
74
+ // Template helpers for setting prototype methods
75
+ template <typename T>
76
+ void SetProtoMethod(napi_env env, Napi::Function constructor, const char *name,
77
+ napi_callback callback) {
78
+ // This would need more sophisticated implementation for full compatibility
79
+ // For now, we'll handle this in the class definitions
80
+ }
81
+
82
+ template <typename T>
83
+ void SetProtoMethodNoSideEffect(napi_env env, Napi::Function constructor,
84
+ const char *name, napi_callback callback) {
85
+ SetProtoMethod<T>(env, constructor, name, callback);
86
+ }
87
+
88
+ // Getter helpers
89
+ template <typename T>
90
+ void SetSideEffectFreeGetter(napi_env env, Napi::Function constructor,
91
+ Napi::String name, napi_callback callback) {
92
+ // Simplified implementation
93
+ }
94
+
95
+ // Error throwing helpers
96
+ void THROW_ERR_INVALID_ARG_TYPE(Napi::Env env, const char *message);
97
+ void THROW_ERR_OUT_OF_RANGE(Napi::Env env, const char *message);
98
+
99
+ } // namespace node
100
+
101
+ #endif // SRC_SHIMS_UTIL_H_