@pikku/cli 0.12.36 → 0.12.38

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 (67) hide show
  1. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  2. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
  3. package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
  4. package/dist/.pikku/cli/pikku-cli-channel.js +1 -1
  5. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  6. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  7. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
  8. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  9. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  10. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  11. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  12. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  13. package/dist/.pikku/function/pikku-function-types.gen.d.ts +1 -1
  14. package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
  15. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  16. package/dist/.pikku/function/pikku-functions-meta.gen.json +179 -179
  17. package/dist/.pikku/function/pikku-functions.gen.js +1 -1
  18. package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
  19. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  20. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
  21. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  22. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  23. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
  24. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
  25. package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
  26. package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
  27. package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
  28. package/dist/.pikku/pikku-meta-service.gen.js +1 -1
  29. package/dist/.pikku/pikku-services.gen.d.ts +1 -1
  30. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  31. package/dist/.pikku/pikku-types.gen.js +1 -1
  32. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  33. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  34. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
  35. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
  36. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
  37. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
  38. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +1 -1
  39. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  40. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  41. package/dist/.pikku/schemas/register.gen.js +9 -9
  42. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  43. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  44. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  45. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  46. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  47. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  48. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  49. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  50. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  51. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  52. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
  53. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
  54. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  55. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  56. package/dist/bin/pikku-bin.mjs +2 -2
  57. package/dist/src/fabric/functions/validate-core.js +7 -7
  58. package/dist/src/fabric/functions/validate.function.js +40 -28
  59. package/dist/src/fabric/lib/config.d.ts +4 -4
  60. package/dist/src/fabric/lib/config.js +2 -2
  61. package/dist/src/functions/db/better-auth-schema.js +33 -11
  62. package/dist/src/functions/db/db-codegen.js +9 -5
  63. package/dist/src/functions/db/local-db.d.ts +2 -2
  64. package/dist/src/functions/db/local-db.js +111 -5
  65. package/dist/src/functions/db/sqlite/sqlite-runtime-node.js +2 -1
  66. package/dist/src/scaffold/rpc-remote.gen.js +1 -1
  67. package/package.json +4 -4
@@ -3,6 +3,7 @@ import { resolve, isAbsolute, relative, dirname, join } from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
4
  import { runInNewContext } from 'node:vm';
5
5
  import { transformSync } from 'esbuild';
6
+ import { CamelCasePlugin, CompiledQuery, Kysely, PostgresDialect } from 'kysely';
6
7
  import { migrate } from './db-migrator.js';
7
8
  import { loadAuthOptions, getAuthMigrations } from './better-auth-schema.js';
8
9
  import { generateSchemaTypes } from './db-codegen.js';
@@ -319,14 +320,114 @@ function diffSchemas(desired, actual) {
319
320
  }
320
321
  return { missingTables, missingColumns };
321
322
  }
322
- export async function desiredAuthSchema(rootDir, srcDirectories, logger) {
323
+ function isPostgresAuthDatabase(options) {
324
+ return options.database?.type === 'postgres';
325
+ }
326
+ function createScratchPostgresSchemaName() {
327
+ const random = Math.random().toString(36).slice(2, 10);
328
+ return `pikku_auth_${Date.now().toString(36)}_${random}`;
329
+ }
330
+ async function postgresSchemaToMap(connectionString, schema) {
331
+ const { Client } = await import('pg');
332
+ const client = new Client({ connectionString });
333
+ await client.connect();
334
+ try {
335
+ const tablesResult = await client.query(`SELECT table_name
336
+ FROM information_schema.tables
337
+ WHERE table_schema = $1
338
+ AND table_type = 'BASE TABLE'
339
+ ORDER BY table_name`, [schema]);
340
+ const map = new Map();
341
+ for (const { table_name } of tablesResult.rows) {
342
+ const columnsResult = await client.query(`SELECT column_name
343
+ FROM information_schema.columns
344
+ WHERE table_schema = $1
345
+ AND table_name = $2
346
+ ORDER BY ordinal_position`, [schema, table_name]);
347
+ map.set(table_name, new Set(columnsResult.rows.map((c) => c.column_name)));
348
+ }
349
+ return map;
350
+ }
351
+ finally {
352
+ await client.end();
353
+ }
354
+ }
355
+ async function desiredPostgresAuthSchema(resolved, rootDir, srcDirectories, logger) {
356
+ const { Pool } = await import('pg');
357
+ const schema = createScratchPostgresSchemaName();
358
+ const pool = new Pool({
359
+ connectionString: resolved.connectionString,
360
+ max: 1,
361
+ });
362
+ try {
363
+ const admin = await pool.connect();
364
+ try {
365
+ await admin.query(`CREATE SCHEMA "${schema}"`);
366
+ await admin.query(`SET search_path TO "${schema}"`);
367
+ }
368
+ finally {
369
+ admin.release();
370
+ }
371
+ const kysely = new Kysely({
372
+ dialect: new PostgresDialect({
373
+ pool,
374
+ onReserveConnection: async (connection) => {
375
+ await connection.executeQuery(CompiledQuery.raw(`SET search_path TO "${schema}"`));
376
+ },
377
+ }),
378
+ plugins: [new CamelCasePlugin()],
379
+ }).withSchema(schema);
380
+ try {
381
+ const options = await loadAuthOptions({
382
+ rootDir,
383
+ srcDirectories,
384
+ kysely,
385
+ logger,
386
+ });
387
+ if (!options)
388
+ return null;
389
+ const { runMigrations, compileMigrations } = await getAuthMigrations(options);
390
+ await runMigrations();
391
+ const tables = await postgresSchemaToMap(resolved.connectionString, schema);
392
+ const sql = await compileMigrations();
393
+ return { tables, sql };
394
+ }
395
+ finally {
396
+ await kysely.destroy();
397
+ }
398
+ }
399
+ finally {
400
+ const cleanup = new Pool({
401
+ connectionString: resolved.connectionString,
402
+ max: 1,
403
+ });
404
+ try {
405
+ await cleanup.query(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`);
406
+ }
407
+ finally {
408
+ await cleanup.end();
409
+ }
410
+ }
411
+ }
412
+ export async function desiredAuthSchema(resolved, rootDir, srcDirectories, logger) {
323
413
  const runtime = await loadSqliteRuntime();
324
414
  const db = runtime.open(':memory:');
325
415
  try {
326
416
  const kysely = createSqliteKysely({ db, camelCase: true });
327
- const options = await loadAuthOptions({ rootDir, srcDirectories, kysely, logger });
417
+ const options = await loadAuthOptions({
418
+ rootDir,
419
+ srcDirectories,
420
+ kysely,
421
+ logger,
422
+ });
328
423
  if (!options)
329
424
  return null;
425
+ if (isPostgresAuthDatabase(options)) {
426
+ if (resolved.dialect !== 'postgres') {
427
+ throw new Error('Better Auth database.type is postgres, but the resolved app database is not postgres.');
428
+ }
429
+ return desiredPostgresAuthSchema(resolved, rootDir, srcDirectories, logger);
430
+ }
330
431
  const { runMigrations, compileMigrations } = await getAuthMigrations(options);
331
432
  await runMigrations();
332
433
  const tables = await introspectorToMap(new SqliteIntrospector(db));
@@ -369,9 +470,14 @@ async function coveredSqliteSchema(migrationsDir) {
369
470
  }
370
471
  }
371
472
  export async function computeAuthDrift(resolved, rootDir, srcDirectories, logger) {
372
- const desired = await desiredAuthSchema(rootDir, srcDirectories, logger);
473
+ const desired = await desiredAuthSchema(resolved, rootDir, srcDirectories, logger);
373
474
  if (!desired) {
374
- return { hasAuth: false, inSync: true, missingTables: [], missingColumns: [] };
475
+ return {
476
+ hasAuth: false,
477
+ inSync: true,
478
+ missingTables: [],
479
+ missingColumns: [],
480
+ };
375
481
  }
376
482
  const actual = await introspectSchema(resolved);
377
483
  const { missingTables, missingColumns } = diffSchemas(desired.tables, actual);
@@ -401,7 +507,7 @@ function nextMigrationFile(migrationsDir, label) {
401
507
  export async function generateAuthMigration(resolved, rootDir, srcDirectories, logger) {
402
508
  if (resolved.dialect !== 'sqlite')
403
509
  return { status: 'unsupported-dialect' };
404
- const desired = await desiredAuthSchema(rootDir, srcDirectories, logger);
510
+ const desired = await desiredAuthSchema(resolved, rootDir, srcDirectories, logger);
405
511
  if (!desired)
406
512
  return { status: 'no-auth' };
407
513
  const covered = await coveredSqliteSchema(resolved.migrationsDir);
@@ -15,7 +15,8 @@ class NodeSqliteStatement {
15
15
  upper.startsWith('WITH') ||
16
16
  upper.startsWith('PRAGMA') ||
17
17
  upper.startsWith('EXPLAIN') ||
18
- upper.startsWith('VALUES');
18
+ upper.startsWith('VALUES') ||
19
+ /\bRETURNING\b/.test(upper);
19
20
  }
20
21
  }
21
22
  all(...parameters) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file was generated by @pikku/cli@0.12.36
2
+ * This file was generated by @pikku/cli@0.12.38
3
3
  */
4
4
  /**
5
5
  * Auto-generated remote internal RPC queue worker and HTTP endpoint
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.12.36",
3
+ "version": "0.12.38",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "BUSL-1.1",
6
6
  "imports": {
@@ -26,13 +26,13 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@openapi-contrib/json-schema-to-openapi-schema": "^4.3.1",
29
- "@pikku/better-auth": "workspace:*",
29
+ "@pikku/better-auth": "^0.12.6",
30
30
  "@pikku/core": "^0.12.32",
31
31
  "@pikku/deploy-cloudflare": "^0.12.3",
32
32
  "@pikku/fetch": "^0.12.3",
33
33
  "@pikku/inspector": "^0.12.20",
34
- "@pikku/kysely": "^0.12.14",
35
- "@pikku/kysely-node-sqlite": "^0.12.1",
34
+ "@pikku/kysely": "^0.12.16",
35
+ "@pikku/kysely-node-sqlite": "^0.12.2",
36
36
  "@pikku/node-http-server": "^0.12.2",
37
37
  "@pikku/openapi-parser": "^0.12.10",
38
38
  "@pikku/schedule": "^0.12.0",