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