tthr 0.0.53 → 0.0.54

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -217,14 +217,16 @@ async function deployFunctionsToServer(projectId, token, functionsDir, environme
217
217
  console.log(chalk.dim(`
218
218
  Queries:`));
219
219
  for (const fn of queries) {
220
- console.log(chalk.dim(` - ${fn.name}`));
220
+ const argsInfo = fn.args ? chalk.green(" (has args)") : "";
221
+ console.log(chalk.dim(` - ${fn.name}${argsInfo}`));
221
222
  }
222
223
  }
223
224
  if (mutations.length > 0) {
224
225
  console.log(chalk.dim(`
225
226
  Mutations:`));
226
227
  for (const fn of mutations) {
227
- console.log(chalk.dim(` - ${fn.name}`));
228
+ const argsInfo = fn.args ? chalk.green(" (has args)") : "";
229
+ console.log(chalk.dim(` - ${fn.name}${argsInfo}`));
228
230
  }
229
231
  }
230
232
  } catch (error) {
@@ -317,7 +319,7 @@ function getColumnSqlType(type) {
317
319
  }
318
320
  function buildColumnSql(colName, def, forAlterTable = false) {
319
321
  const sqlType = getColumnSqlType(def.type);
320
- let colSql = `${colName} ${sqlType}`;
322
+ let colSql = `"${colName}" ${sqlType}`;
321
323
  if (def.notNull && !forAlterTable) colSql += " NOT NULL";
322
324
  if (def.unique) colSql += " UNIQUE";
323
325
  if (def.hasDefault && def.type === "timestamp" && !forAlterTable) {
@@ -325,7 +327,7 @@ function buildColumnSql(colName, def, forAlterTable = false) {
325
327
  }
326
328
  if (def.references) {
327
329
  const [refTable, refCol] = def.references.split(".");
328
- colSql += ` REFERENCES ${refTable}(${refCol})`;
330
+ colSql += ` REFERENCES "${refTable}"("${refCol || "_id"}")`;
329
331
  }
330
332
  return colSql;
331
333
  }
@@ -338,7 +340,7 @@ function generateSchemaSQL(tables) {
338
340
  columnDefs.push(buildColumnSql(colName, def));
339
341
  }
340
342
  statements.push(
341
- `CREATE TABLE IF NOT EXISTS ${table.name} (
343
+ `CREATE TABLE IF NOT EXISTS "${table.name}" (
342
344
  ${columnDefs.join(",\n ")}
343
345
  );`
344
346
  );
@@ -347,7 +349,7 @@ function generateSchemaSQL(tables) {
347
349
  const alterColSql = buildColumnSql(colName, def, true);
348
350
  statements.push(
349
351
  `-- Add column if missing (will error if exists, which is OK)
350
- ALTER TABLE ${table.name} ADD COLUMN ${alterColSql};`
352
+ ALTER TABLE "${table.name}" ADD COLUMN ${alterColSql};`
351
353
  );
352
354
  }
353
355
  }
@@ -374,9 +376,25 @@ function parseFunctions(moduleName, source) {
374
376
  }
375
377
  const fnBody = source.slice(startIndex, endIndex);
376
378
  let args;
377
- const argsMatch = fnBody.match(/args\s*:\s*(z\.object\s*\(\s*\{[\s\S]*?\}\s*\))/);
378
- if (argsMatch) {
379
- args = argsMatch[1];
379
+ const argsStartMatch = fnBody.match(/args\s*:\s*(z\.object\s*\(\s*\{)/);
380
+ if (argsStartMatch && argsStartMatch.index !== void 0) {
381
+ const argsStartIndex = argsStartMatch.index + argsStartMatch[0].length - 1;
382
+ let braceCount = 1;
383
+ let endIndex2 = argsStartIndex + 1;
384
+ for (let i = argsStartIndex + 1; i < fnBody.length && braceCount > 0; i++) {
385
+ const char = fnBody[i];
386
+ if (char === "{") braceCount++;
387
+ else if (char === "}") braceCount--;
388
+ endIndex2 = i;
389
+ }
390
+ let parenEndIndex = endIndex2 + 1;
391
+ while (parenEndIndex < fnBody.length && fnBody[parenEndIndex] !== ")") {
392
+ parenEndIndex++;
393
+ }
394
+ const objectStart = fnBody.indexOf("z.object", argsStartMatch.index);
395
+ if (objectStart !== -1) {
396
+ args = fnBody.slice(objectStart, parenEndIndex + 1);
397
+ }
380
398
  }
381
399
  functions.push({
382
400
  name: `${moduleName}.${fnName}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tthr",
3
- "version": "0.0.53",
3
+ "version": "0.0.54",
4
4
  "description": "Tether CLI - project scaffolding and deployment",
5
5
  "type": "module",
6
6
  "bin": {