sasat 0.19.39 → 0.19.41

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/lib/cli/cli.js CHANGED
@@ -5,6 +5,7 @@ import { migrate } from './commands/migrate.js';
5
5
  import { init } from './commands/init.js';
6
6
  import { generate } from './commands/generate.js';
7
7
  import { dumpDB } from './commands/dumpDb.js';
8
+ import * as console from 'console';
8
9
  const cli = cac();
9
10
  try {
10
11
  cli
@@ -14,7 +15,8 @@ try {
14
15
  .option('-d, --dry', 'dry run')
15
16
  .option('-s, --silent', 'do not print logs')
16
17
  .action(async (options) => {
17
- await migrate(options).catch(() => {
18
+ await migrate(options).catch(e => {
19
+ console.error(e);
18
20
  process.exit(1);
19
21
  });
20
22
  });
@@ -6,6 +6,7 @@ import { getDbClient } from '../../db/getDbClient.js';
6
6
  import { CodeGen_v2 } from '../../generatorv2/codegen_v2.js';
7
7
  export const migrate = async (options) => {
8
8
  let current;
9
+ Console.log('--migration started--');
9
10
  try {
10
11
  const migration = new MigrationController();
11
12
  const result = await migration.migrate(options);
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ListQueryOption } from './runtime/sasatDBDatasource.js';
2
- export { ResolverMiddleware } from './runtime/resolverMiddleware.js';
2
+ export { ResolverMiddleware, makeParamsMiddleware, } from './runtime/resolverMiddleware.js';
3
3
  export { makeNumberIdEncoder } from './runtime/id.js';
4
4
  export type { CustomCondition } from './runtime/types.js';
5
5
  export { Queries } from './migration/makeQuery.js';
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { makeParamsMiddleware, } from './runtime/resolverMiddleware.js';
1
2
  export { makeNumberIdEncoder } from './runtime/id.js';
2
3
  export { Queries } from './migration/makeQuery.js';
3
4
  export { Mutations } from './migration/makeMutaion.js';
@@ -9,7 +9,7 @@ import { Console } from '../cli/console.js';
9
9
  export class MigrationController {
10
10
  async migrate(options) {
11
11
  const fileNames = await compileMigrationFiles();
12
- const currentMigration = await getCurrentMigration();
12
+ const currentMigration = await getCurrentMigration(options);
13
13
  Console.log('--current migration--: ' + currentMigration);
14
14
  let store = await createCurrentMigrationDataStore(currentMigration);
15
15
  const target = getMigrationTargets(fileNames, currentMigration);
@@ -1,5 +1,6 @@
1
+ import { MigrateCommandOption } from 'cli/commands/migrate';
1
2
  export declare enum Direction {
2
3
  Up = "up",
3
4
  Down = "down"
4
5
  }
5
- export declare const getCurrentMigration: () => Promise<string | undefined>;
6
+ export declare const getCurrentMigration: (options: MigrateCommandOption) => Promise<string | undefined>;
@@ -1,6 +1,7 @@
1
1
  import { config } from '../../config/config.js';
2
2
  import { getDbClient } from '../../db/getDbClient.js';
3
3
  import { getMigrationFileNames } from './getMigrationFiles.js';
4
+ import { Console } from 'cli/console';
4
5
  export var Direction;
5
6
  (function (Direction) {
6
7
  Direction["Up"] = "up";
@@ -19,13 +20,18 @@ const calcRunMigrationFileNames = (records) => {
19
20
  });
20
21
  return result;
21
22
  };
22
- export const getCurrentMigration = async () => {
23
+ export const getCurrentMigration = async (options) => {
23
24
  const migrationTable = config().migration.table;
24
25
  const files = getMigrationFileNames();
25
26
  const client = getDbClient();
26
- await client.rawQuery(`CREATE TABLE IF NOT EXISTS ${migrationTable} ` +
27
+ const query = `CREATE TABLE IF NOT EXISTS ${migrationTable} ` +
27
28
  '(id int auto_increment primary key , name varchar(100) not null,' +
28
- "direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)");
29
+ "direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)";
30
+ if (!options.silent) {
31
+ Console.log(`creating migration table: ${migrationTable} :: ${Buffer.from(migrationTable).toString('base64')}`);
32
+ Console.log(query);
33
+ }
34
+ await client.rawQuery(query);
29
35
  const result = await client.rawQuery(`SELECT name, direction
30
36
  FROM ${migrationTable}
31
37
  ORDER BY id ASC`);
@@ -1,2 +1,3 @@
1
1
  import { ResolverArgs } from './makeResolver.js';
2
2
  export type ResolverMiddleware<Context, RequiredParams = any, IncomingParams = RequiredParams> = (args: ResolverArgs<Context, IncomingParams | RequiredParams>) => ResolverArgs<Context, RequiredParams | IncomingParams>;
3
+ export declare const makeParamsMiddleware: <RequiredParams, IncomingParams = RequiredParams>(update: (params: RequiredParams) => IncomingParams) => ResolverMiddleware<never, RequiredParams, IncomingParams>;
@@ -1 +1,6 @@
1
- export {};
1
+ export const makeParamsMiddleware = (update) => {
2
+ return args => {
3
+ args[1] = update(args[1]);
4
+ return args;
5
+ };
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.19.39",
3
+ "version": "0.19.41",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",