Code Monkey home page Code Monkey logo

realm-template-apps's Introduction

realm-template-apps

This is the main repo for all MongoDB App Services & Realm template starter app clients and backend configurations.

A GitHub Action uploads to the realm-template-apps S3 bucket. See .github/workflows/zip-everything-and-upload-to-s3.yml.

For bucket access, consult the Realm docs team.

Lay of the Land

  • manifest.json: Tells the App Services server which templates correspond to which backends and various other configuration details. This must be updated whenever you want to expose a new app or move anything around.
  • sync-todo/: The template app. Even though App Services can tie any app from this repo into the template app infrastructure, when people refer to "the template app", they usually mean this one. Comes in many clients and has had many versions.
  • other/: All other apps.
  • tools/: Useful things for working within this repo.

Sync-todo Versions

  • v2: (Current) A todo app with a flexible sync backend that has a few new nifty features.

About "generated"

โš ๏ธ If the path contains /generated/, don't edit it directly! This is generated from another source, probably using Bluehawk.

Artifact Repos

A GitHub Action creates "artifact repos" of a few subdirectories so that the client code can be examined and cloned easily.

Adding a New Template App

  1. Add your project in its own subdirectory. If you are basing your project off of an existing project (for example, creating a Flexible-Sync version of a partition-based app), consider using the Bluehawk state tags and using Bluehawk to copy each app to its own subdirectory within the generated directory.

  2. Be sure your project uses a realm.json file (or .xml, or .plist...) to get the app id, base url info, and data explorer link:

    {
       "appId": "todo-sync-jxgjv",
       "baseUrl": "https://services.cloud.mongodb.com",
       "dataExplorerLink": "https://cloud.mongodb.com/links/app_id/explorer/cluster_name/database/collection/find"
    }
    

    Note that these values will be updated by the script that links the Realm UI to each template app. The location of this file should make sense to your app (and its users) -- you just need to let the build trigger know where it is, which you do in the next step.

  3. Update the manifest.json file that lives in the root of this repo to add a new object to the manifest. Each object has this shape:

    "<my.project.id>": { <-- change to your unique ID
     "name": "The.Title.Of.My.App",
     "repo_owner": "mongodb-university", <-- don't change
     "repo_name": "realm-template-apps", <-- don't change
     "backend_path": "see the notes below",
     "client_path": "my-project-subdirectory-name",
     "metadata_path": "path-to-the-directory-that-contains-your-realm.json-file",
     "metadata_filename": "realm",
     "file_format": "json"
    },
    
    

    Each key in the manifest is the unique ID of the template. No spaces are allowed. Should ideally be somewhat typeable as users have the option of manually pulling templates via the realm-cli (i.e. realm-cli pull --template=some-template-id)

    • name: A friendly name. Presented in the UI or when listing available templates from the CLI.
    • repo_owner, repo_name: This repo's upstream. Just use mongodb-university and realm-template-apps respectively.
    • backend_path: The relative path from the root of this repo to the backend app to import when instantiating the template.
    • client_path: (optional). The relative path from the root of this repo to the client app source directory to be copied when instantiating the template.

    metadata_path, metadata_filename, and file_format are all required if client_path is set. When Realm instantiates the template, it adds the generated backend app ID (and base URL) to a file that the instantiated client then reads to know which backend app to use.

    • metadata_path: The relative path from the root of this repo to the directory where your client reads the Realm metadata file.
    • metadata_filename: The actual name of the Realm metadata file. Probably "Realm" or "realm".
    • file_format: One of "json", "xml", or "plist" -- whichever your client knows how to read. App Services produces a metadata file with the given file_format as file extension in the format specified.
  4. When you merge your branch, a Github action zips everything up and uploads to an S3 bucket. Upon the next reload of App Services (usually around release time but can be requested any time), App Services pulls the zip file down and makes the templates within available to the CLI.

    The product team decides which templates actually show up in the UI.

    In short: when you merge your changes to the repo, the UI will not expose this template immediately. You should be safe to work on this template at your leisure. However, people can create apps with this template via the cli soon after you merge.

Tips & Tricks

Many of the template source directories now follow this structure:

  • backend: The backend configuration.
  • client: The client(s) source code.
  • generated: Contains generated code. Don't edit this directly!
  • bluehawk.sh: Generally bluehawks whatever's in client/ and puts it in generated/. This keeps the client source clean when consumed by the backend or viewed on an artifact repo.
  • realm-template.{json|xml|plist}: Copied after bluehawking to the client(s) in the generated directory. This scrubs the app ID used in development.

realm-template-apps's People

Contributors

andrewzlchen avatar blagoev avatar cbullinger avatar cbush avatar dacharyc avatar desistefanova avatar ejm01 avatar jandersongo avatar jenniferpeshansky avatar krollins-mdb avatar malexandert avatar mongocaleb avatar mongodben avatar nathan-contino-mongo avatar nlarew avatar papafe avatar sudssm avatar takameyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

realm-template-apps's Issues

Android todo app doesn't sync and crashes when pressing subscription button

Hello, I was following tutorial for Kotlin todo app, but having some major issues.
I run the app on hardware device. On login screen, I pressed 'create new account', after providing details and registering, screen goes black. In logcat I see that registration and login were successful, but there an ANR. (I tried the same on the emulator, it also resulted in ANR).
After this I reopen the app, luckily I'm already signed in. I can see todo app UI. I've added several items. Next, as tutorial suggests, I go to Atlas website to 'browse collections' - it's empty. In the android app, if I press button with wifi icon (I assume it's sync?), the app instantly crashes with:

Process: com.mongodb.app, PID: 17568
java.lang.NullPointerException
at io.realm.kotlin.mongodb.internal.SubscriptionSetImpl.waitForSynchronization-VtjQ1oo(SubscriptionSetImpl.kt:126)
at io.realm.kotlin.mongodb.internal.SubscriptionSetImpl$waitForSynchronization$1.invokeSuspend(Unknown Source:16)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@4954412, Dispatchers.Main]

On the website, in App Services section I can see some activity - there is 1 user and some requests. My app id in atlasConfig.xml seems to be correct

`flutter run macos` fails to build on M1

Error appears on this line of the app bar component:

class TodoAppBar extends StatelessWidget with PreferredSizeWidget {

image

flutter run full output:

Launching lib/main.dart on macOS in debug mode...
2023-06-13 18:47:42.616 xcodebuild[6282:571776] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-0014518C3E91801E }
{ platform:macOS, arch:x86_64, id:00006000-0014518C3E91801E }
lib/components/app_bar.dart:8:47: Error: The class 'PreferredSizeWidget' can't be used as a mixin because it isn't a mixin class nor a mixin.
class TodoAppBar extends StatelessWidget with PreferredSizeWidget {
                                              ^
Target kernel_snapshot failed: Exception

Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase '[CP-User] Download Realm Flutter iOS Binaries' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'realm' from project 'Pods')
warning: Run script build phase '[CP-User] Report Metrics' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'realm' from project 'Pods')
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

Building macOS application...                                           
Exception: Build process failed

the dart linter is also reporting the same error on the same line.

Where is the getUserItems defined?

I am trying to figure out how the flexible sync works, and when I am looking at this code:

Realm initRealm(User currentUser) {
  Configuration config = Configuration.flexibleSync(currentUser, [Item.schema]);
  Realm realm = Realm(
    config,
  );
  final userItemSub = realm.subscriptions.findByName('getUserItems');
  if (userItemSub == null) {
    realm.subscriptions.update((mutableSubscriptions) {
      // server-side rules ensure user only downloads own items
      mutableSubscriptions.add(realm.all<Item>(), name: 'getUserItems');
    });
  }
  return realm;
}

I am wondering, where is the getUserItems is defined? I can't find in the codebase: the https://github.com/mongodb/template-app-dart-flutter-todo.git

Errors with repo: missing path-browserify,hermes realm init error whenever @realm/react Providers are used

Errors with repo:

  • missing path-browserify (easy fix)
  • hermes realm init error whenever @realm/react Providers are used (hard fix)
  • warning " > @rneui/[email protected]" has incorrect peer dependency "@rneui/[email protected]" (easy fix)

Steps to reproduce:

error: Error: Unable to resolve module path-browserify from /home/user/Application-0/frontend/react-native.todo.flex/node_modules/realm/dist/platform/react-native/fs.js: path-browserify could not be found within the project or in these directories:
  node_modules/realm/node_modules
  node_modules
  ../../../../../node_modules
  18 | //
  19 | ////////////////////////////////////////////////////////////////////////////
> 20 | const path_browserify_1 = require("path-browserify");
     |                                    ^
  21 | const file_system_1 = require("../file-system");
  22 | const debug_1 = require("../../debug");
  23 | const binding_1 = require("../binding");
    at ModuleResolver.resolveDependency (/home/user/Application-0/frontend/react-native.todo.flex/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:139:15)


warning " > @rneui/[email protected]" has incorrect peer dependency "@rneui/[email protected]".



 LOG  Running "SyncTutorial" with {"rootTag":11}
 ERROR  Error: Getting '$$typeof' from binding before it was injected, js engine: hermes 
    at loadModuleImplementation (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:328:14)
    at RCTView
    at View (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:59473:43)
    at RCTView
    at View (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:59473:43)
    at AppContainer (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:59317:36)
    at SyncTutorial(RootComponent) (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:107957:28)
 ERROR  Error: Getting '$$typeof' from binding before it was injected, js engine: hermes 
    at beginWork (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:93271:49)
    at RCTView
    at View (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:59473:43)
    at RCTView
    at View (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:59473:43)
    at AppContainer (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:59317:36)
    at SyncTutorial(RootComponent) (http://localhost:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true:107957:28)
 ERROR  TypeError: Cannot read property 'AppProvider' of undefined

This error is located at:
    in AppWrapper
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in SyncTutorial(RootComponent), js engine: hermes
 ERROR  TypeError: Cannot read property 'AppProvider' of undefined

This error is located at:
    in AppWrapper
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in SyncTutorial(RootComponent), js engine: hermes

Call To Function is not passing the arguments

Hello team. Not sure if this is the right channel. But I was working on a presentation and using the template tiered from our docs, I realise there was something wrong.

So, inspecting further, I've seen that the call to function joinTeam is doing

const adminFuncArgs = [admin.id, "greenTeam", true /* make admin */];
const adminFuncResult = await admin.callFunction("joinTeam", adminFuncArgs);

The arguments are passed in an Array. The App Services function is defined as exports = async function (userId, teamName, isAdmin = false) and the problem is that all the arguments are stored in userId instead of being spread.

Therefore userId = [admin.id, "greenTeam", true] and teamName = undefined. So the $set is not working as expected as the filter will never work

The fix is pretty simple, just by editing two lines as follows:

const adminFuncResult = await admin.callFunction("joinTeam", admin.id, "greenTeam", true);
const funcResult = await member.callFunction("joinTeam", member.id, "greenTeam", false);

Android With Kotlin Tutorial

I have followed the Android With Kotlin Tutorial but when I download the zip containing the front end code it is empty. As a result I used the CLI (appservices pull) but I cannot get the app to function correctly and I am not sure if this is an issue with the template or configuration that I have missed while following the tutorial.

On the Android device I can login successfully and get the following in the logcat
LoginEvent com.mongodb.app I User logged in successfully.

but then I am presented with a black screen and the logcat repeatedly outputs

REALM com.mongodb.app W [Core] Reading failed: End of input

What am I missing?

React Native todo app get stuck on npm and crashes when built on Mac

I'm trying to follow the tutorial here, but every time I run the sample app it crashes immediately.
https://www.mongodb.com/docs/atlas/app-services/tutorial/react-native/

Here's what I'm running:

realm-cli pull --remote [name of my app in atlas] --template react-native.todo.flex
cd TutorialApp/frontend/react-native.todo.flex
npm install

This will get stuck on reifying realm. So I blow away node_modules and packages-lock.json and run yarn instead.

rm -rf node_modules package-lock.json
yarn
npx pod-install
npx react-native run-ios

It takes a long time, but eventually tries to run the app. When it does, the app simply crashes with a BAD_ACCESS error. This is really weird because I'm able to build and run other React Native apps.

What gives? Am I doing something wrong here?

More details:
Mac OS X Ventura 13.4
XCode 14.3.1
2020 Intel MacBook Pro

EMpty template app

When I download the template app it's empty - and I want to download because of the link
Screenshot 2023-11-19 052921
Screenshot 2023-11-19 052914
Screenshot 2023-11-19 052900
Screenshot 2023-11-19 052848

Realm Prop load error

When running the code through the android simulator, it errors out when initializing the RealmProvider. I get the following errors:

BUNDLE ./index.js

LOG View your data in MongoDB Atlas: https://cloud.mongodb.com/links/<...>/explorer/Cluster0/database/collection/find.
ERROR Error: Exception in HostObject::get for prop 'Realm': java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealm.so caused by: dlopen failed: cannot locate symbol "__emutls_get_address" referenced by "/data/app/~~UrHcuOA1X7s9x-M8jCfU4g==/com.synctutorial-q5oSJsHgqnnBeIlJ_Vt4TQ==/lib/x86_64/librealm.so"... result: 0, js engine: hermes
ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Flutter - atlasUrl is missing in config

Atlas url is used in project but is missing in config

class Config extends ChangeNotifier {
  late String appId;
  late String? atlasUrl;
  late Uri baseUrl;

  Config._create(dynamic realmConfig) {
    appId = realmConfig['appId'];
    atlasUrl = realmConfig['dataExplorerLink'];
    baseUrl = Uri.parse(realmConfig['baseUrl']);
  }

  static Future<Config> getConfig(String jsonConfigPath) async {
    dynamic realmConfig =
        json.decode(await rootBundle.loadString(jsonConfigPath));

    var config = Config._create(realmConfig);

    return config;
  }
}

SwiftUI template app unable to maintain connection with flexible sync

The SwiftUI template todo app is unable to maintain a connection with MongoDB. The app itself works just fine, but it is unable to sync. The steps I'm taking are:

  1. Create a new app and download zip file from Atlas App Services
  2. Ensure appId and appUrl are correct in atlasConfig.plist
  3. Build and launch app on iPhone 14 Pro simulator
  4. Create a user via app and log in to the app
  5. Create todo items

I can see the created user in App Services, but no todos are ever synced. Opening the app on a different simulator confirms that there is no syncing happening. The following is output when the app launches and attempts to connect to flexible sync (I've removed some identifying info from these logs):

Sync: Realm sync client ([realm-core-13.10.1])
Sync: Connection[1]: Session[1]: Binding '[obfuscatedpath]/flx_sync_default.realm' to ''
Sync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, client reset = false
Sync: Connected to endpoint 'x.xx.xxx.xx:xxx' (from 'xxx.xxx.x.xx:xxxxx')
Sync: Connection[1]: Closing the websocket with status='SystemError: invalid certificate chain', was_clean='false'
Sync: Connection[1]: Connection closed due to error

The react-native template pulled from realm platform does not initiate correctly with xcode 69.5

The app is correctly built, but when it is initiated, appears the next error on the simulator:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: Unable to resolve module ./index from /Users/user1/apps/learning-fm/MyRealmApp/.: <br><br>None of these files exist:<br> &nbsp;* index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)<br> &nbsp;* index/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)<br> &nbsp; &nbsp;at ModuleResolver.resolveDependency (/Users/user1/apps/learning-fm/MyRealmApp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:136:15)<br> &nbsp; &nbsp;at DependencyGraph.resolveDependency (/Users/user1/apps/learning-fm/MyRealmApp/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)<br> &nbsp; &nbsp;at /Users/user1/apps/learning-fm/MyRealmApp/node_modules/metro/src/lib/transformHelpers.js:129:24<br> &nbsp; &nbsp;at Server._resolveRelativePath (/Users/user1/apps/learning-fm/MyRealmApp/node_modules/metro/src/Server.js:1137:12)<br> &nbsp; &nbsp;at async Server.requestProcessor [as _processBundleRequest] (/Users/user1/apps/learning-fm/MyRealmApp/node_modules/metro/src/Server.js:464:37)<br> &nbsp; &nbsp;at async Server._processRequest (/Users/user1/apps/learning-fm/MyRealmApp/node_modules/metro/src/Server.js:420:9)</pre>
</body>
</html>


RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start_sim
0x0

I execute the npx react-native init command from the app main folder, the one which contains app.json, realm.json, ios and android folders, etc...

What am I supposed to do different?

Thank a lot in advance!

Screenshot 2022-08-27 at 16 18 41

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.