import { SchemaBase } from './dsl.js'; import type { TableSchema } from './db.js'; /** Frontend form factor. Closed enum, extend when new form factors appear. */ export type FrontType = 'admin' | 'wxmini' | 'mobile'; /** A frontend application (e.g. admin console, wechat mini program). */ export interface FrontAppSchema extends SchemaBase { type: FrontType; /** Source directory relative to project root, e.g. 'web-admin/'. */ dir: string; /** * Tenant table for this app. The tenant column of a business table is * deterministic: `{tenant.phrase}_{tenant.pk}` (e.g. shop with pk id → * `shop_id`). Tables carrying that column get automatic tenant scoping; * tables without it are global tables (e.g. system config) — both valid. */ tenant?: TableSchema; } /** A backend API service. apps references shared FrontAppSchema instances. */ export interface ProjectApiSchema extends SchemaBase { /** Source directory relative to project root, e.g. 'api/'. */ dir: string; /** Frontends this API serves. Direct instance references (see defineProject). */ apps: FrontAppSchema[]; /** API base URL prefix shared by all apps it serves, e.g. '/mall'. '' = no prefix. */ contextPath?: string; /** API service base URL for node clients, e.g. 'http://127.0.0.1:3000'. */ baseUrl?: string; } /** A third-party system (e.g. wechat pay, unionpay). Owns its own * implementation dir and contract (controller_types), just like an API, * but is not part of this repo's served surface. */ export interface ThirdApiSchema extends SchemaBase { /** Source directory relative to project root, e.g. 'wechat/'. */ dir: string; } export interface ProjectSchema extends SchemaBase { apps: FrontAppSchema[]; apis: ProjectApiSchema[]; thirdApis: ThirdApiSchema[]; } /** * Defines the project topology. FrontAppSchema instances are shared value objects: * api.apps references the same instances from project.apps, so an app served * by multiple APIs is defined once and referenced many times. * * Runtime-validates app type whitelist, unique names, api.apps reference * integrity (same style as defineTable/defineCurd), plus two naming * conventions: every app/api/thirdApi dir equals its name ('api/' == 'api'), * and the first api must be named exactly 'api' (prefixed names like * 'xx-api' are only allowed from the second api on). */ export declare function defineProject(name: string, schema: { description?: string; apps: FrontAppSchema[]; apis: ProjectApiSchema[]; thirdApis?: ThirdApiSchema[]; }): ProjectSchema;