@tthr/vue 0.0.57 → 0.0.59

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
@@ -133,6 +133,8 @@ 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`;
136
138
  // Generate a server plugin to auto-register cron handlers from tether/functions
137
139
  // This runs at build time and creates a plugin that imports user's functions
138
140
  // NOTE: Must be .js file (not .ts) to avoid Rollup parse errors during Nitro build
@@ -144,13 +146,10 @@ export default defineNuxtModule({
144
146
  * Auto-generated plugin to register Tether functions as cron handlers
145
147
  * This file is generated by @tthr/vue/nuxt module
146
148
  */
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
+ import { defineNitroPlugin } from 'nitropack/runtime';
149
150
 
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';
151
+ // Absolute path to user's tether functions (injected at build time)
152
+ const TETHER_FUNCTIONS_DIR = '${tetherFunctionsDir}';
154
153
 
155
154
  /**
156
155
  * Create a simple logger for function execution
@@ -169,58 +168,33 @@ function createLogger(functionName) {
169
168
  /**
170
169
  * Create the handler context for a function
171
170
  */
172
- function createHandlerContext(functionName, args) {
173
- const tether = useTetherServer(null);
171
+ function createHandlerContext(functionName, args, tetherClient) {
174
172
  const log = createLogger(functionName);
175
173
 
176
174
  // Create db proxy that uses tether server client
177
175
  const db = new Proxy({}, {
178
176
  get(_, tableName) {
179
177
  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
- },
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 }),
216
190
  };
217
191
  },
218
192
  });
219
193
 
220
194
  // Create tether context for actions
221
195
  const tetherContext = {
222
- query: tether.query.bind(tether),
223
- mutation: tether.mutation.bind(tether),
196
+ query: tetherClient.query.bind(tetherClient),
197
+ mutation: tetherClient.mutation.bind(tetherClient),
224
198
  env: new Proxy({}, {
225
199
  get(_, key) {
226
200
  return process.env[key];
@@ -237,31 +211,46 @@ function createHandlerContext(functionName, args) {
237
211
  };
238
212
  }
239
213
 
240
- export default defineNitroPlugin(() => {
214
+ export default defineNitroPlugin(async () => {
241
215
  console.log('[Tether] Auto-registering functions from tether/functions...');
242
216
 
243
- // Iterate through all exported modules
244
- for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
245
- if (!moduleExports || typeof moduleExports !== 'object') continue;
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);
246
228
 
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;
229
+ // Iterate through all exported modules
230
+ for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
231
+ if (!moduleExports || typeof moduleExports !== 'object') continue;
251
232
 
252
- const fullName = \`\${moduleName}.\${fnName}\`;
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;
253
237
 
254
- // Register the cron handler
255
- registerCronHandler(fullName, async (args) => {
256
- const context = createHandlerContext(fullName, args);
257
- return fnDef.handler(context);
258
- });
238
+ const fullName = \`\${moduleName}.\${fnName}\`;
259
239
 
260
- console.log(\`[Tether] Registered handler: \${fullName}\`);
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
+ }
261
248
  }
262
- }
263
249
 
264
- console.log('[Tether] Function registration complete');
250
+ console.log('[Tether] Function registration complete');
251
+ } catch (error) {
252
+ console.error('[Tether] Failed to register functions:', error);
253
+ }
265
254
  });
266
255
  `,
267
256
  });
package/nuxt/module.ts CHANGED
@@ -159,6 +159,9 @@ export default defineNuxtModule<TetherModuleOptions>({
159
159
  nitroConfig.externals.inline.push(`${nuxt.options.rootDir}/tether`);
160
160
  });
161
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
+
162
165
  // Generate a server plugin to auto-register cron handlers from tether/functions
163
166
  // This runs at build time and creates a plugin that imports user's functions
164
167
  // NOTE: Must be .js file (not .ts) to avoid Rollup parse errors during Nitro build
@@ -170,13 +173,10 @@ export default defineNuxtModule<TetherModuleOptions>({
170
173
  * Auto-generated plugin to register Tether functions as cron handlers
171
174
  * This file is generated by @tthr/vue/nuxt module
172
175
  */
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';
176
+ import { defineNitroPlugin } from 'nitropack/runtime';
175
177
 
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';
178
+ // Absolute path to user's tether functions (injected at build time)
179
+ const TETHER_FUNCTIONS_DIR = '${tetherFunctionsDir}';
180
180
 
181
181
  /**
182
182
  * Create a simple logger for function execution
@@ -195,58 +195,33 @@ function createLogger(functionName) {
195
195
  /**
196
196
  * Create the handler context for a function
197
197
  */
198
- function createHandlerContext(functionName, args) {
199
- const tether = useTetherServer(null);
198
+ function createHandlerContext(functionName, args, tetherClient) {
200
199
  const log = createLogger(functionName);
201
200
 
202
201
  // Create db proxy that uses tether server client
203
202
  const db = new Proxy({}, {
204
203
  get(_, tableName) {
205
204
  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
- },
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 }),
242
217
  };
243
218
  },
244
219
  });
245
220
 
246
221
  // Create tether context for actions
247
222
  const tetherContext = {
248
- query: tether.query.bind(tether),
249
- mutation: tether.mutation.bind(tether),
223
+ query: tetherClient.query.bind(tetherClient),
224
+ mutation: tetherClient.mutation.bind(tetherClient),
250
225
  env: new Proxy({}, {
251
226
  get(_, key) {
252
227
  return process.env[key];
@@ -263,31 +238,46 @@ function createHandlerContext(functionName, args) {
263
238
  };
264
239
  }
265
240
 
266
- export default defineNitroPlugin(() => {
241
+ export default defineNitroPlugin(async () => {
267
242
  console.log('[Tether] Auto-registering functions from tether/functions...');
268
243
 
269
- // Iterate through all exported modules
270
- for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
271
- if (!moduleExports || typeof moduleExports !== 'object') continue;
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);
272
255
 
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;
256
+ // Iterate through all exported modules
257
+ for (const [moduleName, moduleExports] of Object.entries(tetherFunctions)) {
258
+ if (!moduleExports || typeof moduleExports !== 'object') continue;
277
259
 
278
- const fullName = \`\${moduleName}.\${fnName}\`;
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;
279
264
 
280
- // Register the cron handler
281
- registerCronHandler(fullName, async (args) => {
282
- const context = createHandlerContext(fullName, args);
283
- return fnDef.handler(context);
284
- });
265
+ const fullName = \`\${moduleName}.\${fnName}\`;
285
266
 
286
- console.log(\`[Tether] Registered handler: \${fullName}\`);
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
+ }
287
275
  }
288
- }
289
276
 
290
- console.log('[Tether] Function registration complete');
277
+ console.log('[Tether] Function registration complete');
278
+ } catch (error) {
279
+ console.error('[Tether] Failed to register functions:', error);
280
+ }
291
281
  });
292
282
  `,
293
283
  });
@@ -19,7 +19,6 @@
19
19
  */
20
20
 
21
21
  import { createError } from 'h3';
22
- import { useRuntimeConfig } from '#imports';
23
22
 
24
23
  /**
25
24
  * Get a Tether client for use in server-side code
@@ -28,11 +27,11 @@ import { useRuntimeConfig } from '#imports';
28
27
  * @returns A Tether client with query, mutation, and storage methods
29
28
  */
30
29
  export function useTetherServer(_event) {
31
- const config = useRuntimeConfig();
32
-
33
- const apiKey = config.tether?.apiKey || process.env.TETHER_API_KEY;
34
- const url = config.tether?.url || process.env.TETHER_URL || 'https://tether-api.strands.gg';
35
- const projectId = config.tether?.projectId || process.env.TETHER_PROJECT_ID;
30
+ // Use process.env directly to avoid #imports dependency
31
+ // The Nuxt module sets NUXT_TETHER_* vars from runtime config
32
+ const apiKey = process.env.NUXT_TETHER_API_KEY || process.env.TETHER_API_KEY;
33
+ const url = process.env.NUXT_TETHER_URL || process.env.TETHER_URL || 'https://tether-api.strands.gg';
34
+ const projectId = process.env.NUXT_TETHER_PROJECT_ID || process.env.TETHER_PROJECT_ID;
36
35
 
37
36
  if (!apiKey) {
38
37
  throw createError({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tthr/vue",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "description": "Tether Vue/Nuxt SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",