@tthr/vue 0.0.46 → 0.0.47
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/nuxt/module.ts +27 -29
- package/package.json +1 -1
package/nuxt/module.ts
CHANGED
|
@@ -158,8 +158,9 @@ export default defineNuxtModule<TetherModuleOptions>({
|
|
|
158
158
|
|
|
159
159
|
// Generate a server plugin to auto-register cron handlers from tether/functions
|
|
160
160
|
// This runs at build time and creates a plugin that imports user's functions
|
|
161
|
+
// NOTE: Must be .js file (not .ts) to avoid Rollup parse errors during Nitro build
|
|
161
162
|
addTemplate({
|
|
162
|
-
filename: 'server/plugins/tether-functions.
|
|
163
|
+
filename: 'server/plugins/tether-functions.js',
|
|
163
164
|
write: true,
|
|
164
165
|
getContents: () => `
|
|
165
166
|
/**
|
|
@@ -171,70 +172,67 @@ import { registerCronHandler } from '@tthr/vue/nuxt/runtime/server/plugins/cron.
|
|
|
171
172
|
import { useTetherServer } from '@tthr/vue/nuxt/runtime/server/utils/tether.js';
|
|
172
173
|
|
|
173
174
|
// Import all functions from tether/functions (using ~~ for rootDir)
|
|
174
|
-
// @ts-ignore - user's functions may not exist yet
|
|
175
175
|
import * as tetherFunctions from '~~/tether/functions';
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
* Create a simple logger for function execution
|
|
179
179
|
*/
|
|
180
|
-
function createLogger(functionName
|
|
180
|
+
function createLogger(functionName) {
|
|
181
181
|
const prefix = \`[Tether] \${functionName}\`;
|
|
182
182
|
return {
|
|
183
|
-
log: (msg
|
|
184
|
-
info: (msg
|
|
185
|
-
warn: (msg
|
|
186
|
-
error: (msg
|
|
187
|
-
debug: (msg
|
|
183
|
+
log: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
|
|
184
|
+
info: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
|
|
185
|
+
warn: (msg, data) => console.warn(prefix, msg, data !== undefined ? data : ''),
|
|
186
|
+
error: (msg, data) => console.error(prefix, msg, data !== undefined ? data : ''),
|
|
187
|
+
debug: (msg, data) => console.debug(prefix, msg, data !== undefined ? data : ''),
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
192
|
* Create the handler context for a function
|
|
193
193
|
*/
|
|
194
|
-
function createHandlerContext(functionName
|
|
195
|
-
const tether = useTetherServer(null
|
|
194
|
+
function createHandlerContext(functionName, args) {
|
|
195
|
+
const tether = useTetherServer(null);
|
|
196
196
|
const log = createLogger(functionName);
|
|
197
197
|
|
|
198
198
|
// Create db proxy that uses tether server client
|
|
199
|
-
// TODO: This is a placeholder - proper db operations need to be implemented
|
|
200
199
|
const db = new Proxy({}, {
|
|
201
|
-
get(_, tableName
|
|
200
|
+
get(_, tableName) {
|
|
202
201
|
return {
|
|
203
|
-
findMany: async (options
|
|
204
|
-
// Call Tether API for db operations
|
|
202
|
+
findMany: async (options) => {
|
|
205
203
|
return tether.query(\`_db.\${tableName}.findMany\`, options);
|
|
206
204
|
},
|
|
207
|
-
findFirst: async (options
|
|
205
|
+
findFirst: async (options) => {
|
|
208
206
|
return tether.query(\`_db.\${tableName}.findFirst\`, options);
|
|
209
207
|
},
|
|
210
|
-
findUnique: async (options
|
|
208
|
+
findUnique: async (options) => {
|
|
211
209
|
return tether.query(\`_db.\${tableName}.findUnique\`, options);
|
|
212
210
|
},
|
|
213
|
-
findById: async (id
|
|
211
|
+
findById: async (id) => {
|
|
214
212
|
return tether.query(\`_db.\${tableName}.findById\`, { id });
|
|
215
213
|
},
|
|
216
|
-
count: async (options
|
|
214
|
+
count: async (options) => {
|
|
217
215
|
return tether.query(\`_db.\${tableName}.count\`, options);
|
|
218
216
|
},
|
|
219
|
-
create: async (options
|
|
217
|
+
create: async (options) => {
|
|
220
218
|
return tether.mutation(\`_db.\${tableName}.create\`, options);
|
|
221
219
|
},
|
|
222
|
-
insert: async (data
|
|
220
|
+
insert: async (data) => {
|
|
223
221
|
return tether.mutation(\`_db.\${tableName}.insert\`, { data });
|
|
224
222
|
},
|
|
225
|
-
insertMany: async (data
|
|
223
|
+
insertMany: async (data) => {
|
|
226
224
|
return tether.mutation(\`_db.\${tableName}.insertMany\`, { data });
|
|
227
225
|
},
|
|
228
|
-
update: async (options
|
|
226
|
+
update: async (options) => {
|
|
229
227
|
return tether.mutation(\`_db.\${tableName}.update\`, options);
|
|
230
228
|
},
|
|
231
|
-
upsert: async (options
|
|
229
|
+
upsert: async (options) => {
|
|
232
230
|
return tether.mutation(\`_db.\${tableName}.upsert\`, options);
|
|
233
231
|
},
|
|
234
|
-
delete: async (options
|
|
232
|
+
delete: async (options) => {
|
|
235
233
|
return tether.mutation(\`_db.\${tableName}.delete\`, options);
|
|
236
234
|
},
|
|
237
|
-
deleteById: async (id
|
|
235
|
+
deleteById: async (id) => {
|
|
238
236
|
return tether.mutation(\`_db.\${tableName}.deleteById\`, { id });
|
|
239
237
|
},
|
|
240
238
|
};
|
|
@@ -246,7 +244,7 @@ function createHandlerContext(functionName: string, args: unknown) {
|
|
|
246
244
|
query: tether.query.bind(tether),
|
|
247
245
|
mutation: tether.mutation.bind(tether),
|
|
248
246
|
env: new Proxy({}, {
|
|
249
|
-
get(_, key
|
|
247
|
+
get(_, key) {
|
|
250
248
|
return process.env[key];
|
|
251
249
|
},
|
|
252
250
|
}),
|
|
@@ -269,14 +267,14 @@ export default defineNitroPlugin(() => {
|
|
|
269
267
|
if (!moduleExports || typeof moduleExports !== 'object') continue;
|
|
270
268
|
|
|
271
269
|
// Iterate through all exports in each module
|
|
272
|
-
for (const [fnName, fnDef] of Object.entries(moduleExports
|
|
270
|
+
for (const [fnName, fnDef] of Object.entries(moduleExports)) {
|
|
273
271
|
// Check if it's a Tether function definition (has handler property)
|
|
274
272
|
if (!fnDef || typeof fnDef !== 'object' || typeof fnDef.handler !== 'function') continue;
|
|
275
273
|
|
|
276
274
|
const fullName = \`\${moduleName}.\${fnName}\`;
|
|
277
275
|
|
|
278
276
|
// Register the cron handler
|
|
279
|
-
registerCronHandler(fullName, async (args
|
|
277
|
+
registerCronHandler(fullName, async (args) => {
|
|
280
278
|
const context = createHandlerContext(fullName, args);
|
|
281
279
|
return fnDef.handler(context);
|
|
282
280
|
});
|
|
@@ -294,7 +292,7 @@ export default defineNitroPlugin(() => {
|
|
|
294
292
|
nuxt.hook('nitro:config' as any, (nitroConfig: any) => {
|
|
295
293
|
nitroConfig.plugins = nitroConfig.plugins || [];
|
|
296
294
|
// Add our generated plugin after the cron plugin
|
|
297
|
-
nitroConfig.plugins.push('#build/server/plugins/tether-functions');
|
|
295
|
+
nitroConfig.plugins.push('#build/server/plugins/tether-functions.js');
|
|
298
296
|
});
|
|
299
297
|
},
|
|
300
298
|
});
|