@nest-yalc-2/omnikernel-module 2.2.1 → 2.2.4

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 (74) hide show
  1. package/package.json +22 -14
  2. package/src/__tests__/omni-collection.entity.spec.ts +49 -49
  3. package/src/__tests__/omni-collection.service.spec.ts +83 -83
  4. package/src/__tests__/omni-document.entity.spec.ts +55 -55
  5. package/src/__tests__/omni-document.service.spec.ts +83 -83
  6. package/src/__tests__/omni-extension-projection-constraints.spec.ts +518 -518
  7. package/src/__tests__/omni-extension-projection.registration.spec.ts +947 -946
  8. package/src/__tests__/omni-extension-projection.service.spec.ts +806 -806
  9. package/src/__tests__/omni-external-ref.entity.spec.ts +36 -36
  10. package/src/__tests__/omni-external-ref.service.spec.ts +252 -252
  11. package/src/__tests__/omni-named.entity.spec.ts +33 -33
  12. package/src/__tests__/omni-record.entity.spec.ts +32 -32
  13. package/src/__tests__/omni-record.service.spec.ts +107 -107
  14. package/src/__tests__/omni-relation-semantics.spec.ts +102 -102
  15. package/src/__tests__/omni-relation.entity.spec.ts +38 -38
  16. package/src/__tests__/omni-scope-substrate.spec.ts +81 -81
  17. package/src/__tests__/omni-scoped.backend.spec.ts +115 -115
  18. package/src/__tests__/omni-scoped.service.spec.ts +354 -354
  19. package/src/__tests__/omnikernel.diagnostics.spec.ts +94 -94
  20. package/src/__tests__/omnikernel.module.spec.ts +38 -40
  21. package/src/__tests__/omnikernel.persistence.spec.ts +154 -154
  22. package/src/__tests__/omnikernel.public-api.spec.ts +238 -238
  23. package/src/__tests__/omnikernel.query.service.spec.ts +155 -155
  24. package/src/base/omni-base.entity.ts +41 -41
  25. package/src/base/omni-external-ref.entity.ts +53 -53
  26. package/src/base/omni-named.entity.ts +16 -16
  27. package/src/base/omni-record.entity.ts +51 -51
  28. package/src/base/omni-relation.entity.ts +72 -72
  29. package/src/index.ts +49 -49
  30. package/src/omni-collection-kind.enum.ts +10 -10
  31. package/src/omni-collection.backend.ts +16 -16
  32. package/src/omni-collection.dto.ts +170 -170
  33. package/src/omni-collection.entity.ts +21 -21
  34. package/src/omni-collection.service.ts +75 -75
  35. package/src/omni-document-kind.enum.ts +12 -12
  36. package/src/omni-document.backend.ts +16 -16
  37. package/src/omni-document.dto.ts +198 -198
  38. package/src/omni-document.entity.ts +30 -30
  39. package/src/omni-document.service.ts +75 -75
  40. package/src/omni-dto.helpers.ts +21 -21
  41. package/src/omni-extension-projection.definition.ts +294 -294
  42. package/src/omni-extension-projection.resource.ts +274 -274
  43. package/src/omni-extension-projection.service.ts +452 -452
  44. package/src/omni-external-ref-binding.validator.ts +53 -53
  45. package/src/omni-external-ref-internal-type.enum.ts +11 -11
  46. package/src/omni-external-ref.backend.ts +25 -25
  47. package/src/omni-external-ref.dto.ts +128 -128
  48. package/src/omni-external-ref.service.ts +255 -255
  49. package/src/omni-migration.ts +365 -365
  50. package/src/omni-named.backend.ts +11 -11
  51. package/src/omni-named.dto.ts +86 -86
  52. package/src/omni-projection.catalog.ts +345 -345
  53. package/src/omni-projection.lifecycle.ts +53 -53
  54. package/src/omni-record-status.enum.ts +11 -11
  55. package/src/omni-record.backend.ts +19 -19
  56. package/src/omni-record.dto.ts +157 -157
  57. package/src/omni-record.service.ts +113 -113
  58. package/src/omni-relation-kind.contract.ts +49 -49
  59. package/src/omni-relation-kind.enum.ts +12 -12
  60. package/src/omni-relation-projection.definition.ts +166 -166
  61. package/src/omni-relation-projection.resource.ts +360 -360
  62. package/src/omni-relation-projection.service.ts +610 -610
  63. package/src/omni-relation-semantics.ts +52 -52
  64. package/src/omni-relation-status.enum.ts +11 -11
  65. package/src/omni-relation.backend.ts +21 -21
  66. package/src/omni-relation.dto.ts +142 -142
  67. package/src/omni-relation.service.ts +159 -159
  68. package/src/omni-scope.ts +161 -161
  69. package/src/omni-scoped.backend.ts +110 -110
  70. package/src/omni-scoped.repository.ts +34 -34
  71. package/src/omni-scoped.service.ts +338 -338
  72. package/src/omnikernel.diagnostics.ts +83 -83
  73. package/src/omnikernel.module.ts +97 -97
  74. package/src/omnikernel.query.service.ts +108 -108
@@ -1,155 +1,155 @@
1
- import { describe, expect, it, jest } from "@jest/globals";
2
-
3
- import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
4
- import { OmniDocumentKind } from '../omni-document-kind.enum.js';
5
- import { OmniExternalRefInternalType } from '../omni-external-ref-internal-type.enum.js';
6
- import { OmniKernelQueryService } from '../omnikernel.query.service.js';
7
-
8
- describe("OmniKernelQueryService", () => {
9
- it("returns collection members from canonical contains relations", async () => {
10
- const relationRepository = {
11
- find: jest.fn(async () => [
12
- {
13
- targetRecord: {
14
- guid: "doc-1",
15
- kind: OmniDocumentKind.Document,
16
- },
17
- },
18
- ]),
19
- };
20
- const externalRefRepository = {
21
- find: jest.fn(),
22
- };
23
- const service = new OmniKernelQueryService(
24
- relationRepository as never,
25
- externalRefRepository as never,
26
- );
27
-
28
- const result = await service.getCollectionMembers("collection-1");
29
-
30
- expect(relationRepository.find).toHaveBeenCalledWith(
31
- expect.objectContaining({
32
- where: expect.objectContaining({
33
- sourceRecordId: "collection-1",
34
- }),
35
- }),
36
- );
37
- expect(result).toEqual([
38
- {
39
- guid: "doc-1",
40
- kind: OmniDocumentKind.Document,
41
- },
42
- ]);
43
- });
44
-
45
- it("returns parent collections for a document through inverse contains relations", async () => {
46
- const relationRepository = {
47
- find: jest.fn(async () => [
48
- {
49
- sourceRecord: {
50
- guid: "collection-1",
51
- kind: OmniCollectionKind.Collection,
52
- },
53
- },
54
- ]),
55
- };
56
- const externalRefRepository = {
57
- find: jest.fn(),
58
- };
59
- const service = new OmniKernelQueryService(
60
- relationRepository as never,
61
- externalRefRepository as never,
62
- );
63
-
64
- const result = await service.getDocumentCollections("doc-1");
65
-
66
- expect(relationRepository.find).toHaveBeenCalledWith(
67
- expect.objectContaining({
68
- where: expect.objectContaining({
69
- targetRecordId: "doc-1",
70
- }),
71
- }),
72
- );
73
- expect(result).toEqual([
74
- {
75
- guid: "collection-1",
76
- kind: OmniCollectionKind.Collection,
77
- },
78
- ]);
79
- });
80
-
81
- it("filters out inverse contains sources that are not collections", async () => {
82
- const relationRepository = {
83
- find: jest.fn(async () => [
84
- {
85
- sourceRecord: {
86
- guid: "collection-1",
87
- kind: OmniCollectionKind.Collection,
88
- },
89
- },
90
- {
91
- sourceRecord: {
92
- guid: "doc-2",
93
- kind: OmniDocumentKind.Document,
94
- },
95
- },
96
- ]),
97
- };
98
- const externalRefRepository = {
99
- find: jest.fn(),
100
- };
101
- const service = new OmniKernelQueryService(
102
- relationRepository as never,
103
- externalRefRepository as never,
104
- );
105
-
106
- const result = await service.getDocumentCollections("doc-1");
107
-
108
- expect(result).toEqual([
109
- {
110
- guid: "collection-1",
111
- kind: OmniCollectionKind.Collection,
112
- },
113
- ]);
114
- });
115
-
116
- it("returns document external refs through the query layer", async () => {
117
- const relationRepository = {
118
- find: jest.fn(),
119
- };
120
- const externalRefRepository = {
121
- find: jest.fn(async () => [
122
- {
123
- guid: "ref-1",
124
- internalType: OmniExternalRefInternalType.Document,
125
- internalId: "doc-1",
126
- },
127
- ]),
128
- };
129
- const service = new OmniKernelQueryService(
130
- relationRepository as never,
131
- externalRefRepository as never,
132
- );
133
-
134
- const result = await service.getDocumentExternalRefs("doc-1", "github");
135
-
136
- expect(externalRefRepository.find).toHaveBeenCalledWith({
137
- where: {
138
- scopeId: "default",
139
- internalType: OmniExternalRefInternalType.Document,
140
- internalId: "doc-1",
141
- provider: "github",
142
- },
143
- order: {
144
- createdAt: "ASC",
145
- },
146
- });
147
- expect(result).toEqual([
148
- {
149
- guid: "ref-1",
150
- internalType: OmniExternalRefInternalType.Document,
151
- internalId: "doc-1",
152
- },
153
- ]);
154
- });
155
- });
1
+ import { describe, expect, it, jest } from "@jest/globals";
2
+
3
+ import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
4
+ import { OmniDocumentKind } from '../omni-document-kind.enum.js';
5
+ import { OmniExternalRefInternalType } from '../omni-external-ref-internal-type.enum.js';
6
+ import { OmniKernelQueryService } from '../omnikernel.query.service.js';
7
+
8
+ describe("OmniKernelQueryService", () => {
9
+ it("returns collection members from canonical contains relations", async () => {
10
+ const relationRepository = {
11
+ find: jest.fn(async () => [
12
+ {
13
+ targetRecord: {
14
+ guid: "doc-1",
15
+ kind: OmniDocumentKind.Document,
16
+ },
17
+ },
18
+ ]),
19
+ };
20
+ const externalRefRepository = {
21
+ find: jest.fn(),
22
+ };
23
+ const service = new OmniKernelQueryService(
24
+ relationRepository as never,
25
+ externalRefRepository as never,
26
+ );
27
+
28
+ const result = await service.getCollectionMembers("collection-1");
29
+
30
+ expect(relationRepository.find).toHaveBeenCalledWith(
31
+ expect.objectContaining({
32
+ where: expect.objectContaining({
33
+ sourceRecordId: "collection-1",
34
+ }),
35
+ }),
36
+ );
37
+ expect(result).toEqual([
38
+ {
39
+ guid: "doc-1",
40
+ kind: OmniDocumentKind.Document,
41
+ },
42
+ ]);
43
+ });
44
+
45
+ it("returns parent collections for a document through inverse contains relations", async () => {
46
+ const relationRepository = {
47
+ find: jest.fn(async () => [
48
+ {
49
+ sourceRecord: {
50
+ guid: "collection-1",
51
+ kind: OmniCollectionKind.Collection,
52
+ },
53
+ },
54
+ ]),
55
+ };
56
+ const externalRefRepository = {
57
+ find: jest.fn(),
58
+ };
59
+ const service = new OmniKernelQueryService(
60
+ relationRepository as never,
61
+ externalRefRepository as never,
62
+ );
63
+
64
+ const result = await service.getDocumentCollections("doc-1");
65
+
66
+ expect(relationRepository.find).toHaveBeenCalledWith(
67
+ expect.objectContaining({
68
+ where: expect.objectContaining({
69
+ targetRecordId: "doc-1",
70
+ }),
71
+ }),
72
+ );
73
+ expect(result).toEqual([
74
+ {
75
+ guid: "collection-1",
76
+ kind: OmniCollectionKind.Collection,
77
+ },
78
+ ]);
79
+ });
80
+
81
+ it("filters out inverse contains sources that are not collections", async () => {
82
+ const relationRepository = {
83
+ find: jest.fn(async () => [
84
+ {
85
+ sourceRecord: {
86
+ guid: "collection-1",
87
+ kind: OmniCollectionKind.Collection,
88
+ },
89
+ },
90
+ {
91
+ sourceRecord: {
92
+ guid: "doc-2",
93
+ kind: OmniDocumentKind.Document,
94
+ },
95
+ },
96
+ ]),
97
+ };
98
+ const externalRefRepository = {
99
+ find: jest.fn(),
100
+ };
101
+ const service = new OmniKernelQueryService(
102
+ relationRepository as never,
103
+ externalRefRepository as never,
104
+ );
105
+
106
+ const result = await service.getDocumentCollections("doc-1");
107
+
108
+ expect(result).toEqual([
109
+ {
110
+ guid: "collection-1",
111
+ kind: OmniCollectionKind.Collection,
112
+ },
113
+ ]);
114
+ });
115
+
116
+ it("returns document external refs through the query layer", async () => {
117
+ const relationRepository = {
118
+ find: jest.fn(),
119
+ };
120
+ const externalRefRepository = {
121
+ find: jest.fn(async () => [
122
+ {
123
+ guid: "ref-1",
124
+ internalType: OmniExternalRefInternalType.Document,
125
+ internalId: "doc-1",
126
+ },
127
+ ]),
128
+ };
129
+ const service = new OmniKernelQueryService(
130
+ relationRepository as never,
131
+ externalRefRepository as never,
132
+ );
133
+
134
+ const result = await service.getDocumentExternalRefs("doc-1", "github");
135
+
136
+ expect(externalRefRepository.find).toHaveBeenCalledWith({
137
+ where: {
138
+ scopeId: "default",
139
+ internalType: OmniExternalRefInternalType.Document,
140
+ internalId: "doc-1",
141
+ provider: "github",
142
+ },
143
+ order: {
144
+ createdAt: "ASC",
145
+ },
146
+ });
147
+ expect(result).toEqual([
148
+ {
149
+ guid: "ref-1",
150
+ internalType: OmniExternalRefInternalType.Document,
151
+ internalId: "doc-1",
152
+ },
153
+ ]);
154
+ });
155
+ });
@@ -1,41 +1,41 @@
1
- import { ObjectType } from '@nestjs/graphql';
2
- import {
3
- BaseEntity,
4
- CreateDateColumn,
5
- DeleteDateColumn,
6
- PrimaryColumn,
7
- UpdateDateColumn,
8
- VersionColumn,
9
- } from 'typeorm';
10
-
11
- @ObjectType({ isAbstract: true })
12
- export abstract class OmniBaseEntity extends BaseEntity {
13
- /**
14
- * The server-owned partition key. It is never represented by the public
15
- * CRUD DTOs. Together with guid it is the composite primary identity, which
16
- * lets the same logical GUID exist in independent server-owned partitions.
17
- */
18
- @PrimaryColumn('varchar', {
19
- name: 'scopeId',
20
- length: 64,
21
- default: 'default',
22
- })
23
- scopeId: string = 'default';
24
-
25
- @PrimaryColumn('varchar', { name: 'guid', length: 36 })
26
- guid!: string;
27
-
28
- /** Server-managed optimistic version for ordinary Omni updates. */
29
- @VersionColumn({ type: 'integer', default: 1 })
30
- revision!: number;
31
-
32
- /** Present only for resources configured with the tombstone lifecycle. */
33
- @DeleteDateColumn({ nullable: true })
34
- deletedAt?: Date | null;
35
-
36
- @CreateDateColumn()
37
- createdAt!: Date;
38
-
39
- @UpdateDateColumn()
40
- updatedAt!: Date;
41
- }
1
+ import { ObjectType } from '@nestjs/graphql';
2
+ import {
3
+ BaseEntity,
4
+ CreateDateColumn,
5
+ DeleteDateColumn,
6
+ PrimaryColumn,
7
+ UpdateDateColumn,
8
+ VersionColumn,
9
+ } from 'typeorm';
10
+
11
+ @ObjectType({ isAbstract: true })
12
+ export abstract class OmniBaseEntity extends BaseEntity {
13
+ /**
14
+ * The server-owned partition key. It is never represented by the public
15
+ * CRUD DTOs. Together with guid it is the composite primary identity, which
16
+ * lets the same logical GUID exist in independent server-owned partitions.
17
+ */
18
+ @PrimaryColumn('varchar', {
19
+ name: 'scopeId',
20
+ length: 64,
21
+ default: 'default',
22
+ })
23
+ scopeId: string = 'default';
24
+
25
+ @PrimaryColumn('varchar', { name: 'guid', length: 36 })
26
+ guid!: string;
27
+
28
+ /** Server-managed optimistic version for ordinary Omni updates. */
29
+ @VersionColumn({ type: 'integer', default: 1 })
30
+ revision!: number;
31
+
32
+ /** Present only for resources configured with the tombstone lifecycle. */
33
+ @DeleteDateColumn({ nullable: true })
34
+ deletedAt?: Date | null;
35
+
36
+ @CreateDateColumn()
37
+ createdAt!: Date;
38
+
39
+ @UpdateDateColumn()
40
+ updatedAt!: Date;
41
+ }
@@ -1,53 +1,53 @@
1
- import { ObjectType } from '@nestjs/graphql';
2
- import { Column, Entity, Index } from 'typeorm';
3
- import { OmniBaseEntity } from './omni-base.entity.js';
4
- import { OmniExternalRefInternalType } from '../omni-external-ref-internal-type.enum.js';
5
-
6
- @Entity('omni-external-ref')
7
- @Index(
8
- 'omni_external_ref_scope_external_identity_unique',
9
- ['scopeId', 'provider', 'account', 'container', 'externalId'],
10
- { unique: true },
11
- )
12
- @Index('omni_external_ref_scope_internal_lookup_idx', [
13
- 'scopeId',
14
- 'internalType',
15
- 'internalId',
16
- 'provider',
17
- 'guid',
18
- ])
19
- @ObjectType({ isAbstract: true })
20
- export class OmniExternalRefEntity extends OmniBaseEntity {
21
- @Column({
22
- type: 'varchar',
23
- enum: Object.values(OmniExternalRefInternalType),
24
- length: 64,
25
- })
26
- internalType!: OmniExternalRefInternalType;
27
-
28
- @Column({ type: 'varchar', length: 36 })
29
- internalId!: string;
30
-
31
- @Column({ type: 'varchar', length: 128 })
32
- provider!: string;
33
-
34
- /** Empty string is the canonical storage representation of no account. */
35
- @Column({ type: 'varchar', default: '', length: 128 })
36
- account?: string | null;
37
-
38
- /** Empty string is the canonical storage representation of no container. */
39
- @Column({ type: 'varchar', default: '', length: 128 })
40
- container?: string | null;
41
-
42
- @Column({ type: 'varchar', length: 255 })
43
- externalId!: string;
44
-
45
- @Column({ type: 'simple-json', nullable: true })
46
- payload?: Record<string, unknown> | null;
47
-
48
- @Column({ type: 'varchar', nullable: true, length: 128 })
49
- payloadSchemaId?: string | null;
50
-
51
- @Column({ type: 'integer', nullable: true })
52
- payloadSchemaVersion?: number | null;
53
- }
1
+ import { ObjectType } from '@nestjs/graphql';
2
+ import { Column, Entity, Index } from 'typeorm';
3
+ import { OmniBaseEntity } from './omni-base.entity.js';
4
+ import { OmniExternalRefInternalType } from '../omni-external-ref-internal-type.enum.js';
5
+
6
+ @Entity('omni-external-ref')
7
+ @Index(
8
+ 'omni_external_ref_scope_external_identity_unique',
9
+ ['scopeId', 'provider', 'account', 'container', 'externalId'],
10
+ { unique: true },
11
+ )
12
+ @Index('omni_external_ref_scope_internal_lookup_idx', [
13
+ 'scopeId',
14
+ 'internalType',
15
+ 'internalId',
16
+ 'provider',
17
+ 'guid',
18
+ ])
19
+ @ObjectType({ isAbstract: true })
20
+ export class OmniExternalRefEntity extends OmniBaseEntity {
21
+ @Column({
22
+ type: 'varchar',
23
+ enum: Object.values(OmniExternalRefInternalType),
24
+ length: 64,
25
+ })
26
+ internalType!: OmniExternalRefInternalType;
27
+
28
+ @Column({ type: 'varchar', length: 36 })
29
+ internalId!: string;
30
+
31
+ @Column({ type: 'varchar', length: 128 })
32
+ provider!: string;
33
+
34
+ /** Empty string is the canonical storage representation of no account. */
35
+ @Column({ type: 'varchar', default: '', length: 128 })
36
+ account?: string | null;
37
+
38
+ /** Empty string is the canonical storage representation of no container. */
39
+ @Column({ type: 'varchar', default: '', length: 128 })
40
+ container?: string | null;
41
+
42
+ @Column({ type: 'varchar', length: 255 })
43
+ externalId!: string;
44
+
45
+ @Column({ type: 'simple-json', nullable: true })
46
+ payload?: Record<string, unknown> | null;
47
+
48
+ @Column({ type: 'varchar', nullable: true, length: 128 })
49
+ payloadSchemaId?: string | null;
50
+
51
+ @Column({ type: 'integer', nullable: true })
52
+ payloadSchemaVersion?: number | null;
53
+ }
@@ -1,16 +1,16 @@
1
- import { ObjectType } from '@nestjs/graphql';
2
- import { Column, Entity } from 'typeorm';
3
- import { OmniBaseEntity } from './omni-base.entity.js';
4
-
5
- @Entity('omni-named')
6
- @ObjectType({ isAbstract: true })
7
- export class OmniNamedEntity extends OmniBaseEntity {
8
- @Column({ type: 'varchar', nullable: true, length: 128 })
9
- externalId?: string | null;
10
-
11
- @Column({ type: 'varchar', length: 255 })
12
- title!: string;
13
-
14
- @Column({ type: 'varchar', nullable: true, length: 255 })
15
- slug?: string | null;
16
- }
1
+ import { ObjectType } from '@nestjs/graphql';
2
+ import { Column, Entity } from 'typeorm';
3
+ import { OmniBaseEntity } from './omni-base.entity.js';
4
+
5
+ @Entity('omni-named')
6
+ @ObjectType({ isAbstract: true })
7
+ export class OmniNamedEntity extends OmniBaseEntity {
8
+ @Column({ type: 'varchar', nullable: true, length: 128 })
9
+ externalId?: string | null;
10
+
11
+ @Column({ type: 'varchar', length: 255 })
12
+ title!: string;
13
+
14
+ @Column({ type: 'varchar', nullable: true, length: 255 })
15
+ slug?: string | null;
16
+ }
@@ -1,51 +1,51 @@
1
- import { ObjectType } from '@nestjs/graphql';
2
- import { Column, Entity, Index, OneToMany, TableInheritance } from 'typeorm';
3
- import type { Relation } from 'typeorm';
4
- import { OmniNamedEntity } from './omni-named.entity.js';
5
- import { OmniRelationEntity } from './omni-relation.entity.js';
6
- import { OmniRecordStatus } from '../omni-record-status.enum.js';
7
-
8
- @Entity('omni-record')
9
- @Index('omni_record_scope_kind_status_guid_idx', [
10
- 'scopeId',
11
- 'kind',
12
- 'status',
13
- 'guid',
14
- ])
15
- @TableInheritance({
16
- column: {
17
- name: 'recordType',
18
- type: 'varchar',
19
- length: 32,
20
- },
21
- })
22
- @ObjectType({ isAbstract: true })
23
- export class OmniRecordEntity extends OmniNamedEntity {
24
- @Column({ type: 'varchar', length: 64 })
25
- kind!: string;
26
-
27
- @Column({
28
- type: 'varchar',
29
- default: OmniRecordStatus.Draft,
30
- enum: Object.values(OmniRecordStatus),
31
- length: 32,
32
- })
33
- status!: OmniRecordStatus;
34
-
35
- @Column({ type: 'simple-json', nullable: true })
36
- payload?: Record<string, unknown> | null;
37
-
38
- /** Logical schema identity for JSON payload compatibility and migration. */
39
- @Column({ type: 'varchar', nullable: true, length: 128 })
40
- payloadSchemaId?: string | null;
41
-
42
- /** Revision of payloadSchemaId; a schema change is explicit metadata. */
43
- @Column({ type: 'integer', nullable: true })
44
- payloadSchemaVersion?: number | null;
45
-
46
- @OneToMany(() => OmniRelationEntity, (relation) => relation.sourceRecord)
47
- outgoingRelations?: Relation<OmniRelationEntity[]>;
48
-
49
- @OneToMany(() => OmniRelationEntity, (relation) => relation.targetRecord)
50
- incomingRelations?: Relation<OmniRelationEntity[]>;
51
- }
1
+ import { ObjectType } from '@nestjs/graphql';
2
+ import { Column, Entity, Index, OneToMany, TableInheritance } from 'typeorm';
3
+ import type { Relation } from 'typeorm';
4
+ import { OmniNamedEntity } from './omni-named.entity.js';
5
+ import { OmniRelationEntity } from './omni-relation.entity.js';
6
+ import { OmniRecordStatus } from '../omni-record-status.enum.js';
7
+
8
+ @Entity('omni-record')
9
+ @Index('omni_record_scope_kind_status_guid_idx', [
10
+ 'scopeId',
11
+ 'kind',
12
+ 'status',
13
+ 'guid',
14
+ ])
15
+ @TableInheritance({
16
+ column: {
17
+ name: 'recordType',
18
+ type: 'varchar',
19
+ length: 32,
20
+ },
21
+ })
22
+ @ObjectType({ isAbstract: true })
23
+ export class OmniRecordEntity extends OmniNamedEntity {
24
+ @Column({ type: 'varchar', length: 64 })
25
+ kind!: string;
26
+
27
+ @Column({
28
+ type: 'varchar',
29
+ default: OmniRecordStatus.Draft,
30
+ enum: Object.values(OmniRecordStatus),
31
+ length: 32,
32
+ })
33
+ status!: OmniRecordStatus;
34
+
35
+ @Column({ type: 'simple-json', nullable: true })
36
+ payload?: Record<string, unknown> | null;
37
+
38
+ /** Logical schema identity for JSON payload compatibility and migration. */
39
+ @Column({ type: 'varchar', nullable: true, length: 128 })
40
+ payloadSchemaId?: string | null;
41
+
42
+ /** Revision of payloadSchemaId; a schema change is explicit metadata. */
43
+ @Column({ type: 'integer', nullable: true })
44
+ payloadSchemaVersion?: number | null;
45
+
46
+ @OneToMany(() => OmniRelationEntity, (relation) => relation.sourceRecord)
47
+ outgoingRelations?: Relation<OmniRelationEntity[]>;
48
+
49
+ @OneToMany(() => OmniRelationEntity, (relation) => relation.targetRecord)
50
+ incomingRelations?: Relation<OmniRelationEntity[]>;
51
+ }