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