extension-data-viewer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Data Viewer

数据查看器

Admin-only data inspection extension for Caffeine AI.
专为Caffeine AI打造的仅管理员可用的数据检查扩展。

Overview

概述

Every Caffeine app ships with the
caffeineai-data-viewer
mops package and the moc
--generate-view-queries
flag enabled. Together with
include MixinViews()
in the actor, the compiler auto-exposes a controller-only
__<var>
query
for every stable variable of a supported type:
  • 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
null
cursor starts at the beginning; a
null
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.
每个Caffeine应用都预装了
caffeineai-data-viewer
mops包,并启用了moc的
--generate-view-queries
标志。结合actor中的
include 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]
null
游标表示从开头开始;
null
计数表示返回游标之后的所有内容。每个生成的查询方法会对非控制器调用者触发陷阱——这些方法仅用于管理员仪表板和调试查看器,而非面向用户的端点。

Backend

后端实现

The package and
include
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
__<var>
query appears automatically.
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
include-mixin-views
(shipped with the package) errors if the actor body is missing
include MixinViews();
. Keep the include — removing it disables every auto-generated viewer.
该包和
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规则
include-mixin-views
会在actor体中缺少
include MixinViews();
时抛出错误。请保留该include语句——移除它会禁用所有自动生成的查看器。

Rules

使用规则

  • NEVER use the generated
    __<var>
    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
    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
    ,
    pure/Queue
    ) are not supported. The viewer is mutable-only by design; pure collection field access is a deprecated pattern in Caffeine projects anyway.
  • 切勿将生成的
    __<var>
    查询方法用作面向用户端点的替代方案——它们会对非控制器调用者触发陷阱。公共列表/信息流/搜索方法仍需通过
    public query func listX(...)
    正常编写。
  • 切勿声明名称以
    __
    开头的actor成员——这要么会与自动生成的查询方法冲突,要么会使用保留前缀。
  • 纯(不可变)集合(
    pure/Map
    pure/Set
    pure/List
    pure/Queue
    不受支持。查看器设计为仅支持可变集合;在Caffeine项目中,纯集合字段访问已是过时的模式。