@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.
- package/LICENSE +661 -0
- package/README.md +193 -0
- package/package.json +52 -0
- package/src/__tests__/omni-collection.entity.spec.ts +49 -0
- package/src/__tests__/omni-collection.service.spec.ts +83 -0
- package/src/__tests__/omni-document.entity.spec.ts +55 -0
- package/src/__tests__/omni-document.service.spec.ts +83 -0
- package/src/__tests__/omni-extension-projection-constraints.spec.ts +518 -0
- package/src/__tests__/omni-extension-projection.registration.spec.ts +946 -0
- package/src/__tests__/omni-extension-projection.service.spec.ts +806 -0
- package/src/__tests__/omni-external-ref.entity.spec.ts +36 -0
- package/src/__tests__/omni-external-ref.service.spec.ts +252 -0
- package/src/__tests__/omni-named.entity.spec.ts +33 -0
- package/src/__tests__/omni-record.entity.spec.ts +32 -0
- package/src/__tests__/omni-record.service.spec.ts +107 -0
- package/src/__tests__/omni-relation-semantics.spec.ts +102 -0
- package/src/__tests__/omni-relation.entity.spec.ts +38 -0
- package/src/__tests__/omni-scope-substrate.spec.ts +81 -0
- package/src/__tests__/omni-scoped.backend.spec.ts +115 -0
- package/src/__tests__/omni-scoped.service.spec.ts +354 -0
- package/src/__tests__/omnikernel.diagnostics.spec.ts +94 -0
- package/src/__tests__/omnikernel.module.spec.ts +40 -0
- package/src/__tests__/omnikernel.persistence.spec.ts +154 -0
- package/src/__tests__/omnikernel.public-api.spec.ts +238 -0
- package/src/__tests__/omnikernel.query.service.spec.ts +155 -0
- package/src/__tests__/tsconfig.json +6 -0
- package/src/base/omni-base.entity.d.ts +9 -0
- package/src/base/omni-base.entity.js +53 -0
- package/src/base/omni-base.entity.js.map +1 -0
- package/src/base/omni-base.entity.ts +41 -0
- package/src/base/omni-external-ref.entity.d.ts +13 -0
- package/src/base/omni-external-ref.entity.js +72 -0
- package/src/base/omni-external-ref.entity.js.map +1 -0
- package/src/base/omni-external-ref.entity.ts +53 -0
- package/src/base/omni-named.entity.d.ts +6 -0
- package/src/base/omni-named.entity.js +35 -0
- package/src/base/omni-named.entity.js.map +1 -0
- package/src/base/omni-named.entity.ts +16 -0
- package/src/base/omni-record.entity.d.ts +13 -0
- package/src/base/omni-record.entity.js +71 -0
- package/src/base/omni-record.entity.js.map +1 -0
- package/src/base/omni-record.entity.ts +51 -0
- package/src/base/omni-relation.entity.d.ts +15 -0
- package/src/base/omni-relation.entity.js +91 -0
- package/src/base/omni-relation.entity.js.map +1 -0
- package/src/base/omni-relation.entity.ts +72 -0
- package/src/index.d.ts +49 -0
- package/src/index.js +66 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +49 -0
- package/src/omni-collection-kind.enum.d.ts +4 -0
- package/src/omni-collection-kind.enum.js +13 -0
- package/src/omni-collection-kind.enum.js.map +1 -0
- package/src/omni-collection-kind.enum.ts +10 -0
- package/src/omni-collection.backend.d.ts +2 -0
- package/src/omni-collection.backend.js +15 -0
- package/src/omni-collection.backend.js.map +1 -0
- package/src/omni-collection.backend.ts +16 -0
- package/src/omni-collection.dto.d.ts +32 -0
- package/src/omni-collection.dto.js +184 -0
- package/src/omni-collection.dto.js.map +1 -0
- package/src/omni-collection.dto.ts +170 -0
- package/src/omni-collection.entity.d.ts +7 -0
- package/src/omni-collection.entity.js +41 -0
- package/src/omni-collection.entity.js.map +1 -0
- package/src/omni-collection.entity.ts +21 -0
- package/src/omni-collection.service.d.ts +14 -0
- package/src/omni-collection.service.js +24 -0
- package/src/omni-collection.service.js.map +1 -0
- package/src/omni-collection.service.ts +75 -0
- package/src/omni-document-kind.enum.d.ts +6 -0
- package/src/omni-document-kind.enum.js +15 -0
- package/src/omni-document-kind.enum.js.map +1 -0
- package/src/omni-document-kind.enum.ts +12 -0
- package/src/omni-document.backend.d.ts +2 -0
- package/src/omni-document.backend.js +15 -0
- package/src/omni-document.backend.js.map +1 -0
- package/src/omni-document.backend.ts +16 -0
- package/src/omni-document.dto.d.ts +35 -0
- package/src/omni-document.dto.js +213 -0
- package/src/omni-document.dto.js.map +1 -0
- package/src/omni-document.dto.ts +198 -0
- package/src/omni-document.entity.d.ts +10 -0
- package/src/omni-document.entity.js +53 -0
- package/src/omni-document.entity.js.map +1 -0
- package/src/omni-document.entity.ts +30 -0
- package/src/omni-document.service.d.ts +14 -0
- package/src/omni-document.service.js +24 -0
- package/src/omni-document.service.js.map +1 -0
- package/src/omni-document.service.ts +75 -0
- package/src/omni-dto.helpers.d.ts +1 -0
- package/src/omni-dto.helpers.js +10 -0
- package/src/omni-dto.helpers.js.map +1 -0
- package/src/omni-dto.helpers.ts +21 -0
- package/src/omni-extension-projection.definition.d.ts +17 -0
- package/src/omni-extension-projection.definition.js +160 -0
- package/src/omni-extension-projection.definition.js.map +1 -0
- package/src/omni-extension-projection.definition.ts +294 -0
- package/src/omni-extension-projection.resource.d.ts +42 -0
- package/src/omni-extension-projection.resource.js +127 -0
- package/src/omni-extension-projection.resource.js.map +1 -0
- package/src/omni-extension-projection.resource.ts +274 -0
- package/src/omni-extension-projection.service.d.ts +33 -0
- package/src/omni-extension-projection.service.js +332 -0
- package/src/omni-extension-projection.service.js.map +1 -0
- package/src/omni-extension-projection.service.ts +452 -0
- package/src/omni-external-ref-binding.validator.d.ts +14 -0
- package/src/omni-external-ref-binding.validator.js +34 -0
- package/src/omni-external-ref-binding.validator.js.map +1 -0
- package/src/omni-external-ref-binding.validator.ts +53 -0
- package/src/omni-external-ref-internal-type.enum.d.ts +5 -0
- package/src/omni-external-ref-internal-type.enum.js +14 -0
- package/src/omni-external-ref-internal-type.enum.js.map +1 -0
- package/src/omni-external-ref-internal-type.enum.ts +11 -0
- package/src/omni-external-ref.backend.d.ts +2 -0
- package/src/omni-external-ref.backend.js +19 -0
- package/src/omni-external-ref.backend.js.map +1 -0
- package/src/omni-external-ref.backend.ts +25 -0
- package/src/omni-external-ref.dto.d.ts +26 -0
- package/src/omni-external-ref.dto.js +140 -0
- package/src/omni-external-ref.dto.js.map +1 -0
- package/src/omni-external-ref.dto.ts +128 -0
- package/src/omni-external-ref.service.d.ts +33 -0
- package/src/omni-external-ref.service.js +133 -0
- package/src/omni-external-ref.service.js.map +1 -0
- package/src/omni-external-ref.service.ts +255 -0
- package/src/omni-migration.d.ts +28 -0
- package/src/omni-migration.js +239 -0
- package/src/omni-migration.js.map +1 -0
- package/src/omni-migration.ts +365 -0
- package/src/omni-named.backend.d.ts +2 -0
- package/src/omni-named.backend.js +13 -0
- package/src/omni-named.backend.js.map +1 -0
- package/src/omni-named.backend.ts +11 -0
- package/src/omni-named.dto.d.ts +19 -0
- package/src/omni-named.dto.js +94 -0
- package/src/omni-named.dto.js.map +1 -0
- package/src/omni-named.dto.ts +86 -0
- package/src/omni-projection.catalog.d.ts +49 -0
- package/src/omni-projection.catalog.js +177 -0
- package/src/omni-projection.catalog.js.map +1 -0
- package/src/omni-projection.catalog.ts +345 -0
- package/src/omni-projection.lifecycle.d.ts +20 -0
- package/src/omni-projection.lifecycle.js +3 -0
- package/src/omni-projection.lifecycle.js.map +1 -0
- package/src/omni-projection.lifecycle.ts +53 -0
- package/src/omni-record-status.enum.d.ts +5 -0
- package/src/omni-record-status.enum.js +14 -0
- package/src/omni-record-status.enum.js.map +1 -0
- package/src/omni-record-status.enum.ts +11 -0
- package/src/omni-record.backend.d.ts +2 -0
- package/src/omni-record.backend.js +13 -0
- package/src/omni-record.backend.js.map +1 -0
- package/src/omni-record.backend.ts +19 -0
- package/src/omni-record.dto.d.ts +29 -0
- package/src/omni-record.dto.js +169 -0
- package/src/omni-record.dto.js.map +1 -0
- package/src/omni-record.dto.ts +157 -0
- package/src/omni-record.service.d.ts +18 -0
- package/src/omni-record.service.js +45 -0
- package/src/omni-record.service.js.map +1 -0
- package/src/omni-record.service.ts +113 -0
- package/src/omni-relation-kind.contract.d.ts +9 -0
- package/src/omni-relation-kind.contract.js +33 -0
- package/src/omni-relation-kind.contract.js.map +1 -0
- package/src/omni-relation-kind.contract.ts +49 -0
- package/src/omni-relation-kind.enum.d.ts +6 -0
- package/src/omni-relation-kind.enum.js +15 -0
- package/src/omni-relation-kind.enum.js.map +1 -0
- package/src/omni-relation-kind.enum.ts +12 -0
- package/src/omni-relation-projection.definition.d.ts +25 -0
- package/src/omni-relation-projection.definition.js +83 -0
- package/src/omni-relation-projection.definition.js.map +1 -0
- package/src/omni-relation-projection.definition.ts +166 -0
- package/src/omni-relation-projection.resource.d.ts +51 -0
- package/src/omni-relation-projection.resource.js +203 -0
- package/src/omni-relation-projection.resource.js.map +1 -0
- package/src/omni-relation-projection.resource.ts +360 -0
- package/src/omni-relation-projection.service.d.ts +47 -0
- package/src/omni-relation-projection.service.js +385 -0
- package/src/omni-relation-projection.service.js.map +1 -0
- package/src/omni-relation-projection.service.ts +610 -0
- package/src/omni-relation-semantics.d.ts +11 -0
- package/src/omni-relation-semantics.js +34 -0
- package/src/omni-relation-semantics.js.map +1 -0
- package/src/omni-relation-semantics.ts +52 -0
- package/src/omni-relation-status.enum.d.ts +5 -0
- package/src/omni-relation-status.enum.js +14 -0
- package/src/omni-relation-status.enum.js.map +1 -0
- package/src/omni-relation-status.enum.ts +11 -0
- package/src/omni-relation.backend.d.ts +2 -0
- package/src/omni-relation.backend.js +17 -0
- package/src/omni-relation.backend.js.map +1 -0
- package/src/omni-relation.backend.ts +21 -0
- package/src/omni-relation.dto.d.ts +28 -0
- package/src/omni-relation.dto.js +153 -0
- package/src/omni-relation.dto.js.map +1 -0
- package/src/omni-relation.dto.ts +142 -0
- package/src/omni-relation.service.d.ts +19 -0
- package/src/omni-relation.service.js +76 -0
- package/src/omni-relation.service.js.map +1 -0
- package/src/omni-relation.service.ts +159 -0
- package/src/omni-scope.d.ts +33 -0
- package/src/omni-scope.js +91 -0
- package/src/omni-scope.js.map +1 -0
- package/src/omni-scope.ts +161 -0
- package/src/omni-scoped.backend.d.ts +21 -0
- package/src/omni-scoped.backend.js +47 -0
- package/src/omni-scoped.backend.js.map +1 -0
- package/src/omni-scoped.backend.ts +110 -0
- package/src/omni-scoped.repository.d.ts +10 -0
- package/src/omni-scoped.repository.js +26 -0
- package/src/omni-scoped.repository.js.map +1 -0
- package/src/omni-scoped.repository.ts +34 -0
- package/src/omni-scoped.service.d.ts +36 -0
- package/src/omni-scoped.service.js +171 -0
- package/src/omni-scoped.service.js.map +1 -0
- package/src/omni-scoped.service.ts +338 -0
- package/src/omnikernel.diagnostics.d.ts +16 -0
- package/src/omnikernel.diagnostics.js +50 -0
- package/src/omnikernel.diagnostics.js.map +1 -0
- package/src/omnikernel.diagnostics.ts +83 -0
- package/src/omnikernel.module.d.ts +5 -0
- package/src/omnikernel.module.js +87 -0
- package/src/omnikernel.module.js.map +1 -0
- package/src/omnikernel.module.ts +97 -0
- package/src/omnikernel.query.service.d.ts +17 -0
- package/src/omnikernel.query.service.js +85 -0
- package/src/omnikernel.query.service.js.map +1 -0
- package/src/omnikernel.query.service.ts +108 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DataSource } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
export interface OmniKernelQueryPlanEvidence {
|
|
4
|
+
dialect: 'sqlite' | 'postgres';
|
|
5
|
+
recordGridPlan: readonly string[];
|
|
6
|
+
relationSourcePlan: readonly string[];
|
|
7
|
+
usesRecordGridIndex: boolean;
|
|
8
|
+
usesRelationSourceIndex: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const recordGridIndex = 'omni_record_scope_kind_status_guid_idx';
|
|
12
|
+
const relationSourceIndex =
|
|
13
|
+
'omni_relation_scope_source_kind_status_created_guid_idx';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Bounded operator evidence for the two high-fanout generated read shapes.
|
|
17
|
+
* This is diagnostic-only: CRUD continues to use the normal TypeORM path.
|
|
18
|
+
*/
|
|
19
|
+
export async function collectOmniKernelQueryPlanEvidence(
|
|
20
|
+
dataSource: DataSource,
|
|
21
|
+
sample: {
|
|
22
|
+
scopeId: string;
|
|
23
|
+
recordKind: string;
|
|
24
|
+
recordStatus: string;
|
|
25
|
+
sourceRecordId: string;
|
|
26
|
+
relationKind: string;
|
|
27
|
+
relationStatus: string;
|
|
28
|
+
},
|
|
29
|
+
): Promise<OmniKernelQueryPlanEvidence> {
|
|
30
|
+
const dialect = dataSource.options.type;
|
|
31
|
+
if (dialect !== 'sqlite' && dialect !== 'postgres') {
|
|
32
|
+
throw new TypeError(
|
|
33
|
+
'OmniKernel diagnostics support sqlite and postgres only.',
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const statements =
|
|
38
|
+
dialect === 'sqlite'
|
|
39
|
+
? {
|
|
40
|
+
record: `EXPLAIN QUERY PLAN SELECT "guid" FROM "omni-record" WHERE "scopeId" = ? AND "kind" = ? AND "status" = ? AND "deletedAt" IS NULL ORDER BY "guid"`,
|
|
41
|
+
relation: `EXPLAIN QUERY PLAN SELECT "guid" FROM "omni-relation" WHERE "scopeId" = ? AND "sourceRecordId" = ? AND "kind" = ? AND "status" = ? ORDER BY "createdAt", "guid"`,
|
|
42
|
+
}
|
|
43
|
+
: {
|
|
44
|
+
record: `EXPLAIN (FORMAT JSON) SELECT "guid" FROM "omni-record" WHERE "scopeId" = $1 AND "kind" = $2 AND "status" = $3 AND "deletedAt" IS NULL ORDER BY "guid"`,
|
|
45
|
+
relation: `EXPLAIN (FORMAT JSON) SELECT "guid" FROM "omni-relation" WHERE "scopeId" = $1 AND "sourceRecordId" = $2 AND "kind" = $3 AND "status" = $4 ORDER BY "createdAt", "guid"`,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const recordResult = await dataSource.query(statements.record, [
|
|
49
|
+
sample.scopeId,
|
|
50
|
+
sample.recordKind,
|
|
51
|
+
sample.recordStatus,
|
|
52
|
+
]);
|
|
53
|
+
const relationResult = await dataSource.query(statements.relation, [
|
|
54
|
+
sample.scopeId,
|
|
55
|
+
sample.sourceRecordId,
|
|
56
|
+
sample.relationKind,
|
|
57
|
+
sample.relationStatus,
|
|
58
|
+
]);
|
|
59
|
+
const recordGridPlan = flattenPlan(recordResult);
|
|
60
|
+
const relationSourcePlan = flattenPlan(relationResult);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
dialect,
|
|
64
|
+
recordGridPlan,
|
|
65
|
+
relationSourcePlan,
|
|
66
|
+
usesRecordGridIndex: containsIndex(recordGridPlan, recordGridIndex),
|
|
67
|
+
usesRelationSourceIndex: containsIndex(
|
|
68
|
+
relationSourcePlan,
|
|
69
|
+
relationSourceIndex,
|
|
70
|
+
),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function flattenPlan(result: unknown): string[] {
|
|
75
|
+
return JSON.stringify(result)
|
|
76
|
+
.replaceAll('\\n', ' ')
|
|
77
|
+
.split(/(?<=\}),|\n/)
|
|
78
|
+
.filter((line) => line.length > 0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function containsIndex(plan: readonly string[], indexName: string): boolean {
|
|
82
|
+
return plan.some((line) => line.includes(indexName));
|
|
83
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 OmniKernelModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.OmniKernelModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
13
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
14
|
+
const omni_external_ref_entity_js_1 = require("./base/omni-external-ref.entity.js");
|
|
15
|
+
const omni_named_entity_js_1 = require("./base/omni-named.entity.js");
|
|
16
|
+
const omni_record_entity_js_1 = require("./base/omni-record.entity.js");
|
|
17
|
+
const omni_relation_entity_js_1 = require("./base/omni-relation.entity.js");
|
|
18
|
+
const omni_collection_entity_js_1 = require("./omni-collection.entity.js");
|
|
19
|
+
const omni_collection_backend_js_1 = require("./omni-collection.backend.js");
|
|
20
|
+
const omni_document_entity_js_1 = require("./omni-document.entity.js");
|
|
21
|
+
const omni_document_backend_js_1 = require("./omni-document.backend.js");
|
|
22
|
+
const omni_external_ref_backend_js_1 = require("./omni-external-ref.backend.js");
|
|
23
|
+
const omni_named_backend_js_1 = require("./omni-named.backend.js");
|
|
24
|
+
const omni_record_backend_js_1 = require("./omni-record.backend.js");
|
|
25
|
+
const omni_relation_backend_js_1 = require("./omni-relation.backend.js");
|
|
26
|
+
const omnikernel_query_service_js_1 = require("./omnikernel.query.service.js");
|
|
27
|
+
const omni_scope_js_1 = require("./omni-scope.js");
|
|
28
|
+
let OmniKernelModule = OmniKernelModule_1 = class OmniKernelModule {
|
|
29
|
+
static register(registration) {
|
|
30
|
+
const options = (0, omni_scope_js_1.normalizeOmniKernelRegistrationOptions)(registration);
|
|
31
|
+
const { dbConnection } = options;
|
|
32
|
+
const omniNamedProviders = (0, omni_named_backend_js_1.omniNamedBackendProvidersFactory)(dbConnection).providers;
|
|
33
|
+
const omniRecordProviders = (0, omni_record_backend_js_1.omniRecordBackendProvidersFactory)(dbConnection, options.reservedRecordKinds).providers;
|
|
34
|
+
const omniRelationProviders = (0, omni_relation_backend_js_1.omniRelationBackendProvidersFactory)(dbConnection).providers;
|
|
35
|
+
const omniCollectionProviders = (0, omni_collection_backend_js_1.omniCollectionBackendProvidersFactory)(dbConnection).providers;
|
|
36
|
+
const omniDocumentProviders = (0, omni_document_backend_js_1.omniDocumentBackendProvidersFactory)(dbConnection).providers;
|
|
37
|
+
const omniExternalRefProviders = (0, omni_external_ref_backend_js_1.omniExternalRefBackendProvidersFactory)(dbConnection).providers;
|
|
38
|
+
const omniKernelQueryServiceProvider = (0, omnikernel_query_service_js_1.omniKernelQueryServiceProviderFactory)(dbConnection);
|
|
39
|
+
const eventEmitter = new event_emitter_1.EventEmitter2();
|
|
40
|
+
return {
|
|
41
|
+
module: OmniKernelModule_1,
|
|
42
|
+
imports: [
|
|
43
|
+
typeorm_1.TypeOrmModule.forFeature([
|
|
44
|
+
omni_named_entity_js_1.OmniNamedEntity,
|
|
45
|
+
omni_record_entity_js_1.OmniRecordEntity,
|
|
46
|
+
omni_relation_entity_js_1.OmniRelationEntity,
|
|
47
|
+
omni_collection_entity_js_1.OmniCollectionEntity,
|
|
48
|
+
omni_document_entity_js_1.OmniDocumentEntity,
|
|
49
|
+
omni_external_ref_entity_js_1.OmniExternalRefEntity,
|
|
50
|
+
], dbConnection),
|
|
51
|
+
],
|
|
52
|
+
providers: [
|
|
53
|
+
{ provide: omni_scope_js_1.OMNI_KERNEL_OPTIONS, useValue: options },
|
|
54
|
+
omni_scope_js_1.OmniScopeContext,
|
|
55
|
+
{
|
|
56
|
+
provide: event_emitter_1.EventEmitter2,
|
|
57
|
+
useValue: eventEmitter,
|
|
58
|
+
},
|
|
59
|
+
...omniNamedProviders,
|
|
60
|
+
...omniRecordProviders,
|
|
61
|
+
...omniRelationProviders,
|
|
62
|
+
...omniCollectionProviders,
|
|
63
|
+
...omniDocumentProviders,
|
|
64
|
+
...omniExternalRefProviders,
|
|
65
|
+
omniKernelQueryServiceProvider,
|
|
66
|
+
],
|
|
67
|
+
exports: [
|
|
68
|
+
omni_scope_js_1.OMNI_KERNEL_OPTIONS,
|
|
69
|
+
omni_scope_js_1.OmniScopeContext,
|
|
70
|
+
event_emitter_1.EventEmitter2,
|
|
71
|
+
...omniNamedProviders,
|
|
72
|
+
...omniRecordProviders,
|
|
73
|
+
...omniRelationProviders,
|
|
74
|
+
...omniCollectionProviders,
|
|
75
|
+
...omniDocumentProviders,
|
|
76
|
+
...omniExternalRefProviders,
|
|
77
|
+
omniKernelQueryServiceProvider,
|
|
78
|
+
omnikernel_query_service_js_1.OmniKernelQueryService,
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.OmniKernelModule = OmniKernelModule;
|
|
84
|
+
exports.OmniKernelModule = OmniKernelModule = OmniKernelModule_1 = __decorate([
|
|
85
|
+
(0, common_1.Module)({})
|
|
86
|
+
], OmniKernelModule);
|
|
87
|
+
//# sourceMappingURL=omnikernel.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omnikernel.module.js","sourceRoot":"","sources":["omnikernel.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,yDAAsD;AACtD,6CAAgD;AAChD,oFAA2E;AAC3E,sEAA8D;AAC9D,wEAAgE;AAChE,4EAAoE;AACpE,2EAAmE;AACnE,6EAAqF;AACrF,uEAA+D;AAC/D,yEAAiF;AACjF,iFAAwF;AACxF,mEAA2E;AAC3E,qEAA6E;AAC7E,yEAAiF;AACjF,+EAGuC;AACvC,mDAKyB;AAGlB,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B,MAAM,CAAC,QAAQ,CACb,YAAoD;QAEpD,MAAM,OAAO,GAAG,IAAA,sDAAsC,EAAC,YAAY,CAAC,CAAC;QACrE,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QACjC,MAAM,kBAAkB,GACtB,IAAA,wDAAgC,EAAC,YAAY,CAAC,CAAC,SAAS,CAAC;QAC3D,MAAM,mBAAmB,GAAG,IAAA,0DAAiC,EAC3D,YAAY,EACZ,OAAO,CAAC,mBAAmB,CAC5B,CAAC,SAAS,CAAC;QACZ,MAAM,qBAAqB,GACzB,IAAA,8DAAmC,EAAC,YAAY,CAAC,CAAC,SAAS,CAAC;QAC9D,MAAM,uBAAuB,GAC3B,IAAA,kEAAqC,EAAC,YAAY,CAAC,CAAC,SAAS,CAAC;QAChE,MAAM,qBAAqB,GACzB,IAAA,8DAAmC,EAAC,YAAY,CAAC,CAAC,SAAS,CAAC;QAC9D,MAAM,wBAAwB,GAC5B,IAAA,qEAAsC,EAAC,YAAY,CAAC,CAAC,SAAS,CAAC;QACjE,MAAM,8BAA8B,GAClC,IAAA,mEAAqC,EAAC,YAAY,CAAC,CAAC;QACtD,MAAM,YAAY,GAAG,IAAI,6BAAa,EAAE,CAAC;QAEzC,OAAO;YACL,MAAM,EAAE,kBAAgB;YACxB,OAAO,EAAE;gBACP,uBAAa,CAAC,UAAU,CACtB;oBACE,sCAAe;oBACf,wCAAgB;oBAChB,4CAAkB;oBAClB,gDAAoB;oBACpB,4CAAkB;oBAClB,mDAAqB;iBACtB,EACD,YAAY,CACb;aACF;YACD,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,mCAAmB,EAAE,QAAQ,EAAE,OAAO,EAAE;gBACnD,gCAAgB;gBAChB;oBACE,OAAO,EAAE,6BAAa;oBACtB,QAAQ,EAAE,YAAY;iBACvB;gBACD,GAAG,kBAAkB;gBACrB,GAAG,mBAAmB;gBACtB,GAAG,qBAAqB;gBACxB,GAAG,uBAAuB;gBAC1B,GAAG,qBAAqB;gBACxB,GAAG,wBAAwB;gBAC3B,8BAA8B;aAC/B;YACD,OAAO,EAAE;gBACP,mCAAmB;gBACnB,gCAAgB;gBAChB,6BAAa;gBACb,GAAG,kBAAkB;gBACrB,GAAG,mBAAmB;gBACtB,GAAG,qBAAqB;gBACxB,GAAG,uBAAuB;gBAC1B,GAAG,qBAAqB;gBACxB,GAAG,wBAAwB;gBAC3B,8BAA8B;gBAC9B,oDAAsB;aACvB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AArEY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,gBAAgB,CAqE5B"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DynamicModule, Module } from '@nestjs/common';
|
|
2
|
+
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
4
|
+
import { OmniExternalRefEntity } from './base/omni-external-ref.entity.js';
|
|
5
|
+
import { OmniNamedEntity } from './base/omni-named.entity.js';
|
|
6
|
+
import { OmniRecordEntity } from './base/omni-record.entity.js';
|
|
7
|
+
import { OmniRelationEntity } from './base/omni-relation.entity.js';
|
|
8
|
+
import { OmniCollectionEntity } from './omni-collection.entity.js';
|
|
9
|
+
import { omniCollectionBackendProvidersFactory } from './omni-collection.backend.js';
|
|
10
|
+
import { OmniDocumentEntity } from './omni-document.entity.js';
|
|
11
|
+
import { omniDocumentBackendProvidersFactory } from './omni-document.backend.js';
|
|
12
|
+
import { omniExternalRefBackendProvidersFactory } from './omni-external-ref.backend.js';
|
|
13
|
+
import { omniNamedBackendProvidersFactory } from './omni-named.backend.js';
|
|
14
|
+
import { omniRecordBackendProvidersFactory } from './omni-record.backend.js';
|
|
15
|
+
import { omniRelationBackendProvidersFactory } from './omni-relation.backend.js';
|
|
16
|
+
import {
|
|
17
|
+
OmniKernelQueryService,
|
|
18
|
+
omniKernelQueryServiceProviderFactory,
|
|
19
|
+
} from './omnikernel.query.service.js';
|
|
20
|
+
import {
|
|
21
|
+
OMNI_KERNEL_OPTIONS,
|
|
22
|
+
OmniScopeContext,
|
|
23
|
+
normalizeOmniKernelRegistrationOptions,
|
|
24
|
+
type OmniKernelRegistrationOptions,
|
|
25
|
+
} from './omni-scope.js';
|
|
26
|
+
|
|
27
|
+
@Module({})
|
|
28
|
+
export class OmniKernelModule {
|
|
29
|
+
static register(
|
|
30
|
+
registration: string | OmniKernelRegistrationOptions,
|
|
31
|
+
): DynamicModule {
|
|
32
|
+
const options = normalizeOmniKernelRegistrationOptions(registration);
|
|
33
|
+
const { dbConnection } = options;
|
|
34
|
+
const omniNamedProviders =
|
|
35
|
+
omniNamedBackendProvidersFactory(dbConnection).providers;
|
|
36
|
+
const omniRecordProviders = omniRecordBackendProvidersFactory(
|
|
37
|
+
dbConnection,
|
|
38
|
+
options.reservedRecordKinds,
|
|
39
|
+
).providers;
|
|
40
|
+
const omniRelationProviders =
|
|
41
|
+
omniRelationBackendProvidersFactory(dbConnection).providers;
|
|
42
|
+
const omniCollectionProviders =
|
|
43
|
+
omniCollectionBackendProvidersFactory(dbConnection).providers;
|
|
44
|
+
const omniDocumentProviders =
|
|
45
|
+
omniDocumentBackendProvidersFactory(dbConnection).providers;
|
|
46
|
+
const omniExternalRefProviders =
|
|
47
|
+
omniExternalRefBackendProvidersFactory(dbConnection).providers;
|
|
48
|
+
const omniKernelQueryServiceProvider =
|
|
49
|
+
omniKernelQueryServiceProviderFactory(dbConnection);
|
|
50
|
+
const eventEmitter = new EventEmitter2();
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
module: OmniKernelModule,
|
|
54
|
+
imports: [
|
|
55
|
+
TypeOrmModule.forFeature(
|
|
56
|
+
[
|
|
57
|
+
OmniNamedEntity,
|
|
58
|
+
OmniRecordEntity,
|
|
59
|
+
OmniRelationEntity,
|
|
60
|
+
OmniCollectionEntity,
|
|
61
|
+
OmniDocumentEntity,
|
|
62
|
+
OmniExternalRefEntity,
|
|
63
|
+
],
|
|
64
|
+
dbConnection,
|
|
65
|
+
),
|
|
66
|
+
],
|
|
67
|
+
providers: [
|
|
68
|
+
{ provide: OMNI_KERNEL_OPTIONS, useValue: options },
|
|
69
|
+
OmniScopeContext,
|
|
70
|
+
{
|
|
71
|
+
provide: EventEmitter2,
|
|
72
|
+
useValue: eventEmitter,
|
|
73
|
+
},
|
|
74
|
+
...omniNamedProviders,
|
|
75
|
+
...omniRecordProviders,
|
|
76
|
+
...omniRelationProviders,
|
|
77
|
+
...omniCollectionProviders,
|
|
78
|
+
...omniDocumentProviders,
|
|
79
|
+
...omniExternalRefProviders,
|
|
80
|
+
omniKernelQueryServiceProvider,
|
|
81
|
+
],
|
|
82
|
+
exports: [
|
|
83
|
+
OMNI_KERNEL_OPTIONS,
|
|
84
|
+
OmniScopeContext,
|
|
85
|
+
EventEmitter2,
|
|
86
|
+
...omniNamedProviders,
|
|
87
|
+
...omniRecordProviders,
|
|
88
|
+
...omniRelationProviders,
|
|
89
|
+
...omniCollectionProviders,
|
|
90
|
+
...omniDocumentProviders,
|
|
91
|
+
...omniExternalRefProviders,
|
|
92
|
+
omniKernelQueryServiceProvider,
|
|
93
|
+
OmniKernelQueryService,
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FactoryProvider } from '@nestjs/common';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { OmniExternalRefEntity } from './base/omni-external-ref.entity.js';
|
|
4
|
+
import { OmniRecordEntity } from './base/omni-record.entity.js';
|
|
5
|
+
import { OmniRelationEntity } from './base/omni-relation.entity.js';
|
|
6
|
+
import { OmniCollectionEntity } from './omni-collection.entity.js';
|
|
7
|
+
import { type OmniScope } from './omni-scope.js';
|
|
8
|
+
export declare class OmniKernelQueryService {
|
|
9
|
+
protected relationRepository: Repository<OmniRelationEntity>;
|
|
10
|
+
protected externalRefRepository: Repository<OmniExternalRefEntity>;
|
|
11
|
+
protected readonly scope: OmniScope;
|
|
12
|
+
constructor(relationRepository: Repository<OmniRelationEntity>, externalRefRepository: Repository<OmniExternalRefEntity>, scope?: OmniScope);
|
|
13
|
+
getCollectionMembers(collectionId: string): Promise<OmniRecordEntity[]>;
|
|
14
|
+
getDocumentCollections(documentId: string): Promise<OmniCollectionEntity[]>;
|
|
15
|
+
getDocumentExternalRefs(documentId: string, provider?: string): Promise<OmniExternalRefEntity[]>;
|
|
16
|
+
}
|
|
17
|
+
export declare const omniKernelQueryServiceProviderFactory: (dbConnection: string) => FactoryProvider<OmniKernelQueryService>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.omniKernelQueryServiceProviderFactory = exports.OmniKernelQueryService = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
6
|
+
const omni_external_ref_entity_js_1 = require("./base/omni-external-ref.entity.js");
|
|
7
|
+
const omni_relation_entity_js_1 = require("./base/omni-relation.entity.js");
|
|
8
|
+
const omni_external_ref_internal_type_enum_js_1 = require("./omni-external-ref-internal-type.enum.js");
|
|
9
|
+
const omni_relation_kind_enum_js_1 = require("./omni-relation-kind.enum.js");
|
|
10
|
+
const omni_relation_status_enum_js_1 = require("./omni-relation-status.enum.js");
|
|
11
|
+
const omni_relation_semantics_js_1 = require("./omni-relation-semantics.js");
|
|
12
|
+
const omni_scope_js_1 = require("./omni-scope.js");
|
|
13
|
+
const defaultQueryScope = {
|
|
14
|
+
scopeId: 'default',
|
|
15
|
+
cacheKey: (key) => `default:${key}`,
|
|
16
|
+
};
|
|
17
|
+
class OmniKernelQueryService {
|
|
18
|
+
constructor(relationRepository, externalRefRepository, scope = defaultQueryScope) {
|
|
19
|
+
this.relationRepository = relationRepository;
|
|
20
|
+
this.externalRefRepository = externalRefRepository;
|
|
21
|
+
this.scope = scope;
|
|
22
|
+
}
|
|
23
|
+
async getCollectionMembers(collectionId) {
|
|
24
|
+
const relations = await this.relationRepository.find({
|
|
25
|
+
where: {
|
|
26
|
+
scopeId: this.scope.scopeId,
|
|
27
|
+
sourceRecordId: collectionId,
|
|
28
|
+
kind: omni_relation_kind_enum_js_1.OmniRelationKind.Contains,
|
|
29
|
+
status: omni_relation_status_enum_js_1.OmniRelationStatus.Active,
|
|
30
|
+
},
|
|
31
|
+
relations: {
|
|
32
|
+
targetRecord: true,
|
|
33
|
+
},
|
|
34
|
+
order: {
|
|
35
|
+
createdAt: 'ASC',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return relations.map((relation) => relation.targetRecord);
|
|
39
|
+
}
|
|
40
|
+
async getDocumentCollections(documentId) {
|
|
41
|
+
const relations = await this.relationRepository.find({
|
|
42
|
+
where: {
|
|
43
|
+
scopeId: this.scope.scopeId,
|
|
44
|
+
targetRecordId: documentId,
|
|
45
|
+
kind: omni_relation_kind_enum_js_1.OmniRelationKind.Contains,
|
|
46
|
+
status: omni_relation_status_enum_js_1.OmniRelationStatus.Active,
|
|
47
|
+
},
|
|
48
|
+
relations: {
|
|
49
|
+
sourceRecord: true,
|
|
50
|
+
},
|
|
51
|
+
order: {
|
|
52
|
+
createdAt: 'ASC',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
return relations
|
|
56
|
+
.map((relation) => relation.sourceRecord)
|
|
57
|
+
.filter((record) => !!record && (0, omni_relation_semantics_js_1.isOmniCollectionRecordKind)(record.kind));
|
|
58
|
+
}
|
|
59
|
+
async getDocumentExternalRefs(documentId, provider) {
|
|
60
|
+
return this.externalRefRepository.find({
|
|
61
|
+
where: {
|
|
62
|
+
scopeId: this.scope.scopeId,
|
|
63
|
+
internalType: omni_external_ref_internal_type_enum_js_1.OmniExternalRefInternalType.Document,
|
|
64
|
+
internalId: documentId,
|
|
65
|
+
...(provider ? { provider } : {}),
|
|
66
|
+
},
|
|
67
|
+
order: {
|
|
68
|
+
createdAt: 'ASC',
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.OmniKernelQueryService = OmniKernelQueryService;
|
|
74
|
+
const omniKernelQueryServiceProviderFactory = (dbConnection) => ({
|
|
75
|
+
provide: OmniKernelQueryService,
|
|
76
|
+
scope: common_1.Scope.REQUEST,
|
|
77
|
+
useFactory: (relationRepository, externalRefRepository, scope) => new OmniKernelQueryService(relationRepository, externalRefRepository, scope),
|
|
78
|
+
inject: [
|
|
79
|
+
(0, typeorm_1.getRepositoryToken)(omni_relation_entity_js_1.OmniRelationEntity, dbConnection),
|
|
80
|
+
(0, typeorm_1.getRepositoryToken)(omni_external_ref_entity_js_1.OmniExternalRefEntity, dbConnection),
|
|
81
|
+
omni_scope_js_1.OmniScopeContext,
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
exports.omniKernelQueryServiceProviderFactory = omniKernelQueryServiceProviderFactory;
|
|
85
|
+
//# sourceMappingURL=omnikernel.query.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omnikernel.query.service.js","sourceRoot":"","sources":["omnikernel.query.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { FactoryProvider, Scope } from '@nestjs/common';
|
|
2
|
+
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
import { OmniExternalRefEntity } from './base/omni-external-ref.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 { OmniExternalRefInternalType } from './omni-external-ref-internal-type.enum.js';
|
|
9
|
+
import { OmniRelationKind } from './omni-relation-kind.enum.js';
|
|
10
|
+
import { OmniRelationStatus } from './omni-relation-status.enum.js';
|
|
11
|
+
import { isOmniCollectionRecordKind } from './omni-relation-semantics.js';
|
|
12
|
+
import { OmniScopeContext, type OmniScope } from './omni-scope.js';
|
|
13
|
+
|
|
14
|
+
const defaultQueryScope: OmniScope = {
|
|
15
|
+
scopeId: 'default',
|
|
16
|
+
cacheKey: (key) => `default:${key}`,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class OmniKernelQueryService {
|
|
20
|
+
constructor(
|
|
21
|
+
protected relationRepository: Repository<OmniRelationEntity>,
|
|
22
|
+
protected externalRefRepository: Repository<OmniExternalRefEntity>,
|
|
23
|
+
protected readonly scope: OmniScope = defaultQueryScope,
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
async getCollectionMembers(
|
|
27
|
+
collectionId: string,
|
|
28
|
+
): Promise<OmniRecordEntity[]> {
|
|
29
|
+
const relations = await this.relationRepository.find({
|
|
30
|
+
where: {
|
|
31
|
+
scopeId: this.scope.scopeId,
|
|
32
|
+
sourceRecordId: collectionId,
|
|
33
|
+
kind: OmniRelationKind.Contains,
|
|
34
|
+
status: OmniRelationStatus.Active,
|
|
35
|
+
},
|
|
36
|
+
relations: {
|
|
37
|
+
targetRecord: true,
|
|
38
|
+
},
|
|
39
|
+
order: {
|
|
40
|
+
createdAt: 'ASC',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return relations.map((relation) => relation.targetRecord);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getDocumentCollections(
|
|
48
|
+
documentId: string,
|
|
49
|
+
): Promise<OmniCollectionEntity[]> {
|
|
50
|
+
const relations = await this.relationRepository.find({
|
|
51
|
+
where: {
|
|
52
|
+
scopeId: this.scope.scopeId,
|
|
53
|
+
targetRecordId: documentId,
|
|
54
|
+
kind: OmniRelationKind.Contains,
|
|
55
|
+
status: OmniRelationStatus.Active,
|
|
56
|
+
},
|
|
57
|
+
relations: {
|
|
58
|
+
sourceRecord: true,
|
|
59
|
+
},
|
|
60
|
+
order: {
|
|
61
|
+
createdAt: 'ASC',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return relations
|
|
66
|
+
.map((relation) => relation.sourceRecord)
|
|
67
|
+
.filter(
|
|
68
|
+
(record): record is OmniCollectionEntity =>
|
|
69
|
+
!!record && isOmniCollectionRecordKind(record.kind),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getDocumentExternalRefs(documentId: string, provider?: string) {
|
|
74
|
+
return this.externalRefRepository.find({
|
|
75
|
+
where: {
|
|
76
|
+
scopeId: this.scope.scopeId,
|
|
77
|
+
internalType: OmniExternalRefInternalType.Document,
|
|
78
|
+
internalId: documentId,
|
|
79
|
+
...(provider ? { provider } : {}),
|
|
80
|
+
},
|
|
81
|
+
order: {
|
|
82
|
+
createdAt: 'ASC',
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const omniKernelQueryServiceProviderFactory = (
|
|
89
|
+
dbConnection: string,
|
|
90
|
+
): FactoryProvider<OmniKernelQueryService> => ({
|
|
91
|
+
provide: OmniKernelQueryService,
|
|
92
|
+
scope: Scope.REQUEST,
|
|
93
|
+
useFactory: (
|
|
94
|
+
relationRepository: Repository<OmniRelationEntity>,
|
|
95
|
+
externalRefRepository: Repository<OmniExternalRefEntity>,
|
|
96
|
+
scope: OmniScope,
|
|
97
|
+
) =>
|
|
98
|
+
new OmniKernelQueryService(
|
|
99
|
+
relationRepository,
|
|
100
|
+
externalRefRepository,
|
|
101
|
+
scope,
|
|
102
|
+
),
|
|
103
|
+
inject: [
|
|
104
|
+
getRepositoryToken(OmniRelationEntity, dbConnection),
|
|
105
|
+
getRepositoryToken(OmniExternalRefEntity, dbConnection),
|
|
106
|
+
OmniScopeContext,
|
|
107
|
+
],
|
|
108
|
+
});
|