betterstart-cli 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -7935,7 +7935,6 @@ function genTypesContent(ctx) {
7935
7935
  }
7936
7936
  const parts = [
7937
7937
  ctx.dataInterface,
7938
- ctx.displayDataInterface || null,
7939
7938
  ctx.responseInterface,
7940
7939
  ctx.filtersInterface,
7941
7940
  ctx.hasCreatableSelectFields ? buildSelectOptionTypes(ctx) : null,
@@ -8302,14 +8301,14 @@ export async function get${ctx.Singular}ById(id: string): Promise<${ctx.Singular
8302
8301
  }
8303
8302
  function genGetBySlugContent(ctx) {
8304
8303
  if (!ctx.hasSlug) return null;
8305
- const returnType = ctx.hasHtmlOutput ? `${ctx.Singular}View` : `${ctx.Singular}`;
8306
8304
  const dbImports = [ctx.tableVar, "user", ...ctx.relTableImports].sort();
8307
8305
  const drizzle = ["eq"];
8308
8306
  const sortedDrizzle = [...new Set(drizzle)].sort();
8309
- const typeImport = ctx.hasHtmlOutput ? `${ctx.Singular}View` : `${ctx.Singular}`;
8310
- const extraTypes = ctx.hasListRels && ctx.hasHtmlOutput ? `, ${ctx.Singular}` : "";
8311
- const populateImport = ctx.hasListRels ? `
8312
- import { populate${ctx.Singular}ListRelationships } from './helpers'` : "";
8307
+ const bySlugHelperImports = [];
8308
+ if (ctx.hasListRels) bySlugHelperImports.push(`populate${ctx.Singular}ListRelationships`);
8309
+ if (ctx.hasMediaFields) bySlugHelperImports.push(`resolve${ctx.Singular}MediaFields`);
8310
+ const populateImport = bySlugHelperImports.length > 0 ? `
8311
+ import { ${bySlugHelperImports.join(", ")} } from './helpers'` : "";
8313
8312
  return `'use server'
8314
8313
 
8315
8314
  import db from '@admin/db'
@@ -8318,19 +8317,19 @@ import { ${sortedDrizzle.join(", ")} } from 'drizzle-orm'
8318
8317
  import { alias } from 'drizzle-orm/pg-core'
8319
8318
  ${ctx.cacheReadImport}
8320
8319
  import { ${ctx.camelPlural}CacheTags } from './types'
8321
- import type { ${typeImport}${extraTypes} } from './types'${populateImport}
8320
+ import type { ${ctx.Singular} } from './types'${populateImport}
8322
8321
 
8323
8322
  ${buildAuthorshipAliasBlock()}
8324
8323
 
8325
- export async function get${ctx.Singular}BySlug(slug: string): Promise<${returnType} | null> {
8324
+ export async function get${ctx.Singular}BySlug(slug: string): Promise<${ctx.Singular} | null> {
8326
8325
  'use cache'${ctx.cacheLifeLine}
8327
8326
  cacheTag(${ctx.camelPlural}CacheTags.bySlug(slug))
8328
8327
  cacheTag(${ctx.camelPlural}CacheTags.all)
8329
8328
 
8330
8329
  try {
8331
- const result = await ${ctx.displaySelectClause}.where(eq(${ctx.tableVar}.slug, slug)).limit(1)
8330
+ const result = await ${ctx.selectClause}.where(eq(${ctx.tableVar}.slug, slug)).limit(1)
8332
8331
  if (result.length === 0) return null
8333
- ${ctx.displaySingleRowReturn}
8332
+ ${ctx.singleRowReturn}
8334
8333
  } catch (error) {
8335
8334
  console.error('Error fetching ${ctx.singular} by slug:', error)
8336
8335
  return null
@@ -9213,7 +9212,6 @@ function genBarrelContent(files, ctx) {
9213
9212
  const lines = [];
9214
9213
  const typeNames = [
9215
9214
  `${ctx.Singular}`,
9216
- ctx.hasHtmlOutput ? `${ctx.Singular}View` : null,
9217
9215
  `${ctx.Plural}Page`,
9218
9216
  `${ctx.Plural}Query`,
9219
9217
  `${ctx.Singular}CreateInput`,
@@ -9799,18 +9797,6 @@ ${m2mFieldTypes}` : ""}${mediaCompanionTypes ? `
9799
9797
  ${mediaCompanionTypes}` : ""}
9800
9798
  ${buildAuthorshipDataFields()}
9801
9799
  }`;
9802
- const displayDbFields = allDbFields.filter(
9803
- (f) => !htmlOutputFields.some((h) => h.name === f.name)
9804
- );
9805
- const displayDataFields = displayDbFields.map(
9806
- (f) => ` ${quotePropertyName(f.name)}: ${getFieldType(f, "output")}${f.required || f.primaryKey ? "" : " | null"}`
9807
- ).join("\n");
9808
- const displayDataInterface = hasHtmlOutput ? `export interface ${Singular}View {
9809
- ${displayDataFields}${htmlFieldTypes ? `
9810
- ${htmlFieldTypes}` : ""}${m2mFieldTypes ? `
9811
- ${m2mFieldTypes}` : ""}
9812
- ${buildAuthorshipDataFields()}
9813
- }` : "";
9814
9800
  const responseInterface = `export interface ${Plural}Page {
9815
9801
  ${camelPlural}: ${Singular}[]
9816
9802
  total: number
@@ -9870,20 +9856,6 @@ ${updateInterfaceFields}${hasDraft ? `
9870
9856
  authorshipSelects,
9871
9857
  authorshipJoins
9872
9858
  ) : buildExplicitSelect(listDbFields, tableVar, [], authorshipSelects, authorshipJoins) : selectClause;
9873
- const displaySelectClause = hasHtmlOutput && hasSlug ? hasRelationships ? buildRelationshipSelect(
9874
- displayDbFields,
9875
- relationshipFields,
9876
- tableVar,
9877
- htmlOutputFields,
9878
- authorshipSelects,
9879
- authorshipJoins
9880
- ) : buildExplicitSelect(
9881
- displayDbFields,
9882
- tableVar,
9883
- htmlOutputFields,
9884
- authorshipSelects,
9885
- authorshipJoins
9886
- ) : selectClause;
9887
9859
  const filterConditions = filterableFields.map((f) => {
9888
9860
  if (dateRangeFilterFields.has(f.name)) {
9889
9861
  return ` if (query?.${f.name}) {
@@ -9974,23 +9946,6 @@ ${searchFields.map((f) => ` ilike(${tableVar}.${f}, searchTerm)`).join(
9974
9946
  const singleRowReturn = hasMediaFields ? `${baseSingleRowReturn.replace(/return ([\s\S]+)$/, `const singleRow = $1
9975
9947
  const [resolved] = await resolve${Singular}MediaFields([singleRow])
9976
9948
  return resolved`)}` : baseSingleRowReturn;
9977
- const displaySingleRowReturn = hasHtmlOutput ? (() => {
9978
- const displayType = `${Singular}View`;
9979
- if (hasRelationships && hasListRels) {
9980
- return `const row = result[0]
9981
- return await populate${Singular}ListRelationships(${buildSingleRowMapping(displayDbFields, relationshipFields, Singular, htmlOutputFields)}) as unknown as ${displayType}`;
9982
- }
9983
- if (hasRelationships) {
9984
- return `const row = result[0]
9985
- return ${buildSingleRowMapping(displayDbFields, relationshipFields, displayType, htmlOutputFields)}`;
9986
- }
9987
- if (hasListRels) {
9988
- return `const row = result[0]
9989
- return await populate${Singular}ListRelationships(${buildSingleRowMapping(displayDbFields, relationshipFields, Singular, htmlOutputFields)}) as unknown as ${displayType}`;
9990
- }
9991
- return `const row = result[0]
9992
- return ${buildSingleRowMapping(displayDbFields, relationshipFields, displayType, htmlOutputFields)}`;
9993
- })() : singleRowReturn;
9994
9949
  const nextMajor = nextMajorVersion ?? 16;
9995
9950
  const cacheInvalidationFn = nextMajor >= 16 ? "updateTag" : "revalidateTag";
9996
9951
  const cacheReadImport = nextMajor >= 16 ? `import { cacheLife, cacheTag } from 'next/cache'` : `import { unstable_cacheTag as cacheTag } from 'next/cache'`;
@@ -10029,20 +9984,17 @@ ${searchFields.map((f) => ` ilike(${tableVar}.${f}, searchTerm)`).join(
10029
9984
  relTableImports,
10030
9985
  listRelTableImports,
10031
9986
  dataInterface,
10032
- displayDataInterface,
10033
9987
  responseInterface,
10034
9988
  filtersInterface,
10035
9989
  createInterface,
10036
9990
  updateInterface,
10037
9991
  selectClause,
10038
9992
  listSelectClause,
10039
- displaySelectClause,
10040
9993
  filterConditions,
10041
9994
  searchBlock,
10042
9995
  resultMapping,
10043
9996
  listResultMapping,
10044
9997
  singleRowReturn,
10045
- displaySingleRowReturn,
10046
9998
  fieldMeta,
10047
9999
  createMappings,
10048
10000
  htmlCreateBlock,
@@ -14123,9 +14075,6 @@ function generateHook(schema, hooksDir, options = {}) {
14123
14075
  const Plural = toPascalCase(plural);
14124
14076
  const dbFields = flattenFields(schema.fields);
14125
14077
  const hasSlugField = dbFields.some((f) => f.name === "slug");
14126
- const hasHtmlOutput = dbFields.some(
14127
- (f) => (f.type === "richtext" || f.type === "markdown") && f.output === "html"
14128
- );
14129
14078
  const resolvedFilters = resolveEntityFilters(schema).map((filter) => ({
14130
14079
  ...filter,
14131
14080
  variableName: toCamelCase(filter.key),
@@ -14143,12 +14092,7 @@ function generateHook(schema, hooksDir, options = {}) {
14143
14092
  }
14144
14093
  }
14145
14094
  }
14146
- const typeImports = [
14147
- `type ${Singular}`,
14148
- ...hasHtmlOutput && hasSlugField ? [`type ${Singular}View`] : [],
14149
- `type ${Plural}Page`,
14150
- `type ${Plural}Query`
14151
- ];
14095
+ const typeImports = [`type ${Singular}`, `type ${Plural}Page`, `type ${Plural}Query`];
14152
14096
  const filterParams = hasFilters ? resolvedFilters.flatMap(
14153
14097
  (filter) => filter.type === "date-range" ? [`${filter.fromVariableName}?: string`, `${filter.toVariableName}?: string`] : [`${filter.variableName}?: string`]
14154
14098
  ).join(", ") : "";
@@ -14200,10 +14144,9 @@ export function use${Singular}(id: string | null | undefined): UseQueryResult<${
14200
14144
  enabled: !!id,
14201
14145
  })
14202
14146
  }`;
14203
- const slugReturnType = hasHtmlOutput ? `${Singular}View` : `${Singular}`;
14204
14147
  const slugHook = hasSlugField ? `
14205
14148
 
14206
- export function use${Singular}BySlug(slug: string | null | undefined): UseQueryResult<${slugReturnType} | null, Error> {
14149
+ export function use${Singular}BySlug(slug: string | null | undefined): UseQueryResult<${Singular} | null, Error> {
14207
14150
  return useQuery({
14208
14151
  queryKey: ['${singular}', 'slug', slug],
14209
14152
  queryFn: () => (slug ? get${Singular}BySlug(slug) : Promise.resolve(null)),