@tstdl/base 0.93.77 → 0.93.80

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 (105) hide show
  1. package/authentication/client/http-client.middleware.js +2 -2
  2. package/authentication/models/authentication-credentials.model.d.ts +2 -2
  3. package/authentication/models/authentication-credentials.model.js +5 -3
  4. package/authentication/models/authentication-session.model.d.ts +2 -2
  5. package/authentication/models/authentication-session.model.js +5 -3
  6. package/authentication/models/index.d.ts +4 -0
  7. package/authentication/models/index.js +4 -0
  8. package/authentication/models/service-account.model.d.ts +7 -0
  9. package/authentication/models/service-account.model.js +31 -0
  10. package/authentication/models/subject.model.d.ts +16 -0
  11. package/authentication/models/subject.model.js +59 -0
  12. package/authentication/models/system-account.model.d.ts +5 -0
  13. package/authentication/models/system-account.model.js +25 -0
  14. package/authentication/models/user.model.d.ts +15 -0
  15. package/authentication/models/user.model.js +47 -0
  16. package/authentication/server/drizzle/0000_violet_callisto.sql +99 -0
  17. package/authentication/server/drizzle/meta/0000_snapshot.json +500 -6
  18. package/authentication/server/drizzle/meta/_journal.json +2 -2
  19. package/authentication/server/index.d.ts +1 -0
  20. package/authentication/server/index.js +1 -0
  21. package/authentication/server/schemas.d.ts +16 -1
  22. package/authentication/server/schemas.js +7 -1
  23. package/authentication/server/subject.service.d.ts +6 -0
  24. package/authentication/server/subject.service.js +44 -0
  25. package/circuit-breaker/circuit-breaker.d.ts +32 -0
  26. package/circuit-breaker/circuit-breaker.js +9 -0
  27. package/circuit-breaker/index.d.ts +2 -0
  28. package/circuit-breaker/index.js +2 -0
  29. package/circuit-breaker/postgres/circuit-breaker.d.ts +7 -0
  30. package/circuit-breaker/postgres/circuit-breaker.js +78 -0
  31. package/circuit-breaker/postgres/drizzle/0000_hard_shocker.sql +9 -0
  32. package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +82 -0
  33. package/circuit-breaker/postgres/drizzle/meta/_journal.json +13 -0
  34. package/circuit-breaker/postgres/drizzle.config.d.ts +2 -0
  35. package/circuit-breaker/postgres/drizzle.config.js +11 -0
  36. package/circuit-breaker/postgres/index.d.ts +5 -0
  37. package/circuit-breaker/postgres/index.js +5 -0
  38. package/circuit-breaker/postgres/model.d.ts +9 -0
  39. package/circuit-breaker/postgres/model.js +40 -0
  40. package/circuit-breaker/postgres/module.d.ts +6 -0
  41. package/circuit-breaker/postgres/module.js +25 -0
  42. package/circuit-breaker/postgres/provider.d.ts +6 -0
  43. package/circuit-breaker/postgres/provider.js +21 -0
  44. package/circuit-breaker/postgres/schemas.d.ts +8 -0
  45. package/circuit-breaker/postgres/schemas.js +6 -0
  46. package/circuit-breaker/provider.d.ts +4 -0
  47. package/circuit-breaker/provider.js +2 -0
  48. package/circuit-breaker/tests/circuit-breaker.test.js +113 -0
  49. package/document-management/models/document.model.d.ts +0 -1
  50. package/document-management/models/document.model.js +0 -5
  51. package/document-management/server/api/document-management.api.js +1 -2
  52. package/document-management/server/drizzle/{0000_ordinary_pretty_boy.sql → 0000_glamorous_lorna_dane.sql} +96 -76
  53. package/document-management/server/drizzle/meta/0000_snapshot.json +360 -142
  54. package/document-management/server/drizzle/meta/_journal.json +2 -9
  55. package/document-management/server/services/document-collection.service.js +3 -3
  56. package/document-management/server/services/document-management-ancillary.service.d.ts +1 -1
  57. package/document-management/server/services/document-management.service.js +1 -1
  58. package/document-management/server/services/document-workflow.service.js +5 -5
  59. package/document-management/server/services/document.service.d.ts +0 -2
  60. package/document-management/server/services/document.service.js +1 -2
  61. package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
  62. package/examples/document-management/main.d.ts +1 -1
  63. package/examples/document-management/main.js +1 -1
  64. package/logger/transports/console.d.ts +1 -1
  65. package/logger/transports/console.js +4 -1
  66. package/message-bus/message-bus-base.js +1 -1
  67. package/orm/server/drizzle/schema-converter.js +53 -32
  68. package/package.json +6 -3
  69. package/queue/enqueue-batch.d.ts +11 -11
  70. package/queue/enqueue-batch.js +2 -3
  71. package/queue/index.d.ts +1 -0
  72. package/queue/index.js +1 -0
  73. package/queue/postgres/drizzle/0003_tricky_venom.sql +30 -0
  74. package/queue/postgres/drizzle/meta/0003_snapshot.json +288 -0
  75. package/queue/postgres/drizzle/meta/_journal.json +7 -0
  76. package/queue/postgres/drizzle.config.js +2 -2
  77. package/queue/postgres/index.d.ts +1 -1
  78. package/queue/postgres/index.js +1 -1
  79. package/queue/postgres/module.d.ts +1 -1
  80. package/queue/postgres/module.js +1 -1
  81. package/queue/postgres/queue.d.ts +52 -23
  82. package/queue/postgres/queue.js +582 -64
  83. package/queue/postgres/queue.provider.d.ts +1 -1
  84. package/queue/postgres/schemas.d.ts +13 -2
  85. package/queue/postgres/schemas.js +4 -2
  86. package/queue/postgres/task.model.d.ts +24 -0
  87. package/queue/postgres/task.model.js +115 -0
  88. package/queue/provider.d.ts +1 -1
  89. package/queue/queue.d.ts +158 -37
  90. package/queue/queue.js +97 -19
  91. package/queue/task-context.d.ts +38 -0
  92. package/queue/task-context.js +102 -0
  93. package/queue/tests/queue.test.d.ts +1 -0
  94. package/queue/tests/queue.test.js +623 -0
  95. package/test4.d.ts +1 -1
  96. package/test4.js +1 -1
  97. package/utils/format-error.d.ts +17 -20
  98. package/utils/format-error.js +105 -47
  99. package/authentication/server/drizzle/0000_calm_warlock.sql +0 -28
  100. package/document-management/server/drizzle/0001_lyrical_wong.sql +0 -123
  101. package/document-management/server/drizzle/meta/0001_snapshot.json +0 -2728
  102. package/queue/postgres/job.model.d.ts +0 -12
  103. package/queue/postgres/job.model.js +0 -53
  104. package/test6.js +0 -33
  105. /package/{test6.d.ts → circuit-breaker/tests/circuit-breaker.test.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { firstValueFrom } from 'rxjs';
1
+ import { firstValueFrom, timeout } from 'rxjs';
2
2
  import { cacheValueOrAsyncProvider } from '../../utils/value-or-provider.js';
3
3
  import { dontWaitForValidToken } from '../authentication.api.js';
4
4
  /**
@@ -13,7 +13,7 @@ export function waitForAuthenticationCredentialsMiddleware(authenticationService
13
13
  if ((endpoint?.credentials == true) && (endpoint.data?.[dontWaitForValidToken] != true)) {
14
14
  const authenticationService = await getAuthenticationService();
15
15
  while (!authenticationService.hasValidToken) {
16
- await firstValueFrom(authenticationService.validToken$);
16
+ await firstValueFrom(authenticationService.validToken$.pipe(timeout(30000)));
17
17
  }
18
18
  }
19
19
  await next();
@@ -1,6 +1,6 @@
1
- import { Entity } from '../../orm/index.js';
1
+ import { Entity, type Uuid } from '../../orm/index.js';
2
2
  export declare class AuthenticationCredentials extends Entity {
3
- subject: string;
3
+ subject: Uuid;
4
4
  hashVersion: number;
5
5
  /**
6
6
  * The salt used to hash the secret.
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Entity, Table, Unique } from '../../orm/index.js';
11
- import { Integer, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
10
+ import { Entity, Reference, Table, Unique, UuidProperty } from '../../orm/index.js';
11
+ import { Integer, Uint8ArrayProperty } from '../../schema/index.js';
12
+ import { Subject } from './subject.model.js';
12
13
  let AuthenticationCredentials = class AuthenticationCredentials extends Entity {
13
14
  subject;
14
15
  hashVersion;
@@ -22,8 +23,9 @@ let AuthenticationCredentials = class AuthenticationCredentials extends Entity {
22
23
  hash;
23
24
  };
24
25
  __decorate([
25
- StringProperty(),
26
+ Reference(() => Subject),
26
27
  Unique(),
28
+ UuidProperty(),
27
29
  __metadata("design:type", String)
28
30
  ], AuthenticationCredentials.prototype, "subject", void 0);
29
31
  __decorate([
@@ -1,7 +1,7 @@
1
- import type { Timestamp } from '../../orm/index.js';
1
+ import type { Timestamp, Uuid } from '../../orm/index.js';
2
2
  import { Entity } from '../../orm/index.js';
3
3
  export declare class AuthenticationSession extends Entity {
4
- subject: string;
4
+ subject: Uuid;
5
5
  begin: Timestamp;
6
6
  end: Timestamp;
7
7
  refreshTokenHashVersion: number;
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Entity, Table, TimestampProperty } from '../../orm/index.js';
11
- import { Integer, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
10
+ import { Entity, Reference, Table, TimestampProperty, UuidProperty } from '../../orm/index.js';
11
+ import { Integer, Uint8ArrayProperty } from '../../schema/index.js';
12
+ import { Subject } from './subject.model.js';
12
13
  let AuthenticationSession = class AuthenticationSession extends Entity {
13
14
  subject;
14
15
  begin;
@@ -24,7 +25,8 @@ let AuthenticationSession = class AuthenticationSession extends Entity {
24
25
  refreshTokenHash;
25
26
  };
26
27
  __decorate([
27
- StringProperty(),
28
+ Reference(() => Subject),
29
+ UuidProperty(),
28
30
  __metadata("design:type", String)
29
31
  ], AuthenticationSession.prototype, "subject", void 0);
30
32
  __decorate([
@@ -2,5 +2,9 @@ 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
4
  export * from './secret-check-result.model.js';
5
+ export * from './service-account.model.js';
6
+ export * from './subject.model.js';
7
+ export * from './system-account.model.js';
5
8
  export * from './token-payload-base.model.js';
6
9
  export * from './token.model.js';
10
+ export * from './user.model.js';
@@ -2,5 +2,9 @@ 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
4
  export * from './secret-check-result.model.js';
5
+ export * from './service-account.model.js';
6
+ export * from './subject.model.js';
7
+ export * from './system-account.model.js';
5
8
  export * from './token-payload-base.model.js';
6
9
  export * from './token.model.js';
10
+ export * from './user.model.js';
@@ -0,0 +1,7 @@
1
+ import { TenantEntity } from '../../orm/entity.js';
2
+ import { Subject } from './subject.model.js';
3
+ export declare class ServiceAccount extends TenantEntity {
4
+ description: string;
5
+ /** Who owns this service account? If null, it is a tenant-wide service account. */
6
+ parent: Subject | null;
7
+ }
@@ -0,0 +1,31 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { TenantEntity } from '../../orm/entity.js';
11
+ import { Table, TenantReference, UuidProperty } from '../../orm/index.js';
12
+ import { StringProperty } from '../../schema/index.js';
13
+ import { Subject } from './subject.model.js';
14
+ let ServiceAccount = class ServiceAccount extends TenantEntity {
15
+ description;
16
+ /** Who owns this service account? If null, it is a tenant-wide service account. */
17
+ parent;
18
+ };
19
+ __decorate([
20
+ StringProperty(),
21
+ __metadata("design:type", String)
22
+ ], ServiceAccount.prototype, "description", void 0);
23
+ __decorate([
24
+ TenantReference(() => Subject),
25
+ UuidProperty({ nullable: true }),
26
+ __metadata("design:type", Object)
27
+ ], ServiceAccount.prototype, "parent", void 0);
28
+ ServiceAccount = __decorate([
29
+ Table('service_account', { schema: 'authentication' })
30
+ ], ServiceAccount);
31
+ export { ServiceAccount };
@@ -0,0 +1,16 @@
1
+ import { type EnumType } from '../../enumeration/enumeration.js';
2
+ import { TenantEntity } from '../../orm/entity.js';
3
+ import { type Uuid } from '../../orm/index.js';
4
+ export declare const SubjectType: {
5
+ readonly System: "system";
6
+ readonly User: "user";
7
+ readonly ServiceAccount: "service-account";
8
+ };
9
+ export type SubjectType = EnumType<typeof SubjectType>;
10
+ export declare class Subject extends TenantEntity {
11
+ type: SubjectType;
12
+ displayName: string;
13
+ systemAccountId: Uuid | null;
14
+ userId: Uuid | null;
15
+ serviceAccountId: Uuid | null;
16
+ }
@@ -0,0 +1,59 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { defineEnum } from '../../enumeration/enumeration.js';
11
+ import { TenantEntity } from '../../orm/entity.js';
12
+ import { Check, exclusiveNotNull, Table, TenantReference, Unique, UuidProperty } from '../../orm/index.js';
13
+ import { Enumeration, StringProperty } from '../../schema/index.js';
14
+ import { ServiceAccount } from './service-account.model.js';
15
+ import { SystemAccount } from './system-account.model.js';
16
+ import { User } from './user.model.js';
17
+ export const SubjectType = defineEnum('SubjectType', {
18
+ System: 'system',
19
+ User: 'user',
20
+ ServiceAccount: 'service-account',
21
+ });
22
+ let Subject = class Subject extends TenantEntity {
23
+ type;
24
+ displayName;
25
+ systemAccountId;
26
+ userId;
27
+ serviceAccountId;
28
+ };
29
+ __decorate([
30
+ Enumeration(SubjectType),
31
+ __metadata("design:type", String)
32
+ ], Subject.prototype, "type", void 0);
33
+ __decorate([
34
+ StringProperty(),
35
+ __metadata("design:type", String)
36
+ ], Subject.prototype, "displayName", void 0);
37
+ __decorate([
38
+ Unique(),
39
+ TenantReference(() => SystemAccount),
40
+ UuidProperty({ nullable: true }),
41
+ __metadata("design:type", Object)
42
+ ], Subject.prototype, "systemAccountId", void 0);
43
+ __decorate([
44
+ Unique(),
45
+ TenantReference(() => User),
46
+ UuidProperty({ nullable: true }),
47
+ __metadata("design:type", Object)
48
+ ], Subject.prototype, "userId", void 0);
49
+ __decorate([
50
+ Unique(),
51
+ TenantReference(() => ServiceAccount),
52
+ UuidProperty({ nullable: true }),
53
+ __metadata("design:type", Object)
54
+ ], Subject.prototype, "serviceAccountId", void 0);
55
+ Subject = __decorate([
56
+ Table('subject', { schema: 'authentication' }),
57
+ Check('authentication_subject_reference_check', (table) => exclusiveNotNull(table.systemAccountId, table.userId, table.serviceAccountId))
58
+ ], Subject);
59
+ export { Subject };
@@ -0,0 +1,5 @@
1
+ import { TenantEntity } from '../../orm/entity.js';
2
+ export declare class SystemAccount extends TenantEntity {
3
+ /** Programmatic name: 'cleanup-task', 'ai-agent' */
4
+ identifier: string;
5
+ }
@@ -0,0 +1,25 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { TenantEntity } from '../../orm/entity.js';
11
+ import { Table, Unique } from '../../orm/index.js';
12
+ import { StringProperty } from '../../schema/index.js';
13
+ let SystemAccount = class SystemAccount extends TenantEntity {
14
+ /** Programmatic name: 'cleanup-task', 'ai-agent' */
15
+ identifier;
16
+ };
17
+ __decorate([
18
+ Unique(),
19
+ StringProperty(),
20
+ __metadata("design:type", String)
21
+ ], SystemAccount.prototype, "identifier", void 0);
22
+ SystemAccount = __decorate([
23
+ Table('system_account', { schema: 'authentication' })
24
+ ], SystemAccount);
25
+ export { SystemAccount };
@@ -0,0 +1,15 @@
1
+ import { type EnumType } from '../../enumeration/enumeration.js';
2
+ import { TenantEntity } from '../../orm/entity.js';
3
+ export declare const UserStatus: {
4
+ readonly Active: "active";
5
+ readonly Suspended: "suspended";
6
+ readonly PendingApproval: "pending-approval";
7
+ readonly Invited: "invited";
8
+ };
9
+ export type UserStatus = EnumType<typeof UserStatus>;
10
+ export declare class User extends TenantEntity {
11
+ status: UserStatus;
12
+ email: string;
13
+ firstName: string;
14
+ lastName: string;
15
+ }
@@ -0,0 +1,47 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { defineEnum } from '../../enumeration/enumeration.js';
11
+ import { TenantEntity } from '../../orm/entity.js';
12
+ import { Table, Unique } from '../../orm/index.js';
13
+ import { Enumeration, StringProperty } from '../../schema/index.js';
14
+ import { mailPattern } from '../../utils/patterns.js';
15
+ export const UserStatus = defineEnum('UserStatus', {
16
+ Active: 'active',
17
+ Suspended: 'suspended',
18
+ PendingApproval: 'pending-approval',
19
+ Invited: 'invited',
20
+ });
21
+ let User = class User extends TenantEntity {
22
+ status;
23
+ email;
24
+ firstName;
25
+ lastName;
26
+ };
27
+ __decorate([
28
+ Enumeration(UserStatus),
29
+ __metadata("design:type", String)
30
+ ], User.prototype, "status", void 0);
31
+ __decorate([
32
+ StringProperty({ pattern: mailPattern }),
33
+ __metadata("design:type", String)
34
+ ], User.prototype, "email", void 0);
35
+ __decorate([
36
+ StringProperty(),
37
+ __metadata("design:type", String)
38
+ ], User.prototype, "firstName", void 0);
39
+ __decorate([
40
+ StringProperty(),
41
+ __metadata("design:type", String)
42
+ ], User.prototype, "lastName", void 0);
43
+ User = __decorate([
44
+ Table('user', { schema: 'authentication' }),
45
+ Unique(['tenantId', 'email'])
46
+ ], User);
47
+ export { User };
@@ -0,0 +1,99 @@
1
+ CREATE TYPE "authentication"."subject_type" AS ENUM('system', 'user', 'service-account');--> statement-breakpoint
2
+ CREATE TYPE "authentication"."user_status" AS ENUM('active', 'suspended', 'pending-approval', 'invited');--> statement-breakpoint
3
+ CREATE TABLE "authentication"."credentials" (
4
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
5
+ "subject" uuid NOT NULL,
6
+ "hash_version" integer NOT NULL,
7
+ "salt" "bytea" NOT NULL,
8
+ "hash" "bytea" NOT NULL,
9
+ "revision" integer NOT NULL,
10
+ "revision_timestamp" timestamp with time zone NOT NULL,
11
+ "create_timestamp" timestamp with time zone NOT NULL,
12
+ "delete_timestamp" timestamp with time zone,
13
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
14
+ CONSTRAINT "credentials_subject_unique" UNIQUE("subject")
15
+ );
16
+ --> statement-breakpoint
17
+ CREATE TABLE "authentication"."session" (
18
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
19
+ "subject" uuid NOT NULL,
20
+ "begin" timestamp with time zone NOT NULL,
21
+ "end" timestamp with time zone NOT NULL,
22
+ "refresh_token_hash_version" integer NOT NULL,
23
+ "refresh_token_salt" "bytea" NOT NULL,
24
+ "refresh_token_hash" "bytea" NOT NULL,
25
+ "revision" integer NOT NULL,
26
+ "revision_timestamp" timestamp with time zone NOT NULL,
27
+ "create_timestamp" timestamp with time zone NOT NULL,
28
+ "delete_timestamp" timestamp with time zone,
29
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL
30
+ );
31
+ --> statement-breakpoint
32
+ CREATE TABLE "authentication"."service_account" (
33
+ "id" uuid DEFAULT gen_random_uuid() NOT NULL,
34
+ "tenant_id" uuid NOT NULL,
35
+ "description" text NOT NULL,
36
+ "parent" uuid,
37
+ "revision" integer NOT NULL,
38
+ "revision_timestamp" timestamp with time zone NOT NULL,
39
+ "create_timestamp" timestamp with time zone NOT NULL,
40
+ "delete_timestamp" timestamp with time zone,
41
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
42
+ CONSTRAINT "service_account_tenant_id_id_pk" PRIMARY KEY("tenant_id","id")
43
+ );
44
+ --> statement-breakpoint
45
+ CREATE TABLE "authentication"."subject" (
46
+ "id" uuid DEFAULT gen_random_uuid() NOT NULL,
47
+ "tenant_id" uuid NOT NULL,
48
+ "type" "authentication"."subject_type" NOT NULL,
49
+ "display_name" text NOT NULL,
50
+ "system_account_id" uuid,
51
+ "user_id" uuid,
52
+ "service_account_id" uuid,
53
+ "revision" integer NOT NULL,
54
+ "revision_timestamp" timestamp with time zone NOT NULL,
55
+ "create_timestamp" timestamp with time zone NOT NULL,
56
+ "delete_timestamp" timestamp with time zone,
57
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
58
+ CONSTRAINT "subject_tenant_id_id_pk" PRIMARY KEY("tenant_id","id"),
59
+ CONSTRAINT "subject_system_account_id_unique" UNIQUE("system_account_id"),
60
+ CONSTRAINT "subject_user_id_unique" UNIQUE("user_id"),
61
+ CONSTRAINT "subject_service_account_id_unique" UNIQUE("service_account_id"),
62
+ CONSTRAINT "authentication_subject_reference_check" CHECK (num_nonnulls("authentication"."subject"."system_account_id", "authentication"."subject"."user_id", "authentication"."subject"."service_account_id") = 1)
63
+ );
64
+ --> statement-breakpoint
65
+ CREATE TABLE "authentication"."system_account" (
66
+ "id" uuid DEFAULT gen_random_uuid() NOT NULL,
67
+ "tenant_id" uuid NOT NULL,
68
+ "identifier" text NOT NULL,
69
+ "revision" integer NOT NULL,
70
+ "revision_timestamp" timestamp with time zone NOT NULL,
71
+ "create_timestamp" timestamp with time zone NOT NULL,
72
+ "delete_timestamp" timestamp with time zone,
73
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
74
+ CONSTRAINT "system_account_tenant_id_id_pk" PRIMARY KEY("tenant_id","id"),
75
+ CONSTRAINT "system_account_identifier_unique" UNIQUE("identifier")
76
+ );
77
+ --> statement-breakpoint
78
+ CREATE TABLE "authentication"."user" (
79
+ "id" uuid DEFAULT gen_random_uuid() NOT NULL,
80
+ "tenant_id" uuid NOT NULL,
81
+ "status" "authentication"."user_status" NOT NULL,
82
+ "email" text NOT NULL,
83
+ "first_name" text NOT NULL,
84
+ "last_name" text NOT NULL,
85
+ "revision" integer NOT NULL,
86
+ "revision_timestamp" timestamp with time zone NOT NULL,
87
+ "create_timestamp" timestamp with time zone NOT NULL,
88
+ "delete_timestamp" timestamp with time zone,
89
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
90
+ CONSTRAINT "user_tenant_id_id_pk" PRIMARY KEY("tenant_id","id"),
91
+ CONSTRAINT "user_tenant_id_email_unique" UNIQUE("tenant_id","email")
92
+ );
93
+ --> statement-breakpoint
94
+ ALTER TABLE "authentication"."credentials" ADD CONSTRAINT "credentials_subject_subject_id_fk" FOREIGN KEY ("subject") REFERENCES "authentication"."subject"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
95
+ ALTER TABLE "authentication"."session" ADD CONSTRAINT "session_subject_subject_id_fk" FOREIGN KEY ("subject") REFERENCES "authentication"."subject"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
96
+ ALTER TABLE "authentication"."service_account" ADD CONSTRAINT "service_account_id_subject_fkey" FOREIGN KEY ("tenant_id","parent") REFERENCES "authentication"."subject"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
97
+ ALTER TABLE "authentication"."subject" ADD CONSTRAINT "subject_id_system_account_fkey" FOREIGN KEY ("tenant_id","system_account_id") REFERENCES "authentication"."system_account"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
98
+ ALTER TABLE "authentication"."subject" ADD CONSTRAINT "subject_id_user_fkey" FOREIGN KEY ("tenant_id","user_id") REFERENCES "authentication"."user"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
99
+ ALTER TABLE "authentication"."subject" ADD CONSTRAINT "subject_id_service_account_fkey" FOREIGN KEY ("tenant_id","service_account_id") REFERENCES "authentication"."service_account"("tenant_id","id") ON DELETE no action ON UPDATE no action;