@nest-yalc-2/omnikernel-module 2.2.2 → 2.2.6
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/package.json +17 -15
- package/src/__tests__/omni-collection.entity.spec.ts +49 -49
- package/src/__tests__/omni-collection.service.spec.ts +83 -83
- package/src/__tests__/omni-document.entity.spec.ts +55 -55
- package/src/__tests__/omni-document.service.spec.ts +83 -83
- package/src/__tests__/omni-extension-projection-constraints.spec.ts +518 -518
- package/src/__tests__/omni-extension-projection.registration.spec.ts +947 -946
- package/src/__tests__/omni-extension-projection.service.spec.ts +806 -806
- package/src/__tests__/omni-external-ref.entity.spec.ts +36 -36
- package/src/__tests__/omni-external-ref.service.spec.ts +252 -252
- package/src/__tests__/omni-named.entity.spec.ts +33 -33
- package/src/__tests__/omni-record.entity.spec.ts +32 -32
- package/src/__tests__/omni-record.service.spec.ts +107 -107
- package/src/__tests__/omni-relation-semantics.spec.ts +102 -102
- package/src/__tests__/omni-relation.entity.spec.ts +38 -38
- package/src/__tests__/omni-scope-substrate.spec.ts +81 -81
- package/src/__tests__/omni-scoped.backend.spec.ts +115 -115
- package/src/__tests__/omni-scoped.service.spec.ts +354 -354
- package/src/__tests__/omnikernel.diagnostics.spec.ts +94 -94
- package/src/__tests__/omnikernel.module.spec.ts +38 -40
- package/src/__tests__/omnikernel.persistence.spec.ts +154 -154
- package/src/__tests__/omnikernel.public-api.spec.ts +238 -238
- package/src/__tests__/omnikernel.query.service.spec.ts +155 -155
- package/src/base/omni-base.entity.ts +41 -41
- package/src/base/omni-external-ref.entity.ts +53 -53
- package/src/base/omni-named.entity.ts +16 -16
- package/src/base/omni-record.entity.ts +51 -51
- package/src/base/omni-relation.entity.ts +72 -72
- package/src/index.ts +49 -49
- package/src/omni-collection-kind.enum.ts +10 -10
- package/src/omni-collection.backend.ts +16 -16
- package/src/omni-collection.dto.ts +170 -170
- package/src/omni-collection.entity.ts +21 -21
- package/src/omni-collection.service.ts +75 -75
- package/src/omni-document-kind.enum.ts +12 -12
- package/src/omni-document.backend.ts +16 -16
- package/src/omni-document.dto.ts +198 -198
- package/src/omni-document.entity.ts +30 -30
- package/src/omni-document.service.ts +75 -75
- package/src/omni-dto.helpers.ts +21 -21
- package/src/omni-extension-projection.definition.ts +294 -294
- package/src/omni-extension-projection.resource.ts +274 -274
- package/src/omni-extension-projection.service.ts +452 -452
- package/src/omni-external-ref-binding.validator.ts +53 -53
- package/src/omni-external-ref-internal-type.enum.ts +11 -11
- package/src/omni-external-ref.backend.ts +25 -25
- package/src/omni-external-ref.dto.ts +128 -128
- package/src/omni-external-ref.service.ts +255 -255
- package/src/omni-migration.ts +365 -365
- package/src/omni-named.backend.ts +11 -11
- package/src/omni-named.dto.ts +86 -86
- package/src/omni-projection.catalog.ts +345 -345
- package/src/omni-projection.lifecycle.ts +53 -53
- package/src/omni-record-status.enum.ts +11 -11
- package/src/omni-record.backend.ts +19 -19
- package/src/omni-record.dto.ts +157 -157
- package/src/omni-record.service.ts +113 -113
- package/src/omni-relation-kind.contract.ts +49 -49
- package/src/omni-relation-kind.enum.ts +12 -12
- package/src/omni-relation-projection.definition.ts +166 -166
- package/src/omni-relation-projection.resource.ts +360 -360
- package/src/omni-relation-projection.service.ts +610 -610
- package/src/omni-relation-semantics.ts +52 -52
- package/src/omni-relation-status.enum.ts +11 -11
- package/src/omni-relation.backend.ts +21 -21
- package/src/omni-relation.dto.ts +142 -142
- package/src/omni-relation.service.ts +159 -159
- package/src/omni-scope.ts +161 -161
- package/src/omni-scoped.backend.ts +110 -110
- package/src/omni-scoped.repository.ts +34 -34
- package/src/omni-scoped.service.ts +338 -338
- package/src/omnikernel.diagnostics.ts +83 -83
- package/src/omnikernel.module.ts +97 -97
- package/src/omnikernel.query.service.ts +108 -108
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import { describe, expect, it, jest } from "@jest/globals";
|
|
2
|
-
|
|
3
|
-
import { canonicalOmniRelationKinds, createOmniRelationKindContract } from '../omni-relation-kind.contract.js';
|
|
4
|
-
import { normalizeOmniKernelRegistrationOptions, OmniScopeContext } from '../omni-scope.js';
|
|
5
|
-
import { OmniScopedRepository } from '../omni-scoped.repository.js';
|
|
6
|
-
|
|
7
|
-
describe("Omni scoped substrate", () => {
|
|
8
|
-
it("derives a trusted scope, scopes cache keys, and rejects invalid registration", () => {
|
|
9
|
-
const options = normalizeOmniKernelRegistrationOptions({
|
|
10
|
-
dbConnection: "default",
|
|
11
|
-
defaultScopeId: "fallback",
|
|
12
|
-
resolveScope: (request) =>
|
|
13
|
-
(request as { authenticatedScope?: string }).authenticatedScope,
|
|
14
|
-
relationKinds: ["blocks"],
|
|
15
|
-
deletion: { record: "tombstone" },
|
|
16
|
-
});
|
|
17
|
-
const scope = new OmniScopeContext(
|
|
18
|
-
{ req: { authenticatedScope: "scope-alpha" } },
|
|
19
|
-
options,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
expect(scope.scopeId).toBe("scope-alpha");
|
|
23
|
-
expect(scope.cacheKey("record-1")).toBe("scope-alpha:record-1");
|
|
24
|
-
expect(options.deletion.document).toBe("tombstone");
|
|
25
|
-
expect(() => new OmniScopeContext({ req: {} }, options)).toThrow(
|
|
26
|
-
"unavailable",
|
|
27
|
-
);
|
|
28
|
-
expect(() =>
|
|
29
|
-
normalizeOmniKernelRegistrationOptions({
|
|
30
|
-
dbConnection: "",
|
|
31
|
-
}),
|
|
32
|
-
).toThrow("database connection");
|
|
33
|
-
expect(() =>
|
|
34
|
-
normalizeOmniKernelRegistrationOptions({
|
|
35
|
-
dbConnection: "default",
|
|
36
|
-
deletion: { record: "erase" as never },
|
|
37
|
-
}),
|
|
38
|
-
).toThrow("must be hard or tombstone");
|
|
39
|
-
expect(() =>
|
|
40
|
-
normalizeOmniKernelRegistrationOptions({
|
|
41
|
-
dbConnection: "default",
|
|
42
|
-
deletion: { records: "tombstone" } as never,
|
|
43
|
-
}),
|
|
44
|
-
).toThrow("Unknown OmniKernel deletion policy resource");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("keeps canonical relation kinds stable while validating registered extensions", () => {
|
|
48
|
-
const contract = createOmniRelationKindContract(["blocks"]);
|
|
49
|
-
|
|
50
|
-
expect(canonicalOmniRelationKinds).toContain("contains");
|
|
51
|
-
expect(contract.has("blocks")).toBe(true);
|
|
52
|
-
expect(() => contract.assert("unknown")).toThrow("not registered");
|
|
53
|
-
expect(() => createOmniRelationKindContract(["not portable!"])).toThrow(
|
|
54
|
-
"lowercase letters",
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("adds scope to lower-level repository queries and refuses caller scope input", async () => {
|
|
59
|
-
const repository = {
|
|
60
|
-
find: jest.fn(async () => []),
|
|
61
|
-
findOne: jest.fn(async () => null),
|
|
62
|
-
};
|
|
63
|
-
const scoped = new OmniScopedRepository(repository as never, {
|
|
64
|
-
scopeId: "scope-alpha",
|
|
65
|
-
cacheKey: (key: string) => key,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
await scoped.findOneByGuid("record-1");
|
|
69
|
-
await scoped.find({ title: "Scoped record" } as never);
|
|
70
|
-
|
|
71
|
-
expect(repository.findOne).toHaveBeenCalledWith({
|
|
72
|
-
where: { guid: "record-1", scopeId: "scope-alpha" },
|
|
73
|
-
});
|
|
74
|
-
expect(repository.find).toHaveBeenCalledWith({
|
|
75
|
-
where: { title: "Scoped record", scopeId: "scope-alpha" },
|
|
76
|
-
});
|
|
77
|
-
expect(() => scoped.where({ scopeId: "scope-bravo" } as never)).toThrow(
|
|
78
|
-
"derived from server context",
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
1
|
+
import { describe, expect, it, jest } from "@jest/globals";
|
|
2
|
+
|
|
3
|
+
import { canonicalOmniRelationKinds, createOmniRelationKindContract } from '../omni-relation-kind.contract.js';
|
|
4
|
+
import { normalizeOmniKernelRegistrationOptions, OmniScopeContext } from '../omni-scope.js';
|
|
5
|
+
import { OmniScopedRepository } from '../omni-scoped.repository.js';
|
|
6
|
+
|
|
7
|
+
describe("Omni scoped substrate", () => {
|
|
8
|
+
it("derives a trusted scope, scopes cache keys, and rejects invalid registration", () => {
|
|
9
|
+
const options = normalizeOmniKernelRegistrationOptions({
|
|
10
|
+
dbConnection: "default",
|
|
11
|
+
defaultScopeId: "fallback",
|
|
12
|
+
resolveScope: (request) =>
|
|
13
|
+
(request as { authenticatedScope?: string }).authenticatedScope,
|
|
14
|
+
relationKinds: ["blocks"],
|
|
15
|
+
deletion: { record: "tombstone" },
|
|
16
|
+
});
|
|
17
|
+
const scope = new OmniScopeContext(
|
|
18
|
+
{ req: { authenticatedScope: "scope-alpha" } },
|
|
19
|
+
options,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(scope.scopeId).toBe("scope-alpha");
|
|
23
|
+
expect(scope.cacheKey("record-1")).toBe("scope-alpha:record-1");
|
|
24
|
+
expect(options.deletion.document).toBe("tombstone");
|
|
25
|
+
expect(() => new OmniScopeContext({ req: {} }, options)).toThrow(
|
|
26
|
+
"unavailable",
|
|
27
|
+
);
|
|
28
|
+
expect(() =>
|
|
29
|
+
normalizeOmniKernelRegistrationOptions({
|
|
30
|
+
dbConnection: "",
|
|
31
|
+
}),
|
|
32
|
+
).toThrow("database connection");
|
|
33
|
+
expect(() =>
|
|
34
|
+
normalizeOmniKernelRegistrationOptions({
|
|
35
|
+
dbConnection: "default",
|
|
36
|
+
deletion: { record: "erase" as never },
|
|
37
|
+
}),
|
|
38
|
+
).toThrow("must be hard or tombstone");
|
|
39
|
+
expect(() =>
|
|
40
|
+
normalizeOmniKernelRegistrationOptions({
|
|
41
|
+
dbConnection: "default",
|
|
42
|
+
deletion: { records: "tombstone" } as never,
|
|
43
|
+
}),
|
|
44
|
+
).toThrow("Unknown OmniKernel deletion policy resource");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("keeps canonical relation kinds stable while validating registered extensions", () => {
|
|
48
|
+
const contract = createOmniRelationKindContract(["blocks"]);
|
|
49
|
+
|
|
50
|
+
expect(canonicalOmniRelationKinds).toContain("contains");
|
|
51
|
+
expect(contract.has("blocks")).toBe(true);
|
|
52
|
+
expect(() => contract.assert("unknown")).toThrow("not registered");
|
|
53
|
+
expect(() => createOmniRelationKindContract(["not portable!"])).toThrow(
|
|
54
|
+
"lowercase letters",
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("adds scope to lower-level repository queries and refuses caller scope input", async () => {
|
|
59
|
+
const repository = {
|
|
60
|
+
find: jest.fn(async () => []),
|
|
61
|
+
findOne: jest.fn(async () => null),
|
|
62
|
+
};
|
|
63
|
+
const scoped = new OmniScopedRepository(repository as never, {
|
|
64
|
+
scopeId: "scope-alpha",
|
|
65
|
+
cacheKey: (key: string) => key,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await scoped.findOneByGuid("record-1");
|
|
69
|
+
await scoped.find({ title: "Scoped record" } as never);
|
|
70
|
+
|
|
71
|
+
expect(repository.findOne).toHaveBeenCalledWith({
|
|
72
|
+
where: { guid: "record-1", scopeId: "scope-alpha" },
|
|
73
|
+
});
|
|
74
|
+
expect(repository.find).toHaveBeenCalledWith({
|
|
75
|
+
where: { title: "Scoped record", scopeId: "scope-alpha" },
|
|
76
|
+
});
|
|
77
|
+
expect(() => scoped.where({ scopeId: "scope-bravo" } as never)).toThrow(
|
|
78
|
+
"derived from server context",
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { describe, expect, it } from "@jest/globals";
|
|
2
|
-
import { EventEmitter2 } from "@nestjs/event-emitter";
|
|
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 { OmniDocumentEntity } from '../omni-document.entity.js';
|
|
9
|
-
import { OmniExternalRefEntity } from '../base/omni-external-ref.entity.js';
|
|
10
|
-
import { OmniExternalRefService } from '../omni-external-ref.service.js';
|
|
11
|
-
import { OmniRelationService } from '../omni-relation.service.js';
|
|
12
|
-
import { OmniScopedService } from '../omni-scoped.service.js';
|
|
13
|
-
import { normalizeOmniKernelRegistrationOptions } from '../omni-scope.js';
|
|
14
|
-
import { omniScopedBackendProvidersFactory, omniBackendServiceToken } from '../omni-scoped.backend.js';
|
|
15
|
-
import { omniNamedBackendProvidersFactory } from '../omni-named.backend.js';
|
|
16
|
-
import { omniRecordBackendProvidersFactory } from '../omni-record.backend.js';
|
|
17
|
-
import { omniRelationBackendProvidersFactory } from '../omni-relation.backend.js';
|
|
18
|
-
import { omniCollectionBackendProvidersFactory } from '../omni-collection.backend.js';
|
|
19
|
-
import { omniDocumentBackendProvidersFactory } from '../omni-document.backend.js';
|
|
20
|
-
import { omniExternalRefBackendProvidersFactory } from '../omni-external-ref.backend.js';
|
|
21
|
-
|
|
22
|
-
const scope = {
|
|
23
|
-
scopeId: "scope-alpha",
|
|
24
|
-
cacheKey: (key: string) => `scope-alpha:${key}`,
|
|
25
|
-
};
|
|
26
|
-
const options = normalizeOmniKernelRegistrationOptions({
|
|
27
|
-
dbConnection: "default",
|
|
28
|
-
relationKinds: ["blocks"],
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const repositoryFor = (target: unknown) => ({ target });
|
|
32
|
-
|
|
33
|
-
const factoryProvider = (providers: unknown[]) =>
|
|
34
|
-
providers.find(
|
|
35
|
-
(provider) =>
|
|
36
|
-
typeof provider === "object" &&
|
|
37
|
-
provider !== null &&
|
|
38
|
-
"useFactory" in provider,
|
|
39
|
-
) as { useFactory: (...dependencies: unknown[]) => unknown };
|
|
40
|
-
|
|
41
|
-
describe("Omni scoped backend providers", () => {
|
|
42
|
-
it("builds request-scoped generic services for every ordinary resource", () => {
|
|
43
|
-
const cases = [
|
|
44
|
-
[omniNamedBackendProvidersFactory, OmniNamedEntity],
|
|
45
|
-
[omniRecordBackendProvidersFactory, OmniRecordEntity],
|
|
46
|
-
[omniCollectionBackendProvidersFactory, OmniCollectionEntity],
|
|
47
|
-
[omniDocumentBackendProvidersFactory, OmniDocumentEntity],
|
|
48
|
-
] as const;
|
|
49
|
-
|
|
50
|
-
for (const [factory, entity] of cases) {
|
|
51
|
-
const backend = factory("default");
|
|
52
|
-
const service = factoryProvider(backend.providers).useFactory(
|
|
53
|
-
repositoryFor(entity),
|
|
54
|
-
scope,
|
|
55
|
-
options,
|
|
56
|
-
);
|
|
57
|
-
expect(service).toBeInstanceOf(OmniScopedService);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("builds the relation service with a scoped record dependency", () => {
|
|
62
|
-
const backend = omniRelationBackendProvidersFactory("default");
|
|
63
|
-
const service = factoryProvider(backend.providers).useFactory(
|
|
64
|
-
repositoryFor(OmniRelationEntity),
|
|
65
|
-
scope,
|
|
66
|
-
options,
|
|
67
|
-
repositoryFor(OmniRecordEntity),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
expect(service).toBeInstanceOf(OmniRelationService);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("builds the external-reference service and exposes its service alias", () => {
|
|
74
|
-
const backend = omniExternalRefBackendProvidersFactory("default");
|
|
75
|
-
const service = factoryProvider(backend.providers).useFactory(
|
|
76
|
-
repositoryFor(OmniExternalRefEntity),
|
|
77
|
-
scope,
|
|
78
|
-
options,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(service).toBeInstanceOf(OmniExternalRefService);
|
|
82
|
-
expect(backend.providers).toEqual(
|
|
83
|
-
expect.arrayContaining([
|
|
84
|
-
expect.objectContaining({ provide: OmniExternalRefService }),
|
|
85
|
-
]),
|
|
86
|
-
);
|
|
87
|
-
expect(omniBackendServiceToken(OmniExternalRefService)).toBe(
|
|
88
|
-
"OmniExternalRefService",
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("uses the scope-prefixed cache key in the generated request loader", () => {
|
|
93
|
-
const backend = omniScopedBackendProvidersFactory({
|
|
94
|
-
entityModel: OmniRecordEntity,
|
|
95
|
-
dbConnection: "default",
|
|
96
|
-
createService: (repository, resolvedScope) =>
|
|
97
|
-
new OmniScopedService(repository, resolvedScope),
|
|
98
|
-
});
|
|
99
|
-
const loaderProvider = backend.providers.find(
|
|
100
|
-
(provider) =>
|
|
101
|
-
typeof provider === "object" &&
|
|
102
|
-
provider !== null &&
|
|
103
|
-
"useFactory" in provider &&
|
|
104
|
-
provider !== factoryProvider(backend.providers),
|
|
105
|
-
) as { useFactory: (...dependencies: unknown[]) => unknown };
|
|
106
|
-
const service = new OmniScopedService(
|
|
107
|
-
repositoryFor(OmniRecordEntity) as never,
|
|
108
|
-
scope,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(
|
|
112
|
-
loaderProvider.useFactory(service, scope, new EventEmitter2()),
|
|
113
|
-
).toBeDefined();
|
|
114
|
-
});
|
|
115
|
-
});
|
|
1
|
+
import { describe, expect, it } from "@jest/globals";
|
|
2
|
+
import { EventEmitter2 } from "@nestjs/event-emitter";
|
|
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 { OmniDocumentEntity } from '../omni-document.entity.js';
|
|
9
|
+
import { OmniExternalRefEntity } from '../base/omni-external-ref.entity.js';
|
|
10
|
+
import { OmniExternalRefService } from '../omni-external-ref.service.js';
|
|
11
|
+
import { OmniRelationService } from '../omni-relation.service.js';
|
|
12
|
+
import { OmniScopedService } from '../omni-scoped.service.js';
|
|
13
|
+
import { normalizeOmniKernelRegistrationOptions } from '../omni-scope.js';
|
|
14
|
+
import { omniScopedBackendProvidersFactory, omniBackendServiceToken } from '../omni-scoped.backend.js';
|
|
15
|
+
import { omniNamedBackendProvidersFactory } from '../omni-named.backend.js';
|
|
16
|
+
import { omniRecordBackendProvidersFactory } from '../omni-record.backend.js';
|
|
17
|
+
import { omniRelationBackendProvidersFactory } from '../omni-relation.backend.js';
|
|
18
|
+
import { omniCollectionBackendProvidersFactory } from '../omni-collection.backend.js';
|
|
19
|
+
import { omniDocumentBackendProvidersFactory } from '../omni-document.backend.js';
|
|
20
|
+
import { omniExternalRefBackendProvidersFactory } from '../omni-external-ref.backend.js';
|
|
21
|
+
|
|
22
|
+
const scope = {
|
|
23
|
+
scopeId: "scope-alpha",
|
|
24
|
+
cacheKey: (key: string) => `scope-alpha:${key}`,
|
|
25
|
+
};
|
|
26
|
+
const options = normalizeOmniKernelRegistrationOptions({
|
|
27
|
+
dbConnection: "default",
|
|
28
|
+
relationKinds: ["blocks"],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const repositoryFor = (target: unknown) => ({ target });
|
|
32
|
+
|
|
33
|
+
const factoryProvider = (providers: unknown[]) =>
|
|
34
|
+
providers.find(
|
|
35
|
+
(provider) =>
|
|
36
|
+
typeof provider === "object" &&
|
|
37
|
+
provider !== null &&
|
|
38
|
+
"useFactory" in provider,
|
|
39
|
+
) as { useFactory: (...dependencies: unknown[]) => unknown };
|
|
40
|
+
|
|
41
|
+
describe("Omni scoped backend providers", () => {
|
|
42
|
+
it("builds request-scoped generic services for every ordinary resource", () => {
|
|
43
|
+
const cases = [
|
|
44
|
+
[omniNamedBackendProvidersFactory, OmniNamedEntity],
|
|
45
|
+
[omniRecordBackendProvidersFactory, OmniRecordEntity],
|
|
46
|
+
[omniCollectionBackendProvidersFactory, OmniCollectionEntity],
|
|
47
|
+
[omniDocumentBackendProvidersFactory, OmniDocumentEntity],
|
|
48
|
+
] as const;
|
|
49
|
+
|
|
50
|
+
for (const [factory, entity] of cases) {
|
|
51
|
+
const backend = factory("default");
|
|
52
|
+
const service = factoryProvider(backend.providers).useFactory(
|
|
53
|
+
repositoryFor(entity),
|
|
54
|
+
scope,
|
|
55
|
+
options,
|
|
56
|
+
);
|
|
57
|
+
expect(service).toBeInstanceOf(OmniScopedService);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("builds the relation service with a scoped record dependency", () => {
|
|
62
|
+
const backend = omniRelationBackendProvidersFactory("default");
|
|
63
|
+
const service = factoryProvider(backend.providers).useFactory(
|
|
64
|
+
repositoryFor(OmniRelationEntity),
|
|
65
|
+
scope,
|
|
66
|
+
options,
|
|
67
|
+
repositoryFor(OmniRecordEntity),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(service).toBeInstanceOf(OmniRelationService);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("builds the external-reference service and exposes its service alias", () => {
|
|
74
|
+
const backend = omniExternalRefBackendProvidersFactory("default");
|
|
75
|
+
const service = factoryProvider(backend.providers).useFactory(
|
|
76
|
+
repositoryFor(OmniExternalRefEntity),
|
|
77
|
+
scope,
|
|
78
|
+
options,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(service).toBeInstanceOf(OmniExternalRefService);
|
|
82
|
+
expect(backend.providers).toEqual(
|
|
83
|
+
expect.arrayContaining([
|
|
84
|
+
expect.objectContaining({ provide: OmniExternalRefService }),
|
|
85
|
+
]),
|
|
86
|
+
);
|
|
87
|
+
expect(omniBackendServiceToken(OmniExternalRefService)).toBe(
|
|
88
|
+
"OmniExternalRefService",
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("uses the scope-prefixed cache key in the generated request loader", () => {
|
|
93
|
+
const backend = omniScopedBackendProvidersFactory({
|
|
94
|
+
entityModel: OmniRecordEntity,
|
|
95
|
+
dbConnection: "default",
|
|
96
|
+
createService: (repository, resolvedScope) =>
|
|
97
|
+
new OmniScopedService(repository, resolvedScope),
|
|
98
|
+
});
|
|
99
|
+
const loaderProvider = backend.providers.find(
|
|
100
|
+
(provider) =>
|
|
101
|
+
typeof provider === "object" &&
|
|
102
|
+
provider !== null &&
|
|
103
|
+
"useFactory" in provider &&
|
|
104
|
+
provider !== factoryProvider(backend.providers),
|
|
105
|
+
) as { useFactory: (...dependencies: unknown[]) => unknown };
|
|
106
|
+
const service = new OmniScopedService(
|
|
107
|
+
repositoryFor(OmniRecordEntity) as never,
|
|
108
|
+
scope,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
expect(
|
|
112
|
+
loaderProvider.useFactory(service, scope, new EventEmitter2()),
|
|
113
|
+
).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
});
|