// `orders.place` — DESCRIPTOR (browser-safe: schema + target + typed // error only; NO node/database/server imports). // // `TenantMismatch` is imported from the `/guard` subpath, NOT the // package root — the root re-exports the schema mixin, which would drag // `@voltro/database` into the client rpcGroup bundle. `/guard` is the // browser-safe surface for the typed error you declare here. import { defineMutation } from '@voltro/protocol' import { TenantMismatch } from '@voltro/plugin-multitenancy/guard' import { Schema } from 'effect' export const placeOrder = defineMutation({ name: 'orders.place', // Open: writes an order carrying only what the caller sent, into the caller's // own tenant (`assertOwnTenant` rejects a mismatched `tenantId`), and touches // no existing row. No auth strategy and no rbac ship in this template, so // every caller resolves to an anonymous Subject with no scopes and a // `guards: [{ scope }]` would deny all of them. openAccess: 'inserts an order built only from caller-supplied fields into the caller\'s own tenant ' + '(`assertOwnTenant` rejects a mismatch); reads nothing and modifies no existing row. ' + 'No auth strategy ships here, so there is no identity a scope guard could name.', // Auto-optimistic: every query whose `source: 'orders'` matches gets a // placeholder row prepended; the server delta replaces it on commit. target: { table: 'orders', op: 'insert', shape: (input: { tenantId: string; customerName: string; amountCents: number }) => ({ status: 'placed', customerName: input.customerName, amountCents: input.amountCents, tenantId: input.tenantId, }), }, input: Schema.Struct({ tenantId: Schema.String, customerName: Schema.NonEmptyString, amountCents: Schema.Int.pipe(Schema.greaterThan(0)), }), output: Schema.Struct({ id: Schema.String, status: Schema.String, customerName: Schema.String, amountCents: Schema.Number, tenantId: Schema.String, }), error: TenantMismatch, })