@tstdl/base 0.93.0 → 0.93.2

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.
@@ -0,0 +1,188 @@
1
+ {
2
+ "id": "bf59778c-5f0d-4a3f-9d71-4ff638082201",
3
+ "prevId": "00000000-0000-0000-0000-000000000000",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "audit.event": {
8
+ "name": "event",
9
+ "schema": "audit",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "timestamp": {
19
+ "name": "timestamp",
20
+ "type": "timestamp with time zone",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "tenant_id": {
25
+ "name": "tenant_id",
26
+ "type": "uuid",
27
+ "primaryKey": false,
28
+ "notNull": false
29
+ },
30
+ "correlation_id": {
31
+ "name": "correlation_id",
32
+ "type": "uuid",
33
+ "primaryKey": false,
34
+ "notNull": false
35
+ },
36
+ "module": {
37
+ "name": "module",
38
+ "type": "text",
39
+ "primaryKey": false,
40
+ "notNull": true
41
+ },
42
+ "action": {
43
+ "name": "action",
44
+ "type": "text",
45
+ "primaryKey": false,
46
+ "notNull": true
47
+ },
48
+ "outcome": {
49
+ "name": "outcome",
50
+ "type": "audit_outcome",
51
+ "typeSchema": "audit",
52
+ "primaryKey": false,
53
+ "notNull": true
54
+ },
55
+ "severity": {
56
+ "name": "severity",
57
+ "type": "audit_severity",
58
+ "typeSchema": "audit",
59
+ "primaryKey": false,
60
+ "notNull": true
61
+ },
62
+ "actor_id": {
63
+ "name": "actor_id",
64
+ "type": "uuid",
65
+ "primaryKey": false,
66
+ "notNull": true
67
+ },
68
+ "actor_type": {
69
+ "name": "actor_type",
70
+ "type": "actor_type",
71
+ "typeSchema": "audit",
72
+ "primaryKey": false,
73
+ "notNull": true
74
+ },
75
+ "impersonator_id": {
76
+ "name": "impersonator_id",
77
+ "type": "uuid",
78
+ "primaryKey": false,
79
+ "notNull": false
80
+ },
81
+ "impersonator_type": {
82
+ "name": "impersonator_type",
83
+ "type": "actor_type",
84
+ "typeSchema": "audit",
85
+ "primaryKey": false,
86
+ "notNull": false
87
+ },
88
+ "target_id": {
89
+ "name": "target_id",
90
+ "type": "uuid",
91
+ "primaryKey": false,
92
+ "notNull": true
93
+ },
94
+ "target_type": {
95
+ "name": "target_type",
96
+ "type": "text",
97
+ "primaryKey": false,
98
+ "notNull": true
99
+ },
100
+ "network_ip_address": {
101
+ "name": "network_ip_address",
102
+ "type": "text",
103
+ "primaryKey": false,
104
+ "notNull": false
105
+ },
106
+ "network_user_agent": {
107
+ "name": "network_user_agent",
108
+ "type": "text",
109
+ "primaryKey": false,
110
+ "notNull": false
111
+ },
112
+ "network_session_id": {
113
+ "name": "network_session_id",
114
+ "type": "uuid",
115
+ "primaryKey": false,
116
+ "notNull": false
117
+ },
118
+ "changes_before": {
119
+ "name": "changes_before",
120
+ "type": "jsonb",
121
+ "primaryKey": false,
122
+ "notNull": false
123
+ },
124
+ "changes_after": {
125
+ "name": "changes_after",
126
+ "type": "jsonb",
127
+ "primaryKey": false,
128
+ "notNull": false
129
+ },
130
+ "details": {
131
+ "name": "details",
132
+ "type": "jsonb",
133
+ "primaryKey": false,
134
+ "notNull": false
135
+ }
136
+ },
137
+ "indexes": {},
138
+ "foreignKeys": {},
139
+ "compositePrimaryKeys": {},
140
+ "uniqueConstraints": {},
141
+ "policies": {},
142
+ "checkConstraints": {},
143
+ "isRLSEnabled": false
144
+ }
145
+ },
146
+ "enums": {
147
+ "audit.actor_type": {
148
+ "name": "actor_type",
149
+ "schema": "audit",
150
+ "values": [
151
+ "user",
152
+ "system",
153
+ "api-key"
154
+ ]
155
+ },
156
+ "audit.audit_outcome": {
157
+ "name": "audit_outcome",
158
+ "schema": "audit",
159
+ "values": [
160
+ "pending",
161
+ "success",
162
+ "cancelled",
163
+ "failure",
164
+ "denied"
165
+ ]
166
+ },
167
+ "audit.audit_severity": {
168
+ "name": "audit_severity",
169
+ "schema": "audit",
170
+ "values": [
171
+ "info",
172
+ "warn",
173
+ "error",
174
+ "critical"
175
+ ]
176
+ }
177
+ },
178
+ "schemas": {},
179
+ "sequences": {},
180
+ "roles": {},
181
+ "policies": {},
182
+ "views": {},
183
+ "_meta": {
184
+ "columns": {},
185
+ "schemas": {},
186
+ "tables": {}
187
+ }
188
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1757676176019,
9
+ "tag": "0000_tiny_the_captain",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("drizzle-kit").Config;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { relative, resolve } from 'node:path';
2
+ import { defineConfig } from 'drizzle-kit';
3
+ export default defineConfig({
4
+ dialect: 'postgresql',
5
+ out: relative('./', resolve(__dirname, './drizzle/').replace('dist', 'source')),
6
+ schema: resolve(__dirname, './schemas.js'),
7
+ migrations: {
8
+ schema: 'audit',
9
+ table: '_migrations',
10
+ },
11
+ });
@@ -0,0 +1,22 @@
1
+ import type { DatabaseConfig } from '../orm/server/module.js';
2
+ /**
3
+ * Configuration for {@link configureAuditServer}.
4
+ */
5
+ export declare class AuditModuleConfig {
6
+ /**
7
+ * Database configuration for audit module.
8
+ * If not provided, the global database configuration is used.
9
+ */
10
+ database?: DatabaseConfig;
11
+ }
12
+ /**
13
+ * Configures audit server services.
14
+ * @param config Configuration.
15
+ */
16
+ export declare function configureAuditServer(config: AuditModuleConfig): void;
17
+ /**
18
+ * Migrates the audit database schema to the latest version.
19
+ * It uses the database connection provided with {@link configureAuditServer},
20
+ * or falls back to the globally configured database if no specific configuration is provided.
21
+ */
22
+ export declare function migrateAuditSchema(): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { inject } from '../injector/index.js';
2
+ import { Injector } from '../injector/injector.js';
3
+ import { Database, migrate } from '../orm/server/index.js';
4
+ /**
5
+ * Configuration for {@link configureAuditServer}.
6
+ */
7
+ export class AuditModuleConfig {
8
+ /**
9
+ * Database configuration for audit module.
10
+ * If not provided, the global database configuration is used.
11
+ */
12
+ database;
13
+ }
14
+ /**
15
+ * Configures audit server services.
16
+ * @param config Configuration.
17
+ */
18
+ export function configureAuditServer(config) {
19
+ Injector.register(AuditModuleConfig, { useValue: config });
20
+ }
21
+ /**
22
+ * Migrates the audit database schema to the latest version.
23
+ * It uses the database connection provided with {@link configureAuditServer},
24
+ * or falls back to the globally configured database if no specific configuration is provided.
25
+ */
26
+ export async function migrateAuditSchema() {
27
+ const connection = inject(AuditModuleConfig, undefined, { optional: true })?.database?.connection;
28
+ const database = inject(Database, connection);
29
+ await migrate(database, {
30
+ migrationsSchema: 'audit',
31
+ migrationsTable: '_migrations',
32
+ migrationsFolder: import.meta.resolve('./drizzle').replace('file://', ''),
33
+ });
34
+ }
@@ -0,0 +1,6 @@
1
+ import { AuditEvent } from './audit.model.js';
2
+ export declare const auditSchema: import("../orm/server/database-schema.js").DatabaseSchema<"audit">;
3
+ export declare const auditOutcome: import("drizzle-orm/pg-core").PgEnum<["pending", "success", "cancelled", "failure", "denied"]>;
4
+ export declare const auditSeverity: import("drizzle-orm/pg-core").PgEnum<["error", "warn", "info", "critical"]>;
5
+ export declare const actorType: import("drizzle-orm/pg-core").PgEnum<["user", "system", "api-key"]>;
6
+ export declare const auditEvent: import("../orm/server/types.js").PgTableFromType<typeof AuditEvent, "audit">;
@@ -0,0 +1,8 @@
1
+ import { databaseSchema } from '../orm/server/database-schema.js';
2
+ import { AuditEvent } from './audit.model.js';
3
+ import { ActorType, AuditOutcome, AuditSeverity } from './types.js';
4
+ export const auditSchema = databaseSchema('audit');
5
+ export const auditOutcome = auditSchema.getEnum(AuditOutcome);
6
+ export const auditSeverity = auditSchema.getEnum(AuditSeverity);
7
+ export const actorType = auditSchema.getEnum(ActorType);
8
+ export const auditEvent = auditSchema.getTable(AuditEvent);
@@ -1,7 +1,6 @@
1
1
  export * from './authentication-credentials.model.js';
2
2
  export * from './authentication-session.model.js';
3
3
  export * from './init-secret-reset-data.model.js';
4
- export * from './schemas.js';
5
4
  export * from './secret-check-result.model.js';
6
5
  export * from './token-payload-base.model.js';
7
6
  export * from './token.model.js';
@@ -1,7 +1,6 @@
1
1
  export * from './authentication-credentials.model.js';
2
2
  export * from './authentication-session.model.js';
3
3
  export * from './init-secret-reset-data.model.js';
4
- export * from './schemas.js';
5
4
  export * from './secret-check-result.model.js';
6
5
  export * from './token-payload-base.model.js';
7
6
  export * from './token.model.js';
@@ -3,7 +3,7 @@ import { defineConfig } from 'drizzle-kit';
3
3
  export default defineConfig({
4
4
  dialect: 'postgresql',
5
5
  out: relative('./', resolve(__dirname, './drizzle/').replace('dist', 'source')),
6
- schema: resolve(__dirname, '../models/schemas.js'),
6
+ schema: resolve(__dirname, './schemas.js'),
7
7
  migrations: {
8
8
  schema: 'authentication',
9
9
  table: '_migrations',
@@ -5,3 +5,4 @@ export * from './authentication.api-controller.js';
5
5
  export * from './authentication.service.js';
6
6
  export * from './helper.js';
7
7
  export * from './module.js';
8
+ export * from './schemas.js';
@@ -5,3 +5,4 @@ export * from './authentication.api-controller.js';
5
5
  export * from './authentication.service.js';
6
6
  export * from './helper.js';
7
7
  export * from './module.js';
8
+ export * from './schemas.js';
@@ -1,5 +1,5 @@
1
- import { AuthenticationCredentials } from './authentication-credentials.model.js';
2
- import { AuthenticationSession } from './authentication-session.model.js';
1
+ import { AuthenticationCredentials } from '../models/authentication-credentials.model.js';
2
+ import { AuthenticationSession } from '../models/authentication-session.model.js';
3
3
  export declare const authenticationSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"authentication">;
4
4
  export declare const authenticationCredentials: import("../../orm/server/types.js").PgTableFromType<typeof AuthenticationCredentials, "authentication">;
5
5
  export declare const authenticationSession: import("../../orm/server/types.js").PgTableFromType<typeof AuthenticationSession, "authentication">;
@@ -1,6 +1,6 @@
1
1
  import { databaseSchema } from '../../orm/server/database-schema.js';
2
- import { AuthenticationCredentials } from './authentication-credentials.model.js';
3
- import { AuthenticationSession } from './authentication-session.model.js';
2
+ import { AuthenticationCredentials } from '../models/authentication-credentials.model.js';
3
+ import { AuthenticationSession } from '../models/authentication-session.model.js';
4
4
  export const authenticationSchema = databaseSchema('authentication');
5
5
  export const authenticationCredentials = authenticationSchema.getTable(AuthenticationCredentials);
6
6
  export const authenticationSession = authenticationSchema.getTable(AuthenticationSession);
@@ -5,21 +5,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Singleton } from '../../injector/decorators.js';
8
+ import { supportsColoredStdout } from '../../supports.js';
8
9
  import { enumValueName } from '../../utils/enum.js';
9
10
  import { formatError } from '../../utils/format-error.js';
10
11
  import { isNotNullOrUndefined } from '../../utils/type-guards.js';
11
12
  import { LogFormatter } from '../formatter.js';
12
13
  import { LogLevel } from '../level.js';
13
14
  const levelColorMap = {
14
- [LogLevel.Error]: '\x1b[31m', // Red
15
- [LogLevel.Warn]: '\x1b[33m', // Yellow
16
- [LogLevel.Info]: '\x1b[32m', // Green
17
- [LogLevel.Verbose]: '\x1b[36m', // Cyan
18
- [LogLevel.Debug]: '\x1b[34m', // Blue
19
- [LogLevel.Trace]: '\x1b[90m', // Gray
15
+ [LogLevel.Error]: supportsColoredStdout ? '\x1b[31m' : '', // Red
16
+ [LogLevel.Warn]: supportsColoredStdout ? '\x1b[33m' : '', // Yellow
17
+ [LogLevel.Info]: supportsColoredStdout ? '\x1b[32m' : '', // Green
18
+ [LogLevel.Verbose]: supportsColoredStdout ? '\x1b[36m' : '', // Cyan
19
+ [LogLevel.Debug]: supportsColoredStdout ? '\x1b[34m' : '', // Blue
20
+ [LogLevel.Trace]: supportsColoredStdout ? '\x1b[90m' : '', // Gray
20
21
  };
21
- const resetColor = '\x1b[0m';
22
- const dimColor = '\x1b[2m';
22
+ const resetColor = supportsColoredStdout ? '\x1b[0m' : '';
23
+ const dimColor = supportsColoredStdout ? '\x1b[2m' : '';
23
24
  /** Formats log entries in a human-readable, colorful format for development consoles. */
24
25
  let PrettyPrintLogFormatter = class PrettyPrintLogFormatter extends LogFormatter {
25
26
  format(payload) {
package/orm/entity.d.ts CHANGED
@@ -40,3 +40,9 @@ export declare abstract class Entity {
40
40
  export declare abstract class EntityWithoutMetadata {
41
41
  id: IsPrimaryKey<HasDefault<Uuid>>;
42
42
  }
43
+ export declare abstract class TenantEntity extends Entity {
44
+ tenantId: Uuid;
45
+ }
46
+ export declare abstract class TenantEntityWithoutMetadata extends EntityWithoutMetadata {
47
+ tenantId: Uuid;
48
+ }
package/orm/entity.js CHANGED
@@ -83,3 +83,17 @@ __decorate([
83
83
  Uuid({ defaultRandom: true }),
84
84
  __metadata("design:type", Object)
85
85
  ], EntityWithoutMetadata.prototype, "id", void 0);
86
+ export class TenantEntity extends Entity {
87
+ tenantId;
88
+ }
89
+ __decorate([
90
+ Uuid(),
91
+ __metadata("design:type", String)
92
+ ], TenantEntity.prototype, "tenantId", void 0);
93
+ export class TenantEntityWithoutMetadata extends EntityWithoutMetadata {
94
+ tenantId;
95
+ }
96
+ __decorate([
97
+ Uuid(),
98
+ __metadata("design:type", String)
99
+ ], TenantEntityWithoutMetadata.prototype, "tenantId", void 0);