@tthr/vue 0.0.58 → 0.0.60
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 +1 -139
- package/nuxt/module.ts +1 -141
- package/package.json +1 -1
package/nuxt/module.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* Environment variables (in .env):
|
|
19
19
|
* - TETHER_API_KEY: Your project's API key (required, kept server-side)
|
|
20
20
|
*/
|
|
21
|
-
import { defineNuxtModule, addPlugin, createResolver, addImports, addComponent, addServerHandler, addServerImports
|
|
21
|
+
import { defineNuxtModule, addPlugin, createResolver, addImports, addComponent, addServerHandler, addServerImports } from '@nuxt/kit';
|
|
22
22
|
export default defineNuxtModule({
|
|
23
23
|
meta: {
|
|
24
24
|
name: '@tthr/vue',
|
|
@@ -133,143 +133,5 @@ export default defineNuxtModule({
|
|
|
133
133
|
// Also inline the user's tether/functions directory so Nitro transpiles TypeScript
|
|
134
134
|
nitroConfig.externals.inline.push(`${nuxt.options.rootDir}/tether`);
|
|
135
135
|
});
|
|
136
|
-
// Generate a server plugin to auto-register cron handlers from tether/functions
|
|
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
|
|
139
|
-
addTemplate({
|
|
140
|
-
filename: 'server/plugins/tether-functions.js',
|
|
141
|
-
write: true,
|
|
142
|
-
getContents: () => `
|
|
143
|
-
/**
|
|
144
|
-
* Auto-generated plugin to register Tether functions as cron handlers
|
|
145
|
-
* This file is generated by @tthr/vue/nuxt module
|
|
146
|
-
*/
|
|
147
|
-
import { defineNitroPlugin, registerCronHandler } from '@tthr/vue/nuxt/runtime/server/plugins/cron.js';
|
|
148
|
-
import { useTetherServer } from '@tthr/vue/nuxt/runtime/server/utils/tether.js';
|
|
149
|
-
|
|
150
|
-
// Import all functions from tether/functions using relative path
|
|
151
|
-
// Generated plugin is at .nuxt/server/plugins/, so ../../../ gets to project root
|
|
152
|
-
// Using .ts extension explicitly for Nitro's bundler to resolve
|
|
153
|
-
import * as tetherFunctions from '../../../tether/functions/index.ts';
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Create a simple logger for function execution
|
|
157
|
-
*/
|
|
158
|
-
function createLogger(functionName) {
|
|
159
|
-
const prefix = \`[Tether] \${functionName}\`;
|
|
160
|
-
return {
|
|
161
|
-
log: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
|
|
162
|
-
info: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
|
|
163
|
-
warn: (msg, data) => console.warn(prefix, msg, data !== undefined ? data : ''),
|
|
164
|
-
error: (msg, data) => console.error(prefix, msg, data !== undefined ? data : ''),
|
|
165
|
-
debug: (msg, data) => console.debug(prefix, msg, data !== undefined ? data : ''),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Create the handler context for a function
|
|
171
|
-
*/
|
|
172
|
-
function createHandlerContext(functionName, args) {
|
|
173
|
-
const tether = useTetherServer(null);
|
|
174
|
-
const log = createLogger(functionName);
|
|
175
|
-
|
|
176
|
-
// Create db proxy that uses tether server client
|
|
177
|
-
const db = new Proxy({}, {
|
|
178
|
-
get(_, tableName) {
|
|
179
|
-
return {
|
|
180
|
-
findMany: async (options) => {
|
|
181
|
-
return tether.query(\`_db.\${tableName}.findMany\`, options);
|
|
182
|
-
},
|
|
183
|
-
findFirst: async (options) => {
|
|
184
|
-
return tether.query(\`_db.\${tableName}.findFirst\`, options);
|
|
185
|
-
},
|
|
186
|
-
findUnique: async (options) => {
|
|
187
|
-
return tether.query(\`_db.\${tableName}.findUnique\`, options);
|
|
188
|
-
},
|
|
189
|
-
findById: async (id) => {
|
|
190
|
-
return tether.query(\`_db.\${tableName}.findById\`, { id });
|
|
191
|
-
},
|
|
192
|
-
count: async (options) => {
|
|
193
|
-
return tether.query(\`_db.\${tableName}.count\`, options);
|
|
194
|
-
},
|
|
195
|
-
create: async (options) => {
|
|
196
|
-
return tether.mutation(\`_db.\${tableName}.create\`, options);
|
|
197
|
-
},
|
|
198
|
-
insert: async (data) => {
|
|
199
|
-
return tether.mutation(\`_db.\${tableName}.insert\`, { data });
|
|
200
|
-
},
|
|
201
|
-
insertMany: async (data) => {
|
|
202
|
-
return tether.mutation(\`_db.\${tableName}.insertMany\`, { data });
|
|
203
|
-
},
|
|
204
|
-
update: async (options) => {
|
|
205
|
-
return tether.mutation(\`_db.\${tableName}.update\`, options);
|
|
206
|
-
},
|
|
207
|
-
upsert: async (options) => {
|
|
208
|
-
return tether.mutation(\`_db.\${tableName}.upsert\`, options);
|
|
209
|
-
},
|
|
210
|
-
delete: async (options) => {
|
|
211
|
-
return tether.mutation(\`_db.\${tableName}.delete\`, options);
|
|
212
|
-
},
|
|
213
|
-
deleteById: async (id) => {
|
|
214
|
-
return tether.mutation(\`_db.\${tableName}.deleteById\`, { id });
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Create tether context for actions
|
|
221
|
-
const tetherContext = {
|
|
222
|
-
query: tether.query.bind(tether),
|
|
223
|
-
mutation: tether.mutation.bind(tether),
|
|
224
|
-
env: new Proxy({}, {
|
|
225
|
-
get(_, key) {
|
|
226
|
-
return process.env[key];
|
|
227
|
-
},
|
|
228
|
-
}),
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
args,
|
|
233
|
-
db,
|
|
234
|
-
ctx: { auth: { userId: null, claims: {} }, userId: null },
|
|
235
|
-
log,
|
|
236
|
-
tether: tetherContext,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export default defineNitroPlugin(() => {
|
|
241
|
-
console.log('[Tether] Auto-registering functions from tether/functions...');
|
|
242
|
-
|
|
243
|
-
// Iterate through all exported modules
|
|
244
|
-
for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
|
|
245
|
-
if (!moduleExports || typeof moduleExports !== 'object') continue;
|
|
246
|
-
|
|
247
|
-
// Iterate through all exports in each module
|
|
248
|
-
for (const [fnName, fnDef] of Object.entries(moduleExports)) {
|
|
249
|
-
// Check if it's a Tether function definition (has handler property)
|
|
250
|
-
if (!fnDef || typeof fnDef !== 'object' || typeof fnDef.handler !== 'function') continue;
|
|
251
|
-
|
|
252
|
-
const fullName = \`\${moduleName}.\${fnName}\`;
|
|
253
|
-
|
|
254
|
-
// Register the cron handler
|
|
255
|
-
registerCronHandler(fullName, async (args) => {
|
|
256
|
-
const context = createHandlerContext(fullName, args);
|
|
257
|
-
return fnDef.handler(context);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
console.log(\`[Tether] Registered handler: \${fullName}\`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
console.log('[Tether] Function registration complete');
|
|
265
|
-
});
|
|
266
|
-
`,
|
|
267
|
-
});
|
|
268
|
-
// Add the generated plugin to Nitro
|
|
269
|
-
nuxt.hook('nitro:config', (nitroConfig) => {
|
|
270
|
-
nitroConfig.plugins = nitroConfig.plugins || [];
|
|
271
|
-
// Add our generated plugin after the cron plugin
|
|
272
|
-
nitroConfig.plugins.push('#build/server/plugins/tether-functions.js');
|
|
273
|
-
});
|
|
274
136
|
},
|
|
275
137
|
});
|
package/nuxt/module.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* - TETHER_API_KEY: Your project's API key (required, kept server-side)
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { defineNuxtModule, addPlugin, createResolver, addImports, addComponent, addServerHandler, addServerImports
|
|
22
|
+
import { defineNuxtModule, addPlugin, createResolver, addImports, addComponent, addServerHandler, addServerImports } from '@nuxt/kit';
|
|
23
23
|
|
|
24
24
|
export interface TetherModuleOptions {
|
|
25
25
|
/** Project ID from Tether dashboard */
|
|
@@ -158,145 +158,5 @@ export default defineNuxtModule<TetherModuleOptions>({
|
|
|
158
158
|
// Also inline the user's tether/functions directory so Nitro transpiles TypeScript
|
|
159
159
|
nitroConfig.externals.inline.push(`${nuxt.options.rootDir}/tether`);
|
|
160
160
|
});
|
|
161
|
-
|
|
162
|
-
// Generate a server plugin to auto-register cron handlers from tether/functions
|
|
163
|
-
// This runs at build time and creates a plugin that imports user's functions
|
|
164
|
-
// NOTE: Must be .js file (not .ts) to avoid Rollup parse errors during Nitro build
|
|
165
|
-
addTemplate({
|
|
166
|
-
filename: 'server/plugins/tether-functions.js',
|
|
167
|
-
write: true,
|
|
168
|
-
getContents: () => `
|
|
169
|
-
/**
|
|
170
|
-
* Auto-generated plugin to register Tether functions as cron handlers
|
|
171
|
-
* This file is generated by @tthr/vue/nuxt module
|
|
172
|
-
*/
|
|
173
|
-
import { defineNitroPlugin, registerCronHandler } from '@tthr/vue/nuxt/runtime/server/plugins/cron.js';
|
|
174
|
-
import { useTetherServer } from '@tthr/vue/nuxt/runtime/server/utils/tether.js';
|
|
175
|
-
|
|
176
|
-
// Import all functions from tether/functions using relative path
|
|
177
|
-
// Generated plugin is at .nuxt/server/plugins/, so ../../../ gets to project root
|
|
178
|
-
// Using .ts extension explicitly for Nitro's bundler to resolve
|
|
179
|
-
import * as tetherFunctions from '../../../tether/functions/index.ts';
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Create a simple logger for function execution
|
|
183
|
-
*/
|
|
184
|
-
function createLogger(functionName) {
|
|
185
|
-
const prefix = \`[Tether] \${functionName}\`;
|
|
186
|
-
return {
|
|
187
|
-
log: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
|
|
188
|
-
info: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
|
|
189
|
-
warn: (msg, data) => console.warn(prefix, msg, data !== undefined ? data : ''),
|
|
190
|
-
error: (msg, data) => console.error(prefix, msg, data !== undefined ? data : ''),
|
|
191
|
-
debug: (msg, data) => console.debug(prefix, msg, data !== undefined ? data : ''),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Create the handler context for a function
|
|
197
|
-
*/
|
|
198
|
-
function createHandlerContext(functionName, args) {
|
|
199
|
-
const tether = useTetherServer(null);
|
|
200
|
-
const log = createLogger(functionName);
|
|
201
|
-
|
|
202
|
-
// Create db proxy that uses tether server client
|
|
203
|
-
const db = new Proxy({}, {
|
|
204
|
-
get(_, tableName) {
|
|
205
|
-
return {
|
|
206
|
-
findMany: async (options) => {
|
|
207
|
-
return tether.query(\`_db.\${tableName}.findMany\`, options);
|
|
208
|
-
},
|
|
209
|
-
findFirst: async (options) => {
|
|
210
|
-
return tether.query(\`_db.\${tableName}.findFirst\`, options);
|
|
211
|
-
},
|
|
212
|
-
findUnique: async (options) => {
|
|
213
|
-
return tether.query(\`_db.\${tableName}.findUnique\`, options);
|
|
214
|
-
},
|
|
215
|
-
findById: async (id) => {
|
|
216
|
-
return tether.query(\`_db.\${tableName}.findById\`, { id });
|
|
217
|
-
},
|
|
218
|
-
count: async (options) => {
|
|
219
|
-
return tether.query(\`_db.\${tableName}.count\`, options);
|
|
220
|
-
},
|
|
221
|
-
create: async (options) => {
|
|
222
|
-
return tether.mutation(\`_db.\${tableName}.create\`, options);
|
|
223
|
-
},
|
|
224
|
-
insert: async (data) => {
|
|
225
|
-
return tether.mutation(\`_db.\${tableName}.insert\`, { data });
|
|
226
|
-
},
|
|
227
|
-
insertMany: async (data) => {
|
|
228
|
-
return tether.mutation(\`_db.\${tableName}.insertMany\`, { data });
|
|
229
|
-
},
|
|
230
|
-
update: async (options) => {
|
|
231
|
-
return tether.mutation(\`_db.\${tableName}.update\`, options);
|
|
232
|
-
},
|
|
233
|
-
upsert: async (options) => {
|
|
234
|
-
return tether.mutation(\`_db.\${tableName}.upsert\`, options);
|
|
235
|
-
},
|
|
236
|
-
delete: async (options) => {
|
|
237
|
-
return tether.mutation(\`_db.\${tableName}.delete\`, options);
|
|
238
|
-
},
|
|
239
|
-
deleteById: async (id) => {
|
|
240
|
-
return tether.mutation(\`_db.\${tableName}.deleteById\`, { id });
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
},
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// Create tether context for actions
|
|
247
|
-
const tetherContext = {
|
|
248
|
-
query: tether.query.bind(tether),
|
|
249
|
-
mutation: tether.mutation.bind(tether),
|
|
250
|
-
env: new Proxy({}, {
|
|
251
|
-
get(_, key) {
|
|
252
|
-
return process.env[key];
|
|
253
|
-
},
|
|
254
|
-
}),
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
return {
|
|
258
|
-
args,
|
|
259
|
-
db,
|
|
260
|
-
ctx: { auth: { userId: null, claims: {} }, userId: null },
|
|
261
|
-
log,
|
|
262
|
-
tether: tetherContext,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export default defineNitroPlugin(() => {
|
|
267
|
-
console.log('[Tether] Auto-registering functions from tether/functions...');
|
|
268
|
-
|
|
269
|
-
// Iterate through all exported modules
|
|
270
|
-
for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
|
|
271
|
-
if (!moduleExports || typeof moduleExports !== 'object') continue;
|
|
272
|
-
|
|
273
|
-
// Iterate through all exports in each module
|
|
274
|
-
for (const [fnName, fnDef] of Object.entries(moduleExports)) {
|
|
275
|
-
// Check if it's a Tether function definition (has handler property)
|
|
276
|
-
if (!fnDef || typeof fnDef !== 'object' || typeof fnDef.handler !== 'function') continue;
|
|
277
|
-
|
|
278
|
-
const fullName = \`\${moduleName}.\${fnName}\`;
|
|
279
|
-
|
|
280
|
-
// Register the cron handler
|
|
281
|
-
registerCronHandler(fullName, async (args) => {
|
|
282
|
-
const context = createHandlerContext(fullName, args);
|
|
283
|
-
return fnDef.handler(context);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
console.log(\`[Tether] Registered handler: \${fullName}\`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
console.log('[Tether] Function registration complete');
|
|
291
|
-
});
|
|
292
|
-
`,
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
// Add the generated plugin to Nitro
|
|
296
|
-
nuxt.hook('nitro:config' as any, (nitroConfig: any) => {
|
|
297
|
-
nitroConfig.plugins = nitroConfig.plugins || [];
|
|
298
|
-
// Add our generated plugin after the cron plugin
|
|
299
|
-
nitroConfig.plugins.push('#build/server/plugins/tether-functions.js');
|
|
300
|
-
});
|
|
301
161
|
},
|
|
302
162
|
});
|