From ad944f80e3c84d5aef6a991032a268bf680fdbeb Mon Sep 17 00:00:00 2001 From: Krzysztof Borowy <6444719+krizzu@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:11:56 +0200 Subject: [PATCH] sqlite-storage: scaffold workspace (#1071) * chore(deps): bump follow-redirects from 1.15.4 to 1.15.6 (#1074) * feat(default-storage): Add Privacy Manifest for iOS (#1075) privacy file * chore(release): 1.23.0 [skip ci] * fix(default-storage): Privacy manifest missing key (#1076) add missing key * chore(release): 1.23.1 [skip ci] * chore(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 (#1077) Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 5.3.3 to 5.3.4. - [Release notes](https://github.com/webpack/webpack-dev-middleware/releases) - [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md) - [Commits](https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4) --- updated-dependencies: - dependency-name: webpack-dev-middleware dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: GH workflows, turbo and other chores (#1073) * explicit prettierrc * turbo * format test * pull-request workflow * update actions * bump to yarn 4 * build script * init * examples * comments * fix glob * namespace * windows build * fixing windows action * android example search for node_modules --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: AsyncStorageBot <118817110+AsyncStorageBot@users.noreply.github.com> --- .github/actions/setup-project/action.yml | 9 + .github/workflows/default-storage.yml | 4 +- .gitignore | 1 + packages/default-storage/package.json | 2 +- packages/default-storage/tsconfig.json | 2 +- packages/sqlite-storage/.gitattributes | 3 + packages/sqlite-storage/README.md | 3 + .../RNAsyncStorageSQLite.podspec | 41 + packages/sqlite-storage/android/build.gradle | 94 + .../sqlite-storage/android/gradle.properties | 5 + .../android/src/main/AndroidManifest.xml | 3 + .../android/src/main/AndroidManifestNew.xml | 2 + .../sqlitestorage/SqliteStorageModule.kt | 25 + .../sqlitestorage/SqliteStoragePackage.kt | 17 + packages/sqlite-storage/babel.config.js | 3 + packages/sqlite-storage/eslint.config.js | 1 + .../sqlite-storage/example/.watchmanconfig | 1 + packages/sqlite-storage/example/App.tsx | 70 + .../example/android/build.gradle | 42 + .../example/android/gradle.properties | 53 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 43462 bytes .../gradle/wrapper/gradle-wrapper.properties | 7 + .../sqlite-storage/example/android/gradlew | 249 ++ .../example/android/gradlew.bat | 92 + .../example/android/settings.gradle | 21 + packages/sqlite-storage/example/app.json | 16 + packages/sqlite-storage/example/index.js | 5 + .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + packages/sqlite-storage/example/ios/Podfile | 18 + .../sqlite-storage/example/ios/Podfile.lock | 1254 +++++++++ .../ios/SqliteStorage-Bridging-Header.h | 2 + packages/sqlite-storage/ios/SqliteStorage.mm | 16 + .../sqlite-storage/ios/SqliteStorage.swift | 8 + packages/sqlite-storage/jest.config.js | 5 + packages/sqlite-storage/metro.config.js | 15 + packages/sqlite-storage/package.json | 88 + .../sqlite-storage/react-native.config.js | 25 + packages/sqlite-storage/src/index.ts | 22 + packages/sqlite-storage/tests/index.test.ts | 1 + packages/sqlite-storage/tsconfig.build.json | 4 + packages/sqlite-storage/tsconfig.json | 10 + yarn.lock | 2307 ++++++++++++++++- 43 files changed, 4424 insertions(+), 140 deletions(-) create mode 100644 packages/sqlite-storage/.gitattributes create mode 100644 packages/sqlite-storage/README.md create mode 100644 packages/sqlite-storage/RNAsyncStorageSQLite.podspec create mode 100644 packages/sqlite-storage/android/build.gradle create mode 100644 packages/sqlite-storage/android/gradle.properties create mode 100644 packages/sqlite-storage/android/src/main/AndroidManifest.xml create mode 100644 packages/sqlite-storage/android/src/main/AndroidManifestNew.xml create mode 100644 packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStorageModule.kt create mode 100644 packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStoragePackage.kt create mode 100644 packages/sqlite-storage/babel.config.js create mode 100644 packages/sqlite-storage/eslint.config.js create mode 100644 packages/sqlite-storage/example/.watchmanconfig create mode 100644 packages/sqlite-storage/example/App.tsx create mode 100644 packages/sqlite-storage/example/android/build.gradle create mode 100644 packages/sqlite-storage/example/android/gradle.properties create mode 100644 packages/sqlite-storage/example/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 packages/sqlite-storage/example/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 packages/sqlite-storage/example/android/gradlew create mode 100644 packages/sqlite-storage/example/android/gradlew.bat create mode 100644 packages/sqlite-storage/example/android/settings.gradle create mode 100644 packages/sqlite-storage/example/app.json create mode 100644 packages/sqlite-storage/example/index.js create mode 100644 packages/sqlite-storage/example/ios/AsyncStorageSQLiteExample.xcworkspace/contents.xcworkspacedata create mode 100644 packages/sqlite-storage/example/ios/AsyncStorageSQLiteExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 packages/sqlite-storage/example/ios/Podfile create mode 100644 packages/sqlite-storage/example/ios/Podfile.lock create mode 100644 packages/sqlite-storage/ios/SqliteStorage-Bridging-Header.h create mode 100644 packages/sqlite-storage/ios/SqliteStorage.mm create mode 100644 packages/sqlite-storage/ios/SqliteStorage.swift create mode 100644 packages/sqlite-storage/jest.config.js create mode 100644 packages/sqlite-storage/metro.config.js create mode 100644 packages/sqlite-storage/package.json create mode 100644 packages/sqlite-storage/react-native.config.js create mode 100644 packages/sqlite-storage/src/index.ts create mode 100644 packages/sqlite-storage/tests/index.test.ts create mode 100644 packages/sqlite-storage/tsconfig.build.json create mode 100644 packages/sqlite-storage/tsconfig.json diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml index ab2e9822..5449508b 100644 --- a/.github/actions/setup-project/action.yml +++ b/.github/actions/setup-project/action.yml @@ -5,9 +5,18 @@ inputs: required: false description: node version to install default: 20.10.0 # is already cached in Ubuntu 22.04 runner + windows-fix: + required: false + description: https://github.com/actions/setup-node/issues/899#issuecomment-1837381044 + default: "false" runs: using: composite steps: + - uses: actions/setup-node@v4 + if: ${{ inputs.windows-fix == 'true' }} + name: (Windows fix) Setup node without cache + with: + node-version: ${{ inputs.node-version }} - name: Enable corepack shell: bash run: | diff --git a/.github/workflows/default-storage.yml b/.github/workflows/default-storage.yml index 6b753a72..cb797b92 100644 --- a/.github/workflows/default-storage.yml +++ b/.github/workflows/default-storage.yml @@ -18,7 +18,7 @@ jobs: token: ${{ secrets.GH_RELEASE_TOKEN }} filters: | storage: - - 'packages/default-storage' + - 'packages/default-storage/**' android: name: Android @@ -127,6 +127,8 @@ jobs: uses: actions/checkout@v4 - name: Setup project uses: ./.github/actions/setup-project + with: + windows-fix: true - name: Install JS dependencies run: | yarn diff --git a/.gitignore b/.gitignore index e0f35958..b438e5be 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ local.properties #workspaces /packages/*/lib .turbo +build/ diff --git a/packages/default-storage/package.json b/packages/default-storage/package.json index a78ea0db..242fca5b 100644 --- a/packages/default-storage/package.json +++ b/packages/default-storage/package.json @@ -18,7 +18,7 @@ "src/", "windows/" ], - "author": "Krzysztof Borowy ", + "author": "Krzysztof Borowy ", "contributors": [ "Evan Bacon (https://github.com/evanbacon)", "Tommy Nguyen <4123478+tido64@users.noreply.github.com> (https://github.com/tido64)" diff --git a/packages/default-storage/tsconfig.json b/packages/default-storage/tsconfig.json index c0496615..9b4fc0e0 100644 --- a/packages/default-storage/tsconfig.json +++ b/packages/default-storage/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.build.json", + "extends": "../../.config/tsconfig.base.json", "compilerOptions": { "noEmit": true, "types": [ diff --git a/packages/sqlite-storage/.gitattributes b/packages/sqlite-storage/.gitattributes new file mode 100644 index 00000000..030ef144 --- /dev/null +++ b/packages/sqlite-storage/.gitattributes @@ -0,0 +1,3 @@ +*.pbxproj -text +# specific for windows script files +*.bat text eol=crlf \ No newline at end of file diff --git a/packages/sqlite-storage/README.md b/packages/sqlite-storage/README.md new file mode 100644 index 00000000..bfe92bdd --- /dev/null +++ b/packages/sqlite-storage/README.md @@ -0,0 +1,3 @@ +# Async Storage SQLite + +Key-value persistent storage for React Native backed by SQLite. diff --git a/packages/sqlite-storage/RNAsyncStorageSQLite.podspec b/packages/sqlite-storage/RNAsyncStorageSQLite.podspec new file mode 100644 index 00000000..97000547 --- /dev/null +++ b/packages/sqlite-storage/RNAsyncStorageSQLite.podspec @@ -0,0 +1,41 @@ +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) +folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' + +Pod::Spec.new do |s| + s.name = File.basename(__FILE__, '.podspec') + s.version = package["version"] + s.summary = package["description"] + s.homepage = package["homepage"] + s.license = package["license"] + s.authors = package["author"] + + s.platforms = { :ios => min_ios_version_supported } + s.source = { :git => "https://github.com/react-native-async-storage/async-storage.git", :tag => "#{s.version}" } + + s.source_files = "ios/**/*.{h,m,mm,swift}" + + # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. + # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. + if respond_to?(:install_modules_dependencies, true) + install_modules_dependencies(s) + else + s.dependency "React-Core" + + # Don't install the dependencies when we run `pod install` in the old architecture. + if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then + s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", + "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" + } + s.dependency "React-Codegen" + s.dependency "RCT-Folly" + s.dependency "RCTRequired" + s.dependency "RCTTypeSafety" + s.dependency "ReactCommon/turbomodule/core" + end + end +end diff --git a/packages/sqlite-storage/android/build.gradle b/packages/sqlite-storage/android/build.gradle new file mode 100644 index 00000000..a40dce20 --- /dev/null +++ b/packages/sqlite-storage/android/build.gradle @@ -0,0 +1,94 @@ +buildscript { + // Buildscript is evaluated before everything else so we can't use getExtOrDefault + def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["SqliteStorage_kotlinVersion"] + + repositories { + google() + mavenCentral() + } + + dependencies { + classpath "com.android.tools.build:gradle:7.2.1" + // noinspection DifferentKotlinGradleVersion + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +def isNewArchitectureEnabled() { + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" +} + +apply plugin: "com.android.library" +apply plugin: "kotlin-android" + +if (isNewArchitectureEnabled()) { + apply plugin: "com.facebook.react" +} + +def getExtOrDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["SqliteStorage_" + name] +} + +def getExtOrIntegerDefault(name) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SqliteStorage_" + name]).toInteger() +} + +def supportsNamespace() { + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def major = parsed[0].toInteger() + def minor = parsed[1].toInteger() + + // Namespace support was added in 7.3.0 + return (major == 7 && minor >= 3) || major >= 8 +} + +android { + if (supportsNamespace()) { + namespace "org.rnasyncstorage.sqlitestorage" + + sourceSets { + main { + manifest.srcFile "src/main/AndroidManifestNew.xml" + } + } + } + + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") + + defaultConfig { + minSdkVersion getExtOrIntegerDefault("minSdkVersion") + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") + + } + + buildTypes { + release { + minifyEnabled false + } + } + + lintOptions { + disable "GradleCompatible" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +repositories { + mavenCentral() + google() +} + +def kotlin_version = getExtOrDefault("kotlinVersion") + +dependencies { + // For < 0.71, this will be from the local maven repo + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin + //noinspection GradleDynamicVersion + implementation "com.facebook.react:react-native:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" +} + diff --git a/packages/sqlite-storage/android/gradle.properties b/packages/sqlite-storage/android/gradle.properties new file mode 100644 index 00000000..d5ef57fc --- /dev/null +++ b/packages/sqlite-storage/android/gradle.properties @@ -0,0 +1,5 @@ +SqliteStorage_kotlinVersion=1.7.0 +SqliteStorage_minSdkVersion=21 +SqliteStorage_targetSdkVersion=31 +SqliteStorage_compileSdkVersion=31 +SqliteStorage_ndkversion=21.4.7075529 diff --git a/packages/sqlite-storage/android/src/main/AndroidManifest.xml b/packages/sqlite-storage/android/src/main/AndroidManifest.xml new file mode 100644 index 00000000..cf9dd4b9 --- /dev/null +++ b/packages/sqlite-storage/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/packages/sqlite-storage/android/src/main/AndroidManifestNew.xml b/packages/sqlite-storage/android/src/main/AndroidManifestNew.xml new file mode 100644 index 00000000..a2f47b60 --- /dev/null +++ b/packages/sqlite-storage/android/src/main/AndroidManifestNew.xml @@ -0,0 +1,2 @@ + + diff --git a/packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStorageModule.kt b/packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStorageModule.kt new file mode 100644 index 00000000..c9cab554 --- /dev/null +++ b/packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStorageModule.kt @@ -0,0 +1,25 @@ +package org.rnasyncstorage.sqlitestorage + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReactMethod +import com.facebook.react.bridge.Promise + +class SqliteStorageModule(reactContext: ReactApplicationContext) : + ReactContextBaseJavaModule(reactContext) { + + override fun getName(): String { + return NAME + } + + // Example method + // See https://reactnative.dev/docs/native-modules-android + @ReactMethod + fun multiply(a: Double, b: Double, promise: Promise) { + promise.resolve(a * b) + } + + companion object { + const val NAME = "SqliteStorage" + } +} diff --git a/packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStoragePackage.kt b/packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStoragePackage.kt new file mode 100644 index 00000000..46bffa3c --- /dev/null +++ b/packages/sqlite-storage/android/src/main/java/org/rnasyncstorage/sqlitestorage/SqliteStoragePackage.kt @@ -0,0 +1,17 @@ +package org.rnasyncstorage.sqlitestorage + +import com.facebook.react.ReactPackage +import com.facebook.react.bridge.NativeModule +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.uimanager.ViewManager + + +class SqliteStoragePackage : ReactPackage { + override fun createNativeModules(reactContext: ReactApplicationContext): List { + return listOf(SqliteStorageModule(reactContext)) + } + + override fun createViewManagers(reactContext: ReactApplicationContext): List> { + return emptyList() + } +} diff --git a/packages/sqlite-storage/babel.config.js b/packages/sqlite-storage/babel.config.js new file mode 100644 index 00000000..3c25e5d9 --- /dev/null +++ b/packages/sqlite-storage/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: ["module:@react-native/babel-preset"], +}; diff --git a/packages/sqlite-storage/eslint.config.js b/packages/sqlite-storage/eslint.config.js new file mode 100644 index 00000000..f23036d9 --- /dev/null +++ b/packages/sqlite-storage/eslint.config.js @@ -0,0 +1 @@ +module.exports = require("@react-native-async-storage/eslint-config"); diff --git a/packages/sqlite-storage/example/.watchmanconfig b/packages/sqlite-storage/example/.watchmanconfig new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/packages/sqlite-storage/example/.watchmanconfig @@ -0,0 +1 @@ +{} diff --git a/packages/sqlite-storage/example/App.tsx b/packages/sqlite-storage/example/App.tsx new file mode 100644 index 00000000..5d198739 --- /dev/null +++ b/packages/sqlite-storage/example/App.tsx @@ -0,0 +1,70 @@ +import React, { useState } from "react"; +import { + Button, + SafeAreaView, + ScrollView, + Text, + StatusBar, + StyleSheet, + useColorScheme, + View, +} from "react-native"; +import { Colors } from "react-native/Libraries/NewAppScreen"; +import { multiply } from "@react-native-async-storage/sqlite-storage"; + +function App(): React.JSX.Element { + const isDarkMode = useColorScheme() === "dark"; + const [result, setResult] = useState(null); + + const backgroundStyle = { + backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, + }; + + async function test() { + const random = Math.round(Math.random() * 100); + const result = await multiply(random, 2); + setResult(`${random} * 2 = ${result}`); + } + + return ( + + + +