extension-data-viewer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseData Viewer
数据查看器
Admin-only data inspection extension for Caffeine AI.
专为Caffeine AI打造的仅管理员可用的数据检查扩展。
Overview
概述
Every Caffeine app ships with the mops package and the moc flag enabled. Together with in the actor, the compiler auto-exposes a controller-only query for every stable variable of a supported type:
caffeineai-data-viewer--generate-view-queriesinclude MixinViews()__<var>- —
Map.Map<K, V>(?K, ?Nat) -> [(K, V)] - —
Set.Set<K>(?K, ?Nat) -> [K] - ,
[V],[var V],List.List<V>,Stack.Stack<V>—Queue.Queue<V>(?Nat, ?Nat) -> [V]
A cursor starts at the beginning; a count returns everything from the cursor. Each generated query traps on any non-controller caller — they exist for admin dashboards and debug viewers, not user-facing endpoints.
nullnull每个Caffeine应用都预装了 mops包,并启用了moc的标志。结合actor中的,编译器会为每个支持类型的稳定变量自动暴露一个仅控制器可用的查询方法:
caffeineai-data-viewer--generate-view-queriesinclude MixinViews()__<var>- —
Map.Map<K, V>(?K, ?Nat) -> [(K, V)] - —
Set.Set<K>(?K, ?Nat) -> [K] - ,
[V],[var V],List.List<V>,Stack.Stack<V>—Queue.Queue<V>(?Nat, ?Nat) -> [V]
nullnullBackend
后端实现
The package and are already wired into the template. You don't need to add or edit anything for the viewer to work — declare a stable variable of a supported type and the query appears automatically.
include__<var>motoko
import Map "mo:core/Map";
import Principal "mo:core/Principal";
import MixinViews "mo:caffeineai-data-viewer/MixinViews";
actor {
include MixinViews();
let users = Map.empty<Principal, Text>();
// Generated automatically: __users : (ko : ?Principal, count : ?Nat) -> [(Principal, Text)] query
};Lintoko rule (shipped with the package) errors if the actor body is missing . Keep the include — removing it disables every auto-generated viewer.
include-mixin-viewsinclude MixinViews();该包和语句已集成到模板中。要让查看器正常工作,您无需添加或编辑任何内容——只需声明一个支持类型的稳定变量,查询方法就会自动生成。
include__<var>motoko
import Map "mo:core/Map";
import Principal "mo:core/Principal";
import MixinViews "mo:caffeineai-data-viewer/MixinViews";
actor {
include MixinViews();
let users = Map.empty<Principal, Text>();
// Generated automatically: __users : (ko : ?Principal, count : ?Nat) -> [(Principal, Text)] query
};随包提供的Lintoko规则会在actor体中缺少时抛出错误。请保留该include语句——移除它会禁用所有自动生成的查看器。
include-mixin-viewsinclude MixinViews();Rules
使用规则
- NEVER use the generated queries as a substitute for user-facing endpoints — they trap for any non-controller caller. Public list/feed/search methods still need to be written normally with
__<var>.public query func listX(...) - NEVER declare an actor member whose name starts with — it either collides with an auto-generated query or hits a reserved prefix.
__ - Pure (immutable) collections (,
pure/Map,pure/Set,pure/List) are not supported. The viewer is mutable-only by design; pure collection field access is a deprecated pattern in Caffeine projects anyway.pure/Queue
- 切勿将生成的查询方法用作面向用户端点的替代方案——它们会对非控制器调用者触发陷阱。公共列表/信息流/搜索方法仍需通过
__<var>正常编写。public query func listX(...) - 切勿声明名称以开头的actor成员——这要么会与自动生成的查询方法冲突,要么会使用保留前缀。
__ - 纯(不可变)集合(、
pure/Map、pure/Set、pure/List)不受支持。查看器设计为仅支持可变集合;在Caffeine项目中,纯集合字段访问已是过时的模式。pure/Queue