后端只需定义架构、访问策略和函数。

3作者: emilss大约 1 个月前原帖
你会使用一个只需定义模式、访问策略和函数的后端吗?<p>基本上就像在EVM上创建智能合约,但它们运行在一个超大规模云平台上,并具备常规后端的基本功能。<p>这是我想的一个模拟示例:<p>模式 User { email: 字符串 @私有(所有者) name: 字符串 @公开 balance: 数字 @私有(所有者, 管理员) }<p>策略 { User.read: 所有者 或 角色("管理员") User.update.balance: 角色("管理员") }<p>函数 transfer(from: User, to: User, amount: 数字) { assert(caller == from.owner 或 caller.role == "管理员") assert(from.balance >= amount) from.balance -= amount to.balance += amount }<p>我在玩OpenFGA和AWS Lambda的东西,这让我想到这个。<p>所以你会在一个超大规模云平台上“部署”这个合约,然后让用户通过你简洁的JavaScript前端访问它,方式如下:<p>const res = await fetch("https://api.hyperscaler-example.com/c/your-contract-id/transfer", { method: "POST", headers: { "Authorization": "Bearer <user-jwt>", "Content-Type": "application/json" }, body: JSON.stringify({ from: "user_abc", to: "user_xyz", amount: 50 }) });<p>运行时从JWT中解析调用者身份,检查策略规则,运行函数,处理字段的加密/解密,因此你的前端根本不接触这些。<p>就这样,你会使用它吗?有没有什么东西已经完全实现了这个功能?我有点想要构建这个。
查看原文
Would you use a backend where you just define schema, access policy, and functions?<p>Basically something like making smart contracts on EVM, but instead they run on a hyperscaler, and have regular backend fundamentals.<p>Here&#x27;s a mock frenchie made me, was thinking something like this:<p>schema User { email: string @private(owner) name: string @public balance: number @private(owner, admin) }<p>policy { User.read: owner OR role(&quot;admin&quot;) User.update.balance: role(&quot;admin&quot;) }<p>function transfer(from: User, to: User, amount: number) { assert(caller == from.owner OR caller.role == &quot;admin&quot;) assert(from.balance &gt;= amount) from.balance -= amount to.balance += amount }<p>Was playing with OpenFGA, and AWS Lambda stuff, and got me thinking about this.<p>So you would &quot;deploy&quot; this contract on a hyperscaler, which then let&#x27;s users access it from your lean js front-end, via something like this:<p>const res = await fetch(&quot;https:&#x2F;&#x2F;api.hyperscaler-example.com&#x2F;c&#x2F;your-contract-id&#x2F;transfer&quot;, { method: &quot;POST&quot;, headers: { &quot;Authorization&quot;: &quot;Bearer &lt;user-jwt&gt;&quot;, &quot;Content-Type&quot;: &quot;application&#x2F;json&quot; }, body: JSON.stringify({ from: &quot;user_abc&quot;, to: &quot;user_xyz&quot;, amount: 50 }) });<p>The runtime resolves the caller identity from the JWT, checks the policy rules, runs the function, handles the encryption&#x2F;decryption of fields and so your frontend never touches any of that.<p>That&#x27;s it, would you use it? Is there something that does this exactly already? Feeling like building this.