Teta CMS

什么是 Teta CMS?

Teta CMS 是由Teta开发的一个低代码后端服务。我们提供:

  • 可扩展的 NoSQL 数据库
  • 具有套接字(sockets)的实时订阅
  • 用户身份验证系统和策略
  • 使用我们的Ayaya语言对集合执行自定义查询
  • 使用易于使用且响应迅速的用户界面

入门

要使用 Teta CMS,您需要先在Teta.so上创建一个项目。

初始化

要获取凭证,请转到Teta > 项目仪表板 > 入门。

自从调用了.initialize 方法后,您就可以在应用程序的任何地方使用TetaCMS.instanceTetaCMS.I

import 'package:teta_cms/teta_cms.dart';

Future<void> main() {
  await TetaCMS.initialize(
    token: prjToken,
    prjId: prjId,
  );
  
  runApp(
    // Your app...
  );
}

数据库

从集合中获取文档

// Fetch all docs
final res = await TetaCMS.I.db.from('users').get();
if (res.error != null) {
  Logger.printError('Error fetching users, code: ${res.error?.code}, error: ${res.error?.message}');
} else {
  // Safe to use res.data ?
  return res.data;
}

过滤

// Fetch all docs, ordering and filtering
TetaCMS.I.db.from('users').get(
  limit: 10,
  page: 0,
  showDrafts: false,
  filters: [
    Filter(
      'Key',
      'Value',
      type: FilterType.like,
    ),
  ],
);

或者,您可以使用我们的TetaFutureBuilder。它通过防止不必要的调用来管理缓存。

TetaFutureBuilder(
  future: TetaCMS.I.db.from('posts').get(), 
  builder: (final context, final snap) {
    // build your widgets with snap.data as TetaResponse<T, TetaErrorResponse?>
  },
);

TetaFutureBuilder 支持任何 Future。您也可以用它来运行Ayaya查询。

查看其他示例.

实时

集合更改

TetaCMS.I.db.from('posts').on(
  // action: StreamAction.all,
  callback: (final e) {},
);

文档更改

TetaCMS.I.db.from('users').row(docId).on(
  callback: (final e) {},
);

流(Stream)更改

// Stream all docs, ordering and filtering
final sub = TetaCMS.I.db.from('chats').stream(
  limit: 10,
  page: 0,
  showDrafts: false,
  filters: [
    Filter(
      'Key',
      'Value',
      type: FilterType.like,
    ),
  ],
);

// Remember to close it when you're done
sub.close();

或者,您可以使用我们的TetaStreamBuilder。它通过防止不必要的调用来管理缓存,并在 dispose 事件时关闭流控制器。

TetaStreamBuilder(
  stream: TetaCMS.I.db.from('feed').stream(), 
  builder: (final context, final snap) {
    // build your widgets with snap.data as TetaResponse<T, TetaErrorResponse?>
  },
);

自定义查询

使用Ayaya语言进行查询

// Fetch all docs in `users` created less than a week, ordering by `created_at`
final res = await TetaCMS.I.db.query(
  r'''
    MATCH name EQ users;
    IN docs;
    MATCH created_at GT DATESUB($now $week);
    SORT created_at -1;
    LIMIT 20;
  ''', 
);

// Check if it returns an error
if (res.error != null) {
  Logger.printError('${res.error?.message}');
} else {
  // Safe to use res.data ?
  return res.data;
}

使用 Ayaya,您可以连接两个或多个集合

// Fetch all docs in `users` and `posts`
final response = await TetaCMS.I.db.query(
  '''
    MATCHOR name EQ users name EQ posts;
  ''', 
);

安全性:管理数据库策略

策略是安全规则。每个策略都链接到一个特定的集合,并且每次在查询/API中调用集合时都会执行每个策略。

本质上,它们是构成集合的每个查询的附加条件。


认证

社交身份验证

// Sign up user with Apple OAuth provider
TetaCMS.I.auth.signIn(
  provider: TetaProvider.apple,
  onSuccess: (final isFirstTime) async {
    // Success ?
  );
);

isFirstTime 标志告诉我们用户是否是首次登录,这对于我们只需要执行一次性操作非常有用。

检索当前用户

// Get the current user
final TetaUser user = await TetaCMS.I.auth.user.get;
if (user.isLogged) {
  // The user is logged ?
} else {
  // There is no current user
}

退出登录

await TetaCMS.I.auth.signOut();

Teta 身份验证配置

Teta CMS 的身份验证通过打开浏览器让人们使用不同的提供商登录来工作。这种方法使我们能够编写更少的代码。

要打开浏览器并在成功登录后返回应用程序,您需要在应用程序中配置深度链接(deeplink)。

设置您的重定向 URL

  • 转到app.teta.so > 项目仪表板 > 用户 > 配置。
  • 填写Redirect Url字段(例如,com.example.app://welcome,格式为SCHEME://HOSTNAME)。

Teta Auth redirect URL field

Teta 社交 OAuth 配置

请参阅我们关于以下 OAuth 提供商的文档。

Android

ActivityManifest.xml文件中声明您的重定向 URL。在此示例中,我们使用的值为com.example.app://welcome

<manifest ...>
  <application ...>
    <activity ...>
      <!-- ... -->

      <!-- Teta Auth Deeplink -->
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Your redirect URL -->
        <data
          android:scheme="com.example.app"
          android:host="welcome" />
      </intent-filter>
    </activity>
  </application>
</manifest>

Android 文档:https://developer.android.com.cn/training/app-links/deep-linking

iOS

ios/Runner/Info.plist文件中声明您的重定向 URL。在此示例中,我们使用的值为com.example.app://welcome

<plist>
<dict>
  <!-- Teta Auth Deeplink -->
  <key>CFBundleURLTypes</key>
  <array>
    <dict>
      <key>CFBundleTypeRole</key>
      <string>Editor</string>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>com.example.app</string>
      </array>
    </dict>
  </array>
  <!-- ... -->
</dict>
</plist>

Apple 文档:https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app

Web

Web 端无需进行任何设置。

Windows, macOS, Linux

桌面平台的身份验证即将推出。


兼容性

身份验证 数据库 Ayaya 实时 分析
Android
iOS
Web
macOS 即将推出
Windows 即将推出
Linux 即将推出

教程

每当发布新教程时,本部分都会更新。

文档

请参阅我们在teta.so/flutter-docs上的 Flutter 文档。


Teta CMS 仍处于开放测试阶段

  • 封闭测试;
  • 开放测试:我们仍可能引入一些重大更改;
  • 开放测试:可能存在 bug,但已准备好进行测试和副项目;
  • Beta:第一个稳定版本;
  • Teta:我们终于完全 Teta 了;

我们才刚刚开始,还有很长的路要走。

请告诉我们您的想法,感谢您的支持!

Reaction

GitHub

查看 Github