on-zero 0.1.21 → 0.1.22
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/cjs/cli.cjs +4 -0
- package/dist/cjs/cli.js +4 -0
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/cli.native.js +7 -2
- package/dist/cjs/cli.native.js.map +1 -1
- package/dist/cjs/helpers/createMutators.cjs +4 -3
- package/dist/cjs/helpers/createMutators.js +12 -9
- package/dist/cjs/helpers/createMutators.js.map +1 -1
- package/dist/cjs/helpers/createMutators.native.js +25 -21
- package/dist/cjs/helpers/createMutators.native.js.map +1 -1
- package/dist/cjs/mutations.cjs +34 -4
- package/dist/cjs/mutations.js +29 -4
- package/dist/cjs/mutations.js.map +1 -1
- package/dist/cjs/mutations.native.js +36 -4
- package/dist/cjs/mutations.native.js.map +1 -1
- package/dist/cjs/vite-plugin.cjs +168 -0
- package/dist/cjs/vite-plugin.js +145 -0
- package/dist/cjs/vite-plugin.js.map +6 -0
- package/dist/cjs/vite-plugin.native.js +209 -0
- package/dist/cjs/vite-plugin.native.js.map +1 -0
- package/dist/esm/cli.js +4 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/cli.mjs +4 -0
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/cli.native.js +7 -2
- package/dist/esm/cli.native.js.map +1 -1
- package/dist/esm/helpers/createMutators.js +12 -9
- package/dist/esm/helpers/createMutators.js.map +1 -1
- package/dist/esm/helpers/createMutators.mjs +4 -3
- package/dist/esm/helpers/createMutators.mjs.map +1 -1
- package/dist/esm/helpers/createMutators.native.js +25 -21
- package/dist/esm/helpers/createMutators.native.js.map +1 -1
- package/dist/esm/mutations.js +29 -4
- package/dist/esm/mutations.js.map +1 -1
- package/dist/esm/mutations.mjs +34 -4
- package/dist/esm/mutations.mjs.map +1 -1
- package/dist/esm/mutations.native.js +35 -3
- package/dist/esm/mutations.native.js.map +1 -1
- package/dist/esm/vite-plugin.js +131 -0
- package/dist/esm/vite-plugin.js.map +6 -0
- package/dist/esm/vite-plugin.mjs +143 -0
- package/dist/esm/vite-plugin.mjs.map +1 -0
- package/dist/esm/vite-plugin.native.js +181 -0
- package/dist/esm/vite-plugin.native.js.map +1 -0
- package/package.json +7 -2
- package/readme.md +42 -3
- package/src/cli.ts +9 -1
- package/src/helpers/createMutators.ts +14 -8
- package/src/mutations.ts +57 -4
- package/src/vite-plugin.ts +238 -0
- package/types/helpers/createMutators.d.ts.map +1 -1
- package/types/mutations.d.ts.map +1 -1
- package/types/vite-plugin.d.ts +39 -0
- package/types/vite-plugin.d.ts.map +1 -0
package/src/mutations.ts
CHANGED
|
@@ -10,6 +10,59 @@ import type {
|
|
|
10
10
|
} from './types'
|
|
11
11
|
import type { TableBuilderWithColumns } from '@rocicorp/zero'
|
|
12
12
|
|
|
13
|
+
// HMR registry - stores mutation implementations and proxies by table name
|
|
14
|
+
// allows hot-swapping implementations without changing object references
|
|
15
|
+
// stored on globalThis to persist across HMR module reloads
|
|
16
|
+
const registryKey = '__onZeroMutationRegistry__'
|
|
17
|
+
const proxyKey = '__onZeroProxyRegistry__'
|
|
18
|
+
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const mutationRegistry: Map<string, Record<string, Function>> = globalThis[registryKey] ||
|
|
21
|
+
(globalThis[registryKey] = new Map())
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const proxyRegistry: Map<string, any> =
|
|
24
|
+
globalThis[proxyKey] || (globalThis[proxyKey] = new Map())
|
|
25
|
+
|
|
26
|
+
// get or create a proxy that delegates to the registry
|
|
27
|
+
// returns the SAME proxy object on subsequent calls so HMR works
|
|
28
|
+
function getOrCreateMutationProxy<T extends Record<string, Function>>(
|
|
29
|
+
tableName: string,
|
|
30
|
+
implementations: T
|
|
31
|
+
): T {
|
|
32
|
+
// always update implementations (supports HMR)
|
|
33
|
+
mutationRegistry.set(tableName, implementations)
|
|
34
|
+
|
|
35
|
+
// return existing proxy if we have one (HMR case)
|
|
36
|
+
const existing = proxyRegistry.get(tableName)
|
|
37
|
+
if (existing) {
|
|
38
|
+
return existing as T
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// first time - create the proxy
|
|
42
|
+
const proxy = new Proxy({} as T, {
|
|
43
|
+
get(_, key: string) {
|
|
44
|
+
return mutationRegistry.get(tableName)?.[key]
|
|
45
|
+
},
|
|
46
|
+
ownKeys() {
|
|
47
|
+
const current = mutationRegistry.get(tableName)
|
|
48
|
+
return current ? Object.keys(current) : []
|
|
49
|
+
},
|
|
50
|
+
getOwnPropertyDescriptor(_, key: string) {
|
|
51
|
+
const current = mutationRegistry.get(tableName)
|
|
52
|
+
if (current && key in current) {
|
|
53
|
+
return { enumerable: true, configurable: true, value: current[key] }
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
has(_, key: string) {
|
|
57
|
+
const current = mutationRegistry.get(tableName)
|
|
58
|
+
return current ? key in current : false
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
proxyRegistry.set(tableName, proxy)
|
|
63
|
+
return proxy
|
|
64
|
+
}
|
|
65
|
+
|
|
13
66
|
// two ways to use it:
|
|
14
67
|
// - mutations({}) which doesn't add the "allowed" helper or add CRUD
|
|
15
68
|
// - mutation('tableName', permissions) adds CRUD with permissions, adds allowed
|
|
@@ -122,16 +175,16 @@ export function mutations<
|
|
|
122
175
|
upsert: createCRUDMutation('upsert'),
|
|
123
176
|
}
|
|
124
177
|
|
|
125
|
-
const finalMutations =
|
|
178
|
+
const finalMutations = {
|
|
126
179
|
...mutations,
|
|
127
180
|
// overwrite regular mutations but call them if they are defined by user
|
|
128
181
|
...crudMutations,
|
|
129
|
-
|
|
130
|
-
}) as any as Mutations
|
|
182
|
+
} as any as Mutations
|
|
131
183
|
|
|
132
184
|
setMutationsPermissions(tableName, permissions)
|
|
133
185
|
|
|
134
|
-
return
|
|
186
|
+
// return proxy for HMR support - allows swapping implementations at runtime
|
|
187
|
+
return getOrCreateMutationProxy(tableName, finalMutations)
|
|
135
188
|
}
|
|
136
189
|
|
|
137
190
|
// no schema/permissions don't add CRUD
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { basename, resolve } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import type { Plugin } from 'vite'
|
|
6
|
+
|
|
7
|
+
const hash = (s: string) => createHash('sha256').update(s).digest('hex')
|
|
8
|
+
|
|
9
|
+
// cache to avoid unnecessary writes
|
|
10
|
+
let generateCache: Record<string, string> = {}
|
|
11
|
+
|
|
12
|
+
function writeFileIfChanged(filePath: string, content: string): boolean {
|
|
13
|
+
const contentHash = hash(content)
|
|
14
|
+
if (generateCache[filePath] === contentHash && existsSync(filePath)) {
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
writeFileSync(filePath, content, 'utf-8')
|
|
18
|
+
generateCache[filePath] = contentHash
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function generateModelsFile(modelFiles: string[]) {
|
|
23
|
+
const modelNames = modelFiles.map((f) => basename(f, '.ts')).sort()
|
|
24
|
+
const getImportName = (name: string) => (name === 'user' ? 'userPublic' : name)
|
|
25
|
+
|
|
26
|
+
const imports = modelNames
|
|
27
|
+
.map((name) => `import * as ${getImportName(name)} from '../models/${name}'`)
|
|
28
|
+
.join('\n')
|
|
29
|
+
|
|
30
|
+
const sortedByImportName = [...modelNames].sort((a, b) =>
|
|
31
|
+
getImportName(a).localeCompare(getImportName(b))
|
|
32
|
+
)
|
|
33
|
+
const modelsObj = `export const models = {\n${sortedByImportName.map((name) => ` ${getImportName(name)},`).join('\n')}\n}`
|
|
34
|
+
|
|
35
|
+
const hmrBoundary = `
|
|
36
|
+
if (import.meta.hot) {
|
|
37
|
+
import.meta.hot.accept()
|
|
38
|
+
}
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
return `// auto-generated by on-zero vite plugin\n${imports}\n\n${modelsObj}\n${hmrBoundary}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function generateTypesFile(modelFiles: string[]) {
|
|
45
|
+
const modelNames = modelFiles.map((f) => basename(f, '.ts')).sort()
|
|
46
|
+
const getSchemaName = (name: string) => (name === 'user' ? 'userPublic' : name)
|
|
47
|
+
|
|
48
|
+
const typeExports = modelNames
|
|
49
|
+
.map((name) => {
|
|
50
|
+
const pascalName = name.charAt(0).toUpperCase() + name.slice(1)
|
|
51
|
+
const schemaName = getSchemaName(name)
|
|
52
|
+
return `export type ${pascalName} = TableInsertRow<typeof schema.${schemaName}>\nexport type ${pascalName}Update = TableUpdateRow<typeof schema.${schemaName}>`
|
|
53
|
+
})
|
|
54
|
+
.join('\n\n')
|
|
55
|
+
|
|
56
|
+
return `import type { TableInsertRow, TableUpdateRow } from 'on-zero'\nimport type * as schema from './tables'\n\n${typeExports}\n`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function generateTablesFile(modelFiles: string[]) {
|
|
60
|
+
const modelNames = modelFiles.map((f) => basename(f, '.ts')).sort()
|
|
61
|
+
const getExportName = (name: string) => (name === 'user' ? 'userPublic' : name)
|
|
62
|
+
|
|
63
|
+
const exports = modelNames
|
|
64
|
+
.map((name) => `export { schema as ${getExportName(name)} } from '../models/${name}'`)
|
|
65
|
+
.join('\n')
|
|
66
|
+
|
|
67
|
+
return `// auto-generated by on-zero vite plugin\n\n${exports}\n`
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function runGenerate(options: {
|
|
71
|
+
modelsDir: string
|
|
72
|
+
generatedDir: string
|
|
73
|
+
silent?: boolean
|
|
74
|
+
}) {
|
|
75
|
+
const { modelsDir, generatedDir, silent } = options
|
|
76
|
+
|
|
77
|
+
if (!existsSync(generatedDir)) {
|
|
78
|
+
mkdirSync(generatedDir, { recursive: true })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const allModelFiles = readdirSync(modelsDir)
|
|
82
|
+
.filter((f) => f.endsWith('.ts'))
|
|
83
|
+
.sort()
|
|
84
|
+
|
|
85
|
+
const filesWithSchema = allModelFiles.filter((f) =>
|
|
86
|
+
readFileSync(resolve(modelsDir, f), 'utf-8').includes('export const schema = table(')
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
const writeResults = [
|
|
90
|
+
writeFileIfChanged(
|
|
91
|
+
resolve(generatedDir, 'models.ts'),
|
|
92
|
+
generateModelsFile(allModelFiles)
|
|
93
|
+
),
|
|
94
|
+
writeFileIfChanged(
|
|
95
|
+
resolve(generatedDir, 'types.ts'),
|
|
96
|
+
generateTypesFile(filesWithSchema)
|
|
97
|
+
),
|
|
98
|
+
writeFileIfChanged(
|
|
99
|
+
resolve(generatedDir, 'tables.ts'),
|
|
100
|
+
generateTablesFile(filesWithSchema)
|
|
101
|
+
),
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
const filesChanged = writeResults.filter(Boolean).length
|
|
105
|
+
if (filesChanged > 0 && !silent) {
|
|
106
|
+
console.info(`[on-zero] generated ${filesChanged} file(s)`)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return filesChanged
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface OnZeroPluginOptions {
|
|
113
|
+
/**
|
|
114
|
+
* Path to data directory containing models/ and generated/
|
|
115
|
+
* @default 'src/data'
|
|
116
|
+
*/
|
|
117
|
+
dataDir?: string
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Additional paths to apply HMR fix to
|
|
121
|
+
*/
|
|
122
|
+
hmrInclude?: string[]
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Disable code generation (HMR only)
|
|
126
|
+
*/
|
|
127
|
+
disableGenerate?: boolean
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Vite plugin for on-zero that handles:
|
|
132
|
+
* 1. Code generation (models.ts, types.ts, tables.ts)
|
|
133
|
+
* 2. HMR support for model files (prevents cascade, enables hot-swap)
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { onZeroPlugin } from 'on-zero/vite'
|
|
138
|
+
*
|
|
139
|
+
* export default {
|
|
140
|
+
* plugins: [
|
|
141
|
+
* onZeroPlugin(),
|
|
142
|
+
* // ... other plugins
|
|
143
|
+
* ]
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export function onZeroPlugin(options: OnZeroPluginOptions = {}): Plugin[] {
|
|
148
|
+
const dataDir = options.dataDir || 'src/data'
|
|
149
|
+
const hmrPaths = ['/models/', '/generated/', ...(options.hmrInclude || [])]
|
|
150
|
+
|
|
151
|
+
let modelsDir: string
|
|
152
|
+
let generatedDir: string
|
|
153
|
+
|
|
154
|
+
return [
|
|
155
|
+
// generation plugin
|
|
156
|
+
{
|
|
157
|
+
name: 'on-zero:generate',
|
|
158
|
+
apply: 'serve',
|
|
159
|
+
|
|
160
|
+
configResolved(config) {
|
|
161
|
+
modelsDir = resolve(config.root, dataDir, 'models')
|
|
162
|
+
generatedDir = resolve(config.root, dataDir, 'generated')
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
async buildStart() {
|
|
166
|
+
if (options.disableGenerate) return
|
|
167
|
+
await runGenerate({ modelsDir, generatedDir, silent: false })
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
configureServer(server) {
|
|
171
|
+
if (options.disableGenerate) return
|
|
172
|
+
|
|
173
|
+
// watch for model changes
|
|
174
|
+
server.watcher.on('change', async (file) => {
|
|
175
|
+
if (file.includes(modelsDir)) {
|
|
176
|
+
await runGenerate({ modelsDir, generatedDir, silent: false })
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
server.watcher.on('add', async (file) => {
|
|
181
|
+
if (file.includes(modelsDir)) {
|
|
182
|
+
await runGenerate({ modelsDir, generatedDir, silent: false })
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
server.watcher.on('unlink', async (file) => {
|
|
187
|
+
if (file.includes(modelsDir)) {
|
|
188
|
+
await runGenerate({ modelsDir, generatedDir, silent: false })
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
// HMR plugin - removes invalidate calls to prevent cascade
|
|
195
|
+
{
|
|
196
|
+
name: 'on-zero:hmr',
|
|
197
|
+
apply: 'serve',
|
|
198
|
+
enforce: 'post',
|
|
199
|
+
|
|
200
|
+
transform(code, id) {
|
|
201
|
+
const shouldTransform = hmrPaths.some((p) => id.includes(p)) && /\.tsx?$/.test(id)
|
|
202
|
+
|
|
203
|
+
if (shouldTransform && code.includes('import.meta.hot.invalidate')) {
|
|
204
|
+
return {
|
|
205
|
+
code: code.replace(
|
|
206
|
+
/if\s*\(invalidateMessage\)\s*import\.meta\.hot\.invalidate\(invalidateMessage\);?/g,
|
|
207
|
+
'/* on-zero: HMR invalidate disabled */'
|
|
208
|
+
),
|
|
209
|
+
map: null,
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
// build plugin - generate once before build
|
|
216
|
+
{
|
|
217
|
+
name: 'on-zero:build',
|
|
218
|
+
apply: 'build',
|
|
219
|
+
|
|
220
|
+
configResolved(config) {
|
|
221
|
+
modelsDir = resolve(config.root, dataDir, 'models')
|
|
222
|
+
generatedDir = resolve(config.root, dataDir, 'generated')
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
async buildStart() {
|
|
226
|
+
if (options.disableGenerate) return
|
|
227
|
+
await runGenerate({ modelsDir, generatedDir, silent: true })
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// legacy export for backwards compat
|
|
234
|
+
export const onZeroHmrPlugin = (options?: { include?: string[] }): Plugin => {
|
|
235
|
+
return onZeroPlugin({ hmrInclude: options?.include, disableGenerate: true })[1]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default onZeroPlugin
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMutators.d.ts","sourceRoot":"","sources":["../../src/helpers/createMutators.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,QAAQ,EACR,GAAG,EACH,aAAa,EACb,eAAe,EAGhB,MAAM,UAAU,CAAA;AAEjB,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE;IACtC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,OAAO,CAAA;CACd,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE1B,YAAY,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,CAAA;AAE9D,wBAAgB,cAAc,CAAC,MAAM,SAAS,aAAa,EAAE,EAC3D,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,UAAe,EACf,GAAG,EACH,MAAM,EACN,gBAAgB,GACjB,EAAE;IACD,WAAW,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAChC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IACvC,mBAAmB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/C,gBAAgB,CAAC,EAAE,kBAAkB,CAAA;CACtC,GAAG,eAAe,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"createMutators.d.ts","sourceRoot":"","sources":["../../src/helpers/createMutators.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,QAAQ,EACR,GAAG,EACH,aAAa,EACb,eAAe,EAGhB,MAAM,UAAU,CAAA;AAEjB,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE;IACtC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,OAAO,CAAA;CACd,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE1B,YAAY,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,CAAA;AAE9D,wBAAgB,cAAc,CAAC,MAAM,SAAS,aAAa,EAAE,EAC3D,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,UAAe,EACf,GAAG,EACH,MAAM,EACN,gBAAgB,GACjB,EAAE;IACD,WAAW,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAChC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IACvC,mBAAmB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/C,gBAAgB,CAAC,EAAE,kBAAkB,CAAA;CACtC,GAAG,eAAe,CAAC,MAAM,CAAC,CAiJ1B"}
|
package/types/mutations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../src/mutations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEd,cAAc,EACd,KAAK,EACN,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../src/mutations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEd,cAAc,EACd,KAAK,EACN,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AA2D7D,KAAK,eAAe,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AACnF,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAevD,KAAK,YAAY,GAAG,uBAAuB,CAAC,GAAG,CAAC,CAAA;AAEhD,KAAK,aAAa,CAAC,KAAK,SAAS,YAAY,IAAI;IAC/C,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,MAAM,EAAE,eAAe,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;CAC/C,CAAA;AAED,KAAK,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE1D,KAAK,iBAAiB,CAAC,KAAK,SAAS,YAAY,EAAE,SAAS,SAAS,gBAAgB,IAAI;KACtF,GAAG,IAAI,SAAS,GAAG,MAAM,SAAS,GAAG,GAAG,SAAS,MAAM,SAAS,GAC7D,SAAS,CAAC,GAAG,CAAC,GACd,GAAG,SAAS,MAAM,aAAa,CAAC,GAAG,CAAC,GAClC,aAAa,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GACzB,KAAK;CACZ,CAAA;AAED,wBAAgB,SAAS,CAAC,SAAS,SAAS,gBAAgB,EAC1D,SAAS,EAAE,SAAS,GACnB,SAAS,CAAA;AACZ,wBAAgB,SAAS,CAAC,KAAK,SAAS,YAAY,EAAE,WAAW,SAAS,KAAK,EAC7E,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,GACvB,iBAAiB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC/B,wBAAgB,SAAS,CACvB,KAAK,SAAS,YAAY,EAC1B,WAAW,SAAS,KAAK,EACzB,SAAS,SAAS,gBAAgB,EAElC,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,GACnB,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface OnZeroPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Path to data directory containing models/ and generated/
|
|
5
|
+
* @default 'src/data'
|
|
6
|
+
*/
|
|
7
|
+
dataDir?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Additional paths to apply HMR fix to
|
|
10
|
+
*/
|
|
11
|
+
hmrInclude?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Disable code generation (HMR only)
|
|
14
|
+
*/
|
|
15
|
+
disableGenerate?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Vite plugin for on-zero that handles:
|
|
19
|
+
* 1. Code generation (models.ts, types.ts, tables.ts)
|
|
20
|
+
* 2. HMR support for model files (prevents cascade, enables hot-swap)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { onZeroPlugin } from 'on-zero/vite'
|
|
25
|
+
*
|
|
26
|
+
* export default {
|
|
27
|
+
* plugins: [
|
|
28
|
+
* onZeroPlugin(),
|
|
29
|
+
* // ... other plugins
|
|
30
|
+
* ]
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function onZeroPlugin(options?: OnZeroPluginOptions): Plugin[];
|
|
35
|
+
export declare const onZeroHmrPlugin: (options?: {
|
|
36
|
+
include?: string[];
|
|
37
|
+
}) => Plugin;
|
|
38
|
+
export default onZeroPlugin;
|
|
39
|
+
//# sourceMappingURL=vite-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA2GlC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,EAAE,CAoFxE;AAGD,eAAO,MAAM,eAAe,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,KAAG,MAElE,CAAA;AAED,eAAe,YAAY,CAAA"}
|