@nest-yalc-2/omnikernel-module 1.1.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.
Files changed (230) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +193 -0
  3. package/package.json +52 -0
  4. package/src/__tests__/omni-collection.entity.spec.ts +49 -0
  5. package/src/__tests__/omni-collection.service.spec.ts +83 -0
  6. package/src/__tests__/omni-document.entity.spec.ts +55 -0
  7. package/src/__tests__/omni-document.service.spec.ts +83 -0
  8. package/src/__tests__/omni-extension-projection-constraints.spec.ts +518 -0
  9. package/src/__tests__/omni-extension-projection.registration.spec.ts +946 -0
  10. package/src/__tests__/omni-extension-projection.service.spec.ts +806 -0
  11. package/src/__tests__/omni-external-ref.entity.spec.ts +36 -0
  12. package/src/__tests__/omni-external-ref.service.spec.ts +252 -0
  13. package/src/__tests__/omni-named.entity.spec.ts +33 -0
  14. package/src/__tests__/omni-record.entity.spec.ts +32 -0
  15. package/src/__tests__/omni-record.service.spec.ts +107 -0
  16. package/src/__tests__/omni-relation-semantics.spec.ts +102 -0
  17. package/src/__tests__/omni-relation.entity.spec.ts +38 -0
  18. package/src/__tests__/omni-scope-substrate.spec.ts +81 -0
  19. package/src/__tests__/omni-scoped.backend.spec.ts +115 -0
  20. package/src/__tests__/omni-scoped.service.spec.ts +354 -0
  21. package/src/__tests__/omnikernel.diagnostics.spec.ts +94 -0
  22. package/src/__tests__/omnikernel.module.spec.ts +40 -0
  23. package/src/__tests__/omnikernel.persistence.spec.ts +154 -0
  24. package/src/__tests__/omnikernel.public-api.spec.ts +238 -0
  25. package/src/__tests__/omnikernel.query.service.spec.ts +155 -0
  26. package/src/__tests__/tsconfig.json +6 -0
  27. package/src/base/omni-base.entity.d.ts +9 -0
  28. package/src/base/omni-base.entity.js +53 -0
  29. package/src/base/omni-base.entity.js.map +1 -0
  30. package/src/base/omni-base.entity.ts +41 -0
  31. package/src/base/omni-external-ref.entity.d.ts +13 -0
  32. package/src/base/omni-external-ref.entity.js +72 -0
  33. package/src/base/omni-external-ref.entity.js.map +1 -0
  34. package/src/base/omni-external-ref.entity.ts +53 -0
  35. package/src/base/omni-named.entity.d.ts +6 -0
  36. package/src/base/omni-named.entity.js +35 -0
  37. package/src/base/omni-named.entity.js.map +1 -0
  38. package/src/base/omni-named.entity.ts +16 -0
  39. package/src/base/omni-record.entity.d.ts +13 -0
  40. package/src/base/omni-record.entity.js +71 -0
  41. package/src/base/omni-record.entity.js.map +1 -0
  42. package/src/base/omni-record.entity.ts +51 -0
  43. package/src/base/omni-relation.entity.d.ts +15 -0
  44. package/src/base/omni-relation.entity.js +91 -0
  45. package/src/base/omni-relation.entity.js.map +1 -0
  46. package/src/base/omni-relation.entity.ts +72 -0
  47. package/src/index.d.ts +49 -0
  48. package/src/index.js +66 -0
  49. package/src/index.js.map +1 -0
  50. package/src/index.ts +49 -0
  51. package/src/omni-collection-kind.enum.d.ts +4 -0
  52. package/src/omni-collection-kind.enum.js +13 -0
  53. package/src/omni-collection-kind.enum.js.map +1 -0
  54. package/src/omni-collection-kind.enum.ts +10 -0
  55. package/src/omni-collection.backend.d.ts +2 -0
  56. package/src/omni-collection.backend.js +15 -0
  57. package/src/omni-collection.backend.js.map +1 -0
  58. package/src/omni-collection.backend.ts +16 -0
  59. package/src/omni-collection.dto.d.ts +32 -0
  60. package/src/omni-collection.dto.js +184 -0
  61. package/src/omni-collection.dto.js.map +1 -0
  62. package/src/omni-collection.dto.ts +170 -0
  63. package/src/omni-collection.entity.d.ts +7 -0
  64. package/src/omni-collection.entity.js +41 -0
  65. package/src/omni-collection.entity.js.map +1 -0
  66. package/src/omni-collection.entity.ts +21 -0
  67. package/src/omni-collection.service.d.ts +14 -0
  68. package/src/omni-collection.service.js +24 -0
  69. package/src/omni-collection.service.js.map +1 -0
  70. package/src/omni-collection.service.ts +75 -0
  71. package/src/omni-document-kind.enum.d.ts +6 -0
  72. package/src/omni-document-kind.enum.js +15 -0
  73. package/src/omni-document-kind.enum.js.map +1 -0
  74. package/src/omni-document-kind.enum.ts +12 -0
  75. package/src/omni-document.backend.d.ts +2 -0
  76. package/src/omni-document.backend.js +15 -0
  77. package/src/omni-document.backend.js.map +1 -0
  78. package/src/omni-document.backend.ts +16 -0
  79. package/src/omni-document.dto.d.ts +35 -0
  80. package/src/omni-document.dto.js +213 -0
  81. package/src/omni-document.dto.js.map +1 -0
  82. package/src/omni-document.dto.ts +198 -0
  83. package/src/omni-document.entity.d.ts +10 -0
  84. package/src/omni-document.entity.js +53 -0
  85. package/src/omni-document.entity.js.map +1 -0
  86. package/src/omni-document.entity.ts +30 -0
  87. package/src/omni-document.service.d.ts +14 -0
  88. package/src/omni-document.service.js +24 -0
  89. package/src/omni-document.service.js.map +1 -0
  90. package/src/omni-document.service.ts +75 -0
  91. package/src/omni-dto.helpers.d.ts +1 -0
  92. package/src/omni-dto.helpers.js +10 -0
  93. package/src/omni-dto.helpers.js.map +1 -0
  94. package/src/omni-dto.helpers.ts +21 -0
  95. package/src/omni-extension-projection.definition.d.ts +17 -0
  96. package/src/omni-extension-projection.definition.js +160 -0
  97. package/src/omni-extension-projection.definition.js.map +1 -0
  98. package/src/omni-extension-projection.definition.ts +294 -0
  99. package/src/omni-extension-projection.resource.d.ts +42 -0
  100. package/src/omni-extension-projection.resource.js +127 -0
  101. package/src/omni-extension-projection.resource.js.map +1 -0
  102. package/src/omni-extension-projection.resource.ts +274 -0
  103. package/src/omni-extension-projection.service.d.ts +33 -0
  104. package/src/omni-extension-projection.service.js +332 -0
  105. package/src/omni-extension-projection.service.js.map +1 -0
  106. package/src/omni-extension-projection.service.ts +452 -0
  107. package/src/omni-external-ref-binding.validator.d.ts +14 -0
  108. package/src/omni-external-ref-binding.validator.js +34 -0
  109. package/src/omni-external-ref-binding.validator.js.map +1 -0
  110. package/src/omni-external-ref-binding.validator.ts +53 -0
  111. package/src/omni-external-ref-internal-type.enum.d.ts +5 -0
  112. package/src/omni-external-ref-internal-type.enum.js +14 -0
  113. package/src/omni-external-ref-internal-type.enum.js.map +1 -0
  114. package/src/omni-external-ref-internal-type.enum.ts +11 -0
  115. package/src/omni-external-ref.backend.d.ts +2 -0
  116. package/src/omni-external-ref.backend.js +19 -0
  117. package/src/omni-external-ref.backend.js.map +1 -0
  118. package/src/omni-external-ref.backend.ts +25 -0
  119. package/src/omni-external-ref.dto.d.ts +26 -0
  120. package/src/omni-external-ref.dto.js +140 -0
  121. package/src/omni-external-ref.dto.js.map +1 -0
  122. package/src/omni-external-ref.dto.ts +128 -0
  123. package/src/omni-external-ref.service.d.ts +33 -0
  124. package/src/omni-external-ref.service.js +133 -0
  125. package/src/omni-external-ref.service.js.map +1 -0
  126. package/src/omni-external-ref.service.ts +255 -0
  127. package/src/omni-migration.d.ts +28 -0
  128. package/src/omni-migration.js +239 -0
  129. package/src/omni-migration.js.map +1 -0
  130. package/src/omni-migration.ts +365 -0
  131. package/src/omni-named.backend.d.ts +2 -0
  132. package/src/omni-named.backend.js +13 -0
  133. package/src/omni-named.backend.js.map +1 -0
  134. package/src/omni-named.backend.ts +11 -0
  135. package/src/omni-named.dto.d.ts +19 -0
  136. package/src/omni-named.dto.js +94 -0
  137. package/src/omni-named.dto.js.map +1 -0
  138. package/src/omni-named.dto.ts +86 -0
  139. package/src/omni-projection.catalog.d.ts +49 -0
  140. package/src/omni-projection.catalog.js +177 -0
  141. package/src/omni-projection.catalog.js.map +1 -0
  142. package/src/omni-projection.catalog.ts +345 -0
  143. package/src/omni-projection.lifecycle.d.ts +20 -0
  144. package/src/omni-projection.lifecycle.js +3 -0
  145. package/src/omni-projection.lifecycle.js.map +1 -0
  146. package/src/omni-projection.lifecycle.ts +53 -0
  147. package/src/omni-record-status.enum.d.ts +5 -0
  148. package/src/omni-record-status.enum.js +14 -0
  149. package/src/omni-record-status.enum.js.map +1 -0
  150. package/src/omni-record-status.enum.ts +11 -0
  151. package/src/omni-record.backend.d.ts +2 -0
  152. package/src/omni-record.backend.js +13 -0
  153. package/src/omni-record.backend.js.map +1 -0
  154. package/src/omni-record.backend.ts +19 -0
  155. package/src/omni-record.dto.d.ts +29 -0
  156. package/src/omni-record.dto.js +169 -0
  157. package/src/omni-record.dto.js.map +1 -0
  158. package/src/omni-record.dto.ts +157 -0
  159. package/src/omni-record.service.d.ts +18 -0
  160. package/src/omni-record.service.js +45 -0
  161. package/src/omni-record.service.js.map +1 -0
  162. package/src/omni-record.service.ts +113 -0
  163. package/src/omni-relation-kind.contract.d.ts +9 -0
  164. package/src/omni-relation-kind.contract.js +33 -0
  165. package/src/omni-relation-kind.contract.js.map +1 -0
  166. package/src/omni-relation-kind.contract.ts +49 -0
  167. package/src/omni-relation-kind.enum.d.ts +6 -0
  168. package/src/omni-relation-kind.enum.js +15 -0
  169. package/src/omni-relation-kind.enum.js.map +1 -0
  170. package/src/omni-relation-kind.enum.ts +12 -0
  171. package/src/omni-relation-projection.definition.d.ts +25 -0
  172. package/src/omni-relation-projection.definition.js +83 -0
  173. package/src/omni-relation-projection.definition.js.map +1 -0
  174. package/src/omni-relation-projection.definition.ts +166 -0
  175. package/src/omni-relation-projection.resource.d.ts +51 -0
  176. package/src/omni-relation-projection.resource.js +203 -0
  177. package/src/omni-relation-projection.resource.js.map +1 -0
  178. package/src/omni-relation-projection.resource.ts +360 -0
  179. package/src/omni-relation-projection.service.d.ts +47 -0
  180. package/src/omni-relation-projection.service.js +385 -0
  181. package/src/omni-relation-projection.service.js.map +1 -0
  182. package/src/omni-relation-projection.service.ts +610 -0
  183. package/src/omni-relation-semantics.d.ts +11 -0
  184. package/src/omni-relation-semantics.js +34 -0
  185. package/src/omni-relation-semantics.js.map +1 -0
  186. package/src/omni-relation-semantics.ts +52 -0
  187. package/src/omni-relation-status.enum.d.ts +5 -0
  188. package/src/omni-relation-status.enum.js +14 -0
  189. package/src/omni-relation-status.enum.js.map +1 -0
  190. package/src/omni-relation-status.enum.ts +11 -0
  191. package/src/omni-relation.backend.d.ts +2 -0
  192. package/src/omni-relation.backend.js +17 -0
  193. package/src/omni-relation.backend.js.map +1 -0
  194. package/src/omni-relation.backend.ts +21 -0
  195. package/src/omni-relation.dto.d.ts +28 -0
  196. package/src/omni-relation.dto.js +153 -0
  197. package/src/omni-relation.dto.js.map +1 -0
  198. package/src/omni-relation.dto.ts +142 -0
  199. package/src/omni-relation.service.d.ts +19 -0
  200. package/src/omni-relation.service.js +76 -0
  201. package/src/omni-relation.service.js.map +1 -0
  202. package/src/omni-relation.service.ts +159 -0
  203. package/src/omni-scope.d.ts +33 -0
  204. package/src/omni-scope.js +91 -0
  205. package/src/omni-scope.js.map +1 -0
  206. package/src/omni-scope.ts +161 -0
  207. package/src/omni-scoped.backend.d.ts +21 -0
  208. package/src/omni-scoped.backend.js +47 -0
  209. package/src/omni-scoped.backend.js.map +1 -0
  210. package/src/omni-scoped.backend.ts +110 -0
  211. package/src/omni-scoped.repository.d.ts +10 -0
  212. package/src/omni-scoped.repository.js +26 -0
  213. package/src/omni-scoped.repository.js.map +1 -0
  214. package/src/omni-scoped.repository.ts +34 -0
  215. package/src/omni-scoped.service.d.ts +36 -0
  216. package/src/omni-scoped.service.js +171 -0
  217. package/src/omni-scoped.service.js.map +1 -0
  218. package/src/omni-scoped.service.ts +338 -0
  219. package/src/omnikernel.diagnostics.d.ts +16 -0
  220. package/src/omnikernel.diagnostics.js +50 -0
  221. package/src/omnikernel.diagnostics.js.map +1 -0
  222. package/src/omnikernel.diagnostics.ts +83 -0
  223. package/src/omnikernel.module.d.ts +5 -0
  224. package/src/omnikernel.module.js +87 -0
  225. package/src/omnikernel.module.js.map +1 -0
  226. package/src/omnikernel.module.ts +97 -0
  227. package/src/omnikernel.query.service.d.ts +17 -0
  228. package/src/omnikernel.query.service.js +85 -0
  229. package/src/omnikernel.query.service.js.map +1 -0
  230. package/src/omnikernel.query.service.ts +108 -0
@@ -0,0 +1,154 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from '@jest/globals';
2
+ import { DataSource } from 'typeorm';
3
+
4
+ import { OmniNamedEntity } from '../base/omni-named.entity.js';
5
+ import { OmniRecordEntity } from '../base/omni-record.entity.js';
6
+ import { OmniRelationEntity } from '../base/omni-relation.entity.js';
7
+ import { OmniCollectionEntity } from '../omni-collection.entity.js';
8
+ import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
9
+ import { OmniDocumentEntity } from '../omni-document.entity.js';
10
+ import { OmniDocumentKind } from '../omni-document-kind.enum.js';
11
+ import { OmniRecordStatus } from '../omni-record-status.enum.js';
12
+ import { OmniRelationKind } from '../omni-relation-kind.enum.js';
13
+ import { OmniRelationStatus } from '../omni-relation-status.enum.js';
14
+
15
+ describe('OmniKernel persistence', () => {
16
+ let dataSource: DataSource;
17
+
18
+ beforeEach(async () => {
19
+ dataSource = new DataSource({
20
+ type: 'sqlite',
21
+ database: ':memory:',
22
+ dropSchema: true,
23
+ synchronize: true,
24
+ entities: [
25
+ OmniNamedEntity,
26
+ OmniRecordEntity,
27
+ OmniCollectionEntity,
28
+ OmniDocumentEntity,
29
+ OmniRelationEntity,
30
+ ],
31
+ });
32
+
33
+ await dataSource.initialize();
34
+ });
35
+
36
+ afterEach(async () => {
37
+ if (dataSource.isInitialized) {
38
+ await dataSource.destroy();
39
+ }
40
+ });
41
+
42
+ it('stores collections and documents in omni-record and resolves graph links back through the shared record hierarchy', async () => {
43
+ const recordRepo = dataSource.getRepository(OmniRecordEntity);
44
+ const collectionRepo = dataSource.getRepository(OmniCollectionEntity);
45
+ const documentRepo = dataSource.getRepository(OmniDocumentEntity);
46
+ const relationRepo = dataSource.getRepository(OmniRelationEntity);
47
+
48
+ await recordRepo.insert(
49
+ recordRepo.create({
50
+ guid: '11111111-1111-1111-1111-111111111111',
51
+ title: 'Task record',
52
+ kind: 'task',
53
+ status: OmniRecordStatus.Draft,
54
+ }),
55
+ );
56
+ await documentRepo.insert(
57
+ documentRepo.create({
58
+ guid: '22222222-2222-2222-2222-222222222222',
59
+ title: 'Document record',
60
+ status: OmniRecordStatus.Draft,
61
+ documentKind: OmniDocumentKind.Note,
62
+ }),
63
+ );
64
+ await collectionRepo.insert(
65
+ collectionRepo.create({
66
+ guid: '44444444-4444-4444-4444-444444444444',
67
+ title: 'Knowledge base',
68
+ status: OmniRecordStatus.Active,
69
+ collectionKind: OmniCollectionKind.Folder,
70
+ summary: 'Primary document container',
71
+ }),
72
+ );
73
+ await relationRepo.insert(
74
+ relationRepo.create({
75
+ guid: '33333333-3333-3333-3333-333333333333',
76
+ sourceRecordId: '11111111-1111-1111-1111-111111111111',
77
+ targetRecordId: '22222222-2222-2222-2222-222222222222',
78
+ kind: OmniRelationKind.References,
79
+ status: OmniRelationStatus.Active,
80
+ }),
81
+ );
82
+ await relationRepo.insert(
83
+ relationRepo.create({
84
+ guid: '55555555-5555-5555-5555-555555555555',
85
+ sourceRecordId: '44444444-4444-4444-4444-444444444444',
86
+ targetRecordId: '22222222-2222-2222-2222-222222222222',
87
+ kind: OmniRelationKind.Contains,
88
+ status: OmniRelationStatus.Active,
89
+ }),
90
+ );
91
+
92
+ const rows = await dataSource.query(
93
+ 'select guid, kind, recordType, collectionKind, documentKind from "omni-record" order by guid',
94
+ );
95
+
96
+ expect(rows).toEqual(
97
+ expect.arrayContaining([
98
+ expect.objectContaining({
99
+ guid: '11111111-1111-1111-1111-111111111111',
100
+ kind: 'task',
101
+ }),
102
+ expect.objectContaining({
103
+ guid: '22222222-2222-2222-2222-222222222222',
104
+ kind: OmniDocumentKind.Document,
105
+ recordType: OmniDocumentKind.Document,
106
+ documentKind: OmniDocumentKind.Note,
107
+ }),
108
+ expect.objectContaining({
109
+ guid: '44444444-4444-4444-4444-444444444444',
110
+ kind: OmniCollectionKind.Collection,
111
+ recordType: OmniCollectionKind.Collection,
112
+ collectionKind: OmniCollectionKind.Folder,
113
+ }),
114
+ ]),
115
+ );
116
+
117
+ const relation = await relationRepo.findOneOrFail({
118
+ where: { guid: '33333333-3333-3333-3333-333333333333' },
119
+ relations: {
120
+ sourceRecord: true,
121
+ targetRecord: true,
122
+ },
123
+ });
124
+
125
+ expect(relation.sourceRecord.guid).toBe(
126
+ '11111111-1111-1111-1111-111111111111',
127
+ );
128
+ expect(relation.targetRecord).toBeInstanceOf(OmniDocumentEntity);
129
+ expect(relation.targetRecord.guid).toBe(
130
+ '22222222-2222-2222-2222-222222222222',
131
+ );
132
+ expect((relation.targetRecord as OmniDocumentEntity).kind).toBe(
133
+ OmniDocumentKind.Document,
134
+ );
135
+
136
+ const membershipRelation = await relationRepo.findOneOrFail({
137
+ where: { guid: '55555555-5555-5555-5555-555555555555' },
138
+ relations: {
139
+ sourceRecord: true,
140
+ targetRecord: true,
141
+ },
142
+ });
143
+
144
+ expect(membershipRelation.sourceRecord).toBeInstanceOf(OmniCollectionEntity);
145
+ expect(membershipRelation.sourceRecord.guid).toBe(
146
+ '44444444-4444-4444-4444-444444444444',
147
+ );
148
+ expect((membershipRelation.sourceRecord as OmniCollectionEntity).kind).toBe(
149
+ OmniCollectionKind.Collection,
150
+ );
151
+ expect(membershipRelation.targetRecord).toBeInstanceOf(OmniDocumentEntity);
152
+ expect(membershipRelation.kind).toBe(OmniRelationKind.Contains);
153
+ });
154
+ });
@@ -0,0 +1,238 @@
1
+ import { describe, expect, it } from '@jest/globals';
2
+ import 'reflect-metadata';
3
+ import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
4
+ import { OmniDocumentKind } from '../omni-document-kind.enum.js';
5
+ import { OmniRecordStatus } from '../omni-record-status.enum.js';
6
+ import { OmniRelationKind } from '../omni-relation-kind.enum.js';
7
+ import { OmniRelationStatus } from '../omni-relation-status.enum.js';
8
+
9
+ import * as namedDto from '../omni-named.dto.js';
10
+ import * as recordDto from '../omni-record.dto.js';
11
+ import * as collectionDto from '../omni-collection.dto.js';
12
+ import * as relationDto from '../omni-relation.dto.js';
13
+ import * as externalRefDto from '../omni-external-ref.dto.js';
14
+ import * as documentDto from '../omni-document.dto.js';
15
+ import { OmniCollectionEntity } from '../omni-collection.entity.js';
16
+ import { OmniCollectionService } from '../omni-collection.service.js';
17
+ import { OmniDocumentEntity } from '../omni-document.entity.js';
18
+ import { OmniDocumentService } from '../omni-document.service.js';
19
+ import { OmniExternalRefInternalType } from '../omni-external-ref-internal-type.enum.js';
20
+ import { OmniExternalRefService } from '../omni-external-ref.service.js';
21
+ import * as relationSemantics from '../omni-relation-semantics.js';
22
+ import { OmniKernelQueryService } from '../omnikernel.query.service.js';
23
+ import { omniCollectionBackendProvidersFactory } from '../omni-collection.backend.js';
24
+ import { omniNamedBackendProvidersFactory } from '../omni-named.backend.js';
25
+ import { omniRecordBackendProvidersFactory } from '../omni-record.backend.js';
26
+ import { omniRelationBackendProvidersFactory } from '../omni-relation.backend.js';
27
+ import { omniExternalRefBackendProvidersFactory } from '../omni-external-ref.backend.js';
28
+ import { omniDocumentBackendProvidersFactory } from '../omni-document.backend.js';
29
+ import * as omnikernelPublicApi from '../index.js';
30
+
31
+ describe('OmniKernel public API', () => {
32
+ it('copies data through DTO constructors', () => {
33
+ const named = new namedDto.OmniNamedType({
34
+ guid: '6c1bfae7-b56c-4537-a5c7-98c84ce2d23a',
35
+ title: 'Named',
36
+ slug: 'named',
37
+ });
38
+ const record = new recordDto.OmniRecordType({
39
+ guid: 'b7df87c7-b8b8-43a3-99c0-811024a48b39',
40
+ title: 'Record',
41
+ kind: 'generic',
42
+ status: OmniRecordStatus.Active,
43
+ payload: { ok: true },
44
+ });
45
+ const collection = new collectionDto.OmniCollectionType({
46
+ guid: '0f7f6978-66f2-4d96-a7f3-a0ecf399f2e2',
47
+ title: 'Collection',
48
+ kind: OmniCollectionKind.Collection,
49
+ status: OmniRecordStatus.Active,
50
+ collectionKind: OmniCollectionKind.Folder,
51
+ summary: 'Container',
52
+ });
53
+ const relation = new relationDto.OmniRelationType({
54
+ guid: '5bba1944-1a52-4918-ba54-453e09d3d9b3',
55
+ sourceRecordId: 'b7df87c7-b8b8-43a3-99c0-811024a48b39',
56
+ targetRecordId: '6c1bfae7-b56c-4537-a5c7-98c84ce2d23a',
57
+ kind: OmniRelationKind.Contains,
58
+ status: OmniRelationStatus.Active,
59
+ });
60
+ const externalRef = new externalRefDto.OmniExternalRefType({
61
+ guid: '47eaf320-9fbe-4f2e-9a0a-c2c4cbdb2d9e',
62
+ internalType: OmniExternalRefInternalType.Document,
63
+ internalId: 'b7df87c7-b8b8-43a3-99c0-811024a48b39',
64
+ provider: 'github',
65
+ externalId: '123',
66
+ });
67
+ const document = new documentDto.OmniDocumentType({
68
+ guid: 'ebf2fd92-9271-4cb7-b5a8-a7ce0105dff5',
69
+ title: 'Document',
70
+ kind: OmniDocumentKind.Document,
71
+ status: OmniRecordStatus.Active,
72
+ documentKind: OmniDocumentKind.Document,
73
+ content: 'Body',
74
+ });
75
+
76
+ expect(named.title).toBe('Named');
77
+ expect(record.payload).toEqual({ ok: true });
78
+ expect(collection.collectionKind).toBe(OmniCollectionKind.Folder);
79
+ expect(relation.kind).toBe(OmniRelationKind.Contains);
80
+ expect(externalRef.provider).toBe('github');
81
+ expect(document.documentKind).toBe(OmniDocumentKind.Document);
82
+ });
83
+
84
+ it('exposes generated GraphQL input types', () => {
85
+ expect(new namedDto.OmniNamedCreateInput()).toBeInstanceOf(
86
+ namedDto.OmniNamedCreateInput,
87
+ );
88
+ expect(new namedDto.OmniNamedCondition()).toBeInstanceOf(
89
+ namedDto.OmniNamedCondition,
90
+ );
91
+ expect(new namedDto.OmniNamedUpdateInput()).toBeInstanceOf(
92
+ namedDto.OmniNamedUpdateInput,
93
+ );
94
+
95
+ expect(new recordDto.OmniRecordCreateInput()).toBeInstanceOf(
96
+ recordDto.OmniRecordCreateInput,
97
+ );
98
+ expect(new recordDto.OmniRecordCondition()).toBeInstanceOf(
99
+ recordDto.OmniRecordCondition,
100
+ );
101
+ expect(new recordDto.OmniRecordUpdateInput()).toBeInstanceOf(
102
+ recordDto.OmniRecordUpdateInput,
103
+ );
104
+
105
+ expect(new collectionDto.OmniCollectionCreateInput()).toBeInstanceOf(
106
+ collectionDto.OmniCollectionCreateInput,
107
+ );
108
+ expect(new collectionDto.OmniCollectionCondition()).toBeInstanceOf(
109
+ collectionDto.OmniCollectionCondition,
110
+ );
111
+ expect(new collectionDto.OmniCollectionUpdateInput()).toBeInstanceOf(
112
+ collectionDto.OmniCollectionUpdateInput,
113
+ );
114
+
115
+ expect(new relationDto.OmniRelationCreateInput()).toBeInstanceOf(
116
+ relationDto.OmniRelationCreateInput,
117
+ );
118
+ expect(new relationDto.OmniRelationCondition()).toBeInstanceOf(
119
+ relationDto.OmniRelationCondition,
120
+ );
121
+ expect(new relationDto.OmniRelationUpdateInput()).toBeInstanceOf(
122
+ relationDto.OmniRelationUpdateInput,
123
+ );
124
+
125
+ expect(new externalRefDto.OmniExternalRefCreateInput()).toBeInstanceOf(
126
+ externalRefDto.OmniExternalRefCreateInput,
127
+ );
128
+ expect(new externalRefDto.OmniExternalRefCondition()).toBeInstanceOf(
129
+ externalRefDto.OmniExternalRefCondition,
130
+ );
131
+ expect(new externalRefDto.OmniExternalRefUpdateInput()).toBeInstanceOf(
132
+ externalRefDto.OmniExternalRefUpdateInput,
133
+ );
134
+
135
+ expect(new documentDto.OmniDocumentCreateInput()).toBeInstanceOf(
136
+ documentDto.OmniDocumentCreateInput,
137
+ );
138
+ expect(new documentDto.OmniDocumentCondition()).toBeInstanceOf(
139
+ documentDto.OmniDocumentCondition,
140
+ );
141
+ expect(new documentDto.OmniDocumentUpdateInput()).toBeInstanceOf(
142
+ documentDto.OmniDocumentUpdateInput,
143
+ );
144
+ });
145
+
146
+ it('builds backend provider configs for every public backend factory', () => {
147
+ const named = omniNamedBackendProvidersFactory('db');
148
+ const record = omniRecordBackendProvidersFactory('db');
149
+ const collection = omniCollectionBackendProvidersFactory('db');
150
+ const relation = omniRelationBackendProvidersFactory('db');
151
+ const externalRef = omniExternalRefBackendProvidersFactory('db');
152
+ const document = omniDocumentBackendProvidersFactory('db');
153
+
154
+ expect(named.repository).toBeDefined();
155
+ expect(record.repository).toBeDefined();
156
+ expect(collection.repository).toBeDefined();
157
+ expect(relation.repository).toBeDefined();
158
+ expect(externalRef.repository).toBeDefined();
159
+ expect(document.repository).toBeDefined();
160
+ expect(record.providers.length).toBeGreaterThan(0);
161
+ expect(collection.providers.length).toBeGreaterThan(0);
162
+ expect(document.providers.length).toBeGreaterThan(0);
163
+ expect(
164
+ collection.providers.some(
165
+ (provider) =>
166
+ typeof provider === 'object' &&
167
+ provider !== null &&
168
+ 'provide' in provider &&
169
+ provider.provide === OmniCollectionService,
170
+ ),
171
+ ).toBe(true);
172
+ expect(
173
+ document.providers.some(
174
+ (provider) =>
175
+ typeof provider === 'object' &&
176
+ provider !== null &&
177
+ 'provide' in provider &&
178
+ provider.provide === OmniDocumentService,
179
+ ),
180
+ ).toBe(true);
181
+ expect(
182
+ externalRef.providers.some(
183
+ (provider) =>
184
+ typeof provider === 'object' &&
185
+ provider !== null &&
186
+ 'provide' in provider &&
187
+ provider.provide === OmniExternalRefService,
188
+ ),
189
+ ).toBe(true);
190
+ expect(OmniCollectionEntity).toBe(omnikernelPublicApi.OmniCollectionEntity);
191
+ expect(OmniDocumentEntity).toBe(omnikernelPublicApi.OmniDocumentEntity);
192
+ });
193
+
194
+ it('re-exports the documented OmniKernel surface from index.ts', () => {
195
+ expect(omnikernelPublicApi.OmniKernelModule).toBeDefined();
196
+ expect(omnikernelPublicApi.OmniNamedType).toBe(namedDto.OmniNamedType);
197
+ expect(omnikernelPublicApi.OmniRecordType).toBe(recordDto.OmniRecordType);
198
+ expect(omnikernelPublicApi.OmniCollectionType).toBe(
199
+ collectionDto.OmniCollectionType,
200
+ );
201
+ expect(omnikernelPublicApi.OmniRelationType).toBe(
202
+ relationDto.OmniRelationType,
203
+ );
204
+ expect(omnikernelPublicApi.OmniExternalRefType).toBe(
205
+ externalRefDto.OmniExternalRefType,
206
+ );
207
+ expect(omnikernelPublicApi.OmniDocumentType).toBe(
208
+ documentDto.OmniDocumentType,
209
+ );
210
+ expect(omnikernelPublicApi.omniDocumentBackendProvidersFactory).toBe(
211
+ omniDocumentBackendProvidersFactory,
212
+ );
213
+ expect(omnikernelPublicApi.omniCollectionBackendProvidersFactory).toBe(
214
+ omniCollectionBackendProvidersFactory,
215
+ );
216
+ expect(omnikernelPublicApi.omniNamedBackendProvidersFactory).toBe(
217
+ omniNamedBackendProvidersFactory,
218
+ );
219
+ expect(omnikernelPublicApi.omniRecordBackendProvidersFactory).toBe(
220
+ omniRecordBackendProvidersFactory,
221
+ );
222
+ expect(omnikernelPublicApi.omniRelationBackendProvidersFactory).toBe(
223
+ omniRelationBackendProvidersFactory,
224
+ );
225
+ expect(omnikernelPublicApi.omniExternalRefBackendProvidersFactory).toBe(
226
+ omniExternalRefBackendProvidersFactory,
227
+ );
228
+ expect(omnikernelPublicApi.isAllowedOmniRelation).toBe(
229
+ relationSemantics.isAllowedOmniRelation,
230
+ );
231
+ expect(omnikernelPublicApi.OmniExternalRefInternalType).toBe(
232
+ OmniExternalRefInternalType,
233
+ );
234
+ expect(omnikernelPublicApi.OmniKernelQueryService).toBe(
235
+ OmniKernelQueryService,
236
+ );
237
+ });
238
+ });
@@ -0,0 +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
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../../../../tsconfig.test.json",
3
+ "compilerOptions": {
4
+ "rootDir": "../../../../../"
5
+ }
6
+ }
@@ -0,0 +1,9 @@
1
+ import { BaseEntity } from 'typeorm';
2
+ export declare abstract class OmniBaseEntity extends BaseEntity {
3
+ scopeId: string;
4
+ guid: string;
5
+ revision: number;
6
+ deletedAt?: Date | null;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OmniBaseEntity = void 0;
13
+ const graphql_1 = require("@nestjs/graphql");
14
+ const typeorm_1 = require("typeorm");
15
+ let OmniBaseEntity = class OmniBaseEntity extends typeorm_1.BaseEntity {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.scopeId = 'default';
19
+ }
20
+ };
21
+ exports.OmniBaseEntity = OmniBaseEntity;
22
+ __decorate([
23
+ (0, typeorm_1.PrimaryColumn)('varchar', {
24
+ name: 'scopeId',
25
+ length: 64,
26
+ default: 'default',
27
+ }),
28
+ __metadata("design:type", String)
29
+ ], OmniBaseEntity.prototype, "scopeId", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.PrimaryColumn)('varchar', { name: 'guid', length: 36 }),
32
+ __metadata("design:type", String)
33
+ ], OmniBaseEntity.prototype, "guid", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.VersionColumn)({ type: 'integer', default: 1 }),
36
+ __metadata("design:type", Number)
37
+ ], OmniBaseEntity.prototype, "revision", void 0);
38
+ __decorate([
39
+ (0, typeorm_1.DeleteDateColumn)({ nullable: true }),
40
+ __metadata("design:type", Object)
41
+ ], OmniBaseEntity.prototype, "deletedAt", void 0);
42
+ __decorate([
43
+ (0, typeorm_1.CreateDateColumn)(),
44
+ __metadata("design:type", Date)
45
+ ], OmniBaseEntity.prototype, "createdAt", void 0);
46
+ __decorate([
47
+ (0, typeorm_1.UpdateDateColumn)(),
48
+ __metadata("design:type", Date)
49
+ ], OmniBaseEntity.prototype, "updatedAt", void 0);
50
+ exports.OmniBaseEntity = OmniBaseEntity = __decorate([
51
+ (0, graphql_1.ObjectType)({ isAbstract: true })
52
+ ], OmniBaseEntity);
53
+ //# sourceMappingURL=omni-base.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omni-base.entity.js","sourceRoot":"","sources":["omni-base.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA6C;AAC7C,qCAOiB;AAGV,IAAe,cAAc,GAA7B,MAAe,cAAe,SAAQ,oBAAU;IAAhD;;QAWL,YAAO,GAAW,SAAS,CAAC;IAkB9B,CAAC;CAAA,CAAA;AA7BqB,wCAAc;AAWlC;IALC,IAAA,uBAAa,EAAC,SAAS,EAAE;QACxB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,SAAS;KACnB,CAAC;;+CAC0B;AAG5B;IADC,IAAA,uBAAa,EAAC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;;4CACzC;AAId;IADC,IAAA,uBAAa,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;gDAC7B;AAIlB;IADC,IAAA,0BAAgB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;iDACb;AAGxB;IADC,IAAA,0BAAgB,GAAE;8BACP,IAAI;iDAAC;AAGjB;IADC,IAAA,0BAAgB,GAAE;8BACP,IAAI;iDAAC;yBA5BG,cAAc;IADnC,IAAA,oBAAU,EAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;GACX,cAAc,CA6BnC"}
@@ -0,0 +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
+ }
@@ -0,0 +1,13 @@
1
+ import { OmniBaseEntity } from './omni-base.entity.js';
2
+ import { OmniExternalRefInternalType } from '../omni-external-ref-internal-type.enum.js';
3
+ export declare class OmniExternalRefEntity extends OmniBaseEntity {
4
+ internalType: OmniExternalRefInternalType;
5
+ internalId: string;
6
+ provider: string;
7
+ account?: string | null;
8
+ container?: string | null;
9
+ externalId: string;
10
+ payload?: Record<string, unknown> | null;
11
+ payloadSchemaId?: string | null;
12
+ payloadSchemaVersion?: number | null;
13
+ }