sonamu 0.5.4 → 0.5.6

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 (38) hide show
  1. package/dist/api/code-converters.d.ts +8 -5
  2. package/dist/api/code-converters.d.ts.map +1 -1
  3. package/dist/api/code-converters.js +1 -1
  4. package/dist/api/code-converters.js.map +1 -1
  5. package/dist/api/context.d.ts +9 -2
  6. package/dist/api/context.d.ts.map +1 -1
  7. package/dist/api/sonamu.d.ts +1 -0
  8. package/dist/api/sonamu.d.ts.map +1 -1
  9. package/dist/api/sonamu.js +1 -1
  10. package/dist/api/sonamu.js.map +1 -1
  11. package/dist/bin/build-config.d.ts +4 -0
  12. package/dist/bin/build-config.d.ts.map +1 -1
  13. package/dist/bin/build-config.js +1 -1
  14. package/dist/bin/build-config.js.map +1 -1
  15. package/dist/bin/cli-wrapper.js +1 -1
  16. package/dist/bin/cli-wrapper.js.map +1 -1
  17. package/dist/database/puri.d.ts +1 -0
  18. package/dist/database/puri.d.ts.map +1 -1
  19. package/dist/database/puri.js +1 -1
  20. package/dist/database/puri.js.map +1 -1
  21. package/dist/database/puri.types.d.ts +1 -1
  22. package/dist/database/puri.types.d.ts.map +1 -1
  23. package/dist/types/types.d.ts +11 -2
  24. package/dist/types/types.d.ts.map +1 -1
  25. package/dist/types/types.js.map +1 -1
  26. package/package.json +5 -2
  27. package/src/api/code-converters.ts +41 -31
  28. package/src/api/context.ts +11 -2
  29. package/src/api/sonamu.ts +43 -2
  30. package/src/bin/build-config.ts +7 -3
  31. package/src/bin/cli-wrapper.ts +31 -12
  32. package/src/database/puri.ts +19 -0
  33. package/src/database/puri.types.ts +4 -2
  34. package/src/types/types.ts +18 -2
  35. package/dist/entity/migrator.d.ts +0 -135
  36. package/dist/entity/migrator.d.ts.map +0 -1
  37. package/dist/entity/migrator.js +0 -2
  38. package/dist/entity/migrator.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import type { $ZodLooseShape } from "zod/v4/core"
2
3
  import {
3
4
  ApiParam,
4
5
  ApiParamType,
@@ -26,6 +27,17 @@ import {
26
27
  isVirtualProp,
27
28
  } from "../types/types";
28
29
  import { ExtendedApi } from "./decorators";
30
+ import type { Literal } from "zod/v4/core/util";
31
+
32
+ // <any>를 자제하고, Zod에서 제약하는 기본적인 Generic Type Parameter를 사용함.
33
+ type AnyZodRecord = z.ZodRecord<z.ZodString | z.ZodNumber | z.ZodSymbol, z.ZodType>;
34
+ type AnyZodObject = z.ZodObject<$ZodLooseShape>;
35
+ type AnyZodArray = z.ZodArray<z.ZodType>;
36
+ type AnyZodNullable = z.ZodNullable<z.ZodType>;
37
+ type AnyZodOptional = z.ZodOptional<z.ZodType>;
38
+ type AnyZodDefault = z.ZodDefault<z.ZodType>;
39
+ type AnyZodLiteral = z.ZodLiteral<Literal>;
40
+ type AnyZodUnion = z.ZodUnion<z.ZodType[]>;
29
41
 
30
42
  /*
31
43
  ExtendedApi 에서 ZodObject 리턴
@@ -33,7 +45,7 @@ import { ExtendedApi } from "./decorators";
33
45
  export function getZodObjectFromApi(
34
46
  api: ExtendedApi,
35
47
  references: {
36
- [id: string]: z.ZodObject<any>;
48
+ [id: string]: AnyZodObject;
37
49
  } = {}
38
50
  ) {
39
51
  if (api.typeParameters?.length > 0) {
@@ -66,7 +78,7 @@ export function getZodObjectFromApi(
66
78
  export function getZodObjectFromApiParams(
67
79
  apiParams: ApiParam[],
68
80
  references: {
69
- [id: string]: z.ZodObject<any>;
81
+ [id: string]: AnyZodObject;
70
82
  } = {}
71
83
  ): z.ZodObject {
72
84
  return z.object(
@@ -89,7 +101,7 @@ export function getZodObjectFromApiParams(
89
101
  export function getZodTypeFromApiParamType(
90
102
  paramType: ApiParamType,
91
103
  references: {
92
- [id: string]: z.ZodObject<any>;
104
+ [id: string]: AnyZodObject;
93
105
  }
94
106
  ): z.ZodType<unknown> {
95
107
  switch (paramType) {
@@ -135,7 +147,7 @@ export function getZodTypeFromApiParamType(
135
147
  }
136
148
  const [obj, literalOrUnion] = refType.args!.map((arg) =>
137
149
  getZodTypeFromApiParamType(arg, references)
138
- ) as [z.ZodObject<any>, z.ZodUnion<any> | z.ZodLiteral<string>];
150
+ ) as [AnyZodObject, z.ZodUnion<any> | AnyZodLiteral];
139
151
  let keys: string[] = [];
140
152
  if (literalOrUnion instanceof z.ZodUnion) {
141
153
  keys = literalOrUnion.def.options.map(
@@ -338,7 +350,7 @@ export function propToZodTypeDef(
338
350
  }
339
351
 
340
352
  // TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
341
- export function zodTypeToZodCode(zt: z.ZodType<any>): string {
353
+ export function zodTypeToZodCode(zt: z.ZodType): string {
342
354
  switch (zt.def.type) {
343
355
  case "string":
344
356
  return "z.string()";
@@ -361,15 +373,15 @@ export function zodTypeToZodCode(zt: z.ZodType<any>): string {
361
373
  case "never":
362
374
  return "z.never()";
363
375
  case "nullable":
364
- return zodTypeToZodCode((zt as z.ZodNullable<any>).def.innerType) + ".nullable()";
376
+ return zodTypeToZodCode((zt as AnyZodNullable).def.innerType) + ".nullable()";
365
377
  case "default":
366
- const zDefaultDef = (zt as z.ZodDefault<any>).def;
378
+ const zDefaultDef = (zt as AnyZodDefault).def;
367
379
  return (
368
380
  zodTypeToZodCode(zDefaultDef.innerType) +
369
- `.default(${zDefaultDef.defaultValue()})`
381
+ `.default(${zDefaultDef.defaultValue})`
370
382
  );
371
383
  case "record":
372
- const zRecordDef = (zt as z.ZodRecord<any, any>).def;
384
+ const zRecordDef = (zt as AnyZodRecord).def;
373
385
  return `z.record(${zodTypeToZodCode(zRecordDef.keyType)}, ${zodTypeToZodCode(
374
386
  zRecordDef.valueType
375
387
  )})`;
@@ -395,8 +407,8 @@ export function zodTypeToZodCode(zt: z.ZodType<any>): string {
395
407
  }
396
408
  return `z.literal([${items.join(", ")}])`;
397
409
  case "union":
398
- return `z.union([${(zt as z.ZodUnion<any>).def.options
399
- .map((option: z.ZodType<any>) => zodTypeToZodCode(option))
410
+ return `z.union([${(zt as AnyZodUnion).def.options
411
+ .map((option: z.ZodType) => zodTypeToZodCode(option))
400
412
  .join(",")}])`;
401
413
  case "enum":
402
414
  // NOTE: z.enum(["A", "B"])도 z.enum({ A: "A", B: "B" })로 처리됨.
@@ -543,16 +555,16 @@ export function unwrapPromiseOnce(paramType: ApiParamType) {
543
555
  }
544
556
 
545
557
  // TODO(Haze, 251031): "template_literal", "file"에 대한 지원이 필요함.
546
- export function serializeZodType(zt: z.ZodTypeAny): any {
558
+ export function serializeZodType(zt: z.ZodType): any {
547
559
  switch (zt.def.type) {
548
560
  case "object":
549
561
  return {
550
562
  type: "object",
551
- shape: Object.keys((zt as z.ZodObject<any>).shape).reduce(
563
+ shape: Object.keys((zt as AnyZodObject).shape).reduce(
552
564
  (result, key) => {
553
565
  return {
554
566
  ...result,
555
- [key]: serializeZodType((zt as z.ZodObject<any>).shape[key]),
567
+ [key]: serializeZodType((zt as AnyZodObject).shape[key]),
556
568
  };
557
569
  },
558
570
  {}
@@ -561,7 +573,7 @@ export function serializeZodType(zt: z.ZodTypeAny): any {
561
573
  case "array":
562
574
  return {
563
575
  type: "array",
564
- element: serializeZodType((zt as z.ZodArray<any>).def.element),
576
+ element: serializeZodType((zt as AnyZodArray).def.element),
565
577
  };
566
578
  case "enum":
567
579
  return {
@@ -584,12 +596,12 @@ export function serializeZodType(zt: z.ZodTypeAny): any {
584
596
  };
585
597
  case "nullable":
586
598
  return {
587
- ...serializeZodType((zt as z.ZodNullable<any>).def.innerType),
599
+ ...serializeZodType((zt as AnyZodNullable).def.innerType),
588
600
  nullable: true,
589
601
  };
590
602
  case "optional":
591
603
  return {
592
- ...serializeZodType((zt as z.ZodOptional<any>).def.innerType),
604
+ ...serializeZodType((zt as AnyZodOptional).def.innerType),
593
605
  optional: true,
594
606
  };
595
607
  case "any":
@@ -599,13 +611,13 @@ export function serializeZodType(zt: z.ZodTypeAny): any {
599
611
  case "record":
600
612
  return {
601
613
  type: "record",
602
- keyType: serializeZodType((zt as z.ZodRecord<any, any>).def.keyType),
603
- valueType: serializeZodType((zt as z.ZodRecord<any, any>).def.valueType),
614
+ keyType: serializeZodType((zt as AnyZodRecord).def.keyType),
615
+ valueType: serializeZodType((zt as AnyZodRecord).def.valueType),
604
616
  };
605
617
  case "union":
606
618
  return {
607
619
  type: "union",
608
- options: (zt.def as z.ZodUnion<z.ZodType<any>[]>).options.map((option) =>
620
+ options: (zt.def as AnyZodUnion).options.map((option) =>
609
621
  serializeZodType(option)
610
622
  ),
611
623
  };
@@ -631,16 +643,14 @@ export function zodTypeToTsTypeDef(zt: z.ZodType): string {
631
643
  case "never":
632
644
  return zt.def.type;
633
645
  case "nullable":
634
- return zodTypeToTsTypeDef((zt as z.ZodNullable<any>).def.innerType) + " | null";
646
+ return zodTypeToTsTypeDef((zt as AnyZodNullable).def.innerType) + " | null";
635
647
  case "default":
636
- return zodTypeToTsTypeDef((zt as z.ZodDefault<any>).def.innerType);
648
+ return zodTypeToTsTypeDef((zt as AnyZodDefault).def.innerType);
637
649
  case "record":
638
- const recordType = zt as z.ZodRecord<any, any>;
639
- return `{ [ key: ${zodTypeToTsTypeDef(
640
- recordType.def.keyType
641
- )} ]: ${zodTypeToTsTypeDef(recordType.def.valueType)}}`;
650
+ const recordType = zt as AnyZodRecord;
651
+ return `{ [ key: ${zodTypeToTsTypeDef(recordType.def.keyType)} ]: ${zodTypeToTsTypeDef(recordType.def.valueType)}}`;
642
652
  case "literal":
643
- return Array.from((zt as z.ZodLiteral<any>).values).map(value => {
653
+ return Array.from((zt as z.ZodLiteral).values).map(value => {
644
654
  if (typeof value === "string") {
645
655
  return `"${value}"`;
646
656
  }
@@ -656,15 +666,15 @@ export function zodTypeToTsTypeDef(zt: z.ZodType): string {
656
666
  return `${value}`;
657
667
  }).join(" | ")
658
668
  case "union":
659
- return `${(zt as z.ZodUnion<z.ZodTypeAny[]>).options
669
+ return `${(zt as AnyZodUnion).options
660
670
  .map((option) => zodTypeToTsTypeDef(option))
661
671
  .join(" | ")}`;
662
672
  case "enum":
663
673
  return `${(zt as z.ZodEnum).options.map((val) => `"${val}"`).join(" | ")}`;
664
674
  case "array":
665
- return `${zodTypeToTsTypeDef((zt as z.ZodArray<any>).element.type)}[]`;
675
+ return `${zodTypeToTsTypeDef((zt as AnyZodArray).element)}[]`;
666
676
  case "object":
667
- const shape = (zt as z.ZodObject<any>).shape;
677
+ const shape = (zt as AnyZodObject).shape;
668
678
  return [
669
679
  "{",
670
680
  ...Object.keys(shape).map((key) => {
@@ -677,7 +687,7 @@ export function zodTypeToTsTypeDef(zt: z.ZodType): string {
677
687
  "}",
678
688
  ].join("\n");
679
689
  case "optional":
680
- return zodTypeToTsTypeDef((zt as z.ZodOptional<any>).def.innerType) + " | undefined";
690
+ return zodTypeToTsTypeDef((zt as AnyZodOptional).def.innerType) + " | undefined";
681
691
  default:
682
692
  throw new Error(`처리되지 않은 ZodType ${zt.def.type}`);
683
693
  }
@@ -1,4 +1,4 @@
1
- import type { FastifyReply, FastifyRequest } from "fastify";
1
+ import type { FastifyReply, FastifyRequest, PassportUser } from "fastify";
2
2
  import type { RouteGenericInterface } from "fastify/types/route";
3
3
  import type {
4
4
  Server,
@@ -24,7 +24,16 @@ export type Context = {
24
24
  createSSE: <T extends ZodObject>(
25
25
  events: T
26
26
  ) => ReturnType<typeof createSSEFactory<T>>;
27
- } & ContextExtend;
27
+ } & AuthContext &
28
+ ContextExtend;
29
+
30
+ export type AuthContext = {
31
+ user: PassportUser | null;
32
+ passport: {
33
+ login: (user: PassportUser) => Promise<void>;
34
+ logout: () => void;
35
+ };
36
+ };
28
37
 
29
38
  export type UploadContext = {
30
39
  file?: FileStorage;
package/src/api/sonamu.ts CHANGED
@@ -29,8 +29,9 @@ import { findApiRootPath } from "../utils/utils";
29
29
  import { humanizeZodError } from "../utils/zod-error";
30
30
  import { fastifyCaster } from "./caster";
31
31
  import { getZodObjectFromApi } from "./code-converters";
32
- import type { Context, UploadContext } from "./context";
32
+ import type { AuthContext, Context, UploadContext } from "./context";
33
33
  import type { ExtendedApi } from "./decorators";
34
+ import fastifyPassport from "@fastify/passport";
34
35
 
35
36
  export type SonamuConfig = {
36
37
  projectName?: string;
@@ -240,6 +241,16 @@ class SonamuClass {
240
241
  this.registerPlugins(server, options.plugins);
241
242
  }
242
243
 
244
+ if (options.auth) {
245
+ if (!options.plugins?.session) {
246
+ throw new Error(
247
+ "Auth requires session plugin. Please add plugins.session configuration."
248
+ );
249
+ }
250
+
251
+ this.registerAuth(server, options.auth);
252
+ }
253
+
243
254
  // API 라우팅 설정
244
255
  await this.withFastify(server, options.apiConfig, {
245
256
  enableSync: initOptions?.enableSync,
@@ -401,7 +412,6 @@ class SonamuClass {
401
412
  reply
402
413
  );
403
414
 
404
- // 결과 (AsyncLocalStorage 적용)
405
415
  const context: Context = {
406
416
  ...config.contextProvider(
407
417
  {
@@ -409,6 +419,17 @@ class SonamuClass {
409
419
  reply,
410
420
  headers: request.headers,
411
421
  createSSE,
422
+
423
+ // auth
424
+ user: request.user ?? null,
425
+ passport: {
426
+ login: request.login.bind(
427
+ request
428
+ ) as AuthContext["passport"]["login"],
429
+ logout: request.logout.bind(
430
+ request
431
+ ) as AuthContext["passport"]["logout"],
432
+ },
412
433
  },
413
434
  request,
414
435
  reply
@@ -490,6 +511,8 @@ class SonamuClass {
490
511
  multipart: "@fastify/multipart",
491
512
  qs: "fastify-qs",
492
513
  sse: "fastify-sse-v2",
514
+ static: "@fastify/static",
515
+ session: "@fastify/secure-session",
493
516
  } as const;
494
517
 
495
518
  const registerPlugin = <K extends keyof NonNullable<typeof plugins>>(
@@ -515,6 +538,24 @@ class SonamuClass {
515
538
  }
516
539
  }
517
540
 
541
+ private async registerAuth(
542
+ server: FastifyInstance,
543
+ options: NonNullable<SonamuServerOptions["auth"]>
544
+ ) {
545
+ server.register(fastifyPassport.initialize());
546
+ server.register(fastifyPassport.secureSession());
547
+
548
+ if (typeof options === "boolean") {
549
+ fastifyPassport.registerUserSerializer(async (user, _request) => user);
550
+ fastifyPassport.registerUserDeserializer(
551
+ async (serialized, _request) => serialized
552
+ );
553
+ } else {
554
+ fastifyPassport.registerUserSerializer(options.userSerializer);
555
+ fastifyPassport.registerUserDeserializer(options.userDeserializer);
556
+ }
557
+ }
558
+
518
559
  private async boot(server: FastifyInstance, options: SonamuServerOptions) {
519
560
  const port = options.listen?.port ?? 3000;
520
561
  const host = options.listen?.host ?? "localhost";
@@ -1,10 +1,14 @@
1
+ /**
2
+ * 빌드 결과물이 담길 디렉토리 경로
3
+ */
4
+ export const BUILD_DIR = "dist";
5
+
1
6
  /**
2
7
  * SWC 빌드 명령어
3
8
  */
4
- export const SWC_BUILD_COMMAND =
5
- "swc src -d dist --strip-leading-paths --source-maps -C module.type=commonjs -C jsc.parser.syntax=typescript -C jsc.parser.decorators=true -C jsc.target=es5";
9
+ export const SWC_BUILD_COMMAND = `swc src -d ${BUILD_DIR} --strip-leading-paths --source-maps -C module.type=commonjs -C jsc.parser.syntax=typescript -C jsc.parser.decorators=true -C jsc.target=es5`;
6
10
 
7
11
  /**
8
12
  * TSC 타입 체크 명령어
9
13
  */
10
- export const TSC_TYPE_CHECK_COMMAND = "tsc --noEmit";
14
+ export const TSC_TYPE_CHECK_COMMAND = `tsc --noEmit`;
@@ -2,36 +2,55 @@
2
2
 
3
3
  import { spawnSync, execSync } from "child_process";
4
4
  import { resolve } from "path";
5
- import { existsSync } from "fs";
5
+ import { existsSync, rmSync } from "fs";
6
6
  import chalk from "chalk";
7
- import { SWC_BUILD_COMMAND, TSC_TYPE_CHECK_COMMAND } from "./build-config";
7
+ import {
8
+ BUILD_DIR,
9
+ SWC_BUILD_COMMAND,
10
+ TSC_TYPE_CHECK_COMMAND,
11
+ } from "./build-config";
8
12
 
9
13
  const scriptPath = resolve(__dirname, "cli.js");
10
14
  const args = process.argv.slice(2);
11
15
 
12
16
  // build 명령어는 dist 없이도 실행 가능하도록 cli.ts 외부에서 처리(Sonamu.init에서 dist 필요)
13
- function build(checkTypes: boolean = false) {
17
+ function build() {
14
18
  try {
19
+ console.log(chalk.blue("Removing build directory..."));
20
+ if (existsSync(BUILD_DIR)) {
21
+ rmSync(BUILD_DIR, { recursive: true, force: true });
22
+ }
23
+ } catch (error) {
24
+ console.error(chalk.red("Remove build directory failed."), error);
25
+ process.exit(1);
26
+ }
27
+
28
+ try {
29
+ console.log(chalk.blue("Building with swc..."));
15
30
  execSync(SWC_BUILD_COMMAND, { cwd: process.cwd(), stdio: "inherit" });
16
31
  } catch (error) {
17
32
  console.error(chalk.red("Build failed."), error);
18
33
  process.exit(1);
19
34
  }
35
+ }
20
36
 
21
- if (checkTypes) {
22
- try {
23
- console.log(chalk.blue("Checking types with tsc..."));
24
- execSync(TSC_TYPE_CHECK_COMMAND, { cwd: process.cwd(), stdio: "inherit" });
25
- } catch (error) {
26
- console.error(chalk.red("Type check failed."), error);
27
- process.exit(1);
28
- }
37
+ function checkTypes() {
38
+ try {
39
+ console.log(chalk.blue("Checking types with tsc..."));
40
+ execSync(TSC_TYPE_CHECK_COMMAND, {
41
+ cwd: process.cwd(),
42
+ stdio: "inherit",
43
+ });
44
+ } catch (error) {
45
+ console.error(chalk.red("Type check failed."), error);
46
+ process.exit(1);
29
47
  }
30
48
  }
31
49
 
32
50
  if (args[0] === "build") {
33
51
  console.log(chalk.blue("Building the project..."));
34
- build(true);
52
+ build();
53
+ checkTypes();
35
54
  console.log(chalk.green("Build completed successfully."));
36
55
  process.exit(0);
37
56
  }
@@ -559,6 +559,25 @@ export class Puri<
559
559
  return result;
560
560
  }
561
561
 
562
+ // Pluck
563
+ async pluck<
564
+ TColumn extends ResultAvailableColumns<
565
+ TSchema,
566
+ TTable,
567
+ TOriginal,
568
+ TResult,
569
+ TJoined
570
+ >,
571
+ >(
572
+ column: TColumn
573
+ ): Promise<
574
+ ExtractColumnType<TSchema, TTable, TColumn & string, TOriginal, TJoined>[]
575
+ > {
576
+ return this.knexQuery.pluck(column) as Promise<
577
+ ExtractColumnType<TSchema, TTable, TColumn & string, TOriginal, TJoined>[]
578
+ >;
579
+ }
580
+
562
581
  // Insert/Update/Delete
563
582
  // TODO(Haze, 251030): InsertData<T>에서 nullable type을 제대로 처리하지 못하는 것 같음.
564
583
  async insert(
@@ -40,9 +40,11 @@ export type ResultAvailableColumns<
40
40
  TOriginal = any,
41
41
  TResult = any,
42
42
  TJoined = EmptyRecord,
43
- > =
43
+ > = Exclude<
44
44
  | AvailableColumns<TSchema, T, TOriginal, TJoined>
45
- | `${keyof TResult & string}`;
45
+ | `${keyof TResult & string}`,
46
+ "__fulltext__" | `${T & string}.__fulltext__`
47
+ >;
46
48
 
47
49
  // 사용 가능한 컬럼 경로 타입 (메인 테이블 + 조인된 테이블들)
48
50
  export type AvailableColumns<
@@ -9,10 +9,16 @@ import type {
9
9
  } from "fastify";
10
10
  import type { QsPluginOptions } from "fastify-qs";
11
11
  import { z } from "zod";
12
- import type { Context, ApiDecoratorOptions } from "../api";
12
+ import type { ApiDecoratorOptions, AuthContext, Context } from "../api";
13
13
  import type { FastifyMultipartOptions } from "@fastify/multipart";
14
14
  import type { Driver } from "../file-storage/driver";
15
15
  import type { SsePluginOptions } from "fastify-sse-v2/lib/types";
16
+ import type { FastifyStaticOptions } from "@fastify/static";
17
+ import { SecureSessionPluginOptions } from "@fastify/secure-session";
18
+ import {
19
+ DeserializeFunction,
20
+ SerializeFunction,
21
+ } from "@fastify/passport/dist/Authenticator";
16
22
 
17
23
  /*
18
24
  Enums
@@ -837,7 +843,8 @@ export type SonamuFastifyConfig = {
837
843
  defaultContext: Pick<
838
844
  Context,
839
845
  "request" | "reply" | "headers" | "createSSE"
840
- >,
846
+ > &
847
+ AuthContext,
841
848
  request: FastifyRequest,
842
849
  reply: FastifyReply
843
850
  ) => Context;
@@ -888,10 +895,19 @@ export type SonamuServerOptions = {
888
895
  multipart?: boolean | FastifyMultipartOptions;
889
896
  qs?: boolean | QsPluginOptions;
890
897
  sse?: boolean | SsePluginOptions;
898
+ static?: boolean | FastifyStaticOptions;
899
+ session?: boolean | SecureSessionPluginOptions;
891
900
 
892
901
  custom?: (server: FastifyInstance) => void;
893
902
  };
894
903
 
904
+ auth?:
905
+ | boolean
906
+ | {
907
+ userSerializer: SerializeFunction<unknown, unknown>;
908
+ userDeserializer: DeserializeFunction<unknown, unknown>;
909
+ };
910
+
895
911
  apiConfig: SonamuFastifyConfig;
896
912
 
897
913
  storage?: Driver;
@@ -1,135 +0,0 @@
1
- import { Knex } from "knex";
2
- import { GenMigrationCode, MigrationColumn, MigrationForeign, MigrationIndex, MigrationSet, MigrationSetAndJoinTable } from "../types/types";
3
- import { Entity } from "./entity";
4
- type MigratorMode = "dev" | "deploy";
5
- export type MigratorOptions = {
6
- readonly mode: MigratorMode;
7
- };
8
- type MigrationCode = {
9
- name: string;
10
- path: string;
11
- };
12
- type ConnString = `${"mysql2"}://${string}@${string}:${number}/${string}`;
13
- export type MigrationStatus = {
14
- codes: MigrationCode[];
15
- conns: {
16
- name: string;
17
- connKey: string;
18
- connString: ConnString;
19
- currentVersion: string;
20
- status: string | number;
21
- pending: string[];
22
- }[];
23
- preparedCodes: GenMigrationCode[];
24
- };
25
- export declare class Migrator {
26
- readonly mode: MigratorMode;
27
- targets: {
28
- compare?: Knex;
29
- pending: Knex;
30
- shadow: Knex;
31
- apply: Knex[];
32
- };
33
- constructor(options: MigratorOptions);
34
- getMigrationCodes(): Promise<{
35
- normal: MigrationCode[];
36
- onlyTs: MigrationCode[];
37
- onlyJs: MigrationCode[];
38
- }>;
39
- getStatus(): Promise<MigrationStatus>;
40
- runAction(action: "latest" | "rollback", targets: string[]): Promise<{
41
- connKey: string;
42
- batchNo: number;
43
- applied: string[];
44
- }[]>;
45
- delCodes(codeNames: string[]): Promise<number>;
46
- generatePreparedCodes(): Promise<number>;
47
- clearPendingList(): Promise<void>;
48
- check(): Promise<void>;
49
- run(): Promise<void>;
50
- rollback(): Promise<void>;
51
- cleanUpDist(force?: boolean): Promise<void>;
52
- runShadowTest(): Promise<{
53
- connKey: string;
54
- batchNo: number;
55
- applied: string[];
56
- }[]>;
57
- resetAll(): Promise<void>;
58
- compareMigrations(compareDB: Knex): Promise<GenMigrationCode[]>;
59
- getMigrationSetFromDB(compareDB: Knex, table: string): Promise<MigrationSet | null>;
60
- resolveDBColType(colType: string, colField: string): Pick<MigrationColumn, "type" | "unsigned" | "length" | "precision" | "scale">;
61
- readTable(compareDB: Knex, tableName: string): Promise<[DBColumn[], DBIndex[], DBForeign[]]>;
62
- getMigrationSetFromEntity(entity: Entity): MigrationSetAndJoinTable;
63
- genColumnDefinitions(columns: MigrationColumn[]): string[];
64
- genIndexDefinitions(indexes: MigrationIndex[]): string[];
65
- genForeignDefinitions(table: string, foreigns: MigrationForeign[]): {
66
- up: string[];
67
- down: string[];
68
- };
69
- generateCreateCode_ColumnAndIndexes(table: string, columns: MigrationColumn[], indexes: MigrationIndex[]): Promise<GenMigrationCode>;
70
- generateCreateCode_Foreign(table: string, foreigns: MigrationForeign[]): Promise<GenMigrationCode[]>;
71
- showMigrationSet(which: "Entity" | "DB", migrationSet: MigrationSet): void;
72
- generateAlterCode_ColumnAndIndexes(table: string, entityColumns: MigrationColumn[], entityIndexes: MigrationIndex[], dbColumns: MigrationColumn[], dbIndexes: MigrationIndex[], dbForeigns: MigrationForeign[]): Promise<GenMigrationCode[]>;
73
- getAlterColumnsTo(entityColumns: MigrationColumn[], dbColumns: MigrationColumn[]): {
74
- add: MigrationColumn[];
75
- drop: MigrationColumn[];
76
- alter: MigrationColumn[];
77
- };
78
- getAlterColumnLinesTo(columnsTo: ReturnType<Migrator["getAlterColumnsTo"]>, entityColumns: MigrationColumn[], table: string, dbForeigns: MigrationForeign[]): {
79
- add: {
80
- up: string[];
81
- down: string[];
82
- };
83
- drop: {
84
- up: string[];
85
- down: string[];
86
- };
87
- alter: {
88
- up: string[];
89
- down: string[];
90
- };
91
- };
92
- getAlterIndexesTo(entityIndexes: MigrationIndex[], dbIndexes: MigrationIndex[]): {
93
- add: MigrationIndex[];
94
- drop: MigrationIndex[];
95
- };
96
- genIndexDefinition(index: MigrationIndex, table: string): string;
97
- genIndexDropDefinition(index: MigrationIndex): string;
98
- generateAlterCode_Foreigns(table: string, entityForeigns: MigrationForeign[], dbForeigns: MigrationForeign[], droppingColumns?: MigrationColumn[]): Promise<GenMigrationCode[]>;
99
- destroy(): Promise<void>;
100
- }
101
- type DBColumn = {
102
- Field: string;
103
- Type: string;
104
- Null: string;
105
- Key: string;
106
- Default: string | null;
107
- Extra: string;
108
- };
109
- type DBIndex = {
110
- Table: string;
111
- Non_unique: number;
112
- Key_name: string;
113
- Seq_in_index: number;
114
- Column_name: string;
115
- Collation: string | null;
116
- Cardinality: number | null;
117
- Sub_part: number | null;
118
- Packed: string | null;
119
- Null: string;
120
- Index_type: string;
121
- Comment: string;
122
- Index_comment: string;
123
- Visible: string;
124
- Expression: string | null;
125
- };
126
- type DBForeign = {
127
- keyName: string;
128
- from: string;
129
- referencesTable: string;
130
- referencesField: string;
131
- onDelete: string;
132
- onUpdate: string;
133
- };
134
- export {};
135
- //# sourceMappingURL=migrator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../../src/entity/migrator.ts"],"names":[],"mappings":"AACA,OAAa,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAYlC,OAAO,EACL,gBAAgB,EAShB,eAAe,EACf,gBAAgB,EAChB,cAAc,EAEd,YAAY,EACZ,wBAAwB,EAQzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,KAAK,YAAY,GAAG,KAAK,GAAG,QAAQ,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;CAC7B,CAAC;AACF,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,KAA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