mirror of
https://github.com/hanzo-apps/cms.git
synced 2026-10-30 14:47:33 +00:00
Complete de-brand of the fork the org owns (unpublished, empty DB — so no external consumers and no data migration). 1308 files. Applied Payload→CMS / payload→cms / PAYLOAD→CMS to: type/identifier names (PayloadRequest→CMSRequest, getPayload→getCMS, BasePayload→BaseCMS, the request property req.payload→req.cms, PayloadComponent→ CMSComponent, usePayloadAPI→useCMSAPI, …); collection/DB slugs (payload-jobs→cms-jobs, payload-kv, payload-migrations, payload-preferences, payload-locked-documents); env vars (PAYLOAD_*→CMS_*); i18n key + values (payloadSettings→cmsSettings, 'Payload Settings'→'CMS Settings' across 44 languages); CSS @layer/classes; comments/docs/UI. PRESERVED (deliberate — renaming breaks resolution or law): - MIT LICENSE + 'Copyright (c) 2018-2025 Payload CMS, Inc.' (legal attribution) - every import/require/export specifier + path literal; on-disk filenames (payload.config.ts, payload-types.ts) + the packages/payload dir; @payload-config alias - package.json "name" fields (already @hanzo/cms*) - URLs (payloadcms.com); Redux action.payload (a different, unrelated field) CONSISTENCY VERIFIED repo-wide: req.payload=0, from 'payload'=0, payloadSettings=0 (all now cms*), Redux action.payload intact, license intact. Individual files transpile clean. NOT YET VERIFIED: full type-compilation — requires a 44-package monorepo build (node_modules absent). Green build is the gate before publish; not claimed here. Co-authored-by: Hanzo Dev <[email protected]>
269 lines
6.8 KiB
TypeScript
269 lines
6.8 KiB
TypeScript
import type { DrizzleAdapter, Operators } from '@hanzo/cms-drizzle'
|
|
import type { DatabaseAdapterObj, CMS } from '@hanzo/cms'
|
|
|
|
import {
|
|
beginTransaction,
|
|
buildCreateMigration,
|
|
commitTransaction,
|
|
count,
|
|
countGlobalVersions,
|
|
countVersions,
|
|
create,
|
|
createBlocksToJsonMigrator,
|
|
createGlobal,
|
|
createGlobalVersion,
|
|
createSchemaGenerator,
|
|
createVersion,
|
|
deleteMany,
|
|
deleteOne,
|
|
deleteVersions,
|
|
destroy,
|
|
find,
|
|
findDistinct,
|
|
findGlobal,
|
|
findGlobalVersions,
|
|
findOne,
|
|
findVersions,
|
|
migrate,
|
|
migrateDown,
|
|
migrateFresh,
|
|
migrateRefresh,
|
|
migrateReset,
|
|
migrateStatus,
|
|
operatorMap,
|
|
queryDrafts,
|
|
rollbackTransaction,
|
|
updateGlobal,
|
|
updateGlobalVersion,
|
|
updateJobs,
|
|
updateMany,
|
|
updateOne,
|
|
updateVersion,
|
|
upsert,
|
|
} from '@hanzo/cms-drizzle'
|
|
import {
|
|
columnToCodeConverter,
|
|
convertPathToJSONTraversal,
|
|
countDistinct,
|
|
createJSONQuery,
|
|
defaultDrizzleSnapshot,
|
|
deleteWhere,
|
|
dropDatabase,
|
|
execute,
|
|
init,
|
|
insert,
|
|
requireDrizzleKit,
|
|
} from '@hanzo/cms-drizzle/sqlite'
|
|
import { like, notLike } from 'drizzle-orm'
|
|
import { createDatabaseAdapter, defaultBeginTransaction, findMigrationDir } from '@hanzo/cms'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import type { Args, SQLiteAdapter, WalConfig } from './types.js'
|
|
|
|
import { connect } from './connect.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
|
|
export function sqliteAdapter(args: Args): DatabaseAdapterObj<SQLiteAdapter> {
|
|
const sqliteIDType = args.idType || 'number'
|
|
const cmsIDType = sqliteIDType === 'uuid' || sqliteIDType === 'uuidv7' ? 'text' : 'number'
|
|
const allowIDOnCreate = args.allowIDOnCreate ?? false
|
|
|
|
function adapter({ cms }: { cms: CMS }) {
|
|
const migrationDir = findMigrationDir(args.migrationDir)
|
|
let resolveInitializing: () => void = () => {}
|
|
let rejectInitializing: () => void = () => {}
|
|
|
|
const initializing = new Promise<void>((res, rej) => {
|
|
resolveInitializing = res
|
|
rejectInitializing = rej
|
|
})
|
|
|
|
// sqlite's like operator is case-insensitive, so we overwrite the DrizzleAdapter operators to not use ilike
|
|
const operators = {
|
|
...operatorMap,
|
|
contains: like,
|
|
like,
|
|
not_like: notLike,
|
|
} as unknown as Operators
|
|
|
|
let wal: false | WalConfig = false
|
|
|
|
const defaultJournalSizeLimit = 67108864 // 64MB
|
|
|
|
if (args.wal && !args.client.url.startsWith('file:')) {
|
|
cms.logger.warn(
|
|
'[db-sqlite] WAL mode is not supported for in-memory or TCP database connections. Disabling WAL.',
|
|
)
|
|
args.wal = false
|
|
}
|
|
|
|
if (!args.wal) {
|
|
wal = false
|
|
} else if (args.wal === true) {
|
|
wal = { journalSizeLimit: defaultJournalSizeLimit, synchronous: 'FULL' }
|
|
} else {
|
|
wal = {
|
|
journalSizeLimit: args.wal.journalSizeLimit ?? defaultJournalSizeLimit,
|
|
synchronous: args.wal.synchronous ?? 'FULL',
|
|
}
|
|
}
|
|
|
|
const executeMethod = 'run'
|
|
const sanitizeStatements = ({
|
|
sqlExecute,
|
|
statements,
|
|
}: {
|
|
sqlExecute: string
|
|
statements: string[]
|
|
}) => {
|
|
return statements
|
|
.map((statement) => `${sqlExecute}${statement?.replaceAll('`', '\\`')}\`)`)
|
|
.join('\n')
|
|
}
|
|
|
|
const adapter = createDatabaseAdapter<SQLiteAdapter>({
|
|
name: 'sqlite',
|
|
afterSchemaInit: args.afterSchemaInit ?? [],
|
|
allowIDOnCreate,
|
|
autoIncrement: args.autoIncrement ?? false,
|
|
beforeSchemaInit: args.beforeSchemaInit ?? [],
|
|
blocksAsJSON: args.blocksAsJSON ?? false,
|
|
busyTimeout: args.busyTimeout ?? 0,
|
|
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
client: undefined,
|
|
clientConfig: args.client,
|
|
defaultDrizzleSnapshot,
|
|
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
drizzle: undefined,
|
|
features: {
|
|
json: true,
|
|
},
|
|
fieldConstraints: {},
|
|
findDistinct,
|
|
generateSchema: createSchemaGenerator({
|
|
columnToCodeConverter,
|
|
corePackageSuffix: 'sqlite-core',
|
|
defaultOutputFile: args.generateSchemaOutputFile,
|
|
tableImport: 'sqliteTable',
|
|
}),
|
|
idType: sqliteIDType,
|
|
initializing,
|
|
localesSuffix: args.localesSuffix || '_locales',
|
|
logger: args.logger,
|
|
operators,
|
|
prodMigrations: args.prodMigrations,
|
|
wal,
|
|
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
push: args.push,
|
|
rawRelations: {},
|
|
rawTables: {},
|
|
relations: {},
|
|
relationshipsSuffix: args.relationshipsSuffix || '_rels',
|
|
schema: {},
|
|
schemaName: args.schemaName,
|
|
sessions: {},
|
|
tableNameMap: new Map<string, string>(),
|
|
tables: {},
|
|
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
transactionOptions: args.transactionOptions || undefined,
|
|
updateJobs,
|
|
updateMany,
|
|
versionsSuffix: args.versionsSuffix || '_v',
|
|
// DatabaseAdapter
|
|
beginTransaction: args.transactionOptions ? beginTransaction : defaultBeginTransaction(),
|
|
commitTransaction,
|
|
connect,
|
|
convertPathToJSONTraversal,
|
|
count,
|
|
countDistinct,
|
|
countGlobalVersions,
|
|
countVersions,
|
|
create,
|
|
createGlobal,
|
|
createGlobalVersion,
|
|
createJSONQuery,
|
|
createMigration: buildCreateMigration({
|
|
executeMethod,
|
|
filename,
|
|
sanitizeStatements,
|
|
}),
|
|
createVersion,
|
|
defaultIDType: cmsIDType,
|
|
deleteMany,
|
|
deleteOne,
|
|
deleteVersions,
|
|
deleteWhere,
|
|
destroy,
|
|
dropDatabase,
|
|
execute,
|
|
find,
|
|
findGlobal,
|
|
findGlobalVersions,
|
|
findOne,
|
|
findVersions,
|
|
foreignKeys: new Set(),
|
|
indexes: new Set<string>(),
|
|
init,
|
|
insert,
|
|
migrate,
|
|
migrateDown,
|
|
migrateFresh,
|
|
migrateRefresh,
|
|
migrateReset,
|
|
migrateStatus,
|
|
migrationDir,
|
|
packageName: '@hanzo/cms-db-sqlite',
|
|
cms,
|
|
queryDrafts,
|
|
rejectInitializing,
|
|
requireDrizzleKit,
|
|
resolveInitializing,
|
|
rollbackTransaction,
|
|
updateGlobal,
|
|
updateGlobalVersion,
|
|
updateOne,
|
|
updateVersion,
|
|
upsert,
|
|
})
|
|
|
|
adapter.blocksToJsonMigrator = createBlocksToJsonMigrator({
|
|
adapter: adapter as unknown as DrizzleAdapter,
|
|
executeMethod,
|
|
sanitizeStatements,
|
|
})
|
|
|
|
return adapter
|
|
}
|
|
|
|
return {
|
|
name: 'sqlite',
|
|
allowIDOnCreate,
|
|
defaultIDType: cmsIDType,
|
|
init: adapter,
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @todo deprecate /types subpath export in 4.0
|
|
*/
|
|
export type {
|
|
Args as SQLiteAdapterArgs,
|
|
CountDistinct,
|
|
DeleteWhere,
|
|
DropDatabase,
|
|
Execute,
|
|
GeneratedDatabaseSchema,
|
|
GenericColumns,
|
|
GenericRelation,
|
|
GenericTable,
|
|
IDType,
|
|
Insert,
|
|
MigrateDownArgs,
|
|
MigrateUpArgs,
|
|
SQLiteAdapter,
|
|
SQLiteSchemaHook,
|
|
} from './types.js'
|
|
|
|
export { sql } from 'drizzle-orm'
|