-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): lazy load handlers (#700)
# Pull Request type Please check the type of change your PR introduces: - [ ] Bugfix - [x] Feature - [ ] Code style update (formatting, renaming) - [x] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? Issue Number: - IN-911 - IN-912 ## What is the new behavior? - - - ## Does this introduce a breaking change? - [ ] Yes - [ ] No ## Other information PR-URL: #700 Co-authored-by: Joe Karow <[email protected]> Co-authored-by: InReach [Automated User] <[email protected]>
- Loading branch information
Showing
364 changed files
with
10,419 additions
and
6,833 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Client } from '@googlemaps/google-maps-services-js' | ||
|
||
export const googleMapsApi = new Client() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
import { mergeRouters } from '~api/lib/trpc' | ||
import { defineRouter, publicProcedure, staffProcedure } from '~api/lib/trpc' | ||
|
||
// import { mutations } from './mutations' | ||
import { queries } from './queries' | ||
import * as schema from './schemas' | ||
|
||
export const attributeRouter = mergeRouters(queries /*mutations*/) | ||
type AttributeQueryHandlerCache = { | ||
getFilterOptions: typeof import('./query.getFilterOptions.handler').getFilterOptions | ||
getOne: typeof import('./query.getOne.handler').getOne | ||
} | ||
|
||
const HandlerCache: Partial<AttributeQueryHandlerCache> = {} | ||
export const attributeRouter = defineRouter({ | ||
getFilterOptions: publicProcedure.query(async ({ ctx }) => { | ||
if (!HandlerCache.getFilterOptions) | ||
HandlerCache.getFilterOptions = await import('./query.getFilterOptions.handler').then( | ||
(mod) => mod.getFilterOptions | ||
) | ||
|
||
if (!HandlerCache.getFilterOptions) throw new Error('Failed to load handler') | ||
return HandlerCache.getFilterOptions() | ||
}), | ||
getOne: staffProcedure.input(schema.ZGetOneSchema).query(async ({ ctx, input }) => { | ||
if (!HandlerCache.getOne) | ||
HandlerCache.getOne = await import('./query.getOne.handler').then((mod) => mod.getOne) | ||
|
||
if (!HandlerCache.getOne) throw new Error('Failed to load handler') | ||
return HandlerCache.getOne({ ctx, input }) | ||
}), | ||
}) |
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
packages/api/router/attribute/query.getFilterOptions.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { prisma } from '@weareinreach/db' | ||
|
||
export const getFilterOptions = async () => { | ||
const result = await prisma.attribute.findMany({ | ||
where: { | ||
AND: { | ||
filterType: { | ||
not: null, | ||
}, | ||
active: true, | ||
}, | ||
}, | ||
select: { | ||
id: true, | ||
tsKey: true, | ||
tsNs: true, | ||
filterType: true, | ||
}, | ||
orderBy: { | ||
tsKey: 'asc', | ||
}, | ||
}) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { prisma } from '@weareinreach/db' | ||
import { type TRPCHandlerParams } from '~api/types/handler' | ||
|
||
import { type TGetOneSchema } from './query.getOne.schema' | ||
|
||
export const getOne = async ({ input }: TRPCHandlerParams<TGetOneSchema>) => { | ||
const result = await prisma.attribute.findUniqueOrThrow({ | ||
where: input, | ||
select: { | ||
id: true, | ||
tag: true, | ||
tsKey: true, | ||
tsNs: true, | ||
icon: true, | ||
iconBg: true, | ||
active: true, | ||
requireBoolean: true, | ||
requireData: true, | ||
requireDataSchema: { select: { definition: true } }, | ||
requireGeo: true, | ||
requireLanguage: true, | ||
requireText: true, | ||
}, | ||
}) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { z } from 'zod' | ||
|
||
export const ZGetOneSchema = z.object({ id: z.string() }).or(z.object({ tag: z.string() })) | ||
export type TGetOneSchema = z.infer<typeof ZGetOneSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// codegen:start {preset: barrel, include: ./*.schema.ts} | ||
export * from './query.getOne.schema' | ||
// codegen:end |
Oops, something went wrong.