Skip to content

Commit

Permalink
Fixed small issues in TS SDK userApi.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martinsos authored and sodic committed Oct 9, 2024
1 parent a91b88a commit 5894a58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion waspc/packages/wasp-config/src/appSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type Api = {
fn: ExtImport
middlewareConfigFn?: ExtImport
entities?: Ref<'Entity'>[]
httpRoute: HttpRoute[]
httpRoute: HttpRoute
auth?: boolean
}

Expand Down
16 changes: 11 additions & 5 deletions waspc/packages/wasp-config/src/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,20 @@ function mapOperationConfig(
const { fn, entities, auth } = config
return {
fn: mapExtImport(fn),
entities: entities.map((e) => parseEntityRef(e)),
...( entities && { entities: entities.map(parseEntityRef) }),
auth: auth,
}
}

function mapExtImport(extImport: User.ExtImport): AppSpec.ExtImport {
const { import: name, from: path } = extImport
return { kind: 'named', name, path }
if ('import' in extImport) {
return { kind: 'named', name: extImport.import, path: extImport.from };
} else if ('importDefault' in extImport) {
return { kind: 'default', name: extImport.importDefault, path: extImport.from };
} else {
const _exhaustiveCheck: never = extImport;
throw new Error('Invalid ExtImport: neither `import` nor `importDefault` is defined');
}
}

function mapApiConfig(
Expand All @@ -154,7 +160,7 @@ function mapApiConfig(
return {
fn: mapExtImport(fn),
middlewareConfigFn: middlewareConfigFn && mapExtImport(middlewareConfigFn),
entities: entities.map((e) => parseEntityRef(e)),
...( entities && { entities: entities.map(parseEntityRef) }),
httpRoute: httpRoute,
auth: auth,
}
Expand Down Expand Up @@ -350,7 +356,7 @@ function mapJob(
executor: executor,
perform: mapPerform(perform),
schedule: schedule && mapSchedule(schedule),
entities: entities.map((e) => parseEntityRef(e)),
...( entities && { entities: entities.map(parseEntityRef) }),
}
}

Expand Down
13 changes: 8 additions & 5 deletions waspc/packages/wasp-config/src/userApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export type AppConfig = Pick<AppSpec.App, 'title' | 'wasp' | 'head'>
export type ExtImport = {
import: string
from: AppSpec.ExtImport['path']
} | {
importDefault: string
from: AppSpec.ExtImport['path']
}

export type ServerConfig = {
Expand Down Expand Up @@ -132,7 +135,7 @@ type PageName = string & { _brand: 'Page' }

export type ActionConfig = {
fn: ExtImport
entities: string[]
entities?: string[]
auth?: boolean
}

Expand All @@ -144,16 +147,16 @@ export type ApiNamespaceConfig = {
export type ApiConfig = {
fn: ExtImport
middlewareConfigFn?: ExtImport
entities: string[]
httpRoute: AppSpec.HttpRoute[]
entities?: string[]
httpRoute: AppSpec.HttpRoute
auth?: boolean
}

export type JobConfig = {
executor: AppSpec.JobExecutor
perform: Perform
schedule?: ScheduleConfig
entities: string[]
entities?: string[]
}

export type Crud = {
Expand Down Expand Up @@ -193,7 +196,7 @@ type ExecutorOptions = {

export type QueryConfig = {
fn: ExtImport
entities: string[]
entities?: string[]
auth?: boolean
}

Expand Down

0 comments on commit 5894a58

Please sign in to comment.