strapi-relation-names 1.2.2 → 1.3.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 (33) hide show
  1. package/README.md +17 -42
  2. package/dist/{admin/SettingsPage-BebR4ghK.js → _chunks/SettingsPage-BMwx-BuP.js} +122 -48
  3. package/dist/{admin/SettingsPage-DFZP5CZs.mjs → _chunks/SettingsPage-D8leItKF.mjs} +122 -48
  4. package/dist/{admin/index-CiS6cuI9.mjs → _chunks/index-BeLPoAiU.mjs} +1 -1
  5. package/dist/{admin/index-DfSAe961.js → _chunks/index-COuIED98.js} +1 -1
  6. package/dist/admin/index.js +2 -3
  7. package/dist/admin/index.mjs +1 -1
  8. package/dist/admin/src/index.d.ts +1 -1
  9. package/dist/admin/src/pages/SettingsPage.d.ts +1 -0
  10. package/dist/admin/src/utils/template.d.ts +1 -14
  11. package/dist/server/index.js +269 -129
  12. package/dist/server/index.mjs +268 -127
  13. package/dist/server/src/bootstrap.d.ts +1 -1
  14. package/dist/server/src/config/index.d.ts +2 -0
  15. package/dist/server/src/controllers/index.d.ts +1 -1
  16. package/dist/server/src/controllers/settings.d.ts +1 -1
  17. package/dist/server/src/destroy.d.ts +1 -1
  18. package/dist/server/src/index.d.ts +20 -11
  19. package/dist/server/src/register.d.ts +1 -1
  20. package/dist/server/src/services/index.d.ts +8 -7
  21. package/dist/server/src/services/relation-labels.d.ts +6 -9
  22. package/dist/server/src/services/settings.d.ts +2 -2
  23. package/dist/server/src/services/utils/relation-hydration.d.ts +7 -0
  24. package/dist/server/src/services/utils/relation-labels.d.ts +4 -22
  25. package/dist/server/src/services/utils/relation-runtime.d.ts +6 -0
  26. package/dist/server/src/services/utils/relation-values.d.ts +1 -1
  27. package/dist/shared/records.d.ts +1 -0
  28. package/dist/shared/template.d.ts +55 -0
  29. package/package.json +28 -28
  30. /package/dist/{admin → _chunks}/de-Bc81LkbY.mjs +0 -0
  31. /package/dist/{admin → _chunks}/de-CsBvOsWR.js +0 -0
  32. /package/dist/{admin → _chunks}/en-Bk-HIXNd.mjs +0 -0
  33. /package/dist/{admin → _chunks}/en-DT4g6X2H.js +0 -0
@@ -1,12 +1,12 @@
1
1
  declare const _default: {
2
2
  register: ({ strapi }: {
3
- strapi: import('@strapi/types/dist/core').Strapi;
3
+ strapi: import("@strapi/types/dist/core").Strapi;
4
4
  }) => void;
5
5
  bootstrap: ({ strapi }: {
6
- strapi: import('@strapi/types/dist/core').Strapi;
6
+ strapi: import("@strapi/types/dist/core").Strapi;
7
7
  }) => void;
8
8
  destroy: ({ strapi }: {
9
- strapi: import('@strapi/types/dist/core').Strapi;
9
+ strapi: import("@strapi/types/dist/core").Strapi;
10
10
  }) => void;
11
11
  config: {
12
12
  default: {
@@ -14,11 +14,13 @@ declare const _default: {
14
14
  };
15
15
  validator: (config: unknown) => asserts config is {
16
16
  collections: string[];
17
+ locale?: string;
18
+ timeZone?: string;
17
19
  };
18
20
  };
19
21
  controllers: {
20
22
  settings: ({ strapi }: {
21
- strapi: import('@strapi/types/dist/core').Strapi;
23
+ strapi: import("@strapi/types/dist/core").Strapi;
22
24
  }) => {
23
25
  find(ctx: any): Promise<void>;
24
26
  update(ctx: any): Promise<any>;
@@ -29,12 +31,18 @@ declare const _default: {
29
31
  type: string;
30
32
  routes: any[];
31
33
  };
34
+ /**
35
+ * Plugin server methods
36
+ */
32
37
  admin: () => {
33
38
  type: string;
34
39
  routes: {
35
40
  method: string;
36
41
  path: string;
37
42
  handler: string;
43
+ /**
44
+ * Plugin server methods
45
+ */
38
46
  config: {
39
47
  policies: string[];
40
48
  };
@@ -43,20 +51,21 @@ declare const _default: {
43
51
  };
44
52
  services: {
45
53
  'relation-labels': ({ strapi }: {
46
- strapi: import('@strapi/types/dist/core').Strapi;
54
+ strapi: import("@strapi/types/dist/core").Strapi;
47
55
  }) => {
48
56
  decorateCollectionResults: (ctx: any, sourceUid: string, results: unknown[]) => Promise<unknown[]>;
49
57
  decorateConfiguration: (data: any, sourceUid: string) => Promise<any>;
58
+ sanitizeConfigurationUpdate: (configuration: any) => any;
50
59
  decorateRelationResults: (ctx: any, sourceUid: string, targetField: string, results: unknown[]) => Promise<unknown[]>;
51
- compileTemplate: (template: string, targetSchema: import('./services/utils/relation-labels').SchemaLike | undefined, resolveSchema?: import('./services/utils/relation-labels').SchemaResolver) => import('./services/utils/relation-labels').CompiledTemplate | null;
52
- parseTemplate: (template: string) => string[] | null;
53
- renderTemplate: (compiled: import('./services/utils/relation-labels').CompiledTemplate, values: Record<string, unknown>) => string;
60
+ compileTemplate: (template: string, targetSchema: import("./services/utils/relation-labels").TemplateSchema, resolveSchema?: import("./services/utils/relation-labels").SchemaResolver) => import("./services/utils/relation-labels").CompiledTemplate;
61
+ parseTemplate: (template: string) => string[];
62
+ renderTemplate: (compiled: import("./services/utils/relation-labels").CompiledTemplate, values: Record<string, unknown>, context?: import("../../shared/template").TransformContext) => string;
54
63
  };
55
64
  settings: ({ strapi }: {
56
- strapi: import('@strapi/types/dist/core').Strapi;
65
+ strapi: import("@strapi/types/dist/core").Strapi;
57
66
  }) => {
58
- get(): Promise<import('./types').RelationNamesSettings>;
59
- set(value: unknown): Promise<import('./types').RelationNamesSettings>;
67
+ get(): Promise<import("./types").RelationNamesSettings>;
68
+ set(value: unknown): Promise<import("./types").RelationNamesSettings>;
60
69
  };
61
70
  };
62
71
  contentTypes: {};
@@ -1,4 +1,4 @@
1
- import { Core } from '@strapi/strapi';
1
+ import type { Core } from '@strapi/strapi';
2
2
  declare const register: ({ strapi }: {
3
3
  strapi: Core.Strapi;
4
4
  }) => void;
@@ -1,19 +1,20 @@
1
1
  declare const _default: {
2
2
  'relation-labels': ({ strapi }: {
3
- strapi: import('@strapi/types/dist/core').Strapi;
3
+ strapi: import("@strapi/types/dist/core").Strapi;
4
4
  }) => {
5
5
  decorateCollectionResults: (ctx: any, sourceUid: string, results: unknown[]) => Promise<unknown[]>;
6
6
  decorateConfiguration: (data: any, sourceUid: string) => Promise<any>;
7
+ sanitizeConfigurationUpdate: (configuration: any) => any;
7
8
  decorateRelationResults: (ctx: any, sourceUid: string, targetField: string, results: unknown[]) => Promise<unknown[]>;
8
- compileTemplate: (template: string, targetSchema: import('./utils/relation-labels').SchemaLike | undefined, resolveSchema?: import('./utils/relation-labels').SchemaResolver) => import('./utils/relation-labels').CompiledTemplate | null;
9
- parseTemplate: (template: string) => string[] | null;
10
- renderTemplate: (compiled: import('./utils/relation-labels').CompiledTemplate, values: Record<string, unknown>) => string;
9
+ compileTemplate: (template: string, targetSchema: import("./utils/relation-labels").TemplateSchema, resolveSchema?: import("./utils/relation-labels").SchemaResolver) => import("./utils/relation-labels").CompiledTemplate;
10
+ parseTemplate: (template: string) => string[];
11
+ renderTemplate: (compiled: import("./utils/relation-labels").CompiledTemplate, values: Record<string, unknown>, context?: import("../../../shared/template").TransformContext) => string;
11
12
  };
12
13
  settings: ({ strapi }: {
13
- strapi: import('@strapi/types/dist/core').Strapi;
14
+ strapi: import("@strapi/types/dist/core").Strapi;
14
15
  }) => {
15
- get(): Promise<import('../types').RelationNamesSettings>;
16
- set(value: unknown): Promise<import('../types').RelationNamesSettings>;
16
+ get(): Promise<import("../types").RelationNamesSettings>;
17
+ set(value: unknown): Promise<import("../types").RelationNamesSettings>;
17
18
  };
18
19
  };
19
20
  export default _default;
@@ -1,18 +1,15 @@
1
- import { Core } from '@strapi/strapi';
2
- import { SchemaLike } from './utils/relation-labels';
3
- type Populate = Record<string, true | {
4
- populate: Populate;
5
- }>;
6
- declare const buildPopulate: (placeholders: string[]) => Populate | undefined;
1
+ import type { Core } from '@strapi/strapi';
2
+ import { buildPopulate } from './utils/relation-hydration';
7
3
  declare const relationLabels: ({ strapi }: {
8
4
  strapi: Core.Strapi;
9
5
  }) => {
10
6
  decorateCollectionResults: (ctx: any, sourceUid: string, results: unknown[]) => Promise<unknown[]>;
11
7
  decorateConfiguration: (data: any, sourceUid: string) => Promise<any>;
8
+ sanitizeConfigurationUpdate: (configuration: any) => any;
12
9
  decorateRelationResults: (ctx: any, sourceUid: string, targetField: string, results: unknown[]) => Promise<unknown[]>;
13
- compileTemplate: (template: string, targetSchema: SchemaLike | undefined, resolveSchema?: import('./utils/relation-labels').SchemaResolver) => import('./utils/relation-labels').CompiledTemplate | null;
14
- parseTemplate: (template: string) => string[] | null;
15
- renderTemplate: (compiled: import('./utils/relation-labels').CompiledTemplate, values: Record<string, unknown>) => string;
10
+ compileTemplate: (template: string, targetSchema: import("./utils/relation-labels").TemplateSchema, resolveSchema?: import("./utils/relation-labels").SchemaResolver) => import("./utils/relation-labels").CompiledTemplate;
11
+ parseTemplate: (template: string) => string[];
12
+ renderTemplate: (compiled: import("./utils/relation-labels").CompiledTemplate, values: Record<string, unknown>, context?: import("../../../shared/template").TransformContext) => string;
16
13
  };
17
14
  export { buildPopulate };
18
15
  export { compileTemplate, parseTemplate, renderTemplate } from './utils/relation-labels';
@@ -1,5 +1,5 @@
1
- import { Core } from '@strapi/strapi';
2
- import { RelationNamesSettings } from '../types';
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { RelationNamesSettings } from '../types';
3
3
  declare const normalizeSettings: (value: unknown, collections?: string[]) => RelationNamesSettings;
4
4
  declare const settings: ({ strapi }: {
5
5
  strapi: Core.Strapi;
@@ -0,0 +1,7 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { RelationRuntime } from './relation-labels';
3
+ export type Populate = Record<string, true | {
4
+ populate: Populate;
5
+ }>;
6
+ export declare const buildPopulate: (placeholders: string[]) => Populate | undefined;
7
+ export declare const hydrateValues: (strapi: Core.Strapi, ctx: any, runtime: RelationRuntime, values: Record<string, unknown>[]) => Promise<Map<Record<string, unknown>, Record<string, unknown>>>;
@@ -1,29 +1,11 @@
1
- export type SchemaAttribute = {
2
- type?: string;
3
- target?: string;
4
- component?: string;
5
- components?: string[];
6
- relation?: string;
7
- private?: boolean;
8
- };
9
- export type SchemaLike = {
1
+ export type { CompiledTemplate, SchemaResolver, TemplateAttribute as SchemaAttribute, TemplateSchema, } from '../../../../shared/template';
2
+ export { compileTemplate, getPathValue, isRecord, parseTemplate, parseTemplateAst, renderTemplate, } from '../../../../shared/template';
3
+ export type SchemaLike = import('../../../../shared/template').TemplateSchema & {
10
4
  uid: string;
11
5
  modelType?: string;
12
- attributes?: Record<string, SchemaAttribute>;
13
- };
14
- export type SchemaResolver = (uid: string) => SchemaLike | undefined;
15
- export type CompiledTemplate = {
16
- template: string;
17
- placeholders: string[];
18
- displayField: string;
19
6
  };
20
- export type RelationRuntime = CompiledTemplate & {
7
+ export type RelationRuntime = import('../../../../shared/template').CompiledTemplate & {
21
8
  sourceUid: string;
22
9
  targetUid: string;
23
10
  originalMainField: string;
24
11
  };
25
- export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
26
- export declare const getPathValue: (value: unknown, path: string) => unknown;
27
- export declare const parseTemplate: (template: string) => string[] | null;
28
- export declare const compileTemplate: (template: string, targetSchema: SchemaLike | undefined, resolveSchema?: SchemaResolver) => CompiledTemplate | null;
29
- export declare const renderTemplate: (compiled: CompiledTemplate, values: Record<string, unknown>) => string;
@@ -0,0 +1,6 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { RelationNamesSettings } from '../../types';
3
+ import type { TransformContext } from '../../../../shared/template';
4
+ import { type RelationRuntime } from './relation-labels';
5
+ export declare const getRuntime: (strapi: Core.Strapi, settings: RelationNamesSettings, sourceUid: string, targetField: string, userAbility: unknown, transformContext: TransformContext) => Promise<RelationRuntime | null>;
6
+ export declare const getTransformContext: (strapi: Core.Strapi) => TransformContext;
@@ -1,4 +1,4 @@
1
- import { RelationRuntime } from './relation-labels';
1
+ import type { RelationRuntime } from './relation-labels';
2
2
  export declare const getIdentity: (value: Record<string, unknown>, modelType?: string) => unknown;
3
3
  export declare const matchesRelation: (source: Record<string, unknown>, candidate: Record<string, unknown>, targetModelType?: string) => boolean;
4
4
  export declare const applyLabel: (value: Record<string, unknown>, hydrated: Record<string, unknown>, runtime: RelationRuntime) => Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
@@ -0,0 +1,55 @@
1
+ export { isRecord } from './records';
2
+ export type TemplateAttribute = {
3
+ type?: string;
4
+ target?: string;
5
+ targetModel?: string;
6
+ component?: string;
7
+ components?: string[];
8
+ relation?: string;
9
+ private?: boolean;
10
+ };
11
+ export type TemplateSchema = {
12
+ uid?: string;
13
+ attributes?: Record<string, TemplateAttribute>;
14
+ };
15
+ export type SchemaResolver = (uid: string) => TemplateSchema | undefined;
16
+ export type TemplateExpression = {
17
+ path: string;
18
+ transforms: string[];
19
+ };
20
+ export type TemplateToken = {
21
+ type: 'text';
22
+ value: string;
23
+ } | {
24
+ type: 'expression';
25
+ expression: TemplateExpression;
26
+ };
27
+ export type TemplateAst = {
28
+ tokens: TemplateToken[];
29
+ expressions: TemplateExpression[];
30
+ };
31
+ export type TransformContext = {
32
+ locale?: string;
33
+ timeZone?: string;
34
+ };
35
+ export type TransformDefinition = {
36
+ accepts: (fieldType: string | undefined) => boolean;
37
+ apply: (value: unknown, context: TransformContext) => unknown;
38
+ };
39
+ export type CompiledTemplate = {
40
+ template: string;
41
+ placeholders: string[];
42
+ displayField: string;
43
+ tokens?: TemplateToken[];
44
+ expressions?: TemplateExpression[];
45
+ transformContext?: TransformContext;
46
+ };
47
+ export declare const TRANSFORMS: Readonly<Record<string, TransformDefinition>>;
48
+ export declare const getPathValue: (value: unknown, path: string) => unknown;
49
+ export declare const parseTemplateAst: (template: string) => TemplateAst | null;
50
+ export declare const parseTemplate: (template: string) => string[] | null;
51
+ export declare const compileTemplate: (template: string, targetSchema: TemplateSchema | undefined, resolveSchema?: SchemaResolver) => CompiledTemplate | null;
52
+ export declare const renderTemplate: (compiled: CompiledTemplate, values: Record<string, unknown>, context?: TransformContext) => string;
53
+ export declare const validateTemplate: (template: string, attributes: Record<string, TemplateAttribute> | undefined, schemas?: ReadonlyMap<string, TemplateSchema>) => string | null;
54
+ export declare const getAvailableFields: (schema: TemplateSchema | undefined, schemas: ReadonlyMap<string, TemplateSchema>, prefix?: string, ancestors?: Set<string>) => string[];
55
+ export declare const getPlaceholders: (template: string) => string[] | null;
package/package.json CHANGED
@@ -1,17 +1,11 @@
1
1
  {
2
2
  "name": "strapi-relation-names",
3
+ "version": "1.3.0",
3
4
  "description": "Display Strapi relations with clear, customizable labels built from your content fields",
5
+ "keywords": [],
4
6
  "license": "MIT",
5
7
  "author": "Christoph Tupi <christoph.tupi@gmail.com>",
6
- "keywords": [],
7
8
  "type": "commonjs",
8
- "version": "1.2.2",
9
- "strapi": {
10
- "kind": "plugin",
11
- "name": "strapi-relation-names",
12
- "displayName": "Strapi Relation Names",
13
- "description": "Display Strapi relations with clear, customizable labels built from your content fields"
14
- },
15
9
  "exports": {
16
10
  "./package.json": "./package.json",
17
11
  "./strapi-admin": {
@@ -34,22 +28,22 @@
34
28
  ],
35
29
  "scripts": {
36
30
  "build": "strapi-plugin build",
37
- "watch": "strapi-plugin watch",
38
- "watch:link": "strapi-plugin watch:link",
39
- "verify": "strapi-plugin verify",
31
+ "fmt": "oxfmt",
32
+ "lint": "oxlint",
40
33
  "prepare": "lefthook install",
41
34
  "test": "vitest run",
42
- "test:ts:front": "tsc -p admin/tsconfig.json",
43
35
  "test:ts:back": "tsc -p server/tsconfig.json",
44
- "lint": "oxlint",
45
- "fmt": "oxfmt"
36
+ "test:ts:front": "tsc -p admin/tsconfig.json",
37
+ "verify": "strapi-plugin verify",
38
+ "watch": "strapi-plugin watch",
39
+ "watch:link": "strapi-plugin watch:link"
46
40
  },
47
41
  "devDependencies": {
48
- "@strapi/design-system": "^2.2.4",
49
- "@strapi/icons": "^2.2.4",
50
- "@strapi/sdk-plugin": "^6.1.1",
51
- "@strapi/strapi": "^5.52.3",
52
- "@strapi/typescript-utils": "^5.52.3",
42
+ "@strapi/design-system": "^2.0.0-rc.11",
43
+ "@strapi/icons": "^2.0.0-rc.11",
44
+ "@strapi/sdk-plugin": "^5.0.0",
45
+ "@strapi/strapi": "^5.0.0",
46
+ "@strapi/typescript-utils": "^5.0.0",
53
47
  "@types/react": "^18.3.31",
54
48
  "@types/react-dom": "^18.3.7",
55
49
  "lefthook": "^2.1.12",
@@ -64,14 +58,20 @@
64
58
  "vitest": "^5.0.0"
65
59
  },
66
60
  "peerDependencies": {
67
- "@strapi/design-system": "^2.2.4",
68
- "@strapi/icons": "^2.2.4",
69
- "@strapi/sdk-plugin": "^6.1.1",
70
- "@strapi/strapi": "^5.52.3",
71
- "react": "^18.3.1",
72
- "react-dom": "^18.3.1",
73
- "react-intl": "^6.8.9",
74
- "react-router-dom": "^6.30.6",
75
- "styled-components": "^6.5.3"
61
+ "@strapi/design-system": "^2.0.0-rc.11",
62
+ "@strapi/icons": "^2.0.0-rc.11",
63
+ "@strapi/sdk-plugin": "^5.0.0",
64
+ "@strapi/strapi": "^5.0.0",
65
+ "react": "^18.0.0",
66
+ "react-dom": "^18.0.0",
67
+ "react-intl": "^6.6.2",
68
+ "react-router-dom": "^6.0.0",
69
+ "styled-components": "^6.0.0"
70
+ },
71
+ "strapi": {
72
+ "kind": "plugin",
73
+ "name": "strapi-relation-names",
74
+ "displayName": "Strapi Relation Names",
75
+ "description": "Display Strapi relations with clear, customizable labels built from your content fields"
76
76
  }
77
77
  }
File without changes
File without changes
File without changes
File without changes