Skip to content

Commit 0fd6329

Browse files
LukasBolllucas-koehler
authored andcommitted
refactor(core): resolve circular dependencies
Eliminated circular dependencies in the core module and reorganized package structure. Ref #2321
1 parent 635faab commit 0fd6329

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+761
-717
lines changed

packages/core/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,11 @@ module.exports = {
3838
ignore: ['^ava$'],
3939
},
4040
],
41+
'import/no-cycle': [
42+
'error',
43+
{
44+
ignoreExternal: true,
45+
},
46+
],
4147
},
4248
};

packages/core/src/actions/actions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525

2626
import type AJV from 'ajv';
2727
import type { ErrorObject } from 'ajv';
28-
import type { JsonSchema, UISchemaElement } from '../models';
28+
import { JsonSchema, UISchemaElement } from '../models';
2929
import { generateDefaultUISchema, generateJsonSchema } from '../generators';
3030

31-
import type { RankedTester } from '../testers';
32-
import type { UISchemaTester, ValidationMode } from '../reducers';
33-
import type { ErrorTranslator, Translator } from '../i18n';
31+
import { RankedTester, UISchemaTester } from '../testers';
32+
import { ErrorTranslator, Translator, ValidationMode } from '../store';
3433

3534
export const INIT = 'jsonforms/INIT' as const;
3635
export const UPDATE_CORE = 'jsonforms/UPDATE_CORE' as const;

packages/core/src/generators/Generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
THE SOFTWARE.
2424
*/
2525

26+
import { ControlElement, JsonSchema, UISchemaElement } from '../models';
2627
import { generateJsonSchema } from './schema';
2728
import { createControlElement, generateDefaultUISchema } from './uischema';
28-
import type { ControlElement, JsonSchema, UISchemaElement } from '../';
2929

3030
export const Generate: {
3131
// TODO fix @typescript-eslint/ban-types

packages/core/src/generators/uischema.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ import startCase from 'lodash/startCase';
2828
import keys from 'lodash/keys';
2929
import {
3030
ControlElement,
31-
isGroup,
32-
isLayout,
3331
JsonSchema,
3432
LabelElement,
3533
Layout,
3634
UISchemaElement,
3735
} from '../models';
38-
import { deriveTypes, encode, resolveSchema } from '../util';
36+
import { deriveTypes, encode, isGroup, isLayout, resolveSchema } from '../util';
3937

4038
/**
4139
* Creates a new ILayout.

packages/core/src/i18n/i18nUtil.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { ErrorObject } from 'ajv';
2-
import { isInternationalized, Labelable, UISchemaElement } from '../models';
3-
import { getControlPath } from '../reducers';
4-
import { formatErrorMessage } from '../util';
5-
import type { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
2+
import { Labelable, UISchemaElement } from '../models';
3+
import type { i18nJsonSchema, ErrorTranslator, Translator } from '../store';
64
import {
75
ArrayDefaultTranslation,
86
ArrayTranslations,
@@ -11,6 +9,11 @@ import {
119
CombinatorDefaultTranslation,
1210
CombinatorTranslations,
1311
} from './combinatorTranslations';
12+
import {
13+
formatErrorMessage,
14+
getControlPath,
15+
isInternationalized,
16+
} from '../util';
1417

1518
export const getI18nKeyPrefixBySchema = (
1619
schema: i18nJsonSchema | undefined,

packages/core/src/i18n/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './i18nTypes';
2-
export * from './i18nUtil';
31
export * from './arrayTranslations';
42
export * from './combinatorTranslations';
3+
export * from './selectors';
4+
export * from './i18nUtil';

packages/core/src/i18n/selectors.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
The MIT License
3+
4+
Copyright (c) 2017-2019 EclipseSource Munich
5+
https://github.com/eclipsesource/jsonforms
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
*/
25+
26+
import get from 'lodash/get';
27+
import {
28+
ErrorTranslator,
29+
JsonFormsI18nState,
30+
Translator,
31+
JsonFormsState,
32+
} from '../store';
33+
import { defaultErrorTranslator, defaultTranslator } from './i18nUtil';
34+
35+
export const fetchLocale = (state?: JsonFormsI18nState) => {
36+
if (state === undefined) {
37+
return undefined;
38+
}
39+
return state.locale;
40+
};
41+
42+
export const fetchTranslator = (state?: JsonFormsI18nState) => {
43+
if (state === undefined) {
44+
return defaultTranslator;
45+
}
46+
return state.translate;
47+
};
48+
49+
export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
50+
if (state === undefined) {
51+
return defaultErrorTranslator;
52+
}
53+
return state.translateError;
54+
};
55+
56+
export const getLocale = (state: JsonFormsState) =>
57+
fetchLocale(get(state, 'jsonforms.i18n'));
58+
59+
export const getTranslator =
60+
() =>
61+
(state: JsonFormsState): Translator =>
62+
fetchTranslator(get(state, 'jsonforms.i18n'));
63+
64+
export const getErrorTranslator =
65+
() =>
66+
(state: JsonFormsState): ErrorTranslator =>
67+
fetchErrorTranslator(get(state, 'jsonforms.i18n'));

packages/core/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export * from './reducers';
3131
export * from './testers';
3232
export * as Test from './testers';
3333
export * from './util';
34-
35-
export * from './Helpers';
3634
export * from './store';
3735
export * from './i18n';
36+
export * from './mappers';

packages/core/src/util/cell.ts renamed to packages/core/src/mappers/cell.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,7 @@
2424
*/
2525

2626
import isEmpty from 'lodash/isEmpty';
27-
import {
28-
getErrorTranslator,
29-
getAjv,
30-
getConfig,
31-
getData,
32-
getErrorAt,
33-
getSchema,
34-
getTranslator,
35-
} from '../reducers';
36-
import type { JsonFormsCellRendererRegistryEntry } from '../reducers';
37-
import type { AnyAction, Dispatch } from './type';
38-
import { Resolve } from './util';
39-
import { isInherentlyEnabled, isVisible } from './runtime';
27+
import { isVisible, Resolve } from '../util';
4028
import {
4129
DispatchPropsOfControl,
4230
EnumOption,
@@ -47,9 +35,25 @@ import {
4735
OwnPropsOfEnum,
4836
StatePropsOfScopedRenderer,
4937
} from './renderer';
50-
import { getCombinedErrorMessage, getI18nKeyPrefix } from '../i18n';
51-
import type { JsonFormsState } from '../store';
38+
import {
39+
getCombinedErrorMessage,
40+
getErrorTranslator,
41+
getI18nKeyPrefix,
42+
getTranslator,
43+
} from '../i18n';
5244
import type { JsonSchema } from '../models';
45+
import {
46+
AnyAction,
47+
Dispatch,
48+
getAjv,
49+
getConfig,
50+
getData,
51+
getErrorAt,
52+
getSchema,
53+
JsonFormsCellRendererRegistryEntry,
54+
JsonFormsState,
55+
} from '../store';
56+
import { isInherentlyEnabled } from './util';
5357

5458
export interface OwnPropsOfCell extends OwnPropsOfControl {
5559
data?: any;

packages/core/src/util/combinators.ts renamed to packages/core/src/mappers/combinators.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
*/
2525

2626
import type { ControlElement, JsonSchema, UISchemaElement } from '../models';
27-
import { findUISchema, JsonFormsUISchemaRegistryEntry } from '../reducers';
28-
import { Resolve } from './util';
27+
import { findUISchema } from '../reducers';
28+
import { JsonFormsUISchemaRegistryEntry } from '../store';
29+
import { Resolve } from '../util/util';
2930

3031
export interface CombinatorSubSchemaRenderInfo {
3132
schema: JsonSchema;

packages/core/src/mappers/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
The MIT License
3+
4+
Copyright (c) 2024 EclipseSource Munich
5+
https://github.com/eclipsesource/jsonforms
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
*/
25+
26+
export * from './renderer';
27+
export * from './cell';
28+
export * from './combinators';
29+
export * from './util';

0 commit comments

Comments
 (0)