@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,360 @@
|
|
|
1
|
+
import { Scope, type InjectionToken, type Provider } from '@nestjs/common';
|
|
2
|
+
import { InputType, Int, ObjectType } from '@nestjs/graphql';
|
|
3
|
+
import { getDataSourceToken } from '@nestjs/typeorm';
|
|
4
|
+
import {
|
|
5
|
+
CrudGenResourceFactory,
|
|
6
|
+
FilterOptionType,
|
|
7
|
+
ModelField,
|
|
8
|
+
ModelObject,
|
|
9
|
+
getServiceToken,
|
|
10
|
+
type ICrudGenResourceFactoryResult,
|
|
11
|
+
} from '@nest-yalc-2/crud-gen';
|
|
12
|
+
import {
|
|
13
|
+
GQLDataLoader,
|
|
14
|
+
getDataloaderToken,
|
|
15
|
+
getFn,
|
|
16
|
+
} from '@nest-yalc-2/data-loader';
|
|
17
|
+
import { UUIDScalar } from '@nest-yalc-2/graphql/scalars/uuid.scalar.js';
|
|
18
|
+
import type { ClassType } from '@nest-yalc-2/types/globals.d.js';
|
|
19
|
+
import returnValue from '@nest-yalc-2/utils/returnValue.js';
|
|
20
|
+
import { Exclude, Expose } from 'class-transformer';
|
|
21
|
+
import { GraphQLJSON } from 'graphql-type-json';
|
|
22
|
+
import type { DataSource, ObjectLiteral } from 'typeorm';
|
|
23
|
+
import { OmniRecordEntity } from './base/omni-record.entity.js';
|
|
24
|
+
import { OmniRelationEntity } from './base/omni-relation.entity.js';
|
|
25
|
+
import type {
|
|
26
|
+
OmniProjectionReaderCatalogProvider,
|
|
27
|
+
OmniRelationProjectionReaderRegistration,
|
|
28
|
+
} from './omni-projection.catalog.js';
|
|
29
|
+
import {
|
|
30
|
+
getOmniRelationProjectionAliases,
|
|
31
|
+
getOmniRelationProjectionAllowedKinds,
|
|
32
|
+
type OmniRelationProjectionDefinition,
|
|
33
|
+
} from './omni-relation-projection.definition.js';
|
|
34
|
+
import type { OmniProjectionLifecycleProvider } from './omni-projection.lifecycle.js';
|
|
35
|
+
import { OmniRelationProjectionService } from './omni-relation-projection.service.js';
|
|
36
|
+
import { createOmniRelationKindContract } from './omni-relation-kind.contract.js';
|
|
37
|
+
import { OMNI_KERNEL_OPTIONS, OmniScopeContext } from './omni-scope.js';
|
|
38
|
+
|
|
39
|
+
type RelationGraphqlClass = new () => Record<string, unknown>;
|
|
40
|
+
|
|
41
|
+
export interface OmniRelationProjectionGraphqlNames {
|
|
42
|
+
object: string;
|
|
43
|
+
create: string;
|
|
44
|
+
patch: string;
|
|
45
|
+
conditions: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface OmniRelationProjectionRegistrationOptions<
|
|
49
|
+
Api extends ObjectLiteral,
|
|
50
|
+
> {
|
|
51
|
+
/** API-only model used by CrudGen to derive operation names and tokens. */
|
|
52
|
+
apiModel: ClassType<Api>;
|
|
53
|
+
definition: OmniRelationProjectionDefinition;
|
|
54
|
+
dbConnection: string;
|
|
55
|
+
/** Shared catalog provider, normally built from all returned registrations. */
|
|
56
|
+
catalog?: OmniProjectionReaderCatalogProvider;
|
|
57
|
+
/** Request-scoped app policy injected into the generated service factory. */
|
|
58
|
+
lifecycle?: OmniProjectionLifecycleProvider<
|
|
59
|
+
OmniRelationProjectionDefinition,
|
|
60
|
+
OmniRelationEntity
|
|
61
|
+
>;
|
|
62
|
+
rest?: {
|
|
63
|
+
path?: string;
|
|
64
|
+
};
|
|
65
|
+
graphql?: {
|
|
66
|
+
prefix?: string;
|
|
67
|
+
names?: OmniRelationProjectionGraphqlNames;
|
|
68
|
+
};
|
|
69
|
+
/** Optional consumer-owned ModuleRef token for generated GraphQL DI. */
|
|
70
|
+
moduleRefToken?: InjectionToken;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface OmniRelationProjectionGraphqlTypes {
|
|
74
|
+
object: RelationGraphqlClass;
|
|
75
|
+
create: RelationGraphqlClass;
|
|
76
|
+
patch: RelationGraphqlClass;
|
|
77
|
+
conditions: RelationGraphqlClass;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface OmniRelationProjectionRegistration<Api extends ObjectLiteral> {
|
|
81
|
+
/** omni-relation already belongs to OmniKernelModule; no new table exists. */
|
|
82
|
+
entities: readonly [];
|
|
83
|
+
/** Include these in OmniKernelModule.register({ relationKinds }). */
|
|
84
|
+
relationKinds: readonly string[];
|
|
85
|
+
definition: OmniRelationProjectionDefinition;
|
|
86
|
+
reader: OmniRelationProjectionReaderRegistration;
|
|
87
|
+
graphqlTypes: OmniRelationProjectionGraphqlTypes;
|
|
88
|
+
resource: ICrudGenResourceFactoryResult<Api>;
|
|
89
|
+
controllers: readonly ClassType[];
|
|
90
|
+
providers: readonly Provider[];
|
|
91
|
+
serviceToken: string;
|
|
92
|
+
dataLoaderToken: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function namedClass(
|
|
96
|
+
name: string,
|
|
97
|
+
outputFields?: readonly (readonly [string, string])[],
|
|
98
|
+
): RelationGraphqlClass {
|
|
99
|
+
return {
|
|
100
|
+
[name]: class {
|
|
101
|
+
constructor(data?: Record<string, unknown>) {
|
|
102
|
+
if (!outputFields) {
|
|
103
|
+
Object.assign(this, data);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
for (const [publicName, destination] of outputFields) {
|
|
107
|
+
if (data && Object.prototype.hasOwnProperty.call(data, destination)) {
|
|
108
|
+
(this as Record<string, unknown>)[publicName] = data[destination];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
}[name] as RelationGraphqlClass;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function addField(
|
|
117
|
+
target: RelationGraphqlClass,
|
|
118
|
+
name: string,
|
|
119
|
+
destination: string,
|
|
120
|
+
type: unknown,
|
|
121
|
+
nullable: boolean,
|
|
122
|
+
): void {
|
|
123
|
+
ModelField({
|
|
124
|
+
dst: destination,
|
|
125
|
+
gqlType: returnValue(type),
|
|
126
|
+
gqlOptions: { nullable },
|
|
127
|
+
})(target.prototype, name);
|
|
128
|
+
Expose()(target.prototype, name);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function defaultGraphqlNames(
|
|
132
|
+
apiModel: ClassType,
|
|
133
|
+
): OmniRelationProjectionGraphqlNames {
|
|
134
|
+
return {
|
|
135
|
+
object: apiModel.name,
|
|
136
|
+
create: `${apiModel.name}CreateInput`,
|
|
137
|
+
patch: `${apiModel.name}UpdateInput`,
|
|
138
|
+
conditions: `${apiModel.name}Condition`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Builds aliased public types while retaining native fields inside the store. */
|
|
143
|
+
export function createOmniRelationProjectionGraphqlTypes(
|
|
144
|
+
definition: OmniRelationProjectionDefinition,
|
|
145
|
+
names: OmniRelationProjectionGraphqlNames,
|
|
146
|
+
): OmniRelationProjectionGraphqlTypes {
|
|
147
|
+
const aliases = getOmniRelationProjectionAliases(definition);
|
|
148
|
+
const multipleKinds =
|
|
149
|
+
getOmniRelationProjectionAllowedKinds(definition).length > 1;
|
|
150
|
+
const objectFields: Array<readonly [string, string]> = [
|
|
151
|
+
['guid', 'guid'],
|
|
152
|
+
[aliases.source, 'sourceRecordId'],
|
|
153
|
+
[aliases.target, 'targetRecordId'],
|
|
154
|
+
['revision', 'revision'],
|
|
155
|
+
[aliases.payload, 'payload'],
|
|
156
|
+
];
|
|
157
|
+
if (multipleKinds) objectFields.splice(1, 0, [aliases.kind, 'kind']);
|
|
158
|
+
const object = namedClass(names.object, objectFields);
|
|
159
|
+
ObjectType(names.object)(object);
|
|
160
|
+
ModelObject({
|
|
161
|
+
filters: { type: FilterOptionType.INCLUDE, fields: ['guid'] },
|
|
162
|
+
})(object);
|
|
163
|
+
Exclude()(object);
|
|
164
|
+
addField(object, 'guid', 'guid', UUIDScalar, false);
|
|
165
|
+
if (multipleKinds) {
|
|
166
|
+
addField(object, aliases.kind, 'kind', String, false);
|
|
167
|
+
}
|
|
168
|
+
addField(object, aliases.source, 'sourceRecordId', UUIDScalar, false);
|
|
169
|
+
addField(object, aliases.target, 'targetRecordId', UUIDScalar, false);
|
|
170
|
+
addField(object, 'revision', 'revision', Int, false);
|
|
171
|
+
addField(object, aliases.payload, 'payload', GraphQLJSON, true);
|
|
172
|
+
|
|
173
|
+
const create = namedClass(names.create);
|
|
174
|
+
InputType(names.create)(create);
|
|
175
|
+
ModelObject()(create);
|
|
176
|
+
addField(create, 'guid', 'guid', UUIDScalar, false);
|
|
177
|
+
if (multipleKinds) {
|
|
178
|
+
addField(create, aliases.kind, 'kind', String, false);
|
|
179
|
+
}
|
|
180
|
+
addField(create, aliases.source, 'sourceRecordId', UUIDScalar, false);
|
|
181
|
+
addField(create, aliases.target, 'targetRecordId', UUIDScalar, false);
|
|
182
|
+
addField(create, aliases.payload, 'payload', GraphQLJSON, true);
|
|
183
|
+
|
|
184
|
+
const patch = namedClass(names.patch);
|
|
185
|
+
InputType(names.patch)(patch);
|
|
186
|
+
ModelObject()(patch);
|
|
187
|
+
addField(patch, aliases.payload, 'payload', GraphQLJSON, true);
|
|
188
|
+
addField(patch, 'expectedRevision', 'expectedRevision', Int, false);
|
|
189
|
+
|
|
190
|
+
const conditions = namedClass(names.conditions);
|
|
191
|
+
InputType(names.conditions)(conditions);
|
|
192
|
+
ModelObject()(conditions);
|
|
193
|
+
addField(conditions, 'guid', 'guid', UUIDScalar, false);
|
|
194
|
+
|
|
195
|
+
return { object, create, patch, conditions };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Composes one generated REST/GraphQL/dataloader surface over omni-relation.
|
|
200
|
+
* It never creates a relation table or a handwritten transport adapter.
|
|
201
|
+
*/
|
|
202
|
+
export function createOmniRelationProjectionRegistration<
|
|
203
|
+
Api extends ObjectLiteral,
|
|
204
|
+
>(
|
|
205
|
+
options: OmniRelationProjectionRegistrationOptions<Api>,
|
|
206
|
+
): OmniRelationProjectionRegistration<Api> {
|
|
207
|
+
const graphqlTypes = createOmniRelationProjectionGraphqlTypes(
|
|
208
|
+
options.definition,
|
|
209
|
+
options.graphql?.names ?? defaultGraphqlNames(options.apiModel),
|
|
210
|
+
);
|
|
211
|
+
const serviceToken = getServiceToken(options.apiModel);
|
|
212
|
+
const dataLoaderToken = getDataloaderToken(options.apiModel);
|
|
213
|
+
const resource = CrudGenResourceFactory<Api>({
|
|
214
|
+
entityModel: options.apiModel,
|
|
215
|
+
backend: false,
|
|
216
|
+
graphql: {
|
|
217
|
+
resolver: {
|
|
218
|
+
dto: graphqlTypes.object as ClassType,
|
|
219
|
+
input: {
|
|
220
|
+
create: graphqlTypes.create as ClassType,
|
|
221
|
+
update: graphqlTypes.patch as ClassType,
|
|
222
|
+
conditions: graphqlTypes.conditions as ClassType,
|
|
223
|
+
},
|
|
224
|
+
...(options.graphql?.prefix ? { prefix: options.graphql.prefix } : {}),
|
|
225
|
+
...(options.moduleRefToken !== undefined
|
|
226
|
+
? { moduleRefToken: options.moduleRefToken }
|
|
227
|
+
: {}),
|
|
228
|
+
queries: { getResource: { idName: 'guid' } },
|
|
229
|
+
},
|
|
230
|
+
serviceToken,
|
|
231
|
+
dataLoaderToken,
|
|
232
|
+
},
|
|
233
|
+
rest: {
|
|
234
|
+
dto: graphqlTypes.object as ClassType,
|
|
235
|
+
serialize: true,
|
|
236
|
+
...(options.rest?.path ? { path: options.rest.path } : {}),
|
|
237
|
+
idField: 'guid' as keyof Api & string,
|
|
238
|
+
serviceToken,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
const relationKinds = Object.freeze([
|
|
242
|
+
...getOmniRelationProjectionAllowedKinds(options.definition),
|
|
243
|
+
]);
|
|
244
|
+
const reader = Object.freeze({
|
|
245
|
+
type: 'relation' as const,
|
|
246
|
+
id: options.definition.id,
|
|
247
|
+
definition: options.definition,
|
|
248
|
+
});
|
|
249
|
+
const serviceProvider: Provider =
|
|
250
|
+
options.lifecycle && options.catalog
|
|
251
|
+
? {
|
|
252
|
+
provide: serviceToken,
|
|
253
|
+
scope: Scope.REQUEST,
|
|
254
|
+
useFactory: (
|
|
255
|
+
dataSource: DataSource,
|
|
256
|
+
scope: OmniScopeContext,
|
|
257
|
+
omniOptions: { deletion: { relation: 'hard' | 'tombstone' } },
|
|
258
|
+
lifecycle: any,
|
|
259
|
+
catalog: any,
|
|
260
|
+
) =>
|
|
261
|
+
new OmniRelationProjectionService(
|
|
262
|
+
dataSource.getRepository(OmniRelationEntity),
|
|
263
|
+
scope,
|
|
264
|
+
omniOptions.deletion.relation,
|
|
265
|
+
dataSource.getRepository(OmniRecordEntity),
|
|
266
|
+
createOmniRelationKindContract(relationKinds),
|
|
267
|
+
options.definition,
|
|
268
|
+
dataSource,
|
|
269
|
+
lifecycle,
|
|
270
|
+
catalog,
|
|
271
|
+
),
|
|
272
|
+
inject: [
|
|
273
|
+
getDataSourceToken(options.dbConnection),
|
|
274
|
+
OmniScopeContext,
|
|
275
|
+
OMNI_KERNEL_OPTIONS,
|
|
276
|
+
options.lifecycle.token,
|
|
277
|
+
options.catalog.token,
|
|
278
|
+
],
|
|
279
|
+
}
|
|
280
|
+
: options.lifecycle
|
|
281
|
+
? {
|
|
282
|
+
provide: serviceToken,
|
|
283
|
+
scope: Scope.REQUEST,
|
|
284
|
+
useFactory: (
|
|
285
|
+
dataSource: DataSource,
|
|
286
|
+
scope: OmniScopeContext,
|
|
287
|
+
omniOptions: { deletion: { relation: 'hard' | 'tombstone' } },
|
|
288
|
+
lifecycle: any,
|
|
289
|
+
) =>
|
|
290
|
+
new OmniRelationProjectionService(
|
|
291
|
+
dataSource.getRepository(OmniRelationEntity),
|
|
292
|
+
scope,
|
|
293
|
+
omniOptions.deletion.relation,
|
|
294
|
+
dataSource.getRepository(OmniRecordEntity),
|
|
295
|
+
createOmniRelationKindContract(relationKinds),
|
|
296
|
+
options.definition,
|
|
297
|
+
dataSource,
|
|
298
|
+
lifecycle,
|
|
299
|
+
),
|
|
300
|
+
inject: [
|
|
301
|
+
getDataSourceToken(options.dbConnection),
|
|
302
|
+
OmniScopeContext,
|
|
303
|
+
OMNI_KERNEL_OPTIONS,
|
|
304
|
+
options.lifecycle.token,
|
|
305
|
+
],
|
|
306
|
+
}
|
|
307
|
+
: {
|
|
308
|
+
provide: serviceToken,
|
|
309
|
+
scope: Scope.REQUEST,
|
|
310
|
+
useFactory: (
|
|
311
|
+
dataSource: DataSource,
|
|
312
|
+
scope: OmniScopeContext,
|
|
313
|
+
omniOptions: { deletion: { relation: 'hard' | 'tombstone' } },
|
|
314
|
+
) =>
|
|
315
|
+
new OmniRelationProjectionService(
|
|
316
|
+
dataSource.getRepository(OmniRelationEntity),
|
|
317
|
+
scope,
|
|
318
|
+
omniOptions.deletion.relation,
|
|
319
|
+
dataSource.getRepository(OmniRecordEntity),
|
|
320
|
+
createOmniRelationKindContract(relationKinds),
|
|
321
|
+
options.definition,
|
|
322
|
+
dataSource,
|
|
323
|
+
undefined,
|
|
324
|
+
),
|
|
325
|
+
inject: [
|
|
326
|
+
getDataSourceToken(options.dbConnection),
|
|
327
|
+
OmniScopeContext,
|
|
328
|
+
OMNI_KERNEL_OPTIONS,
|
|
329
|
+
],
|
|
330
|
+
};
|
|
331
|
+
const providers: Provider[] = [
|
|
332
|
+
serviceProvider,
|
|
333
|
+
{
|
|
334
|
+
provide: dataLoaderToken,
|
|
335
|
+
scope: Scope.REQUEST,
|
|
336
|
+
useFactory: (
|
|
337
|
+
service: OmniRelationProjectionService,
|
|
338
|
+
scope: OmniScopeContext,
|
|
339
|
+
) =>
|
|
340
|
+
new GQLDataLoader(getFn(service as never), 'guid', undefined, {
|
|
341
|
+
cacheKeyFn: (key) => scope.cacheKey(key),
|
|
342
|
+
}),
|
|
343
|
+
inject: [serviceToken, OmniScopeContext],
|
|
344
|
+
},
|
|
345
|
+
...resource.providers,
|
|
346
|
+
];
|
|
347
|
+
|
|
348
|
+
return Object.freeze({
|
|
349
|
+
entities: Object.freeze([]) as readonly [],
|
|
350
|
+
relationKinds,
|
|
351
|
+
definition: options.definition,
|
|
352
|
+
reader,
|
|
353
|
+
graphqlTypes: Object.freeze(graphqlTypes),
|
|
354
|
+
resource,
|
|
355
|
+
controllers: Object.freeze([...resource.controllers]),
|
|
356
|
+
providers: Object.freeze(providers),
|
|
357
|
+
serviceToken,
|
|
358
|
+
dataLoaderToken,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type CrudGenFindManyOptions } from '@nest-yalc-2/crud-gen';
|
|
2
|
+
import { type DataSource, type DeepPartial, type FindOptionsWhere, type ObjectLiteral, type Repository } from 'typeorm';
|
|
3
|
+
import { OmniRecordEntity } from './base/omni-record.entity.js';
|
|
4
|
+
import { OmniRelationEntity } from './base/omni-relation.entity.js';
|
|
5
|
+
import { type OmniProjectionReaderCatalog } from './omni-projection.catalog.js';
|
|
6
|
+
import { type OmniRelationProjectionDefinition } from './omni-relation-projection.definition.js';
|
|
7
|
+
import type { OmniProjectionLifecycle } from './omni-projection.lifecycle.js';
|
|
8
|
+
import { OmniRelationService } from './omni-relation.service.js';
|
|
9
|
+
import type { OmniRelationKindContract } from './omni-relation-kind.contract.js';
|
|
10
|
+
import type { OmniDeletePolicy, OmniScope } from './omni-scope.js';
|
|
11
|
+
export declare class OmniRelationProjectionService extends OmniRelationService {
|
|
12
|
+
private readonly relationDeletion;
|
|
13
|
+
private readonly definition;
|
|
14
|
+
private readonly dataSource?;
|
|
15
|
+
private readonly lifecycle?;
|
|
16
|
+
private readonly readerCatalog?;
|
|
17
|
+
constructor(repository: Repository<OmniRelationEntity>, scope: OmniScope, relationDeletion: OmniDeletePolicy, recordRepository: Repository<OmniRecordEntity>, kinds: OmniRelationKindContract, definition: OmniRelationProjectionDefinition, dataSource?: DataSource | undefined, lifecycle?: OmniProjectionLifecycle<OmniRelationProjectionDefinition, OmniRelationEntity> | undefined, readerCatalog?: OmniProjectionReaderCatalog | undefined);
|
|
18
|
+
createEntity(input: DeepPartial<OmniRelationEntity>, findOptions?: CrudGenFindManyOptions<OmniRelationEntity>, returnEntity?: true): Promise<OmniRelationEntity>;
|
|
19
|
+
createEntity(input: DeepPartial<OmniRelationEntity>, findOptions?: CrudGenFindManyOptions<OmniRelationEntity>, returnEntity?: boolean): Promise<OmniRelationEntity | boolean>;
|
|
20
|
+
getEntity(conditions: FindOptionsWhere<OmniRelationEntity>[] | FindOptionsWhere<OmniRelationEntity> | ObjectLiteral | string, fields?: (keyof OmniRelationEntity)[], relations?: string[], databaseName?: string, options?: {
|
|
21
|
+
failOnNull: false;
|
|
22
|
+
}): Promise<OmniRelationEntity | undefined>;
|
|
23
|
+
getEntity(conditions: FindOptionsWhere<OmniRelationEntity>[] | FindOptionsWhere<OmniRelationEntity> | ObjectLiteral | string, fields?: (keyof OmniRelationEntity)[], relations?: string[], databaseName?: string, options?: {
|
|
24
|
+
failOnNull?: boolean;
|
|
25
|
+
}): Promise<OmniRelationEntity>;
|
|
26
|
+
getEntityListExtended(findOptions?: CrudGenFindManyOptions<OmniRelationEntity>, withCount?: false, relations?: string[], databaseName?: string): Promise<OmniRelationEntity[]>;
|
|
27
|
+
getEntityListExtended(findOptions: CrudGenFindManyOptions<OmniRelationEntity>, withCount: true, relations?: string[], databaseName?: string): Promise<[OmniRelationEntity[], number]>;
|
|
28
|
+
updateEntity(conditions: FindOptionsWhere<OmniRelationEntity>, input: DeepPartial<OmniRelationEntity>, _findOptions?: CrudGenFindManyOptions<OmniRelationEntity>, returnEntity?: true): Promise<OmniRelationEntity>;
|
|
29
|
+
updateEntity(conditions: FindOptionsWhere<OmniRelationEntity>, input: DeepPartial<OmniRelationEntity>, _findOptions?: CrudGenFindManyOptions<OmniRelationEntity>, returnEntity?: boolean): Promise<OmniRelationEntity | boolean>;
|
|
30
|
+
deleteEntity(conditions: FindOptionsWhere<OmniRelationEntity>): Promise<boolean>;
|
|
31
|
+
protected assertEndpointKinds(source: OmniRecordEntity, target: OmniRecordEntity): void;
|
|
32
|
+
private createValues;
|
|
33
|
+
private publicEntity;
|
|
34
|
+
private publicInput;
|
|
35
|
+
private selectCreateKind;
|
|
36
|
+
private normalizeInput;
|
|
37
|
+
private normalizeConditions;
|
|
38
|
+
private rejectFixedFields;
|
|
39
|
+
private rejectImmutableEndpoints;
|
|
40
|
+
private validatePayload;
|
|
41
|
+
private withDefinitionConditions;
|
|
42
|
+
private definitionFilters;
|
|
43
|
+
private assertFixedConditions;
|
|
44
|
+
private rejectFixedFilters;
|
|
45
|
+
private readers;
|
|
46
|
+
private mutate;
|
|
47
|
+
}
|