{"version":3,"file":"schema.cjs","names":["entityKind","cockroachTableWithSchema","EnableRLS","cockroachViewWithSchema","cockroachMaterializedViewWithSchema","cockroachEnumWithSchema","cockroachEnumObjectWithSchema","cockroachSequenceWithSchema","SQL","sql"],"sources":["../../src/cockroach-core/schema.ts"],"sourcesContent":["import type { Casing } from '~/casing.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { NonArray, Writable } from '~/utils.ts';\nimport {\n\ttype CockroachEnum,\n\ttype CockroachEnumObject,\n\tcockroachEnumObjectWithSchema,\n\tcockroachEnumWithSchema,\n} from './columns/enum.ts';\nimport { type cockroachSequence, cockroachSequenceWithSchema } from './sequence.ts';\nimport { type CockroachTableFn, type CockroachTableFnInternal, cockroachTableWithSchema, EnableRLS } from './table.ts';\nimport {\n\ttype cockroachMaterializedView,\n\tcockroachMaterializedViewWithSchema,\n\ttype cockroachView,\n\tcockroachViewWithSchema,\n} from './view.ts';\n\nexport class CockroachSchema<TName extends string = string> implements SQLWrapper {\n\tstatic readonly [entityKind]: string = 'CockroachSchema';\n\n\tisExisting: boolean = false;\n\tconstructor(\n\t\tpublic readonly schemaName: TName,\n\t\tprotected casing: Casing | undefined,\n\t) {\n\t\tthis.table = Object.assign(this.table, {\n\t\t\twithRLS: ((name, columns, extraConfig) => {\n\t\t\t\tconst table = cockroachTableWithSchema(name, columns, extraConfig, this.schemaName, this.casing);\n\t\t\t\ttable[EnableRLS] = true;\n\n\t\t\t\treturn table;\n\t\t\t}) as CockroachTableFnInternal<TName>,\n\t\t});\n\t}\n\n\ttable: CockroachTableFn<TName> = ((name, columns, extraConfig) => {\n\t\treturn cockroachTableWithSchema(name, columns, extraConfig, this.schemaName, this.casing);\n\t}) as CockroachTableFn<TName>;\n\n\tview = ((name, columns) => {\n\t\treturn cockroachViewWithSchema(name, columns, this.schemaName, this.casing);\n\t}) as typeof cockroachView;\n\n\tmaterializedView = ((name, columns) => {\n\t\treturn cockroachMaterializedViewWithSchema(name, columns, this.schemaName, this.casing);\n\t}) as typeof cockroachMaterializedView;\n\n\tpublic enum<U extends string, T extends Readonly<[U, ...U[]]>>(\n\t\tenumName: string,\n\t\tvalues: T | Writable<T>,\n\t): CockroachEnum<Writable<T>>;\n\n\tpublic enum<E extends Record<string, string>>(\n\t\tenumName: string,\n\t\tenumObj: NonArray<E>,\n\t): CockroachEnumObject<E>;\n\n\tpublic enum(enumName: any, input: any): any {\n\t\treturn Array.isArray(input)\n\t\t\t? cockroachEnumWithSchema(\n\t\t\t\tenumName,\n\t\t\t\t[...input] as [string, ...string[]],\n\t\t\t\tthis.schemaName,\n\t\t\t)\n\t\t\t: cockroachEnumObjectWithSchema(enumName, input, this.schemaName);\n\t}\n\n\tsequence: typeof cockroachSequence = ((name, options) => {\n\t\treturn cockroachSequenceWithSchema(name, options, this.schemaName);\n\t});\n\n\tgetSQL(): SQL {\n\t\treturn new SQL([sql.identifier(this.schemaName)]);\n\t}\n\n\tshouldOmitSQLParens(): boolean {\n\t\treturn true;\n\t}\n\n\texisting(): this {\n\t\tthis.isExisting = true;\n\t\treturn this;\n\t}\n}\n\nexport function isCockroachSchema(obj: unknown): obj is CockroachSchema {\n\treturn is(obj, CockroachSchema);\n}\n\nexport function cockroachSchema<T extends string>(name: T): CockroachSchema<T>;\n/** @internal */\nexport function cockroachSchema<T extends string>(name: T, casing?: Casing): CockroachSchema<T>;\n/** @internal */\nexport function cockroachSchema<T extends string>(name: T, casing?: Casing): CockroachSchema<T> {\n\tif (name === 'public') {\n\t\tthrow new Error(\n\t\t\t`You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use cockroachTable() instead of creating a schema`,\n\t\t);\n\t}\n\n\treturn new CockroachSchema(name, casing);\n}\n"],"mappings":";;;;;;;;;;AAmBA,IAAa,kBAAb,MAAkF;CACjF,QAAiBA,0BAAsB;CAEvC,aAAsB;CACtB,YACC,AAAgB,YAChB,AAAU,QACT;EAFe;EACN;AAE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