-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update npm package to speed up layout generation
- Loading branch information
Showing
17 changed files
with
124 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,25 @@ | ||
import { useQuery } from '@tanstack/vue-query'; | ||
import { useOnshapeUrl } from './useOnshapeUrl'; | ||
import { type Project, getBoardLayouts, type Config } from '@aklinker1/cutlist'; | ||
import { generateBoardLayouts } from '@aklinker1/cutlist'; | ||
|
||
export default function () { | ||
const onshape = useOnshapeApi(); | ||
const loader = useOnshapeLoader(); | ||
const url = useAssemblyUrl(); | ||
const onshapeUrl = useOnshapeUrl(url); | ||
const bladeWidth = useBladeWidth(); | ||
const optimize = useOptimizeFor(); | ||
const config = useCutlistConfig(); | ||
const stock = useStock(); | ||
|
||
return useQuery({ | ||
queryKey: ['board-layouts', url, bladeWidth, optimize, stock], | ||
queryFn: async () => { | ||
if (onshapeUrl.value == null) return undefined; | ||
const partsQuery = useQuery({ | ||
queryKey: ['onshape', 'board-layouts', url], | ||
queryFn: () => loader.getParts(url.value), | ||
}); | ||
|
||
const project: Project = { | ||
source: { | ||
type: 'onshape', | ||
id: onshapeUrl.value.did, | ||
assemblyId: onshapeUrl.value.eid, | ||
}, | ||
}; | ||
const config: Config = { | ||
bladeWidth: bladeWidth.value, | ||
optimize: optimize.value, | ||
}; | ||
return await getBoardLayouts(onshape, project, stock.value, config); | ||
}, | ||
staleTime: 5 * 60e3, // 5 minutes, will refrech latest document | ||
const layouts = computed(() => { | ||
const parts = partsQuery.data.value; | ||
if (parts == null) return undefined; | ||
return generateBoardLayouts(parts, stock.value, config.value); | ||
}); | ||
|
||
return { | ||
...partsQuery, | ||
data: layouts, | ||
}; | ||
} |
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,11 @@ | ||
import type { Config } from '@aklinker1/cutlist'; | ||
|
||
export default createSharedComposable(() => { | ||
const bladeWidth = useBladeWidth(); | ||
const optimize = useOptimizeFor(); | ||
|
||
return computed<Config>(() => ({ | ||
bladeWidth: bladeWidth.value, | ||
optimize: optimize.value, | ||
})); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,10 @@ | ||
import { defineOnshapeLoader } from '@aklinker1/cutlist/onshape'; | ||
|
||
export default createGlobalState(() => | ||
defineOnshapeLoader({ | ||
// Forward requests through server | ||
baseUrl: '/api/onshape', | ||
// Server adds auth, no need to pass anything here | ||
// auth: { ... }, | ||
}), | ||
); |
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,10 @@ | ||
import { useQueryClient } from '@tanstack/vue-query'; | ||
|
||
export default function () { | ||
const queries = useQueryClient(); | ||
return async () => { | ||
await queries.refetchQueries({ | ||
queryKey: ['onshape'], | ||
}); | ||
}; | ||
} |
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,10 +1,10 @@ | ||
import type { NitroApp } from 'nitropack'; | ||
import type { OnshapeApiClient } from '@aklinker1/cutlist/onshape'; | ||
import type { OnshapeLoader } from '@aklinker1/cutlist/onshape'; | ||
|
||
export default function () { | ||
return useNitroApp() as ExtendedNitroApp; | ||
} | ||
|
||
export interface ExtendedNitroApp extends NitroApp { | ||
onshape: OnshapeApiClient; | ||
onshape: OnshapeLoader; | ||
} |
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,9 +1,9 @@ | ||
import { defineOnshapeApi } from '@aklinker1/cutlist/onshape'; | ||
import { defineOnshapeLoader } from '@aklinker1/cutlist/onshape'; | ||
import { type ExtendedNitroApp } from '../composables/useExtendedNitroApp'; | ||
|
||
export default defineNitroPlugin((nitro) => { | ||
const config = useRuntimeConfig(); | ||
(nitro as ExtendedNitroApp).onshape = defineOnshapeApi({ | ||
(nitro as ExtendedNitroApp).onshape = defineOnshapeLoader({ | ||
auth: config.onshape, | ||
}); | ||
}); |