strapi-relation-names 0.0.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +171 -0
  3. package/dist/admin/SettingsPage-BQo5mpAY.mjs +199 -0
  4. package/dist/admin/SettingsPage-C1nFFJjH.js +199 -0
  5. package/dist/admin/de-BBrO1tf0.js +16 -0
  6. package/dist/admin/de-a3KtzZ7N.mjs +16 -0
  7. package/dist/admin/en-8w3y1FSw.mjs +16 -0
  8. package/dist/admin/en-DlY6ZGdo.js +16 -0
  9. package/dist/admin/index-CJO9wtUk.mjs +125 -0
  10. package/dist/admin/index-SsQXjQq0.js +124 -0
  11. package/dist/admin/index.js +4 -0
  12. package/dist/admin/index.mjs +4 -0
  13. package/dist/admin/src/index.d.ts +3 -0
  14. package/dist/admin/src/pages/SettingsPage.d.ts +2 -0
  15. package/dist/admin/src/pluginId.d.ts +1 -0
  16. package/dist/admin/src/types.d.ts +28 -0
  17. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  18. package/dist/admin/src/utils/layout.d.ts +3 -0
  19. package/dist/admin/src/utils/template.d.ts +5 -0
  20. package/dist/server/index.js +564 -0
  21. package/dist/server/index.mjs +564 -0
  22. package/dist/server/src/bootstrap.d.ts +5 -0
  23. package/dist/server/src/config/index.d.ts +12 -0
  24. package/dist/server/src/constants.d.ts +1 -0
  25. package/dist/server/src/content-types/index.d.ts +2 -0
  26. package/dist/server/src/controllers/index.d.ts +9 -0
  27. package/dist/server/src/controllers/settings.d.ts +8 -0
  28. package/dist/server/src/destroy.d.ts +5 -0
  29. package/dist/server/src/index.d.ts +66 -0
  30. package/dist/server/src/middlewares/index.d.ts +2 -0
  31. package/dist/server/src/policies/index.d.ts +2 -0
  32. package/dist/server/src/register.d.ts +5 -0
  33. package/dist/server/src/routes/admin/index.d.ts +12 -0
  34. package/dist/server/src/routes/content-api/index.d.ts +5 -0
  35. package/dist/server/src/routes/index.d.ts +18 -0
  36. package/dist/server/src/services/index.d.ts +19 -0
  37. package/dist/server/src/services/relation-labels.d.ts +14 -0
  38. package/dist/server/src/services/settings.d.ts +11 -0
  39. package/dist/server/src/services/utils/collections.d.ts +1 -0
  40. package/dist/server/src/services/utils/relation-labels.d.ts +27 -0
  41. package/dist/server/src/services/utils/relation-values.d.ts +6 -0
  42. package/dist/server/src/types.d.ts +5 -0
  43. package/package.json +77 -0
@@ -0,0 +1,125 @@
1
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
2
+ const v = glob[path];
3
+ if (v) {
4
+ return typeof v === "function" ? v() : Promise.resolve(v);
5
+ }
6
+ return new Promise((_, reject) => {
7
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
8
+ reject.bind(
9
+ null,
10
+ new Error(
11
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
12
+ )
13
+ )
14
+ );
15
+ });
16
+ };
17
+ const PLUGIN_ID = "strapi-relation-names";
18
+ const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
19
+ const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
20
+ const getMainFieldName = (layout, fieldName) => layout.settings?.relationNames?.[fieldName]?.mainField;
21
+ const mutateFields = (fields, layout) => {
22
+ if (!Array.isArray(fields)) {
23
+ return fields;
24
+ }
25
+ return fields.map((field) => {
26
+ if (!isRecord(field)) {
27
+ return field;
28
+ }
29
+ const mainField = getMainFieldName(layout, typeof field.name === "string" ? field.name : "");
30
+ if (!mainField || !isRecord(field.mainField)) {
31
+ return field;
32
+ }
33
+ return {
34
+ ...field,
35
+ mainField: { ...field.mainField, name: mainField }
36
+ };
37
+ });
38
+ };
39
+ const mutateEditLayoutObject = (layout) => {
40
+ const components = Object.fromEntries(
41
+ Object.entries(layout.components ?? {}).map(([uid, componentLayout]) => [
42
+ uid,
43
+ mutateEditLayoutObject(componentLayout)
44
+ ])
45
+ );
46
+ return {
47
+ ...layout,
48
+ layout: Array.isArray(layout.layout) ? layout.layout.map((entry) => {
49
+ if (!Array.isArray(entry)) {
50
+ return entry;
51
+ }
52
+ return Array.isArray(entry[0]) ? entry.map((row) => mutateFields(row, layout)) : mutateFields(entry, layout);
53
+ }) : layout.layout,
54
+ components
55
+ };
56
+ };
57
+ const mutateEditLayout = (payload) => {
58
+ if (!isRecord(payload) || !isRecord(payload.layout)) {
59
+ return payload;
60
+ }
61
+ return { ...payload, layout: mutateEditLayoutObject(payload.layout) };
62
+ };
63
+ const mutateListHeaders = (payload) => {
64
+ if (!isRecord(payload) || !Array.isArray(payload.displayedHeaders) || !isRecord(payload.layout)) {
65
+ return payload;
66
+ }
67
+ const layout = payload.layout;
68
+ return {
69
+ ...payload,
70
+ displayedHeaders: payload.displayedHeaders.map((header) => {
71
+ if (!isRecord(header) || !isRecord(header.mainField)) {
72
+ return header;
73
+ }
74
+ const mainField = getMainFieldName(
75
+ layout,
76
+ typeof header.name === "string" ? header.name : ""
77
+ );
78
+ return mainField ? { ...header, mainField: { ...header.mainField, name: mainField } } : header;
79
+ })
80
+ };
81
+ };
82
+ const plugin = {
83
+ register(app) {
84
+ app.addSettingsLink("global", {
85
+ id: PLUGIN_ID,
86
+ to: PLUGIN_ID,
87
+ intlLabel: {
88
+ id: `${PLUGIN_ID}.plugin.name`,
89
+ defaultMessage: "Relation Names"
90
+ },
91
+ Component: () => import("./SettingsPage-BQo5mpAY.mjs").then((module) => ({ default: module.SettingsPage })),
92
+ permissions: []
93
+ });
94
+ app.registerPlugin({
95
+ id: PLUGIN_ID,
96
+ isReady: true,
97
+ name: PLUGIN_ID
98
+ });
99
+ },
100
+ bootstrap({ registerHook }) {
101
+ registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditLayout);
102
+ registerHook("Admin/CM/pages/ListView/inject-column-in-table", mutateListHeaders);
103
+ },
104
+ registerTrads({ locales }) {
105
+ return Promise.all(
106
+ locales.map(async (locale) => {
107
+ try {
108
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-a3KtzZ7N.mjs"), "./translations/en.json": () => import("./en-8w3y1FSw.mjs") }), `./translations/${locale}.json`, 3);
109
+ const newData = {};
110
+ const keys = Object.keys(data);
111
+ for (const key of keys) {
112
+ newData[getTranslation(key)] = data[key];
113
+ }
114
+ return { data: newData, locale };
115
+ } catch {
116
+ return { data: {}, locale };
117
+ }
118
+ })
119
+ );
120
+ }
121
+ };
122
+ export {
123
+ getTranslation as g,
124
+ plugin as p
125
+ };
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
3
+ const v = glob[path];
4
+ if (v) {
5
+ return typeof v === "function" ? v() : Promise.resolve(v);
6
+ }
7
+ return new Promise((_, reject) => {
8
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
9
+ reject.bind(
10
+ null,
11
+ new Error(
12
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
13
+ )
14
+ )
15
+ );
16
+ });
17
+ };
18
+ const PLUGIN_ID = "strapi-relation-names";
19
+ const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
20
+ const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
21
+ const getMainFieldName = (layout, fieldName) => layout.settings?.relationNames?.[fieldName]?.mainField;
22
+ const mutateFields = (fields, layout) => {
23
+ if (!Array.isArray(fields)) {
24
+ return fields;
25
+ }
26
+ return fields.map((field) => {
27
+ if (!isRecord(field)) {
28
+ return field;
29
+ }
30
+ const mainField = getMainFieldName(layout, typeof field.name === "string" ? field.name : "");
31
+ if (!mainField || !isRecord(field.mainField)) {
32
+ return field;
33
+ }
34
+ return {
35
+ ...field,
36
+ mainField: { ...field.mainField, name: mainField }
37
+ };
38
+ });
39
+ };
40
+ const mutateEditLayoutObject = (layout) => {
41
+ const components = Object.fromEntries(
42
+ Object.entries(layout.components ?? {}).map(([uid, componentLayout]) => [
43
+ uid,
44
+ mutateEditLayoutObject(componentLayout)
45
+ ])
46
+ );
47
+ return {
48
+ ...layout,
49
+ layout: Array.isArray(layout.layout) ? layout.layout.map((entry) => {
50
+ if (!Array.isArray(entry)) {
51
+ return entry;
52
+ }
53
+ return Array.isArray(entry[0]) ? entry.map((row) => mutateFields(row, layout)) : mutateFields(entry, layout);
54
+ }) : layout.layout,
55
+ components
56
+ };
57
+ };
58
+ const mutateEditLayout = (payload) => {
59
+ if (!isRecord(payload) || !isRecord(payload.layout)) {
60
+ return payload;
61
+ }
62
+ return { ...payload, layout: mutateEditLayoutObject(payload.layout) };
63
+ };
64
+ const mutateListHeaders = (payload) => {
65
+ if (!isRecord(payload) || !Array.isArray(payload.displayedHeaders) || !isRecord(payload.layout)) {
66
+ return payload;
67
+ }
68
+ const layout = payload.layout;
69
+ return {
70
+ ...payload,
71
+ displayedHeaders: payload.displayedHeaders.map((header) => {
72
+ if (!isRecord(header) || !isRecord(header.mainField)) {
73
+ return header;
74
+ }
75
+ const mainField = getMainFieldName(
76
+ layout,
77
+ typeof header.name === "string" ? header.name : ""
78
+ );
79
+ return mainField ? { ...header, mainField: { ...header.mainField, name: mainField } } : header;
80
+ })
81
+ };
82
+ };
83
+ const plugin = {
84
+ register(app) {
85
+ app.addSettingsLink("global", {
86
+ id: PLUGIN_ID,
87
+ to: PLUGIN_ID,
88
+ intlLabel: {
89
+ id: `${PLUGIN_ID}.plugin.name`,
90
+ defaultMessage: "Relation Names"
91
+ },
92
+ Component: () => Promise.resolve().then(() => require("./SettingsPage-C1nFFJjH.js")).then((module2) => ({ default: module2.SettingsPage })),
93
+ permissions: []
94
+ });
95
+ app.registerPlugin({
96
+ id: PLUGIN_ID,
97
+ isReady: true,
98
+ name: PLUGIN_ID
99
+ });
100
+ },
101
+ bootstrap({ registerHook }) {
102
+ registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditLayout);
103
+ registerHook("Admin/CM/pages/ListView/inject-column-in-table", mutateListHeaders);
104
+ },
105
+ registerTrads({ locales }) {
106
+ return Promise.all(
107
+ locales.map(async (locale) => {
108
+ try {
109
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-BBrO1tf0.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-DlY6ZGdo.js")) }), `./translations/${locale}.json`, 3);
110
+ const newData = {};
111
+ const keys = Object.keys(data);
112
+ for (const key of keys) {
113
+ newData[getTranslation(key)] = data[key];
114
+ }
115
+ return { data: newData, locale };
116
+ } catch {
117
+ return { data: {}, locale };
118
+ }
119
+ })
120
+ );
121
+ }
122
+ };
123
+ exports.getTranslation = getTranslation;
124
+ exports.plugin = plugin;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const index = require("./index-SsQXjQq0.js");
4
+ exports.default = index.plugin;
@@ -0,0 +1,4 @@
1
+ import { p } from "./index-CJO9wtUk.mjs";
2
+ export {
3
+ p as default
4
+ };
@@ -0,0 +1,3 @@
1
+ import { StrapiApp } from '@strapi/strapi/admin';
2
+ declare const plugin: StrapiApp['appPlugins'][string];
3
+ export default plugin;
@@ -0,0 +1,2 @@
1
+ declare const SettingsPage: () => import("react").JSX.Element;
2
+ export { SettingsPage };
@@ -0,0 +1 @@
1
+ export declare const PLUGIN_ID = "strapi-relation-names";
@@ -0,0 +1,28 @@
1
+ export type RelationNamesSettings = {
2
+ collections: string[];
3
+ relations: Record<string, Record<string, string>>;
4
+ };
5
+ export type SchemaAttribute = {
6
+ type?: string;
7
+ targetModel?: string;
8
+ target?: string;
9
+ relationType?: string;
10
+ };
11
+ export type Schema = {
12
+ uid: string;
13
+ isDisplayed?: boolean;
14
+ category?: string;
15
+ info?: {
16
+ displayName?: string;
17
+ };
18
+ attributes?: Record<string, SchemaAttribute>;
19
+ };
20
+ export type InitResponse = {
21
+ data: {
22
+ contentTypes: Schema[];
23
+ components: Schema[];
24
+ };
25
+ };
26
+ export type SettingsResponse = {
27
+ data: RelationNamesSettings;
28
+ };
@@ -0,0 +1,2 @@
1
+ declare const getTranslation: (id: string) => string;
2
+ export { getTranslation };
@@ -0,0 +1,3 @@
1
+ declare const mutateEditLayout: (payload: unknown) => unknown;
2
+ declare const mutateListHeaders: (payload: unknown) => unknown;
3
+ export { mutateEditLayout, mutateListHeaders };
@@ -0,0 +1,5 @@
1
+ declare const getPlaceholders: (template: string) => string[] | null;
2
+ declare const validateTemplate: (template: string, attributes: Record<string, {
3
+ type?: string;
4
+ }> | undefined) => string | null;
5
+ export { getPlaceholders, validateTemplate };