@natrave/shared-entities 8.48.0 → 9.0.0

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.
@@ -1,3 +1,4 @@
1
1
  export { IdentityLayer } from './identity-layer.enum';
2
+ export * from './sql';
2
3
  export * from './views';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { IdentityLayer } from "./identity-layer.enum.js";
2
+ export * from "./sql/index.js";
2
3
  export * from "./views/index.js";
3
4
  export {
4
5
  IdentityLayer
@@ -0,0 +1,3 @@
1
+ export * from './member-identity-row';
2
+ export * from './member-identity-sql';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/sql/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./member-identity-row.js";
2
+ export * from "./member-identity-sql.js";
@@ -0,0 +1,19 @@
1
+ import { Position } from '../../players/player-position/enums/position.enum';
2
+ import { TeamMemberType } from '../../teams/player-team/enums/team-member-type.enum';
3
+ import { TechnicalStaffRole } from '../../teams/player-team/enums/technical-staff-role.enum';
4
+ import { IdentityLayer } from '../identity-layer.enum';
5
+ export interface MemberIdentity {
6
+ name: string | null;
7
+ nameSource: IdentityLayer | null;
8
+ photoUrl: string | null;
9
+ photoSource: IdentityLayer | null;
10
+ nickname: string | null;
11
+ shirtNumber: number | null;
12
+ positions: Position[];
13
+ type: TeamMemberType | null;
14
+ role: TechnicalStaffRole | null;
15
+ hasAccount: boolean;
16
+ }
17
+ export type MemberIdentityRow = Partial<Record<keyof MemberIdentity, unknown>>;
18
+ export declare function toMemberIdentity(row: MemberIdentityRow): MemberIdentity;
19
+ //# sourceMappingURL=member-identity-row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"member-identity-row.d.ts","sourceRoot":"","sources":["../../../src/identity/sql/member-identity-row.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yDAAyD,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAOvD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,aAAa,GAAG,IAAI,CAAC;IACjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,aAAa,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IAC5B,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,OAAO,CAAC;CACrB;AAGD,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;AAoC/E,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,iBAAiB,GAAG,cAAc,CAavE"}
@@ -0,0 +1,38 @@
1
+ import { Position } from "../../players/player-position/enums/position.enum.js";
2
+ import { TeamMemberType } from "../../teams/player-team/enums/team-member-type.enum.js";
3
+ import { TechnicalStaffRole } from "../../teams/player-team/enums/technical-staff-role.enum.js";
4
+ import { IdentityLayer } from "../identity-layer.enum.js";
5
+ const POSITIONS = new Set(Object.values(Position));
6
+ const TYPES = new Set(Object.values(TeamMemberType));
7
+ const ROLES = new Set(Object.values(TechnicalStaffRole));
8
+ const LAYERS = new Set(Object.values(IdentityLayer));
9
+ const text = (value) => typeof value === "string" ? value : null;
10
+ function oneOf(values, value) {
11
+ return typeof value === "string" && values.has(value) ? value : null;
12
+ }
13
+ function positions(value) {
14
+ const list = Array.isArray(value) ? value : typeof value === "string" ? value.replace(/^\{|\}$/g, "").split(",").filter(Boolean) : [];
15
+ return list.filter((item) => typeof item === "string" && POSITIONS.has(item));
16
+ }
17
+ function shirtNumber(value) {
18
+ if (value === null || value === void 0) return null;
19
+ const number = Number(value);
20
+ return Number.isInteger(number) ? number : null;
21
+ }
22
+ function toMemberIdentity(row) {
23
+ return {
24
+ name: text(row.name),
25
+ nameSource: oneOf(LAYERS, row.nameSource),
26
+ photoUrl: text(row.photoUrl),
27
+ photoSource: oneOf(LAYERS, row.photoSource),
28
+ nickname: text(row.nickname),
29
+ shirtNumber: shirtNumber(row.shirtNumber),
30
+ positions: positions(row.positions),
31
+ type: oneOf(TYPES, row.type),
32
+ role: oneOf(ROLES, row.role),
33
+ hasAccount: row.hasAccount === true
34
+ };
35
+ }
36
+ export {
37
+ toMemberIdentity
38
+ };
@@ -0,0 +1,60 @@
1
+ export declare const MEMBER_TEAM_IDENTITY_COLUMNS: {
2
+ readonly isAdmin: "is_admin";
3
+ readonly playerTeamId: "player_team_id";
4
+ readonly playerId: "player_id";
5
+ readonly teamId: "team_id";
6
+ readonly userId: "user_id";
7
+ readonly hasAccount: "has_account";
8
+ readonly name: "name";
9
+ readonly nameSource: "name_source";
10
+ readonly photoUrl: "photo_url";
11
+ readonly photoSource: "photo_source";
12
+ readonly nickname: "nickname";
13
+ readonly shirtNumber: "shirt_number";
14
+ readonly positions: "positions";
15
+ readonly type: "type";
16
+ readonly role: "role";
17
+ readonly deletedAt: "deleted_at";
18
+ };
19
+ export declare const MEMBER_TOURNAMENT_IDENTITY_COLUMNS: {
20
+ readonly tournamentPlayerId: "tournament_player_id";
21
+ readonly tournamentTeamId: "tournament_team_id";
22
+ readonly nicknameSource: "nickname_source";
23
+ readonly shirtNumberSource: "shirt_number_source";
24
+ readonly positionsSource: "positions_source";
25
+ readonly isOwner: "is_owner";
26
+ readonly calledUpAt: "called_up_at";
27
+ readonly teamMemberDeletedAt: "team_member_deleted_at";
28
+ readonly playerTeamId: "player_team_id";
29
+ readonly playerId: "player_id";
30
+ readonly teamId: "team_id";
31
+ readonly userId: "user_id";
32
+ readonly hasAccount: "has_account";
33
+ readonly name: "name";
34
+ readonly nameSource: "name_source";
35
+ readonly photoUrl: "photo_url";
36
+ readonly photoSource: "photo_source";
37
+ readonly nickname: "nickname";
38
+ readonly shirtNumber: "shirt_number";
39
+ readonly positions: "positions";
40
+ readonly type: "type";
41
+ readonly role: "role";
42
+ readonly deletedAt: "deleted_at";
43
+ };
44
+ export type MemberTeamIdentityField = keyof typeof MEMBER_TEAM_IDENTITY_COLUMNS;
45
+ export type MemberTournamentIdentityField = keyof typeof MEMBER_TOURNAMENT_IDENTITY_COLUMNS;
46
+ export declare const memberIdentitySql: {
47
+ teamView: string;
48
+ tournamentView: string;
49
+ tournamentOn(tournamentPlayerAlias: string, viewAlias?: string): string;
50
+ teamOn(playerTeamAlias: string, viewAlias?: string): string;
51
+ joinTournament(tournamentPlayerAlias: string, viewAlias?: string): string;
52
+ leftJoinTournament(tournamentPlayerAlias: string, viewAlias?: string): string;
53
+ joinTeam(playerTeamAlias: string, viewAlias?: string): string;
54
+ leftJoinTeam(playerTeamAlias: string, viewAlias?: string): string;
55
+ tournamentColumn(field: MemberTournamentIdentityField, viewAlias?: string): string;
56
+ teamColumn(field: MemberTeamIdentityField, viewAlias?: string): string;
57
+ selectTournament(fields: readonly MemberTournamentIdentityField[], viewAlias?: string, prefix?: string): string;
58
+ selectTeam(fields: readonly MemberTeamIdentityField[], viewAlias?: string, prefix?: string): string;
59
+ };
60
+ //# sourceMappingURL=member-identity-sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"member-identity-sql.d.ts","sourceRoot":"","sources":["../../../src/identity/sql/member-identity-sql.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;CAG/B,CAAC;AAEX,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;CAUrC,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,MAAM,OAAO,4BAA4B,CAAC;AAChF,MAAM,MAAM,6BAA6B,GAAG,MAAM,OAAO,kCAAkC,CAAC;AAsB5F,eAAO,MAAM,iBAAiB;;;wCAKQ,MAAM,uBAAqB,MAAM;4BAK7C,MAAM,uBAAsB,MAAM;0CAKpB,MAAM,uBAAqB,MAAM;8CAI7B,MAAM,uBAAqB,MAAM;8BAKjD,MAAM,uBAAsB,MAAM;kCAI9B,MAAM,uBAAsB,MAAM;4BAKxC,6BAA6B,uBAAqB,MAAM;sBAI9D,uBAAuB,uBAAsB,MAAM;6BAU3D,SAAS,6BAA6B,EAAE,wCAG/C,MAAM;uBAIU,SAAS,uBAAuB,EAAE,wCAAmC,MAAM;CAG/F,CAAC"}
@@ -0,0 +1,96 @@
1
+ import {
2
+ MEMBER_TEAM_IDENTITY_VIEW,
3
+ MEMBER_TOURNAMENT_IDENTITY_VIEW
4
+ } from "../views/member-identity-views.sql.js";
5
+ const SHARED_COLUMNS = {
6
+ playerTeamId: "player_team_id",
7
+ playerId: "player_id",
8
+ teamId: "team_id",
9
+ userId: "user_id",
10
+ hasAccount: "has_account",
11
+ name: "name",
12
+ nameSource: "name_source",
13
+ photoUrl: "photo_url",
14
+ photoSource: "photo_source",
15
+ nickname: "nickname",
16
+ shirtNumber: "shirt_number",
17
+ positions: "positions",
18
+ type: "type",
19
+ role: "role",
20
+ deletedAt: "deleted_at"
21
+ };
22
+ const MEMBER_TEAM_IDENTITY_COLUMNS = {
23
+ ...SHARED_COLUMNS,
24
+ isAdmin: "is_admin"
25
+ };
26
+ const MEMBER_TOURNAMENT_IDENTITY_COLUMNS = {
27
+ ...SHARED_COLUMNS,
28
+ tournamentPlayerId: "tournament_player_id",
29
+ tournamentTeamId: "tournament_team_id",
30
+ nicknameSource: "nickname_source",
31
+ shirtNumberSource: "shirt_number_source",
32
+ positionsSource: "positions_source",
33
+ isOwner: "is_owner",
34
+ calledUpAt: "called_up_at",
35
+ teamMemberDeletedAt: "team_member_deleted_at"
36
+ };
37
+ const SQL_ALIAS = /^[A-Za-z_][A-Za-z0-9_]*$/;
38
+ function alias(value) {
39
+ if (!SQL_ALIAS.test(value)) {
40
+ throw new Error(`Alias de SQL inv\xE1lido para a vis\xE3o de identidade: "${value}"`);
41
+ }
42
+ return value;
43
+ }
44
+ function selectColumns(columns, viewAlias, fields, prefix) {
45
+ const a = alias(viewAlias);
46
+ return fields.map((field) => `${a}.${columns[field]} AS "${prefix}${field}"`).join(",\n ");
47
+ }
48
+ const memberIdentitySql = {
49
+ teamView: MEMBER_TEAM_IDENTITY_VIEW,
50
+ tournamentView: MEMBER_TOURNAMENT_IDENTITY_VIEW,
51
+ /** Condição do join da visão do campeonato com `tournament_players` (alias `tp`). */
52
+ tournamentOn(tournamentPlayerAlias, viewAlias = "mi") {
53
+ return `${alias(viewAlias)}.tournament_player_id = ${alias(tournamentPlayerAlias)}.id`;
54
+ },
55
+ /** Condição do join da visão do time com `player_teams` (alias `pt`). */
56
+ teamOn(playerTeamAlias, viewAlias = "mti") {
57
+ return `${alias(viewAlias)}.player_team_id = ${alias(playerTeamAlias)}.id`;
58
+ },
59
+ /** `JOIN member_tournament_identity mi ON mi.tournament_player_id = tp.id` */
60
+ joinTournament(tournamentPlayerAlias, viewAlias = "mi") {
61
+ return `JOIN ${MEMBER_TOURNAMENT_IDENTITY_VIEW} ${alias(viewAlias)} ON ${this.tournamentOn(tournamentPlayerAlias, viewAlias)}`;
62
+ },
63
+ leftJoinTournament(tournamentPlayerAlias, viewAlias = "mi") {
64
+ return `LEFT ${this.joinTournament(tournamentPlayerAlias, viewAlias)}`;
65
+ },
66
+ /** `JOIN member_team_identity mti ON mti.player_team_id = pt.id` */
67
+ joinTeam(playerTeamAlias, viewAlias = "mti") {
68
+ return `JOIN ${MEMBER_TEAM_IDENTITY_VIEW} ${alias(viewAlias)} ON ${this.teamOn(playerTeamAlias, viewAlias)}`;
69
+ },
70
+ leftJoinTeam(playerTeamAlias, viewAlias = "mti") {
71
+ return `LEFT ${this.joinTeam(playerTeamAlias, viewAlias)}`;
72
+ },
73
+ /** Uma coluna da visão do campeonato, para WHERE e ORDER BY: `mi.name`. */
74
+ tournamentColumn(field, viewAlias = "mi") {
75
+ return `${alias(viewAlias)}.${MEMBER_TOURNAMENT_IDENTITY_COLUMNS[field]}`;
76
+ },
77
+ teamColumn(field, viewAlias = "mti") {
78
+ return `${alias(viewAlias)}.${MEMBER_TEAM_IDENTITY_COLUMNS[field]}`;
79
+ },
80
+ /**
81
+ * Colunas da visão do campeonato com apelido em camelCase, prontas para o SELECT:
82
+ * `mi.photo_url AS "photoUrl"`. `prefix` separa duas pessoas na mesma linha
83
+ * (`scorer` → `"scorerName"`, `"scorerPhotoUrl"`).
84
+ */
85
+ selectTournament(fields, viewAlias = "mi", prefix = "") {
86
+ return selectColumns(MEMBER_TOURNAMENT_IDENTITY_COLUMNS, viewAlias, fields, prefix);
87
+ },
88
+ selectTeam(fields, viewAlias = "mti", prefix = "") {
89
+ return selectColumns(MEMBER_TEAM_IDENTITY_COLUMNS, viewAlias, fields, prefix);
90
+ }
91
+ };
92
+ export {
93
+ MEMBER_TEAM_IDENTITY_COLUMNS,
94
+ MEMBER_TOURNAMENT_IDENTITY_COLUMNS,
95
+ memberIdentitySql
96
+ };
@@ -9,13 +9,11 @@ export declare class Player {
9
9
  createdAt: Date;
10
10
  updatedAt: Date;
11
11
  deletedAt: Date | null;
12
- nickname: string | null;
13
12
  preferredLeg: PreferredLeg | null;
14
13
  user: User | null;
15
14
  positions: PlayerPosition[];
16
15
  teamMemberships: PlayerTeam[];
17
16
  joinRequests: TeamJoinRequest[];
18
17
  personalData: PlayerPersonalData | null;
19
- prepareData(): void;
20
18
  }
21
19
  //# sourceMappingURL=player.entity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"player.entity.d.ts","sourceRoot":"","sources":["../../../src/players/players/player.entity.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,qBAEa,MAAM;IAGjB,EAAE,EAAE,MAAM,CAAC;IAGX,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAGtB,SAAS,EAAE,IAAI,CAAC;IAGhB,SAAS,EAAE,IAAI,CAAC;IAQhB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IAQvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAQxB,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IASlC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAWlB,SAAS,EAAE,cAAc,EAAE,CAAC;IAG5B,eAAe,EAAE,UAAU,EAAE,CAAC;IAE9B,YAAY,EAAE,eAAe,EAAE,CAAC;IAGhC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAMxC,WAAW,IAAI,IAAI;CAKpB"}
1
+ {"version":3,"file":"player.entity.d.ts","sourceRoot":"","sources":["../../../src/players/players/player.entity.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,qBAEa,MAAM;IAGjB,EAAE,EAAE,MAAM,CAAC;IAGX,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAGtB,SAAS,EAAE,IAAI,CAAC;IAGhB,SAAS,EAAE,IAAI,CAAC;IAQhB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IAgBvB,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IASlC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAWlB,SAAS,EAAE,cAAc,EAAE,CAAC;IAG5B,eAAe,EAAE,UAAU,EAAE,CAAC;IAE9B,YAAY,EAAE,eAAe,EAAE,CAAC;IAGhC,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC"}
@@ -9,7 +9,6 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  return result;
10
10
  };
11
11
  import {
12
- BeforeInsert,
13
12
  Column,
14
13
  CreateDateColumn,
15
14
  DeleteDateColumn,
@@ -29,11 +28,6 @@ import { PlayerPersonalData } from "../player-personal-data/index.js";
29
28
  import { PlayerPosition } from "../player-position/index.js";
30
29
  import { PreferredLeg } from "./enums/preferred-leg.enum.js";
31
30
  let Player = class {
32
- prepareData() {
33
- if (this.nickname) {
34
- this.nickname = this.nickname.trim();
35
- }
36
- }
37
31
  };
38
32
  __decorateClass([
39
33
  PrimaryGeneratedColumn()
@@ -55,14 +49,6 @@ __decorateClass([
55
49
  comment: "Data e hora em que o usu\xE1rio foi deletado (soft delete), se aplic\xE1vel."
56
50
  })
57
51
  ], Player.prototype, "deletedAt", 2);
58
- __decorateClass([
59
- Column({
60
- type: "varchar",
61
- length: 255,
62
- nullable: true,
63
- comment: "Apelido ou nome de usu\xE1rio do jogador."
64
- })
65
- ], Player.prototype, "nickname", 2);
66
52
  __decorateClass([
67
53
  Column({
68
54
  type: "enum",
@@ -98,9 +84,6 @@ __decorateClass([
98
84
  __decorateClass([
99
85
  OneToOne(() => PlayerPersonalData, (personalData) => personalData.player)
100
86
  ], Player.prototype, "personalData", 2);
101
- __decorateClass([
102
- BeforeInsert()
103
- ], Player.prototype, "prepareData", 1);
104
87
  Player = __decorateClass([
105
88
  Entity("players"),
106
89
  Index("IDX_players_deleted_at", ["deletedAt"])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@natrave/shared-entities",
3
- "version": "8.48.0",
3
+ "version": "9.0.0",
4
4
  "description": "Entidades compartilhadass da NaTrave",
5
5
  "module": "dist/index.js",
6
6
  "main": "dist/index.js",