clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/prf-provision-custody
lofi / package / schema / mod.ts
mod.ts 4.1K
1/**2 * Declare application tables, permissions, and migrations without importing3 * Jazz directly.4 *5 * This module is a curated re-export of the pinned Jazz 2 schema DSL: the6 * same names and semantics, narrowed to the surface lofi documents and tests.7 * Author code imports {@link s} from here instead of `jazz-tools`, so version8 * bumps and upstream renames are absorbed by the package rather than by every9 * application schema.10 *11 * ```ts12 * import { s } from "@nzip/lofi/schema";13 *14 * export const app = s.defineApp({15 * tasks: s.table({16 * text: s.string(),17 * completed: s.boolean(),18 * createdAt: s.timestamp(),19 * }),20 * });21 * ```22 *23 * @module24 */25import { schema } from "jazz-tools";26import {27 defineNestedApp,28 defineNestedPermissions,29 flattenNestedSchema,30 mergeNestedPermissions,31} from "./nested.ts";3233/**34 * The curated schema DSL type. Every Jazz member is the pinned Jazz 235 * original, unchanged; deprecated members (`rename`) are omitted, and36 * everything else re-exports one-to-one. The nested-namespace members37 * (`defineNestedApp`, `defineNestedPermissions`, `mergeNestedPermissions`,38 * `flattenNestedSchema`) are lofi-owned: a naming layer over the pinned39 * `defineSliceableApp`, not part of the Jazz DSL.40 */41export type SchemaDsl =42 & Pick<43 typeof schema,44 // Column constructors.45 | "string"46 | "boolean"47 | "int"48 | "float"49 | "timestamp"50 | "bytes"51 | "json"52 | "enum"53 | "ref"54 | "array"55 // Column migration operations.56 | "add"57 | "drop"58 | "renameFrom"59 // Tables, schemas, and apps.60 | "table"61 | "defineSchema"62 | "defineApp"63 | "defineSliceableApp"64 // Schema migrations.65 | "defineMigration"66 | "renameTableFrom"67 // Permissions.68 | "definePermissions"69 | "permissionIntrospectionColumns"70 >71 & {72 defineNestedApp: typeof defineNestedApp;73 defineNestedPermissions: typeof defineNestedPermissions;74 mergeNestedPermissions: typeof mergeNestedPermissions;75 flattenNestedSchema: typeof flattenNestedSchema;76 };7778/**79 * The lofi schema surface. Use in `src/schema.ts` and `src/permissions.ts` in80 * place of a raw `jazz-tools` import; Jazz member names and behavior are81 * identical to the pinned Jazz 2 DSL, and the nested-namespace members are82 * the lofi naming layer documented on {@link defineNestedApp}.83 */84export const s: SchemaDsl = {85 ...schema,86 defineNestedApp,87 defineNestedPermissions,88 mergeNestedPermissions,89 flattenNestedSchema,90};9192export {93 defineNestedApp,94 defineNestedPermissions,95 flattenNestedSchema,96 mergeNestedPermissions,97 NESTED_SEPARATOR,98 type NestedApp,99 nestedAppDeployTarget,100 nestedAppTables,101 type NestedSchemaDefinition,102} from "./nested.ts";103104// Store provisioning (./store.ts) is deliberately NOT re-exported here: the105// Jazz schema loader bundles the author's schema module graph — this facade106// included — and executes it to derive the deployed schema, so this module107// must stay authoring-only. Import provisioning from "@nzip/lofi/schema/store".108109/**110 * Schema-authoring types re-exported from the pinned Jazz 2 DSL for use in111 * application signatures. Row types for UI code come from `@nzip/lofi`112 * (`RowOf`), not from this module.113 */114export type {115 App,116 DefinedTable,117 InsertOf,118 Schema,119 SchemaDefinition,120 TableDefinition,121 WhereOf,122} from "jazz-tools";123124/**125 * Column builder types re-exported for signatures and for the alpha.53126 * workaround below: calling `.merge()` or `.transform()` on a column loses127 * the typed builder (the legacy untyped signatures shadow the typed128 * overloads upstream), so cast the result back to the intended column type.129 * The runtime object is unchanged; only the declaration needs repair:130 *131 * ```ts132 * total: s.int().default(0).merge("counter") as unknown as IntColumn<false, true>,133 * tags: s.string().transform({134 * from: (value: string) => value.split(","),135 * to: (value: string[]) => value.join(","),136 * }) as unknown as StringColumn<false, false, string[]>,137 * ```138 */139export type {140 ArrayColumn,141 BooleanColumn,142 BytesColumn,143 EnumColumn,144 FloatColumn,145 IntColumn,146 JsonColumn,147 RefColumn,148 StringColumn,149 TimestampColumn,150} from "jazz-tools";