@nest-yalc-2/omnikernel-module 2.2.1 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +22 -14
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-yalc-2/omnikernel-module",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Foundational OmniKernel persistence module for nestjs-yalc",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,27 +16,35 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@nest-yalc-2/crud-gen": "^2.2.
|
|
20
|
-
"@nest-yalc-2/data-loader": "^2.2.
|
|
21
|
-
"@nest-yalc-2/event-manager": "^2.2.
|
|
22
|
-
"@nest-yalc-2/graphql": "^2.2.
|
|
23
|
-
"@nest-yalc-2/types": "
|
|
24
|
-
"@nest-yalc-2/utils": "^2.2.
|
|
19
|
+
"@nest-yalc-2/crud-gen": "^2.2.4",
|
|
20
|
+
"@nest-yalc-2/data-loader": "^2.2.4",
|
|
21
|
+
"@nest-yalc-2/event-manager": "^2.2.4",
|
|
22
|
+
"@nest-yalc-2/graphql": "^2.2.4",
|
|
23
|
+
"@nest-yalc-2/types": "*",
|
|
24
|
+
"@nest-yalc-2/utils": "^2.2.4",
|
|
25
25
|
"tslib": "^2.8.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@nestjs/common": "^
|
|
29
|
-
"@nestjs/core": "^
|
|
30
|
-
"@nestjs/event-emitter": "^
|
|
31
|
-
"@nestjs/graphql": "^
|
|
32
|
-
"@nestjs/typeorm": "^
|
|
28
|
+
"@nestjs/common": "^12.0.0",
|
|
29
|
+
"@nestjs/core": "^12.0.0",
|
|
30
|
+
"@nestjs/event-emitter": "^12.0.0",
|
|
31
|
+
"@nestjs/graphql": "^14.0.0",
|
|
32
|
+
"@nestjs/typeorm": "^12.0.0",
|
|
33
33
|
"class-transformer": "^0.5.1",
|
|
34
34
|
"class-validator": "^0.15.1",
|
|
35
|
-
"graphql": "^16.
|
|
35
|
+
"graphql": "^16.14.2",
|
|
36
36
|
"graphql-type-json": "^0.3.2",
|
|
37
37
|
"reflect-metadata": "^0.2.2",
|
|
38
|
-
"typeorm": "^0.3.
|
|
38
|
+
"typeorm": "^0.3.30"
|
|
39
39
|
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"nestjs",
|
|
42
|
+
"nestjs-yalc",
|
|
43
|
+
"yalc",
|
|
44
|
+
"omnikernel-module",
|
|
45
|
+
"framework",
|
|
46
|
+
"utility"
|
|
47
|
+
],
|
|
40
48
|
"repository": {
|
|
41
49
|
"type": "git",
|
|
42
50
|
"url": "git+https://github.com/Nek97/nestjs-yalc.git"
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { getMetadataArgsStorage } from 'typeorm';
|
|
3
|
-
|
|
4
|
-
import { OmniRecordEntity } from '../base/omni-record.entity.js';
|
|
5
|
-
import { OmniCollectionEntity } from '../omni-collection.entity.js';
|
|
6
|
-
import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
|
|
7
|
-
|
|
8
|
-
describe('OmniCollectionEntity', () => {
|
|
9
|
-
it('extends OmniRecordEntity', () => {
|
|
10
|
-
expect(new OmniCollectionEntity()).toBeInstanceOf(OmniRecordEntity);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('stores collections as child records in the omni-record table', () => {
|
|
14
|
-
const metadata = getMetadataArgsStorage();
|
|
15
|
-
const recordTable = metadata.tables.find(
|
|
16
|
-
(item) => item.target === OmniRecordEntity,
|
|
17
|
-
);
|
|
18
|
-
const collectionTable = metadata.tables.find(
|
|
19
|
-
(item) => item.target === OmniCollectionEntity,
|
|
20
|
-
);
|
|
21
|
-
const inheritance = metadata.inheritances.find(
|
|
22
|
-
(item) => item.target === OmniRecordEntity,
|
|
23
|
-
);
|
|
24
|
-
const entityColumns = metadata.columns
|
|
25
|
-
.filter((item) => item.target === OmniCollectionEntity)
|
|
26
|
-
.map((item) => item.propertyName);
|
|
27
|
-
|
|
28
|
-
expect(recordTable?.name).toBe('omni-record');
|
|
29
|
-
expect(collectionTable?.type).toBe('entity-child');
|
|
30
|
-
expect(inheritance?.column).toMatchObject({ name: 'recordType' });
|
|
31
|
-
expect(entityColumns).toEqual(
|
|
32
|
-
expect.arrayContaining(['collectionKind', 'summary']),
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('defaults the base record kind to collection in the class instance', () => {
|
|
37
|
-
const entity = new OmniCollectionEntity();
|
|
38
|
-
|
|
39
|
-
expect(entity.kind).toBe(OmniCollectionKind.Collection);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('allows explicit collection subtypes while keeping the base record kind stable', () => {
|
|
43
|
-
const entity = new OmniCollectionEntity();
|
|
44
|
-
entity.collectionKind = OmniCollectionKind.Folder;
|
|
45
|
-
|
|
46
|
-
expect(entity.kind).toBe(OmniCollectionKind.Collection);
|
|
47
|
-
expect(entity.collectionKind).toBe(OmniCollectionKind.Folder);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { getMetadataArgsStorage } from 'typeorm';
|
|
3
|
+
|
|
4
|
+
import { OmniRecordEntity } from '../base/omni-record.entity.js';
|
|
5
|
+
import { OmniCollectionEntity } from '../omni-collection.entity.js';
|
|
6
|
+
import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
|
|
7
|
+
|
|
8
|
+
describe('OmniCollectionEntity', () => {
|
|
9
|
+
it('extends OmniRecordEntity', () => {
|
|
10
|
+
expect(new OmniCollectionEntity()).toBeInstanceOf(OmniRecordEntity);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('stores collections as child records in the omni-record table', () => {
|
|
14
|
+
const metadata = getMetadataArgsStorage();
|
|
15
|
+
const recordTable = metadata.tables.find(
|
|
16
|
+
(item) => item.target === OmniRecordEntity,
|
|
17
|
+
);
|
|
18
|
+
const collectionTable = metadata.tables.find(
|
|
19
|
+
(item) => item.target === OmniCollectionEntity,
|
|
20
|
+
);
|
|
21
|
+
const inheritance = metadata.inheritances.find(
|
|
22
|
+
(item) => item.target === OmniRecordEntity,
|
|
23
|
+
);
|
|
24
|
+
const entityColumns = metadata.columns
|
|
25
|
+
.filter((item) => item.target === OmniCollectionEntity)
|
|
26
|
+
.map((item) => item.propertyName);
|
|
27
|
+
|
|
28
|
+
expect(recordTable?.name).toBe('omni-record');
|
|
29
|
+
expect(collectionTable?.type).toBe('entity-child');
|
|
30
|
+
expect(inheritance?.column).toMatchObject({ name: 'recordType' });
|
|
31
|
+
expect(entityColumns).toEqual(
|
|
32
|
+
expect.arrayContaining(['collectionKind', 'summary']),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('defaults the base record kind to collection in the class instance', () => {
|
|
37
|
+
const entity = new OmniCollectionEntity();
|
|
38
|
+
|
|
39
|
+
expect(entity.kind).toBe(OmniCollectionKind.Collection);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('allows explicit collection subtypes while keeping the base record kind stable', () => {
|
|
43
|
+
const entity = new OmniCollectionEntity();
|
|
44
|
+
entity.collectionKind = OmniCollectionKind.Folder;
|
|
45
|
+
|
|
46
|
+
expect(entity.kind).toBe(OmniCollectionKind.Collection);
|
|
47
|
+
expect(entity.collectionKind).toBe(OmniCollectionKind.Folder);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { describe, expect, it, jest } from '@jest/globals';
|
|
2
|
-
|
|
3
|
-
import { OmniCollectionService } from '../omni-collection.service.js';
|
|
4
|
-
import { OmniCollectionEntity } from '../omni-collection.entity.js';
|
|
5
|
-
import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
|
|
6
|
-
|
|
7
|
-
const createRepositoryPair = () => {
|
|
8
|
-
const readRepository = {
|
|
9
|
-
target: OmniCollectionEntity,
|
|
10
|
-
findOneOrFail: jest.fn(),
|
|
11
|
-
getId: jest.fn((entity: OmniCollectionEntity) => ({ guid: entity.guid })),
|
|
12
|
-
};
|
|
13
|
-
const writeRepository = {
|
|
14
|
-
target: OmniCollectionEntity,
|
|
15
|
-
create: jest.fn((input: unknown) => input),
|
|
16
|
-
insert: jest.fn(async () => ({
|
|
17
|
-
identifiers: [{ guid: 'aaaaaaaa-1111-1111-1111-111111111111' }],
|
|
18
|
-
})),
|
|
19
|
-
update: jest.fn(async () => ({ affected: 1 })),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return { readRepository, writeRepository };
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
describe('OmniCollectionService', () => {
|
|
26
|
-
it('forces the base record kind during createEntity', async () => {
|
|
27
|
-
const { readRepository, writeRepository } = createRepositoryPair();
|
|
28
|
-
const service = new OmniCollectionService(
|
|
29
|
-
readRepository as never,
|
|
30
|
-
writeRepository as never,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
await service.createEntity(
|
|
34
|
-
{
|
|
35
|
-
guid: 'aaaaaaaa-1111-1111-1111-111111111111',
|
|
36
|
-
title: 'Collection',
|
|
37
|
-
kind: 'unexpected-kind',
|
|
38
|
-
collectionKind: OmniCollectionKind.Folder,
|
|
39
|
-
},
|
|
40
|
-
undefined,
|
|
41
|
-
false,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
expect(writeRepository.insert).toHaveBeenCalledWith(
|
|
45
|
-
expect.objectContaining({
|
|
46
|
-
kind: OmniCollectionKind.Collection,
|
|
47
|
-
collectionKind: OmniCollectionKind.Folder,
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('forces the base record kind during updateEntity', async () => {
|
|
53
|
-
const { readRepository, writeRepository } = createRepositoryPair();
|
|
54
|
-
const service = new OmniCollectionService(
|
|
55
|
-
readRepository as never,
|
|
56
|
-
writeRepository as never,
|
|
57
|
-
);
|
|
58
|
-
(service as any).validateConditions = jest.fn(async () => ({
|
|
59
|
-
guid: 'aaaaaaaa-1111-1111-1111-111111111111',
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
await service.updateEntity(
|
|
63
|
-
{ guid: 'aaaaaaaa-1111-1111-1111-111111111111' },
|
|
64
|
-
{
|
|
65
|
-
kind: 'unexpected-kind',
|
|
66
|
-
collectionKind: OmniCollectionKind.Folder,
|
|
67
|
-
},
|
|
68
|
-
undefined,
|
|
69
|
-
false,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
expect(writeRepository.update).toHaveBeenCalledWith(
|
|
73
|
-
expect.objectContaining({
|
|
74
|
-
guid: 'aaaaaaaa-1111-1111-1111-111111111111',
|
|
75
|
-
kind: OmniCollectionKind.Collection,
|
|
76
|
-
}),
|
|
77
|
-
expect.objectContaining({
|
|
78
|
-
kind: OmniCollectionKind.Collection,
|
|
79
|
-
collectionKind: OmniCollectionKind.Folder,
|
|
80
|
-
}),
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
1
|
+
import { describe, expect, it, jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
import { OmniCollectionService } from '../omni-collection.service.js';
|
|
4
|
+
import { OmniCollectionEntity } from '../omni-collection.entity.js';
|
|
5
|
+
import { OmniCollectionKind } from '../omni-collection-kind.enum.js';
|
|
6
|
+
|
|
7
|
+
const createRepositoryPair = () => {
|
|
8
|
+
const readRepository = {
|
|
9
|
+
target: OmniCollectionEntity,
|
|
10
|
+
findOneOrFail: jest.fn(),
|
|
11
|
+
getId: jest.fn((entity: OmniCollectionEntity) => ({ guid: entity.guid })),
|
|
12
|
+
};
|
|
13
|
+
const writeRepository = {
|
|
14
|
+
target: OmniCollectionEntity,
|
|
15
|
+
create: jest.fn((input: unknown) => input),
|
|
16
|
+
insert: jest.fn(async () => ({
|
|
17
|
+
identifiers: [{ guid: 'aaaaaaaa-1111-1111-1111-111111111111' }],
|
|
18
|
+
})),
|
|
19
|
+
update: jest.fn(async () => ({ affected: 1 })),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return { readRepository, writeRepository };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('OmniCollectionService', () => {
|
|
26
|
+
it('forces the base record kind during createEntity', async () => {
|
|
27
|
+
const { readRepository, writeRepository } = createRepositoryPair();
|
|
28
|
+
const service = new OmniCollectionService(
|
|
29
|
+
readRepository as never,
|
|
30
|
+
writeRepository as never,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await service.createEntity(
|
|
34
|
+
{
|
|
35
|
+
guid: 'aaaaaaaa-1111-1111-1111-111111111111',
|
|
36
|
+
title: 'Collection',
|
|
37
|
+
kind: 'unexpected-kind',
|
|
38
|
+
collectionKind: OmniCollectionKind.Folder,
|
|
39
|
+
},
|
|
40
|
+
undefined,
|
|
41
|
+
false,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(writeRepository.insert).toHaveBeenCalledWith(
|
|
45
|
+
expect.objectContaining({
|
|
46
|
+
kind: OmniCollectionKind.Collection,
|
|
47
|
+
collectionKind: OmniCollectionKind.Folder,
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('forces the base record kind during updateEntity', async () => {
|
|
53
|
+
const { readRepository, writeRepository } = createRepositoryPair();
|
|
54
|
+
const service = new OmniCollectionService(
|
|
55
|
+
readRepository as never,
|
|
56
|
+
writeRepository as never,
|
|
57
|
+
);
|
|
58
|
+
(service as any).validateConditions = jest.fn(async () => ({
|
|
59
|
+
guid: 'aaaaaaaa-1111-1111-1111-111111111111',
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
await service.updateEntity(
|
|
63
|
+
{ guid: 'aaaaaaaa-1111-1111-1111-111111111111' },
|
|
64
|
+
{
|
|
65
|
+
kind: 'unexpected-kind',
|
|
66
|
+
collectionKind: OmniCollectionKind.Folder,
|
|
67
|
+
},
|
|
68
|
+
undefined,
|
|
69
|
+
false,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(writeRepository.update).toHaveBeenCalledWith(
|
|
73
|
+
expect.objectContaining({
|
|
74
|
+
guid: 'aaaaaaaa-1111-1111-1111-111111111111',
|
|
75
|
+
kind: OmniCollectionKind.Collection,
|
|
76
|
+
}),
|
|
77
|
+
expect.objectContaining({
|
|
78
|
+
kind: OmniCollectionKind.Collection,
|
|
79
|
+
collectionKind: OmniCollectionKind.Folder,
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { getMetadataArgsStorage } from 'typeorm';
|
|
3
|
-
|
|
4
|
-
import { OmniRecordEntity } from '../base/omni-record.entity.js';
|
|
5
|
-
import { OmniDocumentEntity } from '../omni-document.entity.js';
|
|
6
|
-
import { OmniDocumentKind } from '../omni-document-kind.enum.js';
|
|
7
|
-
|
|
8
|
-
describe('OmniDocumentEntity', () => {
|
|
9
|
-
it('extends OmniRecordEntity', () => {
|
|
10
|
-
expect(new OmniDocumentEntity()).toBeInstanceOf(OmniRecordEntity);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('stores documents as child records in the omni-record table', () => {
|
|
14
|
-
const metadata = getMetadataArgsStorage();
|
|
15
|
-
const recordTable = metadata.tables.find(
|
|
16
|
-
(item) => item.target === OmniRecordEntity,
|
|
17
|
-
);
|
|
18
|
-
const documentTable = metadata.tables.find(
|
|
19
|
-
(item) => item.target === OmniDocumentEntity,
|
|
20
|
-
);
|
|
21
|
-
const inheritance = metadata.inheritances.find(
|
|
22
|
-
(item) => item.target === OmniRecordEntity,
|
|
23
|
-
);
|
|
24
|
-
const entityColumns = metadata.columns
|
|
25
|
-
.filter((item) => item.target === OmniDocumentEntity)
|
|
26
|
-
.map((item) => item.propertyName);
|
|
27
|
-
|
|
28
|
-
expect(recordTable?.name).toBe('omni-record');
|
|
29
|
-
expect(documentTable?.type).toBe('entity-child');
|
|
30
|
-
expect(inheritance?.column).toMatchObject({ name: 'recordType' });
|
|
31
|
-
expect(entityColumns).toEqual(
|
|
32
|
-
expect.arrayContaining([
|
|
33
|
-
'documentKind',
|
|
34
|
-
'content',
|
|
35
|
-
'contentMimeType',
|
|
36
|
-
'sourceUrl',
|
|
37
|
-
'publishedAt',
|
|
38
|
-
]),
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('defaults the base record kind to document in the class instance', () => {
|
|
43
|
-
const entity = new OmniDocumentEntity();
|
|
44
|
-
|
|
45
|
-
expect(entity.kind).toBe(OmniDocumentKind.Document);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('allows explicit document subtypes while keeping the base record kind stable', () => {
|
|
49
|
-
const entity = new OmniDocumentEntity();
|
|
50
|
-
entity.documentKind = OmniDocumentKind.Note;
|
|
51
|
-
|
|
52
|
-
expect(entity.kind).toBe(OmniDocumentKind.Document);
|
|
53
|
-
expect(entity.documentKind).toBe(OmniDocumentKind.Note);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { getMetadataArgsStorage } from 'typeorm';
|
|
3
|
+
|
|
4
|
+
import { OmniRecordEntity } from '../base/omni-record.entity.js';
|
|
5
|
+
import { OmniDocumentEntity } from '../omni-document.entity.js';
|
|
6
|
+
import { OmniDocumentKind } from '../omni-document-kind.enum.js';
|
|
7
|
+
|
|
8
|
+
describe('OmniDocumentEntity', () => {
|
|
9
|
+
it('extends OmniRecordEntity', () => {
|
|
10
|
+
expect(new OmniDocumentEntity()).toBeInstanceOf(OmniRecordEntity);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('stores documents as child records in the omni-record table', () => {
|
|
14
|
+
const metadata = getMetadataArgsStorage();
|
|
15
|
+
const recordTable = metadata.tables.find(
|
|
16
|
+
(item) => item.target === OmniRecordEntity,
|
|
17
|
+
);
|
|
18
|
+
const documentTable = metadata.tables.find(
|
|
19
|
+
(item) => item.target === OmniDocumentEntity,
|
|
20
|
+
);
|
|
21
|
+
const inheritance = metadata.inheritances.find(
|
|
22
|
+
(item) => item.target === OmniRecordEntity,
|
|
23
|
+
);
|
|
24
|
+
const entityColumns = metadata.columns
|
|
25
|
+
.filter((item) => item.target === OmniDocumentEntity)
|
|
26
|
+
.map((item) => item.propertyName);
|
|
27
|
+
|
|
28
|
+
expect(recordTable?.name).toBe('omni-record');
|
|
29
|
+
expect(documentTable?.type).toBe('entity-child');
|
|
30
|
+
expect(inheritance?.column).toMatchObject({ name: 'recordType' });
|
|
31
|
+
expect(entityColumns).toEqual(
|
|
32
|
+
expect.arrayContaining([
|
|
33
|
+
'documentKind',
|
|
34
|
+
'content',
|
|
35
|
+
'contentMimeType',
|
|
36
|
+
'sourceUrl',
|
|
37
|
+
'publishedAt',
|
|
38
|
+
]),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('defaults the base record kind to document in the class instance', () => {
|
|
43
|
+
const entity = new OmniDocumentEntity();
|
|
44
|
+
|
|
45
|
+
expect(entity.kind).toBe(OmniDocumentKind.Document);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('allows explicit document subtypes while keeping the base record kind stable', () => {
|
|
49
|
+
const entity = new OmniDocumentEntity();
|
|
50
|
+
entity.documentKind = OmniDocumentKind.Note;
|
|
51
|
+
|
|
52
|
+
expect(entity.kind).toBe(OmniDocumentKind.Document);
|
|
53
|
+
expect(entity.documentKind).toBe(OmniDocumentKind.Note);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { describe, expect, it, jest } from '@jest/globals';
|
|
2
|
-
|
|
3
|
-
import { OmniDocumentService } from '../omni-document.service.js';
|
|
4
|
-
import { OmniDocumentEntity } from '../omni-document.entity.js';
|
|
5
|
-
import { OmniDocumentKind } from '../omni-document-kind.enum.js';
|
|
6
|
-
|
|
7
|
-
const createRepositoryPair = () => {
|
|
8
|
-
const readRepository = {
|
|
9
|
-
target: OmniDocumentEntity,
|
|
10
|
-
findOneOrFail: jest.fn(),
|
|
11
|
-
getId: jest.fn((entity: OmniDocumentEntity) => ({ guid: entity.guid })),
|
|
12
|
-
};
|
|
13
|
-
const writeRepository = {
|
|
14
|
-
target: OmniDocumentEntity,
|
|
15
|
-
create: jest.fn((input: unknown) => input),
|
|
16
|
-
insert: jest.fn(async () => ({
|
|
17
|
-
identifiers: [{ guid: '11111111-1111-1111-1111-111111111111' }],
|
|
18
|
-
})),
|
|
19
|
-
update: jest.fn(async () => ({ affected: 1 })),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return { readRepository, writeRepository };
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
describe('OmniDocumentService', () => {
|
|
26
|
-
it('forces the base record kind during createEntity', async () => {
|
|
27
|
-
const { readRepository, writeRepository } = createRepositoryPair();
|
|
28
|
-
const service = new OmniDocumentService(
|
|
29
|
-
readRepository as never,
|
|
30
|
-
writeRepository as never,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
await service.createEntity(
|
|
34
|
-
{
|
|
35
|
-
guid: '11111111-1111-1111-1111-111111111111',
|
|
36
|
-
title: 'Document',
|
|
37
|
-
kind: 'unexpected-kind',
|
|
38
|
-
documentKind: OmniDocumentKind.Note,
|
|
39
|
-
},
|
|
40
|
-
undefined,
|
|
41
|
-
false,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
expect(writeRepository.insert).toHaveBeenCalledWith(
|
|
45
|
-
expect.objectContaining({
|
|
46
|
-
kind: OmniDocumentKind.Document,
|
|
47
|
-
documentKind: OmniDocumentKind.Note,
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('forces the base record kind during updateEntity', async () => {
|
|
53
|
-
const { readRepository, writeRepository } = createRepositoryPair();
|
|
54
|
-
const service = new OmniDocumentService(
|
|
55
|
-
readRepository as never,
|
|
56
|
-
writeRepository as never,
|
|
57
|
-
);
|
|
58
|
-
(service as any).validateConditions = jest.fn(async () => ({
|
|
59
|
-
guid: '11111111-1111-1111-1111-111111111111',
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
await service.updateEntity(
|
|
63
|
-
{ guid: '11111111-1111-1111-1111-111111111111' },
|
|
64
|
-
{
|
|
65
|
-
kind: 'unexpected-kind',
|
|
66
|
-
documentKind: OmniDocumentKind.Article,
|
|
67
|
-
},
|
|
68
|
-
undefined,
|
|
69
|
-
false,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
expect(writeRepository.update).toHaveBeenCalledWith(
|
|
73
|
-
expect.objectContaining({
|
|
74
|
-
guid: '11111111-1111-1111-1111-111111111111',
|
|
75
|
-
kind: OmniDocumentKind.Document,
|
|
76
|
-
}),
|
|
77
|
-
expect.objectContaining({
|
|
78
|
-
kind: OmniDocumentKind.Document,
|
|
79
|
-
documentKind: OmniDocumentKind.Article,
|
|
80
|
-
}),
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
1
|
+
import { describe, expect, it, jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
import { OmniDocumentService } from '../omni-document.service.js';
|
|
4
|
+
import { OmniDocumentEntity } from '../omni-document.entity.js';
|
|
5
|
+
import { OmniDocumentKind } from '../omni-document-kind.enum.js';
|
|
6
|
+
|
|
7
|
+
const createRepositoryPair = () => {
|
|
8
|
+
const readRepository = {
|
|
9
|
+
target: OmniDocumentEntity,
|
|
10
|
+
findOneOrFail: jest.fn(),
|
|
11
|
+
getId: jest.fn((entity: OmniDocumentEntity) => ({ guid: entity.guid })),
|
|
12
|
+
};
|
|
13
|
+
const writeRepository = {
|
|
14
|
+
target: OmniDocumentEntity,
|
|
15
|
+
create: jest.fn((input: unknown) => input),
|
|
16
|
+
insert: jest.fn(async () => ({
|
|
17
|
+
identifiers: [{ guid: '11111111-1111-1111-1111-111111111111' }],
|
|
18
|
+
})),
|
|
19
|
+
update: jest.fn(async () => ({ affected: 1 })),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return { readRepository, writeRepository };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('OmniDocumentService', () => {
|
|
26
|
+
it('forces the base record kind during createEntity', async () => {
|
|
27
|
+
const { readRepository, writeRepository } = createRepositoryPair();
|
|
28
|
+
const service = new OmniDocumentService(
|
|
29
|
+
readRepository as never,
|
|
30
|
+
writeRepository as never,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await service.createEntity(
|
|
34
|
+
{
|
|
35
|
+
guid: '11111111-1111-1111-1111-111111111111',
|
|
36
|
+
title: 'Document',
|
|
37
|
+
kind: 'unexpected-kind',
|
|
38
|
+
documentKind: OmniDocumentKind.Note,
|
|
39
|
+
},
|
|
40
|
+
undefined,
|
|
41
|
+
false,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(writeRepository.insert).toHaveBeenCalledWith(
|
|
45
|
+
expect.objectContaining({
|
|
46
|
+
kind: OmniDocumentKind.Document,
|
|
47
|
+
documentKind: OmniDocumentKind.Note,
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('forces the base record kind during updateEntity', async () => {
|
|
53
|
+
const { readRepository, writeRepository } = createRepositoryPair();
|
|
54
|
+
const service = new OmniDocumentService(
|
|
55
|
+
readRepository as never,
|
|
56
|
+
writeRepository as never,
|
|
57
|
+
);
|
|
58
|
+
(service as any).validateConditions = jest.fn(async () => ({
|
|
59
|
+
guid: '11111111-1111-1111-1111-111111111111',
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
await service.updateEntity(
|
|
63
|
+
{ guid: '11111111-1111-1111-1111-111111111111' },
|
|
64
|
+
{
|
|
65
|
+
kind: 'unexpected-kind',
|
|
66
|
+
documentKind: OmniDocumentKind.Article,
|
|
67
|
+
},
|
|
68
|
+
undefined,
|
|
69
|
+
false,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(writeRepository.update).toHaveBeenCalledWith(
|
|
73
|
+
expect.objectContaining({
|
|
74
|
+
guid: '11111111-1111-1111-1111-111111111111',
|
|
75
|
+
kind: OmniDocumentKind.Document,
|
|
76
|
+
}),
|
|
77
|
+
expect.objectContaining({
|
|
78
|
+
kind: OmniDocumentKind.Document,
|
|
79
|
+
documentKind: OmniDocumentKind.Article,
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|