-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.ts
92 lines (79 loc) · 2.73 KB
/
templates.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { addServerTemplate, addTemplate } from '@nuxt/kit'
import type { ExtensionName } from './runtime/types'
import type { ModuleOptions } from './module'
export async function addTemplates(options: ModuleOptions) {
const clientExts = getExtensions(options.client?.extensions)
const serverExts = getExtensions(options.server?.extensions)
addTemplate({
write: true,
filename: 'pglite/extensions.ts',
getContents() {
if (clientExts === undefined) return `export const extensions = {}
export default { extensions }
`
else return `${clientExts.imports.join('\n')}
export const extensions = {
${clientExts.extensions.join(',\n\t')}
}
export default { extensions }
`
},
})
addServerTemplate({
filename: '#pglite/server-extensions.js',
getContents() {
if (serverExts === undefined) return `export const extensions = {}
export default { extensions }
`
else return `${serverExts.imports.join('\n')}
export const extensions = {
${serverExts.extensions.join(',\n\t')}
}
export default { extensions }
`
},
})
}
function getExtensions(extensions: ExtensionName[] = []) {
if (extensions.length === 0) return undefined
const imports: string[] = []
const exts: string[] = []
extensions.forEach((extension) => {
imports.push(`import { ${extension} } from '${extensionSources[extension]}'`)
exts.push(
extension === 'electricSync'
? 'electric: electricSync()'
: extension,
)
})
return {
imports,
extensions: exts,
}
}
const extensionSources = {
live: '@electric-sql/pglite/live',
vector: '@electric-sql/pglite/vector',
electricSync: '@electric-sql/pglite-sync',
adminpack: '@electric-sql/pglite/contrib/adminpack',
amcheck: '@electric-sql/pglite/contrib/amcheck',
auto_explain: '@electric-sql/pglite/contrib/auto_explain',
bloom: '@electric-sql/pglite/contrib/bloom',
btree_gin: '@electric-sql/pglite/contrib/btree_gin',
btree_gist: '@electric-sql/pglite/contrib/btree_gist',
citext: '@electric-sql/pglite/contrib/citext',
cube: '@electric-sql/pglite/contrib/cube',
earthdistance: '@electric-sql/pglite/contrib/earthdistance',
fuzzystrmatch: '@electric-sql/pglite/contrib/fuzzystrmatch',
hstore: '@electric-sql/pglite/contrib/hstore',
isn: '@electric-sql/pglite/contrib/isn',
lo: '@electric-sql/pglite/contrib/lo',
ltree: '@electric-sql/pglite/contrib/ltree',
pg_trgm: '@electric-sql/pglite/contrib/pg_trgm',
seg: '@electric-sql/pglite/contrib/seg',
tablefunc: '@electric-sql/pglite/contrib/tablefunc',
tcn: '@electric-sql/pglite/contrib/tcn',
tsm_system_rows: '@electric-sql/pglite/contrib/tsm_system_rows',
tsm_system_time: '@electric-sql/pglite/contrib/tsm_system_time',
uuid_ossp: '@electric-sql/pglite/contrib/uuid_ossp',
}