@tthr/vue 0.0.59 → 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 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, addTemplate } from '@nuxt/kit';
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,132 +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
- // Get the absolute path to user's tether/functions directory for the generated plugin
137
- const tetherFunctionsDir = `${nuxt.options.rootDir}/tether/functions`;
138
- // Generate a server plugin to auto-register cron handlers from tether/functions
139
- // This runs at build time and creates a plugin that imports user's functions
140
- // NOTE: Must be .js file (not .ts) to avoid Rollup parse errors during Nitro build
141
- addTemplate({
142
- filename: 'server/plugins/tether-functions.js',
143
- write: true,
144
- getContents: () => `
145
- /**
146
- * Auto-generated plugin to register Tether functions as cron handlers
147
- * This file is generated by @tthr/vue/nuxt module
148
- */
149
- import { defineNitroPlugin } from 'nitropack/runtime';
150
-
151
- // Absolute path to user's tether functions (injected at build time)
152
- const TETHER_FUNCTIONS_DIR = '${tetherFunctionsDir}';
153
-
154
- /**
155
- * Create a simple logger for function execution
156
- */
157
- function createLogger(functionName) {
158
- const prefix = \`[Tether] \${functionName}\`;
159
- return {
160
- log: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
161
- info: (msg, data) => console.log(prefix, msg, data !== undefined ? data : ''),
162
- warn: (msg, data) => console.warn(prefix, msg, data !== undefined ? data : ''),
163
- error: (msg, data) => console.error(prefix, msg, data !== undefined ? data : ''),
164
- debug: (msg, data) => console.debug(prefix, msg, data !== undefined ? data : ''),
165
- };
166
- }
167
-
168
- /**
169
- * Create the handler context for a function
170
- */
171
- function createHandlerContext(functionName, args, tetherClient) {
172
- const log = createLogger(functionName);
173
-
174
- // Create db proxy that uses tether server client
175
- const db = new Proxy({}, {
176
- get(_, tableName) {
177
- return {
178
- findMany: async (options) => tetherClient.query(\`_db.\${tableName}.findMany\`, options),
179
- findFirst: async (options) => tetherClient.query(\`_db.\${tableName}.findFirst\`, options),
180
- findUnique: async (options) => tetherClient.query(\`_db.\${tableName}.findUnique\`, options),
181
- findById: async (id) => tetherClient.query(\`_db.\${tableName}.findById\`, { id }),
182
- count: async (options) => tetherClient.query(\`_db.\${tableName}.count\`, options),
183
- create: async (options) => tetherClient.mutation(\`_db.\${tableName}.create\`, options),
184
- insert: async (data) => tetherClient.mutation(\`_db.\${tableName}.insert\`, { data }),
185
- insertMany: async (data) => tetherClient.mutation(\`_db.\${tableName}.insertMany\`, { data }),
186
- update: async (options) => tetherClient.mutation(\`_db.\${tableName}.update\`, options),
187
- upsert: async (options) => tetherClient.mutation(\`_db.\${tableName}.upsert\`, options),
188
- delete: async (options) => tetherClient.mutation(\`_db.\${tableName}.delete\`, options),
189
- deleteById: async (id) => tetherClient.mutation(\`_db.\${tableName}.deleteById\`, { id }),
190
- };
191
- },
192
- });
193
-
194
- // Create tether context for actions
195
- const tetherContext = {
196
- query: tetherClient.query.bind(tetherClient),
197
- mutation: tetherClient.mutation.bind(tetherClient),
198
- env: new Proxy({}, {
199
- get(_, key) {
200
- return process.env[key];
201
- },
202
- }),
203
- };
204
-
205
- return {
206
- args,
207
- db,
208
- ctx: { auth: { userId: null, claims: {} }, userId: null },
209
- log,
210
- tether: tetherContext,
211
- };
212
- }
213
-
214
- export default defineNitroPlugin(async () => {
215
- console.log('[Tether] Auto-registering functions from tether/functions...');
216
-
217
- try {
218
- // Dynamically import the cron module and tether server utilities
219
- const { registerCronHandler } = await import('@tthr/vue/nuxt/runtime/server/plugins/cron.js');
220
- const { useTetherServer } = await import('@tthr/vue/nuxt/runtime/server/utils/tether.js');
221
-
222
- // Dynamically import user's tether functions
223
- // This happens at runtime after Nitro has bundled everything
224
- const tetherFunctions = await import('${tetherFunctionsDir}/index');
225
-
226
- // Get the tether client for handler context
227
- const tetherClient = useTetherServer(null);
228
-
229
- // Iterate through all exported modules
230
- for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
231
- if (!moduleExports || typeof moduleExports !== 'object') continue;
232
-
233
- // Iterate through all exports in each module
234
- for (const [fnName, fnDef] of Object.entries(moduleExports)) {
235
- // Check if it's a Tether function definition (has handler property)
236
- if (!fnDef || typeof fnDef !== 'object' || typeof fnDef.handler !== 'function') continue;
237
-
238
- const fullName = \`\${moduleName}.\${fnName}\`;
239
-
240
- // Register the cron handler
241
- registerCronHandler(fullName, async (args) => {
242
- const context = createHandlerContext(fullName, args, tetherClient);
243
- return fnDef.handler(context);
244
- });
245
-
246
- console.log(\`[Tether] Registered handler: \${fullName}\`);
247
- }
248
- }
249
-
250
- console.log('[Tether] Function registration complete');
251
- } catch (error) {
252
- console.error('[Tether] Failed to register functions:', error);
253
- }
254
- });
255
- `,
256
- });
257
- // Add the generated plugin to Nitro
258
- nuxt.hook('nitro:config', (nitroConfig) => {
259
- nitroConfig.plugins = nitroConfig.plugins || [];
260
- // Add our generated plugin after the cron plugin
261
- nitroConfig.plugins.push('#build/server/plugins/tether-functions.js');
262
- });
263
136
  },
264
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, addTemplate } from '@nuxt/kit';
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,135 +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
- // Get the absolute path to user's tether/functions directory for the generated plugin
163
- const tetherFunctionsDir = `${nuxt.options.rootDir}/tether/functions`;
164
-
165
- // Generate a server plugin to auto-register cron handlers from tether/functions
166
- // This runs at build time and creates a plugin that imports user's functions
167
- // NOTE: Must be .js file (not .ts) to avoid Rollup parse errors during Nitro build
168
- addTemplate({
169
- filename: 'server/plugins/tether-functions.js',
170
- write: true,
171
- getContents: () => `
172
- /**
173
- * Auto-generated plugin to register Tether functions as cron handlers
174
- * This file is generated by @tthr/vue/nuxt module
175
- */
176
- import { defineNitroPlugin } from 'nitropack/runtime';
177
-
178
- // Absolute path to user's tether functions (injected at build time)
179
- const TETHER_FUNCTIONS_DIR = '${tetherFunctionsDir}';
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, tetherClient) {
199
- const log = createLogger(functionName);
200
-
201
- // Create db proxy that uses tether server client
202
- const db = new Proxy({}, {
203
- get(_, tableName) {
204
- return {
205
- findMany: async (options) => tetherClient.query(\`_db.\${tableName}.findMany\`, options),
206
- findFirst: async (options) => tetherClient.query(\`_db.\${tableName}.findFirst\`, options),
207
- findUnique: async (options) => tetherClient.query(\`_db.\${tableName}.findUnique\`, options),
208
- findById: async (id) => tetherClient.query(\`_db.\${tableName}.findById\`, { id }),
209
- count: async (options) => tetherClient.query(\`_db.\${tableName}.count\`, options),
210
- create: async (options) => tetherClient.mutation(\`_db.\${tableName}.create\`, options),
211
- insert: async (data) => tetherClient.mutation(\`_db.\${tableName}.insert\`, { data }),
212
- insertMany: async (data) => tetherClient.mutation(\`_db.\${tableName}.insertMany\`, { data }),
213
- update: async (options) => tetherClient.mutation(\`_db.\${tableName}.update\`, options),
214
- upsert: async (options) => tetherClient.mutation(\`_db.\${tableName}.upsert\`, options),
215
- delete: async (options) => tetherClient.mutation(\`_db.\${tableName}.delete\`, options),
216
- deleteById: async (id) => tetherClient.mutation(\`_db.\${tableName}.deleteById\`, { id }),
217
- };
218
- },
219
- });
220
-
221
- // Create tether context for actions
222
- const tetherContext = {
223
- query: tetherClient.query.bind(tetherClient),
224
- mutation: tetherClient.mutation.bind(tetherClient),
225
- env: new Proxy({}, {
226
- get(_, key) {
227
- return process.env[key];
228
- },
229
- }),
230
- };
231
-
232
- return {
233
- args,
234
- db,
235
- ctx: { auth: { userId: null, claims: {} }, userId: null },
236
- log,
237
- tether: tetherContext,
238
- };
239
- }
240
-
241
- export default defineNitroPlugin(async () => {
242
- console.log('[Tether] Auto-registering functions from tether/functions...');
243
-
244
- try {
245
- // Dynamically import the cron module and tether server utilities
246
- const { registerCronHandler } = await import('@tthr/vue/nuxt/runtime/server/plugins/cron.js');
247
- const { useTetherServer } = await import('@tthr/vue/nuxt/runtime/server/utils/tether.js');
248
-
249
- // Dynamically import user's tether functions
250
- // This happens at runtime after Nitro has bundled everything
251
- const tetherFunctions = await import('${tetherFunctionsDir}/index');
252
-
253
- // Get the tether client for handler context
254
- const tetherClient = useTetherServer(null);
255
-
256
- // Iterate through all exported modules
257
- for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
258
- if (!moduleExports || typeof moduleExports !== 'object') continue;
259
-
260
- // Iterate through all exports in each module
261
- for (const [fnName, fnDef] of Object.entries(moduleExports)) {
262
- // Check if it's a Tether function definition (has handler property)
263
- if (!fnDef || typeof fnDef !== 'object' || typeof fnDef.handler !== 'function') continue;
264
-
265
- const fullName = \`\${moduleName}.\${fnName}\`;
266
-
267
- // Register the cron handler
268
- registerCronHandler(fullName, async (args) => {
269
- const context = createHandlerContext(fullName, args, tetherClient);
270
- return fnDef.handler(context);
271
- });
272
-
273
- console.log(\`[Tether] Registered handler: \${fullName}\`);
274
- }
275
- }
276
-
277
- console.log('[Tether] Function registration complete');
278
- } catch (error) {
279
- console.error('[Tether] Failed to register functions:', error);
280
- }
281
- });
282
- `,
283
- });
284
-
285
- // Add the generated plugin to Nitro
286
- nuxt.hook('nitro:config' as any, (nitroConfig: any) => {
287
- nitroConfig.plugins = nitroConfig.plugins || [];
288
- // Add our generated plugin after the cron plugin
289
- nitroConfig.plugins.push('#build/server/plugins/tether-functions.js');
290
- });
291
161
  },
292
162
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tthr/vue",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "description": "Tether Vue/Nuxt SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",